summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/class/artist.class.php31
-rw-r--r--lib/class/metadata.class.php44
-rw-r--r--lib/class/plugin.class.php12
-rw-r--r--lib/class/song.class.php63
-rw-r--r--lib/init.php1
-rw-r--r--lib/preferences.php3
-rw-r--r--modules/infotools/openstrands.class.php16
-rw-r--r--stats.php41
-rw-r--r--templates/show_artist_box.inc.php11
-rw-r--r--templates/show_artists.inc.php11
-rw-r--r--templates/show_plugins.inc.php2
11 files changed, 185 insertions, 50 deletions
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php
index 2d12e8c6..15258e66 100644
--- a/lib/class/artist.class.php
+++ b/lib/class/artist.class.php
@@ -31,18 +31,21 @@ class Artist {
public $albums;
public $prefix;
+ // Constructed vars
+ public $_fake = false; // Set if construct_from_array() used
+
/**
* Artist
* Artist class, for modifing a artist
* Takes the ID of the artist and pulls the info from the db
*/
- function Artist($artist_id = 0) {
+ public function __construct($id='') {
/* If they failed to pass in an id, just run for it */
- if (!$artist_id) { return false; }
+ if (!$id) { return false; }
/* Assign id for use in get_info() */
- $this->id = intval($artist_id);
+ $this->id = intval($id);
/* Get the information from the db */
$info = $this->_get_info();
@@ -56,6 +59,25 @@ class Artist {
} //constructor
/**
+ * construct_from_array
+ * This is used by the metadata class specifically but fills out a Artist object
+ * based on a key'd array, it sets $_fake to true
+ */
+ public static function construct_from_array($data) {
+
+ $artist = new Artist(0);
+ foreach ($data as $key=>$value) {
+ $artist->$key = $value;
+ }
+
+ //Ack that this is not a real object from the DB
+ $artist->_fake = true;
+
+ return $artist;
+
+ } // construct_from_array
+
+ /**
* _get_info
* get's the vars for $this out of the database taken from the object
*/
@@ -186,6 +208,9 @@ class Artist {
$name = truncate_with_ellipsis(trim($this->prefix . " " . $this->name));
$this->f_name = $name;
+ // If this is a fake object, we're done here
+ if ($this->_fake) { return true; }
+
$this->f_name_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&amp;artist=" . $this->id . "\" title=\"" . $this->full_name . "\">" . $name . "</a>";
// Get the counts
diff --git a/lib/class/metadata.class.php b/lib/class/metadata.class.php
new file mode 100644
index 00000000..01db6072
--- /dev/null
+++ b/lib/class/metadata.class.php
@@ -0,0 +1,44 @@
+<?php
+/*
+
+ Copyright 2001 - 2007 Ampache.org
+ All Rights Reserved
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; version 2
+ of the License.
+
+ 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+/**
+ * metadata class
+ * This class is a abstraction layer for getting
+ * meta data for any object in Ampache, this includes
+ * album art, lyrics, id3tags, recommendations etc
+ * it makes use of Object::construct_from_array() as needed
+ */
+class metadata {
+
+ /**
+ * constructor
+ * We don't use this, as its really a static class
+ */
+ private __construct() {
+
+ // Rien a faire
+
+ } // constructor
+
+} // metadata
+
+?>
diff --git a/lib/class/plugin.class.php b/lib/class/plugin.class.php
index e5b9c485..37f707da 100644
--- a/lib/class/plugin.class.php
+++ b/lib/class/plugin.class.php
@@ -147,13 +147,13 @@ class Plugin {
/**
* is_installed
- * This checks to see if the current plugin is currently installed in the
+ * This checks to see if the specified plugin is currently installed in the
* database, it doesn't check the files for integrity
*/
- function is_installed() {
+ public static function is_installed($plugin_name) {
/* All we do is check the version */
- return $this->get_plugin_version();
+ return self::get_plugin_version($plugin_name);
} // is_installed
@@ -187,11 +187,11 @@ class Plugin {
/**
* get_plugin_version
- * This returns the version of the currently installed plugin
+ * This returns the version of the specified plugin
*/
- function get_plugin_version() {
+ public static function get_plugin_version($plugin_name) {
- $name = Dba::escape('Plugin_' . $this->_plugin->name);
+ $name = Dba::escape('Plugin_' . $plugin_name);
$sql = "SELECT * FROM `update_info` WHERE `key`='$name'";
$db_results = Dba::query($sql);
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index 123d33ad..2b63be6b 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -23,40 +23,40 @@
class Song {
/* Variables from DB */
- var $id;
- var $file;
- var $album; // album.id (Int)
- var $artist; // artist.id (Int)
- var $title;
- var $year;
- var $bitrate;
- var $rate;
- var $mode;
- var $size;
- var $time;
- var $track;
- var $genre; // genre.id (Int)
- var $type;
- var $mime;
- var $played;
- var $enabled;
- var $addition_time;
- var $update_time;
+ public $id;
+ public $file;
+ public $album; // album.id (Int)
+ public $artist; // artist.id (Int)
+ public $title;
+ public $year;
+ public $bitrate;
+ public $rate;
+ public $mode;
+ public $size;
+ public $time;
+ public $track;
+ public $genre; // genre.id (Int)
+ public $type;
+ public $mime;
+ public $played;
+ public $enabled;
+ public $addition_time;
+ public $update_time;
/* Setting Variables */
- var $_transcoded = false;
+ public $_transcoded = false;
+ public $_fake = false; // If this is a 'construct_from_array' object
- /*!
- @function Song
- @discussion Song class, for modifing a song.
- @param $song_id The ID of the song
+ /**
+ * Constructor
+ * Song class, for modifing a song.
*/
- function Song($song_id = 0) {
-
- if (!$song_id) { return false; }
+ public function __construct($id='') {
/* Assign id for use in get_info() */
- $this->id = intval($song_id);
+ $this->id = intval($id);
+
+ if (!$this->id) { return false; }
/* Get the information from the db */
if ($info = $this->_get_info()) {
@@ -64,12 +64,13 @@ class Song {
foreach ($info as $key=>$value) {
$this->$key = $value;
}
- // Format the Type of the song
- $this->format_type();
+ // Format the Type of the song
+ $this->format_type();
}
- } //constructor
+ return true;
+ } // constructor
/*!
@function _get_info
diff --git a/lib/init.php b/lib/init.php
index ad4a913e..6efa68a2 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -130,6 +130,7 @@ require_once $prefix . '/modules/getid3/getid3.php';
require_once $prefix . '/modules/infotools/Snoopy.class.php';
require_once $prefix . '/modules/infotools/AmazonSearchEngine.class.php';
require_once $prefix . '/modules/infotools/lastfm.class.php';
+require_once $prefix . '/modules/infotools/openstrands.class.php';
//require_once $prefix . '/modules/infotools/jamendoSearch.class.php';
/* Temp Fixes */
diff --git a/lib/preferences.php b/lib/preferences.php
index b35f3036..66338a05 100644
--- a/lib/preferences.php
+++ b/lib/preferences.php
@@ -113,7 +113,8 @@ function update_preferences($pref_id=0) {
case 'sample_rate':
$value = validate_bitrate($value);
break;
- /* MD5 the LastFM so it's not plainTXT */
+ /* MD5 the LastFM & MyStrands so it's not plainTXT */
+ case 'mystrands_pass':
case 'lastfm_pass':
/* If it's our default blanking thing then don't use it */
if ($value == '******') { unset($_REQUEST[$name]); break; }
diff --git a/modules/infotools/openstrands.class.php b/modules/infotools/openstrands.class.php
index e445e90f..51b4dee0 100644
--- a/modules/infotools/openstrands.class.php
+++ b/modules/infotools/openstrands.class.php
@@ -440,7 +440,6 @@ class openStrands {
} // recommend_tracks
-
/**
* set_filter
* This builds out the filter for this object, it's a per instance filter
@@ -494,6 +493,21 @@ class openStrands {
} // set_filter
/**
+ * set_auth_token
+ * This function should be called on load to set the auth_token, if you don't
+ * just hardcode it, also allows realtime switching between auth tokens
+ * so that users can use their own limits when querying
+ */
+ public static function set_auth_token($token) {
+
+ // Set it
+ self::$auth_token = $token;
+
+ //FIXME: We should log this event?
+
+ } // set_auth_token
+
+ /**
* run_query
* This builds a URL, runs it and then returns whatever we found
*/
diff --git a/stats.php b/stats.php
index 63fa4f3a..2b99df95 100644
--- a/stats.php
+++ b/stats.php
@@ -45,6 +45,47 @@ switch ($_REQUEST['action']) {
require_once Config::get('prefix') . '/templates/show_user_stats.inc.php';
break;
+ //FIXME:: The logic in here should be moved to our metadata class
+ case 'recommend_similar':
+ // For now this is just MyStrands so verify they've filled out stuff
+ if (!$GLOBALS['user']->has_access('25') || !$GLOBALS['user']->prefs['mystrands_pass'] || !$GLOBALS['user']->prefs['mystrands_user']) {
+ access_denied();
+ exit;
+ }
+
+ // We're good attempt to dial up MyStrands
+ OpenStrands::set_auth_token(Config::get('mystrands_developer_key'));
+ $openstrands = new OpenStrands($GLOBALS['user']->prefs['mystrands_user'],$GLOBALS['user']->prefs['mystrands_pass']);
+
+ if (!$openstrands) {
+ debug_event('openstrands','Unable to authenticate MyStrands user, or authtoken invalid','3');
+ Error::add('general','Unable to authenticate MyStrands user, or authtoken invalid');
+ }
+
+ // Do our recommendation
+ switch ($_REQUEST['type']) {
+ case 'artist':
+ $artist = new Artist($_REQUEST['id']);
+ $seed = array('name'=>array($artist->name));
+ $results = $openstrands->recommend_artists($seed);
+ break;
+ } // end switch
+
+ // Run through what we've found and build out the data
+ foreach ($results as $result) {
+
+ switch ($_REQUEST['type']) {
+ case 'artist':
+ $data['name'] = $result['ArtistName'];
+ $data['f_name_link'] = "<a href=\"" . $result['URI'] . "\">" . $data['name'] . "</a>";
+ $object_ids[] = Artist::construct_from_array($data);
+ break;
+ }
+ } // end foreach
+
+ require_once Config::get('prefix') . '/templates/show_artists.inc.php';
+
+ break;
/* Show their stats */
default:
/* Here's looking at you kid! */
diff --git a/templates/show_artist_box.inc.php b/templates/show_artist_box.inc.php
index 64757603..c2be0a83 100644
--- a/templates/show_artist_box.inc.php
+++ b/templates/show_artist_box.inc.php
@@ -22,7 +22,7 @@
$web_path = Config::get('web_path');
$title = _('Albums by') . " " . $artist->full_name;
-show_box_top(_('Albums by') . ' ' . $artist->full_name);
+show_box_top(_('Albums by') . ' ' . $artist->f_name);
if (Config::get('ratings')) {
echo "<div id=\"rating_" . $artist->id . "_artist\" style=\"display:inline;\">";
show_rating($artist->id, 'artist');
@@ -30,13 +30,16 @@ if (Config::get('ratings')) {
} // end if ratings ?>
<strong><?php echo _('Actions'); ?>:</strong>
<div style="padding-left:5px;">
-<a href="<?php echo $web_path; ?>/artists.php?action=show_all_songs&amp;artist=<?php echo $artist->id; ?>"><?php echo _("Show All Songs By") . " " . $artist->full_name; ?></a><br />
-<span class="text-action"><?php echo Ajax::text('?action=basket&type=artist&id=' . $artist->id,_('Play All Songs By') . ' ' . $artist->full_name,'play_full_artist'); ?></span>
-<span class="text-action"><?php echo Ajax::text('?action=basket&type=artist_random&id=' . $artist->id,_('Play Random Songs By') . ' ' . $artist->full_name,'play_random_artist'); ?></span>
+<a href="<?php echo $web_path; ?>/artists.php?action=show_all_songs&amp;artist=<?php echo $artist->id; ?>"><?php echo _("Show All Songs By") . " " . $artist->f_name; ?></a><br />
+<span class="text-action"><?php echo Ajax::text('?action=basket&type=artist&id=' . $artist->id,_('Play All Songs By') . ' ' . $artist->f_name,'play_full_artist'); ?></span>
+<span class="text-action"><?php echo Ajax::text('?action=basket&type=artist_random&id=' . $artist->id,_('Play Random Songs By') . ' ' . $artist->f_name,'play_random_artist'); ?></span>
<?php if ($GLOBALS['user']->has_access('50')) { ?>
<a href="<?php echo $web_path; ?>/artists.php?action=update_from_tags&amp;artist=<?php echo $artist->id; ?>"><?php echo _("Update from tags"); ?></a><br />
<a href="<?php echo $web_path; ?>/artists.php?action=show_rename&amp;artist=<?php echo $artist->id; ?>"><?php echo _("Rename Artist"); ?></a><br />
<a href="<?php echo $web_path; ?>/artists.php?action=show_similar&amp;artist=<?php echo $artist->id; ?>"><?php echo _("Find duplicate artists"); ?></a><br />
<?php } ?>
+<?php if (Plugin::is_installed('OpenStrands')) { ?>
+<a href="<?php echo $web_path; ?>/stats.php?action=recommend_similar&amp;type=artist&id=<?php echo $artist->id; ?>"><?php echo _('Recommend Similar'); ?></a><br />
+<?php } ?>
</div>
<?php show_box_bottom(); ?>
diff --git a/templates/show_artists.inc.php b/templates/show_artists.inc.php
index 7339b541..9848a7f0 100644
--- a/templates/show_artists.inc.php
+++ b/templates/show_artists.inc.php
@@ -36,10 +36,15 @@ $web_path = Config::get('web_path');
</tr>
<?php
/* Foreach through every artist that has been passed to us */
-//FIXME: These should come in as objects...
foreach ($object_ids as $artist_id) {
- $artist = new Artist($artist_id);
- $artist->format();
+ if (get_class($artist_id) == 'Artist') {
+ $artist = $artist_id;
+ $artist->format();
+ }
+ else {
+ $artist = new Artist($artist_id);
+ $artist->format();
+ }
?>
<tr id="artist_<?php echo $artist->id; ?>" class="<?php echo flip_class(); ?>">
<?php require Config::get('prefix') . '/templates/show_artist_row.inc.php'; ?>
diff --git a/templates/show_plugins.inc.php b/templates/show_plugins.inc.php
index 91428813..196475d4 100644
--- a/templates/show_plugins.inc.php
+++ b/templates/show_plugins.inc.php
@@ -31,7 +31,7 @@
<?php
foreach ($plugins as $plugin_name) {
$plugin = new Plugin($plugin_name);
- if (!$plugin->is_installed()) {
+ if (!Plugin::is_installed($plugin_name)) {
$action = "<a href=\"" . $web_path . "/admin/modules.php?action=install_plugin&amp;plugin=" . scrub_out($plugin_name) . "\">" .
_('Activate') . "</a>";
}