PluginProbe
Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress / 4.7.5
Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress v4.7.5
4.8.1 4.8.0 4.7.9 trunk 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.10 2.11 2.12 2011.1.01 2011.1.02 3.01 3.02 3.03 3.04 3.05 3.06 3.1 All 131 releases
gallery-plugin / gallery-plugin.php

gallery-plugin.php in Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress 4.7.5, at gallery-plugin.php

4,112 lines 154.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 Plugin Name: Gallery by BestWebSoft
4 Plugin URI: https://bestwebsoft.com/products/wordpress/plugins/gallery/
5 Description: Add beautiful galleries, albums & images to your WordPress website in few clicks.
6 Author: BestWebSoft
7 Text Domain: gallery-plugin
8 Domain Path: /languages
9 Version: 4.7.5
10 Author URI: https://bestwebsoft.com/
11 License: GPLv2 or later
12 */
13
14 /**
15 © Copyright 2023 BestWebSoft ( https://support.bestwebsoft.com )
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License, version 2, as
19 published by the Free Software Foundation.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31 if ( ! defined( 'ABSPATH' ) ) {
32 exit;
33 }
34
35 require_once dirname( __FILE__ ) . '/includes/class-gllr-widgets.php';
36 require_once dirname( __FILE__ ) . '/includes/class-gllr-media-table.php';
37
38 if ( ! function_exists( 'add_gllr_admin_menu' ) ) {
39 /**
40 * Add WordPress page 'bws_panel' and sub-page of this plugin to admin-panel.
41 */
42 function add_gllr_admin_menu() {
43 global $submenu, $gllr_options, $gllr_plugin_info, $wp_version;
44
45 if ( empty( $gllr_options ) ) {
46 gllr_settings();
47 }
48 if ( ! is_plugin_active( 'gallery-plugin-pro/gallery-plugin-pro.php' )
49 && ! is_plugin_active( 'gallery-plus/gallery-plus.php' ) ) {
50 $settings = add_submenu_page( 'edit.php?post_type=' . $gllr_options['post_type_name'], __( 'Gallery Settings', 'gallery-plugin' ), __( 'Global Settings', 'gallery-plugin' ), 'manage_options', 'gallery-plugin.php', 'gllr_settings_page' );
51
52 add_submenu_page( 'edit.php?post_type=' . $gllr_options['post_type_name'], 'BWS Panel', 'BWS Panel', 'manage_options', 'gllr-bws-panel', 'bws_add_menu_render' );
53
54 /*pls */
55 if ( isset( $submenu[ 'edit.php?post_type=' . $gllr_options['post_type_name'] ] ) ) {
56 $submenu[ 'edit.php?post_type=' . $gllr_options['post_type_name'] ][] = array(
57 '<span style="color:#d86463"> ' . __( 'Upgrade to Pro', 'gallery-plugin' ) . '</span>',
58 'manage_options',
59 'https://bestwebsoft.com/products/wordpress/plugins/gallery/?k=63a36f6bf5de0726ad6a43a165f38fe5&pn=79&v=' . $gllr_plugin_info['Version'] . '&wp_v=' . $wp_version,
60 );
61 }
62 add_action( 'load-' . $settings, 'gllr_add_tabs' );
63 add_action( 'load-post-new.php', 'gllr_add_tabs' );
64 add_action( 'load-post.php', 'gllr_add_tabs' );
65 add_action( 'load-edit.php', 'gllr_add_tabs' );
66 }
67 }
68 }
69
70 if ( ! function_exists( 'gllr_plugins_loaded' ) ) {
71 /**
72 * Internationalization
73 */
74 function gllr_plugins_loaded() {
75 load_plugin_textdomain( 'gallery-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
76 }
77 }
78
79 if ( ! function_exists( 'gllr_register_galleries' ) ) {
80 /**
81 * Register the plugin post type and update rewrite rules
82 * in order to make the plugin permalinks work.
83 *
84 * @since 4.5.2
85 * @see https://codex.wordpress.org/Function_Reference/register_post_type#Flushing_Rewrite_on_Activation
86 */
87 function gllr_register_galleries() {
88 global $gllr_options;
89 if ( empty( $gllr_options ) ) {
90 $gllr_options = get_option( 'gllr_options' );
91 if ( empty( $gllr_options ) ) {
92 gllr_settings();
93 }
94 }
95 gllr_post_type_images( true );
96 }
97 }
98
99 if ( ! function_exists( 'gllr_init' ) ) {
100 /**
101 * Plugin initialization
102 */
103 function gllr_init() {
104 global $gllr_plugin_info, $pagenow, $gllr_options;
105
106 require_once dirname( __FILE__ ) . '/bws_menu/bws_include.php';
107 bws_include_init( plugin_basename( __FILE__ ) );
108
109 if ( ! $gllr_plugin_info ) {
110 if ( ! function_exists( 'get_plugin_data' ) ) {
111 require_once ABSPATH . 'wp-admin/includes/plugin.php';
112 }
113 $gllr_plugin_info = get_plugin_data( __FILE__ );
114 }
115
116 /* Function check if plugin is compatible with current WP version */
117 bws_wp_min_version_check( plugin_basename( __FILE__ ), $gllr_plugin_info, '4.5' );
118
119 /* Call register settings function */
120 gllr_settings();
121 /* Register post type */
122 gllr_post_type_images();
123
124 if ( ! is_admin() ) {
125 /* Add template for gallery pages */
126 add_action( 'template_include', 'gllr_template_include' );
127 }
128
129 /* Add media button to the gallery post type */
130 if (
131 ( isset( $_GET['post'] ) && get_post_type( sanitize_text_field( wp_unslash( $_GET['post'] ) ) ) === $gllr_options['post_type_name'] ) ||
132 ( 'post-new.php' === $pagenow && isset( $_GET['post_type'] ) && $gllr_options['post_type_name'] === $_GET['post_type'] )
133 ) {
134 add_action( 'edit_form_after_title', 'gllr_media_custom_box' );
135 }
136
137 /* demo data */
138 $demo_options = get_option( 'gllr_demo_options' );
139 if ( ! empty( $demo_options ) || ( isset( $_GET['page'] ) && 'gallery-plugin.php' === $_GET['page'] ) ) {
140 gllr_include_demo_data();
141 }
142 }
143 }
144
145 if ( ! function_exists( 'gllr_admin_init' ) ) {
146 /**
147 * Admin init
148 */
149 function gllr_admin_init() {
150 global $bws_plugin_info, $gllr_plugin_info, $bws_shortcode_list, $pagenow, $gllr_options;
151 /* Add variable for bws_menu */
152 if ( empty( $bws_plugin_info ) ) {
153 $bws_plugin_info = array(
154 'id' => '79',
155 'version' => $gllr_plugin_info['Version'],
156 );
157 }
158
159 /* add gallery to global $bws_shortcode_list */
160 $bws_shortcode_list['gllr'] = array(
161 'name' => 'Gallery',
162 'js_function' => 'gllr_shortcode_init',
163 );
164
165 /*pls */
166 if ( 'plugins.php' === $pagenow ) {
167 /* Install the option defaults */
168 if ( function_exists( 'bws_plugin_banner_go_pro' ) ) {
169 bws_plugin_banner_go_pro( $gllr_options, $gllr_plugin_info, 'gllr', 'gallery', '01a04166048e9416955ce1cbe9d5ca16', '79', 'gallery-plugin' );
170 }
171 }
172 add_filter( 'manage_' . $gllr_options['post_type_name'] . '_posts_columns', 'gllr_change_columns' );
173 add_action( 'manage_' . $gllr_options['post_type_name'] . '_posts_custom_column', 'gllr_custom_columns', 10, 2 );
174
175 if ( isset( $_POST['gllr_export_submit'] ) ) {
176 export_gallery_to_csv();
177 }
178 if ( isset( $_POST['gllr_import_submit'] ) ) {
179 import_gallery_from_csv();
180 }
181 }
182 }
183
184 if ( ! function_exists( 'export_gallery_to_csv' ) ) {
185 function export_gallery_to_csv() {
186 global $wp_filesystem, $wpdb, $gllr_options;
187 /* Check user capabilities */
188 if ( ! current_user_can( 'manage_options' ) ) {
189 return;
190 }
191
192 /* Check nonce for security */
193 if ( ! isset( $_POST['gllr_export_nonce'] ) || ! wp_verify_nonce( $_POST['gllr_export_nonce'], 'gllr_export' ) ) {
194 return;
195 }
196
197 WP_Filesystem();
198
199 $upload_dir = wp_upload_dir();
200 $file_name = wp_tempnam( 'tmp', $upload_dir['path'] . '/' );
201 if ( ! $file_name ) {
202 return false;
203 }
204
205 $export_str = '';
206
207 /* Query galleries (assuming custom post type 'gallery') */
208 $args = array(
209 'post_type' => 'bws-gallery',
210 'posts_per_page' => -1
211 );
212 $galleries = new WP_Query( $args );
213
214 $export_header = array(
215 'Gallery Title',
216 'Gallery Content',
217 'Gallery Category',
218 'Gallery Featured Image',
219 'Images URL',
220 'Images Title',
221 'Images Alt',
222 'Images Text',
223 'Images Order',
224 'Images Shortpixel'
225 );
226
227 $export_str = $wpdb->prepare( '%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;' . PHP_EOL, $export_header );
228
229 /* Loop through galleries and output the data */
230 if ( $galleries->have_posts() ) {
231 while ( $galleries->have_posts() ) {
232 $galleries->the_post();
233 $title = get_the_title();
234 $content = get_the_content();
235 $terms = wp_get_post_terms( get_the_ID(), 'gallery_categories' );
236
237 $featured_id = get_post_meta( get_the_ID(), '_thumbnail_id', true );
238 $featured_image = '';
239 if ( ! empty( $featured_id ) ) {
240 $featured_image = wp_get_attachment_url( $featured_id );
241 }
242
243 $categories = array();
244
245 foreach ( $terms as $term ) {
246 $album_order = get_term_meta( absint( $term->ID ), 'gllr_album_order', true );
247 if ( empty( $album_order ) ) {
248 $album_order = isset( $gllr_options['album_order_by_category_option'] ) ? $gllr_options['album_order_by_category_option'] : 'default';
249 }
250 $categories[] = array( $term->name, $term->slug, $term->description, $term->parent, $album_order );
251 }
252
253 $images = get_post_meta( get_the_ID(), '_gallery_images', true );
254 $images_url = array();
255 $images_title = array();
256 $images_alt = array();
257 $images_text = array();
258 $images_order = array();
259 $images_shortpixel = array();
260
261 if ( ! empty( $images ) ) {
262 $images = explode(',', $images );
263 foreach ( $images as $image ) {
264 $images_url[] = wp_get_attachment_url( $image );
265 $images_title[] = get_the_title( $image );
266 $image_postmeta = get_post_meta( $image );
267 $images_alt[] = $image_postmeta[ '_gallery_order_' . get_the_ID() ][0];
268 $images_text[] = isset( $image_postmeta['gllr_image_alt_tag'][0] ) ? $image_postmeta['gllr_image_alt_tag'][0] : '';
269 $images_order[] = isset( $image_postmeta['gllr_image_text'][0] ) ? $image_postmeta['gllr_image_text'][0] : '';
270 $images_shortpixel[] = isset( $image_postmeta['gallery_images_shortpixel'] ) ? $image_postmeta['gallery_images_shortpixel'][0] : '';
271 }
272 }
273 $export_str .= $wpdb->prepare( '%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;' . PHP_EOL, $title, $content, json_encode( $categories ), $featured_image, json_encode( $images_url ), json_encode( $images_title ), json_encode( $images_alt ), json_encode( $images_text ), json_encode( $images_order ), json_encode( $images_shortpixel ) );
274 }
275 }
276
277 $result = $wp_filesystem->put_contents( $file_name, $export_str );
278 if ( ! $result ) {
279 return false;
280 }
281
282 header( 'Content-Type: application/octet-stream' );
283 header( 'Content-Disposition: attachment; filename="galleries_export.csv"' );
284 echo wp_kses_post( $wp_filesystem->get_contents( $file_name ) );
285 unlink( $file_name );
286 exit();
287 }
288 }
289
290
291 if ( ! function_exists( 'import_gallery_from_csv' ) ) {
292 function import_gallery_from_csv() {
293 global $wp_filesystem, $wpdb, $gllr_upload_errors;
294 /* Check user capabilities */
295 if ( ! current_user_can( 'manage_options' ) ) {
296 return;
297 }
298
299 /* Check nonce for security */
300 if ( ! isset( $_POST['gllr_import_nonce'] ) || ! wp_verify_nonce( $_POST['gllr_import_nonce'], 'gllr_import' ) ) {
301 return;
302 }
303
304 WP_Filesystem();
305
306 $upload_dir = wp_upload_dir();
307 if ( empty( $_FILES['gllr_csv_file']['tmp_name'] ) ) {
308 $gllr_upload_errors = __( 'Select a file to import data', 'gallery-plugin' );
309 return;
310 }
311 $file_tmp_name = sanitize_text_field( wp_unslash( $_FILES['gllr_csv_file']['tmp_name'] ) );
312 $file_name = sanitize_text_field( wp_unslash( $_FILES['gllr_csv_file']['name'] ) );
313 $file_type = sanitize_text_field( wp_unslash( $_FILES['gllr_csv_file']['type'] ) );
314
315 $validate_file_type = wp_check_filetype( $file_name, array( 'csv' => 'text/csv' ) );
316
317 if ( false === $validate_file_type['type'] || false === $validate_file_type['ext'] ) {
318 $gllr_upload_errors = __( 'File type is not allowed, you can only upload a csv file.', 'gallery-plugin' ) . '<br />';
319 } else {
320 $csv_as_array = $wp_filesystem->get_contents( $file_tmp_name );
321 $csv_as_array = explode( PHP_EOL, $csv_as_array );
322 foreach( $csv_as_array as $key => $value ) {
323 $csv_as_array[ $key ] = explode( "';'", trim( $value, "';" ) );
324 }
325 if ( isset( $csv_as_array[0] ) && isset( $csv_as_array[0][0] ) && 'Gallery Title' != $csv_as_array[0][0] ) {
326 $gllr_upload_errors = __( 'An invalid file was uploaded to import gallery data.', 'gallery-plugin' );
327 return;
328 }
329 unset( $csv_as_array[0] );
330 foreach( $csv_as_array as $csv_string ) {
331 if ( empty( $csv_string[0] ) ) {
332 continue;
333 }
334 $post = array(
335 'comment_status' => 'closed',
336 'ping_status' => 'closed',
337 'post_status' => 'publish',
338 'post_type' => 'bws-gallery',
339 'post_title' => $csv_string[0],
340 'post_content' => $csv_string[1],
341 );
342 $post_id = wp_insert_post( $post );
343 $gallery_terms = array();
344 $categories = json_decode( stripslashes_deep( $csv_string[2] ) );
345 if ( ! empty( $categories ) ) {
346 foreach( $categories as $term ) {
347 $term_exists = term_exists( $term[0], 'gallery_categories' );
348 if ( ! $term_exists ) {
349 $term_id = wp_insert_term(
350 $term[0],
351 'gallery_categories',
352 array(
353 'description' => $term[2],
354 'slug' => $term[1],
355 'parent' => $term[3],
356 )
357 );
358 $term_exists['term_id'] = $term_id;
359 }
360 $album_order = get_term_meta( absint( $term_exists['term_id'] ), 'gllr_album_order', true );
361 if ( empty( $album_order ) ) {
362 update_term_meta( absint( $term_exists['term_id'] ), 'gllr_album_order', sanitize_text_field( wp_unslash( $term[4] ) ) );
363 }
364 $gallery_terms[] = $term[1];
365 }
366 }
367 wp_set_object_terms( $post_id, $gallery_terms, 'gallery_categories' );
368 $featured_image = stripslashes_deep( $csv_string[3] );
369
370 $images_url = json_decode( stripslashes_deep( $csv_string[4] ) );
371 $images_title = json_decode( stripslashes_deep( $csv_string[5] ) );
372 $images_alt = json_decode( stripslashes_deep( $csv_string[6] ) );
373 $images_text = json_decode( stripslashes_deep( $csv_string[7] ) );
374 $images_order = json_decode( stripslashes_deep( $csv_string[8] ) );
375 $images_shortpixel = json_decode( stripslashes_deep( $csv_string[9] ) );
376
377 if ( empty( $images_url ) ) {
378 $gllr_upload_errors = __( 'Import completed successfully. It is possible that a file created in a previous version of the plugin was imported and the gallery image data will not be fully loaded.', 'gallery-plugin' );
379 }
380
381 $attach_images = array();
382
383 if ( ! empty( $images_url ) ) {
384 $wp_upload_dir = wp_upload_dir();
385 require_once ABSPATH . 'wp-admin/includes/image.php';
386 foreach( $images_url as $key => $image ) {
387 $http = new WP_Http();
388 $response = $http->request( $image );
389 if ( is_wp_error( $response ) || ! isset( $response['response']['code'] ) || 200 !== $response['response']['code'] ) {
390 $gllr_upload_errors = esc_html__( 'Errors occurred when uploading images, not all images were uploaded to the galleries', 'gallery-plugin' );
391 continue;
392 }
393
394 $upload = wp_upload_bits( basename( $image ), null, $response['body'] );
395 if ( ! empty( $upload['error'] ) ) {
396 $gllr_upload_errors = esc_html__( 'Errors occurred when uploading images, not all images were uploaded to the galleries', 'gallery-plugin' );
397 continue;
398 }
399
400 $file_path = $upload['file'];
401 $file_name = basename( $file_path );
402 $file_type = wp_check_filetype( $file_name, null );
403 $attachment_title = sanitize_file_name( pathinfo( $file_name, PATHINFO_FILENAME ) );
404
405 $post_info = array(
406 'guid' => $wp_upload_dir['url'] . '/' . $file_name,
407 'post_mime_type' => $file_type['type'],
408 'post_title' => $images_title[ $key ],
409 'post_content' => '',
410 'post_status' => 'inherit',
411 'post_parent' => $post_id
412 );
413
414 $attach_id = wp_insert_attachment( $post_info, $file_path );
415 $attach_data = wp_generate_attachment_metadata( $attach_id, $file_path );
416
417 $attach_images[] = $attach_id;
418
419 wp_update_attachment_metadata( $attach_id, $attach_data );
420
421 if ( ! empty( $featured_image ) && $image === $featured_image ) {
422 set_post_thumbnail( $post_id, $attach_id );
423 $featured_image = '';
424 }
425
426 add_post_meta( $attach_id, '_gallery_order_' . $post_id, $images_order[ $key ] );
427 if ( ! empty( $images_alt[ $key ] ) ) {
428 add_post_meta( $attach_id, 'gllr_image_alt_tag', $images_alt[ $key ] );
429 }
430 if ( ! empty( $images_text[ $key ] ) ) {
431 add_post_meta( $attach_id, 'gllr_image_text', $images_text[ $key ] );
432 }
433 if ( ! empty( $images_shortpixel[ $key ] ) ) {
434 add_post_meta( $attach_id, 'gallery_images_shortpixel', $images_shortpixel[ $key ] );
435 }
436 }
437 }
438
439 if ( ! empty( $attach_images ) ) {
440 add_post_meta( $post_id, '_gallery_images', implode( ',', $attach_images ) );
441 }
442
443 if ( ! empty( $featured_image ) ) {
444 $http = new WP_Http();
445 $response = $http->request( $featured_image );
446 if ( 200 !== $response['response']['code'] ) {
447 $gllr_upload_errors = esc_html__( 'Errors occurred when uploading images, not all images were uploaded to the galleries', 'gallery-plugin' );
448 continue;
449 }
450
451 $upload = wp_upload_bits( basename( $featured_image ), null, $response['body'] );
452 if ( ! empty( $upload['error'] ) ) {
453 $gllr_upload_errors = esc_html__( 'Errors occurred when uploading images, not all images were uploaded to the galleries', 'gallery-plugin' );
454 continue;
455 }
456
457 $file_path = $upload['file'];
458 $file_name = basename( $file_path );
459 $file_type = wp_check_filetype( $file_name, null );
460 $attachment_title = sanitize_file_name( pathinfo( $file_name, PATHINFO_FILENAME ) );
461
462 $post_info = array(
463 'guid' => $wp_upload_dir['url'] . '/' . $file_name,
464 'post_mime_type' => $file_type['type'],
465 'post_title' => $images_title[ $key ],
466 'post_content' => '',
467 'post_status' => 'inherit',
468 'post_parent' => $post_id
469 );
470
471 $attach_id = wp_insert_attachment( $post_info, $file_path );
472 $attach_data = wp_generate_attachment_metadata( $attach_id, $file_path );
473
474 wp_update_attachment_metadata( $attach_id, $attach_data );
475
476 set_post_thumbnail( $post_id, $attach_id );
477 $featured_image = '';
478 }
479 }
480 }
481 }
482 }
483
484 if ( ! function_exists( 'gllr_plugin_activate' ) ) {
485 /**
486 * Function for activation
487 */
488 function gllr_plugin_activate() {
489 gllr_register_galleries();
490 /* registering uninstall hook */
491 if ( is_multisite() ) {
492 switch_to_blog( 1 );
493 register_uninstall_hook( __FILE__, 'gllr_plugin_uninstall' );
494 restore_current_blog();
495 } else {
496 register_uninstall_hook( __FILE__, 'gllr_plugin_uninstall' );
497 }
498 }
499 }
500
501 if ( ! function_exists( 'gallery_plugin_status' ) ) {
502 /**
503 * Check plugin status
504 *
505 * @param array $plugins BWS plugins.
506 * @param array $all_plugins All plugins on the site.
507 * @param bool $is_network Flag for network.
508 *
509 * @return array $result
510 */
511 function gallery_plugin_status( $plugins, $all_plugins, $is_network ) {
512 $result = array(
513 'status' => '',
514 'plugin' => '',
515 'plugin_info' => array(),
516 );
517 foreach ( (array) $plugins as $plugin ) {
518 if ( array_key_exists( $plugin, $all_plugins ) ) {
519 if (
520 ( $is_network && is_plugin_active_for_network( $plugin ) ) ||
521 ( ! $is_network && is_plugin_active( $plugin ) )
522 ) {
523 $result['status'] = 'actived';
524 $result['plugin'] = $plugin;
525 $result['plugin_info'] = $all_plugins[ $plugin ];
526 break;
527 } else {
528 $result['status'] = 'deactivated';
529 $result['plugin'] = $plugin;
530 $result['plugin_info'] = $all_plugins[ $plugin ];
531 }
532 }
533 }
534 if ( empty( $result['status'] ) ) {
535 $result['status'] = 'not_installed';
536 }
537 return $result;
538 }
539 }
540
541 if ( ! function_exists( 'gllr_export_slider' ) ) {
542 /**
543 * Export gallery to the slider
544 */
545 function gllr_export_slider() {
546 global $wpdb;
547
548 check_ajax_referer( plugin_basename( __FILE__ ), 'gllr_ajax_nonce_field' );
549
550 $id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : '';
551 $title = isset( $_POST['post_title'] ) ? sanitize_text_field( wp_unslash( $_POST['post_title'] ) ) : '';
552
553 $select = $wpdb->get_results(
554 $wpdb->prepare(
555 '
556 SELECT meta_value
557 FROM ' . $wpdb->prefix . 'postmeta
558 WHERE post_id = %s
559 AND meta_key = "_gallery_images"
560 ',
561 $id
562 ),
563 ARRAY_A
564 );
565
566 if ( $select ) {
567
568 $get_meta_val = $select[0]['meta_value'];
569 $explode_meta_val = explode( ',', $get_meta_val );
570
571 $sldr_settings = array(
572 'loop' => false,
573 'nav' => false,
574 'dots' => false,
575 'items' => 1,
576 'autoplay' => false,
577 'autoplay_timeout' => 2000,
578 'autoplay_hover_pause' => false,
579 );
580
581 $serialize_sldr_settings = serialize( $sldr_settings );
582
583 $wpdb->insert(
584 $wpdb->prefix . 'sldr_slider',
585 array(
586 'title' => $title,
587 'datetime' => date( 'Y-m-d' ),
588 'settings' => $serialize_sldr_settings,
589 )
590 );
591
592 $slider_id = $wpdb->get_results(
593 $wpdb->prepare(
594 '
595 SELECT slider_id
596 FROM ' . $wpdb->prefix . 'sldr_slider
597 WHERE title = %s
598 ',
599 $title
600 ),
601 ARRAY_A
602 );
603
604 $data_slide = array();
605 $data_relation = array();
606 $slice = array_slice( $slider_id, -1 );
607 $slice = array_values( $slice );
608 $slice = $slice[0];
609 $i = 0;
610
611 foreach ( $explode_meta_val as $val ) {
612 $i++;
613 $data_slide[] = $wpdb->prepare(
614 '(%d, %d)',
615 absint( $val ),
616 absint( $i )
617 );
618
619 $data_relation[] = $wpdb->prepare(
620 '(%d, %d)',
621 absint( $slice['slider_id'] ),
622 absint( $val )
623 );
624 }
625
626 $implode_data_slide = implode( ', ', $data_slide );
627
628 $implode_data_relation = implode( ', ', $data_relation );
629
630 $check_duplicate = $wpdb->get_results(
631 $wpdb->prepare(
632 '
633 SELECT slide_id
634 FROM ' . $wpdb->prefix . 'sldr_slide
635 WHERE attachment_id = %d
636 ',
637 $get_meta_val
638 ),
639 ARRAY_A
640 );
641
642 if ( ! $check_duplicate ) {
643 $wpdb->query(
644 '
645 INSERT INTO ' . $wpdb->prefix . 'sldr_slide ( `attachment_id`, `order` )
646 VALUES ' . $implode_data_slide . '
647 '
648 );
649 }
650
651 $wpdb->query(
652 '
653 INSERT INTO ' . $wpdb->prefix . 'sldr_relation ( `slider_id`, `attachment_id` )
654 VALUES ' . $implode_data_relation . '
655 '
656 );
657 }
658 }
659 }
660
661 if ( ! function_exists( 'gllr_settings' ) ) {
662 /**
663 * Register settings function
664 */
665 function gllr_settings() {
666 global $gllr_options, $gllr_plugin_info;
667
668 if ( empty( $gllr_plugin_info ) ) {
669 if ( ! function_exists( 'get_plugin_data' ) ) {
670 require_once ABSPATH . 'wp-admin/includes/plugin.php';
671 }
672 $gllr_plugin_info = get_plugin_data( __FILE__ );
673 }
674 /* Install the option defaults */
675 if ( ! get_option( 'gllr_options' ) ) {
676 $option_defaults = gllr_get_options_default();
677 add_option( 'gllr_options', $option_defaults );
678 }
679
680 /* Get options from the database */
681 $gllr_options = get_option( 'gllr_options' );
682
683 /* Array merge incase this version has added new options */
684 if ( isset( $gllr_options['plugin_option_version'] ) && $gllr_options['plugin_option_version'] !== $gllr_plugin_info['Version'] ) {
685
686 $option_defaults = gllr_get_options_default();
687
688 $option_defaults['display_demo_notice'] = 0;
689 $option_defaults['display_settings_notice'] = 0;
690
691 $gllr_options = array_merge( $option_defaults, $gllr_options );
692 $gllr_options['plugin_option_version'] = $gllr_plugin_info['Version'];
693
694 /* show pro features */
695 $gllr_options['hide_premium_options'] = array();
696
697 update_option( 'gllr_options', $gllr_options );
698 }
699
700 if ( function_exists( 'add_image_size' ) ) {
701 add_image_size( 'album-thumb', $gllr_options['custom_size_px']['album-thumb'][0], $gllr_options['custom_size_px']['album-thumb'][1], true );
702 add_image_size( 'photo-thumb', $gllr_options['custom_size_px']['photo-thumb'][0], $gllr_options['custom_size_px']['photo-thumb'][1], true );
703 }
704 }
705 }
706
707 if ( ! function_exists( 'gllr_get_options_default' ) ) {
708 /**
709 * Get Plugin default options
710 */
711 function gllr_get_options_default() {
712 global $gllr_plugin_info;
713
714 $option_defaults = array(
715 /* internal general */
716 'plugin_option_version' => $gllr_plugin_info['Version'],
717 'first_install' => strtotime( 'now' ),
718 'suggest_feature_banner' => 1,
719 'display_settings_notice' => 1,
720 /* internal */
721 'display_demo_notice' => 1,
722 'flush_rewrite_rules' => 1,
723 /* settings */
724 'custom_size_px' => array(
725 'album-thumb' => array( 120, 80 ),
726 'photo-thumb' => array( 160, 120 ),
727 ),
728 'custom_image_row_count' => 3,
729 'image_size_photo' => 'thumbnail',
730 'image_text' => 0,
731 'border_images' => 1,
732 'border_images_width' => 10,
733 'border_images_color' => '#F1F1F1',
734 'order_by' => 'meta_value_num',
735 'order' => 'ASC',
736 'return_link' => 0,
737 'return_link_url' => '',
738 'return_link_text' => __( 'Return to all albums', 'gallery-plugin' ),
739 'return_link_shortcode' => 0,
740 /* cover */
741 'page_id_gallery_template' => '',
742 'galleries_layout' => 'column',
743 'galleries_column_alignment' => 'left',
744 'image_size_album' => 'medium',
745 'cover_border_images' => 1,
746 'cover_border_images_width' => 10,
747 'cover_border_images_color' => '#F1F1F1',
748 'album_order_by' => 'date',
749 'album_order_by_category_option' => 'default',
750 'album_order_by_shortcode_option' => 'default',
751 'album_order' => 'DESC',
752 'read_more_link_text' => __( 'See images &raquo;', 'gallery-plugin' ),
753 /* lightbox */
754 'enable_lightbox' => 1,
755 'enable_image_opening' => 0,
756 'start_slideshow' => 0,
757 'slideshow_interval' => 2000,
758 'lightbox_download_link' => 0,
759 'lightbox_arrows' => 0,
760 'single_lightbox_for_multiple_galleries' => 0,
761 /* misc */
762 'post_type_name' => 'bws-gallery',
763 /* gallery_category */
764 'default_gallery_category' => '',
765 /* disable 3rd-party fancybox */
766 'disable_foreing_fancybox' => 0,
767 );
768
769 $option_defaults = apply_filters( 'gllr_get_additional_options_default', $option_defaults );
770
771 return $option_defaults;
772 }
773 }
774
775 if ( ! function_exists( 'gllr_include_demo_data' ) ) {
776 /**
777 * Plugin include demo
778 *
779 * @return void
780 */
781 function gllr_include_demo_data() {
782 global $gllr_bws_demo_data;
783 require_once plugin_dir_path( __FILE__ ) . 'includes/demo-data/class-bws-demo-data.php';
784 $args = array(
785 'plugin_basename' => plugin_basename( __FILE__ ),
786 'plugin_prefix' => 'gllr_',
787 'plugin_name' => 'Gallery',
788 'plugin_page' => 'gallery-plugin.php&bws_active_tab=import-export',
789 'install_callback' => 'gllr_plugin_upgrade',
790 'demo_folder' => plugin_dir_path( __FILE__ ) . 'includes/demo-data/',
791 );
792 $gllr_bws_demo_data = new Bws_Demo_Data( $args );
793
794 /* filter for image url from demo data */
795 add_filter( 'wp_get_attachment_url', array( $gllr_bws_demo_data, 'bws_wp_get_attachment_url' ), 10, 2 );
796 add_filter( 'wp_get_attachment_image_attributes', array( $gllr_bws_demo_data, 'bws_wp_get_attachment_image_attributes' ), 10, 3 );
797 add_filter( 'wp_update_attachment_metadata', array( $gllr_bws_demo_data, 'bws_wp_update_attachment_metadata' ), 10, 2 );
798 }
799 }
800 if ( ! function_exists( 'gllr_plugin_upgrade' ) ) {
801 /**
802 * Function for update all gallery images to new version ( Stable tag: 4.3.6 )
803 *
804 * @param bool $is_demo Flag for demo status.
805 */
806 function gllr_plugin_upgrade( $is_demo = true ) {
807 global $wpdb, $gllr_options;
808
809 $all_gallery_attachments = $wpdb->get_results(
810 $wpdb->prepare(
811 'SELECT p1.ID, p1.post_parent, p1.menu_order
812 FROM ' . $wpdb->posts . ' p1, ' . $wpdb->posts . ' p2
813 WHERE p1.post_parent = p2.ID
814 AND p1.post_mime_type LIKE %s
815 AND p1.post_type = "attachment"
816 AND p1.post_status = "inherit"
817 AND p2.post_type = %s',
818 'image%',
819 $gllr_options['post_type_name']
820 ),
821 ARRAY_A
822 );
823
824 if ( ! empty( $all_gallery_attachments ) ) {
825 $attachments_array = array();
826 foreach ( $all_gallery_attachments as $key => $value ) {
827 $post = $value['post_parent'];
828 $attachment = $value['ID'];
829 $order = $value['menu_order'];
830 if ( ! isset( $attachments_array[ $post ] ) || ( isset( $attachments_array[ $post ] ) && ! in_array( $attachment, $attachments_array[ $post ] ) ) ) {
831 $attachments_array[ $post ][] = $attachment;
832 if ( false === $is_demo ) {
833 update_post_meta( $attachment, '_gallery_order_' . $post, $order );
834 }
835 }
836 }
837 foreach ( $attachments_array as $key => $value ) {
838 update_post_meta( $key, '_gallery_images', implode( ',', $value ) );
839 }
840 /* set gallery category for demo data */
841 if ( function_exists( 'gllrctgrs_add_default_term_all_gallery' ) ) {
842 gllrctgrs_add_default_term_all_gallery();
843 }
844 }
845 }
846 }
847
848 if ( ! function_exists( 'gllr_post_type_images' ) ) {
849 /**
850 * Create post type and taxonomy for Gallery
851 *
852 * @param bool $force_flush_rules Flag for flush rules.
853 */
854 function gllr_post_type_images( $force_flush_rules = false ) {
855 global $gllr_options;
856
857 register_post_type(
858 $gllr_options['post_type_name'],
859 array(
860 'labels' => array(
861 'name' => __( 'Galleries', 'gallery-plugin' ),
862 'singular_name' => __( 'Gallery', 'gallery-plugin' ),
863 'add_new' => __( 'Add New Gallery', 'gallery-plugin' ),
864 'add_new_item' => __( 'Add New Gallery', 'gallery-plugin' ),
865 'edit_item' => __( 'Edit Gallery', 'gallery-plugin' ),
866 'new_item' => __( 'New Gallery', 'gallery-plugin' ),
867 'view_item' => __( 'View Gallery', 'gallery-plugin' ),
868 'search_items' => __( 'Search Galleries', 'gallery-plugin' ),
869 'not_found' => __( 'No Gallery found', 'gallery-plugin' ),
870 'parent_item_colon' => '',
871 'menu_name' => __( 'Galleries', 'gallery-plugin' ),
872 ),
873 'public' => true,
874 'publicly_queryable' => true,
875 'exclude_from_search' => true,
876 'query_var' => true,
877 'rewrite' => true,
878 'menu_icon' => 'dashicons-format-gallery',
879 'capability_type' => 'post',
880 'has_archive' => false,
881 'hierarchical' => true,
882 'supports' => array( 'title', 'editor', 'thumbnail', 'author', 'page-attributes', 'comments' ),
883 'register_meta_box_cb' => 'gllr_init_metaboxes',
884 'taxonomy' => array( 'gallery_categories' ),
885 )
886 );
887
888 register_taxonomy(
889 'gallery_categories',
890 $gllr_options['post_type_name'],
891 array(
892 'hierarchical' => true,
893 'labels' => array(
894 'name' => __( 'Gallery Categories', 'gallery-plugin' ),
895 'singular_name' => __( 'Gallery Category', 'gallery-plugin' ),
896 'add_new' => __( 'Add Gallery Category', 'gallery-plugin' ),
897 'add_new_item' => __( 'Add New Gallery Category', 'gallery-plugin' ),
898 'edit' => __( 'Edit Gallery Category', 'gallery-plugin' ),
899 'edit_item' => __( 'Edit Gallery Category', 'gallery-plugin' ),
900 'new_item' => __( 'New Gallery Category', 'gallery-plugin' ),
901 'view' => __( 'View Gallery Category', 'gallery-plugin' ),
902 'view_item' => __( 'View Gallery Category', 'gallery-plugin' ),
903 'search_items' => __( 'Find Gallery Category', 'gallery-plugin' ),
904 'not_found' => __( 'No Gallery Categories found', 'gallery-plugin' ),
905 'not_found_in_trash' => __( 'No Gallery Categories found in Trash', 'gallery-plugin' ),
906 'parent' => __( 'Parent Gallery Category', 'gallery-plugin' ),
907 'items_list_navigation' => __( 'Gallery Categories list navigation', 'gallery-plugin' ),
908 'items_list' => __( 'Gallery Categories list', 'gallery-plugin' ),
909 ),
910 'rewrite' => true,
911 'show_ui' => true,
912 'query_var' => true,
913 'sort' => true,
914 'map_meta_cap' => true,
915 )
916 );
917
918 if ( empty( $gllr_options['default_gallery_category'] ) ) {
919 $terms = get_terms(
920 'gallery_categories',
921 array(
922 'hide_empty' => false,
923 'fields' => 'ids',
924 )
925 );
926
927 if ( ! empty( $terms ) && is_array( $terms ) ) {
928 $def_term_id = min( $terms );
929 } else {
930 $def_term = 'Default';
931 if ( ! term_exists( $def_term, 'gallery_categories' ) ) {
932 $def_term_info = wp_insert_term(
933 $def_term,
934 'gallery_categories',
935 array(
936 'description' => '',
937 'slug' => 'default',
938 )
939 );
940 }
941 if ( is_array( $def_term_info ) ) {
942 $def_term_id = ( array_shift( $def_term_info ) );
943 }
944 }
945 if ( empty( $gllr_options['default_gallery_category'] ) ) {
946 $gllr_options['default_gallery_category'] = absint( $def_term_id );
947 }
948 }
949 $rewrite_rules = get_option( 'rewrite_rules' );
950 if ( is_array( $rewrite_rules ) && ! empty( $rewrite_rules ) && ! in_array( 'bws-gallery', $rewrite_rules ) || $force_flush_rules || ( isset( $gllr_options['flush_rewrite_rules'] ) && 1 === absint( $gllr_options['flush_rewrite_rules'] ) ) ) {
951 flush_rewrite_rules();
952 $gllr_options['flush_rewrite_rules'] = 0;
953 update_option( 'gllr_options', $gllr_options );
954 }
955 }
956 }
957
958 if ( ! function_exists( 'gllr_init_metaboxes' ) ) {
959 /**
960 * Add metabox for gallery post type
961 */
962 function gllr_init_metaboxes() {
963 global $gllr_options;
964 add_meta_box( 'Gallery-Shortcode', __( 'Gallery Shortcode', 'gallery-plugin' ), 'gllr_post_shortcode_box', $gllr_options['post_type_name'], 'side', 'high' );
965 }
966 }
967
968 if ( ! function_exists( 'gllr_post_shortcode_box' ) ) {
969 /**
970 * Create shortcode meta box for gallery post type
971 *
972 * @param string $obj Object for shortcode.
973 * @param string $box Box for shortcode.
974 */
975 function gllr_post_shortcode_box( $obj = '', $box = '' ) {
976 global $post; ?>
977 <div>
978 <?php
979 esc_html_e( 'Add a single gallery with images to your posts, pages, custom post types or widgets by using the following shortcode:', 'gallery-plugin' );
980 bws_shortcode_output( '[print_gllr id=' . $post->ID . ']' );
981 ?>
982 </div>
983 <div style="margin-top: 5px;">
984 <?php
985 esc_html_e( 'Add a gallery cover including featured image, description, and a link to your single gallery using the following shortcode:', 'gallery-plugin' );
986 bws_shortcode_output( '[print_gllr id=' . $post->ID . ' display=short]' );
987 ?>
988 </div>
989 <?php
990 }
991 }
992
993 if ( ! function_exists( 'gllr_save_postdata' ) ) {
994 /**
995 * Save gallery info
996 *
997 * @param number $post_id Post ID.
998 * @param number $post Post object.
999 */
1000 function gllr_save_postdata( $post_id, $post ) {
1001
1002 if ( isset( $post ) ) {
1003 if ( isset( $_POST['gllr_nonce_field'] )
1004 && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['gllr_nonce_field'] ) ), 'gllr_action' )
1005 ) {
1006 if ( isset( $_POST[ '_gallery_order_' . $post->ID ] ) ) {
1007 $i = 1;
1008 foreach ( $_POST[ '_gallery_order_' . $post->ID ] as $post_order_id => $order_id ) {
1009 update_post_meta( absint( $post_order_id ), '_gallery_order_' . $post->ID, $i );
1010 $i++;
1011 }
1012 update_post_meta( $post->ID, '_gallery_images', implode( ',', array_keys( $_POST[ '_gallery_order_' . $post->ID ] ) ) );
1013 }
1014
1015 if ( ( ( isset( $_POST['action-top'] ) && 'delete' === $_POST['action-top'] ) ||
1016 ( isset( $_POST['action-bottom'] ) && 'delete' === $_POST['action-bottom'] ) ) &&
1017 isset( $_POST['media'] ) ) {
1018 $gallery_images = get_post_meta( $post_id, '_gallery_images', true );
1019 $gallery_images_array = explode( ',', $gallery_images );
1020 $gallery_images_array = array_flip( $gallery_images_array );
1021 foreach ( $_POST['media'] as $delete_id ) {
1022 delete_post_meta( absint( $delete_id ), '_gallery_order_' . $post->ID );
1023 unset( $gallery_images_array[ absint( $delete_id ) ] );
1024 }
1025 $gallery_images_array = array_flip( $gallery_images_array );
1026 $gallery_images = implode( ',', $gallery_images_array );
1027 update_post_meta( $post->ID, '_gallery_images', $gallery_images );
1028 }
1029 if ( isset( $_REQUEST['gllr_image_text'] ) ) {
1030 foreach ( $_REQUEST['gllr_image_text'] as $gllr_image_text_key => $gllr_image_text ) {
1031 $value = sanitize_text_field( wp_unslash( $gllr_image_text ) );
1032 if ( get_post_meta( absint( $gllr_image_text_key ), 'gllr_image_text', false ) ) {
1033 /* Custom field has a value and this custom field exists in database */
1034 update_post_meta( absint( $gllr_image_text_key ), 'gllr_image_text', $value );
1035 } elseif ( $value ) {
1036 /* Custom field has a value, but this custom field does not exist in database */
1037 add_post_meta( absint( $gllr_image_text_key ), 'gllr_image_text', $value );
1038 }
1039 }
1040 }
1041 if ( isset( $_REQUEST['gllr_link_url'] ) ) {
1042 foreach ( $_REQUEST['gllr_link_url'] as $gllr_link_url_key => $gllr_link_url ) {
1043 $value = esc_url_raw( wp_unslash( trim( $gllr_link_url ) ) );
1044 if ( filter_var( $value, FILTER_VALIDATE_URL ) === false ) {
1045 $value = '';
1046 }
1047 if ( get_post_meta( absint( $gllr_link_url_key ), 'gllr_link_url', false ) ) {
1048 /* Custom field has a value and this custom field exists in database */
1049 update_post_meta( absint( $gllr_link_url_key ), 'gllr_link_url', $value );
1050 } elseif ( $value ) {
1051 /* Custom field has a value, but this custom field does not exist in database */
1052 add_post_meta( absint( $gllr_link_url_key ), 'gllr_link_url', $value );
1053 }
1054 }
1055 }
1056 if ( isset( $_REQUEST['gllr_image_alt_tag'] ) ) {
1057 foreach ( $_REQUEST['gllr_image_alt_tag'] as $gllr_image_alt_tag_key => $gllr_image_alt_tag ) {
1058 $value = sanitize_text_field( wp_unslash( $gllr_image_alt_tag ) );
1059 if ( get_post_meta( absint( $gllr_image_alt_tag_key ), 'gllr_image_alt_tag', false ) ) {
1060 /* Custom field has a value and this custom field exists in database */
1061 update_post_meta( absint( $gllr_image_alt_tag_key ), 'gllr_image_alt_tag', $value );
1062 } elseif ( $value ) {
1063 /* Custom field has a value, but this custom field does not exist in database */
1064 add_post_meta( absint( $gllr_image_alt_tag_key ), 'gllr_image_alt_tag', $value );
1065 }
1066 }
1067 }
1068 }
1069 }
1070 }
1071 }
1072
1073 if ( ! class_exists( 'Gllr_CategoryDropdown' ) ) {
1074 class Gllr_CategoryDropdown extends Walker_CategoryDropdown {
1075 /**
1076 * Start the element output.
1077 *
1078 * @param string $output Passed by reference. Used to append additional content.
1079 * @param object $term Category data object.
1080 * @param int $depth Depth of category in reference to parents. Default 0.
1081 * @param array $args An array of arguments.
1082 * @param int $id ID of the current term.
1083 */
1084 public function start_el( &$output, $term, $depth = 0, $args = array(), $id = 0 ) {
1085 $term_name = apply_filters( 'list_cats', $term->name, $term );
1086 $output .= '<option class="level-' . $depth . '" value="' . $term->slug . '"';
1087 if ( $term->slug === $args['selected'] ) {
1088 $output .= ' selected="selected"';
1089 }
1090 $output .= '>';
1091 $output .= str_repeat( '&nbsp;', $depth * 3 ) . $term_name;
1092 if ( $args['show_count'] ) {
1093 $output .= '&nbsp;( ' . $term->count . ' )';
1094 }
1095 $output .= '</option>';
1096 }
1097 }
1098 }
1099
1100 if ( ! function_exists( 'gllr_add_notice_below_table' ) ) {
1101 /**
1102 * Add notices on taxonomy page about insert shortcode
1103 */
1104 function gllr_add_notice_below_table() {
1105 global $gllr_options;
1106 if ( ! empty( $gllr_options['default_gallery_category'] ) ) {
1107 $def_term = get_term( $gllr_options['default_gallery_category'], 'gallery_categories' );
1108 if ( ! empty( $def_term ) ) {
1109 $def_term_name = $def_term->name;
1110 if ( ! empty( $def_term_name ) ) {
1111 echo '<div class="form-wrap"><p><i><strong>' . esc_html__( 'Note', 'gallery-plugin' ) . ':</strong> ' . sprintf( esc_html__( 'When deleting a category, the galleries that belong to this category will not be deleted. These galleries will be moved to the category %s.', 'gallery-plugin' ), '<strong>' . esc_html( $def_term_name ) . '</strong>' ) . '</i></p></div>';
1112 }
1113 }
1114 }
1115 }
1116 }
1117
1118 if ( ! function_exists( 'gllr_additive_field_in_category' ) ) {
1119 /**
1120 * Add Sort Galleries in Category dropdown
1121 */
1122 function gllr_additive_field_in_category() {
1123 global $gllr_options;
1124 ?>
1125 <div class="form-field term-description-wrap">
1126 <label for="tag-description"><?php esc_html_e( 'Sort Galleries in Category by', 'gallery-plugin' ); ?></label>
1127 <select name="album_order_by_category_option">
1128 <option value="ID"><?php esc_html_e( 'Gallery ID', 'gallery-plugin' ); ?></option>
1129 <option value="title"><?php esc_html_e( 'Title', 'gallery-plugin' ); ?></option>
1130 <option value="date"><?php esc_html_e( 'Date', 'gallery-plugin' ); ?></option>
1131 <option value="modified"><?php esc_html_e( 'Last modified date', 'gallery-plugin' ); ?></option>
1132 <option value="comment_count"><?php esc_html_e( 'Comment count', 'gallery-plugin' ); ?></option>
1133 <option value="menu_order"><?php esc_html_e( '"Order" field on the gallery edit page', 'gallery-plugin' ); ?></option>
1134 <option value="author"><?php esc_html_e( 'Author', 'gallery-plugin' ); ?></option>
1135 <option value="rand" class="bws_option_affect" data-affect-hide=".gllr_album_order"><?php esc_html_e( 'Random', 'gallery-plugin' ); ?></option>
1136 <option value="default" selected="selected" class="bws_option_affect" data-affect-hide=".gllr_album_order"><?php esc_html_e( 'Plugin Settings', 'gallery-plugin' ); ?></option>
1137 </select>
1138 <p id="description-description"><?php echo sprintf( esc_html__( 'Select galleries sorting order in your category. The sorting direction you can select in the %s', 'gallery-plugin' ), '<a href="' . esc_url( admin_url( 'edit.php?post_type=bws-gallery&page=gallery-plugin.php' ) ) . '">' . esc_html__( 'Cover Settings', 'gallery-plugin' ) . '</a>' ); ?></p>
1139 </div>
1140 <?php wp_nonce_field( 'gllr_category_action', 'gllr_category_nonce_field' ); ?>
1141 <?php
1142 }
1143 }
1144
1145 if ( ! function_exists( 'gllr_additive_field_in_category_edit' ) ) {
1146 /**
1147 * Add Sort Galleries in Category dropdown
1148 */
1149 function gllr_additive_field_in_category_edit() {
1150 $album_order = get_term_meta( absint( $_GET['tag_ID'] ), 'gllr_album_order', true );
1151 if ( empty( $album_order ) ) {
1152 $album_order = isset( $gllr_options['album_order_by_category_option'] ) ? $gllr_options['album_order_by_category_option'] : 'default';
1153 }
1154 ?>
1155 <tr valign="top">
1156 <th scope="row"><?php esc_html_e( 'Sort Galleries in Category by', 'gallery-plugin' ); ?></th>
1157 <td>
1158 <select name="album_order_by_category_option">
1159 <option value="ID" <?php selected( 'ID', $album_order ); ?>><?php esc_html_e( 'Gallery ID', 'gallery-plugin' ); ?></option>
1160 <option value="title" <?php selected( 'title', $album_order ); ?>><?php esc_html_e( 'Title', 'gallery-plugin' ); ?></option>
1161 <option value="date" <?php selected( 'date', $album_order ); ?>><?php esc_html_e( 'Date', 'gallery-plugin' ); ?></option>
1162 <option value="modified" <?php selected( 'modified', $album_order ); ?>><?php esc_html_e( 'Last modified date', 'gallery-plugin' ); ?></option>
1163 <option value="comment_count" <?php selected( 'comment_count', $album_order ); ?>><?php esc_html_e( 'Comment count', 'gallery-plugin' ); ?></option>
1164 <option value="menu_order" <?php selected( 'menu_order', $album_order ); ?>><?php esc_html_e( '"Order" field on the gallery edit page', 'gallery-plugin' ); ?></option>
1165 <option value="author" <?php selected( 'author', $album_order ); ?>><?php esc_html_e( 'Author', 'gallery-plugin' ); ?></option>
1166 <option value="rand" <?php selected( 'rand', $album_order ); ?> class="bws_option_affect" data-affect-hide=".gllr_album_order"><?php esc_html_e( 'Random', 'gallery-plugin' ); ?></option>
1167 <option value="default" <?php selected( 'default', $album_order ); ?> class="bws_option_affect" data-affect-hide=".gllr_album_order"><?php esc_html_e( 'Plugin Settings', 'gallery-plugin' ); ?></option>
1168 </select>
1169 <div class="bws_info"><?php echo sprintf( esc_html__( 'Select galleries sorting order in your category. The sorting direction you can select in the %s', 'gallery-plugin' ), '<a href="' . esc_url( admin_url( 'edit.php?post_type=bws-gallery&page=gallery-plugin.php' ) ) . '">' . esc_html__( 'Cover Settings', 'gallery-plugin' ) . '</a>' ); ?></p></div>
1170 </td>
1171 </tr>
1172 <?php wp_nonce_field( 'gllr_category_action', 'gllr_category_nonce_field' ); ?>
1173 <?php
1174 }
1175 }
1176
1177 if ( ! function_exists( 'gllr_save_category_additive_field' ) ) {
1178 /**
1179 * Save Sort Galleries in Category dropdown
1180 */
1181 function gllr_save_category_additive_field() {
1182 global $gllr_options;
1183 if ( isset( $_POST['album_order_by_category_option'] )
1184 && isset( $_POST['gllr_category_nonce_field'] )
1185 && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['gllr_category_nonce_field'] ) ), 'gllr_category_action' )
1186 ) {
1187 update_term_meta( absint( $_POST['tag_ID'] ), 'gllr_album_order', sanitize_text_field( wp_unslash( $_POST['album_order_by_category_option'] ) ) );
1188 }
1189 }
1190 }
1191
1192 if ( ! function_exists( 'gllr_add_column' ) ) {
1193 /**
1194 * Function for adding column in taxonomy
1195 *
1196 * @param array $column Columns array for taxonomy table.
1197 * @return array $column
1198 */
1199 function gllr_add_column( $column ) {
1200 $column['shortcode'] = __( 'Shortcode', 'gallery-plugin' );
1201 return $column;
1202 }
1203 }
1204
1205 if ( ! function_exists( 'gllr_fill_column' ) ) {
1206 /**
1207 * Function for filling column in taxonomy
1208 *
1209 * @param string $out Info for display.
1210 * @param string $column Column name for display info.
1211 * @param number $id Column id.
1212 * @return string $out
1213 */
1214 function gllr_fill_column( $out, $column, $id ) {
1215 if ( 'shortcode' === $column ) {
1216 $out = bws_shortcode_output( '[print_gllr cat_id=' . $id . ']' );
1217 }
1218 return $out;
1219 }
1220 }
1221
1222 if ( ! function_exists( 'gllr_default_term' ) ) {
1223 /**
1224 * Function assignment of default term for new gallery while updated post
1225 *
1226 * @param number $post_ID Post ID.
1227 */
1228 function gllr_default_term( $post_ID ) {
1229 global $gllr_options;
1230 $post = get_post( $post_ID );
1231 if ( $post->post_type === $gllr_options['post_type_name'] ) {
1232 if ( ! has_term( '', 'gallery_categories', $post ) ) {
1233 wp_set_object_terms( $post->ID, $gllr_options['default_gallery_category'], 'gallery_categories' );
1234 }
1235 }
1236 }
1237 }
1238
1239 if ( ! function_exists( 'gllr_taxonomy_filter' ) ) {
1240 /**
1241 * Function for adding taxonomy filter in gallery
1242 */
1243 function gllr_taxonomy_filter() {
1244 global $typenow, $gllr_options;
1245 if ( $typenow === $gllr_options['post_type_name'] ) {
1246 $current_taxonomy = isset( $_GET['gallery_categories'] ) ? sanitize_text_field( wp_unslash( $_GET['gallery_categories'] ) ) : '';
1247 $terms = get_terms( 'gallery_categories' );
1248 if ( 0 < count( $terms ) ) {
1249 ?>
1250 <select name="gallery_categories" id="gallery_categories">
1251 <option value=''><?php esc_html_e( 'All Gallery Categories', 'gallery-plugin' ); ?></option>
1252 <?php foreach ( $terms as $term ) { ?>
1253 <option value="<?php echo esc_attr( $term->slug ); ?>"<?php selected( $current_taxonomy, $term->slug ); ?>><?php echo esc_html( $term->name ) . ' ( ' . esc_html( $term->count ) . ' ) '; ?></option>
1254 <?php } ?>
1255 </select>
1256 <?php
1257 }
1258 }
1259 }
1260 }
1261
1262 if ( ! function_exists( 'gllr_hide_delete_link' ) ) {
1263 /**
1264 * Function for hide delete link ( protect default category from deletion )
1265 *
1266 * @param array $actions Actions array.
1267 * @param object $tag Term taxonomy object.
1268 * @return array $actions Post ID.
1269 */
1270 function gllr_hide_delete_link( $actions, $tag ) {
1271 global $gllr_options;
1272 if ( absint( $gllr_options['default_gallery_category'] ) === $tag->term_id ) {
1273 unset( $actions['delete'] );
1274 }
1275 return $actions;
1276 }
1277 }
1278
1279 if ( ! function_exists( 'gllr_hide_delete_cb' ) ) {
1280 /**
1281 * Function for hide delete chekbox ( protect default category from deletion )
1282 */
1283 function gllr_hide_delete_cb() {
1284 global $gllr_options;
1285 if ( ! isset( $_GET['taxonomy'] ) || sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) ) !== 'gallery_categories' ) {
1286 return;
1287 }
1288 ?>
1289 <style type="text/css">
1290 input[value="<?php echo esc_html( $gllr_options['default_gallery_category'] ); ?>"] {
1291 display: none;
1292 }
1293 </style>
1294 <?php
1295 }
1296 }
1297
1298 if ( ! function_exists( 'gllr_delete_term' ) ) {
1299 /**
1300 * Function for reassignment categories after delete any category,
1301 * Protect default category from deletion
1302 *
1303 * @param number $tt_id Term taxonomy ID.
1304 */
1305 function gllr_delete_term( $tt_id ) {
1306 global $post, $tag_ID, $gllr_options;
1307 $term = get_term_by( 'term_taxonomy_id', $tt_id, 'gallery_categories' );
1308 if ( ! empty( $term ) ) {
1309 $terms = get_terms(
1310 'gallery_categories',
1311 array(
1312 'orderby' => 'count',
1313 'hide_empty' => 0,
1314 'fields' => 'ids',
1315 )
1316 );
1317 if ( ! empty( $terms ) ) {
1318 $args = array(
1319 'post_type' => $gllr_options['post_type_name'],
1320 'posts_per_page' => -1,
1321 'tax_query' => array(
1322 array(
1323 'taxonomy' => 'gallery_categories',
1324 'field' => 'id',
1325 'terms' => $terms,
1326 'operator' => 'NOT IN',
1327 ),
1328 ),
1329 );
1330 $new_query = new WP_Query( $args );
1331 if ( $new_query->have_posts() ) {
1332 $posts = $new_query->posts;
1333 foreach ( $posts as $post ) {
1334 wp_set_object_terms( $post->ID, $gllr_options['default_gallery_category'], 'gallery_categories' );
1335 }
1336 }
1337 wp_reset_postdata();
1338 }
1339 if ( absint( $gllr_options['default_gallery_category'] ) === $tag_ID ) {
1340 wp_die( esc_html__( "You can't delete default gallery category.", 'gallery-plugin' ) );
1341 }
1342 }
1343 }
1344 }
1345
1346 if ( ! function_exists( 'gllr_custom_permalinks' ) ) {
1347 /**
1348 * Add custom permalinks for pages with 'gallery' template attribute
1349 *
1350 * @param array $rules Permalink rules.
1351 */
1352 function gllr_custom_permalinks( $rules ) {
1353 global $gllr_options;
1354
1355 $newrules = array();
1356
1357 if ( empty( $gllr_options ) ) {
1358 $gllr_options = get_option( 'gllr_options' );
1359 if ( empty( $gllr_options ) ) {
1360 gllr_settings();
1361 }
1362 }
1363
1364 if ( ! empty( $gllr_options['page_id_gallery_template'] ) ) {
1365 $parent = get_post( $gllr_options['page_id_gallery_template'] );
1366 if ( ! empty( $parent ) ) {
1367 if ( ! isset( $rules[ '(.+)/' . $parent->post_name . '/([^/]+)/?$' ] ) || ! isset( $rules[ $parent->post_name . '/([^/]+)/?$' ] ) ) {
1368 $newrules[ '(.+)/' . $parent->post_name . '/([^/]+)/?$' ] = 'index.php?post_type=' . $gllr_options['post_type_name'] . '&name=$matches[2]&posts_per_page=-1';
1369 $newrules[ $parent->post_name . '/([^/]+)/?$' ] = 'index.php?post_type=' . $gllr_options['post_type_name'] . '&name=$matches[1]&posts_per_page=-1';
1370 $newrules[ $parent->post_name . '/page/([^/]+)/?$' ] = 'index.php?pagename=' . $parent->post_name . '&paged=$matches[1]';
1371
1372 /* redirect from archives by gallery categories to the galleries list page */
1373 $newrules['gallery_categories/([^/]+)/page/([^/]+)/?$'] = 'index.php?pagename=' . $parent->post_name . '&gallery_categories=$matches[1]&paged=$matches[2]';
1374 $newrules['gallery_categories/([^/]+)/?$'] = 'index.php?pagename=' . $parent->post_name . '&gallery_categories=$matches[1]';
1375 }
1376 }
1377 }
1378
1379 /* fix feed permalink (<link rel="alternate" type="application/rss+xml" ... >) on the attachment single page (if the attachment is Attached to the gallery page) */
1380 if ( ! empty( $gllr_options['post_type_name'] ) ) {
1381 $newrules[ $gllr_options['post_type_name'] . '/.+?/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?attachment=$matches[1]&feed=$matches[2]';
1382 $newrules[ $gllr_options['post_type_name'] . '/.+?/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?attachment=$matches[1]&feed=$matches[2]';
1383 }
1384
1385 return $newrules + $rules;
1386 }
1387 }
1388
1389 if ( ! function_exists( 'gllr_template_include' ) ) {
1390 /**
1391 * Load a template. Handles template usage so that plugin can use own templates instead of the themes.
1392 *
1393 * Templates are in the 'templates' folder.
1394 * overrides in /{theme}/bws-templates/ by default.
1395 *
1396 * @param mixed $template Template name.
1397 * @return string
1398 */
1399 function gllr_template_include( $template ) {
1400 global $gllr_options, $wp_query;
1401
1402 if ( function_exists( 'is_embed' ) && is_embed() ) {
1403 return $template;
1404 }
1405 if ( ! is_search() ) {
1406 $post_type = get_post_type();
1407 if ( is_single() && $gllr_options['post_type_name'] === $post_type ) {
1408 $file = 'gallery-single-template.php';
1409 } elseif (
1410 ( $gllr_options['post_type_name'] === $post_type || isset( $wp_query->query_vars['gallery_categories'] ) ) ||
1411 ( ! empty( $gllr_options['page_id_gallery_template'] ) && is_page( $gllr_options['page_id_gallery_template'] ) )
1412 ) {
1413 $file = 'gallery-template.php';
1414 }
1415
1416 if ( isset( $file ) ) {
1417 $find = array( $file, 'bws-templates/' . $file );
1418 $template = locate_template( $find );
1419
1420 if ( ! $template ) {
1421 $template = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/' . $file;
1422 }
1423 }
1424 }
1425
1426 return $template;
1427 }
1428 }
1429
1430 if ( ! function_exists( 'gllr_template_title' ) ) {
1431 /**
1432 * This function returns title for gallery post type template
1433 */
1434 function gllr_template_title() {
1435 global $wp_query;
1436 if ( isset( $wp_query->query_vars['gallery_categories'] ) ) {
1437 $term = get_term_by( 'slug', $wp_query->query_vars['gallery_categories'], 'gallery_categories' );
1438 return __( 'Gallery Category', 'gallery-plugin' ) . ':&nbsp;' . $term->name;
1439 } else {
1440 return get_the_title();
1441 }
1442 }
1443 }
1444
1445 if ( ! function_exists( 'gllr_template_content' ) ) {
1446 /**
1447 * This function prints content for gallery post type template and returns array of pagination args and second query
1448 */
1449 function gllr_template_content() {
1450 global $post, $wp_query, $request, $gllr_options, $gllr_plugin_info;
1451 if ( ! $gllr_plugin_info ) {
1452 if ( ! function_exists( 'get_plugin_data' ) ) {
1453 require_once ABSPATH . 'wp-admin/includes/plugin.php';
1454 }
1455 $gllr_plugin_info = get_plugin_data( __FILE__ );
1456 }
1457 wp_register_script( 'gllr_js', plugins_url( 'js/frontend_script.js', __FILE__ ), array( 'jquery' ), $gllr_plugin_info['Version'], true );
1458
1459 if ( get_query_var( 'paged' ) ) {
1460 $paged = get_query_var( 'paged' );
1461 } elseif ( get_query_var( 'page' ) ) {
1462 $paged = get_query_var( 'page' );
1463 } else {
1464 $paged = 1;
1465 }
1466
1467 $per_page = get_option( 'posts_per_page' );
1468
1469 $args = array(
1470 'post_type' => $gllr_options['post_type_name'],
1471 'post_status' => 'publish',
1472 'orderby' => $gllr_options['album_order_by'],
1473 'order' => $gllr_options['album_order'],
1474 'posts_per_page' => $per_page,
1475 'paged' => $paged,
1476 );
1477
1478 if ( get_query_var( 'gallery_categories' ) ) {
1479 $args['tax_query'] = array(
1480 array(
1481 'taxonomy' => 'gallery_categories',
1482 'field' => 'slug',
1483 'terms' => get_query_var( 'gallery_categories' ),
1484 ),
1485 );
1486 }
1487
1488 $second_query = new WP_Query( $args );
1489 $request = $second_query->request;
1490
1491 printf(
1492 '<ul class="gllr-list %s">',
1493 ( 'column' === $gllr_options['galleries_layout'] && in_array( $gllr_options['galleries_column_alignment'], array( 'left', 'right', 'center' ) ) ) ? 'gllr-display-column gllr-column-align-' . esc_attr( $gllr_options['galleries_column_alignment'] ) : 'gllr-display-inline'
1494 );
1495 if ( $second_query->have_posts() ) {
1496 /* get width and height for image_size_album */
1497 if ( 'album-thumb' !== $gllr_options['image_size_album'] ) {
1498 $width = absint( get_option( $gllr_options['image_size_album'] . '_size_w' ) );
1499 $height = absint( get_option( $gllr_options['image_size_album'] . '_size_h' ) );
1500 } else {
1501 $width = $gllr_options['custom_size_px']['album-thumb'][0];
1502 $height = $gllr_options['custom_size_px']['album-thumb'][1];
1503 }
1504
1505 if ( 1 === absint( $gllr_options['cover_border_images'] ) ) {
1506 $border = 'border-width: ' . $gllr_options['cover_border_images_width'] . 'px; border-color:' . $gllr_options['cover_border_images_color'] . '; padding:0;';
1507 $border_images = $gllr_options['cover_border_images_width'] * 2;
1508 } else {
1509 $border = 'padding:0;';
1510 $border_images = 0;
1511 }
1512
1513 while ( $second_query->have_posts() ) {
1514 $second_query->the_post();
1515 $attachments = get_post_thumbnail_id( $post->ID );
1516 $featured_image = false;
1517
1518 if ( empty( $attachments ) ) {
1519 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
1520 $attachments = get_posts(
1521 array(
1522 'showposts' => 1,
1523 'what_to_show' => 'posts',
1524 'post_status' => 'inherit',
1525 'post_type' => 'attachment',
1526 'orderby' => $gllr_options['order_by'],
1527 'order' => $gllr_options['order'],
1528 'post__in' => explode( ',', $images_id ),
1529 'meta_key' => '_gallery_order_' . $post->ID,
1530 )
1531 );
1532 if ( ! empty( $attachments[0] ) ) {
1533 $first_attachment = $attachments[0];
1534 $image_attributes = wp_get_attachment_image_src( $first_attachment->ID, $gllr_options['image_size_album'] );
1535 } else {
1536 $image_attributes = array( '' );
1537 }
1538 } else {
1539 $featured_image = wp_get_attachment_image_src( $attachments, $gllr_options['image_size_album'] );
1540 }
1541 $featured_image = ( false === $featured_image ) ? $image_attributes : $featured_image;
1542
1543 $title = get_the_title();
1544 printf(
1545 '<li%s>',
1546 ( 'rows' === $gllr_options['galleries_layout'] ) ? wp_kses_post( ' style="width: ' . ( absint( $width ) + absint( $border_images ) ) . 'px;" data-gllr-width="' . ( absint( $width ) + absint( $border_images ) ) . '"' ) : ''
1547 );
1548 if ( ! empty( $featured_image[0] ) ) {
1549 $width = ! empty( $width ) ? 'width="' . $width . '"' : '';
1550 $height = ! empty( $height ) ? 'height="' . $height . '"' : '';
1551 $width_style = ! empty( $width ) ? 'width:' . $width . 'px;' : '';
1552 ?>
1553 <a rel="bookmark" href="<?php echo esc_url( get_permalink() ); ?>" title="<?php echo esc_html( $title ); ?>">
1554 <?php
1555 printf(
1556 '<img %1$s %2$s style="%3$s %4$s" alt="%5$s" title="%5$s" src="%6$s" /><div class="clear"></div>',
1557 esc_html( $width ),
1558 esc_html( $height ),
1559 esc_html( $width_style ),
1560 esc_html( $border ),
1561 esc_html( $title ),
1562 esc_url( $featured_image[0] )
1563 );
1564 ?>
1565 <div class="clear"></div>
1566 </a>
1567 <?php } ?>
1568 <div class="gallery_detail_box">
1569 <div class="gllr_detail_title"><?php echo esc_html( $title ); ?></div>
1570 <div class="gllr_detail_excerpt"><?php gllr_the_excerpt_max_charlength( 100 ); ?></div>
1571 <a href="<?php echo esc_url( get_permalink() ); ?>"><?php echo esc_html( $gllr_options['read_more_link_text'] ); ?></a>
1572 </div><!-- .gallery_detail_box -->
1573 <div class="gllr_clear"></div>
1574 </li>
1575 <?php
1576 }
1577 }
1578 ?>
1579 </ul>
1580
1581 <?php
1582 $count_all_albums = $second_query->found_posts;
1583 wp_reset_postdata();
1584 $request = $wp_query->request;
1585 $pages = absint( $count_all_albums / $per_page );
1586 if ( $count_all_albums % $per_page > 0 ) {
1587 ++$pages;
1588 }
1589 $range = 100;
1590 if ( ! $pages ) {
1591 $pages = 1;
1592 }
1593 return array(
1594 'second_query' => $second_query,
1595 'pages' => $pages,
1596 'paged' => $paged,
1597 'per_page' => $per_page,
1598 'range' => $range,
1599 );
1600 }
1601 }
1602
1603 if ( ! function_exists( 'gllr_template_pagination' ) ) {
1604 /**
1605 * This function prints pagination for gallery post type template
1606 *
1607 * @param array $args Arguments for paginations.
1608 */
1609 function gllr_template_pagination( $args ) {
1610 extract( $args );
1611 for ( $i = 1; $i <= $pages; $i++ ) {
1612 if ( 1 !== $pages && ( ! ( $i >= ( $paged + $range + 1 ) || $i <= ( $paged - $range - 1 ) ) || $pages <= $per_page ) ) {
1613 echo ( $paged === $i ) ? "<span class='page-numbers current'>" . esc_attr( $i ) . '</span>' : "<a class='page-numbers inactive' href='" . esc_url( get_pagenum_link( $i ) ) . "'>" . esc_html( $i ) . '</a>';
1614 }
1615 }
1616 }
1617 }
1618
1619 if ( ! function_exists( 'gllr_single_template_content' ) ) {
1620 /**
1621 * This function prints content for single gallery template
1622 */
1623 function gllr_single_template_content() {
1624 global $post, $wp_query, $gllr_options, $gllr_vars_for_inline_script, $gllr_plugin_info;
1625 if ( ! $gllr_plugin_info ) {
1626 if ( ! function_exists( 'get_plugin_data' ) ) {
1627 require_once ABSPATH . 'wp-admin/includes/plugin.php';
1628 }
1629 $gllr_plugin_info = get_plugin_data( __FILE__ );
1630 }
1631 wp_register_script( 'gllr_js', plugins_url( 'js/frontend_script.js', __FILE__ ), array( 'jquery' ), $gllr_plugin_info['Version'], true );
1632
1633 $args = array(
1634 'post_type' => $gllr_options['post_type_name'],
1635 'post_status' => 'publish',
1636 'name' => $wp_query->query_vars['name'],
1637 'posts_per_page' => 1,
1638 'p' => $wp_query->query_vars['p'],
1639 );
1640 $second_query = new WP_Query( $args );
1641
1642 if ( $second_query->have_posts() ) {
1643
1644 /* get width and height for image_size_photo */
1645 if ( 'photo-thumb' !== $gllr_options['image_size_photo'] ) {
1646 $width = absint( get_option( $gllr_options['image_size_photo'] . '_size_w' ) );
1647 $height = absint( get_option( $gllr_options['image_size_photo'] . '_size_h' ) );
1648 } else {
1649 $width = $gllr_options['custom_size_px']['photo-thumb'][0];
1650 $height = $gllr_options['custom_size_px']['photo-thumb'][1];
1651 }
1652
1653 while ( $second_query->have_posts() ) {
1654 $second_query->the_post();
1655 ?>
1656 <header class="entry-header <?php echo ( 'Twenty Twenty' === wp_get_theme()->get( 'Name' ) ) ? 'has-text-align-center' : ''; ?>">
1657 <h1 class="home_page_title entry-title"><?php the_title(); ?></h1>
1658 </header>
1659 <div class="gallery_box_single entry-content">
1660 <div class="gllr_page_content">
1661 <?php
1662 if ( ! post_password_required() ) {
1663 do_action( 'loop_start', $wp_query );
1664 if ( '' !== $post->post_content ) {
1665 the_content();
1666 }
1667
1668 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
1669
1670 $posts = get_posts(
1671 array(
1672 'showposts' => -1,
1673 'what_to_show' => 'posts',
1674 'post_status' => 'inherit',
1675 'post_type' => 'attachment',
1676 'orderby' => $gllr_options['order_by'],
1677 'order' => $gllr_options['order'],
1678 'post__in' => explode( ',', $images_id ),
1679 'meta_key' => '_gallery_order_' . $post->ID,
1680 )
1681 );
1682 if ( count( $posts ) > 0 ) {
1683 if ( '' === $post->post_content ) {
1684 ob_start();
1685 }
1686 $count_image_block = 0;
1687 ?>
1688 <div class="gallery gllr_grid" data-gllr-columns="<?php echo esc_attr( $gllr_options['custom_image_row_count'] ); ?>" data-gllr-border-width="<?php echo esc_attr( $gllr_options['border_images_width'] ); ?>">
1689 <?php
1690 foreach ( $posts as $attachment ) {
1691 $image_attributes = wp_get_attachment_image_src( $attachment->ID, $gllr_options['image_size_photo'] );
1692 $image_attributes_large = wp_get_attachment_image_src( $attachment->ID, 'large' );
1693 $image_attributes_full = wp_get_attachment_image_src( $attachment->ID, 'full' );
1694 if ( 1 === absint( $gllr_options['border_images'] ) ) {
1695 $border = 'border-width: ' . $gllr_options['border_images_width'] . 'px; border-color:' . $gllr_options['border_images_color'] . ';border: ' . $gllr_options['border_images_width'] . 'px solid ' . $gllr_options['border_images_color'];
1696 $border_images = $gllr_options['border_images_width'] * 2;
1697 } else {
1698 $border = '';
1699 $border_images = 0;
1700 }
1701 $url_for_link = get_post_meta( $attachment->ID, 'gllr_link_url', true );
1702 $image_text = get_post_meta( $attachment->ID, 'gllr_image_text', true );
1703 $image_alt_tag = get_post_meta( $attachment->ID, 'gllr_image_alt_tag', true );
1704
1705 if ( 0 === $count_image_block % $gllr_options['custom_image_row_count'] ) {
1706 ?>
1707 <div class="gllr_image_row">
1708 <?php } ?>
1709 <div class="gllr_image_block">
1710 <p style="
1711 <?php
1712 if ( $width ) {
1713 echo 'width:' . ( esc_attr( $width + $border_images ) ) . 'px;';
1714 } if ( $height ) {
1715 echo 'height:' . ( esc_attr( $height + $border_images ) ) . 'px;';
1716 }
1717 ?>
1718 ">
1719 <?php
1720 $width_html = ! empty( $width ) ? 'width="' . $width . '"' : '';
1721 $height_html = ! empty( $height ) ? 'height="' . $height . '"' : '';
1722 $width_style = ! empty( $width ) ? 'width:' . $width . 'px;' : '';
1723 $height_style = ! empty( $height ) ? 'height:' . $height . 'px;' : '';
1724 if ( ! empty( $url_for_link ) ) {
1725 ?>
1726 <a href="<?php echo esc_url( $url_for_link ); ?>" title="<?php echo esc_html( $image_text ); ?>" target="_blank">
1727 <?php
1728 printf(
1729 '<img %1$s %2$s style="%3$s %4$s %5$s" alt="%6$s" title="%7$s" src="%8$s" />',
1730 esc_html( $width_html ),
1731 esc_html( $height_html ),
1732 esc_html( $width_style ),
1733 esc_html( $height_style ),
1734 esc_html( $border ),
1735 esc_html( $image_alt_tag ),
1736 esc_html( $image_text ),
1737 esc_url( $image_attributes[0] )
1738 );
1739 ?>
1740 </a>
1741 <?php
1742 } else {
1743 if ( 1 !== absint( $gllr_options['enable_image_opening'] ) ) {
1744 ?>
1745 <a data-fancybox="gallery_fancybox<?php echo 0 === absint( $gllr_options['single_lightbox_for_multiple_galleries'] ) ? '_' . esc_attr( $post->ID ) : ''; ?>" href="<?php echo esc_url( $image_attributes_large[0] ); ?>" title="<?php echo esc_html( $image_text ); ?>" >
1746 <?php
1747 printf(
1748 '<img %1$s %2$s style="%3$s %4$s %5$s" alt="%6$s" title="%7$s" src="%8$s" rel="#" />',
1749 esc_html( $width_html ),
1750 esc_html( $height_html ),
1751 esc_html( $width_style ),
1752 esc_html( $height_style ),
1753 esc_html( $border ),
1754 esc_html( $image_alt_tag ),
1755 esc_html( $image_text ),
1756 esc_url( $image_attributes_full[0] )
1757 );
1758 ?>
1759 </a>
1760 <?php } else { ?>
1761 <a data-fancybox="gallery_fancybox<?php echo 0 === absint( $gllr_options['single_lightbox_for_multiple_galleries'] ) ? '_' . esc_attr( $post->ID ) : ''; ?>" href="#" style="pointer-events: none;" title="<?php echo esc_html( $image_text ); ?>" >
1762 <?php
1763 printf(
1764 '<img %1$s %2$s style="%3$s %4$s %5$s" alt="%6$s" title="%7$s" src="%8$s" rel="#" />',
1765 esc_html( $width_html ),
1766 esc_html( $height_html ),
1767 esc_html( $width_style ),
1768 esc_html( $height_style ),
1769 esc_html( $border ),
1770 esc_html( $image_alt_tag ),
1771 esc_html( $image_text ),
1772 esc_url( $image_attributes[0] )
1773 );
1774 ?>
1775 </a>
1776 <?php
1777 }
1778 }
1779 ?>
1780 </p>
1781 <?php if ( 1 === absint( $gllr_options['image_text'] ) ) { ?>
1782 <div
1783 <?php
1784 if ( $width ) {
1785 echo 'style="width:' . ( esc_attr( $width + $border_images ) ) . 'px;"';
1786 }
1787 ?>
1788 class="gllr_single_image_text gllr_single_image_text_under"><?php echo esc_html( $image_text ); ?>&nbsp;</div>
1789 <?php } ?>
1790 </div><!-- .gllr_image_block -->
1791 <?php if ( absint( $gllr_options['custom_image_row_count'] ) - 1 === $count_image_block % $gllr_options['custom_image_row_count'] ) { ?>
1792 <div class="clear"></div>
1793 </div><!-- .gllr_image_row -->
1794 <?php
1795 }
1796 $count_image_block++;
1797 }
1798 if ( $count_image_block > 0 && 0 !== $count_image_block % $gllr_options['custom_image_row_count'] ) {
1799 ?>
1800 </div><!-- .gllr_image_row -->
1801 <?php } ?>
1802 </div><!-- .gallery.clearfix -->
1803 <?php
1804 if ( '' === $post->post_content ) {
1805 $output = ob_get_contents();
1806 ob_end_clean();
1807 echo apply_filters( 'the_content', $output );
1808 }
1809 }
1810 if ( 1 === absint( $gllr_options['return_link'] ) ) {
1811 if ( empty( $gllr_options['return_link_url'] ) ) {
1812 if ( ! empty( $gllr_options['page_id_gallery_template'] ) ) {
1813 ?>
1814 <div class="gllr_clear"></div>
1815 <div class="return_link gllr_return_link"><a href="<?php echo esc_url( get_permalink( $gllr_options['page_id_gallery_template'] ) ); ?>"><?php echo esc_html( $gllr_options['return_link_text'] ); ?></a></div>
1816 <?php
1817 }
1818 } else {
1819 ?>
1820 <div class="gllr_clear"></div>
1821 <div class="return_link gllr_return_link"><a href="<?php echo esc_url( $gllr_options['return_link_url'] ); ?>"><?php echo esc_html( $gllr_options['return_link_text'] ); ?></a></div>
1822 <?php
1823 }
1824 }
1825 do_action( 'loop_end', $wp_query );
1826 if ( $gllr_options['enable_lightbox'] ) {
1827
1828 $gllr_vars_for_inline_script['single_script'][] = apply_filters( 'gllr_options_for_inline_script', array( 'post_id' => $post->ID ) );
1829
1830 if ( defined( 'BWS_ENQUEUE_ALL_SCRIPTS' ) ) {
1831 gllr_echo_inline_script();
1832 }
1833 }
1834 } else {
1835 ?>
1836 <p><?php echo get_the_password_form(); ?></p>
1837 <?php } ?>
1838 </div><!-- .gllr_page_content -->
1839 </div><!-- .gallery_box_single -->
1840 <?php
1841 }
1842 } else {
1843 ?>
1844 <div class="gallery_box_single">
1845 <p class="not_found"><?php esc_html_e( 'Sorry, nothing found.', 'gallery-plugin' ); ?></p>
1846 </div><!-- .gallery_box_single -->
1847 <?php
1848 }
1849 }
1850 }
1851
1852 if ( ! function_exists( 'gllr_add_pdf_print_content' ) ) {
1853 /**
1854 * This function returns custom content with images for PDF&Print plugin in Gallery post
1855 *
1856 * @param string $content Content for print button.
1857 * @param array $params Params for content of buttons.
1858 */
1859 function gllr_add_pdf_print_content( $content, $params = '' ) {
1860 global $post, $wp_query, $gllr_options;
1861 $current_post_type = get_post_type();
1862 $custom_content = '';
1863
1864 /* Displaying PDF&PRINT custom content for single gallery */
1865 if ( $gllr_options['post_type_name'] === $current_post_type && ! get_query_var( 'gallery_categories' ) ) {
1866
1867 if ( 'photo-thumb' !== $gllr_options['image_size_photo'] ) {
1868 $width = absint( get_option( $gllr_options['image_size_photo'] . '_size_w' ) );
1869 $height = absint( get_option( $gllr_options['image_size_photo'] . '_size_h' ) );
1870 } else {
1871 $width = $gllr_options['custom_size_px']['photo-thumb'][0];
1872 $height = $gllr_options['custom_size_px']['photo-thumb'][1];
1873 }
1874
1875 $custom_content .= "
1876 <style type='text/css'>
1877 .gllr_grid,
1878 .gllr_grid td {
1879 border: none;
1880 vertical-align: top;
1881 }
1882 .gllr_grid {
1883 table-layout: fixed;
1884 margin: 0 auto;
1885 }
1886 .gllr_grid td img {
1887 width: {$width}px;
1888 height: {$height}px;
1889 }
1890 </style>\n";
1891
1892 if ( 1 === absint( $gllr_options['border_images'] ) ) {
1893 $image_style = "border: {$gllr_options['border_images_width']}px solid {$gllr_options['border_images_color']};";
1894 } else {
1895 $image_style = 'border: none;';
1896 }
1897 $image_style .= 'margin: 0;';
1898
1899 $args = array(
1900 'post_type' => $gllr_options['post_type_name'],
1901 'post_status' => 'publish',
1902 'name' => $wp_query->query_vars['name'],
1903 'posts_per_page' => 1,
1904 );
1905 $second_query = new WP_Query( $args );
1906 if ( $second_query->have_posts() ) {
1907 while ( $second_query->have_posts() ) {
1908 $second_query->the_post();
1909 $custom_content .= '<div class="gallery_box_single entry-content">';
1910 if ( ! post_password_required() ) {
1911 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
1912 $posts = get_posts(
1913 array(
1914 'showposts' => -1,
1915 'what_to_show' => 'posts',
1916 'post_status' => 'inherit',
1917 'post_type' => 'attachment',
1918 'orderby' => $gllr_options['order_by'],
1919 'order' => $gllr_options['order'],
1920 'post__in' => explode( ',', $images_id ),
1921 'meta_key' => '_gallery_order_' . $post->ID,
1922 )
1923 );
1924
1925 if ( count( $posts ) > 0 ) {
1926 $count_image_block = 0;
1927 $custom_content .= '<table class="gallery clearfix gllr_grid">';
1928 foreach ( $posts as $attachment ) {
1929 $image_attributes = wp_get_attachment_image_src( $attachment->ID, $gllr_options['image_size_photo'] );
1930 if ( 0 === $count_image_block % $gllr_options['custom_image_row_count'] ) {
1931 $custom_content .= '<tr>';
1932 }
1933 $custom_content .= '<td class="gllr_image_block">
1934 <div>
1935 <img src="' . $image_attributes[0] . '" style="' . $image_style . '" />
1936 </div>';
1937 if ( 1 === absint( $gllr_options['image_text'] ) ) {
1938 $custom_content .= '<div class="gllr_single_image_text gllr_single_image_text_under">' . get_post_meta( $attachment->ID, 'gllr_image_text', true ) . '</div>';
1939 }
1940 $custom_content .= "</td><!-- .gllr_image_block -->\n";
1941 if ( $count_image_block % $gllr_options['custom_image_row_count'] === $gllr_options['custom_image_row_count'] - 1 ) {
1942 $custom_content .= "</tr>\n";
1943 }
1944 $count_image_block++;
1945 }
1946 if ( $count_image_block > 0 && 0 !== $count_image_block % $gllr_options['custom_image_row_count'] ) {
1947 while ( 0 !== $count_image_block % $gllr_options['custom_image_row_count'] ) {
1948 $custom_content .= '<td class="gllr_image_block"></td>';
1949 $count_image_block++;
1950 }
1951 $custom_content .= '</tr>';
1952 }
1953 $custom_content .= '</table><!-- .gallery.clearfix -->';
1954 }
1955 }
1956 $custom_content .= '</div><!-- .gallery_box_single -->';
1957 }
1958 } else {
1959 $custom_content .= '<div class="gallery_box_single">
1960 <p class="not_found">' . __( 'Sorry, nothing found.', 'gallery-plugin' ) . '</p>
1961 </div><!-- .gallery_box_single -->';
1962 }
1963 $custom_content .= '<div class="gllr_clear"></div>';
1964 } elseif ( absint( $gllr_options['page_id_gallery_template'] ) === $post->ID ) {
1965 if ( 'album-thumb' !== $gllr_options['image_size_album'] ) {
1966 $width = absint( get_option( $gllr_options['image_size_album'] . '_size_w' ) );
1967 $height = absint( get_option( $gllr_options['image_size_album'] . '_size_h' ) );
1968 } else {
1969 $width = $gllr_options['custom_size_px']['album-thumb'][0];
1970 $height = $gllr_options['custom_size_px']['album-thumb'][1];
1971 }
1972 /* Displaying PDF&PRINT custom content for gallery pro template */
1973 $custom_content .= "<style type='text/css'>
1974 .gllr-list {
1975 list-style: none;
1976 margin-left: 0;
1977 padding: 0;
1978 }
1979 .gllr-list li > a > img {
1980 width: {$width}px;
1981 height: {$height}px;
1982 margin: 10px 0;
1983 }
1984 #gallery_pagination > span,
1985 #gallery_pagination > a {
1986 display: inline-block;
1987 padding: 5px;
1988 }
1989 </style>";
1990 $custom_content .= '<ul class="gllr-list">';
1991 global $request;
1992 if ( get_query_var( 'paged' ) ) {
1993 $paged = get_query_var( 'paged' );
1994 } elseif ( get_query_var( 'page' ) ) {
1995 $paged = get_query_var( 'page' );
1996 } else {
1997 $paged = 1;
1998 }
1999
2000 $per_page = get_option( 'posts_per_page' );
2001 $showitems = $per_page;
2002
2003 $args = array(
2004 'post_type' => $gllr_options['post_type_name'],
2005 'post_status' => 'publish',
2006 'orderby' => $gllr_options['album_order_by'],
2007 'order' => $gllr_options['album_order'],
2008 'posts_per_page' => $per_page,
2009 'paged' => $paged,
2010 );
2011 if ( isset( $wp_query->query_vars['gallery_categories'] ) && ( ! empty( $wp_query->query_vars['gallery_categories'] ) ) ) {
2012 $args['tax_query'] = array(
2013 array(
2014 'taxonomy' => 'gallery_categories',
2015 'field' => 'slug',
2016 'terms' => $wp_query->query_vars['gallery_categories'],
2017 ),
2018 );
2019 }
2020 $second_query = new WP_Query( $args );
2021 $request = $second_query->request;
2022
2023 if ( $second_query->have_posts() ) {
2024 while ( $second_query->have_posts() ) {
2025 $second_query->the_post();
2026 $attachments = get_post_thumbnail_id( $post->ID );
2027 if ( empty( $attachments ) ) {
2028 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
2029 $attachments = get_posts(
2030 array(
2031 'showposts' => 1,
2032 'what_to_show' => 'posts',
2033 'post_status' => 'inherit',
2034 'post_type' => 'attachment',
2035 'orderby' => $gllr_options['order_by'],
2036 'order' => $gllr_options['order'],
2037 'post__in' => explode( ',', $images_id ),
2038 'meta_key' => '_gallery_order_' . $post->ID,
2039 )
2040 );
2041 if ( ! empty( $attachments[0] ) ) {
2042 $first_attachment = $attachments[0];
2043 $image_attributes = wp_get_attachment_image_src( $first_attachment->ID, $gllr_options['image_size_album'] );
2044 } else {
2045 $image_attributes = array( '' );
2046 }
2047 } else {
2048 $image_attributes = wp_get_attachment_image_src( $attachments, $gllr_options['image_size_album'] );
2049 }
2050 if ( 1 === absint( $gllr_options['cover_border_images'] ) ) {
2051 $border = 'border: ' . $gllr_options['cover_border_images_width'] . 'px solid ' . $gllr_options['cover_border_images_color'] . '; padding:0;';
2052 } else {
2053 $border = 'padding:0;';
2054 }
2055 $custom_content .= '<li>';
2056 $excerpt = wp_strip_all_tags( get_the_content() );
2057 if ( strlen( $excerpt ) > 100 ) {
2058 $excerpt = substr( $excerpt, 0, strripos( substr( $excerpt, 0, 100 ), ' ' ) ) . '...';
2059 }
2060 $custom_content .= '<img width="' . $width . '" height="' . $height . '" style="width:' . $width . 'px; height:' . $height . 'px;' . $border . '" src="' . $image_attributes[0] . '" />
2061 <div class="gallery_detail_box">
2062 <div class="gllr_detail_title">' . get_the_title() . '</div>
2063 <div class="gllr_detail_excerpt">' . $excerpt . '</div>';
2064 if ( 0 === absint( $gllr_options['hide_single_gallery'] ) ) {
2065 $custom_content .= '<a href="' . get_permalink() . '">' . $gllr_options['read_more_link_text'] . '</a>';
2066 }
2067 $custom_content .= '</div><!-- .gallery_detail_box -->
2068 <div class="gllr_clear"></div>
2069 </li>';
2070 }
2071 }
2072 $custom_content .= '</ul>';
2073 }
2074
2075 /* Displaying PDF&PRINT custom content for shortcode */
2076 if ( ! empty( $params ) && 'array' === gettype( $params ) ) {
2077 extract(
2078 shortcode_atts(
2079 array(
2080 'id' => '',
2081 'display' => 'full',
2082 'cat_id' => '',
2083 ),
2084 $params
2085 )
2086 );
2087
2088 $old_wp_query = $wp_query;
2089
2090 require_once ABSPATH . 'wp-admin/includes/plugin.php';
2091 if ( ! empty( $cat_id ) ) {
2092 global $post, $wp_query;
2093 $term = get_term( $cat_id, 'gallery_categories' );
2094 if ( ! empty( $term ) ) {
2095 $args = array(
2096 'post_type' => $gllr_options['post_type_name'],
2097 'post_status' => 'publish',
2098 'posts_per_page' => -1,
2099 'gallery_categories' => $term->slug,
2100 'orderby' => $gllr_options['album_order_by'],
2101 'order' => $gllr_options['album_order'],
2102 );
2103 $second_query = new WP_Query( $args );
2104 $custom_content .= "<style type='text/css'>
2105 .gallery_box ul {
2106 list-style: none outside none !important;
2107 margin: 0;
2108 padding: 0;
2109 }
2110 .gallery_box ul li {
2111 margin: 0 0 20px;
2112 }
2113 .gallery_box li img {
2114 margin: 0 10px 10px 0;
2115 float: left;
2116 box-sizing: content-box;
2117 -moz-box-sizing: content-box;
2118 -webkit-box-sizing: content-box;
2119 }
2120 .rtl .gallery_box li img {
2121 margin: 0 0 10px 10px;
2122 float: right;
2123 }
2124 .gallery_detail_box {
2125 clear: both;
2126 float: left;
2127 }
2128 .rtl .gallery_detail_box {
2129 float: right;
2130 }
2131 .gllr_clear {
2132 clear: both;
2133 height: 0;
2134 }
2135 </style>";
2136 $custom_content .= '<div class="gallery_box">
2137 <ul>';
2138 if ( $second_query->have_posts() ) {
2139 if ( 'album-thumb' !== $gllr_options['image_size_album'] ) {
2140 $width = absint( get_option( $gllr_options['image_size_album'] . '_size_w' ) );
2141 $height = absint( get_option( $gllr_options['image_size_album'] . '_size_h' ) );
2142 } else {
2143 $width = $gllr_options['custom_size_px']['album-thumb'][0];
2144 $height = $gllr_options['custom_size_px']['album-thumb'][1];
2145 }
2146 if ( 1 === absint( $gllr_options['cover_border_images'] ) ) {
2147 $border = 'border-width: ' . $gllr_options['cover_border_images_width'] . 'px; border-color: ' . $gllr_options['cover_border_images_color'] . ';border: ' . $gllr_options['cover_border_images_width'] . 'px solid ' . $gllr_options['cover_border_images_color'];
2148 } else {
2149 $border = '';
2150 }
2151
2152 while ( $second_query->have_posts() ) {
2153 $second_query->the_post();
2154 $attachments = get_post_thumbnail_id( $post->ID );
2155 if ( empty( $attachments ) ) {
2156 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
2157 $attachments = get_posts(
2158 array(
2159 'showposts' => 1,
2160 'what_to_show' => 'posts',
2161 'post_status' => 'inherit',
2162 'post_type' => 'attachment',
2163 'orderby' => $gllr_options['order_by'],
2164 'order' => $gllr_options['order'],
2165 'post__in' => explode( ',', $images_id ),
2166 'meta_key' => '_gallery_order_' . $post->ID,
2167 )
2168 );
2169 if ( ! empty( $attachments[0] ) ) {
2170 $first_attachment = $attachments[0];
2171 $image_attributes = wp_get_attachment_image_src( $first_attachment->ID, $gllr_options['image_size_album'] );
2172 } else {
2173 $image_attributes = array( '' );
2174 }
2175 } else {
2176 $image_attributes = wp_get_attachment_image_src( $attachments, $gllr_options['image_size_album'] );
2177 }
2178 $excerpt = wp_strip_all_tags( get_the_content() );
2179 if ( strlen( $excerpt ) > 100 ) {
2180 $excerpt = substr( $excerpt, 0, strripos( substr( $excerpt, 0, 100 ), ' ' ) ) . '...';
2181 }
2182 $custom_content .= '<li>
2183 <img width="' . $width . '" height="' . $height . '" style="width:' . $width . 'px; height:' . $height . 'px;' . $border . '" src="' . $image_attributes[0] . '" />
2184 <div class="gallery_detail_box">
2185 <div class="gllr_detail_title">' . get_the_title() . '</div>
2186 <div class="gllr_detail_excerpt">' . $excerpt . '</div>
2187 <a href="' . get_permalink( $post->ID ) . '">' . $gllr_options['read_more_link_text'] . '</a>
2188 </div><!-- .gallery_detail_box -->
2189 <div class="gllr_clear"></div>
2190 </li>';
2191 }
2192 }
2193 $custom_content .= '</ul>
2194 </div><!-- .gallery_box -->';
2195 }
2196 } else {
2197 $args = array(
2198 'post_type' => $gllr_options['post_type_name'],
2199 'post_status' => 'publish',
2200 'p' => $id,
2201 'posts_per_page' => 1,
2202 );
2203 $second_query = new WP_Query( $args );
2204
2205 if ( 'short' === $display ) {
2206 if ( $second_query->have_posts() ) {
2207 $second_query->the_post();
2208 $attachments = get_post_thumbnail_id( $post->ID );
2209 if ( empty( $attachments ) ) {
2210 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
2211 $attachments = get_posts(
2212 array(
2213 'showposts' => 1,
2214 'what_to_show' => 'posts',
2215 'post_status' => 'inherit',
2216 'post_type' => 'attachment',
2217 'orderby' => $gllr_options['order_by'],
2218 'order' => $gllr_options['order'],
2219 'post__in' => explode( ',', $images_id ),
2220 'meta_key' => '_gallery_order_' . $post->ID,
2221 )
2222 );
2223 if ( ! empty( $attachments[0] ) ) {
2224 $first_attachment = $attachments[0];
2225 $image_attributes_featured = wp_get_attachment_image_src( $first_attachment->ID, $gllr_options['image_size_album'] );
2226 } else {
2227 $image_attributes_featured = array( '' );
2228 }
2229 } else {
2230 $image_attributes_featured = wp_get_attachment_image_src( $attachments, $gllr_options['image_size_album'] );
2231 }
2232
2233 if ( 1 === absint( $gllr_options['cover_border_images'] ) ) {
2234 $border = 'border-width: ' . $gllr_options['cover_border_images_width'] . 'px; border-color: ' . $gllr_options['cover_border_images_color'] . ';border: ' . $gllr_options['cover_border_images_width'] . 'px solid ' . $gllr_options['cover_border_images_color'];
2235 } else {
2236 $border = '';
2237 }
2238
2239 $excerpt = wp_strip_all_tags( get_the_content() );
2240 if ( strlen( $excerpt ) > 100 ) {
2241 $excerpt = substr( $excerpt, 0, strripos( substr( $excerpt, 0, 100 ), ' ' ) ) . '...';
2242 }
2243 if ( 'album-thumb' !== $gllr_options['image_size_album'] ) {
2244 $width = absint( get_option( $gllr_options['image_size_album'] . '_size_w' ) );
2245 $height = absint( get_option( $gllr_options['image_size_album'] . '_size_h' ) );
2246 } else {
2247 $width = $gllr_options['custom_size_px']['album-thumb'][0];
2248 $height = $gllr_options['custom_size_px']['album-thumb'][1];
2249 }
2250 $custom_content .= '<div class="gallery_box">';
2251 $custom_content .= "<img width=\"{$width}\" height=\"{$height}\" style=\"width:{$width}px; height:{$height}px; {$border}\" src=\"{$image_attributes_featured[0]}\" />";
2252 $custom_content .= '<div class="gallery_detail_box">
2253 <div class="gllr_detail_title">' . get_the_title() . '</div>
2254 <p class="gllr_detail_excerpt">' . $excerpt . '</p>';
2255 if ( 0 === absint( $gllr_options['hide_single_gallery'] ) ) {
2256 $custom_content .= '<a href="' . get_permalink() . '">' . $gllr_options['read_more_link_text'] . '</a>';
2257 }
2258 $custom_content .= '</div><!-- .gallery_detail_box -->
2259 <div class=\"gllr_clear\"></div>
2260 </div>';
2261 }
2262 } else {
2263 $custom_content .= '<div class="gallery_box_single">';
2264 if ( $second_query->have_posts() ) {
2265 if ( 'photo-thumb' !== $gllr_options['image_size_photo'] ) {
2266 $width = absint( get_option( $gllr_options['image_size_photo'] . '_size_w' ) );
2267 $height = absint( get_option( $gllr_options['image_size_photo'] . '_size_h' ) );
2268 } else {
2269 $width = $gllr_options['custom_size_px']['photo-thumb'][0];
2270 $height = $gllr_options['custom_size_px']['photo-thumb'][1];
2271 }
2272 while ( $second_query->have_posts() ) {
2273 $second_query->the_post();
2274 $custom_content .= do_shortcode( get_the_content() );
2275
2276 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
2277
2278 $posts = get_posts(
2279 array(
2280 'what_to_show' => 'posts',
2281 'post_status' => 'inherit',
2282 'post_type' => 'attachment',
2283 'orderby' => $gllr_options['order_by'],
2284 'order' => $gllr_options['order'],
2285 'post__in' => explode( ',', $images_id ),
2286 'meta_key' => '_gallery_order_' . $post->ID,
2287 'posts_per_page' => -1,
2288 )
2289 );
2290
2291 if ( count( $posts ) > 0 ) {
2292 $count_image_block = 0;
2293
2294 if ( 1 === absint( $gllr_options['border_images'] ) ) {
2295 $border_images_width = $gllr_options['border_images_width'];
2296 $border = 'border-width: ' . $border_images_width . 'px; border-color: ' . $gllr_options['border_images_color'] . ';border: ' . $border_images_width . 'px solid ' . $gllr_options['border_images_color'];
2297 $border_images = $border_images_width * 2;
2298 } else {
2299 $border_images_width = 0;
2300 $border = '';
2301 $border_images = 0;
2302 }
2303
2304 $custom_content .= "
2305 <style type='text/css'>
2306 .gllr_table,
2307 .gllr_table td {
2308 border: none;
2309 vertical-align: top;
2310 }
2311 .gllr_table {
2312 table-layout: fixed;
2313 margin: 0 auto;
2314 }
2315 .gllr_table td img {
2316 width: {$width}px;
2317 height: {$height}px;
2318 }
2319 </style>\n";
2320
2321 if ( 1 === absint( $gllr_options['border_images'] ) ) {
2322 $image_style = "border: {$gllr_options['border_images_width']}px solid {$gllr_options['border_images_color']};";
2323 } else {
2324 $image_style = 'border: none;';
2325 }
2326 $image_style .= 'margin: 0;';
2327
2328 $custom_content .= '<table class="gallery gllr_table" data-gllr-columns="' . $gllr_options['custom_image_row_count'] . '" data-gllr-border-width="' . $border_images_width . '"' . ( ( 1 === absint( $gllr_options['image_text'] ) ) ? 'data-image-text-position="' . $gllr_options['image_text_position'] . '"' : '' ) . '>';
2329
2330 foreach ( $posts as $attachment ) {
2331 $image_attributes = wp_get_attachment_image_src( $attachment->ID, $gllr_options['image_size_photo'] );
2332 $title = get_post_meta( $attachment->ID, 'gllr_image_text', true );
2333 if ( 0 === $count_image_block % $gllr_options['custom_image_row_count'] ) {
2334 $custom_content .= '<tr>';
2335 }
2336 $custom_content .= '<td class="gllr_image_block">';
2337 $custom_content .= '<div>';
2338 $custom_content .= '<img src="' . $image_attributes[0] . '" style="' . $image_style . '" />';
2339 $custom_content .= '</div>';
2340 if ( 1 === absint( $gllr_options['image_text'] ) && '' !== $title ) {
2341 $custom_content .= '<div style="width:' . ( $width + $border_images ) . 'px;" class="gllr_single_image_text gllr_single_image_text_under">' . $title . '</div>';
2342 }
2343 $custom_content .= '</td>';
2344 if ( $count_image_block % $gllr_options['custom_image_row_count'] === $gllr_options['custom_image_row_count'] - 1 ) {
2345 $custom_content .= '</tr>';
2346 }
2347 $count_image_block++;
2348 }
2349 if ( $count_image_block > 0 && 0 !== $count_image_block % $gllr_options['custom_image_row_count'] ) {
2350 $custom_content .= '</tr>';
2351 }
2352 $custom_content .= '</table>';
2353 }
2354 }
2355 }
2356 $custom_content .= '</div><!-- .gallery_box_single -->';
2357 $custom_content .= '<div class="gllr_clear"></div>';
2358 }
2359 }
2360
2361 wp_reset_postdata();
2362 $wp_query = $old_wp_query;
2363 }
2364
2365 return $content . $custom_content;
2366 }
2367 }
2368
2369 if ( ! function_exists( 'gllr_change_columns' ) ) {
2370 /**
2371 * Change the columns for the edit CPT screen
2372 *
2373 * @param array $cols Columns.
2374 * @return array $cols
2375 */
2376 function gllr_change_columns( $cols ) {
2377 $cols = array(
2378 'cb' => '<input type="checkbox" />',
2379 'featured-image' => __( 'Featured Image', 'gallery-plugin' ),
2380 'title' => __( 'Title', 'gallery-plugin' ),
2381 'images' => __( 'Images', 'gallery-plugin' ),
2382 'shortcode' => __( 'Shortcode', 'gallery-plugin' ),
2383 'gallery_categories' => __( 'Gallery Categories', 'gallery-plugin' ),
2384 'author' => __( 'Author', 'gallery-plugin' ),
2385 'date' => __( 'Date', 'gallery-plugin' ),
2386 );
2387 return $cols;
2388 }
2389 }
2390
2391 if ( ! function_exists( 'gllr_custom_columns' ) ) {
2392 /**
2393 * Add custom columns
2394 *
2395 * @param string $column Column name.
2396 * @param number $post_id Posy id.
2397 */
2398 function gllr_custom_columns( $column, $post_id ) {
2399 global $wpdb, $gllr_options;
2400 $post = get_post( $post_id );
2401 switch ( $column ) {
2402 case 'shortcode':
2403 bws_shortcode_output( '[print_gllr id=' . $post->ID . ']' );
2404 echo '<br/>';
2405 bws_shortcode_output( '[print_gllr id=' . $post->ID . ' display=short]' );
2406 break;
2407 case 'featured-image':
2408 echo get_the_post_thumbnail( $post->ID, array( 65, 65 ) );
2409 break;
2410 case 'images':
2411 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
2412 if ( empty( $images_id ) ) {
2413 echo 0;
2414 } else {
2415 echo absint( $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->posts . ' WHERE ID IN( ' . $images_id . ' )' ) );
2416 }
2417 break;
2418 case 'gallery_categories':
2419 $terms = get_the_terms( $post->ID, 'gallery_categories' );
2420 $out = '';
2421 if ( $terms ) {
2422 foreach ( $terms as $term ) {
2423 $out .= '<a href="edit.php?post_type=' . $gllr_options['post_type_name'] . '&amp;gallery_categories=' . $term->slug . '">' . $term->name . '</a><br />';
2424 }
2425 echo wp_kses_post( trim( $out ) );
2426 }
2427 break;
2428 }
2429 }
2430 }
2431
2432 if ( ! function_exists( 'gllr_manage_pre_get_posts' ) ) {
2433 /**
2434 * Change order by and order for gallery post type
2435 *
2436 * @param object $query WPDB query object.
2437 */
2438 function gllr_manage_pre_get_posts( $query ) {
2439 global $gllr_options;
2440
2441 if ( is_admin() && $query->is_main_query() && $query->get( 'post_type' ) === $gllr_options['post_type_name'] && ! isset( $_GET['order'] ) ) {
2442 $query->set( 'orderby', $gllr_options['album_order_by'] );
2443 $query->set( 'order', $gllr_options['album_order'] );
2444 }
2445 }
2446 }
2447
2448 if ( ! function_exists( 'gllr_the_excerpt_max_charlength' ) ) {
2449 /**
2450 * Change excerpt length for gallery post type
2451 *
2452 * @param number $charlength Excerpt length.
2453 */
2454 function gllr_the_excerpt_max_charlength( $charlength ) {
2455 $excerpt = wp_strip_all_tags( get_the_content() );
2456 $charlength ++;
2457 if ( strlen( $excerpt ) > $charlength ) {
2458 $subex = substr( $excerpt, 0, $charlength - 5 );
2459 $exwords = explode( ' ', $subex );
2460 $excut = - ( strlen( $exwords[ count( $exwords ) - 1 ] ) );
2461 if ( $excut < 0 ) {
2462 echo esc_html( substr( $subex, 0, $excut ) );
2463 } else {
2464 echo esc_html( $subex );
2465 }
2466 echo '...';
2467 } else {
2468 echo esc_html( $excerpt );
2469 }
2470 }
2471 }
2472
2473 if ( ! function_exists( 'gllr_settings_page' ) ) {
2474 /**
2475 * Add Settings page for gallery post type
2476 */
2477 function gllr_settings_page() {
2478 if ( ! class_exists( 'Bws_Settings_Tabs' ) ) {
2479 require_once dirname( __FILE__ ) . '/bws_menu/class-bws-settings.php';
2480 }
2481 require_once dirname( __FILE__ ) . '/includes/class-gllr-settings.php';
2482 $page = new Gllr_Settings_Tabs( plugin_basename( __FILE__ ) );
2483 if ( method_exists( $page, 'add_request_feature' ) ) {
2484 $page->add_request_feature();
2485 }
2486 ?>
2487 <div class="wrap">
2488 <h1><?php printf( esc_html__( '%s Settings', 'gallery-plugin' ), 'Gallery' ); ?></h1>
2489 <?php $page->display_content(); ?>
2490 </div>
2491 <?php
2492 }
2493 }
2494
2495 if ( ! function_exists( 'gllr_content_save_pre' ) ) {
2496 /**
2497 * Remove shortcode from the content of the same gallery
2498 *
2499 * @param string $content Content for save.
2500 */
2501 function gllr_content_save_pre( $content ) {
2502 global $post, $gllr_options;
2503
2504 if ( isset( $post ) && $gllr_options['post_type_name'] === $post->post_type && ! wp_is_post_revision( $post->ID ) && ! empty( $_POST ) ) {
2505 /* remove shortcode */
2506 $content = preg_replace( '/\[print_gllr id=' . $post->ID . '( display=short){0,1}\]/', '', $content );
2507 }
2508 return $content;
2509 }
2510 }
2511
2512 if ( ! function_exists( 'gllr_register_plugin_links' ) ) {
2513 /**
2514 * Function to add links to the plugin description on the plugins page
2515 *
2516 * @param array $links All links.
2517 * @param file $file File name.
2518 * @return array
2519 */
2520 function gllr_register_plugin_links( $links, $file ) {
2521 global $gllr_options;
2522 $base = plugin_basename( __FILE__ );
2523 if ( $file === $base ) {
2524 if ( ! is_network_admin() && ! is_plugin_active( 'gallery-plugin-pro/gallery-plugin-pro.php' ) ) {
2525 $links[] = '<a href="edit.php?post_type=' . $gllr_options['post_type_name'] . '&page=gallery-plugin.php">' . __( 'Settings', 'gallery-plugin' ) . '</a>';
2526 }
2527 $links[] = '<a href="https://support.bestwebsoft.com/hc/en-us/sections/200538899" target="_blank">' . __( 'FAQ', 'gallery-plugin' ) . '</a>';
2528 $links[] = '<a href="https://support.bestwebsoft.com">' . __( 'Support', 'gallery-plugin' ) . '</a>';
2529 }
2530 return $links;
2531 }
2532 }
2533
2534 if ( ! function_exists( 'gllr_plugin_action_links' ) ) {
2535 /**
2536 * Function to add action links to the plugin menu
2537 *
2538 * @param array $links All links.
2539 * @param file $file File name.
2540 * @return array
2541 */
2542 function gllr_plugin_action_links( $links, $file ) {
2543 global $gllr_options;
2544 if ( ! is_network_admin() && ! is_plugin_active( 'gallery-plugin-pro/gallery-plugin-pro.php' ) ) {
2545 /* Static so we don't call plugin_basename on every plugin row. */
2546 static $this_plugin;
2547 if ( ! $this_plugin ) {
2548 $this_plugin = plugin_basename( __FILE__ );
2549 }
2550
2551 if ( $file === $this_plugin ) {
2552 $settings_link = '<a href="edit.php?post_type=' . $gllr_options['post_type_name'] . '&page=gallery-plugin.php">' . __( 'Settings', 'gallery-plugin' ) . '</a>';
2553 array_unshift( $links, $settings_link );
2554 }
2555 }
2556 return $links;
2557 }
2558 }
2559
2560 if ( ! function_exists( 'gllr_admin_head' ) ) {
2561 /**
2562 * Enqueue script and styles
2563 */
2564 function gllr_admin_head() {
2565 global $pagenow, $gllr_options, $post, $gllr_plugin_info;
2566 if ( empty( $gllr_plugin_inf ) ) {
2567 if ( ! function_exists( 'get_plugin_data' ) ) {
2568 require_once ABSPATH . 'wp-admin/includes/plugin.php';
2569 }
2570 $gllr_plugin_info = get_plugin_data( __FILE__ );
2571 }
2572
2573 wp_enqueue_style( 'gllr_stylesheet', plugins_url( 'css/style.css', __FILE__ ), array(), $gllr_plugin_info['Version'] );
2574 wp_enqueue_script( 'jquery' );
2575
2576 if ( isset( $_GET['page'] ) && 'gallery-plugin.php' === $_GET['page'] ) {
2577 wp_enqueue_style( 'wp-color-picker' );
2578 bws_enqueue_settings_scripts();
2579 bws_plugins_include_codemirror();
2580 wp_enqueue_script( 'gllr_script', plugins_url( 'js/script.js', __FILE__ ), array( 'wp-color-picker' ), $gllr_plugin_info['Version'], true );
2581 wp_localize_script(
2582 'gllr_script',
2583 'gllr_vars',
2584 array(
2585 'gllr_nonce' => wp_create_nonce( plugin_basename( __FILE__ ), 'gllr_ajax_nonce_field' ),
2586 'update_img_message' => __( 'Updating images...', 'gallery-plugin' ) . '<img class="gllr_loader" src="' . plugins_url( 'images/ajax-loader.gif', __FILE__ ) . '" alt="" />',
2587 'not_found_img_info' => __( 'No images found.', 'gallery-plugin' ),
2588 'img_success' => __( 'All images were updated.', 'gallery-plugin' ),
2589 'img_error' => __( 'Error.', 'gallery-plugin' ),
2590 )
2591 );
2592 } elseif (
2593 ( 'post.php' === $pagenow && isset( $_GET['action'] ) && 'edit' === $_GET['action'] && get_post_type( get_the_ID() ) === $gllr_options['post_type_name'] ) ||
2594 ( 'post-new.php' === $pagenow && isset( $_GET['post_type'] ) && $_GET['post_type'] === $gllr_options['post_type_name'] ) ) {
2595 wp_enqueue_script( 'jquery-ui-sortable' );
2596 bws_enqueue_settings_scripts();
2597 wp_enqueue_script( 'gllr_script', plugins_url( 'js/script.js', __FILE__ ), array(), $gllr_plugin_info['Version'], true );
2598 wp_localize_script(
2599 'gllr_script',
2600 'gllr_vars',
2601 array(
2602 'gllr_nonce' => wp_create_nonce( plugin_basename( __FILE__ ), 'gllr_ajax_nonce_field' ),
2603 'gllr_add_nonce' => wp_create_nonce( plugin_basename( __FILE__ ), 'gllr_ajax_add_nonce' ),
2604 'warnBulkDelete' => __( "You are about to remove these items from this gallery.\n 'Cancel' to stop, 'OK' to delete.", 'gallery-plugin' ),
2605 'warnSingleDelete' => __( "You are about to remove this image from the gallery.\n 'Cancel' to stop, 'OK' to delete.", 'gallery-plugin' ),
2606 'confirm_update_gallery' => __( 'Switching to another mode, all unsaved data will be lost. Save data before switching?', 'gallery-plugin' ),
2607 'wp_media_title' => __( 'Insert Media', 'gallery-plugin' ),
2608 'wp_media_button' => __( 'Insert', 'gallery-plugin' ),
2609 'export_message' => sprintf( '%s <a href="admin.php?page=slider.php">%s</a>', __( 'A new slider is added.', 'gallery-plugin' ), __( 'Edit slider', 'gallery-plugin' ) ),
2610 'post' => $post->ID,
2611 'title' => $post->post_title,
2612 )
2613 );
2614 }
2615 }
2616 }
2617
2618
2619 if ( ! function_exists( 'gllr_enqueue_scripts' ) ) {
2620 /**
2621 * Enqueue script and styles
2622 */
2623 function gllr_enqueue_scripts() {
2624 global $gllr_options, $post, $wp_scripts;
2625
2626 $post_type = get_post_type();
2627 $is_gallery_on_page = ( ( is_single() && $gllr_options['post_type_name'] === $post_type ) || ( isset( $post ) && has_shortcode( $post->post_content, 'print_gllr' ) ) );
2628
2629 /* disable 3rd-party fancybox */
2630 if ( $gllr_options['disable_foreing_fancybox'] && $is_gallery_on_page ) {
2631 foreach ( $wp_scripts->queue as $script ) {
2632 if ( preg_match( '/\.*fancybox\.*/', $script ) ) {
2633 wp_dequeue_script( $script );
2634 wp_deregister_script( $script );
2635 }
2636 }
2637 }
2638
2639 }
2640 }
2641
2642 if ( ! function_exists( 'gllr_wp_head' ) ) {
2643 /**
2644 * Enqueue script and styles
2645 */
2646 function gllr_wp_head() {
2647 global $gllr_options, $gllr_plugin_info;
2648 if ( empty( $gllr_plugin_inf ) ) {
2649 if ( ! function_exists( 'get_plugin_data' ) ) {
2650 require_once ABSPATH . 'wp-admin/includes/plugin.php';
2651 }
2652 $gllr_plugin_info = get_plugin_data( __FILE__ );
2653 }
2654
2655 wp_enqueue_style( 'gllr_stylesheet', plugins_url( 'css/frontend_style.css', __FILE__ ), array( 'dashicons' ), $gllr_plugin_info['Version'] );
2656 do_action( 'gllr_include_plus_style' );
2657
2658 if ( $gllr_options['enable_lightbox'] ) {
2659 wp_enqueue_style( 'gllr_fancybox_stylesheet', plugins_url( 'fancybox/jquery.fancybox.min.css', __FILE__ ), array(), $gllr_plugin_info['Version'] );
2660 /* Start ios */
2661 $script = '
2662 ( function( $ ){
2663 $( document ).ready( function() {
2664 $( \'#fancybox-overlay\' ).css( {
2665 \'width\' : $( document ).width()
2666 } );
2667 } );
2668 } )( jQuery );
2669 ';
2670 /* End ios */
2671 wp_register_script( 'gllr_enable_lightbox_ios', '', array(), $gllr_plugin_info['Version'], true );
2672 wp_enqueue_script( 'gllr_enable_lightbox_ios' );
2673 wp_add_inline_script( 'gllr_enable_lightbox_ios', sprintf( $script ) );
2674 }
2675 if ( 1 === absint( $gllr_options['image_text'] ) ) {
2676 ?>
2677 <style type="text/css">
2678 .gllr_image_row {
2679 clear: both;
2680 }
2681 </style>
2682 <?php
2683 }
2684 }
2685 }
2686
2687 if ( ! function_exists( 'gllr_wp_footer' ) ) {
2688 /**
2689 * Function for script enqueing
2690 */
2691 function gllr_wp_footer() {
2692 global $gllr_options, $wp_scripts, $gllr_plugin_info;
2693 if ( empty( $gllr_plugin_inf ) ) {
2694 if ( ! function_exists( 'get_plugin_data' ) ) {
2695 require_once ABSPATH . 'wp-admin/includes/plugin.php';
2696 }
2697 $gllr_plugin_info = get_plugin_data( __FILE__ );
2698 }
2699
2700 if ( ! defined( 'BWS_ENQUEUE_ALL_SCRIPTS' ) && ! wp_script_is( 'gllr_js', 'registered' ) ) {
2701 return;
2702 }
2703
2704 if ( $gllr_options['disable_foreing_fancybox'] ) {
2705 foreach ( $wp_scripts->queue as $script ) {
2706 if ( preg_match( '/\.*fancybox\.*/', $script ) ) {
2707 wp_dequeue_script( $script );
2708 wp_deregister_script( $script );
2709 }
2710 }
2711 }
2712
2713 wp_enqueue_script( 'jquery' );
2714
2715 if ( ! wp_script_is( 'gllr_js', 'registered' ) ) {
2716 wp_enqueue_script( 'gllr_js', plugins_url( 'js/frontend_script.js', __FILE__ ), array(), $gllr_plugin_info['Version'], true );
2717 } else {
2718 wp_enqueue_script( 'gllr_js' );
2719 }
2720
2721 if ( $gllr_options['enable_lightbox'] ) {
2722 if ( ! wp_script_is( 'bws_fancybox' ) ) {
2723 wp_enqueue_script( 'bws_fancybox', plugins_url( 'fancybox/jquery.fancybox.min.js', __FILE__ ), array( 'jquery' ), $gllr_plugin_info['Version'], true );
2724 }
2725
2726 if ( ! defined( 'BWS_ENQUEUE_ALL_SCRIPTS' ) ) {
2727 wp_enqueue_script( 'gllr_inline_fancybox_script', gllr_echo_inline_script(), array( 'jquery', 'bws_fancybox' ), $gllr_plugin_info['Version'], true );
2728 }
2729 }
2730 }
2731 }
2732
2733 if ( ! function_exists( 'gllr_pagination_callback' ) ) {
2734 /**
2735 * Function for pagination
2736 *
2737 * @param string $content Content for pagination.
2738 */
2739 function gllr_pagination_callback( $content ) {
2740 $content .= '$( ".gllr_grid:visible" ).trigger( "resize" ); if ( typeof gllr_fancy_init === "function" ) { gllr_fancy_init(); }';
2741 return $content;
2742 }
2743 }
2744
2745 if ( ! function_exists( 'gllr_shortcode' ) ) {
2746 /**
2747 * Function for gallery shortcode
2748 *
2749 * @param atring $attr Shortcode attributes.
2750 */
2751 function gllr_shortcode( $attr ) {
2752 global $gllr_options, $gllr_vars_for_inline_script, $gllr_plugin_info;
2753 if ( empty( $gllr_plugin_inf ) ) {
2754 if ( ! function_exists( 'get_plugin_data' ) ) {
2755 require_once ABSPATH . 'wp-admin/includes/plugin.php';
2756 }
2757 $gllr_plugin_info = get_plugin_data( __FILE__ );
2758 }
2759 wp_register_script( 'gllr_js', plugins_url( 'js/frontend_script.js', __FILE__ ), array( 'jquery' ), $gllr_plugin_info['Version'], true );
2760
2761 extract(
2762 shortcode_atts(
2763 array(
2764 'id' => '',
2765 'display' => 'full',
2766 'cat_id' => '',
2767 'sort_by' => '',
2768 ),
2769 $attr
2770 )
2771 );
2772 ob_start();
2773 require_once ABSPATH . 'wp-admin/includes/plugin.php';
2774
2775 $album_order = get_term_meta( absint( $cat_id ), 'gllr_album_order', true );
2776 if ( empty( $album_order ) ) {
2777 $album_order = isset( $gllr_options['album_order_by_category_option'] ) ? $gllr_options['album_order_by_category_option'] : 'default';
2778 }
2779
2780 $galleries_order =
2781 ( ! empty( $sort_by ) && 'default' !== $sort_by )
2782 ?
2783 $sort_by
2784 : (
2785 ( ! empty( $album_order ) && 'default' !== $album_order )
2786 ?
2787 $album_order
2788 :
2789 $gllr_options['album_order_by']
2790 );
2791
2792 if ( ! empty( $cat_id ) ) {
2793 global $post, $wp_query;
2794
2795 $term = get_term( $cat_id, 'gallery_categories' );
2796 if ( ! empty( $term ) ) {
2797
2798 $old_wp_query = $wp_query;
2799
2800 $args = array(
2801 'post_type' => $gllr_options['post_type_name'],
2802 'post_status' => 'publish',
2803 'posts_per_page' => -1,
2804 'gallery_categories' => $term->slug,
2805 'orderby' => $galleries_order,
2806 'order' => $gllr_options['album_order'],
2807 );
2808 $second_query = new WP_Query( $args );
2809 ?>
2810 <div class="gallery_box">
2811 <ul>
2812 <?php
2813 if ( $second_query->have_posts() ) {
2814 if ( 1 === absint( $gllr_options['cover_border_images'] ) ) {
2815 $border = 'border-width: ' . $gllr_options['cover_border_images_width'] . 'px; border-color:' . $gllr_options['cover_border_images_color'] . ';border: ' . $gllr_options['cover_border_images_width'] . 'px solid ' . $gllr_options['cover_border_images_color'];
2816 } else {
2817 $border = '';
2818 }
2819 if ( 'album-thumb' !== $gllr_options['image_size_album'] ) {
2820 $width = absint( get_option( $gllr_options['image_size_album'] . '_size_w' ) );
2821 $height = absint( get_option( $gllr_options['image_size_album'] . '_size_h' ) );
2822 } else {
2823 $width = $gllr_options['custom_size_px']['album-thumb'][0];
2824 $height = $gllr_options['custom_size_px']['album-thumb'][1];
2825 }
2826
2827 while ( $second_query->have_posts() ) {
2828 $second_query->the_post();
2829 $attachments = get_post_thumbnail_id( $post->ID );
2830 if ( empty( $attachments ) ) {
2831 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
2832 $attachments = get_posts(
2833 array(
2834 'showposts' => 1,
2835 'what_to_show' => 'posts',
2836 'post_status' => 'inherit',
2837 'post_type' => 'attachment',
2838 'orderby' => $gllr_options['order_by'],
2839 'order' => $gllr_options['order'],
2840 'post__in' => explode( ',', $images_id ),
2841 'meta_key' => '_gallery_order_' . $post->ID,
2842 )
2843 );
2844 if ( ! empty( $attachments[0] ) ) {
2845 $first_attachment = $attachments[0];
2846 $image_attributes = wp_get_attachment_image_src( $first_attachment->ID, $gllr_options['image_size_album'] );
2847 } else {
2848 $image_attributes = array( '' );
2849 }
2850 } else {
2851 $image_attributes = wp_get_attachment_image_src( $attachments, $gllr_options['image_size_album'] );
2852 }
2853 ?>
2854 <li>
2855 <a rel="bookmark" href="<?php echo esc_url( get_permalink() ); ?>" title="<?php the_title(); ?>">
2856 <?php
2857 $width_html = ! empty( $width ) ? 'width="' . $width . '"' : '';
2858 $height_html = ! empty( $height ) ? 'height="' . $height . '"' : '';
2859 $width_style = ! empty( $width ) ? 'width:' . $width . 'px;' : '';
2860 $height_style = ! empty( $height ) ? 'height:' . $height . 'px;' : '';
2861 printf(
2862 '<img %1$s %2$s style="%3$s %4$s %5$s" alt="%6$s" title="%6$s" src="%7$s" />',
2863 esc_html( $width_html ),
2864 esc_html( $height_html ),
2865 esc_html( $width_style ),
2866 esc_html( $height_style ),
2867 esc_html( $border ),
2868 esc_html( get_the_title() ),
2869 esc_url( $image_attributes[0] )
2870 );
2871 ?>
2872 </a>
2873 <div class="gallery_detail_box">
2874 <div class="gllr_detail_title"><?php the_title(); ?></div>
2875 <div class="gllr_detail_excerpt"><?php gllr_the_excerpt_max_charlength( 100 ); ?></div>
2876 <a href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>"><?php echo esc_html( $gllr_options['read_more_link_text'] ); ?></a>
2877 </div><!-- .gallery_detail_box -->
2878 <div class="gllr_clear"></div>
2879 </li>
2880 <?php
2881 }
2882 }
2883 ?>
2884 </ul>
2885 </div><!-- .gallery_box -->
2886 <?php
2887 wp_reset_postdata();
2888 $wp_query = $old_wp_query;
2889 }
2890 } else {
2891 global $post, $wp_query;
2892 $old_wp_query = $wp_query;
2893
2894 $args = array(
2895 'post_type' => $gllr_options['post_type_name'],
2896 'post_status' => 'publish',
2897 'p' => $id,
2898 'posts_per_page' => 1,
2899 );
2900 $second_query = new WP_Query( $args );
2901 if ( 'short' === $display ) {
2902 ?>
2903 <div class="gallery_box">
2904 <ul>
2905 <?php
2906 if ( $second_query->have_posts() ) {
2907 $second_query->the_post();
2908 $attachments = get_post_thumbnail_id( $post->ID );
2909
2910 if ( 'album-thumb' !== $gllr_options['image_size_album'] ) {
2911 $width = absint( get_option( $gllr_options['image_size_album'] . '_size_w' ) );
2912 $height = absint( get_option( $gllr_options['image_size_album'] . '_size_h' ) );
2913 } else {
2914 $width = $gllr_options['custom_size_px']['album-thumb'][0];
2915 $height = $gllr_options['custom_size_px']['album-thumb'][1];
2916 }
2917
2918 if ( empty( $attachments ) ) {
2919 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
2920 $attachments = get_posts(
2921 array(
2922 'showposts' => 1,
2923 'what_to_show' => 'posts',
2924 'post_status' => 'inherit',
2925 'post_type' => 'attachment',
2926 'orderby' => $gllr_options['order_by'],
2927 'order' => $gllr_options['order'],
2928 'post__in' => explode( ',', $images_id ),
2929 'meta_key' => '_gallery_order_' . $post->ID,
2930 )
2931 );
2932 if ( ! empty( $attachments[0] ) ) {
2933 $first_attachment = $attachments[0];
2934 $image_attributes = wp_get_attachment_image_src( $first_attachment->ID, $gllr_options['image_size_album'] );
2935 } else {
2936 $image_attributes = array( '' );
2937 }
2938 } else {
2939 $image_attributes = wp_get_attachment_image_src( $attachments, $gllr_options['image_size_album'] );
2940 }
2941
2942 if ( 1 === absint( $gllr_options['cover_border_images'] ) ) {
2943 $border = 'border-width: ' . $gllr_options['cover_border_images_width'] . 'px; border-color:' . $gllr_options['cover_border_images_color'] . ';border: ' . $gllr_options['cover_border_images_width'] . 'px solid ' . $gllr_options['cover_border_images_color'];
2944 } else {
2945 $border = '';
2946 }
2947 ?>
2948 <li>
2949 <a rel="bookmark" href="<?php echo esc_html( get_permalink() ); ?>" title="<?php the_title(); ?>">
2950 <?php
2951 $width_html = ! empty( $width ) ? 'width="' . $width . '"' : '';
2952 $height_html = ! empty( $height ) ? 'height="' . $height . '"' : '';
2953 $width_style = ! empty( $width ) ? 'width:' . $width . 'px;' : '';
2954 $height_style = ! empty( $height ) ? 'height:' . $height . 'px;' : '';
2955 printf(
2956 '<img %1$s %2$s style="%3$s %4$s %5$s" alt="%6$s" title="%6$s" src="%7$s" />',
2957 esc_html( $width_html ),
2958 esc_html( $height_html ),
2959 esc_html( $width_style ),
2960 esc_html( $height_style ),
2961 esc_html( $border ),
2962 esc_html( get_the_title() ),
2963 esc_url( $image_attributes[0] )
2964 );
2965 ?>
2966 </a>
2967 <div class="gallery_detail_box">
2968 <div class="gllr_detail_title"><?php the_title(); ?></div>
2969 <div class="gllr_detail_excerpt"><?php gllr_the_excerpt_max_charlength( 100 ); ?></div>
2970 <a href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>"><?php echo esc_html( $gllr_options['read_more_link_text'] ); ?></a>
2971 </div><!-- .gallery_detail_box -->
2972 <div class="gllr_clear"></div>
2973 </li>
2974 <?php } ?>
2975 </ul>
2976 </div><!-- .gallery_box -->
2977 <?php
2978 } else {
2979 if ( $second_query->have_posts() ) {
2980 if ( 1 === absint( $gllr_options['border_images'] ) ) {
2981 $border = 'border-width: ' . $gllr_options['border_images_width'] . 'px; border-color:' . $gllr_options['border_images_color'] . ';border: ' . $gllr_options['border_images_width'] . 'px solid ' . $gllr_options['border_images_color'];
2982 $border_images = $gllr_options['border_images_width'] * 2;
2983 } else {
2984 $border = '';
2985 $border_images = 0;
2986 }
2987 if ( 'photo-thumb' !== $gllr_options['image_size_photo'] ) {
2988 $width = absint( get_option( $gllr_options['image_size_photo'] . '_size_w' ) );
2989 $height = absint( get_option( $gllr_options['image_size_photo'] . '_size_h' ) );
2990 } else {
2991 $width = $gllr_options['custom_size_px']['photo-thumb'][0];
2992 $height = $gllr_options['custom_size_px']['photo-thumb'][1];
2993 }
2994
2995 while ( $second_query->have_posts() ) {
2996 $second_query->the_post();
2997 ?>
2998 <div class="gallery_box_single">
2999 <?php
3000 echo do_shortcode( get_the_content() );
3001
3002 $images_id = get_post_meta( $post->ID, '_gallery_images', true );
3003
3004 $posts = get_posts(
3005 array(
3006 'showposts' => -1,
3007 'what_to_show' => 'posts',
3008 'post_status' => 'inherit',
3009 'post_type' => 'attachment',
3010 'orderby' => $gllr_options['order_by'],
3011 'order' => $gllr_options['order'],
3012 'post__in' => explode( ',', $images_id ),
3013 'meta_key' => '_gallery_order_' . $post->ID,
3014 )
3015 );
3016
3017 if ( 0 < count( $posts ) ) {
3018 $count_image_block = 0;
3019 ?>
3020 <div class="gallery gllr_grid" data-gllr-columns="<?php echo esc_attr( $gllr_options['custom_image_row_count'] ); ?>" data-gllr-border-width="<?php echo esc_attr( $gllr_options['border_images_width'] ); ?>">
3021 <?php
3022 foreach ( $posts as $attachment ) {
3023 $image_attributes = wp_get_attachment_image_src( $attachment->ID, $gllr_options['image_size_photo'] );
3024 $image_attributes_large = wp_get_attachment_image_src( $attachment->ID, 'large' );
3025 $image_attributes_full = wp_get_attachment_image_src( $attachment->ID, 'full' );
3026 $url_for_link = get_post_meta( $attachment->ID, 'gllr_link_url', true );
3027 $image_text = get_post_meta( $attachment->ID, 'gllr_image_text', true );
3028 $image_alt_tag = get_post_meta( $attachment->ID, 'gllr_image_alt_tag', true );
3029
3030 if ( 0 === $count_image_block % $gllr_options['custom_image_row_count'] ) {
3031 ?>
3032 <div class="gllr_image_row">
3033 <?php } ?>
3034 <div class="gllr_image_block">
3035 <p style="
3036 <?php
3037 if ( $width ) {
3038 echo 'width:' . ( esc_attr( $width + $border_images ) ) . 'px;';
3039 } if ( $height ) {
3040 echo 'height:' . ( esc_attr( $height + $border_images ) ) . 'px;';
3041 }
3042 ?>
3043 ">
3044 <?php
3045 $width_html = ! empty( $width ) ? 'width="' . $width . '"' : '';
3046 $height_html = ! empty( $height ) ? 'height="' . $height . '"' : '';
3047 $width_style = ! empty( $width ) ? 'width:' . $width . 'px;' : '';
3048 $height_style = ! empty( $height ) ? 'height:' . $height . 'px;' : '';
3049 if ( ! empty( $url_for_link ) ) {
3050 ?>
3051 <a href="<?php echo esc_url( $url_for_link ); ?>" title="<?php echo esc_html( $image_text ); ?>" target="_blank">
3052 <?php
3053 printf(
3054 '<img %1$s %2$s style="%3$s %4$s %5$s" alt="%6$s" title="%7$s" src="%8$s" />',
3055 esc_html( $width_html ),
3056 esc_html( $height_html ),
3057 esc_html( $width_style ),
3058 esc_html( $height_style ),
3059 esc_html( $border ),
3060 esc_html( $image_alt_tag ),
3061 esc_html( $image_text ),
3062 esc_url( $image_attributes[0] )
3063 );
3064 ?>
3065 </a>
3066 <?php
3067 } else {
3068 if ( 1 !== absint( $gllr_options['enable_image_opening'] ) ) {
3069 ?>
3070 <a data-fancybox="gallery_fancybox<?php echo 0 === absint( $gllr_options['single_lightbox_for_multiple_galleries'] ) ? '_' . esc_attr( $post->ID ) : ''; ?>" href="<?php echo esc_url( $image_attributes_large[0] ); ?>" title="<?php echo esc_html( $image_text ); ?>" >
3071 <?php
3072 printf(
3073 '<img %1$s %2$s style="%3$s %4$s %5$s" alt="%6$s" title="%7$s" src="%8$s" rel="%9$s" />',
3074 esc_html( $width_html ),
3075 esc_html( $height_html ),
3076 esc_html( $width_style ),
3077 esc_html( $height_style ),
3078 esc_html( $border ),
3079 esc_html( $image_alt_tag ),
3080 esc_html( $image_text ),
3081 esc_url( $image_attributes[0] ),
3082 esc_url( $image_attributes_full[0] )
3083 );
3084 ?>
3085 </a>
3086 <?php } else { ?>
3087 <a data-fancybox="gallery_fancybox<?php echo 0 === absint( $gllr_options['single_lightbox_for_multiple_galleries'] ) ? '_' . esc_attr( $post->ID ) : ''; ?>" href="#" style="pointer-events: none;" title="<?php echo esc_html( $image_text ); ?>" >
3088 <?php
3089 printf(
3090 '<img %1$s %2$s style="%3$s %4$s %5$s" alt="%6$s" title="%7$s" src="%8$s" rel="#" />',
3091 esc_html( $width_html ),
3092 esc_html( $height_html ),
3093 esc_html( $width_style ),
3094 esc_html( $height_style ),
3095 esc_html( $border ),
3096 esc_html( $image_alt_tag ),
3097 esc_html( $image_text ),
3098 esc_url( $image_attributes[0] )
3099 );
3100 ?>
3101 </a>
3102 <?php
3103 }
3104 }
3105 ?>
3106 </p>
3107 <?php if ( 1 === absint( $gllr_options['image_text'] ) ) { ?>
3108 <div
3109 <?php
3110 if ( $width ) {
3111 echo 'style="width:' . ( esc_attr( $width + $border_images ) ) . 'px;"';
3112 }
3113 ?>
3114 class="gllr_single_image_text gllr_single_image_text_under"><?php echo esc_html( $image_text ); ?>&nbsp;</div>
3115 <?php } ?>
3116 </div><!-- .gllr_image_block -->
3117 <?php if ( $count_image_block % $gllr_options['custom_image_row_count'] === $gllr_options['custom_image_row_count'] - 1 ) { ?>
3118 </div><!-- .gllr_image_row -->
3119 <?php
3120 }
3121 $count_image_block++;
3122 }
3123 if ( 0 < $count_image_block && 0 !== $count_image_block % $gllr_options['custom_image_row_count'] ) {
3124 ?>
3125 <div class="clear"></div>
3126 </div><!-- .gllr_image_row -->
3127 <?php } ?>
3128 </div><!-- .gallery.clearfix -->
3129 <?php
3130 }
3131 if ( 1 === absint( $gllr_options['return_link_shortcode'] ) ) {
3132 if ( empty( $gllr_options['return_link_url'] ) ) {
3133 if ( ! empty( $gllr_options['page_id_gallery_template'] ) ) {
3134 ?>
3135 <div class="gllr_clear"></div>
3136 <div class="return_link gllr_return_link"><a href="<?php echo esc_url( get_permalink( $gllr_options['page_id_gallery_template'] ) ); ?>"><?php echo esc_html( $gllr_options['return_link_text'] ); ?></a></div>
3137 <?php
3138 }
3139 } else {
3140 ?>
3141 <div class="gllr_clear"></div>
3142 <div class="return_link gllr_return_link"><a href="<?php echo esc_url( $gllr_options['return_link_url'] ); ?>"><?php echo esc_html( $gllr_options['return_link_text'] ); ?></a></div>
3143 <?php
3144 }
3145 }
3146 ?>
3147 </div><!-- .gallery_box_single -->
3148 <div class="gllr_clear"></div>
3149 <?php
3150 }
3151 if ( $gllr_options['enable_lightbox'] ) {
3152
3153 $gllr_vars_for_inline_script['single_script'][] = apply_filters( 'gllr_options_for_inline_script', array( 'post_id' => $post->ID ) );
3154
3155 if ( defined( 'BWS_ENQUEUE_ALL_SCRIPTS' ) ) {
3156 gllr_echo_inline_script();
3157 }
3158 }
3159 } else {
3160 ?>
3161 <div class="gallery_box_single">
3162 <p class="not_found"><?php esc_html_e( 'Sorry, nothing found.', 'gallery-plugin' ); ?></p>
3163 </div><!-- .gallery_box_single -->
3164 <?php
3165 }
3166 }
3167 wp_reset_postdata();
3168 $wp_query = $old_wp_query;
3169 }
3170 $gllr_output = ob_get_clean();
3171 return $gllr_output;
3172 }
3173 }
3174
3175 if ( ! function_exists( 'gllr_echo_inline_script' ) ) {
3176 /**
3177 * Function for inline scripts
3178 */
3179 function gllr_echo_inline_script() {
3180 global $gllr_vars_for_inline_script, $gllr_options;
3181
3182 if ( isset( $gllr_vars_for_inline_script['single_script'] ) ) {
3183 $script = '
3184 var gllr_onload = window.onload;
3185 function gllr_fancy_init() {
3186 var options = {
3187 loop : true,
3188 arrows : ' . ( 1 === absint( $gllr_options['lightbox_arrows'] ) ? 'true' : 'false' ) . ',
3189 infobar : true,
3190 caption : function( instance, current ) {
3191 current.full_src = jQuery( this ).find( \'img\' ).attr( \'rel\' );
3192 var title = jQuery( this ).attr( \'title\' ).replace(/</g, "&lt;");
3193 return title ? \'<div>\' + title + \'</div>\' : \'\';
3194 },
3195 buttons : [\'close\', ]
3196 };
3197 ';
3198
3199 if ( $gllr_options['lightbox_download_link'] ) {
3200 $script .= '
3201 if ( ! jQuery.fancybox.defaults.btnTpl.download ) {
3202 jQuery.fancybox.defaults.btnTpl.download = \'<a class="fancybox-button bws_gallery_download_link dashicons dashicons-download"></a>\';
3203 }
3204
3205 options.buttons.unshift( \'download\' );
3206 options.beforeShow = function( instance, current ) {
3207 jQuery( \'.bws_gallery_download_link\' ).attr( \'href\', current.full_src ).attr( \'download\', current.full_src.substring( current.full_src.lastIndexOf(\'/\') + 1 ) );
3208 }
3209 ';
3210 }
3211
3212 if ( $gllr_options['start_slideshow'] ) {
3213 $script .= '
3214 options.buttons.unshift( \'slideShow\' );
3215 options.slideShow = { autoStart : true, speed : ' . $gllr_options['slideshow_interval'] . ' };
3216 ';
3217 }
3218
3219 /* prevent several fancybox initialization */
3220 if ( $gllr_options['single_lightbox_for_multiple_galleries'] ) {
3221 $script .= '
3222 jQuery( "a[data-fancybox=gallery_fancybox]" ).fancybox( options );
3223 ';
3224 } else {
3225 foreach ( $gllr_vars_for_inline_script['single_script'] as $vars ) {
3226 $script .= '
3227 jQuery( "a[data-fancybox=gallery_fancybox_' . $vars['post_id'] . ']" ).fancybox( options );
3228 ';
3229 }
3230 }
3231
3232 $script .= '
3233 }
3234 if ( typeof gllr_onload === \'function\' ) {
3235 window.onload = function() {
3236 gllr_onload();
3237 gllr_fancy_init();
3238 }
3239 } else {
3240 window.onload = gllr_fancy_init;
3241 }
3242 ';
3243
3244 wp_register_script( 'gllr_fancy_init', '', array(), false, true );
3245 wp_enqueue_script( 'gllr_fancy_init' );
3246 wp_add_inline_script( 'gllr_fancy_init', sprintf( $script ) );
3247
3248 unset( $gllr_vars_for_inline_script );
3249 }
3250
3251 $additional_options = do_action( 'gllr_echo_additional_inline_script', array() );
3252 }
3253 }
3254
3255 if ( ! function_exists( 'gllr_update_image' ) ) {
3256 /**
3257 * Function for gallery ajax
3258 */
3259 function gllr_update_image() {
3260 global $wpdb, $gllr_options;
3261 check_ajax_referer( plugin_basename( __FILE__ ), 'gllr_ajax_nonce_field' );
3262
3263 $action = isset( $_REQUEST['action1'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action1'] ) ) : '';
3264 $id = isset( $_REQUEST['id'] ) ? absint( $_REQUEST['id'] ) : '';
3265 switch ( $action ) {
3266 case 'get_all_attachment':
3267 $array_parent_id = $wpdb->get_col( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_type` = %s", $gllr_options['post_type_name'] ) );
3268
3269 if ( ! empty( $array_parent_id ) ) {
3270
3271 $string_parent_id = implode( ',', $array_parent_id );
3272
3273 $metas = $wpdb->get_results( "SELECT `meta_value` FROM $wpdb->postmeta WHERE `meta_key` = '_gallery_images' AND `post_id` IN ( " . $string_parent_id . ' )', ARRAY_A );
3274
3275 $result_attachment_id = '';
3276 foreach ( $metas as $value ) {
3277 if ( ! empty( $value['meta_value'] ) ) {
3278 $result_attachment_id .= $value['meta_value'] . ',';
3279 }
3280 }
3281 $result_attachment_id_array = explode( ',', rtrim( $result_attachment_id, ',' ) );
3282 echo wp_json_encode( array_unique( $result_attachment_id_array ) );
3283 }
3284 break;
3285 case 'update_image':
3286 $metadata = wp_get_attachment_metadata( $id );
3287 $uploads = wp_upload_dir();
3288 $path = $uploads['basedir'] . '/' . $metadata['file'];
3289 require_once ABSPATH . 'wp-admin/includes/image.php';
3290 $metadata_new = gllr_wp_generate_attachment_metadata( $id, $path, $metadata );
3291 wp_update_attachment_metadata( $id, array_merge( $metadata, $metadata_new ) );
3292 break;
3293 case 'update_options':
3294 unset( $gllr_options['need_image_update'] );
3295 update_option( 'gllr_options', $gllr_options );
3296 break;
3297 }
3298 die();
3299 }
3300 }
3301
3302 if ( ! function_exists( 'gllr_wp_generate_attachment_metadata' ) ) {
3303 /**
3304 * Filter for generate attachment metadata for gallery image
3305 *
3306 * @param number $attachment_id Attachment ID.
3307 * @param string $file File path.
3308 * @param array $metadata Metadata array.
3309 */
3310 function gllr_wp_generate_attachment_metadata( $attachment_id, $file, $metadata ) {
3311 $attachment = get_post( $attachment_id );
3312 $gllr_options = get_option( 'gllr_options' );
3313 $image_size = array( 'thumbnail' );
3314
3315 if ( 'album-thumb' === $gllr_options['image_size_album'] ) {
3316 add_image_size( 'album-thumb', $gllr_options['custom_size_px']['album-thumb'][0], $gllr_options['custom_size_px']['album-thumb'][1], true );
3317 $image_size[] = 'album-thumb';
3318 }
3319 if ( 'photo-thumb' === $gllr_options['image_size_photo'] ) {
3320 add_image_size( 'photo-thumb', $gllr_options['custom_size_px']['photo-thumb'][0], $gllr_options['custom_size_px']['photo-thumb'][1], true );
3321 $image_size[] = 'photo-thumb';
3322 }
3323
3324 $metadata = array();
3325 if ( preg_match( '!^image/!', get_post_mime_type( $attachment ) ) && file_is_displayable_image( $file ) ) {
3326 $imagesize = getimagesize( $file );
3327 $metadata['width'] = $imagesize[0];
3328 $metadata['height'] = $imagesize[1];
3329 list( $uwidth, $uheight ) = wp_constrain_dimensions( $metadata['width'], $metadata['height'], 128, 96 );
3330 $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
3331
3332 /* Make the file path relative to the upload dir */
3333 $metadata['file'] = _wp_relative_upload_path( $file );
3334
3335 /* Make thumbnails and other intermediate sizes */
3336 global $_wp_additional_image_sizes;
3337
3338 foreach ( $image_size as $s ) {
3339 $sizes[ $s ] = array(
3340 'width' => '',
3341 'height' => '',
3342 'crop' => false,
3343 );
3344 if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) ) {
3345 $sizes[ $s ]['width'] = absint( $_wp_additional_image_sizes[ $s ]['width'] ); /* For theme-added sizes */
3346 } else {
3347 $sizes[ $s ]['width'] = get_option( "{$s}_size_w" ); /* For default sizes set in options */
3348 } if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) {
3349 $sizes[ $s ]['height'] = absint( $_wp_additional_image_sizes[ $s ]['height'] ); /* For theme-added sizes */
3350 } else {
3351 $sizes[ $s ]['height'] = get_option( "{$s}_size_h" ); /* For default sizes set in options */
3352 } if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) {
3353 $sizes[ $s ]['crop'] = absint( $_wp_additional_image_sizes[ $s ]['crop'] ); /* For theme-added sizes */
3354 } else {
3355 $sizes[ $s ]['crop'] = get_option( "{$s}_crop" ); /* For default sizes set in options */
3356 }
3357 }
3358 $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
3359 foreach ( $sizes as $size => $size_data ) {
3360 $resized = gllr_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
3361 if ( $resized ) {
3362 $metadata['sizes'][ $size ] = $resized;
3363 }
3364 }
3365 /* Fetch additional metadata from exif/iptc */
3366 $image_meta = wp_read_image_metadata( $file );
3367 if ( $image_meta ) {
3368 $metadata['image_meta'] = $image_meta;
3369 }
3370 }
3371 return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
3372 }
3373 }
3374
3375 if ( ! function_exists( 'gllr_image_make_intermediate_size' ) ) {
3376 /**
3377 * Filter for intermediate size for gallery image
3378 *
3379 * @param string $file File name.
3380 * @param number $width Width value.
3381 * @param number $height Height value.
3382 * @param bool $crop Flag for crop.
3383 */
3384 function gllr_image_make_intermediate_size( $file, $width, $height, $crop = false ) {
3385 if ( $width || $height ) {
3386 $resized_file = gllr_image_resize( $file, $width, $height, $crop );
3387 $info = getimagesize( $resized_file );
3388 if ( ! is_wp_error( $resized_file ) && $resized_file && ! empty( $info ) ) {
3389 $resized_file = apply_filters( 'image_make_intermediate_size', $resized_file );
3390 return array(
3391 'file' => wp_basename( $resized_file ),
3392 'width' => $info[0],
3393 'height' => $info[1],
3394 );
3395 }
3396 }
3397 return false;
3398 }
3399 }
3400
3401 if ( ! function_exists( 'gllr_image_resize' ) ) {
3402 /**
3403 * Filter for gallery image resize
3404 *
3405 * @param string $file File name.
3406 * @param number $max_w Width value.
3407 * @param number $max_h Height value.
3408 * @param bool $crop Flag for crop.
3409 * @param string $suffix Suffix for file name.
3410 * @param string $dest_path Path for save file.
3411 * @param number $jpeg_quality Quality number for save file.
3412 */
3413 function gllr_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
3414 $size = @getimagesize( $file );
3415 if ( ! $size ) {
3416 return new WP_Error( 'invalid_image', __( 'Image size not defined', 'gallery-plugin' ), $file );
3417 }
3418
3419 $type = $size[2];
3420
3421 if ( 3 === $type ) {
3422 $image = imagecreatefrompng( $file );
3423 } elseif ( 2 === $type ) {
3424 $image = imagecreatefromjpeg( $file );
3425 } elseif ( 1 === $type ) {
3426 $image = imagecreatefromgif( $file );
3427 } elseif ( 15 === $type ) {
3428 $image = imagecreatefromwbmp( $file );
3429 } elseif ( 16 === $type ) {
3430 $image = imagecreatefromxbm( $file );
3431 } else {
3432 return new WP_Error( 'invalid_image', __( 'Plugin updates only PNG, JPEG, GIF, WPMP or XBM filetype. For other, please reload images manually.', 'gallery-plugin' ), $file );
3433 }
3434
3435 if ( ! is_resource( $image ) ) {
3436 return new WP_Error( 'error_loading_image', $image, $file );
3437 }
3438
3439 list( $orig_w, $orig_h, $orig_type ) = $size;
3440
3441 $dims = gllr_image_resize_dimensions( $orig_w, $orig_h, $max_w, $max_h, $crop );
3442
3443 if ( ! $dims ) {
3444 return new WP_Error( 'error_getting_dimensions', __( 'Image size not defined', 'gallery-plugin' ) );
3445 }
3446 list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
3447
3448 $newimage = wp_imagecreatetruecolor( $dst_w, $dst_h );
3449
3450 imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
3451
3452 /* Convert from full colors to index colors, like original PNG. */
3453 if ( IMAGETYPE_PNG === $orig_type && function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) ) {
3454 imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) );
3455 }
3456
3457 /* We don't need the original in memory anymore */
3458 imagedestroy( $image );
3459
3460 /* $suffix will be appended to the destination filename, just before the extension */
3461 if ( ! $suffix ) {
3462 $suffix = "{$dst_w}x{$dst_h}";
3463 }
3464
3465 $info = pathinfo( $file );
3466 $dir = $info['dirname'];
3467 $ext = $info['extension'];
3468 $name = wp_basename( $file, ".$ext" );
3469
3470 $_dest_path = realpath( $dest_path );
3471
3472 if ( ! is_null( $dest_path ) && ! empty( $_dest_path ) ) {
3473 $dir = $_dest_path;
3474 }
3475 $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
3476
3477 if ( IMAGETYPE_GIF === $orig_type ) {
3478 if ( ! imagegif( $newimage, $destfilename ) ) {
3479 return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'gallery-plugin' ) );
3480 }
3481 } elseif ( IMAGETYPE_PNG === $orig_type ) {
3482 if ( ! imagepng( $newimage, $destfilename ) ) {
3483 return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'gallery-plugin' ) );
3484 }
3485 } else {
3486 /* All other formats are converted to jpg */
3487 $destfilename = "{$dir}/{$name}-{$suffix}.jpg";
3488 if ( ! imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) ) {
3489 return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'gallery-plugin' ) );
3490 }
3491 }
3492 imagedestroy( $newimage );
3493
3494 /* Set correct file permissions */
3495 $stat = stat( dirname( $destfilename ) );
3496 $perms = $stat['mode'] & 0000666; /* Same permissions as parent folder, strip off the executable bits */
3497 @chmod( $destfilename, $perms );
3498 return $destfilename;
3499 }
3500 }
3501
3502 if ( ! function_exists( 'gllr_image_resize_dimensions' ) ) {
3503 /**
3504 * Filter for gallery image resize dimensions
3505 *
3506 * @param number $orig_w Width value.
3507 * @param number $orig_h Height value.
3508 * @param number $dest_w New width value.
3509 * @param number $dest_h New height value.
3510 * @param bool $crop Flag for crop.
3511 */
3512 function gllr_image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
3513 if ( 0 >= $orig_w || 0 >= $orig_h ) {
3514 return false;
3515 }
3516 /* At least one of dest_w or dest_h must be specific */
3517 if ( 0 >= $dest_w && 0 >= $dest_h ) {
3518 return false;
3519 }
3520
3521 if ( $crop ) {
3522 /* Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h */
3523 $aspect_ratio = $orig_w / $orig_h;
3524 $new_w = min( $dest_w, $orig_w );
3525 $new_h = min( $dest_h, $orig_h );
3526
3527 if ( ! $new_w ) {
3528 $new_w = absint( $new_h * $aspect_ratio );
3529 }
3530
3531 if ( ! $new_h ) {
3532 $new_h = absint( $new_w / $aspect_ratio );
3533 }
3534
3535 $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
3536
3537 $crop_w = round( $new_w / $size_ratio );
3538 $crop_h = round( $new_h / $size_ratio );
3539 $s_x = floor( ( $orig_w - $crop_w ) / 2 );
3540 $s_y = 0;
3541
3542 } else {
3543 /* Don't crop, just resize using $dest_w x $dest_h as a maximum bounding box */
3544 $crop_w = $orig_w;
3545 $crop_h = $orig_h;
3546 $s_x = 0;
3547 $s_y = 0;
3548
3549 list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
3550 }
3551 /* If the resulting image would be the same size or larger we don't want to resize it */
3552 if ( $new_w >= $orig_w && $new_h >= $orig_h ) {
3553 return false;
3554 }
3555 /**
3556 * The return array matches the parameters to imagecopyresampled()
3557 * Int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
3558 */
3559 return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
3560 }
3561 }
3562
3563 if ( ! function_exists( 'gllr_theme_body_classes' ) ) {
3564 /**
3565 * Add a class with theme name
3566 *
3567 * @param array $classes Classes array.
3568 */
3569 function gllr_theme_body_classes( $classes ) {
3570 if ( function_exists( 'wp_get_theme' ) ) {
3571 $current_theme = wp_get_theme();
3572 $classes[] = 'gllr_' . basename( $current_theme->get( 'ThemeURI' ) );
3573 }
3574 return $classes;
3575 }
3576 }
3577
3578 if ( ! function_exists( 'gllr_media_custom_box' ) ) {
3579 /**
3580 * Create custom meta box for gallery post type
3581 *
3582 * @param string $obj Object for shortcode.
3583 * @param string $box Box for shortcode.
3584 */
3585 function gllr_media_custom_box( $obj = '', $box = '' ) {
3586 if ( ! class_exists( 'Bws_Settings_Tabs' ) ) {
3587 require_once dirname( __FILE__ ) . '/bws_menu/class-bws-settings.php';
3588 }
3589 require_once dirname( __FILE__ ) . '/includes/class-gllr-settings.php';
3590 $page = new Gllr_Settings_Tabs( plugin_basename( __FILE__ ) );
3591 ?>
3592 <div style="padding-top:10px;">
3593 <?php $page->display_tabs(); ?>
3594 </div>
3595 <?php
3596 }
3597 }
3598
3599 if ( ! function_exists( 'gllr_delete_image' ) ) {
3600 /**
3601 * Filter for gallery delete image
3602 */
3603 function gllr_delete_image() {
3604 check_ajax_referer( plugin_basename( __FILE__ ), 'gllr_ajax_nonce_field' );
3605
3606 $action = isset( $_POST['action'] ) ? sanitize_text_field( wp_unslash( $_POST['action'] ) ) : '';
3607 $delete_id_array = isset( $_POST['delete_id_array'] ) ? sanitize_text_field( wp_unslash( $_POST['delete_id_array'] ) ) : ''; /* !!!!!!!!!!!!!!!!!!!!!!! */
3608 $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : '';
3609
3610 if ( 'gllr_delete_image' === $action && ! empty( $delete_id_array ) && ! empty( $post_id ) ) {
3611 if ( ! is_array( $delete_id_array ) ) {
3612 $delete_id = explode( ',', trim( $delete_id_array, ',' ) );
3613 } else {
3614 $delete_id[] = $delete_id_array;
3615 }
3616
3617 $gallery_images = get_post_meta( $post_id, '_gallery_images', true );
3618
3619 $gallery_images_array = explode( ',', $gallery_images );
3620 $gallery_images_array = array_flip( $gallery_images_array );
3621
3622 foreach ( $delete_id as $delete_id ) {
3623 delete_post_meta( $delete_id, '_gallery_order_' . $post_id );
3624 unset( $gallery_images_array[ $delete_id ] );
3625 }
3626
3627 $gallery_images_array = array_flip( $gallery_images_array );
3628 $gallery_images = implode( ',', $gallery_images_array );
3629 /* Custom field has a value and this custom field exists in database */
3630 update_post_meta( $post_id, '_gallery_images', $gallery_images );
3631 echo 'updated';
3632 } else {
3633 echo 'error';
3634 }
3635 die();
3636 }
3637 }
3638
3639 if ( ! function_exists( 'gllr_add_from_media' ) ) {
3640 /**
3641 * Add image for gallery from media
3642 */
3643 function gllr_add_from_media() {
3644 global $original_post, $post;
3645 check_ajax_referer( plugin_basename( __FILE__ ), 'gllr_ajax_add_nonce' );
3646
3647 $add_id = isset( $_POST['add_id'] ) ? absint( $_POST['add_id'] ) : '';
3648 $original_post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : '';
3649 $gllr_mode = isset( $_POST['mode'] ) ? sanitize_text_field( wp_unslash( $_POST['mode'] ) ) : 'grid';
3650
3651 if ( ! empty( $add_id ) && ! empty( $original_post_id ) ) {
3652 $post = get_post( $add_id );
3653 if ( ! empty( $post ) ) {
3654 if ( preg_match( '!^image/!', $post->post_mime_type ) ) {
3655 setup_postdata( $post );
3656 $original_post = get_post( $original_post_id );
3657 $GLOBALS['hook_suffix'] = 'gallery';
3658 $wp_gallery_media_table = new Gllr_Media_Table();
3659 $wp_gallery_media_table->prepare_items();
3660 $wp_gallery_media_table->single_row( $gllr_mode );
3661 }
3662 }
3663 }
3664 die();
3665 }
3666 }
3667
3668 if ( ! function_exists( 'gllr_change_view_mode' ) ) {
3669 /**
3670 * Save view mode to user option
3671 */
3672 function gllr_change_view_mode() {
3673 check_ajax_referer( plugin_basename( __FILE__ ), 'gllr_ajax_nonce_field' );
3674 if ( ! empty( $_POST['mode'] ) ) {
3675 update_user_option(
3676 get_current_user_id(),
3677 'gllr_media_library_mode',
3678 sanitize_text_field( wp_unslash( $_POST['mode'] ) )
3679 );
3680 }
3681 die();
3682 }
3683 }
3684
3685 if ( ! function_exists( 'gllr_print_media_notice' ) ) {
3686 /**
3687 * Add place for notice in media upoader for gallery
3688 *
3689 * See wp_print_media_templates() in "wp-includes/media-template.php"
3690 */
3691 function gllr_print_media_notice() {
3692 global $post, $gllr_options;
3693 if ( isset( $post ) ) {
3694 if ( $post->post_type === $gllr_options['post_type_name'] ) {
3695
3696 $script = "( function ($) {
3697 $( '#tmpl-attachment-details' ).html(
3698 $( '#tmpl-attachment-details' ).html().replace( '<div class=\"attachment-info\"', '<# gllr_notice_wiev( data.id ); #><div id=\"gllr_media_notice\" class=\"upload-errors\"></div>$&' )
3699 );
3700 } )(jQuery);";
3701 wp_register_script( 'gllr_print_media_notice', '', array(), false, true );
3702 wp_enqueue_script( 'gllr_print_media_notice' );
3703 wp_add_inline_script( 'gllr_print_media_notice', sprintf( $script ) );
3704 }
3705 }
3706 }
3707 }
3708
3709 if ( ! function_exists( 'gllr_media_check_ajax_action' ) ) {
3710 /**
3711 * Add notises in media upoader for portfolio and gallery
3712 */
3713 function gllr_media_check_ajax_action() {
3714 check_ajax_referer( plugin_basename( __FILE__ ), 'gllr_ajax_nonce_field' );
3715 if ( isset( $_POST['thumbnail_id'] ) ) {
3716 $thumbnail_id = absint( $_POST['thumbnail_id'] );
3717 /*get information about the selected item */
3718 $atachment_detail = get_post( $thumbnail_id );
3719 if ( ! empty( $atachment_detail ) ) {
3720 if ( ! preg_match( '!^image/!', $atachment_detail->post_mime_type ) ) {
3721 $notice_attach = "<div class='upload-error'><strong>" . __( 'Warning', 'gallery-plugin' ) . ': </strong>' . __( 'You can add only images to the gallery', 'gallery-plugin' ) . '</div>';
3722 wp_send_json_success( $notice_attach );
3723 }
3724 }
3725 }
3726 die();
3727 }
3728 }
3729
3730 if ( ! function_exists( 'gllr_shortcode_button_content' ) ) {
3731 /**
3732 * Add shortcode content
3733 *
3734 * @param string $content Content for shortcode.
3735 */
3736 function gllr_shortcode_button_content( $content ) {
3737 global $post, $gllr_options;
3738 ?>
3739 <div id="gllr" style="display:none;">
3740 <fieldset>
3741 <?php
3742 $old_post = $post;
3743 $query = new WP_Query( 'post_type=' . $gllr_options['post_type_name'] . '&post_status=publish&posts_per_page=-1&order=DESC&orderby=date' );
3744 if ( $query->have_posts() ) {
3745 ?>
3746 <label>
3747 <input name="gllr_shortcode_radio" class="gllr_shortcode_radio_category" type="radio"/>
3748 <span class="title"><?php esc_html_e( 'Gallery Categories', 'gallery-plugin' ); ?></span>
3749 <?php
3750 $cat_args = array(
3751 'orderby' => 'date',
3752 'order' => 'DESC',
3753 'show_count' => 1,
3754 'hierarchical' => 1,
3755 'taxonomy' => 'gallery_categories',
3756 'name' => 'gllr_gallery_categories',
3757 'id' => 'gllr_gallery_categories',
3758 );
3759 wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) );
3760 ?>
3761 </label><br/>
3762 <label class="gllr_shortcode_selectbox">
3763 <select name="album_order_by_shortcode_option" id="gllr_album_order_by_shortcode_option">
3764 <option value="ID" <?php selected( 'ID', $gllr_options['album_order_by_shortcode_option'] ); ?>><?php esc_html_e( 'Gallery ID', 'gallery-plugin' ); ?></option>
3765 <option value="title" <?php selected( 'title', $gllr_options['album_order_by_shortcode_option'] ); ?>><?php esc_html_e( 'Title', 'gallery-plugin' ); ?></option>
3766 <option value="date" <?php selected( 'date', $gllr_options['album_order_by_shortcode_option'] ); ?>><?php esc_html_e( 'Date', 'gallery-plugin' ); ?></option>
3767 <option value="modified" <?php selected( 'modified', $gllr_options['album_order_by_shortcode_option'] ); ?>><?php esc_html_e( 'Last modified date', 'gallery-plugin' ); ?></option>
3768 <option value="comment_count" <?php selected( 'comment_count', $gllr_options['album_order_by_shortcode_option'] ); ?>><?php esc_html_e( 'Comment count', 'gallery-plugin' ); ?></option>
3769 <option value="menu_order" <?php selected( 'menu_order', $gllr_options['album_order_by_shortcode_option'] ); ?>><?php esc_html_e( '"Order" field on the gallery edit page', 'gallery-plugin' ); ?></option>
3770 <option value="author" <?php selected( 'author', $gllr_options['album_order_by_shortcode_option'] ); ?>><?php esc_html_e( 'Author', 'gallery-plugin' ); ?></option>
3771 <option value="rand" <?php selected( 'rand', $gllr_options['album_order_by_shortcode_option'] ); ?> class="bws_option_affect"><?php esc_html_e( 'Random', 'gallery-plugin' ); ?></option>
3772 <option value="default" <?php selected( 'default', $gllr_options['album_order_by_shortcode_option'] ); ?> class="bws_option_affect"><?php esc_html_e( 'Plugin Settings', 'gallery-plugin' ); ?></option>
3773 </select>
3774 <div class="bws_info"><?php echo sprintf( esc_html__( 'Select galleries sorting order in your category. The sorting direction you can select in the %s', 'gallery-plugin' ), '<a href="' . esc_url( admin_url( 'edit.php?post_type=bws-gallery&page=gallery-plugin.php' ) ) . '">' . esc_html__( 'Cover Settings', 'gallery-plugin' ) . '</a>' ); ?></div>
3775 </label>
3776 <label>
3777 <input name="gllr_shortcode_radio" class="gllr_shortcode_radio_single" type="radio" checked/>
3778 <span class="title"><?php esc_html_e( 'Gallery', 'gallery-plugin' ); ?></span>
3779 <select name="gllr_list" id="gllr_shortcode_list" style="max-width: 350px;">
3780 <?php
3781 while ( $query->have_posts() ) {
3782 $query->the_post();
3783 if ( ! isset( $gllr_first ) ) {
3784 $gllr_first = get_the_ID();
3785 }
3786 $title = get_the_title( $post->ID );
3787 if ( empty( $title ) ) {
3788 $title = ' ( ' . __( 'no title', 'gallery-plugin' ) . ' ) ';
3789 }
3790 ?>
3791 <option value="<?php the_ID(); ?>"><?php echo esc_html( $title ); ?> ( <?php echo esc_attr( get_the_date( 'Y-m-d' ) ); ?> )</option>
3792 <?php
3793 }
3794 wp_reset_postdata();
3795 $post = $old_post;
3796 ?>
3797 </select>
3798 </label><br/>
3799 <label class="gllr_shortcode_checkbox">
3800 <input type="checkbox" value="1" name="gllr_display_short" id="gllr_display_short" />
3801 <span class="checkbox-title">
3802 <?php esc_html_e( 'Display an album image with the description and the link to a single gallery page', 'gallery-plugin' ); ?>
3803 </span>
3804 </label>
3805 <?php } else { ?>
3806 <span class="title"><?php esc_html_e( 'Sorry, no gallery found.', 'gallery-plugin' ); ?></span>
3807 <?php } ?>
3808 </fieldset>
3809 <?php if ( ! empty( $gllr_first ) ) { ?>
3810 <input class="bws_default_shortcode" type="hidden" name="default" value="[print_gllr id=<?php echo esc_attr( $gllr_first ); ?>]" />
3811 <?php
3812 }
3813
3814 $script = '
3815 function gllr_shortcode_init() {
3816 (function($) {
3817 $( \'.mce-reset input[name="gllr_shortcode_radio"], .mce-reset #gllr_display_short, .mce-reset #gllr_album_order_by_shortcode_option, .mce-reset #gllr_shortcode_list, .mce-reset #gllr_gallery_categories\' ).on( \'change\', function() {
3818 if ( $( \'.mce-reset #gllr_shortcode_list\' ).is( ":focus" ) ) {
3819 $( \'.mce-reset input[class="gllr_shortcode_radio_single"]\' ).prop( \'checked\', true );
3820 } else if ( $( \'.mce-reset #gllr_gallery_categories\' ).is( ":focus" ) ) {
3821 $( \'.mce-reset input[class=gllr_shortcode_radio_category]\' ).prop( \'checked\', true );
3822 }
3823 var shortcode = \'[print_gllr \',
3824 id = \'\',
3825 sort_by = \'\';
3826 if( $( \'.mce-reset input[class=gllr_shortcode_radio_category]\' ).is( \':checked\' ) ) {
3827 id = \'gllr_gallery_categories\';
3828 shortcode += \'cat_id=\';
3829 $( \'.gllr_shortcode_checkbox\' ).hide();
3830 $( \'.gllr_shortcode_selectbox\' ).show();
3831 } else if ( $( \'.mce-reset input[class="gllr_shortcode_radio_single"]\' ).is( \':checked\' ) ) {
3832 id = \'gllr_shortcode_list\';
3833 shortcode += \'id=\';
3834 $( \'.gllr_shortcode_checkbox\' ).show();
3835 $( \'.gllr_shortcode_selectbox\' ).hide();
3836 }
3837 var gllr_list = $( \'.mce-reset #\' + id + \' option:selected\' ).val();
3838 shortcode += gllr_list;
3839 if ( $( \'.mce-reset #gllr_display_short\' ).is( \':checked\' ) && $( \'.mce-reset input[class="gllr_shortcode_radio_single"]\' ).is( \':checked\' ) ) {
3840 shortcode += \' display=short\';
3841 }
3842 if ( $( \'.mce-reset input[class="gllr_shortcode_radio_category"]\' ).is( \':checked\' ) ) {
3843 sort_by = \' sort_by=\' + $( \'.mce-reset #gllr_album_order_by_shortcode_option option:selected\' ).val();
3844 }
3845 shortcode += sort_by;
3846 shortcode += \']\';
3847 $( \'.mce-reset #bws_shortcode_display\' ).text( shortcode );
3848 } ).trigger( \'change\' );
3849 })(jQuery);
3850 }
3851 ';
3852
3853 wp_register_script( 'gllr_shortcode_script', '', array(), false, true );
3854 wp_enqueue_script( 'gllr_shortcode_script' );
3855 wp_add_inline_script( 'gllr_shortcode_script', sprintf( $script ) );
3856 ?>
3857 <div class="clear"></div>
3858 </div>
3859 <?php
3860 }
3861 }
3862
3863 if ( ! function_exists( 'gllr_add_tabs' ) ) {
3864 /**
3865 * Add help tab
3866 */
3867 function gllr_add_tabs() {
3868 global $gllr_options;
3869 $screen = get_current_screen();
3870
3871 if ( ! empty( $screen->post_type ) && $gllr_options['post_type_name'] === $screen->post_type ) {
3872 $args = array(
3873 'id' => 'gllr',
3874 'section' => '200538899',
3875 );
3876 bws_help_tab( $screen, $args );
3877 }
3878 }
3879 }
3880
3881 if ( ! function_exists( 'gllr_admin_notices' ) ) {
3882 /**
3883 * Add admin notice
3884 */
3885 function gllr_admin_notices() {
3886 global $hook_suffix, $gllr_plugin_info, $gllr_bws_demo_data, $gllr_options;
3887
3888 if ( 'plugins.php' === $hook_suffix || ( isset( $_GET['page'] ) && 'gallery-plugin.php' === $_GET['page'] ) ) {
3889
3890 if ( ! $gllr_bws_demo_data ) {
3891 gllr_include_demo_data();
3892 }
3893
3894 $gllr_bws_demo_data->bws_handle_demo_notice( $gllr_options['display_demo_notice'] );
3895
3896 if ( 'plugins.php' === $hook_suffix ) {
3897 bws_plugin_banner_to_settings( $gllr_plugin_info, 'gllr_options', 'gallery-plugin', 'edit.php?post_type=' . $gllr_options['post_type_name'] . '&page=gallery-plugin.php', 'post-new.php?post_type=' . $gllr_options['post_type_name'] );
3898 } else {
3899 bws_plugin_suggest_feature_banner( $gllr_plugin_info, 'gllr_options', 'gallery-plugin' );
3900 }
3901 } else {
3902 $max_filesize = ini_get( 'upload_max_filesize' );
3903 $max_input_vars = ini_get( 'max_input_vars' );
3904 $cs = get_current_screen();
3905 $is_bws_gallery_page = ( 'add' === $cs->action || 'post' === $cs->base ) && $cs->post_type === $gllr_options['post_type_name'];
3906 if ( $is_bws_gallery_page && '' !== $max_filesize ) {
3907 echo '<div class="notice notice-info"><p><strong>' . esc_html__( 'Warning', 'gallery-plugin' ) . ': </strong>' . sprintf( esc_html__( 'Maximum upload file size %s. Contact your administrator or hosting provider if you need to upload a large file size.', 'gallery-plugin' ), esc_html( $max_filesize ) ) . '</p></div>';
3908 }
3909 if ( $is_bws_gallery_page && '' !== $max_input_vars ) {
3910 echo '<div class="notice notice-info"><p><strong>' . esc_html__( 'Warning', 'gallery-plugin' ) . ': </strong>' . sprintf( esc_html__( 'Input vars count %s i.e. the number of pictures in the gallery may be limited. Contact your administrator or hosting provider if you need to upload a large input vars count.', 'gallery-plugin' ), esc_html( $max_input_vars ) ) . '</p></div>';
3911 }
3912 }
3913 }
3914 }
3915
3916 if ( ! function_exists( 'gllr_get_gallery_data' ) ) {
3917 /**
3918 * Gallery data objects. Takes array of id or empty array, single id or 'all'
3919 *
3920 * @param number $gallery_id Gallery ID.
3921 */
3922 function gllr_get_gallery_data( $gallery_id ) {
3923 global $gllr_options;
3924
3925 if ( empty( $gllr_options ) ) {
3926 gllr_settings();
3927 }
3928
3929 $gallery_images = array();
3930 $gallery_posts = array();
3931
3932 /* Get the entire list of posts or the specified array */
3933 if ( 'all' === $gallery_id || is_array( $gallery_id ) ) {
3934
3935 /* Prepare args for get_posts */
3936 if ( is_array( $gallery_id ) && ! empty( $gallery_id ) ) {
3937 $gallery_id_list = $gallery_id;
3938 $args = array(
3939 'post_type' => $gllr_options['post_type_name'],
3940 'include' => $gallery_id_list,
3941 );
3942 } else {
3943 $args = array( 'post_type' => $gllr_options['post_type_name'] );
3944 }
3945
3946 $gallery_posts = get_posts( $args );
3947
3948 } elseif ( is_int( $gallery_id ) ) {
3949
3950 $gallery_int_id = absint( $gallery_id );
3951 $gallery_posts[] = get_post( $gallery_int_id );
3952
3953 }
3954
3955 /* Return false if there are no records */
3956 if ( ! $gallery_posts ) {
3957 return false;
3958 }
3959
3960 foreach ( (array) $gallery_posts as $gallery_post ) {
3961
3962 /* Get a id list of gallery pictures */
3963 $gallery_images_meta = get_post_meta( $gallery_post->ID, '_gallery_images', true );
3964 $gallery_images_id = explode( ',', $gallery_images_meta );
3965
3966 /* Add gallery data to resulting array from wp_posts */
3967 $gallery_images[ $gallery_post->ID ]['gallery_wp_post'] = $gallery_post;
3968
3969 foreach ( $gallery_images_id as $image_id ) {
3970
3971 /* Resulting array with images */
3972 $gallery_image_post_meta = array();
3973
3974 $image_post_meta = get_post_meta( $image_id, '', true );
3975 foreach ( $image_post_meta as $key => $value ) {
3976 $image_post_meta_item = get_post_meta( $image_id, $key, true );
3977 $gallery_image_post_meta[ $key ] = $image_post_meta_item;
3978 }
3979 $gallery_images[ $gallery_post->ID ]['gallery_images'][] = array(
3980 'wp_post_image' => get_post( $image_id ),
3981 'image_post_meta' => $gallery_image_post_meta,
3982 );
3983 }
3984 }
3985
3986 $gallery_objects = $gallery_images;
3987
3988 return $gallery_objects;
3989 }
3990 }
3991
3992 if ( ! function_exists( 'gllr_plugin_uninstall' ) ) {
3993 /**
3994 * Perform at uninstall
3995 */
3996 function gllr_plugin_uninstall() {
3997 global $wpdb, $gllr_bws_demo_data;
3998
3999 if ( ! function_exists( 'get_plugins' ) ) {
4000 require_once ABSPATH . 'wp-admin/includes/plugin.php';
4001 }
4002 $all_plugins = get_plugins();
4003
4004 if ( ! array_key_exists( 'gallery-plugin-pro/gallery-plugin-pro.php', $all_plugins )
4005 && ! array_key_exists( 'gallery-plus/gallery-plus.php', $all_plugins ) ) {
4006 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
4007 $old_blog = $wpdb->blogid;
4008 /* Get all blog ids */
4009 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
4010 foreach ( $blogids as $blog_id ) {
4011 switch_to_blog( $blog_id );
4012 gllr_include_demo_data();
4013 $gllr_bws_demo_data->bws_remove_demo_data();
4014
4015 delete_option( 'gllr_options' );
4016 delete_option( 'widget_gallery_categories_widget' );
4017 }
4018 switch_to_blog( $old_blog );
4019 } else {
4020 gllr_include_demo_data();
4021 $gllr_bws_demo_data->bws_remove_demo_data();
4022
4023 delete_option( 'gllr_options' );
4024 delete_option( 'widget_gallery_categories_widget' );
4025 }
4026 delete_metadata( 'user', null, 'wp_gllr_media_library_mode', '', true );
4027 }
4028
4029 if ( is_multisite() ) {
4030 delete_site_option( 'gllr_options' );
4031 }
4032
4033 require_once dirname( __FILE__ ) . '/bws_menu/bws_include.php';
4034 bws_include_init( plugin_basename( __FILE__ ) );
4035 bws_delete_plugin( plugin_basename( __FILE__ ) );
4036 }
4037 }
4038
4039 /* Activate plugin */
4040 register_activation_hook( __FILE__, 'gllr_plugin_activate' );
4041 add_action( 'after_switch_theme', 'gllr_register_galleries' );
4042
4043 /* Additional links on the plugin page */
4044 add_filter( 'plugin_action_links', 'gllr_plugin_action_links', 10, 2 );
4045 add_filter( 'plugin_row_meta', 'gllr_register_plugin_links', 10, 2 );
4046
4047 add_action( 'admin_menu', 'add_gllr_admin_menu' );
4048 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
4049 add_action( 'network_admin_menu', 'add_gllr_admin_menu' );
4050 }
4051
4052 add_action( 'init', 'gllr_init' );
4053 add_action( 'admin_init', 'gllr_admin_init' );
4054
4055 add_action( 'plugins_loaded', 'gllr_plugins_loaded' );
4056
4057 add_filter( 'rewrite_rules_array', 'gllr_custom_permalinks' ); /* Add custom permalink for gallery */
4058
4059 /* this function returns custom content with images for PDF&Print plugin on Gallery page */
4060 add_filter( 'bwsplgns_get_pdf_print_content', 'gllr_add_pdf_print_content', 100, 2 );
4061
4062 add_action( 'after-gallery_categories-table', 'gllr_add_notice_below_table' );
4063 add_filter( 'manage_edit-gallery_categories_columns', 'gllr_add_column' );
4064 add_filter( 'manage_gallery_categories_custom_column', 'gllr_fill_column', 10, 3 );
4065 add_action( 'post_updated', 'gllr_default_term' );
4066 add_action( 'restrict_manage_posts', 'gllr_taxonomy_filter' );
4067 add_filter( 'gallery_categories_row_actions', 'gllr_hide_delete_link', 10, 2 );
4068 add_action( 'admin_footer-edit-tags.php', 'gllr_hide_delete_cb' );
4069 add_action( 'delete_term_taxonomy', 'gllr_delete_term', 10, 1 );
4070
4071 /* Save custom data from admin */
4072 add_action( 'save_post', 'gllr_save_postdata', 1, 2 );
4073 /* check post content */
4074 add_filter( 'content_save_pre', 'gllr_content_save_pre', 10, 1 );
4075
4076 add_action( 'pre_get_posts', 'gllr_manage_pre_get_posts', 1 );
4077
4078 add_action( 'gallery_categories_add_form_fields', 'gllr_additive_field_in_category', 10, 2 );
4079 add_action( 'gallery_categories_edit_form_fields', 'gllr_additive_field_in_category_edit', 10, 2 );
4080 add_action( 'edited_gallery_categories', 'gllr_save_category_additive_field', 10, 2 );
4081 add_action( 'create_gallery_categories', 'gllr_save_category_additive_field', 10, 2 );
4082
4083 add_action( 'admin_enqueue_scripts', 'gllr_admin_head' );
4084 add_action( 'wp_head', 'gllr_wp_head' );
4085 add_action( 'wp_footer', 'gllr_wp_footer', 15 );
4086 add_action( 'wp_enqueue_scripts', 'gllr_enqueue_scripts', 100 );
4087
4088 add_filter( 'pgntn_callback', 'gllr_pagination_callback' );
4089
4090 /* add theme name as class to body tag */
4091 add_filter( 'body_class', 'gllr_theme_body_classes' );
4092
4093 add_shortcode( 'print_gllr', 'gllr_shortcode' );
4094 add_filter( 'widget_text', 'do_shortcode' );
4095
4096 add_action( 'wp_ajax_gllr_update_image', 'gllr_update_image' );
4097 add_action( 'admin_notices', 'gllr_admin_notices' );
4098
4099 /* Add place for notice in media upoader for portfolio */
4100 add_action( 'print_media_templates', 'gllr_print_media_notice', 11 );
4101 /* Add notises in media upoader for gallery */
4102 add_action( 'wp_ajax_gllr_media_check', 'gllr_media_check_ajax_action' );
4103
4104 /* custom filter for bws button in tinyMCE */
4105 add_filter( 'bws_shortcode_button_content', 'gllr_shortcode_button_content' );
4106
4107 add_action( 'wp_ajax_gllr_delete_image', 'gllr_delete_image' );
4108 add_action( 'wp_ajax_gllr_add_from_media', 'gllr_add_from_media' );
4109 add_action( 'wp_ajax_gllr_change_view_mode', 'gllr_change_view_mode' );
4110
4111 add_action( 'wp_ajax_gllr_export_slider', 'gllr_export_slider' );
4112