| @@ -16,11 +16,13 @@ | ||
| 16 | 16 | public $isPreview = false; |
| 17 | 17 | public $updir = null; |
| 18 | 18 | public $captions = false; |
| 19 | 19 | public $animation = null; |
| 20 | + public $infinite = false; | |
| 20 | 21 | |
| 21 | 22 | abstract function inline_css(); |
| 22 | 23 | |
| 24 | + // MEMO: Done migration to the React version. | |
| 23 | 25 | public function __construct( $atts, $infinite, $isPreview = false ) { |
| 24 | 26 | $wpUploadDir = wp_upload_dir(); |
| 25 | 27 | $options = get_option( Meow_MGL_Core::get_plugin_option_name(), null ); |
| 26 | 28 | $this->id = uniqid(); |
| @@ -28,9 +30,9 @@ | ||
| 28 | 30 | $this->size = apply_filters( 'mgl_media_size', $this->size ); |
| 29 | 31 | $this->infinite = $infinite; |
| 30 | 32 | $this->atts = $atts; |
| 31 | 33 | $this->customClass = isset( $atts['custom-class'] ) ? $atts['custom-class'] : null; |
| 32 | - $this->link = isset( $atts['link'] ) ? $atts['link'] : null; | |
| 34 | + $this->link = isset( $atts['link'] ) ? $atts['link'] : ( $options['link'] ?? null ); | |
| 33 | 35 | $this->align = isset( $atts['align'] ) ? $atts['align'] : $this->align; |
| 34 | 36 | $this->isPreview = $isPreview; |
| 35 | 37 | $this->class_id = 'mgl-gallery-' . $this->id; |
| 36 | 38 | $this->updir = trailingslashit( $wpUploadDir['baseurl'] ); |
| @@ -45,8 +47,10 @@ | ||
| 45 | 47 | function build_inline_attributes( $id, $data ) { |
| 46 | 48 | return ''; |
| 47 | 49 | } |
| 48 | 50 | |
| 51 | + | |
| 52 | + // MEMO: Done migration to the React version. | |
| 49 | 53 | function prepare_data( $idsStr ) { |
| 50 | 54 | global $wpdb; |
| 51 | 55 | |
| 52 | 56 | // Escape the array of IDs for SQL |
| @@ -82,9 +86,9 @@ | ||
| 82 | 86 | if ( empty( $image_size ) || $image_size === 'srcset' ) { |
| 83 | 87 | $imgSrc = wp_get_attachment_image( $id, $this->size, false, |
| 84 | 88 | $this->layout === 'carousel' ? |
| 85 | 89 | [ 'class' => 'skip-lazy' ] : |
| 86 | - [ 'class' => 'wp-image-' . $id ], | |
| 90 | + [ 'class' => 'wp-image-' . $id ] | |
| 87 | 91 | ); |
| 88 | 92 | } |
| 89 | 93 | else { |
| 90 | 94 | $info = wp_get_attachment_image_src( $id, $image_size ); |
| @@ -91,8 +95,9 @@ | ||
| 91 | 95 | $imgSrc = '<img loading="lazy" src="' . $info[0] . '" class="' . |
| 92 | 96 | ( $this->layout === 'carousel' ? 'skip-lazy' : ( 'wp-image-' . $id ) ) . '" />'; |
| 93 | 97 | } |
| 94 | 98 | $attributes = $this->build_inline_attributes( $id, $data ); |
| 99 | + $attributes = apply_filters( 'mgl_attributes', $attributes, $id, $data ); | |
| 95 | 100 | if ( !empty( $attributes ) ) { |
| 96 | 101 | $attributes = ' ' . $attributes; |
| 97 | 102 | } |
| 98 | 103 | |
| @@ -97,11 +102,16 @@ | ||
| 97 | 102 | } |
| 98 | 103 | |
| 99 | 104 | $linkUrl = null; |
| 100 | 105 | if ( $this->link === 'attachment' ) |
| 106 | + { | |
| 101 | 107 | $linkUrl = get_permalink( (int)$id ); |
| 108 | + } | |
| 102 | 109 | else if ( $this->link === 'media' || $this->link === 'file' ) |
| 110 | + { | |
| 103 | 111 | $linkUrl = $src; |
| 112 | + } | |
| 113 | + | |
| 104 | 114 | $linkUrl = apply_filters( 'mgl_link', $linkUrl, (int)$id, $data ); |
| 105 | 115 | $isPreview = $this->isPreview; |
| 106 | 116 | ob_start(); |
| 107 | 117 | include dirname( __FILE__ ) . '/cell.tpl.php'; |
| @@ -108,8 +118,9 @@ | ||
| 108 | 118 | $html = ob_get_clean(); |
| 109 | 119 | return $html; |
| 110 | 120 | } |
| 111 | 121 | |
| 122 | + // MEMO: Done migration to the React version. | |
| 112 | 123 | function build_container_classes() { |
| 113 | 124 | $classes = 'mgl-' . $this->layout . '-container'; |
| 114 | 125 | |
| 115 | 126 | // Align |
| @@ -117,8 +128,9 @@ | ||
| 117 | 128 | |
| 118 | 129 | return $classes; |
| 119 | 130 | } |
| 120 | 131 | |
| 132 | + // MEMO: Done migration to the React version. | |
| 121 | 133 | function build_classes() { |
| 122 | 134 | $classes = 'mgl-gallery'; |
| 123 | 135 | |
| 124 | 136 | // Layout |
| @@ -137,8 +149,9 @@ | ||
| 137 | 149 | |
| 138 | 150 | return $classes; |
| 139 | 151 | } |
| 140 | 152 | |
| 153 | + // MEMO: Done migration to the React version. | |
| 141 | 154 | function build_styles() { |
| 142 | 155 | return ""; |
| 143 | 156 | } |
| 144 | 157 | |
| @@ -155,8 +168,9 @@ | ||
| 155 | 168 | } |
| 156 | 169 | $out .= '</div>'; |
| 157 | 170 | $out = apply_filters( 'mgl_gallery_written', $out, $this->layout ); |
| 158 | 171 | |
| 172 | + // MEMO: Done migration to the React version. | |
| 159 | 173 | // Generate gallery container |
| 160 | 174 | $container_classes = $this->build_container_classes(); |
| 161 | 175 | $inline_css = $this->inline_css(); |
| 162 | 176 | if ( !empty( $inline_css ) ) { |