Skip to content

Commit

Permalink
refs #1749 : added - Context object now covers every plugin-specific …
Browse files Browse the repository at this point in the history
…passing parameters, including skin tag parser.
  • Loading branch information
inureyes committed Feb 16, 2015
1 parent 6a9f6d1 commit 520d92f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 33 deletions.
12 changes: 1 addition & 11 deletions framework/model/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,7 @@ private function __getKey($key, $namespace) {
return $key;
}
public function getProperty($key, $defaultValue = null) {
global $pluginName;
if(strpos($key,'.') === false) { // If key doesn't contain namespace,
if (!empty($this->__namespace)) $key = $this->__namespace.'.'.$key;
else {
if(!empty($pluginName)) {
$key = $pluginName.'.'.$key;
} else {
$key = 'global.'.$key;
}
}
}
$key = $this->__getKey($key, null);
if (isset($this->__property[$key])) return $this->__property[$key];
else return $defaultValue;
}
Expand Down
82 changes: 60 additions & 22 deletions library/model/common.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ function fireEvent($event, $target = null, $mother = null, $condition = true) {
else
$configVal = null;

$context->setProperty('plugin.uri',"{$service['path']}/plugins/{$mapping['plugin']}");
$context->setProperty('plugin.uri',$context->getProperty('service.path')."/plugins/{$mapping['plugin']}");
$context->setProperty('plugin.path',ROOT . "/plugins/{$mapping['plugin']}");
$context->setProperty('plugin.name',$mapping['plugin']);
$pluginURL = "{$service['path']}/plugins/{$mapping['plugin']}";
$pluginPath = ROOT . "/plugins/{$mapping['plugin']}";
$pluginName = $mapping['plugin'];
$pluginURL = $context->getProperty('plugin.uri'); // Legacy plugin support.
$pluginPath = $context->getProperty('plugin.path');
$pluginName = $context->getProperty('plugin.name');
// Loading locale resource
$languageDomain = null;
if(is_dir($pluginPath . '/locale/')) {
Expand Down Expand Up @@ -376,7 +376,8 @@ function fireEvent($event, $target = null, $mother = null, $condition = true) {
}

function handleTags( & $content) {
global $service, $tagMappings, $pluginURL, $pluginPath, $pluginName, $configMappings, $configVal;
global $tagMappings, $pluginURL, $pluginPath, $pluginName, $configMappings, $configVal;
$context = Model_Context::getInstance();
if (preg_match_all('/\[##_(\w+)_##\]/', $content, $matches)) {
foreach ($matches[1] as $tag) {
if (!isset($tagMappings[$tag]))
Expand All @@ -389,9 +390,12 @@ function handleTags( & $content) {
$configVal = getCurrentSetting($mapping['plugin']);
else
$configVal ='';
$pluginURL = "{$service['path']}/plugins/{$mapping['plugin']}";
$pluginPath = ROOT . "/plugins/{$mapping['plugin']}";
$pluginName = $mapping['plugin'];
$context->setProperty('plugin.uri',$context->getProperty('service.path')."/plugins/{$mapping['plugin']}");
$context->setProperty('plugin.path',ROOT . "/plugins/{$mapping['plugin']}");
$context->setProperty('plugin.name',$mapping['plugin']);
$pluginURL = $context->getProperty('plugin.uri'); // Legacy plugin support.
$pluginPath = $context->getProperty('plugin.path');
$pluginName = $context->getProperty('plugin.name');
// Loading locale resource
$languageDomain = null;
if(is_dir($pluginPath . '/locale/')) {
Expand All @@ -406,6 +410,9 @@ function handleTags( & $content) {
$target = call_user_func($mapping['handler'], $target);
if(!is_null($languageDomain)) $locale->domain = $languageDomain;
$pluginURL = $pluginPath = $pluginName = "";
$context->unsetProperty('plugin.uri');
$context->unsetProperty('plugin.path');
$context->unsetProperty('plugin.name');
}
}
dress($tag, $target, $content);
Expand All @@ -414,7 +421,9 @@ function handleTags( & $content) {
}

function handleCenters($mapping) {
global $service, $pluginURL, $pluginPath, $pluginName, $configMappings, $configVal;
global $pluginURL, $pluginPath, $pluginName, $configMappings, $configVal;
$context = Model_Context::getInstance();

$target = '';

include_once (ROOT . "/plugins/{$mapping['plugin']}/index.php");
Expand All @@ -423,9 +432,12 @@ function handleCenters($mapping) {
$configVal = getCurrentSetting($mapping['plugin']);
else
$configVal ='';
$pluginURL = "{$service['path']}/plugins/{$mapping['plugin']}";
$pluginPath = ROOT . "/plugins/{$mapping['plugin']}";
$pluginName = $mapping['plugin'];
$context->setProperty('plugin.uri',$context->getProperty('service.path')."/plugins/{$mapping['plugin']}");
$context->setProperty('plugin.path',ROOT . "/plugins/{$mapping['plugin']}");
$context->setProperty('plugin.name',$mapping['plugin']);
$pluginURL = $context->getProperty('plugin.uri'); // Legacy plugin support.
$pluginPath = $context->getProperty('plugin.path');
$pluginName = $context->getProperty('plugin.name');
// Loading locale resource
$languageDomain = null;
if(is_dir($pluginPath . '/locale/')) {
Expand All @@ -440,6 +452,9 @@ function handleCenters($mapping) {
$target = call_user_func($mapping['handler'], $target);
if(!is_null($languageDomain)) $locale->domain = $languageDomain;
$pluginURL = $pluginPath = $pluginName = "";
$context->unsetProperty('plugin.uri');
$context->unsetProperty('plugin.path');
$context->unsetProperty('plugin.name');
}

return $target;
Expand Down Expand Up @@ -517,6 +532,7 @@ function handleSidebars(& $sval, & $obj, $previewMode) {
// 저장된 표지 정렬 순서 정보를 가져온다.
function handleCoverpages(& $obj, $previewMode = false) {
global $service, $pluginURL, $pluginPath, $pluginName, $configVal, $configMappings;
$context = Model_Context::getInstance();
requireModel("blog.coverpage");
// [coverpage id][element id](type, id, parameters)
// type : 3=plug-in
Expand All @@ -538,10 +554,15 @@ function handleCoverpages(& $obj, $previewMode = false) {
if (function_exists($handler)) {
$obj->coverpageModule[$j] = "[##_temp_coverpage_element_{$i}_{$j}_##]";
$parameters = $currentCoverpageOrder[$j]['parameters'];
$pluginURL = "{$service['path']}/plugins/{$plugin}";
$pluginPath = ROOT . "/plugins/{$plugin}";
$pluginName = $plugin;
if( !empty( $configMappings[$plugin]['config'] ) )

$context->setProperty('plugin.uri',$context->getProperty('service.path')."/plugins/{$plugin}");
$context->setProperty('plugin.path',ROOT . "/plugins/{$plugin}");
$context->setProperty('plugin.name',$plugin);
$pluginURL = $context->getProperty('plugin.uri'); // Legacy plugin support.
$pluginPath = $context->getProperty('plugin.path');
$pluginName = $context->getProperty('plugin.name');

if( !empty( $configMappings[$plugin]['config'] ) )
$configVal = getCurrentSetting($plugin);
else
$configVal ='';
Expand All @@ -561,6 +582,9 @@ function handleCoverpages(& $obj, $previewMode = false) {
$obj->coverpageStorage["temp_coverpage_element_{$i}_{$j}"] = call_user_func($handler, $parameters);
if(!is_null($languageDomain)) $locale->domain = $languageDomain;
$pluginURL = $pluginPath = $pluginName = "";
$context->unsetProperty('plugin.uri');
$context->unsetProperty('plugin.path');
$context->unsetProperty('plugin.name');
} else {
$obj->coverpageStorage["temp_coverpage_element_{$i}_{$j}"] = "";
}
Expand All @@ -574,6 +598,8 @@ function handleCoverpages(& $obj, $previewMode = false) {

function handleDataSet( $plugin , $DATA ) {
global $configMappings, $activePlugins, $service, $pluginURL, $pluginPath, $pluginName, $configMapping, $configVal;
$context = Model_Context::getInstance();

$xmls = new XMLStruct();
if( ! $xmls->open($DATA) ) {
unset($xmls);
Expand All @@ -584,9 +610,13 @@ function handleDataSet( $plugin , $DATA ) {
return array('error' => '9' , 'customError'=> _f('%1 : 플러그인이 활성화되어 있지 않아 설정을 저장하지 못했습니다.',$plugin));
$reSetting = true;
if( !empty( $configMappings[$plugin]['dataValHandler'] ) ) {
$pluginURL = "{$service['path']}/plugins/{$plugin}";
$pluginPath = ROOT . "/plugins/{$plugin}";
$pluginName = $plugin;
$context->setProperty('plugin.uri',$context->getProperty('service.path')."/plugins/{$plugin}");
$context->setProperty('plugin.path',ROOT . "/plugins/{$plugin}");
$context->setProperty('plugin.name',$plugin);
$pluginURL = $context->getProperty('plugin.uri'); // Legacy plugin support.
$pluginPath = $context->getProperty('plugin.path');
$pluginName = $context->getProperty('plugin.name');

include_once (ROOT . "/plugins/{$plugin}/index.php");
if( function_exists( $configMappings[$plugin]['dataValHandler'] ) ) {
if( !empty( $configMappings[$plugin]['config'] ) )
Expand All @@ -607,6 +637,9 @@ function handleDataSet( $plugin , $DATA ) {

$reSetting = call_user_func( $configMappings[$plugin]['dataValHandler'] , serialize(Setting::fetchConfigXML($DATA)));
$pluginURL = $pluginPath = $pluginName = "";
$context->unsetProperty('plugin.uri');
$context->unsetProperty('plugin.path');
$context->unsetProperty('plugin.name');
if(!is_null($languageDomain)) $locale->domain = $languageDomain;
}
if( true !== $reSetting )
Expand All @@ -622,6 +655,7 @@ function fetchConfigVal($DATA) {

function handleConfig($plugin) {
global $service , $typeSchema, $pluginURL, $pluginPath, $pluginName, $configMappings, $configVal, $adminSkinSetting;
$context = Model_Context::getInstance();
$typeSchema = array(
'text'
, 'textarea'
Expand All @@ -647,9 +681,13 @@ function handleConfig($plugin) {
if( !empty($config['.attributes']['manifestHandler']) ) {
$handler = $config['.attributes']['manifestHandler'] ;
$oldconfig = $config;
$pluginURL = "{$service['path']}/plugins/{$plugin}";
$pluginPath = ROOT . "/plugins/{$plugin}";
$pluginName = $plugin;
$context->setProperty('plugin.uri',$context->getProperty('service.path')."/plugins/{$plugin}");
$context->setProperty('plugin.path',ROOT . "/plugins/{$plugin}");
$context->setProperty('plugin.name',$plugin);
$pluginURL = $context->getProperty('plugin.uri'); // Legacy plugin support.
$pluginPath = $context->getProperty('plugin.path');
$pluginName = $context->getProperty('plugin.name');

include_once (ROOT . "/plugins/$plugin/index.php");
if (function_exists($handler)) {
if( !empty( $configMappings[$plugin]['config'] ) )
Expand Down

0 comments on commit 520d92f

Please sign in to comment.