Esempio n. 1
0
File: Text.php Progetto: kix/mdash
 /**
  * Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки
  *
  * @return void
  */
 protected function build_paragraphs()
 {
     $r = mb_strpos($this->_text, '<' . self::BASE64_PARAGRAPH_TAG . '>');
     $p = Util::rstrpos($this->_text, '</' . self::BASE64_PARAGRAPH_TAG . '>');
     if ($r !== false && $p !== false) {
         $beg = mb_substr($this->_text, 0, $r);
         $end = mb_substr($this->_text, $p + mb_strlen('</' . self::BASE64_PARAGRAPH_TAG . '>'));
         $this->_text = (trim($beg) ? $this->do_paragraphs($beg) . "\n" : "") . '<' . self::BASE64_PARAGRAPH_TAG . '>' . mb_substr($this->_text, $r + mb_strlen('<' . self::BASE64_PARAGRAPH_TAG . '>'), $p - ($r + mb_strlen('<' . self::BASE64_PARAGRAPH_TAG . '>'))) . '</' . self::BASE64_PARAGRAPH_TAG . '>' . (trim($end) ? "\n" . $this->do_paragraphs($end) : "");
     } else {
         $this->_text = $this->do_paragraphs($this->_text);
     }
 }
Esempio n. 2
0
File: Quote.php Progetto: kix/mdash
 protected function build_sub_quotations()
 {
     global $__ax, $__ay;
     $okposstack = array('0');
     $okpos = 0;
     $level = 0;
     $off = 0;
     while (true) {
         $p = Util::strpos_ex($this->_text, array("&laquo;", "&raquo;"), $off);
         if ($p === false) {
             break;
         }
         if ($p['str'] == "&laquo;") {
             if ($level > 0) {
                 if (!$this->is_on('no_bdquotes')) {
                     $this->inject_in($p['pos'], self::QUOTE_CRAWSE_OPEN);
                 }
             }
             $level++;
         }
         if ($p['str'] == "&raquo;") {
             $level--;
             if ($level > 0) {
                 if (!$this->is_on('no_bdquotes')) {
                     $this->inject_in($p['pos'], self::QUOTE_CRAWSE_CLOSE);
                 }
             }
         }
         $off = $p['pos'] + strlen($p['str']);
         if ($level == 0) {
             $okpos = $off;
             array_push($okposstack, $okpos);
         } elseif ($level < 0) {
             // уровень стал меньше нуля
             if (!$this->is_on('no_inches')) {
                 do {
                     $lokpos = array_pop($okposstack);
                     $k = substr($this->_text, $lokpos, $off - $lokpos);
                     $k = str_replace(self::QUOTE_CRAWSE_OPEN, self::QUOTE_FIRS_OPEN, $k);
                     $k = str_replace(self::QUOTE_CRAWSE_CLOSE, self::QUOTE_FIRS_CLOSE, $k);
                     //$k = preg_replace("/(^|[^0-9])([0-9]+)\&raquo\;/ui", '\1\2&Prime;', $k, 1, $amount);
                     $amount = 0;
                     $__ax = preg_match_all("/(^|[^0-9])([0-9]+)\\&raquo\\;/ui", $k, $m);
                     $__ay = 0;
                     if ($__ax) {
                         $k = preg_replace_callback("/(^|[^0-9])([0-9]+)\\&raquo\\;/ui", create_function('$m', 'global $__ax,$__ay; $__ay++; if ($__ay==$__ax) { return $m[1].$m[2]."&Prime;";} return $m[0];'), $k);
                         $amount = 1;
                     }
                 } while ($amount == 0 && count($okposstack));
                 // успешно сделали замену
                 if ($amount == 1) {
                     // заново просмотрим содержимое
                     $this->_text = substr($this->_text, 0, $lokpos) . $k . substr($this->_text, $off);
                     $off = $lokpos;
                     $level = 0;
                     continue;
                 }
                 // иначе просто заменим последнюю явно на &quot; от отчаяния
                 if ($amount == 0) {
                     // говорим, что всё в порядке
                     $level = 0;
                     $this->_text = substr($this->_text, 0, $p['pos']) . '&quot;' . substr($this->_text, $off);
                     $off = $p['pos'] + strlen('&quot;');
                     $okposstack = array($off);
                     continue;
                 }
             }
         }
     }
     // не совпало количество, отменяем все подкавычки
     if ($level != 0) {
         // закрывающих меньше, чем надо
         if ($level > 0) {
             $k = substr($this->_text, $okpos);
             $k = str_replace(self::QUOTE_CRAWSE_OPEN, self::QUOTE_FIRS_OPEN, $k);
             $k = str_replace(self::QUOTE_CRAWSE_CLOSE, self::QUOTE_FIRS_CLOSE, $k);
             $this->_text = substr($this->_text, 0, $okpos) . $k;
         }
     }
 }
Esempio n. 3
0
File: Util.php Progetto: kix/mdash
 /**
  * Кодирует спец блок
  *
  * @param  string $text
  * @return string
  */
 public static function iblock($text)
 {
     return \EMT\Util::INTERNAL_BLOCK_OPEN . \EMT\Util::encrypt_tag($text) . \EMT\Util::INTERNAL_BLOCK_CLOSE;
 }
Esempio n. 4
0
 /**
  * Создание защищенного тега с содержимым
  *
  * @see    EMT_lib::build_safe_tag
  * @param  string $content
  * @param  string $tag
  * @param  array $attribute
  * @return string
  */
 protected function tag($content, $tag = 'span', $attribute = array())
 {
     if (isset($attribute['class'])) {
         $classname = $attribute['class'];
         if ($classname == "nowrap") {
             if (!$this->is_on('nowrap')) {
                 $tag = "nobr";
                 $attribute = array();
                 $classname = "";
             }
         }
         if (isset($this->classes[$classname])) {
             $style_inline = $this->classes[$classname];
             if ($style_inline) {
                 $attribute['__style'] = $style_inline;
             }
         }
         $classname = isset($this->class_names[$classname]) ? $this->class_names[$classname] : $classname;
         $classname = ($this->class_layout_prefix ? $this->class_layout_prefix : "") . $classname;
         $attribute['class'] = $classname;
     }
     return Util::build_safe_tag($content, $tag, $attribute, $this->use_layout === false ? Util::LAYOUT_STYLE : $this->use_layout);
 }