/** * Load the form */ private function loadForm() { $this->imageIsAllowed = BackendModel::getModuleSetting($this->URL->getModule(), 'show_image_form', true); $this->frm = new BackendForm('add'); // set hidden values $rbtHiddenValues[] = array('label' => BL::lbl('Hidden', $this->URL->getModule()), 'value' => 'Y'); $rbtHiddenValues[] = array('label' => BL::lbl('Published'), 'value' => 'N'); // get categories $categories = BackendBlogModel::getCategories(); $categories['new_category'] = SpoonFilter::ucfirst(BL::getLabel('AddCategory')); // create elements $this->frm->addText('title', null, null, 'inputText title', 'inputTextError title'); $this->frm->addEditor('text'); $this->frm->addEditor('introduction'); $this->frm->addRadiobutton('hidden', $rbtHiddenValues, 'N'); $this->frm->addCheckbox('allow_comments', BackendModel::getModuleSetting($this->getModule(), 'allow_comments', false)); $this->frm->addDropdown('category_id', $categories, SpoonFilter::getGetValue('category', null, null, 'int')); if (count($categories) != 2) { $this->frm->getField('category_id')->setDefaultElement(''); } $this->frm->addDropdown('user_id', BackendUsersModel::getUsers(), BackendAuthentication::getUser()->getUserId()); $this->frm->addText('tags', null, null, 'inputText tagBox', 'inputTextError tagBox'); $this->frm->addDate('publish_on_date'); $this->frm->addTime('publish_on_time'); if ($this->imageIsAllowed) { $this->frm->addImage('image'); } // meta $this->meta = new BackendMeta($this->frm, null, 'title', true); }
/** * 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); }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); if ($this->frm->isCorrect()) { // build item $item['id'] = BackendContentBlocksModel::getMaximumId() + 1; $item['user_id'] = BackendAuthentication::getUser()->getUserId(); $item['template'] = count($this->templates) > 1 ? $this->frm->getField('template')->getValue() : $this->templates[0]; $item['language'] = BL::getWorkingLanguage(); $item['title'] = $this->frm->getField('title')->getValue(); $item['text'] = $this->frm->getField('text')->getValue(); $item['hidden'] = $this->frm->getField('hidden')->getValue() ? 'N' : 'Y'; $item['status'] = 'active'; $item['created_on'] = BackendModel::getUTCDate(); $item['edited_on'] = BackendModel::getUTCDate(); // insert the item $item['revision_id'] = BackendContentBlocksModel::insert($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('QuestionIsRequired')); $this->frm->getField('answer')->isFilled(BL::err('AnswerIsRequired')); $this->frm->getField('category_id')->isFilled(BL::err('CategoryIsRequired')); $this->meta->validate(); if ($this->frm->isCorrect()) { // build item $item['meta_id'] = $this->meta->save(); $item['category_id'] = $this->frm->getField('category_id')->getValue(); $item['user_id'] = BackendAuthentication::getUser()->getUserId(); $item['language'] = BL::getWorkingLanguage(); $item['question'] = $this->frm->getField('title')->getValue(); $item['answer'] = $this->frm->getField('answer')->getValue(true); $item['created_on'] = BackendModel::getUTCDate(); $item['hidden'] = $this->frm->getField('hidden')->getValue(); $item['sequence'] = BackendFaqModel::getMaximumSequence($this->frm->getField('category_id')->getValue()) + 1; // save the data $item['id'] = BackendFaqModel::insert($item); BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule()); BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // add search index BackendSearchModel::saveIndex('faq', $item['id'], array('title' => $item['question'], 'text' => $item['answer'])); $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['question']) . '&highlight=row-' . $item['id']); } } }
/** * Output a CSV-file as a download * * @param string $filename The name of the file. * @param array $array The array to convert. * @param array[optional] $columns The column names you want to use. * @param array[optional] $excludeColumns The columns you want to exclude. */ public static function outputCSV($filename, array $array, array $columns = null, array $excludeColumns = null) { // get settings $splitCharacter = BackendAuthentication::getUser()->getSetting('csv_split_character'); $lineEnding = BackendAuthentication::getUser()->getSetting('csv_line_ending'); // reformat if ($lineEnding == '\\n') { $lineEnding = "\n"; } if ($lineEnding == '\\r\\n') { $lineEnding = "\r\n"; } // convert into CSV $csv = SpoonFileCSV::arrayToString($array, $columns, $excludeColumns, $splitCharacter, '"', $lineEnding); // set headers for download $headers[] = 'Content-type: application/csv; charset=' . SPOON_CHARSET; $headers[] = 'Content-Disposition: attachment; filename="' . $filename; $headers[] = 'Content-Length: ' . strlen($csv); $headers[] = 'Pragma: no-cache'; // overwrite the headers SpoonHTTP::setHeaders($headers); // ouput the CSV echo $csv; exit; }
/** * Loads the settings form */ private function loadForm() { $this->isGod = BackendAuthentication::getUser()->isGod(); $this->frm = new BackendForm('settings'); // add fields for pagination $this->frm->addDropdown('overview_number_of_items', array_combine(range(1, 30), range(1, 30)), BackendModel::getModuleSetting($this->URL->getModule(), 'overview_num_items', 10)); $this->frm->addDropdown('recent_articles_full_number_of_items', array_combine(range(1, 10), range(1, 10)), BackendModel::getModuleSetting($this->URL->getModule(), 'recent_articles_full_num_items', 5)); $this->frm->addDropdown('recent_articles_list_number_of_items', array_combine(range(1, 10), range(1, 10)), BackendModel::getModuleSetting($this->URL->getModule(), 'recent_articles_list_num_items', 5)); // add fields for spam $this->frm->addCheckbox('spamfilter', BackendModel::getModuleSetting($this->URL->getModule(), 'spamfilter', false)); // no Akismet-key, so we can't enable spam-filter if (BackendModel::getModuleSetting('core', 'akismet_key') == '') { $this->frm->getField('spamfilter')->setAttribute('disabled', 'disabled'); $this->tpl->assign('noAkismetKey', true); } // add fields for comments $this->frm->addCheckbox('allow_comments', BackendModel::getModuleSetting($this->URL->getModule(), 'allow_comments', false)); $this->frm->addCheckbox('moderation', BackendModel::getModuleSetting($this->URL->getModule(), 'moderation', false)); // add fields for notifications $this->frm->addCheckbox('notify_by_email_on_new_comment_to_moderate', BackendModel::getModuleSetting($this->URL->getModule(), 'notify_by_email_on_new_comment_to_moderate', false)); $this->frm->addCheckbox('notify_by_email_on_new_comment', BackendModel::getModuleSetting($this->URL->getModule(), 'notify_by_email_on_new_comment', false)); // add fields for SEO $this->frm->addCheckbox('ping_services', BackendModel::getModuleSetting($this->URL->getModule(), 'ping_services', false)); // add fields for RSS $this->frm->addCheckbox('rss_meta', BackendModel::getModuleSetting($this->URL->getModule(), 'rss_meta_' . BL::getWorkingLanguage(), true)); $this->frm->addText('rss_title', BackendModel::getModuleSetting($this->URL->getModule(), 'rss_title_' . BL::getWorkingLanguage())); $this->frm->addTextarea('rss_description', BackendModel::getModuleSetting($this->URL->getModule(), 'rss_description_' . BL::getWorkingLanguage())); $this->frm->addText('feedburner_url', BackendModel::getModuleSetting($this->URL->getModule(), 'feedburner_url_' . BL::getWorkingLanguage())); // god user? if ($this->isGod) { $this->frm->addCheckbox('show_image_form', BackendModel::getModuleSetting($this->URL->getModule(), 'show_image_form', true)); } }
/** * 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); }
/** * Parse into template */ private function parse() { // get the logged in user $authenticatedUser = BackendAuthentication::getUser(); // check if we need to show the password strength and parse the label $this->tpl->assign('showPasswordStrength', $authenticatedUser->getSetting('password_strength') !== 'strong'); $this->tpl->assign('passwordStrengthLabel', BL::lbl($authenticatedUser->getSetting('password_strength'))); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $newSequence = SpoonFilter::getPostValue('new_sequence', null, ''); // validate if ($newSequence == '') { $this->output(self::BAD_REQUEST, null, 'no new_sequence provided'); } // convert into array $json = @json_decode($newSequence, true); // validate if ($json === false) { $this->output(self::BAD_REQUEST, null, 'invalid new_sequence provided'); } // initialize $userSequence = array(); $hiddenItems = array(); // loop columns foreach ($json as $column => $widgets) { $columnValue = 'left'; if ($column == 1) { $columnValue = 'middle'; } if ($column == 2) { $columnValue = 'right'; } // loop widgets foreach ($widgets as $sequence => $widget) { // store position $userSequence[$widget['module']][$widget['widget']] = array('column' => $columnValue, 'position' => $sequence, 'hidden' => $widget['hidden'], 'present' => $widget['present']); // add to array if ($widget['hidden']) { $hiddenItems[] = $widget['module'] . '_' . $widget['widget']; } } } // get previous setting $currentSetting = BackendAuthentication::getUser()->getSetting('dashboard_sequence'); $data['reload'] = false; // any settings? if ($currentSetting !== null) { // loop modules foreach ($currentSetting as $module => $widgets) { foreach ($widgets as $widget => $values) { if ($values['hidden'] && isset($userSequence[$module][$widget]['hidden']) && !$userSequence[$module][$widget]['hidden']) { $data['reload'] = true; } } } } // store BackendAuthentication::getUser()->setSetting('dashboard_sequence', $userSequence); // output $this->output(self::OK, $data, 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(); // user is god? $isGod = BackendAuthentication::getUser()->isGod(); // get possible languages if ($isGod) { $possibleLanguages = array_unique(array_merge(BL::getWorkingLanguages(), BL::getInterfaceLanguages())); } else { $possibleLanguages = BL::getWorkingLanguages(); } // get parameters $language = SpoonFilter::getPostValue('language', array_keys($possibleLanguages), null, 'string'); $module = SpoonFilter::getPostValue('module', BackendModel::getModules(false), null, 'string'); $name = SpoonFilter::getPostValue('name', null, null, 'string'); $type = SpoonFilter::getPostValue('type', BackendModel::getDB()->getEnumValues('locale', 'type'), null, 'string'); $application = SpoonFilter::getPostValue('application', array('backend', 'frontend'), null, 'string'); $value = SpoonFilter::getPostValue('value', null, null, 'string'); // validate values if (trim($value) == '' || $language == '' || $module == '' || $type == '' || $application == '' || $application == 'frontend' && $module != 'core') { $error = BL::err('InvalidValue'); } // in case this is a 'act' type, there are special rules concerning possible values if ($type == 'act' && !isset($error)) { if (!SpoonFilter::isValidAgainstRegexp('|^([a-z0-9\\-\\_])+$|', $value)) { $error = BL::err('InvalidActionValue', $this->getModule()); } } // no error? if (!isset($error)) { // build item $item['language'] = $language; $item['module'] = $module; $item['name'] = $name; $item['type'] = $type; $item['application'] = $application; $item['value'] = $value; $item['edited_on'] = BackendModel::getUTCDate(); $item['user_id'] = BackendAuthentication::getUser()->getUserId(); // does the translation exist? if (BackendLocaleModel::existsByName($name, $type, $module, $language, $application)) { // add the id to the item $item['id'] = (int) BackendLocaleModel::getByName($name, $type, $module, $language, $application); // update in db BackendLocaleModel::update($item); } else { // insert in db BackendLocaleModel::insert($item); } // output OK $this->output(self::OK); } else { $this->output(self::ERROR, null, $error); } }
/** * Execute the action */ public function execute() { parent::execute(); $this->isGod = BackendAuthentication::getUser()->isGod(); $this->setFilter(); $this->loadForm(); $this->loadDataGrid(); $this->parse(); $this->display(); }
/** * Validate the form * * @return void */ 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(); // shorten the fields $txtName = $this->frm->getField('name'); $txtEmail = $this->frm->getField('email'); $ddmMethod = $this->frm->getField('method'); $txtSuccessMessage = $this->frm->getField('success_message'); $txtIdentifier = $this->frm->getField('identifier'); // validate fields $txtName->isFilled(BL::getError('NameIsRequired')); $txtSuccessMessage->isFilled(BL::getError('SuccessMessageIsRequired')); if ($ddmMethod->isFilled(BL::getError('NameIsRequired')) && $ddmMethod->getValue() == 'database_email') { $txtEmail->isEmail(BL::getError('EmailIsRequired')); } // identifier if ($txtIdentifier->isFilled()) { // invalid characters if (!SpoonFilter::isValidAgainstRegexp('/^[a-zA-Z0-9\\.\\_\\-]+$/', $txtIdentifier->getValue())) { $txtIdentifier->setError(BL::getError('InvalidIdentifier')); } elseif (BackendFormBuilderModel::existsIdentifier($txtIdentifier->getValue())) { $txtIdentifier->setError(BL::getError('UniqueIdentifier')); } } // no errors? if ($this->frm->isCorrect()) { // build array $values['language'] = BL::getWorkingLanguage(); $values['user_id'] = BackendAuthentication::getUser()->getUserId(); $values['name'] = $txtName->getValue(); $values['method'] = $ddmMethod->getValue(); $values['email'] = $values['method'] == 'database_email' ? $txtEmail->getValue() : null; $values['success_message'] = $txtSuccessMessage->getValue(true); $values['identifier'] = $txtIdentifier->isFilled() ? $txtIdentifier->getValue() : BackendFormBuilderModel::createIdentifier(); $values['created_on'] = BackendModel::getUTCDate(); $values['edited_on'] = BackendModel::getUTCDate(); // insert the item $id = BackendFormBuilderModel::insert($values); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $values)); // set frontend locale FL::setLocale(BL::getWorkingLanguage()); // create submit button $field['form_id'] = $id; $field['type'] = 'submit'; $field['settings'] = serialize(array('values' => ucfirst(FL::getLabel('Send')))); BackendFormBuilderModel::insertField($field); // everything is saved, so redirect to the editform $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $id . '&report=added&var=' . urlencode($values['name']) . '#tabFields'); } } }
/** * Execute the action */ public function execute() { // check if the user is really logged on if (BackendAuthentication::getUser()->isAuthenticated()) { $this->redirect($this->getParameter('querystring', 'string', BackendModel::createUrlForAction(null, 'dashboard'))); } parent::execute(); $this->load(); $this->validateForm(); $this->parse(); $this->display(); }
/** * Load the form */ private function loadForm() { // create user objects $this->user = new BackendUser($this->id); $this->authenticatedUser = BackendAuthentication::getUser(); // create form $this->frm = new BackendForm('edit'); // get active groups $groups = BackendGroupsModel::getGroupsByUser($this->id); // loop through groups and set checked foreach ($groups as $group) { $checkedGroups[] = $group['id']; } // create elements // profile $this->frm->addText('email', $this->record['email'], 255); if ($this->user->isGod()) { $this->frm->getField('email')->setAttributes(array('disabled' => 'disabled')); } $this->frm->addText('name', $this->record['settings']['name'], 255); $this->frm->addText('surname', $this->record['settings']['surname'], 255); $this->frm->addText('nickname', $this->record['settings']['nickname'], 24); $this->frm->addImage('avatar'); // password // check if we're god or same user if ($this->authenticatedUser->getUserId() == $this->id || $this->authenticatedUser->isGod()) { // allow to set new password $this->frm->addPassword('new_password', null, 75); $this->frm->addPassword('confirm_password', null, 75); // disable autocomplete $this->frm->getField('new_password')->setAttributes(array('autocomplete' => 'off')); $this->frm->getField('confirm_password')->setAttributes(array('autocomplete' => 'off')); } // settings $this->frm->addDropdown('interface_language', BackendLanguage::getInterfaceLanguages(), $this->record['settings']['interface_language']); $this->frm->addDropdown('date_format', BackendUsersModel::getDateFormats(), $this->user->getSetting('date_format')); $this->frm->addDropdown('time_format', BackendUsersModel::getTimeFormats(), $this->user->getSetting('time_format')); $this->frm->addDropdown('number_format', BackendUsersModel::getNumberFormats(), $this->user->getSetting('number_format', 'dot_nothing')); $this->frm->addDropDown('csv_split_character', BackendUsersModel::getCSVSplitCharacters(), $this->user->getSetting('csv_split_character')); $this->frm->addDropDown('csv_line_ending', BackendUsersModel::getCSVLineEndings(), $this->user->getSetting('csv_line_ending')); // permissions $this->frm->addCheckbox('active', $this->record['active'] == 'Y'); // disable active field for current users if ($this->authenticatedUser->getUserId() == $this->record['id']) { $this->frm->getField('active')->setAttribute('disabled', 'disabled'); } $this->frm->addCheckbox('api_access', isset($this->record['settings']['api_access']) && $this->record['settings']['api_access'] == 'Y'); $this->frm->addMultiCheckbox('groups', BackendGroupsModel::getAll(), $checkedGroups); }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // is the user a GodUser? $this->isGod = BackendAuthentication::getUser()->isGod(); // set filter $this->setFilter(); // load form $this->loadForm(); // load datagrids $this->loadDataGrid(); // parse page $this->parse(); // display the page $this->display(); }
/** * Load the datagird with the drafts * * @return void */ private function loadDataGridDrafts() { // create datagrid $this->dgDrafts = new BackendDataGridDB(BackendPagesModel::QRY_DATAGRID_BROWSE_DRAFTS, array('draft', BackendAuthentication::getUser()->getUserId(), BL::getWorkingLanguage())); // hide columns $this->dgDrafts->setColumnsHidden(array('revision_id')); // disable paging $this->dgDrafts->setPaging(false); // set colum URLs $this->dgDrafts->setColumnURL('title', BackendModel::createURLForAction('edit') . '&id=[id]&draft=[revision_id]'); // set column functions $this->dgDrafts->setColumnFunction(array('BackendDataGridFunctions', 'getUser'), array('[user_id]'), 'user_id', true); $this->dgDrafts->setColumnFunction(array('BackendDataGridFunctions', 'getLongDate'), array('[edited_on]'), 'edited_on'); // add edit column $this->dgDrafts->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit') . '&id=[id]&draft=[revision_id]', BL::lbl('Edit')); // set headers $this->dgDrafts->setHeaderLabels(array('user_id' => ucfirst(BL::lbl('By')), 'edited_on' => ucfirst(BL::lbl('LastEdited')))); }
public function __construct() { // store in reference so we can access it from everywhere Spoon::set('navigation', $this); // grab from the reference $this->URL = Spoon::get('url'); // check if navigation cache file exists if (!SpoonFile::exists(BACKEND_CACHE_PATH . '/navigation/navigation.php')) { $this->buildCache(); } $navigation = array(); // require navigation-file require_once BACKEND_CACHE_PATH . '/navigation/navigation.php'; // load it $this->navigation = (array) $navigation; // cleanup navigation (not needed for god user) if (!BackendAuthentication::getUser()->isGod()) { $this->navigation = $this->cleanup($this->navigation); } }
/** * Execute the action * * @return void */ public function execute() { // check if the user is really logged on if (BackendAuthentication::getUser()->isAuthenticated()) { // get the redirect-URL from the URL $redirectURL = $this->getParameter('querystring', 'string', BackendModel::createUrlForAction(null, 'dashboard')); // redirect to the correct URL (URL the user was looking for or fallback) $this->redirect($redirectURL); } // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // load form $this->load(); // validate the form $this->validateForm(); // parse the error $this->parse(); // display the page $this->display(); }
/** * Execute the action */ public function execute() { $this->id = $this->getParameter('id', 'int'); // does the item exist if ($this->id !== null && BackendLocaleModel::exists($this->id) && BackendAuthentication::getUser()->isGod()) { parent::execute(); // filter options $this->setFilter(); // get data $this->record = (array) BackendLocaleModel::get($this->id); // delete item BackendLocaleModel::delete(array($this->id)); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // build redirect URL $redirectUrl = BackendModel::createURLForAction('index') . '&report=deleted&var=' . urlencode($this->record['name'] . ' (' . strtoupper($this->record['language']) . ')') . $this->filterQuery; // item was deleted, so redirect $this->redirect($redirectUrl); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * Execute the action */ public function execute() { // get parameters $this->id = $this->getParameter('id', 'int'); // does the user exist if ($this->id !== null && BackendUsersModel::exists($this->id) && BackendAuthentication::getUser()->getUserId() != $this->id) { parent::execute(); // get data $user = new BackendUser($this->id); // God-users can't be deleted if ($user->isGod()) { $this->redirect(BackendModel::createURLForAction('index') . '&error=cant-delete-god'); } // delete item BackendUsersModel::delete($this->id); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id)); // item was deleted, so redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=deleted&var=' . $user->getSetting('nickname')); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=non-existing'); } }
/** * Load the form * * @return void */ private function loadForm() { // create form $this->frm = new BackendForm('add'); // create elements $this->frm->addText('email', null, 255); $this->frm->addPassword('password', null, 75, 'inputText inputPassword passwordGenerator', 'inputTextError inputPasswordError passwordGenerator'); $this->frm->addPassword('confirm_password', null, 75); $this->frm->addText('nickname', null, 24); $this->frm->addText('name', null, 255); $this->frm->addText('surname', null, 255); $this->frm->addDropdown('interface_language', BackendLanguage::getInterfaceLanguages()); $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->addImage('avatar'); $this->frm->addCheckbox('active', true); $this->frm->addCheckbox('api_access', false); $this->frm->addMultiCheckbox('groups', BackendGroupsModel::getAll()); // disable autocomplete $this->frm->getField('password')->setAttributes(array('autocomplete' => 'off')); $this->frm->getField('confirm_password')->setAttributes(array('autocomplete' => 'off')); }
/** * Format a UNIX-timestamp as a date * syntac: {$var|formatdate} * * @param int $var The UNIX-timestamp to format. * @return string */ public static function formatTime($var) { // get setting $format = BackendAuthentication::getUser()->getSetting('time_format'); // format the date return SpoonDate::getDate($format, (int) $var, BackendLanguage::getInterfaceLanguage()); }
/** * Process the XML and treat it as a blogpost * * @param SimpleXMLElement $xml The XML to process. * @return bool */ private function processXMLAsPost(SimpleXMLElement $xml) { // init var $postID = substr((string) $xml->id, mb_strpos((string) $xml->id, 'post-') + 5); // validate if ($postID == '') { return false; } if ((string) $xml->title == '') { return false; } // build item $item['id'] = (int) BackendBlogModel::getMaximumId() + 1; $item['user_id'] = BackendAuthentication::getUser()->getUserId(); $item['hidden'] = 'N'; $item['allow_comments'] = 'Y'; $item['num_comments'] = 0; $item['status'] = 'active'; $item['language'] = BL::getWorkingLanguage(); $item['publish_on'] = BackendModel::getUTCDate(null, strtotime((string) $xml->published)); $item['created_on'] = BackendModel::getUTCDate(null, strtotime((string) $xml->published)); $item['edited_on'] = BackendModel::getUTCDate(null, strtotime((string) $xml->updated)); $item['category_id'] = 1; $item['title'] = (string) $xml->title; $item['text'] = (string) $xml->content; // set drafts hidden if (strtotime((string) $xml->published) > time()) { $item['hidden'] = 'Y'; $item['status'] = 'draft'; } // build meta $meta = array(); $meta['keywords'] = $item['title']; $meta['keywords_overwrite'] = 'N'; $meta['description'] = $item['title']; $meta['description_overwrite'] = 'N'; $meta['title'] = $item['title']; $meta['title_overwrite'] = 'N'; $meta['url'] = BackendBlogModel::getURL($item['title']); $meta['url_overwrite'] = 'N'; // replace f****d up links $item['text'] = preg_replace('|<a(.*)onblur="(.*)"(.*)>|Ui', '<a$1$3>', $item['text']); // fix images $item['text'] = preg_replace('|<img(.*)border="(.*)"(.*)>|Ui', '<img$1$3>', $item['text']); // remove inline styles $item['text'] = preg_replace('|<(.*)style="(.*)"(.*)>|Ui', '<$1$3>', $item['text']); // whitespace $item['text'] = preg_replace('|\\s{2,}|', ' ', $item['text']); // cleanup $search = array('<br /><br />', '<div><br /></div>', '<div>', '</div>', '<i>', '</i>', '<b>', '</b>', '<p><object', '</object></p>', '<p><p>', '</p></p>', '...'); $replace = array('</p><p>', '</p><p>', '', '', '<em>', '</em>', '<strong>', '</strong>', '<object', '</object>', '<p>', '</p>', '…'); // cleanup $item['text'] = '<p>' . str_replace($search, $replace, SpoonFilter::htmlentitiesDecode($item['text'])) . '</p>'; // get images $matches = array(); preg_match_all('/<img.*src="(.*)".*\\/>/Ui', $item['text'], $matches); // any images? if (isset($matches[1]) && !empty($matches[1])) { // init var $imagesPath = FRONTEND_FILES_PATH . '/userfiles/images/blog'; $imagesURL = FRONTEND_FILES_URL . '/userfiles/images/blog'; // create dir if needed if (!SpoonDirectory::exists($imagesPath)) { SpoonDirectory::create($imagesPath); } // loop matches foreach ($matches[1] as $key => $file) { // get file info $fileInfo = SpoonFile::getInfo($file); // init var $destinationFile = $item['id'] . '_' . $fileInfo['basename']; try { // download SpoonFile::download($file, $imagesPath . '/' . $destinationFile); // replace the old URL with the new one $item['text'] = str_replace($file, $imagesURL . '/' . $destinationFile, $item['text']); } catch (Exception $e) { // ignore } } } // get links $matches = array(); preg_match_all('/<a.*href="(.*)".*\\/>/Ui', $item['text'], $matches); // any images? if (isset($matches[1]) && !empty($matches[1])) { // loop matches foreach ($matches[1] as $key => $file) { // get new link $replaceWith = self::download($file, $item['id']); // should we replace? if ($replaceWith !== false) { // replace the old URL with the new one $item['text'] = str_replace($file, $replaceWith, $item['text']); } } } // insert meta $item['meta_id'] = BackendModel::getDB(true)->insert('meta', $meta); // insert BackendBlogModel::insert($item); // store the post $this->newIds[$postID] = $item['id']; // get tags $tags = array(); // loop categories foreach ($xml->category as $category) { // is this a tag? if so add it if ((string) $category['scheme'] == 'http://www.blogger.com/atom/ns#') { $tags[] = (string) $category['term']; } } // any tags? if (!empty($tags)) { BackendTagsModel::saveTags($item['id'], implode(',', $tags), $this->getModule()); } // return return true; }
/** * Set language * * @param string $value The language to load. */ private function setLanguage($value) { // set property $this->language = (string) $value; // is this a authenticated user? if (BackendAuthentication::isLoggedIn()) { $language = BackendAuthentication::getUser()->getSetting('interface_language'); } else { $language = BackendModel::getModuleSetting('core', 'default_interface_language'); } // set the locale (we need this for the labels) BackendLanguage::setLocale($language); // set the working language BackendLanguage::setWorkingLanguage($this->language); }
/** * Parse the data */ protected function parse() { parent::parse(); $this->tpl->assign('godUser', BackendAuthentication::getUser()->isGod()); }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // redefine fields $txtName = $this->frm->getField('name'); $txtValue = $this->frm->getField('value'); // name checks if ($txtName->isFilled(BL::err('FieldIsRequired'))) { // allowed regex (a-z and 0-9) if ($txtName->isValidAgainstRegexp('|^([a-z0-9])+$|i', BL::err('InvalidName'))) { // first letter does not seem to be a capital one if (!in_array(substr($txtName->getValue(), 0, 1), range('A', 'Z'))) { $txtName->setError(BL::err('InvalidName')); } else { // this name already exists in this language if (BackendLocaleModel::existsByName($txtName->getValue(), $this->frm->getField('type')->getValue(), $this->frm->getField('module')->getValue(), $this->frm->getField('language')->getValue(), $this->frm->getField('application')->getValue())) { $txtName->setError(BL::err('AlreadyExists')); } } } } // value checks if ($txtValue->isFilled(BL::err('FieldIsRequired'))) { // in case this is a 'act' type, there are special rules concerning possible values if ($this->frm->getField('type')->getValue() == 'act') { if (urlencode($txtValue->getValue()) != SpoonFilter::urlise($txtValue->getValue())) { $txtValue->addError(BL::err('InvalidValue')); } } } // module should be 'core' for any other application than backend if ($this->frm->getField('application')->getValue() != 'backend' && $this->frm->getField('module')->getValue() != 'core') { $this->frm->getField('module')->setError(BL::err('ModuleHasToBeCore')); } if ($this->frm->isCorrect()) { // build item $item['user_id'] = BackendAuthentication::getUser()->getUserId(); $item['language'] = $this->frm->getField('language')->getValue(); $item['application'] = $this->frm->getField('application')->getValue(); $item['module'] = $this->frm->getField('module')->getValue(); $item['type'] = $this->frm->getField('type')->getValue(); $item['name'] = $this->frm->getField('name')->getValue(); $item['value'] = $this->frm->getField('value')->getValue(); $item['edited_on'] = BackendModel::getUTCDate(); // update item $item['id'] = BackendLocaleModel::insert($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index', null, null, null) . '&report=added&var=' . urlencode($item['name']) . '&highlight=row-' . $item['id'] . $this->filterQuery); } } }
/** * Execute the action * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // get parameters $from = $this->getParameter('from'); $to = $this->getParameter('to'); // validate if ($from == '') { throw new BackendException('Specify a from-parameter.'); } if ($to == '') { throw new BackendException('Specify a to-parameter.'); } // get db $db = BackendModel::getDB(true); // get all old pages $ids = $db->getColumn('SELECT id FROM pages AS i WHERE i.language = ? AND i.status = ?', array($to, 'active')); // any old pages if (!empty($ids)) { // delete existing pages foreach ($ids as $id) { // redefine $id = (int) $id; // get revision ids $revisionIDs = (array) $db->getColumn('SELECT i.revision_id FROM pages AS i WHERE i.id = ? AND i.language = ?', array($id, $to)); // get meta ids $metaIDs = (array) $db->getColumn('SELECT i.meta_id FROM pages AS i WHERE i.id = ? AND i.language = ?', array($id, $to)); // delete meta records if (!empty($metaIDs)) { $db->delete('meta', 'id IN (' . implode(',', $metaIDs) . ')'); } // delete blocks and their revisions if (!empty($revisionIDs)) { $db->delete('pages_blocks', 'revision_id IN (' . implode(',', $revisionIDs) . ')'); } // delete page and the revisions if (!empty($revisionIDs)) { $db->delete('pages', 'revision_id IN (' . implode(',', $revisionIDs) . ')'); } } } // delete search indexes $db->delete('search_index', 'module = ? AND language = ?', array('pages', $to)); // get all active pages $ids = BackendModel::getDB()->getColumn('SELECT id FROM pages AS i WHERE i.language = ? AND i.status = ?', array($from, 'active')); // loop foreach ($ids as $id) { // get data $sourceData = BackendPagesModel::get($id, $from); // get and build meta $meta = $db->getRecord('SELECT * FROM meta WHERE id = ?', $sourceData['meta_id']); // remove id unset($meta['id']); // build page record $page = array(); $page['id'] = $sourceData['id']; $page['user_id'] = BackendAuthentication::getUser()->getUserId(); $page['parent_id'] = $sourceData['parent_id']; $page['template_id'] = $sourceData['template_id']; $page['meta_id'] = (int) $db->insert('meta', $meta); $page['language'] = $to; $page['type'] = $sourceData['type']; $page['title'] = $sourceData['title']; $page['navigation_title'] = $sourceData['navigation_title']; $page['navigation_title_overwrite'] = $sourceData['navigation_title_overwrite']; $page['hidden'] = $sourceData['hidden']; $page['status'] = 'active'; $page['publish_on'] = BackendModel::getUTCDate(); $page['created_on'] = BackendModel::getUTCDate(); $page['edited_on'] = BackendModel::getUTCDate(); $page['allow_move'] = $sourceData['allow_move']; $page['allow_children'] = $sourceData['allow_children']; $page['allow_edit'] = $sourceData['allow_edit']; $page['allow_delete'] = $sourceData['allow_delete']; $page['sequence'] = $sourceData['sequence']; $page['data'] = $sourceData['data'] !== null ? serialize($sourceData['data']) : null; // insert page, store the id, we need it when building the blocks $revisionId = BackendPagesModel::insert($page); // init var $blocks = array(); $hasBlock = $sourceData['has_extra'] == 'Y'; // get the blocks $sourceBlocks = BackendPagesModel::getBlocks($id, $from); // loop blocks foreach ($sourceBlocks as $sourceBlock) { // build block $block = array(); $block['id'] = $sourceBlock['id']; $block['revision_id'] = $revisionId; $block['extra_id'] = $sourceBlock['extra_id']; $block['html'] = $sourceBlock['html']; $block['status'] = 'active'; $block['created_on'] = BackendModel::getUTCDate(); $block['edited_on'] = BackendModel::getUTCDate(); // add block $blocks[] = $block; } // insert the blocks BackendPagesModel::insertBlocks($blocks, $hasBlock); // check if the method exists if (method_exists('BackendSearchModel', 'addIndex')) { // init var $text = ''; // build search-text foreach ($blocks as $block) { $text .= ' ' . $block['html']; } // add BackendSearchModel::addIndex('pages', (int) $page['id'], array('title' => $page['title'], 'text' => $text), $to); } // get tags $tags = BackendTagsModel::getTags('pages', $id, 'string', $from); // save tags if ($tags != '') { BackendTagsModel::saveTags($page['id'], $tags, 'pages'); } } // build cache BackendPagesModel::buildCache($to); }
/** * Validate the form */ private function validateForm() { // is the form submitted? if ($this->frm->isSubmitted()) { // get the status $status = SpoonFilter::getPostValue('status', array('active', 'draft'), 'active'); // validate redirect $redirectValue = $this->frm->getField('redirect')->getValue(); if ($redirectValue == 'internal') { $this->frm->getField('internal_redirect')->isFilled(BL::err('FieldIsRequired')); } if ($redirectValue == 'external') { $this->frm->getField('external_redirect')->isURL(BL::err('InvalidURL')); } // set callback for generating an unique URL $this->meta->setURLCallback('BackendPagesModel', 'getURL', array($this->record['id'], $this->record['parent_id'], $this->frm->getField('is_action')->getChecked())); // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); // validate meta $this->meta->validate(); // no errors? if ($this->frm->isCorrect()) { // init var $data = null; // build data if ($this->frm->getField('is_action')->isChecked()) { $data['is_action'] = true; } if ($redirectValue == 'internal') { $data['internal_redirect'] = array('page_id' => $this->frm->getField('internal_redirect')->getValue(), 'code' => '301'); } if ($redirectValue == 'external') { $data['external_redirect'] = array('url' => $this->frm->getField('external_redirect')->getValue(), 'code' => '301'); } // build page record $page['id'] = $this->record['id']; $page['user_id'] = BackendAuthentication::getUser()->getUserId(); $page['parent_id'] = $this->record['parent_id']; $page['template_id'] = (int) $this->frm->getField('template_id')->getValue(); $page['meta_id'] = (int) $this->meta->save(); $page['language'] = BackendLanguage::getWorkingLanguage(); $page['type'] = $this->record['type']; $page['title'] = $this->frm->getField('title')->getValue(); $page['navigation_title'] = $this->frm->getField('navigation_title')->getValue() != '' ? $this->frm->getField('navigation_title')->getValue() : $this->frm->getField('title')->getValue(); $page['navigation_title_overwrite'] = $this->frm->getField('navigation_title_overwrite')->isChecked() ? 'Y' : 'N'; $page['hidden'] = $this->frm->getField('hidden')->getValue(); $page['status'] = $status; $page['publish_on'] = BackendModel::getUTCDate(null, $this->record['publish_on']); $page['created_on'] = BackendModel::getUTCDate(null, $this->record['created_on']); $page['edited_on'] = BackendModel::getUTCDate(); $page['allow_move'] = $this->record['allow_move']; $page['allow_children'] = $this->record['allow_children']; $page['allow_edit'] = $this->record['allow_edit']; $page['allow_delete'] = $this->record['allow_delete']; $page['sequence'] = $this->record['sequence']; $page['data'] = $data !== null ? serialize($data) : null; if ($this->isGod) { $page['allow_move'] = in_array('move', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N'; $page['allow_children'] = in_array('children', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N'; $page['allow_edit'] = in_array('edit', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N'; $page['allow_delete'] = in_array('delete', (array) $this->frm->getField('allow')->getValue()) ? 'Y' : 'N'; } // set navigation title if ($page['navigation_title'] == '') { $page['navigation_title'] = $page['title']; } // insert page, store the id, we need it when building the blocks $page['revision_id'] = BackendPagesModel::update($page); // loop blocks foreach ($this->blocksContent as $i => $block) { // add page revision id to blocks $this->blocksContent[$i]['revision_id'] = $page['revision_id']; // validate blocks, only save blocks for valid positions if (!in_array($block['position'], $this->templates[$this->frm->getField('template_id')->getValue()]['data']['names'])) { unset($this->blocksContent[$i]); } } // insert the blocks BackendPagesModel::insertBlocks($this->blocksContent); // trigger an event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $page)); // save tags BackendTagsModel::saveTags($page['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule()); // build cache BackendPagesModel::buildCache(BL::getWorkingLanguage()); // active if ($page['status'] == 'active') { // init var $text = ''; // build search-text foreach ($this->blocksContent as $block) { $text .= ' ' . $block['html']; } // add to search index BackendSearchModel::saveIndex($this->getModule(), $page['id'], array('title' => $page['title'], 'text' => $text)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $page['id'] . '&report=edited&var=' . urlencode($page['title']) . '&highlight=row-' . $page['id']); } elseif ($page['status'] == 'draft') { // everything is saved, so redirect to the edit action $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $page['id'] . '&report=saved-as-draft&var=' . urlencode($page['title']) . '&highlight=row-' . $page['id'] . '&draft=' . $page['revision_id']); } } } }
/** * 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(); $fields = $this->frm->getFields(); // email is present if (!$this->user->isGod()) { if ($fields['email']->isFilled(BL::err('EmailIsRequired'))) { // is this an email-address if ($fields['email']->isEmail(BL::err('EmailIsInvalid'))) { // was this emailaddress deleted before if (BackendUsersModel::emailDeletedBefore($fields['email']->getValue())) { $fields['email']->addError(sprintf(BL::err('EmailWasDeletedBefore'), BackendModel::createURLForAction('undo_delete', null, null, array('email' => $fields['email']->getValue())))); } elseif (BackendUsersModel::existsEmail($fields['email']->getValue(), $this->id)) { $fields['email']->addError(BL::err('EmailAlreadyExists')); } } } } // required fields if ($this->user->isGod() && $fields['email']->getValue() != '' && $this->user->getEmail() != $fields['email']->getValue()) { $fields['email']->addError(BL::err('CantChangeGodsEmail')); } if (!$this->user->isGod()) { $fields['email']->isEmail(BL::err('EmailIsInvalid')); } $fields['nickname']->isFilled(BL::err('NicknameIsRequired')); $fields['name']->isFilled(BL::err('NameIsRequired')); $fields['surname']->isFilled(BL::err('SurnameIsRequired')); $fields['interface_language']->isFilled(BL::err('FieldIsRequired')); $fields['date_format']->isFilled(BL::err('FieldIsRequired')); $fields['time_format']->isFilled(BL::err('FieldIsRequired')); $fields['number_format']->isFilled(BL::err('FieldIsRequired')); $fields['groups']->isFilled(BL::err('FieldIsRequired')); if (isset($fields['new_password']) && $fields['new_password']->isFilled()) { if ($fields['new_password']->getValue() !== $fields['confirm_password']->getValue()) { $fields['confirm_password']->addError(BL::err('ValuesDontMatch')); } } // validate avatar if ($fields['avatar']->isFilled()) { // correct extension if ($fields['avatar']->isAllowedExtension(array('jpg', 'jpeg', 'gif', 'png'), BL::err('JPGGIFAndPNGOnly'))) { // correct mimetype? $fields['avatar']->isAllowedMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'), BL::err('JPGGIFAndPNGOnly')); } } // no errors? if ($this->frm->isCorrect()) { // build user-array $user['id'] = $this->id; if (!$this->user->isGod()) { $user['email'] = $fields['email']->getValue(true); } if (BackendAuthentication::getUser()->getUserId() != $this->record['id']) { $user['active'] = $fields['active']->isChecked() ? 'Y' : 'N'; } // update password (only if filled in) if (isset($fields['new_password']) && $fields['new_password']->isFilled()) { $user['password'] = BackendAuthentication::getEncryptedString($fields['new_password']->getValue(), $this->record['settings']['password_key']); } // build settings-array $settings['nickname'] = $fields['nickname']->getValue(); $settings['name'] = $fields['name']->getValue(); $settings['surname'] = $fields['surname']->getValue(); $settings['interface_language'] = $fields['interface_language']->getValue(); $settings['date_format'] = $fields['date_format']->getValue(); $settings['time_format'] = $fields['time_format']->getValue(); $settings['datetime_format'] = $settings['date_format'] . ' ' . $settings['time_format']; $settings['number_format'] = $fields['number_format']->getValue(); $settings['csv_split_character'] = $fields['csv_split_character']->getValue(); $settings['csv_line_ending'] = $fields['csv_line_ending']->getValue(); $settings['api_access'] = (bool) $fields['api_access']->getChecked(); // get selected groups $groups = $fields['groups']->getChecked(); // init var $newSequence = BackendGroupsModel::getSetting($groups[0], 'dashboard_sequence'); // loop through groups and collect all dashboard widget sequences foreach ($groups as $group) { $sequences[] = BackendGroupsModel::getSetting($group, 'dashboard_sequence'); } // loop through sequences foreach ($sequences as $sequence) { // loop through modules inside a sequence foreach ($sequence as $moduleKey => $module) { // loop through widgets inside a module foreach ($module as $widgetKey => $widget) { // if widget present set true if ($widget['present']) { $newSequence[$moduleKey][$widgetKey]['present'] = true; } } } } // add new sequence to settings $settings['dashboard_sequence'] = $newSequence; // has the user submitted an avatar? if ($fields['avatar']->isFilled()) { // delete old avatar if it isn't the default-image if ($this->record['settings']['avatar'] != 'no-avatar.jpg') { SpoonFile::delete(FRONTEND_FILES_PATH . '/backend_users/avatars/source/' . $this->record['settings']['avatar']); SpoonFile::delete(FRONTEND_FILES_PATH . '/backend_users/avatars/128x128/' . $this->record['settings']['avatar']); SpoonFile::delete(FRONTEND_FILES_PATH . '/backend_users/avatars/64x64/' . $this->record['settings']['avatar']); SpoonFile::delete(FRONTEND_FILES_PATH . '/backend_users/avatars/32x32/' . $this->record['settings']['avatar']); } // create new filename $filename = rand(0, 3) . '_' . $user['id'] . '.' . $fields['avatar']->getExtension(); // add into settings to update $settings['avatar'] = $filename; // resize (128x128) $fields['avatar']->createThumbnail(FRONTEND_FILES_PATH . '/backend_users/avatars/128x128/' . $filename, 128, 128, true, false, 100); // resize (64x64) $fields['avatar']->createThumbnail(FRONTEND_FILES_PATH . '/backend_users/avatars/64x64/' . $filename, 64, 64, true, false, 100); // resize (32x32) $fields['avatar']->createThumbnail(FRONTEND_FILES_PATH . '/backend_users/avatars/32x32/' . $filename, 32, 32, true, false, 100); } // save changes BackendUsersModel::update($user, $settings); // save groups BackendGroupsModel::insertMultipleGroups($this->id, $groups); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $user)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&var=' . $settings['nickname'] . '&highlight=row-' . $user['id']); } } }
/** * Parse the form */ protected function parse() { parent::parse(); // assign to template $this->tpl->assign('item', $this->record); $this->tpl->assign('settings', $this->settings); $this->tpl->assign('godUser', BackendAuthentication::getUser()->isGod()); $this->settingsForm->parse($this->tpl); // assign message if address was not be geocoded if ($this->record['lat'] == null || $this->record['lng'] == null) { $this->tpl->assign('errorMessage', BL::err('AddressCouldNotBeGeocoded')); } }