<?php
require_once MODX_BASE_PATH.'assets/snippets/includeVideo/includeVideo.class.php';
$param=array();
if(isset($docid))
$param['docid']=$docid;
/*$docid is used to specify another document*/
if(isset($type))
$param['type'] = $type;
/*$type has 2 settings, default uses a modal layer to display the video (trigger by click event) and embed embeds the video in the content*/
if(isset($vimeoID))
$param['vimeoID'] = $vimeoID;
/*$vimeoID allows the editor to directly enter the ID in the snippet call */
$includeVideoApp = new includeVideo($param);
return $includeVideoApp->output;
?>
<?php
if(!class_exists('includeVideo')){
class includeVideo {
public $version = '0.0.1';
var $basePath = MODX_BASE_PATH;
var $params = array();
var $debug = false;
var $froogaloop = '/* froogaloop js code */';
var $script;
function __construct($params=array()){
global $modx;
$default_params = array();
$this->params=array_merge($default_params,$params);
$this->dispatch('BuildVideo');
}
private function BuildVideo(){
global $modx;
if(isset($this->params['vimeoID'])){
$values['vimeoID'] = $this->params['vimeoID'];
} else {
$docid = isset($this->params['docid']) ? $this->params['docid'] : $modx->documentIdentifier;
$values = $modx->getTemplateVarOutput('vimeoID',$docid);
}
if($values['vimeoID'] != ''){
$data = $this->getVimeoData($values['vimeoID']);
$p = array(
'vimeoId' => $values['vimeoID'],
'width' => $data->width,
'height' => $data->height
);
self::buildPageScript($p);
$modx->regClientStartupScript($this->froogaloop);
$modx->regClientScript($this->script);
return;
} else {
die('No Vimeo ID was found.');
}
}
private function getVimeoData($id){
global $modx;
require_once(MODX_BASE_PATH.'assets/lib/vimeo/vimeo.php');
$vimeo = new phpVimeo('my consumer key', 'my consumer secret');
$vimeo->enableCache(phpVimeo::CACHE_FILE, MODX_BASE_PATH.'assets/cache', 300);
$dataArray = array(
'video_id' => $id,
);
$videos = $vimeo->call('vimeo.videos.getInfo', $dataArray);
$data = $videos->video[0];
return $data;
}
public function dispatch($dispatch=NULL,$vars=NULL){
if(method_exists($this, $dispatch)){
if($this->debug){ $this->output .= '<br>Calling => '.$dispatch.'<br />'; }
self::$dispatch($vars);
} else {
$this->output .= str_replace('[+dispatch+]', $dispatch,$this->lang['GlobalDispatchError']);
}
}
function buildPageScript($p){
global $modx;
$vW = $p['width'];
$vH = $p['height'];
$f = '$f'; //to prevent PHP from interpreting the JS $f as a variable.
if($this->params['type'] != 'embed'){
$itemID = $this->generateRandomString(21);
$this->script = "<script type=\"text/javascript\">
/* event triggered modal js */
</script>";
} else {
$itemID = $this->generateRandomString(21);
$this->output = '<iframe id="'.$itemID.'" width="100%" height="100%" frameborder="0" src="http://player.vimeo.com/video/'.$p['vimeoId'].'?title=0&byline=0&portrait=0&color=ffc423&autoplay=0&api=1&player_id='.$itemID.'" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
$this->script = "<script type=\"text/javascript\" name=\"vimeo_scripts\">
/* embedded video js*/
</script>";
}
}
function generateRandomString($length = 24) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = 'con';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
//-- END OF CLASS
}
}
This question has been answered by multiple community members. See the first response.
[!includeVideo? ¶m=`etc…`!]
[[includeVideo? & param=`etc…`]]
I use the "Include" snippet to handle my page templates …Do you change that "Include call" by PHx? Or do use PHx somewhere around the Vimeo Snippet?
[[if? &is=`[+content+]:empty` &then=`[+page_main_art+]` &else=`[+content+]`]]
[[if? &is=`[+content+]:empty` &then=`[+page_main_art+]` &else=`[+content+]`]]