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

234 lines 8.3 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 $controller = 'listing';
56 $columns = array('ID', 'location_id', 'category_id', 'post_title', 'post_date', 'search', 'order_by', 'address','user_id_editor', 'is_featured','is_activated','is_approved');
57 $external_columns = array('location_id', 'category_id', 'post_title', 'user_id_editor',);
58
59 $this->data['categories'] = $this->category_m->get_parents();
60 $this->data['locations'] = $this->location_m->get_parents();
61 $this->data['order_by'] = array('ID DESC' => __('ID', 'wpdirectorykit').' DESC',
62 'ID ASC' => __('ID', 'wpdirectorykit').' ASC',
63 'post_title ASC' => __('Post Title', 'wpdirectorykit').' ASC',
64 'post_title DESC' => __('Post Title', 'wpdirectorykit').' DESC',
65 'post_date ASC' => __('Post Date', 'wpdirectorykit').' ASC',
66 'post_date DESC' => __('Post Date', 'wpdirectorykit').' DESC',
67 'date_modified ASC' => __('Last Modified Date', 'wpdirectorykit').' ASC',
68 'date_modified DESC' => __('Last Modified Date', 'wpdirectorykit').' DESC',
69 );
70
71 $rules = array(
72 array(
73 'field' => 'location_id',
74 'label' => __('Location', 'wpdirectorykit'),
75 'rules' => ''
76 ),
77 array(
78 'field' => 'category_id',
79 'label' => __('Category', 'wpdirectorykit'),
80 'rules' => ''
81 ),
82 array(
83 'field' => 'search',
84 'label' => __('Search tag', 'wpdirectorykit'),
85 'rules' => ''
86 ),
87 array(
88 'field' => 'order_by',
89 'label' => __('Order By', 'wpdirectorykit'),
90 'rules' => ''
91 ),
92 array(
93 'field' => 'user_id_editor',
94 'label' => __('User', 'wpdirectorykit'),
95 'rules' => ''
96 ),
97 array(
98 'field' => 'is_activated',
99 'label' => __('Is Activated', 'wpdirectorykit'),
100 'rules' => ''
101 ),
102 array(
103 'field' => 'is_featured',
104 'label' => __('Is Featured', 'wpdirectorykit'),
105 'rules' => ''
106 ),
107 );
108
109 $this->data['db_data'] = $this->listing_m->prepare_data($this->input->get(), $rules);
110
111 /* [/Search Form] */
112
113 $where = array();
114 if(isset($_GET['inactive']) && $_GET['inactive'] == 'on') {
115 $where['(is_activated IS NULL OR is_approved IS NULL)'] = NULL;
116 }
117
118 wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns);
119 $total_items = $this->listing_m->total($where);
120
121 $current_page = 1;
122
123 if(isset($_GET['paged']))
124 $current_page = intval($_GET['paged']);
125
126 $this->data['paged'] = $current_page;
127
128
129 $per_page = 20;
130 $offset = $per_page*($current_page-1);
131
132 $this->data['pagination_output'] = '';
133
134 if(function_exists('wmvc_wp_paginate'))
135 $this->data['pagination_output'] = wmvc_wp_paginate($total_items, $per_page);
136
137 wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns);
138 $this->data['listings'] = $this->listing_m->get_pagination($per_page, $offset, $where);
139
140 // Load view
141 $this->load->view('wdk/index', $this->data);
142 }
143
144 public function delete()
145 {
146 $this->load->model('listing_m');
147
148 $post_id = (int) $this->input->post_get('id');
149 $paged = (int) $this->input->post_get('paged');
150
151 // Check _wpnonce
152 check_admin_referer( 'wdk-listing-delete_'.$post_id, '_wpnonce' );
153
154 $this->listing_m->delete($post_id);
155
156 wp_redirect(admin_url("admin.php?page=wdk&paged=$paged"));
157 }
158
159 public function bulk_delete($posts_selected)
160 {
161 $this->load->model('listing_m');
162
163 // Check _wpnonce
164 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
165
166 foreach($posts_selected as $key=>$post_id)
167 {
168 $this->listing_m->delete($post_id);
169 }
170
171 wp_redirect(admin_url("admin.php?page=wdk"));
172 }
173
174 public function bulk_deactivate($posts_selected)
175 {
176 // Check _wpnonce
177 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
178
179 $this->load->model('listing_m');
180 foreach($posts_selected as $key=>$post_id)
181 {
182 if($this->listing_m->check_deletable($post_id))
183 $this->listing_m->insert(array('is_activated'=>NULL), $post_id);
184 }
185
186 wp_redirect(admin_url("admin.php?page=wdk"));
187 }
188
189 public function bulk_activate($posts_selected)
190 {
191 // Check _wpnonce
192 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
193
194 $this->load->model('listing_m');
195 foreach($posts_selected as $key=>$post_id)
196 {
197 if($this->listing_m->check_deletable($post_id))
198 $this->listing_m->insert(array('is_activated'=>1), $post_id);
199 }
200
201 wp_redirect(admin_url("admin.php?page=wdk"));
202 }
203 public function bulk_deapprove($posts_selected)
204 {
205
206 // Check _wpnonce
207 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
208
209 $this->load->model('listing_m');
210 foreach($posts_selected as $key=>$post_id)
211 {
212 if($this->listing_m->check_deletable($post_id))
213 $this->listing_m->insert(array('is_approved'=>NULL), $post_id);
214 }
215
216 wp_redirect(admin_url("admin.php?page=wdk"));
217 }
218
219 public function bulk_approve($posts_selected)
220 {
221 // Check _wpnonce
222 check_admin_referer( 'wdk-listing-bulk', '_wpnonce');
223
224 $this->load->model('listing_m');
225 foreach($posts_selected as $key=>$post_id)
226 {
227 if($this->listing_m->check_deletable($post_id))
228 $this->listing_m->insert(array('is_approved'=>1), $post_id);
229 }
230
231 wp_redirect(admin_url("admin.php?page=wdk"));
232 }
233 }
234