コード例 #1
0
ファイル: template.php プロジェクト: neosunchess/dokuwiki
/**
 * Print the correct HTML meta headers
 *
 * This has to go into the head section of your template.
 *
 * @author Andreas Gohr <*****@*****.**>
 * @triggers TPL_METAHEADER_OUTPUT
 * @param  bool $alt Should feeds and alternative format links be added?
 * @return bool
 */
function tpl_metaheaders($alt = true)
{
    global $ID;
    global $REV;
    global $INFO;
    global $JSINFO;
    global $ACT;
    global $QUERY;
    global $lang;
    global $conf;
    // prepare the head array
    $head = array();
    // prepare seed for js and css
    $tseed = 0;
    $depends = getConfigFiles('main');
    foreach ($depends as $f) {
        $time = @filemtime($f);
        if ($time > $tseed) {
            $tseed = $time;
        }
    }
    // the usual stuff
    $head['meta'][] = array('name' => 'generator', 'content' => 'DokuWiki');
    $head['link'][] = array('rel' => 'search', 'type' => 'application/opensearchdescription+xml', 'href' => DOKU_BASE . 'lib/exe/opensearch.php', 'title' => $conf['title']);
    $head['link'][] = array('rel' => 'start', 'href' => DOKU_BASE);
    if (actionOK('index')) {
        $head['link'][] = array('rel' => 'contents', 'href' => wl($ID, 'do=index', false, '&'), 'title' => $lang['btn_index']);
    }
    if ($alt) {
        $head['link'][] = array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => 'Recent Changes', 'href' => DOKU_BASE . 'feed.php');
        $head['link'][] = array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => 'Current Namespace', 'href' => DOKU_BASE . 'feed.php?mode=list&ns=' . $INFO['namespace']);
        if (($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
            $head['link'][] = array('rel' => 'edit', 'title' => $lang['btn_edit'], 'href' => wl($ID, 'do=edit', false, '&'));
        }
        if ($ACT == 'search') {
            $head['link'][] = array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => 'Search Result', 'href' => DOKU_BASE . 'feed.php?mode=search&q=' . $QUERY);
        }
        if (actionOK('export_xhtml')) {
            $head['link'][] = array('rel' => 'alternate', 'type' => 'text/html', 'title' => 'Plain HTML', 'href' => exportlink($ID, 'xhtml', '', false, '&'));
        }
        if (actionOK('export_raw')) {
            $head['link'][] = array('rel' => 'alternate', 'type' => 'text/plain', 'title' => 'Wiki Markup', 'href' => exportlink($ID, 'raw', '', false, '&'));
        }
    }
    // setup robot tags apropriate for different modes
    if (($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
        if ($INFO['exists']) {
            //delay indexing:
            if (time() - $INFO['lastmod'] >= $conf['indexdelay']) {
                $head['meta'][] = array('name' => 'robots', 'content' => 'index,follow');
            } else {
                $head['meta'][] = array('name' => 'robots', 'content' => 'noindex,nofollow');
            }
            $head['link'][] = array('rel' => 'canonical', 'href' => wl($ID, '', true, '&'));
        } else {
            $head['meta'][] = array('name' => 'robots', 'content' => 'noindex,follow');
        }
    } elseif (defined('DOKU_MEDIADETAIL')) {
        $head['meta'][] = array('name' => 'robots', 'content' => 'index,follow');
    } else {
        $head['meta'][] = array('name' => 'robots', 'content' => 'noindex,nofollow');
    }
    // set metadata
    if ($ACT == 'show' || $ACT == 'export_xhtml') {
        // date of modification
        if ($REV) {
            $head['meta'][] = array('name' => 'date', 'content' => date('Y-m-d\\TH:i:sO', $REV));
        } else {
            $head['meta'][] = array('name' => 'date', 'content' => date('Y-m-d\\TH:i:sO', $INFO['lastmod']));
        }
        // keywords (explicit or implicit)
        if (!empty($INFO['meta']['subject'])) {
            $head['meta'][] = array('name' => 'keywords', 'content' => join(',', $INFO['meta']['subject']));
        } else {
            $head['meta'][] = array('name' => 'keywords', 'content' => str_replace(':', ',', $ID));
        }
    }
    // load stylesheets
    $head['link'][] = array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => DOKU_BASE . 'lib/exe/css.php?t=' . $conf['template'] . '&tseed=' . $tseed);
    // make $INFO and other vars available to JavaScripts
    $json = new JSON();
    $script = "var NS='" . $INFO['namespace'] . "';";
    if ($conf['useacl'] && $_SERVER['REMOTE_USER']) {
        $script .= "var SIG='" . toolbar_signature() . "';";
    }
    $script .= 'var JSINFO = ' . $json->encode($JSINFO) . ';';
    $head['script'][] = array('type' => 'text/javascript', '_data' => $script);
    // load external javascript
    $head['script'][] = array('type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => DOKU_BASE . 'lib/exe/js.php' . '?tseed=' . $tseed);
    // trigger event here
    trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
    return true;
}
コード例 #2
0
/**
 * Print the correct HTML meta headers
 *
 * This has to go into the head section of your template.
 *
 * @triggers TPL_METAHEADER_OUTPUT
 * @param  boolean $alt Should feeds and alternative format links be added?
 * @author Andreas Gohr <*****@*****.**>
 */
function tpl_metaheaders($alt = true)
{
    global $ID;
    global $REV;
    global $INFO;
    global $ACT;
    global $QUERY;
    global $lang;
    global $conf;
    $it = 2;
    // prepare the head array
    $head = array();
    // the usual stuff
    $head['meta'][] = array('name' => 'generator', 'content' => 'DokuWiki ' . getVersion());
    $head['link'][] = array('rel' => 'search', 'type' => 'application/opensearchdescription+xml', 'href' => DOKU_BASE . 'lib/exe/opensearch.php', 'title' => $conf['title']);
    $head['link'][] = array('rel' => 'start', 'href' => DOKU_BASE);
    if (actionOK('index')) {
        $head['link'][] = array('rel' => 'contents', 'href' => wl($ID, 'do=index', false, '&'), 'title' => $lang['btn_index']);
    }
    if ($alt) {
        $head['link'][] = array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => 'Recent Changes', 'href' => DOKU_BASE . 'feed.php');
        $head['link'][] = array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => 'Current Namespace', 'href' => DOKU_BASE . 'feed.php?mode=list&ns=' . $INFO['namespace']);
        if (($ACT == 'show' || $ACT == 'search') && $INFO['writable']) {
            $head['link'][] = array('rel' => 'alternate', 'type' => 'application/wiki', 'title' => $lang['btn_edit'], 'href' => wl($ID, 'do=edit', false, '&'));
        }
        if ($ACT == 'search') {
            $head['link'][] = array('rel' => 'alternate', 'type' => 'application/rss+xml', 'title' => 'Search Result', 'href' => DOKU_BASE . 'feed.php?mode=search&q=' . $QUERY);
        }
        if (actionOK('export_xhtml')) {
            $head['link'][] = array('rel' => 'alternate', 'type' => 'text/html', 'title' => 'Plain HTML', 'href' => exportlink($ID, 'xhtml', '', false, '&'));
        }
        if (actionOK('export_raw')) {
            $head['link'][] = array('rel' => 'alternate', 'type' => 'text/plain', 'title' => 'Wiki Markup', 'href' => exportlink($ID, 'raw', '', false, '&'));
        }
    }
    // setup robot tags apropriate for different modes
    if (($ACT == 'show' || $ACT == 'export_xhtml') && !$REV) {
        if ($INFO['exists']) {
            //delay indexing:
            if (time() - $INFO['lastmod'] >= $conf['indexdelay']) {
                $head['meta'][] = array('name' => 'robots', 'content' => 'index,follow');
            } else {
                $head['meta'][] = array('name' => 'robots', 'content' => 'noindex,nofollow');
            }
        } else {
            $head['meta'][] = array('name' => 'robots', 'content' => 'noindex,follow');
        }
    } elseif (defined('DOKU_MEDIADETAIL')) {
        $head['meta'][] = array('name' => 'robots', 'content' => 'index,follow');
    } else {
        $head['meta'][] = array('name' => 'robots', 'content' => 'noindex,nofollow');
    }
    // set metadata
    if ($ACT == 'show' || $ACT == 'export_xhtml') {
        // date of modification
        if ($REV) {
            $head['meta'][] = array('name' => 'date', 'content' => date('Y-m-d\\TH:i:sO', $REV));
        } else {
            $head['meta'][] = array('name' => 'date', 'content' => date('Y-m-d\\TH:i:sO', $INFO['lastmod']));
        }
        // keywords (explicit or implicit)
        if (!empty($INFO['meta']['subject'])) {
            $head['meta'][] = array('name' => 'keywords', 'content' => join(',', $INFO['meta']['subject']));
        } else {
            $head['meta'][] = array('name' => 'keywords', 'content' => str_replace(':', ',', $ID));
        }
    }
    // load stylesheets
    $head['link'][] = array('rel' => 'stylesheet', 'media' => 'all', 'type' => 'text/css', 'href' => DOKU_BASE . 'lib/exe/css.php?s=all&t=' . $conf['template']);
    $head['link'][] = array('rel' => 'stylesheet', 'media' => 'screen', 'type' => 'text/css', 'href' => DOKU_BASE . 'lib/exe/css.php?t=' . $conf['template']);
    $head['link'][] = array('rel' => 'stylesheet', 'media' => 'print', 'type' => 'text/css', 'href' => DOKU_BASE . 'lib/exe/css.php?s=print&t=' . $conf['template']);
    // load javascript
    $js_edit = $ACT == 'edit' || $ACT == 'preview' || $ACT == 'recover' || $ACT == 'wordblock' ? 1 : 0;
    $js_write = $INFO['writable'] ? 1 : 0;
    if (defined('DOKU_MEDIAMANAGER')) {
        $js_edit = 1;
        $js_write = 0;
    }
    if ($js_edit && $js_write || defined('DOKU_MEDIAMANAGER')) {
        $script = "NS='" . $INFO['namespace'] . "';";
        if ($conf['useacl'] && $_SERVER['REMOTE_USER']) {
            require_once DOKU_INC . 'inc/toolbar.php';
            $script .= "SIG='" . toolbar_signature() . "';";
        }
        $head['script'][] = array('type' => 'text/javascript', 'charset' => 'utf-8', '_data' => $script);
    }
    $head['script'][] = array('type' => 'text/javascript', 'charset' => 'utf-8', '_data' => '', 'src' => DOKU_BASE . 'lib/exe/js.php?edit=' . $js_edit . '&write=' . $js_write);
    // trigger event here
    trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
    return true;
}