<?php
/**
* Name: GNU Social Connector
- * Description: Relay public postings to a connected GNU Social account
+ * Description: Bidirectional (posting, relaying and reading) connector for GNU Social.
* Version: 1.0.5
* Author: Tobias Diekershoff <https://f.diekershoff.de/profile/tobias>
* Author: Michael Vogel <https://pirati.ca/profile/heluecht>
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() {
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");
}
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');
}
+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;
$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"]);
$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"]))
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);
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);
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);
}
$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);
}
}
$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,
$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');
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);
}
}