Пример #1
0
/**
 * Convenience function to quickly build a wikilink
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function html_wikilink($id, $name = null, $search = '')
{
    static $xhtml_renderer = null;
    if (is_null($xhtml_renderer)) {
        $xhtml_renderer = p_get_renderer('xhtml');
    }
    return $xhtml_renderer->internallink($id, $name, $search, true, 'navigation');
}
 function test_p_get_renderer_fallback_fail()
 {
     global $conf;
     $old_conf = $conf;
     $conf['renderer_junk'] = 'badvalue';
     $this->assertNull(p_get_renderer('junk'));
     $conf = $old_conf;
 }
Пример #3
0
/**
 * Renders a list of instruction to the specified output mode
 *
 * In the $info array is information from the renderer returned
 *
 * @author Harry Fuecks <*****@*****.**>
 * @author Andreas Gohr <*****@*****.**>
 */
function p_render($mode, $instructions, &$info)
{
    if (is_null($instructions)) {
        return '';
    }
    $Renderer =& p_get_renderer($mode);
    if (is_null($Renderer)) {
        return null;
    }
    $Renderer->reset();
    $Renderer->smileys = getSmileys();
    $Renderer->entities = getEntities();
    $Renderer->acronyms = getAcronyms();
    $Renderer->interwiki = getInterwiki();
    // Loop through the instructions
    foreach ($instructions as $instruction) {
        // Execute the callback against the Renderer
        call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]);
    }
    //set info array
    $info = $Renderer->info;
    // Post process and return the output
    $data = array($mode, &$Renderer->doc);
    trigger_event('RENDERER_CONTENT_POSTPROCESS', $data);
    return $Renderer->doc;
}
Пример #4
0
 function plugin($name, $data)
 {
     if ($name != 'mathpublish' && $name != 'ditaa') {
         return parent::plugin($name, $data);
     }
     $mode = 'xhtml';
     $renderer = p_get_renderer($mode);
     $plugin =& plugin_load('syntax', $name);
     if ($plugin != null) {
         $plugin->render($mode, $renderer, $data);
         if ($name == 'ditaa') {
             epub_check_for_ditaa($renderer->doc, $this);
         } else {
             if ($name == 'mathpublish') {
                 epub_check_for_math($renderer->doc, $this);
             }
         }
         $this->doc .= $renderer->doc;
     }
 }
Пример #5
0
/**
 * Returns users realname w/o link
 *
 * @param string|null $username or null when currently logged-in user should be used
 * @param bool $textonly true returns only plain text, true allows returning html
 * @return string html or plain text(not escaped) of formatted user name
 *
 * @triggers COMMON_USER_LINK
 */
function userlink($username = null, $textonly = false)
{
    global $conf, $INFO;
    /** @var DokuWiki_Auth_Plugin $auth */
    global $auth;
    /** @var Input $INPUT */
    global $INPUT;
    // prepare initial event data
    $data = array('username' => $username, 'name' => '', 'link' => array('target' => '', 'pre' => '', 'suf' => '', 'style' => '', 'more' => '', 'url' => '', 'title' => '', 'class' => ''), 'userlink' => '', 'textonly' => $textonly);
    if ($username === null) {
        $data['username'] = $username = $INPUT->server->str('REMOTE_USER');
        if ($textonly) {
            $data['name'] = $INFO['userinfo']['name'] . ' (' . $INPUT->server->str('REMOTE_USER') . ')';
        } else {
            $data['name'] = '<bdi>' . hsc($INFO['userinfo']['name']) . '</bdi> (<bdi>' . hsc($INPUT->server->str('REMOTE_USER')) . '</bdi>)';
        }
    }
    $evt = new Doku_Event('COMMON_USER_LINK', $data);
    if ($evt->advise_before(true)) {
        if (empty($data['name'])) {
            if ($auth) {
                $info = $auth->getUserData($username);
            }
            if ($conf['showuseras'] != 'loginname' && isset($info) && $info) {
                switch ($conf['showuseras']) {
                    case 'username':
                    case 'username_link':
                        $data['name'] = $textonly ? $info['name'] : hsc($info['name']);
                        break;
                    case 'email':
                    case 'email_link':
                        $data['name'] = obfuscate($info['mail']);
                        break;
                }
            } else {
                $data['name'] = $textonly ? $data['username'] : hsc($data['username']);
            }
        }
        /** @var Doku_Renderer_xhtml $xhtml_renderer */
        static $xhtml_renderer = null;
        if (!$data['textonly'] && empty($data['link']['url'])) {
            if (in_array($conf['showuseras'], array('email_link', 'username_link'))) {
                if (!isset($info)) {
                    if ($auth) {
                        $info = $auth->getUserData($username);
                    }
                }
                if (isset($info) && $info) {
                    if ($conf['showuseras'] == 'email_link') {
                        $data['link']['url'] = 'mailto:' . obfuscate($info['mail']);
                    } else {
                        if (is_null($xhtml_renderer)) {
                            $xhtml_renderer = p_get_renderer('xhtml');
                        }
                        if (empty($xhtml_renderer->interwiki)) {
                            $xhtml_renderer->interwiki = getInterwiki();
                        }
                        $shortcut = 'user';
                        $exists = null;
                        $data['link']['url'] = $xhtml_renderer->_resolveInterWiki($shortcut, $username, $exists);
                        $data['link']['class'] .= ' interwiki iw_user';
                        if ($exists !== null) {
                            if ($exists) {
                                $data['link']['class'] .= ' wikilink1';
                            } else {
                                $data['link']['class'] .= ' wikilink2';
                                $data['link']['rel'] = 'nofollow';
                            }
                        }
                    }
                } else {
                    $data['textonly'] = true;
                }
            } else {
                $data['textonly'] = true;
            }
        }
        if ($data['textonly']) {
            $data['userlink'] = $data['name'];
        } else {
            $data['link']['name'] = $data['name'];
            if (is_null($xhtml_renderer)) {
                $xhtml_renderer = p_get_renderer('xhtml');
            }
            $data['userlink'] = $xhtml_renderer->_formatLink($data['link']);
        }
    }
    $evt->advise_after();
    unset($evt);
    return $data['userlink'];
}
function render_navigation($menuid)
{
    $id = cleanID($menuid);
    // fetch the instructions of the control page
    $instructions = p_cached_instructions(wikiFN($id), false, $id);
    // prepare some vars
    $max = count($instructions);
    $pre = true;
    $lvl = 0;
    $parents = array();
    $page = '';
    $cnt = 0;
    // build a lookup table
    for ($i = 0; $i < $max; $i++) {
        if ($instructions[$i][0] == 'listu_open') {
            $pre = false;
            $lvl++;
            if ($page) {
                array_push($parents, $page);
            }
        } elseif ($instructions[$i][0] == 'listu_close') {
            $lvl--;
            array_pop($parents);
        } elseif ($pre || $lvl == 0) {
            unset($instructions[$i]);
        } elseif ($instructions[$i][0] == 'listitem_close') {
            $cnt++;
        } elseif ($instructions[$i][0] == 'internallink') {
            $page = cleanID($instructions[$i][1][0]);
            $list[$page] = array('parents' => $parents, 'page' => cleanID($instructions[$i][1][0]), 'title' => $instructions[$i][1][1], 'lvl' => $lvl);
        }
    }
    $data = array(wikiFN($id), $list, $opt);
    global $INFO;
    global $ID;
    $fn = $data[0];
    $opt = $data[2];
    $data = $data[1];
    $R =& p_get_renderer('xhtml');
    $R->info['cache'] = false;
    // no cache please
    $parent = array();
    if (isset($data[$INFO['id']])) {
        $parent = (array) $data[$INFO['id']]['parents'];
        // get the "path" of the page we're on currently
        array_push($parent, $INFO['id']);
        $current = $INFO['id'];
    } elseif ($opt == 'ns') {
        $ns = $INFO['id'];
        // traverse up for matching namespaces
        do {
            $ns = getNS($ns);
            $try = "{$ns}:";
            resolve_pageid('', $try, $foo);
            if (isset($data[$try])) {
                // got a start page
                $parent = (array) $data[$try]['parents'];
                array_push($parent, $try);
                $current = $try;
                break;
            } else {
                // search for the first page matching the namespace
                foreach ($data as $key => $junk) {
                    if (getNS($key) == $ns) {
                        $parent = (array) $data[$key]['parents'];
                        array_push($parent, $key);
                        $current = $key;
                        break 2;
                    }
                }
            }
        } while ($ns);
    }
    // we need the top ID for the renderer
    $oldid = $ID;
    $ID = $INFO['id'];
    // create a correctly nested list (or so I hope)
    $open = false;
    $lvl = 1;
    $R->listu_open();
    foreach ((array) $data as $pid => $info) {
        // only show if we are in the "path"
        if (array_diff($info['parents'], $parent)) {
            continue;
        }
        // skip every non readable page
        if (auth_quickaclcheck(cleanID($info['page'])) < AUTH_READ) {
            continue;
        }
        if ($info['lvl'] == $lvl) {
            if ($open) {
                $R->listitem_close();
            }
            $R->listitem_open($lvl);
            $open = true;
        } elseif ($lvl > $info['lvl']) {
            for ($lvl; $lvl > $info['lvl']; $lvl--) {
                $R->listitem_close();
                $R->listu_close();
            }
            $R->listitem_close();
            $R->listitem_open($lvl);
        } elseif ($lvl < $info['lvl']) {
            // more than one run is bad nesting!
            for ($lvl; $lvl < $info['lvl']; $lvl++) {
                $R->listu_open();
                $R->listitem_open($lvl);
                $open = true;
            }
        }
        $format = 'xhtml';
        $R->listcontent_open();
        if ($format == 'xhtml' && ($info['page'] == $current || in_array($info['page'], $parent))) {
            $R->doc .= '<span class="current">';
        }
        $R->internallink($info['page'], $info['title']);
        if ($format == 'xhtml' && ($info['page'] == $current || in_array($info['page'], $parent))) {
            $R->doc .= '</span>';
        }
        $R->listcontent_close();
    }
    while ($lvl > 0) {
        $R->listitem_close();
        $R->listu_close();
        $lvl--;
    }
    $ID = $oldid;
    print $R->doc;
    return true;
}
Пример #7
0
 function render($mode, &$renderer, $data)
 {
     list($ns, $num, $flags, $refine) = $data;
     $first = $_REQUEST['first'];
     if (!is_numeric($first)) {
         $first = 0;
     }
     // get the blog entries for our namespace
     if ($my =& plugin_load('helper', 'blog')) {
         $entries = $my->getBlog($ns);
     }
     // use tag refinements?
     if ($refine) {
         if (plugin_isdisabled('tag') || !($tag =& plugin_load('helper', 'tag'))) {
             msg($this->getLang('missing_tagplugin'), -1);
         } else {
             $entries = $tag->tagRefine($entries, $refine);
         }
     }
     // any create form overrides?
     $formpos = $this->getConf('formposition');
     if (in_array('topform', $flags)) {
         $formpos = 'top';
     } elseif (in_array('bottomform', $flags)) {
         $formpos = 'bottom';
     } elseif (in_array('noform', $flags)) {
         $formpos = 'none';
     }
     if (!$entries) {
         if (auth_quickaclcheck($ns . ':*') >= AUTH_CREATE && $mode == 'xhtml') {
             $renderer->info['cache'] = false;
             if ($formpos != 'none') {
                 $renderer->doc .= $this->_newEntryForm($ns);
             }
         }
         return true;
         // nothing to display
     }
     // slice the needed chunk of pages
     $more = count($entries) > $first + $num ? true : false;
     $entries = array_slice($entries, $first, $num);
     // load the include helper plugin
     if (plugin_isdisabled('include') || !($include =& plugin_load('helper', 'include'))) {
         msg($this->getLang('missing_includeplugin'), -1);
         return false;
     }
     if ($mode == 'xhtml') {
         // prevent caching to ensure the included pages are always fresh
         $renderer->info['cache'] = false;
         // show new entry form
         $perm_create = auth_quickaclcheck($ns . ':*') >= AUTH_CREATE;
         if ($perm_create && $formpos == 'top') {
             $renderer->doc .= $this->_newEntryForm($ns);
         }
         // current section level
         $clevel = 0;
         preg_match_all('|<div class="level(\\d)">|i', $renderer->doc, $matches, PREG_SET_ORDER);
         $n = count($matches) - 1;
         if ($n > -1) {
             $clevel = $matches[$n][1];
         }
         // close current section
         if ($clevel) {
             $renderer->doc .= '</div>' . DOKU_LF;
         }
         $renderer->doc .= '<div class="hfeed">' . DOKU_LF;
     }
     // we need our own renderer
     $include_renderer =& p_get_renderer('xhtml');
     $include_renderer->smileys = getSmileys();
     $include_renderer->entities = getEntities();
     $include_renderer->acronyms = getAcronyms();
     $include_renderer->interwiki = getInterwiki();
     // now include the blog entries
     foreach ($entries as $entry) {
         if ($mode == 'xhtml') {
             if (auth_quickaclcheck($entry['id']) >= AUTH_READ) {
                 $renderer->doc .= $this->render_XHTML($include, $include_renderer, $entry['id'], $clevel, $flags);
             }
         } elseif ($mode == 'metadata') {
             $renderer->meta['relation']['haspart'][$entry['id']] = true;
         }
     }
     if ($mode == 'xhtml') {
         // resume the section
         $renderer->doc .= '</div>' . DOKU_LF;
         if ($clevel) {
             $renderer->doc .= '<div class="level' . $clevel . '">' . DOKU_LF;
         }
         // BEGIN MODIFIED by harukasan
         if (!in_array('nofollowlink', $flags)) {
             // show older / newer entries links
             $renderer->doc .= $this->_browseEntriesLinks($more, $first, $num);
         }
         // END MODIFIED
         // show new entry form
         if ($perm_create && $formpos == 'bottom') {
             $renderer->doc .= $this->_newEntryForm($ns);
         }
     }
     return true;
 }
 function html()
 {
     /** @var helper_plugin_translation $helper */
     $helper = plugin_load('helper', "translation");
     $default_language = $helper->defaultlang;
     /** @var Doku_Renderer_xhtml $xhtml_renderer */
     $xhtml_renderer = p_get_renderer('xhtml');
     echo "<h1>" . $this->getLang("menu") . "</h1>";
     echo "<table id='outdated_translations' class=\"inline\">";
     echo "<tr><th>default: {$default_language}</th>";
     if ($this->getConf('show_path')) {
         echo "<th>" . $this->getLang('path') . "</th>";
     }
     foreach ($helper->translations as $t) {
         if ($t === $default_language) {
             continue;
         }
         echo "<th>{$t}</th>";
     }
     echo "</tr>";
     $pages = $this->getAllPages();
     foreach ($pages as $page) {
         if (!$helper->getLangPart($page["id"]) === $default_language || !$helper->istranslatable($page["id"], false) || !page_exists($page["id"])) {
             continue;
         }
         // We have an existing and translatable page in the default language
         $showRow = false;
         $row = "<tr><td>" . $xhtml_renderer->internallink($page['id'], null, null, true) . "</td>";
         if ($this->getConf('show_path')) {
             $row .= "<td>" . $xhtml_renderer->internallink($page['id'], $page['id'], null, true) . "</td>";
         }
         list($lc, $idpart) = $helper->getTransParts($page["id"]);
         foreach ($helper->translations as $t) {
             if ($t === $default_language) {
                 continue;
             }
             list($translID, $name) = $helper->buildTransID($t, $idpart);
             $difflink = '';
             if (!page_exists($translID)) {
                 $class = "missing";
                 $title = $this->getLang("missing");
                 $showRow = true;
             } else {
                 $translfn = wikiFN($translID);
                 if ($page['mtime'] > filemtime($translfn)) {
                     $class = "outdated";
                     $difflink = " <a href='";
                     $difflink .= $helper->getOldDiffLink($page["id"], $page['mtime']);
                     $difflink .= "'>(diff)</a>";
                     $title = $this->getLang('old');
                     $showRow = true;
                 } else {
                     $class = "current";
                     $title = $this->getLang('current');
                 }
             }
             $row .= "<td class='{$class}'>" . $xhtml_renderer->internallink($translID, $title, null, true) . $difflink . "</td>";
         }
         $row .= "</tr>";
         if ($showRow) {
             echo $row;
         }
     }
     echo "</table>";
 }