Exemple #1
0
 static function createMap($descriptor)
 {
     if (!is_array($descriptor)) {
         if (One_Script_Config::$nsLanguagePackage) {
             $lang = One_Script_Package::call(One_Script_Config::$nsLanguagePackage, 'getLanguage', '');
             return array($descriptor . $lang . DIRECTORY_SEPARATOR, $descriptor);
         } else {
             return array($descriptor);
         }
     }
     if (One_Script_Config::$nsLanguagePackage) {
         $lang = One_Script_Package::call(One_Script_Config::$nsLanguagePackage, 'getLanguage', '');
         $descriptor[] = $lang;
     }
     $segments = array();
     $stub = '';
     foreach ($descriptor as $piece) {
         $stub .= $piece . DIRECTORY_SEPARATOR;
         $segments[] = $stub;
     }
     return array_reverse($segments);
 }
Exemple #2
0
 function parseExpression(&$code, &$data)
 {
     //var_dump($data);
     //		echo "<br>parseExpression(" . htmlspecialchars(''.$code.'') . ")";
     $t = One_Script_Tokenizer::tokenize($code);
     $result = "";
     if (!is_array($t)) {
         return "Expression syntax error: {$tokens}";
     }
     $nTokens = count($t);
     for ($tIndex = 0; $tIndex < $nTokens; $tIndex++) {
         $tv = $t[$tIndex];
         if (is_array($tv)) {
             switch ($tv[0]) {
                 case NST_OBJECT:
                     $tIndex++;
                     $tv = $t[$tIndex];
                     $result .= "->" . $tv[1];
                     break;
                 case NST_COLON:
                     $tIndex++;
                     $result .= "::";
                     break;
                 case NST_LITERAL:
                     // PD31OXT08: corrected, do not assume this is a package if not followed by colon: rather assume it is a literal
                     if (One_Script_Package::isPackage($tv[1]) && $t[$tIndex + 1][0] == NST_COLON) {
                         //							echo "<br> --- package " . $tv[1];
                         $thePackage = $tv[1];
                         // anticipate a colon
                         $tIndex++;
                         $tv = $t[$tIndex];
                         // check for a method string
                         $tIndex++;
                         $tv = $t[$tIndex];
                         if (is_array($tv)) {
                             if ($tv[0] == NST_LITERAL) {
                                 $theMethod = $tv[1];
                                 // anticipate an open parentheses
                                 $tIndex++;
                                 $tv = $t[$tIndex];
                                 if ($tv[0] == NST_DELIM and $tv[1] == "(") {
                                     $result .= "One_Script_Package::call('{$thePackage}','{$theMethod}'";
                                     $ntv = $t[$tIndex + 1];
                                     if (!($ntv[0] == NST_DELIM and $ntv[1] == ")")) {
                                         $result .= ',';
                                     }
                                     break;
                                 } else {
                                     $this->error = "Expression syntax error: expected '(' following package method '{$thePackage}:{$theMethod}' when evaluating '" . htmlspecialchars($code) . "'" . " ({$this->location} : {$this->lineNumber})";
                                     return $this->error;
                                 }
                             } else {
                                 $this->error = "Expression syntax error2: expected method name following package prefix '{$thePackage}:' when evaluating '" . htmlspecialchars($code) . "'" . " ({$this->location} : {$this->lineNumber})";
                                 return $this->error;
                             }
                         } else {
                             $this->error = "Expression syntax error: expected method name following package prefix '{$thePackage}:' when evaluating '" . htmlspecialchars($code) . "'" . " ({$this->location} : {$this->lineNumber})";
                             return $this->error;
                         }
                         $result .= $tv[1];
                     } else {
                         if (array_key_exists($tv[1], $data)) {
                             $newVal = $data[$tv[1]];
                             if (is_null($newVal)) {
                                 $newVal = '';
                             }
                             if (is_string($newVal)) {
                                 $result .= "\$data['" . $tv[1] . "']";
                                 //$result .= "'" . addslashes($newVal) . "'";
                                 //echo "<br> --- replacing " . $tv[1] . " by |" . $newVal . "|";
                             } else {
                                 if (is_array($newVal)) {
                                     $result .= "\$data['" . $tv[1] . "']";
                                     //echo "<br> --- replacing " . $tv[1] . " by |" . $newVal . "|";
                                 } else {
                                     if (is_object($newVal)) {
                                         $result .= "\$data['" . $tv[1] . "']";
                                         //echo "<br> --- replacing " . $tv[1] . " by |" . $newVal . "|";
                                     } else {
                                         //$result .= $newVal;
                                         $result .= "\$data['" . $tv[1] . "']";
                                         // keep rvalue
                                         //echo "<br> --- replacing " . $tv[1] . " by |" . $newVal . "|";
                                     }
                                 }
                             }
                         } else {
                             if (function_exists($tv[1])) {
                                 // a function name is used : determine whether this is a call
                                 $ntv = $t[$tIndex + 1];
                                 if ($ntv[0] == NST_DELIM and $ntv[1] == "(") {
                                     if (One_Script_Config::$expressionAllowsFunctions) {
                                         if (!empty(One_Script_Config::$expressionForbidFunctions)) {
                                             if (in_array($tv[1], One_Script_Config::$expressionForbidFunctions)) {
                                                 $this->error = "Expression syntax error: call to function '{$tv[1]}' is forbidden " . " ({$this->location} : {$this->lineNumber})";
                                                 return $this->error;
                                             }
                                         }
                                         if (!empty(One_Script_Config::$expressionRestrictFunctions)) {
                                             if (!in_array($tv[1], One_Script_Config::$expressionRestrictFunctions)) {
                                                 $this->error = "Expression syntax error: call to function '{$tv[1]}' is not allowed " . " ({$this->location} : {$this->lineNumber})";
                                                 return $this->error;
                                             }
                                         }
                                         $result .= $tv[1];
                                         //echo "<br> --- replacing <b>" . $tv[1] . "</b> by function |" . $tv[1] . "|";
                                     } else {
                                         $this->error = "Expression syntax error: call to function '{$tv[1]}' is not allowed " . " ({$this->location} : {$this->lineNumber})";
                                         return $this->error;
                                     }
                                 } else {
                                     $result .= $tv[1];
                                     //echo "<br> --- replacing <b>" . $tv[1] . "</b> by function |" . $tv[1] . "|";
                                 }
                             } else {
                                 if ($tv[1] == 'array') {
                                     $result .= "array";
                                     //$result .= "''";
                                     //echo "<br> --- replacing <b>" . $tv[1] . "</b> by NADA";
                                 } else {
                                     $result .= "\$data['" . $tv[1] . "']";
                                     //$result .= "''";
                                     //echo "<br> --- replacing <b>" . $tv[1] . "</b> by NADA";
                                 }
                             }
                         }
                     }
                     break;
                 default:
                     // any other token
                     $result .= $tv[1];
             }
         } else {
             switch ($tv) {
                 default:
                     $result .= $tv;
             }
             //echo "<br>$tv";
         }
     }
     return $result;
 }