public static function handle_get_event_terms($events, $parse_taxonomy = false, $atts = array()) { if (!$parse_taxonomy) { return $events; } if (empty($events)) { return $events; } foreach ($events as $i => $post) { //---- $taxonomies = get_object_taxonomies(array('post_type' => $post->post_type), 'objects'); if (!empty($taxonomies)) { foreach ($taxonomies as $taxonomy => $tax) { $terms = wp_get_post_terms($post->ID, $taxonomy); if (is_array($terms) && count($terms) > 0) { foreach ($terms as $term) { // $url = get_term_meta($term->term_id,'website',true); // $url = trim($url)==''?get_term_meta($term->term_id,'url',true):$url; // $url = trim($url)==''?get_term_link( $term, $taxonomy ):$url; $url = get_term_link($term, $taxonomy); $gaddress = get_term_meta($term->term_id, 'gaddress', true); $color = get_term_meta($term->term_id, 'color', true); $bg = get_term_meta($term->term_id, 'background_color', true); $image = get_term_meta($term->term_id, 'image', true); if (empty($image) && function_exists('get_term_thumbnail')) { $term_thumbnail_id = get_term_thumbnail_id($term->term_id); $src = wp_get_attachment_image_src($term_thumbnail_id, 'full'); if (isset($src[0])) { $image = $src[0]; } } $glat = get_term_meta($term->term_id, 'glat', true); $glon = get_term_meta($term->term_id, 'glon', true); $ginfo = get_term_meta($term->term_id, 'ginfo', true); $new = (object) array('term_id' => $term->term_taxonomy_id, 'taxonomy' => $taxonomy, 'taxonomy_label' => $tax->labels->singular_name, 'slug' => $term->slug, 'name' => $term->name, 'url' => $url, 'gaddress' => $gaddress, 'glat' => $glat, 'glon' => $glon, 'ginfo' => $ginfo, 'color' => $color, 'background_color' => $bg, 'image' => $image); foreach (array('address', 'city', 'state', 'zip', 'country') as $meta) { $new->{$meta} = get_term_meta($term->term_id, $meta, true); } if (!property_exists($events[$i], 'terms')) { $events[$i]->terms = array(); } $events[$i]->terms[] = apply_filters('rhc_event_term_meta', $new, $term->term_id, $taxonomy); } } } } //---- } return $events; }
/** * Generate or retrieve the an image of a specific size from the thumb_id. * * @param array/obj/int $term Description * @param integer $x Width of image * @param integer $y Height of image * @param boolean $crop Cropped or not * @param string $name Unique name for this image size * @param array $attr Array of attributes * * @return string The html generated from request. */ function get_irregular_term_thumb($term, $x = 100, $y = 100, $crop = true, $name = 'irregular-post-thumb', $attr = '') { if (!is_object($term) || !isset($term->term_id) || !function_exists('has_term_thumbnail')) { return false; } $term_id = $term->term_id; if (!has_term_thumbnail($term_id)) { return false; } $thumb_id = get_term_thumbnail_id($term_id); if (!empty($thumb_id)) { // Check for and create our image size as needed $thumb_meta = wp_get_attachment_metadata($thumb_id); if (!isset($thumb_meta['sizes'][$name]) && function_exists('add_resized_attachment')) { add_resized_attachment($thumb_id, $x, $y, $crop, $name); } } // The the thumbnail return get_the_term_thumbnail($term_id, $name, $attr); }
function get_events($r, $args, $request = false) { $request = false === $request ? $_REQUEST : $request; global $rhc_plugin, $wpdb; $disable_event_link = '1' == $rhc_plugin->get_option('disable_event_link') ? true : false; $ajax_suppress_filters = '1' == $rhc_plugin->get_option('ajax_suppress_filters', '0', true) ? true : false; //---- $args['numberposts'] = $this->numberposts; $args['suppress_filters'] = $ajax_suppress_filters; //error_log(print_r($args,true)."\n\r",3,ABSPATH.'cal2.log'); if (isset($args['author']) && empty($args['author'])) { return $r; } if (isset($args['author_name']) && empty($args['author_name'])) { return $r; } //---- plugin types consumes too much memory, uncomment this to fix a random memory crash when using that plugin /* global $wp_filter; if( isset($wp_filter['the_posts']) && isset($wp_filter['the_posts'][10]) && isset($wp_filter['the_posts'][10]['WPCF_Loader::wpcf_cache_complete_postmeta']) ){ unset($wp_filter['the_posts'][10]['WPCF_Loader::wpcf_cache_complete_postmeta']); } */ $posts = get_posts($args); if (!empty($posts)) { if (!function_exists('get_term_meta')) { require_once RHC_PATH . 'custom-taxonomy-with-meta/taxonomy-metadata.php'; } foreach ($posts as $post) { setup_postdata($post); //--- $attachment_id = get_post_meta($post->ID, 'rhc_tooltip_image', true); $size = $this->get_image_size(); $image = $this->get_tooltip_image($post->ID, $attachment_id, $size); $image_full = $this->get_tooltip_image($post->ID, $attachment_id, 'full'); //--- $url = $disable_event_link ? false : get_permalink($post->ID); if (false === $url) { if ($request['rhc_action'] == 'get_icalendar_events') { $url = ''; } else { $url = "javascript:void(0);"; } } //--- $tmp = array('id' => sprintf("%s-%s", $post->ID, $post->post_type), 'local_id' => $post->ID, 'title' => get_the_title($post->ID), 'start' => $this->get_start_from_post_id($post->ID), 'end' => $this->get_end_from_post_id($post->ID), 'url' => $url, 'description' => do_shortcode($post->post_excerpt), 'image' => $image, 'image_full' => $image_full, 'terms' => array(), 'fc_click_link' => 'view', 'menu_order' => intval($post->menu_order)); //-- month view image if ($this->month_event_image) { $attachment_id = get_post_meta($post->ID, 'rhc_month_image', true); $size = $this->get_image_size('rhc_media_size'); $image = wp_get_attachment_image_src($attachment_id, $size); if (false !== $image) { $tmp['month_image'] = $image; } } //----handle duplicates if ($this->skip_duplicates) { if (in_array($tmp['id'], $this->done_ids)) { continue; } else { $this->done_ids[] = $tmp['id']; } } //---- foreach (array('fc_rdate' => 'fc_rdate', 'fc_exdate' => 'fc_exdate', 'fc_allday' => 'allDay', 'fc_start' => 'fc_start', 'fc_start_time' => 'fc_start_time', 'fc_end' => 'fc_end', 'fc_end_time' => 'fc_end_time', 'fc_interval' => 'fc_interval', 'fc_rrule' => 'fc_rrule', 'fc_end_interval' => 'fc_end_interval', 'fc_color' => 'color', 'fc_text_color' => 'textColor', 'fc_click_link' => 'fc_click_link', 'fc_click_target' => 'fc_click_target') as $meta_field => $event_field) { $meta_value = get_post_meta($post->ID, $meta_field, true); if ('' != trim($meta_value)) { $tmp[$event_field] = $meta_value; } } $tmp['allDay'] = isset($tmp['allDay']) && $tmp['allDay'] ? true : false; //---- $taxonomies = get_object_taxonomies(array('post_type' => $post->post_type), 'objects'); if (!empty($taxonomies)) { foreach ($taxonomies as $taxonomy => $tax) { $terms = wp_get_post_terms($post->ID, $taxonomy); if (is_array($terms) && count($terms) > 0) { foreach ($terms as $term) { // $url = get_term_meta($term->term_id,'website',true); // $url = trim($url)==''?get_term_meta($term->term_id,'url',true):$url; // $url = trim($url)==''?get_term_link( $term, $taxonomy ):$url; $url = get_term_link($term, $taxonomy); $gaddress = get_term_meta($term->term_id, 'gaddress', true); $color = get_term_meta($term->term_id, 'color', true); $bg = get_term_meta($term->term_id, 'background_color', true); $image = get_term_meta($term->term_id, 'image', true); if (empty($image) && function_exists('get_term_thumbnail')) { $term_thumbnail_id = get_term_thumbnail_id($term->term_id); $src = wp_get_attachment_image_src($term_thumbnail_id, 'full'); if (isset($src[0])) { $image = $src[0]; } } $glat = get_term_meta($term->term_id, 'glat', true); $glon = get_term_meta($term->term_id, 'glon', true); $new = (object) array('term_id' => $term->term_taxonomy_id, 'taxonomy' => $taxonomy, 'taxonomy_label' => $tax->labels->singular_name, 'slug' => $term->slug, 'name' => $term->name, 'url' => $url, 'gaddress' => $gaddress, 'glat' => $glat, 'glon' => $glon, 'color' => $color, 'background_color' => $bg, 'image' => $image); foreach (array('address', 'city', 'state', 'zip', 'country') as $meta) { $new->{$meta} = get_term_meta($term->term_id, $meta, true); } $tmp['terms'][] = apply_filters('rhc_event_term_meta', $new, $term->term_id, $taxonomy); } } } } //---- $r[] = $tmp; } } return $r; }