Jump to content

adrian

PW-Moderators
  • Posts

    10,912
  • Joined

  • Last visited

  • Days Won

    349

Everything posted by adrian

  1. Thanks for this - looks like it has great potential, but at the moment, you have these errors: Warning: stripos() expects parameter 1 to be string, array given in /site/modules/FieldtypeImageExtra/FieldtypeImageExtra.module on line 229|230|231 which break the image upload due to outputting header content before the image during the ajax upload with PW debug set to true. There are also some layout issues if you disable the orientationField - the Link field only takes up half the page width. I had the same issues as Joss, but switching the field type did the trick!
  2. If anyone is getting this issue with images not properly uploading in PHP5.6, make sure to set: always_populate_raw_post_data to -1 in your php.ini file. The deprecated notice is causing header issues with the ajax uploader. Hope that helps someone else out
  3. That was my doing Martijn - since it's hooking into SaveReady, I thought that "Before" was actually appropriate in this case - it's certainly not renaming after save, otherwise we'd have to save again - right? I certainly don't see any harm in using the true option and I think it should generally be safer for page names and how you are generating them.
  4. Glad it's working, but I would suggest adding the "true" back into the pageName sanitizer. From the docs: "Sanitizes a value for a URL friendly Page name and cleans out leading or trailing dashes, and converts double dashes to single dashes. Use this if you are passing in a headline to convert to a page name (for example)."
  5. Try this: <?php /** * ProcessWire 'Rename Page' module by forum user creativejay * * Checks to see if a page uses the template "blog-post" and has a $p->blog_categories value of "Swatch" then redefines the value of $p->title and $p->name * * * ProcessWire 2.x * Copyright (C) 2014 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://processwire.com * */ class RenamePage 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' => 'Rename Page', // version number 'version' => 3, // summary is brief description of what this module is 'summary' => 'Checks to see if a page uses the template blog-post and has a blog_categories value of Swatch then redefines the value of title and name', // Optional URL to more information about the module 'href' => 'https://processwire.com/talk/topic/8863-new-to-hooks-trying-to-wrap-my-head-around-the-syntax/', // 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, // Optional font-awesome icon name, minus the 'fa-' part 'icon' => 'eraser', ); } public function init() { $this->addHookAfter('Pages::saveReady', $this, 'renameBeforeSave'); } public function renameBeforeSave(HookEvent $event) { $p = $event->arguments[0]; if($p->template->name === "blog_post" && $p->blog_categories == "Swatches"){ $concatenatedName = $p->blog_date; $concatenatedName .= '-' . $p->createdUser; $concatenatedName .= '-' . $p->blog_brand; $concatenatedName .= '-' . $p->blog_name; $concatenatedTitle = $p->blog_brand; $concatenatedTitle .= ' ' . $p->blog_name; $p->title = $concatenatedTitle; $p->name = $sanitizer->pageName($concatenatedName, true); } } }
  6. Yeah, looks like my comment about that crossed with your correction
  7. Very good advice from soma (as always). This is what I usually do: $this->addHookAfter('Pages::saveReady', $this, 'renameBeforeSave'); public function renameBeforeSave(HookEvent $event) { $p = $event->arguments[0]; $p->name = $new_name; $event->return = $p; // maybe this isn't actually needed - haven't tested and can't remember //as soma mentioned - this last line definitely isn't needed! } Of course you'll need to add in your logic to limit by template/category and to build up the new name/title.
  8. Nice idea, but I would personally go for a dedicated table for this. Perhaps you could steal some ideas from teppo's ChangeLog module: http://modules.processwire.com/modules/process-changelog/
  9. In the "Extra Allowed Content" section on the Input tab of your field's settings, add the following: span{!color} That will allow span tags so long as the color style attribute is set. You can get more details here: http://docs.ckeditor.com/#!/guide/dev_allowed_content_rules-section-2 If you want to allow span tags no matter what attributes they have, then use this: span[*]{*}(*)
  10. Firstly, if var_dump($page->verein_datum); returns int(1397253600) then the field is not blank - it is set to: Fri, 11 Apr 2014 22:00:00 GMT If it is actually empty, it is as simple as: if(!$page->verein_datum) { //date field is empty } but if you want, you could also do: if(empty($page->verein_datum)) { //date field is empty } or if($page->verein_datum === '') { //date field is empty }
  11. Looks like Ryan is already onto this - maybe you should hold off for a day or two: https://github.com/ryancramerdesign/ProcessWire/commit/bd16deaf8f9e690fc47e91766e479550042eea5d Maybe also keep an eye on CSV import module (http://modules.processwire.com/modules/import-pages-csv/) to see when that gets updated, or maybe it will work already with those core mods in that recent commit - not sure!
  12. I didn't have to do much - I really just fixed those issues you were having with the Edit Imported Content option when removing the images field. Also a little code to not rewrite the image tags and links in the RTE field if the images are not actually migrated across (because the images field wasn't included). You have already contributed significantly by adding comments support for MigratorWordpress! General PW ideas can be posted in the Wishlist board - I think this is likely the best place for module ideas too, but maybe also in the "Module/Plugin Development" sub-board?
  13. The - vs _ is coming from the fact that the module makes use of $sanitizer->fieldName to convert the entered Label for the template into its name. fieldName doesn't allow dashes. I have committed a fix that should solve the mistake. Please let me know how it works for you now. As for the custom templates - it is really situation dependent, but I like it so that I can restrict the creation of new child pages to just one template so the site editors never have to choose the appropriate template when creating a new child page option.
  14. That last update to Migrator that we have been discussing handles your desire to NOT migrate images, but rather point to the original source. If you need to do this until you can upgrade the server and then migrate the images, I am sure it wouldn't be too hard to steal some of the code from Migrator (in the idImagePath() function) to iterate through all the pages, download the images, and edit the links in the RTE fields. Let me know if you need any help with that when the time comes.
  15. It shouldn't be possible - is one basic-page and the other basic_page ? Generally it is safer (although not always necessary) to have dedicated templates for the page tree of a pagefield. If the module is in fact creating duplicate templates, then that is something I need to fix for sure.
  16. Here's another version that deals with the pagination issue you were getting. The problem is that it requires making a core method hookable that currently isn't. Obviously modifying the core is not a good idea and I am not sure that Ryan will want to make numChildren hookable - seems like a weird thing to want to change. I feel like there is a better option to achieve this, but as a proof of concept, this does work. If it works as expected for you, maybe I'll see if we can get Ryan's thoughts on this. So the first thing you need to do is go to wire/core/Page.php and make the numChildren function hookable by adding three underscores at the start, like: public function ___numChildren($selector = null) { Then use this module code: <?php /** * * * 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 HideOtherUserPages extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'HideOtherUserPages', 'author' => 'Adrian Jones', 'version' => 1, 'singular' => true, 'autoload' => true ); } public function init() { // only add hook only if the render parameter is set // (as used by ProcessPageList) // or if superuser, also exit //if(!isset($_GET['render']) || $this->user->isSuperuser()) return; if(!isset($_GET['render'])) return; $this->addHookAfter('ProcessPageList::find', $this, 'pageListHiddenPages'); $this->addHookAfter('Page::numChildren', $this, 'pageListCountPages'); } public function pageListCountPages(HookEvent $event){ $page = $event->object; $i = 0; foreach($page->children() as $p) { if($page->name != 'visitenkarte') continue; if($p->name != $this->user->name) $i++; } $event->return = $event->return - $i; } public function pageListHiddenPages(HookEvent $event){ $pages = $event->return; // make sure it's an ajax request if($this->config->ajax){ // manipulate the json returned and remove any pages found from array foreach($pages as $p) { if($p->parent->name != 'visitenkarte') continue; if($p->name != $this->user->name) $pages->remove($p); } $event->return = $pages; } } }
  17. If the parent template settings are allowing pages with the parent template to have children with the child template and the child template settings are allowing creation of new pages under a parent page with the parent template, then it should all work fine. Sorry, that is a confusing sentence Regardless, it shouldn't matter whether all these pages and templates with created manually or with Page Field Select Creator. Any chance this site is live somewhere that I could log in and take a look for you? Otherwise, perhaps you could export the two templates for me so I can replicate things. You could do this via the built in Export functionality on the main templates page, or using Migrator (https://github.com/adrianbj/ProcessMigrator).
  18. Hi there - I am having trouble following exactly, but Page Field Select Creator sets up the templates for the pages it creates with a setting the "Can this template be used for new pages?" set to "No". This is intentional because I like the trees of pages used for my page fields to have unique parent and child templates. The other settings that are automatically set are to limit the children of the parent page template to just those of the created children. This enables the "Allow new pages to be created from field?" setting to work. I also don't usually allow more than one child template for a parent template as I think it can confuse site editors, but others may not agree here. Sorry, I am answering this in a hurry, but if you change the "Can this template be used for new pages?" to Yes, I think it should solve what you are looking for, although I am not convinced I have got the issue exactly right, despite you detailed explanation Just to clarify - you are using this module for create page fields, rather than general page trees? If you just want to create/edit page trees, check out Batch Child Editor.
  19. Just wanted to thank Sephiroth for helping out here. I am PM'ing with Manlio now and we'll get the template error sorted out, which should take care of everything else I think. Let's continue the rest of this conversation in the Migrator thread.
  20. @manlio - sorry for the rough first experience with Migrator - any chance you could PM me the zip package you are trying to import? @Septhiroth - good catch, and yes, PR's are always very welcome - thanks
  21. Ryan doesn't increase the point version number with every commit, so your best option is to subscribe to the dev RSS feed: https://github.com/ryancramerdesign/ProcessWire/commits/dev.atom
  22. Welcome to PW!! You pretty much had it $matches = $pages->find("somefield*={$page->title}"); $page is always the current page. You can't have spaces within each part of the selector, so I remove the spaces around: *= Remember that if you are "find"ing you will end up with an array of results, not just one, so you need to decide how to handle these. The usual approach is to foreach through them. So you would then: foreach($matches at $match){ echo "<li>{$match->title}</li>"; } or something along those lines.
  23. adrian

    Debugging tips

    I know this thread is old, but with the new Log viewer that Ryan just set up, I have started putting the following just before the body close tag (in main.inc or foot.inc or wherever needed so it is on all pages): if($user->isSuperuser()) echo '<iframe width="100%" height="200px" src="'.$config->urls->admin.'/setup/logs/view/debug/?modal=1"></iframe>'; Then whenever I need to log a variable or output of a function etc, I use the following in my template file: $log->save('debug', $problem_variable); If you need to output an array, json_encode is quite a nice solution: $log->save('debug', json_encode($array)); This will give you (as superuser) a panel showing the "debug" log output (which shows latest entries at the top) at the bottom of your site - very handy
  24. I didn't think about the pagination issue. I am not sure there is an easy fix for that with the current options for hooking into ProcessPageList Just out of interest though, here is a new version that uses ProcessPageList::find as the hook - it simplifies some things quite a lot, but still doesn't fix the pagination issue <?php /** * * * 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 HideOtherUserPages extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'HideOtherUserPages', 'author' => 'Adrian Jones', 'version' => 1, 'singular' => true, 'autoload' => true ); } public function init() { // only add hook only if the render parameter is set // (as used by ProcessPageList) // or if superuser, also exit if(!isset($_GET['render']) || $this->user->isSuperuser()) return; $this->addHookAfter('ProcessPageList::find', $this, 'pageListHiddenPages'); } public function pageListHiddenPages(HookEvent $event){ $pages = $event->return; // make sure it's an ajax request if($this->config->ajax){ // manipulate the json returned and remove any pages found from array foreach($pages as $p) { if($p->parent->name != 'visitenkarte') continue; if($p->name != $this->user->name) $pages->remove($p); } $event->return = $pages; } } }
  25. Glad it works as you want! If you remove that line, then you will hide all pages on your site, because there won't be any direct children of Home that match the name of the current user. One other useful variation you might want to experiment with would be to replace: if($c->name != $this->user->name) unset($json['children'][$key]); with: if($c->createdUser != $this->user) unset($json['children'][$key]); which would hide pages that weren't created by the current logged in user.
×
×
  • Create New...