Version Description
Download this release
Release Info
Developer | qqworld |
Plugin | QQWorld Auto Save Images |
Version | 1.6 |
Comparing to | |
See all releases |
Code changes from version 1.5.9.1 to 1.6
- qqworld-auto-save-images.php +57 -5
qqworld-auto-save-images.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: QQWorld Auto Save Images
|
4 |
Plugin URI: https://wordpress.org/plugins/qqworld-auto-save-images/
|
5 |
Description: Automatically keep the all remote picture to the local, and automatically set featured image.
|
6 |
-
Version: 1.
|
7 |
Author: Michael Wang
|
8 |
Author URI: http://www.qqworld.org
|
9 |
Text Domain: qqworld_auto_save_images
|
@@ -14,7 +14,7 @@ define('QQWORLD_AUTO_SAVE_IMAGES_URL', plugin_dir_url(__FILE__));
|
|
14 |
class QQWorld_auto_save_images {
|
15 |
var $using_action;
|
16 |
var $type;
|
17 |
-
var $preg = '/<img.*?src=[\"\']((?![\"\'])
|
18 |
var $exclude_domain;
|
19 |
function __construct() {
|
20 |
$this->using_action = get_option('using_action', 'publish');
|
@@ -568,15 +568,67 @@ class QQWorld_auto_save_images {
|
|
568 |
set_time_limit(0);
|
569 |
if ( $file=@file_get_contents($image_url) ) {
|
570 |
$filename=basename($image_url);
|
571 |
-
preg_match( '/(.*?)(
|
572 |
-
|
573 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
574 |
$attach_id = $this->insert_attachment($res['file'],$post_id);
|
575 |
if( !has_post_thumbnail($post_id) && $this->featured_image=='yes' ) set_post_thumbnail( $post_id, $attach_id );
|
576 |
return $res;
|
577 |
}
|
578 |
return false;
|
579 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
580 |
|
581 |
//insert attachment
|
582 |
function insert_attachment($file,$id){
|
3 |
Plugin Name: QQWorld Auto Save Images
|
4 |
Plugin URI: https://wordpress.org/plugins/qqworld-auto-save-images/
|
5 |
Description: Automatically keep the all remote picture to the local, and automatically set featured image.
|
6 |
+
Version: 1.6
|
7 |
Author: Michael Wang
|
8 |
Author URI: http://www.qqworld.org
|
9 |
Text Domain: qqworld_auto_save_images
|
14 |
class QQWorld_auto_save_images {
|
15 |
var $using_action;
|
16 |
var $type;
|
17 |
+
var $preg = '/<img.*?src=[\"\']((?![\"\']).*?)((?![\"\'])\?.*?)?[\"\']/i';
|
18 |
var $exclude_domain;
|
19 |
function __construct() {
|
20 |
$this->using_action = get_option('using_action', 'publish');
|
568 |
set_time_limit(0);
|
569 |
if ( $file=@file_get_contents($image_url) ) {
|
570 |
$filename=basename($image_url);
|
571 |
+
preg_match( '/(.*?)(\.(jpg|jpeg|png|gif|bmp))$/i', $filename, $match );
|
572 |
+
if ( empty($match) ) {
|
573 |
+
if ($filetype = $this->getFileType($file) ) {
|
574 |
+
preg_match( '/(.*?)$/i', $filename, $match );
|
575 |
+
$img_name = $match[0] . '.' . $filetype;
|
576 |
+
} else return false;
|
577 |
+
} else {
|
578 |
+
$img_name = $match[1].$match[2];
|
579 |
+
}
|
580 |
+
$res=wp_upload_bits($img_name,'',$file);
|
581 |
$attach_id = $this->insert_attachment($res['file'],$post_id);
|
582 |
if( !has_post_thumbnail($post_id) && $this->featured_image=='yes' ) set_post_thumbnail( $post_id, $attach_id );
|
583 |
return $res;
|
584 |
}
|
585 |
return false;
|
586 |
}
|
587 |
+
|
588 |
+
public function getFileType($file){
|
589 |
+
$bin = substr($file,0,2);
|
590 |
+
$strInfo = @unpack("C2chars", $bin);
|
591 |
+
$typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
|
592 |
+
$fileType = '';
|
593 |
+
switch ($typeCode) {
|
594 |
+
case 7790:
|
595 |
+
$fileType = 'exe';
|
596 |
+
return false;
|
597 |
+
break;
|
598 |
+
case 7784:
|
599 |
+
$fileType = 'midi';
|
600 |
+
return false;
|
601 |
+
break;
|
602 |
+
case 8297:
|
603 |
+
$fileType = 'rar';
|
604 |
+
return false;
|
605 |
+
break;
|
606 |
+
case 255216:
|
607 |
+
$fileType = 'jpg';
|
608 |
+
$mime = 'image/jpeg';
|
609 |
+
return $fileType;
|
610 |
+
break;
|
611 |
+
case 7173:
|
612 |
+
$fileType = 'gif';
|
613 |
+
$mime = 'image/gif';
|
614 |
+
return $fileType;
|
615 |
+
break;
|
616 |
+
case 6677:
|
617 |
+
$fileType = 'bmp';
|
618 |
+
$mime = 'image/bmp';
|
619 |
+
return $fileType;
|
620 |
+
break;
|
621 |
+
case 13780:
|
622 |
+
$fileType = 'png';
|
623 |
+
$mime = 'image/png';
|
624 |
+
return $fileType;
|
625 |
+
break;
|
626 |
+
default:
|
627 |
+
return false;
|
628 |
+
break;
|
629 |
+
}
|
630 |
+
return false;
|
631 |
+
}
|
632 |
|
633 |
//insert attachment
|
634 |
function insert_attachment($file,$id){
|