public static function output($event_id = NULL, $event_cat = NULL, $page = 1, $is_download = FALSE, $is_push = FALSE)
 {
     //ob_clean();
     //ini_set('zlib.output_handler','');
     $EM_Events = !empty($event_id) ? array(em_get_event($event_id)) : EM_Events::get(apply_filters('em_calendar_template_args', array('limit' => get_option('ess_feed_limit'), 'category' => $event_cat, 'page' => $page, 'owner' => FALSE, 'orderby' => 'event_start_date')));
     $limit = 0;
     //no limit for now, but this shall be eventually set in the wP settings page, option name dbem_ess_limit
     //var_dump( $EM_Events );die;
     //echo "count: ".count($EM_Events);
     //echo "limit: " . get_option('ess_feed_limit', $limit );
     //echo "event_id: ". $event_id;
     //die;
     $essFeed = new FeedWriter(strlen(get_option('ess_feed_language')) == 2 ? get_option('ess_feed_language', ESS_Database::DEFAULT_LANGUAGE) : ESS_Database::DEFAULT_LANGUAGE);
     $essFeed->DEBUG = FALSE;
     // ###  DEBUG  MODE
     $essFeed->setTitle(self::_g('ess_feed_title', __('ESS Feed generated by Wordpress', 'dbem')));
     $essFeed->setLink(str_replace('&push=1', '', str_replace('&download=1', '', FeedWriter::getCurrentURL())));
     $essFeed->setPublished(ESS_Timezone::get_date_GMT(get_option('em_last_modified', current_time('timestamp', TRUE))));
     $essFeed->setUpdated(ESS_Timezone::get_date_GMT(current_time('timestamp', TRUE)));
     $essFeed->setRights(self::_g('ess_feed_rights', 'Rights'));
     $count = 0;
     while (count($EM_Events) > 0) {
         foreach ($EM_Events as $ie => $EM_Event) {
             if (intval($EM_Event->event_id) <= 0) {
                 // event empty
                 break;
             }
             if (get_option('ess_feed_limit', $limit) != 0 && $count > get_option('ess_feed_limit', $limit)) {
                 //we've reached the max event per feed
                 break;
             }
             //dd( $EM_Event );
             $event_url = self::unhtmlentities(esc_html(urldecode($EM_Event->guid)));
             // --- Create a new event to the feed: <feed>
             $newEvent = $essFeed->newEventFeed();
             $newEvent->setTitle($EM_Event->output(get_option('dbem_rss_title_format', sprintf(__('Event Nb: %d', 'dbem'), $ie)), "rss"));
             $newEvent->setUri($event_url);
             $newEvent->setPublished(ESS_Timezone::get_date_GMT(strtotime($EM_Event->post_date)));
             $newEvent->setUpdated(ESS_Timezone::get_date_GMT(strtotime($EM_Event->post_modified)));
             $newEvent->setAccess(intval($EM_Event->event_private) === 1 ? EssDTD::ACCESS_PRIVATE : EssDTD::ACCESS_PUBLIC);
             // -- encode a unic ID base on the host name + event_id (e.g. www.sample.com:123)
             $newEvent->setId((strlen(@$_SERVER['SERVER_NAME']) > 0 ? $_SERVER['SERVER_NAME'] : @$_SERVER['HTTP_HOST']) . ":" . $EM_Event->event_id);
             $description = wpautop($EM_Event->post_content, TRUE);
             if (get_option('ess_backlink_enabled')) {
                 $feed_uri_host = parse_url($event_url, PHP_URL_HOST);
                 $description = "<h6>" . __("Source:", 'dbem') . " <a target=\"_blank\" title=\"" . __("Source:", 'dbem') . " " . $feed_uri_host . "\" href=\"" . $event_url . "\">" . $feed_uri_host . "</a></h6>" . $description;
             }
             //dd( $description );
             // Add custom attributes json encoded in HTML comments <!--||ATTR||xx{xx:'xx',xx...}||ATTR||-->
             if (@count(@$EM_Event->event_attributes) > 0 && @$EM_Event->event_attributes != NULL) {
                 $custom_att = $EM_Event->event_attributes;
                 //dd( $custom_att );
                 $description .= "<!--" . self::CUSTOM_ATTRIBUTE_SEPARATOR . json_encode(iconv(mb_detect_encoding($custom_att, mb_detect_order(), TRUE), "UTF-8", $custom_att), JSON_UNESCAPED_SLASHES) . self::CUSTOM_ATTRIBUTE_SEPARATOR . "-->";
             }
             $newEvent->setDescription($description);
             //dd( $description );
             // ====== TAGS ========
             $tags = get_the_terms($EM_Event->post_id, EM_TAXONOMY_TAG);
             //var_dump( $tags );
             if (count($tags) > 0 && $tags != NULL) {
                 $arr_ = array();
                 foreach ($tags as $tag) {
                     if (strlen($tag->name) > 1 && is_numeric($tag->name) == FALSE) {
                         array_push($arr_, $tag->name);
                     }
                 }
                 if (count($arr_) > 0) {
                     $newEvent->setTags($arr_);
                 }
             }
             // ====== CATEGORIES ========
             //dd( $EM_Event );
             // $categories_ = EM_Categories::get( $EM_Event->get_categories()->get_ids() ); // enumerate all the categories
             if (@count(@$EM_Event->categories) > 0 && @$EM_Event->categories != NULL) {
                 $cat_duplicates_ = array();
                 foreach ($EM_Event->categories as $cat) {
                     $category_type = get_option('ess_feed_category_type');
                     if (strlen($cat->name) > 0 && strlen($category_type) > 3) {
                         if (in_array(strtolower($cat->name), $cat_duplicates_) == FALSE) {
                             $newEvent->addCategory($category_type, array('name' => $cat->name, 'id' => $cat->id));
                         }
                         $cat_duplicates_[] = strtolower($cat->name);
                     }
                 }
             }
             // ====== DATES =========
             $event_start = NULL;
             if (isset($EM_Event->event_start_date) && isset($EM_Event->event_end_date)) {
                 $event_start = ESS_Timezone::get_date_GMT(strtotime($EM_Event->event_start_date . " " . $EM_Event->event_start_time));
                 $event_stop = ESS_Timezone::get_date_GMT(strtotime($EM_Event->event_end_date . " " . $EM_Event->event_end_time));
                 // -- STANDALONE -----
                 if ($EM_Event->recurrence <= 0) {
                     $duration_s = FeedValidator::getDateDiff('s', $event_start, $event_stop);
                     // number of seconds between two dates
                     $newEvent->addDate('standalone', 'hour', NULL, NULL, NULL, NULL, array('name' => __('Date', 'dbem'), 'start' => $event_start, 'duration' => $duration_s > 0 ? $duration_s / 60 / 60 : 0));
                 } else {
                     $interval = intval($EM_Event->recurrence_interval);
                     $u = $EM_Event->recurrence_freq;
                     $event_unit = $u == 'daily' ? 'day' : ($u == 'weekly' ? 'week' : ($u == 'monthly' ? 'month' : ($u == 'yearly' ? 'year' : 'hour')));
                     switch ($event_unit) {
                         default:
                         case 'day':
                             $limit = FeedValidator::getDateDiff('d', $event_start, $event_stop);
                             break;
                             // number of days
                         // number of days
                         case 'hour':
                             $limit = FeedValidator::getDateDiff('h', $event_start, $event_stop);
                             break;
                             // number of hours
                         // number of hours
                         case 'week':
                             $limit = FeedValidator::getDateDiff('ww', $event_start, $event_stop);
                             break;
                             // number of weeks
                         // number of weeks
                         case 'month':
                             $limit = FeedValidator::getDateDiff('m', $event_start, $event_stop);
                             break;
                             // number of months
                         // number of months
                         case 'year':
                             $limit = FeedValidator::getDateDiff('yyyy', $event_start, $event_stop);
                             break;
                             // number of years
                     }
                     $d = intval($EM_Event->recurrence_byday);
                     $selected_day = $event_unit == 'year' || $event_unit == 'month' || $event_unit == 'week' ? $d == 0 ? 'sunday' : ($d == 1 ? 'monday' : ($d == 2 ? 'tuesday' : ($d == 3 ? 'wednesday' : ($d == 4 ? 'thursday' : ($d == 5 ? 'friday' : ($d == 6 ? 'saturday' : '')))))) : '';
                     $w = intval($EM_Event->recurrence_byweekno);
                     $selected_week = $event_unit == 'month' ? $w == -1 ? 'last' : ($w == 1 ? 'first' : ($w == 2 ? 'second' : ($w == 3 ? 'third' : ($w == 4 ? 'fourth' : '')))) : '';
                     $newEvent->addDate('recurrent', $event_unit, $limit, $interval, $selected_day, $selected_week, array('name' => sprintf(__('Date: %s', 'dbem'), $event_start), 'start' => $event_start, 'duration' => 0));
                 }
             }
             // end date
             // ====== PLACES ========
             $places_ = $EM_Event->get_location();
             //var_dump( $places_ );
             if (is_object($places_) && strlen($places_->location_name) > 0) {
                 $newEvent->addPlace('fixed', null, array('name' => $places_->location_name == $places_->location_address ? sprintf(__('Place: %s', 'dbem'), $places_->location_name) : $places_->location_name, 'latitude' => isset($places_->location_latitude) ? round($places_->location_latitude * 10000) / 10000 : '', 'longitude' => isset($places_->location_longitude) ? round($places_->location_longitude * 10000) / 10000 : '', 'address' => strlen($places_->location_address) > 0 ? $places_->location_address : $places_->location_name, 'city' => $places_->location_town, 'zip' => $places_->location_postcode, 'state' => $places_->location_region, 'state_code' => $places_->location_state, 'country' => FeedValidator::$COUNTRIES_[strtoupper($places_->location_country)], 'country_code' => strtolower($places_->location_country) == 'xe' ? '' : $places_->location_country));
             }
             // end place
             // ====== PRICES =========
             if ($EM_Event->is_free() == TRUE) {
                 $newEvent->addPrice('standalone', 'free', NULL, NULL, NULL, NULL, NULL, array('name' => __('Free', 'dbem'), 'currency' => get_option('ess_feed_currency', ESS_Database::DEFAULT_CURRENCY), 'value' => 0));
             } else {
                 $prices_ = $EM_Event->get_bookings();
                 //dd($prices_);
                 if ($prices_) {
                     if (count($prices_->tickets->tickets) > 0 && $event_start != NULL && $prices_->tickets->tickets != NULL) {
                         if (isset($prices_->tickets)) {
                             if (is_array($prices_->tickets->tickets)) {
                                 foreach ($prices_->tickets->tickets as $i => $price) {
                                     if (is_object($price)) {
                                         $duration_s = $price->ticket_start && $price->ticket_end ? FeedValidator::getDateDiff('s', $price->ticket_start, $price->ticket_end) : 0;
                                         $ticket_start = isset($price->ticket_start) ? ESS_Timezone::get_date_GMT(strtotime($price->ticket_start)) : 0;
                                         $ticket_end = isset($price->ticket_end) ? ESS_Timezone::get_date_GMT(strtotime($price->ticket_end)) : 0;
                                         $p = intval($price->ticket_price);
                                         $e_start = strtotime($event_start);
                                         $t_end = strtotime($ticket_end);
                                         $t_mode = $p > 0 ? $e_start < $t_end || $ticket_end == 0 ? 'fixed' : 'prepaid' : 'free';
                                         $newEvent->addPrice('standalone', $t_mode, "hour", NULL, NULL, NULL, NULL, array('name' => strlen($price->ticket_name) > 0 ? $price->ticket_name : sprintf(__("Ticket Nb %s", 'dbem'), $i), 'currency' => get_option('ess_feed_currency', ESS_Database::DEFAULT_CURRENCY), 'value' => intval($price->ticket_price) > 0 ? $price->ticket_price : 0, 'start' => isset($price->ticket_start) ? $ticket_start : '', 'duration' => intval($duration_s) > 0 ? $duration_s / 60 / 60 : 0, 'uri' => $event_url . "#em-booking"));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             // end prices
             // ====== PEOPLE ===========
             $people_ = $EM_Event->get_contact();
             //var_dump( $people_ );
             if ($people_ instanceof EM_Person) {
                 $owner_name = strlen(self::_g('ess_owner_firstname')) > 0 && strlen(self::_g('ess_owner_lastname')) > 0 ? trim(self::_g('ess_owner_firstname') . " " . self::_g('ess_owner_lastname')) : $people_->data->display_name;
                 if (strlen($owner_name) > 0 && get_option('ess_owner_activate')) {
                     $newEvent->addPeople('organizer', array('name' => $owner_name, 'firstname' => self::_g('ess_owner_firstname'), 'lastname' => self::_g('ess_owner_lastname'), 'organization' => self::_g('ess_owner_company'), 'logo' => '', 'icon' => '', 'uri' => self::_g('ess_owner_website'), 'address' => self::_g('ess_owner_address'), 'city' => self::_g('ess_owner_city'), 'zip' => self::_g('ess_owner_zip'), 'state' => self::_g('ess_owner_state'), 'state_code' => '', 'country' => FeedValidator::$COUNTRIES_[strtoupper(self::_g('ess_owner_country'))], 'country_code' => strtolower(self::_g('ess_owner_country')) == 'xe' ? 'GB' : self::_g('ess_owner_country'), 'email' => self::_g('ess_owner_email'), 'phone' => self::_g('ess_owner_phone')));
                 }
                 foreach (ESS_Database::$SOCIAL_PLATFORMS as $type => $socials_) {
                     foreach ($socials_ as $social) {
                         if (FeedValidator::isValidURL(get_option('ess_social_' . $social))) {
                             $newEvent->addPeople('social', array('name' => __(ucfirst($social), 'dbem'), 'uri' => self::_g('ess_social_' . $social)));
                         }
                     }
                 }
                 if (strlen(self::_g('ess_feed_title')) > 0 && FeedValidator::isValidURL(self::_g('ess_feed_website'))) {
                     $newEvent->addPeople('author', array('name' => self::_g('ess_feed_title'), 'uri' => self::_g('ess_feed_website')));
                 }
                 if (strlen($EM_Event->post_excerpt) > 0) {
                     $newEvent->addPeople('attendee', array('name' => __('Required'), 'minpeople' => 0, 'maxpeople' => 0, 'minage' => 0, 'restriction' => esc_html($EM_Event->post_excerpt)));
                 }
             }
             // ====== MEDIA ============
             // -- IMAGES -----
             if (get_option('ess_feed_export_images')) {
                 $IMG_ = array();
                 $media_url = $EM_Event->get_image_url();
                 if (FeedValidator::isValidURL($media_url)) {
                     array_push($IMG_, array('name' => __('Main Image', 'dbem'), 'uri' => $media_url));
                 }
                 $images_ = ESS_Images::get($EM_Event->post_id);
                 if (count($images_) > 0 && $images_ != NULL) {
                     foreach ($images_ as $i => $img_) {
                         array_push($IMG_, array('name' => strlen($img_['name']) > 0 ? $img_['name'] : sprintf(__('Image %d', 'dbem'), $i), 'uri' => $img_['uri']));
                     }
                 }
                 if (count($IMG_) > 0 && $IMG_ != NULL) {
                     $IMG_ = array_map("unserialize", array_unique(array_map("serialize", $IMG_)));
                     $duplicates_ = array();
                     foreach ($IMG_ as $i => $img_) {
                         if (!in_array($img_['uri'], $duplicates_)) {
                             $newEvent->addMedia('image', array('name' => strlen($img_['name']) > 0 ? sprintf(__('Image %d', 'dbem'), $i) : $img_['name'], 'uri' => $img_['uri']));
                         }
                         array_push($duplicates_, $img_['uri']);
                     }
                 }
             }
             // -- SOUNDS -----
             if (get_option('ess_feed_export_sounds')) {
                 // TODO:...
             }
             // -- VIDEOS -----
             if (get_option('ess_feed_export_videos')) {
                 // TODO:...
             }
             // -- WEBSITES -----
             if (FeedValidator::isValidURL(self::_g('ess_feed_website'))) {
                 $newEvent->addMedia('website', array('name' => __('The website', 'dbem'), 'uri' => self::_g('ess_feed_website')));
             }
             $essFeed->addItem($newEvent);
             $count++;
         }
         // -- We've reached the limit of event per feed, or showing one event only
         if (!empty($event_id) || intval($event_id) <= 0 || get_option('ess_feed_limit', $limit) != 0 && $count > get_option('ess_feed_limit', $limit) || $count <= get_option('ess_feed_limit', $limit) && intval($page) <= 1) {
             break;
         } else {
             //-- Go to the next page of results
             $page++;
             self::output($event_id, $page, $is_download, $is_push);
         }
     }
     $essFeed->IS_DOWNLOAD = $is_download === TRUE ? TRUE : FALSE;
     $essFeed->AUTO_PUSH = get_option('ess_feed_push', TRUE) && $is_push === TRUE ? TRUE : FALSE;
     //var_dump( $essFeed );
     $essFeed->genarateFeed();
 }
 private function controlNodeContent($name, $value)
 {
     if (FeedValidator::isNull($value) == FALSE) {
         switch (strtolower($name)) {
             case 'start':
             case 'published':
             case 'updated':
                 return FeedValidator::isValidDate(FeedWriter::getISODate($value));
                 break;
             case 'name':
                 return FeedValidator::isNull($value) == FALSE ? TRUE : FALSE;
                 break;
             case 'email':
                 return FeedValidator::isValidEmail($value);
                 break;
             case 'logo':
             case 'icon':
             case 'uri':
                 return FeedValidator::isValidURL($value);
                 break;
             case 'latitude':
                 return FeedValidator::isValidLatitude($value);
                 break;
             case 'longitude':
                 return FeedValidator::isValidLongitude($value);
                 break;
             case 'country_code':
                 return FeedValidator::isValidCountryCode($value);
                 break;
             case 'currency':
                 return FeedValidator::isValidCurrency($value);
                 break;
             default:
                 return TRUE;
                 break;
         }
     }
     return TRUE;
 }
 /**
  * Simple test to check if the URL targets to an existing file.
  *
  * @param 	String	feed_url	URL of the ess feed file to test
  * @return	Boolean	result		return a boolean value.
  */
 public static function is_feed_valid($feed_url = '')
 {
     global $ESS_Notices;
     if (FeedValidator::isValidURL($feed_url) == FALSE) {
         $ESS_Notices->add_error(sprintf(__("The ESS URL is not valid: <a href='%s' target='_blank'>%s</a>", 'dbem'), $feed_url, $feed_url));
         return FALSE;
     } else {
         $response = json_decode(ESS_IO::get_curl_result(FeedWriter::$VALIDATOR_WS, $feed_url), TRUE);
         //dd( $response );
         if ($response !== FALSE) {
             $r = @$response['result'];
             //dd( $r );
             if (@isset($r['result'])) {
                 if (strlen(@$r['result']['error']) > 1 || @$r['type'] == 'KO') {
                     //d( strlen( @$r['result']['error'] ) );
                     if ($response['result']['error'] == NULL) {
                         $response['result']['error'] = array();
                     }
                     array_unshift($response['result']['error'], "<b>" . sprintf(__("The Feed URL is not a valide ESS file: <a href='%s' target='_blank'>%s</a>", 'dbem'), $feed_url, $feed_url) . "</b><br>");
                     array_push($response['result']['error'], "<b>" . sprintf(__("More information about the standard: <a href='%s' target='_blank'>%s</a>", 'dbem'), ESS_IO::ESS_WEBSITE, ESS_IO::ESS_WEBSITE) . "</b><br>");
                     //dd( $r );
                     $ESS_Notices->add_error($response);
                     return FALSE;
                 }
             }
             return TRUE;
         }
     }
     return FALSE;
 }
 public static function control_export_forms()
 {
     if (!isset($_REQUEST['save_export']) || empty($_REQUEST['save_export'])) {
         return;
     }
     global $ESS_Notices;
     // -- Syndication Settings
     ESS_Database::set_option('ess_syndication_status', @$_REQUEST['ess_syndication_status'] == 'on' ? TRUE : FALSE);
     ESS_Database::set_option('ess_backlink_enabled', @$_REQUEST['ess_backlink_enabled'] == 'on' ? TRUE : FALSE);
     // -- Feed Settings
     ESS_Database::set_option('ess_feed_title', @$_REQUEST['ess_feed_title']);
     ESS_Database::set_option('ess_feed_rights', @$_REQUEST['ess_feed_rights']);
     ESS_Database::set_option('ess_feed_website', @$_REQUEST['ess_feed_website']);
     ESS_Database::set_option('ess_feed_limit', @$_REQUEST['ess_feed_limit']);
     ESS_Database::set_option('ess_feed_category_type', @$_REQUEST['ess_feed_category_type']);
     ESS_Database::set_option('ess_feed_currency', @$_REQUEST['ess_feed_currency']);
     ESS_Database::set_option('ess_feed_language', @$_REQUEST['ess_feed_language']);
     ESS_Database::set_option('ess_feed_timezone', @$_REQUEST['ess_feed_timezone']);
     // -- Feed Visibility
     // -- Global
     ESS_Database::set_option('ess_feed_visibility_web', @$_REQUEST['ess_feed_visibility_web'] == 'on' ? TRUE : FALSE);
     ESS_Database::set_option('ess_feed_visibility_meta', @$_REQUEST['ess_feed_visibility_meta'] == 'on' ? TRUE : FALSE);
     ESS_Database::set_option('ess_feed_push', @$_REQUEST['ess_feed_push'] == 'on' ? TRUE : FALSE);
     // Elements
     ESS_Database::set_option('ess_feed_import_images', @$_REQUEST['ess_feed_import_images'] == 'on' ? TRUE : FALSE);
     ESS_Database::set_option('ess_feed_export_images', @$_REQUEST['ess_feed_export_images'] == 'on' ? TRUE : FALSE);
     ESS_Database::set_option('ess_feed_import_videos', @$_REQUEST['ess_feed_import_videos'] == 'on' ? TRUE : FALSE);
     ESS_Database::set_option('ess_feed_export_videos', @$_REQUEST['ess_feed_export_videos'] == 'on' ? TRUE : FALSE);
     ESS_Database::set_option('ess_feed_import_sounds', @$_REQUEST['ess_feed_import_sounds'] == 'on' ? TRUE : FALSE);
     ESS_Database::set_option('ess_feed_export_sounds', @$_REQUEST['ess_feed_export_sounds'] == 'on' ? TRUE : FALSE);
     // -- Event Organizer
     ESS_Database::set_option('ess_owner_activate', @$_REQUEST['ess_owner_activate'] == 'on' ? TRUE : FALSE);
     ESS_Database::set_option('ess_owner_firstname', @$_REQUEST['ess_owner_firstname']);
     ESS_Database::set_option('ess_owner_lastname', @$_REQUEST['ess_owner_lastname']);
     ESS_Database::set_option('ess_owner_company', @$_REQUEST['ess_owner_company']);
     ESS_Database::set_option('ess_owner_city', @$_REQUEST['ess_owner_city']);
     ESS_Database::set_option('ess_owner_address', @$_REQUEST['ess_owner_address']);
     ESS_Database::set_option('ess_owner_zip', @$_REQUEST['ess_owner_zip']);
     ESS_Database::set_option('ess_owner_state', @$_REQUEST['ess_owner_state']);
     ESS_Database::set_option('ess_owner_country', @$_REQUEST['ess_owner_country']);
     ESS_Database::set_option('ess_owner_website', self::url(@$_REQUEST['ess_owner_website']));
     ESS_Database::set_option('ess_owner_phone', @$_REQUEST['ess_owner_phone']);
     // -- Social Platforms
     foreach (ESS_Database::$SOCIAL_PLATFORMS as $type => $socials_) {
         foreach ($socials_ as $social) {
             $url = $_REQUEST['ess_social_' . $social];
             if (strlen($url) > 10) {
                 if (FeedValidator::isValidURL($url)) {
                     ESS_Database::set_option('ess_social_' . $social, $url);
                 } else {
                     $ESS_Notices->add_error(sprintf(__("The URL you have submited for <b>%s</b> is not valide: <a href='%s' target='_blank'>%s</a>", 'dbem'), $social, $url, $url));
                 }
             }
         }
     }
     if (strlen($ESS_Notices->get_errors()) <= 0) {
         $ESS_Notices->add_info(__("The export setting page have been save correctly.", 'dbem'));
     }
 }
 public function pushToAggregators($feedURL = '', $feedData = NULL)
 {
     if ($this->AUTO_PUSH) {
         $geo_ = self::get_geo();
         $post_data = array('LIBRARY_VERSION' => self::LIBRARY_VERSION, 'REMOTE_ADDR' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'SERVER_ADMIN' => isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_ADMIN'] : '', 'PROTOCOL' => isset($_SERVER['SERVER_PROTOCOL']) ? stripos($_SERVER['SERVER_PROTOCOL'], 'https') === TRUE ? 'https://' : 'http://' : 'http://', 'HTTP_HOST' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'REQUEST_URI' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '', 'GEOIP_LATITUDE' => isset($_SERVER['lat']) ? $geo_['lat'] : '', 'GEOIP_LONGITUDE' => isset($_SERVER['lng']) ? $geo_['lng'] : '');
         if ($feedData == NULL && FeedValidator::isValidURL($feedURL)) {
             $post_data['feed'] = $feedURL;
         } else {
             $post_data['feed_file'] = $feedData;
         }
         // -- submit %_POST data with cURL
         $ch = @curl_init();
         if ($ch != FALSE) {
             curl_setopt($ch, CURLOPT_URL, self::$AGGREGATOR_WS);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_VERBOSE, 1);
             curl_setopt($ch, CURLOPT_FAILONERROR, 1);
             curl_setopt($ch, CURLOPT_TIMEOUT, 20);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
             curl_setopt($ch, CURLOPT_COOKIEJAR, self::tmp() . '/cookies');
             curl_setopt($ch, CURLOPT_REFERER, isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '');
             $result = json_decode(curl_exec($ch), TRUE);
             $this->getAggregatorResponse($result);
             //var_dump( $post_data, $result );
         } else {
             // -- submit %_POST data with file_get_contents()
             if (ini_get('allow_url_fopen')) {
                 $opts = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded", 'content' => http_build_query($post_data), 'timeout' => 60 * 20));
                 $result = file_get_contents(self::$AGGREGATOR_WS, false, stream_context_create($opts), -1, 40000);
                 $this->getAggregatorResponse($result);
             } else {
                 // -- submit (only) %_GET data with "wget -q"
                 if ($feedData == NULL && FeedValidator::isValidURL($feedURL)) {
                     $file = self::$AGGREGATOR_WS . "?";
                     foreach ($post_data as $att => $value) {
                         $file .= $att . "=" . urlencode($value) . "&";
                     }
                     $result = exec("wget -q \"" . $file . "\"");
                 }
             }
         }
     }
 }