Esempio n. 1
0
 /**
  * Handles the 'blogtng' feed mode and prevents the default action (recents).
  * Retrieves all blog posts as defined by blog and tags parameters, orders
  * and limits them as requested and returns them inside the event.
  *
  * @param Doku_Event   $event the event as triggered in feed.php
  * @param array        $param empty
  * @return void
  */
 function handle_mode_unknown(Doku_Event $event, $param)
 {
     $opt = $event->data['opt'];
     if ($opt['feed_mode'] != 'blogtng') {
         return;
     }
     $event->preventDefault();
     $event->data['data'] = array();
     $conf = array('blog' => explode(',', $opt['blog']), 'tags' => $opt['tags'] ? explode(',', $opt['tags']) : null, 'sortby' => $opt['sortby'], 'sortorder' => $opt['sortorder'], 'limit' => $opt['items'], 'offset' => 0);
     $this->tools->cleanConf($conf);
     $conf = array_merge($conf, $this->defaultConf);
     $posts = $this->entryhelper->get_posts($conf);
     foreach ($posts as $row) {
         $event->data['data'][] = array('id' => $row['page'], 'date' => $row['created'], 'user' => $row['author'], 'entry' => $row);
     }
 }
Esempio n. 2
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. 3
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. 4
0
 function output($name)
 {
     global $INFO;
     $name = preg_replace('/[^a-zA-Z_\\-]+/', '', $name);
     $tpl = helper_plugin_blogtng_tools::getTplFile($name, 'comments');
     if ($tpl === false) {
         return false;
     }
     $comment = $this;
     if ($comment->data['status'] == 'visible' || $comment->data['status'] == 'hidden' && $INFO['isadmin']) {
         $comment->num++;
         include $tpl;
     }
 }
Esempio n. 5
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;
     }
 }
Esempio n. 6
0
 /**
  * Display a list of recent comments
  */
 public function tpl_recentcomments($tpl = 'default', $num = 5, $blogs = array('default'), $types = array())
 {
     // check template
     $tpl = helper_plugin_blogtng_tools::getTplFile($tpl, 'recentcomments');
     if ($tpl === false) {
         return false;
     }
     if (!$this->sqlitehelper->ready()) {
         return false;
     }
     // prepare and execute query
     if (count($types)) {
         $types = $this->sqlitehelper->getDB()->quote_and_join($types, ',');
         $tquery = " AND B.source IN ({$types}) ";
     } else {
         $tquery = "";
     }
     $blog_query = '(A.blog = ' . $this->sqlitehelper->getDB()->quote_and_join($blogs, ' OR A.blog = ') . ')';
     $query = "SELECT A.pid as pid, page, title, cid\n                    FROM entries A, comments B\n                   WHERE {$blog_query}\n                     AND A.pid = B.pid\n                     {$tquery}\n                     AND B.status = 'visible'\n                     AND GETACCESSLEVEL(A.page) >= " . AUTH_READ . "\n                ORDER BY B.created DESC\n                   LIMIT " . (int) $num;
     $res = $this->sqlitehelper->getDB()->query($query);
     if (!$this->sqlitehelper->getDB()->res2count($res)) {
         return false;
     }
     // no results found
     $res = $this->sqlitehelper->getDB()->res2arr($res);
     // print all hits using the template
     foreach ($res as $row) {
         /** @var helper_plugin_blogtng_entry $entry */
         $entry = plugin_load('helper', 'blogtng_entry');
         $entry->load_by_pid($row['pid']);
         $comment = $this->comment_by_cid($row['cid']);
         include $tpl;
     }
     return true;
 }
Esempio n. 7
0
 function tpl_content($name, $type)
 {
     $whitelist = array('list', 'entry', 'feed');
     if (!in_array($type, $whitelist)) {
         return false;
     }
     $tpl = helper_plugin_blogtng_tools::getTplFile($name, $type);
     if ($tpl !== false) {
         $entry = $this;
         include $tpl;
     }
 }
Esempio n. 8
0
 /**
  * @param $name
  * @param $type
  */
 public function tpl_content($name, $type)
 {
     $whitelist = array('list', 'entry', 'feed', 'tagsearch');
     if (!in_array($type, $whitelist)) {
         return;
     }
     $tpl = helper_plugin_blogtng_tools::getTplFile($name, $type);
     if ($tpl !== false) {
         /** @noinspection PhpUnusedLocalVariableInspection */
         $entry = $this;
         //used in the included template
         include $tpl;
     }
 }