mirror of
https://github.com/e107inc/e107.git
synced 2025-08-04 05:37:32 +02:00
Updated mysql handler to accept array data in a bit different manner, updated forum code to comply.
This commit is contained in:
@@ -9,8 +9,8 @@
|
|||||||
* mySQL Handler
|
* mySQL Handler
|
||||||
*
|
*
|
||||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
|
* $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
|
||||||
* $Revision: 1.34 $
|
* $Revision: 1.35 $
|
||||||
* $Date: 2008-12-13 22:35:13 $
|
* $Date: 2009-01-09 16:22:08 $
|
||||||
* $Author: mcfly_e107 $
|
* $Author: mcfly_e107 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s
|
|||||||
* MySQL Abstraction class
|
* MySQL Abstraction class
|
||||||
*
|
*
|
||||||
* @package e107
|
* @package e107
|
||||||
* @version $Revision: 1.34 $
|
* @version $Revision: 1.35 $
|
||||||
* @author $Author: mcfly_e107 $
|
* @author $Author: mcfly_e107 $
|
||||||
*/
|
*/
|
||||||
class db {
|
class db {
|
||||||
@@ -319,15 +319,26 @@ class db {
|
|||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function db_Insert($table, $arg, $debug = FALSE, $log_type = '', $log_remark = '') {
|
function db_Insert($table, $arg, $debug = FALSE, $log_type = '', $log_remark = '')
|
||||||
|
{
|
||||||
$table = $this->db_IsLang($table);
|
$table = $this->db_IsLang($table);
|
||||||
$this->mySQLcurTable = $table;
|
$this->mySQLcurTable = $table;
|
||||||
if(is_array($arg))
|
if(is_array($arg))
|
||||||
{
|
{
|
||||||
|
if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data']))
|
||||||
|
{
|
||||||
|
//Convert data if not using 'new' format
|
||||||
|
$_tmp = array();
|
||||||
|
$_tmp['data'] = $arg;
|
||||||
|
$arg = $_tmp;
|
||||||
|
unset($_tmp);
|
||||||
|
}
|
||||||
|
if(!isset($arg['data'])) { return false; }
|
||||||
|
|
||||||
$fieldTypes = $this->_getTypes($arg);
|
$fieldTypes = $this->_getTypes($arg);
|
||||||
$keyList= "`".implode("`,`", array_keys($arg))."`";
|
$keyList= '`'.implode('`,`', array_keys($arg['data'])).'`';
|
||||||
$tmp = array();
|
$tmp = array();
|
||||||
foreach($arg as $fk => $fv)
|
foreach($arg['data'] as $fk => $fv)
|
||||||
{
|
{
|
||||||
$tmp[] = $this->_getFieldValue($fk, $fv, $fieldTypes);
|
$tmp[] = $this->_getFieldValue($fk, $fv, $fieldTypes);
|
||||||
}
|
}
|
||||||
@@ -346,7 +357,6 @@ class db {
|
|||||||
$this->mySQLaccess = $db_ConnectionID;
|
$this->mySQLaccess = $db_ConnectionID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($result = $this->mySQLresult = $this->db_Query($query, NULL, 'db_Insert', $debug, $log_type, $log_remark ))
|
if ($result = $this->mySQLresult = $this->db_Query($query, NULL, 'db_Insert', $debug, $log_type, $log_remark ))
|
||||||
{
|
{
|
||||||
$tmp = mysql_insert_id($this->mySQLaccess);
|
$tmp = mysql_insert_id($this->mySQLaccess);
|
||||||
@@ -377,7 +387,8 @@ class db {
|
|||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function db_Update($table, $arg, $debug = FALSE, $log_type = '', $log_remark = '') {
|
function db_Update($table, $arg, $debug = FALSE, $log_type = '', $log_remark = '')
|
||||||
|
{
|
||||||
$table = $this->db_IsLang($table);
|
$table = $this->db_IsLang($table);
|
||||||
$this->mySQLcurTable = $table;
|
$this->mySQLcurTable = $table;
|
||||||
|
|
||||||
@@ -390,15 +401,29 @@ class db {
|
|||||||
if (is_array($arg)) // Remove the need for a separate db_UpdateArray() function.
|
if (is_array($arg)) // Remove the need for a separate db_UpdateArray() function.
|
||||||
{
|
{
|
||||||
$new_data = '';
|
$new_data = '';
|
||||||
$the_where = $arg['WHERE'];
|
if(!isset($arg['_FIELD_TYPES']) && !isset($arg['data']))
|
||||||
|
{
|
||||||
|
//Convert data if not using 'new' format (is this needed?)
|
||||||
|
$_tmp = array();
|
||||||
|
if(isset($arg['WHERE']))
|
||||||
|
{
|
||||||
|
$_tmp['WHERE'] = $arg['WHERE'];
|
||||||
unset($arg['WHERE']);
|
unset($arg['WHERE']);
|
||||||
|
}
|
||||||
|
$_tmp['data'] = $arg;
|
||||||
|
$arg = $_tmp;
|
||||||
|
unset($_tmp);
|
||||||
|
}
|
||||||
|
if(!isset($arg['data'])) { return false; }
|
||||||
|
var_dump($arg);
|
||||||
|
|
||||||
$fieldTypes = $this->_getTypes($arg);
|
$fieldTypes = $this->_getTypes($arg);
|
||||||
foreach ($arg as $fn => $fv)
|
foreach ($arg['data'] as $fn => $fv)
|
||||||
{
|
{
|
||||||
$new_data .= ($new_data ? ', ' : '');
|
$new_data .= ($new_data ? ', ' : '');
|
||||||
$new_data .= "`{$fn}`=".$this->_getFieldValue($fn, $fv, $fieldTypes);
|
$new_data .= "`{$fn}`=".$this->_getFieldValue($fn, $fv, $fieldTypes);
|
||||||
}
|
}
|
||||||
$arg = $new_data .' WHERE '. $the_where;
|
$arg = $new_data .(isset($arg['WHERE']) ? ' WHERE '. $arg['WHERE'] : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result = $this->mySQLresult = $this->db_Query('UPDATE '.$this->mySQLPrefix.$table.' SET '.$arg, NULL, 'db_Update', $debug, $log_type, $log_remark))
|
if ($result = $this->mySQLresult = $this->db_Query('UPDATE '.$this->mySQLPrefix.$table.' SET '.$arg, NULL, 'db_Update', $debug, $log_type, $log_remark))
|
||||||
|
@@ -9,8 +9,8 @@
|
|||||||
* Message Handler
|
* Message Handler
|
||||||
*
|
*
|
||||||
* $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $
|
* $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $
|
||||||
* $Revision: 1.35 $
|
* $Revision: 1.36 $
|
||||||
* $Date: 2008-12-24 04:51:27 $
|
* $Date: 2009-01-09 16:22:08 $
|
||||||
* $Author: mcfly_e107 $
|
* $Author: mcfly_e107 $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -149,12 +149,14 @@ class e107forum
|
|||||||
*/
|
*/
|
||||||
function postAdd($postInfo, $updateThread = true, $updateForum = true)
|
function postAdd($postInfo, $updateThread = true, $updateForum = true)
|
||||||
{
|
{
|
||||||
|
// var_dump($postInfo);
|
||||||
//Future option, will just set to true here
|
//Future option, will just set to true here
|
||||||
$addUserPostCount = true;
|
$addUserPostCount = true;
|
||||||
$result = false;
|
$result = false;
|
||||||
|
|
||||||
$e107 = e107::getInstance();
|
$e107 = e107::getInstance();
|
||||||
$postId = $e107->sql->db_Insert('forum_post', $postInfo);
|
$info['data'] = $postInfo;
|
||||||
|
$postId = $e107->sql->db_Insert('forum_post', $info);
|
||||||
$forumInfo = array();
|
$forumInfo = array();
|
||||||
|
|
||||||
if($postId && $updateThread)
|
if($postId && $updateThread)
|
||||||
@@ -176,11 +178,14 @@ class e107forum
|
|||||||
}
|
}
|
||||||
$threadInfo['thread_lastpost'] = $postInfo['post_datestamp'];
|
$threadInfo['thread_lastpost'] = $postInfo['post_datestamp'];
|
||||||
$threadInfo['thread_total_replies'] = 'thread_total_replies + 1';
|
$threadInfo['thread_total_replies'] = 'thread_total_replies + 1';
|
||||||
$threadInfo['WHERE'] = 'thread_id = '.$postInfo['post_thread'];
|
|
||||||
|
|
||||||
$threadInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
|
$info = array();
|
||||||
$threadInfo['_FIELD_TYPES']['thread_total_replies'] = 'cmd';
|
$info['data'] = $threadInfo;
|
||||||
$result = $e107->sql->db_Update('forum_thread', $threadInfo);
|
$info['WHERE'] = 'thread_id = '.$postInfo['post_thread'];
|
||||||
|
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
|
||||||
|
$info['_FIELD_TYPES']['thread_total_replies'] = 'cmd';
|
||||||
|
|
||||||
|
$result = $e107->sql->db_Update('forum_thread', $info);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,21 +202,23 @@ class e107forum
|
|||||||
$forumInfo['forum_lastpost_user_anon'] = $postInfo['post_user_anon'];
|
$forumInfo['forum_lastpost_user_anon'] = $postInfo['post_user_anon'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$info = array();
|
||||||
//If we update the thread, then we assume it was a reply, otherwise we've added a reply only.
|
//If we update the thread, then we assume it was a reply, otherwise we've added a reply only.
|
||||||
$forumInfo['_FIELD_TYPES'] = $this->fieldTypes['forum'];
|
$info['_FIELD_TYPES'] = $this->fieldTypes['forum'];
|
||||||
if($updateThread)
|
if($updateThread)
|
||||||
{
|
{
|
||||||
$forumInfo['forum_replies'] = 'forum_replies+1';
|
$forumInfo['forum_replies'] = 'forum_replies+1';
|
||||||
$forumInfo['_FIELD_TYPES']['forum_replies'] = 'cmd';
|
$info['_FIELD_TYPES']['forum_replies'] = 'cmd';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$forumInfo['forum_threads'] = 'forum_threads+1';
|
$forumInfo['forum_threads'] = 'forum_threads+1';
|
||||||
$forumInfo['_FIELD_TYPES']['forum_threads'] = 'cmd';
|
$info['_FIELD_TYPES']['forum_threads'] = 'cmd';
|
||||||
}
|
}
|
||||||
$forumInfo['forum_lastpost_info'] = $postInfo['post_datestamp'].'.'.$postInfo['post_thread'];
|
$info['data'] = $forumInfo;
|
||||||
$forumInfo['WHERE'] = 'forum_id = '.$postInfo['post_forum'];
|
$info['data']['forum_lastpost_info'] = $postInfo['post_datestamp'].'.'.$postInfo['post_thread'];
|
||||||
$result = $e107->sql->db_Update('forum', $forumInfo);
|
$info['WHERE'] = 'forum_id = '.$postInfo['post_forum'];
|
||||||
|
$result = $e107->sql->db_Update('forum', $info);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($result && USER && $addUserPostCount)
|
if($result && USER && $addUserPostCount)
|
||||||
@@ -229,11 +236,15 @@ class e107forum
|
|||||||
function threadAdd($threadInfo, $postInfo)
|
function threadAdd($threadInfo, $postInfo)
|
||||||
{
|
{
|
||||||
$e107 = e107::getInstance();
|
$e107 = e107::getInstance();
|
||||||
$threadInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
|
$info = array();
|
||||||
if($newThreadId = $e107->sql->db_Insert('forum_thread', $threadInfo))
|
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
|
||||||
|
$info['data'] = $threadInfo;
|
||||||
|
if($newThreadId = $e107->sql->db_Insert('forum_thread', $info))
|
||||||
{
|
{
|
||||||
$postInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
|
$info = array();
|
||||||
$postInfo['post_thread'] = $newThreadId;
|
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
|
||||||
|
$info['data'] = $postInfo;
|
||||||
|
$info['data']['post_thread'] = $newThreadId;
|
||||||
$newPostId = $this->postAdd($postInfo, false);
|
$newPostId = $this->postAdd($postInfo, false);
|
||||||
$this->threadMarkAsRead($newThreadId);
|
$this->threadMarkAsRead($newThreadId);
|
||||||
return array('postid' => $newPostId, 'threadid' => $newThreadId);
|
return array('postid' => $newPostId, 'threadid' => $newThreadId);
|
||||||
@@ -244,19 +255,21 @@ class e107forum
|
|||||||
function threadUpdate($threadId, $threadInfo)
|
function threadUpdate($threadId, $threadInfo)
|
||||||
{
|
{
|
||||||
$e107 = e107::getInstance();
|
$e107 = e107::getInstance();
|
||||||
$threadInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
|
$info = array();
|
||||||
$threadInfo['WHERE'] = 'thread_id = '.(int)$threadId;
|
$info['data'] = $threadInfo;
|
||||||
$e107->sql->db_Update('forum_thread', $threadInfo);
|
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
|
||||||
|
$info['WHERE'] = 'thread_id = '.(int)$threadId;
|
||||||
|
$e107->sql->db_Update('forum_thread', $info);
|
||||||
}
|
}
|
||||||
|
|
||||||
function postUpdate($postId, $postInfo)
|
function postUpdate($postId, $postInfo)
|
||||||
{
|
{
|
||||||
$e107 = e107::getInstance();
|
$e107 = e107::getInstance();
|
||||||
$postInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
|
$info = array();
|
||||||
$postInfo['WHERE'] = 'post_id = '.(int)$postId;
|
$info['data'] = $postInfo;
|
||||||
// var_dump($postInfo);
|
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
|
||||||
// exit;
|
$info['WHERE'] = 'post_id = '.(int)$postId;
|
||||||
$e107->sql->db_Update('forum_post', $postInfo);
|
$e107->sql->db_Update('forum_post', $info);
|
||||||
}
|
}
|
||||||
|
|
||||||
function threadGet($id, $joinForum = true, $uid = USERID)
|
function threadGet($id, $joinForum = true, $uid = USERID)
|
||||||
@@ -437,9 +450,11 @@ class e107forum
|
|||||||
{
|
{
|
||||||
$tmp['post_attachments'] = '_NULL_';
|
$tmp['post_attachments'] = '_NULL_';
|
||||||
}
|
}
|
||||||
$tmp['_FILE_TYPES']['post_attachments'] = 'escape';
|
$info = array();
|
||||||
$tmp['WHERE'] = 'post_id = '.$id;
|
$info['data'] = $tmp;
|
||||||
$e107->sql->db_update('forum_post', $tmp);
|
$info['_FILE_TYPES']['post_attachments'] = 'escape';
|
||||||
|
$info['WHERE'] = 'post_id = '.$id;
|
||||||
|
$e107->sql->db_update('forum_post', $info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,9 +490,11 @@ class e107forum
|
|||||||
$tmp['thread_lastuser_anon'] = ($lpInfo['post_user_anon'] ? $lpInfo['post_user_anon'] : 'Anonymous');
|
$tmp['thread_lastuser_anon'] = ($lpInfo['post_user_anon'] ? $lpInfo['post_user_anon'] : 'Anonymous');
|
||||||
}
|
}
|
||||||
$tmp['thread_lastpost'] = $lpInfo['post_datestamp'];
|
$tmp['thread_lastpost'] = $lpInfo['post_datestamp'];
|
||||||
$tmp['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
|
$info = array();
|
||||||
$tmp['WHERE'] = 'thread_id = '.$id;
|
$info['data'] = $tmp;
|
||||||
$sql->db_Update('forum_thread', $tmp);
|
$info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
|
||||||
|
$info['WHERE'] = 'thread_id = '.$id;
|
||||||
|
$sql->db_Update('forum_thread', $info);
|
||||||
|
|
||||||
return $lpInfo;
|
return $lpInfo;
|
||||||
}
|
}
|
||||||
@@ -775,8 +792,8 @@ class e107forum
|
|||||||
{
|
{
|
||||||
case 'add':
|
case 'add':
|
||||||
$tmp = array();
|
$tmp = array();
|
||||||
$tmp['track_userid'] = $uid;
|
$tmp['data']['track_userid'] = $uid;
|
||||||
$tmp['track_thread'] = $threadId;
|
$tmp['data']['track_thread'] = $threadId;
|
||||||
$result = $e107->sql->db_Insert('forum_track', $tmp);
|
$result = $e107->sql->db_Insert('forum_track', $tmp);
|
||||||
unset($tmp);
|
unset($tmp);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user