Skip to content

Commit

Permalink
Improve class loading
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpede committed Nov 15, 2017
1 parent 05df7c4 commit 237c05a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
$getyoutube = $modx->getService('getyoutube','getYoutube',$modx->getOption('getyoutube.core_path',null,$modx->getOption('core_path').'components/getyoutube/').'model/getyoutube/',$scriptProperties);
if (!($getyoutube instanceof getYoutube)) return '';

$modx->loadClass('Search',$getyoutube->config['modelPath'], true, true);
$search = new Search($modx);

/* set default properties */
$apiKey = $modx->getOption('getyoutube.api_key',$scriptProperties);
$mode = !empty($mode) ? $mode : ''; //Acceptable values are: channel, video
Expand All @@ -42,37 +45,32 @@
$pageToken = preg_replace('/[^-a-zA-Z0-9_]/','',$_GET['page']); //For pagination
$totalVar = !empty($totalVar) ? $totalVar : '';

include_once ($getyoutube->config['modelPath'] . 'search.class.php');

switch ($mode) {
case "channel":
if (!empty($channel)) {
$query = new search();
$channelUrl = "https://www.googleapis.com/youtube/v3/search?part=id,snippet&channelId=$channel&type=video&safeSearch=$safeSearch&maxResults=$limit&order=$sortby&pageToken=$pageToken&key=$apiKey";
$output = $query->channel($channelUrl,$tpl,$tplAlt,$toPlaceholder,$pageToken,$totalVar);
$output = $search->channel($channelUrl,$tpl,$tplAlt,$toPlaceholder,$pageToken,$totalVar);
}else{
$modx->log(modX::LOG_LEVEL_ERROR, 'getYoutube() - &channel is required');
}
break;
case "playlist":
if (!empty($playlist)) {
$query = new search();
$playlistUrl = "https://www.googleapis.com/youtube/v3/playlistItems?part=id,snippet&playlistId=$playlist&type=video&safeSearch=$safeSearch&maxResults=$limit&order=$sortby&pageToken=$pageToken&key=$apiKey";
$output = $query->playlist($playlistUrl,$tpl,$tplAlt,$toPlaceholder,$pageToken,$totalVar);
$output = $search->playlist($playlistUrl,$tpl,$tplAlt,$toPlaceholder,$pageToken,$totalVar);
}else{
$modx->log(modX::LOG_LEVEL_ERROR, 'getYoutube() - &playlist is required');
}
break;
case "video":
if (!empty($video)) {
$query = new search();
$videoUrl = "https://www.googleapis.com/youtube/v3/videos?part=id,snippet,contentDetails,statistics&id=$video&key=$apiKey";
$output = $query->video($videoUrl,$tpl,$tplAlt,$toPlaceholder,$totalVar);
$output = $search->video($videoUrl,$tpl,$tplAlt,$toPlaceholder,$totalVar);
}else{
$modx->log(modX::LOG_LEVEL_ERROR, 'getYoutube() - &video is required');
}
break;
default: $modx->log(modX::LOG_LEVEL_ERROR, 'getYoutube() - &mode is required'); break;
};

return $output;
return $output;
41 changes: 20 additions & 21 deletions core/components/getyoutube/model/getyoutube/getyoutube.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,24 @@
*/

class getYoutube {
public $modx;
public $config = array();
function __construct(modX &$modx,array $config = array()) {
$this->modx =& $modx;

$corePath = $this->modx->getOption('getyoutube.core_path',$config,$this->modx->getOption('core_path').'components/getyoutube/');
//$assetsUrl = $this->modx->getOption('getyoutube.assets_url',$config,$this->modx->getOption('assets_url').'components/getyoutube/');
$this->config = array_merge(array(
'basePath' => $corePath,
'corePath' => $corePath,
'modelPath' => $corePath.'model/getyoutube/',
//'processorsPath' => $corePath.'processors/',
//'templatesPath' => $corePath.'templates/',
'chunksPath' => $corePath.'elements/chunks/',
//'jsUrl' => $assetsUrl.'js/',
//'cssUrl' => $assetsUrl.'css/',
//'assetsUrl' => $assetsUrl,
//'connectorUrl' => $assetsUrl.'connector.php',
),$config);

}
public $modx;
public $config = array();
function __construct(modX &$modx,array $config = array()) {
$this->modx =& $modx;
$corePath = $this->modx->getOption('getyoutube.core_path',$config,$this->modx->getOption('core_path').'components/getyoutube/');
$assetsUrl = $this->modx->getOption('getyoutube.assets_url',$config,$this->modx->getOption('assets_url').'components/getyoutube/');
$this->config = array_merge(array(
'basePath' => $corePath,
'corePath' => $corePath,
'modelPath' => $corePath.'model/getyoutube/',
'processorsPath' => $corePath.'processors/',
'templatesPath' => $corePath.'templates/',
'chunksPath' => $corePath.'elements/chunks/',
'jsUrl' => $assetsUrl.'js/',
'cssUrl' => $assetsUrl.'css/',
'assetsUrl' => $assetsUrl,
'connectorUrl' => $assetsUrl.'connector.php',
),$config);
$this->modx->addPackage('getyoutube',$this->config['modelPath']);
}
}

0 comments on commit 237c05a

Please sign in to comment.