Update mastodonapi.php
This commit is contained in:
parent
f605b3f8be
commit
bfeb41fdf1
1 changed files with 13 additions and 2 deletions
|
|
@ -109,7 +109,10 @@ class YellowMastodonapi {
|
||||||
$fileName = date("Y-m-d", strtotime($createdAt)) . "-" . $titleSlug . ".md";
|
$fileName = date("Y-m-d", strtotime($createdAt)) . "-" . $titleSlug . ".md";
|
||||||
$fullPath = $this->yellow->system->get("coreServerDocument") . $targetFolder . $fileName;
|
$fullPath = $this->yellow->system->get("coreServerDocument") . $targetFolder . $fileName;
|
||||||
if ( file_exists($fullPath) ) continue;
|
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();
|
$imageFilenames = array();
|
||||||
$imageAltTexts = array();
|
$imageAltTexts = array();
|
||||||
foreach ( $post["media_attachments"] ?? array() as $media ) {
|
foreach ( $post["media_attachments"] ?? array() as $media ) {
|
||||||
|
|
@ -137,10 +140,17 @@ class YellowMastodonapi {
|
||||||
private function downloadAndSaveImage($media, $dirPath) {
|
private function downloadAndSaveImage($media, $dirPath) {
|
||||||
$imageUrl = $media["remote_url"] ?? $media["url"] ?? $media["preview_url"] ?? null;
|
$imageUrl = $media["remote_url"] ?? $media["url"] ?? $media["preview_url"] ?? null;
|
||||||
if ( empty($imageUrl) ) return false;
|
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));
|
$fileName = basename(parse_url($imageUrl, PHP_URL_PATH));
|
||||||
$fullPath = $dirPath . $fileName;
|
$fullPath = $dirPath . $fileName;
|
||||||
|
|
||||||
if ( file_exists($fullPath) ) return $fileName;
|
if ( file_exists($fullPath) ) return $fileName;
|
||||||
|
|
||||||
$ch = curl_init($imageUrl);
|
$ch = curl_init($imageUrl);
|
||||||
curl_setopt_array($ch, array(
|
curl_setopt_array($ch, array(
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
|
@ -151,6 +161,7 @@ class YellowMastodonapi {
|
||||||
));
|
));
|
||||||
$imgData = curl_exec($ch);
|
$imgData = curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
if ( !$imgData ) return false;
|
if ( !$imgData ) return false;
|
||||||
file_put_contents($fullPath, $imgData);
|
file_put_contents($fullPath, $imgData);
|
||||||
return $fileName;
|
return $fileName;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue