public function show() { $page_id = $this->getParam('page_id', fx::env('page_id')); $layout_id = $this->getParam('layout_id', fx::env('layout')); // add admin files bundle BEFORE site scripts/styles if (!$this->getParam('ajax_mode') && fx::isAdmin()) { Admin\Controller\Admin::addAdminFiles(); } $page_infoblocks = fx::router('front')->getPageInfoblocks($page_id, $layout_id); fx::page()->setInfoblocks($page_infoblocks); $ib = fx::data('infoblock', $this->getParam('infoblock_id')); $layout_keyword = 'default'; if ($ib) { $vis = $ib->getVisual(); if ($vis) { $c_keyword = preg_replace("~^.+?\\:~", '', $vis['template']); if ($c_keyword !== '_layout_body') { $layout_keyword = $c_keyword; } } } $path = fx::env('page')->getPath(); $current_page = $path->last(); $res = array('page_id' => $page_id, 'path' => $path, 'current_page' => $current_page, 'layout_keyword' => $layout_keyword); return $res; }
public function route($url = null, $context = null) { $site_id = isset($context['site_id']) ? $context['site_id'] : fx::env('site'); $error_page = $this->getErrorPage($site_id); $ctr = fx::router('front')->route($error_page['url'], $context); fx::http()->status('404'); return $ctr; }
public function route($url = null, $context = null) { if (!fx::isAdmin()) { return null; } if (!preg_match("~^/\\~ib/(\\d+|fake(?:\\-\\d+)?)@(\\d+)~", $url, $ib_info)) { return null; } $c_url = fx::input()->fetchGetPost('_ajax_base_url'); if ($c_url) { $_SERVER['REQUEST_URI'] = $c_url; $path = fx::router()->getPath(fx::path()->removeBase($c_url)); if ($path) { fx::env('page', $path->last()); } else { fx::env('page', fx::router('error')->getErrorPage()); } $c_url = parse_url($c_url); if (isset($c_url['query'])) { parse_str($c_url['query'], $_GET); } } $ib_id = $ib_info[1]; $page_id = $ib_info[2]; if (!fx::env('page') && $page_id) { $page = fx::data('floxim.main.content', $page_id); fx::env('page', $page); } fx::env('ajax', true); $page_infoblocks = fx::router('front')->getPageInfoblocks($page_id, fx::env('layout')); fx::page()->setInfoblocks($page_infoblocks); // import layout template to recreate real env fx::router('front')->importLayoutTemplate(); // front end can try to reload the layout which is out of date // when updating from "layout settings" panel $infoblock = fx::data('infoblock', $ib_id); if (!$infoblock && isset($_POST['infoblock_is_layout']) || $infoblock->isLayout()) { //$infoblock = $layout_infoblock; $infoblock = fx::router('front')->getLayoutInfoblock(fx::env('page')); } fx::http()->status('200'); $infoblock_overs = null; if (fx::isAdmin() && isset($_POST['override_infoblock'])) { $infoblock_overs = fx::input('post', 'override_infoblock'); if (is_string($infoblock_overs)) { parse_str($infoblock_overs, $infoblock_overs); $infoblock_overs = fx::input()->prepareSuperglobal($infoblock_overs); } $infoblock->override($infoblock_overs); } $infoblock->overrideParam('ajax_mode', true); $res = $infoblock->render(); return $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 route($url = null, $context = null) { $path = fx::router()->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); exit; } } 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; }
<?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 route($url = null, $context = null) { $action_info = null; if (!preg_match("~^/\\~ajax/([a-z0-9_\\.\\:\\@-]+)?~", $url, $action_info)) { return null; } fx::env('ajax', true); $c_url = fx::input()->fetchGetPost('_ajax_base_url'); if ($c_url) { $c_url = preg_replace("~^https?://[^/]+~", '', $c_url); $_SERVER['REQUEST_URI'] = $c_url; $base_path = fx::router()->getPath($c_url); if ($base_path) { $page = $base_path->last(); fx::env('page', $page); } else { fx::env('page', fx::router('error')->getErrorPage()); } $c_url = parse_url($c_url); if (isset($c_url['query'])) { parse_str($c_url['query'], $_GET); } } // import layout template to recreate real env fx::router('front')->importLayoutTemplate(); $page_infoblocks = fx::router('front')->getPageInfoblocks($page_id, $layout_id); fx::page()->setInfoblocks($page_infoblocks); $controller_params = fx::input()->fetchGetPost('_ajax_controller_params'); $c_infoblock_id = fx::input()->fetchGetPost('_ajax_infoblock_id'); if ($c_infoblock_id) { $infoblock = fx::data('infoblock', $c_infoblock_id); if ($infoblock) { if ($controller_params) { $infoblock->override(array('params' => $controller_params)); } $res = $infoblock->render(); return $res; } } $template = null; if ($action_info && !empty($action_info[1])) { $action = $action_info[1]; $action = explode("@", $action); if (count($action) == 2) { $template = $action[1]; $action = $action[0]; } else { $action = $action[0]; } } elseif (isset($_POST['_ajax_controller'])) { $action = $_POST['_ajax_controller']; } else { return null; } $action = explode(":", $action); $controller_name = $action[0]; if (preg_match("~^widget_~", $controller_name) && !isset($action[1])) { $action[1] = 'show'; } $action_name = $action[1]; $controller = fx::controller($controller_name . ':' . $action_name, $controller_params); if (!$template) { $template = fx::input()->fetchGetPost('_ajax_template'); } if (!$template) { $tpls = $controller->getAvailableTemplates(); if (count($tpls) > 0) { $template = $tpls[0]['full_id']; } } $res = $controller->process(); if ($template) { $tpl = fx::template($template); if ($tpl) { $res = $tpl->render($res); } } return $res ? $res : true; }
public function suit(System\Collection $infoblocks, $layout_id) { $layout = fx::data('layout', $layout_id); $layout_ib = null; $stub_ibs = new System\Collection(); // Collect all Infoblox without the visual part // Find the InfoBlock-layout foreach ($infoblocks as $ib) { if ($ib->getVisual()->get('is_stub')) { $stub_ibs[] = $ib; } if ($ib->isLayout()) { $layout_ib = $ib; } } $layout_rate = array(); $all_visual = fx::data('infoblock_visual')->getForInfoblocks($stub_ibs, false); foreach ($all_visual as $c_vis) { $c_layout_id = $c_vis['layout_id']; $infoblocks->findOne('id', $c_vis['infoblock_id'])->setVisual($c_vis, $c_layout_id); if (!isset($layout_rate[$c_layout_id])) { $layout_rate[$c_layout_id] = 0; } // count how many visual blocks are defined for each layout // later we should sort this to find correct "original" layout made by human $layout_rate[$c_layout_id]++; } //$source_layout_id = $c_layout_id; $avail_layout_ids = array_keys($layout_rate); // temp: use first // $source_layout_id = $avail_layout_ids[0]; $source_layout_id = end($avail_layout_ids); if (!$layout_ib) { $layout_ib = fx::router('front')->getLayoutInfoblock(fx::env('page')); } $area_map = array(); if ($layout_ib->getVisual()->get('is_stub') || !$layout_ib->getTemplate()) { $this->adjustLayoutVisual($layout_ib, $layout_id, $source_layout_id); $layout_visual = $layout_ib->getVisual(); $area_map = $layout_visual['area_map']; } else { $layout_visual = $layout_ib->getVisual(); $old_layout_template = $layout_ib->getPropInherited('visual.template', $source_layout_id); if ($old_layout_template) { $old_areas = fx::template($old_layout_template)->getAreas(); $new_areas = fx::template($layout_visual['template'])->getAreas(); //$tplv['real_areas'] = $test_layout_tpl->getAreas(); $area_map = $this->mapAreas($old_areas, $new_areas); $area_map = $area_map['map']; } } $layout_template_name = $layout_ib->getPropInherited('visual.template'); $layout_template = fx::template($layout_template_name); // seems to be second call of ::getAreas(), can be cached or reused $c_areas = $layout_template->getAreas(); $c_wrappers = array(); foreach ($infoblocks as $ib) { $ib_visual = $ib->getVisual($layout_id); if (!$ib_visual['is_stub']) { continue; } $old_area = $ib->getPropInherited('visual.area', $source_layout_id); // Suit record infoblock to the area where list infoblock is placed if ($ib->getPropInherited('action') == 'record') { $content_type = $ib->getPropInherited('controller'); $content_ibs = fx::data('infoblock')->where('page_id', $ib['page_id'])->getContentInfoblocks($content_type); if (count($content_ibs)) { $list_ib = $content_ibs->first(); $list_ib_vis = $list_ib->getVisual($layout_id); if ($list_ib_vis && $list_ib_vis['area']) { $ib_visual['area'] = $list_ib_vis['area']; } } } if (!$ib_visual['area']) { if ($old_area && isset($area_map[$old_area])) { $ib_visual['area'] = $area_map[$old_area]; $ib_visual['priority'] = $ib->getPropInherited('visual.priority', $source_layout_id); } elseif (preg_match("~^grid_~", $old_area)) { $ib_visual['area'] = $old_area; } } $ib_controller = fx::controller($ib->getPropInherited('controller'), $ib->getPropInherited('params'), $ib->getPropInherited('action')); $area_meta = isset($c_areas[$ib_visual['area']]) ? $c_areas[$ib_visual['area']] : null; $controller_templates = $ib_controller->getAvailableTemplates($layout['keyword'], $area_meta); $old_template = $ib->getPropInherited('visual.template', $source_layout_id); $used_template_props = null; foreach ($controller_templates as $c_tpl) { if ($c_tpl['full_id'] === $old_template) { $ib_visual['template'] = $c_tpl['full_id']; $used_template_props = $c_tpl; break; } } if (!$ib_visual['template']) { $that = $this; $old_template_id = preg_replace("~^.*?:~", '', $old_template); $controller_templates = fx::collection($controller_templates); $controller_templates->sort(function (&$tpl) use($that, $old_template_id) { $res = $that->compareNames($tpl['id'], $old_template_id); $tpl['name_match'] = $res; return 1 / ($res + 1); }); $res_template = $controller_templates->first(); $ib_visual['template'] = $res_template['full_id']; $used_template_props = $res_template; } if (!$ib_visual['area']) { $block_size = self::getSize($used_template_props['size']); $c_area = null; $c_area_count = 0; foreach ($c_areas as $ca) { $area_size = self::getSize($ca['size']); $area_count = self::checkSizes($block_size, $area_size); if ($area_count >= $c_area_count) { $c_area_count = $area_count; $c_area = $ca['id']; } } $ib_visual['area'] = $c_area; } $old_wrapper = $ib->getPropInherited('visual.wrapper', $source_layout_id); if ($old_wrapper) { if (!isset($c_wrappers[$c_area])) { $c_wrappers[$c_area] = self::getAvailableWrappers($layout_template, $area_meta); } $old_wrapper_id = preg_replace("~^.+\\:~", '', $old_wrapper); $avail_wrappers = $c_wrappers[$c_area]; if (count($avail_wrappers)) { $new_wrapper = fx::collection($avail_wrappers)->sort(function ($w) use($old_wrapper_id) { return 1 / (1 + Suitable::compareNames($w['name'], $old_wrapper_id)); })->first(); $ib_visual['wrapper'] = $new_wrapper['full_id']; $ib_visual['wrapper_visual'] = $ib->getPropInherited('visual.wrapper_visual', $source_layout_id); } } //if ($old_wrapper && $area_meta) { if ($area_meta) { $area_suit = self::parseAreaSuitProp(isset($area_meta['suit']) ? $area_meta['suit'] : null); if ($area_suit['default_wrapper']) { $ib_visual['wrapper'] = $area_suit['default_wrapper'][0]; $ib_visual['wrapper_visual'] = $ib->getPropInherited('visual.wrapper_visual', $source_layout_id); } } unset($ib_visual['is_stub']); $ib_visual->save(); } }
public function layoutSettings($input) { $c_page = fx::env('page'); $infoblock = fx::router('front')->getLayoutInfoblock($c_page); $scope_fields = $this->getScopeFields($infoblock, $c_page); unset($scope_fields['visibility']); $this->response->addFields($scope_fields, false, 'scope'); $format_fields = $this->getFormatFields($infoblock); $this->response->addFields($format_fields, false, 'visual'); if ($input['settings_sent']) { $this->saveLayoutSettings($infoblock, $input); return; } $fields = array($this->ui->hidden('entity', 'infoblock'), $this->ui->hidden('action', 'layout_settings'), $this->ui->hidden('fx_admin', true), $this->ui->hidden('settings_sent', 'true'), $this->ui->hidden('page_id', $input['page_id'])); $existing = fx::data('infoblock')->isLayout()->getForPage($c_page['id'], false); if (count($existing) > 1) { $existing = fx::data('infoblock')->sortInfoblocks($existing); $next = $existing->eq(1); $fields[] = array('type' => 'button', 'role' => 'preset', 'label' => fx::alang('Drop current rule and use the wider one', 'system'), 'data' => array('scope[complex_scope]' => $next->getScopeString(), 'visual[template]' => $next->getPropInherited('visual.template'))); } $this->response->addFields($fields); $res = array('header' => fx::alang('Layout settings', 'system'), 'view' => 'horizontal'); return $res; }