we work magic with and CodeIgniter

Archive for the ‘How-To’ Category

Migrating WordPress sites between dev and live servers

Posted on: September 19th, 2011 by Sam Hotchkiss

In my work, at least once a week I’m either copying a live site onto my development server or moving a site back to the live server. I’ve figured out a few tricks along the way.

Notice: This post assumes that you have a basic comfort level with the command line, it assumes you have a linux web host, and it assumes you’re not going to sue me or hold me responsible if you break something. If that’s not the case, please stop reading now!
(more…)

Checking for (and blocking) free email accounts with jQuery Validation plugin

Posted on: September 9th, 2011 by Sam Hotchkiss

The jQuery Validation plugin is one of the most commonly used and useful jQuery plugins. One of the nicest things about it is how easily you can extend it.

I recently had a client ask me to build a form which wouldn’t allow users to sign up with free email addresses– in particular, no Gmail, Yahoo!, or Hotmail accounts. After playing with it for a little bit, I came up with the following jQuery Validation method to check for, and block, Gmail, Yahoo!, and Hotmail (you can easily add other free email providers):

$.validator.addMethod('nofreeemail', function (value) {
    return /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)([\w-]+\.)+[\w-]{2,4})?$/.test(value);
}, 'Free email addresses are not allowed.');

Once you’ve added the method, you can easily call it:

$("#signup_form").validate({
		rules: {
			'user[first_name]': "required",
			'user[last_name]': "required",
			'user[title]': "required",
			'user[phone]': "required",
			'user[email]': {
				required: true,
				email: true,
				nofreeemail: true
			}
		}
});

So– to wrap up, the final code is:

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	$.validator.addMethod('nofreeemail', function (value) {
	    return /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)([\w-]+\.)+[\w-]{2,4})?$/.test(value);
	}, 'Free email addresses are not allowed.');

	$("#signup_form").validate({
		rules: {
			'user[first_name]': "required",
			'user[last_name]': "required",
			'user[title]': "required",
			'user[phone]': "required",
			'user[email]': {
				required: true,
				email: true,
				nofreeemail: true
			}
		}
	});
});
</script>

Accessing content for non-active languages with qTranslate

Posted on: January 14th, 2010 by Sam Hotchkiss

I’ve recently been working on a new site for a large Jewish philanthropic organization, developing a (very) custom WordPress theme for their site– when it came to coming up with a way to handle bilingual English/Hebrew content, we tried a few WordPress plugins before settling on Qian Qin’s qTranslate, which has been wonderful– great user interface, easy for the client to grasp, easy to work with.  The one problem I encountered way that there is no easy way to reach across languages for content, which was necessary for one section of the site where English content needed to appear alongside Hebrew content.  Without any further ado, here’s the snippet of code I came up with to get at both languages– you are left with $p_title and $p_body which are both arrays, and you need to make sure to substitute your language in for Hebrew, and your language 2 letter code in for iw on line 3:

$enddelim = '<!--:-->';
 $englishdelim = '<!--:en-->';
 $hebrewdelim = '<!--:iw-->';

 $getpost = get_posts('post_type=page&include='.$post->ID);
 foreach($getpost as $p2) :
 setup_postdata($p2);
 $both_titles = 'blah'.$p2->post_title;
 $both_bodies = 'blah'.$p2->post_content;
 endforeach;

 if(strpos($both_titles, $englishdelim)) :
 $pt1 = explode($englishdelim, $both_titles);
 $pt2 = explode($enddelim, $pt1[1]);
 $p_title['english'] = $pt2[0];
 endif;

 if(strpos($both_titles, $hebrewdelim)) :
 $pt1 = explode($hebrewdelim, $both_titles);
 $pt2 = explode($enddelim, $pt1[1]);
 $p_title['hebrew'] = $pt2[0];
 endif;

 if(strpos($both_bodies, $englishdelim)) :
 $pt1 = explode($englishdelim, $both_bodies);
 $pt2 = explode($enddelim, $pt1[1]);
 $p_body['english'] = $pt2[0];
 endif;

 if(strpos($both_bodies, $hebrewdelim)) :
 $pt1 = explode($hebrewdelim, $both_bodies);
 $pt2 = explode($enddelim, $pt1[1]);
 $p_body['hebrew'] = $pt2[0];
 endif;

Calculating age with PHP using a birth date

Posted on: November 15th, 2009 by Sam Hotchkiss

UPDATED 12/2: Code updated for efficiency and code download link added.

Ran into a problem today– there’s no easy way to add and subtract dates in PHP and be left with standard units (year, month, day, etc), so I whipped up a quick script to do it– the biggest problem is months, here, since PHP deals with second-based timestamps, and months don’t possess a standard number of seconds. Without further ado, here’s the code– I hope it’s helpful to your projects:
(more…)

An easy way to handle previous and next product links

Posted on: November 14th, 2009 by Sam Hotchkiss

I’m working on a custom eCommerce site for a customer right now, and ran into an issue– they wanted to have, on every product page, a forward and back button to get to the previous and next items. The problem with this is that they may have arrived on the product page in a couple of different ways, through search or browsing, with different criteria set.

I came up with this easy routine which goes through the result set, whether it’s search result or category view, then creates an array where the key is the current product ID, and the values are the IDs of the product before and the product afterward. So if I’m on product 157, $ordering[157]['next'] will give me the ID of the next product. Just pop it in a session, and you’re good to go.

Simple and straightforward– feel free to reuse all you like!
(more…)

Ditch the Bacn, get the email you want.

Posted on: May 27th, 2009 by Sam Hotchkiss

Mmmm, BacnThe term ‘Bacn‘ has been around for a couple of years to refer to, according to wikipedia:

electronic messages which have been subscribed to and are therefore not unsolicited but are often unread by the recipient for a long period of time, if at all. Bacn has been described as “email you want but not right now.”[1][2]

Bacn differs from spam in that the emails are not unsolicited: the recipient has somehow signed up to receive it. Bacn is also not necessarily sent in bulk. Bacn derives its name from the idea that it is “better than spam, but not as good as a personal email”

Bacn is, generally, non-urgent, not terribly exciting, but may still be information that you want and need.

So we’ve got Spam, Bacn, and then email that actually matters– personal email from one person to another (you!).  I’ll call that chops.  So, how do you keep current on your chops without getting distracted by the spam and bacn?

At Hotchkiss Consulting we use Google Apps to manage our email,  and it does a great job of removing the Spam.  But I can’t stand when I’m in the middle of a project and I get distracted by the constant inflow of Bacn, so I decided to get rid of it!  Since Google Apps is built on the Gmail core, these instructions should work for any gmail user.  Feel free to modify to fit your needs! (more…)

Controlling the Third Gen iPod Shuffle

Posted on: April 24th, 2009 by Sam Hotchkiss

apple-ipod-shuffleBecky got me a 3g iPod shuffle back when they first came out, and it’s been great.  It’s TINY, super light, battery lasts all day… etc etc etc.  It also has no buttons, so you use a little block in the headphone cable by your right cheek to control it.  Apple tells you you can use this to skip tracks forward, skip tracks backward, pause, play, change the volume, and change playlists.  But there are a couple of hidden features, too!

Skip forward within a song: Click the button once, then hold it.  This will fastforward within the song or podcast.

Skip backwards within a song: Click the button twice, then hold it (you have to do this quickly).   This will rewind within the song or podcast.

Skip through songs while hearing the name of every song.  Hold the button until it starts reading the name of the song to you, then double-click the button.  It will speak the name of the new songs as you get to them.

Skip through playlists: Once you hold the button long enough that it starts reading back your playlists, release the button and you can use the volume up and down buttons to quickly scroll through your playlists.

Anybody know any other neat tricks?  Let me know in the comments!

Update: I guess the fast forward/rewind tricks ARE in the online manual… but I could have sworn they’re not in the little booklet. I’ll have to check tonight.

Remember the Milk Email Scripts

Posted on: April 12th, 2009 by Sam Hotchkiss

I know I’ve been promising these for a while, but here are the three PHP scripts that make up my PHP -> Email integration.  I’m still working on converting this to a full multi-user system.  You can see I already started with the conversion on the schedule dispatch email.  Full scripts after the jump!

(more…)

Building an eMail interface for Remember the Milk using PHP

Posted on: March 6th, 2009 by Sam Hotchkiss

UPDATE: Scripts are available here: http://hotchkissconsulting.net/177/remember-the-milk-email-scripts/

rtmSo, in accordance with my plan to switch client communication from phone to email, I have decided that, instead of a Cell Phone, I will carry a Peek with me.  While it has been a rocky road so far, I trust that the people at Peek have some good updates coming down the pipeline, so I’m going to stick it out for a couple months and see how I like it.

The thing about the Peek is that it’s eMail only.  And I really do mean only.  No calculator, no games, no web browser, and no calendar.  For me, that just won’t do– I am an avid fan of Remember the Milk.  I keep it in my OS X dashboard and on my desktop email screen (I use GFYD, Google For Your Domain).  Having my RTM to go is a must.

Currently, RTM offers a couple email-based options.  You can email in new tasks, you can receive a list of your tasks for the day every morning via email, and you can receive an email reminder before a task is due.  This is a good start, but there are some problems:

1) With the daily schedule emails, you can only see what’s going on that day, you can’t see your entire schedule.  This information is crucial for setting appointments.

2) Reminder emails don’t have the task name in the subject line, meaning you have to open the email to see what you’re supposed to do.

3) You can’t do anything with the tasks– no marking them completed or postponing, you have to do this from the computer.

So, I wrote my own email interface, and will go over it and include my source files so you, too, can build your own (if you’ve got some PHP know-how).  If there’s enough interest, I will build a standalone, hosted solution for everyone of every skill level. (more…)