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_messages.php

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

211 lines 7.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_messages extends Winter_MVC_Controller {
5
6 public function __construct(){
7 parent::__construct();
8 }
9
10 public function index()
11 {
12 $this->load->model('messages_m');
13 $this->data['form'] = &$this->form;
14
15 $dbusers = get_users( array( 'search' => '',
16 'orderby' => 'display_name', 'order' => 'ASC'));
17 $users = array();
18 foreach($dbusers as $dbuser) {
19 $this->data['users'][wmvc_show_data('ID', $dbuser)] = '#'.wmvc_show_data('ID', $dbuser).', '.wmvc_show_data('display_name', $dbuser);
20 }
21
22 /* [Table Actions Bulk Form] */
23
24 $table_action = $this->input->post_get('table_action');
25 $action = $this->input->post_get('action');
26 $posts_selected = $this->input->post_get('post');
27
28 if(!empty($table_action))
29 {
30 switch ($action) {
31 case 'delete':
32 $this->bulk_delete($posts_selected);
33 break;
34 case 'deactivate':
35 $this->bulk_deactivate($posts_selected);
36 break;
37 case 'activate':
38 $this->bulk_activate($posts_selected);
39 break;
40 default:
41 }
42 }
43
44 /* [Search Form] */
45
46 $controller = 'messages';
47 $columns = array('idmessage','user_id_editor','display_name','user_login', 'user_email', 'search', 'order_by');
48 $external_columns = array('user_id_editor','display_name','user_login', 'user_email');
49
50 $this->data['order_by'] = array('idmessage DESC' => __('ID DESC', 'wpdirectorykit'),
51 'idmessage ASC' => __('ID ASC', 'wpdirectorykit'),
52 'display_name DESC' => __('User DESC', 'wpdirectorykit'),
53 'display_name ASC' => __('User ASC', 'wpdirectorykit'),
54 );
55
56 $rules = array(
57 array(
58 'field' => 'search',
59 'label' => __('Search tag', 'wpdirectorykit'),
60 'rules' => ''
61 ),
62 array(
63 'field' => 'order_by',
64 'label' => __('Order By', 'wpdirectorykit'),
65 'rules' => ''
66 ),
67 array(
68 'field' => 'user_id_editor',
69 'label' => __('User', 'wpdirectorykit'),
70 'rules' => ''
71 ),
72 );
73
74 $this->data['db_data'] = $this->messages_m->prepare_data($this->input->get(), $rules);
75
76 global $wpdb;
77 $wp_usermeta_table = $wpdb->users;
78
79 $this->db->join($this->db->prefix.'wdk_listings ON '.$this->db->prefix.'wdk_listings.post_id = '.$this->messages_m->_table_name.'.post_id', NULL, 'LEFT');
80 $this->db->join($wp_usermeta_table.' ON '.$this->db->prefix.'wdk_listings.user_id_editor = '.$wp_usermeta_table.'.ID', NULL, 'LEFT');
81 wdk_messages_prepare_search_query_GET($columns, $controller.'_m', $external_columns);
82 $total_items = $this->messages_m->total();
83
84 $current_page = 1;
85 if(isset($_GET['paged']))
86 $current_page = intval($_GET['paged']);
87
88 $this->data['paged'] = $current_page;
89
90 $per_page = 20;
91 $offset = $per_page*($current_page-1);
92
93 $this->data['pagination_output'] = '';
94
95 if(function_exists('wmvc_wp_paginate'))
96 $this->data['pagination_output'] = wmvc_wp_paginate($total_items, $per_page);
97
98 wdk_messages_prepare_search_query_GET($columns, $controller.'_m', $external_columns);
99
100 $post_table = $this->db->prefix.'posts';
101 $this->db->select($this->messages_m->_table_name.'.*,'.$this->db->prefix.'wdk_listings.*, '.$this->messages_m->_table_name.'.date AS message_date,'.$post_table.'.post_title,'.$wp_usermeta_table.'.display_name,'.$wp_usermeta_table.'.user_login,'
102 .$wp_usermeta_table.'.user_email');
103 $this->db->join($this->db->prefix.'wdk_listings ON '.$this->db->prefix.'wdk_listings.post_id = '.$this->messages_m->_table_name.'.post_id', NULL, 'LEFT');
104 $this->db->join($wp_usermeta_table.' ON '.$this->db->prefix.'wdk_listings.user_id_editor = '.$wp_usermeta_table.'.ID', NULL, 'LEFT');
105 $this->data['messages'] = $this->messages_m->get_pagination($per_page, $offset);
106
107 // Load view
108 $this->load->view('wdk_messages/index', $this->data);
109 }
110
111 public function delete()
112 {
113 $id = (int) $this->input->post_get('id');
114 $paged = (int) $this->input->post_get('paged');
115
116 // Check _wpnonce
117 check_admin_referer( 'wdk-messages-delete_'.$id, '_wpnonce' );
118
119 $this->load->model('messages_m');
120 wdk_access_check('messages_m', $id);
121 $this->messages_m->delete($id);
122
123 wp_redirect(admin_url("admin.php?page=wdk_messages&paged=$paged"));
124 }
125
126 public function bulk_delete($posts_selected)
127 {
128 // Check _wpnonce
129 check_admin_referer( 'wdk-messages-bulk', '_wpnonce');
130
131 $this->load->model('messages_m');
132
133 foreach($posts_selected as $id)
134 {
135 wdk_access_check('messages_m', $id);
136 $this->messages_m->delete($id);
137 }
138
139 wp_redirect(admin_url("admin.php?page=wdk_messages&is_updated=true&custom_message=".urlencode(esc_html__('Selected Messages removed', 'wpdirectorykit'))));
140 exit();
141 }
142
143 public function edit()
144 {
145 $this->load->model('messages_m');
146
147 $id = (int) $this->input->post_get('id');
148 wdk_access_check('messages_m', $id);
149 $this->data['db_data'] = NULL;
150
151 $this->data['form'] = &$this->form;
152
153 //exit($this->db->last_query());
154
155 $rules = array(
156 array(
157 'field' => 'post_id',
158 'label' => __('Listing Id', 'wpdirectorykit'),
159 'rules' => 'required'
160 ),
161 array(
162 'field' => 'date',
163 'label' => __('Date', 'wpdirectorykit'),
164 'rules' => ''
165 ),
166 array(
167 'field' => 'message',
168 'label' => __('Message', 'wpdirectorykit'),
169 'rules' => ''
170 ),
171 array(
172 'field' => 'is_readed',
173 'label' => __('Readed', 'wpdirectorykit'),
174 'rules' => ''
175 ),
176 );
177
178 if($this->form->run($rules))
179 {
180
181 // Check _wpnonce
182 check_admin_referer( 'wdk-messages-edit_'.$id, '_wpnonce' );
183
184 // Save procedure for basic data
185 $data = $this->messages_m->prepare_data(wdk_get_post(), $rules);
186
187 // Save standard wp post
188
189 $insert_id = $this->messages_m->insert($data, $id);
190
191 //exit($this->db->last_error());
192
193 // redirect
194 if(!empty($insert_id) && empty($id))
195 {
196 wp_redirect(admin_url("admin.php?page=wdk_messages&id=$insert_id&is_updated=true"));
197 exit;
198 }
199
200 }
201
202 if(!empty($id))
203 {
204 $this->data['db_data'] = $this->messages_m->get($id, TRUE);
205 }
206
207 $this->load->view('wdk_messages/edit', $this->data);
208 }
209
210 }
211