require_once('include/socgraph.php');
require_once('include/plaintext.php');
require_once('include/ostatus.php');
+require_once('include/feed.php');
require_once('mod/share.php');
require_once('library/defuse/php-encryption-1.2.1/Crypto.php');
dbesc($item["uri"]), dbesc($item["network"]));
}
+// Adds a "lang" specification in a "postopts" element of given $arr,
+// if possible and not already present.
+// Expects "body" element to exist in $arr.
+// TODO: add a parameter to request forcing override
+function item_add_language_opt(&$arr) {
+
+ if (version_compare(PHP_VERSION, '5.3.0', '<')) return; // LanguageDetect.php not available ?
+
+ if ( x($arr, 'postopts') )
+ {
+ if ( strstr($arr['postopts'], 'lang=') )
+ {
+ // do not override
+ // TODO: add parameter to request overriding
+ return;
+ }
+ $postopts = $arr['postopts'];
+ }
+ else
+ {
+ $postopts = "";
+ }
+
+ require_once('library/langdet/Text/LanguageDetect.php');
+ $naked_body = preg_replace('/\[(.+?)\]/','',$arr['body']);
+ $l = new Text_LanguageDetect;
+ //$lng = $l->detectConfidence($naked_body);
+ //$arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : '');
+ $lng = $l->detect($naked_body, 3);
+
+ if (sizeof($lng) > 0) {
+ if ($postopts != "") $postopts .= '&'; // arbitrary separator, to be reviewed
+ $postopts .= 'lang=';
+ $sep = "";
+ foreach ($lng as $language => $score) {
+ $postopts .= $sep . $language.";".$score;
+ $sep = ':';
+ }
+ $arr['postopts'] = $postopts;
+ }
+}
+
function item_store($arr,$force_parent = false, $notify = false, $dontcache = false) {
// If it is a posting where users should get notifications, then define it as wall posting
//if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false))
// $arr['body'] = strip_tags($arr['body']);
+ item_add_language_opt($arr);
- if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
- require_once('library/langdet/Text/LanguageDetect.php');
- $naked_body = preg_replace('/\[(.+?)\]/','',$arr['body']);
- $l = new Text_LanguageDetect;
- //$lng = $l->detectConfidence($naked_body);
- //$arr['postopts'] = (($lng['language']) ? 'lang=' . $lng['language'] . ';' . $lng['confidence'] : '');
- $lng = $l->detect($naked_body, 3);
-
- if (sizeof($lng) > 0) {
- $postopts = "";
-
- foreach ($lng as $language => $score) {
- if ($postopts == "")
- $postopts = "lang=";
- else
- $postopts .= ":";
-
- $postopts .= $language.";".$score;
- }
- $arr['postopts'] = $postopts;
- }
- }
+ if ($notify)
+ $guid_prefix = "";
+ else
+ $guid_prefix = $arr['network'];
$arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
- $arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid(32, $arr['network']));
+ $arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid(32, $guid_prefix));
$arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : $arr['guid']);
$arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : '');
- $arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : '');
+ $arr['author-name'] = ((x($arr,'author-name')) ? trim($arr['author-name']) : '');
$arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : '');
$arr['author-avatar'] = ((x($arr,'author-avatar')) ? notags(trim($arr['author-avatar'])) : '');
- $arr['owner-name'] = ((x($arr,'owner-name')) ? notags(trim($arr['owner-name'])) : '');
+ $arr['owner-name'] = ((x($arr,'owner-name')) ? trim($arr['owner-name']) : '');
$arr['owner-link'] = ((x($arr,'owner-link')) ? notags(trim($arr['owner-link'])) : '');
$arr['owner-avatar'] = ((x($arr,'owner-avatar')) ? notags(trim($arr['owner-avatar'])) : '');
$arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
$arr['commented'] = ((x($arr,'commented') !== false) ? datetime_convert('UTC','UTC',$arr['commented']) : datetime_convert());
$arr['received'] = ((x($arr,'received') !== false) ? datetime_convert('UTC','UTC',$arr['received']) : datetime_convert());
$arr['changed'] = ((x($arr,'changed') !== false) ? datetime_convert('UTC','UTC',$arr['changed']) : datetime_convert());
- $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
- $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : '');
+ $arr['title'] = ((x($arr,'title')) ? trim($arr['title']) : '');
+ $arr['location'] = ((x($arr,'location')) ? trim($arr['location']) : '');
$arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : '');
$arr['last-child'] = ((x($arr,'last-child')) ? intval($arr['last-child']) : 0 );
$arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1 );
}
if ($arr['network'] == "") {
- $r = q("SELECT `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
- intval($arr['contact-id']),
+ $r = q("SELECT `network` FROM `contact` WHERE `network` IN ('%s', '%s', '%s') AND `nurl` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS),
+ dbesc(normalise_link($arr['author-link'])),
intval($arr['uid'])
);
+ if(!count($r))
+ $r = q("SELECT `network` FROM `gcontact` WHERE `network` IN ('%s', '%s', '%s') AND `nurl` = '%s' LIMIT 1",
+ dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS),
+ dbesc(normalise_link($arr['author-link']))
+ );
+
+ if(!count($r))
+ $r = q("SELECT `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ intval($arr['contact-id']),
+ intval($arr['uid'])
+ );
+
if(count($r))
$arr['network'] = $r[0]["network"];
// Fill the cache field
put_item_in_cache($arr);
- call_hooks('post_remote',$arr);
+ if ($notify)
+ call_hooks('post_local',$arr);
+ else
+ call_hooks('post_remote',$arr);
if(x($arr,'cancel')) {
logger('item_store: post cancelled by plugin.');
$arr = $unescaped;
// find the item we just created
- $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC ",
+ $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `network` = '%s' ORDER BY `id` ASC ",
dbesc($arr['uri']),
- intval($arr['uid'])
+ intval($arr['uid']),
+ dbesc($arr['network'])
);
if(count($r)) {
$r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post));
if (count($r) == 1) {
- call_hooks('post_remote_end', $r[0]);
+ if ($notify)
+ call_hooks('post_local_end', $r[0]);
+ else
+ call_hooks('post_remote_end', $r[0]);
} else
logger('item_store: new item not found in DB, id ' . $current_post);
}
$rino = get_config('system','rino_encrypt');
$rino = intval($rino);
+ // use RINO1 if mcrypt isn't installed and RINO2 was selected
+ if ($rino==2 and !function_exists('mcrypt_create_iv')) $rino=1;
logger("Local rino version: ". $rino, LOGGER_DEBUG);
function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) {
if ($contact['network'] === NETWORK_OSTATUS) {
if ($pass < 2) {
- // Test - remove before flight
- //$tempfile = tempnam(get_temppath(), "ostatus");
- //file_put_contents($tempfile, $xml);
-
logger("Consume OStatus messages ", LOGGER_DEBUG);
ostatus_import($xml,$importer,$contact, $hub);
}
return;
}
+ if ($contact['network'] === NETWORK_FEED) {
+ if ($pass < 2) {
+ logger("Consume feeds", LOGGER_DEBUG);
+ feed_import($xml,$importer,$contact, $hub);
+ }
+ return;
+ }
+
require_once('library/simplepie/simplepie.inc');
require_once('include/contact_selectors.php');
if(! $item['deleted'])
logger('consume_feed: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
+ if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
+ logger("Deleting event ".$item['event-id'], LOGGER_DEBUG);
+ event_delete($item['event-id']);
+ }
+
if(($item['verb'] === ACTIVITY_TAG) && ($item['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
$xo = parse_xml_string($item['object'],false);
$xt = parse_xml_string($item['target'],false);
$datarray['parent-uri'] = $parent_uri;
$datarray['uid'] = $importer['uid'];
$datarray['contact-id'] = $contact['id'];
- if((activity_match($datarray['verb'],ACTIVITY_LIKE)) || (activity_match($datarray['verb'],ACTIVITY_DISLIKE))) {
+ if(($datarray['verb'] === ACTIVITY_LIKE)
+ || ($datarray['verb'] === ACTIVITY_DISLIKE)
+ || ($datarray['verb'] === ACTIVITY_ATTEND)
+ || ($datarray['verb'] === ACTIVITY_ATTENDNO)
+ || ($datarray['verb'] === ACTIVITY_ATTENDMAYBE)) {
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
// only one like or dislike per person
if((x($datarray,'object-type')) && ($datarray['object-type'] === ACTIVITY_OBJ_EVENT)) {
$ev = bbtoevent($datarray['body']);
- if(x($ev,'desc') && x($ev,'start')) {
+ if((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) {
$ev['uid'] = $importer['uid'];
$ev['uri'] = $item_id;
$ev['edited'] = $datarray['edited'];
$ev['private'] = $datarray['private'];
+ $ev['guid'] = $datarray['guid'];
if(is_array($contact))
$ev['cid'] = $contact['id'];
logger('local_delivery: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
+ if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
+ logger("Deleting event ".$item['event-id'], LOGGER_DEBUG);
+ event_delete($item['event-id']);
+ }
+
if(($item['verb'] === ACTIVITY_TAG) && ($item['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
$xo = parse_xml_string($item['object'],false);
$xt = parse_xml_string($item['target'],false);
$datarray['owner-avatar'] = $own[0]['thumb'];
$datarray['contact-id'] = $importer['id'];
- if(($datarray['verb'] === ACTIVITY_LIKE) || ($datarray['verb'] === ACTIVITY_DISLIKE)) {
+ if(($datarray['verb'] === ACTIVITY_LIKE)
+ || ($datarray['verb'] === ACTIVITY_DISLIKE)
+ || ($datarray['verb'] === ACTIVITY_ATTEND)
+ || ($datarray['verb'] === ACTIVITY_ATTENDNO)
+ || ($datarray['verb'] === ACTIVITY_ATTENDMAYBE)) {
$is_like = true;
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
$datarray['parent-uri'] = $parent_uri;
$datarray['uid'] = $importer['importer_uid'];
$datarray['contact-id'] = $importer['id'];
- if(($datarray['verb'] == ACTIVITY_LIKE) || ($datarray['verb'] == ACTIVITY_DISLIKE)) {
+ if(($datarray['verb'] === ACTIVITY_LIKE)
+ || ($datarray['verb'] === ACTIVITY_DISLIKE)
+ || ($datarray['verb'] === ACTIVITY_ATTEND)
+ || ($datarray['verb'] === ACTIVITY_ATTENDNO)
+ || ($datarray['verb'] === ACTIVITY_ATTENDMAYBE)) {
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
// only one like or dislike per person
if((x($datarray,'object-type')) && ($datarray['object-type'] === ACTIVITY_OBJ_EVENT)) {
$ev = bbtoevent($datarray['body']);
- if(x($ev,'desc') && x($ev,'start')) {
+ if((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) {
$ev['cid'] = $importer['id'];
$ev['uid'] = $importer['uid'];
$ev['uri'] = $item_id;
$ev['edited'] = $datarray['edited'];
$ev['private'] = $datarray['private'];
+ $ev['guid'] = $datarray['guid'];
$r = q("SELECT * FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),