Skip to content
May 28 10

How to Add Title Attributes to Magento’s Main Nav

by mrchris

You may have heard that it’s good to have a title attribute defined in your most visible links for SEO purposes. Unfortunately, Magento’s main nav does not do this. It’s easy to add. Just follow these steps.

First, copy “app/code/core/Mage/Catalog/block/Navigation.php” to “app/code/local/Mage/Catalog/block/Navigation.php”. Create the needed directories if they do not exist. This will override Magento’s core version and will allow your changes to survive an update.

Next, open the file you just created. Find the the function drawItem then find the line that looks like

$html.= ‘<a href=”‘.$this->getCategoryUrl($category).’”><span>’.$this->htmlEscape($category->getName()).’</span></a>’.”\n”;

And replace it with

$html.= ‘<a href=”‘.$this->getCategoryUrl($category).’” title=”‘.$this->htmlEscape($category->getName()).’”><span>’.$this->htmlEscape($category->getName()).’</span></a>’.”\n”;

That will insert the category’s name into the title attribute. Save and it should be working.

May 18 10

Getting Ack to Work in Vim on Ubuntu

by mrchris

As a Magento developer I often have need to search through hundreds to thousands of files just to find a specific piece of text. The tried and true work horse for this type of operation is grep. Unfortunately, grep is a bit sluggish when it comes to a directory tree as large as Magento’s. Enter ack. Ack is fast. I dare say ack is wickedly fast.

With any great search tool, text editor integration is important. For Vim there’s a great plugin for ack. If you’re running any fairly modern flavor of Ubuntu, when you try the plugin you’ll likely encounter the message ”/bin/bash: ack: command not found”.

According the the instructions on the ack Vim plugin page you have to install it with “sudo aptitude install ack-grep”. After that, you’ll still get “/bin/bash: ack: command not found”. The solution?

sudo ln -s /usr/bin/ack-grep /usr/local/bin/ack

After that, you’ll be searching in Vim at blazing speeds.

Apr 1 10

Gray Cat Is Gray

by mrchris

I’ll admit it. Angela and I are cat people. So much so that we have three of them. Today, that has changed as we’ve just crossed the line from “cat people” to “crazy cat people” by adding a fourth.

In true crazy cat person form, I’m blogging about my feline friends. Today we added a new member to our  family. His name is Gray Cat. It should be known that Gray Cat…is Gray.

I’ll keep this story brief. This is an outside cat from the rental house we used to live in. The first time we saw him he just ran up to us. The whole time we were there we would see him outside and he’d be friendly with us. Yesterday I stopped by to check in on him to find him covered in pollen, leaves, dirt, and what was either blood, poop, tree sap or a combination of all three. He is also not neutered so we can imply that he is not properly cared for. Today, I drove by and rescued him.

Currently he is happily sitting next to me in our garage. The garage is temporary until he gets checked out as not to infect the other cats. It’s odd, he shows no signs of being scared and has already made himself quite comfortable. Anyways, on with the pics. Welcome home, Gray Cat.

Mar 27 10

Simple Secure Screenshot Sharing For Ubuntu

by mrchris

If you’ve ever wanted to share a screenshot with someone, you undoubtedly know the hassle it is to save your screenshot somewhere then share it though email or uploading it to an image sharing site. The need to make this easier has been met for Windows and OS X users for some time now with TinyGrab.

This need has also been somewhat met for Linux users with a great screen capture utility called Shutter. Shutter has the option to upload to a remote server but the way it does is not as streamlined as TinyGrab. First, the upload options is something that you have to do manually after you’ve already taken the screenshot. The second is that you are then left with a copy on your hard drive that you have to manually delete. The third is that it only supports FTP which as most people know is entirely insecure.

I’ve come up with a combination of tools that allows Shutter to function as a much more capable screenshot sharing tool. These tools are a remote server you can SSH into, a web server (lighttpd in my case), SSHFS, and of course Shutter. Here’s how to do it.

The secret to the magic is SSHFS. It will allow us to mount a remote folder via SSH. This makes sending files to that server as easy as drag-and-drop and since it goes through SSH it’s encrypted and secure. Now then, let’s get started. Please note that this example will assume this is all being done with Ubuntu so modify this tutorial for your distro.

1. SSH into your remote server and create a folder on the file system which will contain your uploaded screenshots. Throughout this tutorial, remember to replace “myhost.com” with your remote host’s URL and “remoteuser” with your username.

localuser@localcomputer:~$ ssh remoteuser@myhost.com
remoteuser@remotecomputer:~$ mkdir ~/screenshot_uploads

2. We need a web server to make our screenshots accessible over the internet. Assuming that there isn’t a web server already installed, a simple need such as this is easily met by lighttpd.

remoteuser@remotecomputer:~$ sudo aptitude install lighttpd

3. Point the web server document root at our screenshot_uploads folder. To do this open “/etc/lighttpd/lighttpd.conf” in your command line text editor of choice and set “server.document-root” to “/home/remoteuser/screenshot_uploads”. The end result will look like

server.document-root = "/home/remoteuser/screenshot_uploads"

Normally it is not advisable to assign the entire document root to such a folder. This is going under the assumption that this web server will be used for nothing but screenshot sharing. If your needs are different you should modify this part of the tutorial to fit them. After you’ve made the change, restart the web server.

remoteuser@remotecomputer:~$ sudo /etc/init.d/lighttpd restart

At this point, your screenshots folder should be accessible from http://myhost.com. Be sure port 80 is open for that your remote server.

4. Log out of the SSH session  and install SSHFS.

remoteuser@remotecomputer:~$ exit
localuser@localcomputer:~$ sudo aptitude install sshfs

5. Now we can mount our remote folder to our local machine. We will assume that our local folder is /home/localuser/screenshots.

localuser@localcomputer:~$ sshfs remoteuser@myhost.com:screenshot_uploads \
/home/localuser/screenshots

Now anything placed in /home/localuser/screenshots will be automatically sent to the screenshot_uploads folder on your remote server.

6. If you haven’t done so already install Shutter. Then open Shutter and go to Edit->Preferences and set the save directory to be your SSHFS mounted folder. You may want to consider mapping the take screenshot action to a keyboard shortcut. After that it will look something like this.

Shutter Preferences Shutter Preferences 2

That’s it! Take a screenshot, point your browser at the URL for your web server, grab the link and send it to your friends. Truthfully, you can use any screenshot tool and point it at your sshfs mount and it will give you the same result. Shutter just does it in a much more polished fashion.

There are some final considerations. There are the piles of screenshots you’ll undoubtly accumulate from using this nifty setup. On my server I set a daily crontab command to clear out that directory. Another may be have your SSHFS mount set up automatically at boot time. This could be done by registering a public key for your computer with the remote server and adding an entry to the /etc/fstab file that looks like this.

sshfs#remoteuser@myhost.com:/home/remoteuser/screenshot_uploads /home/localuser/screenshots fuse user,auto 0 0

Happy screenshot sharing!