-
- global $xw;
-
- common_element_start('form', array('id' => 'form_notice',
- 'method' => 'post',
- 'action' => 'index.php'));
-
- common_element_start('fieldset');
- common_element('legend', null, 'Send a notice');
-
- common_element_start('ul', 'form_datas');
- common_element_start('li', array('id' => 'noticcommon_elemente_text'));
- common_element('label', array('for' => 'notice_data-text'),
- sprintf(_('What\'s up, %s?'), $user->nickname));
-
- common_element('textarea', array('id' => 'notice_data-text',
- 'cols' => 35,
- 'rows' => 4,
- 'name' => 'status_textarea'));
- common_element_end('li');
- common_element_end('ul');
-
- common_element_start('dl', 'form_note');
- common_element('dt', null, _('Available characters'));
- common_element('dd', array('id' => 'notice_text-count'),
- '140');
- common_element_end('dl');
-
- common_element_start('ul', array('class' => 'form_actions'));
-
- common_element_start('li', array('id' => 'notice_submit'));
-
- common_submit('submit', _('Send'));
-
- /*
- common_element('input', array('id' => 'notice_action-submit',
- 'class' => 'submit',
- 'name' => 'status_submit',
- 'type' => 'submit',
- 'value' => _('Send')));
- */
- common_element_end('li');
- common_element_end('ul');
- common_element_end('fieldset');
- common_element_end('form');
+
+ $user = $this->flink->getUser();
+
+ $content = $this->trimmed('status_textarea');
+
+ if (!$content) {
+ $this->showPage(_('No notice content!'));
+ return;
+ } else {
+ $content_shortened = common_shorten_links($content);
+
+ if (mb_strlen($content_shortened) > 140) {
+ $this->showPage(_('That\'s too long. Max notice size is 140 chars.'));
+ return;
+ }
+ }
+
+ $inter = new CommandInterpreter();
+
+ $cmd = $inter->handle_command($user, $content_shortened);
+
+ if ($cmd) {
+
+ // XXX fix this
+
+ $cmd->execute(new WebChannel());
+ return;
+ }
+
+ $replyto = $this->trimmed('inreplyto');
+
+ $notice = Notice::saveNew($user->id, $content,
+ 'web', 1, ($replyto == 'false') ? null : $replyto);
+
+ if (is_string($notice)) {
+ $this->showPage($notice);
+ return;
+ }
+
+ common_broadcast_notice($notice);
+
+ // Also update the user's Facebook status
+ facebookBroadcastNotice($notice);
+
+ }
+
+}
+
+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;
+ }
+
+}
+
+class FacebookNoticeList extends NoticeList
+{
+
+ /**
+ * constructor
+ *
+ * @param Notice $notice stream of notices from DB_DataObject
+ */
+
+ function __construct($notice, $out=null)
+ {
+ parent::__construct($notice, $out);
+ }
+
+ /**
+ * 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'));
+
+ $cnt = 0;
+
+ while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
+ $cnt++;
+
+ if ($cnt > NOTICES_PER_PAGE) {
+ break;
+ }
+
+ $item = $this->newListItem($this->notice);
+ $item->show();
+ }
+
+ $this->out->elementEnd('ul');
+ $this->out->elementEnd('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, $this);
+ }
+
+}
+
+class FacebookNoticeListItem extends NoticeListItem
+{
+
+ /**
+ * constructor
+ *
+ * Also initializes the profile attribute.
+ *
+ * @param Notice $notice The notice we'll display
+ */
+
+ function __construct($notice, $out=null)
+ {
+ parent::__construct($notice, $out);
+ }
+
+ /**
+ * 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->showNotice();
+ $this->showNoticeInfo();
+
+ // XXX: Need to update to show attachements and controls
+
+ $this->showEnd();
+ }
+
+}
+
+class FacebookProfileBoxNotice extends FacebookNoticeListItem
+{
+
+ /**
+ * constructor
+ *
+ * Also initializes the profile attribute.
+ *
+ * @param Notice $notice The notice we'll display
+ */
+
+ function __construct($notice, $out=null)
+ {
+ parent::__construct($notice, $out);
+ }
+
+ /**
+ * Recipe function for displaying a single notice in the
+ * Facebook App profile notice box
+ *
+ * @return void
+ */
+
+ function show()
+ {
+ $this->showNotice();
+ $this->showNoticeInfo();
+ $this->showAppLink();
+ }
+
+ function showAppLink()
+ {
+
+ $this->facebook = getFacebook();
+
+ $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->out->elementStart('a', array('id' => 'facebook_statusnet_app',
+ 'href' => $this->app_uri));
+ $this->out->text($this->app_name);
+ $this->out->elementEnd('a');