diff --git a/classes/ajax_start.php b/classes/ajax_start.php index 07e6de6e..a835b6e4 100644 --- a/classes/ajax_start.php +++ b/classes/ajax_start.php @@ -10,15 +10,17 @@ $SSL = ($_SERVER['SERVER_PORT'] === '443'); -if (isset($_COOKIE['session'])) { $LoginCookie=$Enc->decrypt($_COOKIE['session']); } -if(isset($LoginCookie)) { - list($SessionID, $UserID)=explode("|~|",$Enc->decrypt($LoginCookie)); +if (isset($_COOKIE['session'])) { + $LoginCookie = $Enc->decrypt($_COOKIE['session']); +} +if (isset($LoginCookie)) { + list($SessionID, $UserID) = explode("|~|",$Enc->decrypt($LoginCookie)); - if(!$UserID || !$SessionID) { + if (!$UserID || !$SessionID) { 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 $DB=NEW DB_MYSQL; //Load the database wrapper $DB->query("SELECT Enabled FROM users_main WHERE ID='$UserID'"); @@ -34,39 +36,50 @@ function error($Error) { } 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 return ($Str == strval(intval($Str)) ? true : false); } function display_str($Str) { - if ($Str!="") { - $Str=make_utf8($Str); - $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","&",$Str); + if ($Str != '') { + $Str = make_utf8($Str); + $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","&",$Str); $Replace = array( "'",'"',"<",">", '€','‚','ƒ','„','…','†','‡','ˆ','‰','Š','‹','Œ','Ž','‘','’','“','”','•','–','—','˜','™','š','›','œ','ž','Ÿ' ); - $With=array( + $With = array( ''','"','<','>', '€','‚','ƒ','„','…','†','‡','ˆ','‰','Š','‹','Œ','Ž','‘','’','“','”','•','–','—','˜','™','š','›','œ','ž','Ÿ' ); - $Str=str_replace($Replace,$With,$Str); + $Str = str_replace($Replace,$With,$Str); } return $Str; } function make_utf8($Str) { - if ($Str!="") { - if (is_utf8($Str)) { $Encoding="UTF-8"; } - if (empty($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); } + if ($Str != '') { + if (is_utf8($Str)) { + $Encoding = 'UTF-8'; + } + if (empty($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()) { foreach ($Array as $Key => $Val) { - if(!in_array($Key, $DontEscape)) { + if (!in_array($Key, $DontEscape)) { $Array[$Key] = display_str($Val); } } diff --git a/classes/class_alias.php b/classes/class_alias.php index 113fff38..2e57a2f6 100644 --- a/classes/class_alias.php +++ b/classes/class_alias.php @@ -9,16 +9,16 @@ function flush() { global $Cache, $DB; $DB->query("SELECT Alias, ArticleID FROM wiki_aliases"); $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) { global $Cache, $DB; $Aliases = $Cache->get_value('wiki_aliases'); - if(!$Aliases){ + if (!$Aliases) { $DB->query("SELECT Alias, ArticleID FROM wiki_aliases"); $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']; } @@ -38,8 +38,9 @@ function to_id($Alias) { function article($ArticleID, $Error = true) { global $Cache, $DB; $Contents = $Cache->get_value('wiki_article_'.$ArticleID); - if(!$Contents){ - $DB->query("SELECT + if (!$Contents) { + $DB->query(" + SELECT w.Revision, w.Title, w.Body, @@ -50,14 +51,16 @@ function article($ArticleID, $Error = true) { u.Username, GROUP_CONCAT(a.Alias), 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 users_main AS u ON u.ID=w.Author - WHERE w.ID='$ArticleID' - GROUP BY w.ID"); - if(!$DB->record_count() && $Error) { error(404); } + WHERE w.ID='$ArticleID' + GROUP BY w.ID"); + if (!$DB->record_count() && $Error) { + error(404); + } $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; } diff --git a/classes/class_artists_similar.php b/classes/class_artists_similar.php index aa2c5a9a..46dc7ea1 100644 --- a/classes/class_artists_similar.php +++ b/classes/class_artists_similar.php @@ -9,7 +9,7 @@ class ARTIST { var $y = 0; var $Similar = array(); - function ARTIST($ID='', $Name=''){ + function ARTIST($ID = '', $Name = '') { $this->ID = $ID; $this->NameLength = mb_strlen($Name, 'utf8'); $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))); } - function load_data($Data){ + function load_data($Data) { list($LastUpdated, $this->Name, $this->x, $this->y, $this->Artists, $this->Similar) = unserialize($Data); $this->Artists = unserialize($this->Artists); $this->Similar = unserialize($this->Similar); } - function set_up(){ - $this->x = ceil(WIDTH/2); - $this->y = ceil(HEIGHT/2); + function set_up() { + $this->x = ceil(WIDTH / 2); + $this->y = ceil(HEIGHT / 2); $this->xValues[$this->x] = $this->ID; $this->yValues[$this->y] = $this->ID; @@ -51,24 +51,24 @@ function set_up(){ $ArtistIDs = array(); $DB->query(" SELECT - s2.ArtistID, - ag.Name, - ass.Score + s2.ArtistID, + ag.Name, + ass.Score FROM artists_similar AS s1 - 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_group AS ag ON ag.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_group AS ag ON ag.ArtistID=s2.ArtistID WHERE s1.ArtistID=".$this->ID." ORDER BY ass.Score DESC LIMIT 14"); - if($DB->record_count() == 0){ + if ($DB->record_count() == 0) { return; } // Build into array. Each artist is its own object in $this->Artists - while(list($ArtistID, $Name, $Score) = $DB->next_record(MYSQLI_NUM, false)){ - if($Score<0){ + while (list($ArtistID, $Name, $Score) = $DB->next_record(MYSQLI_NUM, false)) { + if ($Score < 0) { continue; } $this->Artists[$ArtistID] = new ARTIST($ArtistID, $Name); @@ -78,40 +78,41 @@ function set_up(){ } // Get similarities between artists on the map - $DB->query("SELECT - s1.ArtistID, - s2.ArtistID + $DB->query(" + SELECT + s1.ArtistID, + s2.ArtistID FROM artists_similar AS s1 - 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_group AS a ON a.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_group AS a ON a.ArtistID=s2.ArtistID WHERE s1.ArtistID IN(".implode(',',$ArtistIDs).") - AND s2.ArtistID IN(".implode(',',$ArtistIDs).") + AND s2.ArtistID IN(".implode(',',$ArtistIDs).") "); // 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); } // Calculate decimal point scores between artists - foreach($this->Similar as $SimilarArtist) { + foreach ($this->Similar as $SimilarArtist) { list($ArtistID, $Similar) = array_values($SimilarArtist); $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']; } - if($this->Similar[$ArtistID]['Decimal'] > $this->LargestDecimal){ + if ($this->Similar[$ArtistID]['Decimal'] > $this->LargestDecimal) { $this->LargestDecimal = $this->Similar[$ArtistID]['Decimal']; } } reset($this->Artists); } - function set_positions(){ + function set_positions() { $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 // 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 // We create more very low x values because they're more likely to be skipped - for($i = 0; $i<=count($this->Artists)*4; $i++){ - if($Offset>=((WIDTH/4))){ - $Offset=$Offset%(WIDTH/4); + for ($i = 0; $i <= count($this->Artists) * 4; $i++) { + if ($Offset >= ((WIDTH / 4))) { + $Offset = $Offset % (WIDTH / 4); } - $Plus = $Root+$Offset; // Point on the right of the root - $Minus = abs($Root-$Offset); // Point on the left of the root + $Plus = $Root + $Offset; // Point on the right 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 - if($Minus>30){ - // $xValues[$Minus-30]=$Minus-30; + if ($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; - if($Artist->Displayed == true){ + if ($Artist->Displayed == true) { 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 $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 // (provided that there are enough in the other half to visually balance out) reset($Artist->Similar); - foreach($Artist->Similar as $SimilarArtist) { + foreach ($Artist->Similar as $SimilarArtist) { list($Artist2ID) = array_values($SimilarArtist); - if($this->Artists[$Artist2ID]) { - if($this->Artists[$Artist2ID]->x > (WIDTH/2) && ($NumRight-$NumLeft)<1){ + if ($this->Artists[$Artist2ID]) { + if ($this->Artists[$Artist2ID]->x > (WIDTH / 2) && ($NumRight-$NumLeft) < 1) { $Horizontal = 2; - } elseif($NumLeft-$NumRight<1) { + } elseif ($NumLeft - $NumRight < 1) { $Horizontal = 1; } break; @@ -183,21 +184,21 @@ function set_positions(){ shuffle($xValues); - while($xValue = array_shift($xValues)){ - if(abs($this->x - $xValue) <= $IdealDistance) { - if(hypot(abs($this->x - $xValue), ($this->y - 50)) > $IdealDistance - || 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))); + while ($xValue = array_shift($xValues)) { + if (abs($this->x - $xValue) <= $IdealDistance) { + if (hypot(abs($this->x - $xValue), ($this->y - 50)) > $IdealDistance + || 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))); //echo "Had to change x value for ".$Artist->Name." to ".$xValue."\n"; } // Found a match (Is close enough to the center to satisfy $IdealDistance), // Now it's time to choose which half to put it on - if(!$Horizontal) { + if (!$Horizontal) { // No similar artists displayed - $Horizontal = ($NumLeft<$NumRight) ? 1 : 2; + $Horizontal = ($NumLeft < $NumRight) ? 1 : 2; } - if($Horizontal == 2){ - $xValue = WIDTH-$xValue; + if ($Horizontal == 2) { + $xValue = WIDTH - $xValue; $NumRight++; } else { $NumLeft++; @@ -210,9 +211,9 @@ function set_positions(){ break; } } - if(!$xValue){ // Uh-oh, we were unable to choose an x value. - $xValue = ceil(sqrt(pow($IdealDistance, 2)/2)); - $xValue = (WIDTH/2)-$xValue; + if (!$xValue) { // Uh-oh, we were unable to choose an x value. + $xValue = ceil(sqrt(pow($IdealDistance, 2) / 2)); + $xValue = (WIDTH / 2) - $xValue; $Artist->x = $xValue; $this->xValues[$xValue] = $ArtistID; unset($xValues[$xValue]); @@ -225,11 +226,11 @@ function set_positions(){ // Now we pick if it should go on the top or bottom - if($NumTop>$NumBottom){ // Send it to the bottom half - $yValue=(HEIGHT/2)+$yValue; + if ($NumTop > $NumBottom) { // Send it to the bottom half + $yValue = (HEIGHT / 2) + $yValue; $NumBottom++; } else { - $yValue=(HEIGHT/2)-$yValue; + $yValue=(HEIGHT / 2) - $yValue; $NumTop++; } @@ -238,28 +239,28 @@ function set_positions(){ // $yValue is now a proper y coordinate // Now time to do some spacing out - if($yValue < 10){ - $yValue+=(10+abs($yValue))+rand(10,20); + if ($yValue < 10) { + $yValue += (10 + abs($yValue)) + rand(10,20); } - if($yValue > (HEIGHT - 10)){ - $yValue-=((HEIGHT/2)-rand(10,20)); + if ($yValue > (HEIGHT - 10)) { + $yValue -= ((HEIGHT / 2) - rand(10,20)); } $i = 1; - while($Conflict = $this->scan_array_range($this->yValues, abs($yValue-13), $yValue+13)) { - if($i > 10){ + while ($Conflict = $this->scan_array_range($this->yValues, abs($yValue - 13), $yValue + 13)) { + if ($i > 10) { 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=$Conflict + rand(10, 20); - if($yValue>HEIGHT-10){ - $yValue-=ceil(HEIGHT/2.5); - } elseif($yValue<10) { - $yValue+=ceil(HEIGHT/2.5); + $yValue = $Conflict + rand(10, 20); + if ($yValue > HEIGHT - 10) { + $yValue -= ceil(HEIGHT / 2.5); + } elseif ($yValue < 10) { + $yValue += ceil(HEIGHT / 2.5); } $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 // Pythagoras as fun! - function calculate_distance($SimilarityCoefficient, $Rootx, $Rooty){ + function calculate_distance($SimilarityCoefficient, $Rootx, $Rooty) { $MaxWidth = WIDTH - $Rootx; $MaxHeight = HEIGHT - $Rooty; - $x = $MaxWidth - ($SimilarityCoefficient*$MaxWidth*.01); // Possible x value - $y = $MaxHeight - ($SimilarityCoefficient*$MaxHeight); // Possible y value + $x = $MaxWidth - ($SimilarityCoefficient * $MaxWidth * 0.01); // Possible x value + $y = $MaxHeight - ($SimilarityCoefficient * $MaxHeight); // Possible y value $Hypot = hypot($Rootx - $x, $Rooty - $y); return $MaxWidth - $Hypot; } - function similarity($Score, $TotalArtistScore){ - return (pow(($Score/($TotalArtistScore+1)), (1/1))); + function similarity($Score, $TotalArtistScore) { + return (pow(($Score / ($TotalArtistScore + 1)), (1 / 1))); } - function scan_array_range($Array, $Start, $Finish){ - if($Start<0){ + function scan_array_range($Array, $Start, $Finish) { + if ($Start < 0) { die($Start); } - for ($i = $Start; $i<=$Finish; $i++){ - if(isset($Array[$i])){ + for ($i = $Start; $i <= $Finish; $i++) { + if (isset($Array[$i])) { return $i; } } return false; } - function write_artists(){ + function write_artists() { ?> -
+
Name?>
Artists as $Artist){ - if($Artist->ID == $this->ID){ + foreach ($this->Artists as $Artist) { + if ($Artist->ID == $this->ID) { continue; } - $xPosition = $Artist->x - $Artist->NameLength*4; - if($xPosition<0){ - $xPosition=3; + $xPosition = $Artist->x - $Artist->NameLength * 4; + if ($xPosition < 0) { + $xPosition = 3; $Artist->x = $xPosition; } $Decimal = $this->Similar[$Artist->ID]['Decimal']; - if($Decimal<0.2){ + if ($Decimal < 0.2) { $FontSize = 8; - } elseif($Decimal<0.3){ + } elseif ($Decimal < 0.3) { $FontSize = 9; - } elseif($Decimal<0.4){ + } elseif ($Decimal < 0.4) { $FontSize = 10; } else { $FontSize = 12; } ?> -
+
Name?>
Artists); } - function background_image(){ + function background_image() { global $Img; reset($this->Similar); - foreach($this->Similar as $SimilarArtist) { + foreach ($this->Similar as $SimilarArtist) { list($ArtistID, $Val) = array_values($SimilarArtist); $Artist = $this->Artists[$ArtistID]; $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); unset($Artist->Similar[$this->ID]); reset($Artist->Similar); - foreach($Artist->Similar as $SimilarArtist2) { + foreach ($Artist->Similar as $SimilarArtist2) { list($Artist2ID) = array_values($SimilarArtist2); - if($this->Artists[$Artist2ID]){ + if ($this->Artists[$Artist2ID]) { $Artist2 = $this->Artists[$Artist2ID]; $Img->line($Artist->x, $Artist->y, $Artist2->x, $Artist2->y,$Img->color(173,201,255)); unset($Artist2->Similar[$ArtistID]); @@ -362,13 +361,12 @@ function background_image(){ } reset($this->xValues); } - $Img->make_png(SERVER_ROOT.'/static/similar/'.$this->ID.'.png'); } - function dump(){ + function dump() { echo "Similarities:\n"; - foreach($this->Artists as $Artist){ + foreach ($this->Artists as $Artist) { echo $Artist->ID; echo ' - '; echo $Artist->Name; @@ -381,9 +379,5 @@ function dump(){ } } - - } - - ?> diff --git a/classes/class_feed.php b/classes/class_feed.php index bec42e7b..6bb88588 100644 --- a/classes/class_feed.php +++ b/classes/class_feed.php @@ -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. if ($Date == '') { - $Date = date("r"); + $Date = date('r'); } else { - $Date = date("r",strtotime($Date)); + $Date = date('r',strtotime($Date)); } $Site = $this->UseSSL ? 'https://'.SSL_SITE_URL : 'http://'.NONSSL_SITE_URL; $Item = "\t\t\n"; @@ -44,25 +44,25 @@ function item($Title, $Description, $Page, $Creator, $Comments='', $Category='', return $Item; } - function retrieve($CacheKey,$AuthKey,$PassKey) { + function retrieve($CacheKey, $AuthKey, $PassKey) { global $Cache; $Entries = $Cache->get_value($CacheKey); - if(!$Entries){ + if (!$Entries) { $Entries = array(); } else { - foreach($Entries as $Item){ + foreach ($Entries as $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; $Entries = $Cache->get_value($CacheKey,true); - if(!$Entries){ + if (!$Entries) { $Entries = array(); } else { - if(count($Entries)>=50) { + if (count($Entries) >= 50) { array_pop($Entries); } } diff --git a/classes/class_image.php b/classes/class_image.php index 13b402c4..1c6df30d 100644 --- a/classes/class_image.php +++ b/classes/class_image.php @@ -12,17 +12,17 @@ class IMAGE { function create($Width, $Height) { $this->Image = imagecreate($Width, $Height); $this->Font = SERVER_ROOT.'/classes/fonts/VERDANA.TTF'; - if(function_exists('imageantialias')){ + if (function_exists('imageantialias')) { 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); } - function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1){ - if($Thickness == 1){ + function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1) { + if ($Thickness == 1) { return imageline($this->Image, $x1, $y1, $x2, $y2, $Color); } $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 $a = $t / sqrt(1 + pow($k, 2)); $Points = array( - 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($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), ); imagefilledpolygon($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); } - 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); } - function make_png($FileName = NULL){ + function make_png($FileName = NULL) { return imagepng($this->Image, $FileName); } diff --git a/classes/class_invite_tree.php b/classes/class_invite_tree.php index 4a8791e4..eb9671e1 100644 --- a/classes/class_invite_tree.php +++ b/classes/class_invite_tree.php @@ -11,9 +11,9 @@ class INVITE_TREE { var $Visible = true; // Set things up - function INVITE_TREE($UserID, $Options = array()){ + function INVITE_TREE($UserID, $Options = array()) { $this->UserID = $UserID; - if($Options['visible'] === false){ + if ($Options['visible'] === false) { $this->Visible = false; } } @@ -54,7 +54,7 @@ function make_tree() { JOIN users_info AS ui ON ui.UserID=it.UserID WHERE TreeID=$TreeID AND TreePosition>$TreePosition". - ($MaxPosition ? " AND TreePosition<$MaxPosition" : "")." + ($MaxPosition ? " AND TreePosition<$MaxPosition" : '')." AND TreeLevel>$TreeLevel 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 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 $Count++; - if($TreeLevel > $MaxTreeLevel){ + if ($TreeLevel > $MaxTreeLevel) { $MaxTreeLevel = $TreeLevel; } - if($TreeLevel == $BaseTreeLevel){ + if ($TreeLevel == $BaseTreeLevel) { $Branches++; $TopLevelUpload += $Uploaded; $TopLevelDownload += $Downloaded; } $ClassSummary[$Class]++; - if($Enabled == 2){ + if ($Enabled == 2) { $DisabledCount++; } - if($Donor){ + if ($Donor) { $DonorCount++; } // Manage tree depth - if($TreeLevel > $PreviousTreeLevel){ - for($i = 0; $i<$TreeLevel-$PreviousTreeLevel; $i++){ echo "
  • "; } - } elseif($TreeLevel < $PreviousTreeLevel){ - for($i = 0; $i<$PreviousTreeLevel-$TreeLevel; $i++){ echo "
"; } - echo ""; - echo "
  • "; + if ($TreeLevel > $PreviousTreeLevel) { + for ($i = 0; $i < $TreeLevel - $PreviousTreeLevel; $i++) { + echo '
    • '; + } + } elseif ($TreeLevel < $PreviousTreeLevel) { + for ($i = 0; $i < $PreviousTreeLevel - $TreeLevel; $i++) { + echo '
    '; + } + echo '
  • '; + echo '
  • '; } else { - echo "
  • "; - echo "
  • "; + echo '
  • '; + echo '
  • '; } ?> @@ -140,9 +144,11 @@ function make_tree() { } $Tree = ob_get_clean(); - for($i = 0; $i<$PreviousTreeLevel-$OriginalTreeLevel; $i++){ $Tree .= "
  • \n"; } + for ($i = 0; $i < $PreviousTreeLevel - $OriginalTreeLevel; $i++) { + $Tree .= "\n"; + } - if($Count){ + if ($Count) { ?>

    This tree has entries, branches, and a depth of . @@ -150,20 +156,22 @@ function make_tree() { $ClassCount) { - if($ClassCount == 0) { continue; } + if ($ClassCount == 0) { + continue; + } $LastClass = Users::make_class_string($ClassID); - if($ClassCount>1) { - if($LastClass == "Torrent Celebrity") { + if ($ClassCount > 1) { + if ($LastClass == 'Torrent Celebrity') { $LastClass = 'Torrent Celebrities'; } else { $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); echo implode(', ', $ClassStrings); echo ' and '.$LastClass; @@ -172,16 +180,22 @@ function make_tree() { } echo '. '; echo $DisabledCount; - echo ($DisabledCount==1)?' user is':' users are'; + echo ($DisabledCount == 1) ? ' user is' : ' users are'; echo ' disabled ('; - if($DisabledCount == 0) { echo '0%)'; } - else { echo number_format(($DisabledCount/$Count)*100) . '%)';} + if ($DisabledCount == 0) { + echo '0%)'; + } else { + echo number_format(($DisabledCount / $Count) * 100) . '%)'; + } echo ', and '; echo $DonorCount; - echo ($DonorCount==1)?' user has':' users have'; + echo ($DonorCount == 1) ? ' user has' : ' users have'; echo ' donated ('; - if($DonorCount == 0) { echo '0%)'; } - else { echo number_format(($DonorCount/$Count)*100) . '%)';} + if ($DonorCount == 0) { + echo '0%)'; + } else { + echo number_format(($DonorCount / $Count) * 100) . '%)'; + } echo '.

    '; echo '

    '; @@ -196,22 +210,21 @@ function make_tree() { 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.

    '; + echo 'These numbers include the stats of paranoid users and will be factored into the invitation giving script.

    '; - if($ParanoidCount){ + if ($ParanoidCount) { echo '

    '; echo $ParanoidCount; - echo ($ParanoidCount==1)?' user (':' users ('; - echo number_format(($ParanoidCount/$Count)*100); + echo ($ParanoidCount == 1) ? ' user (' : ' users ('; + echo number_format(($ParanoidCount / $Count) * 100); echo '%) '; - echo ($ParanoidCount==1)?' is':' are'; + echo ($ParanoidCount == 1) ? ' is' : ' are'; 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 '

    '; } } - ?>
    diff --git a/classes/class_irc.php b/classes/class_irc.php index dc57705f..3a1897b0 100644 --- a/classes/class_irc.php +++ b/classes/class_irc.php @@ -76,7 +76,7 @@ public function disconnect() { public function get_channel() { preg_match('/.+ PRIVMSG ([^:]+) :.+/', $this->Data, $Channel); - if(preg_match('/#.+/',$Channel[1])) { + if (preg_match('/#.+/',$Channel[1])) { return $Channel[1]; } else { 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. protected function ip_check($IP,$Gline=false,$Channel=BOT_REPORT_CHAN) { global $Cache, $DB; - if(blacklisted_ip($IP)) { + if (blacklisted_ip($IP)) { $this->send_to($Channel, 'TOR IP Detected: '.$IP); if ($Gline) { $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); if ($Gline) { $this->send_raw('GLINE *@'.$IP.' 90d :IP Ban'); @@ -151,31 +151,31 @@ protected function listen() { global $Cache,$DB; $Cache->InternalCache = false; stream_set_timeout($this->Socket, 10000000000); - while($this->State == 1){ - if($this->Data = fgets($this->Socket, 256)) { + while ($this->State == 1) { + if ($this->Data = fgets($this->Socket, 256)) { //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); //} - if($this->Debug === true) { + if ($this->Debug === true) { $this->send_to(BOT_DEBUG_CHAN, $this->Data); } - if($this->Whois !== false) { + if ($this->Whois !== false) { $Exp = explode(' ',$this->Data); - if($Exp[1] == '307') { + if ($Exp[1] == '307') { $this->Identified[$this->Whois] = 1; $this->send_to($this->LastChan, "$this->Whois correctly identified as a real person!"); $this->Whois = false; $this->LastChan = false; - } elseif($Exp[6] == '/WHOIS') { + } elseif ($Exp[6] == '/WHOIS') { $this->Whois = false; } } - if(preg_match("/:([^!]+)![^\s]* QUIT.* /", $this->Data, $Nick)) { - if(isset($this->Identified[$Nick[1]])) { + if (preg_match("/:([^!]+)![^\s]* QUIT.* /", $this->Data, $Nick)) { + if (isset($this->Identified[$Nick[1]])) { unset($this->Identified[$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(); } - if(preg_match('/PING :(.+)/', $this->Data, $Ping)) { + if (preg_match('/PING :(.+)/', $this->Data, $Ping)) { $this->send_raw('PONG :'.$Ping[1]); } - if(preg_match('/.*PRIVMSG #.*/',$this->Data)) { + if (preg_match('/.*PRIVMSG #.*/',$this->Data)) { $this->channel_events(); } - if(preg_match("/.* PRIVMSG ".BOT_NICK." .*/",$this->Data)) { + if (preg_match("/.* PRIVMSG ".BOT_NICK." .*/",$this->Data)) { $this->query_events(); } } - if($this->Listened = @socket_accept($this->ListenSocket)) { + if ($this->Listened = @socket_accept($this->ListenSocket)) { $this->listener_events(); } diff --git a/classes/class_mysql.php b/classes/class_mysql.php index ac330b5d..4a455c68 100644 --- a/classes/class_mysql.php +++ b/classes/class_mysql.php @@ -53,7 +53,7 @@ * 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; } ----- @@ -310,7 +310,7 @@ function to_array($Key = false, $Type = MYSQLI_BOTH, $Escape = true) { if ($Key !== false) { $Return[$Row[$Key]] = $Row; } else { - $Return[]=$Row; + $Return[] = $Row; } } 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 function collect($Key, $Escape = true) { $Return = array(); - while($Row = mysqli_fetch_array($this->QueryID)){ + while ($Row = mysqli_fetch_array($this->QueryID)) { $Return[] = $Escape ? display_str($Row[$Key]) : $Row[$Key]; } mysqli_data_seek($this->QueryID, 0); return $Return; } - function set_query_id(&$ResultSet){ + function set_query_id(&$ResultSet) { $this->QueryID = $ResultSet; $this->Row = 0; } diff --git a/classes/class_text.php b/classes/class_text.php index e8bac564..9b0eb5cb 100644 --- a/classes/class_text.php +++ b/classes/class_text.php @@ -185,7 +185,9 @@ private function valid_url ($Str, $Extension = '', $Inline = false) { public function local_url ($Str) { $URLInfo = parse_url($Str); - if (!$URLInfo) { return false; } + if (!$URLInfo) { + return false; + } $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 ($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] 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]); ++$ArrayPos; continue; @@ -299,7 +301,7 @@ private function parse ($Str) { } // 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]) @@ -338,19 +340,19 @@ private function parse ($Str) { // We're in a list. Find where it ends $NewLine = $i; do { // Look for \n[*] - $NewLine = strpos($Str, "\n", $NewLine+1); - } while ($NewLine!== false && substr($Str, $NewLine+1, 3) == '['.$TagName.']'); + $NewLine = strpos($Str, "\n", $NewLine + 1); + } while ($NewLine !== false && substr($Str, $NewLine + 1, 3) == '['.$TagName.']'); $CloseTag = $NewLine; if ($CloseTag === false) { // block finishes with list $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. } else { //5b) If it's a normal tag, it may have versions of itself nested inside - $CloseTag = $i-1; - $InTagPos = $i-1; + $CloseTag = $i - 1; + $InTagPos = $i - 1; $NumInOpens = 0; $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 // (as the first close tag won't do - it's been opened again) do { - $CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag+1); + $CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag + 1); if ($CloseTag === false) { $CloseTag = $Len; break; @@ -373,7 +375,7 @@ private function parse ($Str) { } // 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) { break; } else { @@ -385,9 +387,9 @@ private function parse ($Str) { // 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]; $text = ''; if ($n < 5 && $n > 0) { - $e = str_repeat('=', $matches[2]+1); + $e = str_repeat('=', $matches[2] + 1); $text = $e . $matches[3] . $e; } return $text; @@ -512,7 +514,9 @@ public function parse_toc ($Min = 3) foreach ($this->Headlines as $t) { $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); $list .= sprintf('
  • %1$s', $t[1], $t[2]); $level = $t[0]; @@ -551,7 +555,7 @@ private function headline_level (&$ItemLevel, &$Level, &$List, $i, &$Offset) $List .= '
  • ' . str_repeat('', $diff); } elseif ($ItemLevel > $Level) { $diff = $ItemLevel - $Level; - if ($Offset > 0) $List .= str_repeat('
    1. ', $Offset-2); + if ($Offset > 0) $List .= str_repeat('
      1. ', $Offset - 2); if ($ItemLevel > 1) { $List .= $i === 0 ? '
      2. ' : ''; @@ -565,7 +569,9 @@ private function headline_level (&$ItemLevel, &$Level, &$List, $i, &$Offset) private function to_html ($Array) { global $SSL; $this->Levels++; - if ($this->Levels>10) { return $Block['Val']; } // Hax prevention + if ($this->Levels > 10) { + return $Block['Val']; + } // Hax prevention $Str = ''; 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); } else { $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('%2$s', ($Block['Attr']+2), $text, $id); + $Str .= sprintf('%2$s', ($Block['Attr'] + 2), $text, $id); $this->HeadlineID++; } break; @@ -685,7 +693,7 @@ private function to_html ($Array) { $this->NoImg++; // No images inside quote tags $this->InQuotes++; 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])) { $PostID = trim($Exploded[1]); $Str.=''.$Exploded[0].' wrote: '; @@ -718,7 +726,7 @@ private function to_html ($Array) { } break; case 'img': - if ($this->NoImg>0 && $this->valid_url($Block['Val'])) { + if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) { $Str.=''.$Block['Val'].' (image)'; break; } @@ -737,7 +745,7 @@ private function to_html ($Array) { break; case 'aud': - if ($this->NoImg>0 && $this->valid_url($Block['Val'])) { + if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) { $Str.=''.$Block['Val'].' (audio)'; break; } diff --git a/classes/class_text2.php b/classes/class_text2.php index 3d395c67..89d7d485 100644 --- a/classes/class_text2.php +++ b/classes/class_text2.php @@ -54,7 +54,7 @@ class TEXT_2 { private $Levels = 0; // If images should be turned into URLs function __construct() { - foreach($this->Smileys as $Key=>$Val) { + foreach ($this->Smileys as $Key=>$Val) { $this->Smileys[$Key] = ''; } reset($this->Smileys); @@ -110,7 +110,7 @@ function valid_url($Str, $Extension = '', $Inline = false) { $Regex .= '(:[0-9]{1,5})?'; // port $Regex .= '\/?'; // slash? $Regex .= '(\/?[0-9a-z\-_.,&=@~%\/:;()+|!#]+)*'; // /file - if(!empty($Extension)) { + if (!empty($Extension)) { $Regex.=$Extension; } @@ -129,16 +129,16 @@ function valid_url($Str, $Extension = '', $Inline = false) { function local_url($Str) { $URLInfo = parse_url($Str); - if(!$URLInfo) { return false; } + if (!$URLInfo) { return false; } $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($Host == NONSSL_SITE_URL || $Host == SSL_SITE_URL || $Host == 'www.'.NONSSL_SITE_URL) { - if(preg_match('/(\S+\.)*'.NONSSL_SITE_URL.'/', $Host)) { + //if ($Host == NONSSL_SITE_URL || $Host == SSL_SITE_URL || $Host == 'www.'.NONSSL_SITE_URL) { + if (preg_match('/(\S+\.)*'.NONSSL_SITE_URL.'/', $Host)) { $URL = $URLInfo['path']; - if(!empty($URLInfo['query'])) { + if (!empty($URLInfo['query'])) { $URL.='?'.$URLInfo['query']; } - if(!empty($URLInfo['fragment'])) { + if (!empty($URLInfo['fragment'])) { $URL.='#'.$URLInfo['fragment']; } return $URL; @@ -192,7 +192,7 @@ function parse($Str) { $Array = array(); $ArrayPos = 0; - while($i<$Len) { + while ($i < $Len) { $Block = ''; // 1) Find and parse the next tag (regex) @@ -215,7 +215,7 @@ function parse($Str) { $MaxAttribs = $this->ValidTags[$TagName]; // 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; } @@ -231,10 +231,10 @@ function parse($Str) { || (strpos($Attrib, "'") !== false) || (strpos($Attrib, "\"") !== false)) { $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 foreach ($this->ValidTags as $PossibleTag=>$_) { - if (strpos($Attrib, "[".$PossibleTag) !== false) { + if (strpos($Attrib, '['.$PossibleTag) !== false) { $IsTag = 0; } } @@ -246,8 +246,8 @@ function parse($Str) { if (!$IsTag) { // 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])); - $i=$TagPos+strlen($Tag[0][0]); + $Array[$ArrayPos] = substr($Str, $i, ($TagPos - $i) + strlen($Tag[0][0])); + $i = $TagPos + strlen($Tag[0][0]); ++$ArrayPos; continue; } @@ -255,17 +255,17 @@ function parse($Str) { } // 2) If there aren't any tags left, write everything remaining to a block - if(!$IsTag) { + if (!$IsTag) { // No more tags $Array[$ArrayPos] = substr($Str, $i); break; } // 3) If the next tag isn't where the pointer is, write everything up to there to a text block. - if($TagPos>$i) { - $Array[$ArrayPos] = substr($Str, $i, $TagPos-$i); + if ($TagPos > $i) { + $Array[$ArrayPos] = substr($Str, $i, $TagPos - $i); ++$ArrayPos; - $i=$TagPos; + $i = $TagPos; } // 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 [*] - if($TagName == 'img' && $HasAttrib) { //[img=...] + if ($TagName == 'img' && $HasAttrib) { //[img=...] $Block = ''; // Nothing inside this tag // 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 $CloseTag = strcspn($Str, " \n\r", $i); - if($CloseTag === false) { // block finishes with URL + if ($CloseTag === false) { // block finishes with URL $CloseTag = $Len; } - if(preg_match('/[!;,.?:]+$/',substr($Str, $i, $CloseTag), $Match)) { + if (preg_match('/[!;,.?:]+$/',substr($Str, $i, $CloseTag), $Match)) { $CloseTag -= strlen($Match[0]); } $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--; $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 // Therefore, we use += instead of the = everywhere else $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 - } elseif($TagName == '*') { + } elseif ($TagName == '*') { // We're in a list. Find where it ends $NewLine = $i; do { // Look for \n[*] - $NewLine = strpos($Str, "\n", $NewLine+1); - } while($NewLine!== false && substr($Str, $NewLine+1, 3) == '[*]'); + $NewLine = strpos($Str, "\n", $NewLine + 1); + } while ($NewLine !== false && substr($Str, $NewLine + 1, 3) == '[*]'); $CloseTag = $NewLine; - if($CloseTag === false) { // block finishes with list + if ($CloseTag === false) { // block finishes with list $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. } else { //5b) If it's a normal tag, it may have versions of itself nested inside @@ -325,7 +325,7 @@ function parse($Str) { $NumInCloses = -1; $InOpenRegex = '/\[('.$TagName.')'; - if($MaxAttribs>0) { + if ($MaxAttribs > 0) { $InOpenRegex.="(=[^\n'\"\[\]]+)?"; } $InOpenRegex.='\]/i'; @@ -335,7 +335,7 @@ function parse($Str) { // (as the first close tag won't do - it's been opened again) do { $CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag+1); - if($CloseTag === false) { + if ($CloseTag === false) { $CloseTag = $Len; break; } else { @@ -343,21 +343,21 @@ function parse($Str) { } // Is there another open tag inside this one? - $OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos+1); - if(!$OpenTag || $InTag[0][1]>$CloseTag) { + $OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos + 1); + if (!$OpenTag || $InTag[0][1] > $CloseTag) { break; } else { $InTagPos = $InTag[0][1]; $NumInOpens++; } - } while($NumInOpens>$NumInCloses); + } while ($NumInOpens > $NumInCloses); // 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; case 'url': $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'=>''); } else { $Array[$ArrayPos] = array('Type'=>'url', 'Attr'=>$Attrib, 'Val'=>$this->parse($Block)); @@ -379,7 +379,7 @@ function parse($Str) { break; case 'img': case 'image': - if(empty($Block)) { + if (empty($Block)) { $Block = $Attrib; } $Array[$ArrayPos] = array('Type'=>'img', 'Val'=>$Block); @@ -387,7 +387,7 @@ function parse($Str) { case 'aud': case 'mp3': case 'audio': - if(empty($Block)) { + if (empty($Block)) { $Block = $Attrib; } $Array[$ArrayPos] = array('Type'=>'aud', 'Val'=>$Block); @@ -417,7 +417,7 @@ function parse($Str) { case '*': $Array[$ArrayPos] = array('Type'=>'list'); $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)); } break; @@ -425,14 +425,14 @@ function parse($Str) { $ArrayPos--; break; // n serves only to disrupt bbcode (backwards compatibility - use [pre]) default: - if($WikiLink == true) { + if ($WikiLink == true) { $Array[$ArrayPos] = array('Type'=>'wiki','Val'=>$TagName); } else { // Basic tags, like [b] or [size=5] $Array[$ArrayPos] = array('Type'=>$TagName, 'Val'=>$this->parse($Block)); - if(!empty($Attrib) && $MaxAttribs>0) { + if (!empty($Attrib) && $MaxAttribs > 0) { $Array[$ArrayPos]['Attr'] = strtolower($Attrib); } } @@ -445,11 +445,13 @@ function parse($Str) { function to_html($Array) { $this->Levels++; - if($this->Levels>10) { return $Block['Val']; } // Hax prevention + if ($this->Levels > 10) { + return $Block['Val']; + } // Hax prevention $Str = ''; - foreach($Array as $Block) { - if(is_string($Block)) { + foreach ($Array as $Block) { + if (is_string($Block)) { $Str.=$this->smileys($Block); continue; } @@ -489,7 +491,7 @@ function to_html($Array) { break; case 'list': $Str.='
          '; - foreach($Block['Val'] as $Line) { + foreach ($Block['Val'] as $Line) { $Str.='
        • '.$this->to_html($Line).'
        • '; } @@ -497,7 +499,7 @@ function to_html($Array) { break; case 'align': $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]'; } else { $Str.='
          '.$this->to_html($Block['Val']).'
          '; @@ -506,7 +508,7 @@ function to_html($Array) { case 'color': case 'colour': $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]'; } else { $Str.=''.$this->to_html($Block['Val']).''; @@ -515,7 +517,7 @@ function to_html($Array) { case 'inlinesize': case 'size': $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]'; } else { $Str.=''.$this->to_html($Block['Val']).''; @@ -523,7 +525,7 @@ function to_html($Array) { break; case 'quote': $this->NoImg++; // No images inside quote tags - if(!empty($Block['Attr'])) { + if (!empty($Block['Attr'])) { $Str.=''.$this->to_html($Block['Attr']).' wrote: '; } $Str.='
          '.$this->to_html($Block['Val']).'
          '; @@ -534,14 +536,14 @@ function to_html($Array) { $Str.=''; break; case 'img': - if($this->NoImg>0 && $this->valid_url($Block['Val'])) { + if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) { $Str.=''.$Block['Val'].' (image)'; 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]'; } else { - if(check_perms('site_proxy_images')) { + if (check_perms('site_proxy_images')) { $Str.=''.$Block['Val'].''; } else { $Str.=''.$Block['Val'].''; @@ -550,11 +552,11 @@ function to_html($Array) { break; case 'aud': - if($this->NoImg>0 && $this->valid_url($Block['Val'])) { + if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) { $Str.=''.$Block['Val'].' (audio)'; break; } - if(!$this->valid_url($Block['Val'], '\.(mp3|ogg|wav)')) { + if (!$this->valid_url($Block['Val'], '\.(mp3|ogg|wav)')) { $Str.='[aud]'.$Block['Val'].'[/aud]'; } else { //TODO: Proxy this for staff? @@ -564,7 +566,7 @@ function to_html($Array) { case 'url': // Make sure the URL has a label - if(empty($Block['Val'])) { + if (empty($Block['Val'])) { $Block['Val'] = $Block['Attr']; $NoName = true; // If there isn't a Val for this } else { @@ -572,12 +574,14 @@ function to_html($Array) { $NoName = false; } - if(!$this->valid_url($Block['Attr'])) { + if (!$this->valid_url($Block['Attr'])) { $Str.='[url='.$Block['Attr'].']'.$Block['Val'].'[/url]'; } else { $LocalURL = $this->local_url($Block['Attr']); - if($LocalURL) { - if($NoName) { $Block['Val'] = substr($LocalURL,1); } + if ($LocalURL) { + if ($NoName) { + $Block['Val'] = substr($LocalURL,1); + } $Str.=''.$Block['Val'].''; } else { $Str.=''.$Block['Val'].''; @@ -586,7 +590,7 @@ function to_html($Array) { break; case 'inlineurl': - if(!$this->valid_url($Block['Attr'], '', true)) { + if (!$this->valid_url($Block['Attr'], '', true)) { $Array = $this->parse($Block['Attr']); $Block['Attr'] = $Array; $Str.=$this->to_html($Block['Attr']); @@ -594,7 +598,7 @@ function to_html($Array) { else { $LocalURL = $this->local_url($Block['Attr']); - if($LocalURL) { + if ($LocalURL) { $Str.=''.substr($LocalURL,1).''; } else { $Str.=''.$Block['Attr'].''; @@ -611,8 +615,8 @@ function to_html($Array) { function raw_text($Array) { $Str = ''; - foreach($Array as $Block) { - if(is_string($Block)) { + foreach ($Array as $Block) { + if (is_string($Block)) { $Str.=$Block; continue; } @@ -641,14 +645,14 @@ function raw_text($Array) { $Str.=$Block['Val']; break; case 'list': - foreach($Block['Val'] as $Line) { + foreach ($Block['Val'] as $Line) { $Str.='*'.$this->raw_text($Line); } break; case 'url': // Make sure the URL has a label - if(empty($Block['Val'])) { + if (empty($Block['Val'])) { $Block['Val'] = $Block['Attr']; } else { $Block['Val'] = $this->raw_text($Block['Val']); @@ -658,7 +662,7 @@ function raw_text($Array) { break; case 'inlineurl': - if(!$this->valid_url($Block['Attr'], '', true)) { + if (!$this->valid_url($Block['Attr'], '', true)) { $Array = $this->parse($Block['Attr']); $Block['Attr'] = $Array; $Str.=$this->raw_text($Block['Attr']); @@ -675,7 +679,7 @@ function raw_text($Array) { function smileys($Str) { global $LoggedUser; - if(!empty($LoggedUser['DisableSmileys'])) { + if (!empty($LoggedUser['DisableSmileys'])) { return $Str; } $Str = strtr($Str, $this->Smileys); diff --git a/classes/class_text3.php b/classes/class_text3.php index bebfd56f..e0f2e7a3 100644 --- a/classes/class_text3.php +++ b/classes/class_text3.php @@ -51,7 +51,7 @@ class TEXT_3 { private $Levels = 0; // If images should be turned into URLs function __construct() { - foreach($this->Smileys as $Key=>$Val) { + foreach ($this->Smileys as $Key=>$Val) { $this->Smileys[$Key] = ''; } reset($this->Smileys); @@ -102,7 +102,7 @@ function valid_url($Str, $Extension = '', $Inline = false) { $Regex .= '(:[0-9]{1,5})?'; // port $Regex .= '\/?'; // slash? $Regex .= '(\/?[0-9a-z\-_.,&=@~%\/:;()+!#]+)*'; // /file - if(!empty($Extension)) { + if (!empty($Extension)) { $Regex.=$Extension; } @@ -121,16 +121,18 @@ function valid_url($Str, $Extension = '', $Inline = false) { function local_url($Str) { $URLInfo = parse_url($Str); - if(!$URLInfo) { return false; } + if (!$URLInfo) { + return false; + } $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($Host == NONSSL_SITE_URL || $Host == SSL_SITE_URL || $Host == 'www.'.NONSSL_SITE_URL) { - if(preg_match('/(\S+\.)*'.NONSSL_SITE_URL.'/', $Host)) { + //if ($Host == NONSSL_SITE_URL || $Host == SSL_SITE_URL || $Host == 'www.'.NONSSL_SITE_URL) { + if (preg_match('/(\S+\.)*'.NONSSL_SITE_URL.'/', $Host)) { $URL = $URLInfo['path']; - if(!empty($URLInfo['query'])) { + if (!empty($URLInfo['query'])) { $URL.='?'.$URLInfo['query']; } - if(!empty($URLInfo['fragment'])) { + if (!empty($URLInfo['fragment'])) { $URL.='#'.$URLInfo['fragment']; } return $URL; @@ -184,7 +186,7 @@ function parse($Str) { $Array = array(); $ArrayPos = 0; - while($i<$Len) { + while ($i < $Len) { $Block = ''; // 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); // 1a) If there aren't any tags left, write everything remaining to a block - if(!$IsTag) { + if (!$IsTag) { // No more tags $Array[$ArrayPos] = substr($Str, $i); 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. $TagPos = $Tag[0][1]; - if($TagPos>$i) { - $Array[$ArrayPos] = substr($Str, $i, $TagPos-$i); + if ($TagPos > $i) { + $Array[$ArrayPos] = substr($Str, $i, $TagPos - $i); ++$ArrayPos; - $i=$TagPos; + $i = $TagPos; } // 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; $TagName = substr($Tag[4][0], 2, -2); $Attrib = ''; @@ -216,9 +218,9 @@ function parse($Str) { $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] - if(!isset($this->ValidTags[$TagName])) { - $Array[$ArrayPos] = substr($Str, $i, ($TagPos-$i)+strlen($Tag[0][0])); - $i=$TagPos+strlen($Tag[0][0]); + if (!isset($this->ValidTags[$TagName])) { + $Array[$ArrayPos] = substr($Str, $i, ($TagPos - $i) + strlen($Tag[0][0])); + $i = $TagPos + strlen($Tag[0][0]); ++$ArrayPos; continue; } @@ -226,15 +228,15 @@ function parse($Str) { $MaxAttribs = $this->ValidTags[$TagName]; // 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); } else { - $Attrib=''; + $Attrib = ''; } } // 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]) @@ -244,21 +246,21 @@ function parse($Str) { //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 // 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 $CloseTag = strcspn($Str, " \n\r", $i); - if($CloseTag === false) { // block finishes with URL + if ($CloseTag === false) { // block finishes with URL $CloseTag = $Len; } - if(preg_match('/[!;,.?:]+$/',substr($Str, $i, $CloseTag), $Match)) { + if (preg_match('/[!;,.?:]+$/',substr($Str, $i, $CloseTag), $Match)) { $CloseTag -= strlen($Match[0]); } $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--; $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 // Therefore, we use += instead of the = everywhere else $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 - } elseif($TagName == '*') { + } elseif ($TagName == '*') { // We're in a list. Find where it ends $NewLine = $i; do { // Look for \n[*] - $NewLine = strpos($Str, "\n", $NewLine+1); - } while($NewLine!== false && substr($Str, $NewLine+1, 3) == '[*]'); + $NewLine = strpos($Str, "\n", $NewLine + 1); + } while ($NewLine !== false && substr($Str, $NewLine+1, 3) == '[*]'); $CloseTag = $NewLine; - if($CloseTag === false) { // block finishes with list + if ($CloseTag === false) { // block finishes with list $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. } else { //5b) If it's a normal tag, it may have versions of itself nested inside @@ -290,7 +292,7 @@ function parse($Str) { $NumInCloses = -1; $InOpenRegex = '/\[('.$TagName.')'; - if($MaxAttribs>0) { + if ($MaxAttribs > 0) { $InOpenRegex.="(=[^\n'\"\[\]]+)?"; } $InOpenRegex.='\]/i'; @@ -300,7 +302,7 @@ function parse($Str) { // (as the first close tag won't do - it's been opened again) do { $CloseTag = stripos($Str, '[/'.$TagName.']', $CloseTag+1); - if($CloseTag === false) { + if ($CloseTag === false) { $CloseTag = $Len; break; } else { @@ -308,8 +310,8 @@ function parse($Str) { } // Is there another open tag inside this one? - $OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos+1); - if(!$OpenTag || $InTag[0][1]>$CloseTag) { + $OpenTag = preg_match($InOpenRegex, $Str, $InTag, PREG_OFFSET_CAPTURE, $InTagPos + 1); + if (!$OpenTag || $InTag[0][1] > $CloseTag) { break; } else { $InTagPos = $InTag[0][1]; @@ -333,7 +335,7 @@ function parse($Str) { break; case 'url': $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'=>''); } else { $Array[$ArrayPos] = array('Type'=>'url', 'Attr'=>$Attrib, 'Val'=>$this->parse($Block)); @@ -344,7 +346,7 @@ function parse($Str) { break; case 'img': case 'image': - if(empty($Block)) { + if (empty($Block)) { $Block = $Attrib; } $Array[$ArrayPos] = array('Type'=>'img', 'Val'=>$Block); @@ -352,7 +354,7 @@ function parse($Str) { case 'aud': case 'mp3': case 'audio': - if(empty($Block)) { + if (empty($Block)) { $Block = $Attrib; } $Array[$ArrayPos] = array('Type'=>'aud', 'Val'=>$Block); @@ -381,7 +383,7 @@ function parse($Str) { case '*': $Array[$ArrayPos] = array('Type'=>'list'); $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)); } break; @@ -389,14 +391,14 @@ function parse($Str) { $ArrayPos--; break; // n serves only to disrupt bbcode (backwards compatibility - use [pre]) default: - if($WikiLink == true) { + if ($WikiLink == true) { $Array[$ArrayPos] = array('Type'=>'wiki','Val'=>$TagName); } else { // Basic tags, like [b] or [size=5] $Array[$ArrayPos] = array('Type'=>$TagName, 'Val'=>$this->parse($Block)); - if(!empty($Attrib) && $MaxAttribs>0) { + if (!empty($Attrib) && $MaxAttribs>0) { $Array[$ArrayPos]['Attr'] = strtolower($Attrib); } } @@ -409,11 +411,11 @@ function parse($Str) { function to_html($Array) { $this->Levels++; - if($this->Levels>10) { return $Block['Val']; } // Hax prevention + if ($this->Levels>10) { return $Block['Val']; } // Hax prevention $Str = ''; - foreach($Array as $Block) { - if(is_string($Block)) { + foreach ($Array as $Block) { + if (is_string($Block)) { $Str.=$this->smileys($Block); continue; } @@ -450,7 +452,7 @@ function to_html($Array) { break; case 'list': $Str.='
            '; - foreach($Block['Val'] as $Line) { + foreach ($Block['Val'] as $Line) { $Str.='
          • '.$this->to_html($Line).'
          • '; } @@ -458,7 +460,7 @@ function to_html($Array) { break; case 'align': $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]'; } else { $Str.='
            '.$this->to_html($Block['Val']).'
            '; @@ -467,7 +469,7 @@ function to_html($Array) { case 'color': case 'colour': $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]'; } else { $Str.=''.$this->to_html($Block['Val']).''; @@ -476,7 +478,7 @@ function to_html($Array) { case 'inlinesize': case 'size': $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]'; } else { $Str.=''.$this->to_html($Block['Val']).''; @@ -484,7 +486,7 @@ function to_html($Array) { break; case 'quote': $this->NoImg++; // No images inside quote tags - if(!empty($Block['Attr'])) { + if (!empty($Block['Attr'])) { $Str.=''.$this->to_html($Block['Attr']).' wrote: '; } $Str.='
            '.$this->to_html($Block['Val']).'
            '; @@ -495,14 +497,14 @@ function to_html($Array) { $Str.=''; break; case 'img': - if($this->NoImg>0 && $this->valid_url($Block['Val'])) { + if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) { $Str.=''.$Block['Val'].' (image)'; 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]'; } else { - if(check_perms('site_proxy_images')) { + if (check_perms('site_proxy_images')) { $Str.=''.$Block['Val'].''; } else { $Str.=''.$Block['Val'].''; @@ -511,11 +513,11 @@ function to_html($Array) { break; case 'aud': - if($this->NoImg>0 && $this->valid_url($Block['Val'])) { + if ($this->NoImg > 0 && $this->valid_url($Block['Val'])) { $Str.=''.$Block['Val'].' (audio)'; break; } - if(!$this->valid_url($Block['Val'], '\.(mp3|ogg|wav)')) { + if (!$this->valid_url($Block['Val'], '\.(mp3|ogg|wav)')) { $Str.='[aud]'.$Block['Val'].'[/aud]'; } else { //TODO: Proxy this for staff? @@ -525,7 +527,7 @@ function to_html($Array) { case 'url': // Make sure the URL has a label - if(empty($Block['Val'])) { + if (empty($Block['Val'])) { $Block['Val'] = $Block['Attr']; $NoName = true; // If there isn't a Val for this } else { @@ -533,12 +535,14 @@ function to_html($Array) { $NoName = false; } - if(!$this->valid_url($Block['Attr'])) { + if (!$this->valid_url($Block['Attr'])) { $Str.='[url='.$Block['Attr'].']'.$Block['Val'].'[/url]'; } else { $LocalURL = $this->local_url($Block['Attr']); - if($LocalURL) { - if($NoName) { $Block['Val'] = substr($LocalURL,1); } + if ($LocalURL) { + if ($NoName) { + $Block['Val'] = substr($LocalURL,1); + } $Str.=''.$Block['Val'].''; } else { $Str.=''.$Block['Val'].''; @@ -547,7 +551,7 @@ function to_html($Array) { break; case 'inlineurl': - if(!$this->valid_url($Block['Attr'], '', true)) { + if (!$this->valid_url($Block['Attr'], '', true)) { $Array = $this->parse($Block['Attr']); $Block['Attr'] = $Array; $Str.=$this->to_html($Block['Attr']); @@ -555,7 +559,7 @@ function to_html($Array) { else { $LocalURL = $this->local_url($Block['Attr']); - if($LocalURL) { + if ($LocalURL) { $Str.=''.substr($LocalURL,1).''; } else { $Str.=''.$Block['Attr'].''; @@ -572,8 +576,8 @@ function to_html($Array) { function raw_text($Array) { $Str = ''; - foreach($Array as $Block) { - if(is_string($Block)) { + foreach ($Array as $Block) { + if (is_string($Block)) { $Str.=$Block; continue; } @@ -601,14 +605,14 @@ function raw_text($Array) { $Str.=$Block['Val']; break; case 'list': - foreach($Block['Val'] as $Line) { + foreach ($Block['Val'] as $Line) { $Str.='*'.$this->raw_text($Line); } break; case 'url': // Make sure the URL has a label - if(empty($Block['Val'])) { + if (empty($Block['Val'])) { $Block['Val'] = $Block['Attr']; } else { $Block['Val'] = $this->raw_text($Block['Val']); @@ -618,7 +622,7 @@ function raw_text($Array) { break; case 'inlineurl': - if(!$this->valid_url($Block['Attr'], '', true)) { + if (!$this->valid_url($Block['Attr'], '', true)) { $Array = $this->parse($Block['Attr']); $Block['Attr'] = $Array; $Str.=$this->raw_text($Block['Attr']); @@ -635,7 +639,7 @@ function raw_text($Array) { function smileys($Str) { global $LoggedUser; - if(!empty($LoggedUser['DisableSmileys'])) { + if (!empty($LoggedUser['DisableSmileys'])) { return $Str; } $Str = strtr($Str, $this->Smileys); diff --git a/classes/class_tools.php b/classes/class_tools.php index e4e75900..4ffa2406 100644 --- a/classes/class_tools.php +++ b/classes/class_tools.php @@ -23,7 +23,7 @@ public static function site_ban_ip($IP) { return true; } } - + return false; } @@ -95,7 +95,7 @@ public static function get_host_by_ip($IP) { public static function get_host_by_ajax($IP) { static $ID = 0; ++$ID; - return 'Resolving host...'; + return 'Resolving host...'; } @@ -137,7 +137,7 @@ public static function display_ip($IP) { public static function get_country_code_by_ajax($IP) { static $ID = 0; ++$ID; - return 'Resolving CC...'; + return 'Resolving CC...'; } @@ -154,16 +154,18 @@ public static function disable_users($UserIDs, $AdminComment, $BanReason = 1) { if (!is_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', - m.can_leech='0', - i.AdminComment = CONCAT('".sqltime()." - ".($AdminComment ? $AdminComment : 'Disabled by system')."\n\n', i.AdminComment), - i.BanDate='".sqltime()."', - i.BanReason='".$BanReason."', - i.RatioWatchDownload=".($BanReason == 2?'m.Downloaded':"'0'")." + m.can_leech='0', + i.AdminComment = CONCAT('".sqltime()." - ".($AdminComment ? $AdminComment : 'Disabled by system')."\n\n', i.AdminComment), + i.BanDate='".sqltime()."', + i.BanReason='".$BanReason."', + i.RatioWatchDownload=".($BanReason == 2 ? 'm.Downloaded' : "'0'")." WHERE m.ID IN(".implode(',',$UserIDs).") "); $Cache->decrement('stats_user_count',$DB->affected_rows()); - foreach($UserIDs as $UserID) { + foreach ($UserIDs as $UserID) { $Cache->delete_value('enabled_'.$UserID); $Cache->delete_value('user_info_'.$UserID); $Cache->delete_value('user_info_heavy_'.$UserID); diff --git a/classes/class_torrent.php b/classes/class_torrent.php index e0f9a29c..55ba4eda 100644 --- a/classes/class_torrent.php +++ b/classes/class_torrent.php @@ -68,8 +68,8 @@ class BENCODE2 { var $Pos = 1; // Pointer that indicates our position in the string var $Str = ''; // Torrent string - function __construct($Val, $IsParsed = false){ - if(!$IsParsed) { + function __construct($Val, $IsParsed = false) { + if (!$IsParsed) { $this->Str = $Val; $this->dec(); } else { @@ -78,20 +78,20 @@ function __construct($Val, $IsParsed = false){ } // Decode an element based on the type. The type is really just an indicator. - function decode($Type, $Key){ - if(is_number($Type)) { // Element is a string + function decode($Type, $Key) { + if (is_number($Type)) { // Element is a string // Get length of string $StrLen = $Type; - while($this->Str[$this->Pos+1]!=':'){ + while ($this->Str[$this->Pos + 1] != ':') { $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+=2; + $this->Pos += $StrLen; + $this->Pos += 2; - } elseif($Type == 'i') { // Element is an int + } elseif ($Type == 'i') { // Element is an int $this->Pos++; // 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 $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->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->Pos += $this->Val[$Key]->Pos; // Sort by key to respect spec @@ -118,12 +118,12 @@ function decode($Type, $Key){ } } - function encode($Val){ - if(is_int($Val)) { // Integer + function encode($Val) { + if (is_int($Val)) { // Integer return 'i'.$Val.'e'; - } elseif(is_string($Val)) { + } elseif (is_string($Val)) { return strlen($Val).':'.$Val; - } elseif(is_object($Val)) { + } elseif (is_object($Val)) { return $Val->enc(); } else { return 'fail'; @@ -132,7 +132,7 @@ function encode($Val){ } class BENCODE_LIST extends BENCODE2 { - function enc(){ + function enc() { if (empty($this->Val)) { return 'le'; } @@ -145,15 +145,15 @@ function enc(){ } // Decode a list - function dec(){ + function dec() { $Key = 0; // Array index $Length = strlen($this->Str); - while($this->Pos<$Length){ + while ($this->Pos < $Length) { $Type = $this->Str[$this->Pos]; // $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) - if($Type == 'e') { // End of list + if ($Type == 'e') { // End of list $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. return; @@ -169,7 +169,7 @@ function dec(){ } class BENCODE_DICT extends BENCODE2 { - function enc(){ + function enc() { if (empty($this->Val)) { return 'de'; } @@ -182,11 +182,11 @@ function enc(){ } // Decode a dictionary - function dec(){ + function dec() { $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; 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; @@ -197,19 +197,19 @@ function dec(){ $KeyLen = $this->Str[$this->Pos]; // 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++; $KeyLen.=$this->Str[$this->Pos]; } // $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 - $this->Pos+=2; + $this->Pos += 2; // Get the name of the key $Key = substr($this->Str, $this->Pos, $KeyLen); // Move the position past the key to the beginning of the element - $this->Pos+=$KeyLen; + $this->Pos += $KeyLen; $Type = $this->Str[$this->Pos]; // $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) diff --git a/classes/class_torrent_32bit.php b/classes/class_torrent_32bit.php index 707ec184..d36c7d62 100644 --- a/classes/class_torrent_32bit.php +++ b/classes/class_torrent_32bit.php @@ -77,8 +77,8 @@ class BENCODE2 { var $Pos = 1; // Pointer that indicates our position in the string var $Str = ''; // Torrent string - function __construct($Val, $IsParsed = false){ - if(!$IsParsed) { + function __construct($Val, $IsParsed = false) { + if (!$IsParsed) { $this->Str = $Val; $this->dec(); } else { @@ -87,20 +87,20 @@ function __construct($Val, $IsParsed = false){ } // Decode an element based on the type - function decode($Type, $Key){ - if(ctype_digit($Type)) { // Element is a string + function decode($Type, $Key) { + if (ctype_digit($Type)) { // Element is a string // Get length of string $StrLen = $Type; - while($this->Str[$this->Pos+1]!=':'){ + while ($this->Str[$this->Pos + 1] != ':') { $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+=2; + $this->Pos += $StrLen; + $this->Pos += 2; - } elseif($Type == 'i') { // Element is an int + } elseif ($Type == 'i') { // Element is an int $this->Pos++; // 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) $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->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->Pos += $this->Val[$Key]->Pos; // Sort by key to respect spec @@ -125,14 +125,14 @@ function decode($Type, $Key){ } } - function encode($Val){ - if(is_string($Val)) { - if(substr($Val, 0, 7) == '[*INT*]') { + function encode($Val) { + if (is_string($Val)) { + if (substr($Val, 0, 7) == '[*INT*]') { return 'i'.substr($Val,7).'e'; } else { return strlen($Val).':'.$Val; } - } elseif(is_object($Val)) { + } elseif (is_object($Val)) { return $Val->enc(); } else { return 'fail'; @@ -141,25 +141,25 @@ function encode($Val){ } class BENCODE_LIST extends BENCODE2 { - function enc(){ + function enc() { $Str = 'l'; reset($this->Val); - while(list($Key, $Value) = each($this->Val)) { + while (list($Key, $Value) = each($this->Val)) { $Str.=$this->encode($Value); } return $Str.'e'; } // Decode a list - function dec(){ + function dec() { $Key = 0; // Array index $Length = strlen($this->Str); - while($this->Pos<$Length){ + while ($this->Pos<$Length) { $Type = $this->Str[$this->Pos]; // $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) - if($Type == 'e') { // End of list + if ($Type == 'e') { // End of list $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. return; @@ -175,21 +175,21 @@ function dec(){ } class BENCODE_DICT extends BENCODE2 { - function enc(){ + function enc() { $Str = 'd'; reset($this->Val); - while(list($Key, $Value) = each($this->Val)) { + while (list($Key, $Value) = each($this->Val)) { $Str.=strlen($Key).':'.$Key.$this->encode($Value); } return $Str.'e'; } // Decode a dictionary - function dec(){ + function dec() { $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; 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; @@ -200,7 +200,7 @@ function dec(){ $KeyLen = $this->Str[$this->Pos]; // 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++; $KeyLen.=$this->Str[$this->Pos]; } @@ -212,7 +212,7 @@ function dec(){ $Key = substr($this->Str, $this->Pos, $KeyLen); // Move the position past the key to the beginning of the element - $this->Pos+=$KeyLen; + $this->Pos += $KeyLen; $Type = $this->Str[$this->Pos]; // $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) diff --git a/classes/class_torrent_form.php b/classes/class_torrent_form.php index dd07919d..7d4ce0f2 100644 --- a/classes/class_torrent_form.php +++ b/classes/class_torrent_form.php @@ -258,7 +258,7 @@ function music_form($GenreTags) {