无法通过代码将主题发布到phpbb-forum

时间:2014-02-26 13:45:43

标签: php post phpbb

我想知道为什么这段代码不会向论坛提交新主题。

<?php
    define('IN_PHPBB', true);
    $phpbb_root_path = '../PHPBB3/';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);

    include($phpbb_root_path . 'common.' . $phpEx);
    include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
    include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
    include '/phpBB3/includes/functions_posting.php';

    function unhtmlentities($string)
   {
      // replace numeric entities
      $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
      $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string);
      // replace literal entities
      $trans_tbl = get_html_translation_table(HTML_ENTITIES);
      $trans_tbl = array_flip($trans_tbl);
      return strtr($string, $trans_tbl);
   }

    /*   //debug - uncomment for testing
        $_POST["username"] = "username";
        $_POST["password"] = "password";
        $_POST["title"] = "thread title";
        $_POST["text"] = "thread comment";
        $_POST["forumid"] = 24; //this is the forum id you wanna post to (required for a reply too)
        $_POST["topicid"] = ''; //if you wanna submit a reply to a thread add topic id here
    */

    $title = htmlspecialchars($_POST['title']);
    $name = htmlspecialchars($_POST['name']);
    $text = htmlspecialchars($_POST['description']);
    $Prioritet = $_POST['priority'];
    $Typ = $_POST['type'];
    $text = utf8_normalize_nfc($text);

    $poll = $uid = $bitfield = $options = '';
    generate_text_for_storage($text, $uid, $bitfield, $bbcode_options, false, false, false);

    $subject = utf8_normalize_nfc($title);
    $username = utf8_normalize_nfc($name);
    $data = array( 
    // General Posting Settings
    'forum_id'            => 2,    // The forum ID in which the post will be placed. (int)
    'topic_id'            => 0,    // Post a new topic or in an existing one? Set to 0 to create a new one, if not, specify your topic ID here instead.
    'icon_id'            => false,    // The Icon ID in which the post will be displayed with on the viewforum, set to false for icon_id. (int)

    // Defining Post Options
    'enable_bbcode'    => true,    // Enable BBcode in this post. (bool)
    'enable_smilies'    => false,    // Enabe smilies in this post. (bool)
    'enable_urls'        => true,    // Enable self-parsing URL links in this post. (bool)
    'enable_sig'        => true,    // Enable the signature of the poster to be displayed in the post. (bool)

    // Message Body
    'message'            => $text,        // Your text you wish to have submitted. It should pass through generate_text_for_storage() before this. (string)
    'message_md5'    => md5($text),// The md5 hash of your message

    // Values from generate_text_for_storage()
    'bbcode_bitfield'    => $bitfield,    // Value created from the generate_text_for_storage() function.
    'bbcode_uid'        => $uid,        // Value created from the generate_text_for_storage() function.

    // Other Options
    'post_edit_locked'    => 1,        // Disallow post editing? 1 = Yes, 0 = No
    'topic_title'        => $subject,    // Subject/Title of the topic. (string)

    // Email Notification Settings
    'notify_set'        => false,        // (bool)
    'notify'            => false,        // (bool)
    'post_time'         => 0,        // Set a specific time, use 0 to let submit_post() take care of getting the proper time (int)
    'forum_name'        => '',        // For identifying the name of the forum in a notification email. (string)

    // Indexing
    'enable_indexing'    => true,        // Allow indexing the post? (bool)

    // 3.0.6
    'force_approved_state'    => true, // Allow the post to be submitted without going into unapproved queue

    // 3.1-dev, overwrites force_approve_state
    'force_visibility'            => true, // Allow the post to be submitted without going into unapproved queue, or make it be deleted
    );

    submit_post('post', $subject, $username, POST_NORMAL, $poll, $data, [$update_message = true]);
?>

现在,它只显示一个白页而不是我上面的html代码,论坛上没有新帖子。想知道它必须是PHP代码中的东西,但似乎无法找到错误。我很感激我能得到的所有答案!

编辑:问题出在submit_post函数中。也许链接错误或缺少变量?

编辑2:编辑的代码。现在唯一的问题是文本不会在论坛上发布!

编辑3:这是错误日志:警告:include(../ PHPBB3 / common.php):无法打开流:/www/webvol11/jc/87yqo3f2oz6gicm/baaw.se/中没有此类文件或目录第15行的public_html / phpBB3 / formhandled.php

警告:include():无法在/ www / webvol11 / jc / 87yqo3f2oz6gicm / baaw中打开'../PHPBB3/common.php'(include_path ='。:/ usr / local / share / pear')第15行的.se / public_html / phpBB3 / formhandled.php

警告:include(../ PHPBB3 / includes / functions_posting.php):无法打开流:/www/webvol11/jc/87yqo3f2oz6gicm/baaw.se/public_html/phpBB3/formhandled.php中没有此类文件或目录第16行

警告:include():无法在/ www / webvol11 / jc / 87yqo3f2oz6gicm中打开'../PHPBB3/includes/functions_posting.php'(include_path ='。:/ usr / local / share / pear')第16行/baaw.se/public_html/phpBB3/formhandled.php

警告:include(../ PHPBB3 / includes / message_parser.php):无法打开流:/www/webvol11/jc/87yqo3f2oz6gicm/baaw.se/public_html/phpBB3/formhandled.php中没有此类文件或目录第17行

警告:include():无法在/ www / webvol11 / jc / 87yqo3f2oz6gicm中打开'../PHPBB3/includes/message_parser.php'(include_path ='。:/ usr / local / share / pear')第17行/baaw.se/public_html/phpBB3/formhandled.php

警告:include(/baaw.se/public_html/phpBB3/includes/functions_posting.php):无法打开流:/www/webvol11/jc/87yqo3f2oz6gicm/baaw.se/public_html/phpBB3中没有此类文件或目录第18行的/formhandled.php

警告:include():在/ www / webvol11中打开'/baaw.se/public_html/phpBB3/includes/functions_posting.php'以包含(include_path ='。:/ usr / local / share / pear')失败第18行/jc/87yqo3f2oz6gicm/baaw.se/public_html/phpBB3/formhandled.php

致命错误:在第45行的/www/webvol11/jc/87yqo3f2oz6gicm/baaw.se/public_html/phpBB3/formhandled.php中调用未定义的函数utf8_normalize_nfc()

似乎是一些问题...

编辑4:修正了错误,现在我换了一个新错误。 一般错误 SQL错误[mysqli]

列'topic_first_poster_colour'不能为空[1048]

获取此页面时发生sql错误。如果此问题仍然存在,请与管理员联系。

1 个答案:

答案 0 :(得分:0)

  $message = = generate_text_for_storage($meddelande, $new_uid, $new_bitfield, $bbcode_options, false, false, false);

应该是

  $message = generate_text_for_storage($meddelande, $new_uid, $new_bitfield, $bbcode_options, false, false, false);

你有一个额外的=签到 我也这么认为:

$mode = post;

应该是

$mode = 'post';

我认为$ mode需要一个字符串(来自内存,自从我使用submit_post后已经有一段时间了) 编辑是的第一个参数是一个字符串。 &#34;可以发布,编辑,回复或删除。&#34; - 从wiki

中获取