Ejemplo n.º 1
0
function plugin_diff_view($page)
{
    global $script, $hr;
    //	global $_msg_notfound, $_msg_goto, $_msg_deleted, $_msg_addline, $_msg_delline;
    //	global $_title_diff, $_title_diff_delete;
    if (auth::check_role('safemode')) {
        die_message('PKWK_SAFE_MODE prohibits this');
    }
    $_msg_notfound = _('The page was not found.');
    $_msg_addline = _('The added line is <span class="diff_added">THIS COLOR</span>.');
    $_msg_delline = _('The deleted line is <span class="diff_removed">THIS COLOR</span>.');
    $_msg_goto = _('Go to $1.');
    $_msg_deleted = _(' $1 has been deleted.');
    $_title_diff = _('Diff of $1');
    $_title_diff_delete = _('Deleting diff of $1');
    $r_page = rawurlencode($page);
    $s_page = htmlspecialchars($page);
    $menu = array('<li>' . $_msg_addline . '</li>', '<li>' . $_msg_delline . '</li>');
    $is_page = is_page($page);
    if ($is_page) {
        $menu[] = ' <li>' . str_replace('$1', '<a href="' . get_page_uri($page) . '">' . $s_page . '</a>', $_msg_goto) . '</li>';
    } else {
        $menu[] = ' <li>' . str_replace('$1', $s_page, $_msg_deleted) . '</li>';
    }
    $filename = DIFF_DIR . encode($page) . '.txt';
    if (file_exists($filename)) {
        // if (! PKWK_READONLY) {
        if (!auth::check_role('readonly')) {
            $menu[] = '<li><a href="' . $script . '?cmd=diff&amp;action=delete&amp;page=' . $r_page . '">' . str_replace('$1', $s_page, $_title_diff_delete) . '</a></li>';
        }
        $source = join('', file($filename));
        auth::is_role_page($source);
        $msg = '<pre>' . diff_style_to_css(htmlspecialchars($source)) . '</pre>' . "\n";
    } else {
        if ($is_page) {
            $source = join('', get_source($page));
            auth::is_role_page($source);
            $diffdata = trim(htmlspecialchars($source));
            $msg = '<pre><span class="diff_added">' . $diffdata . '</span></pre>' . "\n";
        } else {
            return array('msg' => $_title_diff, 'body' => $_msg_notfound);
        }
    }
    $menu = join("\n", $menu);
    $body = <<<EOD
<ul>
{$menu}
</ul>
{$hr}
EOD;
    return array('msg' => $_title_diff, 'body' => $body . $msg);
}
Ejemplo n.º 2
0
function plugin_source_action()
{
    global $vars;
    //, $_source_messages;
    // if (PKWK_SAFE_MODE) die_message('PKWK_SAFE_MODE prohibits this');
    if (auth::check_role('safemode')) {
        die_message('PKWK_SAFE_MODE prohibits this');
    }
    $page = isset($vars['page']) ? $vars['page'] : '';
    $vars['refer'] = $page;
    if (!is_page($page) || !check_readable($page, false, false)) {
        return array('msg' => _(' $1 was not found.'), 'body' => _('cannot display the page source.'));
    }
    $source = join('', get_source($page));
    auth::is_role_page($source);
    return array('msg' => _('Source of  $1'), 'body' => '<pre id="source">' . htmlspecialchars($source) . '</pre>');
}
Ejemplo n.º 3
0
function plugin_edit_action()
{
    // global $vars, $_title_edit, $load_template_func;
    global $vars, $load_template_func;
    // if (PKWK_READONLY) die_message( _('PKWK_READONLY prohibits editing') );
    if (auth::check_role('readonly')) {
        die_message(_('PKWK_READONLY prohibits editing'));
    }
    if (PKWK_READONLY == ROLE_AUTH && auth::get_role_level() > ROLE_AUTH) {
        die_message(_('PKWK_READONLY prohibits editing'));
    }
    if (isset($vars['realview'])) {
        return plugin_edit_realview();
    }
    $page = isset($vars['page']) ? $vars['page'] : '';
    check_editable($page, true, true);
    if (!is_page($page) && auth::is_check_role(PKWK_CREATE_PAGE)) {
        die_message(_('PKWK_CREATE_PAGE prohibits editing'));
    }
    if (isset($vars['preview']) || $load_template_func && isset($vars['template'])) {
        return plugin_edit_preview();
    } else {
        if (isset($vars['write'])) {
            return plugin_edit_write();
        } else {
            if (isset($vars['cancel'])) {
                return plugin_edit_cancel();
            }
        }
    }
    $source = get_source($page);
    auth::is_role_page($source);
    $postdata = $vars['original'] = join('', $source);
    if (!empty($vars['id'])) {
        $postdata = plugin_edit_parts($vars['id'], $source);
        if ($postdata === FALSE) {
            unset($vars['id']);
            // なかったことに :)
            $postdata = $vars['original'];
        }
    }
    if ($postdata == '') {
        $postdata = auto_template($page);
    }
    return array('msg' => _('Edit of  $1'), 'body' => edit_form($page, $postdata));
}
Ejemplo n.º 4
0
function plugin_template_action()
{
    global $script, $vars;
    //	global $_title_edit;
    //	global $_msg_template_start, $_msg_template_end, $_msg_template_page, $_msg_template_refer;
    //	global $_btn_template_create, $_title_template;
    //	global $_err_template_already, $_err_template_invalid, $_msg_template_force;
    $_title_edit = _('Edit of  $1');
    $_msg_template_start = _('Start:<br />');
    $_msg_template_end = _('End:<br />');
    $_msg_template_page = _('$1/copy');
    $_msg_template_refer = _('Page:');
    $_msg_template_force = _('Edit with a page name which already exists');
    $_err_template_already = _(' $1 already exists.');
    $_err_template_invalid = _(' $1 is not a valid page name.');
    $_btn_template_create = _('Create');
    $_title_template = _('create a new page, using  $1 as a template.');
    // if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
    // if (auth::check_role('readonly')) die_message('PKWK_READONLY prohibits editing');
    if (auth::check_role('safemode') || auth::check_role('readonly')) {
        die_message(_('Prohibited'));
    }
    if (!isset($vars['refer']) || !is_page($vars['refer'])) {
        return FALSE;
    }
    if (!is_page($vars['refer']) || !check_readable($vars['refer'], false, false)) {
        return array('msg' => _(' $1 was not found.'), 'body' => _('cannot display the page source.'));
    }
    $lines = get_source($vars['refer']);
    auth::is_role_page($lines);
    // Remove '#freeze'
    if (!empty($lines) && strtolower(rtrim($lines[0])) == '#freeze') {
        array_shift($lines);
    }
    $begin = isset($vars['begin']) && is_numeric($vars['begin']) ? $vars['begin'] : 0;
    $end = isset($vars['end']) && is_numeric($vars['end']) ? $vars['end'] : count($lines) - 1;
    if ($begin > $end) {
        $temp = $begin;
        $begin = $end;
        $end = $temp;
    }
    $page = isset($vars['page']) ? $vars['page'] : '';
    $is_page = is_page($page);
    // edit
    if ($is_pagename = is_pagename($page) && (!$is_page || !empty($vars['force']))) {
        $postdata = join('', array_splice($lines, $begin, $end - $begin + 1));
        $retvar['msg'] = $_title_edit;
        $retvar['body'] = edit_form($vars['page'], $postdata);
        $vars['refer'] = $vars['page'];
        return $retvar;
    }
    $begin_select = $end_select = '';
    for ($i = 0; $i < count($lines); $i++) {
        $line = htmlspecialchars(mb_strimwidth($lines[$i], 0, MAX_LEN, '...'));
        $tag = $i == $begin ? ' selected="selected"' : '';
        $begin_select .= "<option value=\"{$i}\"{$tag}>{$line}</option>\n";
        $tag = $i == $end ? ' selected="selected"' : '';
        $end_select .= "<option value=\"{$i}\"{$tag}>{$line}</option>\n";
    }
    $_page = htmlspecialchars($page);
    $msg = $tag = '';
    if ($is_page) {
        $msg = $_err_template_already;
        $tag = '<input type="checkbox" name="force" value="1" />' . $_msg_template_force;
    } else {
        if ($page != '' && !$is_pagename) {
            $msg = str_replace('$1', $_page, $_err_template_invalid);
        }
    }
    $s_refer = htmlspecialchars($vars['refer']);
    $s_page = $page == '' ? str_replace('$1', $s_refer, $_msg_template_page) : $_page;
    $ret = <<<EOD
<form action="{$script}" method="post">
 <div>
  <input type="hidden" name="plugin" value="template" />
  <input type="hidden" name="refer"  value="{$s_refer}" />
  {$_msg_template_start} <select name="begin" size="10">{$begin_select}</select><br /><br />
  {$_msg_template_end}   <select name="end"   size="10">{$end_select}</select><br /><br />
  <label for="_p_template_refer">{$_msg_template_refer}</label>
  <input type="text" name="page" id="_p_template_refer" value="{$s_page}" />
  <input type="submit" name="submit" value="{$_btn_template_create}" /> {$tag}
 </div>
</form>
EOD;
    $retvar['msg'] = $msg == '' ? $_title_template : $msg;
    $retvar['body'] = $ret;
    return $retvar;
}
Ejemplo n.º 5
0
function plugin_backup_action()
{
    global $vars, $do_backup, $hr, $script;
    //	global $_msg_backuplist, $_msg_diff, $_msg_nowdiff, $_msg_source, $_msg_backup;
    //	global $_msg_view, $_msg_goto, $_msg_deleted;
    //	global $_msg_visualdiff;
    //	global $_title_backupdiff, $_title_backupnowdiff, $_title_backupsource;
    //	global $_title_backup, $_title_pagebackuplist, $_title_backuplist;
    $_msg_backuplist = _('Backup list');
    $_msg_diff = _('diff');
    $_msg_nowdiff = _('diff current');
    $_msg_source = _('source');
    $_msg_backup = _('backup');
    $_msg_visualdiff = _('diff for visual');
    $_msg_view = _('View the $1.');
    $_msg_goto = _('Go to $1.');
    $_msg_deleted = _(' $1 has been deleted.');
    $_title_backupdiff = _('Backup diff of $1(No. $2)');
    $_title_backupnowdiff = _('Backup diff of $1 vs current(No. $2)');
    $_title_backupsource = _('Backup source of $1(No. $2)');
    $_title_backup = _('Backup of $1(No. $2)');
    $_title_pagebackuplist = _('Backup list of $1');
    $_title_backuplist = _('Backup list');
    if (!$do_backup) {
        return;
    }
    $page = isset($vars['page']) ? $vars['page'] : '';
    if ($page == '') {
        return array('msg' => $_title_backuplist, 'body' => plugin_backup_get_list_all());
    }
    check_readable($page, true, true);
    $s_page = htmlspecialchars($page);
    $r_page = rawurlencode($page);
    $action = isset($vars['action']) ? $vars['action'] : '';
    if ($action == 'delete') {
        return plugin_backup_delete($page);
    }
    $s_action = $r_action = '';
    if ($action != '') {
        $s_action = htmlspecialchars($action);
        $r_action = rawurlencode($action);
    }
    $s_age = isset($vars['age']) && is_numeric($vars['age']) ? $vars['age'] : 0;
    if ($s_age <= 0) {
        return array('msg' => $_title_pagebackuplist, 'body' => plugin_backup_get_list($page));
    }
    $body = '<ul>' . "\n";
    $body .= ' <li><a href="' . $script . '?cmd=backup">' . $_msg_backuplist . '</a></li>' . "\n";
    $href = $script . '?cmd=backup&amp;page=' . $r_page . '&amp;age=' . $s_age;
    $is_page = is_page($page);
    if ($is_page && $action != 'diff') {
        $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '&amp;action=diff">' . $_msg_diff . '</a>', $_msg_view) . '</li>' . "\n";
    }
    if ($is_page && $action != 'nowdiff') {
        $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '&amp;action=nowdiff">' . $_msg_nowdiff . '</a>', $_msg_view) . '</li>' . "\n";
    }
    if ($is_page && $action != 'visualdiff') {
        $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '&amp;action=visualdiff">' . $_msg_visualdiff . '</a>', $_msg_view) . '</li>' . "\n";
    }
    if ($action != 'source') {
        $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '&amp;action=source">' . $_msg_source . '</a>', $_msg_view) . '</li>' . "\n";
    }
    if (!PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING && $action) {
        $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '">' . $_msg_backup . '</a>', $_msg_view) . '</li>' . "\n";
    }
    if ($is_page) {
        $body .= ' <li>' . str_replace('$1', '<a href="' . get_page_uri($page) . '">' . $s_page . '</a>', $_msg_goto) . "\n";
    } else {
        $body .= ' <li>' . str_replace('$1', $s_page, $_msg_deleted) . "\n";
    }
    $backups = get_backup($page);
    $backups_count = count($backups);
    if ($s_age > $backups_count) {
        $s_age = $backups_count;
    }
    if ($backups_count > 0 && $action != 'visualdiff') {
        $body .= '  <ul>' . "\n";
        foreach ($backups as $age => $val) {
            $time = isset($val['real']) ? $val['real'] : $val['time'];
            $date = format_date($time, TRUE);
            $body .= $age == $s_age ? '   <li><em>' . $age . ' ' . $date . '</em></li>' . "\n" : '   <li><a href="' . $script . '?cmd=backup&amp;action=' . $r_action . '&amp;page=' . $r_page . '&amp;age=' . $age . '">' . $age . ' ' . $date . '</a></li>' . "\n";
        }
        $body .= '  </ul>' . "\n";
    }
    $body .= ' </li>' . "\n";
    $body .= '</ul>' . "\n";
    if ($action == 'diff') {
        if (auth::check_role('safemode')) {
            die_message(_('PKWK_SAFE_MODE prohibits this'));
        }
        $title =& $_title_backupdiff;
        $old = $s_age > 1 ? join('', $backups[$s_age - 1]['data']) : '';
        $cur = join('', $backups[$s_age]['data']);
        auth::is_role_page($old);
        auth::is_role_page($cur);
        $body .= plugin_backup_diff(do_diff($old, $cur));
    } else {
        if ($s_action == 'nowdiff') {
            if (auth::check_role('safemode')) {
                die_message(_('PKWK_SAFE_MODE prohibits this'));
            }
            $title =& $_title_backupnowdiff;
            $old = join('', $backups[$s_age]['data']);
            $cur = join('', get_source($page));
            auth::is_role_page($old);
            auth::is_role_page($cur);
            $body .= plugin_backup_diff(do_diff($old, $cur));
        } else {
            if ($s_action == 'visualdiff') {
                $old = join('', $backups[$s_age]['data']);
                $cur = join('', get_source($page));
                auth::is_role_page($old);
                auth::is_role_page($cur);
                $source = do_diff($old, $cur);
                $source = plugin_backup_visualdiff($source);
                $body .= "{$hr}\n" . drop_submit(convert_html($source));
                $body = preg_replace('#<p>\\#spandel(.*?)(</p>)#si', '<span class="remove_word">$1', $body);
                $body = preg_replace('#<p>\\#spanadd(.*?)(</p>)#si', '<span class="add_word">$1', $body);
                $body = preg_replace('#<p>\\#spanend(.*?)(</p>)#si', '$1</span>', $body);
                $body = preg_replace('#&amp;spandel;#i', '<span class="remove_word">', $body);
                $body = preg_replace('#&amp;spanadd;#i', '<span class="add_word">', $body);
                $body = preg_replace('#&amp;spanend;#i', '</span>', $body);
                $title =& $_title_backupnowdiff;
            } else {
                if ($s_action == 'source') {
                    if (auth::check_role('safemode')) {
                        die_message(_('PKWK_SAFE_MODE prohibits this'));
                    }
                    $title =& $_title_backupsource;
                    auth::is_role_page($backups[$s_age]['data']);
                    $body .= '<pre>' . htmlspecialchars(join('', $backups[$s_age]['data'])) . '</pre>' . "\n";
                } else {
                    if (PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING) {
                        die_message(_('This feature is prohibited'));
                    } else {
                        $title =& $_title_backup;
                        auth::is_role_page($backups[$s_age]['data']);
                        $body .= $hr . "\n" . drop_submit(convert_html($backups[$s_age]['data']));
                    }
                }
            }
        }
    }
    return array('msg' => str_replace('$2', $s_age, $title), 'body' => $body);
}