function dok_view_album($VARS, $update_module, $tpl_path) { global $THEME_DATE, $ARTIST_SONG_LINKS, $USER; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { $t = dok_error_template(MSG_ERR_ALBUM_DISPLAY); return array($t, sprintf(MSG_TITLE_DISPLAY_ALBUM, '')); } $res = mysql_query('select name, creation from ' . dok_tn('album') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { $t = dok_error_template(MSG_ERR_ALBUM_DISPLAY); return array($t, sprintf(MSG_TITLE_DISPLAY_ALBUM, '')); } $row = mysql_fetch_assoc($res); $t = new template($tpl_path); $t->set_file('page', 'album_display.tpl'); $t->set_block('page', 'if_albumeditor', 'editor_block'); $t->set_block('page', 'album_songs', 'songs_block'); $t->set_var(array('ALBUM_NAME' => $row['name'], 'ALBUM_DB_CREATION' => date($THEME_DATE, $row['creation']))); if (DOK_ENABLE_USER && !$USER->editor && !$USER->admin) { $t->set_var('editor_block', ''); } else { $t->set_var('ALBUM_EDIT_LINK', $_SERVER['PHP_SELF'] . '?display=edit_album&id=' . $VARS['id']); $t->parse('editor_block', 'if_albumeditor'); } $query = 'select s.id, s.name, s.creation, s.length, s.release, s.comment, r.track from ' . dok_tn('rel_song_album') . ' as r left join ' . dok_tn('song') . ' as s on r.song_id = s.id where r.album_id = ' . $VARS['id'] . ' order by r.track'; $songs = dok_oquery($query); $album_length = 0; if (!$songs->numrows()) { $t->set_var('songs_block', MSG_NO_SONG); } else { $pager_data = array('related' => 'album', 'related_id' => $VARS['id']); while ($song = $songs->fetch_array()) { $song_data = dok_song_format($song, $pager_data); $song_data['SONG_ARTIST'] = preg_replace('/^' . $ARTIST_SONG_LINKS[0] . '/', '', $song_data['SONG_ARTIST']); $t->set_var($song_data); $t->set_var('SONG_TRACK', $song['track']); $t->parse('songs_block', 'album_songs', 'true'); $album_length += $song['length']; } } $t->set_var('ALBUM_LENGTH', dok_sec2str($album_length)); $t->set_var('ALBUM_SONGS', $songs->numrows()); return array($t, sprintf(MSG_TITLE_DISPLAY_ALBUM, $row['name'])); }
function dok_list_albums($VARS, $up, $theme_path) { $orders = array('hits', 'length'); $t = new template($theme_path); $t->set_file('page', 'album_list.tpl'); $t->set_block('page', 'if_artist', 'artist_block'); $t->set_block('page', 'if_artist_2', 'artist_2_block'); $t->set_block('page', 'album', 'album_block'); $t->set_block('page', 'next_page', 'next_page_block'); if (!isset($VARS['alpha'])) { $VARS['alpha'] = '-'; } if (!strlen($VARS['offset']) || $VARS['offset'] < 0) { $VARS['offset'] = '0'; } $VARS['alpha'] = mysql_real_escape_string($VARS['alpha']); //$query = 'select id, name from '.dok_tn('album').' where substring(name from 1 for 1) >= \''.$VARS['alpha'].'\' order by name limit '.$VARS['offset'].', '.DOK_LIST_EPP; $query = 'select sum(s.length) as length, count(s.id) as c, sum(s.hits) as hits, a.id, a.name from ' . dok_tn('song') . ' as s left join ' . dok_tn('rel_song_album') . ' as r on s.id=r.song_id left join ' . dok_tn('album') . ' as a on r.album_id=a.id '; $where = array(); if (isset($VARS['sort']) && !in_array($VARS['sort'], $orders) || !isset($VARS['sort'])) { unset($VARS['sort']); $where[] = 'substring(a.name from 1 for 1) >= \'' . $VARS['alpha'] . '\' '; } if (isset($VARS['artist']) && is_numeric($VARS['artist']) && $VARS['artist'] > 0) { $res = mysql_query('select * from ' . dok_tn('artist') . ' where id = ' . $VARS['artist']); if (mysql_numrows($res)) { $row = mysql_fetch_assoc($res); $t->set_var('ARTIST_NAME', $row['name']); $t->set_var('ARTIST_ID', $row['id']); $t->parse('artist_block', 'if_artist'); $res = dok_oquery('select distinct(r.album_id) from ' . dok_tn('rel_song_album') . ' as r left join ' . dok_tn('rel_song_artist') . ' as r2 on r.song_id=r2.song_id where r2.artist_id = ' . $VARS['artist']); $al_ids = $res->fetch_col_array('album_id'); if (sizeof($al_ids)) { $where[] = 'a.id in(' . implode(', ', $al_ids) . ')'; } } else { unset($VARS['artist']); $t->set_var('artist_block', ''); } } else { unset($VARS['artist']); $t->set_var('artist_block', ''); } if (sizeof($where)) { $query .= ' where ' . implode(' AND ', $where); } $query .= 'group by r.album_id '; if (isset($VARS['sort'])) { $query .= 'order by ' . $VARS['sort'] . ' desc '; } else { $query .= 'order by a.name '; } $query .= 'limit ' . $VARS['offset'] . ', ' . DOK_LIST_EPP; $res = dok_oquery($query); echo mysql_error(); if ($res->numrows()) { //$ids = $res->fetch_col_array('id'); //$n_res = dok_oquery('select album_id, count(*) as c from '.dok_tn('rel_song_album').' where album_id in('.implode(',',$ids).') group by album_id'); //$n_array = $n_res->fetch_col_array('c','album_id'); while ($row = $res->fetch_array()) { $t->set_var('ALBUM_LINK', $_SERVER['PHP_SELF'] . '?display=view_album&id=' . $row['id']); $t->set_var('ALBUM_NAME', $row['name']); $t->set_var('ALBUM_HITS', $row['hits']); $t->set_var('ALBUM_LENGTH', dok_sec2str($row['length'])); if ($row['c'] > 0) { $t->set_var('ALBUM_SONGS', $row['c']); } else { $t->set_var('ALBUM_SONGS', 0); } $t->parse('album_block', 'album', 'true'); } $t_query = 'select count(*) as c from ' . dok_tn('album') . ' as a'; if (sizeof($where)) { $t_query .= ' where ' . implode(' AND ', $where); } $res = mysql_query($t_query); $total = mysql_result($res, 0, 'c'); if ($total > $VARS['offset'] + DOK_LIST_EPP) { $link = $_SERVER['PHP_SELF'] . '?display=list_albums&alpha=' . $VARS['alpha'] . '&offset=' . ($VARS['offset'] + DOK_LIST_EPP . '&artist=' . $VARS['artist']); if (isset($VARS['sort'])) { $link .= '&sort=' . $VARS['sort']; } $t->set_var('NEXT_PAGE_LINK', $link); $t->parse('next_page_block', 'next_page'); } else { $t->set_var('next_page_block', ''); } } else { $t->set_var('album_block', MSG_NO_ALBUM); $t->set_var('next_page_block', ''); } return array($t, MSG_TITLE_LIST_ALBUM); }
/** *get PHPlib variables for a song * * */ function dok_song_format($data, $pager_infos = '') { global $THEME_DATE, $THEME_SONG_LABEL; $label = dok_song_label_vars($data['label']); $ret = $label; $ret['SONG_NAME'] = $data['name']; $ret['SONG_ID'] = $data['id']; $ret['SONG_HITS'] = $data['hits']; $ret['SONG_LINK'] = $_SERVER['PHP_SELF'] . '?display=view_song&id=' . $data['id']; if (is_array($pager_infos)) { $ret['SONG_LINK'] .= '&pager_related=' . $pager_infos['related'] . '&pager_related_id=' . $pager_infos['related_id']; } $ret['SONG_ARTIST'] = dok_get_artists_string($data['id'], $data['ignore_artist']); $ret['SONG_LENGTH'] = dok_sec2str($data['length']); $ret['SONG_RELEASE'] = dok_year2str($data['release']); $ret['SONG_COMMENT'] = $data['comment']; $ret['SONG_DB_CREATION'] = date($THEME_DATE, $data['creation']); $ret['SONG_GENRE'] = dok_genre_name($data['genre']); if ($data['label'] > 0) { $t = new template(getcwd()); $t->set_var('song_label', $THEME_SONG_LABEL); $t->set_var($label); $ret['SONG_LABEL_LINE'] = $t->finish($t->parse('out', 'song_label')); } else { $ret['SONG_LABEL_LINE'] = ''; } //print_r($ret); return $ret; }
function dok_list_artists($VARS, $up, $theme_path) { $orders = array('count', 'length', 'albums'); $t = new template($theme_path); $t->set_file('page', 'artist_list.tpl'); $t->set_block('page', 'artist', 'artist_block'); $t->set_block('page', 'next_page', 'next_page_block'); if (!isset($VARS['alpha'])) { $VARS['alpha'] = '-'; } $VARS['alpha'] = mysql_real_escape_string($VARS['alpha']); if (isset($VARS['sort']) && !in_array($VARS['sort'], $orders)) { unset($VARS['sort']); } if (!strlen($VARS['offset']) || $VARS['offset'] < 0) { $VARS['offset'] = '0'; } $display = array(); // here we do 2 queries: it's better than 1 for mysql if (isset($VARS['sort'])) { $my_display = array(); $query = "select r.artist_id as id, count(distinct r.song_id) as count, sum(s.length) as length, count(distinct al.album_id) as albums from " . dok_tn("rel_song_artist") . ' as r left join ' . dok_tn('song') . ' as s on r.song_id=s.id left join ' . dok_tn('rel_song_album') . ' as al on r.song_id=al.song_id group by r.artist_id order by ' . $VARS['sort'] . ' desc limit ' . $VARS['offset'] . ', ' . DOK_LIST_EPP; //echo $query; $res = dok_oquery($query); while ($row = $res->fetch_array()) { $my_display[$row['id']] = array('id' => $row['id'], 'count' => $row['count'], 'length' => $row['length'], 'albums' => $row['albums']); } if (sizeof($my_display)) { $query = 'select name,id from ' . dok_tn('artist') . ' where id in(' . implode(', ', array_keys($my_display)) . ')'; $res = dok_oquery($query); while ($row = $res->fetch_array()) { $my_display[$row['id']]['name'] = $row['name']; } foreach ($my_display as $one) { $display[] = $one; } } } else { $my_display = array(); $query = 'select name,id from ' . dok_tn('artist') . ' where LEFT(name,1) >= \'' . $VARS['alpha'] . '\' order by name limit ' . $VARS['offset'] . ', ' . DOK_LIST_EPP; $res = dok_oquery($query); while ($row = $res->fetch_array()) { $my_display[$row['id']] = array('name' => $row['name'], 'id' => $row['id']); } if (sizeof($my_display)) { $query = "select r.artist_id as id, count(DISTINCT r.song_id) as count, sum(s.length) as length, count(distinct al.album_id) as albums from " . dok_tn("rel_song_artist") . ' as r left join ' . dok_tn('song') . ' as s on r.song_id=s.id left join ' . dok_tn('rel_song_album') . ' as al on r.song_id=al.song_id where r.artist_id in(' . implode(', ', array_keys($my_display)) . ') group by r.artist_id'; $res = dok_oquery($query); while ($row = $res->fetch_array()) { $my_display[$row['id']]['count'] = $row['count']; $my_display[$row['id']]['length'] = $row['length']; $my_display[$row['id']]['albums'] = $row['albums']; } foreach ($my_display as $one) { $display[] = $one; } } } if (sizeof($display)) { $display_first = $VARS['offset'] + 1; $display_last = $display_first - 1; foreach ($display as $row) { $t->set_var('ARTIST_LINK', $_SERVER['PHP_SELF'] . '?display=view_artist&id=' . $row['id']); $t->set_var('ARTIST_NAME', $row['name']); $t->set_var('ARTIST_SONGS', $row['count']); $t->set_var('ARTIST_ALBUMS', $row['albums']); $t->set_var('ARTIST_LENGTH', dok_sec2str($row['length'])); $t->parse('artist_block', 'artist', 'true'); $display_last++; } if (isset($VARS['sort'])) { $t_query = 'select count(*) as c from ' . dok_tn('rel_song_artist') . ' as r group by r.artist_id'; } else { $t_query = 'select id from ' . dok_tn('artist') . ' where LEFT(name,1) >= \'' . $VARS['alpha'] . '\''; //$t_query='select count(*) as c from '.dok_tn('rel_song_artist').' as r left join '.dok_tn('artist').' as a on r.artist_id = a.id where substring(a.name from 1 for 1) >= \''.$VARS['alpha'].'\' group by r.artist_id'; //echo $t_query; } $res = mysql_query($t_query); $total = mysql_numrows($res); if ($total > $VARS['offset'] + DOK_LIST_EPP) { $t->set_var('NEXT_PAGE_LINK', $_SERVER['PHP_SELF'] . '?display=list_artists&alpha=' . $VARS['alpha'] . '&offset=' . ($VARS['offset'] + DOK_LIST_EPP) . '&sort=' . $VARS['sort']); $t->parse('next_page_block', 'next_page'); } else { $t->set_var('next_page_block', ''); } } else { $t->set_var('artist_block', MSG_NO_ARTIST); $t->set_var('next_page_block', ''); } return array($t, MSG_TITLE_LIST_ARTIST); }
function dok_ask_dup_song($VARS, $update, $theme_path) { global $SONGS_LABELS; if (!is_array($VARS['duplicates']) || !sizeof($VARS['duplicates'])) { $t = dok_error_template(MSG_ERR_NO_DUP_SONG); return array($t, sprintf(MSG_TITLE_DUP_SONG, '')); } if (!$VARS['label'] || $VARS['label'] == 0) { $new_song_label = MSG_LABEL_NONE; } else { $new_song_label = $SONGS_LABELS[$VARS['label']]['label']; } if (!$VARS['track'] || $VARS['track'] == 0) { $new_song_track = MSG_ALBUM_NEXT_TRACK; } else { $new_song_track = $VARS['track']; } /* *find related songs * */ //$res = dok_oquery('select * from '.dok_tn('rel_songs').' where song_id1 = $t = new template($theme_path); $t->set_file('page', 'song_dup.tpl'); $t->set_block('page', 'duplicate', 'dup_block'); $query = 'select * from ' . dok_tn('song') . ' where id in(' . implode(',', $VARS['duplicates']) . ')'; $res = mysql_query($query); $relations = dok_songs_links_array(); while ($row = mysql_fetch_array($res)) { $t->set_var(dok_song_format($row)); $relations_select = '<select name="link[' . $row['id'] . ']"><option value="" SELECTED>' . MSG_RELATION_NONE . '</option>' . "\n"; foreach ($relations as $key => $val) { $relations_select .= '<option value="' . $key . '">' . $val . '</option>' . "\n"; } $relations_select .= '</select>'; $t->set_var('SONG_RELATION_SELECT', $relations_select); $t->parse('dup_block', 'duplicate', 'true'); } if ($update == 'create_song') { $res = mysql_query('select name from ' . dok_tn('album') . ' where id = ' . $VARS['album']); if (!mysql_numrows($res)) { $album = MSG_UNKNOWN; } else { $album = mysql_result($res, 0, 'name'); } $res = mysql_query('select name from ' . dok_tn('artist') . ' where id = ' . $VARS['artist']); if (!mysql_numrows($res)) { $artist = MSG_UNKNOWN; } else { $artist = mysql_result($res, 0, 'name'); } $t->set_var(array('NEW_SONG_NAME' => $VARS['name'], 'NEW_SONG_COMMENT' => dok_textarea_2_db($VARS['comment']), 'NEW_SONG_TRACK' => $new_song_track, 'NEW_SONG_LENGTH' => $VARS['length'], 'NEW_SONG_LABEL' => $new_song_label, 'NEW_SONG_ARTIST' => $artist, 'NEW_SONG_ALBUM' => $album, 'NEW_SONG_GENRE' => dok_genre_name($VARS['genre']), 'NEW_SONG_RELEASE' => dok_year2str($VARS['release']))); } else { $t->set_var(array('NEW_SONG_NAME' => $VARS['name'], 'NEW_SONG_COMMENT' => dok_textarea_2_db($VARS['comment']), 'NEW_SONG_TRACK' => $new_song_track, 'NEW_SONG_LENGTH' => dok_sec2str($VARS['length']), 'NEW_SONG_GENRE' => dok_genre_name($VARS['genre']), 'NEW_SONG_LABEL' => $new_song_label, 'NEW_SONG_ARTIST' => '', 'NEW_SONG_ALBUM' => '', 'NEW_SONG_RELEASE' => dok_year2str($VARS['release']))); } $yes_form = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '"><input type=hidden name="update" value="' . $update . '">'; $yes_form .= '<input type=hidden name="dup_checked" value="1">'; if ($update == 'update_song') { $yes_form .= '<input type=hidden name="id" value="' . $VARS['id'] . '">'; } $yes_form .= '<input type=hidden name="artist" value="' . $VARS['artist'] . '">'; $yes_form .= '<input type=hidden name="album" value="' . $VARS['album'] . '">'; $yes_form .= '<input type=hidden name="track" value="' . str_replace('"', '"', $VARS['track']) . '">'; $yes_form .= '<input type=hidden name="name" value="' . str_replace('"', '"', $VARS['name']) . '">'; $yes_form .= '<input type=hidden name="length" value="' . str_replace('"', '"', $VARS['length']) . '">'; $yes_form .= '<input type=hidden name="release" value="' . str_replace('"', '"', $VARS['release']) . '">'; $yes_form .= '<input type=hidden name="comment" value="' . str_replace('"', '"', $VARS['comment']) . '">'; $yes_form .= '<input type=hidden name="label" value="' . str_replace('"', '"', $VARS['label']) . '">'; $yes_form .= '<input type=hidden name="genre" value="' . $VARS['genre'] . '">'; $t->set_var('SONG_RECORD_FORM', $yes_form); return array($t, MSG_TITLE_DUP_SONG); }
function dok_view_artist($VARS, $update_module, $tpl_path) { global $THEME_DATE, $USER; if (!isset($VARS['id']) || !is_numeric($VARS['id']) || $VARS['id'] < 1) { $t = dok_error_template(MSG_ERR_ARTIST_DISPLAY); return array($t, sprintf(MSG_TITLE_DISPLAY_ARTIST, '')); } $res = mysql_query('select name, creation from ' . dok_tn('artist') . ' where id = ' . $VARS['id']); if (!mysql_numrows($res)) { $t = dok_error_template(MSG_ERR_ARTIST_DISPLAY); return array($t, sprintf(MSG_TITLE_DISPLAY_ARTIST, '')); } $row = mysql_fetch_assoc($res); $t = new template($tpl_path); $t->set_file('page', 'artist_display.tpl'); $t->set_block('page', 'all_albums', 'all_albums_block'); $t->set_block('page', 'all_songs', 'all_songs_block'); $t->set_block('page', 'if_artisteditor', 'editor_block'); $t->set_block('page', 'artist_albums', 'albums_block'); $t->set_block('page', 'artist_songs', 'songs_block'); $t->set_block('page', 'related_artists', 'related_artists_block'); $t->set_var(array('ARTIST_NAME' => $row['name'], 'ARTIST_DB_CREATION' => date($THEME_DATE, $row['creation']))); if (DOK_ENABLE_USER && !$USER->editor && !$USER->admin) { $t->set_var('editor_block', ''); } else { $t->set_var('ARTIST_EDIT_LINK', $_SERVER['PHP_SELF'] . '?display=edit_artist&id=' . $VARS['id']); $t->parse('editor_block', 'if_artisteditor'); } $songs =& dok_rel_song_artist(array(), array($VARS['id'])); $display_songs = array(); echo mysql_error(); if (!$songs->numrows()) { $t->set_var('songs_block', MSG_NO_SONG); $t->set_var('albums_block', MSG_NO_ALBUM); $t->set_var('related_artists_block', MSG_NO_RELATED_ARTIST); $t->set_var('all_songs_block', ''); $t->set_var('all_albums_block', ''); } else { $all_songs = $songs->fetch_col_array('song_id'); $t->set_var('ARTIST_SONGS', sizeof($all_songs)); if (sizeof($all_songs) > DOK_SONGS_ON_ARTIST_PAGE) { $t->set_var('ALL_SONGS_LINK', $_SERVER['PHP_SELF'] . '?display=list_songs&artist=' . $VARS['id']); $t->set_var('ARTIST_REMAINING_SONGS', sizeof($all_songs) - DOK_SONGS_ON_ARTIST_PAGE); $t->parse('all_songs_block', 'all_songs'); $display_songs = array_slice($all_songs, 0, DOK_SONGS_ON_ARTIST_PAGE); } else { $display_songs = $all_songs; $t->set_var('all_songs_block', ''); } $query = 'select * from ' . dok_tn('song') . ' where id in(' . implode(',', $display_songs) . ') order by hits desc,name, creation desc'; unset($songs); $songs = dok_oquery($query); $pager_data = array('related' => 'artist', 'related_id' => $VARS['id']); while ($song = $songs->fetch_array()) { //$sl = dok_sec2min($song['length']); $song['ignore_artist'] = $VARS['id']; $t->set_var(dok_song_format($song, $pager_data)); $t->parse('songs_block', 'artist_songs', 'true'); } //$all_songs = $songs->fetch_col_array('id'); unset($songs); $query = 'select distinct(album_id) from ' . dok_tn('rel_song_album') . ' where song_id in(' . implode(',', $all_songs) . ')'; $albums = dok_oquery($query); $t->set_var('ARTIST_ALBUMS', $albums->numrows()); if (!$albums->numrows()) { $t->set_var('albums_block', MSG_NO_ALBUM); $t->set_var('all_albums_block', ''); } else { $albums_display = array(); $albums_id = $albums->fetch_col_array('album_id'); unset($albums); if (sizeof($albums_id) > DOK_ALBUMS_ON_ARTIST_PAGE) { $albums_display = array_slice($albums_id, 0, DOK_ALBUMS_ON_ARTIST_PAGE); $t->set_var('ALL_ALBUMS_LINK', $_SERVER['PHP_SELF'] . '?display=list_albums&artist=' . $VARS['id']); $t->set_var('ARTIST_REMAINING_ALBUMS', sizeof($albums_id) - DOK_ALBUMS_ON_ARTIST_PAGE); $t->parse('all_albums_block', 'all_albums'); } else { $albums_display = $albums_id; $t->set_var('all_albums_block', ''); } $albums = dok_oquery('select a.id, a.name, a.creation, count(s.id) as count, sum(s.length) as length from ' . dok_tn('album') . ' as a left join ' . dok_tn('rel_song_album') . ' as r on a.id=r.album_id left join ' . dok_tn('song') . ' as s on r.song_id=s.id where a.id in (' . implode(',', $albums_display) . ') group by r.album_id order by a.name'); while ($album = $albums->fetch_array()) { $t->set_var(array('ALBUM_LINK' => $_SERVER['PHP_SELF'] . '?display=view_album&id=' . $album['id'], 'ALBUM_NAME' => $album['name'], 'ALBUM_LENGTH' => dok_sec2str($album['length']), 'ALBUM_SONGS' => $album['count'], 'ALBUM_DB_CREATION' => date($THEME_DATE, $album['creation']))); $t->parse('albums_block', 'artist_albums', 'true'); } } $query = 'select a.name, a.id, count(*) as c from ' . dok_tn('rel_song_artist') . ' as r left join ' . dok_tn('artist') . ' as a on r.artist_id = a.id where r.song_id in(' . implode(',', $all_songs) . ') and artist_id != ' . $VARS['id'] . ' group by r.artist_id order by c desc limit 7'; //echo $query; $res = mysql_query($query); if (!mysql_numrows($res)) { $t->set_var('related_artists_block', MSG_NO_RELATED_ARTIST); } else { while ($row = mysql_fetch_array($res)) { $t->set_var(array('RELATED_ARTIST_LINK' => $_SERVER['PHP_SELF'] . '?display=view_artist&id=' . $row['id'], 'RELATED_ARTIST_NAME' => $row['name'])); $t->parse('related_artists_block', 'related_artists', 'true'); } } } return array($t, sprintf(MSG_TITLE_DISPLAY_ARTIST, $row['name'])); }