diff options
-rw-r--r-- | lib/class/dba.class.php | 2 | ||||
-rw-r--r-- | lib/class/error.class.php | 64 | ||||
-rw-r--r-- | lib/class/localplay.abstract.php | 9 | ||||
-rw-r--r-- | lib/class/preference.class.php | 42 | ||||
-rw-r--r-- | lib/class/rating.class.php | 12 | ||||
-rw-r--r-- | localplay.php | 37 | ||||
-rw-r--r-- | modules/localplay/httpq.controller.php | 57 | ||||
-rw-r--r-- | modules/localplay/mpd.controller.php | 72 | ||||
-rw-r--r-- | modules/plugins/Lastfm.plugin.php | 10 | ||||
-rw-r--r-- | modules/plugins/OpenStrands.plugin.php | 5 | ||||
-rw-r--r-- | server/ajax.server.php | 4 | ||||
-rw-r--r-- | server/localplay.ajax.php | 38 | ||||
-rw-r--r-- | templates/show_album.inc.php | 4 | ||||
-rw-r--r-- | templates/show_localplay_add_instance.inc.php | 26 | ||||
-rw-r--r-- | templates/sidebar_localplay.inc.php | 11 |
15 files changed, 308 insertions, 85 deletions
diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php index 62d18e00..c2c60fce 100644 --- a/lib/class/dba.class.php +++ b/lib/class/dba.class.php @@ -85,9 +85,9 @@ class Dba { public static function fetch_assoc($resource) { $result = mysql_fetch_assoc($resource); + debug_event('Assoc',self::$_sql,'6'); if (!$result) { -// debug_event('fetch_assoc',self::$_sql,'1'); return array(); } diff --git a/lib/class/error.class.php b/lib/class/error.class.php index 29c1c885..61202532 100644 --- a/lib/class/error.class.php +++ b/lib/class/error.class.php @@ -1,27 +1,5 @@ <?php /* - - Copyright (c) 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. - -*/ - - -/** Copyright (c) 2001 - 2007 Ampache.org All Rights Reserved @@ -38,8 +16,9 @@ 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. +*/ - +/** * Error class * This is the baic error class, its better now that we can use php5 * hello static functions and variables @@ -60,6 +39,19 @@ class Error { } // __construct /** + * __destruct + * This saves all of the errors that are left into the session + */ + public function __destruct() { + + + foreach (self::$errors as $key=>$error) { + $_SESSION['errors'][$key] = $error; + } + + } // __destruct + + /** * add * This is a public static function it adds a new error message to the array * It can optionally clobber rather then adding to the error message @@ -70,24 +62,21 @@ class Error { if (!isset(Error::$errors[$name])) { Error::$errors[$name] = $message; Error::$state = 1; - return true; + $_SESSION['errors'][$key] = $message; } - // They want us to clobber it - if ($clobber) { + elseif ($clobber) { Error::$state = 1; Error::$errors[$name] = $message; - return true; + $_SESSION['errors'][$key] = $message; } - // They want us to append the error, add a BR\n and then the message else { Error::$state = 1; Error::$errors[$name] .= "<br />\n" . $message; - return true; + $_SESSION['errors'][$key] .= "<br />\n" . $message; } - } // add /** @@ -116,5 +105,20 @@ class Error { } // display + /** + * auto_init + * This loads the errors from the session back into Ampache + */ + public static function auto_init() { + + if (!is_array($_SESSION['errors'])) { return false; } + + // Re-insert them + foreach ($_SESSION['errors'] as $key=>$error) { + self::add($key,$error); + } + + } // auto_init + } // Error diff --git a/lib/class/localplay.abstract.php b/lib/class/localplay.abstract.php index 1874e390..d8e21387 100644 --- a/lib/class/localplay.abstract.php +++ b/lib/class/localplay.abstract.php @@ -34,11 +34,18 @@ abstract class localplay_controller { abstract public function status(); abstract public function get_version(); // Returns the version of this plugin abstract public function get_description(); // Returns the description - abstract public function actions(); // Return an array of name=>link actions for the sidebar abstract public function is_installed(); // Returns an boolean t/f abstract public function install(); abstract public function uninstall(); + // For display we need the following 'instance' functions + abstract public function add_instance($data); + abstract public function delete_instance($id); + abstract public function get_instances(); + abstract public function instance_fields(); + abstract public function set_active_instance($uid); + abstract public function get_active_instance(); + /** * get_url * This returns the URL for the passed object diff --git a/lib/class/preference.class.php b/lib/class/preference.class.php index 6fb707fe..ef8a0a05 100644 --- a/lib/class/preference.class.php +++ b/lib/class/preference.class.php @@ -175,4 +175,46 @@ class Preference { } // insert + /** + * delete + * This deletes the specified preference, a name or a ID can be passed + */ + public static function delete($preference) { + + // First prepare + if (!is_numeric($preference)) { + $id = self::id_from_name($preference); + $name = $preference; + } + else { + $name = self::name_from_id($preference); + $id = $preference; + } + + $id = Dba::escape($id); + + // Remove the preference, then the user records of it + $sql = "DELETE FROM `preference` WHERE `id`='$id'"; + $db_results = Dba::query($sql); + + self::rebuild_preferences(); + + } // delete + + /** + * rebuild_preferences + * This removes any garbage and then adds back in anything missing preferences wise + */ + public static function rebuild_preferences() { + + // First remove garbage + $sql = "DELETE FROM `user_preference` USING `user_preference` LEFT JOIN `preference` ON `preference`.`id`=`user_preference`.`preference` " . + "WHERE `preference`.`id` IS NULL"; + $db_results = Dba::query($sql); + + // Now add anything that we are missing back in, except System + $sql = "SELECT * FROM `preference` WHERE `type`!='system'"; + + } // rebuild_preferences + } // end Preference class diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index 1ddd842a..ff7b940d 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -64,12 +64,12 @@ class Rating { $user_id = Dba::escape($user_id); - $sql = "SELECT `score` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$this->id' AND `object_type`='$this->type'"; + $sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$this->id' AND `object_type`='$this->type'"; $db_results = Dba::query($sql); $results = Dba::fetch_assoc($db_results); - return $results['score']; + return $results['rating']; } // get_user @@ -82,14 +82,14 @@ class Rating { */ public function get_average() { - $sql = "SELECT `score` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type'"; + $sql = "SELECT `rating` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type'"; $db_results = Dba::query($sql); $i = 0; while ($r = Dba::fetch_assoc($db_results)) { $i++; - $total += $r['score']; + $total += $r['rating']; } // while we're pulling results if ($total > 0) { @@ -123,11 +123,11 @@ class Rating { $db_results = Dba::query($sql); if ($existing = Dba::fetch_assoc($db_results)) { - $sql = "UPDATE `rating` SET `score`='$score' WHERE `id`='" . $existing['id'] . "'"; + $sql = "UPDATE `rating` SET `rating`='$score' WHERE `id`='" . $existing['id'] . "'"; $db_results = Dba::query($sql); } else { - $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`score`,`user`) VALUES " . + $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`rating`,`user`) VALUES " . " ('$this->id','$this->type','$score','" . $GLOBALS['user']->id . "')"; $db_results = Dba::query($sql); } diff --git a/localplay.php b/localplay.php index 06f081c7..4cc0b094 100644 --- a/localplay.php +++ b/localplay.php @@ -1,7 +1,7 @@ <?php /* - Copyright (c) 2001 - 2006 Ampache.org + Copyright (c) 2001 - 2007 Ampache.org All rights reserved. This program is free software; you can redistribute it and/or @@ -19,28 +19,17 @@ */ +require 'lib/init.php'; -require('lib/init.php'); - -/* If we are running a demo, quick while you still can! */ -if (conf('demo_mode')) { - exit(); -} - -$web_path = conf('web_path'); - -if($GLOBALS['user']->prefs['localplay_level'] < 1) { - access_denied(); - exit(); -} - -/* Scrub in the action */ -$action = scrub_in($_REQUEST['action']); - -show_template('header'); +show_header(); +switch ($_REQUEST['action']) { + case 'show_add_instance': + require_once Config::get('prefix') . '/templates/show_localplay_add_instance.inc.php'; + break; + case 'add_instance': -switch ($action) { + break; case 'delete_song': $song_id = scrub_in($_REQUEST['song_id']); $songs = array($song_id); @@ -70,13 +59,7 @@ switch ($action) { require_once (conf('prefix') . '/templates/show_localplay.inc.php'); break; default: - if ($localplay = init_localplay()) { - require_once (conf('prefix') . '/templates/show_localplay.inc.php'); - } - else { - $GLOBALS['error']->add_error('general',_('Localplay Init Failed')); - $GLOBALS['error']->print_error('general'); - } + // Rien a faire? break; } // end switch action diff --git a/modules/localplay/httpq.controller.php b/modules/localplay/httpq.controller.php index 7e812792..fde12a9d 100644 --- a/modules/localplay/httpq.controller.php +++ b/modules/localplay/httpq.controller.php @@ -128,14 +128,63 @@ class AmpacheHttpq extends localplay_controller { } // uninstall /** - * actions - * List all the special kick ass things you can do with MPD + * add_instance + * This takes key'd data and inserts a new MPD instance */ - public function actions() { + public function add_instance($data) { - } // actions + } // add_instance + + /** + * delete_instance + * This takes a UID and deletes the instance in question + */ + public function delete_instance($uid) { + + + } // delete_instance + + /** + * get_instances + * This returns a key'd array of the instance information with + * [UID]=>[NAME] + */ + public function get_instances() { + + + } // get_instances + + /** + * instance_fields + * This returns a key'd array of [NAME]=>array([DESCRIPTION]=>VALUE,[TYPE]=>VALUE) for the + * fields so that we can on-the-fly generate a form + */ + public function instance_fields() { + + + + } // instance_fields + + /** + * set_active_instance + * This sets the specified instance as the 'active' one + */ + public function set_active_instance($uid) { + + + } // set_active_instance + + /** + * get_active_instance + * This returns the UID of the current active instance + * false if none are active + */ + public function get_active_instance() { + + + } // get_active_instance /** * add diff --git a/modules/localplay/mpd.controller.php b/modules/localplay/mpd.controller.php index 1ca7b4f5..d7819c48 100644 --- a/modules/localplay/mpd.controller.php +++ b/modules/localplay/mpd.controller.php @@ -129,10 +129,13 @@ class AmpacheMpd extends localplay_controller { "`host` VARCHAR( 255 ) NOT NULL , " . "`port` INT( 11 ) UNSIGNED NOT NULL DEFAULT '6600', " . "`password` VARCHAR( 255 ) NOT NULL , " . - "`access` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '0' " . + "`access` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '0', " . ") ENGINE = MYISAM"; $db_results = Dba::query($sql); + // Add an internal preference for the users current active instance + Preference::insert('mpd_active','MPD Active Instance','0','25','integer','internal'); + return true; } // install @@ -151,14 +154,73 @@ class AmpacheMpd extends localplay_controller { } // uninstall /** - * actions - * List all the special kick ass things you can do with MPD + * add_instance + * This takes key'd data and inserts a new MPD instance + */ + public function add_instance($data) { + + + + } // add_instance + + /** + * delete_instance + * This takes a UID and deletes the instance in question + */ + public function delete_instance($uid) { + + + } // delete_instance + + /** + * get_instances + * This returns a key'd array of the instance information with + * [UID]=>[NAME] */ - public function actions() { + public function get_instances() { + } // get_instances + + /** + * instance_fields + * This returns a key'd array of [NAME]=>array([DESCRIPTION]=>VALUE,[TYPE]=>VALUE) for the + * fields so that we can on-the-fly generate a form + */ + public function instance_fields() { + + + + } // instance_fields + + /** + * set_active_instance + * This sets the specified instance as the 'active' one + */ + public function set_active_instance($uid,$user_id='') { + + // Not an admin? bubkiss! + if (!$GLOBALS['user']->has_access('100')) { + $user_id = $GLOBALS['user']->id; + } + + $user_id = $user_id ? $user_id : $GLOBALS['user']->id; + + Preference::update('mpd_instance',$user_id,intval($uid)); + + return true; + + } // set_active_instance + + /** + * get_active_instance + * This returns the UID of the current active instance + * false if none are active + */ + public function get_active_instance() { + - } // actions + } // get_active_instance /** * add diff --git a/modules/plugins/Lastfm.plugin.php b/modules/plugins/Lastfm.plugin.php index 098e01e8..0d9c4b18 100644 --- a/modules/plugins/Lastfm.plugin.php +++ b/modules/plugins/Lastfm.plugin.php @@ -70,10 +70,12 @@ class AmpacheLastfm { */ public function uninstall() { - /* We need to remove the preivously added preferences */ - $sql = "DELETE FROM `preference` WHERE `name`='lastfm_pass' OR `name`='lastfm_user' " . - "OR `name`='lastfm_url' OR `name`='lastfm_host' OR `name`='lastfm_port' OR `name`='lastfm_challenge'"; - $db_results = Dba::query($sql); + Preference::delete('lastfm_pass'); + Preference::delete('lastfm_user'); + Preference::delete('lastfm_url'); + Preference::delete('lastfm_host'); + Preference::delete('lastfm_port'); + Preference::delete('lastfm_challenge'); } // uninstall diff --git a/modules/plugins/OpenStrands.plugin.php b/modules/plugins/OpenStrands.plugin.php index f57529b9..d63e9616 100644 --- a/modules/plugins/OpenStrands.plugin.php +++ b/modules/plugins/OpenStrands.plugin.php @@ -57,9 +57,8 @@ class AmpacheOpenStrands { */ function uninstall() { - /* We need to remove the preivously added preferences */ - $sql = "DELETE FROM `preference` WHERE `name`='mystrands_pass' OR `name`='mystrands_user'"; - $db_results = Dba::query($sql); + Preference::delete('mystrands_pass'); + Preference::delete('mystrands_user'); } // uninstall diff --git a/server/ajax.server.php b/server/ajax.server.php index 60e45dcf..26a7a75d 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -53,6 +53,10 @@ switch ($_REQUEST['page']) { require_once Config::get('prefix') . '/server/playlist.ajax.php'; exit; break; + case 'localplay': + require_once Config::get('prefix') . '/server/localplay.ajax.php'; + exit; + break; default: // A taste of compatibility break; diff --git a/server/localplay.ajax.php b/server/localplay.ajax.php new file mode 100644 index 00000000..aa8f9db3 --- /dev/null +++ b/server/localplay.ajax.php @@ -0,0 +1,38 @@ +<?php +/* + + Copyright (c) 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 v2 + as published by the Free Software Foundation. + + 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. + +*/ + +/** + * Sub-Ajax page, requires AJAX_INCLUDE as one + */ +if (AJAX_INCLUDE != '1') { exit; } + +switch ($_REQUEST['action']) { + case 'set_instance': + + break; + default: + $results['rfc3514'] = '0x1'; + break; +} // switch on action; + +// We always do this +echo xml_from_array($results); +?> diff --git a/templates/show_album.inc.php b/templates/show_album.inc.php index f2738e93..3a840db3 100644 --- a/templates/show_album.inc.php +++ b/templates/show_album.inc.php @@ -36,10 +36,8 @@ $title = scrub_out($album->name) . ' (' . $album->year . ') -- ' } ?> </div> - <div style="display:table-cell;vertical-align:top;"> - <!--<div style="float:left; display:inline;" id="rating_<?php echo $album->id; ?>_album">--> + <div style="display:table-cell;vertical-align:top;" id="rating_<?php echo $album->id; ?>_album"> <?php Rating::show($album->id,'album'); ?> - <!--</div>--> </div> <strong><?php echo _('Actions'); ?>:</strong><br /> <div id="information_actions"> diff --git a/templates/show_localplay_add_instance.inc.php b/templates/show_localplay_add_instance.inc.php new file mode 100644 index 00000000..c2ab559f --- /dev/null +++ b/templates/show_localplay_add_instance.inc.php @@ -0,0 +1,26 @@ +<?php +/* + + Copyright (c) 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. + +*/ + +?> +<?php show_box_top(_('Add Localplay Instance')); ?> + +<?php show_box_bottom(); ?> diff --git a/templates/sidebar_localplay.inc.php b/templates/sidebar_localplay.inc.php index 398f4791..815ffc2b 100644 --- a/templates/sidebar_localplay.inc.php +++ b/templates/sidebar_localplay.inc.php @@ -1,3 +1,12 @@ <ul class="sb2" id="sb_localplay"> - <li><h4><?php echo _('Localplay'); ?></h4></li> + <li><h4><?php echo _('Localplay'); ?></h4> + <ul class="sb3" id="sb_localplay_info"> + <li id="sb_localplay_info_add_instance"><a href="<?php echo $web_path; ?>/localplay.php?action=show_add_instance"><?php echo _('Add Instance'); ?></a></li> + </ul> + </li> + <li><h4><?php echo _('Active Instance'); ?></h4> + <ul class="sb3" id="sb_localplay_instances"> + <li id="sb_localplay_instances_none"><?php echo Ajax::text('?page=localplay&action=set_instance&instance=0',_('None'),'localplay_instance_none'); ?></li> + </ul> + </li> </ul> |