Posted tagged ‘php’

Twenty Eleven Sidebar WordPress theme announcement

17/06/2012

Just put up the project page for my Twenty Eleven Sidebar WordPress theme!

Twentyeleven Sidebar is a Twenty Eleven child theme with a persistent sidebar, which means you will see the sidebar on individual posts, pages as well as media pages, such as for images.

Check out the project page, or get the code from Bitbucket!

PHP function for obfuscating e-mail addresses and phone numbers using Javascript.

04/10/2011

Update 2012-12-23

The technique below is now available as a WordPress plugin. Check out the Email Obfuscate Shortcode plugin!

Here’s a short snippet that I have been using in various PHP projects to protect e-mail addresses and phone numbers against being harvested for spam purposes. It uses Javascript to scramble some text and output it as a self-contained piece of Javascript. It’s compatible with all major browsers (and IE5.5 and up). The idea is based on this ruby snippet, so head over there if you want to read more about the way it works!

safe_text() snippet

function safe_text($text)
{
    if(mb_detect_encoding($text, 'UTF-8', true))
        $text = utf8_decode($text);

    $ret = '
<script type="text/javascript">// <![CDATA[
                    var t=[
                ';
    $chars = str_split($text);

    $enc[] = rand(0,255);

    foreach($chars as $char)
    {
        $enc[] = ord($char)-$enc[sizeof($enc)-1];
    }

    $ret .= join(',',$enc);
    $ret .= '
                ]; for (var i=1; i<t.length; i++) { document.write(String.fromCharCode(t[i]+t[i-1])); }
// ]]></script>';

    return $ret;
}

To output the Javascript anywhere (it’s entirely self-contained), simply run:

echo safe_text('bob@examplecorp.com');

Update: Thanks to Fredrik for a fix that makes this function multibyte safe! It now also works with special characters like å,ä,ö and similar.

15 web design resources that will save you time and improve your designs!

25/03/2010

I have been doing quite a lot of creative work recently in the domain of web design (get it, “domain”, har har!) , and I’d be happy to share some of the great web sites and applications that have helped me make better and cleaner design and code jobs. I have divided the sites into six categories, so take your pick and dig in!

If you have any suggestions of your own, I’d be happy to hear them, leave a comment and be heard!

Cliparts and photos

image 

Sxc.hu – Royalty free photography
Sxc.hu, or stock.xchng, is the little brother of  iStockphoto. They offer royalty-free photography for non-commercial use, and an option to contact the authors for use in commercial application using a very relaxed license. My experience with the people there has been great as a whole, highly recommended and great array of photographs, but also clip art.

image 

clker.com – public domain clip art
Clker.com offers public-domain clip art uploaded by users. Great site for any smaller images that you might need, such as bullets and icons.

Compatibility

image

Common font list
When designing a page, you need to make sure you use a font that is visible to and looks visually similar for every viewer, and degrade gracefully in the cases where the font is not present on the viewers computer. This useful webpage displays common font families that work over a wide array of browsers and operating systems.

Inspiration

image

BrowserShots
BrowserShots has lost its glory days as the go-to site for making sure your web pages look equal across all browsers due to its increasingly long rendering waiting time and restrictions, and with IETester mentioned below, you can verify that your page runs properly on all major browsers.

But BrowserShots has introduced a fantastic gallery of web designs, and this is a place where you can find great inspiration.

image

ColorSchemer gallery and ColourLovers palette gallery
Finding the correct colors for your site can be a surprisingly difficult challenge, but when browsing these galleries, this becomes a fun experience. The idea is that you pick a scheme, which contains roughly 3-8 colors, and then try to base your design around these. If you try it, you’ll find a surprisingly clean and beautiful site looking back at you when you are finished. Using schemes with multiple variation of the same color (like this one) has worked the best for me.

image

Web Design From Scratch
A great resource for articles about the philosophy behind, and practical application to modern web design.

Applications/Add-ons

image

Sizer
Sizer is a small application which allows you to easily resize your browser (or really, any) window to see your web pages (hopefully) degrade in a graceful manner. Simple and easy, yet invaluable.

image

Firebug (Firefox add-on)
Firebug is a great web developer tool built as a Firefox add-on. I have barely scraped the surface of this great tool, but it has been very helpful so far.

image 

IETester
Your web design and CSS looks great in the latest versions of Firefox, Chrome, Opera and IE? You’re not done yet! Unfortunately, a large portion of people still use Internet Explorer 7 and 6 (*shudders*) and this tool will help you make sure your design stays true to its form. (although it probably won’t until you spend an hour trying to figure out why IE6/7 doesn’t handle inline block  properly, which brings us to…)

Fixes and hacks for common problems
  image

Google
This might seem like an odd choice at first, but if you’ve ever had a problem, googling will almost always lead to an answer. The great thing about the internet is that chances are great that somewhere, someone has had your exact problem and either asked about it in a forum or given a solution in a blog post, which will usually lead you closer to an answer.

image 

IE PNG Fix
It is fairly common knowledge that Internet Explorer 6 and below does not handle the alpha channel (transparency) for PNG images properly and displays the whole transparent area as a gray box. Resorting to GIF is possible for single-colored background, but for patterned backgrounds your only choice is PNG and this fix (Which is mostly done in CSS) will take care of that.

A quick note: I have noticed that the JavaScript used for tiling images in “IE PNG Fix”, which is called “iepngfix_tilebg.js” seems to break the dropdown functionality of Superfish, which I mentioned earlier. I have been looking at the problem, but haven’t been able to identify the culprit, although I suspect it is related to the way the JS places the image. Unless you absolutely need tiling support, it’s best not to use the JS code, so beware!

image
CSS Sticky Footer
Making a footer that always stays at the bottom of the page, moves with JavaScript and  works over all major browsers is a surprisingly difficult task, but CSS Sticky Footer takes care of it. It requires you to import a fairly large CSS file, but it shouldn’t break your layout too much, aside from a margin that needs fixing here and there.

Coding
 image

CodeIgniter PHP Framework
CodeIgniter is a great framework for easily making web applications in PHP. The features I have enjoyed so far is the fantastic database handling using Active Record, the interesting Model-View-Controller approach (which was new to me) and the great performance I get from my applications. If you want to know what the hype is about, check out this video tutorial entitled “Create a blog in 20 minutes”!

image

Suckerfish JavaScript/CSS menu system
Another thing that seems like there should be a myriad of online, but is surprisingly difficult to find is a menu that works over all browsers, is completely free, simple to use and can be used in commercial applications. Look no further, Suckerfish is what you have been waiting for! And it degrades nicely to CSS-only under environments without JS too!

Bored? Try my hellish Image Maze web game!

21/09/2009

imagemaze_level1The beginning…

Level-based/hacker web games have been around for a long time now. The usual premise is that you land on a page using your browser, and with the help of the information on this page are supposed to reach the “next level”, ie. the next page, with yet another mystery, and so on. This is accomplished by either manipulating the URL through the hints you have received, or inputting a password in a form on the page.

I’ve always thought it was a great concept and have played quite a few of them in my days. (Although I’m having a real time finding them right now, maybe I’m using the wrong search terms – if you remember any of these classics, feel free to post the link to them in the comment section!)

But you’re not here for them, no you’re in for my very own Image Maze. So head on over to
http://fs.shrtl.com/imagemaze/ and you’ll soon notice that you have been bumped to
http://fs.shrtl.com/imagemaze/first – “first” being the level name, and your task is to find the next level, for example, if you were to guess that the next level is called “brownie”, you simply go to http://fs.shrtl.com/imagemaze/brownie/ and check it out. Now you’re on your own!

The game contains six levels, which quickly go from very simple to sucker hard, each level has a very vague hint on what to do to find the next level name, and features some of the photos I’ve taken over the years. Once you’ve finished all of the levels you’ll get a unique code, post it in the comment section if you want to brag about your accomplishment! 🙂

I’ve assembled a bunch of hints if you get stuck, but don’t peek unless you’re absolutely lost – because just like Hint Coins in Professor Layton, it ruins the experience! In order to view the hints, simply mark the text in the black boxes below.

Hints:
Level 1 – What kind of extra information does an image carry when used in HTML?
Level 2 – Now would probably be a great time to check out the HTML code!
Level 3 – Woah, that’s quite a big image – but why?!
Level 4 – What usually causes an image to now be shown?
Level 5 – Your browser won’t help you solve this one, there’s a secret inside the image.
Level 6 – This one is kind of like the last one, only the other way around.

In other news…
ticketbastard

Small logo improvement suggestion to account for actual company policy.

The oddball, unstable queue  and booking system employed by Swedish event ticket seller Ticnet stinks. The fact that they have pretty much a monopoly on any larger event doesn’t make things better. I guess I’ll just have to enjoy my Rammstein concert sitting down… in the back… Blargh.

Software Release: Homepage downtime kit for Apache v1

27/08/2009

downtimekitscreenshotThe bad boy in action.

When you’re managing a homepage for a while, there will be the times when you absolutely need to take your site down for maintenance – be it a hardware upgrade, code upgrade (When migrating to a new version of your/someone elses software.) or disk maintenance due to power loss or crash. But what do you show your users while the regular homepage is unavailable? Simply shutting down the server resulting in an error for the end-user is kind of boring, and gives a far less memorable expression than having a proper downtime page, all the big boys are doing it, so why shouldn’t you?

I spent a few minutes and hacked together a minimalistic “downtime kit”.

The easiest way is to temporarily redirect your page somewhere else (where you host the downtime kit) during the downtime, and there’s a multitude of ways to do so, all depending on the architecture of your hosting setup, so you’ll have to think of the best way for you to utilize this kit.

As for how it works, it simply uses the mod_rewrite functionality in Apache to redirect image requests to one central image, so that any hotlinked images you might have show a proper downtime dialogue on their respective pages. It also redirects users who want to download files and visit pages to a proper downtime dialogue.

Setting the kit up to work for your page takes less than a minute, here are what needs to be done (taken from the readme.txt file in the distribution.)

Prequisites:

  • PHP5 (Should work with PHP4)
  • Apache with mod_rewrite (XAMPP Lite distributions work great for this purpose.)

    License:
    This kit is released as beerware, a very permissive license, so do whatever you please with the code.

    Download link:
    zip file – (Mirror 1 / Mirror 2)

    Tutorial:

    1.) Upload all the files into the root of your web directory, if you want to restrict the script to a subfolder, read step 2, otherwise skip to 3.

    2.) If you uploaded the distribution into a subfolder (like http://www.mypage.com/ahomepage) instead of the root (which in this case would be http://www.mypage.com) – open the .htaccess in a text editor and change the second line from:
    ErrorDocument 404 /index.php
    …to:
    ErrorDocument 404 /<your subdirectoryhere>/index.php

    In our previous example, this line would be:
    ErrorDocument 404 /ahomepage/index.php

    If you have vhosts that link a subfolder to a domain name (ie you can visit the page at ahomepage.mypage.com) this step is not necessary.

    3.) Open config.php in a text editor and change the text
    <b>Status:</b><br>This page is down!
    …to whatever you wish for your downtime page to show.

    4.) Optionally change the notfound.jpg image for another one that suits you or your homepage better.

    5.) Enjoy!

    In other news…

    constantsCover art for “The Constants – The Foundation, The Machine, The Ascension”

    In this episode of “In other news…” we’re going to talk about post-rock. It feels like such a huge topic, but I’ll just satisfy myself by saying it’s a fantastic genre of music, especially instrumental post-rock, so without further ado, here is a list of some of my favourite post-rock band, in unspecified order – click on the band names to visit their homepages/profiles.

    Most of these bands are relatively small, and you can find a lot of music on their respective Myspace profiles and homepages.