Example #1
0
 function add_css(&$event, $param)
 {
     // get content from wiki page
     $txt = io_readWikiPage(wikiFN($this->pagename), $this->pagename);
     // filter for CSS definitions in <code css> blocks
     preg_match_all('/<code css>(.*?)<\\/code>/sm', $txt, $matches);
     $usercss = implode("\n", $matches[1]);
     // fix url() locations
     $usercss = preg_replace_callback('#(url\\([ \'"]*)([^\'"]*)#', create_function('$matches', 'global $ID; $m = $matches[2];
                           resolve_mediaid(getNS($ID), $m, $exists);
                           return $matches[1].ml($m);'), $usercss);
     // append all
     $event->data .= $usercss;
 }
Example #2
0
/**
 * Returns the render instructions for a file
 *
 * Uses and creates a serialized cache file
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function p_cached_instructions($file, $cacheonly = false, $id = '')
{
    global $conf;
    static $run = null;
    if (is_null($run)) {
        $run = array();
    }
    $cache = new cache_instructions($id, $file);
    if ($cacheonly || $cache->useCache() || isset($run[$file])) {
        return $cache->retrieveCache();
    } else {
        if (@file_exists($file)) {
            // no cache - do some work
            $ins = p_get_instructions(io_readWikiPage($file, $id));
            if ($cache->storeCache($ins)) {
                $run[$file] = true;
                // we won't rebuild these instructions in the same run again
            } else {
                msg('Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.', -1);
            }
            return $ins;
        }
    }
    return null;
}
Example #3
0
/**
 * Returns the raw Wiki Text in three slices.
 *
 * The range parameter needs to have the form "from-to"
 * and gives the range of the section in bytes - no
 * UTF-8 awareness is needed.
 * The returned order is prefix, section and suffix.
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function rawWikiSlices($range, $id, $rev = '')
{
    $text = io_readWikiPage(wikiFN($id, $rev), $id, $rev);
    // Parse range
    list($from, $to) = explode('-', $range, 2);
    // Make range zero-based, use defaults if marker is missing
    $from = !$from ? 0 : $from - 1;
    $to = !$to ? strlen($text) : $to - 1;
    $slices[0] = substr($text, 0, $from);
    $slices[1] = substr($text, $from, $to - $from);
    $slices[2] = substr($text, $to);
    return $slices;
}
Example #4
0
/**
 * Returns the raw Wiki Text in three slices.
 *
 * The range parameter needs to have the form "from-to"
 * and gives the range of the section in bytes - no
 * UTF-8 awareness is needed.
 * The returned order is prefix, section and suffix.
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function rawWikiSlices($range, $id, $rev = '')
{
    list($from, $to) = split('-', $range, 2);
    $text = io_readWikiPage(wikiFN($id, $rev), $id, $rev);
    if (!$from) {
        $from = 0;
    }
    if (!$to) {
        $to = strlen($text) + 1;
    }
    $slices[0] = substr($text, 0, $from - 1);
    $slices[1] = substr($text, $from - 1, $to - $from);
    $slices[2] = substr($text, $to);
    return $slices;
}
 function process_page($input)
 {
     $page = $input;
     // integrate all includes
     $includematches = array();
     preg_match_all('/\\[INCLUDE:([^\\]]*)\\]/', $page, $includematches, PREG_SET_ORDER);
     foreach ($includematches as $includematch) {
         $includeid = $includematch[1];
         $file = wikiFN($includeid, '');
         if (@file_exists($file)) {
             $content = io_readWikiPage($file, $includeid);
         }
         if (!$content) {
             $page = str_replace($includematch[0], "include \"{$includeid}\" not found", $page);
             continue;
         }
         $page = str_replace($includematch[0], $content, $page);
     }
     $page = str_replace('~~TEMPLATE~~', '', $page);
     // interpret and remove all maps and variable blocks
     $mapblocks = array();
     preg_match_all('/\\[MAPS\\](.*)?\\[ENDMAPS\\]/sm', $page, $mapblocks, PREG_SET_ORDER);
     foreach ($mapblocks as $mapblock) {
         fill_map($mapblock[1], $this->maps);
         // at this point, maps are stored as strings, we need to convert them
         foreach (array_keys($this->maps) as $mapname) {
             $list = explode(',', $this->maps[$mapname]);
             $map = array();
             foreach ($list as $field) {
                 if ($pos = strpos($field, '=')) {
                     $map[trim(substr($field, 0, $pos))] = trim(substr($field, $pos + 1));
                 } else {
                     // no key found => append
                     $map[] = trim($field);
                 }
             }
             $this->maps[$mapname] = $map;
         }
         $page = str_replace($mapblock[0], '', $page);
     }
     $variableblocks = array();
     preg_match_all('/\\[VARIABLES\\](.*)?\\[ENDVARIABLES\\]/sm', $page, $variableblocks, PREG_SET_ORDER);
     foreach ($variableblocks as $variableblock) {
         fill_map($variableblock[1], $this->variables);
         $page = str_replace($variableblock[0], '', $page);
     }
     // invoke the substitution
     $this->substitute($page, -1);
     return $page;
 }
Example #6
0
/**
 * Get the sidebar html. Get cached sidebar if $cache param is true.
 *
 * @author Cameron Little <*****@*****.**>
 */
function bootstrap_tpl_get_sidebar($pageid, $cache)
{
    global $TOC;
    $oldtoc = $TOC;
    $html = '';
    $rev = '';
    $file = wikiFN($pageid, $rev);
    if ($cache && !$rev) {
        if (@file_exists($file)) {
            $html = p_cached_output($file, 'xhtml', $pageid);
        }
    } else {
        if (@file_exists($file)) {
            $html = p_render('xhtml', p_get_instructions(io_readWikiPage($file, $pageid, $rev)), $info);
            //no caching on old revisions
        }
    }
    return $html;
}
Example #7
0
 /**
  *
  */
 private function parse()
 {
     $text = io_readWikiPage($this->fileName, $this->id);
     $call = p_cached_instructions($this->fileName);
     $calls = count($call);
     for ($c = 0; $c < $calls; $c++) {
         if ($call[$c][0] == 'table_open') {
             $c = $this->parseTable($call, $calls, $c, $text);
         } elseif ($call[$c][0] == 'code') {
             $this->parseCode($call[$c]);
         } elseif ($call[$c][0] == 'plugin' && $call[$c][1][0] == 'data_entry') {
             $this->parseDataEntry($call[$c][1][1]);
         }
     }
 }