]> git.mxchange.org Git - friendica-addons.git/blobdiff - facebook/facebook.php
Merge remote branch 'upstream/master'
[friendica-addons.git] / facebook / facebook.php
index d63c6081080993e22ecb1b9d5d3a17639f5b1cfb..f70524a62c77f7bcc18d9b8f8286098bfeaa0911 100644 (file)
@@ -33,6 +33,7 @@ define('FACEBOOK_MAXPOSTLEN', 63206);
 define('FACEBOOK_SESSION_ERR_NOTIFICATION_INTERVAL', 259200); // 3 days
 define('FACEBOOK_DEFAULT_POLL_INTERVAL', 60); // given in minutes
 define('FACEBOOK_MIN_POLL_INTERVAL', 5);
+define('FACEBOOK_RTU_ERR_MAIL_AFTER_MINUTES', 180); // 3 hours
 
 require_once('include/security.php');
 
@@ -331,6 +332,14 @@ function fb_get_friends_sync_parsecontact($uid, $contact) {
 
     $contact_id  = $r[0]['id'];
 
+       $g = q("select def_gid from user where uid = %d limit 1",
+               intval($uid)
+       );
+       if($g && intval($g[0]['def_gid'])) {
+               require_once('include/group.php');
+               group_add_member($uid,'',$contact_id,$g[0]['def_gid']);
+       }
+
     require_once("Photo.php");
 
     $photos = import_profile_photo($r[0]['photo'],$uid,$contact_id);
@@ -429,6 +438,10 @@ function facebook_post(&$a) {
        $uid = local_user();
        if($uid){
 
+
+               $fb_limited = get_config('facebook','restrict');
+
+
                $value = ((x($_POST,'post_by_default')) ? intval($_POST['post_by_default']) : 0);
                set_pconfig($uid,'facebook','post_by_default', $value);
 
@@ -444,7 +457,13 @@ function facebook_post(&$a) {
                set_pconfig($uid,'facebook','blocked_apps',escape_tags(trim($_POST['blocked_apps'])));
 
                $linkvalue = ((x($_POST,'facebook_linking')) ? intval($_POST['facebook_linking']) : 0);
-               set_pconfig($uid,'facebook','no_linking', (($linkvalue) ? 0 : 1));
+
+               if($fb_limited) {
+                       if($linkvalue == 0)
+                               set_pconfig($uid,'facebook','no_linking', 1);
+               }
+               else    
+                       set_pconfig($uid,'facebook','no_linking', (($linkvalue) ? 0 : 1));
 
                // FB linkage was allowed but has just been turned off - remove all FB contacts and posts
 
@@ -495,6 +514,9 @@ function facebook_content(&$a) {
                info( t('Updating contacts') . EOL);
        }
 
+
+       $fb_limited = get_config('facebook','restrict');
+
        $o = '';
        
        $fb_installed = false;
@@ -548,6 +570,15 @@ function facebook_content(&$a) {
 
                $no_linking = get_pconfig(local_user(),'facebook','no_linking');
                $checked = (($no_linking) ? '' : ' checked="checked" ');
+               if($fb_limited) {
+                       if($no_linking) {
+                               $o .= EOL . '<strong>' . t('Facebook friend linking has been disabled on this site. The following settings will have no effect.') . '</strong>' . EOL;
+                               $checked .= " disabled ";
+                       }
+                       else {
+                               $o .= EOL . '<strong>' . t('Facebook friend linking has been disabled on this site. If you disable it, you will be unable to re-enable it.') . '</strong>' . EOL;
+                       }
+               }
                $o .= '<input type="checkbox" name="facebook_linking" value="1"' . $checked . '/>' . ' ' . t('Link all your Facebook friends and conversations on this website') . EOL ;
 
                $o .= '<p>' . t('Facebook conversations consist of your <em>profile wall</em> and your friend <em>stream</em>.');
@@ -643,8 +674,15 @@ function facebook_cron($a,$b) {
                                logger('facebook_cron: Successful', LOGGER_NORMAL);
                        else {
                                logger('facebook_cron: Failed', LOGGER_NORMAL);
-                               
-                               if(strlen($a->config['admin_email']) && !get_config('facebook', 'realtime_err_mailsent')) {
+
+                               $first_err = get_config('facebook', 'realtime_first_err');
+                               if (!$first_err) {
+                                       $first_err = time();
+                                       set_config('facebook', 'realtime_first_err', $first_err);
+                               }
+                               $first_err_ago = (time() - $first_err);
+
+                               if(strlen($a->config['admin_email']) && !get_config('facebook', 'realtime_err_mailsent') && $first_err_ago > (FACEBOOK_RTU_ERR_MAIL_AFTER_MINUTES * 60)) {
                                        mail($a->config['admin_email'], t('Problems with Facebook Real-Time Updates'),
                                                "Hi!\n\nThere's a problem with the Facebook Real-Time Updates that cannot be solved automatically. Maybe a permission issue?\n\nPlease try to re-activate it on " . $a->config["system"]["url"] . "/admin/plugins/facebook\n\nThis e-mail will only be sent once.",
                                                'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
@@ -657,6 +695,7 @@ function facebook_cron($a,$b) {
                        }
                } else { // !facebook_check_realtime_active()
                        del_config('facebook', 'realtime_err_mailsent');
+                       del_config('facebook', 'realtime_first_err');
                }
        }
        
@@ -712,7 +751,7 @@ function facebook_plugin_admin(&$a, &$o){
        
        $o .= '<label for="fb_appid">' . t('App-ID / API-Key') . '</label><input id="fb_appid" name="appid" type="text" value="' . escape_tags($appid ? $appid : "") . '"><br style="clear: both;">';
        $o .= '<label for="fb_appsecret">' . t('Application secret') . '</label><input id="fb_appsecret" name="appsecret" type="text" value="' . escape_tags($appsecret ? $appsecret : "") . '"><br style="clear: both;">';
-       $o .= '<label for="fb_poll_interval">' . sprintf(t('Polling Interval (min. %1$s minutes)'), FACEBOOK_MIN_POLL_INTERVAL) . '</label><input name="poll_interval" id="fb_poll_interval" type="number" min="' . FACEBOOK_MIN_POLL_INTERVAL . '" value="' . $poll_interval . '"><br style="clear: both;">';
+       $o .= '<label for="fb_poll_interval">' . sprintf(t('Polling Interval in minutes (minimum %1$s minutes)'), FACEBOOK_MIN_POLL_INTERVAL) . '</label><input name="poll_interval" id="fb_poll_interval" type="number" min="' . FACEBOOK_MIN_POLL_INTERVAL . '" value="' . $poll_interval . '"><br style="clear: both;">';
        $o .= '<label for="fb_sync_comments">' . t('Synchronize comments (no comments on Facebook are missed, at the cost of increased system load)') . '</label><input name="sync_comments" id="fb_sync_comments" type="checkbox" ' . ($sync_comments ? 'checked' : '') . '><br style="clear: both;">';
        $o .= '<input type="submit" name="fb_save_keys" value="' . t('Save') . '">';
        
@@ -731,9 +770,9 @@ function facebook_plugin_admin(&$a, &$o){
 
 /**
  * @param App $a
- * @param null|object $o
  */
-function facebook_plugin_admin_post(&$a, &$o){
+
+function facebook_plugin_admin_post(&$a){
        check_form_security_token_redirectOnErr('/admin/plugins/facebook', 'fbsave');
        
        if (x($_REQUEST,'fb_save_keys')) {