Jump to content

Pete

Administrators
  • Posts

    4,049
  • Joined

  • Last visited

  • Days Won

    67

Everything posted by Pete

  1. Cheers ryan - I'll do some more tinkering, but it sounds like these should work if I can get my code working. The code you just posted to detect previous parent - is the previous parent saved somewhere in the db then after a page is moved, or is this info available just before the page is saved? Just curious.
  2. The functions in wire/core/Pages.php are: find save saveField trash restore delete So I guess Restore is going to be the one used when moving a page out of the trash - that's one thing potentially solved at least.
  3. Hehe, now I have the problem of when a page is moved to trash in the main Pages list rather than via the page editor itself my module won't run. Same problem if I empty the trash from that main page list. I'll have a look for hooks for those later on
  4. Just a quick question - would this even affect your SEO? I would have thought that either way either link would take you to the same place so it shouldn't affect SEO. I might be wrong though - entirely possible
  5. Oops - it's an obvious issue in my code that I worked out this morning before I even switched my PC on. More late night tiredness getting in the way If it's in the trash, it's no longer relevant to check the page's parent - it's no longer under the news page instead I really should be checking for the page template ('news' in this case) so it doesn't matter where the page is on the site. I'm getting there and learning the system as I go. Hopefully tonight I'll have a more comprehensive module because of this.
  6. Just for info I've got this all working now. The process goes something like this: 1) Before a page is saved, we check if it's published using if ($page->status >= Page::statusUnpublished) { 2) If not, then we don't need to create a news topic in the forums as the page is obviously brand new and not visible on the site yet, but we should update the forum topic if there is one (checks hidden news_topic_id field in the template, then updates the forum topic if there is an ID in that field) 2) If page is published, check there's a topic id in the news_topic_id field - if not, create one and if there is update the topic 3) If a page is deleted (to the trash) then remove the forum topic if there is one Now, I ended up using the trash function instead of the delete function purely because I couldn't figure out how to run my module when the trash is emptied. Any suggestions on how I might convert this to run the module and execute the code below when the trash is emptied instead of a page being moved to the trash? Here's my hook for when a page is saved and it's moved to the trash: $this->pages->addHookBefore('trash', $this, 'deleteNewsTopic'); and here's my function that that calls: public function deleteNewsTopic($event) { $page = $event->arguments[0]; // Check it's a news article if ($page->parent_id == 5831) { require_once('IPBWI/ipbwi.inc.php'); if (!empty($page->news_topic)) { $ipbwi->topic->delete($page->news_topic); } } } There's other code in there too, but this is just the few snippets for this particular part I tried changing 'trash' to 'delete' in the hook, but that doesn't work - probably because you're not viewing a page when you empty the trash... but I'm not sure how you would add a hook to the actual act of emptying the trash (and presumably then there would have to be code iterating through the pages being deleted, checking the parent ID for the relevant page parent (5831 above is a page called "news" and I bet there's an easier way to do that than remembering the page ID ), then checking the news_topic_id field and deleting topics from the forums as necessary. Other than that the complete module I've got works perfectly and with so few lines of code too!
  7. Hi ryan Thanks for that - I changed it to saving before and it worked. I think I was just suffering from late night coding tiredness and not seeing the rather obvious source of the recursion. 'Exit' was just there for debugging, though to be honest I could just have easily printed the message as per the code in the Hello World module - something I realised this morning. Thanks for the info on the size of those sites. I knew they were big but it's hard at a glance to see exactly how big. I've not got any large (I'm with you in considering those large ) sites to develop yet - StrategyCore is only a few hundred pages at most at the moment - but I do have a few projects in mind that I'll move onto later this year that could potentially have a few thousand pages eventually so those figures are good to know. Thanks as well for the info on that markup caching module. I was going to ask about that as some parts of a page will change very rarely. Does that list on the Villa rental site update itself after a new page is added that would affect it then, or is it literally only once a day? To my mind it would be useful if a page save could trigger rebuilding a list and re-caching that part of the template, but I'm not sure if it's possible now or easy to implement if it's not.
  8. In fact - thanks apeisa! Changing it to before the page is saved works perfectly!
  9. Thanks all - seems more obvious this morning than at 11.30pm last night Is there a way to just save that specific field for that page then instead of saving the entire page, as that's all I need to really do? That way I could still run the code on page save. Thanks SINNUT - I thought I'd seen it somewhere but thought I might have imagined it. Very useful feature - in my MODx sites all I end up with is an ever-expanding list of pages in the admin with no pagination and it gets messy quickly so this is an awesome feature.
  10. Just running into a bit of trouble saving my page content via this module. I've set it to only run the module if the page's parent is the news page and with xDegug turned on on my XAMPP server it says it's stuck in a loop (without xDebug on it just crashes Apache). Here's a very stripped-down version of my module with the issue: <?php /** * ProcessWire 'Hello world' demonstration module * * Demonstrates the Module interface and how to add hooks. * * ProcessWire 2.x * Copyright (C) 2010 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class Newstopic extends WireData implements Module { /** * getModuleInfo is a module required by all modules to tell ProcessWire about them * * @return array * */ public static function getModuleInfo() { return array( // The module's title, typically a little more descriptive than the class name 'title' => 'News Topic Create', // version: major, minor, revision, i.e. 100 = 1.0.0 'version' => 100, // summary is brief description of what this module is 'summary' => 'Creates a topic for each new news article that is saved. Checks none exists currently.', // Optional URL to more information about the module 'href' => 'http://www', // singular=true: indicates that only one instance of the module is allowed. // This is usually what you want for modules that attach hooks. 'singular' => true, // autoload=true: indicates the module should be started with ProcessWire. // This is necessary for any modules that attach runtime hooks, otherwise those // hooks won't get attached unless some other code calls the module on it's own. // Note that autoload modules are almost always also 'singular' (seen above). 'autoload' => true, ); } /** * Initialize the module * * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. * */ public function init() { // add a hook after the $pages->save, to issue a notice every time a page is saved $this->pages->addHookAfter('save', $this, 'createNewsTopic'); // add a hook after each page is rendered and modify the output //$this->addHookAfter('Page::render', $this, 'example2'); // add a 'hello' method to every page that returns "Hello World" //$this->addHook('Page::hello', $this, 'example3'); // add a 'hello_world' property to every page that returns "Hello [user]" //$this->addHookProperty('Page::hello_world', $this, 'example4'); } /** * Example1 hooks into the pages->save method and displays a notice every time a page is saved * */ public function createNewsTopic($event) { $page = $event->arguments[0]; // Check it's a news article if ($page->parent_id == 5831) { // If the hidden news_topic field for this article is empty, then we'll create a topic if (empty($page->news_topic)) { echo "It's empty"; $page->news_topic = 123; } else { echo "It's got a value"; $page->news_topic = ''; $page->save(); } exit; //$this->message("Hello World! You saved {$page->path}."); } } } and here's the debug info from xDebug: ( ! ) Fatal error: Maximum function nesting level of '100' reached, aborting! in C:\xampp\htdocs\sc11\wire\core\Wire.php on line 229 Call Stack # Time Memory Function Location 1 0.0035 392416 {main}( ) ..\index.php:0 2 0.2985 7064064 ProcessPageView->execute( ) ..\index.php:170 3 0.2985 7064216 Wire->__call( ) ..\Wire.php:0 4 0.2985 7064216 Wire->runHooks( ) ..\Wire.php:229 5 0.2985 7065264 call_user_func_array ( ) ..\Wire.php:267 6 0.2985 7065400 ProcessPageView->___execute( ) ..\Wire.php:0 7 0.3080 7109160 Page->render( ) ..\ProcessPageView.module:73 8 0.3080 7109312 Wire->__call( ) ..\Wire.php:0 9 0.3080 7109312 Wire->runHooks( ) ..\Wire.php:229 10 0.3082 7112336 PageRender->renderPage( ) ..\Wire.php:289 11 0.3082 7112536 Wire->__call( ) ..\Wire.php:0 12 0.3082 7112536 Wire->runHooks( ) ..\Wire.php:229 13 0.3082 7113584 call_user_func_array ( ) ..\Wire.php:267 14 0.3082 7113768 PageRender->___renderPage( ) ..\Wire.php:0 15 0.3102 7157328 TemplateFile->render( ) ..\PageRender.module:194 16 0.3102 7157480 Wire->__call( ) ..\Wire.php:0 17 0.3102 7157480 Wire->runHooks( ) ..\Wire.php:229 18 0.3103 7158528 call_user_func_array ( ) ..\Wire.php:267 19 0.3103 7158664 TemplateFile->___render( ) ..\Wire.php:0 20 0.3117 7204976 require( 'C:\xampp\htdocs\sc11\site\templates\admin.php' ) ..\TemplateFile.php:88 21 0.3122 7206648 require( 'C:\xampp\htdocs\sc11\wire\templates-admin\controller.php' ) ..\admin.php:13 22 0.3130 7239504 require( 'C:\xampp\htdocs\sc11\wire\core\admin.php' ) ..\controller.php:13 23 0.3264 7437216 ProcessController->execute( ) ..\admin.php:42 24 0.3264 7437368 Wire->__call( ) ..\Wire.php:0 25 0.3264 7437368 Wire->runHooks( ) ..\Wire.php:229 26 0.3265 7438416 call_user_func_array ( ) ..\Wire.php:267 27 0.3265 7438552 ProcessController->___execute( ) ..\Wire.php:0 28 0.3436 8017272 ProcessPageEdit->execute( ) ..\ProcessController.php:194 29 0.3436 8017424 Wire->__call( ) ..\Wire.php:0 30 0.3437 8017424 Wire->runHooks( ) ..\Wire.php:229 31 0.3437 8018472 call_user_func_array ( ) ..\Wire.php:267 32 0.3437 8018608 ProcessPageEdit->___execute( ) ..\Wire.php:0 33 0.4291 9419280 ProcessPageEdit->processSave( ) ..\ProcessPageEdit.module:94 34 0.4475 9558616 Page->save( ) ..\ProcessPageEdit.module:160 35 0.4475 9558784 Pages->save( ) ..\Page.php:791 36 0.4475 9558984 Wire->__call( ) ..\Wire.php:0 37 0.4475 9558984 Wire->runHooks( ) ..\Wire.php:229 38 0.4509 9545040 Newstopic->createNewsTopic( ) ..\Wire.php:289 39 0.6296 23635104 Page->save( ) ..\Newstopic.module:103 40 0.6296 23635272 Pages->save( ) ..\Page.php:791 41 0.6296 23635472 Wire->__call( ) ..\Wire.php:0 42 0.6296 23635472 Wire->runHooks( ) ..\Wire.php:229 43 0.6352 23644064 Newstopic->createNewsTopic( ) ..\Wire.php:289 44 0.6370 23644512 Page->save( ) ..\Newstopic.module:103 45 0.6370 23644680 Pages->save( ) ..\Page.php:791 46 0.6370 23644880 Wire->__call( ) ..\Wire.php:0 47 0.6370 23644880 Wire->runHooks( ) ..\Wire.php:229 48 0.6392 23648016 Newstopic->createNewsTopic( ) ..\Wire.php:289 49 0.6400 23648136 Page->save( ) ..\Newstopic.module:103 50 0.6400 23648304 Pages->save( ) ..\Page.php:791 51 0.6400 23648504 Wire->__call( ) ..\Wire.php:0 52 0.6400 23648504 Wire->runHooks( ) ..\Wire.php:229 53 0.6425 23651408 Newstopic->createNewsTopic( ) ..\Wire.php:289 54 0.6441 23651856 Page->save( ) ..\Newstopic.module:103 55 0.6441 23652024 Pages->save( ) ..\Page.php:791 56 0.6441 23652224 Wire->__call( ) ..\Wire.php:0 57 0.6441 23652224 Wire->runHooks( ) ..\Wire.php:229 58 0.6461 23655296 Newstopic->createNewsTopic( ) ..\Wire.php:289 59 0.6468 23655416 Page->save( ) ..\Newstopic.module:103 60 0.6468 23655584 Pages->save( ) ..\Page.php:791 61 0.6468 23655784 Wire->__call( ) ..\Wire.php:0 62 0.6468 23655784 Wire->runHooks( ) ..\Wire.php:229 63 0.6487 23658696 Newstopic->createNewsTopic( ) ..\Wire.php:289 64 0.6502 23659144 Page->save( ) ..\Newstopic.module:103 65 0.6503 23659312 Pages->save( ) ..\Page.php:791 66 0.6503 23659512 Wire->__call( ) ..\Wire.php:0 67 0.6503 23659512 Wire->runHooks( ) ..\Wire.php:229 68 0.6522 23662584 Newstopic->createNewsTopic( ) ..\Wire.php:289 69 0.6530 23662704 Page->save( ) ..\Newstopic.module:103 70 0.6530 23662872 Pages->save( ) ..\Page.php:791 71 0.6530 23663072 Wire->__call( ) ..\Wire.php:0 72 0.6530 23663072 Wire->runHooks( ) ..\Wire.php:229 73 0.6551 23665984 Newstopic->createNewsTopic( ) ..\Wire.php:289 74 0.6567 23666432 Page->save( ) ..\Newstopic.module:103 75 0.6567 23666600 Pages->save( ) ..\Page.php:791 76 0.6567 23666800 Wire->__call( ) ..\Wire.php:0 77 0.6567 23666800 Wire->runHooks( ) ..\Wire.php:229 78 0.6586 23669872 Newstopic->createNewsTopic( ) ..\Wire.php:289 79 0.6593 23669992 Page->save( ) ..\Newstopic.module:103 80 0.6593 23670160 Pages->save( ) ..\Page.php:791 81 0.6593 23670360 Wire->__call( ) ..\Wire.php:0 82 0.6593 23670360 Wire->runHooks( ) ..\Wire.php:229 83 0.6593 23671432 call_user_func_array ( ) ..\Wire.php:267 84 0.6593 23671616 Pages->___save( ) ..\Wire.php:0 85 0.6604 23673256 FieldtypeInteger->savePageField( ) ..\Pages.php:421 86 0.6604 23673504 Wire->__call( ) ..\Wire.php:0 87 0.6604 23673504 Wire->runHooks( ) ..\Wire.php:229 88 0.6604 23674560 call_user_func_array ( ) ..\Wire.php:267 89 0.6604 23674792 Fieldtype->___savePageField( ) ..\Wire.php:0 90 0.6605 23674952 FieldtypeInteger->deletePageField( ) ..\Fieldtype.php:504 91 0.6605 23675200 Wire->__call( ) ..\Wire.php:0 92 0.6605 23675200 Wire->runHooks( ) ..\Wire.php:229 93 0.6605 23676256 call_user_func_array ( ) ..\Wire.php:267 94 0.6606 23676488 Fieldtype->___deletePageField( ) ..\Wire.php:0 95 0.6606 23676520 WireData->__unset( ) ..\Data.php:0 96 0.6606 23676520 WireData->remove( ) ..\Data.php:169 97 0.6606 23676480 Wire->trackChange( ) ..\Data.php:133 98 0.6606 23676632 Page->changed( ) ..\Wire.php:504 99 0.6606 23676832 Wire->__call( ) ..\Wire.php:0 This error message was shown because the site is in DEBUG mode. Any ideas why it might be going crazy nesting functions like that?
  11. Just a quick one for ryan - how well does PW scale? What's the most amount of pages you've had on a site and how do you cope in the admin when you get 200 sub-pages in a News section for example (is there pagination in the admin page tree? That would be awesome and I suspect I've seen it already this week and that's why it's popped into my head).
  12. Cheers guys - this is my first foray into modules and the API and it's proving to be very intuitive. I'm happily testing if a hidden field that I'll store my forum topic ID in is empty - if it is then fire up the PHP class to create a topic in the forums, get that topic ID and save the ID to the hidden field. It's nearly done, and I just want to do some other things like check if the page is published (on publish it should create the forum topic, then if it's unpublished for any reason it should hide the forum topic, and if the page is deleted then delete the topic). The joy of working on something based off jQuery's way of doing things is that I also don't have to think too hard about how to do things either - the majority of the time tonight it's been pretty straightfoward
  13. Wow - I didn't realise it would be so simple! Thanks again!
  14. Hi folks Is there any way to run some external PHP code after a page is saved (or even have this as part of a module if that's easier?). The scenario is this - I'd like news articles for a site to be entered into PW. I'd like comments for the news articles to be posted in a forum. I've got PW for the news side of things, the forum software for the commenting, and I've also got a lovely PHP class available with lots of nifty functions including the ability to create a new topic in a news forum on the site. This PHP class also gives me the ability to pull replies to a topic so that in my PW template for news articles I could list anything from the number of replies to a full-blown list of replies like you see in a blog. What I need to do is somehow run some code after a page is saved (lets assume I've got a News page and all pages under it are news articles - makes sense ), that would then allow me to use this PHP class to check if a topic exists for this news article and, if not, create one for me. Since I know the PHP class pretty well, the only thing I'm unsure of is how to run some code after a page save. What would also be nice, but less essential right now, is the ability to run another bit of code after a page is deleted so that if a news article is removed then the related topic in the forums is also removed.
  15. Funnily enough I was thinking of doing something just like what you mentioned in those examples - Publisher and Developer lists could be quite useful and another easy source of content for search engines to lap up as you say, but I'd probably filter out Current Rights Holder as it only makes sense in the context of a specific game. I guess this would be easy enough to do simply by hiding the page or using ! somewhere in the parameters for find()? Oh, and thanks again for the very helpful examples - much appreciated!
  16. Ooookay, now I've actually tried the examples posted above I love the way you guys have suggested to do it. Much quicker, if a little weird at first and more straightforward for lists that might have to be added to in future by non-programmers.
  17. I guess what I'd like to see is a variation on the Fieldtype Select module that allows multi-select or checkboxes when you set the field up: http://processwire.com/talk/index.php/topic,245.msg1426.html#msg1426 However I'd have no clue how to achieve this - I'll look into the Fieldtype Select module later tonight and see if I can modify it a bit
  18. Thanks guys. This will work fine, however it does seem rather overkill in situations calling for very small groups of fields like this. This way there are 3 entries in the database instead of 1. I know it's not the end of the world and that the query will doubtless run just as fast, however it seems a little counterintuitive to have them as pages in the backend at all. On the other hand, it makes the list easier to add to if required which would be good in a lot of cases, but less so in this case as it's a set list that will never change. It just feels a bit weird is all
  19. Hi folks I've been busycreating fields I have for a MODx site so that I can begin moving the site over to PW. For the most part this has been made straightforward by how simple PW is. There's one field I'm having trouble working out how to do though - it's a checkbox group called Type where there are multiple checkboxes you can tick - see the highlighted field in the attached image. Is it possible to have a checkbox group, or a multiple select list? I see there's the option for field groups, but this doesn't seem to be exactly the same - I think in the attached example MODx would save the selected text boxes as a comma separated list - arguably less useful than 3 separate fields (I'd argue that it is useful as you can use mySQL's IN() statement to see if a value is in a comma separated list in the database).
  20. Oh right, I didn't realise the system was already as smart as that
  21. But surely the problem with doing the on the fly is that they're done every page load and affects the user's experience when browsing the site if a thumbnail is to be created on the fly as well? Or am I not understanding this correctly (far more likely ). I think the idea of a config setting where you can set options when creating the field could be the way to go.
  22. Pete

    Page IDs

    My pages started n the 5k's - looking at the database on a fresh install, page 40 is the guest page, then page 5802 is test-role. It just looked a bit of an odd point for the numbers to jump at. It's not really an issue, just looked a bit weird in the DB
  23. When I create a page in 2.1, then go back later on (because of a typo for instance) and go to the Settings tab to change the page name, it doesn't save my changes in PW 2.1.
  24. Just for info, this works and saves the dropdown if you use ryan's amended preg_match line in the module and you're interested in a key -> value dropdown list. One future improvement I'd like to see is if there could be a setting to force the user to select something from the list, otherwise the page will throw an error message when saved. There are plenty of times when you want something to be filled out and select lists are no different. Only trouble is I wouldn't know where to begin with that. Yet. I'm learning slowly but surely
  25. Pete

    Page IDs

    This isn't a bug, but the page numbers in a PW 2.1 installation suddenly jump from low numbers to 5000-odd. I'm guessing you were testing it with lots of content at one point ryan and then didn't reset the auto_increment in the DB? Like I say, not a bug, but it is a weird jump in the numbers.
×
×
  • Create New...