1 | <?php |
||
7 | class FooGallery_Masonry_Gallery_Template { |
||
|
|||
8 | /** |
||
9 | * Wire up everything we need to run the extension |
||
10 | */ |
||
11 | function __construct() { |
||
12 | add_filter( 'foogallery_gallery_templates', array( $this, 'add_template' ) ); |
||
13 | add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) ); |
||
14 | add_filter( 'foogallery_located_template-masonry', array( $this, 'enqueue_dependencies' ) ); |
||
15 | |||
16 | add_filter( 'foogallery_template_thumbnail_dimensions-masonry', array( $this, 'get_thumbnail_dimensions' ), 10, 2 ); |
||
17 | |||
18 | //add extra fields to the templates |
||
19 | add_filter( 'foogallery_override_gallery_template_fields-masonry', array( $this, 'add_common_thumbnail_fields' ), 10, 2 ); |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * Register myself so that all associated JS and CSS files can be found and automatically included |
||
24 | * @param $extensions |
||
25 | * |
||
26 | * @return array |
||
27 | */ |
||
28 | function register_myself( $extensions ) { |
||
29 | $extensions[] = __FILE__; |
||
30 | return $extensions; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Add our gallery template to the list of templates available for every gallery |
||
35 | * @param $gallery_templates |
||
36 | * |
||
37 | * @return array |
||
38 | */ |
||
39 | function add_template( $gallery_templates ) { |
||
40 | $gallery_templates[] = array( |
||
41 | 'slug' => 'masonry', |
||
42 | 'name' => __( 'Masonry Image Gallery', 'foogallery' ), |
||
43 | 'lazyload_support' => true, |
||
44 | 'admin_js' => FOOGALLERY_MASONRY_GALLERY_TEMPLATE_URL . 'js/admin-gallery-masonry.js', |
||
45 | 'fields' => array( |
||
46 | array( |
||
47 | 'id' => 'thumbnail_width', |
||
48 | 'title' => __( 'Thumb Width', 'foogallery' ), |
||
49 | 'desc' => __( 'Choose the width of your thumbnails. Thumbnails will be generated on the fly and cached once generated', 'foogallery' ), |
||
50 | 'section' => __( 'General', 'foogallery' ), |
||
51 | 'type' => 'number', |
||
52 | 'class' => 'small-text', |
||
53 | 'default' => 150, |
||
54 | 'step' => '1', |
||
55 | 'min' => '0', |
||
56 | ), |
||
57 | array( |
||
58 | 'id' => 'layout', |
||
59 | 'title' => __( 'Masonry Layout', 'foogallery' ), |
||
60 | 'desc' => __( 'Choose a fixed width thumb layout, or responsive columns.', 'foogallery' ), |
||
61 | 'section' => __( 'General', 'foogallery' ), |
||
62 | 'type' => 'radio', |
||
63 | 'choices' => array( |
||
64 | 'fixed' => __( 'Fixed Width', 'foogallery' ), |
||
65 | '2col' => __( '2 Columns', 'foogallery' ), |
||
66 | '3col' => __( '3 Columns', 'foogallery' ), |
||
67 | '4col' => __( '4 Columns', 'foogallery' ), |
||
68 | '5col' => __( '5 Columns', 'foogallery' ) |
||
69 | ), |
||
70 | 'default' => 'fixed', |
||
71 | 'row_data'=> array( |
||
72 | 'data-foogallery-change-selector' => 'input:radio', |
||
73 | 'data-foogallery-value-selector' s=> 'input:checked' |
||
74 | ) |
||
75 | ), |
||
76 | array( |
||
77 | 'id' => 'gutter_width', |
||
78 | 'title' => __( 'Gutter Width', 'foogallery' ), |
||
79 | 'desc' => __( 'The spacing between your thumbnails. Only applicable when using a fixed layout!', 'foogallery' ), |
||
80 | 'section' => __( 'General', 'foogallery' ), |
||
81 | 'type' => 'number', |
||
82 | 'class' => 'small-text', |
||
83 | 'default' => 10, |
||
84 | 'step' => '1', |
||
85 | 'min' => '0', |
||
86 | 'row_data'=> array( |
||
87 | 'data-foogallery-hidden' => true, |
||
88 | 'data-foogallery-show-when-field' => 'layout', |
||
89 | 'data-foogallery-show-when-field-value' => 'fixed' |
||
90 | ) |
||
91 | ), |
||
92 | array( |
||
93 | 'id' => 'gutter_percent', |
||
94 | 'title' => __( 'Gutter Size', 'foogallery' ), |
||
95 | 'desc' => __( 'Choose a gutter size when using responsive columns.', 'foogallery' ), |
||
96 | 'section' => __( 'General', 'foogallery' ), |
||
97 | 'type' => 'radio', |
||
98 | 'choices' => array( |
||
99 | 'no-gutter' => __( 'No Gutter', 'foogallery' ), |
||
100 | '' => __( 'Normal Size Gutter', 'foogallery' ), |
||
101 | 'large-gutter' => __( 'Larger Gutter', 'foogallery' ) |
||
102 | ), |
||
103 | 'default' => '', |
||
104 | 'row_data'=> array( |
||
105 | 'data-foogallery-hidden' => true, |
||
106 | 'data-foogallery-show-when-field' => 'layout', |
||
107 | 'data-foogallery-show-when-field-operator' => '!==', |
||
108 | 'data-foogallery-show-when-field-value' => 'fixed' |
||
109 | ) |
||
110 | ), |
||
111 | array( |
||
112 | 'id' => 'center_align', |
||
113 | 'title' => __( 'Alignment', 'foogallery' ), |
||
114 | 'desc' => __( 'You can choose to center align your images or leave them at the default (left). Only applicable when using a fixed layout!', 'foogallery' ), |
||
115 | 'section' => __( 'Look & Feel', 'foogallery' ), |
||
116 | 'type' => 'radio', |
||
117 | 'spacer' => '<span class="spacer"></span>', |
||
118 | 'choices' => array( |
||
119 | 'default' => __( 'Left', 'foogallery' ), |
||
120 | 'center' => __( 'Center', 'foogallery' ), |
||
121 | 'right' => __( 'Right', 'foogallery' ) |
||
122 | ), |
||
123 | 'default' => 'default' |
||
124 | ), |
||
125 | array( |
||
126 | 'id' => 'thumbnail_link', |
||
127 | 'title' => __( 'Thumb Link', 'foogallery' ), |
||
128 | 'default' => 'image' , |
||
129 | 'type' => 'thumb_link', |
||
130 | 'desc' => __( 'You can choose to link each thumbnail to the full size image, or to the image\'s attachment page, or you can choose to not link to anything', 'foogallery' ), |
||
131 | ), |
||
132 | array( |
||
133 | 'id' => 'lightbox', |
||
134 | 'title' => __( 'Lightbox', 'foogallery' ), |
||
135 | 'desc' => __( 'Choose which lightbox you want to display images with. The lightbox will only work if you set the thumbnail link to "Full Size Image"', 'foogallery' ), |
||
136 | 'type' => 'lightbox', |
||
137 | ), |
||
138 | ), |
||
139 | ); |
||
140 | |||
141 | |||
142 | return $gallery_templates; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Enqueue scripts that the masonry gallery template relies on |
||
147 | */ |
||
148 | function enqueue_dependencies() { |
||
149 | wp_enqueue_script( 'jquery' ); |
||
150 | wp_enqueue_script( 'masonry' ); |
||
151 | |||
152 | //enqueue core files |
||
153 | foogallery_enqueue_core_gallery_template_style(); |
||
154 | foogallery_enqueue_core_gallery_template_script(); |
||
155 | |||
156 | $css = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'masonry/css/foogallery.masonry.min.css'; |
||
157 | wp_enqueue_style( 'foogallery-masonry', $css, array( 'foogallery-core' ), FOOGALLERY_VERSION ); |
||
158 | |||
159 | $js = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'masonry/js/foogallery.masonry.min.js'; |
||
160 | wp_enqueue_script( 'foogallery-masonry', $js, array( 'foogallery-core' ), FOOGALLERY_VERSION ); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Get the thumb dimensions arguments saved for the gallery for this gallery template |
||
165 | * |
||
166 | * @param array $dimensions |
||
167 | * @param FooGallery $foogallery |
||
168 | * |
||
169 | * @return mixed |
||
170 | */ |
||
171 | function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
||
172 | $width = $foogallery->get_meta( 'masonry_thumbnail_width', false ); |
||
173 | return array( |
||
174 | 'height' => 0, |
||
175 | 'width' => intval( $width ), |
||
176 | 'crop' => false |
||
177 | ); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Add thumbnail fields to the gallery template |
||
182 | * |
||
183 | * @uses "foogallery_override_gallery_template_fields" |
||
184 | * @param $fields |
||
185 | * @param $template |
||
186 | * |
||
187 | * @return array |
||
188 | */ |
||
189 | function add_common_thumbnail_fields( $fields, $template ) { |
||
190 | return apply_filters( 'foogallery_gallery_template_common_thumbnail_fields', $fields ); |
||
191 | } |
||
192 | } |
||
193 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.