forked from ronakg/awesome-flickr-gallery-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafg_libs.php
431 lines (379 loc) · 16.8 KB
/
afg_libs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
<?php
define('BASE_URL', plugins_url() . '/' . basename(dirname(__FILE__)));
define('SITE_URL', site_url());
define('DEBUG', false);
define('VERSION', '3.3.6');
$afg_sort_order_map = array(
'default' => 'Default',
'flickr' => 'As per Flickr',
'date_taken_cmp_newest' => 'By date taken (Newest first)',
'date_taken_cmp_oldest' => 'By date taken (Oldest first)',
'date_upload_cmp_newest' => 'By date uploaded (Newest first)',
'date_upload_cmp_oldest' => 'By date uploaded (Oldest first)',
'random' => 'Random',
);
$afg_slideshow_map = array(
'default' => 'Default',
'colorbox' => 'Colorbox',
'highslide' => 'Highslide',
'disable' => 'No Slideshow',
'flickr' => 'Link to Flickr Photo page',
'none' => 'No Slideshow and No Link',
);
/* Map for photo titles displayed on the gallery. */
$size_heading_map = array(
'_s' => '',
'_t' => '0.9em',
'_m' => '1em',
'NULL' => '1.2em',
);
$afg_photo_source_map = array(
'photostream' => 'Photostream',
'gallery' => 'Gallery',
'photoset' => 'Photoset',
'group' => 'Group',
'tags' => 'Tags',
'popular' => 'My Popular Photos',
);
$afg_width_map = array(
'default' => 'Default',
'auto' => 'Automatic',
'10' => '10 %',
'20' => '20 %',
'30' => '30 %',
'40' => '40 %',
'50' => '50 %',
'60' => '60 %',
'70' => '70 %',
'80' => '80 %',
'90' => '90 %',
);
$afg_photo_size_map = array(
'default' => 'Default',
'_s' => 'Square (Max 75px)',
'_t' => 'Thumbnail (Max 100px)',
'_m' => 'Small (Max 240px)',
'NULL' => 'Medium (Max 500px)',
'custom' => 'Custom',
);
$afg_on_off_map = array(
'off' => 'Off ',
'on' => 'On ',
'default' => 'Default',
);
$afg_yes_no_map = array(
'off' => 'Yes ',
'on' => 'No ',
'default' => 'Default',
);
$afg_descr_map = array(
'off' => 'Off',
'on' => 'On',
'default' => 'Default',
);
$afg_columns_map = array(
'default' => 'Default',
'1' => '1 ',
'2' => '2 ',
'3' => '3 ',
'4' => '4 ',
'5' => '5 ',
'6' => '6 ',
'7' => '7 ',
'8' => '8 ',
'9' => '9 ',
'10' => '10 ',
'11' => '11 ',
'12' => '12 ',
);
$afg_bg_color_map = array(
'default' => 'Default',
'Black' => 'Black',
'White' => 'White',
'Transparent' => 'Transparent',
);
$afg_text_color_map = array(
'Black' => 'White',
'White' => 'Black',
);
function afg_get_cur_url() {
$isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on");
$port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443")));
$port = ($port) ? ':'.$_SERVER["SERVER_PORT"] : '';
$url = ($isHTTPS ? 'https://' : 'http://').$_SERVER["HTTP_HOST"].$port.$_SERVER["REQUEST_URI"];
return $url;
}
function create_afgFlickr_obj() {
global $pf;
unset($_SESSION['afgFlickr_auth_token']);
$pf = new afgFlickr(get_option('afg_api_key'), get_option('afg_api_secret')? get_option('afg_api_secret'): NULL);
$pf->setToken(get_option('afg_flickr_token'));
}
function afg_error() {
global $pf;
return "<h3>Awesome Flickr Gallery Error - $pf->error_msg</h3>";
}
function date_taken_cmp_newest($a, $b) {
return $a['datetaken'] < $b['datetaken'];
}
function date_taken_cmp_oldest($a, $b) {
return $a['datetaken'] > $b['datetaken'];
}
function date_upload_cmp_newest($a, $b) {
return $a['dateupload'] < $b['dateupload'];
}
function date_upload_cmp_oldest($a, $b) {
return $a['dateupload'] > $b['dateupload'];
}
function afg_fb_like_box() {
return "<iframe src=\"//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fawesome.flickr.gallery&width=300&height=258&colorscheme=light&show_faces=true&border_color&stream=false&header=false&appId=107783615948615\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:300px; height:170px;\" allowTransparency=\"true\"></iframe>";
}
function afg_share_box() {
return "<div id=\"poststuff\">
<div class=\"postbox\" style='width:300px; box-shadow:0 0 2px'>
<h3>Follow Awesome Flickr Gallery</h3>"
. afg_fb_like_box()
. afg_gplus_box()
. "</div></div>";
}
function afg_gplus_box() {
return "<div class=\"g-plus\" data-href=\"https://plus.google.com/110562610836727777499\" data-size=\"badge\"></div>";
}
function delete_afg_caches() {
$galleries = get_option('afg_galleries');
foreach($galleries as $id => $ginfo) {
delete_transient('afg_id_'. $id);
}
}
function afg_get_photo_url($farm, $server, $pid, $secret, $size) {
if ($size == 'NULL') {
$size = '';
}
return urlencode("http://farm$farm.static.flickr.com/$server/{$pid}_$secret$size.jpg");
}
function afg_get_photo_page_url($pid, $uid) {
return "http://www.flickr.com/photos/$uid/$pid";
}
function afg_generate_version_line() {
if(isset($_POST['afg_dismis_ss_msg']) && $_POST['afg_dismis_ss_msg']) {
update_option('afg_dismis_ss_msg', true);
}
$return_str = "" .
" <h4 align=\"right\" style=\"margin-right:0.5%\">" .
" Version: <b>" . VERSION . "</b> |" .
" <a href=\"http://wordpress.org/extend/plugins/awesome-flickr-gallery-plugin/faq/\">FAQ</a> |" .
" <a href=\"http://wordpress.org/extend/plugins/awesome-flickr-gallery-plugin/\">Rate this plugin</a> |" .
" <a href=\"http://www.ronakg.com/discussions/\">Support Forums</a> |" .
" <a href=\"https://github.com/ronakg/Awesome-Flickr-Gallery/wiki/Changelog\">Changelog</a> |" .
" <a href=\"http://www.ronakg.com/photos/\">Live Demo</a>" .
" </h4>";
return $return_str;
}
function afg_generate_flickr_settings_table($photosets, $galleries, $groups) {
global $afg_photo_source_map;
$photosets = afg_generate_options($photosets, '', False);
$galleries = afg_generate_options($galleries, '', False);
$groups = afg_generate_options($groups, '', False);
return "
<div id=\"poststuff\">
<div class=\"postbox\" style='box-shadow:0 0 2px'>
<h3>Flickr Settings</h3>
<table class='form-table'>
<tr valign='top'>
<th scope='row'>Gallery Source</th>
<td><select name='afg_photo_source_type' id='afg_photo_source_type' onchange='getPhotoSourceType()' >" . afg_generate_options($afg_photo_source_map, 'photostream', False) . "
</select></td>
</tr>
<tr>
<th id='afg_photo_source_label'></th>
<td><select style='display:none' name='afg_photosets_box' id='afg_photosets_box'>$photosets
</select>
<select style='display:none' name='afg_galleries_box' id='afg_galleries_box'>$galleries
</select>
<select style='display:none' name='afg_groups_box' id='afg_groups_box'>$groups
</select>
<textarea rows='3' cols='30' name='afg_tags' id='afg_tags' style='display:none'></textarea>
</td>
<td id='afg_source_help' style='display:none'><font size='2'>Enter tags separated by comma. For example: <b>tag1, tag2, tag3, tag4</b><br />Photos matching any of the given tags will be displayed.</font></td>
</tr>
</table>
</div></div>";
}
function afg_generate_gallery_settings_table() {
global $afg_photo_size_map, $afg_on_off_map, $afg_descr_map,
$afg_columns_map, $afg_bg_color_map, $afg_photo_source_map,
$afg_width_map, $afg_yes_no_map, $afg_sort_order_map, $afg_slideshow_map;
if (get_option('afg_photo_size') == 'custom')
$photo_size = '(Custom - ' . get_option('afg_custom_size') . 'px' . ((get_option('afg_custom_size_square') == 'true')? ' - Square)': ')');
else
$photo_size = $afg_photo_size_map[get_option('afg_photo_size')];
return "
<div id=\"poststuff\">
<div class=\"postbox\" style='box-shadow:0 0 2px'>
<h3>Gallery Settings</h3>
<table class='form-table'>
<tr valign='top'>
<th scope='row'>Max Photos Per Page</th>
<td style='width:28%'><input type='checkbox' name='afg_per_page_check' id='afg_per_page_check' onclick='showHidePerPage()' value='default' checked='' style='vertical-align:top'> Default </input><input name='afg_per_page' disabled='true' id='afg_per_page' type='text' size='3' maxlength='3' onblur='verifyBlank()' value='10'/>
</td>
</tr>
<tr valign='top'>
<th scope='row'>Sort order of Photos</th>
<td><select name='afg_sort_order' id='afg_sort_order'>"
. afg_generate_options($afg_sort_order_map, 'default', True, $afg_sort_order_map[get_option('afg_sort_order')]) . "
</select>
<td><font size='2'>Set the sort order of the photos as per your liking and forget about how photos are arranged on Flickr.</font></td>
</td>
</tr>
<tr valign='top'>
<th scope='row'>Size of Photos</th>
<td><select name='afg_photo_size' id='afg_photo_size' onchange='customPhotoSize()'>
" . afg_generate_options($afg_photo_size_map, 'default', True, $photo_size) . "
</select></td>
</tr>
<tr valign='top' id='afg_custom_size_block' style='display:none'>
<th>Custom Width</th>
<td><input type='text' size='3' maxlength='3' name='afg_custom_size' id='afg_custom_size' onblur='verifyCustomSizeBlank()' value='100'><font color='red'>*</font> (in px)
Square? <input type='checkbox' id='afg_custom_size_square' name='afg_custom_size_square' value='true'>
</td>
<td><font size='2'>Fill in the exact width for the photos (min 50, max 500). Height of the photos will be adjusted
accordingly to maintain aspect ratio of the photo. Enable <b>Square</b> to crop
the photo to a square aspect ratio.</td>
</tr>
<tr valign='top'>
<th scope='row'>Photo Titles</th>
<td><select name='afg_captions' id='afg_captions'>
" . afg_generate_options($afg_on_off_map, 'default', True, $afg_on_off_map[get_option('afg_captions')]) . "
</select></td>
<td><font size='2'>Photo Title setting applies only to Thumbnail (and above) size photos.</font></td>
</tr>
<tr valign='top'>
<th scope='row'>Photo Descriptions</th>
<td><select name='afg_descr' id='afg_descr'>
" . afg_generate_options($afg_descr_map, 'default', True, $afg_descr_map[get_option('afg_descr')]) . "
</select></td>
<td><font size='2'>Photo Description setting applies only to Small and Medium size photos.</td>
</tr>
<tr valign='top'>
<th scope='row'>Number of Columns</th>
<td><select name='afg_columns' id='afg_columns'>
" . afg_generate_options($afg_columns_map, 'default', True, $afg_columns_map[get_option('afg_columns')]) . "
</select></td>
</tr>
<tr valign='top'>
<th scope='row'>Slideshow Behavior</th>
<td><select name='afg_slideshow_option' id='afg_slideshow_option'>
" . afg_generate_options($afg_slideshow_map, 'default', True, $afg_slideshow_map[get_option('afg_slideshow_option')]) . "
</select></td>
<td><font size='2'><b>HighSlide is NOT FREE for Commercial websites</b>. If you are using
<i>Awesome Flickr Gallery</i> on a commercial website, you need to purchase a license from their website
<a href='http://highslide.com/#licence' target='_blank'>here</a>. If you want a free slideshow,
use ColorBox instead.</font></td>
</tr>
<tr valign='top'>
<th scope='row'>Background Color</th>
<td><select name='afg_bg_color' id='afg_bg_color'>
" . afg_generate_options($afg_bg_color_map, 'default', True, $afg_bg_color_map[get_option('afg_bg_color')]) . "
</select></td>
</tr>
<tr valign='top'>
<th scope='row'>Gallery Width</th>
<td><select name='afg_width' id='afg_width'>
" . afg_generate_options($afg_width_map, 'default', True, $afg_width_map[get_option('afg_width')]) . "
</select></td>
<td><font size='2'>Width of the Gallery is relative to the width of the page where Gallery is being generated. <i>Automatic</i> is 100% of page width.</font></td>
</tr>
<tr valign='top'>
<th scope='row'>Disable Pagination?</th>
<td><select name='afg_pagination' id='afg_pagination'>
" . afg_generate_options($afg_yes_no_map, 'default', True, $afg_yes_no_map[get_option('afg_pagination')]) . "
</select></td>
<td><font size='2'>Useful when displaying gallery in a sidebar widget where you want only few recent photos.</td>
</tr>
<tr valign='top'>
<th scope='row'>Add a Small Credit Note?</th>
<td><select name='afg_credit_note' id='afg_credit_note'>
" . afg_generate_options($afg_on_off_map, 'default', True, $afg_on_off_map[get_option('afg_credit_note')]) . "
</select></td>
<td><font size='2'>Credit Note will appear at the bottom of the gallery as - </font>
Powered by
<a href=\"http://www.ronakg.com/projects/awesome-flickr-gallery-wordpress-plugin\"/>
AFG</a></td>
</tr>
</table>
</div></div>";
}
function afg_generate_options($params, $selection, $show_default=False, $default_value=0) {
$str = '';
foreach($params as $key => $value) {
if ($key == 'default' && !$show_default)
continue;
if ($selection == $key) {
if ($selection == 'default') $value .= ' - ' . $default_value;
$str .= "<option value=" . $key . " selected='selected'>" . $value . "</option>";
}
else
$str .= "<option value=" . $key . ">" . $value . "</option>";
}
return $str;
}
function afg_filter($param) {
if ($param == 'default') return "";
else return $param;
}
function afg_box($title, $message) {
return "
<div id=\"poststuff\">
<div class=\"postbox\" style='box-shadow:0 0 2px'>
<h3>$title</h3>
<table class='form-table'>
<td>$message</td>
</table>
</div></div>
";
}
function afg_usage_box($code) {
return "
<div id=\"poststuff\">
<div class=\"postbox\" style='box-shadow:0 0 2px'>
<h3>Usage Instructions</h3>
<table class='form-table'>
<td>Just insert $code in any of the posts or page to display your Flickr gallery.</td>
</table>
</div></div>
";
}
function get_afg_option($gallery, $var) {
if (isset($gallery[$var]) && $gallery[$var]) return $gallery[$var];
else return get_option('afg_' . $var);
}
function afg_donate_box() {
return "
<div id=\"poststuff\">
<div class=\"postbox\" style='box-shadow:0 0 2px'>
<h3>Support this plugin</h3>
<table class='form-table'>
<td>It takes time and effort to keep releasing new versions of this plugin. If you like it, consider donating a few bucks <b>(especially if you are using this plugin on a commercial website)</b> to keep receiving new features.
</form><form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\"><div style=\"text-align:center\" class=\"paypal-donations\"><input type='hidden' name='item_name' value='Awesome Flickr Gallery'/><input type=\"hidden\" name=\"cmd\" value=\"_donations\" /><input type=\"hidden\" name=\"business\" value=\"2P32M6V34HDCQ\" /><input type=\"hidden\" name=\"currency_code\" value=\"USD\" /><input type=\"image\" src=\"" . BASE_URL . "/images/donate_small.png\" name=\"submit\" alt=\"PayPal - The safer, easier way to pay online.\" /><img alt=\"PayPal Donate\" src=\"https://www.paypal.com/en_US/i/scr/pixel.gif\" width=\"1\" height=\"1\" /><br /><b>All major credit cards are accepted too.</b></div></form>
</td>
</table>
</div></div>";
}
function afg_reference_box() {
$message = "Max Photos Per Page - <b>" . get_option('afg_per_page') . "</b>";
$size = get_option('afg_photo_size');
if ($size == '_s') $size = 'Square';
else if ($size == '_t') $size = 'Thumbnail';
else if ($size == '_m') $size = 'Small';
else if ($size == 'NULL') $size = 'Medium';
$message .= "<br />Size of Photos - <b>" . $size . "</b>";
$message .= "<br />Photo Titles - <b>" . get_option('afg_captions') . "</b>";
$message .= "<br />Photo Descriptions - <b>" . get_option('afg_descr') . "</b>";
$message .= "<br />No of Columns - <b>" . get_option('afg_columns') . "</b>";
$message .= "<br />Background Color - <b>" . get_option('afg_bg_color') . "</b>";
$message .= "<br />Gallery Width - <b>" . ((get_option('afg_width') == 'auto')?"Automatic":get_option('afg_width') . "%") . "</b>";
$message .= "<br />Pagination - <b>" . get_option('afg_pagination') . "</b>";
$message .= "<br />Credit Note - <b>" . get_option('afg_credit_note') . "</b>";
return afg_box('Default Settings for Reference', $message);
}
?>