 |
|
Thue
|
|
Copenhagen, Denmark
Jan 1970 time: 06:14
|
|
I am by no means a perl wizard, but if you would describe the problem I can see if I can help!
|
|
|  |
 |
|  |
 |
|
|
of course, what do stupid windows people know about perl? 
ok, I've added this code on one of the forums scripts which limits the numbers of threads one can make per X days to 1(this is enabled only for the off-topic forum)
code: # Multiple post per day check
if (($Status ne "Administrator") && ($Status ne "Moderator")) {
if ($number == 23) {
$numDaysToWait = 1;
@finalPList = ();
$nowListTime = time;
if (-e "$MembersPath/postedlist.cgi") {
open (POSTED, "$MembersPath/postedlist.cgi");
@postedList = ;
close (POSTED);
foreach $hasPosted (@postedList) {
($UserHP, $DateHP, $ForumNumHP) = split(/\|\!\|/, $hasPosted);
chomp($ForumNumHP);
if (($nowListTime - $DateHP) < ($numDaysToWait * 86400)) {
push @finalPList, $hasPosted;
if (($UserHP eq $UserName) && ($ForumNumHP == $number)) {
&StandardHTML("Sorry, but you may only post one new
topic in this forum once every $numDaysToWait day.");
exit;
}
}
}
}
open (POSTED, ">$MembersPath/postedlist.cgi");
print POSTED @finalPList;
print POSTED "$UserName|!|$nowListTime|!|$number\n";
close (POSTED);
chmod (0666, "$MembersPath/postedlist.cgi");
}
}
I want to limit a poster to X number of threads for X days(instead of 1 thread for X days)
I'm sure it's something easy, but above my level of perl knowledge 
|
|
|  |
 |
|
Mark von Wagner
|
 |
Albert in a Can
May 1999 time: 00:14
|
|
I've never written a PERL program before, so I don't know how good or bad my style is, but this should do the job (give or take a few syntax errors).
if ((($Status ne "Administrator") && ($Status ne "Moderator")) | | ($UserName ne "Mark von Wagner")) {
if ($number == 23) {
$numDaysToWait = 1;
$numberOfThreads = 3;
@finalPList = ();
$nowListTime = time;
if (-e "$MembersPath/postedlist.cgi") {
open (POSTED, "$MembersPath/postedlist.cgi");
@postedList = ;
close (POSTED);
$userFound = 0;
foreach $hasPosted (@postedList) {
@DateHPs = ();
$slotsFound = 0;
($UserHP,$ForumNumHP,$DateHP) = split(/\|\!\|/, $hasPosted, 3);
chomp($DateHP);
for($counter1 = 0; $counter1 < $numberOfThreads; $counter1++) {
($dateTemp, $DateHP) = split(/\|\!\|/, $hasPosted, 2);
push @DateHPs, $dateTemp;
if(($nowListTime - $dateTemp) > ($numDaysToWait * 86400)) {
$slotsFound++;
}
}
if (($UserHP eq $UserName) && ($ForumNumHP == $number)) {
$userFound = 1;
if($slotsFound == 0) {
&StandardHTML("Sorry, but you may only post $numberOfThreads new topics in this forum every 24 hours.");
exit;
}
else {
$flag1 = 0;
$slotsFound = $slotsFound - 1;
$hasPosted = sprintf("%s|!|%s", $UserHP,$ForumNumHP);
foreach $dateTemp(@DateHPs) {
if ((($nowListTime - $dateTemp) > ($numDaysToWait * 86400)) && ($flag1 == 0)) {
$flag1 = 1;
$dateTemp = $nowListTime;
}
$hasPosted = sprintf("%s|!|%d",$hasPosted,$dateTemp);
}
}
push @finalPList, $hasPosted;
}
else if (($slotsFound < $numberOfThreads)) {
$hasPosted = sprintf("%s|!|%s", $UserHP,$ForumNumHP);
foreach $dateTemp(@DateHPs) {
$hasPosted = sprintf("%s|!|%d",$hasPosted,$dateTemp);
}
push @finalPList, $hasPosted;
}
}
if($userFound == 0){
$oldListTime = $nowListTime - 86400 * numDaysToWait;
$hasPosted = sprintf("%s|!|%s|!|%d", $UserHP,$ForumNumHP, $nowListTime);
for($counter1 = 0; $counter1 < $numberOfThreads; $counter1++) {
$hasPosted = sprintf("%s|!|%d",$hasPosted,$oldListTime);
}
push @finalPList, $hasPosted;
}
}
open (POSTED, ">$MembersPath/postedlist.cgi");
print POSTED @finalPList;
close (POSTED);
chmod (0666, "$MembersPath/postedlist.cgi");
}
}
Edit: Corrected indenting
[This message has been edited by Mark von Wagner (edited June 17, 2000).]
|
|
|  |
 |
|
Thue
|
|
Copenhagen, Denmark
Jan 1970 time: 06:14
|
|
Now, I don't have time for a real review right now, but reading the first line
if ((($Status ne "Administrator") && ($Status ne "Moderator")) | | ($UserName ne "Mark von Wagner")) {
The last | | should be an &&
|
|
|  |
 |
|
|
actually, the | | ($UserName ne "Mark von Wagner") part shouldnt exist 
thanks Mark I'll give it a try
|
|
|  |
 |
|
|
minor problem 1
this code
code: else if (($slotsFound < $numberOfThreads)) {
should be
code: else {
if (($slotsFound < $numberOfThreads)) {
with a } at the end of the if...
else if does not work on perl
[This message has been edited by MarkG (edited June 17, 2000).]
|
|
|  |
 |
|
|
bgier problem: something is wrong and the scripts write wrong things on the file...
|
|
|  |
 |
|
Mark von Wagner
|
 |
Albert in a Can
May 1999 time: 00:14
|
|
Sorry about the problems in my first version. As you can probably tell, I do most of my programming in C++, where things like "else if" are valid. Here is a corrected version that, at least in my tests, works correctly.
if (($Status ne "Administrator") && ($Status ne "Moderator")) {
if ($number == 23) {
$numDaysToWait = 1;
$numberOfThreads = 3;
$userFound = 0;
@finalPList = ();
$nowListTime = time;
if (-e "$MembersPath/postedlist.cgi") {
open (POSTED, "$MembersPath/postedlist.cgi");
@postedList = ;
close (POSTED);
foreach $hasPosted (@postedList) {
@DateHPs = ();
$slotsFound = 0;
($UserHP,$ForumNumHP,$DateHP) = split(/\|\!\|/, $hasPosted, 3);
chomp($DateHP);
for($counter1 = 0; $counter1 < $numberOfThreads; $counter1++) {
($dateTemp, $DateHP) = split(/\|\!\|/, $DateHP, 2);
push @DateHPs, $dateTemp;
if(($nowListTime - $dateTemp) > ($numDaysToWait * 86400)) {
$slotsFound++;
}
}
if (($UserHP eq $UserName) && ($ForumNumHP == $number)) {
$userFound = 1;
if($slotsFound == 0) {
&StandardHTML("Sorry, but you may only post $numberOfThreads new topics in this forum every 24 hours.");
exit;
}
else {
$flag1 = 0;
$slotsFound = $slotsFound - 1;
$hasPosted = sprintf("%s|!|%s", $UserHP,$ForumNumHP);
foreach $dateTemp(@DateHPs) {
if ((($nowListTime - $dateTemp) > ($numDaysToWait * 86400)) && ($flag1 == 0)) {
$flag1 = 1;
$dateTemp = $nowListTime;
}
$hasPosted = sprintf("%s|!|%d",$hasPosted,$dateTemp);
}
}
$hasPosted = sprintf("%s\n",$hasPosted);
push @finalPList, $hasPosted;
}
else {
if (($slotsFound < $numberOfThreads)) {
$hasPosted = sprintf("%s|!|%s", $UserHP,$ForumNumHP);
foreach $dateTemp(@DateHPs) {
$hasPosted = sprintf("%s|!|%d",$hasPosted,$dateTemp);
}
$hasPosted = sprintf("%s\n",$hasPosted);
push @finalPList, $hasPosted;
}
}
}
}
if($userFound == 0){
$oldListTime = $nowListTime - (86400 * $numDaysToWait);
$hasPosted = sprintf("%s|!|%s|!|%d", $UserName,$number, $nowListTime);
for($counter1 = 1; $counter1 < $numberOfThreads; $counter1++) {
$hasPosted = sprintf("%s|!|%d",$hasPosted,$oldListTime);
}
$hasPosted = sprintf("%s\n",$hasPosted);
push @finalPList, $hasPosted;
}
open (POSTED, ">$MembersPath/postedlist.cgi");
print POSTED @finalPList;
close (POSTED);
chmod (0666, "$MembersPath/postedlist.cgi");
}
}
[This message has been edited by Mark von Wagner (edited June 17, 2000).]
|
|
|  |
 |
|  |
 |
|
|
In regards to a post in the Apolyton forum:
BUMP
*sounds of 6367 feet tapping*
Edit: just testing a hypothesis...
[This message has been edited by Richard Cranium (edited July 21, 2000).]
|
|
|  |
 |
|
Murgatroyd
|
|
95 South, 113 West
Feb 2000 time: 21:14
|
|
In regards to a post in the Off-Topic forum:
BUMP
*sounds of 6717 feet tapping*
|
|
|  |
 |
|
Murgatroyd
|
|
95 South, 113 West
Feb 2000 time: 21:14
|
|
An additional BUMP. This thread will not be forgotten!
|
|
|  |
 |
|
|
I don't consider myself a perl wizard. A perl sourcerer, maybe.
|
|
|  |
 |
|
|
this thread has served it's purpose
lets leave the forum for it's real use...
|
|
|  |
All times are GMT. The time now is 05:14. Apolyton Time is 00:14. |
top of page
|
|
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|