[6] | 1 | <?php |
---|
| 2 | |
---|
| 3 | # ----------------------------------------------------------------------------------- |
---|
| 4 | # fonction generale |
---|
| 5 | # |
---|
| 6 | |
---|
| 7 | function e_backend($env) |
---|
| 8 | { if($_GET[$env->param("action")]) |
---|
| 9 | { $function = "a_".$_GET[$env->param("action")]; |
---|
| 10 | if(function_exists($function)) |
---|
| 11 | { $function($env); |
---|
| 12 | } |
---|
| 13 | } |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | # ----------------------------------------------------------------------------------- |
---|
| 17 | # actions |
---|
| 18 | # |
---|
| 19 | |
---|
| 20 | # ---------------------------------------- |
---|
| 21 | # playlists audio generales |
---|
| 22 | |
---|
| 23 | function a_last_downloads($env) |
---|
| 24 | { if(($downloads = $env->data->pl_last_downloads(10)) !== false) |
---|
| 25 | { if($_GET[$env->param("format")] == "m3u") |
---|
| 26 | { echo get_m3u($downloads); |
---|
| 27 | exit; |
---|
| 28 | } |
---|
| 29 | elseif($_GET[$env->param("format")] == "atom") |
---|
| 30 | { $env->out["atom"] = get_downloads_atom |
---|
| 31 | ( "last_downloads", |
---|
| 32 | $env->config("site_name"), |
---|
| 33 | "les 10 derniers morceaux", |
---|
| 34 | "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "last_downloads", "format" => "atom"), "backend.php"), |
---|
| 35 | "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "playlist", "action" => "last_downloads"), "index.php"), |
---|
| 36 | $downloads |
---|
| 37 | ); |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | else echo "Erreur lors de l'accès aux downloads"; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | function a_rand_downloads($env) |
---|
| 44 | { header('Content-type: application/atom+xml; charset=UTF-8'); |
---|
| 45 | if(($downloads = $env->data->pl_rand_downloads(10)) !== false) |
---|
| 46 | { if($_GET[$env->param("format")] == "m3u") |
---|
| 47 | { echo get_m3u($downloads); |
---|
| 48 | exit; |
---|
| 49 | } |
---|
| 50 | elseif($_GET[$env->param("format")] == "atom") |
---|
| 51 | { $env->out["atom"] = get_downloads_atom |
---|
| 52 | ( "rand_downloads", |
---|
| 53 | $env->config("site_name"), |
---|
| 54 | "10 morceaux au hasard", |
---|
| 55 | "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "rand_downloads", "format" => "atom"), "backend.php"), |
---|
| 56 | "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "playlist", "action" => "rand_downloads"), "index.php"), |
---|
| 57 | $downloads |
---|
| 58 | ); |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | else echo "Erreur lors de l'accès aux downloads"; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | # ---------------------------------------- |
---|
| 65 | # playlists artistes |
---|
| 66 | |
---|
| 67 | function a_artiste_downloads($env) |
---|
| 68 | { if($_GET[$env->param("format")] == "m3u") |
---|
| 69 | { if |
---|
| 70 | ( ( $downloads = $env->data->pl_artiste_downloads |
---|
| 71 | ( $_GET[$env->param("artiste")], |
---|
| 72 | isset($_GET[$env->param("album")]) ? $_GET[$env->param("album")] : null |
---|
| 73 | ) |
---|
| 74 | ) !== false |
---|
| 75 | ) |
---|
| 76 | { echo get_m3u($downloads); |
---|
| 77 | exit; |
---|
| 78 | } |
---|
| 79 | else echo "Erreur lors de l'accès aux downloads"; |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | function a_artiste_mp3($env) |
---|
| 84 | { if($_GET[$env->param("format")] == "playlist_xml") |
---|
| 85 | { if |
---|
| 86 | ( ( $env->out["downloads"] = $env->data->artiste_downloads |
---|
| 87 | ( $_GET[$env->param("artiste")], |
---|
| 88 | true, |
---|
| 89 | $_GET[$env->param("album")] ? $_GET[$env->param("album")] : null |
---|
| 90 | ) |
---|
| 91 | ) !== false |
---|
| 92 | ) |
---|
| 93 | { header("Content-Type: application/xml"); |
---|
| 94 | } |
---|
| 95 | else echo "Erreur lors de l'accès aux downloads"; |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | # ---------------------------------------- |
---|
| 100 | # news generales |
---|
| 101 | |
---|
| 102 | function a_last_news($env) |
---|
| 103 | { if(($news = $env->data->contenus(array("root", "news"), 0, 10, " AND public=1 AND date_publication <= NOW()")) !== false) |
---|
| 104 | { $news = $news["list"]; |
---|
| 105 | foreach($news as $id_news => $_news) $news[$id_news]["url"] = |
---|
| 106 | "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "content", "id" => $id_news), "index.php"); |
---|
| 107 | if($_GET[$env->param("format")] == "atom") |
---|
| 108 | { $env->out["atom"] = get_content_atom |
---|
| 109 | ( "last_news", |
---|
| 110 | $env->config("site_name"), |
---|
| 111 | "les 10 dernieres news", |
---|
| 112 | "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "last_news", "format" => "atom"), "backend.php"), |
---|
| 113 | "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "accueil"), "index.php"), |
---|
| 114 | $news |
---|
| 115 | ); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | else echo "Erreur lors de l'accès aux downloads"; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | # ---------------------------------------- |
---|
| 122 | # news artistes |
---|
| 123 | |
---|
| 124 | function a_last_artiste_news($env) |
---|
| 125 | { if(($news = $env->data->contenus(array("root", "artistes", "news", $_GET[$env->param("artiste")]), 0, 10, " AND public=1 AND date_publication <= NOW()")) !== false) |
---|
| 126 | { $news = $news["list"]; |
---|
| 127 | foreach($news as $id_news => $_news) $news[$id_news]["url"] = |
---|
| 128 | "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "content", "id" => $id_news), "index.php"); |
---|
| 129 | if($_GET[$env->param("format")] == "atom") |
---|
| 130 | { $env->out["atom"] = get_content_atom |
---|
| 131 | ( "last_news", |
---|
| 132 | $env->config("site_name"), |
---|
| 133 | "les 10 dernieres news", |
---|
| 134 | "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "last_news", "format" => "atom"), "backend.php"), |
---|
| 135 | "http://".$_SERVER["HTTP_HOST"].$env->url(array("e" => "accueil"), "index.php"), |
---|
| 136 | $news |
---|
| 137 | ); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | else echo "Erreur lors de l'accès aux downloads"; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | # ----------------------------------------------------------------------------------- |
---|
| 144 | # utils |
---|
| 145 | # |
---|
| 146 | |
---|
| 147 | function get_m3u($downloads, $debug = false) |
---|
| 148 | { $playlist = |
---|
| 149 | "#EXTM3U\n"; |
---|
| 150 | if($downloads) foreach($downloads as $id => $download) |
---|
| 151 | { $playlist .= |
---|
| 152 | "#EXTINF:-1,".$download["titre"]."\n" |
---|
| 153 | .$download["url"]."\n"; |
---|
| 154 | } |
---|
| 155 | if(!$debug) |
---|
| 156 | { header("Content-type: audio/x-mpegurl"); |
---|
| 157 | header('Content-Disposition: inline; filename=playlist.m3u'); |
---|
| 158 | header("Content-Length: ".strlen($playlist)); |
---|
| 159 | } |
---|
| 160 | return $playlist; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | function get_downloads_atom($id, $author, $title, $self, $alternate, $downloads) |
---|
| 164 | { $atom = array |
---|
| 165 | ( "id" => "tag:".$_SERVER["HTTP_HOST"].",".date("Y-m-d").":".$id, |
---|
| 166 | "author_name" => $author, |
---|
| 167 | "title" => $title, |
---|
| 168 | "updated" => date("Y-m-d")."T".date("H:i:s")."Z", |
---|
| 169 | "link" => array("self" => str_replace("&", "&", $self), "alternate" => str_replace("&", "&", $alternate)), |
---|
| 170 | "entries" => array() |
---|
| 171 | ); |
---|
| 172 | foreach($downloads as $id_download => $download) |
---|
| 173 | { $atom["entries"][$id_download] = array |
---|
| 174 | ( "id" => "tag:".$_SERVER["HTTP_HOST"]."," |
---|
| 175 | .$download["year_updated"]."-".$download["month_updated"]."-".$download["day_updated"] |
---|
| 176 | .":download/".$id_download, |
---|
| 177 | "title" => $download["auteur"]." - ".$download["titre"], |
---|
| 178 | "updated" => $download["year_updated"]."-".$download["month_updated"]."-".$download["day_updated"]."T00:00:00Z", |
---|
| 179 | "author_name" => $download["auteur"], |
---|
| 180 | "enclosure" => str_replace("&", "&", $download["url"]), |
---|
| 181 | "content_type" => $download["content_type"], |
---|
| 182 | "link" => array("alternate" => str_replace("&", "&", $download["url"])) |
---|
| 183 | ); |
---|
| 184 | } |
---|
| 185 | return $atom; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | function get_content_atom($id, $author, $title, $self, $alternate, $contents) |
---|
| 189 | { $atom = array |
---|
| 190 | ( "id" => "tag:".$_SERVER["HTTP_HOST"].",".date("Y-m-d").":".$id, |
---|
| 191 | "author_name" => $author, |
---|
| 192 | "title" => $title, |
---|
| 193 | "updated" => date("Y-m-d")."T".date("H:i:s")."Z", |
---|
| 194 | "link" => array("self" => str_replace("&", "&", $self), "alternate" => str_replace("&", "&", $alternate)), |
---|
| 195 | "entries" => array() |
---|
| 196 | ); |
---|
| 197 | foreach($contents as $id_content => $content) |
---|
| 198 | { $atom["entries"][$id_content] = array |
---|
| 199 | ( "id" => "tag:".$_SERVER["HTTP_HOST"]."," |
---|
| 200 | .$download["year_updated"]."-".$download["month_updated"]."-".$download["day_updated"] |
---|
| 201 | .":content/".$id_content, |
---|
| 202 | "title" => $content["titre"], |
---|
| 203 | "updated" => $content["date_modification"]."T00:00:00Z", |
---|
| 204 | "author_name" => $content["auteur"], |
---|
| 205 | "summary" => str_replace("&", "&", $content["contenu"]), |
---|
| 206 | "link" => array("alternate" => str_replace("&", "&", $content["url"])) |
---|
| 207 | ); |
---|
| 208 | } |
---|
| 209 | return $atom; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | ?> |
---|