/** * 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(); }
/** * Displays form for attaching a module to the provied * layout name. * * @param string $name * @param array $args * @return mixed */ public function __call($name, $args) { $this->setTitle(t('Attach new module')); $this->setOutputType(self::_OT_CONFIG); if (!$this->_acl->check('content_layout_attach_module')) { throw new Module_NoPermission(); } /** * Create the layout object and get all sectors from the theme of * the site type of this layout */ $layout = new Layout(substr($name, 0, -7)); $siteType = substr($layout->getName(), 0, strpos($layout->getName(), '-')); $theme = new Theme($this->_config->get('theme/' . $siteType . '_default')); // Build the form with validation $form = new View_form('attach/attach.html', 'content_layout'); $form->action($this->_router->makeUrl('content_layout', 'attach', $layout->getName())); $form->addElement('content_layout/module', null, t('Module'), new Validator_InArray(Module::getModules())); $form->addElement('content_layout/sector', null, t('Sector'), new Validator_InArray(array_keys($theme->getSectors()))); if ($form->hasInput() && $form->isValid()) { $fd = $form->getValues('content_layout'); // Attach the new module to the correct sector try { $cntrlrId = $layout->addController($fd['sector'], array('mod' => $fd['module'])); if ($layout->save()) { $this->_event->success(t('Successfully added module')); return zula_redirect($this->_router->makeUrl('content_layout', 'edit', $layout->getName(), null, array('id' => $cntrlrId))); } else { $this->_event->error(t('Unable to save content layout file')); } } catch (Theme_SectorNoExist $e) { $this->_event->error(sprintf(t('Unable to attach module. Sector "%s" does not exist'), $fd['sector'])); } } // Assign additional data $form->assign(array('SECTORS' => $theme->getSectors(), 'LAYOUT' => $layout->getName())); return $form->getOutput(); }
/** * Manages the Module (Hook) Load Order * * @return string|bool */ public function loadorderSection() { $this->setTitle(t('Module load order')); $this->setOutputType(self::_OT_CONFIG); // Build form validation $form = new View_form('config/loadorder.html', 'module_manager'); $form->action($this->_router->makeUrl('module_manager', 'config', 'loadorder')); $form->addElement('module_manager/modules', null, t('Modules'), new Validator_Between(0, 1000)); if ($form->hasInput() && $form->isValid()) { foreach ($form->getValues('module_manager/modules') as $tmpModule => $order) { try { $module = new Module($tmpModule); $module->setLoadOrder($order); } catch (Module_NoExist $e) { } } $this->_event->success(t('Updated module load order')); return zula_redirect($this->_router->makeUrl('module_manager', 'config', 'loadorder')); } $this->_theme->addJsFile('jQuery/plugins/dnd.js'); $this->addAsset('js/dnd_order.js'); $form->assign(array('MODULES' => Hooks::getLoadedModules())); return $form->getOutput(); }
/** * Manages settings for comments * * @return string|bool */ public function settingsSection() { $this->setTitle(t('Comments settings')); $this->setOutputType(self::_OT_CONFIG); if (!$this->_acl->check('comments_manage')) { throw new Module_NoPermission(); } // Build form and validation $form = new View_form('config/settings.html', 'comments'); $form->action($this->_router->makeUrl('comments', 'config', 'settings')); $form->addElement('comments/moderate', $this->_config->get('comments/moderate'), t('Moderate comments'), new Validator_Bool()); if ($form->hasInput() && $form->isValid()) { foreach ($form->getValues('comments') as $key => $val) { $this->_config_sql->update('comments/' . $key, $val); } $this->_event->success(t('Updated comment settings')); return zula_redirect($this->_router->makeUrl('comments', 'config', 'settings')); } return $form->getOutput(); }
/** * Builds the form that allos users to add or edit an article part. * * @param string $body * @param string $title * @param int $order * $param int $aid * $param int $pid * @return object */ protected function buildPartForm($body = null, $title = null, $order = 10, $aid = null, $pid = null) { $op = is_null($pid) ? 'add' : 'edit'; $form = new View_form('config/form_part.html', 'article', is_null($pid)); $args = array('id' => $op == 'add' ? $aid : $pid); $form->action($this->_router->makeUrl('article', 'config', $op . 'part', null, $args)); $form->addElement('article/title', $title, t('Title'), new Validator_Length(0, 255)); $form->addElement('article/body', $body, t('Content'), new Validator_Length(1, 65535)); $form->addElement('article/order', $order, t('Order'), new Validator_Int()); // Add additional form data $form->assign(array('ID' => $pid, 'ARTICLE_ID' => $aid, 'OP' => $op)); return $form; }
/** * Builds the form view for adding or editing a contact form * * @param string $name * @param string $email * @param string $body * @param int $id * @return string */ protected function buildFormView($name = null, $email = null, $body = null, $id = null) { if (is_null($id)) { $op = 'add'; $resource = 'contact-form'; } else { $op = 'edit'; $resource = 'contact-form-' . $id; // Add JS for DnD ordering $this->_theme->addJsFile('jQuery/plugins/dnd.js'); $this->addAsset('js/dnd_order.js'); } $viewForm = new View_form('config/form_view.html', 'contact', is_null($id)); $viewForm->action($this->_router->makeUrl('contact', 'config', $op, null, array('id' => $id))); $viewForm->addElement('contact/name', $name, t('Name'), new Validator_Length(1, 255)); $viewForm->addElement('contact/email', $email, t('Email'), new Validator_Email()); $viewForm->addElement('contact/body', $body, t('Body'), new Validator_Length(0, 50000), $id != null); // Assign some more data to use $viewForm->assign(array('ID' => $id, 'OP' => $op, 'FIELDS' => $id === null ? null : $this->_model()->getFormFields($id))); $viewForm->assignHtml(array('ACL_FORM' => $this->_acl->buildForm(array(t('View contact form') => $resource)))); return $viewForm; }
/** * Builds up the view to display the poll. If being loaded within * the special 'SC' sector, additional details will be displayed. * * @param int $pid * @return string */ protected function displayPoll($pid) { try { $poll = $this->_model()->getPoll($pid); // Check permission $aclResource = 'poll-' . $poll['id']; if (!$this->_acl->resourceExists($aclResource) || !$this->_acl->check($aclResource)) { throw new Module_NoPermission(); } $pollClosed = $this->isClosed($poll); $this->setTitle(sprintf($pollClosed ? t('%s (closed)') : '%s', $poll['title'])); // Get all options, votes and see if user has already voted on this poll $options = $this->_model()->getPollOptions($poll['id']); $votes = $this->_model()->getPollVotes($poll['id']); $votedOn = $this->hasUserVoted($votes); # Option which the current user has voted on (if any). if ($votedOn || $pollClosed) { /** * Display only the results to the user */ $totalVotes = 0; foreach ($votes as $val) { $totalVotes += count($val); } // Insert how many votes and the percentage there is for each option foreach ($options as $key => $tmpOpt) { $options[$key]['votes'] = isset($votes[$tmpOpt['id']]) ? count($votes[$tmpOpt['id']]) : 0; $pct = $options[$key]['votes'] > 0 ? $options[$key]['votes'] / $totalVotes * 100 : 0; $options[$key]['percent'] = round($pct, 2); } $view = $this->loadView('view/results.html'); $view->assign(array('VOTED_ON' => $votedOn, 'TOTAL_VOTES' => $totalVotes, 'SECTOR' => $this->getSector())); } else { /** * Display the form to vote on the poll. */ $view = new View_form('view/vote.html', 'poll'); $view->action($this->_router->makeUrl('poll', 'vote')); } $view->assign(array('POLL' => $poll, 'OPTIONS' => $options)); return $view->getOutput(); } catch (Poll_NoExist $e) { throw new Module_ControllerNoExist(); } }
/** * Builds the edit/add form for the URL Aliases * * @param string $alias * @param string $url * @param int|bool $redirect * @param int $id * @return string */ protected function aliasForm($alias = null, $url = null, $redirect = false, $id = null) { // Make view form class and set operation $op = is_null($id) ? 'add' : 'edit'; $form = new View_form('form.html', 'aliases', is_null($id)); if ($op == 'add') { $form->action($this->_router->makeUrl('aliases', 'index', $op)); } else { $form->action($this->_router->makeUrl('aliases', 'index', $op, null, array('id' => $id))); } // Add all of the validators in $form->addElement('alias/alias', $alias, t('Alias'), array(new Validator_Length(1, 255), new Validator_Alphanumeric('_-.!/'))); $form->addElement('alias/url', $url, 'URL', new Validator_Length(1, 255)); $form->addElement('alias/redirect', $redirect, t('Redirect'), new Validator_Bool()); // Set op and return $form->assign(array('OP' => $op, 'ID' => $id)); return $form; }