Пример #1
0
 /**
  * Запустить типограф на выполнение
  *
  */
 public function apply($trets = null)
 {
     $this->ok = false;
     $this->init();
     $this->_init();
     $atrets = $this->trets;
     if (is_string($trets)) {
         $atrets = array($trets);
     } elseif (is_array($trets)) {
         $atrets = $trets;
     }
     $this->debug($this, 'init', $this->_text);
     $this->_text = $this->safe_blocks($this->_text, true);
     $this->debug($this, 'safe_blocks', $this->_text);
     $this->_text = EMT_Lib::safe_tag_chars($this->_text, true);
     $this->debug($this, 'safe_tag_chars', $this->_text);
     $this->_text = EMT_Lib::clear_special_chars($this->_text);
     $this->debug($this, 'clear_special_chars', $this->_text);
     foreach ($atrets as $tret) {
         // если установлен режим разметки тэгов то выставим его
         if ($this->use_layout_set) {
             $this->tret_objects[$tret]->set_tag_layout_ifnotset($this->use_layout);
         }
         if ($this->class_layout_prefix) {
             $this->tret_objects[$tret]->set_class_layout_prefix($this->class_layout_prefix);
         }
         // влючаем, если нужно
         if ($this->debug_enabled) {
             $this->tret_objects[$tret]->debug_on();
         }
         if ($this->logging) {
             $this->tret_objects[$tret]->logging = true;
         }
         // применяем трэт
         //$this->tret_objects[$tret]->set_text(&$this->_text);
         $this->tret_objects[$tret]->set_text($this->_text);
         $this->tret_objects[$tret]->apply();
         // соберём ошибки если таковые есть
         if (count($this->tret_objects[$tret]->errors) > 0) {
             foreach ($this->tret_objects[$tret]->errors as $err) {
                 $this->tret_error($tret, $err['info'], $err['data']);
             }
         }
         // логгирование
         if ($this->logging) {
             if (count($this->tret_objects[$tret]->logs) > 0) {
                 foreach ($this->tret_objects[$tret]->logs as $log) {
                     $this->tret_log($tret, $log['info'], $log['data']);
                 }
             }
         }
         // отладка
         if ($this->debug_enabled) {
             foreach ($this->tret_objects[$tret]->debug_info as $di) {
                 $unsafetext = $di['text'];
                 $unsafetext = EMT_Lib::safe_tag_chars($unsafetext, false);
                 $unsafetext = $this->safe_blocks($unsafetext, false);
                 $this->debug($tret, $di['place'], $unsafetext, $di['text']);
             }
         }
     }
     $this->_text = $this->decode_internal_blocks($this->_text);
     $this->debug($this, 'decode_internal_blocks', $this->_text);
     if ($this->is_on('dounicode')) {
         EMT_Lib::convert_html_entities_to_unicode($this->_text);
     }
     $this->_text = EMT_Lib::safe_tag_chars($this->_text, false);
     $this->debug($this, 'unsafe_tag_chars', $this->_text);
     $this->_text = $this->safe_blocks($this->_text, false);
     $this->debug($this, 'unsafe_blocks', $this->_text);
     if (!$this->disable_notg_replace) {
         $repl = array('<span class="_notg_start"></span>', '<span class="_notg_end"></span>');
         if ($this->remove_notg) {
             $repl = "";
         }
         $this->_text = str_replace(array('<notg>', '</notg>'), $repl, $this->_text);
     }
     $this->_text = trim($this->_text);
     $this->ok = count($this->errors) == 0;
     return $this->_text;
 }