').appendTo(captchaXE);$div.find('form').submit(function(){if(!$('#secret_text').val()){$div.find('input[type=text]').val('').focus();return false;}captchaXE.compare();return false;});$div.find('button.cancel').click(function(){$('#captcha_layer').hide();});$div.find('button.play').click(function(){var swf = window['captcha_audio'] || document['captcha_audio'];var audio = current_url.setQuery('captcha_action','captchaAudio').setQuery('rnd', (new Date).getTime());$div.find('input[type=text]').focus();swf.setSoundTarget(audio,'1');});$div.find('button.reload').click(function(){var params = new Array();params['captcha_action'] = 'setCaptchaSession';params['mid'] = current_mid;oldExecXml('','',params, function() {$("#captcha_image").attr("src", current_url.setQuery('captcha_action','captchaImage').setQuery('rnd', (new Date).getTime()));});});captchaXE.exec = function(module, act, params, callback_func, response_tags, callback_func_arg, fo_obj) {var doCheck = false;$.each(captchaTargetAct || {}, function(key,val){if (val == act){doCheck = true;return false;} });if (doCheck) {/* captcha 를 사용하는 경우 */ calledArgs = {'module':module,'act':act,'params':params,'callback_func':callback_func,'response_tags':response_tags,'callback_func_arg':callback_func_arg,'fo_obj':fo_obj};var params = new Array();params['captcha_action'] = 'setCaptchaSession';params['mid'] = current_mid;oldExecXml(module, act, params, captchaXE.show,new Array('error','message','about_captcha','captcha_reload','captcha_play','cmd_input','cmd_cancel'));} else {oldExecXml(module, act, params, callback_func, response_tags, callback_func_arg, fo_obj);}return true;};captchaXE.show = function(ret_obj) {$('#captcha_layer').show();$("#captchaAbout").html(ret_obj['about_captcha']);$("#captcha_layer .reload").attr('title',ret_obj['captcha_reload']);$("#captcha_layer .play").attr('title',ret_obj['captcha_play']);$("#captcha_layer button[type=submit]").html(ret_obj['cmd_input']);$("#captcha_layer button.cancel").html(ret_obj['cmd_cancel']);$("#captcha_image").attr("src", current_url.setQuery('captcha_action','captchaImage').setQuery('rnd', (new Date).getTime()));$div.find('input[type=text]').val('').focus();$('html, body').css('height','100%');};captchaXE.compare = function(e) {var params = new Array();params['captcha_action'] = 'captchaCompare';params['mid'] = current_mid;params['secret_text'] = $('#secret_text').val();oldExecXml(calledArgs.module,calledArgs.act,params, function() {$("#captcha_layer").hide();oldExecXml(calledArgs.module, calledArgs.act, calledArgs.params, calledArgs.callback_func, calledArgs.response_tags, calledArgs.callback_func_arg, calledArgs.fo_obj);} );};}return captchaXE;}$(window).ready(function(){oldExecXml = exec_xml;exec_xml = xeCaptcha().exec;});});})(jQuery);
\ No newline at end of file
+var oldExecXml=null;var calledArgs=null;(function(a){a(function(){var b=null;function c(){a("form").each(function(n){var l=false;if(!a(this).attr("onsubmit")||a(this).attr("onsubmit").indexOf("procFilter")<0){var m=a(this).find("input[name=act]").val();for(var n=0;n
')}a(this).submit(function(p){if(a(this).find("input[name=secret_text]").val()){return true}p.preventDefault();var o=this;a("#captcha_layer form").submit(function(r){r.preventDefault();if(!a("#secret_text").val()){a(this).find("input[type=text]").val("").focus();return false}a(o).append('
');a(o).submit()});var q=new Array();q.captcha_action="setCaptchaSession";q.mid=current_mid;oldExecXml("","",q,b.show,new Array("error","message","about_captcha","captcha_reload","captcha_play","cmd_input","cmd_cancel"))})}});var d=a(document.body);var g;if(!b){var j=(navigator.appVersion.indexOf("MSIE")!=-1)?true:false;var k=(navigator.appVersion.toLowerCase().indexOf("win")!=-1)?true:false;var i=(navigator.userAgent.indexOf("Opera")!=-1)?true:false;var h=request_uri+"addons/captcha/swf/play.swf";if(j&&k&&!i){_object_='
').appendTo(document.body);var f="margin:-105px 0 0 -105px; top:50%; left:50%;";if(screen.width<480){f=""}var e=a('
").appendTo(b);e.find("button.cancel").click(function(){a("#captcha_layer").hide()});e.find("button.play").click(function(){var l=window.captcha_audio||document.captcha_audio;var m=current_url.setQuery("captcha_action","captchaAudio").setQuery("rnd",(new Date).getTime());e.find("input[type=text]").focus();l.setSoundTarget(m,"1")});e.find("button.reload").click(function(){var l=new Array();l.captcha_action="setCaptchaSession";l.mid=current_mid;oldExecXml("","",l,function(){a("#captcha_image").attr("src",current_url.setQuery("captcha_action","captchaImage").setQuery("rnd",(new Date).getTime()))})});b.exec=function(p,l,s,o,r,q,m){var n=false;a.each(captchaTargetAct||{},function(t,u){if(u==l){n=true;return false}});if(n){a("#captcha_layer form").submit(function(t){t.preventDefault();if(!a("#secret_text").val()){a(this).find("input[type=text]").val("").focus();return false}b.compare();return false});calledArgs={module:p,act:l,params:s,callback_func:o,response_tags:r,callback_func_arg:q,fo_obj:m};var s=new Array();s.captcha_action="setCaptchaSession";s.mid=current_mid;oldExecXml(p,l,s,b.show,new Array("error","message","about_captcha","captcha_reload","captcha_play","cmd_input","cmd_cancel"))}else{oldExecXml(p,l,s,o,r,q,m)}return true};b.show=function(l){a("#captcha_layer").show();a("#captchaAbout").html(l.about_captcha);a("#captcha_layer .reload").attr("title",l.captcha_reload);a("#captcha_layer .play").attr("title",l.captcha_play);a("#captcha_layer button[type=submit]").html(l.cmd_input);a("#captcha_layer button.cancel").html(l.cmd_cancel);a("#captcha_image").attr("src",current_url.setQuery("captcha_action","captchaImage").setQuery("rnd",(new Date).getTime()));e.find("input[type=text]").val("").focus();a("html, body").css("height","100%")};b.compare=function(l){var m=new Array();m.captcha_action="captchaCompare";m.mid=current_mid;m.secret_text=a("#secret_text").val();oldExecXml(calledArgs.module,calledArgs.act,m,function(){a("#captcha_layer").hide();oldExecXml(calledArgs.module,calledArgs.act,calledArgs.params,calledArgs.callback_func,calledArgs.response_tags,calledArgs.callback_func_arg,calledArgs.fo_obj)})}}return b}a(window).ready(function(){oldExecXml=exec_xml;exec_xml=c().exec})})})(jQuery);
\ No newline at end of file
diff --git a/addons/member_communication/member_communication.addon.php b/addons/member_communication/member_communication.addon.php
index 519c7db47..89ed0fc6d 100644
--- a/addons/member_communication/member_communication.addon.php
+++ b/addons/member_communication/member_communication.addon.php
@@ -4,7 +4,7 @@ if(!defined('__XE__')) exit();
/**
* @file member_communication.addon.php
* @author NHN (developers@xpressengine.com)
- * @brief Promote user communication
+ * @brief Promote user communication
*
* - Pop-up the message if new message comes in
* - When calling MemberModel::getMemberMenu, feature to send a message is added
@@ -46,7 +46,7 @@ if($called_position == 'before_module_init' && $this->module != 'member') {
$mid = Context::get('cur_mid');
// Creates communication model object
$oCommunicationModel = &getModel('communication');
- // Add a feature to display own message box.
+ // Add a feature to display own message box.
if($logged_info->member_srl == $member_srl) {
// Add your own viewing Note Template
$oMemberController->addMemberPopupMenu(getUrl('','mid',$mid,'act','dispCommunicationMessages'), 'cmd_view_message_box', '', 'self');
@@ -55,7 +55,7 @@ if($called_position == 'before_module_init' && $this->module != 'member') {
// If not, Add menus to send message and to add friends
} else {
// Get member information
- $oMemberModel = &getModel('member');
+ $oMemberModel = &getModel('member');
$target_member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl);
if(!$target_member_info->member_srl) return;
// Get logged-in user information
diff --git a/addons/member_communication/tpl/member_communication.js b/addons/member_communication/tpl/member_communication.js
index 5264ee9a0..1fdf33edb 100644
--- a/addons/member_communication/tpl/member_communication.js
+++ b/addons/member_communication/tpl/member_communication.js
@@ -5,6 +5,10 @@ window.xeNotifyMessage = function(text, count){
if(!$bar.length) {
$bar = $('
')
.hide()
+ .css({
+ 'position' : 'absolute',
+ 'z-index' : '100',
+ })
.prependTo(document.body);
}
text = text.replace('%d', count);
@@ -13,6 +17,6 @@ window.xeNotifyMessage = function(text, count){
// hide after 10 seconds
setTimeout(function(){
$bar.slideUp();
- }, 10000);
+ }, 5000);
};
})(jQuery);
diff --git a/addons/member_extra_info/member_extra_info.addon.php b/addons/member_extra_info/member_extra_info.addon.php
index c693da378..925675453 100644
--- a/addons/member_extra_info/member_extra_info.addon.php
+++ b/addons/member_extra_info/member_extra_info.addon.php
@@ -17,7 +17,7 @@ if($called_position != "before_display_content" || Context::get('act')=='dispPag
// Include a file having functions to replace member image name/mark
require_once('./addons/member_extra_info/member_extra_info.lib.php');
// 1. Find a part
content
in the output document, change it to image name/mark by using MemberController::transImageName()
-$temp_output = preg_replace_callback('!<(div|span|a)([^\>]*)member_([0-9]+)([^\>]*)>([^\<]*)\<\/(div|span|a)\>!is', 'memberTransImageName', $output);
+$temp_output = preg_replace_callback('!<(div|span|a)([^\>]*)member_([0-9]+)([^\>]*)>(.*?)\<\/(div|span|a)\>!is', 'memberTransImageName', $output);
if($temp_output) $output = $temp_output;
unset($temp_output);
?>
diff --git a/addons/point_level_icon/point_level_icon.addon.php b/addons/point_level_icon/point_level_icon.addon.php
index 60e6b4530..483e15331 100644
--- a/addons/point_level_icon/point_level_icon.addon.php
+++ b/addons/point_level_icon/point_level_icon.addon.php
@@ -13,7 +13,7 @@ if($called_position != "before_display_content" || Context::get('act')=='dispPag
require_once('./addons/point_level_icon/point_level_icon.lib.php');
-$temp_output = preg_replace_callback('!<(div|span|a)([^\>]*)member_([0-9\-]+)([^\>]*)>([^\<]*)\<\/(div|span|a)\>!is', 'pointLevelIconTrans', $output);
+$temp_output = preg_replace_callback('!<(div|span|a)([^\>]*)member_([0-9\-]+)([^\>]*)>(.*?)\<\/(div|span|a)\>!is', 'pointLevelIconTrans', $output);
if($temp_output) $output = $temp_output;
unset($temp_output);
?>
diff --git a/classes/cache/CacheApc.class.php b/classes/cache/CacheApc.class.php
index c0bdd6240..2d229bf0b 100644
--- a/classes/cache/CacheApc.class.php
+++ b/classes/cache/CacheApc.class.php
@@ -1,14 +1,22 @@
valid_time;
return apc_store(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time);
}
+ /**
+ * Return whether cache is valid or invalid
+ *
+ * @param string $key Cache key
+ * @param int $modified_time Unix time of data modified.
+ * If stored time is older then modified time, the data is invalid.
+ * @return bool Return true on valid or false on invalid.
+ */
function isValid($key, $modified_time = 0) {
$_key = md5(_XE_PATH_.$key);
$obj = apc_fetch($_key, $success);
@@ -42,6 +78,14 @@ class CacheApc extends CacheBase {
return true;
}
+ /**
+ * Fetch a stored variable from the cache
+ *
+ * @param string $key The $key used to store the value.
+ * @param int $modified_time Unix time of data modified.
+ * If stored time is older then modified time, return false.
+ * @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
+ */
function get($key, $modified_time = 0) {
$_key = md5(_XE_PATH_.$key);
$obj = apc_fetch($_key, $success);
@@ -55,15 +99,31 @@ class CacheApc extends CacheBase {
return $obj[1];
}
+ /**
+ * Delete variable from the cache(private)
+ *
+ * @param string $_key Used to store the value.
+ * @return void
+ */
function _delete($_key) {
$this->put($_key,null,1);
}
+ /**
+ * Delete variable from the cache
+ *
+ * @param string $key Used to store the value.
+ * @return void
+ */
function delete($key) {
- $_key = md5(_XE_PATH_.$key);
- $this->_delete($_key);
+ $this->_delete($key);
}
+ /**
+ * Truncate all existing variables at the cache
+ *
+ * @return bool Returns true on success or false on failure.
+ */
function truncate() {
return apc_clear_cache('user');
}
diff --git a/classes/cache/CacheFile.class.php b/classes/cache/CacheFile.class.php
index 516b3419f..bc3f11336 100644
--- a/classes/cache/CacheFile.class.php
+++ b/classes/cache/CacheFile.class.php
@@ -1,15 +1,29 @@
cache_dir = _XE_PATH_ . $this->cache_dir;
if(!is_dir($this->cache_dir)) FileHandler::makeDir($this->cache_dir);
}
+ /**
+ * Get cache file name by key
+ *
+ * @param string $key The key that will be associated with the item.
+ * @return string Returns cache file path
+ */
function getCacheFileName($key){
return $this->cache_dir . str_replace(':', '_', $key);
}
+ /**
+ * Return whether support or not support cache
+ *
+ * @return true
+ */
function isSupport(){
return true;
}
+ /**
+ * Cache a variable in the data store
+ *
+ * @param string $key Store the variable using this name.
+ * @param mixed $obj The variable to store
+ * @param int $valid_time Not used
+ * @return void
+ */
function put($key, $obj, $valid_time = 0){
$cache_file = $this->getCacheFileName($key);
$text = serialize($obj);
FileHandler::writeFile($cache_file, $text);
}
+ /**
+ * Return whether cache is valid or invalid
+ *
+ * @param string $key Cache key
+ * @param int $modified_time Not used
+ * @return bool Return true on valid or false on invalid.
+ */
function isValid($key, $modified_time = 0) {
$cache_file = $this->getCacheFileName($key);
if(file_exists($cache_file)) return true;
@@ -43,6 +88,13 @@ class CacheFile extends CacheBase {
return false;
}
+ /**
+ * Fetch a stored variable from the cache
+ *
+ * @param string $key The $key used to store the value.
+ * @param int $modified_time Not used
+ * @return false|mixed Return false on failure. Return the string associated with the $key on success.
+ */
function get($key, $modified_time = 0) {
$cache_file = $this->getCacheFileName($key);
$content = FileHandler::readFile($cache_file);
@@ -51,15 +103,32 @@ class CacheFile extends CacheBase {
return unserialize($content);
}
+ /**
+ * Delete variable from the cache(private)
+ *
+ * @param string $_key Used to store the value.
+ * @return void
+ */
function _delete($_key) {
$cache_file = $this->getCacheFileName($_key);
FileHandler::removeFile($cache_file);
}
+ /**
+ * Delete variable from the cache
+ *
+ * @param string $key Used to store the value.
+ * @return void
+ */
function delete($key) {
$this->_delete($key);
}
+ /**
+ * Truncate all existing variables at the cache
+ *
+ * @return bool Returns true on success or false on failure.
+ */
function truncate() {
FileHandler::removeFilesInDir($this->cache_dir);
}
diff --git a/classes/cache/CacheHandler.class.php b/classes/cache/CacheHandler.class.php
index 90858635f..1fa0040ae 100644
--- a/classes/cache/CacheHandler.class.php
+++ b/classes/cache/CacheHandler.class.php
@@ -1,15 +1,30 @@
handler && $this->handler->isSupport()) return true;
return false;
}
+ /**
+ * Get cached data
+ *
+ * @param string $key Cache key
+ * @param int $modified_time Unix time of data modified.
+ * If stored time is older then modified time, return false.
+ * @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
+ */
function get($key, $modified_time = 0){
if(!$this->handler) return false;
return $this->handler->get($key, $modified_time);
}
+ /**
+ * Put data into cache
+ *
+ * @param string $key Cache key
+ * @param mixed $obj Value of a variable to store. $value supports all data types except resources, such as file handlers.
+ * @param int $valid_time Time for the variable to live in the cache in seconds.
+ * After the value specified in ttl has passed the stored variable will be deleted from the cache.
+ * If no ttl is supplied, use the default valid time.
+ * @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
+ */
function put($key, $obj, $valid_time = 0){
if(!$this->handler) return false;
return $this->handler->put($key, $obj, $valid_time);
}
+ /**
+ * Delete Cache
+ *
+ * @param string $key Cache key
+ * @return void
+ */
function delete($key){
if(!$this->handler) return false;
return $this->handler->delete($key);
}
+ /**
+ * Return whether cache is valid or invalid
+ *
+ * @param string $key Cache key
+ * @param int $modified_time Unix time of data modified.
+ * If stored time is older then modified time, the data is invalid.
+ * @return bool Return true on valid or false on invalid.
+ */
function isValid($key, $modified_time){
if(!$this->handler) return false;
return $this->handler->isValid($key, $modified_time);
}
+ /**
+ * Truncate all cache
+ *
+ * @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
+ */
function truncate(){
if(!$this->handler) return false;
return $this->handler->truncate();
@@ -91,6 +159,10 @@ class CacheHandler extends Handler {
*
* The new key will be 2:document:123, thus forcing the document
* to be reloaded from the database.
+ *
+ * @param string $keyGroupName Group name
+ * @param string $key Cache key
+ * @return string
*/
function getGroupKey($keyGroupName, $key){
if(!$this->keyGroupVersions[$keyGroupName]){
@@ -101,29 +173,77 @@ class CacheHandler extends Handler {
return $this->keyGroupVersions[$keyGroupName] . ':' . $keyGroupName . ':' . $key;
}
+ /**
+ * Make invalid group key (like delete group key)
+ *
+ * @param string $keyGroupName Group name
+ * @return void
+ */
function invalidateGroupKey($keyGroupName){
$this->keyGroupVersions[$keyGroupName]++;
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
}
}
+/**
+ * Base class of Cache
+ *
+ * @author NHN (developer@xpressengine.com)
+ */
class CacheBase{
+
+ /**
+ * Get cached data
+ *
+ * @param string $key Cache key
+ * @param int $modified_time Unix time of data modified.
+ * If stored time is older then modified time, return false.
+ * @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
+ */
function get($key, $modified_time = 0){
return false;
}
+ /**
+ * Put data into cache
+ *
+ * @param string $key Cache key
+ * @param mixed $obj Value of a variable to store. $value supports all data types except resources, such as file handlers.
+ * @param int $valid_time Time for the variable to live in the cache in seconds.
+ * After the value specified in ttl has passed the stored variable will be deleted from the cache.
+ * If no ttl is supplied, use the default valid time.
+ * @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
+ */
function put($key, $obj, $valid_time = 0){
return false;
}
+ /**
+ * Return whether cache is valid or invalid
+ *
+ * @param string $key Cache key
+ * @param int $modified_time Unix time of data modified.
+ * If stored time is older then modified time, the data is invalid.
+ * @return bool Return true on valid or false on invalid.
+ */
function isValid($key, $modified_time = 0){
return false;
}
+ /**
+ * Return whether support or not support cache
+ *
+ * @return boolean
+ */
function isSupport(){
return false;
}
+ /**
+ * Truncate all cache
+ *
+ * @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
+ */
function truncate(){
return false;
}
diff --git a/classes/cache/CacheMemcache.class.php b/classes/cache/CacheMemcache.class.php
index 1f07c88d4..17962a71c 100644
--- a/classes/cache/CacheMemcache.class.php
+++ b/classes/cache/CacheMemcache.class.php
@@ -1,15 +1,28 @@
Memcache->set('xe', 'xe', MEMCACHE_COMPRESSED, 1)) {
@@ -38,16 +63,47 @@ class CacheMemcache extends CacheBase {
return $GLOBALS['XE_MEMCACHE_SUPPORT'];
}
+ /**
+ * Get unique key of given key by path of XE
+ *
+ * @param string $key Cache key
+ * @return string Return unique key
+ */
function getKey($key){
return md5(_XE_PATH_.$key);
}
+ /**
+ * Store data at the server
+ *
+ * CacheMemcache::put() stores an item $buff with $key on the memcached server.
+ * Parameter $valid_time is expiration time in seconds. If it's 0, the item never expires
+ * (but memcached server doesn't guarantee this item to be stored all the time, it could be delete from the cache to make place for other items).
+ *
+ * Remember that resource variables (i.e. file and connection descriptors) cannot be stored in the cache,
+ * because they can not be adequately represented in serialized state.
+ *
+ * @param string $key The key that will be associated with the item.
+ * @param mixed $buff The variable to store. Strings and integers are stored as is, other types are stored serialized.
+ * @param int $valid_time Expiration time of the item.
+ * You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).
+ * If it's equal to zero, use the default valid time CacheMemcache::valid_time.
+ * @return bool Returns true on success or false on failure.
+ */
function put($key, $buff, $valid_time = 0){
if($valid_time == 0) $valid_time = $this->valid_time;
return $this->Memcache->set($this->getKey($key), array(time(), $buff), MEMCACHE_COMPRESSED, $valid_time);
}
+ /**
+ * Return whether cache is valid or invalid
+ *
+ * @param string $key Cache key
+ * @param int $modified_time Unix time of data modified.
+ * If stored time is older then modified time, the data is invalid.
+ * @return bool Return true on valid or false on invalid.
+ */
function isValid($key, $modified_time = 0) {
$_key = $this->getKey($key);
@@ -63,6 +119,16 @@ class CacheMemcache extends CacheBase {
return true;
}
+ /**
+ * Retrieve item from the server
+ *
+ * CacheMemcache::get() returns previously stored data if an item with such $key exists on the server at this moment.
+ *
+ * @param string $key The key to fetch
+ * @param int $modified_time Unix time of data modified.
+ * If stored time is older then modified time, return false.
+ * @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
+ */
function get($key, $modified_time = 0) {
$_key = $this->getKey($key);
$obj = $this->Memcache->get($_key);
@@ -78,15 +144,39 @@ class CacheMemcache extends CacheBase {
return $obj[1];
}
+ /**
+ * Delete item from the server
+ *
+ * CacheMemcache::delete() deletes an item with tey $key.
+ *
+ * @param string $key The key associated with the item to delete.
+ * @return void
+ */
function delete($key) {
$_key = $this->getKey($key);
$this->_delete($_key);
}
+ /**
+ * Delete item from the server(private)
+ *
+ * @see CacheMemcache::delete()
+ * @param string $_key The key associated with the item to delete.
+ * @return void
+ */
function _delete($_key) {
$this->Memcache->delete($_key);
}
+ /**
+ * Flush all existing items at the server
+ *
+ * CacheMemcache::truncate() immediately invalidates all existing items.
+ * CacheMemcache::truncate() doesn't actually free any resources, it only marks all the items as expired,
+ * so occupied memory will be overwitten by new items.
+ *
+ * @return bool Returns true on success or false on failure.
+ */
function truncate() {
return $this->Memcache->flush();
}
diff --git a/classes/cache/CacheWincache.class.php b/classes/cache/CacheWincache.class.php
index 36484164b..248e98932 100644
--- a/classes/cache/CacheWincache.class.php
+++ b/classes/cache/CacheWincache.class.php
@@ -1,14 +1,24 @@
valid_time;
return wincache_ucache_set(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time);
}
+ /**
+ * Return whether cache is valid or invalid
+ *
+ * @param string $key Cache key
+ * @param int $modified_time Unix time of data modified.
+ * If stored time is older then modified time, the data is invalid.
+ * @return bool Return true on valid or false on invalid.
+ */
function isValid($key, $modified_time = 0) {
$_key = md5(_XE_PATH_.$key);
$obj = wincache_ucache_get($_key, $success);
@@ -42,6 +81,14 @@ class CacheWincache extends CacheBase {
return true;
}
+ /**
+ * Gets a variable stored in the user cache
+ *
+ * @param string $key The $key that was used to store the variable in the cache.
+ * @param int $modified_time Unix time of data modified.
+ * If stored time is older then modified time, return false.
+ * @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
+ */
function get($key, $modified_time = 0) {
$_key = md5(_XE_PATH_.$key);
$obj = wincache_ucache_get($_key, $success);
@@ -55,15 +102,32 @@ class CacheWincache extends CacheBase {
return $obj[1];
}
+ /**
+ * Delete variable from the cache(private)
+ *
+ * @param string $_key Used to store the value.
+ * @return void
+ */
function _delete($_key) {
wincache_ucache_delete($_key);
}
+ /**
+ * Delete variable from the cache
+ *
+ * @param string $key Used to store the value.
+ * @return void
+ */
function delete($key) {
$_key = md5(_XE_PATH_.$key);
$this->_delete($_key);
}
+ /**
+ * Truncate all existing variables at the cache
+ *
+ * @return bool Returns true on success or false on failure.
+ */
function truncate() {
return wincache_ucache_clear();
}
diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php
index 8b0e70682..d3d5ccb44 100644
--- a/classes/context/Context.class.php
+++ b/classes/context/Context.class.php
@@ -362,7 +362,8 @@ class Context {
function checkSSO() {
// pass if it's not GET request or XE is not yet installed
if($this->db_info->use_sso != 'Y' || isCrawler()) return true;
- if(Context::getRequestMethod()!='GET' || !Context::isInstalled() || in_array(Context::get('act'),array('rss','atom'))) return true;
+ $checkActList = array('rss'=>1, 'atom'=>1);
+ if(Context::getRequestMethod()!='GET' || !Context::isInstalled() || isset($checkActList[Context::get('act')])) return true;
// pass if default URL is not set
$default_url = trim($this->db_info->default_url);
@@ -630,8 +631,8 @@ class Context {
function setResponseMethod($method='HTML') {
is_a($this,'Context')?$self=&$this:$self=&Context::getInstance();
- $methods = array('HTML','XMLRPC','JSON');
- $self->response_method = in_array($method, $methods)?$method:$methods[0];
+ $methods = array('HTML'=>1, 'XMLRPC'=>1, 'JSON'=>1);
+ $self->response_method = isset($methods[$method]) ? $method : 'HTML';
}
/*
@@ -644,9 +645,9 @@ class Context {
if($self->response_method) return $self->response_method;
$method = $self->getRequestMethod();
- $methods = array('HTML','XMLRPC','JSON');
+ $methods = array('HTML'=>1, 'XMLRPC'=>1, 'JSON'=>1);
- return in_array($method, $methods)?$method:$methods[0];
+ return isset($methods[$method]) ? $method : 'HTML';
}
/**
@@ -727,19 +728,42 @@ class Context {
* @return filtered value
**/
function _filterRequestVar($key, $val, $do_stripslashes = 1) {
- if( ($key == 'page' || $key == 'cpage' || substr($key,-3)=='srl')) return !preg_match('/^[0-9,]+$/',$val)?(int)$val:$val;
- if($key == 'mid' || $key == 'vid' || $key == 'search_keyword') return htmlspecialchars($val);
- if(is_array($val) && count($val) ) {
- foreach($val as $k => $v) {
- if($do_stripslashes && version_compare(PHP_VERSION, '5.9.0', '<') && get_magic_quotes_gpc()) $v = stripslashes($v);
- $v = trim($v);
- $val[$k] = $v;
- }
- } else {
- if($do_stripslashes && version_compare(PHP_VERSION, '5.9.0', '<') && get_magic_quotes_gpc()) $val = stripslashes($val);
- $val = trim($val);
+ $isArray = TRUE;
+ if(!is_array($val))
+ {
+ $isArray = FALSE;
+ $val = array($val);
+ }
+
+ foreach($val as $k => $v)
+ {
+ if($key === 'page' || $key === 'cpage' || substr($key, -3) === 'srl')
+ {
+ $val[$k] = !preg_match('/^[0-9,]+$/', $v) ? (int)$v : $v;
+ }
+ elseif($key === 'mid' || $key === 'vid' || $key === 'search_keyword')
+ {
+ $val[$k] = htmlspecialchars($v);
+ }
+ else
+ {
+ if($do_stripslashes && version_compare(PHP_VERSION, '5.9.0', '<') && get_magic_quotes_gpc())
+ {
+ $v = stripslashes($v);
+ }
+
+ $val[$k] = trim($v);
+ }
+ }
+
+ if($isArray)
+ {
+ return $val;
+ }
+ else
+ {
+ return $val[0];
}
- return $val;
}
/**
@@ -891,7 +915,8 @@ class Context {
$key = $get_vars['key'];
$srl = $get_vars['document_srl'];
- $is_feed = in_array($act, array('rss', 'atom', 'api'));
+ $tmpArray = array('rss'=>1, 'atom'=>1, 'api'=>1);
+ $is_feed = isset($tmpArray[$act]);
$target_map = array(
'vid'=>$vid,
diff --git a/classes/db/DB.class.php b/classes/db/DB.class.php
index 7b3a1b864..d339947a1 100644
--- a/classes/db/DB.class.php
+++ b/classes/db/DB.class.php
@@ -1,18 +1,4 @@
'=',
'more' => '>=',
'excess' => '>',
@@ -60,35 +66,84 @@
'null' => 'is null',
);
- var $master_db = NULL; // master database connection string
- var $slave_db = NULL; // array of slave databases connection strings
+ /**
+ * master database connection string
+ * @var array
+ */
+ var $master_db = NULL;
+ /**
+ * array of slave databases connection strings
+ * @var array
+ */
+ var $slave_db = NULL;
- var $result = NULL; ///< result
+ var $result = NULL;
- var $errno = 0; ///< error code (0 means no error)
- var $errstr = ''; ///< error message
- var $query = ''; ///< query string of latest executed query
+ /**
+ * error code (0 means no error)
+ * @var int
+ */
+ var $errno = 0;
+ /**
+ * error message
+ * @var string
+ */
+ var $errstr = '';
+ /**
+ * query string of latest executed query
+ * @var string
+ */
+ var $query = '';
var $connection = '';
- var $elapsed_time = 0; ///< elapsed time of latest executed query
- var $elapsed_dbclass_time = 0; ///< elapsed time of latest executed query
+ /**
+ * elapsed time of latest executed query
+ * @var int
+ */
+ var $elapsed_time = 0;
+ /**
+ * elapsed time of latest executed DB class
+ * @var int
+ */
+ var $elapsed_dbclass_time = 0;
- var $transaction_started = false; ///< transaction flag
+ /**
+ * transaction flag
+ * @var boolean
+ */
+ var $transaction_started = false;
- var $is_connected = false; ///< is db connected
+ var $is_connected = false;
- var $supported_list = array(); ///< list of supported db, (will be written by classes/DB/DB***.class.php)
+ /**
+ * returns enable list in supported dbms list
+ * will be written by classes/DB/DB***.class.php
+ * @var array
+ */
+ var $supported_list = array();
- var $cache_file = 'files/cache/queries/'; ///< location of query cache
+ /**
+ * location of query cache
+ * @var string
+ */
+ var $cache_file = 'files/cache/queries/';
- var $db_type; ///< stores database type: 'mysql','cubrid','mssql' etc. or 'db' when database is not yet set
+ /**
+ * stores database type: 'mysql','cubrid','mssql' etc. or 'db' when database is not yet set
+ * @var string
+ */
+ var $db_type;
- var $use_prepared_statements; ///< flag to decide if class prepared statements or not (when supported); can be changed from db.config.info
+ /**
+ * flag to decide if class prepared statements or not (when supported); can be changed from db.config.info
+ * @var string
+ */
+ var $use_prepared_statements;
- /**
- * @brief returns instance of certain db type
- * @param[in] $db_type type of db
- * @return instance
- **/
+ /**
+ * returns instance of certain db type
+ * @param string $db_type type of db
+ * @return DB return DB object instance
+ */
function &getInstance($db_type = NULL) {
if(!$db_type) $db_type = Context::getDBType();
if(!$db_type && Context::isInstalled()) return new Object(-1, 'msg_db_not_setted');
@@ -108,32 +163,39 @@
return $GLOBALS['__DB__'][$db_type];
}
+ /**
+ * returns instance of db
+ * @return DB return DB object instance
+ */
function create() {
return new DB;
}
/**
- * @brief constructor
- * @return none
- **/
+ * constructor
+ * @return void
+ */
function DB() {
$this->count_cache_path = _XE_PATH_.$this->count_cache_path;
$this->cache_file = _XE_PATH_.$this->cache_file;
}
/**
- * @brief returns list of supported db
- * @return list of supported db
- **/
+ * returns list of supported dbms list
+ * this list return by directory list
+ * check by instance can creatable
+ * @return array return supported DBMS list
+ */
function getSupportedList() {
$oDB = new DB();
return $oDB->_getSupportedList();
}
/**
- * @brief returns list of enable in supported db
- * @return list of enable in supported db
- **/
+ * returns enable list in supported dbms list
+ * this list return by child class
+ * @return array return enable DBMS list in supported dbms list
+ */
function getEnableList()
{
if(!$this->supported_list)
@@ -152,9 +214,10 @@
}
/**
- * @brief returns list of disable in supported db
- * @return list of disable in supported db
- **/
+ * returns list of disable in supported dbms list
+ * this list return by child class
+ * @return array return disable DBMS list in supported dbms list
+ */
function getDisableList()
{
if(!$this->supported_list)
@@ -173,10 +236,17 @@
}
/**
- * @brief returns list of supported db
- * @return list of supported db
- **/
+ * returns list of supported dbms list
+ * this method is private
+ * @return array return supported DBMS list
+ */
function _getSupportedList() {
+ static $get_supported_list = '';
+ if(is_array($get_supported_list)) {
+ $this->supported_list = $get_supported_list;
+ return $this->supported_list;
+ }
+ $get_supported_list = array();
$db_classes_path = _XE_PATH_."classes/db/";
$filter = "/^DB([^\.]+)\.class\.php/i";
$supported_list = FileHandler::readDir($db_classes_path, $filter, true);
@@ -203,34 +273,37 @@
$obj->db_type = $db_type;
$obj->enable = $oDB->isSupported() ? true : false;
- $this->supported_list[] = $obj;
+ $get_supported_list[] = $obj;
}
-
+ $this->supported_list = $get_supported_list;
return $this->supported_list;
}
/**
- * @brief check if the db_type is supported
- * @param[in] $db_type type of db to check
- * @return true: is supported, false: is not supported
- **/
+ * Return dbms supportable status
+ * The value is set in the child class
+ * @return boolean true: is supported, false: is not supported
+ */
function isSupported() {
return FALSE;
}
/**
- * @brief check if is connected
- * @return true: connected, false: not connected
- **/
+ * Return connected status
+ * @param string $type master or slave
+ * @param int $indx key of server list
+ * @return boolean true: connected, false: not connected
+ */
function isConnected($type = 'master', $indx = 0) {
if($type == 'master') return $this->master_db["is_connected"] ? true : false;
else return $this->slave_db[$indx]["is_connected"] ? true : false;
}
/**
- * @brief start recording log
- * @return none
- **/
+ * start recording log
+ * @param string $query query string
+ * @return void
+ */
function actStart($query) {
$this->setError(0, 'success');
$this->query = $query;
@@ -239,9 +312,9 @@
}
/**
- * @brief finish recording log
- * @return none
- **/
+ * finish recording log
+ * @return void
+ */
function actFinish() {
if(!$this->query) return;
$this->act_finish = getMicroTime();
@@ -297,41 +370,43 @@
}
/**
- * @brief set error
- * @param[in] $errno error code
- * @param[in] $errstr error message
- * @return none
- **/
+ * set error
+ * @param int $errno error code
+ * @param string $errstr error message
+ * @return void
+ */
function setError($errno = 0, $errstr = 'success') {
$this->errno = $errno;
$this->errstr = $errstr;
}
/**
- * @brief check if an error occured
- * @return true: error, false: no error
- **/
+ * Return error status
+ * @return boolean true: error, false: no error
+ */
function isError() {
return $this->errno === 0 ? false : true;
}
/**
- * @brief returns object of error info
- * @return object of error
- **/
+ * Returns object of error info
+ * @return object object of error
+ */
function getError() {
$this->errstr = Context::convertEncodingStr($this->errstr);
return new Object($this->errno, $this->errstr);
}
/**
- * @brief Run the result of the query xml file
- * @param[in] $query_id query id (module.queryname
- * @param[in] $args arguments for query
- * @return result of query
- * @remarks this function finds xml file or cache file of $query_id, compiles it and then execute it
- **/
+ * Execute Query that result of the query xml file
+ * This function finds xml file or cache file of $query_id, compiles it and then execute it
+ * @param string $query_id query id (module.queryname)
+ * @param array|object $args arguments for query
+ * @param array $arg_columns column list. if you want get specific colums from executed result, add column list to $arg_columns
+ * @return object result of query
+ */
function executeQuery($query_id, $args = NULL, $arg_columns = NULL) {
+ static $cache_file = array();
if(!$query_id) return new Object(-1, 'msg_invalid_queryid');
if(!$this->db_type) return;
@@ -339,49 +414,51 @@
$this->query_id = $query_id;
- $id_args = explode('.', $query_id);
- if(count($id_args) == 2) {
- $target = 'modules';
- $module = $id_args[0];
- $id = $id_args[1];
- } elseif(count($id_args) == 3) {
- $target = $id_args[0];
- if(!in_array($target, array('addons','widgets'))){
- $this->actDBClassFinish();
- return;
- }
- $module = $id_args[1];
- $id = $id_args[2];
- }
- if(!$target || !$module || !$id){
- $this->actDBClassFinish();
- return new Object(-1, 'msg_invalid_queryid');
- }
+ if(!isset($cache_file[$query_id])) {
+ $id_args = explode('.', $query_id);
+ if(count($id_args) == 2) {
+ $target = 'modules';
+ $module = $id_args[0];
+ $id = $id_args[1];
+ } elseif(count($id_args) == 3) {
+ $target = $id_args[0];
+ $typeList = array('addons'=>1, 'widgets'=>1);
+ if(!isset($typeList[$target])){
+ $this->actDBClassFinish();
+ return;
+ }
+ $module = $id_args[1];
+ $id = $id_args[2];
+ }
+ if(!$target || !$module || !$id){
+ $this->actDBClassFinish();
+ return new Object(-1, 'msg_invalid_queryid');
+ }
- $xml_file = sprintf('%s%s/%s/queries/%s.xml', _XE_PATH_, $target, $module, $id);
- if(!file_exists($xml_file)){
- $this->actDBClassFinish();
- return new Object(-1, 'msg_invalid_queryid');
- }
+ $xml_file = sprintf('%s%s/%s/queries/%s.xml', _XE_PATH_, $target, $module, $id);
+ if(!file_exists($xml_file)){
+ $this->actDBClassFinish();
+ return new Object(-1, 'msg_invalid_queryid');
+ }
- // look for cache file
- $cache_file = $this->checkQueryCacheFile($query_id, $xml_file);
- $result = $this->_executeQuery($cache_file, $args, $query_id, $arg_columns);
+ // look for cache file
+ $cache_file[$query_id] = $this->checkQueryCacheFile($query_id, $xml_file);
+ }
+ $result = $this->_executeQuery($cache_file[$query_id], $args, $query_id, $arg_columns);
- $this->actDBClassFinish();
- // execute query
- return $result;
+ $this->actDBClassFinish();
+ // execute query
+ return $result;
}
/**
- * @brief look for cache file
- * @param[in] $query_id query id for finding
- * @param[in] $xml_file original xml query file
- * @return cache file
- **/
+ * Look for query cache file
+ * @param string $query_id query id for finding
+ * @param string $xml_file original xml query file
+ * @return string cache file
+ */
function checkQueryCacheFile($query_id,$xml_file){
-
// first try finding cache file
$cache_file = sprintf('%s%s%s.%s.%s.cache.php', _XE_PATH_, $this->cache_file, $query_id, __ZBXE_VERSION__, $this->db_type);
@@ -400,12 +477,13 @@
/**
- * @brief execute query and return the result
- * @param[in] $cache_file cache file of query
- * @param[in] $source_args arguments for query
- * @param[in] $query_id query id
- * @return result of query
- **/
+ * Execute query and return the result
+ * @param string $cache_file cache file of query
+ * @param array|object $source_args arguments for query
+ * @param string $query_id query id
+ * @param array $arg_columns column list. if you want get specific colums from executed result, add column list to $arg_columns
+ * @return object result of query
+ */
function _executeQuery($cache_file, $source_args, $query_id, $arg_columns) {
global $lang;
@@ -420,6 +498,7 @@
// execute appropriate query
switch($output->getAction()) {
case 'insert' :
+ case 'insert-select' :
$this->resetCountCache($output->tables);
$output = $this->_executeInsertAct($output);
break;
@@ -449,11 +528,11 @@
/**
- * @brief returns counter cache data
- * @param[in] $tables tables to get data
- * @param[in] $condition condition to get data
- * @return count of cache data
- **/
+ * Returns counter cache data
+ * @param array|string $tables tables to get data
+ * @param string $condition condition to get data
+ * @return int count of cache data
+ */
function getCountCache($tables, $condition) {
return false;
if(!$tables) return false;
@@ -483,12 +562,12 @@
}
/**
- * @brief save counter cache data
- * @param[in] $tables tables to save data
- * @param[in] $condition condition to save data
- * @param[in] $count count of cache data to save
- * @return none
- **/
+ * Save counter cache data
+ * @param array|string $tables tables to save data
+ * @param string $condition condition to save data
+ * @param int $count count of cache data to save
+ * @return void
+ */
function putCountCache($tables, $condition, $count = 0) {
return false;
if(!$tables) return false;
@@ -508,10 +587,10 @@
}
/**
- * @brief reset counter cache data
- * @param[in] $tables tables to reset cache data
- * @return true: success, false: failed
- **/
+ * Reset counter cache data
+ * @param array|string $tables tables to reset cache data
+ * @return boolean true: success, false: failed
+ */
function resetCountCache($tables) {
return false;
if(!$tables) return false;
@@ -528,9 +607,9 @@
}
/**
- * @brief returns supported database list
- * @return list of supported database
- **/
+ * Returns supported database list
+ * @return array list of supported database
+ */
function getSupportedDatabase(){
$result = array();
@@ -545,12 +624,23 @@
return $result;
}
+ /**
+ * Drop tables
+ * @param string $table_name
+ * @return void
+ */
function dropTable($table_name){
if(!$table_name) return;
$query = sprintf("drop table %s%s", $this->prefix, $table_name);
$this->_query($query);
}
+ /**
+ * Return select query string
+ * @param object $query
+ * @param boolean $with_values
+ * @return string
+ */
function getSelectSql($query, $with_values = true){
$select = $query->getSelectString($with_values);
if($select == '') return new Object(-1, "Invalid query");
@@ -585,6 +675,13 @@
return $select . ' ' . $from . ' ' . $where . ' ' . $index_hint_list . ' ' . $groupBy . ' ' . $orderBy . ' ' . $limit;
}
+ /**
+ * Return delete query string
+ * @param object $query
+ * @param boolean $with_values
+ * @param boolean $with_priority
+ * @return string
+ */
function getDeleteSql($query, $with_values = true, $with_priority = false){
$sql = 'DELETE ';
@@ -603,6 +700,13 @@
return $sql;
}
+ /**
+ * Return update query string
+ * @param object $query
+ * @param boolean $with_values
+ * @param boolean $with_priority
+ * @return string
+ */
function getUpdateSql($query, $with_values = true, $with_priority = false){
$columnsList = $query->getUpdateString($with_values);
if($columnsList == '') return new Object(-1, "Invalid query");
@@ -618,6 +722,13 @@
return "UPDATE $priority $tables SET $columnsList ".$where;
}
+ /**
+ * Return insert query string
+ * @param object $query
+ * @param boolean $with_values
+ * @param boolean $with_priority
+ * @return string
+ */
function getInsertSql($query, $with_values = true, $with_priority = false){
$tableName = $query->getFirstTableName();
$values = $query->getInsertString($with_values);
@@ -626,12 +737,22 @@
return "INSERT $priority INTO $tableName \n $values";
}
+ /**
+ * Return index from slave server list
+ * @return int
+ */
function _getSlaveConnectionStringIndex() {
$max = count($this->slave_db);
$indx = rand(0, $max - 1);
return $indx;
}
+ /**
+ * Return connection resource
+ * @param string $type use 'master' or 'slave'. default value is 'master'
+ * @param int $indx if indx value is NULL, return rand number in slave server list
+ * @return resource
+ */
function _getConnection($type = 'master', $indx = NULL){
if($type == 'master'){
if(!$this->master_db['is_connected'])
@@ -650,6 +771,10 @@
return $this->slave_db[$indx]["resource"];
}
+ /**
+ * check db information exists
+ * @return boolean
+ */
function _dbInfoExists() {
if (!$this->master_db)
return false;
@@ -658,13 +783,22 @@
return true;
}
+ /**
+ * DB disconnection
+ * this method is protected
+ * @param resource $connection
+ * @return void
+ */
function _close($connection){
}
- /**
- * @brief DB disconnection
- * */
+ /**
+ * DB disconnection
+ * @param string $type 'master' or 'slave'
+ * @param int $indx number in slave dbms server list
+ * @return void
+ */
function close($type = 'master', $indx = 0) {
if (!$this->isConnected($type, $indx))
return;
@@ -679,12 +813,19 @@
$connection["is_connected"] = false;
}
+ /**
+ * DB transaction start
+ * this method is protected
+ * @return boolean
+ */
function _begin(){
return true;
}
- /**
- * @brief Begin transaction
- * */
+
+ /**
+ * DB transaction start
+ * @return void
+ */
function begin() {
if (!$this->isConnected() || $this->transaction_started)
return;
@@ -693,13 +834,19 @@
$this->transaction_started = true;
}
+ /**
+ * DB transaction rollback
+ * this method is protected
+ * @return boolean
+ */
function _rollback(){
return true;
}
- /**
- * @brief Rollback
- * */
+ /**
+ * DB transaction rollback
+ * @return void
+ */
function rollback() {
if (!$this->isConnected() || !$this->transaction_started)
return;
@@ -707,12 +854,20 @@
$this->transaction_started = false;
}
+ /**
+ * DB transaction commit
+ * this method is protected
+ * @return boolean
+ */
function _commit(){
return true;
}
- /**
- * @brief Commits
- * */
+
+ /**
+ * DB transaction commit
+ * @param boolean $force regardless transaction start status or connect status, forced to commit
+ * @return void
+ */
function commit($force = false) {
if (!$force && (!$this->isConnected() || !$this->transaction_started))
return;
@@ -720,18 +875,24 @@
$this->transaction_started = false;
}
+ /**
+ * Execute the query
+ * this method is protected
+ * @param string $query
+ * @param resource $connection
+ * @return void
+ */
function __query($query, $connection){
}
- /**
- * @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
- * */
+
+ /**
+ * Execute the query
+ * this method is protected
+ * @param string $query
+ * @param resource $connection
+ * @return resource
+ */
function _query($query, $connection = null) {
if($connection == null)
$connection = $this->_getConnection('master');
@@ -747,9 +908,11 @@
return $result;
}
- /**
- * @brief DB settings and connect/close
- * */
+ /**
+ * DB info settings
+ * this method is protected
+ * @return void
+ */
function _setDBInfo(){
$db_info = Context::getDBInfo();
$this->master_db = $db_info->master_db;
@@ -766,16 +929,33 @@
$this->use_prepared_statements = $db_info->use_prepared_statements;
}
+ /**
+ * DB Connect
+ * this method is protected
+ * @param array $connection
+ * @return void
+ */
function __connect($connection){
}
+ /**
+ * If have a task after connection, add a taks in this method
+ * this method is protected
+ * @param resource $connection
+ * @return void
+ */
function _afterConnect($connection){
}
- /**
- * @brief DB Connection
- * */
+
+ /**
+ * DB Connect
+ * this method is protected
+ * @param string $type 'master' or 'slave'
+ * @param int $indx number in slave dbms server list
+ * @return void
+ */
function _connect($type = 'master', $indx = 0) {
if ($this->isConnected($type, $indx))
return;
@@ -804,20 +984,21 @@
$this->_afterConnect($result);
}
- /**
- * @brief start recording DBClass log
- * @return none
- **/
+
+ /**
+ * Start recording DBClass log
+ * @return void
+ */
function actDBClassStart() {
$this->setError(0, 'success');
$this->act_dbclass_start = getMicroTime();
$this->elapsed_dbclass_time = 0;
}
- /**
- * @brief finish recording DBClass log
- * @return none
- **/
+ /**
+ * Finish recording DBClass log
+ * @return void
+ */
function actDBClassFinish() {
if(!$this->query) return;
$this->act_dbclass_finish = getMicroTime();
@@ -826,14 +1007,16 @@
$GLOBALS['__dbclass_elapsed_time__'] += $elapsed_dbclass_time;
}
- /**
- * Returns a database specific parser class
- * used for escaping expressions and table/column identifiers
- *
- * Requires an implementation of the DB class (won't work if database is not set)
- *
- * @remarks singleton
- */
+ /**
+ * Returns a database specific parser instance
+ * used for escaping expressions and table/column identifiers
+ *
+ * Requires an implementation of the DB class (won't work if database is not set)
+ * this method is singleton
+ *
+ * @param boolean $force force load DBParser instance
+ * @return DBParser
+ */
function &getParser($force = false){
static $dbParser = null;
if(!$dbParser || $force) {
diff --git a/classes/db/DBCubrid.class.php b/classes/db/DBCubrid.class.php
index a40ef697c..48d14cd69 100644
--- a/classes/db/DBCubrid.class.php
+++ b/classes/db/DBCubrid.class.php
@@ -1,28 +1,34 @@
'numeric(20)',
@@ -37,8 +43,9 @@
);
/**
- * @brief constructor
- **/
+ * constructor
+ * @return void
+ */
function DBCubrid()
{
$this->_setDBInfo();
@@ -46,7 +53,8 @@
}
/**
- * @brief create an instance of this class
+ * Create an instance of this class
+ * @return DBCubrid return DBCubrid object instance
*/
function create()
{
@@ -54,8 +62,10 @@
}
/**
- * @brief Return if installable
- **/
+ * Return if supportable
+ * Check 'cubrid_connect' function exists.
+ * @return boolean
+ */
function isSupported()
{
if (!function_exists('cubrid_connect')) return false;
@@ -63,8 +73,11 @@
}
/**
- * @brief DB Connection
- **/
+ * DB Connect
+ * this method is private
+ * @param array $connection connection's value is db_hostname, db_port, db_database, db_userid, db_password
+ * @return resource
+ */
function __connect($connection)
{
// attempts to connect
@@ -90,8 +103,11 @@
}
/**
- * @brief DB disconnect
- **/
+ * DB disconnection
+ * this method is private
+ * @param resource $connection
+ * @return void
+ */
function _close($connection)
{
@cubrid_commit ($connection);
@@ -100,8 +116,10 @@
}
/**
- * @brief handles quatation of the string variables from the query
- **/
+ * Handles quatation of the string variables from the query
+ * @param string $string
+ * @return string
+ */
function addQuotes($string)
{
if (version_compare (PHP_VERSION, "5.9.0", "<") &&
@@ -126,8 +144,10 @@
}
/**
- * @brief Begin transaction
- **/
+ * DB transaction start
+ * this method is private
+ * @return boolean
+ */
function _begin()
{
if(__CUBRID_VERSION__ >= '8.4.0')
@@ -139,8 +159,10 @@
}
/**
- * @brief Rollback
- **/
+ * DB transaction rollback
+ * this method is private
+ * @return boolean
+ */
function _rollback()
{
$connection = $this->_getConnection('master');
@@ -149,8 +171,10 @@
}
/**
- * @brief Commit
- **/
+ * DB transaction commit
+ * this method is private
+ * @return boolean
+ */
function _commit()
{
$connection = $this->_getConnection('master');
@@ -159,14 +183,12 @@
}
/**
- * @brief : executing the query and fetching the result
- *
- * query: run a query and return the result\n
- * fetch: NULL if no value returned \n
- * array object if rows returned \n
- * object if a row returned \n
- * return\n
- **/
+ * Execute the query
+ * this method is private
+ * @param string $query
+ * @param resource $connection
+ * @return resource
+ */
function __query($query, $connection)
{
if($this->use_prepared_statements == 'Y')
@@ -232,8 +254,11 @@
}
/**
- * @brief Fetch the result
- **/
+ * Fetch the result
+ * @param resource $result
+ * @param int|NULL $arrayIndexEndValue
+ * @return array
+ */
function _fetch($result, $arrayIndexEndValue = NULL)
{
$output = array();
@@ -281,8 +306,10 @@
}
/**
- * @brief return the sequence value incremented by 1(auto_increment column only used in the CUBRID sequence table)
- **/
+ * Return the sequence value incremented by 1
+ * Auto_increment column only used in the CUBRID sequence table
+ * @return int
+ */
function getNextSequence()
{
$this->_makeSequence();
@@ -295,8 +322,9 @@
}
/**
- * @brief return if the table already exists
- **/
+ * if the table already exists, set the status to GLOBALS
+ * @return void
+ */
function _makeSequence()
{
if($_GLOBALS['XE_EXISTS_SEQUENCE']) return;
@@ -337,8 +365,10 @@
/**
- * brief return a table if exists
- **/
+ * Check a table exists status
+ * @param string $target_name
+ * @return boolean
+ */
function isTableExists ($target_name)
{
if($target_name == 'sequence') {
@@ -362,8 +392,15 @@
}
/**
- * @brief add a column to the table
- **/
+ * Add a column to the table
+ * @param string $table_name table name
+ * @param string $column_name column name
+ * @param string $type column type, default value is 'number'
+ * @param int $size column size
+ * @param string|int $default default value
+ * @param boolean $notnull not null status, default value is false
+ * @return void
+ */
function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = '', $notnull = false)
{
$type = strtoupper($this->column_type[$type]);
@@ -397,8 +434,11 @@
}
/**
- * @brief drop a column from the table
- **/
+ * Drop a column from the table
+ * @param string $table_name table name
+ * @param string $column_name column name
+ * @return void
+ */
function dropColumn ($table_name, $column_name)
{
$query = sprintf ("alter class \"%s%s\" drop \"%s\" ", $this->prefix, $table_name, $column_name);
@@ -407,8 +447,11 @@
}
/**
- * @brief return column information of the table
- **/
+ * Check column exist status of the table
+ * @param string $table_name table name
+ * @param string $column_name column name
+ * @return boolean
+ */
function isColumnExists ($table_name, $column_name)
{
$query = sprintf ("select \"attr_name\" from \"db_attribute\" where ". "\"attr_name\" ='%s' and \"class_name\" = '%s%s'", $column_name, $this->prefix, $table_name);
@@ -423,10 +466,15 @@
}
/**
- * @brief add an index to the table
+ * Add an index to the table
* $target_columns = array(col1, col2)
* $is_unique? unique : none
- **/
+ * @param string $table_name table name
+ * @param string $index_name index name
+ * @param string|array $target_columns target column or columns
+ * @param boolean $is_unique
+ * @return void
+ */
function addIndex ($table_name, $index_name, $target_columns, $is_unique = false)
{
if (!is_array ($target_columns)) {
@@ -439,8 +487,12 @@
}
/**
- * @brief drop an index from the table
- **/
+ * Drop an index from the table
+ * @param string $table_name table name
+ * @param string $index_name index name
+ * @param boolean $is_unique
+ * @return void
+ */
function dropIndex ($table_name, $index_name, $is_unique = false)
{
$query = sprintf ("drop %s index \"%s\" on \"%s%s\"", $is_unique?'unique':'', $this->prefix .$index_name, $this->prefix, $table_name);
@@ -449,8 +501,11 @@
}
/**
- * @brief return index information of the table
- **/
+ * Check index status of the table
+ * @param string $table_name table name
+ * @param string $index_name index name
+ * @return boolean
+ */
function isIndexExists ($table_name, $index_name)
{
$query = sprintf ("select \"index_name\" from \"db_index\" where ". "\"class_name\" = '%s%s' and \"index_name\" = '%s' ", $this->prefix, $table_name, $this->prefix .$index_name);
@@ -464,6 +519,10 @@
return true;
}
+ /**
+ * Delete duplicated index of the table
+ * @return boolean
+ */
function deleteDuplicateIndexes()
{
$query = sprintf("
@@ -507,16 +566,20 @@
}
/**
- * @brief creates a table by using xml file
- **/
+ * Creates a table by using xml contents
+ * @param string $xml_doc xml schema contents
+ * @return void|object
+ */
function createTableByXml ($xml_doc)
{
return $this->_createTable ($xml_doc);
}
/**
- * @brief creates a table by using xml file
- **/
+ * Creates a table by using xml file path
+ * @param string $file_name xml schema file path
+ * @return void|object
+ */
function createTableByXmlFile ($file_name)
{
if (!file_exists ($file_name)) return;
@@ -526,12 +589,14 @@
}
/**
- * @brief create table by using the schema xml
+ * Create table by using the schema xml
*
* type : number, varchar, tinytext, text, bigtext, char, date, \n
* opt : notnull, default, size\n
* index : primary key, index, unique\n
- **/
+ * @param string $xml_doc xml schema contents
+ * @return void|object
+ */
function _createTable ($xml_doc)
{
// xml parsing
@@ -645,8 +710,11 @@
/**
- * @brief handles insertAct
- **/
+ * Handles insertAct
+ * @param Object $queryObject
+ * @param boolean $with_values
+ * @return resource
+ */
function _executeInsertAct($queryObject, $with_values = true)
{
if($this->use_prepared_statements == 'Y')
@@ -668,8 +736,11 @@
}
/**
- * @brief handles updateAct
- **/
+ * Handles updateAct
+ * @param Object $queryObject
+ * @param boolean $with_values
+ * @return resource
+ */
function _executeUpdateAct($queryObject, $with_values = true)
{
if($this->use_prepared_statements == 'Y')
@@ -689,8 +760,11 @@
/**
- * @brief handles deleteAct
- **/
+ * Handles deleteAct
+ * @param Object $queryObject
+ * @param boolean $with_values
+ * @return resource
+ */
function _executeDeleteAct($queryObject, $with_values = true)
{
if($this->use_prepared_statements == 'Y')
@@ -710,11 +784,14 @@
}
/**
- * @brief Handle selectAct
- *
- * to get a specific page list easily in select statement,\n
+ * Handle selectAct
+ * To get a specific page list easily in select statement,
* a method, navigation, is used
- **/
+ * @param Object $queryObject
+ * @param resource $connection
+ * @param boolean $with_values
+ * @return Object
+ */
function _executeSelectAct($queryObject, $connection = null, $with_values = true) {
if ($this->use_prepared_statements == 'Y') {
$this->param = $queryObject->getArguments();
@@ -745,6 +822,11 @@
}
}
+ /**
+ * If have a error, return error object
+ * @param Object $queryObject
+ * @return Object
+ */
function queryError($queryObject){
$limit = $queryObject->getLimit();
if ($limit && $limit->isPageHandler()){
@@ -759,6 +841,13 @@
return;
}
+ /**
+ * If select query execute, return page info
+ * @param Object $queryObject
+ * @param resource $connection
+ * @param boolean $with_values
+ * @return Object Object with page info containing
+ */
function queryPageLimit($queryObject, $connection, $with_values){
$limit = $queryObject->getLimit();
// Total count
@@ -834,11 +923,23 @@
return $buff;
}
- function &getParser($force = FALSE){
- $dbParser = new DBParser('"', '"', $this->prefix);
- return $dbParser;
+ /**
+ * Return the DBParser
+ * @param boolean $force
+ * @return DBParser
+ */
+ function getParser($force = FALSE){
+ return new DBParser('"', '"', $this->prefix);
}
+ /**
+ * If select query execute, return paging sql
+ * @param object $query
+ * @param boolean $with_values
+ * @param int $start_count
+ * @param int $list_count
+ * @return string select paging sql
+ */
function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0) {
$select = $query->getSelectString($with_values);
diff --git a/classes/db/DBMssql.class.php b/classes/db/DBMssql.class.php
index 520e134a9..fe709a177 100644
--- a/classes/db/DBMssql.class.php
+++ b/classes/db/DBMssql.class.php
@@ -1,27 +1,30 @@
'bigint',
'number' => 'int',
@@ -34,32 +37,39 @@
);
/**
- * @brief constructor
- **/
+ * Constructor
+ * @return void
+ */
function DBMssql() {
$this->_setDBInfo();
$this->_connect();
}
/**
- * @brief create an instance of this class
+ * Create an instance of this class
+ * @return DBMssql return DBMssql object instance
*/
function create()
{
return new DBMssql;
}
- /**
- * @brief Return if installable
- **/
+ /**
+ * Return if supportable
+ * Check 'sqlsrv' extension loaded.
+ * @return boolean
+ */
function isSupported() {
if (!extension_loaded("sqlsrv")) return false;
return true;
}
- /**
- * @brief DB Connection
- **/
+ /**
+ * DB Connect
+ * this method is private
+ * @param array $connection connection's value is db_hostname, db_database, db_userid, db_password
+ * @return resource
+ */
function __connect($connection) {
//sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
//sqlsrv_configure( 'LogSeverity', SQLSRV_LOG_SEVERITY_ALL );
@@ -75,18 +85,23 @@
return $result;
}
- /**
- * @brief DB disconnect
- **/
+ /**
+ * DB disconnection
+ * this method is private
+ * @param resource $connection
+ * @return void
+ */
function _close($connection) {
$this->commit();
sqlsrv_close($connection);
}
- /**
- * @brief handles quatation of the string variables from the query
- **/
- // TODO See what to do about this
+ /**
+ * Handles quatation of the string variables from the query
+ * @todo See what to do about this
+ * @param string $string
+ * @return string
+ */
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);
@@ -94,42 +109,46 @@
return $string;
}
- /**
- * @brief Begin transaction
- **/
+ /**
+ * DB transaction start
+ * this method is private
+ * @return boolean
+ */
function _begin() {
$connection = $this->_getConnection('master');
if(sqlsrv_begin_transaction($connection) === false) return;
return true;
}
- /**
- * @brief Rollback
- **/
+ /**
+ * DB transaction rollback
+ * this method is private
+ * @return boolean
+ */
function _rollback() {
$connection = $this->_getConnection('master');
sqlsrv_rollback($connection);
return true;
}
- /**
- * @brief Commit
- **/
+ /**
+ * DB transaction commit
+ * this method is private
+ * @return boolean
+ */
function _commit() {
$connection = $this->_getConnection('master');
sqlsrv_commit($connection);
return true;
}
- /**
- * @brief : executing the query and fetching the result
- *
- * query: run a query and return the result\n
- * fetch: NULL if no value returned \n
- * array object if rows returned \n
- * object if a row returned \n
- * return\n
- **/
+ /**
+ * Execute the query
+ * this method is private
+ * @param string $query
+ * @param resource $connection
+ * @return resource|boolean Returns a statement resource on success and FALSE if an error occurred.
+ */
function __query($query, $connection) {
$_param = array();
@@ -183,6 +202,8 @@
* Parameters are sent as an array, where each parameter can be:
* - a PHP variable (by reference)
* - a PHP array (containng param value, type and direction) -> also needs to be sent by reference
+ * @param array $_param
+ * @return array
*/
function _getParametersByReference($_param)
{
@@ -206,9 +227,12 @@
return $args;
}
- /**
- * @brief Fetch results
- **/
+ /**
+ * Fetch results
+ * @param resource $result
+ * @param int|NULL $arrayIndexEndValue
+ * @return array
+ */
function _fetch($result, $arrayIndexEndValue = NULL) {
$output = array();
if(!$this->isConnected() || $this->isError() || !$result) return $output;
@@ -234,9 +258,11 @@
}
- /**
- * @brief Return sequence value incremented by 1(auto_increment is usd in the sequence table only)
- **/
+ /**
+ * Return the sequence value incremented by 1
+ * Auto_increment column only used in the sequence table
+ * @return int
+ */
function getNextSequence() {
$query = sprintf("insert into %ssequence (seq) values (ident_incr('%ssequence'))", $this->prefix, $this->prefix);
$this->_query($query);
@@ -249,9 +275,11 @@
return $tmp->sequence;
}
- /**
- * @brief Return if a table already exists
- **/
+ /**
+ * Check a table exists status
+ * @param string $target_name
+ * @return boolean
+ */
function isTableExists($target_name) {
$query = sprintf("select name from sysobjects where name = '%s%s' and xtype='U'", $this->prefix, $this->addQuotes($target_name));
$result = $this->_query($query);
@@ -261,9 +289,16 @@
return true;
}
- /**
- * @brief Add a column to a table
- **/
+ /**
+ * Add a column to the table
+ * @param string $table_name table name
+ * @param string $column_name column name
+ * @param string $type column type, default value is 'number'
+ * @param int $size column size
+ * @param string|int $default default value
+ * @param boolean $notnull not null status, default value is false
+ * @return void
+ */
function addColumn($table_name, $column_name, $type='number', $size='', $default = '', $notnull=false) {
if($this->isColumnExists($table_name, $column_name)) return;
$type = $this->column_type[$type];
@@ -278,18 +313,24 @@
$this->_query($query);
}
- /**
- * @brief Delete a column from a table
- **/
+ /**
+ * Drop a column from the table
+ * @param string $table_name table name
+ * @param string $column_name column name
+ * @return void
+ */
function dropColumn($table_name, $column_name) {
if(!$this->isColumnExists($table_name, $column_name)) return;
$query = sprintf("alter table %s%s drop %s ", $this->prefix, $table_name, $column_name);
$this->_query($query);
}
- /**
- * @brief Return column information of a table
- **/
+ /**
+ * Check column exist status of the table
+ * @param string $table_name table name
+ * @param string $column_name column name
+ * @return boolean
+ */
function isColumnExists($table_name, $column_name) {
$query = sprintf("select syscolumns.name as name from syscolumns, sysobjects where sysobjects.name = '%s%s' and sysobjects.id = syscolumns.id and syscolumns.name = '%s'", $this->prefix, $table_name, $column_name);
$result = $this->_query($query);
@@ -299,11 +340,16 @@
return true;
}
- /**
- * @brief Add an index to a table
- * $target_columns = array(col1, col2)
- * $is_unique? unique : none
- **/
+ /**
+ * Add an index to the table
+ * $target_columns = array(col1, col2)
+ * $is_unique? unique : none
+ * @param string $table_name table name
+ * @param string $index_name index name
+ * @param string|array $target_columns target column or columns
+ * @param boolean $is_unique
+ * @return void
+ */
function addIndex($table_name, $index_name, $target_columns, $is_unique = false) {
if($this->isIndexExists($table_name, $index_name)) return;
if(!is_array($target_columns)) $target_columns = array($target_columns);
@@ -312,18 +358,25 @@
$this->_query($query);
}
- /**
- * @brief Drop an index from a table
- **/
+ /**
+ * Drop an index from the table
+ * @param string $table_name table name
+ * @param string $index_name index name
+ * @param boolean $is_unique
+ * @return void
+ */
function dropIndex($table_name, $index_name, $is_unique = false) {
if(!$this->isIndexExists($table_name, $index_name)) return;
$query = sprintf("drop index %s%s.%s", $this->prefix, $table_name, $index_name);
$this->_query($query);
}
- /**
- * @brief Return index information of a table
- **/
+ /**
+ * Check index status of the table
+ * @param string $table_name table name
+ * @param string $index_name index name
+ * @return boolean
+ */
function isIndexExists($table_name, $index_name) {
$query = sprintf("select sysindexes.name as name from sysindexes, sysobjects where sysobjects.name = '%s%s' and sysobjects.id = sysindexes.id and sysindexes.name = '%s'", $this->prefix, $table_name, $index_name);
@@ -335,16 +388,20 @@
return true;
}
- /**
- * @brief Create a table by using xml file
- **/
+ /**
+ * Creates a table by using xml contents
+ * @param string $xml_doc xml schema contents
+ * @return void|object
+ */
function createTableByXml($xml_doc) {
return $this->_createTable($xml_doc);
}
- /**
- * @brief Create a table by using xml file
- **/
+ /**
+ * Creates a table by using xml file path
+ * @param string $file_name xml schema file path
+ * @return void|object
+ */
function createTableByXmlFile($file_name) {
if(!file_exists($file_name)) return;
// read xml file
@@ -352,13 +409,15 @@
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
- **/
+ /**
+ * Create table by using the schema xml
+ *
+ * type : number, varchar, tinytext, text, bigtext, char, date, \n
+ * opt : notnull, default, size\n
+ * index : primary key, index, unique\n
+ * @param string $xml_doc xml schema contents
+ * @return void|object
+ */
function _createTable($xml_doc) {
// xml parsing
$oXml = new XmlParser();
@@ -381,6 +440,7 @@
$unique_list = array();
$index_list = array();
+ $typeList = array('number'=>1, 'text'=>1);
foreach($columns as $column) {
$name = $column->attrs->name;
$type = $column->attrs->type;
@@ -395,7 +455,7 @@
$column_schema[] = sprintf('[%s] %s%s %s %s %s',
$name,
$this->column_type[$type],
- !in_array($type,array('number','text'))&&$size?'('.$size.')':'',
+ !isset($typeList[$type])&&$size?'('.$size.')':'',
isset($default)?"default '".$default."'":'',
$notnull?'not null':'null',
$auto_increment?'identity(1,1)':''
@@ -433,25 +493,37 @@
}
- /**
- * @brief Handle the insertAct
- **/
- // TODO Lookup _filterNumber against sql injection - see if it is still needed and how to integrate
+
+ /**
+ * Handles insertAct
+ * @todo Lookup _filterNumber against sql injection - see if it is still needed and how to integrate
+ * @param Object $queryObject
+ * @return resource
+ */
function _executeInsertAct($queryObject) {
$query = $this->getInsertSql($queryObject, false);
$this->param = $queryObject->getArguments();
return $this->_query($query);
}
- /**
- * @brief Handle updateAct
- **/
+ /**
+ * Handles updateAct
+ * @param Object $queryObject
+ * @return resource
+ */
function _executeUpdateAct($queryObject) {
$query = $this->getUpdateSql($queryObject, false);
$this->param = $queryObject->getArguments();
return $this->_query($query);
}
+ /**
+ * Return update query string
+ * @param object $query
+ * @param boolean $with_values
+ * @param boolean $with_priority
+ * @return string
+ */
function getUpdateSql($query, $with_values = true, $with_priority = false){
$columnsList = $query->getUpdateString($with_values);
if($columnsList == '') return new Object(-1, "Invalid query");
@@ -473,15 +545,23 @@
return "UPDATE $priority $alias_list SET $columnsList FROM ".$from.$where;
}
- /**
- * @brief Handle deleteAct
- **/
+ /**
+ * Handles deleteAct
+ * @param Object $queryObject
+ * @return resource
+ */
function _executeDeleteAct($queryObject) {
$query = $this->getDeleteSql($queryObject, false);
$this->param = $queryObject->getArguments();
return $this->_query($query);
}
+ /**
+ * Return select query string
+ * @param object $query
+ * @param boolean $with_values
+ * @return string
+ */
function getSelectSql($query, $with_values = TRUE){
$with_values = false;
@@ -519,12 +599,14 @@
return $select . ' ' . $from . ' ' . $where . ' ' . $groupBy . ' ' . $orderBy;
}
- /**
- * @brief Handle selectAct
- *
- * In order to get a list of pages easily when selecting \n
- * it supports a method as navigation
- **/
+ /**
+ * Handle selectAct
+ * In order to get a list of pages easily when selecting \n
+ * it supports a method as navigation
+ * @param Object $queryObject
+ * @param resource $connection
+ * @return Object
+ */
function _executeSelectAct($queryObject, $connection = null) {
$query = $this->getSelectSql($queryObject);
@@ -540,11 +622,20 @@
else return $this->queryPageLimit($queryObject, $result, $connection);
}
- function &getParser($force = FALSE){
- $dbParser = new DBParser("[", "]", $this->prefix);
- return $dbParser;
+ /**
+ * Return the DBParser
+ * @param boolean $force
+ * @return DBParser
+ */
+ function getParser($force = FALSE){
+ return new DBParser("[", "]", $this->prefix);
}
+ /**
+ * If have a error, return error object
+ * @param Object $queryObject
+ * @return Object
+ */
function queryError($queryObject){
$limit = $queryObject->getLimit();
if ($limit && $limit->isPageHandler()){
@@ -559,6 +650,13 @@
return;
}
+ /**
+ * If select query execute, return page info
+ * @param Object $queryObject
+ * @param resource $result
+ * @param resource $connection
+ * @return Object Object with page info containing
+ */
function queryPageLimit($queryObject, $result, $connection) {
$limit = $queryObject->getLimit();
if ($limit && $limit->isPageHandler()) {
@@ -615,7 +713,7 @@
$buff->page_navigation = new PageHandler($total_count, $total_page, $page, $page_count);
return $buff;
}
-
+
$start_count = ($page - 1) * $list_count;
$this->param = $queryObject->getArguments();
$virtual_no = $total_count - $start_count;
diff --git a/classes/db/DBMysql.class.php b/classes/db/DBMysql.class.php
index 6b95a1d01..b5be890d4 100644
--- a/classes/db/DBMysql.class.php
+++ b/classes/db/DBMysql.class.php
@@ -1,29 +1,30 @@
'bigint',
'number' => 'bigint',
@@ -36,28 +37,38 @@ class DBMysql extends DB {
);
/**
- * @brief constructor
- **/
+ * Constructor
+ * @return void
+ */
function DBMysql() {
$this->_setDBInfo();
$this->_connect();
}
+ /**
+ * Create an instance of this class
+ * @return DBMysql return DBMysql object instance
+ */
function create() {
return new DBMysql;
}
- /**
- * @brief Return if it is installable
- **/
+ /**
+ * Return if supportable
+ * Check 'mysql_connect' function exists.
+ * @return boolean
+ */
function isSupported() {
if(!function_exists('mysql_connect')) return false;
return true;
}
- /**
- * @brief DB Connection
- **/
+ /**
+ * DB Connect
+ * this method is private
+ * @param array $connection connection's value is db_hostname, db_port, db_database, db_userid, db_password
+ * @return resource
+ */
function __connect($connection) {
// Ignore if no DB information exists
if (strpos($connection["db_hostname"], ':') === false && $connection["db_port"])
@@ -85,57 +96,72 @@ class DBMysql extends DB {
return $result;
}
+ /**
+ * If have a task after connection, add a taks in this method
+ * this method is private
+ * @param resource $connection
+ * @return void
+ */
function _afterConnect($connection){
// Set utf8 if a database is MySQL
$this->_query("set names 'utf8'", $connection);
}
- /**
- * @brief DB disconnection
- **/
+ /**
+ * DB disconnection
+ * this method is private
+ * @param resource $connection
+ * @return void
+ */
function _close($connection) {
@mysql_close($connection);
}
- /**
- * @brief Add quotes on the string variables in a query
- **/
+ /**
+ * Handles quatation of the string variables from the query
+ * @param string $string
+ * @return string
+ */
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 = @mysql_real_escape_string($string);
return $string;
}
- /**
- * @brief Begin transaction
- **/
+ /**
+ * DB transaction start
+ * this method is private
+ * @return boolean
+ */
function _begin() {
return true;
}
- /**
- * @brief Rollback
- **/
+ /**
+ * DB transaction rollback
+ * this method is private
+ * @return boolean
+ */
function _rollback() {
return true;
}
- /**
- * @brief Commits
- **/
+ /**
+ * DB transaction commit
+ * this method is private
+ * @return boolean
+ */
function _commit() {
return true;
}
- /**
- * @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
- **/
+ /**
+ * Execute the query
+ * this method is private
+ * @param string $query
+ * @param resource $connection
+ * @return resource
+ */
function __query($query, $connection) {
// Run the query statement
$result = mysql_query($query, $connection);
@@ -145,9 +171,12 @@ class DBMysql extends DB {
return $result;
}
- /**
- * @brief Fetch results
- **/
+ /**
+ * Fetch the result
+ * @param resource $result
+ * @param int|NULL $arrayIndexEndValue
+ * @return array
+ */
function _fetch($result, $arrayIndexEndValue = NULL) {
$output = array();
if(!$this->isConnected() || $this->isError() || !$result) return $output;
@@ -163,9 +192,11 @@ class DBMysql extends DB {
return $output;
}
- /**
- * @brief Return sequence value incremented by 1(auto_increment is used in sequence table only in MySQL)
- **/
+ /**
+ * Return the sequence value incremented by 1
+ * Auto_increment column only used in the sequence table
+ * @return int
+ */
function getNextSequence() {
$query = sprintf("insert into `%ssequence` (seq) values ('0')", $this->prefix);
$this->_query($query);
@@ -178,9 +209,12 @@ class DBMysql extends DB {
return $sequence;
}
- /**
- * @brief Function to obtain mysql old password(mysql only)
- **/
+ /**
+ * Function to obtain mysql old password(mysql only)
+ * @param string $password input password
+ * @param string $saved_password saved password in DBMS
+ * @return boolean
+ */
function isValidOldPassword($password, $saved_password) {
$query = sprintf("select password('%s') as password, old_password('%s') as old_password", $this->addQuotes($password), $this->addQuotes($password));
$result = $this->_query($query);
@@ -189,9 +223,11 @@ class DBMysql extends DB {
return false;
}
- /**
- * @brief Return if a table already exists
- **/
+ /**
+ * Check a table exists status
+ * @param string $target_name
+ * @return boolean
+ */
function isTableExists($target_name) {
$query = sprintf("show tables like '%s%s'", $this->prefix, $this->addQuotes($target_name));
$result = $this->_query($query);
@@ -200,9 +236,16 @@ class DBMysql extends DB {
return true;
}
- /**
- * @brief Add a column to a table
- **/
+ /**
+ * Add a column to the table
+ * @param string $table_name table name
+ * @param string $column_name column name
+ * @param string $type column type, default value is 'number'
+ * @param int $size column size
+ * @param string|int $default default value
+ * @param boolean $notnull not null status, default value is false
+ * @return void
+ */
function addColumn($table_name, $column_name, $type='number', $size='', $default = '', $notnull=false) {
$type = $this->column_type[$type];
if(strtoupper($type)=='INTEGER') $size = '';
@@ -216,17 +259,23 @@ class DBMysql extends DB {
$this->_query($query);
}
- /**
- * @brief Delete a column from a table
- **/
+ /**
+ * Drop a column from the table
+ * @param string $table_name table name
+ * @param string $column_name column name
+ * @return void
+ */
function dropColumn($table_name, $column_name) {
$query = sprintf("alter table `%s%s` drop `%s` ", $this->prefix, $table_name, $column_name);
$this->_query($query);
}
- /**
- * @brief Return column information of a table
- **/
+ /**
+ * Check column exist status of the table
+ * @param string $table_name table name
+ * @param string $column_name column name
+ * @return boolean
+ */
function isColumnExists($table_name, $column_name) {
$query = sprintf("show fields from `%s%s`", $this->prefix, $table_name);
$result = $this->_query($query);
@@ -242,11 +291,16 @@ class DBMysql extends DB {
return false;
}
- /**
- * @brief Add an index to a table
- * $target_columns = array(col1, col2)
- * $is_unique? unique : none
- **/
+ /**
+ * Add an index to the table
+ * $target_columns = array(col1, col2)
+ * $is_unique? unique : none
+ * @param string $table_name table name
+ * @param string $index_name index name
+ * @param string|array $target_columns target column or columns
+ * @param boolean $is_unique
+ * @return void
+ */
function addIndex($table_name, $index_name, $target_columns, $is_unique = false) {
if(!is_array($target_columns)) $target_columns = array($target_columns);
@@ -254,18 +308,25 @@ class DBMysql extends DB {
$this->_query($query);
}
- /**
- * @brief Drop an index from a table
- **/
+ /**
+ * Drop an index from the table
+ * @param string $table_name table name
+ * @param string $index_name index name
+ * @param boolean $is_unique
+ * @return void
+ */
function dropIndex($table_name, $index_name, $is_unique = false) {
$query = sprintf("alter table `%s%s` drop index `%s`", $this->prefix, $table_name, $index_name);
$this->_query($query);
}
- /**
- * @brief Return index information of a table
- **/
+ /**
+ * Check index status of the table
+ * @param string $table_name table name
+ * @param string $index_name index name
+ * @return boolean
+ */
function isIndexExists($table_name, $index_name) {
//$query = sprintf("show indexes from %s%s where key_name = '%s' ", $this->prefix, $table_name, $index_name);
$query = sprintf("show indexes from `%s%s`", $this->prefix, $table_name);
@@ -281,16 +342,20 @@ class DBMysql extends DB {
return false;
}
- /**
- * @brief Create a table by using xml file
- **/
+ /**
+ * Creates a table by using xml contents
+ * @param string $xml_doc xml schema contents
+ * @return void|object
+ */
function createTableByXml($xml_doc) {
return $this->_createTable($xml_doc);
}
- /**
- * @brief Create a table by using xml file
- **/
+ /**
+ * Creates a table by using xml file path
+ * @param string $file_name xml schema file path
+ * @return void|object
+ */
function createTableByXmlFile($file_name) {
if(!file_exists($file_name)) return;
// read xml file
@@ -298,13 +363,15 @@ class DBMysql extends DB {
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
- **/
+ /**
+ * Create table by using the schema xml
+ *
+ * type : number, varchar, tinytext, text, bigtext, char, date, \n
+ * opt : notnull, default, size\n
+ * index : primary key, index, unique\n
+ * @param string $xml_doc xml schema contents
+ * @return void|object
+ */
function _createTable($xml_doc) {
// xml parsing
$oXml = new XmlParser();
@@ -368,39 +435,51 @@ class DBMysql extends DB {
if(!$output) return false;
}
- /**
- * @brief Handle the insertAct
- **/
+ /**
+ * Handles insertAct
+ * @param Object $queryObject
+ * @param boolean $with_values
+ * @return resource
+ */
function _executeInsertAct($queryObject, $with_values = true) {
$query = $this->getInsertSql($queryObject, $with_values, true);
if(is_a($query, 'Object')) return;
return $this->_query($query);
}
- /**
- * @brief Handle updateAct
- **/
+ /**
+ * Handles updateAct
+ * @param Object $queryObject
+ * @param boolean $with_values
+ * @return resource
+ */
function _executeUpdateAct($queryObject, $with_values = true) {
$query = $this->getUpdateSql($queryObject, $with_values, true);
if(is_a($query, 'Object')) return;
return $this->_query($query);
}
- /**
- * @brief Handle deleteAct
- **/
+ /**
+ * Handles deleteAct
+ * @param Object $queryObject
+ * @param boolean $with_values
+ * @return resource
+ */
function _executeDeleteAct($queryObject, $with_values = true) {
$query = $this->getDeleteSql($queryObject, $with_values, true);
if(is_a($query, 'Object')) return;
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
- **/
+ /**
+ * Handle selectAct
+ * In order to get a list of pages easily when selecting \n
+ * it supports a method as navigation
+ * @param Object $queryObject
+ * @param resource $connection
+ * @param boolean $with_values
+ * @return Object
+ */
function _executeSelectAct($queryObject, $connection = null, $with_values = true) {
$limit = $queryObject->getLimit();
$result = NULL;
@@ -423,26 +502,52 @@ class DBMysql extends DB {
}
}
+ /**
+ * Get the ID generated in the last query
+ * Return next sequence from sequence table
+ * This method use only mysql
+ * @return int
+ */
function db_insert_id()
{
$connection = $this->_getConnection('master');
return mysql_insert_id($connection);
}
+ /**
+ * Fetch a result row as an object
+ * @param resource $result
+ * @return object
+ */
function db_fetch_object(&$result)
{
return mysql_fetch_object($result);
}
+ /**
+ * Free result memory
+ * @param resource $result
+ * @return boolean Returns TRUE on success or FALSE on failure.
+ */
function db_free_result(&$result){
return mysql_free_result($result);
}
+ /**
+ * Return the DBParser
+ * @param boolean $force
+ * @return DBParser
+ */
function &getParser($force = FALSE){
$dbParser = new DBParser('`', '`', $this->prefix);
return $dbParser;
}
+ /**
+ * If have a error, return error object
+ * @param Object $queryObject
+ * @return Object
+ */
function queryError($queryObject){
$limit = $queryObject->getLimit();
if ($limit && $limit->isPageHandler()){
@@ -457,6 +562,14 @@ class DBMysql extends DB {
return;
}
+ /**
+ * If select query execute, return page info
+ * @param Object $queryObject
+ * @param resource $result
+ * @param resource $connection
+ * @param boolean $with_values
+ * @return Object Object with page info containing
+ */
function queryPageLimit($queryObject, $result, $connection, $with_values = true){
$limit = $queryObject->getLimit();
// Total count
@@ -469,7 +582,7 @@ class DBMysql extends DB {
$uses_groupby = $queryObject->getGroupByString() != '';
if($uses_distinct || $uses_groupby) {
$count_query = sprintf('select %s %s %s %s'
- , $temp_select
+ , $temp_select == '*' ? '1' : $temp_select
, 'FROM ' . $queryObject->getFromString($with_values)
, ($temp_where === '' ? '' : ' WHERE '. $temp_where)
, ($uses_groupby ? ' GROUP BY ' . $queryObject->getGroupByString() : '')
@@ -529,6 +642,14 @@ class DBMysql extends DB {
return $buff;
}
+ /**
+ * If select query execute, return paging sql
+ * @param object $query
+ * @param boolean $with_values
+ * @param int $start_count
+ * @param int $list_count
+ * @return string select paging sql
+ */
function getSelectPageSql($query, $with_values = true, $start_count = 0, $list_count = 0) {
$select = $query->getSelectString($with_values);
if($select == '') return new Object(-1, "Invalid query");
diff --git a/classes/db/DBMysql_innodb.class.php b/classes/db/DBMysql_innodb.class.php
index d0f117907..ddb580b7a 100644
--- a/classes/db/DBMysql_innodb.class.php
+++ b/classes/db/DBMysql_innodb.class.php
@@ -1,79 +1,87 @@
_setDBInfo();
$this->_connect();
}
/**
- * @brief create an instance of this class
+ * Create an instance of this class
+ * @return DBMysql_innodb return DBMysql_innodb object instance
*/
function create()
{
return new DBMysql_innodb;
}
- /**
- * @brief DB disconnection
- **/
+ /**
+ * DB disconnection
+ * this method is private
+ * @param resource $connection
+ * @return void
+ */
function _close($connection) {
$this->_query("commit", $connection);
@mysql_close($connection);
}
- /**
- * @brief Begin transaction
- **/
+ /**
+ * DB transaction start
+ * this method is private
+ * @return boolean
+ */
function _begin() {
$connection = $this->_getConnection('master');
$this->_query("begin", $connection);
return true;
}
- /**
- * @brief Rollback
- **/
+ /**
+ * DB transaction rollback
+ * this method is private
+ * @return boolean
+ */
function _rollback() {
$connection = $this->_getConnection('master');
$this->_query("rollback", $connection);
return true;
}
- /**
- * @brief Commits
- **/
+ /**
+ * DB transaction commit
+ * this method is private
+ * @return boolean
+ */
function _commit() {
$connection = $this->_getConnection('master');
$this->_query("commit", $connection);
return true;
}
- /**
- * @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
- **/
+ /**
+ * Execute the query
+ * this method is private
+ * @param string $query
+ * @param resource $connection
+ * @return resource
+ */
function __query($query, $connection) {
// Run the query statement
$result = @mysql_query($query, $connection);
@@ -83,13 +91,15 @@
return $result;
}
- /**
- * @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
- **/
+ /**
+ * Create table by using the schema xml
+ *
+ * type : number, varchar, tinytext, text, bigtext, char, date, \n
+ * opt : notnull, default, size\n
+ * index : primary key, index, unique\n
+ * @param string $xml_doc xml schema contents
+ * @return void|object
+ */
function _createTable($xml_doc) {
// xml parsing
$oXml = new XmlParser();
diff --git a/classes/db/DBMysqli.class.php b/classes/db/DBMysqli.class.php
index f44e60877..76be9e810 100644
--- a/classes/db/DBMysqli.class.php
+++ b/classes/db/DBMysqli.class.php
@@ -1,44 +1,52 @@
_setDBInfo();
$this->_connect();
}
- /**
- * @brief Return if it is installable
- **/
+ /**
+ * Return if supportable
+ * Check 'mysqli_connect' function exists.
+ * @return boolean
+ */
function isSupported() {
if(!function_exists('mysqli_connect')) return false;
return true;
}
/**
- * @brief create an instance of this class
+ * Create an instance of this class
+ * @return DBMysqli return DBMysqli object instance
*/
function create()
{
return new DBMysqli;
}
- /**
- * @brief DB Connection
- **/
+ /**
+ * DB Connect
+ * this method is private
+ * @param array $connection connection's value is db_hostname, db_port, db_database, db_userid, db_password
+ * @return resource
+ */
function __connect($connection) {
// Attempt to connect
if ($connection["db_port"]) {
@@ -62,16 +70,21 @@
return $result;
}
- /**
- * @brief DB disconnection
- **/
+ /**
+ * DB disconnection
+ * this method is private
+ * @param resource $connection
+ * @return void
+ */
function _close($connection) {
mysqli_close($connection);
}
- /**
- * @brief Add quotes on the string variables in a query
- **/
+ /**
+ * Handles quatation of the string variables from the query
+ * @param string $string
+ * @return string
+ */
function addQuotes($string) {
if(version_compare(PHP_VERSION, "5.9.0", "<") && get_magic_quotes_gpc()) $string = stripslashes(str_replace("\\","\\\\",$string));
if(!is_numeric($string)){
@@ -81,15 +94,13 @@
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
- **/
+ /**
+ * Execute the query
+ * this method is private
+ * @param string $query
+ * @param resource $connection
+ * @return resource
+ */
function __query($query, $connection) {
if($this->use_prepared_statements == 'Y')
{
@@ -140,6 +151,13 @@
return $result;
}
+ /**
+ * Before execute query, prepare statement
+ * this method is private
+ * @param string $types
+ * @param array $params
+ * @return void
+ */
function _prepareQueryParameters(&$types, &$params){
$types = '';
$params = array();
@@ -182,9 +200,12 @@
}
}
- /**
- * @brief Fetch results
- **/
+ /**
+ * Fetch the result
+ * @param resource $result
+ * @param int|NULL $arrayIndexEndValue
+ * @return array
+ */
function _fetch($result, $arrayIndexEndValue = NULL) {
if($this->use_prepared_statements != 'Y'){
return parent::_fetch($result, $arrayIndexEndValue);
@@ -247,6 +268,12 @@
return $output;
}
+ /**
+ * Handles insertAct
+ * @param Object $queryObject
+ * @param boolean $with_values
+ * @return resource
+ */
function _executeInsertAct($queryObject, $with_values = false){
if($this->use_prepared_statements != 'Y')
{
@@ -258,6 +285,12 @@
return $result;
}
+ /**
+ * Handles updateAct
+ * @param Object $queryObject
+ * @param boolean $with_values
+ * @return resource
+ */
function _executeUpdateAct($queryObject, $with_values = false) {
if($this->use_prepared_statements != 'Y')
{
@@ -269,6 +302,12 @@
return $result;
}
+ /**
+ * Handles deleteAct
+ * @param Object $queryObject
+ * @param boolean $with_values
+ * @return resource
+ */
function _executeDeleteAct($queryObject, $with_values = false) {
if($this->use_prepared_statements != 'Y')
{
@@ -280,6 +319,15 @@
return $result;
}
+ /**
+ * Handle selectAct
+ * In order to get a list of pages easily when selecting \n
+ * it supports a method as navigation
+ * @param Object $queryObject
+ * @param resource $connection
+ * @param boolean $with_values
+ * @return Object
+ */
function _executeSelectAct($queryObject, $connection = null, $with_values = false) {
if($this->use_prepared_statements != 'Y')
{
@@ -291,17 +339,33 @@
return $result;
}
+ /**
+ * Get the ID generated in the last query
+ * Return next sequence from sequence table
+ * This method use only mysql
+ * @return int
+ */
function db_insert_id()
{
$connection = $this->_getConnection('master');
return mysqli_insert_id($connection);
}
+ /**
+ * Fetch a result row as an object
+ * @param resource $result
+ * @return object
+ */
function db_fetch_object(&$result)
{
return mysqli_fetch_object($result);
}
+ /**
+ * Free result memory
+ * @param resource $result
+ * @return boolean Returns TRUE on success or FALSE on failure.
+ */
function db_free_result(&$result){
return mysqli_free_result($result);
}
diff --git a/classes/db/queryparts/Query.class.php b/classes/db/queryparts/Query.class.php
index 1e13e40d4..65f0a1510 100644
--- a/classes/db/queryparts/Query.class.php
+++ b/classes/db/queryparts/Query.class.php
@@ -1,343 +1,497 @@
-queryID = $queryID;
- $this->action = $action;
- $this->priority = $priority;
-
- if(!isset($tables)) return;
- $this->columns = $this->setColumns($columns);
- $this->tables = $this->setTables($tables);
- $this->conditions = $this->setConditions($conditions);
- $this->groups = $this->setGroups($groups);
- $this->orderby = $this->setOrder($orderby);
- $this->limit = $this->setLimit($limit);
- }
-
- function show(){
- return true;
- }
-
- function setQueryId($queryID){
- $this->queryID = $queryID;
- }
-
- function setAction($action){
- $this->action = $action;
- }
+queryID = $queryID;
+ $this->action = $action;
+ $this->priority = $priority;
+
+ if(!isset($tables)) return;
+ $this->columns = $this->setColumns($columns);
+ $this->tables = $this->setTables($tables);
+ $this->conditions = $this->setConditions($conditions);
+ $this->groups = $this->setGroups($groups);
+ $this->orderby = $this->setOrder($orderby);
+ $this->limit = $this->setLimit($limit);
+ }
+
+ function show(){
+ return true;
+ }
+
+ function setQueryId($queryID){
+ $this->queryID = $queryID;
+ }
+
+ function setAction($action){
+ $this->action = $action;
+ }
+
+ function setPriority($priority){
+ $this->priority = $priority;
+ }
+
+ function setColumnList($columnList){
+ $this->columnList = $columnList;
+ if(count($this->columnList) > 0) {
+ $selectColumns = array();
+ $dbParser = DB::getParser();
+
+ foreach($this->columnList as $columnName){
+ $columnName = $dbParser->escapeColumn($columnName);
+ $selectColumns[] = new SelectExpression($columnName);
+ }
+ unset($this->columns);
+ $this->columns = $selectColumns;
+ }
+ }
+
+ function setColumns($columns){
+ if(!isset($columns) || count($columns) === 0){
+ $this->columns = array(new StarExpression());
+ return;
+ }
+
+ if(!is_array($columns)) $columns = array($columns);
+
+ $this->columns = $columns;
+ }
+
+ function setTables($tables){
+ if(!isset($tables) || count($tables) === 0){
+ $this->setError(true);
+ $this->setMessage("You must provide at least one table for the query.");
+ return;
+ }
+
+ if(!is_array($tables)) $tables = array($tables);
+
+ $this->tables = $tables;
+ }
- function setPriority($priority){
- $this->priority = $priority;
+ function setSubquery($subquery){
+ $this->subquery = $subquery;
}
-
- function setColumnList($columnList){
- $this->columnList = $columnList;
- if(count($this->columnList) > 0) {
- $selectColumns = array();
- $dbParser = DB::getParser();
-
- foreach($this->columnList as $columnName){
- $columnName = $dbParser->escapeColumn($columnName);
- $selectColumns[] = new SelectExpression($columnName);
- }
- unset($this->columns);
- $this->columns = $selectColumns;
- }
- }
-
- function setColumns($columns){
- if(!isset($columns) || count($columns) === 0){
- $this->columns = array(new StarExpression());
- return;
- }
-
- if(!is_array($columns)) $columns = array($columns);
-
- $this->columns = $columns;
- }
-
- function setTables($tables){
- if(!isset($tables) || count($tables) === 0){
- $this->setError(true);
- $this->setMessage("You must provide at least one table for the query.");
- return;
- }
-
- if(!is_array($tables)) $tables = array($tables);
-
- $this->tables = $tables;
- }
-
- function setConditions($conditions){
- $this->conditions = array();
- if(!isset($conditions) || count($conditions) === 0) return;
- if(!is_array($conditions)) $conditions = array($conditions);
-
- foreach($conditions as $conditionGroup){
- if($conditionGroup->show()) $this->conditions[] = $conditionGroup;
- }
- }
-
- function setGroups($groups){
- if(!isset($groups) || count($groups) === 0) return;
- if(!is_array($groups)) $groups = array($groups);
-
- $this->groups = $groups;
- }
-
- function setOrder($order){
- if(!isset($order) || count($order) === 0) return;
- if(!is_array($order)) $order = array($order);
-
- $this->orderby = $order;
- }
-
- function setLimit($limit = NULL){
- if(!isset($limit)) return;
- $this->limit = $limit;
- }
-
- // START Fluent interface
- function select($columns= null){
- $this->action = 'select';
- $this->setColumns($columns);
- return $this;
- }
-
- function from($tables){
- $this->setTables($tables);
- return $this;
- }
-
- function where($conditions){
- $this->setConditions($conditions);
- return $this;
- }
-
- function groupBy($groups){
- $this->setGroups($groups);
- return $this;
- }
-
- function orderBy($order){
- $this->setOrder($order);
- return $this;
- }
-
- function limit($limit){
- $this->setLimit($limit);
- return $this;
- }
- // END Fluent interface
-
- function getAction(){
- return $this->action;
- }
-
- function getPriority(){
- return $this->priority?'LOW_PRIORITY':'';
- }
-
- function getSelectString($with_values = true){
- foreach($this->columns as $column){
- if($column->show())
- if($column->isSubquery()){
- $select[] = $column->toString($with_values) . ' as '. $column->getAlias();
- }
- else
- $select[] = $column->getExpression($with_values);
- }
- return trim(implode($select, ', '));
- }
-
- function getUpdateString($with_values = true){
- foreach($this->columns as $column){
- if($column->show())
- $update[] = $column->getExpression($with_values);
- }
- return trim(implode($update, ', '));
- }
-
- function getInsertString($with_values = true){
- $columnsList = '';
- $valuesList = '';
- foreach($this->columns as $column){
- if($column->show()){
- $columnsList .= $column->getColumnName() . ', ';
- $valuesList .= $column->getValue($with_values) . ', ';
- }
- }
- $columnsList = substr($columnsList, 0, -2);
- $valuesList = substr($valuesList, 0, -2);
-
- return "($columnsList) \n VALUES ($valuesList)";
- }
-
- function getTables(){
- return $this->tables;
- }
-
- // from table_a
- // from table_a inner join table_b on x=y
- // from (select * from table a) as x
- // from (select * from table t) as x inner join table y on y.x
- function getFromString($with_values = true){
- $from = '';
- $simple_table_count = 0;
- foreach($this->tables as $table){
- if($table->isJoinTable() || !$simple_table_count) $from .= $table->toString($with_values) . ' ';
- else $from .= ', '.$table->toString($with_values) . ' ';
-
- if(is_a($table, 'Subquery')) $from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' ';
-
- $simple_table_count++;
- }
- if(trim($from) == '') return '';
- return $from;
- }
-
- function getWhereString($with_values = true, $with_optimization = true){
- $where = '';
- $condition_count = 0;
-
- foreach ($this->conditions as $conditionGroup) {
- if ($condition_count === 0) {
- $conditionGroup->setPipe("");
- }
- $condition_string = $conditionGroup->toString($with_values);
- $where .= $condition_string;
- $condition_count++;
- }
-
- if ($with_optimization &&
- (strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order'))) {
-
- if ($condition_count !== 0)
- $where = '(' . $where . ') ';
-
- foreach ($this->orderby as $order) {
- $colName = $order->getColumnName();
- if (strstr($colName, 'list_order') || strstr($colName, 'update_order')) {
- $opt_condition = new ConditionWithoutArgument($colName, 2100000000, 'less', 'and');
- if ($condition_count === 0)
- $opt_condition->setPipe("");
- $where .= $opt_condition->toString($with_values) . ' ';
- $condition_count++;
- }
- }
- }
-
- return trim($where);
- }
-
- function getGroupByString(){
- $groupBy = '';
- if($this->groups) if($this->groups[0] !== "")
- $groupBy = implode(', ', $this->groups);
- return $groupBy;
- }
-
- function getOrderByString(){
- if(!$this->_orderByString){
- if(count($this->orderby) === 0) return '';
- $orderBy = '';
- foreach($this->orderby as $order){
- $orderBy .= $order->toString() .', ';
- }
- $orderBy = substr($orderBy, 0, -2);
- $this->_orderByString = $orderBy;
- }
- return $this->_orderByString;
- }
-
- function getLimit(){
- return $this->limit;
- }
-
- function getLimitString(){
- $limit = '';
- if(count($this->limit) > 0){
- $limit = '';
- $limit .= $this->limit->toString();
- }
- return $limit;
- }
-
- function getFirstTableName(){
- return $this->tables[0]->getName();
- }
-
- function getArguments(){
- if(!isset($this->arguments)){
- $this->arguments = array();
-
- // Join table arguments
- if(count($this->tables) > 0)
- {
- foreach($this->tables as $table)
- {
- if($table->isJoinTable())
- {
- $args = $table->getArguments();
- if($args) $this->arguments = array_merge($this->arguments, $args);
- }
- }
- }
+
+ function setConditions($conditions){
+ $this->conditions = array();
+ if(!isset($conditions) || count($conditions) === 0) return;
+ if(!is_array($conditions)) $conditions = array($conditions);
+
+ foreach($conditions as $conditionGroup){
+ if($conditionGroup->show()) $this->conditions[] = $conditionGroup;
+ }
+ }
+
+ function setGroups($groups){
+ if(!isset($groups) || count($groups) === 0) return;
+ if(!is_array($groups)) $groups = array($groups);
+
+ $this->groups = $groups;
+ }
+
+ function setOrder($order){
+ if(!isset($order) || count($order) === 0) return;
+ if(!is_array($order)) $order = array($order);
+
+ $this->orderby = $order;
+ }
+
+ function setLimit($limit = NULL){
+ if(!isset($limit)) return;
+ $this->limit = $limit;
+ }
+
+ // START Fluent interface
+ /**
+ * seleect set
+ * @param string|array $columns
+ * @return Query return Query instance
+ */
+ function select($columns= null){
+ $this->action = 'select';
+ $this->setColumns($columns);
+ return $this;
+ }
+
+ /**
+ * from set
+ * @param string|array $tables
+ * @return Query return Query instance
+ */
+ function from($tables){
+ $this->setTables($tables);
+ return $this;
+ }
+
+ /**
+ * where set
+ * @param string|array $conditions
+ * @return Query return Query instance
+ */
+ function where($conditions){
+ $this->setConditions($conditions);
+ return $this;
+ }
+
+ /**
+ * groupBy set
+ * @param string|array $groups
+ * @return Query return Query instance
+ */
+ function groupBy($groups){
+ $this->setGroups($groups);
+ return $this;
+ }
+
+ /**
+ * orderBy set
+ * @param string|array $order
+ * @return Query return Query instance
+ */
+ function orderBy($order){
+ $this->setOrder($order);
+ return $this;
+ }
+
+ /**
+ * limit set
+ * @param int $limit
+ * @return Query return Query instance
+ */
+ function limit($limit){
+ $this->setLimit($limit);
+ return $this;
+ }
+ // END Fluent interface
+
+ function getAction(){
+ return $this->action;
+ }
+
+ function getPriority(){
+ return $this->priority?'LOW_PRIORITY':'';
+ }
+
+ /**
+ * Return select sql
+ * @param boolean $with_values
+ * @return string
+ */
+ function getSelectString($with_values = true){
+ foreach($this->columns as $column){
+ if($column->show())
+ if($column->isSubquery()){
+ $select[] = $column->toString($with_values) . ' as '. $column->getAlias();
+ }
+ else
+ $select[] = $column->getExpression($with_values);
+ }
+ return trim(implode($select, ', '));
+ }
+
+ /**
+ * Return update sql
+ * @param boolean $with_values
+ * @return string
+ */
+ function getUpdateString($with_values = true){
+ foreach($this->columns as $column){
+ if($column->show())
+ $update[] = $column->getExpression($with_values);
+ }
+ return trim(implode($update, ', '));
+ }
+
+ /**
+ * Return insert sql
+ * @param boolean $with_values
+ * @return string
+ */
+ function getInsertString($with_values = true){
+ $columnsList = '';
+ if($this->subquery){ // means we have insert-select
- // Column arguments
- if(count($this->columns) > 0){ // The if is for delete statements, all others must have columns
- foreach($this->columns as $column){
- if($column->show()){
- $args = $column->getArguments();
- if($args) $this->arguments = array_merge($this->arguments, $args);
- }
- }
+ foreach($this->columns as $column){
+ $columnsList .= $column->getColumnName() . ', ';
}
-
- // Condition arguments
- if(count($this->conditions) > 0)
- foreach($this->conditions as $conditionGroup){
- $args = $conditionGroup->getArguments();
- if(count($args) > 0) $this->arguments = array_merge($this->arguments, $args);
- }
-
- // Navigation arguments
- if(count($this->orderby) > 0)
- foreach($this->orderby as $order){
- $args = $order->getArguments();
- if(count($args) > 0) $this->arguments = array_merge($this->arguments, $args);
- }
+ $columnsList = substr($columnsList, 0, -2);
+
+ $selectStatement = $this->subquery->toString($with_values);
+ $selectStatement = substr($selectStatement, 1, -1);
+
+ return "($columnsList) \n $selectStatement";
}
- return $this->arguments;
- }
- }
-
-
-
-?>
+
+
+ $valuesList = '';
+ foreach($this->columns as $column){
+ if($column->show()){
+ $columnsList .= $column->getColumnName() . ', ';
+ $valuesList .= $column->getValue($with_values) . ', ';
+ }
+ }
+ $columnsList = substr($columnsList, 0, -2);
+ $valuesList = substr($valuesList, 0, -2);
+
+ return "($columnsList) \n VALUES ($valuesList)";
+ }
+
+ function getTables(){
+ return $this->tables;
+ }
+
+ /**
+ * from table_a
+ * from table_a inner join table_b on x=y
+ * from (select * from table a) as x
+ * from (select * from table t) as x inner join table y on y.x
+ * @param boolean $with_values
+ * @return string
+ */
+ function getFromString($with_values = true){
+ $from = '';
+ $simple_table_count = 0;
+ foreach($this->tables as $table){
+ if($table->isJoinTable() || !$simple_table_count) $from .= $table->toString($with_values) . ' ';
+ else $from .= ', '.$table->toString($with_values) . ' ';
+
+ if(is_a($table, 'Subquery')) $from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' ';
+
+ $simple_table_count++;
+ }
+ if(trim($from) == '') return '';
+ return $from;
+ }
+
+ /**
+ * Return where sql
+ * @param boolean $with_values
+ * @param boolean $with_optimization
+ * @return string
+ */
+ function getWhereString($with_values = true, $with_optimization = true){
+ $where = '';
+ $condition_count = 0;
+
+ foreach ($this->conditions as $conditionGroup) {
+ if ($condition_count === 0) {
+ $conditionGroup->setPipe("");
+ }
+ $condition_string = $conditionGroup->toString($with_values);
+ $where .= $condition_string;
+ $condition_count++;
+ }
+
+ if ($with_optimization &&
+ (strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order'))) {
+
+ if ($condition_count !== 0)
+ $where = '(' . $where . ') ';
+
+ foreach ($this->orderby as $order) {
+ $colName = $order->getColumnName();
+ if (strstr($colName, 'list_order') || strstr($colName, 'update_order')) {
+ $opt_condition = new ConditionWithoutArgument($colName, 2100000000, 'less', 'and');
+ if ($condition_count === 0)
+ $opt_condition->setPipe("");
+ $where .= $opt_condition->toString($with_values) . ' ';
+ $condition_count++;
+ }
+ }
+ }
+
+ return trim($where);
+ }
+
+ /**
+ * Return groupby sql
+ * @return string
+ */
+ function getGroupByString(){
+ $groupBy = '';
+ if($this->groups) if($this->groups[0] !== "")
+ $groupBy = implode(', ', $this->groups);
+ return $groupBy;
+ }
+
+ /**
+ * Return orderby sql
+ * @return string
+ */
+ function getOrderByString(){
+ if(!$this->_orderByString){
+ if(count($this->orderby) === 0) return '';
+ $orderBy = '';
+ foreach($this->orderby as $order){
+ $orderBy .= $order->toString() .', ';
+ }
+ $orderBy = substr($orderBy, 0, -2);
+ $this->_orderByString = $orderBy;
+ }
+ return $this->_orderByString;
+ }
+
+ function getLimit(){
+ return $this->limit;
+ }
+
+ /**
+ * Return limit sql
+ * @return string
+ */
+ function getLimitString(){
+ $limit = '';
+ if(count($this->limit) > 0){
+ $limit = '';
+ $limit .= $this->limit->toString();
+ }
+ return $limit;
+ }
+
+ function getFirstTableName(){
+ return $this->tables[0]->getName();
+ }
+
+ /**
+ * Return argument list
+ * @return array
+ */
+ function getArguments(){
+ if(!isset($this->arguments)){
+ $this->arguments = array();
+
+ // Join table arguments
+ if(count($this->tables) > 0)
+ {
+ foreach($this->tables as $table)
+ {
+ if($table->isJoinTable() || is_a($table, 'Subquery'))
+ {
+ $args = $table->getArguments();
+ if($args) $this->arguments = array_merge($this->arguments, $args);
+ }
+ }
+ }
+
+ // Column arguments
+ if(count($this->columns) > 0){ // The if is for delete statements, all others must have columns
+ foreach($this->columns as $column){
+ if($column->show()){
+ $args = $column->getArguments();
+ if($args) $this->arguments = array_merge($this->arguments, $args);
+ }
+ }
+ }
+
+ // Condition arguments
+ if(count($this->conditions) > 0)
+ foreach($this->conditions as $conditionGroup){
+ $args = $conditionGroup->getArguments();
+ if(count($args) > 0) $this->arguments = array_merge($this->arguments, $args);
+ }
+
+ // Navigation arguments
+ if(count($this->orderby) > 0)
+ foreach($this->orderby as $order){
+ $args = $order->getArguments();
+ if(count($args) > 0) $this->arguments = array_merge($this->arguments, $args);
+ }
+ }
+ return $this->arguments;
+ }
+ }
+
+
+
+?>
diff --git a/classes/db/queryparts/Subquery.class.php b/classes/db/queryparts/Subquery.class.php
index 28352eee2..922b7f0b8 100644
--- a/classes/db/queryparts/Subquery.class.php
+++ b/classes/db/queryparts/Subquery.class.php
@@ -1,9 +1,33 @@
alias = $alias;
diff --git a/classes/db/queryparts/condition/Condition.class.php b/classes/db/queryparts/condition/Condition.class.php
index c8e55d0aa..4e4a2c634 100644
--- a/classes/db/queryparts/condition/Condition.class.php
+++ b/classes/db/queryparts/condition/Condition.class.php
@@ -1,9 +1,27 @@
column_name = $column_name;
$this->argument = $argument;
@@ -23,6 +49,11 @@
return null;
}
+ /**
+ * value to string
+ * @param boolean $withValue
+ * @return string
+ */
function toString($withValue = true){
if (!isset($this->_value_to_string)) {
if (!$this->show())
@@ -41,10 +72,18 @@
return $this->_value_to_string;
}
+ /**
+ * change string without value
+ * @return string
+ */
function toStringWithoutValue(){
return $this->pipe . ' ' . $this->getConditionPart($this->_value);
}
+ /**
+ * change string with value
+ * @return string
+ */
function toStringWithValue(){
return $this->pipe . ' ' . $this->getConditionPart($this->_value);
}
@@ -53,6 +92,9 @@
$this->pipe = $pipe;
}
+ /**
+ * @return boolean
+ */
function show(){
if(!isset($this->_show)){
if(is_array($this->_value) && count($this->_value) === 1 && $this->_value[0] === '') {
@@ -74,6 +116,7 @@
case 'notlike' :
case 'in' :
case 'notin' :
+ case 'not_in' :
case 'and':
case 'or':
case 'xor':
@@ -82,17 +125,32 @@
// if variable is not set or is not string or number, return
if(!isset($this->_value)) { $this->_show = false; break;}
if($this->_value === '') { $this->_show = false; break; }
- if(!in_array(gettype($this->_value), array('string', 'integer'))) {$this->_show = false; break; }
+ $tmpArray = array('string'=>1, 'integer'=>1);
+ if(!isset($tmpArray[gettype($this->_value)]))
+ {
+ $this->_show = false; break;
+ }
break;
case 'between' :
if(!is_array($this->_value)) { $this->_show = false; break;}
if(count($this->_value)!=2) {$this->_show = false; break;}
+ case 'null':
+ case 'notnull':
+ break;
+ default:
+ // If operation is not one of the above, means the condition is invalid
+ $this->_show = false;
}
}
}
return $this->_show;
}
+ /**
+ * Return condition string
+ * @param int|string|array $value
+ * @return string
+ */
function getConditionPart($value) {
$name = $this->column_name;
$operation = $this->operation;
@@ -131,6 +189,7 @@
return $name.' in '.$value;
break;
case 'notin' :
+ case 'not_in' :
return $name.' not in '.$value;
break;
case 'notequal' :
diff --git a/classes/db/queryparts/condition/ConditionGroup.class.php b/classes/db/queryparts/condition/ConditionGroup.class.php
index 201c8c8bf..daa90ad0a 100644
--- a/classes/db/queryparts/condition/ConditionGroup.class.php
+++ b/classes/db/queryparts/condition/ConditionGroup.class.php
@@ -1,12 +1,30 @@
conditions = array();
foreach($conditions as $condition){
@@ -28,6 +46,11 @@
$this->pipe = $pipe;
}
+ /**
+ * value to string
+ * @param boolean $with_value
+ * @return string
+ */
function toString($with_value = true){
if(!isset($this->_group)){
$cond_indx = 0;
@@ -48,6 +71,10 @@
return $this->_group;
}
+ /**
+ * return argument list
+ * @return array
+ */
function getArguments(){
$args = array();
foreach($this->conditions as $condition){
@@ -57,4 +84,4 @@
return $args;
}
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/condition/ConditionSubquery.class.php b/classes/db/queryparts/condition/ConditionSubquery.class.php
index c515e814b..6d359914a 100644
--- a/classes/db/queryparts/condition/ConditionSubquery.class.php
+++ b/classes/db/queryparts/condition/ConditionSubquery.class.php
@@ -1,7 +1,19 @@
_value = $this->argument->toString();
diff --git a/classes/db/queryparts/condition/ConditionWithArgument.class.php b/classes/db/queryparts/condition/ConditionWithArgument.class.php
index 5badb729f..42bc86cd4 100644
--- a/classes/db/queryparts/condition/ConditionWithArgument.class.php
+++ b/classes/db/queryparts/condition/ConditionWithArgument.class.php
@@ -1,7 +1,19 @@
_show = false; return; }
parent::Condition($column_name, $argument, $operation, $pipe);
@@ -13,6 +25,10 @@
return $this->argument;
}
+ /**
+ * change string without value
+ * @return string
+ */
function toStringWithoutValue(){
$value = $this->argument->getUnescapedValue();
@@ -37,6 +53,9 @@
return $this->pipe . ' ' . $this->getConditionPart($q);
}
+ /**
+ * @return boolean
+ */
function show(){
if(!isset($this->_show)){
if(!$this->argument->isValid()) $this->_show = false;
diff --git a/classes/db/queryparts/condition/ConditionWithoutArgument.class.php b/classes/db/queryparts/condition/ConditionWithoutArgument.class.php
index 950235020..688b3e2df 100644
--- a/classes/db/queryparts/condition/ConditionWithoutArgument.class.php
+++ b/classes/db/queryparts/condition/ConditionWithoutArgument.class.php
@@ -1,9 +1,22 @@
1, 'notin'=>1, 'not_in'=>1);
+ if(isset($tmpArray[$operation])){
if(is_array($argument)) $argument = implode($argument, ',');
$this->_value = '('. $argument .')';
}
diff --git a/classes/db/queryparts/expression/ClickCountExpression.class.php b/classes/db/queryparts/expression/ClickCountExpression.class.php
index a112368e8..367681c0c 100644
--- a/classes/db/queryparts/expression/ClickCountExpression.class.php
+++ b/classes/db/queryparts/expression/ClickCountExpression.class.php
@@ -1,15 +1,24 @@
click_count;
}
+ /**
+ * Return column expression, ex) column = column + 1
+ * @return string
+ */
function getExpression(){
return "$this->column_name = $this->column_name + 1";
}
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/expression/DeleteExpression.class.php b/classes/db/queryparts/expression/DeleteExpression.class.php
index 611510109..d304b1e1e 100644
--- a/classes/db/queryparts/expression/DeleteExpression.class.php
+++ b/classes/db/queryparts/expression/DeleteExpression.class.php
@@ -1,20 +1,35 @@
value = $value;
}
+ /**
+ * Return column expression, ex) column = value
+ * @return string
+ */
function getExpression(){
return "$this->column_name = $this->value";
}
@@ -32,4 +47,4 @@
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/expression/Expression.class.php b/classes/db/queryparts/expression/Expression.class.php
index bd11929f6..09868c9cf 100644
--- a/classes/db/queryparts/expression/Expression.class.php
+++ b/classes/db/queryparts/expression/Expression.class.php
@@ -1,18 +1,28 @@
column_name = $column_name;
}
@@ -25,6 +35,10 @@
return false;
}
+ /**
+ * Return column expression, ex) column as alias
+ * @return string
+ */
function getExpression() {
}
- }
\ No newline at end of file
+ }
diff --git a/classes/db/queryparts/expression/InsertExpression.class.php b/classes/db/queryparts/expression/InsertExpression.class.php
index 534c4542e..3cf8d81ee 100644
--- a/classes/db/queryparts/expression/InsertExpression.class.php
+++ b/classes/db/queryparts/expression/InsertExpression.class.php
@@ -1,15 +1,24 @@
argument = $argument;
diff --git a/classes/db/queryparts/expression/SelectExpression.class.php b/classes/db/queryparts/expression/SelectExpression.class.php
index 2ad5c796c..ea3a5d22b 100644
--- a/classes/db/queryparts/expression/SelectExpression.class.php
+++ b/classes/db/queryparts/expression/SelectExpression.class.php
@@ -1,26 +1,40 @@
column_alias = $alias;
}
+ /**
+ * Return column expression, ex) column as alias
+ * @return string
+ */
function getExpression() {
return sprintf("%s%s", $this->column_name, $this->column_alias ? " as ".$this->column_alias : "");
}
diff --git a/classes/db/queryparts/expression/StarExpression.class.php b/classes/db/queryparts/expression/StarExpression.class.php
index b3c298a6a..38a877322 100644
--- a/classes/db/queryparts/expression/StarExpression.class.php
+++ b/classes/db/queryparts/expression/StarExpression.class.php
@@ -1,14 +1,17 @@
argument = $argument;
}
+ /**
+ * Return column expression, ex) column = value
+ * @return string
+ */
function getExpression($with_value = true){
if($with_value)
return $this->getExpressionWithValue();
return $this->getExpressionWithoutValue();
}
+ /**
+ * Return column expression, ex) column = value
+ * @return string
+ */
function getExpressionWithValue(){
$value = $this->argument->getValue();
$operation = $this->argument->getColumnOperation();
@@ -28,6 +46,11 @@
return "$this->column_name = $value";
}
+ /**
+ * Return column expression, ex) column = ?
+ * Can use prepare statement
+ * @return string
+ */
function getExpressionWithoutValue(){
$operation = $this->argument->getColumnOperation();
if(isset($operation))
diff --git a/classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php b/classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php
index ecb528a10..a8cd44495 100644
--- a/classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php
+++ b/classes/db/queryparts/expression/UpdateExpressionWithoutArgument.class.php
@@ -1,14 +1,24 @@
argument = $argument;
@@ -35,11 +45,11 @@
function getArgument(){
return null;
}
-
+
function getArguments(){
return array();
}
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/limit/Limit.class.php b/classes/db/queryparts/limit/Limit.class.php
index 4cc372434..256c42eb1 100644
--- a/classes/db/queryparts/limit/Limit.class.php
+++ b/classes/db/queryparts/limit/Limit.class.php
@@ -1,10 +1,38 @@
list_count = $list_count;
if ($page){
@@ -16,7 +44,11 @@
}
}
- function isPageHandler(){//in case you choose to use query limit in other cases than page select
+ /**
+ * In case you choose to use query limit in other cases than page select
+ * @return boolean
+ */
+ function isPageHandler(){
if ($this->page)return true;
else return false;
}
@@ -34,4 +66,4 @@
else return $this->list_count->getValue();
}
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/order/OrderByColumn.class.php b/classes/db/queryparts/order/OrderByColumn.class.php
index 445eaae64..3dfa8f949 100644
--- a/classes/db/queryparts/order/OrderByColumn.class.php
+++ b/classes/db/queryparts/order/OrderByColumn.class.php
@@ -1,8 +1,27 @@
column_name = $column_name;
$this->sort_order = $sort_order;
@@ -28,4 +47,4 @@
}
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/table/CubridTableWithHint.class.php b/classes/db/queryparts/table/CubridTableWithHint.class.php
index ae1e7a1fe..79d645234 100644
--- a/classes/db/queryparts/table/CubridTableWithHint.class.php
+++ b/classes/db/queryparts/table/CubridTableWithHint.class.php
@@ -1,15 +1,42 @@
index_hints_list = $index_hints_list;
}
+ /**
+ * Return index hint string
+ * @return string
+ */
function getIndexHintString(){
$result = '';
@@ -32,4 +59,4 @@
}
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/table/IndexHint.class.php b/classes/db/queryparts/table/IndexHint.class.php
index 6f24a954b..20e41f009 100644
--- a/classes/db/queryparts/table/IndexHint.class.php
+++ b/classes/db/queryparts/table/IndexHint.class.php
@@ -1,9 +1,27 @@
index_name = $index_name;
$this->index_hint_type = $index_hint_type;
@@ -18,4 +36,4 @@
}
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/table/JoinTable.class.php b/classes/db/queryparts/table/JoinTable.class.php
index 47fd265e4..16818792f 100644
--- a/classes/db/queryparts/table/JoinTable.class.php
+++ b/classes/db/queryparts/table/JoinTable.class.php
@@ -1,19 +1,32 @@
join_type = $join_type;
@@ -43,4 +56,4 @@
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/table/MssqlTableWithHint.class.php b/classes/db/queryparts/table/MssqlTableWithHint.class.php
index a3c2e46e6..077456133 100644
--- a/classes/db/queryparts/table/MssqlTableWithHint.class.php
+++ b/classes/db/queryparts/table/MssqlTableWithHint.class.php
@@ -1,10 +1,33 @@
index_hints_list = $index_hints_list;
@@ -14,9 +37,10 @@
$result = parent::toString();
$index_hint_string = '';
+ $indexTypeList = array('USE'=>1, 'FORCE'=>1);
foreach($this->index_hints_list as $index_hint){
$index_hint_type = $index_hint->getIndexHintType();
- if(in_array($index_hint_type, array('USE', 'FORCE')))
+ if(isset($indexTypeList[$index_hint_type]))
$index_hint_string .= 'INDEX(' . $index_hint->getIndexName() . '), ';
}
if($index_hint_string != ''){
@@ -26,4 +50,4 @@
}
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/table/MysqlTableWithHint.class.php b/classes/db/queryparts/table/MysqlTableWithHint.class.php
index 58bdcac73..39c8c32b7 100644
--- a/classes/db/queryparts/table/MysqlTableWithHint.class.php
+++ b/classes/db/queryparts/table/MysqlTableWithHint.class.php
@@ -1,10 +1,33 @@
index_hints_list = $index_hints_list;
@@ -33,4 +56,4 @@
}
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/db/queryparts/table/Table.class.php b/classes/db/queryparts/table/Table.class.php
index 3a19d3a97..6092e10c7 100644
--- a/classes/db/queryparts/table/Table.class.php
+++ b/classes/db/queryparts/table/Table.class.php
@@ -1,9 +1,27 @@
name = $name;
$this->alias = $alias;
@@ -27,4 +45,4 @@
}
}
-?>
\ No newline at end of file
+?>
diff --git a/classes/display/DisplayHandler.class.php b/classes/display/DisplayHandler.class.php
index 0327211b9..c1145e1d0 100644
--- a/classes/display/DisplayHandler.class.php
+++ b/classes/display/DisplayHandler.class.php
@@ -2,7 +2,7 @@
/**
* @class DisplayHandler
* @author NHN (developers@xpressengine.com)
- * @brief DisplayHandler is responsible for displaying the execution result. \n
+ * DisplayHandler is responsible for displaying the execution result. \n
* Depending on the request type, it can display either HTML or XML content.\n
* Xml content is simple xml presentation of variables in oModule while html content
* is the combination of the variables of oModue and template files/.
@@ -16,11 +16,11 @@
var $handler = null;
/**
- * @brief print either html or xml content given oModule object
- * @remark addon execution and the trigger execution are included within this method, which
- * might create inflexibility for the fine grained caching
- * @param[in] $oModule the module object
- **/
+ * print either html or xml content given oModule object
+ * @remark addon execution and the trigger execution are included within this method, which might create inflexibility for the fine grained caching
+ * @param ModuleObject $oModule the module object
+ * @return void
+ **/
function printContent(&$oModule) {
// Check if the gzip encoding supported
if(
@@ -82,9 +82,10 @@
/**
- * @brief Print debugging message to designated output source depending on the value set to __DEBUG_OUTPUT_. \n
- * This method only functions when __DEBUG__ variable is set to 1.
- * __DEBUG_OUTPUT__ == 0, messages are written in ./files/_debug_message.php
+ * Print debugging message to designated output source depending on the value set to __DEBUG_OUTPUT_. \n
+ * This method only functions when __DEBUG__ variable is set to 1.
+ * __DEBUG_OUTPUT__ == 0, messages are written in ./files/_debug_message.php
+ * @return void
**/
function _debugOutput() {
if(!__DEBUG__) return;
@@ -221,7 +222,8 @@
}
/**
- * @brief print a HTTP HEADER for XML, which is encoded in UTF-8
+ * print a HTTP HEADER for XML, which is encoded in UTF-8
+ * @return void
**/
function _printXMLHeader() {
header("Content-Type: text/xml; charset=UTF-8");
@@ -234,7 +236,8 @@
/**
- * @brief print a HTTP HEADER for HTML, which is encoded in UTF-8
+ * print a HTTP HEADER for HTML, which is encoded in UTF-8
+ * @return void
**/
function _printHTMLHeader() {
header("Content-Type: text/html; charset=UTF-8");
@@ -247,7 +250,8 @@
/**
- * @brief print a HTTP HEADER for JSON, which is encoded in UTF-8
+ * print a HTTP HEADER for JSON, which is encoded in UTF-8
+ * @return void
**/
function _printJSONHeader() {
header("Content-Type: text/html; charset=UTF-8");
@@ -260,7 +264,8 @@
/**
- * @brief print a HTTP HEADER for HTML, which is encoded in UTF-8
+ * print a HTTP HEADER for HTML, which is encoded in UTF-8
+ * @return void
**/
function _printHttpStatusCode($code) {
$statusMessage = Context::get('http_status_message');
diff --git a/classes/display/HTMLDisplayHandler.php b/classes/display/HTMLDisplayHandler.php
index 8670948ad..837a5ba6d 100644
--- a/classes/display/HTMLDisplayHandler.php
+++ b/classes/display/HTMLDisplayHandler.php
@@ -2,8 +2,9 @@
class HTMLDisplayHandler {
/**
- * @brief Produce HTML compliant content given a module object.\n
- * @param[in] $oModule the module object
+ * Produce HTML compliant content given a module object.\n
+ * @param ModuleObject $oModule the module object
+ * @return string compiled template string
**/
function toDoc(&$oModule)
{
@@ -79,6 +80,11 @@ class HTMLDisplayHandler {
return $output;
}
+ /**
+ * when display mode is HTML, prepare code before print.
+ * @param string $output compiled template string
+ * @return void
+ **/
function prepareToPrint(&$output) {
if(Context::getResponseMethod() != 'HTML') return;
@@ -151,6 +157,11 @@ class HTMLDisplayHandler {
$oModuleController->replaceDefinedLangCode($output);
}
+ /**
+ * when display mode is HTML, prepare code before print about
tag value.
+ * @param array $match input value.
+ * @return string input value.
+ **/
function _preserveValue($match)
{
$INPUT_ERROR = Context::get('INPUT_ERROR');
@@ -164,7 +175,7 @@ class HTMLDisplayHandler {
switch($type){
case 'text':
case 'hidden':
- $str = preg_replace('@\svalue="[^"]*?"@', ' ', $str).' value="'.htmlspecialchars($INPUT_ERROR[$match[3]]).'"';
+ $str = preg_replace('@\svalue="[^"]*?"@', ' ', $str).' value="'.@htmlspecialchars($INPUT_ERROR[$match[3]]).'"';
break;
case 'password':
$str = preg_replace('@\svalue="[^"]*?"@', ' ', $str);
@@ -172,7 +183,7 @@ class HTMLDisplayHandler {
case 'radio':
case 'checkbox':
$str = preg_replace('@\schecked(="[^"]*?")?@', ' ', $str);
- if(preg_match('@\s(?i:value)="'.$INPUT_ERROR[$match[3]].'"@', $str)) {
+ if(@preg_match('@\s(?i:value)="'.$INPUT_ERROR[$match[3]].'"@', $str)) {
$str .= ' checked="checked"';
}
break;
@@ -181,6 +192,11 @@ class HTMLDisplayHandler {
return $str.' />';
}
+ /**
+ * when display mode is HTML, prepare code before print about
';
}
+ /**
+ * when display mode is HTML, prepare code before print about