Ejemplo n.º 1
0
function plugin_attach_action()
{
    global $vars, $_attach_messages, $_string;
    // Backward compatible
    if (isset($vars['openfile'])) {
        $vars['file'] = $vars['openfile'];
        $vars['pcmd'] = 'open';
    }
    if (isset($vars['delfile'])) {
        $vars['file'] = $vars['delfile'];
        $vars['pcmd'] = 'delete';
    }
    $pcmd = isset($vars['pcmd']) ? $vars['pcmd'] : NULL;
    $refer = isset($vars['refer']) ? $vars['refer'] : NULL;
    $pass = isset($vars['pass']) ? $vars['pass'] : NULL;
    $page = isset($vars['page']) ? $vars['page'] : $refer;
    if (!empty($page)) {
        $wiki = Factory::Wiki($page);
        if ($wiki->isValied()) {
            // メソッドによってパーミッションを分ける
            if (in_array($pcmd, array('info', 'open', 'list'))) {
                // 読み込み許可
                $wiki->checkReadable();
            } else {
                // 書き込み許可があるか
                $wiki->checkEditable();
            }
        }
    }
    if (in_array($pcmd, array('delete', 'freeze', 'unfreeze'))) {
        if (Auth::check_role('readonly')) {
            Utility::dieMessage($_string['error_prohibit']);
        }
    }
    switch ($pcmd) {
        case 'info':
            return attach_info();
        case 'delete':
            return attach_delete();
        case 'open':
            return attach_open();
        case 'list':
            return attach_list($page);
        case 'freeze':
            return attach_freeze(TRUE);
        case 'unfreeze':
            return attach_freeze(FALSE);
        case 'rename':
            return attach_rename();
        default:
        case 'upload':
            return attach_showform();
        case 'form':
            return array('msg' => str_replace('$1', $refer, $_attach_messages['msg_upload']), 'body' => attach_form($refer));
        case 'post':
            return attach_upload($page, $pass);
        case 'progress':
            return PluginRenderer::getUploadProgress();
    }
    return empty($page) || !$wiki->isValied() ? attach_list() : attach_showform();
}