diff --git a/include/attach.php b/include/attach.php index d048dd37a..f8cacc292 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1304,13 +1304,13 @@ function embedfolder_widget($args) * It is a limitation of the photo table using a name for a photo album instead of a folder hash */ if ($album) { - $x = q( - "select hash from attach where display_path= '%s' and uid = %d limit 1", + $albumEntity = q( + "select * from attach where display_path= '%s' and uid = %d limit 1", dbesc($album), intval($owner_uid) ); - if ($x) { - $y = attach_can_view_folder($owner_uid, get_observer_hash(), $x[0]['hash']); + if ($albumEntity) { + $y = attach_can_view_folder($owner_uid, get_observer_hash(), $albumEntity[0]['hash']); if (!$y) { return ''; } @@ -1324,7 +1324,7 @@ function embedfolder_widget($args) $sql_extra ORDER BY filename ASC", intval($owner_uid), - dbesc($x[0]['hash']) + dbesc($albumEntity[0]['hash']) ); if ($r) { @@ -1367,6 +1367,19 @@ function embedfolder_widget($args) $photos = []; if ($r) { + $photos[] = [ + 'id' => $albumEntity[0]['id'], + 'link' => z_root() . '/embedphotos/filelink/' . $albumEntity[0]['hash'], + 'filename' => t('Attach photo album'), + 'title' => t('Attach photos as album'), + 'src' => '', + 'icon' => getIconFromType('multipart/mixed'), + 'alt' => t('Attach photos as album'), + 'ext' => '', + 'hash' => $albumEntity[0]['hash'], + 'unknown' => t('Unknown') + ]; + foreach ($r as $rr) { $filetype = $rr['filetype']; diff --git a/src/Lib/Activity.php b/src/Lib/Activity.php index b34384547..cf8bbf0ea 100644 --- a/src/Lib/Activity.php +++ b/src/Lib/Activity.php @@ -1413,9 +1413,17 @@ class Activity $img[] = ['type' => 'Image', 'url' => substr($match[1], 1), 'name' => $match[2]]; } // preferred mechanism for adding alt text elseif (str_contains($match[1], 'alt=')) { - $txt = str_replace('"', '"', $match[1]); - $txt = substr($txt, strpos($txt, 'alt="') + 5, -1); - $img[] = ['type' => 'Image', 'url' => $match[2], 'name' => $txt]; + $submatch = null; + $x = preg_match("/alt=\"\;(.*?)\"\;/ism", $match[1], $submatch); + if ($x) { + $alt = $submatch[1]; + } + $submatch = null; + $x = preg_match('/alt="([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"/ism', $match[1], $submatch); + if ($x) { + $alt = $submatch[1]; + } + $img[] = ['type' => 'Image', 'url' => $match[2], 'name' => $alt]; } else { $img[] = ['type' => 'Image', 'url' => $match[2]]; } diff --git a/src/Module/Embedphotos.php b/src/Module/Embedphotos.php index fd0af3291..1ec816dbd 100644 --- a/src/Module/Embedphotos.php +++ b/src/Module/Embedphotos.php @@ -132,9 +132,39 @@ class Embedphotos extends Controller return ''; } - protected static function insertAlbum($folder) + protected static function insertAlbum($folder, $channel) { - return ''; + + $output = ''; + $x = q( + "select * from attach where is_photo = 1 and folder = '%s' and uid = %d ", + dbesc($folder['hash']), + intval($channel['channel_id']) + ); + if ($x) { + foreach ($x as $attach) { + $images = q("select * from photo where resource_id = '%s' and uid = %d and imgscale = 1", + dbesc($attach['hash']), + intval($channel['channel_id']) + ); + if ($images) { + $image = array_shift($images); + $alt = 'alt="' . (($image['description']) ?: $image['filename']) . '"'; + $ext = pathinfo($image['filename'], PATHINFO_EXTENSION); + $url = z_root() . '/photo/' . $image['resource_id'] . '-1' . (($ext) ? '.' . $ext : ''); + if ($image['allow_cid'] && strpos($image['allow_cid'],'')); + $url = $url . '?token=' . $token; + } + + $output .= '[zmg width="' . $image['width'] . '" height="' . $image['height'] . '" ' . "\n\n" . $alt . "\n\n" . ']' + . $url . '[/zmg]' . "\n\n"; + } + } + } + $output .= '[attachment]' . z_root() . '/album/' . $channel['channel_address'] . '/' . $folder['hash'] . '[/attachment]'; + return $output; } @@ -148,7 +178,7 @@ class Embedphotos extends Controller $r = attach_by_hash($resource,get_observer_hash()); if ($r['success'] && $r['data']['is_dir']) { - return self::insertAlbum($r['data']); + return self::insertAlbum($r['data'], $channel); } $url = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $r['data']['display_path']; diff --git a/src/Module/Item.php b/src/Module/Item.php index f26d0883c..0c4427944 100644 --- a/src/Module/Item.php +++ b/src/Module/Item.php @@ -1178,8 +1178,10 @@ class Item extends Controller $attach_link = ''; $hash = substr($mtch, 0, strpos($mtch, ',')); $rev = intval(substr($mtch, strpos($mtch, ','))); - if (str_starts_with($mtch, 'https://')) { - $attachments[] = [ 'href' => $mtch, 'type' => 'application/activity+json', 'title' => $mtch ]; + if (str_starts_with($mtch, 'http')) { + $attachments[] = [ 'href' => $mtch, 'type' => 'text/html', 'title' => $mtch ]; + } elseif (str_starts_with($mtch, 'jsonld://')) { + $attachments[] = [ 'href' => str_replace('jsonld://', 'https://', $mtch), 'type' => 'application/activity+json', 'title' => $mtch ]; } else { $r = attach_by_hash_nodata($hash, $observer['xchan_hash'], $rev); diff --git a/src/Module/Linkinfo.php b/src/Module/Linkinfo.php index 7d71a3ab6..1b7e26ecb 100644 --- a/src/Module/Linkinfo.php +++ b/src/Module/Linkinfo.php @@ -258,7 +258,7 @@ class Linkinfo extends Controller if (check_siteallowed($r['hubloc_id_url']) && check_channelallowed($z['author_xchan'])) { $s = new Zlib\Share($z); echo $s->bbcode(); - echo "\n" . '[attachment]' . $z['mid'] . '[/attachment]' . "\n"; + echo "\n" . '[attachment]' . str_replace('https://', 'jsonld://', $z['mid']) . '[/attachment]' . "\n"; killme(); } } diff --git a/src/Module/Photos.php b/src/Module/Photos.php index 5d49d4b4e..eb23de57b 100644 --- a/src/Module/Photos.php +++ b/src/Module/Photos.php @@ -465,7 +465,7 @@ class Photos extends Controller intval($item_id) ); - // make sure the attach has the same permissions as the photo regardless of any other changes + // make sure the "attach" table has the same permissions as the photo regardless of any other changes $x = q( "update attach set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where hash = '%s' and uid = %d and is_photo = 1", dbesc($perm['allow_cid']),