예제 #1
0
function plugin_rename_phase3($pages)
{
    global $script, $_rename_messages, $vars;
    $msg = $input = '';
    $files = plugin_rename_get_files($pages);
    $exists = array();
    foreach ($files as $_page => $arr) {
        foreach ($arr as $old => $new) {
            if (file_exists($new)) {
                $exists[$_page][$old] = $new;
            }
        }
    }
    if (isset($vars['menu']) && !auth::check_role('role_adm_contents')) {
        return plugin_rename_proceed($pages, $files, $exists);
    }
    $pass = plugin_rename_getvar('pass');
    if ($pass != '' && pkwk_login($pass)) {
        return plugin_rename_proceed($pages, $files, $exists);
    } else {
        if ($pass != '') {
            $msg = plugin_rename_err('adminpass');
        }
    }
    $method = plugin_rename_getvar('method');
    if ($method == 'regex') {
        $s_src = htmlspecialchars(plugin_rename_getvar('src'));
        $s_dst = htmlspecialchars(plugin_rename_getvar('dst'));
        $msg .= $_rename_messages['msg_regex'] . '<br />';
        $input .= '<input type="hidden" name="method" value="regex" />';
        $input .= '<input type="hidden" name="src"    value="' . $s_src . '" />';
        $input .= '<input type="hidden" name="dst"    value="' . $s_dst . '" />';
    } else {
        $s_refer = htmlspecialchars(plugin_rename_getvar('refer'));
        $s_page = htmlspecialchars(plugin_rename_getvar('page'));
        $s_related = htmlspecialchars(plugin_rename_getvar('related'));
        $msg .= $_rename_messages['msg_page'] . '<br />';
        $input .= '<input type="hidden" name="method"  value="page" />';
        $input .= '<input type="hidden" name="refer"   value="' . $s_refer . '" />';
        $input .= '<input type="hidden" name="page"    value="' . $s_page . '" />';
        $input .= '<input type="hidden" name="related" value="' . $s_related . '" />';
    }
    if (!empty($exists)) {
        $msg .= $_rename_messages['err_already_below'] . '<ul>';
        foreach ($exists as $page => $arr) {
            $msg .= '<li>' . make_pagelink(decode($page));
            $msg .= $_rename_messages['msg_arrow'];
            $msg .= htmlspecialchars(decode($pages[$page]));
            if (!empty($arr)) {
                $msg .= '<ul>' . "\n";
                foreach ($arr as $ofile => $nfile) {
                    $msg .= '<li>' . $ofile . $_rename_messages['msg_arrow'] . $nfile . '</li>' . "\n";
                }
                $msg .= '</ul>';
            }
            $msg .= '</li>' . "\n";
        }
        $msg .= '</ul><hr />' . "\n";
        $input .= '<input type="radio" name="exist" value="0" checked="checked" />' . $_rename_messages['msg_exist_none'] . '<br />';
        $input .= '<input type="radio" name="exist" value="1" />' . $_rename_messages['msg_exist_overwrite'] . '<br />';
    }
    $ret = array();
    $auth = '';
    if (auth::check_role('role_adm_contents')) {
        $auth = <<<EOD
  <label for="_p_rename_adminpass">{$_rename_messages['msg_adminpass']}</label>
  <input type="password" name="pass" id="_p_rename_adminpass" value="" />
EOD;
    }
    $ret['msg'] = $_rename_messages['msg_title'];
    $ret['body'] = <<<EOD
<p>{$msg}</p>
<form action="{$script}" method="post">
 <div>
  <input type="hidden" name="plugin" value="rename" />
  <input type="hidden" name="menu"   value="1" />
  {$input}
{$auth}
  <input type="submit" value="{$_rename_messages['btn_submit']}" />
 </div>
</form>
<p>{$_rename_messages['msg_confirm']}</p>
EOD;
    ksort($pages, SORT_STRING);
    $ret['body'] .= '<ul>' . "\n";
    foreach ($pages as $old => $new) {
        $ret['body'] .= '<li>' . make_pagelink(decode($old)) . $_rename_messages['msg_arrow'] . htmlspecialchars(decode($new)) . '</li>' . "\n";
    }
    $ret['body'] .= '</ul>' . "\n";
    return $ret;
}
예제 #2
0
파일: edit.inc.php 프로젝트: big2men/qhm
function plugin_edit_write()
{
    global $vars, $trackback, $layout_pages;
    global $notimeupdate, $do_update_diff_table;
    global $qblog_defaultpage, $date_format, $qblog_menubar;
    $qm = get_qm();
    $page = isset($vars['page']) ? $vars['page'] : '';
    $add = isset($vars['add']) ? $vars['add'] : '';
    $digest = isset($vars['digest']) ? $vars['digest'] : '';
    $vars['msg'] = preg_replace(PLUGIN_EDIT_FREEZE_REGEX, '', $vars['msg']);
    $msg =& $vars['msg'];
    // Reference
    $retvars = array();
    // Collision Detection
    $oldpagesrc = join('', get_source($page));
    $oldpagemd5 = md5($oldpagesrc);
    if ($digest != $oldpagemd5) {
        $vars['digest'] = $oldpagemd5;
        // Reset
        $original = isset($vars['original']) ? $vars['original'] : '';
        list($postdata_input, $auto) = do_update_diff($oldpagesrc, $msg, $original);
        $retvars['msg'] = $qm->m['fmt_title_collided'];
        $retvars['body'] = ($auto ? $qm->m['fmt_msg_collided_auto'] : $qm->m['fmt_msg_collided']) . "\n";
        $retvars['body'] .= $do_update_diff_table;
        $retvars['body'] .= edit_form($page, $postdata_input, $oldpagemd5, FALSE);
        return $retvars;
    }
    // Action?
    if ($add) {
        // Add
        if (isset($vars['add_top']) && $vars['add_top']) {
            $postdata = $msg . "\n\n" . @join('', get_source($page));
        } else {
            $postdata = @join('', get_source($page)) . "\n\n" . $msg;
        }
    } else {
        // Edit or Remove
        $postdata =& $msg;
        // Reference
    }
    //ブログの時は、タイトルを足す
    if ($page !== $qblog_defaultpage && is_qblog()) {
        global $qblog_default_cat;
        $title = trim($vars['title']);
        $image = trim($vars['image']);
        $cat = trim($vars['category']);
        $cat = $cat === '' ? $qblog_default_cat : $cat;
        if ($postdata !== '') {
            $postdata = 'TITLE:' . $title . "\n" . $postdata;
        }
    }
    // NULL POSTING, OR removing existing page
    if ($postdata == '') {
        page_write($page, $postdata);
        $retvars['msg'] = $qm->m['fmt_title_deleted'];
        $retvars['body'] = str_replace('$1', htmlspecialchars($page), $qm->m['fmt_title_deleted']);
        if ($trackback) {
            tb_delete($page);
        }
        return $retvars;
    }
    // $notimeupdate: Checkbox 'Do not change timestamp'
    $notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] != '';
    if ($notimeupdate > 1 && $notimestamp && !pkwk_login($vars['pass'])) {
        // Enable only administrator & password error
        $retvars['body'] = '<p><strong>' . $qm->m['fmt_msg_invalidpass'] . '</strong></p>' . "\n";
        $retvars['body'] .= edit_form($page, $msg, $digest, FALSE);
        return $retvars;
    }
    page_write($page, $postdata, $notimeupdate != 0 && $notimestamp);
    //ブログの場合
    if ($page !== $qblog_defaultpage && is_qblog()) {
        // 日付の変更があったら、ページ名の変更
        $page_date = get_qblog_date($date_format, $page);
        if ($page_date and $vars['qblog_date'] != $page_date) {
            // ページ名の変更
            if (exist_plugin('rename')) {
                // ! renameのために $vasの値を変更
                $vars['page'] = $newpage = qblog_get_newpage($vars['qblog_date']);
                $vars['refer'] = $refer = $page;
                $vars['exist'] = 1;
                $pages = array();
                $pages[encode($refer)] = encode($newpage);
                $files = plugin_rename_get_files($pages);
                $exists = array();
                foreach ($files as $_page => $arr) {
                    foreach ($arr as $old => $new) {
                        if (file_exists($new)) {
                            $exists[$_page][$old] = $new;
                        }
                    }
                }
                plugin_rename_proceed($pages, $files, $exists, FALSE);
                //保留コメントリスト内のページ名を変更
                $datafile = CACHEQBLOG_DIR . 'qblog_pending_comments.dat';
                $pending_comments = unserialize(file_get_contents($datafile));
                foreach ($pending_comments as $i => $comment) {
                    if ($comment['page'] == $page) {
                        $pending_comments[$i]['page'] = $newpage;
                    }
                }
                file_put_contents($datafile, serialize($pending_comments), LOCK_EX);
                //最新コメントリスト内のページ名を変更
                $datafile = CACHEQBLOG_DIR . 'qblog_recent_comments.dat';
                file_put_contents($datafile, str_replace($page, $newpage, file_get_contents($datafile)), LOCK_EX);
                //変数を格納し直す
                $page = $newpage;
            }
        }
        //ブログの時は、ポストキャッシュを書き換える
        $option = array('category' => $cat, 'image' => $image);
        qblog_update_post($force, $page, $option);
        //Ping送信を行う
        if (!$notimestamp) {
            send_qblog_ping();
        }
    }
    pkwk_headers_sent();
    //ブログメニューの場合、ブログトップへ移動する
    if ($page === $qblog_menubar) {
        header('Location: ' . get_script_uri() . '?' . $qblog_defaultpage);
    } else {
        if (array_key_exists($page, $layout_pages)) {
            header('Location: ' . get_script_uri());
        } else {
            header('Location: ' . get_script_uri() . '?' . rawurlencode($page));
        }
    }
    exit;
}