* @license GPL-2.0+ * @link http://webgilde.com * @copyright 2015 Thomas Maier, webgilde GmbH * @since 1.6.10 * * Class containing information about the content ad type * this should also work as an example for other ad types * */ class Advanced_Ads_Ad_Type_Image extends Advanced_Ads_Ad_Type_Abstract{ /** * ID - internal type of the ad type * * must be static so set your own ad type ID here * use slug like format, only lower case, underscores and hyphens * * @since 1.6.10 */ public $ID = 'image'; /** * set basic attributes * * @since 1.6.10 */ public function __construct() { $this->title = __( 'Image Ad', 'advanced-ads' ); $this->description = __( 'Ads in various image formats.', 'advanced-ads' ); $this->parameters = array( 'image_url' => '', 'image_title' => '', 'image_alt' => '', ); } /** * output for the ad parameters metabox * * @param obj $ad ad object * @since 1.6.10 */ public function render_parameters($ad){ // load tinymc content exitor $id = ( isset( $ad->output['image_id'] ) ) ? $ad->output['image_id'] : ''; $url = ( isset( $ad->url ) ) ? esc_attr( $ad->url ) : ''; ?>

create_image_tag( $id, $ad ); ?>


width ) ? absint( $ad->width ) : $width; $height = isset( $ad->height ) ? absint( $ad->height ) : $height; } $hwstring = image_hwstring($width, $height); $attachment = get_post($attachment_id); $alt = trim(esc_textarea( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )); global $wp_current_filter; $more_attributes = $srcset = $sizes = ''; // create srcset and sizes attributes if we are in the the_content filter and in WordPress 4.4 if( isset( $wp_current_filter ) && in_array( 'the_content', $wp_current_filter ) && ! defined( 'ADVADS_DISABLE_RESPONSIVE_IMAGES' )){ if( function_exists( 'wp_get_attachment_image_srcset' ) ){ $srcset = wp_get_attachment_image_srcset( $attachment_id, 'full' ); } if( function_exists( 'wp_get_attachment_image_sizes' ) ){ $sizes = wp_get_attachment_image_sizes( $attachment_id, 'full' ); } if ( $srcset && $sizes ) { $more_attributes .= ' srcset=\'' . $srcset . '\' sizes=\'' . $sizes . '\''; } } // add css rule to be able to center the ad if( isset( $ad->output['position'] ) && 'center' === $ad->output['position'] ){ $style .= 'display: inline-block;'; } $style = apply_filters( 'advanced-ads-ad-image-tag-style', $style ); $style = '' !== $style ? 'style="' . $style . '"' : ''; $more_attributes = apply_filters( 'advanced-ads-ad-image-tag-attributes', $more_attributes ); echo rtrim("$alt"; } } /** * render image icon for overview pages * * @param int $attachment_id post id of the image * @since 1.7.4 */ public function create_image_icon( $attachment_id ){ $image = wp_get_attachment_image_src( $attachment_id, 'medium', true ); if ( $image ) { list( $src, $width, $height ) = $image; // scale down width or height to max 100px if( $width > $height ){ $height = absint( $height / ( $width / 100 ) ); $width = 100; } else { $width = absint( $width / ( $height / 100 ) ); $height = 100; } $hwstring = trim( image_hwstring($width, $height) ); $attachment = get_post($attachment_id); $alt = trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )); echo "$alt"; } } /** * prepare the ads frontend output by adding tags * * @param obj $ad ad object * @return str $content ad content prepared for frontend output * @since 1.6.10. */ public function prepare_output($ad){ $id = ( isset( $ad->output['image_id'] ) ) ? absint( $ad->output['image_id'] ) : ''; $url = ( isset( $ad->url ) ) ? esc_url( $ad->url ) : ''; // get general target setting $options = Advanced_Ads::get_instance()->options(); $target_blank = !empty( $options['target-blank'] ) ? ' target="_blank"' : ''; ob_start(); if( ! defined( 'AAT_VERSION' ) && $url ){ echo ''; } echo $this->create_image_tag( $id, $ad ); if( ! defined( 'AAT_VERSION' ) && $url ){ echo ''; } return ob_get_clean(); } /** * Generate a string with the original image size for output in the backend * Only show, if different from entered image sizes * * @param obj $ad Advanced_Ads_Ad * @return str empty, if the entered size is the same as the original size */ public static function show_original_image_size( $ad ){ $attachment_id = ( isset( $ad->output['image_id'] ) ) ? absint( $ad->output['image_id'] ) : ''; $image = wp_get_attachment_image_src( $attachment_id, 'full' ); if ( $image ) { list( $src, $width, $height ) = $image; ?>

width ) && $ad->width != $width ) || ( isset( $ad->height ) && $ad->height != $height ) ) { printf( /** * translators: $s is a size string like "728 x 90". * This string shows up on the ad edit page of image ads if the size entered for the ad is different from the size of the uploaded image. */ esc_attr__( 'Original size: %s', 'advanced-ads' ), $width . ' x ' . $height ); ?>