Exemplo n.º 1
0
 /**
  * Displays all controllers from the layout map, categories
  * by which sector they are in.
  *
  * @param string $name
  * @param array $args
  * @return mixed
  */
 public function __call($name, $args)
 {
     $this->setOutputType(self::_OT_CONFIG);
     if (!$this->_acl->check('content_layout_config_module')) {
         throw new Module_NoPermission();
     }
     $layoutName = substr($name, 0, -7);
     $siteType = substr($layoutName, 0, strpos($layoutName, '-'));
     if (empty($layoutName) || !$this->_router->siteTypeExists($siteType)) {
         $this->_event->error(t('Unable to manage content layout, invalid name given'));
         return zula_redirect($this->_router->makeUrl('content_layout'));
     }
     $this->setTitle(sprintf(t('"%s" content layout'), $layoutName));
     $this->setOutputType(self::_OT_CONFIG);
     // Create the new content layout object
     $layout = new Layout($layoutName);
     if (!$layout->exists()) {
         $this->_event->error(t('Provided layout does not exist'));
         return zula_redirect($this->_router->makeUrl('content_layout'));
     }
     // Build view form with validation for the regex (for layout)
     $form = new View_form('manage/main.html', 'content_layout');
     $form->caseSensitive();
     $form->action($this->_router->makeUrl('content_layout', 'manage', $layoutName));
     $form->addElement('content_layout/regex', $layout->getRegex(), t('URL/Regex'), new Validator_Length(2, 255));
     if ($form->hasInput() && $form->isValid()) {
         $layout->setRegex($form->getValues('content_layout/regex'));
         if ($layout->save()) {
             $this->_event->success(t('Updated content layout'));
             return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layoutName));
         }
         $this->_event->error(t('Unable to save content layout'));
     }
     /**
      * Gather all controllers in the layout for the theme of the site type
      * this layout is for.
      */
     $theme = new Theme($this->_config->get('theme/' . $siteType . '_default'));
     $themeSectors = array();
     foreach ($theme->getSectors() as $sector) {
         $themeSectors[$sector['id']] = array('sector' => $sector, 'cntrlrs' => $layout->getControllers($sector['id']));
     }
     // Assign additional data
     $form->assign(array('layoutName' => $layout->getName(), 'themeSectors' => $themeSectors));
     $this->_theme->addJsFile('jQuery/plugins/dnd.js');
     $this->addAsset('js/dnd_order.js');
     return $form->getOutput();
 }
Exemplo n.º 2
0
 /**
  * Provides ability to add a new content layout. The user will
  * be redirect to the page, as if they had gone 'Edit' on the
  * layout once it has been created.
  *
  * @return string
  */
 public function addSection()
 {
     $this->setTitle(t('Add new layout'));
     $this->setOutputType(self::_OT_CONFIG);
     try {
         $cloner = $this->_router->getArgument('clone');
         $cloner = new Layout($cloner);
         if ($cloner->exists()) {
             $cloneName = $cloner->getName();
             $cloneRegex = $cloner->getRegex();
             $this->setTitle(sprintf(t('Clone layout "%1$s"'), $cloneName));
         } else {
             throw new Exception();
         }
     } catch (Exception $e) {
         $cloneName = null;
         $cloneRegex = null;
     }
     // Build and check form
     $form = new View_Form('index/form_layout.html', 'content_layout');
     $form->action($this->_router->makeUrl('content_layout', 'index', 'add'));
     $form->addElement('content_layout/name', null, t('Name'), array(new Validator_Alphanumeric('-'), new Validator_Length(2, 225)));
     $form->addElement('content_layout/regex', $cloneRegex, t('URL/Regex'), new Validator_Length(2, 255));
     $form->addElement('content_layout/site_type', $this->_router->getDefaultSiteType(), t('Site type'), new Validator_InArray($this->_router->getSiteTypes()));
     $form->addElement('content_layout/clone', $cloneName, t('Clone'), array(new Validator_Alphanumeric('-'), new Validator_Length(0, 225)));
     if ($form->hasInput() && $form->isValid()) {
         $fd = $form->getValues('content_layout');
         // Check if we are cloning a layout
         if ($fd['clone']) {
             $layout = new Layout($fd['clone']);
             $layout->setName($fd['site_type'] . '-' . $fd['name']);
         } else {
             $layout = new Layout($fd['site_type'] . '-' . $fd['name']);
         }
         $layout->setRegex($fd['regex']);
         $path = $this->_zula->getDir('config') . '/layouts/' . $layout->getName() . '.xml';
         if ($layout->save($path)) {
             $this->_event->success(t('Added new content layout'));
             return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layout->getName()));
         }
         $this->_event->error(t('Unable to save content layout'));
     }
     return $form->getOutput();
 }