diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-11-26 20:28:46 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-11-26 20:28:46 +0000 |
commit | 9c8be228a73a602ac3e91e30bf980dd1cc695a81 (patch) | |
tree | 46b3b2dc825f652410aba04f2d148b566e5b61e5 /lib | |
parent | a41697ea25a58ea5db5ed46a251fb62364626b1b (diff) | |
download | ampache-9c8be228a73a602ac3e91e30bf980dd1cc695a81.tar.gz ampache-9c8be228a73a602ac3e91e30bf980dd1cc695a81.tar.bz2 ampache-9c8be228a73a602ac3e91e30bf980dd1cc695a81.zip |
playlist switcher, plugin interface and the shell of a lastfm plugin (need patch file)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/album.lib.php | 2 | ||||
-rw-r--r-- | lib/class/plugin.class.php | 218 | ||||
-rw-r--r-- | lib/general.lib.php | 38 | ||||
-rw-r--r-- | lib/init.php | 4 | ||||
-rw-r--r-- | lib/preferences.php | 21 | ||||
-rw-r--r-- | lib/ui.lib.php | 15 |
6 files changed, 294 insertions, 4 deletions
diff --git a/lib/album.lib.php b/lib/album.lib.php index 7d518ff8..fc030163 100644 --- a/lib/album.lib.php +++ b/lib/album.lib.php @@ -26,6 +26,4 @@ function get_albums($sql, $action=0) { - - ?> diff --git a/lib/class/plugin.class.php b/lib/class/plugin.class.php new file mode 100644 index 00000000..5a058ac5 --- /dev/null +++ b/lib/class/plugin.class.php @@ -0,0 +1,218 @@ +<?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. + +*/ + +class Plugin { + + /* Base Variables */ + var $name; + + /* constructed objects */ + var $_plugin; + + /** + * Constructor + * This constructor loads the Plugin config file which defines how to + * install/uninstall the plugin from Ampache's database + */ + function Plugin($name) { + + /* Load the plugin */ + if (!$this->_get_info($name)) { + return false; + } + + return true; + + } // Plugin + + + /** + * _get_info + * This actually loads the config file for the plugin the name of the + * class contained within the config file must be Plugin[NAME OF FILE] + */ + function _get_info($name) { + + /* Require the file we want */ + require_once(conf('prefix') . '/modules/plugins/' . $name . '.plugin.php'); + + $plugin_name = "Ampache$name"; + + $this->_plugin = new $plugin_name(); + + if (!$this->is_valid()) { + return false; + } + + return true; + + } // _get_info + + /** + * is_valid + * This checks to make sure the plugin has the required functions and + * settings, Ampache requires Name/Description/Version (Int) and a + * install & uninstall method and Ampache must be within the min/max + * version specifications + */ + function is_valid() { + + /* Check the plugin to make sure it's got the needed vars */ + if (!strlen($this->_plugin->name)) { + return false; + } + if (!strlen($this->_plugin->description)) { + return false; + } + if (!strlen($this->_plugin->version)) { + return false; + } + + /* Make sure we've got the required methods */ + if (!method_exists($this->_plugin,'install')) { + return false; + } + + if (!method_exists($this->_plugin,'uninstall')) { + return false; + } + + /* Make sure it's within the version confines */ + $db_version = $this->get_ampache_db_version(); + + if ($db_version < $this->_plugin->min_ampache) { + return false; + } + + if ($db_version > $this->_plugin->max_ampache) { + return false; + } + + /* We've passed all of the tests its good */ + return true; + + } // is_valid + + /** + * is_installed + * This checks to see if the current plugin is currently installed in the + * database, it doesn't check the files for integrity + */ + function is_installed() { + + /* All we do is check the version */ + return $this->get_plugin_version(); + + } // is_installed + + /** + * install + * This runs the install function of the plugin (must be called install) + * at the end it inserts a row into the update_info table to indicate + * That it's installed + */ + function install() { + + $this->_plugin->install(); + + $this->set_plugin_version($this->_plugin->version); + + } // install + + /** + * uninstall + * This runs the uninstall function of the plugin (must be called uninstall) + * at the end it removes the row from the update_info table to indicate + * that it isn't installed + */ + function uninstall() { + + $this->_plugin->uninstall(); + + $this->remove_plugin_version(); + + } // uninstall + + /** + * get_plugin_version + * This returns the version of the currently installed plugin + */ + function get_plugin_version() { + + $name = sql_escape('Plugin_' . $this->_plugin->name); + + $sql = "SELECT * FROM update_info WHERE `key`='$name'"; + $db_results = mysql_query($sql,dbh()); + + $results = mysql_fetch_assoc($db_results); + + return $results['value']; + + } // get_plugin_version + + /** + * get_ampache_db_version + * This function returns the Ampache database version + */ + function get_ampache_db_version() { + + $sql = "SELECT * FROM update_info WHERE `key`='db_version'"; + $db_results = mysql_query($sql,dbh()); + + $results = mysql_fetch_assoc($db_results); + + return $results['value']; + + } // get_ampache_db_version + + /** + * set_plugin_version + * This sets the plugin version in the update_info table + */ + function set_plugin_version($version) { + + $name = sql_escape('Plugin_' . $this->_plugin->name); + $version = sql_escape($version); + + $sql = "INSERT INTO update_info SET `key`='$name', value='$version'"; + $db_results = mysql_query($sql,dbh()); + + return true; + + } // set_plugin_version + + /** + * remove_plugin_version + * This removes the version row from the db done on uninstall + */ + function remove_plugin_version() { + + $name = sql_escape('Plugin_' . $this->_plugin->name); + + $sql = "DELETE FROM update_info WHERE `key`='$name'"; + $db_results = mysql_query($sql,dbh()); + + return true; + + } // remove_plugin_version + +} //end plugin class +?> diff --git a/lib/general.lib.php b/lib/general.lib.php index 697e0f50..b6c7c3fc 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -988,4 +988,42 @@ function get_user_from_username($username) { } // get_user_from_username +/** + * 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 + + ?> diff --git a/lib/init.php b/lib/init.php index 6418c826..483720fe 100644 --- a/lib/init.php +++ b/lib/init.php @@ -67,7 +67,7 @@ if (!$results = read_config($configfile,0)) { } /** This is the version.... fluf nothing more... **/ -$results['version'] = '3.3.3-Beta1 (Build 001)'; +$results['version'] = '3.3.3-Beta1 (Build 002)'; $results['raw_web_path'] = $results['web_path']; $results['web_path'] = $http_type . $_SERVER['HTTP_HOST'] . $results['web_path']; @@ -153,7 +153,6 @@ require_once(conf('prefix') . '/lib/playlist.lib.php'); require_once(conf('prefix') . '/lib/upload.php'); require_once(conf('prefix') . '/lib/democratic.lib.php'); require_once(conf('prefix') . '/modules/lib.php'); -require_once(conf('prefix') . '/modules/admin.php'); require_once(conf('prefix') . '/modules/catalog.php'); require_once(conf('prefix') . "/modules/id3/getid3/getid3.php"); require_once(conf('prefix') . '/modules/id3/vainfo.class.php'); @@ -170,6 +169,7 @@ if (conf('ratings')) { // Classes require_once(conf('prefix') . '/lib/class/localplay.class.php'); +require_once(conf('prefix') . '/lib/class/plugin.class.php'); require_once(conf('prefix') . '/lib/class/stats.class.php'); require_once(conf('prefix') . '/lib/class/catalog.class.php'); require_once(conf('prefix') . '/lib/class/stream.class.php'); diff --git a/lib/preferences.php b/lib/preferences.php index 39755735..ac18479c 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -487,4 +487,25 @@ function update_preference_level($name,$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 + + ?> diff --git a/lib/ui.lib.php b/lib/ui.lib.php index c1f676ee..e1154b21 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -1426,5 +1426,20 @@ function xml_get_footer($type){ } } //xml_get_footer +/** + * show_manage_users + * This is the admin page for showing all of the users + */ +function show_manage_users() { + + show_box_top(_('Manage Users')); + echo "<ul>\n\t<li><a href=\"".conf('web_path') . "/admin/users.php?action=show_add_user\">" . _('Add a new user') . "</a></li>\n</ul>\n"; + show_box_bottom(); + + /* Show the Users */ + show_users(); + +} // show_manage_users + ?> |