$path = $GLOBALS['pie']['custom_path'] . "/template"; if (!is_dir($path)) { pieError("NoTemplates"); } if (!($dh = opendir($path))) { pieError("NoTemplates"); } $list = array(); while (($file = readdir($dh)) !== false) { if (!preg_match('/^\\w+$/', $file)) { continue; } if (!($dump = file_get_contents("{$path}/{$file}"))) { pieError("NoTemplates"); } $meta = pieExplodePage($dump); $list[$file] = $meta['title']; } closedir($dh); asort($list); // Present available templates. $l = ""; foreach ($list as $file => $info) { $l .= "<option value=\"{$file}\">" . htmlspecialchars($info) . "</option>\n"; } pieError("TemplateList", array('templates' => $l)); } else { // Create a new, empty page. $_REQUEST['source'] = ''; } // Initialize and print editing form.
} $preview = pieTempName("_preview"); // Lock the page. if (!$page->lock($GLOBALS['pie']['user'])) { pieError("PageLockError"); } // Retrieve source (by whatever means): if (@$_REQUEST['source']) { // Literal source provided. $_REQUEST['source'] = pieCleanString($_REQUEST['source']); } elseif (file_exists($preview)) { // Read the source from a temporary preview file. if (!($meta = file_get_contents($preview))) { pieError("SourceReadError"); } $meta = pieExplodePage($meta); foreach ($meta as $k => $v) { $_REQUEST[$k] = $v; } } else { // No source available. pieError("SourceEmpty"); } $_REQUEST['source'] = preg_replace('/\\x0a{3,}/s', "\n\n", @$_REQUEST['source']); // Prepare the previous version for examination. $current = new Page(); if ($page->exists($page->name)) { if (!$current->read($page->name, 0)) { pieError('SourceReadError'); } if (trim($current->source) == $_REQUEST['source']) {