mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 16:35:19 +00:00
attach photo album from cloud
This commit is contained in:
parent
34c2e78a14
commit
1800b88ffd
6 changed files with 68 additions and 15 deletions
|
@ -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'];
|
||||
|
|
|
@ -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]];
|
||||
}
|
||||
|
|
|
@ -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'],'<token:')) {
|
||||
$token = substr($image['allow_cid'], strpos($image['allow_cid'], '<token:'));
|
||||
$token = substr($token, 0, strpos($token, '>'));
|
||||
$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'];
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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']),
|
||||
|
|
Loading…
Reference in a new issue