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
← All changes | application/controllers/Wdk_location.php +214 -21 1.1.0 → 1.5.9 View file →
@@ -8,8 +8,25 @@
8 8 }
9 9
10 10 public function index()
11 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 +
12 29 $this->load->model('location_m');
13 30
14 31 $this->data['locations'] = $this->location_m->get_tree_table();
15 32 // Load view
@@ -20,8 +37,11 @@
20 37 {
21 38 $id = (int) $this->input->post_get('id');
22 39 $paged = (int) $this->input->post_get('paged');
23 40
41 + // Check _wpnonce
42 + check_admin_referer( 'wdk-location-delete_'.$id, '_wpnonce' );
43 + wdk_access_check('location_m', $id);
24 44 $this->load->model('location_m');
25 45
26 46 $this->location_m->delete($id);
27 47
@@ -26,14 +46,30 @@
26 46 $this->location_m->delete($id);
27 47
28 48 wp_redirect(admin_url("admin.php?page=wdk_location&paged=$paged"));
29 49 }
30 -
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 +
31 67 public function edit()
32 68 {
33 69 $this->load->model('location_m');
34 70
35 - $id = $this->input->post_get('id');
71 + $id = (int) $this->input->post_get('id');
36 72 wdk_access_check('location_m', $id);
37 73
38 74 $this->data['db_data'] = NULL;
39 75
@@ -68,37 +104,112 @@
68 104 'field' => 'image_id',
69 105 'label' => __('Parent', 'wpdirectorykit'),
70 106 'rules' => ''
71 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 + ),
72 123 );
73 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 +
74 168 if($this->form->run($rules))
75 169 {
170 +
171 + // Check _wpnonce
172 + check_admin_referer( 'wdk-location-edit_'.$id, '_wpnonce' );
173 +
76 174 // Save procedure for basic data
77 - $data = $this->location_m->prepare_data($this->input->post(), $rules);
175 + $data = $this->location_m->prepare_data(wdk_get_post(), $rules);
78 176
79 - // Save standard wp post
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 {
80 186
81 - $insert_id = $this->location_m->insert($data, $id);
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);
82 192
83 - //exit($this->db->last_error());
193 + //exit($this->db->last_error());
84 194
85 - /* indexes by new order and reorder */
86 - $results = $this->location_m->get_tree_table();
87 - $values = array();
88 - $order_index = 1;
89 - foreach( $results as $item)
90 - {
91 - $values[] = array('order_index' => $order_index, 'idlocation' => $item->idlocation);
92 - $order_index++;
93 - }
94 - $this->db->updateBatch( $this->location_m->_table_name, $values, 'idlocation');
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');
95 205
96 - // redirect
97 - if(!empty($insert_id) && empty($id))
98 - {
99 - wp_redirect(admin_url("admin.php?page=wdk_location&id=$insert_id&is_updated=true"));
100 - exit;
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 + }
101 212 }
102 213
103 214 }
104 215
@@ -107,7 +218,89 @@
107 218 $this->data['db_data'] = $this->location_m->get($id, TRUE);
108 219 }
109 220
110 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);
111 304 }
112 305
113 306 }