We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit b580278d authored by Jonas Haraldsson's avatar Jonas Haraldsson

Merge branch 'master' into smarty3upgrade

Fixed Conflicts:
	nixtape/templating.php
parents de0e4f16 32a29f59
How to install phpdoc and generate api docs gnu-fm (on Debian Squeeze)
----------
---
1. Install dependencies and phpDocumentor-alpha:
---
# aptitude install php-pear php5-xsl
# pear channel-discover pear.phpdoc.org
# pear install phpdoc/phpDocumentor-alpha
for other ways to install, see http://www.phpdoc.org/docs/latest/for-users/installation.html
---
2. Create dir which will be holding the docs, and generate docs:
---
cd /path/to/gnu-fm/nixtape
mkdir docs
phpdoc -d 2.0/ -t docs/
The docs can now be found at http://mynixtapedomain.tld/docs/
Add something similar to this to your crontab to keep the docs up-to-date:
0 0 * * * phpdoc -q -d /path/to/gnu-fm/nixtape/2.0/ -t /path/to/gnu-fm/nixtape/docs
......@@ -88,7 +88,7 @@ Installing Smarty:
$ tar zxvf Smarty*
$ tar zxvf smarty*
$ mv smarty/libs/* smarty/.
$ mv smarty-gettext/block.t.php smarty/.
$ mv smarty-gettext/block.t.php smarty/plugins/.
Installing ADOdb:
$ cp external_dependencies/adodb511.tgz /var/www/htdocs/nixtape/.
......
......@@ -30,10 +30,10 @@ if (!isset($config_version) || $config_version != $version) {
die('Configuration file is out of date. Please delete it (and associated database) and <a href="install.php">reinstall</a>.'); //TODO: Upgrade script for release versions
}
if (isset($_GET['hs']) && isset($_GET['p'])) {
if (substr($_GET['p'], 0, 3) == '1.2') {
if (isset($_REQUEST['hs']) && isset($_REQUEST['p'])) {
if (substr($_REQUEST['p'], 0, 3) == '1.2') {
require_once('submissions/1.2/handshake.php');
} else if (substr($_GET['p'], 0, 3) == '1.1') {
} else if (substr($_REQUEST['p'], 0, 3) == '1.1') {
require_once('submissions/1.1/handshake.php');
}
} else {
......
......@@ -30,11 +30,11 @@ require_once('temp-utils.php');
$supported_protocols = array('1.1');
if (!isset($_GET['p']) || !isset($_GET['u']) || !isset($_GET['c'])) {
if (!isset($_REQUEST['p']) || !isset($_REQUEST['u']) || !isset($_REQUEST['c'])) {
die("FAILED\n");
}
$protocol = $_GET['p']; $username = $_GET['u']; $client = $_GET['c'];
$protocol = $_REQUEST['p']; $username = $_REQUEST['u']; $client = $_REQUEST['c'];
if (!in_array($protocol, $supported_protocols)) {
die("FAILED Unsupported protocol version\n");
......
......@@ -26,15 +26,15 @@ require_once('temp-utils.php');
$supported_protocols = array('1.2', '1.2.1');
if (!isset($_GET['p']) || !isset($_GET['u']) || !isset($_GET['t']) || !isset($_GET['a']) || !isset($_GET['c'])) {
if (!isset($_REQUEST['p']) || !isset($_REQUEST['u']) || !isset($_REQUEST['t']) || !isset($_REQUEST['a']) || !isset($_REQUEST['c'])) {
die("BADAUTH\n");
}
$protocol = $_GET['p'];
$username = $_GET['u'];
$timestamp = $_GET['t'];
$auth_token = $_GET['a'];
$client = $_GET['c'];
$protocol = $_REQUEST['p'];
$username = $_REQUEST['u'];
$timestamp = $_REQUEST['t'];
$auth_token = $_REQUEST['a'];
$client = $_REQUEST['c'];
if ($client == 'import') {
die("FAILED Import scripts are broken\n"); // this should be removed or changed to check the version once import.php is fixed
......@@ -48,8 +48,8 @@ if (abs($timestamp - time()) > 300) {
die("BADTIME\n"); // let's try a 5-minute tolerance
}
if (isset($_GET['api_key']) && isset($_GET['sk'])) {
$authed = check_web_auth($username, $auth_token, $timestamp, $_GET['api_key'], $_GET['sk']);
if (isset($_REQUEST['api_key']) && isset($_REQUEST['sk'])) {
$authed = check_web_auth($username, $auth_token, $timestamp, $_REQUEST['api_key'], $_REQUEST['sk']);
} else {
$authed = check_standard_auth($username, $auth_token, $timestamp);
}
......
......@@ -2,12 +2,19 @@ Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^user/([^/]+)/?$ user-profile.php?user=$1 [NC,QSA]
RewriteRule ^user/([^/]+)/journal/?$ user-journal.php?user=$1 [NC,QSA]
RewriteRule ^user/([^/]+)/groups/?$ user-groups.php?user=$1 [NC,QSA]
RewriteRule ^user/([^/]+)/recent-tracks/?$ user-recent-tracks.php?user=$1 [NC,QSA]
RewriteRule ^user/([^/]+)/stats/?$ user-stats.php?user=$1 [NC,QSA]
RewriteRule ^user/([^/]+)/station/?$ user-station.php?user=$1 [NC,QSA]
RewriteRule ^user/([^/]+)/recommended/?$ user-recommended.php?user=$1 [NC,QSA]
RewriteRule ^user/([^/]+)/library/?$ user-library.php?user=$1 [NC,QSA]
RewriteRule ^user/([^/]+)/library/music/?$ user-library.php?user=$1&section=music [NC,QSA]
RewriteRule ^user/([^/]+)/library/scrobbles/?$ user-library.php?user=$1&section=scrobbles [NC,QSA]
RewriteRule ^user/([^/]+)/library/loved/?$ user-library.php?user=$1&section=loved [NC,QSA]
RewriteRule ^user/([^/]+)/library/banned/?$ user-library.php?user=$1&section=banned [NC,QSA]
RewriteRule ^user/([^/]+)/library/tags/?$ user-library.php?user=$1&section=tags [NC,QSA]
RewriteRule ^user/([^/]+)/library/tags/([^/]+)/?$ user-library.php?user=$1&section=tags&tag=$2 [NC,QSA]
RewriteRule ^user/([^/]+)/library/music/([^/]+)/?$ user-library.php?user=$1&section=music&artist=$2 [NC,QSA]
RewriteRule ^user/([^/]+)/library/music/([^/]+)/([^/]+)/?$ user-library.php?user=$1&section=music&artist=$2&album=$3 [NC,QSA]
RewriteRule ^user/([^/]+)/library/music/([^/]+)/_/([^/]+)/?$ user-library.php?user=$1&section=music&artist=$2&track=$3 [NC,QSA]
RewriteRule ^artist/([^/]+)/track/([^/]+)/edit/?$ track-add.php?artist=$1&track=$2 [NC,QSA]
RewriteRule ^artist/([^/]+)/track/([^/]+)/tag/?$ track-tag.php?artist=$1&track=$2 [NC,QSA]
RewriteRule ^artist/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&track=$2 [NC,QSA]
......@@ -21,12 +28,8 @@ RewriteRule ^artist/([^/]+)/album/([^/]+)/?$ album.php?artist=$1&album=$2 [
RewriteRule ^artist/([^/]+)/?$ artist.php?artist=$1 [NC,QSA]
RewriteRule ^artist/([^/]+)/manage/?$ artist-manage.php?artist=$1 [NC,QSA]
RewriteRule ^artist/([^/]+)/tag/?$ artist-tag.php?artist=$1 [NC,QSA]
RewriteRule ^group/new$ edit_group.php?group=new [NC,QSA]
RewriteRule ^group/([^/]+)/?$ group.php?group=$1 [NC,QSA]
RewriteRule ^group/?$ group.php [NC,QSA]
RewriteRule ^country/([^/]+)/?$ location.php?country=$1 [NC,QSA]
RewriteRule ^logout login.php?action=logout [NC,QSA]
RewriteRule ^listen listen.php [NC,QSA]
RewriteRule ^music popular.php [NC,QSA]
RewriteRule ^users users.php [NC,QSA]
RewriteRule ^tag/([^/]+)/?$ tag.php?tag=$1 [NC,QSA]
This diff is collapsed.
......@@ -42,9 +42,17 @@ if (!isset($this_user) || !$this_user->manages($artist->name)) {
$edit = false;
if (isset($_GET['album'])) {
$edit = true;
$album = new Album($_GET['album'], $artist->name);
}
try {
$album = new Album($_GET['album'], $artist->name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Album not found.');
$smarty->assign('details', 'The album ' . $_GET['album'] . ' by artist ' . $artist->name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
}
$smarty->assign('artist', $artist);
$smarty->assign('edit', $edit);
......
<?php
/* GNU FM -- a free network service for sharing your music listening habits
Copyright (C) 2013 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/>.
*/
function album_menu($album, $active_page) {
global $this_user;
$submenu = array(
array('name' => _('Overview'), 'url' => $album->getURL()),
);
foreach($submenu as &$item) {
$item['active'] = ($item['name'] == $active_page);
}
return $submenu;
}
try {
$album = new Album($_GET['album'], $_GET['artist']);
$smarty->assign('album', $album);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Album not found.');
$smarty->assign('details', 'The album ' . $_GET['album'] . ' by artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
try {
$artist = new Artist($album->artist_name);
$smarty->assign('artist', $artist);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $track->artist_name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('edit_link', $album->getEditURL());
$smarty->assign('add_track_link', $album->getAddTrackURL());
}
$smarty->assign('pagetitle', $artist->name . ' : ' . $album->name);
......@@ -19,40 +19,18 @@
*/
require_once('database.php');
require_once('templating.php');
require_once('data/Album.php');
$album = new Album($_GET['album'], $_GET['artist']);
try {
$artist = new Artist($album->artist_name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $track->artist_name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('edit_link', $album->getEditURL());
}
require_once('album-menu.php');
$smarty->assign('name', $album->name);
$smarty->assign('id', $album->id);
$smarty->assign('artist', $artist);
$smarty->assign('album', $album);
$smarty->assign('pagetitle', $artist->name . ' : ' . $album->name);
$aAlbumTracks = $album->getTracks();
if ($aAlbumTracks) {
$smarty->assign('tracks', $aAlbumTracks);
}
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('add_track_link', $album->getAddTrackURL());
}
$smarty->assign('extra_head_links', array(
array(
'rel' => 'meta',
......@@ -62,5 +40,4 @@ $smarty->assign('extra_head_links', array(
)
));
$smarty->assign('headerfile', 'album-header.tpl');
$smarty->display('album.tpl');
......@@ -135,6 +135,42 @@ class ArtistXML {
return $xml;
}
public static function getTopFans($artistname, $limit, $cache) {
global $adodb;
try {
$artist = new Artist($artistname);
$res = $artist->getTopListeners($limit, 0, False, null, null, $cache);
} catch (Exception $e) {
return XML::error('error', '7', 'Invalid resource specified');
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('topfans', null);
$root->addAttribute('artist', $artist->name);
$i = $offset + 1;
foreach($res as &$row) {
try {
$user = new User($row['username']);
$user_node = $root->addChild('user', null);
$user_node->addChild('name', $user->name);
$user_node->addChild('realname', $user->fullname);
$user_node->addChild('url', repamp($user->getURL()));
$image_small = $user_node->addChild('image', null);
$image_small->addAttribute('size', 'small');
$image_medium = $user_node->addChild('image', null);
$image_medium->addAttribute('size', 'medium');
$image_large = $user_node->addChild('image', null);
$image_large->addAttribute('size', 'large');
$user_node->addChild('weight', $row['freq']);
} catch (Exception $e) {}
$i++;
}
return $xml;
}
public static function getTopTags($artistName, $limit, $cache) {
try {
......
<?php
/* GNU FM -- a free network service for sharing your music listening habits
Copyright (C) 2013 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/>.
*/
require_once($install_path . '/data/Library.php');
require_once('xml.php');
/**
* Class with functions that returns XML-formatted data involving a user's library.
*
* These functions are mainly used by web service methods.
*
* @package API
*/
class LibraryXML {
public static function removeScrobble($userid, $timestamp, $artist, $track) {
$result = Library::removeScrobble($userid, $timestamp, $artist, $track);
if (!$result) {
return XML::error('error', '7', 'Invalid resource specified');
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
return $xml;
}
}
......@@ -34,12 +34,32 @@ class TrackXML {
public static function addTags($userid, $artist, $album, $trackName, $tags) {
try {
$track = new Track($trackName, $artist);
$track->addTags($tags, $userid);
$res = $track->addTags($tags, $userid);
} catch (Exception $e) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
if(!$res) {
$xml = XML::error('failed', '7', 'Invalid resource specified');
} else {
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
}
return $xml;
}
public static function removeTag($userid, $artist, $trackName, $tag) {
try {
$track = new Track($trackName, $artist);
$res = $track->removeTag($tag, $userid);
} catch (Exception $e) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
if(!$res) {
$xml = XML::error('failed', '7', 'Invalid resource specified');
} else {
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
}
return $xml;
}
......@@ -71,6 +91,41 @@ class TrackXML {
return $xml;
}
public static function getTopFans($name, $artistname, $limit, $cache) {
global $adodb;
try {
$track = new Track($name, $artistname);
$res = $track->getTopListeners($limit, 0, False, null, null, $cache);
} catch (Exception $e) {
return XML::error('error', '7', 'Invalid resource specified');
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('topfans', null);
$root->addAttribute('artist', $track->artist_name);
$root->addAttribute('track', $track->name);
foreach($res as &$row) {
try {
$user = new User($row['username']);
$user_node = $root->addChild('user', null);
$user_node->addChild('name', $user->name);
$user_node->addChild('realname', $user->fullname);
$user_node->addChild('url', repamp($user->getURL()));
$image_small = $user_node->addChild('image', null);
$image_small->addAttribute('size', 'small');
$image_medium = $user_node->addChild('image', null);
$image_medium->addAttribute('size', 'medium');
$image_large = $user_node->addChild('image', null);
$image_large->addAttribute('size', 'large');
$user_node->addChild('weight', $row['freq']);
} catch (Exception $e) {}
}
return $xml;
}
public static function getTags($artist, $name, $userid, $limit, $cache) {
try {
......@@ -100,61 +155,68 @@ class TrackXML {
}
public static function ban($artist, $name, $userid) {
global $adodb;
try {
$res = $adodb->Execute('INSERT INTO Banned_Tracks VALUES ('
. $userid . ', '
. $adodb->qstr($name) . ', '
. $adodb->qstr($artist) . ', '
. time() . ')');
} catch (Exception $e) {}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$track = new Track($name, $artist);
$res = $track->ban($userid);
} catch (Exception $e) {
return XML::error('failed', '7', 'Invalid resource specified');
}
if(!$res) {
$xml = XML::error('failed', '7', 'Invalid resource specified');
} else {
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
}
return $xml;
}
public static function love($artist, $name, $userid) {
global $adodb;
try {
$res = $adodb->Execute('INSERT INTO Loved_Tracks VALUES ('
. $userid . ', '
. $adodb->qstr($name) . ', '
. $adodb->qstr($artist) . ', '
. time() . ')');
} catch (Exception $e) {}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$track = new Track($name, $artist);
$res = $track->love($userid);
} catch (Exception $e) {
return XML::error('failed', '7', 'Invalid resource specified');
}
if(!$res) {
$xml = XML::error('failed', '7', 'Invalid resource specified');
} else {
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
}
return $xml;
}
public static function unban($artist, $name, $userid) {
global $adodb;
try {
$res = $adodb->Execute('DELETE FROM Banned_Tracks WHERE userid=' . $userid . ' AND track=' . $adodb->qstr($name) . ' AND artist=' . $adodb->qstr($artist));
} catch (Exception $e) {}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$track = new Track($name, $artist);
$res = $track->unban($userid);
} catch (Exception $e) {
return XML::error('failed', '7', 'Invalid resource specified');
}
if(!$res) {
$xml = XML::error('failed', '7', 'Invalid resource specified');
} else {
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
}
return $xml;
}
public static function unlove($artist, $name, $userid) {
global $adodb;
try {
$res = $adodb->Execute('DELETE FROM Loved_Tracks WHERE userid=' . $userid . ' AND track=' . $adodb->qstr($name) . ' AND artist=' . $adodb->qstr($artist));
} catch (Exception $e) {}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$track = new Track($name, $artist);
$res = $track->unlove($userid);
} catch (Exception $e) {
return XML::error('failed', '7', 'Invalid resource specified');
}
if(!$res) {
$xml = XML::error('failed', '7', 'Invalid resource specified');
} else {
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
}
return $xml;
}
}
......@@ -18,80 +18,102 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once('../../config.php');
require_once($install_path . '/database.php');
require_once($install_path . '/templating.php');
require_once($install_path . '/data/Server.php');
require_once($install_path . '/data/clientcodes.php');
function displayError($error_msg) {
global $smarty;
$smarty->assign('error_msg', $error_msg);
$smarty->display('api_auth.tpl');
exit();
}
$smarty->assign('site_name', $site_name);
if ($logged_in) {
$smarty->assign('username', $this_user->name);
}
// We always need the api_key parameter and parameter cb or token
if (!isset($_REQUEST['api_key']) || !(isset($_REQUEST['cb']) || isset($_REQUEST['token']))) {
displayError('Must submit a combination of parameters api_key and cb or api_key and token to proceed.');
// Web app auth stage 1
} elseif (isset($_GET['api_key']) && isset($_GET['cb']) && !isset($_REQUEST['token'])) {
$token = Server::getAuthToken();
$smarty->assign('stage', 'webapp1');
$smarty->assign('token', $token);
$smarty->assign('cb', $_GET['cb']);
$smarty->assign('api_key', $_GET['api_key']);
// Desktop app auth stage 1
} elseif (isset($_GET['api_key']) && isset($_GET['token']) && !isset($_GET['cb']) && !isset($_POST['token'])) {
require_once('../../database.php');
?>
<html>
<body>
<?php
if (isset($_POST['username'], $_POST['api_key'], $_POST['token'])) {
// Authenticate the user using the submitted password
// Ensures the token exists and is not already bound to a user
$query = 'SELECT * FROM Auth WHERE token = ? AND username IS NULL';
$params = array($_GET['token']);
try {
$result = $adodb->GetOne('SELECT username FROM Users WHERE '
. 'lower(username) = ' . $adodb->qstr(strtolower($_POST['username'])) . ' AND '
. 'password = ' . $adodb->qstr(md5($_POST['password'])));
$result = $adodb->GetRow($query, $params);