Ejemplo n.º 1
0
/**
 * Handle page 'subscribe'
 *
 * Throws exception on error.
 *
 * @author Adrian Lang <*****@*****.**>
 */
function act_subscription($act)
{
    global $lang;
    global $INFO;
    global $ID;
    // get and preprocess data.
    $params = array();
    foreach (array('target', 'style', 'action') as $param) {
        if (isset($_REQUEST["sub_{$param}"])) {
            $params[$param] = $_REQUEST["sub_{$param}"];
        }
    }
    // any action given? if not just return and show the subscription page
    if (!$params['action'] || !checkSecurityToken()) {
        return $act;
    }
    // Handle POST data, may throw exception.
    trigger_event('ACTION_HANDLE_SUBSCRIBE', $params, 'subscription_handle_post');
    $target = $params['target'];
    $style = $params['style'];
    $data = $params['data'];
    $action = $params['action'];
    // Perform action.
    require_once DOKU_INC . 'inc/subscription.php';
    if (!subscription_set($_SERVER['REMOTE_USER'], $target, $style, $data)) {
        throw new Exception(sprintf($lang["subscr_{$action}_error"], hsc($INFO['userinfo']['name']), prettyprint_id($target)));
    }
    msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), prettyprint_id($target)), 1);
    act_redirect($ID, $act);
    // Assure that we have valid data if act_redirect somehow fails.
    $INFO['subscribed'] = get_info_subscribed();
    return 'show';
}
Ejemplo n.º 2
0
 /**
  * Handle the preprocess event
  *
  * Takes care of handling all the post input from creating
  * comments and saves them. Also handles optin and unsubscribe
  * actions.
  */
 function handle_act_preprocess(&$event, $param)
 {
     global $INFO, $ID;
     // optin
     if (isset($_REQUEST['btngo'])) {
         $this->commenthelper->optin($_REQUEST['btngo']);
     }
     // unsubscribe
     if (isset($_REQUEST['btngu'])) {
         $this->commenthelper->unsubscribe_by_key(md5($ID), $_REQUEST['btngu']);
     }
     global $BLOGTNG;
     $BLOGTNG = array();
     // prepare data for comment form
     $comment = array();
     $comment['source'] = $this->tools->getParam('comment/source');
     $comment['name'] = ($commentname = $this->tools->getParam('comment/name')) ? $commentname : $INFO['userinfo']['name'];
     $comment['mail'] = ($commentmail = $this->tools->getParam('comment/mail')) ? $commentmail : $INFO['userinfo']['mail'];
     $comment['web'] = ($commentweb = $this->tools->getParam('comment/web')) ? $commentweb : '';
     $comment['text'] = isset($_REQUEST['wikitext']) ? $_REQUEST['wikitext'] : null;
     // FIXME clean text
     $comment['pid'] = isset($_REQUEST['pid']) ? $_REQUEST['pid'] : null;
     $comment['page'] = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
     $comment['subscribe'] = isset($_REQUEST['blogtng']['subscribe']) ? $_REQUEST['blogtng']['subscribe'] : null;
     $comment['ip'] = clientIP(true);
     $BLOGTNG['comment'] = $comment;
     if (is_array($event->data) && (isset($event->data['comment_submit']) || isset($event->data['comment_preview']))) {
         if (isset($event->data['comment_submit'])) {
             $BLOGTNG['comment_action'] = 'submit';
         }
         if (isset($event->data['comment_preview'])) {
             $BLOGTNG['comment_action'] = 'preview';
         }
         // check for empty fields
         $BLOGTNG['comment_submit_errors'] = array();
         foreach (array('name', 'mail', 'text') as $field) {
             if (empty($comment[$field])) {
                 $BLOGTNG['comment_submit_errors'][$field] = true;
             }
         }
         // check CAPTCHA if available (on submit only)
         $captchaok = true;
         if ($BLOGTNG['comment_action'] == 'submit') {
             $helper = null;
             if (@is_dir(DOKU_PLUGIN . 'captcha')) {
                 $helper = plugin_load('helper', 'captcha');
             }
             if (!is_null($helper) && $helper->isEnabled()) {
                 $captchaok = $helper->check();
             }
         }
         // return on errors
         if (!empty($BLOGTNG['comment_submit_errors']) || !$captchaok) {
             $event->data = 'show';
             $_SERVER['REQUEST_METHOD'] = 'get';
             //FIXME hack to avoid redirect
             return false;
         }
         if ($BLOGTNG['comment_action'] == 'submit') {
             // save comment and redirect FIXME cid
             $this->commenthelper->save($comment);
             act_redirect($comment['page'], 'show');
         } elseif ($BLOGTNG['comment_action'] == 'preview') {
             $event->data = 'show';
             $_SERVER['REQUEST_METHOD'] = 'get';
             //FIXME hack to avoid redirect
             return false;
         }
     } else {
         return true;
     }
 }
Ejemplo n.º 3
0
/**
 * Handle 'login', 'logout'
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function act_auth($act)
{
    global $ID;
    global $INFO;
    //already logged in?
    if (isset($_SERVER['REMOTE_USER']) && $act == 'login') {
        return 'show';
    }
    //handle logout
    if ($act == 'logout') {
        $lockedby = checklock($ID);
        //page still locked?
        if ($lockedby == $_SERVER['REMOTE_USER']) {
            unlock($ID);
        }
        //try to unlock
        // do the logout stuff
        auth_logoff();
        // rebuild info array
        $INFO = pageinfo();
        act_redirect($ID, 'login');
    }
    return $act;
}
Ejemplo n.º 4
0
/**
 * Handle page 'subscribe'
 *
 * Throws exception on error.
 *
 * @author Adrian Lang <*****@*****.**>
 *
 * @param string $act action command
 * @return string action command
 * @throws Exception if (un)subscribing fails
 */
function act_subscription($act)
{
    global $lang;
    global $INFO;
    global $ID;
    /* @var Input $INPUT */
    global $INPUT;
    // subcriptions work for logged in users only
    if (!$INPUT->server->str('REMOTE_USER')) {
        return 'show';
    }
    // get and preprocess data.
    $params = array();
    foreach (array('target', 'style', 'action') as $param) {
        if ($INPUT->has("sub_{$param}")) {
            $params[$param] = $INPUT->str("sub_{$param}");
        }
    }
    // any action given? if not just return and show the subscription page
    if (empty($params['action']) || !checkSecurityToken()) {
        return $act;
    }
    // Handle POST data, may throw exception.
    trigger_event('ACTION_HANDLE_SUBSCRIBE', $params, 'subscription_handle_post');
    $target = $params['target'];
    $style = $params['style'];
    $action = $params['action'];
    // Perform action.
    $sub = new Subscription();
    if ($action == 'unsubscribe') {
        $ok = $sub->remove($target, $INPUT->server->str('REMOTE_USER'), $style);
    } else {
        $ok = $sub->add($target, $INPUT->server->str('REMOTE_USER'), $style);
    }
    if ($ok) {
        msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), prettyprint_id($target)), 1);
        act_redirect($ID, $act);
    } else {
        throw new Exception(sprintf($lang["subscr_{$action}_error"], hsc($INFO['userinfo']['name']), prettyprint_id($target)));
    }
    // Assure that we have valid data if act_redirect somehow fails.
    $INFO['subscribed'] = $sub->user_subscription();
    return 'show';
}