Jump to content

Pete

Administrators
  • Posts

    4,054
  • Joined

  • Last visited

  • Days Won

    67

Everything posted by Pete

  1. The best thing I've had fun playing with recently is chaining in PW, and it's worth knowing about. Here's a good, slightly abstract example: On a large communal news website, an Article page has a PageField called Author - this links to the Author's page. The Author works for a Company - there might be several authors in that company writing on this website and you might be curious and want to find out various things like the following (pretend we're on the article page still): // Let's find all articles by this author: $author_articles = $pages->find("template=article,author=$page->author"); // Let's get the company name that this author works for - going through a few pages to get this one - from the article to the the author' page then the company page - all using the incredibly powerful PageField field type echo $page->author->company->title; // Ridiculously simple huh? // Now let's grab a list of other authors from this company - not sure why you would, but you could (the authors are all PW users in this case, so the template is 'users') $company_authors = $pages->find("template=user,company=$page->author->company"); // And finally let's get a list of all articles written by all authors in this company using $company_authors above $company_articles = $pages->find("template=article,author=$company_authors"); Now some people might wonder how the last one works - surely $company_authors is an object or array right? Well if you run a simple echo on it, it doesn't spit it's dummy out like PHP normally would, but rather gives you a concatenated list of page IDs in the format: 123|124|1024|456 - the pipe character is used in the last $page->find to mean "OR" so it works perfectly. And this is why I keep getting excited whenever I work with ProcessWire. I would need literally dozens of lines of code to recreate that example in any other CMS I can think of. I pulled in the articles and authors by template, but there are various ways of doing it and I just did it with template names as that didn't assume any particular site structure, so it's not necessary to follow that exactly. Have fun!
  2. Oops - forgot a closing bracket and can't edit on my phone.
  3. Yup, so: if ($profile == $profiles->first()) { echo "I'm first!"; } Should work.
  4. Whilst I'm not sure what a CAS system is, Jim has done something with LDAP which may be of some help:
  5. I think diogo may have your answer there and what I was typing below might be way off, but I'll finish typing it anyway as it shows off some other PW features. I would say yes to your question Jeff, but the thing to remember here is that in ProcessWire every piece of content is a page. That sounds confusing and possibly slightly mental at first, but it's incredibly powerful system as a page can be anything you want it to be. Because all "pages" are accessible via the API, it is simple enough to batch-update pages as you want to. As a rough example (that would need tweaking to handle lots of pages) you can do something like this - this just adds a bit of text to say " - edited" to the end of the title field as an abstract example, but you can edit any field you like: $birds = $pages->find('template=birds'); foreach ($birds as $bird) { $bird->title .= " - edited"; $bird->save(); } And that's all there is to it. I realise that's incredibly simple and likely not at all what you want to do, but it does very briefly show off the selectors that you might use to get the relevant pages and the save function to save your changes. If you're making a single change to the same field across many hundreds or thousands of pages, it might be best to instead skip the line where I saved the page and rab all the page ID's instead, then run a mySQL query to do something like: UPDATE field_table SET data = $your_changed_data where pages_id IN($page_ids_selected_earlier) Looking back at diogo's answer though, that would be the far easier approach and I'm not sure why I didn't think of that first - every time I think metadata I think of keywords and a text field with comma-separated values (the way I used to do it in MODx), when what he's suggesting with a dropdown generated from pages containing just a title field (really simple in PW and not as bonkers as it first sounds) is the best way to go by far.
  6. I did end up having a lot of code that I needed to run to check various things on a site I'm currently building so I just went with the include file in head.inc like you say. Keeps things very neat and tidy in the template and is the easiest way of doing it.
  7. Well all you need to do is use something like what I posted and then keep chaining on successive filters if you then want to narrow it down more. I've got to say though that out of any context it is very confusing to work out what you are trying to achieve. I've read it a few times now and I'm still scratching my head I honestly don't understand what you mean by this: ->children('')->getAttr('id') Are you saying in that case that you want to get the ID's of all the children of the current set of pages (which is 10 pages in your example)? In which case you could be returning a rather large number of ID's if each page can have multiple children. I think in this case you would have to use a foreach anyway if all you want is the 10 pages' child IDs - something like this: // $p is your pagearray with 10 pages again $childIDs = array(); foreach ($p->children as $child) { $childIDs[] = $child->id; } If that's what you were trying to do, you won't find a method for it I don't think, mainly because I can't see a reason why you'd want to reinvent what PHP already does so well with just a couple of lines of code. Of course I may be wrong here and ryan may have built something in like this but after some testing I couldn't find one.
  8. I don't think you could do it without iteration, but if you're trying to get a subset, you could possibly do something like this (though I've not tested it): // Let's assume $p is your 10 pages in a page array as you say, and $myfield is the field you're trying to filter on $subset = $p->find("$myfield!="); I seem to recall that that will return all pages where $myfield is not empty (as in it's not equal to "nothing" ). $subset therefore now contains your filtered list. Let me know if that works. My query would be why you would want to get a subset without iterating through them? Surely you have to iterate through them at some point to output some content?
  9. Glad you found it useful
  10. Wow! That all looks awesome! Can't wait to try it out
  11. $limit = 5; $projects = $page->children("limit=$limit"); $total = ceil($page->children->count() / $limit); All I could manage was to make your example slightly shorter, which doesn't answer your question. Mine removes a superfluous $children = $page->children; and uses PW's own count function. I think that's as short as you'll manage to make it though as I don't know of a function in PW to do exactly what you want. To be honest though it's not really a huge issue (might be nice though) as your code works fine
  12. Have you changed the access permissions on the templates themselves?
  13. Unless I'm missing something here with oEmbed, you don't need any complicated libraries. Assuming for example the two most common video services you use on a particular site are YouTube and Vimeo, you would simply need to check the URL that has been input into a text field (or URL field or whatever) in PW for either "youtube" or "vimeo" and then use CURL to do either: https://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D-UUx10KOWIE&format=xml or: http://vimeo.com/api/oembed.xml?url=http%3A//vimeo.com/7100569 and parse the XML into something useable in a template. I think that the second and third solutions linked to in previous posts poll those two websites (noembed and autoembed), adding another unnecessary link which relies on those websites being online all the time (I might be wrong). I would imagine that a module for oEmbed would "simply" (haha ) detect which site, if any, the URL relates to, fetch the XML response for that site's video service and turn it into something useable - so a normal module call for this in a template would probably be about 4 lines or so and could also allow you to specify dimensions for the video and then do all of the outputting for you. You could then theoretically just dump YouTube/Vimeo/whatever URL's into the middle of your TinyMCE content if you like and have the module parse the $page->body field, turning these links into embedded videos if you really wanted to. I'm tempted to build this module myself as I've currently only managed to build support for YouTube in my current project (using a lot of Google YouTube API files that now appear to be unnecessary), but it'll be a few weeks before I got around to it so if anyone else wants to have a go at it feel free.
  14. I think you're on the right track Antti. The first time I thought about it, back when I was very new to PW, I thought that it should save the relationships both ways. Obviously to de-link the pages this makes it a bit more complicated, plus adds unnecessary clutter to the database (you're saving the relationship twice). Your module idea sounds good and I don't think it would be much more work on top of the "view relationships" to have a button that removes the relationship, so you can do it from either end. Having said "I don't think it would be much more work" I don't have time to look at it myself, but I agree it would be an interesting one to look at for the future. Could even be a useful core addition. I think the only concern I have is to keep it from being confusing for the user, as if they can see page relationships but can't add relationships this might become confusing. Again, you could theoretically add functionality to create more relationships from such a module, but then you're really blurring the lines around which page the data is actually stored against. I like to over-complicate things - maybe just viewing the relationships would be fine
  15. Yeah, my original thought was to somehow make this a checkbox config option in your module to keep things really simple, but it would only be a few minutes' work to cache it in the template anyway Of course, if you wanted to cache it properly, say for a day or more you'd want it to rebuild the menu and re-cache it whenever a page is saved to be on the safe side, so whilst my original idea seemed simple it's actually a bit more complicated than that
  16. My first question is why would you need to do that (I originally wanted to do the same thing)? You can already use selectors via the API in templates to find pages in the other direction. For example, on one site I link news to companies, so the Pagefield for the company is available in the news template (call that field related_company) and I can therefore show some company info with that news article. On the company page via the company template, I can still pull news articles for that company (the reverse of the above) by using something like $news = $pages->find('template=news, related_company=$page'); I would say that unless you have a real need to do this, try not to over complicate it. Of course, your scenario could be very different
  17. Yup - a module is definitely easier when you get to recursive submenus. If you want something that will show a lot of pages with multiple levels of submenus it would be good to have the module cache the output (if t doesn't already).
  18. Hehe, no problem - I still do that from time to time and I have no excuse since PHP is my first programming language
  19. If($page->template = Should be: If($page->template ==
  20. I noticed when adding a new page with 15 images yesterday that it creates thumbnails for each crop config as soon as the page is saved. In my case I have 3 different crops so I ended up with 6mb of images for one page. Shouldn't it be making thumbnails when requested by the templates on page view rather than trying to make all options for a page? This seems a bit wrong to me as some of the crops will only be used by one image in my case. Also, does it do any tidying up after itself if you change a crop size in the config? I don't think it does, but I realise it might be hard to add this as well.
  21. Hi MadeMyDay - you might be better off just taking a look a the default head.inc template and changing the breadcrumb layout there if you want to do something quite a bit different. I know how useful WayFinder was coming from MODx myself, but familiarising myself with the head.inc template file also helped me to learn the basics and I was off into the advanced stuff in no time. That's not to knock Soma's module by any means as it's a good, quick way of getting navigation up and running quickly, but rather saying that PW is really easy to customise to do what you want with a fairly easy learning curve compared to full-blown PHP development.
  22. So is there no way when you click Save on a page to have a module access the page's field contents as they were before you hit Save or are you saying that even before save the copy of that page in the memory would be the new one even if it's not saved yet? Surely the old copy in the database should be accessible somehow since we're hookig before page save without the need to clone it? Literally all I want to do is compare the value of a field before the person hit Save and what the value is after they click Save by using a beforePageSave hook if that makes sense.
  23. Just a very quick one from me on the subject - I do love the idea of pulling together emails using content from other pages and templates - simply have a basic template with an introduction field, then a latest news PageField that can select multiple pages and use their contnt, then maybe another text box and so on... you're limited only by your imagination here! What I wouldn't then do is send the email from my own server, due to the blacklisting reasons ffub mentions above. It's a right pain in the arse to get yourself de-listed and all it takes is for a few users to click "Junk" instead of "Trash" (that was an issue years ago so I hope most free email providers have clarified their terminology by now) and you'll be fighting an uphill battle in no time, which is never fun. What I would do personally is use PW to pull together the content and then use a service that allows you to import contents via the API. I know MailChimp can do that and with a basic shell template in the dedicated email service, I don't see why you shouldn't be able to then just inject the HTML you've created from your template in PW into something like MailChimp. Then you have the best of both worlds. And a slight headache from programming a module to shunt the parsed email contents over to the email service, but worth it in the long run You could really go to town with the programming if you wanted to and simply never have your user see the 3rd party interface - I know the MailChimp API lets you pull subscriber lists and stats, and activity reports etc - I find their interface confusing so it would be great to just pull in the information you need. And all of this under its own tab in the PW admin. Well, I can dream can't I? I do like the idea of sending email and handling it all from within PW but I've just had too many bad experiences with subscribers accidentally/intentionally getting a server blacklisted.
  24. Is it possible to do this inside a module? I tried before page save to get the page using something like $previousVersion = wire('pages')->get($page->id); but that didn't work (and certainly wouldn't work after page save ). It's probably something simple like $_POST vars I bet, but just wanted to check.
  25. I think I'm going to use the two template approach on one site just because it's a reasonably complicated layout and is quite image-heavy when you get into the articles. That way I can serve up a mobile-optimised layout with much smaller images. Just got to finish the normal site first
×
×
  • Create New...