PluginProbe
WP Directory Kit / 1.4.8
WP Directory Kit v1.4.8
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.4.8, at application/controllers/Wdk.php

270 lines 10.6 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 $this->listing_m->_table_name.'.rank ASC, ID ASC' => __('Rank', 'wpdirectorykit').' ASC',
83 $this->listing_m->_table_name.'.rank DESC, ID DESC' => __('Rank', 'wpdirectorykit').' DESC',
84 );
85
86 $rules = array(
87 array(
88 'field' => 'location_id',
89 'label' => __('Location', 'wpdirectorykit'),
90 'rules' => ''
91 ),
92 array(
93 'field' => 'category_id',
94 'label' => __('Category', 'wpdirectorykit'),
95 'rules' => ''
96 ),
97 array(
98 'field' => 'search',
99 'label' => __('Search tag', 'wpdirectorykit'),
100 'rules' => ''
101 ),
102 array(
103 'field' => 'order_by',
104 'label' => __('Order By', 'wpdirectorykit'),
105 'rules' => ''
106 ),
107 array(
108 'field' => 'user_id_editor',
109 'label' => __('User', 'wpdirectorykit'),
110 'rules' => ''
111 ),
112 array(
113 'field' => 'is_activated',
114 'label' => __('Is Activated', 'wpdirectorykit'),
115 'rules' => ''
116 ),
117 array(
118 'field' => 'is_featured',
119 'label' => __('Is Featured', 'wpdirectorykit'),
120 'rules' => ''
121 ),
122 );
123
124 $custom_parameters = array();
125 foreach ($this->input->get() as $key => $value) {
126 if(stripos($key, 'c_field_') !== FALSE && stripos($key, '_field',8) !== FALSE) {
127 $field_id = substr($key, 8, (stripos($key, '_',8) - 8) );
128 if(!empty($_GET['c_field_'.$field_id.'_field'])
129 && !empty($_GET['c_field_'.$field_id.'_like'])
130 && !empty($_GET['c_field_'.$field_id.'_value'])) {
131 switch ($_GET['c_field_'.$field_id.'_like']) {
132 case '>': $custom_parameters[sanitize_key($_GET['c_field_'.$field_id.'_field']).'_min'] = sanitize_text_field($_GET['c_field_'.$field_id.'_value']);
133 break;
134 case '<': $custom_parameters[sanitize_key($_GET['c_field_'.$field_id.'_field']).'_max'] = sanitize_text_field($_GET['c_field_'.$field_id.'_value']);
135 break;
136 case '==': $custom_parameters[sanitize_key($_GET['c_field_'.$field_id.'_field'])] = sanitize_text_field($_GET['c_field_'.$field_id.'_value']);
137 break;
138 }
139 }
140 }
141 };
142
143 $this->data['db_data'] = $this->listing_m->prepare_data($this->input->get(), $rules);
144 /* [/Search Form] */
145
146 $where = array();
147 if(isset($_GET['inactive']) && $_GET['inactive'] == 'on') {
148 $where['(is_activated IS NULL OR is_approved IS NULL)'] = NULL;
149 }
150
151 wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns, $custom_parameters);
152 $total_items = $this->listing_m->total($where);
153
154 $current_page = 1;
155
156 if(isset($_GET['paged']))
157 $current_page = intval($_GET['paged']);
158
159 $this->data['paged'] = $current_page;
160
161
162 $per_page = 20;
163 $offset = $per_page*($current_page-1);
164
165 $this->data['pagination_output'] = '';
166
167 if(function_exists('wmvc_wp_paginate'))
168 $this->data['pagination_output'] = wmvc_wp_paginate($total_items, $per_page);
169
170 wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns, $custom_parameters);
171 $this->data['listings'] = $this->listing_m->get_pagination($per_page, $offset, $where);
172
173 // Load view
174 $this->load->view('wdk/index', $this->data);
175 }
176
177 public function delete()
178 {
179 $this->load->model('listing_m');
180
181 $post_id = (int) $this->input->post_get('id');
182 $paged = (int) $this->input->post_get('paged');
183
184 // Check _wpnonce
185 check_admin_referer( 'wdk-listing-delete_'.$post_id, '_wpnonce' );
186
187 $this->listing_m->delete($post_id);
188
189 do_action('wpdirectorykit/listing/removed');
190
191 wp_redirect(admin_url("admin.php?page=wdk&paged=$paged"));
192 }
193
194 public function bulk_delete($posts_selected)
195 {
196 $this->load->model('listing_m');
197
198 // Check _wpnonce
199 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
200
201 foreach($posts_selected as $key=>$post_id)
202 {
203 $this->listing_m->delete($post_id);
204 }
205
206 do_action('wpdirectorykit/listing/bulk_removed');
207 wp_redirect(admin_url("admin.php?page=wdk"));
208 }
209
210 public function bulk_deactivate($posts_selected)
211 {
212 // Check _wpnonce
213 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
214
215 $this->load->model('listing_m');
216 foreach($posts_selected as $key=>$post_id)
217 {
218 if($this->listing_m->check_deletable($post_id))
219 $this->listing_m->insert(array('is_activated'=>NULL), $post_id);
220 }
221 do_action('wpdirectorykit/listing/updated');
222 wp_redirect(admin_url("admin.php?page=wdk"));
223 }
224
225 public function bulk_activate($posts_selected)
226 {
227 // Check _wpnonce
228 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
229
230 $this->load->model('listing_m');
231 foreach($posts_selected as $key=>$post_id)
232 {
233 if($this->listing_m->check_deletable($post_id))
234 $this->listing_m->insert(array('is_activated'=>1), $post_id);
235 }
236 do_action('wpdirectorykit/listing/updated');
237 wp_redirect(admin_url("admin.php?page=wdk"));
238 }
239 public function bulk_deapprove($posts_selected)
240 {
241
242 // Check _wpnonce
243 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
244
245 $this->load->model('listing_m');
246 foreach($posts_selected as $key=>$post_id)
247 {
248 if($this->listing_m->check_deletable($post_id))
249 $this->listing_m->insert(array('is_approved'=>NULL), $post_id);
250 }
251 do_action('wpdirectorykit/listing/updated');
252 wp_redirect(admin_url("admin.php?page=wdk"));
253 }
254
255 public function bulk_approve($posts_selected)
256 {
257 // Check _wpnonce
258 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
259
260 $this->load->model('listing_m');
261 foreach($posts_selected as $key=>$post_id)
262 {
263 if($this->listing_m->check_deletable($post_id))
264 $this->listing_m->insert(array('is_approved'=>1), $post_id);
265 }
266 do_action('wpdirectorykit/listing/updated');
267 wp_redirect(admin_url("admin.php?page=wdk"));
268 }
269 }
270