コード例 #1
0
ファイル: backend.php プロジェクト: cyrilix/rompr
function do_tracks_from_database($why, $what, $who, $fragment = false)
{
    debuglog("Generating tracks for album " . $who . " from database", "DUMPALBUMS", 7);
    if ($fragment) {
        ob_start();
    }
    $track_is_album = false;
    $track_is_artist = false;
    debuglog("Looking for albumID " . $who, "DUMPALBUMS", 8);
    $numdiscs = 1;
    if ($result2 = generic_sql_query("SELECT MAX(Disc) AS NumDiscs FROM Tracktable WHERE Albumindex = '" . $who . "' AND Uri IS NOT NULL AND Hidden=0")) {
        $obj2 = $result2->fetch(PDO::FETCH_OBJ);
        $numdiscs = $obj2->NumDiscs;
    } else {
        debuglog("ERROR! Couldn't find NumDiscs for Albumindex " . $who, "MYSQL", 3);
    }
    $t = $why == "b" ? "AND isSearchResult > 0" : "AND isSearchResult < 2";
    if ($result = generic_sql_query("SELECT t.*, a.Artistname, b.AlbumArtistindex, r.Rating, ti.Image, tg.Name FROM\n\t\tTracktable AS t JOIN Artisttable AS a ON t.Artistindex = a.Artistindex\n\t\tJOIN Albumtable AS b ON t.Albumindex = b.Albumindex\n\t\tLEFT JOIN Ratingtable AS r ON r.TTindex = t.TTindex\n\t\tLEFT JOIN Trackimagetable AS ti ON ti.TTindex = t.TTindex\n\t\tLEFT JOIN TagListtable AS tl oN tl.TTindex = t.TTindex\n\t\tLEFT JOIN Tagtable AS tg ON tl.Tagindex = tg.Tagindex\n\t\tWHERE t.Albumindex = '" . $who . "' AND Uri IS NOT NULL AND Hidden=0 " . $t . " ORDER BY\n\t\tCASE WHEN t.Title LIKE 'Album: %' THEN 1 ELSE 2 END, t.Disc, t.TrackNo")) {
        $trackarr = $result->fetchAll(PDO::FETCH_OBJ);
        $numtracks = count_num_tracks($trackarr);
        $currdisc = -1;
        $count = 0;
        $current_tti = -1;
        $track = array();
        while ($obj = array_shift($trackarr)) {
            if ($obj->TTindex != $current_tti) {
                if ($count > 0) {
                    if ($numdiscs > 1 && $track['disc'] != $currdisc && $track['disc'] > 0) {
                        $currdisc = $track['disc'];
                        print '<div class="discnumber indent">' . ucfirst(strtolower(get_int_text("musicbrainz_disc"))) . ' ' . $currdisc . '</div>';
                    }
                    albumTrack($track['artist'], $track['rating'], $track['uri'], $track['numtracks'], $track['trackno'], $track['title'], $track['time'], $track['lm'], $track['image'], $track['tags']);
                }
                $track = array('artist' => $obj->Artistindex != $obj->AlbumArtistindex ? $obj->Artistname : null, 'rating' => $obj->Rating, 'uri' => rawurlencode($obj->Uri), 'numtracks' => $numtracks, 'trackno' => $obj->TrackNo, 'title' => $obj->Title, 'time' => $obj->Duration, 'lm' => $obj->LastModified, 'image' => $obj->Image, 'tags' => array(), 'disc' => $obj->Disc);
                $current_tti = $obj->TTindex;
            }
            if ($obj->Name) {
                $track['tags'][] = $obj->Name;
            }
            $track_is_album = preg_match('/^.+?:album:/', $obj->Uri) ? $obj->Uri : false;
            $track_is_artist = preg_match('/^.+?:artist:/', $obj->Uri) ? $obj->Uri : false;
            $count++;
        }
        if ($count > 0) {
            albumTrack($track['artist'], $track['rating'], $track['uri'], $track['numtracks'], $track['trackno'], $track['title'], $track['time'], $track['lm'], $track['image'], $track['tags']);
        }
        if ($track_is_artist !== false) {
            debuglog("Album " . $who . " has no tracks, just an artist link", "SQL", 6);
            print '<input type="hidden" class="expandartist"/>';
        } else {
            if ($track_is_album !== false) {
                debuglog("Album " . $who . " has no tracks, just an album link", "SQL", 6);
                print '<input type="hidden" class="expandalbum"/>';
            }
        }
    } else {
        print '<h3>' . get_int_text("label_general_error") . '</h3>';
    }
    if ($fragment) {
        $s = ob_get_contents();
        ob_end_clean();
        return $s;
    }
}
コード例 #2
0
ファイル: functions.php プロジェクト: cyrilix/rompr
function getWishlist()
{
    global $mysqlc, $divtype, $prefs;
    if ($mysqlc === null) {
        connect_to_database();
    }
    $qstring = 'SELECT wishlist.*, Ratingtable.Rating FROM
        (SELECT Tracktable.TTindex AS ttindex, Tracktable.Title AS track, Tracktable.TrackNo
            AS num, Tracktable.Duration AS time, Tracktable.Disc as disc, Artisttable.Artistname
            AS artist, Albumtable.Albumname AS album, Albumtable.Image AS image, Albumtable.ImgKey
            AS imgkey FROM Tracktable JOIN Artisttable USING (Artistindex) JOIN Albumtable ON
            Tracktable.Albumindex = Albumtable.Albumindex WHERE Uri IS NULL AND Hidden = 0
        UNION
        SELECT Tracktable.TTindex AS ttindex, Tracktable.Title AS track, Tracktable.TrackNo
            AS num, Tracktable.Duration AS time, Tracktable.Disc as disc, Artisttable.Artistname
            AS artist, "" AS Albumname, NULL as Image, NULL AS ImgKey FROM Tracktable JOIN
            Artisttable USING (Artistindex) WHERE Albumindex IS NULL AND Uri IS NULL AND Hidden = 0)
        AS wishlist
        LEFT JOIN Ratingtable ON Ratingtable.TTindex = wishlist.ttindex
        ORDER BY ';
    foreach ($prefs['artistsatstart'] as $a) {
        $qstring .= "CASE WHEN LOWER(artist) = LOWER('" . $a . "') THEN 1 ELSE 2 END, ";
    }
    if (count($prefs['nosortprefixes']) > 0) {
        $qstring .= "(CASE ";
        foreach ($prefs['nosortprefixes'] as $p) {
            $phpisshitsometimes = strlen($p) + 2;
            $qstring .= "WHEN LOWER(artist) LIKE '" . strtolower($p) . " %' THEN LOWER(SUBSTR(artist," . $phpisshitsometimes . ")) ";
        }
        $qstring .= "ELSE LOWER(artist) END)";
    } else {
        $qstring .= "LOWER(artist)";
    }
    $qstring .= ', LOWER (album),
    num';
    $current_artist = "";
    $current_album = "";
    $count = 0;
    if ($result = generic_sql_query($qstring)) {
        while ($obj = $result->fetch(PDO::FETCH_OBJ)) {
            $bothclosed = false;
            debuglog("Found Track " . $obj->track, "WISHLIST");
            if ($current_artist != $obj->artist) {
                if ($current_artist != "") {
                    print '</div></div>';
                    $bothclosed = true;
                }
                $current_artist = $obj->artist;
                print artistHeader("wishlistartist_" . $count, $obj->artist);
                print '<div id="wishlistartist_' . $count . '" class="dropmenu ' . $divtype . '">';
                $count++;
                $divtype = $divtype == "album1" ? "album2" : "album1";
            }
            if ($current_album != $obj->album) {
                if (!$bothclosed && $current_album != "") {
                    print '</div>';
                }
                $current_album = $obj->album;
                print albumHeader($obj->album, null, 'wishlistalbum_' . $count, $obj->image === null ? "no" : "yes", $obj->album == "" ? "yes" : "no", $obj->imgkey, $obj->image, null, null, null);
                print '<div id="wishlistalbum_' . $count . '" class="dropmenu">';
                $count++;
            }
            albumTrack(null, $obj->Rating, null, 0, $obj->num, $obj->track, 0, null, null);
        }
    }
}