Location: PHPKode > projects > TxtForum > txtforum/library/sticky.php
<?php 
if (!defined("SKIN")) die("Hack attempt!<br />You can't access directly to this file");
function stick($sort) { 
	for ($i=0;is_string($sort[$i]);$i++) { #let's rock
		list($s_unknow,$s_tid,$s_subject,$s_user,$s_time,$s_is_register,$is_sticky)=explode('<|>',$sort[$i]);
		if ($is_sticky==1) { #if it's sticky add to variable
			$sticky_topics .= "$s_unknow<|>$s_tid<|>$s_subject<|>$s_user<|>$s_time<|>$s_is_register<|>$is_sticky\n";
		}
		else $no_sticky .= "$s_unknow<|>$s_tid<|>$s_subject<|>$s_user<|>$s_time<|>$s_is_register<|>$is_sticky\n";	
	}
	return "$sticky_topics$no_sticky"; 
}

if (${arraj}[a]) { 
	#let's check if topic is sticky or not
	$sort=file('data/headers.txt');
	for ($i=0;is_string($sort[$i]);$i++) {
		list($s_unknow,$s_tid,$s_subject,$s_user,$s_time,$s_is_register,$is_sticky)=explode('<|>',$sort[$i]);
		if ($tid==$s_tid) { #we found $tid
			if($is_sticky==1) { #it's sticked, we need to unstick it
				$is_sticky="0\n";
				$sticked="unsticked";
			}
			else { #let's stick it
				$is_sticky="1\n";
				$sticked="sticked up";
			}
		}
#	echo "$s_unknow<|>$s_tid<|>$s_subject<|>$s_user<|>$s_time<|>$s_is_register<|>$is_sticky<br />";
	$headers.="$s_unknow<|>$s_tid<|>$s_subject<|>$s_user<|>$s_time<|>$s_is_register<|>$is_sticky";
	}
	$sort= explode("\n",rtrim($headers)); #we MUST rtrim(headers) or we will get <|><|><|><|><|><|><|>
	$headers=stick($sort);
	$fo=fopen('data/headers.txt',"w");
	flock($fo,LOCK_EX);
	fwrite($fo,$headers);
	flock($fo,LOCK_UN);
	fclose($fo);	
	admin_msg("Topic $sticked");
}

else {
	die('Hack attempt!<br />You are not admin!');
}
?>
Return current item: TxtForum