/** * 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']); } } }
/** * Execute the action */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // action to execute $id = SpoonFilter::getGetValue('id', null, 0); // no id's provided if (empty($id) || !BackendMailmotorModel::existsMailing($id)) { $this->redirect(BackendModel::createURLForAction('index') . '&error=mailing-does-not-exist'); } else { // get the mailing and reset some fields $mailing = BackendMailmotorModel::getMailing($id); $mailing['status'] = 'concept'; $mailing['send_on'] = null; $mailing['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); $mailing['edited_on'] = $mailing['created_on']; $mailing['data'] = serialize($mailing['data']); unset($mailing['recipients'], $mailing['id'], $mailing['cm_id'], $mailing['send_on_raw']); // set groups $groups = $mailing['groups']; unset($mailing['groups']); // create a new mailing based on the old one $newId = BackendMailmotorModel::insertMailing($mailing); // update groups for this mailing BackendMailmotorModel::updateGroupsForMailing($newId, $groups); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_copy_mailing', array('item' => $mailing)); } // redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=mailing-copied&var=' . $mailing['name']); }
/** * Builds the query for this datagrid * * @return array An array with two arguments containing the query and its parameters. */ private function buildQuery() { $parameters = array($this->id); // start query, as you can see this query is build in the wrong place, because of the filter it is a special case // wherin we allow the query to be in the actionfile itself $query = 'SELECT i.id, UNIX_TIMESTAMP(i.sent_on) AS sent_on FROM forms_data AS i WHERE i.form_id = ?'; // add start date if ($this->filter['start_date'] !== '') { // explode date parts $chunks = explode('/', $this->filter['start_date']); // add condition $query .= ' AND i.sent_on >= ?'; $parameters[] = BackendModel::getUTCDate(null, gmmktime(23, 59, 59, $chunks[1], $chunks[0], $chunks[2])); } // add end date if ($this->filter['end_date'] !== '') { // explode date parts $chunks = explode('/', $this->filter['end_date']); // add condition $query .= ' AND i.sent_on <= ?'; $parameters[] = BackendModel::getUTCDate(null, gmmktime(23, 59, 59, $chunks[1], $chunks[0], $chunks[2])); } // new query return array($query, $parameters); }
/** * 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']); } } }
/** * Execute the action */ public function execute() { parent::execute(); // get parameters $mailingId = SpoonFilter::getPostValue('mailing_id', null, '', 'int'); $sendOnDate = SpoonFilter::getPostValue('send_on_date', null, BackendModel::getUTCDate('d/m/Y')); $sendOnTime = SpoonFilter::getPostValue('send_on_time', null, BackendModel::getUTCDate('H:i')); $messageDate = $sendOnDate; // validate mailing ID if ($mailingId == '') { $this->output(self::BAD_REQUEST, null, 'Provide a valid mailing ID'); } if ($sendOnDate == '' || $sendOnTime == '') { $this->output(self::BAD_REQUEST, null, 'Provide a valid send date date provided'); } // record is empty if (!BackendMailmotorModel::existsMailing($mailingId)) { $this->output(self::BAD_REQUEST, null, BL::err('MailingDoesNotExist', 'mailmotor')); } // reverse the date and make it a proper $explodedDate = explode('/', $sendOnDate); $sendOnDate = $explodedDate[2] . '-' . $explodedDate[1] . '-' . $explodedDate[0]; // calc full send timestamp $sendTimestamp = strtotime($sendOnDate . ' ' . $sendOnTime); // build data $item['id'] = $mailingId; $item['send_on'] = BackendModel::getUTCDate('Y-m-d H:i:s', $sendTimestamp); $item['edited_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // update mailing BackendMailmotorModel::updateMailing($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit_mailing_step4', array('item' => $item)); // output $this->output(self::OK, array('mailing_id' => $mailingId, 'timestamp' => $sendTimestamp), sprintf(BL::msg('SendOn', $this->getModule()), $messageDate, $sendOnTime)); }
/** * 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 $id = SpoonFilter::getPostValue('id', null, '', 'int'); $name = trim(SpoonFilter::getPostValue('value', null, '', 'string')); // validate if ($name == '') { $this->output(self::BAD_REQUEST, null, 'no name provided'); } // get existing id $existingId = BackendMailmotorModel::getCampaignId($name); // existing campaign if ($existingId !== 0 && $id !== $existingId) { $this->output(self::ERROR, array('id' => $existingId, 'error' => true), BL::err('CampaignExists', $this->getModule())); } // build array $item = array(); $item['id'] = $id; $item['name'] = $name; $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // get page $rows = BackendMailmotorModel::updateCampaign($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'edited_campaign', array('item' => $item)); // output if ($rows !== 0) { $this->output(self::OK, array('id' => $id), BL::msg('CampaignEdited', $this->getModule())); } else { $this->output(self::ERROR, null, BL::err('CampaignNotEdited', $this->getModule())); } }
/** * 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(); // shorten fields $txtName = $this->frm->getField('name'); $rbtDefaultForLanguage = $this->frm->getField('default'); // validate fields if ($txtName->isFilled(BL::err('NameIsRequired'))) { // check if the group exists by name if (BackendMailmotorModel::existsGroupByName($txtName->getValue())) { $txtName->addError(BL::err('GroupAlreadyExists')); } } // no errors? if ($this->frm->isCorrect()) { // build item $item['name'] = $txtName->getValue(); $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); $item['language'] = $rbtDefaultForLanguage->getValue() === '0' ? null : $rbtDefaultForLanguage->getValue(); $item['is_default'] = $rbtDefaultForLanguage->getChecked() ? 'Y' : 'N'; // insert the item $item['id'] = BackendMailmotorCMHelper::insertGroup($item); // check if all default groups were set BackendMailmotorModel::checkDefaultGroups(); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_group', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('groups') . '&report=added&var=' . urlencode($item['name']) . '&highlight=id-' . $item['id']); } } }
/** * 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); } }
/** * Create the XML based on the locale items. * * @return void */ private function createXML() { // create XML $xmlOutput = BackendLocaleModel::createXMLForExport($this->locale); // xml headers $headers[] = 'Content-Disposition: attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"'; $headers[] = 'Content-Type: application/octet-stream;charset=utf-8'; $headers[] = 'Content-Length: ' . strlen($xmlOutput); // set headers SpoonHTTP::setHeaders($headers); // output XML echo $xmlOutput; // stop script exit; }
/** * Execute the action. * * @return void */ public function execute() { // call parent, this will probably add some general CSS/JS or other required files parent::execute(); // action to execute $action = SpoonFilter::getGetValue('action', array('addToGroup', 'delete'), ''); $ids = isset($_GET['id']) ? (array) $_GET['id'] : array(); $newGroupId = SpoonFilter::getGetValue('newGroup', array_keys(BackendProfilesModel::getGroups()), ''); // at least one id if (!empty($ids)) { // delete the given profiles if ($action === 'delete') { BackendProfilesModel::delete($ids); $report = 'deleted'; } elseif ($action === 'addToGroup') { // for which we need a group of course if ($newGroupId != '') { // set new status foreach ($ids as $id) { // profile must exist if (BackendProfilesModel::exists($id)) { // make sure the user is not already part of this group without an expiration date foreach (BackendProfilesModel::getProfileGroups($id) as $existingGroup) { // if he is, skip to the next user if ($existingGroup['group_id'] === $newGroupId) { continue 2; } } // OK, it's safe to add the user to this group BackendProfilesModel::insertProfileGroup(array('profile_id' => $id, 'group_id' => $newGroupId, 'starts_on' => BackendModel::getUTCDate())); } } // report $report = 'added-to-group'; } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=no-group-selected'); } } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=unknown-action'); } // report $report = (count($ids) > 1 ? 'profiles-' : 'profile-') . $report; // redirect $this->redirect(BackendModel::createURLForAction('index', null, null, array('offset' => SpoonFilter::getGetValue('offset', null, ''), 'order' => SpoonFilter::getGetValue('order', null, ''), 'sort' => SpoonFilter::getGetValue('sort', null, ''), 'email' => SpoonFilter::getGetValue('email', null, ''), 'status' => SpoonFilter::getGetValue('status', null, ''), 'group' => SpoonFilter::getGetValue('group', null, ''))) . '&report=' . $report); } else { $this->redirect(BackendModel::createURLForAction('index') . '&error=no-profiles-selected'); } }
/** * Parse the keywords datagrid */ private function parseKeywords() { $results = BackendAnalyticsModel::getRecentKeywords(); if (!empty($results)) { $dataGrid = new BackendDataGridArray($results); $dataGrid->setPaging(false); $dataGrid->setColumnsHidden('id', 'date'); // parse the datagrid $this->tpl->assign('dgAnalyticsKeywords', $dataGrid->getContent()); } // get date $date = isset($results[0]['date']) ? substr($results[0]['date'], 0, 10) : date('Y-m-d'); $timestamp = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2), substr($date, 0, 4)); // assign date label $this->tpl->assign('analyticsTrafficSourcesDate', $date != date('Y-m-d') ? BackendModel::getUTCDate('d-m', $timestamp) : BL::lbl('Today')); }
/** * 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(); // no errors? if ($this->frm->isCorrect()) { // the total amount of subscribers $subscribersTotal = 0; // loop all groups foreach ($this->externalGroups as $group) { // insert them in our database $groupID = BackendModel::getDB(true)->insert('mailmotor_groups', array('name' => $group['name'], 'custom_fields' => $group['custom_fields'], 'created_on' => BackendModel::getUTCDate())); // insert the CM ID BackendMailmotorCMHelper::insertCampaignMonitorID('list', $group['id'], $groupID); // continue looping if this group has no subscribers if (empty($group['subscribers'])) { continue; } // add this groups subscribers amount to the total $subscribersTotal += $group['subscribers_amount']; // loop the subscribers for this group, and import them foreach ($group['subscribers'] as $subscriber) { // build new subscriber record $item = array(); $item['email'] = $subscriber['email']; $item['source'] = 'import'; $item['created_on'] = $subscriber['date']; // add an additional custom field 'name', if it was set in the subscriber record if (!empty($subscriber['name'])) { $subscriber['custom_fields']['Name'] = $subscriber['name']; } // save the subscriber in our database, and subscribe it to this group BackendMailmotorModel::saveAddress($item, $groupID, !empty($subscriber['custom_fields']) ? $subscriber['custom_fields'] : null); } } // at this point, groups are set BackendModel::setModuleSetting($this->getModule(), 'cm_groups_set', true); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_import_groups'); // redirect to the index $this->redirect(BackendModel::createURLForAction('index', $this->getModule()) . '&report=groups-imported&var[]=' . count($this->externalGroups) . '&var[]=' . $subscribersTotal); } } }
/** * 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(); // validate fields $this->frm->getField('email')->isFilled(BL::err('EmailIsRequired')); // get addresses $addresses = (array) explode(',', $this->frm->getField('email')->getValue()); // loop addresses foreach ($addresses as $email) { // validate email if (!SpoonFilter::isEmail(trim($email))) { // add error if needed $this->frm->getField('email')->addError(BL::err('ContainsInvalidEmail')); // stop looking break; } } $this->frm->getField('groups')->isFilled(BL::err('ChooseAtLeastOneGroup')); // no errors? if ($this->frm->isCorrect()) { // build item $item = $this->frm->getValues(); $item['source'] = BL::lbl('Manual'); $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // loop the groups foreach ($item['groups'] as $group) { foreach ($addresses as $email) { BackendMailmotorCMHelper::subscribe(trim($email), $group); } } // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_address', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('addresses') . (!empty($this->groupId) ? '&group_id=' . $this->groupId : '') . '&report=added'); } } }
/** * 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(); // get fields $ddmGroup = $this->frm->getField('group'); $txtExpirationDate = $this->frm->getField('expiration_date'); $txtExpirationTime = $this->frm->getField('expiration_time'); // fields filled? $ddmGroup->isFilled(BL::getError('FieldIsRequired')); if ($txtExpirationDate->isFilled()) { $txtExpirationDate->isValid(BL::getError('DateIsInvalid')); } if ($txtExpirationTime->isFilled()) { $txtExpirationTime->isValid(BL::getError('TimeIsInvalid')); } // no errors? if ($this->frm->isCorrect()) { // build item $values['profile_id'] = $this->id; $values['group_id'] = $ddmGroup->getSelected(); $values['starts_on'] = BackendModel::getUTCDate(); // only format date if not empty if ($txtExpirationDate->isFilled() && $txtExpirationTime->isFilled()) { // format date $values['expires_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($txtExpirationDate, $txtExpirationTime)); } // insert values $id = BackendProfilesModel::insertProfileGroup($values); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_profile_add_to_group', array('item' => $values)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $values['profile_id'] . '&report=membership-added&highlight=row-' . $id . '#tabGroups'); } } }
/** * 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(); // shorten fields $txtName = $this->frm->getField('name'); // validate fields $txtName->isFilled(BL::err('NameIsRequired')); // no errors? if ($this->frm->isCorrect()) { // build item $item['name'] = $txtName->getValue(); $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // insert the item $item['id'] = BackendMailmotorModel::insertCampaign($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_campaign', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('campaigns') . '&report=added&var=' . urlencode($item['name']) . '&highlight=id-' . $item['id']); } } }
/** * 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); } } }
/** * Get all queued mail ids * * @return array */ public static function getQueuedMailIds() { return (array) BackendModel::getDB()->getColumn('SELECT e.id FROM emails AS e WHERE e.send_on < ? OR e.send_on IS NULL', array(BackendModel::getUTCDate())); }
/** * 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 fields $txtName = $this->frm->getField('name'); $txtFromName = $this->frm->getField('from_name'); $txtFromEmail = $this->frm->getField('from_email'); $txtReplyToEmail = $this->frm->getField('reply_to_email'); $chkGroups = $this->frm->getField('groups'); $rbtLanguages = $this->frm->getField('languages'); // validate fields if ($txtName->isFilled(BL::err('NameIsRequired'))) { if (BackendMailmotorModel::existsMailingByName($txtName->getValue())) { $txtName->addError(BL::err('MailingAlreadyExists')); } } $txtFromName->isFilled(BL::err('NameIsRequired')); $txtFromEmail->isFilled(BL::err('EmailIsRequired')); $txtReplyToEmail->isFilled(BL::err('EmailIsRequired')); // set form values $values = $this->frm->getValues(); // check if at least one recipient group is chosen if (empty($values['groups'])) { $chkGroups->addError(BL::err('ChooseAtLeastOneGroup')); } else { // fetch the recipients for these groups $recipients = BackendMailmotorModel::getAddressesByGroupID($values['groups']); // if no recipients were found, throw an error if (empty($recipients)) { $chkGroups->addError(BL::err('GroupsNoRecipients')); } } // check if at least one language is chosen if (empty($values['languages'])) { $rbtLanguages->isFilled(BL::err('FieldIsRequired')); } // no errors? if ($this->frm->isCorrect()) { // set values $item['name'] = $txtName->getValue(); $item['from_name'] = $txtFromName->getValue(); $item['from_email'] = $txtFromEmail->getValue(); $item['reply_to_email'] = $txtReplyToEmail->getValue(); $item['language'] = $rbtLanguages->getValue(); $item['status'] = 'concept'; $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); $item['edited_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); if (!empty($values['campaign'])) { $item['campaign_id'] = $this->frm->getField('campaign')->getValue(); } // insert the concept $item['id'] = BackendMailmotorModel::insertMailing($item); // update the groups for this mailing BackendMailmotorModel::updateGroupsForMailing($item['id'], $values['groups']); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add_mailing_step1', array('item' => $item)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $item['id'] . '&step=2'); } } }
/** * 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()) { // get the status $status = SpoonFilter::getPostValue('status', array('active', 'draft'), 'active'); // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid')); $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid')); $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired')); // validate meta $this->meta->validate(); // no errors? if ($this->frm->isCorrect()) { // build item $item['id'] = $this->id; $item['revision_id'] = $this->record['revision_id']; // this is used to let our model know the status (active, archive, draft) of the edited item $item['meta_id'] = $this->meta->save(); $item['category_id'] = (int) $this->frm->getField('category_id')->getValue(); $item['user_id'] = $this->frm->getField('user_id')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['title'] = $this->frm->getField('title')->getValue(); $item['introduction'] = $this->frm->getField('introduction')->getValue(); $item['text'] = $this->frm->getField('text')->getValue(); $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time'))); $item['edited_on'] = BackendModel::getUTCDate(); $item['hidden'] = $this->frm->getField('hidden')->getValue(); $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N'; $item['status'] = $status; if ($this->imageIsAllowed) { $item['image'] = $this->record['image']; // the image path $imagePath = FRONTEND_FILES_PATH . '/blog/images'; // if the image should be deleted if ($this->frm->getField('delete_image')->isChecked()) { // delete the image SpoonFile::delete($imagePath . '/source/' . $item['image']); // reset the name $item['image'] = null; } // new image given? if ($this->frm->getField('image')->isFilled()) { // delete the old image SpoonFile::delete($imagePath . '/source/' . $this->record['image']); // build the image name $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension(); // upload the image $this->frm->getField('image')->moveFile($imagePath . '/source/' . $item['image']); } elseif ($item['image'] != null) { // get the old file extension $imageExtension = SpoonFile::getExtension($imagePath . '/source/' . $item['image']); // get the new image name $newName = $this->meta->getURL() . '.' . $imageExtension; // only change the name if there is a difference if ($newName != $item['image']) { // move the old file to the new name SpoonFile::move($imagePath . '/source/' . $item['image'], $imagePath . '/source/' . $newName); // assign the new name to the database $item['image'] = $newName; } } } else { $item['image'] = null; } // update the item $item['revision_id'] = BackendBlogModel::update($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // recalculate comment count so the new revision has the correct count BackendBlogModel::reCalculateCommentCount(array($this->id)); // save the tags BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule()); // active if ($item['status'] == 'active') { // edit search index BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text'])); // ping if (BackendModel::getModuleSetting($this->URL->getModule(), 'ping_services', false)) { BackendModel::ping(SITE_URL . BackendModel::getURLForBlock($this->URL->getModule(), 'detail') . '/' . $this->meta->getURL()); } // build URL $redirectUrl = BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($item['title']) . '&id=' . $this->id . '&highlight=row-' . $item['revision_id']; } elseif ($item['status'] == 'draft') { // everything is saved, so redirect to the edit action $redirectUrl = BackendModel::createURLForAction('edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id']; } // append to redirect URL if ($this->categoryId != null) { $redirectUrl .= '&category=' . $this->categoryId; } // everything is saved, so redirect to the overview $this->redirect($redirectUrl); } } }
/** * Updates the groups for a given email address * * @param string $email The emailaddress to update. * @param mixed $groupIds The ids of the groups. */ public static function updateGroups($email, $groupIds) { $db = BackendModel::getDB(true); // stop here if groups are empty if (empty($groupIds)) { return false; } // check if $groupIds is an array or not, make it one if it isn't $groupIds = (array) $groupIds; // insert record(s) foreach ($groupIds as $id) { // set variables $variables = array(); $variables['email'] = $email; $variables['group_id'] = $id; $variables['status'] = 'subscribed'; $variables['subscribed_on'] = BackendModel::getUTCDate('Y-m-d H:i:s'); // update $db->insert('mailmotor_addresses_groups', $variables); } }
/** * 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(); // get fields $txtEmail = $this->frm->getField('email'); $txtDisplayName = $this->frm->getField('display_name'); $txtPassword = $this->frm->getField('password'); $txtFirstName = $this->frm->getField('first_name'); $txtLastName = $this->frm->getField('last_name'); $txtCity = $this->frm->getField('city'); $ddmGender = $this->frm->getField('gender'); $ddmDay = $this->frm->getField('day'); $ddmMonth = $this->frm->getField('month'); $ddmYear = $this->frm->getField('year'); $ddmCountry = $this->frm->getField('country'); // email filled in? if ($txtEmail->isFilled(BL::getError('EmailIsRequired'))) { // valid email? if ($txtEmail->isEmail(BL::getError('EmailIsInvalid'))) { // email already exists? if (BackendProfilesModel::existsByEmail($txtEmail->getValue())) { // set error $txtEmail->addError(BL::getError('EmailExists')); } } } // display name filled in? if ($txtDisplayName->isFilled(BL::getError('DisplayNameIsRequired'))) { // display name already exists? if (BackendProfilesModel::existsDisplayName($txtDisplayName->getValue())) { // set error $txtDisplayName->addError(BL::getError('DisplayNameExists')); } } // one of the bday fields are filled in if ($ddmDay->isFilled() || $ddmMonth->isFilled() || $ddmYear->isFilled()) { // valid date? if (!checkdate($ddmMonth->getValue(), $ddmDay->getValue(), $ddmYear->getValue())) { // set error $ddmYear->addError(BL::getError('DateIsInvalid')); } } // no errors? if ($this->frm->isCorrect()) { // build item $values = array('email' => $txtEmail->getValue(), 'registered_on' => BackendModel::getUTCDate(), 'display_name' => $txtDisplayName->getValue(), 'url' => BackendProfilesModel::getUrl($txtDisplayName->getValue())); $this->id = BackendProfilesModel::insert($values); // new password filled in? if ($txtPassword->isFilled()) { // get new salt $salt = BackendProfilesModel::getRandomString(); // update salt BackendProfilesModel::setSetting($this->id, 'salt', $salt); // build password $values['password'] = BackendProfilesModel::getEncryptedString($txtPassword->getValue(), $salt); } // update values BackendProfilesModel::update($this->id, $values); // bday is filled in if ($ddmYear->isFilled()) { // mysql format $birthDate = $ddmYear->getValue() . '-'; $birthDate .= str_pad($ddmMonth->getValue(), 2, '0', STR_PAD_LEFT) . '-'; $birthDate .= str_pad($ddmDay->getValue(), 2, '0', STR_PAD_LEFT); } else { $birthDate = null; } // update settings BackendProfilesModel::setSetting($this->id, 'first_name', $txtFirstName->getValue()); BackendProfilesModel::setSetting($this->id, 'last_name', $txtLastName->getValue()); BackendProfilesModel::setSetting($this->id, 'gender', $ddmGender->getValue()); BackendProfilesModel::setSetting($this->id, 'birth_date', $birthDate); BackendProfilesModel::setSetting($this->id, 'city', $txtCity->getValue()); BackendProfilesModel::setSetting($this->id, 'country', $ddmCountry->getValue()); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $values)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $this->id); } } }
/** * 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(), $this->id)) { $txtIdentifier->setError(BL::getError('UniqueIdentifier')); } } if ($this->frm->isCorrect()) { // build array $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['edited_on'] = BackendModel::getUTCDate(); // insert the item $id = (int) BackendFormBuilderModel::update($this->id, $values); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $values)); // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($values['name']) . '&highlight=row-' . $id); } } }
/** * Import a locale XML file. * * @param SimpleXMLElement $xml The locale XML. * @param bool[optional] $overwriteConflicts Should we overwrite when there is a conflict? * @param array[optional] $frontendLanguages The frontend languages to install locale for. * @param array[optional] $backendLanguages The backend languages to install locale for. * @param int[optional] $userId Id of the user these translations should be inserted for. * @param int[optional] $date The date the translation has been inserted. * @return array The import statistics */ public static function importXML(SimpleXMLElement $xml, $overwriteConflicts = false, $frontendLanguages = null, $backendLanguages = null, $userId = null, $date = null) { $overwriteConflicts = (bool) $overwriteConflicts; $statistics = array('total' => 0, 'imported' => 0); // set defaults if necessary // we can't simply use these right away, because this function is also calles by the installer, which does not have Backend-functions if ($frontendLanguages === null) { $frontendLanguages = array_keys(BL::getWorkingLanguages()); } if ($backendLanguages === null) { $backendLanguages = array_keys(BL::getInterfaceLanguages()); } if ($userId === null) { $userId = BackendAuthentication::getUser()->getUserId(); } if ($date === null) { $date = BackendModel::getUTCDate(); } // get database instance (don't use BackendModel::getDB() here because this function will also be called during install) $db = Spoon::get('database'); // possible values $possibleApplications = array('frontend', 'backend'); $possibleModules = (array) $db->getColumn('SELECT m.name FROM modules AS m'); // types $typesShort = (array) $db->getEnumValues('locale', 'type'); foreach ($typesShort as $type) { $possibleTypes[$type] = self::getTypeName($type); } // install English translations anyhow, they're fallback $possibleLanguages = array('frontend' => array_unique(array_merge(array('en'), $frontendLanguages)), 'backend' => array_unique(array_merge(array('en'), $backendLanguages))); // current locale items (used to check for conflicts) $currentLocale = (array) $db->getColumn('SELECT CONCAT(application, module, type, language, name) FROM locale'); // applications foreach ($xml as $application => $modules) { // application does not exist if (!in_array($application, $possibleApplications)) { continue; } // modules foreach ($modules as $module => $items) { // module does not exist if (!in_array($module, $possibleModules)) { continue; } // items foreach ($items as $item) { // attributes $attributes = $item->attributes(); $type = SpoonFilter::getValue($attributes['type'], $possibleTypes, ''); $name = SpoonFilter::getValue($attributes['name'], null, ''); // missing attributes if ($type == '' || $name == '') { continue; } // real type (shortened) $type = array_search($type, $possibleTypes); // translations foreach ($item->translation as $translation) { // statistics $statistics['total']++; // attributes $attributes = $translation->attributes(); $language = SpoonFilter::getValue($attributes['language'], $possibleLanguages[$application], ''); // language does not exist if ($language == '') { continue; } // the actual translation $translation = (string) $translation; // locale item $locale['user_id'] = $userId; $locale['language'] = $language; $locale['application'] = $application; $locale['module'] = $module; $locale['type'] = $type; $locale['name'] = $name; $locale['value'] = $translation; $locale['edited_on'] = $date; // found a conflict, overwrite it with the imported translation if ($overwriteConflicts && in_array($application . $module . $type . $language . $name, $currentLocale)) { // statistics $statistics['imported']++; // overwrite $db->update('locale', $locale, 'application = ? AND module = ? AND type = ? AND language = ? AND name = ?', array($application, $module, $type, $language, $name)); } elseif (!in_array($application . $module . $type . $language . $name, $currentLocale)) { // statistics $statistics['imported']++; // insert $db->insert('locale', $locale); } } } } } // rebuild cache foreach ($possibleApplications as $application) { foreach ($possibleLanguages[$application] as $language) { self::buildCache($language, $application); } } return $statistics; }
/** * Update an existing item * * @return int * @param array $item The new data. */ public static function update(array $item) { // check if new version is active if ($item['status'] == 'active') { // archive all older active versions BackendModel::getDB(true)->update('blog_posts', array('status' => 'archived'), 'id = ? AND status = ?', array($item['id'], $item['status'])); // get the record of the exact item we're editing $revision = self::getRevision($item['id'], $item['revision_id']); // assign values $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s', $revision['created_on']); $item['num_comments'] = $revision['num_comments']; // if it used to be a draft that we're now publishing, remove drafts if ($revision['status'] == 'draft') { BackendModel::getDB(true)->delete('blog_posts', 'id = ? AND status = ?', array($item['id'], $revision['status'])); } } // don't want revision id unset($item['revision_id']); // how many revisions should we keep $rowsToKeep = (int) BackendModel::getModuleSetting('blog', 'max_num_revisions', 20); // set type of archive $archiveType = $item['status'] == 'active' ? 'archived' : $item['status']; // get revision-ids for items to keep $revisionIdsToKeep = (array) BackendModel::getDB()->getColumn('SELECT i.revision_id FROM blog_posts AS i WHERE i.id = ? AND i.status = ? AND i.language = ? ORDER BY i.edited_on DESC LIMIT ?', array($item['id'], $archiveType, BL::getWorkingLanguage(), $rowsToKeep)); // delete other revisions if (!empty($revisionIdsToKeep)) { BackendModel::getDB(true)->delete('blog_posts', 'id = ? AND status = ? AND revision_id NOT IN (' . implode(', ', $revisionIdsToKeep) . ')', array($item['id'], $archiveType)); } // insert new version $item['revision_id'] = BackendModel::getDB(true)->insert('blog_posts', $item); // invalidate the cache for blog BackendModel::invalidateFrontendCache('blog', BL::getWorkingLanguage()); // return the new revision id return $item['revision_id']; }
/** * 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())) { $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()); // 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'); } } }
/** * 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'); // cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('publish_on_date')->isValid(BL::err('DateIsInvalid')); $this->frm->getField('publish_on_time')->isValid(BL::err('TimeIsInvalid')); $this->frm->getField('category_id')->isFilled(BL::err('FieldIsRequired')); if ($this->frm->getField('category_id')->getValue() == 'new_category') { $this->frm->getField('category_id')->addError(BL::err('FieldIsRequired')); } if ($this->imageIsAllowed) { // validate the image if ($this->frm->getField('image')->isFilled()) { // image extension and mime type $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly')); $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly')); } } // validate meta $this->meta->validate(); if ($this->frm->isCorrect()) { // build item $item['id'] = (int) BackendBlogModel::getMaximumId() + 1; $item['meta_id'] = $this->meta->save(); $item['category_id'] = (int) $this->frm->getField('category_id')->getValue(); $item['user_id'] = $this->frm->getField('user_id')->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['title'] = $this->frm->getField('title')->getValue(); $item['introduction'] = $this->frm->getField('introduction')->getValue(); $item['text'] = $this->frm->getField('text')->getValue(); $item['publish_on'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('publish_on_date'), $this->frm->getField('publish_on_time'))); $item['created_on'] = BackendModel::getUTCDate(); $item['edited_on'] = $item['created_on']; $item['hidden'] = $this->frm->getField('hidden')->getValue(); $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N'; $item['num_comments'] = 0; $item['status'] = $status; if ($this->imageIsAllowed) { // the image path $imagePath = FRONTEND_FILES_PATH . '/blog/images'; // validate the image if ($this->frm->getField('image')->isFilled()) { // build the image name $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension(); // upload the image $this->frm->getField('image')->moveFile($imagePath . '/source/' . $item['image']); } } // insert the item $item['revision_id'] = BackendBlogModel::insert($item); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // save the tags BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule()); // active if ($item['status'] == 'active') { // add search index BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'text' => $item['text'])); // ping if (BackendModel::getModuleSetting($this->getModule(), 'ping_services', false)) { BackendModel::ping(SITE_URL . BackendModel::getURLForBlock('blog', 'detail') . '/' . $this->meta->getURL()); } // everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['revision_id']); } elseif ($item['status'] == 'draft') { // everything is saved, so redirect to the edit action $this->redirect(BackendModel::createURLForAction('edit') . '&report=saved-as-draft&var=' . urlencode($item['title']) . '&id=' . $item['id'] . '&draft=' . $item['revision_id'] . '&highlight=row-' . $item['revision_id']); } } } }
/** * Login the user with the given credentials. * Will return a boolean that indicates if the user is logged in. * * @return bool * @param string $login The users login. * @param string $password The password provided by the user. */ public static function loginUser($login, $password) { // redefine $login = (string) $login; $password = (string) $password; // init vars $db = BackendModel::getDB(true); // fetch the encrypted password $passwordEncrypted = BackendAuthentication::getEncryptedPassword($login, $password); // check in database (is the user active and not deleted, are the email and password correct?) $userId = (int) $db->getVar('SELECT u.id FROM users AS u WHERE u.email = ? AND u.password = ? AND u.active = ? AND u.deleted = ? LIMIT 1', array($login, $passwordEncrypted, 'Y', 'N')); // not 0 = valid user! if ($userId !== 0) { // cleanup old sessions self::cleanupOldSessions(); // build the session array (will be stored in the database) $session = array(); $session['user_id'] = $userId; $session['secret_key'] = BackendAuthentication::getEncryptedString(SpoonSession::getSessionId(), $userId); $session['session_id'] = SpoonSession::getSessionId(); $session['date'] = BackendModel::getUTCDate(); // insert a new row in the session-table $db->insert('users_sessions', $session); // store some values in the session SpoonSession::set('backend_logged_in', true); SpoonSession::set('backend_secret_key', $session['secret_key']); // return result return true; } else { // reset values for invalid users. We can't destroy the session because session-data can be used on the site. SpoonSession::set('backend_logged_in', false); SpoonSession::set('backend_secret_key', ''); // return result return false; } }
/** * 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; }