]> git.mxchange.org Git - friendica-addons.git/blobdiff - fbsync/fbsync.php
Merge remote-tracking branch 'upstream/master'
[friendica-addons.git] / fbsync / fbsync.php
index dac6cd2ef6daa779faf75ec4ebe1fa2d868b38f0..858591519b32fd9bd801ee71437394da5e1ecd4a 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * Name: Facebook Sync
  * Description: Synchronizes the Facebook Newsfeed
- * Version: 0.0.1 alpha
+ * Version: 1.0
  * Author: Michael Vogel <https://pirati.ca/profile/heluecht>
  */
 
@@ -26,6 +26,7 @@ function fbsync_install() {
        register_hook('connector_settings_post', 'addon/fbsync/fbsync.php', 'fbsync_settings_post');
        register_hook('cron', 'addon/fbsync/fbsync.php', 'fbsync_cron');
        register_hook('follow', 'addon/fbsync/fbsync.php', 'fbsync_follow');
+       register_hook('expire', 'addon/fbsync/fbsync.php', 'fbsync_expire');
 }
 
 function fbsync_uninstall() {
@@ -33,6 +34,7 @@ function fbsync_uninstall() {
        unregister_hook('connector_settings_post', 'addon/fbsync/fbsync.php', 'fbsync_settings_post');
        unregister_hook('cron', 'addon/fbsync/fbsync.php', 'fbsync_cron');
        unregister_hook('follow', 'addon/fbsync/fbsync.php', 'fbsync_follow');
+       unregister_hook('expire', 'addon/fbsync/fbsync.php', 'fbsync_expire');
 }
 
 function fbsync_follow($a, &$contact) {
@@ -100,6 +102,9 @@ function fbsync_follow($a, &$contact) {
 
 function fbsync_settings(&$a,&$s) {
 
+       // Settings are done inside the fbpost addon
+       return;
+
        if(! local_user())
                return;
 
@@ -120,11 +125,11 @@ function fbsync_settings(&$a,&$s) {
        /* Add some HTML to the existing form */
 
        $s .= '<span id="settings_fbsync_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_fbsync_expanded\'); openClose(\'settings_fbsync_inflated\');">';
-       $s .= '<h3>' . t('Facebook Import') . '</h3>';
+       $s .= '<img class="connector" src="images/facebook.png" /><h3 class="connector">'. t('Facebook Import').'</h3>';
        $s .= '</span>';
        $s .= '<div id="settings_fbsync_expanded" class="settings-block" style="display: none;">';
        $s .= '<span class="fakelink" onclick="openClose(\'settings_fbsync_expanded\'); openClose(\'settings_fbsync_inflated\');">';
-       $s .= '<h3>' . t('Facebook Import') . '</h3>';
+       $s .= '<img class="connector" src="images/facebook.png" /><h3 class="connector">'. t('Facebook Import').'</h3>';
        $s .= '</span>';
 
        $s .= '<div id="fbsync-enable-wrapper">';
@@ -177,11 +182,35 @@ function fbsync_cron($a,$b) {
                }
        }
 
-       logger('fbsync: cron_end');
+       logger('fbsync_cron: cron_end');
 
        set_config('fbsync','last_poll', time());
 }
 
+function fbsync_expire($a,$b) {
+
+       $days = get_config('fbsync', 'expire');
+
+       if ($days == 0)
+               return;
+
+       $r = q("DELETE FROM `item` WHERE `deleted` AND `network` = '%s'", dbesc(NETWORK_FACEBOOK));
+
+       require_once("include/items.php");
+
+       logger('fbsync_expire: expire_start');
+
+       $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'fbsync' AND `k` = 'sync' AND `v` = '1' ORDER BY RAND()");
+       if(count($r)) {
+               foreach($r as $rr) {
+                       logger('fbsync_expire: user '.$rr['uid']);
+                       item_expire($rr['uid'], $days, NETWORK_FACEBOOK, true);
+               }
+       }
+
+       logger('fbsync_expire: expire_end');
+}
+
 function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $create_user) {
 
        require_once("include/oembed.php");
@@ -279,6 +308,9 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
        if (isset($post->attachment->name) and isset($post->attachment->href)) {
                $oembed_data = oembed_fetch_url($post->attachment->href);
                $type = $oembed_data->type;
+               if ($type == "rich")
+                       $type = "link";
+
                $content = "[bookmark=".$post->attachment->href."]".$post->attachment->name."[/bookmark]";
        } elseif (isset($post->attachment->name) AND ($post->attachment->name != ""))
                $content = "[b]" . $post->attachment->name."[/b]";
@@ -322,7 +354,7 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
        }
 
        if ($content)
-               $postarray["body"] .= "\n\n";
+               $postarray["body"] .= "\n";
 
        if ($type)
                $postarray["body"] .= "[class=type-".$type."]";
@@ -367,7 +399,6 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr
        //      $postarray["body"] = "Type: ".$post->type."\n".$postarray["body"];
        //print_r($post);
        //print_r($postarray);
-
        $item = item_store($postarray);
        logger('fbsync_createpost: User '.$self[0]["nick"].' posted feed item '.$item, LOGGER_DEBUG);
 }
@@ -930,7 +961,6 @@ function fbsync_fetchfeed($a, $uid) {
        $url = "https://graph.facebook.com/fql?q=".urlencode(json_encode($fql))."&access_token=".$access_token;
 
        $feed = fetch_url($url);
-//file_put_contents("/home/ike/pirati.ca/htdocs/fb.".$uid, $feed);
        $data = json_decode($feed);
 
        if (!is_array($data->data)) {
@@ -1014,7 +1044,6 @@ function fbsync_fetchfeed($a, $uid) {
        foreach ($post_data AS $post) {
                if ($post->updated_time > $last_updated)
                        $last_updated = $post->updated_time;
-
                fbsync_createpost($a, $uid, $self, $contacts, $application_data, $post, $create_user);
        }