Example #1
0
function pieRefererList($resource, $context)
{
    $page = new Page();
    $referers = array();
    // Traverse all pages and search for matching links.
    for ($item = $page->first(); $item; $item = $page->next()) {
        if (!$page->read($item, 0)) {
            return false;
        }
        // Check for aliases that refer to originals.
        if ($page->meta['type'] == "alias" && $page->meta['original'] == $resource) {
            $referers[$item] = true;
            continue;
        }
        if ($context == "page") {
            if (!$page->meta['pages']) {
                continue;
            }
            $links = explode(" ", $page->meta['pages']);
        } elseif ($context == "file") {
            if (!$page->meta['files']) {
                continue;
            }
            $links = explode(" ", $page->meta['files']);
        } else {
            return false;
        }
        if (!in_array($resource, $links)) {
            continue;
        }
        // $item refers to $resource.
        $referers[$item] = true;
    }
    $referers = array_keys($referers);
    sort($referers);
    return $referers;
}
Example #2
0
    }
    fclose($f);
} elseif (file_exists($preview)) {
    // Read the data from the temporary preview file.
    if (!($dump = file_get_contents($preview))) {
        pieError("SourceReadError");
    }
    $meta = pieExplodePage($dump);
    $_REQUEST['source'] = trim($meta['source']);
} else {
    // No source available.
    pieError("SourceReadError");
}
// Handle partial updates.
if (@$_REQUEST['section'] > 0 && $page->exists(@$_REQUEST['page'])) {
    if (!$page->read($_REQUEST['page'], 0)) {
        pieError('SourceReadError');
    }
    if ($page->meta['type'] != 'full' && $page->meta['type'] != 'shadow') {
        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));
}
Example #3
0
    $hint_edit = $GLOBALS['pie']['locale']->key("Edit");
    $ip = pieMakeString('[[$^icon_link]]');
    foreach ($referers as $name => $i) {
        $n++;
        print '<tr class="' . ($n % 2 ? "oddRow" : "evenRow") . '">' . '<td>' . pieMakeLink(htmlspecialchars($name), array('page' => $name), array('class' => "itemLink")) . '</td>' . "<td style=\"text-align: right;\">{$i}</td>" . '<td>' . pieMakeLink("<img src=\"{$ip}/information.png\" />", array('action' => "pageinfo", 'page' => $name), array('title' => $hint_info)) . '</td>' . '<td>' . pieMakeLink("<img src=\"{$ip}/page_edit.png\" />", array('action' => "edit", 'page' => $name), array('title' => $hint_edit)) . '</td>' . "</tr>\n";
    }
    print "</table>\n";
} elseif (@$_REQUEST['mode'] == "links") {
    // Walk all pages and examine their links.
    // Collect a list of _links_, i. e. destinations of broken links.
    $page = new Page();
    $file = new File();
    $deadpages = array();
    $deadfiles = array();
    for ($name = $page->first(); $name; $name = $page->next()) {
        if (!$page->read($name, 0)) {
            pieError("SourceReadError");
        }
        if ($page->meta['pages']) {
            // There are page links that are to be checked.
            $list = explode(" ", $page->meta['pages']);
            foreach ($list as $i) {
                if (!$page->exists($i)) {
                    $deadpages[$i]++;
                }
            }
        }
        if ($page->meta['files']) {
            // There are file links that are to be checked.
            $list = explode(" ", $page->meta['files']);
            foreach ($list as $i) {
Example #4
0
$_REQUEST['page'] = pieGetOption(@$_REQUEST['page']);
$page = new Page();
$page->name = $_REQUEST['page'];
// Sanity check:
if (!$page->isValidName($_REQUEST['page'])) {
    pieError("PageNameInvalid");
}
if (!$page->exists($_REQUEST['page'])) {
    pieError("PageNotFound");
}
if (intval($_REQUEST['stamp']) > 0) {
    $stamp = $_REQUEST['stamp'];
} else {
    $stamp = 0;
}
$page->read($_REQUEST['page'], $stamp);
$stamp = $page->meta['stamp'];
// Check for alias:
if ($page->meta['type'] == "alias") {
    pieError("AliasRedirect", array('page' => htmlspecialchars($page->meta['original']), 'alias' => htmlspecialchars($_REQUEST['page'])));
}
// Prepare output:
$data = array('page_count' => 0, 'file_count' => 0);
$data['date'] = date($GLOBALS['pie']['time_format'], $page->meta['stamp']);
$data['author'] = htmlspecialchars($page->meta['author']);
$data['comment'] = "&mdash;";
if ($page->meta['comment']) {
    $data['comment'] = htmlspecialchars($page->meta['comment']);
}
$history = $page->history($page->name);
$data['history_count'] = count($history);
Example #5
0
 public function read($name = "Article")
 {
     parent::read($name);
 }
Example #6
0
    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']) {
        // No changes have been made.
        pieError('NoChanges');
    }
}
// Handle section updates.
$_REQUEST['section'] = intval(@$_REQUEST['section']);
if ($_REQUEST['section'] > 0 && $page->exists($page->name)) {
    if ($current->meta['type'] == 'alias') {
        pieError('SectionNotFound');
    }
    // Determine the text chunks that come before and after the edited
    // section.
Example #7
0
print '<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
';
if (file_exists($GLOBALS['pie']['custom_path'] . '/rss_head.xml')) {
    include $GLOBALS['pie']['custom_path'] . '/rss_head.xml';
} else {
    print '		<title>RSS Feed</title>
		<link>http://' . $_SERVER['SERVER_NAME'] . '/</link>
		<language>' . $GLOBALS['pie']['default_locale'] . '</language>
		<generator>pie</generator>
		<webMaster>' . $_SERVER['SERVER_ADMIN'] . '</webMaster>
';
}
list($stamp) = explode("\t", $data[0]);
print "\t\t<pubDate>" . date('r', $stamp) . "</pubDate>\n";
foreach ($data as $i) {
    list($stamp, $p) = explode("\t", $i, 2);
    if (!$page->read($p, 0)) {
        continue;
    }
    if ($page->meta['type'] == 'alias') {
        continue;
    }
    if (substr($GLOBALS['pie']['page_link'], -10) != '?[[$page]]') {
        $p = urlencode($p);
    }
    $link = 'http://' . $_SERVER['SERVER_NAME'] . ($GLOBALS['pie']['page_link'][0] == '/' ? '' : '/') . pieMakeString($GLOBALS['pie']['page_link'], array('page' => $p));
    print "\t\t<item>\n" . "\t\t\t<title>" . htmlspecialchars($page->meta['title']) . "</title>\n" . "\t\t\t<link>" . $link . "</link>\n" . "\t\t\t<description>" . ($page->meta['comment'] ? htmlspecialchars($page->meta['comment']) : '') . "</description>\n" . "\t\t\t<author>" . htmlspecialchars($page->meta['author']) . "</author>\n" . "\t\t\t<pubDate>" . date('r', $page->meta['stamp']) . "</pubDate>\n" . "\t\t\t<guid>{$link}</guid>\n" . "\t\t</item>\n";
}
print "\t</channel>\n</rss>\n";
Example #8
0
include_once "{$lib}/share/stdio.php";
include_once "{$lib}/share/string.php";
pieLoadLocale();
pieHead();
if (@$_REQUEST['page']) {
    // Preparations for pages.
    $_REQUEST['page'] = pieGetOption($_REQUEST['page']);
    $resource = new Page();
    $resource->name = $_REQUEST['page'];
    if (!$resource->isValidName($_REQUEST['page'])) {
        pieError("PageNameInvalid");
    }
    if (!$resource->exists($_REQUEST['page'])) {
        pieError("PageNotFound");
    }
    if (!$resource->read($_REQUEST['page'], 0)) {
        pieError("SourceReadError");
    }
    if ($resource->meta['type'] == "alias") {
        pieError("AliasRedirect", array('page' => htmlspecialchars($resource->meta['original']), 'alias' => htmlspecialchars($_REQUEST['page'])));
    }
    $context = 'page';
    $history = $resource->history($_REQUEST['page']);
} elseif (@$_REQUEST['file']) {
    // Preparations for files.
    $_REQUEST['file'] = pieGetOption($_REQUEST['file']);
    $resource = new File();
    $resource->name = $_REQUEST['file'];
    if (!$resource->isValidName($_REQUEST['file'])) {
        pieError("FileNameInvalid");
    }
Example #9
0
    }
    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("AliasRedirect", array('page' => htmlspecialchars($page->meta['original']), 'alias' => htmlspecialchars($_REQUEST['page'])));
}
// Format and display the page source:
$source = $page->source;
$source = str_replace('\\[', chr(1), $source);
$source = str_replace('\\]', chr(2), $source);
$source = nl2br(hilightBrackets($source));
$source = str_replace(chr(1), '\\[', $source);
$source = str_replace(chr(2), '\\]', $source);
pieNotice("SourceOfPage", array('source' => $source));
pieTail();
Example #10
0
 function writePage($name, $meta)
 {
     if (!$meta['stamp']) {
         $meta['stamp'] = time();
     }
     $page = new Page();
     if (!$page->isValidName($name)) {
         return false;
     }
     if (!$page->exists($name)) {
         return $this->_writeFullSource($name, $meta);
     }
     // Determine the current diff level.
     $work = $meta;
     $work['parent'] = 0;
     for ($level = 0; $work['type'] != 'full'; $level++) {
         if (!$page->read($name, $work['parent'])) {
             return false;
         }
         $work = $page->meta;
     }
     $max = intval($GLOBALS['pie']['max_diff_level']);
     if ($max > 0 && $level > $max) {
         return $this->_writeFullSource($name, $meta);
     }
     // Determine the version to be referred to as parent.
     if (!($current = $this->readPage($name, 0))) {
         return false;
     }
     $meta['parent'] = $current['stamp'];
     // Create a diff between the latest version and the new one.
     if (!($diff = $this->diff($current['source'], $meta['source']))) {
         return false;
     }
     if (strlen($meta['source']) - strlen($diff) < 100) {
         // The diff is not much smaller (or even larger)
         // than the original source.
         // Write a full version instead of just a diff.
         unset($meta['parent']);
         return $this->_writeFullSource($name, $meta);
     }
     // Note:
     // At this stage, it is decided to write a diff instead
     // of a full version.
     // If the current page is an alias, delete it altogether,
     // to be replaced by a real page with the current data.
     if ($current['type'] == 'alias') {
         if (!$page->delete($name)) {
             return false;
         }
     }
     // Replace the latest shadow, if any.
     $replace = false;
     if ($current['type'] == 'shadow') {
         $replace = true;
     }
     // Write a diff.
     $page->name = $name;
     $page->source = $diff;
     $full = $meta['source'];
     unset($meta['source']);
     $meta['type'] = 'diff';
     $page->meta = $meta;
     if (!$page->write($replace)) {
         return false;
     }
     // Create an additional shadow record including the full source.
     $page->source = $full;
     $page->meta['type'] = 'shadow';
     return $page->write(false);
 }
Example #11
0
    $_REQUEST['file'] = pieGetOption($_REQUEST['file']);
    $target = $_REQUEST['file'];
    $context = "file";
} else {
    pieError("ActionInvalid");
}
// Page or file?
if ($context == "page") {
    $object = new Page();
    if (!$object->isValidName($target)) {
        pieError("PageNameInvalid");
    }
    if (!$object->exists($target)) {
        pieError("PageNotFound");
    }
    if (!$object->read($target, 0)) {
        pieError("SourceReadError");
    }
    // Lock the page.
    if (!$object->lock($GLOBALS['pie']['user'])) {
        pieError("PageLockError");
    }
} elseif ($context == "file") {
    $object = new File();
    if (!$object->isValidName($target)) {
        pieError("FileNameInvalid");
    }
    if (!$object->exists($target)) {
        pieError("FileNotFound");
    }
    if (!$object->read($target, 0)) {
Example #12
0
    $_REQUEST['file'] = pieGetOption($_REQUEST['file']);
    $source = $_REQUEST['file'];
    $context = "file";
} else {
    pieError("ActionInvalid");
}
// Validate the source: page or file?
if ($context == "page") {
    $object = new Page();
    if (!$object->isValidName($source)) {
        pieError("PageNameInvalid");
    }
    if (!$object->exists($source)) {
        pieError("PageNotFound");
    }
    if (!$object->read($source, 0)) {
        pieError("SourceReadError");
    }
    // Lock the page.
    if (!$object->lock($GLOBALS['pie']['user'])) {
        pieError("PageLockError");
    }
} elseif ($context == "file") {
    $object = new File();
    if (!$object->isValidName($source)) {
        pieError("FileNameInvalid");
    }
    if (!$object->exists($source)) {
        pieError("FileNotFound");
    }
    if (!$object->read($source, 0)) {
Example #13
0
        pieNotice('PageNotFound');
        pieError('GotoForm');
    }
    // Print the pages:
    $n = 0;
    pieNotice("TableHead");
    sort($data);
    foreach ($data as $name) {
        $n++;
        print '<tr class="' . ($n % 2 ? "oddRow" : "evenRow") . "\">\n" . "<td>" . pieMakeLink(htmlspecialchars($name), array('action' => "goto", 'page' => $name), array('class' => "itemLink")) . "</td>\n" . "</tr>\n";
    }
    print "</table>\n";
    pieTail();
    exit;
}
if (!$page->read($string, 0)) {
    pieHead();
    pieError("SourceReadError");
}
// Handle aliases:
if ($page->meta['type'] == "alias") {
    $original = $page->meta['original'];
    if ($GLOBALS['pie']['auto_redirect']) {
        header("Location: " . pieMakeString($GLOBALS['pie']['redirect_base_url']) . "?action=goto&page=" . rawurlencode($original) . "&referer=" . rawurlencode($string));
        exit;
    } else {
        pieHead();
        pieError("AliasRedirect", array('page' => htmlspecialchars($original), 'alias' => htmlspecialchars($string)));
    }
}
// Compile source: