Esempio n. 1
1
/**
 * Output all needed JavaScript
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function js_out()
{
    global $conf;
    global $lang;
    global $config_cascade;
    // The generated script depends on some dynamic options
    $cache = new cache('scripts' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'], '.js');
    $cache->_event = 'JS_CACHE_USE';
    // load minified version for some files
    $min = $conf['compress'] ? '.min' : '';
    // array of core files
    $files = array(DOKU_INC . "lib/scripts/jquery/jquery{$min}.js", DOKU_INC . 'lib/scripts/jquery/jquery.cookie.js', DOKU_INC . "lib/scripts/jquery/jquery-ui{$min}.js", DOKU_INC . "lib/scripts/fileuploader.js", DOKU_INC . "lib/scripts/fileuploaderextended.js", DOKU_INC . 'lib/scripts/helpers.js', DOKU_INC . 'lib/scripts/delay.js', DOKU_INC . 'lib/scripts/cookie.js', DOKU_INC . 'lib/scripts/script.js', DOKU_INC . 'lib/scripts/tw-sack.js', DOKU_INC . 'lib/scripts/qsearch.js', DOKU_INC . 'lib/scripts/tree.js', DOKU_INC . 'lib/scripts/index.js', DOKU_INC . 'lib/scripts/drag.js', DOKU_INC . 'lib/scripts/textselection.js', DOKU_INC . 'lib/scripts/toolbar.js', DOKU_INC . 'lib/scripts/edit.js', DOKU_INC . 'lib/scripts/editor.js', DOKU_INC . 'lib/scripts/locktimer.js', DOKU_INC . 'lib/scripts/linkwiz.js', DOKU_INC . 'lib/scripts/media.js', DOKU_INC . 'lib/scripts/compatibility.js', DOKU_INC . 'lib/scripts/behaviour.js', DOKU_INC . 'lib/scripts/page.js', tpl_incdir() . 'script.js');
    // add possible plugin scripts and userscript
    $files = array_merge($files, js_pluginscripts());
    if (isset($config_cascade['userscript']['default'])) {
        $files[] = $config_cascade['userscript']['default'];
    }
    $cache_files = array_merge($files, getConfigFiles('main'));
    $cache_files[] = __FILE__;
    // check cache age & handle conditional request
    // This may exit if a cache can be used
    $cache_ok = $cache->useCache(array('files' => $cache_files));
    http_cached($cache->cache, $cache_ok);
    // start output buffering and build the script
    ob_start();
    // add some global variables
    print "var DOKU_BASE   = '" . DOKU_BASE . "';";
    print "var DOKU_TPL    = '" . tpl_basedir() . "';";
    // FIXME: Move those to JSINFO
    print "var DOKU_UHN    = " . (int) useHeading('navigation') . ";";
    print "var DOKU_UHC    = " . (int) useHeading('content') . ";";
    // load JS specific translations
    $json = new JSON();
    $lang['js']['plugins'] = js_pluginstrings();
    echo 'LANG = ' . $json->encode($lang['js']) . ";\n";
    // load toolbar
    toolbar_JSdefines('toolbar');
    // load files
    foreach ($files as $file) {
        echo "\n\n/* XXXXXXXXXX begin of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";
        js_load($file);
        echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";
    }
    // init stuff
    if ($conf['locktime'] != 0) {
        js_runonstart("dw_locktimer.init(" . ($conf['locktime'] - 60) . "," . $conf['usedraft'] . ")");
    }
    // init hotkeys - must have been done after init of toolbar
    # disabled for FS#1958    js_runonstart('initializeHotkeys()');
    // end output buffering and get contents
    $js = ob_get_contents();
    ob_end_clean();
    // compress whitespace and comments
    if ($conf['compress']) {
        $js = js_compress($js);
    }
    $js .= "\n";
    // https://bugzilla.mozilla.org/show_bug.cgi?id=316033
    http_cached_finish($cache->cache, $js);
}
    public function document_start()
    {
        global $conf;
        global $ID;
        global $updateVersion;
        $this->base = DOKU_BASE . 'lib/plugins/impressjs/tpl/';
        $this->tpl = $this->getConf('template');
        // prepare seed for js and css
        $tseed = $updateVersion;
        $depends = getConfigFiles('main');
        foreach ($depends as $f) {
            $tseed .= @filemtime($f);
        }
        $tseed = md5($tseed);
        $this->doc .= '<!DOCTYPE html>
<html lang="' . $conf['lang'] . '">
<head>
    <meta name="viewport" content="width=1024" />
    <meta charset="utf-8" />
    <title>' . tpl_pagetitle($ID, true) . '</title>
                
    <meta name="generator" content="impress.js" />
    <meta name="version" content="impress.js ab44798b081997319f4207dabbb052736acfc512" />
                
    <link rel="stylesheet" href="' . DOKU_BASE . 'lib/exe/css.php?t=none&tseed=' . $tseed . '" type="text/css" media="screen" />
    <link href="' . $this->base . $this->tpl . '/impress.css" rel="stylesheet" />
    <link href="' . $this->base . $this->tpl . '/impress-extra.css" rel="stylesheet" />
</head>
<body>
    <div id="impress">';
    }
Esempio n. 3
0
/**
 * Checks if a JavaScript Cache file still is valid
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function js_cacheok($cache, $files)
{
    if (isset($_REQUEST['purge'])) {
        return false;
    }
    //support purge request
    $ctime = @filemtime($cache);
    if (!$ctime) {
        return false;
    }
    //There is no cache
    // some additional files to check
    $files = array_merge($files, getConfigFiles('main'));
    $files[] = DOKU_CONF . 'userscript.js';
    $files[] = __FILE__;
    // now walk the files
    foreach ($files as $file) {
        if (@filemtime($file) > $ctime) {
            return false;
        }
    }
    return true;
}
Esempio n. 4
0
/**
 * 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;
}
Esempio n. 5
0
 */
if (!defined('DOKU_INC')) {
    define('DOKU_INC', dirname(__FILE__) . '/');
}
require_once DOKU_INC . 'inc/init.php';
//close session
session_write_close();
// get params
$opt = rss_parseOptions();
// the feed is dynamic - we need a cache for each combo
// (but most people just use the default feed so it's still effective)
$cache = getCacheName(join('', array_values($opt)) . $_SERVER['REMOTE_USER'], '.feed');
$key = join('', array_values($opt)) . $_SERVER['REMOTE_USER'];
$cache = new cache($key, '.feed');
// prepare cache depends
$depends['files'] = getConfigFiles('main');
$depends['age'] = $conf['rss_update'];
$depends['purge'] = $_REQUEST['purge'] ? true : false;
// check cacheage and deliver if nothing has changed since last
// time or the update interval has not passed, also handles conditional requests
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Type: application/xml; charset=utf-8');
header('X-Robots-Tag: noindex');
if ($cache->useCache($depends)) {
    http_conditionalRequest($cache->_time);
    if ($conf['allowdebug']) {
        header("X-CacheUsed: {$cache->cache}");
    }
    print $cache->retrieveCache();
    exit;
Esempio n. 6
0
/**
 * Returns metadata as configured in mediameta config file, ready for creating html
 *
 * @return array with arrays containing the entries:
 *   - string langkey  key to lookup in the $lang var, if not found printed as is
 *   - string type     type of value
 *   - string value    tag value (unescaped)
 */
function tpl_get_img_meta()
{
    $config_files = getConfigFiles('mediameta');
    foreach ($config_files as $config_file) {
        if (file_exists($config_file)) {
            include $config_file;
        }
    }
    /** @var array $fields the included array with metadata */
    $tags = array();
    foreach ($fields as $tag) {
        $t = array();
        if (!empty($tag[0])) {
            $t = array($tag[0]);
        }
        if (is_array($tag[3])) {
            $t = array_merge($t, $tag[3]);
        }
        $value = tpl_img_getTag($t);
        if ($value) {
            $tags[] = array('langkey' => $tag[1], 'type' => $tag[2], 'value' => $value);
        }
    }
    return $tags;
}
 /**
  * Prepare cache
  *
  * @param string $title
  * @param array  $depends (reference) array with dependencies
  * @return cache
  */
 protected function prepareCache($title, &$depends)
 {
     global $REV;
     global $INPUT;
     //different caches for varying config settings
     $template = $this->getConf("tpl_default");
     $template = $INPUT->get->str('odt-template', $template, true);
     $cachekey = join(',', $this->list) . $REV . $template . $title;
     $cache = new cache($cachekey, '.odt');
     $dependencies = array();
     foreach ($this->list as $pageid) {
         $relations = p_get_metadata($pageid, 'relation');
         if (is_array($relations)) {
             if (array_key_exists('media', $relations) && is_array($relations['media'])) {
                 foreach ($relations['media'] as $mediaid => $exists) {
                     if ($exists) {
                         $dependencies[] = mediaFN($mediaid);
                     }
                 }
             }
             if (array_key_exists('haspart', $relations) && is_array($relations['haspart'])) {
                 foreach ($relations['haspart'] as $part_pageid => $exists) {
                     if ($exists) {
                         $dependencies[] = wikiFN($part_pageid);
                     }
                 }
             }
         }
         $dependencies[] = metaFN($pageid, '.meta');
     }
     $depends['files'] = array_map('wikiFN', $this->list);
     $depends['files'][] = __FILE__;
     $depends['files'][] = dirname(__FILE__) . '/renderer/page.php';
     $depends['files'][] = dirname(__FILE__) . '/renderer/book.php';
     $depends['files'][] = dirname(__FILE__) . '/plugin.info.txt';
     $depends['files'] = array_merge($depends['files'], $dependencies, getConfigFiles('main'));
     return $cache;
 }
Esempio n. 8
0
 protected function _addDependencies()
 {
     // parser cache file dependencies ...
     $files = array($this->file, DOKU_INC . 'inc/parser/parser.php', DOKU_INC . 'inc/parser/handler.php');
     $files = array_merge($files, getConfigFiles('main'));
     // ... wiki settings
     $this->depends['files'] = !empty($this->depends['files']) ? array_merge($files, $this->depends['files']) : $files;
     parent::_addDependencies();
 }
Esempio n. 9
0
 function _addDependencies()
 {
     global $conf, $config_cascade;
     $this->depends['age'] = isset($this->depends['age']) ? min($this->depends['age'], $conf['cachetime']) : $conf['cachetime'];
     // parser cache file dependencies ...
     $files = array($this->file, DOKU_INC . 'inc/parser/parser.php', DOKU_INC . 'inc/parser/handler.php');
     $files = array_merge($files, getConfigFiles('main'));
     // ... wiki settings
     $this->depends['files'] = !empty($this->depends['files']) ? array_merge($files, $this->depends['files']) : $files;
     parent::_addDependencies();
 }
Esempio n. 10
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function css_out()
{
    global $conf;
    global $lang;
    global $config_cascade;
    $mediatype = 'screen';
    if (isset($_REQUEST['s']) && in_array($_REQUEST['s'], array('all', 'print', 'feed'))) {
        $mediatype = $_REQUEST['s'];
    }
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $_REQUEST['t']));
    if ($tpl) {
        $tplinc = DOKU_INC . 'lib/tpl/' . $tpl . '/';
        $tpldir = DOKU_BASE . 'lib/tpl/' . $tpl . '/';
    } else {
        $tplinc = DOKU_TPLINC;
        $tpldir = DOKU_TPL;
    }
    // The generated script depends on some dynamic options
    $cache = new cache('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tplinc . $mediatype, '.css');
    // load template styles
    $tplstyles = array();
    if (@file_exists($tplinc . 'style.ini')) {
        $ini = parse_ini_file($tplinc . 'style.ini', true);
        foreach ($ini['stylesheets'] as $file => $mode) {
            $tplstyles[$mode][$tplinc . $file] = $tpldir;
        }
    }
    // Array of needed files and their web locations, the latter ones
    // are needed to fix relative paths in the stylesheets
    $files = array();
    // load core styles
    $files[DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/';
    // load jQuery-UI theme
    $files[DOKU_INC . 'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE . 'lib/scripts/jquery/jquery-ui-theme/';
    // load plugin styles
    $files = array_merge($files, css_pluginstyles($mediatype));
    // load template styles
    if (isset($tplstyles[$mediatype])) {
        $files = array_merge($files, $tplstyles[$mediatype]);
    }
    // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility
    if (isset($config_cascade['userstyle']['default'])) {
        $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default'];
    }
    // load user styles
    if (isset($config_cascade['userstyle'][$mediatype])) {
        $files[$config_cascade['userstyle'][$mediatype]] = DOKU_BASE;
    }
    // load rtl styles
    // @todo: this currently adds the rtl styles only to the 'screen' media type
    //        but 'print' and 'all' should also be supported
    if ($mediatype == 'screen') {
        if ($lang['direction'] == 'rtl') {
            if (isset($tplstyles['rtl'])) {
                $files = array_merge($files, $tplstyles['rtl']);
            }
        }
    }
    $cache_files = array_merge(array_keys($files), getConfigFiles('main'));
    $cache_files[] = $tplinc . 'style.ini';
    $cache_files[] = __FILE__;
    // check cache age & handle conditional request
    // This may exit if a cache can be used
    http_cached($cache->cache, $cache->useCache(array('files' => $cache_files)));
    // start output buffering and build the stylesheet
    ob_start();
    // print the default classes for interwiki links and file downloads
    css_interwiki();
    css_filetypes();
    // load files
    foreach ($files as $file => $location) {
        print css_loadfile($file, $location);
    }
    // end output buffering and get contents
    $css = ob_get_contents();
    ob_end_clean();
    // apply style replacements
    $css = css_applystyle($css, $tplinc);
    // place all @import statements at the top of the file
    $css = css_moveimports($css);
    // compress whitespace and comments
    if ($conf['compress']) {
        $css = css_compress($css);
    }
    // embed small images right into the stylesheet
    if ($conf['cssdatauri']) {
        $base = preg_quote(DOKU_BASE, '#');
        $css = preg_replace_callback('#(url\\([ \'"]*)(' . $base . ')(.*?(?:\\.(png|gif)))#i', 'css_datauri', $css);
    }
    http_cached_finish($cache->cache, $css);
}
Esempio n. 11
0
/**
 * Checks if a CSS Cache file still is valid
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function css_cacheok($cache, $files, $tplinc)
{
    global $config_cascade;
    if (isset($_REQUEST['purge'])) {
        return false;
    }
    //support purge request
    $ctime = @filemtime($cache);
    if (!$ctime) {
        return false;
    }
    //There is no cache
    // some additional files to check
    $files = array_merge($files, getConfigFiles('main'));
    $files[] = $tplinc . 'style.ini';
    $files[] = __FILE__;
    // now walk the files
    foreach ($files as $file) {
        if (@filemtime($file) > $ctime) {
            return false;
        }
    }
    return true;
}
Esempio n. 12
0
/**
 * Returns mediafile tags
 *
 * @author Kate Arzamastseva <*****@*****.**>
 * @param JpegMeta $meta
 * @return array
 */
function media_file_tags($meta)
{
    // load the field descriptions
    static $fields = null;
    if (is_null($fields)) {
        $config_files = getConfigFiles('mediameta');
        foreach ($config_files as $config_file) {
            if (@file_exists($config_file)) {
                include $config_file;
            }
        }
    }
    $tags = array();
    foreach ($fields as $key => $tag) {
        $t = array();
        if (!empty($tag[0])) {
            $t = array($tag[0]);
        }
        if (isset($tag[3]) && is_array($tag[3])) {
            $t = array_merge($t, $tag[3]);
        }
        $value = media_getTag($t, $meta);
        $tags[] = array('tag' => $tag, 'value' => $value);
    }
    return $tags;
}
Esempio n. 13
0
 /**
  * Do the HTML to PDF conversion work
  *
  * @param Doku_Event $event
  * @param array      $param
  * @return bool
  */
 public function convert(&$event, $param)
 {
     global $ACT;
     global $REV;
     global $ID;
     // our event?
     if ($ACT != 'export_pdfbook' && $ACT != 'export_pdf') {
         return false;
     }
     // check user's rights
     if (auth_quickaclcheck($ID) < AUTH_READ) {
         return false;
     }
     // one or multiple pages?
     $list = array();
     if ($ACT == 'export_pdf') {
         $list[0] = $ID;
         $title = p_get_first_heading($ID);
     } elseif (isset($_COOKIE['list-pagelist']) && !empty($_COOKIE['list-pagelist'])) {
         //is in Bookmanager of bookcreator plugin title given
         if (!($title = $_GET['pdfbook_title'])) {
             //TODO when title is changed, the cached file contains the old title
             /** @var $bookcreator action_plugin_bookcreator */
             $bookcreator = plugin_load('action', 'bookcreator');
             msg($bookcreator->getLang('needtitle'), -1);
             $event->data = 'show';
             $_SERVER['REQUEST_METHOD'] = 'POST';
             //clears url
             return false;
         }
         $list = explode("|", $_COOKIE['list-pagelist']);
     } else {
         /** @var $bookcreator action_plugin_bookcreator */
         $bookcreator = plugin_load('action', 'bookcreator');
         msg($bookcreator->getLang('empty'), -1);
         $event->data = 'show';
         $_SERVER['REQUEST_METHOD'] = 'POST';
         //clears url
         return false;
     }
     // it's ours, no one else's
     $event->preventDefault();
     // prepare cache
     $cache = new cache(join(',', $list) . $REV . $this->tpl, '.dw2.pdf');
     $depends['files'] = array_map('wikiFN', $list);
     $depends['files'][] = __FILE__;
     $depends['files'][] = dirname(__FILE__) . '/renderer.php';
     $depends['files'][] = dirname(__FILE__) . '/mpdf/mpdf.php';
     $depends['files'] = array_merge($depends['files'], getConfigFiles('main'));
     // hard work only when no cache available
     if (!$this->getConf('usecache') || !$cache->useCache($depends)) {
         // initialize PDF library
         require_once dirname(__FILE__) . "/DokuPDF.class.php";
         $mpdf = new DokuPDF();
         // let mpdf fix local links
         $self = parse_url(DOKU_URL);
         $url = $self['scheme'] . '://' . $self['host'];
         if ($self['port']) {
             $url .= ':' . $self['port'];
         }
         $mpdf->setBasePath($url);
         // Set the title
         $mpdf->SetTitle($title);
         // some default settings
         $mpdf->mirrorMargins = 1;
         $mpdf->useOddEven = 1;
         $mpdf->setAutoTopMargin = 'stretch';
         $mpdf->setAutoBottomMargin = 'stretch';
         // load the template
         $template = $this->load_template($title);
         // prepare HTML header styles
         $html = '<html><head>';
         $html .= '<style type="text/css">';
         $html .= $this->load_css();
         $html .= '@page { size:auto; ' . $template['page'] . '}';
         $html .= '@page :first {' . $template['first'] . '}';
         $html .= '</style>';
         $html .= '</head><body>';
         $html .= $template['html'];
         $html .= '<div class="dokuwiki">';
         // loop over all pages
         $cnt = count($list);
         for ($n = 0; $n < $cnt; $n++) {
             $page = $list[$n];
             $html .= p_cached_output(wikiFN($page, $REV), 'dw2pdf', $page);
             $html .= $this->page_depend_replacements($template['cite'], cleanID($page));
             if ($n < $cnt - 1) {
                 $html .= '<pagebreak />';
             }
         }
         $html .= '</div>';
         $mpdf->WriteHTML($html);
         // write to cache file
         $mpdf->Output($cache->cache, 'F');
     }
     // deliver the file
     header('Content-Type: application/pdf');
     header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0');
     header('Pragma: public');
     http_conditionalRequest(filemtime($cache->cache));
     $filename = rawurlencode(cleanID(strtr($title, ':/;"', '    ')));
     if ($this->getConf('output') == 'file') {
         header('Content-Disposition: attachment; filename="' . $filename . '.pdf";');
     } else {
         header('Content-Disposition: inline; filename="' . $filename . '.pdf";');
     }
     if (http_sendfile($cache->cache)) {
         exit;
     }
     $fp = @fopen($cache->cache, "rb");
     if ($fp) {
         http_rangeRequest($fp, filesize($cache->cache), 'application/pdf');
     } else {
         header("HTTP/1.0 500 Internal Server Error");
         print "Could not read file - bad permissions?";
     }
     exit;
 }
Esempio n. 14
0
 /**
  * Prepare cache
  *
  * @param string $title
  * @param array  $depends (reference) array with dependencies
  * @return cache
  */
 protected function prepareCache($title, &$depends)
 {
     global $REV;
     $cachekey = join(',', $this->list) . $REV . $this->getExportConfig('template') . $this->getExportConfig('pagesize') . $this->getExportConfig('orientation') . $title;
     $cache = new cache($cachekey, '.odt');
     $dependencies = array();
     foreach ($this->list as $pageid) {
         $relations = p_get_metadata($pageid, 'relation');
         if (is_array($relations)) {
             if (array_key_exists('media', $relations) && is_array($relations['media'])) {
                 foreach ($relations['media'] as $mediaid => $exists) {
                     if ($exists) {
                         $dependencies[] = mediaFN($mediaid);
                     }
                 }
             }
             if (array_key_exists('haspart', $relations) && is_array($relations['haspart'])) {
                 foreach ($relations['haspart'] as $part_pageid => $exists) {
                     if ($exists) {
                         $dependencies[] = wikiFN($part_pageid);
                     }
                 }
             }
         }
         $dependencies[] = metaFN($pageid, '.meta');
     }
     $depends['files'] = array_map('wikiFN', $this->list);
     $depends['files'][] = __FILE__;
     $depends['files'][] = dirname(__FILE__) . '/../renderer.php';
     //        $depends['files'][] = dirname(__FILE__) . '/../mpdf/mpdf.php';
     $depends['files'] = array_merge($depends['files'], $dependencies, getConfigFiles('main'));
     return $cache;
 }
Esempio n. 15
0
            <div class="content">
                <?php 
    tpl_img(900, 700);
    /* parameters: maximum width, maximum height (and more) */
    ?>

                <div class="img_detail">
                    <h2><?php 
    print nl2br(hsc(tpl_img_getTag('simple.title')));
    ?>
</h2>

                    <dl>
                        <?php 
    $config_files = getConfigFiles('mediameta');
    foreach ($config_files as $config_file) {
        if (@file_exists($config_file)) {
            include $config_file;
        }
    }
    foreach ($fields as $key => $tag) {
        $t = array();
        if (!empty($tag[0])) {
            $t = array($tag[0]);
        }
        if (is_array($tag[3])) {
            $t = array_merge($t, $tag[3]);
        }
        $value = tpl_img_getTag($t);
        if ($value) {
Esempio n. 16
0
/**
 * Output all needed JavaScript
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function js_out()
{
    global $conf;
    global $lang;
    global $config_cascade;
    global $INPUT;
    // decide from where to get the template
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $INPUT->str('t')));
    if (!$tpl) {
        $tpl = $conf['template'];
    }
    // The generated script depends on some dynamic options
    $cache = new cache('scripts' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tpl, '.js');
    $cache->_event = 'JS_CACHE_USE';
    // load minified version for some files
    $min = $conf['compress'] ? '.min' : '';
    // array of core files
    $files = array(DOKU_INC . "lib/scripts/jquery/jquery{$min}.js", DOKU_INC . 'lib/scripts/jquery/jquery.cookie.js', DOKU_INC . "lib/scripts/jquery/jquery-ui{$min}.js", DOKU_INC . "lib/scripts/jquery/jquery-migrate{$min}.js", DOKU_INC . 'inc/lang/' . $conf['lang'] . '/jquery.ui.datepicker.js', DOKU_INC . "lib/scripts/fileuploader.js", DOKU_INC . "lib/scripts/fileuploaderextended.js", DOKU_INC . 'lib/scripts/helpers.js', DOKU_INC . 'lib/scripts/delay.js', DOKU_INC . 'lib/scripts/cookie.js', DOKU_INC . 'lib/scripts/script.js', DOKU_INC . 'lib/scripts/qsearch.js', DOKU_INC . 'lib/scripts/tree.js', DOKU_INC . 'lib/scripts/index.js', DOKU_INC . 'lib/scripts/textselection.js', DOKU_INC . 'lib/scripts/toolbar.js', DOKU_INC . 'lib/scripts/edit.js', DOKU_INC . 'lib/scripts/editor.js', DOKU_INC . 'lib/scripts/locktimer.js', DOKU_INC . 'lib/scripts/linkwiz.js', DOKU_INC . 'lib/scripts/media.js', DOKU_INC . 'lib/scripts/compatibility.js', DOKU_INC . 'lib/scripts/behaviour.js', DOKU_INC . 'lib/scripts/page.js', tpl_incdir($tpl) . 'script.js');
    // add possible plugin scripts and userscript
    $files = array_merge($files, js_pluginscripts());
    if (!empty($config_cascade['userscript']['default'])) {
        foreach ($config_cascade['userscript']['default'] as $userscript) {
            $files[] = $userscript;
        }
    }
    $cache_files = array_merge($files, getConfigFiles('main'));
    $cache_files[] = __FILE__;
    // check cache age & handle conditional request
    // This may exit if a cache can be used
    $cache_ok = $cache->useCache(array('files' => $cache_files));
    http_cached($cache->cache, $cache_ok);
    // start output buffering and build the script
    ob_start();
    $json = new JSON();
    // add some global variables
    print "var DOKU_BASE   = '" . DOKU_BASE . "';";
    print "var DOKU_TPL    = '" . tpl_basedir($tpl) . "';";
    print "var DOKU_COOKIE_PARAM = " . $json->encode(array('path' => empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'], 'secure' => $conf['securecookie'] && is_ssl())) . ";";
    // FIXME: Move those to JSINFO
    print "var DOKU_UHN    = " . (int) useHeading('navigation') . ";";
    print "var DOKU_UHC    = " . (int) useHeading('content') . ";";
    // load JS specific translations
    $lang['js']['plugins'] = js_pluginstrings();
    $templatestrings = js_templatestrings($tpl);
    if (!empty($templatestrings)) {
        $lang['js']['template'] = $templatestrings;
    }
    echo 'LANG = ' . $json->encode($lang['js']) . ";\n";
    // load toolbar
    toolbar_JSdefines('toolbar');
    // load files
    foreach ($files as $file) {
        if (!file_exists($file)) {
            continue;
        }
        $ismin = substr($file, -7) == '.min.js';
        $debugjs = $conf['allowdebug'] && strpos($file, DOKU_INC . 'lib/scripts/') !== 0;
        echo "\n\n/* XXXXXXXXXX begin of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";
        if ($ismin) {
            echo "\n/* BEGIN NOCOMPRESS */\n";
        }
        if ($debugjs) {
            echo "\ntry {\n";
        }
        js_load($file);
        if ($debugjs) {
            echo "\n} catch (e) {\n   logError(e, '" . str_replace(DOKU_INC, '', $file) . "');\n}\n";
        }
        if ($ismin) {
            echo "\n/* END NOCOMPRESS */\n";
        }
        echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";
    }
    // init stuff
    if ($conf['locktime'] != 0) {
        js_runonstart("dw_locktimer.init(" . ($conf['locktime'] - 60) . "," . $conf['usedraft'] . ")");
    }
    // init hotkeys - must have been done after init of toolbar
    # disabled for FS#1958    js_runonstart('initializeHotkeys()');
    // end output buffering and get contents
    $js = ob_get_contents();
    ob_end_clean();
    // strip any source maps
    stripsourcemaps($js);
    // compress whitespace and comments
    if ($conf['compress']) {
        $js = js_compress($js);
    }
    $js .= "\n";
    // https://bugzilla.mozilla.org/show_bug.cgi?id=316033
    http_cached_finish($cache->cache, $js);
}
Esempio n. 17
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function css_out()
{
    global $conf;
    global $lang;
    global $config_cascade;
    global $INPUT;
    if ($INPUT->str('s') == 'feed') {
        $mediatypes = array('feed');
        $type = 'feed';
    } else {
        $mediatypes = array('screen', 'all', 'print');
        $type = '';
    }
    // decide from where to get the template
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $INPUT->str('t')));
    if (!$tpl) {
        $tpl = $conf['template'];
    }
    // The generated script depends on some dynamic options
    $cache = new cache('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . $INPUT->int('preview') . DOKU_BASE . $tpl . $type, '.css');
    // load styl.ini
    $styleini = css_styleini($tpl, $INPUT->bool('preview'));
    // cache influencers
    $tplinc = tpl_incdir($tpl);
    $cache_files = getConfigFiles('main');
    $cache_files[] = $tplinc . 'style.ini';
    $cache_files[] = DOKU_CONF . "tpl/{$tpl}/style.ini";
    $cache_files[] = __FILE__;
    if ($INPUT->bool('preview')) {
        $cache_files[] = $conf['cachedir'] . '/preview.ini';
    }
    // Array of needed files and their web locations, the latter ones
    // are needed to fix relative paths in the stylesheets
    $files = array();
    foreach ($mediatypes as $mediatype) {
        $files[$mediatype] = array();
        // load core styles
        $files[$mediatype][DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/';
        // load jQuery-UI theme
        if ($mediatype == 'screen') {
            $files[$mediatype][DOKU_INC . 'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE . 'lib/scripts/jquery/jquery-ui-theme/';
        }
        // load plugin styles
        $files[$mediatype] = array_merge($files[$mediatype], css_pluginstyles($mediatype));
        // load template styles
        if (isset($styleini['stylesheets'][$mediatype])) {
            $files[$mediatype] = array_merge($files[$mediatype], $styleini['stylesheets'][$mediatype]);
        }
        // load user styles
        if (!empty($config_cascade['userstyle'][$mediatype])) {
            foreach ($config_cascade['userstyle'][$mediatype] as $userstyle) {
                $files[$mediatype][$userstyle] = DOKU_BASE;
            }
        }
        $cache_files = array_merge($cache_files, array_keys($files[$mediatype]));
    }
    // check cache age & handle conditional request
    // This may exit if a cache can be used
    http_cached($cache->cache, $cache->useCache(array('files' => $cache_files)));
    // start output buffering
    ob_start();
    // build the stylesheet
    foreach ($mediatypes as $mediatype) {
        // print the default classes for interwiki links and file downloads
        if ($mediatype == 'screen') {
            print '@media screen {';
            css_interwiki();
            css_filetypes();
            print '}';
        }
        // load files
        $css_content = '';
        foreach ($files[$mediatype] as $file => $location) {
            $display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
            $css_content .= "\n/* XXXXXXXXX {$display} XXXXXXXXX */\n";
            $css_content .= css_loadfile($file, $location);
        }
        switch ($mediatype) {
            case 'screen':
                print NL . '@media screen { /* START screen styles */' . NL . $css_content . NL . '} /* /@media END screen styles */' . NL;
                break;
            case 'print':
                print NL . '@media print { /* START print styles */' . NL . $css_content . NL . '} /* /@media END print styles */' . NL;
                break;
            case 'all':
            case 'feed':
            default:
                print NL . '/* START rest styles */ ' . NL . $css_content . NL . '/* END rest styles */' . NL;
                break;
        }
    }
    // end output buffering and get contents
    $css = ob_get_contents();
    ob_end_clean();
    // strip any source maps
    stripsourcemaps($css);
    // apply style replacements
    $css = css_applystyle($css, $styleini['replacements']);
    // parse less
    $css = css_parseless($css);
    // compress whitespace and comments
    if ($conf['compress']) {
        $css = css_compress($css);
    }
    // embed small images right into the stylesheet
    if ($conf['cssdatauri']) {
        $base = preg_quote(DOKU_BASE, '#');
        $css = preg_replace_callback('#(url\\([ \'"]*)(' . $base . ')(.*?(?:\\.(png|gif)))#i', 'css_datauri', $css);
    }
    http_cached_finish($cache->cache, $css);
}
Esempio n. 18
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function css_out()
{
    global $conf;
    global $lang;
    global $config_cascade;
    global $INPUT;
    if ($INPUT->str('s') == 'feed') {
        $mediatypes = array('feed');
        $type = 'feed';
    } else {
        $mediatypes = array('screen', 'all', 'print');
        $type = '';
    }
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $INPUT->str('t')));
    if ($tpl) {
        $tplinc = DOKU_INC . 'lib/tpl/' . $tpl . '/';
        $tpldir = DOKU_BASE . 'lib/tpl/' . $tpl . '/';
    } else {
        $tplinc = tpl_incdir();
        $tpldir = tpl_basedir();
    }
    // used style.ini file
    $styleini = css_styleini($tplinc);
    // The generated script depends on some dynamic options
    $cache = new cache('styles' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tplinc . $type, '.css');
    // load template styles
    $tplstyles = array();
    if ($styleini) {
        foreach ($styleini['stylesheets'] as $file => $mode) {
            $tplstyles[$mode][$tplinc . $file] = $tpldir;
        }
    }
    // if old 'default' userstyle setting exists, make it 'screen' userstyle for backwards compatibility
    if (isset($config_cascade['userstyle']['default'])) {
        $config_cascade['userstyle']['screen'] = $config_cascade['userstyle']['default'];
    }
    // Array of needed files and their web locations, the latter ones
    // are needed to fix relative paths in the stylesheets
    $files = array();
    $cache_files = getConfigFiles('main');
    $cache_files[] = $tplinc . 'style.ini';
    $cache_files[] = $tplinc . 'style.local.ini';
    $cache_files[] = __FILE__;
    foreach ($mediatypes as $mediatype) {
        $files[$mediatype] = array();
        // load core styles
        $files[$mediatype][DOKU_INC . 'lib/styles/' . $mediatype . '.css'] = DOKU_BASE . 'lib/styles/';
        // load jQuery-UI theme
        if ($mediatype == 'screen') {
            $files[$mediatype][DOKU_INC . 'lib/scripts/jquery/jquery-ui-theme/smoothness.css'] = DOKU_BASE . 'lib/scripts/jquery/jquery-ui-theme/';
        }
        // load plugin styles
        $files[$mediatype] = array_merge($files[$mediatype], css_pluginstyles($mediatype));
        // load template styles
        if (isset($tplstyles[$mediatype])) {
            $files[$mediatype] = array_merge($files[$mediatype], $tplstyles[$mediatype]);
        }
        // load user styles
        if (isset($config_cascade['userstyle'][$mediatype])) {
            $files[$mediatype][$config_cascade['userstyle'][$mediatype]] = DOKU_BASE;
        }
        // load rtl styles
        // note: this adds the rtl styles only to the 'screen' media type
        // @deprecated 2012-04-09: rtl will cease to be a mode of its own,
        //     please use "[dir=rtl]" in any css file in all, screen or print mode instead
        if ($mediatype == 'screen') {
            if ($lang['direction'] == 'rtl') {
                if (isset($tplstyles['rtl'])) {
                    $files[$mediatype] = array_merge($files[$mediatype], $tplstyles['rtl']);
                }
                if (isset($config_cascade['userstyle']['rtl'])) {
                    $files[$mediatype][$config_cascade['userstyle']['rtl']] = DOKU_BASE;
                }
            }
        }
        $cache_files = array_merge($cache_files, array_keys($files[$mediatype]));
    }
    // check cache age & handle conditional request
    // This may exit if a cache can be used
    http_cached($cache->cache, $cache->useCache(array('files' => $cache_files)));
    // start output buffering
    ob_start();
    // build the stylesheet
    foreach ($mediatypes as $mediatype) {
        // print the default classes for interwiki links and file downloads
        if ($mediatype == 'screen') {
            print '@media screen {';
            css_interwiki();
            css_filetypes();
            print '}';
        }
        // load files
        $css_content = '';
        foreach ($files[$mediatype] as $file => $location) {
            $css_content .= css_loadfile($file, $location);
        }
        switch ($mediatype) {
            case 'screen':
                print NL . '@media screen { /* START screen styles */' . NL . $css_content . NL . '} /* /@media END screen styles */' . NL;
                break;
            case 'print':
                print NL . '@media print { /* START print styles */' . NL . $css_content . NL . '} /* /@media END print styles */' . NL;
                break;
            case 'all':
            case 'feed':
            default:
                print NL . '/* START rest styles */ ' . NL . $css_content . NL . '/* END rest styles */' . NL;
                break;
        }
    }
    // end output buffering and get contents
    $css = ob_get_contents();
    ob_end_clean();
    // apply style replacements
    $css = css_applystyle($css, $tplinc);
    // place all @import statements at the top of the file
    $css = css_moveimports($css);
    // compress whitespace and comments
    if ($conf['compress']) {
        $css = css_compress($css);
    }
    // embed small images right into the stylesheet
    if ($conf['cssdatauri']) {
        $base = preg_quote(DOKU_BASE, '#');
        $css = preg_replace_callback('#(url\\([ \'"]*)(' . $base . ')(.*?(?:\\.(png|gif)))#i', 'css_datauri', $css);
    }
    http_cached_finish($cache->cache, $css);
}