/** * Edit a page in the mobile interface. */ function pagem_editpage() { global $PIVOTX; $PIVOTX['session']->minLevel(PIVOTX_UL_NORMAL); if ($_GET['uid'] == "") { $PIVOTX['template']->assign('title', __('Write a new Page')); } else { $PIVOTX['template']->assign('title', __('Edit Page')); } $currentuser = $PIVOTX['users']->getUser($PIVOTX['session']->currentUsername()); if (!empty($_GET['uid'])) { // Editing a page.. Get it from the DB.. $page = $PIVOTX['pages']->getPage($_GET['uid']); $PIVOTX['events']->add('edit_entry', intval($_GET['uid']), $entry['title']); if (!$PIVOTX['users']->allowEdit('page', $page['user'])) { $PIVOTX['template']->assign('heading', __("PivotX encountered an error")); $PIVOTX['template']->assign('html', "<p>" . __("You are not allowed to edit this entry.") . "</p>"); renderTemplate('mobile/generic.tpl'); return; } // Make sure we tweak the </textarea> in the intro or body text (since // that would break our own textarea, if we didn't).. $page['introduction'] = str_replace("<textarea", "<textarea", $page['introduction']); $page['introduction'] = str_replace("</textarea", "</textarea", $page['introduction']); $page['body'] = str_replace("<textarea", "<textarea", $page['body']); $page['body'] = str_replace("</textarea", "</textarea", $page['body']); // If the entry was written in 'markdown', and is now // being edited in the mobile editor, we must convert it. if ($page['convert_lb'] == "3") { $page['introduction'] = parse_intro_or_body($page['introduction'], false, $page['convert_lb'], true); $page['body'] = parse_intro_or_body($page['body'], false, $page['convert_lb'], true); } // Otherwise, if the entry was written in 'Plain XHTML' or 'WYSIWYG', and is now // being edited, there is not much more we // can do than strip out the <p> and <br/> tags to replace with linebreaks. if ($page['convert_lb'] == "0" || $page['convert_lb'] == "5") { $page['introduction'] = unparse_intro_or_body($page['introduction']); $page['body'] = unparse_intro_or_body($page['body']); } list($page['link'], $page['link_end']) = explode($page['uri'], $page['link']); } else { // Make a new entry. $page = array(); if ($_GET['chapter'] != "") { $page['chapter'] = intval($_GET['chapter']); } $user = $PIVOTX['session']->currentUser(); $page['user'] = $user['username']; $page['sortorder'] = 10; if ($PIVOTX['config']->get('default_post_status') != "") { $page['status'] = $PIVOTX['config']->get('default_post_status'); } $page['link'] = makePagelink("xxx"); list($page['link'], $page['link_end']) = explode('xxx', $page['link']); } $templates = templateOptions(templateList(), 'page', array('_sub_', '_aux_')); if ($_SERVER['REQUEST_METHOD'] == "GET") { // Show the screen.. // Show the screen.. $PIVOTX['template']->assign('templates', $templates); $PIVOTX['template']->assign('page', $page); $PIVOTX['template']->assign('chapters', $PIVOTX['pages']->getIndex()); $PIVOTX['template']->assign('pivotxsession', $PIVOTX['session']->getCSRF()); $PIVOTX['template']->assign('users', $PIVOTX['users']->getUsers()); $PIVOTX['template']->assign('pageuser', $PIVOTX['users']->getUser($entry['user'])); $PIVOTX['template']->assign("active", "pages"); renderTemplate('mobile/editpage.tpl'); } else { if ($_POST['code'] != $_GET['uid']) { $PIVOTX['events']->add('fatal_error', intval($_GET['uid']), "Tried to fake editing an entry"); echo "Code is wrong! B0rk!"; die; } // Make sure the current user is properly logged in, and that the request is legitimate $PIVOTX['session']->checkCSRF($_POST['pivotxsession']); // Sanitize the $_POST into an entry we can store $page = sanitizePostedPage($page); $page['convert_lb'] = "2"; // Make sure it's processed as 'Textile' $PIVOTX['extensions']->executeHook('page_edit_beforesave', $page); $new_id = $PIVOTX['pages']->savePage($page); $PIVOTX['extensions']->executeHook('page_edit_aftersave', $page); $PIVOTX['messages']->addMessage(sprintf(__('Your page "%s" was successfully saved.'), '<em>' . trimText($page['title'], 25) . '</em>')); // Remove the frontpages and entrypages from the cache. if ($PIVOTX['config']->get('smarty_cache')) { $PIVOTX['template']->clear_cache(); } // Update the search index for this page, but only if we're using flat files. if ($PIVOTX['db']->db_type == "flat") { $page['code'] = $page['uid'] = $new_id; updateSearchIndex($page, 'p'); } pagem_Pages(); } }
/** * Render a Page, using the template that it was set to. * * @see $Parser::render */ function renderPage() { global $PIVOTX; // The type of page we're rendering $this->modifier['pagetype'] = 'page'; $PIVOTX['template']->assign('pagetype', 'page'); $PIVOTX['template']->assign('pageuri', $this->modifier['uri']); // Execute a hook, if present. $PIVOTX['extensions']->executeHook('before_parse', $this->modifier); // If we're previewing, we need to set the posted values as the page, // otherwise get an entry from the DB. if (!empty($_GET['previewpage'])) { // Get the page from posted content. $page = sanitizePostedPage($page); } else { // Get the page from the DB.. $page = $PIVOTX['pages']->getPageByUri($this->modifier['uri']); // Handle the case when a page isn't found if (count($page) == 0) { // If we are using mod_rewrite, check if this is a call for a weblog. if ($PIVOTX['config']->get('mod_rewrite') > 0 && isset($_GET['rewrite'])) { if (in_array($this->modifier['uri'], $PIVOTX['weblogs']->getWeblognames())) { $this->renderWeblog(); return; } } // If it's not a call for a weblog, render the 404 page. $this->render404('page'); return; } } // For pages that aren't previewed we check if it's published and // whether it's displayed with the correct URL. (This is // foolproof, since $_GET['previewpage'] is only set if logged in.) if (!isset($_GET['previewpage'])) { // If the site uses mod_rewrite (and we aren't at the root), crufty URLs // should redirect (to avoid duplicate content). if ($PIVOTX['config']->get('mod_rewrite') > 0 && !$this->modifier['root'] && !isset($_GET['rewrite'])) { header("HTTP/1.1 301 Moved Permanently"); header("Location: " . $page['link']); die; } // If the page isn't published yet, we shouldn't show it. if ($page['status'] != 'publish') { $this->render404('page'); return; } } // Here we convert the " to ", if necessary, but only inside [[ tags ]] // Shouldn't we move this to pages_sql.php or pages_flat.php? $page['introduction'] = preg_replace_callback('/\\[\\[(.*)\\]\\]/ui', "fixquotescallback", $page['introduction']); $page['body'] = preg_replace_callback('/\\[\\[(.*)\\]\\]/ui', "fixquotescallback", $page['body']); // Set the 'code' we can use to invalidate this entry from cache. $this->code = "p" . $page['uid'] . "_"; // Set the uid in the modifier.. $this->modifier['uid'] = $page['uid']; // Set the page in $smarty as an array, as well as separate variables. $PIVOTX['template']->assign('page', $page); foreach ($page as $key => $value) { $PIVOTX['template']->assign($key, $value); } // Either use the specified page template, or the default page template // as specified in the (current) weblog. $template = $page['template']; if ($page['template'] == '-' || $page['template'] == '') { $template = $PIVOTX['weblogs']->get('', 'page_template'); } // Perhaps override the template, if we're allowed to do so. if (!empty($this->modifier['template']) && $PIVOTX['config']->get('allow_template_override') == 1) { $template = $this->modifier['template']; } // If the template isn't set, or doesn't exist.. if ($template == "" || !file_exists($PIVOTX['paths']['templates_path'] . $template)) { // .. we guesstimate a template, and show that.. $template = templateGuess('page'); } // We know what theme we're in, because of the used template. $PIVOTX['template']->assign('themename', dirname($template)); // Render and show the template. $this->parseTemplate($template); }