Skip to content

Commit

Permalink
Release v1.3.8 - Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
reganlawton committed Jun 15, 2021
1 parent cefd5c2 commit 7d5171c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# oEmbed Changelog

## 1.3.8 - 2020-06-15

### Updated
- Fixes issue with code changes due to PHP namespacing.
- Updates to caching key to support embed options, this resolves issues [#73](https://github.com/wrav/oembed/issues/73).

## 1.3.7 - 2020-06-15

### Updated
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wrav/oembed",
"description": "A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.",
"type": "craft-plugin",
"version": "1.3.7",
"version": "1.3.8",
"keywords": [
"craft",
"cms",
Expand Down
5 changes: 3 additions & 2 deletions src/models/OembedModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Embed\Adapters\Youtube;
use wrav\oembed\Oembed;
use craft\base\Model;
use craft\helpers\Json;

/**
* OembedModel Model
Expand Down Expand Up @@ -159,9 +160,9 @@ public function media(array $options = [])
/**
* @return boolean
*/
public function valid()
public function valid(array $options = [])
{
$media = $this->embed();
$media = $this->embed($options);
return (!empty($media) && isset($media->code));
}
}
11 changes: 9 additions & 2 deletions src/services/OembedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ class OembedService extends Component
*/
public function embed($url, array $options = [])
{
try {
$hash = md5(json_encode($options));
} catch (\Exception $exception) {
$hash = '';
}
$cacheKey = $url.'_'.$hash;

if (Oembed::getInstance()->getSettings()->enableCache && Craft::$app->cache->exists($url)) {
return \Craft::$app->cache->get($url);
return \Craft::$app->cache->get($cacheKey);
}

if (Oembed::getInstance()->getSettings()->facebookKey) {
Expand Down Expand Up @@ -132,7 +139,7 @@ public function __call(string $name , array $arguments )
}
finally {
if (Oembed::getInstance()->getSettings()->enableCache) {
Craft::$app->cache->set($url, $media, 'P1H');
Craft::$app->cache->set($cacheKey, $media, 'P1H');
}

return $media;
Expand Down

0 comments on commit 7d5171c

Please sign in to comment.