Merge branch 'dev' of codeberg.org:streams/streams into dev

This commit is contained in:
Mike Macgirvin 2024-06-14 12:44:13 +10:00
commit bff2cc3142
10 changed files with 1468 additions and 1343 deletions

View file

@ -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'];

View file

@ -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=\&quot\;(.*?)\&quot\;/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]];
}

48
src/Lib/DataUrl.php Normal file
View file

@ -0,0 +1,48 @@
<?php
namespace Code\Lib;
class DataUrl
{
protected $data = null;
protected $mediaType = null;
protected $encoding = null;
public function __construct($data, $mediaType = '', $encoding = '')
{
$this->data = $data;
$this->mediaType = $mediaType;
$this->encoding = $encoding;
return $this;
}
public function encode()
{
return 'data:' . $this->mediaType . (($this->encoding) ? ';' . $this->encoding : '') . ','
. (($this->encoding) ? base64_encode($this->data) : urlencode($this->data));
}
public function decode()
{
if (str_starts_with($this->data, 'data:')) {
$explode = explode(',', $this->data);
if (count($explode) === 2) {
$this->mediaType = substr($explode[0], strlen('data:'));
if (str_ends_with($this->mediaType, ';base64')) {
$this->encoding = 'base64';
$this->mediaType = substr($this->mediaType, 0, strlen($this->mediaType) - strlen(';base64'));
} else {
$this->encoding = '';
}
return [
'data' => $this->encoding ? base64_decode($this->data) : urldecode($this->data),
'encoding' => $this->encoding,
'mediaType' => $this->mediaType ?: 'text/plain;charset=US-ASCII',
];
}
}
return null;
}
}

View file

@ -132,6 +132,40 @@ class Embedphotos extends Controller
return '';
}
protected static function insertAlbum($folder, $channel)
{
$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;
}
protected static function filelink($resource, $channel_id = 0)
@ -143,7 +177,9 @@ class Embedphotos extends Controller
}
$r = attach_by_hash($resource,get_observer_hash());
if ($r['success'] && $r['data']['is_dir']) {
return self::insertAlbum($r['data'], $channel);
}
$url = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $r['data']['display_path'];
if (str_starts_with($r['data']['filetype'], 'video')) {

View file

@ -513,4 +513,9 @@ class Inbox extends Controller
}
return false;
}
function get()
{
http_status_exit(403, 'Permission denied');
}
}

View file

@ -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);

View file

@ -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();
}
}

View file

@ -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']),

File diff suppressed because it is too large Load diff

View file

@ -1,2 +1,2 @@
<?php
define ('STD_VERSION', '24.06.10');
define ('STD_VERSION', '24.06.14');