Пример #1
0
function plugin_backup_action()
{
    global $vars, $do_backup, $hr, $script;
    global $layout_pages, $style_name;
    $qm = get_qm();
    $editable = edit_auth($page, FALSE, FALSE);
    if (!$editable) {
        header("Location: {$script}");
        exit;
    }
    if (!$do_backup) {
        return;
    }
    $page = isset($vars['page']) ? $vars['page'] : '';
    if ($page == '') {
        return array('msg' => $qm->m['plg_backup']['title_backuplist'], 'body' => plugin_backup_get_list_all());
    }
    //レイアウト部品の場合、スタイルを変更する
    $is_layout = FALSE;
    if (isset($layout_pages) && isset($layout_pages[$page])) {
        $style_name = '..';
        $is_layout = TRUE;
    }
    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) {
        $title = $is_layout ? h($layout_pages[$page]) . 'のバックアップ一覧' : $qm->m['plg_backup']['title_pagebackuplist'];
        return array('msg' => $title, 'body' => plugin_backup_get_list($page));
    }
    $script = get_script_uri();
    $body = '<ul>' . "\n";
    if (!$is_layout) {
        $body .= ' <li><a href="' . $script . '?cmd=backup">' . $qm->m['plg_backup']['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">' . $qm->m['plg_backup']['diff'] . '</a>', $qm->m['plg_backup']['view']) . '</li>' . "\n";
    }
    if ($is_page && $action != 'nowdiff') {
        $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '&amp;action=nowdiff">' . $qm->m['plg_backup']['nowdiff'] . '</a>', $qm->m['plg_backup']['view']) . '</li>' . "\n";
    }
    if ($action != 'source') {
        $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '&amp;action=source">' . $qm->m['plg_backup']['source'] . '</a>', $qm->m['plg_backup']['view']) . '</li>' . "\n";
    }
    if (!PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING && $action) {
        $body .= ' <li>' . str_replace('$1', '<a href="' . $href . '">' . $qm->m['plg_backup']['backup'] . '</a>', $qm->m['plg_backup']['view']) . '</li>' . "\n";
    }
    if ($is_page && $is_layout) {
        $body .= ' <li><a href="' . $script . '?cmd=edit&amp;page=' . $r_page . '">' . h($layout_pages[$page]) . 'を編集する</a>';
    } else {
        if ($is_page) {
            $body .= ' <li>' . str_replace('$1', '<a href="' . $script . '?' . $r_page . '">' . $s_page . '</a>', $qm->m['fmt_msg_goto']) . "\n";
        } else {
            $body .= ' <li>' . str_replace('$1', $s_page, $qm->m['plg_backup']['deleted']) . "\n";
        }
    }
    $backups = get_backup($page);
    $backups_count = count($backups);
    if ($s_age > $backups_count) {
        $s_age = $backups_count;
    }
    if ($backups_count > 0) {
        $body .= '  <ul>' . "\n";
        foreach ($backups as $age => $val) {
            $date = format_date($val['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') {
        $title = $is_layout ? h($layout_pages[$page]) . ' のバックアップ差分(No.$2)' : $qm->m['plg_backup']['title_backupdiff'];
        $old = $s_age > 1 ? join('', $backups[$s_age - 1]['data']) : '';
        $cur = join('', $backups[$s_age]['data']);
        $body .= plugin_backup_diff(do_diff($old, $cur));
    } else {
        if ($s_action == 'nowdiff') {
            $title = $is_layout ? h($layout_pages[$page]) . ' のバックアップの現在との差分(No.$2)' : $qm->m['plg_backup']['title_backupnowdiff'];
            $old = join('', $backups[$s_age]['data']);
            $cur = join('', get_source($page));
            $body .= plugin_backup_diff(do_diff($old, $cur));
        } else {
            if ($s_action == 'source') {
                $title = $is_layout ? h($layout_pages[$page]) . ' のバックアップソース(No.$2)' : $qm->m['plg_backup']['title_backupsource'];
                $body .= '<pre>' . htmlspecialchars(join('', $backups[$s_age]['data'])) . '</pre>' . "\n";
            } else {
                if (PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING) {
                    die_message($qm->m['fmt_err_prohibited']);
                } else {
                    $title = $is_layout ? h($layout_pages[$page]) . ' のバックアップ(No.$2)' : $qm->m['plg_backup']['title_backup'];
                    $body .= $hr . "\n" . drop_submit(convert_html($backups[$s_age]['data']));
                }
            }
        }
    }
    return array('msg' => str_replace('$2', $s_age, $title), 'body' => $body);
}
Пример #2
0
function plugin_backup_action()
{
    global $vars, $do_backup, $_string, $_button;
    global $_backup_messages;
    if (!$do_backup) {
        return;
    }
    $page = isset($vars['page']) ? $vars['page'] : null;
    $action = isset($vars['action']) ? $vars['action'] : null;
    $s_age = isset($vars['age']) && is_numeric($vars['age']) ? $vars['age'] : 0;
    /**
     * if page is not set, show list of backup files
     */
    if (!$page) {
        return array('msg' => $_backup_messages['title_backuplist'], 'body' => plugin_backup_get_list_all());
    }
    $wiki = Factory::Wiki($page);
    $is_page = $wiki->has();
    $s_page = Utility::htmlsc($page);
    $r_page = rawurlencode($page);
    $backups = Factory::Backup($page)->get();
    $msg = $_backup_messages['msg_backup'];
    if ($s_age > count($backups)) {
        $s_age = count($backups);
    }
    $body = '';
    $wiki->checkReadable();
    if ($s_age <= 0) {
        return array('msg' => $_backup_messages['title_pagebackuplist'], 'body' => plugin_backup_get_list($page));
    }
    $body .= '<div class="panel panel-default">';
    $body .= plugin_backup_get_list($page);
    $body .= '</div>' . "\n";
    if ($action) {
        $data = join("\n", $backups[$s_age]['data']);
        Auth::is_role_page($data);
        switch ($action) {
            case 'delete':
                /**
                 * 指定された世代を確認。指定されていなければ、一覧のみ表示
                 */
                // checkboxが選択されずにselectdeleteを実行された場合は、削除処理をしない
                if (!isset($vars['selectages']) && isset($vars['selectdelete'])) {
                    // 選択削除ボタンが押された
                    // 何もしない
                } else {
                    if (!isset($vars['selectages'])) {
                        // 世代引数がない場合は全削除
                        return plugin_backup_delete($page);
                    }
                    return plugin_backup_delete($page, $vars['selectages']);
                }
            case 'rollback':
                return plugin_backup_rollback($page, $s_age);
                break;
            case 'diff':
                if (Auth::check_role('safemode')) {
                    Utility::dieMessage($_string['prohibit']);
                }
                $title =& $_backup_messages['title_backupdiff'];
                $past_data = $s_age > 1 ? join("\n", $backups[$s_age - 1]['data']) : '';
                Auth::is_role_page($past_data);
                $body .= plugin_backup_diff($past_data, $data);
                break;
            case 'nowdiff':
                if (Auth::check_role('safemode')) {
                    die_message($_string['prohibit']);
                }
                $title =& $_backup_messages['title_backupnowdiff'];
                $now_data = Factory::Wiki($page)->get(true);
                Auth::is_role_page($now_data);
                $body .= plugin_backup_diff($data, $now_data);
                break;
            case 'visualdiff':
                $old = join('', $backups[$s_age]['data']);
                $now_data = get_source($page, TRUE, TRUE);
                Auth::is_role_page($now_data);
                // <ins> <del>タグを使う形式に変更。
                $diff = new Diff($data, $now_data);
                $source = plugin_backup_visualdiff($diff->getDiff());
                $body .= drop_submit(RendererFactory::factory($source));
                $body = preg_replace('#<p>\\#del(.*?)(</p>)#si', '<del class="remove_block">$1', $body);
                $body = preg_replace('#<p>\\#ins(.*?)(</p>)#si', '<ins class="add_block">$1', $body);
                $body = preg_replace('#<p>\\#delend(.*?)(</p>)#si', '$1</del>', $body);
                $body = preg_replace('#<p>\\#insend(.*?)(</p>)#si', '$1</ins>', $body);
                // ブロック型プラグインの処理が無いよ~!
                $body = preg_replace('#&amp;del;#i', '<del class="remove_word">', $body);
                $body = preg_replace('#&amp;ins;#i', '<ins class="add_word">', $body);
                $body = preg_replace('#&amp;delend;#i', '</del>', $body);
                $body = preg_replace('#&amp;insend;#i', '</ins>', $body);
                $title =& $_backup_messages['title_backupnowdiff'];
                break;
            case 'source':
                if (Auth::check_role('safemode')) {
                    die_message($_string['prohibit']);
                }
                $title =& $_backup_messages['title_backupsource'];
                $body .= '<pre class="sh" data-blush="plain">' . htmlsc($data) . '</pre>' . "\n";
                break;
            default:
                if (PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING) {
                    die_message(T_('This feature is prohibited'));
                } else {
                    $title =& $_backup_messages['title_backup'];
                    $body .= drop_submit(RendererFactory::factory($data));
                }
                break;
        }
        $msg = str_replace('$2', $s_age, $title);
    }
    if (!Auth::check_role('readonly')) {
        $body .= '<a class="button" href="' . $wiki->uri('backup', $page, null, array('action' => 'delete')) . '">' . str_replace('$1', $s_page, $_backup_messages['title_backup_delete']) . '</a>';
    }
    return array('msg' => $msg, 'body' => $body);
}
Пример #3
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);
}
Пример #4
0
function plugin_backup_action()
{
    global $vars, $do_backup, $hr;
    global $_msg_backuplist, $_msg_diff, $_msg_nowdiff, $_msg_source, $_msg_backup;
    global $_msg_view, $_msg_goto, $_msg_deleted;
    global $_title_backupdiff, $_title_backupnowdiff, $_title_backupsource;
    global $_title_backup, $_title_pagebackuplist, $_title_backuplist;
    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 = htmlsc($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 = htmlsc($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));
    }
    $script = get_script_uri();
    $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 ($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="' . $script . '?' . $r_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) {
        $body .= '  <ul>' . "\n";
        foreach ($backups as $age => $val) {
            $date = format_date($val['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') {
        $title =& $_title_backupdiff;
        $old = $s_age > 1 ? join('', $backups[$s_age - 1]['data']) : '';
        $cur = join('', $backups[$s_age]['data']);
        $body .= plugin_backup_diff(do_diff($old, $cur));
    } elseif ($s_action == 'nowdiff') {
        $title =& $_title_backupnowdiff;
        $old = join('', $backups[$s_age]['data']);
        $cur = join('', get_source($page));
        $body .= plugin_backup_diff(do_diff($old, $cur));
    } elseif ($s_action == 'source') {
        $title =& $_title_backupsource;
        $body .= '<pre>' . htmlsc(join('', $backups[$s_age]['data'])) . '</pre>' . "\n";
    } else {
        if (PLUGIN_BACKUP_DISABLE_BACKUP_RENDERING) {
            die_message('This feature is prohibited');
        } else {
            $title =& $_title_backup;
            $body .= $hr . "\n" . drop_submit(convert_html($backups[$s_age]['data']));
        }
    }
    return array('msg' => str_replace('$2', $s_age, $title), 'body' => $body);
}