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

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