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

183 lines 6.2 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 /* [Table Actions Bulk Form] */
19
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 $controller = 'listing';
49 $columns = array('ID', 'location_id', 'category_id', 'post_title', 'post_date', 'search', 'order_by', 'address');
50 $external_columns = array('location_id', 'category_id', 'post_title');
51
52 $this->data['categories'] = $this->category_m->get_parents();
53 $this->data['locations'] = $this->location_m->get_parents();
54 $this->data['order_by'] = array('ID DESC' => __('ID', 'wpdirectorykit').' DESC',
55 'ID ASC' => __('ID', 'wpdirectorykit').' ASC',
56 'post_title ASC' => __('Post Title', 'wpdirectorykit').' ASC',
57 'post_title DESC' => __('Post Title', 'wpdirectorykit').' DESC',
58 'post_date ASC' => __('Post Date', 'wpdirectorykit').' ASC',
59 'post_date DESC' => __('Post Date', 'wpdirectorykit').' DESC',);
60
61 $rules = array(
62 array(
63 'field' => 'location_id',
64 'label' => __('Location', 'wpdirectorykit'),
65 'rules' => ''
66 ),
67 array(
68 'field' => 'category_id',
69 'label' => __('Category', 'wpdirectorykit'),
70 'rules' => ''
71 ),
72 array(
73 'field' => 'search',
74 'label' => __('Search tag', 'wpdirectorykit'),
75 'rules' => ''
76 ),
77 array(
78 'field' => 'order_by',
79 'label' => __('Order By', 'wpdirectorykit'),
80 'rules' => ''
81 ),
82 );
83
84 $this->data['db_data'] = $this->listing_m->prepare_data($this->input->get(), $rules);
85
86 /* [/Search Form] */
87
88 wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns);
89 $total_items = $this->listing_m->total();
90
91 $current_page = 1;
92
93 if(isset($_GET['paged']))
94 $current_page = intval($_GET['paged']);
95
96 $this->data['paged'] = $current_page;
97
98 $per_page = 20;
99 $offset = $per_page*($current_page-1);
100
101 $this->data['pagination_output'] = '';
102
103 if(function_exists('wmvc_wp_paginate'))
104 $this->data['pagination_output'] = wmvc_wp_paginate($total_items, $per_page);
105
106 wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns);
107 $this->data['listings'] = $this->listing_m->get_pagination($per_page, $offset);
108
109 // Load view
110 $this->load->view('wdk/index', $this->data);
111 }
112
113 public function delete()
114 {
115 $this->load->model('listing_m');
116
117 $post_id = (int) $this->input->post_get('id');
118 $paged = (int) $this->input->post_get('paged');
119
120 $this->listing_m->delete($post_id);
121
122 wp_redirect(admin_url("admin.php?page=wdk&paged=$paged"));
123 }
124
125 public function bulk_delete($posts_selected)
126 {
127 $this->load->model('listing_m');
128 foreach($posts_selected as $key=>$post_id)
129 {
130 $this->listing_m->delete($post_id);
131 }
132
133 wp_redirect(admin_url("admin.php?page=wdk"));
134 }
135
136 public function bulk_deactivate($posts_selected)
137 {
138 $this->load->model('listing_m');
139 foreach($posts_selected as $key=>$post_id)
140 {
141 if($this->listing_m->check_deletable($post_id))
142 $this->listing_m->insert(array('is_activated'=>NULL), $post_id);
143 }
144
145 wp_redirect(admin_url("admin.php?page=wdk"));
146 }
147
148 public function bulk_activate($posts_selected)
149 {
150 $this->load->model('listing_m');
151 foreach($posts_selected as $key=>$post_id)
152 {
153 if($this->listing_m->check_deletable($post_id))
154 $this->listing_m->insert(array('is_activated'=>1), $post_id);
155 }
156
157 wp_redirect(admin_url("admin.php?page=wdk"));
158 }
159 public function bulk_deapprove($posts_selected)
160 {
161 $this->load->model('listing_m');
162 foreach($posts_selected as $key=>$post_id)
163 {
164 if($this->listing_m->check_deletable($post_id))
165 $this->listing_m->insert(array('is_approved'=>NULL), $post_id);
166 }
167
168 wp_redirect(admin_url("admin.php?page=wdk"));
169 }
170
171 public function bulk_approve($posts_selected)
172 {
173 $this->load->model('listing_m');
174 foreach($posts_selected as $key=>$post_id)
175 {
176 if($this->listing_m->check_deletable($post_id))
177 $this->listing_m->insert(array('is_approved'=>1), $post_id);
178 }
179
180 wp_redirect(admin_url("admin.php?page=wdk"));
181 }
182 }
183