コード例 #1
0
 /**
  * get image - v 2.0  20 nov
  * @param $thumbType
  * @param string $image_link
  * @param string $image_excerpt
  * @param string $featured_image_placeholder  - some modules require that we have a placeholder image @see td_module_mx1
  * @return string
  */
 function get_image($thumbType, $image_link = '', $image_excerpt = '', $featured_image_placeholder = '')
 {
     $buffy = '';
     //the output buffer
     $show_colorbox_class = false;
     if ($featured_image_placeholder == '') {
         //read the placeholder option from the database if $featured_image_placeholder is not receive
         $featured_image_placeholder = td_util::get_option('tds_hide_featured_image_placeholder');
     }
     /*
      *  - if we have a post thumb - show that
      *  - if we don't have a post thumb, check the image placeholder option and if we're also not a single page show the image placeholder.
      */
     if ($this->post_has_thumb or $featured_image_placeholder == '') {
         //and !is_single()//comment this so we can have image placeholder on single post pages
         if ($image_link == '') {
             $image_link = $this->href;
         } else {
             //we are in post, only posts use $image_link
             if (td_util::get_option('tds_featured_image_view_setting') == '') {
                 if (is_single()) {
                     $show_colorbox_class = true;
                 } else {
                     $image_link = $this->href;
                     $show_colorbox_class = false;
                 }
             }
             if (td_util::get_option('tds_featured_image_view_setting') == 'lightbox') {
                 $show_colorbox_class = true;
             }
             if (td_util::get_option('tds_featured_image_view_setting') == 'no_link') {
                 $image_link = '';
                 //remove the link if we have that option
             }
         }
         if ($this->post_has_thumb) {
             // check to see if the thumb size is enabled in the panel
             if (td_util::get_option('tds_thumb_' . $thumbType) != 'yes' and TD_THEME_NAME == 'Newsmag') {
                 // remove Newsmag check on newspaper 5
                 global $_wp_additional_image_sizes;
                 if (empty($_wp_additional_image_sizes[$thumbType]['width'])) {
                     $td_temp_image_url[1] = '';
                 } else {
                     $td_temp_image_url[1] = $_wp_additional_image_sizes[$thumbType]['width'];
                 }
                 if (empty($_wp_additional_image_sizes[$thumbType]['height'])) {
                     $td_temp_image_url[2] = '';
                 } else {
                     $td_temp_image_url[2] = $_wp_additional_image_sizes[$thumbType]['height'];
                 }
                 $td_temp_image_url[0] = get_template_directory_uri() . '/images/thumb-disabled/' . $thumbType . '.png';
                 $attachment_alt = '';
                 $attachment_title = '';
             } else {
                 //if we have a thumb
                 $attachment_id = get_post_thumbnail_id($this->post->ID);
                 $td_temp_image_url = wp_get_attachment_image_src($attachment_id, $thumbType);
                 $attachment_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
                 $attachment_alt = 'alt="' . esc_attr(strip_tags($attachment_alt)) . '"';
                 $attachment_title = ' title="' . $this->title . '"';
                 if (empty($td_temp_image_url[0])) {
                     $td_temp_image_url[0] = '';
                 }
                 if (empty($td_temp_image_url[1])) {
                     $td_temp_image_url[1] = '';
                 }
                 if (empty($td_temp_image_url[2])) {
                     $td_temp_image_url[2] = '';
                 }
             }
             // end panel thumb enabled check
         } else {
             //we have no thumb but the placeholder one is activated
             global $_wp_additional_image_sizes;
             if (empty($_wp_additional_image_sizes[$thumbType]['width'])) {
                 $td_temp_image_url[1] = '';
             } else {
                 $td_temp_image_url[1] = $_wp_additional_image_sizes[$thumbType]['width'];
             }
             if (empty($_wp_additional_image_sizes[$thumbType]['height'])) {
                 $td_temp_image_url[2] = '';
             } else {
                 $td_temp_image_url[2] = $_wp_additional_image_sizes[$thumbType]['height'];
             }
             $td_temp_image_url[0] = get_template_directory_uri() . '/images/no-thumb/' . $thumbType . '.png';
             $attachment_alt = '';
             $attachment_title = '';
         }
         $buffy .= '<div class="td-module-thumb">';
         if (current_user_can('edit_posts')) {
             $buffy .= '<a class="td-admin-edit" href="' . get_edit_post_link($this->post->ID) . '">edit</a>';
         }
         if ($image_link != '') {
             $buffy .= '<a href="' . $image_link . '" rel="bookmark" title="' . $this->title_attribute . '">';
         }
         $buffy .= '<img width="' . $td_temp_image_url[1] . '" height="' . $td_temp_image_url[2] . '" itemprop="image" class="entry-thumb' . td_util::if_show($show_colorbox_class, 'td-modal-image') . '" src="' . $td_temp_image_url[0] . '" ' . $attachment_alt . $attachment_title . '/>';
         if (get_post_format($this->post->ID) == 'video') {
             if ($thumbType == 'td_100x75' or $thumbType == 'td_80x60' or $thumbType == 'thumbnail') {
                 $buffy .= '<span class="td-video-play-ico td-video-small"><img width="20" class="td-retina" src="' . get_template_directory_uri() . '/images/icons/video-small.png' . '" alt="video"/></span>';
             } else {
                 $buffy .= '<span class="td-video-play-ico"><img width="40" class="td-retina" src="' . get_template_directory_uri() . '/images/icons/ico-video-large.png' . '" alt="video"/></span>';
             }
         }
         if ($image_link != '') {
             $buffy .= '</a>';
         }
         $buffy .= $image_excerpt;
         $buffy .= '</div>';
         return $buffy;
     }
 }