aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Scrape.php30
-rw-r--r--include/api.php10
-rw-r--r--include/bb2diaspora.php50
-rw-r--r--include/bbcode.php47
-rw-r--r--include/cache.php29
-rw-r--r--include/contact_widgets.php2
-rw-r--r--include/conversation.php3
-rw-r--r--include/delivery.php18
-rw-r--r--include/diaspora.php169
-rw-r--r--include/event.php7
-rw-r--r--include/items.php175
-rw-r--r--include/nav.php2
-rw-r--r--include/network.php9
-rw-r--r--include/notifier.php42
-rw-r--r--include/oembed.php109
-rw-r--r--include/poller.php36
-rw-r--r--include/profile_update.php107
-rw-r--r--include/queue_fn.php38
-rw-r--r--include/socgraph.php185
-rw-r--r--include/template_processor.php4
-rw-r--r--include/text.php40
21 files changed, 944 insertions, 168 deletions
diff --git a/include/Scrape.php b/include/Scrape.php
index 642b8e624..e42d22afc 100644
--- a/include/Scrape.php
+++ b/include/Scrape.php
@@ -30,8 +30,11 @@ function scrape_dfrn($url) {
}
}
-
- $dom = HTML5_Parser::parse($s);
+ try {
+ $dom = HTML5_Parser::parse($s);
+ } catch (DOMException $e) {
+ logger('scrape_dfrn: parse error: ' . $e);
+ }
if(! $dom)
return $ret;
@@ -132,9 +135,11 @@ function scrape_meta($url) {
}
}
-
-
- $dom = HTML5_Parser::parse($s);
+ try {
+ $dom = HTML5_Parser::parse($s);
+ } catch (DOMException $e) {
+ logger('scrape_meta: parse error: ' . $e);
+ }
if(! $dom)
return $ret;
@@ -177,7 +182,11 @@ function scrape_vcard($url) {
}
}
- $dom = HTML5_Parser::parse($s);
+ try {
+ $dom = HTML5_Parser::parse($s);
+ } catch (DOMException $e) {
+ logger('scrape_vcard: parse error: ' . $e);
+ }
if(! $dom)
return $ret;
@@ -243,7 +252,11 @@ function scrape_feed($url) {
}
}
- $dom = HTML5_Parser::parse($s);
+ try {
+ $dom = HTML5_Parser::parse($s);
+ } catch (DOMException $e) {
+ logger('scrape_feed: parse error: ' . $e);
+ }
if(! $dom)
return $ret;
@@ -356,6 +369,8 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$hcard = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
$profile = unamp($link['@attributes']['href']);
+ if($link['@attributes']['rel'] === 'http://portablecontacts.net/spec/1.0')
+ $poco = unamp($link['@attributes']['href']);
if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') {
$diaspora_base = unamp($link['@attributes']['href']);
$diaspora = true;
@@ -671,6 +686,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$result['poll'] = $poll;
$result['request'] = $request;
$result['confirm'] = $confirm;
+ $result['poco'] = $poco;
$result['photo'] = $vcard['photo'];
$result['priority'] = $priority;
$result['network'] = $network;
diff --git a/include/api.php b/include/api.php
index d8942bfff..1196e0aac 100644
--- a/include/api.php
+++ b/include/api.php
@@ -421,14 +421,6 @@
return $ret;
}
- /**
- * apply xmlify() to all values of array $val, recursively
- */
- function api_xmlify($val){
- if (is_bool($val)) return $val?"true":"false";
- if (is_array($val)) return array_map('api_xmlify', $val);
- return xmlify((string) $val);
- }
/**
* load api $templatename for $type and replace $data array
@@ -441,7 +433,7 @@
case "atom":
case "rss":
case "xml":
- $data = api_xmlify($data);
+ $data = array_xmlify($data);
$tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
$ret = replace_macros($tpl, $data);
break;
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index ef5477f1b..0721d27f6 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -11,15 +11,49 @@ function diaspora2bb($s) {
$s = preg_replace('/\@\{(.+?)\; (.+?)\@(.+?)\}/','@[url=https://$3/u/$2]$1[/url]',$s);
$s = Markdown($s);
$s = html2bbcode($s);
+ $s = str_replace('*','*',$s);
$s = preg_replace("/\[url\=?(.*?)\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/url\]/ism",'[youtube]$2[/youtube]',$s);
+ $s = preg_replace("/\[url\=https?:\/\/www.youtube.com\/watch\?v\=(.*?)\].*?\[\/url\]/ism",'[youtube]$1[/youtube]',$s);
$s = preg_replace("/\[url\=?(.*?)\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/url\]/ism",'[vimeo]$2[/vimeo]',$s);
-
+ $s = preg_replace("/\[url\=https?:\/\/vimeo.com\/([0-9]+)\](.*?)\[\/url\]/ism",'[vimeo]$1[/vimeo]',$s);
+ $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)(vimeo|youtu|www\.youtube|soundcloud)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url]$2$3$4[/url]',$s);
+ $s = scale_diaspora_images($s);
return $s;
}
+function scale_diaspora_images($s,$include_link = true) {
+
+ $matches = null;
+ $c = preg_match_all('/\[img\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER);
+ if($c) {
+ require_once('include/Photo.php');
+ foreach($matches as $mtch) {
+ logger('scale_diaspora_image: ' . $mtch[1]);
+ $i = fetch_url($mtch[1]);
+ if($i) {
+ $ph = new Photo($i);
+ if($ph->is_valid()) {
+ if($ph->getWidth() > 600 || $ph->getHeight() > 600) {
+ $ph->scaleImage(600);
+ $new_width = $ph->getWidth();
+ $new_height = $ph->getHeight();
+ logger('scale_diaspora_image: ' . $new_width . 'w ' . $new_height . 'h' . 'match: ' . $mtch[0], LOGGER_DEBUG);
+ $s = str_replace($mtch[0],'[img=' . $new_width . 'x' . $new_height. ']' . $mtch[1] . '[/img]'
+ . "\n" . ((! $include_link)
+ ? '[url=' . $mtch[1] . ']' . t('view full size') . '[/url]' . "\n"
+ : ''),$s);
+ logger('scale_diaspora_image: new string: ' . $s, LOGGER_DEBUG);
+ }
+ }
+ }
+ }
+ }
+ return $s;
+}
+
function stripdcode_br_cb($s) {
- return '[code]' . str_replace('<br />', '', $s[1]) . '[/code]';
+ return '[code]' . str_replace('<br />', "\n\t", $s[1]) . '[/code]';
}
@@ -53,12 +87,14 @@ function bb2diaspora($Text,$preserve_nl = false) {
// [img]pathtoimage[/img]
+ $Text = preg_replace("/\[bookmark\]([$URLSearchString]*)\[\/bookmark\]/ism", '[$1]($1)', $Text);
+ $Text = preg_replace("/\[bookmark\=([$URLSearchString]*)\](.*?)\[\/bookmark\]/ism", '[$2]($1)', $Text);
$Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '[$1]($1)', $Text);
$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
@@ -117,17 +153,17 @@ function bb2diaspora($Text,$preserve_nl = false) {
$Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/is",'stripdcode_br_cb',$Text);
-// $CodeLayout = '<code>$1</code>';
+ // $CodeLayout = '<code>$1</code>';
// Check for [code] text
- $Text = preg_replace("/\[code\](.*?)\[\/code\]/is","```$1```", $Text);
+ $Text = preg_replace("/\[code\](.*?)\[\/code\]/is","\t$1\n", $Text);
// Declare the format for [quote] layout
-// $QuoteLayout = '<blockquote>$1</blockquote>';
+ // $QuoteLayout = '<blockquote>$1</blockquote>';
// Check for [quote] text
-// $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/is","$QuoteLayout", $Text);
+ $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/is",">$1\n\n", $Text);
// Images
diff --git a/include/bbcode.php b/include/bbcode.php
index b33be686e..8c565add6 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -9,6 +9,21 @@ function stripcode_br_cb($s) {
return '[code]' . str_replace('<br />', '', $s[1]) . '[/code]';
}
+function tryoembed($match){
+ $url = ((count($match)==2)?$match[1]:$match[2]);
+
+ $o = oembed_fetch_url($url);
+
+ //echo "<pre>"; var_dump($match, $url, $o); killme();
+
+ if ($o->type=="error") return $match[0];
+
+ $html = oembed_format_object($o);
+ return $html; //oembed_iframe($html,$o->width,$o->height);
+
+}
+
+
// BBcode 2 HTML was written by WAY2WEB.net
// extended to work with Mistpark/Friendika - Mike Macgirvin
@@ -40,11 +55,15 @@ function bbcode($Text,$preserve_nl = false) {
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString;
- // Perform URL Search
+ // Perform URL Search
$Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text);
+
+ $Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text);
+ $Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$Text);
+ $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text);
$Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="external-link">$1</a>', $Text);
$Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1" target="external-link">$2</a>', $Text);
//$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
@@ -76,6 +95,10 @@ function bbcode($Text,$preserve_nl = false) {
$Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","<span style=\"font-size: $1;\">$2</span>",$Text);
// Check for list text
+
+ if(stristr($Text,'[/list]'))
+ $Text = str_replace("[*]", "<li>", $Text);
+
$Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet">$1</ul>' ,$Text);
$Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ul class="listdecimal">$1</ul>' ,$Text);
$Text = preg_replace("/\[list=i\](.*?)\[\/list\]/sm",'<ul class="listlowerroman">$1</ul>' ,$Text);
@@ -92,7 +115,6 @@ function bbcode($Text,$preserve_nl = false) {
$Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '<table border="0" >$1</table>' ,$Text);
-// $Text = str_replace("[*]", "<li>", $Text);
// Check for font change text
$Text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm","<span style=\"font-family: $1;\">$2</span>",$Text);
@@ -120,6 +142,13 @@ function bbcode($Text,$preserve_nl = false) {
// [img]pathtoimage[/img]
$Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
+
+
+ // Try to Oembed
+ $Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text);
+ $Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text);
+
+
// html5 video and audio
$Text = preg_replace("/\[video\](.*?)\[\/video\]/ism", '<video src="$1" controls="controls" width="425" height="350"><a href="$1">$1</a></video>', $Text);
@@ -129,17 +158,25 @@ function bbcode($Text,$preserve_nl = false) {
$Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '<iframe src="$1" width="425" height="350"><a href="$1">$1</a></iframe>', $Text);
- if (get_pconfig(local_user(), 'oembed', 'use_for_youtube' )==1){
+ /*if (get_pconfig(local_user(), 'oembed', 'use_for_youtube' )==1){
// use oembed for youtube links
$Text = preg_replace("/\[youtube\]/",'[embed]',$Text);
$Text = preg_replace("/\[\/youtube\]/",'[/embed]',$Text);
- } else {
+ } else {*/
// Youtube extensions
+ $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
+ $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text);
+
$Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
+
+
$Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '<iframe width="425" height="350" src="http://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $Text);
- }
+ //}
+
+ $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
+ $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
$Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
$Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
diff --git a/include/cache.php b/include/cache.php
new file mode 100644
index 000000000..082974c61
--- /dev/null
+++ b/include/cache.php
@@ -0,0 +1,29 @@
+<?php
+ /**
+ * cache api
+ */
+
+ class Cache {
+ public static function get($key){
+ $r = q("SELECT `v` FROM `cache` WHERE `k`='%s'",
+ dbesc($key)
+ );
+
+ if (count($r)) return $r[0]['v'];
+ return null;
+ }
+
+ public static function set($key,$value) {
+ q("INSERT INTO `cache` VALUES ('%s','%s','%s')",
+ dbesc($key),
+ dbesc($value),
+ dbesc(datetime_convert()));
+ }
+
+ public static function clear(){
+ q("DELETE FROM `cache` WHERE `updated` < '%s'",
+ dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
+ }
+
+ }
+
diff --git a/include/contact_widgets.php b/include/contact_widgets.php
index efb833aaf..3a21ff2c6 100644
--- a/include/contact_widgets.php
+++ b/include/contact_widgets.php
@@ -32,9 +32,11 @@ function findpeople_widget() {
'$label' => t('Connect/Follow'),
'$hint' => t('Examples: Robert Morgenstein, Fishing'),
'$findthem' => t('Find'),
+ '$suggest' => t('Friend Suggestions'),
'$similar' => t('Similar Interests'),
'$inv' => $inv
));
}
+
diff --git a/include/conversation.php b/include/conversation.php
index 29fa77902..dec70c1a9 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -466,6 +466,8 @@ function conversation(&$a, $items, $mode, $update) {
'classdo' => (($item['starred']) ? "hidden" : ""),
'classundo' => (($item['starred']) ? "" : "hidden"),
'starred' => t('starred'),
+ 'tagger' => t("add tag"),
+ 'classtagger' => "",
);
}
@@ -747,6 +749,7 @@ function status_editor($a,$x, $notes_cid = 0) {
'$linkurl' => t('Please enter a link URL:'),
'$vidurl' => t("Please enter a video link/URL:"),
'$audurl' => t("Please enter an audio link/URL:"),
+ '$term' => t('Tag term:'),
'$whereareu' => t('Where are you right now?'),
'$title' => t('Enter a title for this item')
));
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 99ef5025d..7e1e034d6 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) {
@@ -64,6 +65,9 @@ function diaspora_dispatch($importer,$msg) {
elseif($xmlbase->retraction) {
$ret = diaspora_retraction($importer,$xmlbase->retraction,$msg);
}
+ elseif($xmlbase->signed_retraction) {
+ $ret = diaspora_signed_retraction($importer,$xmlbase->retraction,$msg);
+ }
elseif($xmlbase->photo) {
$ret = diaspora_photo($importer,$xmlbase->photo,$msg);
}
@@ -91,12 +95,14 @@ function find_diaspora_person_by_handle($handle) {
dbesc($handle)
);
if(count($r)) {
+ logger('find_diaspora_person_by handle: in cache ' . print_r($r,true), LOGGER_DEBUG);
// update record occasionally so it doesn't get stale
$d = strtotime($r[0]['updated'] . ' +00:00');
if($d > strtotime('now - 14 days'))
return $r[0];
$update = true;
}
+ logger('find_diaspora_person_by_handle: refresh',LOGGER_DEBUG);
require_once('include/Scrape.php');
$r = probe_url($handle, PROBE_DIASPORA);
if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) {
@@ -448,13 +454,14 @@ function diaspora_request($importer,$xml) {
$batch = (($ret['batch']) ? $ret['batch'] : implode('/', array_slice(explode('/',$ret['url']),0,3)) . '/receive/public');
- $r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
- VALUES ( %d, '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d) ",
+ $r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
+ VALUES ( %d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d) ",
intval($importer['uid']),
dbesc($ret['network']),
dbesc($ret['addr']),
datetime_convert(),
dbesc($ret['url']),
+ dbesc(normalise_link($ret['url'])),
dbesc($batch),
dbesc($ret['name']),
dbesc($ret['nick']),
@@ -589,10 +596,13 @@ function diaspora_post($importer,$xml) {
function diaspora_reshare($importer,$xml) {
+ logger('diaspora_reshare: init: ' . print_r($xml,true));
+
$a = get_app();
$guid = notags(unxmlify($xml->guid));
$diaspora_handle = notags(unxmlify($xml->diaspora_handle));
+
$contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
if(! $contact)
return;
@@ -624,15 +634,23 @@ function diaspora_reshare($importer,$xml) {
logger('diaspora_reshare: unable to fetch source url ' . $source_url);
return;
}
+ logger('diaspora_reshare: source: ' . $x);
+
$x = str_replace(array('<activity_streams-photo>','</activity_streams-photo>'),array('<asphoto>','</asphoto>'),$x);
$source_xml = parse_xml_string($x,false);
- if(strlen($source_xml->asphoto->objectId) && ($source_xml->asphoto->objectId != 0) && ($source_xml->asphoto->image_url))
- $body = '[url=' . notags(unxmlify($source_xml->asphoto->image_url)) . '][img]' . notags(unxmlify($source_xml->asphoto->objectId)) . '[/img][/url]' . "\n";
- elseif($source_xml->asphoto->image_url)
- $body = '[img]' . notags(unxmlify($source_xml->asphoto->image_url)) . '[/img]' . "\n";
- elseif($source_xml->status_message) {
- $body = diaspora2bb($source_xml->status_message->raw_message);
+ if(strlen($source_xml->post->asphoto->objectId) && ($source_xml->post->asphoto->objectId != 0) && ($source_xml->post->asphoto->image_url)) {
+ $body = '[url=' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '][img]' . notags(unxmlify($source_xml->post->asphoto->objectId)) . '[/img][/url]' . "\n";
+ $body = scale_diaspora_images($body,false);
+ }
+ elseif($source_xml->post->asphoto->image_url) {
+ $body = '[img]' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '[/img]' . "\n";
+ $body = scale_diaspora_images($body);
+ }
+ elseif($source_xml->post->status_message) {
+ $body = diaspora2bb($source_xml->post->status_message->raw_message);
+ $body = scale_diaspora_images($body);
+
}
else {
logger('diaspora_reshare: no reshare content found: ' . print_r($source_xml,true));
@@ -668,8 +686,6 @@ function diaspora_reshare($importer,$xml) {
$created = unxmlify($xml->created_at);
$private = ((unxmlify($xml->public) == 'false') ? 1 : 0);
- $body = diaspora2bb($xml->raw_message);
-
$datarray = array();
$str_tags = '';
@@ -765,16 +781,19 @@ function diaspora_asphoto($importer,$xml) {
$created = unxmlify($xml->created_at);
$private = ((unxmlify($xml->public) == 'false') ? 1 : 0);
- if(strlen($xml->objectId) && ($xml->objectId != 0) && ($xml->image_url))
+ if(strlen($xml->objectId) && ($xml->objectId != 0) && ($xml->image_url)) {
$body = '[url=' . notags(unxmlify($xml->image_url)) . '][img]' . notags(unxmlify($xml->objectId)) . '[/img][/url]' . "\n";
- elseif($xml->image_url)
+ $body = scale_diaspora_images($body,false);
+ }
+ elseif($xml->image_url) {
$body = '[img]' . notags(unxmlify($xml->image_url)) . '[/img]' . "\n";
+ $body = scale_diaspora_images($body);
+ }
else {
logger('diaspora_asphoto: no photo url found.');
return;
}
-
$datarray = array();
@@ -943,7 +962,10 @@ function diaspora_comment($importer,$xml,$msg) {
$datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']);
$datarray['body'] = $body;
$datarray['tag'] = $str_tags;
- $datarray['app'] = 'Diaspora';
+
+ // We can't be certain what the original app is if the message is relayed.
+ if(($parent_item['origin']) && (! $parent_author_signature))
+ $datarray['app'] = 'Diaspora';
$message_id = item_store($datarray);
@@ -954,7 +976,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),
@@ -1010,6 +1032,8 @@ function diaspora_photo($importer,$xml,$msg) {
$link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n";
+ $link_text = scale_diaspora_images($link_text);
+
if(strpos($parent_item['body'],$link_text) === false) {
$r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d limit 1",
dbesc($link_text . $parent_item['body']),
@@ -1159,9 +1183,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'];
@@ -1203,9 +1227,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;
@@ -1243,6 +1267,51 @@ function diaspora_retraction($importer,$xml) {
// NOTREACHED
}
+function diaspora_signed_retraction($importer,$xml) {
+
+ $guid = notags(unxmlify($xml->target_guid));
+ $diaspora_handle = notags(unxmlify($xml->sender_handle));
+ $type = notags(unxmlify($xml->target_type));
+ $sig = notags(unxmlify($xml->target_author_signature));
+
+ $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
+ if(! $contact)
+ return;
+
+ // this may not yet work for comments. Need to see how the relaying works
+ // and figure out who signs it.
+
+
+ $signed_data = $guid . ';' . $type ;
+
+ $sig = base64_decode($sig);
+
+ $key = $msg['key'];
+
+ if(! rsa_verify($signed_data,$sig,$key,'sha256')) {
+ logger('diaspora_signed_retraction: owner verification failed.' . print_r($msg,true));
+ return;
+ }
+
+ if($type === 'StatusMessage') {
+ $r = q("select * from item where guid = '%s' and uid = %d limit 1",
+ dbesc('guid'),
+ intval($importer['uid'])
+ );
+ if(count($r)) {
+ if(link_compare($r[0]['author-link'],$contact['url'])) {
+ q("update item set `deleted` = 1, `changed` = '%s' where `id` = %d limit 1",
+ dbesc(datetime_convert()),
+ intval($r[0]['id'])
+ );
+ }
+ }
+ }
+
+ return 202;
+ // NOTREACHED
+}
+
function diaspora_profile($importer,$xml) {
$a = get_app();
@@ -1372,6 +1441,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) {
@@ -1382,12 +1459,24 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
$detail['guid'] = $item['guid'];
$detail['handle'] = $myaddr;
$images[] = $detail;
- $body = str_replace($detail['str'],t('link'),$body);
+ $body = str_replace($detail['str'],$mtch[1],$body);
}
}
+*/
$body = xmlify(html_entity_decode(bb2diaspora($body)));
+ if($item['attach']) {
+ $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism',$item['attach'],$matches,PREG_SET_ORDER);
+ if(cnt) {
+ $body .= "\n" . t('Attachments:') . "\n";
+ foreach($matches as $mtch) {
+ $body .= '[' . $mtch[3] . '](' . $mtch[1] . ')' . "\n";
+ }
+ }
+ }
+
+
$public = (($item['private']) ? 'false' : 'true');
require_once('include/datetime.php');
@@ -1618,11 +1707,14 @@ function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) {
$a = get_app();
$myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
- $tpl = get_markup_template('diaspora_retract.tpl');
+ $signed_text = $item['guid'] . ';' . 'StatusMessage';
+
+ $tpl = get_markup_template('diaspora_signed_retract.tpl');
$msg = replace_macros($tpl, array(
'$guid' => $item['guid'],
- '$type' => 'Post',
- '$handle' => $myaddr
+ '$type' => 'StatusMessage',
+ '$handle' => $myaddr,
+ '$signature' => base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'))
));
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
@@ -1636,22 +1728,35 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch) {
$a = get_app();
$logid = random_string(4);
- logger('diaspora_transmit: ' . $logid . ' ' . (($public_batch) ? $contact['batch'] : $contact['notify']));
- post_url((($public_batch) ? $contact['batch'] : $contact['notify']) . '/',$slap);
+ $dest_url = (($public_batch) ? $contact['batch'] : $contact['notify']);
+ if(! $dest_url) {
+ logger('diaspora_transmit: no url for contact: ' . $contact['id'] . ' batch mode =' . $public_batch);
+ return 0;
+ }
+
+ logger('diaspora_transmit: ' . $logid . ' ' . $dest_url);
+
+ post_url($dest_url . '/', $slap);
+
$return_code = $a->get_curl_code();
logger('diaspora_transmit: ' . $logid . ' returns: ' . $return_code);
- if((! $return_code) || (($curl_stat == 503) && (stristr($a->get_curl_headers(),'retry-after')))) {
+ if((! $return_code) || (($return_code == 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) ",
+
+ $r = q("SELECT id from queue where cid = %d and network = '%s' and content = '%s' and batch = %d limit 1",
intval($contact['id']),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
+ dbesc(NETWORK_DIASPORA),
dbesc($slap),
intval($public_batch)
);
+ if(count($r)) {
+ logger('diaspora_transmit: add_to_queue ignored - identical item already in queue');
+ }
+ else {
+ // queue message for redelivery
+ add_to_queue($contact['id'],NETWORK_DIASPORA,$slap,$public_batch);
+ }
}
diff --git a/include/event.php b/include/event.php
index 746422a13..c7669b381 100644
--- a/include/event.php
+++ b/include/event.php
@@ -53,7 +53,12 @@ function parse_event($h) {
$ret = array();
- $dom = HTML5_Parser::parse($h);
+
+ try {
+ $dom = HTML5_Parser::parse($h);
+ } catch (DOMException $e) {
+ logger('parse_event: parse error: ' . $e);
+ }
if(! $dom)
return $ret;
diff --git a/include/items.php b/include/items.php
index 8dc997b16..2af2b5f55 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 `item`.`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'
@@ -1867,7 +1965,8 @@ function local_delivery($importer,$data) {
// was the top-level post for this reply written by somebody on this site?
// Specifically, the recipient?
- $r = q("select `item`.`id`, `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`
+ $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`,
+ `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item`
LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `contact`.`self` = 1 AND `item`.`wall` = 1 AND `item`.`uri` = '%s' AND `item`.`parent-uri` = '%s'
AND `item`.`uid` = %d LIMIT 1",
@@ -1896,12 +1995,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 +2175,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.
@@ -2236,12 +2388,13 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
// create contact record
- $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `name`, `nick`, `photo`, `network`, `rel`,
+ $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `name`, `nick`, `photo`, `network`, `rel`,
`blocked`, `readonly`, `pending`, `writable` )
- VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 1, 1 ) ",
+ VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, 0, 1, 1 ) ",
intval($importer['uid']),
dbesc(datetime_convert()),
dbesc($url),
+ dbesc(normalise_link($url)),
dbesc($name),
dbesc($nick),
dbesc($photo),
@@ -2523,7 +2676,7 @@ function item_getfeedtags($item) {
if($cnt) {
for($x = 0; $x < count($matches); $x ++) {
if($matches[1][$x])
- $ret[] = array('#',$matches[1][$x], $matches[2][$x]);
+ $ret[] = array('@',$matches[1][$x], $matches[2][$x]);
}
}
return $ret;
@@ -2723,4 +2876,4 @@ function drop_item($id,$interactive = true) {
//NOTREACHED
}
-} \ No newline at end of file
+}
diff --git a/include/nav.php b/include/nav.php
index 5c24df51e..62a8a6d11 100644
--- a/include/nav.php
+++ b/include/nav.php
@@ -147,7 +147,7 @@ function nav(&$a) {
$banner = get_config('system','banner');
if($banner === false)
- $banner .= '<a href="http://project.friendika.com"><img id="logo-img" src="images/friendika-32.png" alt="logo" /></a><span id="logo-text"><a href="http://project.friendika.com">Friendika</a></span>';
+ $banner .= '<a href="http://project.friendika.com"><img id="logo-img" src="images/friendika-32.png" alt="logo" /></a><span id="logo-text"><a href="http://project.friendika.com">Friendica</a></span>';
$tpl = get_markup_template('nav.tpl');
diff --git a/include/network.php b/include/network.php
index ec99d1e0d..a9ee3f0a5 100644
--- a/include/network.php
+++ b/include/network.php
@@ -429,7 +429,12 @@ function lrdd($uri) {
// don't try and parse raw xml as html
if(! strstr($html,'<?xml')) {
require_once('library/HTML5/Parser.php');
- $dom = @HTML5_Parser::parse($html);
+
+ try {
+ $dom = HTML5_Parser::parse($html);
+ } catch (DOMException $e) {
+ logger('lrdd: parse error: ' . $e);
+ }
if($dom) {
$items = $dom->getElementsByTagName('link');
@@ -727,7 +732,6 @@ function add_fcontact($arr,$update = false) {
dbesc($arr['notify']),
dbesc($arr['poll']),
dbesc($arr['confirm']),
- dbesc($arr['network']),
dbesc($arr['alias']),
dbesc($arr['pubkey']),
dbesc(datetime_convert()),
@@ -755,5 +759,6 @@ function add_fcontact($arr,$update = false) {
dbesc(datetime_convert())
);
}
+
return $r;
}
diff --git a/include/notifier.php b/include/notifier.php
index 18ad07012..a4fe9b71e 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
@@ -205,7 +206,7 @@ function notifier_run($argv, $argc){
/**
*
- * Be VERY CAREFUL if you make any changes to the following lines. Seemingly innocuous changes
+ * Be VERY CAREFUL if you make any changes to the following several lines. Seemingly innocuous changes
* have been known to cause runaway conditions which affected several servers, along with
* permissions issues.
*
@@ -217,6 +218,17 @@ function notifier_run($argv, $argc){
$relay_to_owner = true;
}
+ // until the 'origin' flag has been in use for several months
+ // we will just use it as a fallback test
+ // later we will be able to use it as the primary test of whether or not to relay.
+
+ if(! $target_item['origin'])
+ $relay_to_owner = false;
+
+ if($parent['origin'])
+ $relay_to_owner = false;
+
+
if($relay_to_owner) {
logger('notifier: followup', LOGGER_DEBUG);
@@ -519,13 +531,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 +548,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 +563,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);
}
}
}
@@ -728,7 +721,7 @@ function notifier_run($argv, $argc){
if($public_message) {
$r1 = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s'
- AND `uid` = %d AND `rel` != %d ORDER BY rand() ",
+ AND `uid` = %d AND `rel` != %d group by `batch` ORDER BY rand() ",
dbesc(NETWORK_DIASPORA),
intval($owner['uid']),
intval(CONTACT_IS_SHARING)
@@ -802,7 +795,6 @@ function notifier_run($argv, $argc){
call_hooks('notifier_end',$target_item);
-
return;
}
diff --git a/include/oembed.php b/include/oembed.php
index 06f71a3b3..3e86627e4 100644
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -1,36 +1,37 @@
<?php
function oembed_replacecb($matches){
+ logger('oembedcb');
$embedurl=$matches[1];
$j = oembed_fetch_url($embedurl);
- return oembed_format_object($j);
+ $s = oembed_format_object($j);
+ return $s;//oembed_iframe($s,$j->width,$j->height);
+
+
}
function oembed_fetch_url($embedurl){
-
- $r = q("SELECT v FROM `cache` WHERE k='%s'",
- dbesc($embedurl));
+
+ $txt = Cache::get($embedurl);
- if(count($r)){
- $txt = $r[0]['v'];
- } else {
+ if(is_null($txt)){
$txt = "";
// try oembed autodiscovery
$redirects = 0;
$html_text = fetch_url($embedurl, false, $redirects, 15);
- if(! $html_text)
- return;
- $dom = @DOMDocument::loadHTML($html_text);
- if ($dom){
- $xpath = new DOMXPath($dom);
- $attr = "oembed";
-
- $xattr = oe_build_xpath("class","oembed");
- $entries = $xpath->query("//link[@type='application/json+oembed']");
- foreach($entries as $e){
- $href = $e->getAttributeNode("href")->nodeValue;
- $txt = fetch_url($href);
+ if($html_text){
+ $dom = @DOMDocument::loadHTML($html_text);
+ if ($dom){
+ $xpath = new DOMXPath($dom);
+ $attr = "oembed";
+
+ $xattr = oe_build_xpath("class","oembed");
+ $entries = $xpath->query("//link[@type='application/json+oembed']");
+ foreach($entries as $e){
+ $href = $e->getAttributeNode("href")->nodeValue;
+ $txt = fetch_url($href);
+ }
}
}
@@ -44,10 +45,8 @@ function oembed_fetch_url($embedurl){
if ($txt[0]!="{") $txt='{"type":"error"}';
//save in cache
- /*q("INSERT INTO `cache` VALUES ('%s','%s','%s')",
- dbesc($embedurl),
- dbesc($txt),
- dbesc(datetime_convert()));*/
+ Cache::set($embedurl,$txt);
+
}
$j = json_decode($txt);
@@ -57,18 +56,27 @@ function oembed_fetch_url($embedurl){
function oembed_format_object($j){
$embedurl = $j->embedurl;
+ $jhtml = oembed_iframe($j->html,$j->width,$j->height );
$ret="<span class='oembed ".$j->type."'>";
switch ($j->type) {
case "video": {
if (isset($j->thumbnail_url)) {
- /*$tw = (isset($j->thumbnail_width)) ? $j->thumbnail_width:200;
- $th = (isset($j->thumbnail_height)) ? $j->thumbnail_height:180;*/
- $tw=150; $th=120;
- $ret.= "<a href='".$embedurl."' onclick='this.innerHTML=unescape(\"".urlencode($j->html)."\").replace(/\+/g,\" \"); return false;' style='float:left; margin: 1em; '>";
- $ret.= "<img width='$tw' height='$th' src='".$j->thumbnail_url."'>";
- $ret.= "</a>";
+ $tw = (isset($j->thumbnail_width)) ? $j->thumbnail_width:200;
+ $th = (isset($j->thumbnail_height)) ? $j->thumbnail_height:180;
+ $tr = $tw/$th;
+
+ $th=120; $tw = $th*$tr;
+ $tpl=get_markup_template('oembed_video.tpl');
+ $ret.=replace_macros($tpl, array(
+ '$embedurl'=>$embedurl,
+ '$escapedhtml'=>base64_encode($jhtml),
+ '$tw'=>$tw,
+ '$th'=>$th,
+ '$turl'=>$j->thumbnail_url,
+ ));
+
} else {
- $ret=$j->html;
+ $ret=$jhtml;
}
$ret.="<br>";
}; break;
@@ -81,18 +89,40 @@ function oembed_format_object($j){
}; break;
case "rich": {
// not so safe..
- $ret.= "<blockquote>".$j->html."</blockquote>";
+ $ret.= $jhtml;
}; break;
}
- $embedlink = (isset($j->title))?$j->title:$embedurl;
- $ret .= "<a href='$embedurl' rel='oembed'>$embedlink</a>";
- if (isset($j->author_name)) $ret.=" by ".$j->author_name;
- if (isset($j->provider_name)) $ret.=" on ".$j->provider_name;
+ // add link to source if not present in "rich" type
+ if ( $j->type!='rich' || !strpos($j->html,$embedurl) ){
+ $embedlink = (isset($j->title))?$j->title:$embedurl;
+ $ret .= "<a href='$embedurl' rel='oembed'>$embedlink</a>";
+ if (isset($j->author_name)) $ret.=" by ".$j->author_name;
+ if (isset($j->provider_name)) $ret.=" on ".$j->provider_name;
+ } else {
+ // add <a> for html2bbcode conversion
+ $ret .= "<a href='$embedurl' rel='oembed'/>";
+ }
$ret.="<br style='clear:left'></span>";
- return $ret;
+ return mb_convert_encoding($ret, 'HTML-ENTITIES', mb_detect_encoding($ret));
+}
+
+function oembed_iframe($src,$width,$height) {
+ if(! $width || strstr($width,'%'))
+ $width = '640';
+ if(! $height || strstr($height,'%'))
+ $height = '300';
+ // try and leave some room for the description line.
+ $height = intval($height) + 80;
+ $width = intval($width) + 40;
+
+ $s = 'data:text/html;base64,' . base64_encode('<html><body>' . $src . '</body></html>');
+ return '<iframe height="' . $height . '" width="' . $width . '" src="' . $s . '" frameborder="no" >' . t('Embedded content') . '</iframe>';
+
}
+
+
function oembed_bbcode2html($text){
$stopoembed = get_config("system","no_oembed");
if ($stopoembed == true){
@@ -136,8 +166,8 @@ function oembed_html2bbcode($text) {
$xattr = oe_build_xpath("class","oembed");
$entries = $xpath->query("//span[$xattr]");
-
- $xattr = oe_build_xpath("rel","oembed");
+
+ $xattr = "@rel='oembed'";//oe_build_xpath("rel","oembed");
foreach($entries as $e) {
$href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue;
if(!is_null($href)) $e->parentNode->replaceChild(new DOMText("[embed]".$href."[/embed]"), $e);
@@ -148,4 +178,5 @@ function oembed_html2bbcode($text) {
}
}
-?> \ No newline at end of file
+
+
diff --git a/include/poller.php b/include/poller.php
index cef0647b5..d9e5282f2 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -24,6 +24,7 @@ function poller_run($argv, $argc){
require_once('include/items.php');
require_once('include/Contact.php');
require_once('include/email.php');
+ require_once('include/socgraph.php');
load_config('config');
load_config('system');
@@ -64,8 +65,7 @@ function poller_run($argv, $argc){
}
// clear old cache
- q("DELETE FROM `cache` WHERE `updated` < '%s'",
- dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
+ Cache::clear();
$manual_id = 0;
$generation = 0;
@@ -108,13 +108,14 @@ function poller_run($argv, $argc){
$contacts = q("SELECT `contact`.`id` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
- AND `network` != '%s'
+ AND NOT `network` IN ( '%s', '%s' )
$sql_extra
AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0
AND `user`.`account_expired` = 0 $abandon_sql ORDER BY RAND()",
intval(CONTACT_IS_SHARING),
intval(CONTACT_IS_FRIEND),
- dbesc(NETWORK_DIASPORA)
+ dbesc(NETWORK_DIASPORA),
+ dbesc(NETWORK_FACEBOOK)
);
if(! count($contacts)) {
@@ -137,6 +138,9 @@ function poller_run($argv, $argc){
if($manual_id)
$contact['last-update'] = '0000-00-00 00:00:00';
+ if($contact['network'] === NETWORK_DFRN)
+ $contact['priority'] = 2;
+
if($contact['priority'] || $contact['subhub']) {
$hub_update = true;
@@ -218,7 +222,7 @@ function poller_run($argv, $argc){
$importer = $r[0];
- logger("poller: poll: IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
+ logger("poller: poll: ({$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
$last_update = (($contact['last-update'] === '0000-00-00 00:00:00')
? datetime_convert('UTC','UTC','now - 30 days', ATOM_TIME)
@@ -299,6 +303,13 @@ function poller_run($argv, $argc){
if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
continue;
+ if(((float) $res->dfrn_version > 2.21) && ($contact['poco'] == '')) {
+ q("update contact set poco = '%s' where id = %d limit 1",
+ dbesc(str_replace('/profile/','/poco/', $contact['url'])),
+ intval($contact['id'])
+ );
+ }
+
$postvars = array();
$sent_dfrn_id = hex2bin((string) $res->dfrn_id);
@@ -522,6 +533,21 @@ function poller_run($argv, $argc){
intval($contact['id'])
);
+
+ // load current friends if possible.
+
+ if($contact['poco']) {
+ $r = q("SELECT count(*) as total from glink
+ where `cid` = %d and updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
+ intval($contact['id'])
+ );
+ }
+ if(count($r)) {
+ if(! $r[0]['total']) {
+ poco_load($contact['id'],$importer_uid,$contact['poco']);
+ }
+ }
+
// loop - next contact
}
}
diff --git a/include/profile_update.php b/include/profile_update.php
new file mode 100644
index 000000000..61eaee75d
--- /dev/null
+++ b/include/profile_update.php
@@ -0,0 +1,107 @@
+<?php
+
+require_once('include/datetime.php');
+require_once('include/diaspora.php');
+require_once('include/queue_fn.php');
+
+function profile_change() {
+
+ $a = get_app();
+
+ if(! local_user())
+ 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");
+
+ $recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'
+ AND `uid` = %d AND `rel` != %d ",
+ dbesc(NETWORK_DIASPORA),
+ intval(local_user()),
+ intval(CONTACT_IS_SHARING)
+ );
+ if(! count($recips))
+ return;
+
+ $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
+ LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid`
+ WHERE `user`.`uid` = %d AND `profile`.`is-default` = 1 LIMIT 1",
+ intval(local_user())
+ );
+
+ if(! count($r))
+ return;
+ $profile = $r[0];
+
+ $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 = xmlify($profile['gender']);
+ $about = xmlify($profile['about']);
+ require_once('include/bbcode.php');
+ $about = xmlify(strip_tags(bbcode($about)));
+ $location = '';
+ if($profile['locality'])
+ $location .= $profile['locality'];
+ if($profile['region']) {
+ if($location)
+ $location .= ', ';
+ $location .= $profile['region'];
+ }
+ if($profile['country-name']) {
+ if($location)
+ $location .= ', ';
+ $location .= $profile['country-name'];
+ }
+ $location = xmlify($location);
+ $tags = '';
+ if($profile['pub_keywords']) {
+ $kw = str_replace(',',' ',$profile['pub_keywords']);
+ $kw = str_replace(' ',' ',$kw);
+ $arr = explode(' ',$profile['pub_keywords']);
+ if(count($arr)) {
+ for($x = 0; $x < 5; $x ++) {
+ if(trim($arr[$x]))
+ $tags .= '#' . trim($arr[$x]) . ' ';
+ }
+ }
+ }
+ $tags = xmlify(trim($tags));
+ }
+
+ $tpl = get_markup_template('diaspora_profile.tpl');
+
+ $msg = replace_macros($tpl,array(
+ '$handle' => $handle,
+ '$first' => $first,
+ '$last' => $last,
+ '$large' => $large,
+ '$medium' => $medium,
+ '$small' => $small,
+ '$dob' => $dob,
+ '$gender' => $gender,
+ '$about' => $about,
+ '$location' => $location,
+ '$searchable' => $searchable,
+ '$tags' => $tags
+ ));
+ logger('profile_change: ' . $msg, LOGGER_ALL);
+
+ foreach($recips as $recip) {
+ $msgtosend = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$a->user,$recip,$a->user['prvkey'],$recip['pubkey'],false)));
+ add_to_queue($recip['id'],NETWORK_DIASPORA,$msgtosend,false);
+ }
+}
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/socgraph.php b/include/socgraph.php
new file mode 100644
index 000000000..84cfe4468
--- /dev/null
+++ b/include/socgraph.php
@@ -0,0 +1,185 @@
+<?php
+
+require_once('include/datetime.php');
+
+
+/*
+ * poco_load
+ *
+ * Given a contact-id (minimum), load the PortableContacts friend list for that contact,
+ * and add the entries to the gcontact (Global Contact) table, or update existing entries
+ * if anything (name or photo) has changed.
+ * We use normalised urls for comparison which ignore http vs https and www.domain vs domain
+ *
+ * Once the global contact is stored add (if necessary) the contact linkage which associates
+ * the given uid, cid to the global contact entry. There can be many uid/cid combinations
+ * pointing to the same global contact id.
+ *
+ */
+
+
+
+
+function poco_load($cid,$uid = 0,$url = null) {
+ $a = get_app();
+ if((! $url) || (! $uid)) {
+ $r = q("select `poco`, `uid` from `contact` where `id` = %d limit 1",
+ intval($cid)
+ );
+ if(count($r)) {
+ $url = $r[0]['poco'];
+ $uid = $r[0]['uid'];
+ }
+ }
+ if((! $url) || (! $uid))
+ return;
+ $s = fetch_url($url . '/@me/@all?fields=displayName,urls,photos');
+
+ if(($a->get_curl_code() > 299) || (! $s))
+ return;
+ $j = json_decode($s);
+ foreach($j->entry as $entry) {
+
+ $profile_url = '';
+ $profile_photo = '';
+ $name = '';
+
+ $name = $entry->displayName;
+
+ foreach($entry->urls as $url) {
+ if($url->type == 'profile') {
+ $profile_url = $url->value;
+ break;
+ }
+ }
+ foreach($entry->photos as $photo) {
+ if($photo->type == 'profile') {
+ $profile_photo = $photo->value;
+ break;
+ }
+ }
+
+ if((! $name) || (! $profile_url) || (! $profile_photo))
+ continue;
+
+ $x = q("select * from `gcontact` where `nurl` = '%s' limit 1",
+ dbesc(normalise_link($profile_url))
+ );
+ if(count($x)) {
+ $gcid = $x[0]['id'];
+
+ if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo) {
+ q("update gcontact set `name` = '%s', `photo` = '%s' where
+ `nurl` = '%s' limit 1",
+ dbesc($name),
+ dbesc($profile_photo),
+ dbesc(normalise_link($profile_url))
+ );
+ }
+ }
+ else {
+ q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`)
+ values ( '%s', '%s', '%s', '%s') ",
+ dbesc($name),
+ dbesc($profile_url),
+ dbesc(normalise_link($profile_url)),
+ dbesc($profile_photo)
+ );
+ $x = q("select * from `gcontact` where `nurl` = '%s' limit 1",
+ dbesc(normalise_link($profile_url))
+ );
+ if(count($x))
+ $gcid = $x[0]['id'];
+ }
+ if(! $gcid)
+ return;
+
+ $r = q("select * from glink where `cid` = %d and `uid` = %d and `gcid` = %d limit 1",
+ intval($cid),
+ intval($uid),
+ intval($gcid)
+ );
+ if(! count($r)) {
+ q("insert into glink ( `cid`,`uid`,`gcid`,`updated`) values (%d,%d,%d,'%s') ",
+ intval($cid),
+ intval($uid),
+ intval($gcid),
+ dbesc(datetime_convert())
+ );
+ }
+ else {
+ q("update glink set updated = '%s' where `cid` = %d and `uid` = %d and `gcid` = %d limit 1",
+ dbesc(datetime_convert()),
+ intval($cid),
+ intval($uid),
+ intval($gcid)
+ );
+ }
+
+ }
+
+ q("delete from glink where `cid` = %d and `uid` = %d and `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY",
+ intval($cid),
+ intval($uid)
+ );
+
+}
+
+
+function count_common_friends($uid,$cid) {
+
+ $r = q("SELECT count(*) as `total`
+ FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id`
+ where `glink`.`cid` = %d and `glink`.`uid` = %d
+ and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and id != %d ) ",
+ intval($cid),
+ intval($uid),
+ intval($uid),
+ intval($cid)
+ );
+
+ if(count($r))
+ return $r[0]['total'];
+ return 0;
+
+}
+
+
+function common_friends($uid,$cid) {
+
+ $r = q("SELECT `gcontact`.*
+ FROM `glink` left join `gcontact` on `glink`.`gcid` = `gcontact`.`id`
+ where `glink`.`cid` = %d and `glink`.`uid` = %d
+ and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and id != %d ) ",
+ intval($cid),
+ intval($uid),
+ intval($uid),
+ intval($cid)
+ );
+
+ return $r;
+
+}
+
+
+
+function suggestion_query($uid, $start = 0, $limit = 40) {
+
+ if(! $uid)
+ return array();
+
+ $r = q("SELECT count(glink.gcid) as `total`, gcontact.* from gcontact
+ left join glink on glink.gcid = gcontact.id
+ where uid = %d and not gcontact.nurl in ( select nurl from contact where uid = %d)
+ and not gcontact.id in ( select gcid from gcign where uid = %d )
+ group by glink.gcid order by total desc limit %d, %d ",
+ intval($uid),
+ intval($uid),
+ intval($uid),
+ intval($start),
+ intval($limit)
+ );
+
+ return $r;
+
+}
diff --git a/include/template_processor.php b/include/template_processor.php
index 63d75eaa4..25f7703a2 100644
--- a/include/template_processor.php
+++ b/include/template_processor.php
@@ -165,17 +165,17 @@
$this->r = $r;
$this->search = array();
$this->replace = array();
-
+
$this->_build_replace($r, "");
#$s = str_replace(array("\n","\r"),array("§n§","§r§"),$s);
$s = $this->_build_nodes($s);
+
$s = preg_replace_callback('/\|\|([0-9]+)\|\|/', array($this, "_replcb_node"), $s);
if ($s==Null) $this->_preg_error();
// remove comments block
$s = preg_replace('/{#[^#]*#}/', "" , $s);
-
// replace strings recursively (limit to 10 loops)
$os = ""; $count=0;
while($os!=$s && $count<10){
diff --git a/include/text.php b/include/text.php
index 299410a63..59fc15007 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);
@@ -462,7 +465,7 @@ function get_tags($s) {
// Match full names against @tags including the space between first and last
// We will look these up afterward to see if they are full names or not recognisable.
- if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A,:?]+)([ \x0D\x0A,:?]|$)/',$s,$match)) {
+ if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A@,:?]+)([ \x0D\x0A@,:?]|$)/',$s,$match)) {
foreach($match[1] as $mtch) {
if(strstr($mtch,"]")) {
// we might be inside a bbcode color tag - leave it alone
@@ -478,7 +481,7 @@ function get_tags($s) {
// Otherwise pull out single word tags. These can be @nickname, @first_last
// and #hash tags.
- if(preg_match_all('/([@#][^ \x0D\x0A,:?]+)([ \x0D\x0A,:?]|$)/',$s,$match)) {
+ if(preg_match_all('/([@#][^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/',$s,$match)) {
foreach($match[1] as $mtch) {
if(strstr($mtch,"]")) {
// we might be inside a bbcode color tag - leave it alone
@@ -669,7 +672,7 @@ function smilies($s) {
$s = str_replace(
array( '&lt;3', '&lt;/3', '&lt;\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O',
- '~friendika', 'Diaspora*' ),
+ '~friendika', '~friendica', 'Diaspora*' ),
array(
'<img src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
'<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
@@ -688,6 +691,7 @@ function smilies($s) {
'<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" />',
'<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />',
'<a href="http://project.friendika.com">~friendika <img src="' . $a->get_baseurl() . '/images/friendika-16.png" alt="~friendika" /></a>',
+ '<a href="http://friendica.com">~friendica <img src="' . $a->get_baseurl() . '/images/friendika-16.png" alt="~friendica" /></a>',
'<a href="http://diasporafoundation.org">Diaspora<img src="' . $a->get_baseurl() . '/images/diaspora.png" alt="Diaspora*" /></a>',
), $s);
@@ -748,7 +752,9 @@ function prepare_body($item,$attach = false) {
$s = prepare_text($item['body']);
- call_hooks('prepare_body', $s);
+ $prep_arr = array('item' => $item, 'html' => $s);
+ call_hooks('prepare_body', $prep_arr);
+ $s = $prep_arr['html'];
if(! $attach)
return $s;
@@ -781,8 +787,19 @@ function prepare_body($item,$attach = false) {
}
$s .= '<div class="clear"></div></div>';
}
- call_hooks('prepare_body_final', $s);
- return $s;
+
+ $arr = explode(',',$item['tag']);
+ if(count($arr)) {
+ $s .= '<div class="body-tag">';
+ foreach($arr as $r) {
+ $s .= bbcode($r) . ' ';
+ }
+ $s .= '</div>';
+ }
+
+ $prep_arr = array('item' => $item, 'html' => $s);
+ call_hooks('prepare_body_final', $prep_arr);
+ return $prep_arr['html'];
}}
@@ -1036,4 +1053,13 @@ function html2bb_video($s) {
'[vimeo]$2[/vimeo]', $s);
return $s;
-} \ No newline at end of file
+}
+
+/**
+ * apply xmlify() to all values of array $val, recursively
+ */
+function array_xmlify($val){
+ if (is_bool($val)) return $val?"true":"false";
+ if (is_array($val)) return array_map('array_xmlify', $val);
+ return xmlify((string) $val);
+}