diff options
Diffstat (limited to 'addon/facebook/facebook.php')
-rw-r--r-- | addon/facebook/facebook.php | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/addon/facebook/facebook.php b/addon/facebook/facebook.php index c7821b272..8fe6f3717 100644 --- a/addon/facebook/facebook.php +++ b/addon/facebook/facebook.php @@ -291,8 +291,12 @@ function facebook_cron($a,$b) { $last = get_config('facebook','last_poll'); + $poll_interval = intval(get_config('facebook','poll_interval')); + if(! $poll_interval) + $poll_interval = 3600; + if($last) { - $next = $last + 3600; + $next = $last + $poll_interval; if($next > time()) return; } @@ -379,18 +383,23 @@ function facebook_post_hook(&$a,&$b) { $deny = array_unique(array_merge($deny_people,$deny_groups)); $allow_str = dbesc(implode(', ',$recipients)); - $r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $allow_str ) AND `network` = 'face'"); - $allow_arr = array(); - if(count($r)) - foreach($r as $rr) - $allow_arr[] = $rr['notify']; + if($allow_str) { + $r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $allow_str ) AND `network` = 'face'"); + $allow_arr = array(); + if(count($r)) + foreach($r as $rr) + $allow_arr[] = $rr['notify']; + } $deny_str = dbesc(implode(', ',$deny)); - $r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $deny_str ) AND `network` = 'face'"); - $deny_arr = array(); - if(count($r)) - foreach($r as $rr) - $deny_arr[] = $rr['notify']; + if($deny_str) { + $r = q("SELECT `notify` FROM `contact` WHERE `id` IN ( $deny_str ) AND `network` = 'face'"); + $deny_arr = array(); + if(count($r)) + foreach($r as $rr) + $deny_arr[] = $rr['notify']; + } + if(count($deny_arr) && (! count($allow_arr))) { // One or more FB folks were denied access but nobody on FB was specifically allowed access. @@ -442,10 +451,22 @@ function facebook_post_hook(&$a,&$b) { // make links readable before we strip the code + if(preg_match("/\[url=(.+?)\](.+?)\[\/url\]/is",$msg,$matches)) { + + $link = $matches[1]; + if(substr($matches[2],0,5) != '[img]' ) + $linkname = $matches[2]; + } + $msg = preg_replace("/\[url=(.+?)\](.+?)\[\/url\]/is",'$2 $1',$msg); + if(preg_match("/\[img\](.+?)\[\/img\]/is",$msg,$matches)) + $image = $matches[1]; + $msg = preg_replace("/\[img\](.+?)\[\/img\]/is", t('Image: ') . '$1', $msg); + + $msg = trim(strip_tags(bbcode($msg))); $msg = html_entity_decode($msg,ENT_QUOTES,'UTF-8'); @@ -478,6 +499,12 @@ function facebook_post_hook(&$a,&$b) { 'access_token' => $fb_token, 'message' => $msg ); + if(isset($image)) + $postvars['picture'] = $image; + if(isset($link)) + $postvars['link'] = $link; + if(isset($linkname)) + $postvars['name'] = $linkname; } if(($b['private']) && (! $b['parent'])) { @@ -490,17 +517,15 @@ function facebook_post_hook(&$a,&$b) { } - if(! $reply) { - if($b['plink']) - $postvars['actions'] = '{"name": "' . t('View on Friendika') . '", "link": "' . $b['plink'] . '"}'; - } - if($reply) { $url = 'https://graph.facebook.com/' . $reply . '/' . (($likes) ? 'likes' : 'comments'); } else { $url = 'https://graph.facebook.com/me/feed'; + if($b['plink']) + $postvars['actions'] = '{"name": "' . t('View on Friendika') . '", "link": "' . $b['plink'] . '"}'; } + logger('facebook: post to ' . $url); logger('facebook: postvars: ' . print_r($postvars,true)); |