public function process($text, $singleLine = FALSE)
 {
     if ($this->processing) {
         throw new InvalidStateException('Processing is in progress yet.');
     }
     $this->marks = array();
     $this->processing = TRUE;
     if (is_array($this->allowedClasses)) {
         $this->_classes = array_flip($this->allowedClasses);
     } else {
         $this->_classes = $this->allowedClasses;
     }
     if (is_array($this->allowedStyles)) {
         $this->_styles = array_flip($this->allowedStyles);
     } else {
         $this->_styles = $this->allowedStyles;
     }
     $text = TexyUtf::toUtf($text, $this->encoding);
     if ($this->removeSoftHyphens) {
         $text = str_replace("Β­", '', $text);
     }
     $text = self::normalize($text);
     $this->tabWidth = max(1, (int) $this->tabWidth);
     while (strpos($text, "\t") !== FALSE) {
         $text = preg_replace_callback('#^(.*)\\t#mU', array($this, 'tabCb'), $text);
     }
     $this->invokeHandlers('beforeParse', array($this, &$text, $singleLine));
     $this->_linePatterns = $this->linePatterns;
     $this->_blockPatterns = $this->blockPatterns;
     foreach ($this->_linePatterns as $name => $foo) {
         if (empty($this->allowed[$name])) {
             unset($this->_linePatterns[$name]);
         }
     }
     foreach ($this->_blockPatterns as $name => $foo) {
         if (empty($this->allowed[$name])) {
             unset($this->_blockPatterns[$name]);
         }
     }
     $this->DOM = TexyHtml::el();
     if ($singleLine) {
         $this->DOM->parseLine($this, $text);
     } else {
         $this->DOM->parseBlock($this, $text);
     }
     $this->invokeHandlers('afterParse', array($this, $this->DOM, $singleLine));
     $html = $this->DOM->toHtml($this);
     if (self::$advertisingNotice) {
         $html .= "\n<!-- by Texy2! -->";
         if (self::$advertisingNotice === 'once') {
             self::$advertisingNotice = FALSE;
         }
     }
     $this->processing = FALSE;
     return TexyUtf::utf2html($html, $this->encoding);
 }
Exemple #2
0
 /**
  * Converts document in Texy! to (X)HTML code.
  *
  * @param  string   input text
  * @param  bool     is single line?
  * @return string   output HTML code
  */
 public function process($text, $singleLine = FALSE)
 {
     if ($this->processing) {
         throw new InvalidStateException('Processing is in progress yet.');
     }
     // initialization
     $this->marks = array();
     $this->processing = TRUE;
     // speed-up
     if (is_array($this->allowedClasses)) {
         $this->_classes = array_flip($this->allowedClasses);
     } else {
         $this->_classes = $this->allowedClasses;
     }
     if (is_array($this->allowedStyles)) {
         $this->_styles = array_flip($this->allowedStyles);
     } else {
         $this->_styles = $this->allowedStyles;
     }
     // convert to UTF-8 (and check source encoding)
     $text = TexyUtf::toUtf($text, $this->encoding);
     if ($this->removeSoftHyphens) {
         $text = str_replace("­", '', $text);
     }
     // standardize line endings and spaces
     $text = self::normalize($text);
     // replace tabs with spaces
     $this->tabWidth = max(1, (int) $this->tabWidth);
     while (strpos($text, "\t") !== FALSE) {
         $text = preg_replace_callback('#^(.*)\\t#mU', array($this, 'tabCb'), $text);
     }
     // user before handler
     $this->invokeHandlers('beforeParse', array($this, &$text, $singleLine));
     // select patterns
     $this->_linePatterns = $this->linePatterns;
     $this->_blockPatterns = $this->blockPatterns;
     foreach ($this->_linePatterns as $name => $foo) {
         if (empty($this->allowed[$name])) {
             unset($this->_linePatterns[$name]);
         }
     }
     foreach ($this->_blockPatterns as $name => $foo) {
         if (empty($this->allowed[$name])) {
             unset($this->_blockPatterns[$name]);
         }
     }
     // parse Texy! document into internal DOM structure
     $this->DOM = TexyHtml::el();
     if ($singleLine) {
         $this->DOM->parseLine($this, $text);
     } else {
         $this->DOM->parseBlock($this, $text);
     }
     // user after handler
     $this->invokeHandlers('afterParse', array($this, $this->DOM, $singleLine));
     // converts internal DOM structure to final HTML code
     $html = $this->DOM->toHtml($this);
     // this notice should remain
     if (self::$advertisingNotice) {
         $html .= "\n<!-- by Texy2! -->";
         if (self::$advertisingNotice === 'once') {
             self::$advertisingNotice = FALSE;
         }
     }
     $this->processing = FALSE;
     return TexyUtf::utf2html($html, $this->encoding);
 }
Exemple #3
0
<?php

require_once dirname(__FILE__) . '/texy.min.php';
if ($_SERVER["argc"] == 2) {
    Texy::$advertisingNotice = NULL;
    $texy = new Texy();
    $texy->imageModule->root = '';
    $texy->imageModule->linkedRoot = '';
    echo trim($texy->process($_SERVER["argv"][1]));
} else {
    echo "Texy! " . Texy::VERSION;
}
Exemple #4
0
 static function formattingByTexy($source)
 {
     static $texy;
     if (is_null($texy)) {
         if (!class_exists('Texy', false)) {
             $dir = Q::ini('vendor_dir');
             require_once "{$dir}/geshi/geshi.php";
             require_once "{$dir}/texy/texy.php";
         }
         Texy::$advertisingNotice = false;
         $texy = new Texy();
         $options = self::$_texy_options;
         foreach ($options as $module => $config) {
             foreach ($config as $key => $value) {
                 $m = $module . 'Module';
                 $texy->{$m}->{$key} = $value;
             }
         }
         $texy->addHandler('block', array(__CLASS__, 'texyBlockHandler'));
     }
     return $texy->process($source);
 }
Exemple #5
0
function texyla($content, $texyCfg, $charset = 'utf-8', $oneLine = false)
{
    if (empty($content)) {
        # protože je obsah prázdný vrátíme ho prázdný zpátky bez zpracování
        return $content;
    }
    if (!function_exists('iconv') && $charset != 'utf-8') {
        # ověření existence fce iconv(), která se používá pro zmenu
        # kodování vstupního textu při jiném než utf-8 kodování
        trigger_error(texylaErrorMsg(TEXYLA_ICONV_MISSING), E_USER_ERROR);
    }
    # jaky pouzit configurační soubor pro zpracování vstupního textu
    # defaultní hodnota je forum, takže není třeba uvádět.
    $texyCfg = texylaTexyCfg($texyCfg);
    # sestaveni cesty ke konfigu
    $texyCfgFile = dirname(__FILE__) . '/cfg/' . $texyCfg . '.php';
    if (!is_bool($oneLine)) {
        # pokud není bool nastavíme na false (blokový text)
        $oneLine = false;
    }
    if (!class_exists('Texy')) {
        # Neexistuje třída Texy
        trigger_error(texylaErrorMsg(TEXYLA_CLASS_NOT_TEXY_FOUND, $texyFile), E_USER_ERROR);
    }
    # iniciace texy
    $texy = new Texy();
    $texy->alignClasses['left'] = 'fl';
    $texy->alignClasses['right'] = 'fr';
    # nastavíme kódování v kterém je zpracováváný text
    # default je utf-8, není třeba uvádět při volání funkce texyla() [pokud nenásleduje další parametr]
    $texy->encoding = $charset;
    # proměnná, podle které se řídí přidávání hlášky  <!-- by Texy2! --> na konec zpracovávaného textu
    # $GLOBALS['Texy::$advertisingNotice'] = false;
    # verze pro php5
    Texy::$advertisingNotice = false;
    # Odstranění diakritiky z textu, vytvoření
    if ($texyCfg == 'webalize') {
        /*
        	*******************************************************************************************
        	!!! Toto je v Testovací fázi !!! Bugreporty prosím na http://texyla.jaknato.com/khostu.php
        	*******************************************************************************************
        	Jedná se o odstranění diakritiky...
        	Výsledek obsahuje pouze a-z, čísla a spojovník.
        	Není třeba načítat konfiguraci, 
        	Pokud používáte jiné kódování než je utf-8, je text překodován na utf-8 a je z něj 
        	odstraněna diakritika, výsledný text je čisté ASCII, takže se zpštně nepřevádí na 
        	původní kódóvání.
        	Poznámky dgx k webalize:
        	========================
        		Je však možné povolit i další ASCII znaky:
        	
        			$nadpis = "článek/PHP 5.2.1 a funkce is_array()";
        			echo Texy::webalize($nadpis); // standardní chování
        	
        			→ clanek-php-5-2-1-a-funkce-is-array
        	
        			$addChar = '/_.';// navíc povolíme znaky: / _ .
        			echo Texy::webalize($nadpis,$addChar);
        			
        			→ clanek/php-5.2.1-a-funkce-is_array
        	
        			Ještě dodám, že funkce funguje korektně i při chybné implementaci iconv (glibc).
        */
        $content = strtolower($charset) == 'utf-8' ? $content : iconv($charset, 'utf-8', $content);
        $addChar = '';
        return Texy::webalize($content, $addChar);
    }
    # kontrola existence konfiguračního souboru
    if (!file_exists($texyCfgFile)) {
        # neexistuje (nebyl nalezen/includován) soubor s konfigurací pro texy
        return texylaErrorMsg(TEXYLA_FILE_CFG_NOT_FOUND, $texyCfgFile);
    }
    # includujeme soubor s nastavením pro Texy!
    if (!(include $texyCfgFile)) {
        # Nepodařilo se načíst konfigurační soubor,
        # nejspíš špatné práva pro přístup k souboru
        return texylaErrorMsg(TEXYLA_ACCESS_DENIED, $texyFile);
    }
    # kontrola existence pomocné třídy FshlHandler (propojení Texy s fshlParser)
    # a třídy fshlParser (ta se stará o samotné obarvení kodu)
    if (function_exists('TexylaFSHLBlockHandler') && class_exists('fshlParser') && !empty($useFSHL) && $useFSHL === true) {
        # iniciace pomocné třídy starající se o obarvení zdrojovách kódů
        # Autor třídy je: Juraj 'hvge' Durech
        $texy->addHandler('block', 'TexylaFSHLBlockHandler');
    }
    # Provedeme zpracování poslaného obsahu pomocí Texy!
    if (!empty($addTargetBlank) && $addTargetBlank === true) {
        return preg_replace_callback("~<a href~iU", "texylaAddTargetBlank", $texy->process($content, $oneLine));
    }
    return $texy->process($content, $oneLine);
}