summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/batch.lib.php58
-rw-r--r--lib/class/access.class.php334
-rw-r--r--lib/class/ajax.class.php94
-rw-r--r--lib/class/album.class.php644
-rw-r--r--lib/class/ampacherss.class.php126
-rw-r--r--lib/class/api.class.php240
-rw-r--r--lib/class/art.class.php6
-rw-r--r--lib/class/artist.class.php154
-rw-r--r--lib/class/browse.class.php248
-rw-r--r--lib/class/catalog.class.php494
-rw-r--r--lib/class/config.class.php36
-rw-r--r--lib/class/core.class.php90
-rw-r--r--lib/class/democratic.class.php396
-rw-r--r--lib/class/error.class.php70
-rw-r--r--lib/class/flag.class.php212
-rw-r--r--lib/class/localplay.abstract.php76
-rw-r--r--lib/class/localplay.class.php322
-rw-r--r--lib/class/media.interface.php12
-rw-r--r--lib/class/playlist.class.php240
-rw-r--r--lib/class/plugin.class.php158
-rw-r--r--lib/class/preference.class.php298
-rw-r--r--lib/class/query.class.php20
-rw-r--r--lib/class/radio.class.php166
-rw-r--r--lib/class/random.class.php426
-rw-r--r--lib/class/rating.class.php158
-rw-r--r--lib/class/registration.class.php20
-rw-r--r--lib/class/scrobbler.class.php86
-rw-r--r--lib/class/shoutbox.class.php152
-rw-r--r--lib/class/song.class.php528
-rw-r--r--lib/class/stats.class.php126
-rw-r--r--lib/class/stream.class.php488
-rw-r--r--lib/class/tag.class.php470
-rw-r--r--lib/class/tmpplaylist.class.php160
-rw-r--r--lib/class/update.class.php64
-rw-r--r--lib/class/user.class.php12
-rw-r--r--lib/class/vainfo.class.php482
-rw-r--r--lib/class/vauth.class.php14
-rw-r--r--lib/class/video.class.php70
-rw-r--r--lib/class/xmldata.class.php500
-rw-r--r--lib/gettext.php8
-rw-r--r--lib/init.php144
-rw-r--r--lib/install.php40
-rw-r--r--lib/log.lib.php52
-rw-r--r--lib/preferences.php8
-rw-r--r--lib/rating.lib.php12
-rw-r--r--lib/search.php138
-rw-r--r--lib/themes.php34
47 files changed, 4343 insertions, 4343 deletions
diff --git a/lib/batch.lib.php b/lib/batch.lib.php
index aca73874..e79a55d0 100644
--- a/lib/batch.lib.php
+++ b/lib/batch.lib.php
@@ -8,7 +8,7 @@
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
@@ -28,20 +28,20 @@
*/
function get_song_files($media_ids) {
- $media_files = array();
-
+ $media_files = array();
+
foreach ($media_ids as $element) {
- if (is_array($element)) {
- $type = array_shift($element);
- $media = new $type(array_shift($element));
- }
- else {
- $media = new Song($element);
- }
- if ($media->enabled) {
+ if (is_array($element)) {
+ $type = array_shift($element);
+ $media = new $type(array_shift($element));
+ }
+ else {
+ $media = new Song($element);
+ }
+ if ($media->enabled) {
$total_size += sprintf("%.2f",($media->size/1048576));
array_push($media_files, $media->file);
- }
+ }
}
return array($media_files,$total_size);
@@ -59,19 +59,19 @@ function send_zip( $name, $song_files ) {
// Check if they want to save it to a file, if so then make sure they've got
// a defined path as well and that it's writeable
- if (Config::get('file_zip_download') && Config::get('file_zip_path')) {
+ if (Config::get('file_zip_download') && Config::get('file_zip_path')) {
// Check writeable
- if (!is_writable(Config::get('file_zip_path'))) {
- $in_memory = '1';
- debug_event('Error','File Zip Path:' . Config::get('file_zip_path') . ' is not writeable','1');
- }
- else {
- $in_memory = '0';
- $basedir = Config::get('file_zip_path');
- }
+ if (!is_writable(Config::get('file_zip_path'))) {
+ $in_memory = '1';
+ debug_event('Error','File Zip Path:' . Config::get('file_zip_path') . ' is not writeable','1');
+ }
+ else {
+ $in_memory = '0';
+ $basedir = Config::get('file_zip_path');
+ }
} else {
- $in_memory = '1';
+ $in_memory = '1';
} // if file downloads
/* Require needed library */
@@ -84,20 +84,20 @@ function send_zip( $name, $song_files ) {
'level' => 0, // no compression
'comment' => Config::get('file_zip_comment')
);
-
+
$arc->set_options( $options );
$arc->add_files( $song_files );
- if (count($arc->error)) {
+ if (count($arc->error)) {
debug_event('archive',"Error: unable to add songs",'3');
- return false;
+ return false;
} // if failed to add songs
-
- if (!$arc->create_archive()) {
+
+ if (!$arc->create_archive()) {
debug_event('archive',"Error: unable to create archive",'3');
- return false;
+ return false;
} // if failed to create archive
-
+
$arc->download_file();
} // send_zip
diff --git a/lib/class/access.class.php b/lib/class/access.class.php
index 3652715d..7f986fef 100644
--- a/lib/class/access.class.php
+++ b/lib/class/access.class.php
@@ -16,10 +16,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.
*/
-/**
+/**
* Access Class
* This class handles the access list mojo for Ampache, it is ment to restrict
* access based on IP and maybe something else in the future
@@ -38,7 +38,7 @@ class Access {
/**
* constructor
- * Takes an ID of the access_id dealie :)
+ * Takes an ID of the access_id dealie :)
*/
public function __construct($access_id='') {
@@ -48,9 +48,9 @@ class Access {
$this->id = intval($access_id);
$info = $this->_get_info();
- foreach ($info as $key=>$value) {
- $this->$key = $value;
- }
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
return true;
@@ -58,7 +58,7 @@ class Access {
/**
* _get_info
- * get's the vars for $this out of the database
+ * get's the vars for $this out of the database
* Taken from the object
*/
private function _get_info() {
@@ -75,16 +75,16 @@ class Access {
/**
* format
- * This makes the Access object a nice fuzzy human readable object, spiffy ain't it.
+ * This makes the Access object a nice fuzzy human readable object, spiffy ain't it.
*/
- public function format() {
+ public function format() {
- $this->f_start = inet_ntop($this->start);
- $this->f_end = inet_ntop($this->end);
+ $this->f_start = inet_ntop($this->start);
+ $this->f_end = inet_ntop($this->end);
- $this->f_user = $this->get_user_name();
- $this->f_level = $this->get_level_name();
- $this->f_type = $this->get_type_name();
+ $this->f_user = $this->get_user_name();
+ $this->f_level = $this->get_level_name();
+ $this->f_type = $this->get_type_name();
} // format
@@ -92,7 +92,7 @@ class Access {
* update
* This function takes a named array as a datasource and updates the current access list entry
*/
- public function update($data) {
+ public function update($data) {
/* We need to verify the incomming data a littlebit */
$start = @inet_pton($data['start']);
@@ -113,16 +113,16 @@ class Access {
return false;
}
- $name = Dba::escape($data['name']);
- $type = self::validate_type($data['type']);
+ $name = Dba::escape($data['name']);
+ $type = self::validate_type($data['type']);
$start = Dba::escape(inet_pton($data['start']));
- $end = Dba::escape(inet_pton($data['end']));
+ $end = Dba::escape(inet_pton($data['end']));
$level = Dba::escape($data['level']);
- $user = $data['user'] ? Dba::escape($data['user']) : '-1';
- $enabled = make_bool($data['enabled']);
-
- $sql = "UPDATE `access_list` " .
- "SET `start`='$start', `end`='$end', `level`='$level', `user`='$user', " .
+ $user = $data['user'] ? Dba::escape($data['user']) : '-1';
+ $enabled = make_bool($data['enabled']);
+
+ $sql = "UPDATE `access_list` " .
+ "SET `start`='$start', `end`='$end', `level`='$level', `user`='$user', " .
"`name`='$name', `type`='$type',`enabled`='$enabled' WHERE `id`='" . Dba::escape($this->id) . "'";
$db_results = Dba::write($sql);
@@ -132,45 +132,45 @@ class Access {
/**
* create
- * This takes a key'd array of data and trys to insert it as a
+ * This takes a key'd array of data and trys to insert it as a
* new ACL entry
*/
- public static function create($data) {
+ public static function create($data) {
/* We need to verify the incomming data a littlebit */
- $start = @inet_pton($data['start']);
- $end = @inet_pton($data['end']);
-
- if (!$start AND $data['start'] != '0.0.0.0' AND $data['start'] != '::') {
- Error::add('start',_('Invalid IPv4 / IPv6 Address Entered'));
- return false;
- }
- if (!$end) {
- Error::add('end',_('Invalid IPv4 / IPv6 Address Entered'));
- return false;
- }
-
- if (strlen(bin2hex($start)) != strlen(bin2hex($end))) {
- Error::add('start',_('IP Address Version Mismatch'));
- Error::add('end',_('IP Address Version Mismatch'));
- return false;
- }
+ $start = @inet_pton($data['start']);
+ $end = @inet_pton($data['end']);
+
+ if (!$start AND $data['start'] != '0.0.0.0' AND $data['start'] != '::') {
+ Error::add('start',_('Invalid IPv4 / IPv6 Address Entered'));
+ return false;
+ }
+ if (!$end) {
+ Error::add('end',_('Invalid IPv4 / IPv6 Address Entered'));
+ return false;
+ }
+
+ if (strlen(bin2hex($start)) != strlen(bin2hex($end))) {
+ Error::add('start',_('IP Address Version Mismatch'));
+ Error::add('end',_('IP Address Version Mismatch'));
+ return false;
+ }
// Check existing ACL's to make sure we're not duplicating values here
- if (self::exists($data)) {
- debug_event('ACL Create','Error did not create duplicate ACL entrie for ' . $data['start'] . ' - ' . $data['end'],'1');
- return false;
- }
+ if (self::exists($data)) {
+ debug_event('ACL Create','Error did not create duplicate ACL entrie for ' . $data['start'] . ' - ' . $data['end'],'1');
+ return false;
+ }
- $start = Dba::escape($start);
+ $start = Dba::escape($start);
$end = Dba::escape($end);
$name = Dba::escape($data['name']);
- $user = $data['user'] ? Dba::escape($data['user']) : '-1';
+ $user = $data['user'] ? Dba::escape($data['user']) : '-1';
$level = intval($data['level']);
$type = self::validate_type($data['type']);
- $enabled = make_bool($data['enabled']);
+ $enabled = make_bool($data['enabled']);
- $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`user`,`type`,`enabled`) " .
+ $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`user`,`type`,`enabled`) " .
"VALUES ('$name','$level','$start','$end','$user','$type','$enabled')";
$db_results = Dba::write($sql);
@@ -182,22 +182,22 @@ class Access {
* exists
* this sees if the ACL that we've specified already exists, prevent duplicates. This ignores the name
*/
- public static function exists($data) {
+ public static function exists($data) {
- $start = Dba::escape(inet_pton($data['start']));
- $end = Dba::escape(inet_pton($data['end']));
- $type = self::validate_type($data['type']);
- $user = $data['user'] ? Dba::escape($data['user']) : '-1';
+ $start = Dba::escape(inet_pton($data['start']));
+ $end = Dba::escape(inet_pton($data['end']));
+ $type = self::validate_type($data['type']);
+ $user = $data['user'] ? Dba::escape($data['user']) : '-1';
- $sql = "SELECT * FROM `access_list` WHERE `start`='$start' AND `end` = '$end' " .
- "AND `type`='$type' AND `user`='$user'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `access_list` WHERE `start`='$start' AND `end` = '$end' " .
+ "AND `type`='$type' AND `user`='$user'";
+ $db_results = Dba::read($sql);
- if (Dba::fetch_assoc($db_results)) {
- return true;
- }
+ if (Dba::fetch_assoc($db_results)) {
+ return true;
+ }
- return false;
+ return false;
} // exists
@@ -205,23 +205,23 @@ class Access {
* delete
* deletes the specified access_list entry
*/
- public static function delete($access_id) {
+ public static function delete($access_id) {
$sql = "DELETE FROM `access_list` WHERE `id`='" . Dba::escape($access_id) . "'";
$db_results = Dba::write($sql);
} // delete
-
+
/**
* check_function
* This checks if a specific functionality is enabled
* it takes a type only
*/
- public static function check_function($type) {
+ public static function check_function($type) {
- switch ($type) {
- case 'download':
- return Config::get('download');
+ switch ($type) {
+ case 'download':
+ return Config::get('download');
break ;
case 'batch_download':
if (!function_exists('gzcompress')) {
@@ -233,37 +233,37 @@ class Access {
}
break;
default:
- return false;
+ return false;
break;
- } // end switch
+ } // end switch
} // check_function
/**
* check_network
- * This takes a type, ip, user, level and key
+ * This takes a type, ip, user, level and key
* and then returns true or false if they have access to this
* the IP is passed as a dotted quad
*/
- public static function check_network($type,$user,$level,$ip='') {
-
- if (!Config::get('access_control')) {
- switch ($type) {
- case 'interface':
- case 'stream':
- return true;
- break;
- default:
- return false;
+ public static function check_network($type,$user,$level,$ip='') {
+
+ if (!Config::get('access_control')) {
+ switch ($type) {
+ case 'interface':
+ case 'stream':
+ return true;
+ break;
+ default:
+ return false;
} // end switch
} // end if access control is turned off
// Clean incomming variables
- $ip = $ip ? Dba::escape(inet_pton($ip)) : Dba::escape(inet_pton($_SERVER['REMOTE_ADDR']));
+ $ip = $ip ? Dba::escape(inet_pton($ip)) : Dba::escape(inet_pton($_SERVER['REMOTE_ADDR']));
$user = Dba::escape($user);
$level = Dba::escape($level);
- switch ($type) {
+ switch ($type) {
/* This is here because we want to at least check IP before even creating the xml-rpc server
* however we don't have the key that was passed yet so we've got to do just ip
*/
@@ -272,39 +272,39 @@ class Access {
$sql = "SELECT `id` FROM `access_list`" .
" WHERE `start` <= '$ip' AND `end` >= '$ip' AND `type`='rpc' AND `level` >= '$level'";
break;
- case 'rpc':
+ case 'rpc':
case 'xml-rpc':
- $sql = "SELECT `id` FROM `access_list`" .
- " WHERE `start` <= '$ip' AND `end` >= '$ip'" .
+ $sql = "SELECT `id` FROM `access_list`" .
+ " WHERE `start` <= '$ip' AND `end` >= '$ip'" .
" AND `level` >= '$level' AND `type`='rpc'";
break;
case 'init-api':
$type = 'rpc';
- if ($user) {
- $client = User::get_from_username($user);
- $user = $client->id;
- }
+ if ($user) {
+ $client = User::get_from_username($user);
+ $user = $client->id;
+ }
case 'network':
case 'interface':
case 'stream':
default:
- $sql = "SELECT `id` FROM `access_list`" .
+ $sql = "SELECT `id` FROM `access_list`" .
" WHERE `start` <= '$ip' AND `end` >= '$ip'" .
" AND `level` >= '$level' AND `type` = '$type'";
if (strlen($user)) { $sql .= " AND (`user` = '$user' OR `user` = '-1')"; }
else { $sql .= " AND `user` = '-1'"; }
break;
} // end switch on type
-
+
$db_results = Dba::read($sql);
// Yah they have access they can use the mojo
- if (Dba::fetch_row($db_results)) {
+ if (Dba::fetch_row($db_results)) {
return true;
}
// No Access Sucks to be them.
- else {
+ else {
return false;
}
@@ -315,40 +315,40 @@ class Access {
* This is the global 'has_access' function it can check for any 'type' of object
* everything uses the global 0,5,25,50,75,100 stuff. GLOBALS['user'] is always used
*/
- public static function check($type,$level) {
+ public static function check($type,$level) {
- if (Config::get('demo_mode')) { return true; }
- if (INSTALL == '1') { return true; }
+ if (Config::get('demo_mode')) { return true; }
+ if (INSTALL == '1') { return true; }
- $level = intval($level);
+ $level = intval($level);
// Switch on the type
- switch ($type) {
- case 'localplay':
- // Check their localplay_level
- if (Config::get('localplay_level') >= $level OR $GLOBALS['user']->access >= '100') {
- return true;
- }
- else {
- return false;
- }
+ switch ($type) {
+ case 'localplay':
+ // Check their localplay_level
+ if (Config::get('localplay_level') >= $level OR $GLOBALS['user']->access >= '100') {
+ return true;
+ }
+ else {
+ return false;
+ }
break;
- case 'interface':
+ case 'interface':
// Check their standard user level
- if ($GLOBALS['user']->access >= $level) {
- return true;
- }
- else {
- return false;
- }
+ if ($GLOBALS['user']->access >= $level) {
+ return true;
+ }
+ else {
+ return false;
+ }
break;
default:
- return false;
- break;
+ return false;
+ break;
} // end switch on type
// Default false
- return false;
+ return false;
} // check
@@ -356,9 +356,9 @@ class Access {
* validate_type
* This cleans up and validates the specified type
*/
- public static function validate_type($type) {
+ public static function validate_type($type) {
- switch($type) {
+ switch($type) {
case 'rpc':
case 'interface':
case 'network':
@@ -366,8 +366,8 @@ class Access {
break;
case 'xml-rpc':
return 'rpc';
- break;
- default:
+ break;
+ default:
return 'stream';
break;
} // end switch
@@ -378,13 +378,13 @@ class Access {
* get_access_lists
* returns a full listing of all access rules on this server
*/
- public static function get_access_lists() {
+ public static function get_access_lists() {
$sql = "SELECT `id` FROM `access_list`";
$db_results = Dba::read($sql);
-
- $results = array();
-
+
+ $results = array();
+
// Man this is the wrong way to do it...
while ($row = Dba::fetch_assoc($db_results)) {
$results[] = $row['id'];
@@ -395,22 +395,22 @@ class Access {
} // get_access_lists
- /**
+ /**
* get_level_name
* take the int level and return a named level
*/
- public function get_level_name() {
+ public function get_level_name() {
- if ($this->level >= '75') {
+ if ($this->level >= '75') {
return _('All');
}
- if ($this->level == '5') {
- return _('View');
+ if ($this->level == '5') {
+ return _('View');
}
- if ($this->level == '25') {
+ if ($this->level == '25') {
return _('Read');
}
- if ($this->level == '50') {
+ if ($this->level == '50') {
return _('Read/Write');
}
@@ -420,23 +420,23 @@ class Access {
* get_user_name
* Take a user and return their full name
*/
- public function get_user_name() {
+ public function get_user_name() {
+
+ if ($this->user == '-1') { return _('All'); }
- if ($this->user == '-1') { return _('All'); }
-
$user = new User($this->user);
return $user->fullname . " (" . $user->username . ")";
-
+
} // get_user_name
/**
* get_type_name
* This function returns the pretty name for our current type
*/
- public function get_type_name() {
+ public function get_type_name() {
- switch ($this->type) {
- case 'xml-rpc':
+ switch ($this->type) {
+ case 'xml-rpc':
case 'rpc':
return _('API/RPC');
break;
@@ -447,7 +447,7 @@ class Access {
return _('Web Interface');
break;
case 'stream':
- default:
+ default:
return _('Stream Access');
break;
} // end switch
@@ -460,35 +460,35 @@ class Access {
* exists, it also provides an array of key'd data that may be required
* based on the type
*/
- public static function session_exists($data,$key,$type) {
+ public static function session_exists($data,$key,$type) {
// Switch on the type they pass
- switch ($type) {
- case 'api':
- $key = Dba::escape($key);
- $time = time();
- $sql = "SELECT * FROM `session_api` WHERE `id`='$key' AND `expire` > '$time'";
- $db_results = Dba::read($sql);
-
- if (Dba::num_rows($db_results)) {
- $time = $time + 3600;
- $sql = "UPDATE `session_api` WHERE `id`='$key' SET `expire`='$time'";
- $db_results = Dba::write($sql);
- return true;
- }
-
- return false;
-
- break;
- case 'stream':
-
- break;
- case 'interface':
-
- break;
- default:
- return false;
- break;
+ switch ($type) {
+ case 'api':
+ $key = Dba::escape($key);
+ $time = time();
+ $sql = "SELECT * FROM `session_api` WHERE `id`='$key' AND `expire` > '$time'";
+ $db_results = Dba::read($sql);
+
+ if (Dba::num_rows($db_results)) {
+ $time = $time + 3600;
+ $sql = "UPDATE `session_api` WHERE `id`='$key' SET `expire`='$time'";
+ $db_results = Dba::write($sql);
+ return true;
+ }
+
+ return false;
+
+ break;
+ case 'stream':
+
+ break;
+ case 'interface':
+
+ break;
+ default:
+ return false;
+ break;
} // type
diff --git a/lib/class/ajax.class.php b/lib/class/ajax.class.php
index 5381f529..38c451a9 100644
--- a/lib/class/ajax.class.php
+++ b/lib/class/ajax.class.php
@@ -25,15 +25,15 @@
* This class is specifically for setuping/printing out ajax related
* elements onto a page it takes care of the observing and all that raz-a-ma-taz
*/
-class Ajax {
+class Ajax {
- private static $include_override;
+ private static $include_override;
/**
* constructor
* This is what is called when the class is loaded
*/
- public function __construct() {
+ public function __construct() {
// Rien a faire
@@ -43,7 +43,7 @@ class Ajax {
* observe
* This returns a string with the correct and full ajax 'observe' stuff from prototype
*/
- public static function observe($source,$method,$action,$post='') {
+ public static function observe($source,$method,$action,$post='') {
$non_quoted = array('document','window');
@@ -55,15 +55,15 @@ class Ajax {
}
// If it's a post then we need to stop events
- if ($post) {
- $action = 'Event.stop(e); ' . $action;
- }
+ if ($post) {
+ $action = 'Event.stop(e); ' . $action;
+ }
$observe = "<script type=\"text/javascript\">";
$observe .= "Event.observe($source_txt,'$method',function(e){" . $action . ";});";
$observe .= "</script>";
- return $observe;
+ return $observe;
} // observe
@@ -72,9 +72,9 @@ class Ajax {
* This takes the action, the source and the post (if passed) and generated the full
* ajax link
*/
- public static function action($action,$source,$post='') {
+ public static function action($action,$source,$post='') {
- $url = Config::get('ajax_url') . $action;
+ $url = Config::get('ajax_url') . $action;
$non_quoted = array('document','window');
@@ -85,14 +85,14 @@ class Ajax {
$source_txt = "'$source'";
}
- if ($post) {
- $ajax_string = "ajaxPost('$url','$post',$source_txt)";
+ if ($post) {
+ $ajax_string = "ajaxPost('$url','$post',$source_txt)";
+ }
+ else {
+ $ajax_string = "ajaxPut('$url',$source_txt)";
}
- else {
- $ajax_string = "ajaxPut('$url',$source_txt)";
- }
-
- return $ajax_string;
+
+ return $ajax_string;
} // action
@@ -101,24 +101,24 @@ class Ajax {
* This prints out an img of the specified icon with the specified alt text
* and then sets up the required ajax for it
*/
- public static function button($action,$icon,$alt,$source='',$post='',$class='') {
+ public static function button($action,$icon,$alt,$source='',$post='',$class='') {
// Get the correct action
- $ajax_string = self::action($action,$source,$post);
+ $ajax_string = self::action($action,$source,$post);
// If they passed a span class
- if ($class) {
- $class_txt = ' class="' . $class . '"';
- }
+ if ($class) {
+ $class_txt = ' class="' . $class . '"';
+ }
- $string = get_user_icon($icon,$alt);
+ $string = get_user_icon($icon,$alt);
// Generate a <a> so that it's more compliant with older browsers
// (ie :hover actions) and also to unify linkbuttons (w/o ajax) display
- $string = "<a href=\"javascript:void(0);\" id=\"$source\" $class_txt>".$string."</a>\n";
+ $string = "<a href=\"javascript:void(0);\" id=\"$source\" $class_txt>".$string."</a>\n";
- $string .= self::observe($source,'click',$ajax_string);
+ $string .= self::observe($source,'click',$ajax_string);
return $string;
@@ -129,22 +129,22 @@ class Ajax {
* This prints out the specified text as a link and setups the required
* ajax for the link so it works correctly
*/
- public static function text($action,$text,$source,$post='',$class='') {
+ public static function text($action,$text,$source,$post='',$class='') {
// Format the string we wanna use
- $ajax_string = self::action($action,$source,$post);
+ $ajax_string = self::action($action,$source,$post);
// If they passed a span class
- if ($class) {
- $class_txt = ' class="' . $class . '"';
- }
+ if ($class) {
+ $class_txt = ' class="' . $class . '"';
+ }
// If we pass a source put it in the ID
- $string = "<a href=\"javascript:void(0);\" id=\"$source\" $class_txt>$text</a>\n";
+ $string = "<a href=\"javascript:void(0);\" id=\"$source\" $class_txt>$text</a>\n";
- $string .= self::observe($source,'click',$ajax_string);
+ $string .= self::observe($source,'click',$ajax_string);
- return $string;
+ return $string;
} // text
@@ -152,11 +152,11 @@ class Ajax {
* run
* This runs the specified action no questions asked
*/
- public static function run($action) {
+ public static function run($action) {
- echo "<script type=\"text/javascript\"><!--\n";
- echo "$action";
- echo "\n--></script>";
+ echo "<script type=\"text/javascript\"><!--\n";
+ echo "$action";
+ echo "\n--></script>";
} // run
@@ -164,22 +164,22 @@ class Ajax {
* set_include_override
* This sets the cinlduing div override, used only one place kind of a hack
*/
- public static function set_include_override($value) {
+ public static function set_include_override($value) {
- self::$include_override = make_bool($value);
+ self::$include_override = make_bool($value);
} // set_include_override
/**
* start_container
- * This checks to see if we're AJAX'in if we aren't then it echos out the
+ * This checks to see if we're AJAX'in if we aren't then it echos out the
* html needed to start a container that can be replaced by Ajax
*/
- public static function start_container($name) {
+ public static function start_container($name) {
- if (AJAX_INCLUDE == '1' AND !self::$include_override) { return true; }
+ if (AJAX_INCLUDE == '1' AND !self::$include_override) { return true; }
- echo '<div id="' . scrub_out($name) . '">';
+ echo '<div id="' . scrub_out($name) . '">';
} // start_container
@@ -187,13 +187,13 @@ class Ajax {
* end_container
* This ends the container if we're not doing the AJAX thing
*/
- public static function end_container() {
+ public static function end_container() {
- if (AJAX_INCLUDE == '1' AND !self::$include_override) { return true; }
+ if (AJAX_INCLUDE == '1' AND !self::$include_override) { return true; }
- echo "</div>";
+ echo "</div>";
- self::$include_override = false;
+ self::$include_override = false;
} // end_container
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index 144fcf4f..bf8c6d40 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -16,7 +16,7 @@
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.
*/
@@ -30,20 +30,20 @@ class Album extends database_object {
/* Variables from DB */
public $id;
public $name;
- public $full_name; // Prefix + Name, genereated by format();
- public $disk;
+ public $full_name; // Prefix + Name, genereated by format();
+ public $disk;
public $year;
public $prefix;
public $mbid; // MusicBrainz ID
/* Art Related Fields */
public $art;
- public $art_mime;
- public $thumb;
+ public $art_mime;
+ public $thumb;
public $thumb_mime;
// cached information
- public $_songs=array();
+ public $_songs=array();
/**
* __construct
@@ -54,20 +54,20 @@ class Album extends database_object {
*/
public function __construct($id='') {
- if (!$id) { return false; }
+ if (!$id) { return false; }
/* Get the information from the db */
$info = $this->get_info($id);
-
+
// Foreach what we've got
- foreach ($info as $key=>$value) {
- $this->$key = $value;
- }
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
// Little bit of formating here
$this->full_name = trim($info['prefix'] . ' ' . $info['name']);
- return true;
+ return true;
} // constructor
@@ -76,17 +76,17 @@ class Album extends database_object {
* This is often used by the metadata class, it fills out an album object from a
* named array, _fake is set to true
*/
- public static function construct_from_array($data) {
+ public static function construct_from_array($data) {
- $album = new Album(0);
- foreach ($data as $key=>$value) {
- $album->$key = $value;
- }
+ $album = new Album(0);
+ foreach ($data as $key=>$value) {
+ $album->$key = $value;
+ }
// Make sure that we tell em it's fake
- $album->_fake = true;
+ $album->_fake = true;
- return $album;
+ return $album;
} // construct_from_array
@@ -98,19 +98,19 @@ class Album extends database_object {
public static function build_cache($ids,$extra=false) {
// Nothing to do if they pass us nothing
- if (!is_array($ids) OR !count($ids)) { return false; }
+ if (!is_array($ids) OR !count($ids)) { return false; }
$idlist = '(' . implode(',', $ids) . ')';
$sql = "SELECT * FROM `album` WHERE `id` IN $idlist";
$db_results = Dba::read($sql);
-
+
while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('album',$row['id'],$row);
+ parent::add_to_cache('album',$row['id'],$row);
}
// If we're extra'ing cache the extra info as well
- if ($extra) {
+ if ($extra) {
$sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" .
",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id,`song`.`album`".
"FROM `song` " .
@@ -118,12 +118,12 @@ class Album extends database_object {
"LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " .
"WHERE `song`.`album` IN $idlist GROUP BY `song`.`album`";
- $db_results = Dba::read($sql);
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $row['has_art'] = make_bool($row['has_art']);
- $row['has_thumb'] = make_bool($row['has_thumb']);
- parent::add_to_cache('album_extra',$row['album'],$row);
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $row['has_art'] = make_bool($row['has_art']);
+ $row['has_thumb'] = make_bool($row['has_thumb']);
+ parent::add_to_cache('album_extra',$row['album'],$row);
} // while rows
} // if extra
@@ -136,28 +136,28 @@ class Album extends database_object {
* This pulls the extra information from our tables, this is a 3 table join, which is why we don't normally
* do it
*/
- private function _get_extra_info() {
+ private function _get_extra_info() {
- if (parent::is_cached('album_extra',$this->id)) {
- return parent::get_from_cache('album_extra',$this->id);
- }
+ if (parent::is_cached('album_extra',$this->id)) {
+ return parent::get_from_cache('album_extra',$this->id);
+ }
- $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" .
+ $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" .
",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id ".
"FROM `song` " .
"INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " .
- "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " .
+ "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " .
"WHERE `song`.`album`='$this->id' GROUP BY `song`.`album`";
- $db_results = Dba::read($sql);
+ $db_results = Dba::read($sql);
- $results = Dba::fetch_assoc($db_results);
+ $results = Dba::fetch_assoc($db_results);
- if ($results['has_art']) { $results['has_art'] = 1; }
- if ($results['has_thumb']) { $results['has_thumb'] = 1; }
+ if ($results['has_art']) { $results['has_art'] = 1; }
+ if ($results['has_thumb']) { $results['has_thumb'] = 1; }
- parent::add_to_cache('album_extra',$this->id,$results);
+ parent::add_to_cache('album_extra',$this->id,$results);
- return $results;
+ return $results;
} // _get_extra_info
@@ -167,19 +167,19 @@ class Album extends database_object {
* and an optional artist, if artist is passed it only gets
* songs with this album + specified artist
*/
- public function get_songs($limit = 0,$artist='') {
+ public function get_songs($limit = 0,$artist='') {
$results = array();
-
- if ($artist) {
+
+ if ($artist) {
$artist_sql = "AND `artist`='" . Dba::escape($artist) . "'";
- }
+ }
$sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' $artist_sql ORDER BY `track`, `title`";
if ($limit) { $sql .= " LIMIT $limit"; }
$db_results = Dba::read($sql);
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id'];
}
@@ -189,20 +189,20 @@ class Album extends database_object {
/**
* has_art
- * This returns true or false depending on if we find any art for this
- * album.
+ * This returns true or false depending on if we find any art for this
+ * album.
*/
- public function has_art() {
+ public function has_art() {
- $sql = "SELECT `album_id` FROM `album_data` WHERE `album_id`='" . $this->id . "' AND art IS NOT NULL";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `album_id` FROM `album_data` WHERE `album_id`='" . $this->id . "' AND art IS NOT NULL";
+ $db_results = Dba::read($sql);
- if (Dba::fetch_assoc($db_results)) {
- $this->has_art = true;
- return true;
- }
+ if (Dba::fetch_assoc($db_results)) {
+ $this->has_art = true;
+ return true;
+ }
- return false;
+ return false;
} // has_art
@@ -210,16 +210,16 @@ class Album extends database_object {
* has_track
* This checks to see if this album has a track of the specified title
*/
- public function has_track($title) {
+ public function has_track($title) {
- $title = Dba::escape($title);
+ $title = Dba::escape($title);
- $sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' AND `title`='$title'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' AND `title`='$title'";
+ $db_results = Dba::read($sql);
- $data = Dba::fetch_assoc($db_results);
+ $data = Dba::fetch_assoc($db_results);
- return $data;
+ return $data;
} // has_track
@@ -229,48 +229,48 @@ class Album extends database_object {
* album information with the base required
* f_link, f_name
*/
- public function format() {
+ public function format() {
$web_path = Config::get('web_path');
/* Pull the advanced information */
- $data = $this->_get_extra_info();
- foreach ($data as $key=>$value) { $this->$key = $value; }
-
+ $data = $this->_get_extra_info();
+ foreach ($data as $key=>$value) { $this->$key = $value; }
+
/* Truncate the string if it's to long */
$this->f_name = truncate_with_ellipsis($this->full_name,Config::get('ellipse_threshold_album'));
$this->f_name_link = "<a href=\"$web_path/albums.php?action=show&amp;album=" . scrub_out($this->id) . "\" title=\"" . scrub_out($this->full_name) . "\">" . $this->f_name;
// If we've got a disk append it
- if ($this->disk) {
+ if ($this->disk) {
$this->f_name_link .= " <span class=\"discnb disc" .$this->disk. "\">[" . _('Disk') . " " . $this->disk . "]</span>";
- }
+ }
$this->f_name_link .="</a>";
-
- $this->f_link = $this->f_name_link;
- $this->f_title = $full_name;
- if ($this->artist_count == '1') {
+
+ $this->f_link = $this->f_name_link;
+ $this->f_title = $full_name;
+ if ($this->artist_count == '1') {
$artist = scrub_out(truncate_with_ellipsis(trim($this->artist_prefix . ' ' . $this->artist_name),Config::get('ellipse_threshold_artist')));
$this->f_artist_link = "<a href=\"$web_path/artists.php?action=show&amp;artist=" . $this->artist_id . "\" title=\"" . scrub_out($this->artist_name) . "\">" . $artist . "</a>";
- $this->f_artist = $artist;
+ $this->f_artist = $artist;
}
else {
- $this->f_artist_link = "<span title=\"$this->artist_count " . _('Artists') . "\">" . _('Various') . "</span>";
+ $this->f_artist_link = "<span title=\"$this->artist_count " . _('Artists') . "\">" . _('Various') . "</span>";
$this->f_artist = _('Various');
}
- if ($this->year == '0') {
+ if ($this->year == '0') {
$this->year = "N/A";
}
- $tags = Tag::get_top_tags('album',$this->id);
- $this->tags = $tags;
+ $tags = Tag::get_top_tags('album',$this->id);
+ $this->tags = $tags;
+
+ $this->f_tags = Tag::get_display($tags,$this->id,'album');
- $this->f_tags = Tag::get_display($tags,$this->id,'album');
-
// Format the artist name to include the prefix
- $this->f_artist_name = trim($this->artist_prefix . ' ' . $this->artist_name);
+ $this->f_artist_name = trim($this->artist_prefix . ' ' . $this->artist_name);
} // format
@@ -280,15 +280,15 @@ class Album extends database_object {
* it trys to pull the resized art instead, if resized art is found then
* it returns an additional resized=true in the array
*/
- public function get_art($return_raw=false) {
+ public function get_art($return_raw=false) {
// Attempt to get the resized art first
- if (!$return_raw) {
- $art = $this->get_resized_db_art();
- }
-
- if (!is_array($art)) {
- $art = $this->get_db_art();
+ if (!$return_raw) {
+ $art = $this->get_resized_db_art();
+ }
+
+ if (!is_array($art)) {
+ $art = $this->get_db_art();
}
return $art['0'];
@@ -300,57 +300,57 @@ class Album extends database_object {
* This function searches for album art using all configured methods
* for the current album. There is an optional 'limit' passed that will
* gather up to the specified number of possible album covers.
- * There is also an optional array of options the possible options are
+ * There is also an optional array of options the possible options are
* ['keyword'] = STRING
* ['artist'] = STRING
* ['album_name'] = STRING
*/
- public function find_art($options=array(),$limit='') {
+ public function find_art($options=array(),$limit='') {
/* Create Base Vars */
- $results = array();
+ $results = array();
/* Attempt to retrive the album art order */
$config_value = Config::get('album_art_order');
- $class_methods = get_class_methods('Album');
-
+ $class_methods = get_class_methods('Album');
+
/* If it's not set */
- if (empty($config_value)) {
+ if (empty($config_value)) {
// They don't want art!
- return array();
+ return array();
}
- elseif (!is_array($config_value)) {
- $config_value = array($config_value);
+ elseif (!is_array($config_value)) {
+ $config_value = array($config_value);
}
-
- foreach ($config_value AS $method) {
-
- $data = array();
-
+
+ foreach ($config_value AS $method) {
+
+ $data = array();
+
$method_name = "get_" . $method . "_art";
- if (in_array($method_name,$class_methods)) {
+ if (in_array($method_name,$class_methods)) {
// Some of these take options!
- switch ($method_name) {
+ switch ($method_name) {
case 'get_amazon_art':
- $data = $this->{$method_name}($options['keyword'],$limit);
+ $data = $this->{$method_name}($options['keyword'],$limit);
break;
case 'get_lastfm_art':
- $data = $this->{$method_name}($limit,$options);
+ $data = $this->{$method_name}($limit,$options);
+ break;
+ case 'get_google_art':
+ $data = $this->{$method_name}($limit);
break;
- case 'get_google_art':
- $data = $this->{$method_name}($limit);
- break;
default:
- $data = $this->{$method_name}($limit);
- break;
- }
+ $data = $this->{$method_name}($limit);
+ break;
+ }
// Add the results we got to the current set
- $total_results += count($data);
- // HACK for PHP 5, $data must be cast as array $results = array_merge($results, (array)$data);
- $results = array_merge($results,(array)$data);
-
- if ($total_results > $limit AND $limit > 0) {
+ $total_results += count($data);
+ // HACK for PHP 5, $data must be cast as array $results = array_merge($results, (array)$data);
+ $results = array_merge($results,(array)$data);
+
+ if ($total_results > $limit AND $limit > 0) {
return $results;
}
@@ -358,28 +358,28 @@ class Album extends database_object {
} // end foreach
- return $results;
-
+ return $results;
+
} // find_art
/**
* get_lastfm_art
* This returns the art as pulled from lastFM. This doesn't require
- * a special account, we just parse and run with it.
+ * a special account, we just parse and run with it.
*/
- public function get_lastfm_art($limit,$options='') {
+ public function get_lastfm_art($limit,$options='') {
// Create the parser object
- $lastfm = new LastFMSearch();
+ $lastfm = new LastFMSearch();
- if (is_array($options)) {
+ if (is_array($options)) {
$artist = $options['artist'];
- $album = $options['album_name'];
- }
- else {
- $artist = $this->artist_name;
- $album = $this->full_name;
- }
+ $album = $options['album_name'];
+ }
+ else {
+ $artist = $this->artist_name;
+ $album = $this->full_name;
+ }
if(Config::get('proxy_host') AND Config::get('proxy_port')) {
$proxyhost = Config::get('proxy_host');
@@ -389,31 +389,31 @@ class Album extends database_object {
debug_event("lastfm", "set Proxy", "5");
$lastfm->setProxy($proxyhost, $proxyport, $proxyuser, $proxypass);
}
- $raw_data = $lastfm->album_search($artist,$album);
+ $raw_data = $lastfm->album_search($artist,$album);
- if (!count($raw_data)) { return array(); }
+ if (!count($raw_data)) { return array(); }
- $coverart = $raw_data['coverart'];
+ $coverart = $raw_data['coverart'];
- ksort($coverart);
-
- foreach ($coverart as $key=>$value) {
- $i++;
- $url = $coverart[$key];
+ ksort($coverart);
+
+ foreach ($coverart as $key=>$value) {
+ $i++;
+ $url = $coverart[$key];
// We need to check the URL for the /noimage/ stuff
- if (strstr($url,"/noimage/")) {
- debug_event('LastFM','Detected as noimage, skipped ' . $url,'3');
- continue;
- }
-
- $results = pathinfo($url);
- $mime = 'image/' . $results['extension'];
- $data[] = array('url'=>$url,'mime'=>$mime);
- if ($i >= $limit) { return $data; }
+ if (strstr($url,"/noimage/")) {
+ debug_event('LastFM','Detected as noimage, skipped ' . $url,'3');
+ continue;
+ }
+
+ $results = pathinfo($url);
+ $mime = 'image/' . $results['extension'];
+ $data[] = array('url'=>$url,'mime'=>$mime);
+ if ($i >= $limit) { return $data; }
} // end foreach
- return $data;
+ return $data;
} // get_lastfm_art
@@ -423,29 +423,29 @@ class Album extends database_object {
*/
public function get_google_art($limit='') {
$images = array();
-
+
$search = $this->full_name;
-
+
if ($this->artist_count == '1')
$search = $this->artist_name . ', ' . $search;
-
+
$search = rawurlencode($search);
-
+
//$size = ''; // Any
$size = '&imgsz=m'; // Medium
//$size = '&imgsz=l'; // Large
-
+
$html = file_get_contents("http://images.google.com/images?source=hp&q=$search&oq=&um=1&ie=UTF-8&sa=N&tab=wi&start=0&tbo=1$size");
-
+
if(preg_match_all("|\ssrc\=\"(http.+?)\"|", $html, $matches, PREG_PATTERN_ORDER))
foreach ($matches[1] as $match) {
$extension = "image/jpeg";
-
+
if (strrpos($extension, '.') !== false) $extension = substr($extension, strrpos($extension, '.') + 1);
-
+
$images[] = array('url' => $match, 'mime' => $extension);
}
-
+
return $images;
} // get_google_art
@@ -453,39 +453,39 @@ class Album extends database_object {
@function get_id3_art
@discussion looks for art from the id3 tags
*/
- function get_id3_art($limit='') {
+ function get_id3_art($limit='') {
// grab the songs and define our results
- if (!count($this->_songs)) {
- $this->_songs = $this->get_songs();
- }
- $data = array();
+ if (!count($this->_songs)) {
+ $this->_songs = $this->get_songs();
+ }
+ $data = array();
// Foreach songs in this album
- foreach ($this->_songs as $song_id) {
- $song = new Song($song_id);
+ foreach ($this->_songs as $song_id) {
+ $song = new Song($song_id);
// If we find a good one, stop looking
$getID3 = new getID3();
- try { $id3 = $getID3->analyze($song->file); }
- catch (Exception $error) {
- debug_event('getid3',$error->message,'1');
- }
+ try { $id3 = $getID3->analyze($song->file); }
+ catch (Exception $error) {
+ debug_event('getid3',$error->message,'1');
+ }
- if ($id3['format_name'] == "WMA") {
+ if ($id3['format_name'] == "WMA") {
$image = $id3['asf']['extended_content_description_object']['content_descriptors']['13'];
$data[] = array('song'=>$song->file,'raw'=>$image['data'],'mime'=>$image['mime']);
}
- elseif (isset($id3['id3v2']['APIC'])) {
- // Foreach incase they have more then one
- foreach ($id3['id3v2']['APIC'] as $image) {
+ elseif (isset($id3['id3v2']['APIC'])) {
+ // Foreach incase they have more then one
+ foreach ($id3['id3v2']['APIC'] as $image) {
$data[] = array('song'=>$song->file,'raw'=>$image['data'],'mime'=>$image['mime']);
- }
+ }
}
- if (!empty($limit) && $limit < count($data)) {
- return $data;
+ if (!empty($limit) && $limit < count($data)) {
+ return $data;
}
-
+
} // end foreach
return $data;
@@ -498,32 +498,32 @@ class Album extends database_object {
* If a limit is passed or the preferred filename is found the current results set
* is returned
*/
- function get_folder_art($limit='') {
+ function get_folder_art($limit='') {
- if (!count($this->_songs)) {
+ if (!count($this->_songs)) {
$this->_songs = $this->get_songs();
- }
- $data = array();
+ }
+ $data = array();
/* See if we are looking for a specific filename */
$preferred_filename = Config::get('album_art_preferred_filename');
// Init a horrible hack array of lameness
- $cache =array();
-
+ $cache =array();
+
/* Thanks to dromio for origional code */
/* Added search for any .jpg, png or .gif - Vollmer */
- foreach($this->_songs as $song_id) {
+ foreach($this->_songs as $song_id) {
$song = new Song($song_id);
$dir = dirname($song->file);
- debug_event('folder_art',"Opening $dir and checking for Album Art",'3');
+ debug_event('folder_art',"Opening $dir and checking for Album Art",'3');
/* Open up the directory */
$handle = @opendir($dir);
if (!is_resource($handle)) {
- Error::add('general',_('Error: Unable to open') . ' ' . $dir);
+ Error::add('general',_('Error: Unable to open') . ' ' . $dir);
debug_event('read',"Error: Unable to open $dir for album art read",'2');
}
@@ -532,18 +532,18 @@ class Album extends database_object {
$extension = substr($file,strlen($file)-3,4);
/* If it's an image file */
- if ($extension == "jpg" || $extension == "gif" || $extension == "png" || $extension == "jp2" || $extension == "bmp") {
+ if ($extension == "jpg" || $extension == "gif" || $extension == "png" || $extension == "jp2" || $extension == "bmp") {
- if ($extension == 'jpg') { $extension = 'jpeg'; }
+ if ($extension == 'jpg') { $extension = 'jpeg'; }
// HACK ALERT this is to prevent duplicate filenames
- $full_filename = $dir . '/' . $file;
- $index = md5($full_filename);
+ $full_filename = $dir . '/' . $file;
+ $index = md5($full_filename);
/* Make sure it's got something in it */
- if (!filesize($dir . '/' . $file)) { continue; }
+ if (!filesize($dir . '/' . $file)) { continue; }
- if ($file == $preferred_filename) {
+ if ($file == $preferred_filename) {
// If we found the preferred filename we're done, wipe out previous results
$data = array(array('file' => $full_filename, 'mime' => 'image/' . $extension));
return $data;
@@ -551,17 +551,17 @@ class Album extends database_object {
elseif (!isset($cache[$index])) {
$data[] = array('file' => $full_filename, 'mime' => 'image/' . $extension);
}
-
- $cache[$index] = '1';
-
+
+ $cache[$index] = '1';
+
} // end if it's an image
-
+
} // end while reading dir
@closedir($handle);
-
- if (!empty($limit) && $limit < count($data)) {
- return $data;
- }
+
+ if (!empty($limit) && $limit < count($data)) {
+ return $data;
+ }
} // end foreach songs
@@ -574,18 +574,18 @@ class Album extends database_object {
* This looks to see if we have a resized thumbnail that we can load rather then taking
* the fullsized and resizing that
*/
- public function get_resized_db_art() {
+ public function get_resized_db_art() {
- $id = Dba::escape($this->id);
+ $id = Dba::escape($this->id);
$sql = "SELECT `thumb` AS `art`,`thumb_mime` AS `art_mime` FROM `album_data` WHERE `album_id`='$id'";
- $db_results = Dba::read($sql);
-
- $results = Dba::fetch_assoc($db_results);
- if (strlen($results['art_mime'])) {
- $results['resized'] = true;
- }
- else { return false; }
+ $db_results = Dba::read($sql);
+
+ $results = Dba::fetch_assoc($db_results);
+ if (strlen($results['art_mime'])) {
+ $results['resized'] = true;
+ }
+ else { return false; }
$data = array(array('db_resized'=>$this->id,'raw'=>$results['art'],'mime'=>$results['art_mime']));
@@ -604,10 +604,10 @@ class Album extends database_object {
$results = Dba::fetch_assoc($db_results);
- if (!$results['art']) { return array(); }
+ if (!$results['art']) { return array(); }
+
+ $data = array(array('db'=>$this->id,'raw'=>$results['art'],'mime'=>$results['art_mime']));
- $data = array(array('db'=>$this->id,'raw'=>$results['art'],'mime'=>$results['art_mime']));
-
return $data;
} // get_db_art
@@ -672,7 +672,7 @@ class Album extends database_object {
}
// The next bit is based directly on the MusicBrainz server code that displays cover art.
- // I'm leaving in the releaseuri info for the moment, though it's not going to be used.
+ // I'm leaving in the releaseuri info for the moment, though it's not going to be used.
$coverartsites[] = array(
name => "CD Baby",
domain => "cdbaby.com",
@@ -729,7 +729,7 @@ class Album extends database_object {
imguri => '$matches[1]',
releaseuri => '',
);
-
+
foreach ($release->getRelations($mbRelation->TO_URL) as $ar) {
$arurl = $ar->getTargetId();
debug_event('mbz-gatherart', "Found URL AR: " . $arurl , '5');
@@ -766,16 +766,16 @@ class Album extends database_object {
$images = array();
$final_results = array();
$possible_keys = array("LargeImage","MediumImage","SmallImage");
-
+
// Prevent the script from timing out
set_time_limit(0);
- if (empty($keywords)) {
+ if (empty($keywords)) {
$keywords = $this->full_name;
/* If this isn't a various album combine with artist name */
if ($this->artist_count == '1') { $keywords .= ' ' . $this->artist_name; }
}
-
+
/* Create Base Vars */
$amazon_base_urls = array();
@@ -783,18 +783,18 @@ class Album extends database_object {
$config_value = Config::get('amazon_base_urls');
/* If it's not set */
- if (empty($config_value)) {
+ if (empty($config_value)) {
$amazon_base_urls = array('http://webservices.amazon.com');
}
- elseif (!is_array($config_value)) {
+ elseif (!is_array($config_value)) {
array_push($amazon_base_urls,$config_value);
}
- else {
+ else {
$amazon_base_urls = array_merge($amazon_base_urls, Config::get('amazon_base_urls'));
}
/* Foreach through the base urls that we should check */
- foreach ($amazon_base_urls AS $amazon_base) {
+ foreach ($amazon_base_urls AS $amazon_base) {
// Create the Search Object
$amazon = new AmazonSearch(Config::get('amazon_developer_public_key'), Config::get('amazon_developer_private_key'), $amazon_base);
@@ -813,24 +813,24 @@ class Album extends database_object {
$max_pages_to_search = max(Config::get('max_amazon_results_pages'),$amazon->_default_results_pages);
$pages_to_search = $max_pages_to_search; //init to max until we know better.
- // while we have pages to search
+ // while we have pages to search
do {
- $raw_results = $amazon->search(array('artist'=>$artist,'album'=>$albumname,'keywords'=>$keywords));
+ $raw_results = $amazon->search(array('artist'=>$artist,'album'=>$albumname,'keywords'=>$keywords));
- $total = count($raw_results) + count($search_results);
+ $total = count($raw_results) + count($search_results);
// If we've gotten more then we wanted
- if (!empty($limit) && $total > $limit) {
+ if (!empty($limit) && $total > $limit) {
// We don't want ot re-count every loop
- $i = $total;
- while ($i > $limit) {
- array_pop($raw_results);
+ $i = $total;
+ while ($i > $limit) {
+ array_pop($raw_results);
$i--;
- }
+ }
- debug_event('amazon-xml',"Found $total, Limit $limit reducing and breaking from loop",'5');
+ debug_event('amazon-xml',"Found $total, Limit $limit reducing and breaking from loop",'5');
// Merge the results and BREAK!
- $search_results = array_merge($search_results,$raw_results);
+ $search_results = array_merge($search_results,$raw_results);
break;
} // if limit defined
@@ -840,10 +840,10 @@ class Album extends database_object {
$amazon->_currentPage++;
} while($amazon->_currentPage < $pages_to_search);
-
+
// Only do the second search if the first actually returns something
- if (count($search_results)) {
+ if (count($search_results)) {
$final_results = $amazon->lookup($search_results);
}
@@ -851,30 +851,30 @@ class Album extends database_object {
debug_event('amazon-xml',"Searched using $keywords with " . Config::get('amazon_developer_key') . " as key " . count($final_results) . " results found",'5');
// If we've hit our limit
- if (!empty($limit) && count($final_results) >= $limit) {
- break;
- }
-
+ if (!empty($limit) && count($final_results) >= $limit) {
+ break;
+ }
+
} // end foreach
/* Foreach through what we've found */
- foreach ($final_results as $result) {
+ foreach ($final_results as $result) {
/* Recurse through the images found */
- foreach ($possible_keys as $key) {
- if (strlen($result[$key])) {
+ foreach ($possible_keys as $key) {
+ if (strlen($result[$key])) {
break;
- }
+ }
} // foreach
// Rudimentary image type detection, only JPG and GIF allowed.
if (substr($result[$key], -4 == '.jpg')) {
$mime = "image/jpeg";
}
- elseif (substr($result[$key], -4 == '.gif')) {
+ elseif (substr($result[$key], -4 == '.gif')) {
$mime = "image/gif";
}
- elseif (substr($result[$key], -4 == '.png')) {
+ elseif (substr($result[$key], -4 == '.png')) {
$mime = "image/png";
}
else {
@@ -884,31 +884,31 @@ class Album extends database_object {
$data['url'] = $result[$key];
$data['mime'] = $mime;
-
+
$images[] = $data;
- if (!empty($limit)) {
- if (count($images) >= $limit) {
- return $images;
- }
- }
+ if (!empty($limit)) {
+ if (count($images) >= $limit) {
+ return $images;
+ }
+ }
} // if we've got something
-
+
return $images;
- } // get_amazon_art
+ } // get_amazon_art
/**
* get_random_songs
* gets a random number, and a random assortment of songs from this album
*/
- function get_random_songs() {
+ function get_random_songs() {
$sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' ORDER BY RAND()";
$db_results = Dba::read($sql);
- while ($r = Dba::fetch_row($db_results)) {
+ while ($r = Dba::fetch_row($db_results)) {
$results[] = $r['0'];
}
@@ -921,49 +921,49 @@ class Album extends database_object {
* This function takes a key'd array of data and updates this object
* as needed, and then throws down with a flag
*/
- public function update($data) {
+ public function update($data) {
- $year = $data['year'];
- $artist = $data['artist'];
- $name = $data['name'];
+ $year = $data['year'];
+ $artist = $data['artist'];
+ $name = $data['name'];
$disk = $data['disk'];
- $mbid = $data['mbid'];
+ $mbid = $data['mbid'];
- $current_id = $this->id;
+ $current_id = $this->id;
- if ($artist != $this->artist_id AND $artist) {
+ if ($artist != $this->artist_id AND $artist) {
// Update every song
- $songs = $this->get_songs();
- foreach ($songs as $song_id) {
- Song::update_artist($artist,$song_id);
- }
- $updated = 1;
- Catalog::clean_artists();
- }
-
- $album_id = Catalog::check_album($name,$year,$disk,$mbid);
- if ($album_id != $this->id) {
- if (!is_array($songs)) { $songs = $this->get_songs(); }
- foreach ($songs as $song_id) {
- Song::update_album($album_id,$song_id);
+ $songs = $this->get_songs();
+ foreach ($songs as $song_id) {
+ Song::update_artist($artist,$song_id);
+ }
+ $updated = 1;
+ Catalog::clean_artists();
+ }
+
+ $album_id = Catalog::check_album($name,$year,$disk,$mbid);
+ if ($album_id != $this->id) {
+ if (!is_array($songs)) { $songs = $this->get_songs(); }
+ foreach ($songs as $song_id) {
+ Song::update_album($album_id,$song_id);
Song::update_year($year,$song_id);
- }
- $current_id = $album_id;
- $updated = 1;
- Catalog::clean_albums();
- }
+ }
+ $current_id = $album_id;
+ $updated = 1;
+ Catalog::clean_albums();
+ }
- if ($updated) {
+ if ($updated) {
// Flag all songs
- foreach ($songs as $song_id) {
- Flag::add($song_id,'song','retag','Interface Album Update');
- Song::update_utime($song_id);
+ foreach ($songs as $song_id) {
+ Flag::add($song_id,'song','retag','Interface Album Update');
+ Song::update_utime($song_id);
} // foreach song of album
- Catalog::clean_stats();
+ Catalog::clean_stats();
} // if updated
- return $current_id;
+ return $current_id;
} // update
@@ -971,8 +971,8 @@ class Album extends database_object {
* clear_art
* clears the album art from the DB
*/
- public function clear_art() {
-
+ public function clear_art() {
+
$sql = "UPDATE `album_data` SET `art`=NULL, `art_mime`=NULL, `thumb`=NULL, `thumb_mime`=NULL WHERE `album_id`='$this->id'";
$db_results = Dba::write($sql);
@@ -983,12 +983,12 @@ class Album extends database_object {
* this takes a string representation of an image
* and inserts it into the database. You must pass the mime type as well
*/
- public function insert_art($image, $mime) {
+ public function insert_art($image, $mime) {
/* Have to disable this for Demo because people suck and try to
- * insert PORN :(
+ * insert PORN :(
*/
- if (Config::get('demo_mode')) { return false; }
+ if (Config::get('demo_mode')) { return false; }
// Check for PHP:GD and if we have it make sure this image is of some size
if (function_exists('ImageCreateFromString')) {
@@ -997,17 +997,17 @@ class Album extends database_object {
return false;
}
} // if we have PHP:GD
- elseif (strlen($image) < 5) {
- return false;
- }
+ elseif (strlen($image) < 5) {
+ return false;
+ }
// Default to image/jpeg as a guess if there is no passed mime type
- $mime = $mime ? $mime : 'image/jpeg';
+ $mime = $mime ? $mime : 'image/jpeg';
// Push the image into the database
$sql = "REPLACE INTO `album_data` SET `art` = '" . Dba::escape($image) . "'," .
" `art_mime` = '" . Dba::escape($mime) . "'" .
- ", `album_id` = '$this->id'," .
+ ", `album_id` = '$this->id'," .
"`thumb` = NULL, `thumb_mime`=NULL";
$db_results = Dba::write($sql);
@@ -1020,18 +1020,18 @@ class Album extends database_object {
* This takes data from a gd resize operation and saves
* it back into the database as a thumbnail
*/
- public static function save_resized_art($data,$mime,$album) {
+ public static function save_resized_art($data,$mime,$album) {
// Make sure there's actually something to save
- if (strlen($data) < '5') { return false; }
+ if (strlen($data) < '5') { return false; }
- $data = Dba::escape($data);
- $mime = Dba::escape($mime);
- $album = Dba::escape($album);
+ $data = Dba::escape($data);
+ $mime = Dba::escape($mime);
+ $album = Dba::escape($album);
- $sql = "UPDATE `album_data` SET `thumb`='$data',`thumb_mime`='$mime' " .
+ $sql = "UPDATE `album_data` SET `thumb`='$data',`thumb_mime`='$mime' " .
"WHERE `album_data`.`album_id`='$album'";
- $db_results = Dba::write($sql);
+ $db_results = Dba::write($sql);
} // save_resized_art
@@ -1063,18 +1063,18 @@ class Album extends database_object {
while ($row = Dba::fetch_assoc($db_results)) {
$results[$row['album_id']] = $row['no_art'];
} // end for
-
+
asort($results);
$albums = array_keys($results);
$results = array_slice($albums,0,$count);
-
+
return $results;
} // get_random_albums
/**
* get_image_from_source
- * This gets an image for the album art from a source as
+ * This gets an image for the album art from a source as
* defined in the passed array. Because we don't know where
* its comming from we are a passed an array that can look like
* ['url'] = URL *** OPTIONAL ***
@@ -1090,7 +1090,7 @@ class Album extends database_object {
// If it came from the database
if (isset($data['db'])) {
- // Repull it
+ // Repull it
$album_id = Dba::escape($data['db']);
$sql = "SELECT * FROM `album_data` WHERE `album_id`='$album_id'";
$db_results = Dba::read($sql);
@@ -1118,18 +1118,18 @@ class Album extends database_object {
fclose($handle);
return $image_data;
}
-
+
// Check to see if it is embedded in id3 of a song
if (isset($data['song'])) {
// If we find a good one, stop looking
$getID3 = new getID3();
$id3 = $getID3->analyze($data['song']);
-
+
if ($id3['format_name'] == "WMA") {
return $id3['asf']['extended_content_description_object']['content_descriptors']['13']['data'];
}
elseif (isset($id3['id3v2']['APIC'])) {
- // Foreach incase they have more then one
+ // Foreach incase they have more then one
foreach ($id3['id3v2']['APIC'] as $image) {
return $image['data'];
}
@@ -1144,35 +1144,35 @@ class Album extends database_object {
* get_art_url
* This returns the art URL for the album
*/
- public static function get_art_url($album_id,$sid=false) {
+ public static function get_art_url($album_id,$sid=false) {
- $sid = $sid ? scrub_out($sid) : session_id();
+ $sid = $sid ? scrub_out($sid) : session_id();
- $sql = "SELECT `art_mime`,`thumb_mime` FROM `album_data` WHERE `album_id`='" . Dba::escape($album_id) . "'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `art_mime`,`thumb_mime` FROM `album_data` WHERE `album_id`='" . Dba::escape($album_id) . "'";
+ $db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
+ $row = Dba::fetch_assoc($db_results);
- $mime = $row['thumb_mime'] ? $row['thumb_mime'] : $row['art_mime'];
+ $mime = $row['thumb_mime'] ? $row['thumb_mime'] : $row['art_mime'];
- switch ($type) {
- case 'image/gif':
- $type = 'gif';
- break;
- case 'image/png':
- $type = 'png';
- break;
+ switch ($type) {
+ case 'image/gif':
+ $type = 'gif';
+ break;
+ case 'image/png':
+ $type = 'png';
+ break;
default:
- case 'image/jpeg':
- $type = 'jpg';
- break;
+ case 'image/jpeg':
+ $type = 'jpg';
+ break;
} // end type translation
- $name = 'art.' . $type;
+ $name = 'art.' . $type;
$url = Config::get('web_path') . '/image.php?id=' . scrub_out($album_id) . '&auth=' . $sid . '&name=' . $name;
- return $url;
+ return $url;
} // get_art_url
diff --git a/lib/class/ampacherss.class.php b/lib/class/ampacherss.class.php
index 8276bf77..897601bc 100644
--- a/lib/class/ampacherss.class.php
+++ b/lib/class/ampacherss.class.php
@@ -17,7 +17,7 @@
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.
*/
@@ -28,17 +28,17 @@
*/
class AmpacheRSS {
- private $type;
- public $data;
+ private $type;
+ public $data;
/**
* Constructor
* This takes a flagged.id and then pulls in the information for said flag entry
*/
- public function __construct($type) {
+ public function __construct($type) {
+
+ $this->type = self::validate_type($type);
- $this->type = self::validate_type($type);
-
} // constructor
/**
@@ -46,19 +46,19 @@ class AmpacheRSS {
* This returns the xmldocument for the current rss type, it calls a sub function that gathers the data
* and then uses the xmlDATA class to build the document
*/
- public function get_xml() {
+ public function get_xml() {
// Function call name
- $data_function = 'load_' . $this->type;
- $pub_date_function = 'pubdate_' . $this->type;
+ $data_function = 'load_' . $this->type;
+ $pub_date_function = 'pubdate_' . $this->type;
- $data = call_user_func(array('AmpacheRSS',$data_function));
- $pub_date = call_user_func(array('AmpacheRSS',$pub_date_function));
+ $data = call_user_func(array('AmpacheRSS',$data_function));
+ $pub_date = call_user_func(array('AmpacheRSS',$pub_date_function));
- xmlData::set_type('rss');
- $xml_document = xmlData::rss_feed($data,$this->get_title(),$this->get_description(),$pub_date);
+ xmlData::set_type('rss');
+ $xml_document = xmlData::rss_feed($data,$this->get_title(),$this->get_description(),$pub_date);
- return $xml_document;
+ return $xml_document;
} // get_xml
@@ -66,14 +66,14 @@ class AmpacheRSS {
* get_title
* This returns the standardized title for the rss feed based on this->type
*/
- public function get_title() {
+ public function get_title() {
$titles = array('now_playing'=>_('Now Playing'),
'recently_played'=>_('Recently Played'),
'latest_album'=>_('Newest Albums'),
- 'latest_artist'=>_('Newest Artists'));
+ 'latest_artist'=>_('Newest Artists'));
- return scrub_out(Config::get('site_title')) . ' - ' . $titles[$this->type];
+ return scrub_out(Config::get('site_title')) . ' - ' . $titles[$this->type];
} // get_title
@@ -81,10 +81,10 @@ class AmpacheRSS {
* get_description
* This returns the standardized description for the rss feed based on this->type
*/
- public function get_description() {
+ public function get_description() {
//FIXME: For now don't do any kind of translating
- return 'Ampache RSS Feeds';
+ return 'Ampache RSS Feeds';
} // get_description
@@ -92,16 +92,16 @@ class AmpacheRSS {
* validate_type
* this returns a valid type for an rss feed, if the specified type is invalid it returns a default value
*/
- public static function validate_type($type) {
+ public static function validate_type($type) {
$valid_types = array('now_playing','recently_played','latest_album','latest_artist','latest_song',
- 'popular_song','popular_album','popular_artist');
-
- if (!in_array($type,$valid_types)) {
- return 'now_playing';
- }
+ 'popular_song','popular_album','popular_artist');
+
+ if (!in_array($type,$valid_types)) {
+ return 'now_playing';
+ }
- return $type;
+ return $type;
} // validate_type
@@ -109,14 +109,14 @@ class AmpacheRSS {
* get_display
* This dumps out some html and an icon for the type of rss that we specify
*/
- public static function get_display($type='now_playing') {
+ public static function get_display($type='now_playing') {
// Default to now playing
- $type = self::validate_type($type);
+ $type = self::validate_type($type);
- $string = '<a href="' . Config::get('web_path') . '/rss.php?type=' . $type . '">' . get_user_icon('feed',_('RSS Feed')) . '</a>';
+ $string = '<a href="' . Config::get('web_path') . '/rss.php?type=' . $type . '">' . get_user_icon('feed',_('RSS Feed')) . '</a>';
- return $string;
+ return $string;
} // get_display
@@ -127,41 +127,41 @@ class AmpacheRSS {
* This loads in the now playing information. This is just the raw data with key=>value pairs that could be turned
* into an xml document if we so wished
*/
- public static function load_now_playing() {
+ public static function load_now_playing() {
- $data = Stream::get_now_playing();
+ $data = Stream::get_now_playing();
- $results = array();
+ $results = array();
- foreach ($data as $element) {
- $song = $element['media'];
- $client = $element['user'];
+ foreach ($data as $element) {
+ $song = $element['media'];
+ $client = $element['user'];
$xml_array = array('title'=>$song->f_title . ' - ' . $song->f_artist . ' - ' . $song->f_album,
'link'=>$song->link,
'description'=>$song->title . ' - ' . $song->f_artist_full . ' - ' . $song->f_album_full,
'comments'=>$client->fullname . ' - ' . $element['agent'],
'pubDate'=>date("r",$element['expire'])
- );
- $results[] = $xml_array;
- } // end foreach
+ );
+ $results[] = $xml_array;
+ } // end foreach
- return $results;
+ return $results;
} // load_now_playing
/**
* pubdate_now_playing
- * this is the pub date we should use for the now playing information,
+ * this is the pub date we should use for the now playing information,
* this is a little specific as it uses the 'newest' expire we can find
*/
- public static function pubdate_now_playing() {
+ public static function pubdate_now_playing() {
// Little redundent, should be fixed by an improvement in the get_now_playing stuff
- $data = Stream::get_now_playing();
+ $data = Stream::get_now_playing();
- $element = array_shift($data);
+ $element = array_shift($data);
- return $element['expire'];
+ return $element['expire'];
} // pubdate_now_playing
@@ -169,21 +169,21 @@ class AmpacheRSS {
* load_recently_played
* This loads in the recently played information and formats it up real nice like
*/
- public static function load_recently_played() {
+ public static function load_recently_played() {
//FIXME: The time stuff should be centralized, it's currently in two places, lame
$time_unit = array('',_('seconds ago'),_('minutes ago'),_('hours ago'),_('days ago'),_('weeks ago'),_('months ago'),_('years ago'));
- $data = Song::get_recently_played();
+ $data = Song::get_recently_played();
- $results = array();
+ $results = array();
- foreach ($data as $item) {
- $client = new User($item['user']);
- $song = new Song($item['object_id']);
- $song->format();
- $amount = intval(time() - $item['date']+2);
- $time_place = '0';
+ foreach ($data as $item) {
+ $client = new User($item['user']);
+ $song = new Song($item['object_id']);
+ $song->format();
+ $amount = intval(time() - $item['date']+2);
+ $time_place = '0';
while ($amount >= 1) {
$final = $amount;
$time_place++;
@@ -205,7 +205,7 @@ class AmpacheRSS {
if ($time_place > '6') {
$final = $amount . '+';
break;
- }
+ }
} // end while
$time_string = $final . ' ' . $time_unit[$time_place];
@@ -214,12 +214,12 @@ class AmpacheRSS {
'link'=>str_replace('&amp;', '&', $song->link),
'description'=>$song->title . ' - ' . $song->f_artist_full . ' - ' . $song->f_album_full . ' - ' . $time_string,
'comments'=>$client->username,
- 'pubDate'=>date("r",$item['date']));
- $results[] = $xml_array;
+ 'pubDate'=>date("r",$item['date']));
+ $results[] = $xml_array;
- } // end foreach
+ } // end foreach
- return $results;
+ return $results;
} // load_recently_played
@@ -227,13 +227,13 @@ class AmpacheRSS {
* pubdate_recently_played
* This just returns the 'newest' recently played entry
*/
- public static function pubdate_recently_played() {
+ public static function pubdate_recently_played() {
- $data = Song::get_recently_played();
+ $data = Song::get_recently_played();
$element = array_shift($data);
-
- return $element['date'];
+
+ return $element['date'];
} // pubdate_recently_played
diff --git a/lib/class/api.class.php b/lib/class/api.class.php
index fecab380..5c2575fd 100644
--- a/lib/class/api.class.php
+++ b/lib/class/api.class.php
@@ -25,15 +25,15 @@
* This handles functions relating to the API written for ampache, initially this is very focused
* on providing functionality for Amarok so it can integrate with Ampache
*/
-class Api {
+class Api {
+
+ public static $version = '350001';
- public static $version = '350001';
-
/**
* constructor
* This really isn't anything to do here, so it's private
*/
- private function __construct() {
+ private function __construct() {
// Rien a faire
@@ -45,12 +45,12 @@ class Api {
* and vastly simplier way to the end users so we have to do a little handy work to make them
* work internally
*/
- public static function set_filter($filter,$value) {
+ public static function set_filter($filter,$value) {
- if (!strlen($value)) { return false; }
+ if (!strlen($value)) { return false; }
- switch ($filter) {
- case 'add':
+ switch ($filter) {
+ case 'add':
// Check for a range, if no range default to gt
if (strpos('/',$value)) {
$elements = explode('/',$value);
@@ -60,30 +60,30 @@ class Api {
else {
Browse::set_filter('add_gt',strtotime($value));
}
- break;
- case 'update':
+ break;
+ case 'update':
// Check for a range, if no range default to gt
- if (strpos('/',$value)) {
- $elements = explode('/',$value);
- Browse::set_filter('update_lt',strtotime($elements['1']));
- Browse::set_filter('update_gt',strtotime($elements['0']));
+ if (strpos('/',$value)) {
+ $elements = explode('/',$value);
+ Browse::set_filter('update_lt',strtotime($elements['1']));
+ Browse::set_filter('update_gt',strtotime($elements['0']));
}
- else {
- Browse::set_filter('update_gt',strtotime($value));
+ else {
+ Browse::set_filter('update_gt',strtotime($value));
}
- break;
+ break;
case 'alpha_match':
- Browse::set_filter('alpha_match',$value);
- break;
- case 'exact_match':
+ Browse::set_filter('alpha_match',$value);
+ break;
+ case 'exact_match':
Browse::set_filter('exact_match',$value);
- break;
- default:
+ break;
+ default:
// Rien a faire
- break;
+ break;
} // end filter
- return true;
+ return true;
} // set_filter
@@ -91,106 +91,106 @@ class Api {
* handshake
* This is the function that handles the verifying a new handshake
* this takes a timestamp, auth key, and client IP. Optionally it
- * can take a username, if non is passed the ACL must be non-use
+ * can take a username, if non is passed the ACL must be non-use
* specific
*/
- public static function handshake($input) {
+ public static function handshake($input) {
- $timestamp = $input['timestamp'];
- $passphrase = $input['auth'];
- $ip = $_SERVER['REMOTE_ADDR'];
- $username = $input['user'];
- $version = $input['version'];
+ $timestamp = $input['timestamp'];
+ $passphrase = $input['auth'];
+ $ip = $_SERVER['REMOTE_ADDR'];
+ $username = $input['user'];
+ $version = $input['version'];
// Let them know we're attempting
- debug_event('API',"Attempting Handshake IP:$ip User:$username Version:$version",'5');
+ debug_event('API',"Attempting Handshake IP:$ip User:$username Version:$version",'5');
- if (intval($version) < self::$version) {
- debug_event('API','Login Failed version too old','1');
- Error::add('api','Login Failed version too old');
- return false;
- }
+ if (intval($version) < self::$version) {
+ debug_event('API','Login Failed version too old','1');
+ Error::add('api','Login Failed version too old');
+ return false;
+ }
// If the timestamp is over 2hr old sucks to be them
- if ($timestamp < (time() - 14400)) {
- debug_event('API','Login Failed, timestamp too old','1');
- Error::add('api','Login Failed, timestamp too old');
- return false;
- }
-
- // First we'll filter by username and IP
- if (!trim($username)) {
- $user_id = '-1';
- }
- else {
- $client = User::get_from_username($username);
- $user_id =$client->id;
- }
+ if ($timestamp < (time() - 14400)) {
+ debug_event('API','Login Failed, timestamp too old','1');
+ Error::add('api','Login Failed, timestamp too old');
+ return false;
+ }
+
+ // First we'll filter by username and IP
+ if (!trim($username)) {
+ $user_id = '-1';
+ }
+ else {
+ $client = User::get_from_username($username);
+ $user_id =$client->id;
+ }
// Clean incomming variables
- $user_id = Dba::escape($user_id);
- $timestamp = intval($timestamp);
+ $user_id = Dba::escape($user_id);
+ $timestamp = intval($timestamp);
$ip = inet_pton($ip);
// Log this attempt
- debug_event('API','Login Attempt, IP:' . inet_ntop($ip) . ' Time:' . $timestamp . ' User:' . $username . '(' . $user_id . ') Auth:' . $passphrase,'1');
+ debug_event('API','Login Attempt, IP:' . inet_ntop($ip) . ' Time:' . $timestamp . ' User:' . $username . '(' . $user_id . ') Auth:' . $passphrase,'1');
+
+ $ip = Dba::escape($ip);
- $ip = Dba::escape($ip);
-
// Run the query and return the passphrases as we'll have to mangle them
// to figure out if they match what we've got
- $sql = "SELECT * FROM `access_list` " .
- "WHERE `type`='rpc' AND (`user`='$user_id' OR `access_list`.`user`='-1') " .
- "AND `start` <= '$ip' AND `end` >= '$ip'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `access_list` " .
+ "WHERE `type`='rpc' AND (`user`='$user_id' OR `access_list`.`user`='-1') " .
+ "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)) {
- // Now we're sure that there is an ACL line that matches this user or ALL USERS,
- // pull the users password and then see what we come out with
- $sql = "SELECT * FROM `user` WHERE `id`='$user_id'";
- $user_results = Dba::read($sql);
+ // Now we're sure that there is an ACL line that matches this user or ALL USERS,
+ // pull the users password and then see what we come out with
+ $sql = "SELECT * FROM `user` WHERE `id`='$user_id'";
+ $user_results = Dba::read($sql);
- $row = Dba::fetch_assoc($user_results);
+ $row = Dba::fetch_assoc($user_results);
- if (!$row['password']) {
- debug_event('API','Unable to find user with username of ' . $user_id,'1');
- Error::add('api','Invalid Username/Password');
- return false;
- }
+ if (!$row['password']) {
+ debug_event('API','Unable to find user with username of ' . $user_id,'1');
+ Error::add('api','Invalid Username/Password');
+ return false;
+ }
- $sha1pass = hash('sha256',$timestamp . $row['password']);
+ $sha1pass = hash('sha256',$timestamp . $row['password']);
- if ($sha1pass === $passphrase) {
+ if ($sha1pass === $passphrase) {
// Create the Session, in this class for now needs to be moved
- $data['username'] = $client->username;
- $data['type'] = 'api';
- $data['value'] = $timestamp;
- $token = vauth::session_create($data);
+ $data['username'] = $client->username;
+ $data['type'] = 'api';
+ $data['value'] = $timestamp;
+ $token = vauth::session_create($data);
// Insert the token into the streamer
- Stream::insert_session($token,$client->id);
- debug_event('API','Login Success, passphrase matched','1');
+ Stream::insert_session($token,$client->id);
+ debug_event('API','Login Success, passphrase matched','1');
// We need to also get the 'last update' of the catalog information in an RFC 2822 Format
- $sql = "SELECT MAX(`last_update`) AS `update`,MAX(`last_add`) AS `add`, MAX(`last_clean`) AS `clean` FROM `catalog`";
- $db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
+ $sql = "SELECT MAX(`last_update`) AS `update`,MAX(`last_add`) AS `add`, MAX(`last_clean`) AS `clean` FROM `catalog`";
+ $db_results = Dba::read($sql);
+ $row = Dba::fetch_assoc($db_results);
// Now we need to quickly get the totals of songs
- $sql = "SELECT COUNT(`id`) AS `song`,COUNT(DISTINCT(`album`)) AS `album`," .
+ $sql = "SELECT COUNT(`id`) AS `song`,COUNT(DISTINCT(`album`)) AS `album`," .
"COUNT(DISTINCT(`artist`)) AS `artist` FROM `song`";
- $db_results = Dba::read($sql);
- $counts = Dba::fetch_assoc($db_results);
+ $db_results = Dba::read($sql);
+ $counts = Dba::fetch_assoc($db_results);
// Next the video counts
- $sql = "SELECT COUNT(`id`) AS `video` FROM `video`";
- $db_results = Dba::read($sql);
- $vcounts = Dba::fetch_assoc($db_results);
+ $sql = "SELECT COUNT(`id`) AS `video` FROM `video`";
+ $db_results = Dba::read($sql);
+ $vcounts = Dba::fetch_assoc($db_results);
- $sql = "SELECT COUNT(`id`) AS `playlist` FROM `playlist`";
+ $sql = "SELECT COUNT(`id`) AS `playlist` FROM `playlist`";
$db_results = Dba::read($sql);
- $playlist = Dba::fetch_assoc($db_results);
+ $playlist = Dba::fetch_assoc($db_results);
echo xmlData::keyed_array(array('auth'=>$token,
'api'=>self::$version,
@@ -201,13 +201,13 @@ class Api {
'albums'=>$counts['album'],
'artists'=>$counts['artist'],
'playlists'=>$playlist['playlist'],
- 'videos'=>$vcounts['video']));
- } // match
+ 'videos'=>$vcounts['video']));
+ } // match
} // end while
- debug_event('API','Login Failed, unable to match passphrase','1');
- xmlData::error('401',_('Error Invalid Handshake - ') . _('Invalid Username/Password'));
+ debug_event('API','Login Failed, unable to match passphrase','1');
+ xmlData::error('401',_('Error Invalid Handshake - ') . _('Invalid Username/Password'));
} // handshake
@@ -216,7 +216,7 @@ class Api {
* This can be called without being authenticated, it is useful for determining if what the status
* of the server is, and what version it is running/compatible with
*/
- public static function ping($input) {
+ public static function ping($input) {
$xmldata = array('server'=>Config::get('version'),'version'=>Api::$version,'compatible'=>'350001');
@@ -239,7 +239,7 @@ class Api {
* artist objects. This function is deprecated!
* //DEPRECATED
*/
- public static function artists($input) {
+ public static function artists($input) {
Browse::reset_filters();
Browse::set_type('artist');
@@ -266,7 +266,7 @@ class Api {
* This returns a single artist based on the UID of said artist
* //DEPRECATED
*/
- public static function artist($input) {
+ public static function artist($input) {
$uid = scrub_in($input['filter']);
echo xmlData::artists(array($uid));
@@ -277,7 +277,7 @@ class Api {
* artist_albums
* This returns the albums of an artist
*/
- public static function artist_albums($input) {
+ public static function artist_albums($input) {
$artist = new Artist($input['filter']);
@@ -295,7 +295,7 @@ class Api {
* artist_songs
* This returns the songs of the specified artist
*/
- public static function artist_songs($input) {
+ public static function artist_songs($input) {
$artist = new Artist($input['filter']);
$songs = $artist->get_songs();
@@ -312,7 +312,7 @@ class Api {
* albums
* This returns albums based on the provided search filters
*/
- public static function albums($input) {
+ public static function albums($input) {
Browse::reset_filters();
Browse::set_type('album');
@@ -336,7 +336,7 @@ class Api {
* album
* This returns a single album based on the UID provided
*/
- public static function album($input) {
+ public static function album($input) {
$uid = scrub_in($input['filter']);
echo xmlData::albums(array($uid));
@@ -347,7 +347,7 @@ class Api {
* album_songs
* This returns the songs of a specified album
*/
- public static function album_songs($input) {
+ public static function album_songs($input) {
$album = new Album($input['filter']);
$songs = $album->get_songs();
@@ -359,13 +359,13 @@ class Api {
ob_end_clean();
echo xmlData::songs($songs);
- } // album_songs
+ } // album_songs
/**
* tags
* This returns the tags based on the specified filter
*/
- public static function tags($input) {
+ public static function tags($input) {
Browse::reset_filters();
Browse::set_type('tag');
@@ -388,7 +388,7 @@ class Api {
* tag
* This returns a single tag based on UID
*/
- public static function tag($input) {
+ public static function tag($input) {
$uid = scrub_in($input['filter']);
ob_end_clean();
@@ -400,7 +400,7 @@ class Api {
* tag_artists
* This returns the artists assoicated with the tag in question as defined by the UID
*/
- public static function tag_artists($input) {
+ public static function tag_artists($input) {
$artists = Tag::get_tag_objects('artist',$input['filter']);
@@ -416,7 +416,7 @@ class Api {
* tag_albums
* This returns the albums assoicated with the tag in question
*/
- public static function tag_albums($input) {
+ public static function tag_albums($input) {
$albums = Tag::get_tag_objects('album',$input['filter']);
@@ -432,7 +432,7 @@ class Api {
* tag_songs
* returns the songs for this tag
*/
- public static function tag_songs($input) {
+ public static function tag_songs($input) {
$songs = Tag::get_tag_objects('song',$input['filter']);
@@ -448,7 +448,7 @@ class Api {
* songs
* Returns songs based on the specified filter
*/
- public static function songs($input) {
+ public static function songs($input) {
Browse::reset_filters();
Browse::set_type('song');
@@ -474,7 +474,7 @@ class Api {
* song
* returns a single song
*/
- public static function song($input) {
+ public static function song($input) {
$uid = scrub_in($input['filter']);
@@ -487,7 +487,7 @@ class Api {
* url_to_song
* This takes a url and returns the song object in question
*/
- public static function url_to_song($input) {
+ public static function url_to_song($input) {
// Don't scrub in we need to give her raw and juicy to the function
$url = $input['url'];
@@ -503,7 +503,7 @@ class Api {
* playlists
* This returns playlists based on the specified filter
*/
- public static function playlists($input) {
+ public static function playlists($input) {
Browse::reset_filters();
Browse::set_type('playlist');
@@ -526,7 +526,7 @@ class Api {
* playlist
* This returns a single playlist
*/
- public static function playlist($input) {
+ public static function playlist($input) {
$uid = scrub_in($input['filter']);
@@ -539,7 +539,7 @@ class Api {
* playlist_songs
* This returns the songs for a playlist
*/
- public static function playlist_songs($input) {
+ public static function playlist_songs($input) {
$playlist = new Playlist($input['filter']);
$items = $playlist->get_items();
@@ -561,7 +561,7 @@ class Api {
* search_songs
* This returns the songs and returns... songs
*/
- public static function search_songs($input) {
+ public static function search_songs($input) {
$array['s_all'] = $input['filter'];
ob_end_clean();
@@ -583,7 +583,7 @@ class Api {
* videos
* This returns video objects!
*/
- public static function videos($input) {
+ public static function videos($input) {
Browse::reset_filters();
Browse::set_type('video');
@@ -602,10 +602,10 @@ class Api {
} // videos
/**
- * video
+ * video
* This returns a single video
*/
- public static function video($input) {
+ public static function video($input) {
$video_id = scrub_in($input['filter']);
@@ -618,7 +618,7 @@ class Api {
* localplay
* This is for controling localplay
*/
- public static function localplay($input) {
+ public static function localplay($input) {
// Load their localplay instance
$localplay = new Localplay(Config::get('localplay_controller'));
@@ -645,7 +645,7 @@ class Api {
* democratic
* This is for controlling democratic play
*/
- public static function democratic($input) {
+ public static function democratic($input) {
// Load up democratic information
$democratic = Democratic::get_current_playlist();
diff --git a/lib/class/art.class.php b/lib/class/art.class.php
index 2fe672d8..12f76631 100644
--- a/lib/class/art.class.php
+++ b/lib/class/art.class.php
@@ -23,17 +23,17 @@
/**
* Art
* This class handles the images / artwork in ampache
- * This was initially in the album class, but was pulled out
+ * This was initially in the album class, but was pulled out
* to be more general, and apply to albums, artists, movies etc
*/
-class Art extends database_object {
+class Art extends database_object {
/**
* Constructor
* Art constructor, not sure what's here for now
*/
- public function __construct() {
+ public function __construct() {
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php
index a0ca2ad3..c30b20e4 100644
--- a/lib/class/artist.class.php
+++ b/lib/class/artist.class.php
@@ -16,7 +16,7 @@
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.
*/
@@ -44,16 +44,16 @@ class Artist extends database_object {
public function __construct($id='') {
/* If they failed to pass in an id, just run for it */
- if (!$id) { return false; }
+ if (!$id) { return false; }
/* Get the information from the db */
$info = $this->get_info($id);
-
- foreach ($info as $key=>$value) {
- $this->$key = $value;
+
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
} // foreach info
- return true;
+ return true;
} //constructor
@@ -62,15 +62,15 @@ class Artist extends database_object {
* This is used by the metadata class specifically but fills out a Artist object
* based on a key'd array, it sets $_fake to true
*/
- public static function construct_from_array($data) {
+ public static function construct_from_array($data) {
- $artist = new Artist(0);
- foreach ($data as $key=>$value) {
- $artist->$key = $value;
- }
+ $artist = new Artist(0);
+ foreach ($data as $key=>$value) {
+ $artist->$key = $value;
+ }
//Ack that this is not a real object from the DB
- $artist->_fake = true;
+ $artist->_fake = true;
return $artist;
@@ -88,18 +88,18 @@ class Artist extends database_object {
$db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('artist',$row['id'],$row);
+ parent::add_to_cache('artist',$row['id'],$row);
}
// If we need to also pull the extra information, this is normally only used when we are doing the human display
- if ($extra) {
+ if ($extra) {
$sql = "SELECT `song`.`artist`, COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " .
"WHERE `song`.`artist` IN $idlist GROUP BY `song`.`artist`";
$db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('artist_extra',$row['artist'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('artist_extra',$row['artist'],$row);
+ }
} // end if extra
@@ -111,51 +111,51 @@ class Artist extends database_object {
* get_from_name
* This gets an artist object based on the artist name
*/
- public static function get_from_name($name) {
+ public static function get_from_name($name) {
- $name = Dba::escape($name);
- $sql = "SELECT `id` FROM `artist` WHERE `name`='$name'";
- $db_results = Dba::write($sql);
+ $name = Dba::escape($name);
+ $sql = "SELECT `id` FROM `artist` WHERE `name`='$name'";
+ $db_results = Dba::write($sql);
- $row = Dba::fetch_assoc($db_results);
+ $row = Dba::fetch_assoc($db_results);
- $object = new Artist($row['id']);
+ $object = new Artist($row['id']);
- return $object;
+ return $object;
- } // get_from_name
+ } // get_from_name
/**
* get_albums
* gets the album ids that this artist is a part
* of
*/
- public function get_albums() {
+ public function get_albums() {
$results = array();
- $sql = "SELECT `album`.`id` FROM album LEFT JOIN `song` ON `song`.`album`=`album`.`id` " .
+ $sql = "SELECT `album`.`id` FROM album LEFT JOIN `song` ON `song`.`album`=`album`.`id` " .
"WHERE `song`.`artist`='$this->id' GROUP BY `album`.`id` ORDER BY `album`.`name`,`album`.`disk`,`album`.`year`";
$db_results = Dba::read($sql);
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id'];
}
return $results;
-
+
} // get_albums
- /**
+ /**
* get_songs
* gets the songs for this artist
*/
- public function get_songs() {
-
+ public function get_songs() {
+
$sql = "SELECT `song`.`id` FROM `song` WHERE `song`.`artist`='" . Dba::escape($this->id) . "' ORDER BY album, track";
$db_results = Dba::read($sql);
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id'];
}
@@ -186,27 +186,27 @@ class Artist extends database_object {
* _get_extra info
* This returns the extra information for the artist, this means totals etc
*/
- private function _get_extra_info() {
+ private function _get_extra_info() {
// Try to find it in the cache and save ourselves the trouble
- if (parent::is_cached('artist_extra',$this->id)) {
- $row = parent::get_from_cache('artist_extra',$this->id);
- }
- else {
- $uid = Dba::escape($this->id);
- $sql = "SELECT `song`.`artist`,COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " .
+ if (parent::is_cached('artist_extra',$this->id)) {
+ $row = parent::get_from_cache('artist_extra',$this->id);
+ }
+ else {
+ $uid = Dba::escape($this->id);
+ $sql = "SELECT `song`.`artist`,COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " .
"WHERE `song`.`artist`='$uid' GROUP BY `song`.`artist`";
$db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
- parent::add_to_cache('artist_extra',$row['artist'],$row);
- }
-
+ $row = Dba::fetch_assoc($db_results);
+ parent::add_to_cache('artist_extra',$row['artist'],$row);
+ }
+
/* Set Object Vars */
$this->songs = $row['song_count'];
$this->albums = $row['album_count'];
- $this->time = $row['time'];
+ $this->time = $row['time'];
- return $row;
+ return $row;
} // _get_extra_info
@@ -222,30 +222,30 @@ class Artist extends database_object {
/* Combine prefix and name, trim then add ... if needed */
$name = truncate_with_ellipsis(trim($this->prefix . " " . $this->name),Config::get('ellipse_threshold_artist'));
$this->f_name = $name;
- $this->f_full_name = trim($this->prefix . " " . $this->name);
+ $this->f_full_name = trim($this->prefix . " " . $this->name);
// If this is a fake object, we're done here
- if ($this->_fake) { return true; }
+ if ($this->_fake) { return true; }
$this->f_name_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&amp;artist=" . $this->id . "\" title=\"" . $this->full_name . "\">" . $name . "</a>";
- $this->f_link = Config::get('web_path') . '/artists.php?action=show&amp;artist=' . $this->id;
+ $this->f_link = Config::get('web_path') . '/artists.php?action=show&amp;artist=' . $this->id;
- // Get the counts
- $extra_info = $this->_get_extra_info();
+ // Get the counts
+ $extra_info = $this->_get_extra_info();
//Format the new time thingy that we just got
- $min = sprintf("%02d",(floor($extra_info['time']/60)%60));
-
- $sec = sprintf("%02d",($extra_info['time']%60));
+ $min = sprintf("%02d",(floor($extra_info['time']/60)%60));
+
+ $sec = sprintf("%02d",($extra_info['time']%60));
$hours = floor($extra_info['time']/3600);
- $this->f_time = ltrim($hours . ':' . $min . ':' . $sec,'0:');
+ $this->f_time = ltrim($hours . ':' . $min . ':' . $sec,'0:');
- $this->tags = Tag::get_top_tags('artist',$this->id);
+ $this->tags = Tag::get_top_tags('artist',$this->id);
- $this->f_tags = Tag::get_display($this->tags,$this->id,'artist');
+ $this->f_tags = Tag::get_display($this->tags,$this->id,'artist');
- return true;
+ return true;
} // format
@@ -254,30 +254,30 @@ class Artist extends database_object {
* This takes a key'd array of data and updates the current artist
* it will flag songs as neeed
*/
- public function update($data) {
+ public function update($data) {
// Save our current ID
- $current_id = $this->id;
+ $current_id = $this->id;
- $artist_id = Catalog::check_artist($data['name'], $this->mbid);
+ $artist_id = Catalog::check_artist($data['name'], $this->mbid);
// If it's changed we need to update
- if ($artist_id != $this->id) {
- $songs = $this->get_songs();
- foreach ($songs as $song_id) {
- Song::update_artist($artist_id,$song_id);
- }
- $updated = 1;
- $current_id = $artist_id;
- Catalog::clean_artists();
+ if ($artist_id != $this->id) {
+ $songs = $this->get_songs();
+ foreach ($songs as $song_id) {
+ Song::update_artist($artist_id,$song_id);
+ }
+ $updated = 1;
+ $current_id = $artist_id;
+ Catalog::clean_artists();
} // end if it changed
- if ($updated) {
- foreach ($songs as $song_id) {
- Flag::add($song_id,'song','retag','Interface Artist Update');
- Song::update_utime($song_id);
- }
- Catalog::clean_stats();
+ if ($updated) {
+ foreach ($songs as $song_id) {
+ Flag::add($song_id,'song','retag','Interface Artist Update');
+ Song::update_utime($song_id);
+ }
+ Catalog::clean_stats();
} // if updated
return $current_id;
@@ -293,8 +293,8 @@ class Artist extends database_object {
debug_event("lyrics", "Initialized Function", "5");
$sql = "SELECT `song_data`.`lyrics` FROM `song_data` WHERE `song_id`='" . Dba::escape($song_id) . "'";
- $db_results = Dba::read($sql);
- $results = Dba::fetch_assoc($db_results);
+ $db_results = Dba::read($sql);
+ $results = Dba::fetch_assoc($db_results);
// Get Lyrics From id3tag (Lyrics3)
$rs = Dba::read("SELECT `song`.`file` FROM `song` WHERE `id`='" . Dba::escape($song_id) . "'");
diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php
index 8a176bb0..17408a37 100644
--- a/lib/class/browse.class.php
+++ b/lib/class/browse.class.php
@@ -27,29 +27,29 @@
* it also handles pulling back the object_ids and then
* calling the correct template for the object we are displaying
*/
-class Browse extends Query {
+class Browse extends 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;
// Boolean if this is a simple browse method (use different paging code)
- public static $simple_browse;
+ public static $simple_browse;
// 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;
- private static $_cache = array();
+ // apply any filters that would change the result set.
+ public static $static_content = false;
+ private static $_cache = array();
/**
* constructor
* This should never be called
*/
- private function __construct() {
+ private function __construct() {
// Rien a faire
@@ -60,9 +60,9 @@ class Browse extends 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_simple_browse($value) {
+ public static function set_simple_browse($value) {
- parent::set_is_simple($value);
+ parent::set_is_simple($value);
} // set_simple_browse
@@ -70,11 +70,11 @@ class Browse extends Query {
* add_supplemental_object
* Legacy function, need to find a better way to do that
*/
- public static function add_supplemental_object($class,$uid) {
+ public static function add_supplemental_object($class,$uid) {
- $_SESSION['browse']['supplemental'][$class] = intval($uid);
+ $_SESSION['browse']['supplemental'][$class] = intval($uid);
- return true;
+ return true;
} // add_supplemental_object
@@ -83,36 +83,36 @@ class Browse extends Query {
* This returns an array of 'class','id' for additional objects that need to be
* created before we start this whole browsing thing
*/
- public static function get_supplemental_objects() {
+ public static function get_supplemental_objects() {
- $objects = $_SESSION['browse']['supplemental'];
-
- if (!is_array($objects)) { $objects = array(); }
+ $objects = $_SESSION['browse']['supplemental'];
- return $objects;
+ if (!is_array($objects)) { $objects = array(); }
+
+ return $objects;
} // get_supplemental_objects
- /**
+ /**
* is_enabled
* This checks if the specified function/feature
* of browsing is enabled, not sure if this is the best
* way to go about it, but hey. Returns boolean t/f
*/
- public static function is_enabled($item) {
-
- switch ($item) {
- case 'show_art':
- if (Browse::get_filter('show_art')) {
- return true;
- }
- if (Config::get('bandwidth') > 25) {
- return true;
- }
- break;
+ public static function is_enabled($item) {
+
+ switch ($item) {
+ case 'show_art':
+ if (Browse::get_filter('show_art')) {
+ return true;
+ }
+ if (Config::get('bandwidth') > 25) {
+ return true;
+ }
+ break;
} // end switch
- return false;
+ return false;
} // is_enabled
@@ -122,147 +122,147 @@ class Browse extends Query {
* and requires the correct template based on the
* type that we are currently browsing
*/
- public static function show_objects($object_ids=false) {
-
- if (parent::is_simple()) {
- $object_ids = parent::get_saved();
- }
- else {
+ public static function show_objects($object_ids=false) {
+
+ if (parent::is_simple()) {
+ $object_ids = parent::get_saved();
+ }
+ else {
$object_ids = is_array($object_ids) ? $object_ids : parent::get_saved();
- parent::save_objects($object_ids);
- }
-
+ parent::save_objects($object_ids);
+ }
+
// Reset the total items
- self::$total_objects = parent::get_total($object_ids);
-
+ self::$total_objects = parent::get_total($object_ids);
+
// Limit is based on the users preferences if this is not a simple browse because we've got too much here
- if (count($object_ids) > parent::get_start() AND !parent::is_simple()) {
- $object_ids = array_slice($object_ids,parent::get_start(),parent::get_offset(),TRUE);
- }
+ if (count($object_ids) > parent::get_start() AND !parent::is_simple()) {
+ $object_ids = array_slice($object_ids,parent::get_start(),parent::get_offset(),TRUE);
+ }
// Load any additional object we need for this
- $extra_objects = self::get_supplemental_objects();
+ $extra_objects = self::get_supplemental_objects();
- foreach ($extra_objects as $class_name => $id) {
- ${$class_name} = new $class_name($id);
- }
+ foreach ($extra_objects as $class_name => $id) {
+ ${$class_name} = new $class_name($id);
+ }
// Format any matches we have so we can show them to the masses
- if ($filter_value = parent::get_filter('alpha_match')) {
- $match = ' (' . $filter_value . ')';
+ if ($filter_value = parent::get_filter('alpha_match')) {
+ $match = ' (' . $filter_value . ')';
+ }
+ elseif ($filter_value = parent::get_filter('starts_with')) {
+ $match = ' (' . $filter_value . ')';
}
- elseif ($filter_value = parent::get_filter('starts_with')) {
- $match = ' (' . $filter_value . ')';
- }
// Set the correct classes based on type
$class = "box browse_".self::$type;
Ajax::start_container('browse_content');
// Switch on the type of browsing we're doing
- switch (parent::get_type()) {
- case 'song':
- show_box_top(_('Songs') . $match, $class);
- Song::build_cache($object_ids);
- require_once Config::get('prefix') . '/templates/show_songs.inc.php';
- show_box_bottom();
+ switch (parent::get_type()) {
+ case 'song':
+ show_box_top(_('Songs') . $match, $class);
+ Song::build_cache($object_ids);
+ require_once Config::get('prefix') . '/templates/show_songs.inc.php';
+ show_box_bottom();
break;
- case 'album':
- show_box_top(_('Albums') . $match, $class);
+ case 'album':
+ show_box_top(_('Albums') . $match, $class);
Album::build_cache($object_ids,'extra');
require_once Config::get('prefix') . '/templates/show_albums.inc.php';
- show_box_bottom();
+ show_box_bottom();
break;
case 'user':
- show_box_top(_('Manage Users') . $match, $class);
- require_once Config::get('prefix') . '/templates/show_users.inc.php';
- show_box_bottom();
+ show_box_top(_('Manage Users') . $match, $class);
+ require_once Config::get('prefix') . '/templates/show_users.inc.php';
+ show_box_bottom();
break;
case 'artist':
- show_box_top(_('Artists') . $match, $class);
- Artist::build_cache($object_ids,'extra');
- require_once Config::get('prefix') . '/templates/show_artists.inc.php';
- show_box_bottom();
+ show_box_top(_('Artists') . $match, $class);
+ Artist::build_cache($object_ids,'extra');
+ require_once Config::get('prefix') . '/templates/show_artists.inc.php';
+ show_box_bottom();
break;
- case 'live_stream':
- require_once Config::get('prefix') . '/templates/show_live_stream.inc.php';
- show_box_top(_('Radio Stations') . $match, $class);
+ case 'live_stream':
+ require_once Config::get('prefix') . '/templates/show_live_stream.inc.php';
+ show_box_top(_('Radio Stations') . $match, $class);
require_once Config::get('prefix') . '/templates/show_live_streams.inc.php';
- show_box_bottom();
+ show_box_bottom();
break;
- case 'playlist':
- Playlist::build_cache($object_ids);
+ case 'playlist':
+ Playlist::build_cache($object_ids);
show_box_top(_('Playlists') . $match, $class);
- require_once Config::get('prefix') . '/templates/show_playlists.inc.php';
- show_box_bottom();
+ require_once Config::get('prefix') . '/templates/show_playlists.inc.php';
+ show_box_bottom();
+ break;
+ case 'playlist_song':
+ show_box_top(_('Playlist Songs') . $match,$class);
+ require_once Config::get('prefix') . '/templates/show_playlist_songs.inc.php';
+ show_box_bottom();
break;
- case 'playlist_song':
- show_box_top(_('Playlist Songs') . $match,$class);
- require_once Config::get('prefix') . '/templates/show_playlist_songs.inc.php';
- show_box_bottom();
- break;
- case 'playlist_localplay':
- show_box_top(_('Current Playlist'));
- require_once Config::get('prefix') . '/templates/show_localplay_playlist.inc.php';
- show_box_bottom();
+ case 'playlist_localplay':
+ show_box_top(_('Current Playlist'));
+ require_once Config::get('prefix') . '/templates/show_localplay_playlist.inc.php';
+ show_box_bottom();
break;
- case 'catalog':
- show_box_top(_('Catalogs'), $class);
+ case 'catalog':
+ show_box_top(_('Catalogs'), $class);
require_once Config::get('prefix') . '/templates/show_catalogs.inc.php';
- show_box_bottom();
+ show_box_bottom();
+ break;
+ case 'shoutbox':
+ show_box_top(_('Shoutbox Records'),$class);
+ require_once Config::get('prefix') . '/templates/show_manage_shoutbox.inc.php';
+ show_box_bottom();
break;
- case 'shoutbox':
- show_box_top(_('Shoutbox Records'),$class);
- require_once Config::get('prefix') . '/templates/show_manage_shoutbox.inc.php';
- show_box_bottom();
- break;
case 'flagged':
- show_box_top(_('Flagged Records'),$class);
- require_once Config::get('prefix') . '/templates/show_flagged.inc.php';
- show_box_bottom();
+ show_box_top(_('Flagged Records'),$class);
+ require_once Config::get('prefix') . '/templates/show_flagged.inc.php';
+ show_box_bottom();
+ break;
+ case 'tag':
+ Tag::build_cache($tags);
+ show_box_top(_('Tag Cloud'),$class);
+ require_once Config::get('prefix') . '/templates/show_tagcloud.inc.php';
+ show_box_bottom();
+ break;
+ case 'video':
+ Video::build_cache($object_ids);
+ show_box_top(_('Videos'),$class);
+ require_once Config::get('prefix') . '/templates/show_videos.inc.php';
+ show_box_bottom();
break;
- case 'tag':
- Tag::build_cache($tags);
- show_box_top(_('Tag Cloud'),$class);
- require_once Config::get('prefix') . '/templates/show_tagcloud.inc.php';
- show_box_bottom();
- break;
- case 'video':
- Video::build_cache($object_ids);
- show_box_top(_('Videos'),$class);
- require_once Config::get('prefix') . '/templates/show_videos.inc.php';
- show_box_bottom();
- break;
- case 'democratic':
- show_box_top(_('Democratic Playlist'),$class);
- require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php';
- show_box_bottom();
- default:
+ case 'democratic':
+ show_box_top(_('Democratic Playlist'),$class);
+ require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php';
+ show_box_bottom();
+ default:
// Rien a faire
break;
} // end switch on type
- Ajax::end_container();
+ Ajax::end_container();
} // show_object
/**
* _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() {
$offset = Config::get('offset_limit') ? Config::get('offset_limit') : '25';
- parent::set_offset($offset);
+ parent::set_offset($offset);
} // _auto_init
-
+
/**
* set_filter_from_request
* //FIXME
- */
- public static function set_filter_from_request($r) {
+ */
+ public static function set_filter_from_request($r) {
foreach($r as $k=>$v) {
//reinterpret v as a list of int
$vl = explode(',', $v);
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 99e750ab..96766b92 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -30,7 +30,7 @@ class Catalog extends database_object {
public $name;
public $last_update;
public $last_add;
- public $last_clean;
+ public $last_clean;
public $key;
public $rename_pattern;
public $sort_pattern;
@@ -88,15 +88,15 @@ class Catalog extends database_object {
$this->_filecache[strtolower($results['file'])] = $results['id'];
}
- $sql = "SELECT `id`,`file` FROM `video` WHERE `catalog`='$catalog_id'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id`,`file` FROM `video` WHERE `catalog`='$catalog_id'";
+ $db_results = Dba::read($sql);
- while ($results = Dba::fetch_assoc($db_results)) {
- $this->_filecache[strtolower($results['file'])] = 'v_' . $results['id'];
- }
+ while ($results = Dba::fetch_assoc($db_results)) {
+ $this->_filecache[strtolower($results['file'])] = 'v_' . $results['id'];
+ }
} // end if empty filecache
- return true;
+ return true;
} // _create_filecache
@@ -105,33 +105,33 @@ class Catalog extends database_object {
* Try to figure out which catalog path most closely resembles this one
* This is useful when creating a new catalog to make sure we're not doubling up here
*/
- public static function get_from_path($path) {
+ public static function get_from_path($path) {
// First pull a list of all of the paths for the different catalogs
- $sql = "SELECT `id`,`path` FROM `catalog` WHERE `catalog_type`='local'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id`,`path` FROM `catalog` WHERE `catalog_type`='local'";
+ $db_results = Dba::read($sql);
- $catalog_paths = array();
- $component_path = $path;
+ $catalog_paths = array();
+ $component_path = $path;
- while ($row = Dba::fetch_assoc($db_results)) {
+ while ($row = Dba::fetch_assoc($db_results)) {
$catalog_paths[$row['path']] = $row['id'];
- }
+ }
// Break it down into its component parts and start looking for a catalog
- do {
- if ($catalog_paths[$component_path]) {
- return $catalog_paths[$component_path];
- }
+ do {
+ if ($catalog_paths[$component_path]) {
+ return $catalog_paths[$component_path];
+ }
// Keep going until the path stops changing
- $old_path = $component_path;
- $component_path = realpath($component_path . '/../');
+ $old_path = $component_path;
+ $component_path = realpath($component_path . '/../');
- } while (strcmp($component_path,$old_path) != 0);
+ } while (strcmp($component_path,$old_path) != 0);
- return false;
+ return false;
} // get_from_path
@@ -146,7 +146,7 @@ class Catalog extends database_object {
$this->f_path = truncate_with_ellipsis($this->path,Config::get('ellipse_threshold_title'));
$this->f_update = $this->last_update ? date('d/m/Y h:i',$this->last_update) : _('Never');
$this->f_add = $this->last_add ? date('d/m/Y h:i',$this->last_add) : _('Never');
- $this->f_clean = $this->last_clean ? date('d/m/Y h:i',$this->last_clean) : _('Never');
+ $this->f_clean = $this->last_clean ? date('d/m/Y h:i',$this->last_clean) : _('Never');
} // format
@@ -197,8 +197,8 @@ class Catalog extends database_object {
$results = self::count_songs($catalog_id);
$results = array_merge(self::count_users($catalog_id),$results);
- $results['tags'] = self::count_tags();
- $results = array_merge(self::count_video($catalog_id),$results);
+ $results['tags'] = self::count_tags();
+ $results = array_merge(self::count_video($catalog_id),$results);
$hours = floor($results['time']/3600);
// Calculate catalog size in bytes, divided by 1000
@@ -347,7 +347,7 @@ class Catalog extends database_object {
$this->get_album_art('',1);
}
- if ($options['parse_m3u'] AND count($this->_playlists)) {
+ if ($options['parse_m3u'] AND count($this->_playlists)) {
foreach ($this->_playlists as $playlist_file) {
$result = $this->import_m3u($playlist_file);
}
@@ -361,31 +361,31 @@ class Catalog extends database_object {
* count_video
* This returns the current # of video files we've got in the db
*/
- public static function count_video($catalog_id=0) {
+ public static function count_video($catalog_id=0) {
- $catalog_search = $catalog_id ? "WHERE `catalog`='" . Dba::escape($catalog_id) . "'" : '';
+ $catalog_search = $catalog_id ? "WHERE `catalog`='" . Dba::escape($catalog_id) . "'" : '';
+
+ $sql = "SELECT COUNT(`id`) AS `video` FROM `video` $catalog_search";
+ $db_results = Dba::read($sql);
- $sql = "SELECT COUNT(`id`) AS `video` FROM `video` $catalog_search";
- $db_results = Dba::read($sql);
+ $row = Dba::fetch_assoc($db_results);
- $row = Dba::fetch_assoc($db_results);
-
- return $row;
+ return $row;
- } // count_video
+ } // count_video
/**
* count_tags
* This returns the current # of unique tags that exist in the database
*/
- public static function count_tags($catalog_id=0) {
+ public static function count_tags($catalog_id=0) {
- $sql = "SELECT COUNT(`id`) FROM `tag`";
- $db_results = Dba::read($sql);
+ $sql = "SELECT COUNT(`id`) FROM `tag`";
+ $db_results = Dba::read($sql);
- $info = Dba::fetch_row($db_results);
+ $info = Dba::fetch_row($db_results);
- return $info['0'];
+ return $info['0'];
} // count_tags
@@ -396,7 +396,7 @@ class Catalog extends database_object {
*/
public static function count_songs($catalog_id='') {
- $catalog_search = $catalog_id ? "WHERE `catalog`='" . Dba::escape($catalog_id) . "'" : '';
+ $catalog_search = $catalog_id ? "WHERE `catalog`='" . Dba::escape($catalog_id) . "'" : '';
$sql = "SELECT COUNT(`id`),SUM(`time`),SUM(`size`) FROM `song` $catalog_search";
$db_results = Dba::read($sql);
@@ -462,13 +462,13 @@ class Catalog extends database_object {
public function add_files($path,$options) {
// Profile the memory a bit
- debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1);
+ debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1);
// See if we want a non-root path for the add
- if (isset($options['subdirectory'])) {
- $path = $options['subdirectory'];
- unset($options['subdirectory']);
- }
+ if (isset($options['subdirectory'])) {
+ $path = $options['subdirectory'];
+ unset($options['subdirectory']);
+ }
// Correctly detect the slash we need to use here
if (strstr($path,"/")) {
@@ -497,10 +497,10 @@ class Catalog extends database_object {
// Ensure that we've got our cache
$this->_create_filecache();
- debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1);
+ debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1);
// Set the base "ticker" we will only update ever 5+ seconds
- $ticker = time();
+ $ticker = time();
/* Recurse through this dir and create the files array */
while ( false !== ( $file = readdir($handle) ) ) {
@@ -509,7 +509,7 @@ class Catalog extends database_object {
if (substr($file,0,1) == '.') { continue; }
debug_event('read',"Starting work on $file inside $path",'5','ampache-catalog');
- debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1);
+ debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1);
/* Create the new path */
$full_file = $path.$slash_type.$file;
@@ -520,7 +520,7 @@ class Catalog extends database_object {
if (isset($this->_filecache[strtolower($full_file)])) {
continue;
}
-
+
// Incase this is the second time through clear this variable
// if it was set the day before
unset($failed_check);
@@ -559,12 +559,12 @@ class Catalog extends database_object {
$pattern .= ")$/i";
}
- $is_audio_file = preg_match($pattern,$file);
-
+ $is_audio_file = preg_match($pattern,$file);
+
// Define the Video file pattern
if (!$is_audio_file AND Config::get('catalog_video_pattern')) {
- $video_pattern = "/\.(" . Config::get('catalog_video_pattern') . ")$/i";
- $is_video_file = preg_match($video_pattern,$file);
+ $video_pattern = "/\.(" . Config::get('catalog_video_pattern') . ")$/i";
+ $is_video_file = preg_match($video_pattern,$file);
}
/* see if this is a valid audio file or playlist file */
@@ -603,9 +603,9 @@ class Catalog extends database_object {
else {
if ($is_audio_file) { $this->insert_local_song($full_file,$file_size); }
- else { $this->insert_local_video($full_file,$file_size); }
+ else { $this->insert_local_video($full_file,$file_size); }
- $this->count++;
+ $this->count++;
if ( (time() > $ticker+1)) {
$file = str_replace(array('(',')','\''),'',$full_file);
echo "<script type=\"text/javascript\">\n";
@@ -613,7 +613,7 @@ class Catalog extends database_object {
echo "update_txt('" . addslashes(htmlentities($file)) . "','add_dir_" . $this->id . "');";
echo "\n</script>\n";
flush();
- $ticker = time();
+ $ticker = time();
} // update our current state
} // if it's not an m3u
@@ -691,7 +691,7 @@ class Catalog extends database_object {
}
// Start the ticker
- $ticker = time();
+ $ticker = time();
// Run through them an get the art!
foreach ($albums as $album_id) {
@@ -700,19 +700,19 @@ class Catalog extends database_object {
$album = new Album($album_id);
// We're going to need the name here
$album->format();
-
+
debug_event('gather_art','Gathering art for ' . $album->name,'5');
-
+
// Define the options we want to use for the find art function
$options = array(
'album_name' => $album->full_name,
'artist' => $album->artist_name,
- 'keyword' => $album->artist_name . ' ' . $album->full_name
+ 'keyword' => $album->artist_name . ' ' . $album->full_name
);
// Return results
$results = $album->find_art($options,1);
-
+
if (count($results)) {
// Pull the string representation from the source
$image = Album::get_image_from_source($results['0']);
@@ -733,9 +733,9 @@ class Catalog extends database_object {
echo "update_txt('" . addslashes($album->name) . "','read_art_" . $this->id . "');";
echo "\n</script>\n";
flush();
- $ticker = time();
+ $ticker = time();
} //echos song count
-
+
unset($found);
} // foreach albums
@@ -830,9 +830,9 @@ class Catalog extends database_object {
// Setup the base SQL
$sql = "SELECT song.id AS song,artist.id AS artist,album.id AS album,title,COUNT(title) AS ctitle".
- " FROM `song` LEFT JOIN `artist` ON `artist`.`id`=`song`.`artist` " .
+ " FROM `song` LEFT JOIN `artist` ON `artist`.`id`=`song`.`artist` " .
" LEFT JOIN `album` ON `album`.`id`=`song`.`album` $where_sql GROUP BY `song`.`title`";
-
+
// Add any Additional constraints
if ($search_method == "artist_title" OR $search_method == "artist_album_title") {
$sql = $sql.",artist.name";
@@ -924,7 +924,7 @@ class Catalog extends database_object {
else {
$extension = substr($image['0']['mime'],strlen($image['0']['mime'])-3,3);
}
-
+
// Try the preferred filename, if that fails use folder.???
$preferred_filename = Config::get('album_art_preferred_filename');
if (!$preferred_filename || strstr($preferred_filename,"%")) { $preferred_filename = "folder.$extension"; }
@@ -1002,11 +1002,11 @@ class Catalog extends database_object {
* update_last_clean
* This updates the last clean information
*/
- public function update_last_clean() {
+ public function update_last_clean() {
- $date = time();
- $sql = "UPDATE `catalog` SET `last_clean`='$date' WHERE `id`='$this->id'";
- $db_results = Dba::write($sql);
+ $date = time();
+ $sql = "UPDATE `catalog` SET `last_clean`='$date' WHERE `id`='$this->id'";
+ $db_results = Dba::write($sql);
} // update_last_clean
@@ -1075,7 +1075,7 @@ class Catalog extends database_object {
}
} // foreach songs
- self::clean();
+ self::clean();
} // update_single_item
@@ -1084,33 +1084,33 @@ class Catalog extends database_object {
* This is a 'wrapper' function calls the update function for the media type
* in question
*/
- public static function update_media_from_tags(&$media,$sort_pattern='',$rename_pattern='') {
+ public static function update_media_from_tags(&$media,$sort_pattern='',$rename_pattern='') {
// Check for patterns
- if (!$sort_pattern OR !$rename_pattern) {
- $catalog = new Catalog($media->catalog);
- $sort_pattern = $catalog->sort_pattern;
- $rename_pattern = $catalog->rename_pattern;
- }
+ if (!$sort_pattern OR !$rename_pattern) {
+ $catalog = new Catalog($media->catalog);
+ $sort_pattern = $catalog->sort_pattern;
+ $rename_pattern = $catalog->rename_pattern;
+ }
- debug_event('tag-read','Reading tags from ' . $media->file,'5','ampache-catalog');
+ debug_event('tag-read','Reading tags from ' . $media->file,'5','ampache-catalog');
- $vainfo = new vainfo($media->file,'','','',$sort_pattern,$rename_pattern);
- $vainfo->get_info();
+ $vainfo = new vainfo($media->file,'','','',$sort_pattern,$rename_pattern);
+ $vainfo->get_info();
- $key = vainfo::get_tag_type($vainfo->tags);
+ $key = vainfo::get_tag_type($vainfo->tags);
- $results = vainfo::clean_tag_info($vainfo->tags,$key,$media->file);
+ $results = vainfo::clean_tag_info($vainfo->tags,$key,$media->file);
// Figure out what type of object this is and call the right function
// giving it the stuff we've figured out above
- $name = (get_class($media) == 'Song') ? 'song' : 'video';
+ $name = (get_class($media) == 'Song') ? 'song' : 'video';
- $function = 'update_' . $name . '_from_tags';
+ $function = 'update_' . $name . '_from_tags';
- $return = call_user_func(array('Catalog',$function),$results,$media);
+ $return = call_user_func(array('Catalog',$function),$results,$media);
- return $return;
+ return $return;
} // update_media_from_tags
@@ -1119,10 +1119,10 @@ class Catalog extends database_object {
* updates the video info based on tags this is called from a bunch of different places
* and passes in a full song object and the vainfo results
*/
- public static function update_video_from_tags($results,$video) {
+ public static function update_video_from_tags($results,$video) {
// Pretty sweet function here
- return $results;
+ return $results;
} // update_video_from_tags
@@ -1140,20 +1140,20 @@ class Catalog extends database_object {
$new_song->title = $results['title'];
$new_song->year = $results['year'];
$new_song->comment = $results['comment'];
- $new_song->language = $results['language'];
- $new_song->lyrics = $results['lyrics'];
+ $new_song->language = $results['language'];
+ $new_song->lyrics = $results['lyrics'];
$new_song->bitrate = $results['bitrate'];
$new_song->rate = $results['rate'];
- $new_song->mode = ($results['mode'] == 'cbr') ? 'cbr' : 'vbr';
+ $new_song->mode = ($results['mode'] == 'cbr') ? 'cbr' : 'vbr';
$new_song->size = $results['size'];
$new_song->time = $results['time'];
- $new_song->mime = $results['mime'];
- $new_song->track = intval($results['track']);
- $new_song->mbid = $results['mb_trackid'];
+ $new_song->mime = $results['mime'];
+ $new_song->track = intval($results['track']);
+ $new_song->mbid = $results['mb_trackid'];
$artist = $results['artist'];
- $artist_mbid = $results['mb_artistid'];
+ $artist_mbid = $results['mb_artistid'];
$album = $results['album'];
- $album_mbid = $results['mb_albumid'];
+ $album_mbid = $results['mb_albumid'];
$disk = $results['disk'];
$tags = $results['genre']; // multiple genre support makes this an array
@@ -1166,7 +1166,7 @@ class Catalog extends database_object {
$new_song->album = self::check_album($album,$new_song->year,$disk,$album_mbid);
$new_song->f_album = $album . " - " . $new_song->year;
$new_song->title = self::check_title($new_song->title,$new_song->file);
-
+
// Nothing to assign here this is a multi-value doodly
// multiple genre support
foreach ($tags as $tag) {
@@ -1271,7 +1271,7 @@ class Catalog extends database_object {
* the XML RPC stuff and a key to be passed
*/
public function get_remote_catalog($type=0) {
-
+
if (!class_exists('XML_RPC_Client')) {
debug_event('xmlrpc',"Unable to load pear XMLRPC library",'1');
echo "<span class=\"error\"><b>" . _("Error") . "</b>: " . _('Unable to load pear XMLRPC library, make sure XML-RPC is enabled') . "</span><br />\n";
@@ -1317,9 +1317,9 @@ class Catalog extends database_object {
echo "<p class=\"error\">$error_msg</p>";
return;
}
-
+
$data = XML_RPC_Decode($response->value());
-
+
// Print out the catalogs we are going to sync
foreach ($data as $vars) {
$catalog_name = $vars['name'];
@@ -1343,13 +1343,13 @@ class Catalog extends database_object {
echo "<p>" . _('Completed updating remote catalog(s)') . ".</p><hr />\n";
flush();
-
+
// Try to sync the album images from the remote catalog
echo "<p>" . _('Starting synchronisation of album images') . ".</p><br />\n";
$this->get_remote_album_images($client, $token, $path);
echo "<p>" . _('Completed synchronisation of album images') . ".</p><hr />\n";
flush();
-
+
// Update the last update value
$this->update_last_update();
@@ -1400,11 +1400,11 @@ class Catalog extends database_object {
* This function retrieves the album information from the remote server
*/
public function get_remote_album_images($client,$token,$path) {
-
+
$encoded_key = new XML_RPC_Value($token,'string');
$query_array = array($encoded_key);
$xmlrpc_message = new XML_RPC_Message('xmlrpcserver.get_album_images',$query_array);
-
+
/* Depending upon the size of the target catalog this can be a very slow/long process */
set_time_limit(0);
@@ -1427,7 +1427,7 @@ class Catalog extends database_object {
return;
} // get_album_images
-
+
/**
* update_remote_catalog
* actually updates from the remote data, takes an array of songs that are base64 encoded and parses them
@@ -1444,7 +1444,7 @@ class Catalog extends database_object {
// Prevent a timeout
set_time_limit(0);
-
+
$song = unserialize($serialized_song);
$song->artist = self::check_artist($song->artist);
$song->album = self::check_album($song->album,$song->year);
@@ -1473,7 +1473,7 @@ class Catalog extends database_object {
*/
public function update_remote_album_images($data, $remote_server, $auth, $path) {
$label = "catalog.class.php::update_remote_album_images";
-
+
$total_updated = 0;
/* If album images don't exist, return value will be 0. */
@@ -1491,15 +1491,15 @@ class Catalog extends database_object {
$remote_album = new Album();
$remote_album = unserialize($serialized_album);
$remote_album->format(); //this will set the fullname
-
+
$debug_text = "remote_album id, name, year: ";
- $debug_text.= $remote_album->id . ", " . $remote_album->name . ", " . $remote_album->year;
+ $debug_text.= $remote_album->id . ", " . $remote_album->name . ", " . $remote_album->year;
debug_event($label, $debug_text, '4');
-
+
// check the album if it exists by checking the name and the year of the album
$local_album_id = self::check_album($remote_album->name, $remote_album->year,"","", true);
- debug_event($label, "local_album_id: " . $local_album_id, '4');
-
+ debug_event($label, "local_album_id: " . $local_album_id, '4');
+
if ($local_album_id != 0) {
// Local album found lets add the cover
if(isset($path) AND !preg_match("/^\//", $path)) { $path = "/".$path; }
@@ -1509,23 +1509,23 @@ class Catalog extends database_object {
$server_path.= "&auth=" . $auth;
debug_event($label, "image_url: " . $server_path,'4');
$data['url'] = $server_path;
-
+
$local_album = new Album($local_album_id);
$image_data = $local_album->get_image_from_source($data);
-
+
// If we got something back insert it
- if ($image_data) {
+ if ($image_data) {
$local_album->insert_art($image_data,"");
$total_updated++;
debug_event($label, "adding album image succes", '4');
- } else {
+ } else {
debug_event($label, "adding album image failed ", '4');
- }
+ }
}
}
-
+
return $total_updated;
-
+
} // update_remote_album_images
/**
@@ -1537,9 +1537,9 @@ class Catalog extends database_object {
// Added set time limit because this runs out of time for some people
set_time_limit(0);
-
- $dead_video = array();
- $dead_song = array();
+
+ $dead_video = array();
+ $dead_song = array();
require_once Config::get('prefix') . '/templates/show_clean_catalog.inc.php';
flush();
@@ -1555,15 +1555,15 @@ class Catalog extends database_object {
}
/* Get all songs in this catalog */
- $sql = "SELECT `id`,`file`,'song' AS `type` FROM `song` WHERE `catalog`='$this->id' AND `enabled`='1' " .
- "UNION ALL " .
- "SELECT `id`,`file`,'video' AS `type` FROM `video` WHERE `catalog`='$this->id' AND `enabled`='1'";
+ $sql = "SELECT `id`,`file`,'song' AS `type` FROM `song` WHERE `catalog`='$this->id' AND `enabled`='1' " .
+ "UNION ALL " .
+ "SELECT `id`,`file`,'video' AS `type` FROM `video` WHERE `catalog`='$this->id' AND `enabled`='1'";
$db_results = Dba::read($sql);
// Set to 0 our starting point
$dead_files = 0;
- $ticker = time();
+ $ticker = time();
/* Recurse through files, put @ to prevent errors poping up */
while ($results = Dba::fetch_assoc($db_results)) {
@@ -1577,31 +1577,31 @@ class Catalog extends database_object {
echo "update_txt('" . addslashes(htmlentities($file)) . "','clean_dir_" . $this->id . "');";
echo "\n</script>\n";
flush();
- $ticker = time();
+ $ticker = time();
} //echos song count
-
+
/* Also check the file information */
if($this->catalog_type == 'local') {
$file_info = filesize($results['file']);
-
+
/* If it errors somethings splated, or the files empty */
if (!file_exists($results['file']) OR $file_info < 1) {
-
+
/* Add Error */
Error::add('general',_('Error File Not Found or 0 Bytes:') . $results['file']);
- $table = ($results['type'] == 'video') ? 'dead_video' : 'dead_song';
+ $table = ($results['type'] == 'video') ? 'dead_video' : 'dead_song';
- // Store it in an array we'll delete it later...
- ${$table}[] = $results['id'];
+ // Store it in an array we'll delete it later...
+ ${$table}[] = $results['id'];
// Count em!
$dead_files++;
} //if error
- if (!is_readable($results['file'])) {
- debug_event('Clean','Error ' . $results['file'] . ' is not readable, but does exist','1');
- }
+ if (!is_readable($results['file'])) {
+ debug_event('Clean','Error ' . $results['file'] . ' is not readable, but does exist','1');
+ }
} // if localtype
else {
//do remote url check
@@ -1613,10 +1613,10 @@ class Catalog extends database_object {
Error::add('general',_('Error Remote File Not Found or 0 Bytes:') . $results['file']);
- $table = ($results['type'] == 'video') ? 'dead_video' : 'dead_song';
+ $table = ($results['type'] == 'video') ? 'dead_video' : 'dead_song';
- // Store it in an array we'll delete it later...
- ${$table}[] = $results['id'];
+ // Store it in an array we'll delete it later...
+ ${$table}[] = $results['id'];
// Count em!
$dead_files++;
@@ -1628,21 +1628,21 @@ class Catalog extends database_object {
// Check and see if _everything_ has gone away, might indicate a dead mount
// We call this the AlmightyOatmeal Sanity check
- if ($dead_files == $count) {
- Error::add('general',_('Error All songs would be removed, doing nothing'));
- return false;
- }
- else {
- if (count($dead_video)) {
- $idlist = '(' . implode(',',$dead_video) . ')';
- $sql = "DELETE FROM `video` WHERE `id` IN $idlist";
- $db_results = Dba::write($sql);
- }
- if (count($dead_song)) {
- $idlist = '(' . implode(',',$dead_song) . ')';
- $sql = "DELETE FROM `song` WHERE `id` IN $idlist";
- $db_results = Dba::write($sql);
- }
+ if ($dead_files == $count) {
+ Error::add('general',_('Error All songs would be removed, doing nothing'));
+ return false;
+ }
+ else {
+ if (count($dead_video)) {
+ $idlist = '(' . implode(',',$dead_video) . ')';
+ $sql = "DELETE FROM `video` WHERE `id` IN $idlist";
+ $db_results = Dba::write($sql);
+ }
+ if (count($dead_song)) {
+ $idlist = '(' . implode(',',$dead_song) . ')';
+ $sql = "DELETE FROM `song` WHERE `id` IN $idlist";
+ $db_results = Dba::write($sql);
+ }
}
/* Step two find orphaned Arists/Albums
@@ -1665,7 +1665,7 @@ class Catalog extends database_object {
flush();
// Set the last clean date
- $this->update_last_clean();
+ $this->update_last_clean();
} //clean_catalog
@@ -1677,7 +1677,7 @@ class Catalog extends database_object {
public static function clean_tags() {
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `song` ON `song`.`id`=`tag_map`.`object_id` " .
- "WHERE `tag_map`.`object_type`='song' AND `song`.`id` IS NULL";
+ "WHERE `tag_map`.`object_type`='song' AND `song`.`id` IS NULL";
$db_results = Dba::write($sql);
$sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `album` ON `album`.`id`=`tag_map`.`object_id` " .
@@ -1688,13 +1688,13 @@ class Catalog extends database_object {
"WHERE `tag_map`.`object_type`='artist' AND `artist`.`id` IS NULL";
$db_results = Dba::write($sql);
- $sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `video` ON `video`.`id`=`tag_map`.`object_id` " .
- "WHERE `tag_map`.`object_type`='video' AND `video`.`id` IS NULL";
- $db_results = Dba::write($sql);
+ $sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `video` ON `video`.`id`=`tag_map`.`object_id` " .
+ "WHERE `tag_map`.`object_type`='video' AND `video`.`id` IS NULL";
+ $db_results = Dba::write($sql);
// Now nuke the tags themselves
$sql = "DELETE FROM `tag` USING `tag` LEFT JOIN `tag_map` ON `tag`.`id`=`tag_map`.`tag_id` " .
- "WHERE `tag_map`.`id` IS NULL";
+ "WHERE `tag_map`.`id` IS NULL";
$db_results = Dba::write($sql);
} // clean_tags
@@ -1707,7 +1707,7 @@ class Catalog extends database_object {
// Clean songs
$sql = "DELETE FROM `user_shout` USING `user_shout` LEFT JOIN `song` ON `song`.`id`=`user_shout`.`object_id` " .
- "WHERE `song`.`id` IS NULL AND `user_shout`.`object_type`='song'";
+ "WHERE `song`.`id` IS NULL AND `user_shout`.`object_type`='song'";
$db_results = Dba::write($sql);
// Clean albums
@@ -1780,7 +1780,7 @@ class Catalog extends database_object {
// Clear TMP Playlist information as well
$sql = "DELETE FROM `tmp_playlist_data` USING `tmp_playlist_data` LEFT JOIN `song` ON `tmp_playlist_data`.`object_id` = `song`.`id` " .
- "WHERE `song`.`id` IS NULL";
+ "WHERE `song`.`id` IS NULL";
$db_results = Dba::write($sql);
} // clean_playlists
@@ -1792,7 +1792,7 @@ class Catalog extends database_object {
public static function clean_ext_info() {
$sql = "DELETE FROM `song_data` USING `song_data` LEFT JOIN `song` ON `song`.`id` = `song_data`.`song_id` " .
- "WHERE `song`.`id` IS NULL";
+ "WHERE `song`.`id` IS NULL";
$db_results = Dba::write($sql);
} // clean_ext_info
@@ -1820,9 +1820,9 @@ class Catalog extends database_object {
$db_results = Dba::write($sql);
// Clean the stats
- $sql = "DELETE FROM `object_count` USING `object_count` LEFT JOIN `video` ON `video`.`id`=`object_count`.`object_id` " .
- "WHERE `object_count`.`object_type`='video' AND `video`.`id` IS NULL";
- $db_results = Dba::write($sql);
+ $sql = "DELETE FROM `object_count` USING `object_count` LEFT JOIN `video` ON `video`.`id`=`object_count`.`object_id` " .
+ "WHERE `object_count`.`object_type`='video' AND `video`.`id` IS NULL";
+ $db_results = Dba::write($sql);
// Delete Song Ratings information
$sql = "DELETE FROM rating USING rating LEFT JOIN song ON song.id=rating.object_id WHERE object_type='song' AND song.id IS NULL";
@@ -1837,8 +1837,8 @@ class Catalog extends database_object {
$db_results = Dba::write($sql);
// Delete the Video Rating Informations
- $sql = "DELETE FROM `rating` USING `rating` LEFT JOIN `video` ON `video`.`id`=`rating`.`object_id` " .
- "WHERE `rating`.`object_type`='video' AND `video`.`id` IS NULL";
+ $sql = "DELETE FROM `rating` USING `rating` LEFT JOIN `video` ON `video`.`id`=`rating`.`object_id` " .
+ "WHERE `rating`.`object_type`='video' AND `video`.`id` IS NULL";
$db_results = Dba::write($sql);
} // clean_stats
@@ -1852,44 +1852,44 @@ class Catalog extends database_object {
// Create the object so we have some information on it
$catalog = new Catalog($catalog_id);
- $cache = array();
- $songs = array();
+ $cache = array();
+ $songs = array();
// Record that we're caching this stuff so it makes debugging easier
debug_event('Verify','Starting Verify of '. $catalog->name . ' caching data...','5');
/* First get the filenames for the catalog */
$sql = "SELECT `id`,`file`,`artist`,`album`,'song' AS `type` FROM `song` WHERE `song`.`catalog`='$catalog_id' ";
- $db_results = Dba::read($sql);
-
- while ($row = Dba::fetch_assoc($db_results)) {
- $cache[] = $row['id'];
- $artists[] = $row['artist'];
- $albums[] = $row['album'];
- $songs[] = $row;
- }
-
- Song::build_cache($cache);
- Flag::build_map_cache($cache,'song');
- Tag::build_map_cache('album',$albums);
- Tag::build_map_cache('artist',$artists);
- Tag::build_map_cache('song',$cache);
-
- $cache = array();
- $videos = array();
- $sql = "SELECT `id`,`file`,'video' AS `type` FROM `video` WHERE `video`.`catalog`='$catalog_id'";
- $db_results = Dba::read($sql);
-
- while ($row = Dba::fetch_assoc($db_results)) {
+ $db_results = Dba::read($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $cache[] = $row['id'];
+ $artists[] = $row['artist'];
+ $albums[] = $row['album'];
+ $songs[] = $row;
+ }
+
+ Song::build_cache($cache);
+ Flag::build_map_cache($cache,'song');
+ Tag::build_map_cache('album',$albums);
+ Tag::build_map_cache('artist',$artists);
+ Tag::build_map_cache('song',$cache);
+
+ $cache = array();
+ $videos = array();
+ $sql = "SELECT `id`,`file`,'video' AS `type` FROM `video` WHERE `video`.`catalog`='$catalog_id'";
+ $db_results = Dba::read($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
$cache[] = $row['id'];
- $videos[] = $row;
- }
- Video::build_cache($cache);
- Flag::build_map_cache($cache,'video');
+ $videos[] = $row;
+ }
+ Video::build_cache($cache);
+ Flag::build_map_cache($cache,'video');
- $cached_results = array_merge($songs,$videos);
+ $cached_results = array_merge($songs,$videos);
- $number = count($cached_results);
+ $number = count($cached_results);
require_once Config::get('prefix') . '/templates/show_verify_catalog.inc.php';
flush();
@@ -1899,18 +1899,18 @@ class Catalog extends database_object {
// Caching array for album art, save us some time here
$album_art_check_cache = array();
- $ticker = time();
+ $ticker = time();
/* Recurse through this catalogs files
* and get the id3 tage information,
* if it's not blank, and different in
* in the file then update!
*/
- foreach ($cached_results as $results) {
+ foreach ($cached_results as $results) {
debug_event('verify',"Starting work on " . $results['file'],'5','ampache-catalog');
$type = ($results['type'] == 'video') ? 'video' : 'song';
-
+
if (is_readable($results['file'])) {
/* Create the object from the existing database information */
@@ -1923,9 +1923,9 @@ class Catalog extends database_object {
$skip = true;
}
- if (filemtime($results['file']) <= $media->update_time) {
- $skip = true;
- }
+ if (filemtime($results['file']) <= $media->update_time) {
+ $skip = true;
+ }
// if the file hasn't been modified since the last_update
if (!$skip) {
@@ -1951,7 +1951,7 @@ class Catalog extends database_object {
echo "update_txt('" . scrub_out($file) . "','verify_dir_" . $catalog_id . "');";
echo "\n</script>\n";
flush();
- $ticker = time();
+ $ticker = time();
} //echos song count
} // end if file exists
@@ -2014,8 +2014,8 @@ class Catalog extends database_object {
public static function optimize_tables() {
$sql = "OPTIMIZE TABLE `song_data`,`song`,`rating`,`catalog`,`session`,`object_count`,`album`,`album_data`" .
- ",`artist`,`ip_history`,`flagged`,`now_playing`,`user_preference`,`tag`,`tag_map`,`tmp_playlist`" .
- ",`tmp_playlist_data`,`playlist`,`playlist_data`,`session_stream`,`video`";
+ ",`artist`,`ip_history`,`flagged`,`now_playing`,`user_preference`,`tag`,`tag_map`,`tmp_playlist`" .
+ ",`tmp_playlist_data`,`playlist`,`playlist_data`,`session_stream`,`video`";
$db_results = Dba::write($sql);
$sql = "ANALYZE TABLE `song_data`,`song`,`rating`,`catalog`,`session`,`object_count`,`album`,`album_data`" .
@@ -2098,7 +2098,7 @@ class Catalog extends database_object {
unset($id_array);
}
} // fuzzy matching
-
+
/* If not found create */
if (!$readonly && !$exists) {
@@ -2205,7 +2205,7 @@ class Catalog extends database_object {
}
// Save the cache
- self::$albums[$album][$album_year][$disk][$mbid] = $album_id;
+ self::$albums[$album][$album_year][$disk][$mbid] = $album_id;
return $album_id;
@@ -2213,18 +2213,18 @@ class Catalog extends database_object {
/**
* check_tag
- * This checks the tag we've been passed (name)
+ * This checks the tag we've been passed (name)
* and sees if it exists, and if so if it's mapped
* to this object, this is only done for songs for now
*/
- public static function check_tag($value,$object_id,$object_type='song') {
+ public static function check_tag($value,$object_id,$object_type='song') {
- $map_id = Tag::add($object_type,$object_id,$value,'0');
+ $map_id = Tag::add($object_type,$object_id,$value,'0');
- return $map_id;
+ return $map_id;
} // check_tag
-
+
/**
* check_title
* this checks to make sure something is
@@ -2294,21 +2294,21 @@ class Catalog extends database_object {
debug_event('insert',"Unable to insert $file -- $sql" . Dba::error(),'5','ampache-catalog');
Error::add('catalog_add','SQL Error Adding ' . $file);
}
-
+
$song_id = Dba::insert_id();
// multiple genre support
foreach ($tags as $tag) {
$tag = trim($tag);
self::check_tag($tag,$song_id);
- self::check_tag($tag,$album_id,'album');
+ self::check_tag($tag,$album_id,'album');
self::check_tag($tag,$artist_id,'artist');
}
/* Add the EXT information */
$sql = "INSERT INTO `song_data` (`song_id`,`comment`,`lyrics`) " .
- " VALUES ('$song_id','$comment','$lyrics')";
+ " VALUES ('$song_id','$comment','$lyrics')";
$db_results = Dba::write($sql);
if (!$db_results) {
@@ -2339,7 +2339,7 @@ class Catalog extends database_object {
echo "<span style=\"color: #FOO;\">Error Adding Remote $url </span><br />$sql<br />\n";
flush();
}
-
+
} // insert_remote_song
/**
@@ -2348,36 +2348,36 @@ class Catalog extends database_object {
* information we can get is super sketchy so it's kind of a crap shoot
* here
*/
- public function insert_local_video($file,$filesize) {
+ public function insert_local_video($file,$filesize) {
/* Create the vainfo object and get info */
$vainfo = new vainfo($file,'','','',$this->sort_pattern,$this->rename_pattern);
$vainfo->get_info();
- $tag_name = vainfo::get_tag_type($vainfo->tags);
- $results = vainfo::clean_tag_info($vainfo->tags,$tag_name,$file);
+ $tag_name = vainfo::get_tag_type($vainfo->tags);
+ $results = vainfo::clean_tag_info($vainfo->tags,$tag_name,$file);
- $file = Dba::escape($file);
- $catalog_id = Dba::escape($this->id);
- $title = Dba::escape($results['title']);
- $vcodec = $results['video_codec'];
- $acodec = $results['audio_codec'];
- $rezx = intval($results['resolution_x']);
- $rezy = intval($results['resolution_y']);
- $filesize = Dba::escape($filesize);
- $time = Dba::escape($results['time']);
- $mime = Dba::escape($results['mime']);
+ $file = Dba::escape($file);
+ $catalog_id = Dba::escape($this->id);
+ $title = Dba::escape($results['title']);
+ $vcodec = $results['video_codec'];
+ $acodec = $results['audio_codec'];
+ $rezx = intval($results['resolution_x']);
+ $rezy = intval($results['resolution_y']);
+ $filesize = Dba::escape($filesize);
+ $time = Dba::escape($results['time']);
+ $mime = Dba::escape($results['mime']);
// UNUSED CURRENTLY
- $comment = Dba::escape($results['comment']);
- $year = Dba::escape($results['year']);
- $disk = Dba::escape($results['disk']);
+ $comment = Dba::escape($results['comment']);
+ $year = Dba::escape($results['year']);
+ $disk = Dba::escape($results['disk']);
- $sql = "INSERT INTO `video` (`file`,`catalog`,`title`,`video_codec`,`audio_codec`,`resolution_x`,`resolution_y`,`size`,`time`,`mime`) " .
- " VALUES ('$file','$catalog_id','$title','$vcodec','$acodec','$rezx','$rezy','$filesize','$time','$mime')";
- $db_results = Dba::write($sql);
+ $sql = "INSERT INTO `video` (`file`,`catalog`,`title`,`video_codec`,`audio_codec`,`resolution_x`,`resolution_y`,`size`,`time`,`mime`) " .
+ " VALUES ('$file','$catalog_id','$title','$vcodec','$acodec','$rezx','$rezy','$filesize','$time','$mime')";
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // insert_local_video
@@ -2541,7 +2541,7 @@ class Catalog extends database_object {
$name = "M3U - " . basename($filename,'.m3u');
$playlist_id = Playlist::create($name,'public');
- if (!$playlist_id) {
+ if (!$playlist_id) {
$reason = _('Playlist creation error.');
return false;
}
@@ -2549,13 +2549,13 @@ class Catalog extends database_object {
/* Recreate the Playlist */
$playlist = new Playlist($playlist_id);
$playlist->add_songs($songs);
- $reason = sprintf(ngettext('Playlist Import and Recreate Successful. Total: %d Song',
+ $reason = sprintf(ngettext('Playlist Import and Recreate Successful. Total: %d Song',
'Playlist Import and Recreate Successful. Total: %d Songs',
count($songs)), count($songs));
return true;
}
/* HINT: filename */
- $reason = sprintf(ngettext('Parsing %s - Not Found: %d Song. Please check your m3u file.',
+ $reason = sprintf(ngettext('Parsing %s - Not Found: %d Song. Please check your m3u file.',
'Parsing %s - Not Found: %d Songs. Please check your m3u file.',
count($songs)), $filename, count($songs));
return false;
@@ -2578,10 +2578,10 @@ class Catalog extends database_object {
// Only if the previous one works do we go on
if (!$db_results) { return false; }
- $sql = "DELETE FROM `video` WHERE `catalog` = '$catalog_id'";
- $db_results = Dba::write($sql);
+ $sql = "DELETE FROM `video` WHERE `catalog` = '$catalog_id'";
+ $db_results = Dba::write($sql);
- if (!$db_results) { return false; }
+ if (!$db_results) { return false; }
// Next Remove the Catalog Entry it's self
$sql = "DELETE FROM `catalog` WHERE `id` = '$catalog_id'";
@@ -2601,7 +2601,7 @@ class Catalog extends database_object {
// Select all songs in catalog
if($this->id) {
$sql = "SELECT id FROM song WHERE catalog = '$this->id' ORDER BY album,track";
- }
+ }
else {
$sql = "SELECT id FROM song ORDER BY album,track";
}
@@ -2642,9 +2642,9 @@ class Catalog extends database_object {
$song = new Song($results['id']);
$song->format();
echo '"' . $song->id . '","' . $song->title . '","' . $song->f_artist_full . '","' . $song->f_album_full .
- '","' . $song->f_genre . '","' . $song->f_time . '","' . $song->f_track . '","' . $song->year .
- '","' . date("Y-m-d\TH:i:s\Z",$song->addition_time) . '","' . $song->f_bitrate .
- '","' . $song->played . '","' . $song->file . "\n";
+ '","' . $song->f_genre . '","' . $song->f_time . '","' . $song->f_track . '","' . $song->year .
+ '","' . date("Y-m-d\TH:i:s\Z",$song->addition_time) . '","' . $song->f_bitrate .
+ '","' . $song->played . '","' . $song->file . "\n";
}
break;
} // end switch
diff --git a/lib/class/config.class.php b/lib/class/config.class.php
index 1bd18806..601a7813 100644
--- a/lib/class/config.class.php
+++ b/lib/class/config.class.php
@@ -23,25 +23,25 @@
/* config class
* used to store static arrays of
* config values, can read from ini files
- *
+ *
* has static methods, this uses the global config
* creating a 'Config' object will allow for local
* config overides and/or local configs (for like dba)
- * The class should be a static var in the other classes
+ * The class should be a static var in the other classes
*/
class Config {
// These are the settings for this specific class
- private $_local = array();
+ private $_local = array();
// These are the global settings they go where it goes
- private static $_global = array();
+ private static $_global = array();
/**
* constructor
* This is what is called when the class is loaded
*/
- public function __construct() {
+ public function __construct() {
// Rien a faire
@@ -62,12 +62,12 @@ class Config {
* get_all
* This returns all of the current config variables as an array
*/
- public static function get_all() {
+ public static function get_all() {
- return self::$_global;
+ return self::$_global;
} // get_all
-
+
/**
* set
* This checks to see if this is an instance or procedure calls
@@ -75,13 +75,13 @@ class Config {
*/
public static function set($name, $value, $clobber = 0) {
- if (isset(self::$_global[$name]) && !$clobber) {
- Error::add('Config Global',"Trying to clobber'$name' without setting clobber");
+ if (isset(self::$_global[$name]) && !$clobber) {
+ Error::add('Config Global',"Trying to clobber'$name' without setting clobber");
return;
}
- else {
- self::$_global[$name] = $value;
- }
+ else {
+ self::$_global[$name] = $value;
+ }
} // set
@@ -90,12 +90,12 @@ class Config {
* This is the same as the set function except it takes an array as input
*/
public static function set_by_array($array, $clobber = 0) {
-
- foreach ($array as $name => $value) {
- self::set($name,$value,$clobber);
- }
+
+ foreach ($array as $name => $value) {
+ self::set($name,$value,$clobber);
+ }
} // set_by_array
-
+
} // end Config class
?>
diff --git a/lib/class/core.class.php b/lib/class/core.class.php
index 5162c20b..683107d3 100644
--- a/lib/class/core.class.php
+++ b/lib/class/core.class.php
@@ -31,9 +31,9 @@ class Core {
* constructor
* This doesn't do anything
*/
- private function __construct() {
+ private function __construct() {
- return false;
+ return false;
} // construction
@@ -42,25 +42,25 @@ class Core {
* This registers a form with a SID, inserts it into the session variables
* and then returns a string for use in the HTML form
*/
- public static function form_register($name,$type='post') {
+ public static function form_register($name,$type='post') {
// Make ourselves a nice little sid
$sid = md5(uniqid(rand(), true));
// Register it
- $_SESSION['forms'][$name] = array('sid'=>$sid,'expire'=>time() + Config::get('session_length'));
-
- switch ($type) {
- default:
- case 'post':
- $string = '<input type="hidden" name="form_validation" value="' . $sid . '" />';
- break;
- case 'get':
- $string = $sid;
- break;
+ $_SESSION['forms'][$name] = array('sid'=>$sid,'expire'=>time() + Config::get('session_length'));
+
+ switch ($type) {
+ default:
+ case 'post':
+ $string = '<input type="hidden" name="form_validation" value="' . $sid . '" />';
+ break;
+ case 'get':
+ $string = $sid;
+ break;
} // end switch on type
- return $string;
+ return $string;
} // form_register
@@ -69,30 +69,30 @@ class Core {
* This takes a form name and then compares it with the posted sid, if they don't match
* then it returns false and doesn't let the person continue
*/
- public static function form_verify($name,$method='post') {
+ public static function form_verify($name,$method='post') {
- switch ($method) {
- case 'post':
- $source = $_POST['form_validation'];
- break;
- case 'get':
+ switch ($method) {
+ case 'post':
+ $source = $_POST['form_validation'];
+ break;
+ case 'get':
$source = $_GET['form_validation'];
- break;
- case 'cookie':
- $source = $_COOKIE['form_validation'];
- break;
- case 'request':
- $source = $_REQUEST['form_validation'];
- break;
- }
-
- if ($source == $_SESSION['forms'][$name]['sid'] AND $_SESSION['forms'][$name]['expire'] > time()) {
- unset($_SESSION['forms'][$name]);
- return true;
- }
-
- unset($_SESSION['forms'][$name]);
- return false;
+ break;
+ case 'cookie':
+ $source = $_COOKIE['form_validation'];
+ break;
+ case 'request':
+ $source = $_REQUEST['form_validation'];
+ break;
+ }
+
+ if ($source == $_SESSION['forms'][$name]['sid'] AND $_SESSION['forms'][$name]['expire'] > time()) {
+ unset($_SESSION['forms'][$name]);
+ return true;
+ }
+
+ unset($_SESSION['forms'][$name]);
+ return false;
} // form_verify
@@ -101,21 +101,21 @@ class Core {
* This returns the dimensions of the passed song of the passed type
* returns an empty array if PHP-GD is not currently installed, returns
* false on error
- */
- public static function image_dimensions($image_data) {
+ */
+ public static function image_dimensions($image_data) {
- if (!function_exists('ImageCreateFromString')) { return false; }
+ if (!function_exists('ImageCreateFromString')) { return false; }
- $image = ImageCreateFromString($image_data);
+ $image = ImageCreateFromString($image_data);
- if (!$image) { return false; }
+ if (!$image) { return false; }
- $width = imagesx($image);
- $height = imagesy($image);
+ $width = imagesx($image);
+ $height = imagesy($image);
- if (!$width || !$height) { return false; }
+ if (!$width || !$height) { return false; }
- return array('width'=>$width,'height'=>$height);
+ return array('width'=>$width,'height'=>$height);
} // image_dimensions
diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php
index 4d592b0b..1c6afbdc 100644
--- a/lib/class/democratic.class.php
+++ b/lib/class/democratic.class.php
@@ -27,32 +27,32 @@
*/
class Democratic extends tmpPlaylist {
- public $name;
- public $cooldown;
- public $level;
- public $user;
- public $primary;
- public $base_playlist;
+ public $name;
+ public $cooldown;
+ public $level;
+ public $user;
+ public $primary;
+ public $base_playlist;
// Build local, buy local
- public $tmp_playlist;
- public $object_ids = array();
- public $vote_ids = array();
- public $user_votes = array();
+ public $tmp_playlist;
+ public $object_ids = array();
+ public $vote_ids = array();
+ public $user_votes = array();
/**
* constructor
* We need a constructor for this class. It does it's own thing now
*/
- public function __construct($id='') {
+ public function __construct($id='') {
- if (!$id) { return false; }
+ if (!$id) { return false; }
- $info = $this->get_info($id);
-
- foreach ($info as $key=>$value) {
- $this->$key = $value;
- }
+ $info = $this->get_info($id);
+
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
} // constructor
@@ -60,20 +60,20 @@ class Democratic extends tmpPlaylist {
* build_vote_cache
* This builds a vote cache of the objects we've got in the playlist
*/
- public static function build_vote_cache($ids) {
+ public static function build_vote_cache($ids) {
- if (!is_array($ids) OR !count($ids)) { return false; }
+ if (!is_array($ids) OR !count($ids)) { return false; }
- $idlist = '(' . implode(',',$ids) . ')';
+ $idlist = '(' . implode(',',$ids) . ')';
- $sql = "SELECT `object_id`,COUNT(`user`) AS `count` FROM user_vote WHERE `object_id` IN $idlist GROUP BY `object_id`";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `object_id`,COUNT(`user`) AS `count` FROM user_vote WHERE `object_id` IN $idlist GROUP BY `object_id`";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('democratic_vote',$row['object_id'],$row['count']);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('democratic_vote',$row['object_id'],$row['count']);
+ }
- return true;
+ return true;
} // build_vote_cache
@@ -82,11 +82,11 @@ class Democratic extends tmpPlaylist {
* This function just returns true / false if the current democraitc playlist
* is currently enabled / configured
*/
- public function is_enabled() {
+ public function is_enabled() {
- if ($this->tmp_playlist) { return true; }
+ if ($this->tmp_playlist) { return true; }
- return false;
+ return false;
} // is_enabled
@@ -94,16 +94,16 @@ class Democratic extends tmpPlaylist {
* set_parent
* This returns the tmpPlaylist for this democratic play instance
*/
- public function set_parent() {
+ public function set_parent() {
- $demo_id = Dba::escape($this->id);
+ $demo_id = Dba::escape($this->id);
- $sql = "SELECT * FROM `tmp_playlist` WHERE `session`='$demo_id'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `tmp_playlist` WHERE `session`='$demo_id'";
+ $db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
+ $row = Dba::fetch_assoc($db_results);
- $this->tmp_playlist = $row['id'];
+ $this->tmp_playlist = $row['id'];
} // set_parent
@@ -111,24 +111,24 @@ class Democratic extends tmpPlaylist {
/**
* set_user_preferences
* This sets up a (or all) user(s) to use democratic play. This sets their play method
- * and playlist method (clear on send) If no user is passed it does it for everyone and
+ * and playlist method (clear on send) If no user is passed it does it for everyone and
* also locks down the ability to change to admins only
*/
- public static function set_user_preferences($user=NULL) {
+ public static function set_user_preferences($user=NULL) {
//FIXME: Code in single user stuff
- $preference_id = Preference::id_from_name('play_type');
- Preference::update_level($preference_id,'75');
- Preference::update_all($preference_id,'democratic');
+ $preference_id = Preference::id_from_name('play_type');
+ Preference::update_level($preference_id,'75');
+ Preference::update_all($preference_id,'democratic');
- $allow_demo = Preference::id_from_name('allow_democratic_playback');
- Preference::update_all($allow_demo,'1');
+ $allow_demo = Preference::id_from_name('allow_democratic_playback');
+ Preference::update_all($allow_demo,'1');
- $play_method = Preference::id_from_name('playlist_method');
- Preference::update_all($play_method,'clear');
+ $play_method = Preference::id_from_name('playlist_method');
+ Preference::update_all($play_method,'clear');
- return true;
+ return true;
} // set_user_preferences
@@ -136,28 +136,28 @@ class Democratic extends tmpPlaylist {
* format
* This makes the objects variables all purrty so that they can be displayed
*/
- public function format() {
-
- $this->f_cooldown = $this->cooldown . ' ' . _('minutes');
- $this->f_primary = $this->primary ? _('Primary') : '';
-
- switch ($this->level) {
- case '5':
- $this->f_level = _('Guest');
- break;
- case '25':
- $this->f_level = _('User');
- break;
- case '50':
- $this->f_level = _('Content Manager');
- break;
- case '75':
- $this->f_level = _('Catalog Manager');
- break;
- case '100':
- $this->f_level = _('Admin');
- break;
- }
+ public function format() {
+
+ $this->f_cooldown = $this->cooldown . ' ' . _('minutes');
+ $this->f_primary = $this->primary ? _('Primary') : '';
+
+ switch ($this->level) {
+ case '5':
+ $this->f_level = _('Guest');
+ break;
+ case '25':
+ $this->f_level = _('User');
+ break;
+ case '50':
+ $this->f_level = _('Content Manager');
+ break;
+ case '75':
+ $this->f_level = _('Catalog Manager');
+ break;
+ case '100':
+ $this->f_level = _('Admin');
+ break;
+ }
} // format
@@ -166,21 +166,21 @@ class Democratic extends tmpPlaylist {
* This returns all of the current valid 'Democratic' Playlists
* that have been created.
*/
- public static function get_playlists() {
+ public static function get_playlists() {
- // Pull all tmp playlsits with a session of < 0 (as those are fake)
+ // Pull all tmp playlsits with a session of < 0 (as those are fake)
// This is kind of hackish, should really think about tweaking the db
- // and doing this right.
- $sql = "SELECT `id` FROM `democratic` ORDER BY `name`";
- $db_results = Dba::read($sql);
+ // and doing this right.
+ $sql = "SELECT `id` FROM `democratic` ORDER BY `name`";
+ $db_results = Dba::read($sql);
- $results = array();
+ $results = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
- return $results;
+ return $results;
} // get_playlists
@@ -189,22 +189,22 @@ class Democratic extends tmpPlaylist {
* This returns the curren users current playlist, or if specified
* this current playlist of the user
*/
- public static function get_current_playlist() {
+ public static function get_current_playlist() {
- $democratic_id = Config::get('democratic_id');
+ $democratic_id = Config::get('democratic_id');
- if (!$democratic_id) {
- $level = Dba::escape($GLOBALS['user']->access);
- $sql = "SELECT `id` FROM `democratic` WHERE `level` <= '$level' " .
- " ORDER BY `level` DESC,`primary` DESC";
- $db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
+ if (!$democratic_id) {
+ $level = Dba::escape($GLOBALS['user']->access);
+ $sql = "SELECT `id` FROM `democratic` WHERE `level` <= '$level' " .
+ " ORDER BY `level` DESC,`primary` DESC";
+ $db_results = Dba::read($sql);
+ $row = Dba::fetch_assoc($db_results);
$democratic_id = $row['id'];
- }
+ }
- $object = new Democratic($democratic_id);
+ $object = new Democratic($democratic_id);
- return $object;
+ return $object;
} // get_current_playlist
@@ -214,7 +214,7 @@ class Democratic extends tmpPlaylist {
* has gotten a little more complicated because of type, the values are an array
* 0 being ID 1 being TYPE
* FIXME: This is too complex, it makes my brain hurt
- * [VOTE COUNT]
+ * [VOTE COUNT]
* [DATE OF NEWEST VOTE]
* [ROW ID]
* [OBJECT_ID]
@@ -237,46 +237,46 @@ class Democratic extends tmpPlaylist {
/* Define the array */
$items = array();
- $votes = array();
- $object_ids = array();
+ $votes = array();
+ $object_ids = array();
// Itterate and build the sortable array
while ($results = Dba::fetch_assoc($db_results)) {
-
+
// Extra set of data for caching!
- $this->object_ids[] = $results['object_id'];
- $this->vote_ids[] = $results['vote_id'];
+ $this->object_ids[] = $results['object_id'];
+ $this->vote_ids[] = $results['vote_id'];
// First build a variable that holds the number of votes for an object
$name = 'vc_' . $results['object_id'];
// Check if the vote is older then our current vote for this object
- if ($votes[$results['object_id']] < $results['date'] OR !isset($votes[$results['object_id']])) {
- $votes[$results['object_id']] = $results['date'];
- }
+ if ($votes[$results['object_id']] < $results['date'] OR !isset($votes[$results['object_id']])) {
+ $votes[$results['object_id']] = $results['date'];
+ }
// Append one to the vote
- ${$name}++;
- $primary_key = ${$name};
- $secondary_key = $votes[$results['object_id']];
+ ${$name}++;
+ $primary_key = ${$name};
+ $secondary_key = $votes[$results['object_id']];
$items[$primary_key][$secondary_key][$results['id']] = array('object_id'=>$results['object_id'],'object_type'=>$results['object_type'],'id'=>$results['id']);
} // gather data
// Sort highest voted stuff to the top
- krsort($items);
+ krsort($items);
- $sorted_items = array();
+ $sorted_items = array();
// re-collapse the array
- foreach ($items as $vote_count=>$date_array) {
- ksort($date_array);
- foreach ($date_array as $object_array) {
- foreach ($object_array as $key=>$sorted_array) {
+ foreach ($items as $vote_count=>$date_array) {
+ ksort($date_array);
+ foreach ($date_array as $object_array) {
+ foreach ($object_array as $key=>$sorted_array) {
$sorted_items[$key] = $sorted_array;
- }
- }
- }
+ }
+ }
+ }
return $sorted_items;
@@ -288,7 +288,7 @@ class Democratic extends tmpPlaylist {
*/
public function play_url() {
- $link = Stream::get_base_url() . 'uid=' . scrub_out($GLOBALS['user']->id) . '&demo_id=' . scrub_out($this->id);
+ $link = Stream::get_base_url() . 'uid=' . scrub_out($GLOBALS['user']->id) . '&demo_id=' . scrub_out($this->id);
return $link;
@@ -296,22 +296,22 @@ class Democratic extends tmpPlaylist {
/**
* get_next_object
- * This returns the next object in the tmp_playlist most of the time this
+ * This returns the next object in the tmp_playlist most of the time this
* will just be the top entry, but if there is a base_playlist and no
* items in the playlist then it returns a random entry from the base_playlist
*/
public function get_next_object($offset='') {
-
- $offset = $offset ? intval($offset) : '0';
+
+ $offset = $offset ? intval($offset) : '0';
// We have to get all because of the pysco sorting
- $items = self::get_items();
+ $items = self::get_items();
- if (count($items) > $offset) {
- $array = array_slice($items,$offset,1);
- $item = array_shift($array);
+ if (count($items) > $offset) {
+ $array = array_slice($items,$offset,1);
+ $item = array_shift($array);
$results['object_id'] = $item['object_id'];
- }
+ }
/* If nothing was found and this is a voting playlist then get from base_playlist */
if (!$results['object_id']) {
@@ -321,7 +321,7 @@ class Democratic extends tmpPlaylist {
/* We need to pull a random one from the base_playlist */
$base_playlist = new Playlist($this->base_playlist);
$data = $base_playlist->get_random_items(1);
- $results['object_id'] = $data['0']['object_id'];
+ $results['object_id'] = $data['0']['object_id'];
}
else {
$sql = "SELECT `id` as `object_id` FROM `song` WHERE `enabled`='1' ORDER BY RAND() LIMIT 1";
@@ -338,42 +338,42 @@ class Democratic extends tmpPlaylist {
* get_uid_from_object_id
* This takes an object_id and an object type and returns the ID for the row
*/
- public function get_uid_from_object_id($object_id,$object_type='') {
+ public function get_uid_from_object_id($object_id,$object_type='') {
- $object_id = Dba::escape($object_id);
- $object_type = $object_type ? Dba::escape($object_type) : 'song';
+ $object_id = Dba::escape($object_id);
+ $object_type = $object_type ? Dba::escape($object_type) : 'song';
$tmp_id = Dba::escape($this->tmp_playlist);
- $sql = "SELECT `tmp_playlist_data`.`id` FROM `tmp_playlist_data` WHERE `object_type`='$object_type' AND " .
- "`tmp_playlist`='$tmp_id' AND `object_id`='$object_id'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `tmp_playlist_data`.`id` FROM `tmp_playlist_data` WHERE `object_type`='$object_type' AND " .
+ "`tmp_playlist`='$tmp_id' AND `object_id`='$object_id'";
+ $db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
+ $row = Dba::fetch_assoc($db_results);
- return $row['id'];
+ return $row['id'];
} // get_uid_from_object_id
/**
* get_cool_songs
* This returns all of the song_ids for songs that have happened within the last 'cooldown'
- * for this user.
+ * for this user.
*/
- public function get_cool_songs() {
+ public function get_cool_songs() {
// Convert cooldown time to a timestamp in the past
- $cool_time = time() - ($this->cooldown * 60);
+ $cool_time = time() - ($this->cooldown * 60);
- $song_ids = Stats::get_object_history($GLOBALS['user']->id,$cool_time);
+ $song_ids = Stats::get_object_history($GLOBALS['user']->id,$cool_time);
- return $song_ids;
+ return $song_ids;
} // get_cool_songs
/**
* vote
* This function is called by users to vote on a system wide playlist
- * This adds the specified objects to the tmp_playlist and adds a 'vote'
+ * This adds the specified objects to the tmp_playlist and adds a 'vote'
* by this user, naturally it checks to make sure that the user hasn't
* already voted on any of these objects
*/
@@ -381,8 +381,8 @@ class Democratic extends tmpPlaylist {
/* Itterate through the objects if no vote, add to playlist and vote */
foreach ($items as $element) {
- $type = array_shift($element);
- $object_id = array_shift($element);
+ $type = array_shift($element);
+ $object_id = array_shift($element);
if (!$this->has_vote($object_id,$type)) {
$this->add_vote($object_id,$type);
}
@@ -397,9 +397,9 @@ class Democratic extends tmpPlaylist {
public function has_vote($object_id,$type='') {
$tmp_id = Dba::escape($this->tmp_playlist);
- $object_id = Dba::escape($object_id);
- $type = $type ? Dba::escape($type) : 'song';
- $user_id = Dba::escape($GLOBALS['user']->id);
+ $object_id = Dba::escape($object_id);
+ $type = $type ? Dba::escape($type) : 'song';
+ $user_id = Dba::escape($GLOBALS['user']->id);
/* Query vote table */
$sql = "SELECT tmp_playlist_data.object_id FROM `user_vote` " .
@@ -423,13 +423,13 @@ class Democratic extends tmpPlaylist {
* This takes a object id and user and actually inserts the row
*/
public function add_vote($object_id,$object_type='') {
-
+
$object_id = Dba::escape($object_id);
$tmp_playlist = Dba::escape($this->tmp_playlist);
- $object_type = $object_type ? Dba::escape($object_type) : 'song';
- $media = new $object_type($object_id);
- $track = isset($media->track) ? "'" . intval($media->track) . "'" : "NULL";
-
+ $object_type = $object_type ? Dba::escape($object_type) : 'song';
+ $media = new $object_type($object_id);
+ $track = isset($media->track) ? "'" . intval($media->track) . "'" : "NULL";
+
/* If it's on the playlist just vote */
$sql = "SELECT `id` FROM `tmp_playlist_data` " .
"WHERE `tmp_playlist_data`.`object_id`='$object_id' AND `tmp_playlist_data`.`tmp_playlist`='$tmp_playlist'";
@@ -478,17 +478,17 @@ class Democratic extends tmpPlaylist {
* delete_votes
* This removes the votes for the specified object on the current playlist
*/
- public function delete_votes($row_id) {
+ public function delete_votes($row_id) {
- $row_id = Dba::escape($row_id);
+ $row_id = Dba::escape($row_id);
- $sql = "DELETE FROM `user_vote` WHERE `object_id`='$row_id'";
- $db_results = Dba::write($sql);
+ $sql = "DELETE FROM `user_vote` WHERE `object_id`='$row_id'";
+ $db_results = Dba::write($sql);
- $sql = "DELETE FROM `tmp_playlist_data` WHERE `id`='$row_id'";
- $db_results = Dba::write($sql);
+ $sql = "DELETE FROM `tmp_playlist_data` WHERE `id`='$row_id'";
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // delete_votes
@@ -496,19 +496,19 @@ class Democratic extends tmpPlaylist {
* delete
* This deletes a democratic playlist
*/
- public static function delete($democratic_id) {
-
- $democratic_id = Dba::escape($democratic_id);
+ public static function delete($democratic_id) {
- $sql = "DELETE FROM `democratic` WHERE `id`='$democratic_id'";
- $db_results = Dba::write($sql);
+ $democratic_id = Dba::escape($democratic_id);
- $sql = "DELETE FROM `tmp_playlist` WHERE `session`='$democratic_id'";
- $db_results = Dba::write($sql);
-
- self::prune_tracks();
+ $sql = "DELETE FROM `democratic` WHERE `id`='$democratic_id'";
+ $db_results = Dba::write($sql);
+
+ $sql = "DELETE FROM `tmp_playlist` WHERE `session`='$democratic_id'";
+ $db_results = Dba::write($sql);
+
+ self::prune_tracks();
- return true;
+ return true;
} // delete
@@ -516,17 +516,17 @@ class Democratic extends tmpPlaylist {
* update
* This updates an existing democratic playlist item. It takes a key'd array just like the create
*/
- public function update($data) {
+ public function update($data) {
- $name = Dba::escape($data['name']);
- $base = Dba::escape($data['democratic']);
- $cool = Dba::escape($data['cooldown']);
- $id = Dba::escape($this->id);
+ $name = Dba::escape($data['name']);
+ $base = Dba::escape($data['democratic']);
+ $cool = Dba::escape($data['cooldown']);
+ $id = Dba::escape($this->id);
- $sql = "UPDATE `democratic` SET `name`='$name', `base_playlist`='$base',`cooldown`='$cool' WHERE `id`='$id'";
- $db_results = Dba::write($sql);
+ $sql = "UPDATE `democratic` SET `name`='$name', `base_playlist`='$base',`cooldown`='$cool' WHERE `id`='$id'";
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // update
@@ -534,26 +534,26 @@ class Democratic extends tmpPlaylist {
* create
* This is the democratic play create function it inserts this into the democratic table
*/
- public static function create($data) {
+ public static function create($data) {
// Clean up the input
- $name = Dba::escape($data['name']);
- $base = Dba::escape($data['democratic']);
- $cool = Dba::escape($data['cooldown']);
- $level = Dba::escape($data['level']);
- $default = Dba::escape($data['make_default']);
- $user = Dba::escape($GLOBALS['user']->id);
-
- $sql = "INSERT INTO `democratic` (`name`,`base_playlist`,`cooldown`,`level`,`user`,`primary`) " .
- "VALUES ('$name','$base','$cool','$level','$user','$default')";
- $db_results = Dba::write($sql);
+ $name = Dba::escape($data['name']);
+ $base = Dba::escape($data['democratic']);
+ $cool = Dba::escape($data['cooldown']);
+ $level = Dba::escape($data['level']);
+ $default = Dba::escape($data['make_default']);
+ $user = Dba::escape($GLOBALS['user']->id);
+
+ $sql = "INSERT INTO `democratic` (`name`,`base_playlist`,`cooldown`,`level`,`user`,`primary`) " .
+ "VALUES ('$name','$base','$cool','$level','$user','$default')";
+ $db_results = Dba::write($sql);
- if ($db_results) {
- $insert_id = Dba::insert_id();
- parent::create($insert_id,'vote','song');
- }
+ if ($db_results) {
+ $insert_id = Dba::insert_id();
+ parent::create($insert_id,'vote','song');
+ }
- return $db_results;
+ return $db_results;
} // create
@@ -562,7 +562,7 @@ class Democratic extends tmpPlaylist {
* This replaces the normal prune tracks and correctly removes the votes
* as well
*/
- public static function prune_tracks() {
+ public static function prune_tracks() {
// This deletes data without votes, if it's a voting democratic playlist
$sql = "DELETE FROM `tmp_playlist_data` USING `tmp_playlist_data` " .
@@ -578,7 +578,7 @@ class Democratic extends tmpPlaylist {
/**
* clear
* This is really just a wrapper function, it clears the entire playlist
- * including all votes etc.
+ * including all votes etc.
*/
public function clear() {
@@ -594,7 +594,7 @@ class Democratic extends tmpPlaylist {
self::prune_tracks();
// Clean the votes
- self::clear_votes();
+ self::clear_votes();
return true;
@@ -604,14 +604,14 @@ class Democratic extends tmpPlaylist {
* clean_votes
* This removes in left over garbage in the votes table
*/
- public function clear_votes() {
+ public function clear_votes() {
- $sql = "DELETE FROM `user_vote` USING `user_vote` " .
- "LEFT JOIN `tmp_playlist_data` ON `user_vote`.`object_id`=`tmp_playlist_data`.`id` " .
- "WHERE `tmp_playlist_data`.`id` IS NULL";
- $db_results = Dba::write($sql);
+ $sql = "DELETE FROM `user_vote` USING `user_vote` " .
+ "LEFT JOIN `tmp_playlist_data` ON `user_vote`.`object_id`=`tmp_playlist_data`.`id` " .
+ "WHERE `tmp_playlist_data`.`id` IS NULL";
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // clear_votes
@@ -621,9 +621,9 @@ class Democratic extends tmpPlaylist {
*/
public function get_vote($object_id) {
- if (parent::is_cached('democratic_vote',$object_id)) {
- return parent::get_from_cache('democratic_vote',$object_id);
- }
+ if (parent::is_cached('democratic_vote',$object_id)) {
+ return parent::get_from_cache('democratic_vote',$object_id);
+ }
$object_id = Dba::escape($object_id);
@@ -642,9 +642,9 @@ class Democratic extends tmpPlaylist {
* This returns the users that voted for the specified object
* This is an array of user ids
*/
- public function get_voters($object_id) {
+ public function get_voters($object_id) {
- return parent::get_from_cache('democratic_voters',$object_id);
+ return parent::get_from_cache('democratic_voters',$object_id);
} // get_voters
diff --git a/lib/class/error.class.php b/lib/class/error.class.php
index 2da2a7d1..2ed4a034 100644
--- a/lib/class/error.class.php
+++ b/lib/class/error.class.php
@@ -16,7 +16,7 @@
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,
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
*/
@@ -26,7 +26,7 @@
* This is the baic error class, its better now that we can use php5
* hello static functions and variables
*/
-class Error {
+class Error {
private static $state = false; // set to one when an error occurs
private static $errors = array(); // Errors array key'd array with errors that have occured
@@ -35,62 +35,62 @@ class Error {
* __constructor
* This does nothing... amazing isn't it!
*/
- private function __construct() {
+ private function __construct() {
// Rien a faire
-
+
} // __construct
/**
* __destruct
* This saves all of the errors that are left into the session
*/
- public function __destruct() {
+ public function __destruct() {
- foreach (self::$errors as $key=>$error) {
- $_SESSION['errors'][$key] = $error;
- }
+ foreach (self::$errors as $key=>$error) {
+ $_SESSION['errors'][$key] = $error;
+ }
} // __destruct
/**
* add
- * This is a public static function it adds a new error message to the array
+ * This is a public static function it adds a new error message to the array
* It can optionally clobber rather then adding to the error message
*/
- public static function add($name,$message,$clobber=0) {
+ public static function add($name,$message,$clobber=0) {
- // Make sure its set first
- if (!isset(Error::$errors[$name])) {
- Error::$errors[$name] = $message;
+ // Make sure its set first
+ if (!isset(Error::$errors[$name])) {
+ Error::$errors[$name] = $message;
Error::$state = 1;
- $_SESSION['errors'][$key] = $message;
- }
+ $_SESSION['errors'][$key] = $message;
+ }
// They want us to clobber it
- elseif ($clobber) {
+ elseif ($clobber) {
Error::$state = 1;
Error::$errors[$name] = $message;
- $_SESSION['errors'][$key] = $message;
- }
+ $_SESSION['errors'][$key] = $message;
+ }
// They want us to append the error, add a BR\n and then the message
- else {
+ else {
Error::$state = 1;
Error::$errors[$name] .= "<br />\n" . $message;
- $_SESSION['errors'][$key] .= "<br />\n" . $message;
- }
+ $_SESSION['errors'][$key] .= "<br />\n" . $message;
+ }
} // add
- /**
+ /**
* occurred
* This returns true / false if an error has occured anywhere
*/
- public static function occurred() {
+ public static function occurred() {
- if (self::$state == '1') { return true; }
+ if (self::$state == '1') { return true; }
- return false;
+ return false;
} // occurred
@@ -98,9 +98,9 @@ class Error {
* get
* This returns an error by name
*/
- public static function get($name) {
+ public static function get($name) {
- if (!isset(Error::$errors[$name])) { return ''; }
+ if (!isset(Error::$errors[$name])) { return ''; }
return Error::$errors[$name];
@@ -111,27 +111,27 @@ class Error {
* This prints the error out with a standard Error class span
* Ben Goska: Renamed from print to display, print is reserved
*/
- public static function display($name) {
+ public static function display($name) {
// Be smart about this, if no error don't print
- if (!isset(Error::$errors[$name])) { return ''; }
+ if (!isset(Error::$errors[$name])) { return ''; }
echo '<span class="error">' . Error::$errors[$name] . '</span>';
} // display
/**
- * auto_init
+ * auto_init
* This loads the errors from the session back into Ampache
*/
- public static function auto_init() {
+ public static function auto_init() {
- if (!is_array($_SESSION['errors'])) { return false; }
+ if (!is_array($_SESSION['errors'])) { return false; }
- // Re-insert them
- foreach ($_SESSION['errors'] as $key=>$error) {
+ // Re-insert them
+ foreach ($_SESSION['errors'] as $key=>$error) {
self::add($key,$error);
- }
+ }
} // auto_init
diff --git a/lib/class/flag.class.php b/lib/class/flag.class.php
index 8105a247..3394019d 100644
--- a/lib/class/flag.class.php
+++ b/lib/class/flag.class.php
@@ -17,17 +17,17 @@
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.
*/
/**
* Flag Class
- * This handles flagging of songs, albums and artists
+ * This handles flagging of songs, albums and artists
*/
class Flag extends database_object {
- public $id;
+ public $id;
public $user;
public $object_id;
public $object_type;
@@ -44,13 +44,13 @@ class Flag extends database_object {
* Constructor
* This takes a flagged.id and then pulls in the information for said flag entry
*/
- public function __construct($flag_id) {
+ public function __construct($flag_id) {
$info = $this->get_info($flag_id,'flagged');
-
- foreach ($info as $key=>$value) {
- $this->$key = $value;
- }
+
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
return true;
@@ -61,18 +61,18 @@ class Flag extends database_object {
* This takes an array of ids and builds up a nice little cache
* for us
*/
- public static function build_cache($ids) {
+ public static function build_cache($ids) {
- if (!is_array($ids) OR !count($ids)) { return false; }
+ if (!is_array($ids) OR !count($ids)) { return false; }
- $idlist = '(' . implode(',',$ids) . ')';
+ $idlist = '(' . implode(',',$ids) . ')';
- $sql = "SELECT * FROM `flagged` WHERE `id` IN $idlist";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `flagged` WHERE `id` IN $idlist";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('flagged',$row['id'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('flagged',$row['id'],$row);
+ }
} // build_cache
@@ -81,27 +81,27 @@ class Flag extends database_object {
* This takes an array of ids and builds a map cache to avoid some of the object_type calls
* we would normally have to make
*/
- public static function build_map_cache($ids,$type) {
+ public static function build_map_cache($ids,$type) {
- if (!is_array($ids) OR !count($ids)) { return false; }
+ if (!is_array($ids) OR !count($ids)) { return false; }
- $idlist = '(' . implode(',',$ids) . ')';
- $type = Dba::escape($type);
+ $idlist = '(' . implode(',',$ids) . ')';
+ $type = Dba::escape($type);
- $sql = "SELECT * FROM `flagged` " .
- "WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id` IN $idlist";
- $db_results = Dba::read($sql);
-
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[$row['object_id']] = $row;
- }
-
- // Itterate through the passed ids as we need to cache 'nulls'
- foreach ($ids as $id) {
- parent::add_to_cache('flagged_' . $type,$id,$results[$id]);
- }
+ $sql = "SELECT * FROM `flagged` " .
+ "WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id` IN $idlist";
+ $db_results = Dba::read($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[$row['object_id']] = $row;
+ }
+
+ // Itterate through the passed ids as we need to cache 'nulls'
+ foreach ($ids as $id) {
+ parent::add_to_cache('flagged_' . $type,$id,$results[$id]);
+ }
- return true;
+ return true;
} // build_map_cache
@@ -109,23 +109,23 @@ class Flag extends database_object {
* has_flag
* Static function, tries to check the cache, but falls back on a query
*/
- public static function has_flag($id,$type) {
+ public static function has_flag($id,$type) {
+
+ if (parent::is_cached('flagged_' . $type,$id)) {
+ $data = parent::get_from_cache('flagged_' . $type,$id);
+ return $data['date'];
+ }
- if (parent::is_cached('flagged_' . $type,$id)) {
- $data = parent::get_from_cache('flagged_' . $type,$id);
- return $data['date'];
- }
-
// Ok we have to query this
- $type = Dba::escape($type);
+ $type = Dba::escape($type);
- $sql = "SELECT * FROM `flagged` WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id`='$id'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `flagged` WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id`='$id'";
+ $db_results = Dba::read($sql);
$row = Dba::fetch_assoc($db_results);
- parent::add_to_cache('flagged_' . $type,$row['object_id'],$row);
+ parent::add_to_cache('flagged_' . $type,$row['object_id'],$row);
- return $row['date'];
+ return $row['date'];
} // has_flag
@@ -134,19 +134,19 @@ class Flag extends database_object {
* This returns the id's of the most recently flagged songs, it takes an int
* as an argument which is the count of the object you want to return
*/
- public static function get_recent($count=0) {
+ public static function get_recent($count=0) {
- if ($count) { $limit = " LIMIT " . intval($count); }
+ if ($count) { $limit = " LIMIT " . intval($count); }
$results = array();
$sql = "SELECT id FROM flagged ORDER BY date " . $limit;
$db_results = Dba::read($sql);
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id'];
}
-
+
return $results;
} // get_recent
@@ -156,18 +156,18 @@ class Flag extends database_object {
* This returns all of the songs that have been disabled, this is
* a form of being flagged
*/
- public static function get_disabled() {
+ public static function get_disabled() {
- $sql = "SELECT `id` FROM `song` WHERE `enabled`='0'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id` FROM `song` WHERE `enabled`='0'";
+ $db_results = Dba::read($sql);
+
+ $results = array();
- $results = array();
-
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
- return $results;
+ return $results;
} // get_disabled
@@ -176,10 +176,10 @@ class Flag extends database_object {
* This returns an array of ids of flagged songs if no limit is passed
* it gets everything
*/
- public static function get_all($count=0) {
+ public static function get_all($count=0) {
+
+ if ($count) { $limit_clause = "LIMIT " . intval($count); }
- if ($count) { $limit_clause = "LIMIT " . intval($count); }
-
$sql = "SELECT `id` FROM `flagged` $limit_clause";
$db_results = Dba::read($sql);
@@ -187,7 +187,7 @@ class Flag extends database_object {
$results = array();
/* While the query */
- while ($row = Dba::fetch_assoc($db_results)) {
+ while ($row = Dba::fetch_assoc($db_results)) {
$results[] = $row['id'];
}
@@ -199,17 +199,17 @@ class Flag extends database_object {
* get_approved
* This returns an array of approved flagged songs
*/
- public static function get_approved() {
+ public static function get_approved() {
$sql = "SELECT `id` FROM `flagged` WHERE `approved`='1'";
- $db_results = Dba::read($sql);
+ $db_results = Dba::read($sql);
/* Default the results array */
- $results = array();
+ $results = array();
/* While it */
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r['id'];
}
@@ -222,8 +222,8 @@ class Flag extends database_object {
* This adds a flag entry for an item, it takes an id, a type, the flag type
* and a comment and then inserts the mofo
*/
- public static function add($id,$type,$flag,$comment) {
-
+ public static function add($id,$type,$flag,$comment) {
+
$id = Dba::escape($id);
$type = Dba::escape($type);
$flag = self::validate_flag($flag);
@@ -233,9 +233,9 @@ class Flag extends database_object {
$approved = '0';
/* If they are an content manager or higher, it's auto approved */
- if (Access::check('interface','75')) { $approved = '1'; }
+ if (Access::check('interface','75')) { $approved = '1'; }
- $sql = "INSERT INTO `flagged` (`object_id`,`object_type`,`flag`,`comment`,`date`,`approved`,`user`) VALUES " .
+ $sql = "INSERT INTO `flagged` (`object_id`,`object_type`,`flag`,`comment`,`date`,`approved`,`user`) VALUES " .
" ('$id','$type','$flag','$comment','$time','$approved','$user')";
$db_results = Dba::write($sql);
@@ -249,18 +249,18 @@ class Flag extends database_object {
* state, in a perfect world, I could just roll the changes back... not until 3.4
* or.. haha 3.5!
*/
- public function delete() {
+ public function delete() {
// Re-scan the file
- $song = new Song($this->object_id);
- $info = Catalog::update_media_from_tags($song);
+ $song = new Song($this->object_id);
+ $info = Catalog::update_media_from_tags($song);
// Delete the row
$sql = "DELETE FROM `flagged` WHERE `id`='$this->id'";
$db_results = Dba::write($sql);
- // Reset the Last-Updated date so that it'll get re-scaned
- $song->update_utime($song->id,1);
+ // Reset the Last-Updated date so that it'll get re-scaned
+ $song->update_utime($song->id,1);
return true;
@@ -271,44 +271,44 @@ class Flag extends database_object {
* This approves the current flag object ($this->id) by setting approved to
* 1
*/
- public function approve() {
+ public function approve() {
$sql = "UPDATE `flagged` SET `approved`='1' WHERE `id`='$this->id'";
$db_results = Dba::write($sql);
- $this->approved = 1;
+ $this->approved = 1;
return true;
-
+
} // approve
-
+
/**
* format
* This function figures out what kind of object we've got and sets up all the
* vars all nice and fuzzy like
*/
- public function format() {
+ public function format() {
- switch ($this->object_type) {
- case 'song':
+ switch ($this->object_type) {
+ case 'song':
$song = new Song($this->object_id);
- $song->format();
+ $song->format();
$this->f_name = $song->f_link;
break;
- } // end switch on type
+ } // end switch on type
$client = new User($this->user);
- $client->format();
- $this->f_user = $client->f_link;
+ $client->format();
+ $this->f_user = $client->f_link;
} // format
-
+
/**
* print_status
* This prints out a userfriendly version of the current status for this flagged
* object
*/
- public function print_status() {
+ public function print_status() {
if ($this->approved) { echo _('Approved'); }
else { echo _('Pending'); }
@@ -319,20 +319,20 @@ class Flag extends database_object {
* print_flag
* This prints out a userfriendly version of the current flag type
*/
- public function print_flag() {
+ public function print_flag() {
- switch ($this->flag) {
+ switch ($this->flag) {
case 'delete':
$name = _('Delete');
break;
case 'retag':
- $name = _('Re-Tag');
+ $name = _('Re-Tag');
break;
case 'reencode':
$name = _('Re-encode');
break;
case 'other':
- $name = _('Other');
+ $name = _('Other');
break;
default:
$name = _('Unknown');
@@ -340,7 +340,7 @@ class Flag extends database_object {
} // end switch
echo $name;
-
+
} // print_flag
/**
@@ -348,17 +348,17 @@ class Flag extends database_object {
* This takes a flag input and makes sure it's one of the reigstered
* and valid 'flag' values
*/
- public static function validate_flag($flag) {
-
- switch ($flag) {
- case 'delete':
- case 'retag':
- case 'reencode':
- case 'other':
- return $flag;
+ public static function validate_flag($flag) {
+
+ switch ($flag) {
+ case 'delete':
+ case 'retag':
+ case 'reencode':
+ case 'other':
+ return $flag;
break;
- default:
- return 'other';
+ default:
+ return 'other';
break;
} // end switch
@@ -366,14 +366,14 @@ class Flag extends database_object {
/**
* fill_tags
- * This is used by the write_tags script.
+ * This is used by the write_tags script.
*/
public static function fill_tags( $tagWriter, $song, $type = 'comment' ) {
// Set all of the attributes for the tag to be written(All pulled from the song object)
// Use a function since ID3v1, ID3v2, and vorbis/flac/ape are different
- switch ($type) {
- case 'comment':
+ switch ($type) {
+ case 'comment':
$tagWriter->comments['title'] = $song->title;
$tagWriter->comments['date'] = $song->year;
$tagWriter->comments['year'] = $song->year;
@@ -384,7 +384,7 @@ class Flag extends database_object {
$tagWriter->comments['artist'] = $song->get_artist_name();
$tagWriter->comments['genre'] = $song->get_genre_name();
$tagWriter->comments['track'] = $song->track;
- break;
+ break;
case 'id3v1':
$tagWriter->title = $song->title;
$tagWriter->year = $song->year;
diff --git a/lib/class/localplay.abstract.php b/lib/class/localplay.abstract.php
index 6cc3d078..c544c14c 100644
--- a/lib/class/localplay.abstract.php
+++ b/lib/class/localplay.abstract.php
@@ -23,85 +23,85 @@
/*
* This is the abstract class for any localplay controller
*/
-abstract class localplay_controller {
-
+abstract class localplay_controller {
+
// Required Functions
abstract public function add($objects); // Takes an array of song_ids
abstract public function delete_track($object_id); // Takes a single object_id and removes it from the playlist
- abstract public function play();
- abstract public function stop();
- abstract public function get();
- abstract public function connect();
- abstract public function status();
+ abstract public function play();
+ abstract public function stop();
+ abstract public function get();
+ abstract public function connect();
+ abstract public function status();
abstract public function get_version(); // Returns the version of this plugin
- abstract public function get_description(); // Returns the description
- abstract public function is_installed(); // Returns an boolean t/f
- abstract public function install();
- abstract public function uninstall();
+ abstract public function get_description(); // Returns the description
+ abstract public function is_installed(); // Returns an boolean t/f
+ abstract public function install();
+ abstract public function uninstall();
// For display we need the following 'instance' functions
- abstract public function add_instance($data);
- abstract public function delete_instance($id);
- abstract public function update_instance($id,$post);
- abstract public function get_instances();
+ abstract public function add_instance($data);
+ abstract public function delete_instance($id);
+ abstract public function update_instance($id,$post);
+ abstract public function get_instances();
abstract public function instance_fields();
- abstract public function set_active_instance($uid);
- abstract public function get_active_instance();
+ abstract public function set_active_instance($uid);
+ abstract public function get_active_instance();
/**
* get_url
* This returns the URL for the passed object
*/
- public function get_url($object) {
+ public function get_url($object) {
// This might not be an object!
- if (!is_object($object)) {
+ if (!is_object($object)) {
// Stupiidly we'll just blindly add it for now
- return $object;
- }
+ return $object;
+ }
+
+ $class = get_class($object);
- $class = get_class($object);
-
- $url = call_user_func(array($class,'play_url'),$object->id);
+ $url = call_user_func(array($class,'play_url'),$object->id);
return $url;
- } // get_url
+ } // get_url
/**
* get_file
* This returns the Filename for the passed object, not
* always possible
*/
- public function get_file($object) {
+ public function get_file($object) {
- } // get_file
+ } // get_file
/**
- * parse_url
+ * parse_url
* This takes an Ampache URL and then returns the 'primary' part of it
* So that it's easier for localplay modules to return valid song information
*/
- public function parse_url($url) {
+ public function parse_url($url) {
// Define possible 'primary' keys
- $primary_array = array('oid','demo_id','random');
- $data = array();
+ $primary_array = array('oid','demo_id','random');
+ $data = array();
- $variables = parse_url($url,PHP_URL_QUERY);
- parse_str($variables,$data);
+ $variables = parse_url($url,PHP_URL_QUERY);
+ parse_str($variables,$data);
- foreach ($primary_array as $pkey) {
- if ($data[$pkey]) {
- $data['primary_key'] = $pkey;
- return $data;
+ foreach ($primary_array as $pkey) {
+ if ($data[$pkey]) {
+ $data['primary_key'] = $pkey;
+ return $data;
}
} // end foreach
return $data;
- } // parse_url
+ } // parse_url
} // end localplay_controller interface
diff --git a/lib/class/localplay.class.php b/lib/class/localplay.class.php
index 186bea7e..26b39aba 100644
--- a/lib/class/localplay.class.php
+++ b/lib/class/localplay.class.php
@@ -26,10 +26,10 @@ class Localplay {
public $type;
/* Built Variables */
- private $_function_map = array();
+ private $_function_map = array();
private $_template;
private $_preferences = array();
- private $_player;
+ private $_player;
/**
* Constructor
@@ -37,7 +37,7 @@ class Localplay {
* file for the specified type and attempts to load in the function
* map, the preferences and the template
*/
- public function __construct($type) {
+ public function __construct($type) {
$this->type = $type;
@@ -47,12 +47,12 @@ class Localplay {
/**
* _get_info
- * This functions takes the type and attempts to get all the
+ * This functions takes the type and attempts to get all the
* information needed to load it. Will log errors if there are
* any failures, fatal errors will actually return something to the
* gui
*/
- private function _get_info() {
+ private function _get_info() {
$this->_load_player();
@@ -63,29 +63,29 @@ class Localplay {
* This returns true / false if the player load
* failed / worked
*/
- public function player_loaded() {
+ public function player_loaded() {
- if (is_object($this->_player)) {
- return true;
- }
- else {
- return false;
- }
+ if (is_object($this->_player)) {
+ return true;
+ }
+ else {
+ return false;
+ }
} // player_loaded
/**
* format
- * This makes the localplay/plugin information
- * human readable
+ * This makes the localplay/plugin information
+ * human readable
*/
- public function format() {
+ public function format() {
- if (!is_object($this->_player)) { return false; }
+ if (!is_object($this->_player)) { return false; }
- $this->f_name = ucfirst($this->type);
- $this->f_description = $this->_player->get_description();
- $this->f_version = $this->_player->get_version();
+ $this->f_name = ucfirst($this->type);
+ $this->f_description = $this->_player->get_description();
+ $this->f_version = $this->_player->get_version();
} // format
@@ -96,40 +96,40 @@ class Localplay {
* Will interface with in order to make all this magical stuf work
* all LocalPlay modules should be located in /modules/<name>/<name>.class.php
*/
- private function _load_player() {
+ private function _load_player() {
- if (!$this->type) { return false; }
+ if (!$this->type) { return false; }
$filename = Config::get('prefix') . '/modules/localplay/' . $this->type . '.controller.php';
$include = require_once ($filename);
-
- if (!$include) {
+
+ if (!$include) {
/* Throw Error Here */
debug_event('localplay','Unable to load ' . $this->type . ' controller','2');
- return false;
+ return false;
} // include
- else {
+ else {
$class_name = "Ampache" . $this->type;
$this->_player = new $class_name();
- if (!($this->_player instanceof localplay_controller)) {
- debug_event('Localplay',$this->type . ' not an instance of controller abstract, unable to load','1');
- unset($this->_player);
- return false;
- }
+ if (!($this->_player instanceof localplay_controller)) {
+ debug_event('Localplay',$this->type . ' not an instance of controller abstract, unable to load','1');
+ unset($this->_player);
+ return false;
+ }
}
-
+
} // _load_player
/**
* format_name
- * This function takes the track name and checks to see if 'skip'
+ * This function takes the track name and checks to see if 'skip'
* is supported in the current player, if so it returns a 'skip to'
* link, otherwise it returns just the text
*/
- public function format_name($name,$id) {
+ public function format_name($name,$id) {
$name = scrub_out($name);
- $name = Ajax::text('?page=localplay&action=command&command=skip&id=' . $id,$name,'localplay_skip_' . $id);
+ $name = Ajax::text('?page=localplay&action=command&command=skip&id=' . $id,$name,'localplay_skip_' . $id);
return $name;
} // format_name
@@ -138,31 +138,31 @@ class Localplay {
* get_controllers
* This returns the controllers that are currently loaded into this instance
*/
- public static function get_controllers() {
+ public static function get_controllers() {
/* First open the dir */
- $handle = opendir(Config::get('prefix') . '/modules/localplay');
-
- if (!is_resource($handle)) {
- debug_event('Localplay','Error: Unable to read localplay controller directory','1');
- return array();
+ $handle = opendir(Config::get('prefix') . '/modules/localplay');
+
+ if (!is_resource($handle)) {
+ debug_event('Localplay','Error: Unable to read localplay controller directory','1');
+ return array();
}
- $results = array();
+ $results = array();
- while ($file = readdir($handle)) {
+ while ($file = readdir($handle)) {
- if (substr($file,-14,14) != 'controller.php') { continue; }
+ if (substr($file,-14,14) != 'controller.php') { continue; }
/* Make sure it isn't a dir */
- if (!is_dir($file)) {
+ if (!is_dir($file)) {
/* Get the basename and then everything before controller */
- $filename = basename($file,'.controller.php');
- $results[] = $filename;
- }
+ $filename = basename($file,'.controller.php');
+ $results[] = $filename;
+ }
} // end while
- return $results;
+ return $results;
} // get_controllers
@@ -171,14 +171,14 @@ class Localplay {
* This returns true or false depending on if the specified controller
* is currently enabled
*/
- public static function is_enabled($controller) {
+ public static function is_enabled($controller) {
// Load the controller and then check for its preferences
- $localplay = new Localplay($controller);
- // If we can't even load it no sense in going on
- if (!isset($localplay->_player)) { return false; }
+ $localplay = new Localplay($controller);
+ // If we can't even load it no sense in going on
+ if (!isset($localplay->_player)) { return false; }
- return $localplay->_player->is_installed();
+ return $localplay->_player->is_installed();
} // is_enabled
@@ -187,48 +187,48 @@ class Localplay {
* This runs the install for the localplay controller we've
* currently got pimped out
*/
- public function install() {
+ public function install() {
// Run the player's installer
- $installed = $this->_player->install();
-
- return $installed;
+ $installed = $this->_player->install();
+
+ return $installed;
} // install
/**
* uninstall
- * This runs the uninstall for the localplay controller we've
+ * This runs the uninstall for the localplay controller we've
* currently pimped out
*/
- public function uninstall() {
+ public function uninstall() {
// Run the players uninstaller
- $this->_player->uninstall();
+ $this->_player->uninstall();
// If its our current player, reset player to nothing
- if (Config::get('localplay_controller') == $this->type) {
- Preference::update('localplay_controller',$GLOBALS['user']->id,'');
- }
+ if (Config::get('localplay_controller') == $this->type) {
+ Preference::update('localplay_controller',$GLOBALS['user']->id,'');
+ }
- return true;
+ return true;
} // uninstall
/**
* connect
- * This function attempts to connect to the localplay
+ * This function attempts to connect to the localplay
* player that we are using
*/
- public function connect() {
+ public function connect() {
- if (!$this->_player->connect()) {
+ if (!$this->_player->connect()) {
debug_event('localplay','Error Unable to connect, check ' . $this->type . ' controller','1');
return false;
}
return true;
-
+
} // connect
/**
@@ -236,13 +236,13 @@ class Localplay {
* This function passes NULL and calls the play function of the player
* object
*/
- public function play() {
-
- if (!$this->_player->play()) {
+ public function play() {
+
+ if (!$this->_player->play()) {
debug_event('localplay','Error Unable to start playback, check ' . $this->type . ' controller','1');
return false;
}
-
+
return true;
} // play
@@ -252,9 +252,9 @@ class Localplay {
* This functions passes NULl and calls the stop function of the player
* object, it should recieve a true/false boolean value
*/
- public function stop() {
+ public function stop() {
- if (!$this->_player->stop()) {
+ if (!$this->_player->stop()) {
debug_event('localplay','Error Unable to stop playback, check ' . $this->type . ' controller','1');
return false;
}
@@ -266,48 +266,48 @@ class Localplay {
/**
* add
* This function takes a single object and then passes it to
- * to the player, this is a required function.
+ * to the player, this is a required function.
*/
- public function add($object) {
+ public function add($object) {
- if (!$this->_player->add($object)) {
+ if (!$this->_player->add($object)) {
debug_event('localplay','Error Unable to add songs, check ' . $this->type . ' controller','1');
return false;
}
-
+
return true;
} // add
/**
- * add_url
+ * add_url
* This directly adds an array of URLs to the localplay module. This is really how I should
* have done add, will migrate to this eventually
*/
- public function add_url($urls) {
+ public function add_url($urls) {
$function = $this->_function_map['add_url'];
-
- if (!$this->_player->$function($urls)) {
+
+ if (!$this->_player->$function($urls)) {
debug_event('localplay','Error Unable to add urls, check ' . $this->type . ' controller','1');
- return false;
- }
+ return false;
+ }
- return true;
+ return true;
} // add_url
/**
* repeat
- * This turns the repeat feature of a localplay method on or
+ * This turns the repeat feature of a localplay method on or
* off, takes a 0/1 value
*/
- public function repeat($state) {
+ public function repeat($state) {
$data = $this->_player->repeat($state);
- if (!$data) {
+ if (!$data) {
debug_event('localplay',"Error Unable to set Repeat to $state",'1');
}
@@ -318,16 +318,16 @@ class Localplay {
/**
* random
* This turns on the random feature of a localplay method
- * It takes a 0/1 value
+ * It takes a 0/1 value
*/
- public function random($state) {
-
- $data = $this->_player->random($state);
+ public function random($state) {
+
+ $data = $this->_player->random($state);
- if (!$data) {
+ if (!$data) {
debug_event('localplay',"Error Unable to set Random to $state",'1');
}
-
+
return $data;
} // random
@@ -337,11 +337,11 @@ class Localplay {
* This returns current information about the state of the player
* There is an expected array format
*/
- public function status() {
+ public function status() {
$data = $this->_player->status();
- if (!count($data)) {
+ if (!count($data)) {
debug_event('localplay','Error Unable to get status, check ' . $this->type . ' controller','1');
return false;
}
@@ -356,15 +356,15 @@ class Localplay {
* the array of current songs for display or whatever
* an empty array is passed on failure
*/
- public function get() {
+ public function get() {
$data = $this->_player->get();
-
- if (!count($data) OR !is_array($data)) {
+
+ if (!count($data) OR !is_array($data)) {
debug_event('localplay','Error Unable to get song info, check ' . $this->type . ' controller','1');
- return array();
+ return array();
}
-
+
return $data;
} // get
@@ -372,18 +372,18 @@ class Localplay {
/**
* volume_set
* This isn't a required function, it sets the volume to a specified value
- * as passed in the variable it is a 0 - 100 scale the controller is
+ * as passed in the variable it is a 0 - 100 scale the controller is
* responsible for adjusting the scale if nessecary
*/
- public function volume_set($value) {
-
+ public function volume_set($value) {
+
/* Make sure it's int and 0 - 100 */
$value = int($value);
/* Make sure that it's between 0 and 100 */
if ($value > 100 OR $value < 0) { return false; }
- if (!$this->_player->volume($value)) {
+ if (!$this->_player->volume($value)) {
debug_event('localplay','Error: Unable to set volume, check ' . $this->type . ' controller','1');
return false;
}
@@ -397,11 +397,11 @@ class Localplay {
* This function isn't required. It tells the daemon to increase the volume
* by a pre-defined amount controlled by the controller
*/
- public function volume_up() {
+ public function volume_up() {
- if (!$this->_player->volume_up()) {
+ if (!$this->_player->volume_up()) {
debug_event('localplay','Error: Unable to increase volume, check ' . $this->type . ' controller','1');
- return false;
+ return false;
}
return true;
@@ -413,12 +413,12 @@ class Localplay {
* This function isn't required. It tells the daemon to decrese the volume
* by a pre-defined amount controlled by the controller.
*/
- public function volume_down() {
+ public function volume_down() {
- if (!$this->_player->volume_down()) {
+ if (!$this->_player->volume_down()) {
debug_event('localplay','Error: Unable to decrese volume, check ' . $this->type . ' controller','1');
- return false;
- }
+ return false;
+ }
return true;
@@ -429,14 +429,14 @@ class Localplay {
* This function isn't required, It tells the daemon to mute all output
* It's up to the controller to decide what that actually entails
*/
- public function volume_mute() {
+ public function volume_mute() {
- if (!$this->_player->volume(0)){
+ if (!$this->_player->volume(0)){
debug_event('localplay','Error: Unable to mute volume, check ' . $this->type . ' controller','1');
- return false;
+ return false;
}
- return true;
+ return true;
} // volume_mute
@@ -444,11 +444,11 @@ class Localplay {
* skip
* This isn't a required function, it tells the daemon to skip to the specified song
*/
- public function skip($track_id) {
+ public function skip($track_id) {
- if (!$this->_player->skip($track_id)) {
+ if (!$this->_player->skip($track_id)) {
debug_event('localplay','Error: Unable to skip to next song, check ' . $this->type . ' controller','1');
- return false;
+ return false;
}
return true;
@@ -457,14 +457,14 @@ class Localplay {
/**
* next
- * This isn't a required function, it tells the daemon to go to the next
+ * This isn't a required function, it tells the daemon to go to the next
* song
*/
- public function next() {
+ public function next() {
- if (!$this->_player->next()) {
+ if (!$this->_player->next()) {
debug_event('localplay','Error: Unable to skip to next song, check ' . $this->type . ' controller','1');
- return false;
+ return false;
}
return true;
@@ -476,10 +476,10 @@ class Localplay {
* This isn't a required function, it tells the daemon to go the the previous
* song
*/
- public function prev() {
-
+ public function prev() {
+
- if (!$this->_player->prev()) {
+ if (!$this->_player->prev()) {
debug_event('localplay','Error: Unable to skip to previous song, check ' . $this->type . ' controller','1');
return false;
}
@@ -508,11 +508,11 @@ class Localplay {
* get_instances
* This returns the instances of the current type
*/
- public function get_instances() {
+ public function get_instances() {
- $instances = $this->_player->get_instances();
+ $instances = $this->_player->get_instances();
- return $instances;
+ return $instances;
} // get_instances
@@ -520,11 +520,11 @@ class Localplay {
* current_instance
* This returns the UID of the current Instance
*/
- public function current_instance() {
+ public function current_instance() {
- $data = $this->_player->get_instance();
+ $data = $this->_player->get_instance();
- return $data['id'];
+ return $data['id'];
} // current_instance
@@ -532,11 +532,11 @@ class Localplay {
* get_instance
* This returns the specified instance
*/
- public function get_instance($uid) {
+ public function get_instance($uid) {
- $data = $this->_player->get_instance($uid);
-
- return $data;
+ $data = $this->_player->get_instance($uid);
+
+ return $data;
} // get_instance
@@ -544,11 +544,11 @@ class Localplay {
* update_instance
* This updates the specified instance with a named array of data (_POST most likely)
*/
- public function update_instance($uid,$data) {
+ public function update_instance($uid,$data) {
- $data = $this->_player->update_instance($uid,$data);
+ $data = $this->_player->update_instance($uid,$data);
- return $data;
+ return $data;
} // update_instance
@@ -556,9 +556,9 @@ class Localplay {
* add_instance
* This adds a new instance for the current controller type
*/
- public function add_instance($data) {
+ public function add_instance($data) {
- $this->_player->add_instance($data);
+ $this->_player->add_instance($data);
} // add_instance
@@ -566,9 +566,9 @@ class Localplay {
* delete_instance
* This removes an instance (it actually calls the players function)
*/
- public function delete_instance($instance_uid) {
+ public function delete_instance($instance_uid) {
- $this->_player->delete_instance($instance_uid);
+ $this->_player->delete_instance($instance_uid);
} // delete_instance
@@ -576,9 +576,9 @@ class Localplay {
* set_active_instance
* This sets the active instance of the localplay controller
*/
- public function set_active_instance($instance) {
+ public function set_active_instance($instance) {
- $this->_player->set_active_instance($instance);
+ $this->_player->set_active_instance($instance);
} // set_active_instance
@@ -587,9 +587,9 @@ class Localplay {
* This removes songs from the players playlist it takes a single ID as provided
* by the get command
*/
- public function delete_track($object_id) {
+ public function delete_track($object_id) {
- if (!$this->_player->delete_track($object_id)) {
+ if (!$this->_player->delete_track($object_id)) {
debug_event('localplay','Error: Unable to remove songs, check ' . $this->type . ' controller','1');
return false;
}
@@ -604,11 +604,11 @@ class Localplay {
* This removes every song from the players playlist as defined by the delete_all function
* map
*/
- public function delete_all() {
+ public function delete_all() {
- if (!$this->_player->clear_playlist()) {
+ if (!$this->_player->clear_playlist()) {
debug_event('localplay','Error: Unable to delete entire playlist, check ' . $this->type . ' controller','1');
- return false;
+ return false;
}
return true;
@@ -617,12 +617,12 @@ class Localplay {
/**
* get_instance_fields
- * This loads the fields from the localplay
- * player and returns them
+ * This loads the fields from the localplay
+ * player and returns them
*/
- public function get_instance_fields() {
+ public function get_instance_fields() {
- $fields = $this->_player->instance_fields();
+ $fields = $this->_player->instance_fields();
return $fields;
@@ -633,9 +633,9 @@ class Localplay {
* This function returns a user friendly version
* of the current player state
*/
- public function get_user_state($state) {
-
- switch ($state) {
+ public function get_user_state($state) {
+
+ switch ($state) {
case 'play':
return _('Now Playing');
break;
@@ -648,7 +648,7 @@ class Localplay {
default:
return _('Unknown');
break;
- } // switch on state
+ } // switch on state
} // get_user_state
@@ -657,10 +657,10 @@ class Localplay {
* This attempts to return a nice user friendly
* currently playing string
*/
- public function get_user_playing() {
+ public function get_user_playing() {
$status = $this->status();
-
+
/* Format the track name */
$track_name = $status['track_artist'] . ' - ' . $status['track_album'] . ' - ' . $status['track_title'];
@@ -672,7 +672,7 @@ class Localplay {
$track_name = "[" . $status['track'] . "] - " . $track_name;
return $track_name;
-
+
} // get_user_playing
diff --git a/lib/class/media.interface.php b/lib/class/media.interface.php
index 14bfd4f4..60d01967 100644
--- a/lib/class/media.interface.php
+++ b/lib/class/media.interface.php
@@ -25,13 +25,13 @@
* work, this lists all required functions and the expected
* input
*/
-interface media {
+interface media {
- public function format();
- public function native_stream();
- public static function play_url($oid);
- public function stream_cmd();
- public function has_flag();
+ public function format();
+ public function native_stream();
+ public static function play_url($oid);
+ public function stream_cmd();
+ public function has_flag();
} // end interface
diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php
index 8c4eb7f9..042716b2 100644
--- a/lib/class/playlist.class.php
+++ b/lib/class/playlist.class.php
@@ -24,50 +24,50 @@
* Playlist Class
* This class handles playlists in ampache. it references the playlist* tables
*/
-class Playlist extends database_object {
+class Playlist extends database_object {
/* Variables from the Datbase */
public $id;
public $name;
public $user;
public $type;
- public $genre;
+ public $genre;
public $date;
/* Generated Elements */
public $items = array();
/**
- * Constructor
+ * Constructor
* This takes a playlist_id as an optional argument and gathers the information
- * if not playlist_id is passed returns false (or if it isn't found
+ * if not playlist_id is passed returns false (or if it isn't found
*/
- public function __construct($id) {
+ public function __construct($id) {
$info = $this->get_info($id);
- foreach ($info as $key=>$value) {
- $this->$key = $value;
- }
-
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
+
} // Playlist
/**
* build_cache
* This is what builds the cache from the objects
*/
- public static function build_cache($ids) {
-
- if (!count($ids)) { return false; }
+ public static function build_cache($ids) {
- $idlist = '(' . implode(',',$ids) . ')';
+ if (!count($ids)) { return false; }
- $sql = "SELECT * FROM `playlist` WHERE `id` IN $idlist";
- $db_results = Dba::read($sql);
+ $idlist = '(' . implode(',',$ids) . ')';
+
+ $sql = "SELECT * FROM `playlist` WHERE `id` IN $idlist";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('playlist',$row['id'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('playlist',$row['id'],$row);
+ }
} // build_cache
@@ -76,16 +76,16 @@ class Playlist extends database_object {
* This takes the current playlist object and gussies it up a little
* bit so it is presentable to the users
*/
- public function format() {
+ public function format() {
$this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipse_threshold_title'));
- $this->f_link = '<a href="' . Config::get('web_path') . '/playlist.php?action=show_playlist&amp;playlist_id=' . $this->id . '">' . $this->f_name . '</a>';
+ $this->f_link = '<a href="' . Config::get('web_path') . '/playlist.php?action=show_playlist&amp;playlist_id=' . $this->id . '">' . $this->f_name . '</a>';
- $this->f_type = ($this->type == 'private') ? get_user_icon('lock',_('Private')) : '';
+ $this->f_type = ($this->type == 'private') ? get_user_icon('lock',_('Private')) : '';
- $client = new User($this->user);
+ $client = new User($this->user);
- $this->f_user = $client->fullname;
+ $this->f_user = $client->fullname;
} // format
@@ -94,19 +94,19 @@ class Playlist extends database_object {
* This function returns true or false if the current user
* has access to this playlist
*/
- public function has_access() {
-
- if (!Access::check('interface','25')) {
- return false;
- }
- if ($this->user == $GLOBALS['user']->id) {
- return true;
- }
+ public function has_access() {
+
+ if (!Access::check('interface','25')) {
+ return false;
+ }
+ if ($this->user == $GLOBALS['user']->id) {
+ return true;
+ }
else {
- return Access::check('interface','100');
- }
+ return Access::check('interface','100');
+ }
- return false;
+ return false;
} // has_access
@@ -115,17 +115,17 @@ class Playlist extends database_object {
* Returns the single item on the playlist and all of it's information, restrict
* it to this Playlist
*/
- public function get_track($track_id) {
+ public function get_track($track_id) {
- $track_id = Dba::escape($track_id);
- $playlist_id = Dba::escape($this->id);
+ $track_id = Dba::escape($track_id);
+ $playlist_id = Dba::escape($this->id);
$sql = "SELECT * FROM `playlist_data` WHERE `id`='$track_id' AND `playlist`='$playlist_id'";
$db_results = Dba::read($sql);
$row = Dba::fetch_assoc($db_results);
- return $row;
+ return $row;
} // get_track
@@ -134,15 +134,15 @@ class Playlist extends database_object {
* This returns an array of playlist songs that are in this playlist. Because the same
* song can be on the same playlist twice they are key'd by the uid from playlist_data
*/
- public function get_items() {
+ public function get_items() {
- $results = array();
+ $results = array();
$sql = "SELECT `id`,`object_id`,`object_type`,`track` FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`";
$db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id'],'track'=>$row['track'],'track_id'=>$row['id']);
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id'],'track'=>$row['track'],'track_id'=>$row['id']);
} // end while
return $results;
@@ -153,17 +153,17 @@ class Playlist extends database_object {
* get_random_items
* This is the same as before but we randomize the buggers!
*/
- public function get_random_items($limit='') {
+ public function get_random_items($limit='') {
- $results = array();
+ $results = array();
- $limit_sql = $limit ? 'LIMIT ' . intval($limit) : '';
+ $limit_sql = $limit ? 'LIMIT ' . intval($limit) : '';
- $sql = "SELECT `object_id`,`object_type` FROM `playlist_data` " .
- "WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY RAND() $limit_sql";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `object_id`,`object_type` FROM `playlist_data` " .
+ "WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY RAND() $limit_sql";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
+ while ($row = Dba::fetch_assoc($db_results)) {
$results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id']);
} // end while
@@ -177,21 +177,21 @@ class Playlist extends database_object {
* This is called by the batch script, because we can't pass in Dynamic objects they pulled once and then their
* target song.id is pushed into the array
*/
- function get_songs() {
+ function get_songs() {
$results = array();
$sql = "SELECT * FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`";
$db_results = Dba::read($sql);
- while ($r = Dba::fetch_assoc($db_results)) {
- if ($r['dyn_song']) {
+ while ($r = Dba::fetch_assoc($db_results)) {
+ if ($r['dyn_song']) {
$array = $this->get_dyn_songs($r['dyn_song']);
$results = array_merge($array,$results);
}
- else {
+ else {
$results[] = $r['object_id'];
- }
+ }
} // end while
@@ -204,7 +204,7 @@ class Playlist extends database_object {
* This simply returns a int of how many song elements exist in this playlist
* For now let's consider a dyn_song a single entry
*/
- public function get_song_count() {
+ public function get_song_count() {
$sql = "SELECT COUNT(`id`) FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "'";
$db_results = Dba::read($sql);
@@ -220,19 +220,19 @@ class Playlist extends database_object {
* This returns the specified users playlists as an array of
* playlist ids
*/
- public static function get_users($user_id) {
+ public static function get_users($user_id) {
- $user_id = Dba::escape($user_id);
- $results = array();
+ $user_id = Dba::escape($user_id);
+ $results = array();
- $sql = "SELECT `id` FROM `playlist` WHERE `user`='$user_id' ORDER BY `name`";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id` FROM `playlist` WHERE `user`='$user_id' ORDER BY `name`";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
- return $results;
+ return $results;
} // get_users
@@ -240,24 +240,24 @@ class Playlist extends database_object {
* update
* This function takes a key'd array of data and runs updates
*/
- public function update($data) {
+ public function update($data) {
- if ($data['name'] != $this->name) {
- $this->update_name($data['name']);
- }
- if ($data['pl_type'] != $this->type) {
- $this->update_type($data['pl_type']);
- }
+ if ($data['name'] != $this->name) {
+ $this->update_name($data['name']);
+ }
+ if ($data['pl_type'] != $this->type) {
+ $this->update_type($data['pl_type']);
+ }
} // update
/**
* update_type
- * This updates the playlist type, it calls the generic update_item function
+ * This updates the playlist type, it calls the generic update_item function
*/
- private function update_type($new_type) {
+ private function update_type($new_type) {
- if ($this->_update_item('type',$new_type,'50')) {
+ if ($this->_update_item('type',$new_type,'50')) {
$this->type = $new_type;
}
@@ -267,9 +267,9 @@ class Playlist extends database_object {
* update_name
* This updates the playlist name, it calls the generic update_item function
*/
- private function update_name($new_name) {
+ private function update_name($new_name) {
- if ($this->_update_item('name',$new_name,'50')) {
+ if ($this->_update_item('name',$new_name,'50')) {
$this->name = $new_name;
}
@@ -279,10 +279,10 @@ class Playlist extends database_object {
* _update_item
* This is the generic update function, it does the escaping and error checking
*/
- private function _update_item($field,$value,$level) {
+ private function _update_item($field,$value,$level) {
- if ($GLOBALS['user']->id != $this->user AND !Access::check('interface',$level)) {
- return false;
+ if ($GLOBALS['user']->id != $this->user AND !Access::check('interface',$level)) {
+ return false;
}
$value = Dba::escape($value);
@@ -298,14 +298,14 @@ class Playlist extends database_object {
* update_track_number
* This takes a playlist_data.id and a track (int) and updates the track value
*/
- public function update_track_number($track_id,$track) {
+ public function update_track_number($track_id,$track) {
- $playlist_id = Dba::escape($this->id);
- $track_id = Dba::escape($track_id);
- $track = Dba::escape($track);
+ $playlist_id = Dba::escape($this->id);
+ $track_id = Dba::escape($track_id);
+ $track = Dba::escape($track);
- $sql = "UPDATE `playlist_data` SET `track`='$track' WHERE `id`='$track_id' AND `playlist`='$playlist_id'";
- $db_results = Dba::write($sql);
+ $sql = "UPDATE `playlist_data` SET `track`='$track' WHERE `id`='$track_id' AND `playlist`='$playlist_id'";
+ $db_results = Dba::write($sql);
} // update_track_number
@@ -315,10 +315,10 @@ class Playlist extends database_object {
* if you want to add a dyn_song you need to use the one shot function
* add_dyn_song
*/
- public function add_songs($song_ids=array(),$ordered=false) {
+ public function add_songs($song_ids=array(),$ordered=false) {
/* We need to pull the current 'end' track and then use that to
- * append, rather then integrate take end track # and add it to
+ * append, rather then integrate take end track # and add it to
* $song->track add one to make sure it really is 'next'
*/
$sql = "SELECT `track` FROM `playlist_data` WHERE `playlist`='" . $this->id . "' ORDER BY `track` DESC LIMIT 1";
@@ -327,24 +327,24 @@ class Playlist extends database_object {
$base_track = $data['track'];
debug_event('add_songs', 'Track number: '.$base_track, '5');
- foreach ($song_ids as $song_id) {
+ foreach ($song_ids as $song_id) {
/* We need the songs track */
$song = new Song($song_id);
-
+
// Based on the ordered prop we use track + base or just $i++
- if (!$ordered) {
+ if (!$ordered) {
$track = Dba::escape($song->track+$base_track);
- }
- else {
- $i++;
- $track = Dba::escape($base_track+$i);
- }
+ }
+ else {
+ $i++;
+ $track = Dba::escape($base_track+$i);
+ }
$id = Dba::escape($song->id);
$pl_id = Dba::escape($this->id);
/* Don't insert dead songs */
- if ($id) {
- $sql = "INSERT INTO `playlist_data` (`playlist`,`object_id`,`object_type`,`track`) " .
+ if ($id) {
+ $sql = "INSERT INTO `playlist_data` (`playlist`,`object_id`,`object_type`,`track`) " .
" VALUES ('$pl_id','$id','song','$track')";
$db_results = Dba::write($sql);
} // if valid id
@@ -358,14 +358,14 @@ class Playlist extends database_object {
* This function creates an empty playlist, gives it a name and type
* Assumes $GLOBALS['user']->id as the user
*/
- public static function create($name,$type) {
+ public static function create($name,$type) {
$name = Dba::escape($name);
$type = Dba::escape($type);
$user = Dba::escape($GLOBALS['user']->id);
$date = time();
- $sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`date`) " .
+ $sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`date`) " .
" VALUES ('$name','$user','$type','$date')";
$db_results = Dba::write($sql);
@@ -379,7 +379,7 @@ class Playlist extends database_object {
* set_items
* This calles the get_items function and sets it to $this->items which is an array in this object
*/
- function set_items() {
+ function set_items() {
$this->items = $this->get_items();
@@ -391,7 +391,7 @@ class Playlist extends database_object {
* and numbers them in a liner fashion, not allowing for
* the same track # twice, this is an optional funcition
*/
- public function normalize_tracks() {
+ public function normalize_tracks() {
/* First get all of the songs in order of their tracks */
$sql = "SELECT `id` FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track` ASC";
@@ -400,7 +400,7 @@ class Playlist extends database_object {
$i = 1;
$results = array();
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$new_data = array();
$new_data['id'] = $r['id'];
$new_data['track'] = $i;
@@ -408,8 +408,8 @@ class Playlist extends database_object {
$i++;
} // end while results
- foreach($results as $data) {
- $sql = "UPDATE `playlist_data` SET `track`='" . $data['track'] . "' WHERE" .
+ foreach($results as $data) {
+ $sql = "UPDATE `playlist_data` SET `track`='" . $data['track'] . "' WHERE" .
" `id`='" . $data['id'] . "'";
$db_results = Dba::write($sql);
} // foreach re-ordered results
@@ -417,42 +417,42 @@ class Playlist extends database_object {
return true;
} // normalize_tracks
-
+
/**
* delete_track
* this deletes a single track, you specify the playlist_data.id here
*/
- public function delete_track($id) {
+ public function delete_track($id) {
- $this_id = Dba::escape($this->id);
- $id = Dba::escape($id);
-
- $sql = "DELETE FROM `playlist_data` WHERE `playlist_data`.`playlist`='$this_id' AND `playlist_data`.`id`='$id' LIMIT 1";
- $db_results = Dba::write($sql);
+ $this_id = Dba::escape($this->id);
+ $id = Dba::escape($id);
- return true;
+ $sql = "DELETE FROM `playlist_data` WHERE `playlist_data`.`playlist`='$this_id' AND `playlist_data`.`id`='$id' LIMIT 1";
+ $db_results = Dba::write($sql);
+
+ return true;
- } // delete_track
+ } // delete_track
/**
* delete
* This deletes the current playlist and all assoicated data
*/
- public function delete() {
+ public function delete() {
+
+ $id = Dba::escape($this->id);
- $id = Dba::escape($this->id);
-
$sql = "DELETE FROM `playlist_data` WHERE `playlist` = '$id'";
$db_results = Dba::write($sql);
$sql = "DELETE FROM `playlist` WHERE `id`='$id'";
$db_results = Dba::write($sql);
- $sql = "DELETE FROM `object_count` WHERE `object_type`='playlist' AND `object_id`='$id'";
- $db_results = Dba::write($sql);
-
+ $sql = "DELETE FROM `object_count` WHERE `object_type`='playlist' AND `object_id`='$id'";
+ $db_results = Dba::write($sql);
+
return true;
-
+
} // delete
} // class Playlist
diff --git a/lib/class/plugin.class.php b/lib/class/plugin.class.php
index 3e0d70a9..63eeb593 100644
--- a/lib/class/plugin.class.php
+++ b/lib/class/plugin.class.php
@@ -26,21 +26,21 @@ class Plugin {
public $name;
/* constructed objects */
- public $_plugin;
+ public $_plugin;
/**
* Constructor
- * This constructor loads the Plugin config file which defines how to
+ * This constructor loads the Plugin config file which defines how to
* install/uninstall the plugin from Ampache's database
*/
- public function __construct($name) {
+ public function __construct($name) {
/* Load the plugin */
- if (!$this->_get_info($name)) {
- return false;
+ if (!$this->_get_info($name)) {
+ return false;
}
- return true;
+ return true;
} // Constructor
@@ -50,20 +50,20 @@ class Plugin {
* This actually loads the config file for the plugin the name of the
* class contained within the config file must be Plugin[NAME OF FILE]
*/
- public function _get_info($name) {
+ public function _get_info($name) {
/* Require the file we want */
require_once Config::get('prefix') . '/modules/plugins/' . $name . '.plugin.php';
$plugin_name = "Ampache$name";
- $this->_plugin = new $plugin_name();
+ $this->_plugin = new $plugin_name();
- if (!$this->is_valid()) {
- return false;
+ if (!$this->is_valid()) {
+ return false;
}
- return true;
+ return true;
} // _get_info
@@ -71,33 +71,33 @@ class Plugin {
* get_plugins
* This returns an array of plugin names
*/
- public static function get_plugins() {
+ public static function get_plugins() {
- $results = array();
+ $results = array();
// Open up the plugin dir
- $handle = opendir(Config::get('prefix') . '/modules/plugins');
+ $handle = opendir(Config::get('prefix') . '/modules/plugins');
- if (!is_resource($handle)) {
- debug_event('Plugins','Unable to read plugins directory','1');
- }
+ if (!is_resource($handle)) {
+ debug_event('Plugins','Unable to read plugins directory','1');
+ }
// Recurse the directory
- while ($file = readdir($handle)) {
+ while ($file = readdir($handle)) {
// Ignore non-plugin files
- if (substr($file,-10,10) != 'plugin.php') { continue; }
- if (is_dir($file)) { continue; }
+ if (substr($file,-10,10) != 'plugin.php') { continue; }
+ if (is_dir($file)) { continue; }
// It's a plugin record it
- $plugin_name = basename($file,'.plugin.php');
- $results[$plugin_name] = $plugin_name;
+ $plugin_name = basename($file,'.plugin.php');
+ $results[$plugin_name] = $plugin_name;
} // end while
// Little stupid but hey
- ksort($results);
+ ksort($results);
- return $results;
+ return $results;
} // get_plugins
@@ -108,41 +108,41 @@ class Plugin {
* install & uninstall method and Ampache must be within the min/max
* version specifications
*/
- function is_valid() {
+ function is_valid() {
- /* Check the plugin to make sure it's got the needed vars */
- if (!strlen($this->_plugin->name)) {
- return false;
+ /* Check the plugin to make sure it's got the needed vars */
+ if (!strlen($this->_plugin->name)) {
+ return false;
+ }
+ if (!strlen($this->_plugin->description)) {
+ return false;
}
- if (!strlen($this->_plugin->description)) {
- return false;
+ if (!strlen($this->_plugin->version)) {
+ return false;
}
- if (!strlen($this->_plugin->version)) {
- return false;
- }
/* Make sure we've got the required methods */
- if (!method_exists($this->_plugin,'install')) {
- return false;
+ if (!method_exists($this->_plugin,'install')) {
+ return false;
}
- if (!method_exists($this->_plugin,'uninstall')) {
- return false;
- }
+ if (!method_exists($this->_plugin,'uninstall')) {
+ return false;
+ }
/* Make sure it's within the version confines */
- $db_version = $this->get_ampache_db_version();
+ $db_version = $this->get_ampache_db_version();
- if ($db_version < $this->_plugin->min_ampache) {
- return false;
- }
+ if ($db_version < $this->_plugin->min_ampache) {
+ return false;
+ }
- if ($db_version > $this->_plugin->max_ampache) {
- return false;
- }
+ if ($db_version > $this->_plugin->max_ampache) {
+ return false;
+ }
/* We've passed all of the tests its good */
- return true;
+ return true;
} // is_valid
@@ -151,42 +151,42 @@ class Plugin {
* This checks to see if the specified plugin is currently installed in the
* database, it doesn't check the files for integrity
*/
- public static function is_installed($plugin_name) {
+ public static function is_installed($plugin_name) {
- /* All we do is check the version */
- return self::get_plugin_version($plugin_name);
+ /* All we do is check the version */
+ return self::get_plugin_version($plugin_name);
} // is_installed
/**
* install
- * This runs the install function of the plugin (must be called install)
+ * This runs the install function of the plugin (must be called install)
* at the end it inserts a row into the update_info table to indicate
* That it's installed
*/
- public function install() {
+ public function install() {
- $installed = $this->_plugin->install();
+ $installed = $this->_plugin->install();
- $version = $this->set_plugin_version($this->_plugin->version);
+ $version = $this->set_plugin_version($this->_plugin->version);
- if (!$installed OR !$version) { return false; }
+ if (!$installed OR !$version) { return false; }
- return true;
+ return true;
} // install
- /**
+ /**
* uninstall
- * This runs the uninstall function of the plugin (must be called uninstall)
+ * This runs the uninstall function of the plugin (must be called uninstall)
* at the end it removes the row from the update_info table to indicate
* that it isn't installed
*/
- public function uninstall() {
+ public function uninstall() {
- $this->_plugin->uninstall();
+ $this->_plugin->uninstall();
- $this->remove_plugin_version();
+ $this->remove_plugin_version();
} // uninstall
@@ -194,15 +194,15 @@ class Plugin {
* get_plugin_version
* This returns the version of the specified plugin
*/
- public static function get_plugin_version($plugin_name) {
+ public static function get_plugin_version($plugin_name) {
+
+ $name = Dba::escape('Plugin_' . $plugin_name);
- $name = Dba::escape('Plugin_' . $plugin_name);
+ $sql = "SELECT * FROM `update_info` WHERE `key`='$name'";
+ $db_results = Dba::read($sql);
- $sql = "SELECT * FROM `update_info` WHERE `key`='$name'";
- $db_results = Dba::read($sql);
+ $results = Dba::fetch_assoc($db_results);
- $results = Dba::fetch_assoc($db_results);
-
return $results['value'];
} // get_plugin_version
@@ -211,12 +211,12 @@ class Plugin {
* get_ampache_db_version
* This function returns the Ampache database version
*/
- function get_ampache_db_version() {
+ function get_ampache_db_version() {
- $sql = "SELECT * FROM `update_info` WHERE `key`='db_version'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `update_info` WHERE `key`='db_version'";
+ $db_results = Dba::read($sql);
- $results = Dba::fetch_assoc($db_results);
+ $results = Dba::fetch_assoc($db_results);
return $results['value'];
@@ -226,15 +226,15 @@ class Plugin {
* set_plugin_version
* This sets the plugin version in the update_info table
*/
- public function set_plugin_version($version) {
+ public function set_plugin_version($version) {
$name = Dba::escape('Plugin_' . $this->_plugin->name);
$version = Dba::escape($version);
$sql = "INSERT INTO `update_info` SET `key`='$name', `value`='$version'";
- $db_results = Dba::read($sql);
+ $db_results = Dba::read($sql);
- return true;
+ return true;
} // set_plugin_version
@@ -242,14 +242,14 @@ class Plugin {
* remove_plugin_version
* This removes the version row from the db done on uninstall
*/
- public function remove_plugin_version() {
-
+ public function remove_plugin_version() {
+
$name = Dba::escape('Plugin_' . $this->_plugin->name);
-
- $sql = "DELETE FROM `update_info` WHERE `key`='$name'";
- $db_results = Dba::read($sql);
- return true;
+ $sql = "DELETE FROM `update_info` WHERE `key`='$name'";
+ $db_results = Dba::read($sql);
+
+ return true;
} // remove_plugin_version
diff --git a/lib/class/preference.class.php b/lib/class/preference.class.php
index 766859ea..528e6de9 100644
--- a/lib/class/preference.class.php
+++ b/lib/class/preference.class.php
@@ -1,7 +1,7 @@
<?php
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
/*
-
+
Copyright (c) Ampache.org
All Rights Reserved
@@ -18,86 +18,86 @@
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.
-
-*/
+
+*/
/**
* preference Class
* This handles all of the preference stuff for ampache it replaces
* /lib/preference.lib.php
*/
-class Preference {
+class Preference {
/**
* __constructor
* This does nothing... amazing isn't it!
*/
- private function __construct() {
+ private function __construct() {
// Rien a faire
-
+
} // __construct
/**
* update
* This updates a single preference from the given name or id
*/
- public static function update($preference,$user_id,$value,$applytoall='') {
+ public static function update($preference,$user_id,$value,$applytoall='') {
// First prepare
- if (!is_numeric($preference)) {
- $id = self::id_from_name($preference);
- $name = $preference;
- }
- else {
- $name = self::name_from_id($preference);
- $id = $preference;
- }
- if ($applytoall AND Access::check('interface','100')) {
+ if (!is_numeric($preference)) {
+ $id = self::id_from_name($preference);
+ $name = $preference;
+ }
+ else {
+ $name = self::name_from_id($preference);
+ $id = $preference;
+ }
+ if ($applytoall AND Access::check('interface','100')) {
$user_check = "";
}
- else {
+ else {
$user_check = " AND `user`='$user_id'";
- }
+ }
// Now do
- if (self::has_access($name)) {
- $value = Dba::escape($value);
- $user_id = Dba::escape($user_id);
- $sql = "UPDATE `user_preference` SET `value`='$value' " .
- "WHERE `preference`='$id'$user_check";
- $db_results = Dba::write($sql);
+ if (self::has_access($name)) {
+ $value = Dba::escape($value);
+ $user_id = Dba::escape($user_id);
+ $sql = "UPDATE `user_preference` SET `value`='$value' " .
+ "WHERE `preference`='$id'$user_check";
+ $db_results = Dba::write($sql);
Preference::clear_from_session();
- return true;
- }
- else {
- debug_event('denied',$GLOBALS['user']->username . ' attempted to update ' . $name . ' but does not have sufficient permissions','3');
+ return true;
+ }
+ else {
+ debug_event('denied',$GLOBALS['user']->username . ' attempted to update ' . $name . ' but does not have sufficient permissions','3');
}
- return false;
+ return false;
} // update
/**
* update_level
* This takes a preference ID and updates the level required to update it (performed by an admin)
*/
- public static function update_level($preference,$level) {
+ public static function update_level($preference,$level) {
// First prepare
- if (!is_numeric($preference)) {
+ if (!is_numeric($preference)) {
$preference_id = self::id_from_name($preference);
- }
- else {
+ }
+ else {
$preference_id = $preference;
- }
+ }
$preference_id = Dba::escape($preference_id);
- $level = Dba::escape($level);
+ $level = Dba::escape($level);
- $sql = "UPDATE `preference` SET `level`='$level' WHERE `id`='$preference_id'";
- $db_results = Dba::write($sql);
+ $sql = "UPDATE `preference` SET `level`='$level' WHERE `id`='$preference_id'";
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // update_level
@@ -105,15 +105,15 @@ class Preference {
* update_all
* This takes a preference id and a value and updates all users with the new info
*/
- public static function update_all($preference_id,$value) {
+ public static function update_all($preference_id,$value) {
$preference_id = Dba::escape($preference_id);
- $value = Dba::escape($value);
+ $value = Dba::escape($value);
- $sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$preference_id'";
- $db_results = Dba::write($sql);
+ $sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$preference_id'";
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // update_all
@@ -121,14 +121,14 @@ class Preference {
* exists
* This just checks to see if a preference currently exists
*/
- public static function exists($preference) {
+ public static function exists($preference) {
// We assume it's the name
- $name = Dba::escape($preference);
- $sql = "SELECT * FROM `preference` WHERE `name`='$name'";
- $db_results = Dba::read($sql);
+ $name = Dba::escape($preference);
+ $sql = "SELECT * FROM `preference` WHERE `name`='$name'";
+ $db_results = Dba::read($sql);
- return Dba::num_rows($db_results);
+ return Dba::num_rows($db_results);
} // exists
@@ -137,22 +137,22 @@ class Preference {
* This checks to see if the current user has access to modify this preference
* as defined by the preference name
*/
- public static function has_access($preference) {
+ public static function has_access($preference) {
// Nothing for those demo thugs
- if (Config::get('demo_mode')) { return false; }
+ if (Config::get('demo_mode')) { return false; }
- $preference = Dba::escape($preference);
+ $preference = Dba::escape($preference);
- $sql = "SELECT `level` FROM `preference` WHERE `name`='$preference'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `level` FROM `preference` WHERE `name`='$preference'";
+ $db_results = Dba::read($sql);
$data = Dba::fetch_assoc($db_results);
- if (Access::check('interface',$data['level'])) {
- return true;
- }
+ if (Access::check('interface',$data['level'])) {
+ return true;
+ }
- return false;
+ return false;
} // has_access
@@ -160,16 +160,16 @@ class Preference {
* id_from_name
* This takes a name and returns the id
*/
- public static function id_from_name($name) {
+ public static function id_from_name($name) {
- $name = Dba::escape($name);
+ $name = Dba::escape($name);
- $sql = "SELECT `id` FROM `preference` WHERE `name`='$name'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id` FROM `preference` WHERE `name`='$name'";
+ $db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
+ $row = Dba::fetch_assoc($db_results);
- return $row['id'];
+ return $row['id'];
} // id_from_name
@@ -178,16 +178,16 @@ class Preference {
* This returns the name from an id, it's the exact opposite
* of the function above it, amazing!
*/
- public static function name_from_id($id) {
+ public static function name_from_id($id) {
- $id = Dba::escape($id);
+ $id = Dba::escape($id);
- $sql = "SELECT `name` FROM `preference` WHERE `id`='$id'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `name` FROM `preference` WHERE `id`='$id'";
+ $db_results = Dba::read($sql);
- $row = Dba::fetch_assoc($db_results);
+ $row = Dba::fetch_assoc($db_results);
- return $row['name'];
+ return $row['name'];
} // name_from_id
@@ -196,20 +196,20 @@ class Preference {
* This returns an array of the names of the different possible sections
* it ignores the 'internal' catagory
*/
- public static function get_catagories() {
+ public static function get_catagories() {
- $sql = "SELECT `preference`.`catagory` FROM `preference` GROUP BY `catagory` ORDER BY `catagory`";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `preference`.`catagory` FROM `preference` GROUP BY `catagory` ORDER BY `catagory`";
+ $db_results = Dba::read($sql);
- $results = array();
+ $results = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- if ($row['catagory'] != 'internal') {
- $results[] = $row['catagory'];
+ while ($row = Dba::fetch_assoc($db_results)) {
+ if ($row['catagory'] != 'internal') {
+ $results[] = $row['catagory'];
}
} // end while
- return $results;
+ return $results;
} // get_catagories
@@ -217,52 +217,52 @@ class Preference {
* get_all
* This returns a nice flat array of all of the possible preferences for the specified user
*/
- public static function get_all($user_id) {
+ public static function get_all($user_id) {
- $user_id = Dba::escape($user_id);
+ $user_id = Dba::escape($user_id);
if ($user_id != '-1') {
$user_limit = "AND `preference`.`catagory` != 'system'";
}
-
- $sql = "SELECT `preference`.`name`,`preference`.`description`,`user_preference`.`value` FROM `preference` " .
- " INNER JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` " .
- " WHERE `user_preference`.`user`='$user_id' AND `preference`.`catagory` != 'internal' $user_limit " .
- " ORDER BY `preference`.`description`";
- $db_results = Dba::read($sql);
- $results = array();
+ $sql = "SELECT `preference`.`name`,`preference`.`description`,`user_preference`.`value` FROM `preference` " .
+ " INNER JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` " .
+ " WHERE `user_preference`.`user`='$user_id' AND `preference`.`catagory` != 'internal' $user_limit " .
+ " ORDER BY `preference`.`description`";
+ $db_results = Dba::read($sql);
+
+ $results = array();
- while ($row = Dba::fetch_assoc($db_results)) {
+ while ($row = Dba::fetch_assoc($db_results)) {
$results[] = array('name'=>$row['name'],'level'=>$row['level'],'description'=>$row['description'],'value'=>$row['value']);
- }
+ }
- return $results;
+ return $results;
- } // get_all
+ } // get_all
/**
* insert
* This inserts a new preference into the preference table
* it does NOT sync up the users, that should be done independtly
*/
- public static function insert($name,$description,$default,$level,$type,$catagory) {
+ public static function insert($name,$description,$default,$level,$type,$catagory) {
- // Clean em up
- $name = Dba::escape($name);
- $description = Dba::escape($description);
- $default = Dba::escape($default);
- $level = Dba::escape($level);
- $type = Dba::escape($type);
- $catagory = Dba::escape($catagory);
+ // Clean em up
+ $name = Dba::escape($name);
+ $description = Dba::escape($description);
+ $default = Dba::escape($default);
+ $level = Dba::escape($level);
+ $type = Dba::escape($type);
+ $catagory = Dba::escape($catagory);
- $sql = "INSERT INTO `preference` (`name`,`description`,`value`,`level`,`type`,`catagory`) " .
- "VALUES ('$name','$description','$default','$level','$type','$catagory')";
- $db_results = Dba::write($sql);
+ $sql = "INSERT INTO `preference` (`name`,`description`,`value`,`level`,`type`,`catagory`) " .
+ "VALUES ('$name','$description','$default','$level','$type','$catagory')";
+ $db_results = Dba::write($sql);
- if (!$db_results) { return false; }
+ if (!$db_results) { return false; }
- return true;
+ return true;
} // insert
@@ -270,21 +270,21 @@ class Preference {
* delete
* This deletes the specified preference, a name or a ID can be passed
*/
- public static function delete($preference) {
+ public static function delete($preference) {
// First prepare
if (!is_numeric($preference)) {
- $name = Dba::escape($preference);
- $sql = "DELETE FROM `preference` WHERE `name`='$name'";
+ $name = Dba::escape($preference);
+ $sql = "DELETE FROM `preference` WHERE `name`='$name'";
}
else {
- $id = Dba::escape($preference);
- $sql = "DELETE FROM `preference` WHERE `id`='$id'";
+ $id = Dba::escape($preference);
+ $sql = "DELETE FROM `preference` WHERE `id`='$id'";
}
- $db_results = Dba::write($sql);
+ $db_results = Dba::write($sql);
- self::rebuild_preferences();
+ self::rebuild_preferences();
} // delete
@@ -292,34 +292,34 @@ class Preference {
* rebuild_preferences
* This removes any garbage and then adds back in anything missing preferences wise
*/
- public static function rebuild_preferences() {
+ public static function rebuild_preferences() {
// First remove garbage
- $sql = "DELETE FROM `user_preference` USING `user_preference` LEFT JOIN `preference` ON `preference`.`id`=`user_preference`.`preference` " .
- "WHERE `preference`.`id` IS NULL";
- $db_results = Dba::write($sql);
+ $sql = "DELETE FROM `user_preference` USING `user_preference` LEFT JOIN `preference` ON `preference`.`id`=`user_preference`.`preference` " .
+ "WHERE `preference`.`id` IS NULL";
+ $db_results = Dba::write($sql);
// Now add anything that we are missing back in, except System
- $sql = "SELECT * FROM `preference` WHERE `type`!='system'";
+ $sql = "SELECT * FROM `preference` WHERE `type`!='system'";
//FIXME: Uhh WTF shouldn't there be something here??
} // rebuild_preferences
/**
* fix_preferences
- * This takes the preferences, explodes what needs to
+ * This takes the preferences, explodes what needs to
* become an array and boolean everythings
*/
public static function fix_preferences($results) {
- $results['auth_methods'] = trim($results['auth_methods']) ? explode(",",$results['auth_methods']) : array();
- $results['tag_order'] = trim($results['tag_order']) ? explode(",",$results['tag_order']) : array();
- $results['album_art_order'] = trim($results['album_art_order']) ? explode(",",$results['album_art_order']) : array();
+ $results['auth_methods'] = trim($results['auth_methods']) ? explode(",",$results['auth_methods']) : array();
+ $results['tag_order'] = trim($results['tag_order']) ? explode(",",$results['tag_order']) : array();
+ $results['album_art_order'] = trim($results['album_art_order']) ? explode(",",$results['album_art_order']) : array();
if (isset($results['amazin_base_urls']))
$results['amazon_base_urls'] = trim($results['amazin_base_urls']) ? explode(",",$results['amazon_base_urls']) : array();
- else
+ else
$results['amazon_base_urls']= array();
-
+
foreach ($results as $key=>$data) {
if (!is_array($data)) {
if (strcasecmp($data,"true") == "0") { $results[$key] = 1; }
@@ -334,15 +334,15 @@ class Preference {
/**
* load_from_session
* This loads the preferences from the session rather then creating a connection to the database
- */
- public static function load_from_session($uid=-1) {
+ */
+ public static function load_from_session($uid=-1) {
- if (is_array($_SESSION['userdata']['preferences']) AND $_SESSION['userdata']['uid'] == $uid) {
- Config::set_by_array($_SESSION['userdata']['preferences'],1);
- return true;
- }
+ if (is_array($_SESSION['userdata']['preferences']) AND $_SESSION['userdata']['uid'] == $uid) {
+ Config::set_by_array($_SESSION['userdata']['preferences'],1);
+ return true;
+ }
- return false;
+ return false;
} // load_from_session
@@ -351,9 +351,9 @@ class Preference {
* This clears the users preferences, this is done whenever modifications are made to the preferences
* or the admin resets something
*/
- public static function clear_from_session() {
+ public static function clear_from_session() {
- unset($_SESSION['userdata']['preferences']);
+ unset($_SESSION['userdata']['preferences']);
} // clear_from_session
@@ -363,7 +363,7 @@ class Preference {
* This is currently only used by the debug view, could be used other places.. wouldn't be a half
* bad idea
*/
- public static function is_boolean($key) {
+ public static function is_boolean($key) {
$boolean_array = array('session_cookiesecure','require_session',
'access_control','require_localnet_session',
@@ -377,13 +377,13 @@ class Preference {
'allow_stream_playback','allow_democratic_playback',
'use_auth','allow_localplay_playback','debug','lock_songs',
'transcode_m4a','transcode_mp3','transcode_ogg','transcode_flac',
- 'shoutcast_active','httpq_active','show_lyrics');
+ 'shoutcast_active','httpq_active','show_lyrics');
- if (in_array($key,$boolean_array)) {
- return true;
- }
+ if (in_array($key,$boolean_array)) {
+ return true;
+ }
- return false;
+ return false;
} // is_boolean
@@ -392,25 +392,25 @@ class Preference {
* This grabs the preferences and then loads them into conf it should be run on page load
* to initialize the needed variables
*/
- public static function init() {
+ public static function init() {
- $user_id = $GLOBALS['user']->id ? Dba::escape($GLOBALS['user']->id) : '-1';
+ $user_id = $GLOBALS['user']->id ? Dba::escape($GLOBALS['user']->id) : '-1';
// First go ahead and try to load it from the preferences
- if (self::load_from_session($user_id)) {
- return true;
- }
-
+ if (self::load_from_session($user_id)) {
+ return true;
+ }
+
/* Get Global Preferences */
- $sql = "SELECT `preference`.`name`,`user_preference`.`value`,`syspref`.`value` AS `system_value` FROM `preference` " .
- "LEFT JOIN `user_preference` `syspref` ON `syspref`.`preference`=`preference`.`id` AND `syspref`.`user`='-1' AND `preference`.`catagory`='system' " .
- "LEFT JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` AND `user_preference`.`user`='$user_id' AND `preference`.`catagory`!='system'";
+ $sql = "SELECT `preference`.`name`,`user_preference`.`value`,`syspref`.`value` AS `system_value` FROM `preference` " .
+ "LEFT JOIN `user_preference` `syspref` ON `syspref`.`preference`=`preference`.`id` AND `syspref`.`user`='-1' AND `preference`.`catagory`='system' " .
+ "LEFT JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` AND `user_preference`.`user`='$user_id' AND `preference`.`catagory`!='system'";
$db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
- $value = $row['system_value'] ? $row['system_value'] : $row['value'];
+ $value = $row['system_value'] ? $row['system_value'] : $row['value'];
$name = $row['name'];
- $results[$name] = $value;
+ $results[$name] = $value;
} // end while sys prefs
/* Set the Theme mojo */
@@ -425,8 +425,8 @@ class Preference {
}
Config::set_by_array($results,1);
- $_SESSION['userdata']['preferences'] = $results;
- $_SESSION['userdata']['uid'] = $user_id;
+ $_SESSION['userdata']['preferences'] = $results;
+ $_SESSION['userdata']['uid'] = $user_id;
} // init
diff --git a/lib/class/query.class.php b/lib/class/query.class.php
index 057897e2..109cef1f 100644
--- a/lib/class/query.class.php
+++ b/lib/class/query.class.php
@@ -817,15 +817,15 @@ class Query {
switch (self::$type) {
case 'song':
switch($filter) {
- case 'tag':
+ case 'tag':
self::set_join('left','`tag_map`','`tag_map`.`object_id`','`song`.`id`');
- $filter_sql = " `tag_map`.`object_type`='song' AND (";
-
- foreach ($value as $tag_id) {
- $filter_sql .= " `tag_map`.`tag_id`='" . Dba::escape($tag_id) . "' AND";
+ $filter_sql = " `tag_map`.`object_type`='song' AND (";
+
+ foreach ($value as $tag_id) {
+ $filter_sql .= " `tag_map`.`tag_id`='" . Dba::escape($tag_id) . "' AND";
}
- $filter_sql = rtrim($filter_sql,'AND') . ') AND ';
- break;
+ $filter_sql = rtrim($filter_sql,'AND') . ') AND ';
+ break;
case 'exact_match':
$filter_sql = " `song`.`title` = '" . Dba::escape($value) . "' AND ";
break;
@@ -971,9 +971,9 @@ class Query {
case 'exact_match':
$filter_sql = " `tag`.`name` = '" . Dba::escape($value) . "' AND ";
break;
- case 'tag':
- $filter_sql = " `tag`.`id` = '" . Dba::escape($value) . "' AND ";
- break;
+ case 'tag':
+ $filter_sql = " `tag`.`id` = '" . Dba::escape($value) . "' AND ";
+ break;
default:
// Rien a faire
break;
diff --git a/lib/class/radio.class.php b/lib/class/radio.class.php
index 65cdf1d0..7112ea5c 100644
--- a/lib/class/radio.class.php
+++ b/lib/class/radio.class.php
@@ -17,7 +17,7 @@
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.
*/
@@ -29,26 +29,26 @@
class Radio extends database_object implements media {
/* DB based variables */
- public $id;
- public $name;
- public $site_url;
- public $url;
+ public $id;
+ public $name;
+ public $site_url;
+ public $url;
public $frequency;
public $call_sign;
- public $catalog;
+ public $catalog;
/**
* Constructor
* This takes a flagged.id and then pulls in the information for said flag entry
*/
- public function __construct($id) {
+ public function __construct($id) {
$info = $this->get_info($id,'live_stream');
// Set the vars
- foreach ($info as $key=>$value) {
- $this->$key = $value;
- }
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
} // constructor
@@ -57,111 +57,111 @@ class Radio extends database_object implements media {
* This takes the normal data from the database and makes it pretty
* for the users, the new variables are put in f_??? and f_???_link
*/
- public function format() {
+ public function format() {
// Default link used on the rightbar
- $this->f_link = "<a href=\"$this->url\">$this->name</a>";
+ $this->f_link = "<a href=\"$this->url\">$this->name</a>";
- $this->f_name_link = "<a target=\"_blank\" href=\"$this->site_url\">$this->name</a>";
- $this->f_callsign = scrub_out($this->call_sign);
- $this->f_frequency = scrub_out($this->frequency);
+ $this->f_name_link = "<a target=\"_blank\" href=\"$this->site_url\">$this->name</a>";
+ $this->f_callsign = scrub_out($this->call_sign);
+ $this->f_frequency = scrub_out($this->frequency);
- return true;
+ return true;
} // format
/**
* update
* This is a static function that takes a key'd array for input
- * it depends on a ID element to determine which radio element it
+ * it depends on a ID element to determine which radio element it
* should be updating
*/
- public static function update($data) {
+ public static function update($data) {
// Verify the incoming data
- if (!$data['id']) {
+ if (!$data['id']) {
// FIXME: Untranslated
- Error::add('general','Missing ID');
- }
+ Error::add('general','Missing ID');
+ }
- if (!$data['name']) {
+ if (!$data['name']) {
// FIXME: Untranslated
- Error::add('general','Name Required');
- }
+ Error::add('general','Name Required');
+ }
- $allowed_array = array('https','http','mms','mmsh','mmsu','mmst','rtsp');
+ $allowed_array = array('https','http','mms','mmsh','mmsu','mmst','rtsp');
- $elements = explode(":",$data['url']);
-
- if (!in_array($elements['0'],$allowed_array)) {
+ $elements = explode(":",$data['url']);
+
+ if (!in_array($elements['0'],$allowed_array)) {
// FIXME: Untranslated
- Error::add('general','Invalid URL must be mms:// , https:// or http://');
- }
+ Error::add('general','Invalid URL must be mms:// , https:// or http://');
+ }
- if (Error::occurred()) {
- return false;
- }
+ if (Error::occurred()) {
+ return false;
+ }
// Setup the data
- $name = Dba::escape($data['name']);
- $site_url = Dba::escape($data['site_url']);
- $url = Dba::escape($data['url']);
- $frequency = Dba::escape($data['frequency']);
- $call_sign = Dba::escape($data['call_sign']);
- $id = Dba::escape($data['id']);
+ $name = Dba::escape($data['name']);
+ $site_url = Dba::escape($data['site_url']);
+ $url = Dba::escape($data['url']);
+ $frequency = Dba::escape($data['frequency']);
+ $call_sign = Dba::escape($data['call_sign']);
+ $id = Dba::escape($data['id']);
- $sql = "UPDATE `live_stream` SET `name`='$name',`site_url`='$site_url',`url`='$url'" .
- ",`frequency`='$frequency',`call_sign`='$call_sign' WHERE `id`='$id'";
- $db_results = Dba::write($sql);
+ $sql = "UPDATE `live_stream` SET `name`='$name',`site_url`='$site_url',`url`='$url'" .
+ ",`frequency`='$frequency',`call_sign`='$call_sign' WHERE `id`='$id'";
+ $db_results = Dba::write($sql);
- return $db_results;
+ return $db_results;
} // update
/**
* create
* This is a static function that takes a key'd array for input
- * and if everything is good creates the object.
+ * and if everything is good creates the object.
*/
- public static function create($data) {
+ public static function create($data) {
// Make sure we've got a name
- if (!strlen($data['name'])) {
+ if (!strlen($data['name'])) {
// FIXME: Untranslated
- Error::add('name','Name Required');
- }
+ Error::add('name','Name Required');
+ }
+
+ $allowed_array = array('https','http','mms','mmsh','mmsu','mmst','rtsp');
- $allowed_array = array('https','http','mms','mmsh','mmsu','mmst','rtsp');
+ $elements = explode(":",$data['url']);
- $elements = explode(":",$data['url']);
-
- if (!in_array($elements['0'],$allowed_array)) {
- Error::add('url','Invalid URL must be http:// or https://');
- }
+ if (!in_array($elements['0'],$allowed_array)) {
+ Error::add('url','Invalid URL must be http:// or https://');
+ }
// Make sure it's a real catalog
- $catalog = new Catalog($data['catalog']);
- if (!$catalog->name) {
+ $catalog = new Catalog($data['catalog']);
+ if (!$catalog->name) {
// FIXME: Untranslated
- Error::add('catalog','Invalid Catalog');
- }
+ Error::add('catalog','Invalid Catalog');
+ }
- if (Error::occurred()) { return false; }
+ if (Error::occurred()) { return false; }
// Clean up the input
- $name = Dba::escape($data['name']);
- $site_url = Dba::escape($data['site_url']);
- $url = Dba::escape($data['url']);
- $catalog = $catalog->id;
- $frequency = Dba::escape($data['frequency']);
- $call_sign = Dba::escape($data['call_sign']);
+ $name = Dba::escape($data['name']);
+ $site_url = Dba::escape($data['site_url']);
+ $url = Dba::escape($data['url']);
+ $catalog = $catalog->id;
+ $frequency = Dba::escape($data['frequency']);
+ $call_sign = Dba::escape($data['call_sign']);
// If we've made it this far everything must be ok... I hope
- $sql = "INSERT INTO `live_stream` (`name`,`site_url`,`url`,`catalog`,`frequency`,`call_sign`) " .
- "VALUES ('$name','$site_url','$url','$catalog','$frequency','$call_sign')";
- $db_results = Dba::write($sql);
+ $sql = "INSERT INTO `live_stream` (`name`,`site_url`,`url`,`catalog`,`frequency`,`call_sign`) " .
+ "VALUES ('$name','$site_url','$url','$catalog','$frequency','$call_sign')";
+ $db_results = Dba::write($sql);
- return $db_results;
+ return $db_results;
} // create
@@ -169,14 +169,14 @@ class Radio extends database_object implements media {
* delete
* This deletes the current object from the database
*/
- public function delete() {
+ public function delete() {
- $id = Dba::escape($this->id);
+ $id = Dba::escape($this->id);
- $sql = "DELETE FROM `live_stream` WHERE `id`='$id'";
- $db_results = Dba::write($sql);
+ $sql = "DELETE FROM `live_stream` WHERE `id`='$id'";
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // delete
@@ -184,29 +184,29 @@ class Radio extends database_object implements media {
* native_stream
* This is needed by the media interface
*/
- public function native_stream() {
+ public function native_stream() {
- } // native_stream
+ } // native_stream
/**
* play_url
* This is needed by the media interface
*/
- public static function play_url($oid,$sid='',$force_http='') {
+ public static function play_url($oid,$sid='',$force_http='') {
+
+ $radio = new Radio($oid);
- $radio = new Radio($oid);
-
- return $radio->url;
+ return $radio->url;
- } // play_url
+ } // play_url
/**
* has_flag
* This is needed by the media interface
*/
- public function has_flag() {
+ public function has_flag() {
@@ -216,7 +216,7 @@ class Radio extends database_object implements media {
* stream_cmd
* Needed by the media interface
*/
- public function stream_cmd() {
+ public function stream_cmd() {
} // stream_cmd
diff --git a/lib/class/random.class.php b/lib/class/random.class.php
index eab6b3f9..582d00ac 100644
--- a/lib/class/random.class.php
+++ b/lib/class/random.class.php
@@ -17,7 +17,7 @@
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.
*/
@@ -30,17 +30,17 @@
class Random implements media {
public $type;
- public $id;
+ public $id;
/**
* Constructor
* nothing to see here, move along
*/
- public function __construct($id) {
+ public function __construct($id) {
- $this->type = Random::get_id_type($id);
- $this->id = intval($id);
+ $this->type = Random::get_id_type($id);
+ $this->id = intval($id);
} // constructor
@@ -48,14 +48,14 @@ class Random implements media {
* album
* This returns the ID of a random album, nothing special
*/
- public static function album() {
+ public static function album() {
- $sql = "SELECT `id` FROM `album` ORDER BY RAND() LIMIT 1";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id` FROM `album` ORDER BY RAND() LIMIT 1";
+ $db_results = Dba::read($sql);
- $results = Dba::fetch_assoc($db_results);
+ $results = Dba::fetch_assoc($db_results);
- return $results['id'];
+ return $results['id'];
} // album
@@ -63,14 +63,14 @@ class Random implements media {
* artist
* This returns the ID of a random artist, nothing special here for now
*/
- public static function artist() {
+ public static function artist() {
- $sql = "SELECT `id` FROM `artist` ORDER BY RAND() LIMIT 1";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id` FROM `artist` ORDER BY RAND() LIMIT 1";
+ $db_results = Dba::read($sql);
- $results = Dba::fetch_assoc($db_results);
+ $results = Dba::fetch_assoc($db_results);
- return $results['id'];
+ return $results['id'];
} // artist
@@ -79,16 +79,16 @@ class Random implements media {
* This returns a random Playlist with songs little bit of extra
* logic require
*/
- public static function playlist() {
+ public static function playlist() {
- $sql = "SELECT `playlist`.`id` FROM `playlist` LEFT JOIN `playlist_data` " .
- " ON `playlist`.`id`=`playlist_data`.`playlist` WHERE `playlist_data`.`object_id` IS NOT NULL " .
- " ORDER BY RAND()";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `playlist`.`id` FROM `playlist` LEFT JOIN `playlist_data` " .
+ " ON `playlist`.`id`=`playlist_data`.`playlist` WHERE `playlist_data`.`object_id` IS NOT NULL " .
+ " ORDER BY RAND()";
+ $db_results = Dba::read($sql);
- $results = Dba::fetch_assoc($db_results);
+ $results = Dba::fetch_assoc($db_results);
- return $results['id'];
+ return $results['id'];
} // playlist
@@ -97,38 +97,38 @@ class Random implements media {
* This generates a random play url based on the passed type
* and returns it
*/
- public static function play_url($id,$sid='',$force_http='') {
-
- if (!$type = self::get_id_type($id)) {
- return false;
- }
-
- $uid = $GLOBALS['user']->id;
-
+ public static function play_url($id,$sid='',$force_http='') {
+
+ if (!$type = self::get_id_type($id)) {
+ return false;
+ }
+
+ $uid = $GLOBALS['user']->id;
+
$url = Stream::get_base_url() . "random=1&type=$type&uid=$uid";
- return $url;
+ return $url;
- } // play_url
+ } // play_url
/**
* get_single_song
* This returns a single song pulled based on the passed random method
*/
- public static function get_single_song($type) {
+ public static function get_single_song($type) {
- if (!$type = self::validate_type($type)) {
- return false;
- }
+ if (!$type = self::validate_type($type)) {
+ return false;
+ }
+
+ $method_name = 'get_' . $type;
- $method_name = 'get_' . $type;
+ if (method_exists('Random',$method_name)) {
+ $song_ids = self::$method_name(1);
+ $song_id = array_pop($song_ids);
+ }
- if (method_exists('Random',$method_name)) {
- $song_ids = self::$method_name(1);
- $song_id = array_pop($song_ids);
- }
-
- return $song_id;
+ return $song_id;
} // get_single_song
@@ -136,19 +136,19 @@ class Random implements media {
* get_default
* This just randomly picks a song at whim from all catalogs
* nothing special here...
- */
- public static function get_default($limit) {
+ */
+ public static function get_default($limit) {
- $results = array();
+ $results = array();
- $sql = "SELECT `id` FROM `song` ORDER BY RAND() LIMIT $limit";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id` FROM `song` ORDER BY RAND() LIMIT $limit";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['id'];
- }
-
- return $results;
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
+
+ return $results;
} // get_default
@@ -157,24 +157,24 @@ class Random implements media {
* This looks at the last object played by the current user and
* then picks a song of the same genre at random...
*/
- public static function get_genre($limit) {
+ public static function get_genre($limit) {
- $results = array();
+ $results = array();
// Get the last genre played by us
- $data = $GLOBALS['user']->get_recently_played('1','genre');
- if ($data['0']) {
- $where_sql = " WHERE `genre`='" . $data['0'] . "' ";
- }
+ $data = $GLOBALS['user']->get_recently_played('1','genre');
+ if ($data['0']) {
+ $where_sql = " WHERE `genre`='" . $data['0'] . "' ";
+ }
- $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
- return $results;
+ return $results;
} // get_genre
@@ -183,24 +183,24 @@ class Random implements media {
* This looks at the last album played by the current user and
* picks something else in the same album
*/
- public static function get_album($limit) {
+ public static function get_album($limit) {
- $results = array();
+ $results = array();
// Get the last album playbed by us
- $data = $GLOBALS['user']->get_recently_played('1','album');
- if ($data['0']) {
+ $data = $GLOBALS['user']->get_recently_played('1','album');
+ if ($data['0']) {
$where_sql = " WHERE `album`='" . $data['0'] . "' ";
- }
+ }
- $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
- return $results;
+ return $results;
} // get_album
@@ -209,59 +209,59 @@ class Random implements media {
* This looks at the last artist played and then randomly picks a song from the
* same artist
*/
- public static function get_artist($limit) {
+ public static function get_artist($limit) {
+
+ $results = array();
- $results = array();
+ $data = $GLOBALS['user']->get_recently_played('1','artist');
+ if ($data['0']) {
+ $where_sql = " WHERE `artist`='" . $data['0'] . "' ";
+ }
- $data = $GLOBALS['user']->get_recently_played('1','artist');
- if ($data['0']) {
- $where_sql = " WHERE `artist`='" . $data['0'] . "' ";
- }
+ $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit";
+ $db_results = Dba::read($sql);
- $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit";
- $db_results = Dba::read($sql);
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['id'];
- }
-
- return $results;
+ return $results;
} // get_artist
/**
* advanced
- * This processes the results of a post from a form and returns an
- * array of song items that were returned from said randomness
+ * This processes the results of a post from a form and returns an
+ * array of song items that were returned from said randomness
*/
- public static function advanced($data) {
+ public static function advanced($data) {
/* Figure out our object limit */
- $limit = intval($data['random']);
+ $limit = intval($data['random']);
// Generate our matchlist
if ($data['catalog'] != '-1') {
- $matchlist['catalog'] = $data['catalog'];
+ $matchlist['catalog'] = $data['catalog'];
}
- if ($data['genre'][0] != '-1') {
- $matchlist['genre'] = $data['genre'];
- }
-
+ if ($data['genre'][0] != '-1') {
+ $matchlist['genre'] = $data['genre'];
+ }
+
/* If they've passed -1 as limit then don't get everything */
if ($data['random'] == "-1") { unset($data['random']); }
else { $limit_sql = "LIMIT " . Dba::escape($limit); }
$where = "1=1 ";
- if (is_array($matchlist)) {
+ if (is_array($matchlist)) {
foreach ($matchlist as $type => $value) {
if (is_array($value)) {
foreach ($value as $v) {
- if (!strlen($v)) { continue; }
+ if (!strlen($v)) { continue; }
$v = Dba::escape($v);
if ($v != $value[0]) { $where .= " OR $type='$v' "; }
else { $where .= " AND ( $type='$v'"; }
}
- $where .= ")";
+ $where .= ")";
}
elseif (strlen($value)) {
$value = Dba::escape($value);
@@ -269,10 +269,10 @@ class Random implements media {
}
} // end foreach
} // end if matchlist
-
- switch ($data['random_type']) {
- case 'full_album':
- $query = "SELECT `album`.`id` FROM `song` INNER JOIN `album` ON `song`.`album`=`album`.`id` " .
+
+ switch ($data['random_type']) {
+ case 'full_album':
+ $query = "SELECT `album`.`id` FROM `song` INNER JOIN `album` ON `song`.`album`=`album`.`id` " .
"WHERE $where GROUP BY `song`.`album` ORDER BY RAND() $limit_sql";
$db_results = Dba::read($query);
while ($row = Dba::fetch_assoc($db_results)) {
@@ -280,9 +280,9 @@ class Random implements media {
}
$albums_where = ltrim($albums_where," OR");
$sql = "SELECT `song`.`id`,`song`.`size`,`song`.`time` FROM `song` WHERE $albums_where ORDER BY `song`.`album`,`song`.`track` ASC";
- break;
- case 'full_artist':
- $query = "SELECT `artist`.`id` FROM `song` INNER JOIN `artist` ON `song`.`artist`=`artist`.`id` " .
+ break;
+ case 'full_artist':
+ $query = "SELECT `artist`.`id` FROM `song` INNER JOIN `artist` ON `song`.`artist`=`artist`.`id` " .
"WHERE $where GROUP BY `song`.`artist` ORDER BY RAND() $limit_sql";
$db_results = Dba::read($query);
while ($row = Dba::fetch_row($db_results)) {
@@ -291,114 +291,114 @@ class Random implements media {
$artists_where = ltrim($artists_where," OR");
$sql = "SELECT song.id,song.size,song.time FROM song WHERE $artists_where ORDER BY RAND()";
break;
- case 'unplayed':
- $uid = Dba::escape($GLOBALS['user']->id);
+ case 'unplayed':
+ $uid = Dba::escape($GLOBALS['user']->id);
$sql = "SELECT object_id,COUNT(`id`) AS `total` FROM `object_count` WHERE `user`='$uid' GROUP BY `object_id`";
- $db_results = Dba::read($sql);
+ $db_results = Dba::read($sql);
$in_sql = "`id` IN (";
- while ($row = Dba::fetch_assoc($db_results)) {
- $row['object_id'] = Dba::escape($row['object_id']);
- $in_sql .= "'" . $row['object_id'] . "',";
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $row['object_id'] = Dba::escape($row['object_id']);
+ $in_sql .= "'" . $row['object_id'] . "',";
+ }
$in_sql = rtrim($in_sql,',') . ')';
$sql = "SELECT song.id,song.size,song.time FROM song " .
"WHERE ($where) AND $in_sql ORDER BY RAND() $limit_sql";
- break;
- case 'high_rating':
- $sql = "SELECT `rating`.`object_id`,`rating`.`rating` FROM `rating` " .
- "WHERE `rating`.`object_type`='song' ORDER BY `rating` DESC";
- $db_results = Dba::read($sql);
+ break;
+ case 'high_rating':
+ $sql = "SELECT `rating`.`object_id`,`rating`.`rating` FROM `rating` " .
+ "WHERE `rating`.`object_type`='song' ORDER BY `rating` DESC";
+ $db_results = Dba::read($sql);
// Get all of the ratings for songs
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[$row['object_id']][] = $row['rating'];
- }
- // Calculate the averages
- foreach ($results as $key=>$rating_array) {
- $average = intval(array_sum($rating_array) / count($rating_array));
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[$row['object_id']][] = $row['rating'];
+ }
+ // Calculate the averages
+ foreach ($results as $key=>$rating_array) {
+ $average = intval(array_sum($rating_array) / count($rating_array));
// We have to do this because array_slice doesn't maintain indexes
- $new_key = $average . $key;
+ $new_key = $average . $key;
$ratings[$new_key] = $key;
- }
+ }
// Sort it by the value and slice at $limit * 2 so we have a little bit of randomness
- krsort($ratings);
- $ratings = array_slice($ratings,0,$limit*2);
-
- $in_sql = "`song`.`id` IN (";
-
+ krsort($ratings);
+ $ratings = array_slice($ratings,0,$limit*2);
+
+ $in_sql = "`song`.`id` IN (";
+
// Build the IN query, cause if you're OUT it ain't cool
- foreach ($ratings as $song_id) {
+ foreach ($ratings as $song_id) {
$key = Dba::escape($song_id);
- $in_sql .= "'$key',";
- }
+ $in_sql .= "'$key',";
+ }
- $in_sql = rtrim($in_sql,',') . ')';
+ $in_sql = rtrim($in_sql,',') . ')';
// Apply true limit and order by rand
- $sql = "SELECT song.id,song.size,song.time FROM song " .
- "WHERE ($where) AND $in_sql ORDER BY RAND() $limit_sql";
+ $sql = "SELECT song.id,song.size,song.time FROM song " .
+ "WHERE ($where) AND $in_sql ORDER BY RAND() $limit_sql";
break;
- default:
- $sql = "SELECT `id`,`size`,`time` FROM `song` WHERE $where ORDER BY RAND() $limit_sql";
+ default:
+ $sql = "SELECT `id`,`size`,`time` FROM `song` WHERE $where ORDER BY RAND() $limit_sql";
break;
- } // end switch on type of random play
+ } // end switch on type of random play
// Run the query generated above so we can while it
- $db_results = Dba::read($sql);
- $results = array();
+ $db_results = Dba::read($sql);
+ $results = array();
+
+ while ($row = Dba::fetch_assoc($db_results)) {
- while ($row = Dba::fetch_assoc($db_results)) {
-
// If size limit is specified
- if ($data['size_limit']) {
+ if ($data['size_limit']) {
// Convert
- $new_size = ($row['size'] / 1024) / 1024;
-
+ $new_size = ($row['size'] / 1024) / 1024;
+
// Only fuzzy 10 times
- if ($fuzzy_size > 10) { return $results; }
+ if ($fuzzy_size > 10) { return $results; }
// Add and check, skip if over don't return incase theres a smaller one commin round
- if (($size_total + $new_size) > $data['size_limit']) { $fuzzy_size++; continue; }
-
- $size_total = $size_total + $new_size;
- $results[] = $row['id'];
+ if (($size_total + $new_size) > $data['size_limit']) { $fuzzy_size++; continue; }
+
+ $size_total = $size_total + $new_size;
+ $results[] = $row['id'];
// If we are within 4mb of target then jump ship
- if (($data['size_limit'] - floor($size_total)) < 4) { return $results; }
+ if (($data['size_limit'] - floor($size_total)) < 4) { return $results; }
} // if size_limit
// If length really does matter
- if ($data['length']) {
+ if ($data['length']) {
// base on min, seconds are for chumps and chumpettes
- $new_time = floor($row['time'] / 60);
+ $new_time = floor($row['time'] / 60);
+
+ if ($fuzzy_time > 10) { return $results; }
- if ($fuzzy_time > 10) { return $results; }
-
// If the new one would go voer skip!
- if (($time_total + $new_time) > $data['length']) { $fuzzy_time++; continue; }
+ if (($time_total + $new_time) > $data['length']) { $fuzzy_time++; continue; }
- $time_total = $time_total + $new_time;
- $results[] = $row['id'];
+ $time_total = $time_total + $new_time;
+ $results[] = $row['id'];
- // If there are less then 2 min of free space return
- if (($data['length'] - $time_total) < 2) { return $results; }
+ // If there are less then 2 min of free space return
+ if (($data['length'] - $time_total) < 2) { return $results; }
- } // if length does matter
+ } // if length does matter
- if (!$data['size_limit'] AND !$data['length']) {
- $results[] = $row['id'];
- }
+ if (!$data['size_limit'] AND !$data['length']) {
+ $results[] = $row['id'];
+ }
} // end while results
- return $results;
+ return $results;
} // advanced
@@ -406,22 +406,22 @@ class Random implements media {
* get_type_name
* This returns a 'purrty' name for the differnt random types
*/
- public static function get_type_name($type) {
+ public static function get_type_name($type) {
- switch ($type) {
+ switch ($type) {
case 'album':
- return _('Related Album');
+ return _('Related Album');
break;
- case 'genre':
- return _('Related Genre');
+ case 'genre':
+ return _('Related Genre');
break;
- case 'artist':
- return _('Related Artist');
+ case 'artist':
+ return _('Related Artist');
break;
- default:
- return _('Pure Random');
+ default:
+ return _('Pure Random');
break;
- } // end switch
+ } // end switch
} // get_type_name
@@ -431,22 +431,22 @@ class Random implements media {
* MOTHER OF PEARL THIS MAKES BABY JESUS CRY
* HACK HACK HACK HACK HACK HACK HACK HACK
*/
- public static function get_type_id($type) {
-
- switch ($type) {
- case 'album':
- return '1';
- break;
- case 'artist':
- return '2';
- break;
- case 'tag':
- return '3';
- break;
- default:
- return '4';
- break;
- }
+ public static function get_type_id($type) {
+
+ switch ($type) {
+ case 'album':
+ return '1';
+ break;
+ case 'artist':
+ return '2';
+ break;
+ case 'tag':
+ return '3';
+ break;
+ default:
+ return '4';
+ break;
+ }
} // get_type_id
@@ -454,24 +454,24 @@ class Random implements media {
* get_id_name
* This takes an ID and returns the 'name' of the random dealie
* HACK HACK HACK HACK HACK HACK HACK
- * Can you tell I don't like this code?
+ * Can you tell I don't like this code?
*/
- public static function get_id_type($id) {
+ public static function get_id_type($id) {
- switch ($id) {
- case '1':
+ switch ($id) {
+ case '1':
return 'album';
break;
- case '2':
+ case '2':
return 'artist';
- break;
- case '3':
+ break;
+ case '3':
return 'tag';
- break;
- default:
- return 'default';
- break;
- } // end switch
+ break;
+ default:
+ return 'default';
+ break;
+ } // end switch
} // get_id_name
@@ -479,7 +479,7 @@ class Random implements media {
* validiate_type
* this validates the random type
*/
- public static function validate_type($type) {
+ public static function validate_type($type) {
switch ($type) {
case 'default':
@@ -487,19 +487,19 @@ class Random implements media {
case 'album':
case 'artist':
case 'rated':
- return $type;
+ return $type;
break;
default:
return 'default';
break;
} // end switch
-
- return $type;
+
+ return $type;
} // validate_type
- public function native_stream() { }
- public function stream_cmd() { }
+ public function native_stream() { }
+ public function stream_cmd() { }
public function has_flag() { }
public function format() { }
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php
index f5af5519..5c2bb3e9 100644
--- a/lib/class/rating.class.php
+++ b/lib/class/rating.class.php
@@ -23,7 +23,7 @@
/**
* Rating class
* This is an amalgamation(sp?) of code from SoundOfEmotion
- * to track ratings for songs, albums and artists.
+ * to track ratings for songs, albums and artists.
*/
class Rating extends database_object {
@@ -40,21 +40,21 @@ class Rating extends database_object {
* This is run every time a new object is created, it requires
* the id and type of object that we need to pull the raiting for
*/
- public function __construct($id,$type) {
+ public function __construct($id,$type) {
$this->id = intval($id);
$this->type = Dba::escape($type);
// Check for the users rating
- if ($rating = $this->get_user($GLOBALS['user']->id)) {
+ if ($rating = $this->get_user($GLOBALS['user']->id)) {
$this->rating = $rating;
$this->preciserating = $rating;
- }
- else {
+ }
+ else {
$this->get_average();
}
-
- return true;
+
+ return true;
} // Constructor
@@ -65,44 +65,44 @@ class Rating extends database_object {
* //FIXME: Improve logic so that misses get cached as average
*/
public static function build_cache($type, $ids) {
-
+
if (!is_array($ids) OR !count($ids)) { return false; }
- $user_id = Dba::escape($GLOBALS['user']->id);
+ $user_id = Dba::escape($GLOBALS['user']->id);
$idlist = '(' . implode(',', $ids) . ')';
- $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " .
+ $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " .
"AND `object_type`='$type'";
$db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
- $user[$row['object_id']] = $row['rating'];
+ $user[$row['object_id']] = $row['rating'];
}
-
- $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'";
- $db_results = Dba::read($sql);
-
- while ($row = Dba::fetch_assoc($db_results)) {
- $rating[$row['object_id']]['rating'] += $row['rating'];
- $rating[$row['object_id']]['total']++;
- }
-
- foreach ($ids as $id) {
- parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id]));
+
+ $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'";
+ $db_results = Dba::read($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $rating[$row['object_id']]['rating'] += $row['rating'];
+ $rating[$row['object_id']]['total']++;
+ }
+
+ foreach ($ids as $id) {
+ parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id]));
// Do the bit of math required to store this
- if (!isset($rating[$id])) {
- $entry = array('average'=>'0','percise'=>'0');
- }
- else {
- $average = round($rating[$id]['rating']/$rating[$id]['total'],1);
- $entry = array('average'=>floor($average),'percise'=>$average);
- }
-
- parent::add_to_cache('rating_' . $type . '_all',$id,$entry);
- }
-
- return true;
+ if (!isset($rating[$id])) {
+ $entry = array('average'=>'0','percise'=>'0');
+ }
+ else {
+ $average = round($rating[$id]['rating']/$rating[$id]['total'],1);
+ $entry = array('average'=>floor($average),'percise'=>$average);
+ }
+
+ parent::add_to_cache('rating_' . $type . '_all',$id,$entry);
+ }
+
+ return true;
} // build_cache
@@ -112,22 +112,22 @@ class Rating extends database_object {
* in user. It returns the value
*/
public function get_user($user_id) {
-
- $id = intval($this->id);
-
- if (parent::is_cached('rating_' . $this->type . '_user',$id)) {
- return parent::get_from_cache('rating_' . $this->type . '_user',$id);
- }
- $user_id = Dba::escape($user_id);
+ $id = intval($this->id);
+
+ if (parent::is_cached('rating_' . $this->type . '_user',$id)) {
+ return parent::get_from_cache('rating_' . $this->type . '_user',$id);
+ }
+
+ $user_id = Dba::escape($user_id);
$sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$id' AND `object_type`='$this->type'";
$db_results = Dba::read($sql);
-
+
$results = Dba::fetch_assoc($db_results);
- parent::add_to_cache('rating_' . $this->type . '_user',$id,$results['rating']);
-
+ parent::add_to_cache('rating_' . $this->type . '_user',$id,$results['rating']);
+
return $results['rating'];
} // get_user
@@ -136,79 +136,79 @@ class Rating extends database_object {
* get_average
* Get the users average rating this is based off the floor'd average
* of what everyone has rated this album as. This is shown if there
- * is no personal rating, and used for random play mojo. It sets
+ * is no personal rating, and used for random play mojo. It sets
* $this->average_rating and returns the value
*/
- public function get_average() {
+ public function get_average() {
- $id = intval($this->id);
+ $id = intval($this->id);
- if (parent::is_cached('rating_' . $this->type . '_all',$id)) {
- $data = parent::get_from_cache('rating_' . $this->type . '_user',$id);
- $this->rating = $data['rating'];
- $this->perciserating = $data['percise'];
- return true;
- }
+ if (parent::is_cached('rating_' . $this->type . '_all',$id)) {
+ $data = parent::get_from_cache('rating_' . $this->type . '_user',$id);
+ $this->rating = $data['rating'];
+ $this->perciserating = $data['percise'];
+ return true;
+ }
$sql = "SELECT `rating` FROM `rating` WHERE `object_id`='$id' AND `object_type`='$this->type'";
$db_results = Dba::read($sql);
$i = 0;
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$i++;
$total += $r['rating'];
} // while we're pulling results
- if ($total > 0) {
+ if ($total > 0) {
$average = round($total/$i, 1);
}
- elseif ($i >= '1' AND $total == '0') {
+ elseif ($i >= '1' AND $total == '0') {
$average = -1;
}
- else {
+ else {
$average = 0;
}
-
+
$this->preciserating = $average;
$this->rating = floor($average);
-
+
return $this->rating;
} // get_average
/**
* set_rating
- * This function sets a rating for the current $this object.
+ * This function sets a rating for the current $this object.
* This uses the currently logged in user for the 'user' who is rating
* the object. Returns true on success, false on failure
*/
- public function set_rating($score) {
-
+ public function set_rating($score) {
+
$score = Dba::escape($score);
// If score is -1, then remove rating
if ($score == '-1') {
- $sql = "DELETE FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " .
+ $sql = "DELETE FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " .
"AND `user`='" . Dba::escape($GLOBALS['user']->id) . "'";
$db_results = Dba::read($sql);
return true;
}
/* Check if it exists */
- $sql = "SELECT `id` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " .
+ $sql = "SELECT `id` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " .
"AND `user`='" . Dba::escape($GLOBALS['user']->id) . "'";
$db_results = Dba::read($sql);
- if ($existing = Dba::fetch_assoc($db_results)) {
+ if ($existing = Dba::fetch_assoc($db_results)) {
$sql = "UPDATE `rating` SET `rating`='$score' WHERE `id`='" . $existing['id'] . "'";
$db_results = Dba::write($sql);
}
- else {
- $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`rating`,`user`) VALUES " .
+ else {
+ $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`rating`,`user`) VALUES " .
" ('$this->id','$this->type','$score','" . $GLOBALS['user']->id . "')";
$db_results = Dba::write($sql);
- }
+ }
return true;
@@ -216,31 +216,31 @@ class Rating extends database_object {
/**
* show
- * This takes an id and a type and displays the rating if ratings are enabled.
+ * This takes an id and a type and displays the rating if ratings are enabled.
*/
- public static function show ($object_id,$type) {
+ public static function show ($object_id,$type) {
// If there aren't ratings don't return anything
- if (!Config::get('ratings')) { return false; }
+ if (!Config::get('ratings')) { return false; }
- $rating = new Rating($object_id,$type);
+ $rating = new Rating($object_id,$type);
- require Config::get('prefix') . '/templates/show_object_rating.inc.php';
+ require Config::get('prefix') . '/templates/show_object_rating.inc.php';
- } // show
+ } // show
/**
* show_static
- * This is a static version of the ratings created by Andy90
+ * This is a static version of the ratings created by Andy90
*/
- public static function show_static ($object_id,$type) {
+ public static function show_static ($object_id,$type) {
// If there aren't ratings don't return anything
- if (!Config::get('ratings')) { return false; }
+ if (!Config::get('ratings')) { return false; }
- $rating = new Rating($object_id,$type);
+ $rating = new Rating($object_id,$type);
- require Config::get('prefix') . '/templates/show_static_object_rating.inc.php';
+ require Config::get('prefix') . '/templates/show_static_object_rating.inc.php';
} // show_static
diff --git a/lib/class/registration.class.php b/lib/class/registration.class.php
index 30987011..ae85670d 100644
--- a/lib/class/registration.class.php
+++ b/lib/class/registration.class.php
@@ -30,7 +30,7 @@ class Registration {
* constructor
* This is what is called when the class is loaded
*/
- public function __construct() {
+ public function __construct() {
// Rien a faire
@@ -40,7 +40,7 @@ class Registration {
* send_confirmation
* This sends the confirmation e-mail for the specified user
*/
- public static function send_confirmation($username,$fullname,$email,$password,$validation) {
+ public static function send_confirmation($username,$fullname,$email,$password,$validation) {
// Multi-byte Character Mail
if(function_exists('mb_language')) {
@@ -76,7 +76,7 @@ Password: %s
Your account is currently inactive. You cannot use it until you've visited the following link:
-%s
+%s
Thank you for registering
"), $username, $password, Config::get('web_path') . "/register.php?action=validate&username=$username&auth=$validation");
@@ -96,7 +96,7 @@ Thank you for registering
}
// Check to see if the admin should be notified
- if (Config::get('admin_notify_reg')) {
+ if (Config::get('admin_notify_reg')) {
$body = sprintf(_("A new user has registered
The following values were entered.
@@ -113,11 +113,11 @@ E-mail: %s
implode("\n", $additional_header),
'-f'.Config::get('mail_from'));
} else {
- mail(Config::get('mail_from'),$subject,$body,implode("\r\n", $additional_header),'-f'.Config::get('mail_from'));
+ mail(Config::get('mail_from'),$subject,$body,implode("\r\n", $additional_header),'-f'.Config::get('mail_from'));
}
- }
-
- return true;
+ }
+
+ return true;
} // send_confirmation
@@ -125,11 +125,11 @@ E-mail: %s
* show_agreement
* This shows the registration agreement, /config/registration_agreement.php
*/
- public static function show_agreement() {
+ public static function show_agreement() {
$filename = Config::get('prefix') . '/config/registration_agreement.php';
- if (!file_exists($filename)) { return false; }
+ if (!file_exists($filename)) { return false; }
/* Check for existance */
$fp = fopen($filename,'r');
diff --git a/lib/class/scrobbler.class.php b/lib/class/scrobbler.class.php
index ee1ae8a2..537b1490 100644
--- a/lib/class/scrobbler.class.php
+++ b/lib/class/scrobbler.class.php
@@ -30,7 +30,7 @@ class scrobbler {
public $submit_port;
public $submit_url;
public $queued_tracks;
- public $reset_handshake = false;
+ public $reset_handshake = false;
public $scrobble_host = 'post.audioscrobbler.com';
/**
@@ -43,11 +43,11 @@ class scrobbler {
$this->username = trim($username);
$this->password = trim($password);
$this->challenge = $challenge;
- $this->submit_host = $host;
- $this->submit_port = $port;
- $this->submit_url = $url;
+ $this->submit_host = $host;
+ $this->submit_port = $port;
+ $this->submit_url = $url;
$this->queued_tracks = array();
- if ($scrobble_host) { $this->scrobble_host = $scrobble_host; }
+ if ($scrobble_host) { $this->scrobble_host = $scrobble_host; }
} // scrobbler
@@ -71,8 +71,8 @@ class scrobbler {
/**
* handshake
- * This does a handshake with the audioscrobber server it doesn't pass the password, but
- * it does pass the username and has a 10 second timeout
+ * This does a handshake with the audioscrobber server it doesn't pass the password, but
+ * it does pass the username and has a 10 second timeout
*/
public function handshake() {
@@ -83,11 +83,11 @@ class scrobbler {
}
$username = rawurlencode($this->username);
- $timestamp = time();
- $auth_token = rawurlencode(md5($this->password . $timestamp));
-
+ $timestamp = time();
+ $auth_token = rawurlencode(md5($this->password . $timestamp));
+
$get_string = "GET /?hs=true&p=1.2&c=apa&v=0.1&u=$username&t=$timestamp&a=$auth_token HTTP/1.1\r\n";
-
+
fwrite($as_socket, $get_string);
fwrite($as_socket, "Host: $this->scrobble_host\r\n");
fwrite($as_socket, "Accept: */*\r\n\r\n");
@@ -111,23 +111,23 @@ class scrobbler {
$this->error_msg = 'Invalid Username';
return false;
}
- if(substr($response[0],0,7) == 'BADTIME') {
- $this->error_msg = 'Your time is too far off from the server, or your PHP timezone is incorrect';
- return false;
- }
+ if(substr($response[0],0,7) == 'BADTIME') {
+ $this->error_msg = 'Your time is too far off from the server, or your PHP timezone is incorrect';
+ return false;
+ }
if(substr($response[0], 0, 6) == 'UPDATE') {
$this->error_msg = 'You need to update your client: '.substr($response[0], 7);
return false;
}
if(preg_match('/http:\/\/([^\/]+)\/(.*)$/', $response[3], $matches)) {
- $host_parts = explode(":",$matches[1]);
+ $host_parts = explode(":",$matches[1]);
$data['submit_host'] = $host_parts[0];
- $data['submit_port'] = $host_parts[1] ? $host_parts[1] : '80';
+ $data['submit_port'] = $host_parts[1] ? $host_parts[1] : '80';
$data['submit_url'] = '/' . $matches[2];
} else {
- $this->error_msg = "Invalid POST URL returned, unable to continue. Sent:\n$get_string\n----\nReceived:\n" . $buffer .
- "\n---------\nExpeceted:" . print_r($response,1);
+ $this->error_msg = "Invalid POST URL returned, unable to continue. Sent:\n$get_string\n----\nReceived:\n" . $buffer .
+ "\n---------\nExpeceted:" . print_r($response,1);
return false;
}
@@ -137,36 +137,36 @@ class scrobbler {
} // handshake
/**
- * queue_track
+ * queue_track
* This queues the LastFM track by storing it in this object, it doesn't actually
* submit the track or talk to LastFM in anyway, kind of useless for our uses but its
- * here, and that's how it is.
+ * here, and that's how it is.
*/
public function queue_track($artist, $album, $title, $timestamp, $length,$track) {
if ($length < 30) {
debug_event('Scrobbler',"Not queuing track, too short",'5');
return false;
- }
+ }
$newtrack = array();
$newtrack['artist'] = $artist;
$newtrack['album'] = $album;
- $newtrack['title'] = $title;
+ $newtrack['title'] = $title;
$newtrack['track'] = $track;
$newtrack['length'] = $length;
$newtrack['time'] = $timestamp;
$this->queued_tracks[$timestamp] = $newtrack;
- return true;
-
+ return true;
+
} // queue_track
/**
* submit_tracks
* This actually talks to LastFM submiting the tracks that are queued up. It
* passed the md5'd password combinted with the challenge, which is then md5'd
- */
+ */
public function submit_tracks() {
// Check and make sure that we've got some queued tracks
@@ -176,7 +176,7 @@ class scrobbler {
}
//sort array by timestamp
- ksort($this->queued_tracks);
+ ksort($this->queued_tracks);
// build the query string
$query_str = 's='.rawurlencode($this->challenge).'&';
@@ -186,20 +186,20 @@ class scrobbler {
foreach($this->queued_tracks as $track) {
$query_str .= "a[$i]=".rawurlencode($track['artist'])."&t[$i]=".rawurlencode($track['title'])."&b[$i]=".rawurlencode($track['album'])."&";
$query_str .= "m[$i]=&l[$i]=".rawurlencode($track['length'])."&i[$i]=".rawurlencode($track['time'])."&";
- $query_str .= "n[$i]=" . rawurlencode($track['track']) . "&o[$i]=P&r[$i]=&";
+ $query_str .= "n[$i]=" . rawurlencode($track['track']) . "&o[$i]=P&r[$i]=&";
$i++;
}
- if (!trim($this->submit_host) || !$this->submit_port) {
- $this->reset_handshake = true;
- return false;
- }
+ if (!trim($this->submit_host) || !$this->submit_port) {
+ $this->reset_handshake = true;
+ return false;
+ }
$as_socket = fsockopen($this->submit_host, intval($this->submit_port), $errno, $errstr, 2);
if(!$as_socket) {
$this->error_msg = $errstr;
- $this->reset_handshake = true;
+ $this->reset_handshake = true;
return false;
}
@@ -212,7 +212,7 @@ class scrobbler {
fwrite($as_socket, "Content-length: ".strlen($query_str)."\r\n\r\n");
fwrite($as_socket, $query_str."\r\n\r\n");
-
+
$buffer = '';
while(!feof($as_socket)) {
$buffer .= fread($as_socket, 8192);
@@ -222,34 +222,34 @@ class scrobbler {
$split_response = preg_split("/\r\n\r\n/", $buffer);
if(!isset($split_response[1])) {
$this->error_msg = 'Did not receive a valid response';
- $this->reset_handshake = true;
+ $this->reset_handshake = true;
return false;
}
$response = explode("\n", $split_response[1]);
if(!isset($response[0])) {
$this->error_msg = 'Unknown error submitting tracks'.
"\nDebug output:\n".$buffer;
- $this->reset_handshake = true;
+ $this->reset_handshake = true;
return false;
}
if(substr($response[0], 0, 6) == 'FAILED') {
$this->error_msg = $response[0];
- $this->reset_handshake = true;
+ $this->reset_handshake = true;
return false;
}
if(substr($response[0], 0, 7) == 'BADAUTH') {
$this->error_msg = 'Invalid username/password (' . $response[0] . ')';
return false;
}
- if (substr($response[0],0,10) == 'BADSESSION') {
- $this->error_msg = 'Invalid Session passed (' . trim($response[0]) . ')';
- $this->reset_handshake = true;
- return false;
- }
+ if (substr($response[0],0,10) == 'BADSESSION') {
+ $this->error_msg = 'Invalid Session passed (' . trim($response[0]) . ')';
+ $this->reset_handshake = true;
+ return false;
+ }
if(substr($response[0], 0, 2) != 'OK') {
$this->error_msg = 'Response Not ok, unknown error'.
"\nDebug output:\n".$buffer;
- $this->reset_handshake = true;
+ $this->reset_handshake = true;
return false;
}
diff --git a/lib/class/shoutbox.class.php b/lib/class/shoutbox.class.php
index 2de151d4..6c1bf145 100644
--- a/lib/class/shoutbox.class.php
+++ b/lib/class/shoutbox.class.php
@@ -22,19 +22,19 @@
class shoutBox {
- public $id;
+ public $id;
/**
* Constructor
* This pulls the shoutbox information from the database and returns
* a constructed object, uses user_shout table
*/
- public function __construct($shout_id) {
+ public function __construct($shout_id) {
// Load the data from the database
$this->_get_info($shout_id);
- return true;
+ return true;
} // Constructor
@@ -42,48 +42,48 @@ class shoutBox {
* _get_info
* does the db call, reads from the user_shout table
*/
- private function _get_info($shout_id) {
+ private function _get_info($shout_id) {
- $sticky_id = Dba::escape($shout_id);
+ $sticky_id = Dba::escape($shout_id);
- $sql = "SELECT * FROM `user_shout` WHERE `id`='$shout_id'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `user_shout` WHERE `id`='$shout_id'";
+ $db_results = Dba::read($sql);
- $data = Dba::fetch_assoc($db_results);
+ $data = Dba::fetch_assoc($db_results);
- foreach ($data as $key=>$value) {
- $this->$key = $value;
- }
+ foreach ($data as $key=>$value) {
+ $this->$key = $value;
+ }
- return true;
+ return true;
} // _get_info
/**
- * get_top
+ * get_top
* This returns the top user_shouts, shoutbox objects are always shown regardless and count against the total
* number of objects shown
*/
- public static function get_top($limit) {
+ public static function get_top($limit) {
- $shouts = self::get_sticky();
+ $shouts = self::get_sticky();
// If we've already got too many stop here
- if (count($shouts) > $limit) {
- $shouts = array_slice($shouts,0,$limit);
- return $shouts;
- }
+ if (count($shouts) > $limit) {
+ $shouts = array_slice($shouts,0,$limit);
+ return $shouts;
+ }
// Only get as many as we need
- $limit = intval($limit) - count($shouts);
- $sql = "SELECT * FROM `user_shout` WHERE `sticky`='0' ORDER BY `date` DESC LIMIT $limit";
- $db_results = Dba::read($sql);
+ $limit = intval($limit) - count($shouts);
+ $sql = "SELECT * FROM `user_shout` WHERE `sticky`='0' ORDER BY `date` DESC LIMIT $limit";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $shouts[] = $row['id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $shouts[] = $row['id'];
+ }
- return $shouts;
+ return $shouts;
} // get_top
@@ -91,18 +91,18 @@ class shoutBox {
* get_sticky
* This returns all current sticky shoutbox items
*/
- public static function get_sticky() {
+ public static function get_sticky() {
- $sql = "SELECT * FROM `user_shout` WHERE `sticky`='1' ORDER BY `date` DESC";
+ $sql = "SELECT * FROM `user_shout` WHERE `sticky`='1' ORDER BY `date` DESC";
$db_results = Dba::read($sql);
- $results = array();
+ $results = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
- return $results;
+ return $results;
} // get_sticky
@@ -110,67 +110,67 @@ class shoutBox {
* get_object
* This takes a type and an ID and returns a created object
*/
- public static function get_object($type,$object_id) {
+ public static function get_object($type,$object_id) {
- $allowed_objects = array('song','genre','album','artist','radio');
+ $allowed_objects = array('song','genre','album','artist','radio');
- if (!in_array($type,$allowed_objects)) {
- return false;
- }
+ if (!in_array($type,$allowed_objects)) {
+ return false;
+ }
- $object = new $type($object_id);
+ $object = new $type($object_id);
- return $object;
+ return $object;
} // get_object
/**
* get_image
- * This returns an image tag if the type of object we're currently rolling with
+ * This returns an image tag if the type of object we're currently rolling with
* has an image assoicated with it
*/
- public function get_image() {
+ public function get_image() {
- switch ($this->object_type) {
- case 'album':
- $image_string = "<img class=\"shoutboximage\" height=\"75\" width=\"75\" src=\"" . Config::get('web_path') . "/image.php?id=" . $this->object_id . "&amp;thumb=1\" />";
- break;
- case 'artist':
+ switch ($this->object_type) {
+ case 'album':
+ $image_string = "<img class=\"shoutboximage\" height=\"75\" width=\"75\" src=\"" . Config::get('web_path') . "/image.php?id=" . $this->object_id . "&amp;thumb=1\" />";
+ break;
+ case 'artist':
break;
- case 'song':
- $song = new Song($this->object_id);
- $image_string = "<img class=\"shoutboximage\" height=\"75\" width=\"75\" src=\"" . Config::get('web_path') . "/image.php?id=" . $song->album . "&amp;thumb=1\" />";
+ case 'song':
+ $song = new Song($this->object_id);
+ $image_string = "<img class=\"shoutboximage\" height=\"75\" width=\"75\" src=\"" . Config::get('web_path') . "/image.php?id=" . $song->album . "&amp;thumb=1\" />";
break;
- default:
+ default:
// Rien a faire
- break;
+ break;
} // end switch
- return $image_string;
+ return $image_string;
} // get_image
/**
* create
- * This takes a key'd array of data as input and inserts a new shoutbox entry, it returns the auto_inc id
+ * This takes a key'd array of data as input and inserts a new shoutbox entry, it returns the auto_inc id
*/
- public static function create($data) {
+ public static function create($data) {
- $user = Dba::escape($GLOBALS['user']->id);
- $text = Dba::escape(strip_tags($data['comment']));
- $date = time();
- $sticky = make_bool($data['sticky']);
- $object_id = Dba::escape($data['object_id']);
- $object_type = Dba::escape($data['object_type']);
+ $user = Dba::escape($GLOBALS['user']->id);
+ $text = Dba::escape(strip_tags($data['comment']));
+ $date = time();
+ $sticky = make_bool($data['sticky']);
+ $object_id = Dba::escape($data['object_id']);
+ $object_type = Dba::escape($data['object_type']);
- $sql = "INSERT INTO `user_shout` (`user`,`date`,`text`,`sticky`,`object_id`,`object_type`) " .
- "VALUES ('$user','$date','$text','$sticky','$object_id','$object_type')";
- $db_results = Dba::write($sql);
+ $sql = "INSERT INTO `user_shout` (`user`,`date`,`text`,`sticky`,`object_id`,`object_type`) " .
+ "VALUES ('$user','$date','$text','$sticky','$object_id','$object_type')";
+ $db_results = Dba::write($sql);
- $insert_id = Dba::insert_id();
+ $insert_id = Dba::insert_id();
- return $insert_id;
+ return $insert_id;
} // create
@@ -178,16 +178,16 @@ class shoutBox {
* update
* This takes a key'd array of data as input and updates a shoutbox entry
*/
- public static function update($data) {
+ public static function update($data) {
- $id = Dba::escape($data['shout_id']);
- $text = Dba::escape(strip_tags($data['comment']));
- $sticky = make_bool($data['sticky']);
+ $id = Dba::escape($data['shout_id']);
+ $text = Dba::escape(strip_tags($data['comment']));
+ $sticky = make_bool($data['sticky']);
$sql = "UPDATE `user_shout` SET `text`='$text', `sticky`='$sticky' WHERE `id`='$id'";
- $db_results = Dba::write($sql);
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // create
@@ -195,12 +195,12 @@ class shoutBox {
* format
* this function takes the object and reformats some values
*/
-
+
public function format() {
$this->sticky = ($this->sticky == "0") ? 'No' : 'Yes';
$this->date = date("m\/d\/Y - H:i", $this->date);
return true;
-
+
} //format
/**
@@ -211,10 +211,10 @@ class shoutBox {
public function delete($shout_id) {
// Delete the shoutbox post
- $shout_id = Dba::escape($shout_id);
+ $shout_id = Dba::escape($shout_id);
$sql = "DELETE FROM `user_shout` WHERE `id`='$shout_id'";
$db_results = Dba::write($sql);
-
+
} // delete
} // shoutBox class
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index df37d9f7..f376c1dc 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -55,7 +55,7 @@ class Song extends database_object implements media {
*/
public function __construct($id='') {
- if (!$id) { return false; }
+ if (!$id) { return false; }
/* Assign id for use in get_info() */
$this->id = intval($id);
@@ -63,14 +63,14 @@ class Song extends database_object implements media {
/* Get the information from the db */
if ($info = $this->_get_info()) {
- foreach ($info as $key=>$value) {
- $this->$key = $value;
- }
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
// Format the Type of the song
$this->format_type();
}
- return true;
+ return true;
} // constructor
@@ -85,59 +85,59 @@ class Song extends database_object implements media {
if (!is_array($song_ids) OR !count($song_ids)) { return false; }
$idlist = '(' . implode(',', $song_ids) . ')';
-
+
// Song data cache
$sql = "SELECT song.id,file,catalog,album,year,artist,".
"title,bitrate,rate,mode,size,time,track,played,song.enabled,update_time,tag_map.tag_id,".
"mbid,".
"addition_time FROM `song` " .
- "LEFT JOIN `tag_map` ON `tag_map`.`object_id`=`song`.`id` AND `tag_map`.`object_type`='song' " .
+ "LEFT JOIN `tag_map` ON `tag_map`.`object_id`=`song`.`id` AND `tag_map`.`object_type`='song' " .
"WHERE `song`.`id` IN $idlist";
$db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('song',$row['id'],$row);
- $artists[$row['artist']] = $row['artist'];
- $albums[$row['album']] = $row['album'];
- if ($row['tag_id']) {
- $tags[$row['tag_id']] = $row['tag_id'];
- }
+ parent::add_to_cache('song',$row['id'],$row);
+ $artists[$row['artist']] = $row['artist'];
+ $albums[$row['album']] = $row['album'];
+ if ($row['tag_id']) {
+ $tags[$row['tag_id']] = $row['tag_id'];
+ }
}
Artist::build_cache($artists);
- Album::build_cache($albums);
- Tag::build_cache($tags);
- Tag::build_map_cache('song',$song_ids);
+ Album::build_cache($albums);
+ Tag::build_cache($tags);
+ Tag::build_map_cache('song',$song_ids);
// If we're rating this then cache them as well
- if (Config::get('ratings')) {
- Rating::build_cache('song',$song_ids);
- }
+ if (Config::get('ratings')) {
+ Rating::build_cache('song',$song_ids);
+ }
// Build a cache for the song's extended table
- $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('song_data',$row['song_id'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('song_data',$row['song_id'],$row);
+ }
return true;
-
+
} // build_cache
/**
* _get_info
- * get's the vars for $this out of the database
+ * get's the vars for $this out of the database
* Taken from the object
*/
private function _get_info() {
-
- $id = intval($this->id);
- if (parent::is_cached('song',$id)) {
- return parent::get_from_cache('song',$id);
- }
+ $id = intval($this->id);
+
+ if (parent::is_cached('song',$id)) {
+ return parent::get_from_cache('song',$id);
+ }
/* Grab the basic information from the catalog and return it */
$sql = "SELECT song.id,file,catalog,album,year,artist,".
@@ -148,7 +148,7 @@ class Song extends database_object implements media {
$results = Dba::fetch_assoc($db_results);
- parent::add_to_cache('song',$id,$results);
+ parent::add_to_cache('song',$id,$results);
return $results;
@@ -159,22 +159,22 @@ class Song extends database_object implements media {
* This function gathers information from the song_ext_info table and adds it to the
* current object
*/
- public function _get_ext_info() {
+ public function _get_ext_info() {
- $id = intval($this->id);
+ $id = intval($this->id);
- if (parent::is_cached('song_data',$id)) {
+ if (parent::is_cached('song_data',$id)) {
return parent::get_from_cache('song_data',$id);
- }
+ }
$sql = "SELECT * FROM song_data WHERE `song_id`='$id'";
- $db_results = Dba::read($sql);
+ $db_results = Dba::read($sql);
- $results = Dba::fetch_assoc($db_results);
+ $results = Dba::fetch_assoc($db_results);
- parent::add_to_cache('song_data',$id,$results);
+ parent::add_to_cache('song_data',$id,$results);
- return $results;
+ return $results;
} // _get_ext_info
@@ -182,13 +182,13 @@ class Song extends database_object implements media {
* fill_ext_info
* This calls the _get_ext_info and then sets the correct vars
*/
- public function fill_ext_info() {
+ public function fill_ext_info() {
- $info = $this->_get_ext_info();
+ $info = $this->_get_ext_info();
- foreach ($info as $key=>$value) {
- if ($key != 'song_id') {
- $this->$key = $value;
+ foreach ($info as $key=>$value) {
+ if ($key != 'song_id') {
+ $this->$key = $value;
}
} // end foreach
@@ -196,22 +196,22 @@ class Song extends database_object implements media {
/**
* format_type
- * gets the type of song we are trying to
- * play, used to set mime headers and to trick
+ * gets the type of song we are trying to
+ * play, used to set mime headers and to trick
* players into playing them correctly
*/
- public function format_type($override='') {
+ public function format_type($override='') {
// If we pass an override for downsampling or whatever then use it
- if (!empty($override)) {
- $this->type = $override;
+ if (!empty($override)) {
+ $this->type = $override;
}
else {
- $data = pathinfo($this->file);
- $this->type = strtolower($data['extension']);
- }
-
- switch ($this->type) {
+ $data = pathinfo($this->file);
+ $this->type = strtolower($data['extension']);
+ }
+
+ switch ($this->type) {
case 'spx':
case 'ogg':
$this->mime = "application/ogg";
@@ -247,19 +247,19 @@ class Song extends database_object implements media {
break;
}
- return true;
+ return true;
} // format_type
-
+
/**
* get_album_name
- * gets the name of $this->album, allows passing of id
+ * gets the name of $this->album, allows passing of id
*/
public function get_album_name($album_id=0) {
- if (!$album_id) { $album_id = $this->album; }
+ if (!$album_id) { $album_id = $this->album; }
$album = new Album($album_id);
if ($album->prefix)
- return $album->prefix . " " . $album->name;
+ return $album->prefix . " " . $album->name;
else
return $album->name;
} // get_album_name
@@ -270,10 +270,10 @@ class Song extends database_object implements media {
*/
public function get_artist_name($artist_id=0) {
- if (!$artist_id) { $artist_id = $this->artist; }
+ if (!$artist_id) { $artist_id = $this->artist; }
$artist = new Artist($artist_id);
if ($artist->prefix)
- return $artist->prefix . " " . $artist->name;
+ return $artist->prefix . " " . $artist->name;
else
return $artist->name;
@@ -284,12 +284,12 @@ class Song extends database_object implements media {
* This just returns true or false depending on if this song is flagged for something
* We don't care what so we limit the SELECT to 1
*/
- public function has_flag() {
+ public function has_flag() {
$sql = "SELECT `id` FROM `flagged` WHERE `object_type`='song' AND `object_id`='$this->id' LIMIT 1";
$db_results = Dba::read($sql);
- if (Dba::fetch_assoc($db_results)) {
+ if (Dba::fetch_assoc($db_results)) {
return true;
}
@@ -302,9 +302,9 @@ class Song extends database_object implements media {
* this checks to see if the current object has been played
* if not then it sets it to played
*/
- public function set_played() {
+ public function set_played() {
- if ($this->played) {
+ if ($this->played) {
return true;
}
@@ -314,12 +314,12 @@ class Song extends database_object implements media {
return true;
} // set_played
-
+
/**
* compare_song_information
* this compares the new ID3 tags of a file against
* the ones in the database to see if they have changed
- * it returns false if nothing has changes, or the true
+ * it returns false if nothing has changes, or the true
* if they have. Static because it doesn't need this
*/
public static function compare_song_information($song,$new_song) {
@@ -327,81 +327,81 @@ class Song extends database_object implements media {
// Remove some stuff we don't care about
unset($song->catalog,$song->played,$song->enabled,$song->addition_time,$song->update_time,$song->type);
- $string_array = array('title','comment','lyrics');
- $skip_array = array('id','tag_id','mime','mb_artistid','mbid');
+ $string_array = array('title','comment','lyrics');
+ $skip_array = array('id','tag_id','mime','mb_artistid','mbid');
// Pull out all the currently set vars
- $fields = get_object_vars($song);
+ $fields = get_object_vars($song);
// Foreach them
- foreach ($fields as $key=>$value) {
- if (in_array($key,$skip_array)) { continue; }
+ foreach ($fields as $key=>$value) {
+ if (in_array($key,$skip_array)) { continue; }
// If it's a stringie thing
- if (in_array($key,$string_array)) {
- if (trim(stripslashes($song->$key)) != trim(stripslashes($new_song->$key))) {
- $array['change'] = true;
+ if (in_array($key,$string_array)) {
+ if (trim(stripslashes($song->$key)) != trim(stripslashes($new_song->$key))) {
+ $array['change'] = true;
$array['element'][$key] = 'OLD: ' . $song->$key . ' --> ' . $new_song->$key;
}
} // in array of stringies
- else {
- if ($song->$key != $new_song->$key) {
- $array['change'] = true;
+ else {
+ if ($song->$key != $new_song->$key) {
+ $array['change'] = true;
$array['element'][$key] = 'OLD:' . $song->$key . ' --> ' . $new_song->$key;
- }
+ }
} // end else
} // end foreach
- if ($array['change']) {
- debug_event('song-diff',print_r($array['element'],1),'5','ampache-catalog');
- }
+ if ($array['change']) {
+ debug_event('song-diff',print_r($array['element'],1),'5','ampache-catalog');
+ }
return $array;
} // compare_song_information
-
+
/**
* update
* This takes a key'd array of data does any cleaning it needs to
- * do and then calls the helper functions as needed. This will also
+ * do and then calls the helper functions as needed. This will also
* cause the song to be flagged
*/
- public function update($data) {
+ public function update($data) {
- foreach ($data as $key=>$value) {
- switch ($key) {
+ foreach ($data as $key=>$value) {
+ switch ($key) {
case 'artist':
// Don't do anything if we've negative one'd this baby
- if ($value == '-1') {
- $value = Catalog::check_artist($data['artist_name'], $data['mb_artistid']);
- }
+ if ($value == '-1') {
+ $value = Catalog::check_artist($data['artist_name'], $data['mb_artistid']);
+ }
case 'album':
- if ($value == '-1') {
- $value = Catalog::check_album($data['album_name'], $data['year'], $data['disk'], $data['mb_albumid']);
- }
- case 'title':
+ if ($value == '-1') {
+ $value = Catalog::check_album($data['album_name'], $data['year'], $data['disk'], $data['mb_albumid']);
+ }
+ case 'title':
case 'track':
// Check to see if it needs to be updated
- if ($value != $this->$key) {
- $function = 'update_' . $key;
- self::$function($value,$this->id);
- $this->$key = $value;
- $updated = 1;
- }
+ if ($value != $this->$key) {
+ $function = 'update_' . $key;
+ self::$function($value,$this->id);
+ $this->$key = $value;
+ $updated = 1;
+ }
break;
- default:
+ default:
// Rien a faire
break;
} // end whitelist
} // end foreach
// If a field was changed then we need to flag this mofo
- if ($updated) {
- Flag::add($this->id,'song','retag','Interface Update');
- }
+ if ($updated) {
+ Flag::add($this->id,'song','retag','Interface Update');
+ }
- return true;
+ return true;
} // update
@@ -414,36 +414,36 @@ class Song extends database_object implements media {
*/
public static function update_song($song_id, $new_song) {
- $title = Dba::escape($new_song->title);
- $bitrate = Dba::escape($new_song->bitrate);
- $rate = Dba::escape($new_song->rate);
- $mode = Dba::escape($new_song->mode);
- $size = Dba::escape($new_song->size);
- $time = Dba::escape($new_song->time);
- $track = Dba::escape($new_song->track);
+ $title = Dba::escape($new_song->title);
+ $bitrate = Dba::escape($new_song->bitrate);
+ $rate = Dba::escape($new_song->rate);
+ $mode = Dba::escape($new_song->mode);
+ $size = Dba::escape($new_song->size);
+ $time = Dba::escape($new_song->time);
+ $track = Dba::escape($new_song->track);
$mbid = Dba::escape($new_song->mbid);
- $artist = Dba::escape($new_song->artist);
- $album = Dba::escape($new_song->album);
- $year = Dba::escape($new_song->year);
- $song_id = Dba::escape($song_id);
- $update_time = time();
-
-
- $sql = "UPDATE `song` SET `album`='$album', `year`='$year', `artist`='$artist', " .
- "`title`='$title', `bitrate`='$bitrate', `rate`='$rate', `mode`='$mode', " .
- "`size`='$size', `time`='$time', `track`='$track', " .
+ $artist = Dba::escape($new_song->artist);
+ $album = Dba::escape($new_song->album);
+ $year = Dba::escape($new_song->year);
+ $song_id = Dba::escape($song_id);
+ $update_time = time();
+
+
+ $sql = "UPDATE `song` SET `album`='$album', `year`='$year', `artist`='$artist', " .
+ "`title`='$title', `bitrate`='$bitrate', `rate`='$rate', `mode`='$mode', " .
+ "`size`='$size', `time`='$time', `track`='$track', " .
"`mbid`='$mbid', " .
- "`update_time`='$update_time' WHERE `id`='$song_id'";
- $db_results = Dba::write($sql);
-
-
- $comment = Dba::escape($new_song->comment);
- $language = Dba::escape($new_song->language);
- $lyrics = Dba::escape($new_song->lyrics);
-
- $sql = "UPDATE `song_data` SET `lyrics`='$lyrics', `language`='$language', `comment`='$comment' " .
- "WHERE `song_id`='$song_id'";
- $db_results = Dba::write($sql);
+ "`update_time`='$update_time' WHERE `id`='$song_id'";
+ $db_results = Dba::write($sql);
+
+
+ $comment = Dba::escape($new_song->comment);
+ $language = Dba::escape($new_song->language);
+ $lyrics = Dba::escape($new_song->lyrics);
+
+ $sql = "UPDATE `song_data` SET `lyrics`='$lyrics', `language`='$language', `comment`='$comment' " .
+ "WHERE `song_id`='$song_id'";
+ $db_results = Dba::write($sql);
} // update_song
@@ -452,18 +452,18 @@ class Song extends database_object implements media {
* update the year tag
*/
public static function update_year($new_year,$song_id) {
-
- self::_update_item('year',$new_year,$song_id,'50');
-
+
+ self::_update_item('year',$new_year,$song_id,'50');
+
} // update_year
/**
* update_language
* This updates the language tag of the song
*/
- public static function update_language($new_lang,$song_id) {
+ public static function update_language($new_lang,$song_id) {
- self::_update_ext_item('language',$new_lang,$song_id,'50');
+ self::_update_ext_item('language',$new_lang,$song_id,'50');
} // update_language
@@ -471,19 +471,19 @@ class Song extends database_object implements media {
* update_comment
* updates the comment field
*/
- public static function update_comment($new_comment,$song_id) {
-
+ public static function update_comment($new_comment,$song_id) {
+
self::_update_ext_item('comment',$new_comment,$song_id,'50');
-
+
} // update_comment
/**
* update_lyrics
* updates the lyrics field
*/
- public static function update_lyrics($new_lyrics,$song_id) {
-
- self::_update_ext_item('lyrics',$new_lyrics,$song_id,'50');
+ public static function update_lyrics($new_lyrics,$song_id) {
+
+ self::_update_ext_item('lyrics',$new_lyrics,$song_id,'50');
} // update_lyrics
@@ -492,9 +492,9 @@ class Song extends database_object implements media {
* updates the title field
*/
public static function update_title($new_title,$song_id) {
-
+
self::_update_item('title',$new_title,$song_id,'50');
-
+
} // update_title
/**
@@ -502,7 +502,7 @@ class Song extends database_object implements media {
* updates the bitrate field
*/
public static function update_bitrate($new_bitrate,$song_id) {
-
+
self::_update_item('bitrate',$new_bitrate,$song_id,'50');
} // update_bitrate
@@ -512,7 +512,7 @@ class Song extends database_object implements media {
* updates the rate field
*/
public static function update_rate($new_rate,$song_id) {
-
+
self::_update_item('rate',$new_rate,$song_id,'50');
} // update_rate
@@ -531,8 +531,8 @@ class Song extends database_object implements media {
* update_size
* updates the size field
*/
- public static function update_size($new_size,$song_id) {
-
+ public static function update_size($new_size,$song_id) {
+
self::_update_item('size',$new_size,$song_id,'50');
} // update_size
@@ -541,8 +541,8 @@ class Song extends database_object implements media {
* update_time
* updates the time field
*/
- public static function update_time($new_time,$song_id) {
-
+ public static function update_time($new_time,$song_id) {
+
self::_update_item('time',$new_time,$song_id,'50');
} // update_time
@@ -551,7 +551,7 @@ class Song extends database_object implements media {
* update_track
* this updates the track field
*/
- public static function update_track($new_track,$song_id) {
+ public static function update_track($new_track,$song_id) {
self::_update_item('track',$new_track,$song_id,'50');
@@ -577,7 +577,7 @@ class Song extends database_object implements media {
* update_album
* updates the album field
*/
- public static function update_album($new_album,$song_id) {
+ public static function update_album($new_album,$song_id) {
self::_update_item('album',$new_album,$song_id,'50');
@@ -599,7 +599,7 @@ class Song extends database_object implements media {
* update_played
* sets the played flag
*/
- public static function update_played($new_played,$song_id) {
+ public static function update_played($new_played,$song_id) {
self::_update_item('played',$new_played,$song_id,'25');
@@ -610,14 +610,14 @@ class Song extends database_object implements media {
* sets the enabled flag
*/
public static function update_enabled($new_enabled,$song_id) {
-
+
self::_update_item('enabled',$new_enabled,$song_id,'75');
} // update_enabled
/**
* _update_item
- * This is a private function that should only be called from within the song class.
+ * This is a private function that should only be called from within the song class.
* It takes a field, value song id and level. first and foremost it checks the level
* against $GLOBALS['user'] to make sure they are allowed to update this record
* it then updates it and sets $this->{$field} to the new value
@@ -628,7 +628,7 @@ class Song extends database_object implements media {
if (!Access::check('interface',$level)) { return false; }
/* Can't update to blank */
- if (!strlen(trim($value)) && $field != 'comment') { return false; }
+ if (!strlen(trim($value)) && $field != 'comment') { return false; }
$value = Dba::escape($value);
@@ -644,17 +644,17 @@ class Song extends database_object implements media {
* This updates a song record that is housed in the song_ext_info table
* These are items that aren't used normally, and often large/informational only
*/
- private static function _update_ext_item($field,$value,$song_id,$level) {
+ private static function _update_ext_item($field,$value,$song_id,$level) {
/* Check them rights boy! */
- if (!Access::check('interface',$level)) { return false; }
-
- $value = Dba::escape($value);
+ if (!Access::check('interface',$level)) { return false; }
+
+ $value = Dba::escape($value);
$sql = "UPDATE `song_data` SET `$field`='$value' WHERE `song_id`='$song_id'";
- $db_results = Dba::write($sql);
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // _update_ext_item
@@ -664,9 +664,9 @@ class Song extends database_object implements media {
* and does a ton of formating on it creating f_??? variables on the current
* object
*/
- public function format() {
+ public function format() {
- $this->fill_ext_info();
+ $this->fill_ext_info();
// Format the filename
preg_match("/^.*\/(.*?)$/",$this->file, $short);
@@ -683,11 +683,11 @@ class Song extends database_object implements media {
// Format the title
$this->f_title = truncate_with_ellipsis($this->title,Config::get('ellipse_threshold_title'));
- // Create Links for the different objects
+ // Create Links for the different objects
$this->link = Config::get('web_path') . "/song.php?action=show_song&song_id=" . $this->id;
$this->f_link = "<a href=\"" . scrub_out($this->link) . "\" title=\"" . scrub_out($this->title) . "\"> " . scrub_out($this->f_title) . "</a>";
$this->f_album_link = "<a href=\"" . Config::get('web_path') . "/albums.php?action=show&amp;album=" . $this->album . "\" title=\"" . scrub_out($this->f_album_full) . "\"> " . scrub_out($this->f_album) . "</a>";
- $this->f_artist_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&amp;artist=" . $this->artist . "\" title=\"" . scrub_out($this->f_artist_full) . "\"> " . scrub_out($this->f_artist) . "</a>";
+ $this->f_artist_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&amp;artist=" . $this->artist . "\" title=\"" . scrub_out($this->f_artist_full) . "\"> " . scrub_out($this->f_artist) . "</a>";
// Format the Bitrate
$this->f_bitrate = intval($this->bitrate/1000) . "-" . strtoupper($this->mode);
@@ -698,13 +698,13 @@ class Song extends database_object implements media {
$this->f_time = $min . ":" . $sec;
// Format the track (there isn't really anything to do here)
- $this->f_track = $this->track;
+ $this->f_track = $this->track;
// Get the top tags
- $tags = Tag::get_top_tags('song',$this->id);
- $this->tags = $tags;
-
- $this->f_tags = Tag::get_display($tags,$this->id,'song');
+ $tags = Tag::get_top_tags('song',$this->id);
+ $this->tags = $tags;
+
+ $this->f_tags = Tag::get_display($tags,$this->id,'song');
// Format the size
$this->f_size = sprintf("%.2f",($this->size/1048576));
@@ -715,21 +715,21 @@ class Song extends database_object implements media {
/**
* format_pattern
- * This reformates the song information based on the catalog
- * rename patterns
+ * This reformates the song information based on the catalog
+ * rename patterns
*/
- public function format_pattern() {
+ public function format_pattern() {
$extension = ltrim(substr($this->file,strlen($this->file)-4,4),".");
- $catalog = new Catalog($this->catalog);
+ $catalog = new Catalog($this->catalog);
// If we don't have a rename pattern then just return it
- if (!trim($catalog->rename_pattern)) {
+ if (!trim($catalog->rename_pattern)) {
$this->f_pattern = $this->title;
$this->f_file = $this->title . '.' . $extension;
- return;
- }
+ return;
+ }
/* Create the filename that this file should have */
$album = $this->f_album_full;
@@ -743,10 +743,10 @@ class Song extends database_object implements media {
$content_array = array($artist,$album,$title,$track,$year,'-','-');
$rename_pattern = str_replace($replace_array,$content_array,$catalog->rename_pattern);
-
+
$rename_pattern = preg_replace("[\-\:\!]","_",$rename_pattern);
-
- $this->f_pattern = $rename_pattern;
+
+ $this->f_pattern = $rename_pattern;
$this->f_file = $rename_pattern . "." . $extension;
} // format_pattern
@@ -756,20 +756,20 @@ class Song extends database_object implements media {
* This returns all of the 'data' fields for this object, we need to filter out some that we don't
* want to present to a user, and add some that don't exist directly on the object but are related
*/
- public static function get_fields() {
+ public static function get_fields() {
- $fields = get_class_vars('Song');
+ $fields = get_class_vars('Song');
- unset($fields['id'],$fields['_transcoded'],$fields['_fake'],$fields['cache_hit'],$fields['mime'],$fields['type']);
+ unset($fields['id'],$fields['_transcoded'],$fields['_fake'],$fields['cache_hit'],$fields['mime'],$fields['type']);
// Some additional fields
- $fields['tag'] = true;
- $fields['catalog'] = true;
+ $fields['tag'] = true;
+ $fields['catalog'] = true;
//FIXME: These are here to keep the ideas, don't want to have to worry about them for now
-// $fields['rating'] = true;
-// $fields['recently Played'] = true;
+// $fields['rating'] = true;
+// $fields['recently Played'] = true;
- return $fields;
+ return $fields;
} // get_fields
@@ -777,35 +777,35 @@ class Song extends database_object implements media {
* get_from_path
* This returns all of the songs that exist under the specified path
*/
- public static function get_from_path($path) {
+ public static function get_from_path($path) {
- $path = Dba::escape($path);
+ $path = Dba::escape($path);
- $sql = "SELECT * FROM `song` WHERE `file` LIKE '$path%'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `song` WHERE `file` LIKE '$path%'";
+ $db_results = Dba::read($sql);
- $songs = array();
+ $songs = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- $songs[] = $row['id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $songs[] = $row['id'];
+ }
- return $songs;
+ return $songs;
} // get_from_path
/**
* @function get_rel_path
* @discussion returns the path of the song file stripped of the catalog path
- * used for mpd playback
+ * used for mpd playback
*/
public function get_rel_path($file_path=0,$catalog_id=0) {
- if (!$file_path) {
+ if (!$file_path) {
$info = $this->_get_info();
$file_path = $info->file;
}
- if (!$catalog_id) {
+ if (!$catalog_id) {
$catalog_id = $info->catalog;
}
$catalog = new Catalog( $catalog_id );
@@ -817,29 +817,29 @@ class Song extends database_object implements media {
} // get_rel_path
- /*!
+ /*!
@function fill_info
@discussion this takes the $results from getid3 and attempts to fill
as much information as possible from the file name using the
pattern set in the current catalog
*/
- function fill_info($results,$pattern,$catalog_id,$key) {
+ function fill_info($results,$pattern,$catalog_id,$key) {
$filename = $this->get_rel_path($results['file'],$catalog_id);
- if (!strlen($results[$key]['title'])) {
+ if (!strlen($results[$key]['title'])) {
$results[$key]['title'] = $this->get_info_from_filename($filename,$pattern,"%t");
}
- if (!strlen($results[$key]['track'])) {
+ if (!strlen($results[$key]['track'])) {
$results[$key]['track'] = $this->get_info_from_filename($filename,$pattern,"%T");
}
- if (!strlen($results[$key]['year'])) {
+ if (!strlen($results[$key]['year'])) {
$results[$key]['year'] = $this->get_info_from_filename($filename,$pattern,"%y");
}
- if (!strlen($results[$key]['album'])) {
+ if (!strlen($results[$key]['album'])) {
$results[$key]['album'] = $this->get_info_from_filename($filename,$pattern,"%A");
}
- if (!strlen($results[$key]['artist'])) {
+ if (!strlen($results[$key]['artist'])) {
$results[$key]['artist'] = $this->get_info_from_filename($filename,$pattern,"%a");
}
@@ -847,11 +847,11 @@ class Song extends database_object implements media {
} // fill_info
- /*!
+ /*!
@function get_info_from_filename
@discussion get information from a filename based on pattern
*/
- function get_info_from_filename($file,$pattern,$tag) {
+ function get_info_from_filename($file,$pattern,$tag) {
$preg_pattern = str_replace("$tag","(.+)",$pattern);
$preg_pattern = preg_replace("/\%\w/",".+",$preg_pattern);
@@ -869,20 +869,20 @@ class Song extends database_object implements media {
* a stream URL taking into account the downsmapling mojo and everything
* else, this is the true function
*/
- public static function play_url($oid) {
+ public static function play_url($oid) {
- $song = new Song($oid);
- $user_id = $GLOBALS['user']->id ? scrub_out($GLOBALS['user']->id) : '-1';
+ $song = new Song($oid);
+ $user_id = $GLOBALS['user']->id ? scrub_out($GLOBALS['user']->id) : '-1';
$type = $song->type;
- // Required for some versions of winamp that won't work if the stream doesn't end in
- // .ogg This will not break any properly working player, don't report this as a bug!
- if ($song->type == 'flac') { $type = 'ogg'; }
+ // Required for some versions of winamp that won't work if the stream doesn't end in
+ // .ogg This will not break any properly working player, don't report this as a bug!
+ if ($song->type == 'flac') { $type = 'ogg'; }
$song->format();
$song_name = rawurlencode($song->f_artist_full . " - " . $song->title . "." . $type);
-
+
$url = Stream::get_base_url() . "oid=$song->id&uid=$user_id$session_string$ds_string&name=/$song_name";
return $url;
@@ -895,23 +895,23 @@ class Song extends database_object implements media {
* used by the API, and used to parse out stream urls for localplay
* right now just gets song id might do more later, hence the complexity
*/
- public static function parse_song_url($url) {
+ public static function parse_song_url($url) {
// We only care about the question mark stuff
- $query = parse_url($url,PHP_URL_QUERY);
+ $query = parse_url($url,PHP_URL_QUERY);
- $elements = explode("&",$query);
+ $elements = explode("&",$query);
- foreach ($elements as $items) {
- list($key,$value) = explode("=",$items);
- if ($key == 'oid') {
- return $value;
- }
- } // end foreach
+ foreach ($elements as $items) {
+ list($key,$value) = explode("=",$items);
+ if ($key == 'oid') {
+ return $value;
+ }
+ } // end foreach
- return false;
+ return false;
- } // parse_song_url
+ } // parse_song_url
/**
* get_recently_played
@@ -919,28 +919,28 @@ class Song extends database_object implements media {
* it uses the popular threshold to figure out how many to pull
* it will only return unique object
*/
- public static function get_recently_played($user_id='') {
+ public static function get_recently_played($user_id='') {
- if ($user_id) {
- $user_limit = " AND `object_count`.`user`='" . Dba::escape($user_id) . "'";
- }
+ if ($user_id) {
+ $user_limit = " AND `object_count`.`user`='" . Dba::escape($user_id) . "'";
+ }
- $sql = "SELECT `object_count`.`object_id`,`object_count`.`user`,`object_count`.`object_type`, " .
- "`object_count`.`date` " .
- "FROM `object_count` " .
- "WHERE `object_type`='song'$user_limit " .
+ $sql = "SELECT `object_count`.`object_id`,`object_count`.`user`,`object_count`.`object_type`, " .
+ "`object_count`.`date` " .
+ "FROM `object_count` " .
+ "WHERE `object_type`='song'$user_limit " .
"ORDER BY `object_count`.`date` DESC ";
- $db_results = Dba::read($sql);
+ $db_results = Dba::read($sql);
$results = array();
-
- while ($row = Dba::fetch_assoc($db_results)) {
- if (isset($results[$row['object_id']])) { continue; }
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ if (isset($results[$row['object_id']])) { continue; }
$results[$row['object_id']] = $row;
- if (count($results) >= Config::get('popular_threshold')) { break; }
- }
+ if (count($results) >= Config::get('popular_threshold')) { break; }
+ }
- return $results;
+ return $results;
} // get_recently_played
@@ -949,25 +949,25 @@ class Song extends database_object implements media {
* This returns true/false if this can be nativly streamed
*/
public function native_stream() {
-
+
if ($this->_transcode) { return false; }
$conf_var = 'transcode_' . $this->type;
- $conf_type = 'transcode_' . $this->type . '_target';
-
- if (Config::get($conf_var)) {
- $this->_transcode = true;
- debug_event('auto_transcode','Transcoding to ' . $this->type,'5');
- return false;
- }
-
+ $conf_type = 'transcode_' . $this->type . '_target';
+
+ if (Config::get($conf_var)) {
+ $this->_transcode = true;
+ debug_event('auto_transcode','Transcoding to ' . $this->type,'5');
+ return false;
+ }
+
return true;
} // end native_stream
-
+
/**
* stream_cmd
- * test if the song type streams natively and
+ * test if the song type streams natively and
* if not returns a transcoding command from the config
* we can't use this->type because its been formated for the
* downsampling
@@ -976,18 +976,18 @@ class Song extends database_object implements media {
// Find the target for this transcode
$conf_type = 'transcode_' . $this->type . '_target';
- $stream_cmd = 'transcode_cmd_' . $this->type;
+ $stream_cmd = 'transcode_cmd_' . $this->type;
$this->format_type(Config::get($conf_type));
- if (Config::get($stream_cmd)) {
+ if (Config::get($stream_cmd)) {
return $stream_cmd;
- }
- else {
- debug_event('Downsample','Error: Transcode ' . $stream_cmd . ' for ' . $this->type . ' not found, using downsample','2');
}
-
+ else {
+ debug_event('Downsample','Error: Transcode ' . $stream_cmd . ' for ' . $this->type . ' not found, using downsample','2');
+ }
+
return false;
-
+
} // end stream_cmd
} // end of song class
diff --git a/lib/class/stats.class.php b/lib/class/stats.class.php
index 88556f7d..61b61a17 100644
--- a/lib/class/stats.class.php
+++ b/lib/class/stats.class.php
@@ -24,13 +24,13 @@
* Stats
* this class handles the object_count
* Stuff, before this was done in the user class
- * but that's not good, all done through here.
+ * but that's not good, all done through here.
*/
class Stats {
/* Base vars */
- var $id;
- var $object_type;
+ var $id;
+ var $object_type;
var $object_id;
var $date;
var $user;
@@ -40,7 +40,7 @@ class Stats {
* Constructor
* This doesn't do anything currently
*/
- public function __construct() {
+ public function __construct() {
return true;
@@ -49,25 +49,25 @@ class Stats {
/**
* insert
* This inserts a new record for the specified object
- * with the specified information, amazing!
+ * with the specified information, amazing!
*/
- public static function insert($type,$oid,$user) {
+ public static function insert($type,$oid,$user) {
$type = self::validate_type($type);
$oid = Dba::escape($oid);
- $user = Dba::escape($user);
+ $user = Dba::escape($user);
$date = time();
- $sql = "INSERT INTO `object_count` (`object_type`,`object_id`,`date`,`user`) " .
+ $sql = "INSERT INTO `object_count` (`object_type`,`object_id`,`date`,`user`) " .
" VALUES ('$type','$oid','$date','$user')";
$db_results = Dba::write($sql);
- if (!$db_results) {
+ if (!$db_results) {
debug_event('statistics','Unabled to insert statistics:' . $sql,'3');
- }
+ }
} // insert
-
+
/**
* get_last_song
* This returns the full data for the last song that was played, including when it
@@ -75,18 +75,18 @@ class Stats {
* if we should re-submit or if this is a duplicate / if it's too soon. This takes an
* optional user_id because when streaming we don't have $GLOBALS()
*/
- public static function get_last_song($user_id='') {
+ public static function get_last_song($user_id='') {
- $user_id = $user_id ? $user_id : $GLOBALS['user']->id;
+ $user_id = $user_id ? $user_id : $GLOBALS['user']->id;
$user_id = Dba::escape($user_id);
- $sql = "SELECT * FROM `object_count` WHERE `user`='$user_id' AND `object_type`='song' ORDER BY `date` DESC LIMIT 1";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `object_count` WHERE `user`='$user_id' AND `object_type`='song' ORDER BY `date` DESC LIMIT 1";
+ $db_results = Dba::read($sql);
- $results = Dba::fetch_assoc($db_results);
+ $results = Dba::fetch_assoc($db_results);
- return $results;
+ return $results;
} // get_last_song
@@ -95,25 +95,25 @@ class Stats {
* This returns the objects that have happened for $user_id sometime after $time
* used primarly by the democratic cooldown code
*/
- public static function get_object_history($user_id='',$time) {
+ public static function get_object_history($user_id='',$time) {
$user_id = $user_id ? $user_id : $GLOBALS['user']->id;
$user_id = Dba::escape($user_id);
- $time = Dba::escape($time);
+ $time = Dba::escape($time);
- $sql = "SELECT * FROM `object_count` WHERE `user`='$user_id' AND `object_type`='song' AND `date`>='$time' " .
- "ORDER BY `date` DESC";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `object_count` WHERE `user`='$user_id' AND `object_type`='song' AND `date`>='$time' " .
+ "ORDER BY `date` DESC";
+ $db_results = Dba::read($sql);
- $results = array();
+ $results = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['object_id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['object_id'];
+ }
- return $results;
+ return $results;
} // get_object_history
@@ -122,31 +122,31 @@ class Stats {
* This returns the top X for type Y from the
* last conf('stats_threshold') days
*/
- public static function get_top($type,$count='',$threshold = '') {
+ public static function get_top($type,$count='',$threshold = '') {
/* If they don't pass one, then use the preference */
- if (!$threshold) {
+ if (!$threshold) {
$threshold = Config::get('stats_threshold');
}
- if (!$count) {
- $count = Config::get('popular_threshold');
- }
+ if (!$count) {
+ $count = Config::get('popular_threshold');
+ }
$count = intval($count);
$type = self::validate_type($type);
$date = time() - (86400*$threshold);
-
+
/* Select Top objects counting by # of rows */
- $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" .
+ $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" .
" WHERE object_type='$type' AND date >= '$date'" .
" GROUP BY object_id ORDER BY `count` DESC LIMIT $count";
$db_results = Dba::read($sql);
$results = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['object_id'];
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['object_id'];
}
return $results;
@@ -156,34 +156,34 @@ class Stats {
/**
* get_user
* This gets all stats for atype based on user with thresholds and all
- * If full is passed, doesn't limit based on date
+ * If full is passed, doesn't limit based on date
*/
- public static function get_user($count,$type,$user,$full='') {
+ public static function get_user($count,$type,$user,$full='') {
$count = intval($count);
$type = self::validate_type($type);
$user = Dba::escape($user);
-
- /* If full then don't limit on date */
- if ($full) {
+
+ /* If full then don't limit on date */
+ if ($full) {
$date = '0';
}
- else {
+ else {
$date = time() - (86400*Config::get('stats_threshold'));
}
/* Select Objects based on user */
- //FIXME:: Requires table scan, look at improving
- $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" .
- " WHERE object_type='$type' AND date >= '$date' AND user = '$user'" .
+ //FIXME:: Requires table scan, look at improving
+ $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" .
+ " WHERE object_type='$type' AND date >= '$date' AND user = '$user'" .
" GROUP BY object_id ORDER BY `count` DESC LIMIT $count";
$db_results = Dba::read($sql);
-
+
$results = array();
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$results[] = $r;
- }
+ }
return $results;
@@ -194,15 +194,15 @@ class Stats {
* This function takes a type and returns only those
* which are allowed, ensures good data gets put into the db
*/
- public static function validate_type($type) {
+ public static function validate_type($type) {
- switch ($type) {
+ switch ($type) {
case 'artist':
case 'album':
case 'genre':
case 'song':
- case 'video':
- return $type;
+ case 'video':
+ return $type;
default:
return 'song';
break;
@@ -215,24 +215,24 @@ class Stats {
* This returns an array of the newest artists/albums/whatever
* in this ampache instance
*/
- public static function get_newest($type,$limit='') {
+ public static function get_newest($type,$limit='') {
if (!$limit) { $limit = Config::get('popular_threshold'); }
-
- $type = self::validate_type($type);
- $object_name = ucfirst($type);
- $sql = "SELECT DISTINCT($type) FROM `song` ORDER BY `addition_time` DESC " .
- "LIMIT $limit";
- $db_results = Dba::read($sql);
+ $type = self::validate_type($type);
+ $object_name = ucfirst($type);
+
+ $sql = "SELECT DISTINCT($type) FROM `song` ORDER BY `addition_time` DESC " .
+ "LIMIT $limit";
+ $db_results = Dba::read($sql);
- $items = array();
+ $items = array();
- while ($row = Dba::fetch_row($db_results)) {
- $items[] = $row['0'];
+ while ($row = Dba::fetch_row($db_results)) {
+ $items[] = $row['0'];
} // end while results
- return $items;
+ return $items;
} // get_newest
diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php
index 3ae532e1..1b4a7225 100644
--- a/lib/class/stream.class.php
+++ b/lib/class/stream.class.php
@@ -3,7 +3,7 @@
/*
Copyright (c) Ampache.org
- All rights reserved.
+ 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
@@ -16,7 +16,7 @@
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.
*/
@@ -33,15 +33,15 @@ class Stream {
public $type;
public $web_path;
public $media = array();
- public $urls = array();
+ public $urls = array();
public $sess;
- public $user_id;
+ public $user_id;
// Generate once an object is constructed
- public static $session;
+ public static $session;
// Let's us tell if the session has been activated
- private static $session_inserted;
+ private static $session_inserted;
/**
* Constructor for the stream class takes a type and an array
@@ -52,8 +52,8 @@ class Stream {
$this->type = $type;
$this->media = $media_ids;
$this->user_id = $GLOBALS['user']->id;
-
- if (!is_array($this->media)) { settype($this->media,'array'); }
+
+ if (!is_array($this->media)) { settype($this->media,'array'); }
} // Constructor
@@ -64,26 +64,26 @@ class Stream {
*/
public function start() {
- if (!count($this->media) AND !count($this->urls)) {
+ if (!count($this->media) AND !count($this->urls)) {
debug_event('stream','Error: No Songs Passed on ' . $this->type . ' stream','2');
- return false;
+ return false;
}
// We're starting insert the session into session_stream
- if (!self::get_session()) {
- debug_event('stream','Session Insertion failure, aborting','3');
- return false;
+ if (!self::get_session()) {
+ debug_event('stream','Session Insertion failure, aborting','3');
+ return false;
}
$methods = get_class_methods('Stream');
- $create_function = "create_" . $this->type;
+ $create_function = "create_" . $this->type;
// If in the class, call it
if (in_array($create_function,$methods)) {
$this->{$create_function}();
}
// Assume M3u incase they've pooched the type
- else {
+ else {
$this->create_m3u();
}
@@ -91,14 +91,14 @@ class Stream {
/**
* add_urls
- * Add an array of urls, it may be a single one who knows, this
+ * Add an array of urls, it may be a single one who knows, this
* is used for things that aren't coming from media objects
*/
- public function add_urls($urls=array()) {
+ public function add_urls($urls=array()) {
+
+ if (!is_array($urls)) { return false; }
- if (!is_array($urls)) { return false; }
-
- $this->urls = array_merge($urls,$this->urls);
+ $this->urls = array_merge($urls,$this->urls);
} // manual_url_add
@@ -106,13 +106,13 @@ class Stream {
* get_session
* This returns the current stream session
*/
- public static function get_session() {
+ public static function get_session() {
- if (!self::$session_inserted) {
+ if (!self::$session_inserted) {
self::insert_session(self::$session);
- }
+ }
- return self::$session;
+ return self::$session;
} // get_session
@@ -122,10 +122,10 @@ class Stream {
* an additional session into the database, should be called
* with care
*/
- public static function set_session($sid) {
+ public static function set_session($sid) {
- self::$session_inserted = true;
- self::$session=$sid;
+ self::$session_inserted = true;
+ self::$session=$sid;
} // set_session
@@ -133,42 +133,42 @@ class Stream {
* insert_session
* This inserts a row into the session_stream table
*/
- public static function insert_session($sid='',$uid='') {
+ public static function insert_session($sid='',$uid='') {
- $sid = $sid ? Dba::escape($sid) : Dba::escape(self::$session);
- $uid = $uid ? Dba::escape($uid) : Dba::escape($GLOBALS['user']->id);
+ $sid = $sid ? Dba::escape($sid) : Dba::escape(self::$session);
+ $uid = $uid ? Dba::escape($uid) : Dba::escape($GLOBALS['user']->id);
- $expire = time() + Config::get('stream_length');
+ $expire = time() + Config::get('stream_length');
- $sql = "INSERT INTO `session_stream` (`id`,`expire`,`user`) " .
- "VALUES('$sid','$expire','$uid')";
- $db_results = Dba::write($sql);
+ $sql = "INSERT INTO `session_stream` (`id`,`expire`,`user`) " .
+ "VALUES('$sid','$expire','$uid')";
+ $db_results = Dba::write($sql);
- if (!$db_results) { return false; }
+ if (!$db_results) { return false; }
- self::$session_inserted = true;
+ self::$session_inserted = true;
- return true;
+ return true;
} // insert_session
/**
* session_exists
- * This checks to see if the passed stream session exists and is valid
+ * This checks to see if the passed stream session exists and is valid
*/
- public static function session_exists($sid) {
+ public static function session_exists($sid) {
- $sid = Dba::escape($sid);
- $time = time();
+ $sid = Dba::escape($sid);
+ $time = time();
- $sql = "SELECT * FROM `session_stream` WHERE `id`='$sid' AND `expire` > '$time'";
- $db_results = Dba::write($sql);
+ $sql = "SELECT * FROM `session_stream` WHERE `id`='$sid' AND `expire` > '$time'";
+ $db_results = Dba::write($sql);
- if ($row = Dba::fetch_assoc($db_results)) {
- return true;
- }
-
- return false;
+ if ($row = Dba::fetch_assoc($db_results)) {
+ return true;
+ }
+
+ return false;
} // session_exists
@@ -177,49 +177,49 @@ class Stream {
* This function performes the garbage collection stuff, run on extend and on now playing refresh
* There is an array of agents that we will never GC because of their nature, MPD being the best example
*/
- public static function gc_session($ip='',$agent='',$uid='',$sid='') {
+ public static function gc_session($ip='',$agent='',$uid='',$sid='') {
- $append_array = array('MPD');
+ $append_array = array('MPD');
- $time = time();
- $sql = "DELETE FROM `session_stream` WHERE `expire` < '$time'";
- $db_results = Dba::write($sql);
-
- foreach ($append_array as $append_agent) {
- if (strstr(strtoupper($agent),$append_agent)) {
+ $time = time();
+ $sql = "DELETE FROM `session_stream` WHERE `expire` < '$time'";
+ $db_results = Dba::write($sql);
+
+ foreach ($append_array as $append_agent) {
+ if (strstr(strtoupper($agent),$append_agent)) {
// We're done here jump ship!
- return true;
- }
+ return true;
+ }
} // end foreach
// We need all of this to run this query
- if ($ip AND $agent AND $uid AND $sid) {
- $sql = "DELETE FROM `session_stream` WHERE `ip`='$ip' AND `agent`='$agent' AND `user`='$uid' AND `id` != '$sid'";
- $db_results = Dba::write($sql);
- }
+ if ($ip AND $agent AND $uid AND $sid) {
+ $sql = "DELETE FROM `session_stream` WHERE `ip`='$ip' AND `agent`='$agent' AND `user`='$uid' AND `id` != '$sid'";
+ $db_results = Dba::write($sql);
+ }
- } // gc_session
+ } // gc_session
/**
* extend_session
* This takes the passed sid and does a replace into also setting the user
* agent and IP also do a little GC in this function
*/
- public static function extend_session($sid,$uid) {
+ public static function extend_session($sid,$uid) {
- $expire = time() + Config::get('stream_length');
- $sid = Dba::escape($sid);
- $agent = Dba::escape($_SERVER['HTTP_USER_AGENT']);
- $ip = Dba::escape(inet_pton($_SERVER['REMOTE_ADDR']));
- $uid = Dba::escape($uid);
+ $expire = time() + Config::get('stream_length');
+ $sid = Dba::escape($sid);
+ $agent = Dba::escape($_SERVER['HTTP_USER_AGENT']);
+ $ip = Dba::escape(inet_pton($_SERVER['REMOTE_ADDR']));
+ $uid = Dba::escape($uid);
- $sql = "UPDATE `session_stream` SET `expire`='$expire', `agent`='$agent', `ip`='$ip' " .
- "WHERE `id`='$sid'";
- $db_results = Dba::write($sql);
+ $sql = "UPDATE `session_stream` SET `expire`='$expire', `agent`='$agent', `ip`='$ip' " .
+ "WHERE `id`='$sid'";
+ $db_results = Dba::write($sql);
- self::gc_session($ip,$agent,$uid,$sid);
+ self::gc_session($ip,$agent,$uid,$sid);
- return true;
+ return true;
} // extend_session
@@ -234,16 +234,16 @@ class Stream {
header("Content-Type: audio/x-mpegurl;");
// Flip for the poping!
- asort($this->urls);
+ asort($this->urls);
/* Foreach songs */
- foreach ($this->media as $element) {
+ foreach ($this->media as $element) {
$type = array_shift($element);
- echo call_user_func(array($type,'play_url'),array_shift($element)) . "\n";
+ echo call_user_func(array($type,'play_url'),array_shift($element)) . "\n";
} // end foreach
/* Foreach the additional URLs */
- foreach ($this->urls as $url) {
+ foreach ($this->urls as $url) {
echo "$url\n";
}
@@ -254,7 +254,7 @@ class Stream {
* creates an m3u file, this includes the EXTINFO and as such can be
* large with very long playlsits
*/
- public function create_m3u() {
+ public function create_m3u() {
// Send the client an m3u playlist
header("Cache-control: public");
@@ -264,31 +264,31 @@ class Stream {
// Foreach the songs in this stream object
foreach ($this->media as $element) {
- $type = array_shift($element);
- $media = new $type(array_shift($element));
- $media->format();
- switch ($type) {
- case 'song':
+ $type = array_shift($element);
+ $media = new $type(array_shift($element));
+ $media->format();
+ switch ($type) {
+ case 'song':
echo "#EXTINF:$media->time," . $media->f_artist_full . " - " . $media->title . "\n";
break;
- case 'video':
+ case 'video':
echo "#EXTINF: Video - $media->title\n";
break;
- case 'radio':
- echo "#EXTINF: Radio - $media->name [$media->frequency] ($media->site_url)\n";
- break;
- case 'random':
- echo "#EXTINF:Random URL\n";
- break;
- default:
+ case 'radio':
+ echo "#EXTINF: Radio - $media->name [$media->frequency] ($media->site_url)\n";
+ break;
+ case 'random':
+ echo "#EXTINF:Random URL\n";
+ break;
+ default:
echo "#EXTINF:URL-Add\n";
break;
- }
- echo call_user_func(array($type,'play_url'),$media->id) . "\n";
+ }
+ echo call_user_func(array($type,'play_url'),$media->id) . "\n";
} // end foreach
/* Foreach URLS */
- foreach ($this->urls as $url) {
+ foreach ($this->urls as $url) {
echo "#EXTINF: URL-Add\n";
echo $url . "\n";
}
@@ -300,10 +300,10 @@ class Stream {
* This creates a new pls file from an array of songs and
* urls, exciting I know
*/
- public function create_pls() {
+ public function create_pls() {
/* Count entries */
- $total_entries = count($this->media) + count($this->urls);
+ $total_entries = count($this->media) + count($this->urls);
// Send the client a pls playlist
header("Cache-control: public");
@@ -311,30 +311,30 @@ class Stream {
header("Content-Type: audio/x-scpls;");
echo "[Playlist]\n";
echo "NumberOfEntries=$total_entries\n";
- foreach ($this->media as $element) {
+ foreach ($this->media as $element) {
$i++;
- $type = array_shift($element);
- $media = new $type(array_shift($element));
- $media->format();
- switch ($type) {
- case 'song':
+ $type = array_shift($element);
+ $media = new $type(array_shift($element));
+ $media->format();
+ switch ($type) {
+ case 'song':
$name = $media->f_artist_full . " - " . $media->title . "." . $media->type;
- $length = $media->time;
- break;
- default:
- $name = 'URL-Add';
- $length='-1';
- break;
- }
+ $length = $media->time;
+ break;
+ default:
+ $name = 'URL-Add';
+ $length='-1';
+ break;
+ }
$url = call_user_func(array($type,'play_url'),$media->id);
echo "File" . $i . "=$url\n";
echo "Title" . $i . "=$name\n";
echo "Length" . $i . "=$length\n";
- } // end foreach songs
+ } // end foreach songs
/* Foreach Additional URLs */
- foreach ($this->urls as $url) {
+ foreach ($this->urls as $url) {
$i++;
echo "File" . $i ."=$url\n";
echo "Title". $i . "=AddedURL\n";
@@ -348,32 +348,32 @@ class Stream {
/**
* create_asx
* creates an ASX playlist (Thx Samir Kuthiala) This should really only be used
- * if all of the content is ASF files.
+ * if all of the content is ASF files.
*/
- public function create_asx() {
+ public function create_asx() {
header("Cache-control: public");
header("Content-Disposition: filename=ampache_playlist.asx");
header("Content-Type: video/x-ms-wmv;");
-
+
echo "<ASX version = \"3.0\" BANNERBAR=\"AUTO\">\n";
echo "<TITLE>Ampache ASX Playlist</TITLE>";
-
+
foreach ($this->media as $element) {
- $type = array_shift($element);
- $media = new $type(array_shift($element));
- $media->format();
- switch ($type) {
- case 'song':
+ $type = array_shift($element);
+ $media = new $type(array_shift($element));
+ $media->format();
+ switch ($type) {
+ case 'song':
$name = $media->f_album_full . " - " . $media->title . "." . $media->type;
- $author = $media->f_artist_full;
- break;
+ $author = $media->f_artist_full;
+ break;
default:
- $author = 'Ampache';
+ $author = 'Ampache';
$name = 'URL-Add';
- break;
- } // end switch
- $url = call_user_func(array($type,'play_url'),$media->id);
+ break;
+ } // end switch
+ $url = call_user_func(array($type,'play_url'),$media->id);
echo "<ENTRY>\n";
echo "<TITLE>$name</TITLE>\n";
@@ -386,17 +386,17 @@ class Stream {
echo "\t\t<PARAM NAME=\"Prebuffer\" Value=\"false\" />\n";
echo "<REF HREF = \"". $url . "\" />\n";
echo "</ENTRY>\n";
-
+
} // end foreach
/* Foreach urls */
- foreach ($this->urls as $url) {
+ foreach ($this->urls as $url) {
echo "<ENTRY>\n";
echo "<TITLE>AddURL</TITLE>\n";
echo "<AUTHOR>AddURL</AUTHOR>\n";
echo "<REF HREF=\"$url\" />\n";
echo "</ENTRY>\n";
- } // end foreach
+ } // end foreach
echo "</ASX>\n";
@@ -406,26 +406,26 @@ class Stream {
* create_xspf
* creates an XSPF playlist (Thx PB1DFT)
*/
- public function create_xspf() {
+ public function create_xspf() {
// Itterate through the songs
foreach ($this->media as $element) {
- $type = array_shift($element);
- $media = new $type(array_shift($element));
- $media->format();
+ $type = array_shift($element);
+ $media = new $type(array_shift($element));
+ $media->format();
$xml = array();
- switch ($type) {
+ switch ($type) {
default:
- case 'song':
+ case 'song':
$xml['track']['title'] = $media->title;
$xml['track']['creator'] = $media->f_artist_full;
$xml['track']['info'] = Config::get('web_path') . "/albums.php?action=show&album=" . $media->album;
$xml['track']['image'] = Config::get('web_path') . "/image.php?id=" . $media->album . "&thumb=3";
$xml['track']['album'] = $media->f_album_full;
- $length = $media->time;
- break;
+ $length = $media->time;
+ break;
} // type
$xml['track']['location'] = call_user_func(array($type,'play_url'),$media->id);
@@ -435,15 +435,15 @@ class Stream {
$result .= xmlData::keyed_array($xml,1);
} // end foreach
-
- xmlData::set_type('xspf');
+
+ xmlData::set_type('xspf');
header("Cache-control: public");
header("Content-Disposition: filename=ampache_playlist.xspf");
header("Content-Type: application/xspf+xml; charset=utf-8");
- echo xmlData::header();
+ echo xmlData::header();
echo $result;
- echo xmlData::footer();
+ echo xmlData::footer();
} // create_xspf
@@ -453,7 +453,7 @@ class Stream {
* have to do a little 'cheating' to make this work, we are going to take
* advantage of tmp_playlists to do all of this hotness
*/
- public function create_xspf_player() {
+ public function create_xspf_player() {
/* Build the extra info we need to have it pass */
$play_info = "?action=show&tmpplaylist_id=" . $GLOBALS['user']->playlist->id;
@@ -462,7 +462,7 @@ class Stream {
//FIXME: This needs to go in a template, here for now though
//FIXME: This preference doesn't even exists, we'll eventually
//FIXME: just make it the default
- if (Config::get('embed_xspf') == 1 ){
+ if (Config::get('embed_xspf') == 1 ){
header("Location: ".Config::get('web_path')."/index.php?xspf&play_info=".$GLOBALS['user']->playlist->id);
}
else {
@@ -474,13 +474,13 @@ class Stream {
// We do a little check here to see if it's a Wii!
if (false !== stristr($_SERVER['HTTP_USER_AGENT'], 'Nintendo Wii')) {
echo "window.location=URL;\n";
- }
+ }
// Else go ahead and do the normal stuff
else {
echo "window.open(URL, 'XSPF_player', 'width=400,height=170,scrollbars=0,toolbar=0,location=0,directories=0,status=0,resizable=0');\n";
echo "window.location = '" . return_referer() . "';\n";
echo "return false;\n";
- }
+ }
echo "}\n";
echo "// end -->\n";
echo "</script>\n";
@@ -491,41 +491,41 @@ class Stream {
echo "</html>\n";
}
} // create_xspf_player
-
+
/**
* create_localplay
- * This calls the Localplay API and attempts to
+ * This calls the Localplay API and attempts to
* add, and then start playback
*/
- public function create_localplay() {
+ public function create_localplay() {
// First figure out what their current one is and create the object
- $localplay = new Localplay(Config::get('localplay_controller'));
- $localplay->connect();
- foreach ($this->media as $element) {
+ $localplay = new Localplay(Config::get('localplay_controller'));
+ $localplay->connect();
+ foreach ($this->media as $element) {
$type = array_shift($element);
- switch ($type) {
- case 'video':
+ switch ($type) {
+ case 'video':
// Add check for video support
- case 'song':
- case 'radio':
- case 'random':
- $media = new $type(array_shift($element));
- break;
- default:
- $media = array_shift($element);
- break;
- } // switch on types
- $localplay->add($media);
+ case 'song':
+ case 'radio':
+ case 'random':
+ $media = new $type(array_shift($element));
+ break;
+ default:
+ $media = array_shift($element);
+ break;
+ } // switch on types
+ $localplay->add($media);
} // foreach object
/**
* Add urls after the fact
*/
- foreach ($this->urls as $url) {
- $localplay->add($url);
- }
-
+ foreach ($this->urls as $url) {
+ $localplay->add($url);
+ }
+
$localplay->play();
} // create_localplay
@@ -535,10 +535,10 @@ class Stream {
* This 'votes' on the songs it inserts them into
* a tmp_playlist with user of -1 (System)
*/
- public function create_democratic() {
+ public function create_democratic() {
$democratic = Democratic::get_current_playlist();
- $democratic->set_parent();
+ $democratic->set_parent();
$democratic->vote($this->media);
} // create_democratic
@@ -548,21 +548,21 @@ class Stream {
* This prompts for a download of the song, only a single
* element can by in song_ids
*/
- private function create_download() {
+ private function create_download() {
- // There should only be one here...
- foreach ($this->media as $element) {
+ // There should only be one here...
+ foreach ($this->media as $element) {
$type = array_shift($element);
$media = new $type(array_shift($element));
- $url = call_user_func(array($type,'play_url'),$media->id);
-
+ $url = call_user_func(array($type,'play_url'),$media->id);
+
// Append the fact we are downloading
- $url .= '&action=download';
+ $url .= '&action=download';
// Header redirect baby!
- header("Location: $url");
- exit;
- }
+ header("Location: $url");
+ exit;
+ }
} //create_download
@@ -570,26 +570,26 @@ class Stream {
* create_ram
*this functions creates a RAM file for use by Real Player
*/
- public function create_ram() {
+ public function create_ram() {
header("Cache-control: public");
header("Content-Disposition: filename=ampache_playlist.ram");
header("Content-Type: audio/x-pn-realaudio ram;");
foreach ($this->media as $element) {
$type = array_shift($element);
- echo $url = call_user_func(array($type,'play_url'),array_shift($element)) . "\n";
+ echo $url = call_user_func(array($type,'play_url'),array_shift($element)) . "\n";
} // foreach songs
} // create_ram
/**
* start_downsample
- * This is a rather complext function that starts the downsampling of a song and returns the
+ * This is a rather complext function that starts the downsampling of a song and returns the
* opened file handled a reference to the song object is passed so that the changes we make
- * in here affect the external object, References++
+ * in here affect the external object, References++
*/
public static function start_downsample(&$song,$now_playing_id=0,$song_name=0,$start=0) {
-
+
/* Check to see if bitrates are set if so let's go ahead and optomize! */
$max_bitrate = Config::get('max_bit_rate');
$min_bitrate = Config::get('min_bit_rate');
@@ -611,8 +611,8 @@ class Stream {
$results = Dba::fetch_row($db_results);
// Current number of active streams (current is already in now playing, worst case make it 1)
- $active_streams = intval($results[0]);
- if (!$active_streams) { $active_streams = '1'; }
+ $active_streams = intval($results[0]);
+ if (!$active_streams) { $active_streams = '1'; }
/* If only one user, they'll get all available. Otherwise split up equally. */
$sample_rate = floor($max_bitrate/$active_streams);
@@ -630,7 +630,7 @@ class Stream {
$sample_rate = floor($max_bitrate/$active_streams);
} // end else
- // Never go over the users sample rate
+ // Never go over the users sample rate
if ($sample_rate > $user_sample_rate) { $sample_rate = $user_sample_rate; }
debug_event('downsample',"Downsampled: $active_streams current active streams, downsampling to $sample_rate",'2');
@@ -653,7 +653,7 @@ class Stream {
/* Set the Sample Ratio */
$sample_ratio = $sample_rate/($song->bitrate/1000);
}
-
+
// Set the new size for the song
$song->size = floor($sample_ratio*$song->size);
@@ -677,9 +677,9 @@ class Stream {
$downsample_command = str_replace("%EOF%",$eof,$downsample_command,$eof_exists);
$downsample_command = str_replace("%SAMPLE%",$sample_rate,$downsample_command,$sample_exists);
- if (!$file_exists || !$offset_exists || !$eof_exists || !$sample_exists) {
- debug_event('downsample','Error: Downsample command missing a varaible values are File:' . $file_exists . ' Offset:' . $offset_exists . ' Eof:' . $eof_exists . ' Sample:' . $sample_exists,'1');
- }
+ if (!$file_exists || !$offset_exists || !$eof_exists || !$sample_exists) {
+ debug_event('downsample','Error: Downsample command missing a varaible values are File:' . $file_exists . ' Offset:' . $offset_exists . ' Eof:' . $eof_exists . ' Sample:' . $sample_exists,'1');
+ }
// If we are debugging log this event
$message = "Start Downsample: $downsample_command";
@@ -692,7 +692,7 @@ class Stream {
} // start_downsample
- /**
+ /**
* validate_bitrate
* this function takes a bitrate and returns a valid one
*/
@@ -701,17 +701,17 @@ class Stream {
/* Round to standard bitrates */
$sample_rate = 16*(floor($bitrate/16));
- return $sample_rate;
+ return $sample_rate;
} // validate_bitrate
/**
* gc_now_playing
- * This will garbage collect the now playing data,
+ * This will garbage collect the now playing data,
* this is done on every play start
*/
- public static function gc_now_playing() {
+ public static function gc_now_playing() {
// Remove any now playing entries for session_streams that have been GC'd
$sql = "DELETE FROM `now_playing` USING `now_playing` " .
@@ -731,7 +731,7 @@ class Stream {
$time = intval(time()+$length);
$session_id = Dba::escape($sid);
- $object_type = Dba::escape(strtolower($type));
+ $object_type = Dba::escape(strtolower($type));
// Do a replace into ensuring that this client always only has a single row
$sql = "REPLACE INTO `now_playing` (`id`,`object_id`,`object_type`, `user`, `expire`)" .
@@ -758,7 +758,7 @@ class Stream {
* get_now_playing
* This returns the now playing information
*/
- public static function get_now_playing($filter=NULL) {
+ public static function get_now_playing($filter=NULL) {
$sql = "SELECT `session_stream`.`agent`,`now_playing`.* " .
"FROM `now_playing` " .
@@ -766,17 +766,17 @@ class Stream {
"ORDER BY `now_playing`.`expire` DESC";
$db_results = Dba::read($sql);
- $results = array();
+ $results = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- $type = $row['object_type'];
- $media = new $type($row['object_id']);
- $media->format();
- $client = new User($row['user']);
- $results[] = array('media'=>$media,'client'=>$client,'agent'=>$row['agent'],'expire'=>$row['expire']);
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $type = $row['object_type'];
+ $media = new $type($row['object_id']);
+ $media->format();
+ $client = new User($row['user']);
+ $results[] = array('media'=>$media,'client'=>$client,'agent'=>$row['agent'],'expire'=>$row['expire']);
} // end while
- return $results;
+ return $results;
} // get_now_playing
@@ -785,20 +785,20 @@ class Stream {
* This checks to see if the media is already being played, if it is then it returns false
* else return true
*/
- public static function check_lock_media($media_id,$type) {
+ public static function check_lock_media($media_id,$type) {
- $media_id = Dba::escape($media_id);
- $type = Dba::escape($type);
+ $media_id = Dba::escape($media_id);
+ $type = Dba::escape($type);
- $sql = "SELECT `object_id` FROM `now_playing` WHERE `object_id`='$media_id' AND `object_type`='$type'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `object_id` FROM `now_playing` WHERE `object_id`='$media_id' AND `object_type`='$type'";
+ $db_results = Dba::read($sql);
- if (Dba::num_rows($db_results)) {
- debug_event('Stream','Unable to play media currently locked by another user','3');
+ if (Dba::num_rows($db_results)) {
+ debug_event('Stream','Unable to play media currently locked by another user','3');
return false;
- }
+ }
- return true;
+ return true;
} // check_lock_media
@@ -806,7 +806,7 @@ class Stream {
* auto_init
* This is called on class load it sets the session
*/
- public static function _auto_init() {
+ public static function _auto_init() {
// Generate the session ID
self::$session = md5(uniqid(rand(), true));
@@ -817,31 +817,31 @@ class Stream {
* run_playlist_method
* This takes care of the different types of 'playlist methods' the reason this is here
* is because it deals with streaming rather then playlist mojo. If something needs to happen
- * this will echo the javascript required to cause a reload of the iframe.
+ * this will echo the javascript required to cause a reload of the iframe.
*/
- public static function run_playlist_method() {
+ public static function run_playlist_method() {
- // If this wasn't ajax included run away
- if (AJAX_INCLUDE != '1') { return false; }
+ // If this wasn't ajax included run away
+ if (AJAX_INCLUDE != '1') { return false; }
// If we're doin the flash magic then run away as well
- if (Config::get('play_type') == 'xspf_player') { return false; }
+ if (Config::get('play_type') == 'xspf_player') { return false; }
- switch (Config::get('playlist_method')) {
- default:
- case 'clear':
- case 'default':
- return true;
+ switch (Config::get('playlist_method')) {
+ default:
+ case 'clear':
+ case 'default':
+ return true;
break;
- case 'send':
+ case 'send':
$_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket';
break;
- case 'send_clear':
- $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket&playlist_method=clear';
- break;
- } // end switch on method
+ case 'send_clear':
+ $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket&playlist_method=clear';
+ break;
+ } // end switch on method
- // Load our javascript
+ // Load our javascript
echo "<script type=\"text/javascript\">";
//echo "reload_util();";
echo "reload_util('".$_SESSION['iframe']['target']."');";
@@ -853,7 +853,7 @@ class Stream {
* get_base_url
* This returns the base requirements for a stream URL this does not include anything after the index.php?sid=????
*/
- public static function get_base_url() {
+ public static function get_base_url() {
if (Config::get('require_session')) {
$session_string = 'ssid=' . Stream::get_session() . '&';
@@ -864,18 +864,18 @@ class Stream {
if (Config::get('force_http_play') OR !empty(self::$force_http)) {
$web_path = str_replace("https://", "http://",$web_path);
}
- if (Config::get('http_port') != '80') {
- if (preg_match("/:(\d+)/",$web_path,$matches)) {
- $web_path = str_replace(':' . $matches['1'],':' . Config::get('http_port'),$web_path);
- }
- else {
- $web_path = str_replace($_SERVER['HTTP_HOST'],$_SERVER['HTTP_HOST'] . ':' . Config::get('http_port'),$web_path);
- }
- }
-
- $url = $web_path . "/play/index.php?$session_string";
-
- return $url;
+ if (Config::get('http_port') != '80') {
+ if (preg_match("/:(\d+)/",$web_path,$matches)) {
+ $web_path = str_replace(':' . $matches['1'],':' . Config::get('http_port'),$web_path);
+ }
+ else {
+ $web_path = str_replace($_SERVER['HTTP_HOST'],$_SERVER['HTTP_HOST'] . ':' . Config::get('http_port'),$web_path);
+ }
+ }
+
+ $url = $web_path . "/play/index.php?$session_string";
+
+ return $url;
} // get_base_url
diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php
index 1fa9b48b..5fb6cc18 100644
--- a/lib/class/tag.class.php
+++ b/lib/class/tag.class.php
@@ -16,7 +16,7 @@
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.
*/
@@ -26,26 +26,26 @@
*/
class Tag extends database_object {
- public $id;
- public $name;
+ public $id;
+ public $name;
// constructed
- public $weight=0;
- public $count=0;
- public $owner=0;
+ public $weight=0;
+ public $count=0;
+ public $owner=0;
/**
* constructor
* This takes a tag id and returns all of the relevent information
*/
- public function __construct($id) {
+ public function __construct($id) {
- if (!$id) { return false; }
+ if (!$id) { return false; }
- $info = $this->get_info($id);
+ $info = $this->get_info($id);
- foreach ($info as $key=>$value) {
- $this->$key = $value;
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
} // end foreach
} // constructor
@@ -54,14 +54,14 @@ class Tag extends database_object {
* construct_from_name
* This attempts to construct the tag from a name, rather then the ID
*/
- public static function construct_from_name($name) {
+ public static function construct_from_name($name) {
- $tag_id = self::tag_exists($name);
+ $tag_id = self::tag_exists($name);
- $tag = new Tag($tag_id);
+ $tag = new Tag($tag_id);
+
+ return $tag;
- return $tag;
-
} // construct_from_name
/**
@@ -69,31 +69,31 @@ class Tag extends database_object {
* This makes the tag presentable to the great humans that use this program, other life forms
* will just have to fend for themselves
*/
- public function format($type=0,$object_id=0) {
+ public function format($type=0,$object_id=0) {
- if ($type AND !self::validate_type($type)) { return false; }
+ if ($type AND !self::validate_type($type)) { return false; }
- if ($type) {
- $this->set_object($type,$object_id);
- }
+ if ($type) {
+ $this->set_object($type,$object_id);
+ }
- $size = 3 + ($this->weight-1) - ($this->count-1);
- if (abs($size) > 4) { $size = 4; }
- if (abs($size) < 1) { $size = 1; }
+ $size = 3 + ($this->weight-1) - ($this->count-1);
+ if (abs($size) > 4) { $size = 4; }
+ if (abs($size) < 1) { $size = 1; }
- if ($this->owner == $GLOBALS['user']->id) {
- $action = '?page=tag&action=remove_tag&type=' . scrub_out($type) . '&tag_id=' . intval($this->id) . '&object_id=' . intval($object_id);
- $class = "hover-remove ";
- }
- else {
- $action = '?page=tag&action=add_tag&type=' . scrub_out($type) . '&tag_id=' . intval($this->id) . '&object_id=' . intval($object_id);
- $class = "hover-add ";
- }
+ if ($this->owner == $GLOBALS['user']->id) {
+ $action = '?page=tag&action=remove_tag&type=' . scrub_out($type) . '&tag_id=' . intval($this->id) . '&object_id=' . intval($object_id);
+ $class = "hover-remove ";
+ }
+ else {
+ $action = '?page=tag&action=add_tag&type=' . scrub_out($type) . '&tag_id=' . intval($this->id) . '&object_id=' . intval($object_id);
+ $class = "hover-add ";
+ }
- $class .= 'tag_size' . $size;
- $this->f_class = $class;
+ $class .= 'tag_size' . $size;
+ $this->f_class = $class;
- $this->f_name = Ajax::text($action,$this->name,'modify_tag_' . $this->id . '_' . $object_id,'',$class);
+ $this->f_name = Ajax::text($action,$this->name,'modify_tag_' . $this->id . '_' . $object_id,'',$class);
} // format
@@ -102,26 +102,26 @@ class Tag extends database_object {
* This assoicates the tag with a specified object, we try to get the data
* from the map cache, otherwise I guess we'll just have to look it up
*/
- public function set_object($type,$object_id) {
+ public function set_object($type,$object_id) {
- if (parent::is_cached('tag_top_' . $type,$object_id)) {
- $data = parent::get_from_cache('tag_top_' . $type,$object_id);
- }
- else {
- $data = self::get_top_tags($type,$object_id);
- }
+ if (parent::is_cached('tag_top_' . $type,$object_id)) {
+ $data = parent::get_from_cache('tag_top_' . $type,$object_id);
+ }
+ else {
+ $data = self::get_top_tags($type,$object_id);
+ }
// If nothing is found, then go ahead and return false
- if (!is_array($data) OR !count($data)) { return false; }
+ if (!is_array($data) OR !count($data)) { return false; }
+
+ $this->weight = $data[$this->id]['count'];
+
+ if (in_array($GLOBALS['user']->id,$data[$this->id]['users'])) {
+ $this->owner = $GLOBALS['user']->id;
+ }
- $this->weight = $data[$this->id]['count'];
+ $this->count = count($data);
- if (in_array($GLOBALS['user']->id,$data[$this->id]['users'])) {
- $this->owner = $GLOBALS['user']->id;
- }
-
- $this->count = count($data);
-
} // set_object
/**
@@ -129,18 +129,18 @@ class Tag extends database_object {
* This takes an array of object ids and caches all of their information
* in a single query, cuts down on the connections
*/
- public static function build_cache($ids) {
-
+ public static function build_cache($ids) {
+
if (!is_array($ids) OR !count($ids)) { return false; }
- $idlist = '(' . implode(',',$ids) . ')';
-
- $sql = "SELECT * FROM `tag` WHERE `id` IN $idlist";
- $db_results = Dba::read($sql);
+ $idlist = '(' . implode(',',$ids) . ')';
+
+ $sql = "SELECT * FROM `tag` WHERE `id` IN $idlist";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('tag',$row['id'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('tag',$row['id'],$row);
+ }
return true;
} // build_cache
@@ -149,69 +149,69 @@ class Tag extends database_object {
* build_map_cache
* This builds a cache of the mappings for the specified object, no limit is given
*/
- public static function build_map_cache($type,$ids) {
+ public static function build_map_cache($type,$ids) {
if (!is_array($ids) OR !count($ids)) { return false; }
$type = self::validate_type($type);
- $idlist = '(' . implode(',',$ids) . ')';
+ $idlist = '(' . implode(',',$ids) . ')';
$sql = "SELECT `tag_map`.`id`,`tag_map`.`tag_id`,`tag_map`.`object_id`,`tag_map`.`user` FROM `tag_map` " .
"WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id` IN $idlist ";
- $db_results = Dba::read($sql);
+ $db_results = Dba::read($sql);
- $tags = array();
+ $tags = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- $tags[$row['object_id']][$row['tag_id']]['users'][] = $row['user'];
- $tags[$row['object_id']][$row['tag_id']]['count']++;
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $tags[$row['object_id']][$row['tag_id']]['users'][] = $row['user'];
+ $tags[$row['object_id']][$row['tag_id']]['count']++;
$tag_map[$row['object_id']] = array('id'=>$row['id'],'tag_id'=>$row['tag_id'],'user'=>$row['user'],'object_type'=>$type,'object_id'=>$row['object_id']);
}
// Run through our origional ids as we want to cache NULL results
- foreach ($ids as $id) {
- parent::add_to_cache('tag_top_' . $type,$id,$tags[$id]);
- parent::add_to_cache('tag_map_' . $type,$id,$tag_map[$id]);
- }
+ foreach ($ids as $id) {
+ parent::add_to_cache('tag_top_' . $type,$id,$tags[$id]);
+ parent::add_to_cache('tag_map_' . $type,$id,$tag_map[$id]);
+ }
- return true;
+ return true;
} // build_map_cache
/**
* add
* This is a wrapper function, it figures out what we need to add, be it a tag
- * and map, or just the mapping
+ * and map, or just the mapping
*/
- public static function add($type,$id,$value,$user=false) {
+ public static function add($type,$id,$value,$user=false) {
// Validate the tag type
- if (!self::validate_type($type)) { return false; }
+ if (!self::validate_type($type)) { return false; }
- if (!is_numeric($id)) { return false; }
+ if (!is_numeric($id)) { return false; }
- $cleaned_value = self::clean_tag($value);
+ $cleaned_value = self::clean_tag($value);
- if (!strlen($cleaned_value)) { return false; }
+ if (!strlen($cleaned_value)) { return false; }
$uid = ($user === false) ? intval($user) : intval($GLOBALS['user']->id);
// Check and see if the tag exists, if not create it, we need the tag id from this
- if (!$tag_id = self::tag_exists($cleaned_value)) {
- $tag_id = self::add_tag($cleaned_value);
- }
+ if (!$tag_id = self::tag_exists($cleaned_value)) {
+ $tag_id = self::add_tag($cleaned_value);
+ }
- if (!$tag_id) {
- debug_event('Error','Error unable to create tag value:' . $cleaned_value . ' unknown error','1');
- return false;
- }
+ if (!$tag_id) {
+ debug_event('Error','Error unable to create tag value:' . $cleaned_value . ' unknown error','1');
+ return false;
+ }
// We've got the tag id, let's see if it's already got a map, if not then create the map and return the value
- if (!$map_id = self::tag_map_exists($type,$id,$tag_id,$user)) {
- $map_id = self::add_tag_map($type,$id,$tag_id,$user);
+ if (!$map_id = self::tag_map_exists($type,$id,$tag_id,$user)) {
+ $map_id = self::add_tag_map($type,$id,$tag_id,$user);
}
- return $map_id;
+ return $map_id;
} // add
@@ -220,21 +220,21 @@ class Tag extends database_object {
* This function adds a new tag, for now we're going to limit the tagging a bit
*/
public static function add_tag($value) {
-
+
// Clean it up and make it tagish
- $value = self::clean_tag($value);
+ $value = self::clean_tag($value);
+
+ if (!strlen($value)) { return false; }
- if (!strlen($value)) { return false; }
-
- $value = Dba::escape($value);
+ $value = Dba::escape($value);
$sql = "REPLACE INTO `tag` SET `name`='$value'";
$db_results = Dba::write($sql);
- $insert_id = Dba::insert_id();
+ $insert_id = Dba::insert_id();
- parent::add_to_cache('tag_name',$value,$insert_id);
+ parent::add_to_cache('tag_name',$value,$insert_id);
- return $insert_id;
+ return $insert_id;
} // add_tag
@@ -242,75 +242,75 @@ class Tag extends database_object {
* add_tag_map
* This adds a specific tag to the map for specified object
*/
- public static function add_tag_map($type,$object_id,$tag_id,$user='') {
-
- $uid = ($user == '') ? intval($GLOBALS['user']->id) : intval($user);
- $tag_id = intval($tag_id);
- if (!self::validate_type($type)) { return false; }
- $id = intval($object_id);
-
- if (!$tag_id || !$id) { return false; }
-
+ public static function add_tag_map($type,$object_id,$tag_id,$user='') {
+
+ $uid = ($user == '') ? intval($GLOBALS['user']->id) : intval($user);
+ $tag_id = intval($tag_id);
+ if (!self::validate_type($type)) { return false; }
+ $id = intval($object_id);
+
+ if (!$tag_id || !$id) { return false; }
+
$sql = "INSERT INTO `tag_map` (`tag_id`,`user`,`object_type`,`object_id`) " .
"VALUES ('$tag_id','$uid','$type','$id')";
$db_results = Dba::write($sql);
- $insert_id = Dba::insert_id();
+ $insert_id = Dba::insert_id();
- parent::add_to_cache('tag_map_' . $type,$insert_id,array('tag_id'=>$tag_id,'user'=>$uid,'object_type'=>$type,'object_id'=>$id));
+ parent::add_to_cache('tag_map_' . $type,$insert_id,array('tag_id'=>$tag_id,'user'=>$uid,'object_type'=>$type,'object_id'=>$id));
- return $insert_id;
+ return $insert_id;
} // add_tag_map
/**
* tag_exists
- * This checks to see if a tag exists, this has nothing to do with objects or maps
+ * This checks to see if a tag exists, this has nothing to do with objects or maps
*/
- public static function tag_exists($value) {
+ public static function tag_exists($value) {
- if (parent::is_cached('tag_name',$value)) {
- return parent::get_from_cache('tag_name',$value);
- }
+ if (parent::is_cached('tag_name',$value)) {
+ return parent::get_from_cache('tag_name',$value);
+ }
- $value = Dba::escape($value);
- $sql = "SELECT * FROM `tag` WHERE `name`='$value'";
- $db_results = Dba::read($sql);
+ $value = Dba::escape($value);
+ $sql = "SELECT * FROM `tag` WHERE `name`='$value'";
+ $db_results = Dba::read($sql);
- $results = Dba::fetch_assoc($db_results);
+ $results = Dba::fetch_assoc($db_results);
- parent::add_to_cache('tag_name',$results['name'],$results['id']);
+ parent::add_to_cache('tag_name',$results['name'],$results['id']);
- return $results['id'];
+ return $results['id'];
} // tag_exists
/**
* tag_map_exists
* This looks to see if the current mapping of the current object of the current tag of the current
- * user exists, lots of currents... taste good in scones.
+ * user exists, lots of currents... taste good in scones.
*/
- public static function tag_map_exists($type,$object_id,$tag_id,$user) {
+ public static function tag_map_exists($type,$object_id,$tag_id,$user) {
- if (!self::validate_type($type)) { return false; }
+ if (!self::validate_type($type)) { return false; }
- if (parent::is_cached('tag_map_' . $type,$object_id)) {
+ if (parent::is_cached('tag_map_' . $type,$object_id)) {
$data = parent::get_from_cache('tag_map_' . $type,$object_id);
- return $data['id'];
- }
+ return $data['id'];
+ }
- $object_id = Dba::escape($object_id);
- $tag_id = Dba::escape($tag_id);
- $user = Dba::escape($user);
- $type = Dba::escape($type);
+ $object_id = Dba::escape($object_id);
+ $tag_id = Dba::escape($tag_id);
+ $user = Dba::escape($user);
+ $type = Dba::escape($type);
+
+ $sql = "SELECT * FROM `tag_map` WHERE `tag_id`='$tag_id' AND `user`='$user' AND `object_id`='$object_id' AND `object_type`='$type'";
+ $db_results = Dba::read($sql);
- $sql = "SELECT * FROM `tag_map` WHERE `tag_id`='$tag_id' AND `user`='$user' AND `object_id`='$object_id' AND `object_type`='$type'";
- $db_results = Dba::read($sql);
-
- $results = Dba::fetch_assoc($db_results);
+ $results = Dba::fetch_assoc($db_results);
- parent::add_to_cache('tag_map_' . $type,$results['id'],$results);
+ parent::add_to_cache('tag_map_' . $type,$results['id'],$results);
- return $results['id'];
+ return $results['id'];
} // tag_map_exists
@@ -318,32 +318,32 @@ class Tag extends database_object {
* get_top_tags
* This gets the top tags for the specified object using limit
*/
- public static function get_top_tags($type,$object_id,$limit='10') {
+ public static function get_top_tags($type,$object_id,$limit='10') {
- if (!self::validate_type($type)) { return false; }
+ if (!self::validate_type($type)) { return false; }
- if (parent::is_cached('tag_top_' . $type,$object_id)) {
- return parent::get_from_cache('tag_top_' . $type,$object_id);
- }
+ if (parent::is_cached('tag_top_' . $type,$object_id)) {
+ return parent::get_from_cache('tag_top_' . $type,$object_id);
+ }
- $object_id = intval($object_id);
- $limit = intval($limit);
+ $object_id = intval($object_id);
+ $limit = intval($limit);
- $sql = "SELECT `tag_map`.`tag_id`,`tag_map`.`user` FROM `tag_map` " .
- "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id`='$object_id' " .
- "LIMIT $limit";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `tag_map`.`tag_id`,`tag_map`.`user` FROM `tag_map` " .
+ "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id`='$object_id' " .
+ "LIMIT $limit";
+ $db_results = Dba::read($sql);
- $results = array();
+ $results = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[$row['tag_id']]['users'][] = $row['user'];
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[$row['tag_id']]['users'][] = $row['user'];
$results[$row['tag_id']]['count']++;
- }
+ }
- parent::add_to_cache('tag_top_' . $type,$object_id,$results);
+ parent::add_to_cache('tag_top_' . $type,$object_id,$results);
- return $results;
+ return $results;
} // get_top_tags
@@ -354,21 +354,21 @@ class Tag extends database_object {
*/
public static function get_object_tags($type, $id) {
- if (!self::validate_type($type)) { return array(); }
-
- $id = Dba::escape($id);
+ if (!self::validate_type($type)) { return array(); }
+
+ $id = Dba::escape($id);
+
+ $sql = "SELECT `tag_map`.`id`, `tag`.`name`, `tag_map`.`user` FROM `tag` " .
+ "LEFT JOIN `tag_map` ON `tag_map`.`tag_id`=`tag`.`id` " .
+ "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id`='$id'";
- $sql = "SELECT `tag_map`.`id`, `tag`.`name`, `tag_map`.`user` FROM `tag` " .
- "LEFT JOIN `tag_map` ON `tag_map`.`tag_id`=`tag`.`id` " .
- "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id`='$id'";
-
$results = array();
$db_results = Dba::read($sql);
-
- while ($row = Dba::fetch_assoc($db_results)) {
+
+ while ($row = Dba::fetch_assoc($db_results)) {
$results[] = $row;
}
-
+
return $results;
} // get_object_tags
@@ -377,23 +377,23 @@ class Tag extends database_object {
* get_tag_objects
* This gets the objects from a specified tag and returns an array of object ids, nothing more
*/
- public static function get_tag_objects($type,$tag_id) {
+ public static function get_tag_objects($type,$tag_id) {
- if (!self::validate_type($type)) { return array(); }
+ if (!self::validate_type($type)) { return array(); }
- $tag_id = Dba::escape($tag_id);
+ $tag_id = Dba::escape($tag_id);
- $sql = "SELECT DISTINCT `tag_map`.`object_id` FROM `tag_map` " .
- "WHERE `tag_map`.`tag_id`='$tag_id' AND `tag_map`.`object_type`='$type'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT DISTINCT `tag_map`.`object_id` FROM `tag_map` " .
+ "WHERE `tag_map`.`tag_id`='$tag_id' AND `tag_map`.`object_type`='$type'";
+ $db_results = Dba::read($sql);
- $results = array();
+ $results = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['object_id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['object_id'];
+ }
- return $results;
+ return $results;
} // get_tag_objects
@@ -403,27 +403,27 @@ class Tag extends database_object {
* This is a non-object non type depedent function that just returns tags
* we've got, it can take filters (this is used by the tag cloud)
*/
- public static function get_tags($limit,$filters=array()) {
+ public static function get_tags($limit,$filters=array()) {
- $sql = "SELECT `tag_map`.`tag_id`,COUNT(`tag_map`.`object_id`) AS `count` " .
+ $sql = "SELECT `tag_map`.`tag_id`,COUNT(`tag_map`.`object_id`) AS `count` " .
"FROM `tag_map` " .
- "LEFT JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " .
- "GROUP BY `tag`.`name` ORDER BY `count` DESC " .
+ "LEFT JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " .
+ "GROUP BY `tag`.`name` ORDER BY `count` DESC " .
"LIMIT $limit";
- $db_results = Dba::read($sql);
+ $db_results = Dba::read($sql);
- $results = array();
+ $results = array();
- while ($row = Dba::fetch_assoc($db_results)) {
- if ($row['count'] > $top) { $top = $row['count']; }
- $results[$row['tag_id']] = array('id'=>$row['tag_id'],'count'=>$row['count']);
- $count+= $row['count'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ if ($row['count'] > $top) { $top = $row['count']; }
+ $results[$row['tag_id']] = array('id'=>$row['tag_id'],'count'=>$row['count']);
+ $count+= $row['count'];
+ }
// Do something with this
- $min = $row['count'];
+ $min = $row['count'];
- return $results;
+ return $results;
} // get_tags
@@ -433,22 +433,22 @@ class Tag extends database_object {
* it also takes a type so that it knows how to return it, this is used
* by the formating functions of the different objects
*/
- public static function get_display($tags,$element_id,$type='song') {
+ public static function get_display($tags,$element_id,$type='song') {
- if (!is_array($tags)) { return ''; }
+ if (!is_array($tags)) { return ''; }
- $results = '';
+ $results = '';
// Itterate through the tags, format them according to type and element id
- foreach ($tags as $tag_id=>$value) {
- $tag = new Tag($tag_id);
- $tag->format($type,$element_id);
- $results .= $tag->f_name . ', ';
- }
+ foreach ($tags as $tag_id=>$value) {
+ $tag = new Tag($tag_id);
+ $tag->format($type,$element_id);
+ $results .= $tag->f_name . ', ';
+ }
- $results = rtrim($results,', ');
+ $results = rtrim($results,', ');
- return $results;
+ return $results;
} // get_display
@@ -457,20 +457,20 @@ class Tag extends database_object {
* This returns the count for the all objects assoicated with this tag
* If a type is specific only counts for said type are returned
*/
- public function count($type='') {
+ public function count($type='') {
- if ($type) {
- $filter_sql = " AND `object_type`='" . Dba::escape($type) . "'";
- }
+ if ($type) {
+ $filter_sql = " AND `object_type`='" . Dba::escape($type) . "'";
+ }
- $results = array();
+ $results = array();
- $sql = "SELECT COUNT(`id`) AS `count`,`object_type` FROM `tag_map` WHERE `tag_id`='" . Dba::escape($this->id) . "'" . $filter_sql . " GROUP BY `object_type`";
- $db_results = Dba::read($sql);
+ $sql = "SELECT COUNT(`id`) AS `count`,`object_type` FROM `tag_map` WHERE `tag_id`='" . Dba::escape($this->id) . "'" . $filter_sql . " GROUP BY `object_type`";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
+ while ($row = Dba::fetch_assoc($db_results)) {
$results[$row['object_type']] = $row['count'];
- }
+ }
return $results;
@@ -484,7 +484,7 @@ class Tag extends database_object {
$colors = array('#0000FF',
'#00FF00', '#FFFF00', '#00FFFF','#FF00FF','#FF0000');
- $prefs = 'tag company';
+ $prefs = 'tag company';
// $prefs = Config::get('tags_userlist');
$ulist = explode(' ', $prefs);
@@ -496,41 +496,41 @@ class Tag extends database_object {
$req = rtrim($req, ',');
$sql = 'SELECT `id`,`username` FROM `user` WHERE ';
-
- if ($prefs=='all') {
+
+ if ($prefs=='all') {
$sql .= '1';
- }
- else {
+ }
+ else {
$sql .= 'username in ('.$req.')';
}
- $db_results = Dba::read($sql);
+ $db_results = Dba::read($sql);
$uids=array();
$usernames = array();
$p = 0;
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$usernames[$r['id']] = $r['username'];
$uids[$r['id']] = $colors[$p];
$p++;
- if ($p == sizeof($colors)) {
+ if ($p == sizeof($colors)) {
$p = 0;
- }
+ }
}
-
+
$res = array();
-
+
foreach ($l as $i) {
- if ($GLOBALS['user']->id == $i['user']) {
+ if ($GLOBALS['user']->id == $i['user']) {
$res[] = $i;
- }
+ }
elseif (isset($uids[$i['user']])) {
$i['color'] = $uids[$i['user']];
$i['username'] = $usernames[$i['user']];
$res[] = $i;
}
}
-
+
return $res;
} // filter_with_prefs
@@ -539,19 +539,19 @@ class Tag extends database_object {
* remove_map
* This will only remove tag maps for the current user
*/
- public function remove_map($type,$object_id) {
+ public function remove_map($type,$object_id) {
- if (!self::validate_type($type)) { return false; }
+ if (!self::validate_type($type)) { return false; }
- $type = Dba::escape($type);
- $tag_id = Dba::escape($this->id);
- $object_id = Dba::escape($object_id);
- $user_id = Dba::escape($GLOBALS['user']->id);
+ $type = Dba::escape($type);
+ $tag_id = Dba::escape($this->id);
+ $object_id = Dba::escape($object_id);
+ $user_id = Dba::escape($GLOBALS['user']->id);
- $sql = "DELETE FROM `tag_map` WHERE `tag_id`='$tag_id' AND `object_type`='$type' AND `object_id`='$object_id' AND `user`='$user_id'";
- $db_results = Dba::write($sql);
+ $sql = "DELETE FROM `tag_map` WHERE `tag_id`='$tag_id' AND `object_type`='$type' AND `object_id`='$object_id' AND `user`='$user_id'";
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // remove_map
@@ -560,13 +560,13 @@ class Tag extends database_object {
* This validates the type of the object the user wants to tag, we limit this to types
* we currently support
*/
- public static function validate_type($type) {
+ public static function validate_type($type) {
+
+ $valid_array = array('song','artist','album','video','playlist','live_stream');
- $valid_array = array('song','artist','album','video','playlist','live_stream');
-
- if (in_array($type,$valid_array)) { return $type; }
+ if (in_array($type,$valid_array)) { return $type; }
- return false;
+ return false;
} // validate_type
@@ -574,11 +574,11 @@ class Tag extends database_object {
* clean_tag
* This takes a string and makes it Tagish
*/
- public static function clean_tag($value) {
+ public static function clean_tag($value) {
- $tag = preg_replace("/[^\w\_\-\s\&]/","",$value);
+ $tag = preg_replace("/[^\w\_\-\s\&]/","",$value);
- return $tag;
+ return $tag;
} // clean_tag
diff --git a/lib/class/tmpplaylist.class.php b/lib/class/tmpplaylist.class.php
index 615897bb..a2be6e18 100644
--- a/lib/class/tmpplaylist.class.php
+++ b/lib/class/tmpplaylist.class.php
@@ -23,10 +23,10 @@
/**
* TempPlaylist Class
* This class handles the temporary playlists in ampache, it handles the
- * tmp_playlist and tmp_playlist_data tables, and sneaks out at night to
+ * tmp_playlist and tmp_playlist_data tables, and sneaks out at night to
* visit user_vote from time to time
*/
-class tmpPlaylist extends database_object {
+class tmpPlaylist extends database_object {
/* Variables from the Datbase */
public $id;
@@ -36,36 +36,36 @@ class tmpPlaylist extends database_object {
public $base_playlist;
/* Generated Elements */
- public $items = array();
+ public $items = array();
/**
- * Constructor
+ * Constructor
* This takes a playlist_id as an optional argument and gathers the information
- * if not playlist_id is passed returns false (or if it isn't found
+ * if not playlist_id is passed returns false (or if it isn't found
*/
- public function __construct($playlist_id='') {
+ public function __construct($playlist_id='') {
if (!$playlist_id) { return false; }
-
+
$this->id = intval($playlist_id);
$info = $this->_get_info();
- foreach ($info as $key=>$value) {
- $this->$key = $value;
- }
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
return true;
} // __construct
- /**
+ /**
* _get_info
- * This is an internal (private) function that gathers the information for this object from the
- * playlist_id that was passed in.
+ * This is an internal (private) function that gathers the information for this object from the
+ * playlist_id that was passed in.
*/
- private function _get_info() {
+ private function _get_info() {
- $sql = "SELECT * FROM `tmp_playlist` WHERE `id`='" . Dba::escape($this->id) . "'";
+ $sql = "SELECT * FROM `tmp_playlist` WHERE `id`='" . Dba::escape($this->id) . "'";
$db_results = Dba::read($sql);
$results = Dba::fetch_assoc($db_results);
@@ -79,22 +79,22 @@ class tmpPlaylist extends database_object {
* This returns a playlist object based on the session that is passed to us
* this is used by the load_playlist on user for the most part
*/
- public static function get_from_session($session_id) {
+ public static function get_from_session($session_id) {
+
+ $session_id = Dba::escape($session_id);
- $session_id = Dba::escape($session_id);
+ $sql = "SELECT `id` FROM `tmp_playlist` WHERE `session`='$session_id'";
+ $db_results = Dba::read($sql);
- $sql = "SELECT `id` FROM `tmp_playlist` WHERE `session`='$session_id'";
- $db_results = Dba::read($sql);
+ $results = Dba::fetch_row($db_results);
- $results = Dba::fetch_row($db_results);
-
- if (!$results['0']) {
- $results['0'] = tmpPlaylist::create($session_id,'user','song');
- }
+ if (!$results['0']) {
+ $results['0'] = tmpPlaylist::create($session_id,'user','song');
+ }
- $playlist = new tmpPlaylist($results['0']);
+ $playlist = new tmpPlaylist($results['0']);
- return $playlist;
+ return $playlist;
} // get_from_session
@@ -103,20 +103,20 @@ class tmpPlaylist extends database_object {
* This returns a tmp playlist object based on a userid passed
* this is used for the user profiles page
*/
- public static function get_from_userid($user_id) {
+ public static function get_from_userid($user_id) {
// This is a little stupid, because we don't have the user_id in the session or
// in the tmp_playlist table we have to do it this way.
- $client = new User($user_id);
- $username = Dba::escape($client->username);
+ $client = new User($user_id);
+ $username = Dba::escape($client->username);
+
+ $sql = "SELECT `tmp_playlist`.`id` FROM `tmp_playlist` LEFT JOIN `session` ON `session`.`id`=`tmp_playlist`.`session` " .
+ " WHERE `session`.`username`='$username' ORDER BY `session`.`expire` DESC";
+ $db_results = Dba::read($sql);
- $sql = "SELECT `tmp_playlist`.`id` FROM `tmp_playlist` LEFT JOIN `session` ON `session`.`id`=`tmp_playlist`.`session` " .
- " WHERE `session`.`username`='$username' ORDER BY `session`.`expire` DESC";
- $db_results = Dba::read($sql);
+ $data = Dba::fetch_assoc($db_results);
- $data = Dba::fetch_assoc($db_results);
-
- return $data['id'];
+ return $data['id'];
} // get_from_userid
@@ -126,20 +126,20 @@ class tmpPlaylist extends database_object {
* has gotten a little more complicated because of type, the values are an array
* 0 being ID 1 being TYPE
*/
- public function get_items() {
+ public function get_items() {
$order = 'ORDER BY id ASC';
-
+
/* Select all objects from this playlist */
- $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id " .
- "FROM tmp_playlist_data " .
+ $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id " .
+ "FROM tmp_playlist_data " .
"WHERE tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "' $order";
$db_results = Dba::read($sql);
-
+
/* Define the array */
$items = array();
- while ($results = Dba::fetch_assoc($db_results)) {
+ while ($results = Dba::fetch_assoc($db_results)) {
$key = $results['id'];
$items[$key] = array($results['object_type'],$results['object_id']);
}
@@ -150,16 +150,16 @@ class tmpPlaylist extends database_object {
/**
* get_next_object
- * This returns the next object in the tmp_playlist most of the time this
+ * This returns the next object in the tmp_playlist most of the time this
* will just be the top entry, but if there is a base_playlist and no
* items in the playlist then it returns a random entry from the base_playlist
*/
- public function get_next_object() {
+ public function get_next_object() {
$tmp_id = Dba::escape($this->id);
$order = " ORDER BY tmp_playlist_data.id DESC";
- $sql = "SELECT tmp_playlist_data.object_id FROM tmp_playlist_data " .
+ $sql = "SELECT tmp_playlist_data.object_id FROM tmp_playlist_data " .
"WHERE tmp_playlist_data.tmp_playlist = '$tmp_id' $order LIMIT 1";
$db_results = Dba::read($sql);
@@ -173,14 +173,14 @@ class tmpPlaylist extends database_object {
* count_items
* This returns a count of the total number of tracks that are in this tmp playlist
*/
- public function count_items() {
+ public function count_items() {
- $sql = "SELECT COUNT(`id`) FROM `tmp_playlist_data` WHERE `tmp_playlist_data`.`tmp_playlist`='" . $this->id . "'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT COUNT(`id`) FROM `tmp_playlist_data` WHERE `tmp_playlist_data`.`tmp_playlist`='" . $this->id . "'";
+ $db_results = Dba::read($sql);
- $results = Dba::fetch_row($db_results);
+ $results = Dba::fetch_row($db_results);
- return $results['0'];
+ return $results['0'];
} // count_items
@@ -188,50 +188,50 @@ class tmpPlaylist extends database_object {
* clear
* This clears all the objects out of a single playlist
*/
- public function clear() {
+ public function clear() {
- $sql = "DELETE FROM `tmp_playlist_data` WHERE `tmp_playlist_data`.`tmp_playlist`='" . $this->id . "'";
- $db_results = Dba::write($sql);
+ $sql = "DELETE FROM `tmp_playlist_data` WHERE `tmp_playlist_data`.`tmp_playlist`='" . $this->id . "'";
+ $db_results = Dba::write($sql);
- return true;
+ return true;
} // clear
- /**
+ /**
* create
* This function initializes a new tmpPlaylist it is assoicated with the current
* session rather then a user, as you could have same user multiple locations
*/
- public static function create($sessid,$type,$object_type) {
+ public static function create($sessid,$type,$object_type) {
$sessid = Dba::escape($sessid);
$type = Dba::escape($type);
$object_type = Dba::escape($object_type);
- $sql = "INSERT INTO `tmp_playlist` (`session`,`type`,`object_type`) " .
+ $sql = "INSERT INTO `tmp_playlist` (`session`,`type`,`object_type`) " .
" VALUES ('$sessid','$type','$object_type')";
$db_results = Dba::write($sql);
$id = Dba::insert_id();
- $do_prune = rand(0,4);
- if ($do_prune%2) {
+ $do_prune = rand(0,4);
+ if ($do_prune%2) {
self::prune_playlists();
- self::prune_tracks();
- }
+ self::prune_tracks();
+ }
/* Clean any other playlists assoicated with this session */
self::delete($sessid,$id);
return $id;
- } // create
+ } // create
/**
* update_playlist
* This updates the base_playlist on this tmp_playlist
*/
- public function update_playlist($playlist_id) {
+ public function update_playlist($playlist_id) {
$playlist_id = Dba::escape($playlist_id);
$tmp_id = Dba::escape($this->id);
@@ -246,9 +246,9 @@ class tmpPlaylist extends database_object {
/**
* delete
* This deletes any other tmp_playlists assoicated with this
- * session
+ * session
*/
- public static function delete($sessid,$id) {
+ public static function delete($sessid,$id) {
$sessid = Dba::escape($sessid);
$id = Dba::escape($id);
@@ -267,11 +267,11 @@ class tmpPlaylist extends database_object {
* prune_playlists
* This deletes and playlists that don't have an assoicated session
*/
- public static function prune_playlists() {
+ public static function prune_playlists() {
/* Just delete if no matching session row */
- $sql = "DELETE FROM `tmp_playlist` USING `tmp_playlist` " .
- "LEFT JOIN session ON session.id=tmp_playlist.session " .
+ $sql = "DELETE FROM `tmp_playlist` USING `tmp_playlist` " .
+ "LEFT JOIN session ON session.id=tmp_playlist.session " .
"WHERE session.id IS NULL AND tmp_playlist.type != 'vote'";
$db_results = Dba::write($sql);
@@ -281,13 +281,13 @@ class tmpPlaylist extends database_object {
/**
* prune_tracks
- * This prunes tracks that don't have playlists or don't have votes
+ * This prunes tracks that don't have playlists or don't have votes
*/
- public static function prune_tracks() {
+ public static function prune_tracks() {
// This prue is always run clears data for playlists that don't have tmp_playlist anymore
- $sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data " .
- "LEFT JOIN tmp_playlist ON tmp_playlist_data.tmp_playlist=tmp_playlist.id " .
+ $sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data " .
+ "LEFT JOIN tmp_playlist ON tmp_playlist_data.tmp_playlist=tmp_playlist.id " .
"WHERE tmp_playlist.id IS NULL";
$db_results = Dba::write($sql);
@@ -298,13 +298,13 @@ class tmpPlaylist extends database_object {
* This adds the object of $this->object_type to this tmp playlist
* it takes an optional type, default is song
*/
- public function add_object($object_id,$object_type) {
+ public function add_object($object_id,$object_type) {
$object_id = Dba::escape($object_id);
$playlist_id = Dba::escape($this->id);
- $object_type = $object_type ? Dba::escape($object_type) : 'song';
+ $object_type = $object_type ? Dba::escape($object_type) : 'song';
- $sql = "INSERT INTO `tmp_playlist_data` (`object_id`,`tmp_playlist`,`object_type`) " .
+ $sql = "INSERT INTO `tmp_playlist_data` (`object_id`,`tmp_playlist`,`object_type`) " .
" VALUES ('$object_id','$playlist_id','$object_type')";
$db_results = Dba::write($sql);
@@ -315,12 +315,12 @@ class tmpPlaylist extends database_object {
/**
* vote_active
* This checks to see if this playlist is a voting playlist
- * and if it is active
+ * and if it is active
*/
- public function vote_active() {
+ public function vote_active() {
/* Going to do a little more here later */
- if ($this->type == 'vote') { return true; }
+ if ($this->type == 'vote') { return true; }
return false;
@@ -330,17 +330,17 @@ class tmpPlaylist extends database_object {
* delete_track
* This deletes a track from the tmpplaylist
*/
- public function delete_track($id) {
+ public function delete_track($id) {
$id = Dba::escape($id);
/* delete the track its self */
- $sql = "DELETE FROM `tmp_playlist_data` " .
+ $sql = "DELETE FROM `tmp_playlist_data` " .
" WHERE `id`='$id'";
$db_results = Dba::write($sql);
return true;
} // delete_track
-
+
} // class tmpPlaylist
diff --git a/lib/class/update.class.php b/lib/class/update.class.php
index f3ba888c..2fa2bb30 100644
--- a/lib/class/update.class.php
+++ b/lib/class/update.class.php
@@ -329,13 +329,13 @@ class Update {
$version[] = array('version'=>'360001','description'=>$update_string);
- $update_string = '- Add Bandwidth and Feature preferences to simplify how interface is presented<br />' .
- '- Change Tables to FULLTEXT() for improved searching<br />' .
- '- Increase Filename lengths to 4096<br />' .
- '- Remove useless "KEY" reference from ACL and Catalog tables<br />' .
- '- Add new Remote User / Remote Password fields to Catalog<br />';
+ $update_string = '- Add Bandwidth and Feature preferences to simplify how interface is presented<br />' .
+ '- Change Tables to FULLTEXT() for improved searching<br />' .
+ '- Increase Filename lengths to 4096<br />' .
+ '- Remove useless "KEY" reference from ACL and Catalog tables<br />' .
+ '- Add new Remote User / Remote Password fields to Catalog<br />';
- $version[] = array('version'=>'360002','description'=>$update_string);
+ $version[] = array('version'=>'360002','description'=>$update_string);
return $version;
@@ -1811,52 +1811,52 @@ class Update {
* This update makes changes to the cataloging to accomodate the new method for syncing between
* Ampache instances, could be adapted to sync with whatever for "full" catalog
*/
- public static function update_360002() {
+ public static function update_360002() {
// Drop the key from catalog and ACL
- $sql = "ALTER TABLE `catalog` DROP `key`";
- $db_results = Dba::write($sql);
+ $sql = "ALTER TABLE `catalog` DROP `key`";
+ $db_results = Dba::write($sql);
- $sql = "ALTER TABLE `access_list` DROP `key`";
- $db_results = Dba::write($sql);
+ $sql = "ALTER TABLE `access_list` DROP `key`";
+ $db_results = Dba::write($sql);
- // Add in Username / Password for catalog - to be used for remote catalogs
- $sql = "ALTER TABLE `catalog` ADD `remote_username` VARCHAR ( 255 ) AFTER `user`";
- $db_results = Dba::write($sql);
+ // Add in Username / Password for catalog - to be used for remote catalogs
+ $sql = "ALTER TABLE `catalog` ADD `remote_username` VARCHAR ( 255 ) AFTER `user`";
+ $db_results = Dba::write($sql);
- $sql = "ALTER TABLE `catalog` ADD `remote_password` VARCHAR ( 255 ) AFTER `remote_username`";
- $db_results = Dba::write($sql);
+ $sql = "ALTER TABLE `catalog` ADD `remote_password` VARCHAR ( 255 ) AFTER `remote_username`";
+ $db_results = Dba::write($sql);
// Adjust the Filename field in song, make it gi-normous. If someone has anything close to
- // this file length, they seriously need to reconsider what they are doing.
- $sql = "ALTER TABLE `song` CHANGE `file` `file` VARCHAR ( 4096 )";
- $db_results = Dba::write($sql);
+ // this file length, they seriously need to reconsider what they are doing.
+ $sql = "ALTER TABLE `song` CHANGE `file` `file` VARCHAR ( 4096 )";
+ $db_results = Dba::write($sql);
+
+ $sql = "ALTER TABLE `video` CHANGE `file` `file` VARCHAR ( 4096 )";
+ $db_results = Dba::write($sql);
- $sql = "ALTER TABLE `video` CHANGE `file` `file` VARCHAR ( 4096 )";
- $db_results = Dba::write($sql);
+ $sql = "ALTER TABLE `live_stream` CHANGE `url` `url` VARCHAR ( 4096 )";
+ $db_results = Dba::write($sql);
- $sql = "ALTER TABLE `live_stream` CHANGE `url` `url` VARCHAR ( 4096 )";
- $db_results = Dba::write($sql);
-
// Index the Artist, Album, and Song tables to prepare for Fulltext searches.
$sql = "ALTER TABLE `artist` ADD FULLTEXT(`name`)";
$db_results = Dba::write($sql);
-
+
$sql = "ALTER TABLE `album` ADD FULLTEXT(`name`)";
$db_results = Dba::write($sql);
-
+
$sql = "ALTER TABLE `song` ADD FULLTEXT(`title`)";
$db_results = Dba::write($sql);
-
+
// Now add in the min_object_count preference and the random_method
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('bandwidth','50','Bandwidth','5','integer','interface')";
$db_results = Dba::write($sql);
- $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
- "VALUES ('features','50','Features','5','integer','interface')";
- $db_results = Dba::write($sql);
-
+ $sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
+ "VALUES ('features','50','Features','5','integer','interface')";
+ $db_results = Dba::write($sql);
+
/* Fix every users preferences */
$sql = "SELECT `id` FROM `user`";
$db_results = Dba::read($sql);
@@ -1866,7 +1866,7 @@ class Update {
while ($r = Dba::fetch_assoc($db_results)) {
User::fix_preferences($r['id']);
} // while results
-
+
self::set_version('db_version','360002');
} // update_360002
diff --git a/lib/class/user.class.php b/lib/class/user.class.php
index 4ba750d1..f4bc68b5 100644
--- a/lib/class/user.class.php
+++ b/lib/class/user.class.php
@@ -198,9 +198,9 @@ class User extends database_object {
$sql = "SELECT preference.name, preference.description, preference.catagory, preference.level, user_preference.value " .
"FROM preference INNER JOIN user_preference ON user_preference.preference=preference.id " .
- "WHERE user_preference.user='$user_id' " . $user_limit .
+ "WHERE user_preference.user='$user_id' " . $user_limit .
" ORDER BY preference.catagory, preference.description";
-
+
$db_results = Dba::read($sql);
/* Ok this is crapy, need to clean this up or improve the code FIXME */
@@ -729,10 +729,10 @@ class User extends database_object {
/* Get Users Last ip */
if (count($data = $this->get_ip_history(1))) {
$this->ip_history = inet_ntop($data['0']['ip']);
- }
- else {
- $this->ip_history = _('Not Enough Data');
- }
+ }
+ else {
+ $this->ip_history = _('Not Enough Data');
+ }
} // format_user
diff --git a/lib/class/vainfo.class.php b/lib/class/vainfo.class.php
index 692d0229..152cc67d 100644
--- a/lib/class/vainfo.class.php
+++ b/lib/class/vainfo.class.php
@@ -23,15 +23,15 @@
/**
* vainfo
* This class takes the information pulled from getID3 and returns it in a
- * Ampache friendly way.
+ * Ampache friendly way.
*/
-class vainfo {
+class vainfo {
/* Default Encoding */
public $encoding = '';
public $encoding_id3v1 = 'ISO-8859-1';
public $encoding_id3v2 = 'ISO-8859-1';
-
+
/* Loaded Variables */
public $filename = '';
public $type = '';
@@ -41,33 +41,33 @@ class vainfo {
public $_raw = array();
public $_raw2 = array();
public $_getID3 = '';
- public $_iconv = false;
+ public $_iconv = false;
public $_file_encoding = '';
public $_file_pattern = '';
public $_dir_pattern = '';
/* Internal Private */
- private $_binary_parse = array();
- private $_pathinfo;
- private $_broken=false;
+ private $_binary_parse = array();
+ private $_pathinfo;
+ private $_broken=false;
/**
* Constructor
* This function just sets up the class, it doesn't
* actually pull the information
*/
- public function __construct($file,$encoding='',$encoding_id3v1='',$encoding_id3v2='',$dir_pattern,$file_pattern) {
+ public function __construct($file,$encoding='',$encoding_id3v1='',$encoding_id3v2='',$dir_pattern,$file_pattern) {
/* Check for ICONV */
- if (function_exists('iconv')) {
+ if (function_exists('iconv')) {
$this->_iconv = true;
}
$this->filename = $file;
- if ($encoding) {
+ if ($encoding) {
$this->encoding = $encoding;
}
- else {
+ else {
$this->encoding = Config::get('site_charset');
}
@@ -82,20 +82,20 @@ class vainfo {
else {
$this->_pathinfo = pathinfo(str_replace('%2F', '/', urlencode($this->filename)));
}
- $this->_pathinfo['extension'] = strtolower($this->_pathinfo['extension']);
+ $this->_pathinfo['extension'] = strtolower($this->_pathinfo['extension']);
// Before we roll the _getID3 route let's see about using exec + a binary
/*
- if (!isset($this->_binary_parse[$this->_pathinfo['extension']])) {
+ if (!isset($this->_binary_parse[$this->_pathinfo['extension']])) {
// Figure out if we've got binary parse ninja-skills here
- $this->_binary_parse[$this->_pathinfo['extension']] = $this->can_binary_parse();
- debug_event('BinaryParse','Binary Parse for ' . $this->_pathinfo['extension'] . ' set to ' . make_bool($this->_binary_parse[$this->_pathinfo['extension']]),'5');
- }
+ $this->_binary_parse[$this->_pathinfo['extension']] = $this->can_binary_parse();
+ debug_event('BinaryParse','Binary Parse for ' . $this->_pathinfo['extension'] . ' set to ' . make_bool($this->_binary_parse[$this->_pathinfo['extension']]),'5');
+ }
*/
// Initialize getID3 engine
$this->_getID3 = new getID3();
-// if ($this->_binary_parse[$this->_pathinfo['extension']]) { return true; }
+// if ($this->_binary_parse[$this->_pathinfo['extension']]) { return true; }
// get id3tag encodings
// we have to run this right here because we don't know what we have in the files
@@ -105,9 +105,9 @@ class vainfo {
}
catch (Exception $error) {
debug_event('Getid3()',"Broken file detected $file - " . $error->message,'1');
- $this->_broken = true;
- return false;
- }
+ $this->_broken = true;
+ return false;
+ }
if(function_exists('mb_detect_encoding')) {
$this->encoding_id3v1 = array();
@@ -122,7 +122,7 @@ class vainfo {
} else {
$this->encoding_id3v1 = "ISO-8859-1";
}
-
+
$this->encoding_id3v2 = array();
$this->encoding_id3v2[] = mb_detect_encoding($this->_raw2['tags']['id3v2']['artist']['0']);
@@ -147,10 +147,10 @@ class vainfo {
$this->_getID3->option_tags_html = false;
$this->_getID3->option_extra_info = true;
$this->_getID3->option_tag_lyrics3 = true;
- $this->_getID3->encoding = $this->encoding;
+ $this->_getID3->encoding = $this->encoding;
$this->_getID3->encoding_id3v1 = $this->encoding_id3v1;
$this->_getID3->encoding_id3v2 = $this->encoding_id3v2;
- $this->_getID3->option_tags_process = true;
+ $this->_getID3->option_tags_process = true;
} // vainfo
@@ -164,41 +164,41 @@ class vainfo {
*/
public function get_info() {
- // If this is broken, don't waste time figuring it out a second time, just return
+ // If this is broken, don't waste time figuring it out a second time, just return
// their rotting carcass of a media file back on the pile
- if ($this->_broken) {
- $this->tags = $this->set_broken();
- return true;
- }
+ if ($this->_broken) {
+ $this->tags = $this->set_broken();
+ return true;
+ }
// If we've got a green light try out the binary
-// if ($this->_binary_parse[$this->_pathinfo['extension']]) {
-// $this->run_binary_parse();
-// }
-
-// else {
+// if ($this->_binary_parse[$this->_pathinfo['extension']]) {
+// $this->run_binary_parse();
+// }
+
+// else {
/* Get the Raw file information */
- try {
+ try {
$this->_raw = $this->_getID3->analyze($this->filename);
- }
- catch (Exception $error) {
+ }
+ catch (Exception $error) {
debug_event('Getid3()',"Unable to catalog file:" . $error->message,'1');
- }
+ }
/* Figure out what type of file we are dealing with */
$this->type = $this->_get_type();
/* Get the general information about this file */
$info = $this->_get_info();
-// }
+// }
/* Gets the Tags */
$this->tags = $this->_get_tags();
$this->tags['info'] = $info;
unset($this->_raw);
-
+
} // get_info
/**
@@ -207,7 +207,7 @@ class vainfo {
* As defined by your config file and trys to figure out
* which tag type(s) it should use, if your tag_order
* doesn't match anything then it just takes the first one
- * it finds in the results.
+ * it finds in the results.
*/
public static function get_tag_type($results) {
@@ -217,7 +217,7 @@ class vainfo {
if (!is_array($order)) {
$order = array($order);
}
-
+
/* Foreach through the defined key order
* adding them to an ordered array as we go
*/
@@ -244,8 +244,8 @@ class vainfo {
/**
* clean_tag_info
- * This function takes the array from vainfo along with the
- * key we've decided on and the filename and returns it in a
+ * This function takes the array from vainfo along with the
+ * key we've decided on and the filename and returns it in a
* sanatized format that ampache can actually use
*/
public static function clean_tag_info($results,$keys,$filename) {
@@ -275,11 +275,11 @@ class vainfo {
// Specific Audio Flags
foreach ($keys as $key) {
- if (!$results[$key]['video_codec']) {
- $slash_point = strpos($results[$key]['disk'],'/');
- if ($slash_point !== FALSE) {
- $results[$key]['disk'] = substr($results[$key]['disk'],0,$slash_point);
- }
+ if (!$results[$key]['video_codec']) {
+ $slash_point = strpos($results[$key]['disk'],'/');
+ if ($slash_point !== FALSE) {
+ $results[$key]['disk'] = substr($results[$key]['disk'],0,$slash_point);
+ }
/* These are used to generate the correct ID's later */
$info['title'] = $info['title']
? $info['title']
@@ -331,16 +331,16 @@ class vainfo {
$info['language'] = $info['language']
? $info['language']
: Dba::escape($results[$key]['language']);
-
+
$info['lyrics'] = $info['lyrics']
? $info['lyrics']
: str_replace(array("\r\n","\r","\n"), '<br />',strip_tags($results[$key]['unsynchronised lyric']));
- $info['track'] = $info['track']
+ $info['track'] = $info['track']
? $info['track']
: intval($results[$key]['track']);
}
- else {
+ else {
$info['resolution_x'] = $info['resolution_x']
? $info['resolution_x']
: intval($results[$key]['resolution_x']);
@@ -355,7 +355,7 @@ class vainfo {
$info['video_codec'] = $info['video_codec']
? $info['video_codec']
- : Dba::escape($results[$key]['video_codec']);
+ : Dba::escape($results[$key]['video_codec']);
}
}
// Lyrics3 v2.0
@@ -370,23 +370,23 @@ class vainfo {
/**
* _get_type
* This function takes the raw information and figures out
- * what type of file we are dealing with for use by the tag
+ * what type of file we are dealing with for use by the tag
* function
*/
- public function _get_type() {
+ public function _get_type() {
/* There are a few places that the file type can
- * come from, in the end we trust the encoding
+ * come from, in the end we trust the encoding
* type
*/
- if ($type = $this->_raw['video']['dataformat']) {
+ if ($type = $this->_raw['video']['dataformat']) {
// Manually set the tag information
- if ($type == 'flv') {
- $this->_raw['tags']['flv'] = array();
- }
- if ($type == 'quicktime') {
- $this->_raw['tags']['quicktime'] = array();
- }
+ if ($type == 'flv') {
+ $this->_raw['tags']['flv'] = array();
+ }
+ if ($type == 'quicktime') {
+ $this->_raw['tags']['quicktime'] = array();
+ }
if($type == 'mpeg' OR $type == 'mpg') {
$this->_raw['tags']['mpeg'] = array();
}
@@ -396,21 +396,21 @@ class vainfo {
if($type == 'wmv') {
$this->_raw['tags']['wmv'] = array();
}
- else {
- $this->_raw['tags']['avi'] = array();
- }
- $type = $this->_clean_type($type);
- return $type;
- }
- if ($type = $this->_raw['audio']['streams']['0']['dataformat']) {
+ else {
+ $this->_raw['tags']['avi'] = array();
+ }
+ $type = $this->_clean_type($type);
+ return $type;
+ }
+ if ($type = $this->_raw['audio']['streams']['0']['dataformat']) {
$type = $this->_clean_type($type);
return $type;
}
- if ($type = $this->_raw['audio']['dataformat']) {
+ if ($type = $this->_raw['audio']['dataformat']) {
$type = $this->_clean_type($type);
return $type;
}
- if ($type = $this->_raw['fileformat']) {
+ if ($type = $this->_raw['fileformat']) {
$type = $this->_clean_type($type);
return $type;
}
@@ -426,26 +426,26 @@ class vainfo {
* attempts to gather the tags and then normalize them into
* ['tag_name']['var'] = value
*/
- public function _get_tags() {
+ public function _get_tags() {
$results = array();
/* Gather Tag information from the filenames */
$results['file'] = $this->_parse_filename($this->filename);
- /* Return false if we don't have
- * any tags to look at
+ /* Return false if we don't have
+ * any tags to look at
*/
- if (!is_array($this->_raw['tags'])) {
- return $results;
+ if (!is_array($this->_raw['tags'])) {
+ return $results;
}
- /* The tags can come in many different shapes and colors
+ /* The tags can come in many different shapes and colors
* depending on the encoding time of day and phase of the
* moon
*/
- foreach ($this->_raw['tags'] as $key=>$tag_array) {
- switch ($key) {
+ foreach ($this->_raw['tags'] as $key=>$tag_array) {
+ switch ($key) {
case 'vorbiscomment':
debug_event('_get_tags', 'Parsing vorbis', '5');
$results[$key] = $this->_parse_vorbiscomment($tag_array);
@@ -468,14 +468,14 @@ class vainfo {
break;
case 'riff':
debug_event('_get_tags', 'Parsing riff', '5');
- $results[$key] = $this->_parse_riff($tag_array);
+ $results[$key] = $this->_parse_riff($tag_array);
break;
- case 'flv':
+ case 'flv':
debug_event('_get_tags', 'Parsing flv', '5');
- $results[$key] = $this->_parse_flv($this->_raw2);
- break;
+ $results[$key] = $this->_parse_flv($this->_raw2);
+ break;
case 'mpg':
- case 'mpeg':
+ case 'mpeg':
debug_event('_get_tags', 'Parsing MPEG', '5');
$results[$key] = $this->_parse_mpg($this->_raw2);
break;
@@ -484,15 +484,15 @@ class vainfo {
debug_event('_get_tags', 'Parsing WMV/WMA/ASF', '5');
$results[$key] = $this->_parse_wmv($this->_raw2);
break;
- case 'avi':
+ case 'avi':
debug_event('_get_tags', 'Parsing avi', '5');
- $results[$key] = $this->_parse_avi($this->_raw2);
- break;
+ $results[$key] = $this->_parse_avi($this->_raw2);
+ break;
case 'lyrics3':
debug_event('_get_tags', 'Parsing lyrics3', '5');
$results[$key] = $this->_parse_lyrics($tag_array);
break;
- default:
+ default:
debug_event('vainfo','Error: Unable to determine tag type of ' . $key . ' for file ' . $this->filename . ' Assuming id3v2','5');
$results[$key] = $this->_parse_id3v2($this->_raw['id3v2']['comments']);
break;
@@ -509,35 +509,35 @@ class vainfo {
* This function gathers and returns the general information
* about a song, vbr/cbr sample rate channels etc
*/
- private function _get_info() {
+ private function _get_info() {
$array = array();
/* Try to pull the information directly from
- * the audio array
+ * the audio array
*/
- if ($this->_raw['audio']['bitrate_mode']) {
+ if ($this->_raw['audio']['bitrate_mode']) {
$array['bitrate_mode'] = $this->_raw['audio']['bitrate_mode'];
}
- if ($this->_raw['audio']['bitrate']) {
+ if ($this->_raw['audio']['bitrate']) {
$array['bitrate'] = $this->_raw['audio']['bitrate'];
}
- if ($this->_raw['audio']['channels']) {
+ if ($this->_raw['audio']['channels']) {
$array['channels'] = intval($this->_raw['audio']['channels']);
}
- if ($this->_raw['audio']['sample_rate']) {
+ if ($this->_raw['audio']['sample_rate']) {
$array['sample_rate'] = intval($this->_raw['audio']['sample_rate']);
}
- if ($this->_raw['filesize']) {
+ if ($this->_raw['filesize']) {
$array['filesize'] = intval($this->_raw['filesize']);
}
- if ($this->_raw['encoding']) {
+ if ($this->_raw['encoding']) {
$array['encoding'] = $this->_raw['encoding'];
}
- if ($this->_raw['mime_type']) {
+ if ($this->_raw['mime_type']) {
$array['mime'] = $this->_raw['mime_type'];
}
- if ($this->_raw['playtime_seconds']) {
+ if ($this->_raw['playtime_seconds']) {
$array['playing_time'] = $this->_raw['playtime_seconds'];
}
if ($this->_raw['lyrics3']) {
@@ -545,17 +545,17 @@ class vainfo {
}
return $array;
-
+
} // _get_info
/**
* _clean_type
- * This standardizes the type that we are given into a reconized
+ * This standardizes the type that we are given into a reconized
* type
*/
- private function _clean_type($type) {
+ private function _clean_type($type) {
- switch ($type) {
+ switch ($type) {
case 'mp3':
case 'mp2':
case 'mpeg3':
@@ -564,16 +564,16 @@ class vainfo {
case 'vorbis':
return 'ogg';
break;
- case 'flac':
+ case 'flac':
case 'flv':
case 'mpg':
case 'mpeg':
case 'asf':
case 'wmv':
- case 'avi':
- case 'quicktime':
- return $type;
- default:
+ case 'avi':
+ case 'quicktime':
+ return $type;
+ default:
/* Log the fact that we couldn't figure it out */
debug_event('vainfo','Unable to determine file type from ' . $type . ' on file ' . $this->filename,'5');
return $type;
@@ -609,16 +609,16 @@ class vainfo {
* returns the elements translated using iconv if needed in a
* pretty little format
*/
- private function _parse_vorbiscomment($tags) {
+ private function _parse_vorbiscomment($tags) {
/* Results array */
$array = array();
/* go through them all! */
- foreach ($tags as $tag=>$data) {
-
+ foreach ($tags as $tag=>$data) {
+
/* We need to translate a few of these tags */
- switch ($tag) {
+ switch ($tag) {
case 'genre':
// multiple genre support
@@ -629,8 +629,8 @@ class vainfo {
case 'tracknumber':
$array['track'] = $this->_clean_tag($data['0']);
break;
- case 'discnumber':
- $array['disk'] = $this->_clean_tag($data['0']);
+ case 'discnumber':
+ $array['disk'] = $this->_clean_tag($data['0']);
break;
case 'date':
$array['year'] = $this->_clean_tag($data['0']);
@@ -649,23 +649,23 @@ class vainfo {
/**
* _parse_id3v1
* This function takes a id3v1 tag set from getid3() and then
- * returns the elements translated using iconv if needed in a
+ * returns the elements translated using iconv if needed in a
* pretty little format
*/
- private function _parse_id3v1($tags) {
+ private function _parse_id3v1($tags) {
$array = array();
$encoding = $this->_raw['id3v1']['encoding'];
-
+
/* Go through all the tags */
- foreach ($tags as $tag=>$data) {
+ foreach ($tags as $tag=>$data) {
- /* This is our baseline for naming
- * so no translation needed
+ /* This is our baseline for naming
+ * so no translation needed
*/
$array[$tag] = $this->_clean_tag($data['0'],$encoding);
-
+
} // end foreach
return $array;
@@ -678,18 +678,18 @@ class vainfo {
* returns the lelements translated using iconv if needed in a
* pretty little format
*/
- private function _parse_id3v2($tags) {
+ private function _parse_id3v2($tags) {
$array = array();
/* Go through the tags */
- foreach ($tags as $tag=>$data) {
+ foreach ($tags as $tag=>$data) {
/**
- * the new getid3 handles this differently
+ * the new getid3 handles this differently
* so we now need to account for it :(
*/
- switch ($tag) {
+ switch ($tag) {
case 'genre':
// multiple genre support
foreach($data as $genre) {
@@ -706,16 +706,16 @@ class vainfo {
case 'comments':
$array['comment'] = $this->_clean_tag($data['0'],'');
break;
- case 'title':
- $array['title'] = $this->_clean_tag($data['0'],'');
- break;
- default:
+ case 'title':
+ $array['title'] = $this->_clean_tag($data['0'],'');
+ break;
+ default:
$array[$tag] = $this->_clean_tag($data['0'],'');
break;
} // end switch on tag
-
+
} // end foreach
-
+
$id3v2 = $this->_raw['id3v2'];
if(!empty($id3v2['UFID'])) {
@@ -745,9 +745,9 @@ class vainfo {
* returns the elements translated using iconv if needed in a
* pretty little format
*/
- private function _parse_ape($tags) {
+ private function _parse_ape($tags) {
- foreach ($tags as $tag=>$data) {
+ foreach ($tags as $tag=>$data) {
switch ($tag) {
case 'genre':
@@ -762,7 +762,7 @@ class vainfo {
break;
} // end switch on tag
- } // end foreach tags
+ } // end foreach tags
return $array;
@@ -770,35 +770,35 @@ class vainfo {
/**
* _parse_riff
- * this function takes the riff take information passed by getid3() and
+ * this function takes the riff take information passed by getid3() and
* then reformats it so that it matches the other formats. May require iconv
*/
- private function _parse_riff($tags) {
-
- foreach ($tags as $tag=>$data) {
+ private function _parse_riff($tags) {
+
+ foreach ($tags as $tag=>$data) {
- switch ($tag) {
+ switch ($tag) {
case 'product':
- $array['album'] = $this->_clean_tag($data['0'],$this->_file_encoding);
+ $array['album'] = $this->_clean_tag($data['0'],$this->_file_encoding);
break;
- default:
- $array[$tag] = $this->_clean_tag($data['0'],$this->_file_encoding);
+ default:
+ $array[$tag] = $this->_clean_tag($data['0'],$this->_file_encoding);
break;
} // end switch on tag
} // foreach tags
- return $array;
+ return $array;
} // _parse_riff
/**
* _parse_quicktime
* this function takes the quicktime tags set by getid3() and then
- * returns the elements translated using iconv if needed in a
+ * returns the elements translated using iconv if needed in a
* pretty little format
*/
- private function _parse_quicktime($tags) {
+ private function _parse_quicktime($tags) {
/* Results array */
$array = array();
@@ -809,7 +809,7 @@ class vainfo {
/* We need to translate a few of these tags */
switch ($tag) {
case 'creation_date':
- if (strlen($data['0']) > 4) {
+ if (strlen($data['0']) > 4) {
/* Weird Date format, attempt to normalize */
$data['0'] = date("Y",strtotime($data['0']));
}
@@ -820,36 +820,36 @@ class vainfo {
$array[$tag] = $this->_clean_tag($data['0']);
} // end foreach
-
+
// Also add in any video related stuff we might find
- if (strpos($this->_raw2['mime_type'],'video') !== false) {
- $info = $this->_parse_avi($this->_raw2);
- $info['video_codec'] = $this->_raw2['quicktime']['ftyp']['fourcc'];
- $array = array_merge($info,$array);
- }
+ if (strpos($this->_raw2['mime_type'],'video') !== false) {
+ $info = $this->_parse_avi($this->_raw2);
+ $info['video_codec'] = $this->_raw2['quicktime']['ftyp']['fourcc'];
+ $array = array_merge($info,$array);
+ }
return $array;
} // _parse_quicktime
/**
- * _parse_avi
+ * _parse_avi
* This attempts to parse our the information on an avi file and present it in some
* kind of sane format, this is a little hard as these files don't have tags
*/
- private function _parse_avi($tags) {
+ private function _parse_avi($tags) {
- $array = array();
+ $array = array();
$array['title'] = urldecode($this->_pathinfo['filename']);
- $array['video_codec'] = $tags['video']['fourcc'];
- $array['audio_codec'] = $tags['audio']['dataformat'];
- $array['resolution_x'] = $tags['video']['resolution_x'];
- $array['resolution_y'] = $tags['video']['resolution_y'];
- $array['mime'] = $tags['mime_type'];
- $array['comment'] = $tags['video']['codec'];
+ $array['video_codec'] = $tags['video']['fourcc'];
+ $array['audio_codec'] = $tags['audio']['dataformat'];
+ $array['resolution_x'] = $tags['video']['resolution_x'];
+ $array['resolution_y'] = $tags['video']['resolution_y'];
+ $array['mime'] = $tags['mime_type'];
+ $array['comment'] = $tags['video']['codec'];
- return $array;
+ return $array;
} // _parse_avi
@@ -890,7 +890,7 @@ class vainfo {
case 'video/x-ms-wmv':
if(isset($tags['tags']['asf']['title']['0'])) {
$array['title'] = $tags['tags']['asf']['title']['0'];
- }
+ }
else {
$array['title'] = urldecode($this->_pathinfo['filename']);
}
@@ -911,17 +911,17 @@ class vainfo {
* This attempts to parse our the information on an flv file and present it in some
* kind of sane format, this is a little hard as these files don't have tags
*/
- private function _parse_flv($tags) {
+ private function _parse_flv($tags) {
- $array = array();
+ $array = array();
$array['title'] = urldecode($this->_pathinfo['filename']);
- $array['video_codec'] = $tags['video']['codec'];
- $array['audio_codec'] = $tags['audio']['dataformat'];
- $array['resolution_x'] = $tags['video']['resolution_x'];
- $array['resolution_y'] = $tags['video']['resolution_y'];
- $array['mime'] = $tags['mime_type'];
- $array['comment'] = $tags['video']['codec'];
+ $array['video_codec'] = $tags['video']['codec'];
+ $array['audio_codec'] = $tags['audio']['dataformat'];
+ $array['resolution_x'] = $tags['video']['resolution_x'];
+ $array['resolution_y'] = $tags['video']['resolution_y'];
+ $array['mime'] = $tags['mime_type'];
+ $array['comment'] = $tags['video']['codec'];
return $array;
@@ -930,10 +930,10 @@ class vainfo {
/**
* _parse_filename
* This function uses the passed file and dir patterns
- * To pull out extra tag information and populate it into
+ * To pull out extra tag information and populate it into
* it's own array
*/
- private function _parse_filename($filename) {
+ private function _parse_filename($filename) {
$results = array();
@@ -945,11 +945,11 @@ class vainfo {
$slash_type = '\\';
}
- $pattern = preg_quote($this->_dir_pattern) . $slash_type . preg_quote($this->_file_pattern);
+ $pattern = preg_quote($this->_dir_pattern) . $slash_type . preg_quote($this->_file_pattern);
preg_match_all("/\%\w/",$pattern,$elements);
-
+
$preg_pattern = preg_quote($pattern);
- $preg_pattern = preg_replace("/\%[Ty]/","([0-9]+?)",$preg_pattern);
+ $preg_pattern = preg_replace("/\%[Ty]/","([0-9]+?)",$preg_pattern);
$preg_pattern = preg_replace("/\%\w/","(.+?)",$preg_pattern);
$preg_pattern = str_replace("/","\/",$preg_pattern);
$preg_pattern = str_replace(" ","\s",$preg_pattern);
@@ -959,12 +959,12 @@ class vainfo {
array_shift($matches);
/* Foreach through what we've found */
- foreach ($matches as $key=>$value) {
+ foreach ($matches as $key=>$value) {
$new_key = translate_pattern_code($elements['0'][$key]);
- if ($new_key) {
+ if ($new_key) {
$results[$new_key] = $value;
}
- } // end foreach matches
+ } // end foreach matches
return $results;
@@ -975,7 +975,7 @@ class vainfo {
* This translates the tag name to a frame, if there a many it returns the first
* one if finds that exists in the raw
*/
- private function _id3v2_tag_to_frame($tag_name) {
+ private function _id3v2_tag_to_frame($tag_name) {
static $map = array(
'comment'=>array('COM','COMM'),
@@ -986,15 +986,15 @@ class vainfo {
'artist'=>array('TPE1'),
'year'=>array('TDRC'));
- foreach ($map[$tag_name] as $frame) {
- if (isset($this->_raw['id3v2'][$frame])) {
- return $frame;
- }
- }
+ foreach ($map[$tag_name] as $frame) {
+ if (isset($this->_raw['id3v2'][$frame])) {
+ return $frame;
+ }
+ }
- return false;
+ return false;
- } // _id3v2_tag_to_frame
+ } // _id3v2_tag_to_frame
/**
* _clean_tag
@@ -1004,10 +1004,10 @@ class vainfo {
* is, and or if it's different then the encoding recorded
* in the file
*/
- private function _clean_tag($tag,$encoding='') {
+ private function _clean_tag($tag,$encoding='') {
- // If we've got iconv then go ahead and clear her up
- if ($this->_iconv) {
+ // If we've got iconv then go ahead and clear her up
+ if ($this->_iconv) {
/* Guess that it's UTF-8 */
/* Try GNU iconv //TRANSLIT extension first */
if (!$encoding) { $encoding = $this->_getID3->encoding; }
@@ -1027,27 +1027,27 @@ class vainfo {
* This returns true/false if we can do a binary parse of the file in question
* only the extension is passed so this can be inaccurate
*/
- public function can_binary_parse() {
+ public function can_binary_parse() {
// We're going to need exec for this
- if (!is_callable('exec')) {
- return false;
- }
+ if (!is_callable('exec')) {
+ return false;
+ }
// For now I'm going to use an approved list of apps, later we should allow user config
- switch ($this->_pathinfo['extension']) {
- case 'mp3':
+ switch ($this->_pathinfo['extension']) {
+ case 'mp3':
// Verify the application is there and callable
- exec('id3v2 -v',$results,$retval);
- if ($retval == 0) { return true; }
- break;
+ exec('id3v2 -v',$results,$retval);
+ if ($retval == 0) { return true; }
+ break;
default:
//FAILURE
- break;
+ break;
}
- return false;
+ return false;
} // can_binary_parse
@@ -1056,16 +1056,16 @@ class vainfo {
* This runs the binary parse operations here down in Ampache land
* it is passed the filename, and only called if can_binary_parse passes
*/
- public function run_binary_parse() {
+ public function run_binary_parse() {
// Switch on the extension
- switch ($this->_pathinfo['extension']) {
- case 'mp3':
+ switch ($this->_pathinfo['extension']) {
+ case 'mp3':
$this->_raw['tags'] = $this->mp3_binary_parse();
- break;
+ break;
default:
- $this->_raw['tags'] = array();
- break;
+ $this->_raw['tags'] = array();
+ break;
} // switch on extension
} // run_binary_parse
@@ -1075,56 +1075,56 @@ class vainfo {
* This tries to read the tag information from mp3s using a binary and the exec() command
* This will not work on a lot of systems... but it should be faster
*/
- public function mp3_binary_parse() {
+ public function mp3_binary_parse() {
- require_once(Config::get('prefix') . '/modules/getid3/module.tag.id3v2.php');
+ require_once(Config::get('prefix') . '/modules/getid3/module.tag.id3v2.php');
- $filename = escapeshellarg($this->filename);
+ $filename = escapeshellarg($this->filename);
- exec('id3v2 -l ' . $filename,$info,$retval);
+ exec('id3v2 -l ' . $filename,$info,$retval);
- if ($retval != 0) { return array(); }
+ if ($retval != 0) { return array(); }
- $position=0;
- $results = array();
+ $position=0;
+ $results = array();
// If we've got Id3v1 tag information
- if (substr($info[$position],0,5) == 'id3v1') {
- $position++;
- $v1['title'][] = trim(substr($info[$position],8,30));
+ if (substr($info[$position],0,5) == 'id3v1') {
+ $position++;
+ $v1['title'][] = trim(substr($info[$position],8,30));
$v1['artist'][] = trim(substr($info[$position],49,79));
- $position++;
- $v1['album'][] = trim(substr($info[$position],8,30));
- $v1['year'][] = trim(substr($info[$position],47,53));
- $v1['genre'][] = trim(preg_replace("/\(\d+\)/","",substr($info[$position],60,strlen($info[$position]))));
- $position++;
- $v1['comment'][]= trim(substr($info[$position],8,30));
- $v1['track'][] = trim(substr($info[$position],48,3));
- $results['id3v1'] = $v1;
- $position++;
+ $position++;
+ $v1['album'][] = trim(substr($info[$position],8,30));
+ $v1['year'][] = trim(substr($info[$position],47,53));
+ $v1['genre'][] = trim(preg_replace("/\(\d+\)/","",substr($info[$position],60,strlen($info[$position]))));
+ $position++;
+ $v1['comment'][]= trim(substr($info[$position],8,30));
+ $v1['track'][] = trim(substr($info[$position],48,3));
+ $results['id3v1'] = $v1;
+ $position++;
}
- if (substr($info[$position],0,5) == 'id3v2') {
- $position++;
+ if (substr($info[$position],0,5) == 'id3v2') {
+ $position++;
$element_count = count($info);
- while ($position < $element_count) {
+ while ($position < $element_count) {
$position++;
$element = getid3_id3v2::FrameNameShortLookup(substr($info[$position],0,4));
- if (!$element) { continue; }
- $data = explode(":",$info[$position],2);
- $value = array_pop($data);
- $results['id3v2'][$element][] = $value;
- }
+ if (!$element) { continue; }
+ $data = explode(":",$info[$position],2);
+ $value = array_pop($data);
+ $results['id3v2'][$element][] = $value;
+ }
} // end if id3v2
- return $results;
+ return $results;
} // mp3_binary_parse
/**
* set_broken
- * This fills all tag types with Unknown (Broken)
+ * This fills all tag types with Unknown (Broken)
*/
- public function set_broken() {
+ public function set_broken() {
/* Pull In the config option */
$order = Config::get('tag_order');
@@ -1133,13 +1133,13 @@ class vainfo {
$order = array($order);
}
- $key = array_shift($order);
+ $key = array_shift($order);
- $broken[$key]['title'] = '**BROKEN** ' . $this->filename;
- $broken[$key]['album'] = 'Unknown (Broken)';
- $broken[$key]['artist'] = 'Unknown (Broken)';
+ $broken[$key]['title'] = '**BROKEN** ' . $this->filename;
+ $broken[$key]['album'] = 'Unknown (Broken)';
+ $broken[$key]['artist'] = 'Unknown (Broken)';
- return $broken;
+ return $broken;
} // set_broken
diff --git a/lib/class/vauth.class.php b/lib/class/vauth.class.php
index dad3feda..cc11328f 100644
--- a/lib/class/vauth.class.php
+++ b/lib/class/vauth.class.php
@@ -96,7 +96,7 @@ class vauth {
$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');
-
+
$sql = "UPDATE `session` SET `value`='$value', `expire`='$expire' WHERE `id`='$key'";
$db_results = Dba::read($sql);
@@ -196,7 +196,7 @@ class vauth {
/**
* get_session_data
- * This takes a key and returns the raw data from the database, nothing
+ * 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) {
@@ -218,7 +218,7 @@ class vauth {
/**
* create_cookie
- * This is seperated into its own function because of some flaws in
+ * This is seperated into its own function because of some flaws in
* specific webservers *cough* IIS *cough* which prevent us from setting
* a cookie at the same time as a header redirect. As such on view of a
* login a cookie is set with the proper name
@@ -402,7 +402,7 @@ class vauth {
$sid = Dba::escape($sid);
$expire = isset($_COOKIE[Config::get('session_name') . '_remember']) ? time() + Config::get('remember_length') : time() + Config::get('session_length');
- $len = $expire - time();
+ $len = $expire - time();
$sql = "UPDATE `session` SET `expire`='$expire' WHERE `id`='$sid'";
$db_results = Dba::write($sql);
@@ -583,7 +583,7 @@ class vauth {
$results['error'] = "The PAM authentication PHP module is not installed.";
return $results;
}
-
+
if (pam_auth($username, $password, &$results['error'])) {
$results['success'] = true;
$results['type'] = 'local';
@@ -593,7 +593,7 @@ class vauth {
$results['success'] = false;
$results['error'] = "PAM login attempt failed";
}
-
+
return $results;
} // local_auth
@@ -680,7 +680,7 @@ class vauth {
* This auth method relies on HTTP auth from Apache
*/
private static function http_auth($username) {
- if (($_SERVER['REMOTE_USER'] == $username) ||
+ if (($_SERVER['REMOTE_USER'] == $username) ||
($_SERVER['HTTP_REMOTE_USER'] == $username)) {
$results['success'] = true;
$results['type'] = 'http';
diff --git a/lib/class/video.class.php b/lib/class/video.class.php
index cf36eb92..1640c6b8 100644
--- a/lib/class/video.class.php
+++ b/lib/class/video.class.php
@@ -22,26 +22,26 @@
class Video extends database_object implements media {
- public $id;
- public $title;
- public $enabled;
- public $file;
- public $size;
+ public $id;
+ public $title;
+ public $enabled;
+ public $file;
+ public $size;
/**
* Constructor
* This pulls the shoutbox information from the database and returns
* a constructed object, uses user_shout table
*/
- public function __construct($id) {
+ public function __construct($id) {
// Load the data from the database
$info = $this->get_info($id);
- foreach ($info as $key=>$value) {
- $this->$key = $value;
- }
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
- return true;
+ return true;
} // Constructor
@@ -49,18 +49,18 @@ class Video extends database_object implements media {
* build_cache
* Build a cache based on the array of ids passed, saves lots of little queries
*/
- public static function build_cache($ids=array()) {
+ public static function build_cache($ids=array()) {
- if (!is_array($ids) OR !count($ids)) { return false; }
+ if (!is_array($ids) OR !count($ids)) { return false; }
- $idlist = '(' . implode(',',$ids) . ')';
+ $idlist = '(' . implode(',',$ids) . ')';
- $sql = "SELECT * FROM `video` WHERE `video`.`id` IN $idlist";
- $db_results = Dba::read($sql);
+ $sql = "SELECT * FROM `video` WHERE `video`.`id` IN $idlist";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('video',$row['id'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('video',$row['id'],$row);
+ }
} // build_cache
@@ -68,13 +68,13 @@ class Video extends database_object implements media {
* format
* This formats a video object so that it is human readable
*/
- public function format() {
+ public function format() {
- $this->f_title = scrub_out($this->title);
- $this->f_link = scrub_out($this->title);
- $this->f_codec = $this->video_codec . ' / ' . $this->audio_codec;
- $this->f_resolution = $this->resolution_x . 'x' . $this->resolution_y;
- $this->f_tags = '';
+ $this->f_title = scrub_out($this->title);
+ $this->f_link = scrub_out($this->title);
+ $this->f_codec = $this->video_codec . ' / ' . $this->audio_codec;
+ $this->f_resolution = $this->resolution_x . 'x' . $this->resolution_y;
+ $this->f_tags = '';
$this->f_length = floor($this->time/60) . ' ' . _('minutes');
} // format
@@ -83,9 +83,9 @@ class Video extends database_object implements media {
* native_stream
* This returns true or false on the downsampling mojo
*/
- public function native_stream() {
+ public function native_stream() {
- return true;
+ return true;
} // native_stream
@@ -94,18 +94,18 @@ class Video extends database_object implements media {
* This returns a "PLAY" url for the video in question here, this currently feels a little
* like a hack, might need to adjust it in the future
*/
- public static function play_url($oid,$sid='',$force_http='') {
+ public static function play_url($oid,$sid='',$force_http='') {
- $video = new Video($oid);
+ $video = new Video($oid);
- if (!$video->id) { return false; }
+ if (!$video->id) { return false; }
- $uid = intval($GLOBALS['user']->id);
- $oid = intval($video->id);
+ $uid = intval($GLOBALS['user']->id);
+ $oid = intval($video->id);
- $url = Stream::get_base_url() . "video=true&uid=$uid&oid=$oid";
+ $url = Stream::get_base_url() . "video=true&uid=$uid&oid=$oid";
- return $url;
+ return $url;
} // play_url
@@ -115,7 +115,7 @@ class Video extends database_object implements media {
* if not it returns the transocding command from the config file
* we can't use this->type because its been formated for the downsampling
*/
- public function stream_cmd() {
+ public function stream_cmd() {
@@ -126,7 +126,7 @@ class Video extends database_object implements media {
* returns true if the video has been flagged and we shouldn't try to re-read
* the meta data
*/
- public function has_flag() {
+ public function has_flag() {
diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php
index 4e13c0a1..10690670 100644
--- a/lib/class/xmldata.class.php
+++ b/lib/class/xmldata.class.php
@@ -17,27 +17,27 @@
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.
*/
/**
* xmlData
* This class takes care of all of the xml document stuff in Ampache these
- * are all static calls
+ * are all static calls
*/
-class xmlData {
+class xmlData {
// This is added so that we don't pop any webservers
private static $limit = '5000';
- private static $offset = '0';
- private static $type = '';
+ private static $offset = '0';
+ private static $type = '';
/**
* constructor
* We don't use this, as its really a static class
*/
- private function __construct() {
+ private function __construct() {
// Rien a faire
@@ -47,10 +47,10 @@ class xmlData {
* set_offset
* This takes an int and changes the offset
*/
- public static function set_offset($offset) {
+ public static function set_offset($offset) {
- $offset = intval($offset);
- self::$offset = $offset;
+ $offset = intval($offset);
+ self::$offset = $offset;
} // set_offset
@@ -58,12 +58,12 @@ class xmlData {
* set_limit
* This sets the limit for any ampache transactions
*/
- public static function set_limit($limit) {
+ public static function set_limit($limit) {
- if (!$limit) { return false; }
+ if (!$limit) { return false; }
- $limit = intval($limit);
- self::$limit = $limit;
+ $limit = intval($limit);
+ self::$limit = $limit;
} // set_limit
@@ -71,11 +71,11 @@ class xmlData {
* set_type
* This sets the type of xmlData we are working on
*/
- public static function set_type($type) {
+ public static function set_type($type) {
- if (!in_array($type,array('rss','xspf','itunes'))) { return false; }
+ if (!in_array($type,array('rss','xspf','itunes'))) { return false; }
- self::$type = $type;
+ self::$type = $type;
} // set_type
@@ -84,10 +84,10 @@ class xmlData {
* This generates a standard XML Error message
* nothing fancy here...
*/
- public static function error($code,$string) {
-
- $string = self::_header() . "\t<error code=\"$code\"><![CDATA[$string]]></error>" . self::_footer();
- return $string;
+ public static function error($code,$string) {
+
+ $string = self::_header() . "\t<error code=\"$code\"><![CDATA[$string]]></error>" . self::_footer();
+ return $string;
} // error
@@ -95,11 +95,11 @@ class xmlData {
* single_string
* This takes two values, first the key second the string
*/
- public static function single_string($key,$string) {
+ public static function single_string($key,$string) {
- $final = self::_header() . "\t<$key><![CDATA[$string]]></$key>" . self::_footer();
+ $final = self::_header() . "\t<$key><![CDATA[$string]]></$key>" . self::_footer();
- return $final;
+ return $final;
} // single_string
@@ -107,9 +107,9 @@ class xmlData {
* header
* This returns the header
*/
- public static function header() {
+ public static function header() {
- return self::_header();
+ return self::_header();
} // header
@@ -117,56 +117,56 @@ class xmlData {
* footer
* This returns the footer
*/
- public static function footer() {
+ public static function footer() {
- return self::_footer();
+ return self::_footer();
- } // header
+ } // header
/**
* tags_string
- * This returns the formated 'tags' string for an xml document
+ * This returns the formated 'tags' string for an xml document
*/
- private static function tags_string($tags,$type,$object_id) {
+ private static function tags_string($tags,$type,$object_id) {
+
+ $string = '';
- $string = '';
+ foreach ($tags as $tag_id=>$data) {
- foreach ($tags as $tag_id=>$data) {
-
- $tag = new Tag($tag_id);
+ $tag = new Tag($tag_id);
$string .= "\t<tag id=\"" . $tag->id . "\" count=\"" . $data['count'] . "\"><![CDATA[$tag->name]]></tag>\n";
- }
+ }
- return $string;
+ return $string;
} // tags_string
/**
* keyed_array
- * This will build an xml document from a key'd array,
+ * This will build an xml document from a key'd array,
*/
- public static function keyed_array($array,$callback='') {
+ public static function keyed_array($array,$callback='') {
- $string = '';
+ $string = '';
// Foreach it
- foreach ($array as $key=>$value) {
+ foreach ($array as $key=>$value) {
// If it's an array, run again
- if (is_array($value)) {
- $value = self::keyed_array($value,1);
- $string .= "<$key>\n$value\n</$key>\n";
- }
- else {
- $string .= "\t<$key><![CDATA[$value]]></$key>\n";
- }
+ if (is_array($value)) {
+ $value = self::keyed_array($value,1);
+ $string .= "<$key>\n$value\n</$key>\n";
+ }
+ else {
+ $string .= "\t<$key><![CDATA[$value]]></$key>\n";
+ }
- } // end foreach
+ } // end foreach
- if (!$callback) {
- $string = self::_header() . $string . self::_footer();
- }
+ if (!$callback) {
+ $string = self::_header() . $string . self::_footer();
+ }
- return $string;
+ return $string;
} // keyed_array
@@ -174,69 +174,69 @@ class xmlData {
* tags
* This returns tags to the user, in a pretty xml document with the information
*/
- public static function tags($tags) {
-
- if (count($tags) > self::$limit OR self::$offset > 0) {
- $tags = array_splice($tags,self::$offset,self::$limit);
- }
-
- $string = '';
-
- foreach ($tags as $tag_id) {
- $tag = new Tag($tag_id);
- $counts = $tag->count();
- $string .= "<tag id=\"$tag_id\">\n" .
- "\t<name><![CDATA[$tag->name]]></name>\n" .
- "\t<albums>" . intval($counts['album']) . "</albums>\n" .
- "\t<artists>" . intval($counts['artist']) . "</artists>\n" .
- "\t<songs>" . intval($counts['song']) . "</songs>\n" .
- "\t<videos>" . intval($counts['video']) . "</videos>\n" .
- "\t<playlists>" . intval($count['playlist']) . "</playlists>\n" .
- "\t<stream>" . intval($count['live_stream']) . "</stream>\n" .
- "</tag>\n";
- } // end foreach
-
- $final = self::_header() . $string . self::_footer();
-
- return $final;
+ public static function tags($tags) {
+
+ if (count($tags) > self::$limit OR self::$offset > 0) {
+ $tags = array_splice($tags,self::$offset,self::$limit);
+ }
+
+ $string = '';
+
+ foreach ($tags as $tag_id) {
+ $tag = new Tag($tag_id);
+ $counts = $tag->count();
+ $string .= "<tag id=\"$tag_id\">\n" .
+ "\t<name><![CDATA[$tag->name]]></name>\n" .
+ "\t<albums>" . intval($counts['album']) . "</albums>\n" .
+ "\t<artists>" . intval($counts['artist']) . "</artists>\n" .
+ "\t<songs>" . intval($counts['song']) . "</songs>\n" .
+ "\t<videos>" . intval($counts['video']) . "</videos>\n" .
+ "\t<playlists>" . intval($count['playlist']) . "</playlists>\n" .
+ "\t<stream>" . intval($count['live_stream']) . "</stream>\n" .
+ "</tag>\n";
+ } // end foreach
+
+ $final = self::_header() . $string . self::_footer();
+
+ return $final;
} // tags
/**
* artists
- * This takes an array of artists and then returns a pretty xml document with the information
- * we want
+ * This takes an array of artists and then returns a pretty xml document with the information
+ * we want
*/
- public static function artists($artists) {
+ public static function artists($artists) {
- if (count($artists) > self::$limit OR self::$offset > 0) {
- $artists = array_splice($artists,self::$offset,self::$limit);
- }
+ if (count($artists) > self::$limit OR self::$offset > 0) {
+ $artists = array_splice($artists,self::$offset,self::$limit);
+ }
+
+ $string = '';
- $string = '';
-
- Rating::build_cache('artist',$artists);
+ Rating::build_cache('artist',$artists);
- foreach ($artists as $artist_id) {
- $artist = new Artist($artist_id);
- $artist->format();
+ foreach ($artists as $artist_id) {
+ $artist = new Artist($artist_id);
+ $artist->format();
- $rating = new Rating($artist_id,'artist');
- $tag_string = self::tags_string($artist->tags,'artist',$artist->id);
+ $rating = new Rating($artist_id,'artist');
+ $tag_string = self::tags_string($artist->tags,'artist',$artist->id);
- $string .= "<artist id=\"$artist->id\">\n" .
- "\t<name><![CDATA[$artist->f_full_name]]></name>\n" .
- $tag_string .
- "\t<albums>$artist->albums</albums>\n" .
- "\t<songs>$artist->songs</songs>\n" .
+ $string .= "<artist id=\"$artist->id\">\n" .
+ "\t<name><![CDATA[$artist->f_full_name]]></name>\n" .
+ $tag_string .
+ "\t<albums>$artist->albums</albums>\n" .
+ "\t<songs>$artist->songs</songs>\n" .
"\t<preciserating>" . $rating->preciserating . "</preciserating>\n" .
"\t<rating>" . $rating->rating . "</rating>\n" .
- "</artist>\n";
+ "</artist>\n";
} // end foreach artists
- $final = self::_header() . $string . self::_footer();
+ $final = self::_header() . $string . self::_footer();
- return $final;
+ return $final;
} // artists
@@ -244,47 +244,47 @@ class xmlData {
* albums
* This echos out a standard albums XML document, it pays attention to the limit
*/
- public static function albums($albums) {
+ public static function albums($albums) {
- if (count($albums) > self::$limit OR self::$offset > 0) {
- $albums = array_splice($albums,self::$offset,self::$limit);
- }
-
- Rating::build_cache('album',$albums);
+ if (count($albums) > self::$limit OR self::$offset > 0) {
+ $albums = array_splice($albums,self::$offset,self::$limit);
+ }
+
+ Rating::build_cache('album',$albums);
- foreach ($albums as $album_id) {
- $album = new Album($album_id);
- $album->format();
+ foreach ($albums as $album_id) {
+ $album = new Album($album_id);
+ $album->format();
- $rating = new Rating($album_id,'album');
+ $rating = new Rating($album_id,'album');
- // Build the Art URL, include session
- $art_url = Config::get('web_path') . '/image.php?id=' . $album->id . '&auth=' . scrub_out($_REQUEST['auth']);
+ // Build the Art URL, include session
+ $art_url = Config::get('web_path') . '/image.php?id=' . $album->id . '&auth=' . scrub_out($_REQUEST['auth']);
- $string .= "<album id=\"$album->id\">\n" .
- "\t<name><![CDATA[$album->name]]></name>\n";
+ $string .= "<album id=\"$album->id\">\n" .
+ "\t<name><![CDATA[$album->name]]></name>\n";
// Do a little check for artist stuff
- if ($album->artist_count != 1) {
- $string .= "\t<artist id=\"0\"><![CDATA[Various]]></artist>\n";
- }
- else {
- $string .= "\t<artist id=\"$album->artist_id\"><![CDATA[$album->artist_name]]></artist>\n";
- }
-
- $string .= "\t<year>$album->year</year>\n" .
- "\t<tracks>$album->song_count</tracks>\n" .
- "\t<disk>$album->disk</disk>\n" .
- self::tags_string($album->tags,'album',$album->id) .
- "\t<art><![CDATA[$art_url]]></art>\n" .
+ if ($album->artist_count != 1) {
+ $string .= "\t<artist id=\"0\"><![CDATA[Various]]></artist>\n";
+ }
+ else {
+ $string .= "\t<artist id=\"$album->artist_id\"><![CDATA[$album->artist_name]]></artist>\n";
+ }
+
+ $string .= "\t<year>$album->year</year>\n" .
+ "\t<tracks>$album->song_count</tracks>\n" .
+ "\t<disk>$album->disk</disk>\n" .
+ self::tags_string($album->tags,'album',$album->id) .
+ "\t<art><![CDATA[$art_url]]></art>\n" .
"\t<preciserating>" . $rating->preciserating . "</preciserating>\n" .
"\t<rating>" . $rating->rating . "</rating>\n" .
- "</album>\n";
+ "</album>\n";
} // end foreach
- $final = self::_header() . $string . self::_footer();
+ $final = self::_header() . $string . self::_footer();
- return $final;
+ return $final;
} // albums
@@ -292,33 +292,33 @@ class xmlData {
* playlists
* This takes an array of playlist ids and then returns a nice pretty XML document
*/
- public static function playlists($playlists) {
+ public static function playlists($playlists) {
- if (count($playlists) > self::$limit OR self::$offset > 0) {
- $playlists = array_slice($playlists,self::$offset,self::$limit);
- }
+ if (count($playlists) > self::$limit OR self::$offset > 0) {
+ $playlists = array_slice($playlists,self::$offset,self::$limit);
+ }
- $string = '';
+ $string = '';
// Foreach the playlist ids
- foreach ($playlists as $playlist_id) {
- $playlist = new Playlist($playlist_id);
- $playlist->format();
- $item_total = $playlist->get_song_count();
+ foreach ($playlists as $playlist_id) {
+ $playlist = new Playlist($playlist_id);
+ $playlist->format();
+ $item_total = $playlist->get_song_count();
// Build this element
- $string .= "<playlist id=\"$playlist->id\">\n" .
- "\t<name><![CDATA[$playlist->name]]></name>\n" .
- "\t<owner><![CDATA[$playlist->f_user]]></owner>\n" .
- "\t<items>$item_total</items>\n" .
- "\t<type>$playlist->type</type>\n" .
+ $string .= "<playlist id=\"$playlist->id\">\n" .
+ "\t<name><![CDATA[$playlist->name]]></name>\n" .
+ "\t<owner><![CDATA[$playlist->f_user]]></owner>\n" .
+ "\t<items>$item_total</items>\n" .
+ "\t<type>$playlist->type</type>\n" .
"</playlist>\n";
-
+
} // end foreach
- // Build the final and then send her off
- $final = self::_header() . $string . self::_footer();
+ // Build the final and then send her off
+ $final = self::_header() . $string . self::_footer();
return $final;
@@ -328,54 +328,54 @@ class xmlData {
* songs
* This returns an xml document from an array of song ids spiffy isn't it!
*/
- public static function songs($songs) {
+ public static function songs($songs) {
- if (count($songs) > self::$limit OR self::$offset > 0) {
- $songs = array_slice($songs,self::$offset,self::$limit);
- }
+ if (count($songs) > self::$limit OR self::$offset > 0) {
+ $songs = array_slice($songs,self::$offset,self::$limit);
+ }
- Rating::build_cache('song',$songs);
- Stream::set_session($_REQUEST['auth']);
+ Rating::build_cache('song',$songs);
+ Stream::set_session($_REQUEST['auth']);
// Foreach the ids!
- foreach ($songs as $song_id) {
- $song = new Song($song_id);
+ foreach ($songs as $song_id) {
+ $song = new Song($song_id);
// If the song id is invalid/null
- if (!$song->id) { continue; }
- $song->format();
+ if (!$song->id) { continue; }
+ $song->format();
- $tag_string = '';
+ $tag_string = '';
- $tag = new Tag($song->tags['0']);
+ $tag = new Tag($song->tags['0']);
$song->genre = $tag->id;
- $song->f_genre = $tag->name;
-
- $tag_string = self::tags_string($song->tags,'song',$song->id);
-
- $rating = new Rating($song_id,'song');
-
- $art_url = Album::get_art_url($song->album,$_REQUEST['auth']);
-
- $string .= "<song id=\"$song->id\">\n" .
- "\t<title><![CDATA[$song->title]]></title>\n" .
- "\t<artist id=\"$song->artist\"><![CDATA[$song->f_artist_full]]></artist>\n" .
- "\t<album id=\"$song->album\"><![CDATA[$song->f_album_full]]></album>\n" .
- "\t<genre id=\"$song->genre\"><![CDATA[$song->f_genre]]></genre>\n" .
- $tag_string .
- "\t<track>$song->track</track>\n" .
- "\t<time>$song->time</time>\n" .
- "\t<mime>$song->mime</mime>\n" .
- "\t<url><![CDATA[" . Song::play_url($song->id) . "]]></url>\n" .
- "\t<size>$song->size</size>\n" .
- "\t<art><![CDATA[" . $art_url . "]]></art>\n" .
- "\t<preciserating>" . $rating->preciserating . "</preciserating>\n" .
- "\t<rating>" . $rating->rating . "</rating>\n" .
- "</song>\n";
+ $song->f_genre = $tag->name;
+
+ $tag_string = self::tags_string($song->tags,'song',$song->id);
+
+ $rating = new Rating($song_id,'song');
+
+ $art_url = Album::get_art_url($song->album,$_REQUEST['auth']);
+
+ $string .= "<song id=\"$song->id\">\n" .
+ "\t<title><![CDATA[$song->title]]></title>\n" .
+ "\t<artist id=\"$song->artist\"><![CDATA[$song->f_artist_full]]></artist>\n" .
+ "\t<album id=\"$song->album\"><![CDATA[$song->f_album_full]]></album>\n" .
+ "\t<genre id=\"$song->genre\"><![CDATA[$song->f_genre]]></genre>\n" .
+ $tag_string .
+ "\t<track>$song->track</track>\n" .
+ "\t<time>$song->time</time>\n" .
+ "\t<mime>$song->mime</mime>\n" .
+ "\t<url><![CDATA[" . Song::play_url($song->id) . "]]></url>\n" .
+ "\t<size>$song->size</size>\n" .
+ "\t<art><![CDATA[" . $art_url . "]]></art>\n" .
+ "\t<preciserating>" . $rating->preciserating . "</preciserating>\n" .
+ "\t<rating>" . $rating->rating . "</rating>\n" .
+ "</song>\n";
} // end foreach
- $final = self::_header() . $string . self::_footer();
+ $final = self::_header() . $string . self::_footer();
return $final;
@@ -385,32 +385,32 @@ class xmlData {
* videos
* This builds the xml document for displaying video objects
*/
- public static function videos($videos) {
+ public static function videos($videos) {
if (count($videos) > self::$limit OR self::$offset > 0) {
$videos = array_slice($videos,self::$offset,self::$limit);
}
- $string = '';
+ $string = '';
- foreach ($videos as $video_id) {
- $video = new Video($video_id);
- $video->format();
+ foreach ($videos as $video_id) {
+ $video = new Video($video_id);
+ $video->format();
- $string .= "<video id=\"$video->id\">\n" .
- "\t<title><![CDATA[$video->title]]></title>\n" .
- "\t<mime><![CDATA[$video->mime]]></mime>\n" .
+ $string .= "<video id=\"$video->id\">\n" .
+ "\t<title><![CDATA[$video->title]]></title>\n" .
+ "\t<mime><![CDATA[$video->mime]]></mime>\n" .
"\t<resolution>$video->f_resolution</resolution>\n" .
- "\t<size>$video->size</size>\n" .
- self::tags_string($video->tags,'video',$video->id) .
+ "\t<size>$video->size</size>\n" .
+ self::tags_string($video->tags,'video',$video->id) .
"\t<url><![CDATA[" . Video::play_url($video->id) . "]]></url>\n" .
"</video>\n";
- } // end foreach
+ } // end foreach
- $final = self::_header() . $string . self::_footer();
+ $final = self::_header() . $string . self::_footer();
- return $final;
+ return $final;
} // videos
@@ -420,17 +420,17 @@ class xmlData {
* This handles creating an xml document for democratic items, this can be a little complicated
* due to the votes and all of that
*/
- public static function democratic($object_ids=array()) {
+ public static function democratic($object_ids=array()) {
- if (!is_array($object_ids)) { $object_ids = array(); }
+ if (!is_array($object_ids)) { $object_ids = array(); }
$democratic = Democratic::get_current_playlist();
-
- $string = '';
- foreach ($object_ids as $row_id=>$data) {
- $song = new $data['object_type']($data['object_id']);
- $song->format();
+ $string = '';
+
+ foreach ($object_ids as $row_id=>$data) {
+ $song = new $data['object_type']($data['object_id']);
+ $song->format();
//FIXME: This is duplicate code and so wrong, functions need to be improved
$tag_string = '';
@@ -455,38 +455,38 @@ class xmlData {
"\t<time>$song->time</time>\n" .
"\t<mime>$song->mime</mime>\n" .
"\t<url><![CDATA[" . Song::play_url($song->id) . "]]></url>\n" .
- "\t<size>$song->size</size>\n" .
- "\t<art><![CDATA[" . $art_url . "]]></art>\n" .
+ "\t<size>$song->size</size>\n" .
+ "\t<art><![CDATA[" . $art_url . "]]></art>\n" .
"\t<preciserating>" . $rating->preciserating . "</preciserating>\n" .
"\t<rating>" . $rating->rating . "</rating>\n" .
- "\t<vote>" . $democratic->get_vote($row_id) . "</vote>\n" .
- "</song>\n";
-
- } // end foreach
-
- $final = self::_header() . $string . self::_footer();
+ "\t<vote>" . $democratic->get_vote($row_id) . "</vote>\n" .
+ "</song>\n";
- return $final;
+ } // end foreach
+
+ $final = self::_header() . $string . self::_footer();
+
+ return $final;
} // democratic
/**
* rss_feed
*/
- public static function rss_feed($data,$title,$description,$date) {
+ public static function rss_feed($data,$title,$description,$date) {
- $string = "\t<title>$title</title>\n\t<link>" . Config::get('web_path') . "</link>\n\t" .
- "<pubDate>" . date("r",$date) . "</pubDate>\n";
+ $string = "\t<title>$title</title>\n\t<link>" . Config::get('web_path') . "</link>\n\t" .
+ "<pubDate>" . date("r",$date) . "</pubDate>\n";
// Pass it to the keyed array xml function
- foreach ($data as $item) {
+ foreach ($data as $item) {
// We need to enclose it in an item tag
- $string .= self::keyed_array(array('item'=>$item),1);
- }
+ $string .= self::keyed_array(array('item'=>$item),1);
+ }
- $final = self::_header() . $string . self::_footer();
+ $final = self::_header() . $string . self::_footer();
- return $final;
+ return $final;
} // rss_feed
@@ -495,10 +495,10 @@ class xmlData {
* this returns a standard header, there are a few types
* so we allow them to pass a type if they want to
*/
- private static function _header() {
+ private static function _header() {
- switch (self::$type) {
- case 'xspf':
+ switch (self::$type) {
+ case 'xspf':
$header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" .
"<playlist version = \"1\" xmlns=\"http://xspf.org/ns/0/\">\n " .
"<title>Ampache XSPF Playlist</title>\n" .
@@ -506,7 +506,7 @@ class xmlData {
"<annotation>" . scrub_out(Config::get('site_title')) . "</annotation>\n" .
"<info>". Config::get('web_path') ."</info>\n" .
"<trackList>\n";
- break;
+ break;
case 'itunes':
$header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
"<!-- XML Generated by Ampache v." . Config::get('version') . " -->\n";
@@ -520,19 +520,19 @@ class xmlData {
" <key>Features</key><integer>1</integer>\n" .
" <key>Show Content Ratings</key><true/>\n" .
" <key>Tracks</key>\n" .
- " <dict>\n";
- break;
- case 'rss':
- $header = "<?xml version=\"1.0\" encoding=\"" . Config::get('site_charset') . "\" ?>\n " .
- "<!-- RSS Generated by Ampache v." . Config::get('version') . " on " . date("r",time()) . "-->\n" .
- "<rss version=\"2.0\">\n<channel>\n";
- break;
- default:
+ " <dict>\n";
+ break;
+ case 'rss':
+ $header = "<?xml version=\"1.0\" encoding=\"" . Config::get('site_charset') . "\" ?>\n " .
+ "<!-- RSS Generated by Ampache v." . Config::get('version') . " on " . date("r",time()) . "-->\n" .
+ "<rss version=\"2.0\">\n<channel>\n";
+ break;
+ default:
$header = "<?xml version=\"1.0\" encoding=\"" . Config::get('site_charset') . "\" ?>\n<root>\n";
- break;
- } // end switch
+ break;
+ } // end switch
- return $header;
+ return $header;
} // _header
@@ -540,25 +540,25 @@ class xmlData {
* _footer
* this returns the footer for this document, these are pretty boring
*/
- private static function _footer() {
+ private static function _footer() {
- switch (self::$type) {
- case 'itunes':
+ switch (self::$type) {
+ case 'itunes':
$footer = "\t\t</dict>\t\n</dict>\n</plist>\n";
- break;
- case 'xspf':
- $footer = "</trackList>\n</playlist>\n";
- break;
- case 'rss':
- $footer = "\n</channel>\n</rss>\n";
- break;
- default:
- $footer = "\n</root>\n";
- break;
- } // end switch on type
-
-
- return $footer;
+ break;
+ case 'xspf':
+ $footer = "</trackList>\n</playlist>\n";
+ break;
+ case 'rss':
+ $footer = "\n</channel>\n</rss>\n";
+ break;
+ default:
+ $footer = "\n</root>\n";
+ break;
+ } // end switch on type
+
+
+ return $footer;
} // _footer
diff --git a/lib/gettext.php b/lib/gettext.php
index d5e828f5..6c88b057 100644
--- a/lib/gettext.php
+++ b/lib/gettext.php
@@ -24,14 +24,14 @@
@function load_gettext
@discussion sets the local
*/
-function load_gettext() {
+function load_gettext() {
/* If we have gettext */
- if (function_exists('bindtextdomain')) {
+ if (function_exists('bindtextdomain')) {
$lang = Config::get('lang');
putenv("LANG=" . $lang);
putenv("LANGUAGE=" . $lang);
/* Try lang, lang + charset and lang + utf-8 */
- setlocale(LC_ALL,
+ setlocale(LC_ALL,
$lang,
$lang . '.UTF-8', //. Config::get('site_charset'),
$lang . '.UTF-8',
@@ -41,7 +41,7 @@ function load_gettext() {
/* Bind the Text Domain */
bindtextdomain('messages', Config::get('prefix') . "/locale/");
textdomain('messages');
- if (function_exists('bind_textdomain_codeset')) {
+ if (function_exists('bind_textdomain_codeset')) {
bind_textdomain_codeset('messages',Config::get('site_charset'));
} // if we can codeset the textdomain
diff --git a/lib/init.php b/lib/init.php
index 9adc0e86..7dddb533 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -21,16 +21,16 @@
*/
// SVN Fluf
-$svn_version = 'Subversion ' . trim('$Rev$','$ ');
+$svn_version = 'Subversion ' . trim('$Rev$','$ ');
-// Use output buffering, this gains us a few things and
+// Use output buffering, this gains us a few things and
// fixes some CSS issues
ob_start();
// Do a check for PHP5 because nothing will work without it
if (floatval(phpversion()) < 5) {
echo "ERROR: Ampache requires PHP5";
- exit;
+ exit;
}
error_reporting(E_ERROR); // Only show fatal errors in production
@@ -41,7 +41,7 @@ $ampache_path = dirname(__FILE__);
$prefix = realpath($ampache_path . "/../");
$configfile = "$prefix/config/ampache.cfg.php";
require_once $prefix . '/lib/general.lib.php';
-require_once $prefix . '/lib/class/config.class.php';
+require_once $prefix . '/lib/class/config.class.php';
require_once $prefix . '/lib/class/vauth.class.php'; // Fixes synology bug with __autoload in certain cases
if (!function_exists('gettext')) {
@@ -49,15 +49,15 @@ if (!function_exists('gettext')) {
}
// Define some base level config options
-Config::set('prefix',$prefix);
+Config::set('prefix',$prefix);
/*
Check to see if this is Http or https
*/
-if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
+if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$http_type = "https://";
}
-else {
+else {
$http_type = "http://";
}
@@ -66,51 +66,51 @@ else {
then go ahead and move them over to the install
script
*/
-if (!file_exists($configfile)) {
+if (!file_exists($configfile)) {
$path = preg_replace("/(.*)\/(\w+\.php)$/","\${1}", $_SERVER['PHP_SELF']);
$link = $http_type . $_SERVER['HTTP_HOST'] . $path . "/install.php";
header ("Location: $link");
exit();
}
-// Use the built in PHP function, supress errors here so we can handle it properly
-$results = @parse_ini_file($configfile);
+// Use the built in PHP function, supress errors here so we can handle it properly
+$results = @parse_ini_file($configfile);
-if (!count($results)) {
+if (!count($results)) {
$path = preg_replace("/(.*)\/(\w+\.php)$/","\${1}", $_SERVER['PHP_SELF']);
$link = $http_type . $_SERVER['HTTP_HOST'] . $path . "/test.php?action=config";
header ("Location: $link");
exit();
-}
+}
/** Verify a few commonly removed PHP functions exist and re-direct to /test if not **/
-if (!function_exists('hash') OR !function_exists('inet_pton') OR (strtoupper(substr(PHP_OS,0,3)) == 'WIN' AND floatval(phpversion()) < 5.3)) {
+if (!function_exists('hash') OR !function_exists('inet_pton') OR (strtoupper(substr(PHP_OS,0,3)) == 'WIN' AND floatval(phpversion()) < 5.3)) {
$path = preg_replace("/(.*)\/(\w+\.php)$/","\${1}", $_SERVER['PHP_SELF']);
$link = $http_type . $_SERVER['HTTP_HOST'] . $path . "/test.php";
- header ("Location: $link");
- exit();
-}
+ header ("Location: $link");
+ exit();
+}
/** This is the version.... fluf nothing more... **/
-$results['version'] = '3.6-Alpha1 '. $svn_version;
-$results['int_config_version'] = '10';
+$results['version'] = '3.6-Alpha1 '. $svn_version;
+$results['int_config_version'] = '10';
$results['raw_web_path'] = $results['web_path'];
$results['web_path'] = $http_type . $_SERVER['HTTP_HOST'] . $results['web_path'];
$results['http_port'] = $_SERVER['SERVER_PORT'];
-if (!$results['http_port']) {
+if (!$results['http_port']) {
$results['http_port'] = '80';
-}
-if (!$results['site_charset']) {
+}
+if (!$results['site_charset']) {
$results['site_charset'] = "UTF-8";
}
-if (!$results['raw_web_path']) {
+if (!$results['raw_web_path']) {
$results['raw_web_path'] = '/';
}
-if (!$_SERVER['SERVER_NAME']) {
+if (!$_SERVER['SERVER_NAME']) {
$_SERVER['SERVER_NAME'] = '';
}
-if (isset($results['user_ip_cardinality']) && !$results['user_ip_cardinality']) {
+if (isset($results['user_ip_cardinality']) && !$results['user_ip_cardinality']) {
$results['user_ip_cardinality'] = 42;
}
@@ -136,8 +136,8 @@ require_once $prefix . '/lib/gettext.php';
require_once $prefix . '/lib/batch.lib.php';
require_once $prefix . '/lib/themes.php';
require_once $prefix . '/lib/class/localplay.abstract.php';
-require_once $prefix . '/lib/class/database_object.abstract.php';
-require_once $prefix . '/lib/class/media.interface.php';
+require_once $prefix . '/lib/class/database_object.abstract.php';
+require_once $prefix . '/lib/class/media.interface.php';
require_once $prefix . '/modules/getid3/getid3.php';
require_once $prefix . '/modules/nusoap/nusoap.php';
require_once $prefix . '/modules/phpmailer/class.phpmailer.php';
@@ -154,7 +154,7 @@ $results = Preference::fix_preferences($results);
Config::set_by_array($results,1);
// Modules (These are conditionaly included depending upon config values)
-if (Config::get('ratings')) {
+if (Config::get('ratings')) {
require_once $prefix . '/lib/class/rating.class.php';
require_once $prefix . '/lib/rating.lib.php';
}
@@ -164,84 +164,84 @@ $old_error_handler = set_error_handler('ampache_error_handler');
/* Check their PHP Vars to make sure we're cool here */
$post_size = @ini_get('post_max_size');
-if (substr($post_size,strlen($post_size)-1,strlen($post_size)) != 'M') {
+if (substr($post_size,strlen($post_size)-1,strlen($post_size)) != 'M') {
/* Sane value time */
ini_set('post_max_size','8M');
}
-if ($results['memory_limit'] < 24) {
+if ($results['memory_limit'] < 24) {
$results['memory_limit'] = 24;
}
-// Incase the local setting is 0
-ini_set('session.gc_probability','2');
+// Incase the local setting is 0
+ini_set('session.gc_probability','2');
set_memory_limit($results['memory_limit']);
/**** END Set PHP Vars ****/
// If we want a session
-if (NO_SESSION != '1' AND Config::get('use_auth')) {
+if (NO_SESSION != '1' AND Config::get('use_auth')) {
/* Verify Their session */
- if (!vauth::session_exists('interface',$_COOKIE[Config::get('session_name')])) { vauth::logout($_COOKIE[Config::get('session_name')]); exit; }
-
+ if (!vauth::session_exists('interface',$_COOKIE[Config::get('session_name')])) { vauth::logout($_COOKIE[Config::get('session_name')]); exit; }
+
// This actually is starting the session
vauth::check_session();
/* Create the new user */
$GLOBALS['user'] = User::get_from_username($_SESSION['userdata']['username']);
-
+
/* If they user ID doesn't exist deny them */
- if (!$GLOBALS['user']->id AND !Config::get('demo_mode')) { vauth::logout(session_id()); exit; }
+ if (!$GLOBALS['user']->id AND !Config::get('demo_mode')) { vauth::logout(session_id()); exit; }
- vauth::session_extend(session_id());
+ vauth::session_extend(session_id());
/* Load preferences and theme */
$GLOBALS['user']->update_last_seen();
}
-elseif (!Config::get('use_auth')) {
+elseif (!Config::get('use_auth')) {
$auth['success'] = 1;
$auth['username'] = '-1';
$auth['fullname'] = "Ampache User";
$auth['id'] = -1;
$auth['offset_limit'] = 50;
- $auth['access'] = Config::get('default_auth_level') ? User::access_name_to_level(Config::get('default_auth_level')) : '100';
- if (!vauth::session_exists('interface',$_COOKIE[Config::get('session_name')])) {
- vauth::create_cookie();
- vauth::session_create($auth);
- vauth::check_session();
- $GLOBALS['user'] = new User($auth['username']);
- $GLOBALS['user']->username = $auth['username'];
- $GLOBALS['user']->fullname = $auth['fullname'];
- $GLOBALS['user']->access = $auth['access'];
+ $auth['access'] = Config::get('default_auth_level') ? User::access_name_to_level(Config::get('default_auth_level')) : '100';
+ if (!vauth::session_exists('interface',$_COOKIE[Config::get('session_name')])) {
+ vauth::create_cookie();
+ vauth::session_create($auth);
+ vauth::check_session();
+ $GLOBALS['user'] = new User($auth['username']);
+ $GLOBALS['user']->username = $auth['username'];
+ $GLOBALS['user']->fullname = $auth['fullname'];
+ $GLOBALS['user']->access = $auth['access'];
}
- else {
- vauth::check_session();
- if ($_SESSION['userdata']['username']) {
+ else {
+ vauth::check_session();
+ if ($_SESSION['userdata']['username']) {
$GLOBALS['user'] = User::get_from_username($_SESSION['userdata']['username']);
- }
- else {
- $GLOBALS['user'] = new User($auth['username']);
- $GLOBALS['user']->id = '-1';
- $GLOBALS['user']->username = $auth['username'];
- $GLOBALS['user']->fullname = $auth['fullname'];
- $GLOBALS['user']->access = $auth['access'];
- }
+ }
+ else {
+ $GLOBALS['user'] = new User($auth['username']);
+ $GLOBALS['user']->id = '-1';
+ $GLOBALS['user']->username = $auth['username'];
+ $GLOBALS['user']->fullname = $auth['fullname'];
+ $GLOBALS['user']->access = $auth['access'];
+ }
if (!$GLOBALS['user']->id AND !Config::get('demo_mode')) { vauth::logout(session_id()); exit; }
$GLOBALS['user']->update_last_seen();
- }
+ }
}
// If Auth, but no session is set
-else {
- if (isset($_REQUEST['sid'])) {
- session_name(Config::get('session_name'));
+else {
+ if (isset($_REQUEST['sid'])) {
+ session_name(Config::get('session_name'));
session_id(scrub_in($_REQUEST['sid']));
session_start();
$GLOBALS['user'] = User::get_from_username($_SESSION['userdata']['username']);
}
- else {
- $GLOBALS['user'] = new User();
- }
+ else {
+ $GLOBALS['user'] = new User();
+ }
} // If NO_SESSION passed
@@ -249,9 +249,9 @@ else {
Preference::init();
// We need to create the tmp playlist for our user only if we have a session
-if (session_id()) {
- $GLOBALS['user']->load_playlist();
-}
+if (session_id()) {
+ $GLOBALS['user']->load_playlist();
+}
/* Add in some variables for ajax done here because we need the user */
Config::set('ajax_url',Config::get('web_path') . '/server/ajax.server.php',1);
@@ -267,7 +267,7 @@ unset($array);
unset($results);
/* Setup the flip class */
-flip_class(array('odd','even'));
+flip_class(array('odd','even'));
/* Check to see if we need to perform an update */
if (!preg_match('/update\.php/', $_SERVER['PHP_SELF'])) {
@@ -277,14 +277,14 @@ if (!preg_match('/update\.php/', $_SERVER['PHP_SELF'])) {
}
}
// For the XMLRPC stuff
-$GLOBALS['xmlrpc_internalencoding'] = Config::get('site_charset');
+$GLOBALS['xmlrpc_internalencoding'] = Config::get('site_charset');
// If debug is on GIMMIE DA ERRORS
if (Config::get('debug')) {
error_reporting(E_ALL);
}
-// Merge GET then POST into REQUEST effectivly striping COOKIE without depending on
+// Merge GET then POST into REQUEST effectivly striping COOKIE without depending on
// a PHP setting change to take affect
-$_REQUEST = array_merge($_GET,$_POST);
+$_REQUEST = array_merge($_GET,$_POST);
?>
diff --git a/lib/install.php b/lib/install.php
index a851aecd..655bb25d 100644
--- a/lib/install.php
+++ b/lib/install.php
@@ -170,14 +170,14 @@ function install_insert_db($username,$password,$hostname,$database,$dbuser=false
/* Check and see if we should create a user here */
if ($_POST['db_user'] == 'create_db_user' || (strlen($dbuser) AND strlen($dbpass))) {
-
- $db_user = $_POST['db_username'] ? scrub_in($_POST['db_username']) : $dbuser;
- $db_pass = $_POST['db_password'] ? scrub_in($_POST['db_password']) : $dbpass;
- if (!strlen($db_user) || !strlen($db_pass)) {
- Error::add('general','Error: Ampache SQL Username or Password missing');
- return false;
- }
+ $db_user = $_POST['db_username'] ? scrub_in($_POST['db_username']) : $dbuser;
+ $db_pass = $_POST['db_password'] ? scrub_in($_POST['db_password']) : $dbpass;
+
+ if (!strlen($db_user) || !strlen($db_pass)) {
+ Error::add('general','Error: Ampache SQL Username or Password missing');
+ return false;
+ }
$sql = "GRANT ALL PRIVILEGES ON " . Dba::escape($database) . ".* TO " .
"'" . Dba::escape($db_user) . "'@'" . Dba::escape($hostname) . "' IDENTIFIED BY '" . Dba::escape($db_pass) . "' WITH GRANT OPTION";
@@ -235,14 +235,14 @@ function install_insert_db($username,$password,$hostname,$database,$dbuser=false
*/
function install_create_config($web_path,$username,$password,$hostname,$database) {
- $config_file = Config::get('prefix') . '/config/ampache.cfg.php';
+ $config_file = Config::get('prefix') . '/config/ampache.cfg.php';
// Make sure the directory is writeable OR the empty config file is
- if (!is_writeable(Config::get('prefix') . '/config/') AND !is_writeable($config_file)) {
+ if (!is_writeable(Config::get('prefix') . '/config/') AND !is_writeable($config_file)) {
/* HINT: Config File */
- Error::add('general',sprintf(_('%s is not writeable'),$config_file));
- return false;
- }
+ Error::add('general',sprintf(_('%s is not writeable'),$config_file));
+ return false;
+ }
$data['database_username'] = $username;
$data['database_password'] = $password;
@@ -272,14 +272,14 @@ function install_create_config($web_path,$username,$password,$hostname,$database
$final = generate_config($data);
// Open the file and try to write it
- $fhandle = fopen($config_file,'w');
- if (!fwrite($fhandle,$final)) {
- Error::add('general',"Error Writing config file");
- fclose ($fhandle);
- return false;
- }
- fclose ($fhandle);
-
+ $fhandle = fopen($config_file,'w');
+ if (!fwrite($fhandle,$final)) {
+ Error::add('general',"Error Writing config file");
+ fclose ($fhandle);
+ return false;
+ }
+ fclose ($fhandle);
+
return true;
diff --git a/lib/log.lib.php b/lib/log.lib.php
index 5be7e780..0b3e3587 100644
--- a/lib/log.lib.php
+++ b/lib/log.lib.php
@@ -25,21 +25,21 @@
@discussion logs an event either to a database
or to a defined log file based on config options
*/
-function log_event($username='Unknown',$event_name,$event_description,$log_name='ampache') {
+function log_event($username='Unknown',$event_name,$event_description,$log_name='ampache') {
/* Set it up here to make sure it's _always_ the same */
$log_time = time();
/* must have some name */
- if (!strlen($log_name)) { $log_name = 'ampache'; }
+ if (!strlen($log_name)) { $log_name = 'ampache'; }
- $username = $username ? $username : 'ampache';
+ $username = $username ? $username : 'ampache';
$log_filename = Config::get('log_path') . "/$log_name." . date("Ymd",$log_time) . ".log";
- $log_line = date("Y-m-d H:i:s",$log_time) . " [$username] ($event_name) -> $event_description \n";
+ $log_line = date("Y-m-d H:i:s",$log_time) . " [$username] ($event_name) -> $event_description \n";
$log_write = error_log($log_line, 3, $log_filename);
-
- if (!$log_write) {
+
+ if (!$log_write) {
echo "Warning: Unable to write to log ($log_filename) Please check your log_path variable in ampache.cfg.php";
}
@@ -50,12 +50,12 @@ function log_event($username='Unknown',$event_name,$event_description,$log_name=
@discussion an error handler for ampache that traps
as many errors as it can and logs em
*/
-function ampache_error_handler($errno, $errstr, $errfile, $errline) {
+function ampache_error_handler($errno, $errstr, $errfile, $errline) {
/* Default level of 1 */
$level = 1;
-
- switch ($errno) {
+
+ switch ($errno) {
case '2':
$error_name = "Runtime Error";
break;
@@ -81,36 +81,36 @@ function ampache_error_handler($errno, $errstr, $errfile, $errline) {
$level = 2;
break;
} // end switch
-
+
/* Don't log var: Deprecated we know shutup!
* Yea now getid3() spews errors I love it :(
*/
if (strstr($errstr,"var: Deprecated. Please use the public/private/protected modifiers") OR
strstr($errstr,"getimagesize() [") OR strstr($errstr,"Non-static method getid3") OR
- strstr($errstr,"Assigning the return value of new by reference is deprecated")) {
- return false;
+ strstr($errstr,"Assigning the return value of new by reference is deprecated")) {
+ return false;
}
- if (strstr($errstr,"date.timezone")) {
- $error_name = "Warning";
- $errstr = "You have not set a valid timezone (date.timezone) in your php.ini file. This may cause display issues with dates. This warning is non-critical and not caused by Ampache.";
- }
+ if (strstr($errstr,"date.timezone")) {
+ $error_name = "Warning";
+ $errstr = "You have not set a valid timezone (date.timezone) in your php.ini file. This may cause display issues with dates. This warning is non-critical and not caused by Ampache.";
+ }
- /* The XML-RPC lib is broken, well kind of
- * shut your pie hole
+ /* The XML-RPC lib is broken, well kind of
+ * shut your pie hole
*/
- if (strstr($errstr,"used as offset, casting to integer")) {
- return false;
+ if (strstr($errstr,"used as offset, casting to integer")) {
+ return false;
}
$log_line = "[$error_name] $errstr in file $errfile($errline)";
debug_event('PHP Error',$log_line,$level);
-
+
// When a dir is defined lets log it to a logfile
- if (Config::get('log_path') != "")
+ if (Config::get('log_path') != "")
log_event("ampache","PHP Error", $log_line);
-
+
} // ampache_error_handler
/**
@@ -119,13 +119,13 @@ function ampache_error_handler($errno, $errstr, $errfile, $errline) {
* log_event. It checks for conf('debug') and conf('debug_level') and only
* calls log event if both requirements are met.
*/
-function debug_event($type,$message,$level,$file='',$username='') {
+function debug_event($type,$message,$level,$file='',$username='') {
- if (!Config::get('debug') || $level > Config::get('debug_level')) {
+ if (!Config::get('debug') || $level > Config::get('debug_level')) {
return false;
}
- if (!$username) {
+ if (!$username) {
$username = $GLOBALS['user']->username;
}
diff --git a/lib/preferences.php b/lib/preferences.php
index a1a577a3..ac81c398 100644
--- a/lib/preferences.php
+++ b/lib/preferences.php
@@ -266,14 +266,14 @@ function create_preference_input($name,$value) {
echo "\t<option value=\"75\"$bandwidth_75>" . _('High') . "</option>\n";
echo "</select>\n";
break;
- case 'features':
- ${"features_$value"} = ' selected="selected"';
- echo "<select name=\"$name\">\n";
+ case 'features':
+ ${"features_$value"} = ' selected="selected"';
+ echo "<select name=\"$name\">\n";
echo "\t<option value=\"25\"$features_25>" . _('Low') . "</option>\n";
echo "\t<option value=\"50\"$features_50>" . _('Medium') . "</option>\n";
echo "\t<option value=\"75\"$features_75>" . _('High') . "</option>\n";
echo "</select>\n";
- break;
+ break;
case 'transcode':
${$value} = ' selected="selected"';
echo "<select name=\"$name\">\n";
diff --git a/lib/rating.lib.php b/lib/rating.lib.php
index aeac66d1..48ef4ab8 100644
--- a/lib/rating.lib.php
+++ b/lib/rating.lib.php
@@ -24,10 +24,10 @@
* show_rating
* This takes an artist id and includes the right file
*/
-function show_rating($object_id,$type) {
+function show_rating($object_id,$type) {
$rating = new Rating($object_id,$type);
-
+
require Config::get('prefix') . '/templates/show_object_rating.inc.php';
} // show_rating
@@ -43,11 +43,11 @@ function show_rating_static($object_id,$type) {
/**
* get_rating_name
- * This takes a score and returns the name that we should use
+ * This takes a score and returns the name that we should use
*/
-function get_rating_name($score) {
+function get_rating_name($score) {
- switch ($score) {
+ switch ($score) {
case '0':
return _("Don't Play");
break;
@@ -73,7 +73,7 @@ function get_rating_name($score) {
} // end switch
return true;
-
+
} // get_rating_name
?>
diff --git a/lib/search.php b/lib/search.php
index 06385874..2133b0fc 100644
--- a/lib/search.php
+++ b/lib/search.php
@@ -17,38 +17,38 @@
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.
-
+
This library handles all the searching!
*/
-/**
+/**
* run_search
* this function actually runs the search, and returns an array of the results. Unlike the previous
- * function it does not do the display work its self.
+ * function it does not do the display work its self.
* @package Search
* @catagory Search
*/
-function run_search($data) {
+function run_search($data) {
/* Create an array of the object we need to search on */
- foreach ($data as $key=>$value) {
+ foreach ($data as $key=>$value) {
/* Get the first two chars to check
* and see if it's s_
*/
$prefix = substr($key,0,2);
$value = trim($value);
-
- if ($prefix == 's_' AND strlen($value)) {
+
+ if ($prefix == 's_' AND strlen($value)) {
$true_name = substr($key,2,strlen($key));
$search[$true_name] = Dba::escape($value);
}
-
+
} // end foreach
-
+
/* Figure out if they want a AND based search or a OR based search */
- switch($_REQUEST['operator']) {
+ switch($_REQUEST['operator']) {
case 'or':
$operator = 'OR';
break;
@@ -58,7 +58,7 @@ function run_search($data) {
} // end switch on operator
/* Figure out what type of method they would like to use, exact or fuzzy */
- switch($_REQUEST['method']) {
+ switch($_REQUEST['method']) {
case 'fuzzy':
$method = "LIKE '%__%'";
break;
@@ -68,14 +68,14 @@ function run_search($data) {
} // end switch on method
$limit = intval($_REQUEST['limit']);
-
+
/* Switch, and run the correct function */
- switch($_REQUEST['object_type']) {
+ switch($_REQUEST['object_type']) {
case 'artist':
case 'album':
case 'song':
$function_name = 'search_' . $_REQUEST['object_type'];
- if (function_exists($function_name)) {
+ if (function_exists($function_name)) {
$results = call_user_func($function_name,$search,$operator,$method,$limit);
return $results;
}
@@ -84,20 +84,20 @@ function run_search($data) {
$results = search_song($search,$operator,$method,$limit);
return $results;
break;
- } // end switch
+ } // end switch
return array();
} // run_search
-/**
+/**
* search_song
* This function deals specificly with returning song object for the run_search
* function, it assumes that our root table is songs
* @package Search
* @catagory Search
*/
-function search_song($data,$operator,$method,$limit) {
+function search_song($data,$operator,$method,$limit) {
/* Generate BASE SQL */
@@ -108,45 +108,45 @@ function search_song($data,$operator,$method,$limit) {
$field_sql = '';
$order_sql = '';
- if ($limit > 0) {
+ if ($limit > 0) {
$limit_sql = " LIMIT $limit";
}
-
- foreach ($data as $type=>$value) {
-
+
+ foreach ($data as $type=>$value) {
+
/* Create correct Value statement based on method */
$value_string = str_replace("__",$value,$method);
-
- switch ($type) {
+
+ switch ($type) {
case 'all':
$additional_soundex = false;
-
+
if (!(strpos($value, '-'))) // if we want a fuzzier search
$additional_soundex = true;
-
+
$where_sql = " MATCH (`artist2`.`name`, `album2`.`name`, `song`.`title`) AGAINST ('$value' IN BOOLEAN MODE)";
-
+
if ($additional_soundex) {
$where_sql.= " OR `artist2`.`name` SOUNDS LIKE '$value'";
$where_sql.= " OR `album2`.`name` SOUNDS LIKE '$value'";
$where_sql.= " OR `song`.`title` SOUNDS LIKE '$value'";
}
-
+
$table_sql = " LEFT JOIN `album` as `album2` ON `song`.`album`=`album2`.`id`";
$table_sql.= " LEFT JOIN `artist` AS `artist2` ON `song`.`artist`=`artist2`.`id`";
-
+
$order_sql = " ORDER BY";
-
+
$order_sql.= " MATCH (`artist2`.`name`) AGAINST ('$value' IN BOOLEAN MODE)";
if ($additional_soundex) $order_sql.= " + (SOUNDEX(`artist2`.`name`)=SOUNDEX('$value')) DESC,"; else $order_sql.= " DESC,";
-
+
$order_sql.= " MATCH (`album2`.`name`) AGAINST ('$value' IN BOOLEAN MODE)";
if ($additional_soundex) $order_sql.= " + (SOUNDEX(`album2`.`name`)=SOUNDEX('$value')) DESC,"; else $order_sql.= " DESC,";
-
+
$order_sql.= " MATCH (`song`.`title`) AGAINST ('$value' IN BOOLEAN MODE)";
if ($additional_soundex) $order_sql.= " + (SOUNDEX(`song`.`title`)=SOUNDEX('$value')) DESC,"; else $order_sql.= " DESC,";
-
+
$order_sql.= " `artist2`.`name`,";
$order_sql.= " `album2`.`name`,";
$order_sql.= " `song`.`track`,";
@@ -171,14 +171,14 @@ function search_song($data,$operator,$method,$limit) {
$where_sql .= " (`song`.`year` BETWEEN ".$data["year"]." AND ".$data["year2"].") $operator";
}
break;
- case 'time':
- if (!empty($data['time2'])) {
- $where_sql .= " `song`.`time` <= " . Dba::escape(intval($data['time2'])*60) . " $operator";
+ case 'time':
+ if (!empty($data['time2'])) {
+ $where_sql .= " `song`.`time` <= " . Dba::escape(intval($data['time2'])*60) . " $operator";
}
- if (!empty($data['time'])) {
- $where_sql .= " `song`.`time` >= " . Dba::escape(intval($data['time'])*60) . " $operator";
- }
- break;
+ if (!empty($data['time'])) {
+ $where_sql .= " `song`.`time` >= " . Dba::escape(intval($data['time'])*60) . " $operator";
+ }
+ break;
case 'filename':
$where_sql .= " `song`.`file` $value_string $operator";
break;
@@ -199,70 +199,70 @@ function search_song($data,$operator,$method,$limit) {
$value = intval($value);
// This is a little more complext, pull a list of IDs that have this average rating
- $rating_sql = "SELECT `object_id`,AVG(`rating`.`rating`) AS `avgrating` FROM `rating` " .
- "WHERE `object_type`='song' GROUP BY `object_id`";
- $db_results = Dba::read($rating_sql);
+ $rating_sql = "SELECT `object_id`,AVG(`rating`.`rating`) AS `avgrating` FROM `rating` " .
+ "WHERE `object_type`='song' GROUP BY `object_id`";
+ $db_results = Dba::read($rating_sql);
// Fill it with one value to prevent sql error on no results
$where_sql .= " `song`.`id` IN (";
- $ids = array('0');
+ $ids = array('0');
- while ($row = Dba::fetch_assoc($db_results)) {
- if ($row['avgrating'] < $value) { continue; }
- $ids[] = $row['object_id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ if ($row['avgrating'] < $value) { continue; }
+ $ids[] = $row['object_id'];
+ }
- $where_sql .= implode(',',$ids) . ') ' . $operator;
+ $where_sql .= implode(',',$ids) . ') ' . $operator;
break;
- case 'tag':
+ case 'tag':
// Fill it with one value to prevent sql error on no results
- $ids = array('0');
+ $ids = array('0');
- $tag_sql = "SELECT `object_id` FROM `tag` LEFT JOIN `tag_map` ON `tag`.`id`=`tag_map`.`tag_id` " .
- "WHERE `tag_map`.`object_type`='song' AND `tag`.`name` $value_string ";
- $db_results = Dba::read($tag_sql);
+ $tag_sql = "SELECT `object_id` FROM `tag` LEFT JOIN `tag_map` ON `tag`.`id`=`tag_map`.`tag_id` " .
+ "WHERE `tag_map`.`object_type`='song' AND `tag`.`name` $value_string ";
+ $db_results = Dba::read($tag_sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $ids[] = $row['object_id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $ids[] = $row['object_id'];
+ }
- $where_sql = " `song`.`id` IN (" . implode(',',$ids) . ") $operator";
+ $where_sql = " `song`.`id` IN (" . implode(',',$ids) . ") $operator";
- break;
+ break;
default:
// Notzing!
break;
} // end switch on type
-
+
} // foreach data
-
+
/* Trim off the extra $method's and ,'s then combine the sucka! */
$where_sql = rtrim($where_sql,$operator);
$group_sql = rtrim($group_sql,',');
$select_sql = rtrim($select_sql,',');
- if ($group_sql == ' GROUP BY') { $group_sql = ''; }
-
+ if ($group_sql == ' GROUP BY') { $group_sql = ''; }
+
$base_sql = "SELECT DISTINCT(`song`.`id`) $field_sql $select_sql FROM `song`";
$sql = $base_sql . $table_sql . " WHERE " . $where_sql . $group_sql . $order_sql . $limit_sql;
-
+
/**
- * Because we might need this for Dynamic Playlist Action
+ * Because we might need this for Dynamic Playlist Action
* but we don't trust users to provide this store it in the
* session where they can't get to it!
*/
-
+
$_SESSION['userdata']['stored_search'] = $sql;
$db_results = Dba::read($sql);
-
- $results = array();
-
- while ($row = Dba::fetch_assoc($db_results)) {
+
+ $results = array();
+
+ while ($row = Dba::fetch_assoc($db_results)) {
$results[] = $row['id'];
}
diff --git a/lib/themes.php b/lib/themes.php
index 2ff2c335..0fb58fdd 100644
--- a/lib/themes.php
+++ b/lib/themes.php
@@ -22,39 +22,39 @@
/**
* get_themes
- * this looks in /themes and pulls all of the
- * theme.cfg.php files it can find and returns an
+ * this looks in /themes and pulls all of the
+ * theme.cfg.php files it can find and returns an
* array of the results
*/
-function get_themes() {
+function get_themes() {
/* Open the themes dir and start reading it */
$handle = @opendir(Config::get('prefix') . '/themes');
- if (!is_resource($handle)) {
- debug_event('theme',"Error unable to open Themes Directory",'2');
- return array();
+ if (!is_resource($handle)) {
+ debug_event('theme',"Error unable to open Themes Directory",'2');
+ return array();
}
- $results = array();
+ $results = array();
+
+ while ($file = readdir($handle)) {
- while ($file = readdir($handle)) {
-
$full_file = Config::get('prefix') . '/themes/' . $file;
/* See if it's a directory */
- if (is_dir($full_file) AND substr($file,0,1) != ".") {
+ if (is_dir($full_file) AND substr($file,0,1) != ".") {
$config_file = $full_file . '/theme.cfg.php';
/* Open the theme.cfg.php file */
$r = @parse_ini_file($config_file);
$r['path'] = $file;
- $name = $r['name'];
+ $name = $r['name'];
$results[$name] = $r;
}
} // end while directory
// Sort by the theme name
- ksort($results);
+ ksort($results);
return $results;
@@ -65,7 +65,7 @@ function get_themes() {
@discussion get a single theme and read the config file
then return the results
*/
-function get_theme($name) {
+function get_theme($name) {
if (strlen($name) < 1) { return false; }
@@ -80,7 +80,7 @@ function get_theme($name) {
@function get_theme_author
@discussion returns the author of this theme
*/
-function get_theme_author($theme_name) {
+function get_theme_author($theme_name) {
$theme_path = conf('prefix') . "/themes/" . conf('theme_name') . "/theme.cfg.php";
$results = read_config($theme_path);
@@ -93,12 +93,12 @@ function get_theme_author($theme_name) {
@function theme_exists
@discussion this function checks to make sure that a theme actually exists
*/
-function theme_exists($theme_name) {
+function theme_exists($theme_name) {
$theme_path = conf('prefix') . "/themes/" . $theme_name . "/theme.cfg.php";
- if (!file_exists($theme_path)) {
- return false;
+ if (!file_exists($theme_path)) {
+ return false;
}
return true;