Esempio n. 1
0
 /**
  * Handles the actual output creation.
  *
  * @param string          $mode     output format being rendered
  * @param Doku_Renderer   $renderer the current renderer object
  * @param array           $data     data created by handler()
  * @return  boolean                 rendered correctly? (however, returned value is not used at the moment)
  */
 public function render($mode, Doku_Renderer $renderer, $data)
 {
     if ($mode != 'xhtml') {
         return false;
     }
     $this->loadHelpers();
     // set target if not set yet
     global $ID;
     if (!isset($data['conf']['target'])) {
         $data['conf']['target'] = $ID;
     }
     // add additional data from request parameters
     if ($start = $this->tools->getParam('pagination/start')) {
         // start offset
         $data['conf']['offset'] = (int) $start;
     }
     if ($tags = $this->tools->getParam('post/tags')) {
         // tags
         $data['conf']['tags'] = array_merge($data['conf']['tags'], explode(',', $tags));
     }
     $data['conf']['tags'] = array_map('trim', $data['conf']['tags']);
     $data['conf']['tags'] = array_unique($data['conf']['tags']);
     $data['conf']['tags'] = array_filter($data['conf']['tags']);
     // dispatch to the correct type handler
     $renderer->info['cache'] = (bool) $data['conf']['cache'];
     switch ($data['type']) {
         case 'related':
             $renderer->doc .= $this->entryhelper->xhtml_related($data['conf']);
             break;
         case 'pagination':
             $renderer->doc .= $this->entryhelper->xhtml_pagination($data['conf']);
             break;
         case 'newform':
             $renderer->info['cache'] = false;
             //never cache this
             $renderer->doc .= $this->entryhelper->xhtml_newform($data['conf']);
             break;
         case 'recentcomments':
             // FIXME to cache or not to cache?
             $renderer->doc .= $this->commenthelper->xhtml_recentcomments($data['conf']);
             break;
         case 'tagcloud':
             $renderer->info['cache'] = false;
             // never cache this
             $renderer->doc .= $this->taghelper->xhtml_tagcloud($data['conf']);
             break;
         case 'tagsearch':
             $renderer->doc .= $this->entryhelper->xhtml_tagsearch($data['conf'], $renderer);
             break;
         default:
             $renderer->doc .= $this->entryhelper->xhtml_list($data['conf'], $renderer);
     }
     return true;
 }
Esempio n. 2
0
 /**
  * @return array|mixed
  */
 private function _get_post_tags()
 {
     $tags = $this->tools->getParam('post/tags');
     if ($tags === false) {
         return $tags;
     }
     if (!is_array($tags)) {
         $tags = helper_plugin_blogtng_tools::filterExplodeCSVinput($tags);
     }
     return $tags;
 }
Esempio n. 3
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.
  *
  * @param Doku_Event $event  event object by reference
  * @param array      $param  empty array as passed to register_hook()
  * @return bool
  */
 function handle_act_preprocess(Doku_Event $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']) ? cleanText($_REQUEST['wikitext']) : null;
     $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);
     //add "http(s)://" to website
     if (!preg_match('/^http/', $comment['web']) && $comment['web'] != '') {
         $comment['web'] = 'http://' . $comment['web'];
     }
     $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') {
             /** @var helper_plugin_captcha $helper */
             $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';
             //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';
             // hack to avoid redirect
             return false;
         }
     } else {
         return true;
     }
 }