aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-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
8 files changed, 244 insertions, 86 deletions
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);