当前位置:  编程技术>php
本页文章导读:
    ▪使用php来实现网络服务       作者:samisa 以下文中的翻译名称对照表 : payload: 交谈内容 object: 实例 function: 函数 使用 php来实现网络服务 使用框架: WSO2 WSF/PHP 安装环境: windows 或者 linux (厌恶于眼下计算机文章夹杂无.........
    ▪Discuz 6.0+ 批量注册用户名       1.将adduser.php复制到discuz根目录下; /--adduser.php内容如下--/ <? php require_once './include/common.inc.php '; //注册的名字 $user_list = file('./username.txt '); //注册的密码 $a = "12345678"; $pwd = md5($a); // 注册用.........
    ▪火车头discuz6.1 完美采集的php接口文件       PS:对原文件的修改较大,程序中注释已经很详尽,这里就不多说了。 代码如下:<?php // header('Content-Type:text/html;charset=UTF-8'); //if(function_exists("mb_convert_encoding")){ // $tmp = checkAndTranslate("使用前.........

[1]使用php来实现网络服务
    来源: 互联网  发布时间: 2013-11-30
作者:samisa
以下文中的翻译名称对照表 :
payload: 交谈内容
object: 实例
function: 函数
使用 php来实现网络服务
使用框架: WSO2 WSF/PHP
安装环境: windows 或者 linux
(厌恶于眼下计算机文章夹杂无数难懂的翻译以及术语,此处尽量使用口语以及汉语。)
WSMessages 类:
在调用网络服务的过程中,需要两个消息,发送的消息和接受的消息,又来有往方能来往不是。 WSMessages 这个类就是在 Web services framework for php (简称 WSF)这个开源框架中,用来封装这两个消息的类。
WSMessages 有一个很重要的变量 str来保存消息内容,以 xml格式来保存“有效的载荷” (他们把这个叫做 payload,我查英文字典,就是这个意思,但是它来回的出现,反复的出现,今观之,也就是交谈内容,实际上就是除去那些 xml的定义,以及一些其他的所谓‘命名空间' ->namespace的定义而已。要搞清楚什么是命名空间,请查看 xml的 W3C定义 )。有效载荷实在是莫名其妙,我以后还是用‘交谈内容'来指代它把。
如果你通过客户程序发送一个请求,那么你需要构造一个 WSMessage 的实例,并且用 xml形式的交谈内容填写好这个实例。对应请求的回应,也还是一个‘交谈内容'会通过你的程序返回,并且返回的东西也仍然是一个 WSMessage 实例。
也就是说,你的客户端函数掉应一个网络服务,那么他的返回值也是一个 WSMessage 实例。
你可以在一个函数中发送请求,调用网络服务的程序,并且把返回内容放在 WSMessage实例中,并且让函数返回这个 WSMessage实例。
WSMessage 更倾向于发送和接受比较复杂的内容比如有附件什么的。下面就来详细解释一下如何使用 WSMessage 来实现客户端和服务端的交流。
处理交谈内容:
在此之前已经讲解过如何使用 php来创建网络服务,并且已经做了一个简单的客户 -服务端程序来说明工作流程。但是这些程序并没有深入的解释我们怎么处理‘交谈内容'。换句话来说,我们只是把 xml格式的交谈内容发送到了服务端,但并没有想到去处理它。在这里,我们来详细的解释一下如何处理交谈内容并且把它用到计算程序中去。
交谈内容是一个商业逻辑定义的内容,并且用 SOAP( Simple Object Access Protocol)来封装的,(请参见 SOAP w3c的文章)。让我们用个例子来说明如何计算一个阶乘吧。
客户端需要发送的交谈内容:
<getFactorial>
<param>6</param>
</getFactorial>
服务端需要明白这个交谈内容并且把变量分辨出来并且计算它的阶乘。下面就是服务端程序:
function getFactorial ( $message ) {
$simplexml = new SimpleXMLElement ( $message -> str ) ;
$value = $simplexml -> param [ 0 ] ;
$result = factorial ( $value ) ;
$responsePayloadString = <<<XML
<getFactorialResponse>
<result> $result </result>
</getFactorialResponse>
XML;
return $responsePayloadString ;
}
第 3行,我们用输入的‘交谈内容'创建了一个 simpleXmlElement 的实例。你可以看到,输入的交谈内容被保存到了通过函数参数传递进来的 WSMessage 实例 $message的 str变量中。注: SimpleXml是一个 php的扩展,用于处理 xml文件或者字符串。 WSO2 WSF/PHP并没有规定我们必须使用哪一个 php扩展来处理 xml。你可以使用你喜欢的人和 xml php 扩展来处理,比如 domdocument, saxdom之类。
第 4行将交谈内容中的参数值提取出来,这表示服务程序需要知道如何理解这些参数,比如说参数类型之类的东西。(正常来说需要在交谈内容中说明这个参数的类型)。函数中剩下的就是正常的处理阶乘。在第六行,阶乘通过调用其他函数被计算出来。从 8到 12行,回复的交谈内容也被写好并且准被返回此内容。第 14行我们返回回复的交谈内容。
回复的交谈内容应该差不多是这样的:
<getFactorialResponse>
<result>720</result>
</getFactorialResponse>
同样的,客户端也可以用同样的方法处理回复的交谈内容:
$response = $client -> request ( $reqestPayloadString ) ;
$simplexml = new SimpleXMLElement ( $response -> str ) ;
echo "Result = " . $simplexml -> result [ 0 ] . "<br/>" ;
在第 3行,用回复的交谈内容创建了一个 SimpleXMLElement 实例。同样的 $response 也是一个 WSMessage的实例,我们可以访问他的成员变量 str,这个变量保存了 xml格式的回复的交谈内容。我们把它交给一个 SimpleXMLElement 构造函数,由此创建一个 SimpleXMLElement的实例。然后我们就可以访问结果元素 (或者叫节点? element, xml里面可以称之为元素,但对于树状结构的它来说,节点也不为过? )
现在你应该学会如何处理交谈信息中的内容,不管是客户端的申请也好还是服务端的回应也好。
注:在服务端的 getFactorial函数 (14行 ),你可以之间返回一个 WSmessage而不是一个回复的交谈内容。你可以用下面的这一小段程序来实现这个功能。
$outMessage = new WSMessage( $responsePayloadString );
return $outMessage ;
这其实也就是说服务端程序及可以返回 xml格式的交谈内容也可以返回 WSMessage的实例
完整的程序将在这篇文章的末尾附上。
跟踪消息
通过 WSO2 Web services framework for PHP ,你可以跟踪 SOAP消息被客户端发出,然后客户端又收到了来自服务端的消息,(即他们的交谈内容)。网络客户服务类, WSClient 有两个函数可以实现这个目的: getLastReauest()和 getLastResponse()。客户端在使用 request()这个函数以后,你可以通过这两个函数去得到交谈信息。
$response = $client -> request ( $reqestPayloadString ) ;
printf ( "<br/> Request = %s </br>" ,
htmlspecialchars ( $client -> getLastRequest ())) ;
printf ( "<br/> Response = %s </br>" ,
htmlspecialchars ( $client -> getLastResponse ())) ;
以上的程序片段会显示 request()这个函数实现的请求与回复的内容。
实际上,这段程序差不多会输出这样的东西:
Request = <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Header/><soapenv:Body><getFactorial> <param>6</param> </getFactorial></soapenv:Body></soapenv:Envelope>
Response = <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Header/><soapenv:Body><getFactorialResponse> <result>720</result> </getFactorialResponse></soapenv:Body></soapenv:Envelope>
跟踪 SOAP消息对于研究呼叫的服务是非常有用的,特别是对于查找服务和客户端的 bug。比如说,你可以确认所有的客户端发出的消息以及服务端回复的消息,并且,你可以确认交谈内容的格式 (客户端的以及服务端的。 )
Debugging(这个词是如此的普遍,那么我在这里就不翻译它了,尽管我的梦想是有一天程序用中文来写,显而易见的是这个梦已经离我们越来越遥远。 )
用户在使用 php WSF有时会碰到两个问题:
安装 wsf。 你怎么能确定这个 wsf已经正常工作了?好吧,第一,你可以通过 phpinfo()这个函数来检查, (要是你不知道这个函数以及怎么使用它,呃,查查 php手册吧。 ) 你只需要创建一个 php文件,并且在上面写下这几句话,然后用个浏览器打开它。
<?php
phpinfo () ;
?>
如果所有的扩展都被正确的安装的话,你会找到一个项目叫 wsf,在一个以 wsf作为标题的表里,你应当看到 'wsf support'之类的字样。这个东东是在 php.ini里定义的,(或者比如说我就没有在 php.ini 里面定义而是在 /etc/php5/conf.d/里写了一个新的文件叫做 wsf.ini,实际上这个文件夹里面所有的文件到后来都会被合并到 php.ini里,所有如果你没有在 php.ini里找到相应的设置但是你的 wsf缺能用,你不妨来这里看看。 )
如果这个扩这没有显示在 phpinfo里,那么你需要去找安装指南来好好研究一下,如果找不到可以给我发 email: ferdinandfly@yahoo.ca
当你成功的安装了以后,第二个问题就是你好像并不能让这个例子正确运行。同样的,你需要检查一些设置是否正确。 首先是 php.ini记录中,经常会设置一些日志文件的路径,也许他不存在或者是说他设定的路径 php5无法读写。还有,你应到确认 php.ini是否包含了一些脚本文件,而这些脚本文件都是可读的。
如果以上的这些都是正确的但是 wsf就是不干活,你可以查看一下日志文件。日志文件会被写到 wsf.log_path这条记录所确定的路径中。这个东东在 php.ini里进行设定。如果他没有被设定,那么 log就在 /tmp里( linux)。需要知道的是,在 windows平台中,默认的路径很可能不存在,因此你必须为他指定一个日志路径。和服务有关的日志记录在 wsf_php_server.log中,和客户端有关的保存在 wsf_php_client.log中,如果你的客户机和服务主机不是一台机器,那么这两个文件都在服务器上哦。你可以通过调节记录的等级来获得不同详细程度的日志文件。如果是调试,你可以把它设置为 level 4,当然如果是成熟的软件,你可以设置为 0(仅仅是严重错误)或者是 1(错误)。
如果你想确认来往的交谈内容( SOAP)是你所想要的格式的话,你可以用 SOAP 消息跟踪来调试,正如我们前面所讲的。
总结:
在这篇文章中,我解释了 WSMessage这个类以及怎样处理交谈内容并且使用它,客户端或者服务端都可以通过调用 str这个 WSMessage的成员变量来获得交谈内容( xml)。通常交谈内容的格式都是通过 WSDL来定义的,因此我们要求客户端和服务端需要遵守同样的格式是合理的。下一章我们会讨论如何通过 WSO2 WSF/PHP和 WSDL协同工作 .

    
[2]Discuz 6.0+ 批量注册用户名
    来源: 互联网  发布时间: 2013-11-30
1.将adduser.php复制到discuz根目录下;
/--adduser.php内容如下--/
<? php
require_once './include/common.inc.php ';
//注册的名字
$user_list = file('./username.txt ');
//注册的密码
$a = "12345678";
$pwd = md5($a);
// 注册用户数(建议一万一下)
$member_num = count($user_list);
//设置运行时间
set_time_limit(3600 );
for($i=0;$i<$member_num;$i++) {
$username = $user_list[$i];
$db->query("REPLACE INTO {$tablepre}members (username, password,regdate) VALUES ('$username', '$pwd','1175655041')");
$uid = $db->insert_id();
$db->query("INSERT INTO {$tablepre}memberfields (uid) VALUES ('$uid')");
echo $i.':'.$username."__完成<br/>";
?>
2.手工采集用户名,也放于discuz根目录下
/--username.txt内容如下--/
mouse365
大菜鸟
SHAM
确保一行一个即可!
PS:关于用户名的采集可以采用如下方法(以 http://www.freediscuz.net/bbs/member.php?action=list 为例)
1. 打开网址 http://www.freediscuz.net/bbs/member.php?action=list ;
2.复制以下信息保存到username.txt
admin 1 2003-6-7 2008-12-22 15:06 127 421
theoldmemory 3 2003-6-8 2004-8-8 23:15 0 0
lauraych 4 2003-6-9 2007-9-28 16:36 0 0
3.利用UltraEdit等编辑器执行正则匹配去掉无用信息
admin
theoldmemory
lauraych

    
[3]火车头discuz6.1 完美采集的php接口文件
    来源: 互联网  发布时间: 2013-11-30
PS:对原文件的修改较大,程序中注释已经很详尽,这里就不多说了。
代码如下:

<?php
// header('Content-Type:text/html;charset=UTF-8');
//if(function_exists("mb_convert_encoding")){
// $tmp = checkAndTranslate("使用前请将该文件直接上传至论坛根目录", 0);
// header('Content-Type:text/html;charset=UTF-8');
// print($tmp);
//}else{
// print("NO");
//}
// exit("this.line=".__line__);
/*
文件名:locoyonline_for_discuz610.php
*使用前请将该文件直接上传至论坛根目录
*本文件为GBK编码;
*处理后导入数据库的编码为:utf-8;
*需要替换字符时,需把replace.txt复制到同目录下;
*/
//处理全局变量
//foreach($_POST as $key => $value){
//$$key = $value ;
//print($key.' = '.$value.'\n');
//}
//var_dump($_POST);
//exit('end-0');
// 需要插入的数据表
// 1.cdb_threads
// 2.cdb_rewardlog // ok 悬赏记录表
// 3.cdb_mythreads
// 4.cdb_posts
// 5.cdb_tags _update
// 6.cdb_threadtags
// 7.cdb_forums _update
// 8.cdb_members _update ok 更改悬赏表
//done end !
$user_list = file('./makeuser/username.txt');
// 随机发帖的用户名单,必须是已经注册的
// 关于批量注册用户名可以参考 Discuz 6.0+ 批量注册用户名
$user_list = array_map("curlAndCopy", $user_list);
function curlAndCopy($a){
return trim($a);
}
$replyusers = implode("|",$user_list);
//处理回复的格式
function trimAndCurl(/blog_article/$str/index.html){
$str = preg_replace('/\n\s{5,}/','', $str , 1);
$str = trim($str);
$str = checkAndTranslate($str);
return $str;
}
function checkAndTranslate($mess, $if_replace =1, $in_char_type='GBK', $out_char_type='UTF-8'){
//if replace ?
if($if_replace){
$mess = curlAndReplace($mess);
}
//if chinese GBK ?
if(preg_match('/[\x80-\xff]./', $mess) ){
$mess = mb_convert_encoding($mess, $out_char_type, $in_char_type);
}
return addslashes($mess) ;
}
function curlAndReplace($message){
$replace_list = file('./makeuser/replace.txt');
foreach($replace_list as $item){
$item = preg_replace("/\s+/","||",$item);
$items = explode("||",$item);
$tmp = '<!--replace-->';
$message = str_replace($items[0],$tmp,$message);
$message = str_replace($items[1],$items[0],$message);
$message = str_replace($tmp,$items[1],$message);
}
return $message;
}
define('CURSCRIPT', 'post');
define('NOROBOT', TRUE);
require_once './include/common.inc.php';
require_once DISCUZ_ROOT.'./include/post.func.php';
$_DTYPE = $checkoption = $optionlist = array();
if($typeid) {
threadtype_checkoption();
}
require_once DISCUZ_ROOT.'./include/discuzcode.func.php';
$navigation = $navtitle = $thread = '';
//这里是新添加的代码以,开始
if ( $lid <> "locoy" )
{
// die(验证密码错误);
}
//这里是添加的代码,结束,
//rq204,Q285576545,2008.7.29
$navigation = "» <a href=/index.html"forumdisplay.php?fid=$fid".($extra ? '&'.preg_replace("/^(&)*/", '', $extra) : '')."\">$forum[name]</a> $navigation";
$navtitle = $navtitle.strip_tags($forum['name']).' - ';
if($forum['type'] == 'sub') {
$query = $db->query("SELECT name, fid FROM {$tablepre}forums WHERE fid='$forum[fup]'");
$fup = $db->fetch_array($query);
$navigation = "» <a href=/index.html"forumdisplay.php?fid=$fup[fid]\">$fup[name]</a> $navigation";
$navtitle = $navtitle.strip_tags($fup['name']).' - ';
}
$special = empty($special) || !is_numeric($special) || $special < 0 || $special > 6 ? 0 : intval($special);
$allowpostattach = !empty($forum['allowpostattach']) || (!$forum['postattachperm'] && $allowpostattach) || ($forum['postattachperm'] && forumperm($forum['postattachperm']));
$attachextensions = $forum['attachextensions'] ? $forum['attachextensions'] : $attachextensions;
$enctype = $allowpostattach ? 'enctype="multipart/form-data"' : '';
$maxattachsize_kb = $maxattachsize / 1000;
$postcredits = $forum['postcredits'] ? $forum['postcredits'] : $creditspolicy['post'];
$replycredits = $forum['replycredits'] ? $forum['replycredits'] : $creditspolicy['reply'];
$digestcredits = $forum['digestcredits'] ? $forum['digestcredits'] : $creditspolicy['digest'];
$postattachcredits = $forum['postattachcredits'] ? $forum['postattachcredits'] : $creditspolicy['postattach'];
$maxprice = isset($extcredits[$creditstrans]) ? $maxprice : 0;
$extra = rawurlencode($extra);
$blogcheck = empty($isblog) && empty($addtoblog) ? '' : 'checked="checked"';
$notifycheck = empty($emailnotify) ? '' : 'checked="checked"';
$stickcheck = empty($sticktopic) ? '' : 'checked="checked"';
$digestcheck = empty($addtodigest) ? '' : 'checked="checked"';
$subject = isset($subject) ? dhtmlspecialchars(censor(trim($subject))) : '';
$message = isset($message) ? censor(trim($message)) : '';
$readperm = isset($readperm) ? intval($readperm) : 0;
$price = isset($price) ? intval($price) : 0;
$urloffcheck = $usesigcheck = $smileyoffcheck = $codeoffcheck = $htmloncheck = $emailcheck = '';
$seccodecheck = ($seccodestatus & 4) && (!$seccodedata['minposts'] || $posts < $seccodedata['minposts']);
$secqaacheck = $secqaa['status'][2] && (!$secqaa['minposts'] || $posts < $secqaa['minposts']);
if($iscircle = $supe['status'] && $supe['circlestatus'] && $forum['status'] == 2) {
unset($forum['threadtypes']);
}
$allowpostpoll = $allowpost && $allowpostpoll && ($forum['allowpostspecial'] & 1);
$allowposttrade = $allowpost && $allowposttrade && ($forum['allowpostspecial'] & 2);
$allowpostreward = $allowpost && $allowpostreward && ($forum['allowpostspecial'] & 4) && isset($extcredits[$creditstrans]);
$allowpostactivity = $allowpost && $allowpostactivity && ($forum['allowpostspecial'] & 8);
$allowpostdebate = $allowpost && $allowpostdebate && ($forum['allowpostspecial'] & 16);
$allowpostvideo = $allowpost && $allowpostvideo && ($forum['allowpostspecial'] & 32) && $videoopen;
$allowanonymous = $forum['allowanonymous'] || $allowanonymous ? 1 : 0;
$editorid = 'posteditor';
$editoroptions = str_pad(decbin($editoroptions), 2, 0, STR_PAD_LEFT);
$editormode = $editormode == 2 ? $editoroptions{0} : $editormode;
$allowswitcheditor = $editoroptions{1};
$advanceeditor = $special ? 0 : 1;
$previewdisplay = !empty($previewpost) ? '' : 'none';
if($action == 'newthread') {
//复制newthread.inc.php
$discuz_action = 11;
if(empty($forum['fid']) || $forum['type'] == 'group') {
exit('未选择版块或版块不能发帖');
}
$isblog = empty($isblog) ? '' : 'yes';
if($subject == '' || $message == '') {
exit('标题或内容为空');
}
if($post_invalid = checkpost()) {
exit('标题或内容超过发帖限制');
}
if($allowpostattach && is_array($_FILES['attach'])) {
foreach($_FILES['attach']['name'] as $attachname) {
if($attachname != '') {
checklowerlimit($postattachcredits);
break;
}
}
}
$typeid = isset($typeid) && isset($forum['threadtypes']['types'][$typeid]) ? $typeid : 0;
$iconid = !empty($iconid) && isset($_DCACHE['icons'][$iconid]) ? $iconid : 0;
$displayorder = $modnewthreads ? -2 : (($forum['ismoderator'] && !empty($sticktopic)) ? 1 : 0);
$digest = ($forum['ismoderator'] && !empty($addtodigest)) ? 1 : 0;
$blog = $allowuseblog && $forum['allowshare'] && !empty($addtoblog) ? 1 : 0;
$readperm = $allowsetreadperm ? $readperm : 0;
$isanonymous = $isanonymous && $allowanonymous ? 1 : 0;
$price = intval($price);
$price = $maxprice && !$special ? ($price <= $maxprice ? $price : $maxprice) : 0;
//echo $typeid.','.','.','
if(!$typeid && $forum['threadtypes']['required'] && !$special) {
// exit('未填写主题分类');
}
$discuz_user=$_POST['username'];
$discuz_user = checkAndTranslate($discuz_user, 0);
$sql_tmp = "SELECT uid,password,secques FROM {$tablepre}members m WHERE m.username like '%$discuz_user%'";
$query =$db->query($sql_tmp);
if ($rs=$db->fetch_row($query)){
list($discuz_uid,$discuz_pw, $discuz_secques ) =$rs;
}
else
{
// exit('不存在的用户名'.$discuz_user);
exit('不存在的用户名'.$sql_tmp);
}
//var_dump($_POST);exit('<br />this.line='.__line__);
$messages = explode("|||",$message);
//是否需要去除对最佳答案的评论
//$messages = array_merge(array_slice($messages, 0, 2), array_slice($messages, 3));
$mc = count($messages);
$replycount = $mc -1;
$author = !$isanonymous ? $discuz_user : '';
$moderated = $digest || $displayorder > 0 ? 1 : 0;
$attachment = ($allowpostattach && $attachments = attach_upload()) ? 1 : 0;
$subscribed = !empty($emailnotify) && $discuz_uid ? 1 : 0;
$supe_pushstatus = $supe['status'] && $forum['supe_pushsetting']['status'] == 1 && !$modnewthreads ? '1' : '0';
$sgidadd1 = $sgidadd2 = '';
if($iscircle) {
$sgidadd1 = ', sgid';
$sgidadd2 = ", '$sgid'";
}
/*预处理数据*/
//$price = mt_rand(3,10);
$price = 0;
$views = mt_rand(30,256);
$timestamp = mt_rand(strtotime('2008-12-25') ,strtotime('2008-12-29'));
$tagstatus = 0;
$tags = "";
//已解决:
//$price = -$price;
//$closed = 1;
//未解决:
$closed = 0;
$db->query("INSERT INTO {$tablepre}threads (fid, readperm, price, iconid, typeid, author, authorid, subject, dateline, lastpost, lastposter, displayorder, digest, blog,attachment, subscribed, moderated, supe_pushstatus $sgidadd1 ,special ,closed ,views)
VALUES ('$fid', '$readperm', '$price', '$iconid', '$typeid', '$author', '$discuz_uid', '".checkAndTranslate($subject)."', '$timestamp', '$timestamp', '$author', '$displayorder', '$digest', '$blog', '$attachment', '$subscribed', '$moderated', '$supe_pushstatus' $sgidadd2 ,0 ,$closed ,$views )");
$tid = $db->insert_id();
// making reward logs !
$db->query("INSERT INTO {$tablepre}rewardlog (tid,authorid,netamount,dateline) VALUES ('$tid', '$discuz_uid', '$price', '0')");
// updating members logs !
//if minus credits ?
//$db->query("UPDATE {$tablepre}members SET posts=posts+1,credits=credits+$price,lastpost='".$_SERVER['REQUEST_TIME']."' WHERE uid ='$discuz_uid' ");
$db->query("UPDATE {$tablepre}members SET posts=posts+1,lastpost='".$_SERVER['REQUEST_TIME']."' WHERE uid ='$discuz_uid' ");
if($subscribed) {
$db->query("REPLACE INTO {$tablepre}subscriptions (uid, tid, lastpost, lastnotify)
VALUES ('$discuz_uid', '$tid', '$timestamp', '$timestamp')", 'UNBUFFERED');
}
$db->query("REPLACE INTO {$tablepre}mythreads (uid, tid, dateline, special) VALUES ('$discuz_uid', '$tid', '$timestamp', '0')", 'UNBUFFERED');
if($moderated) {
updatemodlog($tid, ($displayorder > 0 ? 'STK' : 'DIG'));
updatemodworks(($displayorder > 0 ? 'STK' : 'DIG'), 1);
}
if($forum['threadtypes']['special'][$typeid] && $optiondata && is_array($optiondata)) {
foreach($optiondata as $optionid => $value) {
$db->query("INSERT INTO {$tablepre}typeoptionvars (typeid, tid, optionid, value, expiration)
VALUES ('$typeid', '$tid', '$optionid', '$value', '".($typeexpiration ? $timestamp + $typeexpiration : 0)."')");
}
}
$bbcodeoff = checkbbcodes($message, !empty($bbcodeoff));
$smileyoff = checksmilies($message, !empty($smileyoff));
$parseurloff = !empty($parseurloff);
//$htmlon = bindec(($tagstatus && !empty($tagoff) ? 1 : 0).($allowhtml && !empty($htmlon) ? 1 : 0));
$htmlon = 1;
$pinvisible = $modnewthreads ? -2 : 0;
$db->query("INSERT INTO {$tablepre}posts (fid, tid, first, author, authorid, subject, dateline, message, useip, invisible, anonymous, usesig, htmlon, bbcodeoff, smileyoff, parseurloff, attachment)
VALUES ('$fid', '$tid', '1', '$discuz_user', '$discuz_uid', '$subject', '$timestamp', '".checkAndTranslate($messages[0])."', '$onlineip', '$pinvisible', '$isanonymous', '$usesig', '$htmlon', '$bbcodeoff', '$smileyoff', '$parseurloff', '$attachment')");
$pid = $db->insert_id();
if($tagstatus && $tags != '') {
$tags = str_replace(array(chr(0xa1).chr(0xa1), chr(0xa1).chr(0x40), chr(0xe3).chr(0x80).chr(0x80)), ' ', $tags);
$tagarray = array_unique(explode(' ', censor($tags)));
$tagcount = 0;
foreach($tagarray as $tagname) {
$tagname = trim($tagname);
if(preg_match('/^([\x7f-\xff_-]|\w){3,20}$/', $tagname)) {
$query = $db->query("SELECT closed FROM {$tablepre}tags WHERE tagname='".checkAndTranslate($tagname, 0)."'");
if($db->num_rows($query)) {
if(!$tagstatus = $db->result($query, 0)) {
$db->query("UPDATE {$tablepre}tags SET total=total+1 WHERE tagname='".checkAndTranslate($tagname, 0)."'", 'UNBUFFERED');
}
} else {
$db->query("INSERT INTO {$tablepre}tags (tagname, closed, total)
VALUES ('".checkAndTranslate($tagname, 0)."', 0, 1)", 'UNBUFFERED');
$tagstatus = 0;
}
if(!$tagstatus) {
$db->query("INSERT {$tablepre}threadtags (tagname, tid) VALUES ('".checkAndTranslate($tagname, 0)."', $tid)", 'UNBUFFERED');
}
$tagcount++;
if($tagcount > 4) {
unset($tagarray);
break;
}
}
}
}
$tradeaid = 0;
if($attachment) {
$searcharray = $pregarray = $replacearray = array();
foreach($attachments as $key => $attach) {
$db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, price, filename, description, filetype, filesize, attachment, downloads, isimage, uid, thumb, remote)
VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[price]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0', '$attach[isimage]', '$attach[uid]', '$attach[thumb]', '$attach[remote]')");
$searcharray[] = '[local]'.$localid[$key].'[/local]';
$pregarray[] = '/\[localimg=(\d{1,3}),(\d{1,3})\]'.$localid[$key].'\[\/localimg\]/is';
$replacearray[] = '[attach]'.$db->insert_id().'[/attach]';
}
$message = str_replace($searcharray, $replacearray, preg_replace($pregarray, $replacearray, $message));
$db->query("UPDATE {$tablepre}posts SET message='".checkAndTranslate($message, 0)."' WHERE pid='$pid'");
updatecredits($discuz_uid, $postattachcredits, count($attachments));
}
if($iscircle && $sgid) {
supe_dbconnect();
$query = $supe['db']->query("UPDATE {$supe[tablepre]}groups SET lastpost='$timestamp' WHERE gid='$sgid'", 'SILENT');
}
if($modnewthreads) {
$db->query("UPDATE {$tablepre}forums SET todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
} else {
if($digest) {
foreach($digestcredits as $id => $addcredits) {
$postcredits[$id] = (isset($postcredits[$id]) ? $postcredits[$id] : 0) + $addcredits;
}
}
updatepostcredits('+', $discuz_uid, $postcredits);
$subject = str_replace("\t", ' ', $subject);
$lastpost = "$tid\t".checkAndTranslate($subject)."\t$timestamp\t$author";
$db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost', threads=threads+1, posts=posts+1, todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
if($forum['type'] == 'sub') {
$db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost' WHERE fid='$forum[fup]'", 'UNBUFFERED');
}
}
echo("成功发表主题|".$tid);
}
if($replycount)
{
//开始发布回复
$discuz_action = 12;
require_once DISCUZ_ROOT.'./include/forum.func.php';
print_r($replyuser);
$replyusers = explode("|",$replyusers);
$reusercount = count($replyusers);
for($re=1;$re<=$replycount;$re++)
{
$index = mt_rand(1,$reusercount-1);
while( in_array( $index ,$post_arr ) || $replyusers[$index] ==$_POST['username'] ){
$index = mt_rand(1,$reusercount-1);
}
$post_arr[] = $index;
$discuz_user = $replyusers[$index];
$discuz_user = checkAndTranslate($discuz_user, 0);
$query =$db->query("SELECT uid,password,secques FROM {$tablepre}members m WHERE m.username like '%$discuz_user%'");
if ($rs=$db->fetch_row($query)){
list($discuz_uid,$discuz_pw, $discuz_secques ) =$rs;
}
else
{
echo('不存在的用户名'.$discuz_user);
continue;
}
$attachnum = 0;
if($allowpostattach && !empty($_FILES['attach']) && is_array($_FILES['attach'])) {
foreach($_FILES['attach']['name'] as $attachname) {
if($attachname != '') {
$attachnum ++;
}
}
$attachnum && checklowerlimit($postattachcredits, $attachnum);
} else {
$_FILES = array();
}
$attachments = $attachnum ? attach_upload() : array();
$attachment = empty($attachments) ? 0 : 1;
$subscribed = $thread['subscribed'] && $timestamp - $thread['lastpost'] < 7776000;
$newsubscribed = !empty($emailnotify) && $discuz_uid;
if($subscribed && !$modnewreplies) {
$db->query("UPDATE {$tablepre}subscriptions SET lastpost='$timestamp' WHERE tid='$tid' AND uid<>'$discuz_uid'", 'UNBUFFERED');
}
if($newsubscribed) {
$db->query("REPLACE INTO {$tablepre}subscriptions (uid, tid, lastpost, lastnotify)
VALUES ('$discuz_uid', '$tid', '".($modnewreplies ? $thread['lastpost'] : $timestamp)."', '$timestamp')", 'UNBUFFERED');
}
$bbcodeoff = checkbbcodes($message, !empty($bbcodeoff));
$smileyoff = checksmilies($message, !empty($smileyoff));
$parseurloff = !empty($parseurloff);
// $htmlon = $allowhtml && !empty($htmlon) ? 1 : 0;
$htmlon = 1;
$usesig = !empty($usesig) ? 1 : 0;
$isanonymous = $allowanonymous && !empty($isanonymous)? 1 : 0;
//$discuz_user = checkAndTranslate($discuz_user, 0);
$author = empty($isanonymous) ? $discuz_user : '';
$pinvisible = $modnewreplies ? -2 : 0;
$rand_time = mt_rand(150,3600);
$timestamp = $timestamp + $rand_time;
$db->query("INSERT INTO {$tablepre}posts (fid, tid, first, author, authorid, subject, dateline, message, useip, invisible, anonymous, usesig, htmlon, bbcodeoff, smileyoff, parseurloff, attachment)
VALUES ('$fid', '$tid', '0', '$discuz_user', '$discuz_uid', '', '$timestamp', '".trimAndCurl(/blog_article/$messages[$re]/index.html)."', '$onlineip', '$pinvisible', '$isanonymous', '$usesig', '$htmlon', '$bbcodeoff', '$smileyoff', '$parseurloff', '$attachment')");
$pid = $db->insert_id();
// updating reward logs
$db->query("UPDATE {$tablepre}rewardlog SET answererid='$discuz_uid',dateline='$timestamp' WHERE tid='$tid'");
// updating members logs !
if($re == 1){
//添加积分问题
$db->query("UPDATE {$tablepre}members SET posts=posts+1,credits=credits+$price,lastpost='".$_SERVER['REQUEST_TIME']."' WHERE uid ='$discuz_uid' ");
}else{
$db->query("UPDATE {$tablepre}members SET posts=posts+1,lastpost='".$_SERVER['REQUEST_TIME']."' WHERE uid ='$discuz_uid' ");
}
$db->query("REPLACE INTO {$tablepre}myposts (uid, tid, pid, position, dateline, special) VALUES ('$discuz_uid', '$tid', '$pid', '".($thread['replies'] + 1)."', '$timestamp', '0')", 'UNBUFFERED');
$tradeaid = 0;
if($attachment) {
$searcharray = $pregarray = $replacearray = array();
foreach($attachments as $key => $attach) {
$db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, price, filename, description, filetype, filesize, attachment, downloads, isimage, uid, thumb, remote)
VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[price]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0', '$attach[isimage]', '$attach[uid]', '$attach[thumb]', '$attach[remote]')");
$searcharray[] = '[local]'.$localid[$key].'[/local]';
$pregarray[] = '/\[localimg=(\d{1,3}),(\d{1,3})\]'.$localid[$key].'\[\/localimg\]/is';
$insertid = $db->insert_id();
$replacearray[] = '[attach]'.$insertid.'[/attach]';
}
if(!empty($trade) && $thread['special'] == 2 && !empty($_FILES['tradeattach']['tmp_name'][0])) {
$tradeaid = $insertid;
}
$message = str_replace($searcharray, $replacearray, preg_replace($pregarray, $replacearray, $message));
$db->query("UPDATE {$tablepre}posts SET message='".checkAndTranslate($message)."' WHERE pid='$pid'");
updatecredits($discuz_uid, $postattachcredits, count($attachments));
}
if($modnewreplies) {
$db->query("UPDATE {$tablepre}forums SET todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
if($newsubscribed) {
$db->query("UPDATE {$tablepre}threads SET subscribed='1' WHERE tid='$tid'", 'UNBUFFERED');
}
} else {
$db->query("UPDATE {$tablepre}threads SET lastposter='$author', lastpost='$timestamp', replies=replies+1 ".($attachment ? ', attachment=\'1\'' : '').", subscribed='".($subscribed || $newsubscribed ? 1 : 0)."' WHERE tid='$tid'", 'UNBUFFERED');
updatepostcredits('+', $discuz_uid, $replycredits);
$lastpost = "$thread[tid]\t".checkAndTranslate($thread['subject'])."\t$timestamp\t$author";
$db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost', posts=posts+1, todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
if($forum['type'] == 'sub') {
$db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost' WHERE fid='$forum[fup]'", 'UNBUFFERED');
}
}
echo "成功回复";
}
}
//exit('Run end.this.line='.__line__);

    
最新技术文章:
▪PHP函数microtime()时间戳的定义与用法
▪PHP单一入口之apache配置内容
▪PHP数组排序方法总结(收藏)
▪php数组排序方法大全(脚本学堂整理奉献)
▪php数组排序的几个函数(附实例)
▪php二维数组排序(实例)
▪php根据键值对二维数组排序的小例子
▪php验证码(附截图)
▪php数组长度的获取方法(三个实例)
▪php获取数组长度的方法举例
▪判断php数组维度(php数组长度)的方法
▪php获取图片的exif信息的示例代码
▪PHP 数组key长度对性能的影响实例分析
▪php函数指定默认值的方法示例
▪php提交表单到当前页面、提交表单后页面重定...
▪php四舍五入的三种实现方法
▪php获得数组长度(元素个数)的方法
▪php日期函数的简单示例代码
▪php数学函数的简单示例代码
▪php字符串函数的简单示例代码
▪php文件下载代码(多浏览器兼容、支持中文文...
▪php实现文件下载、支持中文文件名的示例代码...
▪php文件下载(防止中文文件名乱码)的示例代码
▪解决PHP文件下载时中文文件名乱码的问题
▪php数组去重(一维、二维数组去重)的简单示例
▪php小数点后取两位的三种实现方法
▪php Redis 队列服务的简单示例
▪PHP导出excel时数字变为科学计数的解决方法
▪PHP数组根据值获取Key的简单示例
▪php数组去重的函数代码示例
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3