通过PHP发布到SMF论坛

时间:2016-01-07 03:57:08

标签: forum smf smf-forum simple-machines-forum

我正在构建一个支持包含SMF论坛(2.0.11)的网站的CMS。 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数据库表和post()和post2()函数进行挖掘,似乎在发布帖子时涉及多个表。有没有人在此之前概述过这个?

我已经研究过自定义表单模式等解决方案,但这些表单和模板并不是我想要的。我已经输入了数据并对变量进行了POST操作,我只需要使用正确的表格将其插入到论坛中即可。

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

来源: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包括必须是原始的直接,复制它们并不是诀窍。

相关问题