Jump to content

Soma

Moderators
  • Posts

    6,798
  • Joined

  • Last visited

  • Days Won

    158

Everything posted by Soma

  1. Looking at your code, yes. Because ->get() will always get only 1 page and 6 random images from that page. Ryan's example won't do that because it uses ->find() and returns 6 random pages everytime. As I said it's not exactly the same, of course it depends a lot how many pages and images you have. But going with a case of 20+ pages with ~20 images each will work as good. Considering having 10000+ pages with each ~20 images, Ryans example would work still as good, but grabing all pages and images will most likely end in a out of memory.
  2. I think you're looking for something that isn't really there the way you maybe think. To my mind comes, that you could simply create a custom admin page and just output a markup table that list's all unpublished pages. There must be some thread about it with more examples how to create custom cp admin pages. Example: Create a new page under the Admin tree. Select the "admin" template and give it a title. After saving and publishing it will appear in the top navigation. If you go to the newly created admin page it will output "This page has no Process assigned." You then need to create a new Process Module. That Process Module would basicly look like this: (this is a quickly stripped example from a module I did a while ago) <?php /* * ProcessWire Module * Simple Example admin page Process module to output unpublished pages * * Put this module into you /site/modules folder * Create new admin page using "admin" template and assign this Process module * */ class ProcessUnpublishedList extends Process { protected $sel_unpublished = 'sort=-modified, status=unpublished'; public static function getModuleInfo() { return array( 'title' => 'Process Unpublished List', 'summary' => 'Show unpublished pages in the admin', 'version' => 100, 'permission' => 'page-edit' // or any other permission to manage access to this admin page ); } public function ___execute() { $out = ''; $fieldset = $this->modules->get("InputfieldFieldset"); $field = $this->modules->get("InputfieldMarkup"); $field->label = "Unpublished Pages"; $field->collapsed = Inputfield::collapsedNo; $table = $this->modules->get('MarkupAdminDataTable'); $table->setSortable(false); $table->setEncodeEntities(false); $header = array('Title','Status','modified','by user'); $table->headerRow($header); $rows = array(); $pageArr = $this->pages->find($this->sel_unpublished); foreach($pageArr as $p){ $status = ''; $status = $p->is(Page::statusUnpublished) ? "unpublished" : ''; $editUrl = "{$this->config->urls->admin}page/edit/?id={$p->id}"; $rows[] = $p->editable() ? "<a href='{$editUrl}' style='opacity:0.7'><s>".$p->get('title|name|id').'</s></a>' : $p->get('title|name|id'); $rows[] = $status; $rows[] = date('Y.m.d H:i:s',$p->modified); $rows[] = $p->modifiedUser->name; $table->row($rows); $rows = null; } $field->value = $table->render(); $fieldset->add($field); $out .= $fieldset->render(); return $out; } /** * example * accessing /processwire/adminpage_with_this_module/list2/ * will map to this function */ public function ___executeList2(){ $out = "List2"; return $out; } } Edit: This example shows that you can use certain processwire modules to create fieldsets or a MarkupAdminDataTable to generate markup. This is how PW itself does build all the admin pages pretty much. But you can also just create your own simple html markup and output that.
  3. I would guess that you're assets css and images arent loading because you installed PW in a subdirectory. When you include PW into codeigniter controller the page render output the markup but the paths are screwed. You need to either install PW in the root same as application and system (in case of codeigniter) but that may create problems, or leave it in a subdirectory and somehow fix the paths with htaccess vodoo. I don't really know the answer and what would be best in this case.
  4. You can use a WireArray and fill it with image objects from pages. Then get a random count from that WireArray. It's also in the cheatsheet. // new WireArray object for storing images $images = new WireArray(); // we find all pages using a specific template that have at least 1 or more images. // assumes the image field is named "myimages". If we deal with really lots of pages/images, consider using a limit to avoid performance problems $pa = $pages->find("myimages.count>0, template=basic-page, sort=random, limit=10"); // loop all found pages and import the images to the $images object foreach($pa as $p){ $images->import($p->myimages); } // output 4 random images from the wire array foreach($images->getRandom(4) as $img){ echo "<img src='{$img->url}'/><br/>"; } Reading again, and looking at Ryans code, it does pretty much the same, just little different way. Think about it again... Is there really any difference ? From: get ALL images from ALL pages and choose 6 random from them. To: get randomly 6 pages from ALL pages and choose 1 randomly from each page. I don't see really a difference, only that the second is far better and the way to go, because you limit the find for pages in the first place. Getting all images from all pages could create problems and not so scalable.
  5. http://processwire.com/api/modules/markup-pager-nav/ you may want to read this again. It says any limit greater than n=1.
  6. How about markup cache? Edit: Apart from that. Your initial thought about going from the referenced_pages side would make sense. Cycle all pages and check if any children found then add it and break. I just thought if you're going to use it as a list on page, why not use simple API, cache the markup and only rebuild it every hour. Of course you can't beat raw sql but I think at some point (page count) you anyway want use a cache.
  7. Direction: $events = $page->siblings->remove($page)->find("limit=3");
  8. I agree that it is somehow annoying. Not a major problem but when entering "s" it gets transfered to the page name, but the autocomplete doesn't. Wouldn't it be easy to add a on change event instead of keyup? I think that would work.
  9. I thought it is already like this. Not whole page (fields) are in memory unless you need request it.
  10. you can also use if($page->images->first()) ...
  11. Works with many to many too. $prs = $pages->find("title=Zoo|Theme park|Museum"); // maybe also use the name or id $poi = $pages->find("template=poi, poi_type=$prs"); EDIT: corrected code. yours doesn't work because "get" will return only 1 page and not page array.
  12. $pr = $pages->get("title=Zoo"); $poi = $pages->find("template=poi, poi_type=$pr");
  13. Do try a table repair... (could be) Adit: - or try opening a childpage and change something and save it. - or sort the last page to first place Also try trace 1 page (id) in the db table where the sort field is. Before and after you sort change one page in the admin, what happens in the db table? Does it change anything?
  14. It seems when there's a "'" in the string any "," gets stripped out. I also tested this just to confirm.
  15. Hi jamienk and welcome! I can't reproduce your issue with $page->image->url/path. They still work as expected in latest PW. I don't see what could be wrong with your code, just confirming that it works. Edit: Either your page or most likely field "images" doesn't seem to exists/work in your created page.
  16. With siblings, since it also returns always the page itself (where it is called), $page->siblings will always return at least one page object. SO you would have to check if the count is greater than 1. Not? In this case, you would do something like this to check if the current page has any siblings. if( count ( $page->siblings ) ) > 1 ) { ... } An alternative would be to use the count method for Page Array in PW. if( $page->siblings->count() > 1 ) { ... } As for checking if a field is empty. The if condition works with different return values type false|0|null|empty as false. So if something returns 1 or more it will be true. Usually a if($page->field) will work with textfield and also checkbox (0=not selected or 1 selected) and more. To check if a field exists is a little different. It won't trow an error if the field doesn't exists in a if condition in PW. Also this is not something you'll be doing most of the time but you still can. php isset will return 1 if the property exists (even if empty) in the page object. if( isset( $page->field ) ){ ... }
  17. I think Ryan means, you can add a page reference field to the user template. Then select the properties you want the user to view. Using that reference you check in the template if the user has the property in the page reference selected and show something or not.
  18. I just popped in, and it was easy. Glad I could help you.
  19. Try this count($entry->comment) or maybe this will work too $entry->comment->count(); $entry->comment.count definately doesn't, and returns the toString method of the object which is the id's comma separated I would guess.
  20. Since repeaters (pages) are in the admin section hidden. You could exlude them by id of the admin page. $p = $pages->get($id); if($p->isHidden() || $p->rootParent->id == 2) $session->redirect($pages->get($config->http404PageID)->url) else $session->redirect($p->url);; I think if you want to exlude other branches you could try something like this. $p = $pages->get($id); if($p->isHidden() || $p->is("has_parent=2|10|1033")) $session->redirect($pages->get($config->http404PageID)->url); else $session->redirect($p->url); NOt really tested but let me know if it doesn't work out.
  21. Ah so you're trying to have an id permalink to pages (shortcut). I'm not sure if this woud help but this is how I would solve it. Normally you would setup your tree to have pages that will be in the navigation, and set pages not in navigation to hidden. From there it would just be a simple check to see if the page (id) requested is not hidden. 
 if(!$pages->get($id)->isHidden()) $session->redirect($pages->get($id)->url); else $session->redirect($pages->get($config->http404PageID)->url); Or you could add a field (checkbox) "not_permalink", and give that to templates you need. You could use it for single pages, or just the parent of a branch. So all children pages will either be shown or not. 
 if(!$pages->get($id)->parents->has("not_permalink=1") || $pages->get($id)->not_permalink == 0) $session->redirect($pages->get($id)->url); else $session->redirect($pages->get($config->http404PageID)->url); It depend a lot how you setup you page tree and how you make them appear in your navigation, but I'm sure you'll find a very simple solution. I think it can be as simple as a 2 line code and no module would be required.
  22. Glad you figured it out somehow. Yes I also thought something like this it could work getting only the ids. But this module is usually used for markup generation. I still don't understand completely what you're trying to do though, you could try this: $options = array( 'outer_tpl' => '', 'inner_tpl' => '', 'list_tpl' => '{id} ', 'item_tpl' => '', 'item_current_tpl' => '' ); $array_ids = explode(" ",trim($nav->render($options));
  23. varvanin, I think the $child_title is not translated because there's no translation for those subpages. I think one way would be to add translation in the default.php like it's done for the main admin pages: * __("Pages"); * __("Setup"); * __("Modules"); * __("Access"); * __("Admin"); So it can be added though the default.php, and the topnav.inc will get it from there. I don't know if there's another way. Ryan?
  24. No, when clicking add new, on the screen where you enter the title in the title on top. I'm running quite latest PW from 1-2 weeks ago.
×
×
  • Create New...