public function render($data = array()) { if (isset($data['_idle'])) { $this->context->isIdle(true); unset($data['_idle']); } if (count($data) > 0) { $this->context->push($data); } ob_start(); if (!is_null($this->forced_method)) { $method = $this->forced_method; } else { $method = self::getActionMethod($this->action, $this->context); if (!$method) { throw new \Exception('No template: ' . get_class($this) . '.' . $this->action); } } if ($this->level > 50) { fx::log('recursion in', get_class($this), $method); return '<div class="fx_template_error">bad recursion?</div>'; } $profiler = $this->getProfiler(); if ($profiler) { $sign = preg_replace("~^fx_template_~", '', get_class($this)) . '::' . preg_replace("~^tpl_~", '', $method); $profiler->block('<b style="color:#009;">tpl:</b> ' . $sign); } try { $this->{$method}($this->context); } catch (\Exception $e) { if (preg_match("~Less_Exception~", get_class($e))) { fx::log('Less compiler exception', get_class($this) . ':' . $method, $e->getMessage(), $e->currentFile); } else { fx::log('template exception', $e->getMessage()); } } $result = ob_get_clean(); if (fx::isAdmin()) { if ($this->context->isIdle()) { if ($profiler) { $profiler->stop(); } return $result; } if (!$this->parent) { self::$count_replaces++; $result = Template::replaceAreas($result); $result = Field::replaceFields($result); } } if ($profiler) { $profiler->stop(); } return $result; }
protected static function replaceFieldsInText($html) { $html = preg_replace_callback("~###fxf(\\d+)###~", function ($matches) { $replacement = Field::$replacements[$matches[1]]; if (isset($replacement[1]['html']) && $replacement[1]['html'] || isset($replacement[1]['type']) && $replacement[1]['type'] == 'html') { $tag_name = 'div'; } else { $tag_name = Html::getWrapperTag($replacement[2]); } $tag = HtmlToken::createStandalone('<' . $tag_name . '>'); unset($replacement[1]['stored_value']); $tag->addMeta(array('class' => 'fx_template_var', 'data-fx_var' => $replacement[1])); //fx_template_field::$replacements[$matches[1]] = null; Field::$fields_to_drop[] = $matches[1]; $res = $tag->serialize() . Field::replaceFields($replacement[2]) . '</' . $tag_name . '>'; return $res; }, $html); return $html; }