| 1 |
<?php |
| 2 |
/* |
| 3 |
* this file contains pluing meta information and then shared |
| 4 |
* between pluging and admin classes |
| 5 |
* * [1] |
| 6 |
*/ |
| 7 |
|
| 8 |
if( ! defined('ABSPATH') ) die('Not Allowed.'); |
| 9 |
|
| 10 |
function wpcomment_pa($arr){ |
| 11 |
|
| 12 |
echo '<pre>'; |
| 13 |
print_r($arr); |
| 14 |
echo '</pre>'; |
| 15 |
} |
| 16 |
|
| 17 |
// Get field column |
| 18 |
function wpcomment_get_field_colum( $meta ) { |
| 19 |
|
| 20 |
$field_column = isset($meta['width']) ? $meta['width'] : 12; |
| 21 |
|
| 22 |
// Check width has old settings |
| 23 |
if( strpos( $field_column, '%' ) !== false ) { |
| 24 |
|
| 25 |
$field_column = 12; |
| 26 |
} elseif( intval($field_column) > 12 ) { |
| 27 |
$field_column = 12; |
| 28 |
} |
| 29 |
|
| 30 |
return apply_filters('wpcomment_field_col', $field_column, $meta); |
| 31 |
} |
| 32 |
|
| 33 |
function wpcomment_translation_options( $option ) { |
| 34 |
|
| 35 |
if( !isset($option['option']) ) return $option; |
| 36 |
|
| 37 |
$option['option'] = wpcomment_wpml_translate($option['option'], 'WPCOMMENT'); |
| 38 |
|
| 39 |
// if label is set |
| 40 |
if( isset($option['label']) ) { |
| 41 |
$option['label'] = wpcomment_wpml_translate($option['label'], 'WPCOMMENT'); |
| 42 |
} |
| 43 |
return $option; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* WPML |
| 48 |
* registering and translating strings input by users |
| 49 |
*/ |
| 50 |
function wpcomment_register($field_value, $domain) { |
| 51 |
|
| 52 |
if ( ! function_exists ( 'icl_register_string' )) |
| 53 |
return $field_value; |
| 54 |
|
| 55 |
$field_name = $domain . ' - ' . sanitize_key($field_value); |
| 56 |
//WMPL |
| 57 |
/** |
| 58 |
* register strings for translation |
| 59 |
* source: https://wpml.org/wpml-hook/wpml_register_single_string/ |
| 60 |
*/ |
| 61 |
|
| 62 |
do_action( 'wpml_register_single_string', $domain, $field_name, $field_value ); |
| 63 |
|
| 64 |
//Polylang |
| 65 |
if( function_exists('pll_register_string') ) { |
| 66 |
pll_register_string($field_name, $field_value); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
function wpcomment_wpml_translate($field_value, $domain) { |
| 72 |
|
| 73 |
// $field_value is array then return |
| 74 |
if( is_array($field_value) ) return $field_value; |
| 75 |
|
| 76 |
$field_name = $domain . ' - ' . sanitize_key($field_value); |
| 77 |
$field_value = stripslashes($field_value); |
| 78 |
|
| 79 |
//WMPL |
| 80 |
/** |
| 81 |
* register strings for translation |
| 82 |
* source: https://wpml.org/wpml-hook/wpml_translate_single_string/ |
| 83 |
*/ |
| 84 |
if( has_filter('wpml_translate_single_string') ) { |
| 85 |
$field_value = apply_filters('wpml_translate_single_string', $field_value, $domain, $field_name ); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
// Polylang |
| 90 |
if( function_exists('pll__') ) { |
| 91 |
$field_value = pll__($field_value); |
| 92 |
} |
| 93 |
|
| 94 |
return $field_value; |
| 95 |
} |
| 96 |
/** |
| 97 |
* adding cart items to order |
| 98 |
* @since 8.2 |
| 99 |
**/ |
| 100 |
function wpcomment_make_meta_data( $wpcomment_meta ){ |
| 101 |
|
| 102 |
if( ! isset($wpcomment_meta['wp-comment-fields']['fields']) ) return $wpcomment_meta; |
| 103 |
|
| 104 |
|
| 105 |
$wpcomment_meta = array(); |
| 106 |
$wpcomment_cart_fields = $wpcomment_meta['wp-comment-fields']['fields']; |
| 107 |
$wpcomment_meta_ids = apply_filters('wpcomment_meta_ids_in_cart', null, $wpcomment_meta); |
| 108 |
$wpcomment_meta = wpcomment_generate_cart_meta($wpcomment_cart_fields, $product_id, $wpcomment_meta_ids, $context); |
| 109 |
return apply_filters('wpcomment_meta_data', $wpcomment_meta, $wpcomment_meta, $context); |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* This function will process all fields in cart and return into |
| 114 |
* readable form for comment meta |
| 115 |
* @params: $wpcomment_meta |
| 116 |
**/ |
| 117 |
function wpcomment_output_meta( $comment_meta ) { |
| 118 |
|
| 119 |
$wpcomment_meta = []; |
| 120 |
|
| 121 |
foreach( $comment_meta as $key => $value) { |
| 122 |
|
| 123 |
// if no value |
| 124 |
if( $value == '' ) continue; |
| 125 |
|
| 126 |
// $cart_item['data'] ->post_type == 'product' ? $cart_item['data']->get_id() : $cart_item['data']->get_parent_id(); |
| 127 |
$field_meta = wpcomment_get_field_meta_by_dataname( $key ); |
| 128 |
$data_name = $key; |
| 129 |
// wpcomment_pa($value); |
| 130 |
|
| 131 |
// If field deleted while it's in cart |
| 132 |
if( empty($field_meta) ) continue; |
| 133 |
|
| 134 |
$field_type = isset($field_meta['type']) ? $field_meta['type'] : ''; |
| 135 |
$field_title= isset($field_meta['title']) ? $field_meta['title'] : ''; |
| 136 |
|
| 137 |
// third party plugin for different fields types |
| 138 |
$field_type = apply_filters('wpcomment_make_meta_data_field_type', $field_type, $field_meta); |
| 139 |
$meta_data = array(); |
| 140 |
|
| 141 |
switch( $field_type ) { |
| 142 |
|
| 143 |
case 'file': |
| 144 |
$file_thumbs_html = ''; |
| 145 |
foreach($value as $file_id => $file_uploaded) { |
| 146 |
$file_name = $file_uploaded['org']; |
| 147 |
$file_thumbs_html .= wpcomment_create_thumb_for_meta($field_meta, $file_name); |
| 148 |
} |
| 149 |
$meta_data = array('type'=>$field_type, 'name'=>$field_title, 'value'=>$file_thumbs_html); |
| 150 |
break; |
| 151 |
case 'image': |
| 152 |
if($value) { |
| 153 |
|
| 154 |
$display = wpcomment_generate_html_for_images($field_meta, $value); |
| 155 |
|
| 156 |
$meta_data = array('type'=>$field_type, 'name'=>$field_title, 'value'=>$value, 'display'=>$display); |
| 157 |
} |
| 158 |
break; |
| 159 |
|
| 160 |
case 'palettes': |
| 161 |
$selected_color = array(); |
| 162 |
$color_options = $field_meta['options']; |
| 163 |
$options_filter = wpcomment_convert_options_to_key_val($field_meta['options'], $field_meta); |
| 164 |
foreach($value as $color){ |
| 165 |
foreach($options_filter as $option_key => $opt){ |
| 166 |
|
| 167 |
if( $color == $option_key ){ |
| 168 |
$display = !empty($opt['label']) ? $opt['label'] : $opt['option']; |
| 169 |
$selected_color[] = $display; |
| 170 |
$meta_data = array('type'=>$field_type, 'name'=>$field_title, 'value'=>$value, 'display'=>implode(',',$selected_color)); |
| 171 |
break; |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
break; |
| 177 |
|
| 178 |
case 'audio': |
| 179 |
if($value) { |
| 180 |
$wpcomment_file_count = 1; |
| 181 |
foreach($value as $id => $audio_meta) { |
| 182 |
$audio_meta = json_decode(stripslashes($audio_meta), true); |
| 183 |
$audio_url = stripslashes($audio_meta['link']); |
| 184 |
$audio_html = '<a href="'.esc_url($audio_url).'" title="'.esc_attr($audio_meta['title']).'">'.$audio_meta['title'].'</a>'; |
| 185 |
$meta_lable = $field_title.': '.$wpcomment_file_count++; |
| 186 |
// $wpcomment_meta[$meta_lable] = $audio_html; |
| 187 |
$meta_data = array('type'=>$field_type, 'name'=>$meta_lable, 'value'=>$audio_html); |
| 188 |
} |
| 189 |
} |
| 190 |
break; |
| 191 |
|
| 192 |
case 'checkbox': |
| 193 |
|
| 194 |
$option_posted = $value; |
| 195 |
|
| 196 |
if( is_array($option_posted) ) { |
| 197 |
|
| 198 |
$option_posted = stripslashes_deep($option_posted); |
| 199 |
} |
| 200 |
|
| 201 |
$option_label_array = array(); |
| 202 |
$options_data_array = array(); |
| 203 |
|
| 204 |
$options_filter = wpcomment_convert_options_to_key_val($field_meta['options'], $field_meta); |
| 205 |
|
| 206 |
foreach($option_posted as $posted_value) { |
| 207 |
foreach($options_filter as $option_key => $option) { |
| 208 |
// var_dump($posted_value, $option); |
| 209 |
|
| 210 |
$option_value = stripslashes(wpcomment_wpml_translate($option['raw'],'wp-comment-fields')); |
| 211 |
|
| 212 |
if( stripcslashes($posted_value) === $option_value ) { |
| 213 |
$option_label_array[] = $option['label']; |
| 214 |
$options_data_array[] = array('option'=>$option['raw'],'id'=>$option['option_id']); |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
$meta_data = array('type'=>$field_type, 'name'=>$field_title, 'value'=> implode(', ',$option_label_array)); |
| 220 |
break; |
| 221 |
|
| 222 |
case 'select': |
| 223 |
case 'radio': |
| 224 |
|
| 225 |
$posted_value = stripslashes($value); |
| 226 |
|
| 227 |
$option_price = ''; |
| 228 |
$option_data = array(); |
| 229 |
|
| 230 |
$options_filter = wpcomment_convert_options_to_key_val($field_meta['options'], $field_meta); |
| 231 |
|
| 232 |
foreach($options_filter as $option_key => $option) { |
| 233 |
|
| 234 |
$option_value = stripslashes(wpcomment_wpml_translate($option['raw'],'WPCOMMENT')); |
| 235 |
|
| 236 |
if( $posted_value == $option_value ) { |
| 237 |
$option_price = $option['label']; |
| 238 |
$option_data[] = array('option'=>$option['raw'],'id'=>$option['option_id']); |
| 239 |
break; |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
$meta_data = array('type'=>$field_type, 'name' => $field_title, |
| 244 |
'value' => $option_price, |
| 245 |
); |
| 246 |
break; |
| 247 |
|
| 248 |
case 'section': |
| 249 |
$show_cart = isset($field_meta['comment_display']) && $field_meta['comment_display'] == 'on' ? true : false; |
| 250 |
if( $show_cart ) |
| 251 |
$meta_data = array('type'=>$field_type, 'name' => $field_title, 'value' => $value); |
| 252 |
break; |
| 253 |
|
| 254 |
case 'hidden': |
| 255 |
$show_cart = isset($field_meta['comment_display']) && $field_meta['comment_display'] == 'on' ? false : true; |
| 256 |
$meta_data = array('type'=>$field_type, 'name' => $field_title, 'value' => $value, 'hidden' => $show_cart); |
| 257 |
break; |
| 258 |
|
| 259 |
default: |
| 260 |
|
| 261 |
$value = is_array($value) ? implode(",", $value) : $value; |
| 262 |
// $wpcomment_meta[$field_title] = stripcslashes($value); |
| 263 |
$meta_data = array('type'=>$field_type, 'name'=>$field_title, 'value'=>stripcslashes($value)); |
| 264 |
break; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
$meta_data_field = apply_filters('wpcomment_fields_cart_meta', $meta_data, $key, $field_meta, $comment_meta); |
| 269 |
$wpcomment_meta[$key] = $meta_data_field; |
| 270 |
} |
| 271 |
|
| 272 |
return $wpcomment_meta; |
| 273 |
} |
| 274 |
|
| 275 |
/** |
| 276 |
* hiding prices for variable product |
| 277 |
* only when priced options are used |
| 278 |
* |
| 279 |
* @since 8.2 |
| 280 |
**/ |
| 281 |
function wpcomment_meta_priced_options( $the_meta ) { |
| 282 |
|
| 283 |
$has_priced_option = false; |
| 284 |
foreach ( $the_meta as $key => $meta ) { |
| 285 |
|
| 286 |
$options = ( isset($meta['options'] ) ? $meta['options'] : array()); |
| 287 |
foreach($options as $opt) |
| 288 |
{ |
| 289 |
|
| 290 |
if( isset($opt['price']) && $opt['price'] != '') { |
| 291 |
$has_priced_option = true; |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
return apply_filters('wpcomment_meta_priced_options', $has_priced_option, $the_meta); |
| 297 |
} |
| 298 |
|
| 299 |
/** |
| 300 |
* check if browser is IE |
| 301 |
**/ |
| 302 |
function wpcomment_if_browser_is_ie() |
| 303 |
{ |
| 304 |
//print_r($_SERVER['HTTP_USER_AGENT']); |
| 305 |
|
| 306 |
if(!(isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))){ |
| 307 |
return false; |
| 308 |
}else{ |
| 309 |
return true; |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
function wpcomment_settings_link($links) { |
| 314 |
|
| 315 |
$quote_url = "https://najeebmedia.com/get-quote/"; |
| 316 |
$wpcomment_setting_url = admin_url( 'admin.php?page=wpcomment'); |
| 317 |
$video_url = '#'; |
| 318 |
$wpcomment_deactivate = '#'; |
| 319 |
|
| 320 |
$wpcomment_links = array(); |
| 321 |
$wpcomment_links[] = sprintf(__('<a href="%s">Add Fields</a>', "wpcomment"), esc_url($wpcomment_setting_url) ); |
| 322 |
$wpcomment_links[] = sprintf(__('<a href="%s" target="_blank">Quick Video Guide</a>', "wpcomment"), esc_url($video_url) ); |
| 323 |
$wpcomment_links[] = sprintf(__('<a href="%s">Customized Solution</a>', "wpcomment"), esc_url($quote_url) ); |
| 324 |
|
| 325 |
foreach($wpcomment_links as $link) { |
| 326 |
|
| 327 |
array_push( $links, $link ); |
| 328 |
} |
| 329 |
|
| 330 |
return $links; |
| 331 |
} |
| 332 |
|
| 333 |
// Get field type by data_name |
| 334 |
function wpcomment_get_field_meta_by_dataname( $data_name ) { |
| 335 |
|
| 336 |
$form_obj = new WPComment_Form; |
| 337 |
$wpcomment_fields= $form_obj::$fields; |
| 338 |
|
| 339 |
if( ! $wpcomment_fields ) return ''; |
| 340 |
|
| 341 |
// wpcomment_pa($wpcomment_fields); |
| 342 |
$data_name = apply_filters('wpcomment_get_field_by_dataname_dataname', $data_name); |
| 343 |
|
| 344 |
$field_meta = ''; |
| 345 |
foreach($wpcomment_fields as $field) { |
| 346 |
|
| 347 |
if( ! wpcomment_is_field_visible($field) ) continue; |
| 348 |
|
| 349 |
if( !empty($field['data_name']) && sanitize_key($field['data_name']) == $data_name) { |
| 350 |
$field_meta = $field; |
| 351 |
break; |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
return $field_meta; |
| 356 |
} |
| 357 |
|
| 358 |
// Is PPOM meta has field of specific type |
| 359 |
function wpcomment_has_field_by_type( $product_id, $field_type ) { |
| 360 |
|
| 361 |
$form_obj = new WPComment_Form; |
| 362 |
$wpcomment_fields= $form_obj::$fields; |
| 363 |
if( ! $wpcomment_fields ) return ''; |
| 364 |
|
| 365 |
$fields_found = array(); |
| 366 |
foreach($wpcomment_fields as $field) { |
| 367 |
|
| 368 |
if( !empty($field['type']) && $field['type'] == $field_type ) { |
| 369 |
$fields_found[] = $field; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
return $fields_found; |
| 374 |
} |
| 375 |
|
| 376 |
function wpcomment_load_template($file_name, $variables=array('')){ |
| 377 |
|
| 378 |
if( is_array($variables)) |
| 379 |
extract( $variables ); |
| 380 |
|
| 381 |
$file_path = WPCOMMENT_PATH . '/templates/'.$file_name; |
| 382 |
$file_path = apply_filters('wpcomment_load_template', $file_path, $file_name, $variables); |
| 383 |
|
| 384 |
if( file_exists($file_path)) |
| 385 |
include ($file_path); |
| 386 |
else |
| 387 |
die('File not found'.$file_path); |
| 388 |
} |
| 389 |
|
| 390 |
// Loading loading input template absolute path provided |
| 391 |
function wpcomment_load_input_templates($template_path, $vars=array('')){ |
| 392 |
|
| 393 |
// Extract variable from array |
| 394 |
if( $vars != null && is_array($vars) ){ extract( $vars ); } |
| 395 |
|
| 396 |
if( isset($addon_type) ) { |
| 397 |
$full_path = $template_path; |
| 398 |
}else{ |
| 399 |
$full_path = WPCOMMENT_PATH . "/templates/{$template_path}"; |
| 400 |
} |
| 401 |
|
| 402 |
// wpcomment_pa($vars); |
| 403 |
|
| 404 |
// For template override |
| 405 |
$full_path = apply_filters('wpcomment_input_templates_path', $full_path, $template_path, $vars); |
| 406 |
|
| 407 |
// Load Inputs from theme |
| 408 |
// $theme_template = wpcomment_load_templates_from_theme($template_path); |
| 409 |
|
| 410 |
// if( $theme_template != null ) { $full_path = $theme_template; } |
| 411 |
|
| 412 |
if( file_exists( $full_path ) ){ |
| 413 |
include( $full_path ); |
| 414 |
}else { |
| 415 |
die( "File not found {$full_path}" ); |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
// load file from full given path |
| 420 |
function wpcomment_load_file($file_path, $variables=array('')){ |
| 421 |
|
| 422 |
if( is_array($variables)) |
| 423 |
extract( $variables ); |
| 424 |
|
| 425 |
if( file_exists($file_path)) |
| 426 |
include ($file_path); |
| 427 |
else |
| 428 |
die('File not found'.$file_path); |
| 429 |
} |
| 430 |
|
| 431 |
function wpcomment_load_bootstrap_css() { |
| 432 |
|
| 433 |
$return = true; |
| 434 |
if( wpcomment_get_option('wpcomment_disable_bootstrap') == 'yes' ) $return = false; |
| 435 |
|
| 436 |
return apply_filters('wpcomment_bootstrap_css', $return); |
| 437 |
} |
| 438 |
|
| 439 |
function wpcomment_load_fontawesome() { |
| 440 |
|
| 441 |
$return = true; |
| 442 |
if( wpcomment_get_option('wpcomment_disable_fontawesome') == 'yes' ) $return = false; |
| 443 |
|
| 444 |
return apply_filters('wpcomment_disable_fontawesome', $return); |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
function wpcomment_convert_options_to_key_val($options, $meta) { |
| 449 |
|
| 450 |
if( empty($options) ) return $options; |
| 451 |
|
| 452 |
if( ! apply_filters('wpcomment_is_option_convertable', true, $meta) ){ |
| 453 |
return $options; |
| 454 |
} |
| 455 |
|
| 456 |
$meta_type = isset($meta['type']) ? $meta['type'] : ''; |
| 457 |
|
| 458 |
// Do not change options for cropper |
| 459 |
// if( $meta['type'] == 'cropper' ) return $options; |
| 460 |
|
| 461 |
$wpcomment_new_option = array(); |
| 462 |
foreach($options as $option) { |
| 463 |
|
| 464 |
$the_option = isset($option['option']) ? stripslashes($option['option']) : ''; |
| 465 |
|
| 466 |
//Following input has 'title' instead 'option' in options array |
| 467 |
$option_with_titles_keys = apply_filters('wpcomment_option_with_title_key', array('imageselect', 'image', 'audio') ); |
| 468 |
if( in_array($meta_type, $option_with_titles_keys) ) { |
| 469 |
|
| 470 |
$the_option = ! empty($option['title']) ? stripslashes($option['title']) : $option['id']; |
| 471 |
} |
| 472 |
|
| 473 |
if( $the_option != '' ) { |
| 474 |
|
| 475 |
$option = wpcomment_translation_options($option); |
| 476 |
$data_name = isset($meta['data_name']) ? $meta['data_name'] : ''; |
| 477 |
|
| 478 |
// wpcomment_pa($option); |
| 479 |
$option_label = wpcomment_generate_option_label($option, $meta); |
| 480 |
|
| 481 |
|
| 482 |
$option_id = wpcomment_get_option_id($option, $meta); |
| 483 |
|
| 484 |
$wpcomment_new_option[$the_option] = array('label' => $option_label, |
| 485 |
'raw' => $the_option, |
| 486 |
'data_name' => $data_name, |
| 487 |
'id' => $option_id, // Legacy key fix |
| 488 |
'option_id' => $option_id); |
| 489 |
|
| 490 |
if($meta_type === 'image' ) { |
| 491 |
$wpcomment_new_option[$the_option]['link'] = isset($option['link']) ? $option['link'] : ''; |
| 492 |
$wpcomment_new_option[$the_option]['url'] = isset($option['url']) ? $option['url'] : ''; |
| 493 |
$wpcomment_new_option[$the_option]['image_id'] = $option['id']; |
| 494 |
} |
| 495 |
|
| 496 |
|
| 497 |
$wpcomment_new_option = apply_filters('wpcomment_option_meta',$wpcomment_new_option, $the_option, $option, $meta); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
if( !empty($meta['first_option']) ) { |
| 502 |
|
| 503 |
$fo_labeld = wpcomment_wpml_translate($meta['first_option'], 'WPCOMMENT'); |
| 504 |
$first_option = array('' => array('label'=> $fo_labeld, |
| 505 |
'raw' => '', |
| 506 |
'option_id' => '__first_option__') |
| 507 |
); |
| 508 |
|
| 509 |
$wpcomment_new_option = $first_option + $wpcomment_new_option; |
| 510 |
// array_unshift( $wpcomment_new_option, $first_option); |
| 511 |
} |
| 512 |
|
| 513 |
// wpcomment_pa($wpcomment_new_option); |
| 514 |
return apply_filters('wpcomment_options_after_changes', $wpcomment_new_option, $options, $meta); |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
// Generating option label with price |
| 519 |
function wpcomment_generate_option_label( $option, $meta) { |
| 520 |
|
| 521 |
$meta_type = isset($meta['type']) ? $meta['type'] : ''; |
| 522 |
|
| 523 |
$the_option = isset($option['option']) ? $option['option'] : ''; |
| 524 |
if( $meta_type == 'imageselect' || $meta_type === 'image') { |
| 525 |
$the_option = isset($option['title']) ? $option['title'] : ''; |
| 526 |
} |
| 527 |
|
| 528 |
$option_label = !empty($option['label']) ? $option['label'] : $the_option; |
| 529 |
$option_label = stripcslashes($option_label); |
| 530 |
|
| 531 |
|
| 532 |
return apply_filters('wpcomment_option_label', $option_label, $option, $meta); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
// Retrun unique option ID |
| 537 |
function wpcomment_get_option_id($option, $field_meta=null) { |
| 538 |
|
| 539 |
$data_name = isset($field_meta['data_name']) ? $field_meta['data_name'] : ''; |
| 540 |
$the_option = isset($option['option']) ? $option['option'] : ''; |
| 541 |
$field_type = isset($field_meta['type']) ? $field_meta['type'] : ''; |
| 542 |
|
| 543 |
switch($field_type) { |
| 544 |
case 'image': |
| 545 |
$the_option = isset($option['title']) ? $option['title'] : ''; |
| 546 |
$option['id'] = sanitize_key($the_option); |
| 547 |
break; |
| 548 |
|
| 549 |
case 'imageselect': |
| 550 |
$the_option = isset($option['title']) ? $option['title'] : ''; |
| 551 |
break; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
$default_option = is_null($data_name) ? $the_option : $data_name.'_'.$the_option; |
| 556 |
|
| 557 |
$option_id = empty($option['id']) ? $default_option : $option['id']; |
| 558 |
|
| 559 |
return apply_filters('wpcomment_option_id', sanitize_key( $option_id ), $option, $data_name ); |
| 560 |
} |
| 561 |
|
| 562 |
function wpcomment_get_price_including_tax( $price, $product ) { |
| 563 |
|
| 564 |
if( 'incl' !== get_option( 'woocommerce_tax_display_shop' ) ) return $price; |
| 565 |
|
| 566 |
$line_price = $price; |
| 567 |
$return_price = $line_price; |
| 568 |
|
| 569 |
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() ); |
| 570 |
$taxes = WC_Tax::calc_tax( $line_price, $tax_rates, false ); |
| 571 |
$tax_amount = WC_Tax::get_tax_total( $taxes ); |
| 572 |
$return_price = round( $line_price + $tax_amount, wc_get_price_decimals() ); |
| 573 |
return $return_price; |
| 574 |
|
| 575 |
if ( $product->is_taxable() ) { |
| 576 |
if ( ! wc_prices_include_tax() ) { |
| 577 |
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() ); |
| 578 |
$taxes = WC_Tax::calc_tax( $line_price, $tax_rates, false ); |
| 579 |
$tax_amount = WC_Tax::get_tax_total( $taxes ); |
| 580 |
$return_price = round( $line_price + $tax_amount, wc_get_price_decimals() ); |
| 581 |
} else { |
| 582 |
$tax_rates = WC_Tax::get_rates( $product->get_tax_class() ); |
| 583 |
$base_tax_rates = WC_Tax::get_base_tax_rates( $product->get_tax_class( 'unfiltered' ) ); |
| 584 |
|
| 585 |
/** |
| 586 |
* If the customer is excempt from VAT, remove the taxes here. |
| 587 |
* Either remove the base or the user taxes depending on woocommerce_adjust_non_base_location_prices setting. |
| 588 |
*/ |
| 589 |
if ( ! empty( WC()->customer ) && WC()->customer->get_is_vat_exempt() ) { |
| 590 |
$remove_taxes = apply_filters( 'woocommerce_adjust_non_base_location_prices', true ) ? WC_Tax::calc_tax( $line_price, $base_tax_rates, true ) : WC_Tax::calc_tax( $line_price, $tax_rates, true ); |
| 591 |
$remove_tax = array_sum( $remove_taxes ); |
| 592 |
$return_price = round( $line_price - $remove_tax, wc_get_price_decimals() ); |
| 593 |
|
| 594 |
/** |
| 595 |
* The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing with out of base locations. |
| 596 |
* e.g. If a product costs 10 including tax, all users will pay 10 regardless of location and taxes. |
| 597 |
* This feature is experimental @since 2.4.7 and may change in the future. Use at your risk. |
| 598 |
*/ |
| 599 |
} elseif ( $tax_rates !== $base_tax_rates && apply_filters( 'woocommerce_adjust_non_base_location_prices', true ) ) { |
| 600 |
$base_taxes = WC_Tax::calc_tax( $line_price, $base_tax_rates, true ); |
| 601 |
$modded_taxes = WC_Tax::calc_tax( $line_price - array_sum( $base_taxes ), $tax_rates, false ); |
| 602 |
$return_price = round( $line_price - array_sum( $base_taxes ) + wc_round_tax_total( array_sum( $modded_taxes ), wc_get_price_decimals() ), wc_get_price_decimals() ); |
| 603 |
} |
| 604 |
} |
| 605 |
} |
| 606 |
return apply_filters( 'wpcomment_get_price_including_tax', $return_price, $product); |
| 607 |
} |
| 608 |
|
| 609 |
// Check if field conditionally hidden |
| 610 |
function wpcomment_is_field_hidden_by_condition( $field_name, $conditionally_hidden=null ) { |
| 611 |
|
| 612 |
if( !isset($_POST['wp-comment-fields']['conditionally_hidden']) && $conditionally_hidden == null ) return false; |
| 613 |
|
| 614 |
$conditionally_hidden = isset($_POST['wp-comment-fields']['conditionally_hidden']) ? sanitize_text_field($_POST['wp-comment-fields']['conditionally_hidden']) : $conditionally_hidden; |
| 615 |
|
| 616 |
$wpcomment_is_hidden = false; |
| 617 |
|
| 618 |
$wpcomment_hidden_fields = explode(",", $conditionally_hidden ); |
| 619 |
// Remove duplicates |
| 620 |
$wpcomment_hidden_fields = array_unique( $wpcomment_hidden_fields ); |
| 621 |
|
| 622 |
if( in_array($field_name, $wpcomment_hidden_fields) ) { |
| 623 |
|
| 624 |
$wpcomment_is_hidden = true; |
| 625 |
} |
| 626 |
|
| 627 |
return apply_filters('wpcomment_is_field_hidden_by_condition', $wpcomment_is_hidden); |
| 628 |
} |
| 629 |
|
| 630 |
// Return thumbs size |
| 631 |
function wpcomment_get_thumbs_size() { |
| 632 |
|
| 633 |
return apply_filters('wpcomment_thumbs_size', '100px'); |
| 634 |
} |
| 635 |
|
| 636 |
// Return file size in kb |
| 637 |
function wpcomment_get_filesize_in_kb( $file_name ) { |
| 638 |
|
| 639 |
$base_dir = wpcomment_get_dir_path(); |
| 640 |
$file_path = $base_dir . 'confirmed/' . $file_name; |
| 641 |
|
| 642 |
if (file_exists($file_path)) { |
| 643 |
$size = filesize ( $file_path ); |
| 644 |
return round ( $size / 1024, 2 ) . ' KB'; |
| 645 |
}elseif(file_exists( $base_dir . '/' . $file_name ) ){ |
| 646 |
$size = filesize ( $base_dir . '/' . $file_name ); |
| 647 |
return round ( $size / 1024, 2 ) . ' KB'; |
| 648 |
} |
| 649 |
|
| 650 |
} |
| 651 |
|
| 652 |
|
| 653 |
// Generating html for file input and cropper in order meta from filename |
| 654 |
function wpcomment_generate_html_for_files( $file_names, $input_type, $item ) { |
| 655 |
$file_name_array = explode(',', $file_names); |
| 656 |
|
| 657 |
$order_html = '<table>'; |
| 658 |
foreach($file_name_array as $file_name) { |
| 659 |
|
| 660 |
$file_edit_path = wpcomment_get_dir_path('edits').wpcomment_file_get_name($file_name, $item->get_product_id()); |
| 661 |
|
| 662 |
// Making file thumb download with new path |
| 663 |
$wpcomment_file_url = wpcomment_get_file_download_url( $file_name, $item->get_order_id(), $item->get_product_id()); |
| 664 |
$wpcomment_file_thumb_url = wpcomment_is_file_image($file_name) ? wpcomment_get_dir_url(true) . $file_name : WPCOMMENT_URL.'/images/file.png'; |
| 665 |
$order_html .= '<tr><td><a href="'.esc_url($wpcomment_file_url).'">'; |
| 666 |
$order_html .= '<img class="img-thumbnail" style="width:'.esc_attr(wpcomment_get_thumbs_size()).'" src="'.esc_url($wpcomment_file_thumb_url).'">'; |
| 667 |
$order_html .= '</a></td>'; |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
// Requested by Kevin, hiding downloading file button after order on thank you page |
| 672 |
// @since version 16.6 |
| 673 |
if( is_admin() ) { |
| 674 |
$order_html .= '<td><a class="button" href="'.esc_url($wpcomment_file_url).'">'; |
| 675 |
$order_html .= __('Download File', "wpcomment"); |
| 676 |
$order_html .= '</a></td>'; |
| 677 |
} |
| 678 |
$order_html .= '</tr>'; |
| 679 |
|
| 680 |
if( $input_type == 'cropper' ) { |
| 681 |
|
| 682 |
$cropped_file_name = wpcomment_file_get_name($file_name, $item->get_product_id()); |
| 683 |
$cropped_url = wpcomment_get_dir_url() . 'cropped/' . $cropped_file_name; |
| 684 |
$order_html .= '<tr><td><a href="'.esc_url($cropped_url).'">'; |
| 685 |
$order_html .= '<img style="width:'.esc_attr(wpcomment_get_thumbs_size()).'" class="img-thumbnail" src="'.esc_url($cropped_url).'">'; |
| 686 |
$order_html .= '</a></td>'; |
| 687 |
|
| 688 |
// Requested by Kevin, hiding downloading file button after order on thank you page |
| 689 |
// @since version 16.6 |
| 690 |
if( is_admin() ) { |
| 691 |
$order_html .= '<td><a class="button" href="'.esc_url($cropped_url).'">'; |
| 692 |
$order_html .= __('Cropped', "wpcomment"); |
| 693 |
$order_html .= '</a></td>'; |
| 694 |
} |
| 695 |
$order_html .= '</tr>'; |
| 696 |
|
| 697 |
} elseif( file_exists($file_edit_path) ) { |
| 698 |
|
| 699 |
$edit_file_name = wpcomment_file_get_name($file_name, $item->get_product_id()); |
| 700 |
$edit_url = wpcomment_get_dir_url() . 'edits/' . $edit_file_name; |
| 701 |
$edit_thumb_url = wpcomment_get_dir_url() . 'edits/thumbs/' . $file_name; |
| 702 |
$order_html .= '<tr><td><a href="'.esc_url($edit_url).'">'; |
| 703 |
$order_html .= '<img style="width:'.esc_attr(wpcomment_get_thumbs_size()).'" class="img-thumbnail" src="'.esc_url($edit_thumb_url).'">'; |
| 704 |
$order_html .= '</a></td>'; |
| 705 |
$order_html .= '<td><a class="button" href="'.esc_url($edit_url).'">'; |
| 706 |
$order_html .= __('Edited', "wpcomment"); |
| 707 |
$order_html .= '</a></td></tr>'; |
| 708 |
} |
| 709 |
} |
| 710 |
$order_html .= '</table>'; |
| 711 |
|
| 712 |
return apply_filters('wpcomment_order_files_html', $order_html, $file_names, $input_type, $item); |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
// return html for images selected |
| 717 |
function wpcomment_generate_html_for_images( $field_meta, $images ) { |
| 718 |
|
| 719 |
|
| 720 |
$wpcomment_html = '<p class="wpcomment-img-wrapper">'; |
| 721 |
foreach($images as $id => $images_meta) { |
| 722 |
|
| 723 |
$images_meta = json_decode(stripslashes($images_meta), true); |
| 724 |
// wpcomment_pa($images_meta); |
| 725 |
$image_link = stripslashes($images_meta['link']); |
| 726 |
$image_label = isset($images_meta['raw']) ? $images_meta['raw'] : ''; |
| 727 |
$wpcomment_html .= '<a href="'.esc_url($image_link).'" class="wpcomment-image-link" title="'.esc_attr($image_label).'">'; |
| 728 |
$wpcomment_html .= '<img class="wpcomment-thumbnail" style="width:'.esc_attr(wpcomment_get_thumbs_size()).'" src="'.esc_url($image_link).'" title="'.esc_attr($image_label).'">'; |
| 729 |
$wpcomment_html .= '</a>'; |
| 730 |
$wpcomment_html .= '<p class="wpcomment-img-title">'.esc_html($field_meta['title']).'</p>'; |
| 731 |
} |
| 732 |
|
| 733 |
$wpcomment_html .= '</p>'; |
| 734 |
|
| 735 |
return apply_filters('wpcomment_images_html', $wpcomment_html, $images); |
| 736 |
} |
| 737 |
|
| 738 |
// Getting field option price |
| 739 |
function wpcomment_get_field_option_price( $field_meta, $option_label ) { |
| 740 |
|
| 741 |
// var_dump($field_meta['options']); |
| 742 |
if( ! isset( $field_meta['options']) || $field_meta['type'] == 'bulkquantity' || $field_meta['type'] == 'cropper' ) return 0; |
| 743 |
|
| 744 |
$option_price = 0; |
| 745 |
foreach( $field_meta['options'] as $option ) { |
| 746 |
|
| 747 |
if( isset($option['option']) && $option['option'] == $option_label && isset($option['price']) && $option['price'] != '' ) { |
| 748 |
|
| 749 |
$option_price = $option['price']; |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
// For currency switcher |
| 754 |
$option_price = apply_filters('wpcomment_option_price', $option_price); |
| 755 |
|
| 756 |
return apply_filters("wpcomment_field_option_price", wc_format_decimal($option_price), $field_meta, $option_label); |
| 757 |
} |
| 758 |
|
| 759 |
// check if PPOM PRO is installed |
| 760 |
function wpcomment_pro_is_installed() { |
| 761 |
|
| 762 |
$return = false; |
| 763 |
|
| 764 |
if( class_exists('wpcomment_PRO') ) |
| 765 |
$return = true; |
| 766 |
return $return; |
| 767 |
} |
| 768 |
|
| 769 |
// Check if field is visible |
| 770 |
function wpcomment_is_field_visible( $field ) { |
| 771 |
|
| 772 |
if( ! wpcomment_pro_is_installed() ) return true; |
| 773 |
// wpcomment_pa($field); |
| 774 |
|
| 775 |
$visibility = isset($field['visibility']) ? $field['visibility'] : 'everyone'; |
| 776 |
|
| 777 |
$visibility_role = isset($field['visibility_role']) ? $field['visibility_role'] : ''; |
| 778 |
|
| 779 |
$is_visible = false; |
| 780 |
switch( $visibility ) { |
| 781 |
|
| 782 |
case 'everyone': |
| 783 |
$is_visible = true; |
| 784 |
break; |
| 785 |
|
| 786 |
case 'members': |
| 787 |
if( is_user_logged_in() ) { |
| 788 |
$is_visible = true; |
| 789 |
} |
| 790 |
break; |
| 791 |
|
| 792 |
case 'guests': |
| 793 |
if( ! is_user_logged_in() ) { |
| 794 |
$is_visible = true; |
| 795 |
} |
| 796 |
break; |
| 797 |
|
| 798 |
case 'roles': |
| 799 |
$user_roles = wpcomment_get_current_user_role(); |
| 800 |
$allowed_roles = explode(',', $visibility_role); |
| 801 |
|
| 802 |
$restult = array_intersect($allowed_roles, $user_roles); |
| 803 |
if( !empty($restult) ) { |
| 804 |
$is_visible = true; |
| 805 |
} |
| 806 |
break; |
| 807 |
} |
| 808 |
|
| 809 |
return apply_filters('wpcomment_is_field_visible', $is_visible, $field); |
| 810 |
|
| 811 |
} |
| 812 |
|
| 813 |
// Get logged in user role |
| 814 |
function wpcomment_get_current_user_role() { |
| 815 |
|
| 816 |
if( is_user_logged_in() ) { |
| 817 |
$user = wp_get_current_user(); |
| 818 |
return ( array ) $user->roles; |
| 819 |
} else { |
| 820 |
return array(); |
| 821 |
} |
| 822 |
} |
| 823 |
|
| 824 |
function wpcomment_get_date_formats() { |
| 825 |
|
| 826 |
$formats = array ( |
| 827 |
'mm/dd/yy' => 'Default - mm/dd/yyyy', |
| 828 |
'dd/mm/yy' => 'dd/mm/yyyy', |
| 829 |
'yy-mm-dd' => 'ISO 8601 - yy-mm-dd', |
| 830 |
'd M, y' => 'Short - d M, y', |
| 831 |
'd MM, y' => 'Medium - d MM, y', |
| 832 |
'DD, d MM, yy' => 'Full - DD, d MM, yy', |
| 833 |
'\'day\' d \'of\' MM \'in the year\' yy' => 'With text - \'day\' d \'of\' MM \'in the year\' yy', |
| 834 |
'\'Month\' MM \'day\' d \'in the year\' yy' => 'With text - \'Month\' January \'day\' 7 \'in the year\' yy' |
| 835 |
); |
| 836 |
|
| 837 |
return apply_filters('wpcomment_date_formats', $formats); |
| 838 |
} |
| 839 |
|
| 840 |
// PPOM Get settings |
| 841 |
function wpcomment_get_option($key, $default_val=false) { |
| 842 |
|
| 843 |
// $value = wpcomment_SettingsFramework::get_saved_settings($key, $default_val); |
| 844 |
$value = ''; |
| 845 |
return $value; |
| 846 |
} |
| 847 |
|
| 848 |
// Checking PPOM version |
| 849 |
function wpcomment_get_version() { |
| 850 |
|
| 851 |
if( ! defined('WPCOMMENT_VERSION') ) return 3.0; |
| 852 |
return floatval( WPCOMMENT_VERSION ); |
| 853 |
} |
| 854 |
|
| 855 |
// Checking PPOM Pro version |
| 856 |
function wpcomment_get_pro_version() { |
| 857 |
|
| 858 |
if( ! defined('wpcomment_PRO_VERSION') ) return 3.0; |
| 859 |
return floatval( wpcomment_PRO_VERSION ); |
| 860 |
} |
| 861 |
|
| 862 |
// wp_is_mobile wrapper |
| 863 |
function wpcomment_is_mobile() { |
| 864 |
|
| 865 |
if( ! function_exists('wp_is_mobile') ) return false; |
| 866 |
|
| 867 |
return wp_is_mobile(); |
| 868 |
} |
| 869 |
|
| 870 |
// check client side validation |
| 871 |
function wpcomment_is_client_validation_enabled() { |
| 872 |
|
| 873 |
$validation = false; |
| 874 |
if( WPCOMMENT_ADMIN::get_option('wpcomment_validation', 'yes') == 'yes' ) $validation = true; |
| 875 |
|
| 876 |
return apply_filters('wpcomment_is_client_validation_enabled', $validation); |
| 877 |
} |
| 878 |
|
| 879 |
// generating wpcomment conditional data attributes |
| 880 |
function wpcomment_get_conditional_data_attributes( $meta ) { |
| 881 |
|
| 882 |
$logic = isset($meta['logic']) ? wpcomment_wpml_translate($meta['logic'], 'WPCOMMENT') : ''; |
| 883 |
$conditions = isset($meta['conditions']) ? wpcomment_wpml_translate($meta['conditions'], 'WPCOMMENT') : ''; |
| 884 |
$type = isset($meta['type']) ? wpcomment_wpml_translate($meta['type'], 'WPCOMMENT') : ''; |
| 885 |
|
| 886 |
$attr_html = ''; |
| 887 |
|
| 888 |
$attr_html .= ' data-type="'.esc_attr($type).'"'; |
| 889 |
// wpcomment_pa($conditions); |
| 890 |
|
| 891 |
|
| 892 |
if( isset($conditions['rules']) && $logic === 'on' ) { |
| 893 |
|
| 894 |
$bound = isset($conditions['bound']) ? wpcomment_wpml_translate($conditions['bound'], 'WPCOMMENT') : ''; |
| 895 |
$visibility = isset($conditions['visibility']) ? wpcomment_wpml_translate($conditions['visibility'], 'WPCOMMENT') : ''; |
| 896 |
|
| 897 |
$attr_html .= ' data-cond="1"'; |
| 898 |
$attr_html .= ' data-cond-total="'.esc_attr(count($conditions['rules'])).'"'; |
| 899 |
$attr_html .= ' data-cond-bind="'.esc_attr($bound).'"'; |
| 900 |
$attr_html .= ' data-cond-visibility="'.esc_attr(strtolower($visibility)).'"'; |
| 901 |
|
| 902 |
$index = 0; |
| 903 |
foreach($conditions['rules'] as $rule){ |
| 904 |
|
| 905 |
$counter = ++$index; |
| 906 |
$input = "input".$counter; |
| 907 |
$value = "val".$counter; |
| 908 |
$opr = "operator".$counter; |
| 909 |
$element = isset($rule['elements']) ? wpcomment_wpml_translate($rule['elements'], 'WPCOMMENT') : ''; |
| 910 |
$element_val= isset($rule['element_values']) ? wpcomment_wpml_translate($rule['element_values'], 'WPCOMMENT') : ''; |
| 911 |
$operator = isset($rule['operators']) ? wpcomment_wpml_translate($rule['operators'], 'WPCOMMENT') : ''; |
| 912 |
$attr_html .= ' data-cond-'.$input.'="'.esc_attr($element).'"'; |
| 913 |
$attr_html .= ' data-cond-'.$value.'="'.esc_attr($element_val).'"'; |
| 914 |
$attr_html .= ' data-cond-'.$opr.'="'.esc_attr($operator).'"'; |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
return apply_filters('wpcomment_field_conditions', $attr_html, $meta); |
| 919 |
} |
| 920 |
|
| 921 |
// Check if given type is an addon |
| 922 |
function wpcomment_is_field_addon($type){ |
| 923 |
|
| 924 |
$wpcomment_meta = wpcomment_get_plugin_meta(); |
| 925 |
|
| 926 |
$is_addon = false; |
| 927 |
if( isset($wpcomment_meta[$type]) && $wpcomment_meta[$type]['is_addon']) $is_addon = true; |
| 928 |
|
| 929 |
return $is_addon; |
| 930 |
} |
| 931 |
|
| 932 |
function wpcomment_is_legacy_mode(){ |
| 933 |
|
| 934 |
$is_legacy = false; |
| 935 |
$enable_legacy = wpcomment_get_option('wpcomment_enable_legacy_inputs_rendering'); |
| 936 |
if ($enable_legacy == 'yes') { |
| 937 |
$is_legacy = true; |
| 938 |
} |
| 939 |
|
| 940 |
return $is_legacy; |
| 941 |
} |
| 942 |
|
| 943 |
/** |
| 944 |
* Return cols for inputs |
| 945 |
*/ |
| 946 |
function wpcomment_get_input_cols() { |
| 947 |
|
| 948 |
$ppom_cols = array( |
| 949 |
2 => '2 Col', |
| 950 |
3 => '3 Col', |
| 951 |
4 => '4 Col', |
| 952 |
5 => '5 Col', |
| 953 |
6 => '6 Col', |
| 954 |
7 => '7 Col', |
| 955 |
8 => '8 Col', |
| 956 |
9 => '9 Col', |
| 957 |
10 => '10 Col', |
| 958 |
11 => '11 Col', |
| 959 |
12 => '12 Col' |
| 960 |
); |
| 961 |
|
| 962 |
return apply_filters('ppom_field_cols', $ppom_cols); |
| 963 |
} |
| 964 |
|
| 965 |
/** |
| 966 |
* Return visibility options for inputs |
| 967 |
*/ |
| 968 |
function wpcomment_field_visibility_options() { |
| 969 |
|
| 970 |
$visibility_options = array( |
| 971 |
'everyone' => __('Everyone'), |
| 972 |
'guests' => __('Only Guests'), |
| 973 |
'members' => __('Only Members'), |
| 974 |
'roles' => __('By Role') |
| 975 |
); |
| 976 |
|
| 977 |
return apply_filters('ppom_field_visibility_options', $visibility_options); |
| 978 |
} |
| 979 |
|
| 980 |
/** |
| 981 |
* Get timezone list |
| 982 |
*/ |
| 983 |
function wpcomment_array_get_timezone_list($selected_regions, $show_time) { |
| 984 |
|
| 985 |
if( $selected_regions == 'All' ) { |
| 986 |
$regions = array( |
| 987 |
DateTimeZone::AFRICA, |
| 988 |
DateTimeZone::AMERICA, |
| 989 |
DateTimeZone::ANTARCTICA, |
| 990 |
DateTimeZone::ASIA, |
| 991 |
DateTimeZone::ATLANTIC, |
| 992 |
DateTimeZone::AUSTRALIA, |
| 993 |
DateTimeZone::EUROPE, |
| 994 |
DateTimeZone::INDIAN, |
| 995 |
DateTimeZone::PACIFIC, |
| 996 |
); |
| 997 |
} else { |
| 998 |
$selected_regions = explode(",", $selected_regions); |
| 999 |
$tz_regions = array(); |
| 1000 |
|
| 1001 |
foreach($selected_regions as $region) { |
| 1002 |
|
| 1003 |
switch($region) { |
| 1004 |
case 'AFRICA': |
| 1005 |
$tz_regions[] = DateTimeZone::AFRICA; |
| 1006 |
break; |
| 1007 |
case 'AMERICA': |
| 1008 |
$tz_regions[] = DateTimeZone::AMERICA; |
| 1009 |
break; |
| 1010 |
case 'ANTARCTICA': |
| 1011 |
$tz_regions[] = DateTimeZone::ANTARCTICA; |
| 1012 |
break; |
| 1013 |
case 'ASIA': |
| 1014 |
$tz_regions[] = DateTimeZone::ASIA; |
| 1015 |
break; |
| 1016 |
case 'ATLANTIC': |
| 1017 |
$tz_regions[] = DateTimeZone::ATLANTIC; |
| 1018 |
break; |
| 1019 |
case 'AUSTRALIA': |
| 1020 |
$tz_regions[] = DateTimeZone::AUSTRALIA; |
| 1021 |
break; |
| 1022 |
case 'EUROPE': |
| 1023 |
$tz_regions[] = DateTimeZone::EUROPE; |
| 1024 |
break; |
| 1025 |
case 'INDIAN': |
| 1026 |
$tz_regions[] = DateTimeZone::INDIAN; |
| 1027 |
break; |
| 1028 |
case 'PACIFIC': |
| 1029 |
$tz_regions[] = DateTimeZone::PACIFIC; |
| 1030 |
break; |
| 1031 |
} |
| 1032 |
} |
| 1033 |
$regions = $tz_regions; |
| 1034 |
} |
| 1035 |
|
| 1036 |
$timezones = array(); |
| 1037 |
foreach( $regions as $region ) { |
| 1038 |
$timezones = array_merge( $timezones, DateTimeZone::listIdentifiers( $region ) ); |
| 1039 |
} |
| 1040 |
|
| 1041 |
$timezone_offsets = array(); |
| 1042 |
foreach( $timezones as $timezone ) { |
| 1043 |
$tz = new DateTimeZone($timezone); |
| 1044 |
$timezone_offsets[$timezone] = $tz->getOffset(new DateTime); |
| 1045 |
} |
| 1046 |
|
| 1047 |
// sort timezone by timezone name |
| 1048 |
ksort($timezone_offsets); |
| 1049 |
|
| 1050 |
$timezone_list = array(); |
| 1051 |
foreach( $timezone_offsets as $timezone => $offset ) { |
| 1052 |
$offset_prefix = $offset < 0 ? '-' : '+'; |
| 1053 |
$offset_formatted = gmdate( 'H:i', abs($offset) ); |
| 1054 |
|
| 1055 |
$pretty_offset = "UTC${offset_prefix}${offset_formatted}"; |
| 1056 |
|
| 1057 |
$t = new DateTimeZone($timezone); |
| 1058 |
$c = new DateTime(null, $t); |
| 1059 |
$current_time = $c->format('g:i A'); |
| 1060 |
|
| 1061 |
if( $show_time == 'on' ) { |
| 1062 |
$timezone_list[$timezone] = "(${pretty_offset}) $timezone - $current_time"; |
| 1063 |
} else { |
| 1064 |
$timezone_list[$timezone] = "(${pretty_offset}) $timezone"; |
| 1065 |
} |
| 1066 |
} |
| 1067 |
|
| 1068 |
return $timezone_list; |
| 1069 |
} |
| 1070 |
|
| 1071 |
function wpcomment_get_saved_meta() { |
| 1072 |
$wpcomment_meta = get_option('wpcomment_meta_fields'); |
| 1073 |
|
| 1074 |
// legacy meta |
| 1075 |
if (!$wpcomment_meta) { |
| 1076 |
$wpcomment_meta = wpcomment_get_saved_meta_legacy(); |
| 1077 |
if (!$wpcomment_meta) { |
| 1078 |
$wpcomment_meta = []; |
| 1079 |
} |
| 1080 |
} else { |
| 1081 |
$wpcomment_meta = json_decode($wpcomment_meta, true); |
| 1082 |
|
| 1083 |
// Check if the decoded value is an array |
| 1084 |
if (!is_array($wpcomment_meta)) { |
| 1085 |
$wpcomment_meta = []; |
| 1086 |
} |
| 1087 |
} |
| 1088 |
|
| 1089 |
return $wpcomment_meta; |
| 1090 |
} |
| 1091 |
|
| 1092 |
// get and convert legacy comment meta fields |
| 1093 |
function wpcomment_get_saved_meta_legacy(){ |
| 1094 |
|
| 1095 |
$wpcomment_meta = get_option('wpcomment_meta'); |
| 1096 |
|
| 1097 |
if( !$wpcomment_meta ) return null; |
| 1098 |
|
| 1099 |
// adding status key |
| 1100 |
$wpcomment_meta = array_map(function($c){ |
| 1101 |
$m = $c; |
| 1102 |
$m['status'] = 'on'; |
| 1103 |
if(isset($m['options'])){ |
| 1104 |
$options = explode("\n", $m['options']); |
| 1105 |
// wpcomment_pa($options); |
| 1106 |
$options = array_map(function($opt){ |
| 1107 |
$o['option'] = $opt; |
| 1108 |
$o['id'] = sanitize_key($opt); |
| 1109 |
return $o; |
| 1110 |
}, $options); |
| 1111 |
$m['options'] = $options; |
| 1112 |
// $m['options'] = wpcomment_convert_options_to_key_val($options, $wpcomment_meta); |
| 1113 |
} |
| 1114 |
return $m; |
| 1115 |
}, $wpcomment_meta); |
| 1116 |
|
| 1117 |
return $wpcomment_meta; |
| 1118 |
} |
| 1119 |
|
| 1120 |
/** |
| 1121 |
* just rendering a thumb box |
| 1122 |
* |
| 1123 |
**/ |
| 1124 |
function wpcomment_render_images_legacy($image_name) { |
| 1125 |
|
| 1126 |
$is_thumb = true; |
| 1127 |
$legacy = true; |
| 1128 |
$thumb_url = wpcomment_get_dir_url($is_thumb,$legacy) . $image_name; |
| 1129 |
$file_url = wpcomment_get_dir_url() . $image_name; |
| 1130 |
|
| 1131 |
return apply_filters('wpcomment_imagethumb', sprintf(__('<a href="%s"><img width="75" src="%s" title="%s" /></a>', 'nm-wpcomments'), $file_url, $thumb_url, $image_name), $image_name); |
| 1132 |
} |
| 1133 |
|
| 1134 |
/** |
| 1135 |
* just renderin file name with link |
| 1136 |
**/ |
| 1137 |
function wpcomment_file_link_legacy($file_name) { |
| 1138 |
|
| 1139 |
$is_thumb = false; |
| 1140 |
$legacy = true; |
| 1141 |
$file_url = wpcomment_get_dir_url($is_thumb,$legacy) . $file_name; |
| 1142 |
return apply_filters('wpcomment_filelink', sprintf(__('<a href="%s"><img width="75" src="%s" title="%s" /></a>', 'nm-wpcomments'), $file_url,$thumb_url, $file_name), $file_name, $thumb_url); |
| 1143 |
} |
| 1144 |
|
| 1145 |
// show wpcomment meta fields for given meta against comment |
| 1146 |
function wpcomment_render_comment_meta($comment_meta){ |
| 1147 |
|
| 1148 |
$output = wpcomment_output_meta($comment_meta['fields']); |
| 1149 |
// wpcomment_pa($output); |
| 1150 |
|
| 1151 |
$comment = '<ul class="wpcomment-ul">'; |
| 1152 |
foreach ( $output as $o ) { |
| 1153 |
|
| 1154 |
$display = isset($o['display']) ? $o['display'] : $o['value']; |
| 1155 |
$type = isset($o['type']) ? $o['type'] : ''; |
| 1156 |
|
| 1157 |
|
| 1158 |
// if meta type is image remove the title |
| 1159 |
if( ! in_array($type, ['image','file']) ){ |
| 1160 |
$comment .= '<li class="wpcomment-li"><strong>' . esc_attr($o['name']) . '</strong> - '; |
| 1161 |
$comment .= wp_kses_post( $display ) . '</li>'; |
| 1162 |
} else{ |
| 1163 |
$comment .= '<li class="wpcomment-li"> ' . wp_kses_post( $display ) . '</li>'; |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
$comment .= '</ul>'; |
| 1168 |
|
| 1169 |
return $comment; |
| 1170 |
} |
| 1171 |
|
| 1172 |
function wpcomment_disable_extra_fields(){ |
| 1173 |
$disable_extrafields = WPCOMMENT_ADMIN()::get_option('wpcomment_disable_frontend'); |
| 1174 |
$disable_extrafields = $disable_extrafields === 'on' ? true : false; |
| 1175 |
return apply_filters('wpcomment_show_extra_fields', $disable_extrafields); |
| 1176 |
} |