Forum Replies Created

Viewing 15 replies - 1 through 15 (of 426 total)
  • Halil

    (@halilesen)

    A solution that can be added to the functions file:

    add_filter('admin_init', function () {
    global $_wp_admin_css_colors;

    $keep = 'fresh';

    foreach ($_wp_admin_css_colors as $key => $scheme) {
    if ($key !== $keep) {
    unset($_wp_admin_css_colors[$key]);
    }
    }
    });
    Forum: Fixing WordPress
    In reply to: 7.0 Upgrade & AI
    Halil

    (@halilesen)

    Halil

    (@halilesen)

    I agree. I was shocked when I logged into wp-admin just a moment ago. Disgraceful! And AI? Nope, I don’t want that. If WP didn’t update automatically, I probably wouldn’t have updated it on my own.

    Thread Starter Halil

    (@halilesen)

    Yes, the issue was caused by the w3_phpbb_ban function. It’s looks fine now. However, the ban check should still be reviewed.

    Thank you

    Thread Starter Halil

    (@halilesen)

    Hello

    There is a problem. In the past, when I logged in to phpBB, the wordpress_logged_in_* cookie would appear, but now it doesn’t appear unless I switch to WordPress. SORRY! I tested the older versions. I guess that’s what I thought.

    However, something is causing constant logouts in phpBB… The issue is resolved when I disable the WP plugin. I completely uninstalled the plugin and reinstalled it from scratch. But the problem persists.

    It seems the ‘Brute Force countermeasure’ is triggering false positives even when set to NO, or there is a session mismatch that leads the plugin to think the session is hijacked. The fact that the wordpress_logged_in cookie is no longer appearing on the phpBB side (as it did in older setups) might be the clue, maybe…

    While analyzing cookies in the development tools, I noticed that the phpBB cookies were suddenly being replaced by guest cookies.

    I changed the cache name….

    By the way, I got this warning again:
    “Notice: your username, IP or email is currently banned into our forum. Please contact an administrator.”

    I’ve tried a lot of different settings. Every time, I’m getting automatic logouts in my tests in incognito mode and in feedback from users. I’m disabling the plugin for now because there doesn’t seem to be a solution.

    However, this problem doesn’t occur on the new site.

    Your help is greatly appreciated.

    Thank you

    • This reply was modified 1 month, 2 weeks ago by Halil.
    Thread Starter Halil

    (@halilesen)

    Thank you.

    I think I fixed the user sync from phpBB to WordPress. But for deleting users from phpBB to WordPress, I think the extension is not ready yet, because the relevant code appears to be commented out.

    Thread Starter Halil

    (@halilesen)

    I delayed writing.

    Thank you. I customized the code so that all the custom profile fields I wanted would be synchronized. It works great.

    Forget what I said about emails, it was nonsense. Instead, I extended a feature in my synchronization.

    Forum: Plugins
    In reply to: [WP w3all phpBB] Online?
    Thread Starter Halil

    (@halilesen)

    I rewrote it to make the online list more customisable and to avoid disrupting the overall structure of the extension.

    .....
    $cutoff = time() - 300;

    $sql = $w3all_phpbb_connection->prepare(
    "SELECT session_user_id AS user_id, MAX(session_time) AS last_time
    FROM phpbb_sessions
    WHERE session_user_id > 0
    AND session_time >= %d
    GROUP BY session_user_id
    ORDER BY last_time DESC",
    $cutoff
    );
    ....

    I’m doing it using the extension’s link. It was very difficult, but I think this is important for my WP post-phpBB topic synchronization. As I said, it’s very difficult to do this for everyone, but I was able to implement it by providing a lot of parameters for my own specific theme and use case.

    Thank you.
    You helped me by inspiring me, and I learned many things thanks to this extension.

    Thread Starter Halil

    (@halilesen)

    Hmm. Changing the email addresses for comments might be too expensive, so I’ve developed a more effective method for online display.

    Instead of using the comment’s email address, I matched it with the comment author’s current email address. It made more sense.

    Thanks.

    Forum: Plugins
    In reply to: [WP w3all phpBB] Online?
    Thread Starter Halil

    (@halilesen)

    I matched them via email. But what I’m wondering is, can the phpBB ID of the wp user be known, or just the email?

    I think there’s a 1-minute limit. I should be able to see those who were online within the last 5 minutes, like the default phpBB setting, right?

    Thanks.

    By the way, I’ve made progress on the wp-phpbb post=topic synchronization. Most of it is done. And you were right, it’s quite challenging. It’s not a universal solution, but it can be adapted to my specific usage conditions and scenarios; it requires a lot of interactive thinking.

    Thread Starter Halil

    (@halilesen)

    Yes, I think the problem is the admin ID.

    I plan to disable the admin later and use my other account, so I will be testing more later.

    Could a match like 1 = 2 be made for w3all_phpbb_usession?

    Thread Starter Halil

    (@halilesen)

    So, is it sufficient for it to have SELECT, INSERT and UPDATE privileges?

    Thread Starter Halil

    (@halilesen)

    Hello! It’s good to hear from you. Health is more valuable.

    I don’t know why, but iframe doesn’t feel warm to me.

    I seem to have completed the process of creating a new WordPress post = new phpBB topic using this option, but the update isn’t working.

    /forum/wp_bridge_submit.php

    <?php
    declare(strict_types=1);

    @ini_set('display_errors', '0');
    @ini_set('html_errors', '0');
    error_reporting(E_ALL);
    ob_start();

    define('IN_PHPBB', true);
    $phpbb_root_path = __DIR__ . '/';
    $phpEx = 'php';

    require_once $phpbb_root_path . 'common.' . $phpEx;
    require_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;

    $user->session_begin();
    $auth->acl($user->data);
    $user->setup();

    $request->enable_super_globals();

    $SECRET = 'SUPEASasaR_SECsaRET_SAsKASEY';
    if (!hash_equals($SECRET, $request->variable('secret', ''))) {
    ob_end_clean();
    echo json_encode(['success' => false]);
    exit;
    }

    $mode = $request->variable('mode', 'post');
    $user_id = (int)$request->variable('user_id', 0);
    $forum_id = (int)$request->variable('forum_id', 0);
    $topic_id = (int)$request->variable('topic_id', 0);
    $post_id = (int)$request->variable('post_id', 0);
    $subject = $request->variable('subject', '', true);
    $message = $request->variable('message', '', true);

    $sql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE user_id = ' . $user_id;
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    if (!$row) exit;

    $real_userdata = $user->data;
    foreach ($row as $k => $v) {
    if (array_key_exists($k, $user->data)) {
    $user->data[$k] = $v;
    }
    }
    $auth->acl($user->data);

    $uid = $bitfield = '';
    $options = 0;
    generate_text_for_storage($message, $uid, $bitfield, $options, true, true, false);

    $data = [
    'forum_id' => $forum_id,
    'topic_title' => $subject,
    'post_subject' => $subject,
    'poster_id' => $user->data['user_id'],
    'poster_ip' => $user->ip,
    'icon_id' => 0,
    'enable_bbcode' => 1,
    'enable_smilies' => 0,
    'enable_urls' => 1,
    'enable_sig' => 1,
    'enable_indexing' => 1,
    'notify' => 0,
    'notify_set' => 0,
    'message' => $message,
    'message_md5' => md5($message),
    'bbcode_uid' => $uid,
    'bbcode_bitfield' => $bitfield,
    'post_edit_locked' => 0,
    'force_approved_state' => true,
    ];

    $poll = [];

    if ($mode === 'edit') {
    $data['topic_id'] = $topic_id;
    $data['post_id'] = $post_id;
    submit_post('edit', $subject, $user->data['username'], POST_NORMAL, $poll, $data);
    } else {
    submit_post('post', $subject, $user->data['username'], POST_NORMAL, $poll, $data);
    }

    $user->data = $real_userdata;
    $auth->acl($user->data);

    ob_end_clean();
    header('Content-Type: application/json');
    echo json_encode(['success' => true]);
    exit;

    PW functions.php

    define('WP_PHPBB_BRIDGE_URL',    'https://abc.com/forum/wp_bridge_submit.php');
    define('WP_PHPBB_BRIDGE_SECRET', 'SUPEASasaR_SECsaRET_SAsKASEY');
    define('WP_PHPBB_FORUM_ID', 24);

    /* ---------- HTML → phpBB BBCode ---------- */
    function html_to_bbcode_phpbb($html) {
    $html = stripslashes($html);

    // block → satır
    $html = preg_replace('/<br\s*\/?>/i', "\n", $html);
    $html = preg_replace('/<\/p>/i', "\n\n", $html);
    $html = preg_replace('/<p[^>]*>/i', '', $html);

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

    // formatting
    $html = preg_replace('/<(strong|b)[^>]*>(.*?)<\/\1>/is', '[b]$2[/b]', $html);
    $html = preg_replace('/<(em|i)[^>]*>(.*?)<\/\1>/is', '[i]$2[/i]', $html);
    $html = preg_replace('/<u[^>]*>(.*?)<\/u>/is', '[u]$1[/u]', $html);
    $html = preg_replace('/<(s|del)[^>]*>(.*?)<\/\1>/is', '[s]$2[/s]', $html);

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

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

    // quotes & code
    $html = preg_replace('/<blockquote[^>]*>(.*?)<\/blockquote>/is', '[quote]$1[/quote]', $html);
    $html = preg_replace('/<(pre|code)[^>]*>(.*?)<\/\1>/is', '[code]$2[/code]', $html);

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

    // normalize spacing
    $html = preg_replace("/\n{3,}/", "\n\n", $html);
    return trim($html);
    }


    /* ---------- phpBB PDO (SELECT ONLY) ---------- */
    function wp_phpbb_pdo(): PDO {
    static $pdo;
    if ($pdo) return $pdo;

    $pdo = new PDO(
    'mysql:host=' . PHPBB_DB_HOST . ';dbname=' . PHPBB_DB_NAME . ';charset=utf8mb4',
    PHPBB_DB_USER,
    PHPBB_DB_PASS,
    [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
    );
    return $pdo;
    }

    /* ---------- phpBB user_id by email ---------- */
    function wp_phpbb_get_user_id_by_email(string $email): ?int {
    $pdo = wp_phpbb_pdo();
    $stmt = $pdo->prepare(
    'SELECT user_id FROM ' . PHPBB_DB_PREFIX . 'users WHERE user_email = :email LIMIT 1'
    );
    $stmt->execute(['email' => $email]);
    $id = $stmt->fetchColumn();
    return $id ? (int)$id : null;
    }

    /* =====================================================
    CREATE — NEW WP POST => NEW phpBB TOPIC
    ===================================================== */
    add_action('publish_post', 'wp_phpbb_publish_create', 10, 2);

    function wp_phpbb_publish_create($post_id, $post) {

    if ($post->post_type !== 'post') return;
    if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) return;

    global $wpdb;

    // Zaten var mı?
    $exists = $wpdb->get_var(
    $wpdb->prepare("SELECT phpbb_topic_id FROM wp_phpbb_topic_map WHERE wp_post_id = %d", $post_id)
    );
    if ($exists) return;

    $lock = 'wp_phpbb_lock_' . $post_id;
    if (get_transient($lock)) return;
    set_transient($lock, 1, 60);

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

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

    // CREATE
    $response = wp_remote_post(WP_PHPBB_BRIDGE_URL, [
    'timeout' => 20,
    'body' => [
    'secret' => WP_PHPBB_BRIDGE_SECRET,
    'mode' => 'post',
    'user_id' => $phpbb_user_id,
    'forum_id' => WP_PHPBB_FORUM_ID,
    'subject' => $post->post_title,
    'message' => html_to_bbcode_phpbb($post->post_content),
    ],
    ]);

    if (is_wp_error($response)) return;

    // ID’yi SELECT ile al
    $pdo = wp_phpbb_pdo();
    $stmt = $pdo->prepare("
    SELECT topic_id, topic_first_post_id
    FROM " . PHPBB_DB_PREFIX . "topics
    WHERE forum_id = :forum
    AND topic_poster = :user
    AND topic_title = :title
    ORDER BY topic_time DESC
    LIMIT 1
    ");
    $stmt->execute([
    'forum' => WP_PHPBB_FORUM_ID,
    'user' => $phpbb_user_id,
    'title' => $post->post_title,
    ]);
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    if (!$row) return;

    $wpdb->insert('wp_phpbb_topic_map', [
    'wp_post_id' => $post_id,
    'phpbb_topic_id' => (int)$row['topic_id'],
    'phpbb_first_post_id' => (int)$row['topic_first_post_id'],
    'wp_author_id' => $author->ID,
    'phpbb_author_id' => $phpbb_user_id,
    'created_at' => current_time('mysql'),
    'updated_at' => current_time('mysql'),
    ]);

    delete_transient($lock);
    }

    /* =====================================================
    UPDATE — WP POST UPDATE => phpBB EDIT
    ===================================================== */
    add_action('post_updated', 'wp_phpbb_publish_update', 10, 3);

    function wp_phpbb_publish_update($post_id, $post_after, $post_before) {

    if ($post_after->post_type !== 'post') return;
    if ($post_before->post_status !== 'publish') return;
    if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) return;

    global $wpdb;

    $map = $wpdb->get_row(
    $wpdb->prepare("SELECT * FROM wp_phpbb_topic_map WHERE wp_post_id = %d", $post_id)
    );
    if (!$map) return;

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

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

    wp_remote_post(WP_PHPBB_BRIDGE_URL, [
    'timeout' => 20,
    'body' => [
    'secret' => WP_PHPBB_BRIDGE_SECRET,
    'mode' => 'edit',
    'user_id' => $phpbb_user_id,
    'forum_id' => WP_PHPBB_FORUM_ID,
    'topic_id' => (int)$map->phpbb_topic_id,
    'post_id' => (int)$map->phpbb_first_post_id,
    'subject' => $post_after->post_title,
    'message' => html_to_bbcode_phpbb($post_after->post_content),
    ],
    ]);

    $wpdb->update(
    'wp_phpbb_topic_map',
    ['updated_at' => current_time('mysql')],
    ['wp_post_id' => $post_id]
    );
    }

    We can transfer WordPress comments using a similar method. I think it can be sent via HTTP POST.

    Thread Starter Halil

    (@halilesen)

    But…

    I hope you’re okay.

    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 - 1 through 15 (of 426 total)