Example #1
0
 /**
  * @return \Texy
  */
 public function createTexyForComment()
 {
     $texy = new \Texy();
     $texy->headingModule->top = 3;
     $texy->setOutputMode(\Texy::HTML5);
     // Images
     $texy->imageModule->root = '.' . $this->imagesRoot;
     $texy->imageModule->fileRoot = $this->imagesFileRoot;
     \TexyConfigurator::safeMode($texy);
     \TexyConfigurator::disableImages($texy);
     //$texy->allowed['blockquote'] = false;
     $texy->allowed['emoticon'] = false;
     $texy->allowed['heading/underlined'] = false;
     $texy->allowed['heading/surrounded'] = false;
     $texy->allowed['horizline'] = false;
     //$texy->allowed['html/tag'] = false;
     $texy->allowed['html/comment'] = false;
     //$texy->allowed['list'] = false;
     //$texy->allowed['list/definition'] = false;
     $texy->allowed['script'] = false;
     $texy->allowed['table'] = false;
     $texy->linkModule->forceNoFollow = true;
     $texy->addHandler('block', [$this, 'blockHandler']);
     return $texy;
 }
Example #2
0
 /**
  * Обработать строку (вся разметка):
  */
 public static function markup($text, $safeMode = true, $links = true, $board = null)
 {
     $texy = self::createTexyObject($links, $board);
     if ($safeMode) {
         TexyConfigurator::safeMode($texy);
         TexyConfigurator::disableImages($texy);
     }
     return $texy->process($text);
 }
Example #3
0
 public function __construct()
 {
     parent::__construct();
     // safe mode
     \TexyConfigurator::safeMode($this);
     // output
     $this->setOutputMode(self::HTML4_TRANSITIONAL);
     $this->htmlOutputModule->removeOptional = false;
     self::$advertisingNotice = false;
     $this->allowed['heading/surrounded'] = false;
     $this->allowed['heading/underlined'] = false;
     $this->allowed['link/definition'] = false;
     $this->allowed['image/definition'] = false;
     $this->mergeLines = false;
     $this->addHandler('phrase', array(__CLASS__, 'linkHandler'));
 }
Example #4
0
 public function __construct()
 {
     parent::__construct();
     // output
     $this->setOutputMode(self::HTML4_TRANSITIONAL);
     $this->htmlOutputModule->removeOptional = false;
     self::$advertisingNotice = false;
     // safe mode
     TexyConfigurator::safeMode($this);
     $this->allowed['heading/surrounded'] = false;
     $this->allowed['heading/underlined'] = false;
     $this->allowed['link/definition'] = false;
     $this->allowed['image/definition'] = false;
     // spojování textu v odstavcích po enteru
     $this->mergeLines = true;
     // přidání target="_blank" k odkazům
     // $this->addHandler('phrase', array(__CLASS__, 'addTargetHandler'));
 }
Example #5
0
    // processing
    $text = file_get_contents('sample.texy');
    $html = $texy->process($text);
    // that's all folks!
    // echo formated output
    echo $html;
    // and echo generated HTML code
    echo '<pre>';
    echo htmlSpecialChars($html);
    echo '</pre>';
    echo '<hr />';
}
header('Content-type: text/html; charset=utf-8');
echo '<h2>Enable nearly all valid tags</h2>';
// by default
doIt($texy);
echo '<h2>Texy::ALL - enables all tags</h2>';
$texy->allowedTags = Texy::ALL;
doIt($texy);
echo '<h2>safeMode() - enables only some "safe" tags</h2>';
TexyConfigurator::safeMode($texy);
doIt($texy);
echo '<h2>disableLinks() - disable all links</h2>';
TexyConfigurator::disableLinks($texy);
doIt($texy);
echo '<h2>Texy::NONE - disables all tags</h2>';
$texy->allowedTags = Texy::NONE;
doIt($texy);
echo '<h2>Enable custom tags</h2>';
$texy->allowedTags = array('myExtraTag' => array('attr1'), 'strong' => array());
doIt($texy);
Example #6
0
    }
    return $invocation->proceed();
}
$GLOBALS['wiki_format'] = function (&$content) {
    $cache = $GLOBALS['dir']['cache'] . md5($content) . $GLOBALS['cache_ext'];
    if ($GLOBALS['enable_cache'] && file_exists($cache)) {
        $content = file_get_contents($cache) . '<!-- THIS FILE WAS CACHED IN ' . $cache . ' -->';
    } else {
        if (!(require_once $GLOBALS['texy_path'])) {
            wiki_perror('Cannot load: ' . $GLOBALS['texy_path']);
            return false;
        }
        if (!isset($GLOBALS['texy'])) {
            $GLOBALS['texy'] = new Texy();
            if ($GLOBALS['paranoia']) {
                TexyConfigurator::safeMode($GLOBALS['texy']);
            }
            $GLOBALS['texy']->encoding = $GLOBALS['charset_encoding'];
            $GLOBALS['texy']->htmlOutputModule->baseIndent = 4;
            //$GLOBALS['texy']->linkModule->root = '?page=';
            $GLOBALS['texy']->addHandler('phrase', 'wiki_texy_phraseHandler');
            $GLOBALS['texy']->registerLinePattern('wiki_texy_InlineHandler', '#(?<!\\[\\[)\\[\\[(?!\\ |\\[\\[)(.+)' . TEXY_MODIFIER . '?(?<!\\ |\\]\\])\\]\\](?!\\]\\])()#U', 'wikilink');
            /*$GLOBALS['texy']->registerLinePattern(
                'wiki_texy_InlineHandler',  // callback function or method
                '#(?<!\[)\[(?!\ |\[)(.+)'.TEXY_MODIFIER.'?(?<!\ |\])\](?!\])()#U', // regular expression
                'wikilink' // any syntax name
              );*/
        }
        $content = $GLOBALS['texy']->process($content);
        file_put_contents($cache, $content);
    }
Example #7
0
    $el = TexyHtml::el('a');
    $el->attrs['href'] = '#comm-' . $refName;
    // set link destination
    $el->attrs['class'][] = 'comment';
    // set class name
    $el->attrs['rel'] = 'nofollow';
    // enable rel="nofollow"
    $el->setText("[{$refName}] {$name}:");
    // set link label (with Texy formatting)
    return $el;
}
$texy = new Texy();
// references link [1] [2] will be processed through user function
$texy->addHandler('newReference', 'newReferenceHandler');
// configuration
TexyConfigurator::safeMode($texy);
// safe mode prevets attacker to inject some HTML code and disable images
// how generally disable links or enable images? here is a way:
//    $disallow = array('image', 'figure', 'linkReference', 'linkEmail', 'linkURL', 'linkQuick');
//    foreach ($diallow as $item)
//        $texy->allowed[$item] = FALSE;
// processing
$text = file_get_contents('sample.texy');
$html = $texy->process($text);
// that's all folks!
// echo formated output
header('Content-type: text/html; charset=utf-8');
echo $html;
// do some antispam filtering - this is just very simple example ;-)
$spam = FALSE;
foreach ($texy->summary['links'] as $link) {