Obtain Facebook likes via PHP SDK


In an update to this post here is another way to obtain the number of likes for a Facebook page.

I’ll assume that you’ve already registered a Facebook application, have downloaded the PHP SDK and have included for use in your code.

require('facebook.php');

Setup an array with your Facebook applications credentials

$facebook = new Facebook(array(
'appId' => '000000000', // Put appID here
'secret' => '0000c000c000c000c', // Put your secret key here
));

Decide which page you wish to obtain the number of likes for

$getRequest = $facebook->api('/cocacola'); // Lets look at the Facebook page for the popular soft drink
echo $getRequests['likes'];

Obviously you can consume, contrast and display this information in more exciting ways than simply echoing it to the screen. Enjoy.

Obtain Facebook likes via PHP SDK Read More »

OSX Lion 10.7.2 Tweetdeck Crashes

Twitter

Tweetdeck has been crashing on startup recently, – seemingly without any kind of pattern. At first I attributed this to OSX Lion related issues, but sometimes having Firefox or Chrome open seemed to solve the problem.

I have finally tracked down the underlying issue to Adobe Air, the framework powering Tweetdeck and many other applications. In fact it is the switching software for late model Macbook Pros toggling between the discrete and integrated graphics cards. Launching Firefox or Chrome forces the graphics card to switch to discrete mode, solving the autoswitching and crashing on startup error.

You can manually change the setting to solve the problem by navigating to System Preferences -> Energy Saver. Uncheck the Automatic Graphics Switching at the top of the preferences dialog.

A better fix however is to use gfxCardStatus which is a menu bar application for OSX that allows users of dual-GPU 15″ and 17″ MacBook Pros to view which GPU is in use at a glance, and switch between them on-demand.

Update 29/01/2012
I have discovered that VMWareFusion does not play nicely at all with gfxCardStatus. Fusion will work if you disable dynamic switching and force the use of the discrete GPU but if you change between the two, expect major issues. I’m disabling gfxCardStatus before launching Fusion to avoid the problems.

OSX Lion 10.7.2 Tweetdeck Crashes Read More »

Adding copyright meta data to WordPress

Wordpress Logo

This simple example illustrates how easy it is to automatically have copyright information displayed in a sites meta tags. Simply place the following snippet in your functions.php file (remembering of course to substitute your own copyright details

add_action("wp_head", "add_copyright_meta");

function add_copyright_meta() {
if(is_singular()){
echo "<meta name="copyright" content="Company Details, Year">";
}
}

Adding copyright meta data to WordPress Read More »

Force trailing slash with .htaccess

There are a few reasons to force a trailing slash at the end of URLs including SEO

A quick snippet for your .htaccess is below:

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
</IfModule>

And while I’m here a quick snippet to prevent hotlinking of images. This will redirect all requests to a specified image, simply replace yoursite.com with your own URL, and nohotlinking.jpg with your own image and path.
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlinking.jpg [L]

And finally a snippet to put in your image assets folder (you have images stored separately right?) to prevent malicious code execution and prevent directory listing of all your assets.
Options All -Indexes
AddHandler cgi-script .php .php4 .php5 .pl .jsp .asp .sh .cgi
Options -ExecCGI

Force trailing slash with .htaccess Read More »

Use PHP to display Gravatar images


All URLs on Gravatar are based on the use of the hashed value of an email address. According to their best practice you should:

  1. Trim leading and trailing whitespace from an email address
  2. Force all characters to lower-case
  3. md5 hash the final string

Of course in PHP this is trivial as the following function shows:

function fetchGravatar() {
$fetchHash = md5(strtolower(trim('your_email.address.com')));
$GravatarImage = 'http://www.gravatar.com/avatar/' . $fetchHash;
return $GravatarImage;
}

Profiles are also available if you require them.

Use PHP to display Gravatar images Read More »

CSV to .plist conversion

Property list files (.pfiles) store serialized objects and are often used to store a user’s settings. They are also used to store information about bundles and applications in OSX and recently iOS.

Danilo Campos wrote some time ago some background information and provided his source and blogged about the subject. Better than that however, he provided an OSX binary to download if you want to get going straight away.

This little application makes it easy to format and process your source data in a familiar environment like Excel and then convert ready to use in your application.

EDIT: It seems Danilo has taken his blog offline, and also this binary. I suggest you now use this online tool: https://wtools.io/convert-csv-to-plist

CSV to .plist conversion Read More »

PHP Host Settings Without phpinfo()


Occasionally a webhost will block the very useful phpinfo() command making it difficult to understand any limitations of the server configuration. This script can display relevant information to help you understand what is happening behind the scenes.

<?php
$d_func = ini_get("disable_functions");
$up_max = ini_get("upload_max_filesize");
$up_max = str_replace("M","",$up_max);
$up_max_size = "Megabytes";
$post_max = ini_get("post_max_size");
$post_max = str_replace("M","",$post_max);
$post_max_size = "Megabytes";
$input_max = ini_get("max_input_time");
$mem_limit = ini_get("memory_limit");
$mem_limit = str_replace("M","",$mem_limit);
$mem_limit_size = "Megabytes";
$exec_time = ini_get("max_execution_time");
$safe_mode = ini_get("safe_mode");

if(!is_null($d_func) && $d_func !== ""){echo "Disabled Functions: \n $d_func";}
if(!is_null($safe_mode) && $safe_mode !== ""){echo "<span style='color:red;'>Safe Mode is Active</span> <br>";}
if($up_max >= 1001){$up_max = $up_max / 1024; $up_max_size = "Gigabytes";
if($up_max >= 10001){$up_max = $up_max / 1024; $up_max_size = "Terabytes";}}
if($post_max >= 1001){$post_max = $post_max / 1024; $post_max_size = "Gigabytes";
if($post_max >= 10001){$post_max = $post_max / 1024;$post_max_size = "Terabytes";}}
if (min($input_max,60)){$input_max = $input_max /60;}
if (min($exec_time,60)){$exec_time = $exec_time /60;}
if($mem_limit >= 1001){$mem_limit = $mem_limit / 1024; $mem_limit_size = "Gigabytes";}

echo "Maximum Upload Size = $up_max $up_max_size<br>";
echo "Maximum Post Size = $post_max $post_max_size <br>";
echo "Maximum Input Time = $input_max minute/s<br>";
echo "Memory Limit = $mem_limit $mem_limit_size<br>";
echo "Maximum Execution Time = $exec_time minute/s<br>";
?>

PHP Host Settings Without phpinfo() Read More »