diff --git a/image.php b/image.php
index dfa581b7fb..19dd2959f6 100644
--- a/image.php
+++ b/image.php
@@ -41,7 +41,7 @@
if (!Config::get('resize_images')) { unset($_GET['thumb']); }
// FIXME: Legacy stuff - should be removed after a version or so
-if (!$_GET['object_type']) {
+if (!isset($_GET['object_type'])) {
$_GET['object_type'] = 'album';
}
diff --git a/index.php b/index.php
index d6cb7f7d9c..bbdcf72702 100644
--- a/index.php
+++ b/index.php
@@ -24,7 +24,7 @@
show_header();
-$action = scrub_in($_REQUEST['action']);
+$action = isset($_REQUEST['action']) ? scrub_in($_REQUEST['action']) : null;
/**
* Check for the refresh mojo, if it's there then require the
diff --git a/lib/batch.lib.php b/lib/batch.lib.php
index e79a55d099..088055fa46 100644
--- a/lib/batch.lib.php
+++ b/lib/batch.lib.php
@@ -23,8 +23,7 @@
/**
* get_song_files
- * tmakes array of song ids and returns
- * array of path to actual files
+ * Takes an array of song ids and returns an array of the actual filenames
*/
function get_song_files($media_ids) {
@@ -57,13 +56,13 @@ function get_song_files($media_ids) {
*/
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
+ // 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 writable.
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');
+ debug_event('Error','File Zip Path:' . Config::get('file_zip_path') . ' is not writable','1');
}
else {
$in_memory = '0';
diff --git a/lib/class/access.class.php b/lib/class/access.class.php
index 7f986fef47..93bfbfd66c 100644
--- a/lib/class/access.class.php
+++ b/lib/class/access.class.php
@@ -312,13 +312,15 @@ public static function check_network($type,$user,$level,$ip='') {
/**
* 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 38c451a979..b1e9997aca 100644
--- a/lib/class/ajax.class.php
+++ b/lib/class/ajax.class.php
@@ -108,15 +108,14 @@ public static function button($action,$icon,$alt,$source='',$post='',$class='')
// If they passed a span class
if ($class) {
- $class_txt = ' class="' . $class . '"';
+ $class = ' class="' . $class . '"';
}
-
$string = get_user_icon($icon,$alt);
// Generate a so that it's more compliant with older browsers
// (ie :hover actions) and also to unify linkbuttons (w/o ajax) display
- $string = "".$string."\n";
+ $string = "".$string."\n";
$string .= self::observe($source,'click',$ajax_string);
@@ -126,7 +125,7 @@ public static function button($action,$icon,$alt,$source='',$post='',$class='')
/**
* 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 @@ public static function text($action,$text,$source,$post='',$class='') {
// 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 = "$text\n";
+ $string = "$text\n";
$string .= self::observe($source,'click',$ajax_string);
@@ -177,7 +176,7 @@ public static function set_include_override($value) {
*/
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 '
';
@@ -189,7 +188,7 @@ public static function start_container($name) {
*/
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 "
";
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index cf00b30949..b033bde441 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 @@ public function __construct($id='') {
$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 @@ private function _get_extra_info() {
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 @@ public function get_songs($limit = 0,$artist='') {
$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 @@ public function format() {
$this->f_name_link .="";
$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 ddb74539c8..6bf3a65bbf 100644
--- a/lib/class/art.class.php
+++ b/lib/class/art.class.php
@@ -55,7 +55,12 @@ public function __construct($uid, $type) {
* 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 @@ public static function _auto_init() {
* 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 @@ public function gather_musicbrainz($limit=0) {
$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 @@ public function gather_lastfm($limit,$options=false) {
$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 2520346c6a..f7638b9478 100644
--- a/lib/class/artist.class.php
+++ b/lib/class/artist.class.php
@@ -227,7 +227,7 @@ public function format() {
// If this is a fake object, we're done here
if ($this->_fake) { return true; }
- $this->f_name_link = "id . "\" title=\"" . $this->full_name . "\">" . $name . "";
+ $this->f_name_link = "id . "\" title=\"" . $this->f_full_name . "\">" . $name . "";
$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 7b8a75d9dc..5feaefde8a 100644
--- a/lib/class/browse.class.php
+++ b/lib/class/browse.class.php
@@ -103,6 +103,7 @@ public function show_objects($object_ids = null) {
${$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 ab14774959..2b6577b36c 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -459,7 +459,7 @@ public function add_files($path,$options) {
}
// Correctly detect the slash we need to use here
- if (strstr($path,"/")) {
+ if (strpos($path,"/") !== false) {
$slash_type = '/';
}
else {
@@ -952,7 +952,10 @@ public static function dump_album_art($catalog_id, $methods=array()) {
// 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 dc19b7f09a..4072f4b801 100644
--- a/lib/class/dba.class.php
+++ b/lib/class/dba.class.php
@@ -424,7 +424,10 @@ public static function reset_db_charset() {
// 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 8555b4a6c0..15af3cdd24 100644
--- a/lib/class/query.class.php
+++ b/lib/class/query.class.php
@@ -145,6 +145,7 @@ public function reset() {
$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 @@ public function get_filter($key) {
// 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 59efd43d66..be0ee2f29a 100644
--- a/lib/class/rating.class.php
+++ b/lib/class/rating.class.php
@@ -65,6 +65,8 @@ public static function build_cache($type, $ids) {
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 @@ public static function build_cache($type, $ids) {
$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 @@ public static function build_cache($type, $ids) {
$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 @@ public function get_user_rating($user_id = null) {
"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 ccc9ec4aef..48ddd451fd 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -875,15 +875,16 @@ public static function play_url($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!
+ // 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 @@ public static function parse_song_url($url) {
*/
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 @@ public static function get_recently_played($user_id='') {
/**
* 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 5deee98eb0..35f0f4a3d9 100644
--- a/lib/class/stream.class.php
+++ b/lib/class/stream.class.php
@@ -186,7 +186,7 @@ public static function gc_session($ip='',$agent='',$uid='',$sid='') {
$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 @@ public static function _auto_init() {
/**
* 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 83548e3666..52c6f539a2 100644
--- a/lib/class/tag.class.php
+++ b/lib/class/tag.class.php
@@ -99,8 +99,9 @@ public function format($type=0,$object_id=0) {
/**
* 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 @@ public function set_object($type,$object_id) {
// 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 @@ public static function build_map_cache($type,$ids) {
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 @@ public static function get_top_tags($type,$object_id,$limit='10') {
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 e86c20efcf..2c24935eeb 100644
--- a/lib/class/update.class.php
+++ b/lib/class/update.class.php
@@ -1384,7 +1384,10 @@ public static function update_340018() {
// 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 b93fad0866..5e5b32c2b2 100644
--- a/lib/class/vainfo.class.php
+++ b/lib/class/vainfo.class.php
@@ -937,7 +937,7 @@ private function _parse_filename($filename) {
$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 0568026b45..d69078b0d6 100644
--- a/lib/class/vauth.class.php
+++ b/lib/class/vauth.class.php
@@ -84,7 +84,7 @@ public static function read($key) {
*/
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 @@ public static function logout($key='', $relogin=true) {
// 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 @@ public static function _auto_init() {
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']);
diff --git a/lib/debug.lib.php b/lib/debug.lib.php
index 9347fed268..4464447eee 100644
--- a/lib/debug.lib.php
+++ b/lib/debug.lib.php
@@ -163,20 +163,20 @@ function check_php_pcre() {
function check_config_values($conf) {
if (!$conf['database_hostname']) {
- return false;
- }
- if (!$conf['database_name']) {
- return false;
- }
- if (!$conf['database_username']) {
- return false;
- }
- if (!$conf['database_password']) {
- return false;
- }
- if (!$conf['session_length']) {
- return false;
- }
+ return false;
+ }
+ if (!$conf['database_name']) {
+ return false;
+ }
+ if (!$conf['database_username']) {
+ return false;
+ }
+ if (!$conf['database_password']) {
+ return false;
+ }
+ if (!$conf['session_length']) {
+ return false;
+ }
if (!$conf['session_name']) {
return false;
}
@@ -192,7 +192,7 @@ function check_config_values($conf) {
}
}
- return true;
+ return true;
} // check_config_values
@@ -311,35 +311,35 @@ function generate_config($current) {
/* Start building the new config file */
$distfile = Config::get('prefix') . '/config/ampache.cfg.php.dist';
- $handle = fopen($distfile,'r');
- $dist = fread($handle,filesize($distfile));
- fclose($handle);
+ $handle = fopen($distfile,'r');
+ $dist = fread($handle,filesize($distfile));
+ fclose($handle);
- $data = explode("\n",$dist);
+ $data = explode("\n",$dist);
- /* Run throught the lines and set our settings */
- foreach ($data as $line) {
+ /* Run throught the lines and set our settings */
+ foreach ($data as $line) {
- /* Attempt to pull out Key */
- if (preg_match("/^;?([\w\d]+)\s+=\s+[\"]{1}(.*?)[\"]{1}$/",$line,$matches)
+ /* Attempt to pull out Key */
+ if (preg_match("/^;?([\w\d]+)\s+=\s+[\"]{1}(.*?)[\"]{1}$/",$line,$matches)
|| preg_match("/^;?([\w\d]+)\s+=\s+[\']{1}(.*?)[\']{1}$/", $line, $matches)
- || preg_match("/^;?([\w\d]+)\s+=\s+[\'\"]{0}(.*)[\'\"]{0}$/",$line,$matches)) {
+ || preg_match("/^;?([\w\d]+)\s+=\s+[\'\"]{0}(.*)[\'\"]{0}$/",$line,$matches)) {
$key = $matches[1];
- $value = $matches[2];
+ $value = $matches[2];
- /* Put in the current value */
+ /* Put in the current value */
if ($key == 'config_version') {
$line = $key . ' = ' . $value;
}
- elseif (isset($current[$key])) {
- $line = $key . ' = "' . $current[$key] . '"';
- unset($current[$key]);
+ elseif (isset($current[$key])) {
+ $line = $key . ' = "' . $current[$key] . '"';
+ unset($current[$key]);
} // if set
} // if key
- $final .= $line . "\n";
+ $final .= $line . "\n";
} // end foreach line
diff --git a/lib/gettext.php b/lib/gettext.php
index 6c88b057e9..c73ad50112 100644
--- a/lib/gettext.php
+++ b/lib/gettext.php
@@ -20,10 +20,10 @@
*/
-/*!
- @function load_gettext
- @discussion sets the local
-*/
+/**
+ * load_gettext
+ * Sets up our local gettext settings.
+ */
function load_gettext() {
/* If we have gettext */
if (function_exists('bindtextdomain')) {
@@ -57,9 +57,9 @@ function load_gettext() {
*/
function __($string,$subject,$replace) {
- $translated = _($string);
- $result = str_replace($subject,$replace,$translated);
- return $result;
+ $translated = _($string);
+ $result = str_replace($subject,$replace,$translated);
+ return $result;
} // __
diff --git a/lib/init.php b/lib/init.php
index 6b3fef8a65..59f1ba4faf 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -33,10 +33,8 @@
exit;
}
-error_reporting(E_ERROR); // Only show fatal errors in production
+error_reporting(E_ERROR); // Only show fatal errors in production
-// This makes this file nolonger need customization
-// the config file is in the same dir as this (init.php) file.
$ampache_path = dirname(__FILE__);
$prefix = realpath($ampache_path . "/../");
$configfile = "$prefix/config/ampache.cfg.php";
@@ -52,7 +50,7 @@
Config::set('prefix',$prefix);
/*
- Check to see if this is Http or https
+ Check to see if this is http or https
*/
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$http_type = "https://";
@@ -62,18 +60,18 @@
}
/*
- See if the Config File Exists if it doesn't
- then go ahead and move them over to the install
- script
+ Check to make sure the config file exists. If it doesn't then go ahead and send
+ them over to the install script.
*/
if (!file_exists($configfile)) {
- $path = preg_replace("/(.*)\/(\w+\.php)$/","\${1}", $_SERVER['PHP_SELF']);
+ $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
+// Use the built in PHP function, suppress errors here so we can handle it
+// properly below
$results = @parse_ini_file($configfile);
if (!count($results)) {
@@ -83,7 +81,7 @@
exit();
}
-/** Verify a few commonly removed PHP functions exist and re-direct to /test if not **/
+/** Verify a few commonly disabled 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)) {
$path = preg_replace("/(.*)\/(\w+\.php)$/","\${1}", $_SERVER['PHP_SELF']);
$link = $http_type . $_SERVER['HTTP_HOST'] . $path . "/test.php";
@@ -153,9 +151,8 @@
Config::set_by_array($results,1);
-// Modules (These are conditionaly included depending upon config values)
+// Modules (These are conditionally included depending upon config values)
if (Config::get('ratings')) {
- require_once $prefix . '/lib/class/rating.class.php';
require_once $prefix . '/lib/rating.lib.php';
}
@@ -169,20 +166,20 @@
ini_set('post_max_size','8M');
}
-if ($results['memory_limit'] < 24) {
+// In case the local setting is 0
+ini_set('session.gc_probability','5');
+
+if (! isset($results['memory_limit']) || $results['memory_limit'] < 24) {
$results['memory_limit'] = 24;
}
-// Incase the local setting is 0
-ini_set('session.gc_probability','5');
-
set_memory_limit($results['memory_limit']);
/**** END Set PHP Vars ****/
// If we want a session
-if (NO_SESSION != '1' AND Config::get('use_auth')) {
- /* Verify Their session */
+if (!defined('NO_SESSION') && 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; }
// This actually is starting the session
@@ -191,7 +188,7 @@
/* Create the new user */
$GLOBALS['user'] = User::get_from_username($_SESSION['userdata']['username']);
- /* If they user ID doesn't exist deny them */
+ /* If the user ID doesn't exist deny them */
if (!$GLOBALS['user']->id AND !Config::get('demo_mode')) { vauth::logout(session_id()); exit; }
vauth::session_extend(session_id());
@@ -223,9 +220,9 @@
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'];
+ $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();
@@ -266,7 +263,7 @@
unset($array);
unset($results);
-/* Setup the flip class */
+/* Set up the flip class */
flip_class(array('odd','even'));
/* Check to see if we need to perform an update */
@@ -284,7 +281,7 @@
error_reporting(E_ALL);
}
-// Merge GET then POST into REQUEST effectivly striping COOKIE without depending on
-// a PHP setting change to take affect
+// Merge GET then POST into REQUEST effectively stripping COOKIE without
+// depending on a PHP setting change for the effect
$_REQUEST = array_merge($_GET,$_POST);
?>
diff --git a/lib/install.php b/lib/install.php
index 655bb25dea..5ba4d0d310 100644
--- a/lib/install.php
+++ b/lib/install.php
@@ -22,8 +22,7 @@
/**
* split_sql
- * splits up a standard SQL dump file into distinct
- * sql queryies
+ * splits up a standard SQL dump file into distinct sql queries
*/
function split_sql($sql) {
$sql = trim($sql);
diff --git a/play/index.php b/play/index.php
index 88e02b84aa..eb1b2d5a20 100644
--- a/play/index.php
+++ b/play/index.php
@@ -304,7 +304,8 @@
} // if downsample remote is enabled
// If they are downsampling, or if the song is not a native stream or it's non-local
-if ((Config::get('transcode') == 'always' || !$media->native_stream() || $not_local) && Config::get('transcode') != 'never') {
+if ((Config::get('transcode') == 'always' || !$media->native_stream() ||
+ isset($not_local)) && Config::get('transcode') != 'never') {
debug_event('Downsample','Starting Downsample {Transcode:' . Config::get('transcode') . '} {Native Stream:' . $media->native_stream() .'} {Not Local:' . $not_local . '}','5');
$fp = Stream::start_downsample($media,$lastid,$media_name,$start);
$media_name = $media->f_artist_full . " - " . $media->title . "." . $media->type;
diff --git a/server/ajax.server.php b/server/ajax.server.php
index ecba702658..631ca628d0 100644
--- a/server/ajax.server.php
+++ b/server/ajax.server.php
@@ -37,7 +37,9 @@
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
-switch ($_REQUEST['page']) {
+$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
+
+switch ($page) {
case 'flag':
require_once Config::get('prefix') . '/server/flag.ajax.php';
exit;
diff --git a/server/browse.ajax.php b/server/browse.ajax.php
index f512329cb1..db8b002d4d 100644
--- a/server/browse.ajax.php
+++ b/server/browse.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
if (isset($_REQUEST['browse_id'])) {
$browse_id = $_REQUEST['browse_id'];
diff --git a/server/democratic.ajax.php b/server/democratic.ajax.php
index 1e257d5a8b..48fc6fd09b 100644
--- a/server/democratic.ajax.php
+++ b/server/democratic.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
$democratic = Democratic::get_current_playlist();
$democratic->set_parent();
diff --git a/server/flag.ajax.php b/server/flag.ajax.php
index 4daccb5c62..6573ebd4ad 100644
--- a/server/flag.ajax.php
+++ b/server/flag.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
switch ($_REQUEST['action']) {
case 'reject':
diff --git a/server/index.ajax.php b/server/index.ajax.php
index e84e5bf55c..e1cbedffcb 100644
--- a/server/index.ajax.php
+++ b/server/index.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
switch ($_REQUEST['action']) {
case 'random_albums':
diff --git a/server/localplay.ajax.php b/server/localplay.ajax.php
index 8f289d727f..c056539b2f 100644
--- a/server/localplay.ajax.php
+++ b/server/localplay.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
switch ($_REQUEST['action']) {
case 'set_instance':
diff --git a/server/playlist.ajax.php b/server/playlist.ajax.php
index 289e7f46d0..f22d9d0b68 100644
--- a/server/playlist.ajax.php
+++ b/server/playlist.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
switch ($_REQUEST['action']) {
case 'delete_track':
diff --git a/server/random.ajax.php b/server/random.ajax.php
index 0bf340d576..180ae7579b 100644
--- a/server/random.ajax.php
+++ b/server/random.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
switch ($_REQUEST['action']) {
case 'album':
diff --git a/server/song.ajax.php b/server/song.ajax.php
index 14f354d26d..00015954da 100644
--- a/server/song.ajax.php
+++ b/server/song.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
switch ($_REQUEST['action']) {
case 'flip_state':
diff --git a/server/stats.ajax.php b/server/stats.ajax.php
index 3b824c5fec..fdf8cf8aa2 100644
--- a/server/stats.ajax.php
+++ b/server/stats.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
switch ($_REQUEST['action']) {
default:
diff --git a/server/stream.ajax.php b/server/stream.ajax.php
index 01d6396f73..c49d79d4a9 100644
--- a/server/stream.ajax.php
+++ b/server/stream.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
switch ($_REQUEST['action']) {
case 'set_play_type':
diff --git a/server/tag.ajax.php b/server/tag.ajax.php
index 7fd3febdff..e7242dded5 100644
--- a/server/tag.ajax.php
+++ b/server/tag.ajax.php
@@ -21,9 +21,9 @@
*/
/**
- * Sub-Ajax page, requires AJAX_INCLUDE as one
+ * Sub-Ajax page, requires AJAX_INCLUDE
*/
-if (AJAX_INCLUDE != '1') { exit; }
+if (!defined('AJAX_INCLUDE')) { exit; }
switch ($_REQUEST['action']) {
case 'show_add_tag':
diff --git a/stream.php b/stream.php
index 7e0ab8b37c..193e69ba56 100644
--- a/stream.php
+++ b/stream.php
@@ -164,7 +164,9 @@
/* Start the Stream */
debug_event('stream.php' , 'Stream Type: '.$stream_type.' Media IDs: '.$media_ids, '5');
$stream = new Stream($stream_type,$media_ids);
- $stream->add_urls($urls);
+ if (isset($urls)) {
+ $stream->add_urls($urls);
+ }
$stream->start();
} // end method switch
diff --git a/templates/footer.inc.php b/templates/footer.inc.php
index 8a0ac738d5..1c051cd325 100644
--- a/templates/footer.inc.php
+++ b/templates/footer.inc.php
@@ -22,7 +22,7 @@
*/
?>
-
+
diff --git a/templates/rightbar.inc.php b/templates/rightbar.inc.php
index 55fcf26feb..51f8d97885 100644
--- a/templates/rightbar.inc.php
+++ b/templates/rightbar.inc.php
@@ -79,7 +79,7 @@
$objects = array();
//FIXME :: this is kludgy
- if (NO_SONGS != '1') {
+ if (!defined('NO_SONGS')) {
$objects = $GLOBALS['user']->playlist->get_items();
}
@@ -108,7 +108,7 @@
-
+
...
diff --git a/templates/show_album.inc.php b/templates/show_album.inc.php
index 928ffbb354..3c49a3d1a6 100644
--- a/templates/show_album.inc.php
+++ b/templates/show_album.inc.php
@@ -24,15 +24,16 @@
$ajax_url = Config::get('ajax_url');
// Title for this album
+$title = scrub_out($album->name) . ' (' . $album->year . ')';
if ($album->disk) {
- $disk = "disk. "\">, " . _('Disk') . " " . $album->disk . "";
+ $title .= "disk . "\">, " . _('Disk') . " " . $album->disk . "";
}
-$title = scrub_out($album->name) . ' (' . $album->year . ')' . $disk .' - ' . $album->f_artist_link;
+$title .= ' - ' . $album->f_artist_link;
?>
name != _('Unknown (Orphaned)')) {
$name = '[' . $album->f_artist . '] ' . scrub_out($album->full_name);
$aa_url = $web_path . "/image.php?id=" . $album->id . "&type=popup&sid=" . session_id();
diff --git a/templates/show_install.inc.php b/templates/show_install.inc.php
index 250219f3b6..963267cc90 100644
--- a/templates/show_install.inc.php
+++ b/templates/show_install.inc.php
@@ -19,7 +19,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-if (INSTALL != '1') { exit; }
+if (!defined('INSTALL')) { exit; }
$prefix = realpath(dirname(__FILE__). "/../");
$dir = is_rtl($htmllang) ? 'rtl' : 'ltr';
?>
diff --git a/templates/show_install_account.inc.php b/templates/show_install_account.inc.php
index ef1a967614..826c88bd98 100644
--- a/templates/show_install_account.inc.php
+++ b/templates/show_install_account.inc.php
@@ -20,7 +20,7 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-if (INSTALL != '1') { exit; }
+if (!defined('INSTALL')) { exit; }
$prefix = realpath(dirname(__FILE__). "/../");
?>
diff --git a/templates/show_install_config.inc.php b/templates/show_install_config.inc.php
index ba4dd9af9d..bbf38e3426 100644
--- a/templates/show_install_config.inc.php
+++ b/templates/show_install_config.inc.php
@@ -20,7 +20,7 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-if (INSTALL != '1') { exit; }
+if (!defined('INSTALL')) { exit; }
$prefix = realpath(dirname(__FILE__). "/../");
?>
diff --git a/templates/show_install_lang.inc.php b/templates/show_install_lang.inc.php
index 581af6343b..803c41ac09 100644
--- a/templates/show_install_lang.inc.php
+++ b/templates/show_install_lang.inc.php
@@ -21,7 +21,7 @@
*/
$prefix = realpath(dirname(__FILE__). "/../");
?>
-
+
diff --git a/templates/sidebar_home.inc.php b/templates/sidebar_home.inc.php
index 3593fb5029..b4fd1ec815 100644
--- a/templates/sidebar_home.inc.php
+++ b/templates/sidebar_home.inc.php
@@ -25,8 +25,10 @@