就是發帖的時候,可以直接複製別人的文章。如果別人的文章裏邊包含圖片 ,就自動把圖片 下載到服務器,
並且可以設置縮略圖,添加到附件列表,diy 的時候也可以選擇縮略圖。
先看下效果吧。


下載完成後,自動發帖。
其實遠程圖片下載並不難,php 自帶的文件讀取函數就可以。難的是 要明白 dz 發帖自帶的標籤,圖片的存儲,數據的插入等。
首先縮略圖 用到的數據表為:forum_threadimage 表。
附件表為:forum_attachment(附件帖子對應表) forum_attachment1~9(附件存儲表) forum_attachment_unused(臨時附件表)
剛開始由於不理解原理,繞了很多彎路,
首先就是 獲取 message 就是 帖子內容。不過 dz 已經自動將其標籤化了,遠程圖片標籤為:

上傳的圖片附件標籤為:
[attachimg]aid[/attachimg] 其中 aid 為附件的 id 存儲在 forum_attachment(附件帖子對應表) 中,具體的附件路徑存在 forum_attachment1~9(附件存儲表)
所以你要匹配到 [img] 標籤 然後獲取 url 下載-存儲-插入數據庫。其中比較複雜的是 那個附件臨時表。下載下來的圖片都存儲在附件臨時表中。
具體發帖的時候 從臨時表中讀取然後插入到 forum_attachment1~9(附件存儲表) ,並且更新 forum_attachment(附件帖子對應表)
更新之前

更新之後
這裏比較重要的是 aid 這個字段
算了,下班了,明天再更。發一段 js 代碼吧
- function validate(theform) {
- var message = wysiwyg ? html2bbcode(getEditorContents()) : theform.message.value;
- if(!theform.parseurloff.checked) {
- message = parseurl(message);
- }
- if(($('postsubmit').name != 'replysubmit' && !($('postsubmit').name == 'editsubmit' && !isfirstpost) && theform.subject.value == "") || !sortid && !special && trim(message) == "") {
- showError('抱歉,您尚未輸入標題或內容');
- return false;
- } else if(mb_strlen(theform.subject.value) > 80) {
- showError('您的標題超過 80 個字符的限制');
- return false;
- }
- if(ispicstyleforum == 1 && ATTACHORIMAGE == 0 && isfirstpost) {
- }
- if(in_array($('postsubmit').name, ['topicsubmit', 'editsubmit'])) {
- if(theform.typeid && (theform.typeid.options && theform.typeid.options[theform.typeid.selectedIndex].value == 0) && typerequired) {
- showError('請選擇主題對應的分類');
- return false;
- }
- if(theform.sortid && (theform.sortid.options && theform.sortid.options[theform.sortid.selectedIndex].value == 0) && sortrequired) {
- showError('請選擇主題對應的分類信息');
- return false;
- }
- }
- for(i in EXTRAFUNC['validator']) {
- try {
- eval('var v = ' + EXTRAFUNC['validator'][i] + '()');
- if(!v) {
- return false;
- }
- } catch(e) {}
- }
- if(!disablepostctrl && !sortid && !special && ((postminchars != 0 && mb_strlen(message) < postminchars) || (postmaxchars != 0 && mb_strlen(message) > postmaxchars))) {
- showError('您的帖子長度不符合要求。
當前長度: ' + mb_strlen(message) + ' 字節
系統限制: ' + postminchars + ' 到 ' + postmaxchars + ' 字節'); - return false;
- }
- if(UPLOADSTATUS == 0) {
- if(!confirm('您有等待上傳的附件,確認不上傳這些附件嗎?')) {
- return false;
- }
- } else if(UPLOADSTATUS == 1) {
- showDialog('您有正在上傳的附件,請稍候,上傳完成後帖子將會自動發表...', 'notice');
- AUTOPOST = 1;
- return false;
- }
- if(isfirstpost && $('adddynamic') != null && $('adddynamic').checked && $('postsave') != null && isNaN(parseInt($('postsave').value)) && ($('readperm') != null && $('readperm').value || $('price') != null && $('price').value)) {
- if(confirm('由於您設置了閲讀權限或出售帖,您確認還轉播給您的聽眾看嗎?') == false) {
- return false;
- }
- }
- /* if(jQuery('#postsubmit').hasClass('upload_now') ) {
- showError('正在上傳圖片中!請稍後!');
- return false;
- } */
- return check_remote_img(message,theform);
- }
- function theform_(message,theform) {
- theform.message.value = message;
- if($('postsubmit').name == 'editsubmit') {
- postsubmit(theform);
- return false;
- } else if(in_array($('postsubmit').name, ['topicsubmit', 'replysubmit'])) {
- if(seccodecheck || secqaacheck) {
- var chk = 1, chkv = '';
- if(secqaacheck) {
- chkv = $('checksecqaaverify_' + theform.sechash.value).innerHTML;
- if(chkv.indexOf('loading') != -1) {
- setTimeout(function () { validate(theform); }, 100);
- chk = 0;
- } else if(chkv.indexOf('check_right') == -1) {
- showError('驗證問答錯誤,請重新填寫');
- chk = 0;
- }
- }
- if(seccodecheck) {
- chkv = $('checkseccodeverify_' + theform.sechash.value).innerHTML;
- if(chkv.indexOf('loading') !== -1) {
- setTimeout(function () { validate(theform); }, 100);
- chk = 0;
- } else if(chkv.indexOf('check_right') === -1) {
- showError('驗證碼錯誤,請重新填寫');
- chk = 0;
- }
- }
- if(chk) {
- postsubmit(theform);
- }
- } else {
- postsubmit(theform);
- }
- return false;
- }
- }
- function check_remote_img(message,theform) {
- var reg_1 = /[img=d+,d+]([sS]*?)[/img]/g;
- var reg_2 = /[img]([sS]*?)[/img]/g;
- var reg_3 = /[img=d+,d+]([sS]*?)[/img]/;
- var reg_4 = /[img]([sS]*?)[/img]/;
- var args = new Array();
- args['fade'] = 1;
- args['cover'] = 1;
- if( reg_1.test(message) || reg_2.test(message) ) {
- var match = new Array();
- var url_ = new Array();
- match
= message.match(reg_1); - match2 = message.match(reg_2);
- if( match2 == null && match != null ) {
- match2 = new Array();
- match2 = match2.concat(match);
- url = match2;
- for(i = 0; i < url.length; i++) {
- var str = url[i];
- url_[i] = reg_3.exec(str)[1];
- }
- }
- else if( match2 != null && match != null ) {
- match2 = match2.concat(match);
- url = match2;
- for(i = 0; i < url.length; i++) {
- var str = url[i];
- if( reg_3.test(str) ) {
- url_[i] = reg_3.exec(str)[1];
- }
- else {
- url_[i] = reg_4.exec(str)[1];
- }
- }
- }
- else {
- match = new Array();
- match2 = match.concat(match2);
- url = match2;
- for(i = 0; i < url.length; i++) {
- var str = url[i];
- url_[i] = reg_4.exec(str)[1];
- }
- }
- var html = '<style>'+
- '#uploadRemote {width:530px; height:330px; overflow:hidden;}'+
- '#uploadRemote .upload_c {padding:0px 15px 0;}'+
- '#fwin_dialog h3.flb span{display:none;}'+
- '#message_ {display:none;}'+
- '#upload_show {height:300px; overflow-y:auto;}'+
- '#upload_show p {width:100px; height:100px; margin:0 auto; margin-top:20px;}'+
- '#upload_show ul li {float:left; margin:5px; }'+
- '#upload_show ul li a {text-align:center;}'+
- '.msg {line-height:24px; color:#369; text-align:center; border:1px dashed #ddd;}'+
- '</style>'+
- '<div id="uploadRemote">'+
- '<div >'+
- '<div > 發現你的帖子包含<span style="color:red; font-weight:bold;">'+url_.length+'</span> 張遠程圖片<br /> 系統將為你自動下載!<br /></div>'+
- '<div id="upload_show">'+
- '<p ><img src="/static/image/common/loading2.gif" /></p>'+
- '<ul></ul>'+
- '</div>'+
- '</div>'+
- &nb
sp; &nbs
p; '</div>'; - showDialog(html,'info','遠程圖片下載','',1,args);
- setTimeout(function(){
- jQuery('#postsubmit').addClass('upload_now');
- jQuery('#uploadRemote .msg').html('圖片下載中,請耐心等待。如果等待時間過長,請從新刷新頁面。謝謝!剩餘<span style="color:red ;font-weight:bold;">'+url_.length+'</span> 張');
- i = 0;
- dois(url_,i,message,theform);
- return false;
- jQuery('#upload_show p').hide();
- },1200);
- return false;
- }
- else {
- return theform_(message,theform);
- }
- }
- function dois(url_,i,message,theform) {
- html = '';
- jQuery.ajax({
- type: 'POST',
- url: 'forum.php?mod=uploadRemote&action=newthread',
- data: {url:url_[i],message:message},
- dataType: "json",
- success: function (data) {
- message = data.message;
- html2bbcode(editdoc.body.innerHTML = message);
- message = html2bbcode(getEditorContents());
- if( data.error == 1 ) {
- // 圖片下載失敗!
- html += '<li><a href=""> 下載失敗</a></li>';
- jQuery('#upload_show ul').append(html);
- jQuery('#uploadRemote .msg span').text(url_.length - i - 1);
- i++;
- if( i < url_.length ) {
- dois(url_,i,message,theform);
- }
- else {
- setTimeout(function(){return theform_(message,theform);},2000);
- }
- }
- else {
- html += '<li><img src="'+data.tmp_name+'" width="90" height="90" /></li>';
- jQuery('#upload_show ul').append(html);
- jQuery('#postbox').append('<input type="text" name="attachnew['+data.aid+'][description]" style="display: none" id="image_desc_'+data.aid+'">');
- jQuery('#uploadRemote .msg span').text(url_.length - i - 1);
- i++;
- if( i < url_.length ) {
- dois(url_,i,message,theform);
- }
- else {
- setTimeout(function(){return theform_(message,theform);},2000);
- }
- }
- },
- });
- }
validate() 為發帖調用 js,我是把匹配都放到 js 中了 然後通過 ajax 來下載圖片,並且替換標籤 把 [img] 全部替換為附件標籤 [attachimg]