Let’s Play a Game

Question: What causes the following error in Apache’s error logs?

[IP_address] Undeclared entity warning at line 226, column 1

Answer: A fairly popular, yet, poorly written WordPress plugin.

The first time this error hit the Weblogs.us error_log, one had no clue what was causing it. Unfortunately, the error does not indicate what file triggers the error. However, it will include the referring URI, if applicable. That’s how one found the specific virtual host on the Weblogs.us server that was triggering the error. Next, was finding the infringing code. To do this, one added define('WP_DEBUG', true); to the wp-config.php file for the virtual host. Now, there will be an avalanche of errors and warnings for most sites, all that needs to be done is sift through them and look for ones like “undeclared variable” and “undeclared index”.

Now, what was the actual culprit? The Twitter-for-Wordpress plugin. Specifically, lines 100, and 158. Line 100 tries to increment a non-initialized variable. To fix the issue on line 100, add a new line between line 66 and 67 and place in it $i = 0;. The error on line 158 is it tries to use the undeclared variable $username. What probably happened was author copied the line directly from line 53, while not properly modified for its location. Line 158 should read:
$messages = fetch_rss('http://twitter.com/statuses/user_timeline/'.$item['username'].'.rss');

After these two changes everything should be good to go. Yes, the plugin author was notified of these problems. We’ll see when they officially get fixed in the plugin.

-John Havlik

[end of transmission, stay tuned]

Keep a Page Out of the Breadcrumb Trail

Note: This guide is only valid for versions of Breadcrumb NavXT prior to 4.0. Since Breadcrumb NavXT 4.0 the bcn_after_fill action should be used to remove breadcrumbs from the breadcrumb trail.

In the past, several users have asked how to exclude certain pages from the breadcrumb trail generated by Breadcrumb NavXT. As with most programming problems, many solutions exist to this problem. Previously, one posted code that removed the breadcrumb from the bcn_breadcrumb_trail::trail array before calling bcn_breadcrumb_trail::display(). However, since the introduction of Breadcrumb NavXT 3.0 a much better solution exists. This method uses the inheritance principle of OOP and requires no editing of the distributed files.

Code in this tutorial was written against the SVN Trunk version of Breadcrumb NavXT (the basis or Breadcrumb NavXT 3.3.0). Therefore, any code contained herein will require some modifications to work with Breadcrumb NavXT 3.2.x. The general process, however, is the same for any version of Breadcrumb NavXT since 3.0.0. Also, note that you must have a PHP5 environment for this to work as it requires the PHP5 object model.

First, open the functions.php file of your theme. Within it we are going to create a new class named ext_breadcrumb_trail, and tell PHP that it is an extension of the bcn_breadcrumb_trail class. We’ll place the skeleton for the class constructor in at this time as well.

class ext_breadcrumb_trail extends bcn_breadcrumb_trail
{
	//Default constructor
	function __construct()
	{
		//Need to make sure we call the constructor of bcn_breadcrumb_trail
		parent::__construct();
	}
}

We need a way to get the IDs that will be excluded from the trail into the class. They could be hard coded into the class, but that is not very extensible (and a very bad coding practice). Instead, a public member variable named $excluded_ids will be added to store the IDs. Now, we should have the constructor accept IDs to exclude and store them in $excluded_ids. Our code now looks similar to the following:

class ext_breadcrumb_trail extends bcn_breadcrumb_trail
{
	public $excluded_ids = array();
	//Default constructor
	function __construct($excluded_ids)
	{
		//Set the value of
		$this->excluded_ids = $excluded_ids;
		//Need to make sure we call the constructor of bcn_breadcrumb_trail
		parent::__construct();
	}
}

Now that the IDs of pages to be excluded can get into the class, we need to do something with them. We want to override the function bcn_breadcrumb_trail::page_parents() since it does not know how to exclude pages. To start, we’ll copy the code for page_parents from the class bcn_breadcrumb_trail into our new class. This is the result:

class ext_breadcrumb_trail extends bcn_breadcrumb_trail
{
	public $excluded_ids = array();
	function __construct($excluded_ids)
	{
		$this->excluded_ids = $excluded_ids;
		parent::__construct();
	}
	/**
	 * page_parents
	 *
	 * A Breadcrumb Trail Filling Function
	 *
	 * This recursive functions fills the trail with breadcrumbs for parent pages.
	 * @param  (int)   $id The id of the parent page.
	 * @param  (int)   $frontpage The id of the front page.
	 */
	function page_parents($id, $frontpage)
	{
		$parent = get_post($id);
		//Place the breadcrumb in the trail, uses the constructor
		$breadcrumb = $this->add(new bcn_breadcrumb(apply_filters('the_title', $parent->post_title), $this->opt['page_prefix'], $this->opt['page_suffix']));
		//Assign the anchor properties
		$breadcrumb->set_anchor($this->opt['page_anchor'], get_permalink($id));
		//Make sure the id is valid
		if($parent->post_parent >= 0 && $parent->post_parent != false && $id != $parent->post_parent && $frontpage != $parent->post_parent)
		{
			//If valid, recursively call this function
			$this->page_parents($parent->post_parent, $frontpage);
		}
	}
}

Now, it’s time to modify the page_parents() function. We’ll use ext_breadcrumb_trail::excluded_ids and the PHP function in_array() to skip the breadcrumb insertion step for pages that are to be excluded from the trail. We do this by wrapping the two lines of code containing the variable $breadcrumb within a branch of an if statement. Within the if statement we’ll use $id and $this->excluded_ids as the parameters for in_array(). Since we want the branch to run if the ID is not an excluded ID, we’ll place the not operator (!) in front of in_array. At this point, we have the final version of our class that is ready to use.

class ext_breadcrumb_trail extends bcn_breadcrumb_trail
{
	public $excluded_ids = array();
	function __construct($excluded_ids)
	{
		$this->excluded_ids = $excluded_ids;
		parent::__construct();
	}
	/**
	 * page_parents
	 *
	 * A Breadcrumb Trail Filling Function
	 *
	 * This recursive functions fills the trail with breadcrumbs for parent pages.
	 * @param  (int)   $id The id of the parent page.
	 * @param  (int)   $frontpage The id of the front page.
	 */
	function page_parents($id, $frontpage)
	{
		$parent = get_post($id);
		//Check if the current page should be excluded
		if(!in_array($id, $this->excluded_ids))
		{
			//Place the breadcrumb in the trail, uses the constructor
			$breadcrumb = $this->add(new bcn_breadcrumb(apply_filters('the_title', $parent->post_title), $this->opt['page_prefix'], $this->opt['page_suffix']));
			//Assign the anchor properties
			$breadcrumb->set_anchor($this->opt['page_anchor'], get_permalink($id));
		}
		//Make sure the id is valid
		if($parent->post_parent >= 0 && $parent->post_parent != false && $id != $parent->post_parent && $frontpage != $parent->post_parent)
		{
			//If valid, recursively call this function
			$this->page_parents($parent->post_parent, $frontpage);
		}
	}
}

Next, we need to modify the breadcrumb trail calling code in the theme. Assuming that the theme directly calls the bcn_breadcrumb_trail class, very little has to be modified. We just replace all instances of bcn_breadcrumb_trail with ext_breadcrumb_trail in the calling code. Additionally, when creating the new instance of ext_breadcrumb_trail we need to feed in our array of IDs of pages to be excluded. An example calling code block is located below, in it pages with ID equal to 100, 230, or 231 will not show up in the breadcrumb trail except when they are the current page.

if(class_exists('ext_breadcrumb_trail'))
{
	//Make new instance of the ext_breadcrumb_trail object
	$breadcrumb_trail = new ext_breadcrumb_trail(array(100,230,231));
	//Setup options here if needed
	//Fill the breadcrumb trail
	$breadcrumb_trail->fill();
	//Display the trail
	$breadcrumb_trail->display();
}

In this tutorial we never modified any of the actual plugin files. This was made possible due to inheritance through the creation of a derived class. Since no plugin files were modified, upgrading to new versions of Breadcrumb NavXT are less likely to break the functionality. Finally, this method can easily be modified to exclude categories instead of pages from the breadcrumb trail (replace page_parents with category_parents).

-John Havlik

[end of transmission, stay tuned]

Breadcrumb NavXT 3.2.1

This first service release for the 3.2 branch of Breadcrumb NavXT includes many bug fixes. The bcn_display() and bcn_display_list() wrapper functions obey the $return parameter. Checks are now made to ensure anchor titles remain valid, even when the title of the page has HTML in it. Many fixes involving the import feature are included. Previously, the importer did not handle html entities correctly causing all sorts of problems. Translations for the Belorussian language are now included thanks to “Fat Cow”. Lastly, the administrative interface should work (sort of) with WordPress 2.6 again, do note that in Breadcrumb NavXT 3.3.0 WordPress 2.7 will be required.

You can grab the latest version of Breadcrumb NavXT from the Breadcrumb NavXT page.

-John Havlik

[end of transmission, stay tuned]

Truly Addicting

Once you have a HTPC you’ll never go back to regular television. The media center features of Vista were a component one never tested three years ago in the Vista Beta/RC rounds. At the time one did not have a TV tuner. This time around, with two tuners at hand (the HVR 2250 and the PCTV 800i) one is much better equipped to test media center.

On Saturday, one built a quite modest HTPC setup with a Celeron 430 (OC’d to 2.4Ghz), Intel’s DQ45EK motherboard, 2GiB of ram, a Western Digital Scorpio 120GB hard drive, and a 150W picoPSU. The ram was temporarily robbed from one’s desktop as the other sticks of DDR2 sticks would not work (Intel motherboards are picky about speed and voltages). A full 2x2GiB DDR2 kit is on its way, hopefully it’ll be here on Thursday. The HVR 2250 was placed in this computer as it has dual built in MPEG2 encoders (also it is the only one that is a PCIEx1 card).

After installing Windows 7 RC, about a 30 minute process, one fired up Windows Media Center. Setup of the TV tuner was pretty automated, a few clicks here and there and it was ready to go. Scanning the cable connection for channels took the longest amount of time, a good 15 minutes. At this point all of the analog cable channels worked perfectly. However, Mediacom simulcasts the local channels in 720p or 1080i in unencrypted QAM256. Media Center did not immediately acknowledge the existence of these channels. They were not even in the TV Guide configuration menu. However, there is a manual channel adding option, which is what one had to use. After adding the channels, and associating them with the proper channel listing in the TV Guide everything was a go.

Well, almost everything, the local NBC affiliate does not come in (at this TV it’s channel is usually 112.2, everywhere else in the house it is 112.4 neither work for the HTPC). Regardless, the Celeron and Intel GMA4500 graphics are sufficient for HD decoding and display on a 720p screen (actually a tad bigger pixel wise) while simultaneously recording an analog cable program. At this point one realized more disk space was necessary, and attached an empty 250GB Western Digital Caviar RE in an external enclosure (now that’s about half full).

On to the PCTV 800i. For the last year-and-a-half it has been sitting on the shelf. Sadly, it is only a single tuner, and does not have a hardware MPEG2 encoder for its analog tuner. Thus, it requires a beefier processor to work. Hence, it went in one’s desktop, even though the E8500 is overkill for it. Unlike the HVR 2250, which was literally plug-and-play, the PCTB 800i drivers that Windows 7 installs do not support Clear QAM. Instead, for the digital tuner an unsigned driver must be installed. This means for the digital tuner to work on every boot one has to press F8 and tell Windows to load unsigned drivers, a royal pain.

The upside to the PCTV 800i is once the driver situation was ‘resolved’ Media Center found the Clear QAM channels right away. One still had to associate them to the proper listing, but it was one less step. At this point everything was working as expected.

The only time one has had Windows 7 crash is with Media Center. Both boxes have had their video drivers crash and recover due to Media Center. This occurs occasionally when playing recoded TV and skipping around too fast (more likely to happen if skipping about 10 minutes or more of video right after opening the file). The Celeron box actually presented the BSOD tonight, after being on for about 36 hours. Again, one was trying to skip around recorded TV too soon after opening the file.

TV Guide Background Image Corruption

TV Guide Background Image Corruption

Additionally, the image overlays for the TV Guide occasionally get corrupted. This occurs more often on the Celeron box, but both have exhibited this problem. Since Windows 7 is only a Release Candidate, bugs are to be expected. Hopefully, Microsoft fixes this by the time Windows 7 hits the shelves in early October.

-John Havlik

[end of transmission, stay tuned]

Windows 7 RC 1

Of course, Windows 7 RC1 is already installed on one’s desktop. This time around, Microsoft used the Java applet download manager, the same Adobe uses for CS4 trials. Downloading was a breeze, one was able to pull through 800KB/s the entire time. Installation went just a smoothly as before. Getting the Netgear WPN111 to work required the same steps as before.  Battlefield Heroes works fine, as does Test Drive Unlimited. Other than not being able to play any game that relies on PunkBuster, one finds little reason to hate Windows 7 (and even there one blames Even Balance for their own incompetence).

Again, PunkBuster is not working. Some are claiming success by scattering the PnkBusterA.exe and PnkBusterB.exe files in various folders and modifying the registry. It also requires a reboot and running a script after rebooting, and after each subsequent reboot. Now that Windows 7 is in the release candidate phase, hopefully Even Balance will get their heads out of the sand and get to work (one expects PunkBuster to work perfectly on the day Windows 7 is available in any form at a retail store (be it new computer or retail software)).

The mouse gestures for expanding windows is very handy, especially the ability to make a window open to half the screen width on one’s LP2475W. It’s not the only thing one really enjoys about Windows 7, but it is one thing that really makes XP painful to use after becoming accustomed to Windows 7.

-John Havlik

[end of transmission, stay tuned]

Tagged:
Updated: