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

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