diff options
author | Paul 'flowerysong' Arthur <flowerysong00@yahoo.com> | 2010-06-13 08:11:09 +0000 |
---|---|---|
committer | Paul 'flowerysong' Arthur <flowerysong00@yahoo.com> | 2010-06-13 08:11:09 +0000 |
commit | 4b5756ba9d8ee9e83c1ba4624b461b4746e49e82 (patch) | |
tree | 2e46772da9d25197fd847b273ca1f9b882ad3e34 /lib/class | |
parent | 93f4a26ab07207e1f9a8e716a82c5d8812d5344c (diff) | |
download | ampache-4b5756ba9d8ee9e83c1ba4624b461b4746e49e82.tar.gz ampache-4b5756ba9d8ee9e83c1ba4624b461b4746e49e82.tar.bz2 ampache-4b5756ba9d8ee9e83c1ba4624b461b4746e49e82.zip |
Miscellaneous cleanup.
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/access.class.php | 8 | ||||
-rw-r--r-- | lib/class/ajax.class.php | 15 | ||||
-rw-r--r-- | lib/class/album.class.php | 34 | ||||
-rw-r--r-- | lib/class/art.class.php | 13 | ||||
-rw-r--r-- | lib/class/artist.class.php | 2 | ||||
-rw-r--r-- | lib/class/browse.class.php | 1 | ||||
-rw-r--r-- | lib/class/catalog.class.php | 7 | ||||
-rw-r--r-- | lib/class/dba.class.php | 5 | ||||
-rw-r--r-- | lib/class/query.class.php | 5 | ||||
-rw-r--r-- | lib/class/rating.class.php | 30 | ||||
-rw-r--r-- | lib/class/song.class.php | 26 | ||||
-rw-r--r-- | lib/class/stream.class.php | 11 | ||||
-rw-r--r-- | lib/class/tag.class.php | 20 | ||||
-rw-r--r-- | lib/class/update.class.php | 5 | ||||
-rw-r--r-- | lib/class/vainfo.class.php | 2 | ||||
-rw-r--r-- | lib/class/vauth.class.php | 8 |
16 files changed, 120 insertions, 72 deletions
diff --git a/lib/class/access.class.php b/lib/class/access.class.php index 7f986fef..93bfbfd6 100644 --- a/lib/class/access.class.php +++ b/lib/class/access.class.php @@ -312,13 +312,15 @@ class Access { /** * check_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 + * 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) { if (Config::get('demo_mode')) { return true; } - if (INSTALL == '1') { return true; } + if (defined('INSTALL')) { return true; } $level = intval($level); diff --git a/lib/class/ajax.class.php b/lib/class/ajax.class.php index 38c451a9..b1e9997a 100644 --- a/lib/class/ajax.class.php +++ b/lib/class/ajax.class.php @@ -108,15 +108,14 @@ class Ajax { // If they passed a span class if ($class) { - $class_txt = ' class="' . $class . '"'; + $class = ' class="' . $class . '"'; } - $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>".$string."</a>\n"; $string .= self::observe($source,'click',$ajax_string); @@ -126,7 +125,7 @@ class Ajax { /** * text - * This prints out the specified text as a link and setups the required + * This prints out the specified text as a link and sets up the required * ajax for the link so it works correctly */ public static function text($action,$text,$source,$post='',$class='') { @@ -136,11 +135,11 @@ class Ajax { // If they passed a span class if ($class) { - $class_txt = ' class="' . $class . '"'; + $class = ' 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>$text</a>\n"; $string .= self::observe($source,'click',$ajax_string); @@ -177,7 +176,7 @@ class Ajax { */ public static function start_container($name) { - if (AJAX_INCLUDE == '1' AND !self::$include_override) { return true; } + if (defined('AJAX_INCLUDE') && !self::$include_override) { return true; } echo '<div id="' . scrub_out($name) . '">'; @@ -189,7 +188,7 @@ class Ajax { */ public static function end_container() { - if (AJAX_INCLUDE == '1' AND !self::$include_override) { return true; } + if (defined('AJAX_INCLUDE') && !self::$include_override) { return true; } echo "</div>"; diff --git a/lib/class/album.class.php b/lib/class/album.class.php index cf00b309..b033bde4 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -30,12 +30,13 @@ class Album extends database_object { /* Variables from DB */ public $id; public $name; - public $full_name; // Prefix + Name, genereated by format(); public $disk; public $year; public $prefix; public $mbid; // MusicBrainz ID + public $full_name; // Prefix + Name, generated + // cached information public $_songs=array(); @@ -58,7 +59,7 @@ class Album extends database_object { $this->$key = $value; } - // Little bit of formating here + // Little bit of formatting here $this->full_name = trim(trim($info['prefix']) . ' ' . trim($info['name'])); return true; @@ -140,11 +141,16 @@ class Album extends database_object { 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" . - ",artist.prefix AS artist_prefix, artist.id AS artist_id ". - "FROM `song` " . - "INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " . - "WHERE `song`.`album`='$this->id' GROUP BY `song`.`album`"; + $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`, " . + "`artist`.`id` AS `artist_id` " . + "FROM `song` INNER JOIN `artist` " . + "ON `artist`.`id`=`song`.`artist` " . + "WHERE `song`.`album`='$this->id' " . + "GROUP BY `song`.`album`"; $db_results = Dba::read($sql); $results = Dba::fetch_assoc($db_results); @@ -170,12 +176,16 @@ class Album extends database_object { $results = array(); + $artist = Dba::escape($artist); + + $sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' "; if ($artist) { - $artist_sql = "AND `artist`='" . Dba::escape($artist) . "'"; + $sql .= "AND `artist`='$artist'"; + } + $sql .= "ORDER BY `track`, `title`"; + if ($limit) { + $sql .= " LIMIT $limit"; } - - $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)) { @@ -228,7 +238,7 @@ class Album extends database_object { $this->f_name_link .="</a>"; $this->f_link = $this->f_name_link; - $this->f_title = $full_name; + $this->f_title = $this->full_name; // FIXME: Legacy? if ($this->artist_count == '1') { $artist = trim(trim($this->artist_prefix) . ' ' . trim($this->artist_name)); $this->f_artist_name = $artist; diff --git a/lib/class/art.class.php b/lib/class/art.class.php index ddb74539..6bf3a65b 100644 --- a/lib/class/art.class.php +++ b/lib/class/art.class.php @@ -55,7 +55,12 @@ class Art extends database_object { * Called on creation of the class */ public static function _auto_init() { - self::$enabled = make_bool($_SESSION['art_enabled']); + if (!isset($_SESSION['art_enabled'])) { + $_SESSION['art_enabled'] = (Config::get('bandwidth') > 25); + } + else { + self::$enabled = make_bool($_SESSION['art_enabled']); + } } /** @@ -63,7 +68,7 @@ class Art extends database_object { * Checks whether the user currently wants art */ public static function is_enabled() { - if (self::$enabled || (Config::get('bandwidth') > 25)) { + if (self::$enabled) { return true; } @@ -718,7 +723,7 @@ class Art extends database_object { $arurl = $ar->getTargetId(); debug_event('mbz-gatherart', "Found URL AR: " . $arurl , '5'); foreach ($coverartsites as $casite) { - if (strstr($arurl, $casite['domain'])) { + if (strpos($arurl, $casite['domain']) !== false) { debug_event('mbz-gatherart', "Matched coverart site: " . $casite['name'], '5'); if (preg_match($casite['regexp'], $arurl, $matches) == 1) { $num_found++; @@ -1085,7 +1090,7 @@ class Art extends database_object { $url = $coverart[$key]; // We need to check the URL for the /noimage/ stuff - if (strstr($url,"/noimage/")) { + if (strpos($url,"/noimage/") !== false) { debug_event('LastFM','Detected as noimage, skipped ' . $url,'3'); continue; } diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php index 2520346c..f7638b94 100644 --- a/lib/class/artist.class.php +++ b/lib/class/artist.class.php @@ -227,7 +227,7 @@ class Artist extends database_object { // If this is a fake object, we're done here if ($this->_fake) { return true; } - $this->f_name_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&artist=" . $this->id . "\" title=\"" . $this->full_name . "\">" . $name . "</a>"; + $this->f_name_link = "<a href=\"" . Config::get('web_path') . "/artists.php?action=show&artist=" . $this->id . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>"; $this->f_link = Config::get('web_path') . '/artists.php?action=show&artist=' . $this->id; // Get the counts diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php index 7b8a75d9..5feaefde 100644 --- a/lib/class/browse.class.php +++ b/lib/class/browse.class.php @@ -103,6 +103,7 @@ class Browse extends Query { ${$class_name} = new $class_name($id); } + $match = ''; // Format any matches we have so we can show them to the masses if ($filter_value = $this->get_filter('alpha_match')) { $match = ' (' . $filter_value . ')'; diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index ab147749..2b6577b3 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -459,7 +459,7 @@ class Catalog extends database_object { } // Correctly detect the slash we need to use here - if (strstr($path,"/")) { + if (strpos($path,"/") !== false) { $slash_type = '/'; } else { @@ -952,7 +952,10 @@ class Catalog extends database_object { // 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"; } + if (!$preferred_filename || + strpos($preferred_filename, '%') !== false) { + $preferred_filename = "folder.$extension"; + } $file = "$dir/$preferred_filename"; if ($file_handle = fopen($file,"w")) { diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php index dc19b7f0..4072f4b8 100644 --- a/lib/class/dba.class.php +++ b/lib/class/dba.class.php @@ -424,7 +424,10 @@ class Dba { // Itterate through the columns of the table while ($table = Dba::fetch_assoc($describe_results)) { - if (strstr($table['Type'],'varchar') OR strstr($table['Type'],'enum') OR strstr($table['Table'],'text')) { + if ( + (strpos($table['Type'], 'varchar') !== false) || + (strpos($table['Type'], 'enum') !== false) || + (strpos($table['Table'],'text') !== false)) { $sql = "ALTER TABLE `" . $row['0'] . "` MODIFY `" . $table['Field'] . "` " . $table['Type'] . " CHARACTER SET " . $target_charset; $charset_results = Dba::write($sql); if (!$charset_results) { diff --git a/lib/class/query.class.php b/lib/class/query.class.php index 8555b4a6..15af3cdd 100644 --- a/lib/class/query.class.php +++ b/lib/class/query.class.php @@ -145,6 +145,7 @@ class Query { $this->reset_join(); $this->reset_select(); $this->reset_having(); + $this->set_static_content(false); $this->set_is_simple(false); $this->set_start(0); $this->set_offset(Config::get('offset_limit') ? Config::get('offset_limit') : '25'); @@ -219,7 +220,9 @@ class Query { // Simple enough, but if we ever move this crap // If we ever move this crap what? - return $this->_state['filter'][$key]; + return isset($this->_state['filter'][$key]) + ? $this->_state['filter'][$key] + : false; } // get_filter diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index 59efd43d..be0ee2f2 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -65,6 +65,8 @@ class Rating extends database_object { if (!is_array($ids) OR !count($ids)) { return false; } $user_id = intval($GLOBALS['user']->id); + $ratings = array(); + $user_ratings = array(); $idlist = '(' . implode(',', $ids) . ')'; $sql = "SELECT `rating`, `object_id` FROM `rating` " . @@ -73,7 +75,7 @@ class Rating extends database_object { $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { - $user[$row['object_id']] = $row['rating']; + $user_ratings[$row['object_id']] = $row['rating']; } $sql = "SELECT AVG(`rating`) as `rating`, `object_id` FROM " . @@ -82,19 +84,26 @@ class Rating extends database_object { $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { - $rating[$row['object_id']] = $row['rating']; + $ratings[$row['object_id']] = $row['rating']; } foreach ($ids as $id) { - parent::add_to_cache('rating_' . $type . '_user' . $user_id, $id, intval($user[$id])); - - if (!isset($rating[$id])) { + // First store the user-specific rating + if (!isset($user_ratings[$id])) { $rating = 0; } else { - $rating = round($rating[$id]['rating'], 1); + $rating = intval($user_ratings[$id]); } + parent::add_to_cache('rating_' . $type . '_user' . $user_id, $id, $rating); + // Then store the average + if (!isset($ratings[$id])) { + $rating = 0; + } + else { + $rating = round($ratings[$id]['rating'], 1); + } parent::add_to_cache('rating_' . $type . '_all', $id, $rating); } @@ -125,11 +134,14 @@ class Rating extends database_object { "AND `object_id`='$id' AND `object_type`='$type'"; $db_results = Dba::read($sql); - $results = Dba::fetch_assoc($db_results); + $rating = 0; - parent::add_to_cache($key, $id, $results['rating']); + if ($results = Dba::fetch_assoc($db_results)) { + $rating = $results['rating']; + } - return $results['rating']; + parent::add_to_cache($key, $id, $rating); + return $rating; } // get_user_rating diff --git a/lib/class/song.class.php b/lib/class/song.class.php index ccc9ec4a..48ddd451 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -875,15 +875,16 @@ class Song extends database_object implements media { $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! + // 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"; + $url = Stream::get_base_url() . "oid=$song->id&uid=$user_id&name=/$song_name"; return $url; @@ -921,15 +922,14 @@ class Song extends database_object implements media { */ public static function get_recently_played($user_id='') { + $user_id = Dba::escape($user_id); + + $sql = "SELECT `object_id`, `user`, `object_type`, `date` " . + "FROM `object_count` WHERE `object_type`='song' "; if ($user_id) { - $user_limit = " AND `object_count`.`user`='" . Dba::escape($user_id) . "'"; + $sql .= "AND `user`='$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 " . - "ORDER BY `object_count`.`date` DESC "; + $sql .= "ORDER BY `date` DESC "; $db_results = Dba::read($sql); $results = array(); @@ -946,17 +946,17 @@ class Song extends database_object implements media { /** * native_stream - * This returns true/false if this can be nativly streamed + * This returns true/false if this can be natively streamed */ public function native_stream() { - if ($this->_transcode) { return false; } + if ($this->_transcoded) { return false; } $conf_var = 'transcode_' . $this->type; $conf_type = 'transcode_' . $this->type . '_target'; if (Config::get($conf_var)) { - $this->_transcode = true; + $this->_transcoded = true; debug_event('auto_transcode','Transcoding to ' . $this->type,'5'); return false; } diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index 5deee98e..35f0f4a3 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -186,7 +186,7 @@ class Stream { $db_results = Dba::write($sql); foreach ($append_array as $append_agent) { - if (strstr(strtoupper($agent),$append_agent)) { + if (strpos(strtoupper($agent), $append_agent) !== false) { // We're done here jump ship! return true; } @@ -828,14 +828,15 @@ 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 takes care of the different types of 'playlist methods'. The + * reason this is here is because it deals with streaming rather than + * playlist mojo. If something needs to happen this will echo the + * javascript required to cause a reload of the iframe. */ public static function run_playlist_method() { // If this wasn't ajax included run away - if (AJAX_INCLUDE != '1') { return false; } + if (!defined('AJAX_INCLUDE')) { return false; } // If we're doin the flash magic then run away as well if (Config::get('play_type') == 'xspf_player') { return false; } diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php index 83548e36..52c6f539 100644 --- a/lib/class/tag.class.php +++ b/lib/class/tag.class.php @@ -99,8 +99,9 @@ class Tag extends database_object { /** * set_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 + * This associates 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) { @@ -114,7 +115,7 @@ class Tag extends database_object { // If nothing is found, then go ahead and return false if (!is_array($data) OR !count($data)) { return false; } - $this->weight = $data[$this->id]['count']; + $this->weight = count($data[$this->id]['users']); if (in_array($GLOBALS['user']->id,$data[$this->id]['users'])) { $this->owner = $GLOBALS['user']->id; @@ -164,14 +165,18 @@ class Tag extends database_object { 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 + // Run through our original ids as we also 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]); + if (!isset($tags[$id])) { + $tags[$id] = null; + $tag_map[$id] = null; + } + parent::add_to_cache('tag_top_' . $type, $id, $tags[$id]); + parent::add_to_cache('tag_map_' . $type, $id, $tag_map[$id]); } return true; @@ -338,7 +343,6 @@ class Tag extends database_object { 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); diff --git a/lib/class/update.class.php b/lib/class/update.class.php index e86c20ef..2c24935e 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -1384,7 +1384,10 @@ class Update { // Itterate through the columns of the table while ($table = Dba::fetch_assoc($describe_results)) { - if (strstr($table['Type'],'varchar') OR strstr($table['Type'],'enum') OR strstr($table['Table'],'text')) { + if ( + (strpos($table['Type'], 'varchar') !== false) || + (strpos($table['Type'], 'enum') !== false) || + strpos($table['Table'],'text') !== false) { $sql = "ALTER TABLE `" . $row['0'] . "` MODIFY `" . $table['Field'] . "` " . $table['Type'] . " CHARACTER SET " . $target_charset; $charset_results = Dba::write($sql); if (!$charset_results) { diff --git a/lib/class/vainfo.class.php b/lib/class/vainfo.class.php index b93fad08..5e5b32c2 100644 --- a/lib/class/vainfo.class.php +++ b/lib/class/vainfo.class.php @@ -937,7 +937,7 @@ class vainfo { $results = array(); // Correctly detect the slash we need to use here - if (strstr($filename,"/")) { + if (strpos($filename, '/') !== false) { $slash_type = '/'; } else { diff --git a/lib/class/vauth.class.php b/lib/class/vauth.class.php index 0568026b..d69078b0 100644 --- a/lib/class/vauth.class.php +++ b/lib/class/vauth.class.php @@ -84,7 +84,7 @@ class vauth { */ public static function write($key, $value) { - if (NO_SESSION_UPDATE == '1') { return true; } + if (defined('NO_SESSION_UPDATE')) { return true; } $length = Config::get('session_length'); $value = Dba::escape($value); @@ -168,7 +168,7 @@ class vauth { // Do a quick check to see if this is an AJAXed logout request // if so use the iframe to redirect - if (AJAX_INCLUDE == '1') { + if (defined('AJAX_INCLUDE')) { ob_end_clean(); ob_start(); @@ -455,7 +455,9 @@ class vauth { public static function ungimp_ie() { // If no https, no ungimpage required - if ($_SERVER['HTTPS'] != 'on') { return true; } + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'on') { + return true; + } // Try to detect IE $agent = trim($_SERVER['HTTP_USER_AGENT']); |