【问题标题】:Post to SMF Forum via PHP通过 PHP 发布到 SMF 论坛
【发布时间】:2016-04-11 08:51:19
【问题描述】:

我正在构建一个支持网站的 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 数据库表以及 post() 和 post2() 函数后,似乎在发布帖子时涉及多个表。以前有人概述过吗?

我已经研究过自定义表单 Mod 等解决方案,但这些表单和模板并不是我想要的。我已经将数据输入并发布到变量中,我只需要正确的表格将其插入,以便它出现在论坛上。

提前感谢您的帮助!

【问题讨论】:

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


    【解决方案1】:

    来源: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 必须直接是原始文件,复制它们并不能解决问题。

    【讨论】:

      猜你喜欢
      • 2011-11-09
      • 2022-11-10
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      • 1970-01-01
      • 2022-01-17
      相关资源
      最近更新 更多