public function checkUpdates() { $stored = $this->all(); $url = fx::config('fx.update_url') . '?action=find&from=' . fx::version(); @($res = file_get_contents($url)); if (!$res) { return false; } $res = @json_decode($res); if ($res) { foreach ($res as $patch) { if ($stored->findOne('to', $patch->to)) { continue; } $new_patch = $this->create(array('to' => $patch->to, 'from' => $patch->from, 'url' => $patch->url, 'created' => $patch->created)); if ($patch->from == fx::version()) { $new_patch['status'] = 'ready'; } else { $new_patch['status'] = 'pending'; } $new_patch->save(); } } return true; }
protected function getProfiler() { $profile = fx::config('dev.profile_controllers'); if ($profile) { return fx::profiler(); } }
public function setLang($lang = null) { if (!$lang) { $this->lang = fx::config('lang.admin'); } else { $this->lang = $lang; } }
public function getAvailableBlocks($page, $area_meta = null) { $controllers = fx::data('component')->all(); $controllers->concat(fx::data('widget')->all()); $result = array('controllers' => array(), 'actions' => array(), 'groups' => array('content' => array('name' => 'Данные'), 'content:infoblock' => array('name' => 'Новые данные', 'description' => 'Добавьте пустой блок и заполните его новыми данными.'), 'content:filtered' => array('name' => 'Данные по фильтру', 'description' => 'Добавьте блок для отображения существующих данных — всех, или ограниченных набором условий.'), 'content:selected' => array('name' => 'Данные, отобранные вручную', 'description' => 'Добавьте блок и внесите в него уже существующие данные, выбрав их из списка.'), 'widget' => array('name' => 'Виджеты'))); foreach ($controllers as $c) { if (fx::config()->isBlockDisabled($c['keyword'])) { continue; } $type = $c instanceof Component\Entity ? 'component' : 'widget'; $keyword = $c['keyword']; $result['controllers'][$keyword] = array('name' => $c['name'], 'keyword' => $keyword, 'type' => $type); $ctrl = fx::controller($keyword); $actions = $ctrl->getActions(); foreach ($actions as $action_code => $action_info) { // do not show actions starting with "_" if (preg_match("~^_~", $action_code)) { continue; } if (fx::config()->isBlockDisabled($c['keyword'], $action_code)) { continue; } if (isset($action_info['check_context'])) { $is_avail = call_user_func($action_info['check_context'], $page); if (!$is_avail) { continue; } } $act_ctr = fx::controller($keyword . ':' . $action_code); $act_templates = $act_ctr->getAvailableTemplates(fx::env('layout'), $area_meta); if (count($act_templates) == 0) { continue; } $action = array('controller' => $keyword, 'keyword' => $action_code, 'name' => $action_info['name'], 'id' => $keyword . ':' . $action_code); if (isset($action_info['group'])) { $action['group'] = $action_info['group']; } elseif ($type === 'component' && preg_match("~^list_(.+)\$~", $action_code, $list_type)) { $action['group'] = 'content'; $list_type = $list_type[1]; $action['subgroup'] = in_array($list_type, array('infoblock', 'selected')) ? $list_type : 'filtered'; } else { $action['group'] = 'widget'; } if (empty($action['name'])) { $action['name'] = $action_code; } $result['actions'][] = $action; } } //fx::log($result); return $result; }
public function execute($input) { if ($input['console_text']) { ob_start(); $code = $input['console_text']; fx::env('console', true); fx::config('dev.on', true); $code = self::preProcess($code); eval($code); $res = ob_get_clean(); return array('result' => $res); } }
public function route($url = null, $context = null) { $adm_path = '/' . fx::config('path.admin_dir_name') . '/'; if (trim($url, '/') === trim($adm_path, '/') && $url !== $adm_path) { fx::http()->redirect(fx::config('paht.admin'), 301); } if ($url !== $adm_path) { return null; } $input = fx::input()->makeInput(); $entity = fx::input()->fetchPost('entity'); $action = fx::input()->fetchPost('action'); if (!$entity || !$action) { fx::page()->setBaseUrl(FX_BASE_URL . '/' . trim($adm_path, '/')); return new Controller\Admin(); } $base_url = fx::input()->fetchPost('_base_url'); if ($base_url) { $base_path = fx::router()->getPath(fx::path()->removeBase($base_url)); if ($base_path) { fx::env('page', $base_path->last()); } } fx::env('ajax', true); $posting = fx::input()->fetchPost('posting'); if (!preg_match("~^module_~", $entity) || fx::input()->fetchPost('fx_admin')) { $entity = 'admin_' . $entity; } if ($posting && $posting !== 'false') { $action .= "_save"; } $path = explode('_', $entity, 2); if ($path[0] == 'admin') { $classname = 'Floxim\\Floxim\\Admin\\Controller\\' . fx::util()->underscoreToCamel($path[1]); } else { // todo: psr0 what? } try { $controller = new $classname($input, $action); } catch (\Exception $e) { die("Error! Entity: " . htmlspecialchars($entity)); } //header("Content-type: application/json; charset=utf-8"); return $controller; }
public function getByHostName($host = '') { if (!$host) { $host = fx::config()->HTTP_HOST; } $host = preg_replace("~^https?://~i", '', $host); $host = preg_replace("~/\$~", '', $host); $sites = $this->all(); if (count($sites) === 1) { return $sites->first(); } // search for the domain and the mirrors foreach ($sites as $site) { if (in_array($host, $site->getAllHosts())) { return $site; } } return $sites->first(); }
public function __construct() { $this->options['login'] = '******'; $this->options['action_link'] = fx::config('path.admin'); $this->addMoreMenu(Controller\Adminpanel::getMoreMenu()); $this->addButtons(Controller\Adminpanel::getButtons()); $main_menu = array('manage' => array('name' => fx::alang('Management', 'system'), 'key' => 'manage', 'href' => '/floxim/#admin.administrate.site.all'), 'develop' => array('name' => fx::alang('Development', 'system'), 'key' => 'develop', 'href' => '/floxim/#admin.component.all')); $site = fx::env('site'); if ($site) { $main_menu['site'] = array('name' => fx::env('site')->getLocalDomain(), 'key' => 'site', 'href' => '/'); $other_sites = fx::data('site')->where('id', $site['id'], '!=')->all(); if (count($other_sites) > 0) { $main_menu['site']['children'] = array(); foreach ($other_sites as $other_site) { $domain = $other_site->getLocalDomain(); $main_menu['site']['children'][] = array('name' => $domain, 'href' => 'http://' . $domain . '/'); } } } $this->addMainMenu($main_menu); }
/** * Perform all registered routers, to return most suitable controller * @param string $url * @param array $context * @return fx_controller */ public function route($url = null, $context = array()) { if (is_null($url)) { $url = getenv('REQUEST_URI'); } if (!isset($context['site_id'])) { $env_site = fx::env('site'); $context['site_id'] = $env_site ? $env_site['id'] : null; } foreach ($this->routers as $router_key => $r) { $result = $r['router']->route($url, $context); if ($result !== null && $result !== false) { $log_option = fx::config('dev.log_routes'); if (is_bool($log_option) && $log_option || is_array($log_option) && in_array($router_key, $log_option) || is_string($log_option) && $log_option === $router_key) { fx::log('routed', $router_key, $url); } if ($result instanceof \Floxim\Floxim\System\Controller) { $result = $result->process(); } return $result; } } }
protected function updateVersionNumber($new_version) { fx::config('fx.version', $new_version); fx::config()->store('fx.version'); }
public function getFullPath() { return fx::config()->DOCUMENT_ROOT . $this->getHttpPath(); }
public function isFresh($target_path) { $cache = fx::config('templates.cache'); // template caching is disabled if (!$cache) { return false; } $ttl = fx::config('templates.ttl'); // file is not created yet if (!file_exists($target_path)) { return false; } // cache forever if ($ttl === 0) { return true; } // file is older than ttl if (time() - filemtime($target_path) > $ttl) { return false; } return true; }
<?php use Floxim\Floxim\System\Fx as fx; // current dir /vendor/floxim/floxim/console/ require_once dirname(__DIR__) . '/../../../boot.php'; $manager = new \Floxim\Floxim\System\Console\Manager(); $manager->addCommands(fx::config('console.commands')); $manager->addPath(__DIR__ . '/Command'); $manager->run();
public static function addAdminFiles() { $path_floxim = fx::path('@floxim'); $lang = fx::config('lang.admin'); $js_files = array(FX_JQUERY_PATH, $path_floxim . '/lib/js/jquery.bem.js', $path_floxim . '/Admin/js/fxj.js', $path_floxim . '/Admin/js/fx.js', $path_floxim . '/Admin/js/js-dictionary-' . $lang . '.js', FX_JQUERY_UI_PATH, $lang === 'en' ? null : $path_floxim . '/lib/js/jquery.datepicker.' . $lang . '.js', $path_floxim . '/lib/js/jquery.ba-hashchange.min.js', $path_floxim . '/lib/js/jquery.json-2.3.js', $path_floxim . '/lib/js/ajaxfileupload.js', $path_floxim . '/Admin/js-templates/jstx.js', 'http://' . getenv("HTTP_HOST") . fx::path()->http($path_floxim) . '/Admin/js-templates/compile.php', $path_floxim . '/Admin/js/lib.js', $path_floxim . '/Admin/js/sort.js', $path_floxim . '/Admin/js/front.js', $path_floxim . '/Admin/js/adder.js', $path_floxim . '/Admin/js/buttons.js', $path_floxim . '/Admin/js/form.js', $path_floxim . '/Admin/js/debug.js', $path_floxim . '/Admin/js/livesearch.js', $path_floxim . '/Admin/js/fields.js', $path_floxim . '/Admin/js/edit-in-place.js', $path_floxim . '/Admin/js/panel.js', $path_floxim . '/Admin/js/popup.js', $path_floxim . '/Admin/js/admin.js', $path_floxim . '/Admin/js/nav.js', $path_floxim . '/lib/editors/redactor/redactor.patched.js', $lang === 'en' ? null : $path_floxim . '/lib/editors/redactor/langs/' . $lang . '.js', $path_floxim . '/lib/editors/redactor/fontcolor.js', $path_floxim . '/lib/codemirror/codemirror.all.min.js', $path_floxim . '/lib/js/jquery.form.js', $path_floxim . '/lib/js/jquery.cookie.js', $path_floxim . '/lib/js/jquery.ba-resize.min.js', $path_floxim . '/lib/js/jquery.scrollTo.js', $path_floxim . '/Admin/js/map.js', $path_floxim . '/Admin/js/node-panel.js', $path_floxim . '/Admin/js/infoblock.js'); $page = fx::page(); $page->addJsBundle($js_files, array('name' => 'fx_admin')); $page->addCssFile('https://fonts.googleapis.com/css?family=Roboto:400,500,400italic,500italic,700,700italic&subset=latin,cyrillic'); // todo: need fix path for css - now used server path $page->addCssBundle(array($path_floxim . '/lib/editors/redactor/redactor.css')); $page->addCssBundle(array($path_floxim . '/Admin/style/mixins.less', $path_floxim . '/Admin/style/main.less', $path_floxim . '/Admin/style/backoffice.less', $path_floxim . '/Admin/style/forms.less', $path_floxim . '/Admin/style/front.less', $path_floxim . '/Admin/style/livesearch.less', $path_floxim . '/Admin/style/debug.less', $path_floxim . '/lib/codemirror/codemirror.css'), array('name' => 'admin_less')); }
public function strings($input) { $lang_id = isset($input['id']) ? $input['id'] : isset($input['params'][0]) ? $input['params'][0] : null; $lang = fx::data('lang', $lang_id); $list = array('type' => 'list', 'filter' => false, 'tpl' => 'imgh', 'entity' => 'lang', 'values' => array()); $list['labels'] = array('dict' => array('label' => fx::alang('Dictionary', 'system'), 'filter' => 'select'), 'string' => array('label' => fx::alang('String', 'system'), 'filter' => 'text'), 'value' => array('label' => fx::alang('Value', 'system'), 'filter' => 'text', 'editable' => array('entity' => 'lang', 'action' => 'string', 'lang' => $lang_id))); $strings = fx::data('lang_string')->order('dict')->order('string')->all(); foreach ($strings as $s) { $list['values'][] = array('id' => $s['id'], 'dict' => $s['dict'], 'string' => $s['string'], 'value' => $s['lang_' . $lang['lang_code']]); } $fields = array('strings' => $list); $this->response->addFields($fields); $lang_name = fx::config('lang.admin') == $lang['lang_code'] ? $lang['native_name'] : $lang['en_name']; $this->response->breadcrumb->addItem(fx::alang('Languages', 'system'), '#admin.lang.all'); $this->response->breadcrumb->addItem($lang_name, '#admin.lang.edit(' . $lang['id'] . ')'); $this->response->breadcrumb->addItem(fx::alang('Language strings'), '#admin.lang.strings(' . $lang['id'] . ')'); $this->response->submenu->setMenu('lang'); }
public static function panelHtml() { $data = array('main_menu' => self::getMainMenu(), 'more_menu' => self::getMoreMenu(), 'modes' => array("view" => array("name" => fx::alang("mode_view"), "key" => "view"), "edit" => array("name" => fx::alang("mode_edit"), "key" => "edit")), 'profile' => array('logout' => array('name' => fx::alang('Sign out', 'system'), 'href' => fx::user()->getLogoutUrl())), 'is_front' => $_SERVER['REQUEST_URI'] !== fx::config('path.admin')); $res = fx::template('@admin:panel')->render($data); return $res; }
public function dropOldSessions() { $ttl = (int) fx::config('auth.remember_ttl'); fx::db()->query('delete from {{session}} ' . 'where ' . 'user_id is not null ' . 'and last_activity_time + ' . $ttl . ' < ' . time()); }
protected function tokenCallToCode(Token $token) { $each = $token->getProp('each'); if ($each) { $each_token = Token::create('{each}'); $each_token->setProp('select', $each); $item = '$' . $this->varialize($each) . '_item'; $each_token->setProp('as', $item); $token->setProp('each', ''); $each_token->addChild($token); return $this->tokenEachToCode($each_token); } $code = "<?php\n"; $is_apply = $token->getProp('apply'); $tpl_name = $token->getProp('id'); $tpl = '$tpl_' . $this->varialize($tpl_name); $call_children = $token->getChildren(); /* * Converted: * {call id="wrap"}<div>Something</div>{/call} * like this: * {call id="wrap"}{var id="content"}<div>Something</div>{/var}{/call} */ $has_content_param = false; foreach ($call_children as $call_child) { if ($call_child->name == 'code' && $call_child->isEmpty()) { continue; } if ($call_child->name != 'var') { $has_content_param = true; break; } } if ($has_content_param) { $token->clearChildren(); $var_token = new Token('var', 'single', array('id' => 'content')); foreach ($call_children as $call_child) { $var_token->addChild($call_child); } $token->addChild($var_token); } $with_expr = $token->getProp('with'); if ($with_expr) { $ep = new ExpressionParser(); $with_expr = $ep->parseWith($with_expr); } $switch_context = is_array($with_expr) && isset($with_expr['$']); // && !$is_apply; if ($switch_context) { $new_context_expression = $this->parseExpression($with_expr['$']); } $passed_vars = array(); if (is_array($with_expr)) { foreach ($with_expr as $alias => $var) { if ($alias == '$') { continue; } $passed_vars[trim($alias, '$')] = array('string', $this->parseExpression($var)); } } foreach ($token->getChildren() as $param_var_token) { // internal call only handle var if ($param_var_token->name != 'var') { continue; } $value_to_set = ''; if ($param_var_token->hasChildren()) { // pass the inner html code $value_to_set .= "ob_start();\n"; $value_to_set .= $this->childrenToCode($param_var_token); $value_to_set .= "\n"; $passed_value_type = 'buffer'; } elseif ($select_att = $param_var_token->getProp('select')) { // pass the result of executing the php code $value_to_set = self::parseExpression($select_att); $passed_value_type = 'string'; } $passed_vars[$param_var_token->getProp('id')] = array($passed_value_type, $value_to_set); } $switch_context_local = $switch_context && count($passed_vars) > 0; if ($is_apply) { $context_var = '$context'; } else { if (count($passed_vars) > 0 || $switch_context) { $context_var = $tpl . '_context'; $code .= $context_var . " = new \\Floxim\\Floxim\\Template\\" . fx::config('templates.context_class') . "();\n"; } else { $context_var = 'new \\Floxim\\Floxim\\Template\\' . fx::config('templates.context_class') . '()'; } } // switch context to calculate passed vars inside it if ($switch_context_local) { $code .= '$context->push(' . $new_context_expression . ");\n"; } if (count($passed_vars) > 0) { $tpl_passed = $tpl . "_passed"; $code .= $tpl_passed . " = array();\n"; foreach ($passed_vars as $passed_var_key => $passed_var) { switch ($passed_var[0]) { case 'string': default: $code .= $tpl_passed . "['" . $passed_var_key . "'] = " . $passed_var[1] . ";\n"; break; case 'buffer': $code .= $passed_var[1]; $code .= $tpl_passed . "['" . $passed_var_key . "'] = ob_get_clean();\n"; } } // passed vars calculated, clear context if ($switch_context_local) { $code .= "\$context->pop();\n"; } } if ($switch_context) { $code .= $context_var . "->push(" . $new_context_expression . ");\n"; } if (isset($tpl_passed)) { $code .= $context_var . "->push(" . $tpl_passed . ", array('transparent' => true));\n"; } // ------------ $tpl_name_is_expression = !preg_match("~^[a-z0-9_\\,\\.\\:\\@\\#]+\$~", $tpl_name); $loader = "\\Floxim\\Floxim\\Template\\Loader"; // not a plain name if ($tpl_name_is_expression) { $tpl_name = self::parseExpression($tpl_name); $pn = $tpl . '_parsed'; $code .= $pn . ' = ' . $loader . '::parseTemplateName(' . $tpl_name . ', ' . var_export($this->template_set_name, 1) . ', ' . var_export($this->is_aliased, 1) . ");\n"; $code .= $tpl . " = "; $code .= $loader . "::loadTemplateVariant(" . $pn . '["group"], ' . $pn . '["action"], ' . $context_var . ', ' . $pn . '["forced_group"], ' . $pn . '["tags"]); ' . "\n"; } else { $parsed_name = \Floxim\Floxim\Template\Loader::parseTemplateName($tpl_name, $this->template_set_name, $this->is_aliased); foreach ($parsed_name as &$v) { $v = var_export($v, 1); } $code .= $tpl . " = "; $code .= $loader . "::loadTemplateVariant(" . $parsed_name['group'] . ", " . $parsed_name['action'] . ", " . $context_var . ", " . $parsed_name['forced_group'] . ', ' . $parsed_name['tags'] . ");\n"; } /* if (!preg_match("~[\:\@]~", $tpl_name)) { $tpl_name = $this->template_set_name . ":" . $tpl_name; } $tpl_at_parts = explode("@", $tpl_name); if (count($tpl_at_parts) === 1) { $forced_group = 'null'; list($set_name, $action_name) = explode(":", $tpl_name); // save @ for named ("aliased") template groups (like "@admin") if ($set_name === $this->template_set_name && $this->is_aliased) { $set_name = '@'.$set_name; } } else { $forced_group = !empty($tpl_at_parts[0]) ? $tpl_at_parts[0] : $this->template_set_name; $action_parts = explode(":", $tpl_at_parts[1]); if (count($action_parts) === 1) { array_unshift($action_parts, $forced_group); } list($set_name, $action_name) = $action_parts; $forced_group = "'".$forced_group."'"; } $tag_parts = explode("#", $action_name); if (count($tag_parts) > 1) { $action_name = $tag_parts[0]; $tags = "array('".join("', '", explode(",", $tag_parts[1]))."')"; } else { $tags = 'null'; } */ $code .= "if ( " . $tpl . " ) {\n"; $code .= "echo " . $tpl . "->setParent(\$this)->render();\n"; if ($subroot_var = $token->getProp('extract_subroot')) { $code .= $subroot_var . " = " . $tpl . "->is_subroot;\n"; } $code .= "}\n"; // ------------ // clear vars passed into child template from current context if ($is_apply && count($passed_vars) > 0) { $code .= "\$context->pop();\n"; } // clear context object if ($is_apply && $switch_context) { $code .= "\$context->pop();\n"; } $code .= "\n?>"; return $code; }
protected function getProfiler() { $profile = fx::config('dev.profile_templates'); if ($profile) { return fx::profiler(); } }
public function setCookie() { fx::data('session')->setCookie($this['session_key'], $this['remember'] ? time() + fx::config('auth.remember_ttl') : 0); }
<?php use Floxim\Floxim\System\Fx as fx; // if request directs right to /floxim/index.php // e.g. admin interface // current dir /vendor/floxim/floxim/ //require_once(dirname(__FILE__) . '/../../../boot.php'); $boot = $_SERVER['DOCUMENT_ROOT'] . '/boot.php'; require_once $boot; register_shutdown_function(function () { if (!fx::env()->get('complete_ok')) { $ob_level = ob_get_level(); $res = ''; for ($i = 0; $i < $ob_level; $i++) { $res .= ob_get_clean(); } if (fx::config('dev.on')) { echo fx::page()->postProcess($res); } fx::log('down', $res, $_SERVER, $_POST); } }); $result = fx::router()->route(); if ($result) { $result = $result instanceof \Floxim\Floxim\System\Controller ? $result->process() : $result; if (fx::env('ajax')) { fx::page()->addAssetsAjax(); } echo $result; fx::complete(); }
public function getByLogin($login) { $this->where(fx::config('auth.login_field'), $login); return $this->one(); }
public function canHaveNoInfoblock() { $no_ib_types = fx::config('content.can_have_no_infoblock'); return is_array($no_ib_types) && in_array($this['type'], $no_ib_types); }