Empty commit

This commit is contained in:
Git 2013-07-28 08:00:53 +00:00
parent f74903145c
commit ded9f7ddad
18 changed files with 714 additions and 68 deletions

View File

@ -0,0 +1,251 @@
<?
class SiteHistory {
private static $Categories = array(1 => "Code", "Event", "Milestone", "Policy", "Release", "Staff Change");
private static $SubCategories = array(1 => "Announcement", "Blog Post", "Change Log", "Forum Post", "Wiki");
private static $Tags = array(
"api",
"celebration",
"class.primary",
"class.secondary",
"collage",
"community",
"contest",
"design",
"donate",
"editing",
"editorial",
"feature",
"featured.article",
"featured.album",
"featured.product",
"finances",
"format",
"forum",
"freeleech",
"freeleech.tokens",
"gazelle",
"hierarchy",
"inbox",
"infrastructure",
"interview",
"irc",
"log",
"neutral.leech",
"notifications",
"ocelot",
"paranoia",
"picks.guest",
"picks.staff",
"promotion",
"ratio",
"report",
"request",
"requirement",
"retirement",
"rippy",
"search",
"settings",
"stats",
"store",
"stylesheet",
"tagging",
"transcode",
"toolbox",
"top.10",
"torrent",
"torrent.group",
"upload",
"vanity.house",
"voting",
"whitelist",
"wiki");
public static function get_months() {
$Results = G::$Cache->get_value("site_history_months");
if (!$Results) {
G::$DB->query("
SELECT DISTINCT
YEAR(DATE) AS Year, MONTH(Date) AS Month, MONTHNAME(Date) AS MonthName
FROM site_history
ORDER BY Date DESC");
$Results = G::$DB->to_array();
G::$Cache->cache_value("site_history_months", $Results, 0);
}
return $Results;
}
public static function get_event($ID) {
if (!empty($ID)) {
G::$DB->query("
SELECT
ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
FROM site_history
WHERE ID = '$ID'
ORDER BY Date DESC");
return G::$DB->next_record();
}
}
public static function get_latest_events($Limit) {
self::get_events(null, null, null, null, null, null, $Limit);
}
public static function get_events($Month, $Year, $Title, $Category, $SubCategory, $Tags, $Limit) {
$Month = (int) $Month;
$Year = (int) $Year;
$Title = db_string($Title);
$Category = (int) $Category;
$SubCategory = (int) $SubCategory;
$Tags = db_string($Tags);
$Limit = (int) $Limit;
$Where = array();
if (!empty($Month)) {
$Where[] = " MONTH(Date) = '$Month' ";
}
if (!empty($Year)) {
$Where[] = " YEAR(Date) = '$Year' ";
}
if (!empty($Title)) {
$Where[] = " Title LIKE '%$Title%' ";
}
if (!empty($Category)) {
$Where[] = " Category = '$Category '";
}
if (!empty($SubCategory)) {
$Where[] = " SubCategory = '$SubCategory '";
}
if (!empty($Tags)) {
$Tags = explode(",", $Tags);
$Or = "(";
foreach($Tags as $Tag) {
$Tag = trim($Tag);
$Or .= " Tags LIKE '%$Tag%' OR ";
}
if (strlen($Or) > 1) {
$Or = rtrim($Or, "OR ");
$Or .= ")";
$Where[] = $Or;
}
}
if (!empty($Limit)) {
$Limit = " LIMIT $Limit";
} else {
$Limit = "";
}
if (count($Where) > 0) {
$Query = " WHERE " . implode("AND", $Where);
} else {
$Query = "";
}
G::$DB->query("
SELECT
ID, Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date
FROM site_history
$Query
ORDER BY Date DESC
$Limit");
return G::$DB->to_array();
}
public static function add_event($Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID) {
if (empty($Date)) {
$Date = sqltime();
} else {
list($Y, $M, $D) = explode('-', $Date);
if (!checkdate($M, $D, $Y)) {
error("Error");
}
}
$Title = db_string($Title);
$Link = db_string($Link);
$Category = (int) $Category;
$SubCategory = (int) $SubCategory;
$Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
$ExplodedTags = explode(",", $Tags);
foreach($ExplodedTags as $Tag) {
if (!in_array($Tag, self::get_tags())) {
error("Invalid tag");
}
}
$Body = db_string($Body);
$UserID = (int) $UserID;
if (empty($Title) || empty($Category) || empty($SubCategory)) {
error("Error");
}
G::$DB->query("
INSERT INTO site_history
(Title, Url, Category, SubCategory, Tags, Body, AddedBy, Date)
VALUES
('$Title', '$Link', '$Category', '$SubCategory', '$Tags', '$Body', '$UserID', '$Date')");
G::$Cache->delete_value("site_history_months");
}
public static function update_event($ID, $Date, $Title, $Link, $Category, $SubCategory, $Tags, $Body, $UserID) {
if (empty($Date)) {
$Date = sqltime();
} else {
$Date = db_string($Date);
list($Y, $M, $D) = explode('-', $Date);
if (!checkdate($M, $D, $Y)) {
error("Error");
}
}
$ID = (int) $ID;
$Title = db_string($Title);
$Link = db_string($Link);
$Category = (int) $Category;
$SubCategory = (int) $SubCategory;
$Tags = db_string(strtolower((preg_replace('/\s+/', '', $Tags))));
$ExplodedTags = explode(",", $Tags);
foreach($ExplodedTags as $Tag) {
if (!in_array($Tag, self::get_tags())) {
error("Invalid tag");
}
}
$Body = db_string($Body);
$UserID = (int) $UserID;
if (empty($ID) || empty($Title) || empty($Category) || empty($SubCategory)) {
error("Error");
}
G::$DB->query("
UPDATE site_history
SET
Title = '$Title',
Url = '$Link',
Category = '$Category',
SubCategory = '$SubCategory',
Tags = '$Tags',
Body = '$Body',
AddedBy = '$UserID',
Date = '$Date'
WHERE
ID = '$ID'");
G::$Cache->delete_value("site_history_months");
}
public static function delete_event($ID) {
if (empty($ID)) {
error(404);
}
G::$DB->query("DELETE FROM site_history WHERE ID = '$ID'");
G::$Cache->delete_value("site_history_months");
}
public static function get_categories() {
return self::$Categories;
}
public static function get_sub_categories() {
return self::$SubCategories;
}
public static function get_tags() {
return self::$Tags;
}
}

View File

@ -0,0 +1,210 @@
<?
class SiteHistoryView {
public static function render_linkbox() {
if (check_perms('users_mod')
) { ?>
<div class="linkbox">
<a href="sitehistory.php?action=edit" class="brackets">Create</a>
</div>
<? }
}
public static function render_events($Events) {
$Text = new Text;
$Categories = SiteHistory::get_categories();
$SubCategories = SiteHistory::get_sub_categories();
$CanEdit = check_perms('users_mod') ;
foreach($Events as $Event) { ?>
<div class="box">
<div class="head colhead_dark">
<div class="title">
<? if ($CanEdit) { ?>
<a class="brackets" href="sitehistory.php?action=edit&amp;id=<?=$Event['ID']?>">Edit</a>
<? } ?>
<?=date('F d, Y', strtotime($Event['Date']));?>
-
<a href="sitehistory.php?action=search&amp;category=<?=$Event['Category']?>">[<?=$Categories[$Event['Category']]?>]</a>
<a href="sitehistory.php?action=search&amp;subcategory=<?=$Event['SubCategory']?>">[<?=$SubCategories[$Event['SubCategory']]?>]</a>
<? if (!empty($Event['Url'])) { ?>
<a href="<?=$Event['Url']?>"><?=$Event['Title']?></a>
<? } else { ?>
<?=$Event['Title']?>
<? } ?>
</div>
<div class="tags">
<? self::render_tags($Event['Tags'])?>
</div>
</div>
<? if (!empty($Event['Body'])) { ?>
<div class="body">
<?=$Text->full_format($Event['Body'])?>
</div>
<? } ?>
</div>
<? }
}
private static function render_tags($Tags) {
$Tags = explode(',', $Tags);
natcasesort($Tags);
$FormattedTags = "";
foreach($Tags as $Tag) {
$FormattedTags .= "<a href='sitehistory.php?action=search&amp;tags=". $Tag . "'>" . $Tag . "</a>, ";
}
echo rtrim($FormattedTags, ', ');
}
public static function render_months($Months) { ?>
<div class="box">
<div class="head">Calendar</div>
<div class="pad">
<? $Year = "";
foreach ($Months as $Month) {
if ($Month['Year'] != $Year) {
$Year = $Month['Year'];
echo "<h2>$Year</h2>";
} ?>
<a style="margin-left: 5px;" href="sitehistory.php?month=<?=$Month['Month']?>&amp;year=<?=$Month['Year']?>"><?=$Month['MonthName']?></a>
<? } ?>
</div>
</div>
<? }
public static function render_search() { ?>
<div class="box">
<div class="head">Search</div>
<div class="pad">
<form class="search_form" action="sitehistory.php" method="GET">
<input type="hidden" name="action" value="search" />
<input type="text" id="title" name="title" size="20" placeholder="Title"/>
<br /><br/>
<input type="text" id="tags" name="tags" size="20" placeholder="Comma separated tags"/>
<br /><br/>
<select name="category" id="category">
<option value="0">Choose a category</option>
<? $Categories = SiteHistory::get_categories();
foreach($Categories as $Key => $Value) { ?>
<option <?=$Key == $Event['Category'] ? 'selected="selected"' : ''?> value="<?=$Key?>"><?=$Value?></option>
<? } ?>
</select>
<br /><br/>
<select name="subcategory">
<option value="0">Choose a subcategory</option>
<? $SubCategories = SiteHistory::get_sub_categories();
foreach($SubCategories as $Key => $Value) { ?>
<option <?=$Key == $Event['SubCategory'] ? 'selected="selected"' : ''?> value="<?=$Key?>"><?=$Value?></option>
<? } ?>
</select>
<br /><br/>
<input value="Search" type="submit" />
</form>
</div>
</div>
<? }
public static function render_edit_form($Event) { ?>
<form id="event_form" method="POST">
<? if ($Event) { ?>
<input type="hidden" name="action" value="take_edit" />
<input type="hidden" name="id" value="<?=$Event['ID']?>" />
<? } else { ?>
<input type="hidden" name="action" value="take_create" />
<? } ?>
<input type="hidden" name="auth" value="<?=G::$LoggedUser['AuthKey']?>" />
<table cellpadding="6" cellspacing="1" border="0" class="layout border" width="100%">
<tr>
<td class="label">Title:</td>
<td>
<input type="text" id="title" name="title" size="50" class="required" value="<?=$Event['Title']?>" />
</td>
</tr>
<tr>
<td class="label">Link:</td>
<td>
<input type="text" id="url" name="url" size="50" value="<?=$Event['Url']?>" />
</td>
</tr>
<tr>
<td class="label">Date:</td>
<td>
<input type="date" id="date" name="date" class="required"
<? if ($Event) {?>
value="<?=date('Y-m-d', strtotime($Event['Date']))?>"/>
<? } ?>
</td>
</tr>
<tr>
<td class="label">Category:</td>
<td>
<select id="category" name="category" class="required">
<option value="0">Choose a category</option>
<? $Categories = SiteHistory::get_categories();
foreach($Categories as $Key => $Value) { ?>
<option <?=$Key == $Event['Category'] ? 'selected="selected"' : ''?> value="<?=$Key?>"><?=$Value?></option>
<? } ?>
</select>
</td>
</tr>
<tr>
<td class="label">Subcategory:</td>
<td>
<select id="category" name="sub_category" class="required">
<option value="0">Choose a subcategory</option>
<? $SubCategories = SiteHistory::get_sub_categories();
foreach($SubCategories as $Key => $Value) { ?>
<option <?=$Key == $Event['SubCategory'] ? 'selected="selected"' : ''?> value="<?=$Key?>"><?=$Value?></option>
<? } ?>
</select>
</td>
</tr>
<tr>
<td class="label">Tags:</td>
<td>
<input type="text" id="tags" name="tags" placeholder="Comma separated tags, use periods for spaces" size="50" value="<?=$Event['Tags']?>"/>
<select id="tag_list">
<option>Choose tags</option>
<? $Tags = SiteHistory::get_tags();
foreach($Tags as $Tag) { ?>
<option><?=$Tag?></option>
<? } ?>
</select>
</td>
</tr>
<tr>
<td class="label">Body:</td>
<td>
<textarea id="body" name="body" cols="90" rows="8" tabindex="1" onkeyup="resize('body')"><?=$Event['Body']?></textarea>
</td>
</tr>
</table>
<input type="submit" name="submit" value="Submit" />
<? if ($Event) { ?>
<input type="submit" name="delete" value="Delete" />
<? } ?>
</form>
<? }
public static function render_recent_sidebar($Events) { ?>
<div class="box">
<div class="head colhead_dark">
<strong><a href="sitehistory.php">Latest site history</a></strong>
</div>
<ul class="stats nobullet">
<? $Categories = SiteHistory::get_categories();
foreach ($Events as $Event) {?>
<li>
<a href="sitehistory.php?action=search&amp;category=<?=$Event['Category']?>">[<?=$Categories[$Event['Category']]?>]</a>
<? if (!empty($Event['Url'])) { ?>
<a href="<?=$Event['Url']?>"><?=Format::cut_string($Event['Title'], 20)?></a>
<? } else { ?>
<?=Format::cut_string($Event['Title'], 20)?>
<? }
} ?>
</ul>
</div>
<? }
}

View File

@ -724,6 +724,19 @@ CREATE TABLE `schedule` (
`NextBiWeekly` int(2) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `site_history` (
`ID` int(10) NOT NULL AUTO_INCREMENT,
`Title` varchar(255) DEFAULT NULL,
`Url` varchar(255) NOT NULL DEFAULT '',
`Category` tinyint(2) DEFAULT NULL,
`SubCategory` tinyint(2) DEFAULT NULL,
`Tags` mediumtext,
`AddedBy` int(10) DEFAULT NULL,
`Date` datetime DEFAULT NULL,
`Body` mediumtext,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `sphinx_a` (
`gid` int(11) DEFAULT NULL,
`aname` text CHARACTER SET utf8 COLLATE utf8_bin,

View File

@ -131,6 +131,8 @@
?>
</ul>
</div>
<? //SiteHistoryView::render_recent_sidebar(SiteHistory::get_events(null, null, null, null, null, null, 5));
?>
<div class="box">
<div class="head colhead_dark"><strong>Stats</strong></div>
<ul class="stats nobullet">

View File

@ -468,21 +468,22 @@ function next_hour() {
// If a user has downloaded more than 10 GiBs while on ratio watch, disable leeching privileges, and send the user a message
$DB->query("
SELECT ID
SELECT ID, torrent_pass
FROM users_info AS i
JOIN users_main AS m ON m.ID = i.UserID
WHERE i.RatioWatchEnds != '0000-00-00 00:00:00'
AND i.RatioWatchDownload + 10 * 1024 * 1024 * 1024 < m.Downloaded
AND m.Enabled = '1'
AND m.can_leech = '1'");
$Users = $DB->to_pair('torrent_pass', 'ID');
$UserIDs = $DB->collect('ID');
if (count($UserIDs) > 0) {
if (count($Users) > 0) {
$Subject = 'Leeching Disabled';
$Message = 'You have downloaded more then 10 GiB while on Ratio Watch. Your leeching privileges have been disabled. Please reread the rules and refer to this guide on how to improve your ratio https://'.SSL_SITE_URL.'/wiki.php?action=article&amp;id=110';
foreach ($UserIDs as $UserID) {
$Message = 'You have downloaded more then 10 GiB while on Ratio Watch. Your leeching privileges have been disabled. Please reread the rules and refer to this guide on how to improve your ratio https://' . SSL_SITE_URL . '/wiki.php?action=article&amp;id=110';
foreach ($Users as $TorrentPass => $UserID) {
Misc::send_pm($UserID, 0, $Subject, $Message);
send_irc('PRIVMSG #reports :!leechdisabled Downloaded 10 GB+ on Ratio Watch. https://'.SSL_SITE_URL."/user.php?id=$UserID");
send_irc('PRIVMSG #reports :!leechdisabled Downloaded 10 GB+ on Ratio Watch. https://' . SSL_SITE_URL . "/user.php?id=$UserID");
Tracker::update_tracker('update_user', array('passkey' => $TorrentPass, 'can_leech' => '0'));
}
$DB->query("
@ -490,7 +491,7 @@ function next_hour() {
JOIN users_main AS m ON m.ID = i.UserID
SET m.can_leech = '0',
i.AdminComment = CONCAT('$sqltime - Leeching privileges disabled by ratio watch system for downloading more than 10 GBs on ratio watch. - required ratio: ', m.RequiredRatio, '\n\n', i.AdminComment)
WHERE m.ID IN(".implode(',', $UserIDs).')');
WHERE m.ID IN(" . implode(',', $Users) . ')');
}
}

View File

@ -0,0 +1,30 @@
<?
if (!check_perms('users_mod') ) {
error(403);
}
if (is_number($_GET['id'])) {
$ID = $_GET['id'];
$Event = SiteHistory::get_event($ID);
}
if ($ID) {
$Title = "Edit";
} else {
$Title = "Create";
}
View::show_header($Title, "jquery.validate,form_validate,site_history");
?>
<div class="header">
<? if ($ID) { ?>
<h2>Edit event</h2>
<? } else { ?>
<h2>Create new event</h2>
<? } ?>
</div>
<?
SiteHistoryView::render_edit_form($Event);
View::show_footer();

View File

@ -0,0 +1,52 @@
<?
define('DEFAULT_LIMIT', 10);
$Limit = DEFAULT_LIMIT;
if (is_number($_GET['month'])) {
$Month = $_GET['month'];
$Limit = null;
}
if (is_number($_GET['year'])) {
$Year = $_GET['year'];
$Limit = null;
}
if (!empty($_GET['title'])) {
$Title = $_GET['title'];
$Limit = null;
}
if (!empty($_GET['category'])) {
$Category = $_GET['category'];
$Limit = null;
}
if (!empty($_GET['subcategory'])) {
$SubCategory = $_GET['subcategory'];
$Limit = null;
}
if (!empty($_GET['tags'])) {
$Tags = $_GET['tags'];
$Limit = null;
}
$Events = SiteHistory::get_events($Month, $Year, $Title, $Category, $SubCategory, $Tags, $Limit);
$Months = SiteHistory::get_months();
View::show_header("Site History");
?>
<div class="header">
<h2><a href="sitehistory.php">Site History</a> <?=$Month && $Year ? date("- F, Y", mktime(0, 0, 0, $Month, 1, $Year)) : '' ?></h2>
<?
SiteHistoryView::render_linkbox();
?>
</div>
<div class="sidebar">
<?
SiteHistoryView::render_search();
SiteHistoryView::render_months($Months);
?>
</div>
<div class="main_column">
<?
SiteHistoryView::render_events($Events);
?>
</div>
<?
View::show_footer();

View File

@ -0,0 +1,33 @@
<?
enforce_login();
if (!check_perms('users_mod')) {
error(403);
}
if (!empty($_POST['action'])) {
switch ($_POST['action']) {
case 'take_create':
include(SERVER_ROOT . "/sections/sitehistory/take_create.php");
break;
case 'take_edit':
include(SERVER_ROOT . "/sections/sitehistory/take_edit.php");
break;
default:
error(404);
break;
}
} elseif(!empty($_GET['action'])) {
switch ($_GET['action']) {
case 'search':
include(SERVER_ROOT . "/sections/sitehistory/history.php");
break;
case 'edit':
include(SERVER_ROOT . "/sections/sitehistory/edit.php");
break;
default:
error(404);
break;
}
} else {
include(SERVER_ROOT . "/sections/sitehistory/history.php");
}

View File

@ -0,0 +1,9 @@
<?
authorize();
if (!check_perms('users_mod') ) {
error(403);
}
SiteHistory::add_event($_POST['date'], $_POST['title'], $_POST['url'], $_POST['category'], $_POST['sub_category'], $_POST['tags'], $_POST['body'], $LoggedUser['ID']);
header("Location: sitehistory.php");

View File

@ -0,0 +1,12 @@
<?
authorize();
if (!check_perms('users_mod') ) {
error(403);
}
if ($_POST['submit']) {
SiteHistory::update_event($_POST['id'], $_POST['date'], $_POST['title'], $_POST['url'], $_POST['category'], $_POST['sub_category'], $_POST['tags'], $_POST['body'], $LoggedUser['ID']);
} elseif($_POST['delete']) {
SiteHistory::delete_event($_POST['id']);
}
header("Location: sitehistory.php");

View File

@ -12,6 +12,9 @@
$DB->query("
INSERT INTO changelog (Message, Author, Time)
VALUES ('$Message', '$Author', NOW())");
$ID = $DB->inserted_id();
SiteHistory::add_event(sqltime(), "Changelog $ID", "tools.php?action=change_log", 1, 3, "", $Message, $LoggedUser['ID']);
}
if ($_POST['perform'] == 'remove' && !empty($_POST['change_id'])) {
$ID = (int) $_POST['change_id'];

View File

@ -156,31 +156,11 @@
</td>
</tr>
</form>
<!--<strip> -->
<? if (check_perms('users_mod') || check_perms('admin_advanced_user_search')) { ?>
<tr>
<td class="label">Username:</td>
<td><input type="text" id="username"/></td>
</tr>
<tr>
<td class="label">Email:</td>
<td><input type="text" id="email"/></td>
</tr>
<tr>
<td class="label">IP:</td>
<td>
<input type="text" id="ip"/>
<a class="brackets" href="#" id="lookup">Lookup</a>
</td>
</tr>
<? } ?>
<!--</strip> -->
</table>
</div>
<!--<strip> -->
<table id="results"></table>
<!--</strip> -->
<?
} elseif (!empty($LoggedUser['DisableInvites'])) { ?>

View File

@ -3,7 +3,7 @@
$DB->query("
SELECT username
FROM lastfm_users
WHERE ID = '$UserID'");
WHERE ID = $UserID");
if ($DB->has_results()) {
list($LastFMUsername) = $DB->next_record();
$LastFMInfo = LastFM::get_user_info($LastFMUsername);
@ -13,21 +13,21 @@
<div class="head colhead_dark">Last.fm</div>
<ul class="stats nobullet">
<li>
Username: <a id="lastfm_username" href="<?=($LastFMInfo['user']['url'])?>" target="_blank" title="<?=($LastFMInfo['user']['name'])?> on Last.fm: <?=(number_format($LastFMInfo['user']['playcount']))?> plays, <?=(number_format($LastFMInfo['user']['playlists']))?> playlists."><?=($LastFMInfo['user']['name'])?></a>
Username: <a id="lastfm_username" href="<?=$LastFMInfo['user']['url']?>" target="_blank" title="<?=$LastFMInfo['user']['name']?> on Last.fm: <?=number_format($LastFMInfo['user']['playcount'])?> plays, <?=number_format($LastFMInfo['user']['playlists'])?> playlists."><?=$LastFMUsername?></a>
</li>
<div id="lastfm_stats"<? if ($OwnProfile == true): ?> data-uid="<?=($OwnProfile)?>"<? endif; ?>>
<div id="lastfm_stats"<?=$OwnProfile ? ' data-uid="1"' : ''?>>
</div>
<li>
<a href="#" id="lastfm_expand" onclick="return false" class="brackets">Show more info</a>
<?
//Append the reload stats button only if allowed on the current user page.
$Response = $Cache->get_value('lastfm_clear_cache_' . $LoggedUser . '_' . $_GET['id']);
if (empty($Response)) :
?>
if (empty($Response)) {
?>
<span id="lastfm_reload_container">
<a href="#" id="lastfm_reload" onclick="return false" class="brackets">Reload stats</a>
</span>
<? endif; ?>
<? } ?>
</li>
</ul>
</div>

2
sitehistory.php Normal file
View File

@ -0,0 +1,2 @@
<?
require('classes/script_start.php');

View File

@ -27,6 +27,11 @@ $(document).ready(function() {
$("#request_form").preventDoubleSubmission();
}
break;
case "sitehistory":
if (query['action'] == "edit") {
$("#event_form").validate();
}
break;
default:
break;
}

View File

@ -28,16 +28,16 @@
// Attach to document as lastfm_expand links are added dynamically when fetching the data.
$(document).on('click', "#lastfm_expand", function () {
// Make hidden entries visible and remove the expand button.
if ( $(this).attr("href") == "#sharedartists" ) {
if ($(this).attr("href") == "#sharedartists") {
sharedArtists = sharedArtists.replace(/\ class="hidden"/g,"");
sharedArtists = sharedArtists.replace(/<li>\[<a\ href=\"#sharedartists.*\]<\/li>/,"");
} else if ( $(this).attr("href") == "#topartists" ) {
} else if ($(this).attr("href") == "#topartists") {
topArtists = topArtists.replace(/\ class="hidden"/g,"");
topArtists = topArtists.replace(/<li>\[<a\ href=\"#topartists.*\]<\/li>/,"");
} else if ( $(this).attr("href") == "#topalbums" ) {
} else if ($(this).attr("href") == "#topalbums") {
topAlbums = topAlbums.replace(/\ class="hidden"/g,"");
topAlbums = topAlbums.replace(/<li>\[<a\ href=\"#topalbums.*\]<\/li>/,"");
} else if ( $(this).attr("href") == "#toptracks" ) {
} else if ($(this).attr("href") == "#toptracks") {
topTracks = topTracks.replace(/\ class="hidden"/g,"");
topTracks = topTracks.replace(/<li>\[<a\ href=\"#toptracks.*\]<\/li>/,"");
}
@ -98,7 +98,7 @@
html += '<li id="lastfm_loading">Loading...</li>';
div.html(html);
// If the data isn't expanded hide most of the info.
if ( expanded == false ) {
if (expanded == false) {
$("#lastfm_stats").children(":not(.lastfm_essential)").addClass("hidden");
$("#lastfm_reload_container").addClass("hidden");
} else {
@ -128,12 +128,12 @@
//Own profile, don't show tasteometer and shared artists.
tasteometer = " ";
sharedArtists = " ";
} else {
} else if (username) {
$.get('user.php?action=lastfm_compare&username=' + username, function (response) {
// Two separate elements are received from one Last.fm API call.
var tasteometerHtml = "";
var sharedArtistsHtml = "";
if ( response ) {
if (response && response != "false") {
json = JSON.parse(response);
if (json != null && json['error']) {
console.log("Tasteometer: " + json['message']);
@ -156,7 +156,7 @@
compatibility = "Unknown";
tasteometerHtml += compatibility;
} else {
if (compatibility < 50) {
if (compatibility < 50) {
background = 'rgb(255, '+Math.floor(255*compatibility/50)+', 0)'
} else {
background = 'rgb('+Math.floor((1-(compatibility-50)/50)*255)+', 255, 0)'
@ -173,11 +173,13 @@
if (j['artists']['matches'] != 0) {
sharedArtistsHtml += '<li>Shared artists:</li><li><ul class="nobullet">';
var k = initialCount;
if (a.length < 3) k = a.length;
for (var i = 0; i < k; i++) {
sharedArtistsHtml += '<li><a href="artist.php?artistname=' + escapeAmpUrl(a[i]['name']) + '">' + escapeHtml(a[i]['name']) + '</a></li>'
}
if ( a.length > 3 ) {
if (a.length < 3) {
k = a.length;
}
for (var i = 0; i < k; i++) {
sharedArtistsHtml += '<li><a href="artist.php?artistname=' + escapeAmpUrl(a[i]['name']) + '">' + escapeHtml(a[i]['name']) + '</a></li>'
}
if (a.length > 3) {
for (i = 3; i < a.length; i++) {
sharedArtistsHtml += '<li class="hidden"><a href="artist.php?artistname=' + escapeAmpUrl(a[i]['name']) + '">' + escapeHtml(a[i]['name']) + '</a></li>'
}
@ -203,9 +205,12 @@
}
function getLastPlayedTrack(div) {
if (!username) {
return;
}
$.get('user.php?action=lastfm_last_played_track&username=' + username, function (response) {
var html = "";
if ( response ) {
if (response && response != "false") {
var json = JSON.parse(response);
if (json != null && json['error']) {
console.log("Last played track: " + json['message']);
@ -216,7 +221,9 @@
lastPlayedTrack = " ";
} else {
// Fix Last.fm API returning more than one entry despite limit on certain conditions.
if ( typeof(json[0]) === "object" ) json = json[0];
if (typeof(json[0]) === "object") {
json = json[0];
}
html += '<li class="lastfm_essential">Last played: ';
html += '<a href="artist.php?artistname=' + escapeAmpUrl(json['artist']['#text']) + '">' + escapeHtml(json['artist']['#text']) + '</a> - <a href="torrents.php?artistname=' + escapeAmpUrl(json['artist']['#text']) +'&filelist=' + escapeAmpUrl(json['name']) + '">' + escapeHtml(json['name']) + '</a>';
html += "</li>";
@ -230,9 +237,12 @@
}
function getTopArtists(div) {
if (!username) {
return;
}
$.get('user.php?action=lastfm_top_artists&username=' + username, function (response) {
var html;
if ( response ) {
if (response && response != "false") {
var json = JSON.parse(response);
if (json != null && json['error']) {
console.log("Top artists: " + json['message']);
@ -240,7 +250,7 @@
} else if (json == null) {
console.log("Error: json == null");
topArtists = " ";
} else if ( json['topartists']['total']==0 ) {
} else if (json['topartists']['total'] == 0) {
// No top artists for the specified user, possibly a new Last.fm account.
// Allow removing the loading message regardless.
topArtists = " ";
@ -250,15 +260,17 @@
var j = json['topartists']['artist'];
html += '<ul class="nobullet">';
var k = initialCount;
if (j.length < 3) k = j.length;
if (j.length < 3) {
k = j.length;
}
for (var i = 0; i < k; i++) {
html += '<li><a href="artist.php?artistname=' + escapeAmpUrl(j[i]['name']) + '">' + escapeHtml(j[i]['name']) + '</a></li>'
}
if ( j.length > 3 ) {
if (j.length > 3) {
for (i = 3; i < j.length; i++) {
html += '<li class="hidden"><a href="artist.php?artistname=' + escapeAmpUrl(j[i]['name']) + '">' + escapeHtml(j[i]['name']) + '</a></li>'
}
html+= '<li><a href="#topartists" id="lastfm_expand" onclick="return false" class="brackets">Expand</a></li>'
html += '<li><a href="#topartists" id="lastfm_expand" onclick="return false" class="brackets">Expand</a></li>'
}
html += '</ul>';
html += "</li>";
@ -272,9 +284,12 @@
}
function getTopAlbums(div) {
if (!username) {
return;
}
$.get('user.php?action=lastfm_top_albums&username=' + username, function (response) {
var html;
if ( response ) {
if (response && response != "false") {
var json = JSON.parse(response);
if (json != null && json['error']) {
console.log("Top albums: " + json['message']);
@ -282,7 +297,7 @@
} else if (json == null) {
console.log("Error: json == null");
topAlbums = " ";
} else if ( json['topalbums']['total']==0 ) {
} else if (json['topalbums']['total'] == 0) {
// No top artists for the specified user, possibly a new Last.fm account.
// Allow removing the loading message regardless.
topAlbums = " ";
@ -292,11 +307,13 @@
html += "<li>";
html += '<ul class="nobullet">';
var k = initialCount;
if (j.length < 3) k = j.length;
if (j.length < 3) {
k = j.length;
}
for (var i = 0; i < k; i++) {
html += '<li><a href="artist.php?artistname=' + escapeAmpUrl(j[i]['artist']['name']) + '">' + escapeHtml(j[i]['artist']['name']) + '</a> - <a href="torrents.php?searchstr=' + escapeAmpUrl(j[i]['name']) + '">' + escapeHtml(j[i]['name']) + '</a></li>'
}
if ( j.length>3 ) {
if (j.length > 3) {
for (i = 3; i < j.length; i++) {
html += '<li class="hidden"><a href="artist.php?artistname=' + escapeAmpUrl(j[i]['artist']['name']) + '">' + escapeHtml(j[i]['artist']['name']) + '</a> - <a href="torrents.php?searchstr=' + escapeAmpUrl(j[i]['name']) + '">' + escapeHtml(j[i]['name']) + '</a></li>'
}
@ -314,9 +331,12 @@
}
function getTopTracks(div) {
if (!username) {
return;
}
$.get('user.php?action=lastfm_top_tracks&username=' + username, function (response) {
var html;
if ( response ) {
if (response && response != "false") {
var json = JSON.parse(response);
if (json != null && json['error']) {
console.log("Toptracks: " + json['message']);
@ -324,7 +344,7 @@
} else if (json == null) {
console.log("Error: json == null");
topTracks = " ";
} else if ( json['toptracks']['total']==0 ) {
} else if (json['toptracks']['total'] == 0) {
// No top artists for the specified user, possibly a new Last.fm account.
// Allow removing the loading message regardless.
topTracks = " ";
@ -334,11 +354,13 @@
var j = json['toptracks']['track'];
html += '<ul class="nobullet">';
var k = initialCount;
if (j.length < 3) k = j.length;
if (j.length < 3) {
k = j.length;
}
for (var i = 0; i < k; i++) {
html += '<li><a href="artist.php?artistname=' + escapeAmpUrl(j[i]['artist']['name']) + '">' + escapeHtml(j[i]['artist']['name']) + '</a> - <a href="torrents.php?artistname=' + escapeAmpUrl(j[i]['artist']['name']) + '&filelist=' + escapeAmpUrl(j[i]['name']) + '">' + escapeHtml(j[i]['name']) + '</a></li>'
}
if ( j.length>3 ) {
if (j.length > 3) {
for (i = 3; i < j.length; i++) {
html += '<li class="hidden"><a href="artist.php?artistname=' + escapeAmpUrl(j[i]['artist']['name']) + '">' + escapeHtml(j[i]['artist']['name']) + '</a> - <a href="torrents.php?artistname=' + escapeAmpUrl(j[i]['artist']['name']) + '&filelist=' + escapeAmpUrl(j[i]['name']) + '">' + escapeHtml(j[i]['name']) + '</a></li>'
}

View File

@ -0,0 +1,18 @@
$(document).ready(function() {
var trimmed = false;
var tags = $("#tags");
$("#tag_list").change(function() {
if (tags.val().length == 0) {
trimmed = false;
} else {
trimmed = true;
}
if ($(this).prop("selectedIndex")) {
tags.val(tags.val() + "," + $(this).val());
if (!trimmed) {
tags.val(tags.val().substr(1, tags.val().length));
trimmed = true;
}
}
});
});

View File

@ -148,11 +148,14 @@ function ToggleWarningAdjust(selector) {
addDOMLoadEvent(ToggleIdenticons);
function ToggleIdenticons() {
var selected = $('#disableavatars').raw().selectedIndex;
if (selected == 2 || selected == 3) {
$('#identicons').gshow();
} else {
$('#identicons').ghide();
var disableAvatars = $('#disableavatars');
if (disableAvatars.size()) {
var selected = disableAvatars[0].selectedIndex;
if (selected == 2 || selected == 3) {
$('#identicons').gshow();
} else {
$('#identicons').ghide();
}
}
}