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 --- lib/facebookutil.php | 133 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 3 deletions(-) (limited to 'lib/facebookutil.php') 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 8fdf888edbd74e707d2698c7625dc90b22f0aeef Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sun, 18 Jan 2009 06:12:47 +0000 Subject: trac750 Javascript file for Facebook app --- actions/facebooksettings.php | 17 +++++++---------- js/facebookapp.js | 25 +++++++++++++++++++++++++ lib/facebookaction.php | 15 ++++++++++++--- lib/facebookutil.php | 10 +++++++++- 4 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 js/facebookapp.js (limited to 'lib/facebookutil.php') diff --git a/actions/facebooksettings.php b/actions/facebooksettings.php index eafd91123..372c40c28 100644 --- a/actions/facebooksettings.php +++ b/actions/facebooksettings.php @@ -68,19 +68,18 @@ class FacebooksettingsAction extends FacebookAction $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')); + common_element('form', array('id' => 'redirect_form', + 'style' => 'display: none;')); + common_element_start('p'); - common_element('fb:add-section-button', array('section' => 'profile')); - common_element_end('p'); - - common_element_end('fb:if-section-not-added'); - common_element_start('p'); - common_element_start('fb:prompt-permission', array('perms' => 'status_update')); + common_element_start('fb:prompt-permission', array('perms' => 'status_update', + 'next_fbjs' => 'redirectSettings()')); 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')) { common_element_start('form', array('method' => 'post', @@ -94,8 +93,6 @@ class FacebooksettingsAction extends FacebookAction common_checkbox('replysync', _('Send local "@" replies to Facebook.'), ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true); - // function common_input($id, $label, $value=null,$instructions=null) - $prefix = $facebook->api_client->data_getUserPreference(1); diff --git a/js/facebookapp.js b/js/facebookapp.js new file mode 100644 index 000000000..3f809e50c --- /dev/null +++ b/js/facebookapp.js @@ -0,0 +1,25 @@ +/* + * Laconica - a distributed open-source microblogging tool + * Copyright (C) 2008, Controlez-Vous, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +// Psycho Facebook redirect hack, used because 'document.location' +// simply does not work in FBJS +function redirectSettings() { + form = document.getElementById('redirect_form'); + form.setAction('settings.php'); + form.submit(); +} diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 1bf026281..a8f16b34a 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -37,7 +37,11 @@ class FacebookAction extends Action common_element('link', array('rel' => 'stylesheet', 'type' => 'text/css', - 'href' => get_facebook_css())); + 'href' => getFacebookCSS())); + + common_element('script', array('type' => 'text/javascript', + 'src' => getFacebookJS()), + ' '); common_element_start('a', array('class' => 'url home bookmark', 'href' => common_local_url('public'))); @@ -58,6 +62,12 @@ class FacebookAction extends Action start_fbml(); + 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(); common_element_start('dl', array("id" => 'site_nav_local_views')); @@ -141,8 +151,7 @@ class FacebookAction extends Action common_element('link', array('rel' => 'stylesheet', 'type' => 'text/css', - 'href' => get_facebook_css())); - + 'href' => getFacebookCSS())); $this->showLogo(); diff --git a/lib/facebookutil.php b/lib/facebookutil.php index 532e9c9d7..61469b3c6 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -105,7 +105,7 @@ function update_profile_box($facebook, $fbuid, $user, $notice) $facebook->api_client->profile_setFBML(null, $fbuid, $fbml, null, null, $fbml_main); } -function get_facebook_css() +function getFacebookCSS() { # Add a timestamp to the CSS file so Facebook cache wont ignore our changes $ts = filemtime(theme_file('facebookapp.css')); @@ -113,6 +113,14 @@ function get_facebook_css() 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"; + return $jsurl; +} + class FacebookNoticeList extends NoticeList { -- 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 'lib/facebookutil.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 64bda5bd6ca58289c3a525a20c2dc27501fb1cf8 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 19 Jan 2009 01:34:25 +0000 Subject: trac750 New CSS files for FB app to allow bettter per-install theming --- lib/facebookaction.php | 6 +++++- lib/facebookutil.php | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'lib/facebookutil.php') diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 0a364851f..fd171c457 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -37,7 +37,11 @@ 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()), diff --git a/lib/facebookutil.php b/lib/facebookutil.php index 74e594592..0bde68c0f 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -107,14 +107,22 @@ function update_profile_box($facebook, $fbuid, $user, $notice) $facebook->api_client->profile_setFBML(null, $fbuid, $fbml, null, null, $fbml_main); } -function getFacebookCSS() +function getFacebookBaseCSS() { # 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"; + $ts = filemtime(theme_file('facebookapp_base.css')); + $cssurl = theme_path('facebookapp_base.css') . "?ts=$ts"; return $cssurl; } +function getFacebookThemeCSS() +{ + # Add a timestamp to the CSS file so Facebook cache wont ignore our changes + $ts = filemtime(theme_file('facebookapp_theme.css')); + $cssurl = theme_path('facebookapp_theme.css') . "?ts=$ts"; + return $cssurl; +} + function getFacebookJS() { # Add a timestamp to the FBJS file so Facebook cache wont ignore our changes -- cgit v1.2.3-54-g00ecf From 5f2fce04cb7726f44b797908b073e22e399b8be2 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 19 Jan 2009 01:59:31 +0000 Subject: trac750 Updated paths for new css files; deleted old unused css file --- lib/facebookutil.php | 8 +- theme/identica/facebookapp.css | 161 ----------------------------------------- 2 files changed, 4 insertions(+), 165 deletions(-) delete mode 100644 theme/identica/facebookapp.css (limited to 'lib/facebookutil.php') diff --git a/lib/facebookutil.php b/lib/facebookutil.php index 0bde68c0f..cc4941bdc 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -110,16 +110,16 @@ function update_profile_box($facebook, $fbuid, $user, $notice) function getFacebookBaseCSS() { # Add a timestamp to the CSS file so Facebook cache wont ignore our changes - $ts = filemtime(theme_file('facebookapp_base.css')); - $cssurl = theme_path('facebookapp_base.css') . "?ts=$ts"; + $ts = filemtime(INSTALLDIR.'/theme/base/css/facebookapp.base.css'); + $cssurl = INSTALLDIR.'/theme/base/css/facebookapp.base.css' . "?ts=$ts"; return $cssurl; } function getFacebookThemeCSS() { # Add a timestamp to the CSS file so Facebook cache wont ignore our changes - $ts = filemtime(theme_file('facebookapp_theme.css')); - $cssurl = theme_path('facebookapp_theme.css') . "?ts=$ts"; + $ts = filemtime(theme_file('css/facebookapp.theme.css')); + $cssurl = theme_path('css/facebookapp.theme.css') . "?ts=$ts"; return $cssurl; } diff --git a/theme/identica/facebookapp.css b/theme/identica/facebookapp.css deleted file mode 100644 index b2bbbac51..000000000 --- a/theme/identica/facebookapp.css +++ /dev/null @@ -1,161 +0,0 @@ - -/* XXX: Most of this just copied out of display.css -- need to factor out what we really neeed -- Zach */ - -body { - color: #193441; -} - -a { -color: #d1451a; -text-decoration: none; -} -a:hover { -text-decoration: underline; -} -img, img a { -border: 0; -} -h1 { -font-size: 14px; -} - -#wrap { -margin: 0 auto; -padding: 0 20px; -width: 760px; -background: url(bg-header.gif) repeat-x #fbf2d7; -} - - -#notices { -clear: both; -margin: 0 auto; -padding: 0; -list-style-type: none; -width: 600px; -border-top: 1px solid #dec5b5; -} -#notices a:hover { -text-decoration: underline; -} -.notice_single { -clear: both; -display: block; -margin: 0; -padding: 5px 5px 5px 0; -min-height: 48px; -font-family: Georgia, "Times New Roman", Times, serif; -font-size: 13px; -line-height: 16px; -border-bottom: 1px solid #dec5b5; -background-color:#FCFFF5; -opacity:1; -} -.notice_single:hover { -background-color: #f7ebcc; -} -.notice_single p { -display: inline; -margin: 0; -padding: 0; -} -#notice_delete_form #confirmation_text { - display: block; -font-size: 14px; -font-weight: bold; -} - -input#submit_yes, input#submit_no { -margin: 18px 10px 0px 0px; -padding: 4px; -font-weight: bold; -color: #fff6d5; -background-color: #F60; -cursor: pointer; -border: 0; -width: 40px; -} -input#submit_yes:hover, input#submit_no:hover { -background-color: #701238; -} -.avatar.stream { -float: left; -margin: 0 10px 0.5em 0; -} -p.time { -display: block; -font-family: Verdana, Arial, Helvetica, sans-serif; -font-size: 10px; -line-height: 15px; -} -p.time a { -color: #dab134; -} - - -/* ----- Forms General Style ----- */ -form { - margin: 0 auto; - padding: 0; - } -form { - font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: 12px; - } -form label { - display: block; - font-size: 12px; - font-weight: bold; - line-height: 18px; - } -form input { - border: 1px solid #dec5b5; - width: 264px; - } -input#submit, input.submit { - display: block; - margin: 18px 0; - padding: 4px; - font-weight: bold; - color: #fff6d5; - background-color: #F60; - cursor: pointer; - border: 0; - width: auto; - } -input#submit:hover, input.submit:hover { - background-color: #701238; - } -input.checkbox { - /*width: 14px; - height: 14px;*/ - width: auto; - border: 0; - } - -label.checkbox_label { - display: inline; - font-weight: normal; -} - -textarea, input { - font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: 12px; - color: #701238; - padding: 3px; - } -textarea:focus, input:focus { - background-color: #f8ebc0; - } -textarea { - width: 270px; - border: 1px solid #D8E2D7; - } -.input_instructions { - margin-top: 3px; - display: block; - font-size: 11px; - line-height: 15px; - color: #924959; - font-family: Verdana, Arial, Helvetica, sans-serif; - } -- 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 'lib/facebookutil.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