' . sprintf(__('Powered by %s', 'arlo-for-wordpress'), '
') . '';
});
}
/*
public static function autoload_shortcodes($class_name) {
$class = new \ReflectionClass("\Arlo\Shortcodes\\" . $class_name);
$methods = $class->getMethods();
foreach ($methods as $method) {
if (strpos( $method->name, 'shortcode_' ) === 0) {
$shortcode_name = str_replace('shortcode_', '', $method->name);
$method_name_with_classname = $method->class . '::' . $method->name;
self::add($shortcode_name, function($content = '', $atts, $shortcode_name, $import_id, $method_name_with_classname = '') {
//return $method_name_with_classname($content, $atts, $shortcode_name, $import_id);
}, $method_name_with_classname);
}
}
}
*/
public static function add() {
$args = func_get_args();
if(is_array($args[0])) {
$options = $args[0];
$name = $options['name'];
$function = $options['function'];
} else {
$name = $args[0];
$function = $args[1];
}
$shortcode_name = 'arlo_' . $name;
// add the shortcode
add_shortcode($shortcode_name, array('\Arlo\Shortcodes\Shortcodes', 'the_shortcode'));
$closure = new \ReflectionFunction($function);
// assign the passed function to a filter
// all shortcodes are run through filters to allow external manipulation if required, however we also need a means of running the passed function
add_filter('arlo_shortcode_content_' . $shortcode_name, function($content='', $atts, $shortcode_name, $import_id='') use($closure) {
$plugin = Arlo_For_Wordpress::get_instance();
$import_id = $plugin->get_importer()->get_current_import_id();
if (!empty($import_id))
return $closure->invokeArgs(array($content, $atts, $shortcode_name, $import_id, ''));
}, 10, 3);
}
public static function the_shortcode($atts, $content="", $shortcode_name = '') {
// merge and extract attributes
extract(shortcode_atts(array(
'wrap' => '%s',
'label' => '',
'strip_html' => 'false',
'decode_quotes_in_shortcodes' => 'false',
), $atts, $shortcode_name));
// need to decide ordering - currently makes sense to process the specific filter first
$content = apply_filters('arlo_shortcode_content_'.$shortcode_name, $content, $atts, $shortcode_name);
$content = apply_filters('arlo_shortcode_content', $content, $atts, $shortcode_name);
if ($decode_quotes_in_shortcodes === 'true') {
if (preg_match('/\[(?:[^\/])(?:[^\]\[]*)(?:"|')(?:[^\]\[]*)\]/', $content) === 1) {
$content = str_replace(['"','''], ['"','\''], $content);
}
}
// run any shortcodes prior to conituning
$content = do_shortcode($content);
// if not empty, process labels and wrapping
if(trim($content) != '') {
//strip html, if neccessary
if ($strip_html !== 'false') {
if ($strip_html == 'true') {
$content = strip_tags($content);
} else {
$content = strip_tags($content, $strip_html);
}
}
// prepend label
if (!empty($label)) {
$content = ' ' . $content;
}
// wrap content
$content = sprintf($wrap, $content);
}
return do_shortcode($content);
}
public static function create_region_selector($page_name) {
global $post;
$valid_page_names = ['upcoming', 'event', 'eventsearch', 'widget'];
$settings = get_option('arlo_settings');
$regions = get_option('arlo_regions');
if (!in_array($page_name, $valid_page_names) || !(is_array($regions) && count($regions))) return "";
return self::create_filter('region', $regions, null, null, \Arlo_For_Wordpress::get_region_parameter());
}
public static function create_filter($type, $items, $label, $group, $att_default=null, $page = '') {
if (count($items) == 0 || !is_array($items)) {
return '';
}
$filter_settings = get_option('arlo_filter_settings', []);
$page_filter_settings = get_option('arlo_page_filter_settings', []);
if (!empty($filter_settings[$group][$type][$label]) ) {
$label = $filter_settings[$group][$type][$label];
}
$urlParameter = \Arlo\Utilities::clean_string_url_parameter('arlo-' . $type);
$selected_value = !empty($urlParameter) || $urlParameter == "0" ? $urlParameter : (!empty($att_default) || $att_default == "0" ? $att_default : '');
$options_html = '';
foreach($items as $key => $item) {
if (empty($item['string']) && empty($item['value'])) {
$item = array(
'string' => $item,
'value' => $key,
'id' => $key
);
}
if (!isset($item['id'])) {
$item['id'] = $item['value'];
}
$option_label = '';
if (!empty($filter_settings[$group][$type][$item['id']])) {
$option_label = $filter_settings[$group][$type][$item['id']];
}
else if (!empty($filter_settings[$group][$type][$item['string']])) {
$option_label = $filter_settings[$group][$type][$item['string']];
}
$is_hidden = false;
if (!empty($filter_settings['hiddenfilters'][$group][$type])) {
$is_hidden = in_array($item['id'], $filter_settings['hiddenfilters'][$group][$type]);
}
if (!empty($page_filter_settings['hiddenfilters'][$page][$type])) {
$is_hidden = in_array($item['id'], $page_filter_settings['hiddenfilters'][$page][$type]);
}
$show_only = true;
if (!empty($page_filter_settings['showonlyfilters'][$page][$type])) {
$show_only = in_array($item['id'], $page_filter_settings['showonlyfilters'][$page][$type]);
}
if (!$is_hidden && $show_only) {
$option_label = !empty($option_label) ? $option_label : $item['string'];
$selected = (strlen($selected_value) && strtolower($selected_value) == strtolower($item['value'])) ? ' selected="selected"' : '';
$options_html .= '';
}
}
if (strlen($options_html) == 0) {
return '';
}
$filter_html = '';
return $filter_html;
}
public static function create_rich_snippet($content) {
return '';
}
public static function get_performer($presenter, $link) {
$performer = array("@type" => "Person");
$name_separator = (!empty($presenter["p_firstname"]) && !empty($presenter["p_lastname"]) ? " " : "");
$performer["name"] = $presenter["p_firstname"] . $name_separator . $presenter["p_lastname"];
$p_link = '';
switch ($link) {
case 'viewuri':
$p_link = self::get_rich_snippet_field($presenter,"p_viewuri");
break;
default:
$p_post_id = empty($presenter['post_id']) ? $presenter['p_post_id'] : $presenter['post_id'];
$p_link = get_permalink($p_post_id);
break;
}
$p_link = \Arlo\Utilities::get_absolute_url($p_link);
$performer["url"] = $p_link;
if (!empty($presenter["p_profile"])) {
$performer["description"] = strip_tags( $presenter["p_profile"] );
}
$same_as = array();
if (!empty($presenter["p_twitterid"])) {
array_push($same_as,"https://www.twitter.com/".$presenter["p_twitterid"]);
}
if (!empty($presenter["p_facebookid"])) {
array_push($same_as,"https://www.facebook.com/".$presenter["p_facebookid"]);
}
if (!empty($presenter["p_linkedinid"])) {
array_push($same_as,"https://www.linkedin.com/".$presenter["p_linkedinid"]);
}
if (!empty($same_as)) {
$performer["sameAs"] = $same_as;
}
return $performer;
}
private static function shortcode_search_field($content = '', $atts = [], $shortcode_name = '', $import_id = '') {
global $post, $wpdb;
extract(shortcode_atts(array(
'showbutton' => "true",
'buttonclass' => '',
'inputclass' => '',
'placeholder' => __('Search for an event', 'arlo-for-wordpress'),
'buttontext' => __('Search', 'arlo-for-wordpress'),
), $atts, $shortcode_name, $import_id));
$settings = get_option('arlo_settings');
if (!empty($settings['post_types']['eventsearch']['posts_page'])) {
$slug = get_post($settings['post_types']['eventsearch']['posts_page'])->post_name;
$search_term = \Arlo\Utilities::clean_string_url_parameter('arlo-search');
return '
';
}
}
private static function shortcode_timezones($content = '', $atts = [], $shortcode_name = '', $import_id = '') {
global $post, $wpdb;
$arlo_region = \Arlo_For_Wordpress::get_region_parameter();
// eventtemplate page using Post ID
if($post->post_type === 'arlo_event') {
// find out if we have any online events
$t1 = "{$wpdb->prefix}arlo_eventtemplates";
$t2 = "{$wpdb->prefix}arlo_events";
$items = $wpdb->get_results("
SELECT
$t2.e_isonline,
$t2.e_timezone_id
FROM
$t2
LEFT JOIN
$t1
ON
$t2.et_arlo_id = $t1.et_arlo_id
AND
$t2.e_isonline = 1
AND
$t2.e_parent_arlo_id = 0
AND
$t1.import_id = $t2.import_id
WHERE
$t1.et_post_id = $post->ID
AND
$t2.import_id = $import_id
" . (empty($arlo_region) ? "" : " AND $t2.e_region = '" . esc_sql($arlo_region) . "'") . "
", ARRAY_A);
}
else {
$t1 = "{$wpdb->prefix}arlo_events";
$items = $wpdb->get_results("
SELECT
$t1.e_isonline,
$t1.e_timezone_id
FROM
$t1
WHERE
$t1.e_isonline = 1
AND
$t1.e_parent_arlo_id = 0
AND
$t1.import_id = $import_id
" . (empty($arlo_region) ? "" : " AND $t1.e_region = '" . esc_sql($arlo_region) . "'") . "
", ARRAY_A);
}
if(empty($items)) {
return '';
}
$content = '';
return $content;
}
public static function get_advertised_offers($id, $id_field, $import_id) {
global $wpdb;
$arlo_region = \Arlo_For_Wordpress::get_region_parameter();
$cache_key = md5( serialize( array( $id => $id_field ) ) );
$cache_category = 'ArloOffers';
if($cached = wp_cache_get($cache_key, $cache_category)) {
return $cached;
}
$sql = "
SELECT
offer.*,
replaced_by.o_label AS replacement_label,
replaced_by.o_isdiscountoffer AS replacement_discount,
replaced_by.o_currencycode AS replacement_currency_code,
replaced_by.o_formattedamounttaxexclusive AS replacement_formatted_amount_taxexclusive,
replaced_by.o_formattedamounttaxinclusive AS replacement_formatted_amount_taxinclusive,
replaced_by.o_message AS replacement_message,
replaced_by.o_offeramounttaxexclusive AS replacement_amount_taxexclusive,
replaced_by.o_offeramounttaxinclusive AS replacement_amount_taxinclusive
FROM
{$wpdb->prefix}arlo_offers AS offer
LEFT JOIN
{$wpdb->prefix}arlo_offers AS replaced_by
ON
offer.o_arlo_id = replaced_by.o_replaces
AND
offer.import_id = replaced_by.import_id
AND
offer.$id_field = replaced_by.$id_field
" . (!empty($arlo_region) ? " AND replaced_by.o_region = '" . esc_sql($arlo_region) . "'" : "") . "
WHERE
offer.o_replaces = 0
AND
offer.import_id = $import_id
AND
offer.$id_field = $id
" . (!empty($arlo_region) ? " AND offer.o_region = '" . esc_sql($arlo_region) . "'" : "") . "
ORDER BY
offer.o_order";
$offers = $wpdb->get_results($sql, ARRAY_A);
wp_cache_add( $cache_key, $offers, $cache_category, 30 );
return $offers;
}
public static function get_offers_snippet_data($id, $id_field, $import_id, $price_field) {
$offers_array = self::get_advertised_offers($id, $id_field, $import_id);
$high_price = 0;
$low_price = 0;
$currency = "";
foreach ($offers_array as $offer) {
$replacement_price_field = strpos('inclusive',$price_field) !== false ? "replacement_amount_taxinclusive" : "replacement_amount_taxexclusive" ;
$low_price = ( $offer[$price_field] < $low_price || $low_price == 0 ? $offer[$price_field] : $low_price );
$high_price = ( $offer[$price_field] > $high_price || $high_price == 0 ? $offer[$price_field] : $high_price );
if ( array_key_exists($replacement_price_field, $offer) && !empty($offer[$replacement_price_field]) ) {
$low_price = ( $offer[$replacement_price_field] < $low_price ? $offer[$replacement_price_field] : $low_price );
$high_price = ( $offer[$replacement_price_field] > $high_price ? $offer[$replacement_price_field] : $high_price );
}
$currency = $offer['o_currencycode'];
}
return array(
'high_price' => $high_price,
'low_price' => $low_price,
'currency' => $currency
);
}
public static function advertised_offers($id, $id_field, $import_id, $is_tax_exempt = false) {
global $wpdb;
$regions = get_option('arlo_regions');
$arlo_region = get_query_var('arlo-region', '');
$arlo_region = (!empty($arlo_region) && is_array($regions) && \Arlo\Utilities::array_ikey_exists($arlo_region, $regions) ? $arlo_region : '');
$t1 = "{$wpdb->prefix}arlo_offers";
$offers_array = self::get_advertised_offers($id, $id_field, $import_id);
$offers = '';
$settings = get_option('arlo_settings');
$price_setting = (isset($settings['price_setting']) && $is_tax_exempt != true ? esc_attr($settings['price_setting']) : ARLO_PLUGIN_PREFIX . '-exclgst');
$free_text = (isset($settings['free_text']) ? esc_attr($settings['free_text']) : __('Free', 'arlo-for-wordpress'));
if (empty($offers_array)) { return ''; }
foreach($offers_array as $offer) {
extract($offer);
$amount = $price_setting == ARLO_PLUGIN_PREFIX . '-exclgst' ? $o_offeramounttaxexclusive : $o_offeramounttaxinclusive;
$famount = $price_setting == ARLO_PLUGIN_PREFIX . '-exclgst' ? $o_formattedamounttaxexclusive : $o_formattedamounttaxinclusive;
// set to true if there is a replacement offer returned for this event offer
$replaced = (!empty($replacement_formatted_amount_taxexclusive) && !empty($replacement_formatted_amount_taxinclusive));
$offers .= '- 0) {
$offers .= '' . esc_html($famount) . ' ';
// only include the excl. tax if the offer is not replaced and not tax exempt
$offers .= $replaced ? '' : (!$is_tax_exempt ? '' . esc_html(($price_setting == ARLO_PLUGIN_PREFIX . '-exclgst' ? sprintf(__('excl. %s', 'arlo-for-wordpress'), $o_taxrateshortcode) : sprintf(__('incl. %s', 'arlo-for-wordpress'), $o_taxrateshortcode))) . '' : '');
} else {
$offers .= '' . esc_html($free_text) . ' ';
}
// display message if there is one
$offers .= (!is_null($o_message) || $o_message != '') ? ' ' . esc_html($o_message) : '';
// if a replacement offer exists
if($replaced) {
$offers .= '';
// display replacement offer label if there is one
$offers .= (!is_null($replacement_label) || $replacement_label != '') ? esc_html($replacement_label) . ' ' : '';
$offers .= '' . ($price_setting == ARLO_PLUGIN_PREFIX . '-exclgst' ? $replacement_formatted_amount_taxexclusive : $replacement_formatted_amount_taxinclusive) . '';
if (!$is_tax_exempt) {
$offers.= '' . esc_html(($price_setting == ARLO_PLUGIN_PREFIX . '-exclgst' ? sprintf(__('excl. %s', 'arlo-for-wordpress'), $o_taxrateshortcode) : sprintf(__('incl. %s', 'arlo-for-wordpress'), $o_taxrateshortcode))) . '';
}
// display replacement offer message if there is one
$offers .= (!is_null($replacement_message) || $replacement_message != '') ? ' ' . esc_html($replacement_message) : '';
} // end if
$offers .= '
';
} // end foreach
$offers .= '
';
return $offers;
}
public static function get_rich_snippet_field($event, $field) {
if (!empty($event)) {
return array_key_exists($field, $event) ? ( !empty($event[$field]) ? $event[$field] : '' ) : '';
}
}
public static function get_template_permalink($post_name, $region) {
if(!isset($post_name)) return '';
$region_link_suffix = '';
$regions = get_option('arlo_regions');
if (!empty($region) && is_array($regions) && count($regions)) {
$arlo_region = $region;
} else {
$arlo_region = get_query_var('arlo-region', '');
$arlo_region = (!empty($arlo_region) && is_array($regions) && \Arlo\Utilities::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($post_name, 'arlo_event');
return get_permalink($et_id) . $region_link_suffix;
}
public static function get_custom_shortcodes($type) {
$shortcodes = array();
foreach(\Arlo_For_Wordpress::$templates as $shortcode_name => $shortcode) {
if ( isset($shortcode["type"]) ) {
if (is_string($type) && $shortcode["type"] == $type ) {
$shortcodes[$shortcode_name] = $shortcode;
} else if (is_array($type) && in_array($shortcode["type"], $type)) {
$shortcodes[$shortcode_name] = $shortcode;
}
}
}
return $shortcodes;
}
public static function get_template_name($shortcode_name,$default_shortcode_name,$default_template_name) {
$shortcode_name_root = str_replace('arlo_', '', $shortcode_name);
return $shortcode_name_root != $default_shortcode_name ? $shortcode_name_root : $default_template_name;
}
public static function build_custom_link($text, $url, $cssclass) {
$link = '';
$open = sprintf('', esc_url($url), esc_attr($cssclass));
$close = '';
// Allow syntax: "Before link and %s link itself %s"
if (strpos($text, '%s')) {
$parts = explode('%s', esc_html($text));
$parts[1] = $open . $parts[1] . $close;
$link = implode('', $parts);
} else {
$link = $open . esc_html($text) . $close;
}
return $link;
}
}