| @@ 638-671 (lines=34) @@ | ||
| 635 | ||
| 636 | // get an image file from the doc content if no file attached. |
|
| 637 | $is_tmp_file = false; |
|
| 638 | if(!$source_file) |
|
| 639 | { |
|
| 640 | $random = new Password(); |
|
| 641 | ||
| 642 | preg_match_all("!<img[^>]*src=(?:\"|\')([^\"\']*?)(?:\"|\')!is", $content, $matches, PREG_SET_ORDER); |
|
| 643 | ||
| 644 | foreach($matches as $target_image) |
|
| 645 | { |
|
| 646 | $target_src = trim($target_image[1]); |
|
| 647 | if(preg_match('/\/(common|modules|widgets|addons|layouts|m\.layouts)\//i', $target_src)) continue; |
|
| 648 | ||
| 649 | if(!preg_match('/^(http|https):\/\//i',$target_src)) |
|
| 650 | { |
|
| 651 | $target_src = Context::getRequestUri().$target_src; |
|
| 652 | } |
|
| 653 | ||
| 654 | $target_src = htmlspecialchars_decode($target_src); |
|
| 655 | ||
| 656 | $tmp_file = _XE_PATH_ . 'files/cache/tmp/' . $random->createSecureSalt(32, 'hex'); |
|
| 657 | FileHandler::getRemoteFile($target_src, $tmp_file); |
|
| 658 | if(!file_exists($tmp_file)) continue; |
|
| 659 | ||
| 660 | $imageinfo = getimagesize($tmp_file); |
|
| 661 | list($_w, $_h) = $imageinfo; |
|
| 662 | if($imageinfo === false || ($_w < ($width * 0.3) && $_h < ($height * 0.3))) { |
|
| 663 | FileHandler::removeFile($tmp_file); |
|
| 664 | continue; |
|
| 665 | } |
|
| 666 | ||
| 667 | $source_file = $tmp_file; |
|
| 668 | $is_tmp_file = true; |
|
| 669 | break; |
|
| 670 | } |
|
| 671 | } |
|
| 672 | ||
| 673 | $output = FileHandler::createImageFile($source_file, $thumbnail_file, $width, $height, 'jpg', $thumbnail_type); |
|
| 674 | ||
| @@ 887-920 (lines=34) @@ | ||
| 884 | } |
|
| 885 | // If not exists, file an image file from the content |
|
| 886 | $is_tmp_file = false; |
|
| 887 | if(!$source_file) |
|
| 888 | { |
|
| 889 | $random = new Password(); |
|
| 890 | ||
| 891 | preg_match_all("!<img[^>]*src=(?:\"|\')([^\"\']*?)(?:\"|\')!is", $content, $matches, PREG_SET_ORDER); |
|
| 892 | ||
| 893 | foreach($matches as $target_image) |
|
| 894 | { |
|
| 895 | $target_src = trim($target_image[1]); |
|
| 896 | if(preg_match('/\/(common|modules|widgets|addons|layouts|m\.layouts)\//i', $target_src)) continue; |
|
| 897 | ||
| 898 | if(!preg_match('/^(http|https):\/\//i',$target_src)) |
|
| 899 | { |
|
| 900 | $target_src = Context::getRequestUri().$target_src; |
|
| 901 | } |
|
| 902 | ||
| 903 | $target_src = htmlspecialchars_decode($target_src); |
|
| 904 | ||
| 905 | $tmp_file = _XE_PATH_ . 'files/cache/tmp/' . $random->createSecureSalt(32, 'hex'); |
|
| 906 | FileHandler::getRemoteFile($target_src, $tmp_file); |
|
| 907 | if(!file_exists($tmp_file)) continue; |
|
| 908 | ||
| 909 | $imageinfo = getimagesize($tmp_file); |
|
| 910 | list($_w, $_h) = $imageinfo; |
|
| 911 | if($imageinfo === false || ($_w < ($width * 0.3) && $_h < ($height * 0.3))) { |
|
| 912 | FileHandler::removeFile($tmp_file); |
|
| 913 | continue; |
|
| 914 | } |
|
| 915 | ||
| 916 | $source_file = $tmp_file; |
|
| 917 | $is_tmp_file = true; |
|
| 918 | break; |
|
| 919 | } |
|
| 920 | } |
|
| 921 | ||
| 922 | if($source_file) |
|
| 923 | { |
|