diff options
author | dipsol <dipsol@ampache> | 2009-12-14 08:06:20 +0000 |
---|---|---|
committer | dipsol <dipsol@ampache> | 2009-12-14 08:06:20 +0000 |
commit | a7838e2a13cf2f8875a34e122c44c9c923648bc6 (patch) | |
tree | a2c3a11be556358a59d38c260a1b40ce7c79dae0 /lib | |
parent | 9b3232ba299fbbe6bec922bf7034c005175c9365 (diff) | |
download | ampache-a7838e2a13cf2f8875a34e122c44c9c923648bc6.tar.gz ampache-a7838e2a13cf2f8875a34e122c44c9c923648bc6.tar.bz2 ampache-a7838e2a13cf2f8875a34e122c44c9c923648bc6.zip |
Replaced almost every dba::query to dba::read or dba::write.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/ampachemail.class.php | 58 | ||||
-rw-r--r-- | lib/class/database_object.abstract.php | 70 | ||||
-rw-r--r-- | lib/class/dba.class.php | 404 | ||||
-rw-r--r-- | lib/class/query.class.php | 1026 | ||||
-rw-r--r-- | lib/class/update.class.php | 1560 | ||||
-rw-r--r-- | lib/class/user.class.php | 4 | ||||
-rw-r--r-- | lib/class/vauth.class.php | 402 | ||||
-rw-r--r-- | lib/class/xmlrpcserver.class.php | 162 | ||||
-rw-r--r-- | lib/debug.lib.php | 2 | ||||
-rw-r--r-- | lib/general.lib.php | 4 | ||||
-rw-r--r-- | lib/preferences.php | 142 | ||||
-rw-r--r-- | lib/ui.lib.php | 248 |
12 files changed, 2041 insertions, 2041 deletions
diff --git a/lib/class/ampachemail.class.php b/lib/class/ampachemail.class.php index c8a14a88..5eed4078 100644 --- a/lib/class/ampachemail.class.php +++ b/lib/class/ampachemail.class.php @@ -22,10 +22,10 @@ class AmpacheMail { // The message, recipient and from - public static $message; - public static $recipient; + public static $message; + public static $recipient; public static $fromname; - public static $subject; + public static $subject; public static $to; public static $fullname; public static $sender; @@ -34,7 +34,7 @@ class AmpacheMail { * Constructor * This isn't used */ - private function __construct($name) { + private function __construct($name) { // Rien a faire @@ -45,34 +45,34 @@ class AmpacheMail { * This returns an array of userid's for people who have e-mail addresses * based on the passed filter */ - public static function get_users($filter) { + public static function get_users($filter) { - switch ($filter) { - default: - case 'all': - $sql = "SELECT * FROM `user` WHERE `email` IS NOT NULL"; + switch ($filter) { + default: + case 'all': + $sql = "SELECT * FROM `user` WHERE `email` IS NOT NULL"; break; - case 'users': - $sql = "SELECT * FROM `user` WHERE `access`='25' AND `email` IS NOT NULL"; + case 'users': + $sql = "SELECT * FROM `user` WHERE `access`='25' AND `email` IS NOT NULL"; break; - case 'admins': - $sql = "SELECT * FROM `user` WHERE `access`='100' AND `email` IS NOT NULL"; + case 'admins': + $sql = "SELECT * FROM `user` WHERE `access`='100' AND `email` IS NOT NULL"; break ; - case 'inactive': + case 'inactive': $inactive = time() - (30*86400); - $sql = "SELECT * FROM `user` WHERE `last_seen` <= '$inactive' AND `email` IS NOT NULL"; - break; + $sql = "SELECT * FROM `user` WHERE `last_seen` <= '$inactive' AND `email` IS NOT NULL"; + break; } // end filter switch - - $db_results = Dba::query($sql); - - $results = array(); - - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = array('id'=>$row['id'],'fullname'=>$row['fullname'],'email'=>$row['email']); - } - return $results; + $db_results = Dba::read($sql); + + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = array('id'=>$row['id'],'fullname'=>$row['fullname'],'email'=>$row['email']); + } + + return $results; } // get_users @@ -80,9 +80,9 @@ class AmpacheMail { * add_statistics * This should be run if we want to add some statistics to this e-mail, appends to self::$message */ - public static function add_statistics($methods) { + public static function add_statistics($methods) { + - } // add_statistics @@ -90,11 +90,11 @@ class AmpacheMail { * send * This actually sends the mail, how amazing */ - public static function send() { + public static function send() { $mailtype = Config::get('mail_type'); $mail = new PHPMailer(); - + $mail->AddAddress(self::$to, self::$fullname); $mail->CharSet = Config::get('site_charset'); $mail->Encoding = "base64"; diff --git a/lib/class/database_object.abstract.php b/lib/class/database_object.abstract.php index 50e45f23..c2fd9cc5 100644 --- a/lib/class/database_object.abstract.php +++ b/lib/class/database_object.abstract.php @@ -21,42 +21,42 @@ /** * database_object * This is a general object that is extended by all of the basic - * database based objects in ampache. It attempts to do some standard + * database based objects in ampache. It attempts to do some standard * caching for all of the objects to cut down on the database calls */ -abstract class database_object { +abstract class database_object { - private static $object_cache = array(); + private static $object_cache = array(); // Statistics for debugging - public static $cache_hit = 0; - private static $_enabled = false; + public static $cache_hit = 0; + private static $_enabled = false; /** * get_info * retrieves the info from the database and puts it in the cache */ - public function get_info($id,$table_name='') { + public function get_info($id,$table_name='') { $table_name = $table_name ? Dba::escape($table_name) : Dba::escape(strtolower(get_class($this))); // Make sure we've got a real id - if (!is_numeric($id)) { return array(); } + if (!is_numeric($id)) { return array(); } - if (self::is_cached($table_name,$id)) { - return self::get_from_cache($table_name,$id); - } + if (self::is_cached($table_name,$id)) { + return self::get_from_cache($table_name,$id); + } - $sql = "SELECT * FROM `$table_name` WHERE `id`='$id'"; - $db_results = Dba::query($sql); + $sql = "SELECT * FROM `$table_name` WHERE `id`='$id'"; + $db_results = Dba::read($sql); - if (!$db_results) { return array(); } + if (!$db_results) { return array(); } - $row = Dba::fetch_assoc($db_results); + $row = Dba::fetch_assoc($db_results); - self::add_to_cache($table_name,$id,$row); + self::add_to_cache($table_name,$id,$row); - return $row; + return $row; } // get_info @@ -64,12 +64,12 @@ abstract class database_object { * is_cached * this checks the cache to see if the specified object is there */ - public static function is_cached($index,$id) { + public static function is_cached($index,$id) { // Make sure we've got some parents here before we dive below - if (!isset(self::$object_cache[$index])) { return false; } - - return isset(self::$object_cache[$index][$id]); + if (!isset(self::$object_cache[$index])) { return false; } + + return isset(self::$object_cache[$index][$id]); } // is_cached @@ -77,18 +77,18 @@ abstract class database_object { * get_from_cache * This attempts to retrive the specified object from the cache we've got here */ - public static function get_from_cache($index,$id) { + public static function get_from_cache($index,$id) { // Check if the object is set if (isset(self::$object_cache[$index]) && isset(self::$object_cache[$index][$id]) - ) { - - self::$cache_hit++; - return self::$object_cache[$index][$id]; - } + ) { + + self::$cache_hit++; + return self::$object_cache[$index][$id]; + } - return false; + return false; } // get_from_cache @@ -96,11 +96,11 @@ abstract class database_object { * add_to_cache * This adds the specified object to the specified index in the cache */ - public static function add_to_cache($index,$id,$data) { + public static function add_to_cache($index,$id,$data) { - if (!self::$_enabled) { return false; } + if (!self::$_enabled) { return false; } - $value = is_null($data) ? false : $data; + $value = is_null($data) ? false : $data; self::$object_cache[$index][$id] = $value; } // add_to_cache @@ -110,11 +110,11 @@ abstract class database_object { * This function clears something from the cache, there are a few places we need to do this * in order to have things display correctly */ - public static function remove_from_cache($index,$id) { - - if (isset(self::$object_cache[$index]) && isset(self::$object_cache[$index][$id])) { - unset(self::$object_cache[$index][$id]); - } + public static function remove_from_cache($index,$id) { + + if (isset(self::$object_cache[$index]) && isset(self::$object_cache[$index][$id])) { + unset(self::$object_cache[$index][$id]); + } } // remove_from_cache diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php index d37789fd..2292014e 100644 --- a/lib/class/dba.class.php +++ b/lib/class/dba.class.php @@ -1,21 +1,21 @@ <?php /* - Copyright (c) Ampache.org - All rights reserved. +Copyright (c) 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 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. +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. +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. */ /* Make sure they aren't directly accessing it */ @@ -28,21 +28,21 @@ if (INIT_LOADED != '1') { exit; } * with a few exceptions, the row and assoc will always * return an array, simplifying checking on the far end * it will also auto-connect as needed, and has a default - * database simplifying queries in most cases. + * database simplifying queries in most cases. */ -class Dba { +class Dba { - public static $stats = array('query'=>0); + public static $stats = array('query'=>0); private static $_default_db; - private static $_sql; - private static $config; + private static $_sql; + private static $config; /** * constructor * This does nothing with the DBA class */ - private function __construct() { + private function __construct() { // Rien a faire @@ -53,34 +53,34 @@ class Dba { * This is the meat of the class this does a query, it emulates * The mysql_query function */ - public static function query($sql) { - + public static function query($sql) { + // Run the query - $resource = mysql_query($sql,self::dbh()); + $resource = mysql_query($sql,self::dbh()); debug_event('Query',$sql,'6'); - + // Save the query, to make debug easier - self::$_sql = $sql; - self::$stats['query']++; + self::$_sql = $sql; + self::$stats['query']++; // Do a little error checking here and try to recover from some forms of failure - if (!$resource) { - switch (mysql_errno(self::dbh())) { - case '2006': - case '2013': - case '2055': - debug_event('DBH','Lost connection to database server, trying to re-connect and hope nobody noticed','1'); - self::disconnect(); + if (!$resource) { + switch (mysql_errno(self::dbh())) { + case '2006': + case '2013': + case '2055': + debug_event('DBH','Lost connection to database server, trying to re-connect and hope nobody noticed','1'); + self::disconnect(); // Try again - $resource = mysql_query($sql,self::dbh()); - break; + $resource = mysql_query($sql,self::dbh()); + break; default: - debug_event('DBH',mysql_error(self::dbh()) . ' ['. mysql_errno(self::dbh()) . ']','1'); - break; + debug_event('DBH',mysql_error(self::dbh()) . ' ['. mysql_errno(self::dbh()) . ']','1'); + break; } // end switch on error # } // if failed query - return $resource; + return $resource; } // query @@ -89,33 +89,33 @@ class Dba { * This is a wrapper for query, it's so that in the future if we ever wanted * to split reads and writes we could */ - public static function read($sql) { + public static function read($sql) { - return self::query($sql); + return self::query($sql); } // read /** * write * This is a wrapper for a write query, it is so that we can split out reads and - * writes if we want to + * writes if we want to */ - public static function write($sql) { + public static function write($sql) { - return self::query($sql); + return self::query($sql); } // write /** * escape * This runs a escape on a variable so that it can be safely inserted - * into the sql + * into the sql */ - public static function escape($var) { + public static function escape($var) { + + $string = mysql_real_escape_string($var,self::dbh()); - $string = mysql_real_escape_string($var,self::dbh()); - - return $string; + return $string; } // escape @@ -124,13 +124,13 @@ class Dba { * This emulates the mysql_fetch_assoc and takes a resource result * we force it to always return an array, albit an empty one */ - public static function fetch_assoc($resource) { + public static function fetch_assoc($resource) { - $result = mysql_fetch_assoc($resource); + $result = mysql_fetch_assoc($resource); - if (!$result) { - return array(); - } + if (!$result) { + return array(); + } return $result; @@ -141,15 +141,15 @@ class Dba { * This emulates the mysql_fetch_row and takes a resource result * we force it to always return an array, albit an empty one */ - public static function fetch_row($resource) { + public static function fetch_row($resource) { - $result = mysql_fetch_row($resource); + $result = mysql_fetch_row($resource); - if (!$result) { - return array(); - } + if (!$result) { + return array(); + } - return $result; + return $result; } // fetch_row @@ -159,25 +159,25 @@ class Dba { * just a count of rows returned by our select statement, this * doesn't work for updates or inserts */ - public static function num_rows($resource) { - - $result = mysql_num_rows($resource); - - if (!$result) { - return '0'; - } + public static function num_rows($resource) { + + $result = mysql_num_rows($resource); + + if (!$result) { + return '0'; + } return $result; - } // num_rows + } // num_rows /** * finish * This closes a result handle and clears the memory assoicated with it */ - public static function finish($resource) { + public static function finish($resource) { // Clear the result memory - mysql_free_result($resource); + mysql_free_result($resource); } // finish @@ -185,15 +185,15 @@ class Dba { * affected_rows * This emulates the mysql_affected_rows function */ - public static function affected_rows($resource) { + public static function affected_rows($resource) { - $result = mysql_affected_rows($resource); + $result = mysql_affected_rows($resource); - if (!$result) { - return '0'; - } + if (!$result) { + return '0'; + } - return $result; + return $result; } // affected_rows @@ -201,40 +201,40 @@ class Dba { * _connect * This connects to the database, used by the DBH function */ - private static function _connect($db_name) { - - if (self::$_default_db == $db_name) { - $username = Config::get('database_username'); - $hostname = Config::get('database_hostname'); - $password = Config::get('database_password'); - $database = Config::get('database_name'); - } - else { + private static function _connect($db_name) { + + if (self::$_default_db == $db_name) { + $username = Config::get('database_username'); + $hostname = Config::get('database_hostname'); + $password = Config::get('database_password'); + $database = Config::get('database_name'); + } + else { // Do this later - } + } + + $dbh = mysql_connect($hostname,$username,$password); + if (!$dbh) { debug_event('Database','Error unable to connect to database' . mysql_error(),'1'); } - $dbh = mysql_connect($hostname,$username,$password); - if (!$dbh) { debug_event('Database','Error unable to connect to database' . mysql_error(),'1'); } - $data = self::translate_to_mysqlcharset(Config::get('site_charset')); - if (function_exists('mysql_set_charset')) { - if (!$charset = mysql_set_charset($data['charset'],$dbh)) { - debug_event('Database','Error unable to set MySQL Connection charset to ' . $data['charset'] . ' this may cause issues...','1'); - } - } - else { - $sql = "SET NAMES " . mysql_real_escape_string($data['charset']); - $charset = mysql_query($sql,$dbh); - if (mysql_error($dbh)) { debug_event('Database','Error unable to set MySQL Connection charset to ' . $data['charset'] . ' using SET NAMES, you may have issues','1'); } + if (function_exists('mysql_set_charset')) { + if (!$charset = mysql_set_charset($data['charset'],$dbh)) { + debug_event('Database','Error unable to set MySQL Connection charset to ' . $data['charset'] . ' this may cause issues...','1'); + } + } + else { + $sql = "SET NAMES " . mysql_real_escape_string($data['charset']); + $charset = mysql_query($sql,$dbh); + if (mysql_error($dbh)) { debug_event('Database','Error unable to set MySQL Connection charset to ' . $data['charset'] . ' using SET NAMES, you may have issues','1'); } } - if (!$charset) { debug_event('Database','Error unable to set connection charset, function missing or set failed','1'); } + if (!$charset) { debug_event('Database','Error unable to set connection charset, function missing or set failed','1'); } + + $select_db = mysql_select_db($database,$dbh); + if (!$select_db) { debug_event('Database','Error unable to select ' . $database . ' error ' . mysql_error(),'1'); } - $select_db = mysql_select_db($database,$dbh); - if (!$select_db) { debug_event('Database','Error unable to select ' . $database . ' error ' . mysql_error(),'1'); } - if (Config::get('sql_profiling')) { mysql_query('set profiling=1', $dbh); mysql_query('set profiling_history_size=50', $dbh); @@ -251,13 +251,13 @@ class Dba { public static function show_profile() { if (Config::get('sql_profiling')) { - print '<br/>Profiling data: <br/>'; - $res = Dba::query('show profiles'); - print '<table>'; - while ($r = Dba::fetch_row($res)) { - print '<tr><td>' . implode('</td><td>', $r) . '</td></tr>'; - } - print '</table>'; + print '<br/>Profiling data: <br/>'; + $res = Dba::read('show profiles'); + print '<table>'; + while ($r = Dba::fetch_row($res)) { + print '<tr><td>' . implode('</td><td>', $r) . '</td></tr>'; + } + print '</table>'; } } // show_profile @@ -266,21 +266,21 @@ class Dba { * This is called by the class to return the database handle * for the specified database, if none is found it connects */ - public static function dbh($database='') { + public static function dbh($database='') { - if (!$database) { $database = self::$_default_db; } + if (!$database) { $database = self::$_default_db; } // Assign the Handle name that we are going to store $handle = 'dbh_' . $database; - - if (!is_resource(Config::get($handle))) { + + if (!is_resource(Config::get($handle))) { $dbh = self::_connect($database); - Config::set($handle,$dbh,1); + Config::set($handle,$dbh,1); return $dbh; - } - else { - return Config::get($handle); - } + } + else { + return Config::get($handle); + } } // dbh @@ -289,19 +289,19 @@ class Dba { * disconnect * This nukes the dbh connection based, this isn't used very often... */ - public static function disconnect($database='') { + public static function disconnect($database='') { - if (!$database) { $database = self::$_default_db; } + if (!$database) { $database = self::$_default_db; } - $handle = 'dbh_' . $database; + $handle = 'dbh_' . $database; // Try to close it correctly - mysql_close(Config::get($handle)); + mysql_close(Config::get($handle)); // Nuke it - Config::set($handle,false,1); + Config::set($handle,false,1); - return true; + return true; } // disconnect @@ -310,10 +310,10 @@ class Dba { * This emulates the mysql_insert_id function, it takes * an optional database target */ - public static function insert_id() { + public static function insert_id() { - $id = mysql_insert_id(self::dbh()); - return $id; + $id = mysql_insert_id(self::dbh()); + return $id; } // insert_id @@ -321,22 +321,22 @@ class Dba { * error * this returns the error of the db */ - public static function error() { + public static function error() { - return mysql_error(); + return mysql_error(); } // error /** * auto_init * This is the auto init function it sets up the config class - * and also sets the default database + * and also sets the default database */ - public static function _auto_init() { + public static function _auto_init() { - self::$_default_db = Config::get('database_name'); + self::$_default_db = Config::get('database_name'); - return true; + return true; } // auto_init @@ -344,51 +344,51 @@ class Dba { * translate_to_mysqlcharset * This translates the specified charset to a mysqlcharset, stupid ass mysql * demands that it's charset list is different! - */ - public static function translate_to_mysqlcharset($charset) { - - // MySQL translte real charset names into fancy smancy MySQL land names - switch (strtoupper($charset)) { - case 'CP1250': - case 'WINDOWS-1250': - $target_charset = 'cp1250'; - $target_collation = 'cp1250_general_ci'; - break; - case 'ISO-8859': - case 'ISO-8859-2': - $target_charset = 'latin2'; - $target_collation = 'latin2_general_ci'; - break; - case 'ISO-8859-1': + */ + public static function translate_to_mysqlcharset($charset) { + + // MySQL translte real charset names into fancy smancy MySQL land names + switch (strtoupper($charset)) { + case 'CP1250': + case 'WINDOWS-1250': + $target_charset = 'cp1250'; + $target_collation = 'cp1250_general_ci'; + break; + case 'ISO-8859': + case 'ISO-8859-2': + $target_charset = 'latin2'; + $target_collation = 'latin2_general_ci'; + break; + case 'ISO-8859-1': case 'CP1252': - case 'WINDOWS-1252': - $target_charset = 'latin1'; - $target_collation = 'latin1_general_ci'; - break; - case 'EUC-KR': - $target_charset = 'euckr'; - $target_collation = 'euckr_korean_ci'; - break; - case 'CP932': - $target_charset = 'sjis'; - $target_collation = 'sjis_japanese_ci'; - break; - case 'KOI8-U': - $target_charset = 'koi8u'; - $target_collation = 'koi8u_general_ci'; - break; - case 'KOI8-R': - $target_charset = 'koi8r'; - $target_collation = 'koi8r_general_ci'; - break; - default; - case 'UTF-8': - $target_charset = 'utf8'; - $target_collation = 'utf8_unicode_ci'; - break; - } // end mysql charset translation - - return array('charset'=>$target_charset,'collation'=>$target_collation); + case 'WINDOWS-1252': + $target_charset = 'latin1'; + $target_collation = 'latin1_general_ci'; + break; + case 'EUC-KR': + $target_charset = 'euckr'; + $target_collation = 'euckr_korean_ci'; + break; + case 'CP932': + $target_charset = 'sjis'; + $target_collation = 'sjis_japanese_ci'; + break; + case 'KOI8-U': + $target_charset = 'koi8u'; + $target_collation = 'koi8u_general_ci'; + break; + case 'KOI8-R': + $target_charset = 'koi8r'; + $target_collation = 'koi8r_general_ci'; + break; + default; + case 'UTF-8': + $target_charset = 'utf8'; + $target_collation = 'utf8_unicode_ci'; + break; + } // end mysql charset translation + + return array('charset'=>$target_charset,'collation'=>$target_collation); } // translate_to_mysqlcharset @@ -396,43 +396,43 @@ class Dba { * reset_db_charset * This cruises through the database and trys to set the charset to the current * site charset, this is an admin function that can be run by an administrator - * this can mess up data if you switch between charsets that are not overlapping + * this can mess up data if you switch between charsets that are not overlapping * a catalog verify must be re-run to correct them */ - public static function reset_db_charset() { + public static function reset_db_charset() { - $translated_charset = self::translate_to_mysqlcharset(Config::get('site_charset')); - $target_charset = $translated_charset['charset']; - $target_collation = $translated_charset['collation']; + $translated_charset = self::translate_to_mysqlcharset(Config::get('site_charset')); + $target_charset = $translated_charset['charset']; + $target_collation = $translated_charset['collation']; // Alter the charset for the entire database - $sql = "ALTER DATABASE `" . Config::get('database_name') . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; - $db_results = Dba::query($sql); + $sql = "ALTER DATABASE `" . Config::get('database_name') . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; + $db_results = Dba::write($sql); - $sql = "SHOW TABLES"; - $db_results = Dba::query($sql); + $sql = "SHOW TABLES"; + $db_results = Dba::read($sql); - // Go through the tables! - while ($row = Dba::fetch_row($db_results)) { - $sql = "DESCRIBE `" . $row['0'] . "`"; - $describe_results = Dba::query($sql); + // Go through the tables! + while ($row = Dba::fetch_row($db_results)) { + $sql = "DESCRIBE `" . $row['0'] . "`"; + $describe_results = Dba::read($sql); // Change the tables default charset and colliation - $sql = "ALTER TABLE `" . $row['0'] . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; - $alter_table = Dba::query($sql); - - // Itterate through the columns of the table - while ($table = Dba::fetch_assoc($describe_results)) { - if (strstr($table['Type'],'varchar') OR strstr($table['Type'],'enum') OR strstr($table['Table'],'text')) { - $sql = "ALTER TABLE `" . $row['0'] . "` MODIFY `" . $table['Field'] . "` " . $table['Type'] . " CHARACTER SET " . $target_charset; - $charset_results = Dba::query($sql); - if (!$charset_results) { - debug_event('CHARSET','Unable to update the charset of ' . $table['Field'] . '.' . $table['Type'] . ' to ' . $target_charset,'3'); - } // if it fails - } // if its a varchar - } // end columns - - } // end tables + $sql = "ALTER TABLE `" . $row['0'] . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; + $alter_table = Dba::write($sql); + + // Itterate through the columns of the table + while ($table = Dba::fetch_assoc($describe_results)) { + if (strstr($table['Type'],'varchar') OR strstr($table['Type'],'enum') OR strstr($table['Table'],'text')) { + $sql = "ALTER TABLE `" . $row['0'] . "` MODIFY `" . $table['Field'] . "` " . $table['Type'] . " CHARACTER SET " . $target_charset; + $charset_results = Dba::write($sql); + if (!$charset_results) { + debug_event('CHARSET','Unable to update the charset of ' . $table['Field'] . '.' . $table['Type'] . ' to ' . $target_charset,'3'); + } // if it fails + } // if its a varchar + } // end columns + + } // end tables } // reset_db_charset diff --git a/lib/class/query.class.php b/lib/class/query.class.php index d44f1453..e3553842 100644 --- a/lib/class/query.class.php +++ b/lib/class/query.class.php @@ -24,28 +24,28 @@ * This handles all of the sql/filtering for the ampache database * this was seperated out from browse, to accomodate Dynamic Playlists */ -class Query { +class Query { // Public static vars that are cached - public static $sql; + public static $sql; public static $start; - public static $offset; - public static $total_objects; - public static $type; + public static $offset; + public static $total_objects; + public static $type; // Static Content, this is defaulted to false, if set to true then when we can't - // apply any filters that would change the result set. - public static $static_content = false; + // apply any filters that would change the result set. + public static $static_content = false; // Private cache information - private static $_cache = array(); - private static $_state = array(); + private static $_cache = array(); + private static $_state = array(); /** * constructor * This should never be called */ - private function __construct() { + private function __construct() { // Rien a faire @@ -58,27 +58,27 @@ class Query { * is saved should I change my mind in the future. It also makes * a single point for whitelist tweaks etc */ - public static function set_filter($key,$value) { + public static function set_filter($key,$value) { - switch ($key) { + switch ($key) { case 'show_art': - if (self::get_filter($key)) { + if (self::get_filter($key)) { unset(self::$_state['filter'][self::$type][$key]); - } - else { - self::$_state['filter'][self::$type][$key] = 1; + } + else { + self::$_state['filter'][self::$type][$key] = 1; } break; case 'tag': - if (is_array($value)) { + if (is_array($value)) { self::$_state['filter'][self::$type][$key] = $value; - } - elseif (is_numeric($value)) { + } + elseif (is_numeric($value)) { self::$_state['filter'][self::$type][$key] = array($value); - } - else { + } + else { self::$_state['filter'][self::$type][$key] = array(); - } + } break; case 'artist': case 'album': @@ -88,52 +88,52 @@ class Query { case 'unplayed': case 'rated': - break; - case 'add_lt': - case 'add_gt': - case 'update_lt': + break; + case 'add_lt': + case 'add_gt': + case 'update_lt': case 'update_gt': - self::$_state['filter'][self::$type][$key] = intval($value); - break; - case 'exact_match': + self::$_state['filter'][self::$type][$key] = intval($value); + break; + case 'exact_match': case 'alpha_match': - case 'starts_with': + case 'starts_with': if (self::$static_content) { return false; } - self::$_state['filter'][self::$type][$key] = $value; + self::$_state['filter'][self::$type][$key] = $value; break; - case 'playlist_type': + case 'playlist_type': // They must be content managers to turn this off - if (self::$_state['filter'][self::$type][$key] AND Access::check('interface','50')) { unset(self::$_state['filter'][self::$type][$key]); } - else { self::$_state['filter'][self::$type][$key] = '1'; } - break; + if (self::$_state['filter'][self::$type][$key] AND Access::check('interface','50')) { unset(self::$_state['filter'][self::$type][$key]); } + else { self::$_state['filter'][self::$type][$key] = '1'; } + break; default: // Rien a faire - return false; + return false; break; } // end switch // If we've set a filter we need to reset the totals - self::reset_total(); - self::set_start(0); + self::reset_total(); + self::set_start(0); + + return true; - return true; - } // set_filter /** * reset * Reset everything, this should only be called when we are starting fresh */ - public static function reset() { + public static function reset() { - self::reset_base(); - self::reset_filters(); - self::reset_total(); - self::reset_join(); - self::reset_select(); - self::reset_having(); - self::set_is_simple(0); - self::set_start(0); + self::reset_base(); + self::reset_filters(); + self::reset_total(); + self::reset_join(); + self::reset_select(); + self::reset_having(); + self::set_is_simple(0); + self::set_start(0); } // reset @@ -141,9 +141,9 @@ class Query { * reset_base * this resets the base string */ - public static function reset_base() { + public static function reset_base() { - self::$_state['base'][self::$type] = NULL; + self::$_state['base'][self::$type] = NULL; } // reset_base @@ -151,19 +151,19 @@ class Query { * reset_select * This resets the select fields that we've added so far */ - public static function reset_select() { + public static function reset_select() { - self::$_state['select'][self::$type] = array(); + self::$_state['select'][self::$type] = array(); - } // reset_select + } // reset_select /** * reset_having * Null out the having clause */ - public static function reset_having() { + public static function reset_having() { - unset(self::$_state['having'][self::$type]); + unset(self::$_state['having'][self::$type]); } // reset_having @@ -171,19 +171,19 @@ class Query { * reset_join * clears the joins if there are any */ - public static function reset_join() { + public static function reset_join() { - unset(self::$_state['join'][self::$type]); + unset(self::$_state['join'][self::$type]); } // reset_join /** * reset_filter - * This is a wrapper function that resets the filters + * This is a wrapper function that resets the filters */ - public static function reset_filters() { + public static function reset_filters() { - self::$_state['filter'] = array(); + self::$_state['filter'] = array(); } // reset_filters @@ -191,9 +191,9 @@ class Query { * reset_total * This resets the total for the browse type */ - public static function reset_total() { + public static function reset_total() { - unset(self::$_state['total'][self::$type]); + unset(self::$_state['total'][self::$type]); } // reset_total @@ -201,28 +201,28 @@ class Query { * get_filter * returns the specified filter value */ - public static function get_filter($key) { - - // Simple enough, but if we ever move this crap - return self::$_state['filter'][self::$type][$key]; + public static function get_filter($key) { + + // Simple enough, but if we ever move this crap + return self::$_state['filter'][self::$type][$key]; } // get_filter /** * get_start * This returns the current value of the start - */ - public static function get_start() { + */ + public static function get_start() { return self::$start; - + } // get_start /** * get_offset * This returns the current offset */ - public static function get_offset() { + public static function get_offset() { return self::$offset; @@ -233,24 +233,24 @@ class Query { * This returns the toal number of obejcts for this current sort type. If it's already cached used it! * if they pass us an array then use that! */ - public static function get_total($objects=false) { - + public static function get_total($objects=false) { + // If they pass something then just return that - if (is_array($objects) and !self::is_simple()) { - return count($objects); - } + if (is_array($objects) and !self::is_simple()) { + return count($objects); + } // See if we can find it in the cache - if (isset(self::$_state['total'][self::$type])) { - return self::$_state['total'][self::$type]; - } + if (isset(self::$_state['total'][self::$type])) { + return self::$_state['total'][self::$type]; + } - $db_results = Dba::read(self::get_sql(false)); - $num_rows = Dba::num_rows($db_results); + $db_results = Dba::read(self::get_sql(false)); + $num_rows = Dba::num_rows($db_results); - self::$_state['total'][self::$type] = $num_rows; + self::$_state['total'][self::$type] = $num_rows; - return $num_rows; + return $num_rows; } // get_total @@ -259,38 +259,38 @@ class Query { * This returns an array of the allowed filters based on the type of object we are working * with, this is used to display the 'filter' sidebar stuff, must be called post browse stuff */ - public static function get_allowed_filters() { + public static function get_allowed_filters() { - switch (self::$type) { - case 'album': + switch (self::$type) { + case 'album': $valid_array = array('add_lt','add_gt','update_lt','update_gt','show_art', - 'starts_with','exact_match','alpha_match'); - break; - case 'artist': - case 'song': - $valid_array = array('add_lt','add_gt','update_lt','update_gt','exact_match','alpha_match','starts_with'); - break; - case 'live_stream': - $valid_array = array('alpha_match','starts_with'); - break; - case 'playlist': - $valid_array = array('alpha_match','starts_with'); - if (Access::check('interface','50')) { - array_push($valid_array,'playlist_type'); - } - break; - case 'tag': - $valid_array = array('object_type','exact_match','alpha_match'); - break; - case 'video': - $valid_array = array('starts_with','exact_match','alpha_match'); - break; - default: - $valid_array = array(); - break; + 'starts_with','exact_match','alpha_match'); + break; + case 'artist': + case 'song': + $valid_array = array('add_lt','add_gt','update_lt','update_gt','exact_match','alpha_match','starts_with'); + break; + case 'live_stream': + $valid_array = array('alpha_match','starts_with'); + break; + case 'playlist': + $valid_array = array('alpha_match','starts_with'); + if (Access::check('interface','50')) { + array_push($valid_array,'playlist_type'); + } + break; + case 'tag': + $valid_array = array('object_type','exact_match','alpha_match'); + break; + case 'video': + $valid_array = array('starts_with','exact_match','alpha_match'); + break; + default: + $valid_array = array(); + break; } // switch on the browsetype - return $valid_array; + return $valid_array; } // get_allowed_filters @@ -300,26 +300,26 @@ class Query { * we do this here so we only have to maintain a single whitelist * and if I want to change the location I only have to do it here */ - public static function set_type($type) { + public static function set_type($type) { - switch($type) { + switch($type) { case 'user': - case 'video': + case 'video': case 'playlist': - case 'playlist_song': + case 'playlist_song': case 'song': case 'flagged': case 'catalog': case 'album': case 'artist': case 'tag': - case 'playlist_localplay': - case 'shoutbox': + case 'playlist_localplay': + case 'shoutbox': case 'live_stream': - case 'democratic': + case 'democratic': // Set it - self::$type = $type; - self::load_start(); + self::$type = $type; + self::load_start(); break; default: // Rien a faire @@ -331,9 +331,9 @@ class Query { * get_type * This returns the type of the browse we currently are using */ - public static function get_type() { + public static function get_type() { - return self::$type; + return self::$type; } // get_type @@ -341,61 +341,61 @@ class Query { * set_sort * This sets the current sort(s) */ - public static function set_sort($sort,$order='') { + public static function set_sort($sort,$order='') { - switch (self::get_type()) { - case 'playlist_song': - case 'song': - $valid_array = array('title','year','track','time','album','artist'); + switch (self::get_type()) { + case 'playlist_song': + case 'song': + $valid_array = array('title','year','track','time','album','artist'); break; - case 'artist': - $valid_array = array('name','album'); + case 'artist': + $valid_array = array('name','album'); + break; + case 'tag': + $valid_array = array('tag'); break; - case 'tag': - $valid_array = array('tag'); - break; - case 'album': - $valid_array = array('name','year','artist'); + case 'album': + $valid_array = array('name','year','artist'); break; - case 'playlist': + case 'playlist': $valid_array = array('name','user'); - break; - case 'shoutbox': - $valid_array = array('date','user','sticky'); - break; - case 'live_stream': - $valid_array = array('name','call_sign','frequency'); break; - case 'video': - $valid_array = array('title','resolution','length','codec'); - break; + case 'shoutbox': + $valid_array = array('date','user','sticky'); + break; + case 'live_stream': + $valid_array = array('name','call_sign','frequency'); + break; + case 'video': + $valid_array = array('title','resolution','length','codec'); + break; case 'user': $valid_array = array('fullname','username','last_seen','create_date'); break; - } // end switch + } // end switch // If it's not in our list, smeg off! - if (!in_array($sort,$valid_array)) { - return false; + if (!in_array($sort,$valid_array)) { + return false; } - if ($order) { - $order = ($order == 'DESC') ? 'DESC' : 'ASC'; - self::$_state['sort'][self::$type] = array(); - self::$_state['sort'][self::$type][$sort] = $order; - } - elseif (self::$_state['sort'][self::$type][$sort] == 'DESC') { + if ($order) { + $order = ($order == 'DESC') ? 'DESC' : 'ASC'; + self::$_state['sort'][self::$type] = array(); + self::$_state['sort'][self::$type][$sort] = $order; + } + elseif (self::$_state['sort'][self::$type][$sort] == 'DESC') { // Reset it till I can figure out how to interface the hotness - self::$_state['sort'][self::$type] = array(); - self::$_state['sort'][self::$type][$sort] = 'ASC'; + self::$_state['sort'][self::$type] = array(); + self::$_state['sort'][self::$type][$sort] = 'ASC'; } - else { + else { // Reset it till I can figure out how to interface the hotness - self::$_state['sort'][self::$type] = array(); - self::$_state['sort'][self::$type][$sort] = 'DESC'; - } - - self::resort_objects(); + self::$_state['sort'][self::$type] = array(); + self::$_state['sort'][self::$type][$sort] = 'DESC'; + } + + self::resort_objects(); } // set_sort @@ -403,7 +403,7 @@ class Query { * set_offset * This sets the current offset of this query */ - public static function set_offset($offset) { + public static function set_offset($offset) { self::$offset = abs($offset); @@ -412,21 +412,21 @@ class Query { /** * set_select * This appends more information to the select part of the SQL statement, we're going to move to the - * %%SELECT%% style queries, as I think it's the only way to do this.... + * %%SELECT%% style queries, as I think it's the only way to do this.... */ - public static function set_select($field) { + public static function set_select($field) { - self::$_state['select'][self::$type][] = $field; + self::$_state['select'][self::$type][] = $field; } // set_select /** - * set_join + * set_join * This sets the joins for the current browse object */ - public static function set_join($type,$table,$source,$dest,$priority=100) { + public static function set_join($type,$table,$source,$dest,$priority=100) { - self::$_state['join'][self::$type][$priority][$table] = strtoupper($type) . ' JOIN ' . $table . ' ON ' . $source . '=' . $dest; + self::$_state['join'][self::$type][$priority][$table] = strtoupper($type) . ' JOIN ' . $table . ' ON ' . $source . '=' . $dest; } // set_join @@ -434,11 +434,11 @@ class Query { * set_having * This sets the "HAVING" part of the query, we can only have one.. god this is ugly */ - public static function set_having($condition) { + public static function set_having($condition) { - self::$_state['having'][self::$type] = $condition; + self::$_state['having'][self::$type] = $condition; - } // set_having + } // set_having /** * set_start @@ -446,12 +446,12 @@ class Query { * We need to store this in the session so that it can be pulled * back, if they hit the back button */ - public static function set_start($start) { + public static function set_start($start) { - if (!self::$static_content) { - self::$_state[self::$type]['start'] = intval($start); - } - self::$start = intval($start); + if (!self::$static_content) { + self::$_state[self::$type]['start'] = intval($start); + } + self::$start = intval($start); } // set_start @@ -460,10 +460,10 @@ class Query { * This sets the current browse object to a 'simple' browse method * which means use the base query provided and expand from there */ - public static function set_is_simple($value) { + public static function set_is_simple($value) { - $value = make_bool($value); - self::$_state['simple'][self::$type] = $value; + $value = make_bool($value); + self::$_state['simple'][self::$type] = $value; } // set_is_simple @@ -473,17 +473,17 @@ class Query { * should be static, if they are then content filtering/altering * methods will be skipped */ - public static function set_static_content($value) { + public static function set_static_content($value) { - $value = make_bool($value); - self::$static_content = $value; + $value = make_bool($value); + self::$static_content = $value; // We want to start at 0 it's static - if ($value) { - self::set_start('0'); - } + if ($value) { + self::set_start('0'); + } - self::$_state[self::$type]['static'] = $value; + self::$_state[self::$type]['static'] = $value; } // set_static_content @@ -491,9 +491,9 @@ class Query { * is_simple * this returns true or false if the current browse type is set to static */ - public static function is_simple() { + public static function is_simple() { - return self::$_state['simple'][self::$type]; + return self::$_state['simple'][self::$type]; } // is_simple @@ -501,41 +501,41 @@ class Query { * load_start * This returns a stored start point for the browse mojo */ - public static function load_start() { + public static function load_start() { - self::$start = intval(self::$_state[self::$type]['start']); + self::$start = intval(self::$_state[self::$type]['start']); } // end load_start /** * get_saved - * This looks in the session for the saved + * This looks in the session for the saved * stuff and returns what it finds */ - public static function get_saved() { + public static function get_saved() { // See if we have it in the local cache first - if (is_array(self::$_cache['browse'][self::$type])) { - return self::$_cache['browse'][self::$type]; - } + if (is_array(self::$_cache['browse'][self::$type])) { + return self::$_cache['browse'][self::$type]; + } - if (!self::is_simple()) { + if (!self::is_simple()) { // If not then we're going to need to read from the database :( $sid = session_id(); - $type = Dba::escape(self::$type); + $type = Dba::escape(self::$type); - $sql = "SELECT `data` FROM `tmp_browse` WHERE `sid`='$sid' AND `type`='$type'"; - $db_results = Dba::read($sql); + $sql = "SELECT `data` FROM `tmp_browse` WHERE `sid`='$sid' AND `type`='$type'"; + $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + $row = Dba::fetch_assoc($db_results); - $objects = unserialize($row['data']); - } - else { - $objects = self::get_objects(); - } + $objects = unserialize($row['data']); + } + else { + $objects = self::get_objects(); + } - return $objects; + return $objects; } // get_saved @@ -545,31 +545,31 @@ class Query { * currently browsing by it applies the sql and logic based * filters */ - public static function get_objects() { + public static function get_objects() { // First we need to get the SQL statement we are going to run // This has to run against any possible filters (dependent on type) - $sql = self::get_sql(); - $db_results = Dba::query($sql); + $sql = self::get_sql(); + $db_results = Dba::read($sql); - $results = array(); - while ($data = Dba::fetch_assoc($db_results)) { + $results = array(); + while ($data = Dba::fetch_assoc($db_results)) { $results[] = $data; } $results = self::post_process($results); $filtered = array(); - foreach ($results as $data) { + foreach ($results as $data) { // Make sure that this object passes the logic filter - if (self::logic_filter($data['id'])) { - $filtered[] = $data['id']; - } + if (self::logic_filter($data['id'])) { + $filtered[] = $data['id']; + } } // end while - + // Save what we've found and then return it - self::save_objects($filtered); + self::save_objects($filtered); - return $filtered; + return $filtered; } // get_objects @@ -577,22 +577,22 @@ class Query { * set_base_sql * This saves the base sql statement we are going to use. */ - private static function set_base_sql() { + private static function set_base_sql() { // Only allow it to be set once - if (strlen(self::$_state['base'][self::$type])) { return true; } + if (strlen(self::$_state['base'][self::$type])) { return true; } switch (self::$type) { case 'album': - self::set_select("DISTINCT(`album`.`id`)"); + self::set_select("DISTINCT(`album`.`id`)"); $sql = "SELECT %%SELECT%% FROM `album` "; break; case 'artist': - self::set_select("DISTINCT(`artist`.`id`)"); + self::set_select("DISTINCT(`artist`.`id`)"); $sql = "SELECT %%SELECT%% FROM `artist` "; break; case 'user': - self::set_select("`user`.`id`"); + self::set_select("`user`.`id`"); $sql = "SELECT %%SELECT%% FROM `user` "; break; case 'live_stream': @@ -600,35 +600,35 @@ class Query { $sql = "SELECT %%SELECT%% FROM `live_stream` "; break; case 'playlist': - self::set_select("`playlist`.`id`"); + self::set_select("`playlist`.`id`"); $sql = "SELECT %%SELECT%% FROM `playlist` "; break; - case 'flagged': - self::set_select("`flagged`.`id`"); + case 'flagged': + self::set_select("`flagged`.`id`"); $sql = "SELECT %%SELECT%% FROM `flagged` "; break; - case 'shoutbox': - self::set_select("`user_shout`.`id`"); - $sql = "SELECT %%SELECT%% FROM `user_shout` "; - break; - case 'video': - self::set_select("`video`.`id`"); + case 'shoutbox': + self::set_select("`user_shout`.`id`"); + $sql = "SELECT %%SELECT%% FROM `user_shout` "; + break; + case 'video': + self::set_select("`video`.`id`"); $sql = "SELECT %%SELECT%% FROM `video` "; - break; - case 'tag': - self::set_select("DISTINCT(`tag`.`id`)"); - self::set_join('left','tag_map','`tag_map`.`tag_id`','`tag`.`id`',1); - $sql = "SELECT %%SELECT%% FROM `tag` "; - break; - case 'playlist_song': + break; + case 'tag': + self::set_select("DISTINCT(`tag`.`id`)"); + self::set_join('left','tag_map','`tag_map`.`tag_id`','`tag`.`id`',1); + $sql = "SELECT %%SELECT%% FROM `tag` "; + break; + case 'playlist_song': case 'song': default: - self::set_select("DISTINCT(`song`.`id`)"); + self::set_select("DISTINCT(`song`.`id`)"); $sql = "SELECT %%SELECT%% FROM `song` "; break; } // end base sql - self::$_state['base'][self::$type] = $sql; + self::$_state['base'][self::$type] = $sql; } // set_base_sql @@ -636,10 +636,10 @@ class Query { * get_select * This returns the selects in a format that is friendly for a sql statement */ - private static function get_select() { + private static function get_select() { - $select_string = implode(self::$_state['select'][self::$type],", "); - return $select_string; + $select_string = implode(self::$_state['select'][self::$type],", "); + return $select_string; } // get_select @@ -647,15 +647,15 @@ class Query { * get_base_sql * This returns the base sql statement all parsed up, this should be called after all set operations */ - private static function get_base_sql() { - + private static function get_base_sql() { + // Legacy code, should be removed once other code is updated //FIXME: REMOVE - if (!self::$_state['base'][self::$type]) { self::set_base_sql(); } + if (!self::$_state['base'][self::$type]) { self::set_base_sql(); } - $sql = str_replace("%%SELECT%%",self::get_select(),self::$_state['base'][self::$type]); + $sql = str_replace("%%SELECT%%",self::get_select(),self::$_state['base'][self::$type]); - return $sql; + return $sql; } // get_base_sql @@ -663,42 +663,42 @@ class Query { * get_filter_sql * This returns the filter part of the sql statement */ - private static function get_filter_sql() { + private static function get_filter_sql() { - if (!is_array(self::$_state['filter'][self::$type])) { - return ''; - } + if (!is_array(self::$_state['filter'][self::$type])) { + return ''; + } $sql = "WHERE 1=1 AND "; - foreach (self::$_state['filter'][self::$type] as $key=>$value) { - $sql .= self::sql_filter($key,$value); - } + foreach (self::$_state['filter'][self::$type] as $key=>$value) { + $sql .= self::sql_filter($key,$value); + } - $sql = rtrim($sql,'AND ') . ' '; + $sql = rtrim($sql,'AND ') . ' '; - return $sql; + return $sql; } // get_filter_sql /** * get_sort_sql - * Returns the sort sql part + * Returns the sort sql part */ - private static function get_sort_sql() { - - if (!is_array(self::$_state['sort'][self::$type])) { return ''; } + private static function get_sort_sql() { - $sql = 'ORDER BY '; + if (!is_array(self::$_state['sort'][self::$type])) { return ''; } - foreach (self::$_state['sort'][self::$type] as $key=>$value) { - $sql .= self::sql_sort($key,$value); - } + $sql = 'ORDER BY '; - $sql = rtrim($sql,'ORDER BY '); - $sql = rtrim($sql,','); + foreach (self::$_state['sort'][self::$type] as $key=>$value) { + $sql .= self::sql_sort($key,$value); + } + + $sql = rtrim($sql,'ORDER BY '); + $sql = rtrim($sql,','); - return $sql; + return $sql; } // get_sort_sql @@ -706,36 +706,36 @@ class Query { * get_limit_sql * This returns the limit part of the sql statement */ - private static function get_limit_sql() { + private static function get_limit_sql() { - if (!self::is_simple()) { return ''; } + if (!self::is_simple()) { return ''; } - $sql = ' LIMIT ' . intval(self::$start) . ',' . intval(self::$offset); + $sql = ' LIMIT ' . intval(self::$start) . ',' . intval(self::$offset); - return $sql; + return $sql; - } // get_limit_sql + } // get_limit_sql /** * get_join_sql * This returns the joins that this browse may need to work correctly */ - private static function get_join_sql() { - - if (!is_array(self::$_state['join'][self::$type])) { - return ''; - } + private static function get_join_sql() { + + if (!is_array(self::$_state['join'][self::$type])) { + return ''; + } - $sql = ''; + $sql = ''; // We need to itterate through these from 0 - 100 so that we add the joins in the right order foreach (self::$_state['join'][self::$type] as $joins) { - foreach ($joins as $join) { - $sql .= $join . ' '; + foreach ($joins as $join) { + $sql .= $join . ' '; } // end foreach joins at this level } // end foreach of this level of joins - return $sql; + return $sql; } // get_join_sql @@ -743,11 +743,11 @@ class Query { * get_having_sql * this returns the having sql stuff, if we've got anything */ - public static function get_having_sql() { + public static function get_having_sql() { - $sql = self::$_state['having'][self::$type]; + $sql = self::$_state['having'][self::$type]; - return $sql; + return $sql; } // get_having_sql @@ -757,21 +757,21 @@ class Query { * every time we get the objects because it depends on the filters and the * type of object we are currently browsing */ - public static function get_sql($limit=true) { + public static function get_sql($limit=true) { - $sql = self::get_base_sql(); + $sql = self::get_base_sql(); - $filter_sql = self::get_filter_sql(); - $join_sql = self::get_join_sql(); - $having_sql = self::get_having_sql(); - $order_sql = self::get_sort_sql(); - $limit_sql = $limit ? self::get_limit_sql() : ''; + $filter_sql = self::get_filter_sql(); + $join_sql = self::get_join_sql(); + $having_sql = self::get_having_sql(); + $order_sql = self::get_sort_sql(); + $limit_sql = $limit ? self::get_limit_sql() : ''; - $final_sql = $sql . $join_sql . $filter_sql . $having_sql . $order_sql . $limit_sql; + $final_sql = $sql . $join_sql . $filter_sql . $having_sql . $order_sql . $limit_sql; return $final_sql; - } // get_sql + } // get_sql /** * post_process @@ -781,23 +781,23 @@ class Query { $tags = self::$_state['filter']['tag']; - if (!is_array($tags) || sizeof($tags) < 2) { + if (!is_array($tags) || sizeof($tags) < 2) { return $results; - } + } $cnt = sizeof($tags); $ar = array(); - foreach($results as $row) { + foreach($results as $row) { $ar[$row['id']]++; } $res = array(); - foreach($ar as $k=>$v) { - if ($v >= $cnt) { + foreach($ar as $k=>$v) { + if ($v >= $cnt) { $res[] = array('id' => $k); } - } // end foreach + } // end foreach return $res; @@ -809,24 +809,24 @@ class Query { * to filter by this name on this type returns the approiate sql * if not returns nothing */ - private static function sql_filter($filter,$value) { - - $filter_sql = ''; - - switch (self::$type) { - case 'song': - switch($filter) { - case 'exact_match': - $filter_sql = " `song`.`title` = '" . Dba::escape($value) . "' AND "; - break; + private static function sql_filter($filter,$value) { + + $filter_sql = ''; + + switch (self::$type) { + case 'song': + switch($filter) { + case 'exact_match': + $filter_sql = " `song`.`title` = '" . Dba::escape($value) . "' AND "; + break; case 'alpha_match': $filter_sql = " `song`.`title` LIKE '%" . Dba::escape($value) . "%' AND "; break; - case 'starts_with': - $filter_sql = " `song`.`title` LIKE '" . Dba::escape($value) . "%' AND "; - break; + case 'starts_with': + $filter_sql = " `song`.`title` LIKE '" . Dba::escape($value) . "%' AND "; + break; case 'unplayed': - $filter_sql = " `song`.`played`='0' AND "; + $filter_sql = " `song`.`played`='0' AND "; break; case 'album': $filter_sql = " `song`.`album` = '". Dba::escape($value) . "' AND "; @@ -834,126 +834,126 @@ class Query { case 'artist': $filter_sql = " `song`.`artist` = '". Dba::escape($value) . "' AND "; break; - case 'add_gt': - $filter_sql = " `song`.`addition_time` >= '" . Dba::escape($value) . "' AND "; - break; - case 'add_lt': - $filter_sql = " `song`.`addition_time` <= '" . Dba::escape($value) . "' AND "; - break; - case 'update_gt': - $filter_sql = " `song`.`update_time` >= '" . Dba::escape($value) . "' AND "; - break; - case 'update_lt': - $filter_sql = " `song`.`update_time` <= '" . Dba::escape($value) . "' AND "; - break; - case 'catalog': - $catalogs = $GLOBALS['user']->get_catalogs(); - if (!count($catalogs)) { break; } - $filter_sql .= " `song`.`catalog` IN (" . implode(',',$GLOBALS['user']->get_catalogs()) . ") AND "; - break; - default: + case 'add_gt': + $filter_sql = " `song`.`addition_time` >= '" . Dba::escape($value) . "' AND "; + break; + case 'add_lt': + $filter_sql = " `song`.`addition_time` <= '" . Dba::escape($value) . "' AND "; + break; + case 'update_gt': + $filter_sql = " `song`.`update_time` >= '" . Dba::escape($value) . "' AND "; + break; + case 'update_lt': + $filter_sql = " `song`.`update_time` <= '" . Dba::escape($value) . "' AND "; + break; + case 'catalog': + $catalogs = $GLOBALS['user']->get_catalogs(); + if (!count($catalogs)) { break; } + $filter_sql .= " `song`.`catalog` IN (" . implode(',',$GLOBALS['user']->get_catalogs()) . ") AND "; + break; + default: // Rien a faire break; } // end list of sqlable filters - break; - case 'album': - switch($filter) { - case 'exact_match': - $filter_sql = " `album`.`name` = '" . Dba::escape($value) . "' AND "; - break; + break; + case 'album': + switch($filter) { + case 'exact_match': + $filter_sql = " `album`.`name` = '" . Dba::escape($value) . "' AND "; + break; case 'alpha_match': - $filter_sql = " `album`.`name` LIKE '%" . Dba::escape($value) . "%' AND "; + $filter_sql = " `album`.`name` LIKE '%" . Dba::escape($value) . "%' AND "; + break; + case 'starts_with': + $filter_sql = " `album`.`name` LIKE '" . Dba::escape($value) . "%' AND "; break; - case 'starts_with': - $filter_sql = " `album`.`name` LIKE '" . Dba::escape($value) . "%' AND "; - break; case 'artist': $filter_sql = " `artist`.`id` = '". Dba::escape($value) . "' AND "; break; - case 'add_lt': - self::set_join('left','`song`','`song`.`album`','`album`.`id`'); - $filter_sql = " `song`.`addition_time` <= '" . Dba::escape($value) . "' AND "; + case 'add_lt': + self::set_join('left','`song`','`song`.`album`','`album`.`id`'); + $filter_sql = " `song`.`addition_time` <= '" . Dba::escape($value) . "' AND "; + break; + case 'add_gt': + self::set_join('left','`song`','`song`.`album`','`album`.`id`'); + $filter_sql = " `song`.`addition_time` >= '" . Dba::escape($value) . "' AND "; break; - case 'add_gt': - self::set_join('left','`song`','`song`.`album`','`album`.`id`'); - $filter_sql = " `song`.`addition_time` >= '" . Dba::escape($value) . "' AND "; + case 'update_lt': + self::set_join('left','`song`','`song`.`album`','`album`.`id`'); + $filter_sql = " `song`.`update_time` <= '" . Dba::escape($value) . "' AND "; break; - case 'update_lt': + case 'update_gt': self::set_join('left','`song`','`song`.`album`','`album`.`id`'); - $filter_sql = " `song`.`update_time` <= '" . Dba::escape($value) . "' AND "; + $filter_sql = " `song`.`update_time` >= '" . Dba::escape($value) . "' AND "; break; - case 'update_gt': - self::set_join('left','`song`','`song`.`album`','`album`.`id`'); - $filter_sql = " `song`.`update_time` >= '" . Dba::escape($value) . "' AND "; - break; - default: + default: // Rien a faire break; - } + } break; - case 'artist': - switch($filter) { - case 'exact_match': - $filter_sql = " `artist`.`name` = '" . Dba::escape($value) . "' AND "; - break; + case 'artist': + switch($filter) { + case 'exact_match': + $filter_sql = " `artist`.`name` = '" . Dba::escape($value) . "' AND "; + break; case 'alpha_match': $filter_sql = " `artist`.`name` LIKE '%" . Dba::escape($value) . "%' AND "; break; - case 'starts_with': - $filter_sql = " `artist`.`name` LIKE '" . Dba::escape($value) . "%' AND "; + case 'starts_with': + $filter_sql = " `artist`.`name` LIKE '" . Dba::escape($value) . "%' AND "; break; - case 'add_lt': - self::set_join('left','`song`','`song`.`artist`','`artist`.`id`'); - $filter_sql = " `song`.`addition_time` <= '" . Dba::escape($value) . "' AND "; + case 'add_lt': + self::set_join('left','`song`','`song`.`artist`','`artist`.`id`'); + $filter_sql = " `song`.`addition_time` <= '" . Dba::escape($value) . "' AND "; break; - case 'add_gt': - self::set_join('left','`song`','`song`.`artist`','`artist`.`id`'); - $filter_sql = " `song`.`addition_time` >= '" . Dba::escape($value) . "' AND "; + case 'add_gt': + self::set_join('left','`song`','`song`.`artist`','`artist`.`id`'); + $filter_sql = " `song`.`addition_time` >= '" . Dba::escape($value) . "' AND "; break; case 'update_lt': - self::set_join('left','`song`','`song`.`artist`','`artist`.`id`'); - $filter_sql = " `song`.`update_time` <= '" . Dba::escape($value) . "' AND "; - break; - case 'update_gt': - self::set_join('left','`song`','`song`.`artist`','`artist`.`id`'); - $filter_sql = " `song`.`update_time` >= '" . Dba::escape($value) . "' AND "; - break; + self::set_join('left','`song`','`song`.`artist`','`artist`.`id`'); + $filter_sql = " `song`.`update_time` <= '" . Dba::escape($value) . "' AND "; + break; + case 'update_gt': + self::set_join('left','`song`','`song`.`artist`','`artist`.`id`'); + $filter_sql = " `song`.`update_time` >= '" . Dba::escape($value) . "' AND "; + break; default: // Rien a faire break; } // end filter break; - case 'live_stream': - switch ($filter) { + case 'live_stream': + switch ($filter) { case 'alpha_match': - $filter_sql = " `live_stream`.`name` LIKE '%" . Dba::escape($value) . "%' AND "; + $filter_sql = " `live_stream`.`name` LIKE '%" . Dba::escape($value) . "%' AND "; + break; + case 'starts_with': + $filter_sql = " `live_stream`.`name` LIKE '" . Dba::escape($value) . "%' AND "; break; - case 'starts_with': - $filter_sql = " `live_stream`.`name` LIKE '" . Dba::escape($value) . "%' AND "; - break; - default: + default: // Rien a faire break; } // end filter - break; - case 'playlist': - switch ($filter) { - case 'alpha_match': - $filter_sql = " `playlist`.`name` LIKE '%" . Dba::escape($value) . "%' AND "; + break; + case 'playlist': + switch ($filter) { + case 'alpha_match': + $filter_sql = " `playlist`.`name` LIKE '%" . Dba::escape($value) . "%' AND "; + break; + case 'starts_with': + $filter_sql = " `playlist`.`name` LIKE '" . Dba::escape($value) . "%' AND "; break; - case 'starts_with': - $filter_sql = " `playlist`.`name` LIKE '" . Dba::escape($value) . "%' AND "; + case 'playlist_type': + $user_id = intval($GLOBALS['user']->id); + $filter_sql = " (`playlist`.`type` = 'public' OR `playlist`.`user`='$user_id') AND "; break; - case 'playlist_type': - $user_id = intval($GLOBALS['user']->id); - $filter_sql = " (`playlist`.`type` = 'public' OR `playlist`.`user`='$user_id') AND "; - break; - default; + default; // Rien a faire break; } // end filter - break; - case 'tag': + break; + case 'tag': switch ($filter) { case 'alpha_match': $filter_sql = " `tag`.`name` LIKE '%" . Dba::escape($value) . "%' AND "; @@ -966,22 +966,22 @@ class Query { break; } // end filter break; - case 'video': - switch ($filter) { - case 'alpha_match': - $filter_sql = " `video`.`title` LIKE '%" . Dba::escape($value) . "%' AND "; - break; - case 'starts_with': - $filter_sql = " `video`.`title` LIKE '" . Dba::escape($value) . "%' AND "; + case 'video': + switch ($filter) { + case 'alpha_match': + $filter_sql = " `video`.`title` LIKE '%" . Dba::escape($value) . "%' AND "; break; - default: + case 'starts_with': + $filter_sql = " `video`.`title` LIKE '" . Dba::escape($value) . "%' AND "; + break; + default: // Rien a faire - break; + break; } // end filter - break; - } // end switch on type + break; + } // end switch on type - return $filter_sql; + return $filter_sql; } // sql_filter @@ -992,9 +992,9 @@ class Query { * these should be limited as they are often intensive and * require additional queries per object... :( */ - private static function logic_filter($object_id) { + private static function logic_filter($object_id) { - return true; + return true; } // logic_filter @@ -1005,91 +1005,91 @@ class Query { * a logic based sort that will come later as that's * a lot more complicated */ - private static function sql_sort($field,$order) { + private static function sql_sort($field,$order) { - if ($order != 'DESC') { $order == 'ASC'; } + if ($order != 'DESC') { $order == 'ASC'; } // Depending on the type of browsing we are doing we can apply different filters that apply to different fields - switch (self::$type) { - case 'song': - switch($field) { + switch (self::$type) { + case 'song': + switch($field) { case 'title'; - $sql = "`song`.`title`"; + $sql = "`song`.`title`"; break; case 'year': - $sql = "`song`.`year`"; + $sql = "`song`.`year`"; + break; + case 'time': + $sql = "`song`.`time`"; break; - case 'time': - $sql = "`song`.`time`"; + case 'track': + $sql = "`song`.`track`"; break; - case 'track': - $sql = "`song`.`track`"; + case 'album': + $sql = '`album`.`name`'; + self::set_join('left','`album`','`album`.`id`','`song`.`album`'); break; - case 'album': - $sql = '`album`.`name`'; - self::set_join('left','`album`','`album`.`id`','`song`.`album`'); - break; - case 'artist': - $sql = '`artist`.`name`'; - self::set_join('left','`artist`','`artist`.`id`','`song`.`artist`'); - break; - default: + case 'artist': + $sql = '`artist`.`name`'; + self::set_join('left','`artist`','`artist`.`id`','`song`.`artist`'); + break; + default: // Rien a faire break; } // end switch break; - case 'album': - switch($field) { - case 'name': - $sql = "`album`.`name` $order, `album`.`disk`"; + case 'album': + switch($field) { + case 'name': + $sql = "`album`.`name` $order, `album`.`disk`"; break; - case 'artist': - $sql = "`artist`.`name`"; - self::set_join('left','`song`','`song`.`album`','`album`.`id`'); - self::set_join('left','`artist`','`song`.`artist`','`artist`.`id`'); + case 'artist': + $sql = "`artist`.`name`"; + self::set_join('left','`song`','`song`.`album`','`album`.`id`'); + self::set_join('left','`artist`','`song`.`artist`','`artist`.`id`'); break; - case 'year': - $sql = "`album`.`year`"; + case 'year': + $sql = "`album`.`year`"; break; } // end switch break; - case 'artist': - switch ($field) { - case 'name': - $sql = "`artist`.`name`"; + case 'artist': + switch ($field) { + case 'name': + $sql = "`artist`.`name`"; break; - } // end switch + } // end switch break; - case 'playlist': - switch ($field) { + case 'playlist': + switch ($field) { case 'type': - $sql = "`playlist`.`type`"; - break; + $sql = "`playlist`.`type`"; + break; case 'name': - $sql = "`playlist`.`name`"; + $sql = "`playlist`.`name`"; break; - case 'user': + case 'user': $sql = "`playlist`.`user`"; - break; + break; } // end switch - break; - case 'live_stream': - switch ($field) { + break; + case 'live_stream': + switch ($field) { case 'name': - $sql = "`live_stream`.`name`"; + $sql = "`live_stream`.`name`"; break; case 'call_sign': $sql = "`live_stream`.`call_sign`"; break; - case 'frequency': - $sql = "`live_stream`.`frequency`"; - break; + case 'frequency': + $sql = "`live_stream`.`frequency`"; + break; } // end switch break; - case 'genre': - switch ($field) { - case 'name': - $sql = "`genre`.`name`"; + case 'genre': + switch ($field) { + case 'name': + $sql = "`genre`.`name`"; break; } // end switch break; @@ -1109,30 +1109,30 @@ class Query { break; } // end switch break; - case 'video': - switch ($field) { - case 'title': - $sql = "`video`.`title`"; - break; - case 'resolution': - $sql = "`video`.`resolution_x`"; + case 'video': + switch ($field) { + case 'title': + $sql = "`video`.`title`"; break; - case 'length': - $sql = "`video`.`time`"; + case 'resolution': + $sql = "`video`.`resolution_x`"; + break; + case 'length': + $sql = "`video`.`time`"; + break; + case 'codec': + $sql = "`video`.`video_codec`"; break; - case 'codec': - $sql = "`video`.`video_codec`"; - break; } // end switch on field - break; - default: + break; + default: // Rien a faire break; } // end switch - if ($sql) { $sql_sort = "$sql $order,"; } - - return $sql_sort; + if ($sql) { $sql_sort = "$sql $order,"; } + + return $sql_sort; } // sql_sort @@ -1140,32 +1140,32 @@ class Query { * resort_objects * This takes the existing objects, looks at the current * sort method and then re-sorts them This is internally - * called by the set_sort() function + * called by the set_sort() function */ - private static function resort_objects() { + private static function resort_objects() { - // There are two ways to do this.. the easy way... + // There are two ways to do this.. the easy way... // and the vollmer way, hopefully we don't have to // do it the vollmer way - if (self::is_simple()) { - $sql = self::get_sql(); - } - else { + if (self::is_simple()) { + $sql = self::get_sql(); + } + else { // First pull the objects - $objects = self::get_saved(); + $objects = self::get_saved(); // If there's nothing there don't do anything if (!count($objects) or !is_array($objects)) { return false; - } + } $type = self::$type; $where_sql = "WHERE `$type`.`id` IN ("; foreach ($objects as $object_id) { $object_id = Dba::escape($object_id); $where_sql .= "'$object_id',"; - } - $where_sql = rtrim($where_sql,','); + } + $where_sql = rtrim($where_sql,','); $where_sql .= ")"; @@ -1175,23 +1175,23 @@ class Query { foreach (self::$_state['sort'][self::$type] as $key=>$value) { $order_sql .= self::sql_sort($key,$value); - } + } // Clean her up $order_sql = rtrim($order_sql,"ORDER BY "); $order_sql = rtrim($order_sql,","); - + $sql = $sql . self::get_join_sql() . $where_sql . $order_sql; } // if not simple - - $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['id']; - } - - self::save_objects($results); + $db_results = Dba::read($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } + + self::save_objects($results); - return true; + return true; } // resort_objects @@ -1202,22 +1202,22 @@ class Query { */ public static function save_objects($object_ids) { - // Saving these objects has two operations, one hold it in + // Saving these objects has two operations, one hold it in // a local variable and then second hold it in a row in the tmp_browse // table self::$_cache['browse'][self::$type] = $object_ids; // Only do this if it's a not a simple browse if (!self::is_simple()) { - $sid = Dba::escape(session_id()); + $sid = Dba::escape(session_id()); $data = Dba::escape(serialize($object_ids)); - $type = Dba::escape(self::$type); + $type = Dba::escape(self::$type); $sql = "REPLACE INTO `tmp_browse` SET `data`='$data', `sid`='$sid',`type`='$type'"; $db_results = Dba::write($sql); self::$total_objects = count($object_ids); - } // save it + } // save it return true; @@ -1225,13 +1225,13 @@ class Query { /** * _auto_init - * this function reloads information back from the session + * this function reloads information back from the session * it is called on creation of the class */ - public static function _auto_init() { + public static function _auto_init() { self::$offset = Config::get('offset_limit') ? Config::get('offset_limit') : '25'; - self::$_state = &$_SESSION['browse']; + self::$_state = &$_SESSION['browse']; } // _auto_init @@ -1239,10 +1239,10 @@ class Query { * get_state * This is a debug only function */ - public static function get_state() { + public static function get_state() { - return self::$_state; + return self::$_state; - } // get_state + } // get_state } // query diff --git a/lib/class/update.class.php b/lib/class/update.class.php index 198172af..25bbc215 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -20,12 +20,12 @@ /** * Update Class - * this class handles updating from one version of + * this class handles updating from one version of * ampache to the next. Versions are a 6 digit number * 220000 * ^ * Major Revision - * + * * 220000 * ^ * Minor Revision @@ -45,7 +45,7 @@ class Update { */ function Update ( $key=0 ) { - if (!$key) { return false; } + if (!$key) { return false; } $this->key = intval($key); $info = $this->_get_info(); @@ -63,28 +63,28 @@ class Update { $sql = "SELECT * FROM `update_info` WHERE `key`='$this->key'"; $db_results = Dba::read($sql); - return Dba::fetch_assoc($db_results); + return Dba::fetch_assoc($db_results); } // _get_info /** * get_version * this checks to see what version you are currently running - * because we may not have the update_info table we have to check - * for it's existance first. + * because we may not have the update_info table we have to check + * for it's existance first. */ public static function get_version() { /* Make sure that update_info exits */ $sql = "SHOW TABLES LIKE 'update_info'"; $db_results = Dba::read($sql); - if (!is_resource(Dba::dbh())) { header("Location: test.php"); } + if (!is_resource(Dba::dbh())) { header("Location: test.php"); } // If no table if (!Dba::num_rows($db_results)) { // They can't upgrade, they are too old header("Location: test.php"); - + } // if table isn't found else { @@ -93,7 +93,7 @@ class Update { $db_results = Dba::read($sql); $results = Dba::fetch_assoc($db_results); $version = $results['value']; - } + } return $version; @@ -105,7 +105,7 @@ class Update { */ public static function format_version($data) { - $new_version = substr($data,0,strlen($data) - 5) . "." . substr($data,strlen($data)-5,1) . " Build:" . + $new_version = substr($data,0,strlen($data) - 5) . "." . substr($data,strlen($data)-5,1) . " Build:" . substr($data,strlen($data)-4,strlen($data)); return $new_version; @@ -114,18 +114,18 @@ class Update { /** * need_update - * checks to see if we need to update + * checks to see if we need to update * ampache at all */ public static function need_update() { $current_version = self::get_version(); - + if (!is_array(self::$versions)) { self::$versions = self::populate_version(); } - - /* + + /* Go through the versions we have and see if we need to apply any updates */ @@ -146,22 +146,22 @@ class Update { * installed before allowing you to run the update. this is * to protect the integrity of the database */ - public static function plugins_installed() { + public static function plugins_installed() { /* Pull all version info */ $sql = "SELECT * FROM `update_info`"; $db_results = Dba::read($sql); - while ($results = Dba::fetch_assoc($db_results)) { + while ($results = Dba::fetch_assoc($db_results)) { /* We have only one allowed string */ - if ($results['key'] != 'db_version') { - return false; + if ($results['key'] != 'db_version') { + return false; } } // while update_info results - - return true; + + return true; } // plugins_installed @@ -174,159 +174,159 @@ class Update { /* Define the array */ $version = array(); - - $update_string = '- Moved back to ID for user tracking internally.<br />' . - '- Added date to user_vote to allow sorting by vote time.<br />' . - '- Added Random Method and Object Count Preferences.<br />' . - '- Removed some unused tables/fields.<br />' . + + $update_string = '- Moved back to ID for user tracking internally.<br />' . + '- Added date to user_vote to allow sorting by vote time.<br />' . + '- Added Random Method and Object Count Preferences.<br />' . + '- Removed some unused tables/fields.<br />' . '- Added Label, Catalog # and Language to Extended Song Data Table.'; $version[] = array('version' => '340001','description' => $update_string); $update_string = '- Added Offset Limit to Preferences and removed from user table.'; - $version[] = array('version' => '340002','description' => $update_string); + $version[] = array('version' => '340002','description' => $update_string); - $update_string = '- Moved Art from the Album table into album_data to improve performance.<br />' . - '- Made some minor changes to song table to reduce size of each row.<br />' . - '- Moved song_ext_data to song_data to match album_data pattern.<br />' . - '- Added Playlist Method and Rate Limit Preferences.<br />' . - '- Renamed preferences and ratings to preference and rating to fit table pattern.<br />' . + $update_string = '- Moved Art from the Album table into album_data to improve performance.<br />' . + '- Made some minor changes to song table to reduce size of each row.<br />' . + '- Moved song_ext_data to song_data to match album_data pattern.<br />' . + '- Added Playlist Method and Rate Limit Preferences.<br />' . + '- Renamed preferences and ratings to preference and rating to fit table pattern.<br />' . '- Fixed rating table, renamed user_rating to rating and switched 00 for -1.<br />'; - $version[] = array('version' => '340003','description' => $update_string); + $version[] = array('version' => '340003','description' => $update_string); - $update_string = '- Alter the Session.id to be VARCHAR(64) to account for all potential configs.<br />' . - '- Added new user_shout table for Sticky objects / shoutbox.<br />' . - '- Added new playlist preferences, and new preference catagory of playlist.<br />' . - '- Tweaked Now Playing Table.<br />'; + $update_string = '- Alter the Session.id to be VARCHAR(64) to account for all potential configs.<br />' . + '- Added new user_shout table for Sticky objects / shoutbox.<br />' . + '- Added new playlist preferences, and new preference catagory of playlist.<br />' . + '- Tweaked Now Playing Table.<br />'; - $version[] = array('version' => '340004','description' => $update_string); + $version[] = array('version' => '340004','description' => $update_string); - $update_string = '- Altered Ratings table so the fields make more sense.<br />' . - '- Moved Random Method to Playlist catagory.<br />' . - '- Added Transcode Method to Streaming.<br />'; + $update_string = '- Altered Ratings table so the fields make more sense.<br />' . + '- Moved Random Method to Playlist catagory.<br />' . + '- Added Transcode Method to Streaming.<br />'; - $version[] = array('version' => '340005','description' => $update_string); + $version[] = array('version' => '340005','description' => $update_string); - $update_string = '- Remove Random Method config option, ended up being useless.<br />' . + $update_string = '- Remove Random Method config option, ended up being useless.<br />' . '- Check and change album_data.art to a MEDIUMBLOB if needed.<br />'; - $version[] = array('version' => '340006','description' => $update_string); + $version[] = array('version' => '340006','description' => $update_string); - $update_string = '- Added new session_stream table for sessions tied directly to stream instances.<br />' . - '- Altered the session table, making value a LONGTEXT.<br />'; + $update_string = '- Added new session_stream table for sessions tied directly to stream instances.<br />' . + '- Altered the session table, making value a LONGTEXT.<br />'; - $version[] = array('version' => '340007','description' => $update_string); + $version[] = array('version' => '340007','description' => $update_string); - $update_string = '- Modified Playlist_Data table to account for multiple object types.<br />' . - '- Verified previous updates, adjusting as needed.<br />' . - '- Dropped Allow Downsampling pref, configured in cfg file.<br />' . + $update_string = '- Modified Playlist_Data table to account for multiple object types.<br />' . + '- Verified previous updates, adjusting as needed.<br />' . + '- Dropped Allow Downsampling pref, configured in cfg file.<br />' . '- Renamed Downsample Rate --> Transcode Rate to reflect new terminiology.<br />'; - $version[] = array('version' => '340008','description' => $update_string); + $version[] = array('version' => '340008','description' => $update_string); - $update_string = '- Added disk to Album table.<br />' . - '- Added artist_data for artist images and bios.<br />' . + $update_string = '- Added disk to Album table.<br />' . + '- Added artist_data for artist images and bios.<br />' . '- Added DNS to access list to allow for dns based ACLs.<br />'; - $version[] = array('version' => '340009','description' => $update_string); + $version[] = array('version' => '340009','description' => $update_string); + + $update_string = '- Removed Playlist Add preference.<br />' . + '- Moved Localplay* preferences to options.<br />' . + '- Tweaked Default Playlist Method.<br />' . + '- Change wording on Localplay preferences.<br />'; + $version[] = array('version' => '340010','description'=>$update_string); - $update_string = '- Removed Playlist Add preference.<br />' . - '- Moved Localplay* preferences to options.<br />' . - '- Tweaked Default Playlist Method.<br />' . - '- Change wording on Localplay preferences.<br />'; - $version[] = array('version' => '340010','description'=>$update_string); + $update_string = '- Added api session table, will eventually recombine with others.<br />'; - $update_string = '- Added api session table, will eventually recombine with others.<br />'; + $version[] = array('version' => '340011','description'=>$update_string); - $version[] = array('version' => '340011','description'=>$update_string); + $update_string = '- Added Democratic Table for new democratic play features.<br />' . + '- Added Add Path to Catalog to improve add speeds on large catalogs.<br />'; - $update_string = '- Added Democratic Table for new democratic play features.<br />' . - '- Added Add Path to Catalog to improve add speeds on large catalogs.<br />'; - - $version[] = array('version' => '340012','description'=>$update_string); + $version[] = array('version' => '340012','description'=>$update_string); - $update_string = '- Removed Unused Preferences.<br />' . - '- Changed Localplay Config to Localplay Access.<br />' . + $update_string = '- Removed Unused Preferences.<br />' . + '- Changed Localplay Config to Localplay Access.<br />' . '- Changed all XML-RPC acls to RPC to reflect inclusion of new API.<br />'; - + $version[] = array('version' => '340013','description'=>$update_string); - $update_string = '- Removed API Session table, been a nice run....<br />' . + $update_string = '- Removed API Session table, been a nice run....<br />' . '- Alterted Session table to handle API sessions correctly.<br />'; - $version[] = array('version' => '340014','description'=>$update_string); + $version[] = array('version' => '340014','description'=>$update_string); + + $update_string = '- Alter Playlist Date Field to fix issues with some MySQL configurations.<br />' . + '- Alter Rating type to correct AVG issue on searching.<br />'; - $update_string = '- Alter Playlist Date Field to fix issues with some MySQL configurations.<br />' . - '- Alter Rating type to correct AVG issue on searching.<br />'; - - $version[] = array('version' => '340015','description'=>$update_string); + $version[] = array('version' => '340015','description'=>$update_string); - $update_string = '- Alter the Democratic Playlist table, adding base_playlist.<br />' . - '- Alter tmp_playlist to account for Democratic changes.<br />' . - '- Cleared Existing Democratic playlists due to changes.<br />'; + $update_string = '- Alter the Democratic Playlist table, adding base_playlist.<br />' . + '- Alter tmp_playlist to account for Democratic changes.<br />' . + '- Cleared Existing Democratic playlists due to changes.<br />'; - $version[] = array('version' => '340016','description'=>$update_string); + $version[] = array('version' => '340016','description'=>$update_string); $update_string = '- Fix Tables for new Democratic Play methodology.<br />'; - $version[] = array('version' => '340017','description'=>$update_string); + $version[] = array('version' => '340017','description'=>$update_string); - $update_string = '- Attempt to detect and correct charset issues between filesystem and database.<br />'; + $update_string = '- Attempt to detect and correct charset issues between filesystem and database.<br />'; - $version[] = array('version' => '340018','description'=>$update_string); + $version[] = array('version' => '340018','description'=>$update_string); - $update_string = '- Modify the Tag tables so that they actually work.<br />' . - '- Alter the Prefix fields to allow for more prefixs.<br />'; - - $version[] = array('version' => '350001','description'=>$update_string); + $update_string = '- Modify the Tag tables so that they actually work.<br />' . + '- Alter the Prefix fields to allow for more prefixs.<br />'; - $update_string = '- Remove Genre Field from song table.<br />' . - '- Add user_catalog table for tracking user<-->catalog mappings.<br />' . - '- Add tmp_browse to handle caching rather then session table.<br />'; + $version[] = array('version' => '350001','description'=>$update_string); - $version[] = array('version' => '350002','description'=>$update_string); + $update_string = '- Remove Genre Field from song table.<br />' . + '- Add user_catalog table for tracking user<-->catalog mappings.<br />' . + '- Add tmp_browse to handle caching rather then session table.<br />'; - $update_string = '- Modify Tag tables.<br />' . - '- Remove useless config preferences.<br />'; + $version[] = array('version' => '350002','description'=>$update_string); - $version[] = array('version'=> '350003','description'=>$update_string); + $update_string = '- Modify Tag tables.<br />' . + '- Remove useless config preferences.<br />'; - $update_string = '- Modify ACL table to enable IPv6 ACL support<br />' . - '- Modify Session Tables to store IPv6 addresses if provided<br />' . - '- Modify IP History table to store IPv6 addresses and User Agent<br />'; + $version[] = array('version'=> '350003','description'=>$update_string); - $version[] = array('version'=>'350004','description'=>$update_string); + $update_string = '- Modify ACL table to enable IPv6 ACL support<br />' . + '- Modify Session Tables to store IPv6 addresses if provided<br />' . + '- Modify IP History table to store IPv6 addresses and User Agent<br />'; - $update_string = "- Add table for Video files<br />"; + $version[] = array('version'=>'350004','description'=>$update_string); - $version[] = array('version'=>'350005','description'=>$update_string); + $update_string = "- Add table for Video files<br />"; + + $version[] = array('version'=>'350005','description'=>$update_string); $update_string = "- Add data for Lyrics<br />"; $version[] = array('version'=>'350006','description'=>$update_string); - $update_string = '- Remove unused fields from catalog, playlist, playlist_data<br />' . - '- Add tables for dynamic playlists<br />' . - '- Add last_clean to catalog table<br />' . - '- Add track to tmp_playlist_data<br />' . - '- Increase Thumbnail blob size<br />'; + $update_string = '- Remove unused fields from catalog, playlist, playlist_data<br />' . + '- Add tables for dynamic playlists<br />' . + '- Add last_clean to catalog table<br />' . + '- Add track to tmp_playlist_data<br />' . + '- Increase Thumbnail blob size<br />'; - $version[] = array('version'=>'350007','description'=>$update_string); + $version[] = array('version'=>'350007','description'=>$update_string); - $update_string = '- Modify Now Playing table to handle Videos<br />' . - '- Modify tmp_browse to make it easier to prune<br />' . - '- Add missing indexes to the _data tables<br />' . - '- Drop unused song.hash<br />' . - '- Add addition_time and update_time to video table<br />'; + $update_string = '- Modify Now Playing table to handle Videos<br />' . + '- Modify tmp_browse to make it easier to prune<br />' . + '- Add missing indexes to the _data tables<br />' . + '- Drop unused song.hash<br />' . + '- Add addition_time and update_time to video table<br />'; - $version[] = array('version'=>'350008','description'=>$update_string); + $version[] = array('version'=>'350008','description'=>$update_string); - $update_string = '- Add MBID (MusicBrainz ID) fields<br />' . - '- Remove useless preferences<br />'; + $update_string = '- Add MBID (MusicBrainz ID) fields<br />' . + '- Remove useless preferences<br />'; - $version[] = array('version'=>'360001','description'=>$update_string); + $version[] = array('version'=>'360001','description'=>$update_string); return $version; @@ -344,18 +344,18 @@ class Update { $current_version = self::get_version(); if (!is_array(self::$versions)) { self::$versions = self::populate_version(); - } + } echo "<ul>\n"; foreach (self::$versions as $version) { - + if ($version['version'] > $current_version) { $updated = true; echo "<li><b>Version: " . self::format_version($version['version']) . "</b><br />"; - echo $version['description'] . "<br /></li>\n"; + echo $version['description'] . "<br /></li>\n"; } // if newer - + } // foreach versions echo "</ul>\n"; @@ -366,68 +366,68 @@ class Update { /** * run_update * This function actually updates the db. - * it goes through versions and finds the ones + * it goes through versions and finds the ones * that need to be run. Checking to make sure * the function exists first. */ public static function run_update() { - + /* Nuke All Active session before we start the mojo */ $sql = "TRUNCATE session"; $db_results = Dba::write($sql); - + // Prevent the script from timing out, which could be bad set_time_limit(0); - /* Verify that there are no plugins installed + /* Verify that there are no plugins installed //FIXME: provide a link to remove all plugins, otherwise this could turn into a catch 22 - if (!$self::plugins_installed()) { + if (!$self::plugins_installed()) { $GLOBALS['error']->add_error('general',_('Plugins detected, please remove all Plugins and try again')); - return false; + return false; } */ $methods = array(); - + $current_version = self::get_version(); // Run a check to make sure that they don't try to upgrade from a version that - // won't work. - if ($current_version < '340001') { - echo "<p align=\"center\">Database version too old, please upgrade to <a href=\"http://ampache.org/downloads/ampache-3.3.3.5.tar.gz\">Ampache-3.3.3.5</a> first</p>"; - return false; - } - - + // won't work. + if ($current_version < '340001') { + echo "<p align=\"center\">Database version too old, please upgrade to <a href=\"http://ampache.org/downloads/ampache-3.3.3.5.tar.gz\">Ampache-3.3.3.5</a> first</p>"; + return false; + } + + $methods = get_class_methods('Update'); - - if (!is_array((self::$versions))) { + + if (!is_array((self::$versions))) { self::$versions = self::populate_version(); } - foreach (self::$versions as $version) { + foreach (self::$versions as $version) { // If it's newer than our current version - // let's see if a function exists and run the + // let's see if a function exists and run the // bugger - if ($version['version'] > $current_version) { + if ($version['version'] > $current_version) { $update_function = "update_" . $version['version']; if (in_array($update_function,$methods)) { - $success = call_user_func(array('Update',$update_function)); + $success = call_user_func(array('Update',$update_function)); // If the update fails drop out - if (!$success) { - Error::display('update'); - return false; - } + if (!$success) { + Error::display('update'); + return false; + } } - } - + } + } // end foreach version // Once we've run all of the updates let's re-sync the character set as the user // can change this between updates and cause mis-matches on any new tables - Dba::reset_db_charset(); + Dba::reset_db_charset(); } // run_update @@ -439,248 +439,248 @@ class Update { private static function set_version($key,$value) { $sql = "UPDATE update_info SET value='$value' WHERE `key`='$key'"; - $db_results = Dba::write($sql); + $db_results = Dba::write($sql); } //set_version /** * update_340001 - * This update moves back to the ID for user UID and + * This update moves back to the ID for user UID and * adds date to the user_vote so that it can be sorted * correctly */ - private function update_340001() { + private function update_340001() { // Build the User -> ID map using the username as the key - $sql = "SELECT `id`,`username` FROM `user`"; + $sql = "SELECT `id`,`username` FROM `user`"; $db_results = Dba::read($sql); - $user_array = array(); + $user_array = array(); - while ($r = mysql_fetch_assoc($db_results)) { + while ($r = mysql_fetch_assoc($db_results)) { $username = $r['username']; - $user_array[$username] = Dba::escape($r['id']); + $user_array[$username] = Dba::escape($r['id']); } // end while - // Alter the user table so that you can't have an ID beyond the + // Alter the user table so that you can't have an ID beyond the // range of the other tables which have to allow for -1 $sql = "ALTER TABLE `user` CHANGE `id` `id` INT ( 11 ) NOT NULL AUTO_INCREMENT"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Now pull the access list users, alter table and then re-insert - $sql = "SELECT DISTINCT(`user`) FROM `access_list`"; - $db_results = Dba::query($sql); + $sql = "SELECT DISTINCT(`user`) FROM `access_list`"; + $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { // Build the new SQL $username = $r['user']; - $user_id = $user_array[$username]; - $username = Dba::escape($username); + $user_id = $user_array[$username]; + $username = Dba::escape($username); - $sql = "UPDATE `access_list` SET `user`='$user_id' WHERE `user`='$username'"; - $update_results = Dba::query($sql); + $sql = "UPDATE `access_list` SET `user`='$user_id' WHERE `user`='$username'"; + $update_results = Dba::write($sql); } // end while access_list // Alter the table $sql = "ALTER TABLE `access_list` CHANGE `user` `user` INT ( 11 ) NOT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Now pull flagged users, update and alter $sql = "SELECT DISTINCT(`user`) FROM `flagged`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { - $username = $r['user']; + while ($r = Dba::fetch_assoc($db_results)) { + $username = $r['user']; $user_id = $user_array[$username]; - $username = Dba::escape($username); + $username = Dba::escape($username); $sql = "UPDATE `flagged` SET `user`='$user_id' WHERE `user`='$username'"; - $update_results = Dba::query($sql); + $update_results = Dba::write($sql); - } // end while + } // end while // Alter the table $sql = "ALTER TABLE `flagged` CHANGE `user` `user` INT ( 11 ) NOT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Now fix up the ip history $sql = "SELECT DISTINCT(`user`) FROM `ip_history`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $username = $r['user']; $user_id = $user_array[$username]; - $username = Dba::escape($username); + $username = Dba::escape($username); $sql = "UPDATE `ip_history` SET `user`='$user_id' WHERE `user`='$username'"; - $update_results = Dba::query($sql); + $update_results = Dba::write($sql); } // end while // Alter the table $sql = "ALTER TABLE `ip_history` CHANGE `user` `user` INT ( 11 ) NOT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Now fix now playing $sql = "SELECT DISTINCT(`user`) FROM `now_playing`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $username = $r['user']; $user_id = $user_array[$username]; - $username = Dba::escape($username); + $username = Dba::escape($username); $sql = "UPDATE `now_playing` SET `user`='$user_id' WHERE `user`='$username'"; - $update_results = Dba::query($sql); + $update_results = Dba::write($sql); } // end while // Alter the table $sql = "ALTER TABLE `now_playing` CHANGE `user` `user` INT ( 11 ) NOT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Now fix the playlist table $sql = "SELECT DISTINCT(`user`) FROM `playlist`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $username = $r['user']; $user_id = $user_array[$username]; - $username = Dba::escape($username); + $username = Dba::escape($username); $sql = "UPDATE `playlist` SET `user`='$user_id' WHERE `user`='$username'"; - $update_results = Dba::query($sql); + $update_results = Dba::write($sql); } // end while // Alter the table $sql = "ALTER TABLE `playlist` CHANGE `user` `user` INT ( 11 ) NOT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Drop unused table $sql = "DROP TABLE `playlist_permission`"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Now fix the ratings table $sql = "SELECT DISTINCT(`user`) FROM `ratings`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $username = $r['user']; $user_id = $user_array[$username]; - $username = Dba::escape($username); + $username = Dba::escape($username); $sql = "UPDATE `ratings` SET `user`='$user_id' WHERE `user`='$username'"; - $update_results = Dba::query($sql); + $update_results = Dba::write($sql); } // end while $sql = "ALTER TABLE `ratings` CHANGE `user` `user` INT ( 11 ) NOT NULL"; - $db_results = Dba::query($sql); - - // Now work on the tag_map - $sql = "ALTER TABLE `tag_map` CHANGE `user_id` `user` INT ( 11 ) NOT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); + + // Now work on the tag_map + $sql = "ALTER TABLE `tag_map` CHANGE `user_id` `user` INT ( 11 ) NOT NULL"; + $db_results = Dba::write($sql); // Now fix user preferences $sql = "SELECT DISTINCT(`user`) FROM `user_preference`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $username = $r['user']; $user_id = $user_array[$username]; - $username = Dba::escape($username); + $username = Dba::escape($username); - $sql = "UPDATE `user_preference` SET `user`='$user_id' WHERE `user`='$username'"; - $update_results = Dba::query($sql); + $sql = "UPDATE `user_preference` SET `user`='$user_id' WHERE `user`='$username'"; + $update_results = Dba::write($sql); } // end while // Alter the table $sql = "ALTER TABLE `user_preference` CHANGE `user` `user` INT ( 11 ) NOT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Add a date to the user_vote $sql = "ALTER TABLE `user_vote` ADD `date` INT( 11 ) UNSIGNED NOT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Add the index for said field $sql = "ALTER TABLE `user_vote` ADD INDEX(`date`)"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Add the thumb fields to album $sql = "ALTER TABLE `album` ADD `thumb` TINYBLOB NULL ,ADD `thumb_mime` VARCHAR( 128 ) NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Now add in the min_object_count preference and the random_method - $sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . + $sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . "VALUES('min_object_count','1','Min Element Count','5','integer','interface')"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); - $sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . - "VALUES('random_method','default','Random Method','5','string','interface')"; - $db_results = Dba::query($sql); + $sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . + "VALUES('random_method','default','Random Method','5','string','interface')"; + $db_results = Dba::write($sql); // Delete old preference - $sql = "DELETE FROM `preferences` WHERE `name`='min_album_size'"; - $db_results = Dba::query($sql); + $sql = "DELETE FROM `preferences` WHERE `name`='min_album_size'"; + $db_results = Dba::write($sql); // Make Hash a non-required field and smaller $sql = "ALTER TABLE `song` CHANGE `hash` `hash` VARCHAR ( 64 ) NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Make user access an int, nothing else $sql = "UPDATE `user` SET `access`='100' WHERE `access`='admin'"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); $sql = "UPDATE `user` SET `access`='25' WHERE `access`='user'"; - $db_results = Dba::query($sql); - + $db_results = Dba::write($sql); + $sql = "UPDATE `user` SET `access`='5' WHERE `access`='guest'"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Alter the table $sql = "ALTER TABLE `user` CHANGE `access` `access` TINYINT ( 4 ) UNSIGNED NOT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); // Add in Label and Catalog # and language $sql = "ALTER TABLE `song_ext_data` ADD `label` VARCHAR ( 128 ) NULL, ADD `catalog_number` VARCHAR ( 128 ) NULL, ADD `language` VARCHAR ( 128 ) NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); /* Fix every users preferences */ $sql = "SELECT `id` FROM `user`"; - $db_results = Dba::query($sql); - + $db_results = Dba::read($sql); + User::fix_preferences('-1'); - + while ($r = Dba::fetch_assoc($db_results)) { User::fix_preferences($r['id']); } // while results self::set_version('db_version','340001'); - return true; + return true; } //update_340001 /** * update_340002 - * This update tweaks the preferences a little more and make sure that the + * This update tweaks the preferences a little more and make sure that the * min_object_count has a rational value */ - private function update_340002() { + private function update_340002() { /* Add the offset_limit preference and remove it from the user table */ - $sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . + $sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . "VALUES ('offset_limit','50','Offset Limit','5','integer','interface')"; - $db_results = Dba::query($sql); - - self::set_version('db_version','340002'); + $db_results = Dba::write($sql); - return true; + self::set_version('db_version','340002'); + + return true; } // update_340002 @@ -691,156 +691,156 @@ class Update { * minor changes to the song table in an attempt to reduce * the size of each row */ - public static function update_340003() { + public static function update_340003() { $sql = "ALTER TABLE `song` CHANGE `mode` `mode` ENUM( 'abr', 'vbr', 'cbr' ) NULL DEFAULT 'cbr'"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); $sql = "ALTER TABLE `song` CHANGE `time` `time` SMALLINT( 5 ) UNSIGNED NOT NULL DEFAULT '0'"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); $sql = "ALTER TABLE `song` CHANGE `rate` `rate` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT '0'"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); $sql = "ALTER TABLE `song` CHANGE `bitrate` `bitrate` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT '0'"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `song` CHANGE `track` `track` SMALLINT( 5 ) UNSIGNED NULL DEFAULT NULL "; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `song` CHANGE `track` `track` SMALLINT( 5 ) UNSIGNED NULL DEFAULT NULL "; + $db_results = Dba::write($sql); $sql = "ALTER TABLE `user` CHANGE `disabled` `disabled` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0'"; - $db_results = Dba::query($sql); - - $sql = "CREATE TABLE `album_data` (" . - "`album_id` INT( 11 ) UNSIGNED NOT NULL , " . - "`art` MEDIUMBLOB NULL , " . - "`art_mime` VARCHAR( 64 ) NULL , " . - "`thumb` BLOB NULL , " . - "`thumb_mime` VARCHAR( 64 ) NULL , " . - "UNIQUE ( `album_id` )" . + $db_results = Dba::write($sql); + + $sql = "CREATE TABLE `album_data` (" . + "`album_id` INT( 11 ) UNSIGNED NOT NULL , " . + "`art` MEDIUMBLOB NULL , " . + "`art_mime` VARCHAR( 64 ) NULL , " . + "`thumb` BLOB NULL , " . + "`thumb_mime` VARCHAR( 64 ) NULL , " . + "UNIQUE ( `album_id` )" . ") ENGINE = MYISAM"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); /* Foreach the Albums and move the data into the new album_data table */ - $sql = "SELECT * FROM album"; - $db_results = Dba::query($sql); + $sql = "SELECT * FROM album"; + $db_results = Dba::write($sql); - while ($data = Dba::fetch_assoc($db_results)) { + while ($data = Dba::fetch_assoc($db_results)) { $id = $data['id']; - $art = Dba::escape($data['art']); - $art_mime = Dba::escape($data['art_mime']); - $thumb = Dba::escape($data['thumb']); - $thumb_mime = Dba::escape($data['thumb_mime']); - $sql = "INSERT INTO `album_data` (`album_id`,`art`,`art_mime`,`thumb`,`thumb_mime`)" . - " VALUES ('$id','$art','$art_mime','$thumb','$thumb_mime')"; - $insert_results = Dba::query($sql); + $art = Dba::escape($data['art']); + $art_mime = Dba::escape($data['art_mime']); + $thumb = Dba::escape($data['thumb']); + $thumb_mime = Dba::escape($data['thumb_mime']); + $sql = "INSERT INTO `album_data` (`album_id`,`art`,`art_mime`,`thumb`,`thumb_mime`)" . + " VALUES ('$id','$art','$art_mime','$thumb','$thumb_mime')"; + $insert_results = Dba::write($sql); } // end while - $sql = "RENAME TABLE `song_ext_data` TO `song_data`"; - $db_results = Dba::query($sql); + $sql = "RENAME TABLE `song_ext_data` TO `song_data`"; + $db_results = Dba::write($sql); - $sql = "RENAME TABLE `preferences` TO `preference`"; - $db_results = Dba::query($sql); + $sql = "RENAME TABLE `preferences` TO `preference`"; + $db_results = Dba::write($sql); - $sql = "RENAME TABLE `ratings` TO `rating`"; - $db_results = Dba::query($sql); + $sql = "RENAME TABLE `ratings` TO `rating`"; + $db_results = Dba::write($sql); // Go ahead and drop the art/thumb stuff - $sql = "ALTER TABLE `album` DROP `art`, DROP `art_mime`, DROP `thumb`, DROP `thumb_mime`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `album` DROP `art`, DROP `art_mime`, DROP `thumb`, DROP `thumb_mime`"; + $db_results = Dba::write($sql); // We need to fix the user_vote table - $sql = "ALTER TABLE `user_vote` CHANGE `user` `user` INT( 11 ) UNSIGNED NOT NULL"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `user_vote` CHANGE `user` `user` INT( 11 ) UNSIGNED NOT NULL"; + $db_results = Dba::write($sql); // Remove offset limit from the user - $sql = "ALTER TABLE `user` DROP `offset_limit`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `user` DROP `offset_limit`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `rating` CHANGE `user_rating` `rating` ENUM( '-1', '0', '1', '2', '3', '4', '5' ) NOT NULL DEFAULT '0'"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `rating` CHANGE `user_rating` `rating` ENUM( '-1', '0', '1', '2', '3', '4', '5' ) NOT NULL DEFAULT '0'"; + $db_results = Dba::write($sql); /* Add the rate_limit preference */ $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . "VALUES ('rate_limit','8192','Rate Limit','100','integer','streaming')"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); /* Add the playlist_method preference and remove it from the user table */ $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . "VALUES ('playlist_method','normal','Playlist Method','5','string','streaming')"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `update_info` ADD UNIQUE (`key`)"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `update_info` ADD UNIQUE (`key`)"; + $db_results = Dba::write($sql); $sql = "SELECT `id` FROM `user`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - User::fix_preferences('-1'); + User::fix_preferences('-1'); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { User::fix_preferences($r['id']); } - self::set_version('db_version','340003'); + self::set_version('db_version','340003'); - return true; + return true; } // update_340003 /** * update_340004 - * Update the session.id to varchar(64) to handle + * Update the session.id to varchar(64) to handle * newer configs */ - public static function update_340004() { + public static function update_340004() { /* Alter the session.id so that it's 64 */ $sql = "ALTER TABLE `session` CHANGE `id` `id` VARCHAR( 64 ) NOT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); /* Add Playlist Related Preferences */ - $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . - "VALUES ('playlist_add','append','Add Behavior','5','string','playlist')"; - $db_results = Dba::query($sql); + $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . + "VALUES ('playlist_add','append','Add Behavior','5','string','playlist')"; + $db_results = Dba::write($sql); // Switch the existing preferences over to this new catagory - $sql = "UPDATE `preference` SET `catagory`='playlist' WHERE `name`='playlist_method' " . - " OR `name`='playlist_type'"; - $db_results = Dba::query($sql); - + $sql = "UPDATE `preference` SET `catagory`='playlist' WHERE `name`='playlist_method' " . + " OR `name`='playlist_type'"; + $db_results = Dba::write($sql); + // Change the default value for playlist_method - $sql = "UPDATE `preference` SET `value`='normal' WHERE `name`='playlist_method'"; - $db_results = Dba::query($sql); - + $sql = "UPDATE `preference` SET `value`='normal' WHERE `name`='playlist_method'"; + $db_results = Dba::write($sql); + // Add in the shoutbox - $sql = "CREATE TABLE `user_shout` (`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , " . - "`user` INT( 11 ) NOT NULL , " . - "`text` TEXT NOT NULL , " . - "`date` INT( 11 ) UNSIGNED NOT NULL , " . - "`sticky` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0', " . - "`object_id` INT( 11 ) UNSIGNED NOT NULL , " . - "`object_type` VARCHAR( 32 ) NOT NULL " . - ") ENGINE = MYISAM"; - $db_results = Dba::query($sql); + $sql = "CREATE TABLE `user_shout` (`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , " . + "`user` INT( 11 ) NOT NULL , " . + "`text` TEXT NOT NULL , " . + "`date` INT( 11 ) UNSIGNED NOT NULL , " . + "`sticky` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0', " . + "`object_id` INT( 11 ) UNSIGNED NOT NULL , " . + "`object_type` VARCHAR( 32 ) NOT NULL " . + ") ENGINE = MYISAM"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `user_shout` ADD INDEX ( `sticky` )"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `user_shout` ADD INDEX ( `sticky` )"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `user_shout` ADD INDEX ( `date` )"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `user_shout` ADD INDEX ( `date` )"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `user_shout` ADD INDEX ( `user` )"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `user_shout` ADD INDEX ( `user` )"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `now_playing` CHANGE `start_time` `expire` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0'"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `now_playing` CHANGE `start_time` `expire` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0'"; + $db_results = Dba::write($sql); - $sql = "OPTIMIZE TABLE `album`"; - $db_results = Dba::query($sql); + $sql = "OPTIMIZE TABLE `album`"; + $db_results = Dba::write($sql); $sql = "SELECT `id` FROM `user`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); User::fix_preferences('-1'); @@ -849,45 +849,45 @@ class Update { } // Update our database version now that we are all done - self::set_version('db_version','340004'); + self::set_version('db_version','340004'); - return true; + return true; - } // update_340004 + } // update_340004 /** * update_340005 - * This update fixes the preferences types + * This update fixes the preferences types */ - public static function update_340005() { + public static function update_340005() { // Turn user_rating into a tinyint and call it score $sql = "ALTER TABLE `rating` CHANGE `user_rating` `score` TINYINT( 4 ) UNSIGNED NOT NULL DEFAULT '0'"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); - $sql = "UPDATE `preference` SET `catagory`='playlist' WHERE `name`='random_method'"; - $db_results = Dba::query($sql); + $sql = "UPDATE `preference` SET `catagory`='playlist' WHERE `name`='random_method'"; + $db_results = Dba::write($sql); - $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . - "VALUES ('transcode','default','Transcoding','25','string','streaming')"; - $db_results = Dba::query($sql); + $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . + "VALUES ('transcode','default','Transcoding','25','string','streaming')"; + $db_results = Dba::write($sql); /* We need to check for playlist_method here because I fubar'd an earlier update */ - $sql = "SELECT * FROM `preference` WHERE `name`='playlist_method'"; - $db_results = Dba::query($sql); - if (!Dba::num_rows($db_results)) { + $sql = "SELECT * FROM `preference` WHERE `name`='playlist_method'"; + $db_results = Dba::read($sql); + if (!Dba::num_rows($db_results)) { /* Add the playlist_method preference and remove it from the user table */ $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " . "VALUES ('playlist_method','default','Playlist Method','5','string','playlist')"; - $db_results = Dba::query($sql); - } + $db_results = Dba::write($sql); + } // Add in the object_type to the tmpplaylist data table so that we can have non-songs in there $sql = "ALTER TABLE `tmp_playlist_data` ADD `object_type` VARCHAR( 32 ) NULL AFTER `tmp_playlist`"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); $sql = "SELECT `id` FROM `user`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); User::fix_preferences('-1'); @@ -895,38 +895,38 @@ class Update { User::fix_preferences($r['id']); } - self::set_version('db_version','340005'); + self::set_version('db_version','340005'); - return true; + return true; } // update_340005 /** * update_340006 - * This just updates the size of the album_data table + * This just updates the size of the album_data table * and removes the random_method config option */ - public static function update_340006() { + public static function update_340006() { - $sql = "DESCRIBE `album_data`"; - $db_results = Dba::query($sql); + $sql = "DESCRIBE `album_data`"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - if ($row['Field'] == 'art' AND $row['Type'] == 'blob') { - $blob_needed = true; - } - } // end while - if ($blob_needed) { + while ($row = Dba::fetch_assoc($db_results)) { + if ($row['Field'] == 'art' AND $row['Type'] == 'blob') { + $blob_needed = true; + } + } // end while + if ($blob_needed) { $sql = "ALTER TABLE `album_data` CHANGE `art` `art` MEDIUMBLOB NULL DEFAULT NULL"; - $db_results = Dba::query($sql); - } + $db_results = Dba::write($sql); + } // No matter what remove that random method preference $sql = "DELETE FROM `preference` WHERE `name`='random_method'"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); $sql = "SELECT `id` FROM `user`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); User::fix_preferences('-1'); @@ -946,34 +946,34 @@ class Update { * This update converts the session.value to a longtext * and adds a session_stream table */ - public static function update_340007() { + public static function update_340007() { // Tweak the session table to handle larger session vars for my page-a-nation hotness - $sql = "ALTER TABLE `session` CHANGE `value` `value` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `session` CHANGE `value` `value` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL"; + $db_results = Dba::write($sql); // Create the new stream table where we will store stream SIDs - $sql = "CREATE TABLE `session_stream` ( " . - "`id` VARCHAR( 64 ) NOT NULL , " . - "`user` INT( 11 ) UNSIGNED NOT NULL , " . - "`agent` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL , " . - "`expire` INT( 11 ) UNSIGNED NOT NULL , " . - "`ip` INT( 11 ) UNSIGNED NULL , " . - "PRIMARY KEY ( `id` ) " . - ") ENGINE = MYISAM"; - $db_results = Dba::query($sql); + $sql = "CREATE TABLE `session_stream` ( " . + "`id` VARCHAR( 64 ) NOT NULL , " . + "`user` INT( 11 ) UNSIGNED NOT NULL , " . + "`agent` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL , " . + "`expire` INT( 11 ) UNSIGNED NOT NULL , " . + "`ip` INT( 11 ) UNSIGNED NULL , " . + "PRIMARY KEY ( `id` ) " . + ") ENGINE = MYISAM"; + $db_results = Dba::write($sql); // Change the now playing to use stream session ids for its ID - $sql = "ALTER TABLE `now_playing` CHANGE `id` `id` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `now_playing` CHANGE `id` `id` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL"; + $db_results = Dba::write($sql); // Now longer needed because of the new hotness - $sql = "ALTER TABLE `now_playing` DROP `session`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `now_playing` DROP `session`"; + $db_results = Dba::write($sql); - self::set_version('db_version','340007'); + self::set_version('db_version','340007'); - return true; + return true; } // update_340007 @@ -982,49 +982,49 @@ class Update { * This modifies the playlist table to handle the different types of objects that it needs to be able to * store, and tweaks how dynamic playlist stuff works */ - public static function update_340008() { + public static function update_340008() { - $sql = "ALTER TABLE `playlist_data` CHANGE `song` `object_id` INT( 11 ) UNSIGNED NULL DEFAULT NULL"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `playlist_data` CHANGE `song` `object_id` INT( 11 ) UNSIGNED NULL DEFAULT NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `playlist_data` CHANGE `dyn_song` `dynamic_song` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `playlist_data` CHANGE `dyn_song` `dynamic_song` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `playlist_data` ADD `object_type` VARCHAR( 32 ) NOT NULL DEFAULT 'song' AFTER `object_id`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `playlist_data` ADD `object_type` VARCHAR( 32 ) NOT NULL DEFAULT 'song' AFTER `object_id`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `playlist` ADD `genre` INT( 11 ) UNSIGNED NOT NULL AFTER `type`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `playlist` ADD `genre` INT( 11 ) UNSIGNED NOT NULL AFTER `type`"; + $db_results = Dba::write($sql); - $sql = "DELETE FROM `preference` WHERE `name`='allow_downsample_playback'"; - $db_results = Dba::query($sql); + $sql = "DELETE FROM `preference` WHERE `name`='allow_downsample_playback'"; + $db_results = Dba::write($sql); - $sql = "UPDATE `preference` SET `description`='Transcode Bitrate' WHERE `name`='sample_rate'"; - $db_results = Dba::query($sql); + $sql = "UPDATE `preference` SET `description`='Transcode Bitrate' WHERE `name`='sample_rate'"; + $db_results = Dba::write($sql); // Check for old tables and drop if found, seems like there was a glitch that caused them // not to get droped.. *shrug* - $sql = "DROP TABLE IF EXISTS `preferences`"; - $db_results = Dba::query($sql); + $sql = "DROP TABLE IF EXISTS `preferences`"; + $db_results = Dba::write($sql); - $sql = "DROP TABLE IF EXISTS `song_ext_data`"; - $db_results = Dba::query($sql); + $sql = "DROP TABLE IF EXISTS `song_ext_data`"; + $db_results = Dba::write($sql); - $sql = "DROP TABLE IF EXISTS `ratings`"; - $db_results = Dba::query($sql); + $sql = "DROP TABLE IF EXISTS `ratings`"; + $db_results = Dba::write($sql); $sql = "SELECT `id` FROM `user`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); User::fix_preferences('-1'); while ($r = Dba::fetch_assoc($db_results)) { - User::fix_preferences($r['id']); + User::fix_preferences($r['id']); } - self::set_version('db_version','340008'); + self::set_version('db_version','340008'); - return true; + return true; } // update_340008 @@ -1032,30 +1032,30 @@ class Update { * update_340009 * This modifies the song table to handle pos fields */ - public static function update_340009() { + public static function update_340009() { $sql = "ALTER TABLE `album` ADD `disk` smallint(5) UNSIGNED DEFAULT NULL"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); $sql = "ALTER TABLE `album` ADD INDEX (`disk`)"; - $db_results = Dba::query($sql); - - $sql = "ALTER TABLE `access_list` ADD `dns` VARCHAR( 255 ) NOT NULL AFTER `end`"; - $db_results = Dba::query($sql); - - $sql = "CREATE TABLE `artist_data` (" . - "`artist_id` INT( 11 ) UNSIGNED NOT NULL ," . - "`art` MEDIUMBLOB NOT NULL ," . - "`art_mime` VARCHAR( 32 ) NOT NULL ," . - "`thumb` BLOB NOT NULL ," . - "`thumb_mime` VARCHAR( 32 ) NOT NULL ," . - "`bio` TEXT NOT NULL , " . + $db_results = Dba::write($sql); + + $sql = "ALTER TABLE `access_list` ADD `dns` VARCHAR( 255 ) NOT NULL AFTER `end`"; + $db_results = Dba::write($sql); + + $sql = "CREATE TABLE `artist_data` (" . + "`artist_id` INT( 11 ) UNSIGNED NOT NULL ," . + "`art` MEDIUMBLOB NOT NULL ," . + "`art_mime` VARCHAR( 32 ) NOT NULL ," . + "`thumb` BLOB NOT NULL ," . + "`thumb_mime` VARCHAR( 32 ) NOT NULL ," . + "`bio` TEXT NOT NULL , " . "UNIQUE (`artist_id`) ) ENGINE = MYISAM"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); - self::set_version('db_version','340009'); + self::set_version('db_version','340009'); - return true; + return true; } // update_340009 @@ -1063,26 +1063,26 @@ class Update { * update_340010 * Bunch of minor tweaks to the preference table */ - public static function update_340010() { + public static function update_340010() { - $sql = "UPDATE `preference` SET `catagory`='options' WHERE `name` LIKE 'localplay_%'"; - $db_results = Dba::query($sql); + $sql = "UPDATE `preference` SET `catagory`='options' WHERE `name` LIKE 'localplay_%'"; + $db_results = Dba::write($sql); - $sql = "DELETE FROM `preference` WHERE `name`='playlist_add'"; - $db_results = Dba::query($sql); + $sql = "DELETE FROM `preference` WHERE `name`='playlist_add'"; + $db_results = Dba::write($sql); - $sql = "UPDATE `preference` SET `catagory`='plugins' WHERE (`name` LIKE 'mystrands_%' OR `name` LIKE 'lastfm_%') AND `catagory`='options'"; - $db_results = Dba::query($sql); + $sql = "UPDATE `preference` SET `catagory`='plugins' WHERE (`name` LIKE 'mystrands_%' OR `name` LIKE 'lastfm_%') AND `catagory`='options'"; + $db_results = Dba::write($sql); - $sql = "UPDATE `preference` SET `value`='default' WHERE `name`='playlist_method'"; - $db_results = Dba::query($sql); + $sql = "UPDATE `preference` SET `value`='default' WHERE `name`='playlist_method'"; + $db_results = Dba::write($sql); - $sql = "UPDATE `preference` SET `description`='Localplay Config' WHERE `name`='localplay_level'"; - $db_results = Dba::query($sql); + $sql = "UPDATE `preference` SET `description`='Localplay Config' WHERE `name`='localplay_level'"; + $db_results = Dba::write($sql); /* Fix every users preferences */ $sql = "SELECT `id` FROM `user`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); User::fix_preferences('-1'); @@ -1090,9 +1090,9 @@ class Update { User::fix_preferences($r['id']); } // while results - self::set_version('db_version','340010'); + self::set_version('db_version','340010'); - return true; + return true; } // update_340010 @@ -1102,23 +1102,23 @@ class Update { * It also adds yet another table to the db to handle the sessions for API access. Eventually * should combine all of the session tables, but I'll do that later */ - public static function update_340011() { + public static function update_340011() { // First add the new table for the new session stuff $sql = "CREATE TABLE `session_api` ( " . "`id` VARCHAR( 64 ) NOT NULL , " . "`user` INT( 11 ) UNSIGNED NOT NULL , " . "`agent` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL , " . - "`level` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0', " . + "`level` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0', " . "`expire` INT( 11 ) UNSIGNED NOT NULL , " . "`ip` INT( 11 ) UNSIGNED NULL , " . "PRIMARY KEY ( `id` ) " . ") ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); - self::set_version('db_version','340011'); + self::set_version('db_version','340011'); - return true; + return true; } // 340011 @@ -1127,29 +1127,29 @@ class Update { * This update adds in the democratic stuff, checks for some potentially screwed up indexes * and removes the timestamp from the playlist, and adds the field to the catalog for the upload dir */ - public static function update_340012() { + public static function update_340012() { - $sql = "ALTER TABLE `catalog` ADD `add_path` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER `path`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `catalog` ADD `add_path` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER `path`"; + $db_results = Dba::write($sql); - $sql = "CREATE TABLE `democratic` (`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ," . - "`name` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ," . - "`cooldown` TINYINT( 4 ) UNSIGNED NULL ," . - "`level` TINYINT( 4 ) UNSIGNED NOT NULL DEFAULT '25'," . - "`user` INT( 11 ) NOT NULL ," . - "`primary` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0'" . - ") ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; - $db_results = Dba::query($sql); + $sql = "CREATE TABLE `democratic` (`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ," . + "`name` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ," . + "`cooldown` TINYINT( 4 ) UNSIGNED NULL ," . + "`level` TINYINT( 4 ) UNSIGNED NOT NULL DEFAULT '25'," . + "`user` INT( 11 ) NOT NULL ," . + "`primary` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0'" . + ") ENGINE = MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `democratic` ADD INDEX (`primary`)"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `democratic` ADD INDEX (`primary`)"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `democratic` ADD INDEX (`level`)"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `democratic` ADD INDEX (`level`)"; + $db_results = Dba::write($sql); - self::set_version('db_version','340012'); + self::set_version('db_version','340012'); - return true; + return true; } // update_340012 @@ -1158,30 +1158,30 @@ class Update { * This update removes a whole bunch of preferences that are no longer * being used in any way, and changes the ACL XML-RPC to just RPC */ - public static function update_340013() { + public static function update_340013() { - $sql = "DELETE FROM `preference` WHERE `name`='localplay_mpd_hostname' OR `name`='localplay_mpd_port' " . - "OR `name`='direct_link' OR `name`='localplay_mpd_password' OR `name`='catalog_echo_count'"; - $db_results = Dba::query($sql); + $sql = "DELETE FROM `preference` WHERE `name`='localplay_mpd_hostname' OR `name`='localplay_mpd_port' " . + "OR `name`='direct_link' OR `name`='localplay_mpd_password' OR `name`='catalog_echo_count'"; + $db_results = Dba::write($sql); - $sql = "UPDATE `preference` SET `description`='Localplay Access' WHERE `name`='localplay_level'"; - $db_results = Dba::query($sql); + $sql = "UPDATE `preference` SET `description`='Localplay Access' WHERE `name`='localplay_level'"; + $db_results = Dba::write($sql); - $sql = "UPDATE `access_list` SET `type`='rpc' WHERE `type`='xml-rpc'"; - $db_results = Dba::query($sql); + $sql = "UPDATE `access_list` SET `type`='rpc' WHERE `type`='xml-rpc'"; + $db_results = Dba::write($sql); $sql = "SELECT `id` FROM `user`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); User::fix_preferences('-1'); while ($r = Dba::fetch_assoc($db_results)) { User::fix_preferences($r['id']); } // while we're fixing the useres stuff - - self::set_version('db_version','340013'); - return true; + self::set_version('db_version','340013'); + + return true; } // update_340013 @@ -1190,109 +1190,109 @@ class Update { * This update drops the session_api table that I added just two updates ago * it's been nice while it lasted but it's time to pack your stuff and GTFO * at the same time it updates the core session table to handle the additional - * stuff we're going to ask it to do. + * stuff we're going to ask it to do. */ - public static function update_340014() { + public static function update_340014() { - $sql = "DROP TABLE `session_api`"; - $db_results = Dba::query($sql); + $sql = "DROP TABLE `session_api`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `session` CHANGE `type` `type` ENUM ('mysql','ldap','http','api','xml-rpc') NOT NULL"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `session` CHANGE `type` `type` ENUM ('mysql','ldap','http','api','xml-rpc') NOT NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `session` ADD `agent` VARCHAR ( 255 ) NOT NULL AFTER `type`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `session` ADD `agent` VARCHAR ( 255 ) NOT NULL AFTER `type`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `session` ADD INDEX (`type`)"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `session` ADD INDEX (`type`)"; + $db_results = Dba::write($sql); - self::set_version('db_version','340014'); + self::set_version('db_version','340014'); - return true; + return true; } // update_340014 /** * update_340015 * This update tweaks the playlist table responding to complaints from usres - * who say it doesn't work, unreproduceable. This also adds an index to the + * who say it doesn't work, unreproduceable. This also adds an index to the * album art table to try to make the random album art faster - */ - public static function update_340015() { + */ + public static function update_340015() { - $sql = "ALTER TABLE `playlist` DROP `date`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `playlist` DROP `date`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `playlist` ADD `date` INT ( 11 ) UNSIGNED NOT NULL"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `playlist` ADD `date` INT ( 11 ) UNSIGNED NOT NULL"; + $db_results = Dba::write($sql); // Pull all of the rating information - $sql = "SELECT `id`,`rating` FROM `rating`"; - $db_results = Dba::query($sql); + $sql = "SELECT `id`,`rating` FROM `rating`"; + $db_results = Dba::read($sql); - $results = array(); + $results = array(); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row; - } + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row; + } - $sql = "ALTER TABLE `rating` DROP `rating`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `rating` DROP `rating`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `rating` ADD `rating` TINYINT ( 4 ) NOT NULL"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `rating` ADD `rating` TINYINT ( 4 ) NOT NULL"; + $db_results = Dba::write($sql); - foreach ($results as $row) { + foreach ($results as $row) { $rating = Dba::escape($row['rating']); - $id = Dba::escape($row['id']); - $sql = "UPDATE `rating` SET `rating`='$rating' WHERE `id`='$id'"; - $db_results = Dba::query($sql); - } + $id = Dba::escape($row['id']); + $sql = "UPDATE `rating` SET `rating`='$rating' WHERE `id`='$id'"; + $db_results = Dba::write($sql); + } - self::set_version('db_version','340015'); + self::set_version('db_version','340015'); + + return true; - return true; - } // update_340015 - /** + /** * update_340016 * This adds in the base_playlist to the democratic table... should have * done this in the previous one but I screwed up... sigh */ - public static function update_340016() { + public static function update_340016() { - $sql = "ALTER TABLE `democratic` ADD `base_playlist` INT ( 11 ) UNSIGNED NOT NULL"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `democratic` ADD `base_playlist` INT ( 11 ) UNSIGNED NOT NULL"; + $db_results = Dba::write($sql); - self::set_version('db_version','340016'); + self::set_version('db_version','340016'); - return true; + return true; } // update_340016 /** * update_340017 - * This finalizes the democratic table. + * This finalizes the democratic table. * and fixes the charset crap */ - public static function update_340017() { + public static function update_340017() { - $sql = "ALTER TABLE `democratic` ADD `base_playlist` INT( 11 ) UNSIGNED NOT NULL AFTER `name`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `democratic` ADD `base_playlist` INT( 11 ) UNSIGNED NOT NULL AFTER `name`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `tmp_playlist` DROP `base_playlist`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `tmp_playlist` DROP `base_playlist`"; + $db_results = Dba::write($sql); + + $sql = "DELETE FROM `tmp_playlist` WHERE `session`='-1'"; + $db_results = Dba::write($sql); - $sql = "DELETE FROM `tmp_playlist` WHERE `session`='-1'"; - $db_results = Dba::query($sql); + $sql = "TRUNCATE `democratic`"; + $db_results = Dba::write($sql); - $sql = "TRUNCATE `democratic`"; - $db_results = Dba::query($sql); - - self::set_version('db_version','340017'); + self::set_version('db_version','340017'); - return true; + return true; } // update_340017 @@ -1302,84 +1302,84 @@ class Update { * to make sure that if we do this it will actually will work. We will fail this update * if it would cause problems */ - public static function update_340018() { + public static function update_340018() { // MySQL translate real charset names into fancy smancy MySQL land names - switch (strtoupper(Config::get('site_charset'))) { - case 'CP1250': - case 'WINDOWS-1250': - case 'WINDOWS-1252': - $target_charset = 'cp1250'; - $target_collation = 'cp1250_general_ci'; - break; - case 'ISO-8859': - case 'ISO-8859-2': - $target_charset = 'latin2'; - $target_collation = 'latin2_general_ci'; - break; - case 'ISO-8859-1': - $target_charset = 'latin1'; - $target_charset = 'latin1_general_ci'; - break; - case 'EUC-KR': - $target_charset = 'euckr'; - $target_collation = 'euckr_korean_ci'; - break; - case 'CP932': - $target_charset = 'sjis'; - $target_collation = 'sjis_japanese_ci'; - break; - case 'KOI8-U': - $target_charset = 'koi8u'; - $target_collation = 'koi8u_general_ci'; - break; - case 'KOI8-R': + switch (strtoupper(Config::get('site_charset'))) { + case 'CP1250': + case 'WINDOWS-1250': + case 'WINDOWS-1252': + $target_charset = 'cp1250'; + $target_collation = 'cp1250_general_ci'; + break; + case 'ISO-8859': + case 'ISO-8859-2': + $target_charset = 'latin2'; + $target_collation = 'latin2_general_ci'; + break; + case 'ISO-8859-1': + $target_charset = 'latin1'; + $target_charset = 'latin1_general_ci'; + break; + case 'EUC-KR': + $target_charset = 'euckr'; + $target_collation = 'euckr_korean_ci'; + break; + case 'CP932': + $target_charset = 'sjis'; + $target_collation = 'sjis_japanese_ci'; + break; + case 'KOI8-U': + $target_charset = 'koi8u'; + $target_collation = 'koi8u_general_ci'; + break; + case 'KOI8-R': $target_charset = 'koi8r'; - $target_collation = 'koi8r_general_ci'; - break; - case 'ISO-8859': + $target_collation = 'koi8r_general_ci'; + break; + case 'ISO-8859': $target_charset = 'latin2'; - $target_collation = 'latin2_general_ci'; - break; - default; + $target_collation = 'latin2_general_ci'; + break; + default; case 'UTF-8': - $target_charset = 'utf8'; - $target_collation = 'utf8_unicode_ci'; - break; + $target_charset = 'utf8'; + $target_collation = 'utf8_unicode_ci'; + break; } // end mysql charset translation // Alter the charset for the entire database - $sql = "ALTER DATABASE `" . Config::get('database_name') . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; - $db_results = Dba::query($sql); - - $sql = "SHOW TABLES"; - $db_results = Dba::query($sql); + $sql = "ALTER DATABASE `" . Config::get('database_name') . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; + $db_results = Dba::write($sql); + + $sql = "SHOW TABLES"; + $db_results = Dba::read($sql); // Go through the tables! - while ($row = Dba::fetch_row($db_results)) { - $sql = "DESCRIBE `" . $row['0'] . "`"; - $describe_results = Dba::query($sql); + while ($row = Dba::fetch_row($db_results)) { + $sql = "DESCRIBE `" . $row['0'] . "`"; + $describe_results = Dba::read($sql); // Change the tables default charset and colliation - $sql = "ALTER TABLE `" . $row['0'] . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; - $alter_table = Dba::query($sql); + $sql = "ALTER TABLE `" . $row['0'] . "` DEFAULT CHARACTER SET $target_charset COLLATE $target_collation"; + $alter_table = Dba::write($sql); // Itterate through the columns of the table - while ($table = Dba::fetch_assoc($describe_results)) { - if (strstr($table['Type'],'varchar') OR strstr($table['Type'],'enum') OR strstr($table['Table'],'text')) { + while ($table = Dba::fetch_assoc($describe_results)) { + if (strstr($table['Type'],'varchar') OR strstr($table['Type'],'enum') OR strstr($table['Table'],'text')) { $sql = "ALTER TABLE `" . $row['0'] . "` MODIFY `" . $table['Field'] . "` " . $table['Type'] . " CHARACTER SET " . $target_charset; - $charset_results = Dba::query($sql); - if (!$charset_results) { - debug_event('CHARSET','Unable to update the charset of ' . $table['Field'] . '.' . $table['Type'] . ' to ' . $target_charset,'3'); + $charset_results = Dba::write($sql); + if (!$charset_results) { + debug_event('CHARSET','Unable to update the charset of ' . $table['Field'] . '.' . $table['Type'] . ' to ' . $target_charset,'3'); } // if it fails - } // if its a varchar + } // if its a varchar } // end columns } // end tables - - self::set_version('db_version','340018'); - return true; + self::set_version('db_version','340018'); + + return true; } // update_340018 @@ -1388,26 +1388,26 @@ class Update { * This updates modifies the tag tables per codeunde1load's specs from his tag patch * it also adjusts the prefix fields so that we can use more prefixes */ - public static function update_350001() { + public static function update_350001() { + + $sql = "ALTER TABLE `tag_map` ADD `tag_id` INT ( 11 ) UNSIGNED NOT NULL AFTER `id`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `tag_map` ADD `tag_id` INT ( 11 ) UNSIGNED NOT NULL AFTER `id`"; - $db_results = Dba::query($sql); + $sql = "RENAME TABLE `tags` TO `tag`"; + $db_results = Dba::write($sql); - $sql = "RENAME TABLE `tags` TO `tag`"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `tag` CHANGE `map_id` `id` INT ( 11 ) UNSIGNED NOT NULL auto_increment"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `tag` CHANGE `map_id` `id` INT ( 11 ) UNSIGNED NOT NULL auto_increment"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `album` CHANGE `prefix` `prefix` VARCHAR ( 32 ) NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `album` CHANGE `prefix` `prefix` VARCHAR ( 32 ) NULL"; - $db_results = Dba::query($sql); + $sql = "ALTER TABLE `artist` CHANGE `prefix` `prefix` VARCHAR ( 32 ) NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `artist` CHANGE `prefix` `prefix` VARCHAR ( 32 ) NULL"; - $db_results = Dba::query($sql); - - self::set_version('db_version','350001'); + self::set_version('db_version','350001'); - return true; + return true; } // update_350001 @@ -1417,28 +1417,28 @@ class Update { * rather then try to store everything in the session we split them out into one serilized array per * row, per person. A little slow this way when browsing, but faster when now browsing and more flexible */ - public static function update_350002() { + public static function update_350002() { - $sql = "CREATE TABLE `tmp_browse` (`sid` varchar(128) collate utf8_unicode_ci NOT NULL,`data` longtext collate utf8_unicode_ci NOT NULL," . - " UNIQUE KEY `sid` (`sid`)) ENGINE=MyISAM"; - $db_results = Dba::write($sql); + $sql = "CREATE TABLE `tmp_browse` (`sid` varchar(128) collate utf8_unicode_ci NOT NULL,`data` longtext collate utf8_unicode_ci NOT NULL," . + " UNIQUE KEY `sid` (`sid`)) ENGINE=MyISAM"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `tmp_browse` ADD INDEX ( `type` )"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `tmp_browse` ADD INDEX ( `type` )"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `song` DROP `genre`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `song` DROP `genre`"; + $db_results = Dba::write($sql); - $sql = "CREATE TABLE `user_catalog` (`user` INT( 11 ) UNSIGNED NOT NULL ,`catalog` INT( 11 ) UNSIGNED NOT NULL ,`level` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '5', " . + $sql = "CREATE TABLE `user_catalog` (`user` INT( 11 ) UNSIGNED NOT NULL ,`catalog` INT( 11 ) UNSIGNED NOT NULL ,`level` SMALLINT( 4 ) UNSIGNED NOT NULL DEFAULT '5', " . "INDEX ( `user` )) ENGINE = MYISAM"; - $db_results = Dba::write($sql); + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `user_catalog` ADD INDEX ( `catalog` )"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `user_catalog` ADD INDEX ( `catalog` )"; + $db_results = Dba::write($sql); - self::set_version('db_version','350002'); + self::set_version('db_version','350002'); - return true; + return true; } // update_350002 @@ -1447,136 +1447,136 @@ class Update { * This update tweakes the tag tables a little bit more, we're going to simplify things for the first little bit and then * then if it all works out we will worry about making it complex again. One thing at a time people... */ - public static function update_350003() { + public static function update_350003() { - $sql = "ALTER TABLE `tag` DROP `order`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `tag` DROP `order`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `tag` DROP INDEX `order`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `tag` DROP INDEX `order`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `tag` ADD UNIQUE ( `name` )"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `tag` ADD UNIQUE ( `name` )"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `tag` CHANGE `name` `name` VARCHAR( 255 )"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `tag` CHANGE `name` `name` VARCHAR( 255 )"; + $db_results = Dba::write($sql); // Make sure that they don't have any of the mystrands crap left - $sql = "DELETE FROM `preference` WHERE `name`='mystrands_user' OR `name`='mystrands_pass'"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `preference` WHERE `name`='mystrands_user' OR `name`='mystrands_pass'"; + $db_results = Dba::write($sql); - self::set_version('db_version','350003'); + self::set_version('db_version','350003'); - return true; + return true; } // update_350003 /** * update_350004 - * This update makes some changes to the ACL table so that it can support IPv6 entries as well as some other feature + * This update makes some changes to the ACL table so that it can support IPv6 entries as well as some other feature * enhancements */ - public static function update_350004() { + public static function update_350004() { - $sql = "ALTER TABLE `session` CHANGE `ip` `ip` VARBINARY( 255 ) NULL"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `session` CHANGE `ip` `ip` VARBINARY( 255 ) NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `session_stream` CHANGE `ip` `ip` VARBINARY( 255 ) NULL"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `session_stream` CHANGE `ip` `ip` VARBINARY( 255 ) NULL"; + $db_results = Dba::write($sql); // Pull all of the IP history, this could take a while - $sql = "SELECT * FROM `ip_history`"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `ip_history`"; + $db_results = Dba::read($sql); - $ip_history = array(); + $ip_history = array(); - while ($row = Dba::fetch_assoc($db_results)) { + while ($row = Dba::fetch_assoc($db_results)) { $row['ip'] = long2ip($row['ip']); - $ip_history[] = $row; - } + $ip_history[] = $row; + } // Clear the table before we make the changes - $sql = "TRUNCATE `ip_history`"; - $db_results = Dba::write($sql); + $sql = "TRUNCATE `ip_history`"; + $db_results = Dba::write($sql); + + $sql = "ALTER TABLE `ip_history` CHANGE `ip` `ip` VARBINARY( 255 ) NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `ip_history` CHANGE `ip` `ip` VARBINARY( 255 ) NULL"; - $db_results = Dba::write($sql); - - $sql = "ALTER TABLE `ip_history` ADD `agent` VARCHAR ( 255 ) NULL AFTER `date`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `ip_history` ADD `agent` VARCHAR ( 255 ) NULL AFTER `date`"; + $db_results = Dba::write($sql); // Reinsert the old rows - foreach ($ip_history as $row) { - $ip = Dba::escape(inet_pton($row['ip'])); - $sql = "INSERT INTO `ip_history` (`user`,`ip`,`date`,`agent`) " . - "VALUES ('" . $row['user'] . "','" . $ip . "','" . $row['date'] . "',NULL)"; - $db_results = Dba::write($sql); - } - + foreach ($ip_history as $row) { + $ip = Dba::escape(inet_pton($row['ip'])); + $sql = "INSERT INTO `ip_history` (`user`,`ip`,`date`,`agent`) " . + "VALUES ('" . $row['user'] . "','" . $ip . "','" . $row['date'] . "',NULL)"; + $db_results = Dba::write($sql); + } + // First pull all of their current ACL's - $sql = "SELECT * FROM `access_list`"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `access_list`"; + $db_results = Dba::read($sql); - $acl_information = array(); + $acl_information = array(); - while ($row = Dba::fetch_assoc($db_results)) { + while ($row = Dba::fetch_assoc($db_results)) { $row['start'] = long2ip($row['start']); $row['end'] = long2ip($row['end']); - $acl_information[] = $row; - } + $acl_information[] = $row; + } - $sql = "TRUNCATE `access_list`"; - $db_results = Dba::write($sql); + $sql = "TRUNCATE `access_list`"; + $db_results = Dba::write($sql); // Make the changes to the database - $sql = "ALTER TABLE `access_list` CHANGE `start` `start` VARBINARY( 255 ) NOT NULL"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `access_list` CHANGE `start` `start` VARBINARY( 255 ) NOT NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `access_list` CHANGE `end` `end` VARBINARY( 255 ) NOT NULL"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `access_list` CHANGE `end` `end` VARBINARY( 255 ) NOT NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `access_list` DROP `dns`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `access_list` DROP `dns`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `access_list` ADD `enabled` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1' AFTER `key`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `access_list` ADD `enabled` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1' AFTER `key`"; + $db_results = Dba::write($sql); // If we had nothing in there before add some base ALLOW ALL stuff as we're going - // to start defaulting Access Control to On. - if (!count($acl_information)) { - $v6_start = Dba::escape(inet_pton('::')); - $v6_end = Dba::escape(inet_pton('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')); - $v4_start = Dba::escape(inet_pton('0.0.0.0')); - $v4_end = Dba::escape(inet_pton('255.255.255.255')); - $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`,`enabled`) " . - "VALUES ('DEFAULTv4','75','$v4_start','$v4_end',NULL,'-1','interface','1')"; - $db_results = Dba::write($sql); - $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`,`enabled`) " . - "VALUES ('DEFAULTv4','75','$v4_start','$v4_end',NULL,'-1','stream','1')"; - $db_results = Dba::write($sql); - $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`,`enabled`) " . - "VALUES ('DEFAULTv6','75','$v6_start','$v6_end',NULL,'-1','interface','1')"; - $db_results = Dba::write($sql); - $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`,`enabled`) " . - "VALUES ('DEFAULTv6','75','$v6_start','$v6_end',NULL,'-1','stream','1')"; - $db_results = Dba::write($sql); + // to start defaulting Access Control to On. + if (!count($acl_information)) { + $v6_start = Dba::escape(inet_pton('::')); + $v6_end = Dba::escape(inet_pton('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')); + $v4_start = Dba::escape(inet_pton('0.0.0.0')); + $v4_end = Dba::escape(inet_pton('255.255.255.255')); + $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`,`enabled`) " . + "VALUES ('DEFAULTv4','75','$v4_start','$v4_end',NULL,'-1','interface','1')"; + $db_results = Dba::write($sql); + $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`,`enabled`) " . + "VALUES ('DEFAULTv4','75','$v4_start','$v4_end',NULL,'-1','stream','1')"; + $db_results = Dba::write($sql); + $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`,`enabled`) " . + "VALUES ('DEFAULTv6','75','$v6_start','$v6_end',NULL,'-1','interface','1')"; + $db_results = Dba::write($sql); + $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`,`enabled`) " . + "VALUES ('DEFAULTv6','75','$v6_start','$v6_end',NULL,'-1','stream','1')"; + $db_results = Dba::write($sql); } // Adding default information - foreach ($acl_information as $row) { - debug_event('Crap',print_r($row,1),1); - $row['start'] = Dba::escape(inet_pton($row['start'])); - $row['end'] = Dba::escape(inet_pton($row['end'])); - $row['key'] = Dba::escape($row['key']); - $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`,`enabled`) " . - "VALUES ('" . Dba::escape($row['name']) . "','" . intval($row['level']) . - "','" . $row['start'] . "','" . $row['end'] . "','" . $row['key'] . "','" . intval($row['user']) . "','" . - $row['type'] . "','1')"; - $db_results = Dba::write($sql); + foreach ($acl_information as $row) { + debug_event('Crap',print_r($row,1),1); + $row['start'] = Dba::escape(inet_pton($row['start'])); + $row['end'] = Dba::escape(inet_pton($row['end'])); + $row['key'] = Dba::escape($row['key']); + $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`,`enabled`) " . + "VALUES ('" . Dba::escape($row['name']) . "','" . intval($row['level']) . + "','" . $row['start'] . "','" . $row['end'] . "','" . $row['key'] . "','" . intval($row['user']) . "','" . + $row['type'] . "','1')"; + $db_results = Dba::write($sql); } // end foreach of existing rows - + self::set_version('db_version','350004'); - return true; + return true; } // update_350004 @@ -1584,45 +1584,45 @@ class Update { * update_350005 * This update adds the video table... *gasp* no you didn't <head shake> */ - public static function update_350005() { - - $sql = " CREATE TABLE `video` (" . - "`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ," . - "`file` VARCHAR( 255 ) NOT NULL , " . - "`catalog` INT( 11 ) UNSIGNED NOT NULL ," . - "`title` VARCHAR( 255 ) NOT NULL ," . - "`video_codec` VARCHAR( 255 ) NOT NULL ," . - "`audio_codec` VARCHAR( 255 ) NOT NULL ," . - "`resolution_x` MEDIUMINT UNSIGNED NOT NULL ," . - "`resolution_y` MEDIUMINT UNSIGNED NOT NULL ," . - "`time` INT( 11 ) UNSIGNED NOT NULL ," . - "`size` BIGINT UNSIGNED NOT NULL," . - "`mime` VARCHAR( 255 ) NOT NULL," . + public static function update_350005() { + + $sql = " CREATE TABLE `video` (" . + "`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ," . + "`file` VARCHAR( 255 ) NOT NULL , " . + "`catalog` INT( 11 ) UNSIGNED NOT NULL ," . + "`title` VARCHAR( 255 ) NOT NULL ," . + "`video_codec` VARCHAR( 255 ) NOT NULL ," . + "`audio_codec` VARCHAR( 255 ) NOT NULL ," . + "`resolution_x` MEDIUMINT UNSIGNED NOT NULL ," . + "`resolution_y` MEDIUMINT UNSIGNED NOT NULL ," . + "`time` INT( 11 ) UNSIGNED NOT NULL ," . + "`size` BIGINT UNSIGNED NOT NULL," . + "`mime` VARCHAR( 255 ) NOT NULL," . "`enabled` TINYINT( 1) NOT NULL DEFAULT '1'" . - ") ENGINE = MYISAM "; - $db_results = Dba::write($sql); + ") ENGINE = MYISAM "; + $db_results = Dba::write($sql); $sql = "ALTER TABLE `access_list` ADD INDEX ( `enabled` )"; - $db_results = Dba::write($sql); + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `video` ADD INDEX ( `file` )"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `video` ADD INDEX ( `file` )"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `video` ADD INDEX ( `enabled` )"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `video` ADD INDEX ( `enabled` )"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `video` ADD INDEX ( `title` )"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `video` ADD INDEX ( `title` )"; + $db_results = Dba::write($sql); self::set_version('db_version','350005'); - return true; + return true; } // update_350005 /** * update_350006 - * This update inserts the Lyrics pref table... + * This update inserts the Lyrics pref table... */ public static function update_350006() { @@ -1633,7 +1633,7 @@ class Update { $db_results = Dba::write($sql); $sql = "SELECT `id` FROM `user`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); User::fix_preferences('-1'); @@ -1650,124 +1650,124 @@ class Update { /** * update_350007 * This update adds in the random rules tables, and also increases the size of the blobs - * on the album and artist data. Also add track to tmp_playlist_data + * on the album and artist data. Also add track to tmp_playlist_data */ - public static function update_350007() { + public static function update_350007() { // We need to clear the thumbs as they will need to be re-generated - $sql = "UPDATE `album_data` SET `thumb`=NULL,`thumb_mime`=NULL"; - $db_results = Dba::write($sql); + $sql = "UPDATE `album_data` SET `thumb`=NULL,`thumb_mime`=NULL"; + $db_results = Dba::write($sql); - $sql = "UPDATE `artist_data` SET `thumb`=NULL,`thumb_mime`=NULL"; - $db_results = Dba::write($sql); + $sql = "UPDATE `artist_data` SET `thumb`=NULL,`thumb_mime`=NULL"; + $db_results = Dba::write($sql); // Change the db thumb sizes - $sql = "ALTER TABLE `album_data` CHANGE `thumb` `thumb` MEDIUMBLOB NULL"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `album_data` CHANGE `thumb` `thumb` MEDIUMBLOB NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `artist_data` CHANGE `thumb` `thumb` MEDIUMBLOB NULL"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `artist_data` CHANGE `thumb` `thumb` MEDIUMBLOB NULL"; + $db_results = Dba::write($sql); // Remove dead column - $sql = "ALTER TABLE `playlist_data` DROP `dynamic_song`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `playlist_data` DROP `dynamic_song`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `playlist` DROP `genre`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `playlist` DROP `genre`"; + $db_results = Dba::write($sql); // Add track item to tmp_playlist_data so we can order this stuff manually - $sql = "ALTER TABLE `tmp_playlist_data` ADD `track` INT ( 11 ) UNSIGNED NULL"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `tmp_playlist_data` ADD `track` INT ( 11 ) UNSIGNED NULL"; + $db_results = Dba::write($sql); - $sql = "DROP TABLE `genre`"; - $db_results = Dba::write($sql); + $sql = "DROP TABLE `genre`"; + $db_results = Dba::write($sql); // Clean up the catalog and add last_clean to it - $sql = "ALTER TABLE `catalog` ADD `last_clean` INT ( 11 ) UNSIGNED NULL AFTER `last_update`"; - $db_results = Dba::write($sql); - - $sql = "ALTER TABLE `catalog` DROP `add_path`"; - $db_results = Dba::write($sql); - - $sql = "CREATE TABLE `dynamic_playlist` (" . - "`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ," . - "`name` VARCHAR( 255 ) NOT NULL ," . - "`user` INT( 11 ) NOT NULL ," . - "`date` INT( 11 ) UNSIGNED NOT NULL ," . - "`type` VARCHAR( 128 ) NOT NULL" . + $sql = "ALTER TABLE `catalog` ADD `last_clean` INT ( 11 ) UNSIGNED NULL AFTER `last_update`"; + $db_results = Dba::write($sql); + + $sql = "ALTER TABLE `catalog` DROP `add_path`"; + $db_results = Dba::write($sql); + + $sql = "CREATE TABLE `dynamic_playlist` (" . + "`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ," . + "`name` VARCHAR( 255 ) NOT NULL ," . + "`user` INT( 11 ) NOT NULL ," . + "`date` INT( 11 ) UNSIGNED NOT NULL ," . + "`type` VARCHAR( 128 ) NOT NULL" . ") ENGINE = MYISAM "; - $db_results = Dba::write($sql); - - $sql = "CREATE TABLE `dynamic_playlist_data` (" . - "`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ," . - "`dynamic_id` INT( 11 ) UNSIGNED NOT NULL ," . - "`field` VARCHAR( 255 ) NOT NULL ," . - "`internal_operator` VARCHAR( 64 ) NOT NULL ," . - "`external_operator` VARCHAR( 64 ) NOT NULL ," . + $db_results = Dba::write($sql); + + $sql = "CREATE TABLE `dynamic_playlist_data` (" . + "`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ," . + "`dynamic_id` INT( 11 ) UNSIGNED NOT NULL ," . + "`field` VARCHAR( 255 ) NOT NULL ," . + "`internal_operator` VARCHAR( 64 ) NOT NULL ," . + "`external_operator` VARCHAR( 64 ) NOT NULL ," . "`value` VARCHAR( 255 ) NOT NULL" . - ") ENGINE = MYISAM"; - $db_results = Dba::write($sql); + ") ENGINE = MYISAM"; + $db_results = Dba::write($sql); - self::set_version('db_version','350007'); + self::set_version('db_version','350007'); - return true; + return true; } // update_350007 /** * update_350008 - * Change song_id references to be object so they are a little more general + * Change song_id references to be object so they are a little more general * add a type to now playing table so that we can handle different playing information */ - public static function update_350008() { + public static function update_350008() { - $sql = "ALTER TABLE `now_playing` CHANGE `song_id` `object_id` INT( 11 ) UNSIGNED NOT NULL"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `now_playing` CHANGE `song_id` `object_id` INT( 11 ) UNSIGNED NOT NULL"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `now_playing` ADD `object_type` VARCHAR ( 255 ) NOT NULL AFTER `object_id`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `now_playing` ADD `object_type` VARCHAR ( 255 ) NOT NULL AFTER `object_id`"; + $db_results = Dba::write($sql); + + $sql = "ALTER TABLE `now_playing` ADD INDEX ( `expire` )"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `now_playing` ADD INDEX ( `expire` )"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `video` ADD `addition_time` INT( 11 ) UNSIGNED NOT NULL AFTER `mime`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `video` ADD `addition_time` INT( 11 ) UNSIGNED NOT NULL AFTER `mime`"; - $db_results = Dba::write($sql); - - $sql = "ALTER TABLE `video` ADD `update_time` INT( 11 ) UNSIGNED NULL AFTER `addition_time`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `video` ADD `update_time` INT( 11 ) UNSIGNED NULL AFTER `addition_time`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `video` ADD INDEX (`addition_time`)"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `video` ADD INDEX (`addition_time`)"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `video` ADD INDEX (`update_time`)"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `video` ADD INDEX (`update_time`)"; + $db_results = Dba::write($sql); $sql = "ALTER TABLE `artist_data` ADD INDEX ( `art_mime` )"; $db_results = Dba::write($sql); - $sql = "ALTER TABLE `album_data` ADD INDEX ( `art_mime` )"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `album_data` ADD INDEX ( `art_mime` )"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `tmp_browse` ADD `type` VARCHAR ( 255 ) NOT NULL AFTER `sid`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `tmp_browse` ADD `type` VARCHAR ( 255 ) NOT NULL AFTER `sid`"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `tmp_browse` ADD INDEX (`type)"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `tmp_browse` ADD INDEX (`type)"; + $db_results = Dba::write($sql); - $sql = "ALTER TABLE `song` DROP `hash`"; - $db_results = Dba::write($sql); + $sql = "ALTER TABLE `song` DROP `hash`"; + $db_results = Dba::write($sql); - self::set_version('db_version','350008'); + self::set_version('db_version','350008'); } // update_350008 /** * update_360001 * This adds the MB UUIDs to the different tables as well as some additional cleanup - */ - public static function update_360001() { + */ + public static function update_360001() { + - $sql = "ALTER TABLE `album` ADD `mbid` CHAR ( 36 ) AFTER `prefix`"; $db_results = Dba::write($sql); @@ -1776,16 +1776,16 @@ class Update { $sql = "ALTER TABLE `song` ADD `mbid` CHAR ( 36 ) AFTER `track`"; $db_results = Dba::write($sql); - + // Remove any RIO related information from the database as the plugin has been removed - $sql = "DELETE FROM `update_info` WHERE `key` LIKE 'Plugin_Ri%'"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `update_info` WHERE `key` LIKE 'Plugin_Ri%'"; + $db_results = Dba::write($sql); - $sql = "DELETE FROM `preference` WHERE `name` LIKE 'rio_%'"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `preference` WHERE `name` LIKE 'rio_%'"; + $db_results = Dba::write($sql); $sql = "SELECT `id` FROM `user`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); User::fix_preferences('-1'); @@ -1793,7 +1793,7 @@ class Update { User::fix_preferences($r['id']); } // while we're fixing the useres stuff - self::set_version('db_version','360001'); + self::set_version('db_version','360001'); } // update_360001 diff --git a/lib/class/user.class.php b/lib/class/user.class.php index 766b79b4..5608e025 100644 --- a/lib/class/user.class.php +++ b/lib/class/user.class.php @@ -834,7 +834,7 @@ class User extends database_object { /* Get All Preferences for the current user */ $sql = "SELECT * FROM `user_preference` WHERE `user`='$user_id'"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); $results = array(); @@ -871,7 +871,7 @@ class User extends database_object { if ($user_id != '-1') { $sql .= " WHERE catagory !='system'"; } - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); while ($r = Dba::fetch_assoc($db_results)) { diff --git a/lib/class/vauth.class.php b/lib/class/vauth.class.php index 300426f8..8b948f25 100644 --- a/lib/class/vauth.class.php +++ b/lib/class/vauth.class.php @@ -15,10 +15,10 @@ 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. + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/** +/** * Vauth * This class handles all of the session related stuff in Ampache * it takes over for the vauth libs, and takes some stuff out of other @@ -33,7 +33,7 @@ class vauth { * Constructor * This should never be called */ - private function __construct() { + private function __construct() { // Rien a faire @@ -44,14 +44,14 @@ class vauth { * This function is for opening a new session so we just verify that we have * a database connection, nothing more is needed */ - public static function open($save_path,$session_name) { + public static function open($save_path,$session_name) { - if (!is_resource(Dba::dbh())) { - debug_event('SESSION','Error no database connection session failed','1'); - return false; - } + if (!is_resource(Dba::dbh())) { + debug_event('SESSION','Error no database connection session failed','1'); + return false; + } - return true; + return true; } // open @@ -59,9 +59,9 @@ class vauth { * close * This is run on the end of a sessoin, nothing to do here for now */ - public static function close() { + public static function close() { - return true; + return true; } // close @@ -69,16 +69,16 @@ class vauth { * read * This takes a key and then looks in the database and returns the value */ - public static function read($key) { + public static function read($key) { - $results = self::get_session_data($key); + $results = self::get_session_data($key); - if (!is_array($results)) { - debug_event('SESSION','Error unable to read session from key ' . $key . ' no data found','1'); - return false; - } + if (!is_array($results)) { + debug_event('SESSION','Error unable to read session from key ' . $key . ' no data found','1'); + return false; + } - return $results['value']; + return $results['value']; } // read @@ -86,22 +86,22 @@ class vauth { * write * This saves the sessoin information into the database */ - public static function write($key,$value) { + public static function write($key,$value) { - if (NO_SESSION_UPDATE == '1') { return true; } + if (NO_SESSION_UPDATE == '1') { return true; } - $length = Config::get('session_length'); - $value = Dba::escape($value); - $key = Dba::escape($key); + $length = Config::get('session_length'); + $value = Dba::escape($value); + $key = Dba::escape($key); // Check to see if remember me cookie is set, if so use remember length, otherwise use the session length - $expire = isset($_COOKIE[Config::get('session_name') . '_remember']) ? time() + Config::get('remember_length') : time() + Config::get('session_length'); + $expire = isset($_COOKIE[Config::get('session_name') . '_remember']) ? time() + Config::get('remember_length') : time() + Config::get('session_length'); - $sql = "UPDATE `session` SET `value`='$value', `expire`='$expire' WHERE `id`='$key'"; - $db_results = Dba::query($sql); + $sql = "UPDATE `session` SET `value`='$value', `expire`='$expire' WHERE `id`='$key'"; + $db_results = Dba::read($sql); - debug_event('SESSION','Writing to ' . $key . ' with expire ' . $expire . ' ' . Dba::error(),'6'); + debug_event('SESSION','Writing to ' . $key . ' with expire ' . $expire . ' ' . Dba::error(),'6'); - return $db_results; + return $db_results; } // write @@ -109,20 +109,20 @@ class vauth { * destroy * This removes the specified session from the database */ - public static function destroy($key) { + public static function destroy($key) { - $key = Dba::escape($key); + $key = Dba::escape($key); - if (!strlen($key)) { return false; } + if (!strlen($key)) { return false; } // Remove anything and EVERYTHING - $sql = "DELETE FROM `session` WHERE `id`='$key'"; - $db_results = Dba::query($sql); + $sql = "DELETE FROM `session` WHERE `id`='$key'"; + $db_results = Dba::write($sql); - debug_event('SESSION','Deleting Session with key:' . $key,'6'); + debug_event('SESSION','Deleting Session with key:' . $key,'6'); // Destory our cookie! - setcookie(Config::get('session_name'),'',time() - 86400); + setcookie(Config::get('session_name'),'',time() - 86400); return true; @@ -132,16 +132,16 @@ class vauth { * gc * This function is randomly called and it cleans up the poo */ - public static function gc($maxlifetime) { + public static function gc($maxlifetime) { - $sql = "DELETE FROM `session` WHERE `expire` < '" . time() . "'"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `session` WHERE `expire` < '" . time() . "'"; + $db_results = Dba::write($sql); - $sql = "DELETE FROM `tmp_browse` USING `tmp_browse` LEFT JOIN `session` ON `session`.`id`=`tmp_browse`.`sid` " . - "WHERE `session`.`id` IS NULL"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `tmp_browse` USING `tmp_browse` LEFT JOIN `session` ON `session`.`id`=`tmp_browse`.`sid` " . + "WHERE `session`.`id` IS NULL"; + $db_results = Dba::write($sql); - return true; + return true; } // gc @@ -151,13 +151,13 @@ class vauth { * This is the function used for the Ajax logouts, if no id is passed * it tries to find one from the session */ - public static function logout($key='') { + public static function logout($key='') { // If no key is passed try to find the session id - $key = $key ? $key : session_id(); - + $key = $key ? $key : session_id(); + // Nuke the cookie before all else - self::destroy($key); + self::destroy($key); // Do a quick check to see if this is an AJAX'd logout request // if so use the iframe to redirect @@ -184,7 +184,7 @@ class vauth { header ('Location: ' . Config::get('web_path') . '/login.php'); } - exit; + exit; } // logout @@ -193,20 +193,20 @@ class vauth { * This takes a key and returns the raw data from the database, nothing to * see here move along people */ - public static function get_session_data($key) { + public static function get_session_data($key) { - $key = Dba::escape($key); + $key = Dba::escape($key); - $sql = "SELECT * FROM `session` WHERE `id`='$key' AND `expire` > '" . time() . "'"; - $db_results = Dba::query($sql); + $sql = "SELECT * FROM `session` WHERE `id`='$key' AND `expire` > '" . time() . "'"; + $db_results = Dba::read($sql); - $results = Dba::fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); - if (!count($results)) { - return false; - } + if (!count($results)) { + return false; + } - return $results; + return $results; } // get_session_data @@ -217,21 +217,21 @@ class vauth { * same time as a header redirect. As such on view of a login a cookie is set with * the proper name */ - public static function create_cookie() { + public static function create_cookie() { /* Setup the cookie prefs before we throw down, this is very important */ - $cookie_life = Config::get('cookie_life'); - $cookie_path = Config::get('cookie_path'); - $cookie_domain = false; - $cookie_secure = Config::get('cookie_secure'); + $cookie_life = Config::get('cookie_life'); + $cookie_path = Config::get('cookie_path'); + $cookie_domain = false; + $cookie_secure = Config::get('cookie_secure'); - session_set_cookie_params($cookie_life,$cookie_path,$cookie_domain,$cookie_secure); + session_set_cookie_params($cookie_life,$cookie_path,$cookie_domain,$cookie_secure); - session_name(Config::get('session_name')); + session_name(Config::get('session_name')); /* Start the session */ - self::ungimp_ie(); - session_start(); + self::ungimp_ie(); + session_start(); } // create_cookie, just watch out for the cookie monster @@ -239,10 +239,10 @@ class vauth { * create_remember_cookie * This function just creates the remember me cookie, nothing special */ - public static function create_remember_cookie() { + public static function create_remember_cookie() { - $remember_length = Config::get('remember_length'); - $session_name = Config::get('session_name'); + $remember_length = Config::get('remember_length'); + $session_name = Config::get('session_name'); Config::set('cookie_life',$remember_length,'1'); setcookie($session_name . '_remember',"Rappelez-vous, rappelez-vous le 27 mars",time() + $remember_length,'/'); @@ -252,31 +252,31 @@ class vauth { /** * session_create * This is called when you want to create a new session - * it takes care of setting the initial cookie, and inserting the first chunk of + * it takes care of setting the initial cookie, and inserting the first chunk of * data, nifty ain't it! */ - public static function session_create($data) { + public static function session_create($data) { // Regenerate the session ID to prevent fixation - switch ($data['type']) { - case 'xml-rpc': - case 'api': + switch ($data['type']) { + case 'xml-rpc': + case 'api': $key = md5(uniqid(rand(), true)); - break; - case 'mysql': - default: - session_regenerate_id(); + break; + case 'mysql': + default: + session_regenerate_id(); // Before refresh we don't have the cookie so we have to use session ID - $key = session_id(); - break; - } // end switch on data type - + $key = session_id(); + break; + } // end switch on data type + $username = Dba::escape($data['username']); - $ip = $_SERVER['REMOTE_ADDR'] ? Dba::escape(inet_pton($_SERVER['REMOTE_ADDR'])) : '0'; + $ip = $_SERVER['REMOTE_ADDR'] ? Dba::escape(inet_pton($_SERVER['REMOTE_ADDR'])) : '0'; $type = Dba::escape($data['type']); $value = Dba::escape($data['value']); - $agent = Dba::escape(substr($_SERVER['HTTP_USER_AGENT'],0,254)); + $agent = Dba::escape(substr($_SERVER['HTTP_USER_AGENT'],0,254)); $expire = Dba::escape(time() + Config::get('session_length')); /* We can't have null things here people */ @@ -285,14 +285,14 @@ class vauth { /* Insert the row */ $sql = "INSERT INTO `session` (`id`,`username`,`ip`,`type`,`agent`,`value`,`expire`) " . " VALUES ('$key','$username','$ip','$type','$agent','$value','$expire')"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); if (!$db_results) { debug_event('SESSION',"Session Creation Failed with Query: $sql and " . Dba::error(),'1'); - return false; + return false; } - debug_event('SESSION','Session Created:' . $key,'6'); + debug_event('SESSION','Session Created:' . $key,'6'); return $key; @@ -303,33 +303,33 @@ class vauth { * This checks for an existing sessoin and if it's still valid then go ahead and start it and return * true */ - public static function check_session() { + public static function check_session() { - $session_name = Config::get('session_name'); + $session_name = Config::get('session_name'); // No cookie n go! if (!isset($_COOKIE[$session_name])) { return false; } // Check for a remember me - if (isset($_COOKIE[$session_name . '_remember'])) { - self::create_remember_cookie(); - } + if (isset($_COOKIE[$session_name . '_remember'])) { + self::create_remember_cookie(); + } // Setup the cookie params before we start the session this is vital session_set_cookie_params( Config::get('cookie_life'), Config::get('cookie_path'), Config::get('cookie_domain'), - Config::get('cookie_secure')); - + Config::get('cookie_secure')); + // Set name - session_name($session_name); + session_name($session_name); // Ungimp IE and go - self::ungimp_ie(); - session_start(); + self::ungimp_ie(); + session_start(); - return true; + return true; } // check_session @@ -339,51 +339,51 @@ class vauth { * exists, it also provides an array of key'd data that may be required * based on the type */ - public static function session_exists($type,$key,$data=array()) { + public static function session_exists($type,$key,$data=array()) { // Switch on the type they pass - switch ($type) { - case 'xml-rpc': - case 'api': - $key = Dba::escape($key); - $time = time(); - $sql = "SELECT * FROM `session` WHERE `id`='$key' AND `expire` > '$time' AND `type`='$type'"; - $db_results = Dba::read($sql); - - if (Dba::num_rows($db_results)) { - return true; - } - break; + switch ($type) { + case 'xml-rpc': + case 'api': + $key = Dba::escape($key); + $time = time(); + $sql = "SELECT * FROM `session` WHERE `id`='$key' AND `expire` > '$time' AND `type`='$type'"; + $db_results = Dba::read($sql); + + if (Dba::num_rows($db_results)) { + return true; + } + break; //FIXME: This should use the IN() mojo and compare against enabled auths case 'interface': - $key = Dba::escape($key); - $time = time(); - $sql = "SELECT * FROM `session` WHERE `id`='$key' AND `expire` > '$time' AND `type`!='api' AND `type`!='xml-rpc'"; - $db_results = Dba::read($sql); - - if (Dba::num_rows($db_results)) { - return true; - } - break; - case 'stream': - $key = Dba::escape($key); - $ip = Dba::escape(inet_pton($data['ip'])); - $agent = Dba::escape($data['agent']); - $sql = "SELECT * FROM `session_stream` WHERE `id`='$key' AND `expire` > '$time' AND `ip`='$ip' AND `agent`='$agent'"; - $db_results = Dba::query($sql); - - if (Dba::num_rows($db_results)) { - return true; - } - - break; - default: - return false; - break; + $key = Dba::escape($key); + $time = time(); + $sql = "SELECT * FROM `session` WHERE `id`='$key' AND `expire` > '$time' AND `type`!='api' AND `type`!='xml-rpc'"; + $db_results = Dba::read($sql); + + if (Dba::num_rows($db_results)) { + return true; + } + break; + case 'stream': + $key = Dba::escape($key); + $ip = Dba::escape(inet_pton($data['ip'])); + $agent = Dba::escape($data['agent']); + $sql = "SELECT * FROM `session_stream` WHERE `id`='$key' AND `expire` > '$time' AND `ip`='$ip' AND `agent`='$agent'"; + $db_results = Dba::read($sql); + + if (Dba::num_rows($db_results)) { + return true; + } + + break; + default: + return false; + break; } // type // Default to false - return false; + return false; } // session_exists @@ -392,17 +392,17 @@ class vauth { * This should really be extend_session but hey you gotta go with the flow * this takes a SID and extends it's expire */ - public static function session_extend($sid) { + public static function session_extend($sid) { - $sid = Dba::escape($sid); + $sid = Dba::escape($sid); $expire = isset($_COOKIE[Config::get('session_name') . '_remember']) ? time() + Config::get('remember_length') : time() + Config::get('session_length'); - $sql = "UPDATE `session` SET `expire`='$expire' WHERE `id`='$sid'"; - $db_results = Dba::query($sql); + $sql = "UPDATE `session` SET `expire`='$expire' WHERE `id`='$sid'"; + $db_results = Dba::write($sql); - debug_event('SESSION','Session:' . $sid . ' Has been Extended to ' . $expire,'6'); + debug_event('SESSION','Session:' . $sid . ' Has been Extended to ' . $expire,'6'); - return $db_results; + return $db_results; } // session_extend @@ -410,14 +410,14 @@ class vauth { * _auto_init * This function is called when the object is included, this sets up the session_save_handler */ - public static function _auto_init() { + public static function _auto_init() { - if (!function_exists('session_start')) { - header("Location:" . Config::get('web_path') . "/test.php"); - exit; - } + if (!function_exists('session_start')) { + header("Location:" . Config::get('web_path') . "/test.php"); + exit; + } - session_set_save_handler(array('vauth','open'),array('vauth','close'),array('vauth','read'),array('vauth','write'),array('vauth','destroy'),array('vauth','gc')); + session_set_save_handler(array('vauth','open'),array('vauth','close'),array('vauth','read'),array('vauth','write'),array('vauth','destroy'),array('vauth','gc')); } // auto init @@ -427,19 +427,19 @@ class vauth { * some flavor of IE. The detection used here is very conservative so feel free * to fix it. This only has to be done if we're rolling HTTPS */ - public static function ungimp_ie() { + public static function ungimp_ie() { // If no https, no ungimpage required - if ($_SERVER['HTTPS'] != 'on') { return true; } + if ($_SERVER['HTTPS'] != 'on') { return true; } // Try to detect IE - $agent = trim($_SERVER['HTTP_USER_AGENT']); + $agent = trim($_SERVER['HTTP_USER_AGENT']); - if (strstr($agent,'MSIE') || strstr($agent,'Internet Explorer/')) { - session_cache_limiter('public'); - } + if (strstr($agent,'MSIE') || strstr($agent,'Internet Explorer/')) { + session_cache_limiter('public'); + } - return true; + return true; } // ungimp_ie @@ -448,24 +448,24 @@ class vauth { * This takes a username and password and then returns true or false * based on what happens when we try to do the auth then */ - public static function authenticate($username,$password) { + public static function authenticate($username,$password) { // Foreach the auth methods - foreach (Config::get('auth_methods') as $method) { + foreach (Config::get('auth_methods') as $method) { // Build the function name and call the custom method on this class - $function_name = $method . '_auth'; - - if (!method_exists('vauth',$function_name)) { continue; } + $function_name = $method . '_auth'; + + if (!method_exists('vauth',$function_name)) { continue; } - $results = self::$function_name($username,$password); + $results = self::$function_name($username,$password); // If we achive victory return - if ($results['success']) { break; } + if ($results['success']) { break; } - } // end foreach - - return $results; + } // end foreach + + return $results; } // authenticate @@ -475,39 +475,39 @@ class vauth { * and then tries to figure out if it can use the new SHA password hash or if it needs to fall * back on the mysql method */ - private static function mysql_auth($username,$password) { + private static function mysql_auth($username,$password) { - $username = Dba::escape($username); - $password = Dba::escape($password); + $username = Dba::escape($username); + $password = Dba::escape($password); - if (!strlen($password) OR !strlen($username)) { - Error::add('general',_('Error Username or Password incorrect, please try again')); - return false; - } + if (!strlen($password) OR !strlen($username)) { + Error::add('general',_('Error Username or Password incorrect, please try again')); + return false; + } // We have to pull the password in order to figure out how to handle it *cry* - $sql = "SELECT `password` FROM `user` WHERE `username`='$username'"; - $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + $sql = "SELECT `password` FROM `user` WHERE `username`='$username'"; + $db_results = Dba::read($sql); + $row = Dba::fetch_assoc($db_results); // If it's using the old method then roll with that - if (substr($row['password'],0,1) == '*' OR strlen($row['password']) < 32) { - $response = self::vieux_mysql_auth($username,$password); - return $response; - } + if (substr($row['password'],0,1) == '*' OR strlen($row['password']) < 32) { + $response = self::vieux_mysql_auth($username,$password); + return $response; + } // Use SHA2 now... cooking with fire, SHA3 in 2012 *excitement* - $password = hash('sha256',$password); - - $sql = "SELECT `username`,`id` FROM `user` WHERE `password`='$password' AND `username`='$username'"; - $db_results = Dba::read($sql); + $password = hash('sha256',$password); + + $sql = "SELECT `username`,`id` FROM `user` WHERE `password`='$password' AND `username`='$username'"; + $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + $row = Dba::fetch_assoc($db_results); - if (!count($row)) { - Error::add('general',_('Error Username or Password incorrect, please try again')); - return false; - } + if (!count($row)) { + Error::add('general',_('Error Username or Password incorrect, please try again')); + return false; + } $row['type'] = 'mysql'; $row['success'] = true; @@ -520,17 +520,17 @@ class vauth { * vieux_mysql_auth * This is a private function, it should only be called by authenticate */ - private static function vieux_mysql_auth($username,$password) { + private static function vieux_mysql_auth($username,$password) { $password_check_sql = "PASSWORD('$password')"; // This has to still be here because lots of people use old_password in their config file - $sql = "SELECT `password` FROM `user` WHERE `username`='$username'"; - $db_results = Dba::query($sql); - $row = Dba::fetch_assoc($db_results); + $sql = "SELECT `password` FROM `user` WHERE `username`='$username'"; + $db_results = Dba::read($sql); + $row = Dba::fetch_assoc($db_results); $sql = "SELECT version()"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); $version = Dba::fetch_row($db_results); $mysql_version = substr(preg_replace("/(\d+)\.(\d+)\.(\d+).*/","$1$2$3",$version[0]),0,3); @@ -539,7 +539,7 @@ class vauth { } $sql = "SELECT `username`,`id` FROM `user` WHERE `username`='$username' AND `password`=$password_check_sql"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); $results = Dba::fetch_assoc($db_results); @@ -552,14 +552,14 @@ class vauth { $client = new User($results['id']); $current_ip = $client->is_logged_in(); if ($current_ip AND $current_ip != inet_pton($_SERVER['REMOTE_ADDR'])) { - debug_event('Login','Concurrent Login Failure, attempted to login from ' . $_SERVER['REMOTE_ADDR'] . ' and already logged in','1'); + debug_event('Login','Concurrent Login Failure, attempted to login from ' . $_SERVER['REMOTE_ADDR'] . ' and already logged in','1'); Error::add('general','User Already Logged in'); return false; } } // if prevent_multiple_logins $results['type'] = 'mysql'; - $results['password'] = 'old'; + $results['password'] = 'old'; $results['success'] = true; return $results; @@ -568,7 +568,7 @@ class vauth { /** * ldap_auth - * Step one, connect to the LDAP server and perform a search for teh username provided. + * Step one, connect to the LDAP server and perform a search for teh username provided. * If its found, attempt to bind using that username and the password provided. * Step two, figure out if they are authorized to use ampache: * TODO: need implimented still: @@ -576,7 +576,7 @@ class vauth { * * require-dn "Grant access if the DN in the directive matches the DN fetched from the LDAP directory" * * require-attribute "an attribute fetched from the LDAP directory matches the given value" */ - private static function ldap_auth($username,$password) { + private static function ldap_auth($username,$password) { $ldap_username = Config::get('ldap_username'); $ldap_password = Config::get('ldap_password'); @@ -632,14 +632,14 @@ class vauth { } // if we get something good back - } // if something was sent back + } // if something was sent back - } // if failed connect + } // if failed connect /* Default to bad news */ $results['success'] = false; $results['error'] = "LDAP login attempt failed"; - + return $results; } // ldap_auth @@ -650,7 +650,7 @@ class vauth { * This is not a very secure method of authentication * and defaults to off. */ - public static function http_auth($username) { + public static function http_auth($username) { $results['success'] = true; $results['type'] = 'http'; diff --git a/lib/class/xmlrpcserver.class.php b/lib/class/xmlrpcserver.class.php index 06c6effd..49ca7e50 100644 --- a/lib/class/xmlrpcserver.class.php +++ b/lib/class/xmlrpcserver.class.php @@ -21,9 +21,9 @@ /** * xmlRpcServer - * This class contains all the methods that the /server/xmlrpc.server.php will respond to + * This class contains all the methods that the /server/xmlrpc.server.php will respond to * to add a new method, just define a new public static function in here and it will be automagicaly - * populated to xmlrpcserver.<FUNCTION> in /server/xmlrpc.server.php + * populated to xmlrpcserver.<FUNCTION> in /server/xmlrpc.server.php */ class xmlRpcServer { @@ -34,53 +34,53 @@ class xmlRpcServer { * It requires a key be passed as the first element * //FIXME: USE TOKEN! */ - public static function get_catalogs($xmlrpc_object) { + public static function get_catalogs($xmlrpc_object) { // Pull out the key - $variable = $xmlrpc_object->getParam(0); - $key = $variable->scalarval(); + $variable = $xmlrpc_object->getParam(0); + $key = $variable->scalarval(); // Check it and make sure we're super green - if (!vauth::session_exists('xml-rpc',$key)) { - debug_event('XMLSERVER','Error ' . $_SERVER['REMOTE_ADDR'] . ' with key ' . $key . ' does not match any ACLs','1'); - return new XML_RPC_Response(0,'503','Key/IP Mis-match Access Denied'); - } + if (!vauth::session_exists('xml-rpc',$key)) { + debug_event('XMLSERVER','Error ' . $_SERVER['REMOTE_ADDR'] . ' with key ' . $key . ' does not match any ACLs','1'); + return new XML_RPC_Response(0,'503','Key/IP Mis-match Access Denied'); + } // Go ahead and gather up the information they are legit - $results = array(); + $results = array(); - $sql = "SELECT `catalog`.`name`,COUNT(`song`.`id`) AS `count`,`catalog`.`id` AS `catalog_id` FROM `catalog` ". - "LEFT JOIN `song` ON `catalog`.`id`=`song`.`catalog` WHERE `catalog`.`catalog_type`='local' " . - "GROUP BY `catalog`.`id`"; - $db_results = Dba::query($sql); + $sql = "SELECT `catalog`.`name`,COUNT(`song`.`id`) AS `count`,`catalog`.`id` AS `catalog_id` FROM `catalog` ". + "LEFT JOIN `song` ON `catalog`.`id`=`song`.`catalog` WHERE `catalog`.`catalog_type`='local' " . + "GROUP BY `catalog`.`id`"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row; - } + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row; + } // We need to set time limit at this point as who know how long this data is going to take // to return to the client - set_time_limit(0); + set_time_limit(0); - $encoded_array = XML_RPC_encode($results); - debug_event('XMLSERVER','Returning data about ' . count($results) . ' catalogs to ' . $_SERVER['REMOTE_ADDR'],'5'); + $encoded_array = XML_RPC_encode($results); + debug_event('XMLSERVER','Returning data about ' . count($results) . ' catalogs to ' . $_SERVER['REMOTE_ADDR'],'5'); return new XML_RPC_Response($encoded_array); } // get_catalogs - - + + /** * get_songs * This is a basic function to return all of the song data in a serialized format. It takes a start and end point * as well as the TOKEN for auth mojo * //FIXME: USE TOKEN! */ - public static function get_songs($xmlrpc_object) { + public static function get_songs($xmlrpc_object) { // We're going to be here a while - set_time_limit(0); - + set_time_limit(0); + // Pull out the key $variable = $xmlrpc_object->getParam(0); $key = $variable->scalarval(); @@ -90,50 +90,50 @@ class xmlRpcServer { debug_event('XMLSERVER','Error ' . $_SERVER['REMOTE_ADDR'] . ' with key ' . $key . ' does not match any ACLs','1'); return new XML_RPC_Response(0,'503','Key/IP Mis-match Access Denied'); } - + // Now pull out the start and end - $start = intval($xmlrpc_object->params['1']->me['int']); + $start = intval($xmlrpc_object->params['1']->me['int']); $end = intval($xmlrpc_object->params['2']->me['int']); // Get Catalogs first - $sql = "SELECT `catalog`.`id` FROM `catalog` WHERE `catalog`.`catalog_type`='local'"; - $db_results = Dba::query($sql); + $sql = "SELECT `catalog`.`id` FROM `catalog` WHERE `catalog`.`catalog_type`='local'"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $where_sql .= "`song`.`catalog`='" . $row['id'] . "' OR"; - } + while ($row = Dba::fetch_assoc($db_results)) { + $where_sql .= "`song`.`catalog`='" . $row['id'] . "' OR"; + } - $where_sql = rtrim($where_sql,'OR'); + $where_sql = rtrim($where_sql,'OR'); - $sql = "SELECT `song`.`id` FROM `song` WHERE `song`.`enabled`='1' AND ($where_sql) LIMIT $start,$end"; - $db_results = Dba::query($sql); + $sql = "SELECT `song`.`id` FROM `song` WHERE `song`.`enabled`='1' AND ($where_sql) LIMIT $start,$end"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $song = new Song($row['id']); - $song->fill_ext_info(); - $song->album = $song->get_album_name(); + while ($row = Dba::fetch_assoc($db_results)) { + $song = new Song($row['id']); + $song->fill_ext_info(); + $song->album = $song->get_album_name(); $song->artist = $song->get_artist_name(); - //$song->genre = $song->get_genre_name(); // TODO: Needs to be implemented + //$song->genre = $song->get_genre_name(); // TODO: Needs to be implemented - $output = serialize($song); - $results[] = $output ; + $output = serialize($song); + $results[] = $output ; } // end while - $encoded_array = XML_RPC_encode($results); - debug_event('XMLSERVER','Encoded ' . count($results) . ' songs (' . $start . ',' . $end . ')','5'); + $encoded_array = XML_RPC_encode($results); + debug_event('XMLSERVER','Encoded ' . count($results) . ' songs (' . $start . ',' . $end . ')','5'); return new XML_RPC_Response($encoded_array); } // get_songs - + /** * get_album_images * Returns the images information of the albums */ public static function get_album_images($xmlrpc_object) { // We're going to be here a while - set_time_limit(0); - + set_time_limit(0); + // Pull out the key $variable = $xmlrpc_object->getParam(0); $key = $variable->scalarval(); @@ -143,12 +143,12 @@ class xmlRpcServer { debug_event('XMLSERVER','Error ' . $_SERVER['REMOTE_ADDR'] . ' with key ' . $key . ' does not match any ACLs','1'); return new XML_RPC_Response(0,'503','Key/IP Mis-match Access Denied'); } - + // Get Albums first - $sql = "SELECT `album`.`id` FROM `album` "; - $db_results = Dba::query($sql); + $sql = "SELECT `album`.`id` FROM `album` "; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { + while ($row = Dba::fetch_assoc($db_results)) { // Load the current album $album = new Album($row['id']); $art = $album->get_db_art(); @@ -159,18 +159,18 @@ class xmlRpcServer { $results[] = $output; } } - - $encoded_array = XML_RPC_encode($results); - debug_event('XMLSERVER','Encoded ' . count($results) . 'albums with art','5'); + + $encoded_array = XML_RPC_encode($results); + debug_event('XMLSERVER','Encoded ' . count($results) . 'albums with art','5'); return new XML_RPC_Response($encoded_array); } - + /** * create_stream_session * This creates a new stream session and returns the SID in question, this requires a TOKEN as generated by the handshake */ - public static function create_stream_session($xmlrpc_object) { + public static function create_stream_session($xmlrpc_object) { // Pull out the key $variable = $xmlrpc_object->getParam(0); @@ -182,11 +182,11 @@ class xmlRpcServer { return new XML_RPC_Response(0,'503','Key/IP Mis-match Access Denied'); } - if (!Stream::insert_session($key,'-1')) { - debug_event('XMLSERVER','Failed to create stream session','1'); - return new XML_RPC_Response(0,'503','Failed to Create Stream Session','1'); - } - + if (!Stream::insert_session($key,'-1')) { + debug_event('XMLSERVER','Failed to create stream session','1'); + return new XML_RPC_Response(0,'503','Failed to Create Stream Session','1'); + } + return new XML_RPC_Response(XML_RPC_encode($key)); } // create_stream_session @@ -222,43 +222,43 @@ class xmlRpcServer { /** * handshake * This should be run before any other XMLRPC actions, it checks the KEY encoded with a timestamp then returns a valid TOKEN to be - * used in all further communication + * used in all further communication */ - public static function handshake($xmlrpc_object) { + public static function handshake($xmlrpc_object) { debug_event('XMLSERVER','handshake: ' . print_r ($xmlrpc_object, true),'5'); - + // Pull out the params - $encoded_key = $xmlrpc_object->params['0']->me['string']; + $encoded_key = $xmlrpc_object->params['0']->me['string']; $timestamp = $xmlrpc_object->params['1']->me['int']; // Check the timestamp make sure it's recent - if ($timestamp < (time() - 14400)) { - debug_event('XMLSERVER','Handshake failure, timestamp too old','1'); + if ($timestamp < (time() - 14400)) { + debug_event('XMLSERVER','Handshake failure, timestamp too old','1'); return new XML_RPC_Response(0,'503','Handshake failure, timestamp too old'); - } - + } + // Log the attempt - debug_event('XMLSERVER','Login Attempt, IP: ' . $_SERVER['REMOTE_ADDR'] . ' Time: ' . $timestamp . ' Hash:' . $encoded_key,'1'); + debug_event('XMLSERVER','Login Attempt, IP: ' . $_SERVER['REMOTE_ADDR'] . ' Time: ' . $timestamp . ' Hash:' . $encoded_key,'1'); // Convert the IP Address to an int $ip = Dba::escape(inet_pton($_SERVER['REMOTE_ADDR'])); - // Run the query and return the key's for ACLs of type RPC that would match this IP - $sql = "SELECT * FROM `access_list` WHERE `type`='rpc' AND `start` <= '$ip' AND `end` >= '$ip'"; - $db_results = Dba::query($sql); + // Run the query and return the key's for ACLs of type RPC that would match this IP + $sql = "SELECT * FROM `access_list` WHERE `type`='rpc' AND `start` <= '$ip' AND `end` >= '$ip'"; + $db_results = Dba::read($sql); + + while ($row = Dba::fetch_assoc($db_results)) { - while ($row = Dba::fetch_assoc($db_results)) { - // Build our encoded passphrase $sha256pass = hash('sha256',$timestamp . hash('sha256',$row['key'])); - if ($sha256pass == $encoded_key) { + if ($sha256pass == $encoded_key) { $data['type'] = 'xml-rpc'; - $data['username'] = 'System'; - $data['value'] = 'Handshake'; + $data['username'] = 'System'; + $data['value'] = 'Handshake'; $token = vauth::session_create($data); - - return new XML_RPC_Response(XML_RPC_encode($token)); - } + + return new XML_RPC_Response(XML_RPC_encode($token)); + } } // end while rows diff --git a/lib/debug.lib.php b/lib/debug.lib.php index 365bebe1..1e65b806 100644 --- a/lib/debug.lib.php +++ b/lib/debug.lib.php @@ -54,7 +54,7 @@ function check_database($host,$username,$pass) { function check_database_inserted($dbh,$db_name) { $sql = "DESCRIBE session"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); if (!$db_results) { return false; diff --git a/lib/general.lib.php b/lib/general.lib.php index 1d879490..3c65c178 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -29,7 +29,7 @@ function session_exists($sid,$xml_rpc=0) { $found = true; $sql = "SELECT * FROM `session` WHERE `id` = '$sid'"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); if (!Dba::num_rows($db_results)) { $found = false; @@ -81,7 +81,7 @@ function extend_session($sid) { if ($_COOKIE['amp_longsess'] == '1') { $new_time = time() + 86400*364; } $sql = "UPDATE `session` SET `expire`='$new_time' WHERE `id`='$sid'"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); } // extend_session diff --git a/lib/preferences.php b/lib/preferences.php index 26e8c422..5ea7aba4 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -25,35 +25,35 @@ * and then runs throught $_REQUEST looking for those * values and updates them for this user */ -function update_preferences($pref_id=0) { - +function update_preferences($pref_id=0) { + $pref_user = new User($pref_id); - + /* Get current keys */ $sql = "SELECT `id`,`name`,`type` FROM `preference`"; /* If it isn't the System Account's preferences */ if ($pref_id != '-1') { $sql .= " WHERE `catagory` != 'system'"; } - - $db_results = Dba::query($sql); + + $db_results = Dba::read($sql); // Collect the current possible keys - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $results[] = array('id' => $r['id'], 'name' => $r['name'],'type' => $r['type']); } // end collecting keys /* Foreach through possible keys and assign them */ - foreach ($results as $data) { + foreach ($results as $data) { /* Get the Value from POST/GET var called $data */ $type = $data['type']; $name = $data['name']; $apply_to_all = 'check_' . $data['name']; - $new_level = 'level_' . $data['name']; + $new_level = 'level_' . $data['name']; $id = $data['id']; $value = scrub_in($_REQUEST[$name]); /* Some preferences require some extra checks to be performed */ - switch ($name) { + switch ($name) { case 'sample_rate': $value = Stream::validate_bitrate($value); break; @@ -61,24 +61,24 @@ function update_preferences($pref_id=0) { case 'librefm_pass': case 'lastfm_pass': /* If it's our default blanking thing then don't use it */ - if ($value == '******') { unset($_REQUEST[$name]); break; } - $value = md5($value); + if ($value == '******') { unset($_REQUEST[$name]); break; } + $value = md5($value); break; - default: + default: break; } /* Run the update for this preference only if it's set */ - if (isset($_REQUEST[$name])) { - Preference::update($id,$pref_id,$value,$_REQUEST[$apply_to_all]); - if (Access::check('interface','100') AND $_REQUEST[$new_level]) { - Preference::update_level($id,$_REQUEST[$new_level]); - } + if (isset($_REQUEST[$name])) { + Preference::update($id,$pref_id,$value,$_REQUEST[$apply_to_all]); + if (Access::check('interface','100') AND $_REQUEST[$new_level]) { + Preference::update_level($id,$_REQUEST[$new_level]); + } } } // end foreach preferences // Now that we've done that we need to invalidate the cached preverences - Preference::clear_from_session(); + Preference::clear_from_session(); } // update_preferences @@ -86,26 +86,26 @@ function update_preferences($pref_id=0) { * update_preference * This function updates a single preference and is called by the update_preferences function */ -function update_preference($user_id,$name,$pref_id,$value) { +function update_preference($user_id,$name,$pref_id,$value) { $apply_check = "check_" . $name; - $level_check = "level_" . $name; + $level_check = "level_" . $name; /* First see if they are an administrator and we are applying this to everything */ - if ($GLOBALS['user']->has_access(100) AND make_bool($_REQUEST[$apply_check])) { - Preference::update_all($pref_id,$value); + if ($GLOBALS['user']->has_access(100) AND make_bool($_REQUEST[$apply_check])) { + Preference::update_all($pref_id,$value); return true; } /* Check and see if they are an admin and the level def is set */ - if ($GLOBALS['user']->has_access(100) AND make_bool($_REQUEST[$level_check])) { - Preference::update_level($pref_id,$_REQUEST[$level_check]); - } - + if ($GLOBALS['user']->has_access(100) AND make_bool($_REQUEST[$level_check])) { + Preference::update_level($pref_id,$_REQUEST[$level_check]); + } + /* Else make sure that the current users has the right to do this */ - if (Preference::has_access($name)) { + if (Preference::has_access($name)) { $sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$pref_id' AND `user`='$user_id'"; - $db_results = Dba::query($sql); + $db_results = Dba::write($sql); return true; } @@ -117,23 +117,23 @@ function update_preference($user_id,$name,$pref_id,$value) { * create_preference_input * takes the key and then creates the correct type of input for updating it */ -function create_preference_input($name,$value) { +function create_preference_input($name,$value) { // Escape it for output - $value = scrub_out($value); + $value = scrub_out($value); $len = strlen($value); if ($len <= 1) { $len = 8; } - if (!Preference::has_access($name)) { - if ($value == '1') { + if (!Preference::has_access($name)) { + if ($value == '1') { echo "Enabled"; } - elseif ($value == '0') { + elseif ($value == '0') { echo "Disabled"; } else { - echo $value; + echo $value; } return; } // if we don't have access to it @@ -159,7 +159,7 @@ function create_preference_input($name,$value) { case 'rio_global_stats': case 'embed_xspf': case 'direct_link': - if ($value == '1') { $is_true = "selected=\"selected\""; } + if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; } echo "<select name=\"$name\">\n"; echo "\t<option value=\"1\" $is_true>" . _("Enable") . "</option>\n"; @@ -167,27 +167,27 @@ function create_preference_input($name,$value) { echo "</select>\n"; break; case 'play_type': - if ($value == 'localplay') { $is_local = 'selected="selected"'; } - elseif ($value == 'democratic') { $is_vote = 'selected="selected"'; } - elseif ($value == 'xspf_player') { $is_xspf_player = 'selected="selected"'; } - else { $is_stream = "selected=\"selected\""; } + if ($value == 'localplay') { $is_local = 'selected="selected"'; } + elseif ($value == 'democratic') { $is_vote = 'selected="selected"'; } + elseif ($value == 'xspf_player') { $is_xspf_player = 'selected="selected"'; } + else { $is_stream = "selected=\"selected\""; } echo "<select name=\"$name\">\n"; echo "\t<option value=\"\">" . _('None') . "</option>\n"; - if (Config::get('allow_stream_playback')) { + if (Config::get('allow_stream_playback')) { echo "\t<option value=\"stream\" $is_stream>" . _('Stream') . "</option>\n"; } - if (Config::get('allow_democratic_playback')) { + if (Config::get('allow_democratic_playback')) { echo "\t<option value=\"democratic\" $is_vote>" . _('Democratic') . "</option>\n"; } - if (Config::get('allow_localplay_playback')) { - echo "\t<option value=\"localplay\" $is_local>" . _('Localplay') . "</option>\n"; - } + if (Config::get('allow_localplay_playback')) { + echo "\t<option value=\"localplay\" $is_local>" . _('Localplay') . "</option>\n"; + } echo "\t<option value=\"xspf_player\" $is_xspf_player>" . _('Flash Player') . "</option>\n"; echo "</select>\n"; break; case 'playlist_type': $var_name = $value . "_type"; - ${$var_name} = "selected=\"selected\""; + ${$var_name} = "selected=\"selected\""; echo "<select name=\"$name\">\n"; echo "\t<option value=\"m3u\" $m3u_type>" . _('M3U') . "</option>\n"; echo "\t<option value=\"simple_m3u\" $simple_m3u_type>" . _('Simple M3U') . "</option>\n"; @@ -201,12 +201,12 @@ function create_preference_input($name,$value) { $languages = get_languages(); $var_name = $value . "_lang"; ${$var_name} = "selected=\"selected\""; - + echo "<select name=\"$name\">\n"; - - foreach ($languages as $lang=>$name) { + + foreach ($languages as $lang=>$name) { $var_name = $lang . "_lang"; - + echo "\t<option value=\"$lang\" " . ${$var_name} . ">$name</option>\n"; } // end foreach echo "</select>\n"; @@ -215,18 +215,18 @@ function create_preference_input($name,$value) { $controllers = Localplay::get_controllers(); echo "<select name=\"$name\">\n"; echo "\t<option value=\"\">" . _('None') . "</option>\n"; - foreach ($controllers as $controller) { - if (!Localplay::is_enabled($controller)) { continue; } + foreach ($controllers as $controller) { + if (!Localplay::is_enabled($controller)) { continue; } $is_selected = ''; - if ($value == $controller) { $is_selected = 'selected="selected"'; } + if ($value == $controller) { $is_selected = 'selected="selected"'; } echo "\t<option value=\"" . $controller . "\" $is_selected>" . ucfirst($controller) . "</option>\n"; } // end foreach echo "</select>\n"; break; case 'localplay_level': - if ($value == '25') { $is_user = 'selected="selected"'; } - elseif ($value == '100') { $is_admin = 'selected="selected"'; } - elseif ($value == '50') { $is_manager = 'selected="selected"'; } + if ($value == '25') { $is_user = 'selected="selected"'; } + elseif ($value == '100') { $is_admin = 'selected="selected"'; } + elseif ($value == '50') { $is_manager = 'selected="selected"'; } echo "<select name=\"$name\">\n"; echo "<option value=\"0\">" . _('Disabled') . "</option>\n"; echo "<option value=\"25\" $is_user>" . _('User') . "</option>\n"; @@ -237,7 +237,7 @@ function create_preference_input($name,$value) { case 'theme_name': $themes = get_themes(); echo "<select name=\"$name\">\n"; - foreach ($themes as $theme) { + foreach ($themes as $theme) { $is_selected = ""; if ($value == $theme['path']) { $is_selected = "selected=\"selected\""; } echo "\t<option value=\"" . $theme['path'] . "\" $is_selected>" . $theme['name'] . "</option>\n"; @@ -248,25 +248,25 @@ function create_preference_input($name,$value) { case 'librefm_pass': echo "<input type=\"password\" size=\"16\" name=\"$name\" value=\"******\" />"; break; - case 'playlist_method': - ${$value} = ' selected="selected"'; - echo "<select name=\"$name\">\n"; - echo "\t<option value=\"send\"$send>" . _('Send on Add') . "</option>\n"; - echo "\t<option value=\"send_clear\"$send_clear>" . _('Send and Clear on Add') . "</option>\n"; - echo "\t<option value=\"clear\"$clear>" . _('Clear on Send') . "</option>\n"; - echo "\t<option value=\"default\"$default>" . _('Default') . "</option>\n"; - echo "</select>\n"; + case 'playlist_method': + ${$value} = ' selected="selected"'; + echo "<select name=\"$name\">\n"; + echo "\t<option value=\"send\"$send>" . _('Send on Add') . "</option>\n"; + echo "\t<option value=\"send_clear\"$send_clear>" . _('Send and Clear on Add') . "</option>\n"; + echo "\t<option value=\"clear\"$clear>" . _('Clear on Send') . "</option>\n"; + echo "\t<option value=\"default\"$default>" . _('Default') . "</option>\n"; + echo "</select>\n"; break; case 'transcode': - ${$value} = ' selected="selected"'; - echo "<select name=\"$name\">\n"; - echo "\t<option value=\"never\"$never>" . _('Never') . "</option>\n"; - echo "\t<option value=\"default\"$default>" . _('Default') . "</option>\n"; - echo "\t<option value=\"always\"$always>" . _('Always') . "</option>\n"; + ${$value} = ' selected="selected"'; + echo "<select name=\"$name\">\n"; + echo "\t<option value=\"never\"$never>" . _('Never') . "</option>\n"; + echo "\t<option value=\"default\"$default>" . _('Default') . "</option>\n"; + echo "\t<option value=\"always\"$always>" . _('Always') . "</option>\n"; echo "</select>\n"; break; case 'show_lyrics': - if ($value == '1') { $is_true = "selected=\"selected\""; } + if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; } echo "<select name=\"$name\">\n"; echo "\t<option value=\"1\" $is_true>" . _("Enable") . "</option>\n"; @@ -277,7 +277,7 @@ function create_preference_input($name,$value) { echo "<input type=\"text\" size=\"$len\" name=\"$name\" value=\"$value\" />"; break; - } + } } // create_preference_input diff --git a/lib/ui.lib.php b/lib/ui.lib.php index dc2ca675..34e7fb4d 100644 --- a/lib/ui.lib.php +++ b/lib/ui.lib.php @@ -85,10 +85,10 @@ if (!function_exists('_')) { * ngettext * checks for ngettext and defines it if it doesn't exist */ -if (!function_exists('ngettext')) { - function ngettext($string) { - return $string; - } +if (!function_exists('ngettext')) { + function ngettext($string) { + return $string; + } } // if no ngettext /** @@ -97,11 +97,11 @@ if (!function_exists('ngettext')) { * that they aren't allowed to */ function access_denied() { - + // Clear any crap we've got up top - ob_end_clean(); - require_once Config::get('prefix') . '/templates/show_denied.inc.php'; - exit; + ob_end_clean(); + require_once Config::get('prefix') . '/templates/show_denied.inc.php'; + exit; } // access_denied @@ -119,11 +119,11 @@ function return_referer() { } else { $file = basename($referer); - /* Strip off the filename */ - $referer = substr($referer,0,strlen($referer)-strlen($file)); + /* Strip off the filename */ + $referer = substr($referer,0,strlen($referer)-strlen($file)); } - - if (substr($referer,strlen($referer)-6,6) == 'admin/') { + + if (substr($referer,strlen($referer)-6,6) == 'admin/') { $file = 'admin/' . $file; } @@ -141,8 +141,8 @@ function return_referer() { */ function truncate_with_ellipsis($text, $max='') { - $max = $max ? $max : '27'; - + $max = $max ? $max : '27'; + /* If we want it to be shorter than three, just throw it back */ if ($max > 3) { @@ -171,9 +171,9 @@ function truncate_with_ellipsis($text, $max='') { * This shows the header.inc.php, it may do something * more in the future */ -function show_header() { +function show_header() { - require_once Config::get('prefix') . '/templates/header.inc.php'; + require_once Config::get('prefix') . '/templates/header.inc.php'; } // show_header @@ -203,9 +203,9 @@ function img_resize($image,$size,$type,$album_id) { return $image['raw']; } // Already resized - if ($image['db_resized']) { - debug_event('using_resized','using resized image for Album:' . $album_id,'2'); - return $image['raw']; + if ($image['db_resized']) { + debug_event('using_resized','using resized image for Album:' . $album_id,'2'); + return $image['raw']; } $image = $image['raw']; @@ -226,11 +226,11 @@ function img_resize($image,$size,$type,$album_id) { } $src = imagecreatefromstring($image); - - if (!$src) { + + if (!$src) { debug_event('IMG_RESIZE','Failed to create from string','3'); - return false; - } + return false; + } $width = imagesx($src); $height = imagesy($src); @@ -239,13 +239,13 @@ function img_resize($image,$size,$type,$album_id) { $new_h = $size['height']; $img = imagecreatetruecolor($new_w,$new_h); - - if (!imagecopyresampled($img,$src,0,0,0,0,$new_w,$new_h,$width,$height)) { + + if (!imagecopyresampled($img,$src,0,0,0,0,$new_w,$new_h,$width,$height)) { debug_event('IMG_RESIZE','Failed to copy resample image','3'); return false; } - ob_start(); + ob_start(); // determine image type and send it to the client switch ($type) { @@ -262,19 +262,19 @@ function img_resize($image,$size,$type,$album_id) { } // Grab this image data and save it into the thumbnail - $data = ob_get_contents(); + $data = ob_get_contents(); ob_end_clean(); // If our image create failed don't save it, just return - if (!$data) { - debug_event('IMG_RESIZE','Failed to resize Art from Album:' . $album_id,'3'); + if (!$data) { + debug_event('IMG_RESIZE','Failed to resize Art from Album:' . $album_id,'3'); return $image; } // Save what we've got - Album::save_resized_art($data,'image/' . $type,$album_id); + Album::save_resized_art($data,'image/' . $type,$album_id); - return $data; + return $data; } // img_resize @@ -293,10 +293,10 @@ function get_location() { $location = array(); - if (strlen($_SERVER['PHP_SELF'])) { + if (strlen($_SERVER['PHP_SELF'])) { $source = $_SERVER['PHP_SELF']; } - else { + else { $source = $_SERVER['REQUEST_URI']; } @@ -388,8 +388,8 @@ function get_location() { * it takes a chunck of the crazy preference array and then displays it out * it does not contain the <form> </form> tags */ -function show_preference_box($preferences) { - +function show_preference_box($preferences) { + require Config::get('prefix') . '/templates/show_preference_box.inc.php'; } // show_preference_box @@ -432,9 +432,9 @@ function good_email($email) { /** * show_album_select * This displays a select of every album that we've got in Ampache, (it can be hella long) it's used - * by the Edit page, it takes a $name and a $album_id + * by the Edit page, it takes a $name and a $album_id */ -function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) { +function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) { // Generate key to use for HTML element ID static $id_cnt; if ($song_id) { @@ -447,17 +447,17 @@ function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) { echo "<select name=\"$name\" id=\"$key\">\n"; $sql = "SELECT `id`, `name`, `prefix` FROM `album` ORDER BY `name`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $selected = ''; $album_name = trim($r['prefix'] . " " . $r['name']); - if ($r['id'] == $album_id) { + if ($r['id'] == $album_id) { $selected = "selected=\"selected\""; } echo "\t<option value=\"" . $r['id'] . "\" $selected>" . scrub_out($album_name) . "</option>\n"; - + } // end while if ($allow_add) { @@ -473,7 +473,7 @@ function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) { * show_artist_select * This is the same as the album select except it's *gasp* for artists how inventive! */ -function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id=0) { +function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id=0) { // Generate key to use for HTML element ID static $id_cnt; if ($song_id) { @@ -483,14 +483,14 @@ function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id } echo "<select name=\"$name\" id=\"$key\">\n"; - + $sql = "SELECT `id`, `name`, `prefix` FROM `artist` ORDER BY `name`"; - $db_results = Dba::query($sql); - - while ($r = Dba::fetch_assoc($db_results)) { + $db_results = Dba::read($sql); + + while ($r = Dba::fetch_assoc($db_results)) { $selected = ''; $artist_name = trim($r['prefix'] . " " . $r['name']); - if ($r['id'] == $artist_id) { + if ($r['id'] == $artist_id) { $selected = "selected=\"selected\""; } @@ -509,18 +509,18 @@ function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id /** * show_catalog_select - * Yet another one of these buggers. this shows a drop down of all of your catalogs + * Yet another one of these buggers. this shows a drop down of all of your catalogs */ -function show_catalog_select($name='catalog',$catalog_id=0,$style='') { +function show_catalog_select($name='catalog',$catalog_id=0,$style='') { echo "<select name=\"$name\" style=\"$style\">\n"; $sql = "SELECT `id`, `name` FROM `catalog` ORDER BY `name`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $selected = ''; - if ($r['id'] == $catalog_id) { + if ($r['id'] == $catalog_id) { $selected = "selected=\"selected\""; } @@ -537,21 +537,21 @@ function show_catalog_select($name='catalog',$catalog_id=0,$style='') { * This one is for users! shows a select/option statement so you can pick a user * to blame */ -function show_user_select($name,$selected='',$style='') { +function show_user_select($name,$selected='',$style='') { echo "<select name=\"$name\" style=\"$style\">\n"; echo "\t<option value=\"\">" . _('All') . "</option>\n"; $sql = "SELECT `id`,`username`,`fullname` FROM `user` ORDER BY `fullname`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { + while ($row = Dba::fetch_assoc($db_results)) { $select_txt = ''; - if ($row['id'] == $selected) { + if ($row['id'] == $selected) { $select_txt = 'selected="selected"'; } // If they don't have a full name, revert to the username - $row['fullname'] = $row['fullname'] ? $row['fullname'] : $row['username']; + $row['fullname'] = $row['fullname'] ? $row['fullname'] : $row['username']; echo "\t<option value=\"" . $row['id'] . "\" $select_txt>" . scrub_out($row['fullname']) . "</option>\n"; } // end while users @@ -565,17 +565,17 @@ function show_user_select($name,$selected='',$style='') { * This one is for users! shows a select/option statement so you can pick a user * to blame */ -function show_playlist_select($name,$selected='',$style='') { +function show_playlist_select($name,$selected='',$style='') { echo "<select name=\"$name\" style=\"$style\">\n"; echo "\t<option value=\"\">" . _('None') . "</option>\n"; $sql = "SELECT `id`,`name` FROM `playlist` ORDER BY `name`"; - $db_results = Dba::query($sql); + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { + while ($row = Dba::fetch_assoc($db_results)) { $select_txt = ''; - if ($row['id'] == $selected) { + if ($row['id'] == $selected) { $select_txt = 'selected="selected"'; } // If they don't have a full name, revert to the username @@ -591,9 +591,9 @@ function show_playlist_select($name,$selected='',$style='') { * This function requires the top part of the box * it takes title as an optional argument */ -function show_box_top($title='',$class='') { +function show_box_top($title='',$class='') { - require Config::get('prefix') . '/templates/show_box_top.inc.php'; + require Config::get('prefix') . '/templates/show_box_top.inc.php'; } // show_box_top @@ -602,7 +602,7 @@ function show_box_top($title='',$class='') { * This function requires the bottom part of the box * it does not take any arguments */ -function show_box_bottom() { +function show_box_bottom() { require Config::get('prefix') . '/templates/show_box_bottom.inc.php'; @@ -611,58 +611,58 @@ function show_box_bottom() { /** * get_user_icon * this function takes a name and a returns either a text representation - * or an <img /> tag + * or an <img /> tag */ -function get_user_icon($name,$title='',$id='') { - +function get_user_icon($name,$title='',$id='') { + /* Because we do a lot of calls cache the URLs */ - static $url_cache = array(); + static $url_cache = array(); // If our name is an array - if (is_array($name)) { - $hover_name = $name['1']; - $name = $name['0']; - } + if (is_array($name)) { + $hover_name = $name['1']; + $name = $name['0']; + } - if (!$title) { $title = _(ucfirst($name)); } + if (!$title) { $title = _(ucfirst($name)); } - if ($id) { - $id_element = 'id="' . $id . '"'; - } + if ($id) { + $id_element = 'id="' . $id . '"'; + } - if (isset($url_cache[$name])) { - $img_url = $url_cache[$name]; - $cache_url = true; + if (isset($url_cache[$name])) { + $img_url = $url_cache[$name]; + $cache_url = true; } - if (isset($url_cache[$hover_name])) { + if (isset($url_cache[$hover_name])) { $hover_url = $url_cache[$hover_name]; - $cache_hover = true; + $cache_hover = true; } - - if (empty($hover_name)) { $cache_hover = true; } - if (!isset($cache_url) OR !isset($cache_hover)) { + if (empty($hover_name)) { $cache_hover = true; } + + if (!isset($cache_url) OR !isset($cache_hover)) { $icon_name = 'icon_' . $name . '.png'; /* Build the image url */ - if (file_exists(Config::get('prefix') . Config::get('theme_path') . '/images/icons/' . $icon_name)) { + if (file_exists(Config::get('prefix') . Config::get('theme_path') . '/images/icons/' . $icon_name)) { $img_url = Config::get('web_path') . Config::get('theme_path') . '/images/icons/' . $icon_name; } - else { - $img_url = Config::get('web_path') . '/images/' . $icon_name; + else { + $img_url = Config::get('web_path') . '/images/' . $icon_name; } /* If Hover, then build its url */ - if (!empty($hover_name)) { + if (!empty($hover_name)) { $hover_icon = 'icon_' . $hover_name . '.png'; - if (file_exists(Config::get('prefix') . Config::get('theme_path') . '/images/icons/' . $icon_name)) { + if (file_exists(Config::get('prefix') . Config::get('theme_path') . '/images/icons/' . $icon_name)) { $hov_url = Config::get('web_path') . Config::get('theme_path') . '/images/icons/' . $hover_icon; } - else { + else { $hov_url = Config::get('web_path') . '/images/' . $hover_icon; } - + $hov_txt = "onmouseover=\"this.src='$hov_url'; return true;\" onmouseout=\"this.src='$img_url'; return true;\""; } // end hover @@ -676,14 +676,14 @@ function get_user_icon($name,$title='',$id='') { /** * xml_from_array - * This takes a one dimensional array and - * creates a XML document form it for use + * This takes a one dimensional array and + * creates a XML document form it for use * primarly by the ajax mojo */ -function xml_from_array($array,$callback=0,$type='') { +function xml_from_array($array,$callback=0,$type='') { // If we weren't passed an array then return a blank string - if (!is_array($array)) { return ''; } + if (!is_array($array)) { return ''; } // The type is used for the different XML docs we pass switch ($type) { @@ -732,19 +732,19 @@ function xml_from_array($array,$callback=0,$type='') { return $string; break; default: - foreach ($array as $key=>$value) { - if (is_numeric($key)) { $key = 'item'; } - if (is_array($value)) { + foreach ($array as $key=>$value) { + if (is_numeric($key)) { $key = 'item'; } + if (is_array($value)) { $value = xml_from_array($value,1); $string .= "\t<content div=\"$key\">$value</content>\n"; } - else { + else { /* We need to escape the value */ $string .= "\t<content div=\"$key\"><![CDATA[$value]]></content>\n"; } // end foreach elements - } - if (!$callback) { + } + if (!$callback) { $string = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<root>\n" . $string . "</root>\n"; } @@ -755,7 +755,7 @@ function xml_from_array($array,$callback=0,$type='') { /** * xml_get_header - * This takes the type and returns the correct xml header + * This takes the type and returns the correct xml header */ function xml_get_header($type){ switch ($type){ @@ -776,18 +776,18 @@ function xml_get_header($type){ break; case 'xspf': $header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" . - "<!-- XML Generated by Ampache v." . Config::get('version') . " -->"; + "<!-- XML Generated by Ampache v." . Config::get('version') . " -->"; "<playlist version = \"1\" xmlns=\"http://xspf.org/ns/0/\">\n ". "<title>Ampache XSPF Playlist</title>\n" . "<creator>" . Config::get('site_title') . "</creator>\n" . "<annotation>" . Config::get('site_title') . "</annotation>\n" . "<info>". Config::get('web_path') ."</info>\n" . "<trackList>\n\n\n\n"; - return $header; + return $header; break; default: - $header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; - return $header; + $header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; + return $header; break; } } //xml_get_header @@ -821,14 +821,14 @@ function xml_get_footer($type){ * on the specified require, only works if you * don't need to pass data in */ -function ajax_include($include) { +function ajax_include($include) { - ob_start(); - require_once Config::get('prefix') . '/templates/' . $include; - $results = ob_get_contents(); - ob_end_clean(); + ob_start(); + require_once Config::get('prefix') . '/templates/' . $include; + $results = ob_get_contents(); + ob_end_clean(); - return $results; + return $results; } // ajax_include @@ -836,11 +836,11 @@ function ajax_include($include) { * toggle_visible * this is identicla to the javascript command that it actually calls */ -function toggle_visible($element) { +function toggle_visible($element) { - echo "<script type=\"text/javascript\">\n"; - echo "toggle_visible('$element');"; - echo "\n</script>\n"; + echo "<script type=\"text/javascript\">\n"; + echo "toggle_visible('$element');"; + echo "\n</script>\n"; } // toggle_visible @@ -849,14 +849,14 @@ function toggle_visible($element) { * This shows the now playing templates and does some garbage colleciont * this should really be somewhere else */ -function show_now_playing() { - - Stream::gc_session(); - Stream::gc_now_playing(); - - $web_path = Config::get('web_path'); - $results = Stream::get_now_playing(); - require_once Config::get('prefix') . '/templates/show_now_playing.inc.php'; +function show_now_playing() { + + Stream::gc_session(); + Stream::gc_now_playing(); + + $web_path = Config::get('web_path'); + $results = Stream::get_now_playing(); + require_once Config::get('prefix') . '/templates/show_now_playing.inc.php'; } // show_now_playing |