ts = true;
}else{
$loc_truly_exists = $wpdb->get_var('SELECT post_id FROM '.EM_LOCATIONS_TABLE." WHERE location_id={$this->location_id}") == $this->post_id;
}
}else{
$loc_truly_exists = false;
}
//save all the meta
if( empty($this->location_id) || !$loc_truly_exists ){
$this->previous_status = 0; //for sure this was previously status 0
if ( !$wpdb->insert(EM_LOCATIONS_TABLE, $location_array) ){
$this->add_error( sprintf(__('Something went wrong saving your %s to the index table. Please inform a site administrator about this.','events-manager'),__('location','events-manager')));
}else{
//success, so link the event with the post via an event id meta value for easy retrieval
$this->location_id = $wpdb->insert_id;
update_post_meta($this->post_id, '_location_id', $this->location_id);
$this->feedback_message = sprintf(__('Successfully saved %s','events-manager'),__('Location','events-manager'));
}
}else{
$this->get_previous_status();
if ( $wpdb->update(EM_LOCATIONS_TABLE, $location_array, array('location_id'=>$this->location_id)) === false ){
$this->add_error( sprintf(__('Something went wrong updating your %s to the index table. Please inform a site administrator about this.','events-manager'),__('location','events-manager')));
}else{
$this->feedback_message = sprintf(__('Successfully saved %s','events-manager'),__('Location','events-manager'));
//Also set the status here if status != previous status
if( $this->previous_status != $this->get_status() ) $this->set_status($this->get_status());
}
//check anonymous submission information
if( !empty($this->owner_anonymous) && get_option('dbem_events_anonymous_user') != $this->location_owner ){
//anonymous user owner has been replaced with a valid wp user account, so we remove anonymous status flag but leave email and name for future reference
update_post_meta($this->post_id, '_owner_anonymous', 0);
}elseif( get_option('dbem_events_anonymous_submissions') && get_option('dbem_events_anonymous_user') == $this->location_owner && is_email($this->owner_email) && !empty($this->owner_name) ){
//anonymous user account has been reinstated as the owner, so we can restore anonymous submission status
update_post_meta($this->post_id, '_owner_anonymous', 1);
}
}
}else{
$this->add_error( sprintf(__('You do not have permission to create/edit %s.','events-manager'), __('locations','events-manager')) );
}
$this->compat_keys();
$result = count($this->errors) == 0;
return apply_filters('em_location_save_meta', count($this->errors) == 0, $this);
}
function delete($force_delete = false){
$result = false;
if( $this->can_manage('delete_locations','delete_others_locations') ){
if( !is_admin() ){
include_once('em-location-post-admin.php');
if( !defined('EM_LOCATION_DELETE_INCLUDE') ){
EM_Location_Post_Admin::init();
define('EM_LOCATION_DELETE_INCLUDE',true);
}
}
do_action('em_location_delete_pre', $this);
if( $force_delete ){
$result = wp_delete_post($this->post_id,$force_delete);
}else{
$result = wp_trash_post($this->post_id);
if( !$result && $this->post_status == 'trash' && $this->location_status != -1 ){
//we're probably dealing with a trashed post already, which will return a false with wp_trash_post, but the location_status is null from < v5.4.1 so refresh it
$this->set_status(-1);
$result = true;
}
}
if( !$result && !empty($this->orphaned_location) ){
//this is an orphaned event, so the wp delete posts would have never worked, so we just delete the row in our locations table
$result = $this->delete_meta();
}
}
return apply_filters('em_location_delete', $result != false, $this);
}
function delete_meta(){
global $wpdb;
$result = false;
if( $this->can_manage('delete_locations','delete_others_locations') ){
do_action('em_location_delete_meta_pre', $this);
$result = $wpdb->query ( $wpdb->prepare("DELETE FROM ". EM_LOCATIONS_TABLE ." WHERE location_id=%d", $this->location_id) );
}
return apply_filters('em_location_delete_meta', $result !== false, $this);
}
function is_published(){
return apply_filters('em_location_is_published', ($this->post_status == 'publish' || $this->post_status == 'private'), $this);
}
/**
* Change the status of the location. This will save to the Database too.
* @param int $status A number to change the status to, which may be -1 for trash, 1 for publish, 0 for pending or null if draft.
* @param boolean $set_post_status If set to true the wp_posts table status will also be changed to the new corresponding status.
* @return string
*/
function set_status($status, $set_post_status = false){
global $wpdb;
//decide on what status to set and update wp_posts in the process
if($status === null){
$set_status='NULL'; //draft post
if($set_post_status){
//if the post is trash, don't untrash it!
$wpdb->update( $wpdb->posts, array( 'post_status' => 'draft' ), array( 'ID' => $this->post_id ) );
}
$this->post_status = 'draft';
}elseif( $status == -1 ){ //trashed post
$set_status = -1;
if($set_post_status){
//set the post status of the location in wp_posts too
$wpdb->update( $wpdb->posts, array( 'post_status' => 'trash' ), array( 'ID' => $this->post_id ) );
}
$this->post_status = 'trash'; //set post status in this instance
}else{
$set_status = $status ? 1:0; //published or pending post
$post_status = $set_status ? 'publish':'pending';
if( empty($this->post_name) ){
//published or pending posts should have a valid post slug
$slug = sanitize_title($this->post_title);
$this->post_name = wp_unique_post_slug( $slug, $this->post_id, $post_status, EM_POST_TYPE_LOCATION, 0);
$set_post_name = true;
}
if($set_post_status){
$wpdb->update( $wpdb->posts, array( 'post_status' => $post_status, 'post_name' => $this->post_name ), array( 'ID' => $this->post_id ) );
}elseif( !empty($set_post_name) ){
//if we've added a post slug then update wp_posts anyway
$wpdb->update( $wpdb->posts, array( 'post_name' => $this->post_name ), array( 'ID' => $this->post_id ) );
}
$this->post_status = $post_status;
}
//save in the wp_em_locations table
$this->previous_status = $wpdb->get_var('SELECT location_status FROM '.EM_LOCATIONS_TABLE.' WHERE location_id='.$this->location_id); //get status from db, not post_status, as posts get saved quickly
$result = $wpdb->query($wpdb->prepare("UPDATE ".EM_LOCATIONS_TABLE." SET location_status=$set_status, location_slug=%s WHERE location_id=%d", array($this->post_name, $this->location_id)));
$this->get_status(); //reload status
return apply_filters('em_location_set_status', $result !== false, $status, $this);
}
/**
* Gets the parent of this location, if none exists, null is returned.
* @return EM_Location|null
*/
public function get_parent(){
if( $this->location_parent ){
return em_get_location( $this->location_parent );
}
return null;
}
function get_status($db = false){
switch( $this->post_status ){
case 'private':
$this->location_private = 1;
$this->location_status = $status = 1;
break;
case 'publish':
$this->location_private = 0;
$this->location_status = $status = 1;
break;
case 'pending':
$this->location_private = 0;
$this->location_status = $status = 0;
break;
case 'trash':
$this->location_private = 0;
$this->location_status = $status = -1;
break;
default: //draft or unknown
$this->location_private = 0;
$status = $db ? 'NULL':null;
$this->location_status = null;
break;
}
return $status;
}
function get_previous_status( $force = false ){
global $wpdb;
if( $this->previous_status === false || $force ){
$this->previous_status = $wpdb->get_var('SELECT location_status FROM '.EM_LOCATIONS_TABLE.' WHERE location_id='.$this->location_id); //get status from db, not post_status
}
return $this->previous_status;
}
/**
* @param $criteria
* @return mixed|void
* @deprecated Since 5.9.8.2 - Was never used, assume this may be removed eventually and copy code into your own custom implementation if necessary.
*/
function load_similar($criteria){
global $wpdb;
if( !empty($criteria['location_name']) && !empty($criteria['location_address']) && !empty($criteria['location_town']) && !empty($criteria['location_state']) && !empty($criteria['location_postcode']) && !empty($criteria['location_country']) ){
$locations_table = EM_LOCATIONS_TABLE;
$prepared_sql = $wpdb->prepare("SELECT * FROM $locations_table WHERE location_name = %s AND location_address = %s AND location_town = %s AND location_state = %s AND location_postcode = %s AND location_country = %s", stripcslashes($criteria['location_name']), stripcslashes($criteria['location_address']), stripcslashes($criteria['location_town']), stripcslashes($criteria['location_state']), stripcslashes($criteria['location_postcode']), stripcslashes($criteria['location_country']) );
//$wpdb->show_errors(true);
$location = $wpdb->get_row($prepared_sql, ARRAY_A);
if( is_array($location) ){
$this->to_object($location);
}
return apply_filters('em_location_load_similar', $location, $this);
}
return apply_filters('em_location_load_similar', false, $this);
}
function has_events( $status = 1 ){
global $wpdb;
$events_count = EM_Events::count(array('location_id' => $this->location_id, 'status' => $status));
return apply_filters('em_location_has_events', $events_count > 0, $this);
}
/**
* Can the user manage this location?
*/
function can_manage( $owner_capability = false, $admin_capability = false, $user_to_check = false ){
if( $this->location_id == '' && !is_user_logged_in() && get_option('dbem_events_anonymous_submissions') ){
$user_to_check = get_option('dbem_events_anonymous_user');
}
if( $admin_capability && EM_MS_GLOBAL && get_site_option('dbem_ms_mainblog_locations') ){
//if in global mode with locations restricted to main blog, we check capabilities against the main blog
self::ms_global_switch();
$return = parent::can_manage($owner_capability, $admin_capability, $user_to_check);
self::ms_global_switch_back();
}else{
$return = parent::can_manage($owner_capability, $admin_capability, $user_to_check);
}
return apply_filters('em_location_can_manage', $return, $this, $owner_capability, $admin_capability, $user_to_check);
}
function get_permalink(){
if( EM_MS_GLOBAL ){
//if no blog id defined, assume it belongs to the main blog
$blog_id = empty($this->blog_id) ? get_current_site()->blog_id:$this->blog_id;
if( get_site_option('dbem_ms_mainblog_locations') ){
//all locations belong to the main blog
$link = get_blog_permalink( get_current_site()->blog_id, $this->post_id);
}elseif( $blog_id != get_current_blog_id() ){
//decide whether to give a link to the blog the location originates from or to show it on the main site
if( !get_site_option('dbem_ms_global_locations_links') && is_main_site() && get_option('dbem_locations_page') ){
//showing subsite locations on main site, create a custom link
$link = trailingslashit(get_permalink(get_option('dbem_locations_page')).get_site_option('dbem_ms_locations_slug',EM_LOCATION_SLUG).'/'.$this->location_slug.'-'.$this->location_id);
}else{
//if location doesn't belong to current blog and/or if main blog doesn't have a locations page, link directly to the blog it belongs to
$link = get_blog_permalink( $blog_id, $this->post_id);
}
}
}
if( empty($link) ){
$link = get_post_permalink($this->post_id);
}
return apply_filters('em_location_get_permalink', $link, $this); ;
}
function get_ical_url(){
global $wp_rewrite;
if( !empty($wp_rewrite) && $wp_rewrite->using_permalinks() ){
$return = trailingslashit($this->get_permalink()).'ical/';
}else{
$return = em_add_get_params($this->get_permalink(), array('ical'=>1));
}
return apply_filters('em_location_get_ical_url', $return);
}
function get_rss_url(){
global $wp_rewrite;
if( !empty($wp_rewrite) && $wp_rewrite->using_permalinks() ){
$return = trailingslashit($this->get_permalink()).'feed/';
}else{
$return = em_add_get_params($this->get_permalink(), array('feed'=>1));
}
return apply_filters('em_location_get_rss_url', $return);
}
/*
* Extends the default EM_Object function by switching blogs as needed if in MS Global mode
* @param string $size
* @return string
* @see EM_Object::get_image_url()
*/
function get_image_url($size = 'full'){
if( EM_MS_GLOBAL && get_current_blog_id() != $this->blog_id ){
switch_to_blog($this->blog_id);
$switch_back = true;
}
$return = parent::get_image_url($size);
if( !empty($switch_back) ){ restore_current_blog(); }
return $return;
}
function get_edit_url(){
if( $this->can_manage('edit_locations','edit_others_locations') ){
if( EM_MS_GLOBAL ){
global $current_site, $current_blog;
if( get_site_option('dbem_ms_mainblog_locations') ){
//location stored as post on main blog, but can be edited either in sub-blog admin area or if not on main blog
if( get_blog_option($this->blog_id, 'dbem_edit_locations_page') && !is_admin() ){
$link = em_add_get_params(get_blog_permalink($this->blog_id, get_blog_option($this->blog_id, 'dbem_edit_locations_page')), array('action'=>'edit','location_id'=>$this->location_id), false);
}
if( (is_main_site() || empty($link)) && get_blog_option($current_site->blog_id, 'dbem_edit_locations_page') && !is_admin() ){ //if editing on main site and edit page exists, stay on same site
$link = em_add_get_params(get_blog_permalink(get_option('dbem_edit_locations_page')), array('action'=>'edit','location_id'=>$this->location_id), false);
}
if( empty($link) && !is_main_site() ){
$link = get_admin_url($current_blog->blog_id, "edit.php?post_type=event&page=locations&action=edit&location_id={$this->location_id}");
}elseif( empty($link) && is_main_site() ){
$link = get_admin_url($current_site->blog_id, "post.php?post={$this->post_id}&action=edit");
}
}else{
//location stored as post on blog where location was created
if( get_blog_option($this->blog_id, 'dbem_edit_locations_page') && !is_admin() ){
$link = em_add_get_params(get_blog_permalink($this->blog_id, get_blog_option($this->blog_id, 'dbem_edit_locations_page')), array('action'=>'edit','location_id'=>$this->location_id), false);
}
if( (is_main_site() || empty($link)) && get_blog_option($current_site->blog_id, 'dbem_edit_locations_page') && !is_admin() ){ //if editing on main site and edit page exists, stay on same site
$link = em_add_get_params(get_blog_permalink($current_site->blog_id, get_blog_option($current_site->blog_id, 'dbem_edit_locations_page')), array('action'=>'edit','location_id'=>$this->location_id), false);
}
if( empty($link)){
$link = get_admin_url($this->blog_id, "post.php?post={$this->post_id}&action=edit");
}
}
}else{
if( get_option('dbem_edit_locations_page') && !is_admin() ){
$link = em_add_get_params(get_permalink(get_option('dbem_edit_locations_page')), array('action'=>'edit','location_id'=>$this->location_id), false);
}
if( empty($link))
$link = admin_url()."post.php?post={$this->post_id}&action=edit";
}
return apply_filters('em_location_get_edit_url', $link, $this);
}
}
function output_single($target = 'html'){
$format = get_option ( 'dbem_single_location_format' );
return apply_filters('em_location_output_single', $this->output($format, $target), $this, $target);
}
function output($format, $target="html") {
$location_string = $format;
//First let's do some conditional placeholder removals
for ($i = 0 ; $i < EM_CONDITIONAL_RECURSIONS; $i++){ //you can add nested recursions by modifying this setting in your wp_options table
preg_match_all('/\{([a-zA-Z0-9_]+)\}(.+?)\{\/\1\}/s', $location_string, $conditionals);
if( count($conditionals[0]) > 0 ){
//Check if the language we want exists, if not we take the first language there
foreach($conditionals[1] as $key => $condition){
$show_condition = false;
if ($condition == 'has_loc_image'){
//does this event have an image?
$show_condition = ( $this->get_image_url() != '' );
}elseif ($condition == 'no_loc_image'){
//does this event have an image?
$show_condition = ( $this->get_image_url() == '' );
}elseif ($condition == 'has_events'){
//does this location have any events
$show_condition = $this->has_events();
}elseif ($condition == 'no_events'){
//does this location NOT have any events?
$show_condition = $this->has_events() == false;
}
$show_condition = apply_filters('em_location_output_show_condition', $show_condition, $condition, $conditionals[0][$key], $this);
if($show_condition){
//calculate lengths to delete placeholders
$placeholder_length = strlen($condition)+2;
$replacement = substr($conditionals[0][$key], $placeholder_length, strlen($conditionals[0][$key])-($placeholder_length *2 +1));
}else{
$replacement = '';
}
$location_string = str_replace($conditionals[0][$key], apply_filters('em_location_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $location_string);
}
}
}
//This is for the custom attributes
preg_match_all('/#_LATT\{([^}]+)\}(\{([^}]+)\})?/', $location_string, $results);
foreach($results[0] as $resultKey => $result) {
//check that we haven't mistakenly captured a closing bracket in second bracket set
if( !empty($results[3][$resultKey]) && $results[3][$resultKey][0] == '/' ){
$result = $results[0][$resultKey] = str_replace($results[2][$resultKey], '', $result);
$results[3][$resultKey] = $results[2][$resultKey] = '';
}
//Strip string of placeholder and just leave the reference
$attRef = substr( substr($result, 0, strpos($result, '}')), 7 );
$attString = '';
$placeholder_atts = array('#_ATT', $results[1][$resultKey]);
if( is_array($this->location_attributes) && array_key_exists($attRef, $this->location_attributes) ){
$attString = $this->location_attributes[$attRef];
}elseif( !empty($results[3][$resultKey]) ){
//Check to see if we have a second set of braces;
$placeholder_atts[] = $results[3][$resultKey];
$attStringArray = explode('|', $results[3][$resultKey]);
$attString = $attStringArray[0];
}elseif( !empty($attributes['values'][$attRef][0]) ){
$attString = $attributes['values'][$attRef][0];
}
$attString = apply_filters('em_location_output_placeholder', $attString, $this, $result, $target, $placeholder_atts);
$location_string = str_replace($result, $attString ,$location_string );
}
preg_match_all("/(#@?_?[A-Za-z0-9_]+)({([^}]+)})?/", $location_string, $placeholders);
$replaces = array();
foreach($placeholders[1] as $key => $result) {
$replace = '';
$full_result = $placeholders[0][$key];
$placeholder_atts = array($result);
if( !empty($placeholders[3][$key]) ) $placeholder_atts[] = $placeholders[3][$key];
switch( $result ){
case '#_LOCATIONID':
$replace = $this->location_id;
break;
case '#_LOCATIONPOSTID':
$replace = $this->post_id;
break;
case '#_NAME': //Depricated
case '#_LOCATION': //Depricated
case '#_LOCATIONNAME':
$replace = $this->location_name;
break;
case '#_ADDRESS': //Depricated
case '#_LOCATIONADDRESS':
$replace = $this->location_address;
break;
case '#_TOWN': //Depricated
case '#_LOCATIONTOWN':
$replace = $this->location_town;
break;
case '#_LOCATIONSTATE':
$replace = $this->location_state;
break;
case '#_LOCATIONPOSTCODE':
$replace = $this->location_postcode;
break;
case '#_LOCATIONREGION':
$replace = $this->location_region;
break;
case '#_LOCATIONCOUNTRY':
$replace = $this->get_country();
break;
case '#_LOCATIONFULLLINE':
case '#_LOCATIONFULLBR':
$glue = $result == '#_LOCATIONFULLLINE' ? ', ':'
';
$replace = $this->get_full_address($glue);
break;
case '#_MAP': //Deprecated (but will remain)
case '#_LOCATIONMAP':
if( get_option('dbem_gmap_is_active') ){
ob_start();
$args = array();
if( !empty($placeholders[3][$key]) ){
$dimensions = explode(',', $placeholders[3][$key]);
if(!empty($dimensions[0])) $args['width'] = $dimensions[0];
if(!empty($dimensions[1])) $args['height'] = $dimensions[1];
}
em_locate_template('placeholders/locationmap.php', true, array('args'=>$args,'EM_Location'=>$this));
$replace = ob_get_clean();
}
break;
case '#_LOCATIONLONGITUDE':
$replace = $this->location_longitude;
break;
case '#_LOCATIONLATITUDE':
$replace = $this->location_latitude;
break;
case '#_DESCRIPTION': //Deprecated
case '#_LOCATIONNOTES':
$replace = $this->post_content;
break;
case '#_EXCERPT': //Deprecated
case '#_LOCATIONEXCERPT':
case '#_LOCATIONEXCERPTCUT':
if( !empty($this->post_excerpt) && $result != "#_LOCATIONEXCERPTCUT" ){
$replace = $this->post_excerpt;
}else{
$excerpt_length = ( $result == "#_LOCATIONEXCERPTCUT" ) ? 55 : false;
$excerpt_more = apply_filters('em_excerpt_more', ' ' . '[...]');
if( !empty($placeholders[3][$key]) ){
$ph_args = explode(',', $placeholders[3][$key]);
if( is_numeric($ph_args[0]) || empty($ph_args[0]) ) $excerpt_length = $ph_args[0];
if( !empty($ph_args[1]) ) $excerpt_more = $ph_args[1];
}
$replace = $this->output_excerpt($excerpt_length, $excerpt_more, $result == "#_LOCATIONEXCERPTCUT");
}
break;
case '#_LOCATIONIMAGEURL':
case '#_LOCATIONIMAGE':
$image_url = $this->get_image_url();
if( $image_url != ''){
$image_url = esc_url($image_url);
if($result == '#_LOCATIONIMAGEURL'){
$replace = $image_url;
}else{
if( empty($placeholders[3][$key]) ){
$replace = "";
}else{
$image_size = explode(',', $placeholders[3][$key]);
if( self::array_is_numeric($image_size) && count($image_size) > 1 ){
if( EM_MS_GLOBAL && get_current_blog_id() != $this->blog_id ){
//get a thumbnail
if( get_option('dbem_disable_thumbnails') ){
$image_attr = '';
$image_args = array();
if( empty($image_size[1]) && !empty($image_size[0]) ){
$image_attr = 'width="'.$image_size[0].'"';
$image_args['w'] = $image_size[0];
}elseif( empty($image_size[0]) && !empty($image_size[1]) ){
$image_attr = 'height="'.$image_size[1].'"';
$image_args['h'] = $image_size[1];
}elseif( !empty($image_size[0]) && !empty($image_size[1]) ){
$image_attr = 'width="'.$image_size[0].'" height="'.$image_size[1].'"';
$image_args = array('w'=>$image_size[0], 'h'=>$image_size[1]);
}
$replace = "";
}else{
//location belongs to another blog, so switch blog then call the default wp fucntion
if( EM_MS_GLOBAL && get_current_blog_id() != $this->blog_id ){
switch_to_blog($this->blog_id);
$switch_back = true;
}
$replace = get_the_post_thumbnail($this->ID, $image_size, array('alt' => esc_attr($this->location_name)) );
if( !empty($switch_back) ){ restore_current_blog(); }
}
}else{
$replace = get_the_post_thumbnail($this->ID, $image_size);
}
}else{
$replace = "";
}
}
}
}
break;
case '#_LOCATIONURL':
case '#_LOCATIONLINK':
case '#_LOCATIONPAGEURL': //Depricated
$link = esc_url($this->get_permalink());
$replace = ($result == '#_LOCATIONURL' || $result == '#_LOCATIONPAGEURL') ? $link : ''.esc_html($this->location_name).'';
break;
case '#_LOCATIONEDITURL': // Deprecated - always worked but documented as #_EDITLOCATIONURL
case '#_LOCATIONEDITLINK': // Deprecated - always worked but documented incorrectly as #_EDITLOCATIONLINK
case '#_EDITLOCATIONURL':
case '#_EDITLOCATIONLINK':
if( $this->can_manage('edit_locations','edit_others_locations') ){
$link = esc_url($this->get_edit_url());
$replace = ($result == '#_LOCATIONEDITURL' || $result == '#_EDITLOCATIONURL' ) ? $link : ''.esc_html(sprintf(__('Edit Location','events-manager'))).'';
}
break;
case '#_LOCATIONICALURL':
case '#_LOCATIONICALLINK':
$replace = $this->get_ical_url();
if( $result == '#_LOCATIONICALLINK' ){
$replace = 'iCal';
}
break;
case '#_LOCATIONWEBCALURL':
case '#_LOCATIONWEBCALLINK':
$replace = $this->get_ical_url();
$replace = str_replace(array('http://','https://'), 'webcal://', $replace);
if( $result == '#_LOCATIONWEBCALLINK' ){
$replace = 'Webcal';
}
break;
case '#_LOCATIONRSSURL':
case '#_LOCATIONRSSLINK':
$replace = $this->get_rss_url();
if( $result == '#_LOCATIONRSSLINK' ){
$replace = 'RSS';
}
break;
case '#_PASTEVENTS': //Depricated
case '#_LOCATIONPASTEVENTS':
case '#_NEXTEVENTS': //Depricated
case '#_LOCATIONNEXTEVENTS':
case '#_ALLEVENTS': //Depricated
case '#_LOCATIONALLEVENTS':
//TODO: add limit to lists of events
//convert deprecated placeholders for compatability
$result = ($result == '#_PASTEVENTS') ? '#_LOCATIONPASTEVENTS':$result;
$result = ($result == '#_NEXTEVENTS') ? '#_LOCATIONNEXTEVENTS':$result;
$result = ($result == '#_ALLEVENTS') ? '#_LOCATIONALLEVENTS':$result;
//forget it ever happened? :/
if ( $result == '#_LOCATIONPASTEVENTS'){ $scope = 'past'; }
elseif ( $result == '#_LOCATIONNEXTEVENTS' ){ $scope = 'future'; }
else{ $scope = 'all'; }
$args = array('location'=>$this->location_id, 'scope'=>$scope, 'pagination'=>1, 'ajax'=>0);
$args['format_header'] = get_option('dbem_location_event_list_item_header_format');
$args['format_footer'] = get_option('dbem_location_event_list_item_footer_format');
$args['format'] = get_option('dbem_location_event_list_item_format');
$args['no_results_msg'] = get_option('dbem_location_no_events_message');
$args['limit'] = !empty($placeholders[3][$key]) && is_numeric($placeholders[3][$key]) ? absint($placeholders[3][$key]) : get_option('dbem_location_event_list_limit');
$args['orderby'] = get_option('dbem_location_event_list_orderby');
$args['order'] = get_option('dbem_location_event_list_order');
$args['page'] = (!empty($_REQUEST['pno']) && is_numeric($_REQUEST['pno']) )? $_REQUEST['pno'] : 1;
if( $target == 'email' || !empty($placeholders[3][$key]) ){
$args['pagination'] = 0;
$args['page'] = 1;
}
$replace = EM_Events::output($args);
break;
case '#_LOCATIONNEXTEVENT':
$events = EM_Events::get( array('location'=>$this->location_id, 'scope'=>'future', 'limit'=>1, 'orderby'=>'event_start_date,event_start_time') );
$replace = get_option('dbem_location_no_event_message');
foreach($events as $EM_Event){
$replace = $EM_Event->output(get_option('dbem_location_event_single_format'));
}
break;
default:
$replace = $full_result;
break;
}
$replaces[$full_result] = apply_filters('em_location_output_placeholder', $replace, $this, $full_result, $target, $placeholder_atts);
}
//sort out replacements so that during replacements shorter placeholders don't overwrite longer varieties.
krsort($replaces);
foreach($replaces as $full_result => $replacement){
if( !in_array($full_result, array('#_DESCRIPTION','#_LOCATIONNOTES')) ){
$location_string = str_replace($full_result, $replacement , $location_string );
}else{
$desc_replace[$full_result] = $replacement;
}
}
//Finally, do the location notes, so that previous placeholders don't get replaced within the content, which may use shortcodes
if( !empty($desc_replace) ){
foreach($desc_replace as $full_result => $replacement){
$location_string = str_replace($full_result, $replacement , $location_string );
}
}
return apply_filters('em_location_output', $location_string, $this, $format, $target);
}
function get_country(){
$countries = em_get_countries();
if( !empty($countries[$this->location_country]) ){
return apply_filters('em_location_get_country', $countries[$this->location_country], $this);
}
return apply_filters('em_location_get_country', false, $this);
}
function get_full_address($glue = ', ', $include_country = false){
$location_array = array();
if( !empty($this->location_address) ) $location_array[] = $this->location_address;
if( !empty($this->location_town) ) $location_array[] = $this->location_town;
if( !empty($this->location_state) ) $location_array[] = $this->location_state;
if( !empty($this->location_postcode) ) $location_array[] = $this->location_postcode;
if( !empty($this->location_region) ) $location_array[] = $this->location_region;
if( $include_country ) $location_array[] = $this->get_country();
return implode($glue, $location_array);
}
function get_google_maps_embed_url(){
//generate the map url
$latlng = $this->location_latitude.','.$this->location_longitude;
$args = apply_filters('em_location_google_maps_embed_args', array(
'maptype' => 'roadmap',
'zoom' => 15,
'key' => get_option('dbem_google_maps_browser_key')
), $this);
if( get_option('dbem_gmap_embed_type') == 'place' ){
$args['q'] = urlencode($this->location_name.', '. $this->get_full_address());
}elseif( get_option('dbem_gmap_embed_type') == 'address' ){
$args['q'] = urlencode($this->get_full_address());
}else{
$args['q'] = $latlng;
}
$url = add_query_arg( $args, "https://www.google.com/maps/embed/v1/place");
return apply_filters('em_location_get_google_maps_embed_url', $url, $this);
}
public function to_api(){
return array (
'name' => $this->location_name,
'id' => $this->location_id,
'parent' => $this->location_parent,
'post_id' => $this->post_id,
'blog_id' => $this->blog_id,
'owner' => $this->location_owner,
'status' => $this->location_status,
'slug' => $this->location_slug,
'content' => $this->post_content,
'geo' => array(
'latitude' => $this->location_latitude,
'longitude' => $this->location_longitude,
),
'address' => array(
'address' => $this->location_address,
'town' => $this->location_town,
'region' => $this->location_region,
'state' => $this->location_state,
'postcode' => $this->location_postcode,
'country' => $this->location_country,
),
'language' => $this->location_language,
'translation' => $this->location_translation,
);
}
}