Example #1
0
/**
 * 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);
}
/**
 * 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;
}
Example #3
0
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;
}
 /**
  * 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;
 }
Example #5
0
 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;
     }
 }
Example #6
0
 /**
  * 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();
             }
         }
     }
 }
Example #7
0
 /**
  * Return all sibling pages after 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 nextUntil(Page $page, $selector = '', $filter = '', PageArray $siblings = null)
 {
     if (is_null($siblings)) {
         $siblings = $page->parent()->children();
     } else {
         if (!$siblings->has($page)) {
             $siblings->prepend($page);
         }
     }
     $siblings = $this->nextAll($page, '', $siblings);
     $all = new PageArray();
     $stop = false;
     foreach ($siblings 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->add($sibling);
     }
     if (strlen($filter)) {
         $all->filter($filter);
     }
     return $all;
 }
Example #8
0
 /**
  * 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;
 }
Example #9
0
 /**
  * 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;
 }
Example #10
0
 /**
 * Given a Selector string, return the Page objects that match in a PageArray. 
 *
 * @param string $selectorString
 * @param array $options 
 		- findOne: apply optimizations for finding a single page and include pages with 'hidden' status
 * @return PageArray
 *
 */
 public function ___find($selectorString, $options = array())
 {
     // TODO selector strings with runtime fields, like url=/about/contact/, possibly as plugins to PageFinder
     if (!strlen($selectorString)) {
         return new PageArray();
     }
     if ($selectorString === '/' || $selectorString === 'path=/') {
         $selectorString = 1;
     }
     if ($selectorString[0] == '/') {
         // if selector begins with a slash, then we'll assume it's referring to a path
         $selectorString = "path={$selectorString}";
     } else {
         if (strpos($selectorString, ",") === false && strpos($selectorString, "|") === false) {
             // there is just one param. Lets see if we can find a shortcut.
             if (ctype_digit("{$selectorString}") || strpos($selectorString, "id=") === 0) {
                 // if selector is just a number, or a string like "id=123" then we're going to do a shortcut
                 $s = str_replace("id=", '', $selectorString);
                 if (ctype_digit("{$s}")) {
                     $page = $this->getById(array((int) $s));
                     $pageArray = new PageArray();
                     $value = $page ? $pageArray->add($page) : $pageArray;
                     if ($this->config->debug) {
                         $this->debugLog('find', $selectorString . " [optimized]", $value);
                     }
                     return $value;
                 }
             }
         }
     }
     // see if this has been cached and return it if so
     $pages = $this->getSelectorCache($selectorString, $options);
     if (!is_null($pages)) {
         if ($this->config->debug) {
             $this->debugLog('find', $selectorString, $pages . ' [from-cache]');
         }
         return $pages;
     }
     // check if this find has already been executed, and return the cached results if so
     // if(null !== ($pages = $this->getSelectorCache($selectorString, $options))) return clone $pages;
     // if a specific parent wasn't requested, then we assume they don't want results with status >= Page::statusUnsearchable
     // if(strpos($selectorString, 'parent_id') === false) $selectorString .= ", status<" . Page::statusUnsearchable;
     $selectors = new Selectors($selectorString);
     $pages = $this->pageFinder->find($selectors, $options);
     // note that we save this pagination state here and set it at the end of this method
     // because it's possible that more find operations could be executed as the pages are loaded
     $total = $this->pageFinder->getTotal();
     $limit = $this->pageFinder->getLimit();
     $start = $this->pageFinder->getStart();
     // parent_id is null unless a single parent was specified in the selectors
     $parent_id = $this->pageFinder->getParentID();
     $idsSorted = array();
     $idsByTemplate = array();
     // organize the pages by template ID
     foreach ($pages as $page) {
         $tpl_id = $page['templates_id'];
         if (!isset($idsByTemplate[$tpl_id])) {
             $idsByTemplate[$tpl_id] = array();
         }
         $idsByTemplate[$tpl_id][] = $page['id'];
         $idsSorted[] = $page['id'];
     }
     if (count($idsByTemplate) > 1) {
         // perform a load for each template, which results in unsorted pages
         $unsortedPages = new PageArray();
         foreach ($idsByTemplate as $tpl_id => $ids) {
             $unsortedPages->import($this->getById($ids, $this->templates->get($tpl_id), $parent_id));
         }
         // put pages back in the order that the selectorEngine returned them in, while double checking that the selector matches
         $pages = new PageArray();
         foreach ($idsSorted as $id) {
             foreach ($unsortedPages as $page) {
                 if ($page->id == $id) {
                     $pages->add($page);
                     break;
                 }
             }
         }
     } else {
         // there is only one template used, so no resorting is necessary
         $pages = new PageArray();
         reset($idsByTemplate);
         $pages->import($this->getById($idsSorted, $this->templates->get(key($idsByTemplate)), $parent_id));
     }
     $pages->setTotal($total);
     $pages->setLimit($limit);
     $pages->setStart($start);
     $pages->setSelectors($selectors);
     $pages->setTrackChanges(true);
     $this->selectorCache($selectorString, $options, $pages);
     if ($this->config->debug) {
         $this->debugLog('find', $selectorString, $pages);
     }
     return $pages;
     //return $pages->filter($selectors);
 }
Example #11
0
?>
;
		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});";
}
?>
Example #12
0
 /**
  * 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();
             }
         }
     }
 }
Example #13
0
/**
 * Render breadcrumb navigation
 *
 */
function renderBreadcrumbs(PageArray $items)
{
    // if the page has a headline that's different from the title, add it to the bredcrumbs
    $page = wire('page');
    if ($page->headline) {
        $items->add($page);
    }
    $options = array('class' => 'breadcrumbs', 'active' => 'unavailable');
    return renderNav($items, $options);
}
 *
 */
// 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";
// Emit pager
$content .= $a->renderPager(array('nextItemLabel' => $pager_next, 'previousItemLabel' => $pager_prev, 'listMarkup' => "<ul class='pager'>{out}</ul>", 'itemMarkup' => "<li>{out}</li>", 'linkMarkup' => "<a href='{url}'>{out}</a>"));