phpcms编辑器自动下载外站的图片存在BUG

1、如果外站图片地址还参数如https://i1.hoopchina.com.cn/blogfile/201701/16/BbsImg148455553563159_2448x2448.jpg?x-oss-process=image/resize,w_800/format,jpg

地址后面有?后面一串字符, 正则去匹配 带参数的匹配 不到

2、https开头的图片也下载不了,phpcms没有对https的图片做判断

这两种情况只要出现一种就下载不下来了修改方法,直接上代码

1、/phpcms/libs/attachment.class.php

<?php
class attachment {var $contentid;var $module;var $catid;var $attachments;var $field;var $imageexts = array('gif', 'jpg', 'jpeg', 'png', 'bmp');var $uploadedfiles = array();var $downloadedfiles = array();var $error;var $upload_root;var $siteid;var $site = array();function __construct($module='', $catid = 0,$siteid = 0,$upload_dir = '') {$this->catid = intval($catid);$this->siteid = intval($siteid)== 0 ? 1 : intval($siteid);$this->module = $module ? $module : 'content';pc_base::load_sys_func('dir');pc_base::load_sys_class('image','','0');$this->upload_root = pc_base::load_config('system','upload_path');$this->upload_func = 'copy';$this->upload_dir = $upload_dir;}/*** 附件上传方法* @param $field 上传字段* @param $alowexts 允许上传类型* @param $maxsize 最大上传大小* @param $overwrite 是否覆盖原有文件* @param $thumb_setting 缩略图设置* @param $watermark_enable  是否添加水印*/function upload($field, $alowexts = '', $maxsize = 0, $overwrite = 0,$thumb_setting = array(), $watermark_enable = 1) {if(!isset($_FILES[$field])) {$this->error = UPLOAD_ERR_OK;return false;}if(empty($alowexts) || $alowexts == '') {$site_setting = $this->_get_site_setting($this->siteid);$alowexts = $site_setting['upload_allowext'];}$fn = $_GET['CKEditorFuncNum'] ? $_GET['CKEditorFuncNum'] : '1';$this->field = $field;$this->savepath = $this->upload_root.$this->upload_dir.date('Y/md/');$this->alowexts = $alowexts;$this->maxsize = $maxsize;$this->overwrite = $overwrite;$uploadfiles = array();$description = isset($GLOBALS[$field.'_description']) ? $GLOBALS[$field.'_description'] : array();if(is_array($_FILES[$field]['error'])) {$this->uploads = count($_FILES[$field]['error']);foreach($_FILES[$field]['error'] as $key => $error) {if($error === UPLOAD_ERR_NO_FILE) continue;if($error !== UPLOAD_ERR_OK) {$this->error = $error;return false;}$uploadfiles[$key] = array('tmp_name' => $_FILES[$field]['tmp_name'][$key], 'name' => $_FILES[$field]['name'][$key], 'type' => $_FILES[$field]['type'][$key], 'size' => $_FILES[$field]['size'][$key], 'error' => $_FILES[$field]['error'][$key], 'description'=>$description[$key],'fn'=>$fn);}} else {$this->uploads = 1;if(!$description) $description = '';$uploadfiles[0] = array('tmp_name' => $_FILES[$field]['tmp_name'], 'name' => $_FILES[$field]['name'], 'type' => $_FILES[$field]['type'], 'size' => $_FILES[$field]['size'], 'error' => $_FILES[$field]['error'], 'description'=>$description,'fn'=>$fn);}if(!dir_create($this->savepath)) {$this->error = '8';return false;}if(!is_dir($this->savepath)) {$this->error = '8';return false;}@chmod($this->savepath, 0777);if(!is_writeable($this->savepath)) {$this->error = '9';return false;}if(!$this->is_allow_upload()) {$this->error = '13';return false;}$aids = array();foreach($uploadfiles as $k=>$file) {$fileext = fileext($file['name']);if($file['error'] != 0) {$this->error = $file['error'];return false;}if(!preg_match("/^(".$this->alowexts.")$/", $fileext)) {$this->error = '10';return false;}if($this->maxsize && $file['size'] > $this->maxsize) {$this->error = '11';return false;}if(!$this->isuploadedfile($file['tmp_name'])) {$this->error = '12';return false;}$temp_filename = $this->getname($fileext);$savefile = $this->savepath.$temp_filename;$savefile = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2", $savefile);$filepath = preg_replace(new_addslashes("|^".$this->upload_root."|"), "", $savefile);if(!$this->overwrite && file_exists($savefile)) continue;$upload_func = $this->upload_func;if(@$upload_func($file['tmp_name'], $savefile)) {$this->uploadeds++;@chmod($savefile, 0644);@unlink($file['tmp_name']);$file['name'] = iconv("utf-8",CHARSET,$file['name']);$file['name'] = safe_replace($file['name']);$uploadedfile = array('filename'=>$file['name'], 'filepath'=>$filepath, 'filesize'=>$file['size'], 'fileext'=>$fileext, 'fn'=>$file['fn']);$thumb_enable = is_array($thumb_setting) && ($thumb_setting[0] > 0 || $thumb_setting[1] > 0 ) ? 1 : 0;$image = new image($thumb_enable,$this->siteid);if($thumb_enable) {$image->thumb($savefile,'',$thumb_setting[0],$thumb_setting[1]);}if($watermark_enable) {$image->watermark($savefile, $savefile);}$aids[] = $this->add($uploadedfile);}}return $aids;}/*** 附件下载* Enter description here ...* @param $field 预留字段* @param $value 传入下载内容* @param $watermark 是否加入水印* @param $ext 下载扩展名* @param $absurl 绝对路径* @param $basehref*/function download($field, $value,$watermark = '0',$ext = 'gif|jpg|jpeg|bmp|png', $absurl = '', $basehref = ''){global $image_d;$this->att_db = pc_base::load_model('attachment_model');$upload_url = pc_base::load_config('system','upload_url');$this->field = $field;$dir = date('Y/md/');$uploadpath = $upload_url.$dir;$uploaddir = $this->upload_root.$dir;$string = new_stripslashes($value);#if(!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\.($ext))\\2/i", $string, $matches)) return $value;if(!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\.($ext))(\?\S*)?\\2/i", $string, $matches)) return $value;$remotefileurls = array();foreach($matches[3] as $matche){if(strpos($matche, '://') === false) continue;dir_create($uploaddir);$remotefileurls[$matche] = $this->fillurl($matche, $absurl, $basehref);}unset($matches, $string);$remotefileurls = array_unique($remotefileurls);$oldpath = $newpath = array();foreach($remotefileurls as $k=>$file) {if(strpos($file, '://') === false || strpos($file, $upload_url) !== false) continue;$filename = fileext($file);if(!preg_match("/($ext)/is",$filename) || in_array($filename, array('php','phtml','php3','php4','jsp','dll','asp','cer','asa','shtml','shtm','aspx','asax','cgi','fcgi','pl'))){continue;}$file_name = basename($file);$filename = $this->getname($filename);$newfile = $uploaddir.$filename;$upload_func = $this->upload_func;if($upload_func($file, $newfile)) {$oldpath[] = $k;$GLOBALS['downloadfiles'][] = $newpath[] = $uploadpath.$filename;@chmod($newfile, 0777);$fileext = fileext($filename);if($watermark){watermark($newfile, $newfile,$this->siteid);}$filepath = $dir.$filename;$downloadedfile = array('filename'=>$filename, 'filepath'=>$filepath, 'filesize'=>filesize($newfile), 'fileext'=>$fileext);$aid = $this->add($downloadedfile);$this->downloadedfiles[$aid] = $filepath;}}return str_replace($oldpath, $newpath, $value);}/*** 附件删除方法* @param $where 删除sql语句*/function delete($where) {$this->att_db = pc_base::load_model('attachment_model');$result = $this->att_db->select($where);foreach($result as $r) {$image = $this->upload_root.$r['filepath'];@unlink($image);$thumbs = glob(dirname($image).'/*'.basename($image));if($thumbs) foreach($thumbs as $thumb) @unlink($thumb);}return $this->att_db->delete($where);}/*** 附件添加如数据库* @param $uploadedfile 附件信息*/function add($uploadedfile) {$this->att_db = pc_base::load_model('attachment_model');$uploadedfile['module'] = $this->module;$uploadedfile['catid'] = $this->catid;$uploadedfile['siteid'] = $this->siteid;$uploadedfile['userid'] = $this->userid;$uploadedfile['uploadtime'] = SYS_TIME;$uploadedfile['uploadip'] = ip();$uploadedfile['status'] = pc_base::load_config('system','attachment_stat') ? 0 : 1;$uploadedfile['authcode'] = md5($uploadedfile['filepath']);$uploadedfile['filename'] = strlen($uploadedfile['filename'])>49 ? $this->getname($uploadedfile['fileext']) : $uploadedfile['filename'];$uploadedfile['isimage'] = in_array($uploadedfile['fileext'], $this->imageexts) ? 1 : 0;$aid = $this->att_db->api_add($uploadedfile);$this->uploadedfiles[] = $uploadedfile;return $aid;}function set_userid($userid) {$this->userid = $userid;}/*** 获取缩略图地址..* @param $image 图片路径*/function get_thumb($image){return str_replace('.', '_thumb.', $image);}/*** 获取附件名称* @param $fileext 附件扩展名*/function getname($fileext){return date('Ymdhis').rand(100, 999).'.'.$fileext;}/*** 返回附件大小* @param $filesize 图片大小*/function size($filesize) {if($filesize >= 1073741824) {$filesize = round($filesize / 1073741824 * 100) / 100 . ' GB';} elseif($filesize >= 1048576) {$filesize = round($filesize / 1048576 * 100) / 100 . ' MB';} elseif($filesize >= 1024) {$filesize = round($filesize / 1024 * 100) / 100 . ' KB';} else {$filesize = $filesize . ' Bytes';}return $filesize;}/*** 判断文件是否是通过 HTTP POST 上传的** @param   string  $file   文件地址* @return  bool    所给出的文件是通过 HTTP POST 上传的则返回 TRUE*/function isuploadedfile($file) {return is_uploaded_file($file) || is_uploaded_file(str_replace('\\\\', '\\', $file));}/*** 补全网址** @param  string  $surl       源地址* @param    string  $absurl     相对地址* @param   string  $basehref   网址* @return    string  网址*/function fillurl($surl, $absurl, $basehref = '') {if($basehref != '') {$preurl = strtolower(substr($surl,0,6));if($preurl=='http://' || $preurl=='ftp://' ||$preurl=='mms://' || $preurl=='rtsp://' || $preurl=='thunde' || $preurl=='emule://'|| $preurl=='ed2k://')return  $surl;elsereturn $basehref.'/'.$surl;}$i = 0;$dstr = '';$pstr = '';$okurl = '';$pathStep = 0;$surl = trim($surl);if($surl=='') return '';$urls = @parse_url(SITE_URL);$HomeUrl = $urls['host'];$BaseUrlPath = $HomeUrl.$urls['path'];$BaseUrlPath = preg_replace("/\/([^\/]*)\.(.*)$/",'/',$BaseUrlPath);$BaseUrlPath = preg_replace("/\/$/",'',$BaseUrlPath);$pos = strpos($surl,'#');if($pos>0) $surl = substr($surl,0,$pos);if($surl[0]=='/') {$okurl = 'http://'.$HomeUrl.'/'.$surl;} elseif($surl[0] == '.') {if(strlen($surl)<=2) return '';elseif($surl[0]=='/') {$okurl = 'http://'.$BaseUrlPath.'/'.substr($surl,2,strlen($surl)-2);} else {$urls = explode('/',$surl);foreach($urls as $u) {if($u=="..") $pathStep++;else if($i<count($urls)-1) $dstr .= $urls[$i].'/';else $dstr .= $urls[$i];$i++;}$urls = explode('/', $BaseUrlPath);if(count($urls) <= $pathStep)return '';else {$pstr = 'http://';for($i=0;$i<count($urls)-$pathStep;$i++) {$pstr .= $urls[$i].'/';}$okurl = $pstr.$dstr;}}} else {$preurl = strtolower(substr($surl,0,6));if(strlen($surl)<7)$okurl = 'http://'.$BaseUrlPath.'/'.$surl;elseif($preurl=="http:/"||$preurl=='ftp://' ||$preurl=='mms://' || $preurl=="rtsp://" || $preurl=='thunde' || $preurl=='emule:'|| $preurl=='ed2k:/')$okurl = $surl;elseif(strtolower(substr($surl,0,8))=='https://'){$okurl = $surl;}else$okurl = 'http://'.$BaseUrlPath.'/'.$surl;}$preurl = strtolower(substr($okurl,0,6));if($preurl=='ftp://' || $preurl=='mms://' || $preurl=='rtsp://' || $preurl=='thunde' || $preurl=='emule:'|| $preurl=='ed2k:/') {return $okurl;}elseif(strtolower(substr($surl,0,8))=='https://'){return $okurl;}else {$okurl = preg_replace('/^(http:\/\/)/i','',$okurl);$okurl = preg_replace('/\/{1,}/i','/',$okurl);return 'http://'.$okurl;}}/*** 是否允许上传*/function is_allow_upload() {if($_groupid == 1) return true;$starttime = SYS_TIME-86400;$site_setting = $this->_get_site_setting($this->siteid);return ($uploads < $site_setting['upload_maxsize']);}/*** 返回错误信息*/function error() {$UPLOAD_ERROR = array(0 => L('att_upload_succ'),1 => L('att_upload_limit_ini'),2 => L('att_upload_limit_filesize'),3 => L('att_upload_limit_part'),4 => L('att_upload_nofile'),5 => '',6 => L('att_upload_notemp'),7 => L('att_upload_temp_w_f'),8 => L('att_upload_create_dir_f'),9 => L('att_upload_dir_permissions'),10 => L('att_upload_limit_ext'),11 => L('att_upload_limit_setsize'),12 => L('att_upload_not_allow'),13 => L('att_upload_limit_time'),);return iconv(CHARSET,"utf-8",$UPLOAD_ERROR[$this->error]);}/*** ck编辑器返回* @param $fn* @param $fileurl 路径* @param $message 显示信息*/function mkhtml($fn,$fileurl,$message) {$str='<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction('.$fn.', \''.$fileurl.'\', \''.$message.'\');</script>';exit($str);}/*** flash上传调试方法* @param $id*/function uploaderror($id = 0)   {file_put_contents(PHPCMS_PATH.'xxx.txt', $id);}/*** 获取站点配置信息* @param  $siteid 站点id*/private function _get_site_setting($siteid) {$siteinfo = getcache('sitelist', 'commons');return string2array($siteinfo[$siteid]['setting']);}
}
?>

修改两个地方一个是download方法中的正则图片的规则

if(!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\.($ext))(\?\S*)?\\2/i", $string, $matches)) return $value;

一个是增加fillurl方法中对https的判断

2、修改 /phpcms/model/content_model.class.php 对自动缩略图的正则修改

<?php
defined('IN_PHPCMS') or exit('No permission resources.');
if(!defined('CACHE_MODEL_PATH')) define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);/*** 内容模型数据库操作类*/
pc_base::load_sys_class('model', '', 0);
class content_model extends model {public $table_name = '';public $category = '';public function __construct() {$this->db_config = pc_base::load_config('database');$this->db_setting = 'default';parent::__construct();$this->url = pc_base::load_app_class('url', 'content');$this->siteid = get_siteid();}public function set_model($modelid) {$this->model = getcache('model', 'commons');$this->modelid = $modelid;$this->table_name = $this->db_tablepre.$this->model[$modelid]['tablename'];$this->model_tablename = $this->model[$modelid]['tablename'];}/*** 添加内容* * @param $datas* @param $isimport 是否为外部接口导入*/public function add_content($data,$isimport = 0) {if($isimport) $data = new_addslashes($data);$this->search_db = pc_base::load_model('search_model');$modelid = $this->modelid;require_once CACHE_MODEL_PATH.'content_input.class.php';require_once CACHE_MODEL_PATH.'content_update.class.php';$content_input = new content_input($this->modelid);$inputinfo = $content_input->get($data,$isimport);$systeminfo = $inputinfo['system'];$modelinfo = $inputinfo['model'];if($data['inputtime'] && !is_numeric($data['inputtime'])) {$systeminfo['inputtime'] = strtotime($data['inputtime']);} elseif(!$data['inputtime']) {$systeminfo['inputtime'] = SYS_TIME;} else {$systeminfo['inputtime'] = $data['inputtime'];}//读取模型字段配置中,关于日期配置格式,来组合日期数据$this->fields = getcache('model_field_'.$modelid,'model');$setting = string2array($this->fields['inputtime']['setting']);extract($setting);if($fieldtype=='date') {$systeminfo['inputtime'] = date('Y-m-d');}elseif($fieldtype=='datetime'){$systeminfo['inputtime'] = date('Y-m-d H:i:s');}if($data['updatetime'] && !is_numeric($data['updatetime'])) {$systeminfo['updatetime'] = strtotime($data['updatetime']);} elseif(!$data['updatetime']) {$systeminfo['updatetime'] = SYS_TIME;} else {$systeminfo['updatetime'] = $data['updatetime'];}$inputinfo['system']['username'] = $systeminfo['username'] = $data['username'] ? $data['username'] : param::get_cookie('admin_username');$systeminfo['sysadd'] = defined('IN_ADMIN') ? 1 : 0;//自动提取摘要if(isset($_POST['add_introduce']) && $systeminfo['description'] == '' && isset($modelinfo['content'])) {$content = stripslashes($modelinfo['content']);$introcude_length = intval($_POST['introcude_length']);$systeminfo['description'] = str_cut(str_replace(array("'","\r\n","\t",'[page]','[/page]','&ldquo;','&rdquo;','&nbsp;'), '', strip_tags($content)),$introcude_length);$inputinfo['system']['description'] = $systeminfo['description'] = addslashes($systeminfo['description']);}//自动提取缩略图if(isset($_POST['auto_thumb']) && $systeminfo['thumb'] == '' && isset($modelinfo['content'])) {$content = $content ? $content : stripslashes($modelinfo['content']);$auto_thumb_no = intval($_POST['auto_thumb_no'])-1;if(preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))(\?\S*)?\\2/i", $content, $matches)) {$systeminfo['thumb'] = $matches[3][$auto_thumb_no];}}$systeminfo['description'] = str_replace(array('/','\\','#','.',"'"),' ',$systeminfo['description']);$systeminfo['keywords'] = str_replace(array('/','\\','#','.',"'"),' ',$systeminfo['keywords']);//主表$tablename = $this->table_name = $this->db_tablepre.$this->model_tablename;$id = $modelinfo['id'] = $this->insert($systeminfo,true);$this->update($systeminfo,array('id'=>$id));//更新URL地址if($data['islink']==1) {$urls[0] = trim_script($_POST['linkurl']);$urls[0] = remove_xss($urls[0]);$urls[0] = str_replace(array('select ',')','\\','#',"'"),' ',$urls[0]);} else {$urls = $this->url->show($id, 0, $systeminfo['catid'], $systeminfo['inputtime'], $data['prefix'],$inputinfo,'add');}$this->table_name = $tablename;$this->update(array('url'=>$urls[0]),array('id'=>$id));//附属表$this->table_name = $this->table_name.'_data';$this->insert($modelinfo);//添加统计$this->hits_db = pc_base::load_model('hits_model');$hitsid = 'c-'.$modelid.'-'.$id;$this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$systeminfo['catid'],'updatetime'=>SYS_TIME));if($data['status']==99) {//更新到全站搜索$this->search_api($id,$inputinfo);}//更新栏目统计数据$this->update_category_items($systeminfo['catid'],'add',1);//调用 update$content_update = new content_update($this->modelid,$id);//合并后,调用update$merge_data = array_merge($systeminfo,$modelinfo);$merge_data['posids'] = $data['posids'];$content_update->update($merge_data);//发布到审核列表中if(!defined('IN_ADMIN') || $data['status']!=99) {$this->content_check_db = pc_base::load_model('content_check_model');$check_data = array('checkid'=>'c-'.$id.'-'.$modelid,'catid'=>$systeminfo['catid'],'siteid'=>$this->siteid,'title'=>$systeminfo['title'],'username'=>$systeminfo['username'],'inputtime'=>$systeminfo['inputtime'],'status'=>$data['status'],);$this->content_check_db->insert($check_data);}//END发布到审核列表中if(!$isimport) {$html = pc_base::load_app_class('html', 'content');$urls['data']['system']['id'] = $id;if($urls['content_ishtml'] && $data['status']==99) $html->show($urls[1],$urls['data']);$catid = $systeminfo['catid'];}//发布到其他栏目if($id && isset($_POST['othor_catid']) && is_array($_POST['othor_catid'])) {$linkurl = $urls[0];$r = $this->get_one(array('id'=>$id));foreach ($_POST['othor_catid'] as $cid=>$_v) {$this->set_catid($cid);$mid = $this->category[$cid]['modelid'];if($modelid==$mid) {//相同模型的栏目插入新的数据$inputinfo['system']['catid'] = $systeminfo['catid'] = $cid;$newid = $modelinfo['id'] = $this->insert($systeminfo,true);$this->table_name = $tablename.'_data';$this->insert($modelinfo);if($data['islink']==1) {$urls = $_POST['linkurl'];$urls = str_replace(array('select ',')','\\','#',"'"),' ',$urls);} else {$urls = $this->url->show($newid, 0, $cid, $systeminfo['inputtime'], $data['prefix'],$inputinfo,'add');}$this->table_name = $tablename;$this->update(array('url'=>$urls[0]),array('id'=>$newid));//发布到审核列表中if($data['status']!=99) {$check_data = array('checkid'=>'c-'.$newid.'-'.$mid,'catid'=>$cid,'siteid'=>$this->siteid,'title'=>$systeminfo['title'],'username'=>$systeminfo['username'],'inputtime'=>$systeminfo['inputtime'],'status'=>1,);$this->content_check_db->insert($check_data);}if($urls['content_ishtml'] && $data['status']==99) $html->show($urls[1],$urls['data']);} else {//不同模型插入转向链接地址$newid = $this->insert(array('title'=>$systeminfo['title'],'style'=>$systeminfo['style'],'thumb'=>$systeminfo['thumb'],'keywords'=>$systeminfo['keywords'],'description'=>$systeminfo['description'],'status'=>$systeminfo['status'],'catid'=>$cid,'url'=>$linkurl,'sysadd'=>1,'username'=>$systeminfo['username'],'inputtime'=>$systeminfo['inputtime'],'updatetime'=>$systeminfo['updatetime'],'islink'=>1),true);$this->table_name = $this->table_name.'_data';$this->insert(array('id'=>$newid));//发布到审核列表中if($data['status']!=99) {$check_data = array('checkid'=>'c-'.$newid.'-'.$mid,'catid'=>$systeminfo['catid'],'siteid'=>$this->siteid,'title'=>$systeminfo['title'],'username'=>$systeminfo['username'],'inputtime'=>$systeminfo['inputtime'],'status'=>1,);$this->content_check_db->insert($check_data);}}$hitsid = 'c-'.$mid.'-'.$newid;$this->hits_db->insert(array('hitsid'=>$hitsid,'catid'=>$cid,'updatetime'=>SYS_TIME));}}//END 发布到其他栏目//更新附件状态if(pc_base::load_config('system','attachment_stat')) {$this->attachment_db = pc_base::load_model('attachment_model');$this->attachment_db->api_update('','c-'.$systeminfo['catid'].'-'.$id,2);}//生成静态if(!$isimport && $data['status']==99) {//在添加和修改内容处定义了 INDEX_HTMLif(defined('INDEX_HTML')) $html->index();if(defined('RELATION_HTML')) $html->create_relation_html($catid);}return $id;}/*** 修改内容* * @param $datas*/public function edit_content($data,$id) {$model_tablename = $this->model_tablename;//前台权限判断if(!defined('IN_ADMIN')) {$_username = param::get_cookie('_username');$us = $this->get_one(array('id'=>$id,'username'=>$_username));if(!$us) return false;}$this->search_db = pc_base::load_model('search_model');require_once CACHE_MODEL_PATH.'content_input.class.php';require_once CACHE_MODEL_PATH.'content_update.class.php';$content_input = new content_input($this->modelid);$inputinfo = $content_input->get($data);$systeminfo = $inputinfo['system'];$modelinfo = $inputinfo['model'];if($data['inputtime'] && !is_numeric($data['inputtime'])) {$systeminfo['inputtime'] = strtotime($data['inputtime']);} elseif(!$data['inputtime']) {$systeminfo['inputtime'] = SYS_TIME;} else {$systeminfo['inputtime'] = $data['inputtime'];}if($data['updatetime'] && !is_numeric($data['updatetime'])) {$systeminfo['updatetime'] = strtotime($data['updatetime']);} elseif(!$data['updatetime']) {$systeminfo['updatetime'] = SYS_TIME;} else {$systeminfo['updatetime'] = $data['updatetime'];}//自动提取摘要if(isset($_POST['add_introduce']) && $systeminfo['description'] == '' && isset($modelinfo['content'])) {$content = stripslashes($modelinfo['content']);$introcude_length = intval($_POST['introcude_length']);$systeminfo['description'] = str_cut(str_replace(array("\r\n","\t",'[page]','[/page]','&ldquo;','&rdquo;','&nbsp;'), '', strip_tags($content)),$introcude_length);$inputinfo['system']['description'] = $systeminfo['description'] = addslashes($systeminfo['description']);}//自动提取缩略图if(isset($_POST['auto_thumb']) && $systeminfo['thumb'] == '' && isset($modelinfo['content'])) {$content = $content ? $content : stripslashes($modelinfo['content']);$auto_thumb_no = intval($_POST['auto_thumb_no'])-1;if(preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))(\?\S*)?\\2/i", $content, $matches)) {$systeminfo['thumb'] = $matches[3][$auto_thumb_no];}}if($data['islink']==1) {$systeminfo['url'] = $_POST['linkurl'];$systeminfo['url'] = str_replace(array('select ',')','\\','#',"'"),' ',$systeminfo['url']);} else {//更新URL地址$urls = $this->url->show($id, 0, $systeminfo['catid'], $systeminfo['inputtime'], $data['prefix'],$inputinfo,'edit');$systeminfo['url'] = $urls[0];}$systeminfo['description'] = str_replace(array('/','\\','#','.',"'"),' ',$systeminfo['description']);$systeminfo['keywords'] = str_replace(array('/','\\','#','.',"'"),' ',$systeminfo['keywords']);//主表$this->table_name = $this->db_tablepre.$model_tablename;$this->update($systeminfo,array('id'=>$id));//附属表$this->table_name = $this->table_name.'_data';$this->update($modelinfo,array('id'=>$id));$this->search_api($id,$inputinfo);//调用 update$content_update = new content_update($this->modelid,$id);$content_update->update($data);//更新附件状态if(pc_base::load_config('system','attachment_stat')) {$this->attachment_db = pc_base::load_model('attachment_model');$this->attachment_db->api_update('','c-'.$systeminfo['catid'].'-'.$id,2);}//更新审核列表$this->content_check_db = pc_base::load_model('content_check_model');$check_data = array('catid'=>$systeminfo['catid'],'siteid'=>$this->siteid,'title'=>$systeminfo['title'],'status'=>$systeminfo['status'],);if(!isset($systeminfo['status'])) unset($check_data['status']);$this->content_check_db->update($check_data,array('checkid'=>'c-'.$id.'-'.$this->modelid));//生成静态$html = pc_base::load_app_class('html', 'content');if($urls['content_ishtml']) {$html->show($urls[1],$urls['data']);}//在添加和修改内容处定义了 INDEX_HTMLif(defined('INDEX_HTML')) $html->index();if(defined('RELATION_HTML')) $html->create_relation_html($systeminfo['catid']);return true;}public function status($ids = array(), $status = 99) {$this->content_check_db = pc_base::load_model('content_check_model');$this->message_db = pc_base::load_model('message_model');$this->set_model($this->modelid);if(is_array($ids) && !empty($ids)) {foreach($ids as $id) {$this->update(array('status'=>$status),array('id'=>$id));$del = false;$r = $this->get_one(array('id'=>$id));if($status==0) {//退稿发送短消息、邮件$message = L('reject_message_tips').$r['title']."<BR><a href=\'index.php?m=member&c=content&a=edit&catid={$r[catid]}&id={$r[id]}\'><font color=red>".L('click_edit')."</font></a><br>";if(isset($_POST['reject_c']) && $_POST['reject_c'] != L('reject_msg')) {$message .= $_POST['reject_c'];} elseif(isset($_GET['reject_c']) && $_GET['reject_c'] != L('reject_msg')) {$message .= $_GET['reject_c'];}$this->message_db->add_message($r['username'],'SYSTEM',L('reject_message'),$message);} elseif($status==99 && $r['sysadd']) {$this->content_check_db->delete(array('checkid'=>'c-'.$id.'-'.$this->modelid));$del = true;}if(!$del) $this->content_check_db->update(array('status'=>$status),array('checkid'=>'c-'.$id.'-'.$this->modelid));}} else {$this->update(array('status'=>$status),array('id'=>$ids));$del = false;$r = $this->get_one(array('id'=>$ids));if($status==0) {//退稿发送短消息、邮件$message = L('reject_message_tips').$r['title']."<BR><a href=\'index.php?m=member&c=content&a=edit&catid={$r[catid]}&id={$r[id]}\'><font color=red>".L('click_edit')."</font></a><br>";if(isset($_POST['reject_c']) && $_POST['reject_c'] != L('reject_msg')) {$message .= $_POST['reject_c'];} elseif(isset($_GET['reject_c']) && $_GET['reject_c'] != L('reject_msg')) {$message .= $_GET['reject_c'];}$this->message_db->add_message($r['username'],'SYSTEM',L('reject_message'),$message);} elseif($status==99 && $r['sysadd']) {$this->content_check_db->delete(array('checkid'=>'c-'.$ids.'-'.$this->modelid));$del = true;}if(!$del) $this->content_check_db->update(array('status'=>$status),array('checkid'=>'c-'.$ids.'-'.$this->modelid));}return true;}/*** 删除内容* @param $id 内容id* @param $file 文件路径* @param $catid 栏目id*/public function delete_content($id,$file,$catid = 0) {//删除主表数据$this->delete(array('id'=>$id));//删除从表数据$this->table_name = $this->table_name.'_data';$this->delete(array('id'=>$id));//重置默认表$this->table_name = $this->db_tablepre.$this->model_tablename;//更新栏目统计$this->update_category_items($catid,'delete');}public function search_api($id = 0, $data = array(), $action = 'update') {$type_arr = getcache('search_model_'.$this->siteid,'search');$typeid = $type_arr[$this->modelid]['typeid'];if($action == 'update') {$fulltext_array = getcache('model_field_'.$this->modelid,'model');foreach($fulltext_array AS $key=>$value){if($value['isfulltext']) {$fulltextcontent .= $data['system'][$key] ? $data['system'][$key] : $data['model'][$key];}}$this->search_db->update_search($typeid ,$id, $fulltextcontent,addslashes($data['system']['title']).' '.addslashes($data['system']['keywords']),$data['system']['inputtime']);} elseif($action == 'delete') {$this->search_db->delete_search($typeid ,$id);}}/*** 获取单篇信息* * @param $catid* @param $id*/public function get_content($catid,$id) {$catid = intval($catid);$id = intval($id);if(!$catid || !$id) return false;$siteids = getcache('category_content','commons');$siteid = $siteids[$catid];$this->category = getcache('category_content_'.$siteid,'commons');if(isset($this->category[$catid]) && $this->category[$catid]['type'] == 0) {$modelid = $this->category[$catid]['modelid'];$this->set_model($modelid);$r = $this->get_one(array('id'=>$id));//附属表$this->table_name = $this->table_name.'_data';$r2 = $this->get_one(array('id'=>$id));if($r2) {return array_merge($r,$r2);} else {return $r;}}return true;}/*** 设置catid 所在的模型数据库* * @param $catid*/public function set_catid($catid) {$catid = intval($catid);if(!$catid) return false;if(empty($this->category) || empty($this->category[$catid])) {$siteids = getcache('category_content','commons');$siteid = $siteids[$catid];$this->category = getcache('category_content_'.$siteid,'commons');}if(isset($this->category[$catid]) && $this->category[$catid]['type'] == 0) {$modelid = $this->category[$catid]['modelid'];$this->set_model($modelid);}}private function update_category_items($catid,$action = 'add',$cache = 0) {$this->category_db = pc_base::load_model('category_model');if($action=='add') {$this->category_db->update(array('items'=>'+=1'),array('catid'=>$catid));}  else {$this->category_db->update(array('items'=>'-=1'),array('catid'=>$catid));}if($cache) $this->cache_items();}public function cache_items() {$datas = $this->category_db->select(array('modelid'=>$this->modelid),'catid,type,items',10000);$array = array();foreach ($datas as $r) {if($r['type']==0) $array[$r['catid']] = $r['items'];}setcache('category_items_'.$this->modelid, $array,'commons');}
}
?>

转载于:https://my.oschina.net/u/1421472/blog/883874

phpcms下载图片BUG相关推荐

  1. 微信小程序wx.downloadFile下载图片(甄姬)出现格式.unknown的bug

    微信小程序调用api wx.downloadFile下载图片(甄姬),有时候会出现格式.unknown的bug 针对这个问题我们可以通过自定义图片名称,并且传入filePath指定文件下载后存储的路径 ...

  2. 手机下载神器批量下载图片教程

    手机版IDM下载神器批量下载图片漫画实际操作教程,现在介绍两个批量下载图片的方法 视频教程: 手机IDM下载器批量下载图片漫画实际操作 首先,打开你要下载图片的网页,同时打开手机版idm下载器和手机记 ...

  3. Android框架——下载图片框架Fresco

    版权声明:本文为博主原创文章,未经博主允许不得转载.转载注明出处:Sunzxyong 流行的网络框架 目前流行的网络图片框架:  Picasso.Universal Image Loader.Voll ...

  4. php ajax 下载图片路径,JavaScript_批量下载对路网图片并生成html的实现方法,对路使用ajax实现异步加载内容 - phpStudy...

    批量下载对路网图片并生成html的实现方法 对路使用ajax实现异步加载内容,在它的js代码中找到了相关代码 type : 'POST', url : '/index.php/request/new_ ...

  5. python requests html格式图片打不开_爬虫下载图片打不开是什么原因,最新简易爬虫教程...

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. (本文来自www.777n.com) 作者: GitPython (原文来 ...

  6. Node.js 批量下载图片

    前言 最近接手一个项目,是一个兄弟公司写的,使用PHP的ThinkPHP做的前后端在一起的项目.代码是别人搞到服务器上面去的,突然那边的整个技术部解散了,而我们这边在此之前我还没看见过代码.项目虽说部 ...

  7. 配置echarts下载图片分辨率,以及报错解决

    echarts版本v5.0.1 配置toolbox.feature.saveAsImage. pixelRatio:保存图片的分辨率比例,默认为1,即默认分辨率跟exchart所在DOM相同大小,如果 ...

  8. java下载图片压缩包_java压缩文件和下载图片示例

    本文实例为大家分享了java压缩文件和下载图片示例,供大家参考,具体内容如下 主页面index.xml 项目的主页 主页主页 湖南长沙 发布方式一...... 页面内容压缩演示--gzip 下载图片 ...

  9. Jsoup下载图片报错:UnsupportedMimeTypeException

    2019独角兽企业重金招聘Python工程师标准>>> 使用Jsoup下载图片时,报错:不支持MimeType异常. Response request = Jsoup.connect ...

最新文章

  1. chinese_L-12_H-768_A-12的一个坑
  2. Python知识点笔记-面向对象进阶篇
  3. 取某个日期所在周的任意一天日期
  4. 软件开发中的一些感想
  5. 13 计算机组成原理第七章 输入/输出系统 I/O方式 I/O接口
  6. mysql排序规则错误_MySQL中“非法混合排序规则”错误的疑难解答
  7. 实验报告四 201521430002 张实
  8. 公司这套架构统一处理try...catch这么香,求求你不要再满屏写了,再发现扣绩效!...
  9. 盗链 防止盗链 防止图片盗链
  10. 银联证书下载及导出流程
  11. Python爬虫QQ空间
  12. python文件粉碎传输_如何自己实现文件粉碎机?
  13. 论文写作笔记4 期刊选择-医学计算机
  14. echarts社区饼图 echart饼图 玫瑰图
  15. 玩转小黑框!Terminal 入门到进阶,最后放弃!
  16. 微信群发助手怎么使用?微信群发助手怎么发?
  17. 暴露自己IP地址有危险吗?
  18. day03 Http协议Request
  19. 学习日志——2019/07/04
  20. IGBT的驱动和过流保护电路的研究

热门文章

  1. 分享136个ASP源码,总有一款适合您
  2. IntelliJ IDEA 使用 rest client
  3. Python游戏 (胖鸟快飞Flappybird)
  4. Ypai windows部署小白也可以哦
  5. 学计算机应该准备什么学习工具,#宅家学习技巧# 篇一:学习做网站 之工具准备...
  6. 多米机器人教材_祝博士多米机器人首次进入公校课堂, 科技辅助教学培养学生全面发展!...
  7. 小米应用商店上传apk报图片格式错误,小米手机调试 DELETE_FAILED_INTERNAL_ERROR错误
  8. Activiti 7流程跳转
  9. Python数据分析实战【九】:用Python处理省份城市编码数据【文末源码地址】
  10. 【算法设计与分析】活动安排问题(动态规划和贪心算法)