/** * Load the form */ private function loadForm() { $this->isGod = BackendAuthentication::getUser()->isGod(); $this->frm = new BackendForm('settingsEmail'); // email settings $mailerFrom = $this->get('fork.settings')->get('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'] : '')->setAttribute('type', 'email'); $mailerTo = $this->get('fork.settings')->get('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'] : '')->setAttribute('type', 'email'); $mailerReplyTo = $this->get('fork.settings')->get('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'] : '')->setAttribute('type', 'email'); if ($this->isGod) { $mailerType = $this->get('fork.settings')->get('Core', 'mailer_type', 'mail'); $this->frm->addDropdown('mailer_type', array('mail' => 'PHP\'s mail', 'smtp' => 'SMTP'), $mailerType); // smtp settings $this->frm->addText('smtp_server', $this->get('fork.settings')->get('Core', 'smtp_server', '')); $this->frm->addText('smtp_port', $this->get('fork.settings')->get('Core', 'smtp_port', 25)); $this->frm->addText('smtp_username', $this->get('fork.settings')->get('Core', 'smtp_username', '')); $this->frm->addPassword('smtp_password', $this->get('fork.settings')->get('Core', 'smtp_password', '')); $this->frm->addDropdown('smtp_secure_layer', array('no' => ucfirst(BL::lbl('None')), 'ssl' => 'SSL', 'tls' => 'TLS'), $this->get('fork.settings')->get('Core', 'smtp_secure_layer', 'no')); } $this->tpl->assign('isGod', $this->isGod); }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); $fields = $this->frm->getFields(); // validate fields $fields['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 ? $fields['template']->getValue() : $this->templates[0]; $item['language'] = BL::getWorkingLanguage(); $item['title'] = $fields['title']->getValue(); $item['text'] = $fields['text']->getValue(); $item['hidden'] = $fields['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']); } } }
/** * 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)), $this->get('fork.settings')->get($this->URL->getModule(), 'overview_num_items', 10)); $this->frm->addDropdown('recent_articles_full_number_of_items', array_combine(range(1, 10), range(1, 10)), $this->get('fork.settings')->get($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)), $this->get('fork.settings')->get($this->URL->getModule(), 'recent_articles_list_num_items', 5)); // add fields for spam $this->frm->addCheckbox('spamfilter', $this->get('fork.settings')->get($this->URL->getModule(), 'spamfilter', false)); // no Akismet-key, so we can't enable spam-filter if ($this->get('fork.settings')->get('Core', 'akismet_key') == '') { $this->frm->getField('spamfilter')->setAttribute('disabled', 'disabled'); $this->tpl->assign('noAkismetKey', true); } // add fields for comments $this->frm->addCheckbox('allow_comments', $this->get('fork.settings')->get($this->URL->getModule(), 'allow_comments', false)); $this->frm->addCheckbox('moderation', $this->get('fork.settings')->get($this->URL->getModule(), 'moderation', false)); // add fields for notifications $this->frm->addCheckbox('notify_by_email_on_new_comment_to_moderate', $this->get('fork.settings')->get($this->URL->getModule(), 'notify_by_email_on_new_comment_to_moderate', false)); $this->frm->addCheckbox('notify_by_email_on_new_comment', $this->get('fork.settings')->get($this->URL->getModule(), 'notify_by_email_on_new_comment', false)); // add fields for SEO // @TODO remove this when the api is kicked out $this->frm->addCheckbox('ping_services', $this->get('fork.settings')->get($this->URL->getModule(), 'ping_services', false)); // add fields for RSS $this->frm->addCheckbox('rss_meta', $this->get('fork.settings')->get($this->URL->getModule(), 'rss_meta_' . BL::getWorkingLanguage(), true)); $this->frm->addText('rss_title', $this->get('fork.settings')->get($this->URL->getModule(), 'rss_title_' . BL::getWorkingLanguage())); $this->frm->addTextarea('rss_description', $this->get('fork.settings')->get($this->URL->getModule(), 'rss_description_' . BL::getWorkingLanguage())); // god user? if ($this->isGod) { $this->frm->addCheckbox('show_image_form', $this->get('fork.settings')->get($this->URL->getModule(), 'show_image_form', true)); } }
/** * Load the form */ private function loadForm() { $this->imageIsAllowed = $this->get('fork.settings')->get($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', $this->get('fork.settings')->get($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); }
/** * @param KernelInterface $kernel */ public function __construct(KernelInterface $kernel) { parent::__construct($kernel); // store for later use throughout the application $this->getContainer()->set('navigation', $this); $this->URL = $this->getContainer()->get('url'); // check if navigation cache file exists if (!is_file(self::getCacheDirectory() . 'navigation.php')) { $this->buildCache(); } // check if editor_link_list_LANGUAGE.js cache file exists if (!is_file(FRONTEND_CACHE_PATH . '/Navigation/editor_link_list_' . BackendLanguage::getWorkingLanguage() . '.js')) { BackendPagesModel::buildCache(BackendLanguage::getWorkingLanguage()); } $navigation = array(); // require navigation-file require self::getCacheDirectory() . 'navigation.php'; // load it $this->navigation = (array) $navigation; $this->navigation = $this->addActiveStateToNavigation($this->navigation); // cleanup navigation (not needed for god user) if (!Authentication::getUser()->isGod()) { $this->navigation = $this->cleanup($this->navigation); } }
/** * Output a CSV-file as a download * * @param string $filename The name of the file. * @param array $array The array to convert. * @param array $columns The column names you want to use. * @param array $excludeColumns The columns you want to exclude. */ public static function outputCSV($filename, array $array, array $columns = null, array $excludeColumns = null) { // get settings $splitCharacter = Authentication::getUser()->getSetting('csv_split_character'); $lineEnding = Authentication::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 $charset = BackendModel::getContainer()->getParameter('kernel.charset'); $headers[] = 'Content-type: application/csv; charset=' . $charset; $headers[] = 'Content-Disposition: attachment; filename="' . $filename . '"'; $headers[] = 'Content-Length: ' . strlen($csv); $headers[] = 'Pragma: no-cache'; // overwrite the headers \SpoonHTTP::setHeaders($headers); // output the CSV echo $csv; exit; }
/** * 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', BL::getInterfaceLanguages(), $this->get('fork.settings')->get('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()); // permissions $this->frm->addCheckbox('active', true); $this->frm->addCheckbox('api_access', false); $this->frm->addMultiCheckbox('groups', $groups, $checkedGroups); }
/** * 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 */ public function execute() { parent::execute(); // get parameters $newSequence = \SpoonFilter::getPostValue('new_sequence', null, ''); // validate if ($newSequence == '') { $this->output(self::BAD_REQUEST, null, 'no new_sequence provided'); } else { // convert into array $json = @json_decode($newSequence, true); // validate if ($json === false) { $this->output(self::BAD_REQUEST, null, 'invalid new_sequence provided'); } else { // initialize $userSequence = array(); $hiddenItems = array(); // loop columns foreach ($json as $column => $widgets) { $columnValue = 'left'; if ($column == 1) { $columnValue = 'middle'; } elseif ($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 */ public function execute() { parent::execute(); $this->isGod = BackendAuthentication::getUser()->isGod(); $this->setFilter(); $this->loadForm(); $this->loadDataGrid(); $this->parse(); $this->display(); }
/** * Execute the action */ public function execute() { parent::execute(); $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(), null, 'string'); $name = \SpoonFilter::getPostValue('name', null, null, 'string'); $type = \SpoonFilter::getPostValue('type', BackendModel::getContainer()->get('database')->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 (urlencode($value) != CommonUri::getUrl($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); } }
/** * Copy content blocks * * @param string $from The language code to copy the content blocks from. * @param string $to The language code we want to copy the content blocks to. * * @return array * * @deprecated use the CopyContentBlocksToOtherLocale command */ public static function copy($from, $to) { trigger_error('Backend\\Modules\\ContentBlocks\\Engine::copy is deprecated. Switch the CopyContentBlocksToOtherLocale command instead.', E_USER_DEPRECATED); // get db $db = BackendModel::getContainer()->get('database'); // init variables $contentBlockIds = $oldIds = $newIds = array(); // copy the contentblocks $contentBlocks = (array) $db->getRecords('SELECT * FROM content_blocks WHERE language = ? AND status = "active"', array($from)); // define counter $i = 1; // loop existing content blocks foreach ($contentBlocks as $contentBlock) { // define old id $oldId = $contentBlock['extra_id']; // init new block $newBlock = array(); // build new block $newBlock['id'] = self::getMaximumId() + $i; $newBlock['language'] = $to; $newBlock['created_on'] = BackendModel::getUTCDate(); $newBlock['edited_on'] = BackendModel::getUTCDate(); $newBlock['status'] = $contentBlock['status']; $newBlock['user_id'] = BackendAuthentication::getUser()->getUserId(); $newBlock['template'] = $contentBlock['template']; $newBlock['title'] = $contentBlock['title']; $newBlock['text'] = $contentBlock['text']; $newBlock['hidden'] = $contentBlock['hidden']; // inset content block $newId = self::insert($newBlock); // save ids for later $oldIds[] = $oldId; $newIds[$oldId] = $newId; // redefine counter ++$i; } // get the extra Ids for the content blocks if (!empty($newIds)) { // get content block extra ids $contentBlockExtraIds = (array) $db->getRecords('SELECT revision_id, extra_id FROM content_blocks WHERE revision_id IN (' . implode(',', $newIds) . ')'); // loop new ids foreach ($newIds as $oldId => $newId) { foreach ($contentBlockExtraIds as $extraId) { if ($extraId['revision_id'] == $newId) { $contentBlockIds[$oldId] = $extraId['extra_id']; } } } } // return contentBlockIds return $contentBlockIds; }
/** * Validate the form add image * * @return void */ private function validateForm() { //--Check if the add-image form is submitted if ($this->frm->isSubmitted()) { //--Clean up fields in the form $this->frm->cleanupFields(); //--Get image field $filImage = $this->frm->getField('images'); //--Check if the field is filled in if ($filImage->isFilled()) { //--Image extension and mime type $filImage->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly')); $filImage->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly')); //--Check if there are no errors. $strError = $filImage->getErrors(); if ($strError === null) { //--Get the filename $strFilename = BackendGalleriaModel::checkFilename(substr($filImage->getFilename(), 0, 0 - (strlen($filImage->getExtension()) + 1)), $filImage->getExtension()); //--Fill in the item $item = array(); $item["album_id"] = (int) $this->id; $item["user_id"] = BackendAuthentication::getUser()->getUserId(); $item["language"] = BL::getWorkingLanguage(); $item["filename"] = $strFilename; $item["description"] = ""; $item["publish_on"] = BackendModel::getUTCDate(); $item["hidden"] = "N"; $item["sequence"] = BackendGalleriaModel::getMaximumImageSequence($this->id) + 1; //--the image path $imagePath = FRONTEND_FILES_PATH . '/Galleria/Images'; //--create folders if needed if (!\SpoonDirectory::exists($imagePath . '/Source')) { \SpoonDirectory::create($imagePath . '/Source'); } if (!\SpoonDirectory::exists($imagePath . '/128x128')) { \SpoonDirectory::create($imagePath . '/128x128'); } if (!\SpoonDirectory::exists($imagePath . '/800x')) { \SpoonDirectory::create($imagePath . '/800x'); } //--image provided? if ($filImage->isFilled()) { //--upload the image & generate thumbnails $filImage->generateThumbnails($imagePath, $item["filename"]); } //--Add item to the database BackendGalleriaModel::insert($item); } } } }
/** * Load the datagrid. */ private function loadDataGrid() { // create datagrid with an overview of all active and undeleted users $this->dataGrid = new BackendDataGridDB(BackendUsersModel::QRY_BROWSE, array('N')); // check if this action is allowed if (BackendAuthentication::isAllowedAction('Edit')) { // add column $this->dataGrid->addColumn('nickname', \SpoonFilter::ucfirst(BL::lbl('Nickname')), null, BackendModel::createURLForAction('Edit') . '&id=[id]', BL::lbl('Edit')); // add edit column if (BackendAuthentication::isAllowedAction('Add') || BackendAuthentication::getUser()->isGod()) { $this->dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('Edit') . '&id=[id]'); } } // show the user's nickname $this->dataGrid->setColumnFunction(array('Backend\\Modules\\Users\\Engine\\Model', 'getSetting'), array('[id]', 'nickname'), 'nickname', false); }
/** * Output a CSV-file as a download * * @param string $filename The name of the file. * @param array $array The array to convert. * @param array $columns The column names you want to use. * @param array $excludeColumns The columns you want to exclude. */ public static function outputCSV($filename, array $array, array $columns = null, array $excludeColumns = null) { // get settings $splitCharacter = Authentication::getUser()->getSetting('csv_split_character'); $lineEnding = Authentication::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 $charset = BackendModel::getContainer()->getParameter('kernel.charset'); throw new RedirectException('Return the csv data', new Response($csv, Response::HTTP_OK, ['Content-type' => 'application/csv; charset=' . $charset, 'Content-Disposition' => 'attachment; filename="' . $filename . '"', 'Content-Length' => mb_strlen($csv), 'Pragma' => 'no-cache'])); }
/** * Execute the action */ public function execute() { parent::execute(); $form = $this->createForm(new ContentBlockType($this->get('fork.settings')->get('Core', 'theme', 'core'))); $form->handleRequest($this->get('request')); if (!$form->isValid()) { $this->tpl->assign('form', $form->createView()); $this->parse(); $this->display(); return; } /** @var CreateContentBlock $createContentBlock */ $createContentBlock = $form->getData(); $createContentBlock->userId = Authentication::getUser()->getUserId(); // The command bus will handle the saving of the content block in the database. $this->get('command_bus')->handle($createContentBlock); $this->get('event_dispatcher')->dispatch(ContentBlockCreated::EVENT_NAME, new ContentBlockCreated($createContentBlock->contentBlock)); return $this->redirect(BackendModel::createURLForAction('Index', null, null, ['report' => 'added', 'var' => $createContentBlock->title])); }
/** * @param KernelInterface $kernel */ public function __construct(KernelInterface $kernel) { parent::__construct($kernel); // store for later use throughout the application $this->getContainer()->set('navigation', $this); $this->URL = $this->getContainer()->get('url'); // check if navigation cache file exists if (!is_file(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 (!Authentication::getUser()->isGod()) { $this->navigation = $this->cleanup($this->navigation); } }
/** * Load the datagrid with the drafts */ 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 column functions $this->dgDrafts->setColumnFunction(array(new BackendDataGridFunctions(), 'getUser'), array('[user_id]'), 'user_id', true); $this->dgDrafts->setColumnFunction(array(new BackendDataGridFunctions(), 'getLongDate'), array('[edited_on]'), 'edited_on'); // set headers $this->dgDrafts->setHeaderLabels(array('user_id' => \SpoonFilter::ucfirst(BL::lbl('By')), 'edited_on' => \SpoonFilter::ucfirst(BL::lbl('LastEdited')))); // check if allowed to edit if (BackendAuthentication::isAllowedAction('Edit', $this->getModule())) { // set column URLs $this->dgDrafts->setColumnURL('title', BackendModel::createURLForAction('Edit') . '&id=[id]&draft=[revision_id]'); // add edit column $this->dgDrafts->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('Edit') . '&id=[id]&draft=[revision_id]', BL::lbl('Edit')); } }
/** * load the form */ private function loadForm() { // check if user is almighty $this->isGod = BackendAuthentication::getUser()->isGod(); // create form instance $this->frm = new BackendForm('settings'); // fetch module settings $this->settings = BackendModel::getModuleSettings('Mailchimp'); // connect to mailchimp and get the lists $mailchimp = $this->getContainer()->get('zfr_mail_chimp')->getClient(); $lists = $mailchimp->getLists(); // loop the lists and add to key value array $listItems = array(); if ($lists['total'] > 0) { foreach ($lists['data'] as $l) { $listItems[$l['id']] = $l['name']; } } // add the formfields $this->frm->addDropdown('list', $listItems, $this->settings['activeList']); }
/** * 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'); } }
/** * 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()) != CommonUri::getUrl($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); } } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $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'); $emailAddresses = (array) explode(',', $txtEmail->getValue()); // validate fields $txtName->isFilled(BL::getError('NameIsRequired')); $txtSuccessMessage->isFilled(BL::getError('SuccessMessageIsRequired')); if ($ddmMethod->isFilled(BL::getError('NameIsRequired')) && $ddmMethod->getValue() == 'database_email') { $error = false; // check the addresses foreach ($emailAddresses as $address) { $address = trim($address); if (!\SpoonFilter::isEmail($address)) { $error = true; break; } } // add error if ($error) { $txtEmail->addError(BL::getError('EmailIsInvalid')); } } // 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())) { // unique identifier $txtIdentifier->setError(BL::getError('UniqueIdentifier')); } } 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'] = $ddmMethod->getValue() == 'database_email' ? serialize($emailAddresses) : 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(), true); // create submit button $field['form_id'] = $id; $field['type'] = 'submit'; $field['settings'] = serialize(array('values' => \SpoonFilter::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'); } } }
private function redirectToAllowedModuleAndAction() { $allowedModule = $this->getAllowedModule(); $allowedAction = $this->getAllowedAction($allowedModule); $allowedModuleActionUrl = $allowedModule ? BackendModel::createUrlForAction($allowedAction, $allowedModule) : BackendModel::createUrlForAction('Index', 'Authentication'); $userEmail = BackendAuthentication::getUser()->getEmail(); $this->getContainer()->get('logger')->info("Redirecting user '{$userEmail}' to {$allowedModuleActionUrl}."); $this->redirect($this->getParameter('querystring', 'string', $allowedModuleActionUrl)); }
/** * Parse the data */ protected function parse() { parent::parse(); $this->tpl->assign('godUser', BackendAuthentication::getUser()->isGod()); }
/** * Parse the settings for the authenticated user */ private function parseAuthenticatedUser() { // check if the current user is authenticated if (Authentication::getUser()->isAuthenticated()) { // show stuff that only should be visible if authenticated $this->assign('isAuthenticated', true); // get authenticated user-settings $settings = (array) Authentication::getUser()->getSettings(); foreach ($settings as $key => $setting) { // redefine setting $setting = $setting === null ? '' : $setting; // assign setting $this->assign('authenticatedUser' . \SpoonFilter::toCamelCase($key), $setting); } // check if this action is allowed if (Authentication::isAllowedAction('Edit', 'Users')) { // assign special vars $this->assign('authenticatedUserEditUrl', Model::createURLForAction('Edit', 'Users', null, array('id' => Authentication::getUser()->getUserId()))); } } }
/** * Parse the JS-files */ public function parseJS() { $jsFiles = array(); $existingJSFiles = $this->getJSFiles(); // if there aren't any JS-files added we don't need to do something if (!empty($existingJSFiles)) { // some files should be cached, even if we don't want cached (mostly libraries) $ignoreCache = array('/src/Backend/Core/Js/jquery/jquery.js', '/src/Backend/Core/Js/jquery/jquery.ui.js', '/src/Backend/Core/Js/ckeditor/jquery.ui.dialog.patch.js', '/src/Backend/Core/Js/jquery/jquery.tools.js', '/src/Backend/Core/Js/jquery/jquery.backend.js', '/src/Backend/Core/Js/ckeditor/ckeditor.js', '/src/Backend/Core/Js/ckeditor/adapters/jquery.js', '/src/Backend/Core/Js/ckfinder/ckfinder.js'); foreach ($existingJSFiles as $file) { // some files shouldn't be uncachable if (in_array($file['file'], $ignoreCache) || $file['add_timestamp'] === false) { $file = array('file' => $file['file']); } else { if (substr($file['file'], 0, 11) == '/frontend/js') { $file = array('file' => $file['file'] . '&m=' . time()); } else { $modifiedTime = strpos($file['file'], '?') !== false ? '&m=' . LAST_MODIFIED_TIME : '?m=' . LAST_MODIFIED_TIME; $file = array('file' => $file['file'] . $modifiedTime); } } // add $jsFiles[] = $file; } } // assign JS-files $this->tpl->assign('jsFiles', $jsFiles); // fetch preferred interface language if (Authentication::getUser()->isAuthenticated()) { $interfaceLanguage = (string) Authentication::getUser()->getSetting('interface_language'); } else { $interfaceLanguage = Language::getInterfaceLanguage(); } // some default stuff $this->jsData['debug'] = $this->getContainer()->getParameter('kernel.debug'); $this->jsData['site']['domain'] = SITE_DOMAIN; $this->jsData['editor']['language'] = $interfaceLanguage; $this->jsData['interface_language'] = $interfaceLanguage; // is the user object filled? if (Authentication::getUser()->isAuthenticated()) { $this->jsData['editor']['language'] = (string) Authentication::getUser()->getSetting('interface_language'); } // CKeditor has support for simplified Chinese, but the language is called zh-cn instead of zn if ($this->jsData['editor']['language'] == 'zh') { $this->jsData['editor']['language'] = 'zh-cn'; } // theme if ($this->get('fork.settings')->get('Core', 'theme') !== null) { $this->jsData['theme']['theme'] = $this->get('fork.settings')->get('Core', 'theme'); $this->jsData['theme']['path'] = FRONTEND_PATH . '/Themes/' . $this->get('fork.settings')->get('Core', 'theme'); $this->jsData['theme']['has_css'] = is_file(FRONTEND_PATH . '/Themes/' . $this->get('fork.settings')->get('Core', 'theme') . '/Core/Layout/Css/screen.css'); $this->jsData['theme']['has_editor_css'] = is_file(FRONTEND_PATH . '/Themes/' . $this->get('fork.settings')->get('Core', 'theme') . '/Core/Layout/Css/editor_content.css'); } // encode and add $jsData = json_encode($this->jsData); $this->tpl->assign('jsData', 'var jsData = ' . $jsData . ';' . "\n"); }
/** * Set the locale */ private function setLocale() { $default = $this->get('fork.settings')->get('Core', 'default_interface_language'); $locale = $default; $possibleLocale = array_keys(BackendLanguage::getInterfaceLanguages()); // is the user authenticated if (Authentication::getUser()->isAuthenticated()) { $locale = Authentication::getUser()->getSetting('interface_language', $default); } elseif (CommonCookie::exists('interface_language')) { // no authenticated user, but available from a cookie $locale = CommonCookie::get('interface_language'); } // validate if the requested locale is possible if (!in_array($locale, $possibleLocale)) { $locale = $default; } BackendLanguage::setLocale($locale); }
/** * Do authentication stuff * This method could end the script by throwing an exception */ private function validateLogin() { // check if the user is logged on, if not he shouldn't load any JS-file if (!Authentication::isLoggedIn()) { throw new Exception('Not logged in.'); } // set interface language Language::setLocale(Authentication::getUser()->getSetting('interface_language')); }
/** * Load the data */ private function loadData() { $modules = BackendModel::getModules(); $userSequence = BackendAuthentication::getUser()->getSetting('dashboard_sequence'); $fs = new Filesystem(); // user sequence does not exist? if (!isset($userSequence)) { // get group ID of user $groupId = BackendAuthentication::getUser()->getGroupId(); // get group preset $userSequence = BackendGroupsModel::getSetting($groupId, 'dashboard_sequence'); } // loop all modules foreach ($modules as $module) { // build pathName $pathName = BACKEND_MODULES_PATH . '/' . $module; // you have sufficient rights? if (BackendAuthentication::isAllowedModule($module) && $fs->exists($pathName . '/Widgets')) { $finder = new Finder(); $finder->name('*.php'); // loop widgets foreach ($finder->files()->in($pathName . '/Widgets') as $file) { /** @ver $file \SplFileInfo */ $widgetName = $file->getBaseName('.php'); $className = 'Backend\\Modules\\' . $module . '\\Widgets\\' . $widgetName; if ($module == 'Core') { $className = 'Backend\\Core\\Widgets\\' . $widgetName; } if (!class_exists($className)) { throw new BackendException('The widgetfile ' . $className . ' could not be found.'); } // present? $present = isset($userSequence[$module][$widgetName]['present']) ? $userSequence[$module][$widgetName]['present'] : false; // if not present, continue if (!$present) { continue; } // create instance /** @var $instance BackendBaseWidget */ $instance = new $className($this->getKernel()); // has rights if (!$instance->isAllowed()) { continue; } // hidden? $hidden = isset($userSequence[$module][$widgetName]['hidden']) ? $userSequence[$module][$widgetName]['hidden'] : false; // execute instance if it is not hidden if (!$hidden) { $instance->execute(); } // user sequence provided? $column = isset($userSequence[$module][$widgetName]['column']) ? $userSequence[$module][$widgetName]['column'] : $instance->getColumn(); $position = isset($userSequence[$module][$widgetName]['position']) ? $userSequence[$module][$widgetName]['position'] : $instance->getPosition(); $title = \SpoonFilter::ucfirst(BL::lbl(\SpoonFilter::toCamelCase($module))) . ': ' . BL::lbl(\SpoonFilter::toCamelCase($widgetName)); $templatePath = $instance->getTemplatePath(); // reset template path if ($templatePath == null) { $templatePath = BACKEND_PATH . '/Modules/' . $module . '/Layout/Widgets/' . $widgetName . '.tpl'; } // build item $item = array('template' => $templatePath, 'module' => $module, 'widget' => $widgetName, 'title' => $title, 'hidden' => $hidden); // add on new position if no position is set or if the position is already used if ($position === null || isset($this->widgets[$column][$position])) { $this->widgets[$column][] = $item; } else { // add on requested position $this->widgets[$column][$position] = $item; } } } } // sort the widgets foreach ($this->widgets as &$column) { ksort($column); } }