/**
  * Handle matches of the <feedaggregator> tag, storing the list of feeds in
  * a file in the ~/data/tmp/feedaggregator directory.
  *
  * @param string $match The match of the syntax
  * @param int    $state The state of the handler
  * @param int    $pos The position in the document
  * @param Doku_Handler    $handler The handler
  * @return array Data for the renderer
  */
 public function handle($match, $state, $pos, Doku_Handler $handler)
 {
     global $conf;
     $data = array();
     // Are we to handle this match? If not, don't.
     if ($state !== DOKU_LEXER_UNMATCHED) {
         return $data;
     }
     // Get the feed URLs.
     $matchedFeeds = preg_split('/[\\n\\r]+/', $match, -1, PREG_SPLIT_NO_EMPTY);
     $feeds = array();
     foreach ($matchedFeeds as $feed) {
         if (filter_var($feed, FILTER_VALIDATE_URL) === false) {
             msg("Feed URL not valid: <code>{$feed}</code>", 2);
             continue;
         }
         $feeds[] = $feed;
     }
     $feedList = array_unique($feeds);
     // Save the feeds to a temporary CSV. It'll be ready by the action script.
     $file = fullpath($conf['tmpdir'] . '/feedaggregator.csv');
     file_put_contents($file, join("\n", $feedList));
     // Get the most-recently generated HTML feed aggregation. This won't be
     // up to date with the above feeds yet, but that's okay.
     $data['html'] = io_readFile(fullpath($conf['cachedir'] . '/feedaggregator/output.html'));
     return $data;
 }
 public function setWorkDir($directory)
 {
     $dir = addslash($this->userdir . trim($directory, DIRECTORY_SEPARATOR));
     $path_check = explode($this->userdir, addslash(fullpath($dir, $this->userdir)));
     if (count($path_check) < 2) {
         $dir = $this->userdir;
     }
     $this->workdir = $dir;
     return $dir;
 }
Example #3
0
 /**
  * Constructor
  *
  * Loads the cache
  */
 public function __construct()
 {
     global $conf;
     $this->logfile = fullpath($conf['metadir'] . '/' . $this->getConf('accesslog'));
     // file not found? assume absolute path
     if (!file_exists($this->logfile)) {
         $this->logfile = $this->getConf('accesslog');
     }
     // load the cache file
     $this->logcache = getCacheName($this->getConf('accesslog'), '.statdisplay');
     if (file_exists($this->logcache)) {
         $this->logdata = unserialize(io_readFile($this->logcache, false));
     }
 }
Example #4
0
 function test_windows_paths()
 {
     $base = $_SERVER['SCRIPT_FILENAME'];
     $_SERVER['SCRIPT_FILENAME'] = '/absolute/path/self.php';
     $GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS'] = true;
     // paths to check
     $tests = array('c:foo/bar/baz' => 'c:/foo/bar/baz', 'c:foo//bar/baz' => 'c:/foo/bar/baz', 'c:foo/../bar/baz' => 'c:/bar/baz', 'c:foo/./bar/baz' => 'c:/foo/bar/baz', 'c:foo/bar/..' => 'c:/foo', 'c:foo/bar/../../../baz' => 'c:/baz', 'c:/foo/bar/baz' => 'c:/foo/bar/baz', 'c:/foo//bar/baz' => 'c:/foo/bar/baz', 'c:/foo/../bar/baz' => 'c:/bar/baz', 'c:/foo/./bar/baz' => 'c:/foo/bar/baz', 'c:/foo/bar/..' => 'c:/foo', 'c:/foo/bar/../../../baz' => 'c:/baz', 'c:\\foo\\bar\\baz' => 'c:/foo/bar/baz', 'c:\\foo\\\\bar\\baz' => 'c:/foo/bar/baz', 'c:\\foo\\..\\bar\\baz' => 'c:/bar/baz', 'c:\\foo\\.\\bar\\baz' => 'c:/foo/bar/baz', 'c:\\foo\\bar\\..' => 'c:/foo', 'c:\\foo\\bar\\..\\..\\..\\baz' => 'c:/baz', '\\\\server\\share/foo/bar/baz' => '\\\\server\\share/foo/bar/baz', '\\\\server\\share/foo//bar/baz' => '\\\\server\\share/foo/bar/baz', '\\\\server\\share/foo/../bar/baz' => '\\\\server\\share/bar/baz', '\\\\server\\share/foo/./bar/baz' => '\\\\server\\share/foo/bar/baz', '\\\\server\\share/foo/bar/..' => '\\\\server\\share/foo', '\\\\server\\share/foo/bar/../../../baz' => '\\\\server\\share/baz');
     foreach ($tests as $from => $to) {
         $info = "Testing '{$from}' resulted in '" . fullpath($from) . "'";
         $this->assertEquals(fullpath($from), $to, $info);
     }
     $_SERVER['SCRIPT_FILENAME'] = $base;
     unset($GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS']);
 }
 /**
  * Load all the style sheets and apply the needed replacements
  * @param $plugin_name
  * @param $format
  * @param $template
  * @return string
  */
 public function load($plugin_name, $format, $template)
 {
     global $conf;
     //reusue the CSS dispatcher functions without triggering the main function
     define('SIMPLE_TEST', 1);
     require_once DOKU_INC . 'lib/exe/css.php';
     // Always only use small letters in format
     $format = strtolower($format);
     // prepare CSS files
     $files = array_merge(array(DOKU_INC . 'lib/styles/screen.css' => DOKU_BASE . 'lib/styles/', DOKU_INC . 'lib/styles/print.css' => DOKU_BASE . 'lib/styles/'), css_pluginstyles('all'), $this->css_pluginFormatStyles($format), array(DOKU_PLUGIN . $plugin_name . '/conf/style.css' => DOKU_BASE . 'lib/plugins/' . $plugin_name . '/conf/', DOKU_PLUGIN . $plugin_name . '/tpl/' . $template . '/style.css' => DOKU_BASE . 'lib/plugins/' . $plugin_name . '/tpl/' . $template . '/', DOKU_PLUGIN . $plugin_name . '/conf/style.local.css' => DOKU_BASE . 'lib/plugins/' . $plugin_name . '/conf/'));
     $css = '';
     foreach ($files as $file => $location) {
         $display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
         $css_content = "\n/* XXXXXXXXX {$display} XXXXXXXXX */\n";
         $css_content = css_loadfile($file, $location);
         if (strpos($file, 'screen.css') !== false) {
             $css .= "\n@media screen {\n" . $css_content . "\n}\n";
         } else {
             if (strpos($file, 'style.css') !== false) {
                 $css .= "\n@media screen {\n" . $css_content . "\n}\n";
             } else {
                 if (strpos($file, $format . '.css') !== false) {
                     $css .= "\n@media print {\n" . $css_content . "\n}\n";
                 } else {
                     if (strpos($file, 'print.css') !== false) {
                         $css .= "\n@media print {\n" . $css_content . "\n}\n";
                     } else {
                         $css .= $css_content;
                     }
                 }
             }
         }
     }
     if (function_exists('css_parseless')) {
         // apply pattern replacements
         $styleini = css_styleini($conf['template']);
         $css = css_applystyle($css, $styleini['replacements']);
         // parse less
         $css = css_parseless($css);
     } else {
         // @deprecated 2013-12-19: fix backward compatibility
         $css = css_applystyle($css, DOKU_INC . 'lib/tpl/' . $conf['template'] . '/');
     }
     return $css;
 }
 /**
  * 
  *
  * @param Doku_Event $event  Not used
  * @param mixed      $param  Not used
  * @return void
  */
 public function handle(Doku_Event &$event, $param)
 {
     global $conf;
     if ($event->data != 'feedaggregator') {
         return;
     }
     $event->preventDefault();
     // See if we need a token and whether it matches.
     $requiredToken = $this->getConf('token');
     $suppliedToken = isset($_GET['token']) ? $_GET['token'] : false;
     if (!empty($requiredToken) && $suppliedToken !== $requiredToken) {
         msg("Token doesn't match for feedaggregator");
         return true;
     }
     // Get the feed list.
     $feeds = file(fullpath($conf['tmpdir'] . '/feedaggregator.csv'));
     // Set up SimplePie and merge all the feeds together.
     $simplepie = new FeedParser();
     $ua = 'Mozilla/4.0 (compatible; DokuWiki feedaggregator plugin ' . wl('', '', true) . ')';
     $simplepie->set_useragent($ua);
     $simplepie->force_feed($this->getConf('force_feed'));
     $simplepie->force_fsockopen($this->getConf('force_fsockopen'));
     $simplepie->set_feed_url($feeds);
     // Set up caching.
     $cacheDir = fullpath($conf['cachedir'] . '/feedaggregator');
     io_mkdir_p($cacheDir);
     $simplepie->enable_cache();
     $simplepie->set_cache_location($cacheDir);
     // Run the actual feed aggregation.
     $simplepie->init();
     // Check for errors.
     if ($simplepie->error()) {
         header("Content-type:text/plain");
         echo join("\n", $simplepie->error());
     }
     // Create the output HTML and cache it for use by the syntax component.
     $html = '';
     foreach ($simplepie->get_items() as $item) {
         $html .= "<div class='feedaggregator_item'>\n" . "<h2>" . $item->get_title() . "</h2>\n" . $item->get_content() . "\n" . "<p>" . "  <a href='" . $item->get_permalink() . "'>Published " . $item->get_date('j M Y') . "</a> " . "  in <a href='" . $item->get_feed()->get_permalink() . "'>" . $item->get_feed()->get_title() . "</a>" . "</p>\n" . "</div>\n\n";
     }
     io_saveFile($cacheDir . '/output.html', $html);
     // Output nothing, as this should be run from cron and we don't want to
     // flood the logs with success.
     exit(0);
 }
Example #7
0
/**
 * Let the webserver send the given file via x-sendfile method
 *
 * @author Chris Smith <*****@*****.**>
 *
 * @param string $file absolute path of file to send
 * @returns  void or exits with previous header() commands executed
 */
function http_sendfile($file)
{
    global $conf;
    //use x-sendfile header to pass the delivery to compatible web servers
    if ($conf['xsendfile'] == 1) {
        header("X-LIGHTTPD-send-file: {$file}");
        ob_end_clean();
        exit;
    } elseif ($conf['xsendfile'] == 2) {
        header("X-Sendfile: {$file}");
        ob_end_clean();
        exit;
    } elseif ($conf['xsendfile'] == 3) {
        // FS#2388 nginx just needs the relative path.
        $file = DOKU_REL . substr($file, strlen(fullpath(DOKU_INC)) + 1);
        header("X-Accel-Redirect: {$file}");
        ob_end_clean();
        exit;
    }
}
 public function addFile($file, $duration, $password)
 {
     $torrentfile = explode('|', $file);
     if (count($torrentfile) > 1) {
         $file = array($torrentfile[1], $torrentfile[0]);
     }
     if (is_array($file)) {
         $file = \Flm\Helper::getTorrentHashFilepath($file[0], $file[1]);
     } else {
         $file = fullpath(trim($file, DIRECTORY_SEPARATOR), $this->userdir);
     }
     $this->validDuration($duration);
     $share = Storage::load();
     if ($this->islimited('links', $share->size())) {
         throw new Exception("File limit reached " . $share->size(), 2);
     }
     if (($stat = LFS::stat($file)) === FALSE) {
         throw new Exception("Invalid file " . $file, 2);
     }
     $data = array('path' => $file, 'size' => $stat['size'], 'expire' => time() + 3600 * $duration, 'password' => $password);
     return $share->add($data);
 }
Example #9
0
/**
 * A realpath() replacement
 *
 * This function behaves similar to PHP's realpath() but does not resolve
 * symlinks or accesses upper directories
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author <richpageau at yahoo dot co dot uk>
 * @link   http://de3.php.net/manual/en/function.realpath.php#75992
 */
function fullpath($path, $exists = false)
{
    static $run = 0;
    $root = '';
    $iswin = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' || @$GLOBALS['DOKU_UNITTEST_ASSUME_WINDOWS'];
    // find the (indestructable) root of the path - keeps windows stuff intact
    if ($path[0] == '/') {
        $root = '/';
    } elseif ($iswin) {
        // match drive letter and UNC paths
        if (preg_match('!^([a-zA-z]:)(.*)!', $path, $match)) {
            $root = $match[1] . '/';
            $path = $match[2];
        } else {
            if (preg_match('!^(\\\\\\\\[^\\\\/]+\\\\[^\\\\/]+[\\\\/])(.*)!', $path, $match)) {
                $root = $match[1];
                $path = $match[2];
            }
        }
    }
    $path = str_replace('\\', '/', $path);
    // if the given path wasn't absolute already, prepend the script path and retry
    if (!$root) {
        $base = dirname($_SERVER['SCRIPT_FILENAME']);
        $path = $base . '/' . $path;
        if ($run == 0) {
            // avoid endless recursion when base isn't absolute for some reason
            $run++;
            return fullpath($path, $exists);
        }
    }
    $run = 0;
    // canonicalize
    $path = explode('/', $path);
    $newpath = array();
    foreach ($path as $p) {
        if ($p === '' || $p === '.') {
            continue;
        }
        if ($p === '..') {
            array_pop($newpath);
            continue;
        }
        array_push($newpath, $p);
    }
    $finalpath = $root . implode('/', $newpath);
    // check for existance when needed (except when unit testing)
    if ($exists && !defined('DOKU_UNITTEST') && !@file_exists($finalpath)) {
        return false;
    }
    return $finalpath;
}
Example #10
0
/**
 * Return info about the current document as associative
 * array.
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function pageinfo()
{
    global $ID;
    global $REV;
    global $RANGE;
    global $USERINFO;
    global $lang;
    // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml
    // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary
    $info['id'] = $ID;
    $info['rev'] = $REV;
    // set info about manager/admin status.
    $info['isadmin'] = false;
    $info['ismanager'] = false;
    if (isset($_SERVER['REMOTE_USER'])) {
        $info['userinfo'] = $USERINFO;
        $info['perm'] = auth_quickaclcheck($ID);
        $info['subscribed'] = get_info_subscribed();
        $info['client'] = $_SERVER['REMOTE_USER'];
        if ($info['perm'] == AUTH_ADMIN) {
            $info['isadmin'] = true;
            $info['ismanager'] = true;
        } elseif (auth_ismanager()) {
            $info['ismanager'] = true;
        }
        // if some outside auth were used only REMOTE_USER is set
        if (!$info['userinfo']['name']) {
            $info['userinfo']['name'] = $_SERVER['REMOTE_USER'];
        }
    } else {
        $info['perm'] = auth_aclcheck($ID, '', null);
        $info['subscribed'] = false;
        $info['client'] = clientIP(true);
    }
    $info['namespace'] = getNS($ID);
    $info['locked'] = checklock($ID);
    $info['filepath'] = fullpath(wikiFN($ID));
    $info['exists'] = @file_exists($info['filepath']);
    if ($REV) {
        //check if current revision was meant
        if ($info['exists'] && @filemtime($info['filepath']) == $REV) {
            $REV = '';
        } elseif ($RANGE) {
            //section editing does not work with old revisions!
            $REV = '';
            $RANGE = '';
            msg($lang['nosecedit'], 0);
        } else {
            //really use old revision
            $info['filepath'] = fullpath(wikiFN($ID, $REV));
            $info['exists'] = @file_exists($info['filepath']);
        }
    }
    $info['rev'] = $REV;
    if ($info['exists']) {
        $info['writable'] = is_writable($info['filepath']) && $info['perm'] >= AUTH_EDIT;
    } else {
        $info['writable'] = $info['perm'] >= AUTH_CREATE;
    }
    $info['editable'] = $info['writable'] && empty($info['locked']);
    $info['lastmod'] = @filemtime($info['filepath']);
    //load page meta data
    $info['meta'] = p_get_metadata($ID);
    //who's the editor
    if ($REV) {
        $revinfo = getRevisionInfo($ID, $REV, 1024);
    } else {
        if (is_array($info['meta']['last_change'])) {
            $revinfo = $info['meta']['last_change'];
        } else {
            $revinfo = getRevisionInfo($ID, $info['lastmod'], 1024);
            // cache most recent changelog line in metadata if missing and still valid
            if ($revinfo !== false) {
                $info['meta']['last_change'] = $revinfo;
                p_set_metadata($ID, array('last_change' => $revinfo));
            }
        }
    }
    //and check for an external edit
    if ($revinfo !== false && $revinfo['date'] != $info['lastmod']) {
        // cached changelog line no longer valid
        $revinfo = false;
        $info['meta']['last_change'] = $revinfo;
        p_set_metadata($ID, array('last_change' => $revinfo));
    }
    $info['ip'] = $revinfo['ip'];
    $info['user'] = $revinfo['user'];
    $info['sum'] = $revinfo['sum'];
    // See also $INFO['meta']['last_change'] which is the most recent log line for page $ID.
    // Use $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT in place of $info['minor'].
    if ($revinfo['user']) {
        $info['editor'] = $revinfo['user'];
    } else {
        $info['editor'] = $revinfo['ip'];
    }
    // draft
    $draft = getCacheName($info['client'] . $ID, '.draft');
    if (@file_exists($draft)) {
        if (@filemtime($draft) < @filemtime(wikiFN($ID))) {
            // remove stale draft
            @unlink($draft);
        } else {
            $info['draft'] = $draft;
        }
    }
    // mobile detection
    $info['ismobile'] = clientismobile();
    return $info;
}
/**
 * Creates a directory hierachy.
 *
 * @link    http://www.php.net/manual/en/function.mkdir.php
 * @author  <*****@*****.**>
 * @author  Andreas Gohr <*****@*****.**>
 */
function io_mkdir_p($target)
{
    global $conf;
    if (@is_dir($target) || empty($target)) {
        return 1;
    }
    // best case check first
    if (@file_exists($target) && !is_dir($target)) {
        return 0;
    }
    //recursion
    if (io_mkdir_p(substr($target, 0, strrpos($target, '/')))) {
        if ($conf['safemodehack']) {
            $dir = preg_replace('/^' . preg_quote(fullpath($conf['ftp']['root']), '/') . '/', '', $target);
            return io_mkdir_ftp($dir);
        } else {
            $ret = @mkdir($target, $conf['dmode']);
            // crawl back up & create dir tree
            if ($ret && !empty($conf['dperm'])) {
                chmod($target, $conf['dperm']);
            }
            return $ret;
        }
    }
    return 0;
}
Example #12
0
/**
 * Return info about the current document as associative
 * array.
 *
 * @author Andreas Gohr <*****@*****.**>
 *
 * @return array with info about current document
 */
function pageinfo()
{
    global $ID;
    global $REV;
    global $RANGE;
    global $lang;
    /* @var Input $INPUT */
    global $INPUT;
    $info = basicinfo($ID);
    // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml
    // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary
    $info['id'] = $ID;
    $info['rev'] = $REV;
    if ($INPUT->server->has('REMOTE_USER')) {
        $sub = new Subscription();
        $info['subscribed'] = $sub->user_subscription();
    } else {
        $info['subscribed'] = false;
    }
    $info['locked'] = checklock($ID);
    $info['filepath'] = fullpath(wikiFN($ID));
    $info['exists'] = file_exists($info['filepath']);
    $info['currentrev'] = @filemtime($info['filepath']);
    if ($REV) {
        //check if current revision was meant
        if ($info['exists'] && $info['currentrev'] == $REV) {
            $REV = '';
        } elseif ($RANGE) {
            //section editing does not work with old revisions!
            $REV = '';
            $RANGE = '';
            msg($lang['nosecedit'], 0);
        } else {
            //really use old revision
            $info['filepath'] = fullpath(wikiFN($ID, $REV));
            $info['exists'] = file_exists($info['filepath']);
        }
    }
    $info['rev'] = $REV;
    if ($info['exists']) {
        $info['writable'] = is_writable($info['filepath']) && $info['perm'] >= AUTH_EDIT;
    } else {
        $info['writable'] = $info['perm'] >= AUTH_CREATE;
    }
    $info['editable'] = $info['writable'] && empty($info['locked']);
    $info['lastmod'] = @filemtime($info['filepath']);
    //load page meta data
    $info['meta'] = p_get_metadata($ID);
    //who's the editor
    $pagelog = new PageChangeLog($ID, 1024);
    if ($REV) {
        $revinfo = $pagelog->getRevisionInfo($REV);
    } else {
        if (!empty($info['meta']['last_change']) && is_array($info['meta']['last_change'])) {
            $revinfo = $info['meta']['last_change'];
        } else {
            $revinfo = $pagelog->getRevisionInfo($info['lastmod']);
            // cache most recent changelog line in metadata if missing and still valid
            if ($revinfo !== false) {
                $info['meta']['last_change'] = $revinfo;
                p_set_metadata($ID, array('last_change' => $revinfo));
            }
        }
    }
    //and check for an external edit
    if ($revinfo !== false && $revinfo['date'] != $info['lastmod']) {
        // cached changelog line no longer valid
        $revinfo = false;
        $info['meta']['last_change'] = $revinfo;
        p_set_metadata($ID, array('last_change' => $revinfo));
    }
    $info['ip'] = $revinfo['ip'];
    $info['user'] = $revinfo['user'];
    $info['sum'] = $revinfo['sum'];
    // See also $INFO['meta']['last_change'] which is the most recent log line for page $ID.
    // Use $INFO['meta']['last_change']['type']===DOKU_CHANGE_TYPE_MINOR_EDIT in place of $info['minor'].
    if ($revinfo['user']) {
        $info['editor'] = $revinfo['user'];
    } else {
        $info['editor'] = $revinfo['ip'];
    }
    // draft
    $draft = getCacheName($info['client'] . $ID, '.draft');
    if (file_exists($draft)) {
        if (@filemtime($draft) < @filemtime(wikiFN($ID))) {
            // remove stale draft
            @unlink($draft);
        } else {
            $info['draft'] = $draft;
        }
    }
    return $info;
}
Example #13
0
/**
 * Output all needed Styles
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function epub_css_out($path)
{
    global $conf;
    global $lang;
    global $config_cascade;
    global $INPUT;
    $mediatypes = array('screen', 'all');
    $type = '';
    // decide from where to get the template
    $tpl = trim(preg_replace('/[^\\w-]+/', '', $INPUT->str('t')));
    if (!$tpl) {
        $tpl = $conf['template'];
    }
    // load styl.ini
    $styleini = css_styleini($tpl);
    // 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();
    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 (isset($config_cascade['userstyle'][$mediatype])) {
            $files[$mediatype][$config_cascade['userstyle'][$mediatype]] = DOKU_BASE;
        }
    }
    $css = "";
    // build the stylesheet
    foreach ($mediatypes as $mediatype) {
        // print the default classes for interwiki links and file downloads
        if ($mediatype == 'screen') {
            $css .= '@media screen {';
            css_interwiki($css);
            css_filetypes($css);
            $css .= '}';
        }
        // 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':
                $css .= NL . '@media screen { /* START screen styles */' . NL . $css_content . NL . '} /* /@media END screen styles */' . NL;
                break;
            case 'all':
            default:
                $css .= NL . '/* START rest styles */ ' . NL . $css_content . NL . '/* END rest styles */' . NL;
                break;
        }
    }
    // apply style replacements
    $css .= css_applystyle($css, $styleini['replacements']);
    // parse less
    $css = css_parseless($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);
    }
    io_saveFile($path . 'Styles/style.css', $css);
}
Example #14
0
<?php

/**
 * Editing toolbar functions
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Andreas Gohr <*****@*****.**>
 */
if (!defined('DOKU_INC')) {
    define('DOKU_INC', fullpath(dirname(__FILE__) . '/../') . '/');
}
require_once DOKU_INC . 'inc/JSON.php';
/**
 * Prepares and prints an JavaScript array with all toolbar buttons
 *
 * @todo add toolbar plugins
 * @param  string $varname Name of the JS variable to fill
 * @author Andreas Gohr <*****@*****.**>
 */
function toolbar_JSdefines($varname)
{
    global $ID;
    global $conf;
    global $lang;
    $menu = array();
    $evt = new Doku_Event('TOOLBAR_DEFINE', $menu);
    if ($evt->advise_before()) {
        // build button array
        $menu = array_merge($menu, array(array('type' => 'format', 'title' => $lang['qb_bold'], 'icon' => 'bold.png', 'key' => 'b', 'open' => '**', 'close' => '**'), array('type' => 'format', 'title' => $lang['qb_italic'], 'icon' => 'italic.png', 'key' => 'i', 'open' => '//', 'close' => '//'), array('type' => 'format', 'title' => $lang['qb_underl'], 'icon' => 'underline.png', 'key' => 'u', 'open' => '__', 'close' => '__'), array('type' => 'format', 'title' => $lang['qb_code'], 'icon' => 'mono.png', 'key' => 'c', 'open' => "''", 'close' => "''"), array('type' => 'format', 'title' => $lang['qb_strike'], 'icon' => 'strike.png', 'key' => 'd', 'open' => '<del>', 'close' => '</del>'), array('type' => 'format', 'title' => $lang['qb_h1'], 'icon' => 'h1.png', 'key' => '1', 'open' => '====== ', 'close' => ' ======\\n'), array('type' => 'format', 'title' => $lang['qb_h2'], 'icon' => 'h2.png', 'key' => '2', 'open' => '===== ', 'close' => ' =====\\n'), array('type' => 'format', 'title' => $lang['qb_h3'], 'icon' => 'h3.png', 'key' => '3', 'open' => '==== ', 'close' => ' ====\\n'), array('type' => 'format', 'title' => $lang['qb_h4'], 'icon' => 'h4.png', 'key' => '4', 'open' => '=== ', 'close' => ' ===\\n'), array('type' => 'format', 'title' => $lang['qb_h5'], 'icon' => 'h5.png', 'key' => '5', 'open' => '== ', 'close' => ' ==\\n'), array('type' => 'format', 'title' => $lang['qb_link'], 'icon' => 'link.png', 'key' => 'l', 'open' => '[[', 'close' => ']]'), array('type' => 'format', 'title' => $lang['qb_extlink'], 'icon' => 'linkextern.png', 'open' => '[[', 'close' => ']]', 'sample' => 'http://example.com|' . $lang['qb_extlink']), array('type' => 'format', 'title' => $lang['qb_ol'], 'icon' => 'ol.png', 'open' => '  - ', 'close' => '\\n'), array('type' => 'format', 'title' => $lang['qb_ul'], 'icon' => 'ul.png', 'open' => '  * ', 'close' => '\\n'), array('type' => 'insert', 'title' => $lang['qb_hr'], 'icon' => 'hr.png', 'insert' => '----\\n'), array('type' => 'mediapopup', 'title' => $lang['qb_media'], 'icon' => 'image.png', 'url' => DOKU_BASE . 'lib/exe/mediamanager.php?ns=', 'name' => 'mediaselect', 'options' => 'width=750,height=500,left=20,top=20,scrollbars=yes,resizable=yes'), array('type' => 'picker', 'title' => $lang['qb_smileys'], 'icon' => 'smiley.png', 'list' => getSmileys(), 'icobase' => 'smileys'), array('type' => 'picker', 'title' => $lang['qb_chars'], 'icon' => 'chars.png', 'list' => explode(' ', 'À à Á á  â à ã Ä ä Ǎ ǎ Ă ă Å å Ā ā Ą ą Æ æ Ć ć Ç ç Č č Ĉ ĉ Ċ ċ Ð đ ð Ď ď È è É é Ê ê Ë ë Ě ě Ē ē Ė ė Ę ę Ģ ģ Ĝ ĝ Ğ ğ Ġ ġ Ĥ ĥ Ì ì Í í Î î Ï ï Ǐ ǐ Ī ī İ ı Į į Ĵ ĵ Ķ ķ Ĺ ĺ Ļ ļ Ľ ľ Ł ł Ŀ ŀ Ń ń Ñ ñ Ņ ņ Ň ň Ò ò Ó ó Ô ô Õ õ Ö ö Ǒ ǒ Ō ō Ő ő Œ œ Ø ø Ŕ ŕ Ŗ ŗ Ř ř Ś ś Ş ş Š š Ŝ ŝ Ţ ţ Ť ť Ù ù Ú ú Û û Ü ü Ǔ ǔ Ŭ ŭ Ū ū Ů ů ǖ ǘ ǚ ǜ Ų ų Ű ű Ŵ ŵ Ý ý Ÿ ÿ Ŷ ŷ Ź ź Ž ž Ż ż Þ þ ß Ħ ħ ¿ ¡ ¢ £ ¤ ¥ € ¦ § ª ¬ ¯ ° ± ÷ ‰ ¼ ½ ¾ ¹ ² ³ µ ¶ † ‡ · • º ∀ ∂ ∃ Ə ə ∅ ∇ ∈ ∉ ∋ ∏ ∑ ‾ − ∗ √ ∝ ∞ ∠ ∧ ∨ ∩ ∪ ∫ ∴ ∼ ≅ ≈ ≠ ≡ ≤ ≥ ⊂ ⊃ ⊄ ⊆ ⊇ ⊕ ⊗ ⊥ ⋅ ◊ ℘ ℑ ℜ ℵ ♠ ♣ ♥ ♦ α β Γ γ Δ δ ε ζ η Θ θ ι κ Λ λ μ Ξ ξ Π π ρ Σ σ Τ τ υ Φ φ χ Ψ ψ Ω ω ★ ☆ ☎ ☚ ☛ ☜ ☝ ☞ ☟ ☹ ☺ ✔ ✘ × „ “ ” ‚ ‘ ’ « » ‹ › — – … ← ↑ → ↓ ↔ ⇐ ⇑ ⇒ ⇓ ⇔ © ™ ® ′ ″')), array('type' => 'signature', 'title' => $lang['qb_sig'], 'icon' => 'sig.png', 'key' => 'y')));
    }
    // end event TOOLBAR_DEFINE default action
Example #15
0
    }
}
if (!$dh) {
    $curFile = null;
    $dir = isLocalMode() ? $theSettings->directory : $topDirectory;
    if (strpos(addslash($dir), $topDirectory) !== 0) {
        $dir = $topDirectory;
    }
    $dh = @opendir($dir);
}
$files = array();
$dirs = array();
if ($dh) {
    $dir = addslash($dir);
    while (false !== ($file = readdir($dh))) {
        $path = fullpath($dir . $file);
        if ($file == ".." && $dir == $topDirectory) {
            continue;
        }
        if (is_dir($path) && is_readable($path) && strpos(addslash($path), $topDirectory) === 0 && ($theSettings->uid < 0 || isUserHavePermission($theSettings->uid, $theSettings->gid, $path, 0x5))) {
            $dirs['/' . $file] = $path;
        } else {
            if (LFS::is_file($path) && is_readable($path) && ($theSettings->uid < 0 || isUserHavePermission($theSettings->uid, $theSettings->gid, $path, 0x4))) {
                $files[$file] = $path;
            }
        }
    }
    closedir($dh);
    ksort($files, SORT_STRING);
    ksort($dirs, SORT_STRING);
    $files = array_merge($dirs, $files);
Example #16
0
/**
 * Returns absolute path
 *
 * This tries the given path first, then checks in DOKU_INC.
 * Check for accessability on directories as well.
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function init_path($path)
{
    // check existance
    $p = fullpath($path);
    if (!@file_exists($p)) {
        $p = fullpath(DOKU_INC . $path);
        if (!@file_exists($p)) {
            return '';
        }
    }
    // check writability
    if (!@is_writable($p)) {
        return '';
    }
    // check accessability (execute bit) for directories
    if (@is_dir($p) && !@file_exists("{$p}/.")) {
        return '';
    }
    return $p;
}
Example #17
0
     }
     if ($dh) {
         $files = array();
         $dir = addslash($dir);
         while (false !== ($file = readdir($dh))) {
             $path = fullpath($dir . $file);
             if ($file == ".." && $dir == $topDirectory) {
                 continue;
             }
             if (is_dir($path) && is_readable($path) && strpos(addslash($path), $topDirectory) === 0 && ($theSettings->uid < 0 || isUserHavePermission($theSettings->uid, $theSettings->gid, $path, 0x7))) {
                 $files[] = $file;
             }
         }
         closedir($dh);
         sort($files, SORT_STRING);
         $output["basedir"] = fullpath($dir);
         $output["dirlist"] = $files;
     }
 }
 if (in_array("channels", $modes) && $theSettings->isPluginRegistered('throttle')) {
     require_once '../throttle/throttle.php';
     $trt = rThrottle::load();
     $tnames = array();
     foreach ($trt->thr as $thr) {
         $tnames[] = $thr["name"];
     }
     $output["channels"] = $tnames;
 }
 if (in_array("ratios", $modes) && $theSettings->isPluginRegistered('ratio')) {
     require_once '../ratio/ratio.php';
     $rat = rRatio::load();
/**
 * Print some info about the current page
 *
 * @author  Andreas Gohr <*****@*****.**>
 * @author  Giuseppe Di Terlizzi <*****@*****.**>
 *
 * @param   bool $ret return content instead of printing it
 * @return  bool|string
 */
function bootstrap3_pageinfo($ret = false)
{
    global $conf;
    global $lang;
    global $INFO;
    global $ID;
    // return if we are not allowed to view the page
    if (!auth_quickaclcheck($ID)) {
        return false;
    }
    // prepare date and path
    $fn = $INFO['filepath'];
    if (!$conf['fullpath']) {
        if ($INFO['rev']) {
            $fn = str_replace(fullpath($conf['olddir']) . '/', '', $fn);
        } else {
            $fn = str_replace(fullpath($conf['datadir']) . '/', '', $fn);
        }
    }
    $date_format = bootstrap3_conf('pageInfoDateFormat');
    $page_info = bootstrap3_conf('pageInfo');
    $fn = utf8_decodeFN($fn);
    $date = $date_format == 'dformat' ? dformat($INFO['lastmod']) : datetime_h($INFO['lastmod']);
    // print it
    if ($INFO['exists']) {
        $fn_full = $fn;
        if (!in_array('extension', $page_info)) {
            $fn = str_replace(array('.txt.gz', '.txt'), '', $fn);
        }
        $out = '<ul class="list-inline">';
        if (in_array('filename', $page_info)) {
            $out .= sprintf('<li><i class="fa fa-fw fa-file-text-o text-muted"></i> <span title="%s">%s</span></li>', $fn_full, $fn);
        }
        if (in_array('date', $page_info)) {
            $out .= sprintf('<li><i class="fa fa-fw fa-calendar text-muted"></i> %s <span title="%s">%s</span></li>', $lang['lastmod'], dformat($INFO['lastmod']), $date);
        }
        if (in_array('editor', $page_info)) {
            if (isset($INFO['editor'])) {
                $user = editorinfo($INFO['editor']);
                if (bootstrap3_conf('useGravatar')) {
                    global $auth;
                    $user_data = $auth->getUserData($INFO['editor']);
                    $HTTP = new DokuHTTPClient();
                    $gravatar_img = get_gravatar($user_data['mail'], 16);
                    $gravatar_check = $HTTP->get($gravatar_img . '&d=404');
                    if ($gravatar_check) {
                        $user_img = sprintf('<img src="%s" alt="" width="16" class="img-rounded" /> ', $gravatar_img);
                        $user = str_replace(array('iw_user', 'interwiki'), '', $user);
                        $user = $user_img . $user;
                    }
                }
                $out .= sprintf('<li class="text-muted">%s %s</li>', $lang['by'], $user);
            } else {
                $out .= sprintf('<li>(%s)</li>', $lang['external_edit']);
            }
        }
        if ($INFO['locked'] && in_array('locked', $page_info)) {
            $out .= sprintf('<li><i class="fa fa-fw fa-lock text-muted"></i> %s %s</li>', $lang['lockedby'], editorinfo($INFO['locked']));
        }
        $out .= '</ul>';
        if ($ret) {
            return $out;
        } else {
            echo $out;
            return true;
        }
    }
    return false;
}
Example #19
0
 public function obtain($dir = '../plugins/extsearch/engines')
 {
     $oldEngines = $this->engines;
     $this->engines = array();
     if ($handle = opendir($dir)) {
         while (false !== ($file = readdir($handle))) {
             if (is_file($dir . '/' . $file)) {
                 $name = basename($file, ".php");
                 $this->engines[$name] = array("name" => $name, "path" => fullpath($dir . '/' . $file), "object" => $name . "Engine", "enabled" => true, "global" => true, "limit" => 100);
                 $obj = $this->getObject($name);
                 $this->engines[$name]["enabled"] = intval($obj->defaults["public"]);
                 $this->engines[$name]["public"] = intval($obj->defaults["public"]);
                 $this->engines[$name]["limit"] = $obj->defaults["page_size"];
                 $this->engines[$name]["cats"] = $obj->categories;
                 $this->engines[$name]["cookies"] = array_key_exists("cookies", $obj->defaults) ? $obj->defaults["cookies"] : '';
                 $this->engines[$name]["auth"] = array_key_exists("auth", $obj->defaults) ? 1 : 0;
                 if (array_key_exists("disabled", $obj->defaults) && $obj->defaults["disabled"]) {
                     $this->engines[$name]["enabled"] = 0;
                 }
                 if (array_key_exists($name, $oldEngines) && array_key_exists("limit", $oldEngines[$name])) {
                     $this->engines[$name]["enabled"] = intval($oldEngines[$name]["enabled"]);
                     $this->engines[$name]["global"] = intval($oldEngines[$name]["global"]);
                     $this->engines[$name]["limit"] = intval($oldEngines[$name]["limit"]);
                 }
                 if (!rTorrentSettings::get()->isPluginRegistered('cookies') && $this->engines[$name]["enabled"] && !empty($this->engines[$name]["cookies"])) {
                     $this->engines[$name]["enabled"] = 0;
                 }
                 if (!rTorrentSettings::get()->isPluginRegistered('loginmgr') && $this->engines[$name]["enabled"] && $this->engines[$name]["auth"]) {
                     $this->engines[$name]["enabled"] = 0;
                 }
             }
         }
         closedir($handle);
     }
     ksort($this->engines);
     $this->store();
 }
Example #20
0
 /**
  * Load all the style sheets and apply the needed replacements
  */
 protected function load_css()
 {
     global $conf;
     //reusue the CSS dispatcher functions without triggering the main function
     define('SIMPLE_TEST', 1);
     require_once DOKU_INC . 'lib/exe/css.php';
     // prepare CSS files
     $files = array_merge(array(DOKU_INC . 'lib/styles/screen.css' => DOKU_BASE . 'lib/styles/', DOKU_INC . 'lib/styles/print.css' => DOKU_BASE . 'lib/styles/'), css_pluginstyles('all'), $this->css_pluginPDFstyles(), array(DOKU_PLUGIN . 'dw2pdf/conf/style.css' => DOKU_BASE . 'lib/plugins/dw2pdf/conf/', DOKU_PLUGIN . 'dw2pdf/tpl/' . $this->tpl . '/style.css' => DOKU_BASE . 'lib/plugins/dw2pdf/tpl/' . $this->tpl . '/', DOKU_PLUGIN . 'dw2pdf/conf/style.local.css' => DOKU_BASE . 'lib/plugins/dw2pdf/conf/'));
     $css = '';
     foreach ($files as $file => $location) {
         $display = str_replace(fullpath(DOKU_INC), '', fullpath($file));
         $css .= "\n/* XXXXXXXXX {$display} XXXXXXXXX */\n";
         $css .= css_loadfile($file, $location);
     }
     if (function_exists('css_parseless')) {
         // apply pattern replacements
         $styleini = css_styleini($conf['template']);
         $css = css_applystyle($css, $styleini['replacements']);
         // parse less
         $css = css_parseless($css);
     } else {
         // @deprecated 2013-12-19: fix backward compatibility
         $css = css_applystyle($css, DOKU_INC . 'lib/tpl/' . $conf['template'] . '/');
     }
     return $css;
 }
Example #21
0
 /**
  * Gets basic info from the file - should work with non-JPEGs
  *
  * @author  Sebastian Delmont <*****@*****.**>
  * @author  Andreas Gohr <*****@*****.**>
  */
 function _parseFileInfo()
 {
     if (file_exists($this->_fileName)) {
         $this->_info['file'] = array();
         $this->_info['file']['Name'] = basename($this->_fileName);
         $this->_info['file']['Path'] = fullpath($this->_fileName);
         $this->_info['file']['Size'] = filesize($this->_fileName);
         if ($this->_info['file']['Size'] < 1024) {
             $this->_info['file']['NiceSize'] = $this->_info['file']['Size'] . 'B';
         } elseif ($this->_info['file']['Size'] < 1024 * 1024) {
             $this->_info['file']['NiceSize'] = round($this->_info['file']['Size'] / 1024) . 'KB';
         } elseif ($this->_info['file']['Size'] < 1024 * 1024 * 1024) {
             $this->_info['file']['NiceSize'] = round($this->_info['file']['Size'] / (1024 * 1024)) . 'MB';
         } else {
             $this->_info['file']['NiceSize'] = $this->_info['file']['Size'] . 'B';
         }
         $this->_info['file']['UnixTime'] = filemtime($this->_fileName);
         // get image size directly from file
         $size = getimagesize($this->_fileName);
         $this->_info['file']['Width'] = $size[0];
         $this->_info['file']['Height'] = $size[1];
         // set mime types and formats
         // http://www.php.net/manual/en/function.getimagesize.php
         // http://www.php.net/manual/en/function.image-type-to-mime-type.php
         switch ($size[2]) {
             case 1:
                 $this->_info['file']['Mime'] = 'image/gif';
                 $this->_info['file']['Format'] = 'GIF';
                 break;
             case 2:
                 $this->_info['file']['Mime'] = 'image/jpeg';
                 $this->_info['file']['Format'] = 'JPEG';
                 break;
             case 3:
                 $this->_info['file']['Mime'] = 'image/png';
                 $this->_info['file']['Format'] = 'PNG';
                 break;
             case 4:
                 $this->_info['file']['Mime'] = 'application/x-shockwave-flash';
                 $this->_info['file']['Format'] = 'SWF';
                 break;
             case 5:
                 $this->_info['file']['Mime'] = 'image/psd';
                 $this->_info['file']['Format'] = 'PSD';
                 break;
             case 6:
                 $this->_info['file']['Mime'] = 'image/bmp';
                 $this->_info['file']['Format'] = 'BMP';
                 break;
             case 7:
                 $this->_info['file']['Mime'] = 'image/tiff';
                 $this->_info['file']['Format'] = 'TIFF (Intel)';
                 break;
             case 8:
                 $this->_info['file']['Mime'] = 'image/tiff';
                 $this->_info['file']['Format'] = 'TIFF (Motorola)';
                 break;
             case 9:
                 $this->_info['file']['Mime'] = 'application/octet-stream';
                 $this->_info['file']['Format'] = 'JPC';
                 break;
             case 10:
                 $this->_info['file']['Mime'] = 'image/jp2';
                 $this->_info['file']['Format'] = 'JP2';
                 break;
             case 11:
                 $this->_info['file']['Mime'] = 'application/octet-stream';
                 $this->_info['file']['Format'] = 'JPX';
                 break;
             case 12:
                 $this->_info['file']['Mime'] = 'application/octet-stream';
                 $this->_info['file']['Format'] = 'JB2';
                 break;
             case 13:
                 $this->_info['file']['Mime'] = 'application/x-shockwave-flash';
                 $this->_info['file']['Format'] = 'SWC';
                 break;
             case 14:
                 $this->_info['file']['Mime'] = 'image/iff';
                 $this->_info['file']['Format'] = 'IFF';
                 break;
             case 15:
                 $this->_info['file']['Mime'] = 'image/vnd.wap.wbmp';
                 $this->_info['file']['Format'] = 'WBMP';
                 break;
             case 16:
                 $this->_info['file']['Mime'] = 'image/xbm';
                 $this->_info['file']['Format'] = 'XBM';
                 break;
             default:
                 $this->_info['file']['Mime'] = 'image/unknown';
         }
     } else {
         $this->_info['file'] = array();
         $this->_info['file']['Name'] = basename($this->_fileName);
         $this->_info['file']['Url'] = $this->_fileName;
     }
     return true;
 }
/**
 * Print some info about the current page
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function tpl_pageinfo()
{
    global $conf;
    global $lang;
    global $INFO;
    global $REV;
    global $ID;
    // return if we are not allowed to view the page
    if (!auth_quickaclcheck($ID)) {
        return;
    }
    // prepare date and path
    $fn = $INFO['filepath'];
    if (!$conf['fullpath']) {
        if ($REV) {
            $fn = str_replace(fullpath($conf['olddir']) . '/', '', $fn);
        } else {
            $fn = str_replace(fullpath($conf['datadir']) . '/', '', $fn);
        }
    }
    $fn = utf8_decodeFN($fn);
    $date = strftime($conf['dformat'], $INFO['lastmod']);
    // print it
    if ($INFO['exists']) {
        print $fn;
        print ' &middot; ';
        print $lang['lastmod'];
        print ': ';
        print $date;
        if ($INFO['editor']) {
            print ' ' . $lang['by'] . ' ';
            print $INFO['editor'];
        } else {
            print ' (' . $lang['external_edit'] . ')';
        }
        if ($INFO['locked']) {
            print ' &middot; ';
            print $lang['lockedby'];
            print ': ';
            print $INFO['locked'];
        }
        return true;
    }
    return false;
}
Example #23
0
/**
 * Print some info about the current page
 *
 * @author Andreas Gohr <*****@*****.**>
 * @param bool $ret return content instead of printing it
 * @return bool|string
 */
function tpl_pageinfo($ret = false)
{
    global $conf;
    global $lang;
    global $INFO;
    global $ID;
    // return if we are not allowed to view the page
    if (!auth_quickaclcheck($ID)) {
        return false;
    }
    // prepare date and path
    $fn = $INFO['filepath'];
    if (!$conf['fullpath']) {
        if ($INFO['rev']) {
            $fn = str_replace(fullpath($conf['olddir']) . '/', '', $fn);
        } else {
            $fn = str_replace(fullpath($conf['datadir']) . '/', '', $fn);
        }
    }
    $fn = utf8_decodeFN($fn);
    $date = dformat($INFO['lastmod']);
    // print it
    if ($INFO['exists']) {
        $out = '';
        $out .= $fn;
        $out .= ' · ';
        $out .= $lang['lastmod'];
        $out .= ': ';
        $out .= $date;
        if ($INFO['editor']) {
            $out .= ' ' . $lang['by'] . ' ';
            $out .= editorinfo($INFO['editor']);
        } else {
            $out .= ' (' . $lang['external_edit'] . ')';
        }
        if ($INFO['locked']) {
            $out .= ' · ';
            $out .= $lang['lockedby'];
            $out .= ': ';
            $out .= editorinfo($INFO['locked']);
        }
        if ($ret) {
            return $out;
        } else {
            echo $out;
            return true;
        }
    }
    return false;
}
 /**
  * get abc2ps version
  */
 function _getAbc2psVersion()
 {
     ob_start();
     passthru(fullpath($this->getConf('abc2ps')) . " -V 2>&1");
     $version = ob_get_contents();
     $version = explode("\n", $version);
     ob_end_clean();
     return $version[0];
 }
Example #25
0
/**
 * list old revisions
 *
 * @author Andreas Gohr <*****@*****.**>
 * @author Ben Coburn <*****@*****.**>
 * @author Kate Arzamastseva <*****@*****.**>
 */
function html_revisions($first = 0, $media_id = false)
{
    global $ID;
    global $INFO;
    global $conf;
    global $lang;
    $id = $ID;
    /* we need to get one additionally log entry to be able to
     * decide if this is the last page or is there another one.
     * see html_recent()
     */
    if (!$media_id) {
        $revisions = getRevisions($ID, $first, $conf['recent'] + 1);
    } else {
        $revisions = getRevisions($media_id, $first, $conf['recent'] + 1, 8192, true);
        $id = $media_id;
    }
    if (count($revisions) == 0 && $first != 0) {
        $first = 0;
        if (!$media_id) {
            $revisions = getRevisions($ID, $first, $conf['recent'] + 1);
        } else {
            $revisions = getRevisions($media_id, $first, $conf['recent'] + 1, 8192, true);
        }
    }
    $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');
    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));
    }
    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($id);
        $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(' &ndash; ');
            $form->addElement(htmlspecialchars($INFO['sum']));
            $form->addElement(form_makeCloseTag('span'));
        }
        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
        if (!$media_id) {
            $editor = $INFO['editor'];
        } else {
            $revinfo = getRevisionInfo($id, @filemtime(fullpath(mediaFN($id))), 1024, true);
            if ($revinfo['user']) {
                $editor = $revinfo['user'];
            } else {
                $editor = $revinfo['ip'];
            }
        }
        $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);
        if (!$media_id) {
            $info = getRevisionInfo($id, $rev, true);
            $exists = page_exists($id, $rev);
        } else {
            $info = getRevisionInfo($id, $rev, true, true);
            $exists = @file_exists(mediaFN($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($id);
            $form->addElement(form_makeCloseTag('a'));
        } else {
            $form->addElement('<img src="' . DOKU_BASE . 'lib/images/blank.gif" width="15" height="11" alt="" />');
            $form->addElement($id);
        }
        if ($media_id) {
            $form->addElement(form_makeOpenTag('div'));
        }
        if ($info['sum']) {
            $form->addElement(form_makeOpenTag('span', array('class' => 'sum')));
            if (!$media_id) {
                $form->addElement(' &ndash; ');
            }
            $form->addElement(htmlspecialchars($info['sum']));
            $form->addElement(form_makeCloseTag('span'));
        }
        $form->addElement(form_makeOpenTag('span', array('class' => 'user')));
        if ($info['user']) {
            $form->addElement(editorinfo($info['user']));
            if (auth_ismanager()) {
                $form->addElement(' (' . $info['ip'] . ')');
            }
        } else {
            $form->addElement($info['ip']);
        }
        $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), '&amp;', 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), '&amp;', false, true));
        } else {
            print html_btn('older', $id, "n", array('do' => 'revisions', 'first' => $last));
        }
        print '</div>';
    }
    print '</div>';
}
Example #26
0
function getProfilePath($user = null)
{
    global $profilePath;
    $ret = fullpath(isset($profilePath) ? $profilePath : '../share', dirname(__FILE__));
    if (is_null($user)) {
        $user = getUser();
    }
    if ($user != '') {
        $ret .= '/users/' . $user;
        if (!is_dir($ret)) {
            makeDirectory(array($ret, $ret . '/settings', $ret . '/torrents'));
        }
    }
    return $ret;
}
Example #27
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);
}
Example #28
0
 public function correctDirectory(&$dir, $resolve_links = false)
 {
     global $topDirectory;
     if (strlen($dir) && $dir[0] == '~') {
         $dir = $this->home . substr($dir, 1);
     }
     $dir = fullpath($dir, $this->directory);
     if ($resolve_links) {
         $path = realpath($dir);
         if (!$path) {
             $dir = addslash(realpath(dirname($dir))) . basename($dir);
         } else {
             $dir = $path;
         }
     }
     return strpos(addslash($dir), $topDirectory) === 0;
 }
function get_cut_data($cut_dir, $row, $part = 0)
{
    $row_filename = "{$cut_dir}/cut-{$row}.data";
    if (!file_exists($row_filename)) {
        return false;
    }
    $data = file_get_contents($row_filename);
    if ($part == "all") {
        $path = fullpath($row_filename);
        return "Slice {$row}: <{$path}>";
    }
    $len = RESPONSE_LEN - 10;
    $packets = ceil(strlen($data) / $len);
    $header = "{$part}/{$packets}";
    if ($packets == 1) {
        return "0/1\n{$data}";
    } else {
        if ($part < $packets) {
            return $header . "\n" . substr($data, $len * $part, $len);
        } else {
            return "\n\n\n";
            //EOF
        }
    }
}
 /**
  * Returns all git repositories in this DokuWiki install
  *
  * Looks in root, template and plugin directories only.
  *
  * @return array
  */
 private function findRepos()
 {
     $this->msg_info('Looking for .git directories');
     $data = array_merge(glob(DOKU_INC . '.git', GLOB_ONLYDIR), glob(DOKU_PLUGIN . '*/.git', GLOB_ONLYDIR), glob(fullpath(tpl_incdir() . '../') . '/*/.git', GLOB_ONLYDIR));
     if (!$data) {
         $this->msg_error('Found no .git directories');
     } else {
         $this->msg_success('Found ' . count($data) . ' .git directories');
     }
     $data = array_map('fullpath', array_map('dirname', $data));
     return $data;
 }