Ejemplo n.º 1
0
function getCleanInstructions($file)
{
    $instructions = p_cached_instructions($file);
    $ret = array();
    $i = 0;
    foreach ($instructions as $ins) {
        switch ($ins[0]) {
            # Filter out sections and document start/end instructions
            case 'document_start':
            case 'document_end':
            case 'section_open':
            case 'section_close':
                break;
                # Start new block of instructions on paragraph end
            # Start new block of instructions on paragraph end
            case 'p_close':
                $ret[$i++][] = $ins;
                break;
                # Add the instruction to current block
            # Add the instruction to current block
            default:
                $ret[$i][] = $ins;
                break;
        }
    }
    return $ret;
}
Ejemplo n.º 2
0
 /**
  * Build a ODT from the articles
  *
  * @param string $cachefile
  * @param string $title
  */
 protected function generateODT($cachefile, $title)
 {
     global $ID;
     global $REV;
     /** @var renderer_plugin_odt_book $odt */
     $odt = plugin_load('renderer', 'odt_book');
     // store original pageid
     $keep = $ID;
     // loop over all pages
     $xmlcontent = '';
     $cnt = count($this->list);
     for ($n = 0; $n < $cnt; $n++) {
         $page = $this->list[$n];
         // set global pageid to the rendered page
         $ID = $page;
         $xmlcontent .= p_render('odt_book', p_cached_instructions(wikiFN($page, $REV), false, $page), $info);
     }
     //restore ID
     $ID = $keep;
     $odt->doc = $xmlcontent;
     $odt->setTitle($title);
     $odt->finalize_ODTfile();
     // write to cache file
     io_savefile($cachefile, $odt->doc);
 }
Ejemplo n.º 3
0
 public function handle_tpl_act_render(Doku_Event &$event, $param)
 {
     global $ID;
     global $INFO;
     global $DOKUTRANSLATE_EDITFORM;
     if (!@file_exists(metaFN($ID, '.translate'))) {
         return;
     }
     # Disable TOC on translated pages
     $INFO['prependTOC'] = false;
     if (in_array($event->data, array('edit', 'preview'))) {
         # Take the event over
         $event->preventDefault();
         # Save the edit form for later
         html_edit();
         $DOKUTRANSLATE_EDITFORM = ob_get_clean();
         ob_start();
         # Render the page (renderer inserts saved edit form
         # and preview in the right cell)
         echo p_render('xhtml', p_cached_instructions(wikiFN($ID)), $INFO);
     }
 }
Ejemplo n.º 4
0
 /**
  * Preprocesses a blog post as its added to the feed. Makes sure to
  * remove the first header from the text (otherwise it would be doubled)
  * and takes care of presentation as configured via template.
  *
  * @param $event the event as triggered in feed.php
  * @param $param empty
  * @return void
  */
 function handle_item_add(&$event, $param)
 {
     $opt = $event->data['opt'];
     $ditem = $event->data['ditem'];
     if ($opt['feed_mode'] !== 'blogtng') {
         return;
     }
     if ($opt['item_content'] !== 'html') {
         return;
     }
     if ($opt['link_to'] !== 'current') {
         return;
     }
     // don't add drafts to the feed
     if (p_get_metadata($ditem['id'], 'type') == 'draft') {
         $event->preventDefault();
         return;
     }
     // retrieve first heading from page instructions
     $ins = p_cached_instructions(wikiFN($ditem['id']));
     $headers = array_filter($ins, array($this, '_filterHeaders'));
     $headingIns = array_shift($headers);
     $firstheading = $headingIns[1][0];
     $this->entryhelper->load_by_row($ditem['entry']);
     $output = '';
     ob_start();
     $this->entryhelper->tpl_content($ditem['entry']['blog'], 'feed');
     $output = ob_get_contents();
     ob_end_clean();
     // make URLs work when canonical is not set, regexp instead of rerendering!
     global $conf;
     if (!$conf['canonical']) {
         $base = preg_quote(DOKU_REL, '/');
         $output = preg_replace('/(<a href|<img src)="(' . $base . ')/s', '$1="' . DOKU_URL, $output);
     }
     // strip first heading and replace item title
     $event->data['item']->description = preg_replace('#[^\\n]*?>\\s*?' . preg_quote(hsc($firstheading), '#') . '\\s*?<.*\\n#', '', $output, 1);
     $event->data['item']->title = $ditem['entry']['title'];
 }
Ejemplo n.º 5
0
 function _render_output($renderer, $addID, $mode)
 {
     global $ID;
     //get data(in instructions format) from $file (dont use cache: false)
     $file = wikiFN($addID);
     $instr = p_cached_instructions($file, false);
     //page was empty
     if (empty($instr)) {
         return;
     }
     // Convert Link instructions
     $instr = $this->_convertInstructions($instr, $addID, $renderer);
     // Section IDs
     $check = null;
     $addID = sectionID($addID, $check);
     //not possible to use a:b:c for id
     if ($mode == 'xhtml') {
         //--------RENDER
         //renderer information(TOC build / Cache used)
         $info = array();
         $content = p_render($mode, $instr, $info);
         //Remove TOC`s, section edit buttons and tags
         $content = $this->_cleanXHTML($content);
         // embed the included page
         $renderer->doc .= '<div class="include">';
         //add an anchor to find start of a inserted page
         $renderer->doc .= "<a name='{$addID}' id='{$addID}'>";
         $renderer->doc .= $content;
         $renderer->doc .= '</div>';
     } else {
         if ($mode == 'odt') {
             $renderer->doc .= '<text:bookmark text:name="' . $addID . '"/>';
             // Loop through the instructions
             foreach ($instr as $instruction) {
                 // Execute the callback against the Renderer
                 call_user_func_array(array($renderer, $instruction[0]), $instruction[1]);
             }
         }
     }
 }
Ejemplo n.º 6
0
    /**
     * Returns the converted instructions of a give page/section
     *
     * @author Michael Klier <*****@*****.**>
     * @author Michael Hamann <*****@*****.**>
     */
    function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = array()) {
        $key = ($sect) ? $page . '#' . $sect : $page;
        $this->includes[$key] = true; // legacy code for keeping compatibility with other plugins

        // keep compatibility with other plugins that don't know the $root_id parameter
        if (is_null($root_id)) {
            global $ID;
            $root_id = $ID;
        }

        if ($flags['linkonly']) {
            if (page_exists($page) || $flags['pageexists']  == 0) {
                $title = '';
                if ($flags['title'])
                    $title = p_get_first_heading($page);
                if($flags['parlink']) {
                    $ins = array(
                        array('p_open', array()),
                        array('internallink', array(':'.$key, $title)),
                        array('p_close', array()),
                    );
                } else {
                    $ins = array(array('internallink', array(':'.$key,$title)));
                }
            }else {
                $ins = array();
            }
        } else {
            if (page_exists($page)) {
                global $ID;
                $backupID = $ID;
                $ID = $page; // Change the global $ID as otherwise plugins like the discussion plugin will save data for the wrong page
                $ins = p_cached_instructions(wikiFN($page), false, $page);
                $ID = $backupID;
            } else {
                $ins = array();
            }

            $this->_convert_instructions($ins, $lvl, $page, $sect, $flags, $root_id, $included_pages);
        }
        return $ins;
    }
Ejemplo n.º 7
0
 /**
  * Gathers all page and media data for given namespaces.
  * 
  * @namespaces array() of namespaces
  * @depth Search depth
  * @include_media Determines if media should be regarded, Values: 'ns','all','none'.
  * @use_cached_pages Determines if only cached pages should be used. If this option is turned off, the operation will cache all non-cached pages within the namespace.
  * @use_first_header Determines if the first header is used for title of the pages.
  * 
  * @return array with pages and media: array('pages'=>pages, 'media'=>media).   
  */
 function gather_data($namespaces, $depth = 0, $include_media = 'none', $use_cached_pages = true, $use_first_header = false)
 {
     global $conf;
     $transplugin = plugin_load('helper', 'translation');
     $pages = array();
     $media = array();
     // Loop through the namespaces
     foreach ($namespaces as $ns) {
         // Get the media of the namespace
         if ($include_media == 'ns') {
             $this->get_media($media, $ns, $depth);
         }
         // Get the pages of the namespace
         $this->get_pages($pages, $ns, $depth, $use_first_header);
     }
     // Loop through the pages to get links and media
     foreach ($pages as $pid => $item) {
         // get instructions
         $ins = p_cached_instructions(wikiFN($pid), $use_cached_pages, $pid);
         // find links and media usage
         foreach ($ins as $i) {
             $mid = null;
             // Internal link?
             if ($i[0] == 'internallink') {
                 $id = $i[1][0];
                 $exists = true;
                 resolve_pageid($item['ns'], $id, $exists);
                 list($id) = explode('#', $id, 2);
                 if ($id == $pid) {
                     continue;
                 }
                 // skip self references
                 if ($exists && isset($pages[$id])) {
                     $pages[$pid]['links'][] = $id;
                 }
                 if (is_array($i[1][1]) && $i[1][1]['type'] == 'internalmedia') {
                     $mid = $i[1][1]['src'];
                     // image link
                 } else {
                     continue;
                     // we're done here
                 }
             }
             if ($i[0] == 'internalmedia') {
                 $mid = $i[1][0];
             }
             if (is_null($mid)) {
                 continue;
             }
             if ($include_media == 'none') {
                 continue;
             }
             // no media wanted
             $exists = true;
             resolve_mediaid($item['ns'], $mid, $exists);
             list($mid) = explode('#', $mid, 2);
             $mid = cleanID($mid);
             if ($exists) {
                 if ($include_media == 'all') {
                     if (!isset($media[$mid])) {
                         //add node
                         $media[$mid] = array('size' => filesize(mediaFN($mid)), 'time' => filemtime(mediaFN($mid)), 'ns' => getNS($mid), 'title' => noNS($mid));
                     }
                     $pages[$pid]['media'][] = $mid;
                 } elseif (isset($media[$mid])) {
                     $pages[$pid]['media'][] = $mid;
                 }
             }
         }
         // clean up duplicates
         $pages[$pid]['links'] = array_unique($pages[$pid]['links']);
         $pages[$pid]['media'] = array_unique($pages[$pid]['media']);
     }
     return array('pages' => $pages, 'media' => $media);
 }
Ejemplo n.º 8
0
 /**
  * Initializes the labels, loaded from a defined labelpage
  *
  * @param array $data all data passed to render()
  */
 protected function loadlabels(&$data)
 {
     global $INFO;
     $labelpage = $data['labels'];
     $exists = false;
     resolve_pageid($INFO['namespace'], $labelpage, $exists);
     if (!$exists) {
         msg(sprintf($this->getLang('e_labelpage'), html_wikilink($labelpage)), -1);
         return;
     }
     // parse simple list (first level cdata only)
     $labels = array();
     $instructions = p_cached_instructions(wikiFN($labelpage));
     $inli = 0;
     $item = '';
     foreach ($instructions as $instruction) {
         if ($instruction[0] == 'listitem_open') {
             $inli++;
             continue;
         }
         if ($inli === 1 && $instruction[0] == 'cdata') {
             $item .= $instruction[1][0];
         }
         if ($instruction[0] == 'listitem_close') {
             $inli--;
             if ($inli === 0) {
                 list($k, $v) = explode('=', $item, 2);
                 $k = trim($k);
                 $v = trim($v);
                 if ($k && $v) {
                     $labels[$k] = $v;
                 }
                 $item = '';
             }
         }
     }
     // apply labels to all fields
     $len = count($data['fields']);
     for ($i = 0; $i < $len; $i++) {
         if (isset($data['fields'][$i]->depends_on)) {
             // translate dependency on fieldsets
             $label = $data['fields'][$i]->depends_on[0];
             if (isset($labels[$label])) {
                 $data['fields'][$i]->depends_on[0] = $labels[$label];
             }
         } else {
             if (isset($data['fields'][$i]->opt['label'])) {
                 // translate field labels
                 $label = $data['fields'][$i]->opt['label'];
                 if (isset($labels[$label])) {
                     $data['fields'][$i]->opt['display'] = $labels[$label];
                 }
             }
         }
     }
     if (isset($data['thanks'])) {
         if (isset($labels[$data['thanks']])) {
             $data['thanks'] = $labels[$data['thanks']];
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * Handler for the ACTION_ACT_PREPROCESS event and AFTER advise.
  * 
  * Sends linkback if previous action was 'save' and new one is show.
  */
 function handle_action_act_preprocess_after(&$event, $params)
 {
     global $ID;
     global $ACT;
     global $conf;
     // only perform linkbacks on save of a wikipage
     if ($this->preact != 'save' || $event->data != 'show') {
         return;
     }
     // if guests are not allowed to perform linkbacks, return
     if (!$this->getConf('allow_guests') && !$_SERVER['REMOTE_USER']) {
         return;
     }
     // get linkback meta file name
     $file = metaFN($ID, '.linkbacks');
     $data = array('send' => false, 'receive' => false, 'display' => false, 'sentpings' => array(), 'receivedpings' => array(), 'number' => 0);
     if (@file_exists($file)) {
         $data = unserialize(io_readFile($file, false));
     }
     $data['send'] = $_REQUEST['plugin__linkback_toggle'] ? true : false;
     if (!$data['send']) {
         return;
     }
     $meta = p_get_metadata($ID);
     // prepare linkback info
     $linkback_info = array();
     $linkback_info['title'] = tpl_pagetitle($ID, true);
     $linkback_info['url'] = wl($ID, '', true);
     $linkback_info['blog_name'] = $conf['title'];
     $linkback_info['excerpt'] = $meta['description']['abstract'];
     // get links
     $ilist = p_cached_instructions(wikiFN($ID), false, $ID);
     if (!is_array($ilist)) {
         return;
     }
     $pages = $this->_parse_instructionlist($ilist);
     $sentpings = array();
     foreach ($pages as $page) {
         if (!$data['sentpings'][$page]) {
             // try to ping pages not already pinged
             $this->_ping_page($page, $linkback_info);
         }
         $sentpings[$page] = true;
     }
     $data['sentpings'] = $sentpings;
     // save sent ping info
     io_saveFile($file, serialize($data));
     return true;
 }
Ejemplo n.º 10
0
 /**
  * Index media usage data
  *
  * @param Doku_Event $event The event object
  * @param array $param  Optional parameters (unused)
  */
 public function index_media_use(Doku_Event $event, $param) {
     // From indexer version 6 on the media references are indexed by DokuWiki itself
     if (INDEXER_VERSION >= 6) return;
     $id = $event->data['page'];
     $media_references = array();
     $instructions = p_cached_instructions(wikiFn($id), false, $id);
     if (is_array($instructions)) {
         $this->get_media_references_from_instructions($instructions, $media_references, $id);
     }
     $media_references = array_unique($media_references);
     $event->data['metadata']['relation_media'] = $media_references;
 }
Ejemplo n.º 11
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]);
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * Returns the converted instructions of a give page/section
  *
  * @author Michael Klier <*****@*****.**>
  * @author Michael Hamann <*****@*****.**>
  */
 function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null)
 {
     $key = $sect ? $page . '#' . $sect : $page;
     $this->includes[$key] = true;
     // legacy code for keeping compatibility with other plugins
     // keep compatibility with other plugins that don't know the $root_id parameter
     if (is_null($root_id)) {
         global $ID;
         $root_id = $ID;
     }
     if ($flags['linkonly']) {
         $ins = array(array('p_open', array()), array('internallink', array(':' . $key)), array('p_close', array()));
     } else {
         if (page_exists($page)) {
             $ins = p_cached_instructions(wikiFN($page));
         } else {
             $ins = array();
         }
         $this->_convert_instructions($ins, $lvl, $page, $sect, $flags, $root_id);
     }
     return $ins;
 }
Ejemplo n.º 13
0
 /**
  * FIXME
  * @param $readmore
  * @param $inc_level
  * @param $skipheader
  * @return unknown_type
  */
 function get_entrycontent($readmore = 'syntax', $inc_level = true, $skipheader = false)
 {
     static $recursion = array();
     $id = $this->entry['page'];
     if (in_array($id, $recursion)) {
         msg('blogtng: preventing infinite loop', -1);
         return false;
         // avoid infinite loops
     }
     $recursion[] = $id;
     // FIXME do some caching here!
     global $ID, $TOC, $conf;
     $info = array();
     $ins = p_cached_instructions(wikiFN($id));
     $this->_convert_instructions($ins, $inc_level, $readmore, $skipheader);
     $backupID = $ID;
     $ID = $id;
     $handleTOC = $this->renderer !== null;
     // the call to p_render below might set the renderer
     if ($handleTOC) {
         $renderer =& $this->renderer;
         // save the renderer before p_render changes it
         $backupTOC = $TOC;
         // the renderer overwrites the global $TOC
         $backupTocminheads = $conf['tocminheads'];
         $conf['tocminheads'] = 1;
         // let the renderer always generate a toc
     }
     $content = p_render('xhtml', $ins, $info);
     if ($handleTOC) {
         if ($TOC && $backupTOC !== $TOC && $info['toc']) {
             $renderer->toc = array_merge($renderer->toc, $TOC);
             $TOC = null;
             // Reset the global toc as it is included in the renderer now
             // and if the renderer decides to not to output it the
             // global one should be empty
         }
         $conf['tocminheads'] = $backupTocminheads;
         $this->renderer =& $renderer;
     }
     $ID = $backupID;
     array_pop($recursion);
     return $content;
 }
 /**
  * Keeps section levels
  */
 function setSectionLevels($calls = null)
 {
     global $ID;
     global $conf;
     if ($calls === null) {
         $calls = p_cached_instructions(wikiFN($ID), 'cacheonly');
     }
     list($handler_name, $instructions) = array(0, 1);
     $this->section_levels = array('dummy_entry_for_padding');
     for ($i = 0, $i_max = count($calls); $i < $i_max; $i++) {
         if ($calls[$i][$handler_name] === 'section_open') {
             $section_level = $calls[$i][$instructions][0];
             if ($section_level <= $conf['maxseclevel']) {
                 $this->section_levels[] = $section_level;
             }
         }
     }
 }
Ejemplo n.º 15
0
/**
 * Find all the node and edge data for the given namespaces
 */
function gather_data($namespaces, $depth = 0, $incmedia = 'ns')
{
    global $conf;
    $transplugin = plugin_load('helper', 'translation');
    $pages = array();
    $media = array();
    foreach ($namespaces as $ns) {
        // find media
        if ($incmedia == 'ns') {
            $data = array();
            search($data, $conf['mediadir'], 'search_universal', array('depth' => $depth, 'listfiles' => true, 'listdirs' => false, 'pagesonly' => false, 'skipacl' => true, 'keeptxt' => true, 'meta' => true), str_replace(':', '/', $ns));
            // go through all those media files
            while ($item = array_shift($data)) {
                $media[$item['id']] = array('title' => noNS($item['id']), 'size' => $item['size'], 'ns' => getNS($item['id']), 'time' => $item['mtime']);
            }
        }
        // find pages
        $data = array();
        search($data, $conf['datadir'], 'search_universal', array('depth' => $depth, 'listfiles' => true, 'listdirs' => false, 'pagesonly' => true, 'skipacl' => true, 'firsthead' => true, 'meta' => true), str_replace(':', '/', $ns));
        // ns start page
        if ($ns && page_exists($ns)) {
            $data[] = array('id' => $ns, 'ns' => getNS($ns), 'title' => p_get_first_heading($ns, false), 'size' => filesize(wikiFN($ns)), 'mtime' => filemtime(wikiFN($ns)), 'perm' => 16, 'type' => 'f', 'level' => 0, 'open' => 1);
        }
        // go through all those pages
        while ($item = array_shift($data)) {
            $time = (int) p_get_metadata($item['id'], 'date created', false);
            if (!$time) {
                $time = $item['mtime'];
            }
            $lang = $transplugin ? $transplugin->getLangPart($item['id']) : '';
            if ($lang) {
                $item['ns'] = preg_replace('/^' . $lang . '(:|$)/', '', $item['ns']);
            }
            $pages[$item['id']] = array('title' => $item['title'], 'ns' => $item['ns'], 'size' => $item['size'], 'time' => $time, 'links' => array(), 'media' => array(), 'lang' => $lang);
        }
    }
    // now get links and media
    foreach ($pages as $pid => $item) {
        // get instructions
        $ins = p_cached_instructions(wikiFN($pid), false, $pid);
        // find links and media usage
        foreach ($ins as $i) {
            $mid = null;
            if ($i[0] == 'internallink') {
                $id = $i[1][0];
                $exists = true;
                resolve_pageid($item['ns'], $id, $exists);
                list($id) = explode('#', $id, 2);
                if ($id == $pid) {
                    continue;
                }
                // skip self references
                if ($exists && isset($pages[$id])) {
                    $pages[$pid]['links'][] = $id;
                }
                if (is_array($i[1][1]) && $i[1][1]['type'] == 'internalmedia') {
                    $mid = $i[1][1]['src'];
                    // image link
                } else {
                    continue;
                    // we're done here
                }
            }
            if ($i[0] == 'internalmedia') {
                $mid = $i[1][0];
            }
            if (is_null($mid)) {
                continue;
            }
            if ($incmedia == 'none') {
                continue;
            }
            // no media wanted
            $exists = true;
            resolve_mediaid($item['ns'], $mid, $exists);
            list($mid) = explode('#', $mid, 2);
            $mid = cleanID($mid);
            if ($exists) {
                if ($incmedia == 'all') {
                    if (!isset($media[$mid])) {
                        //add node
                        $media[$mid] = array('size' => filesize(mediaFN($mid)), 'time' => filemtime(mediaFN($mid)), 'ns' => getNS($mid), 'title' => noNS($mid));
                    }
                    $pages[$pid]['media'][] = $mid;
                } elseif (isset($media[$mid])) {
                    $pages[$pid]['media'][] = $mid;
                }
            }
        }
        // clean up duplicates
        $pages[$pid]['links'] = array_unique($pages[$pid]['links']);
        $pages[$pid]['media'] = array_unique($pages[$pid]['media']);
    }
    return array('pages' => $pages, 'media' => $media);
}
Ejemplo n.º 16
0
 /**
  * Lists all links contained in a wiki page
  *
  * @author Michael Klier <*****@*****.**>
  */
 function listLinks($id)
 {
     $id = $this->resolvePageId($id);
     if (auth_quickaclcheck($id) < AUTH_READ) {
         throw new RemoteAccessDeniedException('You are not allowed to read this page', 111);
     }
     $links = array();
     // resolve page instructions
     $ins = p_cached_instructions(wikiFN($id));
     // instantiate new Renderer - needed for interwiki links
     include DOKU_INC . 'inc/parser/xhtml.php';
     $Renderer = new Doku_Renderer_xhtml();
     $Renderer->interwiki = getInterwiki();
     // parse parse instructions
     foreach ($ins as $in) {
         $link = array();
         switch ($in[0]) {
             case 'internallink':
                 $link['type'] = 'local';
                 $link['page'] = $in[1][0];
                 $link['href'] = wl($in[1][0]);
                 array_push($links, $link);
                 break;
             case 'externallink':
                 $link['type'] = 'extern';
                 $link['page'] = $in[1][0];
                 $link['href'] = $in[1][0];
                 array_push($links, $link);
                 break;
             case 'interwikilink':
                 $url = $Renderer->_resolveInterWiki($in[1][2], $in[1][3]);
                 $link['type'] = 'extern';
                 $link['page'] = $url;
                 $link['href'] = $url;
                 array_push($links, $link);
                 break;
         }
     }
     return $links;
 }
Ejemplo n.º 17
0
 /**
  * FIXME
  * @param $readmore
  * @param $inc_level
  * @param $skipheader
  * @return unknown_type
  */
 function get_entrycontent($readmore = 'syntax', $inc_level = true, $skipheader = false)
 {
     static $recursion = false;
     if ($recursion) {
         msg('blogtng: preventing infinite loop', -1);
         return false;
         // avoid infinite loops
     }
     $recursion = true;
     $id = $this->entry['page'];
     // FIXME do some caching here!
     global $ID;
     $info = array();
     $ins = p_cached_instructions(wikiFN($id));
     $backupID = $ID;
     $ID = $id;
     $this->_convert_instructions($ins, $inc_level, $readmore, $skipheader);
     $content = p_render('xhtml', $ins, $info);
     $ID = $backupID;
     $recursion = false;
     return $content;
 }
Ejemplo n.º 18
0
/**
 * renders the metadata of a page
 *
 * @author Esther Brunner <*****@*****.**>
 */
function p_render_metadata($id, $orig)
{
    require_once DOKU_INC . "inc/parser/metadata.php";
    // get instructions
    $instructions = p_cached_instructions(wikiFN($id), false, $id);
    // set up the renderer
    $renderer = new Doku_Renderer_metadata();
    $renderer->meta = $orig;
    // loop through the instructions
    foreach ($instructions as $instruction) {
        // execute the callback against the renderer
        call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1]);
    }
    return $renderer->meta;
}
Ejemplo n.º 19
0
    function create($id, $user_title = false)
    {
        ob_start();
        $id = ltrim($id, ':');
        $id = ":{$id}";
        $namespace = getNS($id);
        epub_save_namespace($namespace);
        $mode = 'epub';
        $Renderer =& plugin_load('renderer', $mode);
        $Renderer->set_oebps();
        $Renderer->set_current_page(epub_clean_name(str_replace(':', '_', $id)) . '.html');
        $this->_renderer = $Renderer;
        if (is_null($Renderer)) {
            msg("No renderer for {$mode} found", -1);
            exit;
        }
        global $ID;
        $oldID = $ID;
        $ID = cleanID($id);
        $wiki_file = wikiFN($id);
        if (!file_exists($wiki_file)) {
            epub_push_spine(array("", ""));
            echo "{$id} not found\n";
            return false;
        }
        epub_update_progress("reading {$id}");
        $instructions = p_cached_instructions($wiki_file, false, $id);
        if (is_null($instructions)) {
            return '';
        }
        $Renderer->notoc();
        $Renderer->smileys = getSmileys();
        $Renderer->entities = getEntities();
        $Renderer->acronyms = array();
        $Renderer->interwiki = getInterwiki();
        epub_update_progress("rendering {$id},  this could take some time");
        // Loop through the instructions
        foreach ($instructions as $instruction) {
            // Execute the callback against the Renderer
            call_user_func_array(array(&$Renderer, $instruction[0]), $instruction[1]);
        }
        $result = "";
        $result .= '<html xmlns="http://www.w3.org/1999/xhtml">' . "\n";
        $result .= "\n<head>\n";
        $result .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>' . "\n";
        $result .= '<link rel="stylesheet"  type="text/css" href="../Styles/style.css"/>';
        epub_check_for_mathjax($result);
        $result .= "\n<title>";
        $result .= "</title>\n</head><body>\n";
        $result .= "<div class='dokuwiki'>\n";
        $info = $Renderer->info;
        $data = array($mode, &$Renderer->doc);
        trigger_event('RENDERER_CONTENT_POSTPROCESS', $data);
        $xhtml = $Renderer->doc;
        $result .= $xhtml;
        $result .= "\n</div></body></html>\n";
        $result = preg_replace_callback("/&(\\w+);/m", "epbub_entity_replace", $result);
        $result = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/m", "\n", $result);
        $result = preg_replace("/^\\s+/m", "", $result);
        $result = preg_replace_callback('|<p>([\\s\\n]*)(.*?<div.*?/div>.*?)([\\s\\n])*<\\/p>|im', create_function('$matches', '$result = $matches[1] . $matches[2] . $matches[3];
											//echo "$result\\n";
											return $result;'), $result);
        ob_end_flush();
        if ($user_title) {
            $id = 'title.html';
        } else {
            $id = epub_clean_name(str_replace(':', '_', $id)) . '.html';
        }
        io_saveFile(epub_get_oebps() . "Text/{$id}", $result);
        if ($user_title) {
            epub_write_zip('Text/title.html');
            $ID = $oldID;
            return true;
        }
        $item_num = epub_write_item("Text/{$id}", "application/xhtml+xml");
        epub_push_spine(array("Text/{$id}", $item_num));
        epub_save_namespace();
        $ID = $oldID;
        return true;
    }
Ejemplo n.º 20
0
/**
 * renders the metadata of a page
 *
 * @author Esther Brunner <*****@*****.**>
 */
function p_render_metadata($id, $orig)
{
    // make sure the correct ID is in global ID
    global $ID, $METADATA_RENDERERS;
    // avoid recursive rendering processes for the same id
    if (isset($METADATA_RENDERERS[$id])) {
        return $orig;
    }
    // store the original metadata in the global $METADATA_RENDERERS so p_set_metadata can use it
    $METADATA_RENDERERS[$id] =& $orig;
    $keep = $ID;
    $ID = $id;
    // add an extra key for the event - to tell event handlers the page whose metadata this is
    $orig['page'] = $id;
    $evt = new Doku_Event('PARSER_METADATA_RENDER', $orig);
    if ($evt->advise_before()) {
        require_once DOKU_INC . "inc/parser/metadata.php";
        // get instructions
        $instructions = p_cached_instructions(wikiFN($id), false, $id);
        if (is_null($instructions)) {
            $ID = $keep;
            unset($METADATA_RENDERERS[$id]);
            return null;
            // something went wrong with the instructions
        }
        // set up the renderer
        $renderer = new Doku_Renderer_metadata();
        $renderer->meta =& $orig['current'];
        $renderer->persistent =& $orig['persistent'];
        // loop through the instructions
        foreach ($instructions as $instruction) {
            // execute the callback against the renderer
            call_user_func_array(array(&$renderer, $instruction[0]), (array) $instruction[1]);
        }
        $evt->result = array('current' => &$renderer->meta, 'persistent' => &$renderer->persistent);
    }
    $evt->advise_after();
    // clean up
    $ID = $keep;
    unset($METADATA_RENDERERS[$id]);
    return $evt->result;
}
function generateLinks($naviID)
{
    global $INFO;
    global $ID;
    $id = $naviID;
    // fetch the instructions of the control page
    $instructions = p_cached_instructions(wikiFN($id), false, $id);
    // prepare some vars
    $max = count($instructions);
    $pre = true;
    $lvl = 0;
    $parents = array();
    $page = '';
    $cnt = 0;
    // build a lookup table
    for ($i = 0; $i < $max; $i++) {
        if ($instructions[$i][0] == 'listu_open') {
            $pre = false;
            $lvl++;
            if ($page) {
                array_push($parents, $page);
            }
        } elseif ($instructions[$i][0] == 'listu_close') {
            $lvl--;
            array_pop($parents);
        } elseif ($pre || $lvl == 0) {
            unset($instructions[$i]);
        } elseif ($instructions[$i][0] == 'listitem_close') {
            $cnt++;
        } elseif ($instructions[$i][0] == 'internallink') {
            $page = cleanID($instructions[$i][1][0]);
            $list[$page] = array('parents' => $parents, 'page' => $instructions[$i][1][0], 'title' => $instructions[$i][1][1], 'lvl' => $lvl);
        }
    }
    $list;
    $data = $list;
    $parent = (array) $data[$INFO['id']]['parents'];
    // get the "path" of the page we're on currently
    array_push($parent, $INFO['id']);
    //print_r($list);
    $navigation = array(1 => array(), 2 => array());
    foreach ((array) $data as $pid => $info) {
        // only show if we are in the "path"
        if (array_diff($info['parents'], $parent)) {
            continue;
        }
        // skip every non readable page
        if (auth_quickaclcheck(cleanID($info['page'])) < AUTH_READ) {
            continue;
        }
        $mylink = html_wikilink($info['page'], $info['title']);
        if (in_array(ltrim($info['page'], ':'), $parent) || in_array($info['page'], $parent)) {
            $mylink = '<span class="in-path">' . $mylink . '</span>';
        }
        array_push($navigation[$info['lvl']], $mylink);
    }
    return $navigation;
}
Ejemplo n.º 22
0
/**
 * Search for backlinks to a given page
 *
 * $opts['ns']    namespace of the page
 * $opts['name']  name of the page without namespace
 *
 * @author  Andreas Gohr <*****@*****.**>
 * @deprecated Replaced by ft_backlinks()
 */
function search_backlinks(&$data, $base, $file, $type, $lvl, $opts)
{
    //we do nothing with directories
    if ($type == 'd') {
        return true;
    }
    //only search txt files
    if (substr($file, -4) != '.txt') {
        return true;
    }
    //absolute search id
    $sid = cleanID($opts['ns'] . ':' . $opts['name']);
    //current id and namespace
    $cid = pathID($file);
    $cns = getNS($cid);
    //check ACL
    if (auth_quickaclcheck($cid) < AUTH_READ) {
        return false;
    }
    //fetch instructions
    $instructions = p_cached_instructions($base . $file, true);
    if (is_null($instructions)) {
        return false;
    }
    //check all links for match
    foreach ($instructions as $ins) {
        if ($ins[0] == 'internallink' || $conf['camelcase'] && $ins[0] == 'camelcaselink') {
            $mid = $ins[1][0];
            resolve_pageid($cns, $mid, $exists);
            //exists is not used
            if ($mid == $sid) {
                //we have a match - finish
                $data[]['id'] = $cid;
                break;
            }
        }
    }
    return false;
}
Ejemplo n.º 23
0
 /**
  * Builds the XHTML to embed the page to include
  */
 function _include(&$renderer, $type, $data, $clevel = 0, $firstseconly = false)
 {
     global $filechain;
     $id = $data['id'];
     $section = $data['section'];
     array_push($filechain, $id . '#' . $section);
     // get instructions and render them on the fly
     $file = wikiFN($id);
     $data['filepath'] = $file;
     $instr = p_cached_instructions($file, false);
     if (!empty($instr)) {
         if ($section) {
             $instr = $this->_getSection($section, $instr);
         }
         $instr = $this->_convertInstructions($instr, $id, $renderer, $clevel, $h, $firstseconly);
         if ($firstseconly) {
             $instr = $this->_readMore($instr, $id);
         }
         $content = p_render('xhtml', $instr, $info);
         $content = $this->_cleanXHTML($content, $tags);
         $data['tags'] = $tags;
         // embed the included page
         $renderer->doc .= '<div class="include">';
         if (!$h && $clevel && $type == 'section') {
             $renderer->doc .= '<div class="level' . $clevel . '">';
         }
         $renderer->doc .= $content . $this->_editButton($data);
         if (!$h && $clevel && $type == 'section') {
             $renderer->doc .= '</div>';
         }
         $renderer->doc .= '</div>';
         $renderer->doc .= $this->_metaLine($data, $renderer);
     }
     array_pop($filechain);
     return true;
 }