require_once("include/Photo.php");
require_once("include/Scrape.php");
require_once("include/follow.php");
+require_once("include/api.php");
require_once("mod/proxy.php");
define('OSTATUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes
*/
-function ostatus_entry($doc, $item, $owner, $toplevel = false) {
+function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false) {
$a = get_app();
- if (!$toplevel) {
+ if (!$toplevel AND $repeat) {
+ $entry = $doc->createElement("activity:object");
+ $title = sprintf("New note by %s", $owner["nick"]);
+ } elseif (!$toplevel) {
$entry = $doc->createElement("entry");
$title = sprintf("New note by %s", $owner["nick"]);
} else {
// But: it seems as if it doesn't federate well between the GS servers
// So we just set it to "note" to be sure that it reaches their target systems
- xml_add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
+ if (!$repeat)
+ xml_add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
+ else
+ xml_add_element($doc, $entry, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA.'activity');
+
xml_add_element($doc, $entry, "id", $item["uri"]);
xml_add_element($doc, $entry, "title", $title);
"href" => $a->get_baseurl()."/display/".$item["guid"]));
xml_add_element($doc, $entry, "status_net", "", array("notice_id" => $item["id"]));
- xml_add_element($doc, $entry, "activity:verb", construct_verb($item));
+
+ $repeated_item = $item;
+ $is_repeat = false;
+
+ if (!$repeat)
+ $is_repeat = api_share_as_retweet($repeated_item);
+
+ if (!$is_repeat)
+ xml_add_element($doc, $entry, "activity:verb", construct_verb($item));
+ else
+ xml_add_element($doc, $entry, "activity:verb", ACTIVITY_SHARE);
+
xml_add_element($doc, $entry, "published", datetime_convert("UTC","UTC",$item["created"]."+00:00",ATOM_TIME));
xml_add_element($doc, $entry, "updated", datetime_convert("UTC","UTC",$item["edited"]."+00:00",ATOM_TIME));
+ if ($is_repeat) {
+ $repeated_owner = array();
+ $repeated_owner["name"] = $repeated_item["author-name"];
+ $repeated_owner["url"] = $repeated_item["author-link"];
+ $repeated_owner["photo"] = normalise_link($repeated_item["author-avatar"]);
+ $repeated_owner["nick"] = "";
+ $repeated_owner["location"] = "";
+ $repeated_owner["about"] = "";
+ $repeated_owner["uid"] = 0;
+
+ $r =q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($repeated_item["author-link"]));
+ if ($r) {
+ $repeated_owner["nick"] = $r[0]["nick"];
+ $repeated_owner["location"] = $r[0]["location"];
+ $repeated_owner["about"] = $r[0]["about"];
+ }
+
+ $entry_repeat = ostatus_entry($doc, $repeated_item, $repeated_owner, false, true);
+ $entry->appendChild($entry_repeat);
+ } elseif ($repeat) {
+ $profile = array();
+ $profile["name"] = $owner["name"];
+ $profile["photo"] = $owner["photo"];
+ $profile["thumb"] = $owner["photo"];
+ $profile["about"] = $owner["about"];
+ $author = ostatus_add_author($doc, $owner, $profile);
+ $entry->appendChild($author);
+ }
+
+ $mentioned = array();
+
if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
- $parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"]));
+ $parent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `id` = %d", intval($item["parent"]));
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
$attributes = array(
"rel" => "related",
"href" => $a->get_baseurl()."/display/".$parent[0]["guid"]);
xml_add_element($doc, $entry, "link", "", $attributes);
+
+ $mentioned[$parent[0]["author-link"]] = $parent[0]["author-link"];
+ $mentioned[$parent[0]["owner-link"]] = $parent[0]["owner-link"];
}
xml_add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation",
if(count($tags))
foreach($tags as $t)
if ($t[0] == "@")
- xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned",
- "ostatus:object-type" => ACTIVITY_OBJ_PERSON,
- "href" => $t[1]));
+ $mentioned[$t[1]] = $t[1];
+
+ foreach ($mentioned AS $mention)
+ xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned",
+ "ostatus:object-type" => ACTIVITY_OBJ_PERSON,
+ "href" => $mention));
if (!$item["private"])
xml_add_element($doc, $entry, "link", "", array("rel" => "mentioned",
if ($app == "")
$app = "web";
- xml_add_element($doc, $entry, "statusnet:notice_info", "", array("local_id" => $item["id"], "source" => $app));
+
+ $attributes = array("local_id" => $item["id"], "source" => $app);
+ if ($is_repeat)
+ $attributes["repeat_of"] = $item["id"];
+
+ xml_add_element($doc, $entry, "statusnet:notice_info", "", $attributes);
return $entry;
}
WHERE `item`.`uid` = %d AND `item`.`received` > '%s' AND NOT `item`.`private` AND NOT `item`.`deleted`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
AND ((`item`.`wall` AND (`item`.`parent` = `item`.`id`))
- OR (`item`.`network` = '%s' AND ((`thread`.`network`='%s') OR (`thritem`.`network` = '%s'))) AND `thread`.`mention`)
- AND (`item`.`owner-link` IN ('%s', '%s'))
+ OR (`item`.`network` = '%s' AND ((`thread`.`network` IN ('%s', '%s')) OR (`thritem`.`network` IN ('%s', '%s')))) AND `thread`.`mention`)
+ AND ((`item`.`owner-link` IN ('%s', '%s') AND (`item`.`parent` = `item`.`id`))
+ OR (`item`.`author-link` IN ('%s', '%s')))
ORDER BY `item`.`received` DESC
LIMIT 0, 300",
- intval($owner["uid"]), dbesc($check_date),
- dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),
+ intval($owner["uid"]), dbesc($check_date), dbesc(NETWORK_DFRN),
+ //dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),
+ //dbesc(NETWORK_OSTATUS), dbesc(NETWORK_OSTATUS),
+ dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN),
+ dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN),
+ dbesc($owner["nurl"]), dbesc(str_replace("http://", "https://", $owner["nurl"])),
dbesc($owner["nurl"]), dbesc(str_replace("http://", "https://", $owner["nurl"]))
);
if(! function_exists('ref_session_open')) {
function ref_session_open ($s,$n) {
- return true;
+ return true;
}}
if(! function_exists('ref_session_read')) {
function ref_session_read ($id) {
- global $session_exists;
- if(x($id))
- $r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
- if(count($r)) {
- $session_exists = true;
- return $r[0]['data'];
- } else {
- logger("no data for session $id", LOGGER_TRACE);
- }
- return '';
+ global $session_exists;
+ if(x($id))
+ $r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
+
+ if(count($r)) {
+ $session_exists = true;
+ return $r[0]['data'];
+ } else {
+ logger("no data for session $id", LOGGER_TRACE);
+ }
+ return '';
}}
if(! function_exists('ref_session_write')) {
function ref_session_write ($id,$data) {
- global $session_exists, $session_expire;
- if(! $id || ! $data) {
- return false;
- }
-
- $expire = time() + $session_expire;
- $default_expire = time() + 300;
-
- if($session_exists)
- $r = q("UPDATE `session`
- SET `data` = '%s', `expire` = '%s'
- WHERE `sid` = '%s'",
- dbesc($data), dbesc($expire), dbesc($id));
- else
- $r = q("INSERT INTO `session`
- SET `sid` = '%s', `expire` = '%s', `data` = '%s'",
- dbesc($id), dbesc($default_expire), dbesc($data));
-
- return true;
+ global $session_exists, $session_expire;
+
+ if(! $id || ! $data) {
+ return false;
+ }
+
+ $expire = time() + $session_expire;
+ $default_expire = time() + 300;
+
+ if($session_exists) {
+ $r = q("UPDATE `session`
+ SET `data` = '%s'
+ WHERE `data` != '%s' AND `sid` = '%s'",
+ dbesc($data), dbesc($data), dbesc($id));
+
+ $r = q("UPDATE `session`
+ SET `expire` = '%s'
+ WHERE `expire` != '%s' AND `sid` = '%s'",
+ dbesc($expire), dbesc($expire), dbesc($id));
+ } else
+ $r = q("INSERT INTO `session`
+ SET `sid` = '%s', `expire` = '%s', `data` = '%s'",
+ dbesc($id), dbesc($default_expire), dbesc($data));
+
+ return true;
}}
if(! function_exists('ref_session_close')) {
function ref_session_close() {
- return true;
+ return true;
}}
if(! function_exists('ref_session_destroy')) {
function ref_session_destroy ($id) {
- q("DELETE FROM `session` WHERE `sid` = '%s'", dbesc($id));
- return true;
+ q("DELETE FROM `session` WHERE `sid` = '%s'", dbesc($id));
+ return true;
}}
if(! function_exists('ref_session_gc')) {
function ref_session_gc($expire) {
- q("DELETE FROM `session` WHERE `expire` < %d", dbesc(time()));
- q("OPTIMIZE TABLE `sess_data`");
- return true;
+ q("DELETE FROM `session` WHERE `expire` < %d", dbesc(time()));
+ q("OPTIMIZE TABLE `sess_data`");
+ return true;
}}
$gc_probability = 50;
session_set_save_handler ('ref_session_open', 'ref_session_close',
- 'ref_session_read', 'ref_session_write',
- 'ref_session_destroy', 'ref_session_gc');
+ 'ref_session_read', 'ref_session_write',
+ 'ref_session_destroy', 'ref_session_gc');