Exemple #1
0
 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;
 }
Exemple #2
0
 protected function tokenBemElementToCode($token)
 {
     $code = "<?php";
     $str = $this->childrenGetPlain($token);
     if ($str !== false) {
         $el_parts = Template::bemParseStr($str);
         $full_name = "\$this->bemGetBlock().'__" . $el_parts['name'] . "'";
         if (count($el_parts['modifiers']) === 0) {
             $code .= ' echo ' . $full_name . '; ?>';
         } else {
             $code .= " \$full_name = " . $full_name . "; ";
             $class = array("\$full_name");
             foreach ($el_parts['modifiers'] as $mod) {
                 $class[] = "\$full_name.'_" . $mod . "'";
             }
             $code .= " echo " . join(".' '.", $class) . "; ?>";
         }
         if (count($el_parts['plain']) > 0) {
             $code .= ' ' . join(' ', $el_parts['plain']);
         }
         return $code;
         //$code .= "echo join(' ', \$el_parts['plain']);\n";
     }
     $code .= "\nob_start();\n";
     $this->pushState('edit', false);
     $code .= $this->childrenToCode($token);
     $this->popState('edit');
     $code .= '$el_string = ob_get_clean();' . "\n";
     $code .= '$el_parts = \\Floxim\\Floxim\\Template\\Template::bemParseStr($el_string);' . "\n";
     $code .= "\$full_name = \$this->bemGetBlock().'__'.\$el_parts['name'];\n";
     $code .= "echo \$full_name.' ';\n";
     $code .= "foreach (\$el_parts['modifiers'] as \$mod) {\n";
     $code .= "echo \$full_name.'_'.\$mod.' ';\n";
     $code .= "}\n";
     $code .= "echo join(' ', \$el_parts['plain']);\n";
     $code .= "?>";
     return $code;
 }