您的位置:首页 > 其它

discuz脚本发表帖子

2013-04-16 15:11 393 查看
$db = mysql_connect("", "", "") or die("not connected");
mysql_query("set NAMES utf8", $db);
$clientip = $_SERVER["REMOTE_ADDR"];
$time = time();
$subject = "还在为大大的毛孔烦恼?";
$message = <<<EOF
还在为油光光的皮肤懊恼?
还在为这些美丽路上的“绊脚石”忧愁?
现在,就是扫除那些美丽困扰的时刻了
快快参与媲美的新一轮微博活动
让毛孔藏起来,美丽心情走起来

【活动时间】

2012.12.11-2012.12.27  a.m12:00

【评奖规则】

本次活动同一账号发帖次数不限
2012年12月27号活动结束后
随机抽取5位网友获得 贝德玛净妍毛孔修护乳

【奖品特点】

贝德玛净妍毛孔修护乳

皮脂调节净化专利,有助于保持毛孔畅通,使用后皮肤不再油光;
具有收缩毛孔的功效,减少皮脂的生成;
甘露醇与银杏叶提取物 保护皮肤受到自由基的侵害,让皮肤恢复自然光泽。
EOF;

$tid = to_bbs($subject, $message);
echo "<a href='http://www.aa.com/bbs/thread-$tid-1-1.html' target='_blank'>http://www.aa.com/bbs/thread-$tid-1-1.html</a>";

function to_bbs($subject, $message) {
global $db;
global $clientip;
global $time;
mysql_select_db('aa', $db) or die('数据库连接失败,请检查数据库名');
$fid = 11; //板块id
$author = '11'; //用户名
$authorid = '111'; //用户uid
$res = mysql_query("SELECT `modnewposts` FROM `pre_forum_forum` WHERE fid='$fid'", $db); //论坛板块设置,是否审核主题贴
$modnewthreads = mysql_result($res, 0); //是否审核主题贴
$displayorder = $modnewthreads ? -2 : 0;
$pinvisible = $modnewthreads ? -2 : 0;
$message = portal_threadcode($message); //将html标签转成规范的discuz标签

/** 插入主题表 * */
$sql = "INSERT INTO pre_forum_thread (`fid`, `posttableid`, `readperm`, `price`, `typeid`, `sortid`, `author`, `authorid`, `subject`, `dateline`, `lastpost`, `lastposter`, `displayorder`, `digest`, `special`, `attachment`, `moderated`, `status`, `isgroup`, `replycredit`, `closed`, `allowinvitation`)
VALUES ('$fid', '0', '0', '0', '0', '0', '$author', '$authorid', '$subject','$time' , '$time', '$author', $displayorder, '0', '0', '0', '0', '32', '0', '0', '0', '0')";
mysql_query($sql, $db);

/** 返回的帖子ID * */
$tid = mysql_insert_id();

/** 插入帖子表 * */
$sql = "INSERT INTO pre_forum_post_tableid (`pid` )VALUES ('null')";
mysql_query($sql, $db);
$pid = mysql_insert_id();
$sql = "INSERT INTO pre_forum_post (`pid`, `fid`, `tid`, `first`, `author`, `authorid`, `subject`, `dateline`, `message`, `useip`, `invisible`, `anonymous`, `usesig`, `htmlon`, `bbcodeoff`, `smileyoff`, `parseurloff`, `attachment`, `tags`, `replycredit`, `status`)
VALUES ('$pid', '$fid' , '$tid', '1', '$author', '$authorid', '$subject', '$time', '$message' , '$clientip', '$pinvisible', '0', '1', '0', '0', '-1', '0', '0', '', '0', '0')";
mysql_query($sql, $db);

if ($modnewthreads) {
/** 增加到审核库 * */
$sql = "REPLACE INTO `pre_common_moderate` set `id`='$tid',`idtype`='tid',`status`='0',`dateline`='$time'";
mysql_query($sql, $db);
/** 更新版块信息 * */
$sql = "UPDATE `pre_forum_forum` SET `todayposts`=`todayposts`+1 WHERE `fid`='$fid'";
mysql_query($sql, $db);
} else {
/** 更新版块信息 * */
$subject = str_replace("\t", ' ', $subject);
$lastpost = "$tid\t$subject\t$time\t$author";
$sql = "UPDATE `pre_forum_forum` SET `lastpost`='$lastpost', `threads`=`threads`+1, `posts`=`posts`+1, `todayposts`=`todayposts`+1 WHERE `fid`='$fid'";
mysql_query($sql, $db);
}
return $tid;
}

/*
* html标签 转换为discuzcode
*/

function portal_threadcode($message) {

$msglower = strtolower($message);
$message = str_replace(
array(
'</font>', '</p>', '<b>', '</b>', '<strike>', '</strike>', '<hr class="l" />', '<i class="pstatus">', '<i>',
'</i>', '<u>', '</u>', '<ul>', '<ul type="1" class="litype_1">', '<ul type="a" class="litype_2">',
'<ul type="A" class="litype_3">', '<li>', '</li>', '</ul>', '<blockquote>', '</blockquote>', '</span>', '<p>', '</div>', '<div>', ' ', '&', '<', '>', '"', ''', '<BR>', '<br>', '</P>', '<P>',
), array(
'[/font]', '[/align]', '', '', '[s]', '[/s]', '[hr]',
'[i=s]', '', '', '', '', '[list]', '[list=1]', '[list=a]',
'[list=A]', "\r\n[*]", '[*]', '[/list]', '[indent]', '[/indent]', '[/float]', '[/align]', ' ', ' ', ' ', '&', '<', '>', '"', "'", "\n", "\n", '[/align]', '[/align]',
), preg_replace(
array(
"/<font\s+color=\"([#\w]+?)\">/i",
"/<font\s+style=\"color:(rgb\([\d\s,]+?\))\">/i",
"/<font\s+style=\"background-color:([#\w]+?)\">/i",
"/<font\s+style=\"background-color:(rgb\([\d\s,]+?\))\">/i",
"/<font\s+size=\"(\d{1,2}?)\">/i",
"/<font\s+style=\"font-size:(\d{1,2}(\.\d{1,2}+)?(px|pt)+?)\">/i",
"/<font\s+face=\"([^\[\<]+?)\">/i",
"/<p\s+align=\"(left|center|right)\">/i",
"/<div\s+align=\"(left|center|right)\">/i",
"/<p\s+style=\"line-height:(\d{1,2}|null)px;text-indent:(\d{1,2}|null)em;text-align:(left|center|right)\">/i",
"/<span\s+style=\"float:left;margin-right:5px\">/i",
"/<span\s+style=\"float:right;margin-left:5px\">/i",
"/###NextPage###/i",
"/###NextPage\[title\=([\w\W]+?)\]###/i",
"/<p\s+style=\"text-align:\s+(left|center|right);\">/i",
"/<p\s+align=(left|center|right)>/i",
'/<script\s+type=\"text\/javascript\"(.*?)<\/script>/i',
), array(
"[color=\\1]",
"[color=\\1]",
"[backcolor=\\1]",
"[backcolor=\\1]",
"[size=\\1]",
"[size=\\1]",
"[font=\\1]",
"[align=\\1]",
"[align=\\1]",
"[p=\\1, \\2, \\3]",
"[float=left]",
"[float=right]",
"\n",
"[align=left]\\1[/align]",
"[align=\\1]",
"[align=\\1]",
"",
), $message
)
);

/* img标签 */
preg_match_all('/<a(.*?)>(.*?)<(img|IMG)(.*?)src=\"(.*?)\"(.*?)>(.*?)<\/a>/ix', $message, $match);

if ($match[0]) {
$match[5] = is_array($match[5]) ? $match[5] : array($match[5]);
$match[0] = is_array($match[0]) ? $match[0] : array($match[0]);
$match[5] = array_map('reimg', $match[5]);

$message = str_replace($match[0], $match[5], $message);

$match = array();
}

preg_match_all('/<(img|IMG)(.*?)src=\"(.*?)\"(.*?)>/isx', $message, $match);
if ($match[0]) {
$match[3] = is_array($match[3]) ? $match[3] : array($match[3]);
$match[0] = is_array($match[0]) ? $match[0] : array($match[0]);
$match[3] = array_map('reimg', $match[3]);
$message = str_replace($match[0], $match[3], $message);
$match = array();
}

/* 链接 */
$message = preg_replace(
array("/<a\s+href=\"(.*?)\"(.*?)>(.*?)<\/a>/i"), array("\\3"), $message
);
/* 音频视频 */
if (strpos($msglower, "[/flash]") != false) {
preg_match_all('/\[flash=(.*?)\](.*?)\[\/flash\]/isx', $message, $match);
$match[0] = is_array($match[0]) ? $match[0] : array($match[0]);
$match[1] = is_array($match[1]) ? $match[1] : array($match[1]);
$match[2] = is_array($match[2]) ? $match[2] : array($match[2]);
$revideo = array();
foreach ($match[0] as $key => $value) {
$revideo[$key] = portalpvideo($match[1][$key], $match[2][$key]);
}
$message = str_replace($match[0], $revideo, $message);
//$message = preg_replace('/\[flash=(.*?)\](.*?)\[\/flash\]/isx',"portalpvideo('\\1','\\2')",$message);
}
/* 解析源码视频 */
if (strpos($msglower, "</object>") != false) {
preg_match_all('/<object(.*?)width=\"(\d+)\"\s+height=\"(\d+)\">([\w\W]*?)src=\"(.*?)\"([\w\W]*?)<\/object>/isx', $message, $match);
$match[0] = is_array($match[0]) ? $match[0] : array($match[0]);
$match[2] = is_array($match[2]) ? $match[2] : array($match[2]);
$match[3] = is_array($match[3]) ? $match[3] : array($match[3]);
$match[5] = is_array($match[5]) ? $match[5] : array($match[5]);
$revideo = array();
foreach ($match[0] as $key => $value) {
$revideo[$key] = portalpvideo2($match[2][$key], $match[3][$key], $match[5][$key]);
}
$message = str_replace($match[0], $revideo, $message);
}
$message = strip_tags($message);

return $message;
}

/*
* 更改img标签
*/

function reimg($img) {
return "";
}

/*
* 解析文章中的视频为discuzcode
*/

function portalpvideo($param, $url) {

if (strtolower($param) == 'media' or strtolower($param) == 'real') {
$ext = substr(strrchr($url, '.'), 1);
return "[media=" . $ext . ",500,375]" . $url . "[/media]";
} elseif (strtolower($param) == 'mp3') {
return "[audio]" . $url . "[/audio]";
} else {
return "" . $url . "";
}
}

/*
* 解析源码视频
*/

function portalpvideo2($width, $height, $url) {
$ext = substr(strrchr($url, '.'), 1);
return "[media=" . $ext . "," . $width . "," . $height . "]" . $url . "[/media]";
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: