Completed
Pull Request — master (#206)
by Kiran
05:47
created

geodir_popular_postview::update()   F

Complexity

Conditions 15
Paths 8192

Size

Total Lines 33
Code Lines 23

Duplication

Lines 4
Ratio 12.12 %
Metric Value
dl 4
loc 33
rs 2.7451
cc 15
eloc 23
nc 8192
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
    public function __construct() {
24
        $widget_ops = array('classname' => 'geodir_popular_post_category', 'description' => __('GD > Popular Post Category', 'geodirectory'));
25
        parent::__construct(
26
            'popular_post_category', // Base ID
27
            __('GD > Popular Post Category', 'geodirectory'), // Name
28
            $widget_ops// Args
29
        );
30
    }
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
	public function widget($args, $instance)
42
    {
43
        geodir_popular_post_category_output($args, $instance);
44
    }
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
	 *
53
	 * @param array $new_instance Values just sent to be saved.
54
	 * @param array $old_instance Previously saved values from database.
55
	 *
56
	 * @return array Updated safe values to be saved.
57
	 */ 
58
	public function update($new_instance, $old_instance)
59
    {
60
        //save the widget
61
        $instance = $old_instance;
62
        $instance['title'] = strip_tags($new_instance['title']);
63
        $category_limit = (int)$new_instance['category_limit'];
64
        $instance['category_limit'] = $category_limit > 0 ? $category_limit : 15;
65
		$instance['default_post_type'] = isset($new_instance['default_post_type']) ? $new_instance['default_post_type'] : '';
66
        return $instance;
67
    }
68
69
	/**
70
	 * Back-end popular post category widget settings form.
71
	 *
72
	 * @since 1.0.0
73
     * @since 1.5.1 Declare function public.
74
     * @since 1.5.1 Added option to set default post type.
75
	 *
76
	 * @param array $instance Previously saved values from database.
77
	 */
78
	public function form($instance)
79
    {
80
        //widgetform in backend
81
        $instance = wp_parse_args((array)$instance, array('title' => '', 'category_limit' => 15, 'default_post_type' => ''));
82
83
        $title = strip_tags($instance['title']);
84
        $category_limit = (int)$instance['category_limit'];
85
        $category_limit = $category_limit > 0 ? $category_limit : 15;
86
		$default_post_type = isset($instance['default_post_type']) ? $instance['default_post_type'] : '';
87
		
88
		$post_type_options = geodir_get_posttypes('options');
89
        ?>
90
        <p>
91
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'geodirectory'); ?>
92
                <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
93
                       name="<?php echo $this->get_field_name('title'); ?>" type="text"
94
                       value="<?php echo esc_attr($title); ?>"/>
95
            </label>
96
        </p>
97
		<p>
98
		  <label for="<?php echo $this->get_field_id('post_type'); ?>">
99
		  <?php _e('Default post type to use (if not set by page)', 'geodirectory');?>
100
		  <select class="widefat" id="<?php echo $this->get_field_id('default_post_type'); ?>" name="<?php echo $this->get_field_name('default_post_type'); ?>">
101
			<?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...
102
			<option value="<?php echo $name;?>" <?php selected($name, $default_post_type);?>><?php echo $title; ?></option>
103
			<?php } ?>
104
		  </select>
105
		  </label>
106
		</p>
107
        <p>
108
            <label
109
                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'); ?>"
111
                       name="<?php echo $this->get_field_name('category_limit'); ?>" type="text"
112
                       value="<?php echo (int)esc_attr($category_limit); ?>"/>
113
114
                <p class="description"
115
                   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>
116
            </label>
117
        </p>
118
    <?php
119
    }
120
} // class geodir_popular_post_category
121
122
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
    public function __construct() {
140
        $widget_ops = array('classname' => 'geodir_popular_post_view', 'description' => __('GD > Popular Post View', 'geodirectory'));
141
        parent::__construct(
142
            'popular_post_view', // Base ID
143
            __('GD > Popular Post View', 'geodirectory'), // Name
144
            $widget_ops// Args
145
        );
146
    }
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
	public function widget($args, $instance)
158
    {
159
        geodir_popular_postview_output($args, $instance);
160
    }
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
	public function update($new_instance, $old_instance)
174
    {
175
        //save the widget
176
        $instance = $old_instance;
177
178
        if ($new_instance['title'] == '') {
179
            $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
        }
182
        $instance['title'] = strip_tags($new_instance['title']);
183
184
        $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
        $instance['category'] = isset($new_instance['category']) ? $new_instance['category'] : '';
187
        $instance['category_title'] = strip_tags($new_instance['category_title']);
188
        $instance['post_number'] = strip_tags($new_instance['post_number']);
189
        $instance['layout'] = strip_tags($new_instance['layout']);
190
        $instance['listing_width'] = strip_tags($new_instance['listing_width']);
191
        $instance['list_sort'] = strip_tags($new_instance['list_sort']);
192
        $instance['character_count'] = $new_instance['character_count'];
193 View Code Duplication
        if (isset($new_instance['add_location_filter']) && $new_instance['add_location_filter'] != '')
194
            $instance['add_location_filter'] = strip_tags($new_instance['add_location_filter']);
195
        else
196
            $instance['add_location_filter'] = '0';
197
198
        $instance['show_featured_only'] = isset($new_instance['show_featured_only']) && $new_instance['show_featured_only'] ? 1 : 0;
199
        $instance['show_special_only'] = isset($new_instance['show_special_only']) && $new_instance['show_special_only'] ? 1 : 0;
200
        $instance['with_pics_only'] = isset($new_instance['with_pics_only']) && $new_instance['with_pics_only'] ? 1 : 0;
201
        $instance['with_videos_only'] = isset($new_instance['with_videos_only']) && $new_instance['with_videos_only'] ? 1 : 0;
202
        $instance['use_viewing_post_type'] = isset($new_instance['use_viewing_post_type']) && $new_instance['use_viewing_post_type'] ? 1 : 0;
203
204
        return $instance;
205
    }
206
207
	/**
208
	 * Back-end popular posts widget settings form.
209
	 *
210
	 * @since 1.0.0
211
     * @since 1.5.1 Declare function public.
212
	 *
213
	 * @param array $instance Previously saved values from database.
214
	 */
215
	public function form($instance)
216
    {
217
        //widgetform in backend
218
        $instance = wp_parse_args((array)$instance,
219
            array('title' => '',
220
                'post_type' => '',
221
                'category' => array(),
222
                'category_title' => '',
223
                'list_sort' => '',
224
                'list_order' => '',
225
                'post_number' => '5',
226
                'layout' => 'gridview_onehalf',
227
                'listing_width' => '',
228
                'add_location_filter' => '1',
229
                'character_count' => '20',
230
                'show_featured_only' => '',
231
                'show_special_only' => '',
232
                'with_pics_only' => '',
233
                'with_videos_only' => '',
234
                'use_viewing_post_type' => ''
235
            )
236
        );
237
238
        $title = strip_tags($instance['title']);
239
240
        $post_type = strip_tags($instance['post_type']);
241
242
        $category = $instance['category'];
243
244
        $category_title = strip_tags($instance['category_title']);
245
246
        $list_sort = strip_tags($instance['list_sort']);
247
248
        $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...
249
250
        $post_number = strip_tags($instance['post_number']);
251
252
        $layout = strip_tags($instance['layout']);
253
254
        $listing_width = strip_tags($instance['listing_width']);
255
256
        $add_location_filter = strip_tags($instance['add_location_filter']);
257
258
        $character_count = $instance['character_count'];
259
260
        $show_featured_only = isset($instance['show_featured_only']) && $instance['show_featured_only'] ? true : false;
261
        $show_special_only = isset($instance['show_special_only']) && $instance['show_special_only'] ? true : false;
262
        $with_pics_only = isset($instance['with_pics_only']) && $instance['with_pics_only'] ? true : false;
263
        $with_videos_only = isset($instance['with_videos_only']) && $instance['with_videos_only'] ? true : false;
264
        $use_viewing_post_type = isset($instance['use_viewing_post_type']) && $instance['use_viewing_post_type'] ? true : false;
265
266
        ?>
267
268
        <p>
269
            <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'geodirectory');?>
270
                <small>(%posttype_singular_label% ,
271
                    %posttype_plural_label% <?php _e('can be used', 'geodirectory');?>)
272
                </small>
273
274
                <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
275
                       name="<?php echo $this->get_field_name('title'); ?>" type="text"
276
                       value="<?php echo esc_attr($title); ?>"/>
277
            </label>
278
        </p>
279
280
        <p>
281
            <label
282
                for="<?php echo $this->get_field_id('post_type'); ?>"><?php _e('Post Type:', 'geodirectory');?>
283
284
                <?php $postypes = geodir_get_posttypes();
285
				/**
286
				 * Filter the post types to display in widget.
287
				 *
288
				 * @since 1.0.0
289
				 *
290
				 * @param array $postypes Post types array.
291
				 */
292
				$postypes = apply_filters('geodir_post_type_list_in_p_widget', $postypes); ?>
293
294
                <select class="widefat" id="<?php echo $this->get_field_id('post_type'); ?>"
295
                        name="<?php echo $this->get_field_name('post_type'); ?>"
296
                        onchange="geodir_change_category_list(this)">
297
298 View Code Duplication
                    <?php foreach ($postypes as $postypes_obj) { ?>
299
300
                        <option <?php if ($post_type == $postypes_obj) {
301
                            echo 'selected="selected"';
302
                        } ?> value="<?php echo $postypes_obj; ?>"><?php $extvalue = explode('_', $postypes_obj);
303
                            echo ucfirst($extvalue[1]); ?></option>
304
305
                    <?php } ?>
306
307
                </select>
308
            </label>
309
        </p>
310
311
312
        <p id="post_type_cats">
313
            <label
314
                for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Post Category:', 'geodirectory');?>
315
316
                <?php
317
318
                $post_type = ($post_type != '') ? $post_type : 'gd_place';
319
320
                $all_postypes = geodir_get_posttypes();
321
322
                if (!in_array($post_type, $all_postypes))
323
                    $post_type = 'gd_place';
324
325
                $category_taxonomy = geodir_get_taxonomies($post_type);
326
                $categories = get_terms($category_taxonomy, array('orderby' => 'count', 'order' => 'DESC'));
327
328
                ?>
329
330
                <select multiple="multiple" class="widefat" name="<?php echo $this->get_field_name('category'); ?>[]"
331
                        onchange="geodir_popular_widget_cat_title(this)">
332
333
                    <option <?php if (!is_array($category) || (is_array($category) && in_array('0', $category))) {
334
                        echo 'selected="selected"';
335
                    } ?> value="0"><?php _e('All', 'geodirectory'); ?></option>
336
                    <?php foreach ($categories as $category_obj) {
337
                        $selected = '';
338
                        if (is_array($category) && in_array($category_obj->term_id, $category))
339
                            echo $selected = 'selected="selected"';
340
341
                        ?>
342
343
                        <option <?php echo $selected; ?>
344
                            value="<?php echo $category_obj->term_id; ?>"><?php echo ucfirst($category_obj->name); ?></option>
345
346
                    <?php } ?>
347
348
                </select>
349
350
351
                <input type="hidden" name="<?php echo $this->get_field_name('category_title'); ?>"
352
                       id="<?php echo $this->get_field_id('category_title'); ?>"
353
                       value="<?php if ($category_title != '') echo $category_title; else echo __('All', 'geodirectory');?>"/>
354
355
            </label>
356
        </p>
357
358
        <p>
359
            <label
360
                for="<?php echo $this->get_field_id('list_sort'); ?>"><?php _e('Sort by:', 'geodirectory');?>
361
362
                <select class="widefat" id="<?php echo $this->get_field_id('list_sort'); ?>"
363
                        name="<?php echo $this->get_field_name('list_sort'); ?>">
364
365
                    <option <?php if ($list_sort == 'az') {
366
                        echo 'selected="selected"';
367
                    } ?> value="az"><?php _e('A-Z', 'geodirectory'); ?></option>
368
369
                    <option <?php if ($list_sort == 'latest') {
370
                        echo 'selected="selected"';
371
                    } ?> value="latest"><?php _e('Latest', 'geodirectory'); ?></option>
372
373
                    <option <?php if ($list_sort == 'featured') {
374
                        echo 'selected="selected"';
375
                    } ?> value="featured"><?php _e('Featured', 'geodirectory'); ?></option>
376
377
                    <option <?php if ($list_sort == 'high_review') {
378
                        echo 'selected="selected"';
379
                    } ?> value="high_review"><?php _e('Review', 'geodirectory'); ?></option>
380
381
                    <option <?php if ($list_sort == 'high_rating') {
382
                        echo 'selected="selected"';
383
                    } ?> value="high_rating"><?php _e('Rating', 'geodirectory'); ?></option>
384
385
                    <option <?php if ($list_sort == 'random') {
386
                        echo 'selected="selected"';
387
                    } ?> value="random"><?php _e('Random', 'geodirectory'); ?></option>
388
389
                </select>
390
            </label>
391
        </p>
392
393
        <p>
394
395
            <label
396
                for="<?php echo $this->get_field_id('post_number'); ?>"><?php _e('Number of posts:', 'geodirectory');?>
397
398
                <input class="widefat" id="<?php echo $this->get_field_id('post_number'); ?>"
399
                       name="<?php echo $this->get_field_name('post_number'); ?>" type="text"
400
                       value="<?php echo esc_attr($post_number); ?>"/>
401
            </label>
402
        </p>
403
404
        <p>
405
            <label for="<?php echo $this->get_field_id('layout'); ?>">
406
                <?php _e('Layout:', 'geodirectory');?>
407
                <select class="widefat" id="<?php echo $this->get_field_id('layout'); ?>"
408
                        name="<?php echo $this->get_field_name('layout'); ?>">
409
                    <option <?php if ($layout == 'gridview_onehalf') {
410
                        echo 'selected="selected"';
411
                    } ?>
412
                        value="gridview_onehalf"><?php _e('Grid View (Two Columns)', 'geodirectory'); ?></option>
413
                    <option <?php if ($layout == 'gridview_onethird') {
414
                        echo 'selected="selected"';
415
                    } ?>
416
                        value="gridview_onethird"><?php _e('Grid View (Three Columns)', 'geodirectory'); ?></option>
417
                    <option <?php if ($layout == 'gridview_onefourth') {
418
                        echo 'selected="selected"';
419
                    } ?>
420
                        value="gridview_onefourth"><?php _e('Grid View (Four Columns)', 'geodirectory'); ?></option>
421
                    <option <?php if ($layout == 'gridview_onefifth') {
422
                        echo 'selected="selected"';
423
                    } ?>
424
                        value="gridview_onefifth"><?php _e('Grid View (Five Columns)', 'geodirectory'); ?></option>
425
                    <option <?php if ($layout == 'list') {
426
                        echo 'selected="selected"';
427
                    } ?> value="list"><?php _e('List view', 'geodirectory'); ?></option>
428
429
                </select>
430
            </label>
431
        </p>
432
433
        <p>
434
            <label
435
                for="<?php echo $this->get_field_id('listing_width'); ?>"><?php _e('Listing width:', 'geodirectory');?>
436
437
                <input class="widefat" id="<?php echo $this->get_field_id('listing_width'); ?>"
438
                       name="<?php echo $this->get_field_name('listing_width'); ?>" type="text"
439
                       value="<?php echo esc_attr($listing_width); ?>"/>
440
            </label>
441
        </p>
442
443
        <p>
444
            <label
445
                for="<?php echo $this->get_field_id('character_count'); ?>"><?php _e('Post Content excerpt character count :', 'geodirectory');?>
446
                <input class="widefat" id="<?php echo $this->get_field_id('character_count'); ?>"
447
                       name="<?php echo $this->get_field_name('character_count'); ?>" type="text"
448
                       value="<?php echo esc_attr($character_count); ?>"/>
449
            </label>
450
        </p>
451
452
        <p>
453
            <label for="<?php echo $this->get_field_id('add_location_filter'); ?>">
454
                <?php _e('Enable Location Filter:', 'geodirectory');?>
455
                <input type="checkbox" id="<?php echo $this->get_field_id('add_location_filter'); ?>"
456
                       name="<?php echo $this->get_field_name('add_location_filter'); ?>" <?php if ($add_location_filter) echo 'checked="checked"';?>
457
                       value="1"/>
458
            </label>
459
        </p>
460
        <p>
461
            <label for="<?php echo $this->get_field_id('show_featured_only'); ?>">
462
                <?php _e('Show only featured listings:', 'geodirectory');?> <input type="checkbox"
463
                                                                                            id="<?php echo $this->get_field_id('show_featured_only'); ?>"
464
                                                                                            name="<?php echo $this->get_field_name('show_featured_only'); ?>" <?php if ($show_featured_only) echo 'checked="checked"';?>
465
                                                                                            value="1"/>
466
            </label>
467
        </p>
468
        <p>
469
            <label for="<?php echo $this->get_field_id('show_special_only'); ?>">
470
                <?php _e('Show only listings with special offers:', 'geodirectory');?> <input type="checkbox"
471
                                                                                                       id="<?php echo $this->get_field_id('show_special_only'); ?>"
472
                                                                                                       name="<?php echo $this->get_field_name('show_special_only'); ?>" <?php if ($show_special_only) echo 'checked="checked"';?>
473
                                                                                                       value="1"/>
474
            </label>
475
        </p>
476
        <p>
477
            <label for="<?php echo $this->get_field_id('with_pics_only'); ?>">
478
                <?php _e('Show only listings with pics:', 'geodirectory');?> <input type="checkbox"
479
                                                                                             id="<?php echo $this->get_field_id('with_pics_only'); ?>"
480
                                                                                             name="<?php echo $this->get_field_name('with_pics_only'); ?>" <?php if ($with_pics_only) echo 'checked="checked"';?>
481
                                                                                             value="1"/>
482
            </label>
483
        </p>
484
        <p>
485
            <label for="<?php echo $this->get_field_id('with_videos_only'); ?>">
486
                <?php _e('Show only listings with videos:', 'geodirectory');?> <input type="checkbox"
487
                                                                                               id="<?php echo $this->get_field_id('with_videos_only'); ?>"
488
                                                                                               name="<?php echo $this->get_field_name('with_videos_only'); ?>" <?php if ($with_videos_only) echo 'checked="checked"';?>
489
                                                                                               value="1"/>
490
            </label>
491
        </p>
492
        <p>
493
            <label
494
                for="<?php echo $this->get_field_id('use_viewing_post_type'); ?>"><?php _e('Use current viewing post type:', 'geodirectory'); ?>
495
                <input type="checkbox" id="<?php echo $this->get_field_id('use_viewing_post_type'); ?>"
496
                       name="<?php echo $this->get_field_name('use_viewing_post_type'); ?>" <?php if ($use_viewing_post_type) {
497
                    echo 'checked="checked"';
498
                } ?>  value="1"/>
499
            </label>
500
        </p>
501
502
503
        <script type="text/javascript">
504
505
            function geodir_popular_widget_cat_title(val) {
506
507
                jQuery(val).find("option:selected").each(function (i) {
508
                    if (i == 0)
509
                        jQuery(val).closest('form').find('#post_type_cats input').val(jQuery(this).html());
510
511
                });
512
513
            }
514
515
            function geodir_change_category_list(obj, selected) {
516
                var post_type = obj.value;
517
518
                var ajax_url = '<?php echo geodir_get_ajax_url(); ?>'
519
520
                var myurl = ajax_url + "&geodir_ajax=admin_ajax&ajax_action=get_cat_dl&post_type=" + post_type + "&selected=" + selected;
521
522
                jQuery.ajax({
523
                    type: "GET",
524
                    url: myurl,
525
                    success: function (data) {
526
527
                        jQuery(obj).closest('form').find('#post_type_cats select').html(data);
528
529
                    }
530
                });
531
532
            }
533
534 View Code Duplication
            <?php if(is_active_widget( false, false, $this->id_base, true )){ ?>
535
            var post_type = jQuery('#<?php echo $this->get_field_id('post_type'); ?>').val();
536
537
            <?php } ?>
538
539
        </script>
540
541
    <?php
542
    }
543
} // class geodir_popular_postview
544
545
register_widget('geodir_popular_postview');