function makeAlias($original) { if (file_exists($this->_filePath($this->name))) { // A file (i. e. page or alias) with this name exists. if (!($info = $this->_current($this->name))) { return false; } // We cannot create an alias whose name is already // taken by a page. if ($info['type'] != 'alias') { return false; } } // Prepare all necessary meta data, complementing the // customized entries. if (!$this->meta['stamp']) { $this->meta['stamp'] = time(); } $this->meta['type'] = 'alias'; $this->meta['original'] = pieBeautifyName($original); if (!($f = fopen($this->_filePath($this->name), 'w'))) { return false; } fwrite($f, pieImplodePage($this->meta, '')); fclose($f); return true; }
function expandCommand($string) { // Split the components, i. e. the command and its argument(s) $string = trim($string); if (strpos($string, $GLOBALS['pie']['link_text_delimiter']) > 0) { list($cmd, $data) = explode($GLOBALS['pie']['link_text_delimiter'], $string, 2); $data = preg_split('/\\s+/', $data); } else { $cmd = preg_replace('/\\s+/', ' ', $string); $data = array(); } if (!preg_match('/^(\\w+):(.+)$/', $cmd, $match)) { return $string; } $cmd = mb_strtolower($match[1]); $arg = $match[2]; if (trim($data[0]) == '') { $data = array(); } // Command multiplexer: switch ($cmd) { case 'page': case $this->commands['Page']: // Link placement via command: // [page:<PageName> ...] return $this->expandLink($arg . $GLOBALS['pie']['link_text_delimiter'] . implode(' ', $data)); break; case 'link': case $this->commands['Link']: // Enforce link to external resource: $text = htmlspecialchars(implode(' ', $data)); if (count($data)) { return '<a href="' . htmlspecialchars($arg) . '" title="' . htmlspecialchars($arg) . '" target="_blank">' . htmlspecialchars(implode(' ', $data)) . '</a>'; } else { return '<a href="' . htmlspecialchars($arg) . '" target="_blank">' . htmlspecialchars($arg) . '</a>'; } break; case 'mail': case 'mailto': // Link to an e-mail address: // [mail:<Address> ...] if (preg_match('/^[\\w\\.\\-_]+@' . HOST_PATTERN . '$/', $arg)) { if (count($data)) { $alt = htmlspecialchars(implode(' ', $data)); } else { $alt = htmlspecialchars($arg); } return "<a href=\"mailto:{$arg}\" class=\"mailLink\">{$alt}</a>"; } else { $this->trapError('InvalidMailLink', $arg); return ''; } break; case 'file': case $this->commands['File']: // Link to a local file: // [file:<FileName> ...] if ($path = $this->expandGroupPath($GLOBALS['pie']['file_link_pattern'], $arg)) { if (count($data) > 0) { $text = implode(' ', $data); } else { if (preg_match('/^(.+)\\.[0-9A-Za-z]{1,5}$/', $path, $match)) { $text = $match[1]; } else { $text = $path; } } $path = pieBeautifyName($path); $this->files[$path]++; return pieMakeLink(htmlspecialchars($text), array('action' => 'download', 'file' => $path), array('class' => 'fileLink', 'title' => htmlspecialchars($path))); } else { $this->trapError('InvalidFileLink', $arg); return ''; } break; case 'image': case $this->commands['Image']: // Embeds a local file as an image: // [image:<ImageName> ...] if (preg_match('/^' . URL_PATTERN . '$/', $arg)) { return $this->expandImage($arg, array_map('htmlspecialchars', $data)); } elseif ($path = $this->expandGroupPath($GLOBALS['pie']['file_link_pattern'], $arg)) { $path = pieBeautifyName($path); $this->files[$path]++; return $this->expandImage(pieMakeString($GLOBALS['pie']['media_link'], array('action' => 'image', 'file' => urlencode($path))), array_map('htmlspecialchars', $data)); } else { $this->trapError('InvalidImageLink', $arg); return ''; } break; case 'figure': case $this->commands['Figure']: case 'preview': case $this->commands['Preview']: // Embeds a thumbnail of an image that acts as a link // to the full-sized version. // [figure:<ImageName> ...] unset($caption); if (count($data)) { $info = htmlspecialchars(implode(' ', $data)); } $data = array('.figure', $this->locale->key('ShowFullSized')); $caption = $info ? "<p class=\"caption\">{$info}</p>\n" : ''; if (preg_match('%^https?://%', $arg)) { return "<div class=\"figure\">\n" . "<p><a href=\"{$arg}\" target=\"_blank\" title=\"" . $this->locale->key('ShowExternalResource') . "\"><img src=\"{$arg}\" alt=\"{$info}\" width=\"" . $GLOBALS['pie']['max_image_size'] . "\" /></a></p>\n" . "{$caption}</div>\n"; } elseif ($path = $this->expandGroupPath($GLOBALS['pie']['file_link_pattern'], $arg)) { $path = pieBeautifyName($path); $this->files[$path]++; $link = pieMakeString($GLOBALS['pie']['base_link'] . 'action=image&file=' . urlencode($path)); $link = "<img src=\"{$link}\" alt=\"" . $GLOBALS['pie']['media_alt_text'] . '" title="' . $this->locale->key('ShowFullSized') . '" />'; $link = pieMakeLink($link, array('action' => 'dump', 'file' => $path), array('class' => 'figure', 'target' => '_blank')); return "<div class=\"figure\">\n<p>{$link}</p>\n{$caption}</div>\n"; } else { $this->trapError('InvalidImageLink', $arg); return ''; } break; case 'embed': case 'media': case $this->commands['Embed']: case $this->commands['Media']: // Embeds a local file as media: // [embed:<FileName> ...] $spec = ''; if (preg_match('/^' . URL_PATTERN . '$/', $arg)) { $path = htmlspecialchars($arg); } elseif ($path = $this->expandGroupPath($GLOBALS['pie']['file_link_pattern'], $arg)) { $path = pieBeautifyName($path); $this->files[$path]++; $path = pieMakeString($GLOBALS['pie']['media_link'], array('action' => 'dump', 'file' => urlencode($path))); } else { $this->trapError('InvalidEmbeddedObject', $arg); return ''; } foreach ($data as $i) { if (preg_match('/^(\\w+)="?([^"]+)"?$/', $i, $match)) { $spec .= " {$match['1']}=\"" . htmlspecialchars($match[2]) . '"'; } } return "<embed src=\"{$path}\" alt=\"" . $GLOBALS['pie']['media_alt_text'] . '"' . ($spec ? $spec : "") . "></embed>"; break; case 'anchor': case $this->commands['Anchor']: // Local anchor // [anchor:<AnchorName>] return '<a name="' . htmlspecialchars($arg) . '"></a>'; break; case 'class': case $this->commands['Class']: case 'style': case $this->commands['Style']: // Class definition for a local environment: // a span, if there are arguments to be applied to // or a customization for the next block. // [class:<ClassName> ...] if (count($data)) { return "<span class=\"{$arg}\">" . htmlspecialchars(implode(" ", $data)) . "</span>"; } elseif ($arg) { $this->custom['class'] = htmlspecialchars($arg); } return ''; break; case 'begin': case $this->commands['Begin']: // Begin of a customized environmental DIV. // [begin:<kind_of_environment> ...] if ($arg[0] == '.') { // Named CSS class. array_unshift($this->nest, 'div'); return '<div class="' . substr($arg, 1) . "\">\n"; } elseif ($arg == 'figure' || $arg == $this->locale->key('Figure')) { // Figure. array_unshift($this->nest, 'div'); return "<div class=\"figure\">\n"; } else { // Unspecified or unknown block type. array_unshift($this->nest, 'div'); return "<div>\n"; } break; case 'end': case $this->commands['End']: // Close an customized environmental context block. // [end:block] if (count($this->nest)) { array_shift($this->nest); return $this->endEnvironment() . "</div>\n"; } else { $this->trapError('NestingNotWellFormed', $arg); return ''; } break; case 'footnote': case $this->commands['Footnote']: array_push($this->footnotes, $arg); $t = count($this->footnotes); if (count($data)) { return "<a name=\"ref{$t}\"></a><a href=\"#footnote{$t}\" title=\"" . $this->locale->key("Footnote") . '">' . htmlspecialchars(implode(" ", $data)) . "</a>"; } else { return "<a name=\"ref{$t}\"></a><a href=\"#footnote{$t}\" title=\"" . $this->locale->key("Footnote") . "\">[{$t}]</a>"; } break; case 'abbr': case $this->commands['Abbr']: return '<abbr title="' . htmlspecialchars(implode(' ', $data)) . '">' . htmlspecialchars($arg) . '</abbr>'; break; default: $this->trapError('UnknownCommand', $cmd); return ''; break; } $this->trapError('InvalidCommand', $cmd); return ''; }
* Edit the contents of a page. */ include_once "{$lib}/class/page.php"; include_once "{$lib}/class/locale.php"; include_once "{$lib}/class/diff.php"; include_once "{$lib}/class/section.php"; include_once "{$lib}/class/userpref.php"; include_once "{$lib}/share/auth.php"; include_once "{$lib}/share/stdio.php"; include_once "{$lib}/share/storage.php"; include_once "{$lib}/share/string.php"; include_once "{$lib}/compiler/html.php"; pieLoadLocale(); pieRequireUser(); pieHead("edit"); $_REQUEST['page'] = pieBeautifyName(pieGetOption(@$_REQUEST['page'])); $_REQUEST['section'] = intval(@$_REQUEST['section']); $_REQUEST['stamp'] = intval(@$_REQUEST['stamp']); if ($_REQUEST['stamp'] < 1) { $_REQUEST['stamp'] = 0; } $page = new Page(); $page->name = $_REQUEST['page']; $preview = pieTempName("_preview"); // Check validity. if (!$page->isValidName($page->name)) { pieError("PageNameInvalid"); } if (!$page->lock($GLOBALS['pie']['user'])) { pieError("PageLockError"); }
* Display a former version of a page. */ if (intval(@$_REQUEST['stamp']) < 1) { // Bogus input => display the current version of the page. include "{$lib}/action/page.php"; exit; } $_REQUEST['stamp'] = intval(@$_REQUEST['stamp']); include_once "{$lib}/class/page.php"; include_once "{$lib}/class/diff.php"; include_once "{$lib}/share/stdio.php"; include_once "{$lib}/compiler/html.php"; pieHead(); // Sanity checks: $_REQUEST['page'] = pieGetOption(@$_REQUEST['page']); $_REQUEST['page'] = pieBeautifyName(@$_REQUEST['page']); $page = new Page(); $diff = new Increment(); if (!$page->isValidName(@$_REQUEST['page'])) { pieError("PageNameInvalid"); } if (!$page->exists(@$_REQUEST['page'])) { pieError("PageNotFound"); } if (!($meta = $diff->readPage($_REQUEST['page'], $_REQUEST['stamp']))) { pieError("SourceVersionMissing"); } if ($meta['type'] == "alias") { pieError("AliasRedirect", array('page' => htmlspecialchars($meta['original']), 'alias' => htmlspecialchars($_REQUEST['page']))); } // Compile and display source:
$context = 'page'; } elseif (@$_REQUEST['file']) { $_REQUEST['file'] = pieGetOption($_REQUEST['file']); $original = $_REQUEST['file']; $resource = new File(); if (!$resource->isValidName($original)) { pieError("FileNameInvalid"); } $context = 'file'; } else { pieError("ActionInvalid"); } // Verify the alias: if (@$_REQUEST['alias']) { $_REQUEST['alias'] = pieGetOption($_REQUEST['alias']); $_REQUEST['alias'] = pieBeautifyName($_REQUEST['alias']); $alias = $_REQUEST['alias']; if (!$resource->isValidName($alias)) { pieError("AliasNameInvalid"); } } // This is where the real work starts. // Decide what to do: if (@$original && @$alias && @$_REQUEST['create']) { if ($resource->exists($alias)) { // A resource with the name of the alias already exists. pieError("NameCollision", array('context' => $context, 'original' => htmlspecialchars($original), 'alias' => htmlspecialchars($alias))); } // Create a new alias for the specified resource. $resource->meta = array('author' => $GLOBALS['pie']['user']); $resource->name = $alias;
} if ($file->meta['comment']) { $data['comment'] = htmlspecialchars($file->meta['comment']); } else { unset($data['comment']); } } } // Print the upload form. pieError("UploadForm", $data); } // Handle the file upload. if (!$file->isValidName($name)) { pieError("FileNameInvalid"); } $name = pieBeautifyName($name); if (!is_uploaded_file($_FILES['upload']['tmp_name'])) { pieError("UploadError"); } if (!move_uploaded_file($_FILES['upload']['tmp_name'], pieTempName("_upload"))) { pieError("FileWriteError"); } if ($file->exists($name)) { // A file with the name already exists. if (!$file->read($name, 0)) { pieError("FileReadError"); } if ($file->meta['author'] == $GLOBALS['pie']['user'] && !@$_REQUEST['append']) { // The upload is an update by the same user. // Delete the previous version before saving the new one. if (!$file->replace($name)) {
} if (!$object->exists($source)) { pieError("FileNotFound"); } if (!$object->read($source, 0)) { pieError("FileReadError"); } } else { pieError("ActionInvalid"); } // Validate the destination: if (!isset($_REQUEST['newname'])) { pieError("RenameForm", array('source' => $source)); } $destination = pieGetOption($_REQUEST['newname']); $destination = pieBeautifyName($destination); $_REQUEST['newname'] = $destination; if (!$object->isValidName($destination)) { pieError("NewNameInvalid"); } if ($object->exists($destination)) { pieError("DestinationExists"); } // Check permissions to delete the resource: $history = $object->history($object->name); if (@$_REQUEST['approve']) { // The user asked to rename the resource, no matter what. if ($GLOBALS['pie']['deny_removal'] && !pieIsSuperuser($GLOBALS['pie']['user'])) { pieError("ActionNotPermitted"); } } else {
function printOutput($output) { if ($GLOBALS['pie']['context'] == 'edit') { print "<div class=\"output\">\n{$output}</div>\n"; } else { print $output; } pieTail(); exit; } // Start here: if (@$_REQUEST['string']) { $string = pieBeautifyName(pieGetOption($_REQUEST['string'])); $_REQUEST['page'] = $string; } elseif (@$_REQUEST['page']) { $string = pieBeautifyName(pieGetOption($_REQUEST['page'])); } else { pieHead(); pieError("GotoForm"); } $page = new Page(); if (!$page->isValidName($string)) { pieHead(); pieError("PageNameInvalid"); } if ($GLOBALS['pie']['page_caching']) { $cache = new Cache(); $cid = $cache->key('page', array('page' => $string)); if ($cache->exists($cid)) { $output = file_get_contents($cache->file($cid)); pieHead();