예제 #1
0
 function _php($file, $data)
 {
     //echo 'Reading ' . $file . '<br />';
     if (!function_exists('token_get_all')) {
         $this->error = 'Tokenizer PHP extension is not available.';
         return false;
     }
     $tokens = Tokenizer::normalize(token_get_all($data));
     // compile array from first ( to next ) after $intl
     // or $GLOBALS['intl']
     $add = array();
     $glob = false;
     $i = false;
     $a = false;
     $s = false;
     foreach ($tokens as $tok) {
         //echo token_name ($tok[0]) . ': ' . $tok[1] . BR;
         if ($tok[0] == T_VARIABLE && $tok[1] == '$intl') {
             // found intl
             //		echo 'Found one ' . $tok[1] . '<br />';
             $i = true;
         } elseif ($tok[0] == T_STRING && $tok[1] == 'intl_get') {
             // found intl_get
             $i = true;
         } elseif ($tok[0] == T_STRING && $tok[1] == 'template_simple') {
             // we found a template_simple function!
             $s = true;
         } elseif ($tok[0] == T_VARIABLE && $tok[1] == '$GLOBALS') {
             // found global
             //		echo 'Found one ' . $tok[1] . '<br />';
             $glob = true;
             continue;
             //	} elseif ($glob && $tok[0] == 0 && $tok[1] == '[') {
             //		$add[] = array ();
         } elseif ($globa && $tok[0] == 0 && $tok[1] == ']') {
             $glob = false;
         } elseif ($glob && $tok[0] == T_CONSTANT_ENCAPSED_STRING && $tok[1] == '\'intl\'') {
             $i = true;
             $glob = false;
         } elseif ($i && $tok[0] == 0 && $tok[1] == '(') {
             $add[] = array('');
             $a = true;
         } elseif ($i && $tok[0] == 0 && ($tok[1] == ')' || $tok[1] == ';')) {
             $i = false;
             $a = false;
         } elseif ($i && $a && $tok[1] == ',') {
             $add[count($add) - 1][] = '';
         } elseif ($i && $a && $tok[0] != T_WHITESPACE) {
             $add[count($add) - 1][count($add[count($add) - 1]) - 1] .= $tok[1];
             // parse the content of template_simple function
             // like if it was a .spt file.
         } elseif ($s && $tok[0] == 0 && $tok[1] == '(') {
             $str = '';
         } else {
             if ($s && $tok[0] == 0 && ($tok[1] == ')' || $tok[1] == ';')) {
                 $s = false;
                 $this->_spt($file, $str);
             } elseif ($s && $tok[0] != T_WHITESPACE) {
                 $str .= $tok[1];
             }
         }
     }
     foreach ($add as $item) {
         $string = array_shift($item);
         if (strpos($string, "'") === 0) {
             $string = ltrim(rtrim($string, "'"), "'");
         } elseif (strpos($string, '"') === 0) {
             $string = ltrim(rtrim($string, '"'), '"');
         } else {
             continue;
         }
         //	if (strstr ($string, "\\'") || strstr ($string, '\\"')) {
         //		$string = stripslashes ($string);
         //	}
         if (count($item) > 0) {
             $params = $item;
         } else {
             $params = false;
         }
         $string = stripslashes($string);
         $this->buffer->set($this->intl->serialize($string), array('string' => $string, 'params' => $params, 'file' => $file, 'line' => false));
     }
     return true;
 }