1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( !class_exists( 'FooGallery_Image_Viewer_Gallery_Template' ) ) { |
4
|
|
|
|
5
|
|
|
define('FOOGALLERY_IMAGE_VIEWER_GALLERY_TEMPLATE_URL', plugin_dir_url( __FILE__ )); |
6
|
|
|
|
7
|
|
|
class FooGallery_Image_Viewer_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
|
|
|
|
14
|
|
|
//add extra fields to the templates |
15
|
|
|
add_filter( 'foogallery_override_gallery_template_fields-image-viewer', array( $this, 'add_common_thumbnail_fields' ), 10, 2 ); |
16
|
|
|
|
17
|
|
|
add_action( 'foogallery_located_template-image-viewer', array( $this, 'enqueue_dependencies' ) ); |
18
|
|
|
|
19
|
|
|
add_filter( 'foogallery_gallery_templates_files', array( $this, 'register_myself' ) ); |
20
|
|
|
|
21
|
|
|
add_filter( 'foogallery_template_thumbnail_dimensions-image-viewer', array( $this, 'get_thumbnail_dimensions' ), 10, 2 ); |
22
|
|
|
|
23
|
|
|
//override specific settings when saving the gallery |
24
|
|
|
add_filter( 'foogallery_save_gallery_settings-image-viewer', array( $this, 'override_settings'), 10, 3 ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
29
|
|
|
* @param $extensions |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
34
|
|
|
$extensions[] = __FILE__; |
35
|
|
|
return $extensions; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Add our gallery template to the list of templates available for every gallery |
40
|
|
|
* @param $gallery_templates |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
45
|
|
|
|
46
|
|
|
$gallery_templates[] = array( |
47
|
|
|
'slug' => 'image-viewer', |
48
|
|
|
'name' => __( 'Image Viewer', 'foogallery' ), |
49
|
|
|
'lazyload_support' => true, |
50
|
|
|
'fields' => array( |
51
|
|
|
array( |
52
|
|
|
'id' => 'thumbnail_size', |
53
|
|
|
'title' => __( 'Thumb Size', 'foogallery' ), |
54
|
|
|
'section' => __( 'General', 'foogallery' ), |
55
|
|
|
'desc' => __( 'Choose the size of your thumbnails', 'foogallery' ), |
56
|
|
|
'type' => 'thumb_size', |
57
|
|
|
'default' => array( |
58
|
|
|
'width' => 640, |
59
|
|
|
'height' => 360, |
60
|
|
|
'crop' => true |
61
|
|
|
) |
62
|
|
|
), |
63
|
|
|
array( |
64
|
|
|
'id' => 'thumbnail_link', |
65
|
|
|
'title' => __( 'Thumb Link', 'foogallery' ), |
66
|
|
|
'section' => __( 'General', 'foogallery' ), |
67
|
|
|
'default' => 'image' , |
68
|
|
|
'type' => 'thumb_link', |
69
|
|
|
'desc' => __( 'You can choose to either link each thumbnail to the full size image or to the image\'s attachment page', 'foogallery') |
70
|
|
|
), |
71
|
|
|
array( |
72
|
|
|
'id' => 'lightbox', |
73
|
|
|
'title' => __( 'Lightbox', 'foogallery' ), |
74
|
|
|
'section' => __( 'General', 'foogallery' ), |
75
|
|
|
'desc' => __( 'Choose which lightbox you want to use in the gallery', 'foogallery' ), |
76
|
|
|
'type' => 'lightbox' |
77
|
|
|
), |
78
|
|
|
array( |
79
|
|
|
'id' => 'alignment', |
80
|
|
|
'title' => __( 'Alignment', 'foogallery' ), |
81
|
|
|
'section' => __( 'General', 'foogallery' ), |
82
|
|
|
'desc' => __( 'The horizontal alignment of the thumbnails inside the gallery', 'foogallery' ), |
83
|
|
|
'default' => 'fg-center', |
84
|
|
|
'type' => 'radio', |
85
|
|
|
'spacer' => '<span class="spacer"></span>', |
86
|
|
|
'choices' => array( |
87
|
|
|
'fg-left' => __( 'Left', 'foogallery' ), |
88
|
|
|
'fg-center' => __( 'Center', 'foogallery' ), |
89
|
|
|
'fg-right' => __( 'Right', 'foogallery' ), |
90
|
|
|
), |
91
|
|
|
'row_data'=> array( |
92
|
|
|
'data-foogallery-change-selector' => 'input:radio', |
93
|
|
|
'data-foogallery-preview' => 'class' |
94
|
|
|
) |
95
|
|
|
), |
96
|
|
|
array( |
97
|
|
|
'id' => 'language-help', |
98
|
|
|
'title' => __( 'Language Help', 'foogallery' ), |
99
|
|
|
'desc' => __( 'This gallery template shows the below items of text. Change them to suit your preference or language.', 'foogallery' ), |
100
|
|
|
'section' => __( 'General', 'foogallery' ), |
101
|
|
|
'type' => 'help' |
102
|
|
|
), |
103
|
|
|
array( |
104
|
|
|
'id' => 'text-prev', |
105
|
|
|
'title' => __( '"Prev" Text', 'foogallery' ), |
106
|
|
|
'section' => __( 'General', 'foogallery' ), |
107
|
|
|
'type' => 'text', |
108
|
|
|
'default' => __('Prev', 'foogallery') |
109
|
|
|
), |
110
|
|
|
array( |
111
|
|
|
'id' => 'text-of', |
112
|
|
|
'title' => __( '"of" Text', 'foogallery' ), |
113
|
|
|
'section' => __( 'General', 'foogallery' ), |
114
|
|
|
'type' => 'text', |
115
|
|
|
'default' => __('of', 'foogallery') |
116
|
|
|
), |
117
|
|
|
array( |
118
|
|
|
'id' => 'text-next', |
119
|
|
|
'title' => __( '"Next" Text', 'foogallery' ), |
120
|
|
|
'section' => __( 'General', 'foogallery' ), |
121
|
|
|
'type' => 'text', |
122
|
|
|
'default' => __('Next', 'foogallery') |
123
|
|
|
) |
124
|
|
|
) |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
return $gallery_templates; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Add thumbnail fields to the gallery template |
132
|
|
|
* |
133
|
|
|
* @uses "foogallery_override_gallery_template_fields" |
134
|
|
|
* @param $fields |
135
|
|
|
* @param $template |
136
|
|
|
* |
137
|
|
|
* @return array |
138
|
|
|
*/ |
139
|
|
|
function add_common_thumbnail_fields( $fields, $template ) { |
|
|
|
|
140
|
|
|
$updated_fields = apply_filters( 'foogallery_gallery_template_common_thumbnail_fields', $fields ); |
141
|
|
|
|
142
|
|
|
//update specific fields |
143
|
|
|
foreach ($updated_fields as &$field) { |
144
|
|
|
if ( 'rounded_corners' === $field['id'] ) { |
145
|
|
|
$field['choices'] = array( |
146
|
|
|
'' => __( 'None', 'foogallery' ), |
147
|
|
|
'fg-round-small' => __( 'Small', 'foogallery' ), |
148
|
|
|
'fg-round-medium' => __( 'Medium', 'foogallery' ), |
149
|
|
|
'fg-round-large' => __( 'Large', 'foogallery' ), |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return $updated_fields; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Enqueue scripts that the default gallery template relies on |
159
|
|
|
*/ |
160
|
|
|
function enqueue_dependencies( $gallery ) { |
|
|
|
|
161
|
|
|
//enqueue core files |
162
|
|
|
foogallery_enqueue_core_gallery_template_style(); |
163
|
|
|
foogallery_enqueue_core_gallery_template_script(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Get the thumb dimensions arguments saved for the gallery for this gallery template |
168
|
|
|
* |
169
|
|
|
* @param array $dimensions |
170
|
|
|
* @param FooGallery $foogallery |
171
|
|
|
* |
172
|
|
|
* @return mixed |
173
|
|
|
*/ |
174
|
|
|
function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
|
|
|
|
175
|
|
|
$dimensions = $foogallery->get_meta( 'image-viewer_thumbnail_size', false ); |
176
|
|
|
return $dimensions; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Override specific settings so that the gallery template will always work |
181
|
|
|
* |
182
|
|
|
* @param $settings |
183
|
|
|
* @param $post_id |
184
|
|
|
* @param $form_data |
185
|
|
|
* |
186
|
|
|
* @return mixed |
187
|
|
|
*/ |
188
|
|
|
function override_settings($settings, $post_id, $form_data) { |
|
|
|
|
189
|
|
|
if ( 'fg-round-full' === $settings['image-viewer_rounded_corners'] ) { |
190
|
|
|
$settings['image-viewer_rounded_corners'] = 'fg-round-large'; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return $settings; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
} |
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.