From c352047228126ab439ca4582995f83f119188588 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 16 Jul 2017 22:51:36 -0700 Subject: mis-attributed profile photo when Mastodon comment author has no profile photo --- include/feedutils.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index 6ee53e2f6..be7c926d4 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1040,6 +1040,11 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['comment_policy'] = 'none'; } + // if we have everything but a photo, provide the default profile photo + + if($author['author_name'] && $author['author_link'] && (! $author['author_photo'])) + $author['author_photo'] = z_root() . '/' . get_default_profile_photo(80); + if((! x($author,'author_name')) || ($author['author_is_feed'])) $author['author_name'] = $contact['xchan_name']; if((! x($author,'author_link')) || ($author['author_is_feed'])) @@ -1244,6 +1249,12 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { $datarray['comment_policy'] = 'none'; } + + // if we have everything but a photo, provide the default profile photo + + if($author['author_name'] && $author['author_link'] && (! $author['author_photo'])) + $author['author_photo'] = z_root() . '/' . get_default_profile_photo(80); + if(is_array($contact)) { if((! x($author,'author_name')) || ($author['author_is_feed'])) $author['author_name'] = $contact['xchan_name']; -- cgit v1.2.3 From ecb1515e5d6cd854bd64444b9c07af50df370efb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 17 Jul 2017 19:28:27 -0700 Subject: activitystreams converters updated to recent spec --- include/feedutils.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/feedutils.php b/include/feedutils.php index be7c926d4..5f2a06029 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1890,17 +1890,17 @@ function i2asld($i) { $ret = array(); - $ret['@context'] = array( 'http://www.w3.org/ns/activitystreams', 'zot' => 'http://purl.org/zot/protocol'); + $ret['@context'] = array( 'https://www.w3.org/ns/activitystreams', 'zot' => 'http://purl.org/zot/protocol'); if($i['verb']) { if(strpos(dirname($i['verb'],'activitystrea.ms/schema/1.0'))) { - $ret['@type'] = ucfirst(basename($i['verb'])); + $ret['type'] = ucfirst(basename($i['verb'])); } elseif(strpos(dirname($i['verb'],'purl.org/zot'))) { - $ret['@type'] = 'zot:' . ucfirst(basename($i['verb'])); + $ret['type'] = 'zot:' . ucfirst(basename($i['verb'])); } } - $ret['@id'] = $i['plink']; + $ret['id'] = $i['plink']; $ret['published'] = datetime_convert('UTC','UTC',$i['created'],ATOM_TIME); @@ -1922,7 +1922,7 @@ function asencode_note($i) { $ret = array(); $ret['@type'] = 'Note'; - $ret['@id'] = $i['plink']; + $ret['id'] = $i['plink']; if($i['title']) $ret['title'] = bbcode($i['title']); @@ -1938,16 +1938,18 @@ function asencode_note($i) { function asencode_person($p) { $ret = array(); - $ret['@type'] = 'Person'; - $ret['@id'] = 'acct:' . $p['xchan_addr']; - $ret['displayName'] = $p['xchan_name']; - $ret['icon'] = array( - '@type' => 'Link', + $ret['type'] = 'Person'; + $ret['id'] = $p['xchan_url']; + $ret['name'] = $p['xchan_name']; + $ret['image'] = array( + 'type' => 'Link', 'mediaType' => $p['xchan_photo_mimetype'], - 'href' => $p['xchan_photo_m'] + 'href' => $p['xchan_photo_l'], + 'height' => 300, + 'width' => 300 ); $ret['url'] = array( - '@type' => 'Link', + 'type' => 'Link', 'mediaType' => 'text/html', 'href' => $p['xchan_url'] ); -- cgit v1.2.3 From 0d062251b6c38a71932e9875cdd777afdfff140b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 17 Jul 2017 19:42:30 -0700 Subject: fix for bug 827 to provide partial backward compatibility with album names in photo items from < hubzilla 2.4 this will only work part of the time - which is why the behaviour was changed --- include/photos.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index 6ea444e2e..b4cc89502 100644 --- a/include/photos.php +++ b/include/photos.php @@ -593,6 +593,15 @@ function photos_album_exists($channel_id, $observer_hash, $album) { intval($channel_id) ); + // partial backward compatibility with Hubzilla < 2.4 when we used the filename only + // (ambiguous which would get chosen if you had two albums of the same name in different directories) + + if(! $r) { + $r = q("SELECT folder, hash, is_dir, filename, os_path, display_path FROM attach WHERE filename = '%s' AND is_dir = 1 AND uid = %d $sql_extra limit 1", + dbesc(hex2bin($album)), + intval($channel_id) + ); + return (($r) ? $r[0] : false); } -- cgit v1.2.3 From 15e836b7dd2fed3f97f134928d88e13db1d8a7f4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 17 Jul 2017 19:53:03 -0700 Subject: provide content-type matching ability for activitypub --- include/network.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'include') diff --git a/include/network.php b/include/network.php index b85a16d21..fe9a9aa2b 100644 --- a/include/network.php +++ b/include/network.php @@ -1896,3 +1896,41 @@ function service_plink($contact, $guid) { return $x['plink']; } +function getBestSupportedMimeType($mimeTypes = null, $acceptedTypes = false) { + // Values will be stored in this array + + if($acceptedTypes === false) + $acceptedTypes = $_SERVER['HTTP_ACCEPT']; + + $AcceptTypes = Array (); + + // Accept header is case insensitive, and whitespace isn’t important + $accept = strtolower(str_replace(' ', '', $acceptedTypes)); + // divide it into parts in the place of a "," + $accept = explode(',', $accept); + foreach ($accept as $a) { + // the default quality is 1. + $q = 1; + // check if there is a different quality + if (strpos($a, ';q=')) { + // divide "mime/type;q=X" into two parts: "mime/type" i "X" + list($a, $q) = explode(';q=', $a); + } + // mime-type $a is accepted with the quality $q + // WARNING: $q == 0 means, that mime-type isn’t supported! + $AcceptTypes[$a] = $q; + } + arsort($AcceptTypes); + + // if no parameter was passed, just return parsed data + if (!$mimeTypes) return $AcceptTypes; + + $mimeTypes = array_map('strtolower', (array)$mimeTypes); + + // let’s check our supported types: + foreach ($AcceptTypes as $mime => $q) { + if ($q && in_array($mime, $mimeTypes)) return $mime; + } + // no mime-type found + return null; +} \ No newline at end of file -- cgit v1.2.3