Skip to content

Commit

Permalink
Fix ampache#173. Fix rating. Fix plenty of Warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
SUTJael committed Mar 27, 2014
1 parent c174c2b commit 7e4e12f
Show file tree
Hide file tree
Showing 23 changed files with 256 additions and 176 deletions.
72 changes: 37 additions & 35 deletions image.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,45 +81,47 @@
break;
} // define size based on thumbnail

switch ($_GET['type']) {
case 'popup':
require_once AmpConfig::get('prefix') . '/templates/show_big_art.inc.php';
break;
// If we need to pull the data out of the session
case 'session':
Session::check();
$filename = scrub_in($_REQUEST['image_index']);
$image = Art::get_from_source($_SESSION['form']['images'][$filename], 'album');
$mime = $_SESSION['form']['images'][$filename]['mime'];
break;
default:
$media = new $type($_GET['id']);
$filename = $media->name;

$art = new Art($media->id,$type);
$art->get_db();
$image = '';
$typeManaged = false;
if (isset($_GET['type'])) {
switch ($_GET['type']) {
case 'popup':
$typeManaged = true;
require_once AmpConfig::get('prefix') . '/templates/show_big_art.inc.php';
break;
case 'session':
// If we need to pull the data out of the session
Session::check();
$filename = scrub_in($_REQUEST['image_index']);
$image = Art::get_from_source($_SESSION['form']['images'][$filename], 'album');
$mime = $_SESSION['form']['images'][$filename]['mime'];
$typeManaged = true;
break;
}
}
if (!$typeManaged) {
$media = new $type($_GET['id']);
$filename = $media->name;

if (!$art->raw_mime) {
$mime = 'image/jpeg';
$image = file_get_contents(AmpConfig::get('prefix') .
AmpConfig::get('theme_path') .
'/images/blankalbum.jpg');
} else {
if ($_GET['thumb']) {
$thumb_data = $art->get_thumb($size);
}
$art = new Art($media->id,$type);
$art->get_db();

$mime = $thumb_data
? $thumb_data['thumb_mime']
: $art->raw_mime;
$image = $thumb_data
? $thumb_data['thumb']
: $art->raw;
if (!$art->raw_mime) {
$mime = 'image/jpeg';
$image = file_get_contents(AmpConfig::get('prefix') .
AmpConfig::get('theme_path') .
'/images/blankalbum.jpg');
} else {
if ($_GET['thumb']) {
$thumb_data = $art->get_thumb($size);
}
break;
} // end switch type

if ($image) {
$mime = isset($thumb_data['thumb_mime']) ? $thumb_data['thumb_mime'] : $art->raw_mime;
$image = isset($thumb_data['thumb']) ? $thumb_data['thumb'] : $art->raw;
}
}

if (!empty($image)) {
$extension = Art::extension($mime);
$filename = scrub_out($filename . '.' . $extension);

Expand Down
4 changes: 3 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

$action = isset($_REQUEST['action']) ? scrub_in($_REQUEST['action']) : null;

session_start();
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$_SESSION['catalog'] = 0;

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/class/album.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,13 @@ public function get_group_disks_ids()
* get_album_suite
* gets the album ids with the same musicbrainz identifier
*/
public function get_album_suite()
public function get_album_suite($catalog = '')
{
$results = array();

$catalog_where = "";
$catalog_join = "LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
if ($catalog) {
if (!empty($catalog)) {
$catalog_where .= " AND `catalog`.`id` = '$catalog'";
}
if (AmpConfig::get('catalog_disable')) {
Expand Down
6 changes: 4 additions & 2 deletions lib/class/browse.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ public function add_supplemental_object($class, $uid)
*/
public function get_supplemental_objects()
{
$objects = $_SESSION['browse']['supplemental'][$this->id];
$objects = isset($_SESSION['browse']['supplemental'][$this->id]) ? $_SESSION['browse']['supplemental'][$this->id] : '';

if (!is_array($objects)) { $objects = array(); }
if (!is_array($objects)) {
$objects = array();
}

return $objects;

Expand Down
2 changes: 1 addition & 1 deletion lib/class/preference.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public static function fix_preferences($results)
*/
public static function load_from_session($uid=-1)
{
if (is_array($_SESSION['userdata']['preferences']) AND $_SESSION['userdata']['uid'] == $uid) {
if (isset($_SESSION['userdata']['preferences']) && is_array($_SESSION['userdata']['preferences']) AND $_SESSION['userdata']['uid'] == $uid) {
AmpConfig::set_by_array($_SESSION['userdata']['preferences'], true);
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/class/query.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ private function get_limit_sql()
*/
private function get_join_sql()
{
if (!is_array($this->_state['join'])) {
if (!isset($this->_state['join']) || !is_array($this->_state['join'])) {
return '';
}

Expand All @@ -1033,7 +1033,7 @@ private function get_join_sql()
*/
public function get_having_sql()
{
$sql = $this->_state['having'];
$sql = isset($this->_state['having']) ? $this->_state['having'] : '';

return $sql;

Expand All @@ -1049,7 +1049,7 @@ public function get_sql($limit = true)
{
$sql = $this->get_base_sql();

if (!$this->_state['custom']) {
if (!isset($this->_state['custom']) || !$this->_state['custom']) {
$filter_sql = $this->get_filter_sql();
$join_sql = $this->get_join_sql();
$having_sql = $this->get_having_sql();
Expand All @@ -1074,7 +1074,7 @@ public function get_sql($limit = true)
*/
private function post_process($data)
{
$tags = $this->_state['filter']['tag'];
$tags = isset($this->_state['filter']['tag']) ? $this->_state['filter']['tag'] : '';

if (!is_array($tags) || sizeof($tags) < 2) {
return $data;
Expand Down
12 changes: 6 additions & 6 deletions lib/class/rating.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ public function get_user_rating($user_id = null)
$user_id = $GLOBALS['user']->id;
}

$key = 'rating_' . $type . '_user' . $user_id;
$key = 'rating_' . $this->type . '_user' . $user_id;
if (parent::is_cached($key, $this->id)) {
return parent::get_from_cache($key, $this->id);
}

$sql = "SELECT `rating` FROM `rating` WHERE `user` = ? ".
"AND `object_id` = ? AND `object_type` = ?";
$db_results = Dba::read($sql, array($user_id, $this->id, $type));
$db_results = Dba::read($sql, array($user_id, $this->id, $this->type));

$rating = 0;

Expand All @@ -149,8 +149,8 @@ public function get_user_rating($user_id = null)
*/
public function get_average_rating()
{
if (parent::is_cached('rating_' . $type . '_all', $id)) {
return parent::get_from_cache('rating_' . $type . '_user', $id);
if (parent::is_cached('rating_' . $this->type . '_all', $this->id)) {
return parent::get_from_cache('rating_' . $this->type . '_user', $this->id);
}

$sql = "SELECT AVG(`rating`) as `rating` FROM `rating` WHERE " .
Expand All @@ -159,7 +159,7 @@ public function get_average_rating()

$results = Dba::fetch_assoc($db_results);

parent::add_to_cache('rating_' . $type . '_all', $id, $results['rating']);
parent::add_to_cache('rating_' . $this->type . '_all', $this->id, $results['rating']);
return $results['rating'];

} // get_average_rating
Expand Down Expand Up @@ -264,7 +264,7 @@ public static function show($object_id, $type, $static=false)
if (!AmpConfig::get('ratings')) { return false; }

$rating = new Rating($object_id, $type);

if ($static) {
require AmpConfig::get('prefix') . '/templates/show_static_object_rating.inc.php';
} else {
Expand Down
10 changes: 8 additions & 2 deletions lib/class/session.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,16 @@ public static function create($data)
break;
} // end switch on data type

$username = $data['username'];
$username = '';
if (isset($data['username'])) {
$username = $data['username'];
}
$ip = $_SERVER['REMOTE_ADDR'] ? inet_pton($_SERVER['REMOTE_ADDR']) : '0';
$type = $data['type'];
$value = $data['value'];
$value = '';
if (isset($data['value'])) {
$value = $data['value'];
}
$agent = (!empty($data['agent'])) ? $data['agent'] : substr($_SERVER['HTTP_USER_AGENT'], 0, 254);

if ($type == 'stream') {
Expand Down
12 changes: 9 additions & 3 deletions lib/class/song.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public static function build_cache($song_ids)
}
$db_results = Dba::read($sql);

$artists = array();
$albums = array();
$tags = array();

while ($row = Dba::fetch_assoc($db_results)) {
if (AmpConfig::get('show_played_times')) {
$row['object_cnt'] = Stats::get_object_count('song', $row['id']);
Expand All @@ -200,7 +204,7 @@ public static function build_cache($song_ids)
Artist::build_cache($artists);
Album::build_cache($albums);
Tag::build_cache($tags);
Tag::build_map_cache('song',$song_ids);
Tag::build_map_cache('song', $song_ids);
Art::build_cache($albums);

// If we're rating this then cache them as well
Expand Down Expand Up @@ -824,8 +828,10 @@ public function format()
$this->fill_ext_info();

// Format the filename
preg_match("/^.*\/(.*?)$/",$this->file, $short);
$this->f_file = htmlspecialchars($short[1]);
preg_match("/^.*\/(.*?)$/", $this->file, $short);
if (is_array($short) && isset($short[1])) {
$this->f_file = htmlspecialchars($short[1]);
}

// Format the album name
$this->f_album_full = $this->get_album_name();
Expand Down
2 changes: 1 addition & 1 deletion lib/class/ui.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static function get_icon($name, $title = null, $id = null)
*/
private static function _find_icon($name)
{
if ($url = self::$_icon_cache[$name]) {
if (isset(self::$_icon_cache[$name]) && $url = self::$_icon_cache[$name]) {
return $url;
}

Expand Down
64 changes: 57 additions & 7 deletions lib/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,24 +180,42 @@ function create_preference_input($name,$value)
case 'share_social':
case 'broadcast_by_default':
case 'album_group':
if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; }
$is_true = '';
$is_false = '';
if ($value == '1') {
$is_true = "selected=\"selected\""; }
else {
$is_false = "selected=\"selected\"";
}
echo "<select name=\"$name\">\n";
echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n";
echo "\t<option value=\"0\" $is_false>" . T_("Disable") . "</option>\n";
echo "</select>\n";
break;
case 'play_type':
if ($value == 'localplay') { $is_local = 'selected="selected"'; } elseif ($value == 'democratic') { $is_vote = 'selected="selected"'; } elseif ($value == 'web_player') { $is_web_player = 'selected="selected"'; } else { $is_stream = "selected=\"selected\""; }
$is_localplay = '';
$is_democratic = '';
$is_web_player = '';
$is_stream = '';
if ($value == 'localplay') {
$is_localplay = 'selected="selected"';
} elseif ($value == 'democratic') {
$is_democratic = 'selected="selected"';
} elseif ($value == 'web_player') {
$is_web_player = 'selected="selected"';
} else {
$is_stream = "selected=\"selected\"";
}
echo "<select name=\"$name\">\n";
echo "\t<option value=\"\">" . T_('None') . "</option>\n";
if (AmpConfig::get('allow_stream_playback')) {
echo "\t<option value=\"stream\" $is_stream>" . T_('Stream') . "</option>\n";
}
if (AmpConfig::get('allow_democratic_playback')) {
echo "\t<option value=\"democratic\" $is_vote>" . T_('Democratic') . "</option>\n";
echo "\t<option value=\"democratic\" $is_democratic>" . T_('Democratic') . "</option>\n";
}
if (AmpConfig::get('allow_localplay_playback')) {
echo "\t<option value=\"localplay\" $is_local>" . T_('Localplay') . "</option>\n";
echo "\t<option value=\"localplay\" $is_localplay>" . T_('Localplay') . "</option>\n";
}
echo "\t<option value=\"web_player\" $is_web_player>" . _('Web Player') . "</option>\n";
echo "</select>\n";
Expand Down Expand Up @@ -236,7 +254,18 @@ function create_preference_input($name,$value)
echo "</select>\n";
break;
case 'localplay_level':
if ($value == '25') { $is_user = 'selected="selected"'; } elseif ($value == '100') { $is_admin = 'selected="selected"'; } elseif ($value == '50') { $is_manager = 'selected="selected"'; }
$is_user = '';
$is_admin = '';
$is_manager = '';
if ($value == '25') {
$is_user = 'selected="selected"';
}
elseif ($value == '100') {
$is_admin = 'selected="selected"';
}
elseif ($value == '50') {
$is_manager = 'selected="selected"';
}
echo "<select name=\"$name\">\n";
echo "<option value=\"0\">" . T_('Disabled') . "</option>\n";
echo "<option value=\"25\" $is_user>" . T_('User') . "</option>\n";
Expand Down Expand Up @@ -272,14 +301,35 @@ function create_preference_input($name,$value)
echo "</select>\n";
break;
case 'show_lyrics':
if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; }
$is_true = '';
$is_false = '';
if ($value == '1') {
$is_true = "selected=\"selected\"";
} else {
$is_false = "selected=\"selected\"";
}
echo "<select name=\"$name\">\n";
echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n";
echo "\t<option value=\"0\" $is_false>" . T_("Disable") . "</option>\n";
echo "</select>\n";
break;
case 'album_sort':
if ($value == 'year_asc') { $is_sort_year_asc = 'selected="selected"'; } elseif ($value == 'year_desc') { $is_sort_year_desc = 'selected="selected"'; } elseif ($value == 'name_asc') { $is_sort_name_asc = 'selected="selected"'; } elseif ($value == 'name_desc') { $is_sort_name_desc = 'selected="selected"'; } else { $is_sort_default = 'selected="selected"'; }
$is_sort_year_asc = '';
$is_sort_year_desc = '';
$is_sort_name_asc = '';
$is_sort_name_desc = '';
$is_sort_default = '';
if ($value == 'year_asc') {
$is_sort_year_asc = 'selected="selected"';
} elseif ($value == 'year_desc') {
$is_sort_year_desc = 'selected="selected"';
} elseif ($value == 'name_asc') {
$is_sort_name_asc = 'selected="selected"';
} elseif ($value == 'name_desc') {
$is_sort_name_desc = 'selected="selected"';
} else {
$is_sort_default = 'selected="selected"';
}

echo "<select name=\"$name\">\n";
echo "\t<option value=\"default\" $is_sort_default>" . T_('Default') . "</option>\n";
Expand Down
4 changes: 2 additions & 2 deletions lib/ui.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function show_playlist_select($name,$selected='',$style='')

function xoutput_headers()
{
$output = $_REQUEST['xoutput'] ?: 'xml';
$output = (isset($_REQUEST['xoutput']) && $_REQUEST['xoutput']) ?: 'xml';
if ($output == 'xml') {
header("Content-type: text/xml; charset=" . AmpConfig::get('site_charset'));
header("Content-Disposition: attachment; filename=ajax.xml");
Expand All @@ -363,7 +363,7 @@ function xoutput_headers()

function xoutput_from_array($array, $callback = false, $type = '')
{
$output = $_REQUEST['xoutput'] ?: 'xml';
$output = (isset($_REQUEST['xoutput']) && $_REQUEST['xoutput']) ?: 'xml';
if ($output == 'xml') {
return xml_from_array($array, $callback, $type);
} elseif ($output == 'raw') {
Expand Down
Loading

0 comments on commit 7e4e12f

Please sign in to comment.