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