/**
 * Markdon Syntax
 *
 * @author     sonots
 * @license    http://www.gnu.org/licenses/gpl.html GPL v2
 * @link       http://lsx.sourceforge.jp/?Plugin%2Fmarkdown.inc.php
 * @version    $Id: markdown.inc.php,v 1.2 2007-02-24 16:28:39Z sonots $
 * @package    plugin
 */
function plugin_markdown_convert()
{
    if (defined('PLUGIN_DIR') && file_exists(PLUGIN_DIR . 'markdown.php')) {
        $markdown = PLUGIN_DIR . 'markdown.php';
    } elseif (defined('EXT_PLUGIN_DIR') && file_exists(EXT_PLUGIN_DIR . 'markdown.php')) {
        $markdown = EXT_PLUGIN_DIR . 'markdown.php';
    } else {
        return "markdown(): markdown.php does not exist under " . PLUGIN_DIR . ' or ' . EXT_PLUGIN_DIR;
    }
    $args = func_get_args();
    $body = array_pop($args);
    $noskin = in_array("noskin", $args);
    global $vars;
    if (!(PKWK_READONLY > 0 or is_freeze($vars['page']) or plugin_markdown_is_edit_auth($vars['page']))) {
        $body = htmlspecialchars($body);
    }
    require_once $markdown;
    $body = Markdown($body);
    if ($noskin) {
        pkwk_common_headers();
        print $body;
        exit;
    }
    return $body;
}
Esempio n. 2
0
 function convert()
 {
     if (func_num_args() == 0) {
         return '<p>$this->plugin(): no argument(s). </p>';
     }
     global $vars;
     $args = func_get_args();
     $url = array_shift($args);
     if (!is_url($url) && is_interwiki($url)) {
         list($interwiki, $page) = explode(':', $url, 2);
         $url = get_interwiki_url($interwiki, $page);
     }
     $page = $vars['page'];
     if (!(PKWK_READONLY > 0 or is_freeze($page) or $this->is_edit_auth($page))) {
         if (!$this->accept($url)) {
             return "<p>{$this->plugin}(): The specified url, {$url}, is not allowed, modify iframe.inc.php<br />" . "Or, restrict editing of current page using freeze or edit_auth or PKWK_READONLY.</p>";
         }
     }
     $url = htmlspecialchars($url);
     $options = array();
     foreach ($args as $arg) {
         list($key, $val) = array_pad(explode('=', $arg, 2), 2, TRUE);
         $options[$key] = htmlspecialchars($val);
     }
     $style = isset($options['style']) ? $options['style'] : NULL;
     if (preg_match("/MSIE (3|4|5|6|7)/", getenv("HTTP_USER_AGENT"))) {
         $style = isset($options['iestyle']) ? $options['iestyle'] : $style;
         return $this->show_iframe($url, $style);
     } else {
         return $this->show_object($url, $style);
     }
 }
Esempio n. 3
0
function is_editable($page)
{
    static $is_editable = array();
    if (!isset($is_editable[$page])) {
        $is_editable[$page] = is_pagename($page) && !is_freeze($page) && !is_cantedit($page);
    }
    return $is_editable[$page];
}
Esempio n. 4
0
function plugin_nofollow_convert()
{
    global $vars, $nofollow;
    $page = isset($vars['page']) ? $vars['page'] : '';
    if (is_freeze($page)) {
        $nofollow = 1;
    }
    return '';
}
Esempio n. 5
0
function is_editable($page)
{
    global $cantedit;
    static $is_editable = array();
    if (!isset($is_editable[$page])) {
        $is_editable[$page] = is_pagename($page) && !is_freeze($page) && !in_array($page, $cantedit);
    }
    return $is_editable[$page];
}
Esempio n. 6
0
function plugin_unfreeze_action()
{
    global $script, $vars, $function_freeze;
    global $_title_isunfreezed, $_title_unfreezed, $_title_unfreeze;
    global $_msg_invalidpass, $_msg_unfreezing, $_btn_unfreeze;
    $page = isset($vars['page']) ? $vars['page'] : '';
    if (!$function_freeze || !is_page($page)) {
        return array('msg' => '', 'body' => '');
    }
    $pass = isset($vars['pass']) ? $vars['pass'] : NULL;
    $msg = $body = '';
    if (!is_freeze($page)) {
        // Unfreezed already
        $msg =& $_title_isunfreezed;
        $body = str_replace('$1', htmlspecialchars(strip_bracket($page)), '<p>' . $_title_isunfreezed . '</p>');
    } else {
        if ($pass !== NULL && pkwk_login($pass)) {
            // Unfreeze
            $postdata = get_source($page);
            array_shift($postdata);
            $postdata = join('', $postdata);
            file_write(DATA_DIR, $page, $postdata, TRUE);
            // Update
            is_freeze($page, TRUE);
            if (PLUGIN_UNFREEZE_EDIT) {
                $vars['cmd'] = 'read';
                // To show 'Freeze' link
                $msg =& $_title_unfreezed;
                $body = edit_form($page, $postdata);
            } else {
                $vars['cmd'] = 'read';
                $msg =& $_title_unfreezed;
                $body = '';
            }
        } else {
            // Show unfreeze form
            // kazuwaya
            $msg =& $_title_unfreeze;
            $s_page = htmlspecialchars($page);
            $body = $pass === NULL ? '' : "<p><strong>{$_msg_invalidpass}</strong></p>\n";
            $body .= <<<EOD
<p>{$_msg_unfreezing}</p>
<form action="{$script}" method="post">
 <p>
  <input type="hidden"   name="cmd"  value="unfreeze" />
  <input type="hidden"   name="page" value="{$s_page}" />
  <input type="password" name="pass" size="12" />
  <input type="submit"   name="ok"   value="{$_btn_unfreeze}" />
 </p>
</form>
EOD;
        }
    }
    return array('msg' => $msg, 'body' => $body);
}
Esempio n. 7
0
function plugin_logsw_convert()
{
    global $log, $vars;
    if ($log['browse']['use']) {
        return;
    }
    if (USE_FREEZE_ONLY && !is_freeze($vars['page'])) {
        return;
    }
    $log['browse']['use'] = 1;
}
Esempio n. 8
0
function plugin_html_convert()
{
    global $script, $vars;
    $qm = get_qm();
    $qt = get_qt();
    $page = isset($vars['page_alt']) ? $vars['page_alt'] : $vars['page'];
    $ids = $qt->getv('plugin_html_id');
    if (!$ids) {
        $ids = array($page => 0);
    }
    $id = ++$ids[$page];
    $qt->setv('plugin_html_id', $ids);
    if (!(PKWK_READONLY > 0 or is_freeze($page) or plugin_html_is_edit_auth($page))) {
        return $qm->replace('fmt_msg_not_editable', '#html', $page);
    }
    $args = func_get_args();
    $body = array_pop($args);
    $size = '';
    $class = 'autofit_iframe';
    foreach ($args as $arg) {
        if ($arg == 'noskin') {
            $noskin = true;
            break;
        } else {
            if ($arg == 'iframe') {
                $iframe = true;
            } else {
                if (preg_match('/^(\\d+)(?:x(\\d+))?$/', $arg, $mts)) {
                    $x = "width:{$mts[1]}px;";
                    $y = isset($mts[2]) ? "height:{$mts[2]}px;" : '';
                    $size = $x . $y;
                    $class = '';
                }
            }
        }
    }
    if ($noskin) {
        pkwk_common_headers();
        print $body;
        exit;
    } else {
        if ($iframe) {
            $qt->setv('jquery_include', true);
            exist_plugin('iframe');
            $qt->appendv_once('plugin_iframe', 'beforescript', PLUGIN_IFRAME_FIT_IFRAME_JS);
            $r_page = rawurlencode($page);
            $body = '<iframe src="' . $script . '?cmd=html&page=' . $r_page . '&id=' . $id . '" frameborder="0" class="' . $class . '" style="' . $size . '"></iframe>';
        }
    }
    return $body;
}
Esempio n. 9
0
function plugin_dlbutton_inline()
{
    global $vars, $script;
    $qm = get_qm();
    $page = $vars['page'];
    if (!(PKWK_READONLY > 0 or is_freeze($page) or plugin_dlbutton_is_edit_auth($page))) {
        return $qm->replace('fmt_err_not_editable', 'dlbutton', $page);
    }
    $args = func_get_args();
    $args_num = count($args);
    if ($args_num < 1 || 5 < $args_num) {
        return $qm->replace('fmt_err_iln', 'dlbutton', $qm->m['plg_dlbutton']['err_usage']);
    }
    $filename = "";
    $label = "";
    $email = "";
    $title = "";
    list($filename, $label, $email, $title) = array_pad($args, 4, '');
    //param check
    if (!is_url($filename) && !file_exists($filename)) {
        return $qm->replace('plg_dlbutton.err_file_notfound', '');
    }
    if ($label == '') {
        $label = $qm->m['plg_dlbutton']['label'];
    }
    if ($email != '') {
        if (!preg_match('/^[a-zA-Z0-9_\\.\\-]+?@[A-Za-z0-9_\\.\\-]+$/', $email)) {
            return $qm->replace('plg_dlbutton.err_invalid_email', $email);
        }
    }
    if ($title == '') {
        $title = $qm->replace('plg_dlbutton.subject', $filename);
    }
    $title = urlencode($title);
    if (isset($vars['page_alt'])) {
        $page = $vars['page_alt'];
    }
    //url encode
    $filename = urlencode($filename);
    $page = urlencode($page);
    //ボタン作成
    $md5 = md5(file_get_contents('qhm.ini.php'));
    if ($email == '') {
        $dlurl = dirname($script) . '/plugin/dlexec.php?filename=' . $filename . '&key=' . $md5;
    } else {
        $dlurl = dirname($script) . '/plugin/dlexec.php?filename=' . $filename . '&key=' . $md5 . '&email=' . $email . '&title=' . $title;
    }
    $dlurl .= '&refer=' . $page;
    $btn = '<input type="button" value=' . $label . ' onClick=\'location.href="' . h($dlurl) . '"\' />';
    return $btn;
}
Esempio n. 10
0
function plugin_freeze_action()
{
    global $script, $vars, $function_freeze;
    $_title_isfreezed = _(' $1 has already been frozen');
    $_title_freezed = _(' $1 has been frozen.');
    $_title_freeze = _('Freeze  $1');
    $_msg_invalidpass = _('Invalid password.');
    $_msg_freezing = _('Please input the password for freezing.');
    $_btn_freeze = _('Freeze');
    $page = isset($vars['page']) ? $vars['page'] : '';
    if (!$function_freeze || is_cantedit($page) || !is_page($page)) {
        return array('msg' => '', 'body' => '');
    }
    $pass = isset($vars['pass']) ? $vars['pass'] : NULL;
    $msg = $body = '';
    if (is_freeze($page)) {
        // Freezed already
        $msg =& $_title_isfreezed;
        $body = str_replace('$1', htmlspecialchars(strip_bracket($page)), $_title_isfreezed);
    } else {
        if (!auth::check_role('role_adm_contents') || $pass !== NULL && pkwk_login($pass)) {
            // Freeze
            $postdata = get_source($page);
            array_unshift($postdata, "#freeze\n");
            file_write(DATA_DIR, $page, join('', $postdata), TRUE);
            // Update
            is_freeze($page, TRUE);
            $vars['cmd'] = 'read';
            $msg =& $_title_freezed;
            $body = '';
        } else {
            // Show a freeze form
            $msg =& $_title_freeze;
            $s_page = htmlspecialchars($page);
            $body = $pass === NULL ? '' : "<p><strong>{$_msg_invalidpass}</strong></p>\n";
            $body .= <<<EOD
<p>{$_msg_freezing}</p>
<form action="{$script}" method="post">
 <div>
  <input type="hidden"   name="cmd"  value="freeze" />
  <input type="hidden"   name="page" value="{$s_page}" />
  <input type="password" name="pass" size="12" />
  <input type="submit"   name="ok"   value="{$_btn_freeze}" />
 </div>
</form>
EOD;
        }
    }
    return array('msg' => $msg, 'body' => $body);
}
Esempio n. 11
0
function plugin_beforescript_convert()
{
    global $vars;
    $qm = get_qm();
    $page = $vars['page'];
    if (!(PKWK_READONLY > 0 or is_freeze($page) or plugin_beforescript_is_edit_auth($page))) {
        return $qm->replace('fmt_err_not_editable', '#html', $page);
    }
    $args = func_get_args();
    $addscript = array_pop($args);
    $qt = get_qt();
    $qt->appendv('beforescript', $addscript);
    return "";
}
Esempio n. 12
0
/**
 * Evaluate text as a php code
 * 
 * Current page must be edit_authed or frozen or whole system must be PKWK_READONLY.Tag Plugin
 *
 * Example: 
 *  #php{{
 *  return 1+1;
 *  }}
 *
 * @author     sonots
 * @license    http://www.gnu.org/licenses/gpl.html GPL v2
 * @version    $Id: php.inc.php,v 1.1 2007-02-24 16:28:39Z sonots $
 * @package    plugin
 */
function plugin_php_convert()
{
    global $vars;
    $page = $vars['page'];
    if (!(PKWK_READONLY > 0 or is_freeze($page) or plugin_php_is_edit_auth($page))) {
        return "<p>php(): Current page, {$page}, must be edit_authed or frozen or whole system must be PKWK_READONLY.</p>";
    }
    $args = func_get_args();
    //ob_start();
    $body = eval(array_pop($args));
    //$body = ob_get_contents();
    //ob_end_clean();
    return $body;
}
Esempio n. 13
0
function plugin_freeze_action()
{
    global $script, $vars, $function_freeze;
    global $_title_isfreezed, $_title_freezed, $_title_freeze;
    global $_msg_invalidpass, $_msg_freezing, $_btn_freeze;
    $qt = get_qt();
    //キャッシュしない
    $qt->enable_cache = false;
    $page = isset($vars['page']) ? $vars['page'] : '';
    if (!$function_freeze || !is_page($page)) {
        return array('msg' => '', 'body' => '');
    }
    $pass = isset($vars['pass']) ? $vars['pass'] : NULL;
    $msg = $body = '';
    if (is_freeze($page)) {
        // Freezed already
        $msg =& $_title_isfreezed;
        $body = str_replace('$1', htmlspecialchars(strip_bracket($page)), $_title_isfreezed);
    } else {
        if ($pass !== NULL && pkwk_login($pass)) {
            // Freeze
            $postdata = get_source($page);
            array_unshift($postdata, "#freeze\n");
            file_write(DATA_DIR, $page, join('', $postdata), TRUE);
            // Update
            is_freeze($page, TRUE);
            $vars['cmd'] = 'read';
            $msg =& $_title_freezed;
            $body = '';
        } else {
            // Show a freeze form
            $msg =& $_title_freeze;
            $s_page = htmlspecialchars($page);
            $body = $pass === NULL ? '' : "<p><strong>{$_msg_invalidpass}</strong></p>\n";
            $body .= <<<EOD
<p>{$_msg_freezing}</p>
<form action="{$script}" method="post">
 <div>
  <input type="hidden"   name="cmd"  value="freeze" />
  <input type="hidden"   name="page" value="{$s_page}" />
  <input type="password" name="pass" size="12" />
  <input type="submit"   name="ok"   value="{$_btn_freeze}" />
 </div>
</form>
EOD;
        }
    }
    return array('msg' => $msg, 'body' => $body);
}
function plugin_monobook_navigation($wikinote, $tabs, $background)
{
    global $vars, $plugin, $_monobook_navigation_messages;
    if (!exist_plugin('monobook_getlink')) {
        die('monobook_getlink plugin not found');
    }
    do_plugin_init('monobook_navigation');
    $main_tabs = '';
    if ($wikinote->is_effect()) {
        $main_tabs = str_replace(array('<ul class="wikinote">', '</ul>', "\n"), '', $wikinote->show_tabs(array(array('cmd' => 'main', 'label' => $_monobook_navigation_messages['article']), array('cmd' => 'note', 'label' => $_monobook_navigation_messages['discuss']))));
    }
    $sub_tabs = '';
    $selected_flag = FALSE;
    foreach ($tabs as $tab) {
        if ($tab === 'edit' && is_freeze($vars['page']) && !in_array('source', $tabs)) {
            $tab = 'source';
        }
        if ($tab === 'edit' && $plugin === 'paraedit') {
            $tab = 'paraedit';
        }
        if ($tab === 'edit' && exist_plugin('revert') && plugin_revert_getlink()) {
            $tab = 'revert';
        }
        list($link, $selected) = plugin_monobook_getlink($tab, $_monobook_navigation_messages, TRUE);
        if (!$link) {
            continue;
        }
        if ($selected) {
            $sub_tabs .= '<li class="selected">' . $link . '</li>';
            $selected_flag = TRUE;
        } else {
            $sub_tabs .= '<li>' . $link . '</li>';
        }
    }
    if (!$selected_flag) {
        $link = plugin_monobook_getlink('nowplugin', $_monobook_navigation_messages);
        if (!$main_tabs) {
            if ($link) {
                $sub_tabs = '<li class="selected" id="separate">' . $link . '</li>' . $sub_tabs;
            } else {
                $sub_tabs = '<li class="selected"><a href="' . get_script_uri() . strrchr($_SERVER['REQUEST_URI'], '?') . '">' . $_monobook_navigation_messages['undefined'] . '</a></li>';
            }
        } elseif ($main_tabs && !arg_check('read') && $link) {
            $sub_tabs = '<li class="selected">' . $link . '</li>' . $sub_tabs;
        }
    }
    return '<div id="navigator"><ul' . $background . '>' . $main_tabs . $sub_tabs . '</ul></div>' . "\n";
}
Esempio n. 15
0
/**
 *   Output 1-Line HTML Plugin
 *   -------------------------------------------
 *   plugin/html2.inc.php
 *   
 *   Copyright (c) 2010 hokuken
 *   http://hokuken.com/
 *   
 *   created  : 
 *   modified :
 *   
 *   1行HTMLをそのまま出力します。
 *   
 *   Usage :
 *     #html2(HTML)
 *   
 */
function plugin_html2_convert()
{
    global $vars;
    $qm = get_qm();
    $page = $vars['page'];
    if (!(PKWK_READONLY > 0 or is_freeze($page) or plugin_html2_is_edit_auth($page))) {
        return $qm->replace('fmt_msg_not_editable', '#html2', $page);
    }
    $args = func_get_args();
    $ret = array_shift($args);
    foreach ($args as $tmpstr) {
        $ret .= ',';
        $ret .= $tmpstr;
    }
    return $ret;
}
Esempio n. 16
0
function is_editable($page)
{
	global $cantedit;
	static $is_editable = array();
	
	if (!array_key_exists($page,$is_editable))
	{
		$is_editable[$page] = (
			is_pagename($page) and
			!is_freeze($page) and
			!in_array($page,$cantedit)
		);
	}
	
	return $is_editable[$page];
}
Esempio n. 17
0
function plugin_mp3play_inline()
{
    global $vars, $script;
    $qm = get_qm();
    $page = $vars['page'];
    if (!(PKWK_READONLY > 0 or is_freeze($page) or plugin_mp3play_is_edit_auth($page))) {
        return $qm->replace('fmt_err_not_editable', '&mp3play', $page);
    }
    $args = func_get_args();
    $args_num = count($args);
    if ($args_num < 1) {
        return "<p>{$qm->m['plg_mp3play']['err_usage']}</p>";
    }
    $filename = "";
    list($filename) = $args;
    //param check
    if (!file_exists($filename)) {
        return "<p>{$qm->m['plg_mp3play']['err_file_notfound']}</p>";
    }
    return '<embed src="' . $filename . '" width="320" height="45" autostart="0"></embed>';
}
Esempio n. 18
0
function plugin_partedit_convert()
{
    global $vars, $fixed_heading_edited;
    list($arg) = func_get_args();
    // 強制オン・オフ
    if ($arg == 'on') {
        $fixed_heading_edited = 1;
    }
    if ($arg == 'off') {
        $fixed_heading_edited = 0;
    }
    if ($arg == 'default' || $arg == '' || !isset($arg)) {
        //		$fixed_heading_edited = 0;
    }
    // 凍結時のみ強制的にオフ
    if (PARTEDIT_FREEZE_OFF) {
        if (is_freeze($vars['page'])) {
            $fixed_heading_edited = 0;
        }
    }
    return '';
}
function plugin_weblog_field_inline()
{
    global $script, $vars, $wiki_user_dir;
    $prmcnt = func_num_args();
    if ($prmcnt < 2) {
        return "";
    }
    $prms = func_get_args();
    $body = array_pop($prms);
    switch ($prms[0]) {
        case "__AUTHOR":
            $body = convert_html(sprintf($wiki_user_dir, $body), false, false);
            $body = preg_replace("/^<p>(.*)<\\/p>\$/ms", "\\1", $body);
            break;
        case "__TIMESTAMP":
            $body = date("Yǯm·îdÆü H»þiʬsÉÃ", $body);
            break;
        case "__CATEGORY":
            $body = convert_html("[[Category {$prms[1]}>{$prms[1]}]]:", false, false);
            $body = preg_replace("/^<p>(.*)<\\/p>\$/ms", "\\1", $body);
            break;
        case "__SUBJECT":
            $page = strip_bracket($vars['page']);
            $body = convert_html("[[{$body}>{$page}]]", false, false);
            $body = preg_replace("/^<p>(.*)<\\/p>\$/ms", "\\1", $body);
            break;
        case "__EDIT":
            if (!is_freeze($page, FALSE)) {
                $_page = preg_replace("/(.*\\/)?([0-9\\-]+)\$/", "\\2", strip_bracket($vars['page']));
                $body = "<a href=\"{$script}?plugin=weblog&mode=edit&conf={$prms[1]}&page_name={$_page}\">";
                $body .= "<img src=\"image/edit.png\" alt=\"Edit\" title=\"Edit\" /></a>";
            }
            break;
        default:
    }
    return $body;
}
Esempio n. 20
0
function plugin_commu_html_convert()
{
    global $vars;
    //キャッシュを無効に
    if (QHM_VERSION < 4.6) {
        global $enable_cache;
        $enable_cache = false;
    } else {
        $qt = get_qt();
        $qt->enable_cache = false;
    }
    $page = $vars['page'];
    if (!(PKWK_READONLY > 0 or is_freeze($page) or plugin_commu_html_is_edit_auth($page))) {
        return "<p>commu_html(): Current page, {$page}, must be edit_authed or frozen or whole system must be PKWK_READONLY.</p>";
    }
    $args = func_get_args();
    $body = array_pop($args);
    $noskin = in_array("noskin", $args);
    $s = array();
    $r = array();
    $cnt = 0;
    if (isset($_SESSION['commu_user'])) {
        foreach ($_SESSION['commu_user'] as $key => $val) {
            $s[$cnt] = '/<%' . $key . '%>/';
            $r[$cnt] = mb_convert_encoding($val, "UTF-8", "UTF-8,EUC-JP");
            $cnt++;
        }
        $body = preg_replace($s, $r, $body);
    }
    if ($noskin) {
        pkwk_common_headers();
        print $body;
        exit;
    }
    return $body;
}
Esempio n. 21
0
function replace_do($search, $replace, $notimestamp)
{
    global $cycle, $cantedit;
    global $_replace_msg;
    // パスワードが合ってたらいよいよ置換
    $pages = auth::get_existpages();
    $replaced_pages = array();
    foreach ($pages as $page) {
        if (REPLACE_IGNORE_FREEZE) {
            $editable = !in_array($page, $cantedit);
        } else {
            $editable = (!is_freeze($page) and !in_array($page, $cantedit));
        }
        if ($editable) {
            // パスワード一致
            $postdata = '';
            $postdata_old = get_source($page);
            foreach ($postdata_old as $line) {
                // キーワードの置換
                $line = str_replace($search, $replace, $line);
                $postdata .= $line;
            }
            if ($postdata != join('', $postdata_old)) {
                $cycle = 0;
                set_time_limit(30);
                page_write($page, $postdata, $notimestamp);
                $replaced_pages[] = htmlspecialchars($page);
            }
        }
    }
    $vars['cmd'] = 'read';
    if (count($replaced_pages) == 0) {
        return array('msg' => $_replace_msg['msg_H0_no_data'], 'body' => '<p>' . $_replace_msg['msg_no_replaced'] . '</p>');
    }
    return array('msg' => $_replace_msg['msg_H0_replaced'], 'body' => '<p>' . $_replace_msg['msg_replaced'] . "</p>\n<p>" . join("<br />\n", $replaced_pages) . '</p>');
}
Esempio n. 22
0
function plugin_toolbar_convert()
{
    global $do_backup, $trackback, $referer;
    global $function_freeze;
    global $vars;
    // $is_read = (arg_check('read') && is_page($vars['page']));
    $is_read = is_page($vars['page']);
    $is_readonly = auth::check_role('readonly');
    $is_safemode = auth::check_role('safemode');
    $is_createpage = auth::is_check_role(PKWK_CREATE_PAGE);
    $num = func_num_args();
    $args = $num ? func_get_args() : array();
    $body = '';
    while (!empty($args)) {
        $name = array_shift($args);
        switch ($name) {
            case 'freeze':
                if ($is_readonly) {
                    break;
                }
                if (!$is_read) {
                    break;
                }
                if ($function_freeze) {
                    if (!is_freeze($vars['page'])) {
                        $name = 'freeze';
                    } else {
                        $name = 'unfreeze';
                    }
                    if ($body != '') {
                        $body .= "\n";
                    }
                    $body .= _toolbar($name);
                }
                break;
            case 'upload':
                if ($is_readonly) {
                    break;
                }
                if (!$is_read) {
                    break;
                }
                if ($function_freeze && is_freeze($vars['page'])) {
                    break;
                }
                if ((bool) ini_get('file_uploads')) {
                    if ($body != '') {
                        $body .= "\n";
                    }
                    $body .= _toolbar($name);
                }
                break;
            case 'filelist':
                if (arg_check('list')) {
                    if ($body != '') {
                        $body .= "\n";
                    }
                    $body .= _toolbar($name);
                }
                break;
            case 'backup':
                if ($do_backup) {
                    if ($body != '') {
                        $body .= "\n";
                    }
                    $body .= _toolbar($name);
                }
                break;
            case 'trackback':
                if ($trackback) {
                    if ($body != '') {
                        $body .= "\n";
                    }
                    $tbcount = tb_count($vars['page']);
                    if ($tbcount > 0) {
                        $body .= _toolbar($name);
                    } else {
                        if (!$is_read) {
                            $body .= _toolbar($name);
                        }
                    }
                }
                break;
            case 'refer':
                if ($referer) {
                    if ($body != '') {
                        $body .= "\n";
                    }
                    $body .= _toolbar($name);
                }
                break;
            case 'rss':
            case 'mixirss':
                if ($body != '') {
                    $body .= "\n";
                }
                $body .= _toolbar($name);
                break;
            case '|':
                $body .= "\n&nbsp;\n";
                break;
            case 'diff':
                if (!$is_read) {
                    break;
                }
                if ($is_safemode) {
                    break;
                }
                if ($body != '') {
                    $body .= "\n";
                }
                $body .= _toolbar($name);
                break;
            case 'edit':
            case 'guiedit':
                if (!$is_read) {
                    break;
                }
                if ($is_readonly) {
                    break;
                }
                if ($function_freeze && is_freeze($vars['page'])) {
                    break;
                }
                if ($body != '') {
                    $body .= "\n";
                }
                $body .= _toolbar($name);
                break;
            case 'new':
            case 'newsub':
                if ($is_createpage) {
                    break;
                }
            case 'rename':
            case 'copy':
                if ($is_readonly) {
                    break;
                }
            case 'reload':
            case 'print':
            case 'full':
                if (!$is_read) {
                    break;
                }
            default:
                if ($body != '') {
                    $body .= "\n";
                }
                $body .= _toolbar($name);
                break;
        }
    }
    return '<div id="toolbar">' . $body . '</div>';
}
Esempio n. 23
0
function plugin_navibar_convert()
{
    global $do_backup, $trackback, $referer;
    global $function_freeze;
    global $vars;
    global $whatsnew, $whatsdeleted;
    /*
    	if ($_LINK['reload'] == '') {
    		return '<p class="message_box ui-state-error ui-corner-all">#navibar: plugin called from wikipage. skipped.</p>';
    	}
    */
    $_page = isset($vars['page']) ? $vars['page'] : null;
    $is_read = arg_check('read') && is_page($_page);
    $is_freeze = is_freeze($_page);
    $is_readonly = Auth::check_role('readonly') || PKWK_READONLY == Auth::ROLE_AUTH && Auth::get_role_level() > Auth::ROLE_AUTH ? true : false;
    $cmd = isset($vars['cmd']) ? $vars['cmd'] : null;
    $num = func_num_args();
    $args = $num ? func_get_args() : array();
    if (IS_MOBILE) {
        $ret[] = '<ul data-role="listview">';
    } else {
        $ret[] = '<ul>';
    }
    while (!empty($args)) {
        $name = array_shift($args);
        switch ($name) {
            case 'freeze':
            case 'unfreeze':
                if ($is_read && $function_freeze && !($_page == $whatsnew || $_page == $whatsdeleted)) {
                    if ($is_freeze) {
                        $name = 'unfreeze';
                    } else {
                        $name = 'freeze';
                    }
                    $ret[] = _navibar($name);
                }
                break;
            case 'list':
                if ($cmd !== 'list') {
                    $ret[] = _navibar($name);
                } else {
                    $ret[] = _navibar('filelist');
                }
                break;
            case 'backup':
                if ($do_backup) {
                    $ret[] = _navibar($name);
                }
                break;
            case 'brokenlink':
            case 'template':
            case 'source':
            case 'diff':
            case 'reload':
            case 'copy':
                if ($is_read || !empty($_page) && !($_page == $whatsnew || $_page == $whatsdeleted)) {
                    $ret[] = _navibar($name);
                }
                break;
            case 'trackback':
                if ($trackback) {
                    if (!empty($_page) && !($_page == $whatsnew || $_page == $whatsdeleted)) {
                        $ret[] = _navibar($name, 'Trackback(' . tb_count($_page) . ')');
                    } else {
                        //		$ret[] = _navibar($name, 'Trackback list');
                    }
                }
                break;
            case 'referer':
            case 'skeylist':
            case 'linklist':
                if ($referer && !empty($_page)) {
                    $ret[] = _navibar($name);
                }
                break;
            case 'log':
                if (!empty($_page)) {
                    $ret[] = _navibar($name);
                }
            case '|':
                if (end($ret) !== '<ul>') {
                    $ret[] = '</ul>';
                    $ret[] = "\n";
                    $ret[] = !IS_MOBILE ? '<ul>' : '<ul data-role="listview">';
                }
                break;
            case 'attach':
            case 'upload':
                if ($is_read && (bool) ini_get('file_uploads') && !$is_freeze && !($_page == $whatsnew || $_page == $whatsdeleted) && !$is_readonly) {
                    $ret[] = _navibar($name);
                }
                break;
            case 'new':
            case 'newsub':
            case 'edit':
            case 'guiedit':
                if (!empty($_page) && $is_read && $function_freeze && !$is_freeze && !($_page == $whatsnew || $_page == $whatsdeleted) && !$is_readonly) {
                    $ret[] = _navibar($name);
                }
                break;
            case 'login':
                $auth_key = Auth::get_user_info();
                if (empty($auth_key['key'])) {
                    $ret[] = _navibar($name);
                }
                break;
            default:
                $ret[] = _navibar($name);
                break;
        }
    }
    if (end($ret) === '<ul>') {
        array_pop($ret);
        array_pop($ret);
    } else {
        $ret[] = '</ul>';
    }
    $body = "\n" . join('', $ret) . "\n";
    if (IS_MOBILE) {
        return $body;
    } else {
        return '<nav class="navibar">' . $body . '</nav>' . "\n";
    }
}
Esempio n. 24
0
function catbody($title, $page, $body)
{
    global $script, $vars, $arg, $defaultpage, $whatsnew, $help_page, $hr;
    global $attach_link, $related_link, $cantedit, $function_freeze;
    global $search_word_color, $_msg_word, $foot_explain, $note_hr, $head_tags;
    global $trackback, $trackback_javascript, $referer, $javascript;
    global $nofollow;
    global $_LANG, $_LINK, $_IMAGE;
    global $pkwk_dtd;
    // XHTML 1.1, XHTML1.0, HTML 4.01 Transitional...
    global $page_title;
    // Title of this site
    global $do_backup;
    // Do backup or not
    global $modifier;
    // Site administrator's  web page
    global $modifierlink;
    // Site administrator's name
    if (!file_exists(SKIN_FILE) || !is_readable(SKIN_FILE)) {
        die_message('SKIN_FILE is not found');
    }
    $_LINK = $_IMAGE = array();
    // Add JavaScript header when ...
    if ($trackback && $trackback_javascript) {
        $javascript = 1;
    }
    // Set something If you want
    if (!PKWK_ALLOW_JAVASCRIPT) {
        unset($javascript);
    }
    $_page = isset($vars['page']) ? $vars['page'] : '';
    $r_page = rawurlencode($_page);
    // Set $_LINK for skin
    $_LINK['add'] = "{$script}?cmd=add&amp;page={$r_page}";
    $_LINK['backup'] = "{$script}?cmd=backup&amp;page={$r_page}";
    $_LINK['copy'] = "{$script}?plugin=template&amp;refer={$r_page}";
    $_LINK['diff'] = "{$script}?cmd=diff&amp;page={$r_page}";
    $_LINK['edit'] = "{$script}?cmd=edit&amp;page={$r_page}";
    $_LINK['filelist'] = "{$script}?cmd=filelist";
    $_LINK['freeze'] = "{$script}?cmd=freeze&amp;page={$r_page}";
    $_LINK['help'] = "{$script}?" . rawurlencode($help_page);
    $_LINK['list'] = "{$script}?cmd=list";
    $_LINK['new'] = "{$script}?plugin=newpage&amp;refer={$r_page}";
    $_LINK['rdf'] = "{$script}?cmd=rss&amp;ver=1.0";
    $_LINK['recent'] = "{$script}?" . rawurlencode($whatsnew);
    $_LINK['refer'] = "{$script}?plugin=referer&amp;page={$r_page}";
    $_LINK['reload'] = "{$script}?{$r_page}";
    $_LINK['rename'] = "{$script}?plugin=rename&amp;refer={$r_page}";
    $_LINK['rss'] = "{$script}?cmd=rss";
    $_LINK['rss10'] = "{$script}?cmd=rss&amp;ver=1.0";
    // Same as 'rdf'
    $_LINK['rss20'] = "{$script}?cmd=rss&amp;ver=2.0";
    $_LINK['search'] = "{$script}?cmd=search";
    $_LINK['top'] = "{$script}?" . rawurlencode($defaultpage);
    if ($trackback) {
        $tb_id = tb_get_id($_page);
        $_LINK['trackback'] = "{$script}?plugin=tb&amp;__mode=view&amp;tb_id={$tb_id}";
    }
    $_LINK['unfreeze'] = "{$script}?cmd=unfreeze&amp;page={$r_page}";
    $_LINK['upload'] = "{$script}?plugin=attach&amp;pcmd=upload&amp;page={$r_page}";
    // Compat: Skins for 1.4.4 and before
    $link_add =& $_LINK['add'];
    $link_new =& $_LINK['new'];
    // New!
    $link_edit =& $_LINK['edit'];
    $link_diff =& $_LINK['diff'];
    $link_top =& $_LINK['top'];
    $link_list =& $_LINK['list'];
    $link_filelist =& $_LINK['filelist'];
    $link_search =& $_LINK['search'];
    $link_whatsnew =& $_LINK['recent'];
    $link_backup =& $_LINK['backup'];
    $link_help =& $_LINK['help'];
    $link_trackback =& $_LINK['trackback'];
    // New!
    $link_rdf =& $_LINK['rdf'];
    // New!
    $link_rss =& $_LINK['rss'];
    $link_rss10 =& $_LINK['rss10'];
    // New!
    $link_rss20 =& $_LINK['rss20'];
    // New!
    $link_freeze =& $_LINK['freeze'];
    $link_unfreeze =& $_LINK['unfreeze'];
    $link_upload =& $_LINK['upload'];
    $link_template =& $_LINK['copy'];
    $link_refer =& $_LINK['refer'];
    // New!
    $link_rename =& $_LINK['rename'];
    // Init flags
    $is_page = is_pagename($_page) && !arg_check('backup') && $_page != $whatsnew;
    $is_read = arg_check('read') && is_page($_page);
    $is_freeze = is_freeze($_page);
    // Last modification date (string) of the page
    $lastmodified = $is_read ? format_date(get_filetime($_page)) . ' ' . get_pg_passage($_page, FALSE) : '';
    // List of attached files to the page
    $attaches = $attach_link && $is_read && exist_plugin_action('attach') ? attach_filelist() : '';
    // List of related pages
    $related = $related_link && $is_read ? make_related($_page) : '';
    // List of footnotes
    ksort($foot_explain, SORT_NUMERIC);
    $notes = !empty($foot_explain) ? $note_hr . join("\n", $foot_explain) : '';
    // Tags will be inserted into <head></head>
    $head_tag = !empty($head_tags) ? join("\n", $head_tags) . "\n" : '';
    // 1.3.x compat
    // Last modification date (UNIX timestamp) of the page
    $fmt = $is_read ? get_filetime($_page) + LOCALZONE : 0;
    // Search words
    if ($search_word_color && isset($vars['word'])) {
        $body = '<div class="small">' . $_msg_word . htmlsc($vars['word']) . '</div>' . $hr . "\n" . $body;
        // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
        // with array_splice(), array_flip()
        $words = preg_split('/\\s+/', $vars['word'], -1, PREG_SPLIT_NO_EMPTY);
        $words = array_splice($words, 0, 10);
        // Max: 10 words
        $words = array_flip($words);
        $keys = array();
        foreach ($words as $word => $id) {
            $keys[$word] = strlen($word);
        }
        arsort($keys, SORT_NUMERIC);
        $keys = get_search_words(array_keys($keys), TRUE);
        $id = 0;
        foreach ($keys as $key => $pattern) {
            $s_key = htmlsc($key);
            $pattern = '/' . '<textarea[^>]*>.*?<\\/textarea>' . '|' . '<[^>]*>' . '|' . '&[^;]+;' . '|' . '(' . $pattern . ')' . '/sS';
            $decorate_Nth_word = create_function('$matches', 'return (isset($matches[1])) ? ' . '\'<strong class="word' . $id . '">\' . $matches[1] . \'</strong>\' : ' . '$matches[0];');
            $body = preg_replace_callback($pattern, $decorate_Nth_word, $body);
            $notes = preg_replace_callback($pattern, $decorate_Nth_word, $notes);
            ++$id;
        }
    }
    $longtaketime = getmicrotime() - MUTIME;
    $taketime = sprintf('%01.03f', $longtaketime);
    require SKIN_FILE;
}
Esempio n. 25
0
function attach_rename()
{
    global $vars, $_attach_messages;
    foreach (array('refer', 'file', 'age', 'pass', 'newname') as $var) {
        ${$var} = isset($vars[$var]) ? $vars[$var] : '';
    }
    if (is_freeze($refer) || !is_editable($refer)) {
        return array('msg' => $_attach_messages['err_noparm']);
    }
    $obj =& new AttachFile($refer, $file, $age);
    if (!$obj->getstatus()) {
        return array('msg' => $_attach_messages['err_notfound']);
    }
    return $obj->rename($pass, $newname);
}
Esempio n. 26
0
function plugin_navibar2_keyword($name)
{
    global $_LINK;
    global $do_backup, $trackback, $referer;
    global $function_freeze;
    global $vars;
    if ($_LINK['reload'] == '') {
        return array();
    }
    $_page = isset($vars['page']) ? $vars['page'] : '';
    $is_read = arg_check('read') && is_page($_page);
    $is_freeze = is_freeze($_page);
    switch ($name) {
        case 'freeze':
            if ($is_read && $function_freeze) {
                if (!$is_freeze) {
                    $name = 'freeze';
                    return _navigator2($name);
                }
            }
            break;
        case 'unfreeze':
            if ($is_read && $function_freeze) {
                if ($is_freeze) {
                    $name = 'unfreeze';
                    return _navigator2($name);
                }
            }
            break;
        case 'upload':
            if ($is_read && (bool) ini_get('file_uploads')) {
                return _navigator2($name);
            }
            break;
        case 'filelist':
            if (arg_check('list')) {
                return _navigator2($name);
            }
            break;
        case 'backup':
            if ($do_backup) {
                return _navigator2($name);
            }
            break;
        case 'brokenlink':
        case 'template':
        case 'source':
            if (!empty($_page)) {
                return _navigator2($name);
            }
            break;
        case 'trackback':
            if ($trackback) {
                $tbcount = tb_count($_page);
                if ($tbcount > 0) {
                    return _navigator2($name, 'Trackback(' . $tbcount . ')');
                } else {
                    if ($is_read) {
                        return array('text' => 'no Trackback');
                    } else {
                        if ($vars['cmd'] == 'list') {
                            return _navigator2($name, 'Trackback list');
                        }
                    }
                }
            }
            break;
        case 'refer':
        case 'skeylist':
        case 'linklist':
            if ($referer) {
                if (!isset($refcount)) {
                    $refcount = ref_count($vars['page']);
                }
                if ($refcount > 0) {
                    return _navigator2($name);
                }
            }
            break;
        case 'log_login':
            if (log_exist('login', $vars['page'])) {
                return _navigator2($name);
            }
            break;
        case 'log_check':
            if (log_exist('check', $vars['page'])) {
                return _navigator2($name);
            }
            break;
        case 'log_browse':
            if (log_exist('browse', $vars['page'])) {
                return _navigator2($name);
            }
            break;
        case 'log_update':
            if (log_exist('update', $vars['page'])) {
                return _navigator2($name);
            }
            break;
        case 'log_down':
            if (log_exist('download', $vars['page'])) {
                return _navigator2($name);
            }
            break;
            // case 'new':
        // case 'new':
        case 'newsub':
        case 'edit':
        case 'guiedit':
        case 'diff':
            if (!$is_read) {
                break;
            }
        default:
            return _navigator2($name);
    }
    return array();
}
Esempio n. 27
0
function plugin_suckerfish_keyword($name)
{
    global $do_backup, $trackback, $referer;
    global $function_freeze;
    global $vars;
    // $is_read = (arg_check('read') && is_page($vars['page']));
    $is_read = isset($vars['page']) && is_page($vars['page']);
    $is_readonly = Auth::check_role('readonly');
    $is_safemode = Auth::check_role('safemode');
    $is_createpage = Auth::is_check_role(PKWK_CREATE_PAGE);
    $num = func_num_args();
    $args = $num ? func_get_args() : array();
    switch ($name) {
        case 'freeze':
            if ($is_readonly) {
                break;
            }
            if (!$is_read) {
                break;
            }
            if ($function_freeze) {
                if (!is_freeze($vars['page'])) {
                    $name = 'freeze';
                } else {
                    $name = 'unfreeze';
                }
                return _suckerfish($name);
            }
            break;
        case 'upload':
            if ($is_readonly) {
                break;
            }
            if (!$is_read) {
                break;
            }
            if ($function_freeze && is_freeze($vars['page'])) {
                break;
            }
            if ((bool) ini_get('file_uploads')) {
                return _suckerfish($name);
            }
            break;
        case 'filelist':
            if (arg_check('list')) {
                return _suckerfish($name);
            }
            break;
        case 'backup':
            if ($do_backup) {
                return _suckerfish($name);
            }
            break;
        case 'referer':
            if ($referer) {
                return _suckerfish($name);
            }
            break;
        case 'rss':
        case 'mixirss':
            return _suckerfish($name);
            break;
        case 'diff':
            if (!$is_read) {
                break;
            }
            if ($is_safemode) {
                break;
            }
            return _suckerfish($name);
            break;
        case 'edit':
        case 'guiedit':
            if (!$is_read) {
                break;
            }
            if ($is_readonly) {
                break;
            }
            if ($function_freeze && is_freeze($vars['page'])) {
                break;
            }
            return _suckerfish($name);
            break;
        case 'new':
        case 'newsub':
            if ($is_createpage) {
                break;
            }
        case 'rename':
        case 'copy':
            if ($is_readonly) {
                break;
            }
        case 'reload':
        case 'print':
        case 'full':
            if (!$is_read) {
                break;
            }
        default:
            return _suckerfish($name);
            break;
    }
    return array();
}
Esempio n. 28
0
/**
 * Details of user
 * @param   $id  int   User's ID
 */
function get_user_info($id)
{
    $field = 'u.wechat,u.mobile_phone,u.home_phone,u.aliww,u.qq,u.rank_points,';
    $mem = new Memcache();
    $mem->connect('127.0.0.1', 11211);
    if ($mem->get("freeze_{$_SESSION['admin_id']}") || is_freeze()) {
        $field = '';
        $mem->set("freeze_{$_SESSION['admin_id']}", 1, false, 3600);
        $mem->close();
    }
    $sql_select = 'SELECT u.age,u.family_id,u.sex,IF(u.calendar=1,CONCAT(u.birthday,"【阴历】"),CONCAT(u.birthday,"【阳历】")) birthday,' . $field . 'u.user_name,u.role_id,u.characters,u.service_time,u.member_cid,u.number_purchased,u.habby,u.email,u.disease,m.card_number,' . 'u.disease_2,u.from_where,u.user_id,u.add_time,u.id_card,u.eff_id,u.qq,t.type_name customer_type,u.remarks' . ',u.level FROM' . $GLOBALS['ecs']->table('users') . ' u LEFT JOIN ' . $GLOBALS['ecs']->table('memship_number') . ' m ON m.user_id=u.user_id, ' . $GLOBALS['ecs']->table('customer_type') . " t WHERE u.customer_type=t.type_id AND u.user_id={$id}";
    $user_info = $GLOBALS['db']->getRow($sql_select);
    if (($_SERVER['REQUEST_TIME'] - $user_info['add_time']) / 60 / 60 / 24 > 1) {
        $user_info['from_where_edit'] = true;
    }
    //if (!admin_priv('all','',false)) {
    //    if($_SESSION['role_id'] != 33 && !in_array($_SESSION['admin_id'],array(4,493,554,330,277))){
    //        $user_info['mobile_phone'] = hideContact($user_info['mobile_phone']);
    //        $user_info['home_phone'] = hideContact($user_info['home_phone']);
    //    }
    //}
    //$sql_select = "SELECT r.rank_name,u.rank_points,u.user_rank FROM ".$GLOBALS['ecs']->table('user_rank').' r,'.
    //    $GLOBALS['ecs']->table('users')." u WHERE u.user_rank=r.rank_id AND u.user_id=$id";
    //$user_rank = array();
    //$user_rank[] = $GLOBALS['db']->getRow($sql_select);
    //$user_rank = reset($user_rank);
    //if(!$user_rank) {
    //    $user_rank = array('rank_name'=>'未分配','rank_points'=>0);
    //}
    //$user_info = array_merge($user_info,$user_rank);
    // 获取顾客地址
    $sql_select = 'SELECT p.region_name province,c.region_name city,d.region_name district,' . 'ua.address,ua.province province_id,ua.city city_id,ua.district district_id,ua.zipcode FROM ' . $GLOBALS['ecs']->table('user_address') . ' ua LEFT JOIN ' . $GLOBALS['ecs']->table('region') . ' p ON p.region_id=ua.province LEFT JOIN ' . $GLOBALS['ecs']->table('region') . ' c ON c.region_id=ua.city LEFT JOIN ' . $GLOBALS['ecs']->table('region') . ' d ON d.region_id=ua.district' . " WHERE ua.user_id={$id}";
    $user_region = $GLOBALS['db']->getAll($sql_select);
    if (is_array($user_region[0])) {
        $user_info = array_merge($user_info, $user_region[0]);
    }
    $sql_select = 'SELECT r.role_name platform FROM ' . $GLOBALS['ecs']->table('role') . ' r, ' . $GLOBALS['ecs']->table('users') . " u WHERE u.role_id=r.role_id AND u.user_id={$id}";
    $user_info['platform'] = $GLOBALS['db']->getOne($sql_select);
    // format time
    $user_info['add_time'] = date('Y-m-d H:i', $user_info['add_time']);
    // 添加时间
    $user_info['service_time'] = date('Y-m-d H:i', $user_info['service_time']);
    // 上次服务时间
    $user_info['birthday'] = mb_strlen($user_info['birthday']) > 12 ? $user_info['birthday'] : '';
    $user_info['disease'] = explode(':', $user_info['disease']);
    // 疾病
    $user_info['characters'] = explode(':', $user_info['characters']);
    // 性格
    // 获取顾客需求
    $sql_select = 'SELECT eff_name FROM ' . $GLOBALS['ecs']->table('effects') . " WHERE eff_id='{$user_info['eff_id']}'";
    $user_info['eff_name'] = $GLOBALS['db']->getOne($sql_select);
    // 获取顾客来源
    $sql_select = 'SELECT `from` FROM ' . $GLOBALS['ecs']->table('from_where') . " WHERE from_id='{$user_info['from_where']}'";
    $user_info['from_where'] = $GLOBALS['db']->getOne($sql_select);
    // 获取顾客经济来源
    $sql_select = 'SELECT income FROM ' . $GLOBALS['ecs']->table('income') . " WHERE income_id='{$user_info['income']}'";
    $user_info['income'] = $GLOBALS['db']->getOne($sql_select);
    return $user_info;
}
Esempio n. 29
0
 /**
  * Check if a page is restricted to edit or not
  *
  * PukiWiki API Extension
  *
  * @access public
  * @static
  * @param string $page
  * @return boolean
  * @uses sonots::is_edit_auth
  * @uses is_freeze (PukiWiki lib/func.php)
  * @version $Id: v 1.0 2008-06-05 11:14:46 sonots $
  */
 function is_edit_restrict($page)
 {
     return PKWK_READONLY > 0 or is_freeze($page) or sonots::is_edit_auth($page);
 }
Esempio n. 30
0
function plugin_approve_action()
{
    global $vars, $post;
    if (auth::check_role('readonly')) {
        die_message(_('PKWK_READONLY prohibits editing'));
    }
    if (auth::is_check_role(PKWK_CREATE_PAGE)) {
        die_message(_('PKWK_CREATE_PAGE prohibits editing'));
    }
    // Petit SPAM Check (Client(Browser)-Server Ticket Check)
    $spam = FALSE;
    if (function_exists('pkwk_session_start') && pkwk_session_start() != 0) {
        $s_tracker = md5(get_ticket() . 'Approve');
        error_log("\$s_tracker: " . $s_tracker);
        error_log("\$_SESSION['tracker']: " . $_SESSION['tracker']);
    } else {
        if (isset($post['encode_hint']) && $post['encode_hint'] != '') {
            error_log("\$post['encode_hint']: " . $post['encode_hint']);
            if (PKWK_ENCODING_HINT != $post['encode_hint']) {
                $spam = TRUE;
            }
        } else {
            error_log("PKWK_ENCODING_HINT: " . PKWK_ENCODING_HINT);
            if (PKWK_ENCODING_HINT != '') {
                $spam = TRUE;
            }
        }
        error_log("is_spampost: " . is_spampost(array('body'), PLUGIN_TRACKER_REJECT_SPAMCOUNT));
        if (is_spampost(array('body'), PLUGIN_TRACKER_REJECT_SPAMCOUNT)) {
            $spam = TRUE;
        }
    }
    error_log("isSpam: " . $spam);
    if ($spam) {
        honeypot_write();
        return array('msg' => 'cannot write', 'body' => '<p>prohibits editing</p>');
    }
    $name = isset($post['name']) ? $post['name'] : '';
    $page = isset($post['_page']) ? $post['_page'] : '';
    if ($name == '') {
        return '<p>approve(): empty name.</p>';
    }
    if ($page == '') {
        return '<p>approve(): empty page.</p>';
    }
    $config_path = PLUGIN_APPROVE_CONFIG_ROOT . $name;
    $config = new YamlConfig($config_path);
    if (!$config->read()) {
        return array('msg' => 'Approve', 'body' => '<p>approve(): failed to load config. "' . $config_path . '"</p>');
    }
    $pattern = $config[PLUGIN_APPROVE_KEY_PATTERN];
    $replace = $config[PLUGIN_APPROVE_KEY_REPLACE];
    $page_regex = $config[PLUGIN_APPROVE_KEY_PAGE_REGEX];
    if ($page == '') {
        return array('msg' => 'Approve', 'body' => '<p>approve(): empty page.</p>');
    }
    if ($pattern == '') {
        return array('msg' => 'Approve', 'body' => '<p>approve(): empty pattern.</p>');
    }
    if ($page_regex == '') {
        return array('msg' => 'Approve', 'body' => '<p>approve(): empty page_regex.</p>');
    }
    if (!preg_match($page_regex, $page)) {
        return array('msg' => 'Approve', 'body' => '<p>approve(): page not match.</p>');
    }
    if (PKWK_READONLY > 0 || is_freeze($vars['page']) || !plugin_approve_is_edit_authed($page)) {
        return array('msg' => 'Approve', 'body' => '<p>approve(): prohibit editing. "' . $page . '"</p>');
    }
    $source = get_source($page, TRUE, TRUE);
    if ($source === FALSE) {
        return array('msg' => 'Approve', 'body' => '<p>approve(): failed to load page. "' . $page . '"</p>');
    }
    if (strpos($source, $pattern) === FALSE) {
        return array('msg' => 'Approve', 'body' => '<p>approve(): pattern not match.</p>');
    }
    $source = str_replace($pattern, $replace, $source);
    //return array('msg'=>'Approve', 'body'=>$source);
    page_write($page, $source);
    pkwk_headers_sent();
    header('Location: ' . get_page_location_uri($page));
    exit;
}