Skip to content

Commit

Permalink
filter random/search types, code indent
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlan-00 committed May 27, 2021
1 parent dcc8fad commit c945384
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
28 changes: 14 additions & 14 deletions lib/class/search.class.php
Expand Up @@ -2039,20 +2039,20 @@ private function song_to_sql()
case 'myplayed':
case 'myplayedalbum':
case 'myplayedartist':
// combine these as they all do the same thing just different tables
$looking = str_replace('myplayed', '', $rule[0]);
$column = ($looking == '') ? 'id' : $looking;
$my_type = ($looking == '') ? 'song' : $looking;
$operator_sql = ((int) $sql_match_operator == 0) ? 'IS NULL' : 'IS NOT NULL';
// played once per user
$table['myplayed'] .= (!strpos((string) $table['myplayed'], "myplayed_" . $my_type . "_" . $userid)) ?
"LEFT JOIN (SELECT `object_id`, `object_type`, `user` FROM `object_count` " .
"WHERE `object_count`.`object_type` = '$my_type' AND `object_count`.`count_type` = 'stream' " .
"AND `object_count`.`user`=$userid GROUP BY `object_id`, `object_type`, `user`) AS " .
"`myplayed_" . $my_type . "_" . $userid . "` " .
"ON `song`.`$column`=`myplayed_" . $my_type . "_" . $userid . "`.`object_id` " .
"AND `myplayed_" . $my_type . "_" . $userid . "`.`object_type` = '$my_type' " : ' ';
$where[] = "`myplayed_" . $my_type . "_" . $userid . "`.`object_id` $operator_sql";
// combine these as they all do the same thing just different tables
$looking = str_replace('myplayed', '', $rule[0]);
$column = ($looking == '') ? 'id' : $looking;
$my_type = ($looking == '') ? 'song' : $looking;
$operator_sql = ((int) $sql_match_operator == 0) ? 'IS NULL' : 'IS NOT NULL';
// played once per user
$table['myplayed'] .= (!strpos((string) $table['myplayed'], "myplayed_" . $my_type . "_" . $userid)) ?
"LEFT JOIN (SELECT `object_id`, `object_type`, `user` FROM `object_count` " .
"WHERE `object_count`.`object_type` = '$my_type' AND `object_count`.`count_type` = 'stream' " .
"AND `object_count`.`user`=$userid GROUP BY `object_id`, `object_type`, `user`) AS " .
"`myplayed_" . $my_type . "_" . $userid . "` " .
"ON `song`.`$column`=`myplayed_" . $my_type . "_" . $userid . "`.`object_id` " .
"AND `myplayed_" . $my_type . "_" . $userid . "`.`object_type` = '$my_type' " : ' ';
$where[] = "`myplayed_" . $my_type . "_" . $userid . "`.`object_id` $operator_sql";
break;
case 'bitrate':
$input = $input * 1000;
Expand Down
2 changes: 1 addition & 1 deletion random.php
Expand Up @@ -28,7 +28,7 @@
// Switch on the actions
switch ($_REQUEST['action']) {
case 'get_advanced':
$object_ids = Random::advanced($_REQUEST['type'], $_POST);
$object_ids = Random::advanced(filter_input(INPUT_GET, 'type', FILTER_SANITIZE_SPECIAL_CHARS), $_POST);

// We need to add them to the active playlist
if (!empty($object_ids)) {
Expand Down
2 changes: 1 addition & 1 deletion templates/show_random.inc.php
Expand Up @@ -20,7 +20,7 @@
*
*/ ?>
<?php UI::show_box_top(T_('Play Random Selection'), 'box box_random'); ?>
<form id="random" method="post" enctype="multipart/form-data" action="<?php echo AmpConfig::get('web_path'); ?>/random.php?action=get_advanced&type=<?php echo Core::get_request('type') ? scrub_out(Core::get_request('type')) : 'song'; ?>">
<form id="random" method="post" enctype="multipart/form-data" action="<?php echo AmpConfig::get('web_path'); ?>/random.php?action=get_advanced&type=<?php echo (string) scrub_out(filter_input(INPUT_GET, 'type', FILTER_SANITIZE_SPECIAL_CHARS)) ?: 'song'; ?>">
<table class="tabledata">
<tr id="search_location">
<td><?php if ((string) filter_input(INPUT_GET, 'type', FILTER_SANITIZE_SPECIAL_CHARS) !== 'song') {
Expand Down
2 changes: 1 addition & 1 deletion templates/show_rules.inc.php
Expand Up @@ -27,7 +27,7 @@
}
$logic_operator = strtolower($logic_operator); ?>
<script src="<?php echo AmpConfig::get('web_path'); ?>/lib/javascript/search.js"></script>
<script src="<?php echo AmpConfig::get('web_path'); ?>/lib/javascript/search-data.php?type=<?php echo (string) filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES) ? scrub_out((string) filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)) : 'song'; ?>"></script>
<script src="<?php echo AmpConfig::get('web_path'); ?>/lib/javascript/search-data.php?type=<?php echo (string) scrub_out(filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)) ?: 'song'; ?>"></script>

<?php UI::show_box_top(T_('Rules') . "...", 'box box_rules'); ?>
<table class="tabledata">
Expand Down
2 changes: 1 addition & 1 deletion templates/show_search_form.inc.php
Expand Up @@ -21,7 +21,7 @@
*/

UI::show_box_top(T_('Search Ampache') . "...", 'box box_advanced_search'); ?>
<form id="search" name="search" method="post" action="<?php echo AmpConfig::get('web_path'); ?>/search.php?type=<?php echo (string) filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES) ? scrub_out((string) filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)) : 'song'; ?>" enctype="multipart/form-data" style="Display:inline">
<form id="search" name="search" method="post" action="<?php echo AmpConfig::get('web_path'); ?>/search.php?type=<?php echo (string) scrub_out(filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)) ?: 'song'; ?>" enctype="multipart/form-data" style="Display:inline">
<table class="tabledata">
<tr id="search_location">
<td><?php if ((string) filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES) !== 'song') { ?>
Expand Down

0 comments on commit c945384

Please sign in to comment.