KEMBAR78
Facebook Development with Zend Framework | PPT
Facebook Development using Zend Framework Brett Harris
Make it work. Make it right. Make it fast. Make it fast. Make it fast.
Challenges Development Environments & Deployment Differences from “Normal” web Learning Curve
Development Environment  & Deployment & Deployment Publicly accessible development environments FBML Parser Proxy Configuration makes life easy
3-Tier Architecture
5-Tier Architecture
Development Environment Webserver must be publicly accessible Must register FB application to use API Facebook must parse FBML to see UI
Proxy Pattern http://en.wikipedia.org/wiki/Proxy_pattern
Dev Environment Proxy
FBML Parser <html> ... <h1> <fb:profile-pic uid=&quot;12345&quot; size=&quot;thumb&quot; /> <fb:name uid=&quot;12345&quot; /> </h1> <hr/> <p> <fb:user-status uid=&quot;12345&quot; linked=&quot;false&quot;/> </p> ... </html>
FBML Parser Parsed by Facebook Not parsed Brett Harris is presenting at ZendCon
FBML Parser Proxy function  smarty_function_fb_name( $params , & $smarty ) { if  (Framework_Config::get( 'MODE')  ==  'local' ) { return   'Grant Raphael' ; } $fbml =  '<fb:name ' ; foreach  ( $params   as   $key  =>  $value ) { $fbml .=  $key  .  '=&quot;'  . addslashes( $value ) .  '&quot;' ; } $fbml .=  ' />' ; return   $fbml ; } http://smarty.net/manual/en/plugins.php
FBML Parsing Mock <html> ... <h1> {fb_profile_pic uid=&quot;12345&quot; size=&quot;thumb&quot; } {fb_name uid=&quot;12345&quot; } </h1> <hr/> <p> {fb_user_status uid=&quot;12345&quot; linked=&quot;false&quot; } </p> ... </html>
FBML Parsing Mock Grant Raphael is updating their status Parsed by Facebook Not parsed Brett Harris is speaking at ZendCon
Configuration Ease deployment Manage mocks [environments] dev_foo_com  = DEV www_foo_com  = LIVE [DEV] APP_NAME  = sample_application BASE_DIR  = /var/www/html/sample ETC_DIR  = /var/www/html/sample/FBFramework/application/etc MODEL_DIR  = /var/www/html/sample/FBFramework/application/model CONTROLLER_DIR  = /var/www/html/sample/FBFramework/application/controller VIEW_DIR  = /var/www/html/sample/FBFramework/application/public/view COMPILE_DIR  = /tmp/templates_c SESSION_DIR  = /tmp/sessions FRAMEWORK_DIR  = /var/www/html/sample/FBFramework/Framework UI_DIR  = /var/www/html/sample/FBFramework/Framework/UI DEFAULT_CONTROLLER  = index DEFAULT_ACTION  = index VIEW_EXTENSION  = tpl BASE_URL  =  http://dev.foo.com/sample EXTERNAL_URL  =  http://dev.foo.com/sample MODE  = local [facebook] FB_USER_ID  = 1 FB_FRIENDS  = 1,2,3,4,5 API_KEY  = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX SECRET_KEY  = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX SESSION_KEY  = XXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXX
Differences from “Normal” Web POST Header redirects
POST Can’t post files due to 5-tiers File makes it to FB, but is not passed along
POST Post to your server, then redirect < html > ... <!--  http://dev.foo.com/sample/item/save  --> < form  method = &quot;post&quot;  action = &quot;{$EXTERNAL_URL}/item/save&quot; >  ... </ form > ... </ html > <?php class  ItemController  extends  Zend_Controller_Action { public   function  saveAction() { $item      =  new  Item((int) $this ->_request->getParam( 'id' )); $item ->name   = (string) $this ->_request->getParam( 'name' ); $item ->save(); /*  http://apps.facebook.com/sample/items  */ $this ->_redirect(Framework_Config::get( 'BASE_URL' ) .  '/items' );  } } ?> [environments] dev_foo_com  = DEV [DEV] ... BASE_URL  =  http://apps.facebook.com/sample EXTERNAL_URL  =  http://dev.foo.com/sample
Header Redirects Can’t redirect due to 5-tier
Header Redirects Use _forwarding <?php class  ItemController  extends  Zend_Controller_Action { public   function  listAction() { try { $category_id = (int) $this ->_request->getParam( 'category_id' ); $this ->view->items = Item::find( 'category_id = ?' ,  $category_id ); } catch  (Exception  $e ) { // Forward to ErrorController::indexAction // aka http://www.foo.com/error/index $this ->_forward( 'index', 'error' );  } } } ?>
Learning Curve FQL FBML etc
FQL Consider it SQL Accessed via web service Requires valid FB session
ActiveRecord http://en.wikipedia.org/wiki/Active_record_pattern
Easier to learn <?php ... // Get the user object from FQL table $fb_user      =  new  Facebook_User( 12345 ); // Get the user's items from local SQL table $items  = Items::find( 'fb_user_id = ?' ,  $fb_user ->uid); ... ?> <?php ... // Get the user object from FQL table $fb_lib =  new  Facebook(API_KEY, SECRET_KEY); $fb_client =  $fb_lib ->api_client; $results =  $fb_client ->fql_query( 'SELECT uid, first_name, last_name, ... FROM user WHERE uid = &quot;12345&quot;' ); $fb_user_array = array_pop( $results ); // Get the user's items from local SQL table $items = Items::find( 'fb_user_id = ?' ,  $fb_user [ 'uid' ]); ... ?>
Don’t build CRUD for FQL or for SQL <?php ... // Get the user object from FQL table $fb_user =  new  Facebook_User( 12345 ); // Get an item from local SQL table $item =  new  Item( 1 ); // Bind item to the user's items in local SQL table $item_bind =  new  Item_Bind(); $item_bind ->fb_uid =  $fb_user ->uid; $item_bind ->item_id =  $item ->id; $item_bind ->save(); ... ?>
FBML Inject FB data without using FQL HTML-like Tag library Core to FB development http://wiki.developers.facebook.com/index.php/FBML
FBML Proxy <html> ... <h1> {fb_profile_pic uid=&quot;12345&quot; size=&quot;thumb&quot; } {fb_name uid=&quot;12345&quot; } </h1> <hr/> <p> {fb_user_status uid=&quot;12345&quot; linked=&quot;false&quot; } </p> ... </html>
UI Components Wrapping AJAX Libraries Multi-application interfaces Why stop with FBML?
UI Components < html > ... {Grid recordset=$recordset} {Column header=&quot;ID&quot; field=&quot;id&quot;} {Column header=&quot;Name&quot; field=&quot;name&quot;} {ColumnComplex header=&quot;Email&quot;} < a  href = &quot;mailto:{$record.email}&quot; > {$record.email} </ a > {/ColumnComplex} {/Grid} ... </ html > Make a grid - 3 columns (ID, Name, Email) - Loop through items in $recordset for rows < html > ... < table > < tr > < th > ID </ th > < th > Name </ th > < th > Email </ th > </ tr > <?php   foreach  ( $recordset   as   $record ) {  ?> < tr > < td > <? =  $record ->id  ?> </ td > < td > <? =  $record ->name  ?> </ td > < td > < a  href =&quot; mailto: <? =  $record ->email  ?> &quot; > <? =  $record ->email  ?> </ a > </ td > </ tr > <?php  }  ?> </ table > ... </ html > ID Name Email 1 John Doe [email_address] 2 Steve Smith [email_address]
Wrapping AJAX Libraries < html > ... < input  id = &quot;mb1&quot;  type = &quot;button&quot;  value = &quot;Show Popup&quot;  /> < script > Ext.onReady( function () { Ext.get( 'mb1' ).on( 'click' ,  function (e) { Ext.MessageBox.confirm( 'Confirm' ,  'Are you sure you want to do that?' , showResult); } ); </ script > ... </ html > < html > ... {PopupButton value=&quot;Show Popup&quot; header=&quot;Confirm&quot; message=&quot;Are you sure you want to do that?&quot; callback=&quot;showResult&quot;} ... </ html > http://extjs.com /
Multi-application interfaces http://zynga.com /
Make it work. Make it right. Make it fast. Make it fast. Make it fast.
Make a framework. Make it right. Make it fast. Make it fast. Make it fast.
Make a framework. Make it right. Use a framework. Use a framework. Use a framework.
Make a framework. Make great FB apps. Use a framework. Use a framework. Use a framework.
Shameless Plug fbframework.googlecode.com

Facebook Development with Zend Framework

  • 1.
    Facebook Development usingZend Framework Brett Harris
  • 2.
    Make it work.Make it right. Make it fast. Make it fast. Make it fast.
  • 3.
    Challenges Development Environments& Deployment Differences from “Normal” web Learning Curve
  • 4.
    Development Environment & Deployment & Deployment Publicly accessible development environments FBML Parser Proxy Configuration makes life easy
  • 5.
  • 6.
  • 7.
    Development Environment Webservermust be publicly accessible Must register FB application to use API Facebook must parse FBML to see UI
  • 8.
  • 9.
  • 10.
    FBML Parser <html>... <h1> <fb:profile-pic uid=&quot;12345&quot; size=&quot;thumb&quot; /> <fb:name uid=&quot;12345&quot; /> </h1> <hr/> <p> <fb:user-status uid=&quot;12345&quot; linked=&quot;false&quot;/> </p> ... </html>
  • 11.
    FBML Parser Parsedby Facebook Not parsed Brett Harris is presenting at ZendCon
  • 12.
    FBML Parser Proxyfunction smarty_function_fb_name( $params , & $smarty ) { if (Framework_Config::get( 'MODE') == 'local' ) { return 'Grant Raphael' ; } $fbml = '<fb:name ' ; foreach ( $params as $key => $value ) { $fbml .= $key . '=&quot;' . addslashes( $value ) . '&quot;' ; } $fbml .= ' />' ; return $fbml ; } http://smarty.net/manual/en/plugins.php
  • 13.
    FBML Parsing Mock<html> ... <h1> {fb_profile_pic uid=&quot;12345&quot; size=&quot;thumb&quot; } {fb_name uid=&quot;12345&quot; } </h1> <hr/> <p> {fb_user_status uid=&quot;12345&quot; linked=&quot;false&quot; } </p> ... </html>
  • 14.
    FBML Parsing MockGrant Raphael is updating their status Parsed by Facebook Not parsed Brett Harris is speaking at ZendCon
  • 15.
    Configuration Ease deploymentManage mocks [environments] dev_foo_com = DEV www_foo_com = LIVE [DEV] APP_NAME = sample_application BASE_DIR = /var/www/html/sample ETC_DIR = /var/www/html/sample/FBFramework/application/etc MODEL_DIR = /var/www/html/sample/FBFramework/application/model CONTROLLER_DIR = /var/www/html/sample/FBFramework/application/controller VIEW_DIR = /var/www/html/sample/FBFramework/application/public/view COMPILE_DIR = /tmp/templates_c SESSION_DIR = /tmp/sessions FRAMEWORK_DIR = /var/www/html/sample/FBFramework/Framework UI_DIR = /var/www/html/sample/FBFramework/Framework/UI DEFAULT_CONTROLLER = index DEFAULT_ACTION = index VIEW_EXTENSION = tpl BASE_URL = http://dev.foo.com/sample EXTERNAL_URL = http://dev.foo.com/sample MODE = local [facebook] FB_USER_ID = 1 FB_FRIENDS = 1,2,3,4,5 API_KEY = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX SECRET_KEY = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX SESSION_KEY = XXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXX
  • 16.
    Differences from “Normal”Web POST Header redirects
  • 17.
    POST Can’t postfiles due to 5-tiers File makes it to FB, but is not passed along
  • 18.
    POST Post toyour server, then redirect < html > ... <!-- http://dev.foo.com/sample/item/save --> < form method = &quot;post&quot; action = &quot;{$EXTERNAL_URL}/item/save&quot; > ... </ form > ... </ html > <?php class ItemController extends Zend_Controller_Action { public function saveAction() { $item = new Item((int) $this ->_request->getParam( 'id' )); $item ->name = (string) $this ->_request->getParam( 'name' ); $item ->save(); /* http://apps.facebook.com/sample/items */ $this ->_redirect(Framework_Config::get( 'BASE_URL' ) . '/items' ); } } ?> [environments] dev_foo_com = DEV [DEV] ... BASE_URL = http://apps.facebook.com/sample EXTERNAL_URL = http://dev.foo.com/sample
  • 19.
    Header Redirects Can’tredirect due to 5-tier
  • 20.
    Header Redirects Use_forwarding <?php class ItemController extends Zend_Controller_Action { public function listAction() { try { $category_id = (int) $this ->_request->getParam( 'category_id' ); $this ->view->items = Item::find( 'category_id = ?' , $category_id ); } catch (Exception $e ) { // Forward to ErrorController::indexAction // aka http://www.foo.com/error/index $this ->_forward( 'index', 'error' ); } } } ?>
  • 21.
  • 22.
    FQL Consider itSQL Accessed via web service Requires valid FB session
  • 23.
  • 24.
    Easier to learn<?php ... // Get the user object from FQL table $fb_user = new Facebook_User( 12345 ); // Get the user's items from local SQL table $items = Items::find( 'fb_user_id = ?' , $fb_user ->uid); ... ?> <?php ... // Get the user object from FQL table $fb_lib = new Facebook(API_KEY, SECRET_KEY); $fb_client = $fb_lib ->api_client; $results = $fb_client ->fql_query( 'SELECT uid, first_name, last_name, ... FROM user WHERE uid = &quot;12345&quot;' ); $fb_user_array = array_pop( $results ); // Get the user's items from local SQL table $items = Items::find( 'fb_user_id = ?' , $fb_user [ 'uid' ]); ... ?>
  • 25.
    Don’t build CRUDfor FQL or for SQL <?php ... // Get the user object from FQL table $fb_user = new Facebook_User( 12345 ); // Get an item from local SQL table $item = new Item( 1 ); // Bind item to the user's items in local SQL table $item_bind = new Item_Bind(); $item_bind ->fb_uid = $fb_user ->uid; $item_bind ->item_id = $item ->id; $item_bind ->save(); ... ?>
  • 26.
    FBML Inject FBdata without using FQL HTML-like Tag library Core to FB development http://wiki.developers.facebook.com/index.php/FBML
  • 27.
    FBML Proxy <html>... <h1> {fb_profile_pic uid=&quot;12345&quot; size=&quot;thumb&quot; } {fb_name uid=&quot;12345&quot; } </h1> <hr/> <p> {fb_user_status uid=&quot;12345&quot; linked=&quot;false&quot; } </p> ... </html>
  • 28.
    UI Components WrappingAJAX Libraries Multi-application interfaces Why stop with FBML?
  • 29.
    UI Components <html > ... {Grid recordset=$recordset} {Column header=&quot;ID&quot; field=&quot;id&quot;} {Column header=&quot;Name&quot; field=&quot;name&quot;} {ColumnComplex header=&quot;Email&quot;} < a href = &quot;mailto:{$record.email}&quot; > {$record.email} </ a > {/ColumnComplex} {/Grid} ... </ html > Make a grid - 3 columns (ID, Name, Email) - Loop through items in $recordset for rows < html > ... < table > < tr > < th > ID </ th > < th > Name </ th > < th > Email </ th > </ tr > <?php foreach ( $recordset as $record ) { ?> < tr > < td > <? = $record ->id ?> </ td > < td > <? = $record ->name ?> </ td > < td > < a href =&quot; mailto: <? = $record ->email ?> &quot; > <? = $record ->email ?> </ a > </ td > </ tr > <?php } ?> </ table > ... </ html > ID Name Email 1 John Doe [email_address] 2 Steve Smith [email_address]
  • 30.
    Wrapping AJAX Libraries< html > ... < input id = &quot;mb1&quot; type = &quot;button&quot; value = &quot;Show Popup&quot; /> < script > Ext.onReady( function () { Ext.get( 'mb1' ).on( 'click' , function (e) { Ext.MessageBox.confirm( 'Confirm' , 'Are you sure you want to do that?' , showResult); } ); </ script > ... </ html > < html > ... {PopupButton value=&quot;Show Popup&quot; header=&quot;Confirm&quot; message=&quot;Are you sure you want to do that?&quot; callback=&quot;showResult&quot;} ... </ html > http://extjs.com /
  • 31.
  • 32.
    Make it work.Make it right. Make it fast. Make it fast. Make it fast.
  • 33.
    Make a framework.Make it right. Make it fast. Make it fast. Make it fast.
  • 34.
    Make a framework.Make it right. Use a framework. Use a framework. Use a framework.
  • 35.
    Make a framework.Make great FB apps. Use a framework. Use a framework. Use a framework.
  • 36.