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

Wdk_location.php in WP Directory Kit 1.1.6, at application/controllers/Wdk_location.php

273 lines 10.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_location 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
14 /* [Table Actions Bulk Form] */
15 $table_action = $this->input->post_get('table_action');
16 $action = $this->input->post_get('action');
17 $posts_selected = $this->input->post_get('post');
18
19 if(!empty($table_action))
20 {
21 switch ($action) {
22 case 'delete':
23 $this->bulk_delete($posts_selected);
24 break;
25 default:
26 }
27 }
28
29 $this->load->model('location_m');
30
31 $this->data['locations'] = $this->location_m->get_tree_table();
32 // Load view
33 $this->load->view('wdk_location/index', $this->data);
34 }
35
36 public function delete()
37 {
38 $id = (int) $this->input->post_get('id');
39 $paged = (int) $this->input->post_get('paged');
40
41 $this->load->model('location_m');
42
43 $this->location_m->delete($id);
44
45 wp_redirect(admin_url("admin.php?page=wdk_location&paged=$paged"));
46 }
47
48 public function bulk_delete($posts_selected)
49 {
50 $this->load->model('location_m');
51 foreach($posts_selected as $id)
52 {
53 $this->location_m->delete($id);
54 }
55
56 wp_redirect(admin_url("admin.php?page=wdk_location&is_updated=true&custom_message=".urlencode(esc_html__('Selected Locations removed', 'wpdirectorykit'))));
57 exit;
58 }
59
60 public function edit()
61 {
62 $this->load->model('location_m');
63
64 $id = $this->input->post_get('id');
65 wdk_access_check('location_m', $id);
66
67 $this->data['db_data'] = NULL;
68
69 $this->data['form'] = &$this->form;
70
71 $this->data['parents'] = $this->location_m->get_parents($id);
72
73 //exit($this->db->last_query());
74
75 $rules = array(
76 array(
77 'field' => 'location_title',
78 'label' => __('Title', 'wpdirectorykit'),
79 'rules' => 'required'
80 ),
81 array(
82 'field' => 'order_index',
83 'label' => __('Order Index', 'wpdirectorykit'),
84 'rules' => ''
85 ),
86 array(
87 'field' => 'parent_id',
88 'label' => __('Parent', 'wpdirectorykit'),
89 'rules' => ''
90 ),
91 array(
92 'field' => 'icon_id',
93 'label' => __('Parent', 'wpdirectorykit'),
94 'rules' => ''
95 ),
96 array(
97 'field' => 'image_id',
98 'label' => __('Parent', 'wpdirectorykit'),
99 'rules' => ''
100 ),
101 array(
102 'field' => 'related_svg_map',
103 'label' => __('Related SVG Map', 'wpdirectorykit'),
104 'rules' => ''
105 ),
106 array(
107 'field' => 'related_svg_map_location',
108 'label' => __('Related SVG Map Location', 'wpdirectorykit'),
109 'rules' => ''
110 ),
111 );
112
113 global $wp_filesystem;
114 // Initialize the WP filesystem, no more using 'file-put-contents' function
115 if (empty($wp_filesystem)) {
116 require_once (ABSPATH . '/wp-admin/includes/file.php');
117 WP_Filesystem();
118 }
119 // @codingStandardsIgnoreEnd
120
121 $maps_list_json = $wp_filesystem->get_contents(WDK_SVG_MAP_PATH.'resourse/maps-list-db.json');
122 $maps_list = json_decode($maps_list_json, JSON_OBJECT_AS_ARRAY);
123
124 $maps_data_json = $wp_filesystem->get_contents(WDK_SVG_MAP_PATH.'resourse/maps-db.json');
125 $maps_data = json_decode($maps_data_json, JSON_OBJECT_AS_ARRAY);
126
127 /* translate */
128 $this->data['maps_list'] = array();
129 foreach ($maps_list as $location_key => $location) {
130 $this->data['maps_list'][str_replace('.svg', '', $location_key)] = esc_html__($location, 'wdk-svg-map');
131 }
132
133 $this->data['map_related_locations'] = array();
134
135 if(!empty($id))
136 {
137 $this->data['db_data'] = $this->location_m->get($id, TRUE);
138 }
139
140 if(wmvc_show_data('related_svg_map', $this->data['db_data'], false) && isset($maps_data[wmvc_show_data('related_svg_map', $this->data['db_data'])])) {
141 foreach ($maps_data[wmvc_show_data('related_svg_map', $this->data['db_data'])]['locations'] as $location_key => $location) {
142 $this->data['map_related_locations'][$location_key] = esc_html__($location, 'wdk-svg-map');
143 }
144
145 asort($this->data['map_related_locations']);
146 }
147
148 if($this->form->run($rules))
149 {
150 // Save procedure for basic data
151 $data = $this->location_m->prepare_data($this->input->post(), $rules);
152
153 if(empty($id) && strpos($data['location_title'], ',') !== FALSE) {
154
155 foreach (explode(',', $data['location_title']) as $title) {
156 // Save standard wp post
157 $insert_id = $this->location_m->insert(array_merge($data, array('location_title' => $title)), NULL);
158 }
159 wp_redirect(admin_url("admin.php?page=wdk_location&is_updated=true&custom_message=".urlencode(esc_html__('Bulk Locations added', 'wpdirectorykit'))));
160 exit;
161 } else {
162
163 $data['icon_path'] = wdk_generate_path_image($data['icon_id']);
164 $data['image_path'] = wdk_generate_path_image($data['image_id']);
165
166 // Save standard wp post
167 $insert_id = $this->location_m->insert($data, $id);
168
169 //exit($this->db->last_error());
170
171 /* indexes by new order and reorder */
172 $results = $this->location_m->get_tree_table();
173 $values = array();
174 $order_index = 1;
175 foreach( $results as $item)
176 {
177 $values[] = array('order_index' => $order_index, 'idlocation' => $item->idlocation);
178 $order_index++;
179 }
180 $this->db->updateBatch( $this->location_m->_table_name, $values, 'idlocation');
181
182 // redirect
183 if(!empty($insert_id) && empty($id))
184 {
185 wp_redirect(admin_url("admin.php?page=wdk_location&id=$insert_id&is_updated=true"));
186 exit;
187 }
188 }
189
190 }
191
192 if(!empty($id))
193 {
194 $this->data['db_data'] = $this->location_m->get($id, TRUE);
195 }
196
197 $this->load->view('wdk_location/location_edit', $this->data);
198 }
199
200 public function import_from_svg()
201 {
202
203 if(!function_exists('run_wdk_svg_map')) {
204 exit(esc_html__('Addon WDK SVG Map missing', 'wdk-svg-map'));
205 }
206
207 $this->load->model('location_m');
208
209 $id = $this->input->post_get('id');
210 wdk_access_check('location_m', $id);
211
212 global $wp_filesystem;
213 // Initialize the WP filesystem, no more using 'file-put-contents' function
214 if (empty($wp_filesystem)) {
215 require_once (ABSPATH . '/wp-admin/includes/file.php');
216 WP_Filesystem();
217 }
218 // @codingStandardsIgnoreEnd
219
220 $maps_data_json = $wp_filesystem->get_contents(WDK_SVG_MAP_PATH.'resourse/maps-list-db.json');
221 $maps_data = json_decode($maps_data_json, JSON_OBJECT_AS_ARRAY);
222
223 /* translate */
224 $this->data['maps_list'] = array();
225 foreach ($maps_data as $location_key => $location) {
226 $this->data['maps_list'][str_replace('.svg', '', $location_key)] = esc_html__($location, 'wdk-svg-map');
227 }
228
229 $this->data['db_data'] = NULL;
230
231 $this->data['form'] = &$this->form;
232
233 $this->data['location'] = $this->location_m->get($id, TRUE);
234 $this->data['parents'] = $this->location_m->get_parents();
235
236 //exit($this->db->last_query());
237
238 $rules = array (
239 array (
240 'field' => 'related_svg_map',
241 'label' => __('Related SVG Map', 'wpdirectorykit'),
242 'rules' => 'required'
243 ),
244 array (
245 'field' => 'related_svg_map_location',
246 'label' => __('Related SVG Map Location', 'wpdirectorykit'),
247 'rules' => ''
248 ),
249 );
250
251 if($this->form->run($rules))
252 {
253 // Save procedure for basic data
254 $data = $this->location_m->prepare_data($this->input->post(), $rules);
255
256 $maps_data_json = $wp_filesystem->get_contents(WDK_SVG_MAP_PATH.'resourse/maps-db.json');
257 $maps_data = json_decode($maps_data_json, JSON_OBJECT_AS_ARRAY);
258
259 if(isset($maps_data[strtolower(wmvc_show_data('related_svg_map',$data))])) {
260 $insert_data = array('parent_id' => wmvc_show_data('related_svg_map_location',$data, NULL));
261 foreach ($maps_data[strtolower(wmvc_show_data('related_svg_map',$data))]['locations'] as $location_key => $location) {
262 if(!$this->location_m->get_by(array('parent_id'=>wmvc_show_data('related_svg_map_location',$data, NULL),'location_title'=>esc_html__($location, 'wdk-svg-map')), TRUE))
263 $insert_id = $this->location_m->insert(array_merge($insert_data, array('location_title' => esc_html__($location, 'wdk-svg-map'))), NULL);
264 }
265 }
266
267 }
268
269 $this->load->view('wdk_location/import_from_svg', $this->data);
270 }
271
272 }
273