/** * Shows a list of events according to given specifications. Accepts any event query attribute. * @param array $atts * @return string */ function em_get_event_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['event']) && is_numeric($atts['event'])) { $EM_Event = new EM_Event($atts['event']); return !empty($atts['format']) ? $EM_Event->output($atts['format']) : $EM_Event->output_single(); } }
/** * @param EM_Event $EM_Event * @return string */ function em_event_added_email($EM_Event) { if (!$EM_Event->get_status() && get_option('dbem_bookings_approval') && get_option('dbem_event_submitted_email_admin') != '') { $admin_emails = explode(',', get_option('dbem_event_submitted_email_admin')); //admin emails are in an array, single or multiple $subject = $EM_Event->output(get_option('dbem_event_submitted_email_subject')); $message = $EM_Event->output(get_option('dbem_event_submitted_email_body')); //Send email to admins $EM_Event->email_send($subject, $message, $admin_emails); } }
/** * Returns an array of EM_Events that match the given specs in the argument, or returns a list of future evetnts in future * (see EM_Events::get_default_search() ) for explanation of possible search array values. You can also supply a numeric array * containing the ids of the events you'd like to obtain * * @param array $args * @return EM_Event array() */ function get($args = array(), $count = false) { global $wpdb; $events_table = EM_EVENTS_TABLE; $locations_table = EM_LOCATIONS_TABLE; //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 = "\n\t\t\t\tSELECT * FROM {$events_table}\n\t\t\t\tLEFT JOIN {$locations_table} ON {$locations_table}.location_id={$events_table}.location_id\n\t\t\t\tWHERE event_id=" . implode(" OR event_id=", $args) . "\n\t\t\t"; $results = $wpdb->get_results(apply_filters('em_events_get_sql', $sql), ARRAY_A); $events = array(); foreach ($results as $result) { $events[$result['event_id']] = new EM_Event($result); } return $events; //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 $where = count($conditions) > 0 ? " WHERE " . implode(" AND ", $conditions) : ''; //Get ordering instructions $EM_Event = new EM_Event(); $accepted_fields = $EM_Event->get_fields(true); $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 $selectors = $count ? 'COUNT(*)' : '*'; $sql = "\n\t\t\tSELECT {$selectors} FROM {$events_table}\n\t\t\tLEFT JOIN {$locations_table} ON {$locations_table}.location_id={$events_table}.location_id\n\t\t\t{$where}\n\t\t\t{$orderby_sql}\n\t\t\t{$limit} {$offset}\n\t\t"; //If we're only counting results, return the number of results if ($count) { return $wpdb->get_var($sql); } $results = $wpdb->get_results(apply_filters('em_events_get_sql', $sql, $args), ARRAY_A); //If we want results directly in an array, why not have a shortcut here? if ($args['array'] == true) { return $results; } //Make returned results EM_Event objects $results = is_array($results) ? $results : array(); $events = array(); foreach ($results as $event) { $events[] = new EM_Event($event); } return apply_filters('em_events_get', $events, $args); }
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()); } }
/** * Overrides the default capability of the user for another owner's event if the user is a group admin and the event belongs to a group. * User must have the relevant permissions globally in order to inherit that capability for this event as well. * @param boolean $result * @param EM_Event $EM_Event */ function bp_em_group_event_can_manage($result, $EM_Event, $owner_capability, $admin_capability, $user_to_check) { if (!$result && $EM_Event->event_owner != get_current_user_id() && !empty($EM_Event->group_id) && bp_is_active('groups')) { //only override if already false, incase it's true //if the user is an admin of this group, and actually has the relevant permissions globally, they can manage this event $EM_Object = new EM_Object(); //create new object to prevent infinite loop should we call $EM_Event->can_manage(); if (groups_is_user_admin(get_current_user_id(), $EM_Event->group_id) && $EM_Object->can_manage($owner_capability, $admin_capability, $user_to_check)) { //This user is an admin of the owner's group, so they can edit this event. return true; } else { $EM_Event->add_error($EM_Object->get_errors()); //add any applicable errors } } return $result; }
function ajax_add_booking() { /* Check the nonce */ check_admin_referer('add_booking', '_wpnonce_add_booking'); if (!empty($_REQUEST['event_id']) && is_numeric($_REQUEST['event_id'])) { $EM_Event = new EM_Event($_REQUEST['event_id']); $result = $EM_Event->get_bookings()->add_from_post(); if ($result) { $return = array('result' => true, 'message' => $EM_Event->get_bookings()->feedback_message); } else { $return = array('result' => false, 'message' => implode('<br />', $EM_Event->get_bookings()->errors)); } echo EM_Object::json_encode($return); exit; } else { $return = array('result' => false, 'message' => ''); echo EM_Object::json_encode($return); exit; } }
function em_admin_event_actions() { if (current_user_can(EM_MIN_CAPABILITY) && !empty($_GET['page']) && $_GET['page'] == 'events-manager-event' && !empty($_REQUEST['action'])) { global $wpdb; global $EM_Event; //if dealing with new event, we still want an event object if (!is_object($EM_Event)) { $EM_Event = new EM_Event(); } // UPDATE or CREATE action if ($_REQUEST['action'] == 'save') { $validation = $EM_Event->get_post(); if ($validation) { //EM_Event gets the event if submitted via POST and validates it (safer than to depend on JS) //Save if ($EM_Event->save()) { $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : ''; $scope = !empty($_REQUEST['scope']) ? $_REQUEST['scope'] : ''; wp_redirect(get_bloginfo('wpurl') . '/wp-admin/admin.php?page=events-manager&p=' . $page . '&scope=' . $scope . '&message=' . urlencode($EM_Event->feedback_message)); } } //errors added automatically to event global object } //Copy the event if ($_REQUEST['action'] == 'duplicate') { global $EZSQL_ERROR; $EM_Event = $EM_Event->duplicate(); if ($EM_Event === false) { $redirect_url = em_add_get_params($_SERVER['HTTP_REFERER'], array('error' => __('There was an error duplicating the event. Try again maybe?', 'dbem'), 'message' => ''), false); wp_redirect($redirect_url); } else { $page = !empty($_REQUEST['pno']) ? $_REQUEST['pno'] : ''; $scope = !empty($_REQUEST['scope']) ? $_REQUEST['scope'] : ''; wp_redirect(get_bloginfo('wpurl') . '/wp-admin/admin.php?page=events-manager-event&event_id=' . $EM_Event->id . '&p=' . $page . '&scope=' . $scope . '&message=' . urlencode($EM_Event->feedback_message)); } } } }
function em_admin_email_test_ajax() { if (wp_verify_nonce($_REQUEST['_check_email_nonce'], 'check_email') && current_user_can('activate_plugins')) { $subject = __("Events Manager Test Email", 'dbem'); $content = __('Congratulations! Your email settings work.', 'dbem'); $current_user = get_user_by('id', get_current_user_id()); //add filters for options used in EM_Mailer so the current supplied ones are used ob_start(); function pre_option_dbem_mail_sender_name() { return sanitize_email($_REQUEST['dbem_mail_sender_name']); } add_filter('pre_option_dbem_mail_sender_name', 'pre_option_dbem_mail_sender_name'); function pre_option_dbem_mail_sender_address() { return sanitize_text_field($_REQUEST['dbem_mail_sender_address']); } add_filter('pre_option_dbem_mail_sender_address', 'pre_option_dbem_mail_sender_address'); function pre_option_dbem_rsvp_mail_send_method() { return sanitize_text_field($_REQUEST['dbem_rsvp_mail_send_method']); } add_filter('pre_option_dbem_rsvp_mail_send_method', 'pre_option_dbem_rsvp_mail_send_method'); function pre_option_dbem_rsvp_mail_port() { return sanitize_text_field($_REQUEST['dbem_rsvp_mail_port']); } add_filter('pre_option_dbem_rsvp_mail_port', 'pre_option_dbem_rsvp_mail_port'); function pre_option_dbem_rsvp_mail_SMTPAuth() { return sanitize_text_field($_REQUEST['dbem_rsvp_mail_SMTPAuth']); } add_filter('pre_option_dbem_rsvp_mail_SMTPAuth', 'pre_option_dbem_rsvp_mail_SMTPAuth'); function pre_option_dbem_smtp_host() { return sanitize_text_field($_REQUEST['dbem_smtp_host']); } add_filter('pre_option_dbem_smtp_host', 'pre_option_dbem_smtp_host'); function pre_option_dbem_smtp_username() { return sanitize_text_field($_REQUEST['dbem_smtp_username']); } add_filter('pre_option_dbem_smtp_username', 'pre_option_dbem_smtp_username'); function pre_option_dbem_smtp_password() { return sanitize_text_field($_REQUEST['dbem_smtp_password']); } add_filter('pre_option_dbem_smtp_password', 'pre_option_dbem_smtp_password'); ob_clean(); //remove any php errors/warnings output $EM_Event = new EM_Event(); if ($EM_Event->email_send($subject, $content, $current_user->user_email)) { $result = array('result' => true, 'message' => sprintf(__('Email sent succesfully to %s', 'dbem'), $current_user->user_email)); } else { $result = array('result' => false, 'message' => __('Email not sent.', 'dbem') . " <ul><li>" . implode('</li><li>', $EM_Event->get_errors()) . '</li></ul>'); } echo EM_Object::json_encode($result); } exit; }
/** * 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; } }
/** * Duplicates this event and returns the duplicated event. Will return false if there is a problem with duplication. * @return EM_Event */ function duplicate() { global $wpdb, $EZSQL_ERROR; //First, duplicate. if ($this->can_manage('edit_events', 'edit_others_events')) { $event_table_name = EM_EVENTS_TABLE; $eventArray = $this->to_array(); unset($eventArray['event_id']); $EM_Event = new EM_Event($eventArray); if ($EM_Event->save()) { $EM_Event->feedback_message = sprintf(__("%s successfully duplicated.", 'dbem'), __('Event', 'dbem')); return apply_filters('em_event_duplicate', $EM_Event, $this); } } else { $EM_Event->add_error(sprintf(__('You are not allowed to manage this %s.'), __('event', 'dbem'))); } //TODO add error notifications for duplication failures. return apply_filters('em_event_duplicate', false, $this); }
/** * Called instead of the filter in EM_Gateways if a manual booking is being made * @param EM_Event $EM_Event */ function em_booking_form_footer($EM_Event) { if ($EM_Event->can_manage('manage_bookings', 'manage_others_bookings')) { //Admin is adding a booking here, so let's show a different form here. ?> <input type="hidden" name="gateway" value="<?php echo $this->gateway; ?> " /> <input type="hidden" name="manual_booking" value="<?php echo wp_create_nonce('em_manual_booking_' . $EM_Event->event_id); ?> " /> <p class="em-booking-gateway" id="em-booking-gateway"> <label><?php _e('Amount Paid', 'em-pro'); ?> </label> <input type="text" name="payment_amount" id="em-payment-amount" value="<?php if (!empty($_REQUEST['payment_amount'])) { echo esc_attr($_REQUEST['payment_amount']); } ?> "> <?php _e('Fully Paid', 'em-pro'); ?> <input type="checkbox" name="payment_full" id="em-payment-full" value="1"><br /> <em><?php _e('If you check this as fully paid, and leave the amount paid blank, it will be assumed the full payment has been made.', 'em-pro'); ?> </em> </p> <?php } return; }
/** * Filters for page content and if an event replaces it with the relevant event data. * @param $data * @return string */ function em_content($content) { $events_page_id = get_option('dbem_events_page'); if (get_the_ID() == $events_page_id && $events_page_id != 0) { global $wpdb, $EM_Event; //TODO FILTER - filter em page content before placeholder replacing //TODO any loop should put the current $EM_Event etc. into the global variable //general defaults $args = array('orderby' => get_option('dbem_events_default_orderby'), 'order' => get_option('dbem_events_default_order'), 'owner' => false, 'pagination' => 1); if (!empty($_REQUEST['calendar_day'])) { //Events for a specific day $args['scope'] = $_REQUEST['calendar_day']; $page = !empty($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1; $events = EM_Events::get(apply_filters('em_content_calendar_day_args', $args)); //Get events first, so we know how many there are in advance if (count($events) > 1 || $page > 1 || get_option('dbem_display_calendar_day_single') == 1) { $args['limit'] = get_option('dbem_events_default_limit'); $args['offset'] = $args['limit'] * ($page - 1); $content = EM_Events::output($events, apply_filters('em_content_calendar_day_output_args', $args)); } elseif (count($events) == 1) { $EM_Event = $events[0]; $content = $EM_Event->output_single(); } else { $content = get_option('dbem_no_events_message'); } } elseif (!empty($_REQUEST['location_id']) && is_numeric($_REQUEST['location_id'])) { //Just a single location $location = new EM_Location($_REQUEST['location_id']); $content = $location->output_single(); } elseif (!empty($_REQUEST['event_id']) && is_numeric($_REQUEST['event_id'])) { // single event page $event = new EM_Event($_REQUEST['event_id']); $content = $event->output_single(); } elseif (!empty($_REQUEST['bookings_id'])) { //bookings page } else { // Multiple events page $scope = !empty($_REQUEST['scope']) ? EM_Object::sanitize($_REQUEST['scope']) : "future"; //If we have a $_GET['page'] var, use it to calculate the offset/limit ratios (safer than offset/limit get vars) $args['scope'] = $scope; if (!empty($_REQUEST['category_id'])) { $args['category'] = $_REQUEST['category_id']; } if (get_option('dbem_display_calendar_in_events_page')) { $args['full'] = 1; $args['long_events'] = get_option('dbem_full_calendar_long_events'); $content = EM_Calendar::output(apply_filters('em_content_calendar_args', $args)); } else { $args['limit'] = get_option('dbem_events_default_limit'); $args['page'] = !empty($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1; /*calculate event list time range */ $time_limit = get_option('dbem_events_page_time_limit'); if (is_numeric($time_limit) && $time_limit > 0) { $args['scope'] = date('Y-m-d') . "," . date('Y-m-t', strtotime('+' . ($time_limit - 1) . ' month')); } $content = EM_Events::output(apply_filters('em_content_events_args', $args)); } } //If disable rewrite flag is on, then we need to add a placeholder here if (get_option('dbem_disable_title_rewrites') == 1) { $content = str_replace('#_PAGETITLE', em_events_page_title(''), get_option('dbem_title_html')) . $content; } //TODO FILTER - filter em page content before display return apply_filters('em_content', '<div id="em-wrapper">' . $content . '</div>'); } return $content; }
function em_admin_email_test_ajax() { if (wp_verify_nonce($_REQUEST['_check_email_nonce'], 'check_email') && current_user_can('activate_plugins')) { $subject = __("Events Manager Test Email", 'dbem'); $content = __('Congratulations! Your email settings work.', 'dbem'); $current_user = get_user_by('id', get_current_user_id()); $EM_Event = new EM_Event(); if ($EM_Event->email_send($subject, $content, $current_user->user_email)) { $result = array('result' => true, 'message' => sprintf(__('Email sent succesfully to %s', 'dbem'), $current_user->user_email)); } else { $result = array('result' => false, 'message' => __('Email not sent.', 'dbem') . " <ul><li>" . implode('</li><li>', $EM_Event->get_errors()) . '</li></ul>'); } echo json_encode($result); } exit; }
/** * Publish the location if the event has just been approved and the location is pending. We assume an editor published the event and approves the location too. * @param EM_Event $EM_Event */ function maybe_publish_location($EM_Event) { //do a dirty update for location too if it's not published if ($EM_Event->is_published() && !empty($EM_Event->location_id)) { $EM_Location = $EM_Event->get_location(); if ($EM_Location->location_status !== 1) { //let's also publish the location $EM_Location->set_status(1, true); } } }
/** * 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); }
/** * 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; } } }
/** * Saves a new event index record if this is a new languge addition, for ML plugins that store translations as new posts * @param boolean $result * @param EM_Event $EM_Event */ public static function event_save_meta_pre($EM_Event) { global $wpdb, $post; if (!empty($post) && $EM_Event->post_id != $post->ID) { //different language, make sure we don't have the same event_id as the original language $event = em_get_event($EM_Event->event_id); //gets the true event if ($EM_Event->post_id == $event->post_id) { //we have a dupe, so we need to reset the event id and the post id here $EM_Event->post_id = $post->ID; $EM_Event->event_id = null; update_post_meta($post->ID, '_post_id', $post->ID); update_post_meta($post->ID, '_event_id', ''); $EM_Event->load_postdata($post, 'post_id'); } } }
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; } } } }
global $EM_Event, $EM_Notices, $bp; //check that user can access this page if (is_object($EM_Event) && !$EM_Event->can_manage('edit_events', 'edit_others_events')) { ?> <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'), __('Event', 'dbem')); ?> </p></div> <?php return false; } elseif (!is_object($EM_Event)) { $EM_Event = new EM_Event(); } $required = apply_filters('em_required_html', '<i>*</i>'); echo $EM_Notices; //Success notice if (!empty($_REQUEST['success'])) { if (!get_option('dbem_events_form_reshow')) { return false; } } ?> <form enctype='multipart/form-data' id="event-form" method="post" action="<?php echo add_query_arg(array('success' => null)); ?> ">
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; }
/** * import events from CSV upload * @param string $filepath */ protected function importEventsCSV($filepath) { global $wpdb; $fp = fopen($filepath, 'r'); if ($fp === false) { throw new EM_ImpExpImportException('error opening CSV file'); } // read first line of CSV to make sure it's the correct format -- fgetscsv is fine for this simple task! $header = fgetcsv($fp); if ($header === false) { throw new EM_ImpExpImportException('error reading import file or file is empty'); } if (is_null($header)) { throw new EM_ImpExpImportException('import file handle is null'); } if (!is_array($header)) { throw new EM_ImpExpImportException('import file did not scan as CSV'); } if (!in_array('summary', $header)) { throw new EM_ImpExpImportException('import file does not contain a field "summary"'); } $wpdb->query('start transaction'); $records = 0; $rows = 0; $attrs = array(); $eventCategories = self::getEventCategories(); $eventCountries = self::getEventCountries(); $csv = new parseCSV(); $csv->fields = $header; while ($line = fgets($fp)) { $line = "\n{$line}\n"; // fix up line so that it can be parsed correctly $cols = $csv->parse_string($line); if ($cols) { $rows++; $cols = $cols[0]; // collect standard event properties $data = array('uid' => isset($cols['uid']) ? trim($cols['uid']) : '', 'url' => isset($cols['url']) ? self::safeURL($cols['url']) : '', 'summary' => isset($cols['summary']) ? $cols['summary'] : '', 'dtstart' => isset($cols['dtstart']) ? $cols['dtstart'] : '', 'dtend' => isset($cols['dtend']) ? $cols['dtend'] : '', 'categories' => isset($cols['categories']) ? $cols['categories'] : '', 'freq' => isset($cols['freq']) ? $cols['freq'] : '', 'byday' => isset($cols['byday']) ? $cols['byday'] : '', 'interval' => isset($cols['interval']) ? $cols['interval'] : '', 'until' => isset($cols['until']) ? $cols['until'] : '', 'post_content' => isset($cols['post_content']) ? $cols['post_content'] : '', 'post_excerpt' => isset($cols['post_excerpt']) ? $cols['post_excerpt'] : '', 'event_spaces' => isset($cols['event_spaces']) ? $cols['event_spaces'] : '', 'location_name' => isset($cols['location_name']) ? $cols['location_name'] : '', 'location_address' => isset($cols['location_address']) ? $cols['location_address'] : '', 'location_town' => isset($cols['location_town']) ? $cols['location_town'] : '', 'location_state' => isset($cols['location_state']) ? $cols['location_state'] : '', 'location_postcode' => isset($cols['location_postcode']) ? $cols['location_postcode'] : '', 'location_country' => isset($cols['location_country']) ? $cols['location_country'] : '', 'location_region' => isset($cols['location_region']) ? $cols['location_region'] : '', 'location_latitude' => isset($cols['location_latitude']) ? $cols['location_latitude'] : '', 'location_longitude' => isset($cols['location_longitude']) ? $cols['location_longitude'] : ''); if (isset($eventCountries[strtolower($data['location_country'])])) { $data['location_country'] = $eventCountries[strtolower($data['location_country'])]; } // collect custom event attributes, being columns not found in standard event properties $attrs = array(); foreach ($cols as $key => $value) { if (strlen($value) > 0 && !isset($data[$key])) { $attrs[$key] = $value; } } // if we have location, try to either retrieve it by name, or create a new location object $location = false; if (self::hasLocation($data)) { if ($data['location_name']) { // try to find location by name $location = $this->getLocationByName($data['location_name']); } if (!$location) { // must create a new location object $location = new EM_Location(); $location->location_name = empty($data['location_name']) ? self::fudgeLocationName($data) : $data['location_name']; $location->location_address = empty($data['location_address']) ? $data['location_name'] : $data['location_address']; $location->location_town = $data['location_town']; $location->location_state = $data['location_state']; $location->location_postcode = $data['location_postcode']; $location->location_country = $data['location_country']; $location->location_region = $data['location_region']; $location->location_latitude = $data['location_latitude']; $location->location_longitude = $data['location_longitude']; self::maybeSetCoordinates($location); $location->save(); } } // try to find existing event with matching unique ID first, so can update it $event = false; if ($data['uid']) { add_filter('em_events_get_default_search', array(__CLASS__, 'filterEventArgs'), 10, 2); add_filter('em_events_build_sql_conditions', array(__CLASS__, 'filterEventSQL'), 10, 2); $event = EM_Events::get(array('em_impexp_uid' => $data['uid'])); $event = count($event) > 0 ? $event[0] : false; remove_filter('em_events_get_default_search', array(__CLASS__, 'filterEventArgs'), 10, 2); remove_filter('em_events_build_sql_conditions', array(__CLASS__, 'filterEventSQL'), 10, 2); } if (!$event) { // must create a new event $event = new EM_Event(); } $event->location_id = $location ? $location->location_id : 0; $event->event_attributes['em_impexp_uid'] = $data['uid']; $event->event_attributes['em_impexp_url'] = $data['url']; $event->event_name = $data['summary']; $event->post_content = $data['post_content']; $event->post_excerpt = $data['post_excerpt']; if (preg_match('@^\\d\\d/\\d\\d/\\d\\d\\d\\d$@', $data['dtstart'])) { $data['dtstart'] .= ' 00:00:00'; $event->start = date_create_from_format('d/m/Y H:i:s', $data['dtstart'])->getTimestamp(); $event->event_start_date = date('Y-m-d', $event->start); $event->event_start_time = date('H:i:s', $event->start); } if (preg_match('@^\\d\\d/\\d\\d/\\d\\d\\d\\d$@', $data['dtend'])) { $data['dtend'] .= ' 00:00:00'; $event->end = date_create_from_format('d/m/Y H:i:s', $data['dtend'])->getTimestamp(); $event->event_end_date = date('Y-m-d', $event->end); $event->event_end_time = date('H:i:s', $event->end); } else { $event->end = $event->start; $event->event_end_date = $event->event_start_date; $event->event_end_time = $event->event_start_time; } $event->event_date_modified = current_time('mysql'); $event->event_all_day = $event->event_start_time === '00:00:00' && $event->event_end_time === '00:00:00' ? 1 : 0; foreach ($attrs as $attrName => $value) { $event->event_attributes[$attrName] = $value; } // TODO: recurring events switch ($data['freq']) { case 'DAILY': break; case 'WEEKLY': //~ $event->freq = $data['freq']; //~ $event->byday = $data['byday']; //~ $event->interval = $data['interval']; //~ $event->until = $data['until']; break; case 'MONTHLY': break; } if ($event) { $event->save(); $event->save_meta(); if ($data['categories']) { $categories = explode(',', $data['categories']); $eventcats = $event->get_categories(); foreach ($categories as $category) { $category = trim($category); if (isset($eventCategories[$category])) { $cat = $eventCategories[$category]; } else { $cat = wp_insert_term($category, 'event-categories'); if (is_array($cat)) { $cat = new EM_Category($cat['term_id']); $eventCategories[$category] = $cat; } } if ($cat) { $eventcats->categories[$cat->id] = $cat; } } $eventcats->save(); } } $records++; } } $wpdb->query('commit'); $this->plugin->showMessage($records === 1 ? '1 events loaded' : "{$records} events loaded"); }
/** * Duplicates this event and returns the duplicated event. Will return false if there is a problem with duplication. * @return EM_Event */ function duplicate() { global $wpdb, $EZSQL_ERROR; //First, duplicate. if ($this->can_manage(true)) { $event_table_name = $wpdb->prefix . EM_EVENTS_TABLE; $eventArray = $this->to_array(true); unset($eventArray['event_id']); $EM_Event = new EM_Event($eventArray); if ($EM_Event->save()) { $EM_Event->feedback_message = __("You are now viewing the duplicated event", 'dbem'); return apply_filters('em_event_duplicate', $EM_Event, $this); } } //TODO add error notifications for duplication failures. return apply_filters('em_event_duplicate', false, $this); }
/** * * get event post data in array. * if the post is not event, return empty array */ public static function getEventPostData($postID) { if (self::isEventsExists() == false) { return array(); } $postType = get_post_type($postID); if ($postType != EM_POST_TYPE_EVENT) { return array(); } $event = new EM_Event($postID, 'post_id'); $location = $event->get_location(); $arrEvent = $event->to_array(); $arrLocation = $location->to_array(); $date_format = get_option('date_format'); $time_format = get_option('time_format'); $arrEvent["event_start_date"] = date_format(date_create_from_format('Y-m-d', $arrEvent["event_start_date"]), $date_format); $arrEvent["event_end_date"] = date_format(date_create_from_format('Y-m-d', $arrEvent["event_end_date"]), $date_format); $arrEvent["event_start_time"] = date_format(date_create_from_format('H:i:s', $arrEvent["event_start_time"]), $time_format); $arrEvent["event_end_time"] = date_format(date_create_from_format('H:i:s', $arrEvent["event_end_time"]), $time_format); $response = array(); $response["start_date"] = $arrEvent["event_start_date"]; $response["end_date"] = $arrEvent["event_end_date"]; $response["start_time"] = $arrEvent["event_start_time"]; $response["end_time"] = $arrEvent["event_end_time"]; $response["id"] = $arrEvent["event_id"]; $response["location_name"] = $arrLocation["location_name"]; $response["location_address"] = $arrLocation["location_address"]; $response["location_slug"] = $arrLocation["location_slug"]; $response["location_town"] = $arrLocation["location_town"]; $response["location_state"] = $arrLocation["location_state"]; $response["location_postcode"] = $arrLocation["location_postcode"]; $response["location_region"] = $arrLocation["location_region"]; $response["location_country"] = $arrLocation["location_country"]; $response["location_latitude"] = $arrLocation["location_latitude"]; $response["location_longitude"] = $arrLocation["location_longitude"]; return $response; }
/** * 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_EVENT) { global $EM_Notices, $EM_Event; $EM_Event = new EM_Event($post_id, 'post_id'); //get a refreshed $EM_Event because otherwise statuses don't get updated by WP $EM_Event->set_status($EM_Event->get_status()); $EM_Notices->remove_all(); //no validation/notices needed } }
/** * @param boolean $result * @param EM_Event $EM_Event * @return boolean */ function em_event_submission_emails($result, $EM_Event) { if ($result) { //if this is just published, we need to email the user about the publication, or send to pending mode again for review $cant_publish_event = $EM_Event->is_individual() && !user_can($EM_Event->get_contact()->ID, 'publish_events'); $cant_publish_recurring_event = $EM_Event->is_recurring() && !user_can($EM_Event->get_contact()->ID, 'publish_recurring_events'); $output_type = get_option('dbem_smtp_html') ? 'html' : 'email'; if ($cant_publish_event || $cant_publish_recurring_event) { if ($EM_Event->is_published() && !$EM_Event->previous_status) { //only send email to users that can't publish events themselves and that were previously unpublished $approvals_count = get_post_meta($EM_Event->post_id, '_event_approvals_count', true); $approvals_count = $approvals_count > 0 ? $approvals_count : 0; if ($approvals_count == 1) { $subject = $EM_Event->output(get_option('dbem_event_approved_email_subject'), 'raw'); $body = $EM_Event->output(get_option('dbem_event_approved_email_body'), $output_type); } else { $subject = $EM_Event->output(get_option('dbem_event_reapproved_email_subject'), 'raw'); $body = $EM_Event->output(get_option('dbem_event_reapproved_email_body'), $output_type); } if ($EM_Event->event_owner == "") { return true; } $EM_Event->email_send($subject, $body, $EM_Event->get_contact()->user_email); } elseif (!$EM_Event->get_status() && get_option('dbem_event_submitted_email_admin') != '') { $approvals_count = get_post_meta($EM_Event->post_id, '_event_approvals_count', true); $approvals_count = $approvals_count > 0 ? $approvals_count : 0; update_post_meta($EM_Event->post_id, '_event_approvals_count', $approvals_count + 1); $admin_emails = explode(',', str_replace(' ', '', get_option('dbem_event_submitted_email_admin'))); //admin emails are in an array, single or multiple if (empty($admin_emails)) { return true; } if ($approvals_count > 1) { $subject = $EM_Event->output(get_option('dbem_event_resubmitted_email_subject'), 'raw'); $message = $EM_Event->output(get_option('dbem_event_resubmitted_email_body'), $output_type); } else { $subject = $EM_Event->output(get_option('dbem_event_submitted_email_subject'), 'raw'); $message = $EM_Event->output(get_option('dbem_event_submitted_email_body'), $output_type); } //Send email to admins $EM_Event->email_send($subject, $message, $admin_emails); } } elseif (!current_user_can('list_users')) { if ($EM_Event->is_published() && !$EM_Event->previous_status) { $admin_emails = explode(',', str_replace(' ', '', get_option('dbem_event_submitted_email_admin'))); //admin emails are in an array, single or multiple if (empty($admin_emails)) { return true; } $subject = $EM_Event->output(get_option('dbem_event_published_email_subject'), 'raw'); $body = $EM_Event->output(get_option('dbem_event_published_email_body'), $output_type); $EM_Event->email_send($subject, $body, $admin_emails); } } } return $result; }
/** * This is a temporary filter function which mimicks the old filters in the old 2.x placeholders function * @param string $result * @param EM_Event $event * @param string $placeholder * @param string $target * @return mixed */ function em_event_output_placeholder($result, $event, $placeholder, $target = 'html') { if ($target == 'raw') { return $result; } if (in_array($placeholder, array("#_EXCERPT", '#_EVENTEXCERPT', "#_LOCATIONEXCERPT")) && $target == 'html') { $result = apply_filters('dbem_notes_excerpt', $result); } elseif ($placeholder == '#_CONTACTEMAIL' && $target == 'html') { $result = em_ascii_encode($event->get_contact()->user_email); } elseif (in_array($placeholder, array('#_EVENTNOTES', '#_NOTES', '#_DESCRIPTION', '#_LOCATIONNOTES', '#_CATEGORYNOTES', '#_CATEGORYDESCRIPTION'))) { if ($target == 'rss') { $result = apply_filters('dbem_notes_rss', $result); $result = apply_filters('the_content_rss', $result); } elseif ($target == 'map') { $result = apply_filters('dbem_notes_map', $result); } elseif ($target == 'ical') { $result = apply_filters('dbem_notes_ical', $result); } elseif ($target == "email") { $result = apply_filters('dbem_notes_email', $result); } else { //html $result = apply_filters('dbem_notes', $result); } } elseif (in_array($placeholder, array("#_NAME", '#_LOCATION', '#_TOWN', '#_ADDRESS', '#_LOCATIONNAME', "#_EVENTNAME", "#_LOCATIONNAME", '#_CATEGORY'))) { if ($target == "rss") { $result = apply_filters('dbem_general_rss', $result); } elseif ($target == "ical") { $result = apply_filters('dbem_general_ical', $result); } elseif ($target == "email") { $result = apply_filters('dbem_general_email', $result); } else { //html $result = apply_filters('dbem_general', $result); } } return $result; }
function updateEvent($data) { $em_event = em_get_event(getPostIdByMetaValue('_ss_id', $data['id']), 'post_id'); $check = true; if (isset($data['command']) && $data['command'] == 'UPDATE') { if (!$em_event->event_id) { $em_event = new EM_Event(); } $em_event->event_start_date = $data["starttag"]; $em_event->event_start_time = $data["startzeit"]; $em_event->event_end_date = $data["endtag"]; $em_event->event_end_time = $data["endzeit"]; $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); $em_event->location_id = isset($data["venueid"]) ? $data["venueid"] : ''; $em_event->post_title = $data["titel"]; $em_event->event_name = $data["titel"]; //$em_event->body = (($data["kurzbeschreibung"]) ? $data["kurzbeschreibung"] : ''); $em_event->post_content = isset($data["kurzbeschreibung"]) ? $data["kurzbeschreibung"] : ''; $em_event->post_excerpt = isset($data["auszug"]) ? $data["auszug"] : ''; $em_event->post_tags = @$data["tags"]; // meta $em_event->event_attributes = array('Status' => $data['status'], 'Line Up' => $data['lineup'], 'Stil' => isset($data["stil"]) ? $data["stil"] : '', 'Preis' => $data['preis'], 'Parent' => isset($data["parentid"]) ? $data["parentid"] : '', 'Team' => $data['team'], 'Recommended' => $data['recommended'], 'Promoted' => $data['promoted'], 'Gewinnspiel' => $data['gewinnspiel'], 'Kurzbeschreibung' => $data["kurzbeschreibung"]); $em_event->group_id = 0; $em_event->event_date_modified = date('Y-m-d H:i:s', time()); $em_event->event_all_day = $data['ganztägig'] ? 1 : 0; $em_event->event_rsvp = 0; $check = $em_event->save(); add_post_meta($em_event->post_id, '_ss_id', $data['id']); // add category $categories = array(); $type = new EM_Category(strtolower($data["veranstaltungstyp"])); if (!$type->term_id) { $type = new EM_Category("sonstiges"); } array_push($categories, $type->term_id); if ($data["recommended"]) { array_push($categories, get_cat_ID('tipp')); } if ($data["promoted"]) { array_push($categories, get_cat_ID('sponsored')); } if ($data["team"]) { array_push($categories, get_cat_ID('team')); } if ($data["veranstaltungstyp"]) { array_push($categories, get_cat_ID(strtolower($data["veranstaltungstyp"]))); } if ($data["gewinnspiel"]) { array_push($categories, get_cat_ID('gewinnspiel')); } if ($data["preis"] != '' && $data["preis"] == 0) { array_push($categories, get_cat_ID('kostenlos')); } if (count($categories)) { wp_set_post_terms($em_event->post_id, $categories, 'event-categories', false); } // add tags $tags = array(); if ($data["tags"]) { array_push($tags, $data["tags"]); } //if($data["ausverkauft"]) array_push($tags, "ausverkauft"); if ($data["openair"]) { array_push($tags, "open air"); } if ($data['lineup']) { $tags = array_merge($tags, explode(',', $data['lineup'])); } if ($data['tags']) { $tags = array_merge($tags, explode(',', $data['tags'])); } if (count($tags)) { wp_set_post_terms($em_event->post_id, $tags, 'event-tags', false); } } elseif (isset($data['command']) && $data['command'] == 'DELETE') { if ($em_event->event_id) { $check = $em_event->delete(true); } } return $check; }