Archive for the ‘How-To’ Category

Using Twilio with CodeIgniter– a model for rapid development

Friday, July 9th, 2010

I’ve developed a CodeIgniter model (attached below) for rapid development of a Twilio-powered app. If you’re not familiar, Twilio lets you develop web apps that interface with telephony via an XML-based API.

This model only deals with incoming calls at the moment, but if I get some feedback (or need it for my own purposes), I’ll update it to initiate outgoing calls, voice->text, as well.

Here’s an example of usage:

$body = $this->twilio->say('Thanks for calling!', 'woman');
$gath = $this->twilio->say('Please enter your ID number then press pound');
$body .= $this->twilio->gather($gath, '/voice/process/idcheck/', 6);
$body .= $this->twilio->redirect('/voice/answer/noid/');
echo $this->twilio->build($body);

These 4 lines, generate the appropriate XML code to have a computerized woman’s voice say “Thanks for calling!”, then the script starts listening for touch-tone entry of a 6 digit number and says, in a male voice, “Please enter your ID number then press pound”. If a 6 digit number is entered, it POSTs it to /voice/process/idcheck/, if not, it redirects to /voice/answer/noid/

The model is available for download here.

Questions? Problems? I’m happy to help.

Want Hotchkiss Consulting to help develop your phone-based app?  We’d love to.

Manually adding Social Media links to a WordPress Theme

Friday, February 19th, 2010

Here’s a set of links to add your posts to Digg, Twitter, StumbleUpon, Del.icio.us, Facebook, MySpace, Google Bookmarks, Technorati, AddThis, and Reddit– I always end up needing these for themes I’m building, so I thought I’d pass them along!


<!-- Digg -->
<a href="http://digg.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" rel="nofollow" title="Submit to Digg" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/digg.gif" alt="Digg" title="Digg" /></a>
<!-- Twitter -->
<a title="Tweet About It!" href="http://twitter.com/home?status=<?php the_title(); ?> <?php the_permalink(); ?>" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/twitter.gif" alt="Twitter" title="Twitter" /></a>
<!-- StumbleUpon -->
<a href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" rel="nofollow" title="Stumble It!" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/stumbleupon.gif" alt="StumbleUpon" title="StumbleUpon" /></a>
<!-- Delicious -->
<a href="http://delicious.com/save?url=<?php urlencode(the_permalink()); ?>&amp;title=<?php urlencode(the_title()); ?>" onclick="window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url=<?php urlencode(the_permalink()); ?>&amp;title=<?php urlencode(the_title()); ?>', 'delicious', 'toolbar=no,width=550,height=550'); return false;" title="Bookmark this post on del.icio.us"><img src="<?php bloginfo('template_directory'); ?>/images/social/delicious.gif" alt="Delicious" title="Delicious" /></a>
<!-- Facebook -->
<a href="http://www.facebook.com/share.php?u=<?php the_permalink(); ?>" rel="nofollow" title="Share on Facebook" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/facebook.gif" alt="Facebook" title="Facebook" /></a>
<!-- MySpace -->
<a href="javascript:GetThis('<?php the_title(); ?>','<?php the_excerpt(); ?>', '<?php the_permalink(); ?>')"><img src="<?php bloginfo('template_directory'); ?>/images/social/myspace.gif" alt="MySpace" title="MySpace" /></a>
<!-- Google Bookmarks -->
<a href="http://www.google.com/bookmarks/mark?op=edit&bkmk=<?php the_permalink(); ?>" rel="nofollow" title="Bookmark on Google" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/google.gif" alt="Google Bookmarks" title="Google Bookmarks" /></a>
<!-- Technorati -->
<a href="http://technorati.com/faves?add=<?php the_permalink(); ?>" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/technorati.gif" alt="Technorati" title="Technorati" /></a>
<!-- AddThis -->
<a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&amp;username=xa-4b6908a945df8eb0"><img src="<?php bloginfo('template_directory'); ?>/images/social/addthis.gif" alt="Bookmark and Share" style="border:0"/></a><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4b6908a945df8eb0"></script>
<!-- Reddit -->
<a href="http://reddit.com/submit?url=<?php the_permalink(); ?>" rel="nofollow" title="Submit to Reddit" target="_blank"><img src="<?php bloginfo('template_directory'); ?>/images/social/reddit.gif" alt="Reddit" title="Reddit" /></a>

In a WordPress theme, only show an element on the first page

Thursday, February 18th, 2010

I just had a colleague shoot me a quick question– he had a flash animated header that he wanted to only show up on the home page, so he wanted to know how he could keep it in the header, but only have it show up on that home page. Without further ado, here’s the code:

<?php if (is_home()) : ?>
<!-- Content to only show on the home page -->
<?php endif; ?>

Easily Add Twitter Status to any page with PHP

Tuesday, February 16th, 2010

Quick post– I found a lot of answers to this problem but none that really worked for me…

This will output your latest twitter status, converting any URLs or email addresses to clickable links:

function get_status($twitterid) {
$xml = @simplexml_load_file('http://twitter.com/statuses/user_timeline/'.$twitterid.'.xml?count=1');
if($xml->status) {
foreach($xml->status as $status){
$text = $status->text;
$text = html_entity_decode($text);
$text = " ".$text;
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1" target=_blank>\\1</a>', $text);
$text = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1" target=_blank>\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2" target=_blank>\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'<a href="mailto:\\1" target=_blank>\\1</a>', $text);
$text .= "<h4>Posted from $status->source</h4>";
}} else {
return 'Trouble in Twittersville, API not loading, sorry!';
}
return $text;
}

Then, to call it, just use this function:


get_status('YOUR_TWITTER_ID');

with your numerical Twitter ID in the obvious spot. You can find your Twitter ID by looking at the URL for your Twitter RSS feed, which will be:

http://twitter.com/statuses/user_timeline/YOUR_TWITTER_ID.rss

Accessing content for non-active languages with qTranslate

Thursday, January 14th, 2010

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

Sunday, November 15th, 2009

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

Saturday, November 14th, 2009

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.

Wednesday, May 27th, 2009

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

Friday, April 24th, 2009

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

Sunday, April 12th, 2009

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…)

Powered by Olark