[geeklog-cvs] geeklog-1.3/public_html lib-common.php,1.218,1.219 submit.php,1.51,1.52

geeklog-cvs-admin at lists.geeklog.net geeklog-cvs-admin at lists.geeklog.net
Mon May 5 12:52:37 EDT 2003


Update of /usr/cvs/geeklog/geeklog-1.3/public_html
In directory internal.geeklog.net:/tmp/cvs-serv5089/public_html

Modified Files:
	lib-common.php submit.php 
Log Message:
Replaced separate commentspeedlimit and submitspeedlimit tables with a general speedlimit table and new COM_ functions operating on it.


Index: lib-common.php
===================================================================
RCS file: /usr/cvs/geeklog/geeklog-1.3/public_html/lib-common.php,v
retrieving revision 1.218
retrieving revision 1.219
diff -C2 -d -r1.218 -r1.219
*** lib-common.php	28 Apr 2003 08:15:33 -0000	1.218
--- lib-common.php	5 May 2003 16:52:35 -0000	1.219
***************
*** 4551,4554 ****
--- 4551,4612 ----
  
  /**
+ * Check if speed limit applies for current IP address.
+ *
+ * @param type   string   type of speed limit to check, e.g. 'submit', 'comment'
+ * @return       int      0 = does not apply, else: seconds since last post
+ */
+ function COM_checkSpeedlimit ($type = 'submit')
+ {
+     global $_TABLES, $REMOTE_ADDR;
+ 
+     $last = 0;
+ 
+     $date = DB_getItem ($_TABLES['speedlimit'], 'date',
+                         "(type = '$type') AND (ipaddress = '$REMOTE_ADDR')");
+     if (!empty ($date)) {
+         $last = time () - $date;
+         if ($last == 0) {
+             // just in case someone manages to submit something in < 1 sec.
+             $last = 1;
+         }
+     }
+ 
+     return $last;
+ }
+ 
+ /**
+ * Store post info for current IP address.
+ *
+ * @param type   string   type of speed limit, e.g. 'submit', 'comment'
+ *
+ */
+ function COM_updateSpeedlimit ($type = 'submit')
+ {
+     global $_TABLES, $REMOTE_ADDR;
+ 
+     DB_save ($_TABLES['speedlimit'], 'ipaddress,date,type',
+              "'$REMOTE_ADDR',unix_timestamp(),'$type'");
+ }
+ 
+ /**
+ * Clear out expired speed limits, i.e. entries older than 'x' seconds
+ *
+ * @param speedlimit   int      number of seconds
+ * @param type         string   type of speed limit, e.g. 'submit', 'comment'
+ *
+ */
+ function COM_clearSpeedlimit ($speedlimit = 60, $type = '')
+ {
+     global $_TABLES;
+ 
+     $sql = "DELETE FROM {$_TABLES['speedlimit']} WHERE ";
+     if (!empty ($type)) {
+         $sql .= "(type = '$type') AND ";
+     }
+     $sql .= "(date < unix_timestamp() - $speedlimit)";
+     DB_query ($sql);
+ }
+ 
+ /**
  * Wrapper function for URL class so as to not confuse people as this will eventually get
  * used all over the place

Index: submit.php
===================================================================
RCS file: /usr/cvs/geeklog/geeklog-1.3/public_html/submit.php,v
retrieving revision 1.51
retrieving revision 1.52
diff -C2 -d -r1.51 -r1.52
*** submit.php	24 Mar 2003 17:42:17 -0000	1.51
--- submit.php	5 May 2003 16:52:35 -0000	1.52
***************
*** 59,71 ****
      $retval = '';
  	
!     DB_query("DELETE FROM {$_TABLES['submitspeedlimit']} WHERE date < unix_timestamp() - {$_CONF["speedlimit"]}");
! 
!     $id = DB_count($_TABLES['submitspeedlimit'],'ipaddress',$REMOTE_ADDR);
  
!     if ($id > 0) {
!         $result = DB_query("SELECT date FROM {$_TABLES['submitspeedlimit']} WHERE ipaddress = '$REMOTE_ADDR'");
!         $A = DB_fetchArray($result);
  
!         $last = time() - $A['date'];
          $retval .= COM_startBlock($LANG12[26])
              . $LANG12[30]
--- 59,67 ----
      $retval = '';
  	
!     COM_clearSpeedlimit ($_CONF['speedlimit'], 'submit');
  
!     $last = COM_checkSpeedlimit ('submit');
  
!     if ($last > 0) {
          $retval .= COM_startBlock($LANG12[26])
              . $LANG12[30]
***************
*** 551,555 ****
              }
              $A['lid'] = COM_makeSid();
!             DB_save($_TABLES['submitspeedlimit'],'ipaddress, date',"'$REMOTE_ADDR',unix_timestamp()");
              if (($_CONF['linksubmission'] == 1) && !SEC_hasRights('link.submit')) {
                  $result = DB_save($_TABLES['linksubmission'],'lid,category,url,description,title,date',"{$A["lid"]},'{$A["category"]}','{$A["url"]}','{$A["description"]}','{$A['title']}',NOW()",$_CONF['site_url']."/index.php?msg=3");
--- 547,551 ----
              }
              $A['lid'] = COM_makeSid();
!             COM_updateSpeedlimit ('submit');
              if (($_CONF['linksubmission'] == 1) && !SEC_hasRights('link.submit')) {
                  $result = DB_save($_TABLES['linksubmission'],'lid,category,url,description,title,date',"{$A["lid"]},'{$A["category"]}','{$A["url"]}','{$A["description"]}','{$A['title']}',NOW()",$_CONF['site_url']."/index.php?msg=3");
***************
*** 609,613 ****
              }
  
!             DB_save($_TABLES['submitspeedlimit'],'ipaddress, date',"'$REMOTE_ADDR',unix_timestamp()");
  
              if ($A['allday'] == 'on') {
--- 605,609 ----
              }
  
!             COM_updateSpeedlimit ('submit');
  
              if ($A['allday'] == 'on') {
***************
*** 670,684 ****
      default:
          if ((strlen($type) > 0) && ($type <> 'story')) {
!             // Update the submitspeedlimit for user - assuming Plugin approves submission record
!     		DB_save($_TABLES['submitspeedlimit'],'ipaddress, date',"'$REMOTE_ADDR',unix_timestamp()");
!             // see if this is a submission that needs to be handled by a plugin and should include it's own redirect
! 			if (!PLG_saveSubmission($type, $A)) {
! 			    COM_errorLog("Could not save your submission.  Bad type: $type");
! 			}	
! 			// plugin and should include it's own redirect - but in case handle it here and redirect to the main page
! 			$retval = COM_refresh ($_CONF['site_url'] . '/index.php');
              return $retval;
-             
          }
          if (!empty($A['title']) && !empty($A['introtext'])) {
              $A['title'] = addslashes(strip_tags(COM_checkWords($A['title'])));
--- 666,684 ----
      default:
          if ((strlen($type) > 0) && ($type <> 'story')) {
!             // Update the submitspeedlimit for user - assuming Plugin approves
!             // submission record
!             COM_updateSpeedlimit ('submit');
! 
!             // see if this is a submission that needs to be handled by a plugin
!             // and should include it's own redirect
!             if (!PLG_saveSubmission($type, $A)) {
!                 COM_errorLog("Could not save your submission.  Bad type: $type");
!             }	
!             // plugin should include it's own redirect - but in case handle
!             // it here and redirect to the main page
!             $retval = COM_refresh ($_CONF['site_url'] . '/index.php');
              return $retval;
          }
+ 
          if (!empty($A['title']) && !empty($A['introtext'])) {
              $A['title'] = addslashes(strip_tags(COM_checkWords($A['title'])));
***************
*** 694,698 ****
                  $_USER['uid'] = 1;
              }					
!             DB_save($_TABLES['submitspeedlimit'],'ipaddress, date',"'$REMOTE_ADDR',unix_timestamp()");
              if (($_CONF['storysubmission'] == 1) && !SEC_hasRights('story.submit')) {
                  DB_save($_TABLES['storysubmission'],"sid,tid,uid,title,introtext,date,postmode","{$A["sid"]},'{$A["tid"]}',{$_USER['uid']},'{$A['title']}','{$A["introtext"]}',NOW(),'{$A["postmode"]}'",$_CONF['site_url']."/index.php?msg=2");
--- 694,698 ----
                  $_USER['uid'] = 1;
              }					
!             COM_updateSpeedlimit ('submit');
              if (($_CONF['storysubmission'] == 1) && !SEC_hasRights('story.submit')) {
                  DB_save($_TABLES['storysubmission'],"sid,tid,uid,title,introtext,date,postmode","{$A["sid"]},'{$A["tid"]}',{$_USER['uid']},'{$A['title']}','{$A["introtext"]}',NOW(),'{$A["postmode"]}'",$_CONF['site_url']."/index.php?msg=2");





More information about the geeklog-cvs mailing list