<?php
/*
Plugin Name: Auto_Save_Image
Version: 2.2.1
Plugin URI: http://www.01on.com/a/497.html
Description: 自动保存远程图片
Author: Bai Yunshan
Author URI: http://www.01on.com
*/
add_action('admin_menu','Auto_Save_Image_addmenu');
add_filter('content_save_pre', 'Auto_Save_Image_savepost');
add_action('admin_footer','Auto_Save_Image_footerinserts');
function Auto_Save_Image_footerinserts() {
if (str_replace("post-new.php","",$_SERVER['REQUEST_URI'])!=$_SERVER['REQUEST_URI']||str_replace("post.php","",$_SERVER['REQUEST_URI'])!=$_SERVER['REQUEST_URI']) {
?>
<script type="text/javascript">
var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;
if(!isIE){//非IE浏览器直接初始化
add_auto_save_image();
}else {
//IE下,防止浏览器提示“internet explore 无法打开internet站点 已终止操作”
if (document.readyState=="complete"){
add_auto_save_image();
} else {
document.onreadystatechange=function(){
if(document.readyState=="complete")add_auto_save_image();
}
}
}
//添加表单元素
function add_auto_save_image(){
document.getElementById("titlediv").innerHTML = document.getElementById("titlediv").innerHTML + "<span id=\"check_post_title\"></span>";
document.getElementById("titlediv").innerHTML = document.getElementById("titlediv").innerHTML + "<p align=\"right\"><input style=\"width:20px;\" type=\"checkbox\" name=\"Auto_Save_Image\" value=\"1\" id=\"checkbox\" <?php echo $_COOKIE["wordpress_Auto_Save_Image"];?> />自动保存远程图片 <input style=\"width:20px;\" type=\"checkbox\" name=\"Auto_Remove_Link\" value=\"1\" id=\"checkbox\" <?php echo $_COOKIE["wordpress_Auto_Remove_Link"];?> />自动去除非本站链接<input type=\"hidden\" name=\"temp_ID2\" id=\"temp_ID2\"></p>";
document.getElementById("temp_ID2").value = document.getElementById("post_ID").value;
var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;
if(isIE)
document.getElementById('title').attachEvent("onblur", check_re_title);
else
document.getElementById('title').addEventListener("blur", check_re_title, false);
}
function check_re_title(){
var obj = document.getElementById('title');
var title;
title = trim(obj.value);
title = title.replace(/</g, '<');
title = title.replace(/>/g, '>');
title = title.replace(/\"/g, '”');
if(title!=""){
document.getElementById("check_post_title").innerHTML = "正在检测标题《"+title+"》是否重复...";
var xmlhttp;
try{
xmlhttp=new XMLHttpRequest();
if (xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType('text/xml');
}
}catch(e){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (4==xmlhttp.readyState){
if (200==xmlhttp.status){
var data=xmlhttp.responseText;
<?php $postid = (int)$_GET["post"];
if($postid==0){ //新添加日志
?>
var re=new RegExp("<td[^<>]{0,}><strong><a[^<>]{1,}>"+title+"</a></strong>"); //如果是2.5版以上
<?php
}else{ //修改日志
?>
data=data.replace(/<td[^<>]{0,}><strong><a[^<>]{1,}post=<?php echo $postid;?>\" title=\"[^<>]{1,}>[^<>]{1,}<\/a><\/strong>/g,"");
//document.write(data);
var re=new RegExp("<td[^<>]{0,}><strong><a[^<>]{1,}>"+title+"</a></strong>"); //如果是2.5版以上
<?php
}
?>
if (re.exec(data)) {
document.getElementById("check_post_title").innerHTML = "<font color=\"red\">标题《"+title+"》重复!</font> <a href=\"edit.php?post_status=publish&s="+title+"&m=0&cat=0\" target=\"_blank\" title=\"查看重复的日志\">查看-><\/a>";
}else{
re=new RegExp("<td>( |\s){0,}"+title+"( |\s){0,}</td>"); //如果是2.3.3版
if (re.exec(data)) {
document.getElementById("check_post_title").innerHTML = "<font color=\"red\">标题《"+title+"》重复!</font> <a href=\"edit.php?post_status=publish&s="+title+"&m=0&cat=0\" target=\"_blank\" title=\"查看重复的日志\">查看-><\/a>";
}else{
document.getElementById("check_post_title").innerHTML = "<font color=\"green\">标题《"+title+"》没有重复</font>";
}
}
}else{
alert("error");
}
}
}
xmlhttp.open("GET", "edit.php?s="+encodeURI(trim(obj.value))+"&post_status=publish&m=0&cat=0", true);
xmlhttp.setRequestHeader('Content-type','text/html');
xmlhttp.send(null);
}else{
document.getElementById("check_post_title").innerHTML = "";
}
}
//去除字符串左右空格
function trim(string)
{
return string.replace(/(^\s*)|(\s*$)/g, "");
}
</script>
<?php
}
}
//保存或修改文章时自动保存远程图片
function Auto_Save_Image_savepost($content){
$Auto_Save_Image = get_option("Auto_Save_Image");
$Auto_Save_Image = split("@@@",$Auto_Save_Image);
$photo_markup = '1';
$photo_markdown = '1';
$photo_wwidth = '200'; //图片宽度大于此才加水印
$photo_wheight = '120'; //图片高度大于此才加水印
$photo_waterpos = $Auto_Save_Image[7];
$photo_watertext = $Auto_Save_Image[3];
$photo_fontsize = $Auto_Save_Image[4];
$photo_fontcolor = $Auto_Save_Image[5];
$photo_fontpath = $Auto_Save_Image[6];
$photo_diaphaneity = $Auto_Save_Image[2];
$photo_markimg = "../".$Auto_Save_Image[1];
$photo_savepath = $Auto_Save_Image[0];
//保存图片
if($_POST['Auto_Save_Image']=="1"){
setcookie('wordpress_Auto_Save_Image', ' checked="checked" ', time()+3600*24*366);
require_once(dirname(__FILE__) . "/inc_photograph.php");
require_once("../wp-includes/class-snoopy.php");
$snoopy_Auto_Save_Image = new Snoopy;
// begin to save pic;
$img_array = array();
if ( !empty( $_REQUEST['post_title'] ) )
$post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] ));
$content1 = stripslashes($content);
if (get_magic_quotes_gpc()) $content1 = stripslashes($content1);
preg_match_all("/ src=(\"|\'){0,}(http:\/\/(.+?))(\"|\'|\s)/is",$content1,$img_array);
$img_array = array_unique(dhtmlspecialchars($img_array[2]));
foreach ($img_array as $key => $value){
set_time_limit(180); //每个图片最长允许下载时间,秒
if(str_replace(get_bloginfo('url'),"",$value)==$value&&str_replace(get_bloginfo('home'),"",$value)==$value){
$fileext = substr(strrchr($value,'.'),1);
$fileext = strtolower($fileext);
if($fileext==""||strlen($fileext)>4)$fileext = "jpg";
$savefiletype = array('jpg','gif','png','bmp');
if (in_array($fileext, $savefiletype)){
if($snoopy_Auto_Save_Image->fetch($value)){
$get_file = $snoopy_Auto_Save_Image->results;
}else{
echo "error fetching file: ".$snoopy_Auto_Save_Image->error."<br>";
echo "error url: ".$value;
die();
}
$filetime = time();
$filepath = "/wp-content/uploads/".$photo_savepath.date("Y",$filetime)."/".date("m",$filetime)."/";//图片保存的路径目录
!is_dir("..".$filepath) ? mkdirs("..".$filepath) : null;
$filename = date("His",$filetime).random(3);
$fp = @fopen("..".$filepath.$filename.".".$fileext,"w");
@fwrite($fp,$get_file);
fclose($fp);
//添加水印开始
$srcFile = "..".$filepath.$filename.".".$fileext;
$info = "";
$srcInfo = GetImageSize($srcFile,$info);
$srcFile_w = $srcInfo[0];
$srcFile_h = $srcInfo[1];
if($srcFile_w > $photo_wwidth && $srcFile_h > $photo_wheight){
$trueMarkimg = $photo_markimg;
if(!file_exists($trueMarkimg) || empty($photo_markimg) || $photo_markimg=='../' || $photo_watertext !='') $trueMa

fayedzhang
- 粉丝: 2
最新资源
- 《C程序设计》教案模板(1).ppt
- 能源计量数据采集、处理、统计分析和应用制度(1).doc
- 浅谈基于网络教学平台高职院校信息化教学改革的几点思考(1).docx
- 水文信息化系统建设项目可行性研究报告(1).doc
- 关于中外中小企业融资制度比较的研究的论文-计算机理论论文(1).docx
- 互联网思维对企业财务管理的影响研究(1).docx
- 销售例会电子商务例会制度(1).doc
- 互联网+思维下图书馆服务的创新分析(1).docx
- 网站工作计划范文9篇(1).doc
- 浅谈我国金融信息化现状与发展战略教学内容(1).doc
- 浙江天台工业园区信息化建设实施方案(1).doc
- 计算机相关专业岗位说明(1).doc
- JSP仓库管理系统论文(2)(1).doc
- 基于java网络音乐系统的设计与实现--毕业论文(1).doc
- 数据库技术在计算机辅助审计中的应用研究(1).docx
- 网站建设合同范本(1).docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



- 1
- 2
前往页