PluginProbe
Meow Gallery / 4.1.6
Meow Gallery v4.1.6
5.5.5 5.5.4 5.5.3 5.5.2 5.5.1 5.5.0 5.4.9 5.4.8 5.4.7 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 All 157 releases
meow-gallery / classes / builders / core.php

core.php in Meow Gallery 4.1.6, at classes/builders/core.php

168 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 abstract class Meow_MGL_Builders_Core {
4
5 public $id = null;
6 public $layout = 'none';
7 public $class_id = 'mgl-gallery-none';
8 public $img_class = '';
9 public $size = 'large';
10 public $customClass = '';
11 public $align = null;
12 public $ids = array();
13 public $link = null;
14 public $atts = array();
15 public $data = array();
16 public $isPreview = false;
17 public $updir = null;
18 public $captions = false;
19 public $animation = null;
20
21 abstract function inline_css();
22
23 public function __construct( $atts, $infinite, $isPreview = false ) {
24 $wpUploadDir = wp_upload_dir();
25 $this->id = uniqid();
26 $this->size = isset( $atts['size'] ) ? $atts['size'] : $this->size;
27 $this->size = apply_filters( 'mgl_media_size', $this->size );
28 $this->infinite = $infinite;
29 $this->atts = $atts;
30 $this->customClass = isset( $atts['custom-class'] ) ? $atts['custom-class'] : null;
31 $this->link = isset( $atts['link'] ) ? $atts['link'] : null;
32 $this->align = isset( $atts['align'] ) ? $atts['align'] : $this->align;
33 $this->isPreview = $isPreview;
34 $this->class_id = 'mgl-gallery-' . $this->id;
35 $this->updir = trailingslashit( $wpUploadDir['baseurl'] );
36 $this->captions = isset( $atts['captions'] ) ? $atts['captions'] : get_option( 'mgl_captions', 'none' );
37 $this->animation = null;
38 if ( isset( $atts['animation'] ) && $atts['animation'] != 'default' )
39 $this->animation = $atts['animation'];
40 else
41 $this->animation = get_option( 'mgl_animation', null );
42 }
43
44 function build_inline_attributes( $id, $data ) {
45 return '';
46 }
47
48 function prepare_data( $idsStr ) {
49 global $wpdb;
50 $query = "SELECT p.ID id, p.post_excerpt caption, m.meta_value meta
51 FROM $wpdb->posts p, $wpdb->postmeta m
52 WHERE m.meta_key = '_wp_attachment_metadata'
53 AND p.ID = m.post_id
54 AND p.ID IN (" . esc_sql( $idsStr ) . ")";
55 $res = $wpdb->get_results( $query );
56 $this->ids = explode( ',', $idsStr );
57 foreach ( $res as $r ) {
58 $this->data[$r->id] = array( 'caption' => $r->caption,'meta' => unserialize( $r->meta ) );
59 }
60 $this->ids = array_reverse( $this->ids );
61 $cleanIds = array();
62 foreach ( $this->ids as $id ) {
63 if ( isset( $this->data[$id] ) )
64 array_push( $cleanIds, $id );
65 }
66 $this->ids = apply_filters( 'mgl_sort', $cleanIds, $this->data, $this->layout, $this->atts );
67 }
68
69 function build_next_cell( $id, $data ) {
70 $src = $this->updir . $data['meta']['file'];
71 $data['caption'] = apply_filters( 'mgl_caption', $data['caption'], $id );
72 $caption = $this->captions ? $data['caption'] : '';
73
74 $image_size = get_option( 'mgl_image_size', 'srcset' );
75 $imgSrc = null;
76 if ( empty( $image_size ) || $image_size === 'srcset' ) {
77 $imgSrc = wp_get_attachment_image( $id, $this->size, false,
78 $this->layout === 'carousel' ? array( 'class' => 'skip-lazy' ) : array( 'class' => 'wp-image-' . $id ) );
79 }
80 else {
81 $info = wp_get_attachment_image_src( $id, $image_size );
82 $imgSrc = '<img src="' . $info[0] . '" class="' .
83 ( $this->layout === 'carousel' ? 'skip-lazy' : ( 'wp-image-' . $id ) ) . '" />';
84 }
85
86 $attributes = $this->build_inline_attributes( $id, $data );
87 if ( !empty( $attributes ) ) {
88 $attributes = ' ' . $attributes;
89 }
90
91 $linkUrl = null;
92 if ( $this->link === 'attachment' )
93 $linkUrl = get_permalink( (int)$id );
94 else if ( $this->link === 'media' || $this->link === 'file' )
95 $linkUrl = $src;
96 $linkUrl = apply_filters( 'mgl_link', $linkUrl, (int)$id, $data );
97 $isPreview = $this->isPreview;
98 ob_start();
99 include dirname( __FILE__ ) . '/cell.tpl.php';
100 $html = ob_get_clean();
101 return $html;
102 }
103
104 function build_container_classes() {
105 $classes = 'mgl-' . $this->layout . '-container';
106
107 // Align
108 $classes .= $this->align ? (' align' . $this->align) : '';
109
110 return $classes;
111 }
112
113 function build_classes() {
114 $classes = 'mgl-gallery';
115
116 // Layout
117 $classes .= ' mgl-' . $this->layout;
118
119 // Custom Class
120 $classes .= $this->customClass ? ( ' ' . $this->customClass ) : '';
121
122 // Animation
123 if ( $this->animation )
124 $classes .= ' is-animated ' . $this->animation;
125
126 // Captions
127 if ( $this->captions )
128 $classes .= ' captions-' . $this->captions;
129
130 return $classes;
131 }
132
133 function build_styles() {
134 return "";
135 }
136
137 function build( $idsStr ) {
138
139 // Generate gallery
140 $classes = $this->build_classes();
141 $styles = $this->build_styles();
142 $out = "<div id='{$this->class_id}' class='{$classes}' style='{$styles}'>";
143 $this->prepare_data( $idsStr );
144 while ( count( $this->ids ) > 0 ) {
145 $id = array_pop( $this->ids );
146 $out .= $this->build_next_cell( $id, $this->data[$id] );
147 }
148 $out .= '</div>';
149 $out = apply_filters( 'mgl_gallery_written', $out, $this->layout );
150
151 // Generate gallery container
152 $container_classes = $this->build_container_classes();
153 $inline_css = $this->inline_css();
154 if ( !empty( $inline_css ) ) {
155 $inline_css = preg_replace( "/\r|\n/", "", $inline_css );
156 $container = "<div class='{$container_classes}'>{$inline_css}{$out}</div>";
157 }
158 else {
159 $container = "<div class='{$container_classes}'>{$out}</div>";
160 }
161
162 return $container;
163 }
164
165 }
166
167 ?>
168