PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
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.5.9, at application/controllers/Wdk_location.php

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