From ab158502b0257c3cd578395ed6f30510ea3c78db Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 14 Jan 2009 00:29:52 -0500 Subject: Move notice form to its own class --- lib/noticeform.php | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 lib/noticeform.php (limited to 'lib/noticeform.php') diff --git a/lib/noticeform.php b/lib/noticeform.php new file mode 100644 index 000000000..c22256874 --- /dev/null +++ b/lib/noticeform.php @@ -0,0 +1,144 @@ +. + * + * @category Form + * @package Laconica + * @author Evan Prodromou + * @author Sarven Capadisli + * @copyright 2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR.'/lib/widget.php'; + +/** + * Form for posting a notice + * + * Frequently-used form for posting a notice + * + * @category Form + * @package Laconica + * @author Evan Prodromou + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see HTMLOutputter + */ + +class NoticeForm extends Form +{ + /** + * Current action, used for returning to this page. + */ + + var $action = null; + + /** + * Pre-filled content of the form + */ + + var $content = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param string $action action to return to, if any + * @param string $content content to pre-fill + */ + + function __construct($out=null, $action=null, $content=null) + { + parent::__construct($out); + + $this->action = $action; + $this->content = $content; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'status_form'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('newnotice'); + } + + /** + * Data elements + * + * @return void + */ + + function formData() + { + $user = common_current_user(); + + $this->out->element('label', array('for' => 'status_textarea', + 'id' => 'status_label'), + sprintf(_('What\'s up, %s?'), $user->nickname)); + // XXX: vary by defined max size + $this->out->element('span', array('id' => 'counter', + 'class' => 'counter'), + '140'); + $this->out->element('textarea', array('id' => 'status_textarea', + 'cols' => 60, + 'rows' => 3, + 'name' => 'status_textarea'), + ($this->content) ? $this->content : ''); + if ($this->action) { + $this->out->hidden('returnto', $this->action); + } + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->element('input', array('id' => 'status_submit', + 'name' => 'status_submit', + 'type' => 'submit', + 'value' => _('Send'))); + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 73272e8ad306a37a2f954f0b757a444d1fc30432 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 14 Jan 2009 01:49:03 -0500 Subject: Fix require in noticeform.php so it gets the notice form --- lib/noticeform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/noticeform.php') diff --git a/lib/noticeform.php b/lib/noticeform.php index c22256874..0e46e0e58 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -32,7 +32,7 @@ if (!defined('LACONICA')) { exit(1); } -require_once INSTALLDIR.'/lib/widget.php'; +require_once INSTALLDIR.'/lib/form.php'; /** * Form for posting a notice -- cgit v1.2.3-54-g00ecf From 47f694582c8bb668ad711182bc7124fe2db0f339 Mon Sep 17 00:00:00 2001 From: sarven Date: Thu, 15 Jan 2009 03:32:07 +0000 Subject: Updated formData(), formActions(), show() Added formLegend() --- lib/form.php | 17 +++++++++++++++++ lib/noticeform.php | 53 +++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 58 insertions(+), 12 deletions(-) (limited to 'lib/noticeform.php') diff --git a/lib/form.php b/lib/form.php index ba1790faa..5c75bb65f 100644 --- a/lib/form.php +++ b/lib/form.php @@ -67,9 +67,12 @@ class Form extends Widget array('id' => $this->id(), 'method' => 'POST', 'action' => $this->action())); + $this->out->elementStart('fieldset'); + $this->formLegend(); $this->sessionToken(); $this->formData(); $this->formActions(); + $this->out->elementEnd('fieldset'); $this->out->elementEnd('form'); } @@ -84,6 +87,20 @@ class Form extends Widget $this->out->hidden('token', common_session_token()); } + + /** + * Name of the form + * + * Sub-classes should overload this with the name of their form. + * + * @return void + */ + + function formLegend() + { + } + + /** * Visible or invisible data elements * diff --git a/lib/noticeform.php b/lib/noticeform.php index 0e46e0e58..0a4f486db 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -87,7 +87,7 @@ class NoticeForm extends Form function id() { - return 'status_form'; + return 'form_notice'; } /** @@ -101,6 +101,18 @@ class NoticeForm extends Form return common_local_url('newnotice'); } + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Send a notice')); + } + + /** * Data elements * @@ -111,21 +123,33 @@ class NoticeForm extends Form { $user = common_current_user(); - $this->out->element('label', array('for' => 'status_textarea', - 'id' => 'status_label'), + $this->out->elementStart('ul', 'form_datas'); + $this->out->elementStart('li', array('id' => 'notice_text')); + $this->out->element('label', array('for' => 'notice_data-text'), sprintf(_('What\'s up, %s?'), $user->nickname)); // XXX: vary by defined max size - $this->out->element('span', array('id' => 'counter', - 'class' => 'counter'), - '140'); - $this->out->element('textarea', array('id' => 'status_textarea', - 'cols' => 60, - 'rows' => 3, + $this->out->element('textarea', array('id' => 'notice_data-text', + 'cols' => 35, + 'rows' => 4, 'name' => 'status_textarea'), ($this->content) ? $this->content : ''); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); + + $this->out->elementStart('dl', 'form_note'); + $this->out->element('dt', null, _('Available characters')); + $this->out->element('dd', array('id' => 'notice_text-count'), + '140'); + $this->out->elementEnd('dl'); + if ($this->action) { - $this->out->hidden('returnto', $this->action); + // FIXME: or VERIFY that notice_return-to doesn't break anything. Changed from 'returnto' + $this->out->hidden('notice_return-to', $this->action); } + + // FIXME: Does this need to be checked like returnto? + $this->out->hidden('notice_in-reply-to', $this->action); + } /** @@ -136,9 +160,14 @@ class NoticeForm extends Form function formActions() { - $this->out->element('input', array('id' => 'status_submit', + $this->out->elementStart('ul', 'form_actions'); + $this->out->elementStart('li', array('id' => 'notice_submit')); + $this->out->element('input', array('id' => 'notice_action-submit', + 'class' => 'submit', 'name' => 'status_submit', 'type' => 'submit', 'value' => _('Send'))); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); } -} \ No newline at end of file +} -- cgit v1.2.3-54-g00ecf From c6d22e4cea3c875fd5ea1e10483fc28060887b4b Mon Sep 17 00:00:00 2001 From: sarven Date: Thu, 15 Jan 2009 19:22:03 +0000 Subject: Extended formData()'s hidden to use a specific @id and @name --- lib/noticeform.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/noticeform.php') diff --git a/lib/noticeform.php b/lib/noticeform.php index 0a4f486db..9bc5e0d6a 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -143,12 +143,10 @@ class NoticeForm extends Form $this->out->elementEnd('dl'); if ($this->action) { - // FIXME: or VERIFY that notice_return-to doesn't break anything. Changed from 'returnto' - $this->out->hidden('notice_return-to', $this->action); + $this->out->hidden('notice_return-to', $this->action, 'returnto'); } - // FIXME: Does this need to be checked like returnto? - $this->out->hidden('notice_in-reply-to', $this->action); + $this->out->hidden('notice_in-reply-to', $this->action, 'inreplyto'); } -- cgit v1.2.3-54-g00ecf From 4a2aebe5cfab4a4b0388f98b296eac66be6e3396 Mon Sep 17 00:00:00 2001 From: sarven Date: Thu, 15 Jan 2009 19:24:07 +0000 Subject: Minor: Including formData()'s inreplyto in action check --- lib/noticeform.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/noticeform.php') diff --git a/lib/noticeform.php b/lib/noticeform.php index 9bc5e0d6a..84817639a 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -144,10 +144,8 @@ class NoticeForm extends Form if ($this->action) { $this->out->hidden('notice_return-to', $this->action, 'returnto'); + $this->out->hidden('notice_in-reply-to', $this->action, 'inreplyto'); } - - $this->out->hidden('notice_in-reply-to', $this->action, 'inreplyto'); - } /** -- cgit v1.2.3-54-g00ecf From 5a10287bc3e2ee2b2529bd95ce73d22e8c237e22 Mon Sep 17 00:00:00 2001 From: sarven Date: Sat, 17 Jan 2009 03:15:45 +0000 Subject: Minor --- lib/noticeform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/noticeform.php') diff --git a/lib/noticeform.php b/lib/noticeform.php index 84817639a..d6a3aa9c2 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -144,8 +144,8 @@ class NoticeForm extends Form if ($this->action) { $this->out->hidden('notice_return-to', $this->action, 'returnto'); - $this->out->hidden('notice_in-reply-to', $this->action, 'inreplyto'); } + $this->out->hidden('notice_in-reply-to', $this->action, 'inreplyto'); } /** -- cgit v1.2.3-54-g00ecf From 0b5f0f4faaf04fdf13dbd5dea1f081b9e1cc6071 Mon Sep 17 00:00:00 2001 From: sarven Date: Mon, 19 Jan 2009 03:09:13 +0000 Subject: Renamed form_datas to form_data --- actions/emailsettings.php | 4 ++-- actions/imsettings.php | 4 ++-- actions/login.php | 2 +- actions/openidsettings.php | 2 +- actions/othersettings.php | 2 +- actions/profilesettings.php | 2 +- actions/register.php | 2 +- actions/smssettings.php | 8 ++++---- actions/twittersettings.php | 4 ++-- lib/noticeform.php | 2 +- theme/base/css/display.css | 22 +++++++++++----------- 11 files changed, 27 insertions(+), 27 deletions(-) (limited to 'lib/noticeform.php') diff --git a/actions/emailsettings.php b/actions/emailsettings.php index 7ae62fb55..b84acb214 100644 --- a/actions/emailsettings.php +++ b/actions/emailsettings.php @@ -110,7 +110,7 @@ class EmailsettingsAction extends AccountSettingsAction $this->hidden('email', $confirm->address); $this->submit('cancel', _('Cancel')); } else { - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->input('email', _('Email Address'), ($this->arg('email')) ? $this->arg('email') : null, @@ -146,7 +146,7 @@ class EmailsettingsAction extends AccountSettingsAction $this->elementStart('fieldset', array('id' => 'settings_email_preferences')); $this->element('legend', null, _('Preferences')); - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->checkbox('emailnotifysub', _('Send me notices of new subscriptions through email.'), diff --git a/actions/imsettings.php b/actions/imsettings.php index edbd81b57..e0f5ede3a 100644 --- a/actions/imsettings.php +++ b/actions/imsettings.php @@ -113,7 +113,7 @@ class ImsettingsAction extends ConnectSettingsAction $this->hidden('jabber', $confirm->address); $this->submit('cancel', _('Cancel')); } else { - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->input('jabber', _('IM Address'), ($this->arg('jabber')) ? $this->arg('jabber') : null, @@ -131,7 +131,7 @@ class ImsettingsAction extends ConnectSettingsAction $this->elementStart('fieldset', array('id' => 'settings_im_preferences')); $this->element('legend', null, _('Preferences')); - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->checkbox('jabbernotify', _('Send me notices through Jabber/GTalk.'), diff --git a/actions/login.php b/actions/login.php index 9fa501a5d..11cf1f02a 100644 --- a/actions/login.php +++ b/actions/login.php @@ -223,7 +223,7 @@ class LoginAction extends Action 'action' => common_local_url('login'))); $this->elementStart('fieldset'); $this->element('legend', null, _('Login to site')); - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->input('nickname', _('Nickname')); $this->elementEnd('li'); diff --git a/actions/openidsettings.php b/actions/openidsettings.php index 126d2c992..92469d20f 100644 --- a/actions/openidsettings.php +++ b/actions/openidsettings.php @@ -95,7 +95,7 @@ class OpenidsettingsAction extends AccountSettingsAction $this->element('p', 'form_guide', _('If you want to add an OpenID to your account, ' . 'enter it in the box below and click "Add".')); - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->element('label', array('for' => 'openid_url'), _('OpenID URL')); diff --git a/actions/othersettings.php b/actions/othersettings.php index cbb2c0cb9..b542233ca 100644 --- a/actions/othersettings.php +++ b/actions/othersettings.php @@ -107,7 +107,7 @@ class OthersettingsAction extends AccountSettingsAction 'metamark.net' => 'metamark.net' ); - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->dropdown('urlshorteningservice', _('Service'), $services, _('Automatic shortening service to use.'), diff --git a/actions/profilesettings.php b/actions/profilesettings.php index 12251b83b..6dd4775e5 100644 --- a/actions/profilesettings.php +++ b/actions/profilesettings.php @@ -93,7 +93,7 @@ class ProfilesettingsAction extends AccountSettingsAction # too much common patterns here... abstractable? - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->input('nickname', _('Nickname'), ($this->arg('nickname')) ? $this->arg('nickname') : $profile->nickname, diff --git a/actions/register.php b/actions/register.php index 08243c1e2..159daaa73 100644 --- a/actions/register.php +++ b/actions/register.php @@ -343,7 +343,7 @@ class RegisterAction extends Action $this->hidden('code', $code); } - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->input('nickname', _('Nickname'), $this->trimmed('nickname'), _('1-64 lowercase letters or numbers, '. diff --git a/actions/smssettings.php b/actions/smssettings.php index 489fd1f58..f89cbe1ab 100644 --- a/actions/smssettings.php +++ b/actions/smssettings.php @@ -113,7 +113,7 @@ class SmssettingsAction extends ConnectSettingsAction $this->hidden('carrier', $confirm->address_extra); $this->submit('cancel', _('Cancel')); - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->input('code', _('Confirmation code'), null, _('Enter the code you received on your phone.')); @@ -121,7 +121,7 @@ class SmssettingsAction extends ConnectSettingsAction $this->elementEnd('ul'); $this->submit('confirm', _('Confirm')); } else { - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->input('sms', _('SMS Phone number'), ($this->arg('sms')) ? $this->arg('sms') : null, @@ -156,7 +156,7 @@ class SmssettingsAction extends ConnectSettingsAction $this->elementStart('fieldset', array('id' => 'settings_sms_preferences')); $this->element('legend', null, _('Preferences')); - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->checkbox('smsnotify', _('Send me notices through SMS; '. @@ -448,7 +448,7 @@ class SmssettingsAction extends ConnectSettingsAction $cnt = $carrier->find(); - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->element('label', array('for' => 'carrier'), _('Mobile carrier')); $this->elementStart('select', array('name' => 'carrier', diff --git a/actions/twittersettings.php b/actions/twittersettings.php index 079099123..efc8215cd 100644 --- a/actions/twittersettings.php +++ b/actions/twittersettings.php @@ -104,7 +104,7 @@ class TwittersettingsAction extends ConnectSettingsAction $this->elementStart('fieldset', array('id' => 'settings_twitter_account')); $this->element('legend', null, _('Twitter Account')); $this->hidden('token', common_session_token()); - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); if ($fuser) { $this->elementStart('li'); $this->element('span', 'twitter_user', $fuser->nickname); @@ -133,7 +133,7 @@ class TwittersettingsAction extends ConnectSettingsAction array('id' => 'settings_twitter_preferences')); $this->element('legend', null, _('Preferences')); - $this->elementStart('ul', 'form_datas'); + $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->checkbox('noticesync', _('Automatically send my notices to Twitter.'), diff --git a/lib/noticeform.php b/lib/noticeform.php index d6a3aa9c2..f0205f1c1 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -123,7 +123,7 @@ class NoticeForm extends Form { $user = common_current_user(); - $this->out->elementStart('ul', 'form_datas'); + $this->out->elementStart('ul', 'form_data'); $this->out->elementStart('li', array('id' => 'notice_text')); $this->out->element('label', array('for' => 'notice_data-text'), sprintf(_('What\'s up, %s?'), $user->nickname)); diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 716f3256f..d659a4b4c 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -114,17 +114,17 @@ font-style:italic; } -.form_settings .form_datas li { +.form_settings .form_data li { width:100%; float:left; } -.form_settings .form_datas label { +.form_settings .form_data label { float:left; } -.form_settings .form_datas textarea, -.form_settings .form_datas select, -.form_settings .form_datas input { +.form_settings .form_data textarea, +.form_settings .form_data select, +.form_settings .form_data input { margin-left:11px; float:left; } @@ -149,7 +149,7 @@ font-weight:bold; display:none; } -.form_settings .form_datas p.form_guide { +.form_settings .form_data p.form_guide { clear:both; margin-left:163px; margin-bottom:0; @@ -424,7 +424,7 @@ display:block; font-size:1.3em; margin-bottom:7px; } -#form_notice .form_datas li { +#form_notice .form_data li { float:left; } @@ -979,12 +979,12 @@ background-color:#D1D9E4; #user_actions #user_subscribe .form_note, -#user_actions #user_subscribe .form_datas, +#user_actions #user_subscribe .form_data, #user_actions #user_subscribe .form_actions label { display:none; } #form_user-relationship .form_note, -#form_user-relationship .form_datas, +#form_user-relationship .form_data, #form_user-relationship .form_actions label { display:block; } @@ -992,7 +992,7 @@ display:block; #user_actions #user-relationship_submit { margin-bottom:0; } -#form_user-relationship .form_datas li label { +#form_user-relationship .form_data li label { margin-right:11px; } @@ -1070,7 +1070,7 @@ font-size:2.2em; -#form_settings_photo .form_datas { +#form_settings_photo .form_data { clear:both; } -- cgit v1.2.3-54-g00ecf From adf77944e84a1d08bcc3d2a89533dff5bc58f3e3 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 23 Jan 2009 03:16:03 +0000 Subject: trac750 Facebook app proper integrated into new uiredesign --- actions/facebookhome.php | 226 +++++++++++-------- actions/facebookinvite.php | 75 ++++--- actions/facebooksettings.php | 97 +++++--- lib/facebookaction.php | 521 +++++++++++++++++++++++++++++++++---------- lib/facebookutil.php | 209 ----------------- lib/noticeform.php | 18 +- 6 files changed, 662 insertions(+), 484 deletions(-) (limited to 'lib/noticeform.php') 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(''); + $content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) . + htmlentities(''); $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'); } } diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 6d42596e8..dcd4e33d0 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -1,106 +1,191 @@ . + * along with this program. If not, see . + * + * @category Faceboook + * @package Laconica + * @author Zach Copley + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { +if (!defined('LACONICA')) +{ exit(1); } require_once INSTALLDIR.'/lib/facebookutil.php'; +require_once INSTALLDIR.'/lib/noticeform.php'; + class FacebookAction extends Action { + + var $facebook = null; + var $fbuid = null; + var $flink = null; + var $action = null; + var $app_uri = null; + var $app_name = null; + + function prepare($argarray) + { + parent::prepare($argarray); + + common_debug("Facebookaction::prepare"); + + $this->facebook = get_facebook(); + $this->fbuid = $this->facebook->require_login(); + + $this->action = $this->trimmed('action'); + + $app_props = $this->facebook->api_client->Admin_getAppProperties( + array('canvas_name', 'application_name')); + + $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name']; + $this->app_name = $app_props['application_name']; + + $this->flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); + + return true; + + } + + function showStylesheets() + { + + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => getFacebookBaseCSS())); - function handle($args) + $this->element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => getFacebookThemeCSS())); + } + + function showScripts() { - parent::handle($args); + $this->element('script', array('type' => 'text/javascript', + 'src' => getFacebookJS()), + ' '); + } + + /** + * Start an Facebook ready HTML document + * + * For Facebook we don't want to actually output any headers, + * DTD info, etc. + * + * If $type isn't specified, will attempt to do content negotiation. + * + * @param string $type MIME type to use; default is to do negotation. + * + * @return void + */ + + function startHTML($type=null) + { + $this->elementStart('div', array('class' => 'facebook-page')); } - function showLogo(){ - - global $xw; - - $this->showStylesheets(); - $this->showScripts(); - - $this->elementStart('a', array('class' => 'url home bookmark', - 'href' => common_local_url('public'))); - if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) { - $this->element('img', array('class' => 'logo photo', - 'src' => (common_config('site', 'logo')) ? - common_config('site', 'logo') : theme_path('logo.png'), - 'alt' => common_config('site', 'name'))); - } + /** + * Ends a Facebook ready HTML document + * + * @return void + */ + function endHTML() + { + $this->elementEnd('div'); + $this->endXML(); + } - $this->element('span', array('class' => 'fn org'), common_config('site', 'name')); - $this->elementEnd('a'); + /** + * Show notice form. + * + * MAY overload if no notice form needed... or direct message box???? + * + * @return nothing + */ + function showNoticeForm() + { + // don't do it for most of the Facebook pages + } + function showBody() + { + $this->elementStart('div', 'wrap'); + $this->showHeader(); + $this->showCore(); + $this->showFooter(); + $this->elementEnd('div'); + } + + function showAside() + { } - function showHeader($msg = null, $success = false) + function showHead($error, $success) { - startFBML(); + $this->showStylesheets(); + $this->showScripts(); + + if ($error) { + $this->element("h1", null, $error); + } + + if ($success) { + $this->element("h1", null, $success); + } $this->elementStart('fb:if-section-not-added', array('section' => 'profile')); $this->elementStart('span', array('id' => 'add_to_profile')); $this->element('fb:add-section-button', array('section' => 'profile')); $this->elementEnd('span'); $this->elementEnd('fb:if-section-not-added'); - - $this->showLogo(); - - if ($msg) { - if ($success) { - $this->element('fb:success', array('message' => $msg)); - } else { - // XXX do an error message here - } - } - - $this->elementStart('div', 'main_body'); - + } - function showNav($selected = 'Home') + + // Make this into a widget later + function showLocalNav() { - - $this->elementStart('dl', array("id" => 'site_nav_local_views')); - $this->element('dt', null, _('Local Views')); - $this->elementStart('dd'); - + $this->elementStart('ul', array('class' => 'nav')); $this->elementStart('li', array('class' => - ($selected == 'Home') ? 'current' : 'facebook_home')); + ($this->action == 'facebookhome') ? 'current' : 'facebook_home')); $this->element('a', array('href' => 'index.php', 'title' => _('Home')), _('Home')); $this->elementEnd('li'); $this->elementStart('li', array('class' => - ($selected == 'Invite') ? 'current' : 'facebook_invite')); + ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite')); $this->element('a', array('href' => 'invite.php', 'title' => _('Invite')), _('Invite')); $this->elementEnd('li'); $this->elementStart('li', array('class' => - ($selected == 'Settings') ? 'current' : 'facebook_settings')); + ($this->action == 'facebooksettings') ? 'current' : 'facebook_settings')); $this->element('a', array('href' => 'settings.php', 'title' => _('Settings')), _('Settings')); @@ -108,16 +193,47 @@ class FacebookAction extends Action $this->elementEnd('ul'); - $this->elementEnd('dd'); - $this->elementEnd('dl'); + } + /** + * Show primary navigation. + * + * @return nothing + */ + function showPrimaryNav() + { + // we don't want to show anything for this } - - function showFooter() + + /** + * Show header of the page. + * + * Calls template methods + * + * @return nothing + */ + function showHeader() { + $this->elementStart('div', array('id' => 'header')); + $this->showLogo(); + $this->showNoticeForm(); + $this->showPrimaryNav(); $this->elementEnd('div'); - $this->endXml(); } + + /** + * Show page, a template method. + * + * @return nothing + */ + function showPage($error = null, $success = null) + { + $this->startHTML(); + $this->showHead($error, $success); + $this->showBody(); + $this->endHTML(); + } + function showInstructions() { @@ -141,36 +257,9 @@ class FacebookAction extends Action $this->elementEnd('dl'); } - function showStylesheets() - { - global $xw; - - $this->element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => getFacebookBaseCSS())); - - $this->element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => getFacebookThemeCSS())); - } - - function showScripts() - { - global $xw; - - $this->element('script', array('type' => 'text/javascript', - 'src' => getFacebookJS())); - - } function showLoginForm($msg = null) { - startFBML(); - - $this->showStylesheets(); - $this->showScripts(); - - $this->showLogo(); $this->elementStart('div', array('class' => 'content')); $this->element('h1', null, _('Login')); @@ -210,57 +299,251 @@ class FacebookAction extends Action $this->elementEnd('div'); - $this->endXml(); + } + + + function updateProfileBox($notice) + { + // Need to include inline CSS for styling the Profile box + + $style = ''; + + $this->xw->openMemory(); + + $item = new FacebookNoticeListItem($notice, $this); + $item->show(); + + $fbml = "$style " . $this->xw->outputMemory(false) . ""; + $fbml .= "$style " . $this->xw->outputMemory(false) . ""; + + $fbml_main = "$style " . $this->xw->outputMemory(false) . ""; + + $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main); + + $this->xw->openURI('php://output'); } + + + /** + * 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 + 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' => "$this->app_uri/$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' => "$this->app_uri/$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'); + } + } + - function showNoticeForm($user) +} + +class FacebookNoticeForm extends NoticeForm +{ + + var $post_action = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param string $action action to return to, if any + * @param string $content content to pre-fill + */ + + function __construct($out=null, $action=null, $content=null, + $post_action=null, $user=null) { + parent::__construct($out, $action, $content, $user); + $this->post_action = $post_action; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return $this->post_action; + } - global $xw; +} - $this->elementStart('form', array('id' => 'form_notice', - 'method' => 'post', - 'action' => 'index.php')); +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() + { + $this->out->elementStart('div', array('id' =>'notices_primary')); + $this->out->element('h2', null, _('Notices')); + $this->out->elementStart('ul', array('class' => 'notices')); - $this->elementStart('fieldset'); - $this->element('legend', null, 'Send a notice'); + $cnt = 0; - $this->elementStart('ul', 'form_datas'); - $this->elementStart('li', array('id' => 'noticcommon_elemente_text')); - $this->element('label', array('for' => 'notice_data-text'), - sprintf(_('What\'s up, %s?'), $user->nickname)); + while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) { + $cnt++; - $this->element('textarea', array('id' => 'notice_data-text', - 'cols' => 35, - 'rows' => 4, - 'name' => 'status_textarea')); - $this->elementEnd('li'); - $this->elementEnd('ul'); + if ($cnt > NOTICES_PER_PAGE) { + break; + } - $this->elementStart('dl', 'form_note'); - $this->element('dt', null, _('Available characters')); - $this->element('dd', array('id' => 'notice_text-count'), - '140'); - $this->elementEnd('dl'); + $item = $this->newListItem($this->notice); + $item->show(); + } + + $this->out->elementEnd('ul'); + $this->out->elementEnd('div'); + + return $cnt; + } - $this->elementStart('ul', array('class' => 'form_actions')); + /** + * 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, $this); + } - $this->elementStart('li', array('id' => 'notice_submit')); +} - $this->submit('submit', _('Send')); +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(); - /* - $this->element('input', array('id' => 'notice_action-submit', - 'class' => 'submit', - 'name' => 'status_submit', - 'type' => 'submit', - 'value' => _('Send'))); - */ - $this->elementEnd('li'); - $this->elementEnd('ul'); - $this->elementEnd('fieldset'); - $this->elementEnd('form'); + $this->out->elementStart('div', 'entry-title'); + $this->showAuthor(); + $this->showContent(); + $this->out->elementEnd('div'); + + $this->out->elementStart('div', 'entry-content'); + $this->showNoticeLink(); + $this->showNoticeSource(); + $this->showReplyTo(); + $this->out->elementEnd('div'); + + $this->showEnd(); + } + + 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; + } + + $this->out->elementStart('dl', 'timestamp'); + $this->out->element('dt', null, _('Published')); + $this->out->elementStart('dd', null); + $this->out->elementStart('a', array('rel' => 'bookmark', + 'href' => $noticeurl)); + $dt = common_date_iso8601($this->notice->created); + $this->out->element('abbr', array('class' => 'published', + 'title' => $dt), + common_date_string($this->notice->created)); + $this->out->elementEnd('a'); + $this->out->elementEnd('dd'); + $this->out->elementEnd('dl'); } } diff --git a/lib/facebookutil.php b/lib/facebookutil.php index a133ce8ba..7b3fd7b49 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -52,61 +52,6 @@ function startFBML($indent = true) $xw->setIndent($indent); } -function update_profile_box($facebook, $fbuid, $user, $notice) -{ - - // Need to include inline CSS for styling the Profile box - - $style = ''; - - global $xw; - $xw = new XMLWriter(); - $xw->openMemory(); - - $item = new FacebookNoticeListItem($notice); - $item->show(); - - $fbml = "$style " . $xw->outputMemory(false) . ""; - $fbml .= "$style " . $xw->outputMemory(false) . ""; - - $fbml_main = "$style " . $xw->outputMemory(false) . ""; - - $facebook->api_client->profile_setFBML(null, $fbuid, $fbml, null, null, $fbml_main); -} - function getFacebookBaseCSS() { # Add a timestamp to the CSS file so Facebook cache wont ignore our changes @@ -131,157 +76,3 @@ function getFacebookJS() { return $jsurl; } - -// 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 -{ - /** - * 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'); - } - -} - diff --git a/lib/noticeform.php b/lib/noticeform.php index f0205f1c1..0c991c969 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -63,6 +63,12 @@ class NoticeForm extends Form var $content = null; + /** + * The current user + */ + + var $user = null; + /** * Constructor * @@ -71,12 +77,19 @@ class NoticeForm extends Form * @param string $content content to pre-fill */ - function __construct($out=null, $action=null, $content=null) + function __construct($out=null, $action=null, $content=null, $user=null) { parent::__construct($out); $this->action = $action; $this->content = $content; + + if ($user) { + $this->user = $user; + } else { + $this->user = common_current_user(); + } + } /** @@ -121,12 +134,11 @@ class NoticeForm extends Form function formData() { - $user = common_current_user(); $this->out->elementStart('ul', 'form_data'); $this->out->elementStart('li', array('id' => 'notice_text')); $this->out->element('label', array('for' => 'notice_data-text'), - sprintf(_('What\'s up, %s?'), $user->nickname)); + sprintf(_('What\'s up, %s?'), $this->user->nickname)); // XXX: vary by defined max size $this->out->element('textarea', array('id' => 'notice_data-text', 'cols' => 35, -- cgit v1.2.3-54-g00ecf