/** * Link to the previous page in the containing chapter. * * @param array $params * @return string */ function smarty_previouspage($params, &$smarty) { global $PIVOTX; // This tag is only allowed on pages.. if ($PIVOTX['parser']->modifier['pagetype'] != "page") { return; } $vars = $smarty->get_template_vars(); // The current page must exist/have an uid if (empty($vars['page']['uid'])) { debug("There is no uid for the current page."); return; } $params = cleanParams($params); $chapters = $PIVOTX['pages']->getIndex(); $pages = $chapters[$vars['page']['chapter']]['pages']; // Handle sorting $sort = false; if (isset($params['sort'])) { $sort = true; if ($params['sort'] == 'title') { $pages_sort_key = 'title'; } else { if ($params['sort'] == 'uri') { $pages_sort_key = 'uri'; } else { if ($params['sort'] == 'date') { $pages_sort_key = 'date'; } else { $sort = false; } } } } if ($sort) { foreach ($pages as $key => $page) { $pages[$page[$pages_sort_key]] = $page; unset($pages[$key]); } ksort($pages); } // We will find the previous page by searching the array in reverse order. // This means that have to reverse it, if sortorder isn't reverse ;-) if ($params['sortorder'] != 'reverse') { $pages = array_reverse($pages, true); } $found = false; do { $page = current($pages); $prevpage = next($pages); if (!$found && $page['uid'] == $vars['page']['uid']) { $found = true; } } while ($prevpage !== false && !($prevpage['status'] == "publish" && $found)); $text = getDefault($params['text'], '« <a href="%link%">%title%</a>'); $cutoff = getDefault($params['cutoff'], 20); if ($prevpage) { $title = strlen($prevpage['title']) > 2 ? $prevpage['title'] : substr($prevpage['introduction'], 0, 100); $link = makePageLink($prevpage['uri'], $prevpage['title'], $prevpage['uid'], $prevpage['date'], $params['weblog']); $output = $text; $output = str_replace("%link%", $link, $output); $output = str_replace("%title%", trimText($title, $cutoff), $output); $output = str_replace("%subtitle%", trimText($prevpage['subtitle'], $cutoff), $output); return entifyAmpersand($output); } else { return ""; } }
/** * Get a single page by its uid * * @param integer $uid * @return array */ function getPage($uid) { global $PIVOTX; $page = loadSerialize($PIVOTX['paths']['db_path'] . "pages/page_{$uid}.php"); $page['link'] = makePageLink($page['uri']); if ($page['title'] == '') { $page['title'] = __('No title..'); } // Set the chapter name and description (in addition to just the chapter's ID) $chapters = $PIVOTX['pages']->getIndex(); $page['chaptername'] = $chapters[$page['chapter']]['chaptername']; $page['chapterdesc'] = $chapters[$page['chapter']]['description']; return $page; }
/** * Get a single page by its URI * * @param string $uri * @return array */ function getPageByUri($uri) { global $PIVOTX; $qry = array(); $qry['select'] = "*"; $qry['from'] = $this->pagestable; $qry['limit'] = 1; $qry['where'] = "uri LIKE " . $this->sql->quote($uri); $this->sql->build_select($qry); $this->sql->query(); $page = $this->sql->fetch_row(); if (is_array($page)) { $page['link'] = makePageLink($page['uri']); // get the 'extra fields' $this->sql->query("SELECT * FROM " . $this->extrafieldstable . " WHERE contenttype='page' and target_uid=" . intval($page['uid']) . " ORDER BY uid ASC"); $temp_fields = $this->sql->fetch_all_rows(); $page['extrafields'] = array(); if (is_array($temp_fields)) { foreach ($temp_fields as $temp_field) { $page['extrafields'][$temp_field['fieldkey']] = $temp_field['value']; } } // Set the chaptername (in addition to just the chapter's ID) $chapters = $PIVOTX['pages']->getIndex(); $page['chaptername'] = $chapters[$page['chapter']]['chaptername']; return $page; } else { // we couldn't find the page. Bummer! return array(); } }