1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 09:49:30 +02:00

Add methods to retrieve library item description and art with fallback to parent data

This commit is contained in:
Afterster 2015-04-05 10:21:43 +02:00
parent 81ff034bd1
commit b04208b5c3
32 changed files with 255 additions and 64 deletions

View file

@ -129,10 +129,6 @@ class Album extends database_object implements library_item
* @var string $f_name
*/
public $f_name;
/**
* @var string $f_name_link
*/
public $f_name_link;
/**
* @var string $link
*/
@ -602,16 +598,15 @@ class Album extends database_object implements library_item
$this->f_name = $this->full_name;
$this->link = $web_path . '/albums.php?action=show&album=' . scrub_out($this->id);
$this->f_name_link = "<a href=\"" . $this->link . "\" title=\"" . scrub_out($this->full_name) . "\">" . scrub_out($this->f_name);
$this->f_link = "<a href=\"" . $this->link . "\" title=\"" . scrub_out($this->full_name) . "\">" . scrub_out($this->f_name);
// Looking if we need to combine or display disks
if ($this->disk && (!$this->allow_group_disks || ($this->allow_group_disks && !AmpConfig::get('album_group')))) {
$this->f_name_link .= " <span class=\"discnb\">[" . T_('Disk') . " " . $this->disk . "]</span>";
$this->f_link .= " <span class=\"discnb\">[" . T_('Disk') . " " . $this->disk . "]</span>";
}
$this->f_name_link .="</a>";
$this->f_link .="</a>";
$this->f_link = $this->f_name_link;
$this->f_title = $this->full_name;
if ($this->artist_count == '1') {
$artist = trim(trim($this->artist_prefix) . ' ' . trim($this->artist_name));
@ -735,6 +730,31 @@ class Album extends database_object implements library_item
return 'default';
}
public function get_description()
{
// Album description is not supported yet, always return artist description
$artist = new Artist($this->artist_id);
return $artist->get_description();
}
public function display_art($thumb = 2)
{
$id = null;
$type = null;
if (Art::has_db($this->id, 'album')) {
$id = $this->id;
$type = 'album';
} else if (Art::has_db($this->artist_id, 'artist')) {
$id = $this->artist_id;
$type = 'artist';
}
if ($id !== null && $type !== null) {
Art::display($type, $id, $this->get_fullname(), $thumb, $this->link);
}
}
/**
* get_random_songs
* gets a random number, and a random assortment of songs from this album

View file

@ -105,10 +105,6 @@ class Artist extends database_object implements library_item
* @var string $f_link
*/
public $f_link;
/**
* @var string $f_name_link
*/
public $f_name_link;
/**
* @var string $f_time
*/
@ -437,10 +433,10 @@ class Artist extends database_object implements library_item
if ($this->catalog_id) {
$this->link = AmpConfig::get('web_path') . '/artists.php?action=show&catalog=' . $this->catalog_id . '&artist=' . $this->id;
$this->f_link = $this->f_name_link = "<a href=\"" . $this->link . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>";
$this->f_link = "<a href=\"" . $this->link . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>";
} else {
$this->link = AmpConfig::get('web_path') . '/artists.php?action=show&artist=' . $this->id;
$this->f_link = $this->f_name_link = "<a href=\"" . $this->link . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>";
$this->f_link = "<a href=\"" . $this->link . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>";
}
if ($details) {
@ -566,6 +562,26 @@ class Artist extends database_object implements library_item
return 'default';
}
public function get_description()
{
return $this->summary;
}
public function display_art($thumb = 2)
{
$id = null;
$type = null;
if (Art::has_db($this->id, 'artist')) {
$id = $this->id;
$type = 'artist';
}
if ($id !== null && $type !== null) {
Art::display($type, $id, $this->get_fullname(), $thumb, $this->link);
}
}
/**
* check
*

View file

@ -269,6 +269,18 @@ class Broadcast extends database_object implements library_item
return 'default';
}
public function get_description()
{
return null;
}
public function display_art($thumb = 2)
{
if (Art::has_db($this->id, 'broadcast')) {
Art::display('broadcast', $this->id, $this->get_fullname(), $thumb, $this->link);
}
}
/**
* Get all broadcasts sql query.
* @return string

View file

@ -75,9 +75,13 @@ abstract class Catalog extends database_object
*/
public $f_name;
/**
* @var string $f_name_link
* @var string $link
*/
public $f_name_link;
public $link;
/**
* @var string $f_link
*/
public $f_link;
/**
* @var string $f_update
*/
@ -496,9 +500,8 @@ abstract class Catalog extends database_object
public function format()
{
$this->f_name = $this->name;
$this->f_name_link = '<a href="' . AmpConfig::get('web_path') .
'/admin/catalog.php?action=show_customize_catalog&catalog_id=' .
$this->id . '" title="' . scrub_out($this->name) . '">' .
$this->link = AmpConfig::get('web_path') . '/admin/catalog.php?action=show_customize_catalog&catalog_id=' . $this->id;
$this->f_link = '<a href="' . $this->link . '" title="' . scrub_out($this->name) . '">' .
scrub_out($this->f_name) . '</a>';
$this->f_update = $this->last_update
? date('d/m/Y h:i', $this->last_update)

View file

@ -489,14 +489,10 @@ class Graph
if (Core::is_library_item($object_type)) {
$libitem = new $object_type($object_id);
$libitem->format();
if (isset($libitem->f_name_link)) {
$blink = $libitem->f_name_link;
} else {
if (isset($libitem->f_link)) {
$blink = $libitem->f_link;
}
}
}
} else if ($user_id) {
$u = new User($user_id);
$u->format();

View file

@ -34,6 +34,10 @@ interface library_item extends playable_item
public function get_default_art_kind();
public function get_description();
public function display_art($thumb);
public function update(array $data);
public static function gc();

View file

@ -95,9 +95,9 @@ class Live_Stream extends database_object implements media, library_item
public function format($details = true)
{
// Default link used on the rightbar
$this->f_link = "<a href=\"$this->url\">$this->name</a>";
$this->f_name_link = "<a target=\"_blank\" href=\"$this->site_url\">$this->name</a>";
$this->f_url_link = "<a target=\"_blank\" href=\"$this->url\">$this->url</a>";
$this->f_link = "<a href=\"" . $this->url . "\">" . $this->name . "</a>";
$this->f_name_link = "<a target=\"_blank\" href=\"" . $this->site_url . "\">" . $this->name . "</a>";
$this->f_url_link = "<a target=\"_blank\" href=\"" . $this->url . "\">" . $this->url . "</a>";
return true;

View file

@ -33,8 +33,8 @@ class Playlist extends playlist_object
public $genre;
public $date;
public $link;
public $f_link;
public $f_name_link;
/* Generated Elements */
public $items = array();
@ -121,8 +121,8 @@ class Playlist extends playlist_object
public function format($details = true)
{
parent::format($details);
$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 . '">' . $this->f_name . '</a>';
$this->link = AmpConfig::get('web_path') . '/playlist.php?action=show_playlist&playlist_id=' . $this->id;
$this->f_link = '<a href="' . $this->link . '">' . $this->f_name . '</a>';
} // format

View file

@ -148,6 +148,16 @@ abstract class playlist_object extends database_object implements library_item
return 'default';
}
public function get_description()
{
return null;
}
public function display_art($thumb = 2)
{
// no art
}
/**
* get_catalogs
*

View file

@ -37,8 +37,8 @@ class Search extends playlist_object
public $basetypes;
public $types;
public $link;
public $f_link;
public $f_name_link;
/**
* constructor
@ -650,8 +650,8 @@ class Search extends playlist_object
{
parent::format();
$this->f_link = AmpConfig::get('web_path') . '/smartplaylist.php?action=show_playlist&playlist_id=' . $this->id;
$this->f_name_link = '<a href="' . $this->f_link . '">' . $this->f_name . '</a>';
$this->link = AmpConfig::get('web_path') . '/smartplaylist.php?action=show_playlist&playlist_id=' . $this->id;
$this->f_link = '<a href="' . $this->link . '">' . $this->f_name . '</a>';
}
/**

View file

@ -241,7 +241,7 @@ class Shoutbox
}
$html .= "<div class='shoutbox-info'>";
if ($details) {
$html .= "<div class='shoutbox-object'>" . ($object->f_name_link ?: $object->f_link) . "</div>";
$html .= "<div class='shoutbox-object'>" . $object->f_link . "</div>";
$html .= "<div class='shoutbox-date'>".date("Y/m/d H:i:s", $this->date) . "</div>";
}
$html .= "<div class='shoutbox-text'>" . preg_replace('/(\r\n|\n|\r)/', '<br />', $this->text) . "</div>";

View file

@ -1408,6 +1408,37 @@ class Song extends database_object implements media, library_item
return 'default';
}
public function get_description()
{
if (!empty($this->comment))
return $this->comment;
$album = new Album($this->album);
$album->format();
return $album->get_description();
}
public function display_art($thumb = 2)
{
$id = null;
$type = null;
if (Art::has_db($this->id, 'song')) {
$id = $this->id;
$type = 'song';
} else if (Art::has_db($this->album, 'album')) {
$id = $this->album;
$type = 'album';
} else if (Art::has_db($this->artist, 'artist')) {
$id = $this->artist;
$type = 'artist';
}
if ($id !== null && $type !== null) {
Art::display($type, $id, $this->get_fullname(), $thumb, $this->link);
}
}
/**
* get_fields
* This returns all of the 'data' fields for this object, we need to filter out some that we don't

View file

@ -716,4 +716,16 @@ class Tag extends database_object implements library_item
return 'default';
}
public function get_description()
{
return null;
}
public function display_art($thumb = 2)
{
if (Art::has_db($this->id, 'tag')) {
Art::display('tag', $this->id, $this->get_fullname(), $thumb, $this->link);
}
}
} // end of Tag class

View file

@ -255,6 +255,18 @@ class TVShow extends database_object implements library_item
return 'default';
}
public function get_description()
{
return $this->summary;
}
public function display_art($thumb = 2)
{
if (Art::has_db($this->id, 'tvshow')) {
Art::display('tvshow', $this->id, $this->get_fullname(), $thumb, $this->link);
}
}
/**
* check
*

View file

@ -205,4 +205,37 @@ class TVShow_Episode extends Video
'object_id' => $this->season
);
}
public function get_description()
{
if (!empty($this->summary))
return $this->summary;
$season = new TVShow_Season($this->season);
return $season->get_description();
}
public function display_art($thumb = 2)
{
$id = null;
$type = null;
if (Art::has_db($this->id, 'video')) {
$id = $this->id;
$type = 'video';
} else if (Art::has_db($this->season, 'tvshow_season')) {
$id = $this->season;
$type = 'tvshow_season';
} else {
$season = new TVShow_Season($this->season);
if (Art::has_db($season->tvshow, 'tvshow')) {
$id = $season->tvshow;
$type = 'tvshow';
}
}
if ($id !== null && $type !== null) {
Art::display($type, $id, $this->get_fullname(), $thumb, $this->link);
}
}
}

View file

@ -216,6 +216,31 @@ class TVShow_Season extends database_object implements library_item
return 'default';
}
public function get_description()
{
// No season description for now, always return tvshow description
$tvshow = new TVShow($this->tvshow);
return $tvshow->get_description();
}
public function display_art($thumb = 2)
{
$id = null;
$type = null;
if (Art::has_db($this->id, 'tvshow_season')) {
$id = $this->id;
$type = 'tvshow_season';
} else if (Art::has_db($this->tvshow, 'tvshow')) {
$id = $this->tvshow;
$type = 'tvshow';
}
if ($id !== null && $type !== null) {
Art::display($type, $id, $this->get_fullname(), $thumb, $this->link);
}
}
/**
* check
*

View file

@ -171,7 +171,7 @@ class Userflag extends database_object
if ($user_id <= 0) {
// Get latest only from user rights >= content manager
$sql .= "LEFT JOIN `user` ON `user`.`id` = `user_flag`.`user`" .
" WHERE `user`.`access` >= 50";
" WHERE `user`.`access` >= 50 AND";
} else {
$sql .= " WHERE";
}

View file

@ -375,6 +375,18 @@ class Video extends database_object implements media, library_item
return 'preview';
}
public function get_description()
{
return '';
}
public function display_art($thumb = 2)
{
if (Art::has_db($this->id, 'video')) {
Art::display('video', $this->id, $this->get_fullname(), $thumb, $this->link);
}
}
/**
* gc
*

View file

@ -66,9 +66,14 @@ class Wanted extends database_object
public $user;
/**
* @var string $f_name_link
* @var string $link
*/
public $f_name_link;
public $link;
/**
* @var string $f_link
*/
public $f_link;
/**
* @var string $f_artist_link
*/
@ -180,14 +185,14 @@ class Wanted extends database_object
}
}
$wanted->accepted = false;
$wanted->f_name_link = "<a href=\"" . AmpConfig::get('web_path') . "/albums.php?action=show_missing&mbid=" . $group['id'];
$wanted->link = AmpConfig::get('web_path') . "/albums.php?action=show_missing&mbid=" . $group['id'];
if ($artist) {
$wanted->f_name_link .= "&artist=" . $wanted->artist;
$wanted->link .= "&artist=" . $wanted->artist;
} else {
$wanted->f_name_link .= "&artist_mbid=" . $mbid;
$wanted->link .= "&artist_mbid=" . $mbid;
}
$wanted->f_name_link .= "\" title=\"" . $wanted->name . "\">" . $wanted->name . "</a>";
$wanted->f_artist_link = $artist ? $artist->f_name_link : $wartist['link'];
$wanted->f_link = "<a href=\"" . $wanted->link . "\" title=\"" . $wanted->name . "\">" . $wanted->name . "</a>";
$wanted->f_artist_link = $artist ? $artist->f_link : $wartist['link'];
$wanted->f_user = $GLOBALS['user']->fullname;
}
$results[] = $wanted;
@ -493,12 +498,13 @@ class Wanted extends database_object
if ($this->artist) {
$artist = new Artist($this->artist);
$artist->format();
$this->f_artist_link = $artist->f_name_link;
$this->f_artist_link = $artist->f_link;
} else {
$wartist = Wanted::get_missing_artist($this->artist_mbid);
$this->f_artist_link = $wartist['link'];
}
$this->f_name_link = "<a href=\"" . AmpConfig::get('web_path') . "/albums.php?action=show_missing&mbid=" . $this->mbid . "&artist=" . $this->artist . "&artist_mbid=" . $this->artist_mbid . "\" title=\"" . $this->name . "\">" . $this->name . "</a>";
$this->link = AmpConfig::get('web_path') . "/albums.php?action=show_missing&mbid=" . $this->mbid . "&artist=" . $this->artist . "&artist_mbid=" . $this->artist_mbid . "\" title=\"" . $this->name;
$this->f_link = "<a href=\"" . $this->link . "\">" . $this->name . "</a>";
$user = new User($this->user);
$this->f_user = $user->fullname;

View file

@ -109,12 +109,11 @@ class AmpacheCatalogFavorites {
echo '</div><br />';
echo '<div style="margin-left: 30px;">';
if (Art::has_db($userflag['id'], $userflag['type'])) {
echo '<div style="float: left; margin-right: 20px;">';
Art::display($userflag['type'], $userflag['id'], $item->get_fullname(), 2, $item->link);
$item->display_art(2);
echo '</div>';
}
echo '<div style="white-space: normal;">'. $item->summary .'</div>';
echo '<div style="white-space: normal;">'. $item->get_description() .'</div>';
echo '</div>';
echo '</td></tr>';

View file

@ -44,7 +44,7 @@ if (Art::is_enabled()) {
?>
</td>
<?php } ?>
<td class="cel_album"><?php echo $libitem->f_name_link; ?></td>
<td class="cel_album"><?php echo $libitem->f_link; ?></td>
<td class="cel_add">
<span class="cel_item_add">
<?php if ($show_playlist_add) { ?>

View file

@ -44,7 +44,7 @@ if (Art::is_enabled()) {
?>
</td>
<?php } ?>
<td class="cel_artist"><?php echo $libitem->f_name_link; ?></td>
<td class="cel_artist"><?php echo $libitem->f_link; ?></td>
<td class="cel_add">
<span class="cel_item_add">
<?php if ($show_playlist_add) { ?>

View file

@ -25,7 +25,7 @@ $web_path = AmpConfig::get('web_path');
$icon = $libitem->enabled ? 'disable' : 'enable';
$button_flip_state_id = 'button_flip_state_' . $libitem->id;
?>
<td class="cel_catalog"><?php echo $libitem->f_name_link; ?></td>
<td class="cel_catalog"><?php echo $libitem->f_link; ?></td>
<td class="cel_info"><?php echo scrub_out($libitem->f_info); ?></td>
<td class="cel_lastverify"><?php echo scrub_out($libitem->f_update); ?></td>
<td class="cel_lastadd"><?php echo scrub_out($libitem->f_add); ?></td>

View file

@ -32,7 +32,7 @@
<td class="cel_name"><?php echo $libitem->name; ?></td>
<td class="cel_interface"><?php echo $libitem->interface; ?></td>
<td class="cel_port"><?php echo $libitem->port; ?></td>
<td class="cel_data"><?php echo $libitem->get_target_object()->f_name_link; ?></td>
<td class="cel_data"><?php echo $libitem->get_target_object()->f_link; ?></td>
<!--<td class="cel_random"><?php echo ($libitem->random ? T_('Yes') : T_('No')); ?></td>
<td class="cel_loop"><?php echo ($libitem->loop ? T_('Yes') : T_('No')); ?></td>-->
<td class="cel_streamtype"><?php echo $libitem->stream_type; ?></td>

View file

@ -28,7 +28,7 @@
<?php } ?>
</div>
</td>
<td class="cel_streamname"><?php echo $libitem->f_name_link; ?></td>
<td class="cel_streamname"><?php echo $libitem->f_link; ?></td>
<td class="cel_streamurl"><?php echo $libitem->f_url_link; ?></td>
<td class="cel_codec"><?php echo $libitem->codec; ?></td>
<td class="cel_action">

View file

@ -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_name_link; ?></td>
<td><?php echo $playlist->f_link; ?></td>
<td><?php echo $democratic->f_cooldown; ?></td>
<td><?php echo $democratic->f_level; ?></td>
<td><?php echo $democratic->f_primary; ?></td>

View file

@ -37,7 +37,7 @@
} else {
$artist = new Artist($a['id']);
$artist->format();
echo $artist->f_name_link;
echo $artist->f_link;
}
?>
</div>

View file

@ -34,7 +34,7 @@
<?php } ?>
</div>
</td>
<td class="cel_playlist"><?php echo $libitem->f_name_link; ?></td>
<td class="cel_playlist"><?php echo $libitem->f_link; ?></td>
<td class="cel_add">
<span class="cel_item_add">
<?php echo Ajax::button('?action=basket&type=playlist&id=' . $libitem->id,'add', T_('Add to temporary playlist'),'add_playlist_' . $libitem->id); ?>

View file

@ -31,7 +31,7 @@
<?php } ?>
</div>
</td>
<td class="cel_playlist"><?php echo $libitem->f_name_link; ?></td>
<td class="cel_playlist"><?php echo $libitem->f_link; ?></td>
<td class="cel_add">
<span class="cel_item_add">
<?php echo Ajax::button('?action=basket&type=search&id=' . $libitem->id,'add', T_('Add to temporary playlist'),'add_playlist_' . $libitem->id); ?>

View file

@ -21,7 +21,7 @@
*/
?>
<tr id="flagged_<?php echo $libitem->id; ?>" class="<?php echo UI::flip_class(); ?>">
<td class="cel_object"><?php echo ($object->f_name_link ?: $object->f_link); ?></td>
<td class="cel_object"><?php echo $object->f_link; ?></td>
<td class="cel_username"><?php echo $client->f_link; ?></td>
<td class="cel_sticky"><?php echo $libitem->sticky; ?></td>
<td class="cel_comment"><?php echo scrub_out($libitem->text); ?></td>

View file

@ -29,14 +29,14 @@ require AmpConfig::get('prefix') . '/templates/show_objects.inc.php';
UI::show_box_bottom();
$objects = Stats::get_top('artist');
$headers = array('f_name_link' => T_('Most Popular Artists'));
$headers = array('f_link' => T_('Most Popular Artists'));
UI::show_box_top('','info-box box_popular_artists');
require AmpConfig::get('prefix') . '/templates/show_objects.inc.php';
UI::show_box_bottom();
if (AmpConfig::get('allow_video')) {
$objects = Stats::get_top('video');
$headers = array('f_name_link' => T_('Most Popular Videos'));
$headers = array('f_link' => T_('Most Popular Videos'));
UI::show_box_top('','info-box box_popular_videos');
require AmpConfig::get('prefix') . '/templates/show_objects.inc.php';
UI::show_box_bottom();

View file

@ -21,7 +21,7 @@
*/
?>
<td class="cel_album"><?php echo $libitem->f_name_link; ?></td>
<td class="cel_album"><?php echo $libitem->f_link; ?></td>
<td class="cel_artist"><?php echo $libitem->f_artist_link; ?></td>
<td class="cel_year"><?php echo $libitem->year; ?></td>
<td class="cel_user"><?php echo $libitem->f_user; ?></td>