public function init() { fx::template()->import('floxim.layout.wrapper'); fx::listen('before_save', function ($e) { $entity = $e['entity']; if (!$entity instanceof \Floxim\Floxim\Component\InfoblockVisual\Entity) { return; } if (!preg_match("~column_new-in-(\\d+)~", $entity['area'], $column_infoblock_id)) { return; } $column_infoblock_id = $column_infoblock_id[1]; $column = fx::data('floxim.layout.column')->create(array('infoblock_id' => $column_infoblock_id)); if (preg_match("~(before|after)-(\\d+)~", $entity['area'], $rel_col)) { $column['__move_' . $rel_col[1]] = $rel_col[2]; } fx::log($rel_col, $column); $column->save(); $entity['area'] = $column['area_keyword']; }); }
public function getTemplateInfo($full_id) { $tpl = fx::template($full_id); if (!$tpl) { return; } $info = $tpl->getInfo(); if (!isset($info['file']) || !isset($info['offset'])) { return; } $res = array(); $source = file_get_contents(fx::path()->abs($info['file'])); $res['file'] = $info['file']; $res['hash'] = md5($source); $res['full'] = $source; $offset = explode(',', $info['offset']); $length = $offset[1] - $offset[0]; $res['start'] = $offset[0]; $res['length'] = $length; $source_part = $res['source'] = mb_substr($source, $offset[0], $length); $first_part = mb_substr($source, 0, $res['start']); $res['first_line'] = count(explode("\n", $first_part)); $space_tale = ''; if (preg_match("~[ \t]+\$~", $first_part, $space_tale)) { $space_tale = $space_tale[0]; $tale_length = strlen($space_tale); $lines = explode("\n", $source_part); foreach ($lines as &$l) { if (substr($l, 0, $tale_length) === $space_tale) { $l = substr($l, $tale_length); } } $source_part = join("\n", $lines); } $res['common_spaces'] = $space_tale; $res['source'] = $source_part; return $res; }
public function importLayoutTemplate() { $c_page = fx::env('page'); if (!$c_page) { return false; } $layout_infoblock = $this->getLayoutInfoblock($c_page); if (!$layout_infoblock) { return false; } return fx::template()->import(preg_replace('~\\:.*$~', '', $layout_infoblock->getVisual()->get('template'))); }
/** * @return string */ public function adminOffice() { self::addAdminFiles(); if (fx::isAdmin()) { $panel = Adminpanel::panelHtml(); $res = fx::template('@admin:back_office')->render(array('panel' => $panel)); $js_config = new FxAdmin\Configjs(); fx::page()->addJsText("\$fx.init(" . $js_config->getConfig() . ");"); } else { $auth_form = fx::controller('user:auth_form')->render('user:auth_form'); $recover_form = fx::controller('user:recover_form', array('email' => isset($_POST['email']) ? $_POST['email'] : null))->render('user:recover_form'); $res = fx::template('@admin:authorize')->render(array('auth_form' => $auth_form, 'recover_form' => $recover_form)); } return fx::page()->postProcess($res); }
/** * wrap ib's output */ protected function wrapOutput($output) { $wrapper = $this->getPropInherited('visual.wrapper'); if (!$wrapper) { return $output; } $tpl_wrap = fx::template($wrapper); if (!$tpl_wrap) { return $output; } $tpl_wrap->isWrapper(true); $wrap_params = $this->getPropInherited('visual.wrapper_visual'); if (!is_array($wrap_params)) { $wrap_params = array(); } $wrap_params['content'] = $output; $wrap_params['infoblock'] = $this; $is_admin = fx::isAdmin(); try { $result = $tpl_wrap->render($wrap_params); } catch (\Exception $e) { fx::log('error while wrapping ib #' . $this['id'], $e->getMessage()); $result = $output; } if ($is_admin) { $this->infoblock_meta['wrapper_params'] = $tpl_wrap->getRegisteredParams(); } $this->output_is_subroot = $tpl_wrap->is_subroot; return $result; }
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; }
protected function adjustLayoutVisual($layout_ib, $layout_id, $source_layout_id) { $is_root_layout = (bool) $layout_ib['parent_infoblock_id']; if ($is_root_layout && $source_layout_id) { $root_layout_ib = $layout_ib->getRootInfoblock(); if ($root_layout_ib->getVisual($layout_id)->get('is_stub')) { $this->adjustLayoutVisual($root_layout_ib, $layout_id, $source_layout_id); } } $layout = fx::data('layout', $layout_id); $layout_tpl = fx::template('theme.' . $layout['keyword']); $template_variants = $layout_tpl->getTemplateVariants(); $source_template_params = null; if ($source_layout_id) { $source_template = $layout_ib->getPropInherited('visual.template', $source_layout_id); if (!$is_root_layout) { $source_template_params = $layout_ib->getPropInherited('visual.template_visual', $source_layout_id); } $old_template = fx::template($source_template); if ($old_template) { $old_areas = $old_template->getAreas(); } else { $old_areas = array(); } $c_relevance = 0; $c_variant = null; foreach ($template_variants as $tplv) { if ($tplv['of'] !== 'floxim.component.layout:show' && $tplv['id'] !== '_layout_body') { continue; } $test_layout_tpl = fx::template($tplv['full_id']); $tplv['real_areas'] = $test_layout_tpl->getAreas(); $map = $this->mapAreas($old_areas, $tplv['real_areas']); if (!$map) { continue; } if ($map['relevance'] > $c_relevance) { $c_relevance = $map['relevance']; $c_variant = $map + array('full_id' => $tplv['full_id'], 'areas' => $tplv['real_areas']); } } } if (!$source_layout_id || !$c_variant) { foreach ($template_variants as $tplv) { if ($tplv['of'] == 'layout:show') { $c_variant = $tplv; break; } } if (!$c_variant) { $c_variant = array('full_id' => 'theme.' . $layout['keyword'] . ':_layout_body'); } } $layout_vis = $layout_ib->getVisual(); $layout_vis['template'] = $c_variant['full_id']; if ($source_template_params) { $layout_vis['template_visual'] = $source_template_params; } if ($c_variant['areas']) { $layout_vis['areas'] = $c_variant['areas']; $layout_vis['area_map'] = $c_variant['map']; } unset($layout_vis['is_stub']); $layout_vis->save(); }
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 source($layout) { $template = fx::template('theme.' . $layout['keyword']); $vars = $template->getTemplateVariants(); $files = array(); foreach ($vars as $var) { $files[preg_replace("~^.+/~", '', $var['file'])] = $var['file']; } foreach ($files as $file => $path) { $tab_code = md5($file); //preg_replace("~\.~", '_', $file); $tab_name = fx::path()->fileName($file); $source = file_get_contents($path); $this->response->addTab($tab_code, $tab_name); $this->response->addFields(array(array('type' => 'text', 'code' => 'htmlmixed', 'name' => 'source_' . $tab_code, 'value' => $source)), $tab_code); } $fields = array($this->ui->hidden('entity', 'layout'), $this->ui->hidden('action', 'source')); $this->response->submenu->setMenu('layout'); $this->response->addFormButton('save'); return array('fields' => $fields, 'form_button' => array('save')); }
public function init() { fx::template()->register(array('floxim.ui.slider', 'floxim.ui.tiles', 'floxim.ui.menu', 'floxim.ui.list', 'floxim.ui.box', 'floxim.ui.record')); }
protected function getFormatFields(CompInfoblock\Entity $infoblock, $area_meta = null) { $i2l = $infoblock->getVisual(); $fields = array(array('label' => "Area", 'name' => 'area', 'value' => $i2l['area'], 'type' => 'hidden')); $layout_name = fx::data('layout', $i2l['layout_id'])->get('keyword'); $controller_name = $infoblock->getPropInherited('controller'); $action_name = $infoblock->getPropInherited('action'); $area_suit = Template\Suitable::parseAreaSuitProp(isset($area_meta['suit']) ? $area_meta['suit'] : ''); $force_wrapper = $area_suit['force_wrapper']; $default_wrapper = $area_suit['default_wrapper']; $wrappers = array(); $c_wrapper = ''; if (!$force_wrapper) { $wrappers[''] = fx::alang('With no wrapper', 'system'); if ($i2l['id'] || !$default_wrapper) { $c_wrapper = $i2l['wrapper']; } else { $c_wrapper = $default_wrapper[0]; } } // Collect available wrappers $layout_tpl = fx::template('theme.' . $layout_name); if ($layout_tpl) { $avail_wrappers = \Floxim\Floxim\Template\Suitable::getAvailableWrappers($layout_tpl, $area_meta); foreach ($avail_wrappers as $avail_wrapper) { $wrappers[$avail_wrapper['full_id']] = $avail_wrapper['name']; } //$wrappers = array_merge($wrappers, $avail_wrappers); } // Collect the available templates $controller = fx::controller($controller_name . ':' . $action_name); $tmps = $controller->getAvailableTemplates($layout_name, $area_meta); if (!empty($tmps)) { foreach ($tmps as $template) { $templates[] = array($template['full_id'], $template['name']); } } if (count($templates) == 1) { $fields[] = array('name' => 'template', 'type' => 'hidden', 'value' => $templates[0][0]); } else { $fields[] = array('label' => fx::alang('Template', 'system'), 'name' => 'template', 'type' => 'select', 'values' => $templates, 'value' => $i2l['template']); } if ($controller_name != 'layout' && (count($wrappers) > 1 || !isset($wrappers['']))) { $fields[] = array('label' => fx::alang('Wrapper', 'system'), 'name' => 'wrapper', 'type' => 'select', 'values' => $wrappers, 'value' => $c_wrapper); } return $fields; }
protected function presetToTemplate(Token $token) { $tpl_token = Token::create('{template}'); $target_tpl = $token->getProp('template'); $full_target_tpl = $target_tpl; $id = preg_replace("~[^a-z0-9_]+~", '_', $target_tpl); if ($own_id = $token->getProp('id')) { $id .= '_' . $own_id; } $source_info = array(); if (preg_match("~[a-z0-9\\._-]+?\\:[a-z0-9_-]+\$~", $target_tpl)) { try { $target_tpl_obj = fx::template($target_tpl); if ($target_tpl_obj) { $source_info = $target_tpl_obj->getInfo(); } } catch (\Exception $e) { fx::log('Can not init target template', $token, $e); } } else { $full_target_tpl = $this->template_set_name . ':' . $target_tpl; if (isset($this->templates[$target_tpl])) { $source_info =& $this->templates[$target_tpl]; if (!$own_id) { $source_hash = md5($source_info['_code'] . $target_tpl); if (!isset($source_info['tags'])) { $source_info['tags'] = array(); } $source_info['tags'][] = $source_hash; $full_target_tpl .= '#' . $source_hash; } } } // copy these props from source template and/or preset token to the generated template $passed_props = array('suit', 'of', 'size'); foreach ($passed_props as $passed_prop) { if (isset($source_info[$passed_prop])) { $tpl_token->setProp($passed_prop, $source_info[$passed_prop]); } } if (isset($source_info['name'])) { $tpl_token->setProp('name', $source_info['name'] . ($own_id ? '#' . $own_id : '')); } $tpl_token->setProp('is_preset_of', preg_replace("~\\#.+\$~", '', $full_target_tpl)); if ($token->getProp('replace')) { $tpl_token->setProp('replace_original', true); } $tpl_token->setProp('id', $id); $passed_props[] = 'name'; foreach ($passed_props as $passed_prop) { if ($preset_prop = $token->getProp($passed_prop)) { $tpl_token->setProp($passed_prop, $preset_prop); } } //$apply = '{apply '.$token->getProp('template'); $apply = '{apply ' . $full_target_tpl; $vars = array(); foreach ($token->getChildren() as $child) { if (in_array($child->name, array('js', 'css', 'param', 'if', 'else', 'elseif', 'set'))) { $tpl_token->addChild($child); continue; } if ($child->name !== 'code') { fx::log('unknown preset child', $child); continue; } $data = $child->getProp('value'); $data = explode("\n", trim($data)); foreach ($data as $line) { $line = trim($line); if (!preg_match("~([\$a-z0-9_-]+)\\s*\\:\\s*(.+)\$~i", $line, $parts)) { continue; } $var = $parts[1]; if (!preg_match("~^\$~", $var)) { $var = '$' . $var; } $val = $parts[2]; if (!preg_match('~^([\\"\\\']).+\\1$~', $val)) { $val = '"' . $val . '"'; } $vars[] = $var . ' = ' . $val; } } if (count($vars) > 0) { $apply .= ' with ' . join(", ", $vars); } $apply .= '/}'; $apply_token = Token::create($apply); $apply_token->setProp('extract_subroot', '$this->is_subroot'); $tpl_token->addChild($apply_token); return $tpl_token; }
public function findTemplate() { $layout = $this->getLayout(); $tpl_name = 'layout_' . $layout['keyword']; return fx::template($tpl_name); }