/** * Posts a new comment for a given request path, if it * is valid. Once done it will return back to the URL * * @return bool|string */ public function indexSection() { $this->setTitle(t('Post comment')); if (!$this->_acl->check('comments_post')) { throw new Module_NoPermission(); } // Check request path hash try { $hashPath = $this->_input->post('comments/hash'); if (isset($_SESSION['mod']['comments'][$hashPath])) { $requestPath = $_SESSION['mod']['comments'][$hashPath]['path']; $siteType = $_SESSION['mod']['comments'][$hashPath]['siteType']; } else { throw new Exception(); } } catch (Exception $e) { if (empty($_SESSION['previous_url'])) { $_SESSION['previous_url'] = $this->_router->getBaseUrl(); } $this->_event->error(t('Unable to post comment')); return zula_redirect($_SESSION['previous_url']); } // Build and validate form $isGuest = $this->_session->isLoggedIn() == false; $form = new View_form('form.html', 'comments'); $form->antispam(true); $form->addElement('comments/hash', $hashPath, 'hash path', new Validator_Alphanumeric()); $form->addElement('comments/name', null, t('Name'), new Validator_Length(0, 255), $isGuest); $form->addElement('comments/website', null, t('Website'), new Validator_Url(false), false); $form->addElement('comments/body', null, t('Message'), new Validator_Length(10, 4096)); if ($form->hasInput() && $form->isValid()) { $fd = $form->getValues('comments'); if ($isGuest == false) { $fd['name'] = ''; # Registered users will have their own details used } try { $commentId = $this->_model()->add($requestPath, $fd['body'], $fd['name'], $fd['website']); // Redirect back to correct place if ($siteType != $this->_router->getDefaultSiteType()) { $requestPath = $siteType . '/' . $requestPath; } $url = $this->_router->makeUrl($requestPath); if ($this->_config->get('comments/moderate')) { $this->_event->success(t('Comment is now in the moderation queue')); } else { $this->_event->success(t('Added new comment')); $url->fragment('comment-' . $commentId); } return zula_redirect($url); } catch (Exception $e) { $this->_event->error($e->getMessage()); } } $this->_session->storePrevious(false); # Don't store this URL as previous return $form->getOutput(); }
/** * Shows a list of enabled and disabled sites * * @return string */ public function indexSection() { if (!$this->_acl->check('shareable_manage')) { throw new Module_NoPermission(); } $this->setTitle(t('Shareable configuration')); $this->setOutputType(self::_OT_CONFIG); // Get sites $sites = $this->_model()->getSites(); $siteCount = count($sites); // Build form with validation $form = new View_form('config/manage.html', 'shareable'); $form->addElement('shareable/order', null, t('Order'), new Validator_Length($siteCount)); $form->addElement('shareable/enabled', null, t('Enabled'), new Validator_Length(0, $siteCount), false); if ($form->hasInput() && $form->isValid()) { try { $enabledSites = $form->getValues('shareable/enabled'); } catch (View_FormValueNoExist $e) { $enabledSites = array(); } $editData = array(); foreach ($form->getValues('shareable/order') as $key => $val) { $editData[$key] = array('order' => abs($val), 'disabled' => !in_array($key, $enabledSites)); } $this->_model()->edit($editData); $this->_event->success(t('Updated config')); return zula_redirect($this->_router->makeUrl('shareable', 'config')); } $this->_theme->addJsFile('jQuery/plugins/dnd.js'); $this->addAsset('js/dnd_order.js'); $form->assign(array('sites' => $sites)); return $form->getOutput(); }
/** * Shows form for editing an existing comment * * @param int $commentId * @return bool|string */ public function indexSection($commentId = null) { $this->setTitle(t('Edit comment')); // Check if we are editing 'inline' or via the main config cntrlr if ($this->_router->hasArgument('inline') || $this->_input->has('post', 'comments_inline')) { $editInline = true; } else { $editInline = false; $this->setPageLinks(array(t('Manage comments') => $this->_router->makeUrl('comments', 'config'), t('Settings') => $this->_router->makeUrl('comments', 'config', 'settings'))); } try { if ($commentId === null) { $commentId = $this->_input->post('comments/id'); } $comment = $this->_model()->getDetails($commentId); } catch (Comments_NoExist $e) { $this->_event->error(t('Unable to edit comment as it does not exist')); $url = $editInline ? $this->_router->getBaseUrl() : $this->_router->makeUrl('comments', 'config'); return zula_redirect($url); } if (($comment['user_id'] == Ugmanager::_GUEST_ID || $comment['user_id'] != $this->_session->getUserId()) && !$this->_acl->check('comments_manage')) { throw new Module_NoPermission(); } // Build form and validation $form = new View_form('edit.html', 'comments', false); $form->addElement('comments/id', $comment['id'], 'ID', new Validator_Int()); $form->addElement('comments/website', $comment['website'], t('Website'), new Validator_Url(false), false); $form->addElement('comments/body', $comment['body'], t('Message'), new Validator_Length(10, 4096)); if ($form->hasInput() && $form->isValid()) { $fd = $form->getValues('comments'); unset($fd['id']); try { $commentId = $this->_model()->edit($comment['id'], $fd); $this->_event->success(sprintf(t('Edited comment #%1$d'), $comment['id'])); if ($editInline === false) { return zula_redirect($this->_router->makeUrl('comments', 'config')); } else { if ($this->_router->getSiteType() != $this->_router->getDefaultSiteType()) { $comment['url'] = $this->_router->getSiteType() . '/' . $comment['url']; } return zula_redirect($this->_router->makeUrl($comment['url'])->fragment('comment-' . $comment['id'])); } } catch (Exception $e) { $this->_event->error($e->getMessage()); } } $form->assign(array('edit_inline' => $editInline)); return $form->getOutput(); }
/** * 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(); }
/** * Update common basic settings so a user doesn't forget * to change them after installation. * * @return bool|string */ public function indexSection() { $this->setTitle(t('Basic configuration')); if ($this->_zula->getMode() != 'cli' && (!isset($_SESSION['installStage']) || $_SESSION['installStage'] !== 5)) { return zula_redirect($this->_router->makeUrl('install', 'checks')); } // Get data from either a form or CLI arguments if ($this->_zula->getMode() == 'cli') { $title = $this->_input->cli('t'); $email = $this->_input->cli('e'); $data = array('config' => array('title' => $title), 'mail' => array('outgoing' => $email, 'incoming' => $email)); } else { $form = new View_form('settings.html', 'install'); $form->addElement('settings/config/title', null, t('Site title'), new Validator_Length(0, 255)); $form->addElement('settings/meta/description', null, t('Meta description'), new Validator_Length(0, 255)); $form->addElement('settings/mail/outgoing', null, t('Outgoing email'), new Validator_Email()); $form->addElement('settings/mail/incoming', null, t('Incoming email'), new Validator_Email()); $form->addElement('settings/mail/subject_prefix', true, t('Email prefix'), new Validator_Bool()); if ($form->hasInput() && $form->isValid()) { $data = $form->getValues('settings'); } else { return $form->getOutput(); } } foreach ($data as $confRealm => $confValues) { foreach ($confValues as $key => $val) { $this->_config_sql->update($confRealm . '/' . $key, $val); } } // Update scheme/protocol that is being used $this->_config_sql->add('config/protocol', $this->_router->getScheme()); if (isset($_SESSION['installStage'])) { ++$_SESSION['installStage']; } $this->_event->success(t('Basic configuration updated')); return zula_redirect($this->_router->makeUrl('install', 'complete')); }
/** * 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(); }
/** * Displays all users awaiting validation, these can either be accepted * or declined. * * @return string */ public function validationsSection() { $this->setTitle(t('Manage validations')); $this->setOutputType(self::_OT_CONFIG); if (!$this->_acl->check('session_manage')) { throw new Module_NoPermission(); } // Build form validation $form = new View_form('config/validation.html', 'session'); $form->addElement('session/action', null, t('Action'), new Validator_InArray(array('accept', 'decline'))); $form->addElement('session/uids', null, t('Users'), new Validator_Is('array')); if ($form->hasInput() && $form->isValid()) { // Activate or Decline/Remove all selected users foreach ($form->getValues('session/uids') as $user) { try { $user = $this->_ugmanager->getUser($user, true, true); if ($user['activate_code']) { if ($form->getValues('session/action') == 'accept') { $this->_ugmanager->editUser($user['id'], array('status' => 'active', 'activate_code' => null)); $viewFile = 'config/validation_accepted.txt'; $eventMsg = t('Selected users are now active'); } else { $this->_ugmanager->deleteUser($user['id']); $viewFile = 'config/validation_declined.txt'; $eventMsg = t('Selected users have been declined'); } $msgView = $this->loadView($viewFile); $msgView->assign(array('USERNAME' => $user['username'])); // Send off the correct email to the user, to notify them. $message = new Email_Message(t('Account Status'), $msgView->getOutput()); $message->setTo($user['email']); $email = new Email(); $email->send($message); } } catch (Ugmanager_UserNoExist $e) { // We don't really care if it does not exist, do nothing. } catch (Email_Exception $e) { $this->_event->error(t('An error occurred when sending the validation email')); $this->_log->message('Unable to send validation email: ' . $e->getMessage(), Log::L_WARNING); } } $this->_event->success($eventMsg); return zula_redirect($this->_router->makeUrl('session', 'config', 'validations')); } $form->assign(array('VALIDATIONS' => $this->_model()->getAwaitingValidation())); 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(); }
/** * Allows for shorter URLs. Selects a CSS file to edit, will use * the first CSS file if none is specified * * @param string $name * @param array $args * @return string|bool */ public function __call($name, $args) { if (!$this->_acl->check('theme_view_css')) { throw new Module_NoPermission(); } $this->setTitle(t('Edit CSS files')); $this->setOutputType(self::_OT_CONFIG); /** * Gather details of the theme and check if the CSS file exists */ try { $theme = new Theme(substr($name, 0, -7)); $this->setTitle(sprintf(t('"%s" stylesheets'), $theme->getDetail('title'))); // All CSS files for this theme $themeCssFiles = $theme->getAllCss(); if (empty($themeCssFiles)) { $this->_event->error(t('There are no CSS files available')); return zula_redirect($this->_router->makeUrl('theme')); } else { try { $selectedCss = $this->_router->getArgument('file'); } catch (Router_ArgNoExist $e) { $cssDetails = reset($themeCssFiles); $selectedCss = $cssDetails['name']; } if (isset($themeCssFiles[$selectedCss])) { $cssDetails = $themeCssFiles[$selectedCss]; } else { // Eek, the CSS file does not exist! $this->_event->error(sprintf(t('Stylesheet "%1$s" does not exist'), $selectedCss)); return zula_redirect($this->_router->makeUrl('theme', 'css', $theme->getDetail('name'))); } } } catch (Theme_NoExist $e) { $this->_event->error(t('Theme does not exist')); return zula_redirect($this->_router->makeUrl('theme')); } /** * Setup the form and validation for the contents */ $form = new View_form('css.html', 'theme'); $form->addElement('theme/body', file_get_contents($cssDetails['path']), t('Stylesheet'), new Validator_length(0, 10000)); if ($form->hasInput() && $form->isValid()) { if (!$this->_acl->check('theme_edit_css')) { throw new Module_NoPermission(); } else { if (zula_is_writable($cssDetails['path'])) { file_put_contents($cssDetails['path'], $form->getValues('theme/body')); $this->_event->success(t('Stylesheet updated')); return zula_redirect($this->_router->makeUrl('theme', 'css', $theme->getDetail('name'), null, array('file' => $cssDetails['name']))); } else { $this->_event->error(sprintf(t('CSS file "%s" is not writable'), $cssDetails['path'])); } } } // Assign other data to be provided to the view file $this->addAsset('js/editor.js'); $this->_theme->addCssFile('jquery.linedtextarea.css'); $this->_theme->addJsFile('jquery.linedtextarea'); $form->assign(array('CSS_FILES' => $themeCssFiles, 'CSS_NAME' => $selectedCss, 'THEME' => array('NAME' => $theme->getDetail('name')))); return $form->getOutput(); }
/** * Allows the user to change an expired password, however it can not be * the same as the current password! * * @return string|bool */ public function expireSection() { if (empty($_SESSION['mod']['session']['changePw'])) { throw new Module_ControllerNoExist(); } $this->setTitle(t('Your password has expired')); $form = new View_form('pwd/expire.html', 'session'); $form->addElement('session/password', null, 'Password', array(new Validator_Length(4, 32), new Validator_Confirm('session/password_confirm', Validator_Confirm::_POST), array($this, 'validatePreviousPw'))); if ($form->hasInput() && $form->isValid()) { $this->_ugmanager->editUser($this->_session->getUserId(), $form->getValues('session')); $this->_event->success(t('Your password has been successfully changed')); unset($_SESSION['mod']['session']['changePw']); return zula_redirect($this->_router->getCurrentUrl()); } return $form->getOutput(); }
/** * Handles adding a new media item to a category, either uploaded or from * external media such as a YouTube video. * * @param string $name * @param array $args * @return mixed */ public function __call($name, $args) { $type = substr($name, 0, -7); if ($type != 'external' && $type != 'upload') { throw new Module_ControllerNoExist(); } $this->setTitle(t('Add/upload new media item')); // Prepare the form validation $form = new View_form('add/form.html', 'media'); $form->addElement('media/cid', null, 'CID', new Validator_Int()); if ($type == 'external') { // Specific for external YouTube $form->addElement('media/external/service', null, t('External service'), new Validator_Length(1, 32)); $form->addElement('media/external/youtube_url', null, t('YouTube URL'), new Validator_Url()); } if ($form->hasInput() && $form->isValid()) { /** * Ensure the category exists and user has permission */ try { $category = $this->_model()->getCategory($form->getValues('media/cid')); if (!$this->_acl->check('media-cat_upload_' . $category['id'])) { throw new Module_NoPermission(); } } catch (Media_CategoryNoExist $e) { $this->_event->error(t('Media category does not exist')); return zula_redirect($this->_router->makeUrl('media')); } try { if ($type == 'upload') { $uploadedFiles = $this->handleUpload($form->getValues('media')); } else { if ($type == 'external') { $uploadedFiles = $this->handleExternal($form->getValues('media')); } } $fileCount = count($uploadedFiles); foreach ($uploadedFiles as $file) { if (!isset($file['external'])) { $file['external'] = array('service' => '', 'id' => ''); } $lastItem = $this->_model()->addItem($category['id'], $file['title'], $file['desc'], $file['type'], $file['file'], $file['thumbnail'], $file['external']['service'], $file['external']['id']); } if ($fileCount == 1) { $this->_event->success(t('Added new media item')); } else { $this->_event->success(sprintf('Added %1$d new media items', $fileCount)); } return zula_redirect($this->_router->makeUrl('media', 'manage', 'outstanding')->queryArgs(array('cid' => $category['id']))); } catch (Media_Exception $e) { $this->_event->error($e->getMessage()); } } // Redirect back to correct location $url = $this->_router->makeUrl('media', 'add'); try { $url->queryArgs(array('cid' => $this->_input->post('media/cid'))); } catch (Input_KeyNoExist $e) { } return zula_redirect($url); }
/** * 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; }
/** * 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(); }
/** * Magic method, allows for shorter URLs. Display the specified * contact form to the user. * * @param string $name * @param array $args * @return mixed */ public function __call($name, array $args) { $this->setTitle(t('Contact')); $this->setOutputType(self::_OT_COLLECTIVE); // Get the correct form identifier to display try { $contact = $this->_model()->getForm(substr($name, 0, -7), false); } catch (Contact_NoExist $e) { throw new Module_ControllerNoExist(); } if (!$this->_acl->check('contact-form-' . $contact['id'])) { throw new Module_NoPermission(); } $this->setTitle($contact['name']); /** * Prepare form validation, if needed */ $fields = $this->_model()->getFormFields($contact['id']); if ($fields) { $form = new View_form('contact.html', 'contact'); $form->caseSensitive()->antispam(true); $form->addElement('contact/email', $this->_session->getUser('email'), t('Email address'), new Validator_Email()); foreach ($fields as &$tmpField) { $tmpField['options'] = zula_split_config($tmpField['options']); // Use correct validation for the given types. switch ($tmpField['type']) { case 'textbox': case 'password': $validator = new Validator_Length(1, 300); break; case 'textarea': $validator = new Validator_Length(1, 3000); break; case 'radio': case 'select': case 'checkbox': $validator = new Validator_InArray(array_values($tmpField['options'])); break; default: $validator = null; } $form->addElement('contact/fields/' . $tmpField['id'], null, $tmpField['name'], $validator, (bool) $tmpField['required']); } if ($form->hasInput() && $form->isValid()) { /** * Send out the contact form email */ $mailBody = $this->loadView('email_body.txt'); $mailBody->assign(array('form' => $contact, 'fields' => $fields, 'email' => $form->getValues('contact/email'))); $mailBody->assignHtml(array('contact' => $form->getValues('contact'))); try { $message = new Email_message(sprintf(t('Contact form "%s"'), $contact['name']), $mailBody->getOutput(), 'text/plain'); $message->setTo($contact['email']); $message->setReplyTo($form->getValues('contact/email')); $email = new Email(); $email->send($message); $this->_event->success(t('Contact form sent successfully')); } catch (Email_Exception $e) { $this->_event->error(t('Sorry, there was a technical error while sending the contact form')); $this->_log->message($e->getMessage(), Log::L_WARNING); } return zula_redirect($this->_router->getParsedUrl()); } } else { $form = $this->loadView('contact.html'); } // Parse the body $editor = new Editor($contact['body']); unset($contact['body']); $form->assignHtml(array('body' => $editor->parse())); $form->assign(array('details' => $contact, 'fields' => $fields)); return $form->getOutput(); }
/** * 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; }
/** * Edit a media item (only Name/Title and Description) * * @return string */ public function editSection() { $this->setTitle(t('Edit media ttem')); // Get details for the media item to edit try { $itemId = $this->_router->getArgument('id'); $item = $this->_model()->getItem($itemId); // Get parent category permission $resource = 'media-cat_moderate_' . $item['cat_id']; if (!$this->_acl->resourceExists($resource) || !$this->_acl->check($resource)) { throw new Module_NoPermission(); } // Prepare form validation $form = new View_form('manage/edit.html', 'media', false); $form->addElement('media/id', $item['id'], 'id', new Validator_Int()); $form->addElement('media/title', $item['name'], t('Title'), new Validator_Length(1, 255)); $form->addElement('media/desc', $item['description'], t('Description'), new Validator_Length(0, 1000)); if ($form->hasInput() && $form->isValid()) { $fd = $form->getValues('media'); $this->_model()->editItem($item['id'], $fd['title'], $fd['desc']); $this->_event->success(t('Edited media item')); return zula_redirect($this->_router->makeUrl('media', 'view', $item['identifier'])); } return $form->getOutput(); } catch (Router_ArgNoExist $e) { $this->_event->error(t('No media item selected')); } catch (Media_ItemNoExist $e) { $this->_event->error(t('Media item does not exist')); } return zula_redirect($this->_router->makeUrl('media')); }
/** * Builds the form for adding or editing a poll option * * @param string $title * @param int $optionId * @return object */ protected function buildOptionForm($title = null, $optionId = null) { $op = is_null($optionId) ? 'add' : 'edit'; $form = new View_form('config/form_option.html', 'poll', $op == 'add'); $form->addElement('poll/title', $title, t('Title'), new Validator_Length(1, 255)); $form->assign(array('ID' => $optionId, 'OP' => $op)); return $form; }
/** * 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; }
/** * 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(); }
/** * Updates settings for the media module * * @return string */ public function settingsSection() { $this->setTitle(t('Media Settings')); $this->setOutputType(self::_OT_CONFIG); if (!$this->_acl->check('media_manage_settings')) { throw new Module_NoPermission(); } // Prepare the form of settings $mediaConf = $this->_config->get('media'); $form = new View_form('config/settings.html', 'media'); $form->addElement('media/per_page', $mediaConf['per_page'], t('Per page'), new Validator_Int())->addElement('media/use_lightbox', $mediaConf['use_lightbox'], t('Use lightbox'), new Validator_Bool())->addElement('media/max_fs', $mediaConf['max_fs'], t('Maximum file size'), new Validator_Int())->addElement('media/thumb_dimension', $mediaConf['thumb_dimension'], t('Thumbnail width/height'), new Validator_Between(20, 200))->addElement('media/max_image_width', $mediaConf['max_image_width'], t('Maximum image width'), new Validator_Between(200, 90000))->addElement('media/wm_position', $mediaConf['wm_position'], t('Watermark position'), new Validator_InArray(array('t', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl')), false); if ($form->hasInput() && $form->isValid()) { $purgeTmpImages = false; foreach ($form->getValues('media') as $key => $val) { if ($key == 'max_image_width' && $mediaConf['max_image_width'] != $val || $key == 'wm_position' && $mediaConf['wm_position'] != $val) { $purgeTmpImages = true; } else { if ($key == 'max_fs') { $val = zula_byte_value($val . $this->_input->post('media/max_fs_unit')); } } $this->_config_sql->update('media/' . $key, $val); } // Upload the watermark if ($this->_input->has('post', 'media_wm_delete')) { unlink($this->_zula->getDir('uploads') . '/media/wm.png'); unlink($this->_zula->getDir('uploads') . '/media/wm_thumb.png'); $purgeTmpImages = true; } try { $uploader = new Uploader('media_wm', $this->_zula->getDir('uploads') . '/media'); $uploader->subDirectories(false)->allowImages(); $file = $uploader->getFile(); if ($file->upload() !== false) { $image = new Image($file->path); $image->mime = 'image/png'; $image->save($file->dirname . '/wm.png', false); $image->thumbnail(80, 80)->save($file->dirname . '/wm_thumb.png'); $purgeTmpImages = true; } } catch (Uploader_NotEnabled $e) { $this->_event->error(t('Sorry, it appears file uploads are disabled within your PHP configuration')); } catch (Uploader_MaxFileSize $e) { $msg = sprintf(t('Selected file exceeds the maximum allowed file size of %s'), zula_human_readable($e->getMessage())); $this->_event->error($msg); } catch (Uploader_InvalidMime $e) { $this->_event->error(t('Sorry, the uploaded file is of the wrong file type')); } catch (Uploader_Exception $e) { $this->_log->message($e->getMessage(), Log::L_WARNING); $this->_event->error(t('Oops, an error occurred while uploading your files')); } catch (Image_Exception $e) { $this->_log->message($e->getMessage(), Log::L_WARNING); $this->_event->error(t('Oops, an error occurred while processing an image')); } // Purge tmp images if needed and redirect if ($purgeTmpImages) { $files = (array) glob($this->_zula->getDir('tmp') . '/media/max*-*'); foreach (array_filter($files) as $tmpFile) { unlink($tmpFile); } } $this->_event->success(t('Updated media settings')); return zula_redirect($this->_router->makeUrl('media', 'config', 'settings')); } if (is_file($this->_zula->getDir('uploads') . '/media/wm_thumb.png')) { $wmThumbPath = $this->_zula->getDir('uploads', true) . '/media/wm_thumb.png'; } else { $wmThumbPath = null; } $form->assign(array('WM_THUMB_PATH' => $wmThumbPath)); return $form->getOutput(); }