1

(8 replies, posted in PunBB 1.4 additions)

paulcambull, simply modify the CSS of your theme to either adjust the style for all devices, or adjust it for just smaller screens. It's a combination of losing positive or negative margins for those div containers.

Here's one example of what I did to achieve that recently, which you can see is responsive for desktop and mobile:
http://www.bobafettfanclub.com/boards/t … boba-fett/

Based on what I shared at http://punbb.informer.com/forums/topic/ … nbb-forum/ and have hosted at http://fwdlabs.com/resources/code/, I just got a question from "janereigytasuda" about how one could post to a PunBB forum from a PHP form outside of PunBB.

This variant of my other integration would really be for an administrator to create a domino effect and bypasses all of the handy security features of PunBB. That said, maybe it's useful to someone.

PHP variables to configure before the query:

$myPunBBPrefix = MySQL table prefix (e.g. punbb_)
$myPunBBUsername = PunBB username (e.g. admin)
$myPunBBSubject = PunBB topic title (e.g. "New Topic")
$myPunBBDate = strtotime() of a YYYY-MM-DD date (e.g. 2016-01-28)
$myPunBBForumID = PunBB forum ID number (e.g. 1)
$myPunBBUserID = PunBB user ID (e.g. 1)
$myPunBBMessage = PunBB post within a topic (e.g. "This is a post.")
$myPunBBUserIP = PunBB user IP address

Note: mysql_query() is was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. MySQLi or PDO_MySQL should be used instead for more future-friendly code.

mysql_query("INSERT INTO ".$myPunBBPrefix."topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES(
    '".$myPunBBUsername."',
    '".$myPunBBSubject."',
    ".$myPunBBDate.",
    ".$myPunBBDate.",
    '".$myPunBBUsername."',
    '".$myPunBBForumID."'
    )");
$myPunBBNewTopicID = mysql_insert_id();

First, we need to create a new topic. The above is the "insert." PunBB's topic needs the poster's username, the subject, the date string, the last posted string, the last poster's username (which can match the original poster's username), and the forum ID number. If you create an input form that sends that all to the right MySQL table, it will then show up in punBB as a new topic.

mysql_query("INSERT INTO ".$myPunBBPrefix."posts (poster, poster_id, message, posted, topic_id, poster_ip) VALUES(
    '".$myPunBBUsername."',
    ".$punbbUserID.",
    '".$myPunBBMessage."',
    ".$myPunBBDate.",
    ".$myPunBBNewTopicID.",
    '".$myPunBBUserIP."'
    )");
$myPunBBNewPostID = mysql_insert_id();

Second, we need to create the post within that topic. PunBB's posts need the poster's username, the poster's user ID, the message of that post, the date string, the topic ID, and the user's IP address. This then makes the post show up within the new topic.

Hope someone here finds it useful. I'll post it along with some other open-source work at http://fwdlabs.com/resources/code/.

Hi kudataz, thanks for the question!

We're on WordPress 4.1 with this code and it's still working.

Related, see http://fwdlabs.com/resources/code/wordp … nbb-forum/ for more up-to-date code releases.

Regarding your questions on the config:

* $punbbUsername should be a real username unless it's intentionally to appear as a bot aka non-user (which isn't the intention here)

* $punbbUserID should match the real username or may create a problem, since it wasn't built to run as a bot / non-user

* $punbbUserIP can be spoofed and is a required variable that punBB wants to store, generally for security purposes

* $punbbForumID should be the forum ID known within punBB so this auto-post shows up in the right spot

Let me know if you have any other questions or concerns. Thanks again!

sleddog2, thank you for figuring out this problem! Your solution worked for me.

For others who may experience this same problem, it occurred for me with a server that has SNI enabled and that's hosting several sites, some which use valid SSL certs but not the one with punBB which threw this error.

Adding the "empty($_SERVER['HTTPS'])" statement should definitely be included in the next upgrade to punBB. Fingers crossed it comes soon.

achtungbaby and kudataz, thanks for the posts!

I've just reviewed the code that's running in production now on a WordPress 3.9 install with a punBB 1.4.2 install. The same core code works well, however, I've re-written it to improve upon my earlier post:

/**
 * Name: WordPress Posts Re-posted to punBB Forum
 * Requirements: WordPress 3.9+, punBB 1.4.2+
 * Instructions: 1. Edit config to match your punBB install and preferred user. 2. Add this code to your WordPress theme's functions.php file. 3. Publish a post on WordPress and see it auto-publish to your punBB.
 * Version: 1.0
 * Author: FWD:labs, based on code by Jones at punbb.informer.com/forums/topic/23056/wordpress2punbb-posting/
 * Author URI: http://fwdlabs.com/resources/code/
 * License: GPL2
 */

function punbb_publish_post($post_ID) {
        
    global $wpdb;
    
    // Config
    $punbbPrefix = ""; // Example: punbb_
    $punbbUsername = ""; // Example: Forum Admin
    $punbbUserID = ""; // Example: 2
    $punbbUserIP = ""; // Example: 1.2.3.4
    $punbbForumID = ""; // Example: 8
    
    // Exit gracefully if config unchanged
    if ($punbbPrefix == "" || $punbbUsername == "" || $punbbUserID == "" || $punbbUserIP == "" || $punbbForumID == "") {
        return false;
    }
    
    // Select WordPress post based on the provided $post_ID
    $wppost = $wpdb->get_row("SELECT ID, post_date, post_title, post_content FROM ".$wpdb->posts." WHERE ID = ".mysql_real_escape_string(trim($post_ID))." LIMIT 1");
        
    $getArticle = $wppost->post_content;

    // Convert HTML to BBCode
    
        // Images need some extra help to get to BBCode
        
        // If WordPress formatted the image
        // $getArticle = preg_replace("/<img src=([^>]+) alt=([^>]+) width=([^>]+) height=([^>]+) class=([^>]+)\>/i", '[img]$1[/img]', $getArticle);

        // If a content editor formatted the image by hand
        // $getArticle = preg_replace("/<img src=([^>]+) \/\>/i", '[img]$1[/img]', $getArticle);

        $getArticle = preg_replace('#<img.+?src=[\'"]([^\'"]+)[\'"].*?>#i', '[img]$1[/img]', $getArticle);    
                
        // Remove <br style="clear:both;/">, which may break the input
        $getArticle = preg_replace("/<br style=([^>]+)\>/i", "\n", $getArticle);
        
        // Remove [caption] content
        // Source: stackoverflow.com/a/16988328/1527619
        $getArticle = preg_replace('#\s*\[caption[^]]*\].*?\[/caption\]\s*#is', '', $getArticle);
    
        // Convert HTML to punBB'd BBCODE
        // Improvements made for list items and double quotes
        // Based upon bb2html() by Louai Munajim
        $htmlcode = array("&lt;", "&gt;",
            "<ul>", "</ul>", 
            "<li>", "</li>", 
            "<strong>", "</strong>", 
            "<u>", "</u>", 
            "<i>", "</i>",
            "<em>", "</em>",
            '<a href="', "</a>",
            "<blockquote>", "</blockquote>",
            '">',
            '"');
        $bbcode = array("<", ">",
            "[list]", "[/list]", 
            "[*]", "[/*]",
            "[b]", "[/b]", 
            "[u]", "[/u]", 
            "[i]", "[/i]",
            "[i]", "[/i]",
            '[url="', "[/url]",
            "[quote]", "[/quote]",
            '"]',
            '');

    $getArticle = str_replace($htmlcode, $bbcode, $getArticle);
                
    // Check punBB if we're editing a topic or adding a new topic, simply based on the username and post date matching
    $wppost_check = $wpdb->get_row("SELECT id, topic_id FROM ".$punbbPrefix."posts WHERE poster = '".$punbbUsername."' AND posted = ".strtotime($wppost->post_date));
    
    // punBB found a match, so we're editing an existing topic
    if ($wppost_check) {

        // Update the title of the punBB topic with any changes made within WordPress
         $wpdb->query("UPDATE ".$punbbPrefix."topics SET subject = '".mysql_real_escape_string(trim($wppost->post_title))."' WHERE id = ".$wppost_check->topic_id);
        
        // Update the content of the punBB post with any changes made within WordPress
        $wpdb->query("UPDATE ".$punbbPrefix."posts SET message = '".mysql_real_escape_string(trim($getArticle))."' WHERE id = ".$wppost_check->id);

    // punBB did not find a match, so we're adding a new topic
    } else {
        
        // Add a permalink to the original post in WordPress to the punBB message board re-post
        $permalink = get_permalink($post_ID);
        $wp_add = "\n\nView the original post [url=$permalink]here[/url]";
        $displayArticle = $getArticle.$wp_add;
        
        // Modify the title of the punBB version, perhaps with a prefix like [NEWS]
        $displayTopicTitle = $wppost->post_title;
        $displayTopicTitle = "[NEWS] ".$displayTopicTitle;
        
        // Create the punBB topic
        $wpdb->query("INSERT INTO ".$punbbPrefix."topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES(
            '".$punbbUsername."',
            '".$displayTopicTitle."',
            ".strtotime($wppost->post_date).",
            ".strtotime($wppost->post_date).",
            '".$punbbUsername."',
            '".$punbbForumID."'
            )");
        $topic_id = $wpdb->insert_id;

        // Create the punBB post in the new topic
        $wpdb->query("INSERT INTO ".$punbbPrefix."posts (poster, poster_id, message, posted, topic_id, poster_ip) VALUES(
            '".$punbbUsername."',
            ".$punbbUserID.",
            '".mysql_real_escape_string(trim($displayArticle))."',
            ".strtotime($wppost->post_date).",
            ".$topic_id.",
            '".$punbbUserIP."'
            )");
        $post_id = $wpdb->insert_id;

        // New topic in punBB needs first_post_id and last_post_id to successfully set
        $wpdb->query("UPDATE ".$punbbPrefix."topics SET last_post_id = ".$post_id.", first_post_id = ".$post_id." WHERE id = ".$topic_id);
        
        // Update the forums table with last post, last post ID, and last poster, which emulates how posts are done within punBB
        $wpdb->query("UPDATE ".$punbbPrefix."forums SET last_post = ".strtotime($wppost->post_date).", last_post_id = ".$post_id.", last_poster = '".$punbbUsername."' WHERE id = $punbbForumID");
        
        // Get the number of posts of the user
        $punbb_postnumber = $wpdb->get_row("SELECT num_posts FROM ".$punbbPrefix."users WHERE username = '".$punbbUsername."' LIMIT 1");
        
        // Add one to the number of their posts
        $wpdb->query("UPDATE ".$punbbPrefix."users SET num_posts = ".$punbb_postnumber->num_posts."+1 WHERE username = '".$punbbUsername."'");
        
    }

    return $post_ID;

}

add_action( 'publish_post', 'punbb_publish_post' );

You can see this in action at these links, refreshed today.

punBB:
bobafettfanclub.com/boards/topic/4168/news-black-series-boba-fett-reissued-in-wave-4/

WordPress:
bobafettfanclub.com/news/collectibles/black-series-boba-fett-re-issued-in-wave-4/

This is a re-post of http://punbb.informer.com/forums/topic/ … -posting/, now in a more-appropriate v.1.4 forum. Thank you, Jones, for starting this much needed integration between WordPress posts and punBB auto-posts.

For members like freequest and others, the code below is to be added to your WordPress theme's function.php.

I've made some adjustments to make the code easier to edit. This was tested and works with punBB 1.4 and WordPress 3.5.1. Whenever a new post is published within WordPress, it is also auto-posted to the punBB board with a permalink back to the original URL.

You can see it in action with posts between the home page of the following link and www [dot] bobafettfanclub [dot] com/boards/forum/8/dialogue/.

Simply replace the defaults noted in the code below:

function punbb_publish_post($post_ID) {
    
    /*
    
    Based upon code by Jones
    
    Revisions on 2013-05-03 by FWD:labs / Aaron Proctor include:
    - Replace WordPress HTML content to valid BBCode
    - Sanitize database imputs with mysql_real_escape_string(trim($variable))
    - Add link within punBB re-post back to WordPress permalink
    
    */
    
    global $wpdb;
    
        /* Defaults - declare all of the following before using */
        $punbbPrefix = ""; // e.g. punbb_
        $punbbUsername = ""; // e.g. admin
        $punbbUserID = ""; // e.g. 2
        $punbbUserIP = ""; // e.g 1.2.3.4
        $punbbForumID = ""; // e.g. 8
    
    $wppost = $wpdb->get_row("SELECT ID, post_date, post_title, post_content FROM ".$wpdb->posts." WHERE ID = ".mysql_real_escape_string(trim($post_ID))." LIMIT 1");
    
    /* Check if edited or new, based on username and post date match only */
    $wppost_check = $wpdb->get_row("SELECT id, topic_id FROM ".$punbbPrefix."posts WHERE poster = '".$punbbUsername."' AND posted = ".strtotime($wppost->post_date));

    $getArticle = $wppost->post_content;

        // Convert HTML to BBCode
    
        // Images need some extra help to get to BBCode
        
            // WordPress formatted
        $getArticle = preg_replace("/<img src=([^>]+) alt=([^>]+) width=([^>]+) height=([^>]+) class=([^>]+)\>/i", '[img]$1[/img]', $getArticle);
            // By-hand formatted
        $getArticle = preg_replace("/<img src=([^>]+) \/\>/i", '[img]$1[/img]', $getArticle);
                
        // <br style="clear:both;/"> may break the input
        $getArticle = preg_replace("/<br style=([^>]+)\>/i", "\n", $getArticle);
    
        // Based upon bb2html() by Louai Munajim
        // Improvements made for list items and double quotes
        $htmlcode = array("&lt;", "&gt;",
                        "<ul>", "</ul>", 
                        "<li>", "</li>", 
                        "<strong>", "</strong>", 
                        "<u>", "</u>", 
                        "<i>", "</i>",
                        '<a href="', "</a>",
                        "<blockquote>", "</blockquote>",
                        '">',
                        '"');
        $bbcode = array("<", ">",
                        "[list]", "[/list]", 
                        "[*]", "[/*]",
                        "[b]", "[/b]", 
                        "[u]", "[/u]", 
                        "[i]", "[/i]",
                        '[url="', "[/url]",
                        "[quote]", "[/quote]",
                        '"]',
                        '');
        $getArticle = str_replace($htmlcode, $bbcode, $getArticle);
        
    if ($wppost_check) {

        /* Edited Post */
        $wpdb->query("UPDATE ".$punbbPrefix."topics SET subject = '".mysql_real_escape_string(trim($wppost->post_title))."' WHERE id = ".$wppost_check->topic_id);
        $wpdb->query("UPDATE ".$punbbPrefix."posts SET message = '".mysql_real_escape_string(trim($getArticle))."' WHERE id = ".$wppost_check->id);

    } else {
        
        /* New Post */

        /* Puts a link to the original posting in the message board post */
        $permalink = get_permalink($post_ID);
        $wp_add = "\n\nView the original post [url=$permalink]here[/url]";
        $displayArticle = $getArticle.$wp_add;
        
        $wpdb->query("INSERT INTO ".$punbbPrefix."topics (poster, subject, posted, last_post, last_poster, forum_id) VALUES(
    '".$punbbUsername."',
    '".$wppost->post_title."',
    ".strtotime($wppost->post_date).",
    ".strtotime($wppost->post_date).",
    '".$punbbUsername."',
    '".$punbbForumID."'
    )");
        $topic_id = $wpdb->insert_id;

        $wpdb->query("INSERT INTO ".$punbbPrefix."posts (poster, poster_id, message, posted, topic_id, poster_ip) VALUES(
    '".$punbbUsername."',
    ".$punbbUserID.",
    '".mysql_real_escape_string(trim($displayArticle))."',
    ".strtotime($wppost->post_date).",
    ".$topic_id.",
    '".$punbbUserIP."'
    )");
        $post_id = $wpdb->insert_id;

        /* Add new topic needs first_post_id and last_post_id to successfully delete within punBB */
        $wpdb->query("UPDATE ".$punbbPrefix."topics SET last_post_id = ".$post_id.", first_post_id = ".$post_id." WHERE id = ".$topic_id);
        
        $wpdb->query("UPDATE ".$punbbPrefix."forums SET last_post = ".strtotime($wppost->post_date).", last_post_id = ".$post_id.", last_poster = '".$punbbUsername."' WHERE id = $punbbForumID");
        $punbb_postnumber = $wpdb->get_row("SELECT num_posts, username FROM ".$punbbPrefix."users WHERE username = '".$punbbUsername."' LIMIT 1");
        $wpdb->query("UPDATE ".$punbbPrefix."users SET num_posts = ".$punbb_postnumber->num_posts."+1 WHERE username = '".$punbbUsername."'");
    
    }

    return $post_ID; /* Optional? */

}

add_action( 'publish_post', 'punbb_publish_post' );

7

(14 replies, posted in PunBB 1.3 troubleshooting)

Thank you, Jones, for starting this much needed integration between WordPress posts and punBB auto-posts.

I've made some adjustments to make the code easier to edit over here, since it's v.1.4 compatible:
http://punbb.informer.com/forums/post/149067/#p149067

8

(0 replies, posted in PunBB 1.2 show off)

Over at BobaFett.com, we've been running PunBB since January 2006:

http://bobafett.com/boards/

For a site dedicated to the bounty hunter from Star Wars, and online since 1996, PunBB has been a great tool for focusing on content first, features second.

Speaking of features, popular with the site's members are the preferred stylesheet options, the after-thought edit, the ease of moderation, and the overall ease of usability. I'm running only three modifications -- Reputation/Karma, Private Messaging, and RSS -- all of which are huge hits.

I also have some external queries to the database, to show off our top 10 lists: posters, topic starters, karma, and topics. I also have latest user to post, active topics and newest topics pulled to our home page.

Because it works so well, the user management of PunBB is also the core of our site. I use integration bridges with Coppermine for users to upload images to our site. I was also looking at bridges for Mediawiki (and Dokuwiki), but they're not far enough along in development.

Finally, since the message boards were recently been hit hard with spam registrations, I resorted to Googling an answer -- this forum is a little hard to follow -- and am giving AntiBot a try.