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

TrackXML.php 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php
/* GNU 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/>.

 */

require_once($install_path . '/database.php');
require_once($install_path . '/data/Track.php');
require_once('xml.php');

class TrackXML {

27
	public static function getTopTags($artist, $name) {
Mike Sheldon's avatar
Mike Sheldon committed
28
		global $base_url;
29 30

		$track = new Track($name, $artist);
31
		$tags = $track->getTopTags();
32 33 34

		$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');

35
		$root = $xml->addChild('toptags', null);
36 37 38
		$root->addAttribute('artist', $artist);
		$root->addAttribute('track', $name);

39
		foreach($tags as &$tag) {
40
			$tag_node = $root->addChild('tag', null);
41
			$tag_node->addChild('name', repamp($tag['tag']));
42 43
			$tag_node->addChild('count', $tag['freq']);
			$tag_node->addChild('url', Server::getTagURL($row['tag']));
44 45
		}

46
		return $xml;
47 48
	}

49
	public static function getTags($artist, $name, $userid) {
Mike Sheldon's avatar
Mike Sheldon committed
50
		global $base_url;
51 52 53 54 55 56 57 58 59 60 61 62 63

		$track = new Track($name, $artist);
		$tags = $track->getTags($userid);

		$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');

		$root = $xml->addChild('tags', null);
		$root->addAttribute('artist', $artist);
		$root->addAttribute('track', $name);

		foreach($tags as $tag) {
			$tag_node = $root->addChild('tag', null);
			$tag_node->addChild('name', repamp($tag));
64
			$tag_node->addChild('url', Server::getTagURL($row['tag']));
65 66
		}

67 68 69 70 71 72 73 74 75 76 77 78 79 80
		return $xml;
	}

	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) . ")");
		} catch (exception $ex) {}

		$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
81

82
		return $xml;
83 84
	}

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
	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) . ")");
		} catch (exception $ex) {}

		$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');

		return $xml;
	}

100 101
}
?>