PluginProbe
WP Directory Kit / 1.1.8
WP Directory Kit v1.1.8
1.5.9 1.5.7 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 All 37 releases
wpdirectorykit / application / controllers / Wdk_location.php

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

277 lines 10.2 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 if(function_exists('run_wdk_svg_map')) {
122 $maps_list_json = $wp_filesystem->get_contents(WDK_SVG_MAP_PATH.'resourse/maps-list-db.json');
123 $maps_list = json_decode($maps_list_json, JSON_OBJECT_AS_ARRAY);
124
125 $maps_data_json = $wp_filesystem->get_contents(WDK_SVG_MAP_PATH.'resourse/maps-db.json');
126 $maps_data = json_decode($maps_data_json, JSON_OBJECT_AS_ARRAY);
127
128 /* translate */
129 $this->data['maps_list'] = array();
130 foreach ($maps_list as $location_key => $location) {
131 $this->data['maps_list'][str_replace('.svg', '', $location_key)] = esc_html__($location, 'wdk-svg-map');
132 }
133 }
134
135 $this->data['map_related_locations'] = array();
136
137 if(!empty($id))
138 {
139 $this->data['db_data'] = $this->location_m->get($id, TRUE);
140 }
141
142 if(function_exists('run_wdk_svg_map')) {
143 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'])])) {
144 foreach ($maps_data[wmvc_show_data('related_svg_map', $this->data['db_data'])]['locations'] as $location_key => $location) {
145 $this->data['map_related_locations'][$location_key] = esc_html__($location, 'wdk-svg-map');
146 }
147
148 asort($this->data['map_related_locations']);
149 }
150 }
151
152 if($this->form->run($rules))
153 {
154 // Save procedure for basic data
155 $data = $this->location_m->prepare_data($this->input->post(), $rules);
156
157 if(empty($id) && strpos($data['location_title'], ',') !== FALSE) {
158
159 foreach (explode(',', $data['location_title']) as $title) {
160 // Save standard wp post
161 $insert_id = $this->location_m->insert(array_merge($data, array('location_title' => $title)), NULL);
162 }
163 wp_redirect(admin_url("admin.php?page=wdk_location&is_updated=true&custom_message=".urlencode(esc_html__('Bulk Locations added', 'wpdirectorykit'))));
164 exit;
165 } else {
166
167 $data['icon_path'] = wdk_generate_path_image($data['icon_id']);
168 $data['image_path'] = wdk_generate_path_image($data['image_id']);
169
170 // Save standard wp post
171 $insert_id = $this->location_m->insert($data, $id);
172
173 //exit($this->db->last_error());
174
175 /* indexes by new order and reorder */
176 $results = $this->location_m->get_tree_table();
177 $values = array();
178 $order_index = 1;
179 foreach( $results as $item)
180 {
181 $values[] = array('order_index' => $order_index, 'idlocation' => $item->idlocation);
182 $order_index++;
183 }
184 $this->db->updateBatch( $this->location_m->_table_name, $values, 'idlocation');
185
186 // redirect
187 if(!empty($insert_id) && empty($id))
188 {
189 wp_redirect(admin_url("admin.php?page=wdk_location&id=$insert_id&is_updated=true"));
190 exit;
191 }
192 }
193
194 }
195
196 if(!empty($id))
197 {
198 $this->data['db_data'] = $this->location_m->get($id, TRUE);
199 }
200
201 $this->load->view('wdk_location/location_edit', $this->data);
202 }
203
204 public function import_from_svg()
205 {
206
207 if(!function_exists('run_wdk_svg_map')) {
208 exit(esc_html__('Addon WDK SVG Map missing', 'wdk-svg-map'));
209 }
210
211 $this->load->model('location_m');
212
213 $id = $this->input->post_get('id');
214 wdk_access_check('location_m', $id);
215
216 global $wp_filesystem;
217 // Initialize the WP filesystem, no more using 'file-put-contents' function
218 if (empty($wp_filesystem)) {
219 require_once (ABSPATH . '/wp-admin/includes/file.php');
220 WP_Filesystem();
221 }
222 // @codingStandardsIgnoreEnd
223
224 $maps_data_json = $wp_filesystem->get_contents(WDK_SVG_MAP_PATH.'resourse/maps-list-db.json');
225 $maps_data = json_decode($maps_data_json, JSON_OBJECT_AS_ARRAY);
226
227 /* translate */
228 $this->data['maps_list'] = array();
229 foreach ($maps_data as $location_key => $location) {
230 $this->data['maps_list'][str_replace('.svg', '', $location_key)] = esc_html__($location, 'wdk-svg-map');
231 }
232
233 $this->data['db_data'] = NULL;
234
235 $this->data['form'] = &$this->form;
236
237 $this->data['location'] = $this->location_m->get($id, TRUE);
238 $this->data['parents'] = $this->location_m->get_parents();
239
240 //exit($this->db->last_query());
241
242 $rules = array (
243 array (
244 'field' => 'related_svg_map',
245 'label' => __('Related SVG Map', 'wpdirectorykit'),
246 'rules' => 'required'
247 ),
248 array (
249 'field' => 'related_svg_map_location',
250 'label' => __('Related SVG Map Location', 'wpdirectorykit'),
251 'rules' => ''
252 ),
253 );
254
255 if($this->form->run($rules))
256 {
257 // Save procedure for basic data
258 $data = $this->location_m->prepare_data($this->input->post(), $rules);
259
260 $maps_data_json = $wp_filesystem->get_contents(WDK_SVG_MAP_PATH.'resourse/maps-db.json');
261 $maps_data = json_decode($maps_data_json, JSON_OBJECT_AS_ARRAY);
262
263 if(isset($maps_data[strtolower(wmvc_show_data('related_svg_map',$data))])) {
264 $insert_data = array('parent_id' => wmvc_show_data('related_svg_map_location',$data, NULL));
265 foreach ($maps_data[strtolower(wmvc_show_data('related_svg_map',$data))]['locations'] as $location_key => $location) {
266 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))
267 $insert_id = $this->location_m->insert(array_merge($insert_data, array('location_title' => esc_html__($location, 'wdk-svg-map'))), NULL);
268 }
269 }
270
271 }
272
273 $this->load->view('wdk_location/import_from_svg', $this->data);
274 }
275
276 }
277