/** * Updates the metadata in the blogtng database. * * @param Doku_Event $event * @param $params */ function update_data(Doku_Event $event, $params) { global $ID; /** @var DokuWiki_Auth_Plugin $auth */ global $auth; $data = $event->result; //newly rendered data is here. $pid = md5($ID); $this->entryhelper->load_by_pid($pid); //only refreshing for blog entries if ($this->entryhelper->entry['blog']) { // fetch author info $login = $this->entryhelper->entry['login']; if (!$login) { $login = $data['current']['user']; } if (!$login) { $login = $_SERVER['REMOTE_USER']; } $userdata = false; if ($login) { if ($auth != null) { $userdata = $auth->getUserData($login); } } // fetch dates $date_created = $data['current']['date']['created']; $date_modified = $data['current']['date']['modified']; // prepare entry ... $entry = array('page' => $ID, 'title' => $data['current']['title'], 'image' => $data['current']['relation']['firstimage'], 'created' => $date_created, 'lastmod' => !$date_modified ? $date_created : $date_modified, 'login' => $login, 'author' => $userdata ? $userdata['name'] : $login, 'mail' => $userdata ? $userdata['mail'] : ''); $this->entryhelper->set($entry); // ... and save it $this->entryhelper->save(); } // unset old persistent tag data if (isset($data['persistent']['subject'])) { // persistent metadata is copied to the current metadata, clean current metadata // if it hasn't been changed in the renderer if ($data['persistent']['subject'] == $data['current']['subject']) { $event->result['current']['subject'] = array(); } unset($event->result['persistent']['subject']); } // save blogtng tags to the metadata of the page $taghelper = $this->entryhelper->getTagHelper(); if (isset($data['current']['subject'])) { $event->result['current']['subject'] = array_unique(array_merge((array) $data['current']['subject'], $taghelper->getTags())); } else { $event->result['current']['subject'] = $taghelper->getTags(); } }
/** * 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; }
/** * Add next and prev meta headers for navigating through * blog posts * * @param Doku_Event $event event object by reference * @param array $param empty array as passed to register_hook() * @return void|bool */ function handle_metaheader_output(Doku_Event $event, $param) { global $ACT, $ID; if ($ACT != 'show') { return false; } $pid = md5($ID); $this->entryhelper->load_by_pid($pid); if ($this->entryhelper->get_blog() == '') { return true; } $relatedentries = $this->entryhelper->getAdjacentLinks($ID); if (isset($relatedentries['prev'])) { $event->data['link'][] = array('rel' => 'prev', 'href' => wl($relatedentries['prev']['page'], '')); } if (isset($relatedentries['next'])) { $event->data['link'][] = array('rel' => 'next', 'href' => wl($relatedentries['next']['page'], '')); } return true; }
/** * Displays the search form * * @author Michael Klier <*****@*****.**> */ private function xhtml_search_form() { global $lang; ptln('<div class="level1">'); $blogs = $this->entryhelper->get_blogs(); $form = new Doku_Form(array('id' => 'blogtng__search_form')); $form->startFieldset($lang['btn_search']); $form->addHidden('page', 'blogtng'); $form->addHidden('btng[admin]', 'search'); $form->addElement(form_makeListBoxField('btng[query][blog]', $blogs, $_REQUEST['btng']['query']['blog'], $this->getLang('blog'))); $form->addElement(form_makeListBoxField('btng[query][filter]', array('entry_title', 'entry_author', 'comment', 'comment_ip', 'tags'), $_REQUEST['btng']['query']['filter'], $this->getLang('filter'))); $form->addElement(form_makeTextField('btng[query][string]', $_REQUEST['btng']['query']['string'], '')); $form->addElement(form_makeButton('submit', 'admin', $lang['btn_search'])); $form->endFieldset(); html_form('blogtng__search_form', $form); ptln('</div>'); }
/** * 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'; } }
<?php $blogtng_meta__excluded_syntax = array('info', 'blogtng_commentreply', 'blogtng_blog', 'blogtng_readmore', 'blogtng_header', 'blogtng_topic'); $meta['default_commentstatus'] = array('multichoice', '_choices' => array('enabled', 'closed', 'disabled')); $meta['default_blog'] = array('multichoice', '_choices' => helper_plugin_blogtng_entry::get_blogs()); $meta['default_tags'] = array('string'); $meta['comments_allow_web'] = array('onoff'); $meta['comments_subscription'] = array('onoff'); $meta['comments_gravatar_rating'] = array('multichoice', '_choices' => array('X', 'R', 'PG', 'G')); $meta['comments_gravatar_default'] = array('multichoice', '_choices' => array('blank', 'default', 'identicon', 'monsterid', 'wavatar')); $meta['comments_forbid_syntax'] = array('multicheckbox', '_choices' => array_diff(plugin_list('syntax'), $blogtng_meta__excluded_syntax)); $meta['comments_xhtml_renderer'] = array('multicheckbox', '_choices' => array_diff(plugin_list('syntax'), $blogtng_meta__excluded_syntax)); $meta['editform_set_date'] = array('onoff'); $meta['tags'] = array('string'); $meta['receive_linkbacks'] = array('onoff'); $meta['send_linkbacks'] = array('onoff');
/** * Save the blog related meta data of a page to the sqlite DB * * @param Doku_Event $event * @param $param */ function handle_action_act_preprocess(Doku_Event $event, $param) { list($type) = $param; switch ($type) { case 'before': if (is_array($event->data)) { list($this->preact) = array_keys($event->data); } else { $this->preact = $event->data; } break; case 'after': global $ID; if ($this->preact != 'save' || $event->data != 'show') { return; } // does the page still exist? might be a deletion if (!page_exists($ID)) { return; } $blog = $this->tools->getParam('post/blog'); $blogs = $this->entryhelper->get_blogs(); if (!in_array($blog, $blogs)) { $blog = null; } if ($blog === null) { $this->entryhelper->poke(); } else { $pid = md5($ID); $this->entryhelper->load_by_pid($pid); $entry = $this->_collectInfoForEntry(); $this->entryhelper->set($entry); $this->entryhelper->entry['blog'] = $blog; $this->entryhelper->entry['commentstatus'] = $this->tools->getParam('post/commentstatus'); if (empty($this->entryhelper->entry['page'])) { $this->entryhelper->entry['page'] = $ID; } // allow to override created date if ($this->tools->getParam('post/date') && $this->getConf('editform_set_date')) { foreach (array('hh', 'mm', 'MM', 'DD') as $key) { $_REQUEST['btng']['post']['date'][$key] = $_REQUEST['btng']['post']['date'][$key][0] == 0 ? $_REQUEST['btng']['post']['date'][$key][1] : $_REQUEST['btng']['post']['date'][$key]; } $time = mktime($this->tools->getParam('post/date/hh'), $this->tools->getParam('post/date/mm'), 0, $this->tools->getParam('post/date/MM'), $this->tools->getParam('post/date/DD'), $this->tools->getParam('post/date/YY')); $this->entryhelper->entry['created'] = $time; } $this->entryhelper->save(); $tags = $this->_get_post_tags(); if ($tags === false) { $tags = array(); } $allowed_tags = $this->_get_allowed_tags(); if (count($allowed_tags) > 0) { foreach ($tags as $n => $tag) { if (!in_array($tag, $allowed_tags)) { unset($tags[$n]); } } } $this->taghelper->load($pid); $this->taghelper->setTags($tags); $this->taghelper->save(); } break; } }