PluginProbe
Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress / 4.7.4
Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress v4.7.4
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.4, at gallery-plugin.php

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