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

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

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