admin
8 months ago
compatibility
8 months ago
extensions
8 months ago
foopluginbase
8 months ago
public
8 months ago
thumbs
8 months ago
.DS_Store
8 months ago
class-attachment-filters.php
8 months ago
class-foogallery-animated-gif-support.php
8 months ago
class-foogallery-attachment-custom-class.php
8 months ago
class-foogallery-attachment-type.php
8 months ago
class-foogallery-attachment.php
8 months ago
class-foogallery-cache.php
8 months ago
class-foogallery-common-fields.php
8 months ago
class-foogallery-crop-position.php
8 months ago
class-foogallery-datasource-media_library.php
8 months ago
class-foogallery-debug.php
8 months ago
class-foogallery-extensions-compatibility.php
8 months ago
class-foogallery-force-https.php
8 months ago
class-foogallery-lazyload.php
8 months ago
class-foogallery-lightbox.php
8 months ago
class-foogallery-paging.php
8 months ago
class-foogallery-password-protect.php
8 months ago
class-foogallery-sitemaps.php
8 months ago
class-foogallery-widget.php
8 months ago
class-foogallery.php
8 months ago
class-gallery-advanced-settings.php
8 months ago
class-il8n.php
8 months ago
class-override-thumbnail.php
8 months ago
class-posttypes.php
8 months ago
class-retina.php
8 months ago
class-thumbnail-dimensions.php
8 months ago
class-thumbnails.php
8 months ago
class-version-check.php
8 months ago
constants.php
8 months ago
functions.php
8 months ago
includes.php
8 months ago
index.php
12 years ago
render-functions.php
8 months ago
class-foogallery-attachment.php
262 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class FooGalleryAttachment |
| 4 | * |
| 5 | * An easy to use wrapper class for a FooGallery Attachment |
| 6 | */ |
| 7 | if ( ! class_exists( 'FooGalleryAttachment' ) ) { |
| 8 | |
| 9 | class FooGalleryAttachment extends stdClass { |
| 10 | /** |
| 11 | * public constructor |
| 12 | * |
| 13 | * @param null $post |
| 14 | */ |
| 15 | public function __construct( $post = null ) { |
| 16 | $this->set_defaults(); |
| 17 | |
| 18 | if ( $post !== null ) { |
| 19 | $this->load( $post ); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Sets the default when a new gallery is instantiated |
| 25 | */ |
| 26 | private function set_defaults() { |
| 27 | $this->_post = null; |
| 28 | $this->ID = 0; |
| 29 | $this->type = 'image'; // set the default type to image. |
| 30 | $this->title = ''; |
| 31 | $this->caption = ''; |
| 32 | $this->description = ''; |
| 33 | $this->alt = ''; |
| 34 | $this->url = ''; |
| 35 | $this->width = 0; |
| 36 | $this->height = 0; |
| 37 | $this->custom_url = ''; |
| 38 | $this->custom_target = ''; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * private attachment load function |
| 43 | * @param $post | WP_Post |
| 44 | */ |
| 45 | private function load( $post ) { |
| 46 | $this->_post = $post; |
| 47 | $this->ID = $post->ID; |
| 48 | $this->title = trim( $post->post_title ); |
| 49 | $this->caption = trim( $post->post_excerpt ); |
| 50 | $this->description = trim( $post->post_content ); |
| 51 | $this->alt = trim( get_post_meta( $this->ID, '_wp_attachment_image_alt', true ) ); |
| 52 | $this->custom_url = get_post_meta( $this->ID, '_foogallery_custom_url', true ); |
| 53 | $this->custom_target = get_post_meta( $this->ID, '_foogallery_custom_target', true ); |
| 54 | $this->load_attachment_image_data( $this->ID ); |
| 55 | |
| 56 | $this->date = !empty( $post->post_date_gmt ) ? $post->post_date_gmt : $post->post_date; |
| 57 | $this->modified = !empty( $post->post_modified_gmt ) ? $post->post_modified_gmt : $post->post_modified; |
| 58 | |
| 59 | do_action( 'foogallery_attachment_instance_after_load', $this, $post ); |
| 60 | } |
| 61 | |
| 62 | public function load_attachment_image_data( $attachment_id ) { |
| 63 | $image_attributes = foogallery_get_full_size_image_data( $attachment_id ); |
| 64 | if ( $image_attributes ) { |
| 65 | $this->url = $image_attributes[0]; |
| 66 | $this->width = $image_attributes[1]; |
| 67 | $this->height = $image_attributes[2]; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Static function to load a FooGalleryAttachment instance by passing in a post object |
| 73 | * @static |
| 74 | * |
| 75 | * @param $post |
| 76 | * |
| 77 | * @return FooGalleryAttachment |
| 78 | */ |
| 79 | public static function get( $post ) { |
| 80 | return new self( $post ); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Static function to load a FooGalleryAttachment instance by passing in an attachment_id |
| 85 | * @static |
| 86 | * |
| 87 | * @param $attachment_id |
| 88 | * |
| 89 | * @return FooGalleryAttachment |
| 90 | */ |
| 91 | public static function get_by_id( $attachment_id ) { |
| 92 | $post = get_post( $attachment_id ); |
| 93 | return new self( $post ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Returns the image source only |
| 98 | * |
| 99 | * @param array $args |
| 100 | * @return string |
| 101 | */ |
| 102 | public function html_img_src( $args = array() ) { |
| 103 | return esc_url( apply_filters( 'foogallery_attachment_resize_thumbnail', $this->url, $args, $this ) ); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @deprecated 1.9.24 Functions inside render-functions.php should rather be used |
| 108 | * |
| 109 | * Returns the HTML img tag for the attachment |
| 110 | * @param array $args |
| 111 | * |
| 112 | * @return string |
| 113 | */ |
| 114 | public function html_img( $args = array() ) { |
| 115 | $attr['src'] = $this->html_img_src( $args ); |
| 116 | |
| 117 | if ( ! empty( $this->alt ) ) { |
| 118 | $attr['alt'] = $this->alt; |
| 119 | } |
| 120 | |
| 121 | //pull any custom attributes out the args |
| 122 | if ( isset( $args['image_attributes'] ) && is_array( $args['image_attributes'] ) ) { |
| 123 | $attr = array_merge( $attr, $args['image_attributes'] ); |
| 124 | } |
| 125 | |
| 126 | //check for width and height args and add those to the image |
| 127 | if ( isset( $args['width'] ) && intval( $args['width'] ) > 0 ) { |
| 128 | $attr['width'] = $args['width']; |
| 129 | } |
| 130 | if ( isset( $args['height'] ) && intval( $args['height'] ) > 0 ) { |
| 131 | $attr['height'] = $args['height']; |
| 132 | } |
| 133 | |
| 134 | $attr = apply_filters( 'foogallery_attachment_html_image_attributes', $attr, $args, $this ); |
| 135 | $attr = array_map( 'esc_attr', $attr ); |
| 136 | $html = '<img '; |
| 137 | foreach ( $attr as $name => $value ) { |
| 138 | $html .= " $name=" . '"' . $value . '"'; |
| 139 | } |
| 140 | $html .= ' />'; |
| 141 | |
| 142 | return apply_filters( 'foogallery_attachment_html_image', $html, $args, $this ); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @deprecated 1.9.24 Functions inside render-functions.php should rather be used |
| 147 | * |
| 148 | * Returns HTML for the attachment |
| 149 | * @param array $args |
| 150 | * @param bool $output_image |
| 151 | * @param bool $output_closing_tag |
| 152 | * |
| 153 | * @return string |
| 154 | */ |
| 155 | public function html( $args = array(), $output_image = true, $output_closing_tag = true ) { |
| 156 | if ( empty ( $this->url ) ) { |
| 157 | return ''; |
| 158 | } |
| 159 | |
| 160 | $arg_defaults = array( |
| 161 | 'link' => 'image', |
| 162 | 'custom_link' => $this->custom_url |
| 163 | ); |
| 164 | |
| 165 | $args = wp_parse_args( $args, $arg_defaults ); |
| 166 | |
| 167 | $link = $args['link']; |
| 168 | |
| 169 | $img = $this->html_img( $args ); |
| 170 | |
| 171 | /* 12 Apr 2016 - PLEASE NOTE |
| 172 | We no longer just return the image html when "no link" option is chosen. |
| 173 | It was decided that it is better to return an anchor link with no href or target attributes. |
| 174 | This results in more standardized HTML output for better CSS and JS code |
| 175 | */ |
| 176 | |
| 177 | if ( 'page' === $link ) { |
| 178 | //get the URL to the attachment page |
| 179 | $url = get_attachment_link( $this->ID ); |
| 180 | } else if ( 'custom' === $link ) { |
| 181 | $url = $args['custom_link']; |
| 182 | } else { |
| 183 | $url = $this->url; |
| 184 | } |
| 185 | |
| 186 | //fallback for images that might not have a custom url |
| 187 | if ( empty( $url ) ) { |
| 188 | $url = $this->url; |
| 189 | } |
| 190 | |
| 191 | $attr = array(); |
| 192 | |
| 193 | //only add href and target attributes to the anchor if the link is NOT set to 'none' |
| 194 | if ( $link !== 'none' ){ |
| 195 | $attr['href'] = $url; |
| 196 | if ( ! empty( $this->custom_target ) && 'default' !== $this->custom_target ) { |
| 197 | $attr['target'] = $this->custom_target; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | if ( ! empty( $this->caption ) ) { |
| 202 | $attr['data-caption-title'] = $this->caption; |
| 203 | } |
| 204 | |
| 205 | if ( !empty( $this->description ) ) { |
| 206 | $attr['data-caption-desc'] = $this->description; |
| 207 | } |
| 208 | |
| 209 | $attr['data-attachment-id'] = $this->ID; |
| 210 | |
| 211 | //pull any custom attributes out the args |
| 212 | if ( isset( $args['link_attributes'] ) && is_array( $args['link_attributes'] ) ) { |
| 213 | $attr = array_merge( $attr, $args['link_attributes'] ); |
| 214 | } |
| 215 | |
| 216 | $attr = apply_filters( 'foogallery_attachment_html_link_attributes', $attr, $args, $this ); |
| 217 | $attr = array_map( 'esc_attr', $attr ); |
| 218 | $html = '<a '; |
| 219 | foreach ( $attr as $name => $value ) { |
| 220 | $html .= " $name=" . '"' . $value . '"'; |
| 221 | } |
| 222 | $html .= '>'; |
| 223 | if ( $output_image ) { |
| 224 | $html .= $img; |
| 225 | } |
| 226 | if ( $output_closing_tag ) { |
| 227 | $html .= '</a>'; |
| 228 | }; |
| 229 | |
| 230 | return apply_filters( 'foogallery_attachment_html_link', $html, $args, $this ); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @deprecated 1.9.24 Functions inside render-functions.php should rather be used |
| 235 | * |
| 236 | * Returns generic html for captions |
| 237 | * |
| 238 | * @param $caption_content string Include title, desc, or both |
| 239 | * |
| 240 | * @return string |
| 241 | */ |
| 242 | public function html_caption( $caption_content ) { |
| 243 | $html = ''; |
| 244 | $caption_html = array(); |
| 245 | if ( $this->caption && ( 'title' === $caption_content || 'both' === $caption_content ) ) { |
| 246 | $caption_html[] = '<div class="foogallery-caption-title">' . $this->caption . '</div>'; |
| 247 | } |
| 248 | if ( $this->description && ( 'desc' === $caption_content || 'both' === $caption_content ) ) { |
| 249 | $caption_html[] = '<div class="foogallery-caption-desc">' . $this->description . '</div>'; |
| 250 | } |
| 251 | |
| 252 | if ( count($caption_html) > 0 ) { |
| 253 | $html = '<div class="foogallery-caption"><div class="foogallery-caption-inner">'; |
| 254 | $html .= implode( $caption_html ); |
| 255 | $html .= '</div></div>'; |
| 256 | } |
| 257 | |
| 258 | return apply_filters( 'foogallery_attachment_html_caption', $html, $caption_content, $this ); |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 |