Exemple #1
0
 /**
  * Route users
  * @return string template
  */
 function route($parts)
 {
     if (parent::route($parts)) {
         return true;
     }
     $layout = $this->context->cfg('template', 'root');
     // request
     $r = new stdClass();
     $r->action = 'users';
     $r->user = '';
     // [cp][profile]
     $count = count($parts);
     // users actions
     if (1 == $count) {
         $r->action = $parts[0];
         $parts = array();
     } else {
         // users/cp/action/*params////*
         if ('cp' == @$parts[0] && $count > 1) {
             $layout = $this->context->cfg('cp_template', 'root');
             $r->action = 'cp';
             $r->option = $parts[1];
             $r->option_params = count($parts > 2) ? array_splice($parts, 2) : array();
             $parts = array();
         }
     }
     $count = count($parts);
     if (1 == $count) {
         $r->user = $parts[0];
     }
     /** @var users_controller */
     $controller = $this->context->controller;
     $controller->run($r);
     $this->context->renderer->set_page_template($layout)->set_main_template($controller->get_template());
     return true;
 }
Exemple #2
0
 /**
  * Try base route,
  * otherwise try find out node
  *
  * @todo move stuff to controller
  */
 function route($parts)
 {
     // Try abse routes
     if (parent::route($parts)) {
         return true;
     }
     $uri = implode('/', $parts);
     $in_index = empty($parts);
     if ($in_index) {
         $this->render_index();
         return true;
     }
     $comment_filter = $this->create_filter('sat.comment/modify');
     $this->append_filter('comment_modify', $comment_filter);
     if (!$comment_filter->match_uri($uri)) {
         $comment_filter = null;
     }
     $pagination_filter = $this->create_filter('pagination');
     // append filter for later use
     $this->append_filter('pagination', $pagination_filter);
     $pagination_filter->match_uri($uri);
     // string(54) "14_dvigatel_mehanicheskaya_chast/klapanniy_zazor_2zzge"
     $node_url = '/' . $uri;
     if (strings::substr($node_url, -5) != loader::DOT_HTML) {
         $node_url .= '/';
     }
     $this->_static_node_url = $node_url;
     $c_site_id = $this->context->get_current_site_id();
     $_item = $this->context->get_tree_item($c_site_id, $node_url, tf_sat::TREE_URL);
     if (!$_item) {
         throw new router_exception('Node not found', router_exception::NOT_FOUND);
     }
     /** @var sat_node_item $item */
     $item = $this->context->get_node($_item['id']);
     if (!$item) {
         throw new router_exception('Node item not found', router_exception::NOT_FOUND);
     }
     core::dprint(array('Found node %d, %s ', $item->id, $item->title));
     $tlayout = $item->get_template();
     if (isset($tlayout['site']['order'])) {
         $item->get_children_handle()->set_order($tlayout['site']['order']);
     }
     core::event('sat_route_before', $item);
     /* pagination filter */
     $page = $pagination_filter->get_start();
     try {
         $item->apply_children_filter($page);
     } catch (collection_filter_exception $e) {
         throw new router_exception($e->getMessage(), router_exception::NOT_FOUND);
     }
     $item->get_parent();
     // load secondary, if not disabled
     if (!isset($tlayout["site"]["item"]["deps"]) || $tlayout["site"]["item"]["deps"]) {
         $item->with_deps(@$tlayout["site"]["item"]["deps"]);
         $item->load_secondary(@$tlayout["site"]["item"]["deps"]);
     }
     $this->_current_node = $item;
     // for comments bindings
     $this->context->controller->set_current_item($item);
     if ($comment_filter) {
         $comment_filter->run();
     }
     /** @var tf_renderer */
     $renderer = $this->context->renderer;
     //
     // template alternative layout {layout}.tpl
     //
     if ($tlayout['template']) {
         $renderer->set_page_template($tlayout['template']);
     }
     core::event('sat_render_before', $item);
     $renderer->current->node = $item->render();
     $renderer->current->node_chain = $this->context->get_node_parents($item->id)->render();
     $renderer->set_main_template(($tpl = $this->context->get_controller()->get_template()) ? $tpl : 'sat/node/item');
     return true;
 }