* @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("";
}
}
/**
* 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 "";
}
}
/**
* prepare the ads frontend output by adding