mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 03:49:56 +02:00
Personal information visibility (Fix #81)
This commit is contained in:
parent
1bbeee0ef4
commit
9edffd6fb8
6 changed files with 154 additions and 57 deletions
|
@ -27,7 +27,7 @@
|
||||||
* This handles all of the preference stuff for Ampache
|
* This handles all of the preference stuff for Ampache
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Preference
|
class Preference extends database_object
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* __constructor
|
* __constructor
|
||||||
|
@ -39,6 +39,32 @@ class Preference
|
||||||
|
|
||||||
} // __construct
|
} // __construct
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get_by_user
|
||||||
|
* Return a preference for specific user identifier
|
||||||
|
*/
|
||||||
|
public static function get_by_user($user_id, $pref_name)
|
||||||
|
{
|
||||||
|
//debug_event('preference.class.php', 'Getting preference {'.$pref_name.'} for user identifier {'.$user_id.'}...', '5');
|
||||||
|
$user_id = Dba::escape($user_id);
|
||||||
|
$pref_name = Dba::escape($pref_name);
|
||||||
|
$id = self::id_from_name($pref_name);
|
||||||
|
|
||||||
|
if (parent::is_cached('get_by_user', $user_id)) {
|
||||||
|
return parent::get_from_cache('get_by_user', $user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = "SELECT `value` FROM `user_preference` WHERE `preference`='$id' AND `user`='$user_id'";
|
||||||
|
$db_results = Dba::read($sql);
|
||||||
|
$data = Dba::fetch_assoc($db_results);
|
||||||
|
|
||||||
|
parent::add_to_cache('get_by_user', $user_id, $data['value']);
|
||||||
|
|
||||||
|
return $data['value'];
|
||||||
|
|
||||||
|
} // get_by_user
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update
|
* update
|
||||||
* This updates a single preference from the given name or id
|
* This updates a single preference from the given name or id
|
||||||
|
@ -61,15 +87,17 @@ class Preference
|
||||||
|
|
||||||
// Now do
|
// Now do
|
||||||
if (self::has_access($name)) {
|
if (self::has_access($name)) {
|
||||||
$value = Dba::escape($value);
|
$value = Dba::escape($value);
|
||||||
$user_id = Dba::escape($user_id);
|
$user_id = Dba::escape($user_id);
|
||||||
$sql = "UPDATE `user_preference` SET `value`='$value' " .
|
$sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$id'$user_check";
|
||||||
"WHERE `preference`='$id'$user_check";
|
|
||||||
$db_results = Dba::write($sql);
|
$db_results = Dba::write($sql);
|
||||||
Preference::clear_from_session();
|
Preference::clear_from_session();
|
||||||
|
|
||||||
|
parent::remove_from_cache('get_by_user', user_id);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
debug_event('denied',$GLOBALS['user']->username . ' attempted to update ' . $name . ' but does not have sufficient permissions','3');
|
debug_event('denied', $GLOBALS['user']->username . ' attempted to update ' . $name . ' but does not have sufficient permissions','3');
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -88,8 +116,8 @@ class Preference
|
||||||
$preference_id = $preference;
|
$preference_id = $preference;
|
||||||
}
|
}
|
||||||
|
|
||||||
$preference_id = Dba::escape($preference_id);
|
$preference_id = Dba::escape($preference_id);
|
||||||
$level = Dba::escape($level);
|
$level = Dba::escape($level);
|
||||||
|
|
||||||
$sql = "UPDATE `preference` SET `level`='$level' WHERE `id`='$preference_id'";
|
$sql = "UPDATE `preference` SET `level`='$level' WHERE `id`='$preference_id'";
|
||||||
$db_results = Dba::write($sql);
|
$db_results = Dba::write($sql);
|
||||||
|
@ -104,12 +132,14 @@ class Preference
|
||||||
*/
|
*/
|
||||||
public static function update_all($preference_id,$value)
|
public static function update_all($preference_id,$value)
|
||||||
{
|
{
|
||||||
$preference_id = Dba::escape($preference_id);
|
$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'";
|
$sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$preference_id'";
|
||||||
$db_results = Dba::write($sql);
|
$db_results = Dba::write($sql);
|
||||||
|
|
||||||
|
parent::clear_cache();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} // update_all
|
} // update_all
|
||||||
|
@ -161,11 +191,16 @@ class Preference
|
||||||
{
|
{
|
||||||
$name = Dba::escape($name);
|
$name = Dba::escape($name);
|
||||||
|
|
||||||
|
if (parent::is_cached('id_from_name', $name)) {
|
||||||
|
return parent::get_from_cache('id_from_name', $name);
|
||||||
|
}
|
||||||
|
|
||||||
$sql = "SELECT `id` FROM `preference` WHERE `name`='$name'";
|
$sql = "SELECT `id` FROM `preference` WHERE `name`='$name'";
|
||||||
$db_results = Dba::read($sql);
|
$db_results = Dba::read($sql);
|
||||||
|
|
||||||
$row = Dba::fetch_assoc($db_results);
|
$row = Dba::fetch_assoc($db_results);
|
||||||
|
|
||||||
|
parent::add_to_cache('id_from_name', $name, $row['id']);
|
||||||
|
|
||||||
return $row['id'];
|
return $row['id'];
|
||||||
|
|
||||||
} // id_from_name
|
} // id_from_name
|
||||||
|
@ -226,8 +261,8 @@ class Preference
|
||||||
" INNER JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` " .
|
" INNER JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` " .
|
||||||
" WHERE `user_preference`.`user`='$user_id' AND `preference`.`catagory` != 'internal' $user_limit " .
|
" WHERE `user_preference`.`user`='$user_id' AND `preference`.`catagory` != 'internal' $user_limit " .
|
||||||
" ORDER BY `preference`.`description`";
|
" ORDER BY `preference`.`description`";
|
||||||
$db_results = Dba::read($sql);
|
|
||||||
|
|
||||||
|
$db_results = Dba::read($sql);
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
while ($row = Dba::fetch_assoc($db_results)) {
|
while ($row = Dba::fetch_assoc($db_results)) {
|
||||||
|
@ -241,17 +276,17 @@ class Preference
|
||||||
/**
|
/**
|
||||||
* insert
|
* insert
|
||||||
* This inserts a new preference into the preference table
|
* This inserts a new preference into the preference table
|
||||||
* it does NOT sync up the users, that should be done independtly
|
* it does NOT sync up the users, that should be done independently
|
||||||
*/
|
*/
|
||||||
public static function insert($name,$description,$default,$level,$type,$catagory)
|
public static function insert($name,$description,$default,$level,$type,$catagory)
|
||||||
{
|
{
|
||||||
// Clean em up
|
// Clean em up
|
||||||
$name = Dba::escape($name);
|
$name = Dba::escape($name);
|
||||||
$description = Dba::escape($description);
|
$description = Dba::escape($description);
|
||||||
$default = Dba::escape($default);
|
$default = Dba::escape($default);
|
||||||
$level = Dba::escape($level);
|
$level = Dba::escape($level);
|
||||||
$type = Dba::escape($type);
|
$type = Dba::escape($type);
|
||||||
$catagory = Dba::escape($catagory);
|
$catagory = Dba::escape($catagory);
|
||||||
|
|
||||||
$sql = "INSERT INTO `preference` (`name`,`description`,`value`,`level`,`type`,`catagory`) " .
|
$sql = "INSERT INTO `preference` (`name`,`description`,`value`,`level`,`type`,`catagory`) " .
|
||||||
"VALUES ('$name','$description','$default','$level','$type','$catagory')";
|
"VALUES ('$name','$description','$default','$level','$type','$catagory')";
|
||||||
|
@ -332,8 +367,8 @@ class Preference
|
||||||
|
|
||||||
foreach ($results as $key=>$data) {
|
foreach ($results as $key=>$data) {
|
||||||
if (!is_array($data)) {
|
if (!is_array($data)) {
|
||||||
if (strcasecmp($data,"true") == "0") { $results[$key] = 1; }
|
if (strcasecmp($data,"true") == "0") { $results[$key] = 1; }
|
||||||
if (strcasecmp($data,"false") == "0") { $results[$key] = 0; }
|
if (strcasecmp($data,"false") == "0") { $results[$key] = 0; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1020,7 +1020,7 @@ class Song extends database_object implements media
|
||||||
}
|
}
|
||||||
else if (!Access::check('interface','100')) {
|
else if (!Access::check('interface','100')) {
|
||||||
// If user identifier is empty, we need to retrieve only users which have allowed view of personnal info
|
// If user identifier is empty, we need to retrieve only users which have allowed view of personnal info
|
||||||
$personal_info_id = Preference::id_from_name('allow_personal_info');
|
$personal_info_id = Preference::id_from_name('allow_personal_info_recent');
|
||||||
if ($personal_info_id) {
|
if ($personal_info_id) {
|
||||||
$current_user = $GLOBALS['user']->id;
|
$current_user = $GLOBALS['user']->id;
|
||||||
$sql .= "AND `user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='$personal_info_id' AND `value`='1') OR `user`='$current_user') ";
|
$sql .= "AND `user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='$personal_info_id' AND `value`='1') OR `user`='$current_user') ";
|
||||||
|
|
|
@ -228,7 +228,7 @@ class Stream
|
||||||
|
|
||||||
if (!Access::check('interface','100')) {
|
if (!Access::check('interface','100')) {
|
||||||
// We need to check only for users which have allowed view of personnal info
|
// We need to check only for users which have allowed view of personnal info
|
||||||
$personal_info_id = Preference::id_from_name('allow_personal_info');
|
$personal_info_id = Preference::id_from_name('allow_personal_info_now');
|
||||||
if ($personal_info_id) {
|
if ($personal_info_id) {
|
||||||
$current_user = $GLOBALS['user']->id;
|
$current_user = $GLOBALS['user']->id;
|
||||||
$sql .= "WHERE (`now_playing`.`user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='$personal_info_id' AND `value`='1') OR `user`='$current_user')) ";
|
$sql .= "WHERE (`now_playing`.`user` IN (SELECT `user` FROM `user_preference` WHERE (`preference`='$personal_info_id' AND `value`='1') OR `user`='$current_user')) ";
|
||||||
|
|
|
@ -329,6 +329,11 @@ class Update
|
||||||
$update_string = '- Add option to allow/disallow to show personnal information to other users (now playing and recently played).<br />';
|
$update_string = '- Add option to allow/disallow to show personnal information to other users (now playing and recently played).<br />';
|
||||||
$version[] = array('version' => '360027','description' => $update_string);
|
$version[] = array('version' => '360027','description' => $update_string);
|
||||||
|
|
||||||
|
$update_string = '- Personnal information: allow/disallow to show in now playing.<br />'.
|
||||||
|
'- Personnal information: allow/disallow to show in recently played.<br />'.
|
||||||
|
'- Personnal information: allow/disallow to show time and/or agent in recently played.<br />';
|
||||||
|
$version[] = array('version' => '360028','description' => $update_string);
|
||||||
|
|
||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1814,7 +1819,7 @@ class Update
|
||||||
/**
|
/**
|
||||||
* update_360027
|
* update_360027
|
||||||
*
|
*
|
||||||
* This inserts the Album default sort preference...
|
* Personal information: allow/disallow to show my personal information into now playing and recently played lists.
|
||||||
*/
|
*/
|
||||||
public static function update_360027()
|
public static function update_360027()
|
||||||
{
|
{
|
||||||
|
@ -1829,4 +1834,44 @@ class Update
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update_360028
|
||||||
|
*
|
||||||
|
* Personal information: allow/disallow to show in now playing.
|
||||||
|
* Personal information: allow/disallow to show in recently played.
|
||||||
|
* Personal information: allow/disallow to show time and/or agent in recently played.
|
||||||
|
*/
|
||||||
|
public static function update_360028()
|
||||||
|
{
|
||||||
|
// Update previous update preference
|
||||||
|
$sql = "UPDATE `preference` SET `name`='allow_personal_info_now', `description`='Personal information visibility - Now playing' WHERE `name`='allow_personal_info'";
|
||||||
|
Dba::write($sql);
|
||||||
|
|
||||||
|
// Insert new recently played preference
|
||||||
|
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
|
||||||
|
"VALUES ('allow_personal_info_recent','1','Personal information visibility - Recently played',25,'boolean','interface')";
|
||||||
|
Dba::write($sql);
|
||||||
|
$id = Dba::insert_id();
|
||||||
|
$sql = "INSERT INTO `user_preference` VALUES (-1,?,'1')";
|
||||||
|
Dba::write($sql, array($id));
|
||||||
|
|
||||||
|
// Insert streaming time preference
|
||||||
|
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
|
||||||
|
"VALUES ('allow_personal_info_time','1','Personal information visibility - Recently played - Allow to show streaming date/time',25,'boolean','interface')";
|
||||||
|
Dba::write($sql);
|
||||||
|
$id = Dba::insert_id();
|
||||||
|
$sql = "INSERT INTO `user_preference` VALUES (-1,?,'1')";
|
||||||
|
Dba::write($sql, array($id));
|
||||||
|
|
||||||
|
// Insert streaming agent preference
|
||||||
|
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
|
||||||
|
"VALUES ('allow_personal_info_agent','1','Personal information visibility - Recently played - Allow to show streaming agent',25,'boolean','interface')";
|
||||||
|
Dba::write($sql);
|
||||||
|
$id = Dba::insert_id();
|
||||||
|
$sql = "INSERT INTO `user_preference` VALUES (-1,?,'1')";
|
||||||
|
Dba::write($sql, array($id));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,10 @@ function create_preference_input($name,$value)
|
||||||
case 'plex_backend':
|
case 'plex_backend':
|
||||||
case 'webplayer_flash':
|
case 'webplayer_flash':
|
||||||
case 'webplayer_html5':
|
case 'webplayer_html5':
|
||||||
case 'allow_personal_info':
|
case 'allow_personal_info_now':
|
||||||
|
case 'allow_personal_info_recent':
|
||||||
|
case 'allow_personal_info_time':
|
||||||
|
case 'allow_personal_info_agent':
|
||||||
if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; }
|
if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; }
|
||||||
echo "<select name=\"$name\">\n";
|
echo "<select name=\"$name\">\n";
|
||||||
echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n";
|
echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n";
|
||||||
|
|
|
@ -40,37 +40,51 @@ $thcount = 7;
|
||||||
<?php foreach ($data as $row) {
|
<?php foreach ($data as $row) {
|
||||||
$row_user = new User($row['user']);
|
$row_user = new User($row['user']);
|
||||||
$song = new Song($row['object_id']);
|
$song = new Song($row['object_id']);
|
||||||
$interval = intval(time() - $row['date']);
|
|
||||||
$agent = $row['agent'];
|
|
||||||
|
|
||||||
if ($interval < 60) {
|
$agent = '';
|
||||||
$unit = 'seconds';
|
$time_string = '-';
|
||||||
} else if ($interval < 3600) {
|
|
||||||
$interval = floor($interval / 60);
|
$is_allowed = Access::check('interface', '100') || $GLOBALS['user']->id == $row_user->id;
|
||||||
$unit = 'minutes';
|
if (!$is_allowed) {
|
||||||
} else if ($interval < 86400) {
|
$has_allowed_time = Preference::get_by_user($row_user->id, 'allow_personal_info_time');
|
||||||
$interval = floor($interval / 3600);
|
$has_allowed_agent = Preference::get_by_user($row_user->id, 'allow_personal_info_agent');
|
||||||
$unit = 'hours';
|
|
||||||
} else if ($interval < 604800) {
|
|
||||||
$interval = floor($interval / 86400);
|
|
||||||
$unit = 'days';
|
|
||||||
} else if ($interval < 2592000) {
|
|
||||||
$interval = floor($interval / 604800);
|
|
||||||
$unit = 'weeks';
|
|
||||||
} else if ($interval < 31556926) {
|
|
||||||
$interval = floor($interval / 2592000);
|
|
||||||
$unit = 'months';
|
|
||||||
} else if ($interval < 631138519) {
|
|
||||||
$interval = floor($interval / 31556926);
|
|
||||||
$unit = 'years';
|
|
||||||
} else {
|
|
||||||
$interval = floor($interval / 315569260);
|
|
||||||
$unit = 'decades';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// I wonder how smart gettext is?
|
if ($is_allowed || $has_allowed_agent) {
|
||||||
$time_string = sprintf(T_ngettext('%d ' . rtrim($unit, 's') . ' ago', '%d ' . $unit . ' ago', $interval), $interval);
|
$agent = $row['agent'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($is_allowed || $has_allowed_time) {
|
||||||
|
$interval = intval(time() - $row['date']);
|
||||||
|
|
||||||
|
if ($interval < 60) {
|
||||||
|
$unit = 'seconds';
|
||||||
|
} else if ($interval < 3600) {
|
||||||
|
$interval = floor($interval / 60);
|
||||||
|
$unit = 'minutes';
|
||||||
|
} else if ($interval < 86400) {
|
||||||
|
$interval = floor($interval / 3600);
|
||||||
|
$unit = 'hours';
|
||||||
|
} else if ($interval < 604800) {
|
||||||
|
$interval = floor($interval / 86400);
|
||||||
|
$unit = 'days';
|
||||||
|
} else if ($interval < 2592000) {
|
||||||
|
$interval = floor($interval / 604800);
|
||||||
|
$unit = 'weeks';
|
||||||
|
} else if ($interval < 31556926) {
|
||||||
|
$interval = floor($interval / 2592000);
|
||||||
|
$unit = 'months';
|
||||||
|
} else if ($interval < 631138519) {
|
||||||
|
$interval = floor($interval / 31556926);
|
||||||
|
$unit = 'years';
|
||||||
|
} else {
|
||||||
|
$interval = floor($interval / 315569260);
|
||||||
|
$unit = 'decades';
|
||||||
|
}
|
||||||
|
|
||||||
|
// I wonder how smart gettext is?
|
||||||
|
$time_string = sprintf(T_ngettext('%d ' . rtrim($unit, 's') . ' ago', '%d ' . $unit . ' ago', $interval), $interval);
|
||||||
|
}
|
||||||
$song->format();
|
$song->format();
|
||||||
?>
|
?>
|
||||||
<tr class="<?php echo UI::flip_class(); ?>">
|
<tr class="<?php echo UI::flip_class(); ?>">
|
||||||
|
@ -95,9 +109,9 @@ $thcount = 7;
|
||||||
</td>
|
</td>
|
||||||
<td class="cel_lastplayed"><?php echo $time_string; ?></td>
|
<td class="cel_lastplayed"><?php echo $time_string; ?></td>
|
||||||
<td class="cel_agent">
|
<td class="cel_agent">
|
||||||
<?php if ($agent != '') { ?>
|
<?php if (!empty($agent)) {
|
||||||
<?php echo UI::get_icon('info', $agent); ?>
|
echo UI::get_icon('info', $agent);
|
||||||
<?php } ?>
|
} ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue