From a9b2b48d082b5e97fd3bb1481d2b01e81d04735a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 27 Nov 2015 23:16:54 +0100 Subject: [PATCH 1/8] Some small improvements to the OStatus export --- include/bbcode.php | 2 +- include/items.php | 2 +- include/ostatus.php | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 81536d3720..e07b63313a 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -100,7 +100,7 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { } if ($simplehtml == 7) - $text = sprintf('%s', + $text = sprintf('%s
', $url, $title, $title); elseif (($simplehtml != 4) AND ($simplehtml != 0)) $text = sprintf('%s
', $url, $title); diff --git a/include/items.php b/include/items.php index 53f4784c2d..f86c6453f6 100644 --- a/include/items.php +++ b/include/items.php @@ -4645,7 +4645,7 @@ function item_getfeedtags($item) { if($cnt) { for($x = 0; $x < $cnt; $x ++) { if($matches[1][$x]) - $ret[] = array('#',$matches[1][$x], $matches[2][$x]); + $ret[$matches[2][$x]] = array('#',$matches[1][$x], $matches[2][$x]); } } $matches = false; diff --git a/include/ostatus.php b/include/ostatus.php index ce254ed61a..2c6480fd32 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1201,6 +1201,14 @@ function ostatus_get_attachment($doc, $root, $item) { break; } + if (($siteinfo["type"] != "photo") AND isset($siteinfo["image"])) { + $photodata = get_photo_info($siteinfo["image"]); + + $attributes = array("rel" => "preview", "href" => $siteinfo["image"], "media:width" => $photodata[0], "media:height" => $photodata[1]); + xml_add_element($doc, $root, "link", "", $attributes); + } + + $arr = explode('[/attach],',$item['attach']); if(count($arr)) { foreach($arr as $r) { @@ -1327,6 +1335,7 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) { if ($item['title'] != "") $body = "[b]".$item['title']."[/b]\n\n".$body; + $body = bb_remove_share_information($body); $body = bbcode($body, false, false, 7); xml_add_element($doc, $entry, "content", $body, array("type" => "html")); @@ -1440,7 +1449,7 @@ function ostatus_feed(&$a, $owner_nick, $last_update) { $root->appendChild($entry); } - return($doc->saveXML()); + return(trim($doc->saveXML())); } function ostatus_salmon($item,$owner) { @@ -1452,6 +1461,6 @@ function ostatus_salmon($item,$owner) { $doc->appendChild($entry); - return($doc->saveXML()); + return(trim($doc->saveXML())); } ?> From 79092f149c2438c1c55b0f92594e5722eb33859b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 28 Nov 2015 01:03:26 +0100 Subject: [PATCH 2/8] Requests for soapbox and freelove accounts are automatically accepted --- include/items.php | 52 +++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/include/items.php b/include/items.php index f86c6453f6..65d66b77a1 100644 --- a/include/items.php +++ b/include/items.php @@ -4171,14 +4171,13 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { ); } // send email notification to owner? - } - else { + } else { // create contact record - $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', '%s', %d, 0, 0, 1, 1 ) ", + $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', '%s', %d, 0, 0, 1, 1)", intval($importer['uid']), dbesc(datetime_convert()), dbesc($url), @@ -4193,27 +4192,38 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { intval($importer['uid']), dbesc($url) ); - if(count($r)) + if(count($r)) { $contact_record = $r[0]; - // create notification - $hash = random_string(); + $photos = import_profile_photo($photo,$importer["uid"],$contact_record["id"]); - if(is_array($contact_record)) { - $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `hash`, `datetime`) - VALUES ( %d, %d, 0, 0, '%s', '%s' )", - intval($importer['uid']), - intval($contact_record['id']), - dbesc($hash), - dbesc(datetime_convert()) - ); + q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d", + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + intval($contact_record["id"]) + ); } + $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($importer['uid']) ); $a = get_app(); - if(count($r)) { + if(count($r) AND !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) { + + // create notification + $hash = random_string(); + + if(is_array($contact_record)) { + $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `hash`, `datetime`) + VALUES ( %d, %d, 0, 0, '%s', '%s' )", + intval($importer['uid']), + intval($contact_record['id']), + dbesc($hash), + dbesc(datetime_convert()) + ); + } if(intval($r[0]['def_gid'])) { require_once('include/group.php'); @@ -4221,7 +4231,7 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { } if(($r[0]['notify-flags'] & NOTIFY_INTRO) && - in_array($r[0]['page-flags'], array(PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE))) { + in_array($r[0]['page-flags'], array(PAGE_NORMAL))) { notification(array( 'type' => NOTIFY_INTRO, @@ -4239,7 +4249,13 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { )); } + } elseif (count($r) AND in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) { + $r = q("UPDATE `contact` SET `pending` = 0 WHERE `uid` = %d AND `url` = '%s' AND `pending` LIMIT 1", + intval($importer['uid']), + dbesc($url) + ); } + } } From 643e228d6bee06ba354fe55df2ad9444678595e3 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 28 Nov 2015 07:37:02 +0100 Subject: [PATCH 3/8] Bookmark links are now looking again like bookmark links --- include/bbcode.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index e07b63313a..98c1f11991 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -99,10 +99,15 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { $image = ""; } - if ($simplehtml == 7) + if ($simplehtml == 7) { + $title2 = $title; + // If the link description is similar to the text above then don't add the link description + if (($title != "") AND ((strpos($match[1],$title) !== false) OR + (similar_text($match[1],$title) / strlen($title)) > 0.9)) + $title2 = $url; $text = sprintf('%s
', - $url, $title, $title); - elseif (($simplehtml != 4) AND ($simplehtml != 0)) + $url, $title, $title2); + } elseif (($simplehtml != 4) AND ($simplehtml != 0)) $text = sprintf('%s
', $url, $title); else { $text = sprintf('', $type); @@ -950,11 +955,13 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi", 'bb_DiasporaLinks', $Text); // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text - if (!$forplaintext) - $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); - else { - $Text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism"," $1 ",$Text); - $Text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_RemovePictureLinks', $Text); + if ($simplehtml != 7) { + if (!$forplaintext) + $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1$2', $Text); + else { + $Text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism"," $1 ",$Text); + $Text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_RemovePictureLinks', $Text); + } } if ($tryoembed) From 59242d7932495a431cd6c68c7990a8d984953d53 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 28 Nov 2015 07:37:56 +0100 Subject: [PATCH 4/8] Forgotten file --- include/ostatus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ostatus.php b/include/ostatus.php index 2c6480fd32..750952e908 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1335,7 +1335,7 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false) { if ($item['title'] != "") $body = "[b]".$item['title']."[/b]\n\n".$body; - $body = bb_remove_share_information($body); + //$body = bb_remove_share_information($body); $body = bbcode($body, false, false, 7); xml_add_element($doc, $entry, "content", $body, array("type" => "html")); From 32fa5d185c27b9490410ddf2fa4b13eff1d8129e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 28 Nov 2015 10:28:14 +0100 Subject: [PATCH 5/8] Before the comparism the entities must be removed --- include/bbcode.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 98c1f11991..acf6979d84 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -101,9 +101,13 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { if ($simplehtml == 7) { $title2 = $title; + + $test1 = trim(html_entity_decode($match[1],ENT_QUOTES,'UTF-8')); + $test2 = trim(html_entity_decode($title,ENT_QUOTES,'UTF-8')); + // If the link description is similar to the text above then don't add the link description - if (($title != "") AND ((strpos($match[1],$title) !== false) OR - (similar_text($match[1],$title) / strlen($title)) > 0.9)) + if (($title != "") AND ((strpos($test1,$test2) !== false) OR + (similar_text($test1,$test2) / strlen($title)) > 0.9)) $title2 = $url; $text = sprintf('%s
', $url, $title, $title2); From 679ce3243e44b634918fd5cf4c1479a4df3342d8 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 28 Nov 2015 16:35:16 +0100 Subject: [PATCH 6/8] Admin settings for table optimisation --- mod/admin.php | 3 +++ view/templates/admin_site.tpl | 1 + 2 files changed, 4 insertions(+) diff --git a/mod/admin.php b/mod/admin.php index d9a17dcad7..6333cb5321 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -409,6 +409,7 @@ function admin_page_site_post(&$a){ $poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0); $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50); $maxloadavg_frontend = ((x($_POST,'maxloadavg_frontend')) ? intval(trim($_POST['maxloadavg_frontend'])) : 50); + $optimize_max_tablesize = ((x($_POST,'optimize_max_tablesize')) ? intval(trim($_POST['optimize_max_tablesize'])): 100); $poco_completion = ((x($_POST,'poco_completion')) ? intval(trim($_POST['poco_completion'])) : false); $poco_requery_days = ((x($_POST,'poco_requery_days')) ? intval(trim($_POST['poco_requery_days'])) : 7); $poco_discovery = ((x($_POST,'poco_discovery')) ? intval(trim($_POST['poco_discovery'])) : 0); @@ -490,6 +491,7 @@ function admin_page_site_post(&$a){ set_config('system','poll_interval',$poll_interval); set_config('system','maxloadavg',$maxloadavg); set_config('system','maxloadavg_frontend',$maxloadavg_frontend); + set_config('system','optimize_max_tablesize',$optimize_max_tablesize); set_config('system','poco_completion',$poco_completion); set_config('system','poco_requery_days',$poco_requery_days); set_config('system','poco_discovery',$poco_discovery); @@ -772,6 +774,7 @@ function admin_page_site(&$a) { '$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")), '$maxloadavg_frontend' => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(get_config('system','maxloadavg_frontend')) > 0)?get_config('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")), + '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimisation"), ((intval(get_config('system','optimize_max_tablesize')) > 0)?get_config('system','optimize_max_tablesize'):100), t("Maximum table size (in MB) for the automatic optimization - default 100 MB.")), '$poco_completion' => array('poco_completion', t("Periodical check of global contacts"), get_config('system','poco_completion'), t("If enabled, the global contacts are checked periodically for missing or outdated data and the vitality of the contacts and servers.")), '$poco_requery_days' => array('poco_requery_days', t("Days between requery"), get_config('system','poco_requery_days'), t("Number of days after which a server is requeried for his contacts.")), diff --git a/view/templates/admin_site.tpl b/view/templates/admin_site.tpl index 13270e2eba..c1e70614ce 100644 --- a/view/templates/admin_site.tpl +++ b/view/templates/admin_site.tpl @@ -123,6 +123,7 @@ {{include file="field_input.tpl" field=$poll_interval}} {{include file="field_input.tpl" field=$maxloadavg}} {{include file="field_input.tpl" field=$maxloadavg_frontend}} + {{include file="field_input.tpl" field=$optimize_max_tablesize}} {{include file="field_input.tpl" field=$abandon_days}} {{include file="field_input.tpl" field=$lockpath}} {{include file="field_input.tpl" field=$temppath}} From b53a2c3122c5ece9b25351a2168947eb687736cd Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 28 Nov 2015 17:43:52 +0100 Subject: [PATCH 7/8] Changed documentation --- mod/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/admin.php b/mod/admin.php index 6333cb5321..8d2a7688f8 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -774,7 +774,7 @@ function admin_page_site(&$a) { '$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")), '$maxloadavg_frontend' => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(get_config('system','maxloadavg_frontend')) > 0)?get_config('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")), - '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimisation"), ((intval(get_config('system','optimize_max_tablesize')) > 0)?get_config('system','optimize_max_tablesize'):100), t("Maximum table size (in MB) for the automatic optimization - default 100 MB.")), + '$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimization"), ((intval(get_config('system','optimize_max_tablesize')) > 0)?get_config('system','optimize_max_tablesize'):100), t("Maximum table size (in MB) for the automatic optimization - default 100 MB. Enter -1 to disable it.")), '$poco_completion' => array('poco_completion', t("Periodical check of global contacts"), get_config('system','poco_completion'), t("If enabled, the global contacts are checked periodically for missing or outdated data and the vitality of the contacts and servers.")), '$poco_requery_days' => array('poco_requery_days', t("Days between requery"), get_config('system','poco_requery_days'), t("Number of days after which a server is requeried for his contacts.")), From cd16eb14af967648cdefaee4f420d483ed9aa309 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 28 Nov 2015 19:42:18 +0100 Subject: [PATCH 8/8] Show the name instead of the nick in the feed --- include/ostatus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ostatus.php b/include/ostatus.php index 750952e908..ebd5741e51 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1237,7 +1237,7 @@ function ostatus_add_author($doc, $owner, $profile) { $author = $doc->createElement("author"); xml_add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON); xml_add_element($doc, $author, "uri", $owner["url"]); - xml_add_element($doc, $author, "name", $owner["nick"]); + xml_add_element($doc, $author, "name", $profile["name"]); $attributes = array("rel" => "alternate", "type" => "text/html", "href" => $owner["url"]); xml_add_element($doc, $author, "link", "", $attributes);