get_plugin_slug(); /* * Add event category to title when filtered by a category */ add_filter( 'the_title', function($title, $id = null){ global $post; $title = htmlentities($title, ENT_QUOTES, "UTF-8", false); $settings = get_option('arlo_settings'); $pages = []; if (!empty($settings['post_types']['event']['posts_page'])) { array_push($pages, $settings['post_types']['event']['posts_page']); } if (!empty($settings['post_types']['eventsearch']['posts_page'])) { array_push($pages, $settings['post_types']['eventsearch']['posts_page']); } if (!empty($settings['post_types']['upcoming']['posts_page'])) { array_push($pages, $settings['post_types']['upcoming']['posts_page']); } $subtitle = ''; $arlo_category = isset($_GET['arlo-category']) && !empty($_GET['arlo-category']) ? $_GET['arlo-category'] : get_query_var('arlo-category', ''); $cat_slug = !empty($arlo_category) ? $arlo_category : ''; $cat = null; if (!empty($cat_slug)) $cat = \Arlo\Categories::get(array('slug' => $cat_slug)); $location = !empty($_GET['arlo-location']) ? $_GET['arlo-location'] : get_query_var('arlo-location', ''); $search = !empty($_GET['arlo-search']) ? $_GET['arlo-search'] : get_query_var('arlo-search', ''); $location = stripslashes(urldecode($location)); $search = stripslashes(urldecode($search)); if($id === null || !in_array($id, $pages) || $id != $post->ID || !in_the_loop() ) return $title; if(!$cat && empty($location) && empty($search)) return $title; if (!empty($cat->c_name)) { $subtitle = $cat->c_name; if (!empty($location)) { $subtitle .= ' (' . $location . ')'; } } else if (!empty($location)) { $subtitle = htmlentities($location); } else if (!empty($search)) { $subtitle = htmlentities($search); } // append category name to events page if (!empty($subtitle)) { $subtitle = htmlentities($subtitle, ENT_QUOTES, "UTF-8"); $subtitle = '' . (!empty($title) ? ': ':'') . $subtitle . ' '; } return $title . $subtitle; }, 10, 2); /* * Trick WP to treat custom post types as pages */ add_action('parse_query', function($wp_query){ if (isset($wp_query->query['post_type']) && in_array($wp_query->query['post_type'], array('arlo_event', 'arlo_presenter', 'arlo_venue', 'arlo_region'))) { $wp_query->is_single = false; $wp_query->is_page = true; } return $wp_query; }); /* * Now allow custom templates for these custom post types */ add_filter('page_template', function($template){ global $post; if(in_array($post->post_type, array('arlo_event', 'arlo_presenter', 'arlo_venue'))) { $type = str_replace('arlo_', '', $post->post_type); if(($file = locate_template($type . '.php')) && is_page()) { return $file; } } add_filter( 'body_class', function( $classes ) { $classes[] = 'arlo'; return $classes; }); return $template; }, 100, 1); /** * arlo_child_categories function. * * @access public * @param mixed $cats * @param int $depth (default: 0) * @return void */ function arlo_child_categories($cats, $depth=0) { if(!is_array($cats)) return array(); $space = ($depth > 0) ? ' ' : ''; $output = array(); foreach($cats as $cat) { $output[] = array( 'string' => str_repeat('–', $depth) . $space . $cat->c_name, 'value' => $cat->c_slug, 'id' => $cat->c_arlo_id ); $output = array_merge($output, arlo_child_categories($cat->children, $depth+1)); } return $output; } /** * arlo_create_region_selector function. * * @access public * @param string $page_name * @return string */ function arlo_create_region_selector($page_name) { global $post; $valid_page_names = ['upcoming', 'event', 'eventsearch']; $settings = get_option('arlo_settings'); $regions = get_option('arlo_regions'); if (!in_array($page_name, $valid_page_names) || !(is_array($regions) && count($regions))) return ""; $regionselector_html .= arlo_create_filter('region', $regions); return $regionselector_html; } /** * arlo_create_filter function. * * @access public * @param mixed $type * @param mixed $items * @param mixed $label (default: null) * @return void */ function arlo_create_filter($type, $items, $label=null) { $filter_html = ''; return $filter_html; } /** * Replace all arlo marcos with data from arlo tables * * @since 1.0.0 * * @param array $items * @param string $content * * @return string Macro filtered content */ function arlo_replace_macros($items, $content) { foreach($items as $key => $value) { $content = str_replace('[arlo_' . $key . ']', $value, $content); } return $content; } /** * Registers the arlo custom post types * * @since 1.0.0 * */ function arlo_register_custom_post_types() { $settings = get_option('arlo_settings'); foreach(Arlo_For_Wordpress::$post_types as $id => $type) { // default slug $slug = str_replace('_', '-', strtolower(trim(preg_replace('/[^A-Za-z]+/', '', $type['name'])))); $slug = 'arlo/' . $slug; // slug based on page, if it exists $page_id = null; if(isset($settings['post_types'][$id]['posts_page']) && $settings['post_types'][$id]['posts_page'] != 0) { $page_id = $settings['post_types'][$id]['posts_page']; $slug = substr(substr(str_replace(get_home_url(), '', get_permalink($settings['post_types'][$id]['posts_page'])), 0, -1), 1); } $args = array( 'labels' => array( 'name' => __( $type['name'], $GLOBALS['arlo_plugin_slug']), 'singular_name' => __( $type['singular_name'], $GLOBALS['arlo_plugin_slug']) ), 'public' => true, 'publicly_queryable' => true, 'show_ui' => false, 'show_in_menu' => false, 'query_var' => true, 'rewrite' => array( 'slug' => $slug, 'with_front' => false // false ensures no blog-like url ), 'capability_type' => 'page', 'has_archive' => false, 'hierarchical' => false, 'menu_position' => null, 'supports' => array( 'comments' => false ) ); // let's try some custom rewrite rules if($page_id) { switch($id) { case 'upcoming': add_rewrite_rule('^' . $slug . '/(region-([^/]*))?/?(cat-([^/]*))?/?(month-([^/]*))?/?(location-([^/]*))?/?(delivery-([^/]*))?/?(eventtag-([^/]*))?/?(page/([^/]*))?','index.php?page_id=' . $page_id . '&arlo-region=$matches[2]&arlo-category=$matches[4]&arlo-month=$matches[6]&arlo-location=$matches[8]&arlo-delivery=$matches[10]&arlo-eventtag=$matches[12]&paged=$matches[14]','top'); break; case 'event': add_rewrite_rule('^' . $slug . '/(\d+-[^/]*)+/?(region-([^/]*))?/?$','index.php?arlo_event=$matches[1]&arlo-region=$matches[3]','top'); add_rewrite_rule('^' . $slug . '/(region-([^/]*))?/?(cat-([^/]*))?/?(month-([^/]*))?/?(location-([^/]*))?/?(delivery-([^/]*))?/?(templatetag-([^/]*))?/?(page/([^/]*))?','index.php?page_id=' . $page_id . '&arlo-region=$matches[2]&arlo-category=$matches[4]&arlo-month=$matches[6]&arlo-location=$matches[8]&arlo-delivery=$matches[10]&arlo-templatetag=$matches[12]&paged=$matches[14]','top'); break; case 'eventsearch': add_rewrite_rule('^' . $slug . '/?(region-([^/]*))?/search/([^/]*)?/?(page/([^/]*))?','index.php?page_id=' . $page_id . '&arlo-region=$matches[2]&arlo-search=$matches[3]&paged=$matches[5]','top'); add_rewrite_rule('^' . $slug . '/?(region-([^/]*))?/?(page/([^/]*))?','index.php?page_id=' . $page_id . '&arlo-region=$matches[2]&paged=$matches[4]','top'); break; case 'presenter': add_rewrite_rule('^' . $slug . '/page/([^/]*)/?','index.php?page_id=' . $page_id . '&paged=$matches[1]','top'); break; case 'venue': add_rewrite_rule('^' . $slug . '/page/([^/]*)/?','index.php?page_id=' . $page_id . '&paged=$matches[1]','top'); break; } } register_post_type('arlo_' . $id, $args); } // these should possibly be in there own function? add_rewrite_tag('%page_id%', '([^&]+)'); add_rewrite_tag('%arlo-region%', '([^&]+)'); add_rewrite_tag('%arlo-category%', '([^&]+)'); add_rewrite_tag('%arlo-month%', '([^&]+)'); add_rewrite_tag('%arlo-location%', '([^&]+)'); add_rewrite_tag('%arlo-delivery%', '([^&]+)'); add_rewrite_tag('%arlo-eventtag%', '([^&]+)'); add_rewrite_tag('%arlo-templatetag%', '([^&]+)'); add_rewrite_tag('%arlo-search%', '([^&]+)'); add_rewrite_tag('%paged%', '([^&]+)'); // flush cached rewrite rules if we've just updated the arlo settings if(isset($_GET['settings-updated'])) flush_rewrite_rules(); } /** * If there is a search term for arlo-search, we need to redirect to a friendlier url. * * @since 2.2.0 * */ function set_search_redirect() { $settings = get_option('arlo_settings'); if (strpos($_SERVER['QUERY_STRING'], 'arlo-search') !== false && !empty($_GET['arlo-search'])) { if(isset($settings['post_types']['eventsearch']['posts_page']) && $settings['post_types']['eventsearch']['posts_page'] != 0) { $slug = substr(substr(str_replace(get_home_url(), '', get_permalink($settings['post_types']['eventsearch']['posts_page'])), 0, -1), 1); $location = '/' . $slug . '/search/' . urlencode(stripslashes_deep($_GET['arlo-search'])) . '/'; wp_redirect( get_home_url() . $location ); exit(); } } } /** * If there is at least one region, and the url doesn't contain any region information, we have to construct the url with region, * and set the cookie according to the default (first) region * * @since 2.2.0 * */ function set_region_redirect() { global $post; $regions = get_option('arlo_regions'); $settings = get_option('arlo_settings'); $selected_region = get_query_var('arlo-region', ''); $page_id = get_query_var('page_id', ''); $page_obj = get_queried_object(); $page_type = ''; if (!empty($page_obj)) { $page_type = $page_obj->post_type; $page_id = $page_obj->ID; } foreach(Arlo_For_Wordpress::$post_types as $id => $arlo_post) { if (isset($arlo_post['regionalized']) && is_bool($arlo_post['regionalized']) && $arlo_post['regionalized']) { $arlo_page_ids[intval($settings['post_types'][$id]['posts_page'])] = $id; } } if (((array_key_exists($page_id, $arlo_page_ids) && !empty($settings['post_types'][$arlo_page_ids[$page_id]]['posts_page'])) || $page_type == 'arlo_event') && is_array($regions) && count($regions)) { if (empty($selected_region)) { //try to read the region from a cookie if (!empty($_COOKIE['arlo-region']) && in_array($_COOKIE['arlo-region'], array_keys($regions))) { $selected_region = $_COOKIE['arlo-region']; } else { $selected_region = reset(array_keys($regions)); } setcookie("arlo-region", $selected_region, time()+60*60*24*30, '/'); if ($page_type == 'arlo_event') { $slug = substr(substr(str_replace(get_home_url(), '', get_post_permalink($page_id)), 0, -1), 1); } else { $slug = substr(substr(str_replace(get_home_url(), '', get_permalink($settings['post_types'][$arlo_page_ids[$page_id]]['posts_page'])), 0, -1), 1); } $location = str_replace($slug, $slug.'/region-' . $selected_region , $_SERVER['REQUEST_URI']); wp_redirect($location); exit(); } else { setcookie("arlo-region", $selected_region, time()+60*60*24*30, '/'); } } } /** * Checks if a post is a arlo custom post and sends the content to the revelant function * * @since 1.0.0 * * @param string $content The content of the custom post * * @return string */ function arlo_the_content($content) { global $post; $post_type = str_replace('arlo_', '', get_post_type($post)); if(function_exists('arlo_the_content_'.$post_type) && in_the_loop()) { return call_user_func_array('arlo_the_content_'.$post_type, func_get_args()); } return $content; } /** * Returns arlo custom post event page content parsed of shortcodes and macros * * @since 1.0.0 * * @param string $content The content of the custom post * * @return string The content replaced by the filtered event template */ function arlo_the_content_event($content) { global $post, $wpdb; $templates = arlo_get_option('templates'); $content = $templates['event']['html']; $regions = get_option('arlo_regions'); $arlo_region = get_query_var('arlo-region', ''); $arlo_region = (!empty($arlo_region) && array_ikey_exists($arlo_region, $regions) ? $arlo_region : ''); $t1 = "{$wpdb->prefix}arlo_eventtemplates"; $t2 = "{$wpdb->prefix}posts"; $sql = " SELECT et.*, post.ID as post_id FROM $t1 et LEFT JOIN $t2 post ON et.et_post_name = post.post_name WHERE post.post_type = 'arlo_event' AND post.ID = $post->ID " . (!empty($arlo_region) ? " AND et.et_region = '" . $arlo_region . "'" : "") . " ORDER BY et.et_name ASC "; $item = $wpdb->get_row($sql, ARRAY_A); $GLOBALS['arlo_eventtemplate'] = $item; $output = do_shortcode($content); unset($GLOBALS['arlo_eventtemplate']); return $output; } /** * Returns arlo custom post presenter page content parsed of shortcodes and macros * * @since 1.0.0 * * @param string $content The content of the custom post * * @return string The content replaced by the filtered presenter template */ function arlo_the_content_presenter($content) { $templates = arlo_get_option('templates'); $content = $templates['presenter']['html']; global $post, $wpdb; $t1 = "{$wpdb->prefix}arlo_presenters"; $t2 = "{$wpdb->prefix}posts"; $item = $wpdb->get_row( "SELECT p.*, post.ID as post_id FROM $t1 p LEFT JOIN $t2 post ON p.p_post_name = post.post_name WHERE post.post_type = 'arlo_presenter' AND post.ID = $post->ID ORDER BY p.p_lastname ASC", ARRAY_A); $GLOBALS['arlo_presenter_list_item'] = $item; $output = do_shortcode($content); unset($GLOBALS['arlo_presenter_list_item']); return $output; } /** * Returns arlo custom post venue page content parsed of shortcodes and macros * * @since 1.0.0 * * @param string $content The content of the custom post * * @return string The content replaced by the filtered venue template */ function arlo_the_content_venue($content) { $templates = arlo_get_option('templates'); $content = $templates['venue']['html']; global $post, $wpdb; $t1 = "{$wpdb->prefix}arlo_venues"; $t2 = "{$wpdb->prefix}posts"; $item = $wpdb->get_row( "SELECT v.*, post.ID as post_id FROM $t1 v LEFT JOIN $t2 post ON v.v_post_name = post.post_name WHERE post.post_type = 'arlo_venue' AND post.ID = $post->ID ORDER BY v.v_name ASC", ARRAY_A); $GLOBALS['arlo_venue_list_item'] = $item; $output = do_shortcode($content); unset($GLOBALS['arlo_venue_list_item']); return $output; } /** * Returns pagination HTML for a list page such as Event Templates or Venues * * @since 2.0.0 * * @param int $num Total amount of items e.g. Event Templates or Venues * * @return string The pagination HTML */ function arlo_pagination($num, $limit=null) { // the wordpress posts per page option value $limit = is_null($limit) ? get_option('posts_per_page') : $limit; $big = 999999999; $current = !empty($_GET['paged']) ? intval($_GET['paged']) : intval(get_query_var('paged')); return paginate_links(array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, $current ), 'total' => ceil($num/$limit), 'mid_size' => 6 )); } /** * Get the content of a blueprint file * * @since 1.0.0 * * @param string $name name of the blueprint file to get * * @return string the contents of the blueprint file */ function arlo_get_blueprint($name) { $path = ARLO_PLUGIN_DIR.'/includes/blueprints/'.$name.'.tmpl'; if(file_exists($path)) { return file_get_contents($path); } return 'Blueprint NOT found'; } /** * Flush permalinks * * @since 1.0.0 * */ function arlo_flush_permalinks() { //update_option('rewrite_rules',''); //arlo_register_custom_post_types(); //flush_rewrite_rules(); } /** * arlo_get_option function. * * @access public * @param mixed $key * @param mixed $default (default: null) * @return void */ function arlo_get_option($key, $default = null) { $settings = get_option('arlo_settings', array()); if(isset($settings[$key])) { return $settings[$key]; } return $default; } /** * arlo_set_option function. * * @access public * @param mixed $key * @param mixed $value (default: null) * @return boolean */ function arlo_set_option($key, $value = null) { $settings = get_option('arlo_settings', array()); $settings[$key] = $value; return update_option('arlo_settings', $settings); } /** * arlo_add_datamodel function. * * @access public * @return void */ function arlo_add_datamodel() { install_table_arlo_eventtemplate(); install_table_arlo_contentfields(); install_table_arlo_tags(); install_table_arlo_events(); install_table_arlo_venues(); install_table_arlo_presenters(); install_table_arlo_offers(); install_table_arlo_eventtemplates_presenters(); install_table_arlo_events_presenters(); install_table_arlo_import_log(); install_table_arlo_categories(); install_table_arlo_eventtemplates_categories(); install_table_arlo_timezones(); return; } /** * core_set_charset function. * * @access public * @return void */ function core_set_charset() { global $wpdb; /* Load db functions */ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); if ( !empty($wpdb->charset) ) return "DEFAULT CHARACTER SET $wpdb->charset"; return ''; } /** * install_table_arlo_eventtemplate function. * * @access public * @return void */ function install_table_arlo_eventtemplate() { global $wpdb, $current_user; $table_name = $wpdb->prefix . "arlo_eventtemplates"; $sql = "CREATE TABLE " . $table_name . " ( et_id INT(11) NOT NULL AUTO_INCREMENT, et_arlo_id INT(11) NOT NULL, et_code VARCHAR(255) NULL, et_name VARCHAR(255) NULL, et_descriptionsummary TEXT NULL, et_post_name VARCHAR(255) NULL, active INT(10) unsigned DEFAULT NULL, et_registerinteresturi TEXT NULL, et_viewuri TEXT NULL, et_region VARCHAR(5) NULL, PRIMARY KEY (et_id), KEY et_arlo_id (et_arlo_id), KEY et_region (et_region)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * install_table_arlo_contentfields function. * * @access public * @return void */ function install_table_arlo_contentfields() { global $wpdb, $current_user; $table_name = $wpdb->prefix . "arlo_contentfields"; $sql = "CREATE TABLE " . $table_name . " ( cf_id INT(11) NOT NULL AUTO_INCREMENT, et_id INT(11) NOT NULL, cf_fieldname VARCHAR(255) NULL, cf_text TEXT NULL, cf_order INT(11) NULL, e_contenttype VARCHAR(255) NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (cf_id), KEY cf_order (cf_order), KEY et_id (et_id)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * install_table_arlo_events function. * * @access public * @return void */ function install_table_arlo_events() { global $wpdb, $current_user; $table_name = $wpdb->prefix . "arlo_events"; $sql = "CREATE TABLE " . $table_name . " ( e_id INT(11) NOT NULL AUTO_INCREMENT, e_arlo_id INT(11) NOT NULL, et_arlo_id INT(11) NULL, e_code VARCHAR(255) NULL, e_name VARCHAR(255) NULL, e_startdatetime DATETIME NOT NULL, e_finishdatetime DATETIME NULL, e_datetimeoffset VARCHAR(6) NULL, e_timezone VARCHAR(10) NULL, e_timezone_id TINYINT(3) UNSIGNED NULL, v_id INT(11) NULL, e_locationname VARCHAR(255) NULL, e_locationroomname VARCHAR(255) NULL, e_locationvisible TINYINT(1) NOT NULL DEFAULT '0', e_isfull TINYINT(1) NOT NULL DEFAULT FALSE, e_placesremaining INT(11) NULL, e_summary VARCHAR(255) NULL, e_sessiondescription VARCHAR(255) NULL, e_notice TEXT NULL, e_viewuri VARCHAR(255) NULL, e_registermessage VARCHAR(255) NULL, e_registeruri VARCHAR(255) NULL, e_providerorganisation VARCHAR(255) NULL, e_providerwebsite VARCHAR(255) NULL, e_isonline TINYINT(1) NOT NULL DEFAULT FALSE, e_parent_arlo_id INT(11) NOT NULL, e_region VARCHAR(5) NOT NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (e_id), KEY et_arlo_id (et_arlo_id), KEY e_arlo_id (e_arlo_id), KEY e_region (e_region), KEY v_id (v_id)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * install_table_arlo_venues function. * * @access public * @return void */ function install_table_arlo_venues() { global $wpdb, $current_user; $table_name = $wpdb->prefix . "arlo_venues"; $sql = "CREATE TABLE " . $table_name . " ( v_id INT(11) NOT NULL AUTO_INCREMENT, v_arlo_id INT(11) NOT NULL, v_name VARCHAR(255) NULL, v_geodatapointlatitude DECIMAL(10,6) NULL, v_geodatapointlongitude DECIMAL(10,6) NULL, v_physicaladdressline1 VARCHAR(255) NULL, v_physicaladdressline2 VARCHAR(255) NULL, v_physicaladdressline3 VARCHAR(255) NULL, v_physicaladdressline4 VARCHAR(255) NULL, v_physicaladdresssuburb VARCHAR(255) NULL, v_physicaladdresscity VARCHAR(255) NULL, v_physicaladdressstate VARCHAR(255) NULL, v_physicaladdresspostcode VARCHAR(255) NULL, v_physicaladdresscountry VARCHAR(255) NULL, v_viewuri VARCHAR(255) NULL, v_facilityinfodirections TEXT NULL, v_facilityinfoparking TEXT NULL, v_post_name VARCHAR(255) NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (v_id), KEY v_arlo_id (v_arlo_id)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * install_table_arlo_presenters function. * * @access public * @return void */ function install_table_arlo_presenters() { global $wpdb, $current_user; $table_name = $wpdb->prefix . "arlo_presenters"; $sql = "CREATE TABLE " . $table_name . " ( p_id INT(11) NOT NULL AUTO_INCREMENT, p_arlo_id INT(11) NOT NULL, p_firstname VARCHAR(64) NULL, p_lastname VARCHAR(64) NULL, p_viewuri VARCHAR(255) NULL, p_profile TEXT NULL, p_qualifications TEXT NULL, p_interests TEXT NULL, p_twitterid VARCHAR(255) NULL, p_facebookid VARCHAR(255) NULL, p_linkedinid VARCHAR(255) NULL, p_post_name VARCHAR(255) NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (p_id), KEY p_arlo_id (p_arlo_id)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * install_table_arlo_offers function. * * @access public * @return void */ function install_table_arlo_offers() { global $wpdb, $current_user; $charset_collate = core_set_charset(); $table_name = $wpdb->prefix . "arlo_offers"; $sql = "CREATE TABLE " . $table_name . " ( o_id INT(11) NOT NULL AUTO_INCREMENT, o_arlo_id INT, et_id INT, e_id INT, o_label VARCHAR(255) NULL, o_isdiscountoffer TINYINT(1) NOT NULL DEFAULT FALSE, o_currencycode VARCHAR(255) NULL, o_offeramounttaxexclusive DECIMAL(15,2) NULL, o_offeramounttaxinclusive DECIMAL(15,2) NULL, o_formattedamounttaxexclusive VARCHAR(255) NULL, o_formattedamounttaxinclusive VARCHAR(255) NULL, o_taxrateshortcode VARCHAR(255) NULL, o_taxratename VARCHAR(255) NULL, o_taxratepercentage DECIMAL(3,2) NULL, o_message TEXT NULL, o_order INT(11) NULL, o_replaces INT(11) NULL, o_region VARCHAR(5) NOT NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (o_id), KEY o_arlo_id (o_arlo_id), KEY et_id (et_id), KEY e_id (e_id), KEY o_region (o_region), KEY o_order (o_order)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * install_table_arlo_eventtemplates_presenters function. * * @access public * @return void */ function install_table_arlo_eventtemplates_presenters() { global $wpdb, $current_user; $charset_collate = core_set_charset(); $table_name = $wpdb->prefix . "arlo_eventtemplates_presenters"; $sql = "CREATE TABLE " . $table_name . " ( et_arlo_id INT(11) NULL, p_arlo_id INT(11) NULL, p_order INT(11) NULL COMMENT 'Order of the presenters for the event template.', active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (et_arlo_id,p_arlo_id), KEY cf_order (p_order), KEY fk_et_id_idx (et_arlo_id ASC), KEY fk_p_id_idx (p_arlo_id ASC)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * install_table_arlo_tags function. * * @access public * @return void */ function install_table_arlo_tags() { global $wpdb, $current_user; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); $charset_collate = core_set_charset(); $sql = "CREATE TABLE " . $wpdb->prefix . "arlo_tags ( id mediumint(8) unsigned NOT NULL AUTO_INCREMENT, tag varchar(255) NOT NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (id)) CHARACTER SET utf8 COLLATE=utf8_general_ci"; dbDelta($sql); $sql = "CREATE TABLE " . $wpdb->prefix . "arlo_events_tags ( e_arlo_id int(11) NOT NULL, tag_id mediumint(8) unsigned NOT NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (e_arlo_id,tag_id)) CHARACTER SET utf8 COLLATE=utf8_general_ci"; dbDelta($sql); $sql = "CREATE TABLE " . $wpdb->prefix . "arlo_eventtemplates_tags ( et_arlo_id int(11) NOT NULL, tag_id mediumint(8) unsigned NOT NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (et_arlo_id,tag_id)) CHARACTER SET utf8 COLLATE=utf8_general_ci"; dbDelta($sql); } /** * install_table_arlo_events_presenters function. * * @access public * @return void */ function install_table_arlo_events_presenters() { global $wpdb, $current_user; $charset_collate = core_set_charset(); $table_name = $wpdb->prefix . "arlo_events_presenters"; $sql = "CREATE TABLE " . $table_name . " ( e_arlo_id INT(11) NULL, p_arlo_id INT(11) NULL, p_order INT(11) NULL COMMENT 'Order of the presenters for the event.', active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (e_arlo_id,p_arlo_id), KEY fk_e_id_idx (e_arlo_id ASC), KEY fk_p_id_idx (p_arlo_id ASC)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * install_table_arlo_categories function. * * @access public * @return void */ function install_table_arlo_categories() { global $wpdb, $current_user; $charset_collate = core_set_charset(); $table_name = $wpdb->prefix . "arlo_categories"; $sql = "CREATE TABLE " . $table_name . " ( c_id INT(11) NOT NULL AUTO_INCREMENT, c_arlo_id INT(11) NOT NULL, c_name varchar(255) NOT NULL DEFAULT '', c_slug varchar(255) NOT NULL DEFAULT '', c_header text, c_footer text, c_template_num SMALLINT UNSIGNED NOT NULL DEFAULT '0', c_order bigint(20) DEFAULT NULL, c_depth_level tinyint(3) unsigned NOT NULL DEFAULT '0', c_parent_id INT(11) DEFAULT NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (c_id), UNIQUE KEY c_arlo_id (c_arlo_id), KEY c_parent_id (c_parent_id)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * install_table_arlo_eventtemplates_categories function. * * @access public * @return void */ function install_table_arlo_eventtemplates_categories() { global $wpdb, $current_user; $charset_collate = core_set_charset(); $table_name = $wpdb->prefix . "arlo_eventtemplates_categories"; $sql = "CREATE TABLE " . $table_name . " ( et_arlo_id INT(11) NULL, c_arlo_id INT(11) NULL, et_order SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0', active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (et_arlo_id,c_arlo_id), KEY fk_et_id_idx (et_arlo_id ASC), KEY fk_c_id_idx (c_arlo_id ASC)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } /** * install_table_arlo_timezones function. * * @access public * @return void */ function install_table_arlo_timezones() { global $wpdb, $current_user; $charset_collate = core_set_charset(); $table_name = $wpdb->prefix . "arlo_timezones"; $sql = " CREATE TABLE " . $table_name . " ( id tinyint(3) unsigned NOT NULL, name varchar(256) NOT NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (id)) CHARACTER SET utf8 COLLATE=utf8_general_ci; "; $sql2 = " CREATE TABLE IF NOT EXISTS " . $table_name . "_olson ( timezone_id int(11) NOT NULL, olson_name varchar(255) NOT NULL, active INT(10) unsigned DEFAULT NULL, PRIMARY KEY (timezone_id,olson_name) ) CHARACTER SET utf8 COLLATE=utf8_general_ci; "; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); dbDelta($sql2); } /** * install_table_arlo_import_log function. * * @access public * @return void */ function install_table_arlo_import_log() { global $wpdb, $current_user; $charset_collate = core_set_charset(); $table_name = $wpdb->prefix . "arlo_import_log"; $sql = "CREATE TABLE $table_name ( id int(11) unsigned NOT NULL AUTO_INCREMENT, message text, created datetime DEFAULT NULL, successful tinyint(1) DEFAULT NULL, PRIMARY KEY (id)) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); $table_name = $wpdb->prefix . "arlo_import_lock"; $sql = "CREATE TABLE $table_name ( import_id int(10) unsigned NOT NULL, lock_acquired datetime NOT NULL, lock_expired datetime NOT NULL ) CHARACTER SET utf8 COLLATE=utf8_general_ci;"; dbDelta($sql); } /** * arlo_import_from_api function. * * @access public * @return void */ function arlo_import_from_api() { $plugin = Arlo_For_Wordpress::get_instance(); $plugin->import(); } /** * arlo_get_post_by_name function. * * @access public * @param mixed $name * @param string $post_type (default: 'post') * @return void */ function arlo_get_post_by_name($name, $post_type='post') { $args = array( 'name' => $name, 'post_type' => $post_type, 'post_status' => 'publish', 'numberposts' => 1 ); $posts = get_posts($args); if( $posts ) { return $posts[0]; } return false; } /** * getTimezones function. * * @access public * @return void */ function getTimezones() { global $wpdb, $arlo_plugin; $table = $wpdb->prefix . "arlo_timezones"; $active = $arlo_plugin->get_import_id(); $sql = " SELECT id, name FROM {$table} WHERE active = {$active} ORDER BY name "; return $wpdb->get_results($sql); } function getTimezoneOlsonNames($timezone_id = 0) { global $wpdb, $arlo_plugin; $timezone_id = intval($timezone_id); $table = $wpdb->prefix . "arlo_timezones_olson"; $active = $arlo_plugin->get_import_id(); $where = ''; if ($timezone_id > 0) { $where = " timezone_id = {$timezone_id} AND "; } $sql = " SELECT olson_name FROM {$table} WHERE {$where} active = {$active} "; return $wpdb->get_results($sql); } /* * Shortcodes */ $shortcodes = \Arlo\Shortcodes::init(); // event template list shortcode $shortcodes->add('event_template_search_list', function($content='', $atts, $shortcode_name){ $templates = arlo_get_option('templates'); $content = $templates['eventsearch']['html']; return $content; }); // upcoming event list region selector shortcode $shortcodes->add('template_search_region_selector', function($content='', $atts, $shortcode_name){ return arlo_create_region_selector("eventsearch"); }); // upcoming event list region selector shortcode $shortcodes->add('template_region_selector', function($content='', $atts, $shortcode_name){ return arlo_create_region_selector("event"); }); // event template list shortcode $shortcodes->add('event_template_list', function($content='', $atts, $shortcode_name){ $templates = arlo_get_option('templates'); $content = $templates['events']['html']; return $content; }); // event template list pagination $shortcodes->add('event_template_list_pagination', function($content='', $atts, $shortcode_name){ global $wpdb, $wp_query, $arlo_plugin; $active = $arlo_plugin->get_import_id(); if (isset($GLOBALS['show_only_at_bottom']) && $GLOBALS['show_only_at_bottom']) return; $limit = isset($atts['limit']) ? $atts['limit'] : get_option('posts_per_page'); $t1 = "{$wpdb->prefix}arlo_eventtemplates"; $t2 = "{$wpdb->prefix}posts"; $t3 = "{$wpdb->prefix}arlo_eventtemplates_categories"; $t4 = "{$wpdb->prefix}arlo_categories"; $t5 = "{$wpdb->prefix}arlo_events"; $t6 = "{$wpdb->prefix}arlo_eventtemplates_tags"; $t7 = "{$wpdb->prefix}arlo_tags"; $where = "WHERE post.post_type = 'arlo_event'"; $join = ""; $arlo_location = isset($_GET['arlo-location']) && !empty($_GET['arlo-location']) ? $_GET['arlo-location'] : get_query_var('arlo-location', ''); $arlo_category = isset($_GET['arlo-category']) && !empty($_GET['arlo-category']) ? $_GET['arlo-category'] : get_query_var('arlo-category', ''); $arlo_delivery = isset($_GET['arlo-delivery']) && !empty($_GET['arlo-delivery']) ? $_GET['arlo-delivery'] : get_query_var('arlo-delivery', ''); $arlo_templatetag = isset($_GET['arlo-templatetag']) && !empty($_GET['arlo-templatetag']) ? $_GET['arlo-templatetag'] : get_query_var('arlo-templatetag', ''); $arlo_search = isset($_GET['arlo-search']) && !empty($_GET['arlo-search']) ? $_GET['arlo-search'] : get_query_var('arlo-search', ''); $arlo_search = esc_sql(stripslashes(urldecode($arlo_search))); if(!empty($arlo_location) || (isset($arlo_delivery) && strlen($arlo_delivery) && is_numeric($arlo_delivery)) ) : $join .= " LEFT JOIN $t5 e USING (et_arlo_id)"; $where .= " AND e.e_parent_arlo_id = 0"; if(!empty($arlo_location)) : $where .= " AND e.e_locationname = '" . urldecode($arlo_location) . "'"; endif; if(isset($arlo_delivery) && strlen($arlo_delivery) && is_numeric($arlo_delivery)) : $where .= " AND e.e_isonline = " . $arlo_delivery; endif; if (!empty($arlo_region)) { $where .= ' AND e.e_region = "' . $arlo_region . '"'; } endif; if(!empty($arlo_templatetag)) : $join .= " LEFT JOIN $t6 ett USING (et_arlo_id) "; if (!is_numeric($arlo_templatetag)) { $where .= " AND tag.tag = '" . urldecode($arlo_templatetag) . "'"; $join .= " LEFT JOIN $t7 tag ON tag.id = ett.tag_id "; } else { $where .= " AND ett.tag_id = " . intval($arlo_templatetag); } endif; if (!empty($arlo_search)) { $where .= ' AND ( et_code like "%' . $arlo_search . '%" OR et_name like "%' . $arlo_search . '%" OR et_descriptionsummary like "%' . $arlo_search . '%" ) '; } if(!empty($arlo_category) || !empty($atts['category'])) { $cat_id = 0; if(!empty($atts['category'])) { $cat_slug = $atts['category']; } else { $cat_slug = $arlo_category; } $where .= " AND ( c.c_slug = '$cat_slug'"; $cat_id = $wpdb->get_var(" SELECT c_arlo_id FROM {$wpdb->prefix}arlo_categories WHERE c_slug = '{$cat_slug}' "); if (is_null($cat_id)) { $cat_id = 0; } if (isset($GLOBALS['show_child_elements']) && $GLOBALS['show_child_elements']) { $cats = \Arlo\Categories::getTree($cat_id, null); $categories_tree = arlo_child_categories($cats); $ids = array_map(function($item) { return $item['id']; }, $categories_tree); if (is_array($ids) && count($ids)) { $where .= " OR c.c_arlo_id IN (" . implode(',', $ids) . ")"; } } $where .= ')'; } else if (!(isset($atts['show_child_elements']) && $atts['show_child_elements'] == "true")) { $where .= ' AND (c.c_parent_id = (SELECT c_arlo_id FROM ' . $t4 . ' WHERE c_parent_id = 0 AND active = ' . $active . ') OR c.c_parent_id IS NULL)'; } // grouping $group = "GROUP BY et.et_arlo_id"; // if grouping is set... if(isset($atts['group'])) { switch($atts['group']) { case 'category': $group = ''; break; } } $items = $wpdb->get_results( "SELECT et.et_id FROM $t1 et {$join} LEFT JOIN $t2 post ON et.et_post_name = post.post_name LEFT JOIN $t3 etc ON etc.et_arlo_id=et.et_arlo_id AND etc.active = et.active LEFT JOIN $t4 c ON c.c_arlo_id=etc.c_arlo_id AND c.active = etc.active $where $group ORDER BY et.et_name ASC", ARRAY_A); $num = $wpdb->num_rows; return arlo_pagination($num,$limit); }); // event template list item shortcode $shortcodes->add('event_template_list_item', function($content='', $atts, $shortcode_name){ global $wpdb, $wp_query, $arlo_plugin; $settings = get_option('arlo_settings'); $regions = get_option('arlo_regions'); if (isset($atts['show_only_at_bottom']) && $atts['show_only_at_bottom'] == "true" && isset($GLOBALS['categories_count']) && $GLOBALS['categories_count']) { $GLOBALS['show_only_at_bottom'] = true; return; } $active = $arlo_plugin->get_import_id(); $limit = !empty($atts['limit']) ? $atts['limit'] : get_option('posts_per_page'); $page = !empty($_GET['paged']) ? intval($_GET['paged']) : intval(get_query_var('paged')); $offset = ($page > 0) ? $page * $limit - $limit: 0 ; $t1 = "{$wpdb->prefix}arlo_eventtemplates"; $t2 = "{$wpdb->prefix}posts"; $t3 = "{$wpdb->prefix}arlo_eventtemplates_categories"; $t4 = "{$wpdb->prefix}arlo_categories"; $t5 = "{$wpdb->prefix}arlo_events"; $t6 = "{$wpdb->prefix}arlo_eventtemplates_tags"; $t7 = "{$wpdb->prefix}arlo_tags"; $where = "WHERE post.post_type = 'arlo_event' AND et.active = {$active}"; $join = ""; $arlo_location = isset($_GET['arlo-location']) && !empty($_GET['arlo-location']) ? $_GET['arlo-location'] : get_query_var('arlo-location', ''); $arlo_category = isset($_GET['arlo-category']) && !empty($_GET['arlo-category']) ? $_GET['arlo-category'] : get_query_var('arlo-category', ''); $arlo_delivery = isset($_GET['arlo-delivery']) && !empty($_GET['arlo-delivery']) ? $_GET['arlo-delivery'] : get_query_var('arlo-delivery', ''); $arlo_templatetag = isset($_GET['arlo-templatetag']) && !empty($_GET['arlo-templatetag']) ? $_GET['arlo-templatetag'] : get_query_var('arlo-templatetag', ''); $arlo_search = isset($_GET['arlo-search']) && !empty($_GET['arlo-search']) ? $_GET['arlo-search'] : get_query_var('arlo-search', ''); $arlo_search = esc_sql(stripslashes(urldecode($arlo_search))); $arlo_region = get_query_var('arlo-region', ''); $arlo_region = (!empty($arlo_region) && array_ikey_exists($arlo_region, $regions) ? $arlo_region : ''); if(!empty($arlo_location) || (isset($arlo_delivery) && strlen($arlo_delivery) && is_numeric($arlo_delivery)) ) : $join .= " LEFT JOIN $t5 e USING (et_arlo_id)"; $where .= " AND e.e_parent_arlo_id = 0"; if(!empty($arlo_location)) : $where .= " AND e.e_locationname = '" . urldecode($arlo_location) . "'"; endif; if(isset($arlo_delivery) && strlen($arlo_delivery) && is_numeric($arlo_delivery)) : $where .= " AND e.e_isonline = " . $arlo_delivery; endif; if (!empty($arlo_region)) { $where .= ' AND e.e_region = "' . $arlo_region . '"'; } endif; if(!empty($arlo_templatetag)) : $join .= " LEFT JOIN $t6 ett USING (et_arlo_id) "; if (!is_numeric($arlo_templatetag)) { $where .= " AND tag.tag = '" . urldecode($arlo_templatetag) . "'"; $join .= " LEFT JOIN $t7 tag ON tag.id = ett.tag_id "; } else { $where .= " AND ett.tag_id = " . intval($arlo_templatetag); } endif; if (!empty($arlo_search)) { $where .= ' AND ( et_code like "%' . $arlo_search . '%" OR et_name like "%' . $arlo_search . '%" OR et_descriptionsummary like "%' . $arlo_search . '%" ) '; $atts['show_child_elements'] = "true"; } if (!empty($arlo_region)) { $where .= ' AND et.et_region = "' . $arlo_region . '"'; } if(!empty($arlo_category) || !empty($atts['category'])) { $cat_id = 0; if(!empty($atts['category'])) { $cat_slug = $atts['category']; } else { $cat_slug = $arlo_category; } $where .= " AND ( c.c_slug = '$cat_slug'"; $cat_id = $wpdb->get_var(" SELECT c_arlo_id FROM {$wpdb->prefix}arlo_categories WHERE c_slug = '{$cat_slug}' "); if (is_null($cat_id)) { $cat_id = 0; } if (isset($atts['show_child_elements']) && $atts['show_child_elements'] == "true") { $GLOBALS['show_child_elements'] = true; $cats = \Arlo\Categories::getTree($cat_id, null); $categories_tree = arlo_child_categories($cats); $ids = array_map(function($item) { return $item['id']; }, $categories_tree); if (is_array($ids) && count($ids)) { $where .= " OR c.c_arlo_id IN (" . implode(',', $ids) . ")"; } } $where .= ')'; } else if (!(isset($atts['show_child_elements']) && $atts['show_child_elements'] == "true")) { $where .= ' AND (c.c_parent_id = (SELECT c_arlo_id FROM ' . $t4 . ' WHERE c_parent_id = 0 AND active = ' . $active . ') OR c.c_parent_id IS NULL)'; } // grouping $group = "GROUP BY et.et_arlo_id"; //ordering $order = "ORDER BY et.et_name ASC"; // if grouping is set... if(isset($atts['group'])) { switch($atts['group']) { case 'category': $order = "ORDER BY c.c_order ASC, etc.et_order ASC, c.c_name ASC, et.et_name ASC"; break; } } $sql = "SELECT et.*, post.ID as post_id, etc.c_arlo_id, c.* FROM $t1 et {$join} LEFT JOIN $t2 post ON et.et_post_name = post.post_name LEFT JOIN $t3 etc ON etc.et_arlo_id=et.et_arlo_id AND etc.active = et.active LEFT JOIN $t4 c ON c.c_arlo_id=etc.c_arlo_id AND c.active = etc.active $where $group $order LIMIT $offset,$limit"; $items = $wpdb->get_results($sql, ARRAY_A); if(empty($items)) : $GLOBALS['no_event_text'] = !empty($settings['noevent_text']) ? $settings['noevent_text'] : __('No events to show', $GLOBALS['arlo_plugin_slug']); else : $output = $GLOBALS['no_event_text'] = ''; $previous = null; foreach($items as $item) { if(isset($atts['group'])) { switch($atts['group']) { case 'category': if(is_null($previous) || $item['c_id'] != $previous['c_id']) { $item['show_divider'] = $item['c_name']; } break; case 'alpha': if(is_null($previous) || $item['et_name'][0] != $previous['et_name'][0]) { $item['show_divider'] = $item['et_name'][0]; } break; } } $GLOBALS['arlo_eventtemplate'] = $item; $GLOBALS['arlo_event_list_item'] = $item; $output .= do_shortcode($content); unset($GLOBALS['arlo_eventtemplate']); unset($GLOBALS['arlo_event_list_item']); $previous = $item; } endif; return $output; }); // event template tags shortcode $shortcodes->add('event_template_tags', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_eventtemplate']['et_arlo_id'])) return ''; global $wpdb, $arlo_plugin; $output = ''; $tags = []; $active = $arlo_plugin->get_import_id(); // merge and extract attributes extract(shortcode_atts(array( 'layout' => '', 'prefix' => 'arlo-', ), $atts, $shortcode_name)); $items = $wpdb->get_results(" SELECT tag FROM {$wpdb->prefix}arlo_tags AS t LEFT JOIN {$wpdb->prefix}arlo_eventtemplates_tags AS ett ON tag_id = id WHERE ett.et_arlo_id = {$GLOBALS['arlo_eventtemplate']['et_arlo_id']} AND t.active = {$active} AND ett.active = {$active} ", ARRAY_A); foreach ($items as $t) { $tags[] = $t['tag']; } if (count($tags)) { switch($layout) { case 'list': $output = '
'; break; case 'class': $classes = []; foreach($tags as $tag) { $classes[] = htmlentities(sanitize_title($prefix . $tag), ENT_QUOTES, "UTF-8"); } $output = implode(' ', $classes); break; default: $output = ''; break; } } return $output; }); // event template tags shortcode $shortcodes->add('event_tags', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_event_list_item']['e_arlo_id'])) return ''; global $wpdb, $arlo_plugin; $output = ''; $tags = []; $active = $arlo_plugin->get_import_id(); // merge and extract attributes extract(shortcode_atts(array( 'layout' => '', 'prefix' => 'arlo-', ), $atts, $shortcode_name)); $items = $wpdb->get_results(" SELECT tag FROM {$wpdb->prefix}arlo_tags AS t LEFT JOIN {$wpdb->prefix}arlo_events_tags AS et ON tag_id = id WHERE et.e_arlo_id = {$GLOBALS['arlo_event_list_item']['e_arlo_id']} AND t.active = {$active} AND et.active = {$active} ", ARRAY_A); foreach ($items as $t) { $tags[] = $t['tag']; } if (count($tags)) { switch($layout) { case 'list': $output = ''; break; case 'class': $classes = []; foreach($tags as $tag) { $classes[] = htmlentities(sanitize_title($prefix . $tag), ENT_QUOTES, "UTF-8"); } $output = implode(' ', $classes); break; default: $output = ''; break; } } return $output; }); // event template code shortcode $shortcodes->add('event_template_code', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_eventtemplate']['et_code'])) return ''; return htmlentities($GLOBALS['arlo_eventtemplate']['et_code'], ENT_QUOTES, "UTF-8"); }); // event template name shortcode $shortcodes->add('event_template_name', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_eventtemplate']['et_name'])) return ''; return htmlentities($GLOBALS['arlo_eventtemplate']['et_name'], ENT_QUOTES, "UTF-8"); }); // event template permalink shortcode $shortcodes->add('event_template_permalink', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_eventtemplate']['et_post_name'])) return ''; $region_link_suffix = ''; if (!empty($GLOBALS['arlo_eventtemplate']['et_region'])) { $arlo_region = $GLOBALS['arlo_eventtemplate']['et_region']; } else { $regions = get_option('arlo_regions'); $arlo_region = get_query_var('arlo-region', ''); $arlo_region = (!empty($arlo_region) && array_ikey_exists($arlo_region, $regions) ? $arlo_region : ''); } if (!empty($arlo_region)) { $region_link_suffix = 'region-' . $arlo_region . '/'; } $et_id = arlo_get_post_by_name($GLOBALS['arlo_eventtemplate']['et_post_name'], 'arlo_event'); return get_permalink($et_id) . $region_link_suffix; }); // event view uri shortcode $shortcodes->add('event_template_link', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_eventtemplate']['et_viewuri'])) return ''; return htmlentities($GLOBALS['arlo_eventtemplate']['et_viewuri'], ENT_QUOTES, "UTF-8"); }); // event template summary shortcode $shortcodes->add('event_template_summary', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_eventtemplate']['et_descriptionsummary'])) return ''; return $GLOBALS['arlo_eventtemplate']['et_descriptionsummary']; }); // content field shortcode $shortcodes->add('content_field_item', function($content='', $atts, $shortcode_name){ global $post, $wpdb, $arlo_plugin; $active = $arlo_plugin->get_import_id(); $regions = get_option('arlo_regions'); $arlo_region = get_query_var('arlo-region', ''); $arlo_region = (!empty($arlo_region) && array_ikey_exists($arlo_region, $regions) ? $arlo_region : ''); extract(shortcode_atts(array( 'fields' => 'all', ), $atts, $shortcode_name)); $where_fields = null; if (strtolower($fields) != 'all') { $where_fields = explode(',', $fields); $where_fields = array_map(function($field) { return '"' . trim($field) . '"'; }, $where_fields); } $t1 = "{$wpdb->prefix}arlo_eventtemplates"; $t2 = "{$wpdb->prefix}arlo_contentfields"; $sql = " SELECT $t2.cf_fieldname, $t2.cf_text FROM $t1 INNER JOIN $t2 ON $t1.et_id = $t2.et_id " . (!empty($arlo_region) ? " AND $t1.et_region = '" . $arlo_region . "'" : "" ) . " WHERE $t1.et_post_name = '$post->post_name' " . (is_array($where_fields) && count($where_fields) > 0 ? " AND cf_fieldname IN (" . implode(',', $where_fields) . ") " : "") . " AND $t1.active = $active AND $t2.active = $active ORDER BY $t2.cf_order"; $items = $wpdb->get_results($sql, ARRAY_A); $output = ''; foreach($items as $item) { $GLOBALS['arlo_content_field_item'] = $item; $output .= do_shortcode($content); unset($GLOBALS['arlo_content_field_item']); } return $output; }); // content field name shortcode $shortcodes->add('content_field_name', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_content_field_item']['cf_fieldname'])) return ''; return htmlentities($GLOBALS['arlo_content_field_item']['cf_fieldname'], ENT_QUOTES, "UTF-8"); }); // content field text shortcode $shortcodes->add('content_field_text', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_content_field_item']['cf_text'])) return ''; return wpautop($GLOBALS['arlo_content_field_item']['cf_text']); }); // event template filter shortcode $shortcodes->add('event_template_filters', function($content='', $atts, $shortcode_name){ global $post, $wpdb, $arlo_plugin; $active = $arlo_plugin->get_import_id(); extract(shortcode_atts(array( 'filters' => 'category,location,delivery', 'resettext' => __('Reset', $GLOBALS['arlo_plugin_slug']), 'buttonclass' => 'button' ), $atts, $shortcode_name)); $filters_array = explode(',',$filters); $settings = get_option('arlo_settings'); if (!empty($settings['post_types']['event']['posts_page'])) { $slug = get_post($settings['post_types']['event']['posts_page'])->post_name; } else { $slug = get_post($post)->post_name; } $filter_html = ''; return $filter_html; }); // event list item shortcode $shortcodes->add('event_list_item', function($content='', $atts, $shortcode_name){ global $post, $wpdb; $settings = get_option('arlo_settings'); $regions = get_option('arlo_regions'); $arlo_region = get_query_var('arlo-region', ''); $arlo_region = (!empty($arlo_region) && array_ikey_exists($arlo_region, $regions) ? $arlo_region : ''); $t1 = "{$wpdb->prefix}arlo_eventtemplates"; $t2 = "{$wpdb->prefix}arlo_events"; $t3 = "{$wpdb->prefix}arlo_venues"; $t4 = "{$wpdb->prefix}arlo_events_presenters"; $t5 = "{$wpdb->prefix}arlo_presenters"; $t6 = "{$wpdb->prefix}arlo_offers"; if (!empty($arlo_region)) { $where .= ' AND ' . $t1 . '.et_region = "' . $arlo_region . '" AND ' . $t2 . '.e_region = "' . $arlo_region . '"'; } $sql = "SELECT $t2.*, $t3.v_post_name FROM $t2 LEFT JOIN $t3 ON $t2.v_id = $t3.v_arlo_id LEFT JOIN $t1 ON $t2.et_arlo_id = $t1.et_arlo_id WHERE $t1.et_post_name = '$post->post_name' AND $t2.e_parent_arlo_id = 0 $where ORDER BY $t2.e_startdatetime"; $items = $wpdb->get_results($sql, ARRAY_A); $output = ''; if (is_array($items) && count($items)) { foreach($items as $key => $item) { $GLOBALS['arlo_event_list_item'] = $item; if (!empty($atts['show']) && $key == $atts['show']) { $output .= '' . $no_event_text . '
'; } return $output; }); // event code shortcode $shortcodes->add('event_code', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_event_list_item']['e_code'])) return ''; return htmlentities($GLOBALS['arlo_event_list_item']['e_code'], ENT_QUOTES, "UTF-8"); }); // event name shortcode $shortcodes->add('event_name', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_event_list_item']['e_name']) && !isset($GLOBALS['arlo_event_session_list_item']['e_code'])) return ''; $event = !empty($GLOBALS['arlo_event_session_list_item']) ? $GLOBALS['arlo_event_session_list_item'] : $GLOBALS['arlo_event_list_item']; return htmlentities($event['e_name'], ENT_QUOTES, "UTF-8"); }); // event location shortcode $shortcodes->add('event_location', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_event_list_item']['e_locationname']) && !isset($GLOBALS['arlo_event_session_list_item']['e_locationname'])) return ''; $event = !empty($GLOBALS['arlo_event_session_list_item']) ? $GLOBALS['arlo_event_session_list_item'] : $GLOBALS['arlo_event_list_item']; $location = htmlentities($event['e_locationname'], ENT_QUOTES, "UTF-8"); if($event['e_isonline'] || $event['v_id'] == 0 || $event['e_locationvisible'] == 0) { return $location; } else { $permalink = get_permalink(arlo_get_post_by_name($event['v_post_name'], 'arlo_venue')); return ''.$location.''; } }); // event start date shortcode $shortcodes->add('event_start_date', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_event_list_item']['e_startdatetime']) && !isset($GLOBALS['arlo_event_session_list_item']['e_startdatetime'])) return ''; $timezone = null; $event = !empty($GLOBALS['arlo_event_session_list_item']) ? $GLOBALS['arlo_event_session_list_item'] : $GLOBALS['arlo_event_list_item']; $timewithtz = str_replace(' ', 'T', $event['e_startdatetime']) . $event['e_datetimeoffset']; $start_date = new DateTime($timewithtz); if($event['e_isonline']) { if (!empty($GLOBALS['selected_timezone_olson_names']) && is_array($GLOBALS['selected_timezone_olson_names'])) { foreach ($GLOBALS['selected_timezone_olson_names'] as $TzName) { try { $timezone = new DateTimeZone($TzName->olson_name); } catch (Exception $e) { } if ($timezone !== null) { break; } } if (!is_null($timezone)) { $start_date->setTimezone($timezone); } } } $format = 'D g:i A'; if(isset($atts['format'])) $format = $atts['format']; //if we haven't got timezone, we need to append the timezone abbrev if ($event['e_isonline'] && is_null($timezone) && (preg_match('[G|g|i]', $format) === 1)) { $format .= " T"; } return $start_date->format($format); }); // event end date shortcode $shortcodes->add('event_end_date', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_event_list_item']['e_finishdatetime']) && !isset($GLOBALS['arlo_event_session_list_item']['e_finishdatetime'])) return ''; $event = !empty($GLOBALS['arlo_event_session_list_item']) ? $GLOBALS['arlo_event_session_list_item'] : $GLOBALS['arlo_event_list_item']; $timezone = null; $timewithtz = str_replace(' ','T',$event['e_finishdatetime']) . $event['e_datetimeoffset']; $end_date = new DateTime($timewithtz); if($event['e_isonline']) { if (!empty($GLOBALS['selected_timezone_olson_names']) && is_array($GLOBALS['selected_timezone_olson_names'])) { foreach ($GLOBALS['selected_timezone_olson_names'] as $TzName) { try { $timezone = new DateTimeZone($TzName->olson_name); } catch (Exception $e) { } if ($timezone !== null) { break; } } if (!is_null($timezone)) { $end_date->setTimezone($timezone); } } } $format = 'D g:i A'; if(isset($atts['format'])) $format = $atts['format']; //if we haven't got timezone, we need to append the timezone abbrev if ($event['e_isonline'] && is_null($timezone) && (preg_match('[G|g|i]', $format) === 1)) { $format .= " T"; } return $end_date->format($format); }); // event session description shortcode $shortcodes->add('event_session_description', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_event_list_item']['e_sessiondescription'])) return ''; return htmlentities($GLOBALS['arlo_event_list_item']['e_sessiondescription'], ENT_QUOTES, "UTF-8"); }); // event registration shortcode $shortcodes->add('event_registration', function($content='', $atts, $shortcode_name){ $isfull = $GLOBALS['arlo_event_list_item']['e_isfull']; $registeruri = $GLOBALS['arlo_event_list_item']['e_registeruri']; $registermessage = $GLOBALS['arlo_event_list_item']['e_registermessage']; $placesremaining = intval($GLOBALS['arlo_event_list_item']['e_placesremaining']); $class = (!empty($atts['class']) ? $atts['class'] : 'button' ); $registration = '' . $no_event_text . '
'; else : $previous = null; foreach($items as $item) { if(is_null($previous) || date('m',strtotime($item['e_startdatetime'])) != date('m',strtotime($previous['e_startdatetime']))) { $item['show_divider'] = date('F', strtotime($item['e_startdatetime'])); } $GLOBALS['arlo_event_list_item'] = $item; $GLOBALS['arlo_eventtemplate'] = $item; $output .= do_shortcode($content); unset($GLOBALS['arlo_event_list_item']); unset($GLOBALS['arlo_eventtemplate']); $previous = $item; } endif; return $output; }); // upcoming event offer shortcode $shortcodes->add('upcoming_offer', function($content='', $atts, $shortcode_name){ $settings = get_option('arlo_settings'); $price_setting = (isset($settings['price_setting'])) ? $settings['price_setting'] : ARLO_PLUGIN_PREFIX . '-exclgst'; $free_text = (isset($settings['free_text'])) ? $settings['free_text'] : __('Free', $GLOBALS['arlo_plugin_slug']); $amount = $price_setting == ARLO_PLUGIN_PREFIX . '-exclgst' ? $GLOBALS['arlo_event_list_item']['o_offeramounttaxexclusive'] : $GLOBALS['arlo_event_list_item']['o_offeramounttaxinclusive']; $famount = $price_setting == ARLO_PLUGIN_PREFIX . '-exclgst' ? $GLOBALS['arlo_event_list_item']['o_formattedamounttaxexclusive'] : $GLOBALS['arlo_event_list_item']['o_formattedamounttaxinclusive']; $tax = $GLOBALS['arlo_event_list_item']['o_taxrateshortcode']; $offer = ($amount > 0) ? '' . $famount .' '. ($price_setting == ARLO_PLUGIN_PREFIX . '-exclgst' ? sprintf(__(' excl. %s', $GLOBALS['arlo_plugin_slug']), $tax) : sprintf(__(' incl. %s', $GLOBALS['arlo_plugin_slug']), $tax)). '' : '' . htmlentities($free_text, ENT_QUOTES, "UTF-8") . ''; return $offer; }); // upcoming event filters $shortcodes->add('upcoming_event_filters', function($content='', $atts, $shortcode_name){ global $post, $wpdb, $arlo_plugin; $active = $arlo_plugin->get_import_id(); extract(shortcode_atts(array( 'filters' => 'category,month,location,delivery', 'resettext' => __('Reset', $GLOBALS['arlo_plugin_slug']), 'buttonclass' => 'button' ), $atts, $shortcode_name)); $filters_array = explode(',',$filters); $settings = get_option('arlo_settings'); if (!empty($settings['post_types']['upcoming']['posts_page'])) { $slug = str_replace(get_home_url(), "", get_page_link(get_post($settings['post_types']['upcoming']['posts_page'])->ID)); } else { $slug = str_replace(get_home_url(), "", get_page_link()); } $filter_html = '