From 2c9759c3b329eff455b3998d748292d581635f90 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 16 Jan 2009 20:19:49 +0000 Subject: trac750 Don't accidentally show login form after user logs in --- actions/facebookhome.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'actions/facebookhome.php') diff --git a/actions/facebookhome.php b/actions/facebookhome.php index f72f08a34..b780b8cc3 100644 --- a/actions/facebookhome.php +++ b/actions/facebookhome.php @@ -71,15 +71,16 @@ class FacebookhomeAction extends FacebookAction // XXX: Do some error handling here $this->setDefaults(); - $this->showHome($flink, _('You can now use Identi.ca from Facebook!')); - + return; + } else { $msg = _('Incorrect username or password.'); } } $this->showLoginForm($msg); + } function setDefaults() -- cgit v1.2.3-54-g00ecf From 3e18c2f0f8bbab01e16f66254dc9eadc9e1ffd60 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sun, 18 Jan 2009 01:31:39 +0000 Subject: trac750 Facebook App - generate HTML similar to uiredisign for everything --- actions/facebookhome.php | 10 +-- actions/facebookinvite.php | 8 +-- actions/facebooksettings.php | 14 ++--- lib/facebookaction.php | 145 +++++++++++++++++++++++++++++++------------ lib/facebookutil.php | 133 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 253 insertions(+), 57 deletions(-) (limited to 'actions/facebookhome.php') diff --git a/actions/facebookhome.php b/actions/facebookhome.php index b780b8cc3..46f886451 100644 --- a/actions/facebookhome.php +++ b/actions/facebookhome.php @@ -19,7 +19,7 @@ if (!defined('LACONICA')) { exit(1); } -require_once(INSTALLDIR.'/lib/facebookaction.php'); +require_once INSTALLDIR.'/lib/facebookaction.php'; class FacebookhomeAction extends FacebookAction { @@ -35,6 +35,8 @@ class FacebookhomeAction extends FacebookAction $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); if ($flink) { + $user = $flink->getUser(); + common_set_user($user); $this->showHome($flink, null); } else { $this->login($fbuid); @@ -103,7 +105,7 @@ class FacebookhomeAction extends FacebookAction update_profile_box($facebook, $fbuid, $user, $notice); - $this->show_header('Home'); + $this->showHeader('Home'); if ($msg) { common_element('fb:success', array('message' => $msg)); @@ -111,7 +113,7 @@ class FacebookhomeAction extends FacebookAction echo $this->show_notices($user); - $this->show_footer(); + $this->showFooter(); } function show_notices($user) @@ -132,7 +134,7 @@ class FacebookhomeAction extends FacebookAction function show_notice_list($notice) { - $nl = new NoticeList($notice); + $nl = new FacebookNoticeList($notice); return $nl->show(); } diff --git a/actions/facebookinvite.php b/actions/facebookinvite.php index fe0c5e493..d7e82dae7 100644 --- a/actions/facebookinvite.php +++ b/actions/facebookinvite.php @@ -41,7 +41,7 @@ class FacebookinviteAction extends FacebookAction $facebook = get_facebook(); $fbuid = $facebook->require_login(); - $this->show_header('Invite'); + $this->showHeader('Invite'); common_element('h2', null, _('Thanks for inviting your friends to use Identi.ca!')); common_element('p', null, _('Invitations have been sent to the following users:')); @@ -60,7 +60,7 @@ class FacebookinviteAction extends FacebookAction common_element_end("ul"); - $this->show_footer(); + $this->showFooter(); } function showInviteForm() @@ -69,7 +69,7 @@ class FacebookinviteAction extends FacebookAction $facebook = get_facebook(); $fbuid = $facebook->require_login(); - $this->show_header('Invite'); + $this->showHeader('Invite'); // Get a list of users who are already using the app for exclusion $exclude_ids = $facebook->api_client->friends_getAppUsers(); @@ -104,7 +104,7 @@ class FacebookinviteAction extends FacebookAction common_element_end("ul"); - $this->show_footer(); + $this->showFooter(); } diff --git a/actions/facebooksettings.php b/actions/facebooksettings.php index ab04ad82b..eafd91123 100644 --- a/actions/facebooksettings.php +++ b/actions/facebooksettings.php @@ -19,7 +19,7 @@ if (!defined('LACONICA')) { exit(1); } -require_once(INSTALLDIR.'/lib/facebookaction.php'); +require_once INSTALLDIR.'/lib/facebookaction.php'; class FacebooksettingsAction extends FacebookAction { @@ -29,13 +29,13 @@ class FacebooksettingsAction extends FacebookAction parent::handle($args); if ($this->arg('save')) { - $this->save_settings(); + $this->saveSettings(); } else { - $this->show_form(); + $this->showForm(); } } - function save_settings() { + function saveSettings() { $noticesync = $this->arg('noticesync'); $replysync = $this->arg('replysync'); @@ -59,14 +59,14 @@ class FacebooksettingsAction extends FacebookAction } } - function show_form($msg = null, $success = false) { + function showForm($msg = null, $success = false) { $facebook = get_facebook(); $fbuid = $facebook->require_login(); $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); - $this->show_header('Settings', $msg, $success); + $this->showHeader('Settings', $msg, $success); common_element_start('fb:if-section-not-added', array('section' => 'profile')); common_element('h2', null, _('Add an Identi.ca box to my profile')); @@ -108,7 +108,7 @@ class FacebooksettingsAction extends FacebookAction } - $this->show_footer(); + $this->showFooter(); } } diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 3a00c71dd..1bf026281 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -17,9 +17,11 @@ * along with this program. If not, see . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/facebookutil.php'); +require_once INSTALLDIR.'/lib/facebookutil.php'; class FacebookAction extends Action { @@ -29,32 +31,67 @@ class FacebookAction extends Action parent::handle($args); } - function show_header($selected = 'Home', $msg = null, $success = false) + function showLogo(){ + + global $xw; + + common_element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => get_facebook_css())); + + common_element_start('a', array('class' => 'url home bookmark', + 'href' => common_local_url('public'))); + if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) { + common_element('img', array('class' => 'logo photo', + 'src' => (common_config('site', 'logo')) ? + common_config('site', 'logo') : theme_path('logo.png'), + 'alt' => common_config('site', 'name'))); + } + + common_element('span', array('class' => 'fn org'), common_config('site', 'name')); + common_element_end('a'); + + } + + function showHeader($selected = 'Home', $msg = null, $success = false) { start_fbml(); - # Add a timestamp to the CSS file so Facebook cache wont ignore our changes - $ts = filemtime(theme_file('facebookapp.css')); - $cssurl = theme_path('facebookapp.css') . "?ts=$ts"; + $this->showLogo(); - common_element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => $cssurl)); + common_element_start('dl', array("id" => 'site_nav_local_views')); + common_element('dt', null, _('Local Views')); + common_element_start('dd'); + + common_element_start('ul', array('class' => 'nav')); + + common_element_start('li', array('class' => + ($selected == 'Home') ? 'current' : 'facebook_home')); + common_element('a', + array('href' => 'index.php', 'title' => _('Home')), _('Home')); + common_element_end('li'); - common_element('fb:dashboard'); + + common_element_start('li', + array('class' => + ($selected == 'Invite') ? 'current' : 'facebook_invite')); + common_element('a', + array('href' => 'invite.php', 'title' => _('Invite')), _('Invite')); + common_element_end('li'); - common_element_start('fb:tabs'); - common_element('fb:tab-item', array('title' => 'Home', - 'href' => 'index.php', - 'selected' => ($selected == 'Home'))); - common_element('fb:tab-item', array('title' => 'Invite', - 'href' => 'invite.php', - 'selected' => ($selected == 'Invite'))); - common_element('fb:tab-item', array('title' => 'Settings', - 'href' => 'settings.php', - 'selected' => ($selected == 'Settings'))); - common_element_end('fb:tabs'); + common_element_start('li', + array('class' => + ($selected == 'Settings') ? 'current' : 'facebook_settings')); + common_element('a', + array('href' => 'settings.php', + 'title' => _('Settings')), _('Settings')); + common_element_end('li'); + + common_element_end('ul'); + + common_element_end('dd'); + common_element_end('dl'); if ($msg) { @@ -69,44 +106,73 @@ class FacebookAction extends Action } - function show_footer() + function showFooter() { common_element_end('div'); common_end_xml(); } + + function showInstructions() + { + global $xw; + + common_element_start('dl', array('class' => 'system_notice')); + common_element('dt', null, 'Page Notice'); + + $loginmsg_part1 = _('To use the %s Facebook Application you need to login ' . + 'with your username and password. Don\'t have a username yet? '); + + $loginmsg_part2 = _(' a new account.'); + + common_element_start('dd'); + common_element_start('p'); + common_text(sprintf($loginmsg_part1, common_config('site', 'name'))); + common_element('a', + array('href' => common_local_url('register')), _('Register')); + common_text($loginmsg_part2); + common_element_end('dd'); + common_element_end('dl'); + } + function showLoginForm($msg = null) { start_fbml(); - common_element_start('a', array('href' => 'http://identi.ca')); - common_element('img', array('src' => 'http://theme.identi.ca/identica/logo.png', - 'alt' => 'Identi.ca', - 'id' => 'logo')); - common_element_end('a'); + common_element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => get_facebook_css())); + + $this->showLogo(); + + common_element_start('div', array('class' => 'content')); + common_element('h1', null, _('Login')); + if ($msg) { common_element('fb:error', array('message' => $msg)); } + + $this->showInstructions(); - common_element("h2", null, - _('To add the Identi.ca application, you need to log into your Identi.ca account.')); - + common_element_start('div', array('id' => 'content_inner')); - common_element_start('div', array('class' => 'instructions')); - common_element_start('p'); - common_raw('Login with your username and password. Don\'t have a username yet?' - .' Register a new account.'); - common_element_end('p'); - common_element_end('div'); - - common_element_start('div', array('id' => 'content')); common_element_start('form', array('method' => 'post', 'id' => 'login', 'action' => 'index.php')); + + common_element_start('fieldset'); + common_element('legend', null, _('Login to site')); + + common_element_start('ul', array('class' => 'form_datas')); + common_element_start('li'); common_input('nickname', _('Nickname')); + common_element_end('li'); + common_element_start('li'); common_password('password', _('Password')); - + common_element_end('li'); + common_element_end('ul'); + common_submit('submit', _('Login')); common_element_end('form'); @@ -114,6 +180,7 @@ class FacebookAction extends Action common_element('a', array('href' => common_local_url('recoverpassword')), _('Lost or forgotten password?')); common_element_end('p'); + common_element_end('div'); common_end_xml(); diff --git a/lib/facebookutil.php b/lib/facebookutil.php index 2529b8a4b..532e9c9d7 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -17,8 +17,8 @@ * along with this program. If not, see . */ -require_once(INSTALLDIR.'/extlib/facebook/facebook.php'); -require_once(INSTALLDIR.'/lib/noticelist.php'); +require_once INSTALLDIR.'/extlib/facebook/facebook.php'; +require_once INSTALLDIR.'/lib/noticelist.php'; define("FACEBOOK_SERVICE", 2); // Facebook is foreign_service ID 2 @@ -94,7 +94,7 @@ function update_profile_box($facebook, $fbuid, $user, $notice) $xw = new XMLWriter(); $xw->openMemory(); - $item = new NoticeListItem($notice); + $item = new FacebookNoticeListItem($notice); $item->show(); $fbml = "$style " . $xw->outputMemory(false) . ""; @@ -104,3 +104,130 @@ function update_profile_box($facebook, $fbuid, $user, $notice) $facebook->api_client->profile_setFBML(null, $fbuid, $fbml, null, null, $fbml_main); } + +function get_facebook_css() +{ + # Add a timestamp to the CSS file so Facebook cache wont ignore our changes + $ts = filemtime(theme_file('facebookapp.css')); + $cssurl = theme_path('facebookapp.css') . "?ts=$ts"; + return $cssurl; +} + + +class FacebookNoticeList extends NoticeList +{ + /** + * show the list of notices + * + * "Uses up" the stream by looping through it. So, probably can't + * be called twice on the same list. + * + * @return int count of notices listed. + */ + + function show() + { + common_element_start('div', array('id' =>'notices_primary')); + common_element('h2', null, _('Notices')); + common_element_start('ul', array('class' => 'notices')); + + $cnt = 0; + + while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) { + $cnt++; + + if ($cnt > NOTICES_PER_PAGE) { + break; + } + + $item = $this->newListItem($this->notice); + $item->show(); + } + + common_element_end('ul'); + common_element_end('div'); + + return $cnt; + } + + /** + * returns a new list item for the current notice + * + * Overridden to return a Facebook specific list item. + * + * @param Notice $notice the current notice + * + * @return FacebookNoticeListItem a list item for displaying the notice + * formatted for display in the Facebook App. + */ + + function newListItem($notice) + { + return new FacebookNoticeListItem($notice); + } + +} + +class FacebookNoticeListItem extends NoticeListItem +{ + /** + * recipe function for displaying a single notice in the Facebook App. + * + * Overridden to strip out some of the controls that we don't + * want to be available. + * + * @return void + */ + + function show() + { + $this->showStart(); + + common_element_start('div', 'entry-title'); + $this->showAuthor(); + $this->showContent(); + common_element_end('div'); + + common_element_start('div', 'entry-content'); + $this->showNoticeLink(); + $this->showNoticeSource(); + $this->showReplyTo(); + common_element_end('div'); + + $this->showEnd(); + } + + function showStart() + { + // XXX: RDFa + // TODO: add notice_type class e.g., notice_video, notice_image + common_element_start('li', array('class' => 'hentry notice', + 'id' => 'notice-' . $this->notice->id)); + } + + function showNoticeLink() + { + $noticeurl = common_local_url('shownotice', + array('notice' => $this->notice->id)); + // XXX: we need to figure this out better. Is this right? + if (strcmp($this->notice->uri, $noticeurl) != 0 && + preg_match('/^http/', $this->notice->uri)) { + $noticeurl = $this->notice->uri; + } + + common_element_start('dl', 'timestamp'); + common_element('dt', null, _('Published')); + common_element_start('dd', null); + common_element_start('a', array('rel' => 'bookmark', + 'href' => $noticeurl)); + $dt = common_date_iso8601($this->notice->created); + common_element('abbr', array('class' => 'published', + 'title' => $dt), + common_date_string($this->notice->created)); + common_element_end('a'); + common_element_end('dd'); + common_element_end('dl'); + } + +} + -- cgit v1.2.3-54-g00ecf From 12f7ec980ceb40d5241b63b88e7601e293c9f277 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 19 Jan 2009 00:50:45 +0000 Subject: trac750 Better workflow for asking user for status update permission --- actions/facebookhome.php | 94 ++++++++++++++++++++++++++++++++++++++++++-- actions/facebooksettings.php | 49 +++++++++++++++-------- lib/facebookaction.php | 60 ++++++++++++++-------------- lib/facebookutil.php | 26 ++++++------ 4 files changed, 166 insertions(+), 63 deletions(-) (limited to 'actions/facebookhome.php') diff --git a/actions/facebookhome.php b/actions/facebookhome.php index 46f886451..d211e8844 100644 --- a/actions/facebookhome.php +++ b/actions/facebookhome.php @@ -31,14 +31,41 @@ class FacebookhomeAction extends FacebookAction $facebook = get_facebook(); $fbuid = $facebook->require_login(); + // 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( + FACEBOOK_PROMPTED_UPDATE_PREF, 'true'); + } + // Check to see whether there's already a Facebook link for this user $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); if ($flink) { + $user = $flink->getUser(); common_set_user($user); + + // 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; + } + } + + // Use 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); + } else { + + // User hasn't authenticated yet, prompt for creds $this->login($fbuid); } @@ -73,16 +100,18 @@ class FacebookhomeAction extends FacebookAction // XXX: Do some error handling here $this->setDefaults(); - $this->showHome($flink, _('You can now use Identi.ca from Facebook!')); + //$this->showHome($flink, _('You can now use Identi.ca from Facebook!')); + + $this->getUpdatePermission(); return; - + } else { $msg = _('Incorrect username or password.'); } } $this->showLoginForm($msg); - + } function setDefaults() @@ -90,7 +119,10 @@ class FacebookhomeAction extends FacebookAction $facebook = get_facebook(); // A default prefix string for notices - $facebook->api_client->data_setUserPreference(1, 'dented: '); + $facebook->api_client->data_setUserPreference( + FACEBOOK_NOTICE_PREFIX, 'dented: '); + $facebook->api_client->data_setUserPreference( + FACEBOOK_PROMPTED_UPDATE_PREF, 'false'); } function showHome($flink, $msg) @@ -138,4 +170,58 @@ class FacebookhomeAction extends FacebookAction return $nl->show(); } + function getUpdatePermission() { + + $facebook = get_facebook(); + $fbuid = $facebook->require_login(); + + start_fbml(); + + common_element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => getFacebookCSS())); + + $this->showLogo(); + + common_element_start('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); + + common_element_start('p'); + common_element('span', array('id' => 'permissions_notice'), $instructions); + common_element_end('p'); + + common_element_start('form', array('method' => 'post', + 'action' => $app_url, + 'id' => 'facebook-skip-permissions')); + + common_element_start('ul', array('id' => 'fb-permissions-list')); + common_element_start('li', array('id' => 'fb-permissions-item')); + common_element_start('fb:prompt-permission', array('perms' => 'status_update', + 'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')')); + common_element('span', array('class' => 'facebook-button'), + _('Allow Identi.ca to update my Facebook status')); + common_element_end('fb:prompt-permission'); + common_element_end('li'); + + common_element_start('li', array('id' => 'fb-permissions-item')); + common_submit('skip', _('Skip')); + common_element_end('li'); + common_element_end('ul'); + + common_element_end('form'); + common_element_end('div'); + + common_end_xml(); + + } + } diff --git a/actions/facebooksettings.php b/actions/facebooksettings.php index b678f19a1..84e9a343b 100644 --- a/actions/facebooksettings.php +++ b/actions/facebooksettings.php @@ -50,12 +50,13 @@ class FacebooksettingsAction extends FacebookAction $flink->set_flags($noticesync, $replysync, false); $result = $flink->update($original); - $facebook->api_client->data_setUserPreference(1, substr($prefix, 0, 128)); + $facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX, + substr($prefix, 0, 128)); if ($result) { - $this->show_form('Sync preferences saved.', true); + $this->showForm('Sync preferences saved.', true); } else { - $this->show_form('There was a problem saving your sync preferences!'); + $this->showForm('There was a problem saving your sync preferences!'); } } @@ -67,18 +68,7 @@ class FacebooksettingsAction extends FacebookAction $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); $this->showHeader('Settings', $msg, $success); - - common_element_start('p'); - - // Figure what the URL of our app is. - $app_props = $facebook->api_client->Admin_getAppProperties(array('canvas_name')); - $app_url = 'http://apps.facebook.com/' . $app_props['canvas_name'] . '/settings.php'; - - common_element_start('fb:prompt-permission', array('perms' => 'status_update', - 'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')')); - common_element('h2', null, _('Allow Identi.ca to update my Facebook status')); - common_element_end('fb:prompt-permission'); - common_element_end('p'); + if ($facebook->api_client->users_hasAppPermission('status_update')) { @@ -90,11 +80,11 @@ class FacebooksettingsAction extends FacebookAction common_checkbox('noticesync', _('Automatically update my Facebook status with my notices.'), ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true); - common_checkbox('replysync', _('Send local "@" replies to Facebook.'), + common_checkbox('replysync', _('Send "@" replies to Facebook.'), ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true); $prefix = $facebook->api_client->data_getUserPreference(1); - + common_input('prefix', _('Prefix'), ($prefix) ? $prefix : null, @@ -103,6 +93,31 @@ class FacebooksettingsAction extends FacebookAction common_element_end('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 ' . + 'your Facebook status with your latest notice, you need ' . + 'to give it permission.'), $app_name); + + common_element_start('p'); + common_element('span', array('id' => 'permissions_notice'), $instructions); + common_element_end('p'); + + common_element_start('ul', array('id' => 'fb-permissions-list')); + common_element_start('li', array('id' => 'fb-permissions-item')); + common_element_start('fb:prompt-permission', array('perms' => 'status_update', + 'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')')); + common_element('span', array('class' => 'facebook-button'), + _('Allow Identi.ca to update my Facebook status')); + common_element_end('fb:prompt-permission'); + common_element_end('li'); + common_element_end('ul'); } $this->showFooter(); diff --git a/lib/facebookaction.php b/lib/facebookaction.php index a8f16b34a..0a364851f 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -if (!defined('LACONICA')) { +if (!defined('LACONICA')) { exit(1); } @@ -32,9 +32,9 @@ class FacebookAction extends Action } function showLogo(){ - + global $xw; - + common_element('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => getFacebookCSS())); @@ -47,14 +47,14 @@ class FacebookAction extends Action 'href' => common_local_url('public'))); if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) { common_element('img', array('class' => 'logo photo', - 'src' => (common_config('site', 'logo')) ? + 'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : theme_path('logo.png'), 'alt' => common_config('site', 'name'))); } - + common_element('span', array('class' => 'fn org'), common_config('site', 'name')); common_element_end('a'); - + } function showHeader($selected = 'Home', $msg = null, $success = false) @@ -76,25 +76,25 @@ class FacebookAction extends Action common_element_start('ul', array('class' => 'nav')); - common_element_start('li', array('class' => + common_element_start('li', array('class' => ($selected == 'Home') ? 'current' : 'facebook_home')); - common_element('a', + common_element('a', array('href' => 'index.php', 'title' => _('Home')), _('Home')); common_element_end('li'); - - common_element_start('li', + + common_element_start('li', array('class' => ($selected == 'Invite') ? 'current' : 'facebook_invite')); - common_element('a', + common_element('a', array('href' => 'invite.php', 'title' => _('Invite')), _('Invite')); common_element_end('li'); - common_element_start('li', + common_element_start('li', array('class' => ($selected == 'Settings') ? 'current' : 'facebook_settings')); - common_element('a', - array('href' => 'settings.php', + common_element('a', + array('href' => 'settings.php', 'title' => _('Settings')), _('Settings')); common_element_end('li'); @@ -125,24 +125,24 @@ class FacebookAction extends Action function showInstructions() { - global $xw; - + global $xw; + common_element_start('dl', array('class' => 'system_notice')); common_element('dt', null, 'Page Notice'); - + $loginmsg_part1 = _('To use the %s Facebook Application you need to login ' . - 'with your username and password. Don\'t have a username yet? '); - + 'with your username and password. Don\'t have a username yet? '); + $loginmsg_part2 = _(' a new account.'); - + common_element_start('dd'); common_element_start('p'); common_text(sprintf($loginmsg_part1, common_config('site', 'name'))); - common_element('a', + common_element('a', array('href' => common_local_url('register')), _('Register')); common_text($loginmsg_part2); common_element_end('dd'); - common_element_end('dl'); + common_element_end('dl'); } function showLoginForm($msg = null) @@ -154,14 +154,14 @@ class FacebookAction extends Action 'href' => getFacebookCSS())); $this->showLogo(); - + common_element_start('div', array('class' => 'content')); common_element('h1', null, _('Login')); - + if ($msg) { common_element('fb:error', array('message' => $msg)); } - + $this->showInstructions(); common_element_start('div', array('id' => 'content_inner')); @@ -169,19 +169,19 @@ class FacebookAction extends Action common_element_start('form', array('method' => 'post', 'id' => 'login', 'action' => 'index.php')); - + common_element_start('fieldset'); common_element('legend', null, _('Login to site')); - + common_element_start('ul', array('class' => 'form_datas')); - common_element_start('li'); + common_element_start('li'); common_input('nickname', _('Nickname')); common_element_end('li'); common_element_start('li'); common_password('password', _('Password')); common_element_end('li'); common_element_end('ul'); - + common_submit('submit', _('Login')); common_element_end('form'); @@ -189,7 +189,7 @@ class FacebookAction extends Action common_element('a', array('href' => common_local_url('recoverpassword')), _('Lost or forgotten password?')); common_element_end('p'); - + common_element_end('div'); common_end_xml(); diff --git a/lib/facebookutil.php b/lib/facebookutil.php index 61469b3c6..74e594592 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -21,6 +21,8 @@ require_once INSTALLDIR.'/extlib/facebook/facebook.php'; require_once INSTALLDIR.'/lib/noticelist.php'; define("FACEBOOK_SERVICE", 2); // Facebook is foreign_service ID 2 +define("FACEBOOK_NOTICE_PREFIX", 1); +define("FACEBOOK_PROMPTED_UPDATE_PREF", 2); // Gets all the notices from users with a Facebook link since a given ID function get_facebook_notices($since) @@ -106,18 +108,18 @@ function update_profile_box($facebook, $fbuid, $user, $notice) } function getFacebookCSS() -{ +{ # Add a timestamp to the CSS file so Facebook cache wont ignore our changes $ts = filemtime(theme_file('facebookapp.css')); - $cssurl = theme_path('facebookapp.css') . "?ts=$ts"; + $cssurl = theme_path('facebookapp.css') . "?ts=$ts"; return $cssurl; } function getFacebookJS() { - + # Add a timestamp to the FBJS file so Facebook cache wont ignore our changes $ts = filemtime(INSTALLDIR.'/js/facebookapp.js'); - $jsurl = common_path('js/facebookapp.js') . "?ts=$ts"; + $jsurl = common_path('js/facebookapp.js') . "?ts=$ts"; return $jsurl; } @@ -157,7 +159,7 @@ class FacebookNoticeList extends NoticeList return $cnt; } - + /** * returns a new list item for the current notice * @@ -173,7 +175,7 @@ class FacebookNoticeList extends NoticeList { return new FacebookNoticeListItem($notice); } - + } class FacebookNoticeListItem extends NoticeListItem @@ -190,7 +192,7 @@ class FacebookNoticeListItem extends NoticeListItem function show() { $this->showStart(); - + common_element_start('div', 'entry-title'); $this->showAuthor(); $this->showContent(); @@ -201,10 +203,10 @@ class FacebookNoticeListItem extends NoticeListItem $this->showNoticeSource(); $this->showReplyTo(); common_element_end('div'); - + $this->showEnd(); } - + function showStart() { // XXX: RDFa @@ -222,9 +224,9 @@ class FacebookNoticeListItem extends NoticeListItem preg_match('/^http/', $this->notice->uri)) { $noticeurl = $this->notice->uri; } - + common_element_start('dl', 'timestamp'); - common_element('dt', null, _('Published')); + common_element('dt', null, _('Published')); common_element_start('dd', null); common_element_start('a', array('rel' => 'bookmark', 'href' => $noticeurl)); @@ -237,5 +239,5 @@ class FacebookNoticeListItem extends NoticeListItem common_element_end('dl'); } -} +} -- cgit v1.2.3-54-g00ecf From cd6b9d6c4608cc5bb524031f8de97a3dc5cc3ea9 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 19 Jan 2009 02:13:25 +0000 Subject: trac750 fix method calls to get CSS files --- actions/facebookhome.php | 10 +++++++++- lib/facebookaction.php | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'actions/facebookhome.php') diff --git a/actions/facebookhome.php b/actions/facebookhome.php index d211e8844..7430cc41f 100644 --- a/actions/facebookhome.php +++ b/actions/facebookhome.php @@ -179,7 +179,15 @@ class FacebookhomeAction extends FacebookAction common_element('link', array('rel' => 'stylesheet', 'type' => 'text/css', - 'href' => getFacebookCSS())); + 'href' => getFacebookBaseCSS())); + + common_element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => getFacebookThemeCSS())); + + common_element('script', array('type' => 'text/javascript', + 'src' => getFacebookJS()), + ' '); $this->showLogo(); diff --git a/lib/facebookaction.php b/lib/facebookaction.php index fd171c457..263248f67 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -155,7 +155,15 @@ class FacebookAction extends Action common_element('link', array('rel' => 'stylesheet', 'type' => 'text/css', - 'href' => getFacebookCSS())); + 'href' => getFacebookBaseCSS())); + + common_element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => getFacebookThemeCSS())); + + common_element('script', array('type' => 'text/javascript', + 'src' => getFacebookJS()), + ' '); $this->showLogo(); -- cgit v1.2.3-54-g00ecf From 739baf0396b2e6796f07616cdb9d52d09cf6ed2f Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 19 Jan 2009 07:24:12 +0000 Subject: trac750 Add notice input box to FB app and ability to post notices --- actions/facebookhome.php | 93 ++++++++++++++++++++++---------- actions/facebookinvite.php | 3 +- actions/facebookremove.php | 2 +- actions/facebooksettings.php | 4 +- lib/facebookaction.php | 124 +++++++++++++++++++++++++++++++------------ lib/facebookutil.php | 38 ++++++++++++- scripts/update_facebook.php | 10 ++-- 7 files changed, 205 insertions(+), 69 deletions(-) (limited to 'actions/facebookhome.php') diff --git a/actions/facebookhome.php b/actions/facebookhome.php index 7430cc41f..3696df90a 100644 --- a/actions/facebookhome.php +++ b/actions/facebookhome.php @@ -30,6 +30,9 @@ class FacebookhomeAction extends FacebookAction $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); // If the user has opted not to initially allow the app to have // Facebook status update permission, store that preference. Only @@ -39,11 +42,13 @@ class FacebookhomeAction extends FacebookAction FACEBOOK_PROMPTED_UPDATE_PREF, 'true'); } - // Check to see whether there's already a Facebook link for this user - $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); - if ($flink) { + if ($_POST['submit'] == 'Send') { + $this->saveNewNotice($flink); + return; + } + $user = $flink->getUser(); common_set_user($user); @@ -136,19 +141,16 @@ class FacebookhomeAction extends FacebookAction $notice = $user->getCurrentNotice(); update_profile_box($facebook, $fbuid, $user, $notice); - - $this->showHeader('Home'); - - if ($msg) { - common_element('fb:success', array('message' => $msg)); - } - - echo $this->show_notices($user); + $this->showHeader($msg); + $this->showNoticeForm($user); + $this->showNav('Home'); + + echo $this->showNotices($user); $this->showFooter(); } - function show_notices($user) + function showNotices($user) { $page = $this->trimmed('page'); @@ -158,13 +160,13 @@ class FacebookhomeAction extends FacebookAction $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); - $cnt = $this->show_notice_list($notice); + $cnt = $this->showNoticeList($notice); - common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, - $page, 'all', array('nickname' => $user->nickname)); + facebookPagination($page > 1, $cnt > NOTICES_PER_PAGE, + $page, 'all', array('nickname' => $user->nickname)); } - function show_notice_list($notice) + function showNoticeList($notice) { $nl = new FacebookNoticeList($notice); return $nl->show(); @@ -175,19 +177,10 @@ class FacebookhomeAction extends FacebookAction $facebook = get_facebook(); $fbuid = $facebook->require_login(); - start_fbml(); + startFBML(); - common_element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => getFacebookBaseCSS())); - - common_element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => getFacebookThemeCSS())); - - common_element('script', array('type' => 'text/javascript', - 'src' => getFacebookJS()), - ' '); + $this->showStylesheets(); + $this->showScripts(); $this->showLogo(); @@ -231,5 +224,49 @@ class FacebookhomeAction extends FacebookAction common_end_xml(); } + + function saveNewNotice($flink) + { + + $user = $flink->getUser(); + $content = $_POST['status_textarea']; + + if (!$content) { + $this->showHome($flink, _('No content!')); + return; + } else { + $content_shortened = common_shorten_links($content); + + 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.')); + return; + } + } + + $inter = new CommandInterpreter(); + + $cmd = $inter->handle_command($user, $content_shortened); + + if ($cmd) { + $cmd->execute(new WebChannel()); + return; + } + + $replyto = $this->trimmed('inreplyto'); + + $notice = Notice::saveNew($user->id, $content, + 'Facebook', 1, ($replyto == 'false') ? null : $replyto); + + if (is_string($notice)) { + $this->showHome($flink, 'Error!'); + return; + } + + common_broadcast_notice($notice); + $this->showHome($flink, 'Success!'); + } + } diff --git a/actions/facebookinvite.php b/actions/facebookinvite.php index d7e82dae7..e67bfaa00 100644 --- a/actions/facebookinvite.php +++ b/actions/facebookinvite.php @@ -69,7 +69,8 @@ class FacebookinviteAction extends FacebookAction $facebook = get_facebook(); $fbuid = $facebook->require_login(); - $this->showHeader('Invite'); + $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(); diff --git a/actions/facebookremove.php b/actions/facebookremove.php index a200fefbf..557c0655b 100644 --- a/actions/facebookremove.php +++ b/actions/facebookremove.php @@ -19,7 +19,7 @@ if (!defined('LACONICA')) { exit(1); } -require_once(INSTALLDIR.'/lib/facebookaction.php'); +require_once INSTALLDIR.'/lib/facebookaction.php'; class FacebookremoveAction extends FacebookAction { diff --git a/actions/facebooksettings.php b/actions/facebooksettings.php index 84e9a343b..a08abc937 100644 --- a/actions/facebooksettings.php +++ b/actions/facebooksettings.php @@ -67,8 +67,8 @@ class FacebooksettingsAction extends FacebookAction $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); - $this->showHeader('Settings', $msg, $success); - + $this->showHeader($msg, $success); + $this->showNav('Settings'); if ($facebook->api_client->users_hasAppPermission('status_update')) { diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 263248f67..cd43a2ccb 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -35,17 +35,8 @@ class FacebookAction extends Action global $xw; - common_element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => getFacebookBaseCSS())); - - common_element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => getFacebookThemeCSS())); - - common_element('script', array('type' => 'text/javascript', - 'src' => getFacebookJS()), - ' '); + $this->showStylesheets(); + $this->showScripts(); common_element_start('a', array('class' => 'url home bookmark', 'href' => common_local_url('public'))); @@ -61,19 +52,34 @@ class FacebookAction extends Action } - function showHeader($selected = 'Home', $msg = null, $success = false) - { - start_fbml(); + function showHeader($msg = null, $success = false) + { + startFBML(); common_element_start('fb:if-section-not-added', array('section' => 'profile')); common_element_start('span', array('id' => 'add_to_profile')); common_element('fb:add-section-button', array('section' => 'profile')); common_element_end('span'); common_element_end('fb:if-section-not-added'); - + $this->showLogo(); + if ($msg) { + if ($success) { + common_element('fb:success', array('message' => $msg)); + } else { + // XXX do an error message here + } + } + + common_element_start('div', 'main_body'); + + } + + function showNav($selected = 'Home') + { + common_element_start('dl', array("id" => 'site_nav_local_views')); common_element('dt', null, _('Local Views')); common_element_start('dd'); @@ -86,7 +92,6 @@ class FacebookAction extends Action array('href' => 'index.php', 'title' => _('Home')), _('Home')); common_element_end('li'); - common_element_start('li', array('class' => ($selected == 'Invite') ? 'current' : 'facebook_invite')); @@ -107,17 +112,6 @@ class FacebookAction extends Action common_element_end('dd'); common_element_end('dl'); - - if ($msg) { - if ($success) { - common_element('fb:success', array('message' => $msg)); - } else { - // XXX do an error message here - } - } - - common_element_start('div', 'main_body'); - } function showFooter() @@ -149,10 +143,11 @@ class FacebookAction extends Action common_element_end('dl'); } - function showLoginForm($msg = null) - { - start_fbml(); + function showStylesheets() + { + global $xw; + common_element('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => getFacebookBaseCSS())); @@ -160,10 +155,23 @@ class FacebookAction extends Action common_element('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => getFacebookThemeCSS())); - + } + + function showScripts() + { + global $xw; + common_element('script', array('type' => 'text/javascript', - 'src' => getFacebookJS()), - ' '); + 'src' => getFacebookJS())); + + } + + function showLoginForm($msg = null) + { + startFBML(); + + $this->showStylesheets(); + $this->showScripts(); $this->showLogo(); @@ -179,6 +187,7 @@ class FacebookAction extends Action common_element_start('div', array('id' => 'content_inner')); common_element_start('form', array('method' => 'post', + 'class' => 'form_settings', 'id' => 'login', 'action' => 'index.php')); @@ -209,4 +218,53 @@ class FacebookAction extends Action } + function showNoticeForm($user) + { + + global $xw; + + common_element_start('form', array('id' => 'form_notice', + 'method' => 'post', + 'action' => 'index.php')); + + common_element_start('fieldset'); + common_element('legend', null, 'Send a notice'); + + common_element_start('ul', 'form_datas'); + common_element_start('li', array('id' => 'noticcommon_elemente_text')); + common_element('label', array('for' => 'notice_data-text'), + sprintf(_('What\'s up, %s?'), $user->nickname)); + + common_element('textarea', array('id' => 'notice_data-text', + 'cols' => 35, + 'rows' => 4, + 'name' => 'status_textarea')); + common_element_end('li'); + common_element_end('ul'); + + common_element_start('dl', 'form_note'); + common_element('dt', null, _('Available characters')); + common_element('dd', array('id' => 'notice_text-count'), + '140'); + common_element_end('dl'); + + common_element_start('ul', array('class' => 'form_actions')); + + common_element_start('li', array('id' => 'notice_submit')); + + common_submit('submit', _('Send')); + + /* + common_element('input', array('id' => 'notice_action-submit', + 'class' => 'submit', + 'name' => 'status_submit', + 'type' => 'submit', + 'value' => _('Send'))); + */ + common_element_end('li'); + common_element_end('ul'); + common_element_end('fieldset'); + common_element_end('form'); + } + } diff --git a/lib/facebookutil.php b/lib/facebookutil.php index cc4941bdc..a133ce8ba 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -44,7 +44,7 @@ function get_facebook() return new Facebook($apikey, $secret); } -function start_fbml($indent = true) +function startFBML($indent = true) { global $xw; $xw = new XMLWriter(); @@ -132,6 +132,42 @@ function getFacebookJS() { } +// Does a little before-after block for next/prev page + +function facebookPagination($have_before, $have_after, $page, $action, $args=null) +{ + + if ($have_before || $have_after) { + common_element_start('div', array('id' => 'pagination')); + common_element_start('ul', array('id' => 'nav_pagination')); + } + + if ($have_before) { + $pargs = array('page' => $page-1); + $newargs = ($args) ? array_merge($args,$pargs) : $pargs; + + common_element_start('li', 'before'); + common_element('a', array('href' => "index.php?page=$newargs[page]", 'rel' => 'prev'), + _('« After')); + common_element_end('li'); + } + + if ($have_after) { + $pargs = array('page' => $page+1); + $newargs = ($args) ? array_merge($args,$pargs) : $pargs; + common_element_start('li', 'after'); + common_element('a', array('href' => "index.php?page=$newargs[page]", 'rel' => 'next'), + _('Before »')); + common_element_end('li'); + } + + if ($have_before || $have_after) { + common_element_end('ul'); + common_element_end('div'); + } +} + + class FacebookNoticeList extends NoticeList { /** diff --git a/scripts/update_facebook.php b/scripts/update_facebook.php index 8c91df384..0c54cec7c 100755 --- a/scripts/update_facebook.php +++ b/scripts/update_facebook.php @@ -67,9 +67,13 @@ while($notice->fetch()) { // If it's not a reply, or if the user WANTS to send replies... if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $content) || (($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) { - update_status($fbuid, $content); - update_profile_box($facebook, $fbuid, $user, $notice); - $cnt++; + + // Avoid a Loop + if ($notice->source != 'Facebook') { + update_status($fbuid, $content); + update_profile_box($facebook, $fbuid, $user, $notice); + $cnt++; + } } } } -- cgit v1.2.3-54-g00ecf