Compatability issues with phpbb recent topics plugin ?

I’ve recently run into a compatibility problem with my phpbb topic plugin, basically I tried to copy the code I did ( the ob_start / stop buffer thing ) and I found that the second time I ran the loop it didn’t work !

Anyway in lieu of working on an admin interface for setting up the phpbb connection I’m solving this, if anyone is having a similar issue please let me know.

Oh, and this might be of interest…

———- Forwarded message ———-
From: Nick
Date: 12-Mar-2007 11:38
Subject: Re: Recent phpBB Topics on WordPress Plugin
To: Paul Stokes

Hi Paul,

You can do this by playing with the SQL statement in the plugin, for example

SELECT * FROM $TOPIC_TABLE WHERE forum_id != 1 ORDER BY topic_time DESC LIMIT $limit

would exclude topics from forum 1

hope that helps,
Nick

On 11/03/07, Paul Stokes wrote:

Hello,

First I must say what a great plug-in you have here!
Is there a way to keep the hidden forums topic hidden?
Thanks
-Paul

Service Recovery Scripts & Error Page Tips.

A couple of weeks ago, I was proper ill with flu; the problem with looking after your own server is that only you can fix it – it’s well and good having monitoring systems (nagios) telling you about faults, but if you can’t read or see the alerts the fault won’t get resolved.

During this time I was ill, for an unknown reason the mySQL process on my server died, as such my website (and others I look after) were down for 8 hours. The fix was simple, one command, restart the service and normal service was resumed (excuse the pun).

This led to me to the conclusion that there must be a way to get the server to fix it’s self. after all, why do a job when you can get a computer to do it for you ! Fortunately I had a light bulb moment and realised that I could use the init scripts that are provided by redhat, the below code will restart apache (httpd) and mySQL on a redhat based system in the event that the service was not stopped cleanly. (In-fact this config has only be tested on CentOS, your mileage may vary on anything else)

#!/bin/bash

# taken from redhast default scripts - /etc/rc.d/init.d/functions

# Set up a default search path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
export PATH

status() {
        local base=${1##*/}
        local pid

        # Test syntax.
        if [ "$#" = 0 ] ; then
                echo $"Usage: status {program}"
                return 1
        fi

        # First try "pidof"
        pid=`pidof -o $$ -o $PPID -o %PPID -x $1 ||
             pidof -o $$ -o $PPID -o %PPID -x ${base}`
        if [ -n "$pid" ]; then
# Uncomment this if you want OK messages
#               echo $"${base} (pid $pid) is running..."
                return 0
        fi

        # Next try "/var/run/*.pid" files
        if [ -f /var/run/${base}.pid ] ; then
                read pid < /var/run/${base}.pid
                if [ -n "$pid" ]; then
                        echo $"${base} dead but pid file exists"
                        /etc/init.d/${base} restart
                        return 1
                fi
        fi
        # See if /var/lock/subsys/${base} exists
        if [ -f /var/lock/subsys/${base} ]; then
                echo $"${base} dead but subsys locked"
                /etc/init.d/${base} restart
                return 2
        fi
        echo $"${base} is stopped"
        return 3
}

# found in /etc/init.d/httpd
httpd=${HTTPD-/usr/sbin/httpd}

status mysqld
status $httpd

If you save this, as /etc/cron.hourly/auto_recovery.sh , then do chmod +x /etc/cron.hourly/auto_recovery.sh , assuming you’ve not changed the default cron setup, every hour mySQL & httpd will be checked, if they have died the’ll be restarted and root will get an e-mail about what happened.

Cool eh !

A final finishing touch: I wanted to change the default “Database Down” error messages on my two most popular applications.

  • Melvin Rivera has written a tutorial on how to customize the wordpress error page, note that it involves editing a file outside of wp-content, that means you’ll have to re-do this “hack” every time you upgrade wordpress.
  • PHPBB: Setting a custom error page on that is really easy, first create a php page displaying your message. Then at the bottom of /path/to/phpbb-install/includes/db.php you’ll see
    // Make the database connection.
    $db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
    if(!$db->db_connect_id)
    {
    message_die(CRITICAL_ERROR, "Could not connect to the database");
    }

    change it to

     // Make the database connection.
    $db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
    if(!$db->db_connect_id)
    {
     include("/path/to/my-custom-error-page.php");
            die();
    }

Now if you database dies, for the time it’s down (before cron fixes it) wordpress & phpbb sites would get a much prettier error message. Obviously there’s no solution for apache as there’s nothing to serve the pages, but hopefully this kind of thing doesn’t happen to often :D

Recent phpBB Topics on WordPress Plugin

UPDATE: This Plugin has been updated, the latest version is available on wordpress.org please comment on the new post, thanks.

Written primarily for my wife to use in the future, but I’ve developed a pluging that allows you to post a list of recent phpBB threads/topics within wordpress.

If found this plugin by Brandon Alexander but it wasn’t right for my needs, firstly he looks up usernames from phpBB, now my phpBB & wordpress installs don’t share databases and I thought it was a bit of a security risk giving wordpress access to my users password hashes… and secondly that plugin gives a list of recent posts, not what I wanted, and wanted threads (topics).

This is the 1st version, the massive fault with it is that you have to edit the file (to tell it where to find phpBB), I’m not yet smart enough to include an admin interface.

Installation: Download phpbb_recent_topics.txt and save as phpbb_recent_topics.php in your wordpress plugins directory. Edit the file, and change these bits to your appropriate settings…

$PHPBBDB = "phpbb_database"; // phpBB db name
$TOPIC_TABLE = "phpbb_topics"; // phpbb topics table
$SITEURL = "http://www.domain.com/phpbb"; //Forum (phpbb) URL

A bit about Database configuration.
If wordpress & phpBB share a DB already then set $PHPBBDB to DB_NAME and everything will be fine, else you’re going to need to GRANT the wordpress user read access to phpBB.

How to GRANT wordpress read only access to phpBB ?
If you don’t know it already you need to find your wordpress mysql user id, it’ll be in wp-config.php

define('DB_USER', 'wp_user');     // Your MySQL username

and you should have already found your phpbb database & table for the above.
You need to type the following syntax into your mysql database

GRANT SELECT ON phpbb_database.phpbb_topics TO wp_user@localhost;

this can be achieved by logging into phpmyadmin as your phpbb user, selecting SQL and pasting the correct GRANT into the text box.

Plugin Usage.
The plugin can be used in two ways, for those who don’t like editing templates you can call (type)

{phpbb_recent_topics}

from any post or page, and it will be replaced with an list of the last 5 topics.

For those who want to include the list in a sidebar template or similar, call the following function: phpbb_topics(), something like

 if ( function_exists('phpbb_topics') ) { phpbb_topics(5); }

where by the number 5 can be replaced with anything less that 10, and that’ll be the number of topics returned.

Hopefully that all makes sense, feel free to contact me with problems.

UPDATE: Comments about combatability issues here please.

Root Cookie WordPress – Plugin updated !

UPDATE: This Plugin has been updated, see please the new post, thanks.

Unless there’s a security risk, I’m always slow to upgrade my blog to the latest & greatest WP, the reason is plugins, when there’s a major revision update, plugins cause problems, so it’s usually best to wait for the maintainers to fix them before upgrading.

Anyway, I started to test the upgrade, and realised that I had a plugin that didn’t work, and yes you guessed it, it was the one I wrote ! – DOH !

It appears that v2.1 was more fussy about pluggable functions, but a quick fix and it’s done, so I give you…

Root Cookie, Version: 1.1

Standard wordpress plugin rules apply, save as root-cookie.php, stick it in your wp-content/plugins directly and activate, log-out (or clear your cookies) and when you log in you’ll get a cookie with the full domain path… happy days !

Avatar BBPress Plugin Browser

I’ve been playing with bbpress, by default there are no Avatars, I’ve made a little adjustment to the plugin by Joshua Hutchins

Here is my Forum Post: Avatar  bbPress plugin browser

I wrote an extra function for your plugin so that the avatar can be displayed on the profile page…

function profile_avatar() {
global $user;
if ( get_avatar_loc ( $user->ID ) ) {
echo ‘<img src=”‘ . get_avatar_loc( $user->ID ) . ‘” alt=”‘ . $user->user_login . ‘s Avatar”‘ . ‘ />’;
}
}

Styles & img sizes could be added into the tag as desired…. then in profile.php template, add…

<?php if ( function_exists(‘profile_avatar’) ) { profile_avatar(); } ?>

hope that helps :-)

k2 for bbPress

UPDATE: This theme has been updated, please see the new post, thanks.

K2 style for bbpress

I’m thinking about hosting a forum for some friends to use, so I thought I’d take a look at bbpress; I look after phpbb for my better half, and find the patching & modding a bit of a pain, the stuff photomatt does never lets me down, so I thought I’d take a look at his attempt at a forum.

For “regular” forum users I think they may find the interface a bit of a shock, but that doesn’t bother me, there are some features missing, but the community have been putting plugins together to plug the gap (poor, poor pun, sorry !).

The main thing I noticed was a lack of theme repository and EDIT: Theme & Plugin Repo here at http://proforums.palmansworld.com, I really hate green with an absolute passion, so although the default theme is slick, I couldn’t stand looking at the green ! Anyway, since this could be a service on my work in progress, I wanted it to match the k2 theme I’m using, I found there wasn’t one available to download, so to cut a long post short….

Download k2 for bbpress here

It’s a work in progress, there’s a demo available here sorry demo closed., I don’t think it’s a bad 1st crack !

EDIT: I’ve added a screenshot since the demo site will probably change is down.

Cookie Path Plugin For WordPress 2.0 (root Cookie)

UPDATE: This Plugin has been updated, the below links to the new file, but please comment on the new post, thanks.

I’ve been busy this AM, my site is a little bit integrated with WordPress, basically I call the header and footer from WP so that my custom code changes themes when WordPress does :)

I want to take it further and use the authentication cookie, so that my code recognizes me when I log in (in the same way WordPress does). In order for linickx.com to see the cookie set by linickx.com/blog, I need to change the COOKIEPATH. The change is actually quite simple, in fact the “set cookie” function is a pluggable one :D

The function / plugin I’ve written is really simple, all I’ve done is change the PATH to be / (root) that way linickx.com or linickx.com/blah can reference the cookie, and because it’s set to / the plugin can be used on any site !

To install:

  • Save root-cookie.txt in your plugins directory as root-cookie.php (Right Click – Save As)
  • From the Plugin Manager in the Dashboard, “Activate” the plugin
  • Log out, and log in again
  • Done

Now your cookie can be referenced from any custom code you may have written outside of your WordPress install directory !

h4x0r (Hacker) / The Matrix Theme for WordPress

My h4x0r Theme

I thought I’d try something different ;)

I’ve been playing with wordpress for nearly a year now, and thought it’d be cool to make a publicly available theme, I wasn’t sure on what to do so I thought I’d start with a simple pallet. My theme is a black on green code looking theme, you know the hacker site style; to make it more interesting I added some matrix references, and silly bits of php code.

The theme has been tested on wp 1.5 & 2.01 (including a blank one as requested on the codex) , there is a screenshot and I’ve also installed a theme switcher so you can demo it :D

h4x0r is available for download here, please let me know your thoughts.

Multiple Loops in WordPress

I wanted to run the wordpress loop on my php page more than once, & I don’t know if I’m the only person, but I found the offical multiple look example hard to swallow.

Google found is nima’s how to which was useful, but I wanted to take it further; the problem was I wanted a function.

This is what I came up with:

<?php
require(‘path_to_wordpress/wp-blog-header.php’);
?>

<?php
function show_posts_from_cat($MYCAT){

?>

<ul>
<?php if (have_posts()) : ?>

<?php $my_query = new WP_Query(“category_name=$MYCAT”); ?>

<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li>

<span class=”my-post-title”>
<span id=”post-<?php the_ID(); ?>”><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></a></span>
<!–
<?php trackback_rdf(); ?>
–>
</span>
<small><?php the_time(‘jS F Y’) ?> <!– by <?php the_author() ?> –></small>
</li>

<?php endwhile; ?>

<?php else : ?>

<h2 class=”center”>Not Found</h2>
<p class=”center”><?php _e(“looks like there aren’t any related posts.”); ?></p>

<?php endif; ?>

</ul>

<?php
}
?>

So here’s what I found, if you just run the wordpress loop twice, the second time you run it, it’ll fail :s so my function creates a new object each time you run the loop. The object is then used to display the results, the benefit being ,each time you call the function it over-writes the object with the new results, allowing you to call the function as many times as you like, and generating fresh results every time :D

function usage: show_posts_from_cat(“Category_name”);

Good luck, let me know if you have ant problems.