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

214 lines 7.7 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 $this->listing_m->delete($post_id);
152
153 wp_redirect(admin_url("admin.php?page=wdk&paged=$paged"));
154 }
155
156 public function bulk_delete($posts_selected)
157 {
158 $this->load->model('listing_m');
159 foreach($posts_selected as $key=>$post_id)
160 {
161 $this->listing_m->delete($post_id);
162 }
163
164 wp_redirect(admin_url("admin.php?page=wdk"));
165 }
166
167 public function bulk_deactivate($posts_selected)
168 {
169 $this->load->model('listing_m');
170 foreach($posts_selected as $key=>$post_id)
171 {
172 if($this->listing_m->check_deletable($post_id))
173 $this->listing_m->insert(array('is_activated'=>NULL), $post_id);
174 }
175
176 wp_redirect(admin_url("admin.php?page=wdk"));
177 }
178
179 public function bulk_activate($posts_selected)
180 {
181 $this->load->model('listing_m');
182 foreach($posts_selected as $key=>$post_id)
183 {
184 if($this->listing_m->check_deletable($post_id))
185 $this->listing_m->insert(array('is_activated'=>1), $post_id);
186 }
187
188 wp_redirect(admin_url("admin.php?page=wdk"));
189 }
190 public function bulk_deapprove($posts_selected)
191 {
192 $this->load->model('listing_m');
193 foreach($posts_selected as $key=>$post_id)
194 {
195 if($this->listing_m->check_deletable($post_id))
196 $this->listing_m->insert(array('is_approved'=>NULL), $post_id);
197 }
198
199 wp_redirect(admin_url("admin.php?page=wdk"));
200 }
201
202 public function bulk_approve($posts_selected)
203 {
204 $this->load->model('listing_m');
205 foreach($posts_selected as $key=>$post_id)
206 {
207 if($this->listing_m->check_deletable($post_id))
208 $this->listing_m->insert(array('is_approved'=>1), $post_id);
209 }
210
211 wp_redirect(admin_url("admin.php?page=wdk"));
212 }
213 }
214