summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-01-18 01:31:39 +0000
committerZach Copley <zach@controlyourself.ca>2009-01-18 01:31:39 +0000
commit3e18c2f0f8bbab01e16f66254dc9eadc9e1ffd60 (patch)
treefa42e4e9175f6003b7d57ba64dadeaf1986b412e
parent2c9759c3b329eff455b3998d748292d581635f90 (diff)
trac750 Facebook App - generate HTML similar to uiredisign for everything
-rw-r--r--actions/facebookhome.php10
-rw-r--r--actions/facebookinvite.php8
-rw-r--r--actions/facebooksettings.php14
-rw-r--r--lib/facebookaction.php145
-rw-r--r--lib/facebookutil.php133
5 files changed, 253 insertions, 57 deletions
diff --git a/actions/facebookhome.php b/actions/facebookhome.php
index b780b8cc3..46f886451 100644
--- a/actions/facebookhome.php
+++ b/actions/facebookhome.php
@@ -19,7 +19,7 @@
if (!defined('LACONICA')) { exit(1); }
-require_once(INSTALLDIR.'/lib/facebookaction.php');
+require_once INSTALLDIR.'/lib/facebookaction.php';
class FacebookhomeAction extends FacebookAction
{
@@ -35,6 +35,8 @@ class FacebookhomeAction extends FacebookAction
$flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
if ($flink) {
+ $user = $flink->getUser();
+ common_set_user($user);
$this->showHome($flink, null);
} else {
$this->login($fbuid);
@@ -103,7 +105,7 @@ class FacebookhomeAction extends FacebookAction
update_profile_box($facebook, $fbuid, $user, $notice);
- $this->show_header('Home');
+ $this->showHeader('Home');
if ($msg) {
common_element('fb:success', array('message' => $msg));
@@ -111,7 +113,7 @@ class FacebookhomeAction extends FacebookAction
echo $this->show_notices($user);
- $this->show_footer();
+ $this->showFooter();
}
function show_notices($user)
@@ -132,7 +134,7 @@ class FacebookhomeAction extends FacebookAction
function show_notice_list($notice)
{
- $nl = new NoticeList($notice);
+ $nl = new FacebookNoticeList($notice);
return $nl->show();
}
diff --git a/actions/facebookinvite.php b/actions/facebookinvite.php
index fe0c5e493..d7e82dae7 100644
--- a/actions/facebookinvite.php
+++ b/actions/facebookinvite.php
@@ -41,7 +41,7 @@ class FacebookinviteAction extends FacebookAction
$facebook = get_facebook();
$fbuid = $facebook->require_login();
- $this->show_header('Invite');
+ $this->showHeader('Invite');
common_element('h2', null, _('Thanks for inviting your friends to use Identi.ca!'));
common_element('p', null, _('Invitations have been sent to the following users:'));
@@ -60,7 +60,7 @@ class FacebookinviteAction extends FacebookAction
common_element_end("ul");
- $this->show_footer();
+ $this->showFooter();
}
function showInviteForm()
@@ -69,7 +69,7 @@ class FacebookinviteAction extends FacebookAction
$facebook = get_facebook();
$fbuid = $facebook->require_login();
- $this->show_header('Invite');
+ $this->showHeader('Invite');
// Get a list of users who are already using the app for exclusion
$exclude_ids = $facebook->api_client->friends_getAppUsers();
@@ -104,7 +104,7 @@ class FacebookinviteAction extends FacebookAction
common_element_end("ul");
- $this->show_footer();
+ $this->showFooter();
}
diff --git a/actions/facebooksettings.php b/actions/facebooksettings.php
index ab04ad82b..eafd91123 100644
--- a/actions/facebooksettings.php
+++ b/actions/facebooksettings.php
@@ -19,7 +19,7 @@
if (!defined('LACONICA')) { exit(1); }
-require_once(INSTALLDIR.'/lib/facebookaction.php');
+require_once INSTALLDIR.'/lib/facebookaction.php';
class FacebooksettingsAction extends FacebookAction
{
@@ -29,13 +29,13 @@ class FacebooksettingsAction extends FacebookAction
parent::handle($args);
if ($this->arg('save')) {
- $this->save_settings();
+ $this->saveSettings();
} else {
- $this->show_form();
+ $this->showForm();
}
}
- function save_settings() {
+ function saveSettings() {
$noticesync = $this->arg('noticesync');
$replysync = $this->arg('replysync');
@@ -59,14 +59,14 @@ class FacebooksettingsAction extends FacebookAction
}
}
- function show_form($msg = null, $success = false) {
+ function showForm($msg = null, $success = false) {
$facebook = get_facebook();
$fbuid = $facebook->require_login();
$flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
- $this->show_header('Settings', $msg, $success);
+ $this->showHeader('Settings', $msg, $success);
common_element_start('fb:if-section-not-added', array('section' => 'profile'));
common_element('h2', null, _('Add an Identi.ca box to my profile'));
@@ -108,7 +108,7 @@ class FacebooksettingsAction extends FacebookAction
}
- $this->show_footer();
+ $this->showFooter();
}
}
diff --git a/lib/facebookaction.php b/lib/facebookaction.php
index 3a00c71dd..1bf026281 100644
--- a/lib/facebookaction.php
+++ b/lib/facebookaction.php
@@ -17,9 +17,11 @@
* along with this program. If not, see <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');
+ }
+
+}
+