Check size before download
Add common.php with common functions
This commit is contained in:
parent
30cd0ba548
commit
f8d59cca32
8 changed files with 455 additions and 308 deletions
173
htdocs/index.php
173
htdocs/index.php
|
|
@ -2,48 +2,9 @@
|
|||
|
||||
define("MAIN_DIR", __dir__."/..");
|
||||
|
||||
function get_info($url)
|
||||
{
|
||||
$ec = file(MAIN_DIR."/database",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
$nbLign = count($ec);
|
||||
|
||||
for ($i = 0; $i < $nbLign; $i++)
|
||||
{
|
||||
if ($ec[$i] == $url)
|
||||
break;
|
||||
else
|
||||
{
|
||||
while ($i < $nbLign && trim($ec[$i]) != "--")
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($i+2 < $nbLign)
|
||||
{
|
||||
if ($ec[$i+3] == "-- ")
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+2]);
|
||||
else
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+3]);
|
||||
@$filenameogg = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.ogg', $filename);
|
||||
return @array($ec[$i], $ec[$i+1], $ec[$i+2], $ec[$i+3], trim($filename), trim($filenameogg));
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
header("Content-type: text/html;charset=utf-8");
|
||||
|
||||
$user = "generic";
|
||||
foreach ($_GET as $k => $t)
|
||||
{
|
||||
if (empty($t))
|
||||
{
|
||||
$user = $k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!preg_match("#^[a-zA-Z0-9_]+$#", $user))
|
||||
die ("Le nom d'utilisateur contient des caractères interdits.");
|
||||
require(MAIN_DIR."/common.php");
|
||||
?>
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
|
@ -57,33 +18,23 @@ if (!preg_match("#^[a-zA-Z0-9_]+$#", $user))
|
|||
<body>
|
||||
<div class="blk">
|
||||
<h2>Chansons prêtes à être téléchargées</h2>
|
||||
<ul><?php
|
||||
$dir = MAIN_DIR."/content/";
|
||||
|
||||
$someone = false;
|
||||
if (is_file(MAIN_DIR."/users/".$user.".dlist.done"))
|
||||
<div class="dled"><?php
|
||||
$list_ready = get_user_ready($user);
|
||||
if (count($list_ready))
|
||||
{
|
||||
$ec = file(MAIN_DIR."/users/".$user.".dlist.done",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
foreach ($ec as $k => $lign)
|
||||
{
|
||||
$musik = get_info($lign);
|
||||
if(isset($musik) && (is_file($dir.'/'.$musik[4]) || is_file($dir.'/'.$musik[5])))
|
||||
{
|
||||
$someone = true;
|
||||
echo '<li><a href="dl.php?'.$user.'&f='.$k.'">'.$musik[1].'</a></li>';
|
||||
}
|
||||
}
|
||||
foreach ($list_ready as $m)
|
||||
format_clip($user, $m);
|
||||
}
|
||||
|
||||
if (empty($someone))
|
||||
echo "<h3>Aucun élément dans cette liste</h3>";
|
||||
?> </ul>
|
||||
else
|
||||
echo "<h3>Pas de nouvelle chanson à télécharger</h3>";
|
||||
?> </div>
|
||||
</div>
|
||||
<div class="blk">
|
||||
<h2>Ajouter une chanson</h2>
|
||||
<?php
|
||||
if ((!empty($_GET["a"]) && $_GET["a"] == "add" && (!empty($_POST["url"]) || !empty($_SERVER["HTTP_REFERER"]))) || !empty($_GET["url"]))
|
||||
if ((!empty($_GET["a"]) && $_GET["a"] == "add"
|
||||
&& (!empty($_POST["url"]) || !empty($_SERVER["HTTP_REFERER"])))
|
||||
|| !empty($_GET["url"]))
|
||||
{
|
||||
if (!empty($_GET["url"]))
|
||||
$url = $_GET["url"];
|
||||
|
|
@ -91,35 +42,7 @@ if (empty($someone))
|
|||
$url = $_POST["url"];
|
||||
else
|
||||
$url = $_SERVER["HTTP_REFERER"];
|
||||
|
||||
if ($url == "clear")
|
||||
{
|
||||
if ($fp = fopen(MAIN_DIR."/users/".$user.".dlist", "a+"))
|
||||
{
|
||||
fputs($fp, "clear\n");
|
||||
print "<h3 style=\"color: #00FF00;\">La demande de vidage de la liste a été ajouté à la file d'attente</h3>";
|
||||
}
|
||||
}
|
||||
elseif (
|
||||
preg_match("#^http://(www.)?youtube.com/watch\?v=([a-zA-Z0-9_-]+)#", $url, $matched)
|
||||
|| preg_match("#^http://youtu.be/([a-zA-Z0-9_-]+)#", $url, $matched)
|
||||
|| preg_match("#^http://(www.)?dailymotion.com/video/([a-zA-Z0-9_-]+)#", $url, $matched)
|
||||
|| preg_match("#^http://(www.)?vimeo.com/([0-9]+)#", $url, $matched)
|
||||
)
|
||||
{
|
||||
//Check if the URL isn't already in the file
|
||||
if (is_file(MAIN_DIR."/users/".$user.".dlist"))
|
||||
$content = file(MAIN_DIR."/users/".$user.".dlist",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
else
|
||||
$content = array();
|
||||
if (!in_array($matched[0], $content) && $fp = fopen(MAIN_DIR."/users/".$user.".dlist", "a+"))
|
||||
{
|
||||
fputs($fp, $matched[0]."\n");
|
||||
print "<h3 style=\"color: #00FF00;\">L'adresse a bien été ajoutée avec succès.</h3>";
|
||||
}
|
||||
}
|
||||
else
|
||||
print "<h3>L'adresse fournie n'est pas valide !</h3>";
|
||||
add_url($user, $url);
|
||||
}
|
||||
?>
|
||||
<form method="post" action="?a=add&<?php echo $user; ?>">
|
||||
|
|
@ -131,55 +54,33 @@ if (empty($someone))
|
|||
<h2>Chansons en file d'attente</h2>
|
||||
<form method="post" action="?a=del">
|
||||
<ul><?php
|
||||
$someone = false;
|
||||
if (is_file(MAIN_DIR."/users/".$user.".dlist.ec"))
|
||||
$ecdl = get_ecdl($user);
|
||||
foreach($ecdl as $lign)
|
||||
{
|
||||
$ec = file(MAIN_DIR."/users/".$user.".dlist.ec",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
if (!empty($ec[0]))
|
||||
{
|
||||
$musik = get_info($ec[0]);
|
||||
if(isset($musik))
|
||||
{
|
||||
echo '<div style="text-align: center;"><img src="'.$musik[2].'" alt="Miniature"></div>';
|
||||
|
||||
if (count ($ec) == 1)
|
||||
echo "<label>En cours de téléchargement :</label>";
|
||||
else if (count ($ec) == 2)
|
||||
echo "<label>En cours de conversion :</label>";
|
||||
|
||||
echo $musik[1];
|
||||
$encours = $ec[0];
|
||||
$someone = true;
|
||||
}
|
||||
}
|
||||
echo '<li>'.$lign.' <input type="submit" name="del'.
|
||||
sha1($lign).'" value="Retirer de la liste"></li>';
|
||||
}
|
||||
if (is_file(MAIN_DIR."/users/".$user.".dlist"))
|
||||
{
|
||||
$ec = file(MAIN_DIR."/users/".$user.".dlist",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
foreach ($ec as $k => $lign)
|
||||
{
|
||||
if (isset($encours) && $lign == $encours)
|
||||
continue;
|
||||
|
||||
$someone = true;
|
||||
$musik = get_info($lign);
|
||||
if(isset($musik) && is_file($dir.'/'.$musik[4]))
|
||||
echo '<li>'.$musik[1].'</li>';
|
||||
else
|
||||
echo '<li>'.$lign.' <input type="submit" name="del'.sha1($lign).'" value="Retirer de la liste"></li>';
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($someone))
|
||||
if (empty($ecdl))
|
||||
echo "<h3>Aucun élément dans cette liste</h3>";
|
||||
?></ul>
|
||||
</form>
|
||||
</div>
|
||||
<div class="blk">
|
||||
<h2>Chansons déjà téléchargées</h2>
|
||||
<h3>Prochainement ...</h3>
|
||||
</div>
|
||||
</body>
|
||||
</div><?php
|
||||
$list_archives = get_user_archives($user);
|
||||
if (count($list_archives))
|
||||
{
|
||||
print '<div class="blk"><h2>Chansons déjà téléchargées</h2><div class="dled">';
|
||||
$last = 0;
|
||||
foreach ($list_archives as $m)
|
||||
{
|
||||
$ths = intval($m["dled"] / 21600);
|
||||
if ($last < $ths)
|
||||
{
|
||||
$last = $ths;
|
||||
echo "<h4>".strftime("%a. %d %b %G - %H:%M", $m["dled"])."</h4>";
|
||||
}
|
||||
format_clip($user, $m);
|
||||
}
|
||||
print '</div></div>';
|
||||
}
|
||||
?></body>
|
||||
</html>
|
||||
|
|
|
|||
Reference in a new issue