Image Photo Gallery Final Tiles Grid - Version 3.5.2

Version Description

  • 10/01/2022 =
  • Removed: Google Plus
  • Fixed: Gallery images Would not show
  • Fixed: Lightbox Settings would not save properly
  • Fixed: Image upload modal would display a strange countour
Download this release

Release Info

Developer raldea89
Plugin Icon 128x128 Image Photo Gallery Final Tiles Grid
Version 3.5.2
Comparing to
See all releases

Code changes from version 3.5.1 to 3.5.2

FinalTilesGalleryLite.php CHANGED
@@ -1,1558 +1,1555 @@
1
- <?php
2
-
3
- /**
4
- * Plugin Name: Final Tiles Grid Gallery - Image Gallery
5
- * Description: Wordpress Plugin for creating responsive image galleries.
6
- * Version: 3.5.1
7
- * Author: WPChill
8
- * Author URI: https://wpchill.com
9
- * Tested up to: 5.2
10
- * Requires: 5.2 or higher
11
- * License: GPLv3 or later
12
- * License URI: http://www.gnu.org/licenses/gpl-3.0.html
13
- * Requires PHP: 5.6
14
- * Text Domain: final-tiles-grid-gallery-lite
15
- * Domain Path: /languages
16
- *
17
- * Copyright 2015-2019 GreenTreeLabs diego@greentreelabs.net
18
- * Copyright 2019-2020 MachoThemes office@machothemes.com
19
- * SVN commit with proof of ownership transfer: https://plugins.trac.wordpress.org/changeset/2163481/
20
- * NOTE: MachoThemes took ownership of this plugin on: 09/26/2019 08:49:37 AM as can be seen from the above SVN commit.
21
- * Copyright 2020 WPChill heyyy@wpchill.com
22
- *
23
- * Original Plugin URI: https://greentreelabs.net/final-tiles-gallery-lite/
24
- * Original Author URI: https://greentreelabs.net
25
- * Original Author: https://profiles.wordpress.org/greentreealbs/
26
- *
27
- */
28
- define( "FTGVERSION", "3.5.1" );
29
- // Create a helper function for easy SDK access.
30
-
31
- if ( !function_exists( 'ftg_fs' ) ) {
32
- // Create a helper function for easy SDK access.
33
- function ftg_fs()
34
- {
35
- global $ftg_fs ;
36
-
37
- if ( !isset( $ftg_fs ) ) {
38
- // Activate multisite network integration.
39
- if ( !defined( 'WP_FS__PRODUCT_1002_MULTISITE' ) ) {
40
- define( 'WP_FS__PRODUCT_1002_MULTISITE', true );
41
- }
42
- // Include Freemius SDK.
43
- require_once dirname( __FILE__ ) . '/freemius/start.php';
44
- $ftg_fs = fs_dynamic_init( array(
45
- 'id' => '1002',
46
- 'slug' => 'final-tiles-grid-gallery-lite',
47
- 'type' => 'plugin',
48
- 'public_key' => 'pk_d0e075b84d491d510a1d0a21087af',
49
- 'is_premium' => false,
50
- 'has_addons' => false,
51
- 'has_paid_plans' => true,
52
- 'trial' => array(
53
- 'days' => 14,
54
- 'is_require_payment' => true,
55
- ),
56
- 'has_affiliation' => 'all',
57
- 'menu' => array(
58
- 'slug' => 'ftg-lite-gallery-admin',
59
- ),
60
- 'is_live' => true,
61
- ) );
62
- }
63
-
64
- return $ftg_fs;
65
- }
66
-
67
- // Init Freemius.
68
- ftg_fs();
69
- // Signal that SDK was initiated.
70
- do_action( 'ftg_fs_loaded' );
71
- }
72
-
73
- function activate_finaltilesgallery()
74
- {
75
- global $wpdb ;
76
- include_once 'lib/install-db.php';
77
- FinalTiles_Gallery::define_db_tables();
78
- FinalTilesdb::updateConfiguration();
79
-
80
- if ( is_multisite() ) {
81
- foreach ( $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" ) as $blog_id ) {
82
- switch_to_blog( $blog_id );
83
- install_db();
84
- restore_current_blog();
85
- }
86
- } else {
87
- install_db();
88
- }
89
-
90
- }
91
-
92
- define( "FTG_PLAN", "free" );
93
- if ( !class_exists( 'FinalTiles_Gallery' ) ) {
94
- class FinalTiles_Gallery
95
- {
96
- private $defaultValues = array(
97
- 'aClass' => '',
98
- 'afterGalleryText' => '',
99
- 'allFilterLabel' => 'All',
100
- 'ajaxLoading' => 'F',
101
- 'backgroundColor' => 'transparent',
102
- 'beforeGalleryText' => '',
103
- 'blank' => 'F',
104
- 'borderColor' => 'transparent',
105
- 'borderRadius' => 0,
106
- 'borderSize' => 0,
107
- 'captionBackgroundColor' => '#000000',
108
- 'captionBehavior' => 'none',
109
- 'captionColor' => '#ffffff',
110
- 'captionCustomFields' => '',
111
- 'captionEasing' => 'linear',
112
- 'captionEffect' => 'slide-from-bottom',
113
- 'captionEffectDuration' => 250,
114
- 'captionEmpty' => 'hide',
115
- 'captionFontSize' => 12,
116
- 'captionFrame' => 'F',
117
- 'captionFrameColor' => '#ffffff',
118
- 'captionHorizontalAlignment' => 'center',
119
- 'captionIcon' => 'zoom',
120
- 'captionIconColor' => '#ffffff',
121
- 'captionIconSize' => 12,
122
- 'captionMobileBehavior' => "desktop",
123
- 'captionOpacity' => 80,
124
- 'captionPosition' => 'inside',
125
- 'captionVerticalAlignment' => 'middle',
126
- 'categoriesAsFilters' => 'F',
127
- 'columns' => 4,
128
- 'columnsPhoneLandscape' => 3,
129
- 'columnsPhonePortrait' => 2,
130
- 'columnsTabletLandscape' => 4,
131
- 'columnsTabletPortrait' => 3,
132
- 'compressHTML' => 'T',
133
- 'customCaptionIcon' => '',
134
- 'defaultFilter' => '',
135
- 'defaultSize' => 'medium',
136
- 'delay' => 0,
137
- 'disableLightboxGroups' => 'F',
138
- 'enableFacebook' => 'F',
139
- 'enableGplus' => 'F',
140
- 'enablePinterest' => 'F',
141
- 'enableTwitter' => 'F',
142
- 'enlargeImages' => 'T',
143
- 'filterClick' => 'F',
144
- 'filters' => '',
145
- 'gridCellSize' => 25,
146
- 'gridCellSizeDisabledBelow' => 800,
147
- 'hoverDuration' => 250,
148
- 'hoverIconRotation' => 'F',
149
- 'hoverRotation' => 0,
150
- 'hoverZoom' => 100,
151
- 'imageSizeFactor' => 30,
152
- 'imageSizeFactorCustom' => '',
153
- 'imageSizeFactorPhoneLandscape' => 30,
154
- 'imageSizeFactorPhonePortrait' => 20,
155
- 'imageSizeFactorTabletLandscape' => 30,
156
- 'imageSizeFactorTabletPortrait' => 20,
157
- 'imagesOrder' => 'user',
158
- 'layout' => 'final',
159
- 'lazyLoad' => false,
160
- 'lightbox' => 'lightbox2',
161
- 'lightboxImageSize' => 'large',
162
- 'lightboxOptions' => '',
163
- 'lightboxOptionsMobile' => '',
164
- 'loadedDuration' => 500,
165
- 'loadedEasing' => 'ease-out',
166
- 'loadedHSlide' => 0,
167
- 'loadedRotateY' => 0,
168
- 'loadedRotateX' => 0,
169
- 'loadedScaleY' => 100,
170
- 'loadedScaleX' => 100,
171
- 'loadedVSlide' => 0,
172
- 'loadingBarBackgroundColor' => "#fff",
173
- 'loadingBarColor' => "#666",
174
- 'loadMethod' => 'sequential',
175
- 'margin' => 10,
176
- 'max_posts' => 0,
177
- 'minTileWidth' => '250',
178
- 'mobileLightbox' => 'lightbox2',
179
- 'post_types' => '',
180
- 'post_taxonomies' => '',
181
- 'recentPostsCaption' => 'title',
182
- 'recentPostsCaptionAutoExcerptLength' => 20,
183
- 'rel' => '',
184
- 'reverseOrder' => false,
185
- 'script' => '',
186
- 'shadowColor' => '#cccccc',
187
- 'shadowSize' => 0,
188
- 'socialIconColor' => '#ffffff',
189
- 'socialIconPosition' => 'bottom',
190
- 'socialIconStyle' => 'none',
191
- 'source' => 'images',
192
- 'style' => '',
193
- 'support' => 'F',
194
- 'supportText' => 'Powered by Final Tiles Grid Gallery',
195
- 'taxonomyOperator' => 'OR',
196
- 'tilesPerPage' => 0,
197
- 'titleFontSize' => 14,
198
- 'width' => '100%',
199
- 'wp_field_caption' => 'description',
200
- 'wp_field_title' => 'title',
201
- ) ;
202
- //Constructor
203
- public function __construct()
204
- {
205
- $this->plugin_name = plugin_basename( __FILE__ );
206
- $this->define_constants();
207
- $this->setupFields();
208
- $this->define_db_tables();
209
- $this->FinalTilesdb = $this->create_db_conn();
210
- add_filter( 'widget_text', 'do_shortcode' );
211
- add_action( 'init', array( $this, 'create_textdomain' ) );
212
- add_action( 'wp_enqueue_scripts', array( $this, 'add_gallery_scripts' ) );
213
- //add_action( 'admin_init', array($this,'gallery_admin_init') );
214
- add_action( 'admin_menu', array( $this, 'add_gallery_admin_menu' ) );
215
- add_action( 'init', array( $this, 'register_gutenberg_block' ) );
216
- add_shortcode( 'FinalTilesGallery', array( $this, 'gallery_shortcode_handler' ) );
217
- add_action( 'wp_ajax_save_gallery', array( $this, 'save_gallery' ) );
218
- add_action( 'wp_ajax_add_new_gallery', array( $this, 'add_new_gallery' ) );
219
- add_action( 'wp_ajax_delete_gallery', array( $this, 'delete_gallery' ) );
220
- add_action( 'wp_ajax_clone_gallery', array( $this, 'clone_gallery' ) );
221
- add_action( 'wp_ajax_save_image', array( $this, 'save_image' ) );
222
- add_action( 'wp_ajax_add_image', array( $this, 'add_image' ) );
223
- add_action( 'wp_ajax_save_video', array( $this, 'save_video' ) );
224
- add_action( 'wp_ajax_sort_images', array( $this, 'sort_images' ) );
225
- add_action( 'wp_ajax_delete_image', array( $this, 'delete_image' ) );
226
- add_action( 'wp_ajax_assign_filters', array( $this, 'assign_filters' ) );
227
- add_action( 'wp_ajax_assign_group', array( $this, 'assign_group' ) );
228
- add_action( 'wp_ajax_toggle_visibility', array( $this, 'toggle_visibility' ) );
229
- add_action( 'wp_ajax_refresh_gallery', array( $this, 'refresh_gallery' ) );
230
- add_action( 'wp_ajax_get_gallery_configuration', array( $this, 'get_configuration' ) );
231
- add_action( 'wp_ajax_update_gallery_configuration', array( $this, 'update_configuration' ) );
232
- add_action( 'wp_ajax_get_image_size_url', array( $this, 'get_image_size_url' ) );
233
- add_filter( 'mce_buttons', array( $this, 'editor_button' ) );
234
- add_filter( 'mce_external_plugins', array( $this, 'register_editor_plugin' ) );
235
- add_action( 'wp_ajax_ftg_shortcode_editor', array( $this, 'ftg_shortcode_editor' ) );
236
- add_filter(
237
- 'plugin_row_meta',
238
- array( $this, 'register_links' ),
239
- 10,
240
- 2
241
- );
242
- add_action( 'wp_ajax_load_chunk', array( $this, 'load_chunk' ) );
243
- add_action( 'wp_ajax_nopriv_load_chunk', array( $this, 'load_chunk' ) );
244
-
245
- if ( ftg_fs()->is_not_paying() ) {
246
- add_action( 'admin_notices', array( $this, 'review' ) );
247
- add_action( 'wp_ajax_ftg_dismiss_review', array( $this, 'dismiss_review' ) );
248
- add_filter(
249
- 'admin_footer_text',
250
- array( $this, 'admin_footer' ),
251
- 1,
252
- 2
253
- );
254
- }
255
-
256
- $this->resetFields();
257
- }
258
-
259
- /**
260
- * Register Gutenberg Block
261
- */
262
- public function register_gutenberg_block()
263
- {
264
- if ( !function_exists( 'register_block_type' ) ) {
265
- // Gutenberg is not active.
266
- return;
267
- }
268
- // Register block js script
269
- wp_register_script( 'ftg-gallery-block', plugins_url( 'scripts/gutenberg_block.js', __FILE__ ), array(
270
- 'wp-blocks',
271
- 'wp-i18n',
272
- 'wp-element',
273
- 'wp-editor',
274
- 'wp-components'
275
- ) );
276
- // Editor CSS
277
- wp_register_style( 'ftg-gallery-block-editor', plugins_url( 'admin/css/gutenberg_block.css', __FILE__ ), array( 'wp-edit-blocks' ) );
278
- // Register block
279
- register_block_type( 'ftg/gallery', array(
280
- 'editor_style' => 'ftg-gallery-block-editor',
281
- 'editor_script' => 'ftg-gallery-block',
282
- ) );
283
- // Set block translation
284
- wp_set_script_translations( 'FinalTiles-gallery', 'final-tiles-gallery', dirname( plugin_basename( __FILE__ ) ) . '/lib/languages/' );
285
- $galls = [ [
286
- 'value' => 0,
287
- 'label' => esc_html__( 'Select gallery', 'final-tiles-grid-gallery-lite' ),
288
- ] ];
289
- $galleries = $this->FinalTilesdb->getGalleries();
290
- if ( $galleries ) {
291
- foreach ( $galleries as $g ) {
292
- $galls[] = [
293
- 'value' => $g->Id,
294
- 'label' => $g->name,
295
- ];
296
- }
297
- }
298
- // send list of galleries to block
299
- wp_localize_script( 'ftg-gallery-block', 'ftg_galleries', array(
300
- 'items' => $galls,
301
- 'add_new_galler_url' => admin_url( 'admin.php?page=ftg-add-gallery' ),
302
- ) );
303
- }
304
-
305
- public function review()
306
- {
307
- // Verify that we can do a check for reviews.
308
- $review = get_option( 'ftg_review' );
309
- $time = time();
310
- $load = false;
311
- $there_was_review = false;
312
-
313
- if ( !$review ) {
314
- $review = array(
315
- 'time' => $time,
316
- 'dismissed' => false,
317
- );
318
- $load = true;
319
- $there_was_review = false;
320
- } else {
321
- // Check if it has been dismissed or not.
322
- if ( isset( $review['dismissed'] ) && !$review['dismissed'] && (isset( $review['time'] ) && $review['time'] + DAY_IN_SECONDS <= $time) ) {
323
- $load = true;
324
- }
325
- }
326
-
327
- // If we cannot load, return early.
328
- if ( !$load ) {
329
- return;
330
- }
331
- // Update the review option now.
332
- update_option( 'ftg_review', $review );
333
- // Run through optins on the site to see if any have been loaded for more than a week.
334
- $valid = false;
335
- $galleries = $this->FinalTilesdb->getGalleries();
336
- if ( !$galleries ) {
337
- return;
338
- }
339
- $with_date = false;
340
- foreach ( $galleries as $gallery ) {
341
- if ( !isset( $gallery->date ) ) {
342
- continue;
343
- }
344
- $with_date = true;
345
- $data = $gallery->date;
346
- // Check the creation date of the local optin. It must be at least one week after.
347
- $created = ( isset( $data ) ? strtotime( $data ) + 7 * DAY_IN_SECONDS : false );
348
- if ( !$created ) {
349
- continue;
350
- }
351
-
352
- if ( $created <= $time ) {
353
- $valid = true;
354
- break;
355
- }
356
-
357
- }
358
- if ( !$with_date && count( $galleries ) > 0 && !$there_was_review ) {
359
- $valid = true;
360
- }
361
- // If we don't have a valid option yet, return.
362
- if ( !$valid ) {
363
- return;
364
- }
365
- // We have a candidate! Output a review message.
366
- ?>
367
- <div class="notice notice-info is-dismissible ftg-review-notice">
368
- <p><?php
369
- esc_html_e( 'Hey, I noticed you created a photo gallery with Final Tiles - that’s awesome! Would you mind give it a 5-star rating on WordPress to help us spread the word and boost our motivation for new featrues?', 'final-tiles-grid-gallery-lite' );
370
- ?></p>
371
- <p><strong><?php
372
- esc_html_e( 'MachoThemes', 'final-tiles-grid-gallery-lite' );
373
- ?></strong></p>
374
- <p>
375
- <a href="https://wordpress.org/support/plugin/final-tiles-grid-gallery-lite/reviews/?filter=5#new-post" class="ftg-dismiss-review-notice ftg-review-out" target="_blank" rel="noopener"><?php
376
- esc_html_e( 'Ok, you deserve it', 'final-tiles-grid-gallery-lite' );
377
- ?></a><br>
378
- <a href="#" class="ftg-dismiss-review-notice" rel="noopener"><?php
379
- esc_html_e( 'Nope, maybe later', 'final-tiles-grid-gallery-lite' );
380
- ?></a><br>
381
- <a href="#" class="ftg-dismiss-review-notice" rel="noopener"><?php
382
- esc_html_e( 'I already did', 'final-tiles-grid-gallery-lite' );
383
- ?></a><br>
384
- </p>
385
- </div>
386
- <script type="text/javascript">
387
- jQuery(document).ready( function($) {
388
- $(document).on('click', '.ftg-dismiss-review-notice, .ftg-review-notice button', function( event ) {
389
- if ( ! $(this).hasClass('ftg-review-out') ) {
390
- event.preventDefault();
391
- }
392
-
393
- $.post( ajaxurl, {
394
- action: 'ftg_dismiss_review'
395
- });
396
-
397
- $('.ftg-review-notice').remove();
398
- });
399
- });
400
- </script>
401
- <?php
402
- }
403
-
404
- public function dismiss_review()
405
- {
406
- $review = get_option( 'ftg_review' );
407
- if ( !$review ) {
408
- $review = array();
409
- }
410
- $review['time'] = time();
411
- $review['dismissed'] = true;
412
- update_option( 'ftg_review', $review );
413
- die;
414
- }
415
-
416
- public function admin_footer( $text )
417
- {
418
- global $current_screen ;
419
-
420
- if ( !empty($current_screen->id) && strpos( $current_screen->id, 'ftg' ) !== false ) {
421
- $url = esc_url( 'https://wordpress.org/support/plugin/final-tiles-grid-gallery-lite/reviews/?filter=5#new-post' );
422
- $text = sprintf( __( 'Please rate <strong>Final Tiles Gallery</strong> <a href="%s" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a> on <a href="%s" target="_blank">WordPress.org</a> to help us spread the word. Thank you from the Final Tiles Gallery team!', 'final-tiles-grid-gallery-lite' ), $url, $url );
423
- }
424
-
425
- return $text;
426
- }
427
-
428
- private function resetFields()
429
- {
430
- $keys = array(
431
- 'name',
432
- 'hiddenFor',
433
- 'type',
434
- 'description',
435
- 'default',
436
- 'min',
437
- 'max',
438
- 'mu',
439
- 'excludeFrom'
440
- );
441
- foreach ( $this->fields as $tab_name => $tab ) {
442
- foreach ( $tab["fields"] as $key => $field ) {
443
- //print_r($field);
444
- foreach ( $keys as $kk ) {
445
- if ( !array_key_exists( $kk, $field ) ) {
446
- $this->fields[$tab_name]["fields"][$key][$kk] = "";
447
- }
448
- }
449
- }
450
- }
451
- //print_r($this->fields);
452
- }
453
-
454
- public function register_links( $links, $file )
455
- {
456
- $base = plugin_basename( __FILE__ );
457
-
458
- if ( $file == $base ) {
459
- $links[] = '<a href="admin.php?page=ftg-lite-gallery-admin" title="Final Tiles Grid Gallery Dashboard">Dashboard</a>';
460
- $links[] = '<a href="https://www.machothemes.com/" title="MachoThemes website">MachoThemes</a>';
461
- $links[] = '<a href="https://twitter.com/machothemes" title="@MachoThemes on Twitter">Twitter</a>';
462
- $links[] = '<a href="https://www.facebook.com/machothemes" title="MachoThemes on Facebook">Facebook</a>';
463
- }
464
-
465
- return $links;
466
- }
467
-
468
- /*public function create_db_tables()
469
- {
470
- include_once 'lib/install-db.php';
471
- install_db();
472
- }
473
-
474
- public function activation()
475
- {
476
-
477
- }*/
478
- //Define textdomain
479
- public function create_textdomain()
480
- {
481
- $plugin_dir = basename( dirname( __FILE__ ) );
482
- load_plugin_textdomain( 'final-tiles-grid-gallery-lite', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
483
- foreach ( $this->fields as $s => $section ) {
484
- foreach ( $section["fields"] as $f => $field ) {
485
- $this->fields[$s]["fields"][$f]["description"] = esc_html__( $this->fields[$s]["fields"][$f]["description"], 'final-tiles-grid-gallery-lite' );
486
- }
487
- }
488
- }
489
-
490
- //Define constants
491
- public function define_constants()
492
- {
493
- if ( !defined( 'FINALTILESGALLERY_PLUGIN_BASENAME' ) ) {
494
- define( 'FINALTILESGALLERY_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
495
- }
496
- if ( !defined( 'FINALTILESGALLERY_PLUGIN_NAME' ) ) {
497
- define( 'FINALTILESGALLERY_PLUGIN_NAME', trim( dirname( FINALTILESGALLERY_PLUGIN_BASENAME ), '/' ) );
498
- }
499
- if ( !defined( 'FINALTILESGALLERY_PLUGIN_DIR' ) ) {
500
- define( 'FINALTILESGALLERY_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . FINALTILESGALLERY_PLUGIN_NAME );
501
- }
502
- }
503
-
504
- //Define DB tables
505
- public static function define_db_tables()
506
- {
507
- global $wpdb ;
508
- $wpdb->FinalTilesGalleries = $wpdb->prefix . 'FinalTiles_gallery';
509
- $wpdb->FinalTilesImages = $wpdb->prefix . 'FinalTiles_gallery_images';
510
- }
511
-
512
- public function create_db_conn()
513
- {
514
- require 'lib/db-class.php';
515
- $FinalTilesdb = FinalTilesDB::getInstance();
516
- return $FinalTilesdb;
517
- }
518
-
519
- public function editor_button( $buttons )
520
- {
521
- array_push( $buttons, 'separator', 'ftg_shortcode_editor' );
522
- return $buttons;
523
- }
524
-
525
- public function register_editor_plugin( $plugin_array )
526
- {
527
- $plugin_array['ftg_shortcode_editor'] = plugins_url( '/admin/scripts/editor-plugin.js', __FILE__ );
528
- return $plugin_array;
529
- }
530
-
531
- public function ftg_shortcode_editor()
532
- {
533
- $css_path = plugins_url( 'assets/css/admin.css', __FILE__ );
534
- $admin_url = admin_url();
535
- $galleries = $this->FinalTilesdb->getGalleries();
536
- //load all galleries
537
- include 'admin/include/tinymce-galleries.php';
538
- wp_die();
539
- }
540
-
541
- public function attachment_fields_to_edit( $form, $post )
542
- {
543
- $form["ftg_link"] = array(
544
- "label" => "Link <small>FTG</small>",
545
- "input" => "text",
546
- "value" => get_post_meta( $post->ID, "_ftg_link", true ),
547
- "helps" => "",
548
- );
549
- $form["ftg_target"] = array(
550
- "label" => "_blank <small>FTG</small>",
551
- "input" => "html",
552
- "html" => "<input type='checkbox' name='attachments[{$post->ID}][ftg_target]' id='attachments[{$post->ID}][ftg_target]' value='_mblank' " . (( get_post_meta( $post->ID, "_ftg_target", true ) == "_mblank" ? "checked" : "" )) . " />",
553
- );
554
- return $form;
555
- }
556
-
557
- public function attachment_fields_to_save( $post, $attachment )
558
- {
559
- if ( isset( $attachment['ftg_link'] ) ) {
560
- update_post_meta( $post['ID'], '_ftg_link', esc_url_raw( $attachment['ftg_link'] ) );
561
- }
562
- if ( isset( $attachment['ftg_target'] ) ) {
563
- update_post_meta( $post['ID'], '_ftg_target', sanitize_text_field( $attachment['ftg_target'] ) );
564
- }
565
- return $post;
566
- }
567
-
568
- //Delete gallery
569
- public function delete_gallery()
570
- {
571
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
572
- $this->FinalTilesdb->deleteGallery( intval( $_POST['id'] ) );
573
- }
574
- return array();
575
- }
576
-
577
- public function update_configuration()
578
- {
579
-
580
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
581
- $id = $_POST['galleryId'];
582
- $config = stripslashes( $_POST['config'] );
583
- $this->FinalTilesdb->update_config( $id, $config );
584
- }
585
-
586
- exit;
587
- }
588
-
589
- public function get_configuration()
590
- {
591
-
592
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
593
- $id = $_POST['galleryId'];
594
- $gallery = $this->FinalTilesdb->getGalleryConfig( $id );
595
- echo $gallery ;
596
- }
597
-
598
- exit;
599
- }
600
-
601
- public function get_image_size_url()
602
- {
603
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
604
- echo wp_get_attachment_image_url( $_POST['id'], $_POST['size'], false ) ;
605
- }
606
- exit;
607
- }
608
-
609
- //Clone gallery
610
- public function clone_gallery()
611
- {
612
-
613
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
614
- $sourceId = intval( $_POST['id'] );
615
- $g = $this->FinalTilesdb->getGalleryById( $sourceId, true );
616
- $g['name'] .= " (copy)";
617
- $this->FinalTilesdb->addGallery( $g );
618
- $id = $this->FinalTilesdb->getNewGalleryId();
619
- $images = $this->FinalTilesdb->getImagesByGalleryId( $sourceId, 0, 0 );
620
- foreach ( $images as &$image ) {
621
- $image->Id = null;
622
- $image->gid = $id;
623
- }
624
- $this->FinalTilesdb->addImages( $id, $images );
625
- }
626
-
627
- return array();
628
- }
629
-
630
- //Add gallery scripts
631
- public function add_gallery_scripts()
632
- {
633
- wp_enqueue_script( 'jquery' );
634
- wp_register_script(
635
- 'finalTilesGallery',
636
- plugins_url( 'scripts/jquery.finalTilesGallery.js', __FILE__ ),
637
- array( 'jquery' ),
638
- FTGVERSION,
639
- true
640
- );
641
- wp_enqueue_script( 'finalTilesGallery' );
642
- wp_register_style(
643
- 'finalTilesGallery_stylesheet',
644
- plugins_url( 'scripts/ftg.css', __FILE__ ),
645
- array(),
646
- FTGVERSION
647
- );
648
- wp_enqueue_style( 'finalTilesGallery_stylesheet' );
649
- wp_register_script( 'lightbox2_script', plugins_url( 'lightbox/lightbox2/js/script.js', __FILE__ ), array( 'jquery' ) );
650
- wp_register_style( 'lightbox2_stylesheet', plugins_url( 'lightbox/lightbox2/css/style.css', __FILE__ ) );
651
- wp_register_style( 'fontawesome_stylesheet', '//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css' );
652
- wp_enqueue_style( 'fontawesome_stylesheet' );
653
- }
654
-
655
- //Admin Section - register scripts and styles
656
- public function gallery_admin_init()
657
- {
658
- if ( function_exists( 'wp_enqueue_media' ) ) {
659
- wp_enqueue_media();
660
- }
661
- $ftg_db_version = '20190518';
662
- $installed_ver = get_option( "FinalTiles_gallery_db_version" );
663
- if ( !$installed_ver || empty($installed_ver) ) {
664
- update_option( "FinalTiles_gallery_db_version", $ftg_db_version );
665
- }
666
-
667
- if ( $installed_ver != $ftg_db_version ) {
668
- activate_finaltilesgallery();
669
- update_option( "FinalTiles_gallery_db_version", $ftg_db_version );
670
- }
671
-
672
- function ftg_get_image_sizes()
673
- {
674
- global $_wp_additional_image_sizes ;
675
- $sizes = array();
676
- foreach ( get_intermediate_image_sizes() as $_size ) {
677
-
678
- if ( in_array( $_size, array(
679
- 'thumbnail',
680
- 'medium',
681
- 'medium_large',
682
- 'large'
683
- ) ) ) {
684
- $sizes[$_size]['width'] = get_option( "{$_size}_size_w" );
685
- $sizes[$_size]['height'] = get_option( "{$_size}_size_h" );
686
- $sizes[$_size]['crop'] = (bool) get_option( "{$_size}_crop" );
687
- } elseif ( isset( $_wp_additional_image_sizes[$_size] ) ) {
688
- $sizes[$_size] = array(
689
- 'width' => $_wp_additional_image_sizes[$_size]['width'],
690
- 'height' => $_wp_additional_image_sizes[$_size]['height'],
691
- 'crop' => $_wp_additional_image_sizes[$_size]['crop'],
692
- );
693
- }
694
-
695
- }
696
- return $sizes;
697
- }
698
-
699
- foreach ( ftg_get_image_sizes() as $name => $size ) {
700
- $this->fields["Links & Lightbox"]["fields"]["lightboxImageSize"]["values"]["Size"][] = $name . "|" . $name . " (" . $size['width'] . 'x' . $size['height'] . (( $size['crop'] ? ' cropped)' : ')' ));
701
- }
702
- $this->fields["Links & Lightbox"]["fields"]["lightboxImageSize"]["values"]["Size"][] = "full|Original (full)";
703
- wp_enqueue_script( 'jquery' );
704
- wp_enqueue_script( 'jquery-ui-dialog' );
705
- wp_enqueue_script( 'jquery-ui-sortable' );
706
- wp_enqueue_script( 'wp-color-picker' );
707
- wp_enqueue_style( 'wp-color-picker' );
708
- wp_enqueue_script( 'media-upload' );
709
- wp_enqueue_script( 'thickbox' );
710
- wp_register_style( 'google-fonts', '//fonts.googleapis.com/css?family=Roboto:400,700,500,300,900' );
711
- wp_enqueue_style( 'google-fonts' );
712
- wp_register_style( 'google-icons', '//cdn.materialdesignicons.com/1.9.32/css/materialdesignicons.min.css', array() );
713
- wp_enqueue_style( 'google-icons' );
714
- wp_register_style( 'final-tiles-gallery-admin', plugins_url( 'admin/css/style.css', __FILE__ ), array( 'colors' ) );
715
- wp_enqueue_style( 'final-tiles-gallery-admin' );
716
- wp_register_script( 'materialize', plugins_url( 'admin/scripts/materialize.min.js', __FILE__ ), array( 'jquery' ) );
717
- wp_enqueue_script( 'materialize' );
718
- wp_register_script( 'final-tiles-gallery', plugins_url( 'admin/scripts/final-tiles-gallery-admin.js', __FILE__ ), array(
719
- 'jquery',
720
- 'media-upload',
721
- 'thickbox',
722
- 'materialize'
723
- ) );
724
- wp_enqueue_script( 'final-tiles-gallery' );
725
- wp_enqueue_style( 'thickbox' );
726
- wp_register_style( 'fontawesome_stylesheet', '//netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.css' );
727
- wp_enqueue_style( 'fontawesome_stylesheet' );
728
- }
729
-
730
- //Create Admin Menu
731
- public function add_gallery_admin_menu()
732
- {
733
- $overview = add_menu_page(
734
- 'Final Tiles Gallery',
735
- 'Final Tiles Gallery',
736
- 'edit_posts',
737
- 'ftg-lite-gallery-admin',
738
- array( $this, 'add_overview' ),
739
- plugins_url( 'admin/icon.png', __FILE__ )
740
- );
741
- $add_gallery = add_submenu_page(
742
- 'ftg-lite-gallery-admin',
743
- esc_html__( 'FinalTiles Gallery >> Add Gallery', 'final-tiles-grid-gallery-lite' ),
744
- esc_html__( 'Add Gallery', 'final-tiles-grid-gallery-lite' ),
745
- 'edit_posts',
746
- 'ftg-add-gallery',
747
- array( $this, 'add_gallery' )
748
- );
749
- add_action( 'load-' . $overview, array( $this, 'gallery_admin_init' ) );
750
- add_action( 'load-' . $add_gallery, array( $this, 'gallery_admin_init' ) );
751
- /*if(! class_exists("PhotoBlocks"))
752
- {
753
- $photoblocks = add_submenu_page('ftg-lite-gallery-admin', __('FinalTiles Gallery >> PhotoBlocks', 'FinalTiles-gallery'), __('PhotoBlocks', 'FinalTiles-gallery'), 'edit_posts', 'ftg-photoblocks', array($this, 'photoblocks'));
754
- add_action('load-' . $photoblocks, array($this, 'gallery_admin_init'));
755
- }
756
-
757
- if(! class_exists("EverlightBox"))
758
- {
759
- $everlightbox = add_submenu_page('ftg-lite-gallery-admin', __('FinalTiles Gallery >> EverlightBox', 'FinalTiles-gallery'), __('EverlightBox', 'FinalTiles-gallery'), 'edit_posts', 'ftg-everlightbox', array($this, 'everlightbox'));
760
- add_action('load-' . $everlightbox, array($this, 'gallery_admin_init'));
761
- }*/
762
- }
763
-
764
- //Create Admin Pages
765
- public function add_overview()
766
- {
767
- global $ftg_fields ;
768
- $ftg_fields = $this->fields;
769
- global $ftg_parent_page ;
770
- $ftg_parent_page = "dashboard";
771
-
772
- if ( array_key_exists( "id", $_GET ) ) {
773
- $woocommerce_post_types = array(
774
- "product",
775
- "product_variation",
776
- "shop_order",
777
- "shop_order_refund",
778
- "shop_coupon",
779
- "shop_webhook"
780
- );
781
- $wp_post_types = array( "revision", "nav_menu_item" );
782
- $excluded_post_types = array_merge( $wp_post_types, $woocommerce_post_types );
783
- $woo_categories = $this->getWooCategories();
784
- include "admin/edit-gallery.php";
785
- } else {
786
- include "admin/overview.php";
787
- }
788
-
789
- }
790
-
791
- public function tutorial()
792
- {
793
- include "admin/tutorial.php";
794
- }
795
-
796
- public function support()
797
- {
798
- include "admin/support.php";
799
- }
800
-
801
- public function photoblocks()
802
- {
803
- include "admin/photoblocks.php";
804
- }
805
-
806
- public function everlightbox()
807
- {
808
- include "admin/everlightbox.php";
809
- }
810
-
811
- private function getWooCategories()
812
- {
813
-
814
- if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
815
- $taxonomy = 'product_cat';
816
- $orderby = 'name';
817
- $show_count = 0;
818
- // 1 for yes, 0 for no
819
- $pad_counts = 0;
820
- // 1 for yes, 0 for no
821
- $hierarchical = 1;
822
- // 1 for yes, 0 for no
823
- $title = '';
824
- $empty = 0;
825
- $args = array(
826
- 'taxonomy' => $taxonomy,
827
- 'orderby' => $orderby,
828
- 'show_count' => $show_count,
829
- 'pad_counts' => $pad_counts,
830
- 'hierarchical' => $hierarchical,
831
- 'title_li' => $title,
832
- 'hide_empty' => $empty,
833
- );
834
- return get_categories( $args );
835
- } else {
836
- return array();
837
- }
838
-
839
- }
840
-
841
- public function add_gallery()
842
- {
843
- global $ftg_fields ;
844
- $ftg_fields = $this->fields;
845
- $gallery = null;
846
- $woocommerce_post_types = array(
847
- "product",
848
- "product_variation",
849
- "shop_order",
850
- "shop_order_refund",
851
- "shop_coupon",
852
- "shop_webhook"
853
- );
854
- $wp_post_types = array( "revision", "nav_menu_item" );
855
- $excluded_post_types = array_merge( $wp_post_types, $woocommerce_post_types );
856
- $woo_categories = $this->getWooCategories();
857
- include "admin/add-gallery.php";
858
- }
859
-
860
- public function delete_image()
861
- {
862
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
863
- foreach ( explode( ",", $_POST["id"] ) as $id ) {
864
- $this->FinalTilesdb->deleteImage( intval( $id ) );
865
- }
866
- }
867
- wp_die();
868
- }
869
-
870
- public function assign_filters()
871
- {
872
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
873
-
874
- if ( $_POST['source'] == 'posts' ) {
875
- foreach ( explode( ",", $_POST["id"] ) as $id ) {
876
- update_post_meta( intval( $id ), 'ftg_filters', sanitize_text_field( $_POST['filters'] ) );
877
- }
878
- } else {
879
- foreach ( explode( ",", $_POST["id"] ) as $id ) {
880
- $result = $this->FinalTilesdb->editImage( $id, array(
881
- "filters" => sanitize_text_field( $_POST["filters"] ),
882
- ) );
883
- }
884
- }
885
-
886
- }
887
- wp_die();
888
- }
889
-
890
- public function toggle_visibility()
891
- {
892
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
893
- foreach ( explode( ",", $_POST["id"] ) as $id ) {
894
- $image = $this->FinalTilesdb->getImage( $id );
895
- $this->FinalTilesdb->editImage( $id, array(
896
- "hidden" => ( $image->hidden == 'T' ? 'F' : 'T' ),
897
- ) );
898
- }
899
- }
900
- wp_die();
901
- }
902
-
903
- public function assign_group()
904
- {
905
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
906
-
907
- if ( $_POST['source'] == 'posts' ) {
908
- foreach ( explode( ",", $_POST["id"] ) as $id ) {
909
- update_post_meta( intval( $id ), 'ftg_group', sanitize_text_field( $_POST['group'] ) );
910
- }
911
- } else {
912
- foreach ( explode( ",", $_POST["id"] ) as $id ) {
913
- $result = $this->FinalTilesdb->editImage( $id, array(
914
- "group" => sanitize_text_field( $_POST["group"] ),
915
- ) );
916
- }
917
- }
918
-
919
- }
920
- wp_die();
921
- }
922
-
923
- public function add_image()
924
- {
925
-
926
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
927
- $gid = intval( $_POST['galleryId'] );
928
- $enc_images = stripslashes( $_POST["enc_images"] );
929
- $images = json_decode( $enc_images );
930
- $result = $this->FinalTilesdb->addImages( $gid, $images );
931
- header( "Content-type: application/json" );
932
-
933
- if ( $result === false ) {
934
- echo "{\"success\":false}" ;
935
- } else {
936
- echo "{\"success\":true}" ;
937
- }
938
-
939
- }
940
-
941
- wp_die();
942
- }
943
-
944
- public function list_thumbnail_sizes()
945
- {
946
- global $_wp_additional_image_sizes ;
947
- $sizes = array();
948
- foreach ( get_intermediate_image_sizes() as $s ) {
949
-
950
- if ( in_array( $s, array( 'thumbnail', 'medium', 'large' ) ) ) {
951
- $sizes[$s][0] = get_option( $s . '_size_w' );
952
- $sizes[$s][1] = get_option( $s . '_size_h' );
953
- } else {
954
- if ( isset( $_wp_additional_image_sizes ) && isset( $_wp_additional_image_sizes[$s] ) && $_wp_additional_image_sizes[$s]['width'] > 0 && $_wp_additional_image_sizes[$s]['height'] > 0 ) {
955
- $sizes[$s] = array( $_wp_additional_image_sizes[$s]['width'], $_wp_additional_image_sizes[$s]['height'] );
956
- }
957
- }
958
-
959
- }
960
- return $sizes;
961
- }
962
-
963
- public function sort_images()
964
- {
965
-
966
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
967
- $result = $this->FinalTilesdb->sortImages( explode( ',', $_POST['ids'] ) );
968
- header( "Content-type: application/json" );
969
-
970
- if ( $result === false ) {
971
- echo "{\"success\":false}" ;
972
- } else {
973
- echo "{\"success\":true}" ;
974
- }
975
-
976
- }
977
-
978
- wp_die();
979
- }
980
-
981
- public function load_chunk()
982
- {
983
- require_once 'lib/gallery-class.php';
984
-
985
- if ( check_admin_referer( 'finaltilesgallery', 'finaltilesgallery' ) ) {
986
- $gid = intval( $_POST["gallery"] );
987
- $images = $this->FinalTilesdb->getImagesByGalleryId( $gid, 0, 0 );
988
- $FinalTilesGallery = new FinalTilesGallery( $gid, $this->FinalTilesdb, $this->defaultValues );
989
- echo $FinalTilesGallery->images_markup() ;
990
- }
991
-
992
- wp_die();
993
- }
994
-
995
- public function refresh_gallery()
996
- {
997
- if ( $_POST['source'] == 'images' ) {
998
- $this->list_images();
999
- }
1000
- }
1001
-
1002
- public function save_image()
1003
- {
1004
-
1005
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
1006
- $result = false;
1007
-
1008
- if ( $_POST['source'] == 'posts' ) {
1009
- $result = true;
1010
- $postId = intval( $_POST['post_id'] );
1011
- $img_url = stripslashes( $_POST['img_url'] );
1012
- update_post_meta( $postId, 'ftg_image_url', esc_url_raw( $img_url ) );
1013
- if ( array_key_exists( "filters", $_POST ) && strlen( $_POST['filters'] ) ) {
1014
- update_post_meta( $postId, 'ftg_filters', sanitize_text_field( $_POST['filters'] ) );
1015
- }
1016
- } else {
1017
- $type = sanitize_text_field( $_POST['type'] );
1018
- $imageUrl = stripslashes( $_POST['img_url'] );
1019
- $imageCaption = wp_kses_post( $_POST['description'] );
1020
- $filters = stripslashes( $_POST['filters'] );
1021
- $title = wp_kses_post( $_POST['imageTitle'] );
1022
- $target = sanitize_text_field( $_POST['target'] );
1023
- $group = sanitize_text_field( $_POST['group'] );
1024
- $alt = sanitize_text_field( $_POST['alt'] );
1025
- $hidden = $this->checkboxVal( 'hidden' );
1026
- $link = ( isset( $_POST['link'] ) ? stripslashes( $_POST['link'] ) : null );
1027
- $imageId = intval( $_POST['img_id'] );
1028
- $sortOrder = intval( $_POST['sortOrder'] );
1029
- $data = array(
1030
- "imagePath" => $imageUrl,
1031
- "target" => $target,
1032
- "link" => $link,
1033
- "imageId" => $imageId,
1034
- "description" => $imageCaption,
1035
- "filters" => $filters,
1036
- "title" => $title,
1037
- "group" => $group,
1038
- "alt" => $alt,
1039
- "hidden" => $hidden,
1040
- "sortOrder" => $sortOrder,
1041
- );
1042
-
1043
- if ( !empty($_POST["id"]) ) {
1044
- $imageId = intval( $_POST['id'] );
1045
- $result = $this->FinalTilesdb->editImage( $imageId, $data );
1046
- } else {
1047
- $data["gid"] = intval( $_POST['galleryId'] );
1048
- $result = $this->FinalTilesdb->addFullImage( $data );
1049
- }
1050
-
1051
- }
1052
-
1053
- header( "Content-type: application/json" );
1054
-
1055
- if ( $result === false ) {
1056
- echo "{\"success\":false}" ;
1057
- } else {
1058
- echo "{\"success\":true}" ;
1059
- }
1060
-
1061
- }
1062
-
1063
- wp_die();
1064
- }
1065
-
1066
- public function save_video()
1067
- {
1068
-
1069
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
1070
- $result = false;
1071
- $type = ( isset( $_POST['type'] ) ? $_POST['type'] : "" );
1072
- $data = array(
1073
- "imagePath" => stripslashes( $_POST["embed"] ),
1074
- "filters" => sanitize_text_field( $_POST['filters'] ),
1075
- "gid" => intval( $_POST['galleryId'] ),
1076
- );
1077
- $id = ( isset( $_POST['id'] ) ? intval( $_POST['id'] ) : "" );
1078
- $step = ( isset( $_POST['step'] ) ? $_POST['step'] : "" );
1079
- if ( !empty($step) ) {
1080
-
1081
- if ( $step == "add" ) {
1082
- $result = $this->FinalTilesdb->addVideo( $data );
1083
- } else {
1084
- if ( $step == "edit" ) {
1085
- $result = $this->FinalTilesdb->editVideo( $id, $data );
1086
- }
1087
- }
1088
-
1089
- }
1090
- header( "Content-type: application/json" );
1091
-
1092
- if ( $result === false ) {
1093
- echo "{\"success\":false}" ;
1094
- } else {
1095
- echo "{\"success\":true}" ;
1096
- }
1097
-
1098
- }
1099
-
1100
- wp_die();
1101
- }
1102
-
1103
- public function list_images()
1104
- {
1105
-
1106
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
1107
- $gid = intval( $_POST["gid"] );
1108
- $imageResults = $this->FinalTilesdb->getImagesByGalleryId( $gid, 0, 0 );
1109
- $gallery = $this->FinalTilesdb->getGalleryById( $gid );
1110
- $list_size = "medium";
1111
- $column_size = "s6 m3 l3";
1112
- if ( isset( $_POST['list_size'] ) && !empty($_POST['list_size']) ) {
1113
- $list_size = $_POST['list_size'];
1114
- }
1115
- setcookie( 'ftg_imglist_size', $list_size );
1116
- $_COOKIE['ftg_imglist_size'] = $list_size;
1117
- if ( $list_size == 'small' ) {
1118
- $column_size = 's4 m2 l2';
1119
- }
1120
- if ( $list_size == 'medium' ) {
1121
- $column_size = 's6 m3 l3';
1122
- }
1123
- if ( $list_size == 'big' ) {
1124
- $column_size = 's12 m4 l4';
1125
- }
1126
- include 'admin/include/image-list.php';
1127
- }
1128
-
1129
- wp_die();
1130
- }
1131
-
1132
- public function add_new_gallery()
1133
- {
1134
-
1135
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
1136
- $data = $this->defaultValues;
1137
- $data["name"] = wp_filter_post_kses( $_POST['ftg_name'] );
1138
- $data["description"] = wp_filter_post_kses( $_POST['ftg_description'] );
1139
- $data["source"] = sanitize_text_field( $_POST['ftg_source'] );
1140
- $data["wp_field_caption"] = sanitize_text_field( $_POST['ftg_wp_field_caption'] );
1141
- $data["wp_field_title"] = sanitize_text_field( $_POST['ftg_wp_field_title'] );
1142
- $data["captionEffect"] = sanitize_text_field( $_POST['ftg_captionEffect'] );
1143
- $data["post_types"] = sanitize_text_field( $_POST["post_types"] );
1144
- $data["layout"] = sanitize_text_field( $_POST["layout"] );
1145
- $data["defaultWooImageSize"] = sanitize_text_field( $_POST['def_imgsize'] );
1146
- $data["defaultPostImageSize"] = sanitize_text_field( $_POST['def_imgsize'] );
1147
- $data["woo_categories"] = sanitize_text_field( $_POST["woo_categories"] );
1148
- $result = $this->FinalTilesdb->addGallery( $data );
1149
- $id = $this->FinalTilesdb->getNewGalleryId();
1150
-
1151
- if ( $id > 0 && array_key_exists( 'enc_images', $_POST ) && strlen( $_POST['enc_images'] ) ) {
1152
- $enc_images = stripslashes( $_POST["enc_images"] );
1153
- $images = json_decode( $enc_images );
1154
- $result = $this->FinalTilesdb->addImages( $id, $images );
1155
- }
1156
-
1157
- echo $id ;
1158
- } else {
1159
- echo -1 ;
1160
- }
1161
-
1162
- wp_die();
1163
- }
1164
-
1165
- private function checkboxVal( $field )
1166
- {
1167
- if ( isset( $_POST[$field] ) ) {
1168
- return 'T';
1169
- }
1170
- return 'F';
1171
- }
1172
-
1173
- public function save_gallery()
1174
- {
1175
-
1176
- if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
1177
- $galleryName = stripslashes( $_POST['ftg_name'] );
1178
- $galleryDescription = stripslashes( $_POST['ftg_description'] );
1179
- $slug = strtolower( str_replace( " ", "", $galleryName ) );
1180
- $margin = intval( $_POST['ftg_margin'] );
1181
- $minTileWidth = intval( $_POST['ftg_minTileWidth'] );
1182
- $gridCellSize = intval( $_POST['ftg_gridCellSize'] );
1183
- $imagesOrder = sanitize_text_field( $_POST['ftg_imagesOrder'] );
1184
- $width = sanitize_text_field( $_POST['ftg_width'] );
1185
- $enableTwitter = $this->checkboxVal( 'ftg_enableTwitter' );
1186
- $filterClick = $this->checkboxVal( 'ftg_filterClick' );
1187
- $enableFacebook = $this->checkboxVal( 'ftg_enableFacebook' );
1188
- $enableGplus = $this->checkboxVal( 'ftg_enableGplus' );
1189
- $enablePinterest = $this->checkboxVal( 'ftg_enablePinterest' );
1190
- $lightbox = sanitize_text_field( $_POST['ftg_lightbox'] );
1191
- $mobileLightbox = sanitize_text_field( $_POST['ftg_mobileLightbox'] );
1192
- $blank = $this->checkboxVal( 'ftg_blank' );
1193
- $filters = sanitize_text_field( $_POST['ftg_filters'] );
1194
- $scrollEffect = $_POST['ftg_scrollEffect'];
1195
- $captionBehavior = sanitize_text_field( $_POST['ftg_captionBehavior'] );
1196
- $captionMobileBehavior = sanitize_text_field( $_POST['ftg_captionMobileBehavior'] );
1197
- $captionEffect = sanitize_text_field( $_POST['ftg_captionEffect'] );
1198
- $captionColor = sanitize_hex_color( $_POST['ftg_captionColor'] );
1199
- $captionBackgroundColor = sanitize_hex_color( $_POST['ftg_captionBackgroundColor'] );
1200
- $captionEasing = sanitize_text_field( $_POST['ftg_captionEasing'] );
1201
- $captionHorizontalAlignment = sanitize_text_field( $_POST['ftg_captionHorizontalAlignment'] );
1202
- $captionVerticalAlignment = sanitize_text_field( $_POST['ftg_captionVerticalAlignment'] );
1203
- $captionEmpty = sanitize_text_field( $_POST['ftg_captionEmpty'] );
1204
- $captionOpacity = intval( $_POST['ftg_captionOpacity'] );
1205
- $borderSize = intval( $_POST['ftg_borderSize'] );
1206
- $borderColor = sanitize_hex_color( $_POST['ftg_borderColor'] );
1207
- $titleFontSize = intval( $_POST['ftg_titleFontSize'] );
1208
- $loadingBarColor = sanitize_hex_color( $_POST['ftg_loadingBarColor'] );
1209
- $loadingBarBackgroundColor = sanitize_hex_color( $_POST['ftg_loadingBarBackgroundColor'] );
1210
- $borderRadius = intval( $_POST['ftg_borderRadius'] );
1211
- $allFilterLabel = sanitize_text_field( $_POST['ftg_allFilterLabel'] );
1212
- $shadowColor = sanitize_hex_color( $_POST['ftg_shadowColor'] );
1213
- $shadowSize = intval( $_POST['ftg_shadowSize'] );
1214
- $enlargeImages = $this->checkboxVal( 'ftg_enlargeImages' );
1215
- $wp_field_caption = sanitize_text_field( $_POST['ftg_wp_field_caption'] );
1216
- $wp_field_title = sanitize_text_field( $_POST['ftg_wp_field_title'] );
1217
- $style = $_POST['ftg_style'];
1218
- $script = $_POST['ftg_script'];
1219
- $loadedHSlide = intval( $_POST['ftg_loadedHSlide'] );
1220
- $loadedVSlide = intval( $_POST['ftg_loadedVSlide'] );
1221
- $captionEffectDuration = intval( $_POST['ftg_captionEffectDuration'] );
1222
- $id = ( isset( $_POST['ftg_gallery_edit'] ) ? intval( $_POST['ftg_gallery_edit'] ) : 0 );
1223
- $data = array(
1224
- 'ajaxLoading' => sanitize_text_field( $_POST['ftg_ajaxLoading'] ),
1225
- 'layout' => sanitize_text_field( $_POST['ftg_layout'] ),
1226
- 'name' => $galleryName,
1227
- 'slug' => $slug,
1228
- 'description' => $galleryDescription,
1229
- 'lightbox' => $lightbox,
1230
- 'lightboxOptions' => sanitize_text_field( $_POST['ftg_lightboxOptions'] ),
1231
- 'lightboxOptionsMobile' => sanitize_text_field( $_POST['lightboxOptionsMobile'] ),
1232
- 'mobileLightbox' => $mobileLightbox,
1233
- 'lightboxImageSize' => sanitize_text_field( $_POST['ftg_lightboxImageSize'] ),
1234
- 'blank' => $blank,
1235
- 'margin' => $margin,
1236
- 'allFilterLabel' => $allFilterLabel,
1237
- 'minTileWidth' => $minTileWidth,
1238
- 'gridCellSize' => $gridCellSize,
1239
- 'gridCellSizeDisabledBelow' => intval( $_POST['ftg_gridCellSizeDisabledBelow'] ),
1240
- 'enableTwitter' => $enableTwitter,
1241
- 'backgroundColor' => sanitize_hex_color( $_POST['ftg_backgroundColor'] ),
1242
- 'filterClick' => $filterClick,
1243
- 'disableLightboxGroups' => $this->checkboxVal( 'ftg_disableLightboxGroups' ),
1244
- 'defaultFilter' => sanitize_text_field( $_POST['ftg_filterDef'] ),
1245
- 'enableFacebook' => $enableFacebook,
1246
- 'enableGplus' => $enableGplus,
1247
- 'enablePinterest' => $enablePinterest,
1248
- 'imagesOrder' => $imagesOrder,
1249
- 'compressHTML' => $this->checkboxVal( 'ftg_compressHTML' ),
1250
- 'loadMethod' => sanitize_text_field( $_POST['ftg_loadMethod'] ),
1251
- 'socialIconColor' => sanitize_hex_color( $_POST['ftg_socialIconColor'] ),
1252
- 'socialIconPosition' => sanitize_text_field( $_POST['ftg_socialIconPosition'] ),
1253
- 'socialIconStyle' => sanitize_text_field( $_POST['ftg_socialIconStyle'] ),
1254
- 'recentPostsCaption' => sanitize_text_field( $_POST['ftg_recentPostsCaption'] ),
1255
- 'recentPostsCaptionAutoExcerptLength' => intval( $_POST['ftg_recentPostsCaptionAutoExcerptLength'] ),
1256
- 'captionBehavior' => $captionBehavior,
1257
- 'captionEffect' => $captionEffect,
1258
- 'captionEmpty' => $captionEmpty,
1259
- 'captionBackgroundColor' => $captionBackgroundColor,
1260
- 'captionColor' => $captionColor,
1261
- 'captionCustomFields' => wp_kses_post( $_POST['ftg_captionCustomFields'] ),
1262
- 'captionFrameColor' => sanitize_hex_color( $_POST['ftg_captionFrameColor'] ),
1263
- 'captionEffectDuration' => $captionEffectDuration,
1264
- 'captionEasing' => $captionEasing,
1265
- 'captionVerticalAlignment' => $captionVerticalAlignment,
1266
- 'captionHorizontalAlignment' => $captionHorizontalAlignment,
1267
- 'captionMobileBehavior' => $captionMobileBehavior,
1268
- 'captionOpacity' => $captionOpacity,
1269
- 'captionIcon' => sanitize_text_field( $_POST['ftg_captionIcon'] ),
1270
- 'captionFrame' => $this->checkboxVal( 'ftg_captionFrame' ),
1271
- 'customCaptionIcon' => sanitize_text_field( $_POST['ftg_customCaptionIcon'] ),
1272
- 'captionIconColor' => sanitize_hex_color( $_POST['ftg_captionIconColor'] ),
1273
- 'captionIconSize' => intval( $_POST['ftg_captionIconSize'] ),
1274
- 'captionFontSize' => intval( $_POST['ftg_captionFontSize'] ),
1275
- 'captionPosition' => sanitize_text_field( $_POST['ftg_captionPosition'] ),
1276
- 'titleFontSize' => intval( $_POST['ftg_titleFontSize'] ),
1277
- 'hoverZoom' => intval( $_POST['ftg_hoverZoom'] ),
1278
- 'hoverRotation' => intval( $_POST['ftg_hoverRotation'] ),
1279
- 'hoverDuration' => intval( $_POST['ftg_hoverDuration'] ),
1280
- 'hoverIconRotation' => $this->checkboxVal( 'ftg_hoverIconRotation' ),
1281
- 'filters' => $filters,
1282
- 'wp_field_caption' => $wp_field_caption,
1283
- 'wp_field_title' => $wp_field_title,
1284
- 'borderSize' => $borderSize,
1285
- 'borderColor' => $borderColor,
1286
- 'loadingBarColor' => $loadingBarColor,
1287
- 'loadingBarBackgroundColor' => $loadingBarBackgroundColor,
1288
- 'enlargeImages' => $enlargeImages,
1289
- 'borderRadius' => $borderRadius,
1290
- 'imageSizeFactor' => intval( $_POST['ftg_imageSizeFactor'] ),
1291
- 'imageSizeFactorTabletLandscape' => intval( $_POST['ftg_imageSizeFactorTabletLandscape'] ),
1292
- 'imageSizeFactorTabletPortrait' => intval( $_POST['ftg_imageSizeFactorTabletPortrait'] ),
1293
- 'imageSizeFactorPhoneLandscape' => intval( $_POST['ftg_imageSizeFactorPhoneLandscape'] ),
1294
- 'imageSizeFactorPhonePortrait' => intval( $_POST['ftg_imageSizeFactorPhonePortrait'] ),
1295
- 'imageSizeFactorCustom' => sanitize_text_field( $_POST['ftg_imageSizeFactorCustom'] ),
1296
- 'taxonomyAsFilter' => sanitize_text_field( $_POST['ftg_taxonomyAsFilter'] ),
1297
- 'columns' => intval( $_POST['ftg_columns'] ),
1298
- 'columnsTabletLandscape' => intval( $_POST['ftg_columnsTabletLandscape'] ),
1299
- 'columnsTabletPortrait' => intval( $_POST['ftg_columnsTabletPortrait'] ),
1300
- 'columnsPhoneLandscape' => intval( $_POST['ftg_columnsPhoneLandscape'] ),
1301
- 'columnsPhonePortrait' => intval( $_POST['ftg_columnsPhonePortrait'] ),
1302
- 'max_posts' => intval( $_POST['ftg_max_posts'] ),
1303
- 'shadowSize' => $shadowSize,
1304
- 'shadowColor' => $shadowColor,
1305
- 'source' => sanitize_text_field( $_POST['ftg_source'] ),
1306
- 'post_types' => sanitize_text_field( $_POST['ftg_post_types'] ),
1307
- 'post_taxonomies' => sanitize_text_field( $_POST['ftg_post_taxonomies'] ),
1308
- 'taxonomyOperator' => sanitize_text_field( $_POST['ftg_taxonomyOperator'] ),
1309
- 'post_tags' => sanitize_text_field( $_POST['ftg_post_tags'] ),
1310
- 'tilesPerPage' => intval( $_POST['ftg_tilesPerPage'] ),
1311
- 'woo_categories' => ( isset( $_POST['ftg_woo_categories'] ) ? $_POST['ftg_woo_categories'] : '' ),
1312
- 'defaultPostImageSize' => sanitize_text_field( $_POST['ftg_defaultPostImageSize'] ),
1313
- 'defaultWooImageSize' => ( isset( $_POST['ftg_defaultWooImageSize'] ) ? $_POST['ftg_defaultWooImageSize'] : '' ),
1314
- 'width' => $width,
1315
- 'beforeGalleryText' => wp_kses_post( $_POST['ftg_beforeGalleryText'] ),
1316
- 'afterGalleryText' => wp_kses_post( $_POST['ftg_afterGalleryText'] ),
1317
- 'aClass' => sanitize_text_field( $_POST['ftg_aClass'] ),
1318
- 'rel' => sanitize_text_field( $_POST['ftg_rel'] ),
1319
- 'style' => $style,
1320
- 'delay' => intval( $_POST['ftg_delay'] ),
1321
- 'script' => $script,
1322
- 'support' => $this->checkboxVal( 'ftg_support' ),
1323
- 'supportText' => sanitize_text_field( $_POST['ftg_supportText'] ),
1324
- 'scrollEffect' => $scrollEffect,
1325
- 'loadedScaleY' => intval( $_POST['ftg_loadedScaleY'] ),
1326
- 'loadedScaleX' => intval( $_POST['ftg_loadedScaleX'] ),
1327
- 'loadedHSlide' => $loadedHSlide,
1328
- 'loadedVSlide' => $loadedVSlide,
1329
- 'loadedEasing' => sanitize_text_field( $_POST['ftg_loadedEasing'] ),
1330
- 'loadedDuration' => absint( $_POST['ftg_loadedDuration'] ),
1331
- 'loadedRotateY' => intval( $_POST['ftg_loadedRotateY'] ),
1332
- 'loadedRotateX' => intval( $_POST['ftg_loadedRotateX'] ),
1333
- );
1334
- header( "Content-type: application/json" );
1335
-
1336
- if ( $id > 0 ) {
1337
- $result = $this->FinalTilesdb->editGallery( $id, $data );
1338
- } else {
1339
- $result = $this->FinalTilesdb->addGallery( $data );
1340
- $id = $this->FinalTilesdb->getNewGalleryId();
1341
- }
1342
-
1343
-
1344
- if ( $result ) {
1345
- echo "{\"success\":true,\"id\":" . $id . "}" ;
1346
- } else {
1347
- echo "{\"success\":false}" ;
1348
- }
1349
-
1350
- }
1351
-
1352
- wp_die();
1353
- }
1354
-
1355
- public static function get_image_size_links( $id )
1356
- {
1357
- $result = array();
1358
- $sizes = get_intermediate_image_sizes();
1359
- $sizes[] = 'full';
1360
- foreach ( $sizes as $size ) {
1361
- $image = wp_get_attachment_image_src( $id, $size );
1362
- if ( !empty($image) && (true == $image[3] || 'full' == $size) ) {
1363
- $result["{$image[1]}x{$image[2]}"] = $image[0];
1364
- }
1365
- }
1366
- ksort( $result );
1367
- return $result;
1368
- }
1369
-
1370
- //Create gallery
1371
- public function create_gallery( $attrs )
1372
- {
1373
- require_once 'lib/gallery-class.php';
1374
- global $FinalTilesGallery ;
1375
- $galleryId = $attrs['id'];
1376
-
1377
- if ( class_exists( 'FinalTilesGallery' ) ) {
1378
- $FinalTilesGallery = new FinalTilesGallery(
1379
- $galleryId,
1380
- $this->FinalTilesdb,
1381
- $this->defaultValues,
1382
- $attrs
1383
- );
1384
- $settings = $FinalTilesGallery->getGallery();
1385
-
1386
- if ( $settings != null ) {
1387
- switch ( $settings->lightbox ) {
1388
- case "magnific":
1389
- wp_enqueue_style( 'magnific_stylesheet' );
1390
- wp_enqueue_script( 'magnific_script' );
1391
- break;
1392
- case "prettyphoto":
1393
- wp_enqueue_style( 'prettyphoto_stylesheet' );
1394
- wp_enqueue_script( 'prettyphoto_script' );
1395
- break;
1396
- case "fancybox":
1397
- wp_enqueue_style( 'fancybox_stylesheet' );
1398
- wp_enqueue_script( 'fancybox_script' );
1399
- break;
1400
- case "colorbox":
1401
- wp_enqueue_style( 'colorbox_stylesheet' );
1402
- wp_enqueue_script( 'colorbox_script' );
1403
- break;
1404
- case "swipebox":
1405
- wp_enqueue_style( 'swipebox_stylesheet' );
1406
- wp_enqueue_script( 'swipebox_script' );
1407
- break;
1408
- case "lightbox2":
1409
- wp_enqueue_style( 'lightbox2_stylesheet' );
1410
- wp_enqueue_script( 'lightbox2_script' );
1411
- break;
1412
- case "image-lightbox":
1413
- wp_enqueue_script( 'image-lightbox_script' );
1414
- break;
1415
- case "lightgallery":
1416
- wp_enqueue_style( 'lightgallery_stylesheet' );
1417
- wp_enqueue_script( 'lightgallery_script' );
1418
- break;
1419
- }
1420
- switch ( $settings->mobileLightbox ) {
1421
- default:
1422
- case "magnific":
1423
- wp_enqueue_style( 'magnific_stylesheet' );
1424
- wp_enqueue_script( 'magnific_script' );
1425
- break;
1426
- case "prettyphoto":
1427
- wp_enqueue_style( 'prettyphoto_stylesheet' );
1428
- wp_enqueue_script( 'prettyphoto_script' );
1429
- break;
1430
- case "fancybox":
1431
- wp_enqueue_style( 'fancybox_stylesheet' );
1432
- wp_enqueue_script( 'fancybox_script' );
1433
- break;
1434
- case "colorbox":
1435
- wp_enqueue_style( 'colorbox_stylesheet' );
1436
- wp_enqueue_script( 'colorbox_script' );
1437
- break;
1438
- case "swipebox":
1439
- wp_enqueue_style( 'swipebox_stylesheet' );
1440
- wp_enqueue_script( 'swipebox_script' );
1441
- break;
1442
- case "lightbox2":
1443
- wp_enqueue_style( 'lightbox2_stylesheet' );
1444
- wp_enqueue_script( 'lightbox2_script' );
1445
- break;
1446
- case "image-lightbox":
1447
- wp_enqueue_script( 'image-lightbox_script' );
1448
- case "lightgallery":
1449
- wp_enqueue_style( 'lightgallery_stylesheet' );
1450
- wp_enqueue_script( 'lightgallery_script' );
1451
- break;
1452
- }
1453
- }
1454
-
1455
- return $FinalTilesGallery->render();
1456
- } else {
1457
- return "Gallery not found.";
1458
- }
1459
-
1460
- }
1461
-
1462
- //Create Short Code
1463
- private $photon_removed ;
1464
- public function gallery_shortcode_handler( $atts )
1465
- {
1466
- $this->photon_removed = '';
1467
- if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) {
1468
- $this->photon_removed = remove_filter( 'image_downsize', array( Jetpack_Photon::instance(), 'filter_image_downsize' ) );
1469
- }
1470
- return $this->create_gallery( $atts );
1471
- //@todo: statement can't be reached. Investigate
1472
- if ( $this->photon_removed ) {
1473
- add_filter(
1474
- 'image_downsize',
1475
- array( Jetpack_Photon::instance(), 'filter_image_downsize' ),
1476
- 10,
1477
- 3
1478
- );
1479
- }
1480
- }
1481
-
1482
- public static function slugify( $text )
1483
- {
1484
- $text = preg_replace( '~[^\\pL\\d]+~u', '-', $text );
1485
- $text = trim( $text, '-' );
1486
- if ( function_exists( "iconv" ) ) {
1487
- $text = iconv( 'utf-8', 'us-ascii//TRANSLIT', $text );
1488
- }
1489
- $text = strtolower( $text );
1490
- $text = preg_replace( '~[^-\\w]+~', '', $text );
1491
- if ( empty($text) ) {
1492
- return 'n-a';
1493
- }
1494
- return $text;
1495
- }
1496
-
1497
- public static function getFieldType( $field )
1498
- {
1499
- return "cta";
1500
- }
1501
-
1502
- var $fields = array() ;
1503
- private function addField( $section, $field, $data )
1504
- {
1505
- $this->fields[$section]["fields"][$field] = $data;
1506
- }
1507
-
1508
- private function setupFields()
1509
- {
1510
- include 'admin/include/fields.php';
1511
- }
1512
-
1513
- }
1514
- }
1515
- if ( !class_exists( "FinalTilesGalleryUtils" ) ) {
1516
- class FinalTilesGalleryUtils
1517
- {
1518
- public static function shortcodeToFieldName( $string, $capitalizeFirstCharacter = false )
1519
- {
1520
- $str = str_replace( '-', '\\t', $string );
1521
- $str = str_replace( '_', '', ucwords( $str ) );
1522
- $str = str_replace( '\\t', '_', $str );
1523
- if ( !$capitalizeFirstCharacter ) {
1524
- $str = lcfirst( $str );
1525
- }
1526
- return $str;
1527
- }
1528
-
1529
- public static function fieldNameToShortcode( $string )
1530
- {
1531
- preg_match_all( '!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $string, $matches );
1532
- $ret = $matches[0];
1533
- foreach ( $ret as &$match ) {
1534
- $match = ( $match == strtoupper( $match ) ? strtolower( $match ) : lcfirst( $match ) );
1535
- }
1536
- return implode( '_', $ret );
1537
- }
1538
-
1539
- }
1540
- }
1541
-
1542
- if ( class_exists( "FinalTiles_Gallery" ) ) {
1543
- global $ob_FinalTiles_Gallery ;
1544
- $ob_FinalTiles_Gallery = new FinalTiles_Gallery();
1545
- }
1546
-
1547
-
1548
- if ( !function_exists( "ftg_admin_script" ) ) {
1549
- function ftg_admin_script()
1550
- {
1551
- wp_register_script( 'admin-generic-ftg', plugins_url( 'admin/scripts/admin.js', __FILE__ ), array( 'jquery' ) );
1552
- wp_enqueue_script( 'admin-generic-ftg' );
1553
- }
1554
-
1555
- add_action( 'admin_enqueue_scripts', 'ftg_admin_script' );
1556
- }
1557
-
1558
  register_activation_hook( __FILE__, 'activate_finaltilesgallery' );
1
+ <?php
2
+
3
+ /**
4
+ * Plugin Name: Final Tiles Grid Gallery - Image Gallery
5
+ * Description: Wordpress Plugin for creating responsive image galleries.
6
+ * Version: 3.5.2
7
+ * Author: WPChill
8
+ * Author URI: https://wpchill.com
9
+ * Tested up to: 5.8
10
+ * Requires: 5.2 or higher
11
+ * License: GPLv3 or later
12
+ * License URI: http://www.gnu.org/licenses/gpl-3.0.html
13
+ * Requires PHP: 5.6
14
+ * Text Domain: final-tiles-grid-gallery-lite
15
+ * Domain Path: /languages
16
+ *
17
+ * Copyright 2015-2019 GreenTreeLabs diego@greentreelabs.net
18
+ * Copyright 2019-2020 MachoThemes office@machothemes.com
19
+ * SVN commit with proof of ownership transfer: https://plugins.trac.wordpress.org/changeset/2163481/
20
+ * NOTE: MachoThemes took ownership of this plugin on: 09/26/2019 08:49:37 AM as can be seen from the above SVN commit.
21
+ * Copyright 2020 WPChill heyyy@wpchill.com
22
+ *
23
+ * Original Plugin URI: https://greentreelabs.net/final-tiles-gallery-lite/
24
+ * Original Author URI: https://greentreelabs.net
25
+ * Original Author: https://profiles.wordpress.org/greentreealbs/
26
+ *
27
+ */
28
+ define( "FTGVERSION", "3.5.2" );
29
+ // Create a helper function for easy SDK access.
30
+
31
+ if ( !function_exists( 'ftg_fs' ) ) {
32
+ // Create a helper function for easy SDK access.
33
+ function ftg_fs()
34
+ {
35
+ global $ftg_fs ;
36
+
37
+ if ( !isset( $ftg_fs ) ) {
38
+ // Activate multisite network integration.
39
+ if ( !defined( 'WP_FS__PRODUCT_1002_MULTISITE' ) ) {
40
+ define( 'WP_FS__PRODUCT_1002_MULTISITE', true );
41
+ }
42
+ // Include Freemius SDK.
43
+ require_once dirname( __FILE__ ) . '/freemius/start.php';
44
+ $ftg_fs = fs_dynamic_init( array(
45
+ 'id' => '1002',
46
+ 'slug' => 'final-tiles-grid-gallery-lite',
47
+ 'type' => 'plugin',
48
+ 'public_key' => 'pk_d0e075b84d491d510a1d0a21087af',
49
+ 'is_premium' => false,
50
+ 'has_addons' => false,
51
+ 'has_paid_plans' => true,
52
+ 'trial' => array(
53
+ 'days' => 14,
54
+ 'is_require_payment' => true,
55
+ ),
56
+ 'has_affiliation' => 'all',
57
+ 'menu' => array(
58
+ 'slug' => 'ftg-lite-gallery-admin',
59
+ ),
60
+ 'is_live' => true,
61
+ ) );
62
+ }
63
+
64
+ return $ftg_fs;
65
+ }
66
+
67
+ // Init Freemius.
68
+ ftg_fs();
69
+ // Signal that SDK was initiated.
70
+ do_action( 'ftg_fs_loaded' );
71
+ }
72
+
73
+ function activate_finaltilesgallery()
74
+ {
75
+ global $wpdb ;
76
+ include_once 'lib/install-db.php';
77
+ FinalTiles_Gallery::define_db_tables();
78
+ FinalTilesdb::updateConfiguration();
79
+
80
+ if ( is_multisite() ) {
81
+ foreach ( $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" ) as $blog_id ) {
82
+ switch_to_blog( $blog_id );
83
+ install_db();
84
+ restore_current_blog();
85
+ }
86
+ } else {
87
+ install_db();
88
+ }
89
+
90
+ }
91
+
92
+ define( "FTG_PLAN", "free" );
93
+ if ( !class_exists( 'FinalTiles_Gallery' ) ) {
94
+ class FinalTiles_Gallery
95
+ {
96
+ private $defaultValues = array(
97
+ 'aClass' => '',
98
+ 'afterGalleryText' => '',
99
+ 'allFilterLabel' => 'All',
100
+ 'ajaxLoading' => 'F',
101
+ 'backgroundColor' => 'transparent',
102
+ 'beforeGalleryText' => '',
103
+ 'blank' => 'F',
104
+ 'borderColor' => 'transparent',
105
+ 'borderRadius' => 0,
106
+ 'borderSize' => 0,
107
+ 'captionBackgroundColor' => '#000000',
108
+ 'captionBehavior' => 'none',
109
+ 'captionColor' => '#ffffff',
110
+ 'captionCustomFields' => '',
111
+ 'captionEasing' => 'linear',
112
+ 'captionEffect' => 'slide-from-bottom',
113
+ 'captionEffectDuration' => 250,
114
+ 'captionEmpty' => 'hide',
115
+ 'captionFontSize' => 12,
116
+ 'captionFrame' => 'F',
117
+ 'captionFrameColor' => '#ffffff',
118
+ 'captionHorizontalAlignment' => 'center',
119
+ 'captionIcon' => 'zoom',
120
+ 'captionIconColor' => '#ffffff',
121
+ 'captionIconSize' => 12,
122
+ 'captionMobileBehavior' => "desktop",
123
+ 'captionOpacity' => 80,
124
+ 'captionPosition' => 'inside',
125
+ 'captionVerticalAlignment' => 'middle',
126
+ 'categoriesAsFilters' => 'F',
127
+ 'columns' => 4,
128
+ 'columnsPhoneLandscape' => 3,
129
+ 'columnsPhonePortrait' => 2,
130
+ 'columnsTabletLandscape' => 4,
131
+ 'columnsTabletPortrait' => 3,
132
+ 'compressHTML' => 'T',
133
+ 'customCaptionIcon' => '',
134
+ 'defaultFilter' => '',
135
+ 'defaultSize' => 'medium',
136
+ 'delay' => 0,
137
+ 'disableLightboxGroups' => 'F',
138
+ 'enableFacebook' => 'F',
139
+ 'enablePinterest' => 'F',
140
+ 'enableTwitter' => 'F',
141
+ 'enlargeImages' => 'T',
142
+ 'filterClick' => 'F',
143
+ 'filters' => '',
144
+ 'gridCellSize' => 25,
145
+ 'gridCellSizeDisabledBelow' => 800,
146
+ 'hoverDuration' => 250,
147
+ 'hoverIconRotation' => 'F',
148
+ 'hoverRotation' => 0,
149
+ 'hoverZoom' => 100,
150
+ 'imageSizeFactor' => 30,
151
+ 'imageSizeFactorCustom' => '',
152
+ 'imageSizeFactorPhoneLandscape' => 30,
153
+ 'imageSizeFactorPhonePortrait' => 20,
154
+ 'imageSizeFactorTabletLandscape' => 30,
155
+ 'imageSizeFactorTabletPortrait' => 20,
156
+ 'imagesOrder' => 'user',
157
+ 'layout' => 'final',
158
+ 'lazyLoad' => false,
159
+ 'lightbox' => 'lightbox2',
160
+ 'lightboxImageSize' => 'large',
161
+ 'lightboxOptions' => '',
162
+ 'lightboxOptionsMobile' => '',
163
+ 'loadedDuration' => 500,
164
+ 'loadedEasing' => 'ease-out',
165
+ 'loadedHSlide' => 0,
166
+ 'loadedRotateY' => 0,
167
+ 'loadedRotateX' => 0,
168
+ 'loadedScaleY' => 100,
169
+ 'loadedScaleX' => 100,
170
+ 'loadedVSlide' => 0,
171
+ 'loadingBarBackgroundColor' => "#fff",
172
+ 'loadingBarColor' => "#666",
173
+ 'loadMethod' => 'sequential',
174
+ 'margin' => 10,
175
+ 'max_posts' => 0,
176
+ 'minTileWidth' => '250',
177
+ 'mobileLightbox' => 'lightbox2',
178
+ 'post_types' => '',
179
+ 'post_taxonomies' => '',
180
+ 'recentPostsCaption' => 'title',
181
+ 'recentPostsCaptionAutoExcerptLength' => 20,
182
+ 'rel' => '',
183
+ 'reverseOrder' => false,
184
+ 'script' => '',
185
+ 'shadowColor' => '#cccccc',
186
+ 'shadowSize' => 0,
187
+ 'socialIconColor' => '#ffffff',
188
+ 'socialIconPosition' => 'bottom',
189
+ 'socialIconStyle' => 'none',
190
+ 'source' => 'images',
191
+ 'style' => '',
192
+ 'support' => 'F',
193
+ 'supportText' => 'Powered by Final Tiles Grid Gallery',
194
+ 'taxonomyOperator' => 'OR',
195
+ 'tilesPerPage' => 0,
196
+ 'titleFontSize' => 14,
197
+ 'width' => '100%',
198
+ 'wp_field_caption' => 'description',
199
+ 'wp_field_title' => 'title',
200
+ ) ;
201
+ //Constructor
202
+ public function __construct()
203
+ {
204
+ $this->plugin_name = plugin_basename( __FILE__ );
205
+ $this->define_constants();
206
+ $this->setupFields();
207
+ $this->define_db_tables();
208
+ $this->FinalTilesdb = $this->create_db_conn();
209
+ add_filter( 'widget_text', 'do_shortcode' );
210
+ add_action( 'init', array( $this, 'create_textdomain' ) );
211
+ add_action( 'wp_enqueue_scripts', array( $this, 'add_gallery_scripts' ) );
212
+ //add_action( 'admin_init', array($this,'gallery_admin_init') );
213
+ add_action( 'admin_menu', array( $this, 'add_gallery_admin_menu' ) );
214
+ add_action( 'init', array( $this, 'register_gutenberg_block' ) );
215
+ add_shortcode( 'FinalTilesGallery', array( $this, 'gallery_shortcode_handler' ) );
216
+ add_action( 'wp_ajax_save_gallery', array( $this, 'save_gallery' ) );
217
+ add_action( 'wp_ajax_add_new_gallery', array( $this, 'add_new_gallery' ) );
218
+ add_action( 'wp_ajax_delete_gallery', array( $this, 'delete_gallery' ) );
219
+ add_action( 'wp_ajax_clone_gallery', array( $this, 'clone_gallery' ) );
220
+ add_action( 'wp_ajax_save_image', array( $this, 'save_image' ) );
221
+ add_action( 'wp_ajax_add_image', array( $this, 'add_image' ) );
222
+ add_action( 'wp_ajax_save_video', array( $this, 'save_video' ) );
223
+ add_action( 'wp_ajax_sort_images', array( $this, 'sort_images' ) );
224
+ add_action( 'wp_ajax_delete_image', array( $this, 'delete_image' ) );
225
+ add_action( 'wp_ajax_assign_filters', array( $this, 'assign_filters' ) );
226
+ add_action( 'wp_ajax_assign_group', array( $this, 'assign_group' ) );
227
+ add_action( 'wp_ajax_toggle_visibility', array( $this, 'toggle_visibility' ) );
228
+ add_action( 'wp_ajax_refresh_gallery', array( $this, 'refresh_gallery' ) );
229
+ add_action( 'wp_ajax_get_gallery_configuration', array( $this, 'get_configuration' ) );
230
+ add_action( 'wp_ajax_update_gallery_configuration', array( $this, 'update_configuration' ) );
231
+ add_action( 'wp_ajax_get_image_size_url', array( $this, 'get_image_size_url' ) );
232
+ add_filter( 'mce_buttons', array( $this, 'editor_button' ) );
233
+ add_filter( 'mce_external_plugins', array( $this, 'register_editor_plugin' ) );
234
+ add_action( 'wp_ajax_ftg_shortcode_editor', array( $this, 'ftg_shortcode_editor' ) );
235
+ add_filter(
236
+ 'plugin_row_meta',
237
+ array( $this, 'register_links' ),
238
+ 10,
239
+ 2
240
+ );
241
+ add_action( 'wp_ajax_load_chunk', array( $this, 'load_chunk' ) );
242
+ add_action( 'wp_ajax_nopriv_load_chunk', array( $this, 'load_chunk' ) );
243
+
244
+ if ( ftg_fs()->is_not_paying() ) {
245
+ add_action( 'admin_notices', array( $this, 'review' ) );
246
+ add_action( 'wp_ajax_ftg_dismiss_review', array( $this, 'dismiss_review' ) );
247
+ add_filter(
248
+ 'admin_footer_text',
249
+ array( $this, 'admin_footer' ),
250
+ 1,
251
+ 2
252
+ );
253
+ }
254
+
255
+ $this->resetFields();
256
+ }
257
+
258
+ /**
259
+ * Register Gutenberg Block
260
+ */
261
+ public function register_gutenberg_block()
262
+ {
263
+ if ( !function_exists( 'register_block_type' ) ) {
264
+ // Gutenberg is not active.
265
+ return;
266
+ }
267
+ // Register block js script
268
+ wp_register_script( 'ftg-gallery-block', plugins_url( 'scripts/gutenberg_block.js', __FILE__ ), array(
269
+ 'wp-blocks',
270
+ 'wp-i18n',
271
+ 'wp-element',
272
+ 'wp-editor',
273
+ 'wp-components'
274
+ ) );
275
+ // Editor CSS
276
+ wp_register_style( 'ftg-gallery-block-editor', plugins_url( 'admin/css/gutenberg_block.css', __FILE__ ), array( 'wp-edit-blocks' ) );
277
+ // Register block
278
+ register_block_type( 'ftg/gallery', array(
279
+ 'editor_style' => 'ftg-gallery-block-editor',
280
+ 'editor_script' => 'ftg-gallery-block',
281
+ ) );
282
+ // Set block translation
283
+ wp_set_script_translations( 'FinalTiles-gallery', 'final-tiles-gallery', dirname( plugin_basename( __FILE__ ) ) . '/lib/languages/' );
284
+ $galls = [ [
285
+ 'value' => 0,
286
+ 'label' => esc_html__( 'Select gallery', 'final-tiles-grid-gallery-lite' ),
287
+ ] ];
288
+ $galleries = $this->FinalTilesdb->getGalleries();
289
+ if ( $galleries ) {
290
+ foreach ( $galleries as $g ) {
291
+ $galls[] = [
292
+ 'value' => $g->Id,
293
+ 'label' => $g->name,
294
+ ];
295
+ }
296
+ }
297
+ // send list of galleries to block
298
+ wp_localize_script( 'ftg-gallery-block', 'ftg_galleries', array(
299
+ 'items' => $galls,
300
+ 'add_new_galler_url' => admin_url( 'admin.php?page=ftg-add-gallery' ),
301
+ ) );
302
+ }
303
+
304
+ public function review()
305
+ {
306
+ // Verify that we can do a check for reviews.
307
+ $review = get_option( 'ftg_review' );
308
+ $time = time();
309
+ $load = false;
310
+ $there_was_review = false;
311
+
312
+ if ( !$review ) {
313
+ $review = array(
314
+ 'time' => $time,
315
+ 'dismissed' => false,
316
+ );
317
+ $load = true;
318
+ $there_was_review = false;
319
+ } else {
320
+ // Check if it has been dismissed or not.
321
+ if ( isset( $review['dismissed'] ) && !$review['dismissed'] && (isset( $review['time'] ) && $review['time'] + DAY_IN_SECONDS <= $time) ) {
322
+ $load = true;
323
+ }
324
+ }
325
+
326
+ // If we cannot load, return early.
327
+ if ( !$load ) {
328
+ return;
329
+ }
330
+ // Update the review option now.
331
+ update_option( 'ftg_review', $review );
332
+ // Run through optins on the site to see if any have been loaded for more than a week.
333
+ $valid = false;
334
+ $galleries = $this->FinalTilesdb->getGalleries();
335
+ if ( !$galleries ) {
336
+ return;
337
+ }
338
+ $with_date = false;
339
+ foreach ( $galleries as $gallery ) {
340
+ if ( !isset( $gallery->date ) ) {
341
+ continue;
342
+ }
343
+ $with_date = true;
344
+ $data = $gallery->date;
345
+ // Check the creation date of the local optin. It must be at least one week after.
346
+ $created = ( isset( $data ) ? strtotime( $data ) + 7 * DAY_IN_SECONDS : false );
347
+ if ( !$created ) {
348
+ continue;
349
+ }
350
+
351
+ if ( $created <= $time ) {
352
+ $valid = true;
353
+ break;
354
+ }
355
+
356
+ }
357
+ if ( !$with_date && count( $galleries ) > 0 && !$there_was_review ) {
358
+ $valid = true;
359
+ }
360
+ // If we don't have a valid option yet, return.
361
+ if ( !$valid ) {
362
+ return;
363
+ }
364
+ // We have a candidate! Output a review message.
365
+ ?>
366
+ <div class="notice notice-info is-dismissible ftg-review-notice">
367
+ <p><?php
368
+ esc_html_e( 'Hey, I noticed you created a photo gallery with Final Tiles - that’s awesome! Would you mind give it a 5-star rating on WordPress to help us spread the word and boost our motivation for new featrues?', 'final-tiles-grid-gallery-lite' );
369
+ ?></p>
370
+ <p><strong><?php
371
+ esc_html_e( 'MachoThemes', 'final-tiles-grid-gallery-lite' );
372
+ ?></strong></p>
373
+ <p>
374
+ <a href="https://wordpress.org/support/plugin/final-tiles-grid-gallery-lite/reviews/?filter=5#new-post" class="ftg-dismiss-review-notice ftg-review-out" target="_blank" rel="noopener"><?php
375
+ esc_html_e( 'Ok, you deserve it', 'final-tiles-grid-gallery-lite' );
376
+ ?></a><br>
377
+ <a href="#" class="ftg-dismiss-review-notice" rel="noopener"><?php
378
+ esc_html_e( 'Nope, maybe later', 'final-tiles-grid-gallery-lite' );
379
+ ?></a><br>
380
+ <a href="#" class="ftg-dismiss-review-notice" rel="noopener"><?php
381
+ esc_html_e( 'I already did', 'final-tiles-grid-gallery-lite' );
382
+ ?></a><br>
383
+ </p>
384
+ </div>
385
+ <script type="text/javascript">
386
+ jQuery(document).ready( function($) {
387
+ $(document).on('click', '.ftg-dismiss-review-notice, .ftg-review-notice button', function( event ) {
388
+ if ( ! $(this).hasClass('ftg-review-out') ) {
389
+ event.preventDefault();
390
+ }
391
+
392
+ $.post( ajaxurl, {
393
+ action: 'ftg_dismiss_review'
394
+ });
395
+
396
+ $('.ftg-review-notice').remove();
397
+ });
398
+ });
399
+ </script>
400
+ <?php
401
+ }
402
+
403
+ public function dismiss_review()
404
+ {
405
+ $review = get_option( 'ftg_review' );
406
+ if ( !$review ) {
407
+ $review = array();
408
+ }
409
+ $review['time'] = time();
410
+ $review['dismissed'] = true;
411
+ update_option( 'ftg_review', $review );
412
+ die;
413
+ }
414
+
415
+ public function admin_footer( $text )
416
+ {
417
+ global $current_screen ;
418
+
419
+ if ( !empty($current_screen->id) && strpos( $current_screen->id, 'ftg' ) !== false ) {
420
+ $url = esc_url( 'https://wordpress.org/support/plugin/final-tiles-grid-gallery-lite/reviews/?filter=5#new-post' );
421
+ $text = sprintf( __( 'Please rate <strong>Final Tiles Gallery</strong> <a href="%s" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a> on <a href="%s" target="_blank">WordPress.org</a> to help us spread the word. Thank you from the Final Tiles Gallery team!', 'final-tiles-grid-gallery-lite' ), $url, $url );
422
+ }
423
+
424
+ return $text;
425
+ }
426
+
427
+ private function resetFields()
428
+ {
429
+ $keys = array(
430
+ 'name',
431
+ 'hiddenFor',
432
+ 'type',
433
+ 'description',
434
+ 'default',
435
+ 'min',
436
+ 'max',
437
+ 'mu',
438
+ 'excludeFrom'
439
+ );
440
+ foreach ( $this->fields as $tab_name => $tab ) {
441
+ foreach ( $tab["fields"] as $key => $field ) {
442
+ //print_r($field);
443
+ foreach ( $keys as $kk ) {
444
+ if ( !array_key_exists( $kk, $field ) ) {
445
+ $this->fields[$tab_name]["fields"][$key][$kk] = "";
446
+ }
447
+ }
448
+ }
449
+ }
450
+ //print_r($this->fields);
451
+ }
452
+
453
+ public function register_links( $links, $file )
454
+ {
455
+ $base = plugin_basename( __FILE__ );
456
+
457
+ if ( $file == $base ) {
458
+ $links[] = '<a href="admin.php?page=ftg-lite-gallery-admin" title="Final Tiles Grid Gallery Dashboard">Dashboard</a>';
459
+ $links[] = '<a href="https://www.machothemes.com/" title="MachoThemes website">MachoThemes</a>';
460
+ $links[] = '<a href="https://twitter.com/machothemes" title="@MachoThemes on Twitter">Twitter</a>';
461
+ $links[] = '<a href="https://www.facebook.com/machothemes" title="MachoThemes on Facebook">Facebook</a>';
462
+ }
463
+
464
+ return $links;
465
+ }
466
+
467
+ /*public function create_db_tables()
468
+ {
469
+ include_once 'lib/install-db.php';
470
+ install_db();
471
+ }
472
+
473
+ public function activation()
474
+ {
475
+
476
+ }*/
477
+ //Define textdomain
478
+ public function create_textdomain()
479
+ {
480
+ $plugin_dir = basename( dirname( __FILE__ ) );
481
+ load_plugin_textdomain( 'final-tiles-grid-gallery-lite', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
482
+ foreach ( $this->fields as $s => $section ) {
483
+ foreach ( $section["fields"] as $f => $field ) {
484
+ $this->fields[$s]["fields"][$f]["description"] = esc_html__( $this->fields[$s]["fields"][$f]["description"], 'final-tiles-grid-gallery-lite' );
485
+ }
486
+ }
487
+ }
488
+
489
+ //Define constants
490
+ public function define_constants()
491
+ {
492
+ if ( !defined( 'FINALTILESGALLERY_PLUGIN_BASENAME' ) ) {
493
+ define( 'FINALTILESGALLERY_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
494
+ }
495
+ if ( !defined( 'FINALTILESGALLERY_PLUGIN_NAME' ) ) {
496
+ define( 'FINALTILESGALLERY_PLUGIN_NAME', trim( dirname( FINALTILESGALLERY_PLUGIN_BASENAME ), '/' ) );
497
+ }
498
+ if ( !defined( 'FINALTILESGALLERY_PLUGIN_DIR' ) ) {
499
+ define( 'FINALTILESGALLERY_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . FINALTILESGALLERY_PLUGIN_NAME );
500
+ }
501
+ }
502
+
503
+ //Define DB tables
504
+ public static function define_db_tables()
505
+ {
506
+ global $wpdb ;
507
+ $wpdb->FinalTilesGalleries = $wpdb->prefix . 'FinalTiles_gallery';
508
+ $wpdb->FinalTilesImages = $wpdb->prefix . 'FinalTiles_gallery_images';
509
+ }
510
+
511
+ public function create_db_conn()
512
+ {
513
+ require 'lib/db-class.php';
514
+ $FinalTilesdb = FinalTilesDB::getInstance();
515
+ return $FinalTilesdb;
516
+ }
517
+
518
+ public function editor_button( $buttons )
519
+ {
520
+ array_push( $buttons, 'separator', 'ftg_shortcode_editor' );
521
+ return $buttons;
522
+ }
523
+
524
+ public function register_editor_plugin( $plugin_array )
525
+ {
526
+ $plugin_array['ftg_shortcode_editor'] = plugins_url( '/admin/scripts/editor-plugin.js', __FILE__ );
527
+ return $plugin_array;
528
+ }
529
+
530
+ public function ftg_shortcode_editor()
531
+ {
532
+ $css_path = plugins_url( 'assets/css/admin.css', __FILE__ );
533
+ $admin_url = admin_url();
534
+ $galleries = $this->FinalTilesdb->getGalleries();
535
+ //load all galleries
536
+ include 'admin/include/tinymce-galleries.php';
537
+ wp_die();
538
+ }
539
+
540
+ public function attachment_fields_to_edit( $form, $post )
541
+ {
542
+ $form["ftg_link"] = array(
543
+ "label" => "Link <small>FTG</small>",
544
+ "input" => "text",
545
+ "value" => get_post_meta( $post->ID, "_ftg_link", true ),
546
+ "helps" => "",
547
+ );
548
+ $form["ftg_target"] = array(
549
+ "label" => "_blank <small>FTG</small>",
550
+ "input" => "html",
551
+ "html" => "<input type='checkbox' name='attachments[{$post->ID}][ftg_target]' id='attachments[{$post->ID}][ftg_target]' value='_mblank' " . (( get_post_meta( $post->ID, "_ftg_target", true ) == "_mblank" ? "checked" : "" )) . " />",
552
+ );
553
+ return $form;
554
+ }
555
+
556
+ public function attachment_fields_to_save( $post, $attachment )
557
+ {
558
+ if ( isset( $attachment['ftg_link'] ) ) {
559
+ update_post_meta( $post['ID'], '_ftg_link', esc_url_raw( $attachment['ftg_link'] ) );
560
+ }
561
+ if ( isset( $attachment['ftg_target'] ) ) {
562
+ update_post_meta( $post['ID'], '_ftg_target', sanitize_text_field( $attachment['ftg_target'] ) );
563
+ }
564
+ return $post;
565
+ }
566
+
567
+ //Delete gallery
568
+ public function delete_gallery()
569
+ {
570
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
571
+ $this->FinalTilesdb->deleteGallery( intval( $_POST['id'] ) );
572
+ }
573
+ return array();
574
+ }
575
+
576
+ public function update_configuration()
577
+ {
578
+
579
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
580
+ $id = $_POST['galleryId'];
581
+ $config = stripslashes( $_POST['config'] );
582
+ $this->FinalTilesdb->update_config( $id, $config );
583
+ }
584
+
585
+ exit;
586
+ }
587
+
588
+ public function get_configuration()
589
+ {
590
+
591
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
592
+ $id = $_POST['galleryId'];
593
+ $gallery = $this->FinalTilesdb->getGalleryConfig( $id );
594
+ echo $gallery ;
595
+ }
596
+
597
+ exit;
598
+ }
599
+
600
+ public function get_image_size_url()
601
+ {
602
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
603
+ echo wp_get_attachment_image_url( $_POST['id'], $_POST['size'], false ) ;
604
+ }
605
+ exit;
606
+ }
607
+
608
+ //Clone gallery
609
+ public function clone_gallery()
610
+ {
611
+
612
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
613
+ $sourceId = intval( $_POST['id'] );
614
+ $g = $this->FinalTilesdb->getGalleryById( $sourceId, true );
615
+ $g['name'] .= " (copy)";
616
+ $this->FinalTilesdb->addGallery( $g );
617
+ $id = $this->FinalTilesdb->getNewGalleryId();
618
+ $images = $this->FinalTilesdb->getImagesByGalleryId( $sourceId, 0, 0 );
619
+ foreach ( $images as &$image ) {
620
+ $image->Id = null;
621
+ $image->gid = $id;
622
+ }
623
+ $this->FinalTilesdb->addImages( $id, $images );
624
+ }
625
+
626
+ return array();
627
+ }
628
+
629
+ //Add gallery scripts
630
+ public function add_gallery_scripts()
631
+ {
632
+ wp_enqueue_script( 'jquery' );
633
+ wp_register_script(
634
+ 'finalTilesGallery',
635
+ plugins_url( 'scripts/jquery.finalTilesGallery.js', __FILE__ ),
636
+ array( 'jquery' ),
637
+ FTGVERSION,
638
+ true
639
+ );
640
+ wp_enqueue_script( 'finalTilesGallery' );
641
+ wp_register_style(
642
+ 'finalTilesGallery_stylesheet',
643
+ plugins_url( 'scripts/ftg.css', __FILE__ ),
644
+ array(),
645
+ FTGVERSION
646
+ );
647
+ wp_enqueue_style( 'finalTilesGallery_stylesheet' );
648
+ wp_register_script( 'lightbox2_script', plugins_url( 'lightbox/lightbox2/js/script.js', __FILE__ ), array( 'jquery' ) );
649
+ wp_register_style( 'lightbox2_stylesheet', plugins_url( 'lightbox/lightbox2/css/style.css', __FILE__ ) );
650
+ wp_register_style( 'fontawesome_stylesheet', '//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css' );
651
+ wp_enqueue_style( 'fontawesome_stylesheet' );
652
+ }
653
+
654
+ //Admin Section - register scripts and styles
655
+ public function gallery_admin_init()
656
+ {
657
+ if ( function_exists( 'wp_enqueue_media' ) ) {
658
+ wp_enqueue_media();
659
+ }
660
+ $ftg_db_version = '20190518';
661
+ $installed_ver = get_option( "FinalTiles_gallery_db_version" );
662
+ if ( !$installed_ver || empty($installed_ver) ) {
663
+ update_option( "FinalTiles_gallery_db_version", $ftg_db_version );
664
+ }
665
+
666
+ if ( $installed_ver != $ftg_db_version ) {
667
+ activate_finaltilesgallery();
668
+ update_option( "FinalTiles_gallery_db_version", $ftg_db_version );
669
+ }
670
+
671
+ function ftg_get_image_sizes()
672
+ {
673
+ global $_wp_additional_image_sizes ;
674
+ $sizes = array();
675
+ foreach ( get_intermediate_image_sizes() as $_size ) {
676
+
677
+ if ( in_array( $_size, array(
678
+ 'thumbnail',
679
+ 'medium',
680
+ 'medium_large',
681
+ 'large'
682
+ ) ) ) {
683
+ $sizes[$_size]['width'] = get_option( "{$_size}_size_w" );
684
+ $sizes[$_size]['height'] = get_option( "{$_size}_size_h" );
685
+ $sizes[$_size]['crop'] = (bool) get_option( "{$_size}_crop" );
686
+ } elseif ( isset( $_wp_additional_image_sizes[$_size] ) ) {
687
+ $sizes[$_size] = array(
688
+ 'width' => $_wp_additional_image_sizes[$_size]['width'],
689
+ 'height' => $_wp_additional_image_sizes[$_size]['height'],
690
+ 'crop' => $_wp_additional_image_sizes[$_size]['crop'],
691
+ );
692
+ }
693
+
694
+ }
695
+ return $sizes;
696
+ }
697
+
698
+ foreach ( ftg_get_image_sizes() as $name => $size ) {
699
+ $this->fields["Links & Lightbox"]["fields"]["lightboxImageSize"]["values"]["Size"][] = $name . "|" . $name . " (" . $size['width'] . 'x' . $size['height'] . (( $size['crop'] ? ' cropped)' : ')' ));
700
+ }
701
+ $this->fields["Links & Lightbox"]["fields"]["lightboxImageSize"]["values"]["Size"][] = "full|Original (full)";
702
+ wp_enqueue_script( 'jquery' );
703
+ wp_enqueue_script( 'jquery-ui-dialog' );
704
+ wp_enqueue_script( 'jquery-ui-sortable' );
705
+ wp_enqueue_script( 'wp-color-picker' );
706
+ wp_enqueue_style( 'wp-color-picker' );
707
+ wp_enqueue_script( 'media-upload' );
708
+ wp_enqueue_script( 'thickbox' );
709
+ wp_register_style( 'google-fonts', '//fonts.googleapis.com/css?family=Roboto:400,700,500,300,900' );
710
+ wp_enqueue_style( 'google-fonts' );
711
+ wp_register_style( 'google-icons', '//cdn.materialdesignicons.com/1.9.32/css/materialdesignicons.min.css', array() );
712
+ wp_enqueue_style( 'google-icons' );
713
+ wp_register_style( 'final-tiles-gallery-admin', plugins_url( 'admin/css/style.css', __FILE__ ), array( 'colors' ) );
714
+ wp_enqueue_style( 'final-tiles-gallery-admin' );
715
+ wp_register_script( 'materialize', plugins_url( 'admin/scripts/materialize.min.js', __FILE__ ), array( 'jquery' ) );
716
+ wp_enqueue_script( 'materialize' );
717
+ wp_register_script( 'final-tiles-gallery', plugins_url( 'admin/scripts/final-tiles-gallery-admin.js', __FILE__ ), array(
718
+ 'jquery',
719
+ 'media-upload',
720
+ 'thickbox',
721
+ 'materialize'
722
+ ) );
723
+ wp_enqueue_script( 'final-tiles-gallery' );
724
+ wp_enqueue_style( 'thickbox' );
725
+ wp_register_style( 'fontawesome_stylesheet', '//netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.css' );
726
+ wp_enqueue_style( 'fontawesome_stylesheet' );
727
+ }
728
+
729
+ //Create Admin Menu
730
+ public function add_gallery_admin_menu()
731
+ {
732
+ $overview = add_menu_page(
733
+ 'Final Tiles Gallery',
734
+ 'Final Tiles Gallery',
735
+ 'edit_posts',
736
+ 'ftg-lite-gallery-admin',
737
+ array( $this, 'add_overview' ),
738
+ plugins_url( 'admin/icon.png', __FILE__ )
739
+ );
740
+ $add_gallery = add_submenu_page(
741
+ 'ftg-lite-gallery-admin',
742
+ esc_html__( 'FinalTiles Gallery >> Add Gallery', 'final-tiles-grid-gallery-lite' ),
743
+ esc_html__( 'Add Gallery', 'final-tiles-grid-gallery-lite' ),
744
+ 'edit_posts',
745
+ 'ftg-add-gallery',
746
+ array( $this, 'add_gallery' )
747
+ );
748
+ add_action( 'load-' . $overview, array( $this, 'gallery_admin_init' ) );
749
+ add_action( 'load-' . $add_gallery, array( $this, 'gallery_admin_init' ) );
750
+ /*if(! class_exists("PhotoBlocks"))
751
+ {
752
+ $photoblocks = add_submenu_page('ftg-lite-gallery-admin', __('FinalTiles Gallery >> PhotoBlocks', 'FinalTiles-gallery'), __('PhotoBlocks', 'FinalTiles-gallery'), 'edit_posts', 'ftg-photoblocks', array($this, 'photoblocks'));
753
+ add_action('load-' . $photoblocks, array($this, 'gallery_admin_init'));
754
+ }
755
+
756
+ if(! class_exists("EverlightBox"))
757
+ {
758
+ $everlightbox = add_submenu_page('ftg-lite-gallery-admin', __('FinalTiles Gallery >> EverlightBox', 'FinalTiles-gallery'), __('EverlightBox', 'FinalTiles-gallery'), 'edit_posts', 'ftg-everlightbox', array($this, 'everlightbox'));
759
+ add_action('load-' . $everlightbox, array($this, 'gallery_admin_init'));
760
+ }*/
761
+ }
762
+
763
+ //Create Admin Pages
764
+ public function add_overview()
765
+ {
766
+ global $ftg_fields ;
767
+ $ftg_fields = $this->fields;
768
+ global $ftg_parent_page ;
769
+ $ftg_parent_page = "dashboard";
770
+
771
+ if ( array_key_exists( "id", $_GET ) ) {
772
+ $woocommerce_post_types = array(
773
+ "product",
774
+ "product_variation",
775
+ "shop_order",
776
+ "shop_order_refund",
777
+ "shop_coupon",
778
+ "shop_webhook"
779
+ );
780
+ $wp_post_types = array( "revision", "nav_menu_item" );
781
+ $excluded_post_types = array_merge( $wp_post_types, $woocommerce_post_types );
782
+ $woo_categories = $this->getWooCategories();
783
+ include "admin/edit-gallery.php";
784
+ } else {
785
+ include "admin/overview.php";
786
+ }
787
+
788
+ }
789
+
790
+ public function tutorial()
791
+ {
792
+ include "admin/tutorial.php";
793
+ }
794
+
795
+ public function support()
796
+ {
797
+ include "admin/support.php";
798
+ }
799
+
800
+ public function photoblocks()
801
+ {
802
+ include "admin/photoblocks.php";
803
+ }
804
+
805
+ public function everlightbox()
806
+ {
807
+ include "admin/everlightbox.php";
808
+ }
809
+
810
+ private function getWooCategories()
811
+ {
812
+
813
+ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
814
+ $taxonomy = 'product_cat';
815
+ $orderby = 'name';
816
+ $show_count = 0;
817
+ // 1 for yes, 0 for no
818
+ $pad_counts = 0;
819
+ // 1 for yes, 0 for no
820
+ $hierarchical = 1;
821
+ // 1 for yes, 0 for no
822
+ $title = '';
823
+ $empty = 0;
824
+ $args = array(
825
+ 'taxonomy' => $taxonomy,
826
+ 'orderby' => $orderby,
827
+ 'show_count' => $show_count,
828
+ 'pad_counts' => $pad_counts,
829
+ 'hierarchical' => $hierarchical,
830
+ 'title_li' => $title,
831
+ 'hide_empty' => $empty,
832
+ );
833
+ return get_categories( $args );
834
+ } else {
835
+ return array();
836
+ }
837
+
838
+ }
839
+
840
+ public function add_gallery()
841
+ {
842
+ global $ftg_fields ;
843
+ $ftg_fields = $this->fields;
844
+ $gallery = null;
845
+ $woocommerce_post_types = array(
846
+ "product",
847
+ "product_variation",
848
+ "shop_order",
849
+ "shop_order_refund",
850
+ "shop_coupon",
851
+ "shop_webhook"
852
+ );
853
+ $wp_post_types = array( "revision", "nav_menu_item" );
854
+ $excluded_post_types = array_merge( $wp_post_types, $woocommerce_post_types );
855
+ $woo_categories = $this->getWooCategories();
856
+ include "admin/add-gallery.php";
857
+ }
858
+
859
+ public function delete_image()
860
+ {
861
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
862
+ foreach ( explode( ",", $_POST["id"] ) as $id ) {
863
+ $this->FinalTilesdb->deleteImage( intval( $id ) );
864
+ }
865
+ }
866
+ wp_die();
867
+ }
868
+
869
+ public function assign_filters()
870
+ {
871
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
872
+
873
+ if ( $_POST['source'] == 'posts' ) {
874
+ foreach ( explode( ",", $_POST["id"] ) as $id ) {
875
+ update_post_meta( intval( $id ), 'ftg_filters', sanitize_text_field( $_POST['filters'] ) );
876
+ }
877
+ } else {
878
+ foreach ( explode( ",", $_POST["id"] ) as $id ) {
879
+ $result = $this->FinalTilesdb->editImage( $id, array(
880
+ "filters" => sanitize_text_field( $_POST["filters"] ),
881
+ ) );
882
+ }
883
+ }
884
+
885
+ }
886
+ wp_die();
887
+ }
888
+
889
+ public function toggle_visibility()
890
+ {
891
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
892
+ foreach ( explode( ",", $_POST["id"] ) as $id ) {
893
+ $image = $this->FinalTilesdb->getImage( $id );
894
+ $this->FinalTilesdb->editImage( $id, array(
895
+ "hidden" => ( $image->hidden == 'T' ? 'F' : 'T' ),
896
+ ) );
897
+ }
898
+ }
899
+ wp_die();
900
+ }
901
+
902
+ public function assign_group()
903
+ {
904
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
905
+
906
+ if ( $_POST['source'] == 'posts' ) {
907
+ foreach ( explode( ",", $_POST["id"] ) as $id ) {
908
+ update_post_meta( intval( $id ), 'ftg_group', sanitize_text_field( $_POST['group'] ) );
909
+ }
910
+ } else {
911
+ foreach ( explode( ",", $_POST["id"] ) as $id ) {
912
+ $result = $this->FinalTilesdb->editImage( $id, array(
913
+ "group" => sanitize_text_field( $_POST["group"] ),
914
+ ) );
915
+ }
916
+ }
917
+
918
+ }
919
+ wp_die();
920
+ }
921
+
922
+ public function add_image()
923
+ {
924
+
925
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
926
+ $gid = intval( $_POST['galleryId'] );
927
+ $enc_images = stripslashes( $_POST["enc_images"] );
928
+ $images = json_decode( $enc_images );
929
+ $result = $this->FinalTilesdb->addImages( $gid, $images );
930
+ header( "Content-type: application/json" );
931
+
932
+ if ( $result === false ) {
933
+ echo "{\"success\":false}" ;
934
+ } else {
935
+ echo "{\"success\":true}" ;
936
+ }
937
+
938
+ }
939
+
940
+ wp_die();
941
+ }
942
+
943
+ public function list_thumbnail_sizes()
944
+ {
945
+ global $_wp_additional_image_sizes ;
946
+ $sizes = array();
947
+ foreach ( get_intermediate_image_sizes() as $s ) {
948
+
949
+ if ( in_array( $s, array( 'thumbnail', 'medium', 'large' ) ) ) {
950
+ $sizes[$s][0] = get_option( $s . '_size_w' );
951
+ $sizes[$s][1] = get_option( $s . '_size_h' );
952
+ } else {
953
+ if ( isset( $_wp_additional_image_sizes ) && isset( $_wp_additional_image_sizes[$s] ) && $_wp_additional_image_sizes[$s]['width'] > 0 && $_wp_additional_image_sizes[$s]['height'] > 0 ) {
954
+ $sizes[$s] = array( $_wp_additional_image_sizes[$s]['width'], $_wp_additional_image_sizes[$s]['height'] );
955
+ }
956
+ }
957
+
958
+ }
959
+ return $sizes;
960
+ }
961
+
962
+ public function sort_images()
963
+ {
964
+
965
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
966
+ $result = $this->FinalTilesdb->sortImages( explode( ',', $_POST['ids'] ) );
967
+ header( "Content-type: application/json" );
968
+
969
+ if ( $result === false ) {
970
+ echo "{\"success\":false}" ;
971
+ } else {
972
+ echo "{\"success\":true}" ;
973
+ }
974
+
975
+ }
976
+
977
+ wp_die();
978
+ }
979
+
980
+ public function load_chunk()
981
+ {
982
+ require_once 'lib/gallery-class.php';
983
+
984
+ if ( check_admin_referer( 'finaltilesgallery', 'finaltilesgallery' ) ) {
985
+ $gid = intval( $_POST["gallery"] );
986
+ $images = $this->FinalTilesdb->getImagesByGalleryId( $gid, 0, 0 );
987
+ $FinalTilesGallery = new FinalTilesGallery( $gid, $this->FinalTilesdb, $this->defaultValues );
988
+ echo $FinalTilesGallery->images_markup() ;
989
+ }
990
+
991
+ wp_die();
992
+ }
993
+
994
+ public function refresh_gallery()
995
+ {
996
+ if ( $_POST['source'] == 'images' ) {
997
+ $this->list_images();
998
+ }
999
+ }
1000
+
1001
+ public function save_image()
1002
+ {
1003
+
1004
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
1005
+ $result = false;
1006
+
1007
+ if ( $_POST['source'] == 'posts' ) {
1008
+ $result = true;
1009
+ $postId = intval( $_POST['post_id'] );
1010
+ $img_url = stripslashes( $_POST['img_url'] );
1011
+ update_post_meta( $postId, 'ftg_image_url', esc_url_raw( $img_url ) );
1012
+ if ( array_key_exists( "filters", $_POST ) && strlen( $_POST['filters'] ) ) {
1013
+ update_post_meta( $postId, 'ftg_filters', sanitize_text_field( $_POST['filters'] ) );
1014
+ }
1015
+ } else {
1016
+ $type = sanitize_text_field( $_POST['type'] );
1017
+ $imageUrl = stripslashes( $_POST['img_url'] );
1018
+ $imageCaption = wp_kses_post( $_POST['description'] );
1019
+ $filters = stripslashes( $_POST['filters'] );
1020
+ $title = wp_kses_post( $_POST['imageTitle'] );
1021
+ $target = sanitize_text_field( $_POST['target'] );
1022
+ $group = sanitize_text_field( $_POST['group'] );
1023
+ $alt = sanitize_text_field( $_POST['alt'] );
1024
+ $hidden = $this->checkboxVal( 'hidden' );
1025
+ $link = ( isset( $_POST['link'] ) ? stripslashes( $_POST['link'] ) : null );
1026
+ $imageId = intval( $_POST['img_id'] );
1027
+ $sortOrder = intval( $_POST['sortOrder'] );
1028
+ $data = array(
1029
+ "imagePath" => $imageUrl,
1030
+ "target" => $target,
1031
+ "link" => $link,
1032
+ "imageId" => $imageId,
1033
+ "description" => $imageCaption,
1034
+ "filters" => $filters,
1035
+ "title" => $title,
1036
+ "group" => $group,
1037
+ "alt" => $alt,
1038
+ "hidden" => $hidden,
1039
+ "sortOrder" => $sortOrder,
1040
+ );
1041
+
1042
+ if ( !empty($_POST["id"]) ) {
1043
+ $imageId = intval( $_POST['id'] );
1044
+ $result = $this->FinalTilesdb->editImage( $imageId, $data );
1045
+ } else {
1046
+ $data["gid"] = intval( $_POST['galleryId'] );
1047
+ $result = $this->FinalTilesdb->addFullImage( $data );
1048
+ }
1049
+
1050
+ }
1051
+
1052
+ header( "Content-type: application/json" );
1053
+
1054
+ if ( $result === false ) {
1055
+ echo "{\"success\":false}" ;
1056
+ } else {
1057
+ echo "{\"success\":true}" ;
1058
+ }
1059
+
1060
+ }
1061
+
1062
+ wp_die();
1063
+ }
1064
+
1065
+ public function save_video()
1066
+ {
1067
+
1068
+ if ( check_admin_referer( 'FinalTiles_gallery', 'FinalTiles_gallery' ) ) {
1069
+ $result = false;
1070
+ $type = ( isset( $_POST['type'] ) ? $_POST['type'] : "" );
1071
+ $data = array(
1072
+ "imagePath" => stripslashes( $_POST["embed"] ),
1073
+ "filters" => sanitize_text_field( $_POST['filters'] ),
1074
+ "gid" => intval( $_POST['galleryId'] ),
1075
+ );
1076
+ $id = ( isset( $_POST['id'] ) ? intval( $_POST['id'] ) : "" );
1077
+ $step = ( isset( $_POST['step'] ) ? $_POST['step'] : "" );
1078
+ if ( !empty($step) ) {
1079
+
1080
+ if ( $step == "add" ) {
1081
+ $result = $this->FinalTilesdb->addVideo( $data );
1082
+ } else {
1083
+ if ( $step == "edit" ) {
1084
+ $result = $this->FinalTilesdb->editVideo( $id, $data );