|
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
|
|
|
|
|
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' => 'justified', |
|
42
|
|
|
'name' => __( 'Justified Gallery', 'foogallery' ), |
|
43
|
|
|
'lazyload_support' => true, |
|
44
|
|
|
'fields' => array( |
|
45
|
|
|
array( |
|
46
|
|
|
'id' => 'thumb_height', |
|
47
|
|
|
'title' => __( 'Thumb Height', 'foogallery' ), |
|
48
|
|
|
'desc' => __( 'Choose the height of your thumbnails. Thumbnails will be generated on the fly and cached once generated.', 'foogallery' ), |
|
49
|
|
|
'type' => 'number', |
|
50
|
|
|
'class' => 'small-text', |
|
51
|
|
|
'default' => 250, |
|
52
|
|
|
'step' => '10', |
|
53
|
|
|
'min' => '0', |
|
54
|
|
|
), |
|
55
|
|
|
array( |
|
56
|
|
|
'id' => 'row_height', |
|
57
|
|
|
'title' => __( 'Row Height', 'foogallery' ), |
|
58
|
|
|
'desc' => __( 'The preferred height of your gallery rows. This can be different from the thumbnail height.', 'foogallery' ), |
|
59
|
|
|
'type' => 'number', |
|
60
|
|
|
'class' => 'small-text', |
|
61
|
|
|
'default' => 150, |
|
62
|
|
|
'step' => '10', |
|
63
|
|
|
'min' => '0', |
|
64
|
|
|
), |
|
65
|
|
|
array( |
|
66
|
|
|
'id' => 'max_row_height', |
|
67
|
|
|
'title' => __( 'Max Row Height', 'foogallery' ), |
|
68
|
|
|
'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' ), |
|
69
|
|
|
'type' => 'text', |
|
70
|
|
|
'class' => 'small-text', |
|
71
|
|
|
'default' => '200%' |
|
72
|
|
|
), |
|
73
|
|
|
array( |
|
74
|
|
|
'id' => 'margins', |
|
75
|
|
|
'title' => __( 'Margins', 'foogallery' ), |
|
76
|
|
|
'desc' => __( 'The spacing between your thumbnails.', 'foogallery' ), |
|
77
|
|
|
'type' => 'number', |
|
78
|
|
|
'class' => 'small-text', |
|
79
|
|
|
'default' => 1, |
|
80
|
|
|
'step' => '1', |
|
81
|
|
|
'min' => '0', |
|
82
|
|
|
), |
|
83
|
|
|
array( |
|
84
|
|
|
'id' => 'captions', |
|
85
|
|
|
'title' => __( 'Show Captions', 'foogallery' ), |
|
86
|
|
|
'desc' => __( 'Show a caption when hovering over your thumbnails. (Set captions by adding either a title or alt text to an attachment)', 'foogallery' ), |
|
87
|
|
|
'type' => 'checkbox', |
|
88
|
|
|
'default' => 'on', |
|
89
|
|
|
), |
|
90
|
|
|
array( |
|
91
|
|
|
'id' => 'caption_source', |
|
92
|
|
|
'title' => __( 'Caption Source', 'foogallery' ), |
|
93
|
|
|
'desc' => __( 'Pull captions from either the attachment Title, Caption or Alt Text.', 'foogallery' ), |
|
94
|
|
|
'type' => 'radio', |
|
95
|
|
|
'default' => 'title', |
|
96
|
|
|
'spacer' => '<span class="spacer"></span>', |
|
97
|
|
|
'choices' => array( |
|
98
|
|
|
'title' => __( 'Attachment Title', 'foogallery' ), |
|
99
|
|
|
'caption' => __( 'Attachment Caption', 'foogallery' ), |
|
100
|
|
|
'alt' => __( 'Attachment Alt Text', 'foogallery' ) |
|
101
|
|
|
) |
|
102
|
|
|
), |
|
103
|
|
|
array( |
|
104
|
|
|
'id' => 'thumbnail_link', |
|
105
|
|
|
'title' => __( 'Thumbnail Link', 'foogallery' ), |
|
106
|
|
|
'default' => 'image' , |
|
107
|
|
|
'type' => 'thumb_link', |
|
108
|
|
|
'spacer' => '<span class="spacer"></span>', |
|
109
|
|
|
'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' ), |
|
110
|
|
|
), |
|
111
|
|
|
array( |
|
112
|
|
|
'id' => 'lightbox', |
|
113
|
|
|
'title' => __( 'Lightbox', 'foogallery' ), |
|
114
|
|
|
'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' ), |
|
115
|
|
|
'type' => 'lightbox', |
|
116
|
|
|
), |
|
117
|
|
|
), |
|
118
|
|
|
); |
|
119
|
|
|
|
|
120
|
|
|
return $gallery_templates; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get the thumb dimensions arguments saved for the gallery for this gallery template |
|
125
|
|
|
* |
|
126
|
|
|
* @param array $dimensions |
|
127
|
|
|
* @param FooGallery $foogallery |
|
128
|
|
|
* |
|
129
|
|
|
* @return mixed |
|
130
|
|
|
*/ |
|
131
|
|
|
function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
|
|
|
|
|
|
132
|
|
|
$height = $foogallery->get_meta( 'justified_thumb_height', false ); |
|
133
|
|
|
return array( |
|
134
|
|
|
'height' => intval( $height ), |
|
135
|
|
|
'width' => 0, |
|
136
|
|
|
'crop' => false |
|
137
|
|
|
); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Add thumbnail fields to the gallery template |
|
142
|
|
|
* |
|
143
|
|
|
* @uses "foogallery_override_gallery_template_fields" |
|
144
|
|
|
* @param $fields |
|
145
|
|
|
* @param $template |
|
146
|
|
|
* |
|
147
|
|
|
* @return array |
|
148
|
|
|
*/ |
|
149
|
|
|
function add_common_thumbnail_fields( $fields, $template ) { |
|
|
|
|
|
|
150
|
|
|
$fields = array_merge( $fields, foogallery_get_gallery_template_common_thumbnail_fields($template) ); |
|
151
|
|
|
|
|
152
|
|
|
return $fields; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Enqueue scripts that the default gallery template relies on |
|
157
|
|
|
*/ |
|
158
|
|
|
function enqueue_dependencies( $gallery ) { |
|
|
|
|
|
|
159
|
|
|
wp_enqueue_script( 'jquery' ); |
|
160
|
|
|
|
|
161
|
|
|
//enqueue core files |
|
162
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
|
163
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
|
164
|
|
|
|
|
165
|
|
|
$css = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'justified/css/foogallery.justified.min.css'; |
|
166
|
|
|
wp_enqueue_style( 'foogallery-justified', $css, array(), FOOGALLERY_VERSION ); |
|
167
|
|
|
|
|
168
|
|
|
$js = FOOGALLERY_DEFAULT_TEMPLATES_EXTENSION_URL . 'justified/js/foogallery.justified.min.js'; |
|
169
|
|
|
wp_enqueue_script( 'foogallery-justified', $js, array(), FOOGALLERY_VERSION ); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
} |
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.