mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 18:51:41 +09:00
Add auto ruleset function
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9982 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
983516dbac
commit
8db1be04bf
7 changed files with 77 additions and 6 deletions
|
|
@ -1151,9 +1151,13 @@ class Context {
|
|||
* @brief Add the js file
|
||||
* @deprecated
|
||||
**/
|
||||
function addJsFile($file, $optimized = false, $targetie = '',$index=0, $type='head', $isRuleset = false) {
|
||||
function addJsFile($file, $optimized = false, $targetie = '',$index=0, $type='head', $isRuleset = false, $autoPath = null) {
|
||||
if($isRuleset)
|
||||
{
|
||||
if (strpos($file, '#') !== false){
|
||||
$file = str_replace('#', '', $file);
|
||||
if (!is_readable($file)) $file = $autoPath;
|
||||
}
|
||||
$validator = new Validator($file);
|
||||
$validator->setCacheDir('files/cache');
|
||||
$file = $validator->getJsPath();
|
||||
|
|
|
|||
|
|
@ -370,7 +370,7 @@
|
|||
if(!empty($ruleset))
|
||||
{
|
||||
$rulesetModule = $forward->module ? $forward->module : $this->module;
|
||||
$rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset);
|
||||
$rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset, $this->mid);
|
||||
if(!empty($rulesetFile))
|
||||
{
|
||||
$Validator = new Validator($rulesetFile);
|
||||
|
|
|
|||
|
|
@ -215,18 +215,30 @@ class TemplateHandler {
|
|||
preg_match('/ruleset="([^"]*?)"/is', $matches[1], $m);
|
||||
if($m[0])
|
||||
{
|
||||
$matches[1] = preg_replace('/'.$m[0].'/i', '', $matches[1]);
|
||||
$matches[2] = '<input type="hidden" name="ruleset" value="'.$m[1].'" />'.$matches[2];
|
||||
$matches[1] = preg_replace('/'.addcslashes($m[0], '?$').'/i', '', $matches[1]);
|
||||
|
||||
if (strpos($m[1],'@') !== false){
|
||||
$path = str_replace('@', '', $m[1]);
|
||||
$path = './files/ruleset/'.$path.'.xml';
|
||||
}else if(strpos($m[1],'#') !== false){
|
||||
$fileName = str_replace('#', '', $m[1]);
|
||||
$fileName = str_replace('<?php echo ', '', $fileName);
|
||||
$fileName = str_replace(' ?>', '', $fileName);
|
||||
$path = '#./files/ruleset/'.$fileName.'.xml';
|
||||
|
||||
preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm);
|
||||
$module_path = $mm[1];
|
||||
list($rulsetFile) = explode('.', $fileName);
|
||||
$autoPath = $module_path.'/ruleset/'.$rulsetFile.'.xml';
|
||||
$m[1] = $rulsetFile;
|
||||
}else if(preg_match('@(?:^|\.?/)(modules/[\w-]+)@', $this->path, $mm)) {
|
||||
$module_path = $mm[1];
|
||||
$path = $module_path.'/ruleset/'.$m[1].'.xml';
|
||||
}
|
||||
|
||||
$matches[2] = '<input type="hidden" name="ruleset" value="'.$m[1].'" />'.$matches[2];
|
||||
//assign to addJsFile method for js dynamic recache
|
||||
$matches[1] = '<?php Context::addJsFile("'.$path.'", false, "", 0, "head", true) ?'.'>'.$matches[1];
|
||||
$matches[1] = '<?php Context::addJsFile("'.$path.'", false, "", 0, "head", true, "'.$autoPath.'") ?'.'>'.$matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -421,6 +421,8 @@ class Validator
|
|||
|
||||
if(preg_match('@(^|/)files/ruleset/\w+\.xml$@i', $this->_xml_path)) $ruleset = '@'.$ruleset;
|
||||
|
||||
list($ruleset) = explode('.', $ruleset);
|
||||
|
||||
// current language
|
||||
$lang_type = class_exists('Context')?Context::getLangType():'en';
|
||||
|
||||
|
|
|
|||
43
classes/xml/XmlGenerator.class.php
Normal file
43
classes/xml/XmlGenerator.class.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
class XmlGenerator{
|
||||
|
||||
function obj2xml($xml){
|
||||
$buff = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
|
||||
|
||||
foreach($xml as $nodeName => $nodeItem){
|
||||
$buff .= $this->_makexml($nodeItem);
|
||||
}
|
||||
return $buff;
|
||||
}
|
||||
|
||||
function _makexml($node){
|
||||
$body = '';
|
||||
foreach($node as $key => $value){
|
||||
switch($key){
|
||||
case 'node_name' : break;
|
||||
case 'attrs' : {
|
||||
$attrs = '';
|
||||
if (isset($value)){
|
||||
foreach($value as $attrName=>$attrValue){
|
||||
$attrs .= sprintf(' %s="%s"', $attrName, htmlspecialchars($attrValue));
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case 'body' : $body = $value; break;
|
||||
default : {
|
||||
if (is_array($value)){
|
||||
foreach($value as $idx => $arrNode){
|
||||
$body .= $this->_makexml($arrNode);
|
||||
}
|
||||
}else if(is_object($value)){
|
||||
$body = $this->_makexml($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sprintf('<%s%s>%s</%s>'."\n", $node->node_name, $attrs, $body, $node->node_name);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -167,6 +167,7 @@
|
|||
require(_XE_PATH_.'classes/extravar/Extravar.class.php');
|
||||
require(_XE_PATH_.'classes/handler/Handler.class.php');
|
||||
require(_XE_PATH_.'classes/xml/XmlParser.class.php');
|
||||
require(_XE_PATH_.'classes/xml/XmlGenerator.class.php');
|
||||
require(_XE_PATH_.'classes/xml/XmlJsFilter.class.php');
|
||||
require(_XE_PATH_.'classes/xml/XmlLangParser.class.php');
|
||||
require(_XE_PATH_.'classes/cache/CacheHandler.class.php');
|
||||
|
|
|
|||
|
|
@ -1509,12 +1509,21 @@
|
|||
* @brief Return ruleset cache file path
|
||||
* @param module, act
|
||||
**/
|
||||
function getValidatorFilePath($module, $ruleset) {
|
||||
function getValidatorFilePath($module, $ruleset, $mid=null) {
|
||||
// load dynamic ruleset xml file
|
||||
if (strpos($ruleset, '@') !== false){
|
||||
$rulsetFile = str_replace('@', '', $ruleset);
|
||||
$xml_file = sprintf('./files/ruleset/%s.xml', $rulsetFile);
|
||||
return FileHandler::getRealPath($xml_file);
|
||||
}else if (strpos($ruleset, '#') !== false){
|
||||
$rulsetFile = str_replace('#', '', $ruleset).'.'.$mid;
|
||||
$xml_file = sprintf('./files/ruleset/%s.xml', $rulsetFile);
|
||||
if (is_readable($xml_file))
|
||||
return FileHandler::getRealPath($xml_file);
|
||||
else{
|
||||
$ruleset = str_replace('#', '', $ruleset);
|
||||
}
|
||||
|
||||
}
|
||||
// Get a path of the requested module. Return if not exists.
|
||||
$class_path = ModuleHandler::getModulePath($module);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue