$regex_matches_new[0], 'type' => $regex_matches_new[2], 'url' => $regex_matches_new[5] ); if (false == $enable_multi) { break; } endif; } return $media; } function ad_mag_lite_content_get_gallery($content, $enable_multi = false) { return ad_mag_lite_content_get_media($content, $enable_multi, array('gallery')); } function ad_mag_lite_content_get_quote($content, $enable_multi = false) { return ad_mag_lite_content_get_media($content, $enable_multi, array('gallery')); } function ad_mag_lite_content_get_audio($content, $enable_multi = false) { return ad_mag_lite_content_get_media($content, $enable_multi, array('audio', 'soundcloud')); } function ad_mag_lite_content_get_video($content, $enable_multi = false) { return ad_mag_lite_content_get_media($content, $enable_multi, array('vimeo', 'youtube', 'video', 'embed', 'wpvideo')); } /** * Get gallery string ids after getting matched gallery array * @return array of attachment ids in gallery * @return empty if no gallery were found */ function ad_mag_lite_content_get_gallery_attachment_ids( $content ) { $gallery = ad_mag_lite_content_get_gallery( $content ); if (isset( $gallery[0] )) { $gallery = $gallery[0]; } else { return ''; } if ( isset($gallery['shortcode']) ) { $shortcode = $gallery['shortcode']; } else { return ''; } // get gallery string ids preg_match_all('/ids=\"(?:\d+,*)+\"/', $shortcode, $gallery_string_ids); if ( isset( $gallery_string_ids[0][0] ) ) { $gallery_string_ids = $gallery_string_ids[0][0]; } else { return ''; } // get array of image id preg_match_all('/\d+/', $gallery_string_ids, $gallery_ids); if ( isset( $gallery_ids[0] ) ) { $gallery_ids = $gallery_ids[0]; } else { return ''; } return $gallery_ids; } /** * Template tag: Show socials link */ function ad_mag_lite_social() { $social_links = array( 'social_facebook' => array( 'url' => '', 'icon' => 'fa-facebook', 'display' => false, 'name' => 'Facebook' ), 'social_twitter' => array( 'url' => '', 'icon' => 'fa-twitter', 'display' => false, 'name' => 'Twitter' ), 'social_google_plus' => array( 'url' => '', 'icon' => 'fa-google-plus', 'display' => false, 'name' => 'Google +' ), 'social_linkedin' => array( 'url' => '', 'icon' => 'fa-linkedin', 'display' => false, 'name' => 'Linkedin' ), 'social_tumblr' => array( 'url' => '', 'icon' => 'fa-tumblr', 'display' => false, 'name' => 'Tumblr' ), 'social_pinterest' => array( 'url' => '', 'icon' => 'fa-pinterest', 'display' => false, 'name' => 'Pinterest' ), 'social_rss' => array( 'url' => '', 'icon' => 'fa-rss', 'display' => false, 'name' => 'RSS' ), ); $display = false; foreach( $social_links as $social_name => $social_atts ) { $option_name = $social_name; $social_atts['url'] = get_theme_mod( $option_name, '' ); if ( 'social_rss' == $social_name ) { if ( empty( $social_atts['url'] ) ) { $social_atts['url'] = get_bloginfo('rss2_url'); $social_atts['display'] = true; $display = true; } elseif ( $social_atts['url'] != 'HIDE' ) { $social_atts['url'] = esc_url( $social_atts['url'] ); $social_atts['display'] = true; } } else { $social_atts['url'] = esc_url( $social_atts['url'] ); if ( !empty( $social_atts['url'] ) ) { $social_atts['display'] = true; $display = true;} } $social_links[ $social_name ] = $social_atts; } $target = '_blank'; ?> __('----SELECT----', 'ad-mag-lite') ); foreach($terms as $v) $arr_cat[$v->term_id] = $v->name . '(' . $v->count . ')'; if ($limit) { $cats = (array)$arr_cat; $cats = implode(',', $cats); if( !empty($cats) ){ $posts = new WP_Query('cat='.$cats.'&posts_per_page='.$limit); }else{ $posts = new WP_Query( 'posts_per_page='.$limit); } ?>
'; $breadcrumb_after = '
'; $breadcrumb_home = ''; $breadcrumb = ''; ?> %2$s', $current_class, get_the_title(get_option('page_for_posts'))); } else { $breadcrumb.= $prefix . sprintf('%2$s', $current_class, __('Blog', 'ad-mag-lite')); } } else if (is_post_type_archive('product') && get_option('woocommerce_shop_page_id')) { $breadcrumb.= $breadcrumb_home; $breadcrumb.= $prefix . sprintf('', $current_class, get_the_title(get_option('woocommerce_shop_page_id'))); } else if (is_tag()) { $breadcrumb.= $breadcrumb_home; $term = get_term(get_queried_object_id(), 'post_tag'); $breadcrumb.= $prefix . sprintf('%2$s', $current_class, $term->name); } else if (is_category()) { $breadcrumb.= $breadcrumb_home; $category_id = get_queried_object_id(); $terms_link = explode(',', substr(get_category_parents(get_queried_object_id(), TRUE, ','), 0, (strlen(',') * -1))); $n = count($terms_link); if ($n > 1) { for ($i = 0; $i < ($n - 1); $i++) { $breadcrumb.= $prefix . $terms_link[$i]; } } $breadcrumb.= $prefix . sprintf('', $current_class, get_the_category_by_ID(get_queried_object_id())); } else if ( is_tax('product_cat') ) { $breadcrumb.= $breadcrumb_home; $breadcrumb.= $prefix . ''; $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $parents = array(); $parent = $term->parent; while ($parent): $parents[] = $parent; $new_parent = get_term_by( 'id', $parent, get_query_var( 'taxonomy' )); $parent = $new_parent->parent; endwhile; if( ! empty( $parents ) ): $parents = array_reverse($parents); foreach ($parents as $parent): $item = get_term_by( 'id', $parent, get_query_var( 'taxonomy' )); $breadcrumb .= $prefix . ''; endforeach; endif; $queried_object = get_queried_object(); // $breadcrumb.= $prefix . sprintf('%2$s', $current_class, $queried_object->name); $breadcrumb.= $prefix . sprintf('', $current_class, $queried_object->name); } else if ( is_tax( 'product_tag' ) ) { $breadcrumb.= $breadcrumb_home; $breadcrumb.= $prefix . ''.get_the_title( get_option('woocommerce_shop_page_id') ).''; $queried_object = get_queried_object(); $breadcrumb.= $prefix . sprintf('%2$s', $current_class, $queried_object->name); } else if (is_single()) { global $post; $breadcrumb.= $breadcrumb_home; if ( is_singular('product')) : $breadcrumb .= $prefix . ''; if ($terms = get_the_terms( $post->ID, 'product_cat' )) : $term = apply_filters( 'jigoshop_product_cat_breadcrumb_terms', current($terms), $terms); $parents = array(); $parent = $term->parent; while ($parent): $parents[] = $parent; $new_parent = get_term_by( 'id', $parent, 'product_cat'); $parent = $new_parent->parent; endwhile; if(!empty($parents)): $parents = array_reverse($parents); foreach ($parents as $parent): $item = get_term_by( 'id', $parent, 'product_cat'); $breadcrumb .= $prefix . ''; endforeach; endif; $breadcrumb .= $prefix . ''; endif; $breadcrumb.= $prefix . sprintf('', $current_class, get_the_title(get_queried_object_id())); else : $categories = get_the_category(get_queried_object_id()); if ($categories) { foreach ($categories as $category) { $breadcrumb.= $prefix . sprintf('', get_category_link($category->term_id), $category->name); } } $post_id = get_queried_object_id(); $breadcrumb.= $prefix . sprintf('', $current_class, get_the_title(get_queried_object_id())); endif; } else if (is_page()) { if (!is_front_page()) { $post_id = get_queried_object_id(); $breadcrumb.= $breadcrumb_home; $post_ancestors = get_post_ancestors($post); if ($post_ancestors) { $post_ancestors = array_reverse($post_ancestors); foreach ($post_ancestors as $crumb) $breadcrumb.= $prefix . sprintf('%2$s', get_permalink($crumb), get_the_title($crumb)); } $breadcrumb.= $prefix . sprintf('', $current_class, get_the_title(get_queried_object_id())); } } else if (is_year() || is_month() || is_day()) { $breadcrumb.= $breadcrumb_home; $date = array('y' => NULL, 'm' => NULL, 'd' => NULL); $date['y'] = get_the_time('Y'); $date['m'] = get_the_time('m'); $date['d'] = get_the_time('j'); if (is_year()) { $breadcrumb.= $prefix . sprintf('%2$s', $current_class, $date['y']); } if (is_month()) { $breadcrumb.= $prefix . sprintf('%2$s', get_year_link($date['y']), $date['y']); $breadcrumb.= $prefix . sprintf('%2$s', $current_class, date_i18n('F', $date['m'])); } if (is_day()) { $breadcrumb.= $prefix . sprintf('%2$s', get_year_link($date['y']), $date['y']); $breadcrumb.= $prefix . sprintf('%2$s', get_month_link($date['y'], $date['m']), date_i18n('F', $date['m'])); $breadcrumb.= $prefix . sprintf('%2$s', $current_class, $date['d']); } } else if (is_search()) { $breadcrumb.= $breadcrumb_home; $s = get_search_query(); $c = $wp_query->found_posts; $description = sprintf(__('Your search for "%2$s"', 'ad-mag-lite'), $current_class, $s); $breadcrumb .= $prefix . $description; } else if (is_author()) { $breadcrumb.= $breadcrumb_home; $author_id = get_queried_object_id(); $breadcrumb.= $prefix . sprintf('%2$s', $current_class, sprintf(__('Posts created by %1$s', 'ad-mag-lite'), get_the_author_meta('display_name', $author_id))); } else if (is_404()) { $breadcrumb.= $breadcrumb_home; $breadcrumb.= $prefix . sprintf('', $current_class, __('Error 404', 'ad-mag-lite')); } if ($breadcrumb) echo apply_filters('ad_mag_lite_breadcrumb', $breadcrumb_before . $breadcrumb . $breadcrumb_after); } } function ad_mag_lite_register_new_image_sizes(){ add_image_size( 'post-thumb', 410, 370, true ); } /** * Show first single's category */ function ad_mag_lite_the_first_category($ID,$class = ''){ global $post; if($post->post_type == 'page'){ return; } if($post->post_type == 'product'){ $terms = get_the_terms( $post->ID, 'product_cat' ); if($terms){ foreach ($terms as $term) { $product_cat = $term->name; $product_cat_link = get_term_link( $term->term_id, 'product_cat' ); break; } echo '
'.$product_cat.'
'; } }else{ $category = get_the_category($ID); $category_link = get_category_link( $category[0]->cat_ID ); if(!empty($class)){ echo '
'.$category[0]->cat_name.'
'; }else{ echo '
'.$category[0]->cat_name.'
'; } } } /** * Show author post with avatar */ function ad_mag_lite_author_avatar($ID, $span = false){ $url = get_author_posts_url($ID); if($span){ $name = ''.get_the_author_meta('display_name', $ID).''; }else{ $name = get_the_author_meta('display_name', $ID); } $img = get_avatar($ID, 20, '', $name ); echo ' '; } /* * Get youtube duration by id */ function ad_mag_lite_get_youtube_duration($videoid) { $xml = simplexml_load_file('https://gdata.youtube.com/feeds/api/videos/' . $videoid . '?v=2'); $result = $xml->xpath('//yt:duration[@seconds]'); $total_seconds = (int) $result[0]->attributes()->seconds; $total_seconds = $total_seconds-1; if($total_seconds < 3600){ $time = gmdate('i:s', $total_seconds); }else{ $time = gmdate('H:i:s', $total_seconds); } return $time; } /* * Get youtube duration in content */ function ad_mag_lite_video_time($id) { $post_object = get_post( $id ); $content = $post_object->post_content; $post_format = get_post_format($id); $ids = array(); // find all urls preg_match_all('/(http|https)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/', $content, $links); foreach ($links[0] as $link) { if (preg_match('~youtube\.com~', $link)) { if (preg_match('/[^=]+=([^?]+)/', $link, $id)) { $ids[] = $id[1]; } } } if(!empty($ids[0]) && $post_format == 'video'){ echo ''.ad_mag_lite_get_youtube_duration($ids[0]).''; } }