Пример #1
0
 /**
  * Makes a correct URL needed for all of the pagination links
  *
  * @param int $page
  * @return string
  */
 protected function makeUrl($page = 1)
 {
     $page = abs($page);
     if ($this->requestPath) {
         $url = new Router_Url($this->requestPath);
     } else {
         // Use the current parsed URL as a base
         $url = new Router_Url($this->_router->getRawRequestPath());
         if ($this->appendQuery) {
             $url->queryArgs($this->_router->getParsedUrl()->getAllQueryArgs());
         }
     }
     if ($page > 1) {
         $url->queryArgs(array($this->urlArgument => $page));
     } else {
         $url->removeQueryArgs($this->urlArgument);
     }
     return $url->make();
 }
Пример #2
0
 /**
  * Allows the user to configure the module that is attached to a
  * sector. This, however, currently depends on JavaScript enabled.
  *
  * @return string
  */
 public function indexSection($layoutName = null)
 {
     $this->setTitle(t('Edit module'));
     $this->setOutputType(self::_OT_CONFIG);
     // Check permission and if a layout has been provided
     if (!$this->_acl->check('content_layout_config_module')) {
         throw new Module_NoPermission();
     } else {
         if ($layoutName === null) {
             $this->_event->error(t('Unable to edit attached module, no layout given'));
             return zula_redirect($this->_router->makeUrl('content_layout'));
         }
     }
     // Get correct cntrlr ID that is to be edited
     try {
         $cntrlrId = $this->_router->getArgument('id');
     } catch (Router_ArgNoExist $e) {
         try {
             $cntrlrId = $this->_input->post('content_layout/cid');
         } catch (Input_KeyNoExist $e) {
             $this->_event->error(t('Unable to edit attached module, no ID given'));
             return zula_redirect($this->_router->makeUrl('content_layout'));
         }
     }
     // Create the correct layout and ensure cntrlr exists
     $layout = new Layout($layoutName);
     try {
         $cntrlr = $layout->getControllerDetails($cntrlrId);
         $module = new Module($cntrlr['mod']);
         $this->setTitle(sprintf(t('Configure attached module "%1$s"'), $module->title));
         if (!isset($cntrlr['config']['clDescription'])) {
             $cntrlr['config']['clDescription'] = '';
         }
     } catch (Layout_ControllerNoExist $e) {
         $this->_event->error(sprintf(t('Unable to edit controller "%1$d" as it does not exist'), $cntrlrId));
         return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layoutName));
     } catch (Module_NoExist $e) {
         $this->_event->error(sprintf(t('Unable to edit attached module "%1$s" as it does not exist'), $cntrlr['mod']));
         return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layoutName));
     }
     /**
      * Prepare form validation
      */
     $form = new View_form('edit/module.html', $this->getDetail('name'), false);
     $form->addElement('content_layout/config/displayTitle', $cntrlr['config']['displayTitle'], t('Display Title'), new Validator_InArray(array('true', 'false', 'custom')));
     $form->addElement('content_layout/config/customTitle', $cntrlr['config']['customTitle'], t('Custom title'), new Validator_Length(0, 255));
     $form->addElement('content_layout/config/htmlWrapClass', $cntrlr['config']['htmlWrapClass'], t('HTML class'), new Validator_Length(0, 500), $cntrlr['sector'] != 'SC');
     $form->addElement('content_layout/config/clDescription', $cntrlr['config']['clDescription'], t('Description'), new Validator_Length(0, 255), $cntrlr['sector'] != 'SC');
     $form->addElement('content_layout/cntrlr', null, t('Controller'), new Validator_Alphanumeric('_-.!+'));
     $form->addElement('content_layout/section', null, t('Section'), new Validator_Alphanumeric('_-.!+'));
     $form->addElement('content_layout/config', null, t('Config'), new Validator_Is('array'), false);
     if ($form->hasInput() && $form->isValid()) {
         $fd = $form->getValues('content_layout');
         try {
             $layout->editController($cntrlr['id'], array('con' => $fd['cntrlr'], 'sec' => $fd['section'], 'order' => $cntrlr['order'], 'config' => isset($fd['config']) ? $fd['config'] : array()));
             try {
                 $roles = $this->_input->post('acl_resources/layout_controller_' . $cntrlr['id']);
             } catch (Input_ValueNoExist $e) {
                 $roles = array();
             }
             $this->_acl->allowOnly('layout_controller_' . $cntrlr['id'], $roles);
             if ($layout->save()) {
                 $this->_event->success(sprintf(t('Configured attached module ID "%d"'), $cntrlr['id']));
             } else {
                 $this->_event->error(t('Unable to save layout, ensure file is writable'));
             }
         } catch (Layout_ControllerNoExist $e) {
             $this->_event->error(sprintf(t('Unable to edit attached module ID "%d" as it does not exist'), $cntrlr['id']));
         } catch (Theme_SectorMapNotWriteable $e) {
             $this->_event->error(sprintf(t('Unable to edit module in sector map: $s'), $e->getMessage()));
         }
         // Redirect back to correct location, FPSC layouts go back to index
         $url = new Router_Url('content_layout');
         $url->siteType($this->_router->getSiteType());
         if (strpos($layoutName, 'fpsc-') === 0) {
             $url->queryArgs(array('type' => substr($layoutName, 5)));
         } else {
             $url->controller('manage')->section($layoutName);
         }
         return zula_redirect($url);
     }
     /**
      * Gets all displays modes that this module offers, the current display
      * mode being used - once done start building up the form.
      */
     $displayModes = Hooks::notifyAll($module->name . '_display_modes');
     $currentMode = Hooks::notifyAll($module->name . '_resolve_mode', $cntrlr['con'], $cntrlr['sec'], $cntrlr['config']);
     $this->addAsset('js/edit.js');
     $form->assign(array('CID' => $cntrlr['id'], 'LAYOUT_NAME' => $layoutName, 'SECTOR' => $cntrlr['sector'], 'MODULE' => $module->getDetails(), 'DISPLAY_MODES' => empty($displayModes) ? array('default' => t('Default')) : $displayModes, 'CURRENT_MODE' => empty($currentMode) ? 'default' : $currentMode[0]));
     $jsConfig = array_merge($cntrlr, $cntrlr['config']);
     unset($jsConfig['config']);
     $form->assignHtml(array('JS_CONFIG' => zula_array_js_string($jsConfig), 'ACL_FORM' => $this->_acl->buildForm(array(t('View attached module') => 'layout_controller_' . $cntrlr['id']))));
     return $form->getOutput();
 }