diff options
author | Zach Copley <zach@controlyourself.ca> | 2009-01-18 01:31:39 +0000 |
---|---|---|
committer | Zach Copley <zach@controlyourself.ca> | 2009-01-18 01:31:39 +0000 |
commit | 3e18c2f0f8bbab01e16f66254dc9eadc9e1ffd60 (patch) | |
tree | fa42e4e9175f6003b7d57ba64dadeaf1986b412e /lib | |
parent | 2c9759c3b329eff455b3998d748292d581635f90 (diff) |
trac750 Facebook App - generate HTML similar to uiredisign for everything
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facebookaction.php | 145 | ||||
-rw-r--r-- | lib/facebookutil.php | 133 |
2 files changed, 236 insertions, 42 deletions
diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 3a00c71dd..1bf026281 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -17,9 +17,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('LACONICA')) { + exit(1); +} -require_once(INSTALLDIR.'/lib/facebookutil.php'); +require_once INSTALLDIR.'/lib/facebookutil.php'; class FacebookAction extends Action { @@ -29,32 +31,67 @@ class FacebookAction extends Action parent::handle($args); } - function show_header($selected = 'Home', $msg = null, $success = false) + function showLogo(){ + + global $xw; + + common_element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => get_facebook_css())); + + common_element_start('a', array('class' => 'url home bookmark', + 'href' => common_local_url('public'))); + if (common_config('site', 'logo') || file_exists(theme_file('logo.png'))) { + common_element('img', array('class' => 'logo photo', + 'src' => (common_config('site', 'logo')) ? + common_config('site', 'logo') : theme_path('logo.png'), + 'alt' => common_config('site', 'name'))); + } + + common_element('span', array('class' => 'fn org'), common_config('site', 'name')); + common_element_end('a'); + + } + + function showHeader($selected = 'Home', $msg = null, $success = false) { start_fbml(); - # Add a timestamp to the CSS file so Facebook cache wont ignore our changes - $ts = filemtime(theme_file('facebookapp.css')); - $cssurl = theme_path('facebookapp.css') . "?ts=$ts"; + $this->showLogo(); - common_element('link', array('rel' => 'stylesheet', - 'type' => 'text/css', - 'href' => $cssurl)); + common_element_start('dl', array("id" => 'site_nav_local_views')); + common_element('dt', null, _('Local Views')); + common_element_start('dd'); + + common_element_start('ul', array('class' => 'nav')); + + common_element_start('li', array('class' => + ($selected == 'Home') ? 'current' : 'facebook_home')); + common_element('a', + array('href' => 'index.php', 'title' => _('Home')), _('Home')); + common_element_end('li'); - common_element('fb:dashboard'); + + common_element_start('li', + array('class' => + ($selected == 'Invite') ? 'current' : 'facebook_invite')); + common_element('a', + array('href' => 'invite.php', 'title' => _('Invite')), _('Invite')); + common_element_end('li'); - common_element_start('fb:tabs'); - common_element('fb:tab-item', array('title' => 'Home', - 'href' => 'index.php', - 'selected' => ($selected == 'Home'))); - common_element('fb:tab-item', array('title' => 'Invite', - 'href' => 'invite.php', - 'selected' => ($selected == 'Invite'))); - common_element('fb:tab-item', array('title' => 'Settings', - 'href' => 'settings.php', - 'selected' => ($selected == 'Settings'))); - common_element_end('fb:tabs'); + common_element_start('li', + array('class' => + ($selected == 'Settings') ? 'current' : 'facebook_settings')); + common_element('a', + array('href' => 'settings.php', + 'title' => _('Settings')), _('Settings')); + common_element_end('li'); + + common_element_end('ul'); + + common_element_end('dd'); + common_element_end('dl'); if ($msg) { @@ -69,44 +106,73 @@ class FacebookAction extends Action } - function show_footer() + function showFooter() { common_element_end('div'); common_end_xml(); } + + function showInstructions() + { + global $xw; + + common_element_start('dl', array('class' => 'system_notice')); + common_element('dt', null, 'Page Notice'); + + $loginmsg_part1 = _('To use the %s Facebook Application you need to login ' . + 'with your username and password. Don\'t have a username yet? '); + + $loginmsg_part2 = _(' a new account.'); + + common_element_start('dd'); + common_element_start('p'); + common_text(sprintf($loginmsg_part1, common_config('site', 'name'))); + common_element('a', + array('href' => common_local_url('register')), _('Register')); + common_text($loginmsg_part2); + common_element_end('dd'); + common_element_end('dl'); + } + function showLoginForm($msg = null) { start_fbml(); - common_element_start('a', array('href' => 'http://identi.ca')); - common_element('img', array('src' => 'http://theme.identi.ca/identica/logo.png', - 'alt' => 'Identi.ca', - 'id' => 'logo')); - common_element_end('a'); + common_element('link', array('rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => get_facebook_css())); + + $this->showLogo(); + + common_element_start('div', array('class' => 'content')); + common_element('h1', null, _('Login')); + if ($msg) { common_element('fb:error', array('message' => $msg)); } + + $this->showInstructions(); - common_element("h2", null, - _('To add the Identi.ca application, you need to log into your Identi.ca account.')); - + common_element_start('div', array('id' => 'content_inner')); - common_element_start('div', array('class' => 'instructions')); - common_element_start('p'); - common_raw('Login with your username and password. Don\'t have a username yet?' - .' <a href="http://identi.ca/main/register">Register</a> a new account.'); - common_element_end('p'); - common_element_end('div'); - - common_element_start('div', array('id' => 'content')); common_element_start('form', array('method' => 'post', 'id' => 'login', 'action' => 'index.php')); + + common_element_start('fieldset'); + common_element('legend', null, _('Login to site')); + + common_element_start('ul', array('class' => 'form_datas')); + common_element_start('li'); common_input('nickname', _('Nickname')); + common_element_end('li'); + common_element_start('li'); common_password('password', _('Password')); - + common_element_end('li'); + common_element_end('ul'); + common_submit('submit', _('Login')); common_element_end('form'); @@ -114,6 +180,7 @@ class FacebookAction extends Action common_element('a', array('href' => common_local_url('recoverpassword')), _('Lost or forgotten password?')); common_element_end('p'); + common_element_end('div'); common_end_xml(); diff --git a/lib/facebookutil.php b/lib/facebookutil.php index 2529b8a4b..532e9c9d7 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -17,8 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -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 = "<fb:wide>$style " . $xw->outputMemory(false) . "</fb:wide>"; @@ -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'); + } + +} + |