Esempio n. 1
0
 /**
  * Replaces variables with WordPress content
  *
  * @since 1.0.0
  *
  * @param int $id User ID
  */
 function issuem_replacements_args($string, $post)
 {
     $issuem_settings = get_issuem_settings();
     if (!empty($issuem_settings['use_wp_taxonomies'])) {
         $tags = 'post_tag';
         $cats = 'category';
     } else {
         $tags = 'issuem_issue_tags';
         $cats = 'issuem_issue_categories';
     }
     /* HAS added for Easst */
     $string = str_ireplace('%SECTION%', get_article_section($post->ID), $string);
     $string = str_ireplace('%TITLE%', get_the_title(), $string);
     $string = str_ireplace('%URL%', apply_filters('issuem_article_url', get_permalink($post->ID), $post->ID), $string);
     if (preg_match('/%CATEGORY\\[?(\\d*)\\]?%/i', $string, $matches)) {
         $post_cats = get_the_terms($post->ID, $cats);
         $categories = '';
         if ($post_cats && !is_wp_error($post_cats)) {
             if (!empty($matches[1])) {
                 $max_cats = $matches[1];
             } else {
                 $max_cats = 0;
             }
             $cat_array = array();
             $count = 1;
             foreach ($post_cats as $post_cat) {
                 $cat_array[] = $post_cat->name;
                 if (0 != $max_cats && $max_cats <= $count) {
                     break;
                 }
                 $count++;
             }
             $categories = join(", ", $cat_array);
         }
         $string = preg_replace('/%CATEGORY\\[?(\\d*)\\]?%/i', $categories, $string);
     }
     if (preg_match('/%TAG\\[?(\\d*)\\]?%/i', $string, $matches)) {
         $post_tags = get_the_terms($post->ID, $tags);
         $tag_string = '';
         if ($post_tags && !is_wp_error($post_tags)) {
             if (!empty($matches[1])) {
                 $max_tags = $matches[1];
             } else {
                 $max_tags = 0;
             }
             $cat_array = array();
             $count = 1;
             foreach ($post_tags as $post_tag) {
                 $cat_array[] = $post_tag->name;
                 if (0 != $max_tags && $max_tags <= $count) {
                     break;
                 }
                 $count++;
             }
             $tag_string = join(", ", $cat_array);
         }
         $string = preg_replace('/%TAG\\[?(\\d*)\\]?%/i', $tag_string, $string);
     }
     if (preg_match('/%TEASER%/i', $string, $matches)) {
         if ($teaser = get_post_meta($post->ID, '_teaser_text', true)) {
             $string = preg_replace('/%TEASER%/i', $teaser, $string);
         } else {
             $string = preg_replace('/%TEASER%/i', '%EXCERPT%', $string);
         }
         // If no Teaser Text exists, try to get an excerpt
     }
     if (preg_match('/%EXCERPT\\[?(\\d*)\\]?%/i', $string, $matches)) {
         if (!empty($matches[1])) {
             $excerpt_length = $matches[1];
         } else {
             $excerpt_length = 0;
         }
         if (empty($post->post_excerpt)) {
             $excerpt = $excerpt_length === 0 ? '' : get_the_content();
         } else {
             $excerpt = $post->post_excerpt;
         }
         $excerpt = strip_shortcodes($excerpt);
         $excerpt = apply_filters('the_content', $excerpt);
         $excerpt = str_replace(']]>', ']]&gt;', $excerpt);
         if ($excerpt_length !== 0 && empty($post->post_excerpt)) {
             $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
             $excerpt = wp_trim_words($excerpt, $excerpt_length, $excerpt_more);
         }
         $string = preg_replace('/%EXCERPT\\[?(\\d*)\\]?%/i', $excerpt, $string);
     }
     if (preg_match('/%CONTENT%/i', $string, $matches)) {
         $content = get_the_content();
         $content = apply_filters('the_content', $content);
         $content = str_replace(']]>', ']]&gt;', $content);
         $string = preg_replace('/%CONTENT%/i', $content, $string);
     }
     if (preg_match('/%FEATURE_IMAGE%/i', $string, $matches)) {
         $image = get_the_post_thumbnail($post->ID);
         $string = preg_replace('/%FEATURE_IMAGE%/i', $image, $string);
     }
     if (preg_match('/%ISSUEM_FEATURE_THUMB%/i', $string, $matches)) {
         $image = get_the_post_thumbnail($post->ID, 'issuem-featured-thumb-image');
         $string = preg_replace('/%ISSUEM_FEATURE_THUMB%/i', $image, $string);
     }
     if (preg_match('/%BYLINE%/i', $string, $matches)) {
         $author_name = get_issuem_author_name($post);
         if (strlen(trim($author_name)) > 0) {
             $byline = sprintf(__('by %s', 'issuem'), apply_filters('issuem_author_name', $author_name, $post->ID));
         } else {
             $byline = '';
         }
         $string = preg_replace('/%BYLINE%/i', $byline, $string);
     }
     if (preg_match('/%DATE%/i', $string, $matches)) {
         $post_date = get_the_date('', $post->ID);
         $string = preg_replace('/%DATE%/i', $post_date, $string);
     }
     $string = apply_filters('issuem_custom_replacement_args', $string, $post);
     return stripcslashes($string);
 }
Esempio n. 2
0
 /**
  * Outputs Issue Featured Thumbnail Images HTML from shortcode call
  *
  * @since 1.0.0
  *
  * @param array $atts Arguments passed through shortcode
  * @return string HTML output of Issue Featured Rotator Thumbnails
  */
 function do_issuem_featured_thumbs($atts)
 {
     global $post;
     $results = '';
     $issuem_settings = get_issuem_settings();
     $defaults = array('content_type' => 'teaser', 'posts_per_page' => -1, 'offset' => 0, 'orderby' => 'menu_order', 'order' => 'DESC', 'max_images' => 0, 'issue' => get_active_issuem_issue(), 'article_category' => 'all', 'show_cats' => false);
     // Merge defaults with passed atts
     // Extract (make each array element its own PHP var
     extract(shortcode_atts($defaults, $atts));
     $args = array('posts_per_page' => $posts_per_page, 'offset' => $offset, 'post_type' => 'article', 'orderby' => $orderby, 'order' => $order, 'meta_key' => '_featured_thumb', 'issuem_issue' => $issue);
     if (!empty($issuem_settings['use_wp_taxonomies'])) {
         $cat_type = 'category';
     } else {
         $cat_type = 'issuem_issue_categories';
     }
     if (!empty($article_category) && 'all' !== $article_category) {
         $category = array('taxonomy' => $cat_type, 'field' => 'slug', 'terms' => split(',', $article_category));
         $args['tax_query'] = array('relation' => 'AND', $issuem_issue, $category);
     }
     $featured_articles = get_posts($args);
     if ($featured_articles) {
         $results .= '<div id="issuem-featured-article-thumbs-wrap">';
         $count = 1;
         /* start the loop */
         foreach ($featured_articles as $article) {
             if (has_post_thumbnail($article->ID)) {
                 $image = wp_get_attachment_image_src(get_post_thumbnail_id($article->ID), 'issuem-featured-thumb-image');
                 $image = apply_filters('issuem_featured_thumbs_article_image', $image, $article);
                 $results .= apply_filters('issuem_featured_thumbs_before_thumbnail_div', '', $article);
                 $results .= '<div class="issuem-featured-article-thumb">';
                 $results .= apply_filters('issuem_featured_thumbs_start_thumbnail_div', '', $article);
                 $results .= apply_filters('issuem_featured_thumbs_before_thumbnail_image', '', $article);
                 $results .= apply_filters('issuem_featured_thumbs_thumbnail_image', '<a class="issuem-featured-thumbs-img" href="' . get_permalink($article->ID) . '"><img src="' . $image[0] . '" width="' . $image[1] . '" height="' . $image[2] . '" alt="' . get_post_meta($article->ID, '_teaser_text', true) . '" /></a>', $article);
                 $results .= apply_filters('issuem_featured_thumbs_after_thumbnail_image', '', $article);
                 if ('true' === $show_cats) {
                     $results .= apply_filters('issuem_featured_thumbs_before_thumbnail_category', '', $article);
                     $results .= apply_filters('issuem_featured_thumbs_thumbnail_category', '<p class="issuem-article-category">' . get_the_term_list($article->ID, $cat_type) . '</p>', $article);
                     $results .= apply_filters('issuem_featured_thumbs_after_thumbnail_category', '', $article);
                 }
                 $results .= apply_filters('issuem_featured_thumbs_before_thumbnail_title', '', $article);
                 $results .= apply_filters('issuem_featured_thumbs_after_thumbnail_title', '<h3 class="issuem-featured-thumb-title"><a href="' . get_permalink($article->ID) . '">' . get_the_title($article->ID) . '</a></h3>', $article);
                 $results .= apply_filters('issuem_featured_thumbs_after_thumbnail_title', '', $article);
                 $results .= apply_filters('issuem_featured_thumbs_before_thumbnail_content', '', $article);
                 switch ($content_type) {
                     case 'excerpt':
                         $results .= apply_filters('issuem_featured_thumbs_thumbnail_content', '<p class="issuem-featured-thumb-content">' . get_issuem_article_excerpt($article->ID) . '</p>', $article);
                         break;
                     case 'teaser':
                     default:
                         $results .= apply_filters('issuem_featured_thumbs_thumbnail_content', '<p class="featured-thumb-content">' . get_post_meta($article->ID, '_teaser_text', true) . '</p>', $article);
                         break;
                 }
                 $results .= apply_filters('issuem_featured_thumbs_after_thumbnail_content', '', $article);
                 $results .= apply_filters('issuem_featured_thumbs_before_thumbnail_byline', '', $article);
                 if ($issuem_settings['show_thumbnail_byline']) {
                     $author_name = get_issuem_author_name($article);
                     $results .= apply_filters('issuem_featured_thumbs_thumbnail_byline', '<p class="featured-thumb-byline">' . sprintf(__('By %s', 'issuem'), apply_filters('issuem_author_name', $author_name, $article->ID)) . '</p>', $article);
                 }
                 $results .= apply_filters('issuem_featured_thumbs_before_thumbnail_byline', '', $article);
                 $results .= apply_filters('issuem_featured_thumbs_end_thumbnail_div', '', $article);
                 $results .= '</div>';
                 $results .= apply_filters('issuem_featured_article_after_thumbnail_div', '', $article);
                 if (0 != $max_images && $max_images <= $count) {
                     break;
                 }
                 $count++;
             }
         }
         $results .= '</div>';
     }
     return $results;
 }