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

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