1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-06 03:49:56 +02:00

- Added modules section to sidebar, conforming to new layout from r1127

- Re-enabled plugins, added openstrands plugin
This commit is contained in:
Karl 'vollmerk' Vollmer 2007-08-06 00:39:54 +00:00
parent 00bcfdca5f
commit bf6e9f88d8
12 changed files with 248 additions and 206 deletions

View file

@ -1,13 +1,13 @@
<?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
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
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
@ -20,7 +20,7 @@
*/
require('../lib/init.php');
require_once '../lib/init.php';
if (!$GLOBALS['user']->has_access(100)) {
access_denied();
@ -28,12 +28,10 @@ if (!$GLOBALS['user']->has_access(100)) {
}
$action = scrub_in($_REQUEST['action']);
/* Always show the header */
show_template('header');
show_header();
switch ($action) {
switch ($_REQUEST['action']) {
case 'insert_localplay_preferences':
$type = scrub_in($_REQUEST['type']);
insert_localplay_preferences($type);
@ -59,30 +57,33 @@ switch ($action) {
break;
case 'install_plugin':
/* Verify that this plugin exists */
$plugins = get_plugins();
$plugins = Plugin::get_plugins();
if (!array_key_exists($_REQUEST['plugin'],$plugins)) {
debug_event('plugins','Error: Invalid Plugin: ' . $_REQUEST['plugin'] . ' selected','1');
break;
}
$plugin = new Plugin($_REQUEST['plugin']);
$plugin->install();
// Don't trust the plugin to this stuff
User::rebuild_all_preferences();
/* Show Confirmation */
$url = conf('web_path') . '/admin/preferences.php?tab=modules';
$url = Config::get('web_path') . '/admin/modules.php?action=show_plugins';
$title = _('Plugin Activated');
$body = '';
show_confirmation($title,$body,$url);
break;
case 'confirm_uninstall_plugin':
$plugin = scrub_in($_REQUEST['plugin']);
$url = conf('web_path') . '/admin/modules.php?action=uninstall_plugin&amp;plugin=' . $plugin;
$url = Config::get('web_path') . '/admin/modules.php?action=uninstall_plugin&amp;plugin=' . $plugin;
$title = _('Are you sure you want to remove this plugin?');
$body = '';
show_confirmation($title,$body,$url,1);
break;
case 'uninstall_plugin':
/* Verify that this plugin exists */
$plugins = get_plugins();
$plugins = Plugin::get_plugins();
if (!array_key_exists($_REQUEST['plugin'],$plugins)) {
debug_event('plugins','Error: Invalid Plugin: ' . $_REQUEST['plugin'] . ' selected','1');
break;
@ -90,17 +91,29 @@ switch ($action) {
$plugin = new Plugin($_REQUEST['plugin']);
$plugin->uninstall();
// Don't trust the plugin to do it
User::rebuild_all_preferences();
/* Show Confirmation */
$url = conf('web_path') . '/admin/preferences.php?tab=modules';
$url = Config::get('web_path') . '/admin/modules.php?action=show_plugins';
$title = _('Plugin Deactivated');
$body = '';
show_confirmation($title,$body,$url);
break;
case 'upgrade_plugin':
break;
case 'show_plugins':
$plugins = Plugin::get_plugins();
show_box_top(_('Plugins'));
require_once Config::get('prefix') . '/templates/show_plugins.inc.php';
show_box_bottom();
break;
case 'show_localplay':
break;
default:
require_once (conf('prefix') . '/templates/show_modules.inc.php');
// Rien a faire
break;
} // end switch

View file

@ -4,6 +4,9 @@
--------------------------------------------------------------------------
v.3.4-Alpha2
- Added MyStrands Plugin
- Re-enabled / updated Plugin functionality
- Fixed CSS (Thx Spocky)
- Added Playlists as a browse type and fixed playback
- Fixed an issue where albums of the moment would show when you
had 0 albums

View file

@ -22,17 +22,17 @@
class Plugin {
/* Base Variables */
var $name;
public $name;
/* constructed objects */
var $_plugin;
public $_plugin;
/**
* Constructor
* This constructor loads the Plugin config file which defines how to
* install/uninstall the plugin from Ampache's database
*/
function Plugin($name) {
public function __construct($name) {
/* Load the plugin */
if (!$this->_get_info($name)) {
@ -41,7 +41,7 @@ class Plugin {
return true;
} // Plugin
} // Constructor
/**
@ -52,7 +52,7 @@ class Plugin {
function _get_info($name) {
/* Require the file we want */
require_once(conf('prefix') . '/modules/plugins/' . $name . '.plugin.php');
require_once Config::get('prefix') . '/modules/plugins/' . $name . '.plugin.php';
$plugin_name = "Ampache$name";
@ -66,6 +66,40 @@ class Plugin {
} // _get_info
/**
* get_plugins
* This returns an array of plugin names
*/
public static function get_plugins() {
$results = array();
// Open up the plugin dir
$handle = opendir(Config::get('prefix') . '/modules/plugins');
if (!is_resource($handle)) {
debug_event('Plugins','Unable to read plugins directory','1');
}
// Recurse the directory
while ($file = readdir($handle)) {
// Ignore non-plugin files
if (substr($file,-10,10) != 'plugin.php') { continue; }
if (is_dir($file)) { continue; }
// It's a plugin record it
$plugin_name = basename($file,'.plugin.php');
$results[$plugin_name] = $plugin_name;
} // end while
// Little stupid but hey
ksort($results);
return $results;
} // get_plugins
/**
* is_valid
* This checks to make sure the plugin has the required functions and
@ -157,12 +191,12 @@ class Plugin {
*/
function get_plugin_version() {
$name = sql_escape('Plugin_' . $this->_plugin->name);
$name = Dba::escape('Plugin_' . $this->_plugin->name);
$sql = "SELECT * FROM update_info WHERE `key`='$name'";
$db_results = mysql_query($sql,dbh());
$sql = "SELECT * FROM `update_info` WHERE `key`='$name'";
$db_results = Dba::query($sql);
$results = mysql_fetch_assoc($db_results);
$results = Dba::fetch_assoc($db_results);
return $results['value'];
@ -174,10 +208,10 @@ class Plugin {
*/
function get_ampache_db_version() {
$sql = "SELECT * FROM update_info WHERE `key`='db_version'";
$db_results = mysql_query($sql,dbh());
$sql = "SELECT * FROM `update_info` WHERE `key`='db_version'";
$db_results = Dba::query($sql);
$results = mysql_fetch_assoc($db_results);
$results = Dba::fetch_assoc($db_results);
return $results['value'];
@ -187,13 +221,13 @@ class Plugin {
* set_plugin_version
* This sets the plugin version in the update_info table
*/
function set_plugin_version($version) {
public function set_plugin_version($version) {
$name = sql_escape('Plugin_' . $this->_plugin->name);
$version = sql_escape($version);
$name = Dba::escape('Plugin_' . $this->_plugin->name);
$version = Dba::escape($version);
$sql = "INSERT INTO update_info SET `key`='$name', value='$version'";
$db_results = mysql_query($sql,dbh());
$sql = "INSERT INTO `update_info` SET `key`='$name', `value`='$version'";
$db_results = Dba::query($sql);
return true;
@ -203,12 +237,12 @@ class Plugin {
* remove_plugin_version
* This removes the version row from the db done on uninstall
*/
function remove_plugin_version() {
public function remove_plugin_version() {
$name = sql_escape('Plugin_' . $this->_plugin->name);
$name = Dba::escape('Plugin_' . $this->_plugin->name);
$sql = "DELETE FROM update_info WHERE `key`='$name'";
$db_results = mysql_query($sql,dbh());
$sql = "DELETE FROM `update_info` WHERE `key`='$name'";
$db_results = Dba::query($sql);
return true;

View file

@ -1102,6 +1102,25 @@ class User {
return true;
} // check_username
/**
* rebuild_all_preferences
* This rebuilds the user preferences for all installed users, called by the plugin functions
*/
public static function rebuild_all_preferences() {
$sql = "SELECT * FROM `user`";
$db_results = Dba::query($sql);
User::fix_preferences('-1');
while ($row = Dba::fetch_assoc($db_results)) {
User::fix_preferences($row['id']);
}
return true;
} // rebuild_all_preferences
} //end user class

View file

@ -738,43 +738,6 @@ function invert_boolean($value) {
} // invert_boolean
/**
* get_plugins
* This returns a list of the plugins and their information
*/
function get_plugins() {
/* Init our vars */
$plugins = array();
/* Open the dir */
$handle = opendir(conf('prefix') . '/modules/plugins');
if (!is_resource($handle)) {
debug_event('plugins','Error: Unable to read plugins directory','1');
}
while ($file = readdir($handle)) {
if (substr($file,-10,10) != 'plugin.php') { continue; }
/* Make sure it isn't a subdir */
if (!is_dir($file)) {
/* Get the Basename */
$plugin_name = basename($file,'.plugin.php');
/* Load it */
$plugin = new Plugin($plugin_name);
$plugins[$plugin_name] = $plugin;
} // if its not a subdir
} // end while
return $plugins;
} // get_plugins
/**
* unhtmlentities
* This is required to make thing work.. but holycrap is it ugly

View file

@ -328,6 +328,7 @@ function create_preference_input($name,$value) {
echo "\t<option value=\"genre\">" . _('Related Genre') . "</option>";
echo "</select>\n";
break;
case 'mystrands_pass':
case 'lastfm_pass':
echo "<input type=\"password\" size=\"16\" name=\"$name\" value=\"******\" />";
break;
@ -519,26 +520,6 @@ function update_preference_level($pref_id,$level) {
} // update_preference_level
/**
* fix_all_users_prefs
* This function is used by install/uninstall and fixes all of the users preferences
*/
function fix_all_users_prefs() {
$sql = "SELECT * FROM user";
$db_results = mysql_query($sql,dbh());
$user = new User();
$user->fix_preferences('-1');
while ($r = mysql_fetch_assoc($db_results)) {
$user->fix_preferences($r['username']);
}
return true;
} // fix_all_users_prefs
/**
* fix_preferences
* This takes the preferences, explodes what needs to

View file

@ -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
@ -21,12 +21,12 @@
class AmpacheLastfm {
var $name ='Last.FM';
var $description ='Records your played songs to your Last.FM Account';
var $url ='';
var $version ='000001';
var $min_ampache ='334001';
var $max_ampache ='334005';
public $name ='Last.FM';
public $description ='Records your played songs to your Last.FM Account';
public $url ='';
public $version ='000002';
public $min_ampache ='340007';
public $max_ampache ='340008';
/**
* Constructor
@ -54,8 +54,6 @@ class AmpacheLastfm {
"VALUES ('lastfm_pass',' ','Last.FM Password','25','string','options')";
$db_results = Dba::query($sql);
fix_all_users_prefs();
} // install
/**
@ -66,11 +64,9 @@ class AmpacheLastfm {
function uninstall() {
/* We need to remove the preivously added preferences */
$sql = "DELETE FROM preference WHERE name='lastfm_pass' OR name='lastfm_user'";
$sql = "DELETE FROM `preference` WHERE `name`='lastfm_pass' OR `name`='lastfm_user'";
$db_results = Dba::query($sql);
fix_all_users_prefs();
} // uninstall
} // end AmpacheLastfm

View file

@ -0,0 +1,73 @@
<?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.
*/
class AmpacheOpenStrands {
public $name ='OpenStrands';
public $description ='Interface with MyStrands, recommendations etc';
public $url ='http://www.mystrands.com/openstrands/overview.vm';
public $version ='000001';
public $min_ampache ='340007';
public $max_ampache ='340008';
/**
* Constructor
* This function does nothing...
*/
public function __construct() {
return true;
} // PluginLastfm
/**
* install
* This is a required plugin function it inserts the required preferences
* into Ampache
*/
public function install() {
/* We need to insert the new preferences */
$sql = "INSERT INTO preference (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('mystrands_user',' ','MyStrands Username','25','string','options')";
$db_results = Dba::query($sql);
$sql = "INSERT INTO preference (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('mystrands_pass',' ','MyStrands Password','25','string','options')";
$db_results = Dba::query($sql);
} // install
/**
* uninstall
* This is a required plugin function it removes the required preferences from
* the database returning it to its origional form
*/
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);
} // uninstall
} // end AmpacheLastfm
?>

View file

@ -1,101 +0,0 @@
<?php
/*
Copyright (c) 2001 - 2006 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.
*/
/**
* for now we only have the localplay modules so this is going to be centered on them
* however the idea would be as module support is added more and more are put on this
* same page
*/
/* Get Localplay Modules */
$localplay_modules = get_localplay_controllers('disabled');
/* Get Plugins */
$plugins = get_plugins();
$web_path = conf('web_path');
?>
<!-- Localplay Modules -->
<table class="tabledata" border="0" cellspacing="0">
<tr class="odd">
<th colspan="2" class="header2" align="left"><?php echo _('Localplay Modules');?></th>
</tr>
<tr class="table-header">
<td><?php echo _('Module Name'); ?></td>
<td><?php echo _('Action'); ?></td>
</tr>
<?php
foreach ($localplay_modules as $module) {
if (!verify_localplay_preferences($module)) {
$action = "<a href=\"" . $web_path . "/admin/modules.php?action=insert_localplay_preferences&amp;type=" . $module . "\">" .
_('Activate') . "</a>";
}
else {
$action = "<a href=\"" . $web_path . "/admin/modules.php?action=confirm_remove_localplay_preferences&amp;type=" . $module . "\">" .
_('Deactivate') . "</a>";
}
?>
<tr class="<?php echo flip_class(); ?>">
<td><?php echo scrub_out($module); ?></td>
<td><?php echo $action; ?></td>
</tr>
<?php } if (!count($localplay_modules)) { ?>
<tr class="<?php echo flip_class(); ?>">
<td colspan="2"><span class="error"><?php echo _('No Records Found'); ?></span></td>
</tr>
<?php } ?>
</table>
<br />
<!-- Plugins -->
<table class="tabledata" border="0" cellspacing="0">
<tr class="odd">
<th colspan="4" class="header2" align="left"><?php echo _('Available Plugins'); ?></th>
<tr class="table-header">
<td><?php echo _('Name'); ?></td>
<td><?php echo _('Description'); ?></td>
<td><?php echo _('Version'); ?></td>
<td><?php echo _('Action'); ?></td>
</tr>
<?php
foreach ($plugins as $key=>$plugin) {
if (!$plugin->is_installed()) {
$action = "<a href=\"" . $web_path . "/admin/modules.php?action=install_plugin&amp;plugin=" . scrub_out($key) . "\">" .
_('Activate') . "</a>";
}
else {
$action = "<a href=\"" . $web_path . "/admin/modules.php?action=confirm_uninstall_plugin&amp;plugin=" . scrub_out($key) . "\">" .
_('Deactivate') . "</a>";
}
?>
<tr class="<?php echo flip_class(); ?>">
<td><?php echo scrub_out($plugin->_plugin->name); ?></td>
<td><?php echo scrub_out($plugin->_plugin->description); ?></td>
<td><?php echo scrub_out($plugin->_plugin->version); ?></td>
<td><?php echo $action; ?></td>
</tr>
<?php } if (!count($plugins)) { ?>
<tr class="<?php echo flip_class(); ?>">
<td colspan="4"><span class="error"><?php echo _('No Records Found'); ?></span></td>
</tr>
<?php } ?>
</table>
<br />

View file

@ -0,0 +1,56 @@
<?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.
*/
?>
<!-- Plugin we've found -->
<table class="tabledata" border="0" cellspacing="0">
<tr class="table-header">
<th><?php echo _('Name'); ?></th>
<th><?php echo _('Description'); ?></th>
<th><?php echo _('Version'); ?></th>
<th><?php echo _('Action'); ?></th>
</tr>
<?php
foreach ($plugins as $plugin_name) {
$plugin = new Plugin($plugin_name);
if (!$plugin->is_installed()) {
$action = "<a href=\"" . $web_path . "/admin/modules.php?action=install_plugin&amp;plugin=" . scrub_out($plugin_name) . "\">" .
_('Activate') . "</a>";
}
else {
$action = "<a href=\"" . $web_path . "/admin/modules.php?action=confirm_uninstall_plugin&amp;plugin=" . scrub_out($plugin_name) . "\">" .
_('Deactivate') . "</a>";
}
?>
<tr class="<?php echo flip_class(); ?>">
<td><?php echo scrub_out($plugin->_plugin->name); ?></td>
<td><?php echo scrub_out($plugin->_plugin->description); ?></td>
<td><?php echo scrub_out($plugin->_plugin->version); ?></td>
<td><?php echo $action; ?></td>
</tr>
<?php } if (!count($plugins)) { ?>
<tr class="<?php echo flip_class(); ?>">
<td colspan="4"><span class="error"><?php echo _('No Records Found'); ?></span></td>
</tr>
<?php } ?>
</table>
<br />

View file

@ -18,7 +18,6 @@
<li><?php echo _('Filters'); ?>
<div class="sb3">
<?php show_alphabet_list($_REQUEST['alpha_match'],$_REQUEST['action']); ?>
<hr />
<!--
<input type="checkbox" onclick="ajaxPut('<?php echo $ajax_info; ?>?action=browse&amp;key=show_art&amp;value=1');return true;" value="1" />
<?php echo _('Show Art'); ?><br />

View file

@ -18,5 +18,11 @@
<li id="sb_preferences_sc_System"><a href="<?php echo $web_path; ?>/preferences.php?action=admin&amp;tab=system"><?php echo _('System'); ?></a></li>
</ul>
</li>
<li><?php echo _('Modules'); ?>
<ul class="sb3" id="sb_Modules">
<li id="sb_preferences_mo_localplay"><a href="<?php echo $web_path; ?>/admin/modules.php?action=show_localplay"><?php echo _('Localplay Modules'); ?></a></li>
<li id="sb_preferences_mo_plugins"><a href="<?php echo $web_path; ?>/admin/modules.php?action=show_plugins"><?php echo _('Available Plugins'); ?></a></li>
</ul>
</li>
</ul>
<?php } ?>