EDD_SL_Plugin_Updater.php
8 years ago
ad-ajax.php
9 years ago
ad-debug.php
8 years ago
ad-model.php
9 years ago
ad-select.php
9 years ago
ad.php
8 years ago
ad_ajax_callbacks.php
8 years ago
ad_group.php
8 years ago
ad_placements.php
8 years ago
ad_type_abstract.php
11 years ago
ad_type_content.php
8 years ago
ad_type_dummy.php
8 years ago
ad_type_group.php
8 years ago
ad_type_image.php
8 years ago
ad_type_plain.php
9 years ago
checks.php
9 years ago
display-conditions.php
8 years ago
filesystem.php
8 years ago
frontend_checks.php
8 years ago
plugin.php
8 years ago
upgrades.php
9 years ago
utils.php
9 years ago
visitor-conditions.php
8 years ago
widget.php
8 years ago
ad_type_image.php
167 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Advanced Ads Image Ad Type |
| 4 | * |
| 5 | * @package Advanced_Ads |
| 6 | * @author Thomas Maier <thomas.maier@webgilde.com> |
| 7 | * @license GPL-2.0+ |
| 8 | * @link http://webgilde.com |
| 9 | * @copyright 2015 Thomas Maier, webgilde GmbH |
| 10 | * @since 1.6.10 |
| 11 | * |
| 12 | * Class containing information about the content ad type |
| 13 | * this should also work as an example for other ad types |
| 14 | * |
| 15 | */ |
| 16 | class Advanced_Ads_Ad_Type_Image extends Advanced_Ads_Ad_Type_Abstract{ |
| 17 | |
| 18 | /** |
| 19 | * ID - internal type of the ad type |
| 20 | * |
| 21 | * must be static so set your own ad type ID here |
| 22 | * use slug like format, only lower case, underscores and hyphens |
| 23 | * |
| 24 | * @since 1.6.10 |
| 25 | */ |
| 26 | public $ID = 'image'; |
| 27 | |
| 28 | /** |
| 29 | * set basic attributes |
| 30 | * |
| 31 | * @since 1.6.10 |
| 32 | */ |
| 33 | public function __construct() { |
| 34 | $this->title = __( 'Image Ad', 'advanced-ads' ); |
| 35 | $this->description = __( 'Ads in various image formats.', 'advanced-ads' ); |
| 36 | $this->parameters = array( |
| 37 | 'image_url' => '', |
| 38 | 'image_title' => '', |
| 39 | 'image_alt' => '', |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * output for the ad parameters metabox |
| 45 | * |
| 46 | * @param obj $ad ad object |
| 47 | * @since 1.6.10 |
| 48 | */ |
| 49 | public function render_parameters($ad){ |
| 50 | // load tinymc content exitor |
| 51 | $id = ( isset( $ad->output['image_id'] ) ) ? $ad->output['image_id'] : ''; |
| 52 | $url = ( isset( $ad->url ) ) ? esc_url( $ad->url ) : ''; |
| 53 | |
| 54 | ?><p><button href="#" class="advads_image_upload button button-secondary" type="button" data-uploader-title="<?php |
| 55 | _e( 'Insert File', 'advanced-ads' ); ?>" data-uploader-button-text="<?php _e( 'Insert', 'advanced-ads' ); ?>" onclick="return false;"><?php _e( 'select image', 'advanced-ads' ); ?></button> |
| 56 | <a id="advads-image-edit-link" href="<?php if( $id ){ echo get_edit_post_link( $id ); } ?>"><?php _e('edit', 'advanced-ads' ); ?></a> |
| 57 | </p> |
| 58 | <input type="hidden" name="advanced_ad[output][image_id]" value="<?php echo $id; ?>" id="advads-image-id"/> |
| 59 | <div id="advads-image-preview"> |
| 60 | <?php $this->create_image_tag( $id ); ?> |
| 61 | </div> |
| 62 | |
| 63 | <?php // don’t show if tracking plugin enabled |
| 64 | if( ! defined( 'AAT_VERSION' )) : ?> |
| 65 | <span class="label"><?php _e( 'URL', 'advanced-ads' ); ?></span> |
| 66 | <div> |
| 67 | <input type="url" name="advanced_ad[url]" id="advads-url" class="advads-ad-url" value="<?php echo $url; ?>" placeholder="<?php _e( 'Link to target site', 'advanced-ads' ); ?>" /></p> |
| 68 | </div><hr/><?php |
| 69 | endif; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * render image tag |
| 74 | * |
| 75 | * @param int $attachment_id post id of the image |
| 76 | * @since 1.6.10 |
| 77 | */ |
| 78 | public function create_image_tag( $attachment_id ){ |
| 79 | |
| 80 | $image = wp_get_attachment_image_src( $attachment_id, 'full' ); |
| 81 | if ( $image ) { |
| 82 | list( $src, $width, $height ) = $image; |
| 83 | $hwstring = image_hwstring($width, $height); |
| 84 | $attachment = get_post($attachment_id); |
| 85 | $alt = trim(esc_textarea( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )); |
| 86 | $title = trim(esc_textarea( $attachment->post_title )); // Finally, use the title |
| 87 | |
| 88 | global $wp_current_filter; |
| 89 | |
| 90 | $more_attributes = $srcset = $sizes = ''; |
| 91 | // create srcset and sizes attributes if we are in the the_content filter and in WordPress 4.4 |
| 92 | if( isset( $wp_current_filter ) |
| 93 | && in_array( 'the_content', $wp_current_filter ) |
| 94 | && ! defined( 'ADVADS_DISABLE_RESPONSIVE_IMAGES' )){ |
| 95 | if( function_exists( 'wp_get_attachment_image_srcset' ) ){ |
| 96 | $srcset = wp_get_attachment_image_srcset( $attachment_id, 'full' ); |
| 97 | } |
| 98 | if( function_exists( 'wp_get_attachment_image_sizes' ) ){ |
| 99 | $sizes = wp_get_attachment_image_sizes( $attachment_id, 'full' ); |
| 100 | } |
| 101 | if ( $srcset && $sizes ) { |
| 102 | $more_attributes .= ' srcset=\'' . $srcset . '\' sizes=\'' . $sizes . '\''; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | $more_attributes = apply_filters( 'advanced-ads-ad-image-tag-attributes', $more_attributes ); |
| 107 | |
| 108 | echo rtrim("<img $hwstring") . " src='$src' alt='$alt' title='$title' $more_attributes/>"; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * render image icon for overview pages |
| 114 | * |
| 115 | * @param int $attachment_id post id of the image |
| 116 | * @since 1.7.4 |
| 117 | */ |
| 118 | public function create_image_icon( $attachment_id ){ |
| 119 | |
| 120 | $image = wp_get_attachment_image_src( $attachment_id, 'medium', true ); |
| 121 | if ( $image ) { |
| 122 | list( $src, $width, $height ) = $image; |
| 123 | |
| 124 | // scale down width or height to max 100px |
| 125 | if( $width > $height ){ |
| 126 | $height = absint( $height / ( $width / 100 ) ); |
| 127 | $width = 100; |
| 128 | } else { |
| 129 | $width = absint( $width / ( $height / 100 ) ); |
| 130 | $height = 100; |
| 131 | } |
| 132 | |
| 133 | $hwstring = trim( image_hwstring($width, $height) ); |
| 134 | $attachment = get_post($attachment_id); |
| 135 | $alt = trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )); |
| 136 | |
| 137 | $title = ( $attachment instanceof WP_Post ) ? trim(strip_tags( $attachment->post_title )) : ''; // Finally, use the title |
| 138 | |
| 139 | echo "<img $hwstring src='$src' alt='$alt' title='$title'/>"; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * prepare the ads frontend output by adding <object> tags |
| 145 | * |
| 146 | * @param obj $ad ad object |
| 147 | * @return str $content ad content prepared for frontend output |
| 148 | * @since 1.6.10. |
| 149 | */ |
| 150 | public function prepare_output($ad){ |
| 151 | |
| 152 | $id = ( isset( $ad->output['image_id'] ) ) ? absint( $ad->output['image_id'] ) : ''; |
| 153 | $url = ( isset( $ad->url ) ) ? esc_url( $ad->url ) : ''; |
| 154 | // get general target setting |
| 155 | $options = Advanced_Ads::get_instance()->options(); |
| 156 | $target_blank = !empty( $options['target-blank'] ) ? ' target="_blank"' : ''; |
| 157 | |
| 158 | ob_start(); |
| 159 | if( ! defined( 'AAT_VERSION' ) && $url ){ echo '<a href="'. $url .'"'.$target_blank.'>'; } |
| 160 | echo $this->create_image_tag( $id ); |
| 161 | if( ! defined( 'AAT_VERSION' ) && $url ){ echo '</a>'; } |
| 162 | |
| 163 | return ob_get_clean(); |
| 164 | } |
| 165 | |
| 166 | } |
| 167 |