/var/www/hkosl.com/aga/wp-content/plugins/smart-slider-3/includes/widget.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
<?php

class N2SS3Widget extends WP_Widget {

    private 
$preventRender false;

    function 
__construct() {

        
parent::__construct('smartslider3'// Base ID
            
'Smart Slider'// Name
            
array('description' => 'Displays a Smart Slider'// Args
        
);

        
// YOAST SEO fix
        
add_action('wpseo_head', array(
            
$this,
            
'preventRender'
        
), 0);
        
add_action('wpseo_head', array(
            
$this,
            
'notPreventRender'
        
), 10000000000);
    }

    public static function 
register_widget() {
        
register_widget('N2SS3Widget');
    }

    public function 
preventRender() {
        
$this->preventRender true;
    }

    public function 
notPreventRender() {
        
$this->preventRender false;
    }

    function 
widget($args$instance) {
        global 
$wpdb;
        if (
$this->preventRender) {
            return;
        }
        
$instance array_merge(array(
            
'id'     => md5(time()),
            
'slider' => 0,
            
'title'  => ''
        
), $instance);

        if (
$instance['slider'] === 0) {

            
$instance['slider'] = $wpdb->get_var('SELECT id FROM ' $wpdb->prefix 'nextend2_smartslider3_sliders LIMIT 0,1');
        }

        
$slider do_shortcode('[smartslider3 slider=' $instance['slider'] . ']');

        if (
$slider != '') {

            
$title apply_filters('widget_title'$instance['title'], $instance$this->id_base);

            echo 
$args['before_widget'];
            if (!empty(
$title)) echo $args['before_title'] . $title $args['after_title'];

            echo 
$slider;

            echo 
$args['after_widget'];
        }
    }

    function 
form($instance) {
        
$instance wp_parse_args((array)$instance, array(
            
'title'  => '',
            
'slider' => 0
        
));
        
$title    $instance['title'];

        
N2SSShortcodeInsert::addForced();

        
?>

        <p>
            <?php
            N2base
::getApplication('smartslider')
                  ->
getApplicationType('backend');
            
N2Loader::import("models.Sliders""smartslider");

            
$slidersModel = new N2SmartsliderSlidersModel();

            
$choices = array();
            foreach (
$slidersModel->getAll(0) AS $slider) {
                if (
$slider['type'] == 'group') {

                    
$subChoices = array();
                    if (!empty(
$slider['alias'])) {
                        
$subChoices[$slider['alias']] = n2_('Whole group') . ' - ' $slider['title'] . ' #Alias: ' $slider['alias'];
                    }
                    
$subChoices[$slider['id']] = n2_('Whole group') . ' - ' $slider['title'] . ' #' $slider['id'];
                    foreach (
$slidersModel->getAll($slider['id']) AS $_slider) {
                        if (!empty(
$_slider['alias'])) {
                            
$subChoices[$_slider['alias']] = $_slider['title'] . ' #Alias: ' $_slider['alias'];
                        }
                        
$subChoices[$_slider['id']] = $_slider['title'] . ' #' $_slider['id'];
                    }

                    
$choices[$slider['id']] = array(
                        
'label'   => $slider['title'] . ' #' $slider['id'],
                        
'choices' => $subChoices
                    
);
                } else {
                    if (!empty(
$slider['alias'])) {
                        
$choices[$slider['alias']] = $slider['title'] . ' #Alias: ' $slider['alias'];
                    }
                    
$choices[$slider['id']] = $slider['title'] . ' #' $slider['id'];
                }

            }
            
$value $instance['slider'];

            
$_title '';
            
?>
            <select id="<?php echo $this->get_field_id('slider'); ?>" onchange="jQuery('#<?php echo $this->get_field_id('temp-title'); ?>').val(jQuery(this).find('option:selected').text()).trigger('change');" name="<?php echo $this->get_field_name('slider'); ?>" class="widefat">
                    <option value=""><?php n2_e('None'); ?></option>
                <?php
                
foreach ($choices AS $id => $choice) {
                    if (
is_array($choice)) {
                        
?>
                        <optgroup label="<?php echo $choice['label']; ?>">
                                <?php
                                
foreach ($choice['choices'] AS $_id => $_choice) {
                                    
?>
                                    <option <?php if ($_id == $value){
                                            
$_title $_choice?>selected <?php ?>value="<?php echo $_id?>"><?php echo $_choice?></option>
                                    <?php
                                
}
                                
?>
                            </optgroup>
                        <?php
                    
} else {
                        
?>
                        <option <?php if ($id == $value){
                                
$_title $choice?>selected <?php ?>value="<?php echo $id?>"><?php echo $choice?></option>
                        <?php
                    
}
                }
                
?>
                </select>
        <input id="<?php echo $this->get_field_id('temp-title'); ?>"
               name="<?php echo $this->get_field_name('temp-title'); ?>" type="hidden"
               value="<?php echo $_title?>"/>

        <span style="display:block;line-height:2;padding:10px;"><?php n2_e('OR'); ?></span>

        <a style="vertical-align: top;" href="#" onclick="<?php echo SmartSlider3::sliderSelectAction('jQuery(\'#' $this->get_field_id('slider') . '\')'); ?>return false;" class="button button-primary elementor-button elementor-button-smartslider fl-builder-button fl-builder-button-large" title="Select slider">Select slider</a>
        </p>
        <p>
            <label for="<?php echo $this->get_field_id('title'); ?>">
                Title:
                <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
                       name="<?php echo $this->get_field_name('title'); ?>" type="text"
                       value="<?php echo esc_attr($title); ?>"/>
            </label>
        </p>
        <?php
    
}

    function 
update($new_instance$old_instance) {
        
$instance           $old_instance;
        
$instance['title']  = $new_instance['title'];
        
$instance['slider'] = $new_instance['slider'];

        return 
$instance;
    }
}

add_action('widgets_init''N2SS3Widget::register_widget');