Example #1
0
 /**
  * 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);
             }
         }
     }
 }
Example #2
0
 /**
  * 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);
             }
         }
     }
 }
Example #3
0
 /**
  * Reads an feed into a SpoonRSS object.
  *
  * @return	SpoonRSS					Returns as an instance of SpoonRSS.
  * @param	string $URL					An URL where the feed is located or the XML of the feed.
  * @param	string[optional] $type		The type of feed, possible values are: url, string.
  */
 public static function readFromFeed($URL, $type = 'url')
 {
     // redefine var
     $URL = (string) $URL;
     $type = (string) SpoonFilter::getValue($type, array('url', 'string'), 'url');
     // validate
     if ($type == 'url' && !SpoonFilter::isURL($URL)) {
         throw new SpoonFeedException('This (' . SpoonFilter::htmlentities($URL) . ') isn\'t a valid URL.');
     }
     if (!self::isValid($URL, $type)) {
         throw new SpoonFeedException('Invalid feed');
     }
     // load xmlstring
     if ($type == 'url') {
         $xmlString = SpoonHTTP::getContent($URL);
     } else {
         $xmlString = $URL;
     }
     // convert to simpleXML
     $XML = @simplexml_load_string($xmlString);
     // validate the feed
     if ($XML === false) {
         throw new SpoonFeedException('Invalid rss-string.');
     }
     // get title, link and description
     $title = (string) $XML->channel->title;
     $link = (string) $XML->channel->link;
     $description = (string) $XML->channel->description;
     // create instance
     $RSS = new SpoonFeedRSS($title, $link, $description);
     // add items
     foreach ($XML->channel->item as $item) {
         // try to read
         try {
             // read xml
             $item = SpoonFeedRSSItem::readFromXML($item);
             $RSS->addItem($item);
         } catch (Exception $e) {
             // ignore exceptions
         }
     }
     // add category
     if (isset($XML->channel->category)) {
         foreach ($XML->channel->category as $category) {
             if (isset($category['domain'])) {
                 $RSS->addCategory((string) $category, (string) $category['domain']);
             } else {
                 $RSS->addCategory((string) $category);
             }
         }
     }
     // add skip day
     if (isset($XML->channel->skipDays)) {
         // loop ski-days
         foreach ($XML->channel->skipDays->day as $day) {
             // try to add
             try {
                 // add skip-day
                 $RSS->addSkipDay((string) $day);
             } catch (Exception $e) {
                 // ignore exceptions
             }
         }
     }
     // add skip hour
     if (isset($XML->channel->skipHours)) {
         foreach ($XML->channel->skipHours->hour as $hour) {
             // try to add
             try {
                 // add skip hour
                 $RSS->addSkipHour((int) $hour);
             } catch (Exception $e) {
                 // ignore exceptions
             }
         }
     }
     // set cloud
     if (isset($XML->channel->cloud['domain']) && isset($XML->channel->cloud['port']) && isset($XML->channel->cloud['path']) && isset($XML->channel->cloud['registerProce-dure']) && isset($XML->channel->cloud['protocol'])) {
         // read attributes
         $cloudDomain = (string) $XML->channel->cloud['domain'];
         $cloudPort = (int) $XML->channel->cloud['port'];
         $cloudPath = (string) $XML->channel->cloud['path'];
         $cloudRegisterProcedure = (string) $XML->channel->cloud['registerProce-dure'];
         $cloudProtocol = (string) $XML->channel->cloud['protocol'];
         // set property
         $RSS->setCloud($cloudDomain, $cloudPort, $cloudPath, $cloudRegisterProcedure, $cloudProtocol);
     }
     // set copyright
     if (isset($XML->channel->copyright)) {
         $copyright = (string) $XML->channel->copyright;
         $RSS->setCopyright($copyright);
     }
     // set docs
     if (isset($XML->channel->docs)) {
         $docs = (string) $XML->channel->docs;
         $RSS->setDocs($docs);
     }
     // set generator if it is present
     if (isset($XML->channel->generator)) {
         $generator = (string) $XML->channel->generator;
         $RSS->setGenerator($generator);
     }
     // set image if it is present
     if (isset($XML->channel->image->title) && isset($XML->channel->image->url) && isset($XML->channel->image->link)) {
         // read properties
         $imageTitle = (string) $XML->channel->image->title;
         $imageURL = (string) $XML->channel->image->url;
         $imageLink = (string) $XML->channel->image->link;
         // read optional properties
         if (isset($XML->channel->image->width)) {
             $imageWidth = (int) $XML->channel->image->width;
         } else {
             $imageWidth = null;
         }
         if (isset($XML->channel->image->height)) {
             $imageHeight = (int) $XML->channel->image->height;
         } else {
             $imageHeight = null;
         }
         if (isset($XML->channel->image->description)) {
             $imageDescription = (string) $XML->channel->image->description;
         } else {
             $imageDescription = null;
         }
         // try to set image
         try {
             // set image
             $RSS->setImage($imageURL, $imageTitle, $imageLink, $imageWidth, $imageHeight, $imageDescription);
         } catch (Exception $e) {
             // ignore exceptions
         }
     }
     // set language if its is present
     if (isset($XML->channel->language)) {
         $language = (string) $XML->channel->language;
         $RSS->setLanguage($language);
     }
     // set last build date if it is present
     if (isset($XML->channel->lastBuildDate)) {
         $lastBuildDate = (int) strtotime($XML->channel->lastBuildDate);
         $RSS->setLastBuildDate($lastBuildDate);
     }
     // set managing editor
     if (isset($XML->channel->managingEditor)) {
         $managingEditor = (string) $XML->channel->managingEditor;
         $RSS->setManagingEditor($managingEditor);
     }
     // set publication date
     if (isset($XML->channel->pubDate)) {
         $publicationDate = (int) strtotime($XML->channel->pubDate);
         $RSS->setPublicationDate($publicationDate);
     }
     // set rating
     if (isset($XML->channel->rating)) {
         $rating = (string) $XML->channel->rating;
         $RSS->setRating($rating);
     }
     // set ttl
     if (isset($XML->channel->ttl)) {
         $ttl = (int) $XML->channel->ttl;
         $RSS->setTTL($ttl);
     }
     // set webmaster
     if (isset($XML->channel->webmaster)) {
         $webmaster = (string) $XML->channel->webmaster;
         $RSS->setWebmaster($webmaster);
     }
     // return
     return $RSS;
 }
Example #4
0
 /**
  * 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']);
             }
         }
     }
 }
Example #5
0
 /**
  * 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']);
         }
     }
 }
Example #6
0
 /**
  * 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']);
         }
     }
 }
Example #7
0
 /**
  * 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']);
         }
     }
 }
Example #8
0
 /**
  * Get coordinates latitude/longitude
  *
  * @param  string $street
  * @param  string $streetNumber
  * @param  string $city
  * @param  string $zip
  * @param  string $country
  * @return array  Contains 'latitude' and 'longitude' as variables
  */
 public static function getCoordinates($street = null, $streetNumber = null, $city = null, $zip = null, $country = null)
 {
     // init item
     $item = array();
     // building item
     if (!empty($street)) {
         $item[] = $street;
     }
     if (!empty($streetNumber)) {
         $item[] = $streetNumber;
     }
     if (!empty($city)) {
         $item[] = $city;
     }
     if (!empty($zip)) {
         $item[] = $zip;
     }
     if (!empty($country)) {
         $item[] = Intl::getRegionBundle()->getCountryName($country, BL::getInterfaceLanguage());
     }
     // define address
     $address = implode(' ', $item);
     // define url
     $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&sensor=false';
     // define result
     $geocodes = json_decode(\SpoonHTTP::getContent($url), true);
     // return coordinates latitude/longitude
     return array('latitude' => array_key_exists(0, $geocodes['results']) ? $geocodes['results'][0]['geometry']['location']['lat'] : null, 'longitude' => array_key_exists(0, $geocodes['results']) ? $geocodes['results'][0]['geometry']['location']['lng'] : null);
 }
Example #9
0
 /**
  * Reads an feed into a SpoonRSS object.
  *
  * @return	SpoonAtomRSS				Returns as an instance of SpoonAtomRSS.
  * @param	string $URL					An URL where the feed is located or the XML of the feed.
  * @param	string[optional] $type		The type of feed, possible values are: url, string.
  * @param	bool[optional] $force		Force to read this feed without validation.
  */
 public static function readFromFeed($URL, $type = 'url', $force = false)
 {
     // redefine var
     $URL = (string) $URL;
     $type = (string) SpoonFilter::getValue($type, array('url', 'string'), 'url');
     // validate
     if ($type == 'url' && !SpoonFilter::isURL($URL)) {
         throw new SpoonFeedException('This (' . SpoonFilter::htmlentities($URL) . ') isn\'t a valid URL.');
     }
     if (!$force) {
         if (!self::isValid($URL, $type)) {
             throw new SpoonFeedException('Invalid feed');
         }
     }
     // load xmlstring
     if ($type == 'url') {
         $xmlString = SpoonHTTP::getContent($URL);
     } else {
         $xmlString = $URL;
     }
     // convert to simpleXML
     $XML = @simplexml_load_string($xmlString);
     // validate the feed
     if ($XML === false) {
         throw new SpoonFeedException('Invalid rss-string.');
     }
     // get title, link and description
     $title = (string) $XML->title;
     $id = (string) $XML->id;
     // create instance
     $RSS = new SpoonFeedAtomRSS($title, $id);
     // add authors
     if (isset($XML->author)) {
         foreach ($XML->author as $author) {
             // get the values
             $author['name'] = (string) $XML->author->name;
             $author['email'] = isset($XML->author->email) ? (string) $XML->author->email : null;
             $author['uri'] = isset($XML->author->uri) ? (string) $XML->author->uri : null;
             // set the values
             $RSS->addAuthor($author);
         }
     }
     // add contributors
     if (isset($XML->contributor)) {
         foreach ($XML->contributor as $contributor) {
             $name = (string) $contributor['name'];
             $email = isset($contributor['scheme']) ? (string) $contributor['email'] : null;
             $uri = isset($contributor['label']) ? (string) $contributor['uri$contributor'] : null;
             // set property
             $RSS->addContributor($name, $email, $uri);
         }
     }
     // add categories
     if (isset($XML->category)) {
         foreach ($XML->category as $category) {
             // build category
             $cat['term'] = (string) $category['term'];
             if (isset($category['scheme'])) {
                 $cat['scheme'] = (string) $category['scheme'];
             }
             if (isset($category['label'])) {
                 $cat['label'] = (string) $category['label'];
             }
             // set property
             $RSS->addCategory($cat);
         }
     }
     // add links
     if (isset($XML->link)) {
         foreach ($XML->link as $link) {
             // build link
             $aLink['href'] = $link['href'];
             if (isset($link['rel'])) {
                 $aLink['rel'] = $link['rel'];
             }
             if (isset($link['type'])) {
                 $aLink['type'] = $link['type'];
             }
             if (isset($link['title'])) {
                 $aLink['title'] = $link['title'];
             }
             if (isset($link['hreflang'])) {
                 $aLink['hreflang'] = $link['hreflang'];
             }
             if (isset($link['length'])) {
                 $aLink['length'] = $link['length'];
             }
             // set property
             $RSS->addLink($aLink);
         }
     }
     // add items
     foreach ($XML->entry as $item) {
         // try to read
         try {
             // read xml
             $item = SpoonFeedAtomRSSItem::readFromXML($item);
             $RSS->addItem($item);
         } catch (Exception $e) {
             // ignore exceptions
         }
     }
     // set updated date
     if (isset($XML->updated)) {
         $RSS->setUpdatedDate((int) strtotime($XML->updated));
     }
     // set generator
     if (isset($XML->generator)) {
         $RSS->setGenerator((string) $XML->generator);
     }
     // set icon
     if (isset($XML->icon)) {
         $RSS->setIcon((string) $XML->icon);
     }
     // set logo
     if (isset($XML->logo)) {
         $RSS->setLogo((string) $XML->logo);
     }
     // set rights
     if (isset($XML->rights)) {
         $RSS->setRights((string) $XML->rights);
     }
     // return
     return $RSS;
 }