[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Librefm-commits] [1449] merge nixtape/data/ from trunk
From: |
Clint Adams |
Subject: |
[Librefm-commits] [1449] merge nixtape/data/ from trunk |
Date: |
Sun, 10 May 2009 03:21:58 +0000 |
Revision: 1449
http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1449
Author: clint
Date: 2009-05-10 03:21:57 +0000 (Sun, 10 May 2009)
Log Message:
-----------
merge nixtape/data/ from trunk
Modified Paths:
--------------
branches/stable/nixtape/data/Album.php
branches/stable/nixtape/data/Artist.php
branches/stable/nixtape/data/Server.php
branches/stable/nixtape/data/Statistic.php
branches/stable/nixtape/data/TagCloud.php
branches/stable/nixtape/data/Track.php
branches/stable/nixtape/data/User.php
Added Paths:
-----------
branches/stable/nixtape/database2.php
Modified: branches/stable/nixtape/data/Album.php
===================================================================
--- branches/stable/nixtape/data/Album.php 2009-05-10 03:14:19 UTC (rev
1448)
+++ branches/stable/nixtape/data/Album.php 2009-05-10 03:21:57 UTC (rev
1449)
@@ -77,7 +77,9 @@
$res = $mdb2->query("SELECT COUNT(*) AS scrobbles FROM
Scrobbles JOIN Track ON Scrobbles.track = Track.name WHERE Scrobbles.artist = "
. $mdb2->quote($this->artist_name, 'text') . ' AND
Track.album_name ='
. $mdb2->quote($this->name, 'text'));
- if(!$res->numRows()) {
+ if(PEAR::isError($res)) {
+ reportError($res->getMessage(), $res->getUserInfo());
+ } else if (!$res->numRows()) {
$c = 0;
} else {
$row = sanitize($res->fetchRow(MDB2_FETCHMODE_ASSOC));
@@ -142,8 +144,6 @@
$image = $aws_xml->Items->Item->MediumImage->URL;
$URI = $aws_xml->Items->Item->DetailPageURL;
-
- if ($image == "") { $image = $base_url . "/i/qm50.png"; $license =
"unknown-to-amazon";}
if ($image) {
Modified: branches/stable/nixtape/data/Artist.php
===================================================================
--- branches/stable/nixtape/data/Artist.php 2009-05-10 03:14:19 UTC (rev
1448)
+++ branches/stable/nixtape/data/Artist.php 2009-05-10 03:21:57 UTC (rev
1449)
@@ -52,7 +52,7 @@
. "mbid = " . $mdb2->quote($mbid, "text") . " OR "
. "name = " . $mdb2->quote($name, "text"));
if(!$res->numRows()) {
- PEAR::raiseError("No such artist: " . $name);
+ return(new PEAR_Error("No such artist: " . $name));
} else {
$row = sanitize($res->fetchRow(MDB2_FETCHMODE_ASSOC));
$this->name = $row["name"];
@@ -109,7 +109,7 @@
*/
function getTopTracks($number) {
global $mdb2;
- $res = $mdb2->query("SELECT track, COUNT(track) AS freq,
COUNT(DISTINCT username) AS listeners FROM Scrobbles WHERE rating<>'S' AND "
+ $res = $mdb2->query("SELECT track, COUNT(track) AS freq,
COUNT(DISTINCT username) AS listeners FROM Scrobbles WHERE"
. " artist = " . $mdb2->quote($this->name, 'text')
. " GROUP BY track ORDER BY freq DESC LIMIT " .
$mdb2->quote($number, "integer"));
while($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
@@ -130,9 +130,9 @@
function getURL() {
global $friendly_urls, $base_url;
if($friendly_urls) {
- return $base_url . "/artist/" .
urlencode(stripslashes($this->name));
+ return $base_url . "/artist/" .
rawurlencode(stripslashes($this->name));
} else {
- return $base_url . "/artist.php?artist=" .
urlencode(stripslashes($this->name));
+ return $base_url . "/artist.php?artist=" .
rawurlencode(stripslashes($this->name));
}
}
Modified: branches/stable/nixtape/data/Server.php
===================================================================
--- branches/stable/nixtape/data/Server.php 2009-05-10 03:14:19 UTC (rev
1448)
+++ branches/stable/nixtape/data/Server.php 2009-05-10 03:21:57 UTC (rev
1449)
@@ -21,7 +21,7 @@
require_once($install_path . '/database.php');
require_once($install_path . '/data/Artist.php');
-require_once($install_path . '/data/Group.php');
+// require_once($install_path . '/data/Group.php');
require_once($install_path . '/data/Track.php');
require_once($install_path . '/data/User.php');
require_once($install_path . "/data/sanitize.php");
@@ -66,12 +66,11 @@
LEFT JOIN Album l
ON l.artist_name=s.artist
AND l.name=s.album
+ LEFT JOIN Scrobble_Track st
+ ON s.stid = st.id
LEFT JOIN Track t
- ON lower(s.artist) = lower(t.artist)
- AND lower(s.album) = lower(t.album)
- AND lower(s.track) = lower(t.name)
- WHERE s.rating<>'S'
- AND lower(s.username) = " .
$mdb2->quote(strtolower($username), "text") . '
+ ON st.track = t.id
+ WHERE lower(s.username) = " .
$mdb2->quote(strtolower($username), "text") . '
ORDER BY
s.time DESC
LIMIT ' . $mdb2->quote($number, "integer"));
@@ -95,11 +94,10 @@
LEFT JOIN Album l
ON l.artist_name=s.artist
AND l.name=s.album
+ LEFT JOIN Scrobble_Track st
+ ON s.stid = st.id
LEFT JOIN Track t
- ON lower(s.artist) = lower(t.artist)
- AND lower(s.album) = lower(t.album)
- AND lower(s.track) = lower(t.name)
- WHERE s.rating<>'S'
+ ON st.track = t.id
ORDER BY
s.time DESC
LIMIT " . $mdb2->quote($number, "integer"));
@@ -155,7 +153,7 @@
static function getTopArtists($number=20) {
global $mdb2;
- $res = $mdb2->query("SELECT COUNT(artist) as c, artist FROM Scrobbles
WHERE rating<>'S' GROUP BY artist ORDER BY c DESC LIMIT 20");
+ $res = $mdb2->query("SELECT COUNT(artist) as c, artist FROM Scrobbles
GROUP BY artist ORDER BY c DESC LIMIT 20");
if(PEAR::isError($res)) {
return $res;
@@ -201,6 +199,7 @@
ON lower(n.artist) =
lower(t.artist_name)
AND lower(n.album) =
lower(t.album_name)
AND lower(n.track) =
lower(t.name)
+ AND lower(n.mbid) =
lower(t.mbid)
WHERE lower(username) = " .
$mdb2->quote(strtolower($username), "text") . "
ORDER BY t.streamable DESC, n.expires
DESC LIMIT " . $mdb2->quote($number, "integer"));
} else {
@@ -224,6 +223,7 @@
ON lower(n.artist) =
lower(t.artist_name)
AND lower(n.album) =
lower(t.album_name)
AND lower(n.track) =
lower(t.name)
+ AND lower(n.mbid) =
lower(t.mbid)
ORDER BY t.streamable DESC, n.expires
DESC LIMIT " . $mdb2->quote($number, "integer"));
}
@@ -248,7 +248,7 @@
$row["trackurl"] = Server::getTrackURL($row['artist'],
$row['album'], $row['track']);
// We really want to get an image URI from the database
and only fall back to qm50.png if we can't find an image.
- $row['albumart'] = $base_url . '/i/qm50.png';
+ $row['albumart'] = $base_url . 'themes/' .
$default_theme . '/images/qm50.png';
$row["licenseurl"] = $row["license"];
$row["license"] = simplify_license($row["licenseurl"]);
@@ -272,6 +272,8 @@
if ($component == 'edit')
{
return $base_url . "/user-edit.php";
+ } elseif ($component == 'delete') {
+ return $base_url . "/delete-profile.php";
}
elseif($friendly_urls)
{
@@ -279,49 +281,49 @@
$component = '';
else
$component = "/{$component}";
- return $base_url . "/user/" . urlencode($username) .
$component;
+ return $base_url . "/user/" . rawurlencode($username) .
$component;
}
else
{
- return $base_url . "/user-{$component}.php?user=" .
urlencode($username);
+ return $base_url . "/user-{$component}.php?user=" .
rawurlencode($username);
}
}
static function getGroupURL($groupname) {
global $friendly_urls, $base_url;
if($friendly_urls) {
- return $base_url . "/group/" . urlencode($groupname);
+ return $base_url . "/group/" . rawurlencode($groupname);
} else {
- return $base_url . "/group.php?group=" .
urlencode($groupname);
+ return $base_url . "/group.php?group=" .
rawurlencode($groupname);
}
}
static function getArtistURL($artist) {
global $friendly_urls, $base_url;
if($friendly_urls) {
- return $base_url . "/artist/" . urlencode($artist);
+ return $base_url . "/artist/" . rawurlencode($artist);
} else {
- return $base_url . "/artist.php?artist=" .
urlencode($artist);
+ return $base_url . "/artist.php?artist=" .
rawurlencode($artist);
}
}
static function getAlbumURL($artist, $album) {
global $friendly_urls, $base_url;
if($friendly_urls) {
- return $base_url . "/artist/" . urlencode($artist) .
"/album/" . urlencode($album);
+ return $base_url . "/artist/" . rawurlencode($artist) .
"/album/" . rawurlencode($album);
} else {
- return $base_url . "/album.php?artist=" .
urlencode($artist) . "&album=" . urlencode($album);
+ return $base_url . "/album.php?artist=" .
rawurlencode($artist) . "&album=" . rawurlencode($album);
}
}
static function getTrackURL($artist, $album, $track) {
global $friendly_urls, $base_url;
if ($friendly_urls && $album) {
- return $base_url . "/artist/" . urlencode($artist) .
"/album/" . urlencode($album) . "/track/" . urlencode($track);
+ return $base_url . "/artist/" . rawurlencode($artist) .
"/album/" . rawurlencode($album) . "/track/" . rawurlencode($track);
} elseif ($friendly_urls) {
- return $base_url . "/artist/" . urlencode($artist) .
"/track/" . urlencode($track);
+ return $base_url . "/artist/" . rawurlencode($artist) .
"/track/" . rawurlencode($track);
} else {
- return $base_url . "/track.php?artist=" .
urlencode($artist) . "&album=" . urlencode($album) . "&track=" .
urlencode($track);
+ return $base_url . "/track.php?artist=" .
rawurlencode($artist) . "&album=" . rawurlencode($album) . "&track=" .
rawurlencode($track);
}
}
Modified: branches/stable/nixtape/data/Statistic.php
===================================================================
--- branches/stable/nixtape/data/Statistic.php 2009-05-10 03:14:19 UTC (rev
1448)
+++ branches/stable/nixtape/data/Statistic.php 2009-05-10 03:21:57 UTC (rev
1449)
@@ -39,14 +39,12 @@
if (!is_string($table)) return false;
if (!is_integer($limit)) return false;
$query = "SELECT $field, count(*) AS count FROM $table";
- $query .= (!is_null($constraint) || ($table == "Scrobbles")) ? ' WHERE
' : null;
+ $query .= (!is_null($constraint)) ? ' WHERE ' : null;
if ($field == "track") {
$query .= (!is_null($constraint)) ? ' artist = ' .
$mdb2->quote($constraint, 'text') : null;
} else {
$query .= (!is_null($constraint)) ? ' username = ' .
$mdb2->quote($constraint, 'text') : null;
}
- $query .= (!is_null($constraint) && ($table == "Scrobbles")) ? ' AND '
: null;
- $query .= ($table == "Scrobbles") ? " rating <> 'S' " : null;
$query .= " GROUP BY $field ORDER BY count DESC LIMIT $limit";
$res = $mdb2->query($query);
if (PEAR::isError($res)) {
@@ -81,10 +79,8 @@
$query = "SELECT COUNT(*) as count, DATE(TO_TIMESTAMP(time)) as date
FROM $table";
if( strpos($connect_string , "mysql" ) === 0 ) $query = "SELECT
COUNT(*) as count,DATE(FROM_UNIXTIME(time)) as date FROM $table";
- $query .= (!is_null($constraint) || ($table == "Scrobbles")) ? ' WHERE
' : null;
+ $query .= (!is_null($constraint)) ? ' WHERE ' : null;
$query .= (!is_null($constraint)) ? ' username = ' .
$mdb2->quote($constraint, 'text') : null;
- $query .= (!is_null($constraint) && ($table == "Scrobbles")) ? ' AND '
: null;
- $query .= ($table == "Scrobbles") ? " rating <> 'S' " : null;
$query .= " GROUP BY date ORDER BY date DESC LIMIT $limit";
$res = $mdb2->query($query);
if (PEAR::isError($res)) {
Modified: branches/stable/nixtape/data/TagCloud.php
===================================================================
--- branches/stable/nixtape/data/TagCloud.php 2009-05-10 03:14:19 UTC (rev
1448)
+++ branches/stable/nixtape/data/TagCloud.php 2009-05-10 03:21:57 UTC (rev
1449)
@@ -18,8 +18,9 @@
*/
-require_once($install_path . '/database.php');
+require_once($install_path . '/database2.php');
require_once($install_path . '/data/Server.php');
+require_once($install_path . '/config.php'); // Should already be required
though.
class TagCloud {
/*
@@ -33,40 +34,60 @@
* @return array tagcloud
*/
static function generateTagCloud($table, $field, $limit = 40, $constraint
= null, $constrained_field = false) {
- global $mdb2;
+ global $adodb;
if (!is_string($field)) return false;
if (!is_string($table)) return false;
if (!is_integer($limit)) return false;
$sizes = array('xx-large', 'x-large', 'large', 'medium', 'small',
'x-small', 'xx-small');
$query = "SELECT $field, count(*) AS count FROM $table";
- $query .= (!is_null($constraint) || (($table == "Scrobbles") ||
($table == "Free_Scrobbles"))) ? ' WHERE ' : null;
+ $query .= (!is_null($constraint)) ? ' WHERE ' : null;
if ($constrained_field) {
- $query .= (!is_null($constraint)) ? " $constrained_field = " .
$mdb2->quote($constraint, 'text') : null;
+ $query .= (!is_null($constraint)) ? " $constrained_field = " .
$adodb->qstr($constraint) : null;
} elseif ($field == "track") {
- $query .= (!is_null($constraint)) ? ' artist = ' .
$mdb2->quote($constraint, 'text') : null;
+ $query .= (!is_null($constraint)) ? ' artist = ' .
$adodb->qstr($constraint) : null;
} else {
- $query .= (!is_null($constraint)) ? ' username = ' .
$mdb2->quote($constraint, 'text') : null;
+ $query .= (!is_null($constraint)) ? ' username = ' .
$adodb->qstr($constraint) : null;
}
- $query .= (!is_null($constraint) && (($table == "Scrobbles") ||
($table == "Free_Scrobbles"))) ? ' AND ' : null;
- $query .= (($table == "Scrobbles") || ($table == "Free_Scrobbles")) ?
" rating <> 'S' " : null;
$query .= " GROUP BY $field ORDER BY count DESC LIMIT $limit";
- $res = $mdb2->query($query);
- if (PEAR::isError($res)) {
- echo("ERROR - " . $res->getMessage());
- }
- if (!$res->numRows()) {
- return false;
+ $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
+ $res = $adodb->CacheGetAll(7200,$query);
+ if (!$res) {
+ echo("ERROR $query");
} else {
- $data = $res->fetchAll(MDB2_FETCHMODE_ASSOC);
- foreach($data as $count => &$i) {
- $i['size'] = $sizes[(int) ($count/(count($data)/7))];
+ foreach($res as $count => &$i) {
+ $i['size'] = $sizes[(int) ($count/(count($res)/7))];
}
- foreach($data as &$i){
+ foreach($res as &$i){
$i['pageurl'] = Server::getArtistURL($i['artist']);
}
- sort($data);
- return $data;
+ sort($res);
+ return $res;
}
}
+
+ /**
+ * Returns the preferred table to generate scrobble data from.
+ *
+ * @param string $area The are where we're displaying scrobble data;
one of 'main', 'user', 'group'. Optional: defaults to 'main'.
+ * @return string Usually 'Scrobbles' or 'Free_Scrobbles'.
+ * @author tobyink
+ */
+ static function scrobblesTable ($area = 'main')
+ {
+ // This array can be set up in config.php
+ global $scrobblecloud_table;
+
+ if (!empty($scrobblecloud_table[$area]))
+ {
+ return $scrobblecloud_table[$area];
+ }
+
+ if ($area == 'main')
+ {
+ return 'Free_Scrobbles';
+ }
+
+ return 'Scrobbles';
+ }
}
?>
Modified: branches/stable/nixtape/data/Track.php
===================================================================
--- branches/stable/nixtape/data/Track.php 2009-05-10 03:14:19 UTC (rev
1448)
+++ branches/stable/nixtape/data/Track.php 2009-05-10 03:21:57 UTC (rev
1449)
@@ -26,6 +26,7 @@
require_once($install_path . "/data/Server.php");
require_once($install_path . "/resolve-external.php");
require_once($install_path . "/licenses.php");
+require_once($install_path . '/utils/linkeddata.php');
/**
* Represents track data
@@ -35,6 +36,7 @@
class Track {
public $name, $artist_name, $album_name, $mbid, $duration, $streamable,
$license, $downloadurl, $streamurl;
+ public $id;
private $_playcount = false, $_listenercount = false;
@@ -63,6 +65,8 @@
$this->licenseurl = $row["license"];
$this->downloadurl =
resolve_external_url($row["downloadurl"]);
$this->streamurl =
resolve_external_url($row["streamurl"]);
+
+ $this->id = identifierTrack(null, $this->artist_name,
$this->name, $this->album_name, null, $this->mbid, null, null);
}
}
@@ -116,14 +120,19 @@
private function _getPlayCountAndListenerCount() {
global $mdb2;
- $res = $mdb2->query("SELECT COUNT(track) AS freq,
COUNT(DISTINCT username) AS listeners FROM Scrobbles WHERE rating<>'S' AND "
+ $res = $mdb2->query("SELECT COUNT(track) AS freq,
COUNT(DISTINCT username) AS listeners FROM Scrobbles WHERE"
. " artist = " . $mdb2->quote($this->artist_name,
'text')
. " AND track = " . $mdb2->quote($this->name, "text")
. " GROUP BY track ORDER BY freq DESC");
$row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
- $this->_playcount = $row['freq'];
- $this->_listenercount = $row['listeners'];
+ if (!isset($row)) {
+ $this->setPlaycount(0);
+ $this->setListenerCount(0);
+ } else {
+ $this->setPlaycount($row['freq']);
+ $this->setListenerCount($row['listeners']);
+ }
}
/**
Modified: branches/stable/nixtape/data/User.php
===================================================================
--- branches/stable/nixtape/data/User.php 2009-05-10 03:14:19 UTC (rev
1448)
+++ branches/stable/nixtape/data/User.php 2009-05-10 03:21:57 UTC (rev
1449)
@@ -34,7 +34,7 @@
public $name, $email, $fullname, $bio, $location, $homepage, $error,
$userlevel;
public $id, $acctid, $avatar_uri, $location_uri, $webid_uri,
$laconica_profile, $journal_rss;
- public $password, $has_identica;
+ public $password, $has_identica, $created, $modified, $uniqueid;
/**
* User constructor
@@ -73,6 +73,9 @@
$this->laconica_profile = $row["laconica_profile"];
$this->journal_rss = $row["journal_rss"];
$this->acctid = $this->getURL() . '#acct';
+ $this->created = $row["created"];
+ $this->modified = $row["modified"];
+ $this->uniqueid = $row["uniqueid"];
$this->has_identica =
preg_match('#^http://identi\.ca/#i', $this->laconica_profile);
@@ -81,6 +84,17 @@
}
}
+
+ public static function new_from_uniqueid_number ($uid)
+ {
+ global $mdb2;
+ $res = $mdb2->query(sprintf('SELECT * FROM Users WHERE uniqueid
= %d', (int)$uid));
+ if($res->numRows()) {
+ $row = $res->fetchRow(MDB2_FETCHMODE_ASSOC);
+ return new User($row['username'], $row);
+ }
+ }
+
function save ()
{
global $mdb2;
@@ -213,7 +227,7 @@
function getTopTracks($number=20) {
global $mdb2;
- $res = $mdb2->query("SELECT COUNT(track) as c, artist, album,
track FROM Scrobbles WHERE rating<>'S' AND
username=".$mdb2->quote($this->name,"text")." GROUP BY artist,album,track ORDER
BY c DESC LIMIT $number");
+ $res = $mdb2->query("SELECT COUNT(track) as c, artist, album,
track FROM Scrobbles WHERE username = ".$mdb2->quote($this->name,"text")."
GROUP BY artist,album,track ORDER BY c DESC LIMIT $number");
if(PEAR::isError($res)) {
return $res;
Added: branches/stable/nixtape/database2.php
===================================================================
--- branches/stable/nixtape/database2.php (rev 0)
+++ branches/stable/nixtape/database2.php 2009-05-10 03:21:57 UTC (rev
1449)
@@ -0,0 +1,38 @@
+<?php
+
+/* Libre.fm -- a free network service for sharing your music listening habits
+
+ Copyright (C) 2009 Free Software Foundation, Inc
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+if(!file_exists(dirname(__FILE__) . "/config.php")) {
+ die("Please run the <a href='install.php'>Install</a> script to
configure your installation");
+}
+
+require_once('config.php');
+require_once('adodb/adodb-exceptions.inc.php');
+require_once('adodb/adodb.inc.php');
+
+try {
+ $adodb =& NewADOConnection($adodb_connect_string);
+} catch (exception $e) {
+ var_dump($e);
+ adodb_backtrace($e->gettrace());
+}
+
+?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Librefm-commits] [1449] merge nixtape/data/ from trunk,
Clint Adams <=