diff --git a/classes/class_format.php b/classes/class_format.php index 41866708..6075c0bf 100644 --- a/classes/class_format.php +++ b/classes/class_format.php @@ -1,5 +1,39 @@ -class Format { +class Format +{ + /** + * Torrent Labels + * Map a common display string to a CSS class + * Indexes are lower case + * Note the "tl_" prefix for "torrent label" + * + * There are five basic types: + * * tl_free (leech status) + * * tl_snatched + * * tl_reported + * * tl_approved + * * tl_notice (default) + * + * @var array Strings + */ + private static $TorrentLabels = array( + 'default' => 'tl_notice', + 'snatched' => 'tl_snatched', + + 'freeleech' => 'tl_free', + 'neutral leech' => 'tl_free tl_neutral', + 'personal freeleech' => 'tl_free tl_personal', + + 'reported' => 'tl_reported', + 'bad tags' => 'tl_reported tl_bad_tags', + 'bad folders' => 'tl_reported tl_bad_folders', + 'bad file names' => 'tl_reported tl_bad_file_names', + + 'cassette approved' => 'tl_approved tl_cassete', + 'lossy master approved' => 'tl_approved tl_lossy_master', + 'lossy web approved' => 'tl_approved tl_lossy_web' + ); + /** * Shorten a string * @@ -463,4 +497,35 @@ public static function is_utf8($Str) { ); } + /** + * Modified accessor for the $TorrentLabels array + * + * Converts $text to lowercase and strips non-word characters + * + * @param string $text Search string + * @return string CSS class(es) + */ + public static function find_torrent_label_class ($text) + { + $index = mb_eregi_replace('(?:[^\w\d\s]+)', '', strtolower($text)); + if (isset(self::$TorrentLabels[$index])) return self::$TorrentLabels[$index]; + return self::$TorrentLabels['default']; + } + + /** + * Creates a strong element that notes the torrent's state. + * Eg: snatched/freeleech/neutral leech/reported + * + * The CSS class is infered using find_torrent_label_class($text) + * + * @param string $text Display text + * @param string $class Custom CSS class + * @return string Strong element + */ + public static function torrent_label ($text, $class='') + { + if (empty($class)) $class = self::find_torrent_label_class($text); + return sprintf('%2$s', + display_str($class), display_str($text)); + } } \ No newline at end of file diff --git a/classes/class_torrents.php b/classes/class_torrents.php index b018a406..c5da7c28 100644 --- a/classes/class_torrents.php +++ b/classes/class_torrents.php @@ -457,10 +457,10 @@ public static function torrent_info($Data, $ShowMedia = false, $ShowEdition = fa if (!empty($Data['RemasterTitle'])) { $EditionInfo[]=$Data['RemasterTitle']; } if (count($EditionInfo)) { $Info[]=implode(' ',$EditionInfo); } } - if ($Data['IsSnatched']) { $Info[]='Snatched!'; } - if ($Data['FreeTorrent'] == '1') { $Info[]='Freeleech!'; } - if ($Data['FreeTorrent'] == '2') { $Info[]='Neutral Leech!'; } - if ($Data['PersonalFL']) { $Info[]='Personal Freeleech!'; } + if ($Data['IsSnatched']) { $Info[]= Format::torrent_label('Snatched!'); } + if ($Data['FreeTorrent'] == '1') { $Info[]= Format::torrent_label('Freeleech!'); } + if ($Data['FreeTorrent'] == '2') { $Info[]= Format::torrent_label('Neutral Leech!'); } + if ($Data['PersonalFL']) { $Info[]= Format::torrent_label('Personal Freeleech!'); } return implode(' / ', $Info); } diff --git a/sections/better/transcode.php b/sections/better/transcode.php index 605a2021..88b11398 100644 --- a/sections/better/transcode.php +++ b/sections/better/transcode.php @@ -147,7 +147,7 @@ $DisplayName .= " [".$ReleaseTypes[$ReleaseType]."]"; } if ($Edition['IsSnatched']) { - $DisplayName .= ' Snatched!'; + $DisplayName .= ' ' . Format::torrent_label('Snatched!'); } $EditionInfo = array(); diff --git a/sections/bookmarks/torrents.php b/sections/bookmarks/torrents.php index ec6c18d7..a8f4ebf0 100644 --- a/sections/bookmarks/torrents.php +++ b/sections/bookmarks/torrents.php @@ -192,14 +192,14 @@ function compare($X, $Y){ $DisplayName = ''.$GroupName.''; if ($Torrent['IsSnatched']) { - $DisplayName .= ' Snatched!'; + $DisplayName .= ' ' . Format::torrent_label('Snatched!'); } if ($Torrent['FreeTorrent'] == '1') { - $DisplayName .= ' Freeleech!'; + $DisplayName .= ' ' . Format::torrent_label('Freeleech!'); } elseif ($Torrent['FreeTorrent'] == '2') { - $DisplayName .= ' Neutral Leech!'; + $DisplayName .= ' ' . Format::torrent_label('Neutral leech!'); } elseif ($Torrent['PersonalFL']) { - $DisplayName .= ' Personal Freeleech!'; + $DisplayName .= ' ' . Format::torrent_label('Personal Freeleech!'); } $SnatchedTorrentClass = $Torrent['IsSnatched'] ? ' snatched_torrent' : ''; ?> diff --git a/sections/collages/collage.php b/sections/collages/collage.php index 782a889b..829a8772 100644 --- a/sections/collages/collage.php +++ b/sections/collages/collage.php @@ -267,14 +267,14 @@ function compare($X, $Y){ $DisplayName = ''.$GroupName.''; if ($Torrent['IsSnatched']) { - $DisplayName .= ' Snatched!'; + $DisplayName .= ' ' . Format::torrent_label('Snatched!'); } if ($Torrent['FreeTorrent'] == '1') { - $DisplayName .= ' Freeleech!'; + $DisplayName .= ' ' . Format::torrent_label('Freeleech!'); } elseif ($Torrent['FreeTorrent'] == '2') { - $DisplayName .= ' Neutral Leech!'; + $DisplayName .= ' ' . Format::torrent_label('Neutral Leech!'); } elseif ($Torrent['PersonalFL']) { - $DisplayName .= ' Personal Freeleech!'; + $DisplayName .= ' ' . Format::torrent_label('Personal Freeleech!'); } $SnatchedTorrentClass = $Torrent['IsSnatched'] ? ' snatched_torrent' : ''; ?> diff --git a/sections/top10/torrents.php b/sections/top10/torrents.php index a2c5e280..99261df6 100644 --- a/sections/top10/torrents.php +++ b/sections/top10/torrents.php @@ -453,7 +453,7 @@ function generate_torrent_table($Caption, $Tag, $Details, $Limit) { if($Scene) { $ExtraInfo.=$AddExtra.'Scene'; $AddExtra=' / '; } if($Year>0) { $ExtraInfo.=$AddExtra.$Year; $AddExtra=' '; } if($RemasterTitle) { $ExtraInfo.=$AddExtra.$RemasterTitle; } - if($IsSnatched) { if($GroupCategoryID == 1) { $ExtraInfo .= ' / '; } $ExtraInfo.='Snatched!'; } + if($IsSnatched) { if($GroupCategoryID == 1) { $ExtraInfo .= ' / '; } $ExtraInfo.= Format::torrent_label('Snatched!'); } if($ExtraInfo!='') { $ExtraInfo = "- [$ExtraInfo]"; } diff --git a/sections/top10/votes.php b/sections/top10/votes.php index 30db9c02..74b5f2b7 100644 --- a/sections/top10/votes.php +++ b/sections/top10/votes.php @@ -310,14 +310,14 @@ $DisplayName = $Number .' - '.$GroupName.''; if($Torrent['IsSnatched']) { - $DisplayName .= ' Snatched!'; + $DisplayName .= ' ' . Format::torrent_label('Snatched!'); } if ($Torrent['FreeTorrent'] == '1') { - $DisplayName .= ' Freeleech!'; + $DisplayName .= ' ' . Format::torrent_label('Freeleech!'); } elseif ($Torrent['FreeTorrent'] == '2') { - $DisplayName .= ' Neutral Leech!'; + $DisplayName .= ' ' . Format::torrent_label('Neutral leech!'); } elseif (Torrents::has_token($TorrentID)) { - $DisplayName .= ' Personal Freeleech!'; + $DisplayName .= ' ' . Format::torrent_label('Personal Freeleech!'); } $SnatchedTorrentClass = $Torrent['IsSnatched'] ? ' snatched_torrent' : ''; ?> diff --git a/sections/torrents/browse.php b/sections/torrents/browse.php index ef1711cb..79066181 100644 --- a/sections/torrents/browse.php +++ b/sections/torrents/browse.php @@ -948,7 +948,7 @@ function header_link($SortKey,$DefaultWay="DESC") { if(trim($Torrents['remastertitle'][$Key])) { $ExtraInfo.=$AddExtra.$Torrents['remastertitle'][$Key]; $AddExtra=" - "; } elseif($Torrents['remastered'][$Key]=="1") { $ExtraInfo.=$AddExtra."Remastered"; $AddExtra=" - "; } if($Torrents['year'][$Key]>"0") { $ExtraInfo.=$AddExtra.$Torrents['year'][$Key]; $AddExtra=" / "; } - if($Torrents['freetorrent'][$Key]=="1") { $ExtraInfo.=$AddExtra.'Freeleech!'; $AddExtra=" / "; } + if($Torrents['freetorrent'][$Key]=="1") { $ExtraInfo.=$AddExtra. Format::torrent_label('Freeleech!'); $AddExtra=" / "; } ?>