/** * Looks at the request values, saves/updates and then displays the right menu in the admin * @return null */ function em_admin_locations_page() { //TODO EM_Location is globalized, use it fully here global $EM_Location; //Take actions if (!empty($_REQUEST['action']) || !empty($_REQUEST['location_id'])) { if ($_REQUEST['action'] == "edit" || $_REQUEST['action'] == "add") { //edit/add location em_admin_location(); } elseif ($_REQUEST['action'] == "delete") { //delelte location $locations = $_REQUEST['locations']; foreach ($locations as $location_id) { $EM_Location = new EM_Location($location_id); $EM_Location->delete(); } em_admin_locations(__('Locations Deleted', "dbem")); } elseif ($_REQUEST['action'] == "save") { // save (add/update) location if (empty($EM_Location) || !is_object($EM_Location)) { $EM_Location = new EM_Location(); //blank location $success_message = __('The location has been added.', 'dbem'); } else { $success_message = __('The location has been updated.', 'dbem'); } $EM_Location->get_post(); $validation_result = $EM_Location->validate(); if ($validation_result) { $EM_Location->save(); //FIXME better handling of db write fails when saving location em_admin_locations($success_message); } else { ?> <div id='message' class='error '> <p> <strong><?php _e("Ach, there's a problem here:", "dbem"); ?> </strong><br /><br /><?php echo implode('<br />', $EM_Location->errors); ?> </p> </div> <?php unset($EM_Location); em_admin_location(); } } } else { // no action, just a locations list em_admin_locations(); } }
function em_docs_init() { if (class_exists('EM_Event')) { add_action('wp_head', 'emd_head'); //Generate the docs global $EM_Documentation; $EM_Event = new EM_Event(); $event_fields = $EM_Event->get_fields(true); $EM_Location = new EM_Location(); $location_fields = $EM_Location->get_fields(true); $EM_Documentation = array('arguments' => array('events' => array('search' => array('default' => __('Do a search for this string within event name, details and location address.', 'dbem')), 'limit' => array('default' => __('See the events lists limit option on the settings page.', 'dbem')), 'orderby' => array('desc' => __('Choose what fields to order your results by. You can supply a single field or multiple comma-seperated fields (e.g. "start_date,name").', 'dbem'), 'default' => __('See the event lists ordering option on the settings page.', 'dbem'), 'args' => 'name, start_date, start_time, end_date, end_time'), 'order' => array('default' => __('See the event lists ordering option on the settings page.', 'dbem'))), 'locations' => array('eventful' => array('desc' => __('If set to 1 will only show locations that have at least one event occurring during the scope.', 'dbem'), 'default' => 0), 'eventless' => array('desc' => __('If set to 1 will only show locations that have no events occurring during the scope.', 'dbem'), 'default' => 0), 'orderby' => array('desc' => __('Choose what fields to order your results by. You can supply a single field or multiple comma-seperated fields (e.g. "start_date,name").', 'dbem'), 'default' => 'name', 'args' => 'name, address, town'), 'scope' => array('default' => 'all'), 'town' => array('desc' => __('Search for locations in this town (no partial matches, case sensitive).', 'dbem'), 'default' => __('none', 'dbem')), 'state' => array('desc' => __('Search for locations in this state (no partial matches, case sensitive).', 'dbem'), 'default' => __('none', 'dbem')), 'region' => array('desc' => __('Search for locations in this region (no partial matches, case sensitive).', 'dbem'), 'default' => __('none', 'dbem')), 'country' => array('desc' => __('Search for locations in this country (no partial matches, case sensitive).', 'dbem'), 'default' => __('none', 'dbem')), 'postcode' => array('desc' => __('Search for locations in this postcode (no partial matches, case sensitive).', 'dbem'), 'default' => __('none', 'dbem'))), 'calendar' => array('full' => array('desc' => __('If set to 1 it will display a full calendar that shows event names.', 'dbem'), 'default' => 0), 'long_events' => array('desc' => __('If set to 1, will show events that last longer than a day.', 'dbem'), 'default' => 0), 'order' => array('desc' => __('Same as for events.', 'dbem')), 'scope' => array('default' => 'future')), 'general' => array('limit' => array('desc' => __('Limits the amount of values returned to this number.', 'dbem'), 'default' => '0 (no limit)'), 'scope' => array('desc' => __('Choose the time frame of events to show. Accepted values are "future", "past" or "all" events. Additionally you can supply dates (in format of YYYY-MM-DD), either single for events on a specific date or two dates seperated by a comma (e.g. 2010-12-25,2010-12-31) for events ocurring between these dates.', 'dbem'), 'default' => 'future'), 'order' => array('desc' => __('Indicates the order of the events. Choose between ASC (ascending) and DESC (descending).', 'dbem'), 'default' => 'ASC'), 'orderby' => array('desc' => __('Choose what fields to order your results by. You can supply a single field or multiple comma-seperated fields (e.g. "start_date,name"). See specific instances (e.g. events, locations, etc.) for field names.', 'dbem'), 'default' => 0), 'format' => array('desc' => __('If you are displaying some information with the shortcode or function (e.g. listing events), you can supply the html and placeholders here.', 'dbem'), 'default' => __('The relevant default format will be taken from the settings page.', 'dbem')), 'event' => array('desc' => __('Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to events with these id(s).', 'dbem'), 'default' => 0), 'category' => array('desc' => __('Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to events in these categories.', 'dbem'), 'default' => 0), 'location' => array('desc' => __('Supply a single id or comma-seperated ids to limit the search to these locations (or events in these locations).', 'dbem'), 'default' => 0), 'offset' => array('desc' => __('For example, if you have ten results, if you set this to 5, only the last 5 results will be returned. Useful for pagination.', 'dbem'), 'default' => 0), 'recurrence' => array('desc' => __('If set to 1, will show only events that are recurring (i.e. events that are repeated over different dates).', 'dbem'), 'default' => 0), 'recurring' => array('desc' => __('If set to 1, will only show recurring event templates. Only useful if you know what you\'re doing, use recurrence if you want events that are recurrences.', 'dbem'), 'default' => 0), 'month' => array('desc' => __('If set to a month (1 to 12) only events that start or end during this month/year will be retured. Must be used in conjunction with year and does not work as intended if used with scope.', 'dbem'), 'default' => ''), 'year' => array('desc' => __('If set to a year (e.g. 2010) only events that start or end during this year/month will be returned. Does not work as intended if used with scope.', 'dbem'), 'default' => ''), 'array' => array('desc' => __('If you supply this as an argument, the returned data will be in an array, no objects (only useful wen using PHP, not shortcodes)', 'dbem'), 'default' => 0), 'pagination' => array('desc' => __('When using a function or shortcode that outputs items (e.g. [events_list] for events, [locations_list] for locations), if the number of items supercede the limit of items to show, setting this to 1 will show page links under the list.', 'dbem'), 'default' => 0))), 'placeholders' => array('events' => array('Event Details' => array('placeholders' => array('#_NAME' => array('desc' => __('Displays the name of the event.', 'dbem')), '#_NOTES' => array('desc' => __('Shows the description of the event.', 'dbem')), '#_EXCERPT' => array('desc' => __('If you added a <a href="http://en.support.wordpress.com/splitting-content/more-tag/">more tag</a> to your event description, only the content before this tag will show (currently, no read more link is added).', 'dbem')), '#_EVENTID' => array('desc' => __('Shows the event corresponding ID number in the database table.', 'dbem')), '#_EVENTIMAGE' => array('desc' => __('Shows the event image, if available.', 'dbem')))), 'Time' => array('desc' => '', 'placeholders' => array('#_24HSTARTTIME' => array('desc' => __('Displays the start time in a 24 hours format (e.g. 16:30).', 'dbem')), '#_24HENDTIME' => array('desc' => __('Displays the end time in a 24 hours format (e.g. 18:30).', 'dbem')), '#_12HSTARTTIME' => array('desc' => __('Displays the start time in a 12 hours format (e.g. 4:30 PM).', 'dbem')), '#_12HENDTIME' => array('desc' => __('Displays the end time in a 12 hours format (e.g. 6:30 PM).', 'dbem')))), 'Custom Date/Time Formatting' => array('desc' => __('Events Manager allows extremely flexible date formatting by using <a href="http://www.php.net/manual/en/function.date.php">PHP date syntax format characters</a> along with placeholders.', 'dbem'), 'placeholders' => array('# or #@' => array('desc' => __('Prepend <code>#</code> or <code>#@</code> before a valid PHP date syntax format character to show start and end date/time information respectively (e.g. <code>#F</code> will show the starting month name like "January", #@h shows the end hour).', 'dbem')), '#{x} or #@{x}' => array('desc' => __('You can also create a date format without prepending # to each character by wrapping a valid php date() format in <code>#{}</code> or <code>#@{}</code> (e.g. <code>#_{d/m/Y}</code>). If there is no end date (or is same as start date), the value is not shown. This is useful if you want to show event end dates only on events that are longer than on day, e.g. <code>#j #M #Y #@_{ \\u\\n\\t\\i\\l j M Y}</code>.', 'dbem')))), 'Links' => array('placeholders' => array('#_EVENTURL' => array('desc' => __('Simply prints the event URL. You can use this placeholder to build your own customised links.', 'dbem')), '#_EVENTIMAGEURL' => array('desc' => __('Shows the event image url, if available.', 'dbem')), '#_EVENTLINK' => array('desc' => __('Displays the event name with a link to the event page.', 'dbem')), '#_EDITEVENTLINK' => array('desc' => __('Inserts a link to the admin or buddypress (if activated) edit event page, only if a user is logged in and is allowed to edit the event.', 'dbem')), '#_EDITEVENTURL' => array('desc' => __('Inserts a url to the admin or buddypress (if activated) edit event page, only if a user is logged in and is allowed to edit the event.', 'dbem')))), 'Custom Attributes' => array('desc' => __('Events Manager allows you to create dynamic attributes to your events, which act as extra information fields for your events (e.g. "Dress Code"). For more information see <a href="http://wp-events-plugin.com/documentation/categories-and-attributes/">our online documentation</a> for more info on attributes.', 'dbem'), 'placeholders' => array('#_ATT{key}' => array('desc' => __('This key will appear as an option when adding attributes to your event.', 'dbem')), '#_ATT{key}{alternative text}' => array('desc' => __('This key will appear as an option when adding attributes to your event. The text in the second braces will appear if the attribute is not defined or left blank for that event.', 'dbem')), '#_ATT{key}{option 1|option 2|option 3|etc.}' => array('desc' => __('This key will appear as an option when adding attributes to your event. The second braces are optional and will use a select box with these values as input. If no valid value is defined, the first option is used.', 'dbem')))), 'Bookings' => array('desc' => __('These placeholders will only show if bookings are enabled for the given event and in the events manager settings page. Spaces placeholders will default to 0', 'dbem'), 'placeholders' => array('#_BOOKINGFORM' => array('desc' => __('Adds a booking forms for this event.', 'dbem')), '#_AVAILABLESPACES' => array('desc' => __('Shows available spaces for the event.', 'dbem')), '#_BOOKEDSPACES' => array('desc' => __('Shows the amount of currently booked spaces for the event.', 'dbem')), '#_PENDINGSPACES' => array('desc' => __('Shows the amount of pending spaces for the event.', 'dbem')), '#_SPACES' => array('desc' => __('Shows the total spaces for the event.', 'dbem')), '#_ATTENDEES' => array('desc' => __('Shows the list of user avatars attending events.', 'dbem')), '#_BOOKINGBUTTON' => array('desc' => __('A single button that will appear to logged in users, if they click on it, they apply for a booking. This button will only display if there is one ticket.', 'dbem')), '#_BOOKINGSURL' => array('desc' => __('Shows the url to the admin or buddypress (if activated) bookings management page for this event. Only shown if user is logged in and able to manage bookings.', 'dbem')), '#_BOOKINGSLINK' => array('desc' => __('Shows a link to the admin or buddypress (if activated) bookings management page for this event. Only shown if user is logged in and able to manage bookings.', 'dbem')))), 'Contact Details' => array('desc' => __('The values here are taken from the chosen contact for the specific event, or the default contact in the settings page.', 'dbem'), 'placeholders' => array('#_CONTACTNAME' => array('desc' => __('Name of the contact person for this event (as shown in the dropdown when adding an event).', 'dbem')), '#_CONTACTUSERNAME' => array('desc' => __('Contact person\'s username.', 'dbem')), '#_CONTACTEMAIL' => array('desc' => __('E-mail of the contact person for this event.', 'dbem')), '#_CONTACTPHONE' => array('desc' => __('Phone number of the contact person for this event. Can be set in the user profile page.', 'dbem')), '#_CONTACTAVATAR' => array('desc' => __('Contact person\'s avatar.', 'dbem')), '#_CONTACTPROFILELINK' => array('desc' => __('Contact person\'s "Profile" link. Only works with BuddyPress enabled.', 'dbem')), '#_CONTACTPROFILEURL' => array('desc' => __('Contact person\'s profile url. Only works with BuddyPress enabled.', 'dbem')), '#_CONTACTID' => array('desc' => __('Contact person\'s wordpress user ID.', 'dbem'))))), 'categories' => array('Category Details' => array('placeholders' => array('#_CATEGORYNAME' => array('desc' => __('Shows the category name of the event.', 'dbem')), '#_CATEGORYID' => array('desc' => __('Shows the category ID of the event.', 'dbem')), '#_CATEGORYIMAGE' => array('desc' => __('Shows the event image, if available.', 'dbem')), '#_CATEGORYIMAGEURL' => array('desc' => __('Shows the event image url, if available.', 'dbem')), '#_CATEGORYNOTES' => array('desc' => __('Shows the location description.', 'dbem'))))), 'locations' => array('Location Details' => array('desc' => '', 'placeholders' => array('#_LOCATIONNAME' => array('desc' => __('Displays the location name.', 'dbem')), '#_LOCATIONADDRESS' => array('desc' => __('Displays the address.', 'dbem')), '#_LOCATIONTOWN' => array('desc' => __('Displays the town.', 'dbem')), '#_LOCATIONSTATE' => array('desc' => __('Displays the state/county.', 'dbem')), '#_LOCATIONPOSTCODE' => array('desc' => __('Displays the postcode.', 'dbem')), '#_LOCATIONREGION' => array('desc' => __('Displays the region.', 'dbem')), '#_LOCATIONCOUNTRY' => array('desc' => __('Displays the country.', 'dbem')), '#_LOCATIONMAP' => array('desc' => __('Displays a google map showing where the event is located (Will not show if maps are disabled in the settings page)', 'dbem')), '#_LOCATIONNOTES' => array('desc' => __('Shows the location description.', 'dbem')), '#_LOCATIONEXCERPT' => array('desc' => __('If you added a <a href="http://en.support.wordpress.com/splitting-content/more-tag/">more tag</a> to your location description, only the content before this tag will show (currently, no read more link is added).', 'dbem')), '#_LOCATIONIMAGE' => array('desc' => __('Shows the location image.', 'dbem')), '#_LOCATIONID' => array('desc' => __('Displays the location ID number.', 'dbem')))), 'Links' => array('placeholders' => array('#_LOCATIONURL' => array('desc' => __('Simply prints the location URL. You can use this placeholder to build your own customised links.', 'dbem')), '#_LOCATIONLINK' => array('desc' => __('Displays the location name with a link to the location page.', 'dbem')))), 'Related Events' => array('desc' => __('You can show lists of other events that are being held at this location. The formatting of the list is the same as a normal events list.', 'dbem'), 'placeholders' => array('#_LOCATIONPASTEVENTS' => array('desc' => __('Will show a list of all past events at this location.', 'dbem')), '#_LOCATIONNEXTEVENTS' => array('desc' => __('Will show a list of all future events at this location.', 'dbem')), '#_LOCATIONALLEVENTS' => array('desc' => __('Will show a list of all events at this location.', 'dbem'))))), 'bookings' => array('Booking Person Information' => array('desc' => __('When a specific booking is displayed (on screen and on email), you can use these placeholders to show specific information about the booking. For contact details of the contact of this event, see the events placeholders.', 'dbem'), 'placeholders' => array('#_BOOKINGNAME' => array('desc' => __('Name of person who made the booking.', 'dbem')), '#_BOOKINGEMAIL' => array('desc' => __('Email of person who made the booking.', 'dbem')), '#_BOOKINGPHONE' => array('desc' => __('Phone number of person who made the booking.', 'dbem')), '#_BOOKINGSPACES' => array('desc' => __('Number of spaces the person has booked.', 'dbem')), '#_BOOKINGCOMMENT' => array('desc' => __('Any specific comments made by the person who made the booking.', 'dbem')), '#_BOOKINGTICKETNAME' => array('desc' => __('Name of the ticket booked. Useful in single ticket mode, if multiple tickets are booked a random ticket is used.', 'dbem')), '#_BOOKINGTICKETDESCRIPTION' => array('desc' => __('Description of the ticket booked. Useful in single ticket mode, if multiple tickets are booked a random ticket is used.', 'dbem')), '#_BOOKINGTICKETPRICE' => array('desc' => __('Booked ticket price with currency symbol (e.g. $ 10.00). Useful in single ticket mode, if multiple tickets are booked a random ticket is used.', 'dbem')), '#_BOOKINGTICKETS' => array('desc' => __('A list of booked tickets. You can modify this by using template files and modifying templates/emails/bookingtickets.php', 'dbem')), '#_BOOKINGFORMCUSTOM{field_id}' => array('desc' => sprintf(__('(<a href="%s">pro only</a>) Shows booking form custom fields. The field_id value must match that of your custom booking form field.', 'dbem'), 'http://wp-events-plugin.com/upgrade/')), '#_BOOKINGFORMCUSTOMREG{field_id}' => array('desc' => sprintf(__('(<a href="%s">pro only</a>) Shows booking form custom fields that are used for guest user registration. The field_id value must match that of your custom booking form field.', 'dbem'), 'http://wp-events-plugin.com/upgrade/')))), 'Links' => array('desc' => __('People are able to manage their bookings. Below are some placeholder which automatically provides correctly formatted urls', 'dbem'), 'placeholders' => array('#_BOOKINGLISTURL' => array('desc' => __('URL to page showing that users booked events.', 'dbem')))))), 'capabilities' => array()); } }
/** * Returns an array of EM_Location objects * @param boolean $eventful * @param boolean $return_objects * @return array */ function get($args = array()) { global $wpdb; $events_table = $wpdb->prefix . EM_EVENTS_TABLE; $locations_table = $wpdb->prefix . EM_LOCATIONS_TABLE; //Quick version, we can accept an array of IDs, which is easy to retrieve if (self::array_is_numeric($args) && count()) { //Array of numbers, assume they are event IDs to retreive //We can just get all the events here and return them $sql = "SELECT * FROM {$locations_table} WHERE location_id=" . implode(" OR location_id=", $args); $results = $wpdb->get_results($sql, ARRAY_A); $events = array(); foreach ($results as $result) { $locations[$result['location_id']] = new EM_Location($result); } return $locations; //We return all the events matched as an EM_Event array. } //We assume it's either an empty array or array of search arguments to merge with defaults $args = self::get_default_search($args); $limit = $args['limit'] && is_numeric($args['limit']) ? "LIMIT {$args['limit']}" : ''; $offset = $limit != "" && is_numeric($args['offset']) ? "OFFSET {$args['offset']}" : ''; //Get the default conditions $conditions = self::build_sql_conditions($args); //Put it all together $EM_Location = new EM_Location(0); //Empty class for strict message avoidance $fields = $locations_table . "." . implode(", {$locations_table}.", array_keys($EM_Location->fields)); $where = count($conditions) > 0 ? " WHERE " . implode(" AND ", $conditions) : ''; //Get ordering instructions $EM_Event = new EM_Event(); //blank event for below $accepted_fields = $EM_Location->get_fields(true); $accepted_fields = array_merge($EM_Event->get_fields(true), $accepted_fields); $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')); //Now, build orderby sql $orderby_sql = count($orderby) > 0 ? 'ORDER BY ' . implode(', ', $orderby) : ''; //Create the SQL statement and execute $sql = "\n\t\t\tSELECT {$fields} FROM {$locations_table}\n\t\t\tLEFT JOIN {$events_table} ON {$locations_table}.location_id={$events_table}.location_id\n\t\t\t{$where}\n\t\t\tGROUP BY location_id\n\t\t\t{$orderby_sql}\n\t\t\t{$limit} {$offset}\n\t\t"; $results = $wpdb->get_results($sql, ARRAY_A); //If we want results directly in an array, why not have a shortcut here? if ($args['array'] == true) { return $results; } $locations = array(); foreach ($results as $location) { $locations[] = new EM_Location($location); } return apply_filters('em_locations_get', $locations, $args); }
function em_docs_init($force_init = false) { global $pagenow; if ($pagenow == 'edit.php' && !empty($_GET['page']) && $_GET['page'] == 'events-manager-help' && class_exists('EM_Event') || $force_init) { add_action('wp_head', 'emd_head'); //Generate the docs global $EM_Documentation; $EM_Event = new EM_Event(); $event_fields = $EM_Event->get_fields(true); $EM_Location = new EM_Location(); $location_fields = $EM_Location->get_fields(true); $EM_Documentation = array('arguments' => array('events' => array('blog' => array('desc' => sprintf('Limit search to %s created in a specific blog id (MultiSite only)', 'events')), 'bookings' => array('desc' => 'Include only events with bookings enabled. Use \'user\' to show events a logged in user has booked.' . '1 = yes, 0 = no'), 'category' => array('desc' => sprintf('Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to events in these %s. You can also use negative numbers to exclude specific categories (e.g. -1,-2,-3).', 'categories'), 'default' => 0), 'tag' => array('desc' => sprintf('Supply a single id or comma-seperated ids (e.g. "music,theatre,sport") to limit the search to events in these %s.', 'tags'), 'default' => 0), 'event' => array('desc' => sprintf('Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to %s with the %s.', 'events', 'event_id(s)'), 'default' => 0), 'group' => array('desc' => 'Limit search to events belonging to a specific group id (BuddyPress only). Using \'my\' will show events belonging to groups the logged in user is a member of.'), 'post_id' => array('desc' => sprintf('Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to %s with the %s.', 'events', 'post_id(s)')), 'private' => array('desc' => sprintf('Display private %s within your list?', 'events'), 'args' => '1 = yes, 0 = no', 'default' => 'If user can view private events, 1, otherwise 0.'), 'private_only' => array('desc' => sprintf('Display only private %s ?', 'events'), 'args' => '1 = yes, 0 = no', 'default' => '0'), 'recurrence' => array('desc' => 'If set to the event id of the recurring event, this will show only events this event recurrences.', 'default' => 0), 'recurring' => array('desc' => 'If set to 1, will only show recurring event templates. Only useful if you know what you\'re doing, use recurrence if you want events that are recurrences.', 'default' => 0), 'search' => array('desc' => 'Do a search for this string within event name, details and location address.'), 'status' => array('desc' => sprintf('Limit search to %s with a spefic status (1 is active, 0 is pending approval)', 'events'), 'default' => 1), 'scope' => array('desc' => 'Choose the time frame of events to show. Additionally you can supply dates (in format of YYYY-MM-DD), either single for events on a specific date or two dates seperated by a comma (e.g. 2010-12-25,2010-12-31) for events ocurring between these dates.', 'default' => 'future', 'args' => array("future", "past", "today", "tomorrow", "month", "next-month", "1-months", "2-months", "3-months", "6-months", "12-months", "all")), 'year' => array('desc' => 'If set to a year (e.g. 2010) only events that start or end during this year/month will be returned. Does not work as intended if used with scope.', 'default' => '')), 'locations' => array('blog' => array('desc' => sprintf('Limit search to %s created in a specific blog id (MultiSite only)', 'locations')), 'eventful' => array('desc' => 'If set to 1 will only show locations that have at least one event occurring during the scope.', 'default' => 0), 'eventless' => array('desc' => 'If set to 1 will only show locations that have no events occurring during the scope.', 'default' => 0), 'location' => array('desc' => sprintf('Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to %s with the %s.', 'locations', 'location_id(s)'), 'default' => 0), 'post_id' => array('desc' => sprintf('Supply a single id or comma-seperated ids (e.g. "1,2,3") to limit the search to %s with the %s.', 'locations', 'post_id(s)')), 'private' => array('desc' => sprintf('Display private %s within your list?', 'locations'), 'args' => '1 = yes, 0 = no', 'default' => 'If user can view private locations, 1, otherwise 0.'), 'private_only' => array('desc' => sprintf('Display only private %s ?', 'locations'), 'args' => '1 = yes, 0 = no', 'default' => '0'), 'scope' => array('default' => 'all'), 'status' => array('desc' => sprintf('Limit search to %s with a spefic status (1 is active, 0 is pending approval)', 'locations'), 'default' => 1), 'country' => array('desc' => sprintf('Search for %s in this %s (no partial matches, case sensitive).', 'locations', 'Country'), 'default' => 'none', 'args' => 'Use two-character country codes as defined in <a href="http://countrycode.org/">countrycode.org</a>, e.g. US,GB,ES'), 'region' => array('desc' => sprintf('Search for %s in this %s (no partial matches, case sensitive).', 'locations', 'Region'), 'default' => 'none'), 'state' => array('desc' => sprintf('Search for %s in this %s (no partial matches, case sensitive).', 'locations', 'State'), 'default' => 'none'), 'town' => array('desc' => sprintf('Search for %s in this %s (no partial matches, case sensitive).', 'locations', 'Town'), 'default' => 'none'), 'postcode' => array('desc' => sprintf('Search for %s in this %s (no partial matches, case sensitive).', 'locations', 'Postcode'), 'default' => 'none')), 'categories' => array('' => array('desc' => 'See the <a href="http://codex.wordpress.org/Function_Reference/get_terms">WordPress get_terms() Codex</a> for a list of possible search attributes/arguments.')), 'tags' => array('' => array('desc' => 'See the <a href="http://codex.wordpress.org/Function_Reference/get_terms">WordPress get_terms() Codex</a> for a list of possible search attributes/arguments.')), 'calendar' => array('full' => array('desc' => 'If set to 1 it will display a full calendar that shows event names.', 'default' => 0), 'long_events' => array('desc' => 'If set to 1, will show events that last longer than a day.', 'default' => 0)), 'general' => array('array' => array('desc' => 'If you supply this as an argument, the returned data will be in an array, not an object (only useful wen using PHP, not shortcodes)', 'default' => 0), 'format_header' => array('desc' => sprintf('If you are displaying lists (e.g. listing events), you can supply the %s html and placeholders here.', 'header'), 'default' => 'The relevant default format will be taken from the settings page.'), 'format' => array('desc' => 'If you are displaying some information with the shortcode or function (e.g. listing events), you can supply the html and placeholders here.', 'default' => 'The relevant default format will be taken from the settings page.'), 'format_footer' => array('desc' => sprintf('If you are displaying lists (e.g. listing events), you can supply the %s html and placeholders here.', 'footer'), 'default' => 'The relevant default format will be taken from the settings page.'), 'limit' => array('desc' => 'Limits the amount of values returned to this number.', 'default' => '0 (no limit)'), 'offset' => array('desc' => 'For example, if you have ten results, if you set this to 5, only the last 5 results will be returned. Useful for pagination.', 'default' => 0), 'order' => array('desc' => 'Indicates the alphabeitcal/numerical order of the lists. Choose between ASC (ascending) and DESC (descending).', 'default' => 'ASC'), 'orderby' => array('desc' => 'Choose what fields to order your results by. You can supply a single field or multiple comma-seperated fields (e.g. "event_start_date,event_name").', 'default' => 0, 'args' => 'Database table fields, e.g. <code>event_name</code> or <code>location_name</code>'), 'owner' => array('desc' => 'Limits returned results to a specific owner, identified by their user id (e.g. list events or locations owned by user)', 'default' => 0), 'pagination' => array('desc' => 'When using a function or shortcode that outputs items (e.g. [events_list] for events, [locations_list] for locations), if the number of items supercede the limit of items to show, setting this to 1 will show page links under the list.', 'default' => 0))), 'placeholders' => array('events' => array('Event Details' => array('placeholders' => array('#_EVENTID' => array('desc' => 'Shows the event ID number in the wp_em_events table.'), '#_EVENTPOSTID' => array('desc' => 'Shows the event corresponding Post ID in the wp_posts table.'), '#_EVENTNAME' => array('desc' => 'Displays the name of the event.'), '#_EVENTNOTES' => array('desc' => 'Shows the description of the event.'), '#_EVENTEXCERPT' => array('desc' => 'If you added a <a href="http://en.support.wordpress.com/splitting-content/more-tag/">more tag</a> to your event description, only the content before this tag will show (currently, no read more link is added).'), '#_EVENTIMAGE' => array('desc' => 'Shows the event image, if available.'), '#_EVENTIMAGE{x,y}' => array('desc' => 'Shows the event image thumbnail, x and y are width and height respectively, both being numbers e.g. <code>#_EVENTIMAGE{100,100}</code>'), '#_EVENTCATEGORIES' => array('desc' => 'Shows a list of category links this event belongs to.'), '#_EVENTCATEGORIESIMAGES' => array('desc' => 'Shows a list of category images this event belongs to. Categories without an image will be ignored.'), '#_EVENTTAGS' => array('desc' => 'Shows a list of tag links this event belongs to.'))), 'Date and Times' => array('desc' => '', 'placeholders' => array('#_24HSTARTTIME' => array('desc' => 'Displays the start time in a 24 hours format (e.g. 16:30).'), '#_24HENDTIME' => array('desc' => 'Displays the end time in a 24 hours format (e.g. 18:30).'), '#_12HSTARTTIME' => array('desc' => 'Displays the start time in a 12 hours format (e.g. 4:30 PM).'), '#_12HENDTIME' => array('desc' => 'Displays the end time in a 12 hours format (e.g. 6:30 PM).'), '#_EVENTTIMES' => array('desc' => 'Displays either a single time, time-span, or "All Day" depending on your event times. Format is taken from your Events Manager settings page.'), '#_EVENTDATES' => array('desc' => 'Displays either a single date or a date range depending on your event dates. Format is taken from your Events Manager settings page.'))), 'Custom Date/Time Formatting' => array('desc' => 'Events Manager allows extremely flexible date formatting by using <a href="http://www.php.net/manual/en/function.date.php">PHP date syntax format characters</a> along with placeholders.', 'placeholders' => array('# or #@' => array('desc' => 'Prepend <code>#</code> or <code>#@</code> before a valid PHP date syntax format character to show start and end date/time information respectively (e.g. <code>#F</code> will show the starting month name like "January", #@h shows the end hour).'), '#{x} or #@{x}' => array('desc' => 'You can also create a date format without prepending # to each character by wrapping a valid php date() format in <code>#{}</code> or <code>#@{}</code> (e.g. <code>#_{d/m/Y}</code>). If there is no end date (or is same as start date), the value is not shown. This is useful if you want to show event end dates only on events that are longer than on day, e.g. <code>#j #M #Y #@_{ \\u\\n\\t\\i\\l j M Y}</code>.'))), 'Links/URLs' => array('placeholders' => array('#_EVENTIMAGEURL' => array('desc' => 'Shows the event image url, if available.'), '#_EVENTURL' => array('desc' => 'Simply prints the event URL. You can use this placeholder to build your own customised links.'), '#_EVENTLINK' => array('desc' => 'Displays the event name with a link to the event page.'), '#_EDITEVENTLINK' => array('desc' => 'Inserts a link to the admin or buddypress (if activated) edit event page, only if a user is logged in and is allowed to edit the event.'), '#_EDITEVENTURL' => array('desc' => 'Inserts a url to the admin or buddypress (if activated) edit event page, only if a user is logged in and is allowed to edit the event.'))), 'Custom Attributes' => array('desc' => 'Events Manager allows you to create dynamic attributes to your events, which act as extra information fields for your events (e.g. "Dress Code"). For more information see <a href="http://wp-events-plugin.com/documentation/categories-and-attributes/">our online documentation</a> for more info on attributes.', 'placeholders' => array('#_ATT{key}' => array('desc' => 'This key will appear as an option when adding attributes to your event.'), '#_ATT{key}{alternative text}' => array('desc' => 'This key will appear as an option when adding attributes to your event. The text in the second braces will appear if the attribute is not defined or left blank for that event.'), '#_ATT{key}{option 1|option 2|option 3|etc.}' => array('desc' => 'This key will appear as an option when adding attributes to your event. The second braces are optional and will use a select box with these values as input. If no valid value is defined, the first option is used.'))), 'Bookings' => array('desc' => 'These placeholders will only show if bookings are enabled for the given event and in the events manager settings page. Spaces placeholders will default to 0', 'placeholders' => array('#_BOOKINGFORM' => array('desc' => 'Adds a booking forms for this event.'), '#_BOOKINGBUTTON' => array('desc' => 'A single button that will appear to logged in users, if they click on it, they apply for a booking. This button will only display if there is one ticket.'), '#_AVAILABLESPACES' => array('desc' => 'Shows available spaces for the event.'), '#_BOOKEDSPACES' => array('desc' => 'Shows the amount of currently booked spaces for the event.'), '#_PENDINGSPACES' => array('desc' => 'Shows the amount of pending spaces for the event.'), '#_SPACES' => array('desc' => 'Shows the total spaces for the event.'), '#_ATTENDEES' => array('desc' => 'Shows the list of user avatars attending the event.'), '#_ATTENDEESLIST' => array('desc' => 'Shows the list of people attending the event.'), '#_BOOKINGSURL' => array('desc' => 'Shows the url to the admin, front-end or buddypress (if activated) bookings management page for this event. Only shown if user is logged in and able to manage bookings.'), '#_BOOKINGSLINK' => array('desc' => 'Shows a link to the admin, front-end or buddypress (if activated) bookings management page for this event. Only shown if user is logged in and able to manage bookings.'), '#_EVENTPRICERANGE' => array('desc' => 'Shows a "maximum - minimum" price range, or a single price if there is no range. Price is formatted according to currency formatting in your settings page.'), '#_EVENTPRICEMIN' => array('desc' => 'Shows the lowest ticket price for this event.'), '#_EVENTPRICEMAX' => array('desc' => 'Shows the highest ticket price for this event.'))), 'Contact Details' => array('desc' => 'The values here are taken from the chosen contact for the specific event, or the default contact in the settings page.', 'placeholders' => array('#_CONTACTNAME' => array('desc' => 'Name of the contact person for this event (as shown in the dropdown when adding an event).'), '#_CONTACTUSERNAME' => array('desc' => 'Contact person\'s username.'), '#_CONTACTEMAIL' => array('desc' => 'E-mail of the contact person for this event.'), '#_CONTACTPHONE' => array('desc' => 'Phone number of the contact person for this event. Can be set in the user profile page.'), '#_CONTACTAVATAR' => array('desc' => 'Contact person\'s avatar.'), '#_CONTACTPROFILELINK' => array('desc' => 'Contact person\'s "Profile" link. Only works with BuddyPress enabled.'), '#_CONTACTPROFILEURL' => array('desc' => 'Contact person\'s profile url. Only works with BuddyPress enabled.'), '#_CONTACTID' => array('desc' => 'Contact person\'s WordPress user ID.'), '#_CONTACTMETA' => array('desc' => 'Display any user meta of a WordPress account by including the meta key, e.g. #_CONTACTMETA{dbem_phone}'))), 'iCal/Calendar' => array('placeholders' => array('#_EVENTICALURL' => array('desc' => 'Displays the URL of the event ical feed (ics file format).'), '#_EVENTICALLINK' => array('desc' => 'Displays an html link to the event ical feed (ics file format).'), '#_EVENTGCALURL' => array('desc' => 'Displays URL which would take the user to Google Calendar and pre-fill their add new event form.'), '#_EVENTGCALLINK' => array('desc' => 'Displays a button which would take the user to Google Calendar and pre-fill their add new event form.')))), 'categories' => array('Category Details' => array('placeholders' => array('#_CATEGORYNAME' => array('desc' => 'Shows the category name of the event.'), '#_CATEGORYID' => array('desc' => 'Shows the category ID of the event.'), '#_CATEGORYIMAGE' => array('desc' => 'Shows the event image, if available.'), '#_CATEGORYIMAGE{x,y}' => array('desc' => 'Shows the category image thumbnail, x and y are width and height respectively, both being numbers e.g. <code>#_CATEGORYIMAGE{100,100}</code>'), '#_CATEGORYIMAGEURL' => array('desc' => 'Shows the category image url, if available.'), '#_CATEGORYNOTES' => array('desc' => 'Shows the location description.'))), 'Related Events' => array('desc' => 'You can show lists of other events belonging to this category. The formatting of the list is the same as a normal events list.', 'placeholders' => array('#_CATEGORYPASTEVENTS' => array('desc' => 'Will show a list of all past events at this category.'), '#_CATEGORYNEXTEVENTS' => array('desc' => 'Will show a list of all future events at this category.'), '#_CATEGORYALLEVENTS' => array('desc' => 'Will show a list of all events at this category.')))), 'locations' => array('Location Details' => array('desc' => '', 'placeholders' => array('#_LOCATIONID' => array('desc' => 'Shows the event ID number in the wp_em_locations table.'), '#_LOCATIONPOSTID' => array('desc' => 'Shows the location corresponding Post ID in the wp_posts table.'), '#_LOCATIONNAME' => array('desc' => 'Displays the location name.'), '#_LOCATIONADDRESS' => array('desc' => 'Displays the address.'), '#_LOCATIONTOWN' => array('desc' => 'Displays the town.'), '#_LOCATIONSTATE' => array('desc' => 'Displays the state/county.'), '#_LOCATIONPOSTCODE' => array('desc' => 'Displays the postcode.'), '#_LOCATIONREGION' => array('desc' => 'Displays the region.'), '#_LOCATIONCOUNTRY' => array('desc' => 'Displays the country.'), '#_LOCATIONMAP' => array('desc' => 'Displays a google map showing where the event is located (Will not show if maps are disabled in the settings page)'), '#_LOCATIONNOTES' => array('desc' => 'Shows the location description.'), '#_LOCATIONEXCERPT' => array('desc' => 'If you added a <a href="http://en.support.wordpress.com/splitting-content/more-tag/">more tag</a> to your location description, only the content before this tag will show (currently, no read more link is added).'), '#_LOCATIONIMAGE' => array('desc' => 'Shows the location image.'), '#_LOCATIONIMAGE{x,y}' => array('desc' => 'Shows the location image thumbnail, x and y are width and height respectively, both being numbers e.g. <code>#_LOCATIONIMAGE{100,100}</code>'), '#_LOCATIONIMAGEURL' => array('desc' => 'Shows the location image url, if available.'), '#_LOCATIONFULLLINE' => array('desc' => 'Shows a comma-seperated line of location information, ommitting blanks (format of address, town, state, postcode, region'), '#_LOCATIONFULLBR' => array('desc' => 'Shows a line-break (br tag) seperated location information, ommitting blanks (format of address, town, state, postcode, region'))), 'Custom Attributes' => array('desc' => 'Events Manager allows you to create dynamic attributes to your locations, which act as extra information fields for your locations (e.g. "Dress Code"). For more information see <a href="http://wp-events-plugin.com/documentation/categories-and-attributes/">our online documentation</a> for more info on attributes.', 'placeholders' => array('#_LATT{key}' => array('desc' => 'This key will appear as an option when adding attributes to your location.'), '#_LATT{key}{alternative text}' => array('desc' => 'This key will appear as an option when adding attributes to your location. The text in the second braces will appear if the attribute is not defined or left blank for that location.'), '#_LATT{key}{option 1|option 2|option 3|etc.}' => array('desc' => 'This key will appear as an option when adding attributes to your location. The second braces are optional and will use a select box with these values as input. If no valid value is defined, the first option is used.'))), 'Links' => array('placeholders' => array('#_LOCATIONURL' => array('desc' => 'Simply prints the location URL. You can use this placeholder to build your own customised links.'), '#_LOCATIONLINK' => array('desc' => 'Displays the location name with a link to the location page.'), '#_EDITLOCATIONLINK' => array('desc' => 'Inserts a link to the admin or buddypress (if activated) edit location page, only if a user is logged in and is allowed to edit the location.'), '#_EDITLOCATIONURL' => array('desc' => 'Inserts a url to the admin or buddypress (if activated) edit location page, only if a user is logged in and is allowed to edit the location.'))), 'Related Events' => array('desc' => 'You can show lists of other events that are being held at this location. The formatting of the list is the same as a normal events list.', 'placeholders' => array('#_LOCATIONPASTEVENTS' => array('desc' => 'Will show a list of all past events at this location.'), '#_LOCATIONNEXTEVENTS' => array('desc' => 'Will show a list of all future events at this location.'), '#_LOCATIONALLEVENTS' => array('desc' => 'Will show a list of all events at this location.'), '#_LOCATIONNEXTEVENT' => array('desc' => 'Will show a link to the next event at this location, or the no events message.')))), 'bookings' => array('Booking Person Information' => array('desc' => 'When a specific booking is displayed (on screen and on email), you can use these placeholders to show specific information about the booking. Event and Location placeholders are also available in these cases.', 'placeholders' => array('#_BOOKINGID' => array('desc' => 'The unique ID of this booking, useful if you are making your own customizations to this plugin.'), '#_BOOKINGNAME' => array('desc' => 'Name of person who made the booking.'), '#_BOOKINGEMAIL' => array('desc' => 'Email of person who made the booking.'), '#_BOOKINGPHONE' => array('desc' => 'Phone number of person who made the booking.'), '#_BOOKINGSPACES' => array('desc' => 'Number of spaces the person has booked.'), '#_BOOKINGCOMMENT' => array('desc' => 'Any specific comments made by the person who made the booking.'), '#_BOOKINGTICKETNAME' => array('desc' => 'Name of the ticket booked. Useful in single ticket mode, if multiple tickets are booked a random ticket is used.'), '#_BOOKINGTICKETDESCRIPTION' => array('desc' => 'Description of the ticket booked. Useful in single ticket mode, if multiple tickets are booked a random ticket is used.'), '#_BOOKINGTICKETPRICE' => array('desc' => 'Booked ticket price with currency symbol (e.g. $ 10.00). Useful in single ticket mode, if multiple tickets are booked a random ticket is used.'), '#_BOOKINGTICKETS' => array('desc' => 'A list of booked tickets. You can modify this by using template files and modifying templates/emails/bookingtickets.php'), '#_BOOKINGFORMCUSTOM{field_id}' => array('desc' => sprintf('(<a href="%s">pro only</a>) Shows booking form custom fields. The field_id value must match that of your custom booking form field.', 'http://wp-events-plugin.com/upgrade/')), '#_BOOKINGFORMCUSTOMREG{field_id}' => array('desc' => sprintf('(<a href="%s">pro only</a>) Shows booking form custom fields that are used for guest user registration. The field_id value must match that of your custom booking form field.', 'http://wp-events-plugin.com/upgrade/')), '#_BOOKINGFORMCUSTOMFIELDS' => array('desc' => sprintf('(<a href="%s">pro only</a>) Generates a list of booking form custom fields that are used in the booking.', 'http://wp-events-plugin.com/upgrade/')))), 'Pricing Information' => array('desc' => '', 'placeholders' => array('#_BOOKINGPRICE' => array('desc' => 'Displays booking total price (tax inclusion depends on your booking settings).'), '#_BOOKINGPRICETAX' => array('desc' => 'Displays booking total tax.'), '#_BOOKINGPRICEWITHOUTTAX' => array('desc' => 'Displays booking total without tax.'), '#_BOOKINGPRICEWITHTAX' => array('desc' => 'Displays booking total with tax.'))), 'Ticket Information' => array('desc' => '', 'placeholders' => array('#_BOOKINGTICKETS' => array('desc' => 'Shows a breakdown of tickets and pricing, defined in the <code>emails/bookingtickets.php</code> template. (See <a href="http://wp-events-plugin.com/documentation/using-template-files/">Using Template Files</a> for more information)'), '#_BOOKINGTICKETDESCRIPTION' => array('desc' => 'Shows the description of the first ticket booked (useful in single ticket mode/events).'), '#_BOOKINGTICKETPRICE' => array('desc' => 'Shows the price of the first ticket booked, tax inclusion depending on your booking settings (useful in single ticket mode/events).'), '#_BOOKINGTICKETTAX' => array('desc' => 'Shows the tax of the first ticket booked (useful in single ticket mode/events).'), '#_BOOKINGTICKETPRICEWITHTAX' => array('desc' => 'Shows the price including tax of the first ticket booked (useful in single ticket mode/events).'), '#_BOOKINGTICKETPRICEWITHOUTTAX' => array('desc' => 'Shows the price excluding tax of the first ticket booked (useful in single ticket mode/events).'))), 'Links' => array('desc' => 'People are able to manage their bookings. Below are some placeholder which automatically provides correctly formatted urls', 'placeholders' => array('#_BOOKINGLISTURL' => array('desc' => 'URL to page showing that users booked events.'))), 'Gateway-Specific Information' => array('desc' => '', 'placeholders' => array('#_BOOKINGTXNID' => array('desc' => '<em>Online Payments Only</em> - Prints the transaction ID of this booking if available.'))))), 'capabilities' => array()); } }
function save_post($post_id) { global $wpdb, $EM_Location, $EM_Notices; $saving_status = !in_array(get_post_status($post_id), array('trash', 'auto-draft')) && !defined('DOING_AUTOSAVE'); $is_post_type = get_post_type($post_id) == EM_POST_TYPE_LOCATION; if (!defined('UNTRASHING_' . $post_id) && $is_post_type && $saving_status) { if (wp_verify_nonce($_REQUEST['_emnonce'], 'edit_location')) { $EM_Location = em_get_location($post_id, 'post_id'); do_action('em_location_save_pre', $EM_Location); $get_meta = $EM_Location->get_post_meta(); $save_meta = $EM_Location->save_meta(); //Handle Errors by making post draft if (!$get_meta || !$save_meta) { $EM_Location->set_status(null, true); $EM_Notices->add_error('<strong>' . sprintf(__('Your %s details are incorrect and cannot be published, please correct these errors first:', 'dbem'), __('location', 'dbem')) . '</strong>', true); //Always seems to redirect, so we make it static $EM_Notices->add_error($EM_Location->get_errors(), true); //Always seems to redirect, so we make it static apply_filters('em_location_save', false, $EM_Location); } else { apply_filters('em_location_save', true, $EM_Location); } } else { //do a quick and dirty update do_action('em_location_save_pre', $this); $EM_Location = new EM_Location($post_id, 'post_id'); //check for existence of index $loc_truly_exists = $wpdb->get_var('SELECT location_id FROM ' . EM_LOCATIONS_TABLE . " WHERE location_id={$EM_Location->location_id}") == $EM_Location->location_id; if (empty($EM_Location->location_id) || !$loc_truly_exists) { $EM_Location->save_meta(); } //continue $location_status = $EM_Location->is_published() ? 1 : 0; $wpdb->query("UPDATE " . EM_LOCATIONS_TABLE . " SET location_name='{$EM_Location->location_name}', location_slug='{$EM_Location->location_slug}', location_private='{$EM_Location->location_private}',location_status={$location_status} WHERE location_id='{$EM_Location->location_id}'"); apply_filters('em_location_save', true, $this); } } }
/** * Returns this object in the form of an array, useful for saving directly into the wp_dbem_events table. * @param boolean $location * @param boolean $for_database * @return array */ function to_array($location = false, $for_database = false) { $event = array(); //Core Event Data foreach ($this->fields as $key => $val) { //TODO does it matter if it's for db or not... shouldn't it just not include blanks? if (!$for_database || $for_database && $this->{$val}['name']) { $event[$key] = $this->{$val}['name']; } } //Location Data if ($location && is_object($this->location)) { $location = $this->location->to_array(); $event = array_merge($event, $location); } return $event; }
/** * Performs actions on init. This works for both ajax and normal requests, the return results depends if an em_ajax flag is passed via POST or GET. */ function em_init_actions() { global $wpdb, $EM_Notices, $EM_Event; if (defined('DOING_AJAX') && DOING_AJAX) { $_REQUEST['em_ajax'] = true; } //NOTE - No EM objects are globalized at this point, as we're hitting early init mode. //TODO Clean this up.... use a uniformed way of calling EM Ajax actions if (!empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action'])) { if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') { if (isset($_REQUEST['id'])) { $EM_Location = new EM_Location($_REQUEST['id'], 'location_id'); $location_array = $EM_Location->to_array(); $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format')); echo EM_Object::json_encode($location_array); } die; } if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'delete_ticket') { if (isset($_REQUEST['id'])) { $EM_Ticket = new EM_Ticket($_REQUEST['id']); $result = $EM_Ticket->delete(); if ($result) { $result = array('result' => true); } else { $result = array('result' => false, 'error' => $EM_Ticket->feedback_message); } } else { $result = array('result' => false, 'error' => __('No ticket id provided', 'dbem')); } echo EM_Object::json_encode($result); die; } if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') { $EM_Locations = EM_Locations::get($_REQUEST); $json_locations = array(); foreach ($EM_Locations as $location_key => $EM_Location) { $json_locations[$location_key] = $EM_Location->to_array(); $json_locations[$location_key]['location_balloon'] = $EM_Location->output(get_option('dbem_map_text_format')); } echo EM_Object::json_encode($json_locations); die; } if (isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) { //FIXME if long events enabled originally, this won't show up on ajax call echo EM_Calendar::output($_REQUEST, false); die; } } //Event Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 5) == 'event') { //Load the event object, with saved event if requested if (!empty($_REQUEST['event_id'])) { $EM_Event = new EM_Event($_REQUEST['event_id']); } else { $EM_Event = new EM_Event(); } //Save Event, only via BP or via [event_form] if ($_REQUEST['action'] == 'event_save' && $EM_Event->can_manage('edit_events', 'edit_others_events')) { //Check Nonces if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'wpnonce_event_save')) { exit('Trying to perform an illegal action.'); } //Grab and validate submitted data if ($EM_Event->get_post() && $EM_Event->save()) { //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS) $events_result = true; //Success notice if (is_user_logged_in()) { $EM_Notices->add_confirm($EM_Event->output(get_option('dbem_events_form_result_success')), true); } else { $EM_Notices->add_confirm($EM_Event->output(get_option('dbem_events_anonymous_result_success')), true); } $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); $redirect = em_add_get_params($redirect, array('success' => 1)); wp_redirect($redirect); exit; } else { $EM_Notices->add_error($EM_Event->get_errors()); $events_result = false; } } if ($_REQUEST['action'] == 'event_duplicate' && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_duplicate_' . $EM_Event->event_id)) { $EM_Event = $EM_Event->duplicate(); if ($EM_Event === false) { $EM_Notices->add_error($EM_Event->errors, true); } else { $EM_Notices->add_confirm($EM_Event->feedback_message, true); } wp_redirect(wp_get_referer()); exit; } if ($_REQUEST['action'] == 'event_delete' && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_delete_' . $EM_Event->event_id)) { //DELETE action $selectedEvents = !empty($_REQUEST['events']) ? $_REQUEST['events'] : ''; if (EM_Object::array_is_numeric($selectedEvents)) { $events_result = EM_Events::delete($selectedEvents); } elseif (is_object($EM_Event)) { $events_result = $EM_Event->delete(); } $plural = count($selectedEvents) > 1 ? __('Events', 'dbem') : __('Event', 'dbem'); if ($events_result) { $message = !empty($EM_Event->feedback_message) ? $EM_Event->feedback_message : sprintf(__('%s successfully deleted.', 'dbem'), $plural); $EM_Notices->add_confirm($message, true); } else { $message = !empty($EM_Event->errors) ? $EM_Event->errors : sprintf(__('%s could not be deleted.', 'dbem'), $plural); $EM_Notices->add_error($message, true); } wp_redirect(wp_get_referer()); exit; } elseif ($_REQUEST['action'] == 'event_detach' && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_detach_' . get_current_user_id() . '_' . $EM_Event->event_id)) { //Detach event and move on if ($EM_Event->detach()) { $EM_Notices->add_confirm($EM_Event->feedback_message, true); } else { $EM_Notices->add_error($EM_Event->errors, true); } wp_redirect(wp_get_referer()); exit; } elseif ($_REQUEST['action'] == 'event_attach' && !empty($_REQUEST['undo_id']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_attach_' . get_current_user_id() . '_' . $EM_Event->event_id)) { //Detach event and move on if ($EM_Event->attach($_REQUEST['undo_id'])) { $EM_Notices->add_confirm($EM_Event->feedback_message, true); } else { $EM_Notices->add_error($EM_Event->errors, true); } wp_redirect(wp_get_referer()); exit; } //AJAX Exit if (isset($events_result) && !empty($_REQUEST['em_ajax'])) { if ($events_result) { $return = array('result' => true, 'message' => $EM_Event->feedback_message); } else { $return = array('result' => false, 'message' => $EM_Event->feedback_message, 'errors' => $EM_Event->errors); } } } //Location Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 8) == 'location') { global $EM_Location, $EM_Notices; //Load the location object, with saved event if requested if (!empty($_REQUEST['location_id'])) { $EM_Location = new EM_Location($_REQUEST['location_id']); } else { $EM_Location = new EM_Location(); } if ($_REQUEST['action'] == 'location_save' && current_user_can('edit_locations')) { if (get_site_option('dbem_ms_mainblog_locations')) { EM_Object::ms_global_switch(); } //switch to main blog if locations are global //Check Nonces em_verify_nonce('location_save'); //Grab and validate submitted data if ($EM_Location->get_post() && $EM_Location->save()) { //EM_location gets the location if submitted via POST and validates it (safer than to depend on JS) $EM_Notices->add_confirm($EM_Location->feedback_message, true); $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); exit; } else { $EM_Notices->add_error($EM_Location->get_errors()); $result = false; } if (get_site_option('dbem_ms_mainblog_locations')) { EM_Object::ms_global_switch_back(); } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "location_delete") { //delete location //get object or objects if (!empty($_REQUEST['locations']) || !empty($_REQUEST['location_id'])) { $args = !empty($_REQUEST['locations']) ? $_REQUEST['locations'] : $_REQUEST['location_id']; $locations = EM_Locations::get($args); foreach ($locations as $location) { if (!$location->delete()) { $EM_Notices->add_error($location->get_errors()); $errors = true; } } if (empty($errors)) { $result = true; $location_term = count($locations) > 1 ? __('Locations', 'dbem') : __('Location', 'dbem'); $EM_Notices->add_confirm(sprintf(__('%s successfully deleted', 'dbem'), $location_term)); } else { $result = false; } } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "locations_search" && (!empty($_REQUEST['term']) || !empty($_REQUEST['q']))) { $results = array(); if (is_user_logged_in() || get_option('dbem_events_anonymous_submissions') && user_can(get_option('dbem_events_anonymous_user'), 'read_others_locations')) { $location_cond = is_user_logged_in() && !current_user_can('read_others_locations') ? "AND location_owner=" . get_current_user_id() : ''; $term = isset($_REQUEST['term']) ? '%' . $_REQUEST['term'] . '%' : '%' . $_REQUEST['q'] . '%'; $sql = $wpdb->prepare("\r\n\t\t\t\t\tSELECT \r\n\t\t\t\t\t\tlocation_id AS `id`,\r\n\t\t\t\t\t\tConcat( location_name, ', ', location_address, ', ', location_town) AS `label`,\r\n\t\t\t\t\t\tlocation_name AS `value`,\r\n\t\t\t\t\t\tlocation_address AS `address`, \r\n\t\t\t\t\t\tlocation_town AS `town`, \r\n\t\t\t\t\t\tlocation_state AS `state`,\r\n\t\t\t\t\t\tlocation_region AS `region`,\r\n\t\t\t\t\t\tlocation_postcode AS `postcode`,\r\n\t\t\t\t\t\tlocation_country AS `country`\r\n\t\t\t\t\tFROM " . EM_LOCATIONS_TABLE . " \r\n\t\t\t\t\tWHERE ( `location_name` LIKE %s ) AND location_status=1 {$location_cond} LIMIT 10\r\n\t\t\t\t", $term); $results = $wpdb->get_results($sql); } echo EM_Object::json_encode($results); die; } if (isset($result) && $result && !empty($_REQUEST['em_ajax'])) { $return = array('result' => true, 'message' => $EM_Location->feedback_message); echo EM_Object::json_encode($return); die; } elseif (isset($result) && !$result && !empty($_REQUEST['em_ajax'])) { $return = array('result' => false, 'message' => $EM_Location->feedback_message, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode($return); die; } } //Booking Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 7) == 'booking' && (is_user_logged_in() || $_REQUEST['action'] == 'booking_add' && get_option('dbem_bookings_anonymous'))) { global $EM_Event, $EM_Booking, $EM_Person; //Load the booking object, with saved booking if requested $EM_Booking = !empty($_REQUEST['booking_id']) ? new EM_Booking($_REQUEST['booking_id']) : new EM_Booking(); if (!empty($EM_Booking->event_id)) { //Load the event object, with saved event if requested $EM_Event = $EM_Booking->get_event(); } elseif (!empty($_REQUEST['event_id'])) { $EM_Event = new EM_Event($_REQUEST['event_id']); } $allowed_actions = array('bookings_approve' => 'approve', 'bookings_reject' => 'reject', 'bookings_unapprove' => 'unapprove', 'bookings_delete' => 'delete'); $result = false; $feedback = ''; if ($_REQUEST['action'] == 'booking_add') { //ADD/EDIT Booking ob_start(); em_verify_nonce('booking_add'); if (!is_user_logged_in() || get_option('dbem_bookings_double') || !$EM_Event->get_bookings()->has_booking(get_current_user_id())) { $post_validation = $EM_Booking->get_post(); do_action('em_booking_add', $EM_Event, $EM_Booking, $post_validation); if ($post_validation) { //Does this user need to be registered first? $registration = true; //TODO do some ticket validation before registering the user if ($EM_Event->get_bookings()->get_available_spaces() >= $EM_Booking->get_spaces(true)) { if ((!is_user_logged_in() || defined('EM_FORCE_REGISTRATION')) && get_option('dbem_bookings_anonymous') && !get_option('dbem_bookings_registration_disable')) { //find random username - less options for user, less things go wrong $username_root = explode('@', $_REQUEST['user_email']); $username_rand = $username_root[0] . rand(1, 1000); while (username_exists($username_root[0] . rand(1, 1000))) { $username_rand = $username_root[0] . rand(1, 1000); } $_REQUEST['dbem_phone'] = !empty($_REQUEST['dbem_phone']) ? $_REQUEST['dbem_phone'] : ''; //fix to prevent warnings $_REQUEST['user_name'] = !empty($_REQUEST['user_name']) ? $_REQUEST['user_name'] : ''; //fix to prevent warnings $user_data = array('user_login' => $username_rand, 'user_email' => $_REQUEST['user_email'], 'user_name' => $_REQUEST['user_name'], 'dbem_phone' => $_REQUEST['dbem_phone']); $id = em_register_new_user($user_data); if (is_numeric($id)) { $EM_Person = new EM_Person($id); $EM_Booking->person_id = $id; $feedback = get_option('dbem_booking_feedback_new_user'); $EM_Notices->add_confirm($feedback); } else { $registration = false; if (is_object($id) && get_class($id) == 'WP_Error') { /* @var $id WP_Error */ if ($id->get_error_code() == 'email_exists') { $EM_Notices->add_error(get_option('dbem_booking_feedback_email_exists')); } else { $EM_Notices->add_error($id->get_error_messages()); } } else { $EM_Notices->add_error(get_option('dbem_booking_feedback_reg_error')); } } } elseif ((!is_user_logged_in() || defined('EM_FORCE_REGISTRATION')) && get_option('dbem_bookings_registration_disable')) { //Validate name, phone and email $user_data = array(); if (empty($EM_Booking->booking_meta['registration'])) { $EM_Booking->booking_meta['registration'] = array(); } // Check the e-mail address if ($_REQUEST['user_email'] == '') { $registration = false; $EM_Notices->add_error(__('<strong>ERROR</strong>: Please type your e-mail address.', 'dbem')); } elseif (!is_email($_REQUEST['user_email'])) { $registration = false; $EM_Notices->add_error(__('<strong>ERROR</strong>: The email address isn’t correct.', 'dbem')); } elseif (email_exists($_REQUEST['user_email'])) { $registration = false; $EM_Notices->add_error(get_option('dbem_booking_feedback_email_exists')); } else { $user_data['user_email'] = $_REQUEST['user_email']; } //Check the user name if (!empty($_REQUEST['user_name'])) { $name_string = explode(' ', wp_kses($_REQUEST['user_name'], array())); $user_data['first_name'] = array_shift($name_string); $user_data['last_name'] = implode(' ', $name_string); } //Check the first/last name if (!empty($_REQUEST['first_name'])) { $user_data['first_name'] = wp_kses($_REQUEST['first_name'], array()); } if (!empty($_REQUEST['last_name'])) { $user_data['last_name'] = wp_kses($_REQUEST['last_name'], array()); } //Check the phone if (!empty($_REQUEST['dbem_phone'])) { $user_data['dbem_phone'] = wp_kses($_REQUEST['dbem_phone'], array()); } //Add booking meta $EM_Booking->booking_meta['registration'] = array_merge($EM_Booking->booking_meta['registration'], $user_data); //in case someone else added stuff //Save default person to booking $EM_Booking->person_id = get_option('dbem_bookings_registration_user'); } elseif (!is_user_logged_in()) { $registration = false; $EM_Notices->add_error(get_option('dbem_booking_feedback_log_in')); } elseif (empty($EM_Booking->person_id)) { //user must be logged in, so we make this person the current user id $EM_Booking->person_id = get_current_user_id(); } } $EM_Bookings = $EM_Event->get_bookings(); if ($registration && $EM_Bookings->add($EM_Booking)) { $result = true; $EM_Notices->add_confirm($EM_Bookings->feedback_message); $feedback = $EM_Bookings->feedback_message; } else { $result = false; $EM_Notices->add_error($EM_Bookings->get_errors()); $feedback = $EM_Bookings->feedback_message; } } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); } } else { $result = false; $feedback = get_option('dbem_booking_feedback_already_booked'); $EM_Notices->add_error($feedback); } ob_clean(); } elseif ($_REQUEST['action'] == 'booking_add_one' && is_object($EM_Event) && is_user_logged_in()) { //ADD/EDIT Booking em_verify_nonce('booking_add_one'); if (!$EM_Event->get_bookings()->has_booking(get_current_user_id()) || get_option('dbem_bookings_double')) { $EM_Booking = new EM_Booking(array('person_id' => get_current_user_id(), 'event_id' => $EM_Event->event_id, 'booking_spaces' => 1)); //new booking $EM_Ticket = $EM_Event->get_bookings()->get_tickets()->get_first(); //get first ticket in this event and book one place there. similar to getting the form values in EM_Booking::get_post_values() $EM_Ticket_Booking = new EM_Ticket_Booking(array('ticket_id' => $EM_Ticket->ticket_id, 'ticket_booking_spaces' => 1)); $EM_Booking->tickets_bookings = new EM_Tickets_Bookings(); $EM_Booking->tickets_bookings->booking = $EM_Ticket_Booking->booking = $EM_Booking; $EM_Booking->tickets_bookings->add($EM_Ticket_Booking); //Now save booking if ($EM_Event->get_bookings()->add($EM_Booking)) { $result = true; $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message); $feedback = $EM_Event->get_bookings()->feedback_message; } else { $result = false; $EM_Notices->add_error($EM_Event->get_bookings()->get_errors()); $feedback = $EM_Event->get_bookings()->feedback_message; } } else { $result = false; $feedback = get_option('dbem_booking_feedback_already_booked'); $EM_Notices->add_error($feedback); } } elseif ($_REQUEST['action'] == 'booking_cancel') { //Cancel Booking em_verify_nonce('booking_cancel'); if ($EM_Booking->can_manage() || $EM_Booking->person->ID == get_current_user_id() && get_option('dbem_bookings_user_cancellation')) { if ($EM_Booking->cancel()) { $result = true; if (!defined('DOING_AJAX')) { if ($EM_Booking->person->ID == get_current_user_id()) { $EM_Notices->add_confirm(get_option('dbem_booking_feedback_cancelled'), true); } else { $EM_Notices->add_confirm($EM_Booking->feedback_message, true); } wp_redirect($_SERVER['HTTP_REFERER']); exit; } } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); $feedback = $EM_Booking->feedback_message; } } else { $EM_Notices->add_error(__('You must log in to cancel your booking.', 'dbem')); } //TODO user action shouldn't check permission, booking object should. } elseif (array_key_exists($_REQUEST['action'], $allowed_actions) && $EM_Event->can_manage('manage_bookings', 'manage_others_bookings')) { //Event Admin only actions $action = $allowed_actions[$_REQUEST['action']]; //Just do it here, since we may be deleting bookings of different events. if (!empty($_REQUEST['bookings']) && EM_Object::array_is_numeric($_REQUEST['bookings'])) { $results = array(); foreach ($_REQUEST['bookings'] as $booking_id) { $EM_Booking = new EM_Booking($booking_id); $result = $EM_Booking->{$action}(); $results[] = $result; if (!in_array(false, $results) && !$result) { $feedback = $EM_Booking->feedback_message; } } $result = !in_array(false, $results); } elseif (is_object($EM_Booking)) { $result = $EM_Booking->{$action}(); $feedback = $EM_Booking->feedback_message; } //FIXME not adhereing to object's feedback or error message, like other bits in this file. //TODO multiple deletion won't work in ajax if (!empty($_REQUEST['em_ajax'])) { if ($result) { echo $feedback; } else { echo '<span style="color:red">' . $feedback . '</span>'; } die; } } elseif ($_REQUEST['action'] == 'booking_save') { em_verify_nonce('booking_save_' . $EM_Booking->booking_id); do_action('em_booking_save', $EM_Event, $EM_Booking); if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings')) { if ($EM_Booking->get_post(true) && $EM_Booking->save(false)) { $EM_Notices->add_confirm($EM_Booking->feedback_message, true); $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); exit; } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); $feedback = $EM_Booking->feedback_message; } } } elseif ($_REQUEST['action'] == 'booking_set_status') { em_verify_nonce('booking_set_status_' . $EM_Booking->booking_id); if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings') && $_REQUEST['booking_status'] != $EM_Booking->booking_status) { if ($EM_Booking->set_status($_REQUEST['booking_status'], false)) { if (!empty($_REQUEST['send_email'])) { if ($EM_Booking->email(false)) { $EM_Booking->feedback_message .= " " . __('Mail Sent.', 'dbem'); } else { $EM_Booking->feedback_message .= ' <span style="color:red">' . __('ERROR : Mail Not Sent.', 'dbem') . '</span>'; } } $EM_Notices->add_confirm($EM_Booking->feedback_message, true); $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); exit; } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); $feedback = $EM_Booking->feedback_message; } } } elseif ($_REQUEST['action'] == 'booking_resend_email') { em_verify_nonce('booking_resend_email_' . $EM_Booking->booking_id); if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings')) { if ($EM_Booking->email(false, true)) { $EM_Notices->add_confirm(__('Mail Sent.', 'dbem'), true); $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); exit; } else { $result = false; $EM_Notices->add_error(__('ERROR : Mail Not Sent.', 'dbem')); $feedback = $EM_Booking->feedback_message; } } } if ($result && defined('DOING_AJAX')) { $return = array('result' => true, 'message' => $feedback); echo EM_Object::json_encode(apply_filters('em_action_' . $_REQUEST['action'], $return, $EM_Booking)); die; } elseif (!$result && defined('DOING_AJAX')) { $return = array('result' => false, 'message' => $feedback, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode(apply_filters('em_action_' . $_REQUEST['action'], $return, $EM_Booking)); die; } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'booking_add' && !is_user_logged_in() && !get_option('dbem_bookings_anonymous')) { $EM_Notices->add_error(get_option('dbem_booking_feedback_log_in')); if (!$result && defined('DOING_AJAX')) { $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode(apply_filters('em_action_' . $_REQUEST['action'], $return, $EM_Booking)); } die; } //AJAX call for searches if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 6) == 'search') { if ($_REQUEST['action'] == 'search_states') { $results = array(); $conds = array(); if (!empty($_REQUEST['country'])) { $conds[] = $wpdb->prepare("(location_country = '%s' OR location_country IS NULL )", $_REQUEST['country']); } if (!empty($_REQUEST['region'])) { $conds[] = $wpdb->prepare("( location_region = '%s' OR location_region IS NULL )", $_REQUEST['region']); } $cond = count($conds) > 0 ? "AND " . implode(' AND ', $conds) : ''; $results = $wpdb->get_col("SELECT DISTINCT location_state FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' {$cond} ORDER BY location_state"); if ($_REQUEST['return_html']) { //quick shortcut for quick html form manipulation ob_start(); ?> <option value=''><?php echo get_option('dbem_search_form_states_label'); ?> </option> <?php foreach ($results as $result) { echo "<option>{$result}</option>"; } $return = ob_get_clean(); echo apply_filters('em_ajax_search_states', $return); exit; } else { echo EM_Object::json_encode($results); exit; } } if ($_REQUEST['action'] == 'search_towns') { $results = array(); $conds = array(); if (!empty($_REQUEST['country'])) { $conds[] = $wpdb->prepare("(location_country = '%s' OR location_country IS NULL )", $_REQUEST['country']); } if (!empty($_REQUEST['region'])) { $conds[] = $wpdb->prepare("( location_region = '%s' OR location_region IS NULL )", $_REQUEST['region']); } if (!empty($_REQUEST['state'])) { $conds[] = $wpdb->prepare("(location_state = '%s' OR location_state IS NULL )", $_REQUEST['state']); } $cond = count($conds) > 0 ? "AND " . implode(' AND ', $conds) : ''; $results = $wpdb->get_col("SELECT DISTINCT location_town FROM " . EM_LOCATIONS_TABLE . " WHERE location_town IS NOT NULL AND location_town != '' {$cond} ORDER BY location_town"); if ($_REQUEST['return_html']) { //quick shortcut for quick html form manipulation ob_start(); ?> <option value=''><?php echo get_option('dbem_search_form_towns_label'); ?> </option> <?php foreach ($results as $result) { echo "<option>{$result}</option>"; } $return = ob_get_clean(); echo apply_filters('em_ajax_search_towns', $return); exit; } else { echo EM_Object::json_encode($results); exit; } } if ($_REQUEST['action'] == 'search_regions') { if (!empty($_REQUEST['country'])) { $conds[] = $wpdb->prepare("(location_country = '%s' OR location_country IS NULL )", $_REQUEST['country']); } $cond = count($conds) > 0 ? "AND " . implode(' AND ', $conds) : ''; $results = $wpdb->get_results("SELECT DISTINCT location_region AS value FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != '' {$cond} ORDER BY location_region"); if ($_REQUEST['return_html']) { //quick shortcut for quick html form manipulation ob_start(); ?> <option value=''><?php echo get_option('dbem_search_form_regions_label'); ?> </option> <?php foreach ($results as $result) { echo "<option>{$result->value}</option>"; } $return = ob_get_clean(); echo apply_filters('em_ajax_search_regions', $return); exit; } else { echo EM_Object::json_encode($results); exit; } } elseif ($_REQUEST['action'] == 'search_events' && get_option('dbem_events_page_search') && defined('DOING_AJAX')) { $args = EM_Events::get_post_search(); $args['owner'] = false; ob_start(); em_locate_template('templates/events-list.php', true, array('args' => $args)); //if successful, this template overrides the settings and defaults, including search echo apply_filters('em_ajax_search_events', ob_get_clean(), $args); exit; } } //EM Ajax requests require this flag. if (is_user_logged_in()) { //Admin operations //Specific Oject Ajax if (!empty($_REQUEST['em_obj'])) { switch ($_REQUEST['em_obj']) { case 'em_bookings_events_table': case 'em_bookings_pending_table': case 'em_bookings_confirmed_table': //add some admin files just in case include_once 'admin/bookings/em-confirmed.php'; include_once 'admin/bookings/em-events.php'; include_once 'admin/bookings/em-pending.php'; call_user_func($_REQUEST['em_obj']); exit; break; } } } //Export CSV - WIP if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'export_bookings_csv' && wp_verify_nonce($_REQUEST['_wpnonce'], 'export_bookings_csv')) { //sort out cols if (!empty($_REQUEST['cols']) && is_array($_REQUEST['cols'])) { $cols = array(); foreach ($_REQUEST['cols'] as $col => $active) { if ($active) { $cols[] = $col; } } $_REQUEST['cols'] = $cols; } $_REQUEST['limit'] = 0; //generate bookings export according to search request $show_tickets = !empty($_REQUEST['show_tickets']); $EM_Bookings_Table = new EM_Bookings_Table($show_tickets); header("Content-Type: application/octet-stream; charset=utf-8"); header("Content-Disposition: Attachment; filename=" . sanitize_title(get_bloginfo()) . "-bookings-export.csv"); echo sprintf(__('Exported booking on %s', 'dbem'), date_i18n('D d M Y h:i', current_time('timestamp'))) . "\n"; echo '"' . implode('","', $EM_Bookings_Table->get_headers(true)) . '"' . "\n"; //Rows $EM_Bookings_Table->limit = 150; //if you're having server memory issues, try messing with this number $EM_Bookings = $EM_Bookings_Table->get_bookings(); $handle = fopen("php://output", "w"); while (!empty($EM_Bookings)) { foreach ($EM_Bookings as $EM_Booking) { //Display all values /* @var $EM_Booking EM_Booking */ /* @var $EM_Ticket_Booking EM_Ticket_Booking */ if ($show_tickets) { foreach ($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking) { $row = $EM_Bookings_Table->get_row_csv($EM_Ticket_Booking); fputcsv($handle, $row); } } else { $row = $EM_Bookings_Table->get_row_csv($EM_Booking); fputcsv($handle, $row); } } //reiterate loop $EM_Bookings_Table->offset += $EM_Bookings_Table->limit; $EM_Bookings = $EM_Bookings_Table->get_bookings(); } fclose($handle); exit; } }
/** * Will output a event in the format passed in $format by replacing placeholders within the format. * @param string $format * @param string $target * @return string */ function output($format, $target = "html") { //First let's do some conditional placeholder removals preg_match_all('/\\{([a-zA-Z0-9_]+)\\}([^{]+)\\{\\/[a-zA-Z0-9_]+\\}/', $format, $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) { $replacement = $conditionals[0][$key]; if ($condition == 'has_bookings') { //check if there's a booking, if not, remove this section of code. if ($this->rsvp) { $replacement = substr($conditionals[0][$key], 14, strlen($conditionals[0][$key]) - 29); //29 = (15+14) } else { $replacement = ''; } } if ($condition == 'no_bookings') { //check if there's a booking, if not, remove this section of code. if (!$this->rsvp) { $replacement = substr($conditionals[0][$key], 13, strlen($conditionals[0][$key]) - 28); //28 = (13+14) } else { $replacement = ''; } str_replace($conditionals[0][$key], $replacement, $format); } $format = str_replace($conditionals[0][$key], apply_filters('em_event_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $format); } } $event_string = $format; //Now let's check out the placeholders. preg_match_all("/#@?_?[A-Za-z0-9]+/", $format, $placeholders); foreach ($placeholders[0] as $result) { $match = true; $replace = ''; switch ($result) { //Event Details case '#_EVENTID': $replace = $this->id; break; case '#_NAME': $replace = $this->name; break; case '#_NOTES': case '#_EXCERPT': //SEE AT BOTTOM OF FILE FOR OLD TARGET FILTERS FROM 2.x $replace = $this->notes; if ($result == "#_EXCERPT") { $matches = explode('<!--more', $this->notes); $replace = $matches[0]; } break; case '#_EVENTIMAGEURL': case '#_EVENTIMAGE': if ($this->image_url != '') { $replace = $result == '#_EVENTIMAGEURL' ? $this->image_url : "<img src='" . $this->image_url . "' alt='" . $this->name . "'/>"; } break; //Times //Times case '#_24HSTARTTIME': case '#_24HENDTIME': $time = $result == '#_24HSTARTTIME' ? $this->start_time : $this->end_time; $replace = substr($time, 0, 5); break; case '#_12HSTARTTIME': case '#_12HENDTIME': $time = $result == '#_12HSTARTTIME' ? $this->start_time : $this->end_time; $replace = date('g:i A', strtotime($time)); break; //Links //Links case '#_EVENTPAGEURL': //Depreciated //Depreciated case '#_LINKEDNAME': //Depreciated //Depreciated case '#_EVENTURL': //Just the URL //Just the URL case '#_EVENTLINK': //HTML Link //If this event is not of this blog, we need a new URL $EM_URI = EM_URI; if (is_multisite() && get_site_option('dbem_ms_global_events') && get_site_option('dbem_ms_global_events_links') && !empty($this->blog_id) && is_main_site() && $this->blog_id != get_current_blog_id()) { $EM_URI = get_blog_permalink($this->blog_id, get_blog_option($this->blog_id, 'dbem_events_page')); } $joiner = stristr($EM_URI, "?") ? "&" : "?"; $event_link = $EM_URI . $joiner . "event_id=" . $this->id; if ($result == '#_LINKEDNAME' || $result == '#_EVENTLINK') { $replace = "<a href='{$event_link}' title='{$this->name}'>{$this->name}</a>"; } else { $replace = $event_link; } break; case '#_EDITEVENTURL': case '#_EDITEVENTLINK': if ($this->can_manage('edit_events', 'edit_others_events')) { if (is_multisite() && get_site_option('dbem_ms_global_events') && get_site_option('dbem_ms_global_events_links') && !empty($this->blog_id) && is_main_site() && $this->blog_id != get_current_blog_id()) { $replace = get_site_url($this->blog_id, "/wp-admin/admin.php?page=events-manager-event&event_id={$this->id}"); } else { $replace = get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-event&event_id={$this->id}"; } if ($result == '#_EDITEVENTLINK') { $replace = "<a href='{$replace}'>" . __('Edit') . ' ' . __('Event', 'dbem') . "</a>"; } } break; //Bookings //Bookings case '#_ADDBOOKINGFORM': //Depreciated //Depreciated case '#_REMOVEBOOKINGFORM': //Depreciated //Depreciated case '#_BOOKINGFORM': ob_start(); $template = em_locate_template('placeholders/bookingform.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_BOOKINGBUTTON': ob_start(); $template = em_locate_template('placeholders/bookingbutton.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_AVAILABLESEATS': //Depreciated //Depreciated case '#_AVAILABLESPACES': if ($this->rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_available_spaces(); } else { $replace = "0"; } break; case '#_BOOKEDSEATS': //Depreciated //Depreciated case '#_BOOKEDSPACES': if ($this->rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_booked_spaces(); } else { $replace = "0"; } break; case '#_PENDINGSPACES': if ($this->rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_pending_spaces(); } else { $replace = "0"; } break; case '#_SEATS': //Depreciated //Depreciated case '#_SPACES': $replace = $this->get_spaces(); break; case '#_BOOKINGSURL': case '#_BOOKINGSLINK': $bookings_link = get_bloginfo('wpurl') . "/wp-admin/admin.php?page=events-manager-bookings&event_id=" . $this->id; if ($result == '#_BOOKINGSLINK') { $replace = "<a href='{$bookings_link}' title='{$this->name}'>{$this->name}</a>"; } else { $replace = $bookings_link; } break; //Contact Person //Contact Person case '#_CONTACTNAME': case '#_CONTACTPERSON': //Depreciated (your call, I think name is better) $replace = $this->contact->display_name; break; case '#_CONTACTUSERNAME': $replace = $this->contact->user_login; break; case '#_CONTACTEMAIL': case '#_CONTACTMAIL': //Depreciated $replace = $this->contact->user_email; break; case '#_CONTACTID': $replace = $this->contact->ID; break; case '#_CONTACTPHONE': $replace = $this->contact->phone != '' ? $this->contact->phone : __('N/A', 'dbem'); break; case '#_CONTACTAVATAR': $replace = get_avatar($this->contact->ID, $size = '50'); break; case '#_CONTACTPROFILELINK': case '#_CONTACTPROFILEURL': if (function_exists('bp_core_get_user_domain')) { $replace = bp_core_get_user_domain($this->contact->ID); if ($result == '#_CONTACTPROFILELINK') { $replace = '<a href="' . $replace . '">' . __('Profile') . '</a>'; } } break; case '#_CONTACTPROFILELINK': case '#_CONTACTPROFILEURL': if (function_exists('bp_core_get_user_domain')) { $replace = bp_core_get_user_domain($this->contact->ID); if ($result == '#_CONTACTPROFILELINK') { $replace = '<a href="' . $replace . '">' . __('Profile') . '</a>'; } } break; case '#_ATTENDEES': ob_start(); $template = em_locate_template('placeholders/attendees.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_CATEGORIES': ob_start(); $template = em_locate_template('placeholders/categories.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; default: $replace = $result; break; } $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } //Time placeholders foreach ($placeholders[0] as $result) { // matches all PHP START date and time placeholders if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#"), $this->start); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } // matches all PHP END time placeholders for endtime if (preg_match('/^#@[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#@"), $this->end); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } } //Time place holder that doesn't show if empty. //TODO add filter here too preg_match_all('/#@?_\\{[A-Za-z0-9 -\\/,\\.\\\\]+\\}/', $format, $results); foreach ($results[0] as $result) { if (substr($result, 0, 3) == "#@_") { $date = 'end_date'; $offset = 4; } else { $date = 'start_date'; $offset = 3; } if ($date == 'end_date' && $this->end_date == $this->start_date) { $replace = __(apply_filters('em_event_output_placeholder', '', $this, $result, $target)); } else { $replace = __(apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, strlen($result) - ($offset + 1)), $this->{$date}), $this, $result, $target)); } $event_string = str_replace($result, $replace, $event_string); } //This is for the custom attributes preg_match_all('/#_ATT\\{([^}]+)\\}(\\{([^}]+)\\})?/', $format, $results); foreach ($results[0] as $resultKey => $result) { //Strip string of placeholder and just leave the reference $attRef = substr(substr($result, 0, strpos($result, '}')), 6); $attString = ''; if (is_array($this->attributes) && array_key_exists($attRef, $this->attributes)) { $attString = $this->attributes[$attRef]; } elseif (!empty($results[3][$resultKey])) { //Check to see if we have a second set of braces; $attString = $results[3][$resultKey]; } $attString = apply_filters('em_event_output_placeholder', $attString, $this, $result, $target); $event_string = str_replace($result, $attString, $event_string); } //Now do dependent objects $event_string = $this->location->output($event_string, $target); //for backwards compat and easy use, take over the individual category placeholders with the frirst cat in th elist. $EM_Categories = $this->get_categories(); if (count($EM_Categories->categories) > 0) { $EM_Category = $EM_Categories->categories[0]; } if (empty($EM_Category)) { $EM_Category = new EM_Category(); } $event_string = $EM_Category->output($event_string, $target); return apply_filters('em_event_output', $event_string, $this, $target); }
/** * Shows a single location according to given specifications. Accepts any event query attribute. * @param array $atts * @return string */ function em_get_location_shortcode($atts, $format = '') { $atts = (array) $atts; $atts['format'] = $format != '' || empty($atts['format']) ? $format : $atts['format']; $atts['format'] = html_entity_decode($atts['format']); //shorcode doesn't accept html if (!empty($atts['location']) && is_numeric($atts['location'])) { $EM_Location = new EM_Location($atts['location']); return !empty($atts['format']) ? $EM_Location->output($atts['format']) : $EM_Location->output_single(); } }
/** * Filter for titles when on event pages * @param $data * @return string */ function em_events_page_title($content) { global $EM_Event; global $post; $events_page_id = get_option('dbem_events_page'); if ($post->ID == $events_page_id && $events_page_id != 0) { if (isset($_REQUEST['calendar_day']) && $_REQUEST['calendar_day'] != '') { $events = EM_Events::get(array('limit' => 2, 'scope' => $_REQUEST['calendar_day'], 'owner' => false)); if (count($events) != 1 || get_option('dbem_display_calendar_day_single') == 1) { //We only support dates for the calendar day list title, so we do a simple filter for the supplied calendar_day $content = get_option('dbem_list_date_title'); preg_match_all("/#[A-Za-z0-9]+/", $content, $placeholders); foreach ($placeholders[0] as $placeholder) { // matches all PHP date and time placeholders if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $placeholder)) { $content = str_replace($placeholder, mysql2date(ltrim($placeholder, "#"), $_REQUEST['calendar_day']), $content); } } } else { $event = array_shift($events); $content = $event->output(get_option('dbem_event_page_title_format')); } } elseif (isset($_REQUEST['location_id']) && ($_REQUEST['location_id'] |= '')) { $location = new EM_Location(EM_Object::sanitize($_REQUEST['location_id'])); $content = $location->output(get_option('dbem_location_page_title_format')); } elseif (isset($_REQUEST['event_id']) && $_REQUEST['event_id'] != '') { // single event page $content = $EM_Event->output(get_option('dbem_event_page_title_format')); } else { // Multiple events page $content = get_option('dbem_events_page_title'); } //TODO FILTER - filter titles before em output } return apply_filters('em_events_page_title', $content); }
/** * Performs actions on init. This works for both ajax and normal requests, the return results depends if an em_ajax flag is passed via POST or GET. */ function em_init_actions() { global $wpdb, $EM_Notices, $EM_Event; if (defined('DOING_AJAX') && DOING_AJAX) { $_REQUEST['em_ajax'] = true; } //NOTE - No EM objects are globalized at this point, as we're hitting early init mode. //TODO Clean this up.... use a uniformed way of calling EM Ajax actions if (!empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action'])) { if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') { if (isset($_REQUEST['id'])) { $EM_Location = new EM_Location($_REQUEST['id'], 'location_id'); $location_array = $EM_Location->to_array(); $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format')); echo EM_Object::json_encode($location_array); } die; } if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'delete_ticket') { if (isset($_REQUEST['id'])) { $EM_Ticket = new EM_Ticket($_REQUEST['id']); $result = $EM_Ticket->delete(); if ($result) { $result = array('result' => true); } else { $result = array('result' => false, 'error' => $EM_Ticket->feedback_message); } } else { $result = array('result' => false, 'error' => __('No ticket id provided', 'dbem')); } echo EM_Object::json_encode($result); die; } if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') { $EM_Locations = EM_Locations::get($_REQUEST); $json_locations = array(); foreach ($EM_Locations as $location_key => $EM_Location) { $json_locations[$location_key] = $EM_Location->to_array(); $json_locations[$location_key]['location_balloon'] = $EM_Location->output(get_option('dbem_map_text_format')); } echo EM_Object::json_encode($json_locations); die; } if (isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) { //FIXME if long events enabled originally, this won't show up on ajax call echo EM_Calendar::output($_REQUEST, false); die; } } //Event Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 5) == 'event') { //Load the event object, with saved event if requested if (!empty($_REQUEST['event_id'])) { $EM_Event = new EM_Event($_REQUEST['event_id']); } else { $EM_Event = new EM_Event(); } //Save Event, only via BP or via [event_form] if ($_REQUEST['action'] == 'event_save' && $EM_Event->can_manage('edit_events', 'edit_others_events')) { //Check Nonces if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'wpnonce_event_save')) { exit('Trying to perform an illegal action.'); } //Grab and validate submitted data if ($EM_Event->get_post() && $EM_Event->save()) { //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS) $events_result = true; //Success notice if (is_user_logged_in()) { if (empty($_REQUEST['event_id'])) { $EM_Notices->add_confirm($EM_Event->output(get_option('dbem_events_form_result_success')), true); } else { $EM_Notices->add_confirm($EM_Event->output(get_option('dbem_events_form_result_success_updated')), true); } } else { $EM_Notices->add_confirm($EM_Event->output(get_option('dbem_events_anonymous_result_success')), true); } $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); $redirect = em_add_get_params($redirect, array('success' => 1), false, false); wp_redirect($redirect); exit; } else { $EM_Notices->add_error($EM_Event->get_errors()); $events_result = false; } } if ($_REQUEST['action'] == 'event_duplicate' && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_duplicate_' . $EM_Event->event_id)) { $event = $EM_Event->duplicate(); if ($event === false) { $EM_Notices->add_error($EM_Event->errors, true); wp_redirect(wp_get_referer()); } else { $EM_Notices->add_confirm($EM_Event->feedback_message, true); wp_redirect($event->get_edit_url()); } exit; } if ($_REQUEST['action'] == 'event_delete' && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_delete_' . $EM_Event->event_id)) { //DELETE action $selectedEvents = !empty($_REQUEST['events']) ? $_REQUEST['events'] : ''; if (EM_Object::array_is_numeric($selectedEvents)) { $events_result = EM_Events::delete($selectedEvents); } elseif (is_object($EM_Event)) { $events_result = $EM_Event->delete(); } $plural = count($selectedEvents) > 1 ? __('Events', 'dbem') : __('Event', 'dbem'); if ($events_result) { $message = !empty($EM_Event->feedback_message) ? $EM_Event->feedback_message : sprintf(__('%s successfully deleted.', 'dbem'), $plural); $EM_Notices->add_confirm($message, true); } else { $message = !empty($EM_Event->errors) ? $EM_Event->errors : sprintf(__('%s could not be deleted.', 'dbem'), $plural); $EM_Notices->add_error($message, true); } wp_redirect(wp_get_referer()); exit; } elseif ($_REQUEST['action'] == 'event_detach' && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_detach_' . get_current_user_id() . '_' . $EM_Event->event_id)) { //Detach event and move on if ($EM_Event->detach()) { $EM_Notices->add_confirm($EM_Event->feedback_message, true); } else { $EM_Notices->add_error($EM_Event->errors, true); } wp_redirect(wp_get_referer()); exit; } elseif ($_REQUEST['action'] == 'event_attach' && !empty($_REQUEST['undo_id']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_attach_' . get_current_user_id() . '_' . $EM_Event->event_id)) { //Detach event and move on if ($EM_Event->attach($_REQUEST['undo_id'])) { $EM_Notices->add_confirm($EM_Event->feedback_message, true); } else { $EM_Notices->add_error($EM_Event->errors, true); } wp_redirect(wp_get_referer()); exit; } //AJAX Exit if (isset($events_result) && !empty($_REQUEST['em_ajax'])) { if ($events_result) { $return = array('result' => true, 'message' => $EM_Event->feedback_message); } else { $return = array('result' => false, 'message' => $EM_Event->feedback_message, 'errors' => $EM_Event->errors); } echo EM_Object::json_encode($return); edit(); } } //Location Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 8) == 'location') { global $EM_Location, $EM_Notices; //Load the location object, with saved event if requested if (!empty($_REQUEST['location_id'])) { $EM_Location = new EM_Location($_REQUEST['location_id']); } else { $EM_Location = new EM_Location(); } if ($_REQUEST['action'] == 'location_save' && $EM_Location->can_manage('edit_locations', 'edit_others_locations')) { //Check Nonces em_verify_nonce('location_save'); //Grab and validate submitted data if ($EM_Location->get_post() && $EM_Location->save()) { //EM_location gets the location if submitted via POST and validates it (safer than to depend on JS) $EM_Notices->add_confirm($EM_Location->feedback_message, true); $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); exit; } else { $EM_Notices->add_error($EM_Location->get_errors()); $result = false; } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "location_delete") { //delete location //get object or objects if (!empty($_REQUEST['locations']) || !empty($_REQUEST['location_id'])) { $args = !empty($_REQUEST['locations']) ? $_REQUEST['locations'] : $_REQUEST['location_id']; $locations = EM_Locations::get($args); foreach ($locations as $location) { if (!$location->delete()) { $EM_Notices->add_error($location->get_errors()); $errors = true; } } if (empty($errors)) { $result = true; $location_term = count($locations) > 1 ? __('Locations', 'dbem') : __('Location', 'dbem'); $EM_Notices->add_confirm(sprintf(__('%s successfully deleted', 'dbem'), $location_term)); } else { $result = false; } } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "locations_search" && (!empty($_REQUEST['term']) || !empty($_REQUEST['q']))) { $results = array(); if (is_user_logged_in() || get_option('dbem_events_anonymous_submissions') && user_can(get_option('dbem_events_anonymous_user'), 'read_others_locations')) { $location_cond = is_user_logged_in() && !current_user_can('read_others_locations') ? "AND location_owner=" . get_current_user_id() : ''; if (!is_user_logged_in() && get_option('dbem_events_anonymous_submissions')) { if (!user_can(get_option('dbem_events_anonymous_user'), 'read_private_locations')) { $location_cond = " AND location_private=0"; } } elseif (is_user_logged_in() && !current_user_can('read_private_locations')) { $location_cond = " AND location_private=0"; } elseif (!is_user_logged_in()) { $location_cond = " AND location_private=0"; } $location_cond = apply_filters('em_actions_locations_search_cond', $location_cond); $term = isset($_REQUEST['term']) ? '%' . $_REQUEST['term'] . '%' : '%' . $_REQUEST['q'] . '%'; $sql = $wpdb->prepare("\n\t\t\t\t\tSELECT \n\t\t\t\t\t\tlocation_id AS `id`,\n\t\t\t\t\t\tConcat( location_name ) AS `label`,\n\t\t\t\t\t\tlocation_name AS `value`,\n\t\t\t\t\t\tlocation_address AS `address`, \n\t\t\t\t\t\tlocation_town AS `town`, \n\t\t\t\t\t\tlocation_state AS `state`,\n\t\t\t\t\t\tlocation_region AS `region`,\n\t\t\t\t\t\tlocation_postcode AS `postcode`,\n\t\t\t\t\t\tlocation_country AS `country`\n\t\t\t\t\tFROM " . EM_LOCATIONS_TABLE . " \n\t\t\t\t\tWHERE ( `location_name` LIKE %s ) AND location_status=1 {$location_cond} LIMIT 10\n\t\t\t\t", $term); $results = $wpdb->get_results($sql); } echo EM_Object::json_encode($results); die; } if (isset($result) && $result && !empty($_REQUEST['em_ajax'])) { $return = array('result' => true, 'message' => $EM_Location->feedback_message); echo EM_Object::json_encode($return); die; } elseif (isset($result) && !$result && !empty($_REQUEST['em_ajax'])) { $return = array('result' => false, 'message' => $EM_Location->feedback_message, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode($return); die; } } //Booking Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 7) == 'booking' && (is_user_logged_in() || $_REQUEST['action'] == 'booking_add' && get_option('dbem_bookings_anonymous'))) { global $EM_Event, $EM_Booking, $EM_Person; //Load the booking object, with saved booking if requested $EM_Booking = !empty($_REQUEST['booking_id']) ? em_get_booking($_REQUEST['booking_id']) : em_get_booking(); if (!empty($EM_Booking->event_id)) { //Load the event object, with saved event if requested $EM_Event = $EM_Booking->get_event(); } elseif (!empty($_REQUEST['event_id'])) { $EM_Event = new EM_Event($_REQUEST['event_id']); } $allowed_actions = array('bookings_approve' => 'approve', 'bookings_reject' => 'reject', 'bookings_unapprove' => 'unapprove', 'bookings_delete' => 'delete'); $result = false; $feedback = ''; if ($_REQUEST['action'] == 'booking_add') { //ADD/EDIT Booking ob_start(); if (!defined('WP_CACHE') || !WP_CACHE) { em_verify_nonce('booking_add'); } if (!is_user_logged_in() || get_option('dbem_bookings_double') || !$EM_Event->get_bookings()->has_booking(get_current_user_id())) { $EM_Booking->get_post(); $post_validation = $EM_Booking->validate(); do_action('em_booking_add', $EM_Event, $EM_Booking, $post_validation); if ($post_validation) { //register the user - or not depending - according to the booking $registration = em_booking_add_registration($EM_Booking); $EM_Bookings = $EM_Event->get_bookings(); if ($registration && $EM_Bookings->add($EM_Booking)) { if (is_user_logged_in() && is_multisite() && !is_user_member_of_blog(get_current_user_id(), get_current_blog_id())) { add_user_to_blog(get_current_blog_id(), get_current_user_id(), get_option('default_role')); } $result = true; $EM_Notices->add_confirm($EM_Bookings->feedback_message); $feedback = $EM_Bookings->feedback_message; } else { $result = false; if (!$registration) { $EM_Notices->add_error($EM_Booking->get_errors()); $feedback = $EM_Booking->feedback_message; } else { $EM_Notices->add_error($EM_Bookings->get_errors()); $feedback = $EM_Bookings->feedback_message; } } global $em_temp_user_data; $em_temp_user_data = false; //delete registered user temp info (if exists) } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); } } else { $result = false; $feedback = get_option('dbem_booking_feedback_already_booked'); $EM_Notices->add_error($feedback); } ob_clean(); } elseif ($_REQUEST['action'] == 'booking_add_one' && is_object($EM_Event) && is_user_logged_in()) { //ADD/EDIT Booking em_verify_nonce('booking_add_one'); if (!$EM_Event->get_bookings()->has_booking(get_current_user_id()) || get_option('dbem_bookings_double')) { $EM_Booking = em_get_booking(array('person_id' => get_current_user_id(), 'event_id' => $EM_Event->event_id, 'booking_spaces' => 1)); //new booking $EM_Ticket = $EM_Event->get_bookings()->get_tickets()->get_first(); //get first ticket in this event and book one place there. similar to getting the form values in EM_Booking::get_post_values() $EM_Ticket_Booking = new EM_Ticket_Booking(array('ticket_id' => $EM_Ticket->ticket_id, 'ticket_booking_spaces' => 1)); $EM_Booking->tickets_bookings = new EM_Tickets_Bookings(); $EM_Booking->tickets_bookings->booking = $EM_Ticket_Booking->booking = $EM_Booking; $EM_Booking->tickets_bookings->add($EM_Ticket_Booking); //Now save booking if ($EM_Event->get_bookings()->add($EM_Booking)) { $result = true; $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message); $feedback = $EM_Event->get_bookings()->feedback_message; } else { $result = false; $EM_Notices->add_error($EM_Event->get_bookings()->get_errors()); $feedback = $EM_Event->get_bookings()->feedback_message; } } else { $result = false; $feedback = get_option('dbem_booking_feedback_already_booked'); $EM_Notices->add_error($feedback); } } elseif ($_REQUEST['action'] == 'booking_cancel') { //Cancel Booking em_verify_nonce('booking_cancel'); if ($EM_Booking->can_manage() || $EM_Booking->person->ID == get_current_user_id() && get_option('dbem_bookings_user_cancellation')) { if ($EM_Booking->cancel()) { $result = true; if (!defined('DOING_AJAX')) { if ($EM_Booking->person->ID == get_current_user_id()) { $EM_Notices->add_confirm(get_option('dbem_booking_feedback_cancelled'), true); } else { $EM_Notices->add_confirm($EM_Booking->feedback_message, true); } wp_redirect($_SERVER['HTTP_REFERER']); exit; } } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); $feedback = $EM_Booking->feedback_message; } } else { $EM_Notices->add_error(__('You must log in to cancel your booking.', 'dbem')); } //TODO user action shouldn't check permission, booking object should. } elseif (array_key_exists($_REQUEST['action'], $allowed_actions) && $EM_Event->can_manage('manage_bookings', 'manage_others_bookings')) { //Event Admin only actions $action = $allowed_actions[$_REQUEST['action']]; //Just do it here, since we may be deleting bookings of different events. if (!empty($_REQUEST['bookings']) && EM_Object::array_is_numeric($_REQUEST['bookings'])) { $results = array(); foreach ($_REQUEST['bookings'] as $booking_id) { $EM_Booking = em_get_booking($booking_id); $result = $EM_Booking->{$action}(); $results[] = $result; if (!in_array(false, $results) && !$result) { $feedback = $EM_Booking->feedback_message; } } $result = !in_array(false, $results); } elseif (is_object($EM_Booking)) { $result = $EM_Booking->{$action}(); $feedback = $EM_Booking->feedback_message; } //FIXME not adhereing to object's feedback or error message, like other bits in this file. //TODO multiple deletion won't work in ajax if (!empty($_REQUEST['em_ajax'])) { if ($result) { echo $feedback; } else { echo '<span style="color:red">' . $feedback . '</span>'; } die; } else { if ($result) { $EM_Notices->add_confirm($feedback); } else { $EM_Notices->add_error($feedback); } } } elseif ($_REQUEST['action'] == 'booking_save') { em_verify_nonce('booking_save_' . $EM_Booking->booking_id); do_action('em_booking_save', $EM_Event, $EM_Booking); if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings')) { if ($EM_Booking->get_post(true) && $EM_Booking->validate(true) && $EM_Booking->save(false)) { $EM_Notices->add_confirm($EM_Booking->feedback_message, true); $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); exit; } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); $feedback = $EM_Booking->feedback_message; } } } elseif ($_REQUEST['action'] == 'booking_set_status') { em_verify_nonce('booking_set_status_' . $EM_Booking->booking_id); if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings') && $_REQUEST['booking_status'] != $EM_Booking->booking_status) { if ($EM_Booking->set_status($_REQUEST['booking_status'], false, true)) { if (!empty($_REQUEST['send_email'])) { if ($EM_Booking->email()) { if ($EM_Booking->mails_sent > 0) { $EM_Booking->feedback_message .= " " . __('Email Sent.', 'dbem'); } else { $EM_Booking->feedback_message .= " " . _x('No emails to send for this booking.', 'bookings', 'dbem'); } } else { $EM_Booking->feedback_message .= ' <span style="color:red">' . __('ERROR : Email Not Sent.', 'dbem') . '</span>'; } } $EM_Notices->add_confirm($EM_Booking->feedback_message, true); $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); exit; } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); $feedback = $EM_Booking->feedback_message; } } } elseif ($_REQUEST['action'] == 'booking_resend_email') { em_verify_nonce('booking_resend_email_' . $EM_Booking->booking_id); if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings')) { if ($EM_Booking->email(false, true)) { if ($EM_Booking->mails_sent > 0) { $EM_Notices->add_confirm(__('Email Sent.', 'dbem'), true); } else { $EM_Notices->add_confirm(_x('No emails to send for this booking.', 'bookings', 'dbem'), true); } $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); exit; } else { $result = false; $EM_Notices->add_error(__('ERROR : Email Not Sent.', 'dbem')); $feedback = $EM_Booking->feedback_message; } } } elseif ($_REQUEST['action'] == 'booking_modify_person') { em_verify_nonce('booking_modify_person_' . $EM_Booking->booking_id); if ($EM_Booking->can_manage('manage_bookings', 'manage_others_bookings')) { global $wpdb; $no_user = get_option('dbem_bookings_registration_disable') && $EM_Booking->get_person()->ID == get_option('dbem_bookings_registration_user'); if ($no_user && $EM_Booking->get_person_post() && $wpdb->update(EM_BOOKINGS_TABLE, array('booking_meta' => serialize($EM_Booking->booking_meta)), array('booking_id' => $EM_Booking->booking_id))) { $EM_Notices->add_confirm($EM_Booking->feedback_message, true); $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); exit; } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); $feedback = $EM_Booking->feedback_message; } } do_action('em_booking_modify_person', $EM_Event, $EM_Booking); } if ($result && defined('DOING_AJAX')) { $return = array('result' => true, 'message' => $feedback); header('Content-Type: application/javascript; charset=UTF-8', true); //add this for HTTP -> HTTPS requests which assume it's a cross-site request echo EM_Object::json_encode(apply_filters('em_action_' . $_REQUEST['action'], $return, $EM_Booking)); die; } elseif (!$result && defined('DOING_AJAX')) { $return = array('result' => false, 'message' => $feedback, 'errors' => $EM_Notices->get_errors()); header('Content-Type: application/javascript; charset=UTF-8', true); //add this for HTTP -> HTTPS requests which assume it's a cross-site request echo EM_Object::json_encode(apply_filters('em_action_' . $_REQUEST['action'], $return, $EM_Booking)); die; } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'booking_add' && !is_user_logged_in() && !get_option('dbem_bookings_anonymous')) { $EM_Notices->add_error(get_option('dbem_booking_feedback_log_in')); if (!$result && defined('DOING_AJAX')) { $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode(apply_filters('em_action_' . $_REQUEST['action'], $return, $EM_Booking)); } die; } //AJAX call for searches if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 6) == 'search') { //default search arts if ($_REQUEST['action'] == 'search_states') { $results = array(); $conds = array(); if (!empty($_REQUEST['country'])) { $conds[] = $wpdb->prepare("(location_country = '%s' OR location_country IS NULL )", $_REQUEST['country']); } if (!empty($_REQUEST['region'])) { $conds[] = $wpdb->prepare("( location_region = '%s' )", $_REQUEST['region']); } $cond = count($conds) > 0 ? "AND " . implode(' AND ', $conds) : ''; $results = $wpdb->get_col("SELECT DISTINCT location_state FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' {$cond} ORDER BY location_state"); if ($_REQUEST['return_html']) { //quick shortcut for quick html form manipulation ob_start(); ?> <option value=''><?php echo get_option('dbem_search_form_states_label'); ?> </option> <?php foreach ($results as $result) { echo "<option>{$result}</option>"; } $return = ob_get_clean(); echo apply_filters('em_ajax_search_states', $return); exit; } else { echo EM_Object::json_encode($results); exit; } } if ($_REQUEST['action'] == 'search_towns') { $results = array(); $conds = array(); if (!empty($_REQUEST['country'])) { $conds[] = $wpdb->prepare("(location_country = '%s' OR location_country IS NULL )", $_REQUEST['country']); } if (!empty($_REQUEST['region'])) { $conds[] = $wpdb->prepare("( location_region = '%s' )", $_REQUEST['region']); } if (!empty($_REQUEST['state'])) { $conds[] = $wpdb->prepare("(location_state = '%s' )", $_REQUEST['state']); } $cond = count($conds) > 0 ? "AND " . implode(' AND ', $conds) : ''; $results = $wpdb->get_col("SELECT DISTINCT location_town FROM " . EM_LOCATIONS_TABLE . " WHERE location_town IS NOT NULL AND location_town != '' {$cond} ORDER BY location_town"); if ($_REQUEST['return_html']) { //quick shortcut for quick html form manipulation ob_start(); ?> <option value=''><?php echo get_option('dbem_search_form_towns_label'); ?> </option> <?php foreach ($results as $result) { echo "<option>{$result}</option>"; } $return = ob_get_clean(); echo apply_filters('em_ajax_search_towns', $return); exit; } else { echo EM_Object::json_encode($results); exit; } } if ($_REQUEST['action'] == 'search_regions') { $results = array(); if (!empty($_REQUEST['country'])) { $conds[] = $wpdb->prepare("(location_country = '%s' )", $_REQUEST['country']); } $cond = count($conds) > 0 ? "AND " . implode(' AND ', $conds) : ''; $results = $wpdb->get_results("SELECT DISTINCT location_region AS value FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != '' {$cond} ORDER BY location_region"); if ($_REQUEST['return_html']) { //quick shortcut for quick html form manipulation ob_start(); ?> <option value=''><?php echo get_option('dbem_search_form_regions_label'); ?> </option> <?php foreach ($results as $result) { echo "<option>{$result->value}</option>"; } $return = ob_get_clean(); echo apply_filters('em_ajax_search_regions', $return); exit; } else { echo EM_Object::json_encode($results); exit; } } } //EM Ajax requests require this flag. if (is_user_logged_in()) { //Admin operations //Specific Oject Ajax if (!empty($_REQUEST['em_obj'])) { switch ($_REQUEST['em_obj']) { case 'em_bookings_events_table': include_once 'admin/bookings/em-events.php'; em_bookings_events_table(); exit; break; case 'em_bookings_pending_table': include_once 'admin/bookings/em-pending.php'; em_bookings_pending_table(); exit; break; case 'em_bookings_confirmed_table': //add some admin files just in case include_once 'admin/bookings/em-confirmed.php'; em_bookings_confirmed_table(); exit; break; } } } //Export CSV - WIP if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'export_bookings_csv' && wp_verify_nonce($_REQUEST['_wpnonce'], 'export_bookings_csv')) { if (!empty($_REQUEST['event_id'])) { $EM_Event = em_get_event($_REQUEST['event_id']); } //sort out cols if (!empty($_REQUEST['cols']) && is_array($_REQUEST['cols'])) { $cols = array(); foreach ($_REQUEST['cols'] as $col => $active) { if ($active) { $cols[] = $col; } } $_REQUEST['cols'] = $cols; } $_REQUEST['limit'] = 0; //generate bookings export according to search request $show_tickets = !empty($_REQUEST['show_tickets']); $EM_Bookings_Table = new EM_Bookings_Table($show_tickets); header("Content-Type: application/octet-stream; charset=utf-8"); $file_name = !empty($EM_Event->event_slug) ? $EM_Event->event_slug : get_bloginfo(); header("Content-Disposition: Attachment; filename=" . sanitize_title($file_name) . "-bookings-export.csv"); do_action('em_csv_header_output'); echo ""; // UTF-8 for MS Excel (a little hacky... but does the job) if (!defined('EM_CSV_DISABLE_HEADERS') || !EM_CSV_DISABLE_HEADERS) { if (!empty($_REQUEST['event_id'])) { echo __('Event', 'dbem') . ' : ' . $EM_Event->event_name . "\n"; if ($EM_Event->location_id > 0) { echo __('Where', 'dbem') . ' - ' . $EM_Event->get_location()->location_name . "\n"; } echo __('When', 'dbem') . ' : ' . $EM_Event->output('#_EVENTDATES - #_EVENTTIMES') . "\n"; } echo sprintf(__('Exported booking on %s', 'dbem'), date_i18n('D d M Y h:i', current_time('timestamp'))) . "\n"; } echo '"' . implode('","', $EM_Bookings_Table->get_headers(true)) . '"' . "\n"; //Rows $EM_Bookings_Table->limit = 150; //if you're having server memory issues, try messing with this number $EM_Bookings = $EM_Bookings_Table->get_bookings(); $handle = fopen("php://output", "w"); $delimiter = !defined('EM_CSV_DELIMITER') ? ',' : EM_CSV_DELIMITER; while (!empty($EM_Bookings->bookings)) { foreach ($EM_Bookings->bookings as $EM_Booking) { //Display all values /* @var $EM_Booking EM_Booking */ /* @var $EM_Ticket_Booking EM_Ticket_Booking */ if ($show_tickets) { foreach ($EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking) { $row = $EM_Bookings_Table->get_row_csv($EM_Ticket_Booking); fputcsv($handle, $row, $delimiter); } } else { $row = $EM_Bookings_Table->get_row_csv($EM_Booking); fputcsv($handle, $row, $delimiter); } } //reiterate loop $EM_Bookings_Table->offset += $EM_Bookings_Table->limit; $EM_Bookings = $EM_Bookings_Table->get_bookings(); } fclose($handle); exit; } }
public static function untrashed_post($post_id) { if (get_post_type($post_id) == EM_POST_TYPE_LOCATION) { global $EM_Notices; $EM_Location = new EM_Location($post_id, 'post_id'); $EM_Location->set_status($EM_Location->get_status()); $EM_Notices->remove_all(); //no validation/notices needed } }
/** * Performs actions on init. This works for both ajax and normal requests, the return results depends if an em_ajax flag is passed via POST or GET. */ function em_init_actions() { global $wpdb, $EM_Notices, $EM_Event; //NOTE - No EM objects are globalized at this point, as we're hitting early init mode. //TODO Clean this up.... use a uniformed way of calling EM Ajax actions if (!empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action'])) { if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') { if (isset($_REQUEST['id'])) { $EM_Location = new EM_Location($_REQUEST['id']); $location_array = $EM_Location->to_array(); $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format')); echo EM_Object::json_encode($location_array); } die; } if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'delete_ticket') { if (isset($_REQUEST['id'])) { $EM_Ticket = new EM_Ticket($_REQUEST['id']); $result = $EM_Ticket->delete(); if ($result) { $result = array('result' => true); } else { $result = array('result' => false, 'error' => $EM_Ticket->feedback_message); } } else { $result = array('result' => false, 'error' => __('No ticket id provided', 'dbem')); } echo EM_Object::json_encode($result); die; } if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') { $EM_Locations = EM_Locations::get($_REQUEST); $json_locations = array(); foreach ($EM_Locations as $location_key => $EM_Location) { $json_locations[$location_key] = $EM_Location->to_array(); $json_locations[$location_key]['location_balloon'] = $EM_Location->output(get_option('dbem_map_text_format')); } echo EM_Object::json_encode($json_locations); die; } if (isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) { //FIXME if long events enabled originally, this won't show up on ajax call echo EM_Calendar::output($_REQUEST); die; } } //Event Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 5) == 'event') { //Load the event object, with saved event if requested if (!empty($_REQUEST['event_id'])) { $EM_Event = new EM_Event($_REQUEST['event_id']); } else { $EM_Event = new EM_Event(); } if ($_REQUEST['action'] == 'event_save' && current_user_can('edit_events')) { //Check Nonces if (is_admin()) { if (!wp_verify_nonce($_REQUEST['_wpnonce'] && 'event_save')) { check_admin_referer('trigger_error'); } } else { if (!wp_verify_nonce($_REQUEST['_wpnonce'] && 'event_save')) { exit('Trying to perform an illegal action.'); } } //Grab and validate submitted data if ($EM_Event->get_post() && $EM_Event->save()) { //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS) $EM_Notices->add_confirm($EM_Event->feedback_message); if (is_admin()) { $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : ''; $scope = !empty($_REQUEST['scope']) ? $_REQUEST['scope'] : ''; //wp_redirect( get_bloginfo('wpurl').'/wp-admin/admin.php?page=events-manager&pno='.$page.'&scope='.$scope.'&message='.urlencode($EM_Event->feedback_message)); } else { $redirect = !empty($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : wp_get_referer(); wp_redirect($redirect); } $events_result = true; } else { $EM_Notices->add_error($EM_Event->get_errors()); $events_result = false; } } if ($_REQUEST['action'] == 'event_duplicate') { global $EZSQL_ERROR; $EM_Event = $EM_Event->duplicate(); if ($EM_Event === false) { $EM_Notices->add_error($EM_Event->errors, true); } else { if ($EM_Event->id == $_REQUEST['event_id']) { $EM_Notices->add_confirm($EM_Event->feedback_message . " " . sprintf(__('You are now viewing the duplicated %s.', 'dbem'), __('event', 'dbem')), true); } else { $EM_Notices->add_confirm($EM_Event->feedback_message, true); } } } if ($_REQUEST['action'] == 'event_delete') { //DELETE action $selectedEvents = !empty($_REQUEST['events']) ? $_REQUEST['events'] : ''; if (EM_Object::array_is_numeric($selectedEvents)) { $events_result = EM_Events::delete($selectedEvents); } elseif (is_object($EM_Event)) { $events_result = $EM_Event->delete(); } $plural = count($selectedEvents) > 1 ? __('Events', 'dbem') : __('Event', 'dbem'); if ($events_result) { $message = is_object($EM_Event) ? $EM_Event->feedback_message : sprintf(__('%s successfully deleted.', 'dbem'), $plural); $EM_Notices->add_confirm($message); } else { $message = is_object($EM_Event) ? $EM_Event->errors : sprintf(__('%s could not be deleted.', 'dbem'), $plural); $EM_Notices->add_confirm($message); } } elseif ($_REQUEST['action'] == 'event_approve') { //Approve Action $events_result = $EM_Event->approve(); if ($events_result) { $EM_Notices->add_confirm($EM_Event->feedback_message); } else { $EM_Notices->add_error($EM_Event->errors); } } //AJAX Exit if (isset($events_result) && !empty($_REQUEST['em_ajax'])) { if ($events_result) { $return = array('result' => true, 'message' => $EM_Event->feedback_message); } else { $return = array('result' => false, 'message' => $EM_Event->feedback_message, 'errors' => $EM_Event->errors); } } } //Location Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 8) == 'location') { global $EM_Location, $EM_Notices; //Load the location object, with saved event if requested if (!empty($_REQUEST['location_id'])) { $EM_Location = new EM_Location($_REQUEST['location_id']); } else { $EM_Location = new EM_Location(); } if ($_REQUEST['action'] == 'location_save' && current_user_can('edit_locations')) { //Check Nonces em_verify_nonce('location_save'); //Grab and validate submitted data if ($EM_Location->get_post() && $EM_Location->save()) { //EM_location gets the location if submitted via POST and validates it (safer than to depend on JS) $EM_Notices->add_confirm($EM_Location->feedback_message); $result = true; } else { $EM_Notices->add_error($EM_Location->get_errors()); $result = false; } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "location_delete") { //delete location //get object or objects if (!empty($_REQUEST['locations']) || !empty($_REQUEST['location_id'])) { $args = !empty($_REQUEST['locations']) ? $_REQUEST['locations'] : $_REQUEST['location_id']; $locations = EM_Locations::get($args); foreach ($locations as $location) { if (!$location->delete()) { $EM_Notices->add_error($location->get_errors()); $errors = true; } } if (empty($errors)) { $result = true; $location_term = count($locations) > 1 ? __('Locations', 'dbem') : __('Location', 'dbem'); $EM_Notices->add_confirm(sprintf(__('%s successfully deleted', 'dbem'), $location_term)); } else { $result = false; } } } if (isset($result) && $result && !empty($_REQUEST['em_ajax'])) { $return = array('result' => true, 'message' => $EM_Location->feedback_message); echo EM_Object::json_encode($return); die; } elseif (isset($result) && !$result && !empty($_REQUEST['em_ajax'])) { $return = array('result' => false, 'message' => $EM_Location->feedback_message, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode($return); die; } } //Category Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 8) == 'category') { global $EM_Category, $EM_Notices; //Load the category object, with saved event if requested if (!empty($_REQUEST['category_id'])) { $EM_Category = new EM_Category($_REQUEST['category_id']); } else { $EM_Category = new EM_Category(); } if ($_REQUEST['action'] == 'category_save' && current_user_can('edit_categories')) { //Check Nonces em_verify_nonce('category_save'); //Grab and validate submitted data if ($EM_Category->get_post() && $EM_Category->save()) { //EM_Category gets the category if submitted via POST and validates it (safer than to depend on JS) $EM_Notices->add_confirm($EM_Category->feedback_message); $result = true; } else { $EM_Notices->add_error($EM_Category->get_errors()); $result = false; } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == "category_delete") { //delete category //get object or objects if (!empty($_REQUEST['categories']) || !empty($_REQUEST['category_id'])) { $args = !empty($_REQUEST['categories']) ? $_REQUEST['categories'] : $_REQUEST['category_id']; $categories = EM_Categories::get($args); foreach ($categories as $category) { if (!$category->delete()) { $EM_Notices->add_error($category->get_errors()); $errors = true; } } if (empty($errors)) { $result = true; $category_term = count($categories) > 1 ? __('EM_Categories', 'dbem') : __('Category', 'dbem'); $EM_Notices->add_confirm(sprintf(__('%s successfully deleted', 'dbem'), $category_term)); } else { $result = false; } } } if (isset($result) && $result && !empty($_REQUEST['em_ajax'])) { $return = array('result' => true, 'message' => $EM_Category->feedback_message); echo EM_Object::json_encode($return); die; } elseif (isset($result) && !$result && !empty($_REQUEST['em_ajax'])) { $return = array('result' => false, 'message' => $EM_Category->feedback_message, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode($return); die; } } //Booking Actions if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 7) == 'booking' && (is_user_logged_in() || $_REQUEST['action'] == 'booking_add' && get_option('dbem_bookings_anonymous'))) { global $EM_Event, $EM_Booking, $EM_Person; //Load the event object, with saved event if requested $EM_Event = !empty($_REQUEST['event_id']) ? new EM_Event($_REQUEST['event_id']) : new EM_Event(); //Load the booking object, with saved booking if requested $EM_Booking = !empty($_REQUEST['booking_id']) ? new EM_Booking($_REQUEST['booking_id']) : new EM_Booking(); $allowed_actions = array('bookings_approve' => 'approve', 'bookings_reject' => 'reject', 'bookings_unapprove' => 'unapprove', 'bookings_delete' => 'delete'); $result = false; if ($_REQUEST['action'] == 'booking_add') { //ADD/EDIT Booking em_verify_nonce('booking_add'); do_action('em_booking_add', $EM_Event, $EM_Booking); if ($EM_Booking->get_post()) { //Does this user need to be registered first? $registration = true; //TODO do some ticket validation before registering the user if ($_REQUEST['register_user'] && get_option('dbem_bookings_anonymous')) { //find random username - less options for user, less things go wrong $username_root = explode('@', $_REQUEST['user_email']); $username_rand = $username_root[0] . rand(1, 1000); while (username_exists($username_root[0] . rand(1, 1000))) { $username_rand = $username_root[0] . rand(1, 1000); } $id = em_register_new_user($username_rand, $_REQUEST['user_email'], $_REQUEST['user_name'], $_REQUEST['user_phone']); if (is_numeric($id)) { $EM_Person = new EM_Person($id); $EM_Booking->person_id = $id; $EM_Notices->add_confirm(__('A new user account has been created for you. Please check your email for access details.', 'dbem')); } else { $registration = false; if (is_object($id) && get_class($id) == 'WP_Error') { /* @var $id WP_Error */ if ($id->get_error_code() == 'email_exists') { $EM_Notices->add_error(__('This email already exists in our system, please log in to register to proceed with your booking.', 'dbem')); } else { $EM_Notices->add_error($id->get_error_messages()); } } else { $EM_Notices->add_error(__('There was a problem creating a user account, please contact a website administrator.', 'dbem')); } } } if ($EM_Event->get_bookings()->add($EM_Booking) && $registration) { $result = true; $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message); } else { ob_start(); echo "<pre>"; print_r($id); echo "</pre>"; $EM_Booking->feedback_message = ob_get_clean(); $EM_Notices->add_error($EM_Event->get_bookings()->get_errors()); } } else { $result = false; $EM_Notices->add_error($EM_Booking->get_errors()); } } elseif ($_REQUEST['action'] == 'booking_add_one' && is_object($EM_Event) && is_user_logged_in()) { //ADD/EDIT Booking em_verify_nonce('booking_add_one'); $EM_Booking = new EM_Booking(array('person_id' => get_current_user_id(), 'event_id' => $EM_Event->id)); //new booking //get first ticket in this event and book one place there. $EM_Ticket = $EM_Event->get_bookings()->get_tickets()->get_first(); $EM_Ticket_Booking = new EM_Ticket_Booking(array('ticket_id' => $EM_Ticket->id, 'ticket_booking_spaces' => 1)); $EM_Booking->get_tickets_bookings(); $EM_Booking->tickets_bookings->tickets_bookings[] = $EM_Ticket_Booking; //Now save booking if ($EM_Event->get_bookings()->add($EM_Booking)) { $EM_Booking = $booking; $result = true; $EM_Notices->add_confirm($EM_Event->get_bookings()->feedback_message); } else { $EM_Notices->add_error($EM_Event->get_bookings()->get_errors()); } } elseif ($_REQUEST['action'] == 'booking_cancel') { //Cancel Booking em_verify_nonce('booking_cancel'); if ($EM_Booking->can_manage() || $EM_Booking->person->ID == get_current_user_id()) { if ($EM_Booking->cancel()) { $result = true; if (!defined('DOING_AJAX')) { if ($EM_Booking->person->ID == get_current_user_id()) { $EM_Notices->add_confirm(sprintf(__('Booking %s', 'dbem'), __('Cancelled', 'dbem')), true); } else { $EM_Notices->add_confirm($EM_Booking->feedback_message, true); } wp_redirect($_SERVER['HTTP_REFERER']); exit; } } else { $EM_Notices->add_error($EM_Booking->get_errors()); } } else { $EM_Notices->add_error(__('You must log in to cancel your booking.', 'dbem')); } } elseif (array_key_exists($_REQUEST['action'], $allowed_actions) && $EM_Event->can_manage('manage_bookings', 'manage_others_bookings')) { //Event Admin only actions $action = $allowed_actions[$_REQUEST['action']]; //Just do it here, since we may be deleting bookings of different events. if (!empty($_REQUEST['bookings']) && EM_Object::array_is_numeric($_REQUEST['bookings'])) { $results = array(); foreach ($_REQUEST['bookings'] as $booking_id) { $EM_Booking = new EM_Booking($booking_id); $result = $EM_Booking->{$action}(); $results[] = $result; if (!in_array(false, $results) && !$result) { $feedback = $EM_Booking->feedback_message; } } $result = !in_array(false, $results); } elseif (is_object($EM_Booking)) { $result = $EM_Booking->{$action}(); $feedback = $EM_Booking->feedback_message; } //FIXME not adhereing to object's feedback or error message, like other bits in this file. //TODO multiple deletion won't work in ajax if (isset($result) && !empty($_REQUEST['em_ajax'])) { if ($result) { echo $feedback; } else { echo '<span style="color:red">' . $feedback . '</span>'; } die; } } if ($result && defined('DOING_AJAX')) { $return = array('result' => true, 'message' => $EM_Booking->feedback_message); echo EM_Object::json_encode($return); die; } elseif (!$result && defined('DOING_AJAX')) { $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode($return); die; } } elseif (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'booking_add' && !is_user_logged_in() && !get_option('dbem_bookings_anonymous')) { $EM_Notices->add_error(__('You must log in before you make a booking.', 'dbem')); if (!$result && defined('DOING_AJAX')) { $return = array('result' => false, 'message' => $EM_Booking->feedback_message, 'errors' => $EM_Notices->get_errors()); echo EM_Object::json_encode($return); } die; } //AJAX call for searches if (!empty($_REQUEST['action']) && substr($_REQUEST['action'], 0, 6) == 'search') { if ($_REQUEST['action'] == 'search_states' && wp_verify_nonce($_REQUEST['_wpnonce'], 'search_states')) { if (!empty($_REQUEST['country'])) { $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' AND location_country=%s", $_REQUEST['country'])); } elseif (!empty($_REQUEST['region'])) { $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_state IS NOT NULL AND location_state != '' AND location_region=%s", $_REQUEST['region'])); } else { $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_state AS value, location_country AS country, CONCAT(location_state, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE, $_REQUEST['country'] . "WHERE location_state IS NOT NULL AND location_state != ''")); } if ($_REQUEST['return_html']) { //quick shortcut for quick html form manipulation ob_start(); ?> <option value=''><?php _e('All States', 'dbem'); ?> </option> <?php foreach ($results as $result) { echo "<option>{$result->value}</option>"; } $return = ob_get_clean(); echo apply_filters('em_ajax_search_states', $return); exit; } else { echo EM_Object::json_encode($results); exit; } } if ($_REQUEST['action'] == 'search_regions' && wp_verify_nonce($_REQUEST['_wpnonce'], 'search_regions')) { if (!empty($_REQUEST['country'])) { $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_region AS value, location_country AS country, CONCAT(location_region, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != '' AND location_country=%s", $_REQUEST['country'])); } else { $results = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT location_region AS value, location_country AS country, CONCAT(location_region, ', ', location_country) AS label FROM " . EM_LOCATIONS_TABLE . " WHERE location_region IS NOT NULL AND location_region != ''", $_REQUEST['country'])); } if ($_REQUEST['return_html']) { //quick shortcut for quick html form manipulation ob_start(); ?> <option value=''><?php _e('All Regions', 'dbem'); ?> </option> <?php foreach ($results as $result) { echo "<option>{$result->value}</option>"; } $return = ob_get_clean(); echo apply_filters('em_ajax_search_regions', $return); exit; } else { echo EM_Object::json_encode($results); exit; } } elseif ($_REQUEST['action'] == 'search_events' && wp_verify_nonce($_POST['_wpnonce'], 'search_events') && get_option('dbem_events_page_search')) { $args = EM_Events::get_post_search(); ob_start(); em_locate_template('templates/events-list.php', true, array('args' => $args)); //if successful, this template overrides the settings and defaults, including search echo apply_filters('em_ajax_search_events', ob_get_clean(), $args); exit; } } //EM Ajax requests require this flag. if (is_admin() && is_user_logged_in()) { //Admin operations //Specific Oject Ajax if (!empty($_REQUEST['em_obj'])) { switch ($_REQUEST['em_obj']) { case 'em_bookings_events_table': case 'em_bookings_pending_table': case 'em_bookings_confirmed_table': call_user_func($_REQUEST['em_obj']); break; } die; } } }
public static function create_event_from_feed(array $FEED_ = NULL, $event_id = NULL) { global $ESS_Notices, $current_site; $EM_Event = NULL; if ($FEED_ != NULL) { //dd( $FEED_ ); $EM_Event = new EM_Event(intval($event_id) > 0 ? $event_id : 0); // set eventID for update // -- Populate $_POST global var for EM functions if (ESS_Import::set_post_from_feed($FEED_)) { //dd($_POST); if ($EM_Event->can_manage('edit_events', 'edit_recurring_events', 'edit_others_events') && $EM_Event->get_post()) { // -- temporarily remove the save listener to prevent multi-pushing to search engines ESS_IO::set_save_filter(FALSE); $EM_Location = NULL; $EM_Categories = NULL; $EM_Tickets = NULL; $blog_id = isset($current_site) ? $current_site->blog_id : NULL; // used as global by some functions (Cf: EM_location::save()) if (empty($event_id)) { $EM_Event->force_status = intval(get_option('ess_syndication_status')) >= 1 ? ESS_Database::EVENT_STATUS_PUBLISH : ESS_Database::EVENT_STATUS_DRAFT; $EM_Event->event_status = 1; $EM_Event->previous_status = 1; } else { $EM_Event->event_id = $event_id; // -- Remove old images in case of event's update if (get_option('ess_feed_import_images') && intval($EM_Event->post_id) > 0) { ESS_Images::delete($EM_Event->post_id); } } $EM_Event->post_status = strtolower($_POST['event_access']) == 'private' ? 'private' : ESS_Database::EVENT_STATUS_PUBLISH; // == GENERAL if (strlen($_POST['content']) > 0) { if (get_option('ess_backlink_enabled')) { $feed_uri = $FEED_['generals']['uri']; $feed_uri_host = parse_url($feed_uri, PHP_URL_HOST); $_POST['content'] .= "<h6>" . __("Source:", 'dbem') . " <a title=\"" . __("Source:", 'dbem') . " " . $feed_uri_host . "\" href=\"" . $feed_uri . "\">" . parse_url($feed_uri, PHP_URL_HOST) . "</a></h6>"; } } // == PLACE / LOCATION //dd( $_POST['location_name'] ); if ($_POST['no_location'] === FALSE && strlen($_POST['location_name']) > 0 && get_option('dbem_locations_enabled')) { $EM_Location = new EM_Location(); if ($EM_Location->can_manage('publish_locations') && $EM_Location->get_post(FALSE)) { //d( $EM_Location ); // -- Search if this location already exists in the database $similar_ = ESS_Import::load_similar_location(array('location_name' => $EM_Location->location_name, 'location_address' => $EM_Location->location_address, 'location_town' => $EM_Location->location_town, 'location_state' => $EM_Location->location_state, 'location_postcode' => $EM_Location->location_postcode, 'location_country' => $EM_Location->location_country)); //dd( $similar_ ); // if the location already exists use it instead. if (@count($similar_) > 0 && $similar_ != NULL) { foreach ($similar_ as $key => $val) { $EM_Location->{$key} = $val; } } else { $EM_Location->post_status = 'publish'; $EM_Location->location_status = 1; $EM_Location->post_content = ''; } // -- Search & defines latitude / longitude if not set if (FeedValidator::isValidLatitude((string) $_POST['location_latitude']) == FALSE || FeedValidator::isValidLongitude((string) $_POST['location_longitude']) == FALSE) { require_once EM_ESS_DIR . "/inc/libs/geocoder/GoogleGeocode.php"; $geocode_ = GoogleGeocode::getGeocodeFromAddress(trim($EM_Location->location_address . " " . $EM_Location->location_town . " " . $EM_Location->location_postcode . " " . $EM_Location->location_country)); $lat = (string) $geocode_['results'][0]['geometry']['location']['lat']; $lng = (string) $geocode_['results'][0]['geometry']['location']['lng']; //echo "latitude: " . $lat . " ==> ".((FeedValidator::isValidLatitude( $lat ))?'TRUE':'FALSE')."<br/>"; //echo "longitude: " . $lng . " ==> ".((FeedValidator::isValidLongitude( $lng ))?'TRUE':'FALSE')."<br/>"; if (FeedValidator::isValidLatitude($lat) && FeedValidator::isValidLongitude($lng)) { $EM_Location->location_latitude = $lat; $EM_Location->location_longitude = $lng; } } if ($EM_Location->save() === FALSE) { $ESS_Notices->add_error($EM_Location->get_errors()); } $EM_Event->location_id = $EM_Location->location_id; } else { $ESS_Notices->add_error($EM_Location->get_errors()); } } // end add location //dd( $EM_Location ); // == PRICE / TICKETS //dd( $_POST['em_tickets'] ); if (@count($_POST['em_tickets']) > 0 && get_option('dbem_rsvp_enabled')) { $EM_Tickets = new EM_Tickets($EM_Event); $ticket_data = NULL; // Create tickets only if they doesn't exists if (@count($EM_Tickets->tickets) <= 0) { foreach ($_POST['em_tickets'] as $ticket_data) { $EM_Ticket = new EM_Ticket(); $EM_Ticket->get_post($ticket_data); $EM_Tickets->tickets[] = $EM_Ticket; } } if ($ticket_data != NULL) { $EM_Event->event_rsvp = TRUE; $EM_Event->event_rsvp_date = $ticket_data['event_rsvp_date']; $EM_Event->event_rsvp_time = $ticket_data['event_rsvp_time']; $EM_Event->event_spaces = $ticket_data['event_spaces']; $EM_Event->rsvp_time = $ticket_data['event_rsvp_time']; } } // end add tickets //dd( $EM_Tickets ); // == CATEGORIES //dd( $_POST['event_categories'] ); if (@count($_POST['event_categories']) > 0 && get_option('dbem_categories_enabled')) { $EM_Categories = new EM_Categories(); if ($EM_Categories->can_manage('edit_event_categories')) { $caregory_ids_ = array(); foreach ($_POST['event_categories'] as $category_name) { $category_term = get_term_by('name', $category_name, EM_TAXONOMY_CATEGORY); // DEBUG: 2014-01-30 // Fix a internationalization bug report: http://wordpress.org/support/topic/finding-event-category-by-slug-is-not-always-a-good-idea //$category_slug = sanitize_title_with_dashes( $category_name ); //$category_term = get_term_by( 'slug', $category_slug, EM_TAXONOMY_CATEGORY ); if ($category_term === FALSE) { // Term (with category taxonomy) not created yet, let's create it //$term_array = wp_insert_term( $category_name, EM_TAXONOMY_CATEGORY, array( 'slug' => $category_slug ) ); $term_array = wp_insert_term($category_name, EM_TAXONOMY_CATEGORY, array('name' => $category_name)); if (intval($term_array['term_id']) > 0) { array_push($caregory_ids_, intval($term_array['term_id'])); } } else { if (intval($category_term->term_id) > 0) { array_push($caregory_ids_, intval($category_term->term_id)); } } } $_POST['event_categories'] = $caregory_ids_; if ($EM_Categories->get_post() === FALSE) { $ESS_Notices->add_error($EM_Categories->get_errors()); } } else { $ESS_Notices->add_error($EM_Categories->get_errors()); } } // end add categories $EM_Event->categories = $EM_Categories; //dd( $EM_Categories ); // == TAGS //dd( $_POST['event_tags'] ); if (@count($_POST['event_tags']) > 0 && get_option('dbem_tags_enabled')) { $EM_Tags = new EM_Tags(); $tag_ids_ = array(); foreach ($_POST['event_tags'] as $tag_name) { $tag_slug = sanitize_title_with_dashes($tag_name); $tag_term = get_term_by('slug', $tag_slug, EM_TAXONOMY_TAG); if ($tag_term === FALSE) { // -- Term (with tag taxonomy) not created yet, let's create it $term_array = wp_insert_term($tag_name, EM_TAXONOMY_TAG, array('slug' => $tag_slug)); if (intval($term_array['term_id']) > 0) { array_push($tag_ids_, intval($term_array['term_id'])); } } else { if (intval($tag_term->term_id) > 0) { array_push($tag_ids_, intval($tag_term->term_id)); } } } $_POST['event_tags'] = $tag_ids_; if ($EM_Tags->get_post() === FALSE) { $ESS_Notices->add_error($EM_Categories->get_errors()); } } // end add tags //dd( $EM_Tags ); // == DATE (force date values) if (strlen($_POST['event_start_date']) > 0) { $EM_Event->event_start_date = $_POST['event_start_date']; $EM_Event->start_date = $_POST['event_start_date']; $EM_Event->event_start_time = $_POST['event_start_time']; $EM_Event->start_time = $_POST['event_start_time']; $EM_Event->event_end_date = $_POST['event_end_date']; $EM_Event->end_date = $_POST['event_end_date']; $EM_Event->event_end_time = $_POST['event_end_time']; $EM_Event->end_time = $_POST['event_end_time']; $EM_Event->start = strtotime($EM_Event->event_start_date . " " . $EM_Event->event_start_time); $EM_Event->end = strtotime($EM_Event->event_end_date . " " . $EM_Event->event_end_time); if ($EM_Event->end < date('U')) { $ESS_Notices->add_info(__("An event imported is already finished: " . ESS_Elements::get_ahref($FEED_['generals']['uri']), 'dbem')); } } // end add date // == PEOPLE $EM_Event->post_excerpt = strlen($_POST['event_excerpt']) > 0 ? $_POST['event_excerpt'] : ''; // -- update the information already set line 187 //dd( get_option( 'ess_syndication_status' ) ); $EM_Event->force_status = intval(get_option('ess_syndication_status')) >= 1 ? ESS_Database::EVENT_STATUS_PUBLISH : ESS_Database::EVENT_STATUS_DRAFT; //dd( $EM_Event ); // == SAVE EVENT ====== $res = $EM_Event->save(); //dd( $res ); // return FALSE if two of some functions are not updated in EM_Events() //echo "event post id: ". $EM_Event->post_id ."<br/>"; //echo "event event id: ". $EM_Event->event_id."<br/>"; if (intval($EM_Event->post_id) > 0) { // == MEDIA ========== if (@count($_POST['event_media'])) { //var_dump( $_POST['event_media'] ); $media_attachement_ = array(); foreach ($_POST['event_media'] as $media_) { if (ESS_IO::is_file_exists($media_['uri'])) { // Use the same 'manage' value to control the importation of 'images', 'sounds' or 'videos'. if ($EM_Event->can_manage('upload_event_images')) { // == IMAGES if (FeedValidator::getMediaType($media_['uri']) == 'image' && get_option('ess_feed_import_images')) { $attachment_id = ESS_Images::add(array('uri' => $media_['uri'], 'name' => $media_['name'], 'post_id' => $EM_Event->post_id)); if ($attachment_id !== FALSE && intval($attachment_id) > 0) { array_push($media_attachement_, array('attachement_id' => $attachment_id, 'uri' => $media_['uri'])); } else { $ESS_Notices->add_error(__("Impossible to upload the event's image: ", 'dbem') . ESS_Elements::get_ahref($media_['uri'])); } } // end add images // == VIDEOS (TODO...) if (FeedValidator::getMediaType($media_['uri']) == 'video' && get_option('ess_feed_import_videos')) { if (ESS_Videos::add(array('uri' => $media_['uri'], 'name' => $media_['name'], 'post_id' => $EM_Event->post_id)) === FALSE) { $ESS_Notices->add_error(__("Impossible to upload the event's video: ", 'dbem') . ESS_Elements::get_ahref($media_['uri'])); } } // end add videos // == SOUNDS (TODO...) if (FeedValidator::getMediaType($media_['uri']) == 'sound' && get_option('ess_feed_import_sounds')) { if (ESS_Sounds::add(array('uri' => $media_['uri'], 'name' => $media_['name'], 'post_id' => $EM_Event->post_id)) === FALSE) { $ESS_Notices->add_error(__("Impossible to upload the event's audio file: ", 'dbem') . ESS_Elements::get_ahref($media_['uri'])); } } // end add sounds } else { $ESS_Notices->add_error($EM_Event->get_errors()); } } else { $ESS_Notices->add_info(sprintf(__("A media file defined in the ESS feed is not reachable: <a href='%s' target='_blank'>%s</a>", 'dbem'), $media_['uri'], $media_['uri'])); } } // -- Define image with the highest 'priority' as first attachement $priority_test = 1; foreach ($_POST['event_media'] as $media_) { if (get_option('ess_feed_import_images') == FALSE) { break; } if (@$media_['priority'] == $priority_test) { if (FeedValidator::getMediaType($media_['uri']) == 'image') { foreach ($media_attachement_ as $ma_) { if ($ma_['uri'] == $media_['uri'] && $ma_['attachement_id'] > 0) { ESS_Images::delete($EM_Event->post_id, $ma_['attachement_id']); $err = ESS_Images::add(array('uri' => $media_['uri'], 'name' => $media_['name'], 'post_id' => $EM_Event->post_id)); } } } else { $priority_test++; } } } // -- Display all the media files thumbnail at the bottom of the event's description $imgs_ = ESS_Images::get_thumbnails($EM_Event->post_id); //var_dump( $imgs_ );die; if (@count($imgs_) > 0) { $EM_Event->post_content .= "<br/><hr/>"; foreach ($imgs_ as $img_) { if (FeedValidator::isValidURL($img_['url'])) { $EM_Event->post_content .= "<img src='" . $img_['url'] . "' width='" . $img_['width'] . "' height='" . $img_['height'] . "' style='display:inline;margin:5px;'/>"; } } // -- UPDATE event's description with thumbnail images at the bottom $res = $EM_Event->save(); } } // end add media // == TICKETS ========== if (@count($EM_Tickets->tickets) > 0 && get_option('dbem_rsvp_enabled')) { $EM_Tickets->blog_id = $blog_id; $EM_Tickets->event_id = $EM_Event->event_id; if ($EM_Tickets->save() === FALSE) { $ESS_Notices->add_error($EM_Tickets->get_errors()); } } // end assign event to categories // == CATEGORIES ========== if (@count($EM_Categories->categories) > 0 && get_option('dbem_categories_enabled')) { $EM_Categories->blog_id = $blog_id; $EM_Categories->event_id = $EM_Event->event_id; if ($EM_Categories->save() === FALSE) { $ESS_Notices->add_error($EM_Categories->get_errors()); } } // end assign event to categories // == TAGS ========== if (@count($EM_Tags->tags) > 0 && get_option('dbem_tags_enabled')) { //var_dump( $EM_Tags->tags ); $EM_Tags->blog_id = $blog_id; $EM_Tags->event_id = $EM_Event->event_id; // this function doesn't seem to work... if ($EM_Tags->save() === FALSE) { $ESS_Notices->add_error($EM_Tags->get_errors()); } $tags_ = array(); foreach ($EM_Tags->tags as $EM_Tag) { if (strlen($EM_Tag->slug) > 0) { array_push($tags_, $EM_Tag->slug); } } if (@count($tags_) > 0) { wp_set_object_terms($EM_Event->post_id, $tags_, EM_TAXONOMY_TAG); } } // end assign event to tags // == LOCATION ========== ESS_Database::clear_locations(); //dd( $EM_Event ); ESS_IO::set_save_filter(TRUE); } } else { $ESS_Notices->add_error($EM_Event->get_errors()); } } } return $EM_Event; }
/** * Returns an array of EM_Location objects * @param boolean $eventful * @param boolean $return_objects * @return array */ public static function get($args = array(), $count = false) { global $wpdb; $events_table = EM_EVENTS_TABLE; $locations_table = EM_LOCATIONS_TABLE; $locations = array(); //Quick version, we can accept an array of IDs, which is easy to retrieve if (self::array_is_numeric($args)) { //Array of numbers, assume they are event IDs to retreive //We can just get all the events here and return them $sql = "SELECT * FROM {$locations_table} WHERE location_id=" . implode(" OR location_id=", $args); $results = $wpdb->get_results($sql, ARRAY_A); $events = array(); foreach ($results as $result) { $locations[$result['location_id']] = new EM_Location($result); } return apply_filters('em_locations_get', $locations, $args); //We return all the events matched as an EM_Event array. } elseif (is_numeric($args)) { //return an event in the usual array format return apply_filters('em_locations_get', array(new EM_Location($args)), $args); } elseif (is_array($args) && is_object(current($args)) && get_class(current($args)) == 'EM_Location') { return apply_filters('em_locations_get', $args, $args); } //We assume it's either an empty array or array of search arguments to merge with defaults $args = self::get_default_search($args); $limit = $args['limit'] && is_numeric($args['limit']) ? "LIMIT {$args['limit']}" : ''; $offset = $limit != "" && is_numeric($args['offset']) ? "OFFSET {$args['offset']}" : ''; //Get the default conditions $conditions = self::build_sql_conditions($args); //Put it all together $EM_Location = new EM_Location(0); //Empty class for strict message avoidance $fields = $locations_table . "." . implode(", {$locations_table}.", array_keys($EM_Location->fields)); $where = count($conditions) > 0 ? " WHERE " . implode(" AND ", $conditions) : ''; //Get ordering instructions $EM_Event = new EM_Event(); //blank event for below $accepted_fields = $EM_Location->get_fields(true); $accepted_fields = array_merge($EM_Event->get_fields(true), $accepted_fields); $orderby = self::build_sql_orderby($args, $accepted_fields, get_option('dbem_events_default_order')); //Now, build orderby sql $orderby_sql = count($orderby) > 0 ? 'ORDER BY ' . implode(', ', $orderby) : ''; $fields = $count ? $locations_table . '.location_id' : $locations_table . '.post_id'; if (EM_MS_GLOBAL) { $selectors = $count ? 'COUNT(' . $locations_table . '.location_id)' : $locations_table . '.post_id, ' . $locations_table . '.blog_id'; } else { $selectors = $count ? 'COUNT(' . $locations_table . '.location_id)' : $locations_table . '.post_id'; } //Create the SQL statement and execute $sql = "\r\n\t\t\tSELECT {$selectors} FROM {$locations_table}\r\n\t\t\tLEFT JOIN {$events_table} ON {$locations_table}.location_id={$events_table}.location_id\r\n\t\t\t{$where}\r\n\t\t\tGROUP BY {$locations_table}.location_id\r\n\t\t\t{$orderby_sql}\r\n\t\t\t{$limit} {$offset}\r\n\t\t"; //If we're only counting results, return the number of results if ($count) { return apply_filters('em_locations_get_array', count($wpdb->get_col($sql)), $args); } $results = $wpdb->get_results($sql, ARRAY_A); //If we want results directly in an array, why not have a shortcut here? if ($args['array'] == true) { return apply_filters('em_locations_get_array', $results, $args); } if (EM_MS_GLOBAL) { foreach ($results as $location) { if (empty($location['blog_id'])) { $location['blog_id'] = get_current_site()->blog_id; } $locations[] = em_get_location($location['post_id'], $location['blog_id']); } } else { foreach ($results as $location) { $locations[] = em_get_location($location['post_id'], 'post_id'); } } return apply_filters('em_locations_get', $locations, $args); }
function dbem_replace_locations_placeholders($format, $location, $target = "html") { $EM_Location = new EM_Location($location); return $EM_Location->output($format, $target); }
function em_admin_location($message = "") { global $EM_Location, $EM_Notices; //check that user can access this page if (is_object($EM_Location) && !$EM_Location->can_manage('edit_locations', 'edit_others_locations')) { ?> <div class="wrap"><h2><?php _e('Unauthorized Access', 'dbem'); ?> </h2><p><?php _e('You do not have the rights to manage this location.', 'dbem'); ?> </p></div> <?php return false; } if (empty($EM_Location) || !is_object($EM_Location)) { $title = __('Add location', 'dbem'); $EM_Location = new EM_Location(); } else { $title = __('Edit location', 'dbem'); } $required = "<i>(" . __('required', 'dbem') . ")</i>"; echo $EM_Notices; ?> <form enctype='multipart/form-data' name='editcat' id='location-form' method='post' action='admin.php?page=events-manager-locations' class='validate'> <input type='hidden' name='action' value='location_save' /> <input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('location_save'); ?> ' /> <input type='hidden' name='location_id' value='<?php echo $EM_Location->id; ?> '/> <div class='wrap'> <div id='icon-edit' class='icon32'> <br/> </div> <h2><?php echo $title; ?> </h2> <?php global $EM_Notices; echo $EM_Notices; ?> <div id='ajax-response'></div> <div id="poststuff" class="metabox-holder"> <div id="post-body"> <div id="post-body-content"> <div id="location_name" class="stuffbox"> <h3> <?php _e('Location Name', 'dbem'); ?> </h3> <div class="inside"> <input name='location_name' id='location-name' type='text' value='<?php echo htmlspecialchars($EM_Location->name, ENT_QUOTES); ?> ' size='40' /> <br /> <?php _e('The name of the location', 'dbem'); ?> <?php $slug_link = __('View Slug', 'dbem'); ?> <a href="#" id="location-slug-trigger"><?php echo $slug_link; ?> </a> <script type="text/javascript"> jQuery(document).ready(function($){ $('#location-slug-trigger').click(function(){ if( $(this).text() == '<?php echo $slug_link; ?> '){ $('.location-slug').show(); $(this).text('<?php _e('Hide Slug', 'dbem'); ?> '); }else{ $('.location-slug').hide(); $(this).text('<?php echo $slug_link; ?> '); } }); }); </script> <p class='location-slug' style="display:none"> <?php echo sprintf(__('%s Slug', 'dbem'), __('Location', 'dbem')); ?> : <input type="text" name="location_slug" id="location-slug" value="<?php echo $EM_Location->slug; ?> " /> <br /> <?php _e('The event slug. If the event slug already exists, a random number will be appended to the end.', 'dbem'); ?> </p> </div> </div> <?php if (current_user_can('edit_others_locations')) { ?> <div id="location_owner" class="stuffbox"> <h3> <?php _e('Location Owner', 'dbem'); ?> </h3> <div class="inside"> <?php $location_owner = !empty($EM_Location->id) ? $EM_Location->owner : get_current_user_id(); $user_args = array('name' => 'location_owner', 'show_option_none' => __("Select...", 'dbem'), 'selected' => $location_owner); if (is_super_admin() || is_main_site()) { $user_args['blog_id'] = false; } wp_dropdown_users($user_args); ?> </div> </div> <?php } ?> <div id="location_coordinates" class="stuffbox" style='display: none;'> <h3> <?php _e('Coordinates', 'dbem'); ?> </h3> <div class="inside"> <input id='location-latitude' name='location_latitude' type='text' value='<?php echo $EM_Location->latitude; ?> ' size='15' /> - <input id='location-longitude' name='location_longitude' type='text' value='<?php echo $EM_Location->longitude; ?> ' size='15' /> </div> </div> <div id="location_info" class="stuffbox"> <h3> <?php _e('Location', 'dbem'); ?> </h3> <div class="inside"> <p><?php _e("If you're using the Google Maps, the more detail you provide, the more accurate Google can be at finding your location. If your address isn't being found, please <a='http://maps.google.com'>try it on maps.google.com</a> by adding all the fields below seperated by commas.", 'dbem'); ?> </p> <div id="em-location-data"> <table> <tr> <th><?php _e('Address:', 'dbem'); ?> </th> <td> <input id="location-address" type="text" name="location_address" value="<?php echo htmlspecialchars($EM_Location->address, ENT_QUOTES); ?> " /> <?php echo $required; ?> </td> </tr> <tr> <th><?php _e('City/Town:', 'dbem'); ?> </th> <td> <input id="location-town" type="text" name="location_town" value="<?php echo htmlspecialchars($EM_Location->town, ENT_QUOTES); ?> " /> <?php echo $required; ?> </td> </tr> <tr> <th><?php _e('State/County:', 'dbem'); ?> </th> <td> <input id="location-state" type="text" name="location_state" value="<?php echo htmlspecialchars($EM_Location->state, ENT_QUOTES); ?> " /> </td> </tr> <tr> <th><?php _e('Postcode:', 'dbem'); ?> </th> <td> <input id="location-postcode" type="text" name="location_postcode" value="<?php echo htmlspecialchars($EM_Location->postcode, ENT_QUOTES); ?> " /> </td> </tr> <tr> <th><?php _e('Region:', 'dbem'); ?> </th> <td> <input id="location-region" type="text" name="location_region" value="<?php echo htmlspecialchars($EM_Location->region, ENT_QUOTES); ?> " /> <input id="location-region-wpnonce" type="hidden" value="<?php echo wp_create_nonce('search_regions'); ?> " /> </td> </tr> <tr> <th><?php _e('Country:', 'dbem'); ?> </th> <td> <select id="location-country" name="location_country"> <?php foreach (em_get_countries(__('none selected', 'dbem')) as $country_key => $country_name) { ?> <option value="<?php echo $country_key; ?> " <?php echo $EM_Location->country === $country_key || $EM_Location->country == '' && $EM_Location->id == '' && get_option('dbem_location_default_country') == $country_key ? 'selected="selected"' : ''; ?> ><?php echo $country_name; ?> </option> <?php } ?> </select> <?php echo $required; ?> </td> </tr> </table> <?php if (get_option('dbem_gmap_is_active')) { ?> <div style="width: 400px; height: 300px; float:left;"> <div id='em-map-404' style='width: 400px; height:300px; vertical-align:middle; text-align: center;'> <p><em><?php _e('Location not found', 'dbem'); ?> </em></p> </div> <div id='em-map' style='width: 400px; height: 300px; display: none;'></div> </div> <?php } ?> <br style="clear:both; " /> </div> </div> </div> <div id="location_description" class="postbox"> <h3> <?php _e('Details', 'dbem'); ?> </h3> <div class="inside"> <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?> " class="postarea"> <?php the_editor($EM_Location->description); ?> </div> <br /> <?php _e('Details about the location', 'dbem'); ?> </div> </div> <div id="location_description" class="stuffbox"> <h3> <?php _e('Location image', 'dbem'); ?> </h3> <div class="inside" style="padding:10px;"> <?php if ($EM_Location->get_image_url() != '') { ?> <img src='<?php echo $EM_Location->image_url; ?> ' alt='<?php echo $EM_Location->name; ?> '/> <?php } else { ?> <?php _e('No image uploaded for this location yet', 'dbem'); ?> <?php } ?> <br /><br /> <label for='location_image'><?php _e('Upload/change picture', 'dbem'); ?> </label> <input id='location-image' name='location_image' id='location_image' type='file' size='40' /> </div> </div> <?php do_action('em_admin_location_form_footer'); ?> </div> </div> </div> <p class='submit'><input type='submit' class='button-primary' name='submit' value='<?php _e('Update location', 'dbem'); ?> ' /></p> </div> </form> <?php }
/** * Will output a event in the format passed in $format by replacing placeholders within the format. * @param string $format * @param string $target * @return string */ function output($format, $target = "html") { $event_string = $format; //Time place holder that doesn't show if empty. //TODO add filter here too preg_match_all('/#@?_\\{[^}]+\\}/', $format, $results); foreach ($results[0] as $result) { if (substr($result, 0, 3) == "#@_") { $date = 'end_date'; $offset = 4; } else { $date = 'start_date'; $offset = 3; } if ($date == 'end_date' && $this->event_end_date == $this->event_start_date) { $replace = __(apply_filters('em_event_output_placeholder', '', $this, $result, $target)); } else { $replace = __(apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, strlen($result) - ($offset + 1)), $this->{$date}), $this, $result, $target)); } $event_string = str_replace($result, $replace, $event_string); } //This is for the custom attributes preg_match_all('/#_ATT\\{([^}]+)\\}(\\{([^}]+)\\})?/', $format, $results); foreach ($results[0] as $resultKey => $result) { //Strip string of placeholder and just leave the reference $attRef = substr(substr($result, 0, strpos($result, '}')), 6); $attString = ''; if (is_array($this->event_attributes) && array_key_exists($attRef, $this->event_attributes)) { $attString = $this->event_attributes[$attRef]; } elseif (!empty($results[3][$resultKey])) { //Check to see if we have a second set of braces; $attString = $results[3][$resultKey]; } $attString = apply_filters('em_event_output_placeholder', $attString, $this, $result, $target); $event_string = str_replace($result, $attString, $event_string); } //First let's do some conditional placeholder removals for ($i = 0; $i < get_option('dbem_conditional_recursions', 1); $i++) { //you can add nested recursions by modifying this setting in your wp_options table preg_match_all('/\\{([a-zA-Z0-9_]+)\\}(.+?)\\{\\/\\1\\}/s', $event_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_bookings') { //check if there's a booking, if not, remove this section of code. $show_condition = $this->event_rsvp && get_option('dbem_rsvp_enabled'); } elseif ($condition == 'no_bookings') { //check if there's a booking, if not, remove this section of code. $show_condition = !$this->event_rsvp && get_option('dbem_rsvp_enabled'); } elseif ($condition == 'no_location') { //does this event have a valid location? $show_condition = empty($this->location_id) || !$this->get_location()->location_status; } elseif ($condition == 'has_location') { //does this event have a valid location? $show_condition = !empty($this->location_id) && $this->get_location()->location_status; } elseif ($condition == 'has_image') { //does this event have an image? $show_condition = $this->get_image_url() != ''; } elseif ($condition == 'no_image') { //does this event have an image? $show_condition = $this->get_image_url() == ''; } elseif ($condition == 'has_time') { //are the booking times different and not an all-day event $show_condition = $this->start != $this->end && !$this->event_all_day; } elseif ($condition == 'no_time') { //are the booking times exactly the same and it's not an all-day event. $show_condition = $this->event_start_time == $this->event_end_time && !$this->event_all_day; } elseif ($condition == 'all_day') { //is it an all day event $show_condition = !empty($this->event_all_day); } elseif ($condition == 'logged_in') { //user is logged in $show_condition = is_user_logged_in(); } elseif ($condition == 'not_logged_in') { //not logged in $show_condition = !is_user_logged_in(); } elseif ($condition == 'has_spaces') { //is it an all day event $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() > 0; } elseif ($condition == 'fully_booked') { //is it an all day event $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() <= 0; } elseif ($condition == 'is_long') { //is it an all day event $show_condition = $this->event_start_date != $this->event_end_date; } elseif ($condition == 'not_long') { //is it an all day event $show_condition = $this->event_start_date == $this->event_end_date; } elseif ($condition == 'is_past') { //if event is past $show_condition = $this->start <= current_time('timestamp'); } elseif ($condition == 'is_future') { //if event is upcoming $show_condition = $this->start > current_time('timestamp'); } $show_condition = apply_filters('em_event_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 = ''; } $event_string = str_replace($conditionals[0][$key], apply_filters('em_event_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $event_string); } } } //Now let's check out the placeholders. preg_match_all("/(#@?_?[A-Za-z0-9]+)({([a-zA-Z0-9_,]+)})?/", $format, $placeholders); $replaces = array(); foreach ($placeholders[1] as $key => $result) { $match = true; $replace = ''; $full_result = $placeholders[0][$key]; switch ($result) { //Event Details case '#_EVENTID': $replace = $this->event_id; break; case '#_EVENTPOSTID': $replace = $this->post_id; break; case '#_NAME': //depreciated //depreciated case '#_EVENTNAME': $replace = $this->event_name; break; case '#_NOTES': //depreciated //depreciated case '#_EXCERPT': //depreciated //depreciated case '#_EVENTNOTES': case '#_EVENTEXCERPT': $replace = $this->post_content; if ($result == "#_EXCERPT" || $result == "#_EVENTEXCERPT") { if (!empty($this->post_excerpt)) { $replace = $this->post_excerpt; } else { $matches = explode('<!--more', $this->post_content); $replace = $matches[0]; } } break; case '#_EVENTIMAGEURL': case '#_EVENTIMAGE': if ($this->get_image_url() != '') { if ($result == '#_EVENTIMAGEURL') { $replace = esc_url($this->image_url); } else { if (empty($placeholders[3][$key])) { $replace = "<img src='" . esc_url($this->image_url) . "' alt='" . esc_attr($this->event_name) . "'/>"; } else { $image_size = explode(',', $placeholders[3][$key]); $image_src = $this->image_url; if ($this->array_is_numeric($image_size) && count($image_size) > 1) { global $blog_id; if (is_multisite() && $blog_id > 0) { $imageParts = explode('/blogs.dir/', $image_src); if (isset($imageParts[1])) { $image_src = network_site_url('/wp-content/blogs.dir/' . $blog_id . '/' . $imageParts[1]); } } $replace = "<img src='" . esc_url(em_get_thumbnail_url($image_src, $image_size[0], $image_size[1])) . "' alt='" . esc_attr($this->event_name) . "'/>"; } else { $replace = "<img src='" . esc_url($image_src) . "' alt='" . esc_attr($this->event_name) . "'/>"; } } } } break; //Times & Dates //Times & Dates case '#_24HSTARTTIME': case '#_24HENDTIME': $time = $result == '#_24HSTARTTIME' ? $this->event_start_time : $this->event_end_time; $replace = substr($time, 0, 5); break; case '#_12HSTARTTIME': case '#_12HENDTIME': $time = $result == '#_12HSTARTTIME' ? $this->event_start_time : $this->event_end_time; $replace = date('g:i A', strtotime($time)); break; case '#_EVENTTIMES': //get format of time to show if (!$this->event_all_day) { $time_format = get_option('dbem_time_format') ? get_option('dbem_time_format') : get_option('time_format'); if ($this->event_start_time != $this->event_end_time) { $replace = date_i18n($time_format, $this->start) . get_option('dbem_times_seperator') . date_i18n($time_format, $this->end); } else { $replace = date_i18n($time_format, $this->start); } } else { $replace = get_option('dbem_event_all_day_message'); } break; case '#_EVENTDATES': //get format of time to show $date_format = get_option('dbem_date_format') ? get_option('dbem_date_format') : get_option('date_format'); if ($this->event_start_date != $this->event_end_date) { $replace = date_i18n($date_format, $this->start) . get_option('dbem_dates_seperator') . date_i18n($date_format, $this->end); } else { $replace = date_i18n($date_format, $this->start); } break; //Links //Links case '#_EVENTPAGEURL': //Depreciated //Depreciated case '#_LINKEDNAME': //Depreciated //Depreciated case '#_EVENTURL': //Just the URL //Just the URL case '#_EVENTLINK': //HTML Link $event_link = esc_url($this->get_permalink()); if ($result == '#_LINKEDNAME' || $result == '#_EVENTLINK') { $replace = '<a href="' . $event_link . '" title="' . esc_attr($this->event_name) . '">' . esc_attr($this->event_name) . '</a>'; } else { $replace = $event_link; } break; case '#_EDITEVENTURL': case '#_EDITEVENTLINK': if ($this->can_manage('edit_events', 'edit_others_events')) { $link = esc_url($this->get_edit_url()); if ($result == '#_EDITEVENTLINK') { $replace = '<a href="' . $link . '">' . esc_html(sprintf(__('Edit %s', 'dbem'), __('Event', 'dbem'))) . '</a>'; } else { $replace = $link; } } break; //Bookings //Bookings case '#_ADDBOOKINGFORM': //Depreciated //Depreciated case '#_REMOVEBOOKINGFORM': //Depreciated //Depreciated case '#_BOOKINGFORM': if (get_option('dbem_rsvp_enabled')) { ob_start(); $template = em_locate_template('placeholders/bookingform.php', true, array('EM_Event' => $this)); if (!defined('EM_BOOKING_JS_LOADED')) { //this kicks off the Javascript required by booking forms. This is fired once for all booking forms on a page load and appears at the bottom of the page //your theme must call the wp_footer() function for this to work (as required by many other plugins too) function em_booking_js_footer() { ?> <script type="text/javascript"> jQuery(document).ready( function($){ <?php //we call the segmented JS files and include them here include WP_PLUGIN_DIR . '/events-manager/includes/js/bookingsform.js'; do_action('em_gateway_js'); ?> }); </script> <?php } add_action('wp_footer', 'em_booking_js_footer'); add_action('admin_footer', 'em_booking_js_footer'); define('EM_BOOKING_JS_LOADED', true); } $replace = ob_get_clean(); } break; case '#_BOOKINGBUTTON': if (get_option('dbem_rsvp_enabled')) { ob_start(); $template = em_locate_template('placeholders/bookingbutton.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); } break; case '#_EVENTPRICERANGE': //get the range of prices $min = false; $max = 0; foreach ($this->get_tickets()->tickets as $EM_Ticket) { if ($EM_Ticket->get_price() > $max) { $max = $EM_Ticket->get_price(); } if ($EM_Ticket->get_price() < $min || $min === false) { $min = $EM_Ticket->get_price(); } } if ($min === false) { $min = 0; } if ($min != $max) { $replace = em_get_currency_formatted($min) . ' - ' . em_get_currency_formatted($max); } else { $replace = em_get_currency_formatted($min); } break; case '#_EVENTPRICEMIN': //get the range of prices $min = false; foreach ($this->get_tickets()->tickets as $EM_Ticket) { if ($EM_Ticket->get_price() < $min || $min === false) { $min = $EM_Ticket->get_price(); } } if ($min === false) { $min = 0; } $replace = em_get_currency_formatted($min); break; case '#_EVENTPRICEMAX': //get the range of prices $max = 0; foreach ($this->get_tickets()->tickets as $EM_Ticket) { if ($EM_Ticket->get_price() > $max) { $max = $EM_Ticket->get_price(); } } $replace = em_get_currency_formatted($max); break; case '#_AVAILABLESEATS': //Depreciated //Depreciated case '#_AVAILABLESPACES': if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_available_spaces(); } else { $replace = "0"; } break; case '#_BOOKEDSEATS': //Depreciated //Depreciated case '#_BOOKEDSPACES': //This placeholder is actually a little misleading, as it'll consider reserved (i.e. pending) bookings as 'booked' if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_booked_spaces(); if (get_option('dbem_bookings_approval_reserved')) { $replace += $this->get_bookings()->get_pending_spaces(); } } else { $replace = "0"; } break; case '#_PENDINGSPACES': if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_pending_spaces(); } else { $replace = "0"; } break; case '#_SEATS': //Depreciated //Depreciated case '#_SPACES': $replace = $this->get_spaces(); break; case '#_BOOKINGSURL': case '#_BOOKINGSLINK': if ($this->can_manage('manage_bookings', 'manage_others_bookings')) { $bookings_link = esc_url($this->get_bookings_url()); if ($result == '#_BOOKINGSLINK') { $replace = '<a href="' . $bookings_link . '" title="' . esc_attr($this->event_name) . '">' . esc_html($this->event_name) . '</a>'; } else { $replace = $bookings_link; } } break; //Contact Person //Contact Person case '#_CONTACTNAME': case '#_CONTACTPERSON': //Depreciated (your call, I think name is better) $replace = $this->get_contact()->display_name; break; case '#_CONTACTUSERNAME': $replace = $this->get_contact()->user_login; break; case '#_CONTACTEMAIL': case '#_CONTACTMAIL': //Depreciated $replace = $this->get_contact()->user_email; break; case '#_CONTACTID': $replace = $this->get_contact()->ID; break; case '#_CONTACTPHONE': $replace = $this->get_contact()->phone != '' ? $this->get_contact()->phone : __('N/A', 'dbem'); break; case '#_CONTACTAVATAR': $replace = get_avatar($this->get_contact()->ID, $size = '50'); break; case '#_CONTACTPROFILELINK': case '#_CONTACTPROFILEURL': if (function_exists('bp_core_get_user_domain')) { $replace = bp_core_get_user_domain($this->get_contact()->ID); if ($result == '#_CONTACTPROFILELINK') { $replace = '<a href="' . esc_url($replace) . '">' . __('Profile', 'dbem') . '</a>'; } } break; case '#_CONTACTMETA': if (!empty($placeholders[3][$key])) { $replace = get_user_meta($this->event_owner, $placeholders[3][$key], true); } break; case '#_ATTENDEES': ob_start(); $template = em_locate_template('placeholders/attendees.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_ATTENDEESLIST': ob_start(); $template = em_locate_template('placeholders/attendeeslist.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; //Categories and Tags //Categories and Tags case '#_EVENTCATEGORIESIMAGES': ob_start(); $template = em_locate_template('placeholders/eventcategoriesimages.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_EVENTTAGS': ob_start(); $template = em_locate_template('placeholders/eventtags.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_CATEGORIES': //depreciated //depreciated case '#_EVENTCATEGORIES': ob_start(); $template = em_locate_template('placeholders/categories.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; //Ical Stuff //Ical Stuff case '#_EVENTICALURL': case '#_EVENTICALLINK': $replace = $this->get_ical_url(); if ($result == '#_EVENTICALLINK') { $replace = '<a href="' . esc_url($replace) . '">iCal</a>'; } break; case '#_EVENTGCALURL': case '#_EVENTGCALLINK': //get dates if ($this->event_all_day && $this->event_start_date == $this->event_end_date) { $dateStart = date('Ymd', $this->start - 60 * 60 * get_option('gmt_offset')); $dateEnd = date('Ymd', $this->start + 60 * 60 * 24 - 60 * 60 * get_option('gmt_offset')); } else { $dateStart = date('Ymd\\THis\\Z', $this->start - 60 * 60 * get_option('gmt_offset')); $dateEnd = date('Ymd\\THis\\Z', $this->end - 60 * 60 * get_option('gmt_offset')); } //build url $gcal_url = 'http://www.google.com/calendar/event?action=TEMPLATE&text=event_name&dates=start_date/end_date&details=post_content&location=location_name&trp=false&sprop=event_url&sprop=name:blog_name'; $gcal_url = str_replace('event_name', urlencode($this->event_name), $gcal_url); $gcal_url = str_replace('start_date', urlencode($dateStart), $gcal_url); $gcal_url = str_replace('end_date', urlencode($dateEnd), $gcal_url); $gcal_url = str_replace('location_name', urlencode($this->output('#_LOCATION')), $gcal_url); $gcal_url = str_replace('blog_name', urlencode(get_bloginfo()), $gcal_url); $gcal_url = str_replace('event_url', urlencode($this->get_permalink()), $gcal_url); //calculate URL length so we know how much we can work with to make a description. if (!empty($this->post_excerpt)) { $gcal_url_description = $this->post_excerpt; } else { $matches = explode('<!--more', $this->post_content); $gcal_url_description = wp_kses_data($matches[0]); } $gcal_url_length = strlen($gcal_url) - 9; if (strlen($gcal_url_description) + $gcal_url_length > 1500) { $gcal_url_description = substr($gcal_url_description, 0, 1530 - $gcal_url_length - 3) . '...'; } $gcal_url = str_replace('post_content', urlencode($gcal_url_description), $gcal_url); //get the final url $replace = $gcal_url; if ($result == '#_EVENTGCALLINK') { $img_url = 'www.google.com/calendar/images/ext/gc_button2.gif'; $img_url = is_ssl() ? 'https://' . $img_url : 'http://' . $img_url; $replace = '<a href="' . esc_url($replace) . '" target="_blank"><img src="' . esc_url($img_url) . '" alt="0" border="0"></a>'; } break; default: $replace = $full_result; break; } $replaces[$full_result] = apply_filters('em_event_output_placeholder', $replace, $this, $full_result, $target); } //sort out replacements so that during replacements shorter placeholders don't overwrite longer varieties. krsort($replaces); foreach ($replaces as $full_result => $replacement) { $event_string = str_replace($full_result, $replacement, $event_string); } //Time placeholders foreach ($placeholders[1] as $result) { // matches all PHP START date and time placeholders if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#"), $this->start); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } // matches all PHP END time placeholders for endtime if (preg_match('/^#@[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#@"), $this->end); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } } //Now do dependent objects if (!empty($this->location_id) && $this->get_location()->location_status) { $event_string = $this->get_location()->output($event_string, $target); } else { $EM_Location = new EM_Location(); $event_string = $EM_Location->output($event_string, $target); } //for backwards compat and easy use, take over the individual category placeholders with the frirst cat in th elist. $EM_Categories = $this->get_categories(); if (count($EM_Categories->categories) > 0) { $EM_Category = $EM_Categories->get_first(); } if (empty($EM_Category)) { $EM_Category = new EM_Category(); } $event_string = $EM_Category->output($event_string, $target); return apply_filters('em_event_output', $event_string, $this, $format, $target); }
*/ global $EM_Location, $EM_Notices; //check that user can access this page if (is_object($EM_Location) && !$EM_Location->can_manage('edit_locations', 'edit_others_locations')) { ?> <div class="wrap"><h2><?php _e('Unauthorized Access', 'dbem'); ?> </h2><p><?php echo sprintf(__('You do not have the rights to manage this %s.', 'dbem'), __('location', 'dbem')); ?> </p></div> <?php return false; } elseif (!is_object($EM_Location)) { $EM_Location = new EM_Location(); } $required = "<i>(" . __('required', 'dbem') . ")</i>"; echo $EM_Notices; ?> <form enctype='multipart/form-data' id='location-form' method='post' action=''> <input type='hidden' name='action' value='location_save' /> <input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('location_save'); ?> ' /> <input type='hidden' name='location_id' value='<?php echo $EM_Location->location_id; ?> '/>
*/ global $EM_Location, $EM_Notices; //check that user can access this page if (is_object($EM_Location) && !$EM_Location->can_manage('edit_locations', 'edit_others_locations')) { ?> <div class="wrap"><h2><?php esc_html_e('Unauthorized Access', 'dbem'); ?> </h2><p><?php echo sprintf(__('You do not have the rights to manage this %s.', 'dbem'), __('location', 'dbem')); ?> </p></div> <?php return false; } elseif (!is_object($EM_Location)) { $EM_Location = new EM_Location(); } if (!is_admin()) { echo $EM_Notices; } ?> <form enctype='multipart/form-data' id='location-form' method='post' action='<?php echo esc_url(add_query_arg(array('success' => null))); ?> '> <input type='hidden' name='action' value='location_save' /> <input type='hidden' name='_wpnonce' value='<?php echo wp_create_nonce('location_save'); ?> ' /> <input type='hidden' name='location_id' value='<?php
function em_ajax_actions() { //TODO Clean this up.... use a uniformed way of calling EM Ajax actions if (!empty($_REQUEST['em_ajax']) || !empty($_REQUEST['em_ajax_action'])) { if (isset($_REQUEST['dbem_ajax_action']) && $_REQUEST['dbem_ajax_action'] == 'booking_data') { if (isset($_REQUEST['id'])) { $EM_Event = new EM_Event($_REQUEST['id']); echo "[{bookedSeats:" . $EM_Event->get_bookings()->get_booked_seats() . ", availableSeats:" . $EM_Event->get_bookings()->get_available_seats() . "}]"; } die; } if (isset($_REQUEST['em_ajax_action']) && $_REQUEST['em_ajax_action'] == 'get_location') { if (isset($_REQUEST['id'])) { $EM_Location = new EM_Location($_REQUEST['id']); $location_array = $EM_Location->to_array(); $location_array['location_balloon'] = $EM_Location->output(get_option('dbem_location_baloon_format')); echo EM_Object::json_encode($location_array); } die; } if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'GlobalMapData') { $locations = EM_Locations::get($_REQUEST); $json_locations = array(); foreach ($locations as $location_key => $location) { $json_locations[$location_key] = $location->to_array(); $json_locations[$location_key]['location_balloon'] = $location->output(get_option('dbem_map_text_format')); } echo EM_Object::json_encode($json_locations); die; } if (isset($_REQUEST['ajaxCalendar']) && $_REQUEST['ajaxCalendar']) { //FIXME if long events enabled originally, this won't show up on ajax call echo EM_Calendar::output($_REQUEST); die; } //EM Ajax requests require this flag. if (is_admin()) { //Admin operations //Booking Actions global $EM_Booking; if (!empty($_REQUEST['bookings']) || is_object($EM_Booking)) { if (is_object($EM_Booking)) { $_REQUEST['bookings'] = $EM_Booking; //small hack to prevent unecessary db reads } $EM_Bookings = new EM_Bookings(); //Empty, not bound to event. if ($_REQUEST['action'] == 'bookings_approve') { $EM_Bookings->approve($_REQUEST['bookings']); echo $EM_Bookings->feedback_message; die; } elseif ($_REQUEST['action'] == 'bookings_reject') { $EM_Bookings->reject($_REQUEST['bookings']); echo $EM_Bookings->feedback_message; die; } elseif ($_REQUEST['action'] == 'bookings_unapprove') { $EM_Bookings->unapprove($_REQUEST['bookings']); echo $EM_Bookings->feedback_message; die; } elseif ($_REQUEST['action'] == 'bookings_delete') { //Just do it here, since we may be deleting bookings of different events. $result = false; if (EM_Object::array_is_numeric($_REQUEST['bookings'])) { $results = array(); foreach ($_REQUEST['bookings'] as $booking_id) { $EM_Booking = new EM_Booking($booking_id); $results[] = $EM_Booking->delete(); } $result = !in_array(false, $results); } elseif (is_numeric($_REQUEST['bookings'])) { $EM_Booking = new EM_Booking($_REQUEST['bookings']); $result = $EM_Booking->delete(); } elseif (is_object($EM_Booking)) { $result = $EM_Booking->delete(); } if ($result) { echo __('Booking Deleted', 'dbem'); } else { echo '<span style="color:red">' . __('Booking deletion unsuccessful', 'dbem') . '</span>'; } die; } } //Specific Oject Ajax if (!empty($_REQUEST['em_obj'])) { switch ($_REQUEST['em_obj']) { case 'em_bookings_events_table': case 'em_bookings_pending_table': case 'em_bookings_confirmed_table': call_user_func($_REQUEST['em_obj']); break; } die; } } } }
/** * Will output a event in the format passed in $format by replacing placeholders within the format. * @param string $format * @param string $target * @return string */ function output($format, $target = "html") { $event_string = $format; //Time place holder that doesn't show if empty. //TODO add filter here too preg_match_all('/#@?_\\{[^}]+\\}/', $format, $results); foreach ($results[0] as $result) { if (substr($result, 0, 3) == "#@_") { $date = 'end_date'; $offset = 4; } else { $date = 'start_date'; $offset = 3; } if ($date == 'end_date' && $this->event_end_date == $this->event_start_date) { $replace = __(apply_filters('em_event_output_placeholder', '', $this, $result, $target)); } else { $replace = __(apply_filters('em_event_output_placeholder', mysql2date(substr($result, $offset, strlen($result) - ($offset + 1)), $this->{$date}), $this, $result, $target)); } $event_string = str_replace($result, $replace, $event_string); } //This is for the custom attributes preg_match_all('/#_ATT\\{([^}]+)\\}(\\{([^}]+)\\})?/', $event_string, $results); $attributes = em_get_attributes(); foreach ($results[0] as $resultKey => $result) { //Strip string of placeholder and just leave the reference $attRef = substr(substr($result, 0, strpos($result, '}')), 6); $attString = ''; if (is_array($this->event_attributes) && array_key_exists($attRef, $this->event_attributes)) { $attString = $this->event_attributes[$attRef]; } elseif (!empty($results[3][$resultKey])) { //Check to see if we have a second set of braces; $attString = $results[3][$resultKey]; } elseif (!empty($attributes['values'][$attRef][0])) { $attString = $attributes['values'][$attRef][0]; } $attString = apply_filters('em_event_output_placeholder', $attString, $this, $result, $target); $event_string = str_replace($result, $attString, $event_string); } //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', $event_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_bookings') { //check if there's a booking, if not, remove this section of code. $show_condition = $this->event_rsvp && get_option('dbem_rsvp_enabled'); } elseif ($condition == 'no_bookings') { //check if there's a booking, if not, remove this section of code. $show_condition = !$this->event_rsvp && get_option('dbem_rsvp_enabled'); } elseif ($condition == 'no_location') { //does this event have a valid location? $show_condition = empty($this->location_id) || !$this->get_location()->location_status; } elseif ($condition == 'has_location') { //does this event have a valid location? $show_condition = !empty($this->location_id) && $this->get_location()->location_status; } elseif ($condition == 'has_image') { //does this event have an image? $show_condition = $this->get_image_url() != ''; } elseif ($condition == 'no_image') { //does this event have an image? $show_condition = $this->get_image_url() == ''; } elseif ($condition == 'has_time') { //are the booking times different and not an all-day event $show_condition = $this->event_start_time != $this->event_end_time && !$this->event_all_day; } elseif ($condition == 'no_time') { //are the booking times exactly the same and it's not an all-day event. $show_condition = $this->event_start_time == $this->event_end_time && !$this->event_all_day; } elseif ($condition == 'all_day') { //is it an all day event $show_condition = !empty($this->event_all_day); } elseif ($condition == 'logged_in') { //user is logged in $show_condition = is_user_logged_in(); } elseif ($condition == 'not_logged_in') { //not logged in $show_condition = !is_user_logged_in(); } elseif ($condition == 'has_spaces') { //there are still empty spaces $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() > 0; } elseif ($condition == 'fully_booked') { //event is fully booked $show_condition = $this->event_rsvp && $this->get_bookings()->get_available_spaces() <= 0; } elseif ($condition == 'bookings_open') { //bookings are still open $show_condition = $this->event_rsvp && $this->get_bookings()->is_open(); } elseif ($condition == 'bookings_closed') { //bookings are still closed $show_condition = $this->event_rsvp && !$this->get_bookings()->is_open(); } elseif ($condition == 'is_free' || $condition == 'is_free_now') { //is it a free day event, if _now then free right now $show_condition = !$this->event_rsvp || $this->is_free($condition == 'is_free_now'); } elseif ($condition == 'not_free' || $condition == 'not_free_now') { //is it a paid event, if _now then paid right now $show_condition = $this->event_rsvp && !$this->is_free($condition == 'not_free_now'); } elseif ($condition == 'is_long') { //is it an all day event $show_condition = $this->event_start_date != $this->event_end_date; } elseif ($condition == 'not_long') { //is it an all day event $show_condition = $this->event_start_date == $this->event_end_date; } elseif ($condition == 'is_past') { //if event is past if (get_option('dbem_events_current_are_past')) { $show_condition = $this->start <= current_time('timestamp'); } else { $show_condition = $this->end <= current_time('timestamp'); } } elseif ($condition == 'is_future') { //if event is upcoming $show_condition = $this->start > current_time('timestamp'); } elseif ($condition == 'is_current') { //if event is upcoming $ts = current_time('timestamp'); $show_condition = $this->start <= $ts && $this->end >= $ts; } elseif ($condition == 'is_recurrence') { //if event is a recurrence $show_condition = $this->is_recurrence(); } elseif ($condition == 'not_recurrence') { //if event is not a recurrence $show_condition = !$this->is_recurrence(); } elseif ($condition == 'is_private') { //if event is a recurrence $show_condition = $this->event_private == 1; } elseif ($condition == 'not_private') { //if event is not a recurrence $show_condition = $this->event_private == 0; } elseif (preg_match('/^has_category_([a-zA-Z0-9_\\-]+)$/', $condition, $category_match)) { //event is in this category $show_condition = has_term($category_match[1], EM_TAXONOMY_CATEGORY, $this->post_id); } elseif (preg_match('/^no_category_([a-zA-Z0-9_\\-]+)$/', $condition, $category_match)) { //event is NOT in this category $show_condition = !has_term($category_match[1], EM_TAXONOMY_CATEGORY, $this->post_id); } elseif (preg_match('/^has_tag_([a-zA-Z0-9_\\-]+)$/', $condition, $tag_match)) { //event has this tag $show_condition = has_term($tag_match[1], EM_TAXONOMY_TAG, $this->post_id); } elseif (preg_match('/^no_tag_([a-zA-Z0-9_\\-]+)$/', $condition, $tag_match)) { //event doesn't have this tag $show_condition = !has_term($tag_match[1], EM_TAXONOMY_TAG, $this->post_id); } //other potential ones - has_attribute_... no_attribute_... has_categories_... $show_condition = apply_filters('em_event_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 = ''; } $event_string = str_replace($conditionals[0][$key], apply_filters('em_event_output_condition', $replacement, $condition, $conditionals[0][$key], $this), $event_string); } } } //Now let's check out the placeholders. preg_match_all("/(#@?_?[A-Za-z0-9]+)({([^}]+)})?/", $event_string, $placeholders); $replaces = array(); foreach ($placeholders[1] as $key => $result) { $match = true; $replace = ''; $full_result = $placeholders[0][$key]; switch ($result) { //Event Details case '#_EVENTID': $replace = $this->event_id; break; case '#_EVENTPOSTID': $replace = $this->post_id; break; case '#_NAME': //depreciated //depreciated case '#_EVENTNAME': $replace = $this->event_name; break; case '#_NOTES': //depreciated //depreciated case '#_EXCERPT': //depreciated //depreciated case '#_EVENTNOTES': case '#_EVENTEXCERPT': $replace = $this->post_content; if ($result == "#_EXCERPT" || $result == "#_EVENTEXCERPT") { if (!empty($this->post_excerpt)) { $replace = $this->post_excerpt; } else { $excerpt_length = 55; $excerpt_more = apply_filters('em_excerpt_more', ' ' . '[...]'); if (!empty($placeholders[3][$key])) { $trim = true; $ph_args = explode(',', $placeholders[3][$key]); if (is_numeric($ph_args[0])) { $excerpt_length = $ph_args[0]; } if (!empty($ph_args[1])) { $excerpt_more = $ph_args[1]; } } if (preg_match('/<!--more(.*?)?-->/', $replace, $matches)) { $content = explode($matches[0], $replace, 2); $replace = force_balance_tags($content[0]); } if (!empty($trim)) { //shorten content by supplied number - copied from wp_trim_excerpt $replace = strip_shortcodes($replace); $replace = str_replace(']]>', ']]>', $replace); $replace = wp_trim_words($replace, $excerpt_length, $excerpt_more); } } } break; case '#_EVENTIMAGEURL': case '#_EVENTIMAGE': if ($this->get_image_url() != '') { if ($result == '#_EVENTIMAGEURL') { $replace = esc_url($this->image_url); } else { if (empty($placeholders[3][$key])) { $replace = "<img src='" . esc_url($this->image_url) . "' alt='" . esc_attr($this->event_name) . "'/>"; } else { $image_size = explode(',', $placeholders[3][$key]); $image_url = $this->image_url; if (self::array_is_numeric($image_size) && count($image_size) > 1) { //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 = "<img src='" . esc_url(em_add_get_params($image_url, $image_args)) . "' alt='" . esc_attr($this->event_name) . "' {$image_attr} />"; } else { 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); if (!empty($switch_back)) { restore_current_blog(); } } } else { $replace = "<img src='" . esc_url($image_url) . "' alt='" . esc_attr($this->event_name) . "'/>"; } } } } break; //Times & Dates //Times & Dates case '#_24HSTARTTIME': case '#_24HENDTIME': $time = $result == '#_24HSTARTTIME' ? $this->event_start_time : $this->event_end_time; $replace = substr($time, 0, 5); break; case '#_12HSTARTTIME': case '#_12HENDTIME': $time = $result == '#_12HSTARTTIME' ? $this->event_start_time : $this->event_end_time; $replace = date('g:i A', strtotime($time)); break; case '#_EVENTTIMES': //get format of time to show if (!$this->event_all_day) { $time_format = get_option('dbem_time_format') ? get_option('dbem_time_format') : get_option('time_format'); if ($this->event_start_time != $this->event_end_time) { $replace = date_i18n($time_format, $this->start) . get_option('dbem_times_separator') . date_i18n($time_format, $this->end); } else { $replace = date_i18n($time_format, $this->start); } } else { $replace = get_option('dbem_event_all_day_message'); } break; case '#_EVENTDATES': //get format of time to show $date_format = get_option('dbem_date_format') ? get_option('dbem_date_format') : get_option('date_format'); if ($this->event_start_date != $this->event_end_date) { $replace = date_i18n($date_format, $this->start) . get_option('dbem_dates_separator') . date_i18n($date_format, $this->end); } else { $replace = date_i18n($date_format, $this->start); } break; //Links //Links case '#_EVENTPAGEURL': //Depreciated //Depreciated case '#_LINKEDNAME': //Depreciated //Depreciated case '#_EVENTURL': //Just the URL //Just the URL case '#_EVENTLINK': //HTML Link $event_link = esc_url($this->get_permalink()); if ($result == '#_LINKEDNAME' || $result == '#_EVENTLINK') { $replace = '<a href="' . $event_link . '" title="' . esc_attr($this->event_name) . '">' . esc_attr($this->event_name) . '</a>'; } else { $replace = $event_link; } break; case '#_EDITEVENTURL': case '#_EDITEVENTLINK': if ($this->can_manage('edit_events', 'edit_others_events')) { $link = esc_url($this->get_edit_url()); if ($result == '#_EDITEVENTLINK') { $replace = '<a href="' . $link . '">' . esc_html(sprintf(__('Edit Event', 'dbem'))) . '</a>'; } else { $replace = $link; } } break; //Bookings //Bookings case '#_ADDBOOKINGFORM': //Depreciated //Depreciated case '#_REMOVEBOOKINGFORM': //Depreciated //Depreciated case '#_BOOKINGFORM': if (get_option('dbem_rsvp_enabled')) { if (!defined('EM_XSS_BOOKINGFORM_FILTER') && locate_template('plugins/events-manager/placeholders/bookingform.php')) { //xss fix for old overriden booking forms add_filter('em_booking_form_action_url', 'esc_url'); define('EM_XSS_BOOKINGFORM_FILTER', true); } ob_start(); $template = em_locate_template('placeholders/bookingform.php', true, array('EM_Event' => $this)); EM_Bookings::enqueue_js(); $replace = ob_get_clean(); } break; case '#_BOOKINGBUTTON': if (get_option('dbem_rsvp_enabled') && $this->event_rsvp) { ob_start(); $template = em_locate_template('placeholders/bookingbutton.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); } break; case '#_EVENTPRICERANGEALL': $show_all_ticket_prices = true; //continues below //continues below case '#_EVENTPRICERANGE': //get the range of prices $min = false; $max = 0; if ($this->get_bookings()->is_open() || !empty($show_all_ticket_prices)) { foreach ($this->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable') || !empty($show_all_ticket_prices)) { if ($EM_Ticket->get_price() > $max) { $max = $EM_Ticket->get_price(); } if ($EM_Ticket->get_price() < $min || $min === false) { $min = $EM_Ticket->get_price(); } } } } if ($min === false) { $min = 0; } if ($min != $max) { $replace = em_get_currency_formatted($min) . ' - ' . em_get_currency_formatted($max); } else { $replace = em_get_currency_formatted($min); } break; case '#_EVENTPRICEMIN': //get the range of prices $min = false; foreach ($this->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable')) { if ($EM_Ticket->get_price() < $min || $min === false) { $min = $EM_Ticket->get_price(); } } } if ($min === false) { $min = 0; } $replace = em_get_currency_formatted($min); break; case '#_EVENTPRICEMAX': //get the range of prices $max = 0; foreach ($this->get_tickets()->tickets as $EM_Ticket) { /* @var $EM_Ticket EM_Ticket */ if ($EM_Ticket->is_available() || get_option('dbem_bookings_tickets_show_unavailable')) { if ($EM_Ticket->get_price() > $max) { $max = $EM_Ticket->get_price(); } } } $replace = em_get_currency_formatted($max); break; case '#_AVAILABLESEATS': //Depreciated //Depreciated case '#_AVAILABLESPACES': if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_available_spaces(); } else { $replace = "0"; } break; case '#_BOOKEDSEATS': //Depreciated //Depreciated case '#_BOOKEDSPACES': //This placeholder is actually a little misleading, as it'll consider reserved (i.e. pending) bookings as 'booked' if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_booked_spaces(); if (get_option('dbem_bookings_approval_reserved')) { $replace += $this->get_bookings()->get_pending_spaces(); } } else { $replace = "0"; } break; case '#_PENDINGSPACES': if ($this->event_rsvp && get_option('dbem_rsvp_enabled')) { $replace = $this->get_bookings()->get_pending_spaces(); } else { $replace = "0"; } break; case '#_SEATS': //Depreciated //Depreciated case '#_SPACES': $replace = $this->get_spaces(); break; case '#_BOOKINGSURL': case '#_BOOKINGSLINK': if ($this->can_manage('manage_bookings', 'manage_others_bookings')) { $bookings_link = esc_url($this->get_bookings_url()); if ($result == '#_BOOKINGSLINK') { $replace = '<a href="' . $bookings_link . '" title="' . esc_attr($this->event_name) . '">' . esc_html($this->event_name) . '</a>'; } else { $replace = $bookings_link; } } break; case '#_BOOKINGSCUTOFF': case '#_BOOKINGSCUTOFFDATE': case '#_BOOKINGSCUTOFFTIME': $replace = ''; if ($this->event_rsvp && get_option('dbem_rsvp_enabled') && !empty($this->rsvp_end)) { $replace_format = get_option('dbem_date_format') . ' ' . get_option('dbem_time_format'); if ($result == '#_BOOKINGSCUTOFFDATE') { $replace_format = get_option('dbem_date_format'); } if ($result == '#_BOOKINGSCUTOFFTIME') { $replace_format = get_option('dbem_time_format'); } $replace = date($replace_format, $this->rsvp_end); } break; //Contact Person //Contact Person case '#_CONTACTNAME': case '#_CONTACTPERSON': //Depreciated (your call, I think name is better) $replace = $this->get_contact()->display_name; break; case '#_CONTACTUSERNAME': $replace = $this->get_contact()->user_login; break; case '#_CONTACTEMAIL': case '#_CONTACTMAIL': //Depreciated $replace = $this->get_contact()->user_email; break; case '#_CONTACTURL': $replace = $this->get_contact()->user_url; break; case '#_CONTACTID': $replace = $this->get_contact()->ID; break; case '#_CONTACTPHONE': $replace = $this->get_contact()->phone != '' ? $this->get_contact()->phone : __('N/A', 'dbem'); break; case '#_CONTACTAVATAR': $replace = get_avatar($this->get_contact()->ID, $size = '50'); break; case '#_CONTACTPROFILELINK': case '#_CONTACTPROFILEURL': if (function_exists('bp_core_get_user_domain')) { $replace = bp_core_get_user_domain($this->get_contact()->ID); if ($result == '#_CONTACTPROFILELINK') { $replace = '<a href="' . esc_url($replace) . '">' . __('Profile', 'dbem') . '</a>'; } } break; case '#_CONTACTMETA': if (!empty($placeholders[3][$key])) { $replace = get_user_meta($this->event_owner, $placeholders[3][$key], true); } break; case '#_ATTENDEES': ob_start(); $template = em_locate_template('placeholders/attendees.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_ATTENDEESLIST': ob_start(); $template = em_locate_template('placeholders/attendeeslist.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_ATTENDEESPENDINGLIST': ob_start(); $template = em_locate_template('placeholders/attendeespendinglist.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; //Categories and Tags //Categories and Tags case '#_EVENTCATEGORIESIMAGES': ob_start(); $template = em_locate_template('placeholders/eventcategoriesimages.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_EVENTTAGS': ob_start(); $template = em_locate_template('placeholders/eventtags.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; case '#_CATEGORIES': //depreciated //depreciated case '#_EVENTCATEGORIES': ob_start(); $template = em_locate_template('placeholders/categories.php', true, array('EM_Event' => $this)); $replace = ob_get_clean(); break; //Ical Stuff //Ical Stuff case '#_EVENTICALURL': case '#_EVENTICALLINK': $replace = $this->get_ical_url(); if ($result == '#_EVENTICALLINK') { $replace = '<a href="' . esc_url($replace) . '">iCal</a>'; } break; case '#_EVENTGCALURL': case '#_EVENTGCALLINK': //get dates in UTC/GMT time if ($this->event_all_day && $this->event_start_date == $this->event_end_date) { $dateStart = get_gmt_from_date(date('Y-m-d H:i:s', $this->start), 'Ymd'); $dateEnd = get_gmt_from_date(date('Y-m-d H:i:s', $this->start + 60 * 60 * 24), 'Ymd'); } else { $dateStart = get_gmt_from_date(date('Y-m-d H:i:s', $this->start), 'Ymd\\THis\\Z'); $dateEnd = get_gmt_from_date(date('Y-m-d H:i:s', $this->end), 'Ymd\\THis\\Z'); } //build url $gcal_url = 'http://www.google.com/calendar/event?action=TEMPLATE&text=event_name&dates=start_date/end_date&details=post_content&location=location_name&trp=false&sprop=event_url&sprop=name:blog_name'; $gcal_url = str_replace('event_name', urlencode($this->event_name), $gcal_url); $gcal_url = str_replace('start_date', urlencode($dateStart), $gcal_url); $gcal_url = str_replace('end_date', urlencode($dateEnd), $gcal_url); $gcal_url = str_replace('location_name', urlencode($this->output('#_LOCATION')), $gcal_url); $gcal_url = str_replace('blog_name', urlencode(get_bloginfo()), $gcal_url); $gcal_url = str_replace('event_url', urlencode($this->get_permalink()), $gcal_url); //calculate URL length so we know how much we can work with to make a description. if (!empty($this->post_excerpt)) { $gcal_url_description = $this->post_excerpt; } else { $matches = explode('<!--more', $this->post_content); $gcal_url_description = wp_kses_data($matches[0]); } $gcal_url_length = strlen($gcal_url) - 9; if (strlen($gcal_url_description) + $gcal_url_length > 1350) { $gcal_url_description = substr($gcal_url_description, 0, 1380 - $gcal_url_length - 3) . '...'; } $gcal_url = str_replace('post_content', urlencode($gcal_url_description), $gcal_url); //get the final url $replace = $gcal_url; if ($result == '#_EVENTGCALLINK') { $img_url = 'www.google.com/calendar/images/ext/gc_button2.gif'; $img_url = is_ssl() ? 'https://' . $img_url : 'http://' . $img_url; $replace = '<a href="' . esc_url($replace) . '" target="_blank"><img src="' . esc_url($img_url) . '" alt="0" border="0"></a>'; } break; default: $replace = $full_result; break; } $replaces[$full_result] = apply_filters('em_event_output_placeholder', $replace, $this, $full_result, $target); } //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('#_NOTES', '#_EVENTNOTES'))) { $event_string = str_replace($full_result, $replacement, $event_string); } else { $new_placeholder = str_replace('#_', '__#', $full_result); //this will avoid repeated filters when locations/categories are parsed $event_string = str_replace($full_result, $new_placeholder, $event_string); $desc_replace[$new_placeholder] = $replacement; } } //Time placeholders foreach ($placeholders[1] as $result) { // matches all PHP START date and time placeholders if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#"), $this->start); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } // matches all PHP END time placeholders for endtime if (preg_match('/^#@[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $result)) { $replace = date_i18n(ltrim($result, "#@"), $this->end); $replace = apply_filters('em_event_output_placeholder', $replace, $this, $result, $target); $event_string = str_replace($result, $replace, $event_string); } } //Now do dependent objects if (!empty($this->location_id) && $this->get_location()->location_status) { $event_string = $this->get_location()->output($event_string, $target); } else { $EM_Location = new EM_Location(); $event_string = $EM_Location->output($event_string, $target); } //for backwards compat and easy use, take over the individual category placeholders with the frirst cat in th elist. $EM_Categories = $this->get_categories(); if (count($EM_Categories->categories) > 0) { $EM_Category = $EM_Categories->get_first(); } if (empty($EM_Category)) { $EM_Category = new EM_Category(); } $event_string = $EM_Category->output($event_string, $target); //Finally, do the event 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) { $event_string = str_replace($full_result, $replacement, $event_string); } } //do some specific formatting //TODO apply this sort of formatting to any output() function if ($target == 'ical') { //strip html and escape characters $event_string = str_replace('\\', '\\\\', strip_tags($event_string)); $event_string = str_replace(';', '\\;', $event_string); $event_string = str_replace(',', '\\,', $event_string); //remove and define line breaks in ical format $event_string = str_replace('\\\\n', '\\n', $event_string); $event_string = str_replace("\r\n", '\\n', $event_string); $event_string = str_replace("\n", '\\n', $event_string); } return apply_filters('em_event_output', $event_string, $this, $format, $target); }
/** * Filter for titles when on event pages * @param $data * @return string */ function em_content_page_title($content) { global $EM_Event, $EM_Location, $EM_Category, $wp_query, $post; $events_page_id = get_option('dbem_events_page'); if ($post->ID == $events_page_id && $events_page_id != 0) { $content = apply_filters('em_content_page_title_pre', '', $content); if (empty($content)) { if (!empty($_REQUEST['calendar_day'])) { $events = EM_Events::get(array('limit' => 2, 'scope' => $_REQUEST['calendar_day'], 'owner' => false)); if (count($events) != 1 || get_option('dbem_display_calendar_day_single') == 1) { //We only support dates for the calendar day list title, so we do a simple filter for the supplied calendar_day $content = get_option('dbem_list_date_title'); preg_match_all("/#[A-Za-z0-9]+/", $content, $placeholders); foreach ($placeholders[0] as $placeholder) { // matches all PHP date and time placeholders if (preg_match('/^#[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]$/', $placeholder)) { $content = str_replace($placeholder, mysql2date(ltrim($placeholder, "#"), $_REQUEST['calendar_day']), $content); } } } else { $event = array_shift($events); $content = $event->output(get_option('dbem_event_page_title_format')); } } elseif (is_object($EM_Location)) { $location = new EM_Location(EM_Object::sanitize($_REQUEST['location_id'])); $content = $location->output(get_option('dbem_location_page_title_format')); } elseif (is_object($EM_Category)) { //Just a single location $content = $EM_Category->output(get_option('dbem_category_page_title_format')); } elseif ($wp_query->get('bookings_page')) { //Bookings Page $content = sprintf(__('My %s', 'dbem'), __('Bookings', 'dbem')); } elseif (is_object($EM_Event) && !empty($_REQUEST['book'])) { //bookings page $content = $EM_Event->output(get_option('dbem_bookings_page_title')); } elseif (is_object($EM_Event)) { // single event page if ($EM_Event->status == 1) { $content = $EM_Event->output(get_option('dbem_event_page_title_format')); } else { $content = get_option('dbem_events_page_title'); } } elseif (!empty($_REQUEST['event_categories'])) { $content = get_option('dbem_categories_page_title'); } elseif (!empty($_REQUEST['event_locations'])) { $content = get_option('dbem_locations_page_title'); } else { // Multiple events page $content = get_option('dbem_events_page_title'); } } return apply_filters('em_content_page_title', $content); } return $content; }