abilities
1 month ago
admin
1 month ago
compatibility
1 month ago
extensions
1 month ago
foopluginbase
1 month ago
public
1 month ago
thumbs
1 month ago
asset-manifest.php
1 month ago
class-attachment-filters.php
1 month ago
class-command-palette.php
1 month ago
class-foogallery-animated-gif-support.php
1 month ago
class-foogallery-attachment-custom-class.php
1 month ago
class-foogallery-attachment-filename.php
1 month ago
class-foogallery-attachment-type.php
1 month ago
class-foogallery-attachment.php
1 month ago
class-foogallery-cache.php
1 month ago
class-foogallery-common-fields.php
1 month ago
class-foogallery-crop-position.php
1 month ago
class-foogallery-datasource-media_library.php
1 month ago
class-foogallery-debug.php
1 month ago
class-foogallery-delayed-runtime-loader.php
1 month ago
class-foogallery-extensions-compatibility.php
1 month ago
class-foogallery-force-https.php
1 month ago
class-foogallery-lazyload.php
1 month ago
class-foogallery-license-constant-handler.php
1 month ago
class-foogallery-lightbox.php
1 month ago
class-foogallery-paging.php
1 month ago
class-foogallery-password-protect.php
1 month ago
class-foogallery-sitemaps.php
1 month ago
class-foogallery-widget.php
1 month ago
class-foogallery.php
1 month ago
class-gallery-advanced-settings.php
1 month ago
class-il8n.php
1 month ago
class-override-thumbnail.php
1 month ago
class-posttypes.php
1 month ago
class-previews.php
1 month ago
class-retina.php
1 month ago
class-thumbnail-dimensions.php
1 month ago
class-thumbnails.php
1 month ago
class-version-check.php
1 month ago
constants.php
1 month ago
functions.php
1 month ago
gallery-management-functions.php
1 month ago
includes.php
1 month ago
index.php
1 month ago
render-functions.php
1 month ago
class-foogallery-attachment.php
159 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Class FooGalleryAttachment |
| 9 | * |
| 10 | * An easy to use wrapper class for a FooGallery Attachment |
| 11 | */ |
| 12 | if ( ! class_exists( 'FooGalleryAttachment' ) ) { |
| 13 | |
| 14 | class FooGalleryAttachment extends stdClass { |
| 15 | /** |
| 16 | * public constructor |
| 17 | * |
| 18 | * @param null $post |
| 19 | */ |
| 20 | public function __construct( $post = null ) { |
| 21 | $this->set_defaults(); |
| 22 | |
| 23 | if ( $post !== null ) { |
| 24 | $this->load( $post ); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Sets the default when a new gallery is instantiated |
| 30 | */ |
| 31 | private function set_defaults() { |
| 32 | $this->_post = null; |
| 33 | $this->ID = 0; |
| 34 | $this->type = 'image'; // set the default type to image. |
| 35 | $this->title = ''; |
| 36 | $this->caption = ''; |
| 37 | $this->description = ''; |
| 38 | $this->alt = ''; |
| 39 | $this->url = ''; |
| 40 | $this->width = 0; |
| 41 | $this->height = 0; |
| 42 | $this->parent_post_id = 0; |
| 43 | $this->parent_post_url = ''; |
| 44 | $this->custom_url = ''; |
| 45 | $this->custom_target = ''; |
| 46 | $this->custom_rel = ''; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * private attachment load function |
| 51 | * @param $post | WP_Post |
| 52 | */ |
| 53 | private function load( $post ) { |
| 54 | $this->_post = $post; |
| 55 | $this->ID = $post->ID; |
| 56 | $this->title = trim( $post->post_title ); |
| 57 | $this->caption = trim( $post->post_excerpt ); |
| 58 | $this->description = trim( $post->post_content ); |
| 59 | $this->alt = trim( get_post_meta( $this->ID, '_wp_attachment_image_alt', true ) ); |
| 60 | $this->custom_url = foogallery_sanitize_attachment_custom_url( get_post_meta( $this->ID, '_foogallery_custom_url', true ) ); |
| 61 | $this->custom_target = foogallery_sanitize_attachment_custom_target( get_post_meta( $this->ID, '_foogallery_custom_target', true ) ); |
| 62 | $this->custom_rel = foogallery_sanitize_attachment_custom_rel( get_post_meta( $this->ID, '_foogallery_custom_rel', true ) ); |
| 63 | $this->parent_post_id = (int) $post->post_parent; |
| 64 | if ( $this->parent_post_id > 0 ) { |
| 65 | $this->parent_post_url = get_permalink( $this->parent_post_id ); |
| 66 | } |
| 67 | $this->load_attachment_image_data( $this->ID ); |
| 68 | |
| 69 | $this->date = !empty( $post->post_date_gmt ) ? $post->post_date_gmt : $post->post_date; |
| 70 | $this->modified = !empty( $post->post_modified_gmt ) ? $post->post_modified_gmt : $post->post_modified; |
| 71 | |
| 72 | do_action( 'foogallery_attachment_instance_after_load', $this, $post ); |
| 73 | } |
| 74 | |
| 75 | public function load_attachment_image_data( $attachment_id ) { |
| 76 | $image_attributes = foogallery_get_full_size_image_data( $attachment_id ); |
| 77 | if ( $image_attributes ) { |
| 78 | $this->url = $image_attributes[0]; |
| 79 | $this->width = $image_attributes[1]; |
| 80 | $this->height = $image_attributes[2]; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Static function to load a FooGalleryAttachment instance by passing in a post object |
| 86 | * @static |
| 87 | * |
| 88 | * @param $post |
| 89 | * |
| 90 | * @return FooGalleryAttachment |
| 91 | */ |
| 92 | public static function get( $post ) { |
| 93 | return new self( $post ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Static function to load a FooGalleryAttachment instance by passing in an attachment_id |
| 98 | * @static |
| 99 | * |
| 100 | * @param $attachment_id |
| 101 | * |
| 102 | * @return FooGalleryAttachment |
| 103 | */ |
| 104 | public static function get_by_id( $attachment_id ) { |
| 105 | $post = get_post( $attachment_id ); |
| 106 | return new self( $post ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Returns the image source only |
| 111 | * |
| 112 | * @param array $args |
| 113 | * @return string |
| 114 | */ |
| 115 | public function html_img_src( $args = array() ) { |
| 116 | return esc_url( apply_filters( 'foogallery_attachment_resize_thumbnail', $this->url, $args, $this ) ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @deprecated 1.9.24 Functions inside render-functions.php should rather be used |
| 121 | * |
| 122 | * Returns the HTML img tag for the attachment |
| 123 | * @param array $args |
| 124 | * |
| 125 | * @return string |
| 126 | */ |
| 127 | public function html_img( $args = array() ) { |
| 128 | return foogallery_attachment_html_image( $this, $args ); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * @deprecated 1.9.24 Functions inside render-functions.php should rather be used |
| 133 | * |
| 134 | * Returns HTML for the attachment |
| 135 | * @param array $args |
| 136 | * @param bool $output_image |
| 137 | * @param bool $output_closing_tag |
| 138 | * |
| 139 | * @return string |
| 140 | */ |
| 141 | public function html( $args = array(), $output_image = true, $output_closing_tag = true ) { |
| 142 | return foogallery_attachment_html_anchor( $this, $args, $output_image, $output_closing_tag ); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * @deprecated 1.9.24 Functions inside render-functions.php should rather be used |
| 147 | * |
| 148 | * Returns generic html for captions |
| 149 | * |
| 150 | * @param $caption_content string Include title, desc, or both |
| 151 | * |
| 152 | * @return string |
| 153 | */ |
| 154 | public function html_caption( $caption_content ) { |
| 155 | return foogallery_attachment_html_caption( $this ); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 |