Skip to content

Commit

Permalink
Fixed download options no longer working since per-network options.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmauryCarrade committed Jul 13, 2018
1 parent 5012004 commit a0d53ea
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
25 changes: 19 additions & 6 deletions classes/SSEShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ abstract class SSEShortcode extends Shortcode
*/
private $shortcode_name;

/**
* @var string The network name, as returned by getNetworkName().
* @see SSEShortcode::getNetworkName()
*/
private $network_name;

/** @var string The cache directory for API data */
private $cache_dir;

Expand All @@ -43,6 +49,7 @@ public function __construct()
parent::__construct();

$this->shortcode_name = $this->getShortcodeName();
$this->network_name = $this->getNetworkName();

/** @var $locator ResourceLocatorInterface */
$locator = $this->grav['locator'];
Expand All @@ -63,6 +70,14 @@ public function __construct()
*/
abstract protected function getShortcodeName();


/**
* The network name (e.g. “twitter”), used to retrieve related configuration.
*
* @return string The network name
*/
abstract protected function getNetworkName();

/**
* From the URL, retrieves and returns data transferred to the template.
*
Expand Down Expand Up @@ -159,24 +174,22 @@ protected function fetchMedia($url, $format = 'auto')


// Are we allowed to cache images?
if ($format == 'image' && !$this->config->get('plugins.static-social-embeds.' . $this->shortcode_name . '.download_content.images'))
if ($format == 'image' && !$this->config->get('plugins.static-social-embeds.' . $this->network_name . '.download_content.images'))
{
return $url;
}

// Or videos?
if ($format == 'video' && !$this->config->get('plugins.static-social-embeds.' . $this->shortcode_name . '.download_content.videos'))
if ($format == 'video' && !$this->config->get('plugins.static-social-embeds.' . $this->network_name . '.download_content.videos'))
{
return $url;
}

$cache_permissions = $this->config->get('system.images.cache_perms', '0755');

$ch = curl_init();
$tmp_file_path = $this->tmp_dir . '/' . sha1($url) . '.' . $extension;
$tmp_dir_name = dirname($tmp_file_path);

if (!is_dir($tmp_dir_name)) mkdir($tmp_dir_name, $cache_permissions, true);
if (!is_dir($tmp_dir_name)) mkdir($tmp_dir_name, 0755, true);

$tmp_file = fopen($tmp_file_path, 'w');

Expand All @@ -203,7 +216,7 @@ protected function fetchMedia($url, $format = 'auto')
$storage_file_path = '/' . implode('/', $storage_file_path) . '/' . $storage_file_name;
$storage_file_dir = dirname($this->images_dir . $storage_file_path);

if (!is_dir($storage_file_dir)) mkdir($storage_file_dir, $cache_permissions, true);
if (!is_dir($storage_file_dir)) mkdir($storage_file_dir, 0755, true);

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

Expand Down
11 changes: 10 additions & 1 deletion shortcodes/InstagramShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class InstagramShortcode extends SSEShortcode
{

/**
* The shortcode name (e.g. "tweet"), used for the shortcode of course,
* but also for the template name (in this example, "partials/static-social-embeds/tweet.html.twig").
Expand All @@ -17,6 +16,16 @@ protected function getShortcodeName()
return 'instagram';
}

/**
* The network name (e.g. “twitter”), used to retrieve related configuration.
*
* @return string The network name
*/
protected function getNetworkName()
{
return 'instagram';
}

/**
* From the URL, retrieves and returns data transferred to the template.
*
Expand Down
11 changes: 10 additions & 1 deletion shortcodes/MastodonShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class MastodonShortcode extends SSEShortcode
{

/**
* The shortcode name (e.g. "tweet"), used for the shortcode of course,
* but also for the template name (in this example, "partials/static-social-embeds/tweet.html.twig").
Expand All @@ -23,6 +22,16 @@ protected function getShortcodeName()
return 'toot';
}

/**
* The network name (e.g. “twitter”), used to retrieve related configuration.
*
* @return string The network name
*/
protected function getNetworkName()
{
return 'mastodon';
}

/**
* From the URL, retrieves and returns data transferred to the template.
*
Expand Down
13 changes: 11 additions & 2 deletions shortcodes/TwitterShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class TwitterShortcode extends SSEShortcode
{

/**
* The shortcode name (e.g. "tweet"), used for the shortcode of course,
* but also for the template name (in this example, "partials/static-social-embeds/tweet.html.twig").
Expand All @@ -15,7 +14,17 @@ class TwitterShortcode extends SSEShortcode
*/
protected function getShortcodeName()
{
return "tweet";
return 'tweet';
}

/**
* The network name (e.g. “twitter”), used to retrieve related configuration.
*
* @return string The network name
*/
protected function getNetworkName()
{
return 'twitter';
}

/**
Expand Down

0 comments on commit a0d53ea

Please sign in to comment.