C:\xampp\htdocs\landing\wp-content\updraft\plugins-old\LayerSlider\classes\class.ls.sliders.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
<?php

class LS_Sliders {

    
/**
     * @var array $results Array containing the result of the last DB query
     * @access public
     */
    
public static $results = array();



    
/**
     * @var int $count Count of found sliders in the last DB query
     * @access public
     */
    
public static $count null;



    
/**
     * Private constructor to prevent instantiate static class
     *
     * @since 5.0.0
     * @access private
     * @return void
     */
    
private function __construct() {

    }



    
/**
     * Returns the count of found sliders in the last DB query
     *
     * @since 5.0.0
     * @access public
     * @return int Count of found sliders in the last DB query
     */
    
public static function count() {
        return 
self::$count;
    }



    
/**
     * Find sliders with the provided filters
     *
     * @since 5.0.0
     * @access public
     * @param mixed $args Find any slider with the provided filters
     * @return mixed Array on success, false otherwise
     */
    
public static function find$args = array() ) {

        
$userArgs $args;

        
// Find by slider ID
        
if(is_numeric($args) && intval($args) == $args) {
            return 
self::_getById( (int) $args );

        
// Random slider
        
} elseif($args === 'random') {
            return 
self::_getRandom();

        
// Find by slider slug
        
} elseif(is_string($args)) {
            return 
self::_getBySlug($args);

        
// Find by list of slider IDs
        
} elseif(is_array($args) && isset($args[0]) && is_numeric($args[0])) {
            return 
self::_getByIds($args);

        
// Find by query
        
} else {

            
// Defaults
            
$defaults = array(
                
'columns' => '*',
                
'where' => '',
                
'exclude' => array('removed'),
                
'orderby' => 'date_c',
                
'order' => 'DESC',
                
'limit' => 30,
                
'page' => 1,
                
'groups' => false,
                
'data' => true
            
);

            
// Merge user data with defaults
            
foreach( $defaults as $key => $val ) {
                if( ! isset( 
$args$key ] ) ) {
                    
$args$key ] = $val;
                }
            }

            
// Escape user data
            
foreach( $args as $key => $val ) {
                if( 
$key !== 'where' ) {
                    
$args$key ] = esc_sql$val );
                }
            }

            
// Due to the nature of dynamically built queries we can't
            // use prepared statements or $wpdb::prepare(). By keeping
            // this function backwards compatible, we have even less
            // options to completely eliminate potential issues caused
            // by unhandled data.

            // In addition of using esc_sql(), we're performing some
            // further tests trying to filter out user data that might
            // not be handled properly prior to this function call.
            
$columns = array('id''author''name''slug''data''date_c''date_m''flag_hidden''flag_deleted''schedule_start''schedule_end');

            
$args['orderby']     = in_array($args['orderby'], $columns) ? $args['orderby'] : 'date_c';
            
$args['order']         = ($args['order'] === 'DESC') ? 'DESC' 'ASC';
            
$args['limit']         = (int)  $args['limit'];
            
$args['page']         = (int)  $args['page'];
            
$args['groups']     = (bool) $args['groups'];
            
$args['data']         = (bool) $args['data'];




            
$exclude = array();
            if( 
$args['groups'] ) {
                
$exclude[] = "group_id IS NULL";
            } else {
                
$exclude[] = "flag_group = '0'";
            }


            if( ! empty( 
$args['exclude'] ) ) {

                if( 
in_array'hidden'$args['exclude'] ) ) {
                    
$exclude[] = "flag_hidden = '0'";
                }

                if( 
in_array'removed'$args['exclude'] ) ) {
                    
$exclude[] = "flag_deleted = '0'";
                }
            }

            
$args['exclude'] = implode(' AND '$exclude);

            
// Where
            
$where '';
            if(!empty(
$args['where']) && !empty($args['exclude'])) {
                
$where "WHERE ({$args['exclude']}) AND ({$args['where']}) ";

            } elseif(!empty(
$args['where'])) {
                
$where "WHERE {$args['where']} ";

            } elseif(!empty(
$args['exclude'])) {
                
$where "WHERE {$args['exclude']} ";
            }

            
// Some adjustments
            
$args['limit'] = ($args['limit'] * $args['page'] - $args['limit']).', '.$args['limit'];

            
// Build the query
            
global $wpdb;
            
$table $wpdb->prefix.LS_DB_TABLE;
            
$sliders $wpdb->get_results("
                SELECT SQL_CALC_FOUND_ROWS 
{$args['columns']}
                FROM 
$table
                
$where
                ORDER BY `
{$args['orderby']}{$args['order']}
                LIMIT 
{$args['limit']}

            "
ARRAY_A);

            
// Set counter
            
$found $wpdb->get_col("SELECT FOUND_ROWS()");
            
self::$count = (int) $found[0];

            
// Return original value on error
            
if(!is_array($sliders)) { return $sliders; };

            
// Parse slider data
            
if($args['data']) {
                foreach(
$sliders as $key => $val) {
                    
$sliders[$key]['data'] = json_decode($val['data'], true);
                }
            }


            if( 
$args['groups'] ) {
                foreach( 
$sliders as $key => $val ) {

                    if( 
$val['flag_group'] ) {

                        
$sliders$key ]['items'] = self::_getGroupItems( (int) $val['id'], $userArgs );
                    }
                }
            }

            
// Return sliders
            
return $sliders;
        }
    }



    
/**
     * Add slider with the provided name and optional slider data
     *
     * @since 5.0.0
     * @access public
     * @param string $title The title of the slider to create
     * @param array $data The settings of the slider to create
     * @return int The slider database ID inserted
     */
    
public static function add($title 'Unnamed'$data = array(), $slug ''$groupId NULL ) {

        global 
$wpdb;

        
// Slider data
        
$data = !empty($data) ? $data : array(
            
'properties' => array(
                
'createdWith' => LS_PLUGIN_VERSION,
                
'sliderVersion' => LS_PLUGIN_VERSION,
                
'title' => $title,
                
'new' => true,
            ),
            
'layers' => array(array()),
        );

        
// Fix WP 4.2 issue with longer varchars
        // than the column length
        
if(strlen($title) > 99) {
            
$title substr($title0, (99-strlen($title)) );
        }

        
// Popup?
        
$popup 0;
        if( ! empty(
$data['properties']['type']) && $data['properties']['type'] == 'popup') {
            
$popup 1;
        }

        
// Insert slider, WPDB will escape data automatically
        
$wpdb->insert($wpdb->prefix.LS_DB_TABLE, array(
            
'group_id' => $groupId,
            
'author' => get_current_user_id(),
            
'name' => $title,
            
'slug' => $slug,
            
'data' => json_encode($data),
            
'date_c' => time(),
            
'date_m' => time(),
            
'flag_popup' => $popup
        
), array(
            
'%d''%d''%s''%s''%s''%d''%d''%d'
        
));

        
// Return insert database ID
        
return $wpdb->insert_id;
    }



    
/**
     * Updates sliders
     *
     * @since 5.2.0
     * @access public
     * @param int $id The database ID of the slider to be updated
     * @param string $title The new title of the slider
     * @param array $data The new settings of the slider
     * @return bool Returns true on success, false otherwise
     */
    
public static function update($id 0$title 'Unnamed'$data = array(), $slug '') {

        global 
$wpdb;

        
// Slider data
        
$data = !empty($data) ? $data : array(
            
'properties' => array('title' => $title),
            
'layers' => array(array()),
        );

        
// Fix WP 4.2 issue with longer varchars
        // than the column length
        
if(strlen($title) > 99) {
            
$title substr($title0, (99-strlen($title)) );
        }

        
// Status
        
$status 0;
        if( empty(
$data['properties']['status']) || $data['properties']['status'] === 'false') {
            
$status 1;
        }

        
// Schedule
        
$schedule = array('schedule_start' => 0'schedule_end' => 0);
        foreach(
$schedule as $key => $val) {
            if( ! empty(
$data['properties'][$key]) ) {
                if( 
is_numeric($data['properties'][$key]) ) {
                    
$schedule[$key] = (int) $data['properties'][$key];
                } else {
                    
$tz date_default_timezone_get();
                    
date_default_timezone_setget_option('timezone_string') );
                    
$schedule[$key] = (int) strtotime($data['properties'][$key]);
                    
date_default_timezone_set$tz );
                }
            }
        }

        
// Popup?
        
$popup 0;
        if( ! empty(
$data['properties']['type']) && $data['properties']['type'] == 'popup') {
            
$popup 1;
        }

        
// Insert slider, WPDB will escape data automatically
        
$wpdb->update($wpdb->prefix.LS_DB_TABLE, array(
                
'name' => $title,
                
'slug' => $slug,
                
'data' => json_encode($data),
                
'schedule_start' => $schedule['schedule_start'],
                
'schedule_end' => $schedule['schedule_end'],
                
'date_m' => time(),
                
'flag_hidden' => $status,
                
'flag_popup' => $popup
            
),
            array(
'id' => $id),
            array(
'%s''%s''%s''%d''%d''%d''%d''%d')
        );

        
// Return insert database ID
        
return true;
    }


    
/**
     * Marking a slider as removed without deleting it
     * with its database ID.
     *
     * @since 5.0.0
     * @access public
     * @param int $id The database ID if the slider to remove
     * @return bool Returns true on success, false otherwise
     */
    
public static function remove($id null) {

        
// Check ID
        
if(!is_int($id)) { return false; }

        
// Remove
        
global $wpdb;
        
$wpdb->update($wpdb->prefix.LS_DB_TABLE,
            array(
'flag_deleted' => 1),
            array(
'id' => $id),
            
'%d''%d'
        
);

        return 
true;
    }


    
/**
     * Delete a slider by its database ID
     *
     * @since 5.0.0
     * @access public
     * @param int $id The database ID if the slider to delete
     * @return bool Returns true on success, false otherwise
     */
    
public static function delete($id null) {

        
// Check ID
        
if(!is_int($id)) { return false; }

        
// Get slider data before deleting
        
$slider self::_getById$id );

        
// Delete
        
global $wpdb;
        
$wpdb->delete($wpdb->prefix.LS_DB_TABLE, array('id' => $id), '%d');

        
// Check if the slider was part of a group
        // that might also need to be deleted.
        
if( ! empty( $slider['group_id'] ) ) {
            
self::checkForEmptyGroup( (int) $slider['group_id'] );
        }

        return 
true;
    }



    
/**
     * Restore a slider marked as removed previously by its database ID.
     *
     * @since 5.0.0
     * @access public
     * @param int $id The database ID if the slider to restore
     * @return bool Returns true on success, false otherwise
     */
    
public static function restore($id null) {

        
// Check ID
        
if(!is_int($id)) { return false; }

        
// Remove
        
global $wpdb;
        
$wpdb->update($wpdb->prefix.LS_DB_TABLE,
            array(
'flag_deleted' => 0),
            array(
'id' => $id),
            
'%d''%d'
        
);

        return 
true;
    }


    
/**
     * Adds the specified slider to the specified group
     *
     * @since 6.9.0
     * @access public
     * @param string $sliderId The slider database ID
     * @param string $groupId The group database ID
     * @return bool Returns true on success, false otherwise
     */
    
public static function addSliderToGroup$sliderId$groupId ) {

        global 
$wpdb;
        
$wpdb->update$wpdb->prefix.LS_DB_TABLE,
            array( 
'group_id' => $groupId ),
            array( 
'id' => $sliderId ),
            
'%d',
            
'%d'
        
);

        return 
true;
    }


    
/**
     * Removes the specified slider from its group
     *
     * @since 6.9.0
     * @access public
     * @param string $sliderId The slider database ID
     * @param string $groupId The group database ID
     * @return bool Returns true on success, false otherwise
     */
    
public static function removeSliderFromGroup$sliderId$groupId ) {

        global 
$wpdb;
        
$wpdb->update$wpdb->prefix.LS_DB_TABLE,
            array( 
'group_id' => null ),
            array( 
'id' => $sliderId ),
            
'%d',
            
'%d'
        
);

        
self::checkForEmptyGroup$groupId );

        return 
true;
    }


    
/**
     * Checks whether a slider group is empty and delete
     * it if it is.
     *
     * @since 6.9.0
     * @access public
     * @param string $groupId The group database ID
     * @return void
     */
    
public static function checkForEmptyGroup$groupId ) {

        
$sliders self::_getGroupItems$groupId, array(
            
'exclude' => ''
        
));


        if( empty( 
$sliders ) ) {
            
self::removeGroup$groupId );
        }
    }



    
/**
     * Adds group with the provided group name
     *
     * @since 6.9.0
     * @access public
     * @param string $name The group name
     * @return int The group database ID inserted
     */
    
public static function addGroup$name 'Unnamed' ) {

        if( 
strlen$name ) > 99) {
            
$name substr$name0, ( 99 strlen$name ) ) );
        }

        global 
$wpdb;

        
// Insert slider, WPDB will escape data automatically
        
$wpdb->insert($wpdb->prefix.LS_DB_TABLE, array(
            
'author' => get_current_user_id(),
            
'name' => $name,
            
'data' => '',
            
'date_c' => time(),
            
'date_m' => time(),
            
'flag_popup' => 0,
            
'flag_group' => 1
        
), array(
            
'%d''%s''%s''%s''%d''%d''%d''%d'
        
));

        return 
$wpdb->insert_id;
    }



    
/**
     * Removes the specified group
     *
     * @since 6.9.0
     * @access public
     * @param string $groupId The group database ID
     * @return bool Returns true on success, false otherwise
     */
    
public static function removeGroup$groupId ) {

        global 
$wpdb;

        
// Attempt to remove any sliders from group
        // before deleting it.
        
$wpdb->update(
            
$wpdb->prefix.LS_DB_TABLE,
            array( 
'group_id' => null ),
            array( 
'group_id' => $groupId ),
            array( 
'%d' ),
            array( 
'%d' )
        );

        
// Delete the group
        
$wpdb->delete(
            
$wpdb->prefix.LS_DB_TABLE,
            array( 
'id' => $groupId ),
            array( 
'%d' )
        );

        return 
true;
    }



    
/**
     * Adds group with the provided group name
     *
     * @since 6.9.0
     * @access public
     * @param int $groupId The group ID
     * @param string $name The group name
     * @return bool Returns true on success, false otherwise
     */
    
public static function renameGroup$groupId 0$name 'Unnamed' ) {

        if( 
strlen$name ) > 99) {
            
$name substr$name0, ( 99 strlen$name ) ) );
        }

        global 
$wpdb;

        
// Insert slider, WPDB will escape data automatically
        
$wpdb->update(
            
$wpdb->prefix.LS_DB_TABLE,
            array( 
'name' => $name ),
            array( 
'id' => $groupId ),
            array( 
'%s' ),
            array( 
'%d' )
        );

        
// Return insert database ID
        
return true;
    }



    private static function 
_getGroupItems$id null$args = array() ) {

        
// Check ID
        
if( ! is_int$id ) ) { return false; }

        
// Defaults
        
$defaults = array(
            
'exclude' => array('removed'),
            
'orderby' => 'date_c',
            
'order' => 'DESC',
            
'limit' => 30,
            
'page' => 1,
            
'data' => true
        
);

        
// Merge user data with defaults
        
foreach( $defaults as $key => $val ) {
            if( ! isset( 
$args$key ] ) ) {
                
$args$key ] = $val;
            }
        }

        
$where = array();
        
$where[] = "group_id = '$id'";

        if( ! empty( 
$args['exclude'] ) ) {

            if( 
in_array'hidden'$args['exclude'] ) ) {
                
$where[] = "flag_hidden = '0'";
            }

            if( 
in_array'removed'$args['exclude'] ) ) {
                
$where[] = "flag_deleted = '0'";
            }
        }

        
$where implode(' AND '$where );

        
$args['order']         = ($args['order'] === 'DESC') ? 'DESC' 'ASC';
        
$args['limit']         = (int)  $args['limit'];
        
$args['page']         = (int)  $args['page'];
        
$args['data']         = (bool) $args['data'];

        
// DB stuff
        
global $wpdb;
        
$table $wpdb->prefix.LS_DB_TABLE;

        
// Make the call
        
$result $wpdb->get_results("
            SELECT *
            FROM 
$table
            WHERE 
$where
            ORDER BY `
{$args['orderby']}{$args['order']}
            LIMIT 
{$args['limit']}
        "
ARRAY_A );

        
// Decode slider data
        
if(is_array($result) && !empty($result)) {

            if( ! empty( 
$args['data'] ) ) {
                foreach(
$result as $key => $slider) {
                    
$result[$key]['data'] = json_decode($slider['data'], true);
                }
            }

            return 
$result;

        
// Failed query
        
} else {
            return 
false;
        }
    }



    private static function 
_getById($id null) {

        
// Check ID
        
if(!is_int($id)) { return false; }

        
// Get Sliders
        
global $wpdb;
        
$table $wpdb->prefix.LS_DB_TABLE;
        
$result $wpdb->get_row("SELECT * FROM $table WHERE id = '$id' ORDER BY id DESC LIMIT 1"ARRAY_A);

        
// Check return value
        
if(!is_array($result)) { return false; }

        
// Return result
        
$result['data'] = json_decode($result['data'], true);
        return 
$result;
    }



    private static function 
_getByIds($ids null) {

        
// Check ID
        
if(!is_array($ids)) { return false; }

        
// DB stuff
        
global $wpdb;
        
$table $wpdb->prefix.LS_DB_TABLE;
        
$limit count($ids);

        
// Collect IDs
        
if(is_array($ids) && !empty($ids)) {
            
$tmp = array();
            foreach(
$ids as $id) {
                
$tmp[] = 'id = \''.intval($id).'\'';
            }
            
$ids implode(' OR '$tmp);
            unset(
$tmp);
        }

        
// Make the call
        
$result $wpdb->get_results("SELECT * FROM $table WHERE $ids ORDER BY id DESC LIMIT $limit"ARRAY_A);

        
// Decode slider data
        
if(is_array($result) && !empty($result)) {
            foreach(
$result as $key => $slider) {
                
$result[$key]['data'] = json_decode($slider['data'], true);
            }

            return 
$result;

        
// Failed query
        
} else {
            return 
false;
        }
    }





    private static function 
_getBySlug($slug) {

        
// Check slug
        
if(empty($slug)) { return false; }
            else { 
$slug esc_sql($slug); }

        
// Get DB stuff
        
global $wpdb;
        
$table $wpdb->prefix.LS_DB_TABLE;

        
// Make the call
        
$result $wpdb->get_row("SELECT * FROM $table WHERE slug = '$slug' ORDER BY id DESC LIMIT 1"ARRAY_A);

        
// Check return value
        
if(!is_array($result)) { return false; }

        
// Return result
        
$result['data'] = json_decode($result['data'], true);
        return 
$result;
    }



    private static function 
_getRandom() {

        
// Get DB stuff
        
global $wpdb;
        
$table $wpdb->prefix.LS_DB_TABLE;

        
// Make the call
        
$result $wpdb->get_row("SELECT * FROM $table WHERE flag_hidden = '0' AND flag_deleted = '0' ORDER BY RAND() LIMIT 1"ARRAY_A);

        
// Check return value
        
if(!is_array($result)) { return false; }

        
// Return result
        
$result['data'] = json_decode($result['data'], true);
        return 
$result;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586