1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Personal data exporters. |
4
|
|
|
* |
5
|
|
|
* @since 1.2.26 |
6
|
|
|
* @package GeoDirectory |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
defined( 'ABSPATH' ) || exit; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* GeoDir_Privacy_Exporters Class. |
13
|
|
|
*/ |
14
|
|
|
class GeoDir_Privacy_Exporters { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Finds and exports data which could be used to identify a person from GeoDirectory data associated with an email address. |
18
|
|
|
* |
19
|
|
|
* Posts are exported in blocks of 10 to avoid timeouts. |
20
|
|
|
* |
21
|
|
|
* @since 1.6.26 |
22
|
|
|
* @param string $email_address The user email address. |
23
|
|
|
* @param int $page Page. |
24
|
|
|
* @return array An array of personal data in name value pairs |
25
|
|
|
*/ |
26
|
|
|
public static function post_data_exporter( $email_address, $page ) { |
27
|
|
|
$post_type = GeoDir_Privacy::exporter_post_type(); |
28
|
|
|
|
29
|
|
|
$done = false; |
|
|
|
|
30
|
|
|
$page = (int) $page; |
31
|
|
|
$data_to_export = array(); |
32
|
|
|
|
33
|
|
|
$posts = self::posts_by_author( $email_address, $post_type, $page ); |
34
|
|
|
|
35
|
|
|
if ( 0 < count( $posts ) ) { |
36
|
|
|
$obj_post_type = get_post_type_object( $post_type ); |
37
|
|
|
|
38
|
|
|
foreach ( $posts as $post_ID ) { |
39
|
|
|
$gd_post = geodir_get_post_info( $post_ID ); |
40
|
|
|
if ( empty( $gd_post ) ) { |
41
|
|
|
continue; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$data_to_export[] = array( |
45
|
|
|
'group_id' => 'geodirectory-post-' . $post_type, |
46
|
|
|
'group_label' => __( $obj_post_type->labels->name, 'geodirectory' ), |
47
|
|
|
'item_id' => 'post-' . $post_ID, |
48
|
|
|
'data' => self::get_post_personal_data( $gd_post ), |
|
|
|
|
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
$done = 10 > count( $posts ); |
52
|
|
|
} else { |
53
|
|
|
$done = true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return array( |
57
|
|
|
'data' => $data_to_export, |
58
|
|
|
'done' => $done, |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get personal data (key/value pairs) for an post object. |
64
|
|
|
* |
65
|
|
|
* @since 1.6.26 |
66
|
|
|
* @param WP_Post $gd_post The post object. |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
protected static function get_post_personal_data( $gd_post ) { |
70
|
|
|
$post_categories = array(); |
71
|
|
|
$post_tags = array(); |
72
|
|
|
$default_category = ''; |
73
|
|
|
|
74
|
|
|
$cat_taxonomy = $gd_post->post_type . 'category'; |
75
|
|
|
$tag_taxonomy = $gd_post->post_type . '_tags'; |
76
|
|
|
|
77
|
|
|
$post_terms = wp_get_post_terms( $gd_post->ID, array( $cat_taxonomy, $tag_taxonomy ) ); |
78
|
|
|
if ( ! empty( $post_terms ) && ! is_wp_error( $post_terms ) ) { |
79
|
|
|
foreach ( $post_terms as $term ) { |
80
|
|
|
if ( $term->taxonomy == $cat_taxonomy ) { |
81
|
|
|
$post_categories[] = $term->name; |
82
|
|
|
} else { |
83
|
|
|
$post_tags[] = $term->name; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if ( $gd_post->default_category == $term->term_id ) { |
87
|
|
|
$default_category = $term->name; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$personal_data = array(); |
93
|
|
|
$personal_data[] = array( |
94
|
|
|
'name' => __( 'Post ID', 'geodirectory' ), |
95
|
|
|
'value' => $gd_post->ID, |
96
|
|
|
); |
97
|
|
|
$personal_data[] = array( |
98
|
|
|
'name' => __( 'Post Title', 'geodirectory' ), |
99
|
|
|
'value' => $gd_post->post_title, |
100
|
|
|
); |
101
|
|
|
$personal_data[] = array( |
102
|
|
|
'name' => __( 'Post Date', 'geodirectory' ), |
103
|
|
|
'value' => $gd_post->post_date, |
104
|
|
|
); |
105
|
|
|
$personal_data[] = array( |
106
|
|
|
'name' => __( 'Post Status', 'geodirectory' ), |
107
|
|
|
'value' => $gd_post->post_status, |
108
|
|
|
); |
109
|
|
|
$personal_data[] = array( |
110
|
|
|
'name' => __( 'Post Categories', 'geodirectory' ), |
111
|
|
|
'value' => ( ! empty( $post_categories ) ? implode( ', ', $post_categories ) : '' ), |
112
|
|
|
); |
113
|
|
|
if ( $default_category ) { |
114
|
|
|
$personal_data[] = array( |
115
|
|
|
'name' => __( 'Default Category', 'geodirectory' ), |
116
|
|
|
'value' => $default_category, |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
View Code Duplication |
if ( ! empty( $post_tags ) ) { |
120
|
|
|
$personal_data[] = array( |
121
|
|
|
'name' => __( 'Post Tags', 'geodirectory' ), |
122
|
|
|
'value' => implode( ', ', $post_tags ), |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
$personal_data[] = array( |
126
|
|
|
'name' => __( 'Post URL', 'geodirectory' ), |
127
|
|
|
'value' => get_permalink( $gd_post->ID ), |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
// Post Images |
131
|
|
|
$post_images = geodir_get_images( $gd_post->ID ); |
132
|
|
|
if ( ! empty( $post_images ) ) { |
133
|
|
|
$images = array(); |
134
|
|
|
foreach ( $post_images as $key => $post_image ) { |
|
|
|
|
135
|
|
|
if ( ! empty( $post_image->src ) ) { |
136
|
|
|
$images[] = $post_image->src; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
View Code Duplication |
if ( ! empty( $images ) ) { |
141
|
|
|
$personal_data[] = array( |
142
|
|
|
'name' => __( 'Post Images', 'geodirectory' ), |
143
|
|
|
'value' => self::parse_files_value( $images ), |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
// Post Rating |
149
|
|
|
$post_rating = geodir_get_post_rating( $gd_post->ID ); |
150
|
|
|
if ( $post_rating > 0 ) { |
151
|
|
|
$post_rating = ( is_float( $post_rating) || ( strpos( $post_rating, ".", 1 ) == 1 && strlen( $post_rating ) > 3 ) ) ? number_format( $post_rating, 1, '.', '' ) : $post_rating; |
152
|
|
|
$personal_data[] = array( |
153
|
|
|
'name' => __( 'Post Rating', 'geodirectory' ), |
154
|
|
|
'value' => $post_rating . ' / 5', |
155
|
|
|
); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// Post Reviews |
159
|
|
|
$post_reviews = geodir_get_review_count_total( $gd_post->ID ); |
160
|
|
|
if ( $post_reviews > 0 ) { |
161
|
|
|
$personal_data[] = array( |
162
|
|
|
'name' => __( 'Post Reviews', 'geodirectory' ), |
163
|
|
|
'value' => $post_reviews, |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
View Code Duplication |
if ( ! empty( $gd_post->is_featured ) ) { |
168
|
|
|
$personal_data[] = array( |
169
|
|
|
'name' => __( 'Post Featured', 'geodirectory' ), |
170
|
|
|
'value' => __( 'Yes', 'geodirectory' ), |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
$custom_fields = geodir_post_custom_fields( $gd_post->package_id, 'all', $gd_post->post_type ); |
175
|
|
|
$post_fields = array_keys( (array) $gd_post ); |
176
|
|
|
|
177
|
|
|
foreach ( $custom_fields as $key => $field ) { |
178
|
|
|
$field_name = ! empty( $field['htmlvar_name'] ) ? $field['htmlvar_name'] : ''; |
179
|
|
|
if ( empty( $field_name ) ) { |
180
|
|
|
continue; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
$field = stripslashes_deep( $field ); |
184
|
|
|
|
185
|
|
|
$extra_fields = ! empty( $field['extra_fields'] ) ? $field['extra_fields'] : array(); |
186
|
|
|
$data_type = $field['data_type']; |
|
|
|
|
187
|
|
|
$field_type = $field['field_type']; |
188
|
|
|
$field_title = $field['site_title']; |
189
|
|
|
if ( $field_name == 'post' ) { |
190
|
|
|
$field_name = 'post_address'; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
if ( ! in_array( $field_name, $post_fields ) ) { |
194
|
|
|
continue; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$name = $field_title; |
198
|
|
|
$value = ''; |
199
|
|
|
switch ( $field_type ) { |
200
|
|
|
case 'address': |
201
|
|
|
$location_allowed = function_exists( 'geodir_cpt_no_location' ) && geodir_cpt_no_location( $gd_post->post_type ) ? false : true; |
202
|
|
|
if ( $location_allowed && ! empty( $gd_post->post_country ) && ! empty( $gd_post->post_region ) && ! empty( $gd_post->post_city ) ) { |
203
|
|
|
$personal_data[] = array( |
204
|
|
|
'name' => __( 'Post Address', 'geodirectory' ), |
205
|
|
|
'value' => $gd_post->post_address, |
206
|
|
|
); |
207
|
|
|
$personal_data[] = array( |
208
|
|
|
'name' => __( 'Post City', 'geodirectory' ), |
209
|
|
|
'value' => $gd_post->post_city, |
210
|
|
|
); |
211
|
|
|
$personal_data[] = array( |
212
|
|
|
'name' => __( 'Post Region', 'geodirectory' ), |
213
|
|
|
'value' => $gd_post->post_region, |
214
|
|
|
); |
215
|
|
|
$personal_data[] = array( |
216
|
|
|
'name' => __( 'Post Country', 'geodirectory' ), |
217
|
|
|
'value' => $gd_post->post_country, |
218
|
|
|
); |
219
|
|
|
$personal_data[] = array( |
220
|
|
|
'name' => __( 'Post Zip', 'geodirectory' ), |
221
|
|
|
'value' => $gd_post->post_zip, |
222
|
|
|
); |
223
|
|
|
$personal_data[] = array( |
224
|
|
|
'name' => __( 'Post Latitude', 'geodirectory' ), |
225
|
|
|
'value' => $gd_post->post_latitude, |
226
|
|
|
); |
227
|
|
|
$personal_data[] = array( |
228
|
|
|
'name' => __( 'Post Longitude', 'geodirectory' ), |
229
|
|
|
'value' => $gd_post->post_longitude, |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
break; |
233
|
|
|
case 'checkbox': |
234
|
|
|
if ( ! empty( $gd_post->{$field_name} ) ) { |
235
|
|
|
$value = __( 'Yes', 'geodirectory' ); |
236
|
|
|
} else { |
237
|
|
|
$value = __( 'No', 'geodirectory' ); |
238
|
|
|
} |
239
|
|
|
break; |
240
|
|
|
case 'datepicker': |
241
|
|
|
$value = $gd_post->{$field_name} != '0000-00-00' ? $gd_post->{$field_name} : ''; |
242
|
|
|
break; |
243
|
|
|
case 'radio': |
244
|
|
|
if ( $gd_post->{$field_name} !== '' ) { |
245
|
|
|
if ( $gd_post->{$field_name} == 'f' || $gd_post->{$field_name} == '0') { |
246
|
|
|
$value = __( 'No', 'geodirectory' ); |
247
|
|
|
} else if ( $gd_post->{$field_name} == 't' || $gd_post->{$field_name} == '1') { |
248
|
|
|
$value = __( 'Yes', 'geodirectory' ); |
249
|
|
View Code Duplication |
} else { |
250
|
|
|
if ( !empty( $field['option_values'] ) ) { |
251
|
|
|
$cf_option_values = geodir_string_values_to_options(stripslashes_deep( $field['option_values'] ), true ); |
252
|
|
|
if ( ! empty( $cf_option_values ) ) { |
253
|
|
|
foreach ( $cf_option_values as $cf_option_value ) { |
254
|
|
|
if ( isset( $cf_option_value['value'] ) && $cf_option_value['value'] == $gd_post->{$field_name} ) { |
255
|
|
|
$value = $cf_option_value['label']; |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
break; |
263
|
|
|
case 'select': |
264
|
|
|
$value = __( $gd_post->{$field_name}, 'geodirectory'); |
265
|
|
View Code Duplication |
if ( !empty( $field['option_values'] ) ) { |
266
|
|
|
$cf_option_values = geodir_string_values_to_options(stripslashes_deep( $field['option_values'] ), true ); |
267
|
|
|
if ( ! empty( $cf_option_values ) ) { |
268
|
|
|
foreach ( $cf_option_values as $cf_option_value ) { |
269
|
|
|
if ( isset( $cf_option_value['value'] ) && $cf_option_value['value'] == $gd_post->{$field_name} ) { |
270
|
|
|
$value = $cf_option_value['label']; |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
break; |
276
|
|
|
case 'multiselect': |
277
|
|
|
$field_values = explode( ',', trim( $gd_post->{$field_name}, "," ) ); |
278
|
|
|
if ( is_array( $field_values ) ) { |
279
|
|
|
$field_values = array_map( 'trim', $field_values ); |
280
|
|
|
} |
281
|
|
|
$values = array(); |
282
|
|
View Code Duplication |
if ( ! empty( $field['option_values'] ) ) { |
283
|
|
|
$cf_option_values = geodir_string_values_to_options(stripslashes_deep( $field['option_values'] ), true ); |
284
|
|
|
|
285
|
|
|
if ( ! empty( $cf_option_values ) ) { |
286
|
|
|
foreach ( $cf_option_values as $cf_option_value ) { |
287
|
|
|
if ( isset( $cf_option_value['value'] ) && in_array( $cf_option_value['value'], $field_values ) ) { |
288
|
|
|
$values[] = $cf_option_value['label']; |
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
$value = ! empty( $values ) ? implode( ', ', $values ) : ''; |
294
|
|
|
break; |
295
|
|
|
case 'time': |
296
|
|
|
$value = $gd_post->{$field_name} != '00:00:00' ? $gd_post->{$field_name} : ''; |
297
|
|
|
break; |
298
|
|
|
case 'email': |
299
|
|
|
case 'phone': |
300
|
|
|
case 'text': |
301
|
|
|
case 'url': |
302
|
|
|
case 'html': |
303
|
|
|
case 'textarea': |
304
|
|
|
$value = $gd_post->{$field_name} ? $gd_post->{$field_name} : ''; |
305
|
|
|
break; |
306
|
|
|
case 'file': |
307
|
|
|
$files = explode( ",", $gd_post->{$field_name} ); |
308
|
|
|
if ( ! empty( $files ) ) { |
309
|
|
|
$allowed_file_types = !empty( $extra_fields['gd_file_types'] ) && is_array( $extra_fields['gd_file_types'] ) && !in_array( "*", $extra_fields['gd_file_types'] ) ? $extra_fields['gd_file_types'] : ''; |
310
|
|
|
|
311
|
|
|
$file_urls = array(); |
312
|
|
|
foreach ( $files as $file ) { |
313
|
|
|
if ( ! empty( $file ) ) { |
314
|
|
|
$image_name_arr = explode( '/', $file ); |
315
|
|
|
$curr_img_dir = $image_name_arr[ count( $image_name_arr ) - 2]; |
|
|
|
|
316
|
|
|
$filename = end($image_name_arr); |
317
|
|
|
$img_name_arr = explode('.', $filename); |
|
|
|
|
318
|
|
|
|
319
|
|
|
$arr_file_type = wp_check_filetype( $filename ); |
320
|
|
|
if ( empty( $arr_file_type['ext'] ) || empty( $arr_file_type['type'] ) ) { |
321
|
|
|
continue; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
$uploaded_file_type = $arr_file_type['type']; |
325
|
|
|
$uploaded_file_ext = $arr_file_type['ext']; |
326
|
|
|
|
327
|
|
|
if ( ! empty( $allowed_file_types ) && !in_array( $uploaded_file_ext, $allowed_file_types ) ) { |
328
|
|
|
continue; // Invalid file type. |
329
|
|
|
} |
330
|
|
|
$image_file_types = array( 'image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/x-icon' ); |
331
|
|
|
$audio_file_types = array( 'audio/mpeg', 'audio/ogg', 'audio/mp4', 'audio/vnd.wav', 'audio/basic', 'audio/mid' ); |
|
|
|
|
332
|
|
|
|
333
|
|
|
// If the uploaded file is image |
334
|
|
|
if ( in_array( $uploaded_file_type, $image_file_types ) ) { |
335
|
|
|
$file_urls[] = $file; |
336
|
|
|
} |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
$value = ! empty( $file_urls ) ? self::parse_files_value( $file_urls ) : ''; |
340
|
|
|
} |
341
|
|
|
break; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
View Code Duplication |
if ( ! empty( $name ) && $value !== '' ) { |
345
|
|
|
$personal_data[] = array( |
346
|
|
|
'name' => __( $name, 'geodirectory' ), |
347
|
|
|
'value' => $value, |
348
|
|
|
); |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* Allow extensions to register their own personal data for this post for the export. |
354
|
|
|
* |
355
|
|
|
* @since 1.6.26 |
356
|
|
|
* @param array $personal_data Array of name value pairs to expose in the export. |
357
|
|
|
* @param WP_Post $gd_post The post object. |
358
|
|
|
*/ |
359
|
|
|
$personal_data = apply_filters( 'geodir_privacy_export_post_personal_data', $personal_data, $gd_post ); |
360
|
|
|
|
361
|
|
|
return $personal_data; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
public static function posts_by_author( $email_address, $post_type, $page ) { |
365
|
|
|
if ( empty( $email_address ) || empty( $post_type ) || empty( $page ) ) { |
366
|
|
|
return array(); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
$user = get_user_by( 'email', $email_address ); |
370
|
|
|
if ( empty( $user ) ) { |
371
|
|
|
return array(); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
$statuses = array_keys( get_post_statuses() ); |
375
|
|
|
$skip_statuses = geodir_imex_export_skip_statuses(); |
376
|
|
|
if ( ! empty( $skip_statuses ) ) { |
377
|
|
|
$statuses = array_diff( $statuses, $skip_statuses ); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
$query_args = array( |
381
|
|
|
'post_type' => $post_type, |
382
|
|
|
'post_status' => $statuses, |
383
|
|
|
'fields' => 'ids', |
384
|
|
|
'author' => $user->ID, |
385
|
|
|
'posts_per_page' => 10, |
386
|
|
|
'paged' => $page, |
387
|
|
|
'orderby' => 'ID', |
388
|
|
|
'order' => 'ASC' |
389
|
|
|
); |
390
|
|
|
|
391
|
|
|
$query_args = apply_filters( 'geodir_privacy_post_data_exporter_post_query', $query_args, $post_type, $email_address, $page ); |
392
|
|
|
|
393
|
|
|
$posts = get_posts( $query_args ); |
394
|
|
|
|
395
|
|
|
return apply_filters( 'geodir_privacy_post_data_exporter_posts', $posts, $query_args, $post_type, $email_address, $page ); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
public static function review_data_exporter( $response, $exporter_index, $email_address, $page, $request_id, $send_as_email, $exporter_key ) { |
|
|
|
|
399
|
|
|
global $wpdb; |
400
|
|
|
|
401
|
|
|
$exporter_key = GeoDir_Privacy::personal_data_exporter_key(); |
402
|
|
|
|
403
|
|
|
if ( $exporter_key == 'wordpress-comments' && ! empty( $response['data'] ) ) { |
404
|
|
|
foreach ( $response['data'] as $key => $data ) { |
405
|
|
|
$comment_id = str_replace( 'comment-', '', $data['item_id'] ); |
406
|
|
|
|
407
|
|
|
$review = geodir_get_review( $comment_id ); |
408
|
|
|
if ( ! empty( $review ) ) { |
409
|
|
View Code Duplication |
if ( ! empty( $review->overall_rating ) ) { |
410
|
|
|
$response['data'][ $key ]['data'][] = array( |
411
|
|
|
'name' => __( 'Rating (Overall)', 'geodirectory' ), |
412
|
|
|
'value' => (float)$review->overall_rating . ' / 5', |
413
|
|
|
); |
414
|
|
|
} |
415
|
|
|
if ( defined( 'GEODIRREVIEWRATING_VERSION' ) ) { |
416
|
|
|
if ( get_option( 'geodir_reviewrating_enable_rating' ) ) { |
417
|
|
|
$ratings = maybe_unserialize( $review->ratings ); |
418
|
|
|
|
419
|
|
|
if ( ! empty( $ratings ) && $rating_ids = array_keys( $ratings ) ) { |
420
|
|
|
$styles = $wpdb->get_results( "SELECT rc.id, rc.title, rs.star_number AS total FROM `" . GEODIR_REVIEWRATING_CATEGORY_TABLE . "` AS rc LEFT JOIN `" . GEODIR_REVIEWRATING_STYLE_TABLE . "` AS rs ON rs.id = rc.category_id WHERE rc.id IN(" . implode( ',', $rating_ids ) . ") AND rs.id IS NOT NULL" ); |
421
|
|
|
|
422
|
|
|
foreach ( $styles as $style ) { |
423
|
|
|
if ( ! empty( $ratings[ $style->id ] ) ) { |
424
|
|
|
$response['data'][ $key ]['data'][] = array( |
425
|
|
|
'name' => wp_sprintf( __( 'Rating (%s)', 'geodirectory' ), __( $style->title, 'geodirectory' ) ), |
426
|
|
|
'value' => $ratings[ $style->id ] . ' / ' . $style->total, |
427
|
|
|
); |
428
|
|
|
} |
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
if ( get_option( 'geodir_reviewrating_enable_images' ) ) { |
434
|
|
|
if ( ! empty( $review->comment_images ) ) { |
435
|
|
|
$comment_images = explode( ',', $review->comment_images ); |
436
|
|
|
$response['data'][ $key ]['data'][] = array( |
437
|
|
|
'name' => __( 'Review Images', 'geodirectory' ), |
438
|
|
|
'value' => self::parse_files_value( $comment_images ), |
439
|
|
|
); |
440
|
|
|
} |
441
|
|
|
} |
442
|
|
|
} |
443
|
|
View Code Duplication |
if ( ! empty( $review->post_city ) ) { |
444
|
|
|
$response['data'][ $key ]['data'][] = array( |
445
|
|
|
'name' => __( 'Review City', 'geodirectory' ), |
446
|
|
|
'value' => $review->post_city, |
447
|
|
|
); |
448
|
|
|
} |
449
|
|
View Code Duplication |
if ( ! empty( $review->post_region ) ) { |
450
|
|
|
$response['data'][ $key ]['data'][] = array( |
451
|
|
|
'name' => __( 'Review Region', 'geodirectory' ), |
452
|
|
|
'value' => $review->post_region, |
453
|
|
|
); |
454
|
|
|
} |
455
|
|
View Code Duplication |
if ( ! empty( $review->post_country ) ) { |
456
|
|
|
$response['data'][ $key ]['data'][] = array( |
457
|
|
|
'name' => __( 'Review Country', 'geodirectory' ), |
458
|
|
|
'value' => $review->post_country, |
459
|
|
|
); |
460
|
|
|
} |
461
|
|
View Code Duplication |
if ( ! empty( $review->post_latitude ) ) { |
462
|
|
|
$response['data'][ $key ]['data'][] = array( |
463
|
|
|
'name' => __( 'Review Latitude', 'geodirectory' ), |
464
|
|
|
'value' => $review->post_latitude, |
465
|
|
|
); |
466
|
|
|
} |
467
|
|
View Code Duplication |
if ( ! empty( $review->post_longitude ) ) { |
468
|
|
|
$response['data'][ $key ]['data'][] = array( |
469
|
|
|
'name' => __( 'Review Longitude', 'geodirectory' ), |
470
|
|
|
'value' => $review->post_longitude, |
471
|
|
|
); |
472
|
|
|
} |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
} |
476
|
|
|
return $response; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
public static function parse_files_value( $files ) { |
480
|
|
|
if ( empty( $files ) ) { |
481
|
|
|
return ''; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
if ( ! is_array( $files ) ) { |
485
|
|
|
return $files; |
486
|
|
|
} |
487
|
|
|
|
488
|
|
|
if ( count( $files ) == 1 ) { |
489
|
|
|
return $files[0]; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
$links = array(); |
493
|
|
|
foreach ( $files as $file ) { |
494
|
|
|
if ( false === strpos( $file, ' ' ) && ( 0 === strpos( $file, 'http://' ) || 0 === strpos( $file, 'https://' ) ) ) { |
495
|
|
|
$file = '<a href="' . esc_url( $file ) . '">' . esc_html( $file ) . '</a>'; |
496
|
|
|
} |
497
|
|
|
$links[] = $file; |
498
|
|
|
} |
499
|
|
|
$links = ! empty( $links ) ? implode( ' <br> ', $links ) : ''; |
500
|
|
|
|
501
|
|
|
return $links; |
502
|
|
|
} |
503
|
|
|
} |
504
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.