PluginProbe
WP Directory Kit / 1.2.4
WP Directory Kit v1.2.4
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / application / controllers / Wdk.php

Wdk.php in WP Directory Kit 1.2.4, at application/controllers/Wdk.php

265 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly;
3
4 class Wdk_index extends Winter_MVC_Controller {
5
6 public function __construct(){
7 parent::__construct();
8 }
9
10 public function index()
11 {
12 $this->load->model('field_m');
13 $this->load->model('listing_m');
14 $this->load->model('listingfield_m');
15 $this->load->model('location_m');
16 $this->load->model('category_m');
17 $this->load->load_helper('listing');
18
19 /* [Table Actions Bulk Form] */
20 $table_action = $this->input->post_get('table_action');
21 $action = $this->input->post_get('action');
22 $posts_selected = $this->input->post_get('post');
23
24 if(!empty($table_action))
25 {
26 switch ($action) {
27 case 'delete':
28 $this->bulk_delete($posts_selected);
29 break;
30 case 'deactivate':
31 $this->bulk_deactivate($posts_selected);
32 break;
33 case 'activate':
34 $this->bulk_activate($posts_selected);
35 break;
36 case 'deapprove':
37 $this->bulk_deapprove($posts_selected);
38 break;
39 case 'approve':
40 $this->bulk_approve($posts_selected);
41 break;
42 default:
43 }
44 }
45
46 /* [Search Form] */
47
48 $dbusers = get_users( array( 'search' => '',
49 'orderby' => 'display_name', 'order' => 'ASC'));
50
51 foreach($dbusers as $dbuser) {
52 $this->data['users'][wmvc_show_data('ID', $dbuser)] = '#'.wmvc_show_data('ID', $dbuser).', '.wmvc_show_data('display_name', $dbuser);
53 }
54
55 $this->data['fields_list'] = $this->field_m->get();
56
57 $fields_data = $this->field_m->get();
58 $this->data['fields_list'] = array();
59
60 foreach($fields_data as $field)
61 {
62 if(wmvc_show_data('field_type', $field) == 'SECTION') {
63 } else {
64 $this->data['fields_list']['field_'.wmvc_show_data('idfield', $field)] = '#'.wmvc_show_data('idfield', $field).' '.wmvc_show_data('field_label', $field).'['.wmvc_show_data('field_type', $field).']';
65 }
66 }
67
68 $controller = 'listing';
69 $columns = array('ID', 'location_id', 'category_id', 'post_title', 'post_date', 'search', 'order_by', 'address','user_id_editor', 'is_featured','is_activated','is_approved');
70 $external_columns = array('location_id', 'category_id', 'post_title', 'user_id_editor',);
71
72 $this->data['categories'] = $this->category_m->get_parents();
73 $this->data['locations'] = $this->location_m->get_parents();
74 $this->data['order_by'] = array('ID DESC' => __('ID', 'wpdirectorykit').' DESC',
75 'ID ASC' => __('ID', 'wpdirectorykit').' ASC',
76 'post_title ASC' => __('Post Title', 'wpdirectorykit').' ASC',
77 'post_title DESC' => __('Post Title', 'wpdirectorykit').' DESC',
78 'post_date ASC' => __('Post Date', 'wpdirectorykit').' ASC',
79 'post_date DESC' => __('Post Date', 'wpdirectorykit').' DESC',
80 'date_modified ASC' => __('Last Modified Date', 'wpdirectorykit').' ASC',
81 'date_modified DESC' => __('Last Modified Date', 'wpdirectorykit').' DESC',
82 );
83
84 $rules = array(
85 array(
86 'field' => 'location_id',
87 'label' => __('Location', 'wpdirectorykit'),
88 'rules' => ''
89 ),
90 array(
91 'field' => 'category_id',
92 'label' => __('Category', 'wpdirectorykit'),
93 'rules' => ''
94 ),
95 array(
96 'field' => 'search',
97 'label' => __('Search tag', 'wpdirectorykit'),
98 'rules' => ''
99 ),
100 array(
101 'field' => 'order_by',
102 'label' => __('Order By', 'wpdirectorykit'),
103 'rules' => ''
104 ),
105 array(
106 'field' => 'user_id_editor',
107 'label' => __('User', 'wpdirectorykit'),
108 'rules' => ''
109 ),
110 array(
111 'field' => 'is_activated',
112 'label' => __('Is Activated', 'wpdirectorykit'),
113 'rules' => ''
114 ),
115 array(
116 'field' => 'is_featured',
117 'label' => __('Is Featured', 'wpdirectorykit'),
118 'rules' => ''
119 ),
120 );
121
122 $custom_parameters = array();
123 foreach ($this->input->get() as $key => $value) {
124 if(stripos($key, 'c_field_') !== FALSE && stripos($key, '_field',8) !== FALSE) {
125 $field_id = substr($key, 8, (stripos($key, '_',8) - 8) );
126 if(!empty($_GET['c_field_'.$field_id.'_field'])
127 && !empty($_GET['c_field_'.$field_id.'_like'])
128 && !empty($_GET['c_field_'.$field_id.'_value'])) {
129 switch ($_GET['c_field_'.$field_id.'_like']) {
130 case '>': $custom_parameters[sanitize_key($_GET['c_field_'.$field_id.'_field']).'_min'] = sanitize_text_field($_GET['c_field_'.$field_id.'_value']);
131 break;
132 case '<': $custom_parameters[sanitize_key($_GET['c_field_'.$field_id.'_field']).'_max'] = sanitize_text_field($_GET['c_field_'.$field_id.'_value']);
133 break;
134 case '==': $custom_parameters[sanitize_key($_GET['c_field_'.$field_id.'_field'])] = sanitize_text_field($_GET['c_field_'.$field_id.'_value']);
135 break;
136 }
137 }
138 }
139 };
140
141 $this->data['db_data'] = $this->listing_m->prepare_data($this->input->get(), $rules);
142 /* [/Search Form] */
143
144 $where = array();
145 if(isset($_GET['inactive']) && $_GET['inactive'] == 'on') {
146 $where['(is_activated IS NULL OR is_approved IS NULL)'] = NULL;
147 }
148
149 wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns, $custom_parameters);
150 $total_items = $this->listing_m->total($where);
151
152 $current_page = 1;
153
154 if(isset($_GET['paged']))
155 $current_page = intval($_GET['paged']);
156
157 $this->data['paged'] = $current_page;
158
159
160 $per_page = 20;
161 $offset = $per_page*($current_page-1);
162
163 $this->data['pagination_output'] = '';
164
165 if(function_exists('wmvc_wp_paginate'))
166 $this->data['pagination_output'] = wmvc_wp_paginate($total_items, $per_page);
167
168 wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns, $custom_parameters);
169 $this->data['listings'] = $this->listing_m->get_pagination($per_page, $offset, $where);
170
171 // Load view
172 $this->load->view('wdk/index', $this->data);
173 }
174
175 public function delete()
176 {
177 $this->load->model('listing_m');
178
179 $post_id = (int) $this->input->post_get('id');
180 $paged = (int) $this->input->post_get('paged');
181
182 // Check _wpnonce
183 check_admin_referer( 'wdk-listing-delete_'.$post_id, '_wpnonce' );
184
185 $this->listing_m->delete($post_id);
186
187 wp_redirect(admin_url("admin.php?page=wdk&paged=$paged"));
188 }
189
190 public function bulk_delete($posts_selected)
191 {
192 $this->load->model('listing_m');
193
194 // Check _wpnonce
195 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
196
197 foreach($posts_selected as $key=>$post_id)
198 {
199 $this->listing_m->delete($post_id);
200 }
201
202 wp_redirect(admin_url("admin.php?page=wdk"));
203 }
204
205 public function bulk_deactivate($posts_selected)
206 {
207 // Check _wpnonce
208 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
209
210 $this->load->model('listing_m');
211 foreach($posts_selected as $key=>$post_id)
212 {
213 if($this->listing_m->check_deletable($post_id))
214 $this->listing_m->insert(array('is_activated'=>NULL), $post_id);
215 }
216
217 wp_redirect(admin_url("admin.php?page=wdk"));
218 }
219
220 public function bulk_activate($posts_selected)
221 {
222 // Check _wpnonce
223 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
224
225 $this->load->model('listing_m');
226 foreach($posts_selected as $key=>$post_id)
227 {
228 if($this->listing_m->check_deletable($post_id))
229 $this->listing_m->insert(array('is_activated'=>1), $post_id);
230 }
231
232 wp_redirect(admin_url("admin.php?page=wdk"));
233 }
234 public function bulk_deapprove($posts_selected)
235 {
236
237 // Check _wpnonce
238 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
239
240 $this->load->model('listing_m');
241 foreach($posts_selected as $key=>$post_id)
242 {
243 if($this->listing_m->check_deletable($post_id))
244 $this->listing_m->insert(array('is_approved'=>NULL), $post_id);
245 }
246
247 wp_redirect(admin_url("admin.php?page=wdk"));
248 }
249
250 public function bulk_approve($posts_selected)
251 {
252 // Check _wpnonce
253 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
254
255 $this->load->model('listing_m');
256 foreach($posts_selected as $key=>$post_id)
257 {
258 if($this->listing_m->check_deletable($post_id))
259 $this->listing_m->insert(array('is_approved'=>1), $post_id);
260 }
261
262 wp_redirect(admin_url("admin.php?page=wdk"));
263 }
264 }
265