Example #1
0
 /**
  * Used to find the template and makes a call to parse all page views.  Sets the
  * defaultTemplate variable for the layout.
  * This function parses the settings for templates, in order to decide which
  * template to use, based on url, and user role.
  *
  * @todo Move this to the webpage model and optimize it.. looks a bit overcomplicated
  */
 public function _getTemplate()
 {
     if (defined('__APP_TEMPLATES')) {
         $templates = templateSettings();
         // check urls first so that we don't accidentally use a default template before a
         // template that was set for this url.
         if (!empty($templates)) {
             foreach ($templates as $key => $template) {
                 if (!empty($template['urls'])) {
                     // this over rides isDefault, so if its truly a default template, don't set urls
                     $this->templateId = $this->_urlTemplate($template);
                     // get rid of template values so we don't have to check them twice
                     unset($templates[$key]);
                 }
                 if (!empty($this->templateId)) {
                     $templated['Webpage']['id'] = $template['templateId'];
                     // used in javascript.ctp and css.ctp elements
                     // as soon as we have the first template that matches, end this loop
                     break;
                 }
             }
             // end loop
         }
         if (!empty($templates) && empty($this->templateId)) {
             foreach ($templates as $key => $template) {
                 if (!empty($template['isDefault'])) {
                     $this->templateId = $template['templateName'];
                     $this->templateId = !empty($template['userRoles']) ? $this->_userTemplate($template) : $this->templateId;
                 }
                 if (!empty($this->templateId)) {
                     $templated['Webpage']['id'] = $template['templateId'];
                     // used in javascript.ctp and css.ctp elements
                     // as soon as we have the first template that matches, end this loop
                     break;
                 }
             }
             // end loop
         }
     }
     // getting rid of the template in the navbar (no one uses it) 7/22/2013 RK
     // this is because the Webpage model is not loaded for the install site page, and
     // 'all' so that we can pass all templates to the navbar
     // $templated = $this->request->controller == 'install' && $this->request->action
     // == 'site' ? null : $this->Webpage->find('all', array('conditions' =>
     // array('Webpage.type' => 'template'), 'order' =>
     // array('FIND_IN_SET(`Webpage`.`id`, \''.$this->templateId.'\')' => 'DESC')));
     $templateFile = ROOT . DS . SITE_DIR . DS . 'Locale' . DS . 'View' . DS . 'Layouts' . DS . $this->templateId;
     $templated['Webpage']['content'] = file_get_contents($templateFile);
     // $templated = $this->request->controller == 'install' && $this->request->action
     // == 'site' ? null : $this->Webpage->find('first', array('conditions' =>
     // array('Webpage.id' => $this->templateId), 'callbacks' => false));
     // $this->set('templates', Set::combine($templated, '{n}.Webpage.id',
     // '{n}.Webpage.name')); // for the admin navbar
     // $templated = !empty($this->templateId) ? Set::extract('/Webpage[id=' .
     // $this->templateId . ']', $templated) : null; // getting it back to 'first'
     // type results
     // $templated = !empty($templated[0]) ? $templated[0] : null; // getting it back
     // to 'first' type results
     $this->Webpage->parseIncludedPages($templated, null, null, $this->userRoleId, $this->request);
     $this->set('defaultTemplate', $templated);
     if (!empty($this->templateId)) {
         $this->set('templateId', $this->templateId);
         // for the admin navbar
         $this->layout = 'custom';
     }
 }
Example #2
0
 /**
  * Build method
  * 
  */
 public function build()
 {
     $currentlyLoadedPlugins = CakePlugin::loaded();
     CakePlugin::loadAll();
     foreach (CakePlugin::loaded() as $plugin) {
         $Plugin = ClassRegistry::init($plugin . '.' . $plugin . 'AppModel');
         if (method_exists($Plugin, 'menuInit')) {
             $plugins[] = $plugin;
         }
     }
     $this->set('plugins', $plugins);
     //$plugins = array_diff(CakePlugin::loaded(), array('Activities', 'Answers', 'Categories', 'Connections', 'Contacts', 'Drafts', 'Facebook', 'Feeds', 'Forms', 'Media', 'Privileges', 'Recaptcha', 'Searchable', 'Subscribers', 'Tags', 'Twitter', 'Utils', 'Webpages', 'Wizards', 'Workflows')));
     CakePlugin::unload();
     CakePlugin::load($currentlyLoadedPlugins);
     // create some links to, and install the plugin if it isn't already
     if (($this->request->is('post') || $this->request->is('put')) && $this->request->data['WebpageMenuItem']['page_type'] == 'plugin') {
         $this->request->data['WebpageMenuItem']['item_text'] = $plugins[$this->request->data['WebpageMenuItem']['item_text']];
         // if not already installed, then install the plugin
         if (!in_array($this->request->data['WebpageMenuItem']['item_text'], $currentlyLoadedPlugins)) {
             $this->_plugin($this->request->data['WebpageMenuItem']['item_text']);
         }
         // create the menu (independent of the plugin - we can always install later)
         $MenuItem = ClassRegistry::init('Webpages.WebpageMenuItem');
         if ($MenuItem->saveAll($this->request->data)) {
             $this->Session->setFlash(__('Flow updated.'));
         } else {
             $this->Session->setFlash(__('Error occurred, please try again.'));
         }
     }
     $this->layout = 'default';
     App::uses('UserRole', 'Users.Model');
     $UserRole = new UserRole();
     $this->set('userRoles', $userRoles = $UserRole->find('all'));
     $this->set('userRoleOptions', Set::combine($userRoles, '{n}.UserRole.session_user_role_id', '{n}.UserRole.name'));
     App::uses('Template', 'Model');
     $Template = new Template();
     $this->set('templates', $templates = $Template->find('all', array('conditions' => array('Template.install NOT' => null))));
     $this->set('page_title_for_layout', 'SITE buildrr');
     $this->set('title_for_layout', 'SITE buildrr');
     $defaultTemplate = Set::combine(templateSettings(), '{n}.isDefault', '{n}');
     $defaultTemplate = Set::extract('/Template[layout=' . $defaultTemplate[1]['templateName'] . ']', $templates);
     $defaultTemplate = !empty($defaultTemplate) ? $defaultTemplate : $Template->placeholder();
     $this->set(compact('defaultTemplate'));
     $Menu = ClassRegistry::init('Webpages.WebpageMenu');
     foreach ($userRoles as $userRole) {
         $varName = preg_replace("/[^A-Za-z]/", '', $userRole['UserRole']['name']) . 'Sections';
         $conditions = $userRole['UserRole']['id'] == __SYSTEM_GUESTS_USER_ROLE_ID ? array('OR' => array(array('WebpageMenu.user_role_id' => ''), array('WebpageMenu.user_role_id' => null))) : array('WebpageMenu.user_role_id' => $userRole['UserRole']['id']);
         $menu = $Menu->find('threaded', array('conditions' => $conditions));
         // remove --Home from Home menu
         for ($i = 0; $i < count($menu[0]['children']); $i++) {
             if ($menu[0]['children'][$i]['WebpageMenu']['name'] == $menu[0]['WebpageMenu']['name']) {
                 unset($menu[0]['children'][$i]);
             }
         }
         $this->set($varName, $menu);
     }
     //$this->set('sections', $Menu->find('threaded', array('conditions' => array('WebpageMenu.lft >=' => $menu['WebpageMenu']['lft'], 'WebpageMenu.rght <=' => $menu['WebpageMenu']['rght']))));
     // used for re-ordering items $this->request->data['WebpageMenu']['children'] = $this->WebpageMenu->find('count', array('conditions' => array('WebpageMenu.lft >' => $menu['WebpageMenu']['lft'], 'WebpageMenu.rght <' => $menu['WebpageMenu']['rght'])));
     //$this->set('sections', $sections = $Menu->find('all', array('conditions' => array('OR' => array(array('WebpageMenu.parent_id' => null), array('WebpageMenu.parent_id' => ''))))));
     $menus = $Menu->generateTreeList(null, null, null, '--');
     foreach ($menus as $menu) {
         if (strpos($menu, '-') !== 0) {
             // this key should be removed, because if there is a link to the same page as the menu name
             $menus = ZuhaSet::devalue($menus, '--' . $menu, true);
         }
     }
     $this->set(compact('menus'));
 }