1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( !class_exists( 'FooGallery_Justified_Gallery_Template' ) ) { |
4
|
|
|
|
5
|
|
|
define('FOOGALLERY_JUSTIFIED_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ )); |
6
|
|
|
|
7
|
|
|
class FooGallery_Justified_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_template_thumbnail_dimensions-justified', array( $this, 'get_thumbnail_dimensions' ), 10, 2 ); |
15
|
|
|
|
16
|
|
|
//add extra fields to the templates |
17
|
|
|
add_filter( 'foogallery_override_gallery_template_fields-justified', array( $this, 'add_common_thumbnail_fields' ), 10, 2 ); |
18
|
|
|
|
19
|
|
|
add_action( 'foogallery_located_template-justified', array( $this, 'enqueue_dependencies' ) ); |
20
|
|
|
|
21
|
|
|
//add the data options needed for justified |
22
|
|
|
add_filter( 'foogallery_build_container_data_options-justified', array( $this, 'add_justified_options' ), 10, 3 ); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
27
|
|
|
* @param $extensions |
28
|
|
|
* |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
32
|
|
|
$extensions[] = __FILE__; |
33
|
|
|
return $extensions; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Add our gallery template to the list of templates available for every gallery |
38
|
|
|
* @param $gallery_templates |
39
|
|
|
* |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
43
|
|
|
$gallery_templates[] = array( |
44
|
|
|
'slug' => 'justified', |
45
|
|
|
'name' => __( 'Justified Gallery', 'foogallery' ), |
46
|
|
|
'lazyload_support' => true, |
47
|
|
|
'fields' => array( |
48
|
|
|
array( |
49
|
|
|
'id' => 'thumb_height', |
50
|
|
|
'title' => __( 'Thumb Height', 'foogallery' ), |
51
|
|
|
'desc' => __( 'Choose the height of your thumbnails. Thumbnails will be generated on the fly and cached once generated', 'foogallery' ), |
52
|
|
|
'section' => __( 'General', 'foogallery' ), |
53
|
|
|
'type' => 'number', |
54
|
|
|
'class' => 'small-text', |
55
|
|
|
'default' => 250, |
56
|
|
|
'step' => '10', |
57
|
|
|
'min' => '0', |
58
|
|
|
), |
59
|
|
|
array( |
60
|
|
|
'id' => 'row_height', |
61
|
|
|
'title' => __( 'Row Height', 'foogallery' ), |
62
|
|
|
'desc' => __( 'The preferred height of your gallery rows. This can be different from the thumbnail height', 'foogallery' ), |
63
|
|
|
'section' => __( 'General', 'foogallery' ), |
64
|
|
|
'type' => 'number', |
65
|
|
|
'class' => 'small-text', |
66
|
|
|
'default' => 150, |
67
|
|
|
'step' => '10', |
68
|
|
|
'min' => '0', |
69
|
|
|
'row_data'=> array( |
70
|
|
|
'data-foogallery-change-selector' => 'input', |
71
|
|
|
'data-foogallery-value-selector' => 'input', |
72
|
|
|
'data-foogallery-preview' => 'data', |
73
|
|
|
) |
74
|
|
|
), |
75
|
|
|
array( |
76
|
|
|
'id' => 'max_row_height', |
77
|
|
|
'title' => __( 'Max Row Height', 'foogallery' ), |
78
|
|
|
'desc' => __( 'A number (e.g 200) which specifies the maximum row height in pixels. A negative value for no limits. Alternatively, use a percentage (e.g. 200% which means that the row height cannot exceed 2 * rowHeight)', 'foogallery' ), |
79
|
|
|
'section' => __( 'General', 'foogallery' ), |
80
|
|
|
'type' => 'text', |
81
|
|
|
'class' => 'small-text', |
82
|
|
|
'default' => '200%', |
83
|
|
|
'row_data'=> array( |
84
|
|
|
'data-foogallery-change-selector' => 'input', |
85
|
|
|
'data-foogallery-value-selector' => 'input', |
86
|
|
|
'data-foogallery-preview' => 'data', |
87
|
|
|
) |
88
|
|
|
), |
89
|
|
|
array( |
90
|
|
|
'id' => 'margins', |
91
|
|
|
'title' => __( 'Margins', 'foogallery' ), |
92
|
|
|
'desc' => __( 'The spacing between your thumbnails.', 'foogallery' ), |
93
|
|
|
'section' => __( 'General', 'foogallery' ), |
94
|
|
|
'type' => 'number', |
95
|
|
|
'class' => 'small-text', |
96
|
|
|
'default' => 1, |
97
|
|
|
'step' => '1', |
98
|
|
|
'min' => '0', |
99
|
|
|
'row_data'=> array( |
100
|
|
|
'data-foogallery-change-selector' => 'input', |
101
|
|
|
'data-foogallery-value-selector' => 'input', |
102
|
|
|
'data-foogallery-preview' => 'data', |
103
|
|
|
) |
104
|
|
|
), |
105
|
|
|
array( |
106
|
|
|
'id' => 'thumbnail_link', |
107
|
|
|
'title' => __( 'Thumbnail Link', 'foogallery' ), |
108
|
|
|
'section' => __( 'General', 'foogallery' ), |
109
|
|
|
'default' => 'image' , |
110
|
|
|
'type' => 'thumb_link', |
111
|
|
|
'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' ), |
112
|
|
|
), |
113
|
|
|
array( |
114
|
|
|
'id' => 'lightbox', |
115
|
|
|
'title' => __( 'Lightbox', 'foogallery' ), |
116
|
|
|
'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' ), |
117
|
|
|
'section' => __( 'General', 'foogallery' ), |
118
|
|
|
'type' => 'lightbox', |
119
|
|
|
), |
120
|
|
|
), |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
return $gallery_templates; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Get the thumb dimensions arguments saved for the gallery for this gallery template |
128
|
|
|
* |
129
|
|
|
* @param array $dimensions |
130
|
|
|
* @param FooGallery $foogallery |
131
|
|
|
* |
132
|
|
|
* @return mixed |
133
|
|
|
*/ |
134
|
|
|
function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
|
|
|
|
135
|
|
|
$height = $foogallery->get_meta( 'justified_thumb_height', false ); |
136
|
|
|
return array( |
137
|
|
|
'height' => intval( $height ), |
138
|
|
|
'width' => 0, |
139
|
|
|
'crop' => false |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Add thumbnail fields to the gallery template |
145
|
|
|
* |
146
|
|
|
* @uses "foogallery_override_gallery_template_fields" |
147
|
|
|
* @param $fields |
148
|
|
|
* @param $template |
149
|
|
|
* |
150
|
|
|
* @return array |
151
|
|
|
*/ |
152
|
|
|
function add_common_thumbnail_fields( $fields, $template ) { |
|
|
|
|
153
|
|
|
return apply_filters( 'foogallery_gallery_template_common_thumbnail_fields', $fields ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Enqueue scripts that the default gallery template relies on |
158
|
|
|
*/ |
159
|
|
|
function enqueue_dependencies( $gallery ) { |
|
|
|
|
160
|
|
|
//enqueue core files |
161
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
162
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Add the required justified options if needed |
167
|
|
|
* |
168
|
|
|
* @param $options |
169
|
|
|
* @param $gallery FooGallery |
170
|
|
|
* |
171
|
|
|
* @param $attributes array |
172
|
|
|
* |
173
|
|
|
* @return array |
174
|
|
|
*/ |
175
|
|
|
function add_justified_options($options, $gallery, $attributes) { |
|
|
|
|
176
|
|
|
|
177
|
|
|
$row_height = foogallery_gallery_template_setting( 'row_height', '150' ); |
178
|
|
|
$max_row_height = foogallery_gallery_template_setting( 'max_row_height', '200%' ); |
179
|
|
|
if ( strpos( $max_row_height, '%' ) === false ) { |
180
|
|
|
$max_row_height = intval( $max_row_height ); |
181
|
|
|
} |
182
|
|
|
$margins = foogallery_gallery_template_setting( 'margins', '1' ); |
183
|
|
|
|
184
|
|
|
$options['template']['rowHeight'] = intval($row_height); |
185
|
|
|
$options['template']['maxRowHeight'] = $max_row_height; |
186
|
|
|
$options['template']['margins'] = intval($margins); |
187
|
|
|
|
188
|
|
|
return $options; |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
} |
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.