X-Git-Url: https://git.mxchange.org/?p=friendica-addons.git;a=blobdiff_plain;f=statusnet%2Fstatusnet.php;h=febe4032f19d1c7f4566fdd43295f40e4b0e1833;hp=7041c399b837496bc2a6a6c2e332fefad161f50a;hb=5fb7ef40fd9861a8011cfb01dc0dbd4d1d6046f6;hpb=96b8512e5ef41996b9547407acba66ef4e401b1d diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 7041c399..febe4032 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -1,7 +1,7 @@ * Author: Michael Vogel @@ -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; @@ -581,7 +589,7 @@ function statusnet_post_hook(&$a,&$b) { $image = ""; - if (isset($msgarr["url"])) { + if (isset($msgarr["url"]) AND ($msgarr["type"] != "photo")) { if ((strlen($msgarr["url"]) > 20) AND ((strlen($msg." \n".$msgarr["url"]) > $max_char))) $msg .= " \n".short_link($msgarr["url"]); @@ -738,7 +746,7 @@ function statusnet_prepare_body(&$a,&$b) { $msgarr = plaintext($a, $item, $max_char, true, 7); $msg = $msgarr["text"]; - if (isset($msgarr["url"])) + if (isset($msgarr["url"]) AND ($msgarr["type"] != "photo")) $msg .= " ".$msgarr["url"]; if (isset($msgarr["image"])) @@ -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,32 +919,39 @@ 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' LIMIT 1", - intval($uid), 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)); if(!count($r) AND !$create_user) return(0); @@ -966,10 +984,10 @@ function statusnet_fetch_contact($uid, $contact, $create_user) { intval(1) ); - $r = q("SELECT * FROM `contact` WHERE `alias` = '%s' AND `uid` = %d LIMIT 1", + $r = q("SELECT * FROM `contact` WHERE `alias` = '%s' AND `uid` = %d AND `network` = '%s' LIMIT 1", dbesc($contact->statusnet_profile_url), - intval($uid) - ); + intval($uid), + dbesc(NETWORK_STATUSNET)); if(! count($r)) return(false); @@ -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); } }