Ejemplo n.º 1
0
 /**
  * Parse the file uses the PHP tokeniser to analyse a php script and pull included/required files inline
  *
  * @param string $filename The full/path/to the file to be processed
  * @return string The compiled script contents
  */
 public function parseFile($filename)
 {
     // Don't try and process the file if the tokenizer isn't available
     if (!function_exists('token_get_all')) {
         return false;
     }
     // Track included files to allow require_once/include_once to work correctly
     $thisFile = OX::realPathRelative(getcwd() . '/' . $filename);
     $this->onlyOnce[$thisFile] = true;
     // Read the file
     $source = file_get_contents($filename);
     // Tokenize the source
     $tokens = token_get_all($source);
     // Start in standard state
     $state = STATE_STD;
     // Track if we are in a STRIP_DELIVERY codeblock
     $strip_delivery = false;
     // Track if we just output a newline
     $was_nl = false;
     // The compiled script goes in here, return value
     $ret = '';
     // If we meet a require/require_once, we store the filename here for recursion
     // (the filename may be build by concatination ...)
     $cur = '';
     // Hold the original content we left off from start of a require/require_once, so
     // if we are currently waiting for the filename to be completed, and realize a
     // dynamic filename (i.e. T_VARIABLE), we can give up on this filename, and
     // output the original, unchanged source
     $orig = '';
     // Iterate over the file tokens (note: grey magic ;)
     foreach ($tokens as $token) {
         if (is_string($token)) {
             // next token is a none special, simple character
             // we can clear newline-flag ...
             $was_nl = false;
             // if we currently strip off none delivery code, ignore
             // this token, start with next
             if ($strip_delivery) {
                 continue;
             }
             // in normal state, just add to our return buffer
             if ($state === STATE_STD) {
                 $ret .= $token;
             } else {
                 // we waiting to complete a require/require_once, so
                 // this is just happen !!!
                 if ($token === ';') {
                     switch ($state) {
                         case STATE_REQUIRE_ONCE:
                             // if we have done this file, don't slurp it again
                             $thisfile = OX::realPathRelative($cur);
                             if (array_key_exists($thisfile, $this->onlyOnce)) {
                                 break;
                             }
                             //fall through
                         //fall through
                         case STATE_REQUIRE:
                             // try to load the file, if ...
                             if (!($content = $this->flattenFile($cur))) {
                                 // we are unable to slurp it, just add the original
                                 // require-statement into our buffer
                                 $ret .= $orig . ";\n";
                             } else {
                                 $ret .= $content;
                             }
                             break;
                     }
                     // require/require_once statement finished, return to normal
                     $state = STATE_STD;
                 } else {
                     // we are currently collecting a require/require_once filename,
                     // so keep the original content
                     $orig .= $token;
                     // and capture the filename if not the concat op.
                     if (strpos('.()', $token) === false) {
                         $cur .= $token;
                     }
                 }
             }
         } else {
             // token array
             list($id, $text) = $token;
             // if we currently strip off none delivery code, we could leave
             // this mode only in a comment ...
             if ($strip_delivery && !$this->isComment($id)) {
                 continue;
             }
             // is last was a newline and we don't like whitespace ...
             if ($was_nl && !$this->echoWhite) {
                 // ... but this is one, cont. on next token
                 if ($id === T_WHITESPACE) {
                     continue;
                 } else {
                     if (!$this->echoComment && $this->isComment($id)) {
                     } else {
                         $was_nl = false;
                     }
                 }
             }
             if ($this->dumpToken) {
                 $ret .= "[{$id}:" . token_name($id) . ":" . $text . "]";
             }
             switch ($id) {
                 case T_COMMENT:
                 case T_ML_COMMENT:
                     // we've defined this
                 // we've defined this
                 case T_DOC_COMMENT:
                     // and this
                     // comments are only added on request
                     // check if we reach or leave a none-delivery-code secition
                     // and set flag ...
                     if ($this->echoComment) {
                         if ($state === STATE_STD) {
                             $ret .= $text;
                         }
                     }
                     if ($strip_delivery) {
                         if (strstr($text, '###END_STRIP_DELIVERY') !== false) {
                             $strip_delivery = false;
                         }
                     } else {
                         if (strstr($text, '###START_STRIP_DELIVERY') !== false) {
                             $strip_delivery = true;
                         }
                     }
                     break;
                 case T_OPEN_TAG:
                     // keep track of begin/end php-code sections, to avoid
                     // have more than one begin or end in our result code
                     if ($this->insidePhp == 0) {
                         $ret .= $text;
                     }
                     $this->insidePhp++;
                     break;
                 case T_CLOSE_TAG:
                     $this->insidePhp--;
                     if ($this->insidePhp == 0) {
                         $ret .= $text;
                     }
                     break;
                 case T_REQUIRE:
                     // require found
                     $state = STATE_REQUIRE;
                     // clear out filename buffer
                     $cur = '';
                     // start collecting the original content
                     $orig = $text;
                     break;
                 case T_REQUIRE_ONCE:
                     // require_once found, see above
                     $state = STATE_REQUIRE_ONCE;
                     $cur = '';
                     $orig = $text;
                     break;
                 case T_CONSTANT_ENCAPSED_STRING:
                     // just a string with quotes
                     if ($state === STATE_STD) {
                         $ret .= $text;
                     } else {
                         // strip off the quotes and add to filename
                         $cur .= substr($text, 1, strlen($text) - 2);
                         $orig .= $text;
                     }
                     break;
                 case T_VARIABLE:
                     if ($state === STATE_STD) {
                         $ret .= $text;
                     } else {
                         // sorry boy, dynamic filename found
                         // append the original code to the output
                         // and return to normal state
                         $ret .= $orig . $text;
                         $state = STATE_STD;
                     }
                     break;
                 case T_STRING:
                     if ($state === STATE_STD) {
                         $ret .= $text;
                     } else {
                         // a require/require_once path may contain our
                         // special MAX_PATH, so add the real value instead
                         if ($text === 'MAX_PATH') {
                             $cur .= MAX_PATH;
                         }
                         if ($text === 'OX_PATH') {
                             $cur .= OX_PATH;
                         }
                         $orig .= $text;
                     }
                     break;
                 case T_WHITESPACE:
                     // one or more spaces, newlines, ...
                     if ($state === STATE_STD) {
                         if ($this->echoWhite) {
                             $ret .= $text;
                         } else {
                             if (strstr($text, "\n") !== false) {
                                 // a newline found, set our flag to avoid
                                 // multiple empty lines
                                 $was_nl = true;
                                 $ret .= "\n";
                             } else {
                                 // reduce incoming spaces to a single one
                                 $ret .= ' ';
                             }
                         }
                     } else {
                         $orig .= $text;
                     }
                     break;
                 default:
                     if ($state === STATE_STD) {
                         $ret .= $text;
                     } else {
                         $cur .= $text;
                         $orig .= $text;
                     }
                     break;
             }
         }
     }
     return $ret;
 }
Ejemplo n.º 2
0
        $_POST['table_edit'] = '';
    } else {
        if (array_key_exists('schemaFile', $_COOKIE) && !empty($_COOKIE['schemaFile'])) {
            $schemaPath = $_COOKIE['schemaPath'];
            $schemaFile = $_COOKIE['schemaFile'];
        }
    }
}
if (empty($schemaPath) || empty($schemaFile)) {
    $schemaPath = '';
    //OX_CORE;
    $schemaFile = 'tables_core.xml';
}
// ensure correct directory format. $schemaPath requires trailing '/'. Using trailing DIRECTORY_SEPARATOR fails on Windows for reasons unknown
if (isset($schemaPath) && $schemaPath != '') {
    $schemaPath = OX::realPathRelative(urldecode($schemaPath));
    $schemaPath .= '/';
}
setcookie('schemaPath', $schemaPath);
setcookie('schemaFile', $schemaFile);
global $oaSchema;
$oaSchema = new Openads_Schema_Manager($schemaFile, '', $schemaPath);
if (is_array($aErrs = OX_DevToolbox::checkFilePermissions(array(PATH_DEV, PATH_VAR, MAX_PATH . $pluginPath)))) {
    setcookie('schemaFile', '');
    setcookie('schemaPath', '');
    $errorMessage = join("<br />\n", $aErrs['errors']) . "<br /><br ><hr /><br />\n" . 'To fix, please execute the following commands:' . "<br /><br >\n" . join("<br />\n", $aErrs['fixes']);
    die($errorMessage);
}
require_once PATH_DEV . '/lib/xajax.inc.php';
if (array_key_exists('btn_copy_final', $_POST)) {
    $oaSchema->createTransitional();