예제 #1
0
파일: track.cpp 프로젝트: eqbeats/eqbeats
void Pages::track(Document *doc){

    std::string sub;
    int tid = route("track", path, sub);
    bool post = cgi.getEnvironment().getRequestMethod() == "POST";

    if(!tid) return;

    if(sub == ""){

        ExtendedTrack t(tid);
        if(!t) return;

        doc->setHtml("html/track.tpl", t.title);

        doc->rootDict()->SetValueAndShowSection("TID", number(t.id), "HAS_OEMBED");
        t.fill(doc->dict());
        t.player(doc->dict(), true);
        Audio(&t).fill(doc->dict());

        Dict *embed = doc->dict()->AddIncludeDictionary("EMBED_CODE");
        embed->SetFilename("html/embed-code.tpl");
        embed->SetIntValue("WIDTH", 150);
        t.Track::fill(embed);

        Dict *uploader = doc->dict()->AddIncludeDictionary("UPLOADER");
        uploader->SetFilename("html/uploader.tpl");
        uploader->SetValue("ACTION", t.url() + "/upload");

        EventList::track(t).fill(doc->dict(), "EVENTS");
    }
}
예제 #2
0
Dict* Track::player(Dict *d, bool fallback) const{
    Dict *p = d->AddIncludeDictionary("PLAYER");
    p->SetFilename("html/player.tpl");
    fill(p);
    p->SetIntValue("LIST", id);
    if(fallback) p->ShowSection("FALLBACK");
    return p;
}
예제 #3
0
파일: user.cpp 프로젝트: eqbeats/eqbeats
void Pages::user(Document *doc){

    std::string sub;
    int uid = route("user", path, sub);

    if(!uid || (sub != "" && sub != "json")) return;

    Account u(uid);
    if(!u) return;

    if(sub == "json"){
        doc->setJson("json/account.tpl");
        u.fill(doc->dict());
        doc->dict()->ShowSection("LONG");
        Tracks::byUser(u.id, 0).fillJson(doc->dict(), false);

        std::vector<Playlist> playlists = Playlist::forUser(u);
        for(std::vector<Playlist>::const_iterator i=playlists.begin(); i!=playlists.end(); i++){
            Dict *playlistDict = doc->dict()->AddSectionDictionary("PLAYLIST");
            Dict *item = playlistDict->AddIncludeDictionary("PLAYLIST");
            item->SetFilename("json/playlist.tpl");
            i->fill(item);
        }

    } else { // plain HTML
        doc->setHtml("html/user.tpl", u.name);
        u.fill(doc->dict());
        Tracks::byUser(u.id, u.self()).fill(doc->dict(), "TRACK_LIST");

#ifdef HAVE_LIBHIREDIS
        Stat::push("userView", uid);
#endif

        std::vector<Playlist> playlists = Playlist::forUser(u);
        doc->dict()->ShowSection(playlists.empty() ? "NO_PLAYLIST" : "HAS_PLAYLISTS");
        for(std::vector<Playlist>::const_iterator i=playlists.begin(); i!=playlists.end(); i++){
            Dict *playlistDict = doc->dict()->AddSectionDictionary("PLAYLIST");
            i->fill(playlistDict);
        }

        EventList::user(u, 12).fill(doc->dict(), "EVENTS");
        Follower(u.id).followed().fill(doc->dict(), "FOLLOWED_USERS");

        Feature(u.id).fill(doc->dict());

    }
}
예제 #4
0
void Pages::track(Document *doc){

    std::string sub;
    int tid = route("track", path, sub);
    bool post = cgi.getEnvironment().getRequestMethod() == "POST";

    if(!tid) return;

    if(sub == ""){

        ExtendedTrack t(tid);
        if(!t) return;

        doc->setHtml("html/track.tpl", t.title);

        doc->rootDict()->SetValueAndShowSection("TID", number(t.id), "HAS_OEMBED");
        t.fill(doc->dict());
        t.player(doc->dict(), true);
        Audio(&t).fill(doc->dict());

        doc->dict()->ShowSection(Youtube(t.artist.id) ? "HAS_YOUTUBE" : "NO_YOUTUBE");

        Dict *embed = doc->dict()->AddIncludeDictionary("EMBED_CODE");
        embed->SetFilename("html/embed-code.tpl");
        embed->SetIntValue("WIDTH", 150);
        t.Track::fill(embed);

        Dict *uploader = doc->dict()->AddIncludeDictionary("UPLOADER");
        uploader->SetFilename("html/uploader.tpl");
        uploader->SetValue("ACTION", t.url() + "/upload");

        int hits = Stat::push("trackView", t.artist.id, tid);
        doc->dict()->SetValue("HIT_COUNT", number(hits));
        int unique_hits = Stat::get("trackView", 0, tid, true);
        doc->dict()->SetValue("UNIQUE_HIT_COUNT", number(unique_hits));
        doc->rootDict()->ShowSection("REQUIRES_STATS_JS");

        Session::fill(doc->dict());
        EventList::track(t).fill(doc->dict(), "EVENTS", false);
        doc->dict()->ShowSection(Follower(Session::user().id).favorited(tid) ? "IS_FAVORITE" : "NOT_FAVORITE");

        if(Session::user()){
            DB::Result playlists = DB::query(
                "SELECT id, name FROM playlists WHERE user_id = " + number(Session::user().id) + " ORDER BY name ASC");
            if(!playlists.empty()){
                doc->dict()->ShowSection("HAS_PLAYLISTS");
                for(DB::Result::const_iterator i=playlists.begin(); i!=playlists.end(); i++){
                    Dict *playlist = doc->dict()->AddSectionDictionary("PLAYLIST");
                    playlist->SetValue("PLAYLIST_ID", i->at(0));
                    playlist->SetValue("PLAYLIST_NAME", i->at(1));
                }
            }
        }
    }

    else if(sub == "delete"){
        Track t(tid);
        if(!t) return;
        if(!t.artist.self())
            doc->redirect(t.url());

        else if(!post || cgi("confirm") != "Delete" || Session::nonce() != cgi("nonce")){
            Session::newNonce();
            doc->setHtml("html/delete.tpl", "Track deletion");
            doc->dict()->SetValue("WHAT", t.title);
            doc->dict()->SetValue("CANCEL_URL", t.url());
        }

        else{
            log("Deleting track: " + t.title + " (" + number(t.id) + ")");

            Art art(t.id);
            if(art) art.remove();
            Audio(&t).unlink();

            Playlist::removeTrack(t.id);
            DB::query("DELETE FROM events WHERE track_id = " + number(t.id));
            DB::query("DELETE FROM featured_tracks WHERE track_id = " + number(t.id));
            DB::query("DELETE FROM favorites WHERE type = 'track' AND ref = " + number(t.id));
            DB::query("DELETE FROM user_features WHERE type = 'track' AND ref = " + number(t.id));
            DB::query("DELETE FROM tracks WHERE id = " + number(t.id));

            doc->redirect(Session::user().url());
        }

    }

    else if(sub == "publish"){
        Track t(tid);
        if(!t) return;
        if(tid != number(cgi("tid")))
            return doc->redirect(t.url());

        if(t.artist.self() && !t.visible && post){

            DB::query("UPDATE tracks SET visible = 't', date = 'now' WHERE id = " + number(t.id));

            Event e;
            e.type = Event::Publish;
            e.source = t.artist;
            e.track = t;
            e.push();

            std::vector<std::string> emails = Follower(t.artist.id).followers();
            std::string maildata =
                "From: EqBeats notification <*****@*****.**>\n"
                "Message-ID: notify-t" + number(t.id) + "\n"
                "Subject: " + filter("EqBeats notification: " + t.artist.name + " - " + t.title) + "\n"
                "Precedence: bulk\n\n" +
                t.artist.name + " just published a new track : " + t.title + "\n"
                "Listen to it here : " + eqbeatsUrl() + t.url() + "\n\n"
                "You're receiving this email because you're following " + t.artist.name + " on EqBeats.\n"
                "If you don't want to receive these notifications anymore, go to " + eqbeatsUrl() + t.artist.url() + " and click \"Stop following\".";
            for(std::vector<std::string>::const_iterator i = emails.begin(); i!=emails.end(); i++)
                sendMail(i->c_str(), maildata.c_str());

        }
        doc->redirect(t.url());

    }

}