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

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

180 lines 6.1 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 );
123
124 if($this->form->run($rules))
125 {
126 // Check _wpnonce
127 check_admin_referer( 'wdk-category-edit_'.$id, '_wpnonce' );
128
129 // Save procedure for basic data
130 $data = $this->category_m->prepare_data(wdk_get_post(), $rules);
131
132 if(empty($id) && strpos($data['category_title'], ',') !== FALSE) {
133
134 foreach (explode(',', $data['category_title']) as $title) {
135 // Save standard wp post
136 $insert_id = $this->category_m->insert(array_merge($data, array('category_title' => $title)), NULL);
137 }
138 wp_redirect(admin_url("admin.php?page=wdk_category&is_updated=true&custom_message=".urlencode(esc_html__('Bulk Categories added', 'wpdirectorykit'))));
139 exit;
140 } else {
141 // Save standard wp post
142 $data['icon_path'] = wdk_generate_path_image($data['icon_id']);
143 $data['image_path'] = wdk_generate_path_image($data['image_id']);
144 $data['marker_image_path'] = wdk_generate_path_image($data['marker_image_id']);
145
146 $insert_id = $this->category_m->insert($data, $id);
147
148 /* indexes by new order and reorder */
149 $results = $this->category_m->get_tree_table();
150 $values = array();
151 $order_index = 1;
152 foreach( $results as $item)
153 {
154 $values[] = array('order_index' => $order_index, 'idcategory' => $item->idcategory);
155 $order_index++;
156 }
157 $this->db->updateBatch( $this->category_m->_table_name, $values, 'idcategory');
158
159 //exit($this->db->last_error());
160
161 // redirect
162
163 if(!empty($insert_id) && empty($id))
164 {
165 wp_redirect(admin_url("admin.php?page=wdk_category&id=$insert_id&is_updated=true"));
166 exit;
167 }
168 }
169 }
170
171 if(!empty($id))
172 {
173 $this->data['db_data'] = $this->category_m->get($id, TRUE);
174 }
175
176 $this->load->view('wdk_category/category_edit', $this->data);
177 }
178
179 }
180