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

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