| @@ -37,8 +37,11 @@ | ||
| 37 | 37 | { |
| 38 | 38 | $id = (int) $this->input->post_get('id'); |
| 39 | 39 | $paged = (int) $this->input->post_get('paged'); |
| 40 | 40 | |
| 41 | + // Check _wpnonce | |
| 42 | + check_admin_referer( 'wdk-location-delete_'.$id, '_wpnonce' ); | |
| 43 | + wdk_access_check('location_m', $id); | |
| 41 | 44 | $this->load->model('location_m'); |
| 42 | 45 | |
| 43 | 46 | $this->location_m->delete($id); |
| 44 | 47 | |
| @@ -46,11 +49,15 @@ | ||
| 46 | 49 | } |
| 47 | 50 | |
| 48 | 51 | public function bulk_delete($posts_selected) |
| 49 | 52 | { |
| 53 | + // Check _wpnonce | |
| 54 | + check_admin_referer( 'wdk-location-bulk', '_wpnonce'); | |
| 55 | + | |
| 50 | 56 | $this->load->model('location_m'); |
| 51 | 57 | foreach($posts_selected as $id) |
| 52 | 58 | { |
| 59 | + wdk_access_check('location_m', $id); | |
| 53 | 60 | $this->location_m->delete($id); |
| 54 | 61 | } |
| 55 | 62 | |
| 56 | 63 | wp_redirect(admin_url("admin.php?page=wdk_location&is_updated=true&custom_message=".urlencode(esc_html__('Selected Locations removed', 'wpdirectorykit')))); |
| @@ -60,9 +67,9 @@ | ||
| 60 | 67 | public function edit() |
| 61 | 68 | { |
| 62 | 69 | $this->load->model('location_m'); |
| 63 | 70 | |
| 64 | - $id = $this->input->post_get('id'); | |
| 71 | + $id = (int) $this->input->post_get('id'); | |
| 65 | 72 | wdk_access_check('location_m', $id); |
| 66 | 73 | |
| 67 | 74 | $this->data['db_data'] = NULL; |
| 68 | 75 | |
| @@ -107,8 +114,13 @@ | ||
| 107 | 114 | 'field' => 'related_svg_map_location', |
| 108 | 115 | 'label' => __('Related SVG Map Location', 'wpdirectorykit'), |
| 109 | 116 | 'rules' => '' |
| 110 | 117 | ), |
| 118 | + array( | |
| 119 | + 'field' => 'titles_for_search', | |
| 120 | + 'label' => __('Alternative titles for search', 'wpdirectorykit'), | |
| 121 | + 'rules' => '' | |
| 122 | + ), | |
| 111 | 123 | ); |
| 112 | 124 | |
| 113 | 125 | global $wp_filesystem; |
| 114 | 126 | // Initialize the WP filesystem, no more using 'file-put-contents' function |
| @@ -117,18 +129,22 @@ | ||
| 117 | 129 | WP_Filesystem(); |
| 118 | 130 | } |
| 119 | 131 | // @codingStandardsIgnoreEnd |
| 120 | 132 | |
| 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'); | |
| 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 | + } | |
| 131 | 147 | } |
| 132 | 148 | |
| 133 | 149 | $this->data['map_related_locations'] = array(); |
| 134 | 150 | |
| @@ -136,26 +152,34 @@ | ||
| 136 | 152 | { |
| 137 | 153 | $this->data['db_data'] = $this->location_m->get($id, TRUE); |
| 138 | 154 | } |
| 139 | 155 | |
| 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'); | |
| 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']); | |
| 143 | 165 | } |
| 144 | - | |
| 145 | - asort($this->data['map_related_locations']); | |
| 146 | 166 | } |
| 147 | 167 | |
| 148 | 168 | if($this->form->run($rules)) |
| 149 | 169 | { |
| 170 | + | |
| 171 | + // Check _wpnonce | |
| 172 | + check_admin_referer( 'wdk-location-edit_'.$id, '_wpnonce' ); | |
| 173 | + | |
| 150 | 174 | // Save procedure for basic data |
| 151 | - $data = $this->location_m->prepare_data($this->input->post(), $rules); | |
| 175 | + $data = $this->location_m->prepare_data(wdk_get_post(), $rules); | |
| 152 | 176 | |
| 153 | 177 | if(empty($id) && strpos($data['location_title'], ',') !== FALSE) { |
| 154 | 178 | |
| 155 | 179 | foreach (explode(',', $data['location_title']) as $title) { |
| 156 | 180 | // Save standard wp post |
| 157 | - $insert_id = $this->location_m->insert(array_merge($data, array('location_title' => $title)), NULL); | |
| 181 | + $insert_id = $this->location_m->insert(array_merge($data, array('location_title' => trim($title))), NULL); | |
| 158 | 182 | } |
| 159 | 183 | wp_redirect(admin_url("admin.php?page=wdk_location&is_updated=true&custom_message=".urlencode(esc_html__('Bulk Locations added', 'wpdirectorykit')))); |
| 160 | 184 | exit; |
| 161 | 185 | } else { |
| @@ -200,9 +224,9 @@ | ||
| 200 | 224 | public function import_from_svg() |
| 201 | 225 | { |
| 202 | 226 | |
| 203 | 227 | if(!function_exists('run_wdk_svg_map')) { |
| 204 | - exit(esc_html__('Addon WDK SVG Map missing', 'wdk-svg-map')); | |
| 228 | + exit(esc_html__('Addon WDK SVG Map missing', 'wpdirectorykit')); | |
| 205 | 229 | } |
| 206 | 230 | |
| 207 | 231 | $this->load->model('location_m'); |
| 208 | 232 | |
| @@ -222,9 +246,11 @@ | ||
| 222 | 246 | |
| 223 | 247 | /* translate */ |
| 224 | 248 | $this->data['maps_list'] = array(); |
| 225 | 249 | foreach ($maps_data as $location_key => $location) { |
| 226 | - $this->data['maps_list'][str_replace('.svg', '', $location_key)] = esc_html__($location, 'wdk-svg-map'); | |
| 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'); | |
| 227 | 253 | } |
| 228 | 254 | |
| 229 | 255 | $this->data['db_data'] = NULL; |
| 230 | 256 | |
| @@ -249,10 +275,14 @@ | ||
| 249 | 275 | ); |
| 250 | 276 | |
| 251 | 277 | if($this->form->run($rules)) |
| 252 | 278 | { |
| 279 | + | |
| 280 | + // Check _wpnonce | |
| 281 | + check_admin_referer( 'wdk-svg-import', '_wpnonce' ); | |
| 282 | + | |
| 253 | 283 | // Save procedure for basic data |
| 254 | - $data = $this->location_m->prepare_data($this->input->post(), $rules); | |
| 284 | + $data = $this->location_m->prepare_data(wdk_get_post(), $rules); | |
| 255 | 285 | |
| 256 | 286 | $maps_data_json = $wp_filesystem->get_contents(WDK_SVG_MAP_PATH.'resourse/maps-db.json'); |
| 257 | 287 | $maps_data = json_decode($maps_data_json, JSON_OBJECT_AS_ARRAY); |
| 258 | 288 | |
| @@ -258,10 +288,14 @@ | ||
| 258 | 288 | |
| 259 | 289 | if(isset($maps_data[strtolower(wmvc_show_data('related_svg_map',$data))])) { |
| 260 | 290 | $insert_data = array('parent_id' => wmvc_show_data('related_svg_map_location',$data, NULL)); |
| 261 | 291 | 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); | |
| 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); | |
| 264 | 298 | } |
| 265 | 299 | } |
| 266 | 300 | |
| 267 | 301 | } |