aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--boot.php4
-rw-r--r--database.sql7
-rw-r--r--include/bb2diaspora.php2
-rw-r--r--include/delivery.php18
-rw-r--r--include/diaspora.php31
-rw-r--r--include/items.php165
-rw-r--r--include/notifier.php27
-rw-r--r--include/profile_update.php46
-rw-r--r--include/queue_fn.php38
-rw-r--r--include/text.php3
-rw-r--r--mod/network.php10
-rw-r--r--mod/search.php17
-rw-r--r--mod/tagger.php195
-rw-r--r--update.php10
14 files changed, 472 insertions, 101 deletions
diff --git a/boot.php b/boot.php
index 9623b4b14..6a43806ab 100644
--- a/boot.php
+++ b/boot.php
@@ -9,9 +9,9 @@ require_once('include/nav.php');
require_once('include/cache.php');
define ( 'FRIENDIKA_PLATFORM', 'Free Friendika');
-define ( 'FRIENDIKA_VERSION', '2.3.1140' );
+define ( 'FRIENDIKA_VERSION', '2.3.1143' );
define ( 'DFRN_PROTOCOL_VERSION', '2.21' );
-define ( 'DB_UPDATE_VERSION', 1097 );
+define ( 'DB_UPDATE_VERSION', 1098 );
define ( 'EOL', "<br />\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
diff --git a/database.sql b/database.sql
index c9e239075..5d7a3020c 100644
--- a/database.sql
+++ b/database.sql
@@ -477,7 +477,12 @@ CREATE TABLE IF NOT EXISTS `queue` (
`created` DATETIME NOT NULL ,
`last` DATETIME NOT NULL ,
`content` MEDIUMTEXT NOT NULL,
-`batch` TINYINT( 1 ) NOT NULL DEFAULT '0'
+`batch` TINYINT( 1 ) NOT NULL DEFAULT '0',
+INDEX ( `cid` ),
+INDEX ( `created` ),
+INDEX ( `last` ),
+INDEX ( `network` ),
+INDEX ( `batch` )
) ENGINE = MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `pconfig` (
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index ef5477f1b..d6c7994ba 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -58,7 +58,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
$Text = preg_replace("/\#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[#$2]($1)', $Text);
$Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[$2]($1)', $Text);
-// $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('Image/photo: ') . '$1', $Text);
+ $Text = preg_replace("/\[img\](.*?)\[\/img\]/", '![' . t('image/photo') . '](' . '$1' . ')', $Text);
// $Text = preg_replace("/\[img\](.*?)\[\/img\]/", t('image/photo'), $Text);
// Perform MAIL Search
diff --git a/include/delivery.php b/include/delivery.php
index 8318be4dd..a9e629fcf 100644
--- a/include/delivery.php
+++ b/include/delivery.php
@@ -1,5 +1,6 @@
<?php
require_once("boot.php");
+require_once('include/queue_fn.php');
function delivery_run($argv, $argc){
global $a, $db;
@@ -323,14 +324,7 @@ function delivery_run($argv, $argc){
if($deliver_status == (-1)) {
logger('notifier: delivery failed: queuing message');
- // queue message for redelivery
- q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
- VALUES ( %d, '%s', '%s', '%s') ",
- intval($contact['id']),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($atom)
- );
+ add_to_queue($contact['id'],NETWORK_DFRN,$atom);
}
break;
@@ -370,13 +364,7 @@ function delivery_run($argv, $argc){
$deliver_status = slapper($owner,$contact['notify'],$slappy);
if($deliver_status == (-1)) {
// queue message for redelivery
- q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
- VALUES ( %d, '%s', '%s', '%s') ",
- intval($contact['id']),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($slappy)
- );
+ add_to_queue($contact['id'],NETWORK_OSTATUS,$slappy);
}
}
}
diff --git a/include/diaspora.php b/include/diaspora.php
index 89707967f..2379ae8e3 100644
--- a/include/diaspora.php
+++ b/include/diaspora.php
@@ -4,6 +4,7 @@ require_once('include/crypto.php');
require_once('include/items.php');
require_once('include/bb2diaspora.php');
require_once('include/contact_selectors.php');
+require_once('include/queue_fn.php');
function diaspora_dispatch_public($msg) {
@@ -957,7 +958,7 @@ function diaspora_comment($importer,$xml,$msg) {
);
}
- if(! $parent_author_signature) {
+ if(($parent_item['origin']) && (! $parent_author_signature)) {
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
intval($message_id),
dbesc($author_signed_data),
@@ -1162,9 +1163,9 @@ EOT;
$arr['parent'] = $parent_item['id'];
$arr['parent-uri'] = $parent_item['uri'];
- $arr['owner-name'] = $contact['name'];
- $arr['owner-link'] = $contact['url'];
- $arr['owner-avatar'] = $contact['thumb'];
+ $arr['owner-name'] = $parent_item['name'];
+ $arr['owner-link'] = $parent_item['url'];
+ $arr['owner-avatar'] = $parent_item['thumb'];
$arr['author-name'] = $person['name'];
$arr['author-link'] = $person['url'];
@@ -1206,9 +1207,9 @@ EOT;
// if the message isn't already being relayed, notify others
// the existence of parent_author_signature means the parent_author or owner
- // is already relaying.
+ // is already relaying. The parent_item['origin'] indicates the message was created on our system
- if(! $parent_author_signature)
+ if(($parent_item['origin']) && (! $parent_author_signature))
proc_run('php','include/notifier.php','comment',$message_id);
return;
@@ -1375,6 +1376,14 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
$body = $item['body'];
+/*
+ // We're trying to match Diaspora's split message/photo protocol but
+ // all the photos are displayed on D* as links and not img's - even
+ // though we're sending pretty much precisely what they send us when
+ // doing the same operation.
+ // Commented out for now, we'll use bb2diaspora to convert photos to markdown
+ // which seems to get through intact.
+
$cnt = preg_match_all('|\[img\](.*?)\[\/img\]|',$body,$matches,PREG_SET_ORDER);
if($cnt) {
foreach($matches as $mtch) {
@@ -1388,6 +1397,7 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
$body = str_replace($detail['str'],$mtch[1],$body);
}
}
+*/
$body = xmlify(html_entity_decode(bb2diaspora($body)));
@@ -1647,14 +1657,7 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch) {
if((! $return_code) || (($curl_stat == 503) && (stristr($a->get_curl_headers(),'retry-after')))) {
logger('diaspora_transmit: queue message');
// queue message for redelivery
- q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`,`batch`)
- VALUES ( %d, '%s', '%s', '%s', %d) ",
- intval($contact['id']),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($slap),
- intval($public_batch)
- );
+ add_to_queue($contact['id'],NETWORK_DIASPORA,$slap,$public_batch);
}
diff --git a/include/items.php b/include/items.php
index 8dc997b16..a12cdd911 100644
--- a/include/items.php
+++ b/include/items.php
@@ -617,7 +617,7 @@ function get_atom_elements($feed,$item) {
if(! $body)
$body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
// preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
- $res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
+ $res['target'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) {
$body = html2bb_video($body);
@@ -1263,7 +1263,8 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
$when = datetime_convert('UTC','UTC','now','Y-m-d H:i:s');
}
if($deleted && is_array($contact)) {
- $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
+ $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join `contact` on `item`.`contact-id` = `contact`.id`
+ WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
dbesc($uri),
intval($importer['uid']),
intval($contact['id'])
@@ -1274,6 +1275,41 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
if(! $item['deleted'])
logger('consume_feed: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
+ if(($item['verb'] === ACTIVITY_TAG) && ($item['object-type'] === ACTVITY_OBJ_TAGTERM)) {
+ $xo = parse_xml_string($item['object'],false);
+ $xt = parse_xml_string($item['target'],false);
+ if($xt->type === ACTIVITY_OBJ_NOTE) {
+ $i = q("select * from `item` where uri = '%s' and uid = %d limit 1",
+ dbesc($xt->id),
+ intval($importer['importer_uid'])
+ );
+ if(count($i)) {
+
+ // For tags, the owner cannot remove the tag on the author's copy of the post.
+
+ $owner_remove = (($item['contact-id'] == $i[0]['contact-id']) ? true: false);
+ $author_remove = (($item['origin'] && $item['self']) ? true : false);
+ $author_copy = (($item['origin']) ? true : false);
+
+ if($owner_remove && $author_copy)
+ continue;
+ if($author_remove || $owner_remove) {
+ $tags = explode(',',$i[0]['tag']);
+ $newtags = array();
+ if(count($tags)) {
+ foreach($tags as $tag)
+ if(trim($tag) !== trim($xo->body))
+ $newtags[] = trim($tag);
+ }
+ q("update item set tag = '%s' where id = %d limit 1",
+ dbesc(implode(',',$newtags)),
+ intval($i[0]['id'])
+ );
+ }
+ }
+ }
+ }
+
if($item['uri'] == $item['parent-uri']) {
$r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
`body` = '', `title` = ''
@@ -1420,6 +1456,30 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
$datarray['gravity'] = GRAVITY_LIKE;
}
+ if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
+ $xo = parse_xml_string($datarray['object'],false);
+ $xt = parse_xml_string($datarray['target'],false);
+
+ if($xt->type == ACTIVITY_OBJ_NOTE) {
+ $r = q("select * from item where `uri` = '%s' AND `uid` = %d limit 1",
+ dbesc($xt->id),
+ intval($importer['importer_uid'])
+ );
+ if(! count($r))
+ continue;
+
+ // extract tag, if not duplicate, add to parent item
+ if($xo->content) {
+ if(! (stristr($r[0]['tag'],trim($xo->content)))) {
+ q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1",
+ dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'),
+ intval($r[0]['id'])
+ );
+ }
+ }
+ }
+ }
+
$r = item_store($datarray,$force_parent);
continue;
}
@@ -1797,7 +1857,8 @@ function local_delivery($importer,$data) {
}
if($deleted) {
- $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
+ $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join contact on `item`.`contact-id` = `contact`.`id`
+ WHERE `uri` = '%s' AND `uid` = %d AND `contact-id` = %d LIMIT 1",
dbesc($uri),
intval($importer['importer_uid']),
intval($importer['id'])
@@ -1806,8 +1867,45 @@ function local_delivery($importer,$data) {
if(count($r)) {
$item = $r[0];
- if(! $item['deleted'])
- logger('local_delivery: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
+ if($item['deleted'])
+ continue;
+
+ logger('local_delivery: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
+
+ if(($item['verb'] === ACTIVITY_TAG) && ($item['object-type'] === ACTVITY_OBJ_TAGTERM)) {
+ $xo = parse_xml_string($item['object'],false);
+ $xt = parse_xml_string($item['target'],false);
+ if($xt->type === ACTIVITY_OBJ_NOTE) {
+ $i = q("select * from `item` where uri = '%s' and uid = %d limit 1",
+ dbesc($xt->id),
+ intval($importer['importer_uid'])
+ );
+ if(count($i)) {
+
+ // For tags, the owner cannot remove the tag on the author's copy of the post.
+
+ $owner_remove = (($item['contact-id'] == $i[0]['contact-id']) ? true: false);
+ $author_remove = (($item['origin'] && $item['self']) ? true : false);
+ $author_copy = (($item['origin']) ? true : false);
+
+ if($owner_remove && $author_copy)
+ continue;
+ if($author_remove || $owner_remove) {
+ $tags = explode(',',$i[0]['tag']);
+ $newtags = array();
+ if(count($tags)) {
+ foreach($tags as $tag)
+ if(trim($tag) !== trim($xo->body))
+ $newtags[] = trim($tag);
+ }
+ q("update item set tag = '%s' where id = %d limit 1",
+ dbesc(implode(',',$newtags)),
+ intval($i[0]['id'])
+ );
+ }
+ }
+ }
+ }
if($item['uri'] == $item['parent-uri']) {
$r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s'
@@ -1896,12 +1994,39 @@ function local_delivery($importer,$data) {
$datarray['owner-link'] = $r[0]['url'];
$datarray['owner-avatar'] = $r[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)) {
$is_like = true;
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
$datarray['last-child'] = 0;
}
+
+ if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
+
+
+ $xo = parse_xml_string($datarray['object'],false);
+ $xt = parse_xml_string($datarray['target'],false);
+
+ if(($xt->type == ACTIVITY_OBJ_NOTE) && ($xt->id == $r[0]['uri'])) {
+
+ // extract tag, if not duplicate, and this user allows tags, add to parent item
+ if($xo->content) {
+
+ if(! (stristr($r[0]['tag'],trim($xo->content)))) {
+ $i = q("SELECT `blocktags` FROM `user` where `uid` = %d LIMIT 1",
+ intval($importer['importer_uid'])
+ );
+ if(count($i) && ! ($i[0]['blocktags'])) {
+ q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1",
+ dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'),
+ intval($r[0]['id'])
+ );
+ }
+ }
+ }
+ }
+ }
+
$posted_id = item_store($datarray);
$parent = 0;
@@ -2049,6 +2174,32 @@ function local_delivery($importer,$data) {
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
}
+
+ if(($datarray['verb'] === ACTIVITY_TAG) && ($datarray['object-type'] === ACTIVITY_OBJ_TAGTERM)) {
+
+ $xo = parse_xml_string($datarray['object'],false);
+ $xt = parse_xml_string($datarray['target'],false);
+
+ if($xt->type == ACTIVITY_OBJ_NOTE) {
+ $r = q("select * from item where `uri` = '%s' AND `uid` = %d limit 1",
+ dbesc($xt->id),
+ intval($importer['importer_uid'])
+ );
+ if(! count($r))
+ continue;
+
+ // extract tag, if not duplicate, add to parent item
+ if($xo->content) {
+ if(! (stristr($r[0]['tag'],trim($xo->content)))) {
+ q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1",
+ dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'),
+ intval($r[0]['id'])
+ );
+ }
+ }
+ }
+ }
+
$posted_id = item_store($datarray);
// find out if our user is involved in this conversation and wants to be notified.
@@ -2723,4 +2874,4 @@ function drop_item($id,$interactive = true) {
//NOTREACHED
}
-} \ No newline at end of file
+}
diff --git a/include/notifier.php b/include/notifier.php
index 18ad07012..61274bedf 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -1,6 +1,7 @@
<?php
require_once("boot.php");
+require_once('include/queue_fn.php');
/*
* This file was at one time responsible for doing all deliveries, but this caused
@@ -519,13 +520,7 @@ function notifier_run($argv, $argc){
if($deliver_status == (-1)) {
logger('notifier: delivery failed: queuing message');
// queue message for redelivery
- q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
- VALUES ( %d, '%s', '%s', '%s') ",
- intval($contact['id']),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($atom)
- );
+ add_to_queue($contact['id'],NETWORK_DFRN,$atom);
}
break;
case NETWORK_OSTATUS:
@@ -542,14 +537,7 @@ function notifier_run($argv, $argc){
if($deliver_status == (-1)) {
// queue message for redelivery
- q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
- VALUES ( %d, '%s', '%s', '%s') ",
- intval($contact['id']),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($slap)
- );
-
+ add_to_queue($contact['id'],NETWORK_OSTATUS,$slap);
}
}
else {
@@ -564,13 +552,7 @@ function notifier_run($argv, $argc){
$deliver_status = slapper($owner,$contact['notify'],$slappy);
if($deliver_status == (-1)) {
// queue message for redelivery
- q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
- VALUES ( %d, '%s', '%s', '%s') ",
- intval($contact['id']),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($slappy)
- );
+ add_to_queue($contact['id'],NETWORK_OSTATUS,$slappy);
}
}
}
@@ -802,7 +784,6 @@ function notifier_run($argv, $argc){
call_hooks('notifier_end',$target_item);
-
return;
}
diff --git a/include/profile_update.php b/include/profile_update.php
index 1a2d9d3b5..f2a806cfd 100644
--- a/include/profile_update.php
+++ b/include/profile_update.php
@@ -2,6 +2,7 @@
require_once('include/datetime.php');
require_once('include/diaspora.php');
+require_once('include/queue_fn.php');
function profile_change() {
@@ -11,8 +12,8 @@ function profile_change() {
return;
// $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
- // if($url && strlen(get_config('system','directory_submit_url')))
- // proc_run('php',"include/directory.php","$url");
+// if($url && strlen(get_config('system','directory_submit_url')))
+// proc_run('php',"include/directory.php","$url");
$recips = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s'
AND `uid` = %d AND `rel` != %d ORDER BY rand() ",
@@ -33,24 +34,25 @@ function profile_change() {
return;
$profile = $r[0];
- $handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
- $first = ((strpos($profile['name'],' '))
- ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
- $last = (($first === $profile['name']) ? '' : trim(substr($profile['name'],strlen($first))));
- $large = $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg';
- $medium = $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg';
- $small = $a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg';
- $searchable = (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' );
+ $handle = xmlify($a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3));
+ $first = xmlify(((strpos($profile['name'],' '))
+ ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']));
+ $last = xmlify((($first === $profile['name']) ? '' : trim(substr($profile['name'],strlen($first)))));
+ $large = xmlify($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg');
+ $medium = xmlify($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg');
+ $small = xmlify($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg');
+ $searchable = xmlify((($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ));
+// $searchable = 'true';
if($searchable === 'true') {
$dob = '1000-00-00';
if(($profile['dob']) && ($profile['dob'] != '0000-00-00'))
$dob = ((intval($profile['dob'])) ? intval($profile['dob']) : '1000') . '-' . datetime_convert('UTC','UTC',$profile['dob'],'m-d');
- $gender = $profile['gender'];
- $about = $profile['about'];
+ $gender = xmlify($profile['gender']);
+ $about = xmlify($profile['about']);
require_once('include/bbcode.php');
- $about = strip_tags(bbcode($about));
+ $about = xmlify(strip_tags(bbcode($about)));
$location = '';
if($profile['locality'])
$location .= $profile['locality'];
@@ -64,6 +66,7 @@ function profile_change() {
$location .= ', ';
$location .= $profile['country-name'];
}
+ $location = xmlify($location);
$tags = '';
if($profile['pub_keywords']) {
$kw = str_replace(',',' ',$profile['pub_keywords']);
@@ -76,12 +79,11 @@ function profile_change() {
}
}
}
- $tags = trim($tags);
+ $tags = xmlify(trim($tags));
}
$tpl = get_markup_template('diaspora_profile.tpl');
-
$msg = replace_macros($tpl,array(
'$handle' => $handle,
'$first' => $first,
@@ -98,16 +100,8 @@ function profile_change() {
));
logger('profile_change: ' . $msg, LOGGER_ALL);
- $msgtosend = diaspora_msg_build($msg,$a->user,null,$a->user['prvkey'],null,true);
foreach($recips as $recip) {
- q("insert into queue (`cid`,`network`,`created`,`last`,`content`,`batch`)
- values(%d,'%s','%s','%s','%s',%d)",
- intval($recip['id']),
- dbesc(NETWORK_DIASPORA),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($msgtosend),
- intval(1)
- );
+ $msgtosend = diaspora_msg_build($msg,$a->user,$recip,$a->user['prvkey'],null,true);
+ add_to_queue($recip['id'],NETWORK_DIASPORA,$msgtosend,true);
}
-} \ No newline at end of file
+}
diff --git a/include/queue_fn.php b/include/queue_fn.php
index bc47ceffd..3c1087f4e 100644
--- a/include/queue_fn.php
+++ b/include/queue_fn.php
@@ -14,3 +14,41 @@ function remove_queue_item($id) {
intval($id)
);
}
+
+
+function add_to_queue($cid,$network,$msg,$batch = false) {
+
+ $max_queue = get_config('system','max_contact_queue');
+ if($max_queue < 1)
+ $max_queue = 500;
+
+ $batch_queue = get_config('system','max_batch_queue');
+ if($batch_queue < 1)
+ $batch_queue = 1000;
+
+ $r = q("SELECT COUNT(*) AS `total` FROM `queue` left join `contact` ON `queue`.`cid` = `contact`.`id`
+ WHERE `queue`.`cid` = %d AND `contact`.`self` = 0 ",
+ intval($cid)
+ );
+ if($r && count($r)) {
+ if($batch && ($r[0]['total'] > $batch_queue)) {
+ logger('add_to_queue: too many queued items for batch server ' . $cid . ' - discarding message');
+ return;
+ }
+ elseif((! $batch) && ($r[0]['total'] > $max_queue)) {
+ logger('add_to_queue: too many queued items for contact ' . $cid . ' - discarding message');
+ return;
+ }
+ }
+
+ q("INSERT INTO `queue` ( `cid`, `network`, `created`, `last`, `content`, `batch`)
+ VALUES ( %d, '%s', '%s', '%s', '%s', %d) ",
+ intval($cid),
+ dbesc($network),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($msg),
+ intval(($batch) ? 1: 0)
+ );
+
+}
diff --git a/include/text.php b/include/text.php
index 299410a63..ca8dc5ac3 100644
--- a/include/text.php
+++ b/include/text.php
@@ -195,6 +195,9 @@ function unxmlify($s) {
if(! function_exists('hex2bin')) {
function hex2bin($s) {
+ if(! (is_string($s) && strlen($s)))
+ return '';
+
if(! ctype_xdigit($s)) {
logger('hex2bin: illegal input: ' . print_r(debug_backtrace(), true));
return($s);
diff --git a/mod/network.php b/mod/network.php
index 04c2a1782..491603f35 100644
--- a/mod/network.php
+++ b/mod/network.php
@@ -333,10 +333,14 @@ function network_content(&$a, $update = 0) {
$sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
- if(x($_GET,'search'))
- $sql_extra .= " AND `item`.`body` REGEXP '" . dbesc(escape_tags($_GET['search'])) . "' ";
+ if(x($_GET,'search')) {
+ $search = escape_tags($_GET['search']);
+ $sql_extra .= sprintf(" AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' ) ",
+ dbesc($search),
+ dbesc('\\]' . $search . '\\[')
+ );
+ }
-
$r = q("SELECT COUNT(*) AS `total`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
diff --git a/mod/search.php b/mod/search.php
index 2a8bf1484..e2c365fd3 100644
--- a/mod/search.php
+++ b/mod/search.php
@@ -96,12 +96,15 @@ function search_content(&$a) {
// Only public wall posts can be shown
// OR your own posts if you are a logged in member
- $s_bool = "AND MATCH (`item`.`body`) AGAINST ( '%s' IN BOOLEAN MODE )";
- $s_regx = "AND `item`.`body` REGEXP '%s' ";
- if(mb_strlen($search) >= 3)
- $search_alg = $s_bool;
- else
+// $s_bool = sprintf("AND MATCH (`item`.`body`) AGAINST ( '%s' IN BOOLEAN MODE )", dbesc($search));
+ $s_regx = sprintf("AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' )",
+ dbesc($search), dbesc('\\]' . $search . '\\['));
+
+// if(mb_strlen($search) >= 3)
+// $search_alg = $s_bool;
+// else
+
$search_alg = $s_regx;
$r = q("SELECT COUNT(*) AS `total`
@@ -111,8 +114,7 @@ function search_content(&$a) {
OR `item`.`uid` = %d )
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
$search_alg ",
- intval(local_user()),
- dbesc($search)
+ intval(local_user())
);
if(count($r))
@@ -137,7 +139,6 @@ function search_content(&$a) {
$search_alg
ORDER BY `received` DESC LIMIT %d , %d ",
intval(local_user()),
- dbesc($search),
intval($a->pager['start']),
intval($a->pager['itemspage'])
diff --git a/mod/tagger.php b/mod/tagger.php
new file mode 100644
index 000000000..dd4b8ffea
--- /dev/null
+++ b/mod/tagger.php
@@ -0,0 +1,195 @@
+<?php
+
+require_once('include/security.php');
+require_once('include/bbcode.php');
+require_once('include/items.php');
+
+
+function tagger_content(&$a) {
+
+ if(! local_user() && ! remote_user()) {
+ return;
+ }
+
+ $term= notags(trim($_GET['term']));
+
+ if(! $term)
+ return;
+
+ $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
+
+ logger('tagger: tag ' . $term . ' item ' . $item_id);
+
+
+ $r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1",
+ dbesc($item_id),
+ dbesc($item_id)
+ );
+
+ if(! $item_id || (! count($r))) {
+ logger('tagger: no item ' . $item_id);
+ return;
+ }
+
+ $item = $r[0];
+
+ $owner_uid = $item['uid'];
+
+ $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1",
+ intval($owner_uid)
+ );
+ if(count($r)) {
+ $owner_nick = $r[0]['nickname'];
+ $blocktags = $r[0]['blocktags'];
+ }
+
+// if(local_user() != $owner_uid)
+// return;
+
+ if(remote_user()) {
+ $r = q("select * from contact where id = %d AND `uid` = %d limit 1",
+ intval(remote_user()),
+ intval($item['uid'])
+ );
+ }
+ else {
+ $r = q("select * from contact where self = 1 and uid = %d limit 1",
+ intval(local_user())
+ );
+ }
+ if(count($r))
+ $contact = $r[0];
+ else {
+ logger('tagger: no contact_id');
+ return;
+ }
+
+ $uri = item_new_uri($a->get_hostname(),$owner_uid);
+
+ $post_type = (($item['resource-id']) ? t('photo') : t('status'));
+ $targettype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
+
+ $link = xmlify('<link rel="alternate" type="text/html" href="'
+ . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
+
+ $body = $item['body'];
+
+ $target = <<< EOT
+ <target>
+ <type>$targettype</type>
+ <local>1</local>
+ <id>{$item['uri']}</id>
+ <link>$link</link>
+ <title></title>
+ <content>$body</content>
+ </target>
+EOT;
+
+ $tagid = $a->get_baseurl() . '/search?search=' . $term;
+ $objtype = ACTIVITY_OBJ_TAGTERM;
+
+ $obj = <<< EOT
+ <object>
+ <type>$objtype</type>
+ <local>1</local>
+ <id>$tagid</id>
+ <link>$tagid</link>
+ <title>$term</title>
+ <content>$term</content>
+ </object>
+EOT;
+
+ $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s');
+
+ if(! isset($bodyverb))
+ return;
+
+ $termlink = '#[url=' . $a->get_baseurl() . '/search?search=' . urlencode($term) . ']'. $term . '[/url]';
+
+ $arr = array();
+
+ $arr['uri'] = $uri;
+ $arr['uid'] = $owner_uid;
+ $arr['contact-id'] = $contact['id'];
+ $arr['type'] = 'activity';
+ $arr['wall'] = $item['wall'];
+ $arr['gravity'] = GRAVITY_COMMENT;
+ $arr['parent'] = $item['id'];
+ $arr['parent-uri'] = $item['uri'];
+ $arr['owner-name'] = $item['author-name'];
+ $arr['owner-link'] = $item['author-link'];
+ $arr['owner-avatar'] = $item['author-avatar'];
+ $arr['author-name'] = $contact['name'];
+ $arr['author-link'] = $contact['url'];
+ $arr['author-avatar'] = $contact['thumb'];
+
+ $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
+ $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
+ $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]';
+ $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink );
+
+ $arr['verb'] = ACTIVITY_TAG;
+ $arr['target-type'] = $targettype;
+ $arr['target'] = $target;
+ $arr['object-type'] = $objtype;
+ $arr['object'] = $obj;
+ $arr['allow_cid'] = $item['allow_cid'];
+ $arr['allow_gid'] = $item['allow_gid'];
+ $arr['deny_cid'] = $item['deny_cid'];
+ $arr['deny_gid'] = $item['deny_gid'];
+ $arr['visible'] = 1;
+ $arr['unseen'] = 1;
+ $arr['last-child'] = 1;
+ $arr['origin'] = 1;
+
+ $post_id = item_store($arr);
+
+ q("UPDATE `item` set plink = '%s' where id = %d limit 1",
+ dbesc($a->get_baseurl() . '/display/' . $owner_nick . '/' . $post_id),
+ intval($post_id)
+ );
+
+
+ if(! $item['visible']) {
+ $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ intval($item['id']),
+ intval($owner_uid)
+ );
+ }
+
+ if((! $blocktags) && (! stristr($item['tag'], ']' . $term . '[' ))) {
+ q("update item set tag = '%s' where id = %d limit 1",
+ dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?search=' . $term . ']'. $term . '[/url]'),
+ intval($item['id'])
+ );
+ }
+
+ // if the original post is on this site, update it.
+
+ $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
+ dbesc($item['uri'])
+ );
+ if(count($r)) {
+ $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
+ intval($r[0]['uid'])
+ );
+ if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) {
+ q("update item set tag = '%s' where id = %d limit 1",
+ dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?search=' . $term . ']'. $term . '[/url]'),
+ intval($r[0]['id'])
+ );
+ }
+
+ }
+
+
+ $arr['id'] = $post_id;
+
+ call_hooks('post_local_end', $arr);
+
+ proc_run('php',"include/notifier.php","tag","$post_id");
+
+ return; // NOTREACHED
+
+
+} \ No newline at end of file
diff --git a/update.php b/update.php
index ed6b9e05e..c85962691 100644
--- a/update.php
+++ b/update.php
@@ -1,6 +1,6 @@
<?php
-define( 'UPDATE_VERSION' , 1097 );
+define( 'UPDATE_VERSION' , 1098 );
/**
*
@@ -800,4 +800,12 @@ function update_1096() {
q("ALTER TABLE `item` ADD `origin` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deleted` , ADD INDEX ( `origin` ) ");
}
+function update_1097() {
+ q("ALTER TABLE `queue`
+ ADD INDEX (`cid`),
+ ADD INDEX (`created`),
+ ADD INDEX (`last`),
+ ADD INDEX (`network`),
+ ADD INDEX (`batch`) ");
+}