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
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
18
|
|
|
* @param $extensions |
19
|
|
|
* |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
23
|
|
|
$extensions[] = __FILE__; |
24
|
|
|
return $extensions; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Add our gallery template to the list of templates available for every gallery |
29
|
|
|
* @param $gallery_templates |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
34
|
|
|
$gallery_templates[] = array( |
35
|
|
|
'slug' => 'justified', |
36
|
|
|
'name' => __( 'Justified Gallery', 'foogallery' ), |
37
|
|
|
'fields' => array( |
38
|
|
|
array( |
39
|
|
|
'id' => 'help', |
40
|
|
|
'title' => __( 'Tip', 'foogallery' ), |
41
|
|
|
'type' => 'html', |
42
|
|
|
'help' => true, |
43
|
|
|
'desc' => __( 'The Justified Gallery template uses the popular <a href="http://miromannino.com/projects/justified-gallery/" target="_blank">Justified Gallery jQuery Plugin</a> under the hood. You can specify thumbnail captions by setting the alt text for your attachments. Use a small thumb height for lightning fast page loading, larger thumbnails will be loaded afterwards depening on chosen alternates.<br><br>Make sure to have thumbnails in your theme with a width of 9999 to be able to choose an Initial thumb.', 'foogallery' ), |
44
|
|
|
), |
45
|
|
|
array( |
46
|
|
|
'id' => 'thumb_initial', |
47
|
|
|
'title' => __( 'Initial Thumb', 'foogallery' ), |
48
|
|
|
'desc' => __( 'Choose initial thumbnails to be loaded. Should be roughly matching your row height or smaller. Needs to have a width of 9999.', 'foogallery' ), |
49
|
|
|
'type' => 'select', |
50
|
|
|
'choices' => $this->get_thumb_size_choices_filtered() |
51
|
|
|
), |
52
|
|
|
array( |
53
|
|
|
'id' => 'thumb_sizes', |
54
|
|
|
'title' => __( 'Alternate thumb sizes', 'foogallery' ), |
55
|
|
|
'desc' => __( 'Alternate thumbnail sizes that will be loaded after loading the initial thumbnail. Will be used if larger thumbnails could be used in your gallery. Will only display thumbnails with a width of 9999', 'foogallery' ), |
56
|
|
|
'type' => 'checkboxlist', |
57
|
|
|
'choices' => $this->get_thumb_size_choices_filtered() |
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, but should roughly match it.', 'foogallery' ), |
63
|
|
|
'type' => 'number', |
64
|
|
|
'class' => 'small-text', |
65
|
|
|
'default' => 150, |
66
|
|
|
'step' => '10', |
67
|
|
|
'min' => '0', |
68
|
|
|
), |
69
|
|
|
array( |
70
|
|
|
'id' => 'fixed_height', |
71
|
|
|
'title' => __( 'Fixed Row height', 'foogallery' ), |
72
|
|
|
'desc' => __( 'Fix rows at the specified row height ("Max Row Height" is not used). Depending on aspect ratio the images could be cropped.', 'foogallery' ), |
73
|
|
|
'type' => 'checkbox', |
74
|
|
|
'default' => 'off', |
75
|
|
|
), |
76
|
|
|
array( |
77
|
|
|
'id' => 'max_row_height', |
78
|
|
|
'title' => __( 'Max Row Height', 'foogallery' ), |
79
|
|
|
'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' ), |
80
|
|
|
'type' => 'text', |
81
|
|
|
'class' => 'small-text', |
82
|
|
|
'default' => '200%' |
83
|
|
|
), |
84
|
|
|
array( |
85
|
|
|
'id' => 'last_row', |
86
|
|
|
'title' => __( 'Last Row', 'foogallery' ), |
87
|
|
|
'desc' => __( 'Sets display options for the last row if not enough images exist to fill the row.', 'foogallery' ), |
88
|
|
|
'type' => 'radio', |
89
|
|
|
'default' => 'justify', |
90
|
|
|
'spacer' => '<span class="spacer"></span>', |
91
|
|
|
'choices' => array( |
92
|
|
|
'justify' => __( 'Justify', 'foogallery' ), |
93
|
|
|
'nojustify' => __( 'No Justify', 'foogallery' ), |
94
|
|
|
'hide' => __( 'Hide', 'foogallery' ) |
95
|
|
|
) |
96
|
|
|
), |
97
|
|
|
array( |
98
|
|
|
'id' => 'margins', |
99
|
|
|
'title' => __( 'Margins', 'foogallery' ), |
100
|
|
|
'desc' => __( 'The spacing between your thumbnails.', 'foogallery' ), |
101
|
|
|
'type' => 'number', |
102
|
|
|
'class' => 'small-text', |
103
|
|
|
'default' => 1, |
104
|
|
|
'step' => '1', |
105
|
|
|
'min' => '0', |
106
|
|
|
), |
107
|
|
|
array( |
108
|
|
|
'id' => 'captions', |
109
|
|
|
'title' => __( 'Show Captions', 'foogallery' ), |
110
|
|
|
'desc' => __( 'Show a caption when hovering over your thumbnails. (Set captions by adding either a title or alt text to an attachment)', 'foogallery' ), |
111
|
|
|
'type' => 'checkbox', |
112
|
|
|
'default' => 'on', |
113
|
|
|
), |
114
|
|
|
array( |
115
|
|
|
'id' => 'caption_source', |
116
|
|
|
'title' => __( 'Caption Source', 'foogallery' ), |
117
|
|
|
'desc' => __( 'Pull captions from either the attachment Title, Caption or Alt Text.', 'foogallery' ), |
118
|
|
|
'type' => 'radio', |
119
|
|
|
'default' => 'title', |
120
|
|
|
'spacer' => '<span class="spacer"></span>', |
121
|
|
|
'choices' => array( |
122
|
|
|
'title' => __( 'Attachment Title', 'foogallery' ), |
123
|
|
|
'caption' => __( 'Attachment Caption', 'foogallery' ), |
124
|
|
|
'alt' => __( 'Attachment Alt Text', 'foogallery' ) |
125
|
|
|
) |
126
|
|
|
), |
127
|
|
|
array( |
128
|
|
|
'id' => 'thumbnail_link', |
129
|
|
|
'title' => __( 'Thumbnail Link', 'foogallery' ), |
130
|
|
|
'default' => 'image' , |
131
|
|
|
'type' => 'thumb_link', |
132
|
|
|
'spacer' => '<span class="spacer"></span>', |
133
|
|
|
'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' ), |
134
|
|
|
), |
135
|
|
|
array( |
136
|
|
|
'id' => 'lightbox', |
137
|
|
|
'title' => __( 'Lightbox', 'foogallery' ), |
138
|
|
|
'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' ), |
139
|
|
|
'type' => 'lightbox', |
140
|
|
|
), |
141
|
|
|
), |
142
|
|
|
); |
143
|
|
|
|
144
|
|
|
return $gallery_templates; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
function get_thumb_size_choices_filtered() { |
|
|
|
|
148
|
|
|
global $_wp_additional_image_sizes; |
|
|
|
|
149
|
|
|
$sizes = array(); |
150
|
|
|
foreach( get_intermediate_image_sizes() as $s ){ |
151
|
|
|
if ( in_array( $s, array( 'thumbnail', 'medium', 'large', ) ) ){ |
152
|
|
|
$sizes[ $s ]['width'] = get_option( $s . '_size_w' ); |
153
|
|
|
$sizes[ $s ]['height'] = get_option( $s . '_size_h' ); |
154
|
|
|
$sizes[ $s ]['crop'] = (bool) get_option( $s . '_crop' ); |
155
|
|
|
} elseif ( isset( $_wp_additional_image_sizes[ $s ] ) ) { |
156
|
|
|
$sizes[ $s ] = array( |
157
|
|
|
'width' => $_wp_additional_image_sizes[ $s ]['width'], |
158
|
|
|
'height' => $_wp_additional_image_sizes[ $s ]['height'], |
159
|
|
|
'crop' => (bool) $_wp_additional_image_sizes[ $s ]['crop'], |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
//order by height |
165
|
|
|
if (!function_exists('sortbyheight')) { |
166
|
|
|
function sortbyheight($a, $b) { |
|
|
|
|
167
|
|
|
if ($a['height'] == $b['height']) { |
168
|
|
|
return 0; |
169
|
|
|
} |
170
|
|
|
return ($a['height'] < $b['height']) ? -1 : 1; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
uasort($sizes, "sortbyheight"); |
174
|
|
|
|
175
|
|
|
$sizesfiltered = array(); |
176
|
|
|
|
177
|
|
|
//filter sizes to only include non-cropped and width 9999 |
178
|
|
|
foreach ($sizes as $key => $value) { |
179
|
|
|
if ( !$value['crop'] == 1 && $value['width'] == '9999') { |
180
|
|
|
$sizesfiltered[$key] = ucwords($key) . " (" . $value['width'] . " x " . $value['height'] . ") "; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
return $sizesfiltered; |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
} |
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.