Kinetic Pulse
  • Home
  • Services
  • Portfolio
  • Blog
  • Terms
  • Contact

Improved way of getting last Twitter status using SimplePie

September 4, 2010

On Aug 31st 2010 Twitter changed its way that applications could authenticate with it – it now uses OAuth http://blog.twitter.com/2010/08/twitter-applications-and-oauth.html

In a previous post, Display your last tweet using PHP & Twitter API
I had suggested use the cURL command in php to send the Twitter username & password to authenticate with the Twitter API to retrieve the xml of the status updates.

However this no longer works with the coming of OAuth – a problem that some of my clients noticed over the past couple of days.


So how to fix this? Well I looked into the scant (and baffling) documentation on OAuth, and downloaded a library or too for php implementation of the Twitter OAuth, but I had this nagging feeling I was using a hammer to crack a nut. Surely anyone can see what my last Twitter update is just by going on Twitter – they don’t need to be logged in?

Then it hit me – that the xml that was being returned could be read using a feed reader like good old SimplePie!

I know it works on the 1&1 hosting that myself and my clients use. I know that you can read Twitter statuses in a feed reader (like Google Reader) so it must be possible.

So thanks to this hugely helpful post here:
http://www.sitepoint.com/blogs/2009/09/29/build-a-lifestream-with-simplepie/
I’ve written the following function that allows you to get the last Tweet of a particular Tweeter:


<?php

require_once('includes/modules/simplepie.inc');
$cache = "/cache";
$duration = 1800;
// snipe's twitterify function turns links into clickable goodness
// http://www.snipe.net/2009/09/php-twitter-clickable-links/
function twitterify($ret) {
   $ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a
href=\"\\2\">\\2</a>", $ret);
   $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a
href=\"http://\\2\">\\2</a>", $ret);
   $ret = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1
\">@\\1</a>", $ret);
   $ret = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?
q=\\1\">#\\1</a>", $ret);
   return $ret;
}
function getLastTweet($username){
   $twitter = new SimplePie("http://twitter.com/statuses/user_timeline/$username.rss", $cache, $duration);
   foreach ($twitter->get_items(0,1) as $item) :
    echo twitterify(str_replace("$username: ", "", $item->get_title
()));
   endforeach;
}
?>
<?php getLastTweet("GriffithsHire");?>

Add a Facebook Like button to individual products in Zen Cart

August 25, 2010

After being asked by a client to add a Like button to each of her products (like ASOS) and getting confused by Facebook’s documentation on adding custom Like buttons, I stumbled upon this excellent post for how to do it in WordPress:
http://www.hyperarts.com/blog/how-to-add-facebook-like-button-social-plugins-to-wordpress-posts/
I have adapted it to work with ZenCart


1) Register for an application with Facebook – write down your application ID and your Admin id (see the HyperArts post for a good explanation)
(BTW I had a blank screen problem after creating an application – but the app was there when I went to my applications home page in Facebook)

2) Add the following into your html header – change your html tag to read:

<html xmlns=”http://www.w3.org/1999/xhtml”
xmlns:og=”http://opengraphprotocol.org/schema/”
xmlns:fb=”http://www.facebook.com/2008/fbml” >

3) Add the following meta tags

<meta content=”YOUR ADMIN ID” property=”fb:admins”></meta>
<meta content=”YOUR APP ID” property=”fb:app_id”></meta>
<meta content=”product” property=”og:type”></meta>
<meta content=”<?php echo META_TAG_TITLE; ?>” property=”og:title”></meta>
<meta content=”YOUR MAIN SITE URL<? echo $_SERVER[‘REQUEST_URI’];?>” property=”og:url”></meta>’

4) The Like button should live somewhere on the tpl_product_info_display.php template

<div id=”fb-root” ></div>
<script>
    window.fbAsyncInit = function() {
    FB.init({appId: ‘YOUR APP ID’, status: true, cookie: true,
    xfbml: true});
    };
    (function() {
    var e = document.createElement(‘script’); e.async = true;
    e.src = document.location.protocol +
    ‘//connect.facebook.net/en_US/all.js’;
    document.getElementById(‘fb-root’).appendChild(e);
    }());
</script>
<fb:like action=”like” colorscheme=”light”
layout=’standard’ show_faces=’true’ width=’500’/>
</fb:like>

I’m aware that as a newbie I’ve probably made a few errors along the way but it seems to work for now. Any comments would be appreciated!
Here’s the example at work:
http://www.thecherrycloset.com/index.php?main_page=product_info&cPath=3&products_id=191

UPDATE: 28th Aug 2010
While the code above was working I was getting the annoying problem with a random product image (eg one of the additional images) appearing next to the shared link on facebook – and not the main product image.
This might not be a problem for Zen Carts that only have the one product image – but it needed to be fixed.
Cue time to delve into the inner workings of Zen Cart:

1) Modify the includes\modules\meta_tags.php file:

The SQL SELECT statement around line 210 needs an additional field adding in the list;
“p.products_image“

Then about line 225 I have the following line:

  $meta_products_image = $product_info_metatags->fields[‘products_image’] ;

Then at line 296 I add a new line to define a new variable called META_TAG_PRODUCT_IMAGE

    define(‘META_TAG_PRODUCT_IMAGE’, $meta_products_image);

2) Modify the html_header.php template as above by adding the following line:

<meta property=”og:image” content=”http://YOUR SITE URL/images/<? echo META_TAG_PRODUCT_IMAGE;?>” />

How to stop that balloon appearing on embedded Google Maps

July 12, 2010

Just a quick one.
Google Maps is great for embedding a quick map on a Contact Us page – but often the pop-up ballon that appears giving more info about the address can look out of place – especially if the frame you are displaying it in is smaller than the balloon.
Its tough to find official documentaion on how to easily customise these embedded maps, but here is a nice post with details of some of the extra variables that appear in the querystring for the url of the iframe:
http://mapki.com/wiki/Google_Map_Parameters

So, if you have the one address that you just want to display the red “pushpin” for, and NOT the balloon, do the following:

1) In the embedded code you have copied from Google, locate the parameter in the iframe src url (not the href for the text View Larger Map) that says “iwoc=A”
2) Change it to “iwoc=B”

According to mapwiki (see link above) it changes the balloon’s position to be over the pushpin for B – and as that doesn’t exist in this case,  it doesn’t appear – woo hoo!

There is probably a neater, less voodoo, way to do this – but this works for me for now!

Make selecting size attribute compulsory in ZenCart

July 7, 2010

I love Zencart most of the time – but its implementation of size/colours attributes always causes me headaches.
A common request is for the size to be compulsory when adding a product to the basket.

But the official Zen cart way of doing it involves a complex process of adding a dummy option to the top and forcing that to be default. Not a great way – especially as you can still end up with an item in the basket that has a size of “Please select…”

So I’ve written a quick n dirty javascript/jQuery function to check if the option has been chosen:

In the tpl_product_info_display.php template add the following javascript above the line that says

<?php echo zen_draw_form(‘cart_quantity’, zen_href_link(zen_get_info_page($_GET[‘products_id’]), zen_get_all_get_params(array(‘action’)) . ‘action=add_product’), ‘post’, ‘enctype=”multipart/form-data”‘) . “\n”; ?>
<script type=”javascript”>
var clickedOption  = false;
$(document).ready(function() {
    $(“input[name*=’id[1]’]”).click(function() {
        clickedOption  = true;
    });
});
function checkOptions(){
    if(clickedOption){       
        return true;
    }else{
        alert(“Please select a size”);
        return false;
    } 
}
</script>

Note: You will have to repeat the $(“input[name*=’id[1]’]”).click() function for as many possible attributes you have. (Calls for some sort of loop surely?!)

Then change the following line:

<?php echo zen_draw_form(‘cart_quantity’, zen_href_link(zen_get_info_page($_GET[‘products_id’]), zen_get_all_get_params(array(‘action’)) . ‘action=add_product’), ‘post’, ‘enctype=”multipart/form-data”‘) . “\n”; ?>

to

<?php echo zen_draw_form(‘cart_quantity’, zen_href_link(zen_get_info_page($_GET[‘products_id’]), zen_get_all_get_params(array(‘action’)) . ‘action=add_product’), ‘post’, ‘enctype=”multipart/form-data” onSubmit=”return checkOptions();”‘) . “\n”; ?>

So that it forces the checkOptions() function to run each time you try to add something to the cart

I admit this is very quick-and-dirty – and it only caters for 1 option at a time on the page.
And I know purists among you will bemoan the fact that this is just client side validation, and what if the visitor doesn’t use Javascript etc etc.
Well it works for me for for now.
Who knows maybe I’ll post an update with all these issues addressed? For now, enjoy!

10 ZenCart Plugins you really need to install

June 28, 2010

I’m working on this post to list my favourite plugins that I almost always use on my Zen Cart sites – I’m up to nine at the moment – I’m just working out wihich others are worthy enough to make it into my top ten. Any suggestions? I’d be interested….

1) Easy Populate
http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=395
Allow import of product lists – very useful for getting lots of stock into the site at the start. Also works with modifying products too.

2) Sage Pay Form
To integrate using SagePay Form – ie redirects customer to the SagePay site to take payment/ In these days of PCI Compliance its my recommended solution
http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=1385
(CeonDev does modules for SagePay Direct but they are not free – very good though)

3) About Us Page
http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=182
Lest face it, those “EZ Pages” are not very nice and not very SEO friendly are they?
This mod allows you to create your own pages with associated includes. Painful to start with but worth it!

4) Column Layout for Product Listing
http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=77
Show your products in columns rather than one long list (does need tweaking in CSS to hide messily long product descriptions)
eg http://www.deadlyisthefemale.com/index.php?main_page=index&cPath=1_2


5) Newsletter Subscriptions
http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=106
Allows user to sign up for just a newsletter rather than having to register with the site

6) HTMLArea Image Manager
http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=318
Allow client to upload their own images – and view what images they already have installed.
Much easier than having to explain FTP to them
Even includes simple image editing tools (crop etc)

7) Stock with Attributes
http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=1199
ZenCart by default only allows you to keep track of the stock for the product itself – not its variants (eg sizes, colours)
Use a plugin like this to keep track of how much stock you have in various sizes.

I am very hesitant to put on the SEO mod that I talk about here as in practice it is troublesome to implement and can make the site very slow… Any suggestions for good SEO modules for ZenCart are most welcome!

Update: 30th June 2010.
8) CEON URI Mapping (SEO)
http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=1269
I am now officially in love with this mod. Its a little fiddly to install if you have made any mods to your site (so install this first!)  but once in its the ultimate in nicely working URL rewriting for your site.
OK its mostly the Categories & Products pages its rewrites (you have to manually add any other pages yourself – eg special offers etc) But the beauty of this mod is in its flexibility – you are in control of the URLs that get mapped so you can choose nice clean ones, without ugly ids! One thing to note that it doesn’t auto generate the custom URLs on the fly (making it faster than other mods) so you will have to go through all existing categories & products to update the “slug” – but any new category/product should have this generated automatically (I’m guessing it won’t get generated for EasyPopulate batch uploads of products either) Still it works – and I’m in the throes of writing a quick n dirty SQL patch to loop through existing categories & products and insert them into the appropriate table to be used for the URL mapping

Update : 19th July 2010
9)Multi Cross Sell
http://www.zen-cart.com/index.php?main_page=product_contrib_info&products_id=1677
Only just installed this but it looks like a winner – to be able to link multiple products so that they show up when you view a particular product page. To give a “you may also be interested in” panel of products that you might want to promote.

10) Additional Table Rates
http://www.zen-cart.com/index.php?main_page=product_contrib_info&cPath=40_51&products_id=1027
Realy useful to add the additional delivery options such as Next Day Delivery to your ZenCart

  • Newer
  • 1
  • …
  • 10
  • 11
  • 12
  • 13
  • 14
  • …
  • 16
  • Older

Testimonials

Thank you guys so much for all that you’ve done helping us to create a really awesome website!! We get such great feedback – everyone loves it & we couldn’t be prouder! Look forward to working with you again soon!
Wild Thyme PlantsWild Thyme Plants
I like it.  I like it a lot !!!

 You have interpreted what I wanted to achieve perfectly considering what you have to play with i.e not redoing the whole thing in the process.

Fiona Simmons-MooreSouth Gloucestershire Parents & Carers
It’s been fab working with you – we love the site and certainly going to recommend you!
James DaviesThirty Eight Degrees North
Thanks so much for all your work on this, really appreciated. It’s come on in leaps and bounds since you took over.
Pete KewRedwood Strip Curtains
Absolutely fantastically professional web developer – I would highly recommend!!! Thank you so much Kinetic Pulse!
Tania MarstonDoris Designs
Amazing and brilliant, Kinetic Pulse have lifted a dream to reality, Highly recommended and great if you are total novice, they know their stuff…Thanks again
Annie LindridgeSalt Yourself Out
Thank you for all of your hard work its looks fab and I am over the moon with it!
Amanda MercerAmanda Mercer Ceramics

Copyright 2026 Kinetic Pulse