Wicked_Page::getProcessor PHP Method

getProcessor() public method

public getProcessor ( $output_format = 'Xhtml' )
    public function getProcessor($output_format = 'Xhtml')
    {
        if (isset($this->_proc)) {
            return $this->_proc;
        }
        /* Create format-specific Text_Wiki object */
        $class = 'Text_Wiki_' . $GLOBALS['conf']['wicked']['format'];
        $this->_proc = new $class();
        /* Use a non-printable delimiter character that is still a valid UTF-8
         * character. See http://pear.php.net/bugs/bug.php?id=12490. */
        $this->_proc->delim = chr(1);
        /* Override rules */
        $this->_proc->insertRule('Heading2', 'Heading');
        $this->_proc->deleteRule('Heading');
        $this->_proc->loadParseObj('Paragraph');
        $skip = $this->_proc->parseObj['Paragraph']->getConf('skip');
        $skip[] = 'heading2';
        $this->_proc->setParseConf('Paragraph', 'skip', $skip);
        $this->_proc->setParseConf('Wikilink', 'utf-8', true);
        $this->_proc->setParseConf('Freelink', 'utf-8', true);
        if ($GLOBALS['conf']['wicked']['format'] == 'Default' || $GLOBALS['conf']['wicked']['format'] == 'Cowiki' || $GLOBALS['conf']['wicked']['format'] == 'Tiki') {
            $this->_proc->insertRule('Toc2', 'Toc');
        }
        $this->_proc->deleteRule('Toc');
        switch ($output_format) {
            case 'Plain':
                $this->_proc->insertRule('Table2', 'Table');
                $this->_proc->deleteRule('Table');
                break;
            case 'Rst':
                require_once __DIR__ . '/Text_Wiki/Render/Rst.php';
                $this->_proc->insertRule('Table2', 'Table');
                $this->_proc->deleteRule('Table');
                $this->_proc->setRenderConf('Rst', 'Wikilink', $this->_getLinkConf(true));
                if ($GLOBALS['conf']['wicked']['format'] == 'Default') {
                    $this->_proc->insertRule('Freelink2', 'Freelink');
                    $this->_proc->setParseConf('Freelink2', 'utf-8', true);
                    $this->_proc->setRenderConf('Rst', 'Freelink2', $this->_getLinkConf(true));
                }
                $this->_proc->deleteRule('Freelink');
                break;
            case 'Xhtml':
                if ($GLOBALS['conf']['wicked']['format'] != 'Creole') {
                    $this->_proc->insertRule('Code2', 'Code');
                }
                $this->_proc->deleteRule('Code');
                if ($GLOBALS['conf']['wicked']['format'] == 'BBCode') {
                    $this->_proc->insertRule('Wickedblock', 'Code2');
                } else {
                    $this->_proc->insertRule('Wikilink2', 'Wikilink');
                    $this->_proc->setParseConf('Wikilink2', 'utf-8', true);
                    $this->_proc->insertRule('Wickedblock', 'Raw');
                }
                $this->_proc->deleteRule('Wikilink');
                if ($GLOBALS['conf']['wicked']['format'] == 'Default' || $GLOBALS['conf']['wicked']['format'] == 'Cowiki' || $GLOBALS['conf']['wicked']['format'] == 'Tiki') {
                    $this->_proc->insertRule('Freelink2', 'Freelink');
                    $this->_proc->setParseConf('Freelink2', 'utf-8', true);
                }
                $this->_proc->deleteRule('Freelink');
                $this->_proc->insertRule('Image2', 'Image');
                $this->_proc->deleteRule('Image');
                $this->_proc->insertRule('RegistryLink', 'Wickedblock');
                $this->_proc->insertRule('Attribute', 'RegistryLink');
                $this->_proc->deleteRule('Include');
                $this->_proc->deleteRule('Embed');
                $this->_proc->setFormatConf('Xhtml', 'charset', 'UTF-8');
                $this->_proc->setFormatConf('Xhtml', 'translate', HTML_SPECIALCHARS);
                $this->_proc->setRenderConf('Xhtml', 'Wikilink2', $this->_getLinkConf());
                $this->_proc->setRenderConf('Xhtml', 'Freelink2', $this->_getLinkConf());
                $this->_proc->setRenderConf('Xhtml', 'Toc2', array('title' => '<h2>' . _("Table of Contents") . '</h2>'));
                $this->_proc->setRenderConf('Xhtml', 'Table', array('css_table' => 'horde-table'));
                break;
        }
        $autoloader = $GLOBALS['injector']->getInstance('Horde_Autoloader');
        $autoloader->addClassPathMapper(new Horde_Autoloader_ClassPathMapper_Prefix('/^Text_Wiki_Render_' . $output_format . '/', WICKED_BASE . '/lib/Text_Wiki/Render/' . $output_format));
        $autoloader->addClassPathMapper(new Horde_Autoloader_ClassPathMapper_Prefix('/^Text_Wiki_Parse/', WICKED_BASE . '/lib/Text_Wiki/Parse/' . $GLOBALS['conf']['wicked']['format']));
        return $this->_proc;
    }

Usage Example

Ejemplo n.º 1
0
<?php

/**
 * Copyright 2004-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @author Chuck Hagenbuch <*****@*****.**>
 */
require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('wicked');
if (!($text = Horde_Util::getFormData('page_text'))) {
    exit;
}
$view = $injector->createInstance('Horde_View');
$page = new Wicked_Page();
$view->text = $page->getProcessor()->transform($text);
Wicked::setTopbar();
$page_output->header(array('title' => sprintf(_("Edit %s"), Horde_Util::getFormData('age'))));
$notification->notify(array('listeners' => 'status'));
echo $view->render('edit/preview');
$page_output->footer();