/** * 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 all actions of the admin component * * @author Michael Klier <*****@*****.**> */ public function handle() { if (!isset($_REQUEST['btng']['admin'])) { $admin = null; } else { $admin = is_array($_REQUEST['btng']['admin']) ? key($_REQUEST['btng']['admin']) : $_REQUEST['btng']['admin']; } //skip actions when no valid security token given $noSecTokenNeeded = array('search', 'comment_edit', 'comment_preview', null); if (!in_array($admin, $noSecTokenNeeded) && !checkSecurityToken()) { $admin = null; } // handle actions switch ($admin) { case 'comment_save': // FIXME error handling? $comment = $_REQUEST['btng']['comment']; $this->commenthelper->save($comment); msg($this->getLang('msg_comment_save'), 1); break; case 'comment_delete': // FIXME error handling $comment = $_REQUEST['btng']['comment']; $this->commenthelper->delete($comment['cid']); msg($this->getLang('msg_comment_delete'), 1); break; case 'comment_batch_edit': $batch = $_REQUEST['btng']['admin']['comment_batch_edit']; $cids = $_REQUEST['btng']['comments']['cids']; if ($cids) { foreach ($cids as $cid) { switch ($batch) { // FIXME messages case 'delete': $this->commenthelper->delete($cid); msg($this->getLang('msg_comment_delete'), 1); break; case 'status_hidden': $this->commenthelper->moderate($cid, 'hidden'); msg($this->getLang('msg_comment_status_change'), 1); break; case 'status_visible': $this->commenthelper->moderate($cid, 'visible'); msg($this->getLang('msg_comment_status_change'), 1); break; } } } break; case 'entry_set_blog': // FIXME errors? $pid = $_REQUEST['btng']['entry']['pid']; $blog = $_REQUEST['btng']['entry']['blog']; if ($pid) { $blogs = $this->entryhelper->get_blogs(); if (in_array($blog, $blogs)) { $this->entryhelper->load_by_pid($pid); $this->entryhelper->entry['blog'] = $blog; $this->entryhelper->save(); } } msg($this->getLang('msg_entry_blog_change'), 1); break; case 'entry_set_commentstatus': $pid = $_REQUEST['btng']['entry']['pid']; $status = $_REQUEST['btng']['entry']['commentstatus']; if ($pid) { if (in_array($status, array('disabled', 'enabled', 'closed'))) { $this->entryhelper->load_by_pid($pid); $this->entryhelper->entry['commentstatus'] = $status; $this->entryhelper->save(); } } msg($this->getLang('msg_comment_status_change'), 1); break; default: // do nothing - show dashboard break; } }
/** * 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; } }