1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_ROOT_PATH . "/modules/legacy/lib/EasyLex/EasyLex_SQLScanner.class.php";
14:
15: class Legacy_SQLScanner extends EasyLex_SQLScanner
16: {
17: var $mDB_PREFIX = "";
18: var $mDirname = "";
19:
20: function setDB_PREFIX($prefix)
21: {
22: $this->mDB_PREFIX = $prefix;
23: }
24:
25: function setDirname($dirname)
26: {
27: $this->mDirname = $dirname;
28: }
29:
30: function &getOperations()
31: {
32: $t_lines = array();
33: $t_tokens = array();
34: $depth = 0;
35:
36: foreach (array_keys($this->mTokens) as $key) {
37: if ($this->mTokens[$key]->mType == EASYLEX_SQL_OPEN_PARENTHESIS) {
38: $depth++;
39: }
40: elseif ($this->mTokens[$key]->mType == EASYLEX_SQL_CLOSE_PARENTHESIS) {
41: $depth--;
42: }
43:
44: $t_tokens[] =& $this->mTokens[$key];
45:
46: if (count($t_tokens) > 1 && $depth == 0) {
47: if ($this->mTokens[$key]->mType == EASYLEX_SQL_SEMICOLON) {
48: $t_lines[] =& $t_tokens;
49: unset($t_tokens);
50: $t_tokens = array();
51: }
52: elseif ($this->mTokens[$key]->mType == EASYLEX_SQL_LETTER && (strtoupper($this->mTokens[$key]->mValue) =='CREATE' || strtoupper($this->mTokens[$key]->mValue) =='ALTER' || strtoupper($this->mTokens[$key]->mValue) =='INSERT')) {
53: array_pop($t_tokens);
54: $t_lines[] =& $t_tokens;
55: unset($t_tokens);
56: $t_tokens = array();
57: $t_tokens[] =& $this->mTokens[$key];
58: }
59: }
60: }
61:
62: if (count($t_tokens) > 0) {
63: $t_lines[] =& $t_tokens;
64: unset($t_tokens);
65: }
66:
67:
68:
69:
70: $t_search = array('{prefix}', '{dirname}', '{Dirname}', '{_dirname_}');
71: $t_replace = array($this->mDB_PREFIX, strtolower($this->mDirname), ucfirst(strtolower($this->mDirname)), $this->mDirname);
72:
73: foreach (array_keys($t_lines) as $idx) {
74: foreach (array_keys($t_lines[$idx]) as $op_idx) {
75: $t_lines[$idx][$op_idx]->mValue = str_replace($t_search, $t_replace, $t_lines[$idx][$op_idx]->mValue);
76: }
77: }
78:
79: return $t_lines;
80: }
81: }
82:
83: ?>
84: