00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 include_once( "lib/ezdb/classes/ezdb.php" );
00041
00042 class eZTipafriendRequest extends eZPersistentObject
00043 {
00044
00045
00046
00047 function eZTipafriendRequest( $row )
00048 {
00049 $this->eZPersistentObject( $row );
00050 }
00051
00052 function definition()
00053 {
00054 return array( "fields" => array( 'email_receiver' => array( 'name' => 'EmailReceiver',
00055 'datatype' => 'string',
00056 'default' => '',
00057 'required' => true ),
00058 'created' => array( 'name' => 'Created',
00059 'datatype' => 'integer',
00060 'default' => 0,
00061 'required' => true ) ),
00062 'keys' => array( 'email_receiver' ),
00063 'class_name' => 'eZTipafriendRequest',
00064 'sort' => array( 'created' => 'desc' ),
00065 'name' => 'eztipafriend_request' );
00066 }
00067
00068 function create( $receiver )
00069 {
00070 $row = array( "email_receiver" => $receiver,
00071 "created" => time() );
00072 return new eZTipafriendRequest( $row );
00073 }
00074
00075 function checkReceiver( $receiver )
00076 {
00077 eZTipafriendRequest::cleanup();
00078 $ini = eZINI::instance();
00079 $timeFrame = 1;
00080 if ( $ini->hasVariable( 'TipAFriend', 'TimeFrame' ) )
00081 $timeFrame = $ini->variable( 'TipAFriend', 'TimeFrame' );
00082 $time = time() - $timeFrame * 3600;
00083 $requestsPerTimeframe = 1;
00084 if ( $ini->hasVariable( 'TipAFriend', 'MaxRequestsPerTimeframe' ) )
00085 $requestsPerTimeframe = $ini->variable( 'TipAFriend', 'MaxRequestsPerTimeframe' );
00086
00087 $db = eZDB::instance();
00088 $receiver = $db->escapeString( $receiver );
00089 $countResult = $db->arrayQuery( "SELECT count(*) as count
00090 FROM eztipafriend_request
00091 WHERE email_receiver = '$receiver'
00092 AND created > $time " );
00093 $count = 0;
00094 if ( isset( $countResult[0]['count'] ) )
00095 $count = $countResult[0]['count'];
00096 if ( $count >= $requestsPerTimeframe )
00097 return false;
00098 return true;
00099 }
00100
00101
00102
00103
00104
00105 function cleanup()
00106 {
00107 $ini = eZINI::instance();
00108 $db = eZDB::instance();
00109 $timeFrame = 1;
00110 if ( $ini->hasVariable( 'TipAFriend', 'TimeFrame' ) )
00111 $timeFrame = $ini->variable( 'TipAFriend', 'TimeFrame' );
00112 $time = time() - $timeFrame * 3600;
00113
00114 $db->query( "DELETE FROM eztipafriend_request
00115 WHERE created < $time " );
00116 }
00117
00118 }
00119
00120 ?>