PluginProbe ʕ •ᴥ•ʔ
Download Manager / trunk
Download Manager vtrunk
3.3.62 3.3.61 3.3.60 3.3.59 3.3.58 3.3.57 3.3.56 trunk 2.1.3 2.3.0 2.5.96 2.5.97 2.6.2 2.6.96 2.8.3 2.9.99 3.0.4 3.1.05 3.1.07 3.1.08 3.1.11 3.1.12 3.1.14 3.1.17 3.1.18 3.1.22 3.1.23 3.1.24 3.1.25 3.1.26 3.1.27 3.1.28 3.2.04 3.2.13 3.2.14 3.2.16 3.2.18 3.2.19 3.2.21 3.2.22 3.2.23 3.2.24 3.2.25 3.2.27 3.2.28 3.2.29 3.2.30 3.2.31 3.2.32 3.2.33 3.2.34 3.2.35 3.2.37 3.2.38 3.2.39 3.2.40 3.2.41 3.2.42 3.2.43 3.2.44 3.2.45 3.2.46 3.2.47 3.2.48 3.2.49 3.2.50 3.2.51 3.2.52 3.2.53 3.2.54 3.2.55 3.2.56 3.2.57 3.2.58 3.2.59 3.2.60 3.2.61 3.2.63 3.2.64 3.2.65 3.2.66 3.2.67 3.2.68 3.2.69 3.2.70 3.2.71 3.2.72 3.2.73 3.2.74 3.2.75 3.2.76 3.2.77 3.2.78 3.2.79 3.2.80 3.2.81 3.2.82 3.2.83 3.2.84 3.2.85 3.2.86 3.2.87 3.2.88 3.2.89 3.2.90 3.2.91 3.2.92 3.2.93 3.2.94 3.2.95 3.2.96 3.2.97 3.2.98 3.2.99 3.3.00 3.3.01 3.3.02 3.3.03 3.3.04 3.3.05 3.3.06 3.3.07 3.3.08 3.3.09 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.15 3.3.16 3.3.17 3.3.18 3.3.19 3.3.20 3.3.21 3.3.22 3.3.23 3.3.24 3.3.25 3.3.26 3.3.27 3.3.28 3.3.29 3.3.30 3.3.31 3.3.32 3.3.33 3.3.34 3.3.35 3.3.36 3.3.37 3.3.38 3.3.39 3.3.40 3.3.41 3.3.42 3.3.43 3.3.44 3.3.45 3.3.46 3.3.47 3.3.48 3.3.49 3.3.50 3.3.51 3.3.52 3.3.53 3.3.54 3.3.55
download-manager / src / Widgets / Categories.php
download-manager / src / Widgets Last commit date
CatPackages.php 4 years ago Categories.php 4 years ago ListPackages.php 4 years ago NewDownloads.php 4 years ago PackageInfo.php 4 years ago Search.php 4 years ago Tags.php 2 years ago TopDownloads.php 4 years ago WidgetController.php 2 years ago
Categories.php
189 lines
1 <?php
2
3 use WPDM\Category\CategoryController;
4
5 if (!defined("ABSPATH")) die("Shit happens!");
6 if (!class_exists('WPDM_Categories')) {
7 class WPDM_Categories extends \WP_Widget
8 {
9 /** constructor */
10 function __construct()
11 {
12 parent::__construct(false, 'WPDM Categories');
13 }
14
15 /** @see WP_Widget::widget */
16 function widget($args, $instance)
17 {
18 extract($args);
19 $instance['title'] = isset($instance['title']) ? $instance['title'] : '';
20 $title = apply_filters('widget_title', $instance['title']);
21 $parent = isset($instance['parent']) && $instance['parent'] > 0 ? intval($instance['parent']) : 0;
22 $style = isset($instance['style']) ? esc_attr($instance['style']) : 'flat';
23 $toplevel = isset($instance['toplevel']) ? esc_attr($instance['toplevel']) : 0;
24 $category_page = isset($instance['category_page']) ? esc_attr($instance['category_page']) : 'showall';
25 $hideon0 = isset($instance['hideon0']) ? esc_attr($instance['hideon0']) : 0;
26
27
28 $args = array(
29 'orderby' => 'name',
30 'order' => 'ASC',
31 'hide_empty' => false,
32 'exclude' => array(),
33 'exclude_tree' => array(),
34 'include' => array(),
35 'number' => '',
36 'fields' => 'all',
37 'slug' => '',
38 'parent' => '',
39 'hierarchical' => ($style == 'flat' ? false : true),
40 'child_of' => $parent,
41 'childless' => false,
42 'get' => '',
43 'name__like' => '',
44 'description__like' => '',
45 'pad_counts' => false,
46 'offset' => '',
47 'search' => '',
48 'cache_domain' => 'core'
49 );
50
51 $object = get_queried_object();
52 if ($category_page == 'subs' && !isset($object->post_type))
53 $args['parent'] = get_queried_object_id();
54
55 $terms = get_terms("wpdmcategory", $args);
56
57 if ($hideon0 == 1 && count($terms) == 0) {
58 return;
59 }
60
61 echo $before_widget;
62 if ($title)
63 echo $before_title . $title . $after_title;
64
65 if ($style == 'flat') {
66 echo "<div class='w3eden'><div class='list-group'>";
67 foreach ($terms as $term) {
68 if (($toplevel == 1 && ($term->parent == 0 || $term->parent === $parent)) || $toplevel == 0)
69 echo "<a href='" . get_term_link($term) . "' class='list-group-item d-flex justify-content-between align-items-center'>{$term->name}<span class='badge'>{$term->count}</span></a>\n";
70 }
71
72 echo "</div></div>\n";
73 } else if ($style == 'icon') {
74
75
76 echo "<div class='wpdm-categories icon-list'>";
77 foreach ($terms as $term) {
78 $icon = CategoryController::icon($term->term_id);
79 if ($icon == '') $icon = "https://cdn1.iconfinder.com/data/icons/gradient-android-apps/64/1-05-512.png";
80 if (($toplevel == 1 && ($term->parent == 0 || $term->parent === $parent)) || $toplevel == 0)
81 echo "<div class='icon-cat'><a href='" . get_term_link($term) . "'><img src='{$icon}' class='cat-icon' /> {$term->name}</a></div>\n";
82 }
83 echo "</div>";
84 } else {
85
86 function wpdm_categories_tree($parent = 0, $selected = array())
87 {
88 $categories = get_terms('wpdmcategory', array('hide_empty' => 0, 'parent' => $parent));
89 $checked = "";
90 foreach ($categories as $category) {
91 if ($selected) {
92 foreach ($selected as $ptype) {
93 if ($ptype->term_id == $category->term_id) {
94 $checked = "checked='checked'";
95 break;
96 } else $checked = "";
97 }
98 }
99 echo '<li><a href="' . get_term_link($category) . '"> ' . $category->name . ' </a>';
100 $termchildren = get_term_children($category->term_id, 'wpdmcategory');
101 if ($termchildren) {
102 echo "<ul>";
103 wpdm_categories_tree($category->term_id, $selected);
104 echo "</ul>";
105 }
106 echo "</li>";
107 }
108 }
109
110 echo "<ul class='wpdm-categories'>";
111 $cparent = $parent;
112 if ($cparent !== 0) {
113 $cparent = get_term_by('slug', $cparent, 'wpdmcategory');
114 $cparent = $cparent->term_id;
115 }
116 wpdm_categories_tree($cparent, $terms);
117 echo "</ul>";
118 }
119 echo $after_widget; ?>
120 <?php
121 }
122
123 /** @see WP_Widget::update */
124 function update($new_instance, $old_instance)
125 {
126 return $new_instance;
127 }
128
129 /** @see WP_Widget::form */
130 function form($instance)
131 {
132 $title = isset($instance['title']) ? esc_attr($instance['title']) : "";
133 $parent = isset($instance['parent']) ? intval($instance['parent']) : 0;
134 $style = isset($instance['style']) ? esc_attr($instance['style']) : 'flat';
135 $toplevel = isset($instance['toplevel']) ? esc_attr($instance['toplevel']) : 0;
136 $category_page = isset($instance['category_page']) ? esc_attr($instance['category_page']) : 0;
137 $hideon0 = isset($instance['hideon0']) ? esc_attr($instance['hideon0']) : 0;
138 ?>
139 <p>
140 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
141 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>"
142 name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>"/>
143 </p>
144 <p>
145 <label for="<?php echo $this->get_field_id('parent'); ?>"><?php _e('Parent:'); ?></label><br/>
146 <?php wpdm_dropdown_categories($this->get_field_name('parent'), $parent, $this->get_field_id('parent')); ?>
147 </p>
148 <p>
149 <label for="<?php echo $this->get_field_id('category_page'); ?>"><?php _e('On Category Page:', 'download-manger'); ?></label><br/>
150 <select id="<?php echo $this->get_field_id('category_page'); ?>"
151 name="<?php echo $this->get_field_name('category_page'); ?>">
152 <option value="showall" <?php selected('showall', $category_page); ?>><?php echo __("Show all", "download-manager") ?></option>
153 <option value="subs" <?php selected('subs', $category_page); ?>><?php echo __("Show subcategories only", "download-manager") ?></option>
154 </select>
155 </p>
156 <p>
157 <label><?php _e('Style:'); ?></label><br/>
158 <label><input type="radio"
159 name="<?php echo $this->get_field_name('style'); ?>" <?php checked('flat', $style); ?>
160 value="flat"> Flat List</label><br/>
161 <label><input type="radio"
162 name="<?php echo $this->get_field_name('style'); ?>" <?php checked('tree', $style); ?>
163 value="tree"> Hierarchy List</label><br/>
164 <label><input type="radio"
165 name="<?php echo $this->get_field_name('style'); ?>" <?php checked('icon', $style); ?>
166 value="icon"> Icon List ( Flat )</label><br/>
167 <!-- label><input type="radio" name="<?php echo $this->get_field_name('style'); ?>" <?php checked('dropdown', $style); ?> value="dropdown"> Dropdown List</label></br -->
168 </p>
169 <p>
170 <label for="<?php echo $this->get_field_id('toplevel'); ?>"><input type="checkbox"
171 name="<?php echo $this->get_field_name('toplevel'); ?>" <?php checked('1', $toplevel); ?>
172 value="1"> <?php _e('Top Level Only', 'download-manager'); ?>
173 </label><br/>
174 </p>
175 <p>
176 <label for="<?php echo $this->get_field_id('hideon0'); ?>"><input type="checkbox"
177 name="<?php echo $this->get_field_name('hideon0'); ?>" <?php checked('1', $hideon0); ?>
178 value="1"> <?php _e('Hide widget when no category', 'download-manager'); ?>
179 </label><br/>
180 </p>
181 <?php
182 }
183
184 }
185 }
186
187 register_widget('WPDM_Categories');
188
189