我正在构建一个支持网站的CMS,该网站还包含SMF论坛(2.0.11)。CMS中的一个模块涉及跟踪出席情况的"报告"。该数据被查询到smf之外但在同一数据库中的表。除了它现在所做的,我还希望在SMF论坛的特定董事会上发布一篇包含格式化内容的帖子。由于所有的帖子都包含在数据库中,这当然是可能的,但它似乎比表中的一行更重要。
用最简单的代码来说,下面是我在页面上单击"提交"时希望发生的事情。
$title = "2015-03-04 - Attendance";
$author = "KGrimes";
$body = "Attendance was good.";
$SQL = "INSERT INTO smf_some_table (title, author, body) VALUES ($title, $author, $body)";
$result = mysqli_query($db_handle, $SQL);
在深入研究了smf DB表以及post()和post2()函数之后,在发布post时,似乎涉及到多个表。以前有人概述过这一点吗?
我已经研究过诸如Custom Form Mod之类的解决方案,但这些表单和模板不是我想要的。我已经输入了数据并将其发布到变量中,我只需要正确的表将其插入,以便它出现在论坛上。
提前感谢您的帮助!
来源:http://www.simplemachines.org/community/index.php?topic=542521.0
你想创建帖子的代码:
//Define variables
//msgOptions
$smf_subject = "Test Title";
//Handle & escape
$smf_subject = htmlspecialchars($smf_subject);
$smf_subject = quote_smart($smf_subject, $db_handle);
$smf_body = "This is a test.";
//Handle & escape
$smf_body = htmlspecialchars($smf_body);
$smf_body = quote_smart($smf_body, $db_handle);
//topicOptions
$smf_board = 54; //Any board id, found in URL
//posterOptions
$smf_id = 6; //any id, this is found as ID in memberlist
//SMF Post function
require_once('../../forums/SSI.php');
require_once('../../forums/Sources/Subs-Post.php');
//createPost($msgOptions, $topicOptions, $posterOptions);
// Create a post, either as new topic (id_topic = 0) or in an existing one.
// The input parameters of this function assume:
// - Strings have been escaped.
// - Integers have been cast to integer.
// - Mandatory parameters are set.
// Collect all parameters for the creation or modification of a post.
$msgOptions = array(
'subject' => $smf_subject,
'body' => $smf_body,
//'smileys_enabled' => !isset($_POST['ns']),
);
$topicOptions = array(
//'id' => empty($topic) ? 0 : $topic,
'board' => $smf_board,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => $smf_id,
);
//Execute SMF post
createPost($msgOptions, $topicOptions, $posterOptions);
这将创建最简单的帖子,标题和正文由您定义,以及位置和作者。更多参数可以在createPost的SMF函数数据库中找到。包含的SSI和Subs-Post.php必须是直接的原始文件,复制它们不会起到任何作用。