Test Failed
Pull Request — master (#411)
by Kiran
19:19
created

geodir_popular_postview   D

Complexity

Total Complexity 59

Size/Duplication

Total Lines 420
Duplicated Lines 3.81 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 84.95%

Importance

Changes 0
Metric Value
dl 16
loc 420
ccs 79
cts 93
cp 0.8495
rs 4.5454
c 0
b 0
f 0
wmc 59
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 333 41

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
362
                for="<?php echo $this->get_field_id('list_sort'); ?>"><?php _e('Sort by:', 'geodirectory');?>
363
364
                <select class="widefat" id="<?php echo $this->get_field_id('list_sort'); ?>"
365
                        name="<?php echo $this->get_field_name('list_sort'); ?>">
366
367
                    <option <?php if ($list_sort == 'az') {
368
                        echo 'selected="selected"';
369
                    } ?> value="az"><?php _e('A-Z', 'geodirectory'); ?></option>
370
371
                    <option <?php if ($list_sort == 'latest') {
372
                        echo 'selected="selected"';
373
                    } ?> value="latest"><?php _e('Latest', 'geodirectory'); ?></option>
374
375
                    <option <?php if ($list_sort == 'featured') {
376
                        echo 'selected="selected"';
377
                    } ?> value="featured"><?php _e('Featured', 'geodirectory'); ?></option>
378
379
                    <option <?php if ($list_sort == 'high_review') {
380
                        echo 'selected="selected"';
381
                    } ?> value="high_review"><?php _e('Review', 'geodirectory'); ?></option>
382
383
                    <option <?php if ($list_sort == 'high_rating') {
384
                        echo 'selected="selected"';
385
                    } ?> value="high_rating"><?php _e('Rating', 'geodirectory'); ?></option>
386
387
                    <option <?php if ($list_sort == 'random') {
388
                        echo 'selected="selected"';
389
                    } ?> value="random"><?php _e('Random', 'geodirectory'); ?></option>
390
391
                </select>
392
            </label>
393
        </p>
394
395
        <p>
396
397
            <label
398
                for="<?php echo $this->get_field_id('post_number'); ?>"><?php _e('Number of posts:', 'geodirectory');?>
399
400
                <input class="widefat" id="<?php echo $this->get_field_id('post_number'); ?>"
401
                       name="<?php echo $this->get_field_name('post_number'); ?>" type="text"
402
                       value="<?php echo esc_attr($post_number); ?>"/>
403
            </label>
404
        </p>
405
406
        <p>
407
            <label for="<?php echo $this->get_field_id('layout'); ?>">
408
                <?php _e('Layout:', 'geodirectory');?>
409
                <select class="widefat" id="<?php echo $this->get_field_id('layout'); ?>"
410 1
                        name="<?php echo $this->get_field_name('layout'); ?>">
411
                    <option <?php if ($layout == 'gridview_onehalf') {
412
                        echo 'selected="selected"';
413
                    } ?>
414
                        value="gridview_onehalf"><?php _e('Grid View (Two Columns)', 'geodirectory'); ?></option>
415
                    <option <?php if ($layout == 'gridview_onethird') {
416
                        echo 'selected="selected"';
417
                    } ?>
418
                        value="gridview_onethird"><?php _e('Grid View (Three Columns)', 'geodirectory'); ?></option>
419
                    <option <?php if ($layout == 'gridview_onefourth') {
420
                        echo 'selected="selected"';
421
                    } ?>
422
                        value="gridview_onefourth"><?php _e('Grid View (Four Columns)', 'geodirectory'); ?></option>
423
                    <option <?php if ($layout == 'gridview_onefifth') {
424
                        echo 'selected="selected"';
425
                    } ?>
426
                        value="gridview_onefifth"><?php _e('Grid View (Five Columns)', 'geodirectory'); ?></option>
427
                    <option <?php if ($layout == 'list') {
428
                        echo 'selected="selected"';
429
                    } ?> value="list"><?php _e('List view', 'geodirectory'); ?></option>
430
431
                </select>
432
            </label>
433
        </p>
434
435
        <p>
436
            <label
437
                for="<?php echo $this->get_field_id('listing_width'); ?>"><?php _e('Listing width:', 'geodirectory');?>
438
439
                <input class="widefat" id="<?php echo $this->get_field_id('listing_width'); ?>"
440
                       name="<?php echo $this->get_field_name('listing_width'); ?>" type="text"
441
                       value="<?php echo esc_attr($listing_width); ?>"/>
442
            </label>
443
        </p>
444
445
        <p>
446
            <label
447
                for="<?php echo $this->get_field_id('character_count'); ?>"><?php _e('Post Content excerpt character count :', 'geodirectory');?>
448
                <input class="widefat" id="<?php echo $this->get_field_id('character_count'); ?>"
449
                       name="<?php echo $this->get_field_name('character_count'); ?>" type="text"
450
                       value="<?php echo esc_attr($character_count); ?>"/>
451
            </label>
452
        </p>
453
454
        <p>
455
            <label for="<?php echo $this->get_field_id('add_location_filter'); ?>">
456
                <?php _e('Enable Location Filter:', 'geodirectory');?>
457
                <input type="checkbox" id="<?php echo $this->get_field_id('add_location_filter'); ?>"
458
                       name="<?php echo $this->get_field_name('add_location_filter'); ?>" <?php if ($add_location_filter) echo 'checked="checked"';?>
459
                       value="1"/>
460
            </label>
461
        </p>
462
        <p>
463
            <label for="<?php echo $this->get_field_id('show_featured_only'); ?>">
464
                <?php _e('Show only featured listings:', 'geodirectory');?> <input type="checkbox"
465
                                                                                            id="<?php echo $this->get_field_id('show_featured_only'); ?>"
466
                                                                                            name="<?php echo $this->get_field_name('show_featured_only'); ?>" <?php if ($show_featured_only) echo 'checked="checked"';?>
467
                                                                                            value="1"/>
468
            </label>
469
        </p>
470
        <p>
471
            <label for="<?php echo $this->get_field_id('show_special_only'); ?>">
472
                <?php _e('Show only listings with special offers:', 'geodirectory');?> <input type="checkbox"
473
                                                                                                       id="<?php echo $this->get_field_id('show_special_only'); ?>"
474
                                                                                                       name="<?php echo $this->get_field_name('show_special_only'); ?>" <?php if ($show_special_only) echo 'checked="checked"';?>
475
                                                                                                       value="1"/>
476
            </label>
477
        </p>
478
        <p>
479
            <label for="<?php echo $this->get_field_id('with_pics_only'); ?>">
480
                <?php _e('Show only listings with pics:', 'geodirectory');?> <input type="checkbox"
481
                                                                                             id="<?php echo $this->get_field_id('with_pics_only'); ?>"
482
                                                                                             name="<?php echo $this->get_field_name('with_pics_only'); ?>" <?php if ($with_pics_only) echo 'checked="checked"';?>
483
                                                                                             value="1"/>
484
            </label>
485
        </p>
486
        <p>
487
            <label for="<?php echo $this->get_field_id('with_videos_only'); ?>">
488
                <?php _e('Show only listings with videos:', 'geodirectory');?> <input type="checkbox"
489
                                                                                               id="<?php echo $this->get_field_id('with_videos_only'); ?>"
490
                                                                                               name="<?php echo $this->get_field_name('with_videos_only'); ?>" <?php if ($with_videos_only) echo 'checked="checked"';?>
491
                                                                                               value="1"/>
492
            </label>
493
        </p>
494
        <p>
495
            <label
496
                for="<?php echo $this->get_field_id('use_viewing_post_type'); ?>"><?php _e('Use current viewing post type:', 'geodirectory'); ?>
497
                <input type="checkbox" id="<?php echo $this->get_field_id('use_viewing_post_type'); ?>"
498
                       name="<?php echo $this->get_field_name('use_viewing_post_type'); ?>" <?php if ($use_viewing_post_type) {
499
                    echo 'checked="checked"';
500
                } ?>  value="1"/>
501
            </label>
502
        </p>
503
        <p>
504
            <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); ?> />
505
            </label>
506
        </p>
507
508
509
        <script type="text/javascript">
510
511
            function geodir_popular_widget_cat_title(val) {
512
513
                jQuery(val).find("option:selected").each(function (i) {
514
                    if (i == 0)
515
                        jQuery(val).closest('form').find('#post_type_cats input').val(jQuery(this).html());
516
517
                });
518
519
            }
520
521
            function geodir_change_category_list(obj, selected) {
522
                var post_type = obj.value;
523
524
                var ajax_url = '<?php echo geodir_get_ajax_url(); ?>'
525
526
                var myurl = ajax_url + "&geodir_ajax=admin_ajax&ajax_action=get_cat_dl&post_type=" + post_type + "&selected=" + selected;
527
528
                jQuery.ajax({
529
                    type: "GET",
530
                    url: myurl,
531
                    success: function (data) {
532
533
                        jQuery(obj).closest('form').find('#post_type_cats select').html(data);
534
535
                    }
536
                });
537
538
            }
539
540 View Code Duplication
            <?php if(is_active_widget( false, false, $this->id_base, true )){ ?>
541
            var post_type = jQuery('#<?php echo $this->get_field_id('post_type'); ?>').val();
542 1
543
            <?php } ?>
544
545 1
        </script>
546
547
    <?php
548
    }
549
} // class geodir_popular_postview
550
551
register_widget('geodir_popular_postview');