This is the documentation on all the theme override functions in Discogs 6.x.
- After you find releases using the import form, the resulting import form is rendered using
theme_discogs_forminfo($info)
. The$info
variable is a multidimensional array of artist/label info. - For releases with multiple artists, you format the "artist" field using
theme_discogs_artists($artists, $cleanup = TRUE)
. The$artists
variable is a multidimensional array artist names and join characters.$cleanup
is a boolean variable that says whether you should "clean up" artists' names; that is, convert "Artist, the (2)" into "Artist." The discogs code uses a helper function to cleanup the artist name, which is called_discogs_cleanup_artist_field($artist)
. - For releases with multiple labels, you format the label" field using
theme_discogs_labels($labels)
. - The custom theme function for formatting the "track_notes" field, is called
theme_discogs_extra_artists($extraartists, $cleanup = TRUE)
. This is the one you want to use for release credits. It works much the same astheme_discogs_artists()
.Note: The array that is passed to this function is generated automatically from the JSON returned by Discogs.com. That means that the track info is in the array - it's just not displayed. It also means that you can use some array-merging trickery to display it however you want.
- To theme the "format" field, you use
theme_discogs_formats($formats)
. It works similar totheme_discogs_labels()
. - Finally, there is
theme_discogs_checkbox_text($release)
. This is to format the text that will be beside a checkbox, in the form where you import releases. The$release
variable is a rather complicated array, so I'll just let the code do the talking there.
The code for all of these functions is below. To override it, make a function with the same signature, but substitute "yourthemename" (whatever that is) instead of "theme".
<?php
/**
* Custom theme function for formatting artist/label information on Discogs.com
* import form.
*
* @param $info_array
* Multidimensional array of artist/label info
* @return
* HTML markup of information
* @see _discogs_cleanup_artist_field()
*/
function theme_discogs_forminfo($info) {
$output = '<div class="discogs-form-info">';
if (isset($info['images']['image']['uri150'])) {
$output .= theme_image($info['images']['image']['uri150'], '', '', NULL, FALSE);
}
elseif (isset($info['images']['image'][0]['uri150'])) {
$output .= theme_image($info['images']['image'][0]['uri150'], '', '', NULL, FALSE);
}
if (is_array($info['urls']['url']) && isset($info['name'])) {
$output .= "\n<h3>". l($info['name'], $info['urls']['url'][0]) . "</h3>";
}
elseif (isset($info['urls']['url']) && isset($info['name'])) {
$output .= "\n<h3>". l($info['name'], $info['urls']['url']) . "</h3>";
}
elseif (isset($info['name'])) {
$output .= '\n<h3>'. check_plain($info['name']) . '</h3>';
}
if (isset($info['namevariations']['name'])) {
$out = (is_array($info['namevariations']['name'])
? implode(", ", $info['namevariations']['name'])
: $info['namevariations']['name']);
$output .= '<p>Name Variations: '. check_plain($out) . '</p>';
}
if (isset($info['aliases']['name'])) {
$out = (is_array($info['aliases']['name'])
? implode(", ", $info['aliases']['name'])
: $info['aliases']['name']);
$output .= '<p>Alias: '. check_plain($out) . '</p>';
}
if (isset($info['contactinfo'])) {
$out = str_replace("\n", "\n<br />", $info['contactinfo']);
$output .= '<p>Contact: '. check_markup($out) . '</p>';
}
if (isset($info['profile'])) {
$out = str_replace(array('[a=', ']'), '', $info['profile']);
$out = str_replace("\n", "\n<br />", $out);
$output .= '<p>'. check_markup($out) . '</p>';
}
if (isset($info['members']['name'])) {
$output .= '<p>Members: '. implode(", ", $info['members']['name']) . '</p>';
}
$output .= '</div>';
return $output;
}
/**
* Custom theme function for formatting releases from Discogs that have more
* than one primary artist.
*
* @param $artists
* Multidimensional array of artist names and join characters
* @param $cleanup
* Boolean whether to clean up artist field (default TRUE)
* @return
* String with multiple artists, joined with join characters
* @see _discogs_cleanup_artist_field()
*/
function theme_discogs_artists($artists, $cleanup = TRUE) {
$artist_string = '';
if (isset($artists['name'])) {
$artist_string = $cleanup
? _discogs_cleanup_artist_field($artists['name'])
: $artists['name'];
}
elseif (isset($artists[0]['name'])) {
foreach ($artists as $artist) {
$name = $cleanup
? _discogs_cleanup_artist_field($artist['name'])
: $artist['name'];
$join = empty($artist['join']) ? ' / ': "{$artist['join']}";
$artist_string .= $name . $join;
}
}
return rtrim($artist_string, $join);
}
/**
* Custom theme function for formatting releases from Discogs that have more
* than one label and catalog number.
*
* @param $labels
* Multidimensional array of artist names and join characters
* @return
* String with multiple artists, joined with join characters
* @see _discogs_cleanup_artist_field()
*/
function theme_discogs_labels($labels) {
if (isset($labels['name'])) {
$new_labels['discog_label'] = $labels['name'];
$new_labels['discog_cat_num'] = $labels['catno'];
}
elseif (isset($labels[0]['name'])) {
$name = '';
$catno = '';
foreach ($labels as $label) {
$name .= $label['name'] . ', ';
$catno .= $label['catno'] . ', ';
}
$new_labels['discog_label'] = rtrim($name, ', ');
$new_labels['discog_cat_num'] = rtrim($catno, ', ');
}
return $new_labels;
}
/**
* Custom theme function for formatting Discogs 'extraartist' array of artist
* names and roles.
*
* @param $extraartists
* Array of artist names/roles
* @param $cleanup
* Boolean whether to clean up artist field (default TRUE)
* @return
* String with themed artists and roles
* @see _discogs_cleanup_artist_field()
*/
function theme_discogs_extra_artists($extraartists, $cleanup = TRUE) {
// Convert $extraartists['name'] and $extraartists['role'] to $notes
$notes = '';
if (is_array($extraartists) && !empty($extraartists)) {
foreach ($extraartists as $extra) {
// $extraartists is sometimes multidimensional and sometimes not
if (isset($extra['name'])) {
$name = $cleanup ?
_discogs_cleanup_artist_field($extra['name']) :
$extra['name'];
$notes .= $extra['role'] . ' - <b>'. $name . "</b>\n";
}
else {
// Handle multidimensional array through recursion
$notes .= theme_discogs_extra_artists($extra, $cleanup);
}
}
}
return $notes;
}
/**
* Themes an array of formats, which may or may not be multidimensional.
*
* @param $formats
* Array (possibly multidimensional) of format names from Discogs
* @return
* String with format names, comma-separated
*/
function theme_discogs_formats($formats) {
$format_string = '';
if (isset($formats['name'])) {
$format_string = $formats['name'];
}
elseif (isset($formats[0]['name'])) {
foreach ($formats as $format) {
$format_string .= $format['name'] . ', ';
}
}
return rtrim($format_string, ', ');
}
/**
* Takes an array of release information, and outputs text that can be
* displayed in a checkbox form element.
*
* @param $release
* Release array. Structure:
* @code
* [release] => array
* (
* [id] => (Discogs ID)
* [status] => (usually "Accepted")
* [type] => (usually "Main," sometimes "TrackAppearance")
* [title] => (Album title)
* [format] => (Album format)
* [label] => (Record label)
* [year] => (4-digit Year, if any)
* [artist] => (Artist, if any)
* [summary] => (Summary, if any)
* )
* @endcode
* @return
* Text to put into checkbox fields
* @see discogs_import_step2()
*/
function theme_discogs_checkbox_text($release) {
$artist = isset($release['artist'])
? check_plain($release['artist'])
: theme('discogs_artists', $release['artists']['artist']);
$text = empty($artist) ? '': "$artist - ";
$text .= "<b>{$release['title']}</b>";
$text .= empty($release['format']) ? '': "{$release['format']}";
$text .= empty($release['year']) ? '': " ({$release['year']})";
return $text;
}
?>
Additionally, there is an entire template file dedicated to displaying releases, and a CSS file. These are discogs-releast.tpl.php
and discogs.css
respectively. I won't post the code for these here.
Hope this helps!