diff options
author | Evan Prodromou <evan@controlyourself.ca> | 2009-01-23 04:21:08 +0100 |
---|---|---|
committer | Evan Prodromou <evan@controlyourself.ca> | 2009-01-23 04:21:08 +0100 |
commit | ed09eece2806212ff412eab6b7a24d8e510f6d1a (patch) | |
tree | 9e8f0a9a18693c7bdae3b93a0857973fd91158a7 /actions | |
parent | 3c8f41deb0f45ebad467cb3b4a8faab214d7ee49 (diff) | |
parent | bf50e4a25af94de956721659336795835c712e0a (diff) |
Merge branch 'master' of evan@dev.controlyourself.ca:/var/www/trunk
Diffstat (limited to 'actions')
-rw-r--r-- | actions/facebookhome.php | 226 | ||||
-rw-r--r-- | actions/facebookinvite.php | 75 | ||||
-rw-r--r-- | actions/facebooksettings.php | 97 |
3 files changed, 245 insertions, 153 deletions
diff --git a/actions/facebookhome.php b/actions/facebookhome.php index 14342f944..ea56ec071 100644 --- a/actions/facebookhome.php +++ b/actions/facebookhome.php @@ -21,62 +21,75 @@ if (!defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/lib/facebookaction.php'; + class FacebookhomeAction extends FacebookAction { + var $page = null; + + function prepare($argarray) + { + parent::prepare($argarray); + + $this->page = $this->trimmed('page'); + + if (!$this->page) { + $this->page = 1; + } + + return true; + } + function handle($args) { - parent::handle($args); - - $facebook = get_facebook(); - $fbuid = $facebook->require_login(); - - // Check to see whether there's already a Facebook link for this user - $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); - + parent::handle($args); + // If the user has opted not to initially allow the app to have // Facebook status update permission, store that preference. Only // promt the user the first time she uses the app if ($this->arg('skip')) { - $facebook->api_client->data_setUserPreference( + $this->facebook->api_client->data_setUserPreference( FACEBOOK_PROMPTED_UPDATE_PREF, 'true'); } - if ($flink) { - - if ($_POST['submit'] == 'Send') { - $this->saveNewNotice($flink); - return; - } + if ($this->flink) { - $user = $flink->getUser(); - common_set_user($user); + $this->user = $this->flink->getUser(); // If this is the first time the user has started the app - // prompt for Facebook status update permission - if (!$facebook->api_client->users_hasAppPermission('status_update')) { - - if ($facebook->api_client->data_getUserPreference( - FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') { - $this->getUpdatePermission(); - return; - } + // prompt for Facebook status update permission + if (!$this->facebook->api_client->users_hasAppPermission('status_update')) { + + if ($this->facebook->api_client->data_getUserPreference( + FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') { + $this->getUpdatePermission(); + return; + } + } + + // Make sure the user's profile box has the lastest notice + $notice = $this->user->getCurrentNotice(); + $this->updateProfileBox($notice); + + if ($this->arg('status_submit') == 'Send') { + $this->saveNewNotice(); } - // Use is authenticated and has already been prompted once for + // User is authenticated and has already been prompted once for // Facebook status update permission? Then show the main page // of the app - $this->showHome($flink, null); + $this->showPage(); + } else { // User hasn't authenticated yet, prompt for creds - $this->login($fbuid); + $this->login(); } } - function login($fbuid) + function login() { $nickname = common_canonical_nickname($this->trimmed('nickname')); $password = $this->arg('password'); @@ -95,7 +108,7 @@ class FacebookhomeAction extends FacebookAction $flink = DB_DataObject::factory('foreign_link'); $flink->user_id = $user->id; - $flink->foreign_id = $fbuid; + $flink->foreign_id = $this->fbuid; $flink->service = FACEBOOK_SERVICE; $flink->created = common_sql_now(); $flink->set_flags(true, false, false); @@ -121,80 +134,62 @@ class FacebookhomeAction extends FacebookAction function setDefaults() { - $facebook = get_facebook(); - // A default prefix string for notices - $facebook->api_client->data_setUserPreference( + $this->facebook->api_client->data_setUserPreference( FACEBOOK_NOTICE_PREFIX, 'dented: '); - $facebook->api_client->data_setUserPreference( + $this->facebook->api_client->data_setUserPreference( FACEBOOK_PROMPTED_UPDATE_PREF, 'false'); } + - function showHome($flink, $msg) + function showNoticeForm() { + + $post_action = "$this->app_uri/index.php"; + + $notice_form = new FacebookNoticeForm($this, $post_action, null, + $post_action, $this->user); + $notice_form->show(); + } - $facebook = get_facebook(); - $fbuid = $facebook->require_login(); - - $user = $flink->getUser(); - - $notice = $user->getCurrentNotice(); - update_profile_box($facebook, $fbuid, $user, $notice); - - $this->showHeader($msg); - $this->showNoticeForm($user); - $this->showNav('Home'); - - echo $this->showNotices($user); - - $this->showFooter(); + function title() + { + if ($this->page > 1) { + return sprintf(_("%s and friends, page %d"), $this->user->nickname, $this->page); + } else { + return sprintf(_("%s and friends"), $this->user->nickname); + } } - function showNotices($user) + function showContent() { - $page = $this->trimmed('page'); - if (!$page) { - $page = 1; - } + $notice = $this->user->noticesWithFriends(($this->page-1) * + NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + + $nl = new NoticeList($notice, $this); - $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + $cnt = $nl->show(); - $cnt = $this->showNoticeList($notice); + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'index.php', array('nickname' => $this->user->nickname)); - facebookPagination($page > 1, $cnt > NOTICES_PER_PAGE, - $page, 'all', array('nickname' => $user->nickname)); } function showNoticeList($notice) { - $nl = new FacebookNoticeList($notice); + + $nl = new NoticeList($notice, $this); return $nl->show(); } function getUpdatePermission() { - $facebook = get_facebook(); - $fbuid = $facebook->require_login(); - - startFBML(); - - $this->showStylesheets(); - $this->showScripts(); - - $this->showLogo(); - $this->elementStart('div', array('class' => 'content')); - // Figure what the URL of our app is. - $app_props = $facebook->api_client->Admin_getAppProperties( - array('canvas_name', 'application_name')); - $app_url = 'http://apps.facebook.com/' . $app_props['canvas_name'] . '/index.php'; - $app_name = $app_props['application_name']; - $instructions = sprintf(_('If you would like the %s app to automatically update ' . 'your Facebook status with your latest notice, you need ' . - 'to give it permission.'), $app_name); + 'to give it permission.'), $this->app_name); $this->elementStart('p'); $this->element('span', array('id' => 'permissions_notice'), $instructions); @@ -207,33 +202,31 @@ class FacebookhomeAction extends FacebookAction $this->elementStart('ul', array('id' => 'fb-permissions-list')); $this->elementStart('li', array('id' => 'fb-permissions-item')); $this->elementStart('fb:prompt-permission', array('perms' => 'status_update', - 'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')')); + 'next_fbjs' => 'document.setLocation(\'' . $this->app_uri . '\')')); $this->element('span', array('class' => 'facebook-button'), - _('Allow Identi.ca to update my Facebook status')); + sprintf(_('Allow %s to update my Facebook status'), $this->app_name)); $this->elementEnd('fb:prompt-permission'); $this->elementEnd('li'); $this->elementStart('li', array('id' => 'fb-permissions-item')); - common_submit('skip', _('Skip')); + $this->submit('skip', _('Skip')); $this->elementEnd('li'); $this->elementEnd('ul'); $this->elementEnd('form'); $this->elementEnd('div'); - common_end_xml(); - } - function saveNewNotice($flink) + function saveNewNotice() { - $user = $flink->getUser(); - - $content = $_POST['status_textarea']; + $user = $this->flink->getUser(); + $content = $this->trimmed('status_textarea'); + if (!$content) { - $this->showHome($flink, _('No content!')); + $this->showPage(_('No notice content!')); return; } else { $content_shortened = common_shorten_links($content); @@ -241,7 +234,7 @@ class FacebookhomeAction extends FacebookAction if (mb_strlen($content_shortened) > 140) { common_debug("Content = '$content_shortened'", __FILE__); common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__); - $this->showHome($flink, _('That\'s too long. Max notice size is 140 chars.')); + $this->showPage(_('That\'s too long. Max notice size is 140 chars.')); return; } } @@ -251,6 +244,9 @@ class FacebookhomeAction extends FacebookAction $cmd = $inter->handle_command($user, $content_shortened); if ($cmd) { + + // XXX fix this + $cmd->execute(new WebChannel()); return; } @@ -261,12 +257,62 @@ class FacebookhomeAction extends FacebookAction 'Facebook', 1, ($replyto == 'false') ? null : $replyto); if (is_string($notice)) { - $this->showHome($flink, 'Error!'); + $this->showPage($notice); return; } common_broadcast_notice($notice); - $this->showHome($flink, 'Success!'); + + } + + /** + * Generate pagination links + * + * @param boolean $have_before is there something before? + * @param boolean $have_after is there something after? + * @param integer $page current page + * @param string $action current action + * @param array $args rest of query arguments + * + * @return nothing + */ + function pagination($have_before, $have_after, $page, $action, $args=null) + { + + // Does a little before-after block for next/prev page + + // XXX: Fix so this uses common_local_url() if possible. + + if ($have_before || $have_after) { + $this->elementStart('div', array('class' => 'pagination')); + $this->elementStart('dl', null); + $this->element('dt', null, _('Pagination')); + $this->elementStart('dd', null); + $this->elementStart('ul', array('class' => 'nav')); + } + if ($have_before) { + $pargs = array('page' => $page-1); + $newargs = $args ? array_merge($args, $pargs) : $pargs; + $this->elementStart('li', array('class' => 'nav_prev')); + $this->element('a', array('href' => "$action?page=$newargs[page]", 'rel' => 'prev'), + _('After')); + $this->elementEnd('li'); + } + if ($have_after) { + $pargs = array('page' => $page+1); + $newargs = $args ? array_merge($args, $pargs) : $pargs; + $this->elementStart('li', array('class' => 'nav_next')); + $this->element('a', array('href' => "$action?page=$newargs[page]", 'rel' => 'next'), + _('Before')); + $this->elementEnd('li'); + } + if ($have_before || $have_after) { + $this->elementEnd('ul'); + $this->elementEnd('dd'); + $this->elementEnd('dl'); + $this->elementEnd('div'); + } } + } diff --git a/actions/facebookinvite.php b/actions/facebookinvite.php index 1e6f6496e..b7224783a 100644 --- a/actions/facebookinvite.php +++ b/actions/facebookinvite.php @@ -27,26 +27,51 @@ class FacebookinviteAction extends FacebookAction function handle($args) { parent::handle($args); + $this->showForm(); + } + + /** + * Wrapper for showing a page + * + * Stores an error and shows the page + * + * @param string $error Error, if any + * + * @return void + */ + + function showForm($error=null) + { + $this->error = $error; + $this->showPage(); + } + /** + * Show the page content + * + * Either shows the registration form or, if registration was successful, + * instructions for using the site. + * + * @return void + */ + + function showContent() + { if ($this->arg('ids')) { - $this->showThankYou(); + $this->showSuccessContent(); } else { - $this->showInviteForm(); + $this->showFormContent(); } } - - function showThankYou() + function showSuccessContent() { - $facebook = get_facebook(); - $fbuid = $facebook->require_login(); - $this->showHeader('Invite'); - - $this->element('h2', null, _('Thanks for inviting your friends to use Identi.ca!')); + $this->element('h2', null, sprintf(_('Thanks for inviting your friends to use %s'), + common_config('site', 'name'))); $this->element('p', null, _('Invitations have been sent to the following users:')); - $friend_ids = $_POST['ids']; // Hmm... $this->arg('ids') doesn't seem to work + $friend_ids = $_POST['ids']; // XXX: Hmm... is this the best way to acces the list? $this->elementStart("ul"); @@ -60,31 +85,24 @@ class FacebookinviteAction extends FacebookAction $this->elementEnd("ul"); - $this->showFooter(); } - function showInviteForm() + function showFormContent() { - $facebook = get_facebook(); - $fbuid = $facebook->require_login(); - - $this->showHeader(); - $this->showNav('Invite'); - // Get a list of users who are already using the app for exclusion - $exclude_ids = $facebook->api_client->friends_getAppUsers(); + $exclude_ids = $this->facebook->api_client->friends_getAppUsers(); - $content = _('You have been invited to Identi.ca!') . - htmlentities('<fb:req-choice url="http://apps.facebook.com/identica_app/" label="Add"/>'); + $content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) . + htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>'); $this->elementStart('fb:request-form', array('action' => 'invite.php', 'method' => 'post', 'invite' => 'true', - 'type' => 'Identi.ca', + 'type' => common_config('site', 'name'), 'content' => $content)); $this->hidden('invite', 'true'); - $actiontext = 'Invite your friends to use Identi.ca.'; + $actiontext = sprintf(_('Invite your friends to use %s'), common_config('site', 'name')); $this->element('fb:multi-friend-selector', array('showborder' => 'false', 'actiontext' => $actiontext, 'exclude_ids' => implode(',', $exclude_ids), @@ -92,7 +110,8 @@ class FacebookinviteAction extends FacebookAction $this->elementEnd('fb:request-form'); - $this->element('h2', null, _('Friends already using Identi.ca:')); + $this->element('h2', null, sprintf(_('Friends already using %s:'), + common_config('site', 'name'))); $this->elementStart("ul"); foreach ($exclude_ids as $friend) { @@ -104,9 +123,11 @@ class FacebookinviteAction extends FacebookAction } $this->elementEnd("ul"); - - $this->showFooter(); - + } + + function title() + { + return sprintf(_('Send invitations')); } } diff --git a/actions/facebooksettings.php b/actions/facebooksettings.php index d4f03e58c..e40496c18 100644 --- a/actions/facebooksettings.php +++ b/actions/facebooksettings.php @@ -27,7 +27,20 @@ class FacebooksettingsAction extends FacebookAction function handle($args) { parent::handle($args); + $this->showPage(); + } + + /** + * Show the page content + * + * Either shows the registration form or, if registration was successful, + * instructions for using the site. + * + * @return void + */ + function showContent() + { if ($this->arg('save')) { $this->saveSettings(); } else { @@ -41,68 +54,76 @@ class FacebooksettingsAction extends FacebookAction $replysync = $this->arg('replysync'); $prefix = $this->trimmed('prefix'); - $facebook = get_facebook(); - $fbuid = $facebook->require_login(); + $original = clone($this->flink); + $this->flink->set_flags($noticesync, $replysync, false); + $result = $this->flink->update($original); - $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); - - $original = clone($flink); - $flink->set_flags($noticesync, $replysync, false); - $result = $flink->update($original); - - $facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX, + $this->facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX, substr($prefix, 0, 128)); - if ($result) { - $this->showForm('Sync preferences saved.', true); + if ($result === false) { + $this->showForm(_('There was a problem saving your sync preferences!')); } else { - $this->showForm('There was a problem saving your sync preferences!'); + $this->showForm(_('Sync preferences saved.'), true); } } function showForm($msg = null, $success = false) { - $facebook = get_facebook(); - $fbuid = $facebook->require_login(); - - $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); - - $this->showHeader($msg, $success); - $this->showNav('Settings'); + if ($msg) { + if ($success) { + $this->element('fb:success', array('message' => $msg)); + } else { + $this->element('fb:error', array('message' => $msg)); + } + } - if ($facebook->api_client->users_hasAppPermission('status_update')) { + if ($this->facebook->api_client->users_hasAppPermission('status_update')) { $this->elementStart('form', array('method' => 'post', 'id' => 'facebook_settings')); - $this->element('h2', null, _('Sync preferences')); - + $this->elementStart('ul', 'form_data'); + + $this->elementStart('li'); + $this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'), - ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true); + ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND) : true); + $this->elementEnd('li'); + + $this->elementStart('li'); + $this->checkbox('replysync', _('Send "@" replies to Facebook.'), - ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true); + ($this->flink) ? ($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true); - $prefix = $facebook->api_client->data_getUserPreference(1); + $this->elementEnd('li'); + + $this->elementStart('li'); + + $prefix = $this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX); $this->input('prefix', _('Prefix'), ($prefix) ? $prefix : null, _('A string to prefix notices with.')); + + $this->elementEnd('li'); + + $this->elementStart('li'); + $this->submit('save', _('Save')); + $this->elementEnd('li'); + + $this->elementEnd('ul'); + $this->elementEnd('form'); } else { - // Figure what the URL of our app is. - $app_props = $facebook->api_client->Admin_getAppProperties( - array('canvas_name', 'application_name')); - $app_url = 'http://apps.facebook.com/' . $app_props['canvas_name'] . '/settings.php'; - $app_name = $app_props['application_name']; - - $instructions = sprintf(_('If you would like the %s app to automatically update ' . + $instructions = sprintf(_('If you would like %s to automatically update ' . 'your Facebook status with your latest notice, you need ' . - 'to give it permission.'), $app_name); + 'to give it permission.'), $this->app_name); $this->elementStart('p'); $this->element('span', array('id' => 'permissions_notice'), $instructions); @@ -111,15 +132,19 @@ class FacebooksettingsAction extends FacebookAction $this->elementStart('ul', array('id' => 'fb-permissions-list')); $this->elementStart('li', array('id' => 'fb-permissions-item')); $this->elementStart('fb:prompt-permission', array('perms' => 'status_update', - 'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')')); + 'next_fbjs' => 'document.setLocation(\'' . "$this->app_url/settings.php" . '\')')); $this->element('span', array('class' => 'facebook-button'), - _('Allow Identi.ca to update my Facebook status')); + sprintf(_('Allow %s to update my Facebook status'), common_config('site', 'name'))); $this->elementEnd('fb:prompt-permission'); $this->elementEnd('li'); $this->elementEnd('ul'); } - $this->showFooter(); + } + + function title() + { + return _('Sync preferences'); } } |