-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to rebuild the Vimeo cache of custom content elements
- Loading branch information
Showing
6 changed files
with
251 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* vimeo_api extension for Contao Open Source CMS | ||
* | ||
* Copyright (C) 2016 derhaeuptling | ||
* | ||
* @author derhaeuptling <https://derhaeuptling.com> | ||
* @author Codefog <http://codefog.pl> | ||
* @author Kamil Kuzminski <kamil.kuzminski@codefog.pl> | ||
* @license LGPL | ||
*/ | ||
|
||
namespace Derhaeuptling\VimeoApi\Maintenance; | ||
|
||
use Contao\Config; | ||
use Contao\ContentModel; | ||
use Derhaeuptling\VimeoApi\VimeoApi; | ||
use Derhaeuptling\VimeoApi\VimeoVideo; | ||
|
||
class AlbumCacheRebuilder implements CacheRebuildInterface | ||
{ | ||
/** | ||
* Return true if the element is eligible for rebuild | ||
* | ||
* @param array $data | ||
* | ||
* @return bool | ||
*/ | ||
public function isEligible(array $data) | ||
{ | ||
return $data['vimeo_albumId'] ? true : false; | ||
} | ||
|
||
/** | ||
* Rebuild the cache and return true on success, false otherwise | ||
* | ||
* @param VimeoApi $api | ||
* @param ContentModel $contentElement | ||
* | ||
* @return bool | ||
*/ | ||
public function rebuild(VimeoApi $api, ContentModel $contentElement) | ||
{ | ||
$client = $api->getClient(); | ||
|
||
if (($album = $api->getAlbum($client, $contentElement->vimeo_albumId)) === null) { | ||
return false; | ||
} | ||
|
||
/** @var VimeoVideo $video */ | ||
foreach ($api->getAlbumVideos($client, $contentElement->vimeo_albumId) as $video) { | ||
if (($image = $api->getVideoImage($client, $video->getId(), Config::get('vimeo_imageIndex'))) === null) { | ||
return false; | ||
} | ||
|
||
$video->setPicturesData($image); | ||
$video->downloadPoster(); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* vimeo_api extension for Contao Open Source CMS | ||
* | ||
* Copyright (C) 2016 derhaeuptling | ||
* | ||
* @author derhaeuptling <https://derhaeuptling.com> | ||
* @author Codefog <http://codefog.pl> | ||
* @author Kamil Kuzminski <kamil.kuzminski@codefog.pl> | ||
* @license LGPL | ||
*/ | ||
|
||
namespace Derhaeuptling\VimeoApi\Maintenance; | ||
|
||
use Contao\ContentModel; | ||
use Derhaeuptling\VimeoApi\VimeoApi; | ||
|
||
interface CacheRebuildInterface | ||
{ | ||
/** | ||
* Return true if the element is eligible for rebuild | ||
* | ||
* @param array $data | ||
* | ||
* @return bool | ||
*/ | ||
public function isEligible(array $data); | ||
|
||
/** | ||
* Rebuild the cache and return true on success, false otherwise | ||
* | ||
* @param VimeoApi $api | ||
* @param ContentModel $contentElement | ||
* | ||
* @return bool | ||
*/ | ||
public function rebuild(VimeoApi $api, ContentModel $contentElement); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* vimeo_api extension for Contao Open Source CMS | ||
* | ||
* Copyright (C) 2016 derhaeuptling | ||
* | ||
* @author derhaeuptling <https://derhaeuptling.com> | ||
* @author Codefog <http://codefog.pl> | ||
* @author Kamil Kuzminski <kamil.kuzminski@codefog.pl> | ||
* @license LGPL | ||
*/ | ||
|
||
namespace Derhaeuptling\VimeoApi\Maintenance; | ||
|
||
use Contao\Config; | ||
use Contao\ContentModel; | ||
use Derhaeuptling\VimeoApi\VimeoApi; | ||
|
||
class VideoCacheRebuilder implements CacheRebuildInterface | ||
{ | ||
/** | ||
* Return true if the element is eligible for rebuild | ||
* | ||
* @param array $data | ||
* | ||
* @return bool | ||
*/ | ||
public function isEligible(array $data) | ||
{ | ||
return $data['vimeo_videoId'] ? true : false; | ||
} | ||
|
||
/** | ||
* Rebuild the cache and return true on success, false otherwise | ||
* | ||
* @param VimeoApi $api | ||
* @param ContentModel $contentElement | ||
* | ||
* @return bool | ||
*/ | ||
public function rebuild(VimeoApi $api, ContentModel $contentElement) | ||
{ | ||
$client = $api->getClient(); | ||
|
||
if (($video = $api->getVideo($client, $contentElement->vimeo_videoId)) === null) { | ||
return false; | ||
} | ||
|
||
if (($image = $api->getVideoImage($client, $video->getId(), Config::get('vimeo_imageIndex'))) === null) { | ||
return false; | ||
} | ||
|
||
$video->setPicturesData($image); | ||
$video->downloadPoster(); | ||
|
||
return true; | ||
} | ||
} |