]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Facebook/facebookaction.php
FacebookPlugin: Fix up FBML canvas app so it keeps working after
[quix0rs-gnu-social.git] / plugins / Facebook / facebookaction.php
index c852bbf5e6e0a1540d423fe032d0ac0a8cf774a1..003bf8cd7e8e91a44b608c6800af407826808ddf 100644 (file)
@@ -32,11 +32,10 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
 }
 
 require_once INSTALLDIR . '/plugins/Facebook/facebookutil.php';
-require_once INSTALLDIR . '/lib/noticeform.php';
+require_once INSTALLDIR . '/plugins/Facebook/facebooknoticeform.php';
 
 class FacebookAction extends Action
 {
-
     var $facebook = null;
     var $fbuid    = null;
     var $flink    = null;
@@ -44,7 +43,7 @@ class FacebookAction extends Action
     var $app_uri  = null;
     var $app_name = null;
 
-    function __construct($output='php://output', $indent=true, $facebook=null, $flink=null)
+    function __construct($output='php://output', $indent=null, $facebook=null, $flink=null)
     {
         parent::__construct($output, $indent);
 
@@ -82,14 +81,25 @@ class FacebookAction extends Action
 
     function showStylesheets()
     {
+        // Loading CSS via files in Facebook FBML Canvas apps is still busted as of 1/31/11
+        // See: http://bugs.developers.facebook.net/show_bug.cgi?id=10052
         $this->cssLink('css/display.css', 'base');
         $this->cssLink('css/display.css', null, 'screen, projection, tv');
         $this->cssLink('plugins/Facebook/facebookapp.css');
+
+       // Also, Facebook refuses to let me do this... gar!
+/*
+       $baseCss = file_get_contents(INSTALLDIR . '/theme/base/css/display.css');
+       $this->style($baseCss);
+
+        $facebookCss = file_get_contents(INSTALLDIR . '/plugins/Facebook/facebookapp.css');
+        $this->style($facebookCss);
+*/
     }
 
     function showScripts()
     {
-        $this->script('js/facebookapp.js');
+        $this->script('plugins/Facebook/facebookapp.js');
     }
 
     /**
@@ -102,7 +112,6 @@ class FacebookAction extends Action
      *
      * @return void
      */
-
     function startHTML($type=null)
     {
         $this->showStylesheets();
@@ -143,7 +152,6 @@ class FacebookAction extends Action
 
     function showHead($error, $success)
     {
-
         if ($error) {
             $this->element("h1", null, $error);
         }
@@ -168,7 +176,10 @@ class FacebookAction extends Action
         $this->elementStart('li', array('class' =>
             ($this->action == 'facebookhome') ? 'current' : 'facebook_home'));
         $this->element('a',
-            array('href' => 'index.php', 'title' => _('Home')), _('Home'));
+            // TRANS: Link description for 'Home' link that leads to a start page.
+            array('href' => 'index.php', 'title' => _m('MENU','Home')),
+            // TRANS: Tooltip for 'Home' link that leads to a start page.
+            _m('Home'));
         $this->elementEnd('li');
 
         if (common_config('invite', 'enabled')) {
@@ -176,7 +187,10 @@ class FacebookAction extends Action
                 array('class' =>
                     ($this->action == 'facebookinvite') ? 'current' : 'facebook_invite'));
             $this->element('a',
-                array('href' => 'invite.php', 'title' => _('Invite')), _('Invite'));
+                // TRANS: Link description for 'Invite' link that leads to a page where friends can be invited.
+                array('href' => 'invite.php', 'title' => _m('MENU','Invite')),
+                // TRANS: Tooltip for 'Invite' link that leads to a page where friends can be invited.
+                _m('Invite'));
             $this->elementEnd('li');
         }
 
@@ -185,7 +199,10 @@ class FacebookAction extends Action
                 ($this->action == 'facebooksettings') ? 'current' : 'facebook_settings'));
         $this->element('a',
             array('href' => 'settings.php',
-                'title' => _('Settings')), _('Settings'));
+                // TRANS: Link description for 'Settings' link that leads to a page user preferences can be set.
+                'title' => _m('MENU','Settings')),
+                // TRANS: Tooltip for 'Settings' link that leads to a page user preferences can be set.
+                _m('Settings'));
         $this->elementEnd('li');
 
         $this->elementEnd('ul');
@@ -219,22 +236,22 @@ class FacebookAction extends Action
 
     function showInstructions()
     {
-
         $this->elementStart('div', array('class' => 'facebook_guide'));
 
         $this->elementStart('dl', array('class' => 'system_notice'));
         $this->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.');
+        $loginmsg_part1 = _m('To use the %s Facebook Application you need to login ' .
+            'with your username and password. Don\'t have a username yet?');
+        $loginmsg_part2 = _m(' a new account.');
 
         $this->elementStart('dd');
         $this->elementStart('p');
         $this->text(sprintf($loginmsg_part1, common_config('site', 'name')));
+        // @todo FIXME: Bad i18n. Patchwork message in two parts.
         $this->element('a',
-            array('href' => common_local_url('register')), _('Register'));
-        $this->text($loginmsg_part2);
+            array('href' => common_local_url('register')), _m('Register'));
+        $this->text( " " . $loginmsg_part2);
         $this->elementEnd('p');
         $this->elementEnd('dd');
 
@@ -246,7 +263,7 @@ class FacebookAction extends Action
     {
 
         $this->elementStart('div', array('id' => 'content'));
-        $this->element('h1', null, _('Login'));
+        $this->element('h1', null, _m('Login'));
 
         if ($msg) {
              $this->element('fb:error', array('message' => $msg));
@@ -265,106 +282,25 @@ class FacebookAction extends Action
 
         $this->elementStart('ul', array('class' => 'form_datas'));
         $this->elementStart('li');
-        $this->input('nickname', _('Nickname'));
+        $this->input('nickname', _m('Nickname'));
         $this->elementEnd('li');
         $this->elementStart('li');
-        $this->password('password', _('Password'));
+        $this->password('password', _m('Password'));
         $this->elementEnd('li');
         $this->elementEnd('ul');
 
-        $this->submit('submit', _('Login'));
+        // TRANS: Login button.
+        $this->submit('submit', _m('BUTTON','Login'));
         $this->elementEnd('fieldset');
         $this->elementEnd('form');
 
         $this->elementStart('p');
         $this->element('a', array('href' => common_local_url('recoverpassword')),
-                       _('Lost or forgotten password?'));
+                       _m('Lost or forgotten password?'));
         $this->elementEnd('p');
 
         $this->elementEnd('div');
         $this->elementEnd('div');
-
-    }
-
-    function updateProfileBox($notice)
-    {
-
-        // Need to include inline CSS for styling the Profile box
-
-        $app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url'));
-        $icon_url = $app_props['icon_url'];
-
-        $style = '<style>
-     .entry-title *,
-     .entry-content * {
-     font-size:14px;
-     font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
-     }
-     .entry-title a,
-     .entry-content a {
-     color:#002E6E;
-     }
-
-         .entry-title .vcard .photo {
-         float:left;
-         display:inline;
-     margin-right:11px;
-     margin-bottom:11px
-         }
-     .entry-title {
-     margin-bottom:11px;
-     }
-         .entry-title p.entry-content {
-         display:inline;
-     margin-left:5px;
-         }
-
-     div.entry-content {
-     clear:both;
-     }
-         div.entry-content dl,
-         div.entry-content dt,
-         div.entry-content dd {
-         display:inline;
-     text-transform:lowercase;
-         }
-
-         div.entry-content dd,
-     div.entry-content .device dt {
-     margin-left:0;
-     margin-right:5px;
-         }
-         div.entry-content dl.timestamp dt,
-     div.entry-content dl.response dt {
-         display:none;
-         }
-         div.entry-content dd a {
-         display:inline-block;
-         }
-
-     #facebook_statusnet_app {
-     text-indent:-9999px;
-     height:16px;
-     width:16px;
-     display:block;
-     background:url('.$icon_url.') no-repeat 0 0;
-     float:right;
-     }
-         </style>';
-
-        $this->xw->openMemory();
-
-        $item = new FacebookProfileBoxNotice($notice, $this);
-        $item->show();
-
-        $fbml = "<fb:wide>$style " . $this->xw->outputMemory(false) . "</fb:wide>";
-        $fbml .= "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
-
-        $fbml_main = "<fb:narrow>$style " . $this->xw->outputMemory(false) . "</fb:narrow>";
-
-        $this->facebook->api_client->profile_setFBML(null, $this->fbuid, $fbml, null, null, $fbml_main);
-
-        $this->xw->openURI('php://output');
     }
 
     /**
@@ -383,7 +319,7 @@ class FacebookAction extends Action
         // Does a little before-after block for next/prev page
         if ($have_before || $have_after) {
             $this->elementStart('dl', 'pagination');
-            $this->element('dt', null, _('Pagination'));
+            $this->element('dt', null, _m('Pagination'));
             $this->elementStart('dd', null);
             $this->elementStart('ul', array('class' => 'nav'));
         }
@@ -392,7 +328,7 @@ class FacebookAction extends Action
             $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'));
+                           _m('After'));
             $this->elementEnd('li');
         }
         if ($have_after) {
@@ -400,7 +336,7 @@ class FacebookAction extends Action
             $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'));
+                           _m('Before'));
             $this->elementEnd('li');
         }
         if ($have_before || $have_after) {
@@ -412,19 +348,19 @@ class FacebookAction extends Action
 
     function saveNewNotice()
     {
-
         $user = $this->flink->getUser();
 
         $content = $this->trimmed('status_textarea');
 
         if (!$content) {
-            $this->showPage(_('No notice content!'));
+            $this->showPage(_m('No notice content!'));
             return;
         } else {
-            $content_shortened = common_shorten_links($content);
+            $content_shortened = $user->shortenLinks($content);
 
             if (Notice::contentTooLong($content_shortened)) {
-                $this->showPage(sprintf(_('That\'s too long. Max notice size is %d chars.'),
+                // @todo FIXME: i18n: Needs plural.
+                $this->showPage(sprintf(_m('That\'s too long. Max notice size is %d chars.'),
                                         Notice::maxContent()));
                 return;
             }
@@ -435,9 +371,7 @@ class FacebookAction extends Action
         $cmd = $inter->handle_command($user, $content_shortened);
 
         if ($cmd) {
-
             // XXX fix this
-
             $cmd->execute(new WebChannel());
             return;
         }
@@ -445,58 +379,19 @@ class FacebookAction extends Action
         $replyto = $this->trimmed('inreplyto');
 
         try {
-            $notice = Notice::saveNew($user->id, $content,
-                                      'web', 1, ($replyto == 'false') ? null : $replyto);
+            $notice = Notice::saveNew($user->id, $content, 'web',
+                                      array('reply_to' => ($replyto == 'false') ? null : $replyto));
+
         } catch (Exception $e) {
             $this->showPage($e->getMessage());
             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
      *
@@ -516,11 +411,10 @@ class FacebookNoticeList extends NoticeList
      *
      * @return int count of notices listed.
      */
-
     function show()
     {
         $this->out->elementStart('div', array('id' =>'notices_primary'));
-        $this->out->element('h2', null, _('Notices'));
+        $this->out->element('h2', null, _m('Notices'));
         $this->out->elementStart('ul', array('class' => 'notices'));
 
         $cnt = 0;
@@ -552,17 +446,14 @@ class FacebookNoticeList extends NoticeList
      * @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
      *
@@ -570,7 +461,6 @@ class FacebookNoticeListItem extends NoticeListItem
      *
      * @param Notice $notice The notice we'll display
      */
-
     function __construct($notice, $out=null)
     {
         parent::__construct($notice, $out);
@@ -584,7 +474,6 @@ class FacebookNoticeListItem extends NoticeListItem
      *
      * @return void
      */
-
     function show()
     {
         $this->showStart();
@@ -595,12 +484,10 @@ class FacebookNoticeListItem extends NoticeListItem
 
         $this->showEnd();
     }
-
 }
 
 class FacebookProfileBoxNotice extends FacebookNoticeListItem
 {
-
     /**
      * constructor
      *
@@ -608,7 +495,6 @@ class FacebookProfileBoxNotice extends FacebookNoticeListItem
      *
      * @param Notice $notice The notice we'll display
      */
-
     function __construct($notice, $out=null)
     {
         parent::__construct($notice, $out);
@@ -620,7 +506,6 @@ class FacebookProfileBoxNotice extends FacebookNoticeListItem
      *
      * @return void
      */
-
     function show()
     {
         $this->showNotice();
@@ -630,7 +515,6 @@ class FacebookProfileBoxNotice extends FacebookNoticeListItem
 
     function showAppLink()
     {
-
         $this->facebook = getFacebook();
 
         $app_props = $this->facebook->api_client->Admin_getAppProperties(
@@ -644,5 +528,4 @@ class FacebookProfileBoxNotice extends FacebookNoticeListItem
         $this->out->text($this->app_name);
         $this->out->elementEnd('a');
     }
-
 }