function handle_revisions(Doku_Event &$event, $param)
 {
     global $ID;
     global $INFO;
     if (!$this->hlp->isActive()) {
         return;
     }
     $meta = p_get_metadata($ID);
     $latest_rev = $meta['last_change']['date'];
     $member = null;
     foreach ($event->data->_content as $key => $ref) {
         if (isset($ref['_elem']) && $ref['_elem'] == 'opentag' && $ref['_tag'] == 'div' && $ref['class'] == 'li') {
             $member = $key;
         }
         if ($member && $ref['_elem'] == 'tag' && $ref['_tag'] == 'input' && $ref['name'] == 'rev2[]') {
             $revision = $ref['value'];
             if ($revision == 'current') {
                 $revision = $INFO['meta']['date']['modified'];
             }
             if ($this->hlp->isRevisionApproved($revision)) {
                 $event->data->_content[$member]['class'] = 'li approved_revision';
             } else {
                 $event->data->_content[$member]['class'] = 'li unapproved_revision';
             }
             $member = null;
         }
     }
     return true;
 }
Example #2
0
 function handle_ajax_call(&$event, $param)
 {
     if ($event->data == 'plugin_do') {
         $id = cleanID($_REQUEST['do_page']);
         if (auth_quickaclcheck($id) < AUTH_EDIT) {
             echo -1;
             $event->preventDefault();
             $event->stopPropagation();
             return false;
         }
         // toggle status of a single task
         $hlp = plugin_load('helper', 'do');
         $status = $hlp->toggleTaskStatus($id, $_REQUEST['do_md5'], $_REQUEST['do_commit']);
         // rerender the page
         p_get_metadata(cleanID($_REQUEST['do_page']), '', true);
         header('Content-Type: text/plain; charset=utf-8');
         echo $status;
         $event->preventDefault();
         $event->stopPropagation();
         return false;
     } elseif ($event->data == 'plugin_do_status') {
         // read status for a bunch of tasks
         require_once DOKU_INC . 'inc/JSON.php';
         $JSON = new JSON();
         $hlp = plugin_load('helper', 'do');
         $status = $hlp->getAllPageStatuses(cleanID($_REQUEST['do_page']));
         $status = $JSON->encode($status);
         header('Content-Type: text/plain; charset=utf-8');
         echo $status;
         $event->preventDefault();
         $event->stopPropagation();
         return false;
     }
     return true;
 }
Example #3
0
 /**
  * This function loads and returns the persistent metadata for the move plugin. If there is metadata for the
  * pagemove plugin (not the old one but the version that immediately preceeded the move plugin) it will be migrated.
  *
  * @param string $id The id of the page the metadata shall be loaded for
  * @return array|null The metadata of the page
  */
 public function getMoveMeta($id)
 {
     $all_meta = p_get_metadata($id, '', METADATA_DONT_RENDER);
     /* todo migrate old move data
        if(isset($all_meta['plugin_pagemove']) && !is_null($all_meta['plugin_pagemove'])) {
            if(isset($all_meta[self::METAKEY])) {
                $all_meta[self::METAKEY] = array_merge_recursive($all_meta['plugin_pagemove'], $all_meta[self::METAKEY]);
            } else {
                $all_meta[self::METAKEY] = $all_meta['plugin_pagemove'];
            }
            p_set_metadata($id, array(self::METAKEY => $all_meta[self::METAKEY], 'plugin_pagemove' => null), false, true);
        }
        */
     $meta = isset($all_meta[self::METAKEY]) ? $all_meta[self::METAKEY] : array();
     if (!isset($meta['origin'])) {
         $meta['origin'] = '';
     }
     if (!isset($meta['pages'])) {
         $meta['pages'] = array();
     }
     if (!isset($meta['media'])) {
         $meta['media'] = array();
     }
     return $meta;
 }
 function render($format, &$renderer, $data)
 {
     if ($this->active) {
         $key = 'test_during_rendering';
         p_set_metadata($this->id, array($key => 'test'), false, true);
         // ensure that the metadata property hasn't been set previously
         $this->assertNotEqual($key, p_get_metadata($this->id, $key));
     }
 }
Example #5
0
 public function test_relation_references_without_link()
 {
     $text = "My page without a link.";
     $id = "source";
     saveWikiText($id, $text, 'Created');
     self::assertEquals(null, p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED));
     $text .= DOKU_LF . "~~META:relation references=foo~~";
     saveWikiText($id, $text, 'Updated');
     self::assertEquals(array('foo' => false), p_get_metadata($id, 'relation references', METADATA_RENDER_UNLIMITED));
 }
Example #6
0
 /**
  * Handle PARSER_CACHE_USE:BEFORE event
  */
 public function beforeParserCacheUse($event, $param)
 {
     global $ID;
     $cache = $event->data;
     if (isset($cache->mode) && $cache->mode == 'xhtml') {
         $depends = p_get_metadata($ID, 'relation depends');
         if (!empty($depends) && isset($depends['rendering'])) {
             $this->addDependencies($cache, array_keys($depends['rendering']));
         }
     }
 }
 /**
  * Create a new Jive discussion for the current wiki page
  * 
  * @return string URL to the discussion on the Jive server or NULL
  */
 public function createJiveDiscussion()
 {
     global $ID;
     global $conf;
     if (($jive = $this->loadHelper('jive')) === NULL) {
         msg('Cannot load helper for jive plugin.', -1);
         return NULL;
     }
     if ($jive->jiveInitServer() === FALSE) {
         msg('Failed to contact the Jive server: ' . $jive->jiveLastErrorMsg(), -1);
         return NULL;
     }
     if (($placeID = $jive->getJiveGroup(NULL)) === NULL) {
         msg('Failed to get Jive group: ' . $jive->jiveLastErrorMsg(), -1);
         return NULL;
     }
     // Get the title of the current page
     $title = p_get_metadata(cleanID($ID), 'title', METADATA_DONT_RENDER);
     if ($title === NULL || $title == '') {
         msg('Failed to get page title from metadata', -1);
         return NULL;
     }
     // create the JSON request data
     if (($json = json_encode(array("content" => array("type" => "text/html", "text" => sprintf($this->getLang('jiveDiscussionContent'), DOKU_URL . $ID, $title)), "subject" => sprintf($this->getLang('jiveDiscussionSubject'), $title), "type" => "discussion", "tags" => array($conf['title'])))) === FALSE) {
         msg('Error encoding discussion creation post to JSON', -1);
         return NULL;
     }
     if (($data = $jive->postJiveData('/places/' . $placeID . '/contents', $json)) === FALSE) {
         msg('Failed to create discussion for that page: ' . $jive->jiveLastErrorMsg(), -1);
         return NULL;
     }
     // Get and store useful URLs in metadata of the page
     $info = json_decode($data, TRUE);
     if ($info === NULL && json_last_error() !== JSON_ERROR_NONE) {
         msg('Failed to decode JSON returned on create Discussion. JSON error: ' . json_last_error_msg(), -1);
         return NULL;
     }
     if (isset($info['error'])) {
         msg('Failed to create Discussion. JSON data returned:<br>' . $info, -1);
         return NULL;
     }
     if (!isset($info['contentID'])) {
         msg('Failed to get contentID for Discussion created. JSON data returned:<br>' . $info, -1);
         return NULL;
     }
     $meta = array('relation' => array('jive_plugin' => array('discussion_contentID' => $info['contentID'], 'discussion_html' => $info['resources']['html']['ref'])));
     if (p_set_metadata(cleanID($ID), $meta) === FALSE) {
         msg('Failed to store metadata. Warning: multiple discussions on the same page maybe created.', -1);
         return NULL;
     }
     return $info['resources']['html']['ref'];
 }
Example #8
0
 function _cache_prepare(&$event, $param)
 {
     global $conf;
     $cache =& $event->data;
     if (!isset($cache->page)) {
         return;
     }
     //if(!isset($cache->mode) || !in_array($cache->mode, $this->supportedModes)) return;
     $depends = p_get_metadata($cache->page);
     if (!is_array($depends)) {
         return;
     }
     // nothing to do
     $cache->depends['purge'] = true;
     /*
     error_log("page: ".$cache->page);
     
             $depends = p_get_metadata($cache->page, 'plugin_driver');
     
             if (!is_array($depends)) return; // nothing to do for us
     
             if (!is_array($depends['pages']) ||
                 !is_array($depends['instructions']) ||
                 $depends['pages'] != $this->helper->_get_included_pages_from_meta_instructions($depends['instructions']) ||
                 // the include_content url parameter may change the behavior for included pages
                 $depends['include_content'] != isset($_REQUEST['include_content'])) {
     
                 $cache->depends['purge'] = true; // included pages changed or old metadata - request purge.
       
             } else {
                 // add plugin.info.txt to depends for nicer upgrades
                 $cache->depends['files'][] = dirname(__FILE__) . '/plugin.info.txt';
                 foreach ($depends['pages'] as $page) {
                     if (!$page['exists']) continue;
                     $file = wikiFN($page['id']);
                     if (!in_array($file, $cache->depends['files'])) {
                         $cache->depends['files'][] = $file;
                     }
                 }
             }
     */
     /*	
     error_log("page: ".$cache->page);
     
     $id = $cache->page;
     $data = array('cache' => 'expire');
     $render = false;
     $persistent = false;
     
     p_set_metadata($id, $data, $render, $persistent);
     */
 }
function _tpl_toc($return = false)
{
    global $TOC;
    global $ACT;
    global $ID;
    global $REV;
    global $INFO;
    global $conf;
    global $INPUT;
    $toc = array();
    //if(is_array($TOC))
    // NOTE:
    // This will happen if sidebar has headings in it, so we don't want to use
    // a TOC from the global scope. I suspect this could break some plugins.
    if (($ACT == 'show' || substr($ACT, 0, 6) == 'export') && !$REV && $INFO['exists']) {
        // get TOC from metadata, render if neccessary
        $meta = p_get_metadata($ID, false, METADATA_RENDER_USING_CACHE);
        if (isset($meta['internal']['toc'])) {
            $tocok = $meta['internal']['toc'];
        } else {
            $tocok = true;
        }
        $toc = $meta['description']['tableofcontents'];
        if (!$tocok || !is_array($toc) || !$conf['tocminheads'] || count($toc) < $conf['tocminheads']) {
            $toc = array();
        }
    } elseif ($ACT == 'admin') {
        // try to load admin plugin TOC FIXME: duplicates code from tpl_admin
        $plugin = null;
        $class = $INPUT->str('page');
        if (!empty($class)) {
            $pluginlist = plugin_list('admin');
            if (in_array($class, $pluginlist)) {
                // attempt to load the plugin
                /** @var $plugin DokuWiki_Admin_Plugin */
                $plugin =& plugin_load('admin', $class);
            }
        }
        if ($plugin !== null && (!$plugin->forAdminOnly() || $INFO['isadmin'])) {
            $toc = $plugin->getTOC();
            $TOC = $toc;
            // avoid later rebuild
        }
    }
    trigger_event('TPL_TOC_RENDER', $toc, null, false);
    $html = bootstrap_html_TOC($toc);
    if ($return) {
        return $html;
    }
    echo $html;
    return '';
}
Example #10
0
 function debug(&$event, $param)
 {
     global $ID;
     ptln('<h1>Publish plug-in debug</h1>');
     ptln('<h1>Metadata</h1>');
     ptln('<pre>');
     ptln(print_r(p_get_metadata($ID), true));
     ptln('</pre>');
     ptln('<h1>pageinfo</h1>');
     ptln('<pre>');
     ptln(print_r(pageinfo(), true));
     ptln('</pre>');
 }
 public function handle_dokuwiki_started(&$event, $param)
 {
     global $ID, $ACT, $REV;
     if ($ACT != 'show' && $ACT != '' || $REV) {
         return;
     }
     $page = p_get_metadata($ID, 'relation isreplacedby');
     // return if no redirection data
     if (empty($page)) {
         return;
     }
     if (isset($_GET['redirect'])) {
         // return if redirection is temporarily disabled,
         // or we have been redirected 5 times in a row
         if ($_GET['redirect'] == 'no' || $_GET['redirect'] > 4) {
             return;
         } elseif ($_GET['redirect'] > 0) {
             $redirect = $_GET['redirect'] + 1;
         } else {
             $redirect = 1;
         }
     } else {
         $redirect = 1;
     }
     // verify metadata currency
     if (@filemtime(metaFN($ID, '.meta')) < @filemtime(wikiFN($ID))) {
         return;
     }
     // preserve #section from $page
     list($page, $section) = explode('#', $page, 2);
     if (isset($section)) {
         $section = '#' . $section;
     } else {
         $section = '';
     }
     // prepare link for internal redirects, keep external targets
     if (!preg_match('#^https?://#i', $page)) {
         $page = wl($page, array('redirect' => $redirect), TRUE, '&');
         if (!headers_sent() && $this->getConf('show_note')) {
             // remember to show note about being redirected from another page
             session_start();
             $_SESSION[DOKU_COOKIE]['redirect'] = $ID;
         }
     }
     // redirect
     header("HTTP/1.1 301 Moved Permanently");
     header("Location: " . $page . $section . $_SERVER['QUERY_STRING']);
     exit;
 }
Example #12
0
 /**
  * Handler for the ACTION_ACT_PREPROCESS event and AFTER advise.
  * 
  * Sends linkback if previous action was 'save' and new one is show.
  */
 function handle_action_act_preprocess_after(&$event, $params)
 {
     global $ID;
     global $ACT;
     global $conf;
     // only perform linkbacks on save of a wikipage
     if ($this->preact != 'save' || $event->data != 'show') {
         return;
     }
     // if guests are not allowed to perform linkbacks, return
     if (!$this->getConf('allow_guests') && !$_SERVER['REMOTE_USER']) {
         return;
     }
     // get linkback meta file name
     $file = metaFN($ID, '.linkbacks');
     $data = array('send' => false, 'receive' => false, 'display' => false, 'sentpings' => array(), 'receivedpings' => array(), 'number' => 0);
     if (@file_exists($file)) {
         $data = unserialize(io_readFile($file, false));
     }
     $data['send'] = $_REQUEST['plugin__linkback_toggle'] ? true : false;
     if (!$data['send']) {
         return;
     }
     $meta = p_get_metadata($ID);
     // prepare linkback info
     $linkback_info = array();
     $linkback_info['title'] = tpl_pagetitle($ID, true);
     $linkback_info['url'] = wl($ID, '', true);
     $linkback_info['blog_name'] = $conf['title'];
     $linkback_info['excerpt'] = $meta['description']['abstract'];
     // get links
     $ilist = p_cached_instructions(wikiFN($ID), false, $ID);
     if (!is_array($ilist)) {
         return;
     }
     $pages = $this->_parse_instructionlist($ilist);
     $sentpings = array();
     foreach ($pages as $page) {
         if (!$data['sentpings'][$page]) {
             // try to ping pages not already pinged
             $this->_ping_page($page, $linkback_info);
         }
         $sentpings[$page] = true;
     }
     $data['sentpings'] = $sentpings;
     // save sent ping info
     io_saveFile($file, serialize($data));
     return true;
 }
Example #13
0
 /**
  * determine the max allowable age of the cache
  *
  * @param   string    $id wiki page name
  *
  * @return  int max allowable age of the cache null means not applicable
  */
 function _cache_maxage($id)
 {
     $hasPart = p_get_metadata($id, 'relation haspart');
     if (empty($hasPart) || !is_array($hasPart)) {
         return null;
     }
     $age = 0;
     foreach ($hasPart as $file => $data) {
         if ($file == "_plugin_twitter") {
             //this is us, outdate the cache if older than the configured seconds
             return $this->getConf('timeout');
         }
     }
     return $age ? time() - $age : null;
 }
Example #14
0
 /**
  * Optionally add a CSS class for the first tag
  *
  * @author Michael Klier <*****@*****.**>
  */
 function _get_firsttag($page) {
     if(plugin_isdisabled('tag') || (!$taghelper =& plugin_load('helper', 'tag'))) {
         return false;
     }
     $subject = p_get_metadata($page, 'subject');
     if (is_array($subject)) {
         $tag = $subject[0];
     } else {
         list($tag, $rest) = explode(' ', $subject, 2);
     }
     if($tag) {
         return $tag;
     } else {
         return false;
     }
 }
Example #15
0
 /**
  * Check for pages changes and eventually purge cache.
  *
  * @author Samuele Tognini <*****@*****.**>
  *
  * @param Doku_Event $event
  * @param mixed      $param not defined
  */
 function _purgecache(&$event, $param)
 {
     global $ID;
     global $conf;
     /** @var cache_parser $cache */
     $cache =& $event->data;
     if (!isset($cache->page)) {
         return;
     }
     //purge only xhtml cache
     if ($cache->mode != "xhtml") {
         return;
     }
     //Check if it is an pagequery page
     if (!p_get_metadata($ID, 'pagequery')) {
         return;
     }
     $aclcache = $this->getConf('aclcache');
     if ($conf['useacl']) {
         $newkey = false;
         if ($aclcache == 'user') {
             //Cache per user
             if ($_SERVER['REMOTE_USER']) {
                 $newkey = $_SERVER['REMOTE_USER'];
             }
         } else {
             if ($aclcache == 'groups') {
                 //Cache per groups
                 global $INFO;
                 if ($INFO['userinfo']['grps']) {
                     $newkey = implode('#', $INFO['userinfo']['grps']);
                 }
             }
         }
         if ($newkey) {
             $cache->key .= "#" . $newkey;
             $cache->cache = getCacheName($cache->key, $cache->ext);
         }
     }
     //Check if a page is more recent than purgefile.
     if (@filemtime($cache->cache) < @filemtime($conf['cachedir'] . '/purgefile')) {
         $event->preventDefault();
         $event->stopPropagation();
         $event->result = false;
     }
 }
Example #16
0
 function handle_cache_prepare(&$event, $param)
 {
     global $conf, $ID;
     $cache =& $event->data;
     // only the ODT rendering mode needs caching tweaks
     if ($cache->mode != "odt") {
         return;
     }
     $odt_meta = p_get_metadata($ID, 'relation odt');
     $template_name = $odt_meta["template"];
     if (!$template_name) {
         return;
     }
     $template_path = $conf['mediadir'] . '/' . $this->getConf("tpl_dir") . "/" . $template_name;
     if (file_exists($template_path)) {
         $cache->depends['files'][] = $template_path;
     }
 }
Example #17
0
 function render($mode, Doku_Renderer $renderer, $data)
 {
     global $ID;
     preg_match('/^\\!\\[(' . $this->nested_brackets_re . ')\\][ ]?(?:\\n[ ]*)?\\[(.*?)\\]$/', $data[1], $matches);
     $title = $matches[1];
     if ($matches[2] == '') {
         $rid = $matches[1];
     } else {
         $rid = $matches[2];
     }
     $rid = preg_replace("/ /", ".", $rid);
     $target = p_get_metadata($ID, 'markdowku_references_' . $rid, METADATA_RENDER_USING_CACHE);
     if ($target == '') {
         $renderer->cdata($data[1]);
     } else {
         $renderer->_media($target, $title);
     }
     return true;
 }
Example #18
0
 function ditaa_sendfile(&$event, $args)
 {
     global $conf;
     if (empty($_REQUEST['ditaa'])) {
         return;
     }
     $plugin = plugin_load('syntax', 'ditaa');
     $data = p_get_metadata($event->data['media'], 'ditaa');
     $event->data['file'] = $plugin->_imgfile($event->data['media'], $data[$_REQUEST['ditaa']]);
     $event->data['mime'] = 'image/png';
     if (!$event->data['file']) {
         $event->data['file'] = dirname(__FILE__) . '/broken.png';
         $event->data['status'] = 404;
         $event->data['statusmessage'] = 'Not Found';
     }
     header('Expires: ' . gmdate("D, d M Y H:i:s", time() + max($conf['cachetime'], 3600)) . ' GMT');
     header('Cache-Control: public, proxy-revalidate, no-transform, max-age=' . max($conf['cachetime'], 3600));
     header('Pragma: public');
 }
Example #19
0
	function handle_pageredirect_redirect(&$event, $param) {
		global $ID, $ACT, $REV;

		if (($ACT == 'show' || $ACT == '') && empty($REV)) {
			$page = p_get_metadata($ID,'relation isreplacedby');

			// return if no redirection data
			if (empty($page)) { return; }

			if (isset($_GET['redirect'])) {
				// return if redirection is temporarily disabled,
				// or we have been redirected 5 times in a row
				if ($_GET['redirect'] == 'no' || $_GET['redirect'] > 4) { return; }
				elseif ($_GET['redirect'] > 0) { $redirect = $_GET['redirect'] +1; }
				else { $redirect = 1; }
			} else {
				$redirect = 1;
			}

			// verify metadata currency
			if (@filemtime(metaFN($ID,'.meta')) < @filemtime(wikiFN($ID))) { return; }

			if (!headers_sent() && $this->getConf('show_note')) {
				// remember to show note about being redirected from another page
				session_start();
				$_SESSION[DOKU_COOKIE]['redirect'] = $ID;
			}

			// preserve #section from $page
			list($page, $section) = explode('#', $page, 2);
			if (isset($section)) {
				$section = '#' . $section;
			} else {
				$section = '';
			}

			// redirect
			header("HTTP/1.1 301 Moved Permanently");
			header("Location: ".wl($page, Array('redirect' => $redirect), TRUE, '&'). $section);
			exit();
		}
	}
 /**
  * For pages containing an aggregation, add the last modified date of the database itself
  * to the cache dependencies
  *
  * @param Doku_Event $event event object by reference
  * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
  *                           handler was registered]
  * @return bool
  */
 public function handle_cache_aggregation(Doku_Event $event, $param)
 {
     global $INPUT;
     /** @var \cache_parser $cache */
     $cache = $event->data;
     if ($cache->mode != 'xhtml') {
         return true;
     }
     if (!$cache->page) {
         return true;
     }
     // not a page cache
     $meta = p_get_metadata($cache->page, 'plugin struct');
     if (isset($meta['hasaggregation'])) {
         /** @var helper_plugin_struct_db $db */
         $db = plugin_load('helper', 'struct_db');
         // cache depends on last database save
         $cache->depends['files'][] = $db->getDB()->getAdapter()->getDbFile();
         // dynamic renders should never overwrite the default page cache
         // we need this in additon to handle_cache_dynamic() below because we can only
         // influence if a cache is used, not that it will be written
         if ($INPUT->has(SearchConfigParameters::$PARAM_FILTER) || $INPUT->has(SearchConfigParameters::$PARAM_OFFSET) || $INPUT->has(SearchConfigParameters::$PARAM_SORT)) {
             $cache->key .= 'dynamic';
         }
         // cache depends on today's date
         if ($meta['hasaggregation'] & SearchConfig::$CACHE_DATE) {
             $oldage = $cache->depends['age'];
             $newage = time() - mktime(0, 0, 1);
             // time since first second today
             $cache->depends['age'] = min($oldage, $newage);
         }
         // cache depends on current user
         if ($meta['hasaggregation'] & SearchConfig::$CACHE_USER) {
             $cache->key .= ';' . $INPUT->server->str('REMOTE_USER');
         }
         // rebuild cachename
         $cache->cache = getCacheName($cache->key, $cache->ext);
     }
     return true;
 }
Example #21
0
 /**
  * called when(after) writing a new page to disk.
  * publishing is triggered from here.
  * see http://www.dokuwiki.org/devel:events_list#io_wikipage_write
  */
 function handle_wikipage_write(&$event, $param)
 {
     global $ID;
     if (!$this->getConf('enable publishing')) {
         return;
     }
     // if an old revision is safed -> run away
     if ($event->data[3]) {
         return true;
     }
     $ns = $event->data[1];
     $name = $event->data[2];
     #$path=$event->data[0][0];
     if (empty($event->data[0][1])) {
         //page has been deleted
     }
     if ($ID != $ns . (!empty($ns) ? ':' : '') . $name) {
         msg('rpcpub: not publishing wiki-page other than current page ID="' . $ID . '" <> file="' . $ns . ':' . $name . '"');
         $this->_debug('rpcpub: not publishing wiki-page other than current page ID="' . $ID . '" <> file="' . $ns . ':' . $name . '"');
         # Note: this prevents publish loops, the XML-RPC does not set $ID.
         return true;
     }
     # check if anonymous users can READ this before publishing.
     #if(auth_quickaclcheck($ID) < AUTH_EDIT || auth_aclcheck($ID, '', array()) < AUTH_READ){
     #    return true;
     #}
     if (isHiddenPage($ID)) {
         return true;
     }
     $meta = p_get_metadata($ID);
     # skip '~~DRAFT~~' - requires the blog plugin.
     if ($meta['type'] == 'draft') {
         return true;
     }
     # TODO: check for other meta-data, namespace-blacklist, etc.
     # TODO: prevent publish loops.
     $this->_wikiRpcPublish($ID);
     return true;
 }
 function handle_pageredirect_redirect(&$event, $param)
 {
     global $ID, $ACT, $REV;
     if (($ACT == 'show' || $ACT == '') && empty($REV)) {
         $page = p_get_metadata($ID, 'relation isreplacedby');
         // return if no redirection data
         if (empty($page)) {
             return;
         }
         if (isset($_GET['redirect'])) {
             // return if redirection is temporarily disabled,
             // or we have been redirected 5 times in a row
             if ($_GET['redirect'] == 'no' || $_GET['redirect'] > 4) {
                 return;
             } elseif ($_GET['redirect'] > 0) {
                 $redirect = $_GET['redirect'] + 1;
             } else {
                 $redirect = 1;
             }
         } else {
             $redirect = 1;
         }
         // verify metadata currency
         if (@filemtime(metaFN($ID, '.meta')) < @filemtime(wikiFN($ID))) {
             return;
         }
         if (!headers_sent() && $this->getConf('show_note')) {
             // remember to show note about being redirected from another page
             session_start();
             if (!isset($_SESSION[DOKU_COOKIE]['redirect']) || $redirect == 1) {
                 $_SESSION[DOKU_COOKIE]['redirect'] = $ID;
             }
         }
         // redirect
         resolve_pageid(getNS($ID), $page, $exists);
         header("Location: " . wl($page, array('redirect' => $redirect), TRUE, '&'));
         exit;
     }
 }
Example #23
0
 /**
  * Arguments:
  *  - cmd
  *  - label
  *  - ++ (optional)
  *
  * @param array $args The tokenized definition, only split at spaces
  */
 public function __construct($args)
 {
     $pp = array_search('++', $args, true);
     if ($pp !== false) {
         unset($args[$pp]);
         $this->autoinc = true;
     }
     parent::__construct($args);
     if ($this->autoinc) {
         global $ID;
         $key = $this->get_key();
         $c_val = p_get_metadata($ID, 'bureaucracy ' . $key);
         if (is_null($c_val)) {
             if (!isset($this->opt['value'])) {
                 $this->opt['value'] = 0;
             }
             p_set_metadata($ID, array('bureaucracy' => array($key => $this->opt['value'])));
         } else {
             $this->opt['value'] = $c_val;
         }
     }
 }
 public function setUp()
 {
     parent::setUp();
     $this->loadSchemaJSON('schema1');
     $this->loadSchemaJSON('schema2');
     $as = new mock\Assignments();
     $page = 'page01';
     $as->assignPageSchema($page, 'schema1');
     $as->assignPageSchema($page, 'schema2');
     saveWikiText($page, "===== TestTitle =====\nabc", "Summary");
     p_get_metadata($page);
     $this->saveData($page, 'schema1', array('first' => 'first data', 'second' => array('second data', 'more data', 'even more'), 'third' => 'third data', 'fourth' => 'fourth data'));
     $this->saveData($page, 'schema2', array('afirst' => 'first data', 'asecond' => array('second data', 'more data', 'even more'), 'athird' => 'third data', 'afourth' => 'fourth data'));
     $as->assignPageSchema('test:document', 'schema1');
     $as->assignPageSchema('test:document', 'schema2');
     $this->saveData('test:document', 'schema1', array('first' => 'document first data', 'second' => array('second', 'more'), 'third' => '', 'fourth' => 'fourth data'));
     $this->saveData('test:document', 'schema2', array('afirst' => 'first data', 'asecond' => array('second data', 'more data', 'even more'), 'athird' => 'third data', 'afourth' => 'fourth data'));
     for ($i = 10; $i <= 20; $i++) {
         $this->saveData("page{$i}", 'schema2', array('afirst' => "page{$i} first data", 'asecond' => array("page{$i} second data"), 'athird' => "page{$i} third data", 'afourth' => "page{$i} fourth data"));
         $as->assignPageSchema("page{$i}", 'schema2');
     }
 }
Example #25
0
 function __construct()
 {
     global $ID;
     $data = p_get_metadata($ID, 'schulzevote');
     $this->prefer = $data['prefer'];
     $this->candys = $data['candys'];
     $this->votees = $data['votees'];
     /* Ambiguous, but B > C and D > A
             $this->prefer = array(
     'A' => array('A' => 0, 'B' => 5, 'C' => 5, 'D' => 3),
     'B' => array('A' => 4, 'B' => 0, 'C' => 7, 'D' => 5),
     'C' => array('A' => 4, 'B' => 2, 'C' => 0, 'D' => 5),
     'D' => array('A' => 6, 'B' => 4, 'C' => 4, 'D' => 0),
     );
             $this->candys = array(
     'A' => 'A',
     'B' => 'B',
     'C' => 'C',
     'D' => 'D',
     );
     */
     /* E > A > C > B > D
             $this->prefer = array(
     'A' => array('A' => 0, 'B' => 20, 'C' => 26, 'D' => 30, 'E' => 22),
     'B' => array('A' => 25, 'B' => 0, 'C' => 16, 'D' => 33, 'E' => 18),
     'C' => array('A' => 19, 'B' => 29, 'C' => 0, 'D' => 17, 'E' => 24),
     'D' => array('A' => 15, 'B' => 12, 'C' => 28, 'D' => 0, 'E' => 14),
     'E' => array('A' => 23, 'B' => 27, 'C' => 21, 'D' => 31, 'E' => 0),
     );
             $this->candys = array(
     'A' => 'A',
     'B' => 'B',
     'C' => 'C',
     'D' => 'D',
     'E' => 'E',
     );
     */
 }
Example #26
0
 /**
  * Removes draft entries from feeds
  *
  * @author Michael Klier <*****@*****.**>
  */
 function handle_feed_item(&$event, $param)
 {
     global $conf;
     $url = parse_url($event->data['item']->link);
     $base_url = getBaseURL();
     // determine page id by rewrite mode
     switch ($conf['userewrite']) {
         case 0:
             preg_match('#id=([^&]*)#', $url['query'], $match);
             if ($base_url != '/') {
                 $id = cleanID(str_replace($base_url, '', $match[1]));
             } else {
                 $id = cleanID($match[1]);
             }
             break;
         case 1:
             if ($base_url != '/') {
                 $id = cleanID(str_replace('/', ':', str_replace($base_url, '', $url['path'])));
             } else {
                 $id = cleanID(str_replace('/', ':', $url['path']));
             }
             break;
         case 2:
             preg_match('#doku.php/([^&]*)#', $url['path'], $match);
             if ($base_url != '/') {
                 $id = cleanID(str_replace($base_url, '', $match[1]));
             } else {
                 $id = cleanID($match[1]);
             }
             break;
     }
     // don't add drafts to the feed
     if (p_get_metadata($id, 'type') == 'draft') {
         $event->preventDefault();
         return;
     }
 }
 function render($mode, &$renderer, $data)
 {
     global $ID;
     preg_match('/^\\[(' . $this->nested_brackets_re . ')\\][ ]?(?:\\n[ ]*)?\\[(.*?)\\]$/', $data[1], $matches);
     $title = $matches[1];
     if ($matches[2] == '') {
         $rid = $matches[1];
     } else {
         $rid = $matches[2];
     }
     $rid = preg_replace("/ /", ".", $rid);
     $target = p_get_metadata($ID, 'markdowku_references_' . $rid, METADATA_RENDER_USING_CACHE);
     if ($target == '') {
         $renderer->cdata($data[1]);
     } else {
         if (preg_match('/^mailto:/', $target) or preg_match('<' . PREG_PATTERN_VALID_EMAIL . '>', $target)) {
             $target = preg_replace('/^mailto:/', '', $target);
             $renderer->emaillink($target, $title);
         } else {
             $renderer->externallink($target, $title);
         }
     }
     return true;
 }
Example #28
0
 /**
  * [Custom event handler which performs action]
  *
  * @param Doku_Event $event  event object by reference
  * @param mixed      $param  [the parameters passed as fifth argument to register_hook() when this
  *                           handler was registered]
  * @return void
  */
 public function handle_parser_cache_use(Doku_Event &$event, $param)
 {
     $pageCache =& $event->data;
     //dbglog("ghissues: In handle_parser_cache_use");
     // We only do anything if it is rendering xhtml
     if (!isset($pageCache->page)) {
         return;
     }
     if (!isset($pageCache->mode) || $pageCache->mode != 'xhtml') {
         return;
     }
     $apiRequests = p_get_metadata($pageCache->page, 'plugin_ghissues_apicalls');
     if (!is_array($apiRequests)) {
         return;
     }
     // No ghissues api calls
     $loadFromCache = $this->loadHelper('ghissues_apiCacheInterface');
     //dbglog('ghissues: handleParser '.var_export($apiRequests, TRUE));
     foreach ($apiRequests as $apiURL => $apiHash) {
         $pageCache->depends['files'][] = $loadFromCache->checkIssuesCache($apiURL);
         //dbglog('ghissues: '.$loadFromCache->checkIssuesCache($apiURL));
     }
     return;
 }
/**
 * Adds/updates the search index for the given page
 *
 * Locking is handled internally.
 *
 * @param string        $page   name of the page to index
 * @param boolean       $verbose    print status messages
 * @param boolean       $force  force reindexing even when the index is up to date
 * @return boolean              the function completed successfully
 * @author Tom N Harris <*****@*****.**>
 */
function enhanced_idx_addPage($page, $verbose = false, $force = false)
{
    $idxtag = metaFN($page, '.indexed');
    // check if page was deleted but is still in the index
    if (!page_exists($page)) {
        if (!@file_exists($idxtag)) {
            if ($verbose) {
                print "Indexer: {$page} does not exist, ignoring" . DOKU_LF;
            }
            return false;
        }
        $Indexer = enhanced_idx_get_indexer();
        $result = $Indexer->deletePage($page);
        if ($result === "locked") {
            if ($verbose) {
                print "Indexer: locked" . DOKU_LF;
            }
            return false;
        }
        @unlink($idxtag);
        return $result;
    }
    // check if indexing needed
    if (!$force && @file_exists($idxtag)) {
        if (trim(io_readFile($idxtag)) == idx_get_version()) {
            $last = @filemtime($idxtag);
            if ($last > @filemtime(wikiFN($page))) {
                if ($verbose) {
                    print "Indexer: index for {$page} up to date" . DOKU_LF;
                }
                return false;
            }
        }
    }
    $indexenabled = p_get_metadata($page, 'internal index', METADATA_RENDER_UNLIMITED);
    if ($indexenabled === false) {
        $result = false;
        if (@file_exists($idxtag)) {
            $Indexer = enhanced_idx_get_indexer();
            $result = $Indexer->deletePage($page);
            if ($result === "locked") {
                if ($verbose) {
                    print "Indexer: locked" . DOKU_LF;
                }
                return false;
            }
            @unlink($idxtag);
        }
        if ($verbose) {
            print "Indexer: index disabled for {$page}" . DOKU_LF;
        }
        return $result;
    }
    $Indexer = enhanced_idx_get_indexer();
    $pid = $Indexer->getPID($page);
    if ($pid === false) {
        if ($verbose) {
            print "Indexer: getting the PID failed for {$page}" . DOKU_LF;
        }
        return false;
    }
    $body = '';
    $metadata = array();
    $metadata['title'] = p_get_metadata($page, 'title', METADATA_RENDER_UNLIMITED);
    if (($references = p_get_metadata($page, 'relation references', METADATA_RENDER_UNLIMITED)) !== null) {
        $metadata['relation_references'] = array_keys($references);
    } else {
        $metadata['relation_references'] = array();
    }
    if (($media = p_get_metadata($page, 'relation media', METADATA_RENDER_UNLIMITED)) !== null) {
        $metadata['relation_media'] = array_keys($media);
    } else {
        $metadata['relation_media'] = array();
    }
    $data = compact('page', 'body', 'metadata', 'pid');
    $evt = new Doku_Event('INDEXER_PAGE_ADD', $data);
    if ($evt->advise_before()) {
        $data['body'] = $data['body'] . " " . rawWiki($page);
    }
    $evt->advise_after();
    unset($evt);
    extract($data);
    $result = $Indexer->addPageWords($page, $body);
    if ($result === "locked") {
        if ($verbose) {
            print "Indexer: locked" . DOKU_LF;
        }
        return false;
    }
    if ($result) {
        $result = $Indexer->addMetaKeys($page, $metadata);
        if ($result === "locked") {
            if ($verbose) {
                print "Indexer: locked" . DOKU_LF;
            }
            return false;
        }
    }
    if ($result) {
        io_saveFile(metaFN($page, '.indexed'), idx_get_version());
    }
    if ($verbose) {
        print "Indexer: finished" . DOKU_LF;
        return true;
    }
    return $result;
}
Example #30
0
    /**
     * Gives a list of pages for a given include statement
     *
     * @author Michael Hamann <*****@*****.**>
     */
    function _get_included_pages($mode, $page, $sect, $parent_id, $flags) {
        global $conf;
        $pages = array();
        switch($mode) {
        case 'namespace':
            $page  = cleanID($page);
            $ns    = utf8_encodeFN(str_replace(':', '/', $page));
            // depth is absolute depth, not relative depth, but 0 has a special meaning.
            $depth = $flags['depth'] ? $flags['depth'] + substr_count($page, ':') + ($page ? 1 : 0) : 0;
            search($pagearrays, $conf['datadir'], 'search_allpages', array('depth' => $depth), $ns);
            if (is_array($pagearrays)) {
                foreach ($pagearrays as $pagearray) {
                    if (!isHiddenPage($pagearray['id'])) // skip hidden pages
                        $pages[] = $pagearray['id'];
                }
            }
            break;
        case 'tagtopic':
            if (!$this->taghelper)
                $this->taghelper =& plugin_load('helper', 'tag');
            if(!$this->taghelper) {
                msg('You have to install the tag plugin to use this functionality!', -1);
                return array();
            }
            $tag   = $page;
            $sect  = '';
            $pagearrays = $this->taghelper->getTopic('', null, $tag);
            foreach ($pagearrays as $pagearray) {
                $pages[] = $pagearray['id'];
            }
            break;
        default:
            $page = $this->_apply_macro($page);
            resolve_pageid(getNS($parent_id), $page, $exists); // resolve shortcuts and clean ID
            if (auth_quickaclcheck($page) >= AUTH_READ)
                $pages[] = $page;
        }

        if (count($pages) > 1) {
            if ($flags['order'] === 'id') {
                if ($flags['rsort']) {
                    usort($pages, array($this, '_r_strnatcasecmp'));
                } else {
                    natcasesort($pages);
                }
            } else {
                $ordered_pages = array();
                foreach ($pages as $page) {
                    $key = '';
                    switch ($flags['order']) {
                        case 'title':
                            $key = p_get_first_heading($page);
                            break;
                        case 'created':
                            $key = p_get_metadata($page, 'date created', METADATA_DONT_RENDER);
                            break;
                        case 'modified':
                            $key = p_get_metadata($page, 'date modified', METADATA_DONT_RENDER);
                            break;
                        case 'indexmenu':
                            $key = p_get_metadata($page, 'indexmenu_n', METADATA_RENDER_USING_SIMPLE_CACHE);
                            if ($key === null)
                                $key = '';
                            break;
                        case 'custom':
                            $key = p_get_metadata($page, 'include_n', METADATA_RENDER_USING_SIMPLE_CACHE);
                            if ($key === null)
                                $key = '';
                            break;
                    }
                    $key .= '_'.$page;
                    $ordered_pages[$key] = $page;
                }
                if ($flags['rsort']) {
                    uksort($ordered_pages, array($this, '_r_strnatcasecmp'));
                } else {
                    uksort($ordered_pages, 'strnatcasecmp');
                }
                $pages = $ordered_pages;
            }
        }

        $result = array();
        foreach ($pages as $page) {
            $exists = page_exists($page);
            $result[] = array('id' => $page, 'exists' => $exists, 'parent_id' => $parent_id);
        }
        return $result;
    }