/** * Load the form */ private function loadForm() { // gender dropdown values $genderValues = array('male' => \SpoonFilter::ucfirst(BL::getLabel('Male')), 'female' => \SpoonFilter::ucfirst(BL::getLabel('Female'))); // birthdate dropdown values $days = range(1, 31); $months = \SpoonLocale::getMonths(BL::getInterfaceLanguage()); $years = range(date('Y'), 1900); // create form $this->frm = new BackendForm('add'); // create elements $this->frm->addText('email')->setAttribute('type', 'email'); $this->frm->addPassword('password'); $this->frm->addText('display_name'); $this->frm->addText('first_name'); $this->frm->addText('last_name'); $this->frm->addText('city'); $this->frm->addDropdown('gender', $genderValues); $this->frm->addDropdown('day', array_combine($days, $days)); $this->frm->addDropdown('month', $months); $this->frm->addDropdown('year', array_combine($years, $years)); $this->frm->addDropdown('country', Intl::getRegionBundle()->getCountryNames(BL::getInterfaceLanguage())); // set default elements dropdowns $this->frm->getField('gender')->setDefaultElement(''); $this->frm->getField('day')->setDefaultElement(''); $this->frm->getField('month')->setDefaultElement(''); $this->frm->getField('year')->setDefaultElement(''); $this->frm->getField('country')->setDefaultElement(''); }
public function testGetConjunction() { $this->assertEquals('and', SpoonLocale::getConjunction('And', 'en')); $this->assertEquals('y', SpoonLocale::getConjunction('And', 'es')); $this->assertEquals('und', SpoonLocale::getConjunction('And', 'de')); $this->assertEquals('et', SpoonLocale::getConjunction('And', 'fr')); $this->assertEquals('en', SpoonLocale::getConjunction('And', 'nl')); }
/** * Load the form. */ private function loadForm() { // gender dropdown values $genderValues = array('male' => \SpoonFilter::ucfirst(FL::getLabel('Male')), 'female' => \SpoonFilter::ucfirst(FL::getLabel('Female'))); // birthdate dropdown values $days = range(1, 31); $months = \SpoonLocale::getMonths(LANGUAGE); $years = range(date('Y'), 1900); // get settings $birthDate = $this->profile->getSetting('birth_date'); $nameChanges = (int) $this->profile->getSetting('display_name_changes'); // get day, month and year if ($birthDate) { list($birthYear, $birthMonth, $birthDay) = explode('-', $birthDate); } else { // no birth date setting $birthDay = ''; $birthMonth = ''; $birthYear = ''; } // create the form $this->frm = new FrontendForm('updateSettings', null, null, 'updateSettingsForm'); // create & add elements $this->frm->addText('display_name', $this->profile->getDisplayName()); $this->frm->addText('first_name', $this->profile->getSetting('first_name')); $this->frm->addText('last_name', $this->profile->getSetting('last_name')); $this->frm->addText('email', $this->profile->getEmail()); $this->frm->addText('city', $this->profile->getSetting('city')); $this->frm->addDropdown('country', Intl::getRegionBundle()->getCountryNames(LANGUAGE), $this->profile->getSetting('country')); $this->frm->addDropdown('gender', $genderValues, $this->profile->getSetting('gender')); $this->frm->addDropdown('day', array_combine($days, $days), $birthDay); $this->frm->addDropdown('month', $months, $birthMonth); $this->frm->addDropdown('year', array_combine($years, $years), (int) $birthYear); // set default elements drop-downs $this->frm->getField('gender')->setDefaultElement(''); $this->frm->getField('day')->setDefaultElement(''); $this->frm->getField('month')->setDefaultElement(''); $this->frm->getField('year')->setDefaultElement(''); $this->frm->getField('country')->setDefaultElement(''); // set email disabled $this->frm->getField('email')->setAttribute('disabled', 'disabled'); // set avatar $this->frm->addImage('avatar'); // when user exceeded the number of name changes set field disabled if ($nameChanges >= FrontendProfilesModel::MAX_DISPLAY_NAME_CHANGES) { $this->frm->getField('display_name')->setAttribute('disabled', 'disabled'); } }
/** * 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(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->frm->getField('street')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired')); // no errors? if ($this->frm->isCorrect()) { // build item $item['language'] = BL::getWorkingLanguage(); $item['title'] = $this->frm->getField('title')->getValue(); $item['text'] = $this->frm->getField('text')->getValue(); $item['street'] = $this->frm->getField('street')->getValue(); $item['number'] = $this->frm->getField('number')->getValue(); $item['zip'] = $this->frm->getField('zip')->getValue(); $item['city'] = $this->frm->getField('city')->getValue(); $item['country'] = $this->frm->getField('country')->getValue(); // geocode address $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['street'] . ' ' . $item['number'] . ', ' . $item['zip'] . ' ' . $item['city'] . ', ' . SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false'; $geocode = json_decode(SpoonHTTP::getContent($url)); $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null; $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null; // insert the item $id = BackendLocationModel::insert($item); // add search index // if(is_callable(array('BackendSearchModel', 'addIndex'))) BackendSearchModel::addIndex($this->getModule(), (int) $id, array('title' => $item['title'], 'text' => $item['text'])); // everything is saved, so redirect to the overview if ($item['lat'] && $item['lng']) { // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item)); // redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $id); } else { $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $id); } } } }
/** * Load the form */ private function loadForm() { // gender dropdown values $genderValues = array('male' => \SpoonFilter::ucfirst(BL::getLabel('Male')), 'female' => \SpoonFilter::ucfirst(BL::getLabel('Female'))); // birthdate dropdown values $days = range(1, 31); $months = \SpoonLocale::getMonths(BL::getInterfaceLanguage()); $years = range(date('Y'), 1900); // get settings $birthDate = BackendProfilesModel::getSetting($this->id, 'birth_date'); // get day, month and year if ($birthDate) { list($birthYear, $birthMonth, $birthDay) = explode('-', $birthDate); } else { // no birth date setting $birthDay = ''; $birthMonth = ''; $birthYear = ''; } // create form $this->frm = new BackendForm('edit'); // create elements $this->frm->addCheckbox('new_email'); $this->frm->addText('email', $this->profile['email']); $this->frm->addCheckbox('new_password'); $this->frm->addPassword('password'); $this->frm->addPassword('password_repeat'); $this->frm->addText('display_name', $this->profile['display_name']); $this->frm->addText('first_name', BackendProfilesModel::getSetting($this->id, 'first_name')); $this->frm->addText('last_name', BackendProfilesModel::getSetting($this->id, 'last_name')); $this->frm->addText('city', BackendProfilesModel::getSetting($this->id, 'city')); $this->frm->addDropdown('gender', $genderValues, BackendProfilesModel::getSetting($this->id, 'gender')); $this->frm->addDropdown('day', array_combine($days, $days), $birthDay); $this->frm->addDropdown('month', $months, $birthMonth); $this->frm->addDropdown('year', array_combine($years, $years), (int) $birthYear); $this->frm->addDropdown('country', Intl::getRegionBundle()->getCountryNames(BL::getInterfaceLanguage()), BackendProfilesModel::getSetting($this->id, 'country')); // set default elements dropdowns $this->frm->getField('gender')->setDefaultElement(''); $this->frm->getField('day')->setDefaultElement(''); $this->frm->getField('month')->setDefaultElement(''); $this->frm->getField('year')->setDefaultElement(''); $this->frm->getField('country')->setDefaultElement(''); }
/** * Validate form */ private function validateForm() { if ($this->frm->isSubmitted()) { if ($this->frm->isCorrect()) { if (!empty($this->records)) { $teller = 0; foreach ($this->records as $key => $record) { if ($teller < $this->frm->getField("number_of_items")->getValue()) { $data = array(); //--Create url $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($record['address'] . ', ' . $record['zipcode'] . ' ' . $record['city'] . ', ' . \SpoonLocale::getCountry($record['country'], BL::getWorkingLanguage())) . '&sensor=false'; //--Get lat $geocode = json_decode(\SpoonHTTP::getContent($url)); //--Sleep between the requests sleep(0.05); //--Check result $data['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null; $data['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null; if ($data['lat'] != null) { BackendAddressesModel::update($record['id'], $data); $this->response .= "<strong>" . $record['company'] . "</strong> - " . $record['address'] . " " . $record['zipcode'] . " " . $record['city'] . " <i>(Lat: " . $data['lat'] . ", Lng: " . $data['lng'] . ")</i><br/>"; //--Delete from array unset($this->records[$key]); } else { $data['lat'] = "notfound"; $data['lng'] = "notfound"; BackendAddressesModel::update($record['id'], $data); $this->responseError .= "<strong>" . $record['company'] . "</strong> - " . $record['address'] . " " . $record['zipcode'] . " " . $record['city'] . "<br/>"; } } else { break; } //--Add teller $teller++; } $this->tpl->assign("responseError", $this->responseError); $this->tpl->assign("response", $this->response); } } } }
/** * Adds months and days from spoonLocale to the json * * @param array $json * @param string $language */ protected function addSpoonLocale(&$json, $language) { // get months $monthsLong = \SpoonLocale::getMonths($language, false); $monthsShort = \SpoonLocale::getMonths($language, true); // get days $daysLong = \SpoonLocale::getWeekDays($language, false, 'sunday'); $daysShort = \SpoonLocale::getWeekDays($language, true, 'sunday'); // build labels foreach ($monthsLong as $key => $value) { $json['loc']['MonthLong' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($monthsShort as $key => $value) { $json['loc']['MonthShort' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($daysLong as $key => $value) { $json['loc']['DayLong' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($daysShort as $key => $value) { $json['loc']['DayShort' . \SpoonFilter::ucfirst($key)] = $value; } }
/** * Parse the locale (things like months, days, ...) */ private function parseLocale() { // init vars $localeToAssign = array(); // get months $monthsLong = \SpoonLocale::getMonths(BL::getInterfaceLanguage(), false); $monthsShort = \SpoonLocale::getMonths(BL::getInterfaceLanguage(), true); // get days $daysLong = \SpoonLocale::getWeekDays(BL::getInterfaceLanguage(), false, 'sunday'); $daysShort = \SpoonLocale::getWeekDays(BL::getInterfaceLanguage(), true, 'sunday'); // build labels foreach ($monthsLong as $key => $value) { $localeToAssign['locMonthLong' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($monthsShort as $key => $value) { $localeToAssign['locMonthShort' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($daysLong as $key => $value) { $localeToAssign['locDayLong' . \SpoonFilter::ucfirst($key)] = $value; } foreach ($daysShort as $key => $value) { $localeToAssign['locDayShort' . \SpoonFilter::ucfirst($key)] = $value; } // assign $this->assignArray($localeToAssign); }
/** * Fetch the time ago as a language dependant sentence. * * @return string String containing a sentence like 'x minutes ago' * @param int $timestamp Timestamp you want to make a sentence of. * @param string[optional] $language Language to use, check SpoonLocale::getAvailableLanguages(). * @param string[optional] $format The format to return if the time passed is greather then a week. */ public static function getTimeAgo($timestamp, $language = 'en', $format = null) { // init vars $timestamp = (int) $timestamp; $language = SpoonFilter::getValue($language, SpoonLocale::getAvailableLanguages(), 'en', 'string'); $locale = array(); // fetch language if (!isset(self::$locales[$language])) { require 'spoon/locale/data/' . $language . '.php'; self::$locales[$language] = $locale; } $locale = self::$locales[$language]; // get seconds between given timestamp and current timestamp $secondsBetween = time() - $timestamp; // calculate years ago $yearsAgo = floor($secondsBetween / (365.242199 * 24 * 60 * 60)); if ($yearsAgo > 1 && $format === null) { return sprintf($locale['time']['YearsAgo'], $yearsAgo); } if ($yearsAgo == 1 && $format === null) { return $locale['time']['YearAgo']; } if ($yearsAgo >= 1 && $format !== null) { return self::getDate($format, $timestamp, $language); } // calculate months ago $monthsAgo = floor($secondsBetween / (365.242199 / 12 * 24 * 60 * 60)); if ($monthsAgo > 1 && $format === null) { return sprintf($locale['time']['MonthsAgo'], $monthsAgo); } if ($monthsAgo == 1 && $format === null) { return $locale['time']['MonthAgo']; } if ($monthsAgo >= 1 && $format !== null) { return self::getDate($format, $timestamp, $language); } // calculate weeks ago $weeksAgo = floor($secondsBetween / (7 * 24 * 60 * 60)); if ($weeksAgo > 1 && $format === null) { return sprintf($locale['time']['WeeksAgo'], $weeksAgo); } if ($weeksAgo == 1 && $format === null) { return $locale['time']['WeekAgo']; } if ($weeksAgo >= 1 && $format !== null) { return self::getDate($format, $timestamp, $language); } // calculate days ago $daysAgo = floor($secondsBetween / (24 * 60 * 60)); if ($daysAgo > 1) { return sprintf($locale['time']['DaysAgo'], $daysAgo); } if ($daysAgo == 1) { return $locale['time']['DayAgo']; } // calculate hours ago $hoursAgo = floor($secondsBetween / (60 * 60)); if ($hoursAgo > 1) { return sprintf($locale['time']['HoursAgo'], $hoursAgo); } if ($hoursAgo == 1) { return $locale['time']['HourAgo']; } // calculate minutes ago $minutesAgo = floor($secondsBetween / 60); if ($minutesAgo > 1) { return sprintf($locale['time']['MinutesAgo'], $minutesAgo); } if ($minutesAgo == 1) { return $locale['time']['MinuteAgo']; } // calculate seconds ago $secondsAgo = floor($secondsBetween); if ($secondsAgo > 1) { return sprintf($locale['time']['SecondsAgo'], $secondsAgo); } if ($secondsAgo <= 1) { return $locale['time']['SecondAgo']; } }
/** * Validate the form */ private function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validate fields $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired')); $this->frm->getField('street')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('number')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired')); $this->frm->getField('city')->isFilled(BL::err('FieldIsRequired')); if ($this->frm->isCorrect()) { // build item $item['id'] = $this->id; $item['language'] = BL::getWorkingLanguage(); $item['extra_id'] = $this->record['extra_id']; $item['title'] = $this->frm->getField('title')->getValue(); $item['text'] = $this->frm->getField('text')->getValue(); $item['street'] = $this->frm->getField('street')->getValue(); $item['number'] = $this->frm->getField('number')->getValue(); $item['zip'] = $this->frm->getField('zip')->getValue(); $item['city'] = $this->frm->getField('city')->getValue(); $item['country'] = $this->frm->getField('country')->getValue(); // check if it's neccessary to geocode again if ($this->record['lat'] === null || $this->record['lng'] === null || $item['street'] != $this->record['street'] || $item['number'] != $this->record['number'] || $item['zip'] != $this->record['zip'] || $item['city'] != $this->record['city'] || $item['country'] != $this->record['country']) { // geocode address $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['street'] . ' ' . $item['number'] . ', ' . $item['zip'] . ' ' . $item['city'] . ', ' . SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false'; $geocode = json_decode(SpoonHTTP::getContent($url)); $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null; $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null; } else { $item['lat'] = $this->record['lat']; $item['lng'] = $this->record['lng']; } // insert the item $id = BackendLocationModel::update($item); // edit search index // @todo why is this commented out? // BackendSearchModel::editIndex($this->getModule(), (int) $id, array('title' => $item['title'], 'text' => $item['text'])); // everything is saved, so redirect to the overview if ($item['lat'] && $item['lng']) { // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $item)); // redirect $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&var=' . urlencode($item['title']) . '&highlight=row-' . $id); } else { $this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $item['id']); } } } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); $fields['title']->isFilled(BL::err('FieldIsRequired')); $fields['begin_date_date']->isFilled(BL::err('FieldIsRequired')); $fields['begin_date_time']->isFilled(BL::err('FieldIsRequired')); $fields['begin_date_date']->isValid(BL::err('DateIsInvalid')); $fields['begin_date_time']->isValid(BL::err('TimeIsInvalid')); $fields['end_date_date']->isFilled(BL::err('FieldIsRequired')); $fields['end_date_time']->isFilled(BL::err('FieldIsRequired')); $fields['end_date_date']->isValid(BL::err('DateIsInvalid')); $fields['end_date_time']->isValid(BL::err('TimeIsInvalid')); $fields['category_id']->isFilled(BL::err('FieldIsRequired')); if ($fields['price']->isFilled()) { $fields['price']->isPrice(BL::err('InvalidValue')); } // validate meta $this->meta->validate(); $this->media->validate(); if ($this->frm->isCorrect()) { $item['id'] = $this->id; $item['language'] = BL::getWorkingLanguage(); $item['title'] = $fields['title']->getValue(); $item['text'] = $fields['text']->getValue(); $item['introduction'] = $fields['introduction']->getValue(); $item['begin_date'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('begin_date_date'), $this->frm->getField('begin_date_time'))); $item['end_date'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('end_date_date'), $this->frm->getField('end_date_time'))); $item['category_id'] = $this->frm->getField('category_id')->getValue(); $item['price'] = $fields['price']->getValue(); $item['whole_day'] = $fields['whole_day']->getChecked() ? 'Y' : 'N'; $item['recurring'] = $fields['recurring']->getChecked() ? 'Y' : 'N'; $item['allow_subscriptions'] = $fields['subscriptions']->getValue(); $item['google_maps'] = $fields['google_maps']->getChecked() ? 'Y' : 'N'; $item['location_name'] = $fields['name']->getValue(); $item['street'] = $fields['street']->getValue(); $item['number'] = $fields['number']->getValue(); $item['zip'] = $fields['zip']->getValue(); $item['city'] = $fields['city']->getValue(); $item['country'] = $fields['country']->getValue(); $item['meta_id'] = $this->meta->save(); // geocode address $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['street'] . ' ' . $item['number'] . ', ' . $item['zip'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false'; $geocode = json_decode(\SpoonHTTP::getContent($url)); $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null; $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null; // update item BackendAgendaModel::update($item); $item['id'] = $this->id; // recurring item if ($item['recurring'] == 'Y') { $recurringItem['id'] = $this->recurringOptions['id']; $recurringItem['agenda_id'] = $item['id']; $recurringItem['type'] = $fields['type']->getValue(); $recurringItem['interval'] = $fields['interval']->getValue(); $recurringItem['ends_on'] = $fields['ends_on']->getValue(); // if recurring type is weekly, get days checked if ($recurringItem['type'] == 1) { $days = $fields['days']->getChecked(); $recurringItem['days'] = implode(",", $days); } // if item ends on x amount of times if ($recurringItem['ends_on'] == 1) { $recurringItem['frequency'] = $fields['frequency']->getValue(); } else { if ($recurringItem['ends_on'] == 2) { // item ends on specific date // check date/time fields if ($fields['recurr_end_date_date']->isFilled() || $fields['recurr_end_date_time']->isFilled()) { $recurringItem['end_date'] = BackendModel::getUTCDate(null, BackendModel::getUTCTimestamp($this->frm->getField('recurr_end_date_date'), $this->frm->getField('recurr_end_date_time'))); } } } // update if options exist if (BackendAgendaModel::existsRecurringOptions($recurringItem['id'], $recurringItem['agenda_id'])) { BackendAgendaModel::updateRecurringOptions($recurringItem); } else { // insert new options BackendAgendaModel::insertRecurringOptions($recurringItem); } } // add search index BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['title'], 'Text' => $item['text'])); BackendModel::triggerEvent($this->getModule(), 'after_edit', $item); $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']); } } }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); // 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')); } $this->meta->validate(); if ($this->frm->isCorrect()) { $item['meta_id'] = $this->meta->save(); $item['company'] = $fields['company']->getValue(); $item['name'] = $fields['name']->getValue(); $item['firstname'] = $fields['firstname']->getValue(); $item['email'] = $fields['email']->getValue(); $item['address'] = $fields['address']->getValue(); $item['zipcode'] = $fields['zipcode']->getValue(); $item['city'] = $fields['city']->getValue(); $item['country'] = $fields['country']->getValue(); $item['phone'] = $fields['phone']->getValue(); $item['fax'] = $fields['fax']->getValue(); $item['website'] = str_replace("http://", "", $fields['website']->getValue()); $item['text'] = $fields['text']->getValue(); $item['zipcodes'] = $fields['zipcodes']->getValue(); $item['remark'] = $fields['remark']->getValue(); //$item['assort'] = $fields['assort']->getValue(); //$item['open'] = $fields['open']->getValue(); //$item['closed'] = $fields['closed']->getValue(); //$item['visit'] = $fields['visit']->getValue(); //$item['size'] = $fields['size']->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['hidden'] = $fields['hidden']->getValue(); if ($item['country'] == '') { $item['country'] = 'BE'; } //--Create url $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['address'] . ', ' . $item['zipcode'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false'; //--Get lat $geocode = json_decode(\SpoonHTTP::getContent($url)); //--Sleep between the requests sleep(0.05); //--Check result $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null; $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null; // the image path $imagePath = FRONTEND_FILES_PATH . '/Addresses/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 . '/400x300')) { \SpoonDirectory::create($imagePath . '/400x300'); } if (!\SpoonDirectory::exists($imagePath . '/800x')) { \SpoonDirectory::create($imagePath . '/800x'); } // image provided? if ($this->frm->getField('image')->isFilled()) { // build the image name $item['image'] = $this->meta->getURL() . '.' . $this->frm->getField('image')->getExtension(); // upload the image & generate thumbnails $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']); } $item['id'] = BackendAddressesModel::insert($item); //--Add the languages foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) { $itemLanguage = array(); $itemLanguage['id'] = $item['id']; $itemLanguage['language'] = $language; $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue(); $itemLanguage['opening_hours'] = $this->frm->getField('opening_hours_' . $language)->getValue(); BackendAddressesModel::insertLanguage($itemLanguage); } if (isset($fields["groups"])) { //--Get all the groups $groups = $fields["groups"]->getValue(); foreach ($groups as $value) { $groupAddress = array(); $groupAddress["address_id"] = $item['id']; $groupAddress["group_id"] = $value; //--Add user to the group BackendAddressesModel::insertAddressToGroup($groupAddress); } } BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['name'], 'text' => $item['name'])); BackendModel::triggerEvent($this->getModule(), 'after_add', $item); $this->redirect(BackendModel::createURLForAction('index') . '&report=added&highlight=row-' . $item['id']); } } }
/** * Parse the locale (things like months, days, ...) */ private function parseLocale() { // init vars $locale = array(); // get months $monthsLong = SpoonLocale::getMonths(FRONTEND_LANGUAGE, false); $monthsShort = SpoonLocale::getMonths(FRONTEND_LANGUAGE, true); // get days $daysLong = SpoonLocale::getWeekDays(FRONTEND_LANGUAGE, false, 'sunday'); $daysShort = SpoonLocale::getWeekDays(FRONTEND_LANGUAGE, true, 'sunday'); // build labels foreach ($monthsLong as $key => $value) { $locale['locMonthLong' . SpoonFilter::ucfirst($key)] = $value; } foreach ($monthsShort as $key => $value) { $locale['locMonthShort' . SpoonFilter::ucfirst($key)] = $value; } foreach ($daysLong as $key => $value) { $locale['locDayLong' . SpoonFilter::ucfirst($key)] = $value; } foreach ($daysShort as $key => $value) { $locale['locDayShort' . SpoonFilter::ucfirst($key)] = $value; } // assign $this->assignArray($locale); }
/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); // $fields['name']->isFilled(BL::err('FieldIsRequired')); $this->meta->validate(); if ($this->frm->isCorrect()) { $item['meta_id'] = $this->meta->save(); $item['company'] = $fields['company']->getValue(); $item['name'] = $fields['name']->getValue(); $item['firstname'] = $fields['firstname']->getValue(); $item['email'] = $fields['email']->getValue(); $item['address'] = $fields['address']->getValue(); $item['zipcode'] = $fields['zipcode']->getValue(); $item['city'] = $fields['city']->getValue(); $item['country'] = $fields['country']->getValue(); $item['phone'] = $fields['phone']->getValue(); $item['fax'] = $fields['fax']->getValue(); $item['website'] = str_replace("http://", "", $fields['website']->getValue()); $item['zipcodes'] = $fields['zipcodes']->getValue(); $item['remark'] = $fields['remark']->getValue(); //$item['text'] = $fields['text']->getValue(); //$item['assort'] = $fields['assort']->getValue(); //$item['open'] = $fields['open']->getValue(); //$item['closed'] = $fields['closed']->getValue(); //$item['visit'] = $fields['visit']->getValue(); //$item['size'] = $fields['size']->getValue(); $item['language'] = BL::getWorkingLanguage(); $item['hidden'] = $fields['hidden']->getValue(); if ($item['country'] == '') { $item['country'] = 'BE'; } //--Create url $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['address'] . ', ' . $item['zipcode'] . ' ' . $item['city'] . ', ' . \SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false'; //--Get lat $geocode = json_decode(\SpoonHTTP::getContent($url)); //--Sleep between the requests sleep(0.05); //--Check result $item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null; $item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null; $item['image'] = $this->record['image']; // the image path $imagePath = FRONTEND_FILES_PATH . '/Addresses/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 . '/400x300')) { \SpoonDirectory::create($imagePath . '/400x300'); } if (!\SpoonDirectory::exists($imagePath . '/800x')) { \SpoonDirectory::create($imagePath . '/800x'); } // 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 & generate thumbnails $this->frm->getField('image')->generateThumbnails($imagePath, $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']) { // loop folders foreach (BackendModel::getThumbnailFolders($imagePath, true) as $folder) { // move the old file to the new name \SpoonFile::move($folder['path'] . '/' . $item['image'], $folder['path'] . '/' . $newName); } // assign the new name to the database $item['image'] = $newName; } } BackendAddressesModel::update($this->id, $item); $item['id'] = $this->id; //--Add the languages foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) { $itemLanguage = array(); $itemLanguage['id'] = $item['id']; $itemLanguage['language'] = $language; $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue(); $itemLanguage['opening_hours'] = $this->frm->getField('opening_hours_' . $language)->getValue(); BackendAddressesModel::updateLanguage($itemLanguage); } if (isset($fields["groups"])) { //--Get all the groups $groups = $fields["groups"]->getValue(); BackendAddressesModel::deleteGroupsFromAddress($item['id']); foreach ($groups as $value) { $groupAddress = array(); $groupAddress["address_id"] = $item['id']; $groupAddress["group_id"] = $value; //--Add user to the group BackendAddressesModel::insertAddressToGroup($groupAddress); } } BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $item['name'], 'text' => $item['name'])); BackendModel::triggerEvent($this->getModule(), 'after_edit', $item); $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']); } } }