您现在的位置是:首页 > 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系统开发。突出多语言支持和国际化布局,三级栏目结构清晰展示产品分类,响应式设计确保更好客户在移动端和PC端获得一致的专业体验。查看源码
  • 响应式电脑维修办公用品维护pbootcms网站模板模板介绍(自适应手机版)响应式电脑修理公司pbootcms网站模板-蓝色HTML5电脑修理维修店网站源码下载PbootCMS内核开发的营销型网站模板,该模查看源码
  • (PC+WAP)红色厨具厨房用品设备pbootcms模板源码下载为厨具设备企业设计的响应式网站模板,采用PbootCMS内核开发,适用于商用厨房设备、家用厨具、厨房用品等企业展示。模板包含产品展示、新闻动态、案例中心等标准模块,助您快速搭建专业级行业网站。查看源码
  • (自适应)调节阀门气动球阀控制阀网站模板源码下载为调节阀门、气动球阀等工业设备企业打造的响应式网站模板,基于PbootCMS系统开发。突出产品参数展示与技术文档管理功能,通过专业化的布局设计有效呈现工业设备特性,适配各类终端访问需求。查看源码
  • (自适应手机端)seo博客网站模板新闻资讯网站源码下载本模板为SEO博客及新闻资讯类平台深度定制,采用PbootCMS内核开发。通过模块化设计实现多行业快速适配,仅需替换图文内容即可转型为医疗、教育、科技等领域网站。响应式布局确保在手机、平板等设备上获得一致浏览体验。查看源码
  • (自适应)餐具英文外贸生活用品带下载功能网站模板免费下载为餐具及生活用品外贸企业打造的响应式网站模板,基于PbootCMS内核开发。突出产品展示与多语言支持特性,通过自适应设计确保更好客户在手机、平板、电脑等设备上获得一致浏览体验。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐