/var/www/hkosl.com/aga/wp-content/plugins/so-widgets-bundle/base/inc/fields/posts.class.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
<?php

/**
 * Class SiteOrigin_Widget_Field_Posts
 */
class SiteOrigin_Widget_Field_Posts extends SiteOrigin_Widget_Field_Container_Base {
    
    
/**
     * An array of post types to use in the query for posts when the 'Select Content' button is clicked.
     *
     * @access protected
     * @var array
     */
    
protected $post_types;

    public function 
__construct$base_name$element_id$element_name$field_optionsSiteOrigin_Widget $for_widget$parent_container = array() ) {
        
parent::__construct$base_name$element_id$element_name$field_options$for_widget$parent_container );

        
$types        get_post_types( array( 'public' => true ), 'objects' );
        
$type_options = array();
        
        if ( empty( 
$this->post_types ) || in_array'_all'$this->post_types ) ) {
            
$type_options['_all'] = __'All''so-widgets-bundle' );
        }

        foreach ( 
$types as $id => $type ) {
            if ( empty( 
$this->post_types ) || in_array$id$this->post_types ) ) {
                
$type_options$id ] = $type->labels->name;
            }
        }

        
$this->fields = array(

            
'post_type' => array(
                
'type'     => 'select',
                
'label'    => __'Post type''so-widgets-bundle' ),
                
'multiple' => true,
                
'options'  => $type_options,
                
'default'  => 'post'
            
),

            
'post__in' => array(
                
'type'  => 'autocomplete',
                
'label' => __'Post in''so-widgets-bundle' ),
                
'source' => 'posts',
            ),

            
'tax_query' => array(
                
'type'  => 'autocomplete',
                
'label' => __'Taxonomies''so-widgets-bundle' ),
                
'source' => 'terms',
                
'description' => __'Taxonomies are groups such as categories, tags, posts and products.''so-widgets-bundle' ),
            ),

            
'date_type' => array(
                
'type' => 'radio',
                
'label' => __'Date selection type''so-widgets-bundle' ),
                
'options' => array(
                    
'specific' => __'Specific''so-widgets-bundle' ),
                    
'relative' => __'Relative''so-widgets-bundle' ),
                ),
                
'description' => __'Select a range between specific dates or relative to the current date.''so-widgets-bundle' ),
                
'default' => 'specific',
                
'state_emitter' => array(
                    
'callback' => 'select',
                    
'args' => array( 'date_type' )
                ),
            ),

            
'date_query' => array(
                
'type'  => 'date-range',
                
'label' => __'Dates''so-widgets-bundle' ),
                
'date_type' => 'specific',
                
'state_handler' => array(
                    
'date_type[specific]' => array('show'),
                    
'_else[date_type]' => array('hide'),
                ),
            ),

            
'date_query_relative' => array(
                
'type'  => 'date-range',
                
'label' => __'Dates''so-widgets-bundle' ),
                
'date_type' => 'relative',
                
'state_handler' => array(
                    
'date_type[relative]' => array('show'),
                    
'_else[date_type]' => array('hide'),
                ),
            ),

            
'orderby' => array(
                
'type'    => 'select',
                
'label'   => __'Order by''so-widgets-bundle' ),
                
'options' => array(
                    
'none'           => __'No order''so-widgets-bundle' ),
                    
'ID'             => __'Post ID''so-widgets-bundle' ),
                    
'author'         => __'Author''so-widgets-bundle' ),
                    
'title'          => __'Title''so-widgets-bundle' ),
                    
'date'           => __'Published date''so-widgets-bundle' ),
                    
'modified'       => __'Modified date''so-widgets-bundle' ),
                    
'parent'         => __'By parent''so-widgets-bundle' ),
                    
'rand'           => __'Random order''so-widgets-bundle' ),
                    
'comment_count'  => __'Comment count''so-widgets-bundle' ),
                    
'menu_order'     => __'Menu order''so-widgets-bundle' ),
                    
'meta_value'     => __'By meta value''so-widgets-bundle' ),
                    
'meta_value_num' => __'By numeric meta value''so-widgets-bundle' ),
                    
'post__in'       => __'By include order''so-widgets-bundle' ),
                ),
                
'default' => 'date',
            ),

            
'order' => array(
                
'type'    => 'radio',
                
'label'   => __'Order direction''so-widgets-bundle' ),
                
'options' => array(
                    
'ASC'  => __'Ascending''so-widgets-bundle' ),
                    
'DESC' => __'Descending''so-widgets-bundle' ),
                ),
                
'default' => 'DESC',
            ),

            
'posts_per_page' => array(
                
'type'  => 'number',
                
'label' => __'Posts per page''so-widgets-bundle' ),
            ),

            
'sticky' => array(
                
'type'    => 'select',
                
'label'   => __'Sticky posts''so-widgets-bundle' ),
                
'options' => array(
                    
''        => __'Default''so-widgets-bundle' ),
                    
'ignore'  => __'Ignore sticky''so-widgets-bundle' ),
                    
'exclude' => __'Exclude sticky''so-widgets-bundle' ),
                    
'only'    => __'Only sticky''so-widgets-bundle' ),
                ),
            ),

            
'additional' => array(
                
'type'        => 'text',
                
'label'       => __'Additional''so-widgets-bundle' ),
                
'description' => __'Additional query arguments. See <a href="http://codex.wordpress.org/Function_Reference/query_posts" target="_blank" rel="noopener noreferrer">query_posts</a>.''so-widgets-bundle' ),
            ),
        );
    }

    protected function 
render_field_label$value$instance ) {
        
?><div class="posts-container-label-wrapper<?php if ( $this->state == 'open' ) {
            echo 
' siteorigin-widget-section-visible';
        } 
?>"><?php
        parent
::render_field_label$value$instance );
        
?><span class="sow-current-count"><?php echo esc_htmlsiteorigin_widget_post_selector_count_posts$value ) )?></span>
        </div><?php
    
}

    protected function 
render_field$value$instance ) {
        
$value wp_parse_args$value );
        
        if( !empty( 
$value['post_type'] ) ) {
            
$value['post_type'] = strpos$value['post_type'], ',' ) !== false explode','$value['post_type'] ) : $value['post_type'];
        }
        
        if ( 
$this->collapsible ) {
            
?><div class="siteorigin-widget-section <?php if ( $this->state == 'closed' ) {
                echo 
'siteorigin-widget-section-hide';
            } 
?>"><?php
        
}

        
$this->create_and_render_sub_fields$value, array( 'name' => $this->base_name'type' => 'composite' ) );

        if ( 
$this->collapsible ) {
            
?></div><?php
        
}
    }

    public function 
enqueue_scripts() {
        
wp_enqueue_script(
            
'so-posts-selector-field',
            
plugin_dir_url__FILE__ ) . 'js/posts-field' SOW_BUNDLE_JS_SUFFIX '.js',
            array( 
'jquery' ),
            
SOW_BUNDLE_VERSION,
            
true
        
);
    }

    protected function 
sanitize_field_input$value$instance ) {
        
// Special handling for the 'additional' args field.
        
if ( ! empty( $value['additional'] ) ) {
            
$value['additional'] = urlencode$value['additional'] );
        }
        
$value parent::sanitize_field_input$value$instance );
        
$result '';
        foreach ( 
$value as $key => $item ) {
            if ( ! empty( 
$item ) ) {
                if ( 
is_array$item ) ) {
                    
$item implode','$item );
                }
                
$result .= ( empty( $result ) ? '' '&' ) . $key '=' $item;
            }
        }

        return 
$result;
    }

}