This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds CDN handler to handle videos using a cdn from the config
- Loading branch information
Showing
1 changed file
with
103 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
|
||
namespace Bolt\Extension\cdowdy\html5video\Handler; | ||
|
||
use Silex\Application; | ||
|
||
|
||
class CDNHandler { | ||
/** | ||
* @var | ||
*/ | ||
protected $app; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $_extensionConfig; | ||
protected $_configname; | ||
|
||
|
||
/** | ||
* CDNHandler constructor. | ||
* | ||
* @param array $_extensionConfig | ||
* @param $configname | ||
* @param Application $app | ||
*/ | ||
public function __construct( array $_extensionConfig, $configname, Application $app ) | ||
{ | ||
$this->_extensionConfig = $_extensionConfig; | ||
$this->_configname = $configname; | ||
$this->app = $app; | ||
} | ||
|
||
|
||
/** | ||
* @param $filename | ||
* | ||
* @return array | ||
*/ | ||
public function cdnFile( $filename ) | ||
{ | ||
|
||
$cdnURL = $this->_extensionConfig['cdn_url']; | ||
$video = []; | ||
|
||
if ( $cdnURL ) { | ||
|
||
if ( is_array( $filename ) ) { | ||
foreach ( $filename as $key => $value ) { | ||
$pathInfo = pathinfo( $value ); | ||
$video += [ $cdnURL . $value => $pathInfo['extension'] ]; | ||
} | ||
} else { | ||
$pathInfo = pathinfo( $filename ); | ||
|
||
$video += [ $cdnURL . $filename => $pathInfo['extension'] ]; | ||
} | ||
|
||
} else { | ||
|
||
|
||
if ( is_array( $filename ) ) { | ||
foreach ( $filename as $key => $value ) { | ||
$pathInfo = pathinfo( $value ); | ||
$video += [ $value => $pathInfo['extension'] ]; | ||
} | ||
} else { | ||
$pathInfo = pathinfo( $filename ); | ||
|
||
$video += [ $filename => $pathInfo['extension'] ]; | ||
} | ||
|
||
} | ||
|
||
|
||
return $video; | ||
} | ||
|
||
/** | ||
* @param $url | ||
* | ||
* @return bool | ||
*/ | ||
public function checkForActualURL( $url ) | ||
{ | ||
$configCDNURL = $this->_extensionConfig['cdn_url']; | ||
// no cdn url found in the config so check if the string submitted in the template is an actual URL | ||
$templateURL = parse_url( $url, PHP_URL_HOST ); | ||
$errorMessage = "A CDN Url could not be found in the config and a proper url wasn't supplied in the template. The File used in the template is: {$url}"; | ||
|
||
if ( ! $configCDNURL && ! $templateURL ) { | ||
$this->app['logger.flash']->error( 'HTML5Video:: ' . $errorMessage ); | ||
|
||
$this->app['logger.system']->error( 'HTML5Video:: ' . $errorMessage, [ 'event' => 'extension' ] ); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |