From 1241e651ae54adfc429aceb92a2bc873f1c82f8d Mon Sep 17 00:00:00 2001 From: Trever Fischer Date: Thu, 15 Oct 2009 05:16:37 -0400 Subject: [PATCH 01/13] Added support for profile designs to the twitter API --- classes/Profile.php | 5 +++++ lib/api.php | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/classes/Profile.php b/classes/Profile.php index 4a069ee84e..a78a27f4a2 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -46,6 +46,11 @@ class Profile extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + function getUser() + { + return User::staticGet('id', $this->id); + } + function getAvatar($width, $height=null) { if (is_null($height)) { diff --git a/lib/api.php b/lib/api.php index 7a63a4a785..9bd2083deb 100644 --- a/lib/api.php +++ b/lib/api.php @@ -134,11 +134,19 @@ class ApiAction extends Action $twitter_user['protected'] = false; # not supported by StatusNet yet $twitter_user['followers_count'] = $profile->subscriberCount(); - // To be supported soon... - $twitter_user['profile_background_color'] = ''; - $twitter_user['profile_text_color'] = ''; - $twitter_user['profile_link_color'] = ''; - $twitter_user['profile_sidebar_fill_color'] = ''; + // Need to pull up the user for some of this + $user = $profile->getUser(); + $design = $user->getDesign(); + $defaultDesign = Design::siteDesign(); + if (!$design) $design = $defaultDesign; + $color = Design::toWebColor(empty($design->backgroundcolor) ? $defaultDesign->backgroundcolor : $design->backgroundcolor); + $twitter_user['profile_background_color'] = ($color == null) ? '' : '#'.$color->hexValue(); + $color = Design::toWebColor(empty($design->textcolor) ? $defaultDesign->textcolor : $design->textcolor); + $twitter_user['profile_text_color'] = ($color == null) ? '' : '#'.$color->hexValue(); + $color = Design::toWebColor(empty($design->linkcolor) ? $defaultDesign->linkcolor : $design->linkcolor); + $twitter_user['profile_link_color'] = ($color == null) ? '' : '#'.$color->hexValue(); + $color = Design::toWebColor(empty($design->sidebarcolor) ? $defaultDesign->sidebarcolor : $design->sidebarcolor); + $twitter_user['profile_sidebar_fill_color'] = ($color == null) ? '' : '#'.$color->hexValue(); $twitter_user['profile_sidebar_border_color'] = ''; $twitter_user['friends_count'] = $profile->subscriptionCount(); @@ -147,8 +155,6 @@ class ApiAction extends Action $twitter_user['favourites_count'] = $profile->faveCount(); // British spelling! - // Need to pull up the user for some of this - $user = User::staticGet($profile->id); $timezone = 'UTC'; From 78e5a5980a21c04cfdacb993ca3c37bf65d21783 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 20 Oct 2009 16:32:30 -0700 Subject: [PATCH 02/13] Extract out Facebook app stuff into a plugin --- lib/router.php | 8 - plugins/Facebook/FacebookPlugin.php | 151 ++++++++++++++++++ plugins/Facebook/README | 5 + {lib => plugins/Facebook}/facebookaction.php | 44 ++--- .../Facebook}/facebookhome.php | 6 +- .../Facebook}/facebookinvite.php | 2 +- .../Facebook}/facebooklogin.php | 34 ++-- .../Facebook}/facebookqueuehandler.php | 2 +- .../Facebook}/facebookremove.php | 6 +- .../Facebook}/facebooksettings.php | 24 +-- {lib => plugins/Facebook}/facebookutil.php | 6 +- scripts/getvaliddaemons.php | 1 - 12 files changed, 209 insertions(+), 80 deletions(-) create mode 100644 plugins/Facebook/FacebookPlugin.php create mode 100644 plugins/Facebook/README rename {lib => plugins/Facebook}/facebookaction.php (94%) rename {actions => plugins/Facebook}/facebookhome.php (98%) rename {actions => plugins/Facebook}/facebookinvite.php (98%) rename {actions => plugins/Facebook}/facebooklogin.php (90%) rename {scripts => plugins/Facebook}/facebookqueuehandler.php (96%) rename {actions => plugins/Facebook}/facebookremove.php (93%) rename {actions => plugins/Facebook}/facebooksettings.php (95%) rename {lib => plugins/Facebook}/facebookutil.php (98%) diff --git a/lib/router.php b/lib/router.php index a5b6a9a304..4fb0834fd0 100644 --- a/lib/router.php +++ b/lib/router.php @@ -86,14 +86,6 @@ class Router $m->connect('doc/:title', array('action' => 'doc')); - // facebook - - $m->connect('facebook', array('action' => 'facebookhome')); - $m->connect('facebook/index.php', array('action' => 'facebookhome')); - $m->connect('facebook/settings.php', array('action' => 'facebooksettings')); - $m->connect('facebook/invite.php', array('action' => 'facebookinvite')); - $m->connect('facebook/remove', array('action' => 'facebookremove')); - // main stuff is repetitive $main = array('login', 'logout', 'register', 'subscribe', diff --git a/plugins/Facebook/FacebookPlugin.php b/plugins/Facebook/FacebookPlugin.php new file mode 100644 index 0000000000..127cf96e64 --- /dev/null +++ b/plugins/Facebook/FacebookPlugin.php @@ -0,0 +1,151 @@ +. + * + * @category Plugin + * @package StatusNet + * @author Zach Copley + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Facebook plugin to add a StatusNet Facebook application + * + * @category Plugin + * @package StatusNet + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class FacebookPlugin extends Plugin +{ + + /** + * Add Facebook app actions to the router table + * + * Hook for RouterInitialized event. + * + * @param Net_URL_Mapper &$m path-to-action mapper + * + * @return boolean hook return + */ + + function onRouterInitialized(&$m) + { + $m->connect('facebook', array('action' => 'facebookhome')); + $m->connect('facebook/index.php', array('action' => 'facebookhome')); + $m->connect('facebook/settings.php', array('action' => 'facebooksettings')); + $m->connect('facebook/invite.php', array('action' => 'facebookinvite')); + $m->connect('facebook/remove', array('action' => 'facebookremove')); + + return true; + } + + /** + * Automatically load the actions and libraries used by the Facebook app + * + * @param Class $cls the class + * + * @return boolean hook return + * + */ + function onAutoload($cls) + { + switch ($cls) { + case 'FacebookAction': + case 'FacebookhomeAction': + case 'FacebookinviteAction': + case 'FacebookremoveAction': + case 'FacebooksettingsAction': + include_once INSTALLDIR . '/plugins/Facebook/' . + strtolower(mb_substr($cls, 0, -6)) . '.php'; + return false; + default: + return true; + } + } + + /** + * Add a Facebook queue item for each notice + * + * @param Notice $notice the notice + * @param array &$transports the list of transports (queues) + * + * @return boolean hook return + */ + function onStartEnqueueNotice($notice, &$transports) + { + array_push($transports, 'facebook'); + return true; + } + + /** + * broadcast the message when not using queuehandler + * + * @param Notice &$notice the notice + * @param array $queue destination queue + * + * @return boolean hook return + */ + function onUnqueueHandleNotice(&$notice, $queue) + { + if (($queue == 'facebook') && ($this->_isLocal($notice))) { + facebookBroadcastNotice($notice); + return false; + } + return true; + } + + /** + * Determine whether the notice was locally created + * + * @param Notice $notice + * + * @return boolean locality + */ + function _isLocal($notice) + { + return ($notice->is_local == Notice::LOCAL_PUBLIC || + $notice->is_local == Notice::LOCAL_NONPUBLIC); + } + + /** + * Add Facebook queuehandler to the list of daemons to start + * + * @param array $daemons the list fo daemons to run + * + * @return boolean hook return + * + */ + function onGetValidDaemons($daemons) + { + array_push($daemons, INSTALLDIR . + '/plugins/Facebook/facebookqueuehandler.php'); + return true; + } + +} \ No newline at end of file diff --git a/plugins/Facebook/README b/plugins/Facebook/README new file mode 100644 index 0000000000..a350c5b5b7 --- /dev/null +++ b/plugins/Facebook/README @@ -0,0 +1,5 @@ + + +TODO: + +- Integrate this and the FB Connect plugin \ No newline at end of file diff --git a/lib/facebookaction.php b/plugins/Facebook/facebookaction.php similarity index 94% rename from lib/facebookaction.php rename to plugins/Facebook/facebookaction.php index 3f3a8d3b09..f5ad3d06b4 100644 --- a/lib/facebookaction.php +++ b/plugins/Facebook/facebookaction.php @@ -2,7 +2,7 @@ /** * StatusNet, the distributed open-source microblogging tool * - * Low-level generator for HTML + * Base Facebook Action * * PHP version 5 * @@ -22,18 +22,17 @@ * @category Faceboook * @package StatusNet * @author Zach Copley - * @copyright 2008 StatusNet, Inc. + * @copyright 2008-2009 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -if (!defined('STATUSNET') && !defined('LACONICA')) -{ +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/facebookutil.php'; -require_once INSTALLDIR.'/lib/noticeform.php'; +require_once INSTALLDIR . '/plugins/Facebook/facebookutil.php'; +require_once INSTALLDIR . '/lib/noticeform.php'; class FacebookAction extends Action { @@ -45,17 +44,6 @@ class FacebookAction extends Action var $app_uri = null; var $app_name = null; - /** - * Constructor - * - * Just wraps the HTMLOutputter constructor. - * - * @param string $output URI to output to, default = stdout - * @param boolean $indent Whether to indent output, default true - * - * @see XMLOutputter::__construct - * @see HTMLOutputter::__construct - */ function __construct($output='php://output', $indent=true, $facebook=null, $flink=null) { parent::__construct($output, $indent); @@ -107,10 +95,8 @@ class FacebookAction extends Action /** * Start an Facebook ready HTML document * - * For Facebook we don't want to actually output any headers, - * DTD info, etc. Just Stylesheet and JavaScript links. - * - * If $type isn't specified, will attempt to do content negotiation. + * For Facebook we don't want to actually output any headers, + * DTD info, etc. Just Stylesheet and JavaScript links. * * @param string $type MIME type to use; default is to do negotation. * @@ -139,8 +125,6 @@ class FacebookAction extends Action /** * Show notice form. * - * MAY overload if no notice form needed... or direct message box???? - * * @return nothing */ function showNoticeForm() @@ -157,10 +141,6 @@ class FacebookAction extends Action $this->elementEnd('div'); } - function showAside() - { - } - function showHead($error, $success) { @@ -214,8 +194,6 @@ class FacebookAction extends Action /** * Show header of the page. * - * Calls template methods - * * @return nothing */ function showHeader() @@ -257,7 +235,7 @@ class FacebookAction extends Action $this->element('a', array('href' => common_local_url('register')), _('Register')); $this->text($loginmsg_part2); - $this->elementEnd('p'); + $this->elementEnd('p'); $this->elementEnd('dd'); $this->elementEnd('dl'); @@ -295,7 +273,7 @@ class FacebookAction extends Action $this->elementEnd('ul'); $this->submit('submit', _('Login')); - $this->elementEnd('fieldset'); + $this->elementEnd('fieldset'); $this->elementEnd('form'); $this->elementStart('p'); @@ -313,8 +291,8 @@ class FacebookAction extends Action // Need to include inline CSS for styling the Profile box - $app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url')); - $icon_url = $app_props['icon_url']; + $app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url')); + $icon_url = $app_props['icon_url']; $style = '