static function render($text, $type = null, $id = null, $instructions = null)
 {
     global $conf, $baseurl, $db;
     // Unfortunately dokuwiki also uses $conf
     $fs_conf = $conf;
     $conf = array();
     // Dokuwiki generates some notices
     error_reporting(E_ALL ^ E_NOTICE);
     if (!$instructions) {
         include_once BASEDIR . '/plugins/dokuwiki/inc/parser/parser.php';
     }
     require_once BASEDIR . '/plugins/dokuwiki/inc/common.php';
     require_once BASEDIR . '/plugins/dokuwiki/inc/parser/xhtml.php';
     // Create a renderer
     $Renderer = new Doku_Renderer_XHTML();
     if (!is_string($instructions) || strlen($instructions) < 1) {
         $modes = p_get_parsermodes();
         $Parser = new Doku_Parser();
         // Add the Handler
         $Parser->Handler = new Doku_Handler();
         // Add modes to parser
         foreach ($modes as $mode) {
             $Parser->addMode($mode['mode'], $mode['obj']);
         }
         $instructions = $Parser->parse($text);
         // Cache the parsed text
         if (!is_null($type) && !is_null($id)) {
             $fields = array('content' => serialize($instructions), 'type' => $type, 'topic' => $id, 'last_updated' => time());
             $keys = array('type', 'topic');
             //autoquote is always true on db class
             $db->Replace('{cache}', $fields, $keys);
         }
     } else {
         $instructions = unserialize($instructions);
     }
     $Renderer->smileys = getSmileys();
     $Renderer->entities = getEntities();
     $Renderer->acronyms = getAcronyms();
     $Renderer->interwiki = getInterwiki();
     $conf = $fs_conf;
     $conf['cachedir'] = FS_CACHE_DIR;
     // for dokuwiki
     $conf['fperm'] = 0600;
     $conf['dperm'] = 0700;
     // 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->doc;
     // Display the output
     if (Get::val('histring')) {
         $words = explode(' ', Get::val('histring'));
         foreach ($words as $word) {
             $return = html_hilight($return, $word);
         }
     }
     return $return;
 }
示例#2
0
 /**
  *
  */
 public function connectModes()
 {
     if (!$this->connected) {
         $this->modes['outside']->connectTo('base');
         $this->modes['entry_parented']->connectTo('base');
         $this->modes['entry_braced']->connectTo('base');
         parent::connectModes();
     }
 }
示例#3
0
/**
 * turns a page into a list of instructions
 *
 * @author Harry Fuecks <*****@*****.**>
 * @author Andreas Gohr <*****@*****.**>
 */
function p_get_instructions($text)
{
    $modes = p_get_parsermodes();
    // Create the parser
    $Parser = new Doku_Parser();
    // Add the Handler
    $Parser->Handler = new Doku_Handler();
    //add modes to parser
    foreach ($modes as $mode) {
        $Parser->addMode($mode['mode'], $mode['obj']);
    }
    // Do the parsing
    trigger_event('PARSER_WIKITEXT_PREPROCESS', $text);
    $p = $Parser->parse($text);
    //  dbg($p);
    return $p;
}
示例#4
0
 function _instructions($text)
 {
     // determine all parser modes that are allowable as inline modes
     // (i.e., those that are allowed inside a table cell, minus those
     // that have a paragraph type other than 'normal')
     // determine all modes allowed inside a table cell or list item
     global $PARSER_MODES;
     $allowedModes = array_merge($PARSER_MODES['formatting'], $PARSER_MODES['substition'], $PARSER_MODES['disabled'], $PARSER_MODES['protected']);
     // determine all modes that are not allowed either due to paragraph
     // handling, or because they're blacklisted as they don't make sense.
     $blockHandler = new Doku_Handler_Block();
     $disallowedModes = array_merge($blockHandler->blockOpen, $blockHandler->stackOpen, array('notoc', 'nocache'));
     $allowedModes = array_diff($allowedModes, $disallowedModes);
     $parser = new Doku_Parser();
     $parser->Handler = new Doku_Handler();
     foreach (p_get_parsermodes() as $mode) {
         if (!in_array($mode['mode'], $allowedModes)) {
             continue;
         }
         $parser->addMode($mode['mode'], $mode['obj']);
     }
     trigger_event('PARSER_WIKITEXT_PREPROCESS', $text);
     $p = $parser->parse($text);
     return $p;
 }
示例#5
0
 /**
  * Rewrite a text in order to fix the content after the given moves.
  *
  * @param string $id   The id of the wiki page, if the page itself was moved the old id
  * @param string $text The text to be rewritten
  * @return string        The rewritten wiki text
  */
 public function rewrite($id, $text)
 {
     $meta = $this->getMoveMeta($id);
     $handlers = array();
     $pages = $meta['pages'];
     $media = $meta['media'];
     $origin = $meta['origin'];
     if ($origin == '') {
         $origin = $id;
     }
     $data = array('id' => $id, 'origin' => &$origin, 'pages' => &$pages, 'media_moves' => &$media, 'handlers' => &$handlers);
     /*
      * PLUGIN_MOVE_HANDLERS REGISTER event:
      *
      * Plugin handlers can be registered in the $handlers array, the key is the plugin name as it is given to the handler
      * The handler needs to be a valid callback, it will get the following parameters:
      * $match, $state, $pos, $pluginname, $handler. The first three parameters are equivalent to the parameters
      * of the handle()-function of syntax plugins, the $pluginname is just the plugin name again so handler functions
      * that handle multiple plugins can distinguish for which the match is. The last parameter is the handler object
      * which is an instance of helper_plugin_move_handle
      */
     trigger_event('PLUGIN_MOVE_HANDLERS_REGISTER', $data);
     $modes = p_get_parsermodes();
     // Create the parser
     $Parser = new Doku_Parser();
     // Add the Handler
     $Parser->Handler = new helper_plugin_move_handler($id, $origin, $pages, $media, $handlers);
     //add modes to parser
     foreach ($modes as $mode) {
         $Parser->addMode($mode['mode'], $mode['obj']);
     }
     return $Parser->parse($text);
 }
示例#6
0
    /**
     * Rewrite a text in order to fix the content after the given moves.
     *
     * @param string $text   The wiki text that shall be rewritten
     * @param string $id     The id of the wiki page, if the page itself was moved the old id
     * @param array $moves  Array of all page moves, the keys are the old ids, the values the new ids
     * @param array $media_moves Array of all media moves.
     * @return string        The rewritten wiki text
     */
    function rewrite_content($text, $id, $moves, $media_moves = array()) {
        $moves = $this->resolve_moves($moves, $id);
        $media_moves = $this->resolve_moves($media_moves, $id);

        $handlers = array();
        $data     = array('id' => $id, 'moves' => &$moves, 'media_moves' => &$media_moves, 'handlers' => &$handlers);

        /*
         * PLUGIN_MOVE_HANDLERS REGISTER event:
         *
         * Plugin handlers can be registered in the $handlers array, the key is the plugin name as it is given to the handler
         * The handler needs to be a valid callback, it will get the following parameters:
         * $match, $state, $pos, $pluginname, $handler. The first three parameters are equivalent to the parameters
         * of the handle()-function of syntax plugins, the $pluginname is just the plugin name again so handler functions
         * that handle multiple plugins can distinguish for which the match is. The last parameter is the handler object.
         * It has the following properties and functions that can be used:
         * - id, ns: id and namespace of the old page
         * - new_id, new_ns: new id and namespace (can be identical to id and ns)
         * - moves: array of moves, the same as $moves in the event
         * - media_moves: array of media moves, same as $media_moves in the event
         * - adaptRelativeId($id): adapts the relative $id according to the moves
         */
        trigger_event('PLUGIN_MOVE_HANDLERS_REGISTER', $data);

        $modes = p_get_parsermodes();

        // Create the parser
        $Parser = new Doku_Parser();

        // Add the Handler
        $Parser->Handler = new helper_plugin_move_handler($id, $moves, $media_moves, $handlers);

        //add modes to parser
        foreach($modes as $mode) {
            $Parser->addMode($mode['mode'], $mode['obj']);
        }

        return $Parser->parse($text);
    }