Ejemplo n.º 1
0
 /**
  * Fetch the template route for the specified template.
  *
  * @param string $group		The name of the template group
  * @param string $template	The name of the template
  * @access public
  * @return EE_Route  An instantiated route object for the matched route
  */
 public function fetch_route($group, $template)
 {
     $site_id = ee()->config->item('site_id');
     $config = TemplateRoute::getConfig();
     $route = "{$group}/{$template}";
     if (!empty($config[$route])) {
         return new EE_Route($config[$route]);
     }
     ee()->db->select('route, route_parsed, route_required, template_name, group_name');
     ee()->db->from('templates');
     ee()->db->join('template_routes', 'templates.template_id = template_routes.template_id');
     ee()->db->join('template_groups', 'templates.group_id = template_groups.group_id');
     ee()->db->where('templates.site_id', $site_id);
     ee()->db->where('template_name', $template);
     ee()->db->where('group_name', $group);
     ee()->db->where('route is not null');
     $query = ee()->db->get();
     if ($query->num_rows() > 0) {
         $required = $query->row()->route_required == 'y';
         return new EE_Route($query->row()->route, $required);
     }
 }
Ejemplo n.º 2
0
 protected function generateSidebar($active = NULL)
 {
     $active_group_id = NULL;
     if (is_numeric($active)) {
         $active_group_id = (int) $active;
     }
     $sidebar = ee('CP/Sidebar')->make();
     // Template Groups
     $template_group_list = $sidebar->addHeader(lang('template_groups'));
     if (ee()->cp->allowed_group('can_create_template_groups')) {
         $template_group_list = $template_group_list->withButton(lang('new'), ee('CP/URL')->make('design/group/create'));
     }
     $template_group_list = $template_group_list->addFolderList('template-group')->withRemoveUrl(ee('CP/URL')->make('design/group/remove'))->withRemovalKey('group_name')->withNoResultsText(lang('zero_template_groups_found'));
     $template_groups = ee('Model')->get('TemplateGroup')->filter('site_id', ee()->config->item('site_id'))->order('group_name', 'asc');
     if (ee()->session->userdata['group_id'] != 1) {
         $assigned_groups = array_keys(ee()->session->userdata['assigned_template_groups']);
         $template_groups->filter('group_id', 'IN', $assigned_groups);
         if (empty($assigned_groups)) {
             $template_groups->markAsFutile();
         }
     }
     foreach ($template_groups->all() as $group) {
         $item = $template_group_list->addItem($group->group_name, ee('CP/URL')->make('design/manager/' . $group->group_name));
         $item->withEditUrl(ee('CP/URL')->make('design/group/edit/' . $group->group_name));
         $item->withRemoveConfirmation(lang('template_group') . ': <b>' . $group->group_name . '</b>')->identifiedBy($group->group_name);
         if (!ee()->cp->allowed_group('can_edit_template_groups')) {
             $item->cannotEdit();
         }
         if (!ee()->cp->allowed_group('can_delete_template_groups')) {
             $item->cannotRemove();
         }
         if ($active_group_id == $group->group_id) {
             $item->isActive();
         }
         if ($group->is_site_default) {
             $item->asDefaultItem();
         }
     }
     // System Templates
     $system_templates = $sidebar->addHeader(lang('system_templates'))->addFolderList('system-templates');
     $item = $system_templates->addItem(lang('messages'), ee('CP/URL')->make('design/system'))->withEditUrl(ee('CP/URL')->make('design/system'))->cannotRemove();
     if ($active == 'messages') {
         $item->isActive();
     }
     $item = $system_templates->addItem(lang('email'), ee('CP/URL')->make('design/email'))->withEditUrl(ee('CP/URL')->make('design/email'))->cannotRemove();
     if ($active == 'email') {
         $item->isActive();
     }
     if (ee()->cp->allowed_group('can_admin_mbr_templates') && ee('Model')->get('Module')->filter('module_name', 'Member')->first()) {
         $item = $system_templates->addItem(lang('members'), ee('CP/URL')->make('design/members'))->withEditUrl(ee('CP/URL')->make('design/members'))->cannotRemove();
         if ($active == 'members') {
             $item->isActive();
         }
     }
     if (ee()->config->item('forum_is_installed') == "y") {
         $item = $system_templates->addItem(lang('forums'), ee('CP/URL')->make('design/forums'))->withEditUrl(ee('CP/URL')->make('design/forums'))->cannotRemove();
         if ($active == 'forums') {
             $item->isActive();
         }
     }
     // Template Partials
     if (ee()->cp->allowed_group_any('can_create_template_partials', 'can_edit_template_partials', 'can_delete_template_partials')) {
         $header = $sidebar->addHeader(lang('template_partials'), ee('CP/URL')->make('design/snippets'));
         if (ee()->cp->allowed_group('can_create_template_partials')) {
             $header->withButton(lang('new'), ee('CP/URL')->make('design/snippets/create'));
         }
         if ($active == 'partials') {
             $header->isActive();
         }
     }
     // Template Variables
     if (ee()->cp->allowed_group_any('can_create_template_variables', 'can_edit_template_variables', 'can_delete_template_variables')) {
         $header = $sidebar->addHeader(lang('template_variables'), ee('CP/URL')->make('design/variables'));
         if (ee()->cp->allowed_group('can_create_template_variables')) {
             $header->withButton(lang('new'), ee('CP/URL')->make('design/variables/create'));
         }
         if ($active == 'variables') {
             $header->isActive();
         }
     }
     // Template Routes
     if (!IS_CORE && !TemplateRoute::getConfig() && ee()->cp->allowed_group('can_admin_design')) {
         $header = $sidebar->addHeader(lang('template_routes'), ee('CP/URL')->make('design/routes'));
         if ($active == 'routes') {
             $header->isActive();
         }
     }
     ee()->cp->add_js_script(array('file' => array('cp/design/menu')));
 }