if (!$result) {
return false;
}
- $row = $result->_result->fetch_array();
+ $row = $result->fetch_array();
return $row[$field];
}
function quote($string) {
- return "'" . parent::escape_string($string) . "'";
+ return "'" . $this->escape_string($string) . "'";
}
-
- // minification compatibility start
- function select_db($database) {
- return parent::select_db($database);
- }
-
- function query($query) {
- // result is packed in envelope object to allow minification
- $result = parent::query($query);
- return (is_object($result) ? new Min_Result($result) : $result);
- }
-
- function multi_query($query) {
- return parent::multi_query($query);
- }
-
- function store_result() {
- $result = parent::store_result();
- return (is_object($result) ? new Min_Result($result) : $result);
- }
-
- function next_result() {
- return parent::next_result();
- }
- }
-
- class Min_Result {
- var $_result, $num_rows;
-
- function __construct($result) {
- $this->_result = $result;
- $this->num_rows = $result->num_rows;
- }
-
- function fetch_assoc() {
- return $this->_result->fetch_assoc();
- }
-
- function fetch_row() {
- return $this->_result->fetch_row();
- }
-
- function fetch_field() {
- return $this->_result->fetch_field();
- }
-
- function free() {
- return $this->_result->free();
- }
- // minification compatibility end
}
} elseif (extension_loaded("mysql")) {
function php_shrink($input) {
$special_variables = array_flip(array('$this', '$GLOBALS', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_SERVER'));
static $short_variables = array();
- static $short_functions = array();
$shortening = true;
- $special_functions = array_flip(array('Min_DB', 'Min_Result', '__construct'));
- $defined_functions = array();
$tokens = token_get_all($input);
foreach ($tokens as $i => $token) {
if ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
$short_variables[$token[1]]++;
- } elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && !isset($special_functions[$token[1]])) {
- $short_functions[$token[1]]++;
- if ($tokens[$i-2][0] === T_FUNCTION) {
- $defined_functions[$token[1]] = true;
- }
}
}
foreach (array_keys($short_variables) as $number => $key) {
$short_variables[$key] = short_identifier($number, implode("", range('a', 'z')) . '_' . implode("", range('A', 'Z'))); // could use also numbers and \x7f-\xff
}
- arsort($short_functions);
- $number = 0;
- foreach ($short_functions as $key => $val) {
- if (isset($defined_functions[$key])) {
- do {
- $short_functions[$key] = short_identifier($number, implode("", range('a', 'z'))); // _ not used to not collide with gettext()
- $number++;
- } while (isset($short_functions[$short_functions[$key]])); // don't overwrite existing functions
- }
- }
$set = array_flip(preg_split('//', '!"#$&\'()*+,-./:;<=>?@[\]^`{|}'));
$space = '';
}
} elseif ($token[0] === T_VARIABLE && !isset($special_variables[$token[1]])) {
$token[1] = '$' . $short_variables[$token[1]];
- } elseif ($token[0] === T_STRING && $tokens[$i+1] === '(' && isset($defined_functions[$token[1]])
- && $tokens[$i-1][0] !== T_DOUBLE_COLON && $tokens[$i-2][0] !== T_NEW && $tokens[$i-2][1] !== '_result' // don't substitute parent methods - used to link PHP methods only
- ) {
- $token[1] = $short_functions[$token[1]];
- } elseif ($token[0] == T_CONSTANT_ENCAPSED_STRING
- && (($tokens[$i-1] === '(' && in_array($tokens[$i-2][1], array('array_map', 'set_exception_handler'), true)) || $token[1] == "'normalize_enum'")
- && isset($defined_functions[substr($token[1], 1, -1)])
- ) { // minify callback functions too
- $token[1] = "'" . $short_functions[substr($token[1], 1, -1)] . "'";
}
if (isset($set[substr($output, -1)]) || isset($set[$token[1]{0}])) {
$space = '';