getMethods(), function($method) { return strpos($method->name, 'shortcode_') === 0; }); foreach ($shortcodes as $shortcode) { $shortcode_name = str_replace('shortcode_', '', $shortcode->name); Shortcodes::add($shortcode_name, function($content = '', $atts, $shortcode_name, $import_id) { $method_name = 'shortcode_' . str_replace('arlo_', '', $shortcode_name); return self::$method_name($content, $atts, $shortcode_name, $import_id); }); } $custom_shortcodes = Shortcodes::get_custom_shortcodes(array('events','schedule','eventsearch')); foreach ($custom_shortcodes as $shortcode_name => $shortcode) { switch($shortcode["type"]) { case 'schedule': Shortcodes::add($shortcode_name, function($content = '', $atts, $shortcode_name, $import_id) { return self::shortcode_schedule($content = '', $atts, $shortcode_name, $import_id); }); break; case 'eventsearch': Shortcodes::add($shortcode_name, function($content = '', $atts, $shortcode_name, $import_id) { return self::shortcode_event_template_search_list($content = '', $atts, $shortcode_name, $import_id); }); break; default: Shortcodes::add($shortcode_name, function($content = '', $atts, $shortcode_name, $import_id) { return self::shortcode_event_template_list($content = '', $atts, $shortcode_name, $import_id); }); break; } } } private static function shortcode_suggest_templates($content = '', $atts = [], $shortcode_name = '', $import_id = '') { global $wpdb, $wp_query; if (empty($GLOBALS['arlo_eventtemplate']['et_arlo_id'])) return ''; $settings = get_option('arlo_settings'); $arlo_region = \Arlo_For_Wordpress::get_region_parameter(); $join = []; extract(shortcode_atts(array( 'limit' => 5, 'base' => 'category', 'tagprefix' => 'group_', 'onlyscheduled' => 'false', 'regionalized' => 'false' ), $atts, $shortcode_name, $import_id)); switch ($base) { case 'tag': //select the tag_id associated with the template and starts with the prefix $where = " t.tag_id IN (SELECT ett.tag_id FROM {$wpdb->prefix}arlo_eventtemplates_tags AS ett LEFT JOIN {$wpdb->prefix}arlo_tags AS t ON ett.tag_id = t.id AND t.import_id = " . $import_id . " WHERE t.tag LIKE '" . esc_sql($tagprefix) . "%' AND ett.import_id = " . $import_id . " AND ett.et_id = {$GLOBALS['arlo_eventtemplate']['et_id']} ) "; $join['t'] = " LEFT JOIN {$wpdb->prefix}arlo_eventtemplates_tags AS t ON t.et_id = et.et_id AND t.import_id = et.import_id "; break; default: //select the categories associated with the template $where = " c.c_arlo_id IN (SELECT ecc.c_arlo_id FROM {$wpdb->prefix}arlo_eventtemplates_categories AS ecc WHERE ecc.import_id = " . $import_id . " AND ecc.et_arlo_id = {$GLOBALS['arlo_eventtemplate']['et_arlo_id']} ) "; $join['c'] = " LEFT JOIN {$wpdb->prefix}arlo_eventtemplates_categories AS c ON et.et_arlo_id = c.et_arlo_id AND c.import_id = et.import_id "; break; } if ($onlyscheduled === "true") { $join['e'] = " INNER JOIN {$wpdb->prefix}arlo_events AS e ON e.et_arlo_id = et.et_arlo_id AND et.import_id = e.import_id "; } if (!empty($arlo_region) && $regionalized === "true") { $where .= ' AND et.et_region = "' . esc_sql($arlo_region) . '"'; } $sql = " SELECT et.et_id, et.et_region, et.et_arlo_id, et.et_code, et.et_name, et.et_descriptionsummary, et.et_post_name, et.et_post_id, et.et_registerinteresturi FROM {$wpdb->prefix}arlo_eventtemplates AS et " . implode("\n", $join) ." WHERE et.import_id = " . $import_id . " AND et.et_arlo_id != {$GLOBALS['arlo_eventtemplate']['et_arlo_id']} AND {$where} GROUP BY et.et_arlo_id ORDER BY RAND() LIMIT $limit"; $items = $wpdb->get_results($sql, ARRAY_A); $output = ''; if(!empty($items)) : foreach($items as $item) { $GLOBALS['arlo_eventtemplate'] = $item; $output .= do_shortcode($content); unset($GLOBALS['arlo_eventtemplate']); } endif; return $output; } private static function shortcode_content_field_name($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if(!isset($GLOBALS['arlo_content_field_item']['cf_fieldname'])) return ''; return htmlentities($GLOBALS['arlo_content_field_item']['cf_fieldname'], ENT_QUOTES, "UTF-8"); } private static function shortcode_content_field_text($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if(!isset($GLOBALS['arlo_content_field_item']['cf_text'])) return ''; return wpautop($GLOBALS['arlo_content_field_item']['cf_text']); } private static function shortcode_content_field_item($content = '', $atts = [], $shortcode_name = '', $import_id = '') { global $post, $wpdb; $arlo_region = \Arlo_For_Wordpress::get_region_parameter(); extract(shortcode_atts(array( 'fields' => 'all', ), $atts, $shortcode_name, $import_id)); $where_fields = null; if (strtolower($fields) != 'all') { $where_fields = explode(',', $fields); $where_fields = array_map(function($field) { return '"' . trim(esc_sql($field)) . '"'; }, $where_fields); } $t1 = "{$wpdb->prefix}arlo_eventtemplates"; $t2 = "{$wpdb->prefix}arlo_contentfields"; if (!empty($GLOBALS['arlo_event_list_item']['et_id'])) { $where = $t1 . ".et_id = " . $GLOBALS['arlo_event_list_item']['et_id']; } else { $where = $t1 . ".et_post_id = " . $post->ID; } $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 = '" . esc_sql($arlo_region) . "'" : "" ) . " WHERE " . $where . " " . (is_array($where_fields) && count($where_fields) > 0 ? " AND cf_fieldname IN (" . implode(',', $where_fields) . ") " : "") . " AND $t1.import_id = $import_id AND $t2.import_id = $import_id 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; } private static function shortcode_event_template_list($content = '', $atts = [], $shortcode_name = '', $import_id = '') { $template_name = Shortcodes::get_template_name($shortcode_name,'event_template_list','events'); return self::template_list_initializer($content, $atts, $shortcode_name, $import_id, $template_name); } private static function shortcode_schedule($content = '', $atts = [], $shortcode_name = '', $import_id = '') { $template_name = Shortcodes::get_template_name($shortcode_name,'schedule','schedule'); return self::template_list_initializer($content, $atts, $shortcode_name, $import_id, $template_name); } private static function template_list_initializer($content = '', $atts = [], $shortcode_name = '', $import_id = '', $template_name) { if (get_option('arlo_plugin_disabled', '0') == '1') return; $filter_settings = get_option('arlo_page_filter_settings', []); $templates = arlo_get_option('templates'); $content = $templates[$template_name]['html']; self::$event_template_atts = self::get_event_template_atts($atts, $import_id); \Arlo\Utilities::set_base_filter($template_name, 'category', $filter_settings, $atts, self::$event_template_atts, '\Arlo\Utilities::convert_string_to_int_array'); \Arlo\Utilities::set_base_filter($template_name, 'category', $filter_settings, $atts, self::$event_template_atts, '\Arlo\Utilities::convert_string_to_int_array', null, true); \Arlo\Utilities::set_base_filter($template_name, 'templatetag', $filter_settings, $atts, self::$event_template_atts, '\Arlo\Entities\Tags::get_tag_ids_by_tag', [$import_id]); \Arlo\Utilities::set_base_filter($template_name, 'templatetag', $filter_settings, $atts, self::$event_template_atts, '\Arlo\Entities\Tags::get_tag_ids_by_tag', [$import_id], true); \Arlo\Utilities::set_base_filter($template_name, 'delivery', $filter_settings, $atts, self::$event_template_atts, '\Arlo\Utilities::convert_string_to_int_array'); \Arlo\Utilities::set_base_filter($template_name, 'delivery', $filter_settings, $atts, self::$event_template_atts, '\Arlo\Utilities::convert_string_to_int_array', null, true); \Arlo\Utilities::set_base_filter($template_name, 'location', $filter_settings, $atts, self::$event_template_atts, '\Arlo\Utilities::convert_string_to_string_array'); \Arlo\Utilities::set_base_filter($template_name, 'location', $filter_settings, $atts, self::$event_template_atts, '\Arlo\Utilities::convert_string_to_string_array', null, true); return $content; } private static function shortcode_event_template_search_list ($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if (get_option('arlo_plugin_disabled', '0') == '1') return; $templates = arlo_get_option('templates'); $content = $templates['eventsearch']['html']; self::$event_template_atts = self::get_event_template_atts($atts, $import_id); return $content; } private static function get_event_template_atts($atts, $import_id) { $new_atts = []; $templatetag = \Arlo\Entities\Tags::get_tag_ids_by_tag(\Arlo\Utilities::get_att_string('templatetag', $atts), $import_id); $new_atts = \Arlo\Utilities::process_att($new_atts, '\Arlo\Utilities::get_att_string', 'location', $atts); $new_atts = \Arlo\Utilities::process_att($new_atts, '\Arlo\Utilities::get_att_string', 'locationhidden', $atts); $new_atts = \Arlo\Utilities::process_att($new_atts, '\Arlo\Utilities::get_att_string', 'category', $atts); $new_atts = \Arlo\Utilities::process_att($new_atts, '\Arlo\Utilities::get_att_string', 'categoryhidden', $atts); $new_atts = \Arlo\Utilities::process_att($new_atts, '\Arlo\Utilities::get_att_string', 'search', $atts); $new_atts = \Arlo\Utilities::process_att($new_atts, '\Arlo\Utilities::get_att_int', 'delivery', $atts); $new_atts = \Arlo\Utilities::process_att($new_atts, '\Arlo\Utilities::get_att_int', 'deliveryhidden', $atts); $new_atts = \Arlo\Utilities::process_att($new_atts, null, 'templatetag', $atts, $templatetag); $new_atts = \Arlo\Utilities::process_att($new_atts, '\Arlo\Utilities::get_att_string', 'state', $atts); $new_atts = \Arlo\Utilities::process_att($new_atts, '\Arlo_For_Wordpress::get_region_parameter', 'region'); return $new_atts; } private static function shortcode_event_template_list_pagination($content = '', $atts = [], $shortcode_name = '', $import_id = '') { global $wpdb; if (isset($GLOBALS['show_only_at_bottom']) && $GLOBALS['show_only_at_bottom']) return; $atts['limit'] = intval(isset(self::$event_template_atts['limit']) ? self::$event_template_atts['limit'] : isset($atts['limit']) && is_numeric($atts['limit']) ? $atts['limit'] : get_option('posts_per_page')); $atts = array_merge($atts,self::$event_template_atts); $sql = self::generate_list_sql($atts, $import_id, true); $items = $wpdb->get_results($sql, ARRAY_A); $num = $wpdb->num_rows; return arlo_pagination($num, $atts['limit']); } private static function shortcode_schedule_pagination($content = '', $atts = [], $shortcode_name = '', $import_id = '') { global $wpdb; if (isset($GLOBALS['show_only_at_bottom']) && $GLOBALS['show_only_at_bottom']) return; $atts['limit'] = intval(isset(self::$event_template_atts['limit']) ? self::$event_template_atts['limit'] : isset($atts['limit']) && is_numeric($atts['limit']) ? $atts['limit'] : get_option('posts_per_page')); $atts = array_merge($atts, self::$event_template_atts); $sql = self::generate_list_sql($atts, $import_id, true); $items = $wpdb->get_results($sql, ARRAY_A); $num = $wpdb->num_rows; return arlo_pagination($num, $atts['limit']); } private static function shortcode_event_template_list_item($content = '', $atts = [], $shortcode_name = '', $import_id = '') { global $wpdb; if (!empty($atts['limit'])) { self::$event_template_atts['limit'] = $atts['limit']; } $settings = get_option('arlo_settings'); $output = ''; if (empty($atts)) { $atts = []; } $atts = array_merge($atts, self::$event_template_atts); $sql = self::generate_list_sql($atts, $import_id); $items = $wpdb->get_results($sql, ARRAY_A); if(empty($items)) : if (!(isset($atts['show_only_at_bottom']) && $atts['show_only_at_bottom'] == "true" && isset($GLOBALS['arlo_categories_count']) && $GLOBALS['arlo_categories_count'])) : $GLOBALS['no_event_text'] = !empty($settings['noevent_text']) ? $settings['noevent_text'] : __('No events to show', 'arlo-for-wordpress'); endif; else : $output = $GLOBALS['no_event_text'] = ''; $previous = null; $snippet_list_items = array(); foreach($items as $key => $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) || strtolower(mb_substr($item['et_name'], 0, 1)) != strtolower(mb_substr($previous['et_name'], 0, 1))) { $item['show_divider'] = mb_substr($item['et_name'], 0, 1); } break; } } $GLOBALS['arlo_eventtemplate'] = $item; $GLOBALS['arlo_event_list_item'] = $item; $output .= do_shortcode($content); $list_item_snippet = array(); $list_item_snippet['@type'] = 'ListItem'; $list_item_snippet['position'] = $key + 1; $list_item_snippet['url'] = $item['et_viewuri']; array_push($snippet_list_items,$list_item_snippet); unset($GLOBALS['arlo_eventtemplate']); unset($GLOBALS['arlo_event_list_item']); $previous = $item; } $item_list = array(); $item_list['@type'] = 'ItemList'; $item_list['itemListElement'] = $snippet_list_items; $output .= Shortcodes::create_rich_snippet( json_encode($item_list) ); endif; return $output; } private static function shortcode_event_template_tags($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if(!isset($GLOBALS['arlo_eventtemplate']['et_arlo_id'])) return ''; global $wpdb; $output = ''; $tags = []; // merge and extract attributes extract(shortcode_atts(array( 'layout' => '', 'prefix' => 'arlo-', ), $atts, $shortcode_name, $import_id)); $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_id = {$GLOBALS['arlo_eventtemplate']['et_id']} AND t.import_id = " . $import_id . " AND ett.import_id = " . $import_id . " ", 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; } private static function shortcode_event_template_register_interest($content = '', $atts = [], $shortcode_name = '', $import_id = '') { $settings = get_option('arlo_settings'); $output = ''; if (!empty($GLOBALS['no_event']) && !empty($GLOBALS['no_onlineactivity'])) { $no_event_text = ''; if (!empty($GLOBALS['arlo_eventtemplate']['et_registerinteresturi'])) { $no_event_text = !empty($settings['noeventontemplate_text']) ? $settings['noeventontemplate_text'] : __('Interested in attending? Have a suggestion about running this event near you?', 'arlo-for-wordpress'); $no_event_text .= '' . $no_event_text . '
'; } return $output; } private static function shortcode_event_template_register_private_interest($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if (empty($GLOBALS['no_event']) || empty($GLOBALS['arlo_eventtemplate']['et_registerprivateinteresturi'])) return; // merge and extract attributes extract(shortcode_atts(array( 'text' => __('Want to run this event in-house? %s Enquire about running this event in-house %s', 'arlo-for-wordpress') ), $atts, $shortcode_name, $import_id)); $link = Shortcodes::build_custom_link($text, $GLOBALS['arlo_eventtemplate']['et_registerprivateinteresturi'], 'arlo-register-private-interest-link'); $output = '' . $link . '
'; return $output; } private static function shortcode_event_template_code($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if(!isset($GLOBALS['arlo_eventtemplate']['et_code'])) return ''; return htmlentities($GLOBALS['arlo_eventtemplate']['et_code'], ENT_QUOTES, "UTF-8"); } private static function shortcode_event_template_name($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if(!isset($GLOBALS['arlo_eventtemplate']['et_name'])) return ''; return htmlentities($GLOBALS['arlo_eventtemplate']['et_name'], ENT_QUOTES, "UTF-8"); } private static function shortcode_event_template_permalink($content = '', $atts = [], $shortcode_name = '', $import_id = '') { return Shortcodes::get_template_permalink($GLOBALS['arlo_eventtemplate']['et_post_name'], $GLOBALS['arlo_eventtemplate']['et_region']); } private static function shortcode_event_template_link($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if(!isset($GLOBALS['arlo_eventtemplate']['et_viewuri'])) return ''; return htmlentities($GLOBALS['arlo_eventtemplate']['et_viewuri'], ENT_QUOTES, "UTF-8"); } private static function shortcode_event_template_summary($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if(!isset($GLOBALS['arlo_eventtemplate']['et_descriptionsummary'])) return ''; return esc_html($GLOBALS['arlo_eventtemplate']['et_descriptionsummary']); } private static function shortcode_event_template_advertised_duration($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if(!isset($GLOBALS['arlo_eventtemplate']['et_advertised_duration'])) return ''; return esc_html($GLOBALS['arlo_eventtemplate']['et_advertised_duration']); } private static function shortcode_event_template_advertised_price($content = '', $atts = [], $shortcode_name = '', $import_id = '') { global $wpdb; if (empty($GLOBALS['arlo_eventtemplate']['et_arlo_id'])) return; extract(shortcode_atts(array( 'showfrom' => 'true', 'showtaxsuffix' => 'true' ), $atts, $shortcode_name, $import_id)); $arlo_region = \Arlo_For_Wordpress::get_region_parameter(); $sql = self::generate_bestoffer_list_sql($GLOBALS['arlo_eventtemplate']['et_arlo_id'], $arlo_region, 2, $import_id); $offers = $wpdb->get_results($sql, OBJECT); if (empty($offers)) return; $offer = $offers[0]; if (empty($offer)) return; //price setting and free text $settings = get_option('arlo_settings'); $free_text = (isset($settings['free_text'])) ? $settings['free_text'] : __('Free', 'arlo-for-wordpress'); $exclgst = (isset($settings['price_setting']) && $settings['price_setting'] === ARLO_PLUGIN_PREFIX . '-exclgst'); if ($offer->o_offeramounttaxexclusive == 0) { return esc_html($free_text); } $fromtext = ''; if (strtolower($showfrom) === "true" && count($offers) > 1) { $fromtext = __('From', 'arlo-for-wordpress') . ' '; } $taxsuffix = ''; if (strtolower($showtaxsuffix) === "true" && !$offer->e_is_taxexempt) { if ($exclgst) { $taxsuffix = ' ' . sprintf(__('excl. %s', 'arlo-for-wordpress'), $offer->o_taxrateshortcode); } else { $taxsuffix = ' ' . sprintf(__('incl. %s', 'arlo-for-wordpress'), $offer->o_taxrateshortcode); } } $formattedprice = ($exclgst || $offer->e_is_taxexempt ? $offer->o_formattedamounttaxexclusive : $offer->o_formattedamounttaxinclusive); return esc_html($fromtext . $formattedprice . $taxsuffix); } private static function shortcode_event_template_advertised_presenters($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if (empty($GLOBALS['arlo_eventtemplate']['et_arlo_id'])) return; $presenters = PresentersEntity::get(['template_id' => $GLOBALS['arlo_eventtemplate']['et_arlo_id']], null, null, $import_id); if (empty($presenters)) return; $presenters_fullnames = array_map(function($presenter) { return $presenter['p_firstname'] . ' ' . $presenter['p_lastname']; }, $presenters); //one presenter occurrence per region (p_viewuri) - we would need a region on presenter too $presenters_fullnames = array_unique($presenters_fullnames); $output = implode(', ', $presenters_fullnames); return esc_html($output); } private static function shortcode_event_template_credits($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if (empty($GLOBALS['arlo_eventtemplate']['et_credits'])) return; // merge and extract attributes extract(shortcode_atts(array( 'layout' => 'list', 'text' => '{%label%}: {%points%}' ), $atts, $shortcode_name, $import_id)); $credits = json_decode($GLOBALS['arlo_eventtemplate']['et_credits']); if (empty($credits) || !is_array($credits)) return; $output = ''; switch ($layout) { default: $output .= '' . $link . '
'; return $output; } private static function shortcode_template_region_selector ($content = '', $atts = [], $shortcode_name = '', $import_id = '') { return Shortcodes::create_region_selector("event"); } private static function shortcode_template_search_region_selector ($content = '', $atts = [], $shortcode_name = '', $import_id = '') { return Shortcodes::create_region_selector("eventsearch"); } private static function shortcode_event_template_rich_snippet($content = '', $atts = [], $shortcode_name = '', $import_id = '') { $et_snippet = self::get_rich_snippet_data($atts,$import_id,$shortcode_name); return Shortcodes::create_rich_snippet( json_encode($et_snippet) ); } private static function get_rich_snippet_data($atts,$import_id,$shortcode_name) { extract(shortcode_atts(array( 'link' => 'permalink' ), $atts, $shortcode_name, $import_id)); $event_template_snippet = array(); if (isset($GLOBALS["arlo_eventtemplate"])) { $event_template_snippet['@context'] = 'http://schema.org'; $event_template_snippet['@type'] = 'Course'; $event_template_snippet['name'] = Shortcodes::get_rich_snippet_field($GLOBALS['arlo_eventtemplate'],'et_name'); $et_link = ''; switch ($link) { case 'viewuri': $et_link = Shortcodes::get_rich_snippet_field($GLOBALS['arlo_eventtemplate'],'et_viewuri'); break; default: $et_link = Shortcodes::get_template_permalink($GLOBALS['arlo_eventtemplate']['et_post_name'], $GLOBALS['arlo_eventtemplate']['et_region']); break; } $et_link = \Arlo\Utilities::get_absolute_url($et_link); $event_template_snippet['url'] = $et_link; $event_template_snippet['description'] = Shortcodes::get_rich_snippet_field($GLOBALS['arlo_eventtemplate'],'et_descriptionsummary'); return $event_template_snippet; } else { return ''; } } private static function shortcode_event_template_hero_image($content = '', $atts = [], $shortcode_name = '', $import_id = '') { if (empty($GLOBALS['arlo_eventtemplate']['et_hero_image'])) return; $url = $GLOBALS['arlo_eventtemplate']['et_hero_image']; $filename = basename($url); return '