get_plugin_slug(); /* * Add event category to title when filtered by a category */ add_filter( 'the_title', function($title, $id = null){ $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']['event']['posts_page']); } if (!empty($settings['post_types']['upcoming']['posts_page'])) { array_push($pages, $settings['post_types']['event']['posts_page']); } $subtitle = ''; $cat_slug = !empty($_GET['arlo-category']) ? $_GET['arlo-category'] : ''; $cat = \Arlo\Categories::get(array('slug' => $cat_slug)); $location = !empty($_GET['arlo-location']) ? stripslashes(urldecode($_GET['arlo-location'])) : ""; $search = !empty($_GET['arlo-search']) ? stripslashes(urldecode($_GET['arlo-search'])) : ""; if($id === null || !in_array($id, $pages)) 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 = $location; } else if (!empty($search)) { $subtitle = $search; } // append category name to events page if (!empty($subtitle)) { $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'))) { $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_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) { if(is_null($label)) $label = $type; $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 . '/page/([^/]*)/?','index.php?page_id=' . $page_id . '&paged=$matches[1]','top'); break; case 'event': add_rewrite_rule('^' . $slug . '/page/([^/]*)/?','index.php?page_id=' . $page_id . '&paged=$matches[1]','top'); break; case 'eventsearch': add_rewrite_rule('^' . $slug . '/page/([^/]*)/?','index.php?page_id=' . $page_id . '&paged=$matches[1]','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('%category%', '([^&]+)'); add_rewrite_tag('%month%', '([^&]+)'); add_rewrite_tag('%location%', '([^&]+)'); add_rewrite_tag('%delivery%', '([^&]+)'); add_rewrite_tag('%paged%', '([^&]+)'); // flush cached rewrite rules if we've just updated the arlo settings if(isset($_GET['settings-updated'])) flush_rewrite_rules(); } /** * 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)) { 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) { $templates = arlo_get_option('templates'); $content = $templates['event']['html']; global $post, $wpdb; $t1 = "{$wpdb->prefix}arlo_eventtemplates"; $t2 = "{$wpdb->prefix}posts"; $item = $wpdb->get_row( "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 ORDER BY et.et_name ASC", 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_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 DATETIME NULL, et_registerinteresturi TEXT NULL, PRIMARY KEY (et_id), KEY et_arlo_id (et_arlo_id)) 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 DATETIME 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, active DATETIME NULL, PRIMARY KEY (e_id), KEY et_arlo_id (et_arlo_id), KEY e_arlo_id (e_arlo_id), 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 DATETIME 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 DATETIME 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, active DATETIME NULL, PRIMARY KEY (o_id), KEY o_arlo_id (o_arlo_id), KEY et_id (et_id), KEY e_id (e_id), 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 datetime 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 datetime NOT 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 datetime NOT 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 datetime NOT 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 datetime 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 datetime 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 datetime 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 datetime NOT 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 datetime NOT 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); } /** * 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_last_import(); $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_last_import(); $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; }); // 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_last_import(); 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"; $where = "WHERE post.post_type = 'arlo_event'"; $join = ""; if(!empty($_GET['arlo-location']) || (isset($_GET['arlo-delivery']) && strlen($_GET['arlo-delivery']) && is_numeric($_GET['arlo-delivery'])) ) : $join .= " LEFT JOIN $t5 e USING (et_arlo_id)"; $where .= " AND e.e_parent_arlo_id = 0"; if(!empty($_GET['arlo-location'])) : $where .= " AND e.e_locationname = '" . urldecode($_GET['arlo-location']) . "'"; endif; if(isset($_GET['arlo-delivery']) && strlen($_GET['arlo-delivery']) && is_numeric($_GET['arlo-delivery'])) : $where .= " AND e.e_isonline = " . $_GET['arlo-delivery']; endif; endif; if(!empty($_GET['arlo-templatetag']) && is_numeric($_GET['arlo-templatetag'])) : $where .= " AND ett.tag_id = '" . intval($_GET['arlo-templatetag']) . "'"; $join .= " LEFT JOIN $t6 ett USING (et_arlo_id) "; endif; if (!empty($_GET['arlo-search'])) { $where .= ' AND ( et_code like "%' . $_GET['arlo-search'] . '%" OR et_name like "%' . $_GET['arlo-search'] . '%" OR et_descriptionsummary like "%' . $_GET['arlo-search'] . '%" ) '; } if(!empty($_GET['arlo-category']) || !empty($atts['category'])) { $cat_id = 0; if(!empty($atts['category'])) { $cat_slug = $atts['category']; } else { $cat_slug = $_GET['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'); 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_last_import(); $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"; $where = "WHERE post.post_type = 'arlo_event' AND et.active = '{$active}'"; $join = ""; if(!empty($_GET['arlo-location']) || (isset($_GET['arlo-delivery']) && strlen($_GET['arlo-delivery']) && is_numeric($_GET['arlo-delivery'])) ) : $join .= " LEFT JOIN $t5 e USING (et_arlo_id)"; $where .= " AND e.e_parent_arlo_id = 0"; if(!empty($_GET['arlo-location'])) : $where .= " AND e.e_locationname = '" . urldecode($_GET['arlo-location']) . "'"; endif; if(isset($_GET['arlo-delivery']) && strlen($_GET['arlo-delivery']) && is_numeric($_GET['arlo-delivery'])) : $where .= " AND e.e_isonline = " . $_GET['arlo-delivery']; endif; endif; if(!empty($_GET['arlo-templatetag']) && is_numeric($_GET['arlo-templatetag'])) : $where .= " AND ett.tag_id = '" . intval($_GET['arlo-templatetag']) . "'"; $join .= " LEFT JOIN $t6 ett USING (et_arlo_id) "; endif; if (!empty($_GET['arlo-search'])) { $where .= ' AND ( et_code like "%' . $_GET['arlo-search'] . '%" OR et_name like "%' . $_GET['arlo-search'] . '%" OR et_descriptionsummary like "%' . $_GET['arlo-search'] . '%" ) '; $atts['show_child_elements'] = "true"; } if(!empty($_GET['arlo-category']) || !empty($atts['category'])) { $cat_id = 0; if(!empty($atts['category'])) { $cat_slug = $atts['category']; } else { $cat_slug = $_GET['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)) : $no_event_text = !empty($settings['noevent_text']) ? $settings['noevent_text'] : __('No events to show', $GLOBALS['arlo_plugin_slug']); $output = ''; else : $output = ''; $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_last_import(); // merge and extract attributes extract(shortcode_atts(array( 'layout' => '', ), $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']; } switch($layout) { case 'list': $output = ''; break; default: $output = '
' . implode(', ', $tags) . '
'; 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_last_import(); // merge and extract attributes extract(shortcode_atts(array( 'layout' => '', ), $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']; } switch($layout) { case 'list': $output = ''; break; default: $output = '
' . implode(', ', $tags) . '
'; 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 $GLOBALS['arlo_eventtemplate']['et_code']; }); // event template name shortcode $shortcodes->add('event_template_name', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_eventtemplate']['et_name'])) return ''; return $GLOBALS['arlo_eventtemplate']['et_name']; }); // event template permalink shortcode $shortcodes->add('event_template_permalink', function($content='', $atts, $shortcode_name){ if(!isset($GLOBALS['arlo_eventtemplate']['et_post_name'])) return ''; $et_id = arlo_get_post_by_name($GLOBALS['arlo_eventtemplate']['et_post_name'], 'arlo_event'); return get_permalink($et_id); }); // 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; 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"; $items = $wpdb->get_results("SELECT $t2.cf_fieldname, $t2.cf_text FROM $t1 INNER JOIN $t2 ON $t1.et_id = $t2.et_id WHERE $t1.et_post_name = '$post->post_name' " . (is_array($where_fields) && count($where_fields) > 0 ? " AND cf_fieldname IN (" . implode(',', $where_fields) . ") " : "") . " ORDER BY $t2.cf_order", 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 $GLOBALS['arlo_content_field_item']['cf_fieldname']; }); // 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_last_import(); 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 = ''; foreach($filters_array as $filter) : switch($filter) : case 'category' : // category select $cats = \Arlo\Categories::getTree(); if (is_array($cats)) { $filter_html .= arlo_create_filter('category', arlo_child_categories($cats[0]->children), __('category', $GLOBALS['arlo_plugin_slug'])); } break; case 'delivery' : // delivery select $filter_html .= arlo_create_filter($filter, Arlo_For_Wordpress::$delivery_labels, __('delivery', $GLOBALS['arlo_plugin_slug'])); break; case 'location' : // location select $t1 = "{$wpdb->prefix}arlo_events"; $items = $wpdb->get_results( "SELECT e.e_locationname FROM $t1 e WHERE e_locationname != '' GROUP BY e.e_locationname ORDER BY e.e_locationname", ARRAY_A); $locations = array(); foreach ($items as $item) { $locations[] = array( 'string' => $item['e_locationname'], 'value' => $item['e_locationname'], ); } $filter_html .= arlo_create_filter($filter, $locations, __('location', $GLOBALS['arlo_plugin_slug'])); break; case 'templatetag' : //template tag select $items = $wpdb->get_results( "SELECT DISTINCT t.id, t.tag FROM {$wpdb->prefix}arlo_eventtemplates_tags AS ett LEFT JOIN {$wpdb->prefix}arlo_tags AS t ON t.id = ett.tag_id WHERE ett.active = '$active' ORDER BY tag", ARRAY_A); $tags = array(); foreach ($items as $item) { $tags[] = array( 'string' => $item['tag'], 'value' => $item['id'], ); } $filter_html .= arlo_create_filter($filter, $tags, __('template tag', $GLOBALS['arlo_plugin_slug'])); break; endswitch; endforeach; // category select $filter_html .= '
'; $filter_html .= ''.$resettext.'
'; $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'); $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"; $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 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 . '