|
Posted by bp90210 on 11/14/06 16:22
If you have a few minutes, I would like to see if anyone can help me
out. I'm trying to modify a rating script. Currently, It allows you
to vote over and over. What I want to do is after you vote it will
write your IP to a text file called ip.txt in the same folder the
script currently writes the rating.txt
('content/'.$y.'/'.$m.'/'.$entry.'/). I want it to check that ip.txt
file to see if your ip is there, if it is then it doesn't write the
new vote. I am sure this can be done rather quickly; I'm just stuck
since I do not know a lot of php (still learning).
Here is the current function. (also in text file:
http://www.margaritatexas.com/rating.txt)
// ----------------
// Rating Functions
// ----------------
function write_rating( $y, $m, $entry, $rating ) {
// Save Rating
$result_array = read_rating( $y, $m, $entry, $rating );
if ( $result_array ) {
$result_array[ 'points' ] = $result_array[ 'points' ] + $rating;
$result_array[ 'votes' ] = $result_array[ 'votes' ] + 1;
} else {
$result_array = array();
$result_array[ 'points' ] = $rating;
$result_array[ 'votes' ] = 1;
}
$str = '';
$keys = array_keys( $result_array );
for ( $i = 0; $i < count( $keys ); $i++ ) {
$key = $keys[ $i ];
if ( $i > 0 ) {
$str = $str . '|';
}
$str = $str . $key . '|' . $result_array[ $key ];
}
$dir = 'content/'.$y.'/'.$m.'/'.$entry;
if ( !file_exists( $dir ) ) {
$oldumask = umask( 0 );
$ok = mkdir( $dir, 0777 );
umask( $oldumask );
if ( !$ok ) {
return( NULL );
}
}
$filename = 'content/'.$y.'/'.$m.'/'.$entry.'/rating.txt';
sb_write_file( $filename, $str );
}
function read_rating( $y, $m, $entry ) {
// Read the rating.txt file and return the stored data.
//
// Returns NULL on fail.
$rating_path = 'content/'.$y.'/'.$m.'/'.$entry.'/';
$contents = sb_read_file( $rating_path . 'rating.txt' );
if ( $contents ) {
$result_array = array();
$data_array = explode('|', $contents);
$key_array = array( 'points', 'votes' );
for ( $i = 0; $i < count( $data_array ); $i = $i + 2 ) {
for ( $j = 0; $j < count( $key_array ); $j++ ) {
if ( $data_array[ $i ] == $key_array[ $j ] ) {
$key = $key_array[ $j ];
$result_array[ $key ] = intval( $data_array[ $i+1 ] );
}
}
}
return( $result_array );
}
}
_________________
Navigation:
[Reply to this message]
|