Empty commit

This commit is contained in:
Git 2013-04-20 08:01:01 +00:00
parent ba33634e19
commit 271dfafde4
52 changed files with 1108 additions and 938 deletions

View File

@ -10,15 +10,17 @@
$SSL = ($_SERVER['SERVER_PORT'] === '443'); $SSL = ($_SERVER['SERVER_PORT'] === '443');
if (isset($_COOKIE['session'])) { $LoginCookie=$Enc->decrypt($_COOKIE['session']); } if (isset($_COOKIE['session'])) {
if(isset($LoginCookie)) { $LoginCookie = $Enc->decrypt($_COOKIE['session']);
list($SessionID, $UserID)=explode("|~|",$Enc->decrypt($LoginCookie)); }
if (isset($LoginCookie)) {
list($SessionID, $UserID) = explode("|~|",$Enc->decrypt($LoginCookie));
if(!$UserID || !$SessionID) { if (!$UserID || !$SessionID) {
die('Not logged in!'); die('Not logged in!');
} }
if(!$Enabled = $Cache->get_value('enabled_'.$UserID)){ if (!$Enabled = $Cache->get_value('enabled_'.$UserID)) {
require(SERVER_ROOT.'/classes/class_mysql.php'); //Require the database wrapper require(SERVER_ROOT.'/classes/class_mysql.php'); //Require the database wrapper
$DB=NEW DB_MYSQL; //Load the database wrapper $DB=NEW DB_MYSQL; //Load the database wrapper
$DB->query("SELECT Enabled FROM users_main WHERE ID='$UserID'"); $DB->query("SELECT Enabled FROM users_main WHERE ID='$UserID'");
@ -34,39 +36,50 @@ function error($Error) {
} }
function is_number($Str) { function is_number($Str) {
if ($Str < 0) { return false; } if ($Str < 0) {
return false;
}
// We're converting input to a int, then string and comparing to original // We're converting input to a int, then string and comparing to original
return ($Str == strval(intval($Str)) ? true : false); return ($Str == strval(intval($Str)) ? true : false);
} }
function display_str($Str) { function display_str($Str) {
if ($Str!="") { if ($Str != '') {
$Str=make_utf8($Str); $Str = make_utf8($Str);
$Str=mb_convert_encoding($Str,"HTML-ENTITIES","UTF-8"); $Str = mb_convert_encoding($Str,'HTML-ENTITIES','UTF-8');
$Str=preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/m","&amp;",$Str); $Str = preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/m","&amp;",$Str);
$Replace = array( $Replace = array(
"'",'"',"<",">", "'",'"',"<",">",
'&#128;','&#130;','&#131;','&#132;','&#133;','&#134;','&#135;','&#136;','&#137;','&#138;','&#139;','&#140;','&#142;','&#145;','&#146;','&#147;','&#148;','&#149;','&#150;','&#151;','&#152;','&#153;','&#154;','&#155;','&#156;','&#158;','&#159;' '&#128;','&#130;','&#131;','&#132;','&#133;','&#134;','&#135;','&#136;','&#137;','&#138;','&#139;','&#140;','&#142;','&#145;','&#146;','&#147;','&#148;','&#149;','&#150;','&#151;','&#152;','&#153;','&#154;','&#155;','&#156;','&#158;','&#159;'
); );
$With=array( $With = array(
'&#39;','&quot;','&lt;','&gt;', '&#39;','&quot;','&lt;','&gt;',
'&#8364;','&#8218;','&#402;','&#8222;','&#8230;','&#8224;','&#8225;','&#710;','&#8240;','&#352;','&#8249;','&#338;','&#381;','&#8216;','&#8217;','&#8220;','&#8221;','&#8226;','&#8211;','&#8212;','&#732;','&#8482;','&#353;','&#8250;','&#339;','&#382;','&#376;' '&#8364;','&#8218;','&#402;','&#8222;','&#8230;','&#8224;','&#8225;','&#710;','&#8240;','&#352;','&#8249;','&#338;','&#381;','&#8216;','&#8217;','&#8220;','&#8221;','&#8226;','&#8211;','&#8212;','&#732;','&#8482;','&#353;','&#8250;','&#339;','&#382;','&#376;'
); );
$Str=str_replace($Replace,$With,$Str); $Str = str_replace($Replace,$With,$Str);
} }
return $Str; return $Str;
} }
function make_utf8($Str) { function make_utf8($Str) {
if ($Str!="") { if ($Str != '') {
if (is_utf8($Str)) { $Encoding="UTF-8"; } if (is_utf8($Str)) {
if (empty($Encoding)) { $Encoding=mb_detect_encoding($Str,'UTF-8, ISO-8859-1'); } $Encoding = 'UTF-8';
if (empty($Encoding)) { $Encoding="ISO-8859-1"; } }
if ($Encoding=="UTF-8") { return $Str; } if (empty($Encoding)) {
else { return @mb_convert_encoding($Str,"UTF-8",$Encoding); } $Encoding = mb_detect_encoding($Str,'UTF-8, ISO-8859-1');
}
if (empty($Encoding)) {
$Encoding = 'ISO-8859-1';
}
if ($Encoding == 'UTF-8') {
return $Str;
} else {
return @mb_convert_encoding($Str,'UTF-8',$Encoding);
}
} }
} }
@ -86,7 +99,7 @@ function is_utf8($Str) {
function display_array($Array, $DontEscape = array()) { function display_array($Array, $DontEscape = array()) {
foreach ($Array as $Key => $Val) { foreach ($Array as $Key => $Val) {
if(!in_array($Key, $DontEscape)) { if (!in_array($Key, $DontEscape)) {
$Array[$Key] = display_str($Val); $Array[$Key] = display_str($Val);
} }
} }

View File

@ -9,16 +9,16 @@ function flush() {
global $Cache, $DB; global $Cache, $DB;
$DB->query("SELECT Alias, ArticleID FROM wiki_aliases"); $DB->query("SELECT Alias, ArticleID FROM wiki_aliases");
$Aliases = $DB->to_array('Alias'); $Aliases = $DB->to_array('Alias');
$Cache->cache_value('wiki_aliases', $Aliases, 3600*24*14); $Cache->cache_value('wiki_aliases', $Aliases, 3600 * 24 * 14); // 2 weeks
} }
function to_id($Alias) { function to_id($Alias) {
global $Cache, $DB; global $Cache, $DB;
$Aliases = $Cache->get_value('wiki_aliases'); $Aliases = $Cache->get_value('wiki_aliases');
if(!$Aliases){ if (!$Aliases) {
$DB->query("SELECT Alias, ArticleID FROM wiki_aliases"); $DB->query("SELECT Alias, ArticleID FROM wiki_aliases");
$Aliases = $DB->to_array('Alias'); $Aliases = $DB->to_array('Alias');
$Cache->cache_value('wiki_aliases', $Aliases, 3600*24*14); $Cache->cache_value('wiki_aliases', $Aliases, 3600 * 24 * 14); // 2 weeks
} }
return $Aliases[$this->convert($Alias)]['ArticleID']; return $Aliases[$this->convert($Alias)]['ArticleID'];
} }
@ -38,8 +38,9 @@ function to_id($Alias) {
function article($ArticleID, $Error = true) { function article($ArticleID, $Error = true) {
global $Cache, $DB; global $Cache, $DB;
$Contents = $Cache->get_value('wiki_article_'.$ArticleID); $Contents = $Cache->get_value('wiki_article_'.$ArticleID);
if(!$Contents){ if (!$Contents) {
$DB->query("SELECT $DB->query("
SELECT
w.Revision, w.Revision,
w.Title, w.Title,
w.Body, w.Body,
@ -50,14 +51,16 @@ function article($ArticleID, $Error = true) {
u.Username, u.Username,
GROUP_CONCAT(a.Alias), GROUP_CONCAT(a.Alias),
GROUP_CONCAT(a.UserID) GROUP_CONCAT(a.UserID)
FROM wiki_articles AS w FROM wiki_articles AS w
LEFT JOIN wiki_aliases AS a ON w.ID=a.ArticleID LEFT JOIN wiki_aliases AS a ON w.ID=a.ArticleID
LEFT JOIN users_main AS u ON u.ID=w.Author LEFT JOIN users_main AS u ON u.ID=w.Author
WHERE w.ID='$ArticleID' WHERE w.ID='$ArticleID'
GROUP BY w.ID"); GROUP BY w.ID");
if(!$DB->record_count() && $Error) { error(404); } if (!$DB->record_count() && $Error) {
error(404);
}
$Contents = $DB->to_array(); $Contents = $DB->to_array();
$Cache->cache_value('wiki_article_'.$ArticleID, $Contents, 3600*24*14); $Cache->cache_value('wiki_article_'.$ArticleID, $Contents, 3600 * 24 * 14); // 2 weeks
} }
return $Contents; return $Contents;
} }

View File

@ -9,7 +9,7 @@ class ARTIST {
var $y = 0; var $y = 0;
var $Similar = array(); var $Similar = array();
function ARTIST($ID='', $Name=''){ function ARTIST($ID = '', $Name = '') {
$this->ID = $ID; $this->ID = $ID;
$this->NameLength = mb_strlen($Name, 'utf8'); $this->NameLength = mb_strlen($Name, 'utf8');
$this->Name = display_str($Name); $this->Name = display_str($Name);
@ -28,19 +28,19 @@ class ARTISTS_SIMILAR extends ARTIST{
function dump_data(){ function dump_data() {
return serialize(array(time(), $this->Name, $this->x, $this->y, serialize($this->Artists), serialize($this->Similar))); return serialize(array(time(), $this->Name, $this->x, $this->y, serialize($this->Artists), serialize($this->Similar)));
} }
function load_data($Data){ function load_data($Data) {
list($LastUpdated, $this->Name, $this->x, $this->y, $this->Artists, $this->Similar) = unserialize($Data); list($LastUpdated, $this->Name, $this->x, $this->y, $this->Artists, $this->Similar) = unserialize($Data);
$this->Artists = unserialize($this->Artists); $this->Artists = unserialize($this->Artists);
$this->Similar = unserialize($this->Similar); $this->Similar = unserialize($this->Similar);
} }
function set_up(){ function set_up() {
$this->x = ceil(WIDTH/2); $this->x = ceil(WIDTH / 2);
$this->y = ceil(HEIGHT/2); $this->y = ceil(HEIGHT / 2);
$this->xValues[$this->x] = $this->ID; $this->xValues[$this->x] = $this->ID;
$this->yValues[$this->y] = $this->ID; $this->yValues[$this->y] = $this->ID;
@ -51,24 +51,24 @@ function set_up(){
$ArtistIDs = array(); $ArtistIDs = array();
$DB->query(" $DB->query("
SELECT SELECT
s2.ArtistID, s2.ArtistID,
ag.Name, ag.Name,
ass.Score ass.Score
FROM artists_similar AS s1 FROM artists_similar AS s1
JOIN artists_similar AS s2 ON s1.SimilarID=s2.SimilarID AND s1.ArtistID!=s2.ArtistID JOIN artists_similar AS s2 ON s1.SimilarID=s2.SimilarID AND s1.ArtistID!=s2.ArtistID
JOIN artists_similar_scores AS ass ON ass.SimilarID=s1.SimilarID JOIN artists_similar_scores AS ass ON ass.SimilarID=s1.SimilarID
JOIN artists_group AS ag ON ag.ArtistID=s2.ArtistID JOIN artists_group AS ag ON ag.ArtistID=s2.ArtistID
WHERE s1.ArtistID=".$this->ID." WHERE s1.ArtistID=".$this->ID."
ORDER BY ass.Score DESC ORDER BY ass.Score DESC
LIMIT 14"); LIMIT 14");
if($DB->record_count() == 0){ if ($DB->record_count() == 0) {
return; return;
} }
// Build into array. Each artist is its own object in $this->Artists // Build into array. Each artist is its own object in $this->Artists
while(list($ArtistID, $Name, $Score) = $DB->next_record(MYSQLI_NUM, false)){ while (list($ArtistID, $Name, $Score) = $DB->next_record(MYSQLI_NUM, false)) {
if($Score<0){ if ($Score < 0) {
continue; continue;
} }
$this->Artists[$ArtistID] = new ARTIST($ArtistID, $Name); $this->Artists[$ArtistID] = new ARTIST($ArtistID, $Name);
@ -78,40 +78,41 @@ function set_up(){
} }
// Get similarities between artists on the map // Get similarities between artists on the map
$DB->query("SELECT $DB->query("
s1.ArtistID, SELECT
s2.ArtistID s1.ArtistID,
s2.ArtistID
FROM artists_similar AS s1 FROM artists_similar AS s1
JOIN artists_similar AS s2 ON s1.SimilarID=s2.SimilarID AND s1.ArtistID!=s2.ArtistID JOIN artists_similar AS s2 ON s1.SimilarID=s2.SimilarID AND s1.ArtistID!=s2.ArtistID
JOIN artists_similar_scores AS ass ON ass.SimilarID=s1.SimilarID JOIN artists_similar_scores AS ass ON ass.SimilarID=s1.SimilarID
JOIN artists_group AS a ON a.ArtistID=s2.ArtistID JOIN artists_group AS a ON a.ArtistID=s2.ArtistID
WHERE s1.ArtistID IN(".implode(',',$ArtistIDs).") WHERE s1.ArtistID IN(".implode(',',$ArtistIDs).")
AND s2.ArtistID IN(".implode(',',$ArtistIDs).") AND s2.ArtistID IN(".implode(',',$ArtistIDs).")
"); ");
// Build into array // Build into array
while(list($Artist1ID, $Artist2ID) = $DB->next_record()){ while (list($Artist1ID, $Artist2ID) = $DB->next_record()) {
$this->Artists[$Artist1ID]->Similar[$Artist2ID] = array('ID'=>$Artist2ID); $this->Artists[$Artist1ID]->Similar[$Artist2ID] = array('ID'=>$Artist2ID);
} }
// Calculate decimal point scores between artists // Calculate decimal point scores between artists
foreach($this->Similar as $SimilarArtist) { foreach ($this->Similar as $SimilarArtist) {
list($ArtistID, $Similar) = array_values($SimilarArtist); list($ArtistID, $Similar) = array_values($SimilarArtist);
$this->Similar[$ArtistID]['Decimal'] = $this->similarity($Similar['Score'], $this->TotalScore); $this->Similar[$ArtistID]['Decimal'] = $this->similarity($Similar['Score'], $this->TotalScore);
if($this->Similar[$ArtistID]['Decimal'] < $this->LowestDecimal){ if ($this->Similar[$ArtistID]['Decimal'] < $this->LowestDecimal) {
$this->LowestDecimal = $this->Similar[$ArtistID]['Decimal']; $this->LowestDecimal = $this->Similar[$ArtistID]['Decimal'];
} }
if($this->Similar[$ArtistID]['Decimal'] > $this->LargestDecimal){ if ($this->Similar[$ArtistID]['Decimal'] > $this->LargestDecimal) {
$this->LargestDecimal = $this->Similar[$ArtistID]['Decimal']; $this->LargestDecimal = $this->Similar[$ArtistID]['Decimal'];
} }
} }
reset($this->Artists); reset($this->Artists);
} }
function set_positions(){ function set_positions() {
$xValues = array(); // Possible x values $xValues = array(); // Possible x values
$Root = ceil(WIDTH/4); // Half-way into half of the image $Root = ceil(WIDTH / 4); // Half-way into half of the image
$Offset = 4; // Distance from the root (a quarter of the way into the image) to the x value $Offset = 4; // Distance from the root (a quarter of the way into the image) to the x value
// The number of artists placed in the top or the bottom // The number of artists placed in the top or the bottom
@ -131,32 +132,32 @@ function set_positions(){
// The script later chooses which side to put them on // The script later chooses which side to put them on
// We create more very low x values because they're more likely to be skipped // We create more very low x values because they're more likely to be skipped
for($i = 0; $i<=count($this->Artists)*4; $i++){ for ($i = 0; $i <= count($this->Artists) * 4; $i++) {
if($Offset>=((WIDTH/4))){ if ($Offset >= ((WIDTH / 4))) {
$Offset=$Offset%(WIDTH/4); $Offset = $Offset % (WIDTH / 4);
} }
$Plus = $Root+$Offset; // Point on the right of the root $Plus = $Root + $Offset; // Point on the right of the root
$Minus = abs($Root-$Offset); // Point on the left of the root $Minus = abs($Root - $Offset); // Point on the left of the root
$xValues[$Plus]=$Plus; $xValues[$Plus] = $Plus;
$xValues[$Minus]=$Minus; $xValues[$Minus] = $Minus;
// Throw in an extra x value closer to the edge, because they're more likely to be skipped // Throw in an extra x value closer to the edge, because they're more likely to be skipped
if($Minus>30){ if ($Minus > 30) {
// $xValues[$Minus-30]=$Minus-30; // $xValues[$Minus - 30] = $Minus - 30;
} }
$Offset = $Offset+rand(5,20); // Increase offset, and go again $Offset = $Offset + rand(5,20); // Increase offset, and go again
} }
foreach($this->Artists as $Artist){ foreach ($this->Artists as $Artist) {
$ArtistID = $Artist->ID; $ArtistID = $Artist->ID;
if($Artist->Displayed == true){ if ($Artist->Displayed == true) {
continue; continue;
} }
$this->Similar[$ArtistID]['Decimal'] = $this->Similar[$ArtistID]['Decimal'] * (1/($this->LargestDecimal))-0.1; $this->Similar[$ArtistID]['Decimal'] = $this->Similar[$ArtistID]['Decimal'] * (1 / ($this->LargestDecimal)) - 0.1;
// Calculate the distance away from the center, based on similarity // Calculate the distance away from the center, based on similarity
$IdealDistance = $this->calculate_distance($this->Similar[$ArtistID]['Decimal'], $this->x, $this->y); $IdealDistance = $this->calculate_distance($this->Similar[$ArtistID]['Decimal'], $this->x, $this->y);
@ -169,12 +170,12 @@ function set_positions(){
// See if any similar artists have been placed yet. If so, place artist in that half // See if any similar artists have been placed yet. If so, place artist in that half
// (provided that there are enough in the other half to visually balance out) // (provided that there are enough in the other half to visually balance out)
reset($Artist->Similar); reset($Artist->Similar);
foreach($Artist->Similar as $SimilarArtist) { foreach ($Artist->Similar as $SimilarArtist) {
list($Artist2ID) = array_values($SimilarArtist); list($Artist2ID) = array_values($SimilarArtist);
if($this->Artists[$Artist2ID]) { if ($this->Artists[$Artist2ID]) {
if($this->Artists[$Artist2ID]->x > (WIDTH/2) && ($NumRight-$NumLeft)<1){ if ($this->Artists[$Artist2ID]->x > (WIDTH / 2) && ($NumRight-$NumLeft) < 1) {
$Horizontal = 2; $Horizontal = 2;
} elseif($NumLeft-$NumRight<1) { } elseif ($NumLeft - $NumRight < 1) {
$Horizontal = 1; $Horizontal = 1;
} }
break; break;
@ -183,21 +184,21 @@ function set_positions(){
shuffle($xValues); shuffle($xValues);
while($xValue = array_shift($xValues)){ while ($xValue = array_shift($xValues)) {
if(abs($this->x - $xValue) <= $IdealDistance) { if (abs($this->x - $xValue) <= $IdealDistance) {
if(hypot(abs($this->x - $xValue), ($this->y - 50)) > $IdealDistance if (hypot(abs($this->x - $xValue), ($this->y - 50)) > $IdealDistance
|| ceil(sqrt(pow($IdealDistance, 2) - pow($this->x - $xValue, 2))) > (HEIGHT/2)){ || ceil(sqrt(pow($IdealDistance, 2) - pow($this->x - $xValue, 2))) > (HEIGHT / 2)) {
$xValue = $this->x - ceil(sqrt(pow($IdealDistance, 2) - pow($IdealDistance*0.1*rand(5,9), 2))); $xValue = $this->x - ceil(sqrt(pow($IdealDistance, 2) - pow($IdealDistance * 0.1 * rand(5,9), 2)));
//echo "Had to change x value for ".$Artist->Name." to ".$xValue."\n"; //echo "Had to change x value for ".$Artist->Name." to ".$xValue."\n";
} }
// Found a match (Is close enough to the center to satisfy $IdealDistance), // Found a match (Is close enough to the center to satisfy $IdealDistance),
// Now it's time to choose which half to put it on // Now it's time to choose which half to put it on
if(!$Horizontal) { if (!$Horizontal) {
// No similar artists displayed // No similar artists displayed
$Horizontal = ($NumLeft<$NumRight) ? 1 : 2; $Horizontal = ($NumLeft < $NumRight) ? 1 : 2;
} }
if($Horizontal == 2){ if ($Horizontal == 2) {
$xValue = WIDTH-$xValue; $xValue = WIDTH - $xValue;
$NumRight++; $NumRight++;
} else { } else {
$NumLeft++; $NumLeft++;
@ -210,9 +211,9 @@ function set_positions(){
break; break;
} }
} }
if(!$xValue){ // Uh-oh, we were unable to choose an x value. if (!$xValue) { // Uh-oh, we were unable to choose an x value.
$xValue = ceil(sqrt(pow($IdealDistance, 2)/2)); $xValue = ceil(sqrt(pow($IdealDistance, 2) / 2));
$xValue = (WIDTH/2)-$xValue; $xValue = (WIDTH / 2) - $xValue;
$Artist->x = $xValue; $Artist->x = $xValue;
$this->xValues[$xValue] = $ArtistID; $this->xValues[$xValue] = $ArtistID;
unset($xValues[$xValue]); unset($xValues[$xValue]);
@ -225,11 +226,11 @@ function set_positions(){
// Now we pick if it should go on the top or bottom // Now we pick if it should go on the top or bottom
if($NumTop>$NumBottom){ // Send it to the bottom half if ($NumTop > $NumBottom) { // Send it to the bottom half
$yValue=(HEIGHT/2)+$yValue; $yValue = (HEIGHT / 2) + $yValue;
$NumBottom++; $NumBottom++;
} else { } else {
$yValue=(HEIGHT/2)-$yValue; $yValue=(HEIGHT / 2) - $yValue;
$NumTop++; $NumTop++;
} }
@ -238,28 +239,28 @@ function set_positions(){
// $yValue is now a proper y coordinate // $yValue is now a proper y coordinate
// Now time to do some spacing out // Now time to do some spacing out
if($yValue < 10){ if ($yValue < 10) {
$yValue+=(10+abs($yValue))+rand(10,20); $yValue += (10 + abs($yValue)) + rand(10,20);
} }
if($yValue > (HEIGHT - 10)){ if ($yValue > (HEIGHT - 10)) {
$yValue-=((HEIGHT/2)-rand(10,20)); $yValue -= ((HEIGHT / 2) - rand(10,20));
} }
$i = 1; $i = 1;
while($Conflict = $this->scan_array_range($this->yValues, abs($yValue-13), $yValue+13)) { while ($Conflict = $this->scan_array_range($this->yValues, abs($yValue - 13), $yValue + 13)) {
if($i > 10){ if ($i > 10) {
break; break;
} }
if(!$this->scan_array_range($this->yValues, abs($yValue-5), $yValue-20)){ if (!$this->scan_array_range($this->yValues, abs($yValue - 5), $yValue - 20)) {
$yValue -= 20; $yValue -= 20;
} }
$yValue=$Conflict + rand(10, 20); $yValue = $Conflict + rand(10, 20);
if($yValue>HEIGHT-10){ if ($yValue > HEIGHT - 10) {
$yValue-=ceil(HEIGHT/2.5); $yValue -= ceil(HEIGHT / 2.5);
} elseif($yValue<10) { } elseif ($yValue < 10) {
$yValue+=ceil(HEIGHT/2.5); $yValue += ceil(HEIGHT / 2.5);
} }
$i++; $i++;
} }
@ -275,63 +276,61 @@ function set_positions(){
// Calculate the ideal distance from the center point ($Rootx, $Rooty) to the artist's point on the board // Calculate the ideal distance from the center point ($Rootx, $Rooty) to the artist's point on the board
// Pythagoras as fun! // Pythagoras as fun!
function calculate_distance($SimilarityCoefficient, $Rootx, $Rooty){ function calculate_distance($SimilarityCoefficient, $Rootx, $Rooty) {
$MaxWidth = WIDTH - $Rootx; $MaxWidth = WIDTH - $Rootx;
$MaxHeight = HEIGHT - $Rooty; $MaxHeight = HEIGHT - $Rooty;
$x = $MaxWidth - ($SimilarityCoefficient*$MaxWidth*.01); // Possible x value $x = $MaxWidth - ($SimilarityCoefficient * $MaxWidth * 0.01); // Possible x value
$y = $MaxHeight - ($SimilarityCoefficient*$MaxHeight); // Possible y value $y = $MaxHeight - ($SimilarityCoefficient * $MaxHeight); // Possible y value
$Hypot = hypot($Rootx - $x, $Rooty - $y); $Hypot = hypot($Rootx - $x, $Rooty - $y);
return $MaxWidth - $Hypot; return $MaxWidth - $Hypot;
} }
function similarity($Score, $TotalArtistScore){ function similarity($Score, $TotalArtistScore) {
return (pow(($Score/($TotalArtistScore+1)), (1/1))); return (pow(($Score / ($TotalArtistScore + 1)), (1 / 1)));
} }
function scan_array_range($Array, $Start, $Finish){ function scan_array_range($Array, $Start, $Finish) {
if($Start<0){ if ($Start < 0) {
die($Start); die($Start);
} }
for ($i = $Start; $i<=$Finish; $i++){ for ($i = $Start; $i <= $Finish; $i++) {
if(isset($Array[$i])){ if (isset($Array[$i])) {
return $i; return $i;
} }
} }
return false; return false;
} }
function write_artists(){ function write_artists() {
?> ?>
<div style="position:absolute;bottom:<?=$this->y-10?>px;left:<?=$this->x - $this->NameLength*4?>px;font-size:13pt;white-space:nowrap;" class="similar_artist_header"> <div style="position: absolute; bottom: <?=$this->y - 10 ?>px; left: <?=$this->x - $this->NameLength * 4 ?>px; font-size: 13pt; white-space: nowrap;" class="similar_artist_header">
<?=$this->Name?> <?=$this->Name?>
</div> </div>
<? <?
foreach ($this->Artists as $Artist) {
if ($Artist->ID == $this->ID) {
foreach($this->Artists as $Artist){
if($Artist->ID == $this->ID){
continue; continue;
} }
$xPosition = $Artist->x - $Artist->NameLength*4; $xPosition = $Artist->x - $Artist->NameLength * 4;
if($xPosition<0){ if ($xPosition < 0) {
$xPosition=3; $xPosition = 3;
$Artist->x = $xPosition; $Artist->x = $xPosition;
} }
$Decimal = $this->Similar[$Artist->ID]['Decimal']; $Decimal = $this->Similar[$Artist->ID]['Decimal'];
if($Decimal<0.2){ if ($Decimal < 0.2) {
$FontSize = 8; $FontSize = 8;
} elseif($Decimal<0.3){ } elseif ($Decimal < 0.3) {
$FontSize = 9; $FontSize = 9;
} elseif($Decimal<0.4){ } elseif ($Decimal < 0.4) {
$FontSize = 10; $FontSize = 10;
} else { } else {
$FontSize = 12; $FontSize = 12;
} }
?> ?>
<div style="position:absolute;top:<?=$Artist->y-5?>px;left:<?=$xPosition?>px;font-size:<?=$FontSize?>pt;white-space:nowrap;"> <div style="position: absolute; top: <?=$Artist->y - 5 ?>px; left: <?=$xPosition?> px; font-size: <?=$FontSize?>pt; white-space: nowrap;">
<a href="artist.php?id=<?=$Artist->ID?>" class="similar_artist"><?=$Artist->Name?></a> <a href="artist.php?id=<?=$Artist->ID?>" class="similar_artist"><?=$Artist->Name?></a>
</div> </div>
<? <?
@ -339,22 +338,22 @@ function write_artists(){
reset($this->Artists); reset($this->Artists);
} }
function background_image(){ function background_image() {
global $Img; global $Img;
reset($this->Similar); reset($this->Similar);
foreach($this->Similar as $SimilarArtist) { foreach ($this->Similar as $SimilarArtist) {
list($ArtistID, $Val) = array_values($SimilarArtist); list($ArtistID, $Val) = array_values($SimilarArtist);
$Artist = $this->Artists[$ArtistID]; $Artist = $this->Artists[$ArtistID];
$Decimal = $this->Similar[$ArtistID]['Decimal']; $Decimal = $this->Similar[$ArtistID]['Decimal'];
$Width = ceil($Decimal*4)+1; $Width = ceil($Decimal * 4) + 1;
$Img->line($this->x, $this->y, $Artist->x, $Artist->y,$Img->color(199,218,255), $Width); $Img->line($this->x, $this->y, $Artist->x, $Artist->y,$Img->color(199,218,255), $Width);
unset($Artist->Similar[$this->ID]); unset($Artist->Similar[$this->ID]);
reset($Artist->Similar); reset($Artist->Similar);
foreach($Artist->Similar as $SimilarArtist2) { foreach ($Artist->Similar as $SimilarArtist2) {
list($Artist2ID) = array_values($SimilarArtist2); list($Artist2ID) = array_values($SimilarArtist2);
if($this->Artists[$Artist2ID]){ if ($this->Artists[$Artist2ID]) {
$Artist2 = $this->Artists[$Artist2ID]; $Artist2 = $this->Artists[$Artist2ID];
$Img->line($Artist->x, $Artist->y, $Artist2->x, $Artist2->y,$Img->color(173,201,255)); $Img->line($Artist->x, $Artist->y, $Artist2->x, $Artist2->y,$Img->color(173,201,255));
unset($Artist2->Similar[$ArtistID]); unset($Artist2->Similar[$ArtistID]);
@ -362,13 +361,12 @@ function background_image(){
} }
reset($this->xValues); reset($this->xValues);
} }
$Img->make_png(SERVER_ROOT.'/static/similar/'.$this->ID.'.png'); $Img->make_png(SERVER_ROOT.'/static/similar/'.$this->ID.'.png');
} }
function dump(){ function dump() {
echo "Similarities:\n"; echo "Similarities:\n";
foreach($this->Artists as $Artist){ foreach ($this->Artists as $Artist) {
echo $Artist->ID; echo $Artist->ID;
echo ' - '; echo ' - ';
echo $Artist->Name; echo $Artist->Name;
@ -381,9 +379,5 @@ function dump(){
} }
} }
} }
?> ?>

View File

@ -23,9 +23,9 @@ function channel($Title, $Description, $Section='') {
} }
function item($Title, $Description, $Page, $Creator, $Comments='', $Category='', $Date='') { //Escape with CDATA, otherwise the feed breaks. function item($Title, $Description, $Page, $Creator, $Comments='', $Category='', $Date='') { //Escape with CDATA, otherwise the feed breaks.
if ($Date == '') { if ($Date == '') {
$Date = date("r"); $Date = date('r');
} else { } else {
$Date = date("r",strtotime($Date)); $Date = date('r',strtotime($Date));
} }
$Site = $this->UseSSL ? 'https://'.SSL_SITE_URL : 'http://'.NONSSL_SITE_URL; $Site = $this->UseSSL ? 'https://'.SSL_SITE_URL : 'http://'.NONSSL_SITE_URL;
$Item = "\t\t<item>\n"; $Item = "\t\t<item>\n";
@ -44,25 +44,25 @@ function item($Title, $Description, $Page, $Creator, $Comments='', $Category='',
return $Item; return $Item;
} }
function retrieve($CacheKey,$AuthKey,$PassKey) { function retrieve($CacheKey, $AuthKey, $PassKey) {
global $Cache; global $Cache;
$Entries = $Cache->get_value($CacheKey); $Entries = $Cache->get_value($CacheKey);
if(!$Entries){ if (!$Entries) {
$Entries = array(); $Entries = array();
} else { } else {
foreach($Entries as $Item){ foreach ($Entries as $Item) {
echo str_replace(array('[[PASSKEY]]','[[AUTHKEY]]'),array(display_str($PassKey),display_str($AuthKey)),$Item); echo str_replace(array('[[PASSKEY]]','[[AUTHKEY]]'),array(display_str($PassKey),display_str($AuthKey)),$Item);
} }
} }
} }
function populate($CacheKey,$Item) { function populate($CacheKey, $Item) {
global $Cache; global $Cache;
$Entries = $Cache->get_value($CacheKey,true); $Entries = $Cache->get_value($CacheKey,true);
if(!$Entries){ if (!$Entries) {
$Entries = array(); $Entries = array();
} else { } else {
if(count($Entries)>=50) { if (count($Entries) >= 50) {
array_pop($Entries); array_pop($Entries);
} }
} }

View File

@ -12,17 +12,17 @@ class IMAGE {
function create($Width, $Height) { function create($Width, $Height) {
$this->Image = imagecreate($Width, $Height); $this->Image = imagecreate($Width, $Height);
$this->Font = SERVER_ROOT.'/classes/fonts/VERDANA.TTF'; $this->Font = SERVER_ROOT.'/classes/fonts/VERDANA.TTF';
if(function_exists('imageantialias')){ if (function_exists('imageantialias')) {
imageantialias($this->Image, true); imageantialias($this->Image, true);
} }
} }
function color($Red, $Green, $Blue, $Alpha=0){ function color($Red, $Green, $Blue, $Alpha = 0) {
return imagecolorallocatealpha($this->Image, $Red, $Green, $Blue, $Alpha); return imagecolorallocatealpha($this->Image, $Red, $Green, $Blue, $Alpha);
} }
function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1){ function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1) {
if($Thickness == 1){ if ($Thickness == 1) {
return imageline($this->Image, $x1, $y1, $x2, $y2, $Color); return imageline($this->Image, $x1, $y1, $x2, $y2, $Color);
} }
$t = $Thickness / 2 - 0.5; $t = $Thickness / 2 - 0.5;
@ -32,24 +32,24 @@ function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1){
$k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q
$a = $t / sqrt(1 + pow($k, 2)); $a = $t / sqrt(1 + pow($k, 2));
$Points = array( $Points = array(
round($x1 - (1+$k)*$a), round($y1 + (1-$k)*$a), round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a),
round($x1 - (1-$k)*$a), round($y1 - (1+$k)*$a), round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a),
round($x2 + (1+$k)*$a), round($y2 - (1-$k)*$a), round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a),
round($x2 + (1-$k)*$a), round($y2 + (1+$k)*$a), round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a),
); );
imagefilledpolygon($this->Image, $Points, 4, $Color); imagefilledpolygon($this->Image, $Points, 4, $Color);
return imagepolygon($this->Image, $Points, 4, $Color); return imagepolygon($this->Image, $Points, 4, $Color);
} }
function ellipse($x, $y, $Width, $Height, $Color){ function ellipse($x, $y, $Width, $Height, $Color) {
return imageEllipse($this->Image, $x, $y, $Width, $Height, $Color); return imageEllipse($this->Image, $x, $y, $Width, $Height, $Color);
} }
function text($x, $y, $Color, $Text){ function text($x, $y, $Color, $Text) {
return imagettftext ($this->Image, $this->FontSize,$this->TextAngle, $x, $y, $Color, $this->Font, $Text); return imagettftext ($this->Image, $this->FontSize,$this->TextAngle, $x, $y, $Color, $this->Font, $Text);
} }
function make_png($FileName = NULL){ function make_png($FileName = NULL) {
return imagepng($this->Image, $FileName); return imagepng($this->Image, $FileName);
} }

View File

@ -11,9 +11,9 @@ class INVITE_TREE {
var $Visible = true; var $Visible = true;
// Set things up // Set things up
function INVITE_TREE($UserID, $Options = array()){ function INVITE_TREE($UserID, $Options = array()) {
$this->UserID = $UserID; $this->UserID = $UserID;
if($Options['visible'] === false){ if ($Options['visible'] === false) {
$this->Visible = false; $this->Visible = false;
} }
} }
@ -54,7 +54,7 @@ function make_tree() {
JOIN users_info AS ui ON ui.UserID=it.UserID JOIN users_info AS ui ON ui.UserID=it.UserID
WHERE TreeID=$TreeID WHERE TreeID=$TreeID
AND TreePosition>$TreePosition". AND TreePosition>$TreePosition".
($MaxPosition ? " AND TreePosition<$MaxPosition" : "")." ($MaxPosition ? " AND TreePosition<$MaxPosition" : '')."
AND TreeLevel>$TreeLevel AND TreeLevel>$TreeLevel
ORDER BY TreePosition"); ORDER BY TreePosition");
@ -82,44 +82,48 @@ function make_tree() {
// We store this in an output buffer, so we can show the summary at the top without having to loop through twice // We store this in an output buffer, so we can show the summary at the top without having to loop through twice
ob_start(); ob_start();
while(list($ID, $Enabled, $Class, $Donor, $Uploaded, $Downloaded, $Paranoia, $TreePosition, $TreeLevel) = $DB->next_record()){ while (list($ID, $Enabled, $Class, $Donor, $Uploaded, $Downloaded, $Paranoia, $TreePosition, $TreeLevel) = $DB->next_record()) {
// Do stats // Do stats
$Count++; $Count++;
if($TreeLevel > $MaxTreeLevel){ if ($TreeLevel > $MaxTreeLevel) {
$MaxTreeLevel = $TreeLevel; $MaxTreeLevel = $TreeLevel;
} }
if($TreeLevel == $BaseTreeLevel){ if ($TreeLevel == $BaseTreeLevel) {
$Branches++; $Branches++;
$TopLevelUpload += $Uploaded; $TopLevelUpload += $Uploaded;
$TopLevelDownload += $Downloaded; $TopLevelDownload += $Downloaded;
} }
$ClassSummary[$Class]++; $ClassSummary[$Class]++;
if($Enabled == 2){ if ($Enabled == 2) {
$DisabledCount++; $DisabledCount++;
} }
if($Donor){ if ($Donor) {
$DonorCount++; $DonorCount++;
} }
// Manage tree depth // Manage tree depth
if($TreeLevel > $PreviousTreeLevel){ if ($TreeLevel > $PreviousTreeLevel) {
for($i = 0; $i<$TreeLevel-$PreviousTreeLevel; $i++){ echo "<ul class=\"invitetree\"><li>"; } for ($i = 0; $i < $TreeLevel - $PreviousTreeLevel; $i++) {
} elseif($TreeLevel < $PreviousTreeLevel){ echo '<ul class="invitetree"><li>';
for($i = 0; $i<$PreviousTreeLevel-$TreeLevel; $i++){ echo "</li></ul>"; } }
echo "</li>"; } elseif ($TreeLevel < $PreviousTreeLevel) {
echo "<li>"; for ($i = 0; $i < $PreviousTreeLevel - $TreeLevel; $i++) {
echo '</li></ul>';
}
echo '</li>';
echo '<li>';
} else { } else {
echo "</li>"; echo '</li>';
echo "<li>"; echo '<li>';
} }
?> ?>
<strong><?=Users::format_username($ID, true, true, $Enabled != 2 ? false : true, true)?></strong> <strong><?=Users::format_username($ID, true, true, $Enabled != 2 ? false : true, true)?></strong>
<? <?
if(check_paranoia(array('uploaded', 'downloaded'), $Paranoia, $UserClass)) { if (check_paranoia(array('uploaded', 'downloaded'), $Paranoia, $UserClass)) {
$TotalUpload += $Uploaded; $TotalUpload += $Uploaded;
$TotalDownload += $Downloaded; $TotalDownload += $Downloaded;
?> ?>
@ -140,9 +144,11 @@ function make_tree() {
} }
$Tree = ob_get_clean(); $Tree = ob_get_clean();
for($i = 0; $i<$PreviousTreeLevel-$OriginalTreeLevel; $i++){ $Tree .= "</li></ul>\n"; } for ($i = 0; $i < $PreviousTreeLevel - $OriginalTreeLevel; $i++) {
$Tree .= "</li></ul>\n";
}
if($Count){ if ($Count) {
?> <p style="font-weight: bold;"> ?> <p style="font-weight: bold;">
This tree has <?=$Count?> entries, <?=$Branches?> branches, and a depth of <?=$MaxTreeLevel - $OriginalTreeLevel?>. This tree has <?=$Count?> entries, <?=$Branches?> branches, and a depth of <?=$MaxTreeLevel - $OriginalTreeLevel?>.
@ -150,20 +156,22 @@ function make_tree() {
<? <?
$ClassStrings = array(); $ClassStrings = array();
foreach ($ClassSummary as $ClassID => $ClassCount) { foreach ($ClassSummary as $ClassID => $ClassCount) {
if($ClassCount == 0) { continue; } if ($ClassCount == 0) {
continue;
}
$LastClass = Users::make_class_string($ClassID); $LastClass = Users::make_class_string($ClassID);
if($ClassCount>1) { if ($ClassCount > 1) {
if($LastClass == "Torrent Celebrity") { if ($LastClass == 'Torrent Celebrity') {
$LastClass = 'Torrent Celebrities'; $LastClass = 'Torrent Celebrities';
} else { } else {
$LastClass.='s'; $LastClass.='s';
} }
} }
$LastClass= $ClassCount.' '.$LastClass.' (' . number_format(($ClassCount/$Count)*100) . '%)'; $LastClass = $ClassCount.' '.$LastClass.' (' . number_format(($ClassCount / $Count) * 100) . '%)';
$ClassStrings []= $LastClass; $ClassStrings[] = $LastClass;
} }
if(count($ClassStrings)>1){ if (count($ClassStrings) > 1) {
array_pop($ClassStrings); array_pop($ClassStrings);
echo implode(', ', $ClassStrings); echo implode(', ', $ClassStrings);
echo ' and '.$LastClass; echo ' and '.$LastClass;
@ -172,16 +180,22 @@ function make_tree() {
} }
echo '. '; echo '. ';
echo $DisabledCount; echo $DisabledCount;
echo ($DisabledCount==1)?' user is':' users are'; echo ($DisabledCount == 1) ? ' user is' : ' users are';
echo ' disabled ('; echo ' disabled (';
if($DisabledCount == 0) { echo '0%)'; } if ($DisabledCount == 0) {
else { echo number_format(($DisabledCount/$Count)*100) . '%)';} echo '0%)';
} else {
echo number_format(($DisabledCount / $Count) * 100) . '%)';
}
echo ', and '; echo ', and ';
echo $DonorCount; echo $DonorCount;
echo ($DonorCount==1)?' user has':' users have'; echo ($DonorCount == 1) ? ' user has' : ' users have';
echo ' donated ('; echo ' donated (';
if($DonorCount == 0) { echo '0%)'; } if ($DonorCount == 0) {
else { echo number_format(($DonorCount/$Count)*100) . '%)';} echo '0%)';
} else {
echo number_format(($DonorCount / $Count) * 100) . '%)';
}
echo '. </p>'; echo '. </p>';
echo '<p style="font-weight: bold;">'; echo '<p style="font-weight: bold;">';
@ -196,22 +210,21 @@ function make_tree() {
echo '; and the total ratio is '.Format::get_ratio_html($TopLevelUpload, $TopLevelDownload).'. '; echo '; and the total ratio is '.Format::get_ratio_html($TopLevelUpload, $TopLevelDownload).'. ';
echo 'These numbers include the stats of paranoid users, and will be factored in to the invitation giving script.</p>'; echo 'These numbers include the stats of paranoid users and will be factored into the invitation giving script.</p>';
if($ParanoidCount){ if ($ParanoidCount) {
echo '<p style="font-weight: bold;">'; echo '<p style="font-weight: bold;">';
echo $ParanoidCount; echo $ParanoidCount;
echo ($ParanoidCount==1)?' user (':' users ('; echo ($ParanoidCount == 1) ? ' user (' : ' users (';
echo number_format(($ParanoidCount/$Count)*100); echo number_format(($ParanoidCount / $Count) * 100);
echo '%) '; echo '%) ';
echo ($ParanoidCount==1)?' is':' are'; echo ($ParanoidCount == 1) ? ' is' : ' are';
echo ' too paranoid to have their stats shown here, and '; echo ' too paranoid to have their stats shown here, and ';
echo ($ParanoidCount==1)?' was':' were'; echo ($ParanoidCount == 1) ? ' was' : ' were';
echo ' not factored into the stats for the total tree.'; echo ' not factored into the stats for the total tree.';
echo '</p>'; echo '</p>';
} }
} }
?> ?>
<br /> <br />
<?=$Tree?> <?=$Tree?>

View File

@ -76,7 +76,7 @@ public function disconnect() {
public function get_channel() { public function get_channel() {
preg_match('/.+ PRIVMSG ([^:]+) :.+/', $this->Data, $Channel); preg_match('/.+ PRIVMSG ([^:]+) :.+/', $this->Data, $Channel);
if(preg_match('/#.+/',$Channel[1])) { if (preg_match('/#.+/',$Channel[1])) {
return $Channel[1]; return $Channel[1];
} else { } else {
return false; return false;
@ -133,13 +133,13 @@ protected function whois($Nick) {
You can probably find it in old RC1 code kicking aronud if you need it. You can probably find it in old RC1 code kicking aronud if you need it.
protected function ip_check($IP,$Gline=false,$Channel=BOT_REPORT_CHAN) { protected function ip_check($IP,$Gline=false,$Channel=BOT_REPORT_CHAN) {
global $Cache, $DB; global $Cache, $DB;
if(blacklisted_ip($IP)) { if (blacklisted_ip($IP)) {
$this->send_to($Channel, 'TOR IP Detected: '.$IP); $this->send_to($Channel, 'TOR IP Detected: '.$IP);
if ($Gline) { if ($Gline) {
$this->send_raw('GLINE *@'.$IP.' 90d :DNSBL Proxy'); $this->send_raw('GLINE *@'.$IP.' 90d :DNSBL Proxy');
} }
} }
if(Tools::site_ban_ip($IP)) { if (Tools::site_ban_ip($IP)) {
$this->send_to($Channel, 'Site IP Ban Detected: '.$IP); $this->send_to($Channel, 'Site IP Ban Detected: '.$IP);
if ($Gline) { if ($Gline) {
$this->send_raw('GLINE *@'.$IP.' 90d :IP Ban'); $this->send_raw('GLINE *@'.$IP.' 90d :IP Ban');
@ -151,31 +151,31 @@ protected function listen() {
global $Cache,$DB; global $Cache,$DB;
$Cache->InternalCache = false; $Cache->InternalCache = false;
stream_set_timeout($this->Socket, 10000000000); stream_set_timeout($this->Socket, 10000000000);
while($this->State == 1){ while ($this->State == 1) {
if($this->Data = fgets($this->Socket, 256)) { if ($this->Data = fgets($this->Socket, 256)) {
//IP checks //IP checks
//if(preg_match('/:\*\*\* (?:REMOTE)?CONNECT: Client connecting (?:.*) \[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\] \[(.+)\]/', $this->Data, $IP)) { //if (preg_match('/:\*\*\* (?:REMOTE)?CONNECT: Client connecting (?:.*) \[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\] \[(.+)\]/', $this->Data, $IP)) {
// $this->ip_check($IP[1],true); // $this->ip_check($IP[1],true);
//} //}
if($this->Debug === true) { if ($this->Debug === true) {
$this->send_to(BOT_DEBUG_CHAN, $this->Data); $this->send_to(BOT_DEBUG_CHAN, $this->Data);
} }
if($this->Whois !== false) { if ($this->Whois !== false) {
$Exp = explode(' ',$this->Data); $Exp = explode(' ',$this->Data);
if($Exp[1] == '307') { if ($Exp[1] == '307') {
$this->Identified[$this->Whois] = 1; $this->Identified[$this->Whois] = 1;
$this->send_to($this->LastChan, "$this->Whois correctly identified as a real person!"); $this->send_to($this->LastChan, "$this->Whois correctly identified as a real person!");
$this->Whois = false; $this->Whois = false;
$this->LastChan = false; $this->LastChan = false;
} elseif($Exp[6] == '/WHOIS') { } elseif ($Exp[6] == '/WHOIS') {
$this->Whois = false; $this->Whois = false;
} }
} }
if(preg_match("/:([^!]+)![^\s]* QUIT.* /", $this->Data, $Nick)) { if (preg_match("/:([^!]+)![^\s]* QUIT.* /", $this->Data, $Nick)) {
if(isset($this->Identified[$Nick[1]])) { if (isset($this->Identified[$Nick[1]])) {
unset($this->Identified[$Nick[1]]); unset($this->Identified[$Nick[1]]);
} }
if (isset($this->DisabledUsers[$Nick[1]])) { if (isset($this->DisabledUsers[$Nick[1]])) {
@ -202,24 +202,24 @@ protected function listen() {
} }
} }
if(preg_match("/End of message of the day./", $this->Data)) { if (preg_match('/End of message of the day./', $this->Data)) {
$this->connect_events(); $this->connect_events();
} }
if(preg_match('/PING :(.+)/', $this->Data, $Ping)) { if (preg_match('/PING :(.+)/', $this->Data, $Ping)) {
$this->send_raw('PONG :'.$Ping[1]); $this->send_raw('PONG :'.$Ping[1]);
} }
if(preg_match('/.*PRIVMSG #.*/',$this->Data)) { if (preg_match('/.*PRIVMSG #.*/',$this->Data)) {
$this->channel_events(); $this->channel_events();
} }
if(preg_match("/.* PRIVMSG ".BOT_NICK." .*/",$this->Data)) { if (preg_match("/.* PRIVMSG ".BOT_NICK." .*/",$this->Data)) {
$this->query_events(); $this->query_events();
} }
} }
if($this->Listened = @socket_accept($this->ListenSocket)) { if ($this->Listened = @socket_accept($this->ListenSocket)) {
$this->listener_events(); $this->listener_events();
} }

View File

@ -53,7 +53,7 @@
* This is how you loop over the result set: * This is how you loop over the result set:
while(list($All,$Columns,$That,$You,$Select)=$DB->next_record()){ while (list($All,$Columns,$That,$You,$Select)=$DB->next_record()) {
echo "Do stuff with ".$All." of the ".$Columns.$That.$You.$Select; echo "Do stuff with ".$All." of the ".$Columns.$That.$You.$Select;
} }
----- -----
@ -310,7 +310,7 @@ function to_array($Key = false, $Type = MYSQLI_BOTH, $Escape = true) {
if ($Key !== false) { if ($Key !== false) {
$Return[$Row[$Key]] = $Row; $Return[$Row[$Key]] = $Row;
} else { } else {
$Return[]=$Row; $Return[] = $Row;
} }
} }
mysqli_data_seek($this->QueryID, 0); mysqli_data_seek($this->QueryID, 0);
@ -337,14 +337,14 @@ function to_pair($KeyField, $ValField, $Escape = true) {
// Loops through the result set, collecting the $Key column into an array // Loops through the result set, collecting the $Key column into an array
function collect($Key, $Escape = true) { function collect($Key, $Escape = true) {
$Return = array(); $Return = array();
while($Row = mysqli_fetch_array($this->QueryID)){ while ($Row = mysqli_fetch_array($this->QueryID)) {
$Return[] = $Escape ? display_str($Row[$Key]) : $Row[$Key]; $Return[] = $Escape ? display_str($Row[$Key]) : $Row[$Key];
} }
mysqli_data_seek($this->QueryID, 0); mysqli_data_seek($this->QueryID, 0);
return $Return; return $Return;
} }
function set_query_id(&$ResultSet){ function set_query_id(&$ResultSet) {
$this->QueryID = $ResultSet; $this->QueryID = $ResultSet;
$this->Row = 0; $this->Row = 0;
} }

View File

@ -185,7 +185,9 @@ private function valid_url ($Str, $Extension = '', $Inline = false) {
public function local_url ($Str) { public function local_url ($Str) {
$URLInfo = parse_url($Str); $URLInfo = parse_url($Str);
if (!$URLInfo) { return false; } if (!$URLInfo) {
return false;
}
$Host = $URLInfo['host']; $Host = $URLInfo['host'];
// If for some reason your site does not require subdomains or contains a directory in the SITE_URL, revert to the line below. // If for some reason your site does not require subdomains or contains a directory in the SITE_URL, revert to the line below.
//if ($Host == NONSSL_SITE_URL || $Host == SSL_SITE_URL || $Host == 'www.'.NONSSL_SITE_URL) { //if ($Host == NONSSL_SITE_URL || $Host == SSL_SITE_URL || $Host == 'www.'.NONSSL_SITE_URL) {
@ -282,7 +284,7 @@ private function parse ($Str) {
//3a) check it against the $this->ValidTags array to see if it's actually a tag and not [bullshit] //3a) check it against the $this->ValidTags array to see if it's actually a tag and not [bullshit]
if (!isset($this->ValidTags[$TagName])) { if (!isset($this->ValidTags[$TagName])) {
$Array[$ArrayPos] = substr($Str, $i, ($TagPos - $i)+strlen($Tag[0][0])); $Array[$ArrayPos] = substr($Str, $i, ($TagPos - $i) + strlen($Tag[0][0]));
$i = $TagPos + strlen($Tag[0][0]); $i = $TagPos + strlen($Tag[0][0]);
++$ArrayPos; ++$ArrayPos;
continue; continue;
@ -299,7 +301,7 @@ private function parse ($Str) {
} }
// 4) Move the pointer past the end of the tag // 4) Move the pointer past the end of the tag
$i=$TagPos+strlen($Tag[0][0]); $i = $TagPos + strlen($Tag[0][0]);
// 5) Find out where the tag closes (beginning of [/tag]) // 5) Find out where the tag closes (beginning of [/tag])
@ -338,19 +340,19 @@ private function parse ($Str) {
// We're in a list. Find where it ends // We're in a list. Find where it ends
$NewLine = $i; $NewLine = $i;
do { // Look for \n[*] do { // Look for \n[*]
$NewLine = strpos($Str, "\n", $NewLine+1); $NewLine = strpos($Str, "\n", $NewLine + 1);
} while ($NewLine!== false && substr($Str, $NewLine+1, 3) == '['.$TagName.']'); } while ($NewLine !== false && substr($Str, $NewLine + 1, 3) == '['.$TagName.']');
$CloseTag = $NewLine; $CloseTag = $NewLine;
if ($CloseTag === false) { // block finishes with list if ($CloseTag === false) { // block finishes with list
$CloseTag = $Len; $CloseTag = $Len;
} }
$Block = substr($Str, $i, $CloseTag-$i); // Get the list $Block = substr($Str, $i, $CloseTag - $i); // Get the list
$i = $CloseTag; // 5d) Move the pointer past the end of the [/close] tag. $i = $CloseTag; // 5d) Move the pointer past the end of the [/close] tag.
} else { } else {
//5b) If it's a normal tag, it may have versions of itself nested inside //5b) If it's a normal tag, it may have versions of itself nested inside
$CloseTag = $i-1; $CloseTag = $i - 1;
$InTagPos = $i-1; $InTagPos = $i - 1;
$NumInOpens = 0; $NumInOpens = 0;
$NumInCloses = -1; $NumInCloses = -1;
@ -364,7 +366,7 @@ private function parse ($Str) {
// Every time we find an internal open tag of the same type, search for the next close tag // Every time we find an internal open tag of the same type, search for the next close tag
// (as the first close tag won't do - it's been opened again) // (as the first close tag won't do - it's been opened again)
do { do {
$CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag+1); $CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag + 1);
if ($CloseTag === false) { if ($CloseTag === false) {
$CloseTag = $Len; $CloseTag = $Len;
break; break;
@ -373,7 +375,7 @@ private function parse ($Str) {
} }
// Is there another open tag inside this one? // Is there another open tag inside this one?
$OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos+1); $OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos + 1);
if (!$OpenTag || $InTag[0][1] > $CloseTag) { if (!$OpenTag || $InTag[0][1] > $CloseTag) {
break; break;
} else { } else {
@ -385,9 +387,9 @@ private function parse ($Str) {
// Find the internal block inside the tag // Find the internal block inside the tag
$Block = substr($Str, $i, $CloseTag-$i); // 5c) Get the contents between [open] and [/close] and call it the block. $Block = substr($Str, $i, $CloseTag - $i); // 5c) Get the contents between [open] and [/close] and call it the block.
$i = $CloseTag+strlen($TagName)+3; // 5d) Move the pointer past the end of the [/close] tag. $i = $CloseTag + strlen($TagName) + 3; // 5d) Move the pointer past the end of the [/close] tag.
} }
@ -446,7 +448,7 @@ private function parse ($Str) {
$n = $matches[2]; $n = $matches[2];
$text = ''; $text = '';
if ($n < 5 && $n > 0) { if ($n < 5 && $n > 0) {
$e = str_repeat('=', $matches[2]+1); $e = str_repeat('=', $matches[2] + 1);
$text = $e . $matches[3] . $e; $text = $e . $matches[3] . $e;
} }
return $text; return $text;
@ -512,7 +514,9 @@ public function parse_toc ($Min = 3)
foreach ($this->Headlines as $t) { foreach ($this->Headlines as $t) {
$n = (int) $t[0]; $n = (int) $t[0];
if ($i === 0 && $n > 1) $off = $n - $level; if ($i === 0 && $n > 1) {
$off = $n - $level;
}
$this->headline_level($n, $level, $list, $i, $off); $this->headline_level($n, $level, $list, $i, $off);
$list .= sprintf('<li><a href="#%2$s">%1$s</a>', $t[1], $t[2]); $list .= sprintf('<li><a href="#%2$s">%1$s</a>', $t[1], $t[2]);
$level = $t[0]; $level = $t[0];
@ -551,7 +555,7 @@ private function headline_level (&$ItemLevel, &$Level, &$List, $i, &$Offset)
$List .= '</li>' . str_repeat('</ol></li>', $diff); $List .= '</li>' . str_repeat('</ol></li>', $diff);
} elseif ($ItemLevel > $Level) { } elseif ($ItemLevel > $Level) {
$diff = $ItemLevel - $Level; $diff = $ItemLevel - $Level;
if ($Offset > 0) $List .= str_repeat('<li><ol>', $Offset-2); if ($Offset > 0) $List .= str_repeat('<li><ol>', $Offset - 2);
if ($ItemLevel > 1) { if ($ItemLevel > 1) {
$List .= $i === 0 ? '<li>' : ''; $List .= $i === 0 ? '<li>' : '';
@ -565,7 +569,9 @@ private function headline_level (&$ItemLevel, &$Level, &$List, $i, &$Offset)
private function to_html ($Array) { private function to_html ($Array) {
global $SSL; global $SSL;
$this->Levels++; $this->Levels++;
if ($this->Levels>10) { return $Block['Val']; } // Hax prevention if ($this->Levels > 10) {
return $Block['Val'];
} // Hax prevention
$Str = ''; $Str = '';
foreach ($Array as $Block) { foreach ($Array as $Block) {
@ -666,9 +672,11 @@ private function to_html ($Array) {
$Str .= sprintf('%1$s%2$s%1$s', str_repeat('=', $Block['Attr'] + 1), $text); $Str .= sprintf('%1$s%2$s%1$s', str_repeat('=', $Block['Attr'] + 1), $text);
} else { } else {
$id = '_' . crc32($raw . $this->HeadlineID); $id = '_' . crc32($raw . $this->HeadlineID);
if ($this->InQuotes === 0) $this->Headlines[] = array($Block['Attr'], $raw, $id); if ($this->InQuotes === 0) {
$this->Headlines[] = array($Block['Attr'], $raw, $id);
}
$Str .= sprintf('<h%1$d id="%3$s">%2$s</h%1$d>', ($Block['Attr']+2), $text, $id); $Str .= sprintf('<h%1$d id="%3$s">%2$s</h%1$d>', ($Block['Attr'] + 2), $text, $id);
$this->HeadlineID++; $this->HeadlineID++;
} }
break; break;
@ -685,7 +693,7 @@ private function to_html ($Array) {
$this->NoImg++; // No images inside quote tags $this->NoImg++; // No images inside quote tags
$this->InQuotes++; $this->InQuotes++;
if (!empty($Block['Attr'])) { if (!empty($Block['Attr'])) {
$Exploded = explode("|", $this->to_html($Block['Attr'])); $Exploded = explode('|', $this->to_html($Block['Attr']));
if (isset($Exploded[1]) && is_numeric($Exploded[1])) { if (isset($Exploded[1]) && is_numeric($Exploded[1])) {
$PostID = trim($Exploded[1]); $PostID = trim($Exploded[1]);
$Str.='<a href="#" onclick="QuoteJump(event, '.$PostID.'); return false;"><strong class="quoteheader">'.$Exploded[0].'</strong> wrote: </a>'; $Str.='<a href="#" onclick="QuoteJump(event, '.$PostID.'); return false;"><strong class="quoteheader">'.$Exploded[0].'</strong> wrote: </a>';
@ -718,7 +726,7 @@ private function to_html ($Array) {
} }
break; break;
case 'img': case 'img':
if ($this->NoImg>0 && $this->valid_url($Block['Val'])) { if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) {
$Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (image)'; $Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (image)';
break; break;
} }
@ -737,7 +745,7 @@ private function to_html ($Array) {
break; break;
case 'aud': case 'aud':
if ($this->NoImg>0 && $this->valid_url($Block['Val'])) { if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) {
$Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (audio)'; $Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (audio)';
break; break;
} }

View File

@ -54,7 +54,7 @@ class TEXT_2 {
private $Levels = 0; // If images should be turned into URLs private $Levels = 0; // If images should be turned into URLs
function __construct() { function __construct() {
foreach($this->Smileys as $Key=>$Val) { foreach ($this->Smileys as $Key=>$Val) {
$this->Smileys[$Key] = '<img border="0" src="'.STATIC_SERVER.'common/smileys/'.$Val.'" alt="" />'; $this->Smileys[$Key] = '<img border="0" src="'.STATIC_SERVER.'common/smileys/'.$Val.'" alt="" />';
} }
reset($this->Smileys); reset($this->Smileys);
@ -110,7 +110,7 @@ function valid_url($Str, $Extension = '', $Inline = false) {
$Regex .= '(:[0-9]{1,5})?'; // port $Regex .= '(:[0-9]{1,5})?'; // port
$Regex .= '\/?'; // slash? $Regex .= '\/?'; // slash?
$Regex .= '(\/?[0-9a-z\-_.,&=@~%\/:;()+|!#]+)*'; // /file $Regex .= '(\/?[0-9a-z\-_.,&=@~%\/:;()+|!#]+)*'; // /file
if(!empty($Extension)) { if (!empty($Extension)) {
$Regex.=$Extension; $Regex.=$Extension;
} }
@ -129,16 +129,16 @@ function valid_url($Str, $Extension = '', $Inline = false) {
function local_url($Str) { function local_url($Str) {
$URLInfo = parse_url($Str); $URLInfo = parse_url($Str);
if(!$URLInfo) { return false; } if (!$URLInfo) { return false; }
$Host = $URLInfo['host']; $Host = $URLInfo['host'];
// If for some reason your site does not require subdomains or contains a directory in the SITE_URL, revert to the line below. // If for some reason your site does not require subdomains or contains a directory in the SITE_URL, revert to the line below.
//if($Host == NONSSL_SITE_URL || $Host == SSL_SITE_URL || $Host == 'www.'.NONSSL_SITE_URL) { //if ($Host == NONSSL_SITE_URL || $Host == SSL_SITE_URL || $Host == 'www.'.NONSSL_SITE_URL) {
if(preg_match('/(\S+\.)*'.NONSSL_SITE_URL.'/', $Host)) { if (preg_match('/(\S+\.)*'.NONSSL_SITE_URL.'/', $Host)) {
$URL = $URLInfo['path']; $URL = $URLInfo['path'];
if(!empty($URLInfo['query'])) { if (!empty($URLInfo['query'])) {
$URL.='?'.$URLInfo['query']; $URL.='?'.$URLInfo['query'];
} }
if(!empty($URLInfo['fragment'])) { if (!empty($URLInfo['fragment'])) {
$URL.='#'.$URLInfo['fragment']; $URL.='#'.$URLInfo['fragment'];
} }
return $URL; return $URL;
@ -192,7 +192,7 @@ function parse($Str) {
$Array = array(); $Array = array();
$ArrayPos = 0; $ArrayPos = 0;
while($i<$Len) { while ($i < $Len) {
$Block = ''; $Block = '';
// 1) Find and parse the next tag (regex) // 1) Find and parse the next tag (regex)
@ -215,7 +215,7 @@ function parse($Str) {
$MaxAttribs = $this->ValidTags[$TagName]; $MaxAttribs = $this->ValidTags[$TagName];
// 1bi) check it against the $this->ValidTags array to see if it's actually a tag and not [bullshit] // 1bi) check it against the $this->ValidTags array to see if it's actually a tag and not [bullshit]
if(!isset($this->ValidTags[$TagName])) { if (!isset($this->ValidTags[$TagName])) {
$IsTag = 0; $IsTag = 0;
} }
@ -231,10 +231,10 @@ function parse($Str) {
|| (strpos($Attrib, "'") !== false) || (strpos($Attrib, "'") !== false)
|| (strpos($Attrib, "\"") !== false)) { || (strpos($Attrib, "\"") !== false)) {
$IsTag = 0; $IsTag = 0;
} elseif (strpos($Attrib, "[") !== false) { } elseif (strpos($Attrib, '[') !== false) {
// attributes aren't allowed to contain any tag (or something which looks like it might be one) inside them // attributes aren't allowed to contain any tag (or something which looks like it might be one) inside them
foreach ($this->ValidTags as $PossibleTag=>$_) { foreach ($this->ValidTags as $PossibleTag=>$_) {
if (strpos($Attrib, "[".$PossibleTag) !== false) { if (strpos($Attrib, '['.$PossibleTag) !== false) {
$IsTag = 0; $IsTag = 0;
} }
} }
@ -246,8 +246,8 @@ function parse($Str) {
if (!$IsTag) { if (!$IsTag) {
// we jump past the beginning of the "tag", but not the attribute value, as this may contain real tags // we jump past the beginning of the "tag", but not the attribute value, as this may contain real tags
$Array[$ArrayPos] = substr($Str, $i, ($TagPos-$i)+strlen($Tag[0][0])); $Array[$ArrayPos] = substr($Str, $i, ($TagPos - $i) + strlen($Tag[0][0]));
$i=$TagPos+strlen($Tag[0][0]); $i = $TagPos + strlen($Tag[0][0]);
++$ArrayPos; ++$ArrayPos;
continue; continue;
} }
@ -255,17 +255,17 @@ function parse($Str) {
} }
// 2) If there aren't any tags left, write everything remaining to a block // 2) If there aren't any tags left, write everything remaining to a block
if(!$IsTag) { if (!$IsTag) {
// No more tags // No more tags
$Array[$ArrayPos] = substr($Str, $i); $Array[$ArrayPos] = substr($Str, $i);
break; break;
} }
// 3) If the next tag isn't where the pointer is, write everything up to there to a text block. // 3) If the next tag isn't where the pointer is, write everything up to there to a text block.
if($TagPos>$i) { if ($TagPos > $i) {
$Array[$ArrayPos] = substr($Str, $i, $TagPos-$i); $Array[$ArrayPos] = substr($Str, $i, $TagPos - $i);
++$ArrayPos; ++$ArrayPos;
$i=$TagPos; $i = $TagPos;
} }
// 4) Move the pointer past the end of the tag // 4) Move the pointer past the end of the tag
@ -279,21 +279,21 @@ function parse($Str) {
//5a) Different for different types of tag. Some tags don't close, others are weird like [*] //5a) Different for different types of tag. Some tags don't close, others are weird like [*]
if($TagName == 'img' && $HasAttrib) { //[img=...] if ($TagName == 'img' && $HasAttrib) { //[img=...]
$Block = ''; // Nothing inside this tag $Block = ''; // Nothing inside this tag
// Don't need to touch $i // Don't need to touch $i
} elseif($TagName == 'inlineurl') { // We did a big replace early on to turn http:// into [inlineurl]http:// } elseif ($TagName == 'inlineurl') { // We did a big replace early on to turn http:// into [inlineurl]http://
// Let's say the block can stop at a newline or a space // Let's say the block can stop at a newline or a space
$CloseTag = strcspn($Str, " \n\r", $i); $CloseTag = strcspn($Str, " \n\r", $i);
if($CloseTag === false) { // block finishes with URL if ($CloseTag === false) { // block finishes with URL
$CloseTag = $Len; $CloseTag = $Len;
} }
if(preg_match('/[!;,.?:]+$/',substr($Str, $i, $CloseTag), $Match)) { if (preg_match('/[!;,.?:]+$/',substr($Str, $i, $CloseTag), $Match)) {
$CloseTag -= strlen($Match[0]); $CloseTag -= strlen($Match[0]);
} }
$URL = substr($Str, $i, $CloseTag); $URL = substr($Str, $i, $CloseTag);
if(substr($URL, -1) == ')' && substr_count($URL, '(') < substr_count($URL, ')')) { if (substr($URL, -1) == ')' && substr_count($URL, '(') < substr_count($URL, ')')) {
$CloseTag--; $CloseTag--;
$URL = substr($URL, 0, -1); $URL = substr($URL, 0, -1);
} }
@ -302,20 +302,20 @@ function parse($Str) {
// strcspn returns the number of characters after the offset $i, not after the beginning of the string // strcspn returns the number of characters after the offset $i, not after the beginning of the string
// Therefore, we use += instead of the = everywhere else // Therefore, we use += instead of the = everywhere else
$i += $CloseTag; // 5d) Move the pointer past the end of the [/close] tag. $i += $CloseTag; // 5d) Move the pointer past the end of the [/close] tag.
} elseif($WikiLink == true || $TagName == 'n') { } elseif ($WikiLink == true || $TagName == 'n') {
// Don't need to do anything - empty tag with no closing // Don't need to do anything - empty tag with no closing
} elseif($TagName == '*') { } elseif ($TagName == '*') {
// We're in a list. Find where it ends // We're in a list. Find where it ends
$NewLine = $i; $NewLine = $i;
do { // Look for \n[*] do { // Look for \n[*]
$NewLine = strpos($Str, "\n", $NewLine+1); $NewLine = strpos($Str, "\n", $NewLine + 1);
} while($NewLine!== false && substr($Str, $NewLine+1, 3) == '[*]'); } while ($NewLine !== false && substr($Str, $NewLine + 1, 3) == '[*]');
$CloseTag = $NewLine; $CloseTag = $NewLine;
if($CloseTag === false) { // block finishes with list if ($CloseTag === false) { // block finishes with list
$CloseTag = $Len; $CloseTag = $Len;
} }
$Block = substr($Str, $i, $CloseTag-$i); // Get the list $Block = substr($Str, $i, $CloseTag - $i); // Get the list
$i = $CloseTag; // 5d) Move the pointer past the end of the [/close] tag. $i = $CloseTag; // 5d) Move the pointer past the end of the [/close] tag.
} else { } else {
//5b) If it's a normal tag, it may have versions of itself nested inside //5b) If it's a normal tag, it may have versions of itself nested inside
@ -325,7 +325,7 @@ function parse($Str) {
$NumInCloses = -1; $NumInCloses = -1;
$InOpenRegex = '/\[('.$TagName.')'; $InOpenRegex = '/\[('.$TagName.')';
if($MaxAttribs>0) { if ($MaxAttribs > 0) {
$InOpenRegex.="(=[^\n'\"\[\]]+)?"; $InOpenRegex.="(=[^\n'\"\[\]]+)?";
} }
$InOpenRegex.='\]/i'; $InOpenRegex.='\]/i';
@ -335,7 +335,7 @@ function parse($Str) {
// (as the first close tag won't do - it's been opened again) // (as the first close tag won't do - it's been opened again)
do { do {
$CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag+1); $CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag+1);
if($CloseTag === false) { if ($CloseTag === false) {
$CloseTag = $Len; $CloseTag = $Len;
break; break;
} else { } else {
@ -343,21 +343,21 @@ function parse($Str) {
} }
// Is there another open tag inside this one? // Is there another open tag inside this one?
$OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos+1); $OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos + 1);
if(!$OpenTag || $InTag[0][1]>$CloseTag) { if (!$OpenTag || $InTag[0][1] > $CloseTag) {
break; break;
} else { } else {
$InTagPos = $InTag[0][1]; $InTagPos = $InTag[0][1];
$NumInOpens++; $NumInOpens++;
} }
} while($NumInOpens>$NumInCloses); } while ($NumInOpens > $NumInCloses);
// Find the internal block inside the tag // Find the internal block inside the tag
$Block = substr($Str, $i, $CloseTag-$i); // 5c) Get the contents between [open] and [/close] and call it the block. $Block = substr($Str, $i, $CloseTag - $i); // 5c) Get the contents between [open] and [/close] and call it the block.
$i = $CloseTag+strlen($TagName)+3; // 5d) Move the pointer past the end of the [/close] tag. $i = $CloseTag + strlen($TagName) + 3; // 5d) Move the pointer past the end of the [/close] tag.
} }
@ -368,7 +368,7 @@ function parse($Str) {
break; break;
case 'url': case 'url':
$Array[$ArrayPos] = array('Type'=>'img', 'Attr'=>$Attrib, 'Val'=>$Block); $Array[$ArrayPos] = array('Type'=>'img', 'Attr'=>$Attrib, 'Val'=>$Block);
if(empty($Attrib)) { // [url]http://...[/url] - always set URL to attribute if (empty($Attrib)) { // [url]http://...[/url] - always set URL to attribute
$Array[$ArrayPos] = array('Type'=>'url', 'Attr'=>$Block, 'Val'=>''); $Array[$ArrayPos] = array('Type'=>'url', 'Attr'=>$Block, 'Val'=>'');
} else { } else {
$Array[$ArrayPos] = array('Type'=>'url', 'Attr'=>$Attrib, 'Val'=>$this->parse($Block)); $Array[$ArrayPos] = array('Type'=>'url', 'Attr'=>$Attrib, 'Val'=>$this->parse($Block));
@ -379,7 +379,7 @@ function parse($Str) {
break; break;
case 'img': case 'img':
case 'image': case 'image':
if(empty($Block)) { if (empty($Block)) {
$Block = $Attrib; $Block = $Attrib;
} }
$Array[$ArrayPos] = array('Type'=>'img', 'Val'=>$Block); $Array[$ArrayPos] = array('Type'=>'img', 'Val'=>$Block);
@ -387,7 +387,7 @@ function parse($Str) {
case 'aud': case 'aud':
case 'mp3': case 'mp3':
case 'audio': case 'audio':
if(empty($Block)) { if (empty($Block)) {
$Block = $Attrib; $Block = $Attrib;
} }
$Array[$ArrayPos] = array('Type'=>'aud', 'Val'=>$Block); $Array[$ArrayPos] = array('Type'=>'aud', 'Val'=>$Block);
@ -417,7 +417,7 @@ function parse($Str) {
case '*': case '*':
$Array[$ArrayPos] = array('Type'=>'list'); $Array[$ArrayPos] = array('Type'=>'list');
$Array[$ArrayPos]['Val'] = explode('[*]', $Block); $Array[$ArrayPos]['Val'] = explode('[*]', $Block);
foreach($Array[$ArrayPos]['Val'] as $Key=>$Val) { foreach ($Array[$ArrayPos]['Val'] as $Key=>$Val) {
$Array[$ArrayPos]['Val'][$Key] = $this->parse(trim($Val)); $Array[$ArrayPos]['Val'][$Key] = $this->parse(trim($Val));
} }
break; break;
@ -425,14 +425,14 @@ function parse($Str) {
$ArrayPos--; $ArrayPos--;
break; // n serves only to disrupt bbcode (backwards compatibility - use [pre]) break; // n serves only to disrupt bbcode (backwards compatibility - use [pre])
default: default:
if($WikiLink == true) { if ($WikiLink == true) {
$Array[$ArrayPos] = array('Type'=>'wiki','Val'=>$TagName); $Array[$ArrayPos] = array('Type'=>'wiki','Val'=>$TagName);
} else { } else {
// Basic tags, like [b] or [size=5] // Basic tags, like [b] or [size=5]
$Array[$ArrayPos] = array('Type'=>$TagName, 'Val'=>$this->parse($Block)); $Array[$ArrayPos] = array('Type'=>$TagName, 'Val'=>$this->parse($Block));
if(!empty($Attrib) && $MaxAttribs>0) { if (!empty($Attrib) && $MaxAttribs > 0) {
$Array[$ArrayPos]['Attr'] = strtolower($Attrib); $Array[$ArrayPos]['Attr'] = strtolower($Attrib);
} }
} }
@ -445,11 +445,13 @@ function parse($Str) {
function to_html($Array) { function to_html($Array) {
$this->Levels++; $this->Levels++;
if($this->Levels>10) { return $Block['Val']; } // Hax prevention if ($this->Levels > 10) {
return $Block['Val'];
} // Hax prevention
$Str = ''; $Str = '';
foreach($Array as $Block) { foreach ($Array as $Block) {
if(is_string($Block)) { if (is_string($Block)) {
$Str.=$this->smileys($Block); $Str.=$this->smileys($Block);
continue; continue;
} }
@ -489,7 +491,7 @@ function to_html($Array) {
break; break;
case 'list': case 'list':
$Str.='<ul>'; $Str.='<ul>';
foreach($Block['Val'] as $Line) { foreach ($Block['Val'] as $Line) {
$Str.='<li>'.$this->to_html($Line).'</li>'; $Str.='<li>'.$this->to_html($Line).'</li>';
} }
@ -497,7 +499,7 @@ function to_html($Array) {
break; break;
case 'align': case 'align':
$ValidAttribs = array('left', 'center', 'right'); $ValidAttribs = array('left', 'center', 'right');
if(!in_array($Block['Attr'], $ValidAttribs)) { if (!in_array($Block['Attr'], $ValidAttribs)) {
$Str.='[align='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/align]'; $Str.='[align='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/align]';
} else { } else {
$Str.='<div style="text-align:'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</div>'; $Str.='<div style="text-align:'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</div>';
@ -506,7 +508,7 @@ function to_html($Array) {
case 'color': case 'color':
case 'colour': case 'colour':
$ValidAttribs = array('aqua', 'black', 'blue', 'fuchsia', 'green', 'grey', 'lime', 'maroon', 'navy', 'olive', 'purple', 'red', 'silver', 'teal', 'white', 'yellow'); $ValidAttribs = array('aqua', 'black', 'blue', 'fuchsia', 'green', 'grey', 'lime', 'maroon', 'navy', 'olive', 'purple', 'red', 'silver', 'teal', 'white', 'yellow');
if(!in_array($Block['Attr'], $ValidAttribs) && !preg_match('/^#[0-9a-f]{6}$/', $Block['Attr'])) { if (!in_array($Block['Attr'], $ValidAttribs) && !preg_match('/^#[0-9a-f]{6}$/', $Block['Attr'])) {
$Str.='[color='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/color]'; $Str.='[color='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/color]';
} else { } else {
$Str.='<span style="color:'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</span>'; $Str.='<span style="color:'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</span>';
@ -515,7 +517,7 @@ function to_html($Array) {
case 'inlinesize': case 'inlinesize':
case 'size': case 'size':
$ValidAttribs = array('1','2','3','4','5','6','7','8','9','10'); $ValidAttribs = array('1','2','3','4','5','6','7','8','9','10');
if(!in_array($Block['Attr'], $ValidAttribs)) { if (!in_array($Block['Attr'], $ValidAttribs)) {
$Str.='[size='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/size]'; $Str.='[size='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/size]';
} else { } else {
$Str.='<span class="size'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</span>'; $Str.='<span class="size'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</span>';
@ -523,7 +525,7 @@ function to_html($Array) {
break; break;
case 'quote': case 'quote':
$this->NoImg++; // No images inside quote tags $this->NoImg++; // No images inside quote tags
if(!empty($Block['Attr'])) { if (!empty($Block['Attr'])) {
$Str.='<strong>'.$this->to_html($Block['Attr']).'</strong> wrote: '; $Str.='<strong>'.$this->to_html($Block['Attr']).'</strong> wrote: ';
} }
$Str.='<blockquote>'.$this->to_html($Block['Val']).'</blockquote>'; $Str.='<blockquote>'.$this->to_html($Block['Val']).'</blockquote>';
@ -534,14 +536,14 @@ function to_html($Array) {
$Str.='<blockquote class="hidden spoiler">'.$this->to_html($Block['Val']).'</blockquote>'; $Str.='<blockquote class="hidden spoiler">'.$this->to_html($Block['Val']).'</blockquote>';
break; break;
case 'img': case 'img':
if($this->NoImg>0 && $this->valid_url($Block['Val'])) { if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) {
$Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (image)'; $Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (image)';
break; break;
} }
if(!$this->valid_url($Block['Val'], '\.(jpe?g|gif|png|bmp|tiff)')) { if (!$this->valid_url($Block['Val'], '\.(jpe?g|gif|png|bmp|tiff)')) {
$Str.='[img]'.$Block['Val'].'[/img]'; $Str.='[img]'.$Block['Val'].'[/img]';
} else { } else {
if(check_perms('site_proxy_images')) { if (check_perms('site_proxy_images')) {
$Str.='<img style="max-width: 500px;" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?i='.urlencode($Block['Val']).'" />'; $Str.='<img style="max-width: 500px;" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?i='.urlencode($Block['Val']).'" />';
} else { } else {
$Str.='<img style="max-width: 500px;" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="'.$Block['Val'].'" />'; $Str.='<img style="max-width: 500px;" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="'.$Block['Val'].'" />';
@ -550,11 +552,11 @@ function to_html($Array) {
break; break;
case 'aud': case 'aud':
if($this->NoImg>0 && $this->valid_url($Block['Val'])) { if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) {
$Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (audio)'; $Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (audio)';
break; break;
} }
if(!$this->valid_url($Block['Val'], '\.(mp3|ogg|wav)')) { if (!$this->valid_url($Block['Val'], '\.(mp3|ogg|wav)')) {
$Str.='[aud]'.$Block['Val'].'[/aud]'; $Str.='[aud]'.$Block['Val'].'[/aud]';
} else { } else {
//TODO: Proxy this for staff? //TODO: Proxy this for staff?
@ -564,7 +566,7 @@ function to_html($Array) {
case 'url': case 'url':
// Make sure the URL has a label // Make sure the URL has a label
if(empty($Block['Val'])) { if (empty($Block['Val'])) {
$Block['Val'] = $Block['Attr']; $Block['Val'] = $Block['Attr'];
$NoName = true; // If there isn't a Val for this $NoName = true; // If there isn't a Val for this
} else { } else {
@ -572,12 +574,14 @@ function to_html($Array) {
$NoName = false; $NoName = false;
} }
if(!$this->valid_url($Block['Attr'])) { if (!$this->valid_url($Block['Attr'])) {
$Str.='[url='.$Block['Attr'].']'.$Block['Val'].'[/url]'; $Str.='[url='.$Block['Attr'].']'.$Block['Val'].'[/url]';
} else { } else {
$LocalURL = $this->local_url($Block['Attr']); $LocalURL = $this->local_url($Block['Attr']);
if($LocalURL) { if ($LocalURL) {
if($NoName) { $Block['Val'] = substr($LocalURL,1); } if ($NoName) {
$Block['Val'] = substr($LocalURL,1);
}
$Str.='<a href="'.$LocalURL.'">'.$Block['Val'].'</a>'; $Str.='<a href="'.$LocalURL.'">'.$Block['Val'].'</a>';
} else { } else {
$Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Attr'].'">'.$Block['Val'].'</a>'; $Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Attr'].'">'.$Block['Val'].'</a>';
@ -586,7 +590,7 @@ function to_html($Array) {
break; break;
case 'inlineurl': case 'inlineurl':
if(!$this->valid_url($Block['Attr'], '', true)) { if (!$this->valid_url($Block['Attr'], '', true)) {
$Array = $this->parse($Block['Attr']); $Array = $this->parse($Block['Attr']);
$Block['Attr'] = $Array; $Block['Attr'] = $Array;
$Str.=$this->to_html($Block['Attr']); $Str.=$this->to_html($Block['Attr']);
@ -594,7 +598,7 @@ function to_html($Array) {
else { else {
$LocalURL = $this->local_url($Block['Attr']); $LocalURL = $this->local_url($Block['Attr']);
if($LocalURL) { if ($LocalURL) {
$Str.='<a href="'.$LocalURL.'">'.substr($LocalURL,1).'</a>'; $Str.='<a href="'.$LocalURL.'">'.substr($LocalURL,1).'</a>';
} else { } else {
$Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Attr'].'">'.$Block['Attr'].'</a>'; $Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Attr'].'">'.$Block['Attr'].'</a>';
@ -611,8 +615,8 @@ function to_html($Array) {
function raw_text($Array) { function raw_text($Array) {
$Str = ''; $Str = '';
foreach($Array as $Block) { foreach ($Array as $Block) {
if(is_string($Block)) { if (is_string($Block)) {
$Str.=$Block; $Str.=$Block;
continue; continue;
} }
@ -641,14 +645,14 @@ function raw_text($Array) {
$Str.=$Block['Val']; $Str.=$Block['Val'];
break; break;
case 'list': case 'list':
foreach($Block['Val'] as $Line) { foreach ($Block['Val'] as $Line) {
$Str.='*'.$this->raw_text($Line); $Str.='*'.$this->raw_text($Line);
} }
break; break;
case 'url': case 'url':
// Make sure the URL has a label // Make sure the URL has a label
if(empty($Block['Val'])) { if (empty($Block['Val'])) {
$Block['Val'] = $Block['Attr']; $Block['Val'] = $Block['Attr'];
} else { } else {
$Block['Val'] = $this->raw_text($Block['Val']); $Block['Val'] = $this->raw_text($Block['Val']);
@ -658,7 +662,7 @@ function raw_text($Array) {
break; break;
case 'inlineurl': case 'inlineurl':
if(!$this->valid_url($Block['Attr'], '', true)) { if (!$this->valid_url($Block['Attr'], '', true)) {
$Array = $this->parse($Block['Attr']); $Array = $this->parse($Block['Attr']);
$Block['Attr'] = $Array; $Block['Attr'] = $Array;
$Str.=$this->raw_text($Block['Attr']); $Str.=$this->raw_text($Block['Attr']);
@ -675,7 +679,7 @@ function raw_text($Array) {
function smileys($Str) { function smileys($Str) {
global $LoggedUser; global $LoggedUser;
if(!empty($LoggedUser['DisableSmileys'])) { if (!empty($LoggedUser['DisableSmileys'])) {
return $Str; return $Str;
} }
$Str = strtr($Str, $this->Smileys); $Str = strtr($Str, $this->Smileys);

View File

@ -51,7 +51,7 @@ class TEXT_3 {
private $Levels = 0; // If images should be turned into URLs private $Levels = 0; // If images should be turned into URLs
function __construct() { function __construct() {
foreach($this->Smileys as $Key=>$Val) { foreach ($this->Smileys as $Key=>$Val) {
$this->Smileys[$Key] = '<img border="0" src="'.STATIC_SERVER.'common/smileys/'.$Val.'" alt="" />'; $this->Smileys[$Key] = '<img border="0" src="'.STATIC_SERVER.'common/smileys/'.$Val.'" alt="" />';
} }
reset($this->Smileys); reset($this->Smileys);
@ -102,7 +102,7 @@ function valid_url($Str, $Extension = '', $Inline = false) {
$Regex .= '(:[0-9]{1,5})?'; // port $Regex .= '(:[0-9]{1,5})?'; // port
$Regex .= '\/?'; // slash? $Regex .= '\/?'; // slash?
$Regex .= '(\/?[0-9a-z\-_.,&=@~%\/:;()+!#]+)*'; // /file $Regex .= '(\/?[0-9a-z\-_.,&=@~%\/:;()+!#]+)*'; // /file
if(!empty($Extension)) { if (!empty($Extension)) {
$Regex.=$Extension; $Regex.=$Extension;
} }
@ -121,16 +121,18 @@ function valid_url($Str, $Extension = '', $Inline = false) {
function local_url($Str) { function local_url($Str) {
$URLInfo = parse_url($Str); $URLInfo = parse_url($Str);
if(!$URLInfo) { return false; } if (!$URLInfo) {
return false;
}
$Host = $URLInfo['host']; $Host = $URLInfo['host'];
// If for some reason your site does not require subdomains or contains a directory in the SITE_URL, revert to the line below. // If for some reason your site does not require subdomains or contains a directory in the SITE_URL, revert to the line below.
//if($Host == NONSSL_SITE_URL || $Host == SSL_SITE_URL || $Host == 'www.'.NONSSL_SITE_URL) { //if ($Host == NONSSL_SITE_URL || $Host == SSL_SITE_URL || $Host == 'www.'.NONSSL_SITE_URL) {
if(preg_match('/(\S+\.)*'.NONSSL_SITE_URL.'/', $Host)) { if (preg_match('/(\S+\.)*'.NONSSL_SITE_URL.'/', $Host)) {
$URL = $URLInfo['path']; $URL = $URLInfo['path'];
if(!empty($URLInfo['query'])) { if (!empty($URLInfo['query'])) {
$URL.='?'.$URLInfo['query']; $URL.='?'.$URLInfo['query'];
} }
if(!empty($URLInfo['fragment'])) { if (!empty($URLInfo['fragment'])) {
$URL.='#'.$URLInfo['fragment']; $URL.='#'.$URLInfo['fragment'];
} }
return $URL; return $URL;
@ -184,7 +186,7 @@ function parse($Str) {
$Array = array(); $Array = array();
$ArrayPos = 0; $ArrayPos = 0;
while($i<$Len) { while ($i < $Len) {
$Block = ''; $Block = '';
// 1) Find the next tag (regex) // 1) Find the next tag (regex)
@ -192,7 +194,7 @@ function parse($Str) {
$IsTag = preg_match("/((\[[a-zA-Z*]+)(=(?:[^\n'\"\[\]]|\[\d*\])+)?\])|(\[\[[^\n\"'\[\]]+\]\])/", $Str, $Tag, PREG_OFFSET_CAPTURE, $i); $IsTag = preg_match("/((\[[a-zA-Z*]+)(=(?:[^\n'\"\[\]]|\[\d*\])+)?\])|(\[\[[^\n\"'\[\]]+\]\])/", $Str, $Tag, PREG_OFFSET_CAPTURE, $i);
// 1a) If there aren't any tags left, write everything remaining to a block // 1a) If there aren't any tags left, write everything remaining to a block
if(!$IsTag) { if (!$IsTag) {
// No more tags // No more tags
$Array[$ArrayPos] = substr($Str, $i); $Array[$ArrayPos] = substr($Str, $i);
break; break;
@ -200,14 +202,14 @@ function parse($Str) {
// 1b) If the next tag isn't where the pointer is, write everything up to there to a text block. // 1b) If the next tag isn't where the pointer is, write everything up to there to a text block.
$TagPos = $Tag[0][1]; $TagPos = $Tag[0][1];
if($TagPos>$i) { if ($TagPos > $i) {
$Array[$ArrayPos] = substr($Str, $i, $TagPos-$i); $Array[$ArrayPos] = substr($Str, $i, $TagPos - $i);
++$ArrayPos; ++$ArrayPos;
$i=$TagPos; $i = $TagPos;
} }
// 2) See if it's a [[wiki-link]] or an ordinary tag, and get the tag name // 2) See if it's a [[wiki-link]] or an ordinary tag, and get the tag name
if(!empty($Tag[4][0])) { // Wiki-link if (!empty($Tag[4][0])) { // Wiki-link
$WikiLink = true; $WikiLink = true;
$TagName = substr($Tag[4][0], 2, -2); $TagName = substr($Tag[4][0], 2, -2);
$Attrib = ''; $Attrib = '';
@ -216,9 +218,9 @@ function parse($Str) {
$TagName = strtolower(substr($Tag[2][0], 1)); $TagName = strtolower(substr($Tag[2][0], 1));
//3a) check it against the $this->ValidTags array to see if it's actually a tag and not [bullshit] //3a) check it against the $this->ValidTags array to see if it's actually a tag and not [bullshit]
if(!isset($this->ValidTags[$TagName])) { if (!isset($this->ValidTags[$TagName])) {
$Array[$ArrayPos] = substr($Str, $i, ($TagPos-$i)+strlen($Tag[0][0])); $Array[$ArrayPos] = substr($Str, $i, ($TagPos - $i) + strlen($Tag[0][0]));
$i=$TagPos+strlen($Tag[0][0]); $i = $TagPos + strlen($Tag[0][0]);
++$ArrayPos; ++$ArrayPos;
continue; continue;
} }
@ -226,15 +228,15 @@ function parse($Str) {
$MaxAttribs = $this->ValidTags[$TagName]; $MaxAttribs = $this->ValidTags[$TagName];
// 3b) Get the attribute, if it exists [name=attribute] // 3b) Get the attribute, if it exists [name=attribute]
if(!empty($Tag[3][0])) { if (!empty($Tag[3][0])) {
$Attrib = substr($Tag[3][0], 1); $Attrib = substr($Tag[3][0], 1);
} else { } else {
$Attrib=''; $Attrib = '';
} }
} }
// 4) Move the pointer past the end of the tag // 4) Move the pointer past the end of the tag
$i=$TagPos+strlen($Tag[0][0]); $i = $TagPos + strlen($Tag[0][0]);
// 5) Find out where the tag closes (beginning of [/tag]) // 5) Find out where the tag closes (beginning of [/tag])
@ -244,21 +246,21 @@ function parse($Str) {
//5a) Different for different types of tag. Some tags don't close, others are weird like [*] //5a) Different for different types of tag. Some tags don't close, others are weird like [*]
if($TagName == 'img' && !empty($Tag[3][0])) { //[img=...] if ($TagName == 'img' && !empty($Tag[3][0])) { //[img=...]
$Block = ''; // Nothing inside this tag $Block = ''; // Nothing inside this tag
// Don't need to touch $i // Don't need to touch $i
} elseif($TagName == 'inlineurl') { // We did a big replace early on to turn http:// into [inlineurl]http:// } elseif ($TagName == 'inlineurl') { // We did a big replace early on to turn http:// into [inlineurl]http://
// Let's say the block can stop at a newline or a space // Let's say the block can stop at a newline or a space
$CloseTag = strcspn($Str, " \n\r", $i); $CloseTag = strcspn($Str, " \n\r", $i);
if($CloseTag === false) { // block finishes with URL if ($CloseTag === false) { // block finishes with URL
$CloseTag = $Len; $CloseTag = $Len;
} }
if(preg_match('/[!;,.?:]+$/',substr($Str, $i, $CloseTag), $Match)) { if (preg_match('/[!;,.?:]+$/',substr($Str, $i, $CloseTag), $Match)) {
$CloseTag -= strlen($Match[0]); $CloseTag -= strlen($Match[0]);
} }
$URL = substr($Str, $i, $CloseTag); $URL = substr($Str, $i, $CloseTag);
if(substr($URL, -1) == ')' && substr_count($URL, '(') < substr_count($URL, ')')) { if (substr($URL, -1) == ')' && substr_count($URL, '(') < substr_count($URL, ')')) {
$CloseTag--; $CloseTag--;
$URL = substr($URL, 0, -1); $URL = substr($URL, 0, -1);
} }
@ -267,20 +269,20 @@ function parse($Str) {
// strcspn returns the number of characters after the offset $i, not after the beginning of the string // strcspn returns the number of characters after the offset $i, not after the beginning of the string
// Therefore, we use += instead of the = everywhere else // Therefore, we use += instead of the = everywhere else
$i += $CloseTag; // 5d) Move the pointer past the end of the [/close] tag. $i += $CloseTag; // 5d) Move the pointer past the end of the [/close] tag.
} elseif($WikiLink == true || $TagName == 'n') { } elseif ($WikiLink == true || $TagName == 'n') {
// Don't need to do anything - empty tag with no closing // Don't need to do anything - empty tag with no closing
} elseif($TagName == '*') { } elseif ($TagName == '*') {
// We're in a list. Find where it ends // We're in a list. Find where it ends
$NewLine = $i; $NewLine = $i;
do { // Look for \n[*] do { // Look for \n[*]
$NewLine = strpos($Str, "\n", $NewLine+1); $NewLine = strpos($Str, "\n", $NewLine + 1);
} while($NewLine!== false && substr($Str, $NewLine+1, 3) == '[*]'); } while ($NewLine !== false && substr($Str, $NewLine+1, 3) == '[*]');
$CloseTag = $NewLine; $CloseTag = $NewLine;
if($CloseTag === false) { // block finishes with list if ($CloseTag === false) { // block finishes with list
$CloseTag = $Len; $CloseTag = $Len;
} }
$Block = substr($Str, $i, $CloseTag-$i); // Get the list $Block = substr($Str, $i, $CloseTag - $i); // Get the list
$i = $CloseTag; // 5d) Move the pointer past the end of the [/close] tag. $i = $CloseTag; // 5d) Move the pointer past the end of the [/close] tag.
} else { } else {
//5b) If it's a normal tag, it may have versions of itself nested inside //5b) If it's a normal tag, it may have versions of itself nested inside
@ -290,7 +292,7 @@ function parse($Str) {
$NumInCloses = -1; $NumInCloses = -1;
$InOpenRegex = '/\[('.$TagName.')'; $InOpenRegex = '/\[('.$TagName.')';
if($MaxAttribs>0) { if ($MaxAttribs > 0) {
$InOpenRegex.="(=[^\n'\"\[\]]+)?"; $InOpenRegex.="(=[^\n'\"\[\]]+)?";
} }
$InOpenRegex.='\]/i'; $InOpenRegex.='\]/i';
@ -300,7 +302,7 @@ function parse($Str) {
// (as the first close tag won't do - it's been opened again) // (as the first close tag won't do - it's been opened again)
do { do {
$CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag+1); $CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag+1);
if($CloseTag === false) { if ($CloseTag === false) {
$CloseTag = $Len; $CloseTag = $Len;
break; break;
} else { } else {
@ -308,8 +310,8 @@ function parse($Str) {
} }
// Is there another open tag inside this one? // Is there another open tag inside this one?
$OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos+1); $OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos + 1);
if(!$OpenTag || $InTag[0][1]>$CloseTag) { if (!$OpenTag || $InTag[0][1] > $CloseTag) {
break; break;
} else { } else {
$InTagPos = $InTag[0][1]; $InTagPos = $InTag[0][1];
@ -333,7 +335,7 @@ function parse($Str) {
break; break;
case 'url': case 'url':
$Array[$ArrayPos] = array('Type'=>'img', 'Attr'=>$Attrib, 'Val'=>$Block); $Array[$ArrayPos] = array('Type'=>'img', 'Attr'=>$Attrib, 'Val'=>$Block);
if(empty($Attrib)) { // [url]http://...[/url] - always set URL to attribute if (empty($Attrib)) { // [url]http://...[/url] - always set URL to attribute
$Array[$ArrayPos] = array('Type'=>'url', 'Attr'=>$Block, 'Val'=>''); $Array[$ArrayPos] = array('Type'=>'url', 'Attr'=>$Block, 'Val'=>'');
} else { } else {
$Array[$ArrayPos] = array('Type'=>'url', 'Attr'=>$Attrib, 'Val'=>$this->parse($Block)); $Array[$ArrayPos] = array('Type'=>'url', 'Attr'=>$Attrib, 'Val'=>$this->parse($Block));
@ -344,7 +346,7 @@ function parse($Str) {
break; break;
case 'img': case 'img':
case 'image': case 'image':
if(empty($Block)) { if (empty($Block)) {
$Block = $Attrib; $Block = $Attrib;
} }
$Array[$ArrayPos] = array('Type'=>'img', 'Val'=>$Block); $Array[$ArrayPos] = array('Type'=>'img', 'Val'=>$Block);
@ -352,7 +354,7 @@ function parse($Str) {
case 'aud': case 'aud':
case 'mp3': case 'mp3':
case 'audio': case 'audio':
if(empty($Block)) { if (empty($Block)) {
$Block = $Attrib; $Block = $Attrib;
} }
$Array[$ArrayPos] = array('Type'=>'aud', 'Val'=>$Block); $Array[$ArrayPos] = array('Type'=>'aud', 'Val'=>$Block);
@ -381,7 +383,7 @@ function parse($Str) {
case '*': case '*':
$Array[$ArrayPos] = array('Type'=>'list'); $Array[$ArrayPos] = array('Type'=>'list');
$Array[$ArrayPos]['Val'] = explode('[*]', $Block); $Array[$ArrayPos]['Val'] = explode('[*]', $Block);
foreach($Array[$ArrayPos]['Val'] as $Key=>$Val) { foreach ($Array[$ArrayPos]['Val'] as $Key=>$Val) {
$Array[$ArrayPos]['Val'][$Key] = $this->parse(trim($Val)); $Array[$ArrayPos]['Val'][$Key] = $this->parse(trim($Val));
} }
break; break;
@ -389,14 +391,14 @@ function parse($Str) {
$ArrayPos--; $ArrayPos--;
break; // n serves only to disrupt bbcode (backwards compatibility - use [pre]) break; // n serves only to disrupt bbcode (backwards compatibility - use [pre])
default: default:
if($WikiLink == true) { if ($WikiLink == true) {
$Array[$ArrayPos] = array('Type'=>'wiki','Val'=>$TagName); $Array[$ArrayPos] = array('Type'=>'wiki','Val'=>$TagName);
} else { } else {
// Basic tags, like [b] or [size=5] // Basic tags, like [b] or [size=5]
$Array[$ArrayPos] = array('Type'=>$TagName, 'Val'=>$this->parse($Block)); $Array[$ArrayPos] = array('Type'=>$TagName, 'Val'=>$this->parse($Block));
if(!empty($Attrib) && $MaxAttribs>0) { if (!empty($Attrib) && $MaxAttribs>0) {
$Array[$ArrayPos]['Attr'] = strtolower($Attrib); $Array[$ArrayPos]['Attr'] = strtolower($Attrib);
} }
} }
@ -409,11 +411,11 @@ function parse($Str) {
function to_html($Array) { function to_html($Array) {
$this->Levels++; $this->Levels++;
if($this->Levels>10) { return $Block['Val']; } // Hax prevention if ($this->Levels>10) { return $Block['Val']; } // Hax prevention
$Str = ''; $Str = '';
foreach($Array as $Block) { foreach ($Array as $Block) {
if(is_string($Block)) { if (is_string($Block)) {
$Str.=$this->smileys($Block); $Str.=$this->smileys($Block);
continue; continue;
} }
@ -450,7 +452,7 @@ function to_html($Array) {
break; break;
case 'list': case 'list':
$Str.='<ul>'; $Str.='<ul>';
foreach($Block['Val'] as $Line) { foreach ($Block['Val'] as $Line) {
$Str.='<li>'.$this->to_html($Line).'</li>'; $Str.='<li>'.$this->to_html($Line).'</li>';
} }
@ -458,7 +460,7 @@ function to_html($Array) {
break; break;
case 'align': case 'align':
$ValidAttribs = array('left', 'center', 'right'); $ValidAttribs = array('left', 'center', 'right');
if(!in_array($Block['Attr'], $ValidAttribs)) { if (!in_array($Block['Attr'], $ValidAttribs)) {
$Str.='[align='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/align]'; $Str.='[align='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/align]';
} else { } else {
$Str.='<div style="text-align:'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</div>'; $Str.='<div style="text-align:'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</div>';
@ -467,7 +469,7 @@ function to_html($Array) {
case 'color': case 'color':
case 'colour': case 'colour':
$ValidAttribs = array('aqua', 'black', 'blue', 'fuchsia', 'green', 'grey', 'lime', 'maroon', 'navy', 'olive', 'purple', 'red', 'silver', 'teal', 'white', 'yellow'); $ValidAttribs = array('aqua', 'black', 'blue', 'fuchsia', 'green', 'grey', 'lime', 'maroon', 'navy', 'olive', 'purple', 'red', 'silver', 'teal', 'white', 'yellow');
if(!in_array($Block['Attr'], $ValidAttribs) && !preg_match('/^#[0-9a-f]{6}$/', $Block['Attr'])) { if (!in_array($Block['Attr'], $ValidAttribs) && !preg_match('/^#[0-9a-f]{6}$/', $Block['Attr'])) {
$Str.='[color='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/color]'; $Str.='[color='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/color]';
} else { } else {
$Str.='<span style="color:'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</span>'; $Str.='<span style="color:'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</span>';
@ -476,7 +478,7 @@ function to_html($Array) {
case 'inlinesize': case 'inlinesize':
case 'size': case 'size':
$ValidAttribs = array('1','2','3','4','5','6','7','8','9','10'); $ValidAttribs = array('1','2','3','4','5','6','7','8','9','10');
if(!in_array($Block['Attr'], $ValidAttribs)) { if (!in_array($Block['Attr'], $ValidAttribs)) {
$Str.='[size='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/size]'; $Str.='[size='.$Block['Attr'].']'.$this->to_html($Block['Val']).'[/size]';
} else { } else {
$Str.='<span class="size'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</span>'; $Str.='<span class="size'.$Block['Attr'].'">'.$this->to_html($Block['Val']).'</span>';
@ -484,7 +486,7 @@ function to_html($Array) {
break; break;
case 'quote': case 'quote':
$this->NoImg++; // No images inside quote tags $this->NoImg++; // No images inside quote tags
if(!empty($Block['Attr'])) { if (!empty($Block['Attr'])) {
$Str.='<strong>'.$this->to_html($Block['Attr']).'</strong> wrote: '; $Str.='<strong>'.$this->to_html($Block['Attr']).'</strong> wrote: ';
} }
$Str.='<blockquote>'.$this->to_html($Block['Val']).'</blockquote>'; $Str.='<blockquote>'.$this->to_html($Block['Val']).'</blockquote>';
@ -495,14 +497,14 @@ function to_html($Array) {
$Str.='<blockquote class="hidden spoiler">'.$this->to_html($Block['Val']).'</blockquote>'; $Str.='<blockquote class="hidden spoiler">'.$this->to_html($Block['Val']).'</blockquote>';
break; break;
case 'img': case 'img':
if($this->NoImg>0 && $this->valid_url($Block['Val'])) { if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) {
$Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (image)'; $Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (image)';
break; break;
} }
if(!$this->valid_url($Block['Val'], '\.(jpe?g|gif|png|bmp|tiff)')) { if (!$this->valid_url($Block['Val'], '\.(jpe?g|gif|png|bmp|tiff)')) {
$Str.='[img]'.$Block['Val'].'[/img]'; $Str.='[img]'.$Block['Val'].'[/img]';
} else { } else {
if(check_perms('site_proxy_images')) { if (check_perms('site_proxy_images')) {
$Str.='<img style="max-width: 500px;" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?i='.urlencode($Block['Val']).'" />'; $Str.='<img style="max-width: 500px;" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?i='.urlencode($Block['Val']).'" />';
} else { } else {
$Str.='<img style="max-width: 500px;" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="'.$Block['Val'].'" />'; $Str.='<img style="max-width: 500px;" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="'.$Block['Val'].'" />';
@ -511,11 +513,11 @@ function to_html($Array) {
break; break;
case 'aud': case 'aud':
if($this->NoImg>0 && $this->valid_url($Block['Val'])) { if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) {
$Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (audio)'; $Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Val'].'">'.$Block['Val'].'</a> (audio)';
break; break;
} }
if(!$this->valid_url($Block['Val'], '\.(mp3|ogg|wav)')) { if (!$this->valid_url($Block['Val'], '\.(mp3|ogg|wav)')) {
$Str.='[aud]'.$Block['Val'].'[/aud]'; $Str.='[aud]'.$Block['Val'].'[/aud]';
} else { } else {
//TODO: Proxy this for staff? //TODO: Proxy this for staff?
@ -525,7 +527,7 @@ function to_html($Array) {
case 'url': case 'url':
// Make sure the URL has a label // Make sure the URL has a label
if(empty($Block['Val'])) { if (empty($Block['Val'])) {
$Block['Val'] = $Block['Attr']; $Block['Val'] = $Block['Attr'];
$NoName = true; // If there isn't a Val for this $NoName = true; // If there isn't a Val for this
} else { } else {
@ -533,12 +535,14 @@ function to_html($Array) {
$NoName = false; $NoName = false;
} }
if(!$this->valid_url($Block['Attr'])) { if (!$this->valid_url($Block['Attr'])) {
$Str.='[url='.$Block['Attr'].']'.$Block['Val'].'[/url]'; $Str.='[url='.$Block['Attr'].']'.$Block['Val'].'[/url]';
} else { } else {
$LocalURL = $this->local_url($Block['Attr']); $LocalURL = $this->local_url($Block['Attr']);
if($LocalURL) { if ($LocalURL) {
if($NoName) { $Block['Val'] = substr($LocalURL,1); } if ($NoName) {
$Block['Val'] = substr($LocalURL,1);
}
$Str.='<a href="'.$LocalURL.'">'.$Block['Val'].'</a>'; $Str.='<a href="'.$LocalURL.'">'.$Block['Val'].'</a>';
} else { } else {
$Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Attr'].'">'.$Block['Val'].'</a>'; $Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Attr'].'">'.$Block['Val'].'</a>';
@ -547,7 +551,7 @@ function to_html($Array) {
break; break;
case 'inlineurl': case 'inlineurl':
if(!$this->valid_url($Block['Attr'], '', true)) { if (!$this->valid_url($Block['Attr'], '', true)) {
$Array = $this->parse($Block['Attr']); $Array = $this->parse($Block['Attr']);
$Block['Attr'] = $Array; $Block['Attr'] = $Array;
$Str.=$this->to_html($Block['Attr']); $Str.=$this->to_html($Block['Attr']);
@ -555,7 +559,7 @@ function to_html($Array) {
else { else {
$LocalURL = $this->local_url($Block['Attr']); $LocalURL = $this->local_url($Block['Attr']);
if($LocalURL) { if ($LocalURL) {
$Str.='<a href="'.$LocalURL.'">'.substr($LocalURL,1).'</a>'; $Str.='<a href="'.$LocalURL.'">'.substr($LocalURL,1).'</a>';
} else { } else {
$Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Attr'].'">'.$Block['Attr'].'</a>'; $Str.='<a rel="noreferrer" target="_blank" href="'.$Block['Attr'].'">'.$Block['Attr'].'</a>';
@ -572,8 +576,8 @@ function to_html($Array) {
function raw_text($Array) { function raw_text($Array) {
$Str = ''; $Str = '';
foreach($Array as $Block) { foreach ($Array as $Block) {
if(is_string($Block)) { if (is_string($Block)) {
$Str.=$Block; $Str.=$Block;
continue; continue;
} }
@ -601,14 +605,14 @@ function raw_text($Array) {
$Str.=$Block['Val']; $Str.=$Block['Val'];
break; break;
case 'list': case 'list':
foreach($Block['Val'] as $Line) { foreach ($Block['Val'] as $Line) {
$Str.='*'.$this->raw_text($Line); $Str.='*'.$this->raw_text($Line);
} }
break; break;
case 'url': case 'url':
// Make sure the URL has a label // Make sure the URL has a label
if(empty($Block['Val'])) { if (empty($Block['Val'])) {
$Block['Val'] = $Block['Attr']; $Block['Val'] = $Block['Attr'];
} else { } else {
$Block['Val'] = $this->raw_text($Block['Val']); $Block['Val'] = $this->raw_text($Block['Val']);
@ -618,7 +622,7 @@ function raw_text($Array) {
break; break;
case 'inlineurl': case 'inlineurl':
if(!$this->valid_url($Block['Attr'], '', true)) { if (!$this->valid_url($Block['Attr'], '', true)) {
$Array = $this->parse($Block['Attr']); $Array = $this->parse($Block['Attr']);
$Block['Attr'] = $Array; $Block['Attr'] = $Array;
$Str.=$this->raw_text($Block['Attr']); $Str.=$this->raw_text($Block['Attr']);
@ -635,7 +639,7 @@ function raw_text($Array) {
function smileys($Str) { function smileys($Str) {
global $LoggedUser; global $LoggedUser;
if(!empty($LoggedUser['DisableSmileys'])) { if (!empty($LoggedUser['DisableSmileys'])) {
return $Str; return $Str;
} }
$Str = strtr($Str, $this->Smileys); $Str = strtr($Str, $this->Smileys);

View File

@ -23,7 +23,7 @@ public static function site_ban_ip($IP) {
return true; return true;
} }
} }
return false; return false;
} }
@ -95,7 +95,7 @@ public static function get_host_by_ip($IP) {
public static function get_host_by_ajax($IP) { public static function get_host_by_ajax($IP) {
static $ID = 0; static $ID = 0;
++$ID; ++$ID;
return '<span id="host_'.$ID.'">Resolving host...<script type="text/javascript">ajax.get(\'tools.php?action=get_host&ip='.$IP.'\',function(host){$(\'#host_'.$ID.'\').raw().innerHTML=host;});</script></span>'; return '<span id="host_'.$ID.'">Resolving host...<script type="text/javascript">ajax.get(\'tools.php?action=get_host&ip='.$IP.'\',function(host) {$(\'#host_'.$ID.'\').raw().innerHTML=host;});</script></span>';
} }
@ -137,7 +137,7 @@ public static function display_ip($IP) {
public static function get_country_code_by_ajax($IP) { public static function get_country_code_by_ajax($IP) {
static $ID = 0; static $ID = 0;
++$ID; ++$ID;
return '<span id="cc_'.$ID.'">Resolving CC...<script type="text/javascript">ajax.get(\'tools.php?action=get_cc&ip='.$IP.'\',function(cc){$(\'#cc_'.$ID.'\').raw().innerHTML=cc;});</script></span>'; return '<span id="cc_'.$ID.'">Resolving CC...<script type="text/javascript">ajax.get(\'tools.php?action=get_cc&ip='.$IP.'\',function(cc) {$(\'#cc_'.$ID.'\').raw().innerHTML=cc;});</script></span>';
} }
@ -154,16 +154,18 @@ public static function disable_users($UserIDs, $AdminComment, $BanReason = 1) {
if (!is_array($UserIDs)) { if (!is_array($UserIDs)) {
$UserIDs = array($UserIDs); $UserIDs = array($UserIDs);
} }
$DB->query("UPDATE users_info AS i JOIN users_main AS m ON m.ID=i.UserID $DB->query("
UPDATE users_info AS i
JOIN users_main AS m ON m.ID=i.UserID
SET m.Enabled='2', SET m.Enabled='2',
m.can_leech='0', m.can_leech='0',
i.AdminComment = CONCAT('".sqltime()." - ".($AdminComment ? $AdminComment : 'Disabled by system')."\n\n', i.AdminComment), i.AdminComment = CONCAT('".sqltime()." - ".($AdminComment ? $AdminComment : 'Disabled by system')."\n\n', i.AdminComment),
i.BanDate='".sqltime()."', i.BanDate='".sqltime()."',
i.BanReason='".$BanReason."', i.BanReason='".$BanReason."',
i.RatioWatchDownload=".($BanReason == 2?'m.Downloaded':"'0'")." i.RatioWatchDownload=".($BanReason == 2 ? 'm.Downloaded' : "'0'")."
WHERE m.ID IN(".implode(',',$UserIDs).") "); WHERE m.ID IN(".implode(',',$UserIDs).") ");
$Cache->decrement('stats_user_count',$DB->affected_rows()); $Cache->decrement('stats_user_count',$DB->affected_rows());
foreach($UserIDs as $UserID) { foreach ($UserIDs as $UserID) {
$Cache->delete_value('enabled_'.$UserID); $Cache->delete_value('enabled_'.$UserID);
$Cache->delete_value('user_info_'.$UserID); $Cache->delete_value('user_info_'.$UserID);
$Cache->delete_value('user_info_heavy_'.$UserID); $Cache->delete_value('user_info_heavy_'.$UserID);

View File

@ -68,8 +68,8 @@ class BENCODE2 {
var $Pos = 1; // Pointer that indicates our position in the string var $Pos = 1; // Pointer that indicates our position in the string
var $Str = ''; // Torrent string var $Str = ''; // Torrent string
function __construct($Val, $IsParsed = false){ function __construct($Val, $IsParsed = false) {
if(!$IsParsed) { if (!$IsParsed) {
$this->Str = $Val; $this->Str = $Val;
$this->dec(); $this->dec();
} else { } else {
@ -78,20 +78,20 @@ function __construct($Val, $IsParsed = false){
} }
// Decode an element based on the type. The type is really just an indicator. // Decode an element based on the type. The type is really just an indicator.
function decode($Type, $Key){ function decode($Type, $Key) {
if(is_number($Type)) { // Element is a string if (is_number($Type)) { // Element is a string
// Get length of string // Get length of string
$StrLen = $Type; $StrLen = $Type;
while($this->Str[$this->Pos+1]!=':'){ while ($this->Str[$this->Pos + 1] != ':') {
$this->Pos++; $this->Pos++;
$StrLen.=$this->Str[$this->Pos]; $StrLen.=$this->Str[$this->Pos];
} }
$this->Val[$Key] = substr($this->Str, $this->Pos+2, $StrLen); $this->Val[$Key] = substr($this->Str, $this->Pos + 2, $StrLen);
$this->Pos+=$StrLen; $this->Pos += $StrLen;
$this->Pos+=2; $this->Pos += 2;
} elseif($Type == 'i') { // Element is an int } elseif ($Type == 'i') { // Element is an int
$this->Pos++; $this->Pos++;
// Find end of integer (first occurance of 'e' after position) // Find end of integer (first occurance of 'e' after position)
@ -99,13 +99,13 @@ function decode($Type, $Key){
// Get the integer, and - IMPORTANT - cast it as an int, so we know later that it's an int and not a string // Get the integer, and - IMPORTANT - cast it as an int, so we know later that it's an int and not a string
$this->Val[$Key] = (int)substr($this->Str, $this->Pos, $End-$this->Pos); $this->Val[$Key] = (int)substr($this->Str, $this->Pos, $End-$this->Pos);
$this->Pos = $End+1; $this->Pos = $End + 1;
} elseif($Type == 'l') { // Element is a list } elseif ($Type == 'l') { // Element is a list
$this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos)); $this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos));
$this->Pos += $this->Val[$Key]->Pos; $this->Pos += $this->Val[$Key]->Pos;
} elseif($Type == 'd') { // Element is a dictionary } elseif ($Type == 'd') { // Element is a dictionary
$this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos)); $this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos));
$this->Pos += $this->Val[$Key]->Pos; $this->Pos += $this->Val[$Key]->Pos;
// Sort by key to respect spec // Sort by key to respect spec
@ -118,12 +118,12 @@ function decode($Type, $Key){
} }
} }
function encode($Val){ function encode($Val) {
if(is_int($Val)) { // Integer if (is_int($Val)) { // Integer
return 'i'.$Val.'e'; return 'i'.$Val.'e';
} elseif(is_string($Val)) { } elseif (is_string($Val)) {
return strlen($Val).':'.$Val; return strlen($Val).':'.$Val;
} elseif(is_object($Val)) { } elseif (is_object($Val)) {
return $Val->enc(); return $Val->enc();
} else { } else {
return 'fail'; return 'fail';
@ -132,7 +132,7 @@ function encode($Val){
} }
class BENCODE_LIST extends BENCODE2 { class BENCODE_LIST extends BENCODE2 {
function enc(){ function enc() {
if (empty($this->Val)) { if (empty($this->Val)) {
return 'le'; return 'le';
} }
@ -145,15 +145,15 @@ function enc(){
} }
// Decode a list // Decode a list
function dec(){ function dec() {
$Key = 0; // Array index $Key = 0; // Array index
$Length = strlen($this->Str); $Length = strlen($this->Str);
while($this->Pos<$Length){ while ($this->Pos < $Length) {
$Type = $this->Str[$this->Pos]; $Type = $this->Str[$this->Pos];
// $Type now indicates what type of element we're dealing with // $Type now indicates what type of element we're dealing with
// It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list) // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
if($Type == 'e') { // End of list if ($Type == 'e') { // End of list
$this->Pos += 1; $this->Pos += 1;
unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster. unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
return; return;
@ -169,7 +169,7 @@ function dec(){
} }
class BENCODE_DICT extends BENCODE2 { class BENCODE_DICT extends BENCODE2 {
function enc(){ function enc() {
if (empty($this->Val)) { if (empty($this->Val)) {
return 'de'; return 'de';
} }
@ -182,11 +182,11 @@ function enc(){
} }
// Decode a dictionary // Decode a dictionary
function dec(){ function dec() {
$Length = strlen($this->Str); $Length = strlen($this->Str);
while($this->Pos<$Length) { while ($this->Pos<$Length) {
if($this->Str[$this->Pos] == 'e') { // End of dictionary if ($this->Str[$this->Pos] == 'e') { // End of dictionary
$this->Pos += 1; $this->Pos += 1;
unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster. unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
return; return;
@ -197,19 +197,19 @@ function dec(){
$KeyLen = $this->Str[$this->Pos]; $KeyLen = $this->Str[$this->Pos];
// Allow for multi-digit lengths // Allow for multi-digit lengths
while($this->Str[$this->Pos+1]!=':' && $this->Pos+1<$Length) { while ($this->Str[$this->Pos + 1] != ':' && $this->Pos + 1 < $Length) {
$this->Pos++; $this->Pos++;
$KeyLen.=$this->Str[$this->Pos]; $KeyLen.=$this->Str[$this->Pos];
} }
// $this->Pos is now on the last letter of the key length // $this->Pos is now on the last letter of the key length
// Adding 2 brings it past that character and the ':' to the beginning of the string // Adding 2 brings it past that character and the ':' to the beginning of the string
$this->Pos+=2; $this->Pos += 2;
// Get the name of the key // Get the name of the key
$Key = substr($this->Str, $this->Pos, $KeyLen); $Key = substr($this->Str, $this->Pos, $KeyLen);
// Move the position past the key to the beginning of the element // Move the position past the key to the beginning of the element
$this->Pos+=$KeyLen; $this->Pos += $KeyLen;
$Type = $this->Str[$this->Pos]; $Type = $this->Str[$this->Pos];
// $Type now indicates what type of element we're dealing with // $Type now indicates what type of element we're dealing with
// It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list) // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)

View File

@ -77,8 +77,8 @@ class BENCODE2 {
var $Pos = 1; // Pointer that indicates our position in the string var $Pos = 1; // Pointer that indicates our position in the string
var $Str = ''; // Torrent string var $Str = ''; // Torrent string
function __construct($Val, $IsParsed = false){ function __construct($Val, $IsParsed = false) {
if(!$IsParsed) { if (!$IsParsed) {
$this->Str = $Val; $this->Str = $Val;
$this->dec(); $this->dec();
} else { } else {
@ -87,20 +87,20 @@ function __construct($Val, $IsParsed = false){
} }
// Decode an element based on the type // Decode an element based on the type
function decode($Type, $Key){ function decode($Type, $Key) {
if(ctype_digit($Type)) { // Element is a string if (ctype_digit($Type)) { // Element is a string
// Get length of string // Get length of string
$StrLen = $Type; $StrLen = $Type;
while($this->Str[$this->Pos+1]!=':'){ while ($this->Str[$this->Pos + 1] != ':') {
$this->Pos++; $this->Pos++;
$StrLen.=$this->Str[$this->Pos]; $StrLen.=$this->Str[$this->Pos];
} }
$this->Val[$Key] = substr($this->Str, $this->Pos+2, $StrLen); $this->Val[$Key] = substr($this->Str, $this->Pos + 2, $StrLen);
$this->Pos+=$StrLen; $this->Pos += $StrLen;
$this->Pos+=2; $this->Pos += 2;
} elseif($Type == 'i') { // Element is an int } elseif ($Type == 'i') { // Element is an int
$this->Pos++; $this->Pos++;
// Find end of integer (first occurance of 'e' after position) // Find end of integer (first occurance of 'e' after position)
@ -108,13 +108,13 @@ function decode($Type, $Key){
// Get the integer, and mark it as an int (on our version 64 bit box, we cast it to an int) // Get the integer, and mark it as an int (on our version 64 bit box, we cast it to an int)
$this->Val[$Key] = '[*INT*]'.substr($this->Str, $this->Pos, $End-$this->Pos); $this->Val[$Key] = '[*INT*]'.substr($this->Str, $this->Pos, $End-$this->Pos);
$this->Pos = $End+1; $this->Pos = $End + 1;
} elseif($Type == 'l') { // Element is a list } elseif ($Type == 'l') { // Element is a list
$this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos)); $this->Val[$Key] = new BENCODE_LIST(substr($this->Str, $this->Pos));
$this->Pos += $this->Val[$Key]->Pos; $this->Pos += $this->Val[$Key]->Pos;
} elseif($Type == 'd') { // Element is a dictionary } elseif ($Type == 'd') { // Element is a dictionary
$this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos)); $this->Val[$Key] = new BENCODE_DICT(substr($this->Str, $this->Pos));
$this->Pos += $this->Val[$Key]->Pos; $this->Pos += $this->Val[$Key]->Pos;
// Sort by key to respect spec // Sort by key to respect spec
@ -125,14 +125,14 @@ function decode($Type, $Key){
} }
} }
function encode($Val){ function encode($Val) {
if(is_string($Val)) { if (is_string($Val)) {
if(substr($Val, 0, 7) == '[*INT*]') { if (substr($Val, 0, 7) == '[*INT*]') {
return 'i'.substr($Val,7).'e'; return 'i'.substr($Val,7).'e';
} else { } else {
return strlen($Val).':'.$Val; return strlen($Val).':'.$Val;
} }
} elseif(is_object($Val)) { } elseif (is_object($Val)) {
return $Val->enc(); return $Val->enc();
} else { } else {
return 'fail'; return 'fail';
@ -141,25 +141,25 @@ function encode($Val){
} }
class BENCODE_LIST extends BENCODE2 { class BENCODE_LIST extends BENCODE2 {
function enc(){ function enc() {
$Str = 'l'; $Str = 'l';
reset($this->Val); reset($this->Val);
while(list($Key, $Value) = each($this->Val)) { while (list($Key, $Value) = each($this->Val)) {
$Str.=$this->encode($Value); $Str.=$this->encode($Value);
} }
return $Str.'e'; return $Str.'e';
} }
// Decode a list // Decode a list
function dec(){ function dec() {
$Key = 0; // Array index $Key = 0; // Array index
$Length = strlen($this->Str); $Length = strlen($this->Str);
while($this->Pos<$Length){ while ($this->Pos<$Length) {
$Type = $this->Str[$this->Pos]; $Type = $this->Str[$this->Pos];
// $Type now indicates what type of element we're dealing with // $Type now indicates what type of element we're dealing with
// It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list) // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)
if($Type == 'e') { // End of list if ($Type == 'e') { // End of list
$this->Pos += 1; $this->Pos += 1;
unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster. unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
return; return;
@ -175,21 +175,21 @@ function dec(){
} }
class BENCODE_DICT extends BENCODE2 { class BENCODE_DICT extends BENCODE2 {
function enc(){ function enc() {
$Str = 'd'; $Str = 'd';
reset($this->Val); reset($this->Val);
while(list($Key, $Value) = each($this->Val)) { while (list($Key, $Value) = each($this->Val)) {
$Str.=strlen($Key).':'.$Key.$this->encode($Value); $Str.=strlen($Key).':'.$Key.$this->encode($Value);
} }
return $Str.'e'; return $Str.'e';
} }
// Decode a dictionary // Decode a dictionary
function dec(){ function dec() {
$Length = strlen($this->Str); $Length = strlen($this->Str);
while($this->Pos<$Length) { while ($this->Pos < $Length) {
if($this->Str[$this->Pos] == 'e') { // End of dictionary if ($this->Str[$this->Pos] == 'e') { // End of dictionary
$this->Pos += 1; $this->Pos += 1;
unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster. unset($this->Str); // Since we're finished parsing the string, we don't need to store it anymore. Benchmarked - this makes the parser run way faster.
return; return;
@ -200,7 +200,7 @@ function dec(){
$KeyLen = $this->Str[$this->Pos]; $KeyLen = $this->Str[$this->Pos];
// Allow for multi-digit lengths // Allow for multi-digit lengths
while($this->Str[$this->Pos+1]!=':' && $this->Pos+1<$Length) { while ($this->Str[$this->Pos + 1] != ':' && $this->Pos + 1 < $Length) {
$this->Pos++; $this->Pos++;
$KeyLen.=$this->Str[$this->Pos]; $KeyLen.=$this->Str[$this->Pos];
} }
@ -212,7 +212,7 @@ function dec(){
$Key = substr($this->Str, $this->Pos, $KeyLen); $Key = substr($this->Str, $this->Pos, $KeyLen);
// Move the position past the key to the beginning of the element // Move the position past the key to the beginning of the element
$this->Pos+=$KeyLen; $this->Pos += $KeyLen;
$Type = $this->Str[$this->Pos]; $Type = $this->Str[$this->Pos];
// $Type now indicates what type of element we're dealing with // $Type now indicates what type of element we're dealing with
// It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list) // It's either an integer (string), 'i' (an integer), 'l' (a list), 'd' (a dictionary), or 'e' (end of dictionary/list)

View File

@ -258,7 +258,7 @@ function music_form($GenreTags) {
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
hide(); hide();
if (document.getElementById("categories").disabled == false){ if (document.getElementById("categories").disabled == false) {
if (navigator.appName == 'Opera') { if (navigator.appName == 'Opera') {
var useragent = navigator.userAgent; var useragent = navigator.userAgent;
var match = useragent.split('Version/'); var match = useragent.split('Version/');
@ -479,7 +479,7 @@ function show() {
<tr> <tr>
<td class="label">Vanity House:</td> <td class="label">Vanity House:</td>
<td> <td>
<label><input type="checkbox" id="vanity_house" name="vanity_house"<? if ($Torrent['GroupID']) { echo ' disabled="disabled"'; } ?><? if ($Torrent['VanityHouse']){ echo ' checked="checked"';} ?> /> <label><input type="checkbox" id="vanity_house" name="vanity_house"<? if ($Torrent['GroupID']) { echo ' disabled="disabled"'; } ?><? if ($Torrent['VanityHouse']) { echo ' checked="checked"';} ?> />
Check this only if you are submitting your own work or submitting on behalf of the artist, and this is intended to be a Vanity House release. Checking this will also automatically add the group as a recommendation. Check this only if you are submitting your own work or submitting on behalf of the artist, and this is intended to be a Vanity House release. Checking this will also automatically add the group as a recommendation.
</label> </label>
</td> </td>
@ -637,7 +637,7 @@ function audiobook_form() {
$Torrent = $this->Torrent; $Torrent = $this->Torrent;
?> ?>
<table cellpadding="3" cellspacing="1" border="0" class="layout border slice" width="100%"> <table cellpadding="3" cellspacing="1" border="0" class="layout border slice" width="100%">
<? if ($this->NewTorrent){ ?> <? if ($this->NewTorrent) { ?>
<tr id="title_tr"> <tr id="title_tr">
<td class="label">Author - Title:</td> <td class="label">Author - Title:</td>
<td> <td>
@ -658,7 +658,9 @@ function audiobook_form() {
<? <?
foreach (Misc::display_array($this->Formats) as $Format) { foreach (Misc::display_array($this->Formats) as $Format) {
echo '<option value="'.$Format.'"'; echo '<option value="'.$Format.'"';
if ($Format == $Torrent['Format']) { echo ' selected="selected"'; } if ($Format == $Torrent['Format']) {
echo ' selected="selected"';
}
echo '>'; echo '>';
echo $Format; echo $Format;
echo "</option>\n"; echo "</option>\n";
@ -675,8 +677,8 @@ function audiobook_form() {
<? <?
if (!$Torrent['Bitrate'] || ($Torrent['Bitrate'] && !in_array($Torrent['Bitrate'], $this->Bitrates))) { if (!$Torrent['Bitrate'] || ($Torrent['Bitrate'] && !in_array($Torrent['Bitrate'], $this->Bitrates))) {
$OtherBitrate = true; $OtherBitrate = true;
if (substr($Torrent['Bitrate'], strlen($Torrent['Bitrate']) - strlen(" (VBR)")) == " (VBR)") { if (substr($Torrent['Bitrate'], strlen($Torrent['Bitrate']) - strlen(' (VBR)')) == ' (VBR)') {
$Torrent['Bitrate'] = substr($Torrent['Bitrate'], 0, strlen($Torrent['Bitrate'])-6); $Torrent['Bitrate'] = substr($Torrent['Bitrate'], 0, strlen($Torrent['Bitrate']) - 6);
$VBR = true; $VBR = true;
} }
} else { } else {
@ -684,7 +686,7 @@ function audiobook_form() {
} }
foreach (Misc::display_array($this->Bitrates) as $Bitrate) { foreach (Misc::display_array($this->Bitrates) as $Bitrate) {
echo '<option value="'.$Bitrate.'"'; echo '<option value="'.$Bitrate.'"';
if ($Bitrate == $Torrent['Bitrate'] || ($OtherBitrate && $Bitrate == "Other")) { if ($Bitrate == $Torrent['Bitrate'] || ($OtherBitrate && $Bitrate == 'Other')) {
echo ' selected="selected"'; echo ' selected="selected"';
} }
echo '>'; echo '>';

View File

@ -61,14 +61,16 @@ function table_query($TableName) {
} }
function get_rank($TableName, $Value) { function get_rank($TableName, $Value) {
if($Value == 0) { return 0; } if ($Value == 0) {
return 0;
}
global $Cache, $DB; global $Cache, $DB;
$Table = $Cache->get_value(PREFIX.$TableName); $Table = $Cache->get_value(PREFIX.$TableName);
if(!$Table) { if (!$Table) {
//Cache lock! //Cache lock!
$Lock = $Cache->get_value(PREFIX.$TableName."_lock"); $Lock = $Cache->get_value(PREFIX.$TableName."_lock");
if($Lock) { if ($Lock) {
return false; return false;
} else { } else {
$Cache->cache_value(PREFIX.$TableName."_lock", '1', 300); $Cache->cache_value(PREFIX.$TableName."_lock", '1', 300);
@ -79,7 +81,7 @@ function get_rank($TableName, $Value) {
$LastPercentile = 0; $LastPercentile = 0;
foreach ($Table as $Row) { foreach ($Table as $Row) {
list($CurValue) = $Row; list($CurValue) = $Row;
if($CurValue>=$Value) { if ($CurValue >= $Value) {
return $LastPercentile; return $LastPercentile;
} }
$LastPercentile++; $LastPercentile++;
@ -87,11 +89,13 @@ function get_rank($TableName, $Value) {
return 100; // 100th percentile return 100; // 100th percentile
} }
function overall_score($Uploaded, $Downloaded, $Uploads, $Requests, $Posts, $Bounty, $Artists, $Ratio){ function overall_score($Uploaded, $Downloaded, $Uploads, $Requests, $Posts, $Bounty, $Artists, $Ratio) {
// We can do this all in 1 line, but it's easier to read this way // We can do this all in 1 line, but it's easier to read this way
if($Ratio>1) { $Ratio = 1; } if ($Ratio > 1) {
$Ratio = 1;
}
$TotalScore = 0; $TotalScore = 0;
if(in_array(false, func_get_args(), true)) { if (in_array(false, func_get_args(), true)) {
return false; return false;
} }
$TotalScore += $Uploaded*15; $TotalScore += $Uploaded*15;

View File

@ -34,13 +34,13 @@ class WIKI {
var $Table = ''; var $Table = '';
var $PageID = 0; var $PageID = 0;
var $BaseURL = ''; var $BaseURL = '';
function WIKI($Table, $PageID, $BaseURL = ''){ function WIKI($Table, $PageID, $BaseURL = '') {
$this->Table = $Table; $this->Table = $Table;
$this->PageID = $PageID; $this->PageID = $PageID;
$this->BaseURL = $BaseURL; $this->BaseURL = $BaseURL;
} }
function revision_history(){ function revision_history() {
global $DB; global $DB;
$BaseURL = $this->BaseURL; $BaseURL = $this->BaseURL;
@ -62,7 +62,7 @@ function revision_history(){
</tr> </tr>
<? //----------------------------------------- <? //-----------------------------------------
$Row = 'a'; $Row = 'a';
while(list($RevisionID, $Summary, $Time, $UserID, $Username) = $DB->next_record()){ while (list($RevisionID, $Summary, $Time, $UserID, $Username) = $DB->next_record()) {
$Row = ($Row == 'a') ? 'b' : 'a'; $Row = ($Row == 'a') ? 'b' : 'a';
//------------------------------------------------------ ?> //------------------------------------------------------ ?>
<tr class="row<?=$Row?>"> <tr class="row<?=$Row?>">

View File

@ -115,7 +115,7 @@
); );
function permissions_form(){ ?> function permissions_form() { ?>
<div class="permissions"> <div class="permissions">
<div class="permission_container"> <div class="permission_container">
<table> <table>

View File

@ -7,15 +7,15 @@
$TorrentForm = new TORRENT_FORM(); $TorrentForm = new TORRENT_FORM();
$GenreTags = $Cache->get_value('genre_tags'); $GenreTags = $Cache->get_value('genre_tags');
if(!$GenreTags){ if (!$GenreTags) {
$DB->query('SELECT Name FROM tags WHERE TagType=\'genre\' ORDER BY Name'); $DB->query('SELECT Name FROM tags WHERE TagType=\'genre\' ORDER BY Name');
$GenreTags = $DB->collect('Name'); $GenreTags = $DB->collect('Name');
$Cache->cache_value('genre_tags', $GenreTags, 3600*24); $Cache->cache_value('genre_tags', $GenreTags, 3600 * 24);
} }
$UploadForm = $Categories[$_GET['categoryid']]; $UploadForm = $Categories[$_GET['categoryid']];
switch($UploadForm) { switch ($UploadForm) {
case 'Music': case 'Music':
$TorrentForm->music_form($GenreTags); $TorrentForm->music_form($GenreTags);
break; break;
@ -32,9 +32,7 @@
$TorrentForm->simple_form($_GET['categoryid']); $TorrentForm->simple_form($_GET['categoryid']);
break; break;
default: default:
echo "Invalid action!"; echo 'Invalid action!';
} }
?> ?>

View File

@ -10,7 +10,7 @@
if (!empty($_REQUEST['action'])) { if (!empty($_REQUEST['action'])) {
switch ($_REQUEST['action']) { switch ($_REQUEST['action']) {
case 'deadthread' : case 'deadthread' :
if (is_number($_GET['id'])){ if (is_number($_GET['id'])) {
$DB->query("UPDATE blog SET ThreadID=NULL WHERE ID=".$_GET['id']); $DB->query("UPDATE blog SET ThreadID=NULL WHERE ID=".$_GET['id']);
$Cache->delete_value('blog'); $Cache->delete_value('blog');
$Cache->delete_value('feed_blog'); $Cache->delete_value('feed_blog');
@ -19,7 +19,7 @@
break; break;
case 'takeeditblog': case 'takeeditblog':
authorize(); authorize();
if (is_number($_POST['blogid']) && is_number($_POST['thread'])){ if (is_number($_POST['blogid']) && is_number($_POST['thread'])) {
$DB->query("UPDATE blog SET Title='".db_string($_POST['title'])."', Body='".db_string($_POST['body'])."', ThreadID=".$_POST['thread']." WHERE ID='".db_string($_POST['blogid'])."'"); $DB->query("UPDATE blog SET Title='".db_string($_POST['title'])."', Body='".db_string($_POST['body'])."', ThreadID=".$_POST['thread']." WHERE ID='".db_string($_POST['blogid'])."'");
$Cache->delete_value('blog'); $Cache->delete_value('blog');
$Cache->delete_value('feed_blog'); $Cache->delete_value('feed_blog');
@ -27,14 +27,14 @@
header('Location: blog.php'); header('Location: blog.php');
break; break;
case 'editblog': case 'editblog':
if (is_number($_GET['id'])){ if (is_number($_GET['id'])) {
$BlogID = $_GET['id']; $BlogID = $_GET['id'];
$DB->query("SELECT Title, Body, ThreadID FROM blog WHERE ID=$BlogID"); $DB->query("SELECT Title, Body, ThreadID FROM blog WHERE ID=$BlogID");
list($Title, $Body, $ThreadID) = $DB->next_record(); list($Title, $Body, $ThreadID) = $DB->next_record();
} }
break; break;
case 'deleteblog': case 'deleteblog':
if (is_number($_GET['id'])){ if (is_number($_GET['id'])) {
authorize(); authorize();
$DB->query("DELETE FROM blog WHERE ID='".db_string($_GET['id'])."'"); $DB->query("DELETE FROM blog WHERE ID='".db_string($_GET['id'])."'");
$Cache->delete_value('blog'); $Cache->delete_value('blog');
@ -91,7 +91,7 @@
<div class="pad"> <div class="pad">
<input type="hidden" name="action" value="<?=((empty($_GET['action'])) ? 'takenewblog' : 'takeeditblog')?>" /> <input type="hidden" name="action" value="<?=((empty($_GET['action'])) ? 'takenewblog' : 'takeeditblog')?>" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" /> <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
<? if (!empty($_GET['action']) && $_GET['action'] == 'editblog'){?> <? if (!empty($_GET['action']) && $_GET['action'] == 'editblog') { ?>
<input type="hidden" name="blogid" value="<?=$BlogID; ?>" /> <input type="hidden" name="blogid" value="<?=$BlogID; ?>" />
<? } ?> <? } ?>
<h3>Title</h3> <h3>Title</h3>

View File

@ -82,7 +82,7 @@
case 'take_warn': case 'take_warn':
require(SERVER_ROOT.'/sections/forums/take_warn.php'); require(SERVER_ROOT.'/sections/forums/take_warn.php');
break; break;
default: default:
error(0); error(0);
} }

View File

@ -19,7 +19,7 @@
$SS->set_filter('visible', array(1)); $SS->set_filter('visible', array(1));
} }
} else { } else {
switch($_GET['type']) { switch ($_GET['type']) {
case 'created': case 'created':
$Title = 'My requests'; $Title = 'My requests';
$SS->set_filter('userid', array($LoggedUser['ID'])); $SS->set_filter('userid', array($LoggedUser['ID']));
@ -27,7 +27,9 @@
case 'voted': case 'voted':
if (!empty($_GET['userid'])) { if (!empty($_GET['userid'])) {
if (is_number($_GET['userid'])) { if (is_number($_GET['userid'])) {
if (!check_paranoia('requestsvoted_list', $UserInfo['Paranoia'], $Perms['Class'], $_GET['userid'])) { error(403); } if (!check_paranoia('requestsvoted_list', $UserInfo['Paranoia'], $Perms['Class'], $_GET['userid'])) {
error(403);
}
$Title = "Requests voted for by ".$UserInfo['Username']; $Title = "Requests voted for by ".$UserInfo['Username'];
$SS->set_filter('voter', array($_GET['userid'])); $SS->set_filter('voter', array($_GET['userid']));
} else { } else {
@ -42,7 +44,9 @@
if (empty($_GET['userid']) || !is_number($_GET['userid'])) { if (empty($_GET['userid']) || !is_number($_GET['userid'])) {
error(404); error(404);
} else { } else {
if (!check_paranoia('requestsfilled_list', $UserInfo['Paranoia'], $Perms['Class'], $_GET['userid'])) { error(403); } if (!check_paranoia('requestsfilled_list', $UserInfo['Paranoia'], $Perms['Class'], $_GET['userid'])) {
error(403);
}
$Title = "Requests filled by ".$UserInfo['Username']; $Title = "Requests filled by ".$UserInfo['Username'];
$SS->set_filter('fillerid', array($_GET['userid'])); $SS->set_filter('fillerid', array($_GET['userid']));
} }
@ -167,7 +171,7 @@
} }
} }
if (!empty($_GET['tags'])){ if (!empty($_GET['tags'])) {
$Tags = explode(',', $_GET['tags']); $Tags = explode(',', $_GET['tags']);
$TagNames = array(); $TagNames = array();
if (!isset($_GET['tags_type']) || $_GET['tags_type'] == 1) { if (!isset($_GET['tags_type']) || $_GET['tags_type'] == 1) {
@ -384,7 +388,7 @@
<input type="checkbox" name="show_filled"<? if (!$Submitted || !empty($_GET['show_filled']) || (!$Submitted && !empty($_GET['type']) && $_GET['type'] == 'filled')) { ?> checked="checked"<? } ?> /> <input type="checkbox" name="show_filled"<? if (!$Submitted || !empty($_GET['show_filled']) || (!$Submitted && !empty($_GET['type']) && $_GET['type'] == 'filled')) { ?> checked="checked"<? } ?> />
</td> </td>
</tr> </tr>
<? if (check_perms('site_see_old_requests')){ ?> <? if (check_perms('site_see_old_requests')) { ?>
<tr id="include_old"> <tr id="include_old">
<td class="label">Include old:</td> <td class="label">Include old:</td>
<td> <td>

View File

@ -1,7 +1,7 @@
<? <?
enforce_login(); enforce_login();
if(!check_perms('site_top10')){ if (!check_perms('site_top10')) {
View::show_header(); View::show_header();
?> ?>
<div class="content_basiccontainer"> <div class="content_basiccontainer">
@ -13,7 +13,7 @@
} }
include(SERVER_ROOT.'/sections/torrents/functions.php'); //Has get_reports($TorrentID); include(SERVER_ROOT.'/sections/torrents/functions.php'); //Has get_reports($TorrentID);
if(empty($_GET['type']) || $_GET['type'] == 'torrents') { if (empty($_GET['type']) || $_GET['type'] == 'torrents') {
include(SERVER_ROOT.'/sections/top10/torrents.php'); include(SERVER_ROOT.'/sections/top10/torrents.php');
} else { } else {
switch($_GET['type']) { switch($_GET['type']) {

View File

@ -350,25 +350,25 @@ function generate_torrent_table($Caption, $Tag, $Details, $Limit) {
global $LoggedUser,$Categories,$ReleaseTypes; global $LoggedUser,$Categories,$ReleaseTypes;
?> ?>
<h3>Top <?=$Limit.' '.$Caption?> <h3>Top <?=$Limit.' '.$Caption?>
<? if (empty($_GET['advanced'])){ ?> <? if (empty($_GET['advanced'])) { ?>
<small class="top10_quantity_links"> <small class="top10_quantity_links">
<? <?
switch($Limit) { switch ($Limit) {
case 100: ?> case 100: ?>
- <a href="top10.php?details=<?=$Tag?>" class="brackets">Top 10</a> - <a href="top10.php?details=<?=$Tag?>" class="brackets">Top 10</a>
- <span class="brackets">Top 100</span> - <span class="brackets">Top 100</span>
- <a href="top10.php?type=torrents&amp;limit=250&amp;details=<?=$Tag?>" class="brackets">Top 250</a> - <a href="top10.php?type=torrents&amp;limit=250&amp;details=<?=$Tag?>" class="brackets">Top 250</a>
<? break; <? break;
case 250: ?> case 250: ?>
- <a href="top10.php?details=<?=$Tag?>" class="brackets">Top 10</a> - <a href="top10.php?details=<?=$Tag?>" class="brackets">Top 10</a>
- <a href="top10.php?type=torrents&amp;limit=100&amp;details=<?=$Tag?>" class="brackets">Top 100</a> - <a href="top10.php?type=torrents&amp;limit=100&amp;details=<?=$Tag?>" class="brackets">Top 100</a>
- <span class="brackets">Top 250</span> - <span class="brackets">Top 250</span>
<? break; <? break;
default: ?> default: ?>
- <span class="brackets">Top 10</span> - <span class="brackets">Top 10</span>
- <a href="top10.php?type=torrents&amp;limit=100&amp;details=<?=$Tag?>" class="brackets">Top 100</a> - <a href="top10.php?type=torrents&amp;limit=100&amp;details=<?=$Tag?>" class="brackets">Top 100</a>
- <a href="top10.php?type=torrents&amp;limit=250&amp;details=<?=$Tag?>" class="brackets">Top 250</a> - <a href="top10.php?type=torrents&amp;limit=250&amp;details=<?=$Tag?>" class="brackets">Top 250</a>
<? } ?> <? } ?>
</small> </small>
<? } ?> <? } ?>
</h3> </h3>
@ -402,7 +402,7 @@ function generate_torrent_table($Caption, $Tag, $Details, $Limit) {
?> ?>
<tr class="rowb"> <tr class="rowb">
<td colspan="9" class="center"> <td colspan="9" class="center">
Found no torrents matching the criteria Found no torrents matching the criteria.
</td> </td>
</tr> </tr>
</table><br /> </table><br />
@ -449,11 +449,11 @@ function generate_torrent_table($Caption, $Tag, $Details, $Limit) {
$AddExtra = ''; $AddExtra = '';
if ($Format) { if ($Format) {
$ExtraInfo.=$Format; $ExtraInfo.=$Format;
$AddExtra=' / '; $AddExtra = ' / ';
} }
if ($Encoding) { if ($Encoding) {
$ExtraInfo.=$AddExtra.$Encoding; $ExtraInfo.=$AddExtra.$Encoding;
$AddExtra=' / '; $AddExtra = ' / ';
} }
// "FLAC / Lossless / Log (100%) / Cue / CD"; // "FLAC / Lossless / Log (100%) / Cue / CD";
if ($HasLog) { if ($HasLog) {

View File

@ -277,11 +277,11 @@
<? } ?> <? } ?>
| <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" title="Report">RP</a> ] | <a href="reportsv2.php?action=report&amp;id=<?=$TorrentID?>" title="Report">RP</a> ]
</span> </span>
&nbsp;&nbsp;&raquo;&nbsp; <a href="torrents.php?id=<?=$GroupID?>&amp;torrentid=<?=$TorrentID?>"><?=Torrents::torrent_info($Torrent)?><?if($Reported){?> / <strong class="torrent_label tl_reported" title="Reported">Reported</strong><?}?></a> &nbsp;&nbsp;&raquo;&nbsp; <a href="torrents.php?id=<?=$GroupID?>&amp;torrentid=<?=$TorrentID?>"><?=Torrents::torrent_info($Torrent)?><? if ($Reported) { ?> / <strong class="torrent_label tl_reported" title="Reported">Reported</strong><? } ?></a>
</td> </td>
<td class="nobr"><?=Format::get_size($Torrent['Size'])?></td> <td class="nobr"><?=Format::get_size($Torrent['Size'])?></td>
<td><?=number_format($Torrent['Snatched'])?></td> <td><?=number_format($Torrent['Snatched'])?></td>
<td<?=($Torrent['Seeders']==0)?' class="r00"':''?>><?=number_format($Torrent['Seeders'])?></td> <td<?=($Torrent['Seeders'] == 0) ? ' class="r00"' : '' ?>><?=number_format($Torrent['Seeders'])?></td>
<td><?=number_format($Torrent['Leechers'])?></td> <td><?=number_format($Torrent['Leechers'])?></td>
</tr> </tr>
<? <?
@ -337,7 +337,7 @@
</td> </td>
<td class="nobr"><?=Format::get_size($Torrent['Size'])?></td> <td class="nobr"><?=Format::get_size($Torrent['Size'])?></td>
<td><?=number_format($Torrent['Snatched'])?></td> <td><?=number_format($Torrent['Snatched'])?></td>
<td<?=($Torrent['Seeders']==0)?' class="r00"':''?>><?=number_format($Torrent['Seeders'])?></td> <td<?=($Torrent['Seeders'] == 0) ? ' class="r00"' : '' ?>><?=number_format($Torrent['Seeders'])?></td>
<td><?=number_format($Torrent['Leechers'])?></td> <td><?=number_format($Torrent['Leechers'])?></td>
</tr> </tr>
<? <?

View File

@ -32,23 +32,23 @@ function get_group_info($GroupID, $Return = true, $RevisionID = 0, $PersonalProp
} }
$SQL .= " $SQL .= "
g.ID, g.ID,
g.Name, g.Name,
g.Year, g.Year,
g.RecordLabel, g.RecordLabel,
g.CatalogueNumber, g.CatalogueNumber,
g.ReleaseType, g.ReleaseType,
g.CategoryID, g.CategoryID,
g.Time, g.Time,
g.VanityHouse, g.VanityHouse,
GROUP_CONCAT(DISTINCT tags.Name SEPARATOR '|'), GROUP_CONCAT(DISTINCT tags.Name SEPARATOR '|'),
GROUP_CONCAT(DISTINCT tags.ID SEPARATOR '|'), GROUP_CONCAT(DISTINCT tags.ID SEPARATOR '|'),
GROUP_CONCAT(tt.UserID SEPARATOR '|'), GROUP_CONCAT(tt.UserID SEPARATOR '|'),
GROUP_CONCAT(tt.PositiveVotes SEPARATOR '|'), GROUP_CONCAT(tt.PositiveVotes SEPARATOR '|'),
GROUP_CONCAT(tt.NegativeVotes SEPARATOR '|') GROUP_CONCAT(tt.NegativeVotes SEPARATOR '|')
FROM torrents_group AS g FROM torrents_group AS g
LEFT JOIN torrents_tags AS tt ON tt.GroupID=g.ID LEFT JOIN torrents_tags AS tt ON tt.GroupID=g.ID
LEFT JOIN tags ON tags.ID=tt.TagID"; LEFT JOIN tags ON tags.ID=tt.TagID";
if ($RevisionID) { if ($RevisionID) {
$SQL .= " $SQL .= "
@ -66,52 +66,61 @@ function get_group_info($GroupID, $Return = true, $RevisionID = 0, $PersonalProp
$DB->query(" $DB->query("
SELECT SELECT
t.ID, t.ID,
t.Media, t.Media,
t.Format, t.Format,
t.Encoding, t.Encoding,
t.Remastered, t.Remastered,
t.RemasterYear, t.RemasterYear,
t.RemasterTitle, t.RemasterTitle,
t.RemasterRecordLabel, t.RemasterRecordLabel,
t.RemasterCatalogueNumber, t.RemasterCatalogueNumber,
t.Scene, t.Scene,
t.HasLog, t.HasLog,
t.HasCue, t.HasCue,
t.LogScore, t.LogScore,
t.FileCount, t.FileCount,
t.Size, t.Size,
t.Seeders, t.Seeders,
t.Leechers, t.Leechers,
t.Snatched, t.Snatched,
t.FreeTorrent, t.FreeTorrent,
t.Time, t.Time,
t.Description, t.Description,
t.FileList, t.FileList,
t.FilePath, t.FilePath,
t.UserID, t.UserID,
t.last_action, t.last_action,
HEX(t.info_hash) AS InfoHash, HEX(t.info_hash) AS InfoHash,
tbt.TorrentID AS BadTags, tbt.TorrentID AS BadTags,
tbf.TorrentID AS BadFolders, tbf.TorrentID AS BadFolders,
tfi.TorrentID AS BadFiles, tfi.TorrentID AS BadFiles,
ca.TorrentID AS CassetteApproved, ca.TorrentID AS CassetteApproved,
lma.TorrentID AS LossymasterApproved, lma.TorrentID AS LossymasterApproved,
lwa.TorrentID AS LossywebApproved, lwa.TorrentID AS LossywebApproved,
t.LastReseedRequest, t.LastReseedRequest,
tln.TorrentID AS LogInDB, tln.TorrentID AS LogInDB,
t.ID AS HasFile t.ID AS HasFile
FROM torrents AS t FROM torrents AS t
LEFT JOIN torrents_bad_tags AS tbt ON tbt.TorrentID=t.ID LEFT JOIN torrents_bad_tags AS tbt ON tbt.TorrentID=t.ID
LEFT JOIN torrents_bad_folders AS tbf on tbf.TorrentID=t.ID LEFT JOIN torrents_bad_folders AS tbf on tbf.TorrentID=t.ID
LEFT JOIN torrents_bad_files AS tfi on tfi.TorrentID=t.ID LEFT JOIN torrents_bad_files AS tfi on tfi.TorrentID=t.ID
LEFT JOIN torrents_cassette_approved AS ca on ca.TorrentID=t.ID LEFT JOIN torrents_cassette_approved AS ca on ca.TorrentID=t.ID
LEFT JOIN torrents_lossymaster_approved AS lma on lma.TorrentID=t.ID LEFT JOIN torrents_lossymaster_approved AS lma on lma.TorrentID=t.ID
LEFT JOIN torrents_lossyweb_approved AS lwa on lwa.TorrentID=t.ID LEFT JOIN torrents_lossyweb_approved AS lwa on lwa.TorrentID=t.ID
LEFT JOIN torrents_logs_new AS tln ON tln.TorrentID=t.ID LEFT JOIN torrents_logs_new AS tln ON tln.TorrentID=t.ID
WHERE t.GroupID='".db_string($GroupID)."' WHERE t.GroupID='".db_string($GroupID)."'
GROUP BY t.ID GROUP BY t.ID
ORDER BY t.Remastered ASC, (t.RemasterYear <> 0) DESC, t.RemasterYear ASC, t.RemasterTitle ASC, t.RemasterRecordLabel ASC, t.RemasterCatalogueNumber ASC, t.Media ASC, t.Format, t.Encoding, t.ID"); ORDER BY t.Remastered ASC,
(t.RemasterYear <> 0) DESC,
t.RemasterYear ASC,
t.RemasterTitle ASC,
t.RemasterRecordLabel ASC,
t.RemasterCatalogueNumber ASC,
t.Media ASC,
t.Format,
t.Encoding,
t.ID");
$TorrentList = $DB->to_array('ID', MYSQLI_ASSOC); $TorrentList = $DB->to_array('ID', MYSQLI_ASSOC);
if (count($TorrentList) == 0) { if (count($TorrentList) == 0) {
@ -182,15 +191,17 @@ function get_reports($TorrentID){
global $Cache, $DB; global $Cache, $DB;
$Reports = $Cache->get_value('reports_torrent_' . $TorrentID); $Reports = $Cache->get_value('reports_torrent_' . $TorrentID);
if ($Reports === false) { if ($Reports === false) {
$DB->query("SELECT r.ID, $DB->query("
SELECT
r.ID,
r.ReporterID, r.ReporterID,
r.Type, r.Type,
r.UserComment, r.UserComment,
r.ReportedTime r.ReportedTime
FROM reportsv2 AS r FROM reportsv2 AS r
WHERE TorrentID = $TorrentID WHERE TorrentID = $TorrentID
AND Type != 'edited' AND Type != 'edited'
AND Status != 'Resolved'"); AND Status != 'Resolved'");
$Reports = $DB->to_array(); $Reports = $DB->to_array();
$Cache->cache_value('reports_torrent_' . $TorrentID, $Reports, 0); $Cache->cache_value('reports_torrent_' . $TorrentID, $Reports, 0);
} }
@ -234,7 +245,9 @@ function filelist($Str) {
unset($ReportedTimes); unset($ReportedTimes);
$Reports = $Cache->get_value('reports_torrent_' . $TorrentID); $Reports = $Cache->get_value('reports_torrent_' . $TorrentID);
if ($Reports === false) { if ($Reports === false) {
$DB->query("SELECT r.ID, $DB->query("
SELECT
r.ID,
r.ReporterID, r.ReporterID,
r.Type, r.Type,
r.UserComment, r.UserComment,
@ -249,7 +262,7 @@ function filelist($Str) {
if (count($Reports) > 0) { if (count($Reports) > 0) {
$Reported = true; $Reported = true;
include(SERVER_ROOT . '/sections/reportsv2/array.php'); include(SERVER_ROOT . '/sections/reportsv2/array.php');
$ReportInfo = '<table><tr class="colhead_dark" style="font-weight: bold;"><td>This torrent has ' . count($Reports) . ' active ' . (count($Reports) > 1 ? "reports" : "report") . ':</td></tr>'; $ReportInfo = '<table><tr class="colhead_dark" style="font-weight: bold;"><td>This torrent has ' . count($Reports) . ' active ' . (count($Reports) > 1 ? 'reports' : 'report') . ':</td></tr>';
foreach ($Reports as $Report) { foreach ($Reports as $Report) {
list($ReportID, $ReporterID, $ReportType, $ReportReason, $ReportedTime) = $Report; list($ReportID, $ReporterID, $ReportType, $ReportReason, $ReportedTime) = $Report;
@ -466,8 +479,7 @@ function filelist($Str) {
<? } <? }
if (!empty($Description)) { if (!empty($Description)) {
echo '<blockquote>' . $Text->full_format($Description) . '</blockquote>'; echo '<blockquote>' . $Text->full_format($Description) . '</blockquote>';
} } ?>
?>
</td> </td>
</tr> </tr>
<? <?

View File

@ -2,13 +2,13 @@
//Function used for pagination of peer/snatch/download lists on details.php //Function used for pagination of peer/snatch/download lists on details.php
function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) { function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
$NumPages = ceil($NumResults/100); $NumPages = ceil($NumResults / 100);
$PageLinks = array(); $PageLinks = array();
for($i = 1; $i<=$NumPages; $i++) { for ($i = 1; $i <= $NumPages; $i++) {
if($i == $CurrentPage) { if ($i == $CurrentPage) {
$PageLinks[]=$i; $PageLinks[] = $i;
} else { } else {
$PageLinks[]='<a href="#" onclick="'.$Action.'('.$TorrentID.', '.$i.')">'.$i.'</a>'; $PageLinks[] = '<a href="#" onclick="'.$Action.'('.$TorrentID.', '.$i.')">'.$i.'</a>';
} }
} }
return implode(' | ',$PageLinks); return implode(' | ',$PageLinks);
@ -17,8 +17,8 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
// This gets used in a few places // This gets used in a few places
$ArtistTypes = array(1 => 'Main', 2 => 'Guest', 3 => 'Remixer', 4 => 'Composer', 5 => 'Conductor', 6 => 'DJ/Compiler', 7 => 'Producer'); $ArtistTypes = array(1 => 'Main', 2 => 'Guest', 3 => 'Remixer', 4 => 'Composer', 5 => 'Conductor', 6 => 'DJ/Compiler', 7 => 'Producer');
if(!empty($_REQUEST['action'])) { if (!empty($_REQUEST['action'])) {
switch($_REQUEST['action']){ switch ($_REQUEST['action']) {
case 'edit': case 'edit':
enforce_login(); enforce_login();
include(SERVER_ROOT.'/sections/torrents/edit.php'); include(SERVER_ROOT.'/sections/torrents/edit.php');
@ -53,7 +53,7 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
enforce_login(); enforce_login();
include(SERVER_ROOT.'/sections/torrents/peerlist.php'); include(SERVER_ROOT.'/sections/torrents/peerlist.php');
break; break;
case 'snatchlist': case 'snatchlist':
enforce_login(); enforce_login();
include(SERVER_ROOT.'/sections/torrents/snatchlist.php'); include(SERVER_ROOT.'/sections/torrents/snatchlist.php');
@ -101,7 +101,6 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
include(SERVER_ROOT.'/sections/torrents/delete_alias.php'); include(SERVER_ROOT.'/sections/torrents/delete_alias.php');
break; break;
case 'history': case 'history':
enforce_login(); enforce_login();
include(SERVER_ROOT.'/sections/torrents/history.php'); include(SERVER_ROOT.'/sections/torrents/history.php');
@ -180,15 +179,17 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
enforce_login(); enforce_login();
authorize(); authorize();
if (!isset($_POST['groupid']) || !is_number($_POST['groupid']) || trim($_POST['body'])==='' || !isset($_POST['body'])) { if (!isset($_POST['groupid']) || !is_number($_POST['groupid']) || trim($_POST['body']) === '' || !isset($_POST['body'])) {
error(0); error(0);
} }
if($LoggedUser['DisablePosting']) { if ($LoggedUser['DisablePosting']) {
error('Your posting rights have been removed.'); error('Your posting rights have been removed.');
} }
$GroupID = $_POST['groupid']; $GroupID = $_POST['groupid'];
if(!$GroupID) { error(404); } if (!$GroupID) {
error(404);
}
$DB->query("SELECT CEIL((SELECT COUNT(ID)+1 FROM torrents_comments AS tc WHERE tc.GroupID='".db_string($GroupID)."')/".TORRENT_COMMENTS_PER_PAGE.") AS Pages"); $DB->query("SELECT CEIL((SELECT COUNT(ID)+1 FROM torrents_comments AS tc WHERE tc.GroupID='".db_string($GroupID)."')/".TORRENT_COMMENTS_PER_PAGE.") AS Pages");
list($Pages) = $DB->next_record(); list($Pages) = $DB->next_record();
@ -197,7 +198,7 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
'".db_string($GroupID)."', '".db_string($LoggedUser['ID'])."','".sqltime()."','".db_string($_POST['body'])."')"); '".db_string($GroupID)."', '".db_string($LoggedUser['ID'])."','".sqltime()."','".db_string($_POST['body'])."')");
$PostID=$DB->inserted_id(); $PostID=$DB->inserted_id();
$CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE*$Pages-TORRENT_COMMENTS_PER_PAGE)/THREAD_CATALOGUE); $CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $Pages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
$Cache->begin_transaction('torrent_comments_'.$GroupID.'_catalogue_'.$CatalogueID); $Cache->begin_transaction('torrent_comments_'.$GroupID.'_catalogue_'.$CatalogueID);
$Post = array( $Post = array(
'ID'=>$PostID, 'ID'=>$PostID,
@ -217,7 +218,9 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
case 'get_post': case 'get_post':
enforce_login(); enforce_login();
if (!$_GET['post'] || !is_number($_GET['post'])) { error(0); } if (!$_GET['post'] || !is_number($_GET['post'])) {
error(0);
}
$DB->query("SELECT Body FROM torrents_comments WHERE ID='".db_string($_GET['post'])."'"); $DB->query("SELECT Body FROM torrents_comments WHERE ID='".db_string($_GET['post'])."'");
list($Body) = $DB->next_record(MYSQLI_NUM); list($Body) = $DB->next_record(MYSQLI_NUM);
@ -232,7 +235,9 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
$Text = new TEXT; $Text = new TEXT;
// Quick SQL injection check // Quick SQL injection check
if(!$_POST['post'] || !is_number($_POST['post'])) { error(0); } if (!$_POST['post'] || !is_number($_POST['post'])) {
error(0);
}
// Mainly // Mainly
$DB->query("SELECT $DB->query("SELECT
@ -247,8 +252,12 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
$DB->query("SELECT ceil(COUNT(ID) / ".TORRENT_COMMENTS_PER_PAGE.") AS Page FROM torrents_comments WHERE GroupID = $GroupID AND ID <= $_POST[post]"); $DB->query("SELECT ceil(COUNT(ID) / ".TORRENT_COMMENTS_PER_PAGE.") AS Page FROM torrents_comments WHERE GroupID = $GroupID AND ID <= $_POST[post]");
list($Page) = $DB->next_record(); list($Page) = $DB->next_record();
if ($LoggedUser['ID']!=$AuthorID && !check_perms('site_moderate_forums')) { error(404); } if ($LoggedUser['ID'] != $AuthorID && !check_perms('site_moderate_forums')) {
if ($DB->record_count()==0) { error(404); } error(404);
}
if ($DB->record_count() == 0) {
error(404);
}
// Perform the update // Perform the update
$DB->query("UPDATE torrents_comments SET $DB->query("UPDATE torrents_comments SET
@ -258,7 +267,7 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
WHERE ID='".db_string($_POST['post'])."'"); WHERE ID='".db_string($_POST['post'])."'");
// Update the cache // Update the cache
$CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE*$Page-TORRENT_COMMENTS_PER_PAGE)/THREAD_CATALOGUE); $CatalogueID = floor((TORRENT_COMMENTS_PER_PAGE * $Page - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
$Cache->begin_transaction('torrent_comments_'.$GroupID.'_catalogue_'.$CatalogueID); $Cache->begin_transaction('torrent_comments_'.$GroupID.'_catalogue_'.$CatalogueID);
$Cache->update_row($_POST['key'], array( $Cache->update_row($_POST['key'], array(
@ -284,10 +293,14 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
authorize(); authorize();
// Quick SQL injection check // Quick SQL injection check
if (!$_GET['postid'] || !is_number($_GET['postid'])) { error(0); } if (!$_GET['postid'] || !is_number($_GET['postid'])) {
error(0);
}
// Make sure they are moderators // Make sure they are moderators
if (!check_perms('site_moderate_forums')) { error(403); } if (!check_perms('site_moderate_forums')) {
error(403);
}
// Get topicid, forumid, number of pages // Get topicid, forumid, number of pages
$DB->query("SELECT $DB->query("SELECT
@ -297,7 +310,7 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
FROM torrents_comments AS tc FROM torrents_comments AS tc
WHERE tc.GroupID=(SELECT GroupID FROM torrents_comments WHERE ID=".$_GET['postid'].") WHERE tc.GroupID=(SELECT GroupID FROM torrents_comments WHERE ID=".$_GET['postid'].")
GROUP BY tc.GroupID"); GROUP BY tc.GroupID");
list($GroupID,$Pages,$Page)=$DB->next_record(); list($GroupID, $Pages, $Page) = $DB->next_record();
// $Pages = number of pages in the thread // $Pages = number of pages in the thread
// $Page = which page the post is on // $Page = which page the post is on
@ -306,9 +319,9 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
$DB->query("DELETE FROM torrents_comments WHERE ID='".db_string($_GET['postid'])."'"); $DB->query("DELETE FROM torrents_comments WHERE ID='".db_string($_GET['postid'])."'");
//We need to clear all subsequential catalogues as they've all been bumped with the absence of this post //We need to clear all subsequential catalogues as they've all been bumped with the absence of this post
$ThisCatalogue = floor((TORRENT_COMMENTS_PER_PAGE*$Page-TORRENT_COMMENTS_PER_PAGE)/THREAD_CATALOGUE); $ThisCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $Page - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
$LastCatalogue = floor((TORRENT_COMMENTS_PER_PAGE*$Pages-TORRENT_COMMENTS_PER_PAGE)/THREAD_CATALOGUE); $LastCatalogue = floor((TORRENT_COMMENTS_PER_PAGE * $Pages - TORRENT_COMMENTS_PER_PAGE) / THREAD_CATALOGUE);
for($i=$ThisCatalogue;$i<=$LastCatalogue;$i++) { for ($i = $ThisCatalogue; $i <= $LastCatalogue; $i++) {
$Cache->delete('torrent_comments_'.$GroupID.'_catalogue_'.$i); $Cache->delete('torrent_comments_'.$GroupID.'_catalogue_'.$i);
} }
@ -317,7 +330,7 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
break; break;
case 'regen_filelist' : case 'regen_filelist' :
if(check_perms('users_mod') && !empty($_GET['torrentid']) && is_number($_GET['torrentid'])) { if (check_perms('users_mod') && !empty($_GET['torrentid']) && is_number($_GET['torrentid'])) {
Torrents::regenerate_filelist($_GET['torrentid']); Torrents::regenerate_filelist($_GET['torrentid']);
header('Location: torrents.php?torrentid='.$_GET['torrentid']); header('Location: torrents.php?torrentid='.$_GET['torrentid']);
die(); die();
@ -326,14 +339,14 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
} }
break; break;
case 'fix_group' : case 'fix_group' :
if((check_perms('users_mod') || check_perms('torrents_fix_ghosts')) && authorize() && !empty($_GET['groupid']) && is_number($_GET['groupid'])) { if ((check_perms('users_mod') || check_perms('torrents_fix_ghosts')) && authorize() && !empty($_GET['groupid']) && is_number($_GET['groupid'])) {
$DB->query("SELECT COUNT(ID) FROM torrents WHERE GroupID = ".$_GET['groupid']); $DB->query("SELECT COUNT(ID) FROM torrents WHERE GroupID = ".$_GET['groupid']);
list($Count) = $DB->next_record(); list($Count) = $DB->next_record();
if($Count == 0) { if ($Count == 0) {
Torrents::delete_group($_GET['groupid']); Torrents::delete_group($_GET['groupid']);
} else { } else {
} }
if(!empty($_GET['artistid']) && is_number($_GET['artistid'])) { if (!empty($_GET['artistid']) && is_number($_GET['artistid'])) {
header('Location: artist.php?id='.$_GET['artistid']); header('Location: artist.php?id='.$_GET['artistid']);
} else { } else {
header('Location: torrents.php?id='.$_GET['groupid']); header('Location: torrents.php?id='.$_GET['groupid']);
@ -351,12 +364,12 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
default: default:
enforce_login(); enforce_login();
if(!empty($_GET['id'])) { if (!empty($_GET['id'])) {
include(SERVER_ROOT.'/sections/torrents/details.php'); include(SERVER_ROOT.'/sections/torrents/details.php');
} elseif(isset($_GET['torrentid']) && is_number($_GET['torrentid'])) { } elseif (isset($_GET['torrentid']) && is_number($_GET['torrentid'])) {
$DB->query("SELECT GroupID FROM torrents WHERE ID=".$_GET['torrentid']); $DB->query("SELECT GroupID FROM torrents WHERE ID=".$_GET['torrentid']);
list($GroupID) = $DB->next_record(); list($GroupID) = $DB->next_record();
if($GroupID) { if ($GroupID) {
header("Location: torrents.php?id=".$GroupID."&torrentid=".$_GET['torrentid']); header("Location: torrents.php?id=".$GroupID."&torrentid=".$_GET['torrentid']);
} }
} else { } else {
@ -367,22 +380,22 @@ function js_pages($Action, $TorrentID, $NumResults, $CurrentPage) {
} else { } else {
enforce_login(); enforce_login();
if(!empty($_GET['id'])) { if (!empty($_GET['id'])) {
include(SERVER_ROOT.'/sections/torrents/details.php'); include(SERVER_ROOT.'/sections/torrents/details.php');
} elseif(isset($_GET['torrentid']) && is_number($_GET['torrentid'])) { } elseif (isset($_GET['torrentid']) && is_number($_GET['torrentid'])) {
$DB->query("SELECT GroupID FROM torrents WHERE ID=".$_GET['torrentid']); $DB->query("SELECT GroupID FROM torrents WHERE ID=".$_GET['torrentid']);
list($GroupID) = $DB->next_record(); list($GroupID) = $DB->next_record();
if($GroupID) { if ($GroupID) {
header("Location: torrents.php?id=".$GroupID."&torrentid=".$_GET['torrentid']."#torrent".$_GET['torrentid']); header("Location: torrents.php?id=".$GroupID."&torrentid=".$_GET['torrentid']."#torrent".$_GET['torrentid']);
} else { } else {
header("Location: log.php?search=Torrent+$_GET[torrentid]"); header("Location: log.php?search=Torrent+$_GET[torrentid]");
} }
} elseif(!empty($_GET['type'])) { } elseif (!empty($_GET['type'])) {
include(SERVER_ROOT.'/sections/torrents/user.php'); include(SERVER_ROOT.'/sections/torrents/user.php');
} elseif(!empty($_GET['groupname']) && !empty($_GET['forward'])) { } elseif (!empty($_GET['groupname']) && !empty($_GET['forward'])) {
$DB->query("SELECT ID FROM torrents_group WHERE Name LIKE '".db_string($_GET['groupname'])."'"); $DB->query("SELECT ID FROM torrents_group WHERE Name LIKE '".db_string($_GET['groupname'])."'");
list($GroupID) = $DB->next_record(); list($GroupID) = $DB->next_record();
if($GroupID) { if ($GroupID) {
header("Location: torrents.php?id=".$GroupID); header("Location: torrents.php?id=".$GroupID);
} else { } else {
include(SERVER_ROOT.'/sections/torrents/browse2.php'); include(SERVER_ROOT.'/sections/torrents/browse2.php');

View File

@ -72,7 +72,7 @@
$Properties['TorrentDescription'] = $_POST['release_desc']; $Properties['TorrentDescription'] = $_POST['release_desc'];
if ($_POST['album_desc']) { if ($_POST['album_desc']) {
$Properties['GroupDescription'] = trim($_POST['album_desc']); $Properties['GroupDescription'] = trim($_POST['album_desc']);
} elseif ($_POST['desc']){ } elseif ($_POST['desc']) {
$Properties['GroupDescription'] = trim($_POST['desc']); $Properties['GroupDescription'] = trim($_POST['desc']);
} }
$Properties['GroupID'] = $_POST['groupid']; $Properties['GroupID'] = $_POST['groupid'];
@ -116,7 +116,7 @@
} }
} }
if ($Properties['Remastered'] && !$Properties['UnknownRelease']){ if ($Properties['Remastered'] && !$Properties['UnknownRelease']) {
$Validate->SetFields('remaster_year', $Validate->SetFields('remaster_year',
'1','number','Year of remaster/re-issue must be entered.'); '1','number','Year of remaster/re-issue must be entered.');
} else { } else {
@ -439,11 +439,11 @@
// Don't escape tg.Name. It's written directly to the log table // Don't escape tg.Name. It's written directly to the log table
list($GroupID, $WikiImage, $WikiBody, $RevisionID, $Properties['Title'], $Properties['Year'], $Properties['ReleaseType'], $Properties['TagList']) = $DB->next_record(MYSQLI_NUM, array(4)); list($GroupID, $WikiImage, $WikiBody, $RevisionID, $Properties['Title'], $Properties['Year'], $Properties['ReleaseType'], $Properties['TagList']) = $DB->next_record(MYSQLI_NUM, array(4));
$Properties['TagList'] = str_replace(array(" ",".","_"), array(", ",".","."), $Properties['TagList']); $Properties['TagList'] = str_replace(array(" ",".","_"), array(", ",".","."), $Properties['TagList']);
if (!$Properties['Image'] && $WikiImage){ if (!$Properties['Image'] && $WikiImage) {
$Properties['Image'] = $WikiImage; $Properties['Image'] = $WikiImage;
$T['Image'] = "'".db_string($WikiImage)."'"; $T['Image'] = "'".db_string($WikiImage)."'";
} }
if (strlen($WikiBody) > strlen($Body)){ if (strlen($WikiBody) > strlen($Body)) {
$Body = $WikiBody; $Body = $WikiBody;
if (!$Properties['Image'] || $Properties['Image'] == $WikiImage) { if (!$Properties['Image'] || $Properties['Image'] == $WikiImage) {
$NoRevision = true; $NoRevision = true;
@ -475,7 +475,7 @@
$Properties['Image'] = $WikiImage; $Properties['Image'] = $WikiImage;
$T['Image'] = "'".db_string($WikiImage)."'"; $T['Image'] = "'".db_string($WikiImage)."'";
} }
if (strlen($WikiBody) > strlen($Body)){ if (strlen($WikiBody) > strlen($Body)) {
$Body = $WikiBody; $Body = $WikiBody;
if (!$Properties['Image'] || $Properties['Image'] == $WikiImage) { if (!$Properties['Image'] || $Properties['Image'] == $WikiImage) {
$NoRevision = true; $NoRevision = true;
@ -916,7 +916,7 @@
$DB->query($SQL); $DB->query($SQL);
$Debug->set_flag('upload: notification query finished'); $Debug->set_flag('upload: notification query finished');
if ($DB->record_count()>0){ if ($DB->record_count() > 0) {
$UserArray = $DB->to_array('UserID'); $UserArray = $DB->to_array('UserID');
$FilterArray = $DB->to_array('ID'); $FilterArray = $DB->to_array('ID');
@ -949,7 +949,7 @@
$Feed->populate('torrents_all',$Item); $Feed->populate('torrents_all',$Item);
$Debug->set_flag('upload: notifications handled'); $Debug->set_flag('upload: notifications handled');
if ($Type == 'Music'){ if ($Type == 'Music') {
$Feed->populate('torrents_music',$Item); $Feed->populate('torrents_music',$Item);
if ($Properties['Media'] == 'Vinyl') { if ($Properties['Media'] == 'Vinyl') {
$Feed->populate('torrents_vinyl',$Item); $Feed->populate('torrents_vinyl',$Item);

View File

@ -1,9 +1,9 @@
<? <?
//TODO: Move to somewhere more appropriate, doesn't really belong under users, tools maybe but we don't have that page publicly accessible. //TODO: Move to somewhere more appropriate, doesn't really belong under users, tools maybe but we don't have that page publicly accessible.
if(isset($_GET['ip']) && isset($_GET['port'])){ if (isset($_GET['ip']) && isset($_GET['port'])) {
$Octets = explode(".", $_GET['ip']); $Octets = explode(".", $_GET['ip']);
if( if (
empty($_GET['ip']) || empty($_GET['ip']) ||
!preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $_GET['ip']) || !preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $_GET['ip']) ||
$Octets[0] < 0 || $Octets[0] < 0 ||
@ -20,12 +20,12 @@
die('Invalid IP'); die('Invalid IP');
} }
if (empty($_GET['port']) || !is_number($_GET['port']) || $_GET['port']<1 || $_GET['port']>65535){ if (empty($_GET['port']) || !is_number($_GET['port']) || $_GET['port'] < 1 || $_GET['port'] > 65535) {
die('Invalid Port'); die('Invalid Port');
} }
//Error suppression, ugh. //Error suppression, ugh.
if(@fsockopen($_GET['ip'], $_GET['port'], $Errno, $Errstr, 20)){ if (@fsockopen($_GET['ip'], $_GET['port'], $Errno, $Errstr, 20)) {
die('Port '.$_GET['port'].' on '.$_GET['ip'].' connected successfully.'); die('Port '.$_GET['port'].' on '.$_GET['ip'].' connected successfully.');
} else { } else {
die('Port '.$_GET['port'].' on '.$_GET['ip'].' failed to connect.'); die('Port '.$_GET['port'].' on '.$_GET['ip'].' failed to connect.');

View File

@ -4,14 +4,16 @@
$InviteKey = db_string($_GET['invite']); $InviteKey = db_string($_GET['invite']);
$DB->query("SELECT InviterID FROM invites WHERE InviteKey='$InviteKey'"); $DB->query("SELECT InviterID FROM invites WHERE InviteKey='$InviteKey'");
list($UserID) = $DB->next_record(); list($UserID) = $DB->next_record();
if($DB->record_count() == 0 || $UserID!=$LoggedUser['ID']){ error(404); } if ($DB->record_count() == 0 || $UserID!=$LoggedUser['ID']) {
error(404);
}
$DB->query("DELETE FROM invites WHERE InviteKey='$InviteKey'"); $DB->query("DELETE FROM invites WHERE InviteKey='$InviteKey'");
if(!check_perms('site_send_unlimited_invites')){ if (!check_perms('site_send_unlimited_invites')) {
$DB->query("SELECT Invites FROM users_main WHERE ID = ".$UserID." LIMIT 1"); $DB->query("SELECT Invites FROM users_main WHERE ID = ".$UserID." LIMIT 1");
list($Invites) = $DB->next_record(); list($Invites) = $DB->next_record();
if($Invites < 10) { if ($Invites < 10) {
$DB->query("UPDATE users_main SET Invites=Invites+1 WHERE ID='$UserID'"); $DB->query("UPDATE users_main SET Invites=Invites+1 WHERE ID='$UserID'");
$Cache->begin_transaction('user_info_heavy_'.$UserID); $Cache->begin_transaction('user_info_heavy_'.$UserID);
$Cache->update_row(false, array('Invites'=>'+1')); $Cache->update_row(false, array('Invites'=>'+1'));

View File

@ -17,22 +17,23 @@
$Val->SetFields('username','1','username','Please enter a username.'); $Val->SetFields('username','1','username','Please enter a username.');
$Err = $Val->ValidateForm($_GET); $Err = $Val->ValidateForm($_GET);
if(!$Err){ if (!$Err) {
// Passed validation. Let's rock. // Passed validation. Let's rock.
list($Page,$Limit) = Format::page_limit(USERS_PER_PAGE); list($Page,$Limit) = Format::page_limit(USERS_PER_PAGE);
if ($Page > 10) { if ($Page > 10) {
$Page = 10; $Page = 10;
$Limit = sprintf("%d, %d", ($Page-1)*USERS_PER_PAGE, USERS_PER_PAGE); $Limit = sprintf("%d, %d", ($Page - 1) * USERS_PER_PAGE, USERS_PER_PAGE);
} }
$DB->query("SELECT SQL_CALC_FOUND_ROWS $DB->query("
ID, SELECT SQL_CALC_FOUND_ROWS
Username, ID,
Enabled, Username,
PermissionID, Enabled,
Donor, PermissionID,
Warned Donor,
Warned
FROM users_main AS um FROM users_main AS um
JOIN users_info AS ui ON ui.UserID=um.ID JOIN users_info AS ui ON ui.UserID=um.ID
WHERE Username LIKE '%".db_string($_GET['username'], true)."%' WHERE Username LIKE '%".db_string($_GET['username'], true)."%'
ORDER BY Username ORDER BY Username
LIMIT $Limit"); LIMIT $Limit");
@ -53,7 +54,7 @@
</div> </div>
<div class="linkbox"> <div class="linkbox">
<? <?
$Pages=Format::get_pages($Page,$NumResults,USERS_PER_PAGE,9); $Pages = Format::get_pages($Page, $NumResults, USERS_PER_PAGE, 9);
echo $Pages; echo $Pages;
?> ?>
</div> </div>

View File

@ -2,7 +2,7 @@
authorize(); authorize();
$UserID = $_REQUEST['userid']; $UserID = $_REQUEST['userid'];
if(!is_number($UserID)) { if (!is_number($UserID)) {
error(404); error(404);
} }
@ -39,7 +39,7 @@
$Err = $Val->ValidateForm($_POST); $Err = $Val->ValidateForm($_POST);
if($Err) { if ($Err) {
error($Err); error($Err);
header('Location: user.php?action=edit&userid='.$UserID); header('Location: user.php?action=edit&userid='.$UserID);
die(); die();
@ -72,29 +72,29 @@
// if showing exactly 2 of stats, show all 3 of stats // if showing exactly 2 of stats, show all 3 of stats
$StatsShown = 0; $StatsShown = 0;
$Stats = array('downloaded', 'uploaded', 'ratio'); $Stats = array('downloaded', 'uploaded', 'ratio');
foreach($Stats as $S) { foreach ($Stats as $S) {
if(isset($_POST['p_'.$S])) { if (isset($_POST['p_'.$S])) {
$StatsShown++; $StatsShown++;
} }
} }
if($StatsShown == 2) { if ($StatsShown == 2) {
foreach($Stats as $S) { foreach ($Stats as $S) {
$_POST['p_'.$S] = 'on'; $_POST['p_'.$S] = 'on';
} }
} }
$Paranoia = array(); $Paranoia = array();
$Checkboxes = array('downloaded', 'uploaded', 'ratio', 'lastseen', 'requiredratio', 'invitedcount', 'artistsadded'); $Checkboxes = array('downloaded', 'uploaded', 'ratio', 'lastseen', 'requiredratio', 'invitedcount', 'artistsadded');
foreach($Checkboxes as $C) { foreach ($Checkboxes as $C) {
if(!isset($_POST['p_'.$C])) { if (!isset($_POST['p_'.$C])) {
$Paranoia[] = $C; $Paranoia[] = $C;
} }
} }
$SimpleSelects = array('torrentcomments', 'collages', 'collagecontribs', 'uploads', 'uniquegroups', 'perfectflacs', 'seeding', 'leeching', 'snatched'); $SimpleSelects = array('torrentcomments', 'collages', 'collagecontribs', 'uploads', 'uniquegroups', 'perfectflacs', 'seeding', 'leeching', 'snatched');
foreach ($SimpleSelects as $S) { foreach ($SimpleSelects as $S) {
if(!isset($_POST['p_'.$S.'_c']) && !isset($_POST['p_'.$S.'_l'])) { if (!isset($_POST['p_'.$S.'_c']) && !isset($_POST['p_'.$S.'_l'])) {
// Very paranoid - don't show count or list // Very paranoid - don't show count or list
$Paranoia[] = $S . '+'; $Paranoia[] = $S . '+';
} elseif (!isset($_POST['p_'.$S.'_l'])) { } elseif (!isset($_POST['p_'.$S.'_l'])) {
@ -126,14 +126,14 @@
$DB->query("SELECT Email FROM users_main WHERE ID=".$UserID); $DB->query("SELECT Email FROM users_main WHERE ID=".$UserID);
list($CurEmail) = $DB->next_record(); list($CurEmail) = $DB->next_record();
if ($CurEmail != $_POST['email']) { if ($CurEmail != $_POST['email']) {
if(!check_perms('users_edit_profiles')) { // Non-admins have to authenticate to change email if (!check_perms('users_edit_profiles')) { // Non-admins have to authenticate to change email
$DB->query("SELECT PassHash,Secret FROM users_main WHERE ID='".db_string($UserID)."'"); $DB->query("SELECT PassHash,Secret FROM users_main WHERE ID='".db_string($UserID)."'");
list($PassHash,$Secret)=$DB->next_record(); list($PassHash,$Secret)=$DB->next_record();
if(!Users::check_password($_POST['cur_pass'], $PassHash, $Secret)) { if (!Users::check_password($_POST['cur_pass'], $PassHash, $Secret)) {
$Err = "You did not enter the correct password."; $Err = "You did not enter the correct password.";
} }
} }
if(!$Err) { if (!$Err) {
$NewEmail = db_string($_POST['email']); $NewEmail = db_string($_POST['email']);
@ -167,7 +167,7 @@
} }
} }
if($LoggedUser['DisableAvatar'] && $_POST['avatar'] != $U['Avatar']) { if ($LoggedUser['DisableAvatar'] && $_POST['avatar'] != $U['Avatar']) {
$Err = "Your avatar rights have been removed."; $Err = "Your avatar rights have been removed.";
} }
@ -177,7 +177,7 @@
die(); die();
} }
if(!empty($LoggedUser['DefaultSearch'])) { if (!empty($LoggedUser['DefaultSearch'])) {
$Options['DefaultSearch'] = $LoggedUser['DefaultSearch']; $Options['DefaultSearch'] = $LoggedUser['DefaultSearch'];
} }
$Options['DisableGrouping2'] = (!empty($_POST['disablegrouping']) ? 1 : 0); $Options['DisableGrouping2'] = (!empty($_POST['disablegrouping']) ? 1 : 0);
@ -201,14 +201,14 @@
$Options['CoverArt'] = (int) !empty($_POST['coverart']); $Options['CoverArt'] = (int) !empty($_POST['coverart']);
if(isset($LoggedUser['DisableFreeTorrentTop10'])) { if (isset($LoggedUser['DisableFreeTorrentTop10'])) {
$Options['DisableFreeTorrentTop10'] = $LoggedUser['DisableFreeTorrentTop10']; $Options['DisableFreeTorrentTop10'] = $LoggedUser['DisableFreeTorrentTop10'];
} }
if(!empty($_POST['sorthide'])) { if (!empty($_POST['sorthide'])) {
$JSON = json_decode($_POST['sorthide']); $JSON = json_decode($_POST['sorthide']);
foreach($JSON as $J) { foreach ($JSON as $J) {
$E = explode("_", $J); $E = explode('_', $J);
$Options['SortHide'][$E[0]] = $E[1]; $Options['SortHide'][$E[0]] = $E[1];
} }
} else { } else {
@ -226,30 +226,29 @@
unset($Options['ShowQueryList']); unset($Options['ShowQueryList']);
unset($Options['ShowCacheList']); unset($Options['ShowCacheList']);
$DownloadAlt = (isset($_POST['downloadalt']))? 1:0; $DownloadAlt = (isset($_POST['downloadalt'])) ? 1 : 0;
$UnseededAlerts = (isset($_POST['unseededalerts']))? 1:0; $UnseededAlerts = (isset($_POST['unseededalerts'])) ? 1 : 0;
$LastFMUsername = db_string($_POST['lastfm_username']); $LastFMUsername = db_string($_POST['lastfm_username']);
$OldLastFMUsername = ""; $OldLastFMUsername = "";
$DB->query("SELECT username FROM lastfm_users WHERE ID = '$UserID'"); $DB->query("SELECT username FROM lastfm_users WHERE ID = '$UserID'");
if($DB->record_count() > 0) { if ($DB->record_count() > 0) {
list($OldLastFMUsername) = $DB->next_record(); list($OldLastFMUsername) = $DB->next_record();
if($OldLastFMUsername != $LastFMUsername) { if ($OldLastFMUsername != $LastFMUsername) {
if(empty($LastFMUsername)) { if (empty($LastFMUsername)) {
$DB->query("DELETE FROM lastfm_users WHERE ID = '$UserID'"); $DB->query("DELETE FROM lastfm_users WHERE ID = '$UserID'");
} else { } else {
$DB->query("UPDATE lastfm_users SET Username = '$LastFMUsername' WHERE ID = '$UserID'"); $DB->query("UPDATE lastfm_users SET Username = '$LastFMUsername' WHERE ID = '$UserID'");
} }
} }
} } elseif (!empty($LastFMUsername)) {
elseif(!empty($LastFMUsername)) {
$DB->query("INSERT INTO lastfm_users (ID, Username) VALUES ('$UserID', '$LastFMUsername')"); $DB->query("INSERT INTO lastfm_users (ID, Username) VALUES ('$UserID', '$LastFMUsername')");
} }
// Information on how the user likes to download torrents is stored in cache // Information on how the user likes to download torrents is stored in cache
if($DownloadAlt != $LoggedUser['DownloadAlt']) { if ($DownloadAlt != $LoggedUser['DownloadAlt']) {
$Cache->delete_value('user_'.$LoggedUser['torrent_pass']); $Cache->delete_value('user_'.$LoggedUser['torrent_pass']);
} }
@ -286,7 +285,7 @@
$SQL .= "m.Paranoia='".db_string(serialize($Paranoia))."'"; $SQL .= "m.Paranoia='".db_string(serialize($Paranoia))."'";
if($ResetPassword) { if ($ResetPassword) {
$ChangerIP = db_string($LoggedUser['IP']); $ChangerIP = db_string($LoggedUser['IP']);
$PassHash=Users::make_crypt_hash($_POST['new_pass_1']); $PassHash=Users::make_crypt_hash($_POST['new_pass_1']);
$SQL.=",m.PassHash='".db_string($PassHash)."'"; $SQL.=",m.PassHash='".db_string($PassHash)."'";

View File

@ -1,6 +1,6 @@
<? <?
if(!$UserCount = $Cache->get_value('stats_user_count')){ if (!$UserCount = $Cache->get_value('stats_user_count')) {
$DB->query("SELECT COUNT(ID) FROM users_main WHERE Enabled='1'"); $DB->query("SELECT COUNT(ID) FROM users_main WHERE Enabled='1'");
list($UserCount) = $DB->next_record(); list($UserCount) = $DB->next_record();
$Cache->cache_value('stats_user_count', $UserCount, 0); $Cache->cache_value('stats_user_count', $UserCount, 0);
@ -14,12 +14,11 @@
$DB->query("SELECT can_leech FROM users_main WHERE ID = ".$UserID); $DB->query("SELECT can_leech FROM users_main WHERE ID = ".$UserID);
list($CanLeech) = $DB->next_record(); list($CanLeech) = $DB->next_record();
if($LoggedUser['RatioWatch'] || if ($LoggedUser['RatioWatch'] ||
!$CanLeech || !$CanLeech ||
$LoggedUser['DisableInvites'] == '1'|| $LoggedUser['DisableInvites'] == '1'||
$LoggedUser['Invites']==0 && !check_perms('site_send_unlimited_invites') || $LoggedUser['Invites'] == 0 && !check_perms('site_send_unlimited_invites') ||
($UserCount >= USER_LIMIT && USER_LIMIT != 0 && !check_perms('site_can_invite_always'))) { ($UserCount >= USER_LIMIT && USER_LIMIT != 0 && !check_perms('site_can_invite_always'))) {
error(403); error(403);
} }
@ -30,15 +29,15 @@
$InviteExpires = time_plus(60*60*24*3); // 3 days $InviteExpires = time_plus(60*60*24*3); // 3 days
//MultiInvite //MultiInvite
if(strpos($Email, '|') && check_perms('site_send_unlimited_invites')) { if (strpos($Email, '|') && check_perms('site_send_unlimited_invites')) {
$Emails = explode('|', $Email); $Emails = explode('|', $Email);
} else { } else {
$Emails = array($Email); $Emails = array($Email);
} }
foreach($Emails as $CurEmail){ foreach ($Emails as $CurEmail) {
if (!preg_match("/^".EMAIL_REGEX."$/i", $CurEmail)) { if (!preg_match("/^".EMAIL_REGEX."$/i", $CurEmail)) {
if(count($Emails) > 1) { if (count($Emails) > 1) {
continue; continue;
} else { } else {
error('Invalid email.'); error('Invalid email.');
@ -47,7 +46,7 @@
} }
} }
$DB->query("SELECT Expires FROM invites WHERE InviterID = ".$LoggedUser['ID']." AND Email LIKE '".$CurEmail."'"); $DB->query("SELECT Expires FROM invites WHERE InviterID = ".$LoggedUser['ID']." AND Email LIKE '".$CurEmail."'");
if($DB->record_count() > 0) { if ($DB->record_count() > 0) {
error("You already have a pending invite to that address!"); error("You already have a pending invite to that address!");
header('Location: user.php?action=invite'); header('Location: user.php?action=invite');
die(); die();

View File

@ -679,7 +679,7 @@
$Summary = implode(', ', $EditSummary)." by ".$LoggedUser['Username']; $Summary = implode(', ', $EditSummary)." by ".$LoggedUser['Username'];
$Summary = sqltime().' - '.ucfirst($Summary); $Summary = sqltime().' - '.ucfirst($Summary);
if ($Reason){ if ($Reason) {
$Summary .= "\nReason: ".$Reason; $Summary .= "\nReason: ".$Reason;
} }

View File

@ -86,9 +86,9 @@
?> ?>
</tr> </tr>
<? <?
foreach ($History as $Key => $Values){ foreach ($History as $Key => $Values) {
if (isset($History[$Key+1])) { if (isset($History[$Key + 1])) {
$Values['Time'] = $History[$Key+1]['Time']; $Values['Time'] = $History[$Key + 1]['Time'];
} else { } else {
$Values['Time'] = $Joined; $Values['Time'] = $Joined;
} }
@ -99,7 +99,16 @@
<td><?=display_str($Values['IP'])?> (<?=display_str($Values['Code'])?>) <a href="user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($Values['IP'])?>" class="brackets" title="Search">S</a></td> <td><?=display_str($Values['IP'])?> (<?=display_str($Values['Code'])?>) <a href="user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($Values['IP'])?>" class="brackets" title="Search">S</a></td>
<? <?
if ($UsersOnly == 1) { if ($UsersOnly == 1) {
$ueQuery = $DB->query("SELECT ue.UserID, Username, ue.Time, ue.IP FROM users_history_emails AS ue, users_main WHERE ue.Email = '".db_string($Values['Email'])."' AND UserID != ".$UserID." AND ID = UserID"); $ueQuery = $DB->query("
SELECT
ue.UserID,
Username,
ue.Time,
ue.IP
FROM users_history_emails AS ue, users_main
WHERE ue.Email = '".db_string($Values['Email'])."'
AND UserID != ".$UserID."
AND ID = UserID");
while (list($UserID2, $Time, $IP) = $DB->next_record()) { ?> while (list($UserID2, $Time, $IP) = $DB->next_record()) { ?>
</tr> </tr>
<tr> <tr>
@ -116,7 +125,6 @@
<? <?
} }
} }
?> } ?>
<? } ?>
</table> </table>
<? View::show_footer(); ?> <? View::show_footer(); ?>

View File

@ -13,18 +13,26 @@
define('IPS_PER_PAGE', 25); define('IPS_PER_PAGE', 25);
$UserID = $_GET['userid']; $UserID = $_GET['userid'];
if (!is_number($UserID)) { error(404); } if (!is_number($UserID)) {
error(404);
}
$DB->query("SELECT um.Username, p.Level AS Class FROM users_main AS um LEFT JOIN permissions AS p ON p.ID=um.PermissionID WHERE um.ID = ".$UserID); $DB->query("
SELECT
um.Username,
p.Level AS Class
FROM users_main AS um
LEFT JOIN permissions AS p ON p.ID=um.PermissionID
WHERE um.ID = ".$UserID);
list($Username, $Class) = $DB->next_record(); list($Username, $Class) = $DB->next_record();
if(!check_perms('users_view_ips', $Class)) { if (!check_perms('users_view_ips', $Class)) {
error(403); error(403);
} }
$UsersOnly = $_GET['usersonly']; $UsersOnly = $_GET['usersonly'];
if(isset($_POST['ip'])) { if (isset($_POST['ip'])) {
$SearchIP = db_string($_POST['ip']); $SearchIP = db_string($_POST['ip']);
$SearchIPQuery = " AND h1.IP = '$SearchIP' "; $SearchIPQuery = " AND h1.IP = '$SearchIP' ";
} }
@ -38,7 +46,7 @@ function ShowIPs(rowname) {
} }
function Ban(ip, id, elemID) { function Ban(ip, id, elemID) {
var notes = prompt("Enter notes for this ban"); var notes = prompt("Enter notes for this ban");
if(notes != null && notes.length > 0) { if (notes != null && notes.length > 0) {
var xmlhttp; var xmlhttp;
if (window.XMLHttpRequest) { if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest(); xmlhttp=new XMLHttpRequest();
@ -79,7 +87,8 @@ function UnBan(ip, id, elemID) {
list($Page,$Limit) = Format::page_limit(IPS_PER_PAGE); list($Page,$Limit) = Format::page_limit(IPS_PER_PAGE);
if ($UsersOnly == 1) { if ($UsersOnly == 1) {
$RS = $DB->query("SELECT SQL_CALC_FOUND_ROWS $RS = $DB->query("
SELECT SQL_CALC_FOUND_ROWS
h1.IP, h1.IP,
h1.StartTime, h1.StartTime,
h1.EndTime, h1.EndTime,
@ -90,39 +99,42 @@ function UnBan(ip, id, elemID) {
GROUP_CONCAT(um2.Enabled SEPARATOR '|'), GROUP_CONCAT(um2.Enabled SEPARATOR '|'),
GROUP_CONCAT(ui2.Donor SEPARATOR '|'), GROUP_CONCAT(ui2.Donor SEPARATOR '|'),
GROUP_CONCAT(ui2.Warned SEPARATOR '|') GROUP_CONCAT(ui2.Warned SEPARATOR '|')
FROM users_history_ips AS h1 FROM users_history_ips AS h1
LEFT JOIN users_history_ips AS h2 ON h2.IP=h1.IP AND h2.UserID!=$UserID LEFT JOIN users_history_ips AS h2 ON h2.IP=h1.IP AND h2.UserID!=$UserID
LEFT JOIN users_main AS um2 ON um2.ID=h2.UserID LEFT JOIN users_main AS um2 ON um2.ID=h2.UserID
LEFT JOIN users_info AS ui2 ON ui2.UserID=h2.UserID LEFT JOIN users_info AS ui2 ON ui2.UserID=h2.UserID
WHERE h1.UserID='$UserID' WHERE h1.UserID='$UserID'
AND h2.UserID>0 $SearchIPQuery AND h2.UserID>0 $SearchIPQuery
GROUP BY h1.IP, h1.StartTime GROUP BY h1.IP, h1.StartTime
ORDER BY h1.StartTime DESC LIMIT $Limit"); ORDER BY h1.StartTime DESC
LIMIT $Limit");
} else { } else {
$RS = $DB->query("SELECT SQL_CALC_FOUND_ROWS $RS = $DB->query("
h1.IP, SELECT SQL_CALC_FOUND_ROWS
h1.StartTime, h1.IP,
h1.EndTime, h1.StartTime,
GROUP_CONCAT(h2.UserID SEPARATOR '|'), h1.EndTime,
GROUP_CONCAT(h2.StartTime SEPARATOR '|'), GROUP_CONCAT(h2.UserID SEPARATOR '|'),
GROUP_CONCAT(IFNULL(h2.EndTime,0) SEPARATOR '|'), GROUP_CONCAT(h2.StartTime SEPARATOR '|'),
GROUP_CONCAT(um2.Username SEPARATOR '|'), GROUP_CONCAT(IFNULL(h2.EndTime,0) SEPARATOR '|'),
GROUP_CONCAT(um2.Enabled SEPARATOR '|'), GROUP_CONCAT(um2.Username SEPARATOR '|'),
GROUP_CONCAT(ui2.Donor SEPARATOR '|'), GROUP_CONCAT(um2.Enabled SEPARATOR '|'),
GROUP_CONCAT(ui2.Warned SEPARATOR '|') GROUP_CONCAT(ui2.Donor SEPARATOR '|'),
GROUP_CONCAT(ui2.Warned SEPARATOR '|')
FROM users_history_ips AS h1 FROM users_history_ips AS h1
LEFT JOIN users_history_ips AS h2 ON h2.IP=h1.IP AND h2.UserID!=$UserID LEFT JOIN users_history_ips AS h2 ON h2.IP=h1.IP AND h2.UserID!=$UserID
LEFT JOIN users_main AS um2 ON um2.ID=h2.UserID LEFT JOIN users_main AS um2 ON um2.ID=h2.UserID
LEFT JOIN users_info AS ui2 ON ui2.UserID=h2.UserID LEFT JOIN users_info AS ui2 ON ui2.UserID=h2.UserID
WHERE h1.UserID='$UserID' $SearchIPQuery WHERE h1.UserID='$UserID' $SearchIPQuery
GROUP BY h1.IP, h1.StartTime GROUP BY h1.IP, h1.StartTime
ORDER BY h1.StartTime DESC LIMIT $Limit"); ORDER BY h1.StartTime DESC
LIMIT $Limit");
} }
$DB->query("SELECT FOUND_ROWS()"); $DB->query("SELECT FOUND_ROWS()");
list($NumResults) = $DB->next_record(); list($NumResults) = $DB->next_record();
$DB->set_query_id($RS); $DB->set_query_id($RS);
$Pages=Format::get_pages($Page,$NumResults,IPS_PER_PAGE,9); $Pages = Format::get_pages($Page, $NumResults, IPS_PER_PAGE, 9);
?> ?>
<div class="thin"> <div class="thin">
@ -130,11 +142,11 @@ function UnBan(ip, id, elemID) {
<h2>IP address history for <a href="/user.php?id=<?=$UserID?>"><?=$Username?></a></h2> <h2>IP address history for <a href="/user.php?id=<?=$UserID?>"><?=$Username?></a></h2>
</div> </div>
<div class="linkbox"> <div class="linkbox">
<? if($UsersOnly) { ?> <? if ($UsersOnly) { ?>
<a href="userhistory.php?action=ips&amp;userid=<?=$UserID?>" class="brackets">View all IP addresses</a> <a href="userhistory.php?action=ips&amp;userid=<?=$UserID?>" class="brackets">View all IP addresses</a>
<? } else { ?> <? } else { ?>
<a href="userhistory.php?action=ips&amp;userid=<?=$UserID?>&amp;usersonly=1" class="brackets">View IP addresses with users</a> <a href="userhistory.php?action=ips&amp;userid=<?=$UserID?>&amp;usersonly=1" class="brackets">View IP addresses with users</a>
<? } ?> <? } ?>
<br /> <br />
<?=$Pages?> <?=$Pages?>
</div> </div>
@ -164,13 +176,15 @@ function UnBan(ip, id, elemID) {
$Results = $DB->to_array(); $Results = $DB->to_array();
$CanManageIPBans = check_perms('admin_manage_ipbans'); $CanManageIPBans = check_perms('admin_manage_ipbans');
foreach($Results as $Index => $Result) { foreach ($Results as $Index => $Result) {
list($IP, $StartTime, $EndTime, $UserIDs, $UserStartTimes, $UserEndTimes, $Usernames, $UsersEnabled, $UsersDonor, $UsersWarned) = $Result; list($IP, $StartTime, $EndTime, $UserIDs, $UserStartTimes, $UserEndTimes, $Usernames, $UsersEnabled, $UsersDonor, $UsersWarned) = $Result;
$HasDupe = false; $HasDupe = false;
$UserIDs = explode('|', $UserIDs); $UserIDs = explode('|', $UserIDs);
if(!$EndTime) { $EndTime = sqltime(); } if (!$EndTime) {
if($UserIDs[0] != 0){ $EndTime = sqltime();
}
if ($UserIDs[0] != 0) {
$HasDupe = true; $HasDupe = true;
$UserStartTimes = explode('|', $UserStartTimes); $UserStartTimes = explode('|', $UserStartTimes);
$UserEndTimes = explode('|', $UserEndTimes); $UserEndTimes = explode('|', $UserEndTimes);
@ -182,14 +196,13 @@ function UnBan(ip, id, elemID) {
?> ?>
<tr class="rowa"> <tr class="rowa">
<td> <td>
<?=$IP?> (<?=Tools::get_country_code_by_ajax($IP)?>) <?=$IP?> (<?=Tools::get_country_code_by_ajax($IP)?>)<?
<? if ($CanManageIPBans) {
if($CanManageIPBans) { if (!isset($IPs[$IP])) {
if(!isset($IPs[$IP])) {
$sql = "SELECT ID, FromIP, ToIP FROM ip_bans WHERE '".Tools::ip_to_unsigned($IP)."' BETWEEN FromIP AND ToIP LIMIT 1"; $sql = "SELECT ID, FromIP, ToIP FROM ip_bans WHERE '".Tools::ip_to_unsigned($IP)."' BETWEEN FromIP AND ToIP LIMIT 1";
$DB->query($sql); $DB->query($sql);
if($DB->record_count() > 0) { if ($DB->record_count() > 0) {
$IPs[$IP] = true; $IPs[$IP] = true;
?> ?>
<strong>[Banned] <strong>[Banned]
@ -214,10 +227,12 @@ function UnBan(ip, id, elemID) {
<td><?//time_diff(strtotime($StartTime), strtotime($EndTime)); ?></td> <td><?//time_diff(strtotime($StartTime), strtotime($EndTime)); ?></td>
</tr> </tr>
<? <?
if($HasDupe){ if ($HasDupe) {
$HideMe = (count($UserIDs) > 10); $HideMe = (count($UserIDs) > 10);
foreach ($UserIDs as $Key => $Val) { foreach ($UserIDs as $Key => $Val) {
if(!$UserEndTimes[$Key]){ $UserEndTimes[$Key] = sqltime(); } if (!$UserEndTimes[$Key]) {
$UserEndTimes[$Key] = sqltime();
}
?> ?>
<tr class="rowb<?=($HideMe ? ' hidden' : '')?>" name="<?=$Index?>"> <tr class="rowb<?=($HideMe ? ' hidden' : '')?>" name="<?=$Index?>">
<td>&nbsp;&nbsp;&#187;&nbsp;<?=Users::format_username($Val, true, true, true)?></td> <td>&nbsp;&nbsp;&#187;&nbsp;<?=Users::format_username($Val, true, true, true)?></td>

View File

@ -11,22 +11,31 @@
************************************************************************/ ************************************************************************/
$UserID = $_GET['userid']; $UserID = $_GET['userid'];
if (!is_number($UserID)) { error(404); } if (!is_number($UserID)) {
error(404);
}
$DB->query("SELECT um.Username, p.Level AS Class FROM users_main AS um LEFT JOIN permissions AS p ON p.ID=um.PermissionID WHERE um.ID = ".$UserID); $DB->query("
SELECT
um.Username,
p.Level AS Class
FROM users_main AS um
LEFT JOIN permissions AS p ON p.ID=um.PermissionID
WHERE um.ID = ".$UserID);
list($Username, $Class) = $DB->next_record(); list($Username, $Class) = $DB->next_record();
if(!check_perms('users_view_keys', $Class)) { if (!check_perms('users_view_keys', $Class)) {
error(403); error(403);
} }
View::show_header("PassKey history for $Username"); View::show_header("PassKey history for $Username");
$DB->query("SELECT $DB->query("
OldPassKey, SELECT
NewPassKey, OldPassKey,
ChangeTime, NewPassKey,
ChangerIP ChangeTime,
ChangerIP
FROM users_history_passkeys FROM users_history_passkeys
WHERE UserID=$UserID WHERE UserID=$UserID
ORDER BY ChangeTime DESC"); ORDER BY ChangeTime DESC");
@ -42,7 +51,7 @@
<td>Changed</td> <td>Changed</td>
<td>IP <a href="/userhistory.php?action=ips&amp;userid=<?=$UserID?>" class="brackets">H</a></td> <td>IP <a href="/userhistory.php?action=ips&amp;userid=<?=$UserID?>" class="brackets">H</a></td>
</tr> </tr>
<? while(list($OldPassKey, $NewPassKey, $ChangeTime, $ChangerIP) = $DB->next_record()){ ?> <? while (list($OldPassKey, $NewPassKey, $ChangeTime, $ChangerIP) = $DB->next_record()) { ?>
<tr class="rowa"> <tr class="rowa">
<td><?=display_str($OldPassKey)?></td> <td><?=display_str($OldPassKey)?></td>
<td><?=display_str($NewPassKey)?></td> <td><?=display_str($NewPassKey)?></td>

View File

@ -11,20 +11,29 @@
************************************************************************/ ************************************************************************/
$UserID = $_GET['userid']; $UserID = $_GET['userid'];
if (!is_number($UserID)) { error(404); } if (!is_number($UserID)) {
error(404);
}
$DB->query("SELECT um.Username, p.Level AS Class FROM users_main AS um LEFT JOIN permissions AS p ON p.ID=um.PermissionID WHERE um.ID = ".$UserID); $DB->query("
SELECT
um.Username,
p.Level AS Class
FROM users_main AS um
LEFT JOIN permissions AS p ON p.ID=um.PermissionID
WHERE um.ID = ".$UserID);
list($Username, $Class) = $DB->next_record(); list($Username, $Class) = $DB->next_record();
if(!check_perms('users_view_keys', $Class)) { if (!check_perms('users_view_keys', $Class)) {
error(403); error(403);
} }
View::show_header("Password reset history for $Username"); View::show_header("Password reset history for $Username");
$DB->query("SELECT $DB->query("
ChangeTime, SELECT
ChangerIP ChangeTime,
ChangerIP
FROM users_history_passwords FROM users_history_passwords
WHERE UserID=$UserID WHERE UserID=$UserID
ORDER BY ChangeTime DESC"); ORDER BY ChangeTime DESC");
@ -38,7 +47,7 @@
<td>Changed</td> <td>Changed</td>
<td>IP <a href="/userhistory.php?action=ips&amp;userid=<?=$UserID?>" class="brackets">H</a></td> <td>IP <a href="/userhistory.php?action=ips&amp;userid=<?=$UserID?>" class="brackets">H</a></td>
</tr> </tr>
<? while(list($ChangeTime, $ChangerIP) = $DB->next_record()){ ?> <? while (list($ChangeTime, $ChangerIP) = $DB->next_record()) { ?>
<tr class="rowa"> <tr class="rowa">
<td><?=time_diff($ChangeTime)?></td> <td><?=time_diff($ChangeTime)?></td>
<td><?=display_str($ChangerIP)?> <a href="/user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($ChangerIP)?>" class="brackets" title="Search">S</a><br /><?=Tools::get_host_by_ajax($ChangerIP)?></td> <td><?=display_str($ChangerIP)?> <a href="/user.php?action=search&amp;ip_history=on&amp;ip=<?=display_str($ChangerIP)?>" class="brackets" title="Search">S</a><br /><?=Tools::get_host_by_ajax($ChangerIP)?></td>

View File

@ -4,7 +4,7 @@
User post history page User post history page
*/ */
if(!empty($LoggedUser['DisableForums'])) { if (!empty($LoggedUser['DisableForums'])) {
error(403); error(403);
} }
@ -14,7 +14,7 @@
$UserID = empty($_GET['userid']) ? $LoggedUser['ID'] : $_GET['userid']; $UserID = empty($_GET['userid']) ? $LoggedUser['ID'] : $_GET['userid'];
if(!is_number($UserID)){ if (!is_number($UserID)) {
error(0); error(0);
} }
@ -26,7 +26,7 @@
list($Page,$Limit) = Format::page_limit($PerPage); list($Page,$Limit) = Format::page_limit($PerPage);
if(($UserInfo = $Cache->get_value('user_info_'.$UserID)) === false) { if (($UserInfo = $Cache->get_value('user_info_'.$UserID)) === false) {
$DB->query("SELECT $DB->query("SELECT
m.Username, m.Username,
m.Enabled, m.Enabled,
@ -38,7 +38,7 @@
JOIN users_info AS i ON i.UserID = m.ID JOIN users_info AS i ON i.UserID = m.ID
WHERE m.ID = $UserID"); WHERE m.ID = $UserID");
if($DB->record_count() == 0){ // If user doesn't exist if ($DB->record_count() == 0) { // If user doesn't exist
error(404); error(404);
} }
list($Username, $Enabled, $Title, $Avatar, $Donor, $Warned) = $DB->next_record(); list($Username, $Enabled, $Title, $Avatar, $Donor, $Warned) = $DB->next_record();
@ -46,26 +46,26 @@
extract(array_intersect_key($UserInfo, array_flip(array('Username', 'Enabled', 'Title', 'Avatar', 'Donor', 'Warned')))); extract(array_intersect_key($UserInfo, array_flip(array('Username', 'Enabled', 'Title', 'Avatar', 'Donor', 'Warned'))));
} }
if(check_perms('site_proxy_images') && !empty($Avatar)) { if (check_perms('site_proxy_images') && !empty($Avatar)) {
$Avatar = 'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&amp;i='.urlencode($Avatar); $Avatar = 'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&amp;i='.urlencode($Avatar);
} }
View::show_header('Post history for '.$Username,'subscriptions,comments,bbcode'); View::show_header('Post history for '.$Username,'subscriptions,comments,bbcode');
if($LoggedUser['CustomForums']) { if ($LoggedUser['CustomForums']) {
unset($LoggedUser['CustomForums']['']); unset($LoggedUser['CustomForums']['']);
$RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0)); $RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0));
} }
$ViewingOwn = ($UserID == $LoggedUser['ID']); $ViewingOwn = ($UserID == $LoggedUser['ID']);
$ShowUnread = ($ViewingOwn && (!isset($_GET['showunread']) || !!$_GET['showunread'])); $ShowUnread = ($ViewingOwn && (!isset($_GET['showunread']) || !!$_GET['showunread']));
$ShowGrouped = ($ViewingOwn && (!isset($_GET['group']) || !!$_GET['group'])); $ShowGrouped = ($ViewingOwn && (!isset($_GET['group']) || !!$_GET['group']));
if($ShowGrouped) { if ($ShowGrouped) {
$sql = 'SELECT $sql = 'SELECT
SQL_CALC_FOUND_ROWS SQL_CALC_FOUND_ROWS
MAX(p.ID) AS ID MAX(p.ID) AS ID
FROM forums_posts AS p FROM forums_posts AS p
LEFT JOIN forums_topics AS t ON t.ID = p.TopicID'; LEFT JOIN forums_topics AS t ON t.ID = p.TopicID';
if($ShowUnread) { if ($ShowUnread) {
$sql.=' $sql.='
LEFT JOIN forums_last_read_topics AS l ON l.TopicID = t.ID AND l.UserID = '.$LoggedUser['ID']; LEFT JOIN forums_last_read_topics AS l ON l.TopicID = t.ID AND l.UserID = '.$LoggedUser['ID'];
} }
@ -73,17 +73,17 @@
LEFT JOIN forums AS f ON f.ID = t.ForumID LEFT JOIN forums AS f ON f.ID = t.ForumID
WHERE p.AuthorID = '.$UserID.' WHERE p.AuthorID = '.$UserID.'
AND ((f.MinClassRead <= '.$LoggedUser['EffectiveClass']; AND ((f.MinClassRead <= '.$LoggedUser['EffectiveClass'];
if(!empty($RestrictedForums)) { if (!empty($RestrictedForums)) {
$sql.=' $sql.='
AND f.ID NOT IN (\''.$RestrictedForums.'\')'; AND f.ID NOT IN (\''.$RestrictedForums.'\')';
} }
$sql .= ')'; $sql .= ')';
if(!empty($PermittedForums)) { if (!empty($PermittedForums)) {
$sql.=' $sql.='
OR f.ID IN (\''.$PermittedForums.'\')'; OR f.ID IN (\''.$PermittedForums.'\')';
} }
$sql .= ')'; $sql .= ')';
if($ShowUnread) { if ($ShowUnread) {
$sql .= ' $sql .= '
AND ((t.IsLocked=\'0\' OR t.IsSticky=\'1\') AND ((t.IsLocked=\'0\' OR t.IsSticky=\'1\')
AND (l.PostID<t.LastPostID OR l.PostID IS NULL))'; AND (l.PostID<t.LastPostID OR l.PostID IS NULL))';
@ -95,29 +95,30 @@
$DB->query("SELECT FOUND_ROWS()"); $DB->query("SELECT FOUND_ROWS()");
list($Results) = $DB->next_record(); list($Results) = $DB->next_record();
if($Results > $PerPage*($Page-1)) { if ($Results > $PerPage*($Page-1)) {
$DB->set_query_id($PostIDs); $DB->set_query_id($PostIDs);
$PostIDs = $DB->collect('ID'); $PostIDs = $DB->collect('ID');
$sql = 'SELECT $sql = '
p.ID, SELECT
p.AddedTime, p.ID,
p.Body, p.AddedTime,
p.EditedUserID, p.Body,
p.EditedTime, p.EditedUserID,
ed.Username, p.EditedTime,
p.TopicID, ed.Username,
t.Title, p.TopicID,
t.LastPostID, t.Title,
l.PostID AS LastRead, t.LastPostID,
t.IsLocked, l.PostID AS LastRead,
t.IsSticky t.IsLocked,
t.IsSticky
FROM forums_posts as p FROM forums_posts as p
LEFT JOIN users_main AS um ON um.ID = p.AuthorID LEFT JOIN users_main AS um ON um.ID = p.AuthorID
LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
JOIN forums_topics AS t ON t.ID = p.TopicID JOIN forums_topics AS t ON t.ID = p.TopicID
JOIN forums AS f ON f.ID = t.ForumID JOIN forums AS f ON f.ID = t.ForumID
LEFT JOIN forums_last_read_topics AS l ON l.UserID = '.$UserID.' AND l.TopicID = t.ID LEFT JOIN forums_last_read_topics AS l ON l.UserID = '.$UserID.' AND l.TopicID = t.ID
WHERE p.ID IN ('.implode(',',$PostIDs).') WHERE p.ID IN ('.implode(',',$PostIDs).')
ORDER BY p.ID DESC'; ORDER BY p.ID DESC';
$Posts = $DB->query($sql); $Posts = $DB->query($sql);
@ -125,7 +126,7 @@
} else { } else {
$sql = 'SELECT $sql = 'SELECT
SQL_CALC_FOUND_ROWS'; SQL_CALC_FOUND_ROWS';
if($ShowGrouped) { if ($ShowGrouped) {
$sql.=' * FROM (SELECT'; $sql.=' * FROM (SELECT';
} }
$sql .= ' $sql .= '
@ -138,7 +139,7 @@
p.TopicID, p.TopicID,
t.Title, t.Title,
t.LastPostID,'; t.LastPostID,';
if($UserID == $LoggedUser['ID']) { if ($UserID == $LoggedUser['ID']) {
$sql .= ' $sql .= '
l.PostID AS LastRead,'; l.PostID AS LastRead,';
} }
@ -146,21 +147,21 @@
t.IsLocked, t.IsLocked,
t.IsSticky t.IsSticky
FROM forums_posts as p FROM forums_posts as p
LEFT JOIN users_main AS um ON um.ID = p.AuthorID LEFT JOIN users_main AS um ON um.ID = p.AuthorID
LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID LEFT JOIN users_info AS ui ON ui.UserID = p.AuthorID
LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID LEFT JOIN users_main AS ed ON ed.ID = p.EditedUserID
JOIN forums_topics AS t ON t.ID = p.TopicID JOIN forums_topics AS t ON t.ID = p.TopicID
JOIN forums AS f ON f.ID = t.ForumID JOIN forums AS f ON f.ID = t.ForumID
LEFT JOIN forums_last_read_topics AS l ON l.UserID = '.$UserID.' AND l.TopicID = t.ID LEFT JOIN forums_last_read_topics AS l ON l.UserID = '.$UserID.' AND l.TopicID = t.ID
WHERE p.AuthorID = '.$UserID.' WHERE p.AuthorID = '.$UserID.'
AND f.MinClassRead <= '.$LoggedUser['EffectiveClass']; AND f.MinClassRead <= '.$LoggedUser['EffectiveClass'];
if(!empty($RestrictedForums)) { if (!empty($RestrictedForums)) {
$sql.=' $sql.='
AND f.ID NOT IN (\''.$RestrictedForums.'\')'; AND f.ID NOT IN (\''.$RestrictedForums.'\')';
} }
if($ShowUnread) { if ($ShowUnread) {
$sql.=' $sql.='
AND ((t.IsLocked=\'0\' OR t.IsSticky=\'1\') AND (l.PostID<t.LastPostID OR l.PostID IS NULL)) '; AND ((t.IsLocked=\'0\' OR t.IsSticky=\'1\') AND (l.PostID<t.LastPostID OR l.PostID IS NULL)) ';
} }
@ -168,7 +169,7 @@
$sql .= ' $sql .= '
ORDER BY p.ID DESC'; ORDER BY p.ID DESC';
if($ShowGrouped) { if ($ShowGrouped) {
$sql.=' $sql.='
) AS sub ) AS sub
GROUP BY TopicID ORDER BY ID DESC'; GROUP BY TopicID ORDER BY ID DESC';
@ -188,10 +189,10 @@
<div class="header"> <div class="header">
<h2> <h2>
<? <?
if($ShowGrouped) { if ($ShowGrouped) {
echo "Grouped ".($ShowUnread?"unread ":"")."post history for <a href=\"user.php?id=$UserID\">$Username</a>"; echo 'Grouped '.($ShowUnread ? 'unread ' : '')."post history for <a href=\"user.php?id=$UserID\">$Username</a>";
} }
elseif($ShowUnread) { elseif ($ShowUnread) {
echo "Unread post history for <a href=\"user.php?id=$UserID\">$Username</a>"; echo "Unread post history for <a href=\"user.php?id=$UserID\">$Username</a>";
} }
else { else {
@ -237,45 +238,45 @@
</div> </div>
</div> </div>
<? <?
if(empty($Results)) { if (empty($Results)) {
?> ?>
<div class="center"> <div class="center">
No topics<?=$ShowUnread?' with unread posts':''?> No topics<?=$ShowUnread ? ' with unread posts' : '' ?>
</div> </div>
<? <?
} else { } else {
?> ?>
<div class="linkbox"> <div class="linkbox">
<? <?
$Pages=Format::get_pages($Page,$Results,$PerPage, 11); $Pages=Format::get_pages($Page, $Results, $PerPage, 11);
echo $Pages; echo $Pages;
?> ?>
</div> </div>
<? <?
while(list($PostID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername, $TopicID, $ThreadTitle, $LastPostID, $LastRead, $Locked, $Sticky) = $DB->next_record()){ while (list($PostID, $AddedTime, $Body, $EditedUserID, $EditedTime, $EditedUsername, $TopicID, $ThreadTitle, $LastPostID, $LastRead, $Locked, $Sticky) = $DB->next_record()) {
?> ?>
<table class="forum_post vertical_margin<?=$HeavyInfo['DisableAvatars'] ? ' noavatar' : ''?>" id="post<?=$PostID ?>"> <table class="forum_post vertical_margin<?=$HeavyInfo['DisableAvatars'] ? ' noavatar' : '' ?>" id="post<?=$PostID ?>">
<colgroup> <colgroup>
<? if(empty($HeavyInfo['DisableAvatars'])) { ?> <? if (empty($HeavyInfo['DisableAvatars'])) { ?>
<col class="col_avatar" /> <col class="col_avatar" />
<? } ?> <? } ?>
<col class="col_post_body" /> <col class="col_post_body" />
</colgroup> </colgroup>
<tr class="colhead_dark"> <tr class="colhead_dark">
<td colspan="<?=empty($HeavyInfo['DisableAvatars']) ? 2 : 1?>"> <td colspan="<?=empty($HeavyInfo['DisableAvatars']) ? 2 : 1 ?>">
<span style="float:left;"> <span style="float: left;">
<?=time_diff($AddedTime) ?> <?=time_diff($AddedTime) ?>
in <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>&amp;postid=<?=$PostID?>#post<?=$PostID?>" title="<?=display_str($ThreadTitle)?>"><?=Format::cut_string($ThreadTitle, 75)?></a> in <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>&amp;postid=<?=$PostID?>#post<?=$PostID?>" title="<?=display_str($ThreadTitle)?>"><?=Format::cut_string($ThreadTitle, 75)?></a>
<? <?
if($ViewingOwn) { if ($ViewingOwn) {
if ((!$Locked || $Sticky) && (!$LastRead || $LastRead < $LastPostID)) { ?> if ((!$Locked || $Sticky) && (!$LastRead || $LastRead < $LastPostID)) { ?>
<span class="new">(New!)</span> <span class="new">(New!)</span>
<? <?
} }
?> ?>
</span> </span>
<? if(!empty($LastRead)) { ?> <? if (!empty($LastRead)) { ?>
<span style="float:left;" class="last_read" title="Jump to last read"> <span style="float: left;" class="last_read" title="Jump to last read">
<a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>&amp;postid=<?=$LastRead?>#post<?=$LastRead?>"></a> <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>&amp;postid=<?=$LastRead?>#post<?=$LastRead?>"></a>
</span> </span>
<? } <? }
@ -284,8 +285,8 @@
</span> </span>
<? } <? }
?> ?>
<span id="bar<?=$PostID ?>" style="float:right;"> <span id="bar<?=$PostID ?>" style="float: right;">
<? if($ViewingOwn && !in_array($TopicID, $UserSubscriptions)) { ?> <? if ($ViewingOwn && !in_array($TopicID, $UserSubscriptions)) { ?>
<a href="#" onclick="Subscribe(<?=$TopicID?>);$('.subscribelink<?=$TopicID?>').remove();return false;" class="brackets subscribelink<?=$TopicID?>">Subscribe</a> <a href="#" onclick="Subscribe(<?=$TopicID?>);$('.subscribelink<?=$TopicID?>').remove();return false;" class="brackets subscribelink<?=$TopicID?>">Subscribe</a>
&nbsp; &nbsp;
<? } ?> <? } ?>
@ -294,15 +295,15 @@
</td> </td>
</tr> </tr>
<? <?
if(!$ShowGrouped) { if (!$ShowGrouped) {
?> ?>
<tr> <tr>
<? <?
if(empty($HeavyInfo['DisableAvatars'])) { if (empty($HeavyInfo['DisableAvatars'])) {
?> ?>
<td class="avatar" valign="top"> <td class="avatar" valign="top">
<? <?
if($Avatar) { if ($Avatar) {
?> ?>
<img src="<?=$Avatar?>" width="150" style="max-height:400px;" alt="<?=$Username?>'s avatar" /> <img src="<?=$Avatar?>" width="150" style="max-height:400px;" alt="<?=$Username?>'s avatar" />
<? <?
@ -315,10 +316,10 @@
<td class="body" valign="top"> <td class="body" valign="top">
<div id="content<?=$PostID?>"> <div id="content<?=$PostID?>">
<?=$Text->full_format($Body)?> <?=$Text->full_format($Body)?>
<? if($EditedUserID) { ?> <? if ($EditedUserID) { ?>
<br /> <br />
<br /> <br />
<? if(check_perms('site_moderate_forums')) { ?> <? if (check_perms('site_moderate_forums')) { ?>
<a href="#content<?=$PostID?>" onclick="LoadEdit(<?=$PostID?>, 1)">&laquo;</a> <a href="#content<?=$PostID?>" onclick="LoadEdit(<?=$PostID?>, 1)">&laquo;</a>
<? } ?> <? } ?>
Last edited by Last edited by

View File

@ -3,7 +3,7 @@
User topic subscription page User topic subscription page
*/ */
if(!empty($LoggedUser['DisableForums'])) { if (!empty($LoggedUser['DisableForums'])) {
error(403); error(403);
} }
@ -19,7 +19,7 @@
View::show_header('Subscribed topics','subscriptions,bbcode'); View::show_header('Subscribed topics','subscriptions,bbcode');
if($LoggedUser['CustomForums']) { if ($LoggedUser['CustomForums']) {
unset($LoggedUser['CustomForums']['']); unset($LoggedUser['CustomForums']['']);
$RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0)); $RestrictedForums = implode("','", array_keys($LoggedUser['CustomForums'], 0));
$PermittedForums = implode("','", array_keys($LoggedUser['CustomForums'], 1)); $PermittedForums = implode("','", array_keys($LoggedUser['CustomForums'], 1));
@ -39,15 +39,15 @@
JOIN forums AS f ON f.ID = t.ForumID JOIN forums AS f ON f.ID = t.ForumID
WHERE p.ID <= IFNULL(l.PostID,t.LastPostID) WHERE p.ID <= IFNULL(l.PostID,t.LastPostID)
AND ((f.MinClassRead <= '.$LoggedUser['Class']; AND ((f.MinClassRead <= '.$LoggedUser['Class'];
if(!empty($RestrictedForums)) { if (!empty($RestrictedForums)) {
$sql.=' AND f.ID NOT IN (\''.$RestrictedForums.'\')'; $sql.=' AND f.ID NOT IN (\''.$RestrictedForums.'\')';
} }
$sql .= ')'; $sql .= ')';
if(!empty($PermittedForums)) { if (!empty($PermittedForums)) {
$sql.=' OR f.ID IN (\''.$PermittedForums.'\')'; $sql.=' OR f.ID IN (\''.$PermittedForums.'\')';
} }
$sql .= ')'; $sql .= ')';
if($ShowUnread) { if ($ShowUnread) {
$sql .= ' $sql .= '
@ -63,7 +63,7 @@
$DB->query('SELECT FOUND_ROWS()'); $DB->query('SELECT FOUND_ROWS()');
list($NumResults) = $DB->next_record(); list($NumResults) = $DB->next_record();
if($NumResults > $PerPage*($Page-1)) { if ($NumResults > $PerPage*($Page-1)) {
$DB->set_query_id($PostIDs); $DB->set_query_id($PostIDs);
$PostIDs = $DB->collect('ID'); $PostIDs = $DB->collect('ID');
$sql = 'SELECT $sql = 'SELECT
@ -99,7 +99,7 @@
<div class="linkbox"> <div class="linkbox">
<? <?
if(!$ShowUnread) { if (!$ShowUnread) {
?> ?>
<br /><br /> <br /><br />
<a href="userhistory.php?action=subscriptions&amp;showunread=1" class="brackets">Only display topics with unread replies</a>&nbsp;&nbsp;&nbsp; <a href="userhistory.php?action=subscriptions&amp;showunread=1" class="brackets">Only display topics with unread replies</a>&nbsp;&nbsp;&nbsp;
@ -110,7 +110,7 @@
<a href="userhistory.php?action=subscriptions&amp;showunread=0" class="brackets">Show all subscribed topics</a>&nbsp;&nbsp;&nbsp; <a href="userhistory.php?action=subscriptions&amp;showunread=0" class="brackets">Show all subscribed topics</a>&nbsp;&nbsp;&nbsp;
<? <?
} }
if($NumResults) { if ($NumResults) {
?> ?>
<a href="#" onclick="Collapse();return false;" id="collapselink" class="brackets"><?=$ShowCollapsed?'Show':'Hide'?> post bodies</a>&nbsp;&nbsp;&nbsp; <a href="#" onclick="Collapse();return false;" id="collapselink" class="brackets"><?=$ShowCollapsed?'Show':'Hide'?> post bodies</a>&nbsp;&nbsp;&nbsp;
<? <?
@ -122,10 +122,10 @@
</div> </div>
</div> </div>
<? <?
if(!$NumResults) { if (!$NumResults) {
?> ?>
<div class="center"> <div class="center">
No subscribed topics<?=$ShowUnread?' with unread posts':''?> No subscribed topics<?=$ShowUnread ? ' with unread posts' : '' ?>
</div> </div>
<? <?
} else { } else {
@ -137,23 +137,23 @@
?> ?>
</div> </div>
<? <?
while(list($ForumID, $ForumName, $TopicID, $ThreadTitle, $Body, $LastPostID, $Locked, $Sticky, $PostID, $AuthorID, $AuthorName, $AuthorAvatar, $EditedUserID, $EditedTime, $EditedUsername) = $DB->next_record()){ while (list($ForumID, $ForumName, $TopicID, $ThreadTitle, $Body, $LastPostID, $Locked, $Sticky, $PostID, $AuthorID, $AuthorName, $AuthorAvatar, $EditedUserID, $EditedTime, $EditedUsername) = $DB->next_record()) {
?> ?>
<table class="forum_post box vertical_margin<?=$HeavyInfo['DisableAvatars'] ? ' noavatar' : ''?>"> <table class="forum_post box vertical_margin<?=$HeavyInfo['DisableAvatars'] ? ' noavatar' : '' ?>">
<colgroup> <colgroup>
<? if(empty($HeavyInfo['DisableAvatars'])) { ?> <? if (empty($HeavyInfo['DisableAvatars'])) { ?>
<col class="col_avatar" /> <col class="col_avatar" />
<? } ?> <? } ?>
<col class="col_post_body" /> <col class="col_post_body" />
</colgroup> </colgroup>
<tr class="colhead_dark"> <tr class="colhead_dark">
<td colspan="<?=empty($HeavyInfo['DisableAvatars']) ? 2 : 1?>"> <td colspan="<?=empty($HeavyInfo['DisableAvatars']) ? 2 : 1 ?>">
<span style="float:left;"> <span style="float:left;">
<a href="forums.php?action=viewforum&amp;forumid=<?=$ForumID?>"><?=$ForumName?></a> &gt; <a href="forums.php?action=viewforum&amp;forumid=<?=$ForumID?>"><?=$ForumName?></a> &gt;
<a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>" title="<?=display_str($ThreadTitle)?>"><?=Format::cut_string($ThreadTitle, 75)?></a> <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID?>" title="<?=display_str($ThreadTitle)?>"><?=Format::cut_string($ThreadTitle, 75)?></a>
<? if($PostID<$LastPostID && !$Locked) { ?> <? if ($PostID < $LastPostID && !$Locked) { ?>
<span class="new">(New!)</span> <span class="new">(New!)</span>
<? } ?> <? } ?>
</span> </span>
<span style="float:left;" class="last_read" title="Jump to last read"> <span style="float:left;" class="last_read" title="Jump to last read">
<a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID.($PostID?'&amp;postid='.$PostID.'#post'.$PostID:'')?>"></a> <a href="forums.php?action=viewthread&amp;threadid=<?=$TopicID.($PostID?'&amp;postid='.$PostID.'#post'.$PostID:'')?>"></a>
@ -165,36 +165,36 @@
</span> </span>
</td> </td>
</tr> </tr>
<tr class="row<?=$ShowCollapsed?' hidden':''?>"> <tr class="row<?=$ShowCollapsed ? ' hidden' : '' ?>">
<? if(empty($HeavyInfo['DisableAvatars'])) { ?> <? if (empty($HeavyInfo['DisableAvatars'])) { ?>
<td class="avatar" valign="top"> <td class="avatar" valign="top">
<? if(check_perms('site_proxy_images') && preg_match('/^https?:\/\/(localhost(:[0-9]{2,5})?|[0-9]{1,3}(\.[0-9]{1,3}){3}|([a-zA-Z0-9\-\_]+\.)+([a-zA-Z]{1,5}[^\.]))(:[0-9]{2,5})?(\/[^<>]+)+\.(jpg|jpeg|gif|png|tif|tiff|bmp)$/is',$AuthorAvatar)) { <? if (check_perms('site_proxy_images') && preg_match('/^https?:\/\/(localhost(:[0-9]{2,5})?|[0-9]{1,3}(\.[0-9]{1,3}){3}|([a-zA-Z0-9\-\_]+\.)+([a-zA-Z]{1,5}[^\.]))(:[0-9]{2,5})?(\/[^<>]+)+\.(jpg|jpeg|gif|png|tif|tiff|bmp)$/is',$AuthorAvatar)) {
$AuthorAvatar = 'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&amp;i='.urlencode($AuthorAvatar); ?> $AuthorAvatar = 'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&amp;i='.urlencode($AuthorAvatar); ?>
<img src="<?=$AuthorAvatar?>" width="150" style="max-height:400px;" alt="<?=$AuthorName?>'s avatar" /> <img src="<?=$AuthorAvatar?>" width="150" style="max-height: 400px;" alt="<?=$AuthorName?>'s avatar" />
<? } elseif(!$AuthorAvatar) { ?> <? } elseif (!$AuthorAvatar) { ?>
<img src="<?=STATIC_SERVER.'common/avatars/default.png'?>" width="150" style="max-height:400px;" alt="Default avatar" /> <img src="<?=STATIC_SERVER.'common/avatars/default.png'?>" width="150" style="max-height: 400px;" alt="Default avatar" />
<? } else { ?> <? } else { ?>
<img src="<?=$AuthorAvatar?>" width="150" style="max-height:400px;" alt="<?=$AuthorName?>'s avatar" /> <img src="<?=$AuthorAvatar?>" width="150" style="max-height: 400px;" alt="<?=$AuthorName?>'s avatar" />
<? } ?> <? } ?>
</td> </td>
<? } ?> <? } ?>
<td class="body" valign="top"> <td class="body" valign="top">
<div class="content3"> <div class="content3">
<?=$Text->full_format($Body) ?> <?=$Text->full_format($Body) ?>
<? if($EditedUserID) { ?> <? if ($EditedUserID) { ?>
<br /><br /> <br /><br />
Last edited by Last edited by
<?=Users::format_username($EditedUserID, false, false, false) ?> <?=time_diff($EditedTime)?> <?=Users::format_username($EditedUserID, false, false, false) ?> <?=time_diff($EditedTime)?>
<? } ?> <? } ?>
</div> </div>
</td> </td>
</tr> </tr>
</table> </table>
<? } // while(list(...)) ?> <? } // while (list(...)) ?>
<div class="linkbox"> <div class="linkbox">
<?=$Pages?> <?=$Pages?>
</div> </div>
<? } // else -- if(empty($NumResults)) ?> <? } // else -- if (empty($NumResults)) ?>
</div> </div>
<? <?

View File

@ -1,14 +1,16 @@
<? <?
authorize(); authorize();
//Todo, check that loggeduser > edit //TODO, check that loggeduser > edit
if(!is_number($_POST['article']) || $_POST['article'] == ''){ error(0); } if (!is_number($_POST['article']) || $_POST['article'] == '') {
error(0);
}
$ArticleID = $_POST['article']; $ArticleID = $_POST['article'];
$NewAlias = $Alias->convert($_POST['alias']); $NewAlias = $Alias->convert($_POST['alias']);
$Dupe = $Alias->to_id($_POST['alias']); $Dupe = $Alias->to_id($_POST['alias']);
if($NewAlias!='' && $NewAlias!='addalias' && !$Dupe){ //Not null, and not dupe if ($NewAlias != '' && $NewAlias!='addalias' && !$Dupe) { //Not null, and not dupe
$DB->query("INSERT INTO wiki_aliases (Alias, UserID, ArticleID) VALUES ('$NewAlias', '$LoggedUser[ID]', '$ArticleID')"); $DB->query("INSERT INTO wiki_aliases (Alias, UserID, ArticleID) VALUES ('$NewAlias', '$LoggedUser[ID]', '$ArticleID')");
$Alias->flush(); $Alias->flush();
} else { } else {

View File

@ -1,10 +1,14 @@
<? <?
if(!isset($_GET['id']) || !is_number($_GET['id'])) { error(404); } if (!isset($_GET['id']) || !is_number($_GET['id'])) {
error(404);
}
$ArticleID = $_GET['id']; $ArticleID = $_GET['id'];
$Latest = $Alias->article($ArticleID); $Latest = $Alias->article($ArticleID);
list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName) = array_shift($Latest); list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName) = array_shift($Latest);
if($Edit > $LoggedUser['EffectiveClass']){ error(404); } if ($Edit > $LoggedUser['EffectiveClass']) {
error(404);
}
View::show_header($Title." Aliases"); View::show_header($Title." Aliases");
?> ?>
@ -43,7 +47,7 @@
</tr> </tr>
<? <?
$DB->query("SELECT Alias FROM wiki_aliases WHERE ArticleID='$ArticleID'"); $DB->query("SELECT Alias FROM wiki_aliases WHERE ArticleID='$ArticleID'");
while(list($Revision, $Title, $AuthorID, $AuthorName, $Date) = $DB->next_record()) { ?> while (list($Revision, $Title, $AuthorID, $AuthorName, $Date) = $DB->next_record()) { ?>
<tr> <tr>
<td><?=$Revision?></td> <td><?=$Revision?></td>
<td><?=$Title?></td> <td><?=$Title?></td>
@ -57,4 +61,4 @@
</table> </table>
</form> </form>
</div> </div>
<? View::show_footer(); ?> <? View::show_footer(); ?>

View File

@ -2,7 +2,7 @@
include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class include(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
$Text = new TEXT(true); $Text = new TEXT(true);
if(!empty($_GET['id']) && is_number($_GET['id'])){ //Visiting article via ID if (!empty($_GET['id']) && is_number($_GET['id'])) { //Visiting article via ID
$ArticleID = $_GET['id']; $ArticleID = $_GET['id'];
} elseif ($_GET['name'] != '') { //Retrieve article ID via alias. } elseif ($_GET['name'] != '') { //Retrieve article ID via alias.
$ArticleID = $Alias->to_id($_GET['name']); $ArticleID = $Alias->to_id($_GET['name']);
@ -11,14 +11,14 @@
error('Unknown article ['.display_str($_GET['id']).']'); error('Unknown article ['.display_str($_GET['id']).']');
} }
if(!$ArticleID) { //No article found if (!$ArticleID) { //No article found
View::show_header('No article found'); View::show_header('No article found');
?> ?>
<div class="thin"> <div class="thin">
<div class="header"> <div class="header">
<h2>No article found</h2> <h2>No article found</h2>
</div> </div>
<div class="box pad" style="padding:10px 10px 10px 20px;"> <div class="box pad" style="padding: 10px 10px 10px 20px;">
There is no article matching the name you requested. There is no article matching the name you requested.
<ul> <ul>
<li><a href="wiki.php?action=search&amp;search=<?=display_str($_GET['name'])?>">Search</a> for an article similar to this.</li> <li><a href="wiki.php?action=search&amp;search=<?=display_str($_GET['name'])?>">Search</a> for an article similar to this.</li>
@ -33,7 +33,9 @@
} }
$Article = $Alias->article($ArticleID); $Article = $Alias->article($ArticleID);
list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName, $Aliases, $UserIDs) = array_shift($Article); list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName, $Aliases, $UserIDs) = array_shift($Article);
if($Read > $LoggedUser['EffectiveClass']){ error('You must be a higher user class to view this wiki article'); } if ($Read > $LoggedUser['EffectiveClass']) {
error('You must be a higher user class to view this wiki article');
}
$TextBody = $Text->full_format($Body, false); $TextBody = $Text->full_format($Body, false);
$TOC = $Text->parse_toc(0); $TOC = $Text->parse_toc(0);
@ -47,7 +49,7 @@
<a href="wiki.php?action=create" class="brackets">Create</a> <a href="wiki.php?action=create" class="brackets">Create</a>
<a href="wiki.php?action=edit&amp;id=<?=$ArticleID?>" class="brackets">Contribute</a> <a href="wiki.php?action=edit&amp;id=<?=$ArticleID?>" class="brackets">Contribute</a>
<a href="wiki.php?action=revisions&amp;id=<?=$ArticleID?>" class="brackets">History</a> <a href="wiki.php?action=revisions&amp;id=<?=$ArticleID?>" class="brackets">History</a>
<? if(check_perms('admin_manage_wiki') && $_GET['id'] != '136'){ ?> <? if (check_perms('admin_manage_wiki') && $_GET['id'] != '136') { ?>
<a href="wiki.php?action=delete&amp;id=<?=$ArticleID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>" class="brackets" onclick="return confirm('Are you sure you want to delete?\nYes, DELETE, not as in \'Oh hey, if this is wrong we can get someone to magically undelete it for us later\' it will be GONE.\nGiven this new information, do you still want to DELETE this article and all its revisions and all its alias\' and act like it never existed?')">Delete</a> <a href="wiki.php?action=delete&amp;id=<?=$ArticleID?>&amp;authkey=<?=$LoggedUser['AuthKey']?>" class="brackets" onclick="return confirm('Are you sure you want to delete?\nYes, DELETE, not as in \'Oh hey, if this is wrong we can get someone to magically undelete it for us later\' it will be GONE.\nGiven this new information, do you still want to DELETE this article and all its revisions and all its alias\' and act like it never existed?')">Delete</a>
<? } ?> <? } ?>
<!--<a href="reports.php?action=submit&amp;type=wiki&amp;article=<?=$ArticleID ?>" class="brackets">Report</a>--> <!--<a href="reports.php?action=submit&amp;type=wiki&amp;article=<?=$ArticleID ?>" class="brackets">Report</a>-->
@ -96,13 +98,13 @@
<li> <li>
<strong>Aliases:</strong> <strong>Aliases:</strong>
<ul> <ul>
<? if($Aliases!=$Title){ <? if ($Aliases != $Title) {
$AliasArray = explode(',', $Aliases); $AliasArray = explode(',', $Aliases);
$UserArray = explode(',', $UserIDs); $UserArray = explode(',', $UserIDs);
$i = 0; $i = 0;
foreach($AliasArray as $AliasItem){ foreach ($AliasArray as $AliasItem) {
?> ?>
<li id="alias_<?=$AliasItem?>"><a href="wiki.php?action=article&amp;name=<?=$AliasItem?>"><?=Format::cut_string($AliasItem,20,1)?></a><? if(check_perms('admin_manage_wiki')){ ?> <a href="#" onclick="Remove_Alias('<?=$AliasItem?>');return false;" class="brackets" title="Delete Alias">X</a> <a href="user.php?id=<?=$UserArray[$i]?>" class="brackets" title="View User">U</a><? } ?></li> <li id="alias_<?=$AliasItem?>"><a href="wiki.php?action=article&amp;name=<?=$AliasItem?>"><?=Format::cut_string($AliasItem,20,1)?></a><? if (check_perms('admin_manage_wiki')) { ?> <a href="#" onclick="Remove_Alias('<?=$AliasItem?>');return false;" class="brackets" title="Delete Alias">X</a> <a href="user.php?id=<?=$UserArray[$i]?>" class="brackets" title="View User">U</a><? } ?></li>
<? $i++; <? $i++;
} }
} }
@ -111,9 +113,9 @@
</li> </li>
</ul> </ul>
</div> </div>
<? if($Edit <= $LoggedUser['EffectiveClass']){ ?> <? if ($Edit <= $LoggedUser['EffectiveClass']) { ?>
<div class="box box_addalias"> <div class="box box_addalias">
<div style="padding:5px;"> <div style="padding: 5px;">
<form class="add_form" name="aliases" action="wiki.php" method="post"> <form class="add_form" name="aliases" action="wiki.php" method="post">
<input type="hidden" name="action" value="add_alias" /> <input type="hidden" name="action" value="add_alias" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" /> <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />

View File

@ -6,12 +6,14 @@ function diff($OldText, $NewText) {
$LineOffset = 0; $LineOffset = 0;
$Result = array(); $Result = array();
foreach($LineArrayOld as $OldLine => $OldString) { foreach ($LineArrayOld as $OldLine => $OldString) {
$Key = $OldLine + $LineOffset; $Key = $OldLine + $LineOffset;
if($Key<0) { $Key = 0; } if ($Key < 0) {
$Key = 0;
}
$Found = -1; $Found = -1;
while($Key<count($LineArrayNew)) { while ($Key<count($LineArrayNew)) {
if ($OldString != $LineArrayNew[$Key]) { if ($OldString != $LineArrayNew[$Key]) {
$Key++; $Key++;
} elseif ($OldString == $LineArrayNew[$Key]) { } elseif ($OldString == $LineArrayNew[$Key]) {
@ -20,18 +22,18 @@ function diff($OldText, $NewText) {
} }
} }
if($Found=='-1') { //we never found the old line in the new array if ($Found == '-1') { //we never found the old line in the new array
$Result[] = '<span class="line_deleted">&larr; '.$OldString.'</span><br />'; $Result[] = '<span class="line_deleted">&larr; '.$OldString.'</span><br />';
$LineOffset = $LineOffset - 1; $LineOffset = $LineOffset - 1;
} elseif ($Found ==$OldLine+$LineOffset) { } elseif ($Found == $OldLine + $LineOffset) {
$Result[] = '<span class="line_unchanged">&#8597; '.$OldString.'</span><br />'; $Result[] = '<span class="line_unchanged">&#8597; '.$OldString.'</span><br />';
} elseif ($Found != $OldLine+$LineOffset) { } elseif ($Found != $OldLine + $LineOffset) {
if ($Found < $OldLine+$LineOffset) { if ($Found < $OldLine + $LineOffset) {
$Result[] = '<span class="line_moved">&#8676; '.$OldString.'</span><br />'; $Result[] = '<span class="line_moved">&#8676; '.$OldString.'</span><br />';
} else { } else {
$Result[] = '<span class="line_moved">&larr; '.$OldString.'</span><br />'; $Result[] = '<span class="line_moved">&larr; '.$OldString.'</span><br />';
$Key = $OldLine + $LineOffset; $Key = $OldLine + $LineOffset;
while ($Key<$Found) { while ($Key < $Found) {
$Result[] = '<span class="line_new">&rarr; '.$LineArrayNew[$Key].'</span><br />'; $Result[] = '<span class="line_new">&rarr; '.$LineArrayNew[$Key].'</span><br />';
$Key++; $Key++;
} }
@ -40,9 +42,9 @@ function diff($OldText, $NewText) {
$LineOffset = $Found-$OldLine; $LineOffset = $Found-$OldLine;
} }
} }
if(count($LineArrayNew)>count($LineArrayOld) + $LineOffset) { if (count($LineArrayNew) > count($LineArrayOld) + $LineOffset) {
$Key = count($LineArrayOld) + $LineOffset; $Key = count($LineArrayOld) + $LineOffset;
while($Key<count($LineArrayNew)) { while ($Key < count($LineArrayNew)) {
$Result[] = '<span class="line_new">&rarr; '.$LineArrayNew[$Key].'</span><br />'; $Result[] = '<span class="line_new">&rarr; '.$LineArrayNew[$Key].'</span><br />';
$Key++; $Key++;
} }
@ -53,11 +55,13 @@ function diff($OldText, $NewText) {
function get_body($ID, $Rev) { function get_body($ID, $Rev) {
global $DB, $Revision, $Body; global $DB, $Revision, $Body;
if($Rev == $Revision) { if ($Rev == $Revision) {
$Str = $Body; $Str = $Body;
} else { } else {
$DB->query("SELECT Body FROM wiki_revisions WHERE ID='$ID' AND Revision='$Rev'"); $DB->query("SELECT Body FROM wiki_revisions WHERE ID='$ID' AND Revision='$Rev'");
if(!$DB->record_count()) { error(404); } if (!$DB->record_count()) {
error(404);
}
list($Str) = $DB->next_record(); list($Str) = $DB->next_record();
} }
return $Str; return $Str;
@ -77,7 +81,9 @@ function get_body($ID, $Rev) {
$Article = $Alias->article($ArticleID); $Article = $Alias->article($ArticleID);
list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName) = array_shift($Article); list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName) = array_shift($Article);
if($Read > $LoggedUser['EffectiveClass']){ error(404); } if ($Read > $LoggedUser['EffectiveClass']) {
error(404);
}
View::show_header('Compare Article Revisions'); View::show_header('Compare Article Revisions');
$Diff2 = get_body($ArticleID, $_GET['new']); $Diff2 = get_body($ArticleID, $_GET['new']);
@ -88,7 +94,7 @@ function get_body($ID, $Rev) {
<h2>Compare <a href="wiki.php?action=article&amp;id=<?=$ArticleID?>"><?=$Title?></a> Revisions</h2> <h2>Compare <a href="wiki.php?action=article&amp;id=<?=$ArticleID?>"><?=$Title?></a> Revisions</h2>
</div> </div>
<div class="box center_revision" id="center"> <div class="box center_revision" id="center">
<div class="body"><? foreach(diff($Diff1, $Diff2) AS $Line) { echo $Line; } ?></div> <div class="body"><? foreach (diff($Diff1, $Diff2) AS $Line) { echo $Line; } ?></div>
</div> </div>
</div> </div>
<? <?

View File

@ -9,7 +9,7 @@
<div> <div>
<h3>Title</h3> <h3>Title</h3>
<input type="text" name="title" size="92" maxlength="100" /> <input type="text" name="title" size="92" maxlength="100" />
<? /* if($_GET['alias']){ ?> <? /* if ($_GET['alias']) { ?>
<input type="hidden" name="alias" value="<?=display_str(alias($_GET['alias']))?>" /> <input type="hidden" name="alias" value="<?=display_str(alias($_GET['alias']))?>" />
<? } else { ?> <? } else { ?>
<h3>Alias</h3> <h3>Alias</h3>
@ -18,14 +18,14 @@
<? } */?> <? } */?>
<h3>Body </h3> <h3>Body </h3>
<? <?
$ReplyText = new TEXTAREA_PREVIEW('body', 'body', '', 91, 22, true, false); $ReplyText = new TEXTAREA_PREVIEW('body', 'body', '', 91, 22, true, false);
?>
<? if(check_perms('admin_manage_wiki')){ ?> if (check_perms('admin_manage_wiki')) { ?>
<h3>Access</h3> <h3>Access</h3>
<p>There are some situations in which the viewing or editing of an article should be restricted to a certain class.</p> <p>There are some situations in which the viewing or editing of an article should be restricted to a certain class.</p>
<strong>Restrict Read:</strong> <select name="minclassread"><?=class_list()?></select> <strong>Restrict read:</strong> <select name="minclassread"><?=class_list()?></select>
<strong>Restrict Edit:</strong> <select name="minclassedit"><?=class_list()?></select> <strong>Restrict edit:</strong> <select name="minclassedit"><?=class_list()?></select>
<? } ?> <? } ?>
<div style="text-align: center;"> <div style="text-align: center;">
<input type="button" value="Preview" class="hidden button_preview_<?=$ReplyText->getID()?>" title="Preview text" tabindex="1" /> <input type="button" value="Preview" class="hidden button_preview_<?=$ReplyText->getID()?>" title="Preview text" tabindex="1" />
<input type="submit" value="Submit" /> <input type="submit" value="Submit" />
@ -34,4 +34,4 @@
</form> </form>
</div> </div>
</div> </div>
<? View::show_footer(); ?> <? View::show_footer(); ?>

View File

@ -1,10 +1,12 @@
<? <?
if(!is_number($_GET['id']) || $_GET['id'] == ''){ error(404); } if (!is_number($_GET['id']) || $_GET['id'] == '') {
$ArticleID=$_GET['id']; error(404);
}
$ArticleID = $_GET['id'];
$Article = $Alias->article($ArticleID); $Article = $Alias->article($ArticleID);
list($Revision, $Title, $Body, $Read, $Edit, $Date, $Author) = array_shift($Article); list($Revision, $Title, $Body, $Read, $Edit, $Date, $Author) = array_shift($Article);
if($Edit > $LoggedUser['EffectiveClass']){ if ($Edit > $LoggedUser['EffectiveClass']) {
error('You do not have access to edit this article.'); error('You do not have access to edit this article.');
} }
@ -22,14 +24,14 @@
<input type="text" name="title" size="92" maxlength="100" value="<?=$Title?>" /> <input type="text" name="title" size="92" maxlength="100" value="<?=$Title?>" />
<h3>Body </h3> <h3>Body </h3>
<? <?
$ReplyText = new TEXTAREA_PREVIEW('body', 'body', $Body, 91, 22, true, false); $ReplyText = new TEXTAREA_PREVIEW('body', 'body', $Body, 91, 22, true, false);
?>
<? if(check_perms('admin_manage_wiki')){ ?> if (check_perms('admin_manage_wiki')) { ?>
<h3>Access</h3> <h3>Access</h3>
<p>There are some situations in which the viewing or editing of an article should be restricted to a certain class.</p> <p>There are some situations in which the viewing or editing of an article should be restricted to a certain class.</p>
<strong>Restrict Read:</strong> <select name="minclassread"><?=class_list($Read)?></select> <strong>Restrict read:</strong> <select name="minclassread"><?=class_list($Read)?></select>
<strong>Restrict Edit:</strong> <select name="minclassedit"><?=class_list($Edit)?></select> <strong>Restrict edit:</strong> <select name="minclassedit"><?=class_list($Edit)?></select>
<? } ?> <? } ?>
<div style="text-align: center;"> <div style="text-align: center;">
<input type="button" value="Preview" class="hidden button_preview_<?=$ReplyText->getID()?>" title="Preview text" tabindex="1" /> <input type="button" value="Preview" class="hidden button_preview_<?=$ReplyText->getID()?>" title="Preview text" tabindex="1" />
<input type="submit" value="Submit" /> <input type="submit" value="Submit" />
@ -38,4 +40,4 @@
</form> </form>
</div> </div>
</div> </div>
<? View::show_footer(); ?> <? View::show_footer(); ?>

View File

@ -9,13 +9,13 @@
define('INDEX_ARTICLE', '1'); define('INDEX_ARTICLE', '1');
function class_list($Selected=0){ function class_list($Selected = 0) {
global $Classes, $LoggedUser; global $Classes, $LoggedUser;
$Return = ''; $Return = '';
foreach ($Classes as $ID => $Class) { foreach ($Classes as $ID => $Class) {
if($Class['Level'] <= $LoggedUser['EffectiveClass']){ if ($Class['Level'] <= $LoggedUser['EffectiveClass']) {
$Return.='<option value="'.$Class['Level'].'"'; $Return.='<option value="'.$Class['Level'].'"';
if($Selected == $Class['Level']){ if ($Selected == $Class['Level']) {
$Return.=' selected="selected"'; $Return.=' selected="selected"';
} }
$Return.='>'.Format::cut_string($Class['Name'], 20, 1).'</option>'."\n"; $Return.='>'.Format::cut_string($Class['Name'], 20, 1).'</option>'."\n";
@ -25,31 +25,31 @@ function class_list($Selected=0){
return $Return; return $Return;
} }
if(!empty($_REQUEST['action'])) { if (!empty($_REQUEST['action'])) {
switch($_REQUEST['action']) { switch ($_REQUEST['action']) {
case 'create': case 'create':
if($_POST['action']){ if ($_POST['action']) {
include('takecreate.php'); include('takecreate.php');
} else { } else {
include('create.php'); include('create.php');
} }
break; break;
case 'edit': case 'edit':
if($_POST['action']){ if ($_POST['action']) {
include('takeedit.php'); include('takeedit.php');
} else { } else {
include('edit.php'); include('edit.php');
} }
break; break;
case 'link': case 'link':
if($_POST['action']){ if ($_POST['action']) {
include('takelink.php'); include('takelink.php');
} else { } else {
include('link.php'); include('link.php');
} }
break; break;
case 'delete': case 'delete':
if($_POST['action']){ if ($_POST['action']) {
include('takedelete.php'); include('takedelete.php');
} else { } else {
include('delete.php'); include('delete.php');

View File

@ -1,11 +1,17 @@
<? <?
if(!isset($_GET['id']) || !is_number($_GET['id'])) { error(404); } if (!isset($_GET['id']) || !is_number($_GET['id'])) {
error(404);
}
$ArticleID = $_GET['id']; $ArticleID = $_GET['id'];
$Latest = $Alias->article($ArticleID); $Latest = $Alias->article($ArticleID);
list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName) = array_shift($Latest); list($Revision, $Title, $Body, $Read, $Edit, $Date, $AuthorID, $AuthorName) = array_shift($Latest);
if($Read > $LoggedUser['EffectiveClass']){ error(404); } if ($Read > $LoggedUser['EffectiveClass']) {
if($Edit > $LoggedUser['EffectiveClass']){ error(403); } error(404);
}
if ($Edit > $LoggedUser['EffectiveClass']) {
error(403);
}
View::show_header("Revisions of ".$Title); View::show_header("Revisions of ".$Title);
?> ?>
@ -34,15 +40,16 @@
<td><input type="radio" name="new" value="<?=$Revision?>" checked="checked" /></td> <td><input type="radio" name="new" value="<?=$Revision?>" checked="checked" /></td>
</tr> </tr>
<? <?
$DB->query("SELECT $DB->query("
w.Revision, SELECT
w.Title, w.Revision,
w.Author, w.Title,
w.Date w.Author,
w.Date
FROM wiki_revisions AS w FROM wiki_revisions AS w
WHERE w.ID='$ArticleID' WHERE w.ID='$ArticleID'
ORDER BY Revision DESC"); ORDER BY Revision DESC");
while(list($Revision, $Title, $AuthorID, $Date) = $DB->next_record()) { ?> while (list($Revision, $Title, $AuthorID, $Date) = $DB->next_record()) { ?>
<tr> <tr>
<td><?=$Revision?></td> <td><?=$Revision?></td>
<td><?=$Title?></td> <td><?=$Title?></td>

View File

@ -1,7 +1,7 @@
<? <?
if(empty($_GET['nojump'])) { if (empty($_GET['nojump'])) {
$ArticleID = $Alias->to_id($_GET['search']); $ArticleID = $Alias->to_id($_GET['search']);
if($ArticleID) { //Found Article if ($ArticleID) { //Found Article
header('Location: wiki.php?action=article&id='.$ArticleID); header('Location: wiki.php?action=article&id='.$ArticleID);
} }
} }
@ -18,28 +18,37 @@
// What are we looking for? Let's make sure it isn't dangerous. // What are we looking for? Let's make sure it isn't dangerous.
$Search = db_string(trim($_GET['search'])); $Search = db_string(trim($_GET['search']));
if(!in_array($Type, array('w.Title', 'w.Body'))) { $Type = 'w.Title'; } if (!in_array($Type, array('w.Title', 'w.Body'))) {
$Type = 'w.Title';
}
// Break search string down into individual words // Break search string down into individual words
$Words = explode(' ', $Search); $Words = explode(' ', $Search);
$Type = $TypeTable[$_GET['type']]; $Type = $TypeTable[$_GET['type']];
if(!$Type) { $Type = 'w.Title'; } if (!$Type) {
$Type = 'w.Title';
}
$Order = $OrderTable[$_GET['order']]; $Order = $OrderTable[$_GET['order']];
if(!$Order) { $Order = 'ID'; } if (!$Order) {
$Order = 'ID';
}
$Way = $WayTable[$_GET['way']]; $Way = $WayTable[$_GET['way']];
if(!$Way) { $Way = 'DESC'; } if (!$Way) {
$Way = 'DESC';
}
$SQL = "SELECT SQL_CALC_FOUND_ROWS $SQL = "
w.ID, SELECT SQL_CALC_FOUND_ROWS
w.Title, w.ID,
w.Date, w.Title,
w.Author w.Date,
w.Author
FROM wiki_articles AS w FROM wiki_articles AS w
WHERE w.MinClassRead <= '".$LoggedUser['EffectiveClass']."'"; WHERE w.MinClassRead <= '".$LoggedUser['EffectiveClass']."'";
if($Search!='') { if ($Search != '') {
$SQL .= " AND $Type LIKE '%"; $SQL .= " AND $Type LIKE '%";
$SQL .= implode("%' AND $Type LIKE '%", $Words); $SQL .= implode("%' AND $Type LIKE '%", $Words);
$SQL .= "%' "; $SQL .= "%' ";
@ -76,21 +85,20 @@
<tr> <tr>
<td class="label"><strong>Search in:</strong></td> <td class="label"><strong>Search in:</strong></td>
<td> <td>
<input type="radio" name="type" value="Title" <? if($Type == 'w.Title') { echo 'checked="checked" '; }?>/> Title <input type="radio" name="type" value="Title" <? if ($Type == 'w.Title') { echo 'checked="checked" '; }?>/> Title
<input type="radio" name="type" value="Body" <? if($Type == 'w.Body') { echo 'checked="checked" '; }?>/> Body <input type="radio" name="type" value="Body" <? if ($Type == 'w.Body') { echo 'checked="checked" '; }?>/> Body
</td> </td>
<td class="label"><strong>Order by:</strong></td> <td class="label"><strong>Order by:</strong></td>
<td> <td>
<select name="order"> <select name="order">
<? <? foreach ($OrderVals as $Cur) { ?>
foreach($OrderVals as $Cur){ ?> <option value="<?=$Cur?>"<? if ($_GET['order'] == $Cur || (!$_GET['order'] && $Cur == 'Time')) { echo ' selected="selected"'; } ?>><?=$Cur?></option>
<option value="<?=$Cur?>"<? if($_GET['order'] == $Cur || (!$_GET['order'] && $Cur == 'Time')) { echo ' selected="selected"'; } ?>><?=$Cur?></option> <? } ?>
<? }?>
</select> </select>
<select name="way"> <select name="way">
<? foreach($WayVals as $Cur){ ?> <? foreach ($WayVals as $Cur) { ?>
<option value="<?=$Cur?>"<? if($_GET['way'] == $Cur || (!$_GET['way'] && $Cur == 'Descending')) { echo ' selected="selected"'; } ?>><?=$Cur?></option> <option value="<?=$Cur?>"<? if ($_GET['way'] == $Cur || (!$_GET['way'] && $Cur == 'Descending')) { echo ' selected="selected"'; } ?>><?=$Cur?></option>
<? }?> <? } ?>
</select> </select>
</td> </td>
</tr> </tr>
@ -105,7 +113,7 @@
<br /> <br />
<div class="linkbox"> <div class="linkbox">
<? <?
$Pages=Format::get_pages($Page,$NumResults,ARTICLES_PER_PAGE); $Pages = Format::get_pages($Page, $NumResults, ARTICLES_PER_PAGE);
echo $Pages; echo $Pages;
?> ?>
</div> </div>
@ -115,7 +123,7 @@
<td>Last updated on</td> <td>Last updated on</td>
<td>Last edited by</td> <td>Last edited by</td>
</tr> </tr>
<? while(list($ID, $Title, $Date, $UserID) = $DB->next_record()) {?> <? while (list($ID, $Title, $Date, $UserID) = $DB->next_record()) { ?>
<tr> <tr>
<td><a href="wiki.php?action=article&amp;id=<?=$ID?>"><?=$Title?></a></td> <td><a href="wiki.php?action=article&amp;id=<?=$ID?>"><?=$Title?></a></td>
<td><?=$Date?></td> <td><?=$Date?></td>

View File

@ -1,8 +1,8 @@
<? <?
authorize(); authorize();
$P=array(); $P = array();
$P=db_array($_POST); $P = db_array($_POST);
include(SERVER_ROOT.'/classes/class_validate.php'); include(SERVER_ROOT.'/classes/class_validate.php');
$Val = new VALIDATE; $Val = new VALIDATE;
@ -11,25 +11,33 @@
//$Val->SetFields('alias', '1','string','Please include at least 1 alias, the entire string should be between 2 and 100 characters.',array('maxlength'=>100, 'minlength'=>2)); //$Val->SetFields('alias', '1','string','Please include at least 1 alias, the entire string should be between 2 and 100 characters.',array('maxlength'=>100, 'minlength'=>2));
$Err = $Val->ValidateForm($_POST); $Err = $Val->ValidateForm($_POST);
if(!$Err) { if (!$Err) {
$DB->query("SELECT ID FROM wiki_articles WHERE Title='$P[title]'"); $DB->query("SELECT ID FROM wiki_articles WHERE Title='$P[title]'");
if($DB->record_count()>0) { if ($DB->record_count() > 0) {
list($ID) = $DB->next_record(); list($ID) = $DB->next_record();
$Err = 'An article with that name already exists <a href="wiki.php?action=article&amp;id='.$ID.'">here</a>.'; $Err = 'An article with that name already exists <a href="wiki.php?action=article&amp;id='.$ID.'">here</a>.';
} }
} }
if($Err) { if ($Err) {
error($Err); error($Err);
} }
if(check_perms('admin_manage_wiki')){ if (check_perms('admin_manage_wiki')) {
$Read=$_POST['minclassread']; $Read = $_POST['minclassread'];
$Edit=$_POST['minclassedit']; $Edit = $_POST['minclassedit'];
if(!is_number($Read)) { error(0); } //int? if (!is_number($Read)) {
if(!is_number($Edit)) { error(0); } error(0); //int?
if($Edit > $LoggedUser['EffectiveClass']){ error('You can\'t restrict articles above your own level'); } }
if($Edit < $Read){ $Edit = $Read; } //Human error fix. if (!is_number($Edit)) {
error(0);
}
if ($Edit > $LoggedUser['EffectiveClass']) {
error('You can\'t restrict articles above your own level');
}
if ($Edit < $Read) {
$Edit = $Read; //Human error fix.
}
} else { } else {
$Read=100; $Read=100;
$Edit=100; $Edit=100;
@ -42,12 +50,12 @@
$ArticleID = $DB->inserted_id(); $ArticleID = $DB->inserted_id();
//$NewAlias = $Alias->convert($_POST['alias']); //$NewAlias = $Alias->convert($_POST['alias']);
//if($NewAlias!=''){ //if ($NewAlias != '') {
// $DB->query("INSERT INTO wiki_aliases (Alias, ArticleID) VALUES ('$NewAlias', '$ArticleID')"); // $DB->query("INSERT INTO wiki_aliases (Alias, ArticleID) VALUES ('$NewAlias', '$ArticleID')");
//} //}
$TitleAlias = $Alias->convert($_POST['title']); $TitleAlias = $Alias->convert($_POST['title']);
if($TitleAlias!=$Alias) { if ($TitleAlias != $Alias) {
$DB->query("INSERT INTO wiki_aliases (Alias, ArticleID) VALUES ('".db_string($TitleAlias)."', '$ArticleID')"); $DB->query("INSERT INTO wiki_aliases (Alias, ArticleID) VALUES ('".db_string($TitleAlias)."', '$ArticleID')");
} }

View File

@ -4,40 +4,54 @@
include(SERVER_ROOT.'/classes/class_validate.php'); include(SERVER_ROOT.'/classes/class_validate.php');
$Val = new VALIDATE; $Val = new VALIDATE;
if(!is_number($_POST['id']) || $_POST['id'] == ''){ error(0); } if (!is_number($_POST['id']) || $_POST['id'] == '') {
error(0);
}
$Val->SetFields('title', '1','string','The title must be between 3 and 100 characters',array('maxlength'=>100, 'minlength'=>3)); $Val->SetFields('title', '1','string','The title must be between 3 and 100 characters',array('maxlength'=>100, 'minlength'=>3));
$Err = $Val->ValidateForm($_POST); $Err = $Val->ValidateForm($_POST);
$ArticleID=$_POST['id']; $ArticleID = $_POST['id'];
if($Err) { if ($Err) {
error($Err); error($Err);
} }
$P=array(); $P = array();
$P=db_array($_POST); $P = db_array($_POST);
$Article = $Alias->article($ArticleID); $Article = $Alias->article($ArticleID);
list($Revision, $Title, $Body, $CurRead, $CurEdit, $Date, $Author) = array_shift($Article); list($Revision, $Title, $Body, $CurRead, $CurEdit, $Date, $Author) = array_shift($Article);
if($CurEdit > $LoggedUser['EffectiveClass']){ error(403); } if ($CurEdit > $LoggedUser['EffectiveClass']) {
error(403);
if(check_perms('admin_manage_wiki')){
$Read=$_POST['minclassread'];
$Edit=$_POST['minclassedit'];
if(!is_number($Read)) { error(0); } //int?
if(!is_number($Edit)) { error(0); }
if($Edit > $LoggedUser['EffectiveClass']){ error('You can\'t restrict articles above your own level.'); }
if($Edit < $Read){ $Edit = $Read; } //Human error fix.
} }
$MyRevision=$_POST['revision']; if (check_perms('admin_manage_wiki')) {
if($MyRevision!=$Revision){ error('This article has already been modified from its original version.'); } $Read=$_POST['minclassread'];
$Edit=$_POST['minclassedit'];
if (!is_number($Read)) {
error(0); //int?
}
if (!is_number($Edit)) {
error(0);
}
if ($Edit > $LoggedUser['EffectiveClass']) {
error('You can\'t restrict articles above your own level.');
}
if ($Edit < $Read) {
$Edit = $Read; //Human error fix.
}
}
$MyRevision = $_POST['revision'];
if ($MyRevision != $Revision) {
error('This article has already been modified from its original version.');
}
$DB->query("INSERT INTO wiki_revisions (ID, Revision, Title, Body, Date, Author) VALUES ('".db_string($ArticleID)."', '".db_string($Revision)."', '".db_string($Title)."', '".db_string($Body)."', '".db_string($Date)."', '".db_string($Author)."')"); $DB->query("INSERT INTO wiki_revisions (ID, Revision, Title, Body, Date, Author) VALUES ('".db_string($ArticleID)."', '".db_string($Revision)."', '".db_string($Title)."', '".db_string($Body)."', '".db_string($Date)."', '".db_string($Author)."')");
$SQL = "UPDATE wiki_articles SET $SQL = "UPDATE wiki_articles SET
Revision='".db_string($Revision+1)."', Revision='".db_string($Revision + 1)."',
Title='$P[title]', Title='$P[title]',
Body='$P[body]',"; Body='$P[body]',";
if($Read && $Edit) { if ($Read && $Edit) {
$SQL .= "MinClassRead='$Read', $SQL .= "MinClassRead='$Read',
MinClassEdit='$Edit',"; MinClassEdit='$Edit',";
} }

View File

@ -1,17 +1,17 @@
<? <?
authorize(); authorize();
if(preg_match('/^https?:\/\/(www\.|ssl\.)?'.NONSSL_SITE_URL.'\/wiki\.php\?action=article\&id=([0-9]+)/i',$_POST['url'],$Match)){ if (preg_match('/^https?:\/\/(www\.|ssl\.)?'.NONSSL_SITE_URL.'\/wiki\.php\?action=article\&id=([0-9]+)/i',$_POST['url'],$Match)) {
$ArticleID=$Match[2]; $ArticleID = $Match[2];
} }
if (preg_match('/^https?:\/\/(www\.|ssl\.)?'.NONSSL_SITE_URL.'\/wiki\.php\?action=article\&name=(.+)/i',$_POST['url'],$Match)){ if (preg_match('/^https?:\/\/(www\.|ssl\.)?'.NONSSL_SITE_URL.'\/wiki\.php\?action=article\&name=(.+)/i',$_POST['url'],$Match)) {
$ArticleID = $Alias->to_id($Match[2]); $ArticleID = $Alias->to_id($Match[2]);
} }
if(!$ArticleID){ if (!$ArticleID) {
error('Unable to link alias to an article.'); error('Unable to link alias to an article.');
} }
$NewAlias = $Alias->convert($_POST['alias']); $NewAlias = $Alias->convert($_POST['alias']);
if($NewAlias!=''){ if ($NewAlias != '') {
$DB->query("INSERT INTO wiki_aliases (Alias, ArticleID) VALUES ('$NewAlias', '$ArticleID')"); $DB->query("INSERT INTO wiki_aliases (Alias, ArticleID) VALUES ('$NewAlias', '$ArticleID')");
$Alias->flush(); $Alias->flush();
} }