From c92bb6176a79ef575c9a9b5dec8fde7034c6421c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 1 Feb 2018 15:09:51 -0800 Subject: more separation of complex code into separate functions --- include/hubloc.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include') diff --git a/include/hubloc.php b/include/hubloc.php index 0daa5908c..d5abda7fb 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -257,6 +257,38 @@ function hubloc_mark_as_down($posturl) { } +/** + * @brief return comma separated string of non-dead clone locations (net addresses) for a given netid + * + * @param string $netid network identity (typically xchan_hash or hubloc_hash) + * @return string + */ + +function locations_by_netid($netid) { + + $strloc = ''; + + $locs = q("select hubloc_addr as location from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_deleted = 0 and site_dead = 0", + dbesc($netid) + ); + + if($locs) { + foreach($locs as $l) { + if(!($l['location'])) + continue; + if(strpos($strloc,$l['location']) !== false) + continue; + if(strlen($strloc)) + $strloc .= ', '; + $strloc .= $l['location']; + } + } + + return $strloc; + +} + + function ping_site($url) { -- cgit v1.2.3 From cc0cd0b292f825d70a626c1ae5d46d0a43a825b9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 1 Feb 2018 17:17:23 -0800 Subject: more generalisation of commonly used code constructs --- include/hubloc.php | 16 +--------------- include/text.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 15 deletions(-) (limited to 'include') diff --git a/include/hubloc.php b/include/hubloc.php index d5abda7fb..0d1a2e560 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -266,25 +266,11 @@ function hubloc_mark_as_down($posturl) { function locations_by_netid($netid) { - $strloc = ''; - $locs = q("select hubloc_addr as location from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' and hubloc_deleted = 0 and site_dead = 0", dbesc($netid) ); - if($locs) { - foreach($locs as $l) { - if(!($l['location'])) - continue; - if(strpos($strloc,$l['location']) !== false) - continue; - if(strlen($strloc)) - $strloc .= ', '; - $strloc .= $l['location']; - } - } - - return $strloc; + return array_elm_to_str($locs,'location',', '); } diff --git a/include/text.php b/include/text.php index 8ec6ebace..10bbc751a 100644 --- a/include/text.php +++ b/include/text.php @@ -3261,3 +3261,31 @@ function purify_filename($s) { return ''; return $s; } + + +/** + * @brief array_elm_to_str($arr,$elm,$delim = ',') extract unique individual elements from an array of arrays and return them as a string separated by a delimiter + * + * empty elements (evaluated after trim()) are ignored. + * @param $arr array + * @param $elm array key to extract from sub-array + * @param $delim string default ',' + * @returns string + */ + +function array_elm_to_str($arr,$elm,$delim = ',') { + + $tmp = []; + if($arr && is_array($arr)) { + foreach($arr as $x) { + if(is_array($x) && array_key_exists($elm,$x)) { + $z = trim($x[$elm]); + if(($z) && (! in_array($z,$tmp))) { + $tmp[] = $z; + } + } + } + } + return implode($tmp,$delim); +} + -- cgit v1.2.3 From dd35cad62a6574143940f4879083d9e80f5a4e88 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 1 Feb 2018 19:52:40 -0800 Subject: some feed cleanup --- include/feedutils.php | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 5e48cb1ee..03124443c 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -15,15 +15,6 @@ */ function get_public_feed($channel, $params) { -/* $type = 'xml'; - $begin = NULL_DATE; - $end = ''; - $start = 0; - $records = 40; - $direction = 'desc'; - $pages = 0; -*/ - if(! $params) $params = []; @@ -106,23 +97,15 @@ function get_feed_for($channel, $observer_hash, $params) { $owner = atom_render_author('zot:owner',$channel); $atom .= replace_macros($feed_template, array( - '$version' => xmlify(Zotlabs\Lib\System::get_project_version()), - '$red' => xmlify(Zotlabs\Lib\System::get_platform_name()), - '$feed_id' => xmlify($channel['xchan_url']), - '$feed_title' => xmlify($channel['channel_name']), - '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now', ATOM_TIME)), - '$author' => $feed_author, - '$owner' => $owner, - '$name' => xmlify($channel['channel_name']), - '$profile_page' => xmlify($channel['xchan_url']), - '$mimephoto' => xmlify($channel['xchan_photo_mimetype']), - '$photo' => xmlify($channel['xchan_photo_l']), - '$thumb' => xmlify($channel['xchan_photo_m']), - '$picdate' => '', - '$uridate' => '', - '$namdate' => '', - '$birthday' => '', - '$community' => '', + '$version' => xmlify(Zotlabs\Lib\System::get_project_version()), + '$generator' => xmlify(Zotlabs\Lib\System::get_platform_name()), + '$generator_uri' => 'https://hubzilla.org', + '$feed_id' => xmlify($channel['xchan_url']), + '$feed_title' => xmlify($channel['channel_name']), + '$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', 'now', ATOM_TIME)), + '$author' => $feed_author, + '$owner' => $owner, + '$profile_page' => xmlify($channel['xchan_url']), )); -- cgit v1.2.3 From 512f3a764361dde44e36fb72c105265d6df298ad Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 1 Feb 2018 21:26:34 -0800 Subject: provide summaries in feeds under very limited cases, but never in compat (GNU-Social) mode --- include/feedutils.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 03124443c..5ef45a6cd 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1826,10 +1826,24 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ create_export_photo_body($item); - if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) - $body = fix_private_photos($item['body'],$owner['uid'],$item,$cid); + // provide separate summary and content unless compat is true; as summary represents a content-warning on some networks + + $matches = false; + if(preg_match('|\[summary\](.*?)\[/summary\]|ism',$item['body'],$matches)) + $summary = $matches[1]; else - $body = $item['body']; + $summary = ''; + + $body = $item['body']; + + if($summary) + $body = preg_replace('|^(.*?)\[summary\](.*?)\[/summary\](.*?)$|ism','$1$3',$item['body']); + + if($compat) + $summary = ''; + + if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) + $body = fix_private_photos($body,$owner['uid'],$item,$cid); if($compat) { $compat_photos = compat_photos_list($body); @@ -1870,6 +1884,8 @@ function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0, $ } else { $o .= '' . xmlify($item['title']) . '' . "\r\n"; + if($summary) + $o .= '' . xmlify(prepare_text($summary,$item['mimetype'])) . '' . "\r\n"; $o .= '' . xmlify(prepare_text($body,$item['mimetype'])) . '' . "\r\n"; } -- cgit v1.2.3