public function route($url = null, $context = null) { if ($url instanceof \Floxim\Main\Page\Entity) { $url = fx::collection(array($url)); } if ($url instanceof \Floxim\Floxim\System\Collection) { $path = $url; $url = $path->last()->get('url'); } else { $url = preg_replace("~^/~", '', $url); $path = $this->getPath($url, $context['site_id']); if (!$path) { return; } } $page = $path->last(); if (!$page) { return null; } else { $url = preg_replace("~\\?.+\$~", '', $url); if ($url && !$page->hasVirtualPath() && urldecode($url) != $page['url'] && $page['url'] !== '404/') { fx::http()->redirect($page['url'], 301); fx::debug($url, '!=', $page['url']); die; } } fx::env('page', $page); fx::http()->status('200'); $layout_ib = $this->getLayoutInfoblock($page); fx::trigger('before_layout_render', array('layout_infoblock' => $layout_ib)); $res = $layout_ib->render(); return $res; }
public function parse($string) { $this->state_stack = array(); $this->prev_state = null; $this->position = 0; $this->state = $this->init_state; $this->parts = $this->splitString($string); if ($this->debug) { fx::debug($string, $this->parts); } while (($ch = current($this->parts)) !== false) { $this->position += mb_strlen($ch); $this->step($ch); next($this->parts); } return $this->res; }
/** * Convert the tree of tokens in the php code * @param string $tree source code of the template * @return string of php code */ public function compile($tree, $class_name) { $code = $this->makeCode($tree, $class_name); $code = self::addTabs($code); if (fx::config('templates.check_php_syntax')) { $is_correct = self::isPhpSyntaxCorrect($code); if ($is_correct !== true) { $error_line = $is_correct[1][1]; $lines = explode("\n", $code); $lines[$error_line - 1] = '[[bad ' . $lines[$error_line - 1] . ']]'; $lined = join("\n", $lines); $error = $is_correct[0] . ': ' . $is_correct[1][0] . ' (line ' . $error_line . ')'; fx::debug($error, $lined); fx::log($error, $is_correct, $lined); throw new \Exception('Syntax error'); } } return $code; }
protected function prepareFileData($file_data, $file) { // convert fx::attributes to the canonical Smarty-syntax $T = new Html($file_data); try { $file_data = $T->transformToFloxim(); } catch (\Exception $e) { fx::debug('Floxim html parser error', $e->getMessage(), $file); } // remove fx-comments $file_data = preg_replace("~\\{\\*.*?\\*\\}~s", '', $file_data); $file_data = trim($file_data); if (!preg_match("~^{(template|preset)~", $file_data)) { $file_data = $this->wrapFile($file, $file_data); } return $file_data; }
public function dropAll() { fx::debug()->dropAll(); return array('reload' => '#admin.log.all'); }