Mostly Harmless

Archive for the ‘Software’ Category

Threaded comment are fixed  

Opensource software is best.

Using a comment callback function in WordPress 2.7, I was trying to customize the threaded comments and ran into a problem. So I left a comment on Jeremy’s blog. He contacted me and was able to find the problem and provide a fix.  His post has been updated with that small change and it’s all good.

Very cool, you can’t get that kind of response from any software company. I’ll keep playing around with the comment format, but now I can implement anything I like and take full advantage of the threaded comment feature.

The article has

no responses yet

Written by Jan Dembowski

January 6th, 2009 at 10:56 am

Posted in Geek, Software

Tagged with ,

Odd way to end a vacation  

I’ve been on vacation since right before Christmas and have enjoyed the time off. Monday I go back to work all refreshed and ready to go.

After our New Years Eve party, I spent the day doing somethings that had meant to do for a while: PHP coding for my WordPress blog. My PHP fu is not that great but this is how I learn and as hobby’s go, it’s almost productive. Starting with easy ones and working my way down, the list looks like this.

1. Clean up my theme directory.

I make changes to my theme all the time and left junk in the theme directory. There is junk in there from plugins that I was experimenting with, looks that I was trying to accomplsh, etc. I can’t remember it all but I know what I need to keep and my backups are good and current.

2. Setup my Flickr badge as a WordPress plugin to put a widget in the sidebar.

I was using a text widget and hard coded the CSS into my theme’s header.php so that the page would validate properly. That worked but if I changed themes, the styling went out the window.  I had wanted to see how to create a widget plugin that inserted the CSS using the wp_head action. By looking at existing plugins I saw how and it’s not hard at all.

Now I can keep the widget no matter which theme I choose and it always validates. Next up to add options in the widget. I’m looking at the Flickr Widget to see how it’s done there. Having GPL’ed code available to examine makes life so much easier.

I want to get an options page just for giggles; I don’t plan on distributing the code since I’m re-using Flickr’s code from here.

3. And now the big one: Fix my comment CSS and get WordPress 2.7 threaded comment callback working properly.

WordPress 2.7 comes with the option of using threaded comments and getting the default output just needs these lines:

1
2
3
<ul class="commentlist">  
<?php wp_list_comments(); ?>  
</ul>

This produces good valid XHTML output and all that is required is to style it anyway you want. With some CSS I get this:

comment-thread

It’s really easy to do and between Otto and Chris Harrison’s posts, getting it looking good is simple. If you want to learn then visit those two sites and start playing with your theme.

Now if you want to explicitly control the output for threaded comments, you need to use a callback as outlined in Jeremy’s post. I’m adding a comment count and trying to keep the look close to the original theme’s styling. By inserting the theme’s original comment code I can maintain the look.

In my comments.php file I comment out the old line and add one to use the callback.

1
2
3
4
<ul class="commentlist">
<?php // wp_list_comments(array('avatar_size'=>40,'reply_text'=>'Reply to this comment')); ?>
<?php wp_list_comments('callback=custom_comment'); ?>
</ul>

In my function.php file I’m adding this code.  Be warned, I am not a PHP programmer and if anyone sees something really gross please feel free to criticize. The $cmtorder is more of a placeholder and I’m not using it yet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
function custom_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<?php global $cmtcount; ?>
<?php
$pageadd = 1;
if(get_option('page_comments')) :
$page = get_query_var('cpage');
$pageadd = (get_option('comments_per_page') * ($page - 1)) + 1;
$cmtorder = get_option('comment_order');
endif; ?>
 
<li id="comment-<?php comment_ID() ?>" class="<?php echo tj_comment_class() ?>">
<div class="commentNumber">#<a href="#comment-<?php comment_ID() ?>"><?php echo $cmtcount + $pageadd; ?></a></div>
<div class="comment_mod">
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
</div>
 
<div class="comment_text">
<?php comment_text() ?>
</div>
 
<div class="comment_author">
<?php if (function_exists('get_avatar')) { ?>
<?php echo get_avatar($comment, '32'); ?>
<?php } ?>
<p><strong><?php comment_author_link() ?></strong></p>
<p><small><?php comment_date('j M y') ?> at <?php comment_time() ?> <? edit_comment_link(__('Edit', 'sandbox'), ' ', ''); ?></small></p>
</div>
<div class="clear"></div>
 
<?php echo comment_reply_link(array('before' => '<div class="reply">', 'after' => '</div>', 'reply_text' => 'Reply to this comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ));  ?>
<?php $cmtcount = $cmtcount + 1; ?>
<?php } ?>

This gets the comments formatted close to the theme’s original comments but adds threading.  I added the comment count as a “why not?”  If you turn on paged comments the comment counter still work. I have not worked out changing the order yet, I’d like to see it working in reverse order if set.

comment-thread-callback

The code is a bit ugly and I’ll clean it up later. It works and I’m not getting and errors in my log so I’m happy for now. The CSS is good and the generated XHTML code is valid.

My only problem is that the javascript reply to comment box is not working exactly the way I want it to.

When you click on the “Reply to this comment” link, the comment box show up outside of that comment’s <li> … </li>. This is probably due to how I’m using comment_reply_link() but right now the codex is a little bit sparse on that topic. I’ve looked at the source code and by changing the parameters, I do get different results, just not the results I want. If I don’t use the callback, the comment box appears within that comment’s <li> … </li>.

I’ll keep playing with it and will be switching them back and forth until I like the output.

The article has

no responses yet

Written by Jan Dembowski

January 3rd, 2009 at 10:25 am

Posted in Geek, Software

Tagged with , ,

SVN says WordPress 2.7 is out  

I just did another ’svn up’ and the WordPress version is now 2.7.  In a little while I’ll switch this blog to 2.7 using ’svn sw http://svn.automattic.com/wordpress/branches/2.7′.

The article has

no responses yet

Written by Jan Dembowski

December 10th, 2008 at 7:51 pm

Posted in Asides, Geek, Software

Tagged with ,

WordPress 2.7 is shaping up nicely  

I’ve had this blog on WordPress 2.7-beta using SVN for a while. So when it went release candidate, all I had to do was another just run another “svn up”.

The comment enhancements are cool and Otto provided a good write up for modifying the files to take advantage of it. Implementing it and staying XHTML valid was not a problem.

My problem was that without styling it, the new comments looked like crap.

Lucky on the WordPress support forums I found that Chris Harrison mapped out all the CSS for the comment list. Adding the elements that he provided let me easily make changes and get the comments close to the original look.

I still need to play around with it but so far I’m satisfied with the results.

The article has

2 responses

Written by Jan Dembowski

December 4th, 2008 at 10:29 pm

Posted in Geek, Software

Tagged with ,

WordPress 2.7 beta 3 is looking good  

I’ve been using WordPress 2.7 beta for a week now and the new layout is very easy to get used to.  So far so good.

I think a lot of people will revolt, cry, wail, and moan complain about the GUI changes and will probably demand their money back.  But 2.7 is looking to be the best version yet.

The article has

2 responses

Written by Jan Dembowski

November 15th, 2008 at 5:16 pm

Posted in Geek, Software

Tagged with , ,

Cleaning up the WP database  

WordPress blogs are based on MySQL and all the dynamic content is stored in a database. After trying out plugins, odd themes, and generally screwing around, my database has items in it that I can’t even recall what they were or if I need them.

One way to clean out the database is to export the blog to an XML file.  This will produce the posts, pages, and all the comments and not export the ton of junk in the database.  This way I create a clean empty blog, add the users, set up the theme and look I want and import the data.

This produces a very clean installation. It also removes me as the author for the comments I’ve left on my own blog. The table wp_comments table has a user_id field that the XML file does not have.

What I wanted to do is run a MySQL command that will find all instances in wp_comments which match my e-mail address, and update that record with my user_id on the blog. I could do this one at a time using phpMyAdmin but that’s pretty inefficient, not geeky, and time consuming.

After some research I found out to run these commands:

$ mysql -p
USE blogdatabase;
Database changed
SELECT * FROM wp_users WHERE user_email = 'notreally@myemail.com';

That gets me the ID number for my user.  Since it’s the first user created the ID is 2.

UPDATE wp_comments SET user_id = 2
WHERE comment_author_email = 'notreally@myemail.com';
Query OK, 113 rows affected (0.00 sec)
Rows matched: 113  Changed: 113  Warnings: 0

This updates the wp_comments table so comments left by me using my e-mail address.

The article has

no responses yet

Written by Jan Dembowski

October 15th, 2008 at 10:24 pm

Posted in Geek, Software

Tagged with ,

Upgrade of VPS from Ubuntu 6.06 LTS to 8.04 LTS  

My upgrade from Ubuntu 6.06 LTS = FAIL.

Last week I created a VPS on Slicehost.  I’ve been using Tektonic for a while now and have no complaints.  The support is very good and I can backup my VPS for when I need to.

I’m using Slicehost because I don’t want both of my domain DNS servers on the same provider. They offer Ubuntu 8.04 LTS, runs on top of Xen, and provide console access via an Ajax web front end.  You need to pay extra for a backup option. Aside from that one little point, using Slicehost is ridiculously easy and very manageable. They eat their own dog food and it shows.

On my Tektonic VPS it’s running on top of Virtuozzo.  No console just ssh but I do get to make a backup of my VPS and re-installing is a breeze. My only complaint is that it’s running Ubuntu 6.06 LTS which is a little dated.  For example the subversion client is 1.3.2 and I’d like to see more current versions such as 1.5.x.  On Ubuntu 8.04 LTS I just added the backports repository and I get current versions of packages.

Switching to Ubuntu 8.04 LTS should be simple. As root I ran these commands:

apt-get update
apt-get upgrade
apt-get install update-manager-core
do-release-upgrade

This is a seamless process and aside from asking me some questions, I had no issues.  The only issue I had is when I rebooted my VPS, it left the VPS un-bootable.  The support tech that I chatted with had not seen that before.  My VPS would not even start and I had to re-install it.

I’m now restoring the VPS to the backup I made yesterday, so it’s not all a total wash.  Most likely I’ll work with Tektonic to get 8.04 LTS on that slice provided they offer it.  Ubuntu 6.06 LTS is still supported so aside from consistency across servers, this is not a big deal for me.

The article has

3 responses

Written by Jan Dembowski

September 21st, 2008 at 8:39 am

Posted in Geek, Linux, Software

Tagged with , ,

Vista is consumer crap  

So I booted my PC today when I got home today. I had intended to check e-mail before running out.

The damn thing won’t boot.  I’m typing this on the kitchen laptop.  It says the registry file is corrupted and I should boot off of my Vista DVD and select the repair option.  Except my PC has 4 GB of RAM in it, and the DVD I have won’t boot. That particular image will only boot with 2 GB of RAM or less.

Tomorrow I’ll pop out the RAM, pop in the old 2 GB that I have laying around and fix my PC.  How could Microsoft release such a unsupportable mess?  This is why I need to have a dual boot option and install Ubuntu Linux.  If I had an issue with Linux, I could fix it in no time at all.

Nuts.

The article has

2 responses

Written by Jan Dembowski

September 16th, 2008 at 9:25 pm

Posted in Just Stupid, Software

Tagged with , ,

Monolith purchased the F.E.A.R. name from Activision  

Sometimes I don’t get just spam in my e-mail.  Monolith purchased the rights to the F.E.A.R. name from Activision.  Check out the sequel web site.

The first F.E.A.R. was meant to be played late at night and in the dark.  When I played it, it scared the crap out of me.  This real sequel is out in February 2009 and I’ll probably buy it the day it comes out for the PC.

The article has

no responses yet

Written by Jan Dembowski

September 9th, 2008 at 10:05 pm

Posted in Games, Geek, Software

Tagged with , ,

“James Bond never had to put up with this Vista sh&^”  

My Vista 64 bit OS has been acting a little flaky for a long time.  The latest symptom was my DHCP client not working.  When Dell did the free motherboard swap upgrade, I was supposed to re-install the OS then.  But I procrastinated and just waited till the pain got bad.

My XPS 700720 came with Windows XP Media Center Edition. When the upgrade came out, I purchased it from Best Buy.  I sent in the $19 and received the Vista 64 bit version DVD in the mail. For months I’ve been using the Vista 64 bit version.

My plan was to do the following:

  1. Using vlite I slipstreamed a copy of Vista SP1 onto my upgrade.  That was time consuming but worked.
  2. Backup all my data onto my WD Mybook.  I’m going to regret saying this but 1 TB is HUGE and my data fit with no problems.
  3. Wipe out my existing drive.  My registry was foobar so that was a good idea.  I did not want to upgrade from one mess to another.
  4. Clean install off the Upgrade DVD.  Worked last time, all you have to do is remember to not install the product key.
  5. Upgrade the clean install.  Redundant, but my version is an upgrade.  If I did not do this then my Vista would not activate.

That was the plan. Except the DVD would not install software, no way no how.

The bootable DVD HATED my 4 GB of high performance RAM.  I kept getting the BSOD before I could install anything.  Now Vista running has no problem with my RAM upgrade.  But the installer on the upgrade DVD refused to do anything except BSOD.  Lucky I kept the old slow speed 2 GB or RAM so I was able to get past that problem.

The upgraded DVD did not like my drives.  It’s not exactly a clean install that it does.  The target drive has to be formatted and a WINDOWS directory, or something in the WINDOWS directory, needs to exist.  If it’s not then the installer will refuse to copy files onto your disk.

I had to insert step 3.5 into my plan. I was able to get around this by booting off of my Windows XP install DVD that came with my PC and began to install the old version onto my system.  I did not have to complete the install.  Once files started to be copied I rebooted with my Vista SP1 upgrade.  Then I was able to proceed as planned.

The one piece of unexpected good news is that the fresh upgrade install activated online successfully.  I  was sure I’d have to do the 1-800-NOT-EXTORTION-EXACTLY call to Microsoft just to activate my software.

This is just crazy

Microsoft might be good with apps (debatable) but their OS’s always requires a rebuild after a period of time.  It’s just how it is since the registry just collects garbage from adding and removing hardware and software.

If my PC came with Vista then in theory I should have had an easier time of it.  Just pop in the vendor supplied rebuild DVD and off you go.  In the past that’s always what I did.  With this Vista upgrade, I should be able to install cleanly without the tricks.

The fact that I have to install an upgrade on top of a clean install that I just did is bizarre.   It shows that either the clean install was a mistake on their part or they put it in because they knew this scenario would exist.

They should include and support this for their upgrade too. A little online documentation would have been helpful.

The article has

one response

Written by Jan Dembowski

July 26th, 2008 at 8:45 am

Posted in Geek, Software

Tagged with , , ,