mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-03 17:59:21 +02:00
Add Playlists to search and option to customize log filename (fix #147)
This commit is contained in:
parent
87b459bfa4
commit
5ea358d90e
9 changed files with 141 additions and 7 deletions
|
@ -469,6 +469,12 @@ debug_level = 5
|
|||
; DEFAULT: NULL
|
||||
;log_path = "/var/log/ampache"
|
||||
|
||||
; Log filename pattern
|
||||
; This defines where the log file name pattern.
|
||||
; %name.%Y%m%d.log will create a different log file every day.
|
||||
; DEFAULT: %name.%Y%m%d.log
|
||||
log_filename = "%name.%Y%m%d.log"
|
||||
|
||||
; Charset of generated HTML pages
|
||||
; Default of UTF-8 should work for most people
|
||||
; DEFAULT: UTF-8
|
||||
|
|
|
@ -59,6 +59,7 @@ class Playlist extends playlist_object
|
|||
public static function gc()
|
||||
{
|
||||
Dba::write("DELETE FROM `playlist_data` USING `playlist_data` LEFT JOIN `song` ON `song`.`id` = `playlist_data`.`object_id` WHERE `song`.`file` IS NULL AND `playlist_data`.`object_type`='song'");
|
||||
Dba::write("DELETE FROM `playlist` USING `playlist` LEFT JOIN `playlist_data` ON `playlist_data`.`playlist` = `playlist`.`id` WHERE `playlist_data`.`object_id` IS NULL");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +108,8 @@ class Playlist extends playlist_object
|
|||
public function format()
|
||||
{
|
||||
parent::format();
|
||||
$this->f_link = '<a href="' . AmpConfig::get('web_path') . '/playlist.php?action=show_playlist&playlist_id=' . $this->id . '">' . $this->f_name . '</a>';
|
||||
$this->f_link = AmpConfig::get('web_path') . '/playlist.php?action=show_playlist&playlist_id=' . $this->id;
|
||||
$this->f_name_link = '<a href="' . $this->f_link . '/playlist.php?action=show_playlist&playlist_id=' . $this->id . '">' . $this->f_name . '</a>';
|
||||
|
||||
} // format
|
||||
|
||||
|
|
|
@ -354,6 +354,13 @@ class Search extends playlist_object
|
|||
'widget' => array('select', $playlists)
|
||||
);
|
||||
|
||||
$this->types[] = array(
|
||||
'name' => 'playlist_name',
|
||||
'label' => T_('Playlist Name'),
|
||||
'type' => 'text',
|
||||
'widget' => array('input', 'text')
|
||||
);
|
||||
|
||||
$playlists = array();
|
||||
foreach (Search::get_searches() as $playlistid) {
|
||||
// Slightly different from the above so we don't instigate
|
||||
|
@ -443,6 +450,14 @@ class Search extends playlist_object
|
|||
'widget' => array('input', 'text')
|
||||
);
|
||||
break;
|
||||
case 'playlist':
|
||||
$this->types[] = array(
|
||||
'name' => 'name',
|
||||
'label' => T_('Name'),
|
||||
'type' => 'text',
|
||||
'widget' => array('input', 'text')
|
||||
);
|
||||
break;
|
||||
} // end switch on searchtype
|
||||
|
||||
} // end constructor
|
||||
|
@ -479,6 +494,7 @@ class Search extends playlist_object
|
|||
case 'artist':
|
||||
case 'video':
|
||||
case 'song':
|
||||
case 'playlist':
|
||||
$request['type'] = $data['type'];
|
||||
break;
|
||||
default:
|
||||
|
@ -1025,6 +1041,11 @@ class Search extends playlist_object
|
|||
case 'catalog':
|
||||
$where[] = "`song`.`catalog` $sql_match_operator '$input'";
|
||||
break;
|
||||
case 'playlist_name':
|
||||
$join['playlist'] = true;
|
||||
$join['playlist_data'] = true;
|
||||
$where[] = "`playlist`.`name` $sql_match_operator '$input'";
|
||||
break;
|
||||
case 'playlist':
|
||||
$join['playlist_data'] = true;
|
||||
$where[] = "`playlist_data`.`playlist` $sql_match_operator '$input'";
|
||||
|
@ -1087,6 +1108,9 @@ class Search extends playlist_object
|
|||
}
|
||||
if ($join['playlist_data']) {
|
||||
$table['playlist_data'] = "LEFT JOIN `playlist_data` ON `song`.`id`=`playlist_data`.`object_id` AND `playlist_data`.`object_type`='song'";
|
||||
if ($join['playlist']) {
|
||||
$table['playlist'] = "LEFT JOIN `playlist` ON `playlist_data`.`playlist`=`playlist`.`id`";
|
||||
}
|
||||
}
|
||||
|
||||
if ($join['catalog']) {
|
||||
|
@ -1159,4 +1183,69 @@ class Search extends playlist_object
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* playlist_to_sql
|
||||
*
|
||||
* Handles the generation of the SQL for playlist searches.
|
||||
*/
|
||||
private function playlist_to_sql()
|
||||
{
|
||||
$sql_logic_operator = $this->logic_operator;
|
||||
$where = array();
|
||||
$table = array();
|
||||
$join = array();
|
||||
|
||||
foreach ($this->rules as $rule) {
|
||||
$type = $this->name_to_basetype($rule[0]);
|
||||
foreach ($this->basetypes[$type] as $operator) {
|
||||
if ($operator['name'] == $rule[1]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$input = $this->_mangle_data($rule[2], $type, $operator);
|
||||
$sql_match_operator = $operator['sql'];
|
||||
|
||||
$where[] = "`playlist`.`type` = 'public'";
|
||||
|
||||
switch ($rule[0]) {
|
||||
case 'name':
|
||||
$where[] = "`playlist`.`name` $sql_match_operator '$input'";
|
||||
break;
|
||||
default:
|
||||
// Nihil
|
||||
break;
|
||||
} // switch on ruletype
|
||||
} // foreach rule
|
||||
|
||||
$join['playlist_data'] = true;
|
||||
$join['song'] = true;
|
||||
$join['catalog'] = true;
|
||||
|
||||
$where_sql = implode(" $sql_logic_operator ", $where);
|
||||
|
||||
if ($join['playlist_data']) {
|
||||
$table['playlist_data'] = "LEFT JOIN `playlist_data` ON `playlist_data`.`playlist` = `playlist`.`id`";
|
||||
}
|
||||
|
||||
if ($join['song']) {
|
||||
$table['song'] = "LEFT JOIN `song` ON `song`.`id`=`playlist_data`.`object_id`";
|
||||
$where_sql .= " AND `playlist_data`.`object_type` = 'song'";
|
||||
|
||||
if ($join['catalog']) {
|
||||
$table['catalog'] = "LEFT JOIN `catalog` AS `catalog_se` ON `catalog_se`.`id`=`song`.`catalog`";
|
||||
$where_sql .= " AND `catalog_se`.`enabled` = '1'";
|
||||
}
|
||||
}
|
||||
|
||||
$table_sql = implode(' ', $table);
|
||||
|
||||
return array(
|
||||
'base' => 'SELECT DISTINCT(`playlist`.`id`) FROM `playlist`',
|
||||
'join' => $join,
|
||||
'where' => $where,
|
||||
'where_sql' => $where_sql,
|
||||
'table' => $table,
|
||||
'table_sql' => $table_sql
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,15 +28,23 @@ function log_event($username, $event_name, $event_description, $log_name)
|
|||
{
|
||||
/* Set it up here to make sure it's _always_ the same */
|
||||
$time = time();
|
||||
// Turn time into strings
|
||||
$log_day = date('Ymd', $time);
|
||||
$log_time = date('Y-m-d H:i:s', $time);
|
||||
|
||||
/* must have some name */
|
||||
$log_name = $log_name ? $log_name : 'ampache';
|
||||
$username = $username ? $username : 'ampache';
|
||||
|
||||
$log_filename = AmpConfig::get('log_path') . "/$log_name.$log_day.log";
|
||||
$log_filename = AmpConfig::get('log_filename');
|
||||
if (empty($log_filename)) {
|
||||
$log_filename = "%name.%Y%m%d.log";
|
||||
}
|
||||
|
||||
$log_filename = str_replace("%name", $log_name, $log_filename);
|
||||
$log_filename = str_replace("%Y", date('Y'), $log_filename);
|
||||
$log_filename = str_replace("%m", date('m'), $log_filename);
|
||||
$log_filename = str_replace("%d", date('d'), $log_filename);
|
||||
|
||||
$log_filename = AmpConfig::get('log_path') . "/" . $log_filename;
|
||||
$log_line = "$log_time [$username] ($event_name) -> $event_description \n";
|
||||
|
||||
// Do the deed
|
||||
|
|
|
@ -117,6 +117,34 @@ switch ($_REQUEST['action']) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($target == 'anywhere' || $target == 'playlist') {
|
||||
$searchreq = array(
|
||||
'limit' => $limit,
|
||||
'type' => 'playlist',
|
||||
'rule_1_input' => $search,
|
||||
'rule_1_operator' => '2', // Starts with...
|
||||
'rule_1' => 'name',
|
||||
);
|
||||
$sres = Search::run($searchreq);
|
||||
// Litmit not reach, new search with another operator
|
||||
if (count($sres) < $limit) {
|
||||
$searchreq['limit'] = $limit - count($sres);
|
||||
$searchreq['rule_1_operator'] = '0';
|
||||
$sres = array_unique(array_merge($sres, Search::run($searchreq)));
|
||||
}
|
||||
foreach ($sres as $id) {
|
||||
$playlist = new Playlist($id);
|
||||
$playlist->format();
|
||||
$results[] = array(
|
||||
'type' => T_('Playlists'),
|
||||
'link' => $playlist->f_link,
|
||||
'label' => $playlist->name,
|
||||
'value' => $playlist->name,
|
||||
'rels' => '',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
$results['rfc3514'] = '0x1';
|
||||
|
|
|
@ -40,7 +40,7 @@ UI::show_box_top(T_('Manage Democratic Playlists')); ?>
|
|||
?>
|
||||
<tr class="<?php echo UI::flip_class(); ?>">
|
||||
<td><?php echo scrub_out($democratic->name); ?></td>
|
||||
<td><?php echo $playlist->f_link; ?></td>
|
||||
<td><?php echo $playlist->f_name_link; ?></td>
|
||||
<td><?php echo $democratic->f_cooldown; ?></td>
|
||||
<td><?php echo $democratic->f_level; ?></td>
|
||||
<td><?php echo $democratic->f_primary; ?></td>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<?php } ?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="cel_playlist"><?php echo $playlist->f_link; ?></td>
|
||||
<td class="cel_playlist"><?php echo $playlist->f_name_link; ?></td>
|
||||
<td class="cel_add">
|
||||
<span class="cel_item_add">
|
||||
<?php echo Ajax::button('?action=basket&type=playlist&id=' . $playlist->id,'add', T_('Add to temporary playlist'),'add_playlist_' . $playlist->id); ?>
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
<option value="title"><?php echo T_('Title')?></option>
|
||||
<option value="album"><?php echo T_('Album')?></option>
|
||||
<option value="artist"><?php echo T_('Artist')?></option>
|
||||
<option value="playlist"><?php echo T_('Playlist')?></option>
|
||||
<option value="tag"><?php echo T_('Tag')?></option>
|
||||
</select>
|
||||
<input class="button" type="submit" value="<?php echo T_('Search'); ?>" id="searchBtn" />
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<?php } ?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="cel_playlist"><?php echo $playlist->f_link; ?></td>
|
||||
<td class="cel_playlist"><?php echo $playlist->f_name_link; ?></td>
|
||||
<td class="cel_add">
|
||||
<span class="cel_item_add">
|
||||
<?php echo Ajax::button('?action=basket&type=smartplaylist&id=' . $playlist->id,'add', T_('Add to temporary playlist'),'add_playlist_' . $playlist->id); ?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue