/** * Load the form */ private function loadForm() { $this->frm = new BackendForm('settingsSeo'); $this->frm->addCheckbox('seo_noodp', BackendModel::getModuleSetting('core', 'seo_noodp', false)); $this->frm->addCheckbox('seo_noydir', BackendModel::getModuleSetting('core', 'seo_noydir', false)); $this->frm->addCheckbox('seo_nofollow_in_comments', BackendModel::getModuleSetting('core', 'seo_nofollow_in_comments', false)); }
/** * Load the form */ private function loadForm() { // create form $this->frm = new BackendForm('add'); // get the groups $groups = BackendGroupsModel::getAll(); // if there is only one group we can check it so the user isn't bothered with an error for not selecting one $checkedGroups = count($groups) == 1 ? $groups[0]['value'] : null; // create elements // profile $this->frm->addText('email', null, 255); $this->frm->addPassword('password', null, 75, 'inputText inputPassword passwordGenerator', 'inputTextError inputPasswordError passwordGenerator')->setAttributes(array('autocomplete' => 'off')); $this->frm->addPassword('confirm_password', null, 75)->setAttributes(array('autocomplete' => 'off')); $this->frm->addText('name', null, 255); $this->frm->addText('surname', null, 255); $this->frm->addText('nickname', null, 24); $this->frm->addImage('avatar'); $this->frm->addDropdown('interface_language', BackendLanguage::getInterfaceLanguages(), BackendModel::getModuleSetting('core', 'default_interface_language')); $this->frm->addDropdown('date_format', BackendUsersModel::getDateFormats(), BackendAuthentication::getUser()->getSetting('date_format')); $this->frm->addDropdown('time_format', BackendUsersModel::getTimeFormats(), BackendAuthentication::getUser()->getSetting('time_format')); $this->frm->addDropdown('number_format', BackendUsersModel::getNumberFormats(), BackendAuthentication::getUser()->getSetting('number_format', 'dot_nothing')); $this->frm->addDropDown('csv_split_character', BackendUsersModel::getCSVSplitCharacters()); $this->frm->addDropDown('csv_line_ending', BackendUsersModel::getCSVLineEndings()); // permissons $this->frm->addCheckbox('active', true); $this->frm->addCheckbox('api_access', false); $this->frm->addMultiCheckbox('groups', $groups, $checkedGroups); }
/** * Load the form * * @return void */ private function loadForm() { // create form $this->frm = new BackendForm('add'); // fetch the campaigns $campaigns = BackendMailmotorModel::getCampaignsAsPairs(); // fetch the groups $groupIds = BackendMailmotorModel::getGroupIDs(); $groups = BackendMailmotorModel::getGroupsWithRecipientsForCheckboxes(); // no groups were made yet if (empty($groups) && empty($groupIds)) { $this->redirect(BackendModel::createURLForAction('add_group') . '&error=add-mailing-no-groups'); } elseif (empty($groups)) { $this->redirect(BackendModel::createURLForAction('addresses') . '&error=no-subscribers'); } // fetch the languages $languages = BackendMailmotorModel::getLanguagesForCheckboxes(); // settings $this->frm->addText('name'); if (count($campaigns) > 1) { $this->frm->addDropdown('campaign', $campaigns); } // sender $this->frm->addText('from_name', BackendModel::getModuleSetting($this->getModule(), 'from_name')); $this->frm->addText('from_email', BackendModel::getModuleSetting($this->getModule(), 'from_email')); // reply-to address $this->frm->addText('reply_to_email', BackendModel::getModuleSetting($this->getModule(), 'reply_to_email')); // groups - if there is only 1 group present, we select it by default $this->frm->addMultiCheckbox('groups', $groups, count($groups) == 1 && isset($groups[0]) ? $groups[0]['value'] : false); // languages $this->frm->addRadiobutton('languages', $languages, BL::getWorkingLanguage()); }
/** * Loads the settings form * * @return void */ private function loadForm() { // init settings form $this->frm = new BackendForm('settings'); // add fields for meta navigation $this->frm->addCheckbox('meta_navigation', BackendModel::getModuleSetting($this->getModule(), 'meta_navigation', false)); }
/** * Loads the settings form */ private function loadForm() { // init settings form $this->frm = new BackendForm('settings'); // get current settings $this->settings = BackendSearchModel::getModuleSettings(); // add field for pagination $this->frm->addDropdown('overview_num_items', array_combine(range(1, 30), range(1, 30)), BackendModel::getModuleSetting($this->URL->getModule(), 'overview_num_items', 20)); $this->frm->addDropdown('autocomplete_num_items', array_combine(range(1, 30), range(1, 30)), BackendModel::getModuleSetting($this->URL->getModule(), 'autocomplete_num_items', 20)); $this->frm->addDropdown('autosuggest_num_items', array_combine(range(1, 30), range(1, 30)), BackendModel::getModuleSetting($this->URL->getModule(), 'autosuggest_num_items', 20)); // modules that, no matter what, can not be searched $disallowedModules = array('search'); // loop modules foreach (BackendModel::getModulesForDropDown() as $module => $label) { // check if module is searchable if (!in_array($module, $disallowedModules) && is_callable(array('Frontend' . SpoonFilter::toCamelCase($module) . 'Model', 'search'))) { // add field to decide wether or not this module is searchable $this->frm->addCheckbox('search_' . $module, isset($this->settings[$module]) ? $this->settings[$module]['searchable'] == 'Y' : false); // add field to decide weight for this module $this->frm->addText('search_' . $module . '_weight', isset($this->settings[$module]) ? $this->settings[$module]['weight'] : 1); // field disabled? if (!isset($this->settings[$module]) || $this->settings[$module]['searchable'] != 'Y') { $this->frm->getField('search_' . $module . '_weight')->setAttribute('disabled', 'disabled'); $this->frm->getField('search_' . $module . '_weight')->setAttribute('class', 'inputText disabled'); } // add to list of modules $this->modules[] = array('module' => $module, 'id' => $this->frm->getField('search_' . $module)->getAttribute('id'), 'label' => $label, 'chk' => $this->frm->getField('search_' . $module)->parse(), 'txt' => $this->frm->getField('search_' . $module . '_weight')->parse(), 'txtError' => ''); } } }
/** * Execute the action */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // init vars $templates = array(); $theme = BackendModel::getModuleSetting('core', 'theme'); $files[] = BACKEND_PATH . '/core/layout/editor_templates/templates.js'; $themePath = FRONTEND_PATH . '/themes/' . $theme . '/core/layout/editor_templates/templates.js'; if (SpoonFile::exists($themePath)) { $files[] = $themePath; } // loop all files foreach ($files as $file) { // process file $templates = array_merge($templates, $this->processFile($file)); } // set headers SpoonHTTP::setHeaders('Content-type: text/javascript'); // output the templates if (!empty($templates)) { echo 'CKEDITOR.addTemplates(\'default\', { imagesPath: \'/\', templates:' . "\n"; echo json_encode($templates) . "\n"; echo '});'; } exit; }
/** * Load the form */ private function loadForm() { $this->isGod = BackendAuthentication::getUser()->isGod(); $this->frm = new BackendForm('settingsEmail'); // email settings $mailerFrom = BackendModel::getModuleSetting('core', 'mailer_from'); $this->frm->addText('mailer_from_name', isset($mailerFrom['name']) ? $mailerFrom['name'] : ''); $this->frm->addText('mailer_from_email', isset($mailerFrom['email']) ? $mailerFrom['email'] : ''); $mailerTo = BackendModel::getModuleSetting('core', 'mailer_to'); $this->frm->addText('mailer_to_name', isset($mailerTo['name']) ? $mailerTo['name'] : ''); $this->frm->addText('mailer_to_email', isset($mailerTo['email']) ? $mailerTo['email'] : ''); $mailerReplyTo = BackendModel::getModuleSetting('core', 'mailer_reply_to'); $this->frm->addText('mailer_reply_to_name', isset($mailerReplyTo['name']) ? $mailerReplyTo['name'] : ''); $this->frm->addText('mailer_reply_to_email', isset($mailerReplyTo['email']) ? $mailerReplyTo['email'] : ''); if ($this->isGod) { $mailerType = BackendModel::getModuleSetting('core', 'mailer_type', 'mail'); $this->frm->addDropdown('mailer_type', array('mail' => 'PHP\'s mail', 'smtp' => 'SMTP'), $mailerType); // smtp settings $this->frm->addText('smtp_server', BackendModel::getModuleSetting('core', 'smtp_server', '')); $this->frm->addText('smtp_port', BackendModel::getModuleSetting('core', 'smtp_port', 25)); $this->frm->addText('smtp_username', BackendModel::getModuleSetting('core', 'smtp_username', '')); $this->frm->addPassword('smtp_password', BackendModel::getModuleSetting('core', 'smtp_password', '')); } $this->tpl->assign('isGod', $this->isGod); }
/** * Validates the settings form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); if ($this->frm->isCorrect()) { // set the base values $width = (int) $this->frm->getField('width_widget')->getValue(); $height = (int) $this->frm->getField('height_widget')->getValue(); if ($width > 800) { $width = 800; } elseif ($width < 300) { $width = BackendModel::getModuleSetting('location', 'width_widget'); } if ($height < 150) { $height = BackendModel::getModuleSetting('location', 'height_widget'); } // set our settings (widgets) BackendModel::setModuleSetting($this->URL->getModule(), 'zoom_level_widget', (string) $this->frm->getField('zoom_level_widget')->getValue()); BackendModel::setModuleSetting($this->URL->getModule(), 'width_widget', $width); BackendModel::setModuleSetting($this->URL->getModule(), 'height_widget', $height); BackendModel::setModuleSetting($this->URL->getModule(), 'map_type_widget', (string) $this->frm->getField('map_type_widget')->getValue()); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_saved_settings'); // redirect to the settings page $this->redirect(BackendModel::createURLForAction('settings') . '&report=saved'); } } }
/** * Execute the widget * * @return void */ public function execute() { // analytics session token and analytics table id if (BackendModel::getModuleSetting('analytics', 'session_token', null) == '') { return; } if (BackendModel::getModuleSetting('analytics', 'table_id', null) == '') { return; } // settings are ok, set option $this->tpl->assign('analyticsValidSettings', true); // set column $this->setColumn('right'); // set position $this->setPosition(0); // add css $this->header->addCSS('widgets.css', 'analytics'); // add highchart javascript $this->header->addJS('highcharts.js', 'analytics'); $this->header->addJS('analytics.js', 'analytics'); // parse $this->parse(); // display $this->display(); }
/** * Checks if default groups were set, and shows a message with more info if they are not. */ private function checkForDefaultGroups() { // groups are already set if (BackendModel::getModuleSetting($this->getModule(), 'cm_groups_defaults_set')) { return true; } // show the message $this->tpl->assign('noDefaultsSet', true); }
/** * Load the record * * @return void */ private function loadData() { // get data $this->selectedTheme = $this->getParameter('theme', 'string'); // build available themes $this->availableThemes = BackendModel::getThemes(); // determine selected theme, based upon submitted form or default theme $this->selectedTheme = SpoonFilter::getValue($this->selectedTheme, array_keys($this->availableThemes), BackendModel::getModuleSetting('core', 'theme', 'core')); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // init vars $this->cachePath = BACKEND_CACHE_PATH . '/analytics'; // get parameters $page = trim(SpoonFilter::getGetValue('page', null, '')); $pageId = trim(SpoonFilter::getGetValue('page_id', null, '')); $identifier = trim(SpoonFilter::getGetValue('identifier', null, '')); $startTimestamp = (int) trim(SpoonFilter::getGetValue('start_date', null, '')); $endTimestamp = (int) trim(SpoonFilter::getGetValue('end_date', null, '')); $force = trim(SpoonFilter::getGetValue('force', array('Y', 'N'), 'N')) == 'Y'; $filename = null; // no parameters given? cronjob called if ($page == '' && $identifier == '' && $startTimestamp === 0 && $endTimestamp === 0) { // is everything still set? if (BackendAnalyticsHelper::getStatus() != 'UNAUTHORIZED') { // get interval $interval = BackendModel::getModuleSetting('analytics', 'interval', 'week'); if ($interval == 'week') { $interval .= ' -2 days'; } // redefine vars $page = 'all'; $startTimestamp = strtotime('-1' . $interval); $endTimestamp = time(); } } elseif ($page != '' && $identifier != '' && $startTimestamp !== 0 && $endTimestamp !== 0) { // init vars $filename = $this->cachePath . '/' . $page . ($pageId != '' ? '_' . $pageId : '') . '_' . $identifier . '.txt'; // is everything still set? if (BackendAnalyticsHelper::getStatus() != 'UNAUTHORIZED') { // create temporary file to indicate we're getting data SpoonFile::setContent($filename, 'busy1'); } else { // set status in cache SpoonFile::setContent($filename, 'unauthorized'); // stop here return; } } else { throw new SpoonException('Some parameters are missing.'); } // get dashboard data $this->getDashboardData(); // get data $this->getData($startTimestamp, $endTimestamp, $force, $page, $pageId, $filename); // cleanup cache $this->cleanupCache(); // cleanup database $this->cleanupDatabase(); }
/** * Generates and downloads the example CSV file * * @return void */ private function downloadExampleFile() { // Should we download the example file or not? $downloadExample = SpoonFilter::getGetValue('example', array(0, 1), 0, 'bool'); // stop here if no download parameter was given if (!$downloadExample) { return false; } // build the csv $csv = array(); $csv[] = array('email' => BackendModel::getModuleSetting($this->getModule(), 'from_email')); // download the file SpoonFileCSV::arrayToFile(BACKEND_CACHE_PATH . '/mailmotor/example.csv', $csv, null, null, ';', '"', true); }
/** * Loads the settings form */ private function loadForm() { $this->frm = new BackendForm('settings'); // add map info (overview map) $this->frm->addDropdown('zoom_level', array_combine(array_merge(array('auto'), range(3, 18)), array_merge(array(BL::lbl('Auto', $this->getModule())), range(3, 18))), BackendModel::getModuleSetting($this->URL->getModule(), 'zoom_level', 'auto')); $this->frm->addText('width', BackendModel::getModuleSetting($this->URL->getModule(), 'width')); $this->frm->addText('height', BackendModel::getModuleSetting($this->URL->getModule(), 'height')); $this->frm->addDropdown('map_type', array('ROADMAP' => BL::lbl('Roadmap', $this->getModule()), 'SATELLITE' => BL::lbl('Satellite', $this->getModule()), 'HYBRID' => BL::lbl('Hybrid', $this->getModule()), 'TERRAIN' => BL::lbl('Terrain', $this->getModule())), BackendModel::getModuleSetting($this->URL->getModule(), 'map_type', 'roadmap')); // add map info (widgets) $this->frm->addDropdown('zoom_level_widget', array_combine(array_merge(array('auto'), range(3, 18)), array_merge(array(BL::lbl('Auto', $this->getModule())), range(3, 18))), BackendModel::getModuleSetting($this->URL->getModule(), 'zoom_level_widget', 13)); $this->frm->addText('width_widget', BackendModel::getModuleSetting($this->URL->getModule(), 'width_widget')); $this->frm->addText('height_widget', BackendModel::getModuleSetting($this->URL->getModule(), 'height_widget')); $this->frm->addDropdown('map_type_widget', array('ROADMAP' => BL::lbl('Roadmap', $this->getModule()), 'SATELLITE' => BL::lbl('Satellite', $this->getModule()), 'HYBRID' => BL::lbl('Hybrid', $this->getModule()), 'TERRAIN' => BL::lbl('Terrain', $this->getModule())), BackendModel::getModuleSetting($this->URL->getModule(), 'map_type_widget', 'roadmap')); }
/** * Checks the settings and optionally returns an array with warnings * * @return array */ public static function checkSettings() { $warnings = array(); // check if this action is allowed if (BackendAuthentication::isAllowedAction('settings', 'mailmotor')) { // analytics session token if (BackendModel::getModuleSetting('mailmotor', 'cm_account') == false) { $warnings[] = array('message' => sprintf(BL::err('AnalysisNoCMAccount', 'mailmotor'), BackendModel::createURLForAction('settings', 'mailmotor'))); } elseif (BackendModel::getModuleSetting('mailmotor', 'cm_client_id') == '') { // add warning $warnings[] = array('message' => sprintf(BL::err('AnalysisNoCMClientID', 'mailmotor'), BackendModel::createURLForAction('settings', 'mailmtor'))); } } return $warnings; }
public function __construct() { // because some cronjobs will be run on the command line we should pass parameters if (isset($_SERVER['argv'])) { // init var $first = true; // loop all passes arguments foreach ($_SERVER['argv'] as $parameter) { // ignore first, because this is the scripts name. if ($first) { // reset $first = false; // skip continue; } // split into chunks $chunks = explode('=', $parameter, 2); // valid paramters? if (count($chunks) == 2) { // build key and value $key = trim($chunks[0], '--'); $value = $chunks[1]; // set in GET if ($key != '' && $value != '') { $_GET[$key] = $value; } } } } // define the Named Application if (!defined('NAMED_APPLICATION')) { define('NAMED_APPLICATION', 'backend'); } // set the module $this->setModule(SpoonFilter::getGetValue('module', null, '')); // set the requested file $this->setAction(SpoonFilter::getGetValue('action', null, '')); // set the language $this->setLanguage(SpoonFilter::getGetValue('language', FrontendLanguage::getActiveLanguages(), SITE_DEFAULT_LANGUAGE)); // mark cronjob as run $cronjobs = (array) BackendModel::getModuleSetting('core', 'cronjobs'); $cronjobs[] = $this->getModule() . '.' . $this->getAction(); BackendModel::setModuleSetting('core', 'cronjobs', array_unique($cronjobs)); // create new action $action = new BackendCronjobAction($this->getAction(), $this->getModule()); $action->execute(); }
/** * Checks the settings and optionally returns an array with warnings * * @return array */ public static function checkSettings() { // init var $warnings = array(); // analytics session token if (BackendModel::getModuleSetting('analytics', 'session_token', null) == '') { // add warning $warnings[] = array('message' => sprintf(BL::err('AnalyseNoSessionToken', 'analytics'), BackendModel::createURLForAction('settings', 'analytics'))); } // analytics table id (only show this error if no other exist) if (empty($warnings) && BackendModel::getModuleSetting('analytics', 'table_id', null) == '') { // add warning $warnings[] = array('message' => sprintf(BL::err('AnalyseNoTableId', 'analytics'), BackendModel::createURLForAction('settings', 'analytics'))); } // return return $warnings; }
/** * Fetch the list of modules that require Google Maps API key * * @return array */ public static function getModulesThatRequireGoogleMaps() { // init vars $modules = array(); $activeModules = BackendModel::getModules(true); // loop active modules foreach ($activeModules as $module) { // fetch setting $setting = BackendModel::getModuleSetting($module, 'requires_google_maps', false); // add to the list if ($setting) { $modules[] = $module; } } // return return $modules; }
/** * Execute the widget */ public function execute() { // check analytics session token and analytics table id if (BackendModel::getModuleSetting('analytics', 'session_token', null) == '') { return; } if (BackendModel::getModuleSetting('analytics', 'table_id', null) == '') { return; } // settings are ok, set option $this->tpl->assign('analyticsValidSettings', true); $this->setColumn('left'); $this->setPosition(0); $this->header->addJS('dashboard.js', 'analytics'); $this->parse(); $this->getData(); $this->display(); }
/** * Check if all required settings have been set * * @param string $module The module. */ public function __construct($module) { parent::__construct($module); $error = false; $action = Spoon::exists('url') ? Spoon::get('url')->getAction() : null; // analytics session token if (BackendModel::getModuleSetting('analytics', 'session_token') === null) { $error = true; } // analytics table id if (BackendModel::getModuleSetting('analytics', 'table_id') === null) { $error = true; } // missing settings, so redirect to the index-page to show a message (except on the index- and settings-page) if ($error && $action != 'settings' && $action != 'index') { SpoonHTTP::redirect(BackendModel::createURLForAction('index')); } }
/** * Validates the settings form */ private function validateForm() { if ($this->frm->isSubmitted()) { if ($this->frm->isCorrect()) { // set our settings BackendModel::setModuleSetting($this->URL->getModule(), 'overview_num_items_per_category', (int) $this->frm->getField('overview_number_of_items_per_category')->getValue()); BackendModel::setModuleSetting($this->URL->getModule(), 'most_read_num_items', (int) $this->frm->getField('most_read_number_of_items')->getValue()); BackendModel::setModuleSetting($this->URL->getModule(), 'related_num_items', (int) $this->frm->getField('related_number_of_items')->getValue()); BackendModel::setModuleSetting($this->URL->getModule(), 'spamfilter', (bool) $this->frm->getField('spamfilter')->getValue()); BackendModel::setModuleSetting($this->URL->getModule(), 'allow_feedback', (bool) $this->frm->getField('allow_feedback')->getValue()); BackendModel::setModuleSetting($this->URL->getModule(), 'allow_own_question', (bool) $this->frm->getField('allow_own_question')->getValue()); BackendModel::setModuleSetting($this->URL->getModule(), 'send_email_on_new_feedback', (bool) $this->frm->getField('send_email_on_new_feedback')->getValue()); if (BackendModel::getModuleSetting('core', 'akismet_key') === null) { BackendModel::setModuleSetting($this->URL->getModule(), 'spamfilter', false); } // redirect to the settings page $this->redirect(BackendModel::createURLForAction('settings') . '&report=saved'); } } }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // required fields $this->frm->getField('file')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('label')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('format')->isFilled(BL::err('FieldIsRequired')); // validate syntax $syntax = trim(str_replace(array("\n", "\r", ' '), '', $this->frm->getField('format')->getValue())); // init var $table = BackendExtensionsModel::templateSyntaxToArray($syntax); // validate the syntax if ($table === false) { $this->frm->getField('format')->addError(BL::err('InvalidTemplateSyntax')); } else { $html = BackendExtensionsModel::buildTemplateHTML($syntax); $cellCount = 0; $first = true; $errors = array(); // loop rows foreach ($table as $row) { // first row defines the cellcount if ($first) { $cellCount = count($row); } // not same number of cells if (count($row) != $cellCount) { // add error $errors[] = BL::err('InvalidTemplateSyntax'); // stop break; } // doublecheck position names foreach ($row as $cell) { // ignore unavailable space if ($cell != '/') { // not alphanumeric -> error if (!in_array($cell, $this->names)) { $errors[] = sprintf(BL::getError('NonExistingPositionName'), $cell); } elseif (substr_count($html, '"#position-' . $cell . '"') != 1) { $errors[] = BL::err('InvalidTemplateSyntax'); } } } // reset $first = false; } // add errors if ($errors) { $this->frm->getField('format')->addError(implode('<br />', array_unique($errors))); } } // no errors? if ($this->frm->isCorrect()) { // build array $item['id'] = $this->id; $item['theme'] = $this->frm->getField('theme')->getValue(); $item['label'] = $this->frm->getField('label')->getValue(); $item['path'] = 'core/layout/templates/' . $this->frm->getField('file')->getValue(); $item['active'] = $this->frm->getField('active')->getChecked() ? 'Y' : 'N'; $item['data']['format'] = trim(str_replace(array("\n", "\r", ' '), '', $this->frm->getField('format')->getValue())); $item['data']['names'] = $this->names; $item['data']['default_extras'] = $this->extras; $item['data']['default_extras_' . BackendLanguage::getWorkingLanguage()] = $this->extras; // serialize $item['data'] = serialize($item['data']); // if this is the default template make the template active if (BackendModel::getModuleSetting('pages', 'default_template') == $this->record['id']) { $item['active'] = 'Y'; } // if the template is in use we can't de-activate it if (BackendExtensionsModel::isTemplateInUse($item['id'])) { $item['active'] = 'Y'; } // insert the item BackendExtensionsModel::updateTemplate($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit_template', array('item' => $item)); // set default template if ($this->frm->getField('default')->getChecked() && $item['theme'] == BackendModel::getModuleSetting('core', 'theme', 'core')) { BackendModel::setModuleSetting('pages', 'default_template', $item['id']); } // update all existing pages using this template to add the newly inserted block(s) if (BackendExtensionsModel::isTemplateInUse($item['id'])) { BackendPagesModel::updatePagesTemplates($item['id'], $item['id'], $this->frm->getField('overwrite')->getChecked()); } // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('theme_templates') . '&theme=' . $item['theme'] . '&report=edited-template&var=' . urlencode($item['label']) . '&highlight=row-' . $item['id']); } } }
/** * Update an existing item. * * @param array $item The new data. * @return int */ public static function update(array $item) { $db = BackendModel::getDB(true); // build extra $extra = array('id' => $item['extra_id'], 'module' => 'content_blocks', 'type' => 'widget', 'label' => 'ContentBlocks', 'action' => 'detail', 'data' => serialize(array('id' => $item['id'], 'extra_label' => $item['title'], 'language' => $item['language'], 'edit_url' => BackendModel::createURLForAction('edit') . '&id=' . $item['id'])), 'hidden' => 'N'); // update extra $db->update('modules_extras', $extra, 'id = ? AND module = ? AND type = ? AND action = ?', array($extra['id'], $extra['module'], $extra['type'], $extra['action'])); // archive all older versions $db->update('content_blocks', array('status' => 'archived'), 'id = ? AND language = ?', array($item['id'], BL::getWorkingLanguage())); // insert new version $item['revision_id'] = $db->insert('content_blocks', $item); // how many revisions should we keep $rowsToKeep = (int) BackendModel::getModuleSetting('content_blocks', 'max_num_revisions', 20); // get revision-ids for items to keep $revisionIdsToKeep = (array) $db->getColumn('SELECT i.revision_id FROM content_blocks AS i WHERE i.id = ? AND i.language = ? AND i.status = ? ORDER BY i.edited_on DESC LIMIT ?', array($item['id'], BL::getWorkingLanguage(), 'archived', $rowsToKeep)); // delete other revisions if (!empty($revisionIdsToKeep)) { $db->delete('content_blocks', 'id = ? AND language = ? AND status = ? AND revision_id NOT IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id'], BL::getWorkingLanguage(), 'archived')); } // return the new revision_id return $item['revision_id']; }
/** * Update an existing item * * @return int * @param array $item The new data. */ public static function update(array $item) { // check if new version is active if ($item['status'] == 'active') { // archive all older active versions BackendModel::getDB(true)->update('blog_posts', array('status' => 'archived'), 'id = ? AND status = ?', array($item['id'], $item['status'])); // get the record of the exact item we're editing $revision = self::getRevision($item['id'], $item['revision_id']); // assign values $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s', $revision['created_on']); $item['num_comments'] = $revision['num_comments']; // if it used to be a draft that we're now publishing, remove drafts if ($revision['status'] == 'draft') { BackendModel::getDB(true)->delete('blog_posts', 'id = ? AND status = ?', array($item['id'], $revision['status'])); } } // don't want revision id unset($item['revision_id']); // how many revisions should we keep $rowsToKeep = (int) BackendModel::getModuleSetting('blog', 'max_num_revisions', 20); // set type of archive $archiveType = $item['status'] == 'active' ? 'archived' : $item['status']; // get revision-ids for items to keep $revisionIdsToKeep = (array) BackendModel::getDB()->getColumn('SELECT i.revision_id FROM blog_posts AS i WHERE i.id = ? AND i.status = ? AND i.language = ? ORDER BY i.edited_on DESC LIMIT ?', array($item['id'], $archiveType, BL::getWorkingLanguage(), $rowsToKeep)); // delete other revisions if (!empty($revisionIdsToKeep)) { BackendModel::getDB(true)->delete('blog_posts', 'id = ? AND status = ? AND revision_id NOT IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id'], $archiveType)); } // insert new version $item['revision_id'] = BackendModel::getDB(true)->insert('blog_posts', $item); // invalidate the cache for blog BackendModel::invalidateFrontendCache('blog', BL::getWorkingLanguage()); // return the new revision id return $item['revision_id']; }
/** * Validates the form * * @return void */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // no errors? if ($this->frm->isCorrect()) { // determine themes $newTheme = $this->frm->getField('theme')->getValue(); $oldTheme = BackendModel::getModuleSetting('core', 'theme', 'core'); // check if we actually switched themes if ($newTheme != $oldTheme) { // fetch templates $oldTemplates = BackendPagesModel::getTemplates($oldTheme); $newTemplates = BackendPagesModel::getTemplates($newTheme); // check if templates already exist if (empty($newTemplates)) { // templates do not yet exist; don't switch $this->redirect(BackendModel::createURLForAction('themes') . '&error=no-templates-available'); exit; } // fetch current default template $oldDefaultTemplatePath = $oldTemplates[BackendModel::getModuleSetting('pages', 'default_template')]['path']; // loop new templates foreach ($newTemplates as $newTemplateId => $newTemplate) { // check if a a similar default template exists if ($newTemplate['path'] == $oldDefaultTemplatePath) { // set new default id $newDefaultTemplateId = (int) $newTemplateId; break; } } // no default template was found, set first template as default if (!isset($newDefaultTemplateId)) { $newDefaultTemplateId = array_keys($newTemplates); $newDefaultTemplateId = $newDefaultTemplateId[0]; } // update theme BackendModel::setModuleSetting('core', 'theme', $newTheme); // set amount of blocks BackendPagesModel::setMaximumBlocks(); // save new default template BackendModel::setModuleSetting('pages', 'default_template', $newDefaultTemplateId); // loop old templates foreach ($oldTemplates as $oldTemplateId => $oldTemplate) { // loop new templates foreach ($newTemplates as $newTemplateId => $newTemplate) { // check if we have a matching template if ($oldTemplate['path'] == $newTemplate['path']) { // switch template BackendPagesModel::updatePagesTemplates($oldTemplateId, $newTemplateId); // break loop continue 2; } } // getting here meant we found no matching template for the new theme; pick first theme's template as default BackendPagesModel::updatePagesTemplates($oldTemplateId, $newDefaultTemplateId); } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_changed_theme'); } // assign report $this->tpl->assign('report', true); $this->tpl->assign('reportMessage', BL::msg('Saved')); } } }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // current status $from = SpoonFilter::getGetValue('from', array('published', 'moderation', 'spam'), 'published'); // action to execute $action = SpoonFilter::getGetValue('action', array('published', 'moderation', 'spam', 'delete'), 'spam'); // no id's provided if (!isset($_GET['id'])) { $this->redirect(BackendModel::createURLForAction('comments') . '&error=no-comments-selected'); } else { // redefine id's $ids = (array) $_GET['id']; // delete comment(s) if ($action == 'delete') { BackendBlogModel::deleteComments($ids); } elseif ($action == 'spam') { // is the spamfilter active? if (BackendModel::getModuleSetting($this->URL->getModule(), 'spamfilter', false)) { // get data $comments = BackendBlogModel::getComments($ids); // loop comments foreach ($comments as $row) { // unserialize data $row['data'] = unserialize($row['data']); // check if needed data is available if (!isset($row['data']['server']['REMOTE_ADDR'])) { continue; } if (!isset($row['data']['server']['HTTP_USER_AGENT'])) { continue; } // build vars $userIp = $row['data']['server']['REMOTE_ADDR']; $userAgent = $row['data']['server']['HTTP_USER_AGENT']; $content = $row['text']; $author = $row['author']; $email = $row['email']; $url = isset($row['website']) && $row['website'] != '' ? $row['website'] : null; $referrer = isset($row['data']['server']['HTTP_REFERER']) ? $row['data']['server']['HTTP_REFERER'] : null; $others = $row['data']['server']; // submit as spam BackendModel::submitSpam($userIp, $userAgent, $content, $author, $email, $url, null, 'comment', $referrer, $others); } } // set new status BackendBlogModel::updateCommentStatuses($ids, $action); } else { // published? if ($action == 'published') { // is the spamfilter active? if (BackendModel::getModuleSetting($this->URL->getModule(), 'spamfilter', false)) { // get data $comments = BackendBlogModel::getComments($ids); // loop comments foreach ($comments as $row) { // previous status is spam if ($row['status'] == 'spam') { // unserialize data $row['data'] = unserialize($row['data']); // check if needed data is available if (!isset($row['data']['server']['REMOTE_ADDR'])) { continue; } if (!isset($row['data']['server']['HTTP_USER_AGENT'])) { continue; } // build vars $userIp = $row['data']['server']['REMOTE_ADDR']; $userAgent = $row['data']['server']['HTTP_USER_AGENT']; $content = $row['text']; $author = $row['author']; $email = $row['email']; $url = isset($row['website']) && $row['website'] != '' ? $row['website'] : null; $referrer = isset($row['data']['server']['HTTP_REFERER']) ? $row['data']['server']['HTTP_REFERER'] : null; $others = $row['data']['server']; // submit as spam BackendModel::submitHam($userIp, $userAgent, $content, $author, $email, $url, null, 'comment', $referrer, $others); } } } } // set new status BackendBlogModel::updateCommentStatuses($ids, $action); } // define report $report = count($ids) > 1 ? 'comments-' : 'comment-'; // init var if ($action == 'published') { $report .= 'moved-published'; } if ($action == 'moderation') { $report .= 'moved-moderation'; } if ($action == 'spam') { $report .= 'moved-spam'; } if ($action == 'delete') { $report .= 'deleted'; } // redirect $this->redirect(BackendModel::createURLForAction('comments') . '&report=' . $report . '#tab' . ucfirst($from)); } }
/** * Load the form */ private function loadForm() { // get default template id $defaultTemplateId = BackendModel::getModuleSetting('pages', 'default_template', 1); // create form $this->frm = new BackendForm('edit'); // assign in template $this->tpl->assign('defaultTemplateId', $defaultTemplateId); // create elements $this->frm->addText('title', $this->record['title'], null, 'inputText title', 'inputTextError title'); $this->frm->addEditor('html'); $this->frm->addHidden('template_id', $this->record['template_id']); $this->frm->addRadiobutton('hidden', array(array('label' => BL::lbl('Hidden'), 'value' => 'Y'), array('label' => BL::lbl('Published'), 'value' => 'N')), $this->record['hidden']); // a god user should be able to adjust the detailed settings for a page easily if ($this->isGod) { // init some vars $items = array('move', 'children', 'edit', 'delete'); $checked = array(); $values = array(); foreach ($items as $value) { $values[] = array('label' => BL::msg(SpoonFilter::toCamelCase('allow_' . $value)), 'value' => $value); if (isset($this->record['allow_' . $value]) && $this->record['allow_' . $value] == 'Y') { $checked[] = $value; } } $this->frm->addMultiCheckbox('allow', $values, $checked); } // build prototype block $block['index'] = 0; $block['formElements']['chkVisible'] = $this->frm->addCheckbox('block_visible_' . $block['index'], true); $block['formElements']['hidExtraId'] = $this->frm->addHidden('block_extra_id_' . $block['index'], 0); $block['formElements']['hidPosition'] = $this->frm->addHidden('block_position_' . $block['index'], 'fallback'); $block['formElements']['txtHTML'] = $this->frm->addTextArea('block_html_' . $block['index'], ''); // this is no editor; we'll add the editor in JS // add default block to "fallback" position, the only one which we can rest assured to exist $this->positions['fallback']['blocks'][] = $block; // content has been submitted: re-create submitted content rather than the db-fetched content if (isset($_POST['block_html_0'])) { // init vars $this->blocksContent = array(); $hasBlock = false; $i = 1; // loop submitted blocks while (isset($_POST['block_position_' . $i])) { // init var $block = array(); // save block position $block['position'] = $_POST['block_position_' . $i]; $positions[$block['position']][] = $block; // set linked extra $block['extra_id'] = $_POST['block_extra_id_' . $i]; // reset some stuff if ($block['extra_id'] <= 0) { $block['extra_id'] = null; } // init html $block['html'] = null; // extra-type is HTML if ($block['extra_id'] === null) { // reset vars $block['extra_id'] = null; $block['html'] = $_POST['block_html_' . $i]; } else { // type of block if (isset($this->extras[$block['extra_id']]['type']) && $this->extras[$block['extra_id']]['type'] == 'block') { // set error if ($hasBlock) { $this->frm->addError(BL::err('CantAdd2Blocks')); } // home can't have blocks if ($this->record['id'] == 1) { $this->frm->addError(BL::err('HomeCantHaveBlocks')); } // reset var $hasBlock = true; } } // set data $block['created_on'] = BackendModel::getUTCDate(); $block['edited_on'] = $block['created_on']; $block['visible'] = isset($_POST['block_visible_' . $i]) && $_POST['block_visible_' . $i] == 'Y' ? 'Y' : 'N'; $block['sequence'] = count($positions[$block['position']]) - 1; // add to blocks $this->blocksContent[] = $block; // increment counter; go fetch next block $i++; } } // build blocks array foreach ($this->blocksContent as $i => $block) { $block['index'] = $i + 1; $block['formElements']['chkVisible'] = $this->frm->addCheckbox('block_visible_' . $block['index'], $block['visible'] == 'Y'); $block['formElements']['hidExtraId'] = $this->frm->addHidden('block_extra_id_' . $block['index'], (int) $block['extra_id']); $block['formElements']['hidPosition'] = $this->frm->addHidden('block_position_' . $block['index'], $block['position']); $block['formElements']['txtHTML'] = $this->frm->addTextArea('block_html_' . $block['index'], $block['html']); // this is no editor; we'll add the editor in JS $this->positions[$block['position']]['blocks'][] = $block; } // redirect $redirectValue = 'none'; if (isset($this->record['data']['internal_redirect']['page_id'])) { $redirectValue = 'internal'; } if (isset($this->record['data']['external_redirect']['url'])) { $redirectValue = 'external'; } $redirectValues = array(array('value' => 'none', 'label' => SpoonFilter::ucfirst(BL::lbl('None'))), array('value' => 'internal', 'label' => SpoonFilter::ucfirst(BL::lbl('InternalLink')), 'variables' => array('isInternal' => true)), array('value' => 'external', 'label' => SpoonFilter::ucfirst(BL::lbl('ExternalLink')), 'variables' => array('isExternal' => true))); $this->frm->addRadiobutton('redirect', $redirectValues, $redirectValue); $this->frm->addDropdown('internal_redirect', BackendPagesModel::getPagesForDropdown(), $redirectValue == 'internal' ? $this->record['data']['internal_redirect']['page_id'] : null); $this->frm->addText('external_redirect', $redirectValue == 'external' ? $this->record['data']['external_redirect']['url'] : null, null, null, null, true); // page info $this->frm->addCheckbox('navigation_title_overwrite', $this->record['navigation_title_overwrite'] == 'Y'); $this->frm->addText('navigation_title', $this->record['navigation_title']); // tags $this->frm->addText('tags', BackendTagsModel::getTags($this->URL->getModule(), $this->id), null, 'inputText tagBox', 'inputTextError tagBox'); // a specific action $isAction = isset($this->record['data']['is_action']) && $this->record['data']['is_action'] == true ? true : false; $this->frm->addCheckbox('is_action', $isAction); // extra $this->frm->addDropdown('extra_type', BackendPagesModel::getTypes()); // meta $this->meta = new BackendMeta($this->frm, $this->record['meta_id'], 'title', true); // set callback for generating an unique URL $this->meta->setURLCallback('BackendPagesModel', 'getURL', array($this->record['id'], $this->record['parent_id'], $isAction)); }
/** * Checks if all necessary settings were set. * * @return void */ private function checkForSettings() { $url = BackendModel::getModuleSetting('mailmotor', 'cm_url'); $username = BackendModel::getModuleSetting('mailmotor', 'cm_username'); $password = BackendModel::getModuleSetting('mailmotor', 'cm_password'); $clientID = BackendModel::getModuleSetting('mailmotor', 'cm_client_id'); return !empty($url) && !empty($username) && !empty($password) && !empty($clientID); }
/** * Parse all user-defined constants */ private function parseConstants() { // constants that should be protected from usage in the template $notPublicConstants = array('DB_TYPE', 'DB_DATABASE', 'DB_HOSTNAME', 'DB_PORT', 'DB_USERNAME', 'DB_PASSWORD'); // get all defined constants $constants = get_defined_constants(true); // init var $realConstants = array(); // remove protected constants aka constants that should not be used in the template foreach ($constants['user'] as $key => $value) { if (!in_array($key, $notPublicConstants)) { $realConstants[$key] = $value; } } // we should only assign constants if there are constants to assign if (!empty($realConstants)) { $this->assign($realConstants); } // we use some abbrviations and common terms, these should also be assigned $this->assign('LANGUAGE', BackendLanguage::getWorkingLanguage()); if ($this->URL instanceof BackendURL) { // assign the current module $this->assign('MODULE', $this->URL->getModule()); // assign the current action if ($this->URL->getAction() != '') { $this->assign('ACTION', $this->URL->getAction()); } } // is the user object filled? if (BackendAuthentication::getUser()->isAuthenticated()) { // assign the authenticated users secret key $this->assign('SECRET_KEY', BackendAuthentication::getUser()->getSecretKey()); // assign the authentiated users preferred interface language $this->assign('INTERFACE_LANGUAGE', (string) BackendAuthentication::getUser()->getSetting('interface_language')); } // assign some variable constants (such as site-title) $this->assign('SITE_TITLE', BackendModel::getModuleSetting('core', 'site_title_' . BackendLanguage::getWorkingLanguage(), SITE_DEFAULT_TITLE)); // theme if (BackendModel::getModuleSetting('core', 'theme') !== null) { $this->assign('THEME', BackendModel::getModuleSetting('core', 'theme')); $this->assign('THEME_PATH', FRONTEND_PATH . '/themes/' . BackendModel::getModuleSetting('core', 'theme')); $this->assign('THEME_HAS_CSS', SpoonFile::exists(FRONTEND_PATH . '/themes/' . BackendModel::getModuleSetting('core', 'theme') . '/core/layout/css/screen.css')); $this->assign('THEME_HAS_EDITOR_CSS', SpoonFile::exists(FRONTEND_PATH . '/themes/' . BackendModel::getModuleSetting('core', 'theme') . '/core/layout/css/editor_content.css')); } }
/** * Validates the form * * @return void */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // validate required fields $this->frm->getField('site_title')->isFilled(BL::err('FieldIsRequired')); // date & time $this->frm->getField('time_format')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('date_format_short')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('date_format_long')->isFilled(BL::err('FieldIsRequired')); // number $this->frm->getField('number_format')->isFilled(BL::err('FieldIsRequired')); // akismet key may be filled in if ($this->needsAkismet && $this->frm->getField('akismet_key')->isFilled()) { // key has changed if ($this->frm->getField('akismet_key')->getValue() != BackendModel::getModuleSetting('core', 'akismet_key', null)) { // load akismet require_once PATH_LIBRARY . '/external/akismet.php'; // create instance $akismet = new Akismet($this->frm->getField('akismet_key')->getValue(), SITE_URL); // invalid key if (!$akismet->verifyKey()) { $this->frm->getField('akismet_key')->setError(BL::err('InvalidAPIKey')); } } } // domains filled in if ($this->frm->getField('site_domains')->isFilled()) { // split on newlines $domains = explode("\n", trim($this->frm->getField('site_domains')->getValue())); // loop domains foreach ($domains as $domain) { // strip funky stuff $domain = trim(str_replace(array('www.', 'http://', 'https://'), '', $domain)); // invalid URL if (!SpoonFilter::isURL('http://' . $domain)) { // set error $this->frm->getField('site_domains')->setError(BL::err('InvalidDomain')); // stop looping domains break; } } } // no errors ? if ($this->frm->isCorrect()) { // general settings BackendModel::setModuleSetting('core', 'site_title_' . BL::getWorkingLanguage(), $this->frm->getField('site_title')->getValue()); BackendModel::setModuleSetting('core', 'site_html_header', $this->frm->getField('site_html_header')->getValue()); BackendModel::setModuleSetting('core', 'site_html_footer', $this->frm->getField('site_html_footer')->getValue()); // facebook settings BackendModel::setModuleSetting('core', 'facebook_admin_ids', $this->frm->getField('facebook_admin_ids')->isFilled() ? $this->frm->getField('facebook_admin_ids')->getValue() : null); BackendModel::setModuleSetting('core', 'facebook_app_id', $this->frm->getField('facebook_application_id')->isFilled() ? $this->frm->getField('facebook_application_id')->getValue() : null); BackendModel::setModuleSetting('core', 'facebook_app_secret', $this->frm->getField('facebook_application_secret')->isFilled() ? $this->frm->getField('facebook_application_secret')->getValue() : null); // api keys BackendModel::setModuleSetting('core', 'fork_api_public_key', $this->frm->getField('fork_api_public_key')->getValue()); BackendModel::setModuleSetting('core', 'fork_api_private_key', $this->frm->getField('fork_api_private_key')->getValue()); if ($this->needsAkismet) { BackendModel::setModuleSetting('core', 'akismet_key', $this->frm->getField('akismet_key')->getValue()); } if ($this->needsGoogleMaps) { BackendModel::setModuleSetting('core', 'google_maps_key', $this->frm->getField('google_maps_key')->getValue()); } // date & time formats BackendModel::setModuleSetting('core', 'time_format', $this->frm->getField('time_format')->getValue()); BackendModel::setModuleSetting('core', 'date_format_short', $this->frm->getField('date_format_short')->getValue()); BackendModel::setModuleSetting('core', 'date_format_long', $this->frm->getField('date_format_long')->getValue()); // date & time formats BackendModel::setModuleSetting('core', 'number_format', $this->frm->getField('number_format')->getValue()); // before we save the languages, we need to ensure that each language actually exists and may be chosen. $languages = array(SITE_DEFAULT_LANGUAGE); // save active languages BackendModel::setModuleSetting('core', 'active_languages', array_unique(array_merge($languages, $this->frm->getField('active_languages')->getValue()))); BackendModel::setModuleSetting('core', 'redirect_languages', array_unique(array_merge($languages, $this->frm->getField('redirect_languages')->getValue()))); // domains may not contain www, http or https. Therefor we must loop and create the list of domains. $siteDomains = array(); // domains filled in if ($this->frm->getField('site_domains')->isFilled()) { // split on newlines $domains = explode("\n", trim($this->frm->getField('site_domains')->getValue())); // loop domains foreach ($domains as $domain) { // strip funky stuff $siteDomains[] = trim(str_replace(array('www.', 'http://', 'https://'), '', $domain)); } } // save domains BackendModel::setModuleSetting('core', 'site_domains', $siteDomains); // assign report $this->tpl->assign('report', true); $this->tpl->assign('reportMessage', BL::msg('Saved')); } } }