1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-25 00:41:52 +02:00

More mysql_class field type changes. Forum updates to use it.

This commit is contained in:
mcfly
2008-11-29 01:24:27 +00:00
parent ef08ad6909
commit d01bf3a3ff
7 changed files with 160 additions and 58 deletions

View File

@@ -12,8 +12,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/mysql_class.php,v $
| $Revision: 1.27 $
| $Date: 2008-11-27 20:13:58 $
| $Revision: 1.28 $
| $Date: 2008-11-29 01:24:27 $
| $Author: mcfly_e107 $
|
+----------------------------------------------------------------------------+
@@ -30,7 +30,7 @@ $db_ConnectionID = NULL; // Stores ID for the first DB connection used - which s
* MySQL Abstraction class
*
* @package e107
* @version $Revision: 1.27 $
* @version $Revision: 1.28 $
* @author $Author: mcfly_e107 $
*/
class db {
@@ -310,11 +310,12 @@ class db {
$this->mySQLcurTable = $table;
if(is_array($arg))
{
$fieldTypes = $this->_getTypes($arg);
$keyList= "`".implode("`,`", array_keys($arg))."`";
$tmp = array();
foreach($arg as $fv)
foreach($arg as $fk => $fv)
{
$tmp[] = $this->_getFieldValue($fv);
$tmp[] = $this->_getFieldValue($fk, $fv, $fieldTypes);
}
$valList= implode(', ', $tmp);
unset($tmp);
@@ -332,10 +333,13 @@ class db {
}
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);
return ($tmp) ? $tmp : TRUE; // return true even if table doesn't have auto-increment.
} else {
}
else
{
$this->dbError("db_Insert ($query)");
return FALSE;
}
@@ -372,12 +376,15 @@ class db {
if (is_array($arg)) // Remove the need for a separate db_UpdateArray() function.
{
$new_data = '';
print_a($arg);
$the_where = $arg['WHERE'];
unset($arg['WHERE']);
echo "where = {$the_where} <br />";
$fieldTypes = $this->_getTypes($arg);
foreach ($arg as $fn => $fv)
{
$new_data .= ($new_data ? ', ' : '');
$new_data .= "`{$fn}`=".$this->_getFieldValue($fv);
$new_data .= "`{$fn}`=".$this->_getFieldValue($fn, $fv, $fieldTypes);
}
$arg = $new_data .' WHERE '. $the_where;
}
@@ -395,6 +402,25 @@ class db {
}
}
function _getTypes(&$arg)
{
if(isset($arg['_FIELD_TYPES']))
{
if(!isset($arg['_FIELD_TYPES']['_DEFAULT']))
{
$arg['_FIELD_TYPES']['_DEFAULT'] = 'todb';
}
$fieldTypes = $arg['_FIELD_TYPES'];
unset($arg['_FIELD_TYPES']);
}
else
{
$fieldTypes = array();
$fieldTypes['_DEFAULT'] = 'string';
}
return $fieldTypes;
}
/**
* @return mixed
* @param string|array $fieldValue
@@ -402,30 +428,30 @@ class db {
*
* @access private
*/
function _getFieldValue($fieldValue)
function _getFieldValue($fieldKey, $fieldValue, &$fieldTypes)
{
if(!is_array($fieldValue))
{
return "'{$fieldValue}'";
}
if($fieldValue == '_NULL_') { return 'NULL';}
$type = (isset($fieldTypes[$fieldKey]) ? $fieldTypes[$fieldKey] : $fieldTypes['_DEFAULT']);
switch ($fieldValue[0])
switch ($type)
{
case 'int':
return (int)$fieldValue[1];
return (int)$fieldValue;
break;
case 'cmd':
return $fieldValue[1];
return $fieldValue;
break;
case 'string':
return "'{$fieldValue}'";
break;
case 'todb':
$e107 = e107::getInstance();
return "'".$e107->tp->toDB($fieldValue[1])."'";
break;
default:
return "'{$fieldValue[1]}'";
if($fieldValue == '') { return ''; }
$e107 = e107::getInstance();
return "'".$e107->tp->toDB($fieldValue)."'";
break;
}
}

View File

@@ -9,8 +9,8 @@
* Forum admin functions
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_admin_class.php,v $
* $Revision: 1.3 $
* $Date: 2008-11-26 19:59:06 $
* $Revision: 1.4 $
* $Date: 2008-11-29 01:24:27 $
* $Author: mcfly_e107 $
*
*/
@@ -394,6 +394,13 @@ class forumAdmin
$row = $e107->sql->db_Fetch(MYSQL_ASSOC);
}
}
else
{
$row = array();
$row['forum_name'] = '';
$row['forum_class'] = e_UC_PUBLIC;
$row['forum_postclass'] = e_UC_MEMBER;
}
$text = "<div style='text-align:center'>
<form method='post' action='".e_SELF.'?'.e_QUERY."'>
@@ -449,6 +456,15 @@ class forumAdmin
$fInfo = $e107->sql->db_Fetch();
}
}
else
{
$fInfo = array(
'forum_parent' => 0,
'forum_moderators' => e_UC_ADMIN,
'forum_class' => e_UC_PUBLIC,
'forum_postclass' => e_UC_MEMBER
);
}
$text = "<div style='text-align:center'>
<form method='post' action='".e_SELF.'?'.e_QUERY."'>\n

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_class.php,v $
| $Revision: 1.10 $
| $Date: 2008-11-27 03:02:26 $
| $Revision: 1.11 $
| $Date: 2008-11-29 01:24:27 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -21,10 +21,26 @@ if (!defined('e107_INIT')) { exit; }
class e107forum
{
var $permList = array();
var $fieldTypes = array();
function e107forum()
{
$this->loadPermList();
$this->fieldTypes['forum_post']['post_user'] = 'int';
$this->fieldTypes['forum_post']['post_forum'] = 'int';
$this->fieldTypes['forum_post']['post_datestamp'] = 'int';
$this->fieldTypes['forum_post']['post_thread'] = 'int';
$this->fieldTypes['forum_thread']['thread_user'] = 'int';
$this->fieldTypes['forum_thread']['thread_lastpost'] = 'int';
$this->fieldTypes['forum_thread']['thread_lastuser'] = 'int';
$this->fieldTypes['forum_thread']['thread_s'] = 'int';
$this->fieldTypes['forum_thread']['thread_forum_id'] = 'int';
$this->fieldTypes['forum_thread']['thread_active'] = 'int';
$this->fieldTypes['forum_thread']['thread_datestamp'] = 'int';
$this->fieldTypes['forum_thread']['thread_views'] = 'int';
$this->fieldTypes['forum_thread']['thread_replies'] = 'int';
// print_a($this->permList);
}
@@ -98,11 +114,13 @@ class e107forum
*
* If threadinfo is given, then we're adding a new thread.
* We must get thread_id to provide to postInfo after insertion
*/
function postAdd($postInfo, $updateThread = true)
*/
function postAdd($postInfo, $updateThread = true, $updateForum = true)
{
$e107 = e107::getInstance();
$result = $e107->sql->db_Insert('forum_post', $postInfo, true);
$forumInfo = array();
if($result && $updateThread)
{
$threadInfo = array();
@@ -110,34 +128,73 @@ class e107forum
{
$threadInfo['thread_lastuser'] = $postInfo['post_user'];
$threadInfo['thread_lastuser_anon'] = '';
$forumInfo['forum_lastpost_user'] = $postInfo['post_user'];
$forumInfo['forum_lastpost_user_anon'] = '';
}
else
{
$threadInfo['thread_lastuser'] = array('int', 0);
$threadInfo['thread_lastuser'] = 0;
$threadInfo['thread_lastuser_anon'] = $postInfo['post_anon_name'];
$forumInfo['forum_lastpost_user'] = 0;
$forumInfo['forum_lastpost_user_anon'] = $postInfo['post_anon_name'];
}
$threadInfo['thread_lastpost'] = array('int', $postInfo['post_datestamp']);
$threadInfo['thread_total_replies'] = array('cmd', 'thread-total_replies + 1');
$threadInfo['thread_lastpost'] = $postInfo['post_datestamp'];
$threadInfo['thread_total_replies'] = 'thread-total_replies + 1';
$threadInfo['WHERE'] = 'thread_id = '.$postInfo['post_thread'];
$threadInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
$threadInfo['_FIELD_TYPES']['thread_total_replies'] = 'cmd';
$result = $e107->sql->db_Update('forum_thread', $threadInfo, true);
}
if($result && $updateForum)
{
if(varset($postInfo['post_user']))
{
$forumInfo['forum_lastpost_user'] = $postInfo['post_user'];
$forumInfo['forum_lastpost_user_anon'] = '_NULL_';
}
else
{
$forumInfo['forum_lastpost_user'] = 0;
$forumInfo['forum_lastpost_user_anon'] = $postInfo['post_anon_name'];
}
//If we updated the thread, then we assume it was a reply, otherwise we've added a reply only.'
$forumInfo['_FIELD_TYPES'] = $this->fieldTypes['forum'];
if($updateThread)
{
$forumInfo['forum_replies'] = 'forum_replies+1';
$forumInfo['_FIELD_TYPES']['forum_replies'] = 'cmd';
}
else
{
$forumInfo['forum_threads'] = 'forum_threads+1';
$forumInfo['_FIELD_TYPES']['forum_threads'] = 'cmd';
}
$forumInfo['forum_lastpost_info'] = $postInfo['post_datestamp'].'.'.$postInfo['post_thread'];
$forumInfo['WHERE'] = 'forum_id = '.$postInfo['post_forum'];
// print_a($forumInfo);
$result = $e107->sql->db_Update('forum', $forumInfo, true);
}
}
function threadAdd($threadInfo, $postInfo)
{
$e107 = e107::getInstance();
$threadInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
if($result = $e107->sql->db_Insert('forum_thread', $threadInfo, true))
{
$postInfo['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
$postInfo['post_thread'] = $result;
$result = $this->postAdd($postInfo, false);
}
}
function threadUpdate($threadInfo, $inc)
{
$e107 = e107::getInstance();
}
function thread_postnum($thread_id)
{
@@ -503,7 +560,7 @@ class e107forum
t.thread_s DESC,
t.thread_lastpost DESC
LIMIT ".(int)$from.','.(int)$view;
$ret = array();
if ($e107->sql->db_Select_gen($qry))
{

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_post.php,v $
| $Revision: 1.18 $
| $Date: 2008-11-27 03:02:26 $
| $Revision: 1.19 $
| $Date: 2008-11-29 01:24:27 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -215,7 +215,7 @@ if (isset($_POST['newthread']) || isset($_POST['reply']))
}
else
{
if ($fp->flood('forum_t', 'thread_datestamp') == false && !ADMIN)
if ($fp->flood('forum_thread', 'thread_datestamp') == false && !ADMIN)
{
echo "<script type='text/javascript'>document.location.href='".e_BASE."index.php'</script>\n";
exit;
@@ -228,29 +228,36 @@ if (isset($_POST['newthread']) || isset($_POST['reply']))
$postInfo['post_user'] = USERID;
$threadInfo['thread_lastuser'] = USERID;
$threadInfo['thread_user'] = USERID;
$threadInfo['thread_lastuser_anon'] = '';
}
else
{
$postInfo['post_anon_name'] = $e107->tp->toDB($_POST['anonname']);
$threadInfo['thread_lastuser'] = $postInfo['post_anon_name'];
$threadInfo['thread_user_anon'] = $postInfo['post_anon_name'];
$postInfo['post_user_anon'] = $_POST['anonname'];
$threadInfo['thread_lastuser_anon'] = $_POST['anonname'];
$threadInfo['thread_user_anon'] = $_POST['anonname'];
}
$time = time();
$postInfo['post_entry'] = $e107->tp->toDB($_POST['post']);
$time = time();
$postInfo['post_entry'] = $_POST['post'];
$postInfo['post_forum'] = $forum_id;
$postInfo['post_datestamp'] = $time;
$threadInfo['thread_lastpost'] = $time;
switch($action)
{
// Reply only. Add the post, update thread record with latest post info.
// Update forum with latest post info
case 'rp':
$postInfo['post_thread'] = $id;
$result = $forum->postAdd($postInfo);
break;
// New thread started. Add the thread info (with lastest post info), add the post.
// Update forum with latest post info
case 'nt':
$threadInfo['thread_s'] = (MODERATOR ? (int)$_POST['threadtype'] : 0);
$threadInfo['thread_name'] = $e107->tp->toDB($_POST['subject']);
$threadInfo['thread_s'] = (MODERATOR ? $_POST['threadtype'] : 0);
$threadInfo['thread_name'] = $_POST['subject'];
$threadInfo['thread_forum_id'] = $forum_id;
$threadInfo['thread_active'] = 1;
$threadInfo['thread_datestamp'] = $time;
@@ -264,8 +271,8 @@ if (isset($_POST['newthread']) || isset($_POST['reply']))
// {
// $subject = "[".LAN_402."] ".$subject;
// }
print_a($threadInfo);
print_a($postInfo);
// print_a($threadInfo);
// print_a($postInfo);
exit;
$result = $forum->postAdd($postInfo, $threadInfo);

View File

@@ -28,6 +28,7 @@ CREATE TABLE forum_thread (
`thread_active` tinyint(3) unsigned NOT NULL default '0',
`thread_lastpost` int(10) unsigned NOT NULL default '0',
`thread_s` tinyint(1) unsigned NOT NULL default '0',
`thread_datestamp` int(10) unsigned default NULL,
`thread_user` int(10) unsigned default NULL,
`thread_user_anon` varchar(30) NULL,
`thread_lastuser` int(10) unsigned default NULL,

View File

@@ -11,16 +11,15 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/forum/forum_viewtopic.php,v $
| $Revision: 1.1.1.1 $
| $Date: 2006-12-02 04:35:15 $
| $Revision: 1.2 $
| $Date: 2008-11-29 01:24:27 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
require_once('../../class2.php');
include_once e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum_viewtopic.php';
include_once e_PLUGIN.'forum/languages/English/lan_forum_viewtopic.php';
include_lan(e_PLUGIN.'forum/languages/English/lan_forum_viewtopic.php');
include_once(e_PLUGIN.'forum/forum_class.php');
@@ -35,11 +34,7 @@ if (isset($_POST['fjsubmit']))
header("location:".e_PLUGIN."forum/forum_viewforum.php?".$_POST['forumjump']);
exit;
}
$highlight_search = FALSE;
if (isset($_POST['highlight_search']))
{
$highlight_search = TRUE;
}
$highlight_search = isset($_POST['highlight_search']);
if (!e_QUERY)
{

View File

@@ -1,11 +1,11 @@
<?php
// $Id: forum.php,v 1.3 2008-11-26 19:59:06 mcfly_e107 Exp $
// $Id: forum.php,v 1.4 2008-11-29 01:24:27 mcfly_e107 Exp $
function url_forum_forum($parms)
{
switch($parms['func'])
{
case 'view':
return e_PLUGIN_ABS."forum/viewforum.php?{$parms['id']}";
return e_PLUGIN_ABS."forum/viewforum.php?id={$parms['id']}";
break;
case 'track':