/**
  * Расстановка защищенных тегов параграфа (<p>...</p>) и переноса строки
  *
  * @return  void
  */
 protected function build_paragraphs()
 {
     $r = mb_strpos($this->_text, '<' . self::BASE64_PARAGRAPH_TAG . '>');
     $p = EMTLib::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
 /**
  * Установить настройку
  *
  * @param mixed $selector
  * @param string $setting
  * @param mixed $value
  */
 protected function doset($selector, $key, $value)
 {
     $tret_pattern = false;
     $rule_pattern = false;
     //if(($selector === false) || ($selector === null) || ($selector === false) || ($selector === "*")) $type = 0;
     if (is_string($selector)) {
         if (strpos($selector, ".") === false) {
             $tret_pattern = $selector;
         } else {
             $pa = explode(".", $selector);
             $tret_pattern = $pa[0];
             array_shift($pa);
             $rule_pattern = implode(".", $pa);
         }
     }
     EMTLib::_process_selector_pattern($tret_pattern);
     EMTLib::_process_selector_pattern($rule_pattern);
     if ($selector == "*") {
         $this->settings[$key] = $value;
     }
     foreach ($this->trets as $tret) {
         $t1 = $this->get_short_tret($tret);
         if (!EMTLib::_test_pattern($tret_pattern, $t1)) {
             if (!EMTLib::_test_pattern($tret_pattern, $tret)) {
                 continue;
             }
         }
         $tret_obj = $this->get_tret($tret);
         if ($key == "active") {
             foreach ($tret_obj->rules as $rulename => $v) {
                 if (!EMTLib::_test_pattern($rule_pattern, $rulename)) {
                     continue;
                 }
                 if (strtolower($value) === "on" || $value === 1 || $value === true || $value == "1") {
                     $tret_obj->enable_rule($rulename);
                 }
                 if (strtolower($value) === "off" || $value === 0 || $value === false || $value == "0") {
                     $tret_obj->disable_rule($rulename);
                 }
             }
         } else {
             if ($rule_pattern === false) {
                 $tret_obj->set($key, $value);
             } else {
                 foreach ($tret_obj->rules as $rulename => $v) {
                     if (!EMTLib::_test_pattern($rule_pattern, $rulename)) {
                         continue;
                     }
                     $tret_obj->set_rule($rulename, $key, $value);
                 }
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * Кодирует спец блок
  *
  * @param 	string $text
  * @return  string
  */
 public static function iblock($text)
 {
     return EMTLib::INTERNAL_BLOCK_OPEN . EMTLib::encrypt_tag($text) . EMTLib::INTERNAL_BLOCK_CLOSE;
 }
Esempio n. 4
0
 /**
  * Создание защищенного тега с содержимым
  *
  * @see 	EMTLib::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 EMTLib::build_safe_tag($content, $tag, $attribute, $this->use_layout === false ? EMTLib::LAYOUT_STYLE : $this->use_layout);
 }
 protected function build_sub_quotations()
 {
     global $__ax, $__ay;
     $exp = strpos($this->_text, "</cA===>") !== false ? "</cA===>" : (strpos($this->_text, "\r\n") !== false ? "\r\n\r\n" : "\n\n");
     $texts_in = explode($exp, $this->_text);
     $texts_out = array();
     foreach ($texts_in as $textx) {
         $okposstack = array('0');
         $okpos = 0;
         $level = 0;
         $off = 0;
         while (true) {
             $p = EMTLib::strpos_ex($textx, 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, $textx);
                     }
                 }
                 $level++;
             }
             if ($p['str'] == "&raquo;") {
                 $level--;
                 if ($level > 0) {
                     if (!$this->is_on('no_bdquotes')) {
                         $this->inject_in($p['pos'], self::QUOTE_CRAWSE_CLOSE, $textx);
                     }
                 }
             }
             $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($textx, $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) {
                         // заново просмотрим содержимое
                         $textx = substr($textx, 0, $lokpos) . $k . substr($textx, $off);
                         $off = $lokpos;
                         $level = 0;
                         continue;
                     }
                     // иначе просто заменим последнюю явно на &quot; от отчаяния
                     if ($amount == 0) {
                         // говорим, что всё в порядке
                         $level = 0;
                         $textx = substr($textx, 0, $p['pos']) . '&quot;' . substr($textx, $off);
                         $off = $p['pos'] + strlen('&quot;');
                         $okposstack = array($off);
                         continue;
                     }
                 }
             }
         }
         // не совпало количество, отменяем все подкавычки
         if ($level != 0) {
             // закрывающих меньше, чем надо
             if ($level > 0) {
                 $k = substr($textx, $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);
                 $textx = substr($textx, 0, $okpos) . $k;
             }
         }
         $texts_out[] = $textx;
     }
     $this->_text = implode($exp, $texts_out);
 }