/** * Output an RSS feed of recent comments when URL segment is 'rss' * */ function renderCommentsRSS($limit) { // selector to locate the comments we want $start = 0; $selector = "limit={$limit}, start={$start}, sort=-created, status>=" . Comment::statusApproved; // find the comments we want to output $comments = findComments($selector); $commentPages = new PageArray(); foreach ($comments as $comment) { $p = wire('pages')->get($comment->pages_id); if (!$p->id) { continue; } $p = clone $p; $p->comment_title = htmlentities($comment->cite, ENT_QUOTES, "UTF-8") . " reply to: " . $p->title; $p->comment_body = htmlentities($comment->text, ENT_QUOTES, "UTF-8"); $p->comment_date = $comment->created; $commentPages->add($p); } $rss = wire('modules')->get('MarkupRSS'); $rss->title = wire('pages')->get('/')->headline . ' - ' . wire('page')->get('headline|title'); $rss->itemTitleField = 'comment_title'; $rss->itemDescriptionField = 'comment_body'; $rss->itemDescriptionLength = 0; $rss->itemDateField = 'comment_date'; $rss->render($commentPages); }
/** * Given a group of pages, render a simple <ul> navigation * * This is here to demonstrate an example of a simple shared function. * Usage is completely optional. * * @param PageArray $items * */ function renderNav(PageArray $items) { if (!$items->count()) { return; } echo "<ul class='nav'>"; // cycle through all the items foreach ($items as $item) { // render markup for each navigation item as an <li> if ($item->id == wire('page')->id) { // if current item is the same as the page being viewed, add a "current" class to it echo "<li class='current'>"; } else { // otherwise just a regular list item echo "<li>"; } // markup for the link echo "<a href='{$item->url}'>{$item->title}</a> "; // if the item has summary text, include that too if ($item->summary) { echo "<div class='summary'>{$item->summary}</div>"; } // close the list item echo "</li>"; } echo "</ul>"; }
/** * Serves as a place to store and retrieve loaded skyscrapers that will be displayed in a google map. * * To add skyscrapers, pass in a PageArray of them. * To retrieve skyscreapers, pass in nothing and retrieve the returned value. * * @param null|PageArray $items Skyscraper pages to store * @return PageArray All Skyscraper pages stored so far * */ function mapSkyscrapers($items = null) { static $skyscrapers = null; if (is_null($skyscrapers)) { $skyscrapers = new PageArray(); } if (!is_null($items) && $items instanceof PageArray) { $skyscrapers->add($items); } return $skyscrapers; }
public static function buildArray($object_family_name) { switch ($object_family_name) { case "page": if (func_num_args() == 2) { $result = new PageArray(func_get_arg(1)); $result->get(); return $result; } else { $result = new PageArray(); $result->get(); return $result; } } }
function renderSitemapChildren(Page $page) { $out = ''; $newParents = new PageArray(); $children = $page->children; foreach ($children as $child) { $out .= renderSitemapPage($child); if ($child->numChildren) { $newParents->add($child); } else { wire('pages')->uncache($child); } } foreach ($newParents as $newParent) { $out .= renderSitemapChildren($newParent); wire('pages')->uncache($newParent); } return $out; }
/** * Get this user's permissions, optionally within the context of a Page * * Does not currently include page-add or page-create permissions. * * @param Page $page Optional page to check against * @return bool * */ public function getPermissions(Page $page = null) { if ($this->isSuperuser()) { return $this->fuel('permissions'); } $permissions = new PageArray(); $roles = $this->get('roles'); if (empty($roles)) { return $permissions; } foreach ($roles as $key => $role) { if ($page && !$page->hasAccessRole($role)) { continue; } foreach ($role->permissions as $permission) { if ($page && $permission->name == 'page-edit' && !in_array($role->id, $page->getAccessTemplate()->editRoles)) { continue; } $permissions->add($permission); } } return $permissions; }
/** * Remove pages from already-loaded PageArray aren't visible or accessible * * @param PageArray $items * @param string $includeMode Optional inclusion mode: * - 'hidden': Allow pages with 'hidden' status' * - 'unpublished': Allow pages with 'unpublished' or 'hidden' status * - 'all': Allow all pages (not much point in calling this method) * @return PageArray * */ protected function filterListable(PageArray $items, $includeMode = '') { if ($includeMode === 'all') { return $items; } $itemsAllowed = new PageArray(); foreach ($items as $item) { if ($includeMode === 'unpublished') { $allow = $item->status < Page::statusTrash; } else { if ($includeMode === 'hidden') { $allow = $item->status < Page::statusUnpublished; } else { $allow = $item->status < Page::statusHidden; } } if ($allow) { $allow = $item->listable(); } // confirm access if ($allow) { $itemsAllowed->add($item); } } $itemsAllowed->resetTrackChanges(true); return $itemsAllowed; }
include_once "autoloader.php"; $pdo_singleton = new PDOSingleton(); if (isset($_GET["id"])) { if ($_GET["id"] == 41) { header("location: http://best.insa-lyon.fr/project_x/course.html"); } elseif ($_GET["id"] == 44) { header("location: http://best.insa-lyon.fr/ebec.html"); } $is_event = TRUE; $event_page = Page::get($_GET["id"]); //rajouter controle ici } else { $is_event = FALSE; $event_page = Page::get("events_presentation"); $events = new PageArray(); $events->get_events(); } ?> <!DOCTYPE html> <html> <head> <title> <?php echo $is_event ? $event_page->title . " par BEST Lyon" : "Évènements BEST Lyon"; ?> </title> <link type="text/css" rel="stylesheet" href="./css/events.css"/> <link href='https://fonts.googleapis.com/css?family=Libre+Baskerville' rel='stylesheet' type='text/css'> <link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
/** * Gallery page template * */ // Thumbnails per page $thumb_per_page = 9; // Thumbnail dimensions $thumb_width = 200; $thumb_height = 150; // Pager labels $pager_next = 'Weiter »'; $pager_prev = '« Zurück'; $gallery_start = ($input->pageNum - 1) * $thumb_per_page; $gallery_total = count($page->images); $gallery_images = $page->images->slice($gallery_start, $thumb_per_page); $a = new PageArray(); foreach ($gallery_images as $unused) { $a->add(new Page()); } $a->setTotal($gallery_total); $a->setLimit($thumb_per_page); $a->setStart($gallery_start); // Primary content: page's body copy $content = $page->body; // Secondary content: image gallery $content .= "\n<ul class='gallery'>\n"; foreach ($gallery_images as $item) { $thumb = $item->size($thumb_width, $thumb_height); $content .= "<li><a href='{$item->url}' title='{$item->description}'><img src='{$thumb->url}' alt='{$item->description}'></a></li>\n"; } $content .= "</ul>\n";
/** * Return this page's parent pages. * */ public function parents() { $parents = new PageArray(); $parent = $this->parent(); while ($parent && $parent->id) { $parents->prepend($parent); $parent = $parent->parent(); } return $parents; }
/** * Get the role pages that are part of this template * * This method returns a blank PageArray if roles haven't yet been loaded into the template. * If the roles have previously been loaded as an array, then this method converts that array to a PageArray and returns it. * * @return PageArray * */ protected function getRoles() { if (is_null($this->_roles)) { return new PageArray(); } else { if ($this->_roles instanceof PageArray) { return $this->_roles; } else { if (is_array($this->_roles)) { $roles = new PageArray(); if (count($this->_roles)) { $roles->import($this->pages->getById($this->_roles)); } $this->_roles = $roles; return $this->_roles; } else { return new PageArray(); } } } }
/** * Given a PageArray, convert it to a cachable array * * @param PageArray $items * @return array * @throws WireException * @since Version 2.5.28 * */ protected function pageArrayToArray(PageArray $items) { $templates = array(); $ids = array(); $pageClasses = array(); foreach ($items as $item) { $templates[$item->template->id] = $item->template->id; $ids[] = $item->id; $pageClass = $item->className(); $pageClasses[$pageClass] = $pageClass; } if (count($pageClasses) > 1) { throw new WireException("Can't cache multiple page types together: " . implode(', ', $pageClasses)); } $data = array('PageArray' => $ids, 'template' => count($templates) == 1 ? reset($templates) : 0); $pageClass = reset($pageClasses); if ($pageClass && $pageClass != 'Page') { $data['pageClass'] = $pageClass; } $pageArrayClass = $items->className(); if ($pageArrayClass != 'PageArray') { $data['pageArrayClass'] = $pageArrayClass; } return $data; }
public function getParents() { if (count($this->parents)) { return $this->wire('pages')->getById($this->parents); } else { $parent = $this->getParent(); $parents = new PageArray(); $parents->add($parent); return $parents; } }
/** * Render pagination links * * This uses ProcessWire's MarkupPagerNav module and overrides the default * markup to focus on Foundation-specific pagination styles. * */ function renderPagination(PageArray $items) { if (!$items->getLimit() || $items->getTotal() <= $items->getLimit()) { return ''; } $page = wire('page'); if (!$page->template->allowPageNum) { // notify developer they need to enable pagination in the template return "<p class='alert label'>" . "This template needs page numbers enabled to support pagination!<br />" . "Go to: Admin - Setup - Templates - Edit: '{$page->template}' - URLs " . "</p>"; } // customize the MarkupPagerNav to output in Foundation-style pagination links $options = array('nextItemLabel' => '»', 'nextItemClass' => 'arrow', 'previousItemLabel' => '«', 'previousItemClass' => 'arrow', 'lastItemClass' => 'last', 'currentItemClass' => 'current', 'separatorItemLabel' => '…', 'separatorItemClass' => 'unavailable', 'listMarkup' => "<ul class='pagination'>{out}</ul>", 'itemMarkup' => "<li class='{class}'>{out}</li>", 'linkMarkup' => "<a href='{url}'>{out}</a>"); $pager = wire('modules')->get('MarkupPagerNav'); $pager->setBaseUrl(wire('page')->url); return $pager->render($items, $options); }
/** * Return all sibling pages before this one until matching the one specified * * @param Page $page * @param string|Page $selector May either be a selector string or Page to stop at. Results will not include this. * @param string $filter Optional selector string to filter matched pages by * @param PageArray|null $siblings Optional PageArray of siblings to use instead of all from the page. * @return PageArray * */ public function prevUntil(Page $page, $selector = '', $filter = '', PageArray $siblings = null) { if (is_null($siblings)) { $siblings = $page->parent()->children(); } else { if (!$siblings->has($page)) { $siblings->add($page); } } $siblings = $this->prevAll($page, '', $siblings); $all = new PageArray(); $stop = false; foreach ($siblings->reverse() as $sibling) { if (is_string($selector) && strlen($selector)) { if (ctype_digit("{$selector}") && $sibling->id == $selector) { $stop = true; } else { if ($sibling->matches($selector)) { $stop = true; } } } else { if (is_int($selector)) { if ($sibling->id == $selector) { $stop = true; } } else { if ($selector instanceof Page && $sibling->id == $selector->id) { $stop = true; } } } if ($stop) { break; } $all->prepend($sibling); } if (strlen($filter)) { $all->filter($filter); } return $all; }
/** * Given an array or CSV string of Page IDs, return a PageArray * * @param array|WireArray|string $ids Array of IDs or CSV string of IDs * @param Template $template Specify a template to make the load faster, because it won't have to attempt to join all possible fields... just those used by the template. * @param int $parent_id Specify a parent to make the load faster, as it reduces the possibility for full table scans * @return PageArray * */ public function getById($ids, Template $template = null, $parent_id = null) { static $instanceID = 0; $pages = new PageArray(); if (is_string($ids)) { $ids = explode(",", $ids); } if (!WireArray::iterable($ids) || !count($ids)) { return $pages; } if (is_object($ids)) { $ids = $ids->getArray(); } $loaded = array(); foreach ($ids as $key => $id) { $id = (int) $id; $ids[$key] = $id; if ($page = $this->getCache($id)) { $loaded[$id] = $page; unset($ids[$key]); } else { if (isset(Page::$loadingStack[$id])) { // if the page is already in the process of being loaded, point to it rather than attempting to load again. // the point of this is to avoid a possible infinite loop with autojoin fields referencing each other. $loaded[$id] = Page::$loadingStack[$id]; // cache the pre-loaded version so that other pages referencing it point to this instance rather than loading again $this->cache($loaded[$id]); unset($ids[$key]); } else { $loaded[$id] = ''; // reserve the spot, in this order } } } $idCnt = count($ids); if (!$idCnt) { return $pages->import($loaded); } $idsByTemplate = array(); if (is_null($template)) { $sql = "SELECT id, templates_id FROM pages WHERE "; if ($idCnt == 1) { $sql .= "id=" . (int) reset($ids); } else { $sql .= "id IN(" . implode(",", $ids) . ")"; } $result = $this->db->query($sql); if ($result && $result->num_rows) { while ($row = $result->fetch_row()) { list($id, $templates_id) = $row; if (!isset($idsByTemplate[$templates_id])) { $idsByTemplate[$templates_id] = array(); } $idsByTemplate[$templates_id][] = $id; } } $result->free(); } else { $idsByTemplate = array($template->id => $ids); } foreach ($idsByTemplate as $templates_id => $ids) { if (!$template || $template->id != $templates_id) { $template = $this->fuel('templates')->get($templates_id); } $fields = $template->fieldgroup; $query = new DatabaseQuerySelect(); $query->select("false AS isLoaded, pages.templates_id AS templates_id, pages.*, pages_sortfields.sortfield, " . "(SELECT COUNT(*) FROM pages AS children WHERE children.parent_id=pages.id) AS numChildren"); $query->leftjoin("pages_sortfields ON pages_sortfields.pages_id=pages.id"); $query->groupby("pages.id"); foreach ($fields as $field) { if (!($field->flags & Field::flagAutojoin)) { continue; } $table = $field->table; if (!$field->type->getLoadQueryAutojoin($field, $query)) { continue; } // autojoin not allowed $query->leftjoin("{$table} ON {$table}.pages_id=pages.id"); } if (!is_null($parent_id)) { $query->where("pages.parent_id=" . (int) $parent_id); } $query->where("pages.templates_id={$template->id}"); $query->where("pages.id IN(" . implode(',', $ids) . ") "); $query->from("pages"); if (!($result = $query->execute())) { throw new WireException($this->db->error); } $class = $template->pageClass && class_exists($template->pageClass) ? $template->pageClass : 'Page'; while ($page = $result->fetch_object($class, array($template))) { $page->instanceID = ++$instanceID; $page->setIsLoaded(true); $page->setIsNew(false); $page->setTrackChanges(true); $page->setOutputFormatting($this->outputFormatting); $loaded[$page->id] = $page; $this->cache($page); } $template = null; $result->free(); } return $pages->import($loaded); }
echo $zoom; ?> ; RCDMap.init('map', <?php echo $lat; ?> , <?php echo $lng; ?> ); $("#content").addClass('has_map'); <?php if ($page->template == 'skyscraper') { $markers = new PageArray(); $markers->add($page); } else { if ($page->template == 'cities' || $page->template == 'home') { $markers = $pages->get("/cities/")->children(); } else { $markers = mapSkyscrapers(); } } foreach ($markers as $item) { if (!$item->map->lat) { continue; } echo "\n\t\tRCDMap.addMarker('{$item->title}', '{$item->url}', {$item->map->lat}, {$item->map->lng});"; } ?>
/** * Given an array or CSV string of Page IDs, return a PageArray * * Optionally specify an $options array rather than a template for argument 2. When present, the 'template' and 'parent_id' arguments may be provided * in the given $options array. These options may be specified: * * - template: instance of Template (see $template argument) * - parent_id: integer (see $parent_id argument) * - getNumChildren: boolean, default=true. Specify false to disable retrieval and population of 'numChildren' Page property. * * @param array|WireArray|string $ids Array of IDs or CSV string of IDs * @param Template|array|null $template Specify a template to make the load faster, because it won't have to attempt to join all possible fields... just those used by the template. * Optionally specify an $options array instead, see the method notes above. * @param int|null $parent_id Specify a parent to make the load faster, as it reduces the possibility for full table scans. * This argument is ignored when an options array is supplied for the $template. * @return PageArray * @throws WireException * */ public function getById($ids, $template = null, $parent_id = null) { $options = array('template' => null, 'parent_id' => null, 'getNumChildren' => true); if (is_array($template)) { // $template property specifies an array of options $options = array_merge($options, $template); $template = $options['template']; $parent_id = $options['parent_id']; } else { if (!is_null($template) && !$template instanceof Template) { throw new WireException('getById argument 2 must be Template or $options array'); } } static $instanceID = 0; $database = $this->wire('database'); $pages = new PageArray(); if (is_string($ids)) { $ids = explode(",", $ids); } if (!WireArray::iterable($ids) || !count($ids)) { return $pages; } if (is_object($ids)) { $ids = $ids->getArray(); } $loaded = array(); foreach ($ids as $key => $id) { $id = (int) $id; $ids[$key] = $id; if ($page = $this->getCache($id)) { $loaded[$id] = $page; unset($ids[$key]); } else { if (isset(Page::$loadingStack[$id])) { // if the page is already in the process of being loaded, point to it rather than attempting to load again. // the point of this is to avoid a possible infinite loop with autojoin fields referencing each other. $loaded[$id] = Page::$loadingStack[$id]; // cache the pre-loaded version so that other pages referencing it point to this instance rather than loading again $this->cache($loaded[$id]); unset($ids[$key]); } else { $loaded[$id] = ''; // reserve the spot, in this order } } } $idCnt = count($ids); if (!$idCnt) { return $pages->import($loaded); } $idsByTemplate = array(); if (is_null($template)) { $sql = "SELECT id, templates_id FROM pages WHERE "; if ($idCnt == 1) { $sql .= "id=" . (int) reset($ids); } else { $sql .= "id IN(" . implode(",", $ids) . ")"; } $query = $database->prepare($sql); $result = $query->execute(); if ($result) { while ($row = $query->fetch(PDO::FETCH_NUM)) { list($id, $templates_id) = $row; if (!isset($idsByTemplate[$templates_id])) { $idsByTemplate[$templates_id] = array(); } $idsByTemplate[$templates_id][] = $id; } } $query->closeCursor(); } else { $idsByTemplate = array($template->id => $ids); } foreach ($idsByTemplate as $templates_id => $ids) { if (!$template || $template->id != $templates_id) { $template = $this->wire('templates')->get($templates_id); } $fields = $template->fieldgroup; $query = new DatabaseQuerySelect(); $joinSortfield = empty($template->sortfield); $query->select("false AS isLoaded, pages.templates_id AS templates_id, pages.*, " . ($joinSortfield ? 'pages_sortfields.sortfield, ' : '') . ($options['getNumChildren'] ? '(SELECT COUNT(*) FROM pages AS children WHERE children.parent_id=pages.id) AS numChildren' : '')); if ($joinSortfield) { $query->leftjoin('pages_sortfields ON pages_sortfields.pages_id=pages.id'); } $query->groupby('pages.id'); foreach ($fields as $field) { if (!($field->flags & Field::flagAutojoin)) { continue; } $table = $database->escapeTable($field->table); if (!$field->type || !$field->type->getLoadQueryAutojoin($field, $query)) { continue; } // autojoin not allowed $query->leftjoin("{$table} ON {$table}.pages_id=pages.id"); // QA } if (!is_null($parent_id)) { $query->where("pages.parent_id=" . (int) $parent_id); } $query->where("pages.templates_id=" . (int) $template->id); // QA $query->where("pages.id IN(" . implode(',', $ids) . ") "); // QA $query->from("pages"); $stmt = $query->execute(); if ($stmt->errorCode() > 0) { $errorInfo = $result->errorInfo(); throw new WireException($errorInfo[2]); } $class = $template->pageClass && class_exists($template->pageClass) ? $template->pageClass : 'Page'; while ($page = $stmt->fetchObject($class, array($template))) { $page->instanceID = ++$instanceID; $page->setIsLoaded(true); $page->setIsNew(false); $page->setTrackChanges(true); $page->setOutputFormatting($this->outputFormatting); $loaded[$page->id] = $page; $this->cache($page); } $stmt->closeCursor(); $template = null; } return $pages->import($loaded); }
/** * Get the role pages that are part of this template * * This method returns a blank PageArray if roles haven't yet been loaded into the template. * If the roles have previously been loaded as an array, then this method converts that array to a PageArray and returns it. * * @param string $type Default is 'view', but you may also specify 'edit', 'create' or 'add' to retrieve those * @return PageArray * @throws WireException if given an unknown roles type * */ public function getRoles($type = 'view') { if (strpos($type, 'page-') === 0) { $type = str_replace('page-', '', $type); } if ($type != 'view') { $roles = new PageArray(); $roleIDs = null; if ($type == 'edit') { $roleIDs = $this->editRoles; } else { if ($type == 'create') { $roleIDs = $this->createRoles; } else { if ($type == 'add') { $roleIDs = $this->addRoles; } else { throw new WireException("Unknown roles type: {$type}"); } } } if (empty($roleIDs)) { return $roles; } return $this->wire('pages')->getById($roleIDs); } // type=view assumed from this point forward if (is_null($this->_roles)) { return new PageArray(); } else { if ($this->_roles instanceof PageArray) { return $this->_roles; } else { if (is_array($this->_roles)) { $errors = array(); $roles = new PageArray(); if (count($this->_roles)) { $test = implode('0', $this->_roles); // test to see if it's all digits (IDs) if (ctype_digit("{$test}")) { $roles->import($this->pages->getById($this->_roles)); } else { // role names foreach ($this->_roles as $name) { $role = $this->wire('roles')->get($name); if ($role->id) { $roles->add($role); } else { $errors[] = $name; } } } } if (count($errors) && $this->useRoles) { $this->error("Unable to load role(s): " . implode(', ', $errors)); } $this->_roles = $roles; return $this->_roles; } else { return new PageArray(); } } } }
/** * Get the role pages that are part of this template * * This method returns a blank PageArray if roles haven't yet been loaded into the template. * If the roles have previously been loaded as an array, then this method converts that array to a PageArray and returns it. * * @return PageArray * */ public function getRoles() { if (is_null($this->_roles)) { return new PageArray(); } else { if ($this->_roles instanceof PageArray) { return $this->_roles; } else { if (is_array($this->_roles)) { $errors = array(); $roles = new PageArray(); if (count($this->_roles)) { $test = implode('0', $this->_roles); // test to see if it's all digits (IDs) if (ctype_digit("{$test}")) { $roles->import($this->pages->getById($this->_roles)); } else { // role names foreach ($this->_roles as $name) { $role = $this->wire('roles')->get($name); if ($role->id) { $roles->add($role); } else { $errors[] = $name; } } } } if (count($errors) && $this->useRoles) { $this->error("Unable to load role(s): " . implode(', ', $errors)); } $this->_roles = $roles; return $this->_roles; } else { return new PageArray(); } } } }
?> </div> </div> <aside> <a href="#events"> <img src="./pictures/go_down.png" alt="go down"/> </a> </aside> </section> <section id="events"> <div class="wrapper"> <?php $events = Page::get("events_presentation"); $events->display_full_page(); $events = new PageArray(); $events->get_events(); $events->display_list(); unset($events); ?> </div> <aside> <a href="#values"> <img src="./pictures/go_down.png" alt="go down"/> </a> </aside> </section> <section id="values"> <div class="wrapper"> <ul>Nos valeurs
/** * Enable iteration of this class * */ public function getIterator() { if ($this->languages && count($this->languages)) { return $this->languages; } $languages = new PageArray(); foreach ($this->getAll() as $language) { if ($language->is(Page::statusUnpublished) || $language->is(Page::statusHidden)) { continue; } $languages->add($language); } if (count($languages)) { $this->languages = $languages; } return $languages; }
/** * Given an array or CSV string of Page IDs, return a PageArray * * @param array|WireArray|string $ids Array of IDs or CSV string of IDs * @param Template $template Specify a template to make the load faster, because it won't have to attempt to join all possible fields... just those used by the template. * @param int $parent_id Specify a parent to make the load faster, as it reduces the possibility for full table scans * @return PageArray * */ public function getById($ids, Template $template = null, $parent_id = null) { static $instanceID = 0; $pages = new PageArray(); if (is_string($ids)) { $ids = explode(",", $ids); } if (!WireArray::iterable($ids) || !count($ids)) { return $pages; } if (is_object($ids)) { $ids = $ids->getArray(); } $loaded = array(); foreach ($ids as $key => $id) { $id = (int) $id; $ids[$key] = $id; if ($page = $this->getCache($id)) { $loaded[$id] = $page; unset($ids[$key]); } else { $loaded[$id] = ''; // reserve the spot, in this order } } $idCnt = count($ids); $fields = is_null($template) ? $this->fuel->fields : $template->fieldgroup; if ($idCnt) { // Optimization to only load the fields specific to the page, if just one page. // Without it, all autojoin fields have to be attempted, whether they are applicable to the pages loaded or not. // Even though this increases queries, it does result in a slight overall speed and memory improvement. if (is_null($template) && $idCnt == 1) { $result = $this->db->query("SELECT templates_id FROM pages WHERE id=" . (int) reset($ids)); if ($result) { list($tpl_id) = $result->fetch_row(); $template = $this->fuel('templates')->get($tpl_id); if ($template) { $fields = $template->fieldgroup; } $result->free(); } } $query = new DatabaseQuerySelect(); $query->select("false AS isLoaded, pages.templates_id AS templates_id, pages.*, pages_sortfields.sortfield, " . "(SELECT COUNT(*) FROM pages AS children WHERE children.parent_id=pages.id) AS numChildren"); $query->leftjoin("pages_sortfields ON pages_sortfields.pages_id=pages.id"); $query->groupby("pages.id"); foreach ($fields as $field) { if (!($field->flags & Field::flagAutojoin)) { continue; } //if($field->type instanceof FieldtypeMulti) continue; $table = $field->table; // if($field->type instanceof FieldtypeMulti) { // $sel .= "(SELECT COUNT(*) FROM $table WHERE $table.pages_id=pages.id) AS {$field->name}, "; // } else { if (!$field->type->getLoadQueryAutojoin($field, $query)) { continue; } // autojoin not allowed // $query->select("$table.data AS {$field->name}"); $query->leftjoin("{$table} ON {$table}.pages_id=pages.id"); } if (!is_null($parent_id)) { $query->where("pages.parent_id=" . (int) $parent_id); } if (!is_null($template)) { $query->where("pages.templates_id={$template->id}"); } $query->where("pages.id IN(" . implode(',', $ids) . ") "); $query->from("pages"); if (!($result = $query->execute())) { throw new WireException($this->db->error); } while ($page = $result->fetch_object('Page', array($template))) { $page->instanceID = ++$instanceID; $page->setIsLoaded(true); $page->setIsNew(false); $page->setTrackChanges(true); $page->setOutputFormatting($this->outputFormatting); $loaded[$page->id] = $page; $this->cache($page); } $result->free(); } $pages->import($loaded); return $pages; }