PluginProbe
WP Directory Kit / 1.1.6
WP Directory Kit v1.1.6
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.1.6, at application/controllers/Wdk_category.php

169 lines 5.7 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 $this->load->model('category_m');
41
42 $this->category_m->delete($id);
43
44 wp_redirect(admin_url("admin.php?page=wdk_category&paged=$paged"));
45 }
46
47 public function bulk_delete($posts_selected)
48 {
49 $this->load->model('category_m');
50 foreach($posts_selected as $id)
51 {
52 $this->category_m->delete($id);
53 }
54
55 wp_redirect(admin_url("admin.php?page=wdk_category&is_updated=true&custom_message=".urlencode(esc_html__('Selected Categories removed', 'wpdirectorykit'))));
56 exit();
57 }
58
59 public function edit()
60 {
61 $this->load->model('category_m');
62
63 $id = $this->input->post_get('id');
64 wdk_access_check('category_m', $id);
65 $this->data['db_data'] = NULL;
66
67 $this->data['form'] = &$this->form;
68
69 $this->data['parents'] = $this->category_m->get_parents($id);
70
71 //exit($this->db->last_query());
72
73 $rules = array(
74 array(
75 'field' => 'category_title',
76 'label' => __('Title', 'wpdirectorykit'),
77 'rules' => 'required'
78 ),
79 array(
80 'field' => 'order_index',
81 'label' => __('Order Index', 'wpdirectorykit'),
82 'rules' => ''
83 ),
84 array(
85 'field' => 'font_icon_code',
86 'label' => __('Font icon code', 'wpdirectorykit'),
87 'rules' => ''
88 ),
89 array(
90 'field' => 'marker_image_id',
91 'label' => __('Custom Map Marker Image', 'wpdirectorykit'),
92 'rules' => ''
93 ),
94 array(
95 'field' => 'parent_id',
96 'label' => __('Parent', 'wpdirectorykit'),
97 'rules' => ''
98 ),
99 array(
100 'field' => 'icon_id',
101 'label' => __('Parent', 'wpdirectorykit'),
102 'rules' => ''
103 ),
104 array(
105 'field' => 'image_id',
106 'label' => __('Parent', 'wpdirectorykit'),
107 'rules' => ''
108 ),
109 array(
110 'field' => 'category_color',
111 'label' => __('Color', 'wpdirectorykit'),
112 'rules' => ''
113 ),
114 );
115
116 if($this->form->run($rules))
117 {
118 // Save procedure for basic data
119 $data = $this->category_m->prepare_data($this->input->post(), $rules);
120
121 if(empty($id) && strpos($data['category_title'], ',') !== FALSE) {
122
123 foreach (explode(',', $data['category_title']) as $title) {
124 // Save standard wp post
125 $insert_id = $this->category_m->insert(array_merge($data, array('category_title' => $title)), NULL);
126 }
127 wp_redirect(admin_url("admin.php?page=wdk_category&is_updated=true&custom_message=".urlencode(esc_html__('Bulk Categories added', 'wpdirectorykit'))));
128 exit;
129 } else {
130 // Save standard wp post
131 $data['icon_path'] = wdk_generate_path_image($data['icon_id']);
132 $data['image_path'] = wdk_generate_path_image($data['image_id']);
133 $data['marker_image_path'] = wdk_generate_path_image($data['marker_image_id']);
134
135 $insert_id = $this->category_m->insert($data, $id);
136
137 /* indexes by new order and reorder */
138 $results = $this->category_m->get_tree_table();
139 $values = array();
140 $order_index = 1;
141 foreach( $results as $item)
142 {
143 $values[] = array('order_index' => $order_index, 'idcategory' => $item->idcategory);
144 $order_index++;
145 }
146 $this->db->updateBatch( $this->category_m->_table_name, $values, 'idcategory');
147
148 //exit($this->db->last_error());
149
150 // redirect
151
152 if(!empty($insert_id) && empty($id))
153 {
154 wp_redirect(admin_url("admin.php?page=wdk_category&id=$insert_id&is_updated=true"));
155 exit;
156 }
157 }
158 }
159
160 if(!empty($id))
161 {
162 $this->data['db_data'] = $this->category_m->get($id, TRUE);
163 }
164
165 $this->load->view('wdk_category/category_edit', $this->data);
166 }
167
168 }
169