Ejemplo n.º 1
0
/**
 * Check the actions and get data for buttons and links
 *
 * Available actions are
 *
 *  edit        - edit/create/show/draft
 *  history     - old revisions
 *  recent      - recent changes
 *  login       - login/logout - if ACL enabled
 *  profile     - user profile (if logged in)
 *  index       - The index
 *  admin       - admin page - if enough rights
 *  top         - back to top
 *  back        - back to parent - if available
 *  backlink    - links to the list of backlinks
 *  subscribe/subscription- subscribe/unsubscribe
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Matthias Grimm <*****@*****.**>
 * @author Adrian Lang <*****@*****.**>
 *
 * @param string $type
 * @return array|bool|string
 */
function tpl_get_action($type)
{
    global $ID;
    global $INFO;
    global $REV;
    global $ACT;
    global $conf;
    /** @var Input $INPUT */
    global $INPUT;
    // check disabled actions and fix the badly named ones
    if ($type == 'history') {
        $type = 'revisions';
    }
    if ($type == 'subscription') {
        $type = 'subscribe';
    }
    if (!actionOK($type)) {
        return false;
    }
    $accesskey = null;
    $id = $ID;
    $method = 'get';
    $params = array('do' => $type);
    $nofollow = true;
    $replacement = '';
    switch ($type) {
        case 'edit':
            // most complicated type - we need to decide on current action
            if ($ACT == 'show' || $ACT == 'search') {
                $method = 'post';
                if ($INFO['writable']) {
                    $accesskey = 'e';
                    if (!empty($INFO['draft'])) {
                        $type = 'draft';
                        $params['do'] = 'draft';
                    } else {
                        $params['rev'] = $REV;
                        if (!$INFO['exists']) {
                            $type = 'create';
                        }
                    }
                } else {
                    if (!actionOK('source')) {
                        return false;
                    }
                    //pseudo action
                    $params['rev'] = $REV;
                    $type = 'source';
                    $accesskey = 'v';
                }
            } else {
                $params = array('do' => '');
                $type = 'show';
                $accesskey = 'v';
            }
            break;
        case 'revisions':
            $type = 'revs';
            $accesskey = 'o';
            break;
        case 'recent':
            $accesskey = 'r';
            break;
        case 'index':
            $accesskey = 'x';
            // allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml)
            if ($conf['start'] == $ID && !$conf['sitemap']) {
                $nofollow = false;
            }
            break;
        case 'top':
            $accesskey = 't';
            $params = array('do' => '');
            $id = '#dokuwiki__top';
            break;
        case 'back':
            $parent = tpl_getparent($ID);
            if (!$parent) {
                return false;
            }
            $id = $parent;
            $params = array('do' => '');
            $accesskey = 'b';
            break;
        case 'img_backto':
            $params = array();
            $accesskey = 'b';
            $replacement = $ID;
            break;
        case 'login':
            $params['sectok'] = getSecurityToken();
            if ($INPUT->server->has('REMOTE_USER')) {
                if (!actionOK('logout')) {
                    return false;
                }
                $params['do'] = 'logout';
                $type = 'logout';
            }
            break;
        case 'register':
            if ($INPUT->server->str('REMOTE_USER')) {
                return false;
            }
            break;
        case 'resendpwd':
            if ($INPUT->server->str('REMOTE_USER')) {
                return false;
            }
            break;
        case 'admin':
            if (!$INFO['ismanager']) {
                return false;
            }
            break;
        case 'revert':
            if (!$INFO['ismanager'] || !$REV || !$INFO['writable']) {
                return false;
            }
            $params['rev'] = $REV;
            $params['sectok'] = getSecurityToken();
            break;
        case 'subscribe':
            if (!$INPUT->server->str('REMOTE_USER')) {
                return false;
            }
            break;
        case 'backlink':
            break;
        case 'profile':
            if (!$INPUT->server->has('REMOTE_USER')) {
                return false;
            }
            break;
        case 'media':
            $params['ns'] = getNS($ID);
            break;
        case 'mediaManager':
            // View image in media manager
            global $IMG;
            $imgNS = getNS($IMG);
            $authNS = auth_quickaclcheck("{$imgNS}:*");
            if ($authNS < AUTH_UPLOAD) {
                return false;
            }
            $params = array('ns' => $imgNS, 'image' => $IMG, 'do' => 'media');
            //$type = 'media';
            break;
        default:
            return '[unknown %s type]';
    }
    return compact('accesskey', 'type', 'id', 'method', 'params', 'nofollow', 'replacement');
}
Ejemplo n.º 2
0
/**
 * Check the actions and get data for buttons and links
 *
 * Available actions are
 *
 *  edit        - edit/create/show/draft
 *  history     - old revisions
 *  recent      - recent changes
 *  login       - login/logout - if ACL enabled
 *  profile     - user profile (if logged in)
 *  index       - The index
 *  admin       - admin page - if enough rights
 *  top         - back to top
 *  back        - back to parent - if available
 *  backlink    - links to the list of backlinks
 *  subscribe/subscription- subscribe/unsubscribe
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Matthias Grimm <*****@*****.**>
 * @author Adrian Lang <*****@*****.**>
 * @param string $type
 * @return array|bool|string
 */
function tpl_get_action($type)
{
    global $ID;
    global $INFO;
    global $REV;
    global $ACT;
    // check disabled actions and fix the badly named ones
    if ($type == 'history') {
        $type = 'revisions';
    }
    if (!actionOK($type)) {
        return false;
    }
    $accesskey = null;
    $id = $ID;
    $method = 'get';
    $params = array('do' => $type);
    switch ($type) {
        case 'edit':
            // most complicated type - we need to decide on current action
            if ($ACT == 'show' || $ACT == 'search') {
                $method = 'post';
                if ($INFO['writable']) {
                    $accesskey = 'e';
                    if (!empty($INFO['draft'])) {
                        $type = 'draft';
                        $params['do'] = 'draft';
                    } else {
                        $params['rev'] = $REV;
                        if (!$INFO['exists']) {
                            $type = 'create';
                        }
                    }
                } else {
                    if (!actionOK('source')) {
                        return false;
                    }
                    //pseudo action
                    $params['rev'] = $REV;
                    $type = 'source';
                    $accesskey = 'v';
                }
            } else {
                $params = array();
                $type = 'show';
                $accesskey = 'v';
            }
            break;
        case 'revisions':
            $type = 'revs';
            $accesskey = 'o';
            break;
        case 'recent':
            $accesskey = 'r';
            break;
        case 'index':
            $accesskey = 'x';
            break;
        case 'top':
            $accesskey = 't';
            $params = array();
            $id = '#dokuwiki__top';
            break;
        case 'back':
            $parent = tpl_getparent($ID);
            if (!$parent) {
                return false;
            }
            $id = $parent;
            $params = array();
            $accesskey = 'b';
            break;
        case 'login':
            $params['sectok'] = getSecurityToken();
            if (isset($_SERVER['REMOTE_USER'])) {
                if (!actionOK('logout')) {
                    return false;
                }
                $params['do'] = 'logout';
                $type = 'logout';
            }
            break;
        case 'register':
            if ($_SERVER['REMOTE_USER']) {
                return false;
            }
            break;
        case 'resendpwd':
            if ($_SERVER['REMOTE_USER']) {
                return false;
            }
            break;
        case 'admin':
            if (!$INFO['ismanager']) {
                return false;
            }
            break;
        case 'revert':
            if (!$INFO['ismanager'] || !$REV || !$INFO['writable']) {
                return false;
            }
            $params['rev'] = $REV;
            $params['sectok'] = getSecurityToken();
            break;
            /** @noinspection PhpMissingBreakStatementInspection */
        /** @noinspection PhpMissingBreakStatementInspection */
        case 'subscription':
            $type = 'subscribe';
            $params['do'] = 'subscribe';
        case 'subscribe':
            if (!$_SERVER['REMOTE_USER']) {
                return false;
            }
            break;
        case 'backlink':
            break;
        case 'profile':
            if (!isset($_SERVER['REMOTE_USER'])) {
                return false;
            }
            break;
        case 'media':
            break;
        default:
            return '[unknown %s type]';
            break;
    }
    return compact('accesskey', 'type', 'id', 'method', 'params');
}
Ejemplo n.º 3
0
/**
 * Like the action buttons but links
 *
 * Available links are
 *
 *  edit    - edit/create/show link
 *  history - old revisions
 *  recent  - recent changes
 *  login   - login/logout link - if ACL enabled
 *  profile - user profile link (if logged in)
 *  index   - The index
 *  admin   - admin page - if enough rights
 *  top     - a back to top link
 *  back    - a back to parent link - if available
 *  backlink - links to the list of backlinks
 *  subscribe/subscription - subscribe/unsubscribe link
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Matthias Grimm <*****@*****.**>
 * @see    tpl_button
 */
function tpl_actionlink($type, $pre = '', $suf = '', $inner = '')
{
    global $ID;
    global $INFO;
    global $REV;
    global $ACT;
    global $conf;
    global $lang;
    global $auth;
    // check disabled actions and fix the badly named ones
    $ctype = $type;
    if ($type == 'history') {
        $ctype = 'revisions';
    }
    if (!actionOK($ctype)) {
        return false;
    }
    switch ($type) {
        case 'edit':
            #most complicated type - we need to decide on current action
            if ($ACT == 'show' || $ACT == 'search') {
                if ($INFO['writable']) {
                    if (!empty($INFO['draft'])) {
                        tpl_link(wl($ID, 'do=draft'), $pre . ($inner ? $inner : $lang['btn_draft']) . $suf, 'class="action edit" accesskey="e" rel="nofollow"');
                    } else {
                        if ($INFO['exists']) {
                            tpl_link(wl($ID, 'do=edit&amp;rev=' . $REV), $pre . ($inner ? $inner : $lang['btn_edit']) . $suf, 'class="action edit" accesskey="e" rel="nofollow"');
                        } else {
                            tpl_link(wl($ID, 'do=edit&amp;rev=' . $REV), $pre . ($inner ? $inner : $lang['btn_create']) . $suf, 'class="action create" accesskey="e" rel="nofollow"');
                        }
                    }
                } else {
                    if (!actionOK('source')) {
                        return false;
                    }
                    //pseudo action
                    tpl_link(wl($ID, 'do=edit&amp;rev=' . $REV), $pre . ($inner ? $inner : $lang['btn_source']) . $suf, 'class="action source" accesskey="v" rel="nofollow"');
                }
            } else {
                tpl_link(wl($ID, 'do=show'), $pre . ($inner ? $inner : $lang['btn_show']) . $suf, 'class="action show" accesskey="v" rel="nofollow"');
            }
            return true;
        case 'history':
            if (!actionOK('revisions')) {
                return false;
            }
            tpl_link(wl($ID, 'do=revisions'), $pre . ($inner ? $inner : $lang['btn_revs']) . $suf, 'class="action revisions" accesskey="o" rel="nofollow"');
            return true;
        case 'recent':
            if (!actionOK('recent')) {
                return false;
            }
            tpl_link(wl($ID, 'do=recent'), $pre . ($inner ? $inner : $lang['btn_recent']) . $suf, 'class="action recent" accesskey="r" rel="nofollow"');
            return true;
        case 'index':
            if (!actionOK('index')) {
                return false;
            }
            tpl_link(wl($ID, 'do=index'), $pre . ($inner ? $inner : $lang['btn_index']) . $suf, 'class="action index" accesskey="x" rel="nofollow"');
            return true;
        case 'top':
            print '<a href="#dokuwiki__top" class="action top" accesskey="x">' . $pre . ($inner ? $inner : $lang['btn_top']) . $suf . '</a>';
            return true;
        case 'back':
            if ($parent = tpl_getparent($ID)) {
                tpl_link(wl($parent, 'do=show'), $pre . ($inner ? $inner : $lang['btn_back']) . $suf, 'class="action back" accesskey="b" rel="nofollow"');
                return true;
            }
            return false;
        case 'login':
            if ($conf['useacl'] && $auth) {
                if ($_SERVER['REMOTE_USER']) {
                    tpl_link(wl($ID, 'do=logout&amp;sectok=' . getSecurityToken()), $pre . ($inner ? $inner : $lang['btn_logout']) . $suf, 'class="action logout" rel="nofollow"');
                } else {
                    tpl_link(wl($ID, 'do=login&amp;sectok=' . getSecurityToken()), $pre . ($inner ? $inner : $lang['btn_login']) . $suf, 'class="action login" rel="nofollow"');
                }
                return true;
            }
            return false;
        case 'admin':
            if ($INFO['ismanager']) {
                tpl_link(wl($ID, 'do=admin'), $pre . ($inner ? $inner : $lang['btn_admin']) . $suf, 'class="action admin" rel="nofollow"');
                return true;
            }
            return false;
        case 'subscribe':
        case 'subscription':
            if ($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1) {
                if ($_SERVER['REMOTE_USER']) {
                    if ($INFO['subscribed']) {
                        if (!actionOK('unsubscribe')) {
                            return false;
                        }
                        tpl_link(wl($ID, 'do=unsubscribe'), $pre . ($inner ? $inner : $lang['btn_unsubscribe']) . $suf, 'class="action unsubscribe" rel="nofollow"');
                    } else {
                        if (!actionOK('subscribe')) {
                            return false;
                        }
                        tpl_link(wl($ID, 'do=subscribe'), $pre . ($inner ? $inner : $lang['btn_subscribe']) . $suf, 'class="action subscribe" rel="nofollow"');
                    }
                    return true;
                }
            }
            return false;
        case 'subscribens':
            if ($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1) {
                if ($_SERVER['REMOTE_USER']) {
                    if ($INFO['subscribedns']) {
                        if (!actionOK('unsubscribens')) {
                            return false;
                        }
                        tpl_link(wl($ID, 'do=unsubscribens'), $pre . ($inner ? $inner : $lang['btn_unsubscribens']) . $suf, 'class="action unsubscribens" rel="nofollow"');
                    } else {
                        if (!actionOK('subscribens')) {
                            return false;
                        }
                        tpl_link(wl($ID, 'do=subscribens'), $pre . ($inner ? $inner : $lang['btn_subscribens']) . $suf, 'class="action subscribens" rel="nofollow"');
                    }
                    return true;
                }
            }
            return false;
        case 'backlink':
            if (!actionOK('backlink')) {
                return false;
            }
            tpl_link(wl($ID, 'do=backlink'), $pre . ($inner ? $inner : $lang['btn_backlink']) . $suf, 'class="action backlink" rel="nofollow"');
            return true;
        case 'profile':
            if ($conf['useacl'] && $auth && $_SERVER['REMOTE_USER'] && $auth->canDo('Profile') && $ACT != 'profile') {
                tpl_link(wl($ID, 'do=profile'), $pre . ($inner ? $inner : $lang['btn_profile']) . $suf, 'class="action profile" rel="nofollow"');
                return true;
            }
            return false;
        default:
            print '[unknown link type]';
            return true;
    }
}