Code Poetry Redeux, Ryans Response

August 20th 2010

As usual, ryan wins this round.

<?php
//jackandjill.php
$kidsnames = $_SERVER['PHP_SELF'];
$kidsnames = basename($kidsnames, ".php");
$firstkid = substr($kidsnames,0,4);
$joinword = substr($kidsnames,4,3);
$secondkid = substr($kidsnames,7,4);
$kidsnames = $firstkid . " " . $joinword . " " . $secondkid;
function makewherecode($whereto){
if($whereto == "halibel"){
$newplace = substr($whereto,0,1);
$newplace = $newplace . substr($whereto,3,1);
$newplace = $newplace . substr($whereto,2,1);
$newplace = $newplace . substr($whereto,2,1);
return $newplace . "\n";
}
}
function hextostr($hex)
{
    $string='';
    for ($i=0; $i < strlen($hex)-1; $i+=2)
    {
        $string .= chr(hexdec($hex[$i].$hex[$i+1]));
    }
    return $string;
}
$rhyme =  nl2br($kidsnames . " went &uarr; a " . makewherecode("halibel"));
$getting = array("pail","water");
$line = "to fetch a " . $getting[0] . " of " . $getting[1];
$rhyme = $rhyme . $line . "<br>";
$line = $firstkid . " fell &darr; <br>";
$rhyme = $rhyme . $line;
$brokewhat = "63726f776e";
if (hextostr($brokewhat) == "crown"){
$line = $joinword . " broke his " . hextostr($brokewhat);
}
$rhyme = $rhyme . $line . hextostr("3c62723e");
$line = $joinword . " " . $secondkid . " came tumbling after.";
$rhyme = $rhyme . $line;
echo $rhyme;
?>
View Comments

Code is Poetry example? Ryan is Challenged!

August 19th 2010

The gauntlet has been dropped, Ryan has been challenged!

<?php
//im-a-little-teapot.php
$whatami = $_SERVER['PHP_SELF'];
$whatami = basename($whatami);
$whatami = basename($whatami, '.php');
$im = str_replace("-", " ", $whatami);
function what_do_i_do($var, $poem) {
	if (strripos($var, "teapot")) {
		return nl2br($mypoem = $poem . "when i get all worked up");
	}
}
$im != "im a little teapot" ? die : $mypoem = $im . "\n short and stout\n"; $teapot = "me";
$container = array("handle", "spout");
foreach ($container as $part) {
	$mypoem = $mypoem . "here is my " . $part . "\n";
}
echo what_do_i_do($im, $mypoem);
if (empty($error)) {
	trigger_error("YOU BETTER WATCH OUT!", E_USER_WARNING);
	$mypoem = "TOOOOOOT! \n";
}
echo nl2br($mypoem . "tip " . $teapot . " over and pour " . $teapot . " out");
?>
View Comments

Tumblr Style Chat Posts for WordPress

August 15th 2010

The problem with Tumblr, for me anyway, is the loss of direct control over the code and ability to host my submissions locally. I know tumblr has been around for a while and it doesn’t look like it’s going anywhere, but anyone who has been on the net for a while knows that just because a site is here today, that doesn’t mean it will still be here tomorrow. Tumblr doesn’t have an export option, so needless to say I’m a little wary about posting anything I might want to be able to look at or back reference a few years from now. Does anyone remember scribble.nu, run by Dustin Vannatter1 of the then OHHELLO network (Swank Army!). It was one of the first blogging platforms, before blog’s were even called blog’s and they were still just called journals. For a time everyone who was anyone had a scribble.nu journal running inline with their current site. The same goes for sites like MODblog2, from Mike Pacific and Gorman of DeskMOD3 fame. I’m sure everyone has sites they have used at one time that just couldn’t handle the traffic or for one reason or another just died a unfortunate death.

I’ve have been toying around with Tumblr a little bit recently though and I am enjoying how it automatically handles different types of content and formats it without any thought on my part. Right now this is something that is still lacking in WordPress, which I touched base in a round-about way on my last post.4

Tumblr makes it incredibly easy to post different types of submissions and have them styled automatically without any per-entry coding, not forcing us to remember which posts require what custom fields like we have to do in WordPress. I had thought WordPress 3.0 was going to help solve some of these problems by introducing Custom Post Types, but unfortunately it’s still not quiet there yet and Custom Post Types aren’t quiet what some of us expected them to be (although the new functions are extremely useful if you use them in the way they were designed for).

So, as part of a larger project I have been working on, here is a quick and easy way to implement tumblr-esque “chat” posts into your site. The following code will take any content between the [chat] and [/chat] shortcodes, automatically format it and apply a specific style. Currently it sorts anything that matches into relevant DL and DT html tags, and applies a highlight class to every other row. So very quickly I can turn this:

Fight Club (1999)
Narrator: You’re making a big mistake, fellas!
Police Officer: You said you would say that.
Narrator: I’m not Tyler Durden!
Police Officer: You told us you’d say that, too.
Narrator: All right then, I’m Tyler Durden. Listen to me, I’m giving you a direct order. We’re aborting this mission right now.
Police Officer: You said you would definitely say that.

Into something a little prettier, like this:

Fight Club (1999)

Narrator:
You’re making a big mistake, fellas!
Police Officer:
You said you would say that.
Narrator:
I’m not Tyler Durden!
Police Officer:
You told us you’d say that, too.
Narrator:
All right then, I’m Tyler Durden. Listen to me, I’m giving you a direct order. We’re aborting this mission right now.
Police Officer:
You said you would definitely say that.
function tumblr_chat_post_shortcode($atts, $content=null) {
$chatoutput = "<dl class=\"chat-transcript\">\n";
$split = preg_split("/(\r?\n)+|(<br\s*\/?>\s*)+/", $content);
	foreach($split as $haystack) {
		if (strpos($haystack, ":")) {
			$string = explode(":", trim($haystack), 2);
			$who = strip_tags(trim($string[0]));
			$what = strip_tags(trim($string[1]));
			$row_class = empty($row_class)? " class=\"chat-highlight\"" : "";
			$chatoutput = $chatoutput . "<dt$row_class><strong>$who:</strong></dt> <dd>$what</dd>\n";
		}
		else {
			// the string didn't contain a needle. Displaying anyway in case theres anything additional you want to add within the transcript
			$chatoutput = $chatoutput . $haystack . "\n";
		}
	}
// print our new formated chat post
$content = $chatoutput . "</dl>\n";
return $content;
}
add_shortcode("chat", "tumblr_chat_post_shortcode");

If shortcodes just aren’t your style and you want something to work on posts transparently, that’s not very difficult either. All we have to do is create a new category (in this example we are using “chats”), and the code posted below will automatically process and format any submissions. Using the built in add_filter functions wordpress provides, it’s easy to modify content before it gets displayed to the browser, allowing us a way to format posts differently based on the category they are in.

function tumblr_chat_post($content) {
global $post;
	//$content = $post->post_content;
	if ($post->post_type == 'post') {
		$postcats = wp_get_object_terms($post->ID, 'category');
		foreach ($postcats as $mycat) {
			if ($mycat->name == "chats") {
			remove_filter ('the_content',  'wpautop');
				$chatoutput = "<dl class=\"chat-transcript\">\n";
				$split = preg_split("/(\r?\n)+|(<br\s*\/?>\s*)+/", $content);
					foreach($split as $haystack) {
						if (strpos($haystack, ":")) {
							$string = explode(":", trim($haystack), 2);
							//list($who, $what) = explode(":", $haystack, 2);
							$who = strip_tags(trim($string[0]));
							$what = strip_tags(trim($string[1]));
							$row_class = empty($row_class)? " class=\"chat-highlight\"" : "";
							$chatoutput = $chatoutput . "<dt$row_class><strong>$who:</strong></dt> <dd>$what</dd>\n";
						}
						else {
						// the string didn't contain a needle. Displaying anyway in case theres anything additional you want to add within the transcript
							$chatoutput = $chatoutput . $haystack . "\n";
						}
					}
					// print our new formated chat post
					$content = $chatoutput . "</dl>\n";
					return $content;
			}
			else {
			add_filter ('the_content',  'wpautop');
			// I don't exist in the defined category, so no processing is needed
			return $content;
			}
		}
	}
	else {

		// I'm not a regular post, so no processing is needed.
		return $content;
	}
}
add_filter( "the_content", "tumblr_chat_post", 9);

Either of these functions can be placed in your themes function.php file and will work automatically as long as your chat transcripts are formatted in a Name: Message structure. This is a fairly simple example on how to use wordpress hooks and shortcodes to modify your post before it gets outputted to the browser, which provides us with some interesting ways to implement specific styled post types without hacking apart the “Custom Post Type” functions WordPress released with version 3.0, something that is just not suited very well or meant for for these type of tasks.

  1. Dustin.Vannater.com : Things I’ve Done []
  2. Interview of Mike Pacific from DeskMOD.com []
  3. Stamford Advocate: Danbury man manages Web Site from his bedroom []
  4. The Problem with WordPress Custom Post Types []
View Comments

The Problem with WordPress Custom Post Types

August 12th 2010

Xzibit Moddin My WordPress!

A lot of “names” in wordpress on the net are politely bashing people because they are trying to use Custom Post Types in the wrong way, but really in my (and clearly a lot of other users) opinions, what they are trying to do is what should be defaultly working in the first place.

Custom post types should be exactly that, custom post types. It should give me the ability to define a custom submission area with specific meta content completely separated from the normal “Submit New Post” area. If you have ever built something for a client, and not just for personal use, you would see how extremely useful this would be. But what we have now with this new feature isn’t custom “post” types like it’s named, it’s actually custom “content” types.

Right now we are stuck with using custom fields and trying to explain to clients in explicitly detailed instructions how to properly define key pairs for specific post types that all still need to be displayed inline with the regular “blog”. Why is it so hard for people to understand that being able to use custom post types as an ability to specifically define certain REAL post submission meta boxes and separate them out in the dashboard is a useful thing.


Continue reading “The Problem with WordPress Custom Post Types” »

View Comments

Transparent PNG background turns into a Gradient in IE8 – Fixed

August 9th 2010

While cross checking between Firefox and IE8 I came across an odd bug on a site I was working on. Whenever I tried to apply Internet Explorers gimped css opacity settings to a block level element that was wrapped by another div with a Alpha Transparent PNG background, the container background would gradient/fadeout from left to right, rather than displaying the alpha transparent png in it’s normal state. For example:

PNG Trasparency shows correctly in Firefox

PNG Trasparency shows correctly in Firefox

Alpha Transparent PNG shows as Gradient in IE8

Alpha Transparent PNG shows as Gradient in IE8


Continue reading “Transparent PNG background turns into a Gradient in IE8 – Fixed” »

View Comments

July Desktop, Litestep Enabled Win7 x64bit

July 30th 2010

Litestep theme: Switch LS [link]
Visual Style: 7Pro Final for Win7 x64bit [link]
Firefox Theme: Deuces [link]
Wallpaper: The Great Wave off Kanagawa [link]
Ad-Free MSN Live Messenger thanks to A-Patch (Lite)

View Comments

Jasmin 3DCC Download

July 30th 2010

Finally found a download link for the oldschool 3DCC, a color changer utility for windows classic type themes.

http://dl.dropbox.com/u/1840925/3dcc4-en.zip

Many thanks goes to bernadinho over at pixelfuckers for sharing the dropbox link.

View Comments

Never go to bed angry

June 9th 2010

Never go to bed angry… stay up and plot your revenge.

View Comments

Craft Store Frogs

February 27th 2010

Whenever I find myself in a craft store I always browse through the patterns and imagine Grandma making me a giant Frog Suit.

View Comments

Stardock Multiplicity on Windows 7 or XP

January 28th 2010

Recently switched my secondary PC over to Windows 7 as well, and besides the headache from getting that playing nice and sharing with my other XP box, I was having some trouble getting Multiplicity to connect correctly between the two Windows 7 boxes and the XP box.

Sadly I found myself getting this unhelpful message:

Multiplicity has been unable to connect to the secondary machine.

If you have not yet installed Multiplicity on the secondary machine, this is perfectly normal.

If you have installed it and rebooted after installation, are you sure you have set the ip address, port, & password correctly?

It turns out there’s a fairly known issue with the services not installing/starting correctly, and lucky for me theres a simple fix that solved my problem right off.

If your having trouble connecting with Multiplicity between Windows 7 and XP, try the following bat file Mike from Stardock put together:

http://sd.stardock.com/mike/apps/reinstall_mpp_service.bat

View Comments