/
unc_gallery.php
335 lines (291 loc) · 13.7 KB
/
unc_gallery.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
<?php
/*
Plugin Name: Uncovery Gallery
Plugin URI: https://uncovery.net/about
Description: A simple, self-generating, date-based gallery with bulk uploading
Version: 5.2
Author: Uncovery
Author URI: http://uncovery.net
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
/**
* This is the main file of the plugin and contains the most basic plugin-handling
* functions that are relevant for wordpress in handling this plugin.
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die();
}
global $UNC_FILE_DATA, $UNC_GALLERY;
$UNC_GALLERY['debug'] = true;
$UNC_GALLERY['errors'] = array(); // we store internal errors here
if (!isset($UNC_GALLERY['start_time'])) {
$UNC_GALLERY['start_time'] = microtime(true);
}
$UNC_GALLERY['data_version'] = 1; // increase this number when you change the format!
require_once( plugin_dir_path( __FILE__ ) . "/libraries/unc_exif.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "/libraries/unc_iptc.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "/libraries/unc_xmp.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "/libraries/unc_rss_feed.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_backend.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_shortcode.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_upload.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_display.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_type_day.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_type_filter.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_type_chrono.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_tools.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_image.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_image_display.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_ranking.inc.php");
require_once( plugin_dir_path( __FILE__ ) . "unc_prints.inc.php");
// require_once( plugin_dir_path( __FILE__ ) . "unc_tagging.inc.php");
// co nfig has to be last because it runs function in unc_image.inc.php
require_once( plugin_dir_path( __FILE__ ) . "unc_config.inc.php");
// actions on activating and deactivating the plugin
register_activation_hook( __FILE__, 'unc_gallery_plugin_activate');
register_deactivation_hook( __FILE__, 'unc_gallery_plugin_deactivate');
register_uninstall_hook( __FILE__, 'unc_gallery_plugin_uninstall');
if (is_admin() === true){ // admin actions
add_action('admin_init', 'unc_gallery_admin_init');
// add an admin menu
add_action('admin_menu', 'unc_gallery_admin_menu');
}
function photos_feed_init(){
add_feed('photos_feed', 'photos_feed');
}
add_action('init', 'photos_feed_init');
// shortcode for the [unc_gallery] replacements
add_shortcode('unc_gallery', 'unc_gallery_apply');
add_shortcode('unc_gallery_image', 'unc_image_display');
add_shortcode('unc_gallery_new', 'unc_gallery_shortcode_translate');
add_shortcode('unc_gallery_ranking', 'unc_ranking_show');
add_shortcode('unc_gallery_prints', 'unc_prints_list');
// add_shortcode('unc_gallery_tagging', 'unc_tagging_show');
// end-user ajax for image ranking
add_action('wp_ajax_unc_ranking_new_image', 'unc_ranking_new_image');
add_action('wp_ajax_nopriv_unc_ranking_new_image', 'unc_ranking_new_image');
// this activates the returns without header & footer on upload Ajax POST
if (is_admin() === true) {
add_action('wp_ajax_unc_gallery_uploads', 'unc_uploads_iterate_files');
add_action('wp_ajax_unc_gallery_import_images', 'unc_uploads_iterate_files');
add_action('wp_ajax_nopriv_unc_gallery_datepicker', 'unc_display_ajax_folder');
add_action('wp_ajax_unc_gallery_datepicker', 'unc_display_ajax_folder');
add_action('wp_ajax_nopriv_unc_filter_update', 'unc_filter_update');
add_action('wp_ajax_unc_tools_progress_get', 'unc_tools_progress_get');
add_action('wp_ajax_nopriv_unc_tools_progress_get', 'unc_tools_progress_get');
add_action('wp_ajax_unc_filter_update', 'unc_filter_update');
add_action('wp_ajax_unc_chrono_update', 'unc_chrono_update');
add_action('wp_ajax_unc_gallery_image_delete', 'unc_tools_image_delete');
add_action('wp_ajax_unc_gallery_images_refresh', 'unc_gallery_images_refresh');
// admin maintenance functions
add_action('wp_ajax_unc_gallery_admin_rebuild_thumbs', 'unc_gallery_admin_rebuild_thumbs');
add_action('wp_ajax_unc_gallery_admin_rebuild_data', 'unc_gallery_admin_rebuild_data');
add_action('wp_ajax_unc_gallery_admin_remove_data', 'unc_gallery_admin_remove_data');
add_action('wp_ajax_unc_gallery_delete_everything', 'unc_gallery_admin_delete_everything');
add_action('wp_ajax_unc_gallery_admin_remove_logs', 'unc_gallery_admin_remove_logs');
add_action('wp_ajax_unc_gallery_admin_orphaned_files', 'unc_gallery_admin_orphaned_files');
// shortcode maker
add_action('wp_ajax_unc_gallery_shortcode_form', 'unc_gallery_shortcode_form');
}
add_action( 'wp_enqueue_scripts', 'unc_gallery_enqueue_css_and_js' );
// get the AjaxURL in the frontend
add_action('wp_head','pluginname_ajaxurl');
function pluginname_ajaxurl() {
echo "<script type=\"text/javascript\">var ajaxurl='" . admin_url('admin-ajax.php') . "'</script>";
}
// execute shortcodes in the excerpts
add_filter('the_excerpt', 'do_shortcode');
add_filter('the_excerpt_rss', 'do_shortcode');
// get the settings from the system and set the global variables
// this iterates the user settings that are supposed to be in the wordpress config
// and gets them from there, setting the default if not available
// inserts them into the global
foreach ($UNC_GALLERY['user_settings'] as $setting => $D) {
$UNC_GALLERY[$setting] = get_option($UNC_GALLERY['settings_prefix'] . $setting, $D['default']);
}
$UNC_GALLERY['debug'] = true;
if ($UNC_GALLERY['debug']) {
$UNC_GALLERY['debug_log'] = array();
register_shutdown_function("unc_tools_debug_write");
}
/**
* Apply default tag/category texts if set in the configuration
* TODO: Find out why this has sometimes only one parameter instead of two.
*
* @global type $UNC_GALLERY
* @param type $description
* @param type $taxonomy
* @return array
*/
function unc_gallery_default_term_description($description = '', $taxonomy = 'post_tag') {
global $UNC_GALLERY;
if ($description) {
return $description;
}
switch ( $taxonomy ) {
case 'category':
$description = $UNC_GALLERY['category_default_description'];
break;
case 'post_tag':
$description = $UNC_GALLERY['tag_default_description'];
break;
}
return $description;
}
add_action('pre_term_description', 'unc_gallery_default_term_description');
/**
* standard wordpress function to activate the plugin.
* creates the uploads folder
*
* @global type $UNC_GALLERY
*/
function unc_gallery_plugin_activate() {
global $UNC_GALLERY;
// we check if the upload path exists (from config) and create if not
if (!file_exists($UNC_GALLERY['upload_path'])) {
$result = mkdir($UNC_GALLERY['upload_path'], 0755);
// check success
if (!$result) {
echo unc_display_errormsg("There was an error creating the upload folder {$UNC_GALLERY['upload_path']}!");
}
}
// create the DB structure
unc_mysql_db_create();
}
function unc_mysql_db_create() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
$table_name_img = $wpdb->prefix . "unc_gallery_img";
$sql_img = "CREATE TABLE $table_name_img (
id mediumint(9) NOT NULL AUTO_INCREMENT,
file_time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
file_name varchar(128) NOT NULL,
file_path varchar(256) NOT NULL,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY `id` (`id`),
UNIQUE KEY `file_time` (`file_time`,`file_name`)
) $charset_collate;";
dbDelta($sql_img);
$table_name_att = $wpdb->prefix . "unc_gallery_att";
$sql_att = "CREATE TABLE $table_name_att (
`att_id` mediumint(9) NOT NULL AUTO_INCREMENT,
`file_id` mediumint(9) NOT NULL,
`att_group` ENUM('default','iptc','exif','xmp') NOT NULL,
`att_name` varchar(25) NOT NULL,
`att_value` varchar(255) NOT NULL,
UNIQUE KEY `att_id` (`att_id`),
KEY `att_name` (`att_name`),
KEY `file_id` (`file_id`)
) $charset_collate;";
dbDelta($sql_att);
$table_name_att = $wpdb->prefix . "unc_gallery_cat_links";
$sql_link = "CREATE TABLE $table_name_att (
`location_code` varchar(128) NOT NULL,
`category_id` mediumint(9) NOT NULL,
UNIQUE KEY `category_id` (`category_id`),
UNIQUE KEY `location_code` (`location_code`)
) $charset_collate;";
dbDelta($sql_link);
$table_name_rank = $wpdb->prefix . "unc_gallery_ranking";
$sql_rank = "CREATE TABLE $table_name_rank (
`file_id` mediumint(9) NOT NULL,
`ranking` mediumint(9) NOT NULL,
`ranked` mediumint(9) NOT NULL,
`rank_time` datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
UNIQUE KEY `file_id` (`file_id`),
KEY `rank_time` (`rank_time`),
KEY `ranking` (`ranking`)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql_rank);
add_option( "unc_gallery_db_version", "2.7" );
}
/**
* standard wordpress function to deactivate the plugin.
*
* @global type $UNC_GALLERY
*/
function unc_gallery_plugin_deactivate() {
global $UNC_GALLERY;
// deactivate all settings
$prefix = $UNC_GALLERY['settings_prefix'];
foreach ($UNC_GALLERY['user_settings'] as $setting => $D) {
unregister_setting('unc_gallery_settings_page', $prefix . $setting);
}
}
/**
* Uninstalling the plugin
*
* @global type $UNC_GALLERY
*/
function unc_gallery_plugin_uninstall() {
global $UNC_GALLERY;
// delete all images optional
if ($UNC_GALLERY['uninstall_deletes_images'] == 'yes') {
unc_tools_recurse_files($UNC_GALLERY['upload_path'], 'unlink', 'rmdir');
}
// TODO: check and remove databases
//delete all settings properly
$prefix = $UNC_GALLERY['settings_prefix'];
foreach ($UNC_GALLERY['user_settings'] as $setting => $D) {
delete_option($prefix . $setting);
}
// register_uninstall_hook($file, $callback)
}
/**
* function that includes all the CSS and JS that are needed.
*
*/
function unc_gallery_enqueue_css_and_js() {
global $UNC_GALLERY, $post;
//we load the code only if we are actually using it.
// the issue is that we don't know at this point if we are
// a) showing only the excerpt or also the content
// b) if we are using the map
// since a lot of the code has to be in the header, we need to enqueue the scripts here.
if (!is_null($post) && (
!has_shortcode($post->post_content, 'unc_gallery') &&
!has_shortcode($post->post_content, 'unc_gallery_ranking') &&
!has_shortcode($post->post_content, 'unc_gallery_image')
)) {
return;
}
// jquery etc
wp_enqueue_script('jquery-ui');
wp_enqueue_script('jquery-form');
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery_ui_css', plugin_dir_url( __FILE__ ) . 'css/jquery-ui.css');
// unc_gallery custom
wp_enqueue_script('unc_gallery_js', plugin_dir_url( __FILE__ ) . 'js/unc_gallery.js');
wp_enqueue_style('unc_gallery_css', plugin_dir_url( __FILE__ ) . 'css/gallery.css');
if ($UNC_GALLERY['image_view_method'] == 'lightbox') {
// lightbox
wp_register_script('unc_gallery_lightbox_js', plugin_dir_url( __FILE__ ) . 'js/lightbox.min.js', array(), '2.8.2', true);
wp_enqueue_script('unc_gallery_lightbox_js');
wp_enqueue_style('unc_gallery_lightbox_css', plugin_dir_url( __FILE__ ) . 'css/lightbox.min.css');
} else if ($UNC_GALLERY['image_view_method'] == 'photoswipe') {
//photoswipe
// the JS in included in unc_display_photoswipe_js()
wp_enqueue_style('unc_gallery_photoswipe_css', plugin_dir_url( __FILE__ ) . 'css/photoswipe.css');
} else if ($UNC_GALLERY['image_view_method'] == 'galleria') {
wp_register_script('unc_gallery_galleria_js', plugin_dir_url( __FILE__ ) . 'js/galleria/galleria.min.js', array(), '1.6.1', false);
wp_register_script('unc_gallery_galleria_theme_js', plugin_dir_url( __FILE__ ) . 'js/galleria/galleria.folio.min.js', array(), '1.6.1', false);
wp_enqueue_script('unc_gallery_galleria_js');
wp_enqueue_script('unc_gallery_galleria_theme_js');
wp_enqueue_style('unc_gallery_galleria_css', plugin_dir_url( __FILE__ ) . 'js/galleria/galleria.folio.min.css');
}
// load google maps if it's set
if (!is_front_page() && strlen($UNC_GALLERY['google_api_key']) > 1) {
$api_key = $UNC_GALLERY['google_api_key'];
wp_register_script('unc_gallery_google_maps', "https://maps.googleapis.com/maps/api/js?key=$api_key", array(), '', false);
wp_register_script('unc_gallery_makerwithlabel_js', plugin_dir_url( __FILE__ ) . 'js/markerwithlabel.js', array(), '', false);
wp_register_script('unc_gallery_makercluster_js', plugin_dir_url( __FILE__ ) . 'js/markerclusterer.js', array(), '', false);
wp_enqueue_script('unc_gallery_google_maps');
wp_enqueue_script('unc_gallery_makerwithlabel_js');
wp_enqueue_script('unc_gallery_makercluster_js');
}
}