/** * Intercept the usual page display and replace it with a * blog template controlled one. * * @param Doku_Event $event event object by reference * @param array $param empty array as passed to register_hook() * @return void|bool */ function handle_tpl_act_render(Doku_Event $event, $param) { global $ID; if ($event->data != 'show') { return false; } $pid = md5($ID); $this->entryhelper->load_by_pid($pid); if ($this->entryhelper->get_blog() == '') { return true; } // we can handle it $event->preventDefault(); $this->commenthelper->setPid($pid); $this->entryhelper->tpl_content($this->entryhelper->entry['blog'], 'entry'); return true; }
/** * Returns a reference to the comment helper plugin preloaded with * the current entry */ public function &getCommentHelper() { if (!$this->commenthelper) { $this->commenthelper = plugin_load('helper', 'blogtng_comments'); $this->commenthelper->setPid($this->entry['pid']); } return $this->commenthelper; }
/** * 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; }
/** * Displays a single entry and related actions * * @author Michael Klier <*****@*****.**> * * @param $entry * @param $query */ private function xhtml_entry_item($entry, $query) { global $lang; global $ID; static $class = 'odd'; ptln('<tr class="' . $class . '">'); $class = $class == 'odd' ? 'even' : 'odd'; ptln('<td class="entry_created">' . dformat($entry['created']) . '</td>'); ptln('<td class="entry_author">' . hsc($entry['author']) . '</td>'); ptln('<td class="entry_title">' . html_wikilink(':' . $entry['page'], $entry['title']) . '</td>'); ptln('<td class="entry_set_blog">' . $this->xhtml_entry_edit_form($entry, $query, 'blog') . '</th>'); ptln('<td class="entry_set_commentstatus">' . $this->xhtml_entry_edit_form($entry, $query, 'commentstatus') . '</th>'); $this->commenthelper->setPid($entry['pid']); // search comments of this entry link ptln('<td class="entry_comments">'); $count = $this->commenthelper->get_count(null, true); if ($count > 0) { $params = array('do' => 'admin', 'page' => 'blogtng', 'btng[admin]' => 'search', 'btng[query][filter]' => 'comment', 'btng[query][pid]' => $entry['pid']); ptln('<a href="' . wl($ID, $params) . '" title="' . $this->getLang('comments') . '">' . $count . '</a>'); } else { ptln($count); } ptln('</td>'); // tags filter links ptln('<td class="entry_tags">'); $this->taghelper->load($entry['pid']); $tags = $this->taghelper->getTags(); $count = count($tags); for ($i = 0; $i < $count; $i++) { $params = array('do' => 'admin', 'page' => 'blogtng', 'btng[admin]' => 'search', 'btng[query][filter]' => 'tags', 'btng[query][string]' => $tags[$i]); $link = '<a href="' . wl($ID, $params) . '" title="' . $tags[$i] . '">' . $tags[$i] . '</a>'; if ($i < $count - 1) { $link .= ', '; } ptln($link); } ptln('</td>'); // edit links ptln('<td class="entry_edit">'); $params = array('id' => $entry['page'], 'do' => 'edit'); ptln('<a href="' . wl($ID, $params) . '" class="blogtng_btn_edit" title="' . $lang['btn_secedit'] . '">' . $lang['btn_secedit'] . '</a>'); ptln('</td>'); ptln('</tr>'); }
/** * 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; } }