Test Failed
Push — master ( e3dc1d...73d69d )
by Stiofan
18:03
created

geodir_popular_postview   C

Complexity

Total Complexity 54

Size/Duplication

Total Lines 419
Duplicated Lines 3.82 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 84.95%

Importance

Changes 0
Metric Value
dl 16
loc 419
ccs 79
cts 93
cp 0.8495
rs 6.8539
c 0
b 0
f 0
wmc 54
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A widget() 0 4 1
F update() 4 34 16
F form() 12 332 36

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like geodir_popular_postview often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use geodir_popular_postview, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * GeoDirectory Popular Post Category Widget & GeoDirectory Popular Post View Widget
4
 *
5
 * @since 1.0.0
6
 *
7
 * @package GeoDirectory
8
 */
9
10
/**
11
 * GeoDirectory popular post category widget class.
12
 *
13
 * @since 1.0.0
14
 */
15
class geodir_popular_post_category extends WP_Widget
16
{
17
    /**
18
     * Register the popular post category widget.
19
     *
20
     * @since 1.0.0
21
     * @since 1.5.1 Changed from PHP4 style constructors to PHP5 __construct.
22
     */
23 1
    public function __construct() {
24 1
        $widget_ops = array('classname' => 'geodir_popular_post_category', 'description' => __('GD > Popular Post Category', 'geodirectory'));
25 1
        parent::__construct(
26 1
            'popular_post_category', // Base ID
27 1
            __('GD > Popular Post Category', 'geodirectory'), // Name
28
            $widget_ops// Args
29 1
        );
30 1
    }
31
32
    /**
33
     * Front-end display content for popular post category widget.
34
     *
35
     * @since 1.0.0
36
     * @since 1.5.1 Declare function public.
37
     *
38
     * @param array $args     Widget arguments.
39
     * @param array $instance Saved values from database.
40
     */
41 1
    public function widget($args, $instance)
42
    {
43 1
        geodir_popular_post_category_output($args, $instance);
44 1
    }
45
46
    /**
47
     * Sanitize popular post category widget form values as they are saved.
48
     *
49
     * @since 1.0.0
50
     * @since 1.5.1 Declare function public.
51
     * @since 1.5.1 Added default_post_type parameter.
52
     * @since 1.6.9 Added parent_only parameter.
53
     *
54
     * @param array $new_instance Values just sent to be saved.
55
     * @param array $old_instance Previously saved values from database.
56
     *
57
     * @return array Updated safe values to be saved.
58 1
     */ 
59
    public function update($new_instance, $old_instance)
60
    {
61 1
        //save the widget
62 1
        $instance = $old_instance;
63 1
        $instance['title'] = strip_tags($new_instance['title']);
64 1
        $category_limit = (int)$new_instance['category_limit'];
65 1
        $instance['category_limit'] = $category_limit > 0 ? $category_limit : 15;
66 1
        $instance['default_post_type'] = isset($new_instance['default_post_type']) ? $new_instance['default_post_type'] : '';
67
        $instance['parent_only'] = !empty($new_instance['parent_only']) ? true : false;
68
        return $instance;
69
    }
70
71
    /**
72
     * Back-end popular post category widget settings form.
73
     *
74
     * @since 1.0.0
75
     * @since 1.5.1 Declare function public.
76
     * @since 1.5.1 Added option to set default post type.
77
     * @since 1.6.9 Added option to show parent categories only.
78 1
     *
79
     * @param array $instance Previously saved values from database.
80
     */
81 1
    public function form($instance) 
82
    {
83 1
        //widgetform in backend
84 1
        $instance = wp_parse_args((array)$instance, array('title' => '', 'category_limit' => 15, 'default_post_type' => '', 'parent_only' => false));
85 1
86 1
        $title = strip_tags($instance['title']);
87
        $category_limit = (int)$instance['category_limit'];
88 1
        $category_limit = $category_limit > 0 ? $category_limit : 15;
89
        $default_post_type = isset($instance['default_post_type']) ? $instance['default_post_type'] : '';
90
        $parent_only = !empty($instance['parent_only']) ? true: false;
91
        
92
        $post_type_options = geodir_get_posttypes('options');
93
        ?>
94
        <p>
95
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'geodirectory'); ?>
96
                <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); ?>"/>
97
            </label>
98
        </p>
99
        <p>
100
            <label for="<?php echo $this->get_field_id('post_type'); ?>"><?php _e('Default post type to use (if not set by page)', 'geodirectory');?>
101
                <select class="widefat" id="<?php echo $this->get_field_id('default_post_type'); ?>" name="<?php echo $this->get_field_name('default_post_type'); ?>">
102
                <?php foreach ($post_type_options as $name => $title) { ?>
0 ignored issues
show
Bug introduced by
The expression $post_type_options of type array|object|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
103
                    <option value="<?php echo $name;?>" <?php selected($name, $default_post_type);?>><?php echo $title; ?></option>
104
                <?php } ?>
105
                </select>
106
            </label>
107
        </p>
108
        <p>
109
            <label for="<?php echo $this->get_field_id('category_limit'); ?>"><?php _e('Customize categories count to appear by default:', 'geodirectory'); ?>
110
                <input class="widefat" id="<?php echo $this->get_field_id('category_limit'); ?>" name="<?php echo $this->get_field_name('category_limit'); ?>" type="text" value="<?php echo (int)esc_attr($category_limit); ?>"/>
111
                <p class="description" style="padding:0"><?php _e('After categories count reaches this limit option More Categories / Less Categoris will be displayed to show/hide categories. Default: 15', 'geodirectory'); ?></p>
112
            </label>
113
        </p>
114
        <p>
115
            <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('parent_only'); ?>" name="<?php echo $this->get_field_name('parent_only'); ?>"<?php checked( $parent_only ); ?> value="1" />
116
            <label for="<?php echo $this->get_field_id('parent_only'); ?>"><?php _e( 'Show parent categories only', 'geodirectory' ); ?></label>
117
        </p>
118
    <?php
119 1
    }
120
} // class geodir_popular_post_category
121
122 1
register_widget('geodir_popular_post_category');
123
124
125
/**
126
 * GeoDirectory popular posts widget class.
127
 *
128
 * @since 1.0.0
129
 */
130
class geodir_popular_postview extends WP_Widget
131
{
132
133
    /**
134
	 * Register the popular posts widget.
135
	 *
136
	 * @since 1.0.0
137
     * @since 1.5.1 Changed from PHP4 style constructors to PHP5 __construct.
138
	 */
139 1
    public function __construct() {
140 1
        $widget_ops = array('classname' => 'geodir_popular_post_view', 'description' => __('GD > Popular Post View', 'geodirectory'));
141 1
        parent::__construct(
142 1
            'popular_post_view', // Base ID
143 1
            __('GD > Popular Post View', 'geodirectory'), // Name
144
            $widget_ops// Args
145 1
        );
146 1
    }
147
148
	/**
149
	 * Front-end display content for popular posts widget.
150
	 *
151
	 * @since 1.0.0
152
     * @since 1.5.1 Declare function public.
153
	 *
154
	 * @param array $args     Widget arguments.
155
	 * @param array $instance Saved values from database.
156
	 */
157 1
	public function widget($args, $instance)
158
    {
159 1
        geodir_popular_postview_output($args, $instance);
160 1
    }
161
162
	/**
163
	 * Sanitize popular posts widget form values as they are saved.
164
	 *
165
	 * @since 1.0.0
166
     * @since 1.5.1 Declare function public.
167
	 *
168
	 * @param array $new_instance Values just sent to be saved.
169
	 * @param array $old_instance Previously saved values from database.
170
	 *
171
	 * @return array Updated safe values to be saved.
172
	 */
173 1
	public function update($new_instance, $old_instance)
174
    {
175
        //save the widget
176 1
        $instance = $old_instance;
177
178 1
        if ($new_instance['title'] == '') {
179 1
            $title = geodir_ucwords(strip_tags($new_instance['category_title']));
0 ignored issues
show
Unused Code introduced by
$title is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
180
            //$instance['title'] = $title;
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
181 1
        }
182 1
        $instance['title'] = strip_tags($new_instance['title']);
183
184 1
        $instance['post_type'] = strip_tags($new_instance['post_type']);
185
        //$instance['category'] = strip_tags($new_instance['category']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
186 1
        $instance['category'] = isset($new_instance['category']) ? $new_instance['category'] : '';
187 1
        $instance['category_title'] = strip_tags($new_instance['category_title']);
188 1
        $instance['post_number'] = strip_tags($new_instance['post_number']);
189 1
        $instance['layout'] = strip_tags($new_instance['layout']);
190 1
        $instance['listing_width'] = strip_tags($new_instance['listing_width']);
191 1
        $instance['list_sort'] = strip_tags($new_instance['list_sort']);
192 1
        $instance['character_count'] = $new_instance['character_count'];
193 1 View Code Duplication
        if (isset($new_instance['add_location_filter']) && $new_instance['add_location_filter'] != '')
194 1
            $instance['add_location_filter'] = strip_tags($new_instance['add_location_filter']);
195
        else
196
            $instance['add_location_filter'] = '0';
197
198 1
        $instance['show_featured_only'] = isset($new_instance['show_featured_only']) && $new_instance['show_featured_only'] ? 1 : 0;
199 1
        $instance['show_special_only'] = isset($new_instance['show_special_only']) && $new_instance['show_special_only'] ? 1 : 0;
200 1
        $instance['with_pics_only'] = isset($new_instance['with_pics_only']) && $new_instance['with_pics_only'] ? 1 : 0;
201 1
        $instance['with_videos_only'] = isset($new_instance['with_videos_only']) && $new_instance['with_videos_only'] ? 1 : 0;
202 1
        $instance['use_viewing_post_type'] = isset($new_instance['use_viewing_post_type']) && $new_instance['use_viewing_post_type'] ? 1 : 0;
203
        $instance['hide_if_empty'] = !empty($new_instance['hide_if_empty']) ? 1 : 0;
204 1
205
        return $instance;
206
    }
207
208
	/**
209
	 * Back-end popular posts widget settings form.
210
	 *
211
	 * @since 1.0.0
212
     * @since 1.5.1 Declare function public.
213
	 *
214
	 * @param array $instance Previously saved values from database.
215 1
	 */
216
	public function form($instance)
217
    {
218 1
        //widgetform in backend
219 1
        $instance = wp_parse_args((array)$instance,
220 1
            array('title' => '',
221 1
                'post_type' => '',
222 1
                'category' => array(),
223 1
                'category_title' => '',
224 1
                'list_sort' => '',
225 1
                'list_order' => '',
226 1
                'post_number' => '5',
227 1
                'layout' => 'gridview_onehalf',
228 1
                'listing_width' => '',
229 1
                'add_location_filter' => '1',
230 1
                'character_count' => '20',
231 1
                'show_featured_only' => '',
232 1
                'show_special_only' => '',
233 1
                'with_pics_only' => '',
234
                'with_videos_only' => '',
235 1
                'use_viewing_post_type' => '',
236 1
                'hide_if_empty' => ''
237
            )
238 1
        );
239
240 1
        $title = strip_tags($instance['title']);
241
242 1
        $post_type = strip_tags($instance['post_type']);
243
244 1
        $category = $instance['category'];
245
246 1
        $category_title = strip_tags($instance['category_title']);
247
248 1
        $list_sort = strip_tags($instance['list_sort']);
249
250 1
        $list_order = strip_tags($instance['list_order']);
0 ignored issues
show
Unused Code introduced by
$list_order is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
251
252 1
        $post_number = strip_tags($instance['post_number']);
253
254 1
        $layout = strip_tags($instance['layout']);
255
256 1
        $listing_width = strip_tags($instance['listing_width']);
257
258 1
        $add_location_filter = strip_tags($instance['add_location_filter']);
259
260 1
        $character_count = $instance['character_count'];
261 1
262 1
        $show_featured_only = isset($instance['show_featured_only']) && $instance['show_featured_only'] ? true : false;
263 1
        $show_special_only = isset($instance['show_special_only']) && $instance['show_special_only'] ? true : false;
264 1
        $with_pics_only = isset($instance['with_pics_only']) && $instance['with_pics_only'] ? true : false;
265
        $with_videos_only = isset($instance['with_videos_only']) && $instance['with_videos_only'] ? true : false;
266
        $use_viewing_post_type = isset($instance['use_viewing_post_type']) && $instance['use_viewing_post_type'] ? true : false;
267
        $hide_if_empty = !empty($instance['hide_if_empty']) ? true : false;
268
269
        ?>
270
        <p>
271
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'geodirectory');?>
272
                <small>(%posttype_singular_label% ,
273
                    %posttype_plural_label% <?php _e('can be used', 'geodirectory');?>)
274
                </small>
275
276
                <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
277
                       name="<?php echo $this->get_field_name('title'); ?>" type="text"
278
                       value="<?php echo esc_attr($title); ?>"/>
279
            </label>
280
        </p>
281
282
        <p>
283
            <label
284
                for="<?php echo $this->get_field_id('post_type'); ?>"><?php _e('Post Type:', 'geodirectory');?>
285
286
                <?php $postypes = geodir_get_posttypes();
287
				/**
288
				 * Filter the post types to display in widget.
289
				 *
290
				 * @since 1.0.0
291
				 *
292
				 * @param array $postypes Post types array.
293
				 */
294
				$postypes = apply_filters('geodir_post_type_list_in_p_widget', $postypes); ?>
295
296
                <select class="widefat" id="<?php echo $this->get_field_id('post_type'); ?>"
297
                        name="<?php echo $this->get_field_name('post_type'); ?>"
298
                        onchange="geodir_change_category_list(this)">
299
300 View Code Duplication
                    <?php foreach ($postypes as $postypes_obj) { ?>
301
302
                        <option <?php if ($post_type == $postypes_obj) {
303
                            echo 'selected="selected"';
304
                        } ?> value="<?php echo $postypes_obj; ?>"><?php $extvalue = explode('_', $postypes_obj);
305
                            echo geodir_utf8_ucfirst($extvalue[1]); ?></option>
306
307
                    <?php } ?>
308
309
                </select>
310
            </label>
311
        </p>
312
313
314
        <p id="post_type_cats">
315
            <label
316
                for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Post Category:', 'geodirectory');?>
317
318 1
                <?php
319
320 1
                $post_type = ($post_type != '') ? $post_type : 'gd_place';
321
322 1
                $all_postypes = geodir_get_posttypes();
323 1
324
                if (!in_array($post_type, $all_postypes))
325 1
                    $post_type = 'gd_place';
326 1
327
                $category_taxonomy = geodir_get_taxonomies($post_type);
328
                $categories = get_terms($category_taxonomy, array('orderby' => 'count', 'order' => 'DESC'));
329
330
                ?>
331
332
                <select multiple="multiple" class="widefat" name="<?php echo $this->get_field_name('category'); ?>[]"
333
                        onchange="geodir_popular_widget_cat_title(this)">
334
335
                    <option <?php if (!is_array($category) || (is_array($category) && in_array('0', $category))) {
336
                        echo 'selected="selected"';
337 1
                    } ?> value="0"><?php _e('All', 'geodirectory'); ?></option>
338 1
                    <?php foreach ($categories as $category_obj) {
339 1
                        $selected = '';
340
                        if (is_array($category) && in_array($category_obj->term_id, $category))
341
                            echo $selected = 'selected="selected"';
342
343
                        ?>
344
345
                        <option <?php echo $selected; ?>
346
                            value="<?php echo $category_obj->term_id; ?>"><?php echo geodir_utf8_ucfirst($category_obj->name); ?></option>
347
348
                    <?php } ?>
349
350
                </select>
351
352
353
                <input type="hidden" name="<?php echo $this->get_field_name('category_title'); ?>"
354
                       id="<?php echo $this->get_field_id('category_title'); ?>"
355
                       value="<?php if ($category_title != '') echo $category_title; else echo __('All', 'geodirectory');?>"/>
356
357
            </label>
358
        </p>
359
360
        <p>
361
            <label for="<?php echo $this->get_field_id('list_sort'); ?>"><?php _e('Sort by:', 'geodirectory');?>
362
363
                <?php
364
                $list_sort_arr = array(
365
                    "az"        =>  __('A-Z', 'geodirectory'),
366
                    "latest"        =>  __('Latest', 'geodirectory'),
367
                    "featured"        =>  __('Featured', 'geodirectory'),
368
                    "high_review"        =>  __('Review', 'geodirectory'),
369
                    "high_rating"        =>  __('Rating', 'geodirectory'),
370
                    "random"        =>  __('Random', 'geodirectory'),
371
                );
372
373
                /**
374
                 * Filter the Popular post view widget sorting options.
375
                 *
376
                 * @since 1.6.22
377
                 * @param array $list_sort_arr The array of key value pairs of settings.
378
                 * @param array $instance The array of widget settings.
379
                 */
380
                $list_sort_arr = apply_filters('geodir_popular_post_view_list_sort',$list_sort_arr,$instance);
381
                ?>
382
383
                <select class="widefat" id="<?php echo $this->get_field_id('list_sort'); ?>"
384
                        name="<?php echo $this->get_field_name('list_sort'); ?>">
385
                    <?php
386
                    foreach($list_sort_arr as $sort_val => $sort_title){
387
                        echo "<option value='$sort_val' ".selected($list_sort,$sort_val)." >$sort_title</option>";
388
                    }
389
                    ?>
390
                </select>
391
            </label>
392
        </p>
393
394
        <p>
395
396
            <label
397
                for="<?php echo $this->get_field_id('post_number'); ?>"><?php _e('Number of posts:', 'geodirectory');?>
398
399
                <input class="widefat" id="<?php echo $this->get_field_id('post_number'); ?>"
400
                       name="<?php echo $this->get_field_name('post_number'); ?>" type="text"
401
                       value="<?php echo esc_attr($post_number); ?>"/>
402
            </label>
403
        </p>
404
405
        <p>
406
            <label for="<?php echo $this->get_field_id('layout'); ?>">
407
                <?php _e('Layout:', 'geodirectory');?>
408
                <select class="widefat" id="<?php echo $this->get_field_id('layout'); ?>"
409
                        name="<?php echo $this->get_field_name('layout'); ?>">
410 1
                    <option <?php if ($layout == 'gridview_onehalf') {
411
                        echo 'selected="selected"';
412
                    } ?>
413
                        value="gridview_onehalf"><?php _e('Grid View (Two Columns)', 'geodirectory'); ?></option>
414
                    <option <?php if ($layout == 'gridview_onethird') {
415
                        echo 'selected="selected"';
416
                    } ?>
417
                        value="gridview_onethird"><?php _e('Grid View (Three Columns)', 'geodirectory'); ?></option>
418
                    <option <?php if ($layout == 'gridview_onefourth') {
419
                        echo 'selected="selected"';
420
                    } ?>
421
                        value="gridview_onefourth"><?php _e('Grid View (Four Columns)', 'geodirectory'); ?></option>
422
                    <option <?php if ($layout == 'gridview_onefifth') {
423
                        echo 'selected="selected"';
424
                    } ?>
425
                        value="gridview_onefifth"><?php _e('Grid View (Five Columns)', 'geodirectory'); ?></option>
426
                    <option <?php if ($layout == 'list') {
427
                        echo 'selected="selected"';
428
                    } ?> value="list"><?php _e('List view', 'geodirectory'); ?></option>
429
430
                </select>
431
            </label>
432
        </p>
433
434
        <p>
435
            <label
436
                for="<?php echo $this->get_field_id('listing_width'); ?>"><?php _e('Listing width:', 'geodirectory');?>
437
438
                <input class="widefat" id="<?php echo $this->get_field_id('listing_width'); ?>"
439
                       name="<?php echo $this->get_field_name('listing_width'); ?>" type="text"
440
                       value="<?php echo esc_attr($listing_width); ?>"/>
441
            </label>
442
        </p>
443
444
        <p>
445
            <label
446
                for="<?php echo $this->get_field_id('character_count'); ?>"><?php _e('Post Content excerpt character count :', 'geodirectory');?>
447
                <input class="widefat" id="<?php echo $this->get_field_id('character_count'); ?>"
448
                       name="<?php echo $this->get_field_name('character_count'); ?>" type="text"
449
                       value="<?php echo esc_attr($character_count); ?>"/>
450
            </label>
451
        </p>
452
453
        <p>
454
            <label for="<?php echo $this->get_field_id('add_location_filter'); ?>">
455
                <?php _e('Enable Location Filter:', 'geodirectory');?>
456
                <input type="checkbox" id="<?php echo $this->get_field_id('add_location_filter'); ?>"
457
                       name="<?php echo $this->get_field_name('add_location_filter'); ?>" <?php if ($add_location_filter) echo 'checked="checked"';?>
458
                       value="1"/>
459
            </label>
460
        </p>
461
        <p>
462
            <label for="<?php echo $this->get_field_id('show_featured_only'); ?>">
463
                <?php _e('Show only featured listings:', 'geodirectory');?> <input type="checkbox"
464
                                                                                            id="<?php echo $this->get_field_id('show_featured_only'); ?>"
465
                                                                                            name="<?php echo $this->get_field_name('show_featured_only'); ?>" <?php if ($show_featured_only) echo 'checked="checked"';?>
466
                                                                                            value="1"/>
467
            </label>
468
        </p>
469
        <p>
470
            <label for="<?php echo $this->get_field_id('show_special_only'); ?>">
471
                <?php _e('Show only listings with special offers:', 'geodirectory');?> <input type="checkbox"
472
                                                                                                       id="<?php echo $this->get_field_id('show_special_only'); ?>"
473
                                                                                                       name="<?php echo $this->get_field_name('show_special_only'); ?>" <?php if ($show_special_only) echo 'checked="checked"';?>
474
                                                                                                       value="1"/>
475
            </label>
476
        </p>
477
        <p>
478
            <label for="<?php echo $this->get_field_id('with_pics_only'); ?>">
479
                <?php _e('Show only listings with pics:', 'geodirectory');?> <input type="checkbox"
480
                                                                                             id="<?php echo $this->get_field_id('with_pics_only'); ?>"
481
                                                                                             name="<?php echo $this->get_field_name('with_pics_only'); ?>" <?php if ($with_pics_only) echo 'checked="checked"';?>
482
                                                                                             value="1"/>
483
            </label>
484
        </p>
485
        <p>
486
            <label for="<?php echo $this->get_field_id('with_videos_only'); ?>">
487
                <?php _e('Show only listings with videos:', 'geodirectory');?> <input type="checkbox"
488
                                                                                               id="<?php echo $this->get_field_id('with_videos_only'); ?>"
489
                                                                                               name="<?php echo $this->get_field_name('with_videos_only'); ?>" <?php if ($with_videos_only) echo 'checked="checked"';?>
490
                                                                                               value="1"/>
491
            </label>
492
        </p>
493
        <p>
494
            <label
495
                for="<?php echo $this->get_field_id('use_viewing_post_type'); ?>"><?php _e('Use current viewing post type:', 'geodirectory'); ?>
496
                <input type="checkbox" id="<?php echo $this->get_field_id('use_viewing_post_type'); ?>"
497
                       name="<?php echo $this->get_field_name('use_viewing_post_type'); ?>" <?php if ($use_viewing_post_type) {
498
                    echo 'checked="checked"';
499
                } ?>  value="1"/>
500
            </label>
501
        </p>
502
        <p>
503
            <label for="<?php echo $this->get_field_id('hide_if_empty'); ?>"><?php _e('Hide if no posts:', 'geodirectory'); ?> <input id="<?php echo $this->get_field_id('hide_if_empty'); ?>" name="<?php echo $this->get_field_name('hide_if_empty'); ?>" type="checkbox" value="1" <?php checked($hide_if_empty, true); ?> />
504
            </label>
505
        </p>
506
507
508
        <script type="text/javascript">
509
510
            function geodir_popular_widget_cat_title(val) {
511
512
                jQuery(val).find("option:selected").each(function (i) {
513
                    if (i == 0)
514
                        jQuery(val).closest('form').find('#post_type_cats input').val(jQuery(this).html());
515
516
                });
517
518
            }
519
520
            function geodir_change_category_list(obj, selected) {
521
                var post_type = obj.value;
522
523
                var ajax_url = '<?php echo geodir_get_ajax_url(); ?>'
524
525
                var myurl = ajax_url + "&geodir_ajax=admin_ajax&ajax_action=get_cat_dl&post_type=" + post_type + "&selected=" + selected;
526
527
                jQuery.ajax({
528
                    type: "GET",
529
                    url: myurl,
530
                    success: function (data) {
531
532
                        jQuery(obj).closest('form').find('#post_type_cats select').html(data);
533
534
                    }
535
                });
536
537
            }
538
539 View Code Duplication
            <?php if(is_active_widget( false, false, $this->id_base, true )){ ?>
540
            var post_type = jQuery('#<?php echo $this->get_field_id('post_type'); ?>').val();
541
542 1
            <?php } ?>
543
544
        </script>
545 1
546
    <?php
547
    }
548
} // class geodir_popular_postview
549
550
register_widget('geodir_popular_postview');