Hacked Simplelife

At the request of a commenter who is also playing around with his simplelife plugin, I’m uploading my currently hacked version.

It’s not pretty so you won’t be able to change all options on the profile (only the ones included in the original) but I’ve included comments in the code so you should be able to figure out what is what.

You will need the Simplepie core WordPress plugin in order to use it.

Currently this version supports the following extras (Over the original simplelife)

In order to make it work for your own lifefeeds, you will need to edit the php code directly. You will have to edit either the ones I’ve set up (for example, change your digg username) or add your own.

To add a new feed you need to do the following

  • Add the new class for it (Defining colour, background and icon)
  • Add a new variable for the feed url
  • Add a new variable for the title that will be used in the chart. Optionaly you can set it to something specific but if you don’t want to, the script will just draw it out of the feed
  • Add a new variable for the counter.
  • Add the new feed url variable in the SimplePie array. Your new feed will need dates so don’t use something like Ponyfish.
  • Create a new if statement (just follow my comments)
  • Optionally, if you’re using getboo or something similar, add a new switch for the subtags
  • Add the title and counter variables to the chart if you want them tracked. You’re better off copy-pasting one of the current entries in the middle and pasting it below. If you copy and paste to the bottom of the chart, you’ll probably add an extra comma where you shouldn’t. Don’t forget to change the small chart as well.

If you have any questions, let me know.

PS: I am currently waiting for version 1.3 to come out so that I can merge all my changes in the new code but it seems to be taking too long. I think I might as well start beatifying it in order to upload it as standalone.

Download the hacked version of the Simplelife WordPress plugin here.

How to hunt for WordPress performance hogs

So after my previous post on how I discovered my major causes of wordpress pain, I kept looking on what is causing my other delays. Eventually, while looking at my source code, I discovered that my wordpress page was always reporting how many SQL queries it took and how long they took to complete. Looking at the footer, this was done by this command:

<?php echo get_num_queries(); ?> queries. <?php timer_stop(1); ?> seconds

Now, I understood that this was very helpful but I couldn’t understand why it was returning a time like 10 seconds when the page was loading for 4-5. A quick google search for this code however did lead me to a page that was explaining how to Keep WordPress overhead down. Through there, I realized that those seconds were some sort of CPU time taken to draw those queries.

Through this then, I now had a semi-accurate way to monitor the impact of each plugin on my site. I only needed to figure out which parts of the site were hogging down the queries and increasing the load time.

I created a quick table in a Spreadsheet and started logging down the differences.

  • First, I made the performance text visible, so that I don’t have to look at the source code each time (You can still see it by scrolling to the bottom of the page)
  • I disabled the WP-Cache so that the queries are done every time
  • I then started disabling each plugin in turn and reloading a page. Then I compared that with the previous loading time (where the plugin was enabled.) I noted down the difference in queries and the average/approximate CPU time difference.

Unfortunately since the CPU time tended to vary from load to load, I couldn’t get an accurate number of the difference. The table I made in the end looked something like this

Plugin name Queries CPU Time Taken
Bad Behaviour 1 5
Hide Text 0 Negligible
Greeklish 0 Negligible
One click install 0 Negligible
SimplePie WordPress Plugin 4 Negligible
Security Scan 1 1

After I went through all the plugins, then I started doing the same thing with my various widgets and snippets of code in my theme that might be causing this.

Once this was done, I had one likely suspect plugin and a few widgets that were probably contributing to this slowdown. You see, my theme, a very heavily hacked HemingwayEx, was using some custom widgets in order to draw from WordPress the latest comments, recent posts and whatnot. These widgets queried the database each and every time a page would load which was quite frankly impractical.

Fortunately a short time before, I had discovered the very useful bundle of post plugins. They were also there to hunt for recent comments & posts and related posts and they also included a built-in caching mechanism! As sweet as it gets.

I quickly modified my widgets to run this code instead and the results were wonderful. By disabling also the single other plugin I found that was slowing things down, Bad Behaviour, I’ve now managed to drop the loading time considerably (or so it seems for the time being). Not only that, but I’ve managed to put a few new toys to use that do a better job than HemingwayEx’s built in functionalities.

Currently my site seems to load lightning fast compared to before but I’m not absolutely convinced this will not change once my shared hosting environment gets bogged down. Hopefully, even if that happens I will still have a much much better performance than before.

I am still stuck at around 65-80 queries per page load but I can’t figure out where they come from. I am hoping that I’ll eventually be able to trace it but for now it seems enough.

Btw, I just loved the functionality of the Post Plugins to measure their own execution time and report it back to you. This is something that all plugins should be doing in order to give the web designer an idea on what is going on with his site. I’m going to work to see if I can implement that in the Lifestream plugin I’m working on and then see if I can place it on other plugin as well.

Btw (2), Can anyone explain why more people don’t take advantage of the Plugin cache plugin? I am fairly certain that a number of heavy plugins (like Popularity contest) could make good use of it.

As always, if you have any more ideas on where to look and tweak to improve my WP performance even more, I’ll be glad to hear them (AKA Whining because no one is commenting on my blog :P).

PS: It’s a pity that I had to disable Bad Behaviour as it worked quite well until now. I also don’t like to reply too much on just a single anti-spam plugin. Unfortunately, the performance hit was undeniable and I’d rather my site doesn’t take an extra 3-4 seconds to load every time.

Where're my damn icons?

I don’t get it. My lifestream icons are not loading for some reason even though you will see in the page source that they are loaded as part of the class. For some reason, initially the last.fm and facebook icons stopped loading after I hacked the SimpleLife plugin to make it play with all kinds of feeds. Then, I discovered why the colours of the custom feeds were not being used (a missing colon) and fixed it, and now <a>all</a> my icons are gone…

Grrr!

Nothing I do seems to fix this and I just cannot see why it is happening. There does not seem to be an obvious error in the code and the rest of the css class (text, background colours) are loading just fine. In the source of the page, you can see the css clearly loading correclty


a.lastfm {
background: 0c0c0c url(http://dbzer0.com/wp-content/plugins/simplelife/lastfm.png) no-repeat 10px 50% !important;
border-top: 1px solid 0c0c0c !important;
border-bottom: 1px solid 0c0c0c !important;
color: #BFBFBF !important;
}

And then the item call

<li class=”item”><a href=”http://www.last.fm/music/Machinae+Supremacy/_/Stand” class=”lastfm” title=”db0’s Recently Played Tracks”><span class=”timesf”>09:48</span> Machinae Supremacy – Stand</a></li>

And the icon exists…
Anyone have any idea what is going on?

At least now I can have feeds from any source (feedburner, del.icio.us, google reader) without losing formatting. I just need to wait for the next plugin version to add options for more streams 🙂

UPDATE: Nevermind. I found the culprit. Apparently I’m blind…

Mighty plugin hacking

Well…for my newbie standards at least 😛

I’ve been playing around with the SimpleLife WordPress plugin, trying to create a simple lifestream I can embed in my about page and perhaps in my sidebar as well. It turned out that this was a job which needed a bit more attempt to make it work.

Below are the changes I did in order to wrangle it.

  • Had to edit the plugin in order to get it to diplay correctly in the plugins page. For some reason it floods the screen with it’s contents. Apparently editing and saving should solve it but in my case I needed to delete some newlines as well.
  • Changed the classes .date and .time to .datesf and .timesf and modified where they were called. Leaving them as they were, they were screwing with other css classes on my site under the same name
  • Changed the if statement for last.fm to look for the string ‘last.fm‘ instead of ‘last‘ since that string may be a part of any other url.
  • Put three new if statements, similar to the ones that check for last.fm and facebook, that check if the link goes to this blog, the ACP or the Wesnoth Journals. Then set the class according to that. The way the plugin is setup, it does not assign the class depending on the feed url bur rather according to the current link url. This means that you cannot use feedburner as your feeds address as it will never trigger an if statement[1]. I actully find the way this is handled a bit weird as it would serve much better to check the feed url and assign a class, rather than check the current link. I’ll have to check if that’s actually feasible…
  • Commented away the if statements for the first three feeds. I’m using the custom ones instead now.
  • Manually set the colour of the last two feeds within the plugin. For some reason even though the php call takes the variable I’ve set in the plugin configuration page (I can see it in the source code of the page) the colour is not being used and the text stays black. Weirdly enough, the background colour is changed well enough and the “blog feed” works just fine.
  • I didn’t want all my delicious feeds to be posted because I seem to be doing an awful lot of them. I prefer to log only the ones that signify my comments for which I use the mycomments tag. Fortunately I’ve discovered that you can use a del.icio.us tag by using the form: username/tagname
  • Created a new page template and inserted the php code there.

All-in-all, the plugin seems very promising and it already seems to work fine for me. However it does seem quite error-prone and lots of people most likely won’t be able to use it yet. Fortunately this will be fixed in the short future.

Now I just have to see if I can add more stuff for it to track.

ClickComments on Feed

I’ve hacked the clickcomments plugin in order to make it display only in the feed (since my layout places the script on the single post’s sidebar).

However I’ve been trying to see it and it is failing for some reason. It just won’t display in my feedburner human-readable feed. I’m not certain if feedburner prevents scripts from running or if the script is malfunctioning but I can see the correct code in the source of the feedburner page.

Can any of me feed readers else see the clickcomments panel under the content? If so I’d appreciate to hear from you.

Just in case you want to do the same with your own blog, in order to make the plugin display the panel only in the feed, you need to edit the plugin in your wordpress installation and just after the function begins, insert:

if(is_feed()) {

and close the bracket just before the return $content; part

In case you want to place the panel in your sidebar (in a widget for example) I’ve found that the folllowing code works just fine

<div class="postreachclickcomments"><script src="http://www.postreach.com/ccengine/display_iframe?perlink=<?php the_permalink(); ?><!-- &url=<?php echo get_settings('home'); ?>" type="text/javascript">
// --></script></div>

And this doesn’t even need the plugin to be installed (but you do need a postreach account)
Hmmm…perhaps I should wrap this in a widget…

As an aside, I’ve figured out why clickcomments stops loading for me eventually. Initially I thought it stopped loading from my specific IP (which is why it kept working from anonymouse) but it’s not that. Apparentlythe script saves a cookie on your browser which stops loading the panel after you’ve voted 3 times.

Unfortunately this created some problems for me as a web designer as I could not actually check if the clickcomments panel is working or not with the changes I made on the layout (I could only see that the source existed). By clearing out all cookies under the Postreach name, the pannel appears again and you can vote once more.

The problem is that this is prone to abuse. Anyone who wished to get a higher rank could just clear his comments and vote his posts once more. Since postreach does not require an account before you vote and it does not check the IP (or so it seems) it is bound to be played by any unscrupulous blogger who dreams of more visitor hits and tries to achieve it through the showcase.

I just hope that Postreach has not implemented a simple security through obscurity method to avoid it and they actually have some checkpoints that I have not seen.

No OpenID for you

I’ve given up trying to make the WP-OpenID plugin work with my theme. It seems it just doesn’t want to. Watever I do, it either tries to always authenticate on the url (even if it isn’t a provider) or never. I can’t get to it actually check the site.

Also, even if I do use a url that provides openid auth, the comment is rejected as spam (probably by bcspamblock) and I can’t be bollocksed to troubleshoot that.

So for now, unfortunately, I’m disabling OpenID functionality on this site. Let’s hope this can be fixed in the future.

Dynamically expanding single-post sidebar

Yay, I’ve now managed to do something I always wanted for my site. It always bothered me that when I wrote a lengthy blogpost, the right side of the screen always stayed empty when you scrolled down. Unfortunately I did not want to just chuck a few random items to expand it as it would mean that even when I wrote a short post, the sidebar would draw the post down which would have the unfortunate results of making the reader scroll down too much to read the comments (as well as look ugly)

After I used the FSD Sidebar I thought to myself that I really should find a solution to my dilemma. Initially I though to use different post templates and then just select one depending on how lengthy the post came out. Unfortunately, after I created the first, I discovered that WP does not support different templates for posts but only for pages. Unfortunately I could not find a plugin to activate this functionality. This was a bit unfortunate but I didn’t give up.

I went for my second idea: To have the single-post sidebar expand downwards with more items depending on the word count of the current post. I looked around the documentation for a way to collect the word count of a post but nothing was built in WP. Fortunately a short Googling led me to the page of someone who created a plugin exactly for this reason. Perfect!

Now I only needed to figure out how to use a php statement so that the sidebar does this expansion. Unfortunately since I don’t have any php skills to speak of, I turned to the nets again and fortunately it was easy to find what I needed. Unfortunately this statement does not accept an actual sidebar item within the brackets {} but a quick look at other themes informed me to the use of <?php if() ?> and <?php endif(); ?> statement. I still don’t know exactly how to use it properly but I did manage to make it work for me so all’s well.

All in all what I did is test if the wordcount is over a specific limit and then insert the item between the if and endif. Use four of these statements for increasing wordcounts, and your sidebar will expand only when you write an appropriate number of words. Of course this doesn’t take into account pictures or videos, or even different screen resolution that might change the size , but I don’t know if there is a way to test this unless I start checking their resolution each time and changing the word count needed…hmmm…

Ack no!

Comments and stuff

So I’ve put a two new tricks on my comment forms.

The first one is that you can now see a preview of what you are going to post. Just write your text and press the preview button and you should see it below. No more orthographical or html errors ;). This was done via the AJAX Comment Preview plugin. It needed me a little css tweaking in order to get it to display as I need it but fortunately I was able to find how to wrap the preview so that it fits with the normal comments.

The second one is the threaded comments option which is done through the plugin with the same name. Although at the moment you can have only one thread per comment, this might make it easier to follow the discussion in case it starts to derail (although I will admit that I don’t have so many commenters). The nifty addition to that is that the author of the comment will now receive an email notification when someone replies to his comment. The bad thing is that you can’t unsubscibe from that but given the low number of comments I get, I do not think that would be a big issue. You can still use the subscribe feature as well, but since this will inform you of every subsequent comment in the thread (even if you do not follow it anymore) most people don’t use it.

This plugin needed me even more time to get right as I needed to format the thread correctly and also test if more than one thread is viable. It is but currently the comment box is screwed on the second comment so I need to work on the css part of it. Until then I’ve enabled only a single thread replies.

One last update is that I expanded the comment field in order to give you a bigger view of what you are writing. I always found the one I had before a bit too small.

I think I’m now going to enable these on my two other blogs as well 😉