diff --git a/ActivityFeed.php b/ActivityFeed.php new file mode 100644 index 0000000..76ef1be --- /dev/null +++ b/ActivityFeed.php @@ -0,0 +1,88 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsBase.php'; + +/** + * The Activity Feed plugin displays the most interesting recent activity + * taking place on your site. + * + * @see http://developers.facebook.com/docs/reference/plugins/activity + */ +class ActivityFeed extends EFaceplugsBase +{ + /** + * The domain to show activity for. Defaults to the current domain. + * @var string + */ + public $site; + /** + * The height of the plugin in pixels. Default height: 300px. + * @var integer + */ + public $height; + /** + * the width of the plugin in pixels. Default width: 300px. + * @var integer + */ + public $width; + /** + * Specifies whether to show the Facebook header. + * @var boolean + */ + public $header; + /** + * The color scheme for the plugin. Options: 'light', 'dark' + * @var string + */ + public $colorscheme; + /** + * The font to display in the plugin. Options: 'arial', 'lucida grande', + * 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana' + * @var string + */ + public $font; + /** + * The border color of the plugin. + * @var string + */ + public $border_color; + /** + * Specifies whether to always show recommendations in the plugin. + * + * If set to true, the plugin will display recommendations in the bottom + * half. + * @var boolean + */ + public $recomendations; + /** + * Allows you to filter which URLs are shown in the plugin. + * + * The plugin will only include URLs which contain the filter in the first + * two path parameters of the URL. If nothing in the first two path + * parameters of the URL matches the filter, the URL will not be included. + * @var string + */ + public $filter; + /** + * A label for tracking referrals; must be less than 50 characters and can + * contain alphanumeric characters and some punctuation (currently +/=-.:_). + * @var string + */ + public $ref; + + public function run() + { + parent::run(); + + $params = $this->getParams(); + echo CHtml::openTag('fb:activity', $params); + echo CHtml::closeTag('fb:activity'); + } + +} diff --git a/Comments.php b/Comments.php new file mode 100644 index 0000000..1cb7fb8 --- /dev/null +++ b/Comments.php @@ -0,0 +1,43 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsBase.php'; + +/** + * The Comments Box easily enables your users to comment on your site's content — + * whether it's for a web page, article, photo, or other piece of content. + * + * @see http://developers.facebook.com/docs/reference/plugins/comments + */ +class Comments extends EFaceplugsBase +{ + /** + * Number of posts to show. + * @var integer + */ + public $numposts; + /** + * the width of the widget. + * @var integer + */ + public $width; + /** + * Specify whether to publish a comment on the user's wall. + * @var boolean + */ + public $publish_feed = true; + + public function run() + { + parent::run(); + + $params = $this->getParams(); + echo CHtml::openTag('fb:comments', $params), CHtml::closeTag('fb:comments'); + } + +} diff --git a/EFaceplugsAppLink.php b/EFaceplugsAppLink.php new file mode 100644 index 0000000..3f6f0b8 --- /dev/null +++ b/EFaceplugsAppLink.php @@ -0,0 +1,24 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsBase.php'; + +/** + * Base class for all plugins which require a Facebook application ID. + */ +abstract class EFaceplugsAppLink extends EFaceplugsBase +{ + public function run() + { + parent::run(); + + if (!isset ($this->app_id) && YII_DEBUG) { + throw new CException('Plugin of type "'. get_class($this) . '" requires the Facebook application ID to be set.'); + } + } +} \ No newline at end of file diff --git a/EFaceplugsBase.php b/EFaceplugsBase.php new file mode 100644 index 0000000..5a5a248 --- /dev/null +++ b/EFaceplugsBase.php @@ -0,0 +1,421 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @version 1.3 + * @author Ianaré Sévi + * @author Gustavo Salomé + */ + +/** + * Base class for all facebook widgets. + * + * Initializes required properties for widgets and sets opengraph properties. + * + * @see http://developers.facebook.com/plugins + * @see http://developers.facebook.com/docs/opengraph + * + */ +abstract class EFaceplugsBase extends CWidget +{ + /** + * Facebook application ID. + * + * This can be set in the 'fbAppId' parameter in the Yii config file. + * @var string + */ + public $app_id; + /** + * Page URL, for Open Graph + * @var string + */ + public $url; + public $css; + /** + * Open Graph properties. + * @var array + */ + public $og = array(); + /** + * Check user's login status. + * @var boolean + */ + public $status = true; + /** + * Enable cookies to allow the server to access the session. + * @var boolean + */ + public $cookie = true; + /** + * Parse XFBML. + * @var boolean + */ + public $xfbml = true; + /** + * Load the Facebook init script asynchronously. + * + * This speeds up page loads because loading the plugin does not block + * loading other elements of the page. + * @var boolean + */ + public $async = true; + /** + * Override default locale for the widget. + * + * Normally locale is set automatically based on the Yii language settings, + * setting it here allows a specific locale to be used. + * @var string + */ + public $locale; + /** + * Specify the debug mode. When active, it loads the debug version of + * the SDK (en_US only). + * + * Options : + * + * @var string + */ + public $debugMode = 'off'; + /** + * URL of the script file to load. + * @var string + */ + protected $scriptFile = 'connect.facebook.net/%%locale%%/all.js'; + /** + * Allowed Open Graph properties. + * @var array + */ + protected $openGraphProperties = array( + 'admins', + 'app_id', + 'title', + 'type', + 'image', + 'url', + 'description', + 'site_name', + 'latitude', + 'longitude', + 'street-address', + 'locality', + 'region', + 'postal-code', + 'country-name', + 'email', + 'phone_number', + 'fax_number', + 'upc', + 'isbn', + 'video', + 'video:height', + 'video:width', + 'video:type', + 'audio', + 'audio:title', + 'audio:artist', + 'audio:album', + 'audio:type', + ); + /** + * Valid Facebook locales. + * @var array + */ + protected $locales = array( + 'az_AZ', + 'be_BY', + 'bg_BG', + 'bn_IN', + 'bs_BA', + 'ca_ES', + 'ck_US', + 'cs_CZ', + 'cy_GB', + 'da_DK', + 'de_DE', + 'eu_ES', + 'en_GB', + 'en_PI', + 'en_UD', + 'en_US', + 'es_LA', + 'es_CL', + 'es_CO', + 'es_ES', + 'es_MX', + 'es_VE', + 'fb_FI', + 'fi_FI', + 'fr_FR', + 'gl_ES', + 'hu_HU', + 'it_IT', + 'ja_JP', + 'ko_KR', + 'nb_NO', + 'nn_NO', + 'nl_NL', + 'pl_PL', + 'pt_BR', + 'pt_PT', + 'ro_RO', + 'ru_RU', + 'sk_SK', + 'sl_SI', + 'sv_SE', + 'th_TH', + 'tr_TR', + 'ku_TR', + 'zh_CN', + 'zh_HK', + 'zh_TW', + 'fb_LT', + 'af_ZA', + 'sq_AL', + 'hy_AM', + 'hr_HR', + 'nl_BE', + 'eo_EO', + 'et_EE', + 'fo_FO', + 'fr_CA', + 'ka_GE', + 'el_GR', + 'gu_IN', + 'hi_IN', + 'is_IS', + 'id_ID', + 'ga_IE', + 'jv_ID', + 'kn_IN', + 'kk_KZ', + 'la_VA', + 'lv_LV', + 'li_NL', + 'lt_LT', + 'mk_MK', + 'mg_MG', + 'ms_MY', + 'mt_MT', + 'mr_IN', + 'mn_MN', + 'ne_NP', + 'pa_IN', + 'rm_CH', + 'sa_IN', + 'sr_RS', + 'so_SO', + 'sw_KE', + 'tl_PH', + 'ta_IN', + 'tt_RU', + 'te_IN', + 'ml_IN', + 'uk_UA', + 'uz_UZ', + 'vi_VN', + 'xh_ZA', + 'zu_ZA', + 'km_KH', + 'tg_TJ', + 'ar_AR', + 'he_IL', + 'ur_PK', + 'fa_IR', + 'sy_SY', + 'yi_DE', + 'gn_PY', + 'qu_PE', + 'ay_BO', + 'se_NO', + 'ps_AF', + 'tl_ST', + ); + + public function init() + { + if (property_exists($this, 'href') && $this->href === null) { + $this->href = $this->url; + } + if (!$this->app_id && isset(Yii::app()->params->fbAppId)) { + $this->app_id = Yii::app()->params->fbAppId; + } + if ($this->url) { + $this->registerOpenGraph('url', $this->url); + } + if ($this->app_id) { + $this->registerOpenGraph('app_id', $this->app_id); + } + + foreach ($this->og as $type => $value) { + $this->registerOpenGraph($type, $value); + } + } + + public function run() + { + //run only once + if (!isset(Yii::app()->params->fbRootSet)) { + if ($this->debugMode === 'auto' && YII_DEBUG === true) { + $this->debugMode = 'on'; + } + if ($this->debugMode === 'on') { + $this->scriptFile = 'static.ak.fbcdn.net/connect/en_US/core.debug.js'; + } + else { + $this->setScriptLocale(); + } + + $protocol = 'http'; + if (isset($_SERVER['HTTPS'])) { + $protocol .= 's'; + } + $this->scriptFile = $protocol . '://' . $this->scriptFile; + + + echo CHtml::openTag('div', array('id' => 'fb-root')); + + $init = $this->registerSDKScript('init', array( + 'status' => $this->status, + 'cookie' => $this->cookie, + 'xfbml' => $this->xfbml, + 'appId' => $this->app_id, + ) + ); + + if ($this->async) { + $init = "window.fbAsyncInit = function(){{$init}}; + (function(){ + var e=document.createElement('script'); + e.async=true; + e.src='{$this->scriptFile}'; + document.getElementById('fb-root').appendChild(e);}());"; + } + else { + Yii::app()->clientScript->registerScriptFile($this->scriptFile, CClientScript::POS_END); + } + Yii::app()->getClientScript()->registerScript('fb-script', $init, CClientScript::POS_END); + echo CHtml::closeTag('div'); + + Yii::app()->params->fbRootSet = true; + } + } + + /** + * Register an opengraph property. + * @param string $property + * @param string $data + */ + public function registerOpenGraph($property, $data) + { + if (!in_array($property, $this->openGraphProperties)) { + throw new CException('Invalid open graph property : ' . $property); + } + $property = 'og:' . $property; + Yii::app()->clientScript->registerMetaTag($data, null, null, array('property' => $property)); + } + + protected function setScriptLocale() + { + if (isset($this->locale)) { + $locale = strtolower($this->locale); + } + else { + $locale = Yii::app()->language; + } + // Adjustments, mainly because facebook doesn't have all countries + // of the same language translated. + $lang = substr($locale, 0, 2); + $adjust = array( + 'de' => 'de_de', + 'nl' => 'nl_nl', + 'ru' => 'ru_ru', + 'ar' => 'ar_ar', // non standard + 'ku' => 'ku_tr', + ); + // single check languages, array above ... + if (isset($adjust[$lang])) { + $locale = $adjust[$lang]; + } + // english + else if ($lang === 'en' && !in_array($locale, array('en_us','en_pi','en_ud'))) { + // closer to US english + if ($locale === 'en_ca') { + $locale = 'en_us'; + } + // closer to UK english + else { + $locale = 'en_gb'; + } + } + // french + else if ($lang === 'fr' && $locale !== 'fr_ca') { + $locale = 'fr_fr'; + } + // spanish + else if ($lang === 'es' && !in_array($locale, array('es_es','es_cl','es_co','es_mx','es_ve'))) { + $locale = 'es_la'; // non standard + } + // portuguese + else if ($lang === 'pt' && $locale !== 'pt_br') { + $locale = 'pt_pt'; + } + $c = explode('_', $locale); + if (!isset($c[1])) { + throw new CException('Locale for Facebook plugins must be in the following format : ll_CC'); + } + $locale = $c[0] . '_' . strtoupper($c[1]); + if (!in_array($locale, $this->locales)) { + throw new CException('Invalid Facebook locale'); + } + $this->scriptFile = str_replace('%%locale%%', $locale, $this->scriptFile); + } + + /** + * Grabs public properties of the class for passing to the plugin creator. + * @return array Associative array + */ + protected function getParams() + { + $ignore = array('skin', 'actionPrefix', 'app_id', 'url', 'status', + 'cookie', 'async', 'debugMode', 'xfbml'); + $ref = new ReflectionObject($this); + $props = $ref->getProperties(ReflectionProperty::IS_PUBLIC); + + $params = array(); + foreach ($props as $k => $v) { + $name = $v->name; + if ($this->$name !== null && !is_array($this->$name) && !in_array($name, $ignore)) { + if (is_bool($this->$name)) { + $value = ($this->$name === true) ? 'true' : 'false'; + } + else { + $value = $this->$name; + } + $params[$name] = $value; + } + } + return $params; + } + + /** + * creates a method of facebook sdk script + * + * @param string $method + * @param array $args args to use in the method + * @return string the js created + */ + public function registerSDKScript($method, $args=array()) + { + $args = CJavaScript::encode($args); + return "FB.{$method}({$args});"; + } + +} diff --git a/Facepile.php b/Facepile.php new file mode 100644 index 0000000..4ea0fdc --- /dev/null +++ b/Facepile.php @@ -0,0 +1,49 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsBase.php'; + +/** + * The Facepile plugin displays the Facebook profile pictures of users who + * have liked your page or have signed up for your site. + * + * @see http://developers.facebook.com/docs/reference/plugins/facepile/ + */ +class Facepile extends EFaceplugsBase +{ + /** + * The URL of the page. + * + * The plugin will display photos of users who have liked this page. + * @var string + */ + public $href; + /** + * The maximum number of rows of faces to display. + * + * Height is dynamically sized; if you specify a maximum of four rows of + * faces, but there are only enough friends to fill two rows, the plugin + * will set its height for two rows of faces. Default: 1. + * @var integer + */ + public $max_rows; + /** + * Width of the plugin in pixels. Default width: 200px. + * @var integer + */ + public $width; + + public function run() + { + parent::run(); + + $params = $this->getParams(); + echo CHtml::openTag('fb:facepile', $params), CHtml::closeTag('fb:facepile'); + } + +} diff --git a/FanBox.php b/FanBox.php new file mode 100644 index 0000000..cafb666 --- /dev/null +++ b/FanBox.php @@ -0,0 +1,73 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsBase.php'; + +/** + * The Like Box is a social plugin that enables Facebook Page owners to + * attract and gain Likes from their own website. + * + * The Like Box enables users to: + * + * + * @see http://developers.facebook.com/docs/reference/plugins/like + */ +class FanBox extends EFaceplugsBase +{ + /** + * The width of the plugin in pixels. Default width: 300px. + * @var integer + */ + public $width; + /** + * The height of the plugin in pixels. + * @var integer + */ + public $height; + /** + * Specifies whether to display a stream of the latest posts from the + * page's wall. + * @var boolean + */ + public $stream; + /** + * Specifies the profile to be a fan of. + * @var string + */ + public $profile_id; + /** + * Specifies whether to display the Facebook logo at the top of the plugin. + * @var boolean + */ + public $logobar; + /** + * Specify the number of connections (faces) to display in the plugin. + * @var integer + */ + public $connections; + /** + * Specify a CSS file to use with the plugin. + * @var string Absolute URL + */ + public $css; + + public function run() + { + parent::run(); + + if (!isset($this->profile_id)) { + $this->profile_id = $this->app_id; + } + $params = $this->getParams(); + echo CHtml::openTag('fb:fan', $params), CHtml::closeTag('fb:fan'); + } +} diff --git a/LikeBox.php b/LikeBox.php new file mode 100644 index 0000000..3b11877 --- /dev/null +++ b/LikeBox.php @@ -0,0 +1,78 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsBase.php'; + +/** + * The Like Box is a social plugin that enables Facebook Page owners to + * attract and gain Likes from their own website. + * + * The Like Box enables users to: + * + * + * @see http://developers.facebook.com/docs/reference/plugins/like + */ +class LikeBox extends EFaceplugsBase +{ + /** + * The URL of the Facebook page for this Like Box. + * @var string + */ + public $href; + /** + * Display profile photos in the plugin. + * @var boolean + */ + public $show_faces; + /** + * The width of the plugin in pixels. Default width: 300px. + * @var integer + */ + public $width; + /** + * The height of the plugin in pixels. + * @var integer + */ + public $height; + /** + * Specifies whether to display a stream of the latest posts from the + * page's wall. + * @var boolean + */ + public $stream; + /** + * Specifies whether to display the Facebook header at the top of the plugin. + * @var boolean + */ + public $header; + /** + * The color scheme for the plugin. Options: 'light', 'dark' + * @var string + */ + public $colorscheme; + /** + * Specifies the profile to like. + * @var string + */ + public $profile_id; + + public function run() + { + parent::run(); + + if (!isset($this->profile_id)) { + $this->profile_id = $this->app_id; + } + $params = $this->getParams(); + echo CHtml::openTag('fb:like-box', $params), CHtml::closeTag('fb:like-box'); + } +} diff --git a/LikeButton.php b/LikeButton.php new file mode 100644 index 0000000..aae11dc --- /dev/null +++ b/LikeButton.php @@ -0,0 +1,71 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsBase.php'; + +/** + * The Like button lets a user share your content with friends on Facebook. + * + * When the user clicks the Like button on your site, a story appears in the + * user's friends' News Feed with a link back to your website. + * + * @see http://developers.facebook.com/docs/reference/plugins/like + */ +class LikeButton extends EFaceplugsBase +{ + /** + * The URL of the Facebook page for this Like button. + * @var string + */ + public $href; + /** + * Display profile photos below the button (standard layout only) + * @var boolean + */ + public $show_faces; + /** + * Width of the Like button, defults to 450px + * @var integer + */ + public $width; + /** + * Three options : 'standard', 'button_count', 'box_count' + * @var string + */ + public $layout; + /** + * The verb to display on the button. Options: 'like', 'recommend' + * @var string + */ + public $action; + /** + * The font to display in the button. Options: 'arial', 'lucida grande', + * 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana' + * @var string + */ + public $font; + /** + * The color scheme for the plugin. Options: 'light', 'dark' + * @var string + */ + public $colorscheme; + /** + * A label for tracking referrals; must be less than 50 characters and can + * contain alphanumeric characters and some punctuation (currently +/=-.:_). + * @var string + */ + public $ref; + + public function run() + { + parent::run(); + + $params = $this->getParams(); + echo CHtml::openTag('fb:like', $params), CHtml::closeTag('fb:like'); + } +} diff --git a/LiveStream.php b/LiveStream.php new file mode 100644 index 0000000..8ef9fa1 --- /dev/null +++ b/LiveStream.php @@ -0,0 +1,50 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsAppLink.php'; + +/** + * The Live Stream plugin lets your users share activity and comments in + * real-time as they interact during a live event. + * + * @see http://developers.facebook.com/docs/reference/plugins/live-stream + */ +class LiveStream extends EFaceplugsAppLink +{ + /** + * Width of the plugin in pixels. Default width: 400px. + * @var integer + */ + public $width; + /** + * The height of the plugin in pixels. Default height: 500px. + * @var integer + */ + public $height; + /** + * The URL that users are redirected to when they click on your app name on + * a status (if not specified, your Connect URL is used). + * @var string + */ + public $via_url; + /** + * If you have multiple live stream boxes on the same page, specify a + * unique xid for each. + * @var integer + */ + public $xid; + + public function run() + { + parent::run(); + + $params = $this->getParams(); + echo CHtml::openTag('fb:live-stream', $params), CHtml::closeTag('fb:live-stream'); + } + +} \ No newline at end of file diff --git a/LoginButton.php b/LoginButton.php new file mode 100644 index 0000000..064186e --- /dev/null +++ b/LoginButton.php @@ -0,0 +1,58 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsAppLink.php'; + +/** + * The Login Button shows profile pictures of the user's friends who have + * already signed up for your site in addition to a login button. + * + * @see http://developers.facebook.com/docs/reference/plugins/login + */ +class LoginButton extends EFaceplugsAppLink +{ + /** + * The URL of the page. + * + * The plugin will display photos of users who have liked this page. + * @var string + */ + public $show_faces; + /** + * The maximum number of rows of profile pictures to display. + * Default value: 1. + * @var integer + */ + public $max_rows; + /** + * The width of the plugin in pixels. Default width: 200px. + * @var integer + */ + public $width; + /** + * A comma separated list of extended permissions. + * + * By default the Login button prompts users for their public information. + * If your application needs to access other parts of the user's profile + * that may be private, your application can request extended permissions. + * + * @see http://developers.facebook.com/docs/authentication/permissions/ + * @var string + */ + public $perms; + + public function run() + { + parent::run(); + + $params = $this->getParams(); + echo CHtml::openTag('fb:login-button', $params), CHtml::closeTag('fb:login-button'); + } + +} diff --git a/Recommendations.php b/Recommendations.php new file mode 100644 index 0000000..f51f3ec --- /dev/null +++ b/Recommendations.php @@ -0,0 +1,78 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsBase.php'; + +/** + * The Recommendations plugin shows personalized recommendations to your users. + * + * @see http://developers.facebook.com/docs/reference/plugins/recommendations + */ +class Recommendations extends EFaceplugsBase +{ + /** + * The domain to show activity for. Defaults to the current domain. + * @var string + */ + public $site; + /** + * The height of the plugin in pixels. Default height: 300px. + * @var integer + */ + public $height; + /** + * the width of the plugin in pixels. Default width: 300px. + * @var integer + */ + public $width; + /** + * Specifies whether to show the Facebook header. + * @var boolean + */ + public $header; + /** + * The color scheme for the plugin. Options: 'light', 'dark' + * @var string + */ + public $colorscheme; + /** + * The font to display in the plugin. Options: 'arial', 'lucida grande', + * 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana' + * @var string + */ + public $font; + /** + * The border color of the plugin. + * @var string + */ + public $border_color; + /** + * Allows you to filter which URLs are shown in the plugin. + * + * The plugin will only include URLs which contain the filter in the first + * two path parameters of the URL. If nothing in the first two path + * parameters of the URL matches the filter, the URL will not be included. + * @var string + */ + public $filter; + /** + * A label for tracking referrals; must be less than 50 characters and can + * contain alphanumeric characters and some punctuation (currently +/=-.:_). + * @var string + */ + public $ref; + + public function run() + { + parent::run(); + + $params = $this->getParams(); + echo CHtml::openTag('fb:recommendations', $params), CHtml::closeTag('fb:recommendations'); + } + +} diff --git a/Registration.php b/Registration.php new file mode 100644 index 0000000..c73c690 --- /dev/null +++ b/Registration.php @@ -0,0 +1,64 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +require_once 'EFaceplugsAppLink.php'; + +/** + * The registration plugin allows users to easily sign up for your website with + * their Facebook account. + * + * @see http://developers.facebook.com/docs/plugins/registration + */ +class Registration extends EFaceplugsAppLink +{ + /** + * If the user arrives logged into Facebook, but has not registered for + * your site, the button will say Register and clicking it will take the + * user to your registration-url. + * @var string + */ + public $registration_url; + /** + * The URI that will process the signed_request. It must be prefixed by + * your Site URL. + * @var string + */ + public $redirect_uri; + /** + * Comma separated list of Named Fields, or JSON of Custom Fields. + * @var string + */ + public $fields; + /** + * Only allow users to register by linking their Facebook profile. + * + * Use this if you do not have your own registration system. Default: false. + * @var boolean + */ + public $fb_only; + /** + * The width in pixels. If the width is < 520 the plugin will + * render in a small layout. + * @var integer + */ + public $width; + /** + * + * @var integer + */ + public $client_id; + + public function run() + { + parent::run(); + $this->client_id = $this->app_id; + $params = $this->getParams(); + echo CHtml::openTag('fb:registration', $params), CHtml::closeTag('fb:registration'); + } + +} diff --git a/RegistrationParser.php b/RegistrationParser.php new file mode 100644 index 0000000..350cb0e --- /dev/null +++ b/RegistrationParser.php @@ -0,0 +1,78 @@ + 2011 + * @license GNU Lesser General Public License v3.0 + * @author Ianaré Sévi + */ + +/** + * The registration parser is used to convert the JSON response from Facebook + * into a format easily inserted into Yii applications. + * + * THIS IS UNFINISHED, UNTESTED CODE !! + * + * !!!! DO NOT USE !!!! + */ +class RegistrationParser extends CComponent +{ + public $data; + public $app_id; + public $app_secret; + public $mapper; + + protected $testData = '{ + "oauth_token": "...big long string...", + "algorithm": "HMAC-SHA256", + "expires": 1291840400, + "issued_at": 1291836800, + "registration": { + "name": "Paul Tarjan", + "email": "fb@paulisageek.com", + "location": { + "name": "San Francisco, California", + "id": 114952118516947 + }, + "gender": "male", + "birthday": "12/16/1985", + "like": true, + "phone": "555-123-4567", + "anniversary": "2/14/1998", + "captain": "K", + "force": "jedi", + "live": { + "name": "Denver, Colorado", + "id": 115590505119035 + } + }, + "user_id": "218471" + }'; + + /** + * change the facebook response to an objet + * @return Object $response + */ + public function parse_signed_request() + { + $data = json_decode($this->testData); + if (strtoupper($data->algorithm) !== 'HMAC-SHA256') { + if (YII_DEBUG) { + throw new CException('Unknown algorithm : "'. $data->algorithm .'" . Expected HMAC-SHA256'); + } + return null; + } + return $data->registration; + } + + /** + * + * @param $input + * @return string + */ + protected function base64UrlDecode($input) + { + return base64_decode(strtr($input, '-_', '+/')); + } + +} \ No newline at end of file