Kempwire.com

By Jonathan Kemp

Delete Blank Lines in TextMate

I use TextMate for coding on the Mac. At work, I use Dreamweaver. I’ve noticed if I switch between the 2, Dreamweaver throws an extra line break in for every line. Some text editors have a command to handle reformatting like deleting blank lines. TextMate by default does not.

You can customize TextMate though and add this command. Here is how you do it.

To add a new command to TextMate simply open the Bundle editor (bundles menu, Bundle Editor, Show Bundle Editor) and press the add button (+) and select “New Command”. This command will appear under the user’s bundle, you can move this later.

The command edtor window has several options these are:

1. Save: This allows you to configure whether to save the file or the current project before running the command
2. Command(s): This is where you enter your commands
3. Input: The text that becomes the standard input to the command. This can either be a selection or the entire document (and selection)
4. Output: This option is how the ouput from the command is handled. This can either be discarded, replace the selection, replace the document, insert as text, insert as snippet, Show as HTML, show as tooltip create a new document.
5. Activation: How the command is triggerred, in each case I’ll leave this up to you.
6. Scope: the scope of documents this should effect, e.g all js files etc.

For this example, we are going to use the sed command to remove all of the blank lines from a document.

Here’s the command configuration:

Save: Nothing
Command: sed /^$/d
Input: Entire document
Output: Replace Document
Activation: I’d recommend using a keystroke of your choice
Scope: Leave this blank

Sed processes a file line by line and carries out substitution based on regular expressions. In this example “/” is the delimiter. The regex part “^$” matches the beginning of a line and the end of a line (i.e a blank line) and lastly the “d” deletes the match.

One note, you may want to make a back up of any files in case something goes wrong.

via Muffin Research Labs.

Elgg Not Showing Latest Activity in 1.6

Update: It turns out this problem was caused by plugins. The Wire plugin is causing it on both sites, and the bookmarks plugin is causing it on one site. If you have this problem, I recommend turning off your plugins and enabling them one by one to see which one is causing the problem.

I complain about Elgg a lot, as you can see here. I want to like it, but it does have a lot of problems. I know it is Open Source, but it is also being actively worked on every day. So in my opinion, if there is a known bug in a prominent feature of the site, it should be fixed.

There is currently a major bug in the Latest Activity feature of the Elgg software. I have 2 sites running Elgg, and neither of them display the latest activity on the latest activity page or on the home page. Latest activity is blank on both sites. They were both upgraded and not fresh installs, which seems to be a common factor. Also, I was running the custom index plugin on both sites, so I didn’t notice the problem until I disabled the plugin.

This is a known bug that has not been fixed yet. As far as I can tell, it was reported at least a year ago here. There is a thread on Google Groups here. Here is the bug ticket for this in Elgg’s bug tracking system that was reported 3 months ago.

How does Elgg handle bug fixes? There is a major bug in Elgg’s latest activity display, which is a major feature of the site. They know about it, and it has not been fixed yet despite 2 discussion threads and a support ticket. Hopefully, they will fix it in the next release whenever that is.

How to Create a Google Analytics Plugin for WordPress

After creating my bbPress Google Analytics plugin, I wanted to do the same thing for WordPress. It is just as easy to do this as it is for bbPress. Your WordPress footer template should have a hook for adding code to the footer. If it doesn’t have this hook, you just have to add this piece of code, wp_footer();, to your footer template. Then you just have to create the code that will add your tracking script to the footer of every page. That is it.

Here is an example of the code you can use. Download wp-analytics here. Just upload the script to your plugins directory, and activate the plugin in the plugin admin. If you are using Google Analytics, all you need to do is replace “UA-XXXXXX-X” with your site code. But it will work with any tracking script, just replace the Google script with your own. Also you can use this same code to add any code you wanted to the footer.

How to Create a Google Analytics Plugin for bbPress

bbPress is a free, open source forum software from the makers of WordPress. I am even using it on this site. It just came out of beta with the relase of 1.0. If you are looking for forum software I recommend it.

However, the theming system is not as simple as WordPress. I had added a Google Analytics script to my themes. But when I upgraded to 1.0, I lost all my tracking scripts.

The best way around this, I thought, is to create an analytics plugin. It turns out, it is very easy, especially if you have experience creating plugins with WordPress. The bbPress footer template has a hook for adding code to the footer. You just have to create the code that will add your tracking script to the footer of every page. That is it.

Here is an example of the code you can use. Download bbpress-analytics here. Just upload the script to your bb-plugins directory, and activate the plugin in the plugin admin. If you are using Google Analytics, all you need to do is replace “UA-XXXXXX-X” with your site code. But it will work with any tracking script, just replace the Google script with your own. Also you can use this same code to add any code you wanted to the footer.

WordPress Users and Site Updates

I just released version 1.1 of WordPress Users. If you are upgrading from a previous version, please check your settings, as they have changed. Avatar and user description display are now optional, so you must enable them for them to show up. Also, user description character limit can now be changed, so check that setting as well.

I just implemented open registration on this site. You should be able to login or register from the sidebar. I also launched Kempwire Forums. The forums are mainly for support of my WordPress plugins, and the site registration is mainly for the forums. If you register on the site, you can use the same login for the forum and vice versa.

For support of plugins, I am leaving comments open on the plugin pages for now, but I appreciate it if all discussion will be added to the forums. Please let me know if you have any questions. Thanks!

Elgg Default Theme Should be a Plugin

I finally upgraded to Elgg 1.5 the other day. I was frustrated that custom themes were broken in this version, but I got over it. It is worth the upgrade with all the improvements. There are still no custom blog title tags, but that is easy enough to fix yourself.

Now, that custom themes no longer work, I decided to modify the default theme. It is not that hard to modify default views in Elgg, if you know what you are doing, but in doing this, I realized a fundamental problem with the default theme. The default theme should be a plugin rather than part of the core files. Because it is not, if you want to modify the default theme at all, you have to create a plugin.

Let’s say that you want to add Google analytics to your template. Unless you want to modify the core files, which you shouldn’t, you have to create a plugin. This should be much easier. Compare with Wordpress. Wordpress comes with a default theme. To make changes, it is easy to modify, add a new one or make your own. It is not easy to do this in Elgg.

Another problem is that a custom theme is the same as a plugin, so when you are looking at your list of plugins, it is hard to tell which ones are themes. Also there is no preview for themes, not even a thumbnail.

So for the next version of Elgg, I would break out the default theme as a plugin. Then I would separate the themes from the plugins in the backend. This will make it much easier to customize your themes in Elgg.

Add Threaded Comments to Your Theme in WordPress 2.7

One of the improvements added in WordPress 2.7 was official support for threaded comments. Previously, this functionality was only available through plugins. But now that threaded comments are available, you need to make sure that your theme is compatible.

To do this, you need to add a couple of things to your theme. First open up header.php in your theme, and add this line in between the head tags, preferably right before the wp_head function.

<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>

This adds the javascript required for threaded comments to any page or post where you have comments enabled, but not on the index or archive pages.

Next open up comments.php in your theme and make sure this code is in there.

<ol class="commentlist">
<?php wp_list_comments(); ?>
</ol>

This code should replace your comments loop. To see an example of this, see comments.php in the default theme in 2.7. Once this is done, you need to activate threaded comments. Go to “Discussion” under “Settings” in your WordPress admin, and check the box that says “enable threaded comments.”

Another important step is the CSS. You need to style your comments properly for the threaded comments to be as functional as possible. For an example, again check out the CSS from the default theme in 2.7. You also need to be aware of how many levels your comments will be nested in your CSS. WordPress allows you to set this in your backend. The default is 5. With those steps, you should be good to go.

The wp_list_comments is an important function for other reasons. It also gives you the ability to sort comments, add gravatars, add CSS hooks for even and odd comments and author comments. So even if you don’t want threaded comments, it is an important function to have in your theme, especially if you are developing themes for public release.

Update: It turns out following the instructions above didn’t work for me. You still need the js file in your header, but there are more changes to comments.php than I thought. The easiest thing to do is to just copy the comments.php file from the default theme in 2.7 to your theme and modify that file to your liking. This finally got threaded comments working for me.

Install Apache and PHP on Leopard with MacPorts

If you have a Mac with Leopard installed, you should have Apache and PHP installed on it by default. If you try to modify your PHP installation however, this is where you run into problems. This was easy to do with Tiger, and I had written several articles on how to do this. Eventually, when I installed Leopard, my dev environment no longer worked.

I found a solution to this problem with MacPorts. The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system.

With MacPorts, it’s easy to install Apache and PHP into an environment you control. MacPorts makes it easy to add libraries to configure your installation however you want. It also makes it easy to update the software whenever you need to. I recommend using this to install your own dev environment on your Mac. Here is a good tutorial for installing Apache and PHP with MacPorts.

Note: the shortcut apache2ctl didn’t work for me because I am using .bash_profile on my machine instead of .profile which MacPorts installs. If you have this problem, you need to add a line of code to .bash_profile. Add the line below to .bash_profile and the shortcut apache2ctl should work.

alias apache2ctl='sudo /opt/local/apache2/bin/apachectl'

Updated Ultimate Noindex Nofollow Tool

The Ultimate Noindex Nofollow Tool lets you add the “noindex” robots meta tag to archives, categories, search pages, tags, author pages, login, admin pages or any other page you choose. Also, you can add the rel=”nofollow” tag to archive links or category links.

The latest version gives you the ability to add rel=”nofollow” to any page link from the wp_list_pages function or Pages widget.

The Ultimate Noindex Nofollow Tool is here, and you can download the Ultimate Noindex Nofollow Tool here. I hope you find it useful. Let me know of any problems or questions.

The Ultimate Noindex Nofollow Tool for WordPress

It seems I’m really into writing WordPress plugins lately. I’m also into WordPress SEO. My latest plugin combines the functionality of some of the previous SEO plugins I wrote, plus some new functionality of its own.

It’s called the Ultimate Noindex Nofollow Tool. It combines the Nofollow Archives, Nofollow Categories and the Noindex Login plugins. You can now add the “noindex” robots meta tag to archives, categories, search pages, tags, author pages, login, admin pages or any other page you choose. Also, you can add the rel=”nofollow” tag to archive links or category links. The next version, which I am working on now, will have the ability to add rel=”nofollow” to any page link from the wp_list_pages function.

If you care about WordPress SEO, you should be using this plugin or a similar one. I’m working on a WordPress SEO post, where I will detail what you should do and how you can use this plugin to improve your WordPress SEO.

The Ultimate Noindex Nofollow Tool is here, and you can download the Ultimate Noindex Nofollow Tool here. I hope you find it useful. Let me know of any problems or questions.

Page 1 of 1612345»...Last »

Copyright © 2005-2009. XHTML | CSS