function handler_ajax_update($page) { $json = json_decode(Env::v('json')); $wiki = new Wiki($json->wid); $page->jsonAssign('success', true); try { $wiki->select(Wiki::SELECT_VERSION); $content = trim($json->content); if ($content != $wiki->content()) { $wiki->update($content); $wiki->select(Wiki::SELECT_VERSION); } $page->jsonAssign('html', $wiki->html()); } catch (Exception $e) { $page->jsonAssign('success', false); } return PL_JSON; }
public static function from($mixed, $insertIfNotExists = false) { try { $w = static::batchFrom(array($mixed))->first(); } catch (ItemNotFoundException $e) { if ($insertIfNotExists) { $w = new Wiki(array('name' => $mixed)); $w->insert(); $w->update(''); } else { throw $e; } } return $w; }
/** * We already knew beforehand what handle was requested and the ID was looked up. * @param int $id * @return array(title,content) */ function execute($id) { $w = new Wiki($this->db); $w->set($id); $this->dispatcher->controller->dispatcherObject = $w; $content = $w->revision->content; $handle = $w->handle; if (!$this->hasRights($_SESSION['access'], 'modify', $handle)) { return array($handle . ' - WikiCreate', 'No Permission'); } $args = $this->defaultArgs; $args['content'] = $content; // Lets save it. if (isset($_POST['save']) && !empty($_POST['wikicontent'])) { // Did it actually change? if (htmlentities($_POST['wikicontent']) !== $content) { $w->update(htmlentities($_POST['wikicontent'])); header('Location: ' . PATH_TO_DOCROOT . '/wiki/' . $handle); exit; } } elseif (isset($_POST['preview']) && !empty($_POST['wikicontent'])) { // But only if the content actually if (htmlentities($_POST['wikicontent']) !== $content) { $wv = new WikiView($this->dispatcher); list(, $args['preview_content']) = $wv->execute('', htmlentities($_POST['wikicontent']), false); $args['content'] = htmlentities($_POST['wikicontent']); $args['preview'] = $this->template->parse('preview', $args); } } $args['button_action'] = '/wiki/' . $handle; $args['button'] = 'Cancel'; $args['class'] = 'buttonmargin'; $buttons = $this->template->parse('button', $args); $args['handle'] = $handle; $args['formaction'] = '/wiki/' . $handle . '?action=edit'; $args['actiontype'] = 'Submit changes'; $args['buttons'] = $buttons; $this->siteArgs['edit']['active'] = 'active'; $this->addSiteArgs(); return array($handle . ' - WikiModify', $this->template->parse('create', $args)); }