]> git.mxchange.org Git - friendica-addons.git/blobdiff - statusnet/statusnet.php
Merge pull request #384 from annando/1609-ignorelist-rendertime
[friendica-addons.git] / statusnet / statusnet.php
index 12c26e470255eaad31f6f704934cd5f2ec4a1d88..febe4032f19d1c7f4566fdd43295f40e4b0e1833 100644 (file)
@@ -44,6 +44,8 @@
 define('STATUSNET_DEFAULT_POLL_INTERVAL', 5); // given in minutes
 
 require_once('library/twitteroauth.php');
+require_once('include/enotify.php');
+require_once("include/socgraph.php");
 
 class StatusNetOAuth extends TwitterOAuth {
     function get_maxlength() {
@@ -119,6 +121,7 @@ function statusnet_install() {
        register_hook('jot_networks',    'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
        register_hook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
        register_hook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
+       register_hook('check_item_notification','addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
        logger("installed GNU Social");
 }
 
@@ -131,6 +134,7 @@ function statusnet_uninstall() {
        unregister_hook('jot_networks',    'addon/statusnet/statusnet.php', 'statusnet_jot_nets');
        unregister_hook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron');
        unregister_hook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body');
+       unregister_hook('check_item_notification','addon/statusnet/statusnet.php', 'statusnet_check_item_notification');
 
        // old setting - remove only
        unregister_hook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook');
@@ -139,6 +143,10 @@ function statusnet_uninstall() {
 
 }
 
+function statusnet_check_item_notification($a, &$notification_data) {
+       $notification_data["profiles"][] = get_pconfig($notification_data["uid"], 'statusnet', 'own_url');
+}
+
 function statusnet_jot_nets(&$a,&$b) {
        if(! local_user())
                return;
@@ -864,6 +872,9 @@ function statusnet_fetchtimeline($a, $uid) {
                        $_REQUEST["source"] = $post->source;
                        $_REQUEST["extid"] = NETWORK_STATUSNET;
 
+                       if (isset($post->id))
+                               $_REQUEST['message_id'] = NETWORK_STATUSNET.":".$post->id;
+
                        //$_REQUEST["date"] = $post->created_at;
 
                        $_REQUEST["title"] = "";
@@ -908,29 +919,36 @@ function statusnet_fetch_contact($uid, $contact, $create_user) {
        if ($contact->statusnet_profile_url == "")
                return(-1);
 
-       // Check if the unique contact is existing
-       // To-Do: only update once a while
-        $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
-                       dbesc(normalise_link($contact->statusnet_profile_url)));
-
-       if (count($r) == 0)
-               q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')",
-                       dbesc(normalise_link($contact->statusnet_profile_url)),
-                       dbesc($contact->name),
-                       dbesc($contact->screen_name),
-                       dbesc($contact->profile_image_url));
-       else
-               q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'",
-                       dbesc($contact->name),
-                       dbesc($contact->screen_name),
-                       dbesc($contact->profile_image_url),
-                       dbesc(normalise_link($contact->statusnet_profile_url)));
+       if (function_exists("update_gcontact"))
+               update_gcontact(array("url" => $contact->statusnet_profile_url,
+                               "network" => NETWORK_STATUSNET, "photo" => $contact->profile_image_url,
+                               "name" => $contact->name, "nick" => $contact->screen_name,
+                               "location" => $contact->location, "about" => $contact->description,
+                               "addr" => statusnet_address($contact), "generation" => 3));
+       else {
+               // Old Code
+                $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
+                               dbesc(normalise_link($contact->statusnet_profile_url)));
+
+               if (count($r) == 0)
+                       q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')",
+                               dbesc(normalise_link($contact->statusnet_profile_url)),
+                               dbesc($contact->name),
+                               dbesc($contact->screen_name),
+                               dbesc($contact->profile_image_url));
+               else
+                       q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'",
+                               dbesc($contact->name),
+                               dbesc($contact->screen_name),
+                               dbesc($contact->profile_image_url),
+                               dbesc(normalise_link($contact->statusnet_profile_url)));
 
-       if (DB_UPDATE_VERSION >= "1177")
-               q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'",
-                       dbesc($contact->location),
-                       dbesc($contact->description),
-                       dbesc(normalise_link($contact->statusnet_profile_url)));
+               if (DB_UPDATE_VERSION >= "1177")
+                       q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'",
+                               dbesc($contact->location),
+                               dbesc($contact->description),
+                               dbesc(normalise_link($contact->statusnet_profile_url)));
+       }
 
        $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1",
                intval($uid), dbesc(normalise_link($contact->statusnet_profile_url)), dbesc(NETWORK_STATUSNET));
@@ -1436,7 +1454,7 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
 
                                        logger('statusnet_fetchhometimeline: User '.$self["nick"].' posted home timeline item '.$item);
 
-                                       if ($item != 0)
+                                       if ($item AND !function_exists("check_item_notification"))
                                                statusnet_checknotification($a, $uid, $nick, $item, $postarray);
                                }
 
@@ -1486,6 +1504,9 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
                                        $postarray["id"] = $item;
 
                                        logger('statusnet_fetchhometimeline: User '.$self["nick"].' posted mention timeline item '.$item);
+
+                                       if ($item AND function_exists("check_item_notification"))
+                                               check_item_notification($item, $uid, NOTIFY_TAGSELF);
                                }
                        }
 
@@ -1498,7 +1519,7 @@ function statusnet_fetchhometimeline($a, $uid, $mode = 1) {
                                $parent_id = $r[0]['parent'];
                        }
 
-                       if ($item != 0) {
+                       if (($item != 0) AND !function_exists("check_item_notification")) {
                                require_once('include/enotify.php');
                                notification(array(
                                        'type'         => NOTIFY_TAGSELF,
@@ -1529,6 +1550,7 @@ function statusnet_complete_conversation($a, $uid, $self, $create_user, $nick, $
        $api     = get_pconfig($uid, 'statusnet', 'baseapi');
        $otoken  = get_pconfig($uid, 'statusnet', 'oauthtoken');
        $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret');
+       $own_url = get_pconfig($uid, 'statusnet', 'own_url');
 
        require_once('library/twitteroauth.php');
 
@@ -1552,7 +1574,7 @@ function statusnet_complete_conversation($a, $uid, $self, $create_user, $nick, $
 
                        logger('statusnet_complete_conversation: User '.$self["nick"].' posted home timeline item '.$item);
 
-                       if ($item != 0)
+                       if ($item AND !function_exists("check_item_notification"))
                                statusnet_checknotification($a, $uid, $nick, $item, $postarray);
                }
        }