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 --- lib/facebookaction.php | 521 ++++++++++++++++++++++++++++++++++++++----------- lib/facebookutil.php | 209 -------------------- lib/noticeform.php | 18 +- 3 files changed, 417 insertions(+), 331 deletions(-) (limited to 'lib') 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