From: Javier B. <jb...@us...> - 2004-12-26 22:57:29
|
Update of /cvsroot/openbash-org/openbash-org/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1613/modules Modified Files: Quote.php Validate.php View.php common.php Log Message: cambiado sistema de validacion por uno que funciona xD; arreglada la guarrada del dbconnect en el config.php: cambiado a los constructores; aplicada cache a consultas repetitivas que no van a tener cambios casi nunca; arreglado algun bug que otro; ... Index: Quote.php =================================================================== RCS file: /cvsroot/openbash-org/openbash-org/modules/Quote.php,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Quote.php 24 Nov 2004 07:40:05 -0000 1.17 --- Quote.php 26 Dec 2004 22:57:18 -0000 1.18 *************** *** 8,14 **** class Quote { function insert_quote($quote, $author, $channel, $network, $ip) { - include ("config.php"); $view = new view(); $quote = nl2br(variable_clean($quote)); --- 8,28 ---- class Quote { + private $bd; + private $expire_cache; + + function __construct() + { + include ('config.php'); + $dsn = "$dbtype://$dbuser:$dbpass@$dbhost/$dbname"; + + $this->bd = NewADOConnection($dsn); + $this->bd->Debug = False; + $this->expire_cache = $ADODB_EXPIRE_CACHE; + } + + function __destruct() { $this->bd->Close(); } + function insert_quote($quote, $author, $channel, $network, $ip) { $view = new view(); $quote = nl2br(variable_clean($quote)); *************** *** 33,37 **** '$ip')"; ! $ins = $bd->_Execute($sql); if ($ins === false) { $view->view_non_inserted_quote(); --- 47,51 ---- '$ip')"; ! $ins = $this->bd->_Execute($sql); if ($ins === false) { $view->view_non_inserted_quote(); *************** *** 46,53 **** function get_quote($id) { - include ("config.php"); $view = new view(); $sql = "SELECT points,quote,author,channel,network,ip,pending FROM quote WHERE id='$id' AND deleted=0"; ! $quote = $bd->_Execute($sql); if($quote->RecordCount() == 1) { switch($quote->fields['pending']) { --- 60,66 ---- function get_quote($id) { $view = new view(); $sql = "SELECT points,quote,author,channel,network,ip,pending FROM quote WHERE id='$id' AND deleted=0"; ! $quote = $this->bd->CacheExecute($this->expire_cache, $sql); if($quote->RecordCount() == 1) { switch($quote->fields['pending']) { *************** *** 61,67 **** function get_quotes_by_id($order, $start, $end) { - include ("config.php"); $sql = "SELECT id FROM quote WHERE deleted=0 AND pending=0 ORDER BY id $order LIMIT $start,$end"; ! $ids = $bd->_Execute($sql); if($ids->RecordCount()) { while (!$ids->EOF) { --- 74,79 ---- function get_quotes_by_id($order, $start, $end) { $sql = "SELECT id FROM quote WHERE deleted=0 AND pending=0 ORDER BY id $order LIMIT $start,$end"; ! $ids = $this->bd->CacheExecute($this->expire_cache, $sql); if($ids->RecordCount()) { while (!$ids->EOF) { *************** *** 78,84 **** function get_quotes_by_top($top) { - include ("config.php"); $sql = "SELECT id FROM quote WHERE deleted=0 AND pending=0 ORDER BY points DESC LIMIT $top"; ! $ids = $bd->_Execute($sql); if($ids->RecordCount()) { while (!$ids->EOF) { --- 90,95 ---- function get_quotes_by_top($top) { $sql = "SELECT id FROM quote WHERE deleted=0 AND pending=0 ORDER BY points DESC LIMIT $top"; ! $ids = $this->bd->CacheExecute($this->expire_cache, $sql); if($ids->RecordCount()) { while (!$ids->EOF) { *************** *** 95,105 **** function get_quotes_by_random($points) { ! include ("config.php"); ! switch ($points) ! { case 1 : $sql ="SELECT id FROM quote WHERE points > 1 AND deleted=0 AND pending=0 ORDER BY RAND()"; break; default: $sql ="SELECT id FROM quote WHERE deleted=0 AND pending=0 ORDER BY RAND()"; break; } ! $ids = $bd->_Execute($sql); if($ids->RecordCount()) { while (!$ids->EOF) { --- 106,114 ---- function get_quotes_by_random($points) { ! switch ($points) { case 1 : $sql ="SELECT id FROM quote WHERE points > 1 AND deleted=0 AND pending=0 ORDER BY RAND()"; break; default: $sql ="SELECT id FROM quote WHERE deleted=0 AND pending=0 ORDER BY RAND()"; break; } ! $ids = $this->bd->CacheExecute($this->expire_cache, $sql); if($ids->RecordCount()) { while (!$ids->EOF) { *************** *** 116,122 **** function get_aproved_quotes() { - include ("config.php"); $sql = "SELECT COUNT(*) AS aproved FROM quote WHERE pending=0"; ! $aproved = $bd->_Execute($sql); if($aproved->RecordCount()) { return ($aproved->fields['aproved']); } else { return (0); } --- 125,130 ---- function get_aproved_quotes() { $sql = "SELECT COUNT(*) AS aproved FROM quote WHERE pending=0"; ! $aproved = $this->bd->CacheExecute($this->expire_cache, $sql); if($aproved->RecordCount()) { return ($aproved->fields['aproved']); } else { return (0); } *************** *** 125,131 **** function get_pending_quotes() { - include ("config.php"); $sql = "SELECT COUNT(*) AS pending FROM quote WHERE pending=1"; ! $pending = $bd->_Execute($sql); if($pending->RecordCount()) { return ($pending->fields['pending']); } else { return (0); } --- 133,138 ---- function get_pending_quotes() { $sql = "SELECT COUNT(*) AS pending FROM quote WHERE pending=1"; ! $pending = $this->bd->CacheExecute($this->expire_cache, $sql); if($pending->RecordCount()) { return ($pending->fields['pending']); } else { return (0); } *************** *** 134,138 **** function set_quote_score($score_id, $score_action) { - include ("config.php"); $ip = get_ipaddr(); --- 141,144 ---- *************** *** 148,152 **** $sql = "SELECT voter FROM quote WHERE id='$score_id'"; ! $voter = $bd->_Execute($sql); if (strcmp($ip, $voter->fields['voter'])) { switch ($score_action) { --- 154,158 ---- $sql = "SELECT voter FROM quote WHERE id='$score_id'"; ! $voter = $this->bd->_Execute($sql); if (strcmp($ip, $voter->fields['voter'])) { switch ($score_action) { *************** *** 157,161 **** if (isset($sql2)) { $view = new view(); ! $bd->_Execute($sql2); $view->view_updated_quote(); } --- 163,167 ---- if (isset($sql2)) { $view = new view(); ! $this->bd->_Execute($sql2); $view->view_updated_quote(); } *************** *** 168,174 **** function mail_revision_quote($id) { - include ("config.php"); $sql = "SELECT quote FROM quote WHERE id='$id'"; ! $quote = $bd->_Execute($sql); if ($quote->RecordCount()) { $q = $quote->fields['quote']; --- 174,179 ---- function mail_revision_quote($id) { $sql = "SELECT quote FROM quote WHERE id='$id'"; ! $quote = $this->bd->CacheExecute($sql); if ($quote->RecordCount()) { $q = $quote->fields['quote']; *************** *** 188,192 **** function mail_pending_quote($author, $quote, $ip) { - include ("config.php"); $rcpt = $moderator_email; $subject = "[ OpenBash ] new quote inserted by $author"; --- 193,196 ---- Index: Validate.php =================================================================== RCS file: /cvsroot/openbash-org/openbash-org/modules/Validate.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Validate.php 25 Nov 2004 14:31:45 -0000 1.4 --- Validate.php 26 Dec 2004 22:57:19 -0000 1.5 *************** *** 1,57 **** <?php ! class validate { ! function do_validate() ! { ! $view = new view(); ! if(!isset($_SESSION['logged'])) { /* if there's no session */ ! if (!isset($_POST['form']) || $_POST['form'] != 1) { /* ask for it */ ! $view->ask_login(); ! return (0); ! } else { /* if asked, verify */ ! if(!$this->check_login($_POST['login'], $_POST['passwd'])) { ! $view->ask_login(); ! return (0); ! } ! } ! } else { /* if there's session */ ! if(isset($_POST['form']) && !$this->check_login($_POST['login'], $_POST['passwd'])) { ! $view->ask_login(); ! return (0); ! } ! if(!$this->check_session()) { ! $view->ask_login(); ! return (0); ! } ! } ! return (1); ! } ! function check_login($nick, $pass) { include ('config.php'); ! $nick = variable_clean($nick); ! $pass = variable_clean($pass); ! $con = "SELECT * FROM users WHERE login LIKE \"$nick\" AND passwd LIKE MD5(\"$pass\")"; ! $res = $bd->_Execute($con); ! $res->Close(); ! if (!$res) return (0); ! //if (!strcmp($nick, $res->fields['login']) && !strcmp(md5($pass), md5($res->fields['passwd']))) { ! if ($res->RecordCount() == 1) { $_SESSION['logged'] = 1; return (1); ! } ! else { ! $_SESSION['logged'] = 0; ! return (0); ! } } ! function check_session() { ! if($_SESSION['logged'] == 1) return 1; ! else return 0; } } - ?> --- 1,40 ---- <?php ! class Validate { ! private $bd; ! function check_form($login, $passwd) { include ('config.php'); ! $dsn = "$dbtype://$dbuser:$dbpass@$dbhost/$dbname"; ! ! $this->bd = NewADOConnection($dsn); ! $this->bd->Debug = True; ! ! //$sql = "SELECT * FROM users WHERE login LIKE \"$login\" AND passwd LIKE MD5(\"$passwd\")"; ! $sql = "SELECT login FROM users WHERE login='$login' AND passwd='$passwd'"; ! ! $res = $this->bd->_Execute($sql); ! ! if ($res->RecordCount() > 0) { $_SESSION['logged'] = 1; return (1); ! } else { ! $_SESSION['logged'] = 0; ! return (0); ! } } ! function check_logged() { ! if ($_SESSION['logged'] == 1) { ! return (1); ! } elseif (isset($_POST['check_form'])) { ! if ($this->check_form($_POST['login'], $_POST['passwd']) == 1) { ! return (1); ! } ! } ! return (0); } } Index: View.php =================================================================== RCS file: /cvsroot/openbash-org/openbash-org/modules/View.php,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** View.php 24 Nov 2004 07:40:05 -0000 1.18 --- View.php 26 Dec 2004 22:57:19 -0000 1.19 *************** *** 126,130 **** <p><?=$login_language['msg']?></p> <form onsubmit="return autocheck(this)" action="?page=admin" method="post" autocomplete="off"> ! <input type="hidden" name="form" value="1"> <table border="0" width="50%"> <tr class="textoficha"> --- 126,130 ---- <p><?=$login_language['msg']?></p> <form onsubmit="return autocheck(this)" action="?page=admin" method="post" autocomplete="off"> ! <input type="hidden" name="check_form" value="1"> <table border="0" width="50%"> <tr class="textoficha"> Index: common.php =================================================================== RCS file: /cvsroot/openbash-org/openbash-org/modules/common.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** common.php 24 Nov 2004 07:40:05 -0000 1.5 --- common.php 26 Dec 2004 22:57:19 -0000 1.6 *************** *** 92,94 **** --- 92,111 ---- return $sec + $usec; } + + function uptime () + { + $fd = fopen('/proc/uptime', 'r'); + $ar_buf = split(' ', fgets($fd, 4096)); + fclose($fd); + $sys_ticks = trim($ar_buf[0]); + $min = $sys_ticks / 60; + $hours = $min / 60; + $days = floor($hours / 24); + $hours = floor($hours - ($days * 24)); + $min = floor($min - ($days * 60 * 24) - ($hours * 60)); + if ($days) $result = "$days"; + if ($hours) $result .= ":$hours"; + $result .= ":$min"; + return ($result); + } ?> |