merge from 1.5.2

git-svn-id: http://xe-core.googlecode.com/svn/trunk@10446 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
devjin 2012-03-20 08:03:02 +00:00
parent 6c23751ef8
commit c727926d9e
382 changed files with 6855 additions and 3603 deletions

View file

@ -88,8 +88,7 @@ class CacheMemcache extends CacheBase {
}
function truncate() {
// not supported on memcached
return false;
return $this->Memcache->flush();
}
}

View file

@ -98,6 +98,7 @@ class Context {
$this->db_info->lang_type = $site_module_info->default_language;
if(!$this->db_info->lang_type) $this->db_info->lang_type = 'en';
if(!$this->db_info->use_db_session) $this->db_info->use_db_session = 'N';
}
// Load Language File
@ -127,7 +128,7 @@ class Context {
$this->loadLang(_XE_PATH_.'modules/module/lang');
// set session handler
if(Context::isInstalled() && $this->db_info->use_db_session != 'N') {
if(Context::isInstalled() && $this->db_info->use_db_session == 'Y') {
$oSessionModel = &getModel('session');
$oSessionController = &getController('session');
session_set_save_handler(
@ -245,6 +246,7 @@ class Context {
if($db_info->qmail_compatibility != 'Y') $db_info->qmail_compatibility = 'N';
$GLOBALS['_qmail_compatibility'] = $db_info->qmail_compatibility;
if(!$db_info->use_db_session) $db_info->use_db_session = 'N';
if(!$db_info->use_ssl) $db_info->use_ssl = 'none';
$this->set('_use_ssl', $db_info->use_ssl);
@ -779,9 +781,13 @@ class Context {
static $url = null;
if(is_null($url)) {
$url = Context::getRequestUri();
if(count($_GET)) {
foreach($_GET as $key => $val) $vars[] = $key.'='.urlencode(Context::convertEncodingStr($val));
$url .= '?'.implode('&',$vars);
if(count($_GET))
{
foreach($_GET as $key => $val)
{
$vars[] = $key . '=' . ($val ? urlencode(Context::convertEncodingStr($val)) : '');
}
$url .= '?' . join('&', $vars);
}
}
return $url;
@ -1018,6 +1024,11 @@ class Context {
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
$self->context->{$key} = $val;
if($set_to_get_vars === false) return;
if($val === NULL || $val === '')
{
unset($self->get_vars->{$key});
return;
}
if($set_to_get_vars || $self->get_vars->{$key}) $self->get_vars->{$key} = $val;
}
@ -1451,4 +1462,3 @@ class Context {
$map[$key] = $content;
}
}
?>

View file

@ -179,7 +179,8 @@
**/
function _fetch($result, $arrayIndexEndValue = NULL)
{
if (!$this->isConnected() || $this->isError() || !$result) return;
$output = array();
if (!$this->isConnected() || $this->isError() || !$result) return array();
// TODO Improve this piece of code
// This code trims values from char type columns
@ -654,8 +655,18 @@
$total_page = 1;
}
// check the page variables
if ($page > $total_page) $page = $total_page;
// check the page variables
if ($page > $total_page) {
// If requested page is bigger than total number of pages, return empty list
$buff = new Object ();
$buff->total_count = $total_count;
$buff->total_page = $total_page;
$buff->page = $page;
$buff->data = array();
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
return $buff;
}
$start_count = ($page - 1) * $list_count;
$query = $this->getSelectPageSql($queryObject, true, $start_count, $list_count);

View file

@ -753,13 +753,24 @@
if ($total_count) $total_page = (int) (($total_count - 1) / $list_count) + 1;
else $total_page = 1;
if($page > $total_page) $page = $total_page;
// check the page variables
if ($page > $total_page) {
// If requested page is bigger than total number of pages, return empty list
$buff = new Object ();
$buff->total_count = $total_count;
$buff->total_page = $total_page;
$buff->page = $page;
$buff->data = array();
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
return $buff;
}
$start_count = ($page-1)*$list_count;
$query = $this->getSelectSql($queryObject, true, $start_count);
if(strpos($query, "substr")) {
$query = str_replace ("substr", "substring", $query);
$query = $this->replaceSubstrFormat($query);
if(strpos($query, "substr")) {
$query = str_replace ("substr", "substring", $query);
$query = $this->replaceSubstrFormat($query);
}
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
$result = $this->_query ($query, null, $connection);

View file

@ -170,11 +170,11 @@
* @brief Fetch results
**/
function _fetch($result, $arrayIndexEndValue = NULL) {
if(!$this->isConnected() || $this->isError() || !$result) return;
$output = array();
if(!$this->isConnected() || $this->isError() || !$result) return $output;
$c = sqlsrv_num_fields($result);
$m = null;
$output = array();
while(sqlsrv_fetch($result)){
if(!$m) $m = sqlsrv_field_metadata($result);
@ -514,14 +514,24 @@
$total_page = (int) (($total_count - 1) / $list_count) + 1;
} else $total_page = 1;
// check the page variables
if ($page > $total_page) $page = $total_page;
$start_count = ($page - 1) * $list_count;
// check the page variables
if ($page > $total_page) {
// If requested page is bigger than total number of pages, return empty list
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
$result = $this->_query ($query, $connection);
if ($this->isError ())
return $this->queryError($queryObject);
$buff = new Object ();
$buff->total_count = $total_count;
$buff->total_page = $total_page;
$buff->page = $page;
$buff->data = array();
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
return $buff;
}
$start_count = ($page - 1) * $list_count;
$query .= (__DEBUG_QUERY__&1 && $queryObject->query_id)?sprintf (' '.$this->comment_syntax, $this->query_id):'';
$result = $this->_query ($query, $connection);
if ($this->isError ())
return $this->queryError($queryObject);
$virtual_no = $total_count - ($page - 1) * $list_count;
$data = $this->_fetch($result, $virtual_no);

View file

@ -147,7 +147,8 @@
* @brief Fetch results
**/
function _fetch($result, $arrayIndexEndValue = NULL) {
if(!$this->isConnected() || $this->isError() || !$result) return;
$output = array();
if(!$this->isConnected() || $this->isError() || !$result) return $output;
while($tmp = $this->db_fetch_object($result)) {
if($arrayIndexEndValue) $output[$arrayIndexEndValue--] = $tmp;
else $output[] = $tmp;
@ -467,7 +468,16 @@
// Total count
$temp_where = $queryObject->getWhereString(true, false);
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($temp_where === '' ? '' : ' WHERE '. $temp_where));
if ($queryObject->getGroupByString() != '') {
// Check for distinct query and if found update count query structure
$temp_select = $queryObject->getSelectString();
if(strpos(strtolower($temp_select), "distinct") !== false) {
$count_query = sprintf('select %s %s %s', 'FROM ' . $queryObject->getFromString(), $temp_select, ($temp_where === '' ? '' : ' WHERE '. $temp_where));
$uses_distinct = true;
}
// If query uses grouping or distinct, count from original select
if ($queryObject->getGroupByString() != '' || $uses_distinct) {
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
}
@ -490,7 +500,16 @@
$total_page = 1;
// check the page variables
if ($page > $total_page) $page = $total_page;
if ($page > $total_page) {
// If requested page is bigger than total number of pages, return empty list
$buff = new Object ();
$buff->total_count = $total_count;
$buff->total_page = $total_page;
$buff->page = $page;
$buff->data = array();
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
return $buff;
}
$start_count = ($page - 1) * $list_count;
$query = $this->getSelectPageSql($queryObject, true, $start_count, $list_count);

View file

@ -1,718 +0,0 @@
<?php
/**
* @class DBSqlite2
* @author NHN (developers@xpressengine.com)
* @brief Class for using SQLite ver 2.x
* @version 0.1
*
* sqlite handling class (sqlite ver 2.x)
**/
class DBSqlite2 extends DB {
/**
* DB information
**/
var $database = NULL; ///< database
var $prefix = 'xe'; // / <prefix of a tablename (One or more XEs can be installed in a single DB)
var $comment_syntax = '/* %s */';
/**
* @brief sqlite column type used in
*
* Becasue a common column type in schema/query xml is used for colum_type,
* it should be replaced properly for each DBMS
**/
var $column_type = array(
'bignumber' => 'INTEGER',
'number' => 'INTEGER',
'varchar' => 'VARCHAR',
'char' => 'CHAR',
'text' => 'TEXT',
'bigtext' => 'TEXT',
'date' => 'VARCHAR(14)',
'float' => 'FLOAT',
);
/**
* @brief constructor
**/
function DBSqlite2() {
$this->_setDBInfo();
$this->_connect();
}
/**
* @brief create an instance of this class
*/
function create()
{
return new DBSqlite2;
}
/**
* @brief Return if it is installable
**/
function isSupported() {
if(!function_exists('sqlite_open')) return false;
return true;
}
/**
* @brief DB settings and connect/close
**/
function _setDBInfo() {
$db_info = Context::getDBInfo();
$this->database = $db_info->db_database;
$this->prefix = $db_info->db_table_prefix;
if(!substr($this->prefix,-1)!='_') $this->prefix .= '_';
}
/**
* @brief DB Connection
**/
function _connect() {
// Ignore if no DB information exists
if(!$this->database) return;
// Attempt to access the database file
$this->fd = sqlite_open($this->database, 0666, $error);
if(!file_exists($this->database) || $error) {
$this->setError(-1,$error);
$this->is_connected = false;
return;
}
// Check connections
$this->is_connected = true;
$this->password = md5($this->password);
}
/**
* @brief DB disconnection
**/
function close() {
if(!$this->isConnected()) return;
sqlite_close($this->fd);
}
/**
* @brief Begin transaction
**/
function begin() {
if(!$this->is_connected || $this->transaction_started) return;
if($this->_query("BEGIN;")) $this->transaction_started = true;
}
/**
* @brief Rollback
**/
function rollback() {
if(!$this->is_connected || !$this->transaction_started) return;
$this->_query("ROLLBACK;");
$this->transaction_started = false;
}
/**
* @brief Commits
**/
function commit($force = false) {
if(!$force && (!$this->isConnected() || !$this->transaction_started)) return;
if(!$this->is_connected || !$this->transaction_started) return;
$this->_query("COMMIT;");
$this->transaction_started = false;
}
/**
* @brief Add quotes on the string variables in a query
**/
function addQuotes($string) {
if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string));
if(!is_numeric($string)) $string = str_replace("'","''", $string);
return $string;
}
/**
* @brief : Run a query and fetch the result
*
* query: run a query and return the result \n
* fetch: NULL if no value is returned \n
* array object if rows are returned \n
* object if a row is returned \n
* return\n
**/
function _query($query) {
if(!$this->isConnected()) return;
// Notify to start a query execution
$this->actStart($query);
// Run the query statement
$result = @sqlite_query($query, $this->fd);
// Error Check
if(sqlite_last_error($this->fd)) $this->setError(sqlite_last_error($this->fd), sqlite_error_string(sqlite_last_error($this->fd)));
// Notify to complete a query execution
$this->actFinish();
return $result;
}
/**
* @brief Fetch results
**/
function _fetch($result) {
if($this->isError() || !$result) return;
while($tmp = sqlite_fetch_array($result, SQLITE_ASSOC)) {
unset($obj);
foreach($tmp as $key => $val) {
$pos = strpos($key, '.');
if($pos) $key = substr($key, $pos+1);
$obj->{$key} = $val;
}
$output[] = $obj;
}
if(count($output)==1) return $output[0];
return $output;
}
/**
* @brief Return the sequence value is incremented by 1
**/
function getNextSequence() {
$query = sprintf("insert into %ssequence (seq) values ('')", $this->prefix);
$this->_query($query);
$sequence = sqlite_last_insert_rowid($this->fd);
if($sequence % 10000 == 0) {
$query = sprintf("delete from %ssequence where seq < %d", $this->prefix, $sequence);
$this->_query($query);
}
return $sequence;
}
/**
* @brief Return if a table already exists
**/
function isTableExists($target_name) {
$query = sprintf('pragma table_info(%s%s)', $this->prefix, $this->addQuotes($target_name));
$result = $this->_query($query);
if(sqlite_num_rows($result)==0) return false;
return true;
}
/**
* @brief Add a column to a table
**/
function addColumn($table_name, $column_name, $type='number', $size='', $default = '', $notnull=false) {
$type = $this->column_type[$type];
if(strtoupper($type)=='INTEGER') $size = '';
$query = sprintf("alter table %s%s add %s ", $this->prefix, $table_name, $column_name);
if($size) $query .= sprintf(" %s(%s) ", $type, $size);
else $query .= sprintf(" %s ", $type);
if($default) $query .= sprintf(" default '%s' ", $default);
if($notnull) $query .= " not null ";
return $this->_query($query);
}
/**
* @brief Delete a column from a table
**/
function dropColumn($table_name, $column_name) {
$query = sprintf("alter table %s%s drop column %s ", $this->prefix, $table_name, $column_name);
$this->_query($query);
}
/**
* @brief Return column information of a table
**/
function isColumnExists($table_name, $column_name) {
$query = sprintf("pragma table_info(%s%s)", $this->prefix, $table_name);
$result = $this->_query($query);
$output = $this->_fetch($result);
if($output) {
$column_name = strtolower($column_name);
foreach($output as $key => $val) {
$name = strtolower($val->name);
if($column_name == $name) return true;
}
}
return false;
}
/**
* @brief Add an index to a table
* $target_columns = array(col1, col2)
* $is_unique? unique : none
**/
function addIndex($table_name, $index_name, $target_columns, $is_unique = false) {
if(!is_array($target_columns)) $target_columns = array($target_columns);
$key_name = sprintf('%s%s_%s', $this->prefix, $table_name, $index_name);
$query = sprintf("pragma table_info(%s%s)", $this->prefix, $table_name);
$query = sprintf('CREATE %s INDEX %s ON %s%s (%s)', $is_unique?'UNIQUE':'', $key_name, $this->prefix, $table_name, implode(',',$target_columns));
return $this->_query($query);
}
/**
* @brief Drop an index from a table
**/
function dropIndex($table_name, $index_name, $is_unique = false) {
$key_name = sprintf('%s%s_%s', $this->prefix, $table_name, $index_name);
$query = sprintf("DROP INDEX %s", $this->prefix, $table_name, $key_name);
$this->_query($query);
}
/**
* @brief Return index information of a table
**/
function isIndexExists($table_name, $index_name) {
$key_name = sprintf('%s%s_%s', $this->prefix, $table_name, $index_name);
$query = sprintf("pragma index_info(%s)", $key_name);
$result = $this->_query($query);
$output = $this->_fetch($result);
if(!$output) return false;
return true;
}
/**
* @brief Create a table by using xml file
**/
function createTableByXml($xml_doc) {
return $this->_createTable($xml_doc);
}
/**
* @brief Create a table by using xml file
**/
function createTableByXmlFile($file_name) {
if(!file_exists($file_name)) return;
// read xml file
$buff = FileHandler::readFile($file_name);
return $this->_createTable($buff);
}
/**
* @brief generate a query statement to create a table by using schema xml
*
* type : number, varchar, text, char, date, \n
* opt : notnull, default, size\n
* index : primary key, index, unique\n
**/
function _createTable($xml_doc) {
// xml parsing
$oXml = new XmlParser();
$xml_obj = $oXml->parse($xml_doc);
// Create a table schema
$table_name = $xml_obj->table->attrs->name;
if($this->isTableExists($table_name)) return;
$table_name = $this->prefix.$table_name;
if(!is_array($xml_obj->table->column)) $columns[] = $xml_obj->table->column;
else $columns = $xml_obj->table->column;
foreach($columns as $column) {
$name = $column->attrs->name;
$type = $column->attrs->type;
if(strtoupper($this->column_type[$type])=='INTEGER') $size = '';
else $size = $column->attrs->size;
$notnull = $column->attrs->notnull;
$primary_key = $column->attrs->primary_key;
$index = $column->attrs->index;
$unique = $column->attrs->unique;
$default = $column->attrs->default;
$auto_increment = $column->attrs->auto_increment;
if($auto_increment) {
$column_schema[] = sprintf('%s %s %s',
$name,
$this->column_type[$type],
$auto_increment?'AUTOINCREMENT':''
);
} else {
$column_schema[] = sprintf('%s %s%s %s %s %s %s',
$name,
$this->column_type[$type],
$size?'('.$size.')':'',
$notnull?'NOT NULL':'',
$primary_key?'PRIMARY KEY':'',
isset($default)?"DEFAULT '".$default."'":'',
$auto_increment?'AUTOINCREMENT':''
);
}
if($unique) $unique_list[$unique][] = $name;
else if($index) $index_list[$index][] = $name;
}
$schema = sprintf('CREATE TABLE %s (%s%s) ;', $this->addQuotes($table_name)," ", implode($column_schema,", "));
$this->_query($schema);
if(count($unique_list)) {
foreach($unique_list as $key => $val) {
$query = sprintf('CREATE UNIQUE INDEX %s_%s ON %s (%s)', $this->addQuotes($table_name), $key, $this->addQuotes($table_name), implode(',',$val));
$this->_query($query);
}
}
if(count($index_list)) {
foreach($index_list as $key => $val) {
$query = sprintf('CREATE INDEX %s_%s ON %s (%s)', $this->addQuotes($table_name), $key, $this->addQuotes($table_name), implode(',',$val));
$this->_query($query);
}
}
}
/**
* @brief Return conditional clause
**/
function getCondition($output) {
if(!$output->conditions) return;
$condition = $this->_getCondition($output->conditions,$output->column_type);
if($condition) $condition = ' where '.$condition;
return $condition;
}
function getLeftCondition($conditions,$column_type){
return $this->_getCondition($conditions,$column_type);
}
function _getCondition($conditions,$column_type) {
$condition = '';
foreach($conditions as $val) {
$sub_condition = '';
foreach($val['condition'] as $v) {
if(!isset($v['value'])) continue;
if($v['value'] === '') continue;
if(!in_array(gettype($v['value']), array('string', 'integer', 'double'))) continue;
$name = $v['column'];
$operation = $v['operation'];
$value = $v['value'];
$type = $this->getColumnType($column_type,$name);
$pipe = $v['pipe'];
$value = $this->getConditionValue($name, $value, $operation, $type, $column_type);
if(!$value) $value = $v['value'];
$str = $this->getConditionPart($name, $value, $operation);
if($sub_condition) $sub_condition .= ' '.$pipe.' ';
$sub_condition .= $str;
}
if($sub_condition) {
if($condition && $val['pipe']) $condition .= ' '.$val['pipe'].' ';
$condition .= '('.$sub_condition.')';
}
}
return $condition;
}
/**
* @brief Handle the insertAct
**/
function _executeInsertAct($output) {
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = $this->prefix.$val;
}
// List columns
foreach($output->columns as $key => $val) {
$name = $val['name'];
$value = $val['value'];
if($output->column_type[$name]!='number') {
$value = "'".$this->addQuotes($value)."'";
if(!$value) $value = 'null';
}
// sql injection 문제로 xml 선언이 number인 경우이면서 넘어온 값이 숫자형이 아니면 숫자형으로 강제 형변환
// elseif(!$value || is_numeric($value)) $value = (int)$value;
else $this->_filterNumber(&$value);
$column_list[] = $name;
$value_list[] = $value;
}
$query = sprintf("insert into %s (%s) values (%s);", implode(',',$table_list), implode(',',$column_list), implode(',', $value_list));
return $this->_query($query);
}
/**
* @brief Handle updateAct
**/
function _executeUpdateAct($output) {
$table_count = count(array_values($output->tables));
// If one day the destination table
if($table_count == 1) {
// List tables
list($target_table) = array_values($output->tables);
$target_table = $this->prefix.$target_table;
// List columns
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
$name = $val['name'];
$value = $val['value'];
if(strpos($name,'.')!==false&&strpos($value,'.')!==false) $column_list[] = $name.' = '.$value;
else {
if($output->column_type[$name]!='number') $value = "'".$this->addQuotes($value)."'";
// sql injection 문제로 xml 선언이 number인 경우이면서 넘어온 값이 숫자형이 아니면 숫자형으로 강제 형변환
else $this->_filterNumber(&$value);
$column_list[] = sprintf("%s = %s", $name, $value);
}
}
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("update %s set %s %s", $target_table, implode(',',$column_list), $condition);
// trick to handle if targt table to update is more than one (sqlite doesn't support update to multi-tables)
} elseif($table_count == 2) {
// List tables
foreach($output->tables as $key => $val) {
$table_list[$val] = $this->prefix.$key;
}
list($source_table, $target_table) = array_values($table_list);
// List the conditional clause
$condition = $this->getCondition($output);
foreach($table_list as $key => $val) {
$condition = eregi_replace($key.'\\.', $val.'.', $condition);
}
// List columns
foreach($output->columns as $key => $val) {
if(!isset($val['value'])) continue;
$name = $val['name'];
$value = $val['value'];
list($s_prefix, $s_column) = explode('.',$name);
list($t_prefix, $t_column) = explode('.',$value);
$s_table = $table_list[$s_prefix];
$t_table = $table_list[$t_prefix];
$column_list[] = sprintf(' %s = (select %s from %s %s) ', $s_column, $t_column, $t_table, $condition);
}
$query = sprintf('update %s set %s where exists(select * from %s %s)', $source_table, implode(',', $column_list), $target_table, $condition);
} else {
return;
}
return $this->_query($query);
}
/**
* @brief Handle deleteAct
**/
function _executeDeleteAct($output) {
// List tables
foreach($output->tables as $key => $val) {
$table_list[] = $this->prefix.$val;
}
// List the conditional clause
$condition = $this->getCondition($output);
$query = sprintf("delete from %s %s", implode(',',$table_list), $condition);
return $this->_query($query);
}
/**
* @brief Handle selectAct
*
* In order to get a list of pages easily when selecting \n
* it supports a method as navigation
**/
function _executeSelectAct($output) {
// List tables
$table_list = array();
foreach($output->tables as $key => $val) {
$table_list[] = $this->prefix.$val.' as '.$key;
}
$left_join = array();
// why???
$left_tables= (array)$output->left_tables;
foreach($left_tables as $key => $val) {
$condition = $this->_getCondition($output->left_conditions[$key],$output->column_type);
if($condition){
$left_join[] = $val . ' '.$this->prefix.$output->_tables[$key].' as '.$key . ' on ' . $condition . '';
}
}
if(!$output->columns) {
$columns = '*';
} else {
$column_list = array();
foreach($output->columns as $key => $val) {
$name = $val['name'];
$alias = $val['alias'];
if($val['click_count']) $click_count[] = $val['name'];
if(substr($name,-1) == '*') {
$column_list[] = $name;
} elseif(strpos($name,'.')===false && strpos($name,'(')===false) {
if($alias) $column_list[] = sprintf('%s as %s', $name, $alias);
else $column_list[] = sprintf('%s',$name);
} else {
if($alias) $column_list[] = sprintf('%s as %s', $name, $alias);
else $column_list[] = sprintf('%s',$name);
}
}
$columns = implode(',',$column_list);
}
$condition = $this->getCondition($output);
$output->column_list = $column_list;
if($output->list_count && $output->page) return $this->_getNavigationData($table_list, $columns, $left_join, $condition, $output);
// Add a condition to use an index when sorting in order by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
foreach($output->order as $key => $val) {
$col = $val[0];
if(!in_array($col, array('list_order','update_order'))) continue;
if($condition) $condition .= sprintf(' and %s < 2100000000 ', $col);
else $condition = sprintf(' where %s < 2100000000 ', $col);
}
}
}
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list),implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
if($output->order) {
foreach($output->order as $key => $val) {
$index_list[] = sprintf('%s %s', $val[0], $val[1]);
}
if(count($index_list)) $query .= ' order by '.implode(',',$index_list);
}
// Apply when using list_count
if($output->list_count['value']) $query = sprintf('%s limit %d', $query, $output->list_count['value']);
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
$result = $this->_query($query);
if($this->isError()) return;
if(count($click_count)>0 && count($output->conditions)>0){
$_query = '';
foreach($click_count as $k => $c) $_query .= sprintf(',%s=%s+1 ',$c,$c);
$_query = sprintf('update %s set %s %s',implode(',',$table_list), substr($_query,1), $condition);
$this->_query($_query);
}
$data = $this->_fetch($result);
$buff = new Object();
$buff->data = $data;
return $buff;
}
/**
* @brief Paging is handled if navigation information exists in the query xml
*
* It is quite convenient although its structure is not good at all .. -_-;
**/
function _getNavigationData($table_list, $columns, $left_join, $condition, $output) {
require_once(_XE_PATH_.'classes/page/PageHandler.class.php');
$column_list = $output->column_list;
/*
// Modified to find total number of SELECT queries having group by clause
// If it works correctly, uncomment the following codes
//
$count_condition = count($output->groups) ? sprintf('%s group by %s', $condition, implode(', ', $output->groups)) : $condition;
$total_count = $this->getCountCache($output->tables, $count_condition);
if($total_count === false) {
$count_query = sprintf("select count(*) as count from %s %s %s", implode(', ', $table_list), implode(' ', $left_join), $count_condition);
if (count($output->groups))
$count_query = sprintf('select count(*) as count from (%s) xet', $count_query);
$result = $this->_query($count_query);
$count_output = $this->_fetch($result);
$total_count = (int)$count_output->count;
$this->putCountCache($output->tables, $count_condition, $total_count);
}
*/
// Get a total count
$count_query = sprintf("select count(*) as count from %s %s %s", implode(',',$table_list),implode(' ',$left_join), $condition);
$count_query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id . ' count(*)'):'';
$result = $this->_query($count_query);
$count_output = $this->_fetch($result);
$total_count = (int)$count_output->count;
$list_count = $output->list_count['value'];
if(!$list_count) $list_count = 20;
$page_count = $output->page_count['value'];
if(!$page_count) $page_count = 10;
$page = $output->page['value'];
if(!$page) $page = 1;
// Get a total page
if($total_count) $total_page = (int)( ($total_count-1) / $list_count) + 1;
else $total_page = 1;
// Check Page variables
if($page > $total_page) $page = $total_page;
$start_count = ($page-1)*$list_count;
// Add a condition to use an index when sorting in order by list_order, update_order
if($output->order) {
$conditions = $this->getConditionList($output);
if(!in_array('list_order', $conditions) && !in_array('update_order', $conditions)) {
foreach($output->order as $key => $val) {
$col = $val[0];
if(!in_array($col, array('list_order','update_order'))) continue;
if($condition) $condition .= sprintf(' and %s < 2100000000 ', $col);
else $condition = sprintf(' where %s < 2100000000 ', $col);
}
}
}
$query = sprintf("select %s from %s %s %s", $columns, implode(',',$table_list), implode(' ',$left_join), $condition);
if(count($output->groups)) $query .= sprintf(' group by %s', implode(',',$output->groups));
if($output->order) {
foreach($output->order as $key => $val) {
$index_list[] = sprintf('%s %s', $val[0], $val[1]);
}
if(count($index_list)) $query .= ' order by '.implode(',',$index_list);
}
$query = sprintf('%s limit %d, %d', $query, $start_count, $list_count);
$query .= (__DEBUG_QUERY__&1 && $output->query_id)?sprintf(' '.$this->comment_syntax,$this->query_id):'';
$result = $this->_query($query);
if($this->isError()) {
$buff = new Object();
$buff->total_count = 0;
$buff->total_page = 0;
$buff->page = 1;
$buff->data = array();
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
return $buff;
}
if($result) {
$virtual_no = $total_count - ($page-1)*$list_count;
while($tmp = sqlite_fetch_array($result, SQLITE_ASSOC)) {
unset($obj);
foreach($tmp as $key => $val) {
$pos = strpos($key, '.');
if($pos) $key = substr($key, $pos+1);
$obj->{$key} = $val;
}
$data[$virtual_no--] = $obj;
}
}
$buff = new Object();
$buff->total_count = $total_count;
$buff->total_page = $total_page;
$buff->page = $page;
$buff->data = $data;
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
return $buff;
}
}
return new DBSqlite2;
?>

View file

@ -517,7 +517,17 @@
$total_page = 1;
// check the page variables
if ($page > $total_page) $page = $total_page;
if ($page > $total_page) {
// If requested page is bigger than total number of pages, return empty list
$buff = new Object ();
$buff->total_count = $total_count;
$buff->total_page = $total_page;
$buff->page = $page;
$buff->data = array();
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
return $buff;
}
$start_count = ($page - 1) * $list_count;
$this->_prepare($this->getSelectPageSql($queryObject, true, $start_count, $list_count));

View file

@ -18,10 +18,12 @@ class HTMLDisplayHandler {
if(Context::get('module')!='admin' && strpos(Context::get('act'),'Admin') === false){
if ($skin && is_string($skin)){
$theme_skin = explode('.', $skin);
if (count($theme_skin) == 2)
$template_path = sprintf('./themes/%s/modules/%s/', $theme_skin[0], $theme_skin[1]);
else
$template_path = $oModule->getTemplatePath();
$template_path = $oModule->getTemplatePath();
if (count($theme_skin) == 2) {
$theme_path = sprintf('./themes/%s',$theme_skin[0]);
if(substr($theme_path,0,strlen($theme_path)) != $theme_path)
$template_path = sprintf('%s/modules/%s/', $theme_path, $theme_skin[1]);
}
}else{
$template_path = $oModule->getTemplatePath();
}
@ -115,6 +117,8 @@ class HTMLDisplayHandler {
$keys = '('.implode('|', $keys).')';
$output = preg_replace_callback('@(<input)([^>]*?)\sname="'.$keys.'"([^>]*?)/?>@is', array(&$this, '_preserveValue'), $output);
$output = preg_replace_callback('@<select[^>]*\sname="'.$keys.'".+</select>@isU', array(&$this, '_preserveSelectValue'), $output);
$output = preg_replace_callback('@<textarea[^>]*\sname="'.$keys.'".+</textarea>@isU', array(&$this, '_preserveTextAreaValue'), $output);
}
if(__DEBUG__==3) $GLOBALS['__trans_content_elapsed__'] = getMicroTime()-$start;
@ -160,7 +164,7 @@ class HTMLDisplayHandler {
switch($type){
case 'text':
case 'hidden':
$str = preg_replace('@\svalue="[^"]*?"@', ' ', $str).' value="'.$INPUT_ERROR[$match[3]].'"';
$str = preg_replace('@\svalue="[^"]*?"@', ' ', $str).' value="'.htmlspecialchars($INPUT_ERROR[$match[3]]).'"';
break;
case 'password':
$str = preg_replace('@\svalue="[^"]*?"@', ' ', $str);
@ -177,6 +181,32 @@ class HTMLDisplayHandler {
return $str.' />';
}
function _preserveSelectValue($matches)
{
$INPUT_ERROR = Context::get('INPUT_ERROR');
preg_replace('@\sselected(="[^"]*?")?@', ' ', $matches[0]);
preg_match('@<select.*?>@is', $matches[0], $mm);
preg_match_all('@<option[^>]*\svalue="([^"]*)".+</option>@isU', $matches[0], $m);
$key = array_search($INPUT_ERROR[$matches[1]], $m[1]);
if($key === FALSE)
{
return $matches[0];
}
$m[0][$key] = preg_replace('@(\svalue=".*?")@is', '$1 selected="selected"', $m[0][$key]);
return $mm[0].implode('', $m[0]).'</select>';
}
function _preserveTextAreaValue($matches)
{
$INPUT_ERROR = Context::get('INPUT_ERROR');
preg_match('@<textarea.*?>@is', $matches[0], $mm);
return $mm[0].$INPUT_ERROR[$matches[1]].'</textarea>';
}
/**
* @brief add html style code extracted from html body to Context, which will be
* printed inside <header></header> later.

View file

@ -206,13 +206,13 @@
// textarea
case 'textarea' :
$buff .= '<textarea name="'.$column_name.'" class="textarea">'.$value.'</textarea>';
$buff .= '<textarea name="'.$column_name.'" rows="8" cols="42">'.$value.'</textarea>';
break;
// multiple choice
case 'checkbox' :
$buff .= '<ul>';
foreach($default as $v) {
if($value && in_array($v, $value)) $checked = ' checked="checked"';
if($value && in_array(trim($v), $value)) $checked = ' checked="checked"';
else $checked = '';
// Temporary ID for labeling
@ -254,7 +254,7 @@
$buff .=
'<input type="hidden" name="'.$column_name.'" value="'.$value.'" />'.
'<input type="text" id="date_'.$column_name.'" value="'.zdate($value,'Y-m-d').'" class="date" />'."\n".
'<input type="text" id="date_'.$column_name.'" value="'.zdate($value,'Y-m-d').'" class="date" /> <input type="button" value="' . Context::getLang('cmd_delete') . '" id="dateRemover_' . $column_name . '" />'."\n".
'<script type="text/javascript">'."\n".
'(function($){'."\n".
' $(function(){'."\n".
@ -263,6 +263,10 @@
' };'."\n".
' $.extend(option,$.datepicker.regional[\''.Context::getLangType().'\']);'."\n".
' $("#date_'.$column_name.'").datepicker(option);'."\n".
' $("#dateRemover_' . $column_name . '").click(function(){' . "\n" .
' $(this).siblings("input").val("");' . "\n" .
' return false;' . "\n" .
' })' . "\n" .
' });'."\n".
'})(jQuery);'."\n".
'</script>';
@ -294,7 +298,7 @@
break;
// General text
default :
$buff .=' <input type="text" name="'.$column_name.'" value="'.$value.'" class="text" />';
$buff .=' <input type="text" name="'.$column_name.'" value="'.($value ? $value : $default).'" class="text" />';
break;
}
if($this->desc) $buff .= '<p>'.$this->desc.'</p>';

View file

@ -148,7 +148,12 @@ class FileHandler {
*/
function moveFile($source, $target) {
$source = FileHandler::getRealPath($source);
return (file_exists($source) && FileHandler::removeFile($target) && FileHandler::rename($source, $target));
if(!file_exists($source))
{
return FALSE;
}
FileHandler::removeFile($target);
return FileHandler::rename($source, $target);
}
/**
@ -529,24 +534,24 @@ class FileHandler {
switch($type) {
case 'gif' :
if(!function_exists('imagecreatefromgif')) return false;
$source = imagecreatefromgif($source_file);
$source = @imagecreatefromgif($source_file);
break;
// jpg
case 'jpeg' :
case 'jpg' :
if(!function_exists('imagecreatefromjpeg')) return false;
$source = imagecreatefromjpeg($source_file);
$source = @imagecreatefromjpeg($source_file);
break;
// png
case 'png' :
if(!function_exists('imagecreatefrompng')) return false;
$source = imagecreatefrompng($source_file);
$source = @imagecreatefrompng($source_file);
break;
// bmp
case 'wbmp' :
case 'bmp' :
if(!function_exists('imagecreatefromwbmp')) return false;
$source = imagecreatefromwbmp($source_file);
$source = @imagecreatefromwbmp($source_file);
break;
default :
return;
@ -676,5 +681,5 @@ class FileHandler {
}
}
/* End of file FileObject.class.php */
/* Location: ./classes/file/FileObject.class.php */
/* End of file FileHandler.class.php */
/* Location: ./classes/file/FileHandler.class.php */

View file

@ -55,7 +55,17 @@ class Mobile {
function isMobileCheckByAgent()
{
return !!preg_match('/(iPod|iPhone|Android|BlackBerry|SymbianOS|SCH-M\d+|SPH-M\d+|Windows Phone|Dorothy Browser|Googlebot-Mobile)/',$_SERVER['HTTP_USER_AGENT']);
$mobildAgent = array('iPod','iPhone','iPad','Android','BlackBerry','SymbianOS','Bada','Kindle','Wii','SCH-','SPH-','CANU-','Windows Phone','Windows CE','POLARIS','Palm','webOS','Dorothy Browser','IEMobile','MobileSafari','Opera Mobi','Opera Mini','MobileExplorer','Minimo','AvantGo','NetFront','Googlebot-Mobile','Nokia','LGPlayer','SonyEricsson','HTC','hp-tablet','SKT','lgtelecom','Vodafone');
foreach($mobildAgent as $agent)
{
if(strpos($_SERVER['HTTP_USER_AGENT'], $agent) !== FALSE)
{
return TRUE;
}
}
return FALSE;
}
function setMobile($ismobile)

View file

@ -89,6 +89,8 @@
if($this->mid != $module_info->mid) {
$this->mid = $module_info->mid;
Context::set('mid', $module_info->mid, true);
header('location:' . getNotEncodedSiteUrl($site_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl));
return false;
}
}
// if requested module is different from one of the document, remove the module information retrieved based on the document number

View file

@ -251,7 +251,7 @@ class TemplateHandler {
$generatedHidden = '';
foreach($resultArray AS $key=>$value)
{
$generatedHidden .= '<input type="hidden" name="'.$value.'" value="<?php echo $__Context->'.$value.' ?>">';
$generatedHidden .= '<input type="hidden" name="'.$value.'" value="<?php echo $__Context->'.$value.' ?>" />';
}
$matches[2] = $generatedHidden.$matches[2];
}
@ -396,7 +396,7 @@ class TemplateHandler {
}
if(strpos($node, '|cond="') !== false) {
$node = preg_replace('@(\s[\w:]+="[^"]+?")\|cond="(.+?)"@s', '<?php if($2){ ?>$1<?php } ?>', $node);
$node = preg_replace('@(\s[\w:\-]+="[^"]+?")\|cond="(.+?)"@s', '<?php if($2){ ?>$1<?php } ?>', $node);
$node = $this->_replaceVar($node);
}

View file

@ -103,6 +103,7 @@
if($this->isStarFunction($column_name)){
return $column_name;
}
if(strpos(strtolower($column_name), 'distinct') !== false) return $column_name;
return $this->escapeColumn($column_name);
}
}

View file

@ -1,209 +1,209 @@
<?php
class Argument {
var $value;
var $name;
var $type;
class Argument {
var $isValid;
var $errorMessage;
var $value;
var $name;
var $type;
var $isValid;
var $errorMessage;
var $column_operation;
var $uses_default_value; // Check if arg value is user submnitted or default
var $_value; // Caches escaped and toString value so that the parsing won't happen multiple times;
var $column_operation;
function Argument($name, $value) {
$this->value = $value;
$this->name = $name;
$this->isValid = true;
}
var $_value; // Caches escaped and toString value so that the parsing won't happen multiple times;
function getType() {
if (isset($this->type))
return $this->type;
if (is_string($this->value))
return 'column_name';
return 'number';
}
function Argument($name, $value){
$this->value = $value;
$this->name = $name;
$this->isValid = true;
}
function setColumnType($value) {
$this->type = $value;
}
function getType(){
if(isset($this->type)) return $this->type;
if(is_string($this->value)) return 'column_name';
return 'number';
}
function setColumnOperation($operation) {
$this->column_operation = $operation;
}
function setColumnType($value){
$this->type = $value;
}
function getName() {
return $this->name;
}
function setColumnOperation($operation){
$this->column_operation = $operation;
}
function getName(){
return $this->name;
}
function getValue(){
if(!isset($this->_value)){
function getValue() {
if (!isset($this->_value)) {
$value = $this->getEscapedValue();
$this->_value = $this->toString($value);
}
return $this->_value;
}
return $this->_value;
}
function getColumnOperation(){
return $this->column_operation;
}
function getColumnOperation() {
return $this->column_operation;
}
function getEscapedValue(){
return $this->escapeValue($this->value);
}
function getEscapedValue() {
return $this->escapeValue($this->value);
}
function getUnescapedValue(){
return $this->value;
function getUnescapedValue() {
return $this->value;
}
function toString($value) {
if (is_array($value)) {
if (count($value) === 0)
return '';
if (count($value) === 1 && $value[0] === '')
return '';
return '(' . implode(',', $value) . ')';
}
return $value;
}
function toString($value){
if(is_array($value)){
if(count($value) === 0) return '';
if(count($value) === 1 && $value[0] === '') return '';
return '('.implode(',', $value).')';
}
return $value;
function escapeValue($value) {
$column_type = $this->getType();
if ($column_type == 'column_name') {
$dbParser = DB::getParser();
return $dbParser->parseExpression($value);
}
if (!isset($value))
return null;
function escapeValue($value){
$column_type = $this->getType();
if($column_type == 'column_name'){
$dbParser = DB::getParser();
return $dbParser->parseExpression($value);
if (in_array($column_type, array('date', 'varchar', 'char', 'text', 'bigtext'))) {
if (!is_array($value))
$value = $this->_escapeStringValue($value);
else {
$total = count($value);
for ($i = 0; $i < $total; $i++)
$value[$i] = $this->_escapeStringValue($value[$i]);
//$value[$i] = '\''.$value[$i].'\'';
}
if(!isset($value)) return null;
if(in_array($column_type, array('date', 'varchar', 'char','text', 'bigtext'))){
if(!is_array($value))
$value = $this->_escapeStringValue ($value);
else {
$total = count($value);
for($i = 0; $i < $total; $i++)
$value[$i] = $this->_escapeStringValue($value[$i]);
//$value[$i] = '\''.$value[$i].'\'';
}
}
if($column_type == 'number')
{
if(is_array($value))
{
foreach($value AS $key=>$val)
{
if(isset($val))
{
$value[$key] = (int)$val;
}
}
if($this->uses_default_value) return $value;
if ($column_type == 'number') {
if (is_array($value)) {
foreach ($value AS $key => $val) {
if (isset($val)) {
$value[$key] = (int) $val;
}
}
else
{
if(isset($val))
{
$value = (int)$value;
} else {
$value = (int) $value;
}
}
return $value;
}
function _escapeStringValue($value) {
$db = &DB::getInstance();
$value = $db->addQuotes($value);
return '\'' . $value . '\'';
}
function isValid() {
return $this->isValid;
}
function getErrorMessage() {
return $this->errorMessage;
}
function ensureDefaultValue($default_value) {
if (!isset($this->value) || $this->value == '')
{
$this->value = $default_value;
$this->uses_default_value = true;
}
}
function checkFilter($filter_type) {
if (isset($this->value) && $this->value != '') {
global $lang;
$val = $this->value;
$key = $this->name;
switch ($filter_type) {
case 'email' :
case 'email_address' :
if (!preg_match('/^[_0-9a-z-]+(\.[_0-9a-z-]+)*@[0-9a-z-]+(\.[0-9a-z-]+)*$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key));
}
}
}
return $value;
}
function _escapeStringValue($value){
$db = &DB::getInstance();
$value = $db->addQuotes($value);
return '\''.$value.'\'';
}
function isValid(){
return $this->isValid;
}
function getErrorMessage(){
return $this->errorMessage;
}
function ensureDefaultValue($default_value){
if(!isset($this->value) || $this->value == '')
$this->value = $default_value;
}
function checkFilter($filter_type){
if(isset($this->value) && $this->value != ''){
global $lang;
$val = $this->value;
$key = $this->name;
switch($filter_type) {
case 'email' :
case 'email_address' :
if(!preg_match('/^[_0-9a-z-]+(\.[_0-9a-z-]+)*@[0-9a-z-]+(\.[0-9a-z-]+)*$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_email, $lang->{$key} ? $lang->{$key} : $key));
}
break;
case 'homepage' :
if(!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key));
}
break;
case 'userid' :
case 'user_id' :
if(!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key));
}
break;
case 'number' :
case 'numbers' :
if(is_array($val)) $val = join(',', $val);
if(!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)){
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
}
break;
case 'alpha' :
if(!preg_match('/^[a-z]+$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key));
}
break;
case 'alpha_number' :
if(!preg_match('/^[0-9a-z]+$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key));
}
break;
}
}
}
function checkMaxLength($length){
if($this->value && (strlen($this->value) > $length)){
global $lang;
$this->isValid = false;
$key = $this->name;
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
}
}
function checkMinLength($length){
if($this->value && (strlen($this->value) < $length)){
global $lang;
$this->isValid = false;
$key = $this->name;
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
}
}
function checkNotNull(){
if(!isset($this->value)){
global $lang;
$this->isValid = false;
$key = $this->name;
$this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key));
break;
case 'homepage' :
if (!preg_match('/^(http|https)+(:\/\/)+[0-9a-z_-]+\.[^ ]+$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_homepage, $lang->{$key} ? $lang->{$key} : $key));
}
break;
case 'userid' :
case 'user_id' :
if (!preg_match('/^[a-zA-Z]+([_0-9a-zA-Z]+)*$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_userid, $lang->{$key} ? $lang->{$key} : $key));
}
break;
case 'number' :
case 'numbers' :
if (is_array($val))
$val = join(',', $val);
if (!preg_match('/^(-?)[0-9]+(,\-?[0-9]+)*$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_number, $lang->{$key} ? $lang->{$key} : $key));
}
break;
case 'alpha' :
if (!preg_match('/^[a-z]+$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha, $lang->{$key} ? $lang->{$key} : $key));
}
break;
case 'alpha_number' :
if (!preg_match('/^[0-9a-z]+$/is', $val)) {
$this->isValid = false;
$this->errorMessage = new Object(-1, sprintf($lang->filter->invalid_alpha_number, $lang->{$key} ? $lang->{$key} : $key));
}
break;
}
}
}
function checkMaxLength($length) {
if ($this->value && (strlen($this->value) > $length)) {
global $lang;
$this->isValid = false;
$key = $this->name;
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
}
}
function checkMinLength($length) {
if ($this->value && (strlen($this->value) < $length)) {
global $lang;
$this->isValid = false;
$key = $this->name;
$this->errorMessage = new Object(-1, sprintf($lang->filter->outofrange, $lang->{$key} ? $lang->{$key} : $key));
}
}
function checkNotNull() {
if (!isset($this->value)) {
global $lang;
$this->isValid = false;
$key = $this->name;
$this->errorMessage = new Object(-1, sprintf($lang->filter->isnull, $lang->{$key} ? $lang->{$key} : $key));
}
}
}
?>

View file

@ -1,104 +1,115 @@
<?php
class QueryArgument {
var $argument_name;
var $variable_name;
var $argument_validator;
var $column_name;
var $operation;
class QueryArgument {
var $ignore_value;
var $argument_name;
var $variable_name;
var $argument_validator;
var $column_name;
var $table_name;
var $operation;
var $ignore_value;
function QueryArgument($tag, $ignore_value = false){
static $number_of_arguments = 0;
function QueryArgument($tag, $ignore_value = false) {
static $number_of_arguments = 0;
$this->argument_name = $tag->attrs->var;
if(!$this->argument_name) $this->argument_name = str_replace('.', '_',$tag->attrs->name);
if(!$this->argument_name) $this->argument_name = str_replace('.', '_',$tag->attrs->column);
$this->argument_name = $tag->attrs->var;
if (!$this->argument_name)
$this->argument_name = str_replace('.', '_', $tag->attrs->name);
if (!$this->argument_name)
$this->argument_name = str_replace('.', '_', $tag->attrs->column);
$this->variable_name = $this->argument_name;
$this->variable_name = $this->argument_name;
$number_of_arguments++;
$this->argument_name .= $number_of_arguments;
$number_of_arguments++;
$this->argument_name .= $number_of_arguments;
$name = $tag->attrs->name;
if(!$name) $name = $tag->attrs->column;
if(strpos($name, '.') === false) $this->column_name = $name;
else {
list($prefix, $name) = explode('.', $name);
$this->column_name = $name;
}
if($tag->attrs->operation) $this->operation = $tag->attrs->operation;
$this->argument_validator = new QueryArgumentValidator($tag, $this);
$this->ignore_value = $ignore_value;
$name = $tag->attrs->name;
if (!$name)
$name = $tag->attrs->column;
if (strpos($name, '.') === false)
$this->column_name = $name;
else {
list($prefix, $name) = explode('.', $name);
$this->column_name = $name;
$this->table_name = $prefix;
}
function getArgumentName(){
return $this->argument_name;
}
function getColumnName(){
return $this->column_name;
}
function getValidatorString(){
return $this->argument_validator->toString();
}
function isConditionArgument(){
if($this->operation) return true;
return false;
}
function toString(){
if($this->isConditionArgument()){
// Instantiation
$arg = sprintf("\n$%s_argument = new ConditionArgument('%s', %s, '%s');\n"
, $this->argument_name
, $this->variable_name
, '$args->'.$this->variable_name
, $this->operation
);
// Call methods to validate argument and ensure default value
$arg .= $this->argument_validator->toString();
// Prepare condition string
$arg .= sprintf("$%s_argument->createConditionValue();\n"
, $this->argument_name
);
// Check that argument passed validation, else return
$arg .= sprintf("if(!$%s_argument->isValid()) return $%s_argument->getErrorMessage();\n"
, $this->argument_name
, $this->argument_name
);
}
else {
$arg = sprintf("\n$%s_argument = new Argument('%s', %s);\n"
, $this->argument_name
, $this->variable_name
, $this->ignore_value ? 'null' : '$args->'.$this->variable_name);
$arg .= $this->argument_validator->toString();
$arg .= sprintf("if(!$%s_argument->isValid()) return $%s_argument->getErrorMessage();\n"
, $this->argument_name
, $this->argument_name
);
}
// If the argument is null, skip it
if($this->argument_validator->isIgnorable()){
$arg = sprintf("if(isset(%s)) {", '$args->'.$this->variable_name)
. $arg
. sprintf("} else \n$%s_argument = null;", $this->argument_name);
}
return $arg;
}
if ($tag->attrs->operation)
$this->operation = $tag->attrs->operation;
$this->argument_validator = new QueryArgumentValidator($tag, $this);
$this->ignore_value = $ignore_value;
}
?>
function getArgumentName() {
return $this->argument_name;
}
function getColumnName() {
return $this->column_name;
}
function getTableName(){
return $this->table_name;
}
function getValidatorString() {
return $this->argument_validator->toString();
}
function isConditionArgument() {
if ($this->operation)
return true;
return false;
}
function toString() {
if ($this->isConditionArgument()) {
// Instantiation
$arg = sprintf("\n" . '${\'%s_argument\'} = new ConditionArgument(\'%s\', %s, \'%s\');' . "\n"
, $this->argument_name
, $this->variable_name
, '$args->' . $this->variable_name
, $this->operation
);
// Call methods to validate argument and ensure default value
$arg .= $this->argument_validator->toString();
// Prepare condition string
$arg .= sprintf('${\'%s_argument\'}->createConditionValue();' . "\n"
, $this->argument_name
);
// Check that argument passed validation, else return
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
, $this->argument_name
, $this->argument_name
);
} else {
$arg = sprintf("\n" . '${\'%s_argument\'} = new Argument(\'%s\', %s);' . "\n"
, $this->argument_name
, $this->variable_name
, $this->ignore_value ? 'null' : '$args->' . $this->variable_name);
$arg .= $this->argument_validator->toString();
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
, $this->argument_name
, $this->argument_name
);
}
// If the argument is null, skip it
if ($this->argument_validator->isIgnorable()) {
$arg = sprintf("if(isset(%s)) {", '$args->' . $this->variable_name)
. $arg
. sprintf("} else\n" . '${\'%s_argument\'} = null;', $this->argument_name);
}
return $arg;
}
}
?>

View file

@ -2,7 +2,7 @@
class SortQueryArgument extends QueryArgument{
function toString(){
$arg = sprintf("\n$%s_argument = new SortArgument('%s', %s);\n"
$arg = sprintf("\n" . '${\'%s_argument\'} = new SortArgument(\'%s\', %s);' . "\n"
, $this->argument_name
, $this->argument_name
, '$args->'.$this->variable_name);
@ -10,7 +10,7 @@
$arg .= $this->argument_validator->toString();
$arg .= sprintf("if(!$%s_argument->isValid()) return $%s_argument->getErrorMessage();\n"
$arg .= sprintf('if(!${\'%s_argument\'}->isValid()) return ${\'%s_argument\'}->getErrorMessage();' . "\n"
, $this->argument_name
, $this->argument_name
);

View file

@ -30,19 +30,19 @@
function toString(){
$validator = '';
if($this->filter){
$validator .= sprintf("$%s_argument->checkFilter('%s');\n"
$validator .= sprintf('${\'%s_argument\'}->checkFilter(\'%s\');' . "\n"
, $this->argument_name
, $this->filter
);
}
if($this->min_length){
$validator .= sprintf("$%s_argument->checkMinLength(%s);\n"
$validator .= sprintf('${\'%s_argument\'}->checkMinLength(%s);' . "\n"
, $this->argument_name
, $this->min_length
);
}
if($this->max_length){
$validator .= sprintf("$%s_argument->checkMaxLength(%s);\n"
$validator .= sprintf('${\'%s_argument\'}->checkMaxLength(%s);'. "\n"
, $this->argument_name
, $this->max_length
);
@ -52,17 +52,17 @@
if($this->default_value->isSequence())
$validator .= '$db = &DB::getInstance(); $sequence = $db->getNextSequence(); ';
if($this->default_value->isOperation())
$validator .= sprintf("$%s_argument->setColumnOperation('%s');\n"
$validator .= sprintf('${\'%s_argument\'}->setColumnOperation(\'%s\');' . "\n"
, $this->argument_name
, $this->default_value->getOperation()
);
$validator .= sprintf("$%s_argument->ensureDefaultValue(%s);\n"
$validator .= sprintf('${\'%s_argument\'}->ensureDefaultValue(%s);' . "\n"
, $this->argument_name
, $this->default_value->toString()
);
}
if($this->notnull){
$validator .= sprintf("$%s_argument->checkNotNull();\n"
$validator .= sprintf('${\'%s_argument\'}->checkNotNull();' . "\n"
, $this->argument_name
);
}
@ -70,4 +70,4 @@
}
}
?>
?>

View file

@ -18,7 +18,7 @@
}
function getExpressionString(){
return sprintf('new InsertExpression(\'%s\', $%s_argument)'
return sprintf('new InsertExpression(\'%s\', ${\'%s_argument\'})'
, $this->name
, $this->argument->argument_name);
}
@ -28,4 +28,4 @@
}
}
?>
?>

View file

@ -44,7 +44,7 @@
function getExpressionString(){
if($this->argument)
return sprintf('new UpdateExpression(\'%s\', $%s_argument)'
return sprintf('new UpdateExpression(\'%s\', ${\'%s_argument\'})'
, $this->name
, $this->argument->argument_name);
else {
@ -59,4 +59,4 @@
}
}
?>
?>

View file

@ -28,7 +28,7 @@
}
function toString(){
return sprintf("new OrderByColumn(\$%s_argument, %s)", $this->argument->getArgumentName(), $this->sort_order);
return sprintf('new OrderByColumn(${\'%s_argument\'}, %s)', $this->argument->getArgumentName(), $this->sort_order);
}
function getArguments(){
@ -40,4 +40,4 @@
}
}
?>
?>

View file

@ -19,12 +19,12 @@
}
function toString(){
if ($this->page)return sprintf("new Limit(\$%s_argument, \$%s_argument, \$%s_argument)", $this->list_count->getArgumentName(), $this->page->getArgumentName(), $this->page_count->getArgumentName());
else return sprintf("new Limit(\$%s_argument)", $this->list_count->getArgumentName());
if ($this->page)return sprintf('new Limit(${\'%s_argument\'}, ${\'%s_argument\'}, ${\'%s_argument\'})', $this->list_count->getArgumentName(), $this->page->getArgumentName(), $this->page_count->getArgumentName());
else return sprintf('new Limit(${\'%s_argument\'})', $this->list_count->getArgumentName());
}
function getArguments(){
return $this->arguments;
}
}
?>
?>

View file

@ -1,12 +1,12 @@
<?php
class QueryTag {
var $action;
var $query_id;
var $priority;
var $column_type;
var $query;
//xml tags
var $columns;
var $tables;
@ -17,22 +17,22 @@ class QueryTag {
var $preBuff;
var $buff;
var $isSubQuery;
var $join_type;
var $join_type;
var $alias;
function QueryTag($query, $isSubQuery = false){
function QueryTag($query, $isSubQuery = false) {
$this->action = $query->attrs->action;
$this->query_id = $query->attrs->id;
$this->priority = $query->attrs->priority;
$this->query = $query;
$this->isSubQuery = $isSubQuery;
if($this->isSubQuery) $this->action = 'select';
if($query->attrs->alias){
$dbParser = DB::getParser();
$this->alias = $dbParser->escape($query->attrs->alias);
}
$this->join_type = $query->attrs->join_type;
if ($this->isSubQuery)
$this->action = 'select';
if ($query->attrs->alias) {
$dbParser = DB::getParser();
$this->alias = $dbParser->escape($query->attrs->alias);
}
$this->join_type = $query->attrs->join_type;
$this->getColumns();
$tables = $this->getTables();
@ -44,155 +44,175 @@ class QueryTag {
$this->getBuff();
}
function show(){
function show() {
return true;
}
function getQueryId(){
function getQueryId() {
return $this->query->attrs->query_id ? $this->query->attrs->query_id : $this->query->attrs->id;
}
function getPriority(){
function getPriority() {
return $this->query->attrs->priority;
}
function getAction(){
function getAction() {
return $this->query->attrs->action;
}
function setTableColumnTypes($tables){
function setTableColumnTypes($tables) {
$query_id = $this->getQueryId();
if(!isset($this->column_type[$query_id])){
if (!isset($this->column_type[$query_id])) {
$table_tags = $tables->getTables();
$column_type = array();
foreach($table_tags as $table_tag){
if(is_a($table_tag, 'TableTag')){
$tag_column_type = QueryParser::getTableInfo($query_id, $table_tag->getTableName());
$column_type = array_merge($column_type, $tag_column_type);
}
foreach ($table_tags as $table_tag) {
if (is_a($table_tag, 'TableTag')) {
$table_name = $table_tag->getTableName();
$table_alias = $table_tag->getTableAlias();
$tag_column_type = QueryParser::getTableInfo($query_id, $table_name);
$column_type[$table_alias] = $tag_column_type;
}
}
$this->column_type[$query_id] = $column_type;
}
}
function getColumns(){
if($this->action == 'select'){
return $this->columns = new SelectColumnsTag($this->query->columns);
}else if($this->action == 'insert'){
return $this->columns = new InsertColumnsTag($this->query->columns->column);
}else if($this->action == 'update') {
return $this->columns = new UpdateColumnsTag($this->query->columns->column);
}else if($this->action == 'delete') {
return $this->columns = null;
function getColumns() {
if ($this->action == 'select') {
return $this->columns = new SelectColumnsTag($this->query->columns);
} else if ($this->action == 'insert') {
return $this->columns = new InsertColumnsTag($this->query->columns->column);
} else if ($this->action == 'update') {
return $this->columns = new UpdateColumnsTag($this->query->columns->column);
} else if ($this->action == 'delete') {
return $this->columns = null;
}
}
function getPrebuff(){
function getPrebuff() {
// TODO Check if this work with arguments in join clause
$arguments = $this->getArguments();
$prebuff = '';
foreach($arguments as $argument){
if(isset($argument)){
$arg_name = $argument->getArgumentName();
if($arg_name){
$prebuff .= $argument->toString();
$column_type = $this->column_type[$this->getQueryId()][$argument->getColumnName()];
if(isset($column_type))
$prebuff .= sprintf("if($%s_argument !== null) $%s_argument->setColumnType('%s');\n"
, $arg_name
, $arg_name
, $column_type );
}
}
foreach ($arguments as $argument) {
if (isset($argument)) {
$arg_name = $argument->getArgumentName();
if ($arg_name) {
unset($column_type);
$prebuff .= $argument->toString();
$table_alias = $argument->getTableName();
if(isset($table_alias))
{
$column_type = $this->column_type[$this->getQueryId()][$table_alias][$argument->getColumnName()];
}
else
{
$current_tables = $this->column_type[$this->getQueryId()];
$column_name = $argument->getColumnName();
foreach($current_tables as $current_table)
{
if($current_table[$column_name])
$column_type = $current_table[$column_name];
}
}
if (isset($column_type))
$prebuff .= sprintf('if(${\'%s_argument\'} !== null) ${\'%s_argument\'}->setColumnType(\'%s\');' . "\n"
, $arg_name
, $arg_name
, $column_type);
}
}
}
$prebuff .= "\n";
return $this->preBuff = $prebuff;
}
function getBuff(){
function getBuff() {
$buff = '';
if($this->isSubQuery){
if ($this->isSubQuery) {
$buff = 'new Subquery(';
$buff .= "'" . $this->alias . '\', ';
$buff .= ($this->columns ? $this->columns->toString() : 'null' ). ', '.PHP_EOL;
$buff .= $this->tables->toString() .','.PHP_EOL;
$buff .= $this->conditions->toString() .',' .PHP_EOL;
$buff .= $this->groups->toString() . ',' .PHP_EOL;
$buff .= $this->navigation->getOrderByString() .','.PHP_EOL;
$limit = $this->navigation->getLimitString() ;
$buff .= $limit ? $limit : 'null' . PHP_EOL;
$buff .= $this->join_type ? "'" . $this->join_type . "'" : '';
$buff .= ($this->columns ? $this->columns->toString() : 'null' ) . ', ' . PHP_EOL;
$buff .= $this->tables->toString() . ',' . PHP_EOL;
$buff .= $this->conditions->toString() . ',' . PHP_EOL;
$buff .= $this->groups->toString() . ',' . PHP_EOL;
$buff .= $this->navigation->getOrderByString() . ',' . PHP_EOL;
$limit = $this->navigation->getLimitString();
$buff .= $limit ? $limit : 'null' . PHP_EOL;
$buff .= $this->join_type ? "'" . $this->join_type . "'" : '';
$buff .= ')';
$this->buff = $buff;
return $this->buff;
}
$buff .= '$query = new Query();'.PHP_EOL;
$buff .= '$query = new Query();' . PHP_EOL;
$buff .= sprintf('$query->setQueryId("%s");%s', $this->query_id, "\n");
$buff .= sprintf('$query->setAction("%s");%s', $this->action, "\n");
$buff .= sprintf('$query->setPriority("%s");%s', $this->priority, "\n");
$buff .= $this->preBuff;
if($this->columns)
$buff .= '$query->setColumns(' . $this->columns->toString() . ');'.PHP_EOL;
if ($this->columns)
$buff .= '$query->setColumns(' . $this->columns->toString() . ');' . PHP_EOL;
$buff .= '$query->setTables(' . $this->tables->toString() .');'.PHP_EOL;
$buff .= '$query->setConditions('.$this->conditions->toString() .');'.PHP_EOL;
$buff .= '$query->setGroups(' . $this->groups->toString() . ');'.PHP_EOL;
$buff .= '$query->setOrder(' . $this->navigation->getOrderByString() .');'.PHP_EOL;
$buff .= '$query->setLimit(' . $this->navigation->getLimitString() .');'.PHP_EOL;
$buff .= '$query->setTables(' . $this->tables->toString() . ');' . PHP_EOL;
$buff .= '$query->setConditions(' . $this->conditions->toString() . ');' . PHP_EOL;
$buff .= '$query->setGroups(' . $this->groups->toString() . ');' . PHP_EOL;
$buff .= '$query->setOrder(' . $this->navigation->getOrderByString() . ');' . PHP_EOL;
$buff .= '$query->setLimit(' . $this->navigation->getLimitString() . ');' . PHP_EOL;
$this->buff = $buff;
return $this->buff;
}
function getTables(){
if($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for))
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
else
return $this->tables = new TablesTag($this->query->tables);
function getTables() {
if ($this->query->index_hint->attrs->for == 'ALL' || Context::getDBType() == strtolower($this->query->index_hint->attrs->for))
return $this->tables = new TablesTag($this->query->tables, $this->query->index_hint);
else
return $this->tables = new TablesTag($this->query->tables);
}
function getConditions(){
function getConditions() {
return $this->conditions = new ConditionsTag($this->query->conditions);
}
function getGroups(){
function getGroups() {
return $this->groups = new GroupsTag($this->query->groups->group);
}
function getNavigation(){
function getNavigation() {
return $this->navigation = new NavigationTag($this->query->navigation);
}
function toString(){
function toString() {
return $this->buff;
}
function getTableString(){
function getTableString() {
return $this->buff;
}
function getConditionString(){
function getConditionString() {
return $this->buff;
}
function getExpressionString(){
function getExpressionString() {
return $this->buff;
}
function getArguments(){
function getArguments() {
$arguments = array();
if($this->columns)
if ($this->columns)
$arguments = array_merge($arguments, $this->columns->getArguments());
$arguments = array_merge($arguments, $this->tables->getArguments());
$arguments = array_merge($arguments, $this->tables->getArguments());
$arguments = array_merge($arguments, $this->conditions->getArguments());
$arguments = array_merge($arguments, $this->navigation->getArguments());
return $arguments;
}
}
?>