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

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

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