Category Archives: Computers

Joys of Computers

The first rule of computing is to RTFM. The lesser known but equally important corollary to that rule is to be sure you are reading the right manual. If I had remembered that, I could have saved myself 3 hours of frustration this evening.

Continue Reading

Author Pages with hCard & jQuery

While I’m definitely not the designer that any of the people who created these beautiful hCards, I was greatly impressed by them. In particular, I liked the personal hCard created by Tim Van Damme and decided to make my own version of it. Only since I’m using WordPress rather; than a static site, I wanted the page to be generated automatically from info stored with my user profile within WordPress. Unfortunately WordPress does not by default store all the information I wanted to display as part of the user profile.

Initially when I setup the author page, I used the Cimy User Extra Fields plugin to get those extra fields; however in the words of Lord Downey, “It, uh … lacked elegance.” Don’t get me wrong, Marco Cimmino has created a very powerful and useful plugin. My problem is that it’s too complicated for what I want to do. Then almost as though the WordPress developers read my mind, the release of WordPress 2.9 included a new filter making it simple to add/remove new fields to the user profile page.  So easy in fact that the following bit of PHP code added to my theme’s function.php file was all that was required to add the fields I needed.

function vl2_contactmethods( $contactmethods ) {
 // Add Twitter
 $contactmethods['twitter'] = 'Twitter';
 //add Facebook
 $contactmethods['facebook'] = 'Facebook';
 //add flickr
 $contactmethods['flickr'] = 'Flickr';
 //add linkedin
 $contactmethods['linkedin'] = 'LinkedIn';
 //add delicious
 $contactmethods['delicious'] = 'Delicious';
 //add phone
 $contactmethods['phone'] = 'Phone';
 //add phone-type
 $contactmethods['phonetype'] = 'Phone Type';
 //add locality
 $contactmethods['locality'] = 'Locality';
 //add region
 $contactmethods['region'] = 'Region';
 //add postalcode
 $contactmethods['postalcode'] = 'Postal Code';
 //add country
 $contactmethods['country'] = 'Country';

 return $contactmethods;

Of course just storing the info with the user’s profile isn’t enough; we also need to be able to pull it back out. This can be done using either the_author_meta or get_the_author_meta. I ended up using get_the_author_meta for two reasons:

1. I’m pulling the author’s meta info outside of the Loop.
2. I wanted to return, not echo the values, so I can manipulate them before displaying them.

But that still wasn’t complicated enough, after all I started this project wanting to generate an hCard, using some jQuery UI to give it a fancy accordion effect. First we load the javascript for that accordion effect, by adding the following to our author.php file.

<script type="text/javascript">
 $(function() {

Next we get all the user fields by:

<?php if(isset($_GET['author_name'])) :
 // NOTE: 2.0 bug requires: get_userdatabylogin(get_the_author_login());
 $curauth = get_userdatabylogin($author_name);
 $id = $curauth->ID;
 else :
 $curauth = get_userdata(intval($author));
 $id = $curauth->ID;

 $twitter = get_the_author_meta('twitter', $id);
 $flickr = get_the_author_meta('flickr', $id);
 $linkedin = get_the_author_meta('linkedin', $id);
 $delicious = get_the_author_meta('delicious', $id);
 $lastfm = get_the_author_meta('lastfm', $id);
 $phone = get_the_author_meta('phone', $id);
 $ptype = get_the_author_meta('phone-type', $id);
 $addr = get_the_author_meta('addr', $id);
 $locality = get_the_author_meta('locality', $id);
 $region = get_the_author_meta('region', $id);
 $postalcode = get_the_author_meta('postalcode', $id);
 $country = get_the_author_meta('country', $id);

Now that we’ve got the data and the JavaScript; we need to combine it

<div id="authorbox">
 <?php if (function_exists('get_avatar')) { echo get_avatar((get_the_author_meta('user_email', $id)), '120'); }?>
 <div id="accordion">
 <h3><a href="#">About</a> <span><span><?php echo $curauth->first_name; ?></span> <span><?php echo $curauth->last_name; ?></span></span></h3>
 <div id="about">
 <p><?php echo $curauth->description; ?></p>
 </div> <!-- #about -->
 <h3><a href="#">Contact</a></h3>
 <div id="contact">
 <p><span><span><?php echo $ptype; ?></span><a href="callto:<?php echo $phone; ?>"><?php echo $phone; ?></a></span></p>
 <p"><a href="<?php echo get_the_author_meta('user_url', $id); ?>" rel="me"><?php echo get_the_author_meta('user_url', $id); ?></a></p>
 <p><span><?php echo $addr; ?></span><br/>
 <span><?php echo $locality; ?></span>, <span><?php echo $region; ?></span> <span><?php echo $postalcode; ?></span><br/><span><?php echo $country; ?></span></p>
 </div> <!-- #contact -->
 <h3><a href="#">Networks</a></h3>
 <div id="social-networks">
 <li><a title="View <?php echo $curauth->first_name; ?> <?php echo $curauth->last_name; ?>'s Profile" href="<?php echo $linkedin ?>"><img src="<?php bloginfo('template_directory'); ?>/images/linkedin.png" alt="LinkedIn" width="48" height="48" /></a></li>
 <li><a title="Follow <?php echo $twitter ?> on Twitter" href="<?php echo $twitter ?>"><img src="<?php bloginfo('template_directory'); ?>/images/twitter.png" width="48" height="48" alt="Twitter" /></a></li>
 <li><a title="See <?php echo $flickr ?>'s photostream" href="<?php echo $flickr ?>"><img src="<?php bloginfo('template_directory'); ?>/images/flickr.png" alt="Flickr" width="48" height="48" /></a></li>
 <li><a title="<?php echo $delicious ?>'s Bookmarks" href="<?php echo $delicious ?>"><img src="<?php bloginfo('template_directory'); ?>/images/delicious.png" alt="Delicious" width="48" height="48" /></a></li>
 </div> <!-- #social-networks -->
 <h3><a href="#"><?php echo $curauth->first_name; ?>'s Last 5 Posts</a></h3>
 <?php $my_query = new WP_Query('showposts=5&author='.$id); ?>
 <div id="5posts">
 <?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
 <li><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> <?php the_time('j F Y'); ?></li>
 <?php endwhile; ?>
 </div> <!-- #5posts -->
 </div><!-- #accordion -->
 </div><!-- #authorbox -->
 <?php else : ?>
 <h2>Not Found</h2>
 <p>Sorry, but you are looking for something that isn't here.</p>
 <?php endif; ?>

Oops, I almost forgot to mention; we need to make sure we’re loading jQuery & jQuery UI on the author page. Since I separate out the header stuff into it’s own file (header.php); I added this bit of code before the closing </head> tag in that file:

<?php //if (is_author()) wp_enqueue_script('jquery-ui-core');
if (is_author()) {
 wp_register_script('jquery', (""), false, '');
 wp_register_script('jquery-ui-core', (""), array('jquery'), '');
} ?>

And that’s that. Now my author page will by default display my gravatar next to the Biographical Info entered in my profile. There will also be three other section available…

* Contact: Gives selected contact information for me.
* Networks: Displays icons for some social networks I use with links to my profiles on those networks.
* Last 5 Posts: Shows my latest posts.

Later when I have more time, I’ll update the zipped copy of the VectorLover2 theme on this site for people who want to download a complete copy of the code I used for the author pages.

Update: I forgot to thank Joost de Valk for his excellent article, User Contact Fields in WordPress 2.9.
Update 2: I changed the code to register jquery-ui-core, so that it recognizes jquery as a dependency. This tutorial had been working fine; but for whatever reason, it suddenly was trying to load jQuery after jQuery-UI (which doesn’t work so good).
Update 3: Hmm, now that I look back at this old post I realize a couple of things: 1) several of the links I’d intended to be here are missing (since corrected) and 2) this post was written worse than I thought it was.

Fixing Now-Reading’s Admin Menu

I like using Now-Reading to track what books I’m currently reading, have read and want to read on my website. Unfortunately the plugin’s author has been too busy of late to update the plugin and one of the recent updates to WordPress caused Now-Reading’s admin menu to break (when using the single menu option). PHP is not a programming language that I’m really familiar with but I did some poking around in Now-Reading’s code and found if I changed this snip of code:

	if ( $options['menuLayout'] == NR_MENU_SINGLE ) {

		add_menu_page('Now Reading', 'Now Reading', 9, 'admin.php?page=add_book', 'now_reading_add');


		add_submenu_page('admin.php?page=add_book', 'Add a Book', 'Add a Book',$nr_level , 'add_book', 'now_reading_add');

		add_submenu_page('admin.php?page=add_book', 'Manage Books', 'Manage Books', $nr_level, 'manage_books', 'nr_manage');

		add_submenu_page('admin.php?page=add_book', 'Options', 'Options', 9, 'nr_options', 'nr_options');

To read like this:

	if ( $options['menuLayout'] == NR_MENU_SINGLE ) {

		add_menu_page('Now Reading', 'Now Reading', 9, 'add_book', 'now_reading_add');
		add_submenu_page('add_book', 'Add a Book', 'Add a Book',$nr_level , 'add_book', 'now_reading_add');
		add_submenu_page('add_book', 'Manage Books', 'Manage Books', $nr_level, 'manage_books', 'nr_manage');
		add_submenu_page('add_book', 'Options', 'Options', 9, 'nr_options', 'nr_options');

Then Now-Reading’s single admin menu worked properly again.

py2avi released!

py2avi is a python script I wrote to make it easier for me to transcode video files from MKV to AVI while not forgetting to extract the subtitles from the MKV file. On the off chance that somebody out there in Internet-land has a similar need, I’m releasing the script under the GPL 2.0. So if you want/need it, take it and have fun with it!

Jaunty Upgrade After Effects

Being something of a linux/technology geek and with the recent-ish release of Ubuntu 9.04, I decided to upgrade my home desktop PC from Ubuntu 8.10.  Like the last time I ran through the upgrade, I was surprised at how smooth the upgrade process went.  Unfortunately 2 new problems appeared after the upgrade was complete, with once again one problem being rather minor and the other one being much bigger.

First up the minor problem, after rebooting into the new hotness of Ubuntu 9.04, I was greeted with a pop-up windo telling me “There was an error while performing indexing : Index corrupted.” The pop-up gave 3 options: “Ok”, “Cancel” or “Reindex all contents”. I tried all 3 but the pop-up kept coming back even after multiple reboots. The only thing I could initiall figure out to do was to kill the tracker
ps -ef | grep tracker

Yes, I know that’s probably a horrible idea but I rarely use the tracker’s search on my home PC so pbbbhhhhttt! A quick Google search later, I found a bug report on LaunchPad about it under which I found these instructions:
sudo aptitude install tracker-utils
tracker-processes -r

I apparently already had the tracker-utils  installed, so the first didn’t do anything for me. The second command above however shutdown the tracker and removed the indexes, so the tracker was able to recreate them cleanly. Since running those commands, the pop-up hasn’t come back.

Now on to the fun with the major problem. This was a case of network failure, specifically wireless network failure. While this is a desktop PC, I live in an old house without network cabling and my PC sits too far away from the ideal location for the router to run a cable. So I have a D-Link PCI wireless NIC in my desktop.  The NIC is based on the Atheros AR5413 chipset, Network performance has never been as good as a wired connection but it had been acceptable until this upgrade to 9.04 when the wireless stopped working.

I had been using ndiswrapper to load the windows driver for the card but that suddenly stopped working. I could see all the wireless networks in my neighborhood, but couldn’t connect to any of them (either networks secured with WPA or wide open ones). I started doing some research into the problem using other computers with working internet connections. I found that my router was getting blacklisted while my desktop was trying to connect and then it would timeout without ever making a network connection.

Also while researching the problem, I found out that there was now a new, open source driver which should be working with my wireless NIC (ath5k).  So I removed ndiswrapper, and tried out this new driver. Alas it wans’t particularly stable, dropping connection ever couple of minutes. However since my wireless NIC uses an Atheros based chipset, I had another option. I installed the madwifi driver via jockey-gtk (Ubuntu’s tool for installing restricted modules/drivers).  For whatever reason, activating the driver via jockey-gtk didn’t actually get it up and running. To test it, I used:

sudo modprobe ath_pci

To actually get the driver to load on every boot, I edited my /etc/modules file to include ath_pci.

The madwifi driver doesn’t appear to make as strong a connection as the ath5k did; the gnome network manager applet shows the connection under madwifi usually has ~45-55% signal strength (under ath5k & ndiswrapper I could get as high as 70%). However I’ve yet to lose a connection to my network while using the madwifi wrapper whereas ath5k would drop connection every couple of minutes and ndiswrapper would usually drop the connection at least once an hour (back on Ubuntu 8.10 where it actually worked for me). Also the madwifi driver allows me to connect to my network on boot-up; unlike ndiswrapper which always took some time to connect after I was booted up and signed in. So overall, I’m pleased with my new networking setup but would have been more pleased if the changes I made could have been done automagically by the upgrade process or if the upgrade process at least warned me that it might break my networking setup.

Copyright © 2004 – 2020 Powered by WordPress.