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();
 }
 /**
  * Convert an Event feed object contains within the feed (previously parsed by ESS_Import::get_feed_content())
  * into the relevents $_POST[xxx] elements, to be ready to be aggregated by Wordpress.
  *
  * @param 	Array	FEED_	Array that contain the relevent elements of an event.
  * @return 	Boolean	result	return a boolean value.
  *
  */
 public static function set_post_from_feed($FEED_)
 {
     //dd( $FEED_ );
     $_REQUEST['action'] = 'event_save';
     $_REQUEST['event_id'] = 0;
     $_POST['action'] = $_REQUEST['action'];
     $_POST['event_id'] = $_REQUEST['event_id'];
     //dd( $FEED_[ 'generals' ] );
     $event_attr_ = explode(ESS_Feed::CUSTOM_ATTRIBUTE_SEPARATOR, $FEED_['generals']['description']);
     $_POST['event_attributes'] = @count($event_attr_) == 3 && $event_attr_ != NULL && strlen(ESS_Feed::CUSTOM_ATTRIBUTE_SEPARATOR) > 0 ? json_decode(@$event_attr_[1], TRUE) : array();
     $_POST['em_attributes'] = $_POST['event_attributes'];
     $_POST['event_excerpt'] = NULL;
     $_POST['event_slug'] = $FEED_['generals']['id'];
     $_POST['event_name'] = $FEED_['generals']['title'];
     $_POST['content'] = $FEED_['generals']['description'];
     $_POST['event_access'] = $FEED_['generals']['access'];
     //$FEED_[ 'generals' ][ 'uri' ];
     //$FEED_[ 'generals' ][ 'published' ];
     //dd( $_POST );
     $minpeople = 0;
     // can also be in custom attributes...
     $maxpeople = 0;
     // ==== PEOPLE ============================
     if (@count(@$FEED_['people']) > 0 && @$FEED_['people'] != NULL) {
         //dd( $FEED_[ 'people' ] );
         foreach ($FEED_['people'] as $people_) {
             if ($people_['type'] == 'organizer' || $people_['type'] == 'author') {
                 $_POST['event_owner_name'] = !isset($_POST['event_owner_name']) ? @$people_['name'] : $_POST['event_owner_name'];
                 $_POST['event_owner_email'] = !isset($_POST['event_owner_email']) ? @$people_['email'] : $_POST['event_owner_email'];
                 // === element available ===
                 //$people_[ 'firstname' ];
                 //$people_[ 'lastname' ];
                 //$people_[ 'organization' ];
                 //$people_[ 'logo' ];
                 //$people_[ 'icon' ];
                 //$people_[ 'uri' ];
                 //$people_[ 'address' ];
                 //$people_[ 'city' ];
                 //$people_[ 'zip' ];
                 //$people_[ 'state' ];
                 //$people_[ 'state_code' ];
                 //$people_[ 'country' ];
                 //$people_[ 'country_code' ];
                 //$people_[ 'phone' ];
             } else {
                 if ($people_['type'] == 'attendee') {
                     $maxpeople = @$people_['maxpeople'];
                     $minpeople = @$people_['minpeople'];
                     $_POST['event_excerpt'] = trim(@$people_['restriction'] . (intval(@$people_['minage']) > 0 ? " min age:" . $people_['minage'] : ''));
                 } else {
                     if ($people_['type'] == 'social') {
                         //$people_[ 'name' ];
                         //$people_[ 'uri' ];
                     }
                 }
             }
         }
     }
     // ==== DATES ============================
     if (@count(@$FEED_['dates']) > 0 && @$FEED_['dates'] != NULL) {
         $_POST['event_all_day'] = 0;
         //dd( $FEED_[ 'dates' ] );
         $date_ = $FEED_['dates'][0];
         //!\\ TAKE IN CONSIDERATION ONLY THE FIRST FEED DATE
         if (FeedValidator::isValidDate($date_['start'])) {
             $dur = floatval(@$date_['duration']);
             $unit = strtolower(strlen(@$date_['unit']) > 0 ? $date_['unit'] . "s" : ' seconds');
             if ($unit == 'hours' && $dur > 0) {
                 $dur = $dur * 60;
                 $unit = "minutes";
             }
             $myDateTime = new DateTime(@$date_['start'], new DateTimeZone('GMT'));
             $date_start = $myDateTime->format('Y-m-d H:i:s');
             $str_start = $date_start . ($dur > 0 ? " + " . $dur . " " . $unit : "");
             $_POST['event_start_date'] = date('Y-m-d', strtotime($date_start));
             $_POST['event_end_date'] = date('Y-m-d', strtotime($str_start));
             $_POST['event_start_time'] = date('H:i:s', strtotime($date_start));
             $_POST['event_end_time'] = date('H:i:s', strtotime($str_start));
             //dd( $dur, $str_start, strtotime( $str_start ) );
             if ($date_['type'] == 'recurrent') {
                 $sd = explode(',', @$date_['selected_day']);
                 // 'monday','tuesday','wednesday','thursday','friday','saturday','sunday' OR 1,2,3,4,5,6,7,8,9,10,11,12,1,3,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
                 $sw = explode(',', @$date_['selected_week']);
                 // 'first', 'second', 'third', 'fourth', 'last'
                 $u = @$date_['unit'];
                 // 'hour','day','week','month','year'
                 $l = @$date_['limit'];
                 // integer: number of time the recursivity will occure.
                 $delay = "+" . $l . " " . $unit;
                 //echo "delay: ". $delay . " => " .date( DateTime::ATOM, strtotime( @$date_[ 'start' ]. " + ".$dur." seconds" ) );
                 $_POST['recurring'] = TRUE;
                 $_POST['event_end_date'] = date('Y-m-d', strtotime($delay, strtotime($str_start)));
                 $_POST['event_end_time'] = date('H:i:s', strtotime($delay, strtotime($str_start)));
                 $_POST['recurrence_interval'] = @$date_['interval'];
                 $_POST['recurrence_freq'] = $u == 'day' ? 'daily' : ($u == 'week' ? 'weekly' : ($u == 'month' ? 'monthly' : ($u == 'year' ? 'yearly' : 'hourly')));
                 $_POST['recurrence_byweekno'] = "";
                 if (strlen(@$date_['selected_week']) > 0 && @count($sw) > 0) {
                     $_POST['recurrence_byweekno'] = array();
                     foreach ($sw as $i => $sw_v) {
                         array_push($_POST['recurrence_byweekno'], $sw_v == 'first' ? 1 : ($sw_v == 'second' ? 2 : ($sw_v == 'third' ? 3 : ($sw_v == 'fourth' ? 4 : -1))));
                     }
                     $_POST['recurrence_byweekno'] = implode(',', $_POST['recurrence_byweekno']);
                 } else {
                     // if no week number have been specified in the feed attribute "selected_week", get the week number of the event as the default recurent value.
                     if ($u == 'month' && isset($date_['start']) && !isset($date_['selected_day'])) {
                         $ed = $_POST['event_end_date'];
                         $weekno = FeedValidator::getDateDiff('ww', $ed, date(DateTime::ATOM, strtotime('01/' . date('m', $ed) . '/' . date('Y', $ed)))) + 1;
                         $_POST['recurrence_byweekno'] = array($weekno > 4 ? -1 : $weekno);
                     }
                 }
                 $_POST['recurrence_byday'] = $_POST['recurrence_bydays'];
                 $_POST['recurrence_days'] = "";
                 $_POST['recurrence_bydays'] = "";
                 $_POST['recurrence_byday'] = "";
                 if (strlen(@$date_['selected_day']) > 0 && @count($sd) > 0) {
                     $_POST['recurrence_days'] = array();
                     $_POST['recurrence_bydays'] = array();
                     foreach ($sd as $i => $sd_v) {
                         if (intval($sd_v) > 1) {
                             array_push($_POST['recurrence_days'], $sd_v);
                         } else {
                             array_push($_POST['recurrence_bydays'], $sd_v == 'monday' ? 1 : ($sd_v == 'tuesday' ? 2 : ($sd_v == 'wednesday' ? 3 : ($sd_v == 'thursday' ? 4 : ($sd_v == 'friday' ? 5 : ($sd_v == 'saturday' ? 6 : 0))))));
                         }
                     }
                     $_POST['recurrence_bydays'] = implode(',', $_POST['recurrence_bydays']);
                     $_POST['recurrence_days'] = implode(',', $_POST['recurrence_days']);
                 } else {
                     // if no weekday have been specified in the feed attribute "selected_day", get the weekday of the event as the default recurrent day.
                     if ($u == 'week' && isset($date_['start'])) {
                         $weekday = date('N', @$date_['start']);
                         $_POST['recurrence_bydays'] = array($weekday == 7 ? 0 : $weekday);
                     }
                 }
                 $_POST['recurrence_byday'] = $_POST['recurrence_bydays'];
             }
         }
         //dd($_POST);
     }
     // ==== PRICES ===========================
     if (@count(@$FEED_['prices']) > 0 && @$FEED_['prices'] != NULL) {
         //dd( $FEED_[ 'prices' ] );
         $_POST['em_tickets'] = array();
         foreach ($FEED_['prices'] as $price_) {
             $date_start = '';
             $date_end = '';
             $dur = floatval(@$price_['duration']);
             $price_description = trim($price_['value'] . ' ' . @$price_['currency'] . ' ' . @$price_['uri']);
             if (strlen(@$price_['start']) > 0 && $dur > 0) {
                 $date_start = date('Y-m-d H:i:s', strtotime(@$price_['start']));
                 $date_end = date('Y-m-d H:i:s', strtotime(@$price_['start'] . " + " . $dur . " seconds"));
                 //echo "Date Range: ". $date_start ." => " .$date_end;
                 if ($price_['type'] == 'recurrent') {
                     $u = @$price_['unit'];
                     // 'hour','day','week','month','year'
                     $l = @$price_['limit'];
                     // integer: number of time the recurcivity will occure.
                     $price_description .= trim("<br/>Reccurent billing for " . $l . " " . $u);
                     $delay = "+" . $l . " " . $u . ($l > 1 ? 's' : '');
                     //echo "delay: ". $delay . " => " .date( DateTime::ATOM, strtotime( @$price_[ 'start' ]. " + ".$dur." seconds" ) );
                     // Defines the ticket's end date at the end of the recurcivity
                     $date_end = date('Y-m-d H:i:s', strtotime($delay, strtotime($date_start . " + " . $dur . " seconds")));
                 }
             }
             array_push($_POST['em_tickets'], array('event_rsvp_date' => !empty($date_start) ? date('Y-m-d', strtotime($date_start)) : '', 'event_rsvp_time' => !empty($date_start) ? date('H:i:s', strtotime($date_start)) : '', 'ticket_id' => 0, 'ticket_name' => $price_['name'], 'ticket_description' => $price_description, 'booking_comment' => $price_description, 'ticket_price' => $price_['value'], 'ticket_start' => $date_start, 'ticket_end' => $date_end, 'ticket_min' => $minpeople, 'ticket_max' => $maxpeople, 'ticket_spaces' => $maxpeople, 'event_spaces' => $maxpeople, 'ticket_members' => FALSE, 'ticket_guests' => $price_['mode'] == 'invitation' ? TRUE : FALSE, 'ticket_required' => $price_['mode'] != 'free' ? TRUE : FALSE, 'event_rsvp' => TRUE));
             //$_POST['booking_tax_rate'] = '';
             // -- available values:
             //$price[ 'type' ];
             //$price[ 'mode' ];
             //$price[ 'unit' ];
             //$price[ 'interval' ];
             //$price[ 'selected_day' ];
             //$price[ 'selected_week' ];
             //$price[ 'limit' ];
             //$price[ 'value' ];
             //$price[ 'name' ];
             //$price[ 'start' ];
             //$price[ 'duration' ];
             //$price[ 'currency' ];
             //$price[ 'uri' ];
         }
     }
     // ==== PLACES ===========================
     if (@count(@$FEED_['places']) > 0 && @$FEED_['places'] != NULL) {
         //dd( $FEED_[ 'places' ] );
         $place_ = $FEED_['places'][0];
         //!\\ TAKE IN CONSIDERATION ONLY THE FIRST FEED'S PLACE
         if (empty($place_['name'])) {
             $_POST['no_location'] = TRUE;
         } else {
             $_POST['no_location'] = FALSE;
             $_POST['location_name'] = $place_['name'];
             $_POST['location_address'] = strlen(@$place_['address']) > 0 ? $place_['address'] : $place_['name'];
             $_POST['location_town'] = @$place_['city'];
             $_POST['location_state'] = @$place_['state_code'];
             $_POST['location_postcode'] = @$place_['zip'];
             $_POST['location_region'] = @$place_['state'];
             $_POST['location_country'] = @$place_['country_code'];
             $_POST['location_latitude'] = @$place_['latitude'];
             $_POST['location_longitude'] = @$place_['longitude'];
         }
     } else {
         $_POST['no_location'] = TRUE;
     }
     // ==== TAGS =============================
     if (@count(@$FEED_['tags']) > 0 && @$FEED_['tags'] != NULL) {
         //dd( $FEED_[ 'tags' ] );
         $tags_ = array();
         foreach ($FEED_['tags'] as $i => $tag) {
             if (strlen($tag) > 1 && is_numeric($tag) == FALSE) {
                 array_push($tags_, $tag);
             }
         }
         if (count($tags_) > 0) {
             $_POST['event_tags'] = $tags_;
         }
     }
     // ==== CATEGORIES ==========================
     if (@count(@$FEED_['categories']) > 0 && @$FEED_['categories'] != NULL) {
         //dd( $FEED_[ 'categories' ] );
         $_POST['event_categories'] = array();
         foreach ($FEED_['categories'] as $i => $cat) {
             array_push($_POST['event_categories'], $cat['name']);
         }
     }
     // ==== MEDIA ============================
     if (@count(@$FEED_['media']) > 0 && @$FEED_['media'] != NULL) {
         //dd( $FEED_[ 'media' ] );
         $_POST['event_media'] = array();
         foreach ($FEED_['media'] as $i => $media_) {
             //dd( $media_ );
             if (FeedValidator::isValidURL($media_['uri'])) {
                 array_push($_POST['event_media'], array('uri' => $media_['uri'], 'name' => $media_['name'], 'type' => FeedValidator::getMediaType($media_['uri']), 'priority' => $media_['priority']));
             }
         }
     }
     return TRUE;
 }