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

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

185 lines 6.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_category extends Winter_MVC_Controller {
5
6 public function __construct(){
7 parent::__construct();
8 }
9
10 public function index()
11 {
12 $this->data['form'] = &$this->form;
13 /* [Table Actions Bulk Form] */
14 $table_action = $this->input->post_get('table_action');
15 $action = $this->input->post_get('action');
16 $posts_selected = $this->input->post_get('post');
17
18 if(!empty($table_action))
19 {
20 switch ($action) {
21 case 'delete':
22 $this->bulk_delete($posts_selected);
23 break;
24 }
25 }
26
27 $this->load->model('category_m');
28
29 $this->data['categories'] = $this->category_m->get_tree_table();
30
31 // Load view
32 $this->load->view('wdk_category/index', $this->data);
33 }
34
35 public function delete()
36 {
37 $id = (int) $this->input->post_get('id');
38 $paged = (int) $this->input->post_get('paged');
39
40 // Check _wpnonce
41 check_admin_referer( 'wdk-category-delete_'.$id, '_wpnonce' );
42
43 $this->load->model('category_m');
44 wdk_access_check('category_m', $id);
45
46 $this->category_m->delete($id);
47
48 wp_redirect(admin_url("admin.php?page=wdk_category&paged=$paged"));
49 }
50
51 public function bulk_delete($posts_selected)
52 {
53 // Check _wpnonce
54 check_admin_referer( 'wdk-category-bulk', '_wpnonce');
55
56 $this->load->model('category_m');
57 foreach($posts_selected as $id)
58 {
59 wdk_access_check('category_m', $id);
60 $this->category_m->delete($id);
61 }
62
63 wp_redirect(admin_url("admin.php?page=wdk_category&is_updated=true&custom_message=".urlencode(esc_html__('Selected Categories removed', 'wpdirectorykit'))));
64 exit();
65 }
66
67 public function edit()
68 {
69 $this->load->model('category_m');
70
71 $id = (int) $this->input->post_get('id');
72 wdk_access_check('category_m', $id);
73 $this->data['db_data'] = NULL;
74
75 $this->data['form'] = &$this->form;
76
77 $this->data['parents'] = $this->category_m->get_parents($id);
78
79 //exit($this->db->last_query());
80
81 $rules = array(
82 array(
83 'field' => 'category_title',
84 'label' => __('Title', 'wpdirectorykit'),
85 'rules' => 'required'
86 ),
87 array(
88 'field' => 'order_index',
89 'label' => __('Order Index', 'wpdirectorykit'),
90 'rules' => ''
91 ),
92 array(
93 'field' => 'font_icon_code',
94 'label' => __('Font icon code', 'wpdirectorykit'),
95 'rules' => ''
96 ),
97 array(
98 'field' => 'marker_image_id',
99 'label' => __('Custom Map Marker Image', 'wpdirectorykit'),
100 'rules' => ''
101 ),
102 array(
103 'field' => 'parent_id',
104 'label' => __('Parent', 'wpdirectorykit'),
105 'rules' => ''
106 ),
107 array(
108 'field' => 'icon_id',
109 'label' => __('Parent', 'wpdirectorykit'),
110 'rules' => ''
111 ),
112 array(
113 'field' => 'image_id',
114 'label' => __('Parent', 'wpdirectorykit'),
115 'rules' => ''
116 ),
117 array(
118 'field' => 'category_color',
119 'label' => __('Color', 'wpdirectorykit'),
120 'rules' => ''
121 ),
122 array(
123 'field' => 'titles_for_search',
124 'label' => __('Alternative titles for search', 'wpdirectorykit'),
125 'rules' => ''
126 ),
127 );
128
129 if($this->form->run($rules))
130 {
131 // Check _wpnonce
132 check_admin_referer( 'wdk-category-edit_'.$id, '_wpnonce' );
133
134 // Save procedure for basic data
135 $data = $this->category_m->prepare_data(wdk_get_post(), $rules);
136
137 if(empty($id) && strpos($data['category_title'], ',') !== FALSE) {
138
139 foreach (explode(',', $data['category_title']) as $title) {
140 // Save standard wp post
141 $insert_id = $this->category_m->insert(array_merge($data, array('category_title' => trim($title))), NULL);
142 }
143 wp_redirect(admin_url("admin.php?page=wdk_category&is_updated=true&custom_message=".urlencode(esc_html__('Bulk Categories added', 'wpdirectorykit'))));
144 exit;
145 } else {
146 // Save standard wp post
147 $data['icon_path'] = wdk_generate_path_image($data['icon_id']);
148 $data['image_path'] = wdk_generate_path_image($data['image_id']);
149 $data['marker_image_path'] = wdk_generate_path_image($data['marker_image_id']);
150
151 $insert_id = $this->category_m->insert($data, $id);
152
153 /* indexes by new order and reorder */
154 $results = $this->category_m->get_tree_table();
155 $values = array();
156 $order_index = 1;
157 foreach( $results as $item)
158 {
159 $values[] = array('order_index' => $order_index, 'idcategory' => $item->idcategory);
160 $order_index++;
161 }
162 $this->db->updateBatch( $this->category_m->_table_name, $values, 'idcategory');
163
164 //exit($this->db->last_error());
165
166 // redirect
167
168 if(!empty($insert_id) && empty($id))
169 {
170 wp_redirect(admin_url("admin.php?page=wdk_category&id=$insert_id&is_updated=true"));
171 exit;
172 }
173 }
174 }
175
176 if(!empty($id))
177 {
178 $this->data['db_data'] = $this->category_m->get($id, TRUE);
179 }
180
181 $this->load->view('wdk_category/category_edit', $this->data);
182 }
183
184 }
185