/** * 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; }
/** * Preprocesses a blog post as its added to the feed. Makes sure to * remove the first header from the text (otherwise it would be doubled) * and takes care of presentation as configured via template. * * @param Doku_Event $event the event as triggered in feed.php * @param array $param empty * @return void */ function handle_item_add(Doku_Event $event, $param) { $opt = $event->data['opt']; $ditem = $event->data['ditem']; if ($opt['feed_mode'] !== 'blogtng') { return; } if ($opt['item_content'] !== 'html') { return; } if ($opt['link_to'] !== 'current') { return; } // don't add drafts to the feed if (p_get_metadata($ditem['id'], 'type') == 'draft') { $event->preventDefault(); return; } // retrieve first heading from page instructions $ins = p_cached_instructions(wikiFN($ditem['id'])); $headers = array_filter($ins, array($this, '_filterHeaders')); $headingIns = array_shift($headers); $firstheading = $headingIns[1][0]; $this->entryhelper->load_by_row($ditem['entry']); ob_start(); $this->entryhelper->tpl_content($ditem['entry']['blog'], 'feed'); $output = ob_get_contents(); ob_end_clean(); // make URLs work when canonical is not set, regexp instead of rerendering! global $conf; if (!$conf['canonical']) { $base = preg_quote(DOKU_REL, '/'); $output = preg_replace('/(<a href|<img src)="(' . $base . ')/s', '$1="' . DOKU_URL, $output); } // strip first heading and replace item title $event->data['item']->description = preg_replace('#[^\\n]*?>\\s*?' . preg_quote(hsc($firstheading), '#') . '\\s*?<.*\\n#', '', $output, 1); $event->data['item']->title = $ditem['entry']['title']; //only supported by RSS 0.91 and RSS 2.0 if ($ditem['entry']['commentstatus'] !== 'disabled') { $event->data['item']->comments = $event->data['item']->link . '#the__comments'; } }