| @@ -7,9 +7,9 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace Smackcoders\SMUSERS; |
| 9 | 9 | |
| 10 | 10 | if ( ! defined( 'ABSPATH' ) ) |
| 11 | -exit; // Exit if accessed directly | |
| 11 | + exit; // Exit if accessed directly | |
| 12 | 12 | |
| 13 | 13 | class MediaHandling{ |
| 14 | 14 | private static $instance=null; |
| 15 | 15 | public $header_array; |
| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | public $header_array; |
| 16 | 16 | public $value_array; |
| 17 | 17 | |
| 18 | 18 | public function __construct(){ |
| 19 | - | |
| 19 | + | |
| 20 | 20 | require_once(ABSPATH.'wp-load.php'); |
| 21 | 21 | require_once(ABSPATH . 'wp-admin/includes/image.php'); |
| 22 | 22 | require_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 23 | 23 | add_action('wp_ajax_image_options', array($this , 'imageOptions')); |
| @@ -42,10 +42,10 @@ | ||
| 42 | 42 | $media_settings['custom_slug'] = sanitize_text_field($_POST['custom_slug']); |
| 43 | 43 | $media_settings['custom_slug'] = sanitize_text_field($_POST['custom_width']); |
| 44 | 44 | $media_settings['custom_height'] = sanitize_text_field($_POST['custom_height']); |
| 45 | 45 | $image_info = array( |
| 46 | - 'media_settings' => $media_settings | |
| 47 | - ); | |
| 46 | + 'media_settings' => $media_settings | |
| 47 | + ); | |
| 48 | 48 | update_option( 'smack_image_options', $image_info ); |
| 49 | 49 | $result['success'] = 'true'; |
| 50 | 50 | echo wp_json_encode($result); |
| 51 | 51 | wp_die(); |
| @@ -138,9 +138,9 @@ | ||
| 138 | 138 | return $attach_id; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | public function image_function($f_img , $post_id , $data_array = null,$option_name = null, $use_existing_image = false,$header_array = null , $value_array = null){ |
| 142 | - | |
| 142 | + | |
| 143 | 143 | global $wpdb; |
| 144 | 144 | $media_handle = get_option('smack_image_options'); |
| 145 | 145 | $media_settings = array_combine($header_array,$value_array); |
| 146 | 146 | if(isset($media_handle['media_settings']['alttext'])) { |
| @@ -240,14 +240,14 @@ | ||
| 240 | 240 | if(empty($file_type['type'])){ |
| 241 | 241 | $file_type['type'] = 'image/jpeg'; |
| 242 | 242 | } |
| 243 | 243 | $post_info = array( |
| 244 | - 'guid' => $uploaddir_url . "/" . $fimg_name, | |
| 245 | - 'post_mime_type' => $file_type['type'], | |
| 246 | - 'post_title' => $attachment_title, | |
| 247 | - 'post_content' => '', | |
| 248 | - 'post_status' => 'inherit', | |
| 249 | - ); | |
| 244 | + 'guid' => $uploaddir_url . "/" . $fimg_name, | |
| 245 | + 'post_mime_type' => $file_type['type'], | |
| 246 | + 'post_title' => $attachment_title, | |
| 247 | + 'post_content' => '', | |
| 248 | + 'post_status' => 'inherit', | |
| 249 | + ); | |
| 250 | 250 | //unset( $post_info['ID'] ); |
| 251 | 251 | $attach_id = wp_insert_attachment( $post_info,$uploaddir_path, $post_id ); |
| 252 | 252 | $attach_data = wp_generate_attachment_metadata( $attach_id, $uploaddir_path ); |
| 253 | 253 | wp_update_attachment_metadata( $attach_id, $attach_data ); |
| @@ -294,18 +294,18 @@ | ||
| 294 | 294 | $media_handle['media_settings']['title'] = $media_settings[$media_handle['media_settings']['title']]; |
| 295 | 295 | } |
| 296 | 296 | if(isset($media_handle['media_settings']['caption']) || isset($media_handle['media_settings']['description'])){ |
| 297 | 297 | wp_update_post(array( |
| 298 | - 'ID' =>$attach_id, | |
| 299 | - 'post_content' =>$media_handle['media_settings']['description'], | |
| 300 | - 'post_excerpt' =>$media_handle['media_settings']['caption'] | |
| 301 | - )); | |
| 298 | + 'ID' =>$attach_id, | |
| 299 | + 'post_content' =>$media_handle['media_settings']['description'], | |
| 300 | + 'post_excerpt' =>$media_handle['media_settings']['caption'] | |
| 301 | + )); | |
| 302 | 302 | } |
| 303 | 303 | if(isset($media_handle['media_settings']['title'])){ |
| 304 | 304 | wp_update_post(array( |
| 305 | - 'ID' =>$attach_id, | |
| 306 | - 'post_title' =>$media_handle['media_settings']['title'] | |
| 307 | - )); | |
| 305 | + 'ID' =>$attach_id, | |
| 306 | + 'post_title' =>$media_handle['media_settings']['title'] | |
| 307 | + )); | |
| 308 | 308 | } |
| 309 | 309 | if($attach_id != null && isset($alttext['_wp_attachment_image_alt'])){ |
| 310 | 310 | update_post_meta($attach_id, '_wp_attachment_image_alt', $alttext['_wp_attachment_image_alt']); |
| 311 | 311 | } |
| @@ -363,40 +363,40 @@ | ||
| 363 | 363 | $dom_obj->loadHTML($page_content); |
| 364 | 364 | $meta_val = null; |
| 365 | 365 | foreach($dom_obj->getElementsByTagName('meta') as $meta) { |
| 366 | 366 | if($meta->getAttribute('property')=='og:image'){ |
| 367 | - $meta_val = $meta->getAttribute('content'); | |
| 367 | + $meta_val = $meta->getAttribute('content'); | |
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | - | |
| 370 | + | |
| 371 | 371 | $response = wp_remote_get($meta_val); |
| 372 | 372 | $rawdata = wp_remote_retrieve_body($response); |
| 373 | 373 | } |
| 374 | 374 | //Removed curl and added wordpress http api |
| 375 | 375 | else{ |
| 376 | - if($file_type['ext'] == 'jpeg'){ | |
| 377 | - $response = wp_remote_get($f_img, array( 'timeout' => 30)); | |
| 378 | - }else{ | |
| 379 | - $response = wp_remote_get($f_img, array( 'timeout' => 10)); | |
| 376 | + if($file_type['ext'] == 'jpeg'){ | |
| 377 | + $response = wp_remote_get($f_img, array( 'timeout' => 30)); | |
| 378 | + }else{ | |
| 379 | + $response = wp_remote_get($f_img, array( 'timeout' => 10)); | |
| 380 | + } | |
| 381 | + $rawdata = wp_remote_retrieve_body($response); | |
| 380 | 382 | } |
| 381 | - $rawdata = wp_remote_retrieve_body($response); | |
| 382 | - } | |
| 383 | 383 | $http_code = wp_remote_retrieve_response_code($response); |
| 384 | - | |
| 384 | + | |
| 385 | 385 | if($http_code == 404){ |
| 386 | 386 | return null; |
| 387 | 387 | } |
| 388 | - | |
| 388 | + | |
| 389 | 389 | // When |
| 390 | 390 | if ( $http_code != 200 && strpos( $rawdata, 'Not Found' ) != 0 ) { |
| 391 | 391 | return null; |
| 392 | 392 | } |
| 393 | - | |
| 393 | + | |
| 394 | 394 | if ($rawdata == false) { |
| 395 | - | |
| 395 | + | |
| 396 | 396 | return null; |
| 397 | 397 | } else { |
| 398 | - | |
| 398 | + | |
| 399 | 399 | if (file_exists($uploaddir_path)) { |
| 400 | 400 | $i = 1; |
| 401 | 401 | $exist = true; |
| 402 | 402 | while($exist){ |
| @@ -419,24 +419,24 @@ | ||
| 419 | 419 | $file_type['type'] = 'image/jpeg'; |
| 420 | 420 | } |
| 421 | 421 | //Removed curl and added wordpress http api |
| 422 | 422 | $post_info = array( |
| 423 | - 'guid' => $uploaddir_url . "/" . $fimg_name, | |
| 424 | - 'post_mime_type' => $file_type['type'], | |
| 425 | - 'post_title' => $attachment_title, | |
| 426 | - 'post_content' => '', | |
| 427 | - 'post_status' => 'inherit', | |
| 428 | - ); | |
| 423 | + 'guid' => $uploaddir_url . "/" . $fimg_name, | |
| 424 | + 'post_mime_type' => $file_type['type'], | |
| 425 | + 'post_title' => $attachment_title, | |
| 426 | + 'post_content' => '', | |
| 427 | + 'post_status' => 'inherit', | |
| 428 | + ); | |
| 429 | 429 | unset( $post_info['ID'] ); |
| 430 | 430 | $attach_id = wp_insert_attachment( $post_info,$uploaddir_path ); |
| 431 | 431 | $attach_data = wp_generate_attachment_metadata( $attach_id, $uploaddir_path ); |
| 432 | 432 | wp_update_attachment_metadata( $attach_id, $attach_data ); |
| 433 | 433 | wp_update_post(array( |
| 434 | - 'ID' => $attach_id, | |
| 435 | - 'post_title' => $data_array['title'], | |
| 436 | - 'post_content' => $data_array['description'], | |
| 437 | - 'post_excerpt' => $data_array['caption'] | |
| 438 | - )); | |
| 434 | + 'ID' => $attach_id, | |
| 435 | + 'post_title' => $data_array['title'], | |
| 436 | + 'post_content' => $data_array['description'], | |
| 437 | + 'post_excerpt' => $data_array['caption'] | |
| 438 | + )); | |
| 439 | 439 | if($attach_id != null && isset($alttext['_wp_attachment_image_alt'])){ |
| 440 | 440 | update_post_meta($attach_id, '_wp_attachment_image_alt', $alttext['_wp_attachment_image_alt']); |
| 441 | 441 | } |
| 442 | 442 | return $attach_id; |
| @@ -454,9 +454,8 @@ | ||
| 454 | 454 | $current_filename = substr($current_filename, (strrpos($current_filename, "/") + 1)); |
| 455 | 455 | |
| 456 | 456 | $ID = $post_id; |
| 457 | 457 | |
| 458 | - //$current_file = get_attached_file($ID, apply_filters( 'emr_unfiltered_get_attached_file', true )); | |
| 459 | 458 | $current_file = get_attached_file($ID); |
| 460 | 459 | $current_path = substr($current_file, 0, (strrpos($current_file, "/"))); |
| 461 | 460 | $current_file = preg_replace("|(?<!:)/{2,}|", "/", $current_file); |
| 462 | 461 | $current_filename = basename($current_file); |
| @@ -461,9 +460,8 @@ | ||
| 461 | 460 | $current_file = preg_replace("|(?<!:)/{2,}|", "/", $current_file); |
| 462 | 461 | $current_filename = basename($current_file); |
| 463 | 462 | $current_metadata = wp_get_attachment_metadata( $post_id ); |
| 464 | 463 | |
| 465 | - // $original_file_perms = fileperms($current_file) & 0777; | |
| 466 | 464 | |
| 467 | 465 | $data = file_get_contents($img_url); |
| 468 | 466 | |
| 469 | 467 | $new_filename = basename($img_url); |
| @@ -493,18 +491,18 @@ | ||
| 493 | 491 | |
| 494 | 492 | $post_date = gmdate( 'Y-m-d H:i:s' ); |
| 495 | 493 | |
| 496 | 494 | $sql = $wpdb->prepare( |
| 497 | - "UPDATE {$wpdb->prefix}posts SET post_title = '$new_filetitle', post_name = '$new_filetitle', guid = '$new_guid', post_mime_type = '$new_filetype', post_date = '$post_date', post_date_gmt = '$post_date' WHERE ID = %d;", | |
| 498 | - $post_id | |
| 499 | - ); | |
| 495 | + "UPDATE {$wpdb->prefix}posts SET post_title = '$new_filetitle', post_name = '$new_filetitle', guid = '$new_guid', post_mime_type = '$new_filetype', post_date = '$post_date', post_date_gmt = '$post_date' WHERE ID = %d;", | |
| 496 | + $post_id | |
| 497 | + ); | |
| 500 | 498 | $wpdb->query($sql); |
| 501 | 499 | |
| 502 | 500 | |
| 503 | 501 | $sql = $wpdb->prepare( |
| 504 | - "SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key = '_wp_attached_file' AND post_id = %d;", | |
| 505 | - $post_id | |
| 506 | - ); | |
| 502 | + "SELECT meta_value FROM {$wpdb->prefix}postmeta WHERE meta_key = '_wp_attached_file' AND post_id = %d;", | |
| 503 | + $post_id | |
| 504 | + ); | |
| 507 | 505 | |
| 508 | 506 | $old_meta_name = $wpdb->get_row($sql, ARRAY_A); |
| 509 | 507 | $old_meta_name = $old_meta_name["meta_value"]; |
| 510 | 508 | |
| @@ -510,11 +508,11 @@ | ||
| 510 | 508 | |
| 511 | 509 | // Make new postmeta _wp_attached_file |
| 512 | 510 | $new_meta_name = str_replace($current_filename, $new_filename, $old_meta_name); |
| 513 | 511 | $sql = $wpdb->prepare( |
| 514 | - "UPDATE {$wpdb->prefix}postmeta SET meta_value = '$new_meta_name' WHERE meta_key = '_wp_attached_file' AND post_id = %d;", | |
| 515 | - $post_id | |
| 516 | - ); | |
| 512 | + "UPDATE {$wpdb->prefix}postmeta SET meta_value = '$new_meta_name' WHERE meta_key = '_wp_attached_file' AND post_id = %d;", | |
| 513 | + $post_id | |
| 514 | + ); | |
| 517 | 515 | $wpdb->query($sql); |
| 518 | 516 | |
| 519 | 517 | $new_metadata = wp_generate_attachment_metadata( $post_id, $new_file ); |
| 520 | 518 | wp_update_attachment_metadata( $post_id, $new_metadata ); |
| @@ -523,11 +521,11 @@ | ||
| 523 | 521 | |
| 524 | 522 | $current_base_url = $this->emr_get_match_url( $current_guid ); // .wp-contet.uplodas/ dae name without ext |
| 525 | 523 | |
| 526 | 524 | $sql = $wpdb->prepare( |
| 527 | - "SELECT ID, post_content FROM {$wpdb->prefix}posts WHERE post_status = 'publish' AND post_content LIKE %s;", | |
| 528 | - '%' . $current_base_url . '%' | |
| 529 | - ); | |
| 525 | + "SELECT ID, post_content FROM {$wpdb->prefix}posts WHERE post_status = 'publish' AND post_content LIKE %s;", | |
| 526 | + '%' . $current_base_url . '%' | |
| 527 | + ); | |
| 530 | 528 | |
| 531 | 529 | |
| 532 | 530 | $rs = $wpdb->get_results( $sql, ARRAY_A ); |
| 533 | 531 | |
| @@ -548,11 +546,11 @@ | ||
| 548 | 546 | |
| 549 | 547 | $post_content = addslashes( str_replace( $search_urls, $replace_urls, $post_content ) ); |
| 550 | 548 | |
| 551 | 549 | $sql = $wpdb->prepare( |
| 552 | - "UPDATE {$wpdb->prefix}posts SET post_content = '$post_content' WHERE ID = %d;", | |
| 553 | - $rows["ID"] | |
| 554 | - ); | |
| 550 | + "UPDATE {$wpdb->prefix}posts SET post_content = '$post_content' WHERE ID = %d;", | |
| 551 | + $rows["ID"] | |
| 552 | + ); | |
| 555 | 553 | |
| 556 | 554 | $wpdb->query( $sql ); |
| 557 | 555 | } |
| 558 | 556 | } |