mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-05 19:41:55 +02:00
more work on the localplay stuff, most details ironed out, just needs some code to back it up, also tweaked plugins and threw in some extra goodies in the preference class, also pimped out the error class
This commit is contained in:
parent
c99ad11ee0
commit
bff9e37fa5
15 changed files with 308 additions and 85 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -59,6 +38,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
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
show_header();
|
||||
|
||||
/* If we are running a demo, quick while you still can! */
|
||||
if (conf('demo_mode')) {
|
||||
exit();
|
||||
}
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'show_add_instance':
|
||||
require_once Config::get('prefix') . '/templates/show_localplay_add_instance.inc.php';
|
||||
break;
|
||||
case 'add_instance':
|
||||
|
||||
$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');
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 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,$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() {
|
||||
|
||||
|
||||
} // get_active_instance
|
||||
|
||||
/**
|
||||
* add
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
38
server/localplay.ajax.php
Normal file
38
server/localplay.ajax.php
Normal file
|
@ -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);
|
||||
?>
|
|
@ -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">
|
||||
|
|
26
templates/show_localplay_add_instance.inc.php
Normal file
26
templates/show_localplay_add_instance.inc.php
Normal file
|
@ -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(); ?>
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue