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
|
|
|
add_filter( 'foogallery_template_thumbnail_dimensions-justified', array( $this, 'get_thumbnail_dimensions' ), 10, 2 ); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Register myself so that all associated JS and CSS files can be found and automatically included |
20
|
|
|
* @param $extensions |
21
|
|
|
* |
22
|
|
|
* @return array |
23
|
|
|
*/ |
24
|
|
|
function register_myself( $extensions ) { |
|
|
|
|
25
|
|
|
$extensions[] = __FILE__; |
26
|
|
|
return $extensions; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Add our gallery template to the list of templates available for every gallery |
31
|
|
|
* @param $gallery_templates |
32
|
|
|
* |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
|
|
function add_template( $gallery_templates ) { |
|
|
|
|
36
|
|
|
$gallery_templates[] = array( |
37
|
|
|
'slug' => 'justified', |
38
|
|
|
'name' => __( 'Justified Gallery', 'foogallery' ), |
39
|
|
|
'fields' => array( |
40
|
|
|
array( |
41
|
|
|
'id' => 'help', |
42
|
|
|
'title' => __( 'Tip', 'foogallery' ), |
43
|
|
|
'type' => 'html', |
44
|
|
|
'help' => true, |
45
|
|
|
'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.', 'foogallery' ), |
46
|
|
|
), |
47
|
|
|
array( |
48
|
|
|
'id' => 'thumb_height', |
49
|
|
|
'title' => __( 'Thumb Height', 'foogallery' ), |
50
|
|
|
'desc' => __( 'Choose the height of your thumbnails. Thumbnails will be generated on the fly and cached once generated.', 'foogallery' ), |
51
|
|
|
'type' => 'number', |
52
|
|
|
'class' => 'small-text', |
53
|
|
|
'default' => 250, |
54
|
|
|
'step' => '10', |
55
|
|
|
'min' => '0', |
56
|
|
|
), |
57
|
|
|
array( |
58
|
|
|
'id' => 'row_height', |
59
|
|
|
'title' => __( 'Row Height', 'foogallery' ), |
60
|
|
|
'desc' => __( 'The preferred height of your gallery rows. This can be different from the thumbnail height.', 'foogallery' ), |
61
|
|
|
'type' => 'number', |
62
|
|
|
'class' => 'small-text', |
63
|
|
|
'default' => 150, |
64
|
|
|
'step' => '10', |
65
|
|
|
'min' => '0', |
66
|
|
|
), |
67
|
|
|
array( |
68
|
|
|
'id' => 'max_row_height', |
69
|
|
|
'title' => __( 'Max Row Height', 'foogallery' ), |
70
|
|
|
'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' ), |
71
|
|
|
'type' => 'text', |
72
|
|
|
'class' => 'small-text', |
73
|
|
|
'default' => '200%' |
74
|
|
|
), |
75
|
|
|
array( |
76
|
|
|
'id' => 'margins', |
77
|
|
|
'title' => __( 'Margins', 'foogallery' ), |
78
|
|
|
'desc' => __( 'The spacing between your thumbnails.', 'foogallery' ), |
79
|
|
|
'type' => 'number', |
80
|
|
|
'class' => 'small-text', |
81
|
|
|
'default' => 1, |
82
|
|
|
'step' => '1', |
83
|
|
|
'min' => '0', |
84
|
|
|
), |
85
|
|
|
array( |
86
|
|
|
'id' => 'captions', |
87
|
|
|
'title' => __( 'Show Captions', 'foogallery' ), |
88
|
|
|
'desc' => __( 'Show a caption when hovering over your thumbnails. (Set captions by adding either a title or alt text to an attachment)', 'foogallery' ), |
89
|
|
|
'type' => 'checkbox', |
90
|
|
|
'default' => 'on', |
91
|
|
|
), |
92
|
|
|
array( |
93
|
|
|
'id' => 'caption_source', |
94
|
|
|
'title' => __( 'Caption Source', 'foogallery' ), |
95
|
|
|
'desc' => __( 'Pull captions from either the attachment Title, Caption or Alt Text.', 'foogallery' ), |
96
|
|
|
'type' => 'radio', |
97
|
|
|
'default' => 'title', |
98
|
|
|
'spacer' => '<span class="spacer"></span>', |
99
|
|
|
'choices' => array( |
100
|
|
|
'title' => __( 'Attachment Title', 'foogallery' ), |
101
|
|
|
'caption' => __( 'Attachment Caption', 'foogallery' ), |
102
|
|
|
'alt' => __( 'Attachment Alt Text', 'foogallery' ) |
103
|
|
|
) |
104
|
|
|
), |
105
|
|
|
array( |
106
|
|
|
'id' => 'thumbnail_link', |
107
|
|
|
'title' => __( 'Thumbnail Link', 'foogallery' ), |
108
|
|
|
'default' => 'image' , |
109
|
|
|
'type' => 'thumb_link', |
110
|
|
|
'spacer' => '<span class="spacer"></span>', |
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
|
|
|
'type' => 'lightbox', |
118
|
|
|
), |
119
|
|
|
), |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
return $gallery_templates; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get the thumb dimensions arguments saved for the gallery for this gallery template |
127
|
|
|
* |
128
|
|
|
* @param array $dimensions |
129
|
|
|
* @param FooGallery $foogallery |
130
|
|
|
* |
131
|
|
|
* @return mixed |
132
|
|
|
*/ |
133
|
|
|
function get_thumbnail_dimensions( $dimensions, $foogallery ) { |
|
|
|
|
134
|
|
|
$height = $foogallery->get_meta( 'justified_thumb_height', false ); |
135
|
|
|
return array( |
136
|
|
|
'height' => intval( $height ), |
137
|
|
|
'width' => 0, |
138
|
|
|
'crop' => false |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
} |
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.