function write($replace) { // Prepare data. $this->source = pieCleanString($this->source); $this->source = preg_replace('/\\x0a{3,}/s', "\n\n", $this->source); $this->source = rtrim($this->source) . "\n\n"; $this->meta['size'] = strlen($this->source); if (!$this->meta['stamp']) { $this->meta['stamp'] = time(); } if (!$this->meta['type']) { $this->meta['type'] = 'full'; } // Write source and meta data to database. if (!($out = pieTempFile($this->name))) { return false; } fwrite($out, pieImplodePage($this->meta, $this->source)); // Append any previous versions if ($this->exists($this->name)) { if (!($in = fopen($this->_filePath($this->name), 'r'))) { fclose($out); unlink(pieTempName($this->name)); return false; } while ($info = $this->_nextVersion($in)) { if ($replace) { $replace = false; continue; } // Remove redundant data before updating. $source = $info['source']; unset($info['source']); unset($info['pages']); unset($info['files']); fwrite($out, pieImplodePage($info, $source)); } fclose($in); } // Activate new file fclose($out); touch(pieTempName($this->name), $this->meta['stamp']); return rename(pieTempName($this->name), $this->_filePath($this->name)); }
pieExpireDirectory($GLOBALS['pie']['run_path'] . "/temp", $GLOBALS['pie']['edit_timeout']); } $_REQUEST['cols'] = 80; $_REQUEST['rows'] = 20; $_REQUEST['author'] = $GLOBALS['pie']['user']; $pref = new UserPref(); if (($t = $pref->read($GLOBALS['pie']['user'], "cols")) !== false) { $_REQUEST['cols'] = $t; } if (($t = $pref->read($GLOBALS['pie']['user'], "rows")) !== false) { $_REQUEST['rows'] = $t; } // Determine the source of the source (so to speak). if ($_POST['source']) { // User provided input via HTTP request. $_REQUEST['source'] = pieCleanString($_REQUEST['source']); $_REQUEST['title'] = pieGetOption($_REQUEST['title']); $_REQUEST['comment'] = pieGetOption($_REQUEST['comment']); } elseif (file_exists($preview)) { // Read source and meta data from temporary preview file. if (!($dump = file_get_contents($preview))) { pieError("SourceReadError"); } $meta = pieExplodePage($dump); foreach (array('source', 'title', 'comment') as $i) { $_REQUEST[$i] = $meta[$i]; } unset($meta); } elseif ($page->exists($_REQUEST['page'])) { // The page already exists. Use and edit the existing source. $diff = new Increment();
if (preg_match('/(\\A|.*\\x0A)([<>!;=\\|\\*\\+:]+)(.*)/s', $string, $m)) { return hilightBrackets($m[1]) . '<span class="hilightSelector">' . htmlspecialchars($m[2]) . '</span>' . hilightBrackets($m[3]); } if (preg_match('/(.*)\\[\\[([^\\[\\]\\|]+)((\\|)([^\\[\\]]+))?\\]\\](.*)/s', $string, $m)) { return hilightBrackets($m[1]) . '<span class="hilightHide">[[</span><span class="hilightLink">' . htmlspecialchars($m[2]) . '</span><span class="hilightHide">' . $m[4] . '</span>' . htmlspecialchars($m[5]) . '<span class="hilightHide">]]</span>' . hilightBrackets($m[6]); } if (preg_match('/(.*)\\[(\\w+):([^\\[\\]\\|]*)(\\|[^\\[\\]]+)?\\](.*)/s', $string, $m)) { return hilightBrackets($m[1]) . '<span class="hilightHide">[</span><span class="hilightCommand">' . htmlspecialchars($m[2]) . '</span><span class="hilightHide">:' . htmlspecialchars($m[3]) . '</span>' . htmlspecialchars($m[4]) . '<span class="hilightHide">]</span>' . hilightBrackets($m[5]); } if (preg_match('/(.*)\\[([\\x21-\\x2F\\x3A-\\x40])([^\\[\\]]+)\\](.*)/s', $string, $m)) { return hilightBrackets($m[1]) . '<span class="hilightHide">[</span><span class="hilightSelector">' . htmlspecialchars($m[2]) . '</span>' . htmlspecialchars($m[3]) . '<span class="hilightHide">]</span>' . hilightBrackets($m[4]); } return htmlspecialchars($string); } pieHead(); $_REQUEST['page'] = pieCleanString(@$_REQUEST['page']); $page = new Page(); $page->name = $_REQUEST['page']; if (!$page->isValidName($_REQUEST['page'])) { pieError("PageNameInvalid"); } if (!$page->exists($_REQUEST['page'])) { pieError("PageNotFound"); } if (!(($_REQUEST['stamp'] = intval($_REQUEST['stamp'])) > 0)) { $_REQUEST['stamp'] = 0; } if (!$page->read($_REQUEST['page'], $_REQUEST['stamp'])) { pieError("SourceReadError"); } if ($page->meta['type'] == "alias") {
pieError('SectionNotFound'); } // Determine the text that come before and after the edited section. $section = new Section(); if (($p = $section->offset($page->source, $_REQUEST['section'])) === false) { pieError('SectionNotFound'); } if (($old = $section->extract($page->source, $_REQUEST['section'])) === false) { pieError('SectionNotFound'); } $_REQUEST['source'] = substr($page->source, 0, $p) . rtrim($_REQUEST['source']) . "\n\n" . substr($page->source, $p + strlen($old)); } // Parse and compile the source. $data = array(); $compiler = new htmlCompiler(); $compiler->source = pieCleanString($_REQUEST['source']); if ($GLOBALS['pie']['page_header'] || $GLOBALS['pie']['page_footer']) { // Header and footer require meta data. $compiler->meta = array('title' => pieGetOption($_REQUEST['title']), 'author' => $GLOBALS['pie']['user'], 'stamp' => time()); } if (!$compiler->compile()) { $data['error'] = "<ul>\n"; foreach ($compiler->error as $i) { $data['error'] .= "<li class=\"warning\">{$i}</li>\n"; } $data['error'] .= "</ul>\n"; pieNotice("CompilerError", $data); } // Present the output: $data['preview'] = $compiler->output; pieNotice("ApprovePreview", $data);
function pieGetOption($string) { return trim(preg_replace('/\\x0A+/', ' ', pieCleanString($string))); }