1、在wp-admin/edit-form-advanced.php 第167行
HTML 代码:
<span id=”autosave”></span>后面加增加HTML 代码:
Save pic:<input type=”checkbox” name=”savepic” value=”checked” />
2、修改 wp-admin/post.php,将第7行的PHP 代码:
wp_reset_vars(array(’action’, ’safe_mode’, ’withcomments’, ’posts’,
’content’, ’edited_post_title’, ’comment_error’, ’profile’, ’trackback_url’,
excerpt’, ’showcomments’, ’commentstart’, ’commentend’, ’commentorder’));
改为PHP 代码:
wp_reset_vars(array(’action’, ’safe_mode’, ’withcomments’, ’posts’, ’content’,
edited_post_title’, ’comment_error’, ’profile’, ’trackback_url’, ’excerpt’, ’showcomments’,
’commentstart’, ’commentend’, ’commentorder’, ’savepic’));
3、在wp-admin/includes/post.php的开头增加PHP 代码:
function open($file,$type=”){
global $fromurl,$referer;
$cachename=$file;
if($type){
$file=$fromurl.’/’.$type.’/’.$file;
}else{
$file=$fromurl.$file;
}
if($open=file($file)){
$count=count($open);
for($i=0;$i<$count;$i++){
$theget.=$open[$i];
}
}else{
die(’请求过多,超时,请刷新’);
}
return $theget;
}
function cut($file,$from,$end){
$message=explode($from,$file);
$message=explode($end,$message[1]);
return $message[0];
}
function dhtmlspecialchars($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = dhtmlspecialchars($val);
}
} else {
$string = str_replace(’&’, ’&’, $string);
$string = str_replace(’”‘, ’”‘, $string);
$string = str_replace(’<’, ’<’, $string);
$string = str_replace(’>’, ’>’, $string);
$string = preg_replace(’/&(#\d;)/’, ’&\1′, $string);
}
return $string;
}
function random($length) {
$hash = ”;
$chars = ’ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz’;
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
function mkdirs($dir)
{
if(!is_dir($dir))
{
mkdirs(dirname($dir));
mkdir($dir);
}
return ;
}
再在PHP 代码:
$_POST[’post_content’] = $_POST[’content’];
的后面添加以下代码:
注意,上面的代码有两个地方有,第一个是修改的,最后一个是添加的.你如果只加添加的功能就在最后那个加,如果修改的也要加,就在前面的也加上.PHP 代码:
if($_POST[’savepic’]==”checked”){
// begin to save pic;
$img_array = array();
$content1 = stripslashes($_POST[’post_content’]);
if (get_magic_quotes_gpc()) $content1 = stripslashes($content1);
//echo $content1;//文章内容嘿嘿开始处理了
preg_match_all(”/(src|SRC)=\”(http:\/\/(.+).(gif|jpg|jpeg|bmp|png))/isU”,$content1,$img_array);//正则开始匹配所有的图片并放入数据
$img_array = array_unique(dhtmlspecialchars($img_array[2]));
print_r($img_array);
set_time_limit(0);
foreach ($img_array as $key => $value) {
$get_file = file_get_contents($value);//开始获取图片了哦
$filetime = time();
$filepath = ”../wp-content/uploads/pic2/”.date(”Y”,$filetime).”/”.date(”m”,$filetime).”/”;//图片保存的路径目录
!is_dir($filepath) ? mkdirs($filepath) : null;
$filename = date(”YmdHis”,$filetime).random(1).’.’.substr($value,-3,3);
$fp = @fopen($filepath.$filename,”w”);
@fwrite($fp,$get_file);
fclose($fp);//完工,哈
$content1 = preg_replace(”/”.addcslashes($value,”/”).”/isU”, ”/wp-content/uploads/pic2/”.date(”Y”,$filetime).”/”.date(”m”,$filetime).”/”.$filename, $content1); //顺便替换一下文章里面的图片地址
}
$_POST[’post_content’] = AddSlashes($content1); //老鬼的旧版本没有这个转义过程所以会出错
// end save pic;
}
完毕。现在,你再发表文章时,提交按钮旁边多了个选项选中“save pic”,再点“发表”,即可保存远程图片了。总结一下,要修改的文件有:wp-admin/edit-form-advanced.php
wp-admin/post.php
wp-admin/includes/post.php
WordPress自动保存远程图片到本地(2.3.X系列测试通过)转载
作者: 馒头 日期: 2008-02-24 01:25
HTML 代码:
<span id=”autosave”></span>后面加增加HTML 代码:
Save pic:<input type=”checkbox” name=”savepic” value=”checked” />
2、修改 wp-admin/post.php,将第7行的PHP 代码:
wp_reset_vars(array(’action’, ’safe_mode’, ’withcomments’, ’posts’,
’content’, ’edited_post_title’, ’comment_error’, ’profile’, ’trackback_url’,
excerpt’, ’showcomments’, ’commentstart’, ’commentend’, ’commentorder’));
改为PHP 代码:
wp_reset_vars(array(’action’, ’safe_mode’, ’withcomments’, ’posts’, ’content’,
edited_post_title’, ’comment_error’, ’profile’, ’trackback_url’, ’excerpt’, ’showcomments’,
’commentstart’, ’commentend’, ’commentorder’, ’savepic’));
3、在wp-admin/includes/post.php的开头增加PHP 代码:
function open($file,$type=”){
global $fromurl,$referer;
$cachename=$file;
if($type){
$file=$fromurl.’/’.$type.’/’.$file;
}else{
$file=$fromurl.$file;
}
if($open=file($file)){
$count=count($open);
for($i=0;$i<$count;$i++){
$theget.=$open[$i];
}
}else{
die(’请求过多,超时,请刷新’);
}
return $theget;
}
function cut($file,$from,$end){
$message=explode($from,$file);
$message=explode($end,$message[1]);
return $message[0];
}
function dhtmlspecialchars($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = dhtmlspecialchars($val);
}
} else {
$string = str_replace(’&’, ’&’, $string);
$string = str_replace(’”‘, ’”‘, $string);
$string = str_replace(’<’, ’<’, $string);
$string = str_replace(’>’, ’>’, $string);
$string = preg_replace(’/&(#\d;)/’, ’&\1′, $string);
}
return $string;
}
function random($length) {
$hash = ”;
$chars = ’ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz’;
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) {
$hash .= $chars[mt_rand(0, $max)];
}
return $hash;
}
function mkdirs($dir)
{
if(!is_dir($dir))
{
mkdirs(dirname($dir));
mkdir($dir);
}
return ;
}
再在PHP 代码:
$_POST[’post_content’] = $_POST[’content’];
的后面添加以下代码:
注意,上面的代码有两个地方有,第一个是修改的,最后一个是添加的.你如果只加添加的功能就在最后那个加,如果修改的也要加,就在前面的也加上.PHP 代码:
if($_POST[’savepic’]==”checked”){
// begin to save pic;
$img_array = array();
$content1 = stripslashes($_POST[’post_content’]);
if (get_magic_quotes_gpc()) $content1 = stripslashes($content1);
//echo $content1;//文章内容嘿嘿开始处理了
preg_match_all(”/(src|SRC)=\”(http:\/\/(.+).(gif|jpg|jpeg|bmp|png))/isU”,$content1,$img_array);//正则开始匹配所有的图片并放入数据
$img_array = array_unique(dhtmlspecialchars($img_array[2]));
print_r($img_array);
set_time_limit(0);
foreach ($img_array as $key => $value) {
$get_file = file_get_contents($value);//开始获取图片了哦
$filetime = time();
$filepath = ”../wp-content/uploads/pic2/”.date(”Y”,$filetime).”/”.date(”m”,$filetime).”/”;//图片保存的路径目录
!is_dir($filepath) ? mkdirs($filepath) : null;
$filename = date(”YmdHis”,$filetime).random(1).’.’.substr($value,-3,3);
$fp = @fopen($filepath.$filename,”w”);
@fwrite($fp,$get_file);
fclose($fp);//完工,哈
$content1 = preg_replace(”/”.addcslashes($value,”/”).”/isU”, ”/wp-content/uploads/pic2/”.date(”Y”,$filetime).”/”.date(”m”,$filetime).”/”.$filename, $content1); //顺便替换一下文章里面的图片地址
}
$_POST[’post_content’] = AddSlashes($content1); //老鬼的旧版本没有这个转义过程所以会出错
// end save pic;
}
完毕。现在,你再发表文章时,提交按钮旁边多了个选项选中“save pic”,再点“发表”,即可保存远程图片了。总结一下,要修改的文件有:wp-admin/edit-form-advanced.php
wp-admin/post.php
wp-admin/includes/post.php
注:要打开了PHP.INI的output_buffering 和allow_url_fopen
评论: 0 |
引用: 0 |
阅读: 529
订阅
上一篇
返回
下一篇
标签:
给 wordpress 评论框增加贴图标签 (2008-01-24 02:56)
给wordpress 加上干扰码防采集 (2008-01-23 01:30)
WordPress提供免费3GB空间 (2008-01-23 01:25)
WordPress不会有2.4版本直接2.5 (2008-01-07 00:52)
High Performance WordPress (2007-12-12 13:15)
WordPress v2.3.1 Final又升级了。。。。。。 (2007-10-27 17:08)
WordPress 2.3 正式版发布/下载 (2007-09-25 11:33)
WordPress V2.3 RC1终于发布了。。本地下载 (2007-09-19 23:36)
WordPress v2.3 Beta 2 (2007-09-05 01:00)
Wordpress 皮肤生成工具 (2007-04-27 02:37)
博客圈最流行的30个 wordpress 插件 (2007-04-01 08:46)
WordPress的网络硬盘插件 (2007-02-26 12:59)
WordPress 2.1.1 和2.0.9版本发布 (2007-02-22 21:29)