Update mastodonapi.php

This commit is contained in:
simonpipe 2026-01-07 19:14:15 +01:00
parent f605b3f8be
commit bfeb41fdf1

View file

@ -109,7 +109,10 @@ class YellowMastodonapi {
$fileName = date("Y-m-d", strtotime($createdAt)) . "-" . $titleSlug . ".md";
$fullPath = $this->yellow->system->get("coreServerDocument") . $targetFolder . $fileName;
if ( file_exists($fullPath) ) continue;
if ( !is_dir(dirname($fullPath)) ) mkdir(dirname($fullPath), 0755, true);
if ( !is_dir(dirname($fullPath)) ) {
mkdir(dirname($fullPath), 0777, true);
chmod(dirname($fullPath), 0777);
}
$imageFilenames = array();
$imageAltTexts = array();
foreach ( $post["media_attachments"] ?? array() as $media ) {
@ -137,10 +140,17 @@ class YellowMastodonapi {
private function downloadAndSaveImage($media, $dirPath) {
$imageUrl = $media["remote_url"] ?? $media["url"] ?? $media["preview_url"] ?? null;
if ( empty($imageUrl) ) return false;
if ( !is_dir($dirPath) ) mkdir($dirPath, 0755, true);
if ( !is_dir($dirPath) ) {
mkdir($dirPath, 0777, true);
chmod($dirPath, 0777);
}
$fileName = basename(parse_url($imageUrl, PHP_URL_PATH));
$fullPath = $dirPath . $fileName;
if ( file_exists($fullPath) ) return $fileName;
$ch = curl_init($imageUrl);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true,
@ -151,6 +161,7 @@ class YellowMastodonapi {
));
$imgData = curl_exec($ch);
curl_close($ch);
if ( !$imgData ) return false;
file_put_contents($fullPath, $imgData);
return $fileName;