param("action")]) { $function = "a_".$_GET[$env->param("action")]; if(function_exists($function)) { $function($env); } } } # ----------------------------------------------------------------------------------- # actions # # ---------------------------------------- # playlists audio generales function a_last_downloads($env) { if(($downloads = $env->data->pl_last_downloads(10)) !== false) { if($_GET[$env->param("format")] == "m3u") { echo get_m3u($downloads); exit; } elseif($_GET[$env->param("format")] == "atom") { $env->out["atom"] = get_downloads_atom ( "last_downloads", $env->config("site_name"), "les 10 derniers morceaux", "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "last_downloads", "format" => "atom"), "backend.php"), "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "playlist", "action" => "last_downloads"), "index.php"), $downloads ); } } else echo "Erreur lors de l'accès aux downloads"; } function a_rand_downloads($env) { header('Content-type: application/atom+xml; charset=UTF-8'); if(($downloads = $env->data->pl_rand_downloads(10)) !== false) { if($_GET[$env->param("format")] == "m3u") { echo get_m3u($downloads); exit; } elseif($_GET[$env->param("format")] == "atom") { $env->out["atom"] = get_downloads_atom ( "rand_downloads", $env->config("site_name"), "10 morceaux au hasard", "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "rand_downloads", "format" => "atom"), "backend.php"), "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "playlist", "action" => "rand_downloads"), "index.php"), $downloads ); } } else echo "Erreur lors de l'accès aux downloads"; } # ---------------------------------------- # playlists artistes function a_artiste_downloads($env) { if($_GET[$env->param("format")] == "m3u") { if ( ( $downloads = $env->data->pl_artiste_downloads ( $_GET[$env->param("artiste")], isset($_GET[$env->param("album")]) ? $_GET[$env->param("album")] : null ) ) !== false ) { echo get_m3u($downloads); exit; } else echo "Erreur lors de l'accès aux downloads"; } } function a_artiste_mp3($env) { if($_GET[$env->param("format")] == "playlist_xml") { if ( ( $env->out["downloads"] = $env->data->artiste_downloads ( $_GET[$env->param("artiste")], true, $_GET[$env->param("album")] ? $_GET[$env->param("album")] : null ) ) !== false ) { header("Content-Type: application/xml"); } else echo "Erreur lors de l'accès aux downloads"; } } # ---------------------------------------- # news generales function a_last_news($env) { if(($news = $env->data->contenus(array("root", "news"), 0, 10, " AND public=1 AND date_publication <= NOW()")) !== false) { $news = $news["list"]; foreach($news as $id_news => $_news) $news[$id_news]["url"] = "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "content", "id" => $id_news), "index.php"); if($_GET[$env->param("format")] == "atom") { $env->out["atom"] = get_content_atom ( "last_news", $env->config("site_name"), "les 10 dernieres news", "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "last_news", "format" => "atom"), "backend.php"), "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "accueil"), "index.php"), $news ); } } else echo "Erreur lors de l'accès aux downloads"; } # ---------------------------------------- # news artistes function a_last_artiste_news($env) { if(($news = $env->data->contenus(array("root", "artistes", "news", $_GET[$env->param("artiste")]), 0, 10, " AND public=1 AND date_publication <= NOW()")) !== false) { $news = $news["list"]; foreach($news as $id_news => $_news) $news[$id_news]["url"] = "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "content", "id" => $id_news), "index.php"); if($_GET[$env->param("format")] == "atom") { $env->out["atom"] = get_content_atom ( "last_news", $env->config("site_name"), "les 10 dernieres news", "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "last_news", "format" => "atom"), "backend.php"), "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "accueil"), "index.php"), $news ); } } else echo "Erreur lors de l'accès aux downloads"; } # ----------------------------------------------------------------------------------- # utils # function get_m3u($downloads, $debug = false) { $playlist = "#EXTM3U\n"; if($downloads) foreach($downloads as $id => $download) { $playlist .= "#EXTINF:-1,".$download["titre"]."\n" .$download["url"]."\n"; } if(!$debug) { header("Content-type: audio/x-mpegurl"); header('Content-Disposition: inline; filename=playlist.m3u'); header("Content-Length: ".strlen($playlist)); } return $playlist; } function get_downloads_atom($id, $author, $title, $self, $alternate, $downloads) { $atom = array ( "id" => "tag:".$_SERVER["HTTP_HOST"].",".date("Y-m-d").":".$id, "author_name" => $author, "title" => $title, "updated" => date("Y-m-d")."T".date("H:i:s")."Z", "link" => array("self" => str_replace("&", "&", $self), "alternate" => str_replace("&", "&", $alternate)), "entries" => array() ); foreach($downloads as $id_download => $download) { $atom["entries"][$id_download] = array ( "id" => "tag:".$_SERVER["HTTP_HOST"]."," .$download["year_updated"]."-".$download["month_updated"]."-".$download["day_updated"] .":download/".$id_download, "title" => $download["auteur"]." - ".$download["titre"], "updated" => $download["year_updated"]."-".$download["month_updated"]."-".$download["day_updated"]."T00:00:00Z", "author_name" => $download["auteur"], "enclosure" => str_replace("&", "&", $download["url"]), "content_type" => $download["content_type"], "link" => array("alternate" => str_replace("&", "&", $download["url"])) ); } return $atom; } function get_content_atom($id, $author, $title, $self, $alternate, $contents) { $atom = array ( "id" => "tag:".$_SERVER["HTTP_HOST"].",".date("Y-m-d").":".$id, "author_name" => $author, "title" => $title, "updated" => date("Y-m-d")."T".date("H:i:s")."Z", "link" => array("self" => str_replace("&", "&", $self), "alternate" => str_replace("&", "&", $alternate)), "entries" => array() ); foreach($contents as $id_content => $content) { $atom["entries"][$id_content] = array ( "id" => "tag:".$_SERVER["HTTP_HOST"]."," .$download["year_updated"]."-".$download["month_updated"]."-".$download["day_updated"] .":content/".$id_content, "title" => $content["titre"], "updated" => $content["date_modification"]."T00:00:00Z", "author_name" => $content["auteur"], "summary" => str_replace("&", "&", $content["contenu"]), "link" => array("alternate" => str_replace("&", "&", $content["url"])) ); } return $atom; } ?>