• Resolved Halil

    (@halilesen)


    Hi,

    Notice: your username, IP or email is currently banned into our forum. Please contact an administrator.

    I’ve been getting this error message for a long time now. For some reason, sometimes the WP login page comes, and when I try to log in, I’m not allowed to.

    It used to redirect to the WP login page after logging into phpBB, but I haven’t experienced that in a long time, so I think it’s resolved.

Viewing 15 replies - 16 through 30 (of 34 total)
  • Plugin Author axew3

    (@axewww)

    function w3_removeAllExceptBody() {
    echo '<script>
    jQuery(document).ready(function() {
    var a = jQuery( ".entry-content" ).clone();
    jQuery("body > div:gt(0)").remove();
    jQuery("#wpadminbar").remove();
    jQuery("body").append(a);
    });
    </script>';
    }

    function w3all_jqueryLIB() {
    wp_enqueue_script("jquery");
    }

    add_action('wp_enqueue_scripts', 'w3all_jqueryLIB');
    add_action( 'wp_head', 'w3_removeAllExceptBody' );

    the js code that can be added on the header remove all the document tags except the body, and after cloning wanted elements (in this case the .entry-content), then re-add the element. To automate this, maybe adding the needed js code only when needed, can be done considering if the post belong to specified category, or is done by specified user with specified capabilities into a specified category, or if tagged in some way, or more hard custom additions maybe adding options or any kind but the mentioned to maintain it very simple seem very good solutions.

    The result can se so added as iframe into the phpBB post, which will display the entire content of WP post without header and footer. You could specify an easy template to be used for posts into a specific category. Possibilities are really infinite and quite easy to be done, even if yes it require little work to be done. I used my raw html on phpBB extension to show you a possible very basic result as intended. The whole joke can be easily automated. I will take a look to the html extension i did, i will improve right now a little, adding the possibility for example, to add rules (admin, global moderators) allowed to post HTML content and a look if something can be improved again someway.

    Result

    https://files.fm/u/bcfkxdmvah#/view/yc3b97y7sc

    https://files.fm/u/bcfkxdmvah#/view/33rd6mamha

    • This reply was modified 4 months, 2 weeks ago by axew3.
    Plugin Author axew3

    (@axewww)

    Ps the post in phpBB with the HTML on posts extension active look like this

    [HTMLMARKUP]
    <iframe
    id="inlineFrameExample"
    title="Inline Frame Example"
    width="100%"
    height="650px"
    src="https://myw3host.com/a-post-for-phpbb/">
    </iframe>

    the height need to be automated to be correct automatically. Maybe this is the most tricky part of the js code if all require to be automated. It is quite easy anyway tp be achieved adding some ajax line of code.

    Thread Starter Halil

    (@halilesen)

    I don’t think the iframe is necessary. I did a test below.

    function html_to_bbcode($html) {
    $html = stripslashes($html);

    $html = preg_replace('/<strong[^>]*>(.*?)<\/strong>/is', '$1', $html);
    $html = preg_replace('/<b[^>]*>(.*?)<\/b>/is', '$1', $html);

    $html = preg_replace('/<h[1-6][^>]*>(.*?)<\/h[1-6]>/is', '[b]$1[/b]', $html);

    $html = preg_replace('/<strong[^>]*>(.*?)<\/strong>/is', '[b]$1[/b]', $html);
    $html = preg_replace('/<b[^>]*>(.*?)<\/b>/is', '[b]$1[/b]', $html);

    $html = preg_replace('/<em[^>]*>(.*?)<\/em>/is', '[i]$1[/i]', $html);
    $html = preg_replace('/<i[^>]*>(.*?)<\/i>/is', '[i]$1[/i]', $html);

    $html = preg_replace('/<u[^>]*>(.*?)<\/u>/is', '[u]$1[/u]', $html);

    $html = preg_replace('/<s[^>]*>(.*?)<\/s>/is', '[s]$1[/s]', $html);
    $html = preg_replace('/<del[^>]*>(.*?)<\/del>/is', '[s]$1[/s]', $html);

    $html = preg_replace('/<a\s+href=["\']([^"\']+)["\']\s*title=["\']([^"\']*)["\'][^>]*>(.*?)<\/a>/is', '[url=$1]$3[/url]', $html);
    $html = preg_replace('/<a\s+href=["\']([^"\']+)["\'][^>]*>(.*?)<\/a>/is', '[url=$1]$2[/url]', $html);

    $html = preg_replace('/<img\s+src=["\']([^"\']+)["\'][^>]*alt=["\']([^"\']*)["\'][^>]*>/is', '[img]$1[/img]', $html);
    $html = preg_replace('/<img\s+src=["\']([^"\']+)["\'][^>]*>/is', '[img]$1[/img]', $html);

    $html = preg_replace('/<ul[^>]*>/is', '[list]', $html);
    $html = preg_replace('/<ol[^>]*>/is', '[list=1]', $html);
    $html = preg_replace('/<\/ul>/is', '[/list]', $html);
    $html = preg_replace('/<\/ol>/is', '[/list]', $html);
    $html = preg_replace('/<li[^>]*>(.*?)<\/li>/is', '[*]$1', $html);

    $html = preg_replace('/<blockquote[^>]*>(.*?)<\/blockquote>/is', '[quote]$1[/quote]', $html);

    $html = preg_replace('/<code[^>]*>(.*?)<\/code>/is', '[code]$1[/code]', $html);
    $html = preg_replace('/<pre[^>]*>(.*?)<\/pre>/is', '[code]$1[/code]', $html);

    $html = preg_replace('/<hr\s*\/?>/is', "\n---\n", $html);

    $html = preg_replace('/<p[^>]*>(.*?)<\/p>/is', '$1' . "\n\n", $html);
    $html = preg_replace('/<br\s*\/?>/is', "\n", $html);
    $html = preg_replace('/<div[^>]*>(.*?)<\/div>/is', '$1' . "\n\n", $html);

    $html = strip_tags($html);

    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');

    $html = preg_replace('/[ \t]+/u', ' ', $html);
    $html = preg_replace('/\n\n\n+/u', "\n\n", $html);
    $html = trim($html);

    return $html;
    }

    add_filter('the_content', function($content) {
    if (is_single() && !is_admin()) {
    $bbcode = html_to_bbcode(get_the_content());

    $output = $content;
    $output .= '<div style="margin-top: 30px; border: 1px solid #ddd; padding: 20px; background-color: #f9f9f9; border-radius: 5px;">';
    $output .= '<h3 style="margin-top: 0;">BBCode Formatı</h3>';
    $output .= '<p style="font-size: 12px; color: #666;">Bu içeriğin BBCode formatı (phpBB forumunda kullanmak için):</p>';
    $output .= '<textarea readonly style="width: 100%; height: 300px; font-family: monospace; padding: 10px; border: 1px solid #ccc; border-radius: 3px; font-size: 12px;">' . esc_textarea($bbcode) . '</textarea>';
    $output .= '<p style="font-size: 12px;"><button onclick="copyBBCode(this)" style="padding: 8px 15px; background-color: #0073aa; color: white; border: none; border-radius: 3px; cursor: pointer;">Kopyala</button></p>';
    $output .= '</div>';

    $output .= '<script>
    function copyBBCode(button) {
    const textarea = button.parentElement.parentElement.querySelector("textarea");
    textarea.select();
    document.execCommand("copy");
    const originalText = button.innerText;
    button.innerText = "Kopyalandı!";
    setTimeout(() => { button.innerText = originalText; }, 2000);
    }
    </script>';

    return $output;
    }

    return $content;
    });

    The html_to_bbcode function can do what I want and I think it is highly customizable. Do you think this makes more sense? Thus, phpBB functions (quote etc.) will not cause problems for the first post of the topic, which is WP Post.

    This function can also be used when adding WP Comments as replies/posts to the topic. A similar function can be used to convert posts in the topic to HTML when adding them as comments to a WP Post.

    When the WP Post is updated, the first post of the topic in phpBB should also be updated. I guess getting the function working again could do that? But I think need to check if this topic hasn’t been brought up before.

    I want WP Comments to be edited in phpBB and not in the WordPress wp-admin.

    When a WP Post is posted and a topic is created in phpBB, the id of that topic must be kept in WP. Also, the phpBB post id of all comments is required because I will use it in dynamic URLs such as “View in forum” and “Full editor”. I think we can use php variable. Do you think it is better to add a separate table or just a column in database?

    There’s no need to store any WP information in the phpBB. But it seems logical to add [url=WPLOSTLINK][logo][/logo][/url] at the beginning and Article Link: [url=WPPOSTLINK]WPLOSTTITLE[/url] at the end.

    I will add some functions to WP Comment, but that will come later. For example, quote or report. I can do this in the forum with a dynamic URL.

    I use a button like below in the forum. But it’s old and I need to update it. When clicked, it goes to a quick reply.

    <a href="javascript:document.getElementById('....').focus()" rel="nofollow" title="Post a reply" class="pbc-button rplypostbtn"><span class="preply5on"></span><span>Reply</span></a>

    You have the Reply extension. I used to be eager for “Show replies” but have since learned to live without it. Maybe I’ll just add the ID part and adapt it to the style when it’s ready. This way, when the phpBB post becomes a WP Comment, it becomes clear which WP comment it will be added as a reply to or not. Do that make sense to you?

    Thread Starter Halil

    (@halilesen)

    +++

    I added post_parent to phpBB post database. I’m currently working on this function. But It’s for WP. We can find the comment_parent version of the comment in wp using the post_parent id in phpBB, right?

    • This reply was modified 4 months, 1 week ago by Halil.
    Thread Starter Halil

    (@halilesen)

    ++

    I’m having some trouble getting post_parent into the database. How does your extension do this? I can’t seem to see it right now.

    Plugin Author axew3

    (@axewww)

    If you want published the posts replies extension i will prepare it and release in short asap.

    Anyway the extension do not create automatically the table into the database, i did not added the related code so this require to be done manually into the phpBB db

    CREATE TABLE phpbb_posts_replies (
    post_id int NOT NULL,
    topic_id int NOT NULL,
    pid_reply int NOT NULL
    )
    ALTER TABLE phpbb_posts_replies
    ADD PRIMARY KEY (post_id),
    ADD KEY topic_id (topic_id),
    ADD KEY pid_reply (pid_reply);

    i waited to release because i would have liked it to work together with this:

    https://www.axew3.com/www/phpbb4/viewtopic.php?t=2

    the vertical views and posts scroller, that can be of course adjusted after then

    Thread Starter Halil

    (@halilesen)

    I tried to keep it simpler. I added a column to the post table with this query.

    ALTER TABLE phpbb_posts 
    ADD post_parent INT(11) NOT NULL DEFAULT 0;

    I used this button:

    <a href="#" class="post-reply-link" data-postid="{postrow.POST_ID}" data-replyto="Reply to the post #{postrow.POST_NUMBER}"><span>Reply</span></a>

    I added this to the quick reply editor

    <input type="hidden" name="post_parent" id="post_parent" value="0">

    I made it change with a js. However, I was not able to process it in the database. I also added a url parameter for the Full editor page, but I left it there.

    Thread Starter Halil

    (@halilesen)

    I did it.

    public function save_parent($event)
    {
    global $request;

    $post_parent = $request->variable('post_parent', 0);
    $sql_data = $event['sql_data'];

    if (isset($sql_data[POSTS_TABLE]['sql']) && $post_parent > 0)
    {
    $sql_data[POSTS_TABLE]['sql']['post_parent'] = (int) $post_parent;
    }

    $event['sql_data'] = $sql_data;
    }

    Now I can add the parents to the post table correctly.

    In WordPress, the comment parent is located in the comment_parent column in the wp_comments table.

    So, while synchronizing “WPPostComment =phpBBTopicPost”, it is necessary to ensure that *_parent are also synchronized.

    Come to think of it, I think we should create two separate tables: WP Post ID and its phpBB Topic ID equivalent, and WP Comment ID and its phpBB Post ID equivalent.

    posttopic table:
    wordpress_id / phpbb_id
    commentpost table:
    wordpress_id / wordpress_parent_id / phpbb_id / phpbb_parant_id

    Do it make sense? But should these tables be in the WordPress database, the phpBB database, or both? Can the necessary information be provided after submitting the form? Does it get complicated when you think about it a little? When a phpBB post is published, it will go to WP. If there is a parent, the parent post’s WP equivalent will be found and sent to WP.

    What if a comment is submit on WP but on phpBB it needs to be approved by a moderator first, or if the user is banned/limited? (I think the sample code in the link I sent also checks user permissions.) When a WP comment is submitted, should it be checked in phpBB first? If it’s subject to approval, it won’t be published in WP first. However, once it’s approved in phpBB, it goes to WP. Does that make sense? Maybe we should add an “approved” column to the commentpost table. 0/1

    Did you try the BBcode converter code I sent you? I think it makes sense. When a WP post is published or updated, it is converted to bbcode and shared on forum id14 on behalf of the author. WP post id and phpBB topic id are added to the posttopic table. When a comment is written on WP, it is sent to the topic in phpBB on behalf of the user, and if it is published as visible, it is also published on WP. When written to the topic in phpBB, if it’s visible, it’s also added to wp. If there’s a parent, the IDs are added to the table and synchronized for two. Is there a need to the “approved” column? There may not be, because if it needs to be approved, the event will happen again in phpBB.

    Does WPComment=phpBBPost seem more difficult than WPPost=phpBBTopic?

    I know I’m repeating some things. I’m just trying to reduce the margin of error and make things clear.

    Best

    • This reply was modified 4 months, 1 week ago by Halil.
    • This reply was modified 4 months, 1 week ago by Halil.
    Thread Starter Halil

    (@halilesen)

    I have achieved somethings in the WP to phpBB step. With author matching and DB injection via email…

    Thread Starter Halil

    (@halilesen)

    With the help of aı, I made progress in the “wp to phpBB” step.

    Thread Starter Halil

    (@halilesen)

    I could only perform SQL injection. I couldn’t use submit_post. SQL seems to work, but standard phpBB events may be missing and BBcode to DB conversion does not occur.

    add_action('publish_post', 'sync_wp_post_to_phpbb');
    add_action('post_updated', 'sync_wp_post_update_to_phpbb', 10, 3);
    add_action('before_delete_post', 'sync_wp_post_delete_to_phpbb');

    add_action('comment_post', 'sync_wp_comment_to_phpbb', 10, 3);
    add_action('edit_comment', 'sync_wp_comment_update_to_phpbb');
    add_action('delete_comment', 'sync_wp_comment_delete_to_phpbb');

    function sync_wp_post_to_phpbb($post_id) {
    $post = get_post($post_id);

    if ($post->post_status !== 'publish' || $post->post_type !== 'post') {
    return;
    }

    $author = get_user_by('id', $post->post_author);
    if (!$author) return;

    $phpbb_user_id = get_phpbb_user_by_email($author->user_email);
    if (!$phpbb_user_id) return;

    global $wpdb;

    $existing = $wpdb->get_row($wpdb->prepare(
    "SELECT * FROM {$wpdb->prefix}phpbb_posts WHERE wp_post_id = %d",
    $post_id
    ));

    if ($existing) return;

    $bbcode_content = html_to_bbcode_phpbb($post->post_content);

    $result = create_phpbb_topic($phpbb_user_id, $post->post_title, $bbcode_content);

    if ($result['success']) {
    $wpdb->insert("{$wpdb->prefix}phpbb_posts", array(
    'wp_post_id' => $post_id,
    'phpbb_topic_id' => $result['topic_id'],
    'phpbb_first_post_id' => $result['post_id'],
    'wp_author_email' => $author->user_email,
    ), array('%d', '%d', '%d', '%s'));

    error_log('WP→phpBB: Post ' . $post_id . ' → Topic ' . $result['topic_id'] . ' (Yazar: ' . $author->user_login . ')');
    }
    }

    function sync_wp_post_update_to_phpbb($post_id, $post_before, $post_after) {
    $post = get_post($post_id);

    if ($post->post_status !== 'publish' || $post->post_type !== 'post') {
    return;
    }

    global $wpdb;

    $sync = $wpdb->get_row($wpdb->prepare(
    "SELECT * FROM {$wpdb->prefix}phpbb_posts WHERE wp_post_id = %d",
    $post_id
    ));

    if (!$sync) return;

    $author = get_user_by('id', $post->post_author);
    if (!$author) return;

    $phpbb_user_id = get_phpbb_user_by_email($author->user_email);
    if (!$phpbb_user_id) return;

    $bbcode_content = html_to_bbcode_phpbb($post->post_content);

    update_phpbb_post_full($sync->phpbb_first_post_id, $post->post_title, $bbcode_content, $phpbb_user_id);

    update_phpbb_topic_title($sync->phpbb_topic_id, $post->post_title);

    update_phpbb_topic_author($sync->phpbb_topic_id, $phpbb_user_id);

    $wpdb->update("{$wpdb->prefix}phpbb_posts",
    array('updated_at' => current_time('mysql')),
    array('wp_post_id' => $post_id)
    );

    error_log('WP→phpBB: Post ' . $post_id . ' güncellendi (Yazar: ' . $author->user_login . ')');
    }

    function sync_wp_post_delete_to_phpbb($post_id) {
    $post = get_post($post_id);

    if ($post->post_type !== 'post') return;

    global $wpdb;

    $sync = $wpdb->get_row($wpdb->prepare(
    "SELECT * FROM {$wpdb->prefix}phpbb_posts WHERE wp_post_id = %d",
    $post_id
    ));

    if (!$sync) return;

    soft_delete_phpbb_topic($sync->phpbb_topic_id);

    $wpdb->delete("{$wpdb->prefix}phpbb_posts", array('wp_post_id' => $post_id));

    error_log('WP→phpBB: Post ' . $post_id . ' silindi');
    }

    function sync_wp_comment_to_phpbb($comment_id, $comment_approved, $commentdata) {
    $comment = get_comment($comment_id);
    $post = get_post($comment->comment_post_ID);

    if (!$post || $post->post_status !== 'publish') {
    return;
    }

    global $wpdb;

    $sync_post = $wpdb->get_row($wpdb->prepare(
    "SELECT phpbb_topic_id FROM {$wpdb->prefix}phpbb_posts WHERE wp_post_id = %d",
    $comment->comment_post_ID
    ));

    if (!$sync_post) return;

    $commenter_email = $comment->comment_author_email;
    $phpbb_user_id = get_phpbb_user_by_email($commenter_email);

    if (!$phpbb_user_id) return;

    $bbcode_content = html_to_bbcode_phpbb($comment->comment_content);

    $parent_phpbb_post_id = 0;
    if ($comment->comment_parent > 0) {
    $parent_sync = $wpdb->get_row($wpdb->prepare(
    "SELECT phpbb_post_id FROM {$wpdb->prefix}phpbb_comments WHERE wp_comment_id = %d",
    $comment->comment_parent
    ));
    $parent_phpbb_post_id = $parent_sync ? $parent_sync->phpbb_post_id : 0;
    }

    $result = create_phpbb_post(
    $phpbb_user_id,
    $sync_post->phpbb_topic_id,
    substr($bbcode_content, 0, 50),
    $bbcode_content,
    $parent_phpbb_post_id
    );

    if ($result['success']) {
    $wpdb->insert("{$wpdb->prefix}phpbb_comments", array(
    'wp_comment_id' => $comment_id,
    'wp_post_id' => $comment->comment_post_ID,
    'phpbb_post_id' => $result['post_id'],
    'phpbb_topic_id' => $sync_post->phpbb_topic_id,
    'wp_comment_parent_id' => $comment->comment_parent,
    'phpbb_post_parent_id' => $parent_phpbb_post_id,
    'approved' => $comment_approved,
    'wp_author_email' => $commenter_email,
    ), array('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s'));

    error_log('WP→phpBB: Comment ' . $comment_id . ' → Post ' . $result['post_id'] . ' (Yazar: ' . $comment->comment_author . ')');
    }
    }

    function sync_wp_comment_update_to_phpbb($comment_id) {
    $comment = get_comment($comment_id);
    global $wpdb;

    $sync = $wpdb->get_row($wpdb->prepare(
    "SELECT * FROM {$wpdb->prefix}phpbb_comments WHERE wp_comment_id = %d",
    $comment_id
    ));

    if (!$sync) return;

    $commenter_email = $comment->comment_author_email;
    $phpbb_user_id = get_phpbb_user_by_email($commenter_email);
    if (!$phpbb_user_id) return;

    $bbcode_content = html_to_bbcode_phpbb($comment->comment_content);
    update_phpbb_post_full($sync->phpbb_post_id, '', $bbcode_content, $phpbb_user_id);

    $wpdb->update("{$wpdb->prefix}phpbb_comments",
    array('updated_at' => current_time('mysql')),
    array('wp_comment_id' => $comment_id)
    );

    error_log('WP→phpBB: Comment ' . $comment_id . ' güncellendi');
    }

    function sync_wp_comment_delete_to_phpbb($comment_id) {
    global $wpdb;

    $sync = $wpdb->get_row($wpdb->prepare(
    "SELECT * FROM {$wpdb->prefix}phpbb_comments WHERE wp_comment_id = %d",
    $comment_id
    ));

    if (!$sync) return;

    soft_delete_phpbb_post($sync->phpbb_post_id);

    $wpdb->delete("{$wpdb->prefix}phpbb_comments", array('wp_comment_id' => $comment_id));

    error_log('WP→phpBB: Comment ' . $comment_id . ' silindi');
    }

    function get_phpbb_user_by_email($email) {
    $pdo = get_phpbb_connection();
    if (!$pdo) return false;

    try {
    $stmt = $pdo->prepare("SELECT user_id, username FROM " . PHPBB_DB_PREFIX . "users WHERE user_email = :email");
    $stmt->execute([':email' => $email]);
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    return $row ? (int)$row['user_id'] : false;
    } catch (PDOException $e) {
    error_log('PHPBB USER QUERY ERROR: ' . $e->getMessage());
    return false;
    }
    }

    function get_phpbb_connection() {
    try {
    $pdo = new PDO(
    'mysql:host=' . PHPBB_DB_HOST . ';dbname=' . PHPBB_DB_NAME . ';charset=utf8mb4',
    PHPBB_DB_USER,
    PHPBB_DB_PASS
    );
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $pdo;
    } catch (PDOException $e) {
    error_log('PHPBB CONNECTION ERROR: ' . $e->getMessage());
    return null;
    }
    }

    function create_phpbb_topic($phpbb_user_id, $topic_title, $message) {
    $pdo = get_phpbb_connection();
    if (!$pdo) return array('success' => false);

    try {
    $forum_id = 24;
    $post_time = time();

    $stmt = $pdo->prepare("SELECT username FROM " . PHPBB_DB_PREFIX . "users WHERE user_id = :uid");
    $stmt->execute([':uid' => (int)$phpbb_user_id]);
    $user = $stmt->fetch(PDO::FETCH_ASSOC);

    if (!$user) return array('success' => false);

    $topic_data = array(
    'forum_id' => (int)$forum_id,
    'topic_title' => $topic_title,
    'topic_poster' => (int)$phpbb_user_id,
    'topic_first_poster_name' => $user['username'],
    'topic_time' => $post_time,
    'topic_views' => 0,
    'topic_status' => 0,
    'topic_posts_approved' => 1,
    'topic_posts_unapproved' => 0,
    'topic_posts_softdeleted' => 0,
    'topic_type' => 0,
    'topic_visibility' => 1,
    'topic_last_view_time' => $post_time,
    );

    $cols = implode(', ', array_keys($topic_data));
    $vals = implode(', ', array_map(function($k) { return ':' . $k; }, array_keys($topic_data)));
    $stmt = $pdo->prepare("INSERT INTO " . PHPBB_DB_PREFIX . "topics ($cols) VALUES ($vals)");
    $stmt->execute($topic_data);
    $topic_id = (int)$pdo->lastInsertId();

    $post_data = array(
    'forum_id' => (int)$forum_id,
    'topic_id' => (int)$topic_id,
    'poster_id' => (int)$phpbb_user_id,
    'post_time' => $post_time,
    'enable_bbcode' => 1,
    'enable_smilies' => 0,
    'enable_magic_url' => 1,
    'enable_sig' => 1,
    'post_subject' => $topic_title,
    'post_text' => $message,
    'post_checksum' => md5($message),
    'post_attachment' => 0,
    'post_postcount' => 1,
    'post_visibility' => 1,
    'post_edit_locked' => 0,
    'post_edit_time' => 0,
    'post_modified' => 0,
    'post_created' => $post_time,
    );

    $cols = implode(', ', array_keys($post_data));
    $vals = implode(', ', array_map(function($k) { return ':' . $k; }, array_keys($post_data)));
    $stmt = $pdo->prepare("INSERT INTO " . PHPBB_DB_PREFIX . "posts ($cols) VALUES ($vals)");
    $stmt->execute($post_data);
    $post_id = (int)$pdo->lastInsertId();

    $username_escaped = $pdo->quote($user['username']);
    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "topics
    SET topic_first_post_id = $post_id,
    topic_last_post_id = $post_id,
    topic_last_poster_id = $phpbb_user_id,
    topic_last_poster_name = $username_escaped,
    topic_last_post_time = $post_time
    WHERE topic_id = $topic_id");

    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "forums
    SET forum_posts_approved = forum_posts_approved + 1,
    forum_topics_approved = forum_topics_approved + 1,
    forum_last_post_time = $post_time,
    forum_last_poster_id = $phpbb_user_id,
    forum_last_poster_name = $username_escaped,
    forum_last_post_id = $post_id
    WHERE forum_id = $forum_id");

    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "users
    SET user_posts = user_posts + 1,
    user_lastpost_time = $post_time
    WHERE user_id = $phpbb_user_id");

    return array('success' => true, 'topic_id' => $topic_id, 'post_id' => $post_id);

    } catch (Exception $e) {
    error_log('CREATE TOPIC ERROR: ' . $e->getMessage());
    return array('success' => false);
    }
    }

    function create_phpbb_post($phpbb_user_id, $topic_id, $post_title, $message, $parent_post_id = 0) {
    $pdo = get_phpbb_connection();
    if (!$pdo) return array('success' => false);

    try {
    $post_time = time();

    $stmt = $pdo->prepare("SELECT forum_id FROM " . PHPBB_DB_PREFIX . "topics WHERE topic_id = :tid");
    $stmt->execute([':tid' => (int)$topic_id]);
    $topic = $stmt->fetch(PDO::FETCH_ASSOC);

    if (!$topic) return array('success' => false);

    $post_data = array(
    'forum_id' => (int)$topic['forum_id'],
    'topic_id' => (int)$topic_id,
    'poster_id' => (int)$phpbb_user_id,
    'post_time' => $post_time,
    'enable_bbcode' => 1,
    'enable_smilies' => 0,
    'enable_magic_url' => 1,
    'enable_sig' => 1,
    'post_subject' => $post_title,
    'post_text' => $message,
    'post_checksum' => md5($message),
    'post_attachment' => 0,
    'post_postcount' => 1,
    'post_visibility' => 1,
    );

    $cols = implode(', ', array_keys($post_data));
    $vals = implode(', ', array_map(function($k) { return ':' . $k; }, array_keys($post_data)));
    $stmt = $pdo->prepare("INSERT INTO " . PHPBB_DB_PREFIX . "posts ($cols) VALUES ($vals)");
    $stmt->execute($post_data);
    $post_id = (int)$pdo->lastInsertId();

    if ($parent_post_id > 0) {
    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "posts SET post_parent = $parent_post_id WHERE post_id = $post_id");
    }

    $stmt = $pdo->prepare("SELECT username FROM " . PHPBB_DB_PREFIX . "users WHERE user_id = :uid");
    $stmt->execute([':uid' => (int)$phpbb_user_id]);
    $user = $stmt->fetch(PDO::FETCH_ASSOC);

    $username_escaped = $pdo->quote($user['username']);

    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "topics
    SET topic_posts_approved = topic_posts_approved + 1,
    topic_last_post_id = $post_id,
    topic_last_poster_id = $phpbb_user_id,
    topic_last_poster_name = $username_escaped,
    topic_last_post_time = $post_time
    WHERE topic_id = $topic_id");

    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "forums
    SET forum_posts_approved = forum_posts_approved + 1,
    forum_last_post_time = $post_time,
    forum_last_poster_id = $phpbb_user_id,
    forum_last_poster_name = $username_escaped,
    forum_last_post_id = $post_id
    WHERE forum_id = " . (int)$topic['forum_id']);

    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "users
    SET user_posts = user_posts + 1,
    user_lastpost_time = $post_time
    WHERE user_id = $phpbb_user_id");

    return array('success' => true, 'post_id' => $post_id);

    } catch (Exception $e) {
    error_log('CREATE POST ERROR: ' . $e->getMessage());
    return array('success' => false);
    }
    }

    function update_phpbb_post_full($post_id, $post_title, $message, $poster_id) {
    $pdo = get_phpbb_connection();
    if (!$pdo) return;

    try {
    $edit_time = time();
    $message_checksum = md5($message);

    if (!empty($post_title)) {
    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "posts
    SET post_text = " . $pdo->quote($message) . ",
    post_checksum = '$message_checksum',
    post_subject = " . $pdo->quote($post_title) . ",
    poster_id = $poster_id,
    post_edit_time = $edit_time
    WHERE post_id = $post_id");
    } else {
    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "posts
    SET post_text = " . $pdo->quote($message) . ",
    post_checksum = '$message_checksum',
    poster_id = $poster_id,
    post_edit_time = $edit_time
    WHERE post_id = $post_id");
    }

    } catch (Exception $e) {
    error_log('UPDATE POST FULL ERROR: ' . $e->getMessage());
    }
    }

    function update_phpbb_topic_title($topic_id, $new_title) {
    $pdo = get_phpbb_connection();
    if (!$pdo) return;

    try {
    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "topics
    SET topic_title = " . $pdo->quote($new_title) . "
    WHERE topic_id = $topic_id");
    } catch (Exception $e) {
    error_log('UPDATE TOPIC TITLE ERROR: ' . $e->getMessage());
    }
    }

    function update_phpbb_topic_author($topic_id, $new_user_id) {
    $pdo = get_phpbb_connection();
    if (!$pdo) return;

    try {
    $stmt = $pdo->prepare("SELECT username FROM " . PHPBB_DB_PREFIX . "users WHERE user_id = :uid");
    $stmt->execute([':uid' => (int)$new_user_id]);
    $user = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($user) {
    $username_escaped = $pdo->quote($user['username']);
    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "topics
    SET topic_poster = $new_user_id,
    topic_first_poster_name = $username_escaped
    WHERE topic_id = $topic_id");
    }
    } catch (Exception $e) {
    error_log('UPDATE TOPIC AUTHOR ERROR: ' . $e->getMessage());
    }
    }

    function soft_delete_phpbb_topic($topic_id) {
    $pdo = get_phpbb_connection();
    if (!$pdo) return;

    try {
    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "topics SET topic_visibility = 2 WHERE topic_id = $topic_id");
    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "posts SET post_visibility = 2 WHERE topic_id = $topic_id");
    } catch (Exception $e) {
    error_log('SOFT DELETE TOPIC ERROR: ' . $e->getMessage());
    }
    }

    function soft_delete_phpbb_post($post_id) {
    $pdo = get_phpbb_connection();
    if (!$pdo) return;

    try {
    $pdo->query("UPDATE " . PHPBB_DB_PREFIX . "posts SET post_visibility = 2 WHERE post_id = $post_id");
    } catch (Exception $e) {
    error_log('SOFT DELETE POST ERROR: ' . $e->getMessage());
    }
    }

    function html_to_bbcode_phpbb($html) {
    $html = stripslashes($html);
    $html = wp_specialchars_decode($html);

    $html = preg_replace('/<p[^>]*>/is', '', $html);
    $html = preg_replace('/<\/p>/is', "\n\n", $html);

    $html = preg_replace('/<h[1-6][^>]*>(.*?)<\/h[1-6]>/is', '[b]$1[/b]' . "\n", $html);

    $html = preg_replace('/<strong[^>]*>(.*?)<\/strong>/is', '[b]$1[/b]', $html);
    $html = preg_replace('/<b[^>]*>(.*?)<\/b>/is', '[b]$1[/b]', $html);

    $html = preg_replace('/<em[^>]*>(.*?)<\/em>/is', '[i]$1[/i]', $html);
    $html = preg_replace('/<i[^>]*>(.*?)<\/i>/is', '[i]$1[/i]', $html);

    $html = preg_replace('/<u[^>]*>(.*?)<\/u>/is', '[u]$1[/u]', $html);

    $html = preg_replace('/<s[^>]*>(.*?)<\/s>/is', '[s]$1[/s]', $html);
    $html = preg_replace('/<del[^>]*>(.*?)<\/del>/is', '[s]$1[/s]', $html);

    $html = preg_replace('/<a\s+href=["\']([^"\']+)["\']\s*title=["\']([^"\']*)["\'][^>]*>(.*?)<\/a>/is', '[url=$1]$3[/url]', $html);
    $html = preg_replace('/<a\s+href=["\']([^"\']+)["\'][^>]*>(.*?)<\/a>/is', '[url=$1]$2[/url]', $html);

    $html = preg_replace('/<img\s+src=["\']([^"\']+)["\'][^>]*>/is', '[img]$1[/img]', $html);

    $html = preg_replace('/<ul[^>]*>/is', '[list]', $html);
    $html = preg_replace('/<ol[^>]*>/is', '[list=1]', $html);
    $html = preg_replace('/<\/ul>/is', '[/list]', $html);
    $html = preg_replace('/<\/ol>/is', '[/list]', $html);
    $html = preg_replace('/<li[^>]*>(.*?)<\/li>/is', '[*]$1', $html);

    $html = preg_replace('/<blockquote[^>]*>(.*?)<\/blockquote>/is', '[quote]$1[/quote]', $html);

    $html = preg_replace('/<code[^>]*>(.*?)<\/code>/is', '[code]$1[/code]', $html);
    $html = preg_replace('/<pre[^>]*>(.*?)<\/pre>/is', '[code]$1[/code]', $html);

    $html = preg_replace('/<br\s*\/?>/is', "\n", $html);
    $html = preg_replace('/<div[^>]*>(.*?)<\/div>/is', '$1' . "\n", $html);
    $html = preg_replace('/<hr\s*\/?>/is', "\n---\n", $html);

    $html = strip_tags($html);

    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');

    $html = preg_replace('/[ \t]+/u', ' ', $html);
    $html = preg_replace('/\n{3,}/u', "\n\n", $html);
    $html = trim($html);

    return $html;
    }
    Plugin Author axew3

    (@axewww)

    I do not think it is the right way to do this thing.

    You go to insert a phpBB post via db instructions that do not accomplish i think with all what it need to be stored into the db, when a new post or topic is inserted. You forget many things like: the search indexing and all the others posts data updates that occurs each time a post/topic is inserted or removed so to maintain topics and posts stored in the correct way into the db. For this reason my suggestion to call the submit_post() via cURL.

    It is the unique way probably to do this thing without to become crazy because things to be managed are a lot and more than you imagine if you like to insert a post just using DB queries.

    The call to submit_post simplify the task, and you do not have to re-write half phpBB code to get the result. Unfortunately, maybe AI can propose you a code but AI do not know how to do things like this, it only give you confused pieces of code unified in a way that normally do not works.

    The unique way i see possible this task is by using cURL or DB queries when an event (insert/update/deletion) occur, and passing data using requests or calling native functions, then leaving to the native WP and phpBB functions to do their work for you about insertion or posts update or deletion.

    Then you have to instruct WP to display phpBB posts, and phpBB to display WP posts, without going to change the way they store data into the db. Or as said, you are doing something that will not be reliable under many aspects.

    • This reply was modified 4 months, 1 week ago by axew3.
    • This reply was modified 4 months, 1 week ago by axew3.
    Thread Starter Halil

    (@halilesen)

    I wanted to contact you using the form on your website, but I wonder if the message was not sent?

    Thread Starter Halil

    (@halilesen)

    I just sent one more form. There’s no need for the WP admin page or anything like that. the code I can add to the functions file for WP and the code I can add to my phpBB extension will suffice.

    Thread Starter Halil

    (@halilesen)

    I think I’ve managed to figure out how to send from wp to phpBB(http api). I’ll start working on the function code.

Viewing 15 replies - 16 through 30 (of 34 total)

You must be logged in to reply to this topic.