public function recountFiles() { $modified_params = $this->getModifiedParams(); $fxPath = fx::path(); foreach ($modified_params as $field => $params) { $all_params = $this[$field]; foreach ($params as $pk => $pv) { if (self::checkValueIsFile($pv['new'])) { fx::log($pv, 'is file'); $ib = $this['infoblock']; $site_id = $ib ? $ib['site_id'] : fx::env('site_id'); $file_name = $fxPath->fileName($pv['new']); $new_path = $fxPath->abs('@content_files/' . $site_id . '/visual/' . $file_name); $move_from = $fxPath->abs($pv['new']); if (file_exists($move_from)) { fx::files()->move($move_from, $new_path); $all_params[$pk] = $fxPath->removeBase($fxPath->http($new_path)); } } if ($pv['old']) { $old_path = $fxPath->abs(FX_BASE_URL . $pv['old']); if (self::checkValueIsFile($old_path)) { fx::files()->rm($old_path); } } } $this[$field] = $all_params; } }
public function doNeighbours() { $item = fx::env('page'); $q = $this->getFinder()->order(null)->limit(1)->where('site_id', fx::env('site_id')); $q_next = clone $q; $q_prev = clone $q; if ($this->getParam('sorting') === 'auto' && $item['infoblock_id']) { $item_ib_params = fx::data('infoblock', $item['infoblock_id'])->get('params'); $ib_sorting = $item_ib_params['sorting']; $this->setParam('sorting', $ib_sorting == 'manual' || $ib_sorting == 'auto' ? 'priority' : $ib_sorting); $this->setParam('sorting_dir', $item_ib_params['sorting_dir']); } $sort_field = $this->getParam('sorting', 'priority'); if ($sort_field === 'auto') { $sort_field = 'priority'; } $dir = strtolower($this->getParam('sorting_dir', 'asc')); $where_prev = array(array($sort_field, $item[$sort_field], $dir == 'asc' ? '<' : '>')); $where_next = array(array($sort_field, $item[$sort_field], $dir == 'asc' ? '>' : '<')); $group_by_parent = $this->getParam('group_by_parent'); if ($group_by_parent) { $c_parent = fx::content($item['parent_id']); // todo: psr0 need verify $q_prev->order('parent.priority', 'desc')->where('parent.priority', $c_parent['priority'], '<='); $q_next->order('parent.priority', 'asc')->where('parent.priority', $c_parent['priority'], '>='); $where_prev[] = array('parent_id', $item['parent_id'], '!='); $where_next[] = array('parent_id', $item['parent_id'], '!='); } $q_prev->order($sort_field, $dir == 'asc' ? 'desc' : 'asc')->where($where_prev, null, 'or'); $prev = $q_prev->all(); $q_next->order($sort_field, $dir)->where($where_next, null, 'or'); $next = $q_next->all(); //fx::log($q_prev->showQuery(), $q_next->showQuery()); return array('prev' => $prev, 'current' => $item, 'next' => $next); }
public function getErrorPage($site_id = null) { if (is_null($site_id)) { $site_id = fx::env('site_id'); } $error_page = fx::data('page', fx::data('site', $site_id)->get('error_page_id')); return $error_page; }
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; }
/** * Get infoblocks where content can be placed and displayed * * @param type $content */ public function getForContent($content) { if (!$content['type']) { return fx::collection(); } $this->whereContent($content['type']); if (!$content['parent_id']) { $site_id = $content['site_id'] ? $content['site_id'] : fx::env('site_id'); return $this->where('site_id', $site_id)->all(); } return $this->getForPage($content['parent']); }
public function postprocess($html) { if ($this->getParam('ajax_mode')) { $html = preg_replace("~^.+?<body[^>]*?>~is", '', $html); $html = preg_replace("~</body>.+?\$~is", '', $html); } else { $page = fx::env('page'); $meta_title = empty($page['title']) ? $page['name'] : $page['title']; $this->showAdminPanel(); $html = fx::page()->setMetatags('title', $meta_title)->setMetatags('description', $page['description'])->setMetatags('keywords', $page['keywords'])->postProcess($html); } return $html; }
public static function getMoreMenu() { $more_menu = array(); $c_page = fx::env('page'); $more_menu['edit_current_page'] = array('name' => fx::alang('Edit current page', 'system'), 'button' => array('entity' => 'content', 'action' => 'add_edit', 'content_type' => $c_page['type'], 'content_id' => $c_page['id'])); $more_menu['layout_settings'] = array('name' => fx::alang('Layout settings', 'system'), 'button' => array('entity' => 'infoblock', 'action' => 'layout_settings', 'page_id' => fx::env('page_id'))); $more_menu['switch_theme'] = array('name' => fx::alang('Change theme', 'system'), 'button' => array('entity' => 'layout', 'action' => 'change_theme', 'page_id' => fx::env('page_id'))); $more_menu['page_infoblocks'] = array('name' => fx::alang('Page infoblocks', 'system'), 'button' => array('entity' => 'infoblock', 'action' => 'list_for_page', 'page_id' => fx::env('page_id'))); $res = array('name' => fx::alang('More'), 'children' => $more_menu); fx::trigger('admin_more_menu_ready', array('menu' => &$res)); $res['children'] = array_values($res['children']); return $res; }
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 getPath($url, $site_id = null) { $url = preg_replace("~\\#.*\$~", '', $url); if (is_null($site_id)) { $site_id = fx::env('site_id'); } // @todo check if url contains another host name $url = preg_replace("~^https?://.+?/~", '/', $url); foreach ($this->routers as $r) { $result = $r['router']->getPath($url, $site_id); if ($result) { return $result; } } }
public function offsetGet($offset) { if (!$this->is_generated || !in_array($offset, self::$editable_for_generated)) { return parent::offsetGet($offset); } $res = null; $template = fx::env()->getCurrentTemplate(); if ($template && ($context = $template->context)) { $res = $context->get('field_' . $this['name'] . '_' . $offset); } if ($res) { return $res; } return parent::offsetGet($offset); }
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 contentExists() { static $content_by_type = null; if (is_null($content_by_type)) { $res = fx::db()->getResults('select `type`, count(*) as cnt ' . 'from {{floxim_main_content}} ' . 'where site_id = "' . fx::env('site_id') . '" ' . 'group by `type`'); $content_by_type = fx::collection($res)->getValues('cnt', 'type'); } $com = $this->getComponent(); if (isset($content_by_type[$com['keyword']])) { return true; } foreach ($com->getAllChildren() as $child) { if (isset($content_by_type[$child['keyword']])) { return true; } } return false; }
/** * get page (urlAlias) by url string * * @param string url string * * @return object page */ public function getByUrl($url, $site_id = null) { $url_variants = array($url); if ($site_id === null) { $site_id = fx::env('site_id'); } $url_with_no_params = preg_replace("~\\?.+\$~", '', $url); $url_variants[] = preg_match("~/\$~", $url_with_no_params) ? preg_replace("~/\$~", '', $url_with_no_params) : $url_with_no_params . '/'; if ($url_with_no_params != $url) { $url_variants[] = $url_with_no_params; } // get alias by url $alias = fx::data('urlAlias')->where('url', $url_variants)->where('site_id', $site_id)->one(); if (!$alias) { return null; } // get page by id $page = $this->getById($alias['page_id']); return $page; }
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); }
public function getLayoutInfoblock($page) { if (!is_object($page)) { fx::log(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); } $path = $page->getPath()->copy()->reverse(); foreach ($path as $c_page) { if (method_exists($c_page, 'getLayoutInfoblock')) { $layout_ib = $c_page->getLayoutInfoblock(); break; } } if ($layout_ib->getVisual()->get('is_stub') || !$layout_ib->getTemplate()) { $suitable = new Template\Suitable(); //$infoblocks = $page->getPageInfoblocks(); $infoblocks = fx::data('infoblock')->getForPage($page); // delete all parent layouts from collection $infoblocks->findRemove(function ($ib) use($layout_ib) { return $ib->isLayout() && $ib['id'] !== $layout_ib['id']; }); $suitable->suit($infoblocks, fx::env('layout_id')); return $infoblocks->findOne(function ($ib) { return $ib->isLayout(); }); } return $layout_ib; }
public function getTemplate() { $tpl_name = $this->getPropInherited('visual.template'); if (!$tpl_name) { return false; } $parts = explode(":", $tpl_name); $tpl = \Floxim\Floxim\Template\Loader::loadTemplateVariant($parts[0], $parts[1]); // Assign template into env if this infoblock is the layout infoblock if ($this['controller'] === 'layout' && $this['action'] === 'show') { fx::env('theme_template', $tpl); } return $tpl; }
public function doShow() { $path = fx::env()->getPath()->copy(); $this->assign('items', $path); }
public function getLayoutInfoblock() { if (isset($this->data['layout_infoblock'])) { return $this->data['layout_infoblock']; } $layout_ibs = $this->getPageInfoblocks()->find(function ($ib) { return $ib->isLayout(); }); if (count($layout_ibs) == 0) { // force root layout infoblock $lay_ib = fx::data('infoblock')->where('controller', 'layout')->where('site_id', fx::env('site_id'))->where('parent_infoblock_id', 0)->one(); if (!$lay_ib) { $lay_ib = fx::data('infoblock')->create(array('site_id' => fx::env('site_id'), 'controller' => 'layout', 'action' => 'show', 'page_id' => fx::env('site')->get('index_page_id'))); $lay_ib->save(); } } else { $layout_ibs = fx::data('infoblock')->sortInfoblocks($layout_ibs); $lay_ib = $layout_ibs->first(); } $this->data['layout_infoblock'] = $lay_ib; return $lay_ib; }
public function getParentConfigFields() { $vals = array(array('current_page', 'Разные на разных страницах'), array('certain_page', 'Везде одинаковые')); return array('parent_type' => array('type' => 'livesearch', 'label' => 'Данные', 'value' => 'current_page', 'parent' => array('/scope[type]' => '!~one_page'), 'values' => $vals, 'hidden_on_one_value' => true), 'parent_id' => array('type' => 'hidden', 'value' => fx::env('page_id'))); }
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; }
/** * Get the id of the page-parents * @return array */ public function getParentIds() { if (!is_null($this->parent_ids)) { return $this->parent_ids; } $path = $this['materialized_path']; if (!empty($path)) { $path = explode(".", trim($path, '.')); $this->parent_ids = $path; return $this->parent_ids; } $c_pid = $this->get('parent_id'); // if page has null parent, hold it as if it was nested to index if ($c_pid === null && ($site = fx::env('site')) && ($index_id = $site['index_page_id'])) { return $index_id != $this['id'] ? array($index_id) : array(); } $ids = array(); while ($c_pid != 0) { array_unshift($ids, $c_pid); $c_pid = fx::data('floxim.main.page', $ids[0])->get('parent_id'); } $this->parent_ids = $ids; return $ids; }
/** * Create new content entity * @param array $data Initial params * @return New content entity (not saved yet, without ID) */ public function create($data = array()) { $obj = parent::create($data); $component = fx::component($this->component_id); $obj['created'] = date("Y-m-d H:i:s"); if ($component['keyword'] != 'floxim.user.user' && ($user = fx::env()->getUser())) { $obj['user_id'] = $user['id']; } $obj['type'] = $component['keyword']; if (!isset($data['site_id'])) { $obj['site_id'] = fx::env('site')->get('id'); } $fields = $component->getAllFields()->find('default', '', System\Collection::FILTER_NEQ); foreach ($fields as $f) { if ($f['default'] === 'null') { continue; } if (!isset($data[$f['keyword']])) { if ($f['type'] == Field\Entity::FIELD_DATETIME) { $obj[$f['keyword']] = date('Y-m-d H:i:s'); } else { $obj[$f['keyword']] = $f['default']; } } } return $obj; }
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 deleteSave($input) { if (!isset($input['content_type'])) { return; } $content_type = $input['content_type']; $id = isset($input['content_id']) ? $input['content_id'] : (isset($input['id']) ? $input['id'] : false); if (!$id) { return; } $content = fx::data($content_type, $id); if (!$content) { return; } $fields = array(array('name' => 'delete_confirm', 'type' => 'hidden', 'value' => 1), $this->ui->hidden('entity', 'content'), $this->ui->hidden('action', 'delete_save'), $this->ui->hidden('content_id', $content['id']), $this->ui->hidden('fx_admin', true)); if (isset($input['content_type'])) { $fields[] = $this->ui->hidden('content_type', $input['content_type']); } if (isset($input['page_id'])) { $fields[] = $this->ui->hidden('page_id', $input['page_id']); } /** * check children */ $alert = ''; $is_linker = $content->isInstanceOf('floxim.main.linker'); if ($is_linker) { $linked_entity = $content['content']; $linked_com = $linked_entity->getComponent(); $alert = '<p>' . fx::alang('Only link will be removed, not %s itself', null, $linked_com->getItemName('one')); $linked_section = $linked_entity->getPath()->copy()->reverse()->findOne(function ($i) use($linked_entity) { return $i->isInstanceOf('floxim.nav.section') && $i['id'] !== $linked_entity['id']; }); if ($linked_section) { $alert .= fx::alang(', it will be available in the %s section', null, $linked_section['name']); } $alert .= '</p>'; //fx::log($linked_entity->getPath()); } elseif ($content->isInstanceOf('floxim.main.content')) { $all_descendants = fx::data('content')->descendantsOf($content)->all()->group('type'); $type_parts = array(); foreach ($all_descendants as $descendants_type => $descendants) { if ($descendants_type === 'floxim.main.linker') { continue; } $descendants_com = fx::component($descendants_type); $type_parts[] = count($descendants) . ' ' . fx::util()->getDeclensionByNumber($descendants_com['declension'], count($descendants)); } if (count($type_parts) > 0) { $com_name = fx::util()->ucfirst($content->getComponent()->getItemName('one')); $alert = '<p>' . $com_name . ' содержит данные, они также будут удалены:</p>'; $alert .= '<ul><li>' . join('</li><li>', $type_parts) . '</li></ul>'; } } if ($alert) { $fields[] = array('type' => 'html', 'html' => '<div class="fx_delete_alert">' . $alert . '</div>'); } $this->response->addFields($fields); $this->response->addFormButton(array('key' => 'save', 'class' => 'delete', 'label' => fx::alang('Delete'))); if (isset($input['delete_confirm']) && $input['delete_confirm']) { $response = array('status' => 'ok'); $c_page = fx::env('page'); if ($c_page) { $c_path = $c_page->getPath(); $content_in_path = $c_path->findOne('id', $content['id']); if ($content_in_path) { $response['reload'] = $content_in_path['parent'] ? $content_in_path['parent']['url'] : '/'; } } $content->delete(); return $response; } $component = fx::data('component', $content_type); if ($is_linker) { $com_name = $linked_com->getItemName('add'); } else { $com_name = $component->getItemName('add'); } $header = $is_linker ? fx::alang('delete_from_list') : fx::alang("Delete"); $header .= ' ' . mb_strtolower($com_name); if ($content_name = $content['name']) { $content_name = strip_tags($content_name); $content_name = trim($content_name); $header .= ' «' . $content_name . '»'; } elseif ($is_linker) { $header .= ' ' . fx::alang('from this list'); } $header .= "?"; $res = array('header' => $header); return $res; }
public function createSession($remember = 0, $params = array()) { $session = fx::data('session')->start(array('user_id' => $this['id'], 'site_id' => $this->isAdmin() ? null : fx::env('site_id'), 'remember' => $remember, 'params' => $params)); return $session; }
public function getIcon($what_for) { $theme = fx::env('theme_template'); if (!$theme) { return; } $dirs = $theme->getTemplateSourceDirs(); if (!$dirs) { return; } $file = $what_for . '.png'; foreach ($dirs as $dir) { $c_file = $dir . '/icons/' . $file; if (file_exists(fx::path($c_file))) { return $c_file; } } }
<?php use Floxim\Floxim\System\Fx as fx; $source_ibs = fx::data('infoblock')->getContentInfoblocks('floxim.nav.section')->find('site_id', fx::env('site')->get('id'))->getValues('name', 'id'); return array('actions' => array('*list*' => array('icon' => 'Nav', 'name' => 'Меню', 'defaults' => array('!is_pass_through' => true, '!limit' => 0, '!create_record_ib' => false, '!sorting' => 'manual', '!sorting_dir' => 'asc', '!pagination' => false, '!submenu' => 'none'), 'settings' => array('extra_infoblocks' => array('name' => 'extra_infoblocks', 'label' => 'Добавить ссылки из другого блока', 'type' => 'livesearch', 'is_multiple' => true, 'ajax_preload' => true, 'content_type' => 'infoblock', 'conditions' => array('controller' => array(fx::data('component', 'page')->getAllVariants()->getValues(function ($ch) { return $ch['keyword']; }), 'IN'), 'id' => array($this->getParam('infoblock_id'), '!='), 'site_id' => fx::env('site_id'), 'action' => 'list_infoblock')))), 'list_infoblock' => array('name' => 'Меню', 'default_scope' => function () { $ds = fx::env('site')->get('index_page_id') . '-descendants-'; return $ds; }), 'breadcrumbs' => array('icon' => 'Nav', 'icon_extra' => 'bre', 'name' => fx::alang('Breadcrumbs', 'component_section'), 'settings' => array('header_only' => array('name' => 'header_only', 'type' => 'checkbox', 'label' => fx::alang('Show only header?', 'component_section'))))));
public function prepare() { $this->addField(array('name' => $this->getSentMarkerName(), 'value' => 1, 'type' => 'hidden')); $tpl = fx::env()->getCurrentTemplate(); $form_id = isset($this['form_id']) ? $this['form_id'] : 'form'; if ($tpl) { $ib = $tpl->context->getFromTop('infoblock'); if ($ib) { $form_id = $form_id . '-' . $ib['id']; } } $this['form_id'] = $form_id; }
<?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 changeTheme($input) { $fields = array(); $layouts = fx::data('layout')->all(); $layouts_select = array(); $current_preview = fx::env()->getLayoutPreview(); foreach ($layouts as $layout) { $layouts_select[] = array($layout['id'], $layout['name'] . ($current_preview == $layout['id'] ? ' (' . fx::alang('Preview') . ')' : '')); } $fields[] = array('name' => 'layout_id', 'type' => 'select', 'values' => $layouts_select, 'value' => fx::env('layout_id'), 'label' => fx::alang('Layout', 'system')); $fields[] = $this->ui->hidden('settings_sent', 'true'); $fields[] = $this->ui->hidden('entity', 'layout'); $fields[] = $this->ui->hidden('action', 'change_theme'); $real_layout_id = fx::env('site')->get('layout_id'); if ($current_preview) { $fields[] = array('type' => 'button', 'role' => 'preset', 'label' => fx::alang('Cancel preview', 'system'), 'data' => array('layout_id' => $real_layout_id), 'parent' => array('layout_id' => '!=' . $real_layout_id), 'submit' => true); } if (isset($input['settings_sent'])) { if ($input['pressed_button'] == 'preview') { fx::env()->setLayoutPreview($input['layout_id']); } else { if (!$current_preview || $current_preview != $real_layout_id) { fx::env('site')->set('layout_id', $input['layout_id'])->save(); } if ($current_preview) { fx::env()->setLayoutPreview(false); } } return array('status' => 'ok', 'reload' => true); } $this->response->addFormButton(array('key' => 'preview', 'label' => fx::alang('Preview', 'system'))); $this->response->addFormButton(array('key' => 'save', 'label' => fx::alang('Save', 'system'))); return array('fields' => $fields, 'header' => fx::alang('Change theme', 'system'), 'view' => 'horizontal'); }