]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
trac750 Add notice input box to FB app and ability to post notices
authorZach Copley <zach@controlyourself.ca>
Mon, 19 Jan 2009 07:24:12 +0000 (07:24 +0000)
committerZach Copley <zach@controlyourself.ca>
Mon, 19 Jan 2009 07:24:12 +0000 (07:24 +0000)
actions/facebookhome.php
actions/facebookinvite.php
actions/facebookremove.php
actions/facebooksettings.php
lib/facebookaction.php
lib/facebookutil.php
scripts/update_facebook.php

index 7430cc41fa7c2428262da36cd09613351942fb14..3696df90ac534b962e803de50e042be78e6fbfc3 100644 (file)
@@ -30,6 +30,9 @@ class FacebookhomeAction extends FacebookAction
 
         $facebook = get_facebook();
         $fbuid = $facebook->require_login();
+        // Check to see whether there's already a Facebook link for this user
+        $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
 
         // If the user has opted not to initially allow the app to have
         // Facebook status update permission, store that preference. Only
@@ -39,11 +42,13 @@ class FacebookhomeAction extends FacebookAction
                 FACEBOOK_PROMPTED_UPDATE_PREF, 'true');
         }
 
-        // Check to see whether there's already a Facebook link for this user
-        $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
-
         if ($flink) {
 
+            if ($_POST['submit'] == 'Send') {       
+                $this->saveNewNotice($flink);
+                return;
+            }
+
             $user = $flink->getUser();
             common_set_user($user);
 
@@ -136,19 +141,16 @@ class FacebookhomeAction extends FacebookAction
         $notice = $user->getCurrentNotice();
         update_profile_box($facebook, $fbuid, $user, $notice);
 
-
-        $this->showHeader('Home');
-
-        if ($msg) {
-            common_element('fb:success', array('message' => $msg));
-        }
-
-        echo $this->show_notices($user);
+        $this->showHeader($msg);      
+        $this->showNoticeForm($user);
+        $this->showNav('Home');
+        
+        echo $this->showNotices($user);
 
         $this->showFooter();
     }
 
-    function show_notices($user)
+    function showNotices($user)
     {
 
         $page = $this->trimmed('page');
@@ -158,13 +160,13 @@ class FacebookhomeAction extends FacebookAction
 
         $notice = $user->noticesWithFriends(($page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
 
-        $cnt = $this->show_notice_list($notice);
+        $cnt = $this->showNoticeList($notice);
 
-        common_pagination($page > 1, $cnt > NOTICES_PER_PAGE,
-                          $page, 'all', array('nickname' => $user->nickname));
+        facebookPagination($page > 1, $cnt > NOTICES_PER_PAGE,
+            $page, 'all', array('nickname' => $user->nickname));
     }
 
-    function show_notice_list($notice)
+    function showNoticeList($notice)
     {
         $nl = new FacebookNoticeList($notice);
         return $nl->show();
@@ -175,19 +177,10 @@ class FacebookhomeAction extends FacebookAction
         $facebook = get_facebook();
         $fbuid = $facebook->require_login();
 
-        start_fbml();
+        startFBML();
 
-        common_element('link', array('rel' => 'stylesheet',
-                                     'type' => 'text/css',
-                                     'href' => getFacebookBaseCSS()));
-
-        common_element('link', array('rel' => 'stylesheet',
-                                     'type' => 'text/css',
-                                     'href' => getFacebookThemeCSS()));
-
-        common_element('script', array('type' => 'text/javascript',
-                                       'src' => getFacebookJS()),
-                                       ' ');
+        $this->showStylesheets();
+        $this->showScripts();
 
         $this->showLogo();
 
@@ -231,5 +224,49 @@ class FacebookhomeAction extends FacebookAction
         common_end_xml();
 
     }
+    
+    function saveNewNotice($flink)
+    {
+        
+        $user = $flink->getUser();
 
+        $content = $_POST['status_textarea']; 
+
+        if (!$content) {
+            $this->showHome($flink, _('No content!'));
+            return;
+        } else {
+            $content_shortened = common_shorten_links($content);
+
+            if (mb_strlen($content_shortened) > 140) {
+                common_debug("Content = '$content_shortened'", __FILE__);
+                common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__);
+                $this->showHome($flink, _('That\'s too long. Max notice size is 140 chars.'));
+                return;
+            }
+        }
+
+        $inter = new CommandInterpreter();
+
+        $cmd = $inter->handle_command($user, $content_shortened);
+
+        if ($cmd) {
+            $cmd->execute(new WebChannel());
+            return;
+        }
+
+        $replyto = $this->trimmed('inreplyto');
+
+        $notice = Notice::saveNew($user->id, $content,
+            'Facebook', 1, ($replyto == 'false') ? null : $replyto);
+
+        if (is_string($notice)) {
+            $this->showHome($flink, 'Error!');
+            return;
+        }
+
+        common_broadcast_notice($notice);
+        $this->showHome($flink, 'Success!');
+    }
+    
 }
index d7e82dae7b7cbb21acc33958b75718a2ae8ba943..e67bfaa0006422378b843b271921a353ca5b1e37 100644 (file)
@@ -69,7 +69,8 @@ class FacebookinviteAction extends FacebookAction
         $facebook = get_facebook();
         $fbuid = $facebook->require_login();
 
-        $this->showHeader('Invite');
+        $this->showHeader();
+        $this->showNav('Invite');
 
         // Get a list of users who are already using the app for exclusion
         $exclude_ids = $facebook->api_client->friends_getAppUsers();
index a200fefbfe8afebf8df3bb5d4503ced30b68fb92..557c0655b48b0e826d36750d58abd6fa4e9dbea9 100644 (file)
@@ -19,7 +19,7 @@
 
 if (!defined('LACONICA')) { exit(1); }
 
-require_once(INSTALLDIR.'/lib/facebookaction.php');
+require_once INSTALLDIR.'/lib/facebookaction.php';
 
 class FacebookremoveAction extends FacebookAction
 {
index 84e9a343bf435a942f1600098aa3d1174c47dd74..a08abc93719117d9a161b29121494a9591ef5b5a 100644 (file)
@@ -67,8 +67,8 @@ class FacebooksettingsAction extends FacebookAction
 
         $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
 
-        $this->showHeader('Settings', $msg, $success);
-
+        $this->showHeader($msg, $success);
+        $this->showNav('Settings');
 
         if ($facebook->api_client->users_hasAppPermission('status_update')) {
 
index 263248f679567d480a15eef714a5a8eecf991e2f..cd43a2ccb98b17cb1f4c351ca005eb0a48c9fb57 100644 (file)
@@ -35,17 +35,8 @@ class FacebookAction extends Action
 
         global $xw;
 
-        common_element('link', array('rel' => 'stylesheet',
-                                     'type' => 'text/css',
-                                     'href' => getFacebookBaseCSS()));
-
-        common_element('link', array('rel' => 'stylesheet',
-                                     'type' => 'text/css',
-                                     'href' => getFacebookThemeCSS()));
-
-        common_element('script', array('type' => 'text/javascript',
-                                       'src' => getFacebookJS()),
-                                       ' ');
+        $this->showStylesheets();
+        $this->showScripts();
 
         common_element_start('a', array('class' => 'url home bookmark',
                                             'href' => common_local_url('public')));
@@ -61,19 +52,34 @@ class FacebookAction extends Action
 
     }
 
-    function showHeader($selected = 'Home', $msg = null, $success = false)
-    {
 
-        start_fbml();
+    function showHeader($msg = null, $success = false) 
+    {
+        startFBML();
 
         common_element_start('fb:if-section-not-added', array('section' => 'profile'));
         common_element_start('span', array('id' => 'add_to_profile'));
         common_element('fb:add-section-button', array('section' => 'profile'));
         common_element_end('span');
         common_element_end('fb:if-section-not-added');
-
+        
         $this->showLogo();
 
+        if ($msg) {
+            if ($success) {
+                common_element('fb:success', array('message' => $msg));
+            } else {
+                // XXX do an error message here
+            }
+        }
+
+        common_element_start('div', 'main_body');        
+        
+    }
+
+    function showNav($selected = 'Home')
+    {
+
         common_element_start('dl', array("id" => 'site_nav_local_views'));
         common_element('dt', null, _('Local Views'));
         common_element_start('dd');
@@ -86,7 +92,6 @@ class FacebookAction extends Action
             array('href' => 'index.php', 'title' => _('Home')), _('Home'));
         common_element_end('li');
 
-
         common_element_start('li',
             array('class' =>
                 ($selected == 'Invite') ? 'current' : 'facebook_invite'));
@@ -107,17 +112,6 @@ class FacebookAction extends Action
         common_element_end('dd');
         common_element_end('dl');
 
-
-        if ($msg) {
-            if ($success) {
-                common_element('fb:success', array('message' => $msg));
-            } else {
-                // XXX do an error message here
-            }
-        }
-
-        common_element_start('div', 'main_body');
-
     }
 
     function showFooter()
@@ -149,10 +143,11 @@ class FacebookAction extends Action
         common_element_end('dl');
     }
 
-    function showLoginForm($msg = null)
-    {
-        start_fbml();
 
+    function showStylesheets() 
+    {
+        global $xw;
+        
         common_element('link', array('rel' => 'stylesheet',
                                      'type' => 'text/css',
                                      'href' => getFacebookBaseCSS()));
@@ -160,10 +155,23 @@ class FacebookAction extends Action
         common_element('link', array('rel' => 'stylesheet',
                                      'type' => 'text/css',
                                      'href' => getFacebookThemeCSS()));
-
+    }
+    
+    function showScripts() 
+    {
+        global $xw;
+        
         common_element('script', array('type' => 'text/javascript',
-                                       'src' => getFacebookJS()),
-                                       ' ');
+                                       'src' => getFacebookJS()));
+        
+    }
+
+    function showLoginForm($msg = null)
+    {
+        startFBML();
+
+        $this->showStylesheets();
+        $this->showScripts();
 
         $this->showLogo();
 
@@ -179,6 +187,7 @@ class FacebookAction extends Action
         common_element_start('div', array('id' => 'content_inner'));
 
         common_element_start('form', array('method' => 'post',
+                                               'class' => 'form_settings',
                                                'id' => 'login',
                                                'action' => 'index.php'));
 
@@ -209,4 +218,53 @@ class FacebookAction extends Action
     }
 
 
+    function showNoticeForm($user) 
+    {
+    
+        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');
+    }
+
 }
index cc4941bdc14eb0f5017794e7dee3d2053b34771a..a133ce8ba5dd987814fb068a6ba6e189fb08b219 100644 (file)
@@ -44,7 +44,7 @@ function get_facebook()
     return new Facebook($apikey, $secret);
 }
 
-function start_fbml($indent = true)
+function startFBML($indent = true)
 {
     global $xw;
     $xw = new XMLWriter();
@@ -132,6 +132,42 @@ function getFacebookJS() {
 }
 
 
+// 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
 {
     /**
index 8c91df384b215dd2f97803a1a6f1fc1de86ba6eb..0c54cec7cfd87cf6907479e29b6bb1c0f596ae70 100755 (executable)
@@ -67,9 +67,13 @@ while($notice->fetch()) {
         // If it's not a reply, or if the user WANTS to send replies...
         if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $content) ||
             (($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) {
-                update_status($fbuid, $content);
-                update_profile_box($facebook, $fbuid, $user, $notice);
-                $cnt++;
+             
+                // Avoid a Loop
+                if ($notice->source != 'Facebook') {
+                    update_status($fbuid, $content);
+                    update_profile_box($facebook, $fbuid, $user, $notice);
+                    $cnt++;
+                }
             }
     }
 }