summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/ajax_start.php10
-rw-r--r--classes/class_cache.php2
-rw-r--r--classes/class_debug.php2
-rw-r--r--classes/class_forums.php2
-rw-r--r--classes/class_image_tools.php197
-rw-r--r--classes/class_paranoia.php27
-rw-r--r--classes/class_search.php54
-rw-r--r--classes/class_sphinxql.php12
-rw-r--r--classes/class_sphinxqlquery.php38
-rw-r--r--classes/class_sphinxqlresult.php24
-rw-r--r--classes/class_templates.php57
-rw-r--r--classes/class_text.php6
-rw-r--r--classes/class_text2.php6
-rw-r--r--classes/class_text3.php12
-rw-r--r--classes/class_textarea_preview.php59
-rw-r--r--classes/class_time.php2
-rw-r--r--classes/class_tools.php2
-rw-r--r--classes/class_torrents.php6
-rw-r--r--classes/class_tracker.php4
-rw-r--r--classes/class_users.php10
-rw-r--r--classes/script_start.php3
21 files changed, 253 insertions, 282 deletions
diff --git a/classes/ajax_start.php b/classes/ajax_start.php
index a835b6e..5a7c391 100644
--- a/classes/ajax_start.php
+++ b/classes/ajax_start.php
@@ -70,7 +70,7 @@ function make_utf8($Str) {
$Encoding = 'UTF-8';
}
if (empty($Encoding)) {
- $Encoding = mb_detect_encoding($Str,'UTF-8, ISO-8859-1');
+ $Encoding = mb_detect_encoding($Str, 'UTF-8, ISO-8859-1');
}
if (empty($Encoding)) {
$Encoding = 'ISO-8859-1';
@@ -78,7 +78,7 @@ function make_utf8($Str) {
if ($Encoding == 'UTF-8') {
return $Str;
} else {
- return @mb_convert_encoding($Str,'UTF-8',$Encoding);
+ return @mb_convert_encoding($Str, 'UTF-8', $Encoding);
}
}
}
@@ -108,9 +108,9 @@ function display_array($Array, $DontEscape = array()) {
function make_secret($Length = 32) {
$Secret = '';
- $Chars='abcdefghijklmnopqrstuvwxyz0123456789';
- for($i=0; $i<$Length; $i++) {
- $Rand = mt_rand(0, strlen($Chars)-1);
+ $Chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
+ for ($i = 0; $i < $Length; $i++) {
+ $Rand = mt_rand(0, strlen($Chars) - 1);
$Secret .= substr($Chars, $Rand, 1);
}
return str_shuffle($Secret);
diff --git a/classes/class_cache.php b/classes/class_cache.php
index 04fd1c7..a3d5345 100644
--- a/classes/class_cache.php
+++ b/classes/class_cache.php
@@ -97,7 +97,7 @@ class CACHE extends Memcache
}
public function get_value($Key, $NoCache=false) {
- if(!$this->InternalCache) {
+ if (!$this->InternalCache) {
$NoCache = true;
}
$StartTime=microtime(true);
diff --git a/classes/class_debug.php b/classes/class_debug.php
index 93d41a0..d0c9645 100644
--- a/classes/class_debug.php
+++ b/classes/class_debug.php
@@ -456,7 +456,7 @@ class DEBUG {
public function cache_table($CacheKeys=false) {
global $Cache;
- $Header = 'Cache Keys';
+ $Header = 'Cache keys';
if (!is_array($CacheKeys)) {
$CacheKeys = $this->get_cache_keys();
$Header .= ' ('.number_format($this->get_cache_time(), 5).' ms)';
diff --git a/classes/class_forums.php b/classes/class_forums.php
index 506e1fc..3530a79 100644
--- a/classes/class_forums.php
+++ b/classes/class_forums.php
@@ -63,4 +63,4 @@ class Forums {
}
}
-} \ No newline at end of file
+}
diff --git a/classes/class_image_tools.php b/classes/class_image_tools.php
index b36671d..c3f84f4 100644
--- a/classes/class_image_tools.php
+++ b/classes/class_image_tools.php
@@ -9,13 +9,13 @@ class ImageTools {
* Store processed links to avoid repetition
* @var array 'URL' => 'Parsed URL'
*/
- static private $Storage = array();
+ private static $Storage = array();
/**
* We use true as an extra property to make the domain an array key
* @var array $Hosts Array of image hosts
*/
- static private $Hosts = array(
+ private static $Hosts = array(
'whatimg.com' => true,
'imgur.com' => true
);
@@ -24,7 +24,7 @@ class ImageTools {
* Blacklisted sites
* @var array $Blacklist Array of blacklisted hosts
*/
- static private $Blacklist = array(
+ private static $Blacklist = array(
'tinypic.com'
);
@@ -32,7 +32,7 @@ class ImageTools {
* Array of image hosts that provide thumbnailing
* @var array $Thumbs
*/
- static private $Thumbs = array(
+ private static $Thumbs = array(
'i.imgur.com' => true,
'whatimg.com' => true
);
@@ -41,7 +41,7 @@ class ImageTools {
* Array of extensions
* @var array $Extensions
*/
- static private $Extensions = array(
+ private static $Extensions = array(
'jpg' => true,
'jpeg' => true,
'png' => true,
@@ -78,7 +78,7 @@ class ImageTools {
* @param string $Url Link to an image
* @return string|false Matched host or false
*/
- public static function thumbnailable($Url) {
+ private static function thumbnailable($Url) {
$ParsedUrl = parse_url($Url);
return !empty(self::$Thumbs[$ParsedUrl['host']]);
}
@@ -88,7 +88,7 @@ class ImageTools {
* @param string $Ext Extension to check
* @return boolean
*/
- public static function valid_extension($Ext) {
+ private static function valid_extension($Ext) {
// return @self::$Extensions[$Ext] === true;
return !empty(self::$Extensions[$Ext]) && self::$Extensions[$Ext] === true;
}
@@ -98,7 +98,7 @@ class ImageTools {
* @param type $Link
* @param type $Processed
*/
- public static function store($Link, $Processed) {
+ private static function store($Link, $Processed) {
self::$Storage[$Link] = $Processed;
}
@@ -107,7 +107,7 @@ class ImageTools {
* @param type $Link
* @return boolean|string Returns false if no match
*/
- public static function get_stored($Link) {
+ private static function get_stored($Link) {
if (isset(self::$Storage[$Link])) {
return self::$Storage[$Link];
}
@@ -115,79 +115,34 @@ class ImageTools {
}
/**
- * Turns link into thumbnail (if possible) or default group image (if missing)
- * Automatically applies proxy when appropriate
- *
- * @global array $CategoryIcons
- * @param string $Link Link to an image
- * @param int $Groupid The torrent's group ID for a default image
- * @param boolean $Thumb Thumbnail image
- * @return string Link to image
+ * Checks if URL points to a whatimg thumbnail.
*/
- public static function wiki_image($Link, $GroupID = 0, $Thumb = true) {
- global $CategoryIcons;
-
- if ($Link && $Thumb) {
- $Thumb = self::thumbnail($Link);
- if (check_perms('site_proxy_images')) {
- return self::proxy_url($Thumb);
- }
- return $Thumb;
- }
-
- return STATIC_SERVER . 'common/noartwork/' . $CategoryIcons[$GroupID];
+ private static function has_whatimg_thumb($Url) {
+ return (strpos($Url, '_thumb') !== false);
}
/**
- * The main function called to get a thumbnail link.
- * Use wiki_image() instead of this method for more advanced options
- *
- * @param string $Link Image link
- * @return string Image link
- */
- public static function thumbnail($Link) {
- if (($Found = self::get_stored($Link))) {
- return $Found;
- }
- return self::process_thumbnail($Link);
+ * Cleans up imgur URL if it already has a modifier attached to the end of it.
+ */
+ private static function clean_imgur_url($Url) {
+ $Extension = pathinfo($Url, PATHINFO_EXTENSION);
+ $Full = preg_replace('/\.[^.]*$/', '', $Url);
+ $Base = substr($Full, 0, strrpos($Full, '/'));
+ $Path = substr($Full, strrpos($Full, '/') + 1);
+ if (strlen($Path) == 6) {
+ $Last = $Path[strlen($Path) - 1];
+ if ($Last == 'm' || $Last == 'l' || $Last == 's' || $Last == 'h' || $Last == 'b') {
+ $Path = substr($Path, 0, -1);
+ }
+ }
+ return $Base . '/' . $Path . '.' . $Extension;
}
/**
- * Matches a hosts that thumbnails and stores link
- * @param string $Link Image link
- * @return string Thumbnail link or Image link
+ * Replaces the extension.
*/
- static private function process_thumbnail($Link) {
- $Thumb = $Link;
- $Extension = pathinfo($Link, PATHINFO_EXTENSION);
-
- if (self::thumbnailable($Link) && self::valid_extension($Extension)) {
- if (contains('whatimg', $Link) && !has_whatimg_thumb($Link)) {
- $Thumb = replace_extension($Link, '_thumb.' . $Extension);
- } elseif (contains('imgur', $Link)) {
- $Thumb = replace_extension(clean_imgur_url($Link), 'm.' . $Extension);
- }
- }
- self::store($Link, $Thumb);
- return $Thumb;
- }
-
- /**
- * Creates an HTML thumbnail
- * @param type $Source
- * @param type $Category
- * @param type $Size
- */
- public static function cover_thumb($Source, $Category = 0, $Size = 90, $Title = 'Cover') {
- $Img = self::wiki_image($Source, $Category);
- if (!$Source) {
- $Source = $Img;
- } elseif (check_perms('site_proxy_images')) {
- $Source = self::proxy_url($Source);
- }
-?>
- <img src="<?=$Img?>" width="<?=$Size?>" height="<?=$Size?>" alt="<?=$Title?>" onclick="lightbox.init('<?=$Source?>', <?=$Size?>)" />
-<?
+ private static function replace_extension($String, $Extension) {
+ return preg_replace('/\.[^.]*$/', $Extension, $String);
}
/**
@@ -197,48 +152,70 @@ class ImageTools {
*/
public static function proxy_url($Url) {
global $SSL;
- return ($SSL ? 'https' : 'http') . '://' . SITE_URL
- . '/image.php?i=' . urlencode($Url);
+ return ($SSL ? 'https' : 'http') . '://' . SITE_URL . '/image.php?c=1&amp;i=' . urlencode($Url);
}
-}
-
-/**
- * This non-class determines the thumbnail equivalent of an image's URL after being passed the original
- *
- **/
+ /**
+ * Determine the image URL. This takes care of the image proxy and thumbnailing.
+ * @param string $Url
+ * @param bool $Thumb
+ * @return string
+ */
+ public static function process($Url, $Thumb = false) {
+ global $LoggedUser;
+ if (empty($Url)) {
+ return '';
+ }
+ if (($Found = self::get_stored($Url . ($Thumb ? '_thumb' : '')))) {
+ return $Found;
+ }
-/**
- * Replaces the extension.
- */
-function replace_extension($String, $Extension) {
- return preg_replace('/\.[^.]*$/', $Extension, $String);
-}
+ $ProcessedUrl = $Url;
+ if ($Thumb) {
+ $Extension = pathinfo($Url, PATHINFO_EXTENSION);
+ if (self::thumbnailable($Url) && self::valid_extension($Extension)) {
+ if (strpos($Url, 'whatimg') !== false && !self::has_whatimg_thumb($Url)) {
+ $ProcessedUrl = self::replace_extension($Url, '_thumb.' . $Extension);
+ } elseif (strpos($Url, 'imgur') !== false) {
+ $ProcessedUrl = self::replace_extension(self::clean_imgur_url($Url), 'm.' . $Extension);
+ }
+ }
+ }
-function contains($Substring, $String) {
- return strpos($String, $Substring) !== false;
-}
+ if (isset($LoggedUser['Permissions'])) {
+ /*
+ * We only want to apply the proxy and store the processed URL if the
+ * permissions were loaded before. This is necessary because self::process
+ * is used in Users::user_info which is called in script_start.php before
+ * the permissions are loaded, causing the own avatar to always load without
+ * proxy later on.
+ */
+ if (check_perms('site_proxy_images')) {
+ $ProcessedUrl = self::proxy_url($ProcessedUrl);
+ }
-/**
- * Checks if URL points to a whatimg thumbnail.
- */
-function has_whatimg_thumb($Url) {
- return contains("_thumb", $Url);
-}
+ self::store($Url . ($Thumb ? '_thumb' : ''), $ProcessedUrl);
+ }
+ return $ProcessedUrl;
+ }
-/**
- * Cleans up imgur URL if it already has a modifier attached to the end of it.
- */
-function clean_imgur_url($Url) {
- $Extension = pathinfo($Url, PATHINFO_EXTENSION);
- $Full = preg_replace('/\.[^.]*$/', '', $Url);
- $Base = substr($Full, 0, strrpos($Full, '/'));
- $Path = substr($Full, strrpos($Full, '/') + 1);
- if (strlen($Path) == 6) {
- $Last = $Path[strlen($Path) - 1];
- if ($Last == 'm' || $Last == 'l' || $Last == 's' || $Last == 'h' || $Last == 'b') {
- $Path = substr($Path, 0, -1);
+ /**
+ * Cover art thumbnail in browse, on artist pages etc.
+ * @global array $CategoryIcons
+ * @param string $Url
+ * @param int $CategoryID
+ */
+ public static function cover_thumb($Url, $CategoryID) {
+ global $CategoryIcons;
+ if ($Url) {
+ $Src = self::process($Url, true);
+ $Lightbox = self::process($Url);
+ } else {
+ $Src = STATIC_SERVER . 'common/noartwork/' . $CategoryIcons[$CategoryID - 1];
+ $Lightbox = $Src;
}
+?>
+ <img src="<?=$Src?>" width="90" height="90" alt="Cover" onclick="lightbox.init('<?=$Lightbox?>', 90)" />
+<?
}
- return $Base . '/' . $Path . '.' . $Extension;
}
diff --git a/classes/class_paranoia.php b/classes/class_paranoia.php
index b68b0bb..fdfa1ea 100644
--- a/classes/class_paranoia.php
+++ b/classes/class_paranoia.php
@@ -50,51 +50,54 @@ function check_paranoia($Property, $Paranoia, $UserClass, $UserID = false) {
if ($Property == false) {
return false;
}
- if(!is_array($Paranoia)) {
+ if (!is_array($Paranoia)) {
$Paranoia = unserialize($Paranoia);
}
- if(!is_array($Paranoia)) {
+ if (!is_array($Paranoia)) {
$Paranoia = array();
}
- if(is_array($Property)) {
+ if (is_array($Property)) {
$all = true;
- foreach ($Property as $P) { $all = $all && check_paranoia($P, $Paranoia, $UserClass, $UserID); }
+ foreach ($Property as $P) {
+ $all = $all && check_paranoia($P, $Paranoia, $UserClass, $UserID);
+ }
return $all;
} else {
- if(($UserID !== false) && ($LoggedUser['ID'] == $UserID)) {
+ if (($UserID !== false) && ($LoggedUser['ID'] == $UserID)) {
return PARANOIA_ALLOWED;
}
$May = !in_array($Property, $Paranoia) && !in_array($Property . '+', $Paranoia);
- if($May)
+ if ($May)
return PARANOIA_ALLOWED;
- if(check_perms('users_override_paranoia', $UserClass))
+ if (check_perms('users_override_paranoia', $UserClass)) {
return PARANOIA_OVERRIDDEN;
+ }
$Override=false;
switch ($Property) {
case 'downloaded':
case 'ratio':
case 'uploaded':
case 'lastseen':
- if(check_perms('users_mod', $UserClass))
+ if (check_perms('users_mod', $UserClass))
return PARANOIA_OVERRIDDEN;
break;
case 'snatched': case 'snatched+':
- if(check_perms('users_view_torrents_snatchlist', $UserClass))
+ if (check_perms('users_view_torrents_snatchlist', $UserClass))
return PARANOIA_OVERRIDDEN;
break;
case 'uploads': case 'uploads+':
case 'seeding': case 'seeding+':
case 'leeching': case 'leeching+':
- if(check_perms('users_view_seedleech', $UserClass))
+ if (check_perms('users_view_seedleech', $UserClass))
return PARANOIA_OVERRIDDEN;
break;
case 'invitedcount':
- if(check_perms('users_view_invites', $UserClass))
+ if (check_perms('users_view_invites', $UserClass))
return PARANOIA_OVERRIDDEN;
break;
}
return false;
}
-} \ No newline at end of file
+}
diff --git a/classes/class_search.php b/classes/class_search.php
index 1c9f133..a39d150 100644
--- a/classes/class_search.php
+++ b/classes/class_search.php
@@ -1,6 +1,6 @@
<?
//Require base class
-if(!extension_loaded('sphinx')) {
+if (!extension_loaded('sphinx')) {
require(SERVER_ROOT.'/classes/sphinxapi.php');
}
@@ -51,17 +51,17 @@ class SPHINX_SEARCH extends SphinxClient {
$QueryEndTime=microtime(true);
$Filters = array();
- foreach($this->Filters as $Name => $Values) {
- foreach($Values as $Value) {
+ foreach ($this->Filters as $Name => $Values) {
+ foreach ($Values as $Value) {
$Filters[] = $Name." - ".$Value;
}
}
- $this->Queries[]=array('Params: '.$Query.' Filters: '.implode(", ", $Filters).' Indicies: '.$this->Index,($QueryEndTime-$QueryStartTime)*1000);
- $this->Time+=($QueryEndTime-$QueryStartTime)*1000;
+ $this->Queries[] = array('Params: '.$Query.' Filters: '.implode(", ", $Filters).' Indicies: '.$this->Index,($QueryEndTime-$QueryStartTime) * 1000);
+ $this->Time += ($QueryEndTime-$QueryStartTime) * 1000;
- if($Result === false) {
- if($this->_connerror && !$Cache->get_value('sphinx_crash_reported')) {
+ if ($Result === false) {
+ if ($this->_connerror && !$Cache->get_value('sphinx_crash_reported')) {
send_irc('PRIVMSG '.ADMIN_CHAN.' :!dev Connection to searchd failed');
$Cache->cache_value('sphinx_crash_reported', 1, 3600);
}
@@ -71,7 +71,7 @@ class SPHINX_SEARCH extends SphinxClient {
$this->TotalResults = $Result['total_found'];
$this->SearchTime = $Result['time'];
- if(empty($Result['matches'])) {
+ if (empty($Result['matches'])) {
return false;
}
$Matches = $Result['matches'];
@@ -82,49 +82,49 @@ class SPHINX_SEARCH extends SphinxClient {
$NotFound = array();
$Skip = array();
- if(!empty($ReturnData)) {
+ if (!empty($ReturnData)) {
$AllFields = false;
} else {
$AllFields = true;
}
- foreach($MatchIDs as $Match) {
+ foreach ($MatchIDs as $Match) {
$Matches[$Match] = $Matches[$Match]['attrs'];
- if(!empty($CachePrefix)) {
+ if (!empty($CachePrefix)) {
$Data = $Cache->get_value($CachePrefix.'_'.$Match);
- if($Data == false) {
- $NotFound[]=$Match;
+ if ($Data == false) {
+ $NotFound[] = $Match;
continue;
}
} else {
- $NotFound[]=$Match;
+ $NotFound[] = $Match;
}
- if(!$AllFields) {
+ if (!$AllFields) {
// Populate list of fields to unset (faster than picking out the ones we need). Should only be run once, on the first cache key
- if(empty($Skip)) {
- foreach(array_keys($Data) as $Key) {
- if(!in_array($Key, $ReturnData)) {
- $Skip[]=$Key;
+ if (empty($Skip)) {
+ foreach (array_keys($Data) as $Key) {
+ if (!in_array($Key, $ReturnData)) {
+ $Skip[] = $Key;
}
}
- if(empty($Skip)) {
+ if (empty($Skip)) {
$AllFields = true;
}
}
- foreach($Skip as $Key) {
+ foreach ($Skip as $Key) {
unset($Data[$Key]);
}
reset($Skip);
}
- if(!empty($Data)) {
+ if (!empty($Data)) {
$Matches[$Match] = array_merge($Matches[$Match], $Data);
}
}
- if($SQL!='') {
- if(!empty($NotFound)) {
+ if ($SQL != '') {
+ if (!empty($NotFound)) {
$DB->query(str_replace('%ids', implode(',',$NotFound), $SQL));
- while($Data = $DB->next_record(MYSQLI_ASSOC)) {
+ while ($Data = $DB->next_record(MYSQLI_ASSOC)) {
$Matches[$Data[$IDColumn]] = array_merge($Matches[$Data[$IDColumn]], $Data);
$Cache->cache_value($CachePrefix.'_'.$Data[$IDColumn], $Data, $CacheLength);
}
@@ -148,8 +148,8 @@ class SPHINX_SEARCH extends SphinxClient {
}
function set_filter($Name, $Vals, $Exclude=false) {
- foreach($Vals as $Val) {
- if($Exclude) {
+ foreach ($Vals as $Val) {
+ if ($Exclude) {
$this->Filters[$Name][] = "!$Val";
} else {
$this->Filters[$Name][] = $Val;
diff --git a/classes/class_sphinxql.php b/classes/class_sphinxql.php
index 9c411e0..d7d41c6 100644
--- a/classes/class_sphinxql.php
+++ b/classes/class_sphinxql.php
@@ -38,7 +38,7 @@ class Sphinxql extends mysqli {
* @return identification string
*/
private function get_ident($Server, $Port, $Socket) {
- if($Socket) {
+ if ($Socket) {
return $Socket;
} else {
return "$Server:$Port";
@@ -55,7 +55,7 @@ class Sphinxql extends mysqli {
*/
public static function init_connection($Server, $Port, $Socket) {
$Ident = self::get_ident($Server, $Port, $Socket);
- if(!isset(self::$Connections[$Ident])) {
+ if (!isset(self::$Connections[$Ident])) {
self::$Connections[$Ident] = new Sphinxql($Server, $Port, $Socket);
}
return self::$Connections[$Ident];
@@ -65,11 +65,11 @@ class Sphinxql extends mysqli {
* Connect the Sphinxql object to the Sphinx server
*/
public function connect() {
- if(!$this->Connected) {
+ if (!$this->Connected) {
global $Debug;
$Debug->set_flag('Connecting to Sphinx server '.$this->Ident);
parent::__construct($this->Server, '', '', '', $this->Port, $this->Socket);
- if($this->connect_error) {
+ if ($this->connect_error) {
$Errno = $this->connect_errno;
$Error = $this->connect_error;
$this->error("Connection failed. ".strval($Errno)." (".strval($Error).")");
@@ -90,10 +90,10 @@ class Sphinxql extends mysqli {
global $Debug;
$ErrorMsg = 'SphinxQL ('.$this->Ident.'): '.strval($Msg);
$Debug->analysis('SphinxQL Error', $ErrorMsg, 3600*24);
- if($Halt === true && (DEBUG_MODE || check_perms('site_debug'))) {
+ if ($Halt === true && (DEBUG_MODE || check_perms('site_debug'))) {
echo '<pre>'.display_str($ErrorMsg).'</pre>';
die();
- } elseif($Halt === true) {
+ } elseif ($Halt === true) {
error('-1');
}
}
diff --git a/classes/class_sphinxqlquery.php b/classes/class_sphinxqlquery.php
index e5909ee..03e2668 100644
--- a/classes/class_sphinxqlquery.php
+++ b/classes/class_sphinxqlquery.php
@@ -56,26 +56,26 @@ class SphinxqlQuery {
* @return current Sphinxql query object
*/
public function where($Attribute, $Values, $Exclude = false) {
- if(empty($Attribute) && empty($Values)) {
+ if (empty($Attribute) && empty($Values)) {
return false;
}
$Filters = array();
- if(is_array($Values)) {
- foreach($Values as $Value) {
- if(!is_number($Value)) {
+ if (is_array($Values)) {
+ foreach ($Values as $Value) {
+ if (!is_number($Value)) {
$this->error("Filters require numeric values");
}
}
- if($Exclude) {
+ if ($Exclude) {
$Filters[] = "$Attribute NOT IN (".implode(",", $Values).")";
} else {
$Filters[] = "$Attribute IN (".implode(",", $Values).")";
}
} else {
- if(!is_number($Values)) {
+ if (!is_number($Values)) {
$this->error("Filters require numeric values");
}
- if($Exclude) {
+ if ($Exclude) {
$Filters[] = "$Attribute != $Values";
} else {
$Filters[] = "$Attribute = $Values";
@@ -93,7 +93,7 @@ class SphinxqlQuery {
* @return current Sphinxql query object
*/
public function where_between($Attribute, $Values) {
- if(empty($Attribute) || empty($Values) || count($Values) != 2 || !is_number($Values[0]) || !is_number($Values[1])) {
+ if (empty($Attribute) || empty($Values) || count($Values) != 2 || !is_number($Values[0]) || !is_number($Values[1])) {
$this->error("Filter range requires array of two numerical boundaries as values.");
}
$this->Filters[] = "$Attribute BETWEEN $Values[0] AND $Values[1]";
@@ -109,7 +109,7 @@ class SphinxqlQuery {
* @return current Sphinxql query object
*/
public function where_match($Expr, $Field = '*', $Escape = true) {
- if(empty($Expr)) {
+ if (empty($Expr)) {
return $this;
}
if ($Field !== false) {
@@ -216,29 +216,29 @@ class SphinxqlQuery {
* Combine the query conditions into a valid Sphinx query segment
*/
private function build_query() {
- if(!$this->Indexes) {
+ if (!$this->Indexes) {
$this->error('Index name is required.');
}
$this->QueryString = "SELECT $this->Select\nFROM $this->Indexes";
- if(!empty($this->Expressions)) {
+ if (!empty($this->Expressions)) {
$this->Filters['expr'] = "MATCH('".implode(" ", $this->Expressions)."')";
}
- if(!empty($this->Filters)) {
+ if (!empty($this->Filters)) {
$this->QueryString .= "\nWHERE ".implode("\n\tAND ", $this->Filters);
}
- if(!empty($this->GroupBy)) {
+ if (!empty($this->GroupBy)) {
$this->QueryString .= "\nGROUP BY $this->GroupBy";
}
- if(!empty($this->SortGroupBy)) {
+ if (!empty($this->SortGroupBy)) {
$this->QueryString .= "\nWITHIN GROUP ORDER BY $this->SortGroupBy";
}
- if(!empty($this->SortBy)) {
+ if (!empty($this->SortBy)) {
$this->QueryString .= "\nORDER BY ".implode(", ", $this->SortBy);
}
- if(!empty($this->Limits)) {
+ if (!empty($this->Limits)) {
$this->QueryString .= "\nLIMIT $this->Limits";
}
- if(!empty($this->Options)) {
+ if (!empty($this->Options)) {
$Options = $this->build_options();
$this->QueryString .= "\nOPTION $Options";
}
@@ -279,12 +279,12 @@ class SphinxqlQuery {
* @return Sphinxql result object
*/
private function send_query($GetMeta) {
- if(!$this->QueryString) {
+ if (!$this->QueryString) {
return false;
}
$this->Sphinxql->connect();
$Result = $this->Sphinxql->query($this->QueryString);
- if($Result === false) {
+ if ($Result === false) {
$Errno = $this->Sphinxql->errno;
$Error = $this->Sphinxql->error;
$this->error("Query returned error $Errno ($Error).\n$this->QueryString");
diff --git a/classes/class_sphinxqlresult.php b/classes/class_sphinxqlresult.php
index 11a4295..1c2491c 100644
--- a/classes/class_sphinxqlresult.php
+++ b/classes/class_sphinxqlresult.php
@@ -39,7 +39,7 @@ class SphinxqlResult {
*/
public function collect($Key) {
$Return = array();
- while($Row = $this->fetch_array()) {
+ while ($Row = $this->fetch_array()) {
$Return[] = $Row[$Key];
}
$this->data_seek(0);
@@ -55,8 +55,8 @@ class SphinxqlResult {
*/
public function to_array($Key, $ResultType = MYSQLI_ASSOC) {
$Return = array();
- while($Row = $this->fetch_array($ResultType)) {
- if($Key !== false) {
+ while ($Row = $this->fetch_array($ResultType)) {
+ if ($Key !== false) {
$Return[$Row[$Key]] = $Row;
} else {
$Return[] = $Row;
@@ -75,7 +75,7 @@ class SphinxqlResult {
*/
public function to_pair($Key1, $Key2) {
$Return = array();
- while($Row = $this->fetch_array()) {
+ while ($Row = $this->fetch_array()) {
$Return[$Row[$Key1]] = $Row[$Key2];
}
$this->data_seek(0);
@@ -89,11 +89,11 @@ class SphinxqlResult {
* @return array with meta data
*/
public function get_meta($Keys = false) {
- if($Keys !== false) {
- if(is_array($Keys)) {
+ if ($Keys !== false) {
+ if (is_array($Keys)) {
$Return = array();
- foreach($Keys as $Key) {
- if(!isset($this->Meta[$Key])) {
+ foreach ($Keys as $Key) {
+ if (!isset($this->Meta[$Key])) {
continue;
}
$Return[$Key] = $this->Meta[$Key];
@@ -114,11 +114,11 @@ class SphinxqlResult {
* @return array with result information
*/
public function get_result_info($Keys = false) {
- if($Keys !== false) {
- if(is_array($Keys)) {
+ if ($Keys !== false) {
+ if (is_array($Keys)) {
$Return = array();
- foreach($Keys as $Key) {
- if(!isset($this->Result->$Key)) {
+ foreach ($Keys as $Key) {
+ if (!isset($this->Result->$Key)) {
continue;
}
$Return[$Key] = $this->Result->$Key;
diff --git a/classes/class_templates.php b/classes/class_templates.php
index 05e8acf..9e69d9d 100644
--- a/classes/class_templates.php
+++ b/classes/class_templates.php
@@ -6,15 +6,15 @@
// $TPL->get();
class TEMPLATE {
- var $file='';
- var $vars=array();
+ var $file = '';
+ var $vars = array();
function open($file) {
- $this->file=file($file);
+ $this->file = file($file);
}
function set($name,$var,$ifnone='<span style="font-style: italic;">-None-</span>') {
- if ($name!='') {
+ if ($name != '') {
$this->vars[$name][0]=$var;
$this->vars[$name][1]=$ifnone;
}
@@ -22,24 +22,28 @@ class TEMPLATE {
function show() {
$TMPVAR='';
- for($i=0; $i<sizeof($this->file); $i++) {
+ for ($i=0; $i<sizeof($this->file); $i++) {
$TMPVAR=$this->file[$i];
- foreach($this->vars as $k=>$v) {
- if ($v[1]!="" && $v[0]=="") { $v[0]=$v[1]; }
- $TMPVAR=str_replace('{{'.$k.'}}',$v[0],$TMPVAR);
+ foreach ($this->vars as $k=>$v) {
+ if ($v[1] != '' && $v[0] == '') {
+ $v[0] = $v[1];
+ }
+ $TMPVAR = str_replace('{{'.$k.'}}',$v[0],$TMPVAR);
}
print $TMPVAR;
}
}
function get() {
- $RESULT='';
- $TMPVAR='';
- for($i=0; $i<sizeof($this->file); $i++) {
+ $RESULT = '';
+ $TMPVAR = '';
+ for ($i = 0; $i < sizeof($this->file); $i++) {
$TMPVAR=$this->file[$i];
- foreach($this->vars as $k=>$v) {
- if ($v[1]!="" && $v[0]=="") { $v[0]=$v[1]; }
- $TMPVAR=str_replace('{{'.$k.'}}',$v[0],$TMPVAR);
+ foreach ($this->vars as $k=>$v) {
+ if ($v[1] != '' && $v[0] == '') {
+ $v[0] = $v[1];
+ }
+ $TMPVAR = str_replace('{{'.$k.'}}',$v[0],$TMPVAR);
}
$RESULT.=$TMPVAR;
}
@@ -47,33 +51,32 @@ class TEMPLATE {
}
function str_align($len,$str,$align,$fill) {
- $strlen=strlen($str);
- if ($strlen>$len) {
+ $strlen = strlen($str);
+ if ($strlen > $len) {
return substr($str, 0, $len);
- } elseif (($strlen==0)||($len==0)) {
+ } elseif (($strlen == 0) || ($len == 0)) {
return '';
} else {
- if (($align=='l')||($align=='left')) {
- $result=$str.str_repeat($fill,($len-$strlen));
+ if (($align == 'l') || ($align == 'left')) {
+ $result = $str.str_repeat($fill,($len - $strlen));
- } elseif (($align=='r')||($align=='right')) {
- $result=str_repeat($fill,($len-$strlen)).$str;
+ } elseif (($align == 'r') || ($align == 'right')) {
+ $result = str_repeat($fill,($len - $strlen)).$str;
- } elseif (($align=='c')||($align=='center')) {
- $snm=intval(($len-$strlen)/2);
- if (($strlen+($snm*2))==$len) {
- $result=str_repeat($fill,$snm).$str;
+ } elseif (($align == 'c') || ($align == 'center')) {
+ $snm = intval(($len - $strlen) / 2);
+ if (($strlen + ($snm * 2)) == $len) {
+ $result = str_repeat($fill,$snm).$str;
} else {
- $result=str_repeat($fill,$snm+1).$str;
+ $result = str_repeat($fill,$snm + 1).$str;
}
$result.=str_repeat($fill,$snm);
}
-
return $result;
}
}
diff --git a/classes/class_text.php b/classes/class_text.php
index bb497fc..9389a4c 100644
--- a/classes/class_text.php
+++ b/classes/class_text.php
@@ -736,7 +736,7 @@ class TEXT {
}
}
$Str.='<blockquote>'.$this->to_html($Block['Val']).'</blockquote>';
- if($this->InQuotes == $this->NestsBeforeHide) { //Close quote the deeply nested quote [hide].
+ if ($this->InQuotes == $this->NestsBeforeHide) { //Close quote the deeply nested quote [hide].
$Str.='</blockquote><br />'; // Ensure new line after quote train hiding
}
$this->NoImg--;
@@ -772,10 +772,8 @@ class TEXT {
$LocalURL = $this->local_url($Block['Val']);
if ($LocalURL) {
$Str.='<img class="scale_image" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="'.$LocalURL.'" />';
- } elseif (check_perms('site_proxy_images')) {
- $Str.='<img class="scale_image" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?i='.urlencode($Block['Val']).'" />';
} else {
- $Str.='<img class="scale_image" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="'.$Block['Val'].'" />';
+ $Str.='<img class="scale_image" onclick="lightbox.init(this,500);" alt="'.$Block['Val'].'" src="'.ImageTools::process($Block['Val']).'" />';
}
}
break;
diff --git a/classes/class_text2.php b/classes/class_text2.php
index 89d7d48..b79ed17 100644
--- a/classes/class_text2.php
+++ b/classes/class_text2.php
@@ -543,11 +543,7 @@ EXPLANATION OF PARSER LOGIC
if (!$this->valid_url($Block['Val'], '\.(jpe?g|gif|png|bmp|tiff)')) {
$Str.='[img]'.$Block['Val'].'[/img]';
} else {
- 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']).'" />';
- } 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="'.ImageTools::process($Block['Val']).'" />';
}
break;
diff --git a/classes/class_text3.php b/classes/class_text3.php
index e0f2e7a..ca8abb3 100644
--- a/classes/class_text3.php
+++ b/classes/class_text3.php
@@ -286,8 +286,8 @@ EXPLANATION OF PARSER LOGIC
$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;
@@ -318,7 +318,7 @@ EXPLANATION OF PARSER LOGIC
$NumInOpens++;
}
- } while($NumInOpens>$NumInCloses);
+ } while ($NumInOpens > $NumInCloses);
// Find the internal block inside the tag
@@ -504,11 +504,7 @@ EXPLANATION OF PARSER LOGIC
if (!$this->valid_url($Block['Val'], '\.(jpe?g|gif|png|bmp|tiff)')) {
$Str.='[img]'.$Block['Val'].'[/img]';
} else {
- 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']).'" />';
- } 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="'.ImageTools::process($Block['Val']).'" />';
}
break;
diff --git a/classes/class_textarea_preview.php b/classes/class_textarea_preview.php
index 536996a..b7c0f54 100644
--- a/classes/class_textarea_preview.php
+++ b/classes/class_textarea_preview.php
@@ -3,8 +3,7 @@
* This super class is used to manage the ammount of textareas there are and to
* generate the required JavaScript that enables the previews to work.
*/
-class TEXTAREA_PREVIEW_SUPER
-{
+class TEXTAREA_PREVIEW_SUPER {
/**
* @static
* @var int $Textareas Total number of textareas created
@@ -37,11 +36,13 @@ class TEXTAREA_PREVIEW_SUPER
* @example <pre><?php TEXT_PREVIEW::JavaScript(); ?></pre>
* @return void
*/
- static public function JavaScript ($all = true)
- {
- if (self::$Textareas === 0) return;
- if (self::$Exectuted === false && $all)
+ static public function JavaScript ($all = true) {
+ if (self::$Textareas === 0) {
+ return;
+ }
+ if (self::$Exectuted === false && $all) {
View::parse('generic/textarea/script.phtml');
+ }
self::$Exectuted = true;
self::iterator();
@@ -55,10 +56,9 @@ class TEXTAREA_PREVIEW_SUPER
* @static
* @return void
*/
- static private function iterator ()
- {
+ static private function iterator () {
$script = array();
- for($i = 0; $i < self::$Textareas; $i++) {
+ for ($i = 0; $i < self::$Textareas; $i++) {
if (isset(self::$_ID[$i]) && is_string(self::$_ID[$i])) {
$a = sprintf('%d, "%s"', $i, self::$_ID[$i]);
} else {
@@ -66,9 +66,9 @@ class TEXTAREA_PREVIEW_SUPER
}
$script[] = sprintf('[%s]', $a);
}
- if (!empty($script))
- View::parse('generic/textarea/script_factory.phtml',
- array('script' => join(', ', $script)));
+ if (!empty($script)) {
+ View::parse('generic/textarea/script_factory.phtml', array('script' => join(', ', $script)));
+ }
}
}
@@ -111,8 +111,7 @@ class TEXTAREA_PREVIEW_SUPER
* </div>
* </pre>
*/
-class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER
-{
+class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER {
/**
* @var int Unique ID
*/
@@ -157,14 +156,19 @@ class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER
parent::$Textareas += 1;
array_push(parent::$_ID, $ID);
- if (empty($ID)) $ID = 'quickpost_' . $this->id;
+ if (empty($ID)) {
+ $ID = 'quickpost_' . $this->id;
+ }
- if (!empty($ExtraAttributes))
+ if (!empty($ExtraAttributes)) {
$Attributes = ' ' . implode(' ', $ExtraAttributes);
- else
+ } else {
$Attributes = '';
+ }
- if ($Preview === true) $this->preview();
+ if ($Preview === true) {
+ $this->preview();
+ }
$this->buffer = View::parse('generic/textarea/textarea.phtml', array(
'ID' => $ID,
@@ -176,17 +180,19 @@ class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER
'Attributes' => &$Attributes
), $Buffer);
- if ($Buttons === true) $this->buttons();
+ if ($Buttons === true) {
+ $this->buttons();
+ }
}
/**
* Outputs the divs required for previewing the AJAX content
* Will only output once
*/
- public function preview ()
- {
- if (!$this->preview)
+ public function preview () {
+ if (!$this->preview) {
View::parse('generic/textarea/preview.phtml', array('ID' => $this->id));
+ }
$this->preview = true;
}
@@ -194,16 +200,14 @@ class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER
* Outputs the preview and edit buttons
* Can be called many times to place buttons in different areas
*/
- public function buttons ()
- {
+ public function buttons () {
View::parse('generic/textarea/buttons.phtml', array('ID' => $this->id));
}
/**
* Returns the textarea's numeric ID.
*/
- public function getID ()
- {
+ public function getID () {
return $this->id;
}
@@ -211,8 +215,7 @@ class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER
* Returns textarea string when buffer is enabled in the constructor
* @return string
*/
- public function getBuffer ()
- {
+ public function getBuffer () {
return $this->buffer;
}
}
diff --git a/classes/class_time.php b/classes/class_time.php
index b8d8a77..510a99e 100644
--- a/classes/class_time.php
+++ b/classes/class_time.php
@@ -121,7 +121,7 @@ function time_diff($TimeStamp, $Levels=2, $Span=true, $Lowercase=false) {
if ($Return != '') {
$Return.=' and ';
}
- if ($Minutes>1) {
+ if ($Minutes > 1) {
$Return.=$Minutes.' mins';
} else {
$Return.=$Minutes.' min';
diff --git a/classes/class_tools.php b/classes/class_tools.php
index 4ffa240..fc60a95 100644
--- a/classes/class_tools.php
+++ b/classes/class_tools.php
@@ -172,7 +172,7 @@ class Tools {
$Cache->delete_value('user_stats_'.$UserID);
$DB->query("SELECT SessionID FROM users_sessions WHERE UserID='$UserID' AND Active = 1");
- while(list($SessionID) = $DB->next_record()) {
+ while (list($SessionID) = $DB->next_record()) {
$Cache->delete_value('session_'.$UserID.'_'.$SessionID);
}
$Cache->delete_value('users_sessions_'.$UserID);
diff --git a/classes/class_torrents.php b/classes/class_torrents.php
index 6a36177..0ac2ddf 100644
--- a/classes/class_torrents.php
+++ b/classes/class_torrents.php
@@ -81,7 +81,7 @@ class Torrents {
g.ID, g.Name, g.Year, g.RecordLabel, g.CatalogueNumber, g.TagList, g.ReleaseType, g.VanityHouse, g.WikiImage, g.CategoryID
FROM torrents_group AS g WHERE g.ID IN ($IDs)");
- while($Group = $DB->next_record(MYSQLI_ASSOC, true)) {
+ while ($Group = $DB->next_record(MYSQLI_ASSOC, true)) {
unset($NotFound[$Group['ID']]);
$Found[$Group['ID']] = $Group;
$Found[$Group['ID']]['Torrents'] = array();
@@ -104,7 +104,7 @@ class Torrents {
WHERE GroupID IN($IDs)
ORDER BY GroupID, Remastered, (RemasterYear <> 0) DESC, RemasterYear, RemasterTitle,
RemasterRecordLabel, RemasterCatalogueNumber, Media, Format, Encoding, ID");
- while($Torrent = $DB->next_record(MYSQLI_ASSOC, true)) {
+ while ($Torrent = $DB->next_record(MYSQLI_ASSOC, true)) {
$Found[$Torrent['GroupID']]['Torrents'][$Torrent['ID']] = $Torrent;
}
@@ -262,7 +262,7 @@ class Torrents {
// Torrent notifications
$DB->query("SELECT UserID FROM users_notify_torrents WHERE TorrentID='$ID'");
- while(list($UserID) = $DB->next_record()) {
+ while (list($UserID) = $DB->next_record()) {
$Cache->delete_value('notifications_new_'.$UserID);
}
$DB->query("DELETE FROM users_notify_torrents WHERE TorrentID='$ID'");
diff --git a/classes/class_tracker.php b/classes/class_tracker.php
index ef6251f..5de49a5 100644
--- a/classes/class_tracker.php
+++ b/classes/class_tracker.php
@@ -23,7 +23,7 @@ class Tracker {
}
$Path = TRACKER_SECRET.$Get;
- $Return = "";
+ $Return = '';
$Attempts = 0;
while ($Return != "success" && $Attempts < 3) {
@@ -52,7 +52,7 @@ class Tracker {
} while (!feof($File) && !Misc::ends_with($ResHeader, "\r\n\r\n"));
$Response = '';
- while($Line = fgets($File)) {
+ while ($Line = fgets($File)) {
$Response .= $Line;
}
diff --git a/classes/class_users.php b/classes/class_users.php
index 340e66d..daba276 100644
--- a/classes/class_users.php
+++ b/classes/class_users.php
@@ -104,9 +104,7 @@ class Users {
}
// Image proxy
- if (check_perms('site_proxy_images') && !empty($UserInfo['Avatar'])) {
- $UserInfo['Avatar'] = 'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&amp;avatar='.$UserID.'&amp;i='.urlencode($UserInfo['Avatar']);
- }
+ $UserInfo['Avatar'] = ImageTools::process($UserInfo['Avatar']);
return $UserInfo;
}
@@ -397,12 +395,12 @@ class Users {
$Numchars = strlen($Chars) - 1;
if ($Handle = @fopen('/dev/urandom', 'r')) {
$Bytes = fread($Handle, 22);
- for($i = 0; $i < 21; $i++) {
+ for ($i = 0; $i < 21; $i++) {
$Salt .= $Chars[ord($Bytes[$i]) & $Numchars];
}
$Salt[$i] = $Chars[(ord($Bytes[$i]) & 3) << 4];
} else {
- for($i = 0; $i < 21; $i++) {
+ for ($i = 0; $i < 21; $i++) {
$Salt .= $Chars[mt_rand(0, $Numchars)];
}
$Salt[$i] = $Chars[mt_rand(0, 3) << 4];
@@ -481,7 +479,7 @@ class Users {
if (check_perms('site_proxy_images') && !empty($UserInfo['Title'])) {
$UserInfo['Title'] = preg_replace_callback('~src=("?)(http.+?)(["\s>])~',
function($Matches) {
- return 'src='.$Matches[1].'http'.($SSL?'s':'').'://'.SITE_URL.'/image.php?c=1&amp;i='.urlencode($Matches[2]).$Matches[3];
+ return 'src=' . $Matches[1] . ImageTools::process($Matches[2]) . $Matches[3];
},
$UserInfo['Title']);
}
diff --git a/classes/script_start.php b/classes/script_start.php
index da6f05f..ce7af93 100644
--- a/classes/script_start.php
+++ b/classes/script_start.php
@@ -10,7 +10,6 @@
/*------------------------------------------------------*/
/********************************************************/
require 'config.php'; //The config contains all site wide configuration information
-
//Deal with dumbasses
if (isset($_REQUEST['info_hash']) && isset($_REQUEST['peer_id'])) { die('d14:failure reason40:Invalid .torrent, try downloading again.e'); }
@@ -435,8 +434,6 @@ $Debug->set_flag('ending function definitions');
$Document = basename(parse_url($_SERVER['SCRIPT_FILENAME'], PHP_URL_PATH), '.php');
if (!preg_match('/^[a-z0-9]+$/i', $Document)) { error(404); }
-
-
require(SERVER_ROOT.'/sections/'.$Document.'/index.php');
$Debug->set_flag('completed module execution');