Пример #1
0
 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;
 }
Пример #2
0
 public function addSave($input)
 {
     $result = array('status' => 'ok');
     $keyword = trim($input['keyword']);
     $name = trim($input['name']);
     $vendor = trim($input['vendor']);
     if (empty($keyword)) {
         $keyword = fx::util()->strToKeyword($name);
     }
     //$keyword = $vendor.'.'.fx::util()->underscoreToCamel($keyword,true);
     $keyword = fx::util()->camelToUnderscore($vendor) . '.' . $keyword;
     $existing = fx::data('layout')->where('keyword', $keyword)->one();
     if ($existing) {
         return array('status' => 'error', 'text' => sprintf(fx::alang('Layout %s already exists'), $keyword));
     }
     $data = array('name' => $name, 'keyword' => $keyword);
     $layout = fx::data('layout')->create($data);
     try {
         $layout->save();
         $layout->scaffold();
         fx::trigger('layout_created', array('layout' => $layout));
         $result['reload'] = '#admin.layout.all';
     } catch (Exception $e) {
         $result['status'] = 'error';
     }
     return $result;
 }
Пример #3
0
 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;
 }
Пример #4
0
 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;
 }
Пример #5
0
 public static function loadTemplateVariant($name, $action = null, $context = null, $force_group = false, $tags = null)
 {
     // just return new template instance
     if (!$action) {
         $tpl_class = self::import($name);
         if (!$tpl_class) {
             return false;
         }
         return new $tpl_class(null, $context);
     }
     // if group is forced
     if ($force_group) {
         $tpl_class = self::import($force_group);
         if (!$tpl_class) {
             return false;
         }
         // recount action name for external group
         if ($force_group !== $name) {
             $action = str_replace(".", "_", $name) . "__" . $action;
         }
         $method = $tpl_class::getActionMethod($action, $context, $tags);
         if (!$method) {
             return false;
         }
         $tpl = new $tpl_class(null, $context);
         $tpl->forceMethod($method);
         return $tpl;
     }
     // run full process - trigger event and collect external implementations
     $base_class = self::import($name);
     $found_variants = fx::trigger('loadTemplate', array('name' => $name, 'action' => $action, 'context' => $context, 'full_name' => $name . ':' . $action, 'tags' => $tags));
     // no external implementation, quickly return base one
     if (!$found_variants) {
         if (!$base_class) {
             return false;
         }
         $method = $base_class::getActionMethod($action, $context, $tags);
         if (!$method) {
             return false;
         }
         $tpl = new $base_class(null, $context);
         $tpl->forceMethod($method);
         return $tpl;
     }
     if ($local_method = $base_class::getActionMethod($action, $context, $tags, true)) {
         $local_method[2] = $base_class;
         $found_variants[] = $local_method;
     }
     usort($found_variants, function ($a, $b) use($base_class) {
         $ap = $a[1];
         $bp = $b[1];
         if ($ap > $bp) {
             return -1;
         }
         if ($ap < $bp) {
             return 1;
         }
         $a_loc = $a[2] === $base_class;
         $b_loc = $b[2] === $base_class;
         if ($a_loc) {
             return 1;
         }
         if ($b_loc) {
             return -1;
         }
         return 0;
     });
     $winner = $found_variants[0];
     $winner_class = $winner[2];
     $tpl = new $winner_class(null, $context);
     $tpl->forceMethod($winner[0]);
     return $tpl;
 }
Пример #6
0
 public function can($action, $target)
 {
     $method = 'can' . fx::util()->underscoreToCamel($action);
     if (method_exists($this, $method)) {
         $res = $this->{$method}($target);
         if (is_bool($res)) {
             return $res;
         }
     }
     if ($this->isAdmin()) {
         return true;
     }
     $event_res = fx::trigger('checkAbility', array('user' => $this, 'action' => $action, 'target' => $target));
     return $event_res;
 }
Пример #7
0
 public static function renderArea($area, $context, $mode = 'both')
 {
     if (isset($area['size'])) {
         $area['size'] = preg_replace("~[^a-z0-9]+~i", ',', $area['size']);
     }
     $is_admin = fx::isAdmin();
     if ($mode != 'marker') {
         fx::trigger('render_area', array('area' => $area));
         if ($is_admin && $context->isIdle()) {
             return;
         }
     }
     if ($is_admin) {
         ob_start();
     }
     if ($mode != 'marker' && (!isset($area['render']) || $area['render'] != 'manual')) {
         $area_blocks = fx::page()->getAreaInfoblocks($area['id']);
         $pos = 1;
         foreach ($area_blocks as $ib) {
             $ib->addParams(array('infoblock_area_position' => $pos));
             $result = $ib->render();
             echo $result;
             $pos++;
         }
     }
     if ($is_admin) {
         $area_result = ob_get_clean();
         self::$area_replacements[] = array($area, $area_result);
         $marker = '###fxa' . (count(self::$area_replacements) - 1);
         if ($mode != 'both') {
             $marker .= '|' . $mode;
         }
         $marker .= '###';
         echo $marker;
     }
 }