Пример #1
0
function plugin_wikinote_action()
{
    global $vars, $post;
    $_post = array();
    foreach ($post as $key => $value) {
        if (strpos($key, '_wikinote_') === 0) {
            $_post[substr($key, 10)] = $value;
        }
    }
    $page = '';
    if (isset($_post['refer'])) {
        $page = $_post['refer'];
    } elseif (isset($vars['page'])) {
        $page = $vars['page'];
    }
    if ($page === '') {
        return;
    }
    // if the notepage exists already, do nothing
    if (is_page($page)) {
        header('Location: ' . get_script_uri() . '?' . rawurlencode($page));
        exit;
    }
    $wikinote = new PluginWikinote();
    if (!$wikinote->is_effect($page)) {
        return;
    }
    if (!$wikinote->is_notepage($page)) {
        return;
    }
    // if the wikinote page does not exist, show template html
    if (empty($_post)) {
        return $wikinote->show_template_html($page);
    }
    // if POST, create the notepage
    // Check whether the POST is for allowed plugins or not
    $allowed = TRUE;
    if (isset($_post['plugin']) && isset($wikinote->allowed_plugin[$_post['plugin']])) {
        foreach ($wikinote->allowed_plugin[$_post['plugin']] as $name) {
            if ($_post[$name] === NULL || $_post[$name] === '') {
                $allowed = FALSE;
                break;
            }
        }
    } else {
        $allowed = FALSE;
    }
    if (!$allowed) {
        header('Location: ' . get_script_uri() . '?cmd=wikinote&page=' . rawurlencode($page));
        exit;
    }
    // create the notepage
    $vars['cmd'] = 'read';
    if (!$wikinote->create_notepage($page)) {
        header('Location: ' . get_script_uri() . '?cmd=wikinote&page=' . rawurlencode($page));
        exit;
    }
    $_post['digest'] = md5(@join('', get_source($page)));
    $vars = $post = $_post;
    return do_plugin_action($post['plugin']);
}