您现在的位置是:首页 > cms教程 > Discuz教程Discuz教程

discuz脚本发表帖子的方法

海云2025-07-10Discuz教程已有人查阅

导读还在为油光光的皮肤懊恼?还在为这些美丽路上的“绊脚石”忧愁?现在,就是扫除那些美丽困扰的时刻了快快参与媲美的新一轮微博活动让毛孔藏起来,美丽心情走起来

$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.27a.m12:00
【评奖规则】
本次活动同一账号发帖次数不限
2012年12月27号活动结束后
随机抽取5位网友获得 贝德玛净妍毛孔修护乳
【奖品特点】
贝德玛净妍毛孔修护乳
皮脂调节净化专利,有助于保持毛孔畅通,使用后皮肤不再油光;
具有收缩毛孔的功效,减少皮脂的生成;
甘露醇与银杏叶提取物 保护皮肤受到自由基的侵害,让皮肤恢复自然光泽。
EOF;
$tid = to_bbs($subject, $message);
echo "<a href='http:// .aa.com/bbs/thread-$tid-1-1.html' target='_blank'>http:// .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>', ' ', '&', '<', '>', '"', '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(
"",
"",
"[backcolor=\\1]",
"[backcolor=\\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 "";
} else {
return "" . $url . "";
}
}
/*
* 解析源码视频
*/
function portalpvideo2($width, $height, $url) {
$ext = substr(strrchr($url, '.'), 1);
return "[media=" . $ext . "," . $width . "," . $height . "]" . $url . "[/media]";
}

本文标签:

很赞哦! ()

相关源码

  • (响应式)企业管理人力资源服务类pbootcms模板源码下载为人力资源服务及企业管理设计的响应式网站模板,基于PbootCMS内核开发。通过宽屏布局优化岗位展示效果,简洁界面聚焦人才服务核心业务,自适应技术确保在PC端与手机端查看源码
  • (PC+WAP)地暖热水器烘干机节能设备网站模板下载为地暖热水器及节能设备企业设计的PbootCMS网站模板,集成产品展示、节能方案介绍、技术参数说明等专业模块。采用PC与移动端同步响应架构查看源码
  • 手机软件APP游戏软件下载网站Pbootcms模板(自适应)基于PbootCMS内核深度开发的网站模板,为移动互联网时代打造。无论是手机APP推广、游戏软件展示,还是各类企业官网需求,本模板都能通过简单的图文替换实现行业无缝切换查看源码
  • (自适应)HTML5响应式双语绿色物流运输快递货运pbootcms源码本款基于PbootCMS开发的网站模板为物流运输、快递货运行业设计,采用HTML5技术构建,支持简繁字体切换。模板设计充分考虑了货运物流行业的特点,可专业展示运输服务、物流网络和业务优势等内容。查看源码
  • (自适应)蓝色英文外贸电子科技产品带三级栏目网站模板为外贸企业设计的英文网站模板,基于PbootCMS系统开发。突出多语言支持和国际化布局,三级栏目结构清晰展示产品分类,响应式设计确保更好客户在移动端和PC端获得一致的专业体验。查看源码
  • 自适应车行汽车租赁二手车行业企业网站模板为汽车租赁与二手车交易场景深度优化,采用PbootCMS内核开发,聚焦车辆展示、租赁流程与服务介绍三大核心模块。响应式布局确保PC与移动端数据实时同步,后台一键管理车辆信息查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐