PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / class-foogallery-attachment-type.php
foogallery / includes Last commit date
abilities 2 months ago admin 2 months ago compatibility 2 months ago extensions 2 months ago foopluginbase 2 months ago public 2 months ago thumbs 2 months ago asset-manifest.php 2 months ago class-attachment-filters.php 2 months ago class-command-palette.php 2 months ago class-foogallery-animated-gif-support.php 2 months ago class-foogallery-attachment-custom-class.php 2 months ago class-foogallery-attachment-filename.php 2 months ago class-foogallery-attachment-type.php 2 months ago class-foogallery-attachment.php 2 months ago class-foogallery-cache.php 2 months ago class-foogallery-common-fields.php 2 months ago class-foogallery-crop-position.php 2 months ago class-foogallery-datasource-media_library.php 2 months ago class-foogallery-debug.php 2 months ago class-foogallery-delayed-runtime-loader.php 2 months ago class-foogallery-extensions-compatibility.php 2 months ago class-foogallery-force-https.php 2 months ago class-foogallery-lazyload.php 2 months ago class-foogallery-license-constant-handler.php 2 months ago class-foogallery-lightbox.php 2 months ago class-foogallery-paging.php 2 months ago class-foogallery-password-protect.php 2 months ago class-foogallery-sitemaps.php 2 months ago class-foogallery-widget.php 2 months ago class-foogallery.php 2 months ago class-gallery-advanced-settings.php 2 months ago class-il8n.php 2 months ago class-override-thumbnail.php 2 months ago class-posttypes.php 2 months ago class-previews.php 2 months ago class-retina.php 2 months ago class-thumbnail-dimensions.php 2 months ago class-thumbnails.php 2 months ago class-version-check.php 2 months ago constants.php 2 months ago functions.php 2 months ago includes.php 2 months ago index.php 2 months ago render-functions.php 2 months ago
class-foogallery-attachment-type.php
98 lines
1 <?php
2 if ( ! class_exists('FooGallery_Attachment_Type') ) {
3
4 class FooGallery_Attachment_Type {
5
6 function __construct() {
7 //determine the type of the attachment
8 add_action( 'foogallery_attachment_instance_after_load', array( $this, 'determine_type' ), 99, 2 );
9
10 //add attachment field for custom type
11 add_filter( 'foogallery_attachment_custom_fields', array( $this, 'add_override_type_field' ), 50 );
12
13 //add attributes to front-end anchor
14 add_filter( 'foogallery_attachment_html_link_attributes', array( $this, 'alter_link_attributes' ), 30, 3 );
15 }
16
17 /**
18 * Determines the type of the item
19 *
20 * @param $foogallery_attachment FooGalleryAttachment
21 * @param $post WP_Post
22 */
23 function determine_type( $foogallery_attachment, $post ) {
24 if ( isset( $foogallery_attachment->is_video ) && $foogallery_attachment->is_video === true ) {
25 $foogallery_attachment->type = 'video';
26
27 //check if we have set the type to embed
28 if ( isset( $foogallery_attachment->is_embed ) && $foogallery_attachment->is_embed === true ) {
29 $foogallery_attachment->type = 'embed';
30 }
31 } else {
32 $link = foogallery_gallery_template_setting( 'thumbnail_link', 'image' );
33 if ( 'page' === $link || ( 'parent_post' === $link && ! empty( $foogallery_attachment->parent_post_url ) ) || ( 'custom' === $link && ! empty( $foogallery_attachment->custom_url ) ) ) {
34 // let's check if the custom URL is an image.
35 if ( 'custom' === $link && $this->check_maybe_image( $foogallery_attachment->custom_url ) ) {
36 $foogallery_attachment->type = 'image';
37 } else {
38 $foogallery_attachment->type = 'iframe';
39 }
40 }
41 }
42
43 // check if we have overridden the type for the attachment
44 $override_type = get_post_meta( $foogallery_attachment->ID, '_foogallery_override_type', true );
45 if ( ! empty( $override_type ) ) {
46 $foogallery_attachment->type = sanitize_title( $override_type );
47 }
48 }
49
50 /**
51 * Checks to see if the url is maybe an image based on the extension
52 *
53 * @param string $url The url to check.
54 *
55 * @return false
56 */
57 private function check_maybe_image( $url ) {
58 $known_image_extensions = array( 'gif', 'jpg', 'jpeg', 'png', 'tiff', 'tif', 'bmp', 'svg', 'webp' );
59 $url_extension = pathinfo( $url, PATHINFO_EXTENSION );
60 return in_array( $url_extension, $known_image_extensions, true );
61 }
62
63 /**
64 * Adds a override type field to the attachments
65 *
66 * @param $fields array
67 *
68 * @return array
69 */
70 function add_override_type_field( $fields ) {
71 $fields['foogallery_override_type'] = array(
72 'label' => __( 'Override Type', 'foogallery' ),
73 'input' => 'text',
74 'helps' => __( 'Override the type of the attachment used by lightbox', 'foogallery' ),
75 'exclusions' => array( 'audio', 'video' ),
76 );
77
78 return $fields;
79 }
80
81
82 /**
83 * @uses "foogallery_attachment_html_link_attributes" filter
84 *
85 * @param $attr
86 * @param $args
87 * @param object|FooGalleryAttachment $attachment
88 *
89 * @return mixed
90 */
91 public function alter_link_attributes( $attr, $args, $attachment ) {
92 $attr['data-type'] = $attachment->type;
93
94 return $attr;
95 }
96 }
97 }
98