Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions core/components/cliche/controllers/clichecontroller.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function __construct(&$controller) {
$this->controller =& $controller;
$this->modx =& $controller->modx;
}

/**
* Set an option for this module
* @param string $key
Expand Down Expand Up @@ -70,8 +70,8 @@ abstract class ClicheController {
/** @var array $scriptProperties */
protected $scriptProperties = array();

protected $placeholders = array();
protected $placeholders = array();

abstract public function initialize();
abstract public function process();

Expand All @@ -92,7 +92,7 @@ function __construct(Cliche &$cliche,array $config = array()) {
*/
public function run($scriptProperties) {
$this->setProperties($scriptProperties);
$this->loadPlugin();
$this->loadPlugin();
$this->initialize();
/* chunks_path is not overridable by script properties - better for multi instance call */
$chunksPath = isset( $this->config['chunks_path'] ) ? $this->config['chunks_path'] : null;
Expand All @@ -109,12 +109,13 @@ public function run($scriptProperties) {
public function loadPlugin(){
$plugin = $this->getProperty('plugin');
if(!empty($plugin)){
if (!$this->modx->loadClass("{$plugin}.{$plugin}", $this->config['plugins_path'],true,true)) {
$this->modx->log(modX::LOG_LEVEL_ERROR, '[Cliche] Could not load '.$plugin.' plugin in: '. $this->config['plugins_path'] . $plugin .'/'. $plugin .'.class.php');
$pluginFile = strtolower($plugin);
if (!$this->modx->loadClass("{$pluginFile}.{$pluginFile}", $this->config['plugins_path'],true,true)) {
$this->modx->log(modX::LOG_LEVEL_ERROR, '[Cliche] Could not load '.$plugin.' plugin in: '. $this->config['plugins_path'] . $pluginFile .'/'. $pluginFile .'.class.php');
}
$className = empty($plugin) || $plugin == 'default' ? 'DefaultPlugin' : ucfirst($plugin);
$this->plugin = new $className($this);
}
$className = empty($plugin) || $plugin == 'default' ? 'DefaultPlugin' : ucfirst($plugin);
$this->plugin = new $className($this);
}

/**
Expand All @@ -123,7 +124,7 @@ public function loadPlugin(){
* @param mixed $args Optional arguments to pass to the plugin class
* @return mixed/void if $args is not supplied else the processed $args
*/
public function fireEvent($event, $args = null){
public function fireEvent($event, $args = null){
if(isset($this->plugin) && is_object($this->plugin)){
if(is_callable(array($this->plugin, $event))){
if($args == null){
Expand All @@ -132,8 +133,8 @@ public function fireEvent($event, $args = null){
} else {
return call_user_func_array( array($this->plugin, $event), $args );
}
}
}
}
}
return false;
}

Expand All @@ -143,7 +144,7 @@ public function fireEvent($event, $args = null){
*/
public function loadCSS($name) {
$this->modx->regClientCSS($this->config['plugin_assets_url'] . $name .'.css');
}
}

/**
* Set the default options for this module
Expand Down Expand Up @@ -243,7 +244,7 @@ public function runProcessor($processor,array $scriptProperties = array()) {
}
return $output;
}

/**
* Convert string params to path for use in file based chunks
*
Expand All @@ -257,14 +258,14 @@ private function _setDefaultChunksPath(){
$this->modx->getOption('base_path'),
$this->modx->getOption('assets_path'),
), $this->config);
$config['chunks_path'] = $config['plugins_path'] . $this->getProperty('plugin') . '/';
$config['plugin_assets_url'] = $config['plugins_url'] . $this->getProperty('plugin') . '/';
$this->config = array_merge($this->config, $config);
$this->cliche->config = $this->config;
}

$config['chunks_path'] = $config['plugins_path'] . strtolower($this->getProperty('plugin')) . '/';
$config['plugin_assets_url'] = $config['plugins_url'] . strtolower($this->getProperty('plugin')) . '/';

$this->config = array_merge($this->config, $config);
$this->cliche->config = $this->config;
}

/**
* Processes the content of a chunk in either of the following ways:
*
Expand All @@ -286,10 +287,10 @@ public function getChunk($name, $properties = array()) {
if (!$useFileBasedChunks) {
$chunk = $this->modx->getObject('modChunk',array('name' => $name));
}
if (empty($chunk)) {
if (empty($chunk)) {
$chunk = $this->_getTplChunk($name);
if(!is_object($chunk)) return $chunk;
}
}
$this->chunks[$name] = $chunk->getContent();
} else { /* load chunk from cache */
$o = $this->chunks[$name];
Expand All @@ -299,7 +300,7 @@ public function getChunk($name, $properties = array()) {
$chunk->setCacheable(false);
return $chunk->process($properties);
}

/**
* Returns a modChunk object from a template file.
*
Expand Down