nicEdit Firefox center and right align bug patch.

July 28th, 2010 No 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 be this:

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;
                    dummy.style.height="1px;";

                    //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'){
                        window.getSelection().collapseToEnd();
                        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);
                    dummy.parentNode.removeChild(dummy);

                     //RestoreSelection if we changed it...
                     if(restoreSelection){
                        window.getSelection().addRange(range);
                     }
                 } 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:

require_once('config.php');

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;
	    }
	    else{
	    	throw new Joey_Facebook_Exception("Parameters Do Not Authenticate!");
	    }
	}

	private static function authenticatePayloadFromFacebook($parameters, $application_secret){
		ksort($parameters);
	    $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;
	    }
	    else{
	    	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: FBML, Profile Tabs, facebook Tags:

oEmbed – Easily get the information you need to embed content from viddler, flickr, hooloo, etc… in your pages.

June 9th, 2010 No comments

oEmbed is an open standard that allows you to pass a url to an oEmbed provider and get back information about that resource.

i.e. Pass a hulu url to hulu’s oEmbed service: http://www.hulu.com/api/oembed.xml?url=http%3A//www.hulu.com/watch/20807/late-night-with-conan-obrien-wed-may-21-2008  and you’ll get back a json object with details of the video (thumbnail size and url, etc..) and on some oembed services the html needed to embed the video.

For more information, check out this page: http://www.oembed.com/

Categories: Uncategorized Tags:

Facebook f8 announces new Easy to use API

April 29th, 2010 No comments

If you are a serious web developer that wants to ride the wave into the next decade, you MUST integrate with Social Networking / Media in your apps. Fortunatly, facebook just released a new API that is a piece of cake to use. WAY WAY WAY easier than their old one.

Check out the video about it’s features here: (The best stuff is half way through the video)

http://www.facebook.com/f8

Categories: Social Media, facebook Tags:

phpMiniAdmin

April 27th, 2010 No comments

I’ve used phpMyAdmin for a while, but I find it to be a little heavyweight at times. Sometimes I just want to run a simple query. The MySQL client is obtuse to use sometimes. So I went on a search for alternatives.

I now use phpMiniAdmin almost exclusively. It’s extremely light weight, fast and has LOTS of neat features. It provides everything I need 99.9% of the time. And it’s easier to configure then phpMyAdmin.

Categories: mysql, php5, web Tags:

Google Atmosphere Talk – Mobile Internet

April 26th, 2010 No comments

I watched this talk on You Tube by Mary Meeker who is the Managing Director for Morgan Stanley (A Big Wall Street Company, A Good One). It is extremely informative and filled with facts.

httpv://www.youtube.com/eventsatgoogle#p/u/8/X1w1FvgdZnE

Categories: web Tags:

HTML 5 Freature Overview Presentation With Sample Code

April 23rd, 2010 No comments

At work Shawn Lonas sent this out to all of us, it’s a really good concise overview of some html5 features.

http://apirocks.com/html5/html5.html

Categories: Uncategorized, html, html5 Tags: , ,

Magento – WOW!

January 19th, 2010 No comments

Some say that Magento is horrible to work with. I say they are wrong. Magento is one of the most well designed pieces of software I’ve ever seen. Complete inversion of control. Awesome extendability. Sweet seperation of concerns. Proper use of classes, it’s all there.

But… It’s under documented, and it has a few core concepts you have to understand before it makes sense.

Recently I need to make a new shipping method for myhomefurniturestore.com. Fortunatly for me, magentomagick had a great article that had instructions start to finish (except for two details that are mentioned in the comments) for just such a task.

Categories: php5 Tags:

Get more pageviews! How to add a “Post to Facebook” button to your site!

January 10th, 2010 No comments

This is so so easy… Every site on the web should have one of these…

All you have to do, is paste the code from here: http://www.facebook.com/facebook-widgets/share.php

Onto your site…

See: Share with my friends.

Categories: Social Media, facebook Tags: