|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
-
- <?php
-
- chdir(dirname(__FILE__));
- require_once 'common.php';
- require_once '../library/HTMLPurifier.auto.php';
- assertCli();
-
- if (version_compare(PHP_VERSION, '5.2.2', '<')) {
- echo "This script requires PHP 5.2.2 or later, for tokenizer line numbers.";
- exit(1);
- }
-
-
-
- $FS = new FSTools();
- chdir(dirname(__FILE__) . '/../library/');
- $raw_files = $FS->globr('.', '*.php');
- $files = array();
- foreach ($raw_files as $file) {
- $file = substr($file, 2);
- if (strncmp('standalone/', $file, 11) === 0) continue;
- if (substr_count($file, '.') > 1) continue;
- $files[] = $file;
- }
-
-
- function consumeWhitespace($tokens, &$i)
- {
- do {$i++;} while (is_array($tokens[$i]) && $tokens[$i][0] === T_WHITESPACE);
- }
-
-
- function testToken($token, $value_or_token, $value = null)
- {
- if (is_null($value)) {
- if (is_int($value_or_token)) return is_array($token) && $token[0] === $value_or_token;
- else return $token === $value_or_token;
- } else {
- return is_array($token) && $token[0] === $value_or_token && $token[1] === $value;
- }
- }
-
- $counter = 0;
- $full_counter = 0;
- $tracker = array();
-
- foreach ($files as $file) {
- $tokens = token_get_all(file_get_contents($file));
- $file = str_replace('\\', '/', $file);
- for ($i = 0, $c = count($tokens); $i < $c; $i++) {
- $ok = false;
-
- if (!$ok && testToken($tokens[$i], T_VARIABLE, '$config')) $ok = true;
-
- while (!$ok && testToken($tokens[$i], T_VARIABLE, '$this')) {
- consumeWhitespace($tokens, $i);
- if (!testToken($tokens[$i], T_OBJECT_OPERATOR)) break;
- consumeWhitespace($tokens, $i);
- if (testToken($tokens[$i], T_STRING, 'config')) $ok = true;
- break;
- }
- if (!$ok) continue;
-
- $ok = false;
- for($i++; $i < $c; $i++) {
- if ($tokens[$i] === ',' || $tokens[$i] === ')' || $tokens[$i] === ';') {
- break;
- }
- if (is_string($tokens[$i])) continue;
- if ($tokens[$i][0] === T_OBJECT_OPERATOR) {
- $ok = true;
- break;
- }
- }
- if (!$ok) continue;
-
- $line = $tokens[$i][2];
-
- consumeWhitespace($tokens, $i);
- if (!testToken($tokens[$i], T_STRING, 'get')) continue;
-
- consumeWhitespace($tokens, $i);
- if (!testToken($tokens[$i], '(')) continue;
-
- $full_counter++;
-
- $matched = false;
- do {
-
-
-
-
-
-
- consumeWhitespace($tokens, $i);
- if (!testToken($tokens[$i], T_CONSTANT_ENCAPSED_STRING)) continue;
- $id = substr($tokens[$i][1], 1, -1);
-
- $counter++;
- $matched = true;
-
- if (!isset($tracker[$id])) $tracker[$id] = array();
- if (!isset($tracker[$id][$file])) $tracker[$id][$file] = array();
- $tracker[$id][$file][] = $line;
-
- } while (0);
-
-
- }
- }
-
- echo "\n$counter/$full_counter instances of \$config or \$this->config found in source code.\n";
-
- echo "Generating XML... ";
-
- $xw = new XMLWriter();
- $xw->openURI('../configdoc/usage.xml');
- $xw->setIndent(true);
- $xw->startDocument('1.0', 'UTF-8');
- $xw->startElement('usage');
- foreach ($tracker as $id => $files) {
- $xw->startElement('directive');
- $xw->writeAttribute('id', $id);
- foreach ($files as $file => $lines) {
- $xw->startElement('file');
- $xw->writeAttribute('name', $file);
- foreach ($lines as $line) {
- $xw->writeElement('line', $line);
- }
- $xw->endElement();
- }
- $xw->endElement();
- }
- $xw->endElement();
- $xw->flush();
-
- echo "done!\n";
-
-
|