1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 17:59:21 +02:00

Requires user catalog right to edit arts

Avoid additional sql requests on searches
This commit is contained in:
Afterster 2014-10-15 22:37:06 +02:00
parent a59af3e965
commit 173d5e9d76
24 changed files with 117 additions and 96 deletions

View file

@ -24,6 +24,9 @@ require_once 'lib/init.php';
require_once AmpConfig::get('prefix') . '/templates/header.inc.php'; require_once AmpConfig::get('prefix') . '/templates/header.inc.php';
// If not a content manager user then kick em out
if (!Access::check('interface','50')) { UI::access_denied(); exit; }
$object_type = $_GET['object_type']; $object_type = $_GET['object_type'];
$object_id = $_GET['object_id']; $object_id = $_GET['object_id'];
$burl = ''; $burl = '';
@ -34,7 +37,6 @@ if (isset($_GET['burl'])) {
/* Switch on Action */ /* Switch on Action */
switch ($_REQUEST['action']) { switch ($_REQUEST['action']) {
case 'clear_art': case 'clear_art':
if (!$GLOBALS['user']->has_access('75')) { UI::access_denied(); }
$art = new Art($object_id, $object_type); $art = new Art($object_id, $object_type);
$art->reset(); $art->reset();
show_confirmation(T_('Art Cleared'), T_('Art information has been removed from the database'), $burl); show_confirmation(T_('Art Cleared'), T_('Art information has been removed from the database'), $burl);
@ -64,9 +66,6 @@ switch ($_REQUEST['action']) {
break; break;
case 'find_art': case 'find_art':
// If not a user then kick em out
if (!Access::check('interface','25')) { UI::access_denied(); exit; }
// Prevent the script from timing out // Prevent the script from timing out
set_time_limit(0); set_time_limit(0);

View file

@ -577,14 +577,27 @@ class Album extends database_object implements library_item
* album information with the base required * album information with the base required
* f_link, f_name * f_link, f_name
*/ */
public function format() public function format($details = true)
{ {
$web_path = AmpConfig::get('web_path'); $web_path = AmpConfig::get('web_path');
if ($details) {
/* Pull the advanced information */ /* Pull the advanced information */
$data = $this->_get_extra_info(); $data = $this->_get_extra_info();
foreach ($data as $key=>$value) { $this->$key = $value; } foreach ($data as $key=>$value) { $this->$key = $value; }
if ($this->album_artist) {
$Album_artist = new Artist($this->album_artist);
$Album_artist->format();
$this->album_artist_name = $Album_artist->name;
$this->f_album_artist_name = $Album_artist->f_name;
$this->f_album_artist_link = "<a href=\"" . $web_path . "/artists.php?action=show&artist=" . $this->album_artist . "\" title=\"" . scrub_out($this->album_artist_name) . "\">" . $this->f_album_artist_name . "</a>";
}
$this->tags = Tag::get_top_tags('album', $this->id);
$this->f_tags = Tag::get_display($this->tags, true, 'album');
}
/* Truncate the string if it's to long */ /* Truncate the string if it's to long */
$this->f_name = $this->full_name; $this->f_name = $this->full_name;
@ -611,21 +624,10 @@ class Album extends database_object implements library_item
$this->f_artist_name = $this->f_artist; $this->f_artist_name = $this->f_artist;
} }
if ($this->album_artist) {
$Album_artist = new Artist($this->album_artist);
$Album_artist->format();
$this->album_artist_name = $Album_artist->name;
$this->f_album_artist_name = $Album_artist->f_name;
$this->f_album_artist_link = "<a href=\"" . $web_path . "/artists.php?action=show&artist=" . $this->album_artist . "\" title=\"" . scrub_out($this->album_artist_name) . "\">" . $this->f_album_artist_name . "</a>";
}
if (!$this->year) { if (!$this->year) {
$this->f_year = "N/A"; $this->f_year = "N/A";
} }
$this->tags = Tag::get_top_tags('album', $this->id);
$this->f_tags = Tag::get_display($this->tags, true, 'album');
$this->f_release_type = ucwords($this->release_type); $this->f_release_type = ucwords($this->release_type);
} // format } // format

View file

@ -1495,12 +1495,11 @@ class Art extends database_object
echo "</div>"; echo "</div>";
} }
echo "<div class=\"item_art_actions\">"; echo "<div class=\"item_art_actions\">";
if ($GLOBALS['user']->has_access(25)) { if ($GLOBALS['user']->has_access(50)) {
echo "<a href=\"javascript:NavigateTo('" . AmpConfig::get('web_path') . "/arts.php?action=find_art&object_type=" . $object_type . "&object_id=" . $object_id . "&burl=' + getCurrentPage());\">"; echo "<a href=\"javascript:NavigateTo('" . AmpConfig::get('web_path') . "/arts.php?action=find_art&object_type=" . $object_type . "&object_id=" . $object_id . "&burl=' + getCurrentPage());\">";
echo UI::get_icon('edit', T_('Edit/Find Art')); echo UI::get_icon('edit', T_('Edit/Find Art'));
echo "</a>"; echo "</a>";
}
if ($GLOBALS['user']->has_access(75)) {
echo "<a href=\"javascript:NavigateTo('" . AmpConfig::get('web_path') . "/arts.php?action=clear_art&object_type=" . $object_type . "&object_id=" . $object_id . "&burl=' + getCurrentPage());\" onclick=\"return confirm('" . T_('Do you really want to reset art?') . "');\">"; echo "<a href=\"javascript:NavigateTo('" . AmpConfig::get('web_path') . "/arts.php?action=clear_art&object_type=" . $object_type . "&object_id=" . $object_id . "&burl=' + getCurrentPage());\" onclick=\"return confirm('" . T_('Do you really want to reset art?') . "');\">";
echo UI::get_icon('delete', T_('Reset Art')); echo UI::get_icon('delete', T_('Reset Art'));
echo "</a>"; echo "</a>";

View file

@ -421,7 +421,7 @@ class Artist extends database_object implements library_item
* it changes the title into a full link. * it changes the title into a full link.
* @return boolean * @return boolean
*/ */
public function format() public function format($details = true)
{ {
/* Combine prefix and name, trim then add ... if needed */ /* Combine prefix and name, trim then add ... if needed */
$name = trim($this->prefix . " " . $this->name); $name = trim($this->prefix . " " . $this->name);
@ -438,6 +438,8 @@ class Artist extends database_object implements library_item
$this->f_link = AmpConfig::get('web_path') . '/artists.php?action=show&artist=' . $this->id; $this->f_link = AmpConfig::get('web_path') . '/artists.php?action=show&artist=' . $this->id;
$this->f_name_link = "<a href=\"" . $this->f_link . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>"; $this->f_name_link = "<a href=\"" . $this->f_link . "\" title=\"" . $this->f_full_name . "\">" . $name . "</a>";
} }
if ($details) {
// Get the counts // Get the counts
$extra_info = $this->_get_extra_info($this->catalog_id); $extra_info = $this->_get_extra_info($this->catalog_id);
@ -453,6 +455,7 @@ class Artist extends database_object implements library_item
$this->f_tags = Tag::get_display($this->tags, true, 'artist'); $this->f_tags = Tag::get_display($this->tags, true, 'artist');
$this->object_cnt = $extra_info['object_cnt']; $this->object_cnt = $extra_info['object_cnt'];
}
return true; return true;

View file

@ -176,13 +176,15 @@ class Broadcast extends database_object implements library_item
return $this->id; return $this->id;
} }
public function format() public function format($details = true)
{ {
$this->f_name = $this->name; $this->f_name = $this->name;
$this->f_link = '<a href="' . AmpConfig::get('web_path') . '/broadcast.php?id=' . $this->id . '">' . scrub_out($this->f_name) . '</a>'; $this->f_link = '<a href="' . AmpConfig::get('web_path') . '/broadcast.php?id=' . $this->id . '">' . scrub_out($this->f_name) . '</a>';
if ($details) {
$this->tags = Tag::get_top_tags('broadcast', $this->id); $this->tags = Tag::get_top_tags('broadcast', $this->id);
$this->f_tags = Tag::get_display($this->tags, true, 'broadcast'); $this->f_tags = Tag::get_display($this->tags, true, 'broadcast');
} }
}
/** /**
* Get item keywords for metadata searches. * Get item keywords for metadata searches.

View file

@ -182,11 +182,13 @@ class Channel extends database_object implements media, library_item
} }
} }
public function format() public function format($details = true)
{ {
if ($details) {
$this->tags = Tag::get_top_tags('channel', $this->id); $this->tags = Tag::get_top_tags('channel', $this->id);
$this->f_tags = Tag::get_display($this->tags, true, 'channel'); $this->f_tags = Tag::get_display($this->tags, true, 'channel');
} }
}
public function get_keywords() public function get_keywords()
{ {

View file

@ -91,10 +91,11 @@ class Clip extends Video
* this function takes the object and reformats some values * this function takes the object and reformats some values
*/ */
public function format() public function format($details = true)
{ {
parent::format(); parent::format($details);
if ($details) {
if ($this->artist) { if ($this->artist) {
$artist = new Artist($this->artist); $artist = new Artist($this->artist);
$artist->format(); $artist->format();
@ -106,6 +107,7 @@ class Clip extends Video
$song->format(); $song->format();
$this->f_song = $song->f_link; $this->f_song = $song->f_link;
} }
}
return true; return true;

View file

@ -148,7 +148,7 @@ class Democratic extends Tmp_Playlist
* format * format
* This makes the variables all purrty so that they can be displayed * This makes the variables all purrty so that they can be displayed
*/ */
public function format() public function format($details = true)
{ {
$this->f_cooldown = $this->cooldown . ' ' . T_('minutes'); $this->f_cooldown = $this->cooldown . ' ' . T_('minutes');
$this->f_primary = $this->primary ? T_('Primary') : ''; $this->f_primary = $this->primary ? T_('Primary') : '';

View file

@ -92,7 +92,7 @@ class Live_Stream extends database_object implements media, library_item
* This takes the normal data from the database and makes it pretty * This takes the normal data from the database and makes it pretty
* for the users, the new variables are put in f_??? and f_???_link * for the users, the new variables are put in f_??? and f_???_link
*/ */
public function format() public function format($details = true)
{ {
// Default link used on the rightbar // Default link used on the rightbar
$this->f_link = "<a href=\"$this->url\">$this->name</a>"; $this->f_link = "<a href=\"$this->url\">$this->name</a>";

View file

@ -114,9 +114,9 @@ class Movie extends Video
* this function takes the object and reformats some values * this function takes the object and reformats some values
*/ */
public function format() public function format($details = true)
{ {
parent::format(); parent::format($details);
$this->f_original_name = trim($this->prefix . " " . $this->f_title); $this->f_original_name = trim($this->prefix . " " . $this->f_title);
$this->f_title = ($this->f_original_name ?: $this->f_title); $this->f_title = ($this->f_original_name ?: $this->f_title);

View file

@ -92,9 +92,9 @@ class Personal_Video extends Video
* this function takes the object and reformats some values * this function takes the object and reformats some values
*/ */
public function format() public function format($details = true)
{ {
parent::format(); parent::format($details);
$this->f_location = $this->location; $this->f_location = $this->location;

View file

@ -33,7 +33,7 @@ interface playable_item
* *
* Creates member variables for output * Creates member variables for output
*/ */
public function format(); public function format($details = true);
/** /**
* get_fullname * get_fullname

View file

@ -118,9 +118,9 @@ class Playlist extends playlist_object
* This takes the current playlist object and gussies it up a little * This takes the current playlist object and gussies it up a little
* bit so it is presentable to the users * bit so it is presentable to the users
*/ */
public function format() public function format($details = true)
{ {
parent::format(); parent::format($details);
$this->f_link = AmpConfig::get('web_path') . '/playlist.php?action=show_playlist&playlist_id=' . $this->id; $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->f_name_link = '<a href="' . $this->f_link . '">' . $this->f_name . '</a>';

View file

@ -64,14 +64,15 @@ abstract class playlist_object extends database_object implements library_item
* This takes the current playlist object and gussies it up a little * This takes the current playlist object and gussies it up a little
* bit so it is presentable to the users * bit so it is presentable to the users
*/ */
public function format() public function format($details = true)
{ {
$this->f_name = $this->name; $this->f_name = $this->name;
$this->f_type = ($this->type == 'private') ? UI::get_icon('lock', T_('Private')) : ''; $this->f_type = ($this->type == 'private') ? UI::get_icon('lock', T_('Private')) : '';
if ($details) {
$client = new User($this->user); $client = new User($this->user);
$this->f_user = $client->fullname; $this->f_user = $client->fullname;
}
} // format } // format

View file

@ -622,9 +622,10 @@ class Search extends playlist_object
* format * format
* Gussy up the data * Gussy up the data
*/ */
public function format() public function format($details = true)
{ {
parent::format(); parent::format();
$this->f_link = AmpConfig::get('web_path') . '/smartplaylist.php?action=show_playlist&playlist_id=' . $this->id; $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->f_name_link = '<a href="' . $this->f_link . '">' . $this->f_name . '</a>';
} }

View file

@ -194,13 +194,15 @@ class Share extends database_object
} }
} }
public function format() public function format($details = true)
{ {
if ($details) {
$object = new $this->object_type($this->object_id); $object = new $this->object_type($this->object_id);
$object->format(); $object->format();
$this->f_object_link = $object->f_link; $this->f_object_link = $object->f_link;
$user = new User($this->user); $user = new User($this->user);
$this->f_user = $user->fullname; $this->f_user = $user->fullname;
}
$this->f_allow_stream = $this->allow_stream; $this->f_allow_stream = $this->allow_stream;
$this->f_allow_download = $this->allow_download; $this->f_allow_download = $this->allow_download;
$this->f_creation_date = date("Y-m-d H:i:s", $this->creation_date); $this->f_creation_date = date("Y-m-d H:i:s", $this->creation_date);

View file

@ -1243,10 +1243,16 @@ class Song extends database_object implements media, library_item
* and does a ton of formating on it creating f_??? variables on the current * and does a ton of formating on it creating f_??? variables on the current
* object * object
*/ */
public function format() public function format($details = true)
{ {
if ($details) {
$this->fill_ext_info(); $this->fill_ext_info();
// Get the top tags
$this->tags = Tag::get_top_tags('song', $this->id);
$this->f_tags = Tag::get_display($this->tags, true, 'song');
}
// Format the album name // Format the album name
$this->f_album_full = $this->get_album_name(); $this->f_album_full = $this->get_album_name();
$this->f_album = $this->f_album_full; $this->f_album = $this->f_album_full;
@ -1285,10 +1291,6 @@ class Song extends database_object implements media, library_item
// Format the track (there isn't really anything to do here) // Format the track (there isn't really anything to do here)
$this->f_track = (string) $this->track; $this->f_track = (string) $this->track;
// Get the top tags
$this->tags = Tag::get_top_tags('song', $this->id);
$this->f_tags = Tag::get_display($this->tags, true, 'song');
// Format the size // Format the size
$this->f_size = UI::format_bytes($this->size); $this->f_size = UI::format_bytes($this->size);

View file

@ -192,7 +192,7 @@ class Song_Preview extends database_object implements media, playable_item
* and does a ton of formating on it creating f_??? variables on the current * and does a ton of formating on it creating f_??? variables on the current
* object * object
*/ */
public function format() public function format($details = true)
{ {
// Format the artist name // Format the artist name
if ($this->artist) { if ($this->artist) {

View file

@ -646,7 +646,7 @@ class Tag extends database_object implements library_item
} // remove_map } // remove_map
public function format() public function format($details = true)
{ {
} }

View file

@ -175,15 +175,17 @@ class TVShow extends database_object implements library_item
* format * format
* this function takes the object and reformats some values * this function takes the object and reformats some values
*/ */
public function format() public function format($details = true)
{ {
$this->f_name = trim($this->prefix . " " . $this->name); $this->f_name = trim($this->prefix . " " . $this->name);
$this->link = AmpConfig::get('web_path') . '/tvshows.php?action=show&tvshow=' . $this->id; $this->link = AmpConfig::get('web_path') . '/tvshows.php?action=show&tvshow=' . $this->id;
$this->f_link = '<a href="' . $this->link . '" title="' . $this->f_name . '">' . $this->f_name . '</a>'; $this->f_link = '<a href="' . $this->link . '" title="' . $this->f_name . '">' . $this->f_name . '</a>';
if ($details) {
$this->_get_extra_info(); $this->_get_extra_info();
$this->tags = Tag::get_top_tags('tvshow', $this->id); $this->tags = Tag::get_top_tags('tvshow', $this->id);
$this->f_tags = Tag::get_display($this->tags, true, 'tvshow'); $this->f_tags = Tag::get_display($this->tags, true, 'tvshow');
}
return true; return true;
} }

View file

@ -144,12 +144,12 @@ class TVShow_Episode extends Video
* format * format
* this function takes the object and reformats some values * this function takes the object and reformats some values
*/ */
public function format() public function format($details = true)
{ {
parent::format(); parent::format($details);
$season = new TVShow_Season($this->season); $season = new TVShow_Season($this->season);
$season->format(); $season->format($details);
$this->f_title = ($this->original_name ?: $this->f_title); $this->f_title = ($this->original_name ?: $this->f_title);
$this->f_link = '<a href="' . $this->link . '">' . $this->f_title . '</a>'; $this->f_link = '<a href="' . $this->link . '">' . $this->f_title . '</a>';

View file

@ -129,19 +129,21 @@ class TVShow_Season extends database_object implements library_item
* format * format
* this function takes the object and reformats some values * this function takes the object and reformats some values
*/ */
public function format() public function format($details = true)
{ {
$this->f_name = T_('Season') . ' ' . $this->season_number; $this->f_name = T_('Season') . ' ' . $this->season_number;
$tvshow = new TVShow($this->tvshow); $tvshow = new TVShow($this->tvshow);
$tvshow->format(); $tvshow->format($details);
$this->f_tvshow = $tvshow->f_name; $this->f_tvshow = $tvshow->f_name;
$this->f_tvshow_link = $tvshow->f_link; $this->f_tvshow_link = $tvshow->f_link;
$this->link = AmpConfig::get('web_path') . '/tvshow_seasons.php?action=show&season=' . $this->id; $this->link = AmpConfig::get('web_path') . '/tvshow_seasons.php?action=show&season=' . $this->id;
$this->f_link = '<a href="' . $this->link . '" title="' . $tvshow->f_name . ' - ' . $this->f_name . '">' . $this->f_name . '</a>'; $this->f_link = '<a href="' . $this->link . '" title="' . $tvshow->f_name . ' - ' . $this->f_name . '">' . $this->f_name . '</a>';
if ($details) {
$this->_get_extra_info(); $this->_get_extra_info();
}
return true; return true;
} }

View file

@ -245,7 +245,7 @@ class Video extends database_object implements media, library_item
* format * format
* This formats a video object so that it is human readable * This formats a video object so that it is human readable
*/ */
public function format() public function format($details = true)
{ {
$this->f_title = scrub_out($this->title); $this->f_title = scrub_out($this->title);
$this->f_full_title = $this->f_title; $this->f_full_title = $this->f_title;
@ -274,9 +274,11 @@ class Video extends database_object implements media, library_item
$min_h = sprintf("%02d", ($min%60)); $min_h = sprintf("%02d", ($min%60));
$this->f_time_h = $hour . ":" . $min_h . ":" . $sec; $this->f_time_h = $hour . ":" . $min_h . ":" . $sec;
if ($details) {
// Get the top tags // Get the top tags
$this->tags = Tag::get_top_tags('video', $this->id); $this->tags = Tag::get_top_tags('video', $this->id);
$this->f_tags = Tag::get_display($this->tags, true, 'video'); $this->f_tags = Tag::get_display($this->tags, true, 'video');
}
$this->f_length = floor($this->time/60) . ' ' . T_('minutes'); $this->f_length = floor($this->time/60) . ' ' . T_('minutes');
$this->f_file = $this->f_title . '.' . $this->type; $this->f_file = $this->f_title . '.' . $this->type;

View file

@ -50,7 +50,7 @@ switch ($_REQUEST['action']) {
} }
foreach ($sres as $id) { foreach ($sres as $id) {
$artist = new Artist($id); $artist = new Artist($id);
$artist->format(); $artist->format(false);
$results[] = array( $results[] = array(
'type' => T_('Artists'), 'type' => T_('Artists'),
'link' => $artist->f_link, 'link' => $artist->f_link,
@ -79,7 +79,7 @@ switch ($_REQUEST['action']) {
} }
foreach ($sres as $id) { foreach ($sres as $id) {
$album = new Album($id); $album = new Album($id);
$album->format(); $album->format(false);
$a_title = $album->f_title; $a_title = $album->f_title;
if ($album->disk) { if ($album->disk) {
$a_title .= " [" . T_('Disk') . " " . $album->disk . "]"; $a_title .= " [" . T_('Disk') . " " . $album->disk . "]";
@ -112,7 +112,7 @@ switch ($_REQUEST['action']) {
} }
foreach ($sres as $id) { foreach ($sres as $id) {
$song = new Song($id); $song = new Song($id);
$song->format(); $song->format(false);
$results[] = array( $results[] = array(
'type' => T_('Songs'), 'type' => T_('Songs'),
'link' => $song->link, 'link' => $song->link,
@ -141,7 +141,7 @@ switch ($_REQUEST['action']) {
} }
foreach ($sres as $id) { foreach ($sres as $id) {
$playlist = new Playlist($id); $playlist = new Playlist($id);
$playlist->format(); $playlist->format(false);
$results[] = array( $results[] = array(
'type' => T_('Playlists'), 'type' => T_('Playlists'),
'link' => $playlist->f_link, 'link' => $playlist->f_link,