Archive for July, 2010

nicEdit Firefox center and right align bug patch.

July 28th, 2010 2 comments

If you are using nicEdit on content editable areas instead of the iFrame method, then you may have run across the FireFox bug that prevents you from changing the text alignment on the first line of a content editable element. 

As a work around, change the nicCommand method in nicEdit.js (Line 610 or so), to the below. This code catches the error that firefox throws, inserts a temporary div immediately before the selection, repeats the call that failed (the bug only causes the alignment to fail when it is the very first element in the content editable), and then removes the temporary div.

nicCommand : function(cmd, args) {
        if ((cmd == 'justifyright') || (cmd == 'justifyleft') || (cmd ==
        'justifycenter') || (cmd == 'justifyfull')) {
              try {
                 document.execCommand(cmd, false, null);
              catch (e) {
                 //special case for Mozilla Bug #442186
                 if (e && e.result == 2147500037) {
                    //probably firefox bug 442186 - workaround
                    var range = window.getSelection().getRangeAt(0);
                    var dummy = document.createElement('div');

                     //To restore the range after collapsing for triple click bug...
                     var restoreSelection = false;                     

                    //find node with contentEditable

                    //Triple Click selection Problem in mozilla, the selection contains the content editable div, which creates a problem for some reason, so we collapse the selection to the end, and then re-select everything...
                    if(range.startContainer.contentEditable == 'true'){
                        restoreSelection = true;

                    var ceNode = window.getSelection().getRangeAt(0).startContainer;

                    while (ceNode && ceNode.contentEditable != 'true')
                       ceNode = ceNode.parentNode;

                    if (!ceNode) throw 'Selected node is not editable!';

                    ceNode.insertBefore(dummy, ceNode.childNodes[0]);                    
                    document.execCommand(cmd, false, null);

                     //RestoreSelection if we changed it...
                 } else if (console && console.log) console.log(e);
           } else {
              document.execCommand(cmd, false, args);

Things I Learned Today

July 22nd, 2010 No comments

Uniserver on Windows REQUIRES the .htaccess file to have the “Options +ExecCGI +FollowSymLinks” line in it… Or else you get a 403 forbidden on every page you try to access.

Categories: php5, web Tags:

Facebook Profile Tab Application (FBML)

July 17th, 2010 No comments

To Start with, setup your application with these instructions: (Insert link here).

Receiving Facebook Posts

You FBML application will receive information from Facebook in the form of a signed post. To determine if a post from facebook is authentic, there is an algorithm described here.

I have written a class I use that looks like this:


class Joey_Facebook{
	public static function getFacebookParams(){
		if(!isset($_POST['fb_sig'])) throw new Joey_Facebook_Exception("No Facebook Signatore Parameter");
	    $parameters = $_POST;    
	    if(self::authenticatePayloadFromFacebook($parameters, FACEBOOK_APPLICATION_SECRET)){
	    	return $parameters;	
	    	throw new Joey_Facebook_Exception("Parameters Do Not Authenticate!");
	private static function authenticatePayloadFromFacebook($parameters, $application_secret){
	    $payload = '';
		foreach ($parameters as $key => $value) {
	        if ($key != 'fb_sig') {
	            $payload .= substr($key, 7) . '=' . $value;
	    if (md5($payload . $application_secret) == $parameters['fb_sig']) {
	    	return true;	      
	    	return false;

class Joey_Facebook_Exception extends Exception{
	public $msg;
	public function __construct($msg){
		$this->msg = $msg;		

Once you have authenticated the request, you can now use the data in it. The important data (to me) is…

When a user has granted your appliation basic permissions, the $_POST[‘fb_sig_user’] is the facebook users id. Your application can use this to store and retrieve database records, display customized content, etc…

If your application is viewed via a profile tab, the profile owner’s fbid is in $_POST[‘fb_sig_profile_id’].

With these two basic pieces of information you can essentialy embed basic web applications into Facebook. You can gather much more information from the post, and also use Facebook’s API (btw… It does need to be de-mistified…) to gather more information about the user and add more social features to your application.

Getting a user to “Add Application”

To redirect the user to the basic add application page, view the details on this page.

Categories: facebook, FBML, Profile Tabs Tags: