Jump to content

Need a little help with a script...


Padgoi

Recommended Posts

So my site uses IPB (Invision Power Boards).  One of the features of IPB is the ability to see latest posts in a topic by clicking the link that says "Last post by:".  Unfortunately, a few days ago, I installed a modification and ever since then, whenever I click to see last posts, I get sent to a blank page.  The script is somehow blocking the info on what are the latest posts.  I was wondering if anyone could help me because I am 100% positive that the error is somewhere in this code (sorry for the length of it, but it's somewhere in there):

 

function SmartnessCheckPost($row, $checkit = false){
	$_PREFIX = "ibf_";
	$_ADMINGROUPS = array(4); // array of group IDs that are allowed to add words to dictionary
	$_DATE = 1193808052;		// timestamp for posts to be checked (should be left alone, I'll set it for you)
	$_DAYSTOBEMOVED = 2;		// number of days a member will be moved to a certain group for
	$_GROUPTOBEMOVED = 22;		// the group a member will be moved to for having <= 0 smartness

	$row = mysql_fetch_array(mysql_query("SELECT * FROM `".$_PREFIX."posts` WHERE `pid` = ".$row['pid']." LIMIT 1"));

	if($row['points'] == 2 && $row['post_date'] > $_DATE){
	// if post is new,
	// add 1 to author points
	mysql_query("UPDATE `".$_PREFIX."posts` SET `points` = 1 WHERE `pid` = ".$row['pid']." LIMIT 1") or die(mysql_error());
	$m = mysql_fetch_array(mysql_query("SELECT * FROM `".$_PREFIX."members` WHERE `id` = ".$row['author_id']." LIMIT 1"));
	mysql_query("UPDATE `".$_PREFIX."members` SET `smartpoints` = ".($m['smartpoints']+1)." WHERE `id` = ".$row['author_id']." LIMIT 1") or die(mysql_error());		

	$checkit = true;
	}
	$row['points'] = 1;

	if (($checkit == true || $row['edit_time'] >= $row['last_check']) && $row['post_date'] > $_DATE) {
		/* Re-spell check this post */
		/* First convert &#39;s back to apostrophes, and such */
		$row['post'] = str_replace("&#039;", "'", $row['post']);
		$row['post'] = str_replace("&#39;", "'", $row['post']);			

		/* Give the author all their points back */
		$points = 1 - $row['points'];
		mysql_query("UPDATE `".$_PREFIX."posts` SET `points` = 1 WHERE `pid` = ".$row['pid']." LIMIT 1") or die(mysql_error());
		$m = mysql_fetch_array(mysql_query("SELECT * FROM `".$_PREFIX."members` WHERE `id` = ".$row['author_id']." LIMIT 1"));
		mysql_query("UPDATE `".$_PREFIX."members` SET `smartpoints` = ".($m['smartpoints']+$points)." WHERE `id` = ".$row['author_id']." LIMIT 1") or die(mysql_error());	
		$row['points'] = 1;

		/* remove all previous spelling thingies */
		$row['post'] = str_replace("<sp>", "", $row['post']);
		$row['post'] = str_replace("</sp>", "", $row['post']);

		/* get all the words in the post */
  		$split = preg_split("/[^a-zA-Z\']/", $row['post'], -1, PREG_SPLIT_OFFSET_CAPTURE);
  		foreach($split as $word){
  			$words[$word[1]] = $word[0];
  		}
  		
  		/* get rid of all the words that are inside HTML tags,
  			while still keeping each word's offset (i.e. would
  			be simpler to use strip_tags() but it removes offset...
  			hard to explain what I want but I got it working.)	 */
  		preg_match_all("/[<>]/", $row['post'], $matched, PREG_OFFSET_CAPTURE);
  		$matched = $matched[0];
  		$opened = array();
  		foreach($matched as $tag){
  			if($tag[0] == "<"){
  				$opened[] = $tag[1];
  			} else {
  				if(count($opened) > 0){
  					foreach ($words as $off => $word){
  						if($off > $opened[count($opened)-1] && $off < $tag[1]){
  							unset($words[$off]);
  						}
  						if($word == "" || $word == " "){
  							unset($words[$off]);
  						}
  					}					
  					array_pop($opened);
  				}
  			}
  		}
  		
  		/* Now we are left with an array, $words
  			which contains each word and its offset
  			i.e. $words[offset] = word				*/
  			
  		/* Spell check each word! */
		$i = 0;
  		foreach($words as $off => $word){
  			$check = SmartnessCheckWord($word, $row['pid']);
  			if(!$check){ //i.e. if it returns false (word is WRONG)
  				$row['points'] = $row['points'] - 1;
  				// replace word
  				$words[$off] = "<sp>".$word."</sp>";
  				$row['post'] = substr_replace($row['post'], $words[$off], $off+(9*$i), strlen($word));
				$i++;
  			}
  		}

		mysql_query("UPDATE `".$_PREFIX."posts` SET `post`='".addslashes($row['post'])."',`points`=".$row['points'].",`last_check`=".time()." WHERE `pid`=".$row['pid']." LIMIT 1") or die(mysql_error());
        $points = 1 - $row['points'];
		$m = mysql_fetch_array(mysql_query("SELECT * FROM `".$_PREFIX."members` WHERE `id` = ".$row['author_id']." LIMIT 1"));
		mysql_query("UPDATE `".$_PREFIX."members` SET `smartpoints` = ".($m['smartpoints']-$points)." WHERE `id` = ".$row['author_id']." LIMIT 1") or die(mysql_error());

		/* GET member information
			to check if they should be moved (less than or equal to 0 smartness) */
		$member = mysql_fetch_array(mysql_query("SELECT * FROM `".$_PREFIX."members` WHERE `id` = ".$row['author_id']." LIMIT 1"));
		if($member['smartpoints'] <= 0){
			// they are dumb, move them to a specific group, reset smartness to 100
			// have not tested this so no idea if it works
			mysql_query("UPDATE `".$_PREFIX."members` SET `mgroup`=".$_GROUPTOBEMOVED.",`previous_group`=".$member['mgroup'].",`group_change_time`=".(time()+($_DAYSTOBEMOVED*24*3600)).",`smart_points`=50 WHERE `id`=".$row['author_id']." LIMIT 1") or die(mysql_error());
		} 

	}

	// replace every instance of <sp> etc with <a href=></a> etc
	// check if user is an administrator
    $sel = mysql_query("SELECT * FROM `".$_PREFIX."members` WHERE `id`=".$_COOKIE['member_id']." LIMIT 1");
    $user = mysql_fetch_array($sel);
    $_ISADMIN = false;
    foreach($_ADMINGROUPS as $group){
    	if($user['mgroup'] == $group){
    		$_ISADMIN = true;
    	}
    }
	if($_ISADMIN){
		$row['post'] = preg_replace("/(<sp>)((.)+?)(<\/sp>)/i", "<a href='".$_SERVER['REQUEST_URI']."&addWord=$2' class='spellingError'>$2</a>", $row['post']);
	} else {
		$row['post'] = str_replace("<sp>", "<span class='spellingError'>", $row['post']);
		$row['post'] = str_replace("</sp>", "</span>", $row['post']);
	}

	// style for the box ripped straight from face punch forums, change it to whatever you want.
	if($row['points'] <= 0){
		$row['post'] = '<div style="float: right; padding: 3px; margin: 5px; font-weight: bolder; background-color: #f00; border: 2px solid #000"><a href="/Woot/index.php?&act=Help" style="text-decoration: none; color: #fff">-'.abs($row['points']).'</a></div>' . $row['post'];
	}

	return $row['post'];
}

function SmartnessCheckWord($word, $pid){
	$checkit = mysql_fetch_array(mysql_query("SELECT * FROM `spelling_words` WHERE `word`=\"".strtolower($word)."\""));
	if($checkit || $word == "" || $word == " "){
		return true;
	} else {
		$badwords = mysql_fetch_array(mysql_query("SELECT * FROM `spelling_bad_words` WHERE `word`=\"".strtolower($word)."\""));
		if($badwords){
			mysql_query("UPDATE `spelling_bad_words` SET `posts` = \"".$badwords['posts'].",".$pid."\" WHERE `id`=".$badwords['id']." LIMIT 1") or die(mysql_error());
		} else {
			mysql_query("INSERT INTO `spelling_bad_words` (`word`, `posts`) VALUES (\"".strtolower($word)."\", \"0,$pid\")") or die(mysql_error());
		}

		return false;
	}
}

function SmartnessUnmoveAllMembers(){
	$_PREFIX = "ibf_";
	/* look at all the members that have been moved,
		and if they've been moved for longer than they should have,
		move them back */
	$query = mysql_query("SELECT * FROM `".$_PREFIX."members` WHERE `group_change_time` <= ".time()." AND `group_change_time` > 0");
	while($m = mysql_fetch_array($query)){
		mysql_query("UPDATE `".$_PREFIX."members` SET `group_change_time`=0,`mgroup`=".$m['previous_group']." WHERE `id`=".$m['id']." LIMIT 1") or die(mysql_error());
	} 
}

function SmartnessAddWord($word){
	$_PREFIX = "ibf_";
	$_ADMINGROUPS = array(4); // array of group IDs that are allowed to add words to dictionary

	// check if user is an administrator
    $sel = mysql_query("SELECT * FROM `".$_PREFIX."members` WHERE `id`=".$_COOKIE['member_id']." LIMIT 1");
    $user = mysql_fetch_array($sel);
    $_ISADMIN = false;
    foreach($_ADMINGROUPS as $group){
    	if($user['mgroup'] == $group){
    		$_ISADMIN = true;
    	}
    }

	if($_ISADMIN){
		$query = mysql_fetch_array(mysql_query("SELECT * FROM `spelling_bad_words` WHERE `word`=\"".strtolower($word)."\" LIMIT 1"));
		if($query){
			$listOfPosts = explode(",", $query['posts']);
			$listOfPosts = array_unique($listOfPosts);
			mysql_query("INSERT INTO `spelling_words` (`word`) VALUES (\"".strtolower($word)."\")") or die(mysql_error());
			mysql_query("DELETE FROM `spelling_bad_words` WHERE `word`=\"".strtolower($word)."\" LIMIT 1") or die(mysql_error());
			foreach ($listOfPosts as $pid){
				if($pid > 0){
  					$row = mysql_fetch_array(mysql_query("SELECT * FROM `".$_PREFIX."posts` WHERE `pid`=".$pid)); 
  					SmartnessCheckPost($row, true);
				}
			}
		}
	}
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/75456-need-a-little-help-with-a-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.