function get_first_heading($page) { $heading = p_get_first_heading($page); if (!isset($heading)) { $heading = $page; } return $heading; }
private function buildTitle($idMainPage, $defaultTitle) { if (!is_null($idMainPage)) { $title = p_get_first_heading($idMainPage, true); if (!is_null($title) && $this->useTitle) { return $title; } } return $defaultTitle; }
/** * get the Title for the page **/ public function getSiteTitle($ID) { if (useHeading('content') && $ID) { $heading = p_get_first_heading($ID, true); if ($heading) { return $this->xmlEntities($heading); } } return ucwords($this->xmlEntities(array_pop(explode(':', $ID)))); }
function indexmenu_search_index(&$data, $base, $file, $type, $lvl, $opts) { global $conf; $ret = true; $item = array(); if ($type == 'f' && !preg_match('#\\.txt$#', $file)) { // don't add return false; } // get page id by filename $id = pathID($file); // check hiddens if ($type == 'f' && isHiddenPage($id)) { return false; } // bugfix for the // /ns/ // /<ns>.txt // case, need to force the 'directory' type if ($type == 'f' && file_exists(dirname(wikiFN($id . ":" . noNS($id))))) { $type = 'd'; } // page target id = global id $target = $id; if ($type == 'd') { // this will check 3 kinds of headpage: // 1. /<ns>/<ns>.txt // 2. /<ns>/ // /<ns>.txt // 3. /<ns>/ // /<ns>/<start_page> $nsa = array($id . ":" . noNS($id), $id, $id . ":" . $conf['start']); $nspage = false; foreach ($nsa as $nsp) { if (@file_exists(wikiFN($nsp)) && auth_quickaclcheck($nsp) >= AUTH_READ) { $nspage = $nsp; break; } } //headpage exists if ($nspage) { $target = $nspage; } else { // open namespace index, if headpage does not exists $target = $target . ':'; } } $data[] = array('id' => $id, 'date' => @filectime(wikiFN($target)), 'type' => $type, 'target' => $target, 'title' => $conf['useheading'] && ($title = p_get_first_heading($target)) ? $title : $id, 'level' => $lvl); if (substr_count($id, ":") > 2) { $ret = 0; } return $ret; }
private function tagToName($t) { $exists = false; $id = $t; resolve_pageID($this->tagplugin->namespace, $id, $exists); $name = p_get_first_heading($id, false); if (empty($name)) { $name = $t; } else { $name = $name; } return $name; }
public function CreateDefault() { global $ID; $data = array(); $data['FB']['url'] = wl($ID, null, true); $data['FB']['title'] = p_get_first_heading($ID); $text = ""; $data['FB']['description'] = $text; $data['FB']['site_name'] = "FYKOS"; //var_dump(p_get_metadata($ID,'relation')); $data['FB']['image'] = ml($this->getConf('default_image'), array('w' => 600, 'h' => 600), true, '&', true); $data['FB']['type'] = "website"; $data['FB']['locale'] = 'cs_CZ'; return $data; }
/** * Searches for matching pagenames * * @author Andreas Gohr <*****@*****.**> */ function ajax_qsearch() { global $lang; global $INPUT; $maxnumbersuggestions = 50; $query = $INPUT->post->str('q'); if (empty($query)) { $query = $INPUT->get->str('q'); } if (empty($query)) { return; } $query = urldecode($query); $data = ft_pageLookup($query, true, useHeading('navigation')); if (!count($data)) { return; } print '<strong>' . $lang['quickhits'] . '</strong>'; print '<ul>'; $counter = 0; foreach ($data as $id => $title) { if (useHeading('navigation')) { $name = $title; } else { $ns = getNS($id); if ($ns) { /* Displays the Header of the Namespace-Page or of namespace:start as the Name of the NS */ $ns_name = p_get_first_heading(getNS($id)); if (!$ns_name) { $ns_name = p_get_first_heading(getNS($id) . ':start'); } $name = shorten(' [' . $ns_name . ']', 30); } else { $name = $id; } } echo '<li>' . html_wikilink(':' . $id, $name) . '</li>'; $counter++; if ($counter > $maxnumbersuggestions) { echo '<li>...</li>'; break; } } print '</ul>'; }
/** * This is a very universal callback for the search() function, replacing * many of the former individual functions at the cost of a more complex * setup. * * How the function behaves, depends on the options passed in the $opts * array, where the following settings can be used. * * depth int recursion depth. 0 for unlimited * keeptxt bool keep .txt extension for IDs * listfiles bool include files in listing * listdirs bool include namespaces in listing * pagesonly bool restrict files to pages * skipacl bool do not check for READ permission * sneakyacl bool don't recurse into nonreadable dirs * hash bool create MD5 hash for files * meta bool return file metadata * filematch string match files against this regexp * idmatch string match full ID against this regexp * dirmatch string match directory against this regexp when adding * nsmatch string match namespace against this regexp when adding * recmatch string match directory against this regexp when recursing * showmsg bool warn about non-ID files * showhidden bool show hidden files too * firsthead bool return first heading for pages * * @author Andreas Gohr <*****@*****.**> */ function search_universal(&$data, $base, $file, $type, $lvl, $opts) { $item = array(); $return = true; // get ID and check if it is a valid one $item['id'] = pathID($file); if ($item['id'] != cleanID($item['id'])) { if ($opts['showmsg']) { msg(hsc($item['id']) . ' is not a valid file name for DokuWiki - skipped', -1); } return false; // skip non-valid files } $item['ns'] = getNS($item['id']); if ($type == 'd') { // decide if to recursion into this directory is wanted if (!$opts['depth']) { $return = true; // recurse forever } else { $depth = substr_count($file, '/'); if ($depth >= $opts['depth']) { $return = false; // depth reached } else { $return = true; } } if ($return && !preg_match('/' . $opts['recmatch'] . '/', $file)) { $return = false; // doesn't match } } // check ACL if (!$opts['skipacl']) { if ($type == 'd') { $item['perm'] = auth_quickaclcheck($item['id'] . ':*'); } else { $item['perm'] = auth_quickaclcheck($item['id']); //FIXME check namespace for media files } } else { $item['perm'] = AUTH_DELETE; } // are we done here maybe? if ($type == 'd') { if (!$opts['listdirs']) { return $return; } if (!$opts['skipacl'] && $opts['sneakyacl'] && $item['perm'] < AUTH_READ) { return false; } //neither list nor recurse if ($opts['dirmatch'] && !preg_match('/' . $opts['dirmatch'] . '/', $file)) { return $return; } if ($opts['nsmatch'] && !preg_match('/' . $opts['nsmatch'] . '/', $item['ns'])) { return $return; } } else { if (!$opts['listfiles']) { return $return; } if (!$opts['skipacl'] && $item['perm'] < AUTH_READ) { return $return; } if ($opts['pagesonly'] && substr($file, -4) != '.txt') { return $return; } if (!$conf['showhidden'] && isHiddenPage($id)) { return $return; } if ($opts['filematch'] && !preg_match('/' . $opts['filematch'] . '/', $file)) { return $return; } if ($opts['idmatch'] && !preg_match('/' . $opts['idmatch'] . '/', $item['id'])) { return $return; } } // still here? prepare the item $item['type'] = $type; $item['level'] = $lvl; $item['open'] = $return; if ($opts['meta']) { $item['file'] = basename($file); $item['size'] = filesize($base . '/' . $file); $item['mtime'] = filemtime($base . '/' . $file); $item['rev'] = $item['mtime']; $item['writable'] = is_writable($base . '/' . $file); $item['executable'] = is_executable($base . '/' . $file); } if ($type == 'f') { if ($opts['hash']) { $item['hash'] = md5(io_readFile($base . '/' . $file, false)); } if ($opts['firsthead']) { $item['title'] = p_get_first_heading($item['id'], false); } } // finally add the item $data[] = $item; return $return; }
/** * Construct a title and handle images in titles * * @author Harry Fuecks <*****@*****.**> * @param string|array $title either string title or media array * @param string $default default title if nothing else is found * @param bool $isImage will be set to true if it's a media file * @param null|string $id linked page id (used to extract title from first heading) * @param string $linktype content|navigation * @return string HTML of the title, might be full image tag or just escaped text */ function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') { $isImage = false; if (is_array($title)) { $isImage = true; return $this->_imageTitle($title); } elseif (is_null($title) || trim($title) == '') { if (useHeading($linktype) && $id) { $heading = p_get_first_heading($id); if ($heading) { return $this->_xmlEntities($heading); } } return $this->_xmlEntities($default); } else { return $this->_xmlEntities($title); } }
/** * Adds all pages of a specific namespace to the pages array. * * @param pages pre-initialised pages array. * @param ns Namespace in which to look for pages. * @param depth Search depth. * @param use_first_header (optional) Includes the first header as page title. */ function get_pages(&$pages, $ns, $depth = 0, $use_first_header = false) { global $conf; // find pages $search_results = array(); search($search_results, $conf['datadir'], 'search_universal', array('depth' => $depth, 'listfiles' => true, 'listdirs' => false, 'pagesonly' => true, 'skipacl' => true, 'firsthead' => true, 'meta' => true), str_replace(':', '/', $ns)); // Start page of the namespace if ($ns && page_exists($ns)) { // Add to the search results $search_results[] = array('id' => $ns, 'ns' => getNS($ns), 'title' => p_get_first_heading($ns, false), 'size' => filesize(wikiFN($ns)), 'mtime' => filemtime(wikiFN($ns)), 'perm' => 16, 'type' => 'f', 'level' => 0, 'open' => 1); } // loop through the pages while ($item = array_shift($search_results)) { // Check that the user is allowed to read the page if (auth_quickaclcheck($item['id']) > AUTH_READ) { continue; } // Check that the user is allowed to read the page if (auth_quickaclcheck($item['ns']) > AUTH_READ) { continue; } // Get the create time $time = (int) p_get_metadata($item['id'], 'date created', false); if (!$time) { $time = $item['mtime']; } // Get specific language part $lang = $transplugin ? $transplugin->getLangPart($item['id']) : ''; if ($lang) { $item['ns'] = preg_replace('/^' . $lang . '(:|$)/', '', $item['ns']); } if ($use_first_header) { $title = $item['title']; } else { // Use the last part of the id for the name $title = ucwords(substr(strrchr(strtr($item['id'], '_', ' '), ':'), 1)); } // Add the page to the page list $pages[$item['id']] = array('title' => $title, 'ns' => $item['ns'], 'size' => $item['size'], 'time' => $time, 'links' => array(), 'media' => array(), 'lang' => $lang); } }
/** * Adds/updates the search for the given page * * This is the core function of the indexer which does most * of the work. This function needs to be called with proper * locking! * * @author Andreas Gohr <*****@*****.**> */ function idx_addPage($page) { global $conf; // load known documents $page_idx = idx_getIndex('page', ''); // get page id (this is the linenumber in page.idx) $pid = array_search("{$page}\n", $page_idx); if (!is_int($pid)) { $pid = count($page_idx); // page was new - write back if (!idx_appendIndex('page', '', "{$page}\n")) { trigger_error("Failed to write page index", E_USER_ERROR); return false; } } unset($page_idx); // free memory idx_saveIndexLine('title', '', $pid, p_get_first_heading($page, false)); $pagewords = array(); // get word usage in page $words = idx_getPageWords($page); if ($words === false) { return false; } if (!empty($words)) { foreach (array_keys($words) as $wlen) { $index = idx_getIndex('i', $wlen); foreach ($words[$wlen] as $wid => $freq) { if ($wid < count($index)) { $index[$wid] = idx_updateIndexLine($index[$wid], $pid, $freq); } else { // New words **should** have been added in increasing order // starting with the first unassigned index. // If someone can show how this isn't true, then I'll need to sort // or do something special. $index[$wid] = idx_updateIndexLine('', $pid, $freq); } $pagewords[] = "{$wlen}*{$wid}"; } // save back word index if (!idx_saveIndex('i', $wlen, $index)) { trigger_error("Failed to write index", E_USER_ERROR); return false; } } } // Remove obsolete index entries $pageword_idx = trim(idx_getIndexLine('pageword', '', $pid)); if ($pageword_idx !== '') { $oldwords = explode(':', $pageword_idx); $delwords = array_diff($oldwords, $pagewords); $upwords = array(); foreach ($delwords as $word) { if ($word == '') { continue; } list($wlen, $wid) = explode('*', $word); $wid = (int) $wid; $upwords[$wlen][] = $wid; } foreach ($upwords as $wlen => $widx) { $index = idx_getIndex('i', $wlen); foreach ($widx as $wid) { $index[$wid] = idx_updateIndexLine($index[$wid], $pid, 0); } idx_saveIndex('i', $wlen, $index); } } // Save the reverse index $pageword_idx = join(':', $pagewords) . "\n"; if (!idx_saveIndexLine('pageword', '', $pid, $pageword_idx)) { trigger_error("Failed to write word index", E_USER_ERROR); return false; } return true; }
/** * Returns the name of the given page (current one if none given). * * If useheading is enabled this will use the first headline else * the given ID is printed. * * based on tpl_pagetitle in inc/template.php */ function tpl_pagename($id = null) { global $conf; if (is_null($id)) { global $ID; $id = $ID; } $name = $id; if ($conf['useheading']) { $title = p_get_first_heading($id); if ($title) { $name = $title; } } return hsc($name); }
/** * List all pages in the given namespace (and below) */ function search($query) { $regex = ''; $data = ft_pageSearch($query, $regex); $pages = array(); // prepare additional data $idx = 0; foreach ($data as $id => $score) { $file = wikiFN($id); if ($idx < FT_SNIPPET_NUMBER) { $snippet = ft_snippet($id, $regex); $idx++; } else { $snippet = ''; } $pages[] = array('id' => $id, 'score' => intval($score), 'rev' => filemtime($file), 'mtime' => filemtime($file), 'size' => filesize($file), 'snippet' => $snippet, 'title' => useHeading('navigation') ? p_get_first_heading($id) : $id); } return $pages; }
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) */ // must be run from within DokuWiki if (!defined('DOKU_INC')) { die; } if (($ACT == 'show' || defined('DOKU_MEDIADETAIL')) && bootstrap3_conf('showPageIcons')) { global $ID; $page_icons = bootstrap3_conf('pageIcons'); $social_share = in_array('social-share', $page_icons); $social_share_providers = bootstrap3_conf('socialShareProviders'); $help_page = false; $help_title = null; if (in_array('help', $page_icons)) { $help_page = page_findnearest('help', bootstrap3_conf('useACL')); $help_title = hsc(p_get_first_heading($help_page)); } ?> <div class="dw-page-icons pull-right hidden-print"> <ul class="list-inline pull-right"> <?php if (in_array('feed', $page_icons)) { ?> <li> <a href="<?php echo DOKU_URL . 'feed.php'; ?> " title="<?php echo $lang['btn_recent']; ?>
/** * Build the browsable index of pages * * $opts['ns'] is the current namespace * * @author Andreas Gohr <*****@*****.**> * modified by Samuele Tognini <*****@*****.**> */ function _search_index(&$data, $base, $file, $type, $lvl, $opts) { global $conf; $hns = false; $return = false; $isopen = false; $skip_index = $opts['skip_index']; $skip_file = $opts['skip_file']; $headpage = $opts['headpage']; $id = pathID($file); if ($type == 'd') { // Skip folders in plugin conf if (!empty($skip_index) && preg_match($skip_index, $id)) { return false; } //check ACL (for sneaky_index namespaces too). if ($this->getConf('sneaky_index') && auth_quickaclcheck($id . ':') < AUTH_READ) { return false; } //Open requested level if ($opts['level'] > $lvl || $opts['level'] == -1) { $isopen = true; } //Search optional namespaces if (!empty($opts['nss'])) { $nss = $opts['nss']; for ($a = 0; $a < count($nss); $a++) { if (preg_match("/^" . $id . "(\$|:.+)/i", $nss[$a][0], $match)) { //It contains an optional namespace $isopen = true; } elseif (preg_match("/^" . $nss[$a][0] . "(:.*)/i", $id, $match)) { //It's inside an optional namespace if ($nss[$a][1] == -1 || substr_count($match[1], ":") < $nss[$a][1]) { $isopen = true; } else { $isopen = false; } } } } if ($opts['nons']) { return $isopen; } elseif ($opts['max'] > 0 && !$isopen && $lvl >= $opts['max']) { $isopen = false; //Stop recursive searching $return = false; //change type $type = "l"; } elseif ($opts['js']) { $return = true; } else { $return = $isopen; } //Set title and headpage $title = $this->_getTitle($id, $headpage, $hns); if (!$hns && $opts['nopg']) { $hns = $id . ":" . $conf['start']; } } else { //Nopg.Dont show pages if ($opts['nopg']) { return false; } $return = true; //Nons.Set all pages at first level if ($opts['nons']) { $lvl = 1; } //don't add if (substr($file, -4) != '.txt') { return false; } //check hiddens and acl if (isHiddenPage($id) || auth_quickaclcheck($id) < AUTH_READ) { return false; } //Skip files in plugin conf if (!empty($skip_file) && preg_match($skip_file, $id)) { return false; } //Skip headpages to hide if (!$opts['nons'] && !empty($headpage) && $opts['hide_headpage']) { if ($id == $conf['start']) { return false; } $ahp = explode(",", $headpage); foreach ($ahp as $hp) { switch ($hp) { case ":inside:": if (noNS($id) == noNS(getNS($id))) { return false; } break; case ":same:": if (@is_dir(dirname(wikiFN($id)) . "/" . utf8_encodeFN(noNS($id)))) { return false; } break; //it' s an inside start //it' s an inside start case ":start:": if (noNS($id) == $conf['start']) { return false; } break; default: if (noNS($id) == cleanID($hp)) { return false; } } } } //Set title if (!$conf['useheading'] || !($title = p_get_first_heading($id, FALSE))) { $title = noNS($id); } $title = htmlspecialchars($title, ENT_QUOTES); } $item = array('id' => $id, 'type' => $type, 'level' => $lvl, 'open' => $isopen, 'title' => $title, 'hns' => $hns, 'file' => $file, 'return' => $return); $item['sort'] = $this->_setorder($item); $data[] = $item; return $return; }
/** * Prints or returns the name of the given page (current one if none given). * * If useheading is enabled this will use the first headline else * the given ID is used. * * @author Andreas Gohr <*****@*****.**> * * @param string $id page id * @param bool $ret return content instead of printing * @return bool|string */ function tpl_pagetitle($id = null, $ret = false) { global $ACT, $INPUT, $conf, $lang; if (is_null($id)) { global $ID; $id = $ID; } $name = $id; if (useHeading('navigation')) { $first_heading = p_get_first_heading($id); if ($first_heading) { $name = $first_heading; } } // default page title is the page name, modify with the current action switch ($ACT) { // admin functions case 'admin': $page_title = $lang['btn_admin']; // try to get the plugin name /** @var $plugin DokuWiki_Admin_Plugin */ if ($plugin = plugin_getRequestAdminPlugin()) { $plugin_title = $plugin->getMenuText($conf['lang']); $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName(); } break; // user functions // user functions case 'login': case 'profile': case 'register': case 'resendpwd': $page_title = $lang['btn_' . $ACT]; break; // wiki functions // wiki functions case 'search': case 'index': $page_title = $lang['btn_' . $ACT]; break; // page functions // page functions case 'edit': $page_title = "✎ " . $name; break; case 'revisions': $page_title = $name . ' - ' . $lang['btn_revs']; break; case 'backlink': case 'recent': case 'subscribe': $page_title = $name . ' - ' . $lang['btn_' . $ACT]; break; default: // SHOW and anything else not included $page_title = $name; } if ($ret) { return hsc($page_title); } else { print hsc($page_title); return true; } }
/** * This builds the breadcrumb trail and returns it as array * * @author Andreas Gohr <*****@*****.**> */ function breadcrumbs() { // we prepare the breadcrumbs early for quick session closing static $crumbs = null; if ($crumbs != null) { return $crumbs; } global $ID; global $ACT; global $conf; //first visit? $crumbs = isset($_SESSION[DOKU_COOKIE]['bc']) ? $_SESSION[DOKU_COOKIE]['bc'] : array(); //we only save on show and existing wiki documents $file = wikiFN($ID); if ($ACT != 'show' || !@file_exists($file)) { $_SESSION[DOKU_COOKIE]['bc'] = $crumbs; return $crumbs; } // page names $name = noNSorNS($ID); if (useHeading('navigation')) { // get page title $title = p_get_first_heading($ID, METADATA_RENDER_USING_SIMPLE_CACHE); if ($title) { $name = $title; } } //remove ID from array if (isset($crumbs[$ID])) { unset($crumbs[$ID]); } //add to array $crumbs[$ID] = $name; //reduce size while (count($crumbs) > $conf['breadcrumbs']) { array_shift($crumbs); } //save to session $_SESSION[DOKU_COOKIE]['bc'] = $crumbs; return $crumbs; }
/** * Construct a title and handle images in titles * * @author Harry Fuecks <*****@*****.**> */ function _getLinkTitle($title, $default, &$isImage, $id = NULL) { global $conf; $isImage = FALSE; if (is_null($title)) { if ($conf['useheading'] && $id) { $heading = p_get_first_heading($id); if ($heading) { return $this->_xmlEntities($heading); } } return $this->_xmlEntities($default); } else { if (is_string($title)) { return $this->_xmlEntities($title); } else { if (is_array($title)) { $isImage = TRUE; return $this->_imageTitle($title); } } } }
/** * list old revisions * * @author Andreas Gohr <*****@*****.**> * @author Ben Coburn <*****@*****.**> * @author Kate Arzamastseva <*****@*****.**> * * @param int $first skip the first n changelog lines * @param bool|string $media_id id of media, or false for current page */ function html_revisions($first = 0, $media_id = false) { global $ID; global $INFO; global $conf; global $lang; $id = $ID; if ($media_id) { $id = $media_id; $changelog = new MediaChangeLog($id); } else { $changelog = new PageChangeLog($id); } /* we need to get one additional log entry to be able to * decide if this is the last page or is there another one. * see html_recent() */ $revisions = $changelog->getRevisions($first, $conf['recent'] + 1); if (count($revisions) == 0 && $first != 0) { $first = 0; $revisions = $changelog->getRevisions($first, $conf['recent'] + 1); } $hasNext = false; if (count($revisions) > $conf['recent']) { $hasNext = true; array_pop($revisions); // remove extra log entry } if (!$media_id) { $date = dformat($INFO['lastmod']); } else { $date = dformat(@filemtime(mediaFN($id))); } if (!$media_id) { print p_locale_xhtml('revisions'); } $params = array('id' => 'page__revisions', 'class' => 'changes'); if ($media_id) { $params['action'] = media_managerURL(array('image' => $media_id), '&'); } $form = new Doku_Form($params); $form->addElement(form_makeOpenTag('ul')); if (!$media_id) { $exists = $INFO['exists']; } else { $exists = file_exists(mediaFN($id)); } $display_name = !$media_id && useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id; if (!$display_name) { $display_name = $id; } if ($exists && $first == 0) { if (!$media_id && isset($INFO['meta']) && isset($INFO['meta']['last_change']) && $INFO['meta']['last_change']['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); } else { $form->addElement(form_makeOpenTag('li')); } $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); $form->addElement(form_makeTag('input', array('type' => 'checkbox', 'name' => 'rev2[]', 'value' => 'current'))); $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); $form->addElement($date); $form->addElement(form_makeCloseTag('span')); $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />'); if (!$media_id) { $href = wl($id); } else { $href = media_managerURL(array('image' => $id, 'tab_details' => 'view'), '&'); } $form->addElement(form_makeOpenTag('a', array('class' => 'wikilink1', 'href' => $href))); $form->addElement($display_name); $form->addElement(form_makeCloseTag('a')); if ($media_id) { $form->addElement(form_makeOpenTag('div')); } if (!$media_id) { $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); $form->addElement(' – '); $form->addElement(htmlspecialchars($INFO['sum'])); $form->addElement(form_makeCloseTag('span')); } $changelog->setChunkSize(1024); $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); if ($media_id) { $revinfo = $changelog->getRevisionInfo(@filemtime(fullpath(mediaFN($id)))); if ($revinfo['user']) { $editor = $revinfo['user']; } else { $editor = $revinfo['ip']; } } else { $editor = $INFO['editor']; } $form->addElement(empty($editor) ? '(' . $lang['external_edit'] . ')' : editorinfo($editor)); $form->addElement(form_makeCloseTag('span')); $form->addElement('(' . $lang['current'] . ')'); if ($media_id) { $form->addElement(form_makeCloseTag('div')); } $form->addElement(form_makeCloseTag('div')); $form->addElement(form_makeCloseTag('li')); } foreach ($revisions as $rev) { $date = dformat($rev); $info = $changelog->getRevisionInfo($rev); if ($media_id) { $exists = file_exists(mediaFN($id, $rev)); } else { $exists = page_exists($id, $rev); } if ($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) { $form->addElement(form_makeOpenTag('li', array('class' => 'minor'))); } else { $form->addElement(form_makeOpenTag('li')); } $form->addElement(form_makeOpenTag('div', array('class' => 'li'))); if ($exists) { $form->addElement(form_makeTag('input', array('type' => 'checkbox', 'name' => 'rev2[]', 'value' => $rev))); } else { $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />'); } $form->addElement(form_makeOpenTag('span', array('class' => 'date'))); $form->addElement($date); $form->addElement(form_makeCloseTag('span')); if ($exists) { if (!$media_id) { $href = wl($id, "rev={$rev},do=diff", false, '&'); } else { $href = media_managerURL(array('image' => $id, 'rev' => $rev, 'mediado' => 'diff'), '&'); } $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'diff_link'))); $form->addElement(form_makeTag('img', array('src' => DOKU_BASE . 'lib/images/diff.png', 'width' => 15, 'height' => 11, 'title' => $lang['diff'], 'alt' => $lang['diff']))); $form->addElement(form_makeCloseTag('a')); if (!$media_id) { $href = wl($id, "rev={$rev}", false, '&'); } else { $href = media_managerURL(array('image' => $id, 'tab_details' => 'view', 'rev' => $rev), '&'); } $form->addElement(form_makeOpenTag('a', array('href' => $href, 'class' => 'wikilink1'))); $form->addElement($display_name); $form->addElement(form_makeCloseTag('a')); } else { $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />'); $form->addElement($display_name); } if ($media_id) { $form->addElement(form_makeOpenTag('div')); } if ($info['sum']) { $form->addElement(form_makeOpenTag('span', array('class' => 'sum'))); if (!$media_id) { $form->addElement(' – '); } $form->addElement('<bdi>' . htmlspecialchars($info['sum']) . '</bdi>'); $form->addElement(form_makeCloseTag('span')); } $form->addElement(form_makeOpenTag('span', array('class' => 'user'))); if ($info['user']) { $form->addElement('<bdi>' . editorinfo($info['user']) . '</bdi>'); if (auth_ismanager()) { $form->addElement(' <bdo dir="ltr">(' . $info['ip'] . ')</bdo>'); } } else { $form->addElement('<bdo dir="ltr">' . $info['ip'] . '</bdo>'); } $form->addElement(form_makeCloseTag('span')); if ($media_id) { $form->addElement(form_makeCloseTag('div')); } $form->addElement(form_makeCloseTag('div')); $form->addElement(form_makeCloseTag('li')); } $form->addElement(form_makeCloseTag('ul')); if (!$media_id) { $form->addElement(form_makeButton('submit', 'diff', $lang['diff2'])); } else { $form->addHidden('mediado', 'diff'); $form->addElement(form_makeButton('submit', '', $lang['diff2'])); } html_form('revisions', $form); print '<div class="pagenav">'; $last = $first + $conf['recent']; if ($first > 0) { $first -= $conf['recent']; if ($first < 0) { $first = 0; } print '<div class="pagenav-prev">'; if ($media_id) { print html_btn('newer', $media_id, "p", media_managerURL(array('first' => $first), '&', false, true)); } else { print html_btn('newer', $id, "p", array('do' => 'revisions', 'first' => $first)); } print '</div>'; } if ($hasNext) { print '<div class="pagenav-next">'; if ($media_id) { print html_btn('older', $media_id, "n", media_managerURL(array('first' => $last), '&', false, true)); } else { print html_btn('older', $id, "n", array('do' => 'revisions', 'first' => $last)); } print '</div>'; } print '</div>'; }
/** * Construct a title and handle images in titles * * @author Harry Fuecks <*****@*****.**> */ public function _getLinkTitle($title, $default, $id = NULL) { global $conf; $isImage = false; if (is_null($title)) { if ($conf['useheading'] && $id) { $heading = p_get_first_heading($id, false); if ($heading) { return $heading; } } return $default; } elseif (is_string($title)) { return $title; } elseif (is_array($title)) { return '[' . $title . ']'; } }
function render($mode, &$renderer, $data) { global $conf; list($type, $num, $namespaces) = $data; if ($mode == 'xhtml') { if ($type == 'tag') { // we need the tag helper plugin if (plugin_isdisabled('tag') || !($tag = plugin_load('helper', 'tag'))) { msg('The Tag Plugin must be installed to display tag clouds.', -1); return false; } $cloud = $this->_getTagCloud($num, $min, $max, $namespaces, $tag); } elseif ($type == 'search') { $helper = plugin_load('helper', 'searchstats'); if ($helper) { $cloud = $helper->getSearchWordArray($num); // calculate min/max values $min = PHP_INT_MAX; $max = 0; foreach ($cloud as $size) { $min = min($size, $min); $max = max($size, $max); } } else { msg('You have to install the searchstats plugin to use this feature.', -1); return false; } } else { $cloud = $this->_getWordCloud($num, $min, $max); } if (!is_array($cloud) || empty($cloud)) { return false; } $delta = ($max - $min) / 16; // prevent caching to ensure the included pages are always fresh $renderer->info['cache'] = false; // and render the cloud $renderer->doc .= '<div class="cloud">' . DOKU_LF; foreach ($cloud as $word => $size) { if ($size < $min + round($delta)) { $class = 'cloud1'; } elseif ($size < $min + round(2 * $delta)) { $class = 'cloud2'; } elseif ($size < $min + round(4 * $delta)) { $class = 'cloud3'; } elseif ($size < $min + round(8 * $delta)) { $class = 'cloud4'; } else { $class = 'cloud5'; } $name = $word; if ($type == 'tag') { $id = $word; $exists = false; resolve_pageID($tag->namespace, $id, $exists); if ($exists) { $link = wl($id); if ($conf['useheading']) { $name = p_get_first_heading($id, false); } else { $name = $word; } } else { $link = wl($id, array('do' => 'showtag', 'tag' => $word)); } $title = $word; $class .= $exists ? '_tag1' : '_tag2'; } else { if ($conf['userewrite'] == 2) { $link = wl($word, array('do' => 'search', 'id' => $word)); $title = $size; } else { $link = wl($word, 'do=search'); $title = $size; } } $renderer->doc .= DOKU_TAB . '<a href="' . $link . '" class="' . $class . '"' . ' title="' . $title . '">' . hsc($name) . '</a>' . DOKU_LF; } $renderer->doc .= '</div>' . DOKU_LF; return true; } return false; }
function _recurse(&$renderer, $data, $dir, $ns, $excluPages, $excluNS, $depth = -1) { if ($depth == 0) { return; } $depth--; $mainPageId = $ns . ':'; $mainPageExists; resolve_pageid('', $mainPageId, $mainPageExists); if (!$mainPageExists) { $mainPageId = NULL; } global $conf; $path = $conf['savedir'] . '/pages/' . $dir; $handle = @opendir($path); if (!$handle) { msg(sprintf($this->getLang('dontexist'), $ns), 0); return; } while (($item = readdir($handle)) !== false) { if ($item[0] == '.' || $item[0] == '_') { continue; } $name = str_replace('.txt', '', $item); $id = $ns . ':' . $name; $infos = array('id' => $id, 'name' => $name); if (is_dir($path . '/' . $item)) { if ($excluNS) { continue; } $startid = $id . ':'; $startexist = false; resolve_pageid('', $startid, $startexist); $infos['title'] = $startexist ? p_get_first_heading($startid, true) : $name; if ($this->_isExcluded($infos, $data['exclutype'], $data['excluns'])) { continue; } $perms = auth_quickaclcheck($id . ':*'); $this->_displayNSBegin($renderer, $infos, $data['displayType'], ($startexist || $data['forceLinks']) && $perms >= AUTH_READ, $data['nsInBold'], $data['expand']); if (!$this->_isExcluded($infos, $data['exclutype'], $data['exclunsall']) && $perms >= AUTH_READ) { $exclunspages = $this->_isExcluded($infos, $data['exclutype'], $data['exclunspages']); $exclunsns = $this->_isExcluded($infos, $data['exclutype'], $data['exclunsns']); $this->_recurse($renderer, $data, $dir . '/' . $item, $ns . ':' . $item, $exclunspages, $exclunsns, $depth); } $this->_displayNSEnd($renderer, $data['displayType'], $data['createPageButtonEach'] && $perms >= AUTH_CREATE ? $id . ':' : NULL); } else { if (!$excluPages) { if (auth_quickaclcheck($id) < AUTH_READ) { continue; } $infos['title'] = p_get_first_heading($id, true); if (is_null($infos['title'])) { $infos['title'] = $name; } if ($this->_isExcluded($infos, $data['exclutype'], $data['exclupage'])) { continue; } if ($id != $mainPageId) { $this->_displayPage($renderer, $infos, $data['displayType']); } } } } closedir($handle); }
/** * Prints or returns the name of the given page (current one if none given). * * If useheading is enabled this will use the first headline else * the given ID is used. * * @author Andreas Gohr <*****@*****.**> * @param string $id page id * @param bool $ret return content instead of printing * @return bool|string */ function tpl_pagetitle($id = null, $ret = false) { if (is_null($id)) { global $ID; $id = $ID; } $name = $id; if (useHeading('navigation')) { $title = p_get_first_heading($id); if ($title) { $name = $title; } } if ($ret) { return hsc($name); } else { print hsc($name); return true; } }
/** * Obtain list of pages and title, based on url parameters * * @param Doku_Event $event * @return string|bool */ protected function collectExportPages(Doku_Event $event) { global $ACT; global $ID; global $INPUT; global $conf; // list of one or multiple pages $list = array(); if ($ACT == 'export_odt') { $list[0] = $ID; $title = $INPUT->str('book_title'); if (!$title) { $title = p_get_first_heading($ID); } } elseif ($ACT == 'export_odtns') { //check input for title and ns if (!($title = $INPUT->str('book_title'))) { $this->showPageWithErrorMsg($event, 'needtitle'); return false; } $docnamespace = cleanID($INPUT->str('book_ns')); if (!@is_dir(dirname(wikiFN($docnamespace . ':dummy')))) { $this->showPageWithErrorMsg($event, 'needns'); return false; } //sort order $order = $INPUT->str('book_order', 'natural', true); $sortoptions = array('pagename', 'date', 'natural'); if (!in_array($order, $sortoptions)) { $order = 'natural'; } //search depth $depth = $INPUT->int('book_nsdepth', 0); if ($depth < 0) { $depth = 0; } //page search $result = array(); $opts = array('depth' => $depth); //recursive all levels $dir = utf8_encodeFN(str_replace(':', '/', $docnamespace)); search($result, $conf['datadir'], 'search_allpages', $opts, $dir); //sorting if (count($result) > 0) { if ($order == 'date') { usort($result, array($this, '_datesort')); } elseif ($order == 'pagename') { usort($result, array($this, '_pagenamesort')); } } foreach ($result as $item) { $list[] = $item['id']; } } elseif (isset($_COOKIE['list-pagelist']) && !empty($_COOKIE['list-pagelist'])) { // Here is $ACT == 'export_odtbook' //is in Bookmanager of bookcreator plugin a title given? if (!($title = $INPUT->str('book_title'))) { $this->showPageWithErrorMsg($event, 'needtitle'); return false; } else { $list = explode("|", $_COOKIE['list-pagelist']); } } else { //show empty bookcreator message $this->showPageWithErrorMsg($event, 'empty'); return false; } $list = array_map('cleanID', $list); return array($title, $list); }
/** * Returns the link for one given tag * * @param string $tag the tag the link shall point to * @param string $title the title of the link (optional) * @param bool $dynamic if the link class shall be changed if no pages with the specified tag exist * @return string The HTML code of the link */ function tagLink($tag, $title = '', $dynamic = false) { global $conf; $svtag = $tag; $tag_title = str_replace('_', ' ', noNS($tag)); resolve_pageid($this->namespace, $tag, $exists); // resolve shortcuts if ($exists) { $class = 'wikilink1'; $url = wl($tag); if ($conf['useheading']) { // important: set sendond param to false to prevent recursion! $heading = p_get_first_heading($tag, false); if ($heading) { $tag_title = $heading; } } } else { if ($dynamic) { $pages = $this->getTopic('', 1, $svtag); if (empty($pages)) { $class = 'wikilink2'; } else { $class = 'wikilink1'; } } else { $class = 'wikilink1'; } $url = wl($tag, array('do' => 'showtag', 'tag' => $svtag)); } if (!$title) { $title = $tag_title; } $link = '<a href="' . $url . '" class="' . $class . '" title="' . hsc($tag) . '" rel="tag">' . hsc($title) . '</a>'; return $link; }
function orph_report_table($data, $page_exists, $has_links, $params_array) { global $conf; $show_heading = $page_exists && $conf['useheading']; //take off $params_array[0]; $exclude_array = array_slice($params_array, 1); $count = 1; $output = ''; // for valid html - need to close the <p> that is feed before this $output .= '</p>'; $output .= '<table class="inline"><tr><th> # </th><th> ID </th>' . ($show_heading ? '<th>Title</th>' : '') . '<th>Links</th></tr>' . "\n"; arsort($data); foreach ($data as $id => $item) { if ($item["exists"] == $page_exists and ($item["links"] != 0) == $has_links) { // $id is a string, looks like this: page, namespace:page, or namespace:<subspaces>:page $match_array = explode(":", $id); //remove last item in array, the page identifier $match_array = array_slice($match_array, 0, -1); //put it back together $page_namespace = implode(":", $match_array); //add a trailing : $page_namespace = $page_namespace . ':'; //set it to show, unless blocked by exclusion list $show_it = true; foreach ($exclude_array as $exclude_item) { //add a trailing : to each $item too $exclude_item = $exclude_item . ":"; // need === to avoid boolean false // strpos(haystack, needle) // if exclusion is beginning of page's namespace , block it if (strpos($page_namespace, $exclude_item) === 0) { //there is a match, so block it $show_it = false; } } if ($show_it) { $output .= "<tr><td>{$count}</td><td><a href=\"" . wl($id) . "\" class=\"" . ($page_exists ? "wikilink1" : "wikilink2") . "\" onclick=\"return svchk()\" onkeypress=\"return svchk()\">" . $id . "</a></td>" . ($show_heading ? "<td>" . hsc(p_get_first_heading($id)) . "</td>" : "") . "<td>" . $item["links"] . ($has_links ? " : <a href=\"" . wl($id, 'do=backlink') . "\" class=\"wikilink1\">Show backlinks</a>" : "") . "</td></tr>\n"; $count++; } } } //close the html table $output .= "</table>\n"; //for valid html = need to reopen a <p> $output .= '<p>'; return $output; }
/** * 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; }
/** * Construct a title and handle images in titles * * @author Harry Fuecks <*****@*****.**> */ function _getLinkTitle($title, $default, $id = NULL) { global $conf; $isImage = false; if (is_null($title)) { if (useHeading('content') && $id) { $heading = p_get_first_heading($id, false); if ($heading) { return $heading; } } return $default; } else { if (is_string($title)) { return $title; } else { if (is_array($title)) { return '[' . $title['title'] . ']'; } } } }
function _ft_pageLookup(&$data) { // split out original parameters $id = $data['id']; if (preg_match('/(?:^| )@(\\w+)/', $id, $matches)) { $ns = cleanID($matches[1]) . ':'; $id = str_replace($matches[0], '', $id); } $in_ns = $data['in_ns']; $in_title = $data['in_title']; $cleaned = cleanID($id); $Indexer = idx_get_indexer(); $page_idx = $Indexer->getPages(); $pages = array(); if ($id !== '' && $cleaned !== '') { foreach ($page_idx as $p_id) { if (strpos($in_ns ? $p_id : noNSorNS($p_id), $cleaned) !== false) { if (!isset($pages[$p_id])) { $pages[$p_id] = p_get_first_heading($p_id, METADATA_DONT_RENDER); } } } if ($in_title) { foreach ($Indexer->lookupKey('title', $id, '_ft_pageLookupTitleCompare') as $p_id) { if (!isset($pages[$p_id])) { $pages[$p_id] = p_get_first_heading($p_id, METADATA_DONT_RENDER); } } } } if (isset($ns)) { foreach (array_keys($pages) as $p_id) { if (strpos($p_id, $ns) !== 0) { unset($pages[$p_id]); } } } // discard hidden pages // discard nonexistent pages // check ACL permissions foreach (array_keys($pages) as $idx) { if (!isVisiblePage($idx) || !page_exists($idx) || auth_quickaclcheck($idx) < AUTH_READ) { unset($pages[$idx]); } } uksort($pages, 'ft_pagesorter'); return $pages; }
function getTitle() { global $ID; return p_get_first_heading($ID); }