Skip to content

Commit

Permalink
Fixed Mastodon medias not downloaded even if setting is enabled.
Browse files Browse the repository at this point in the history
Medias were downloaded, but the URLs were incorrectly saved to the cached toot, as the remote
URLs were kept by mistake. This has been resolved.

Closes #2.
  • Loading branch information
AmauryCarrade committed Apr 22, 2019
1 parent 5fec5a3 commit 27de887
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions classes/SSEShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ protected function fetchMedia($url, $format = 'auto')
}
}

error_log("Downloading media: " . $url);
error_log("Format: " . $format);
error_log('plugins.static-social-embeds.' . $this->network_name . '.download_content.images = ' . $this->config->get('plugins.static-social-embeds.' . $this->network_name . '.download_content.images'));
error_log('plugins.static-social-embeds.' . $this->network_name . '.download_content.videos = ' . $this->config->get('plugins.static-social-embeds.' . $this->network_name . '.download_content.videos'));

// Are we allowed to cache images?
if ($format == 'image' && !$this->config->get('plugins.static-social-embeds.' . $this->network_name . '.download_content.images'))
Expand All @@ -185,6 +189,8 @@ protected function fetchMedia($url, $format = 'auto')
return $url;
}

error_log("Downloading…");

$ch = curl_init();
$tmp_file_path = $this->tmp_dir . '/' . sha1($url) . '.' . $extension;
$tmp_dir_name = dirname($tmp_file_path);
Expand Down Expand Up @@ -220,6 +226,9 @@ protected function fetchMedia($url, $format = 'auto')

rename($tmp_file_path, $this->images_dir . $storage_file_path);

error_log("Downloaded to " . $this->grav['base_url'] . '/' . $this->images_path . $storage_file_path);
error_log("");

return $this->grav['base_url'] . '/' . $this->images_path . $storage_file_path;
}

Expand Down
2 changes: 2 additions & 0 deletions shortcodes/MastodonShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ protected function getData($url)
$media['preview_url'] = $media['url'];
break;
}

$toot['media_attachments'][$id] = $media;
}
}

Expand Down

0 comments on commit 27de887

Please sign in to comment.