function action_view($args) { global $manager, $tree, $config, $user, $lang; // If no arguments are provided redirect if (!count($args)) { $id = $tree->getHome(); if (!is_null($id)) { header('Location: ' . url::item($id)); exit; } // There are no pages $id = 0; $type = ''; $ext = ''; $item = null; if ($user->admin()) { // Allow admins to add pages... $action = 'edit'; $page = new admin(); // Notify plugins of a PreSkinParse event; $data = array('page' => &$page, 'template' => &$page->template, 'type' => $type, 'params' => array('action' => $action, 'id' => $id, 'ext' => $ext, 'args' => $args)); $manager->handleEvent('PreSkinParse', $data); $page->show(); exit; } else { if ($lang->id != _DEFAULT_LANGUAGE_) { // Redirect to the default language header('Location: ' . url::language(_DEFAULT_LANGUAGE_)); } else { // Show error message that website is offline $config = new config(); $lang = new language(_DEFAULT_LANGUAGE_, _DEFAULT_SITE_, true); $page = new theme(); $page->showError(_OFFLINE_MESSAGE_, 4); } } } else { // Decode argumenst $id = array_shift($args); // Check if the id contains an file extension if (preg_match('/(.*)\\.([a-z0-9]+)$/i', $id, $matches)) { $id = $matches[1]; $ext = $matches[2]; } else { $ext = ''; } // Load the page $item =& $tree->getItemById($id); $id = $item['id']; $type = $item['type']; $action = 'view'; // Setup Theme $page = new theme($id, $type); } // Notify plugins of a PreSkinParse event; $data = array('page' => &$page, 'template' => &$page->template, 'type' => $type, 'params' => array('action' => $action, 'id' => $id, 'ext' => $ext, 'args' => $args)); $manager->handleEvent('PreSkinParse', $data); // Handle authorisation $ticket = false; if (isset($_REQUEST['ticket'])) { if (ticket::authorize($_REQUEST['ticket']) == $data['params']['id']) { $ticket = true; } } if ($ticket || $tree->_hasRights('view', $item['rights'])) { $page->title->set($item['name']); if ($item['title'] != '') { $page->title->set($item['title']); } $manager->handleType($type, $data); $page->template->set('action', $action); $page->template->set('id', $id); $page->template->set('slug', isset($item['slug']) ? $item['slug'] : ''); $page->template->set('type', $type); if (isset($item)) { if (!isset($manager->types[$item['type']]['generated']) || !$manager->types[$item['type']]['generated']) { if ($config->get('showLastModified')) { $page->template->set('modified', revisions::getModificationDate($id, $item['revision'])); } } } } else { if ($config->get('redirectToLogin') && $user->anonymous()) { array_unshift($args, $id); $manager->handleAction('login', $args); //header ('Location: ' . url::item($id, 'login')); exit; } else { $page->template->set('error', $lang->s('notenoughrights')); } } $page->show(); }
function _retrieveCollection($id) { global $tree; $collection = array(); if ($item =& $tree->getItemById($id)) { if ($item['visible']) { $res = sql::query("\n\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t* \n\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents_collection\n\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\tid='" . $item['id'] . "' AND\n\t\t\t\t\t\t\trevision='" . $item['revision'] . "'\n\t\t\t\t\t"); if ($row = sql::fetch_array($res)) { $limit = intval($row['limit']); /* We need a major hack here... we have a dependency on the story plugin, so we need to make sure is loaded properly */ // $manager->load('types/story'); $updated = 0; if ($children =& $tree->getChildrenById($id)) { $sort = 0; if ($sort == 0 && $row['sort'] != 0) { $sort = $row['sort']; } if ($sort == 0 && $tree->data[$id]['sort'] != 0) { $sort = $tree->data[$id]['sort']; } if ($sort != 0) { switch (abs($sort)) { case 1: $t = "strcasecmp(\$a['name'], \$b['name'])"; break; case 2: $t = "\$a['created'] - \$b['created']"; break; case 3: $t = "\$a['published'] - \$b['published']"; break; case 4: $t = "\$a['modified'] - \$b['modified']"; break; default: continue; } uasort($children, create_function('$a, $b', "return " . ($sort > 0 ? '' : '-') . "(" . $t . ");")); } while (list(, $child) = each($children)) { if ($child['visible'] && $child['type'] == $row['type']) { // Basic data $author = new user($child['rights']['author']); $author->load(); $name = $author->details['firstname'] . ($author->details['prefix'] != '' ? ' ' . $author->details['prefix'] : '') . ' ' . $author->details['lastname'] . ' (' . $author->details['username'] . ')'; $collection[$child['id']] = array('id' => $child['id'], 'title' => $child['name'], 'url' => $child['url'], 'created' => $child['meta']['created'], 'modified' => revisions::getModificationDate($child['id'], $child['revision']), 'author' => $name); if ($child['title'] != '') { $collection[$child['id']]['title'] = $child['title']; } $updated = max($updated, $collection[$child['id']]['modified']); // Retrieve story $res = sql::query("\n\t\t\t\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\t\t\t\t*\n\t\t\t\t\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents_story \n\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\t`ID` = '" . $child['id'] . "' AND\n\t\t\t\t\t\t\t\t\t\t\t`revision` = '" . $child['revision'] . "'\n\t\t\t\t\t\t\t\t\t"); if ($story = sql::fetch_array($res, MYSQL_ASSOC)) { $summary = preg_split('/<hr( \\/)?>/i', $story['text']); $summary = is_array($summary) && count($summary) ? $summary[0] : $story['text']; $collection[$child['id']]['summary'] = $summary; $collection[$child['id']]['content'] = $story['text']; } else { $collection[$child['id']]['summary'] = ''; $collection[$child['id']]['content'] = ''; } // Retrieve image $res = sql::query("\n\t\t\t\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\t\t\t\t* \n\t\t\t\t\t\t\t\t\t\tFROM \n\t\t\t\t\t\t\t\t\t\t\t" . _TABLE_PREFIX_ . "contents_image\n\t\t\t\t\t\t\t\t\t\tWHERE \n\t\t\t\t\t\t\t\t\t\t\tid='" . $child['id'] . "' AND\n\t\t\t\t\t\t\t\t\t\t\trevision='" . $child['revision'] . "'\n\t\t\t\t\t\t\t\t\t"); if ($image = sql::fetch_array($res)) { $collection[$child['id']]['image'] = $image['image']; } } // Limit the stories if ($limit > 0) { $collection = array_splice($collection, 0, $limit); } } } } } } if (count($collection)) { return $collection; } }