]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/facebooksettings.php
Merge branch 'master' of /var/www/trunk
[quix0rs-gnu-social.git] / actions / facebooksettings.php
index d28b1aa5ca95b7027be03d16b15bcce04b9ac6a3..bc034bc46d7a3e538fa60efd9b544e9e09f2a88d 100644 (file)
@@ -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,85 +29,97 @@ 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');
+        $prefix = $this->trimmed('prefix');
 
         $facebook = get_facebook();
         $fbuid = $facebook->require_login();
 
-        $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
+        $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
 
         $original = clone($flink);
         $flink->set_flags($noticesync, $replysync, false);
         $result = $flink->update($original);
 
+        $facebook->api_client->data_setUserPreference(FACEBOOK_NOTICE_PREFIX,
+            substr($prefix, 0, 128));
+
         if ($result) {
-            echo '<fb:success message="Sync preferences saved." />';
+            $this->showForm('Sync preferences saved.', true);
+        } else {
+            $this->showForm('There was a problem saving your sync preferences!');
         }
-
-        $this->show_form();
-
     }
 
-    function show_form() {
+    function showForm($msg = null, $success = false) {
 
         $facebook = get_facebook();
         $fbuid = $facebook->require_login();
 
-        $flink = Foreign_link::getByForeignID($fbuid, 2); // 2 == Facebook
+        $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE);
 
-        $this->show_header('Settings');
+        $this->showHeader($msg, $success);
+        $this->showNav('Settings');
 
-        $fbml = '<fb:if-section-not-added section="profile">'
-            .'<h2>Add an Identi.ca box to my profile</h2>'
-            .'<p><fb:add-section-button section="profile"/></p>'
-            .'</fb:if-section-not-added>';
+        if ($facebook->api_client->users_hasAppPermission('status_update')) {
 
-        $fbml .= '<p><fb:prompt-permission perms="status_update"><h2>Allow Identi.ca to update my Facebook status</h2></fb:prompt-permission></p>';
+            $this->elementStart('form', array('method' => 'post',
+                                               'id' => 'facebook_settings'));
 
-        if ($facebook->api_client->users_hasAppPermission('status_update')) {
+            $this->element('h2', null, _('Sync preferences'));
 
-        $fbml .= '<form method="post" id="facebook_settings">'
-        .'<h2>Sync preferences</h2>'
-        .'<p>';
+            $this->checkbox('noticesync', _('Automatically update my Facebook status with my notices.'),
+                                ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND) : true);
 
-        if ($flink->noticesync & FOREIGN_NOTICE_SEND) {
-            $fbml .= '<input name="noticesync" type="checkbox" class="checkbox" id="noticesync" checked="checked"/>';
-        } else {
-            $fbml .= '<input name="noticesync" type="checkbox" class="checkbox" id="noticesync">';
-        }
+            $this->checkbox('replysync', _('Send "@" replies to Facebook.'),
+                             ($flink) ? ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) : true);
 
-        $fbml .= '<label class="checkbox_label" for="noticesync">Automatically update my Facebook status with my notices.</label>'
-        .'</p>'
-        .'<p>';
+            $prefix = $facebook->api_client->data_getUserPreference(1);
 
-        if ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) {
-            $fbml .= '<input name="replysync" type="checkbox" class="checkbox" id="replysync" checked="checked"/>';
-        } else {
-            $fbml .= '<input name="replysync" type="checkbox" class="checkbox" id="replysync"/>';
-        }
+            $this->input('prefix', _('Prefix'),
+                         ($prefix) ? $prefix : null,
+                         _('A string to prefix notices with.'));
+            $this->submit('save', _('Save'));
 
-        $fbml .= '<label class="checkbox_label" for="replysync">Send &quot;@&quot; replies to Facebook.</label>'
-        .'</p>'
-        .'<p>'
-        .'<input type="submit" id="save" name="save" class="submit" value="Save"/>'
-        .'</p>'
-        .'</form>';
+            $this->elementEnd('form');
 
-    }
+        } else {
 
-        echo $fbml;
+            // Figure what the URL of our app is.
+            $app_props = $facebook->api_client->Admin_getAppProperties(
+                    array('canvas_name', 'application_name'));
+            $app_url = 'http://apps.facebook.com/' . $app_props['canvas_name'] . '/settings.php';
+            $app_name = $app_props['application_name'];
+
+            $instructions = sprintf(_('If you would like the %s app to automatically update ' .
+                'your Facebook status with your latest notice, you need ' .
+                'to give it permission.'), $app_name);
+
+            common_element_start('p');
+            common_element('span', array('id' => 'permissions_notice'), $instructions);
+            common_element_end('p');
+
+            common_element_start('ul', array('id' => 'fb-permissions-list'));
+            common_element_start('li', array('id' => 'fb-permissions-item'));
+            common_element_start('fb:prompt-permission', array('perms' => 'status_update',
+                'next_fbjs' => 'document.setLocation(\'' . $app_url . '\')'));
+            common_element('span', array('class' => 'facebook-button'),
+                _('Allow Identi.ca to update my Facebook status'));
+            common_element_end('fb:prompt-permission');
+            common_element_end('li');
+            common_element_end('ul');
+        }
 
-        $this->show_footer();
+        $this->showFooter();
     }
 
 }