Add atom feed, update main script and fix some issues
This commit is contained in:
parent
cf8262d3cb
commit
30cd0ba548
5 changed files with 326 additions and 109 deletions
119
htdocs/atom.php
Normal file
119
htdocs/atom.php
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$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.");
|
||||
|
||||
header("Content-type: application/atom+xml;charset=utf-8");
|
||||
|
||||
$xml = new DOMDocument('1.0', 'UTF-8');
|
||||
$xml->formatOutput = true;
|
||||
|
||||
$xml_feed = $xml->createElement("feed");
|
||||
$xml_feed->setAttribute("xmlns", "http://www.w3.org/2005/Atom");
|
||||
|
||||
$xml_feed_link = $xml->createElement("link");
|
||||
$xml_feed_link->setAttribute("rel", "self");
|
||||
$xml_feed_link->setAttribute("href", "http://".$_SERVER["SERVER_NAME"].dirname($_SERVER["REQUEST_URI"])."atom.php?".$user);
|
||||
|
||||
$xml_feed_rights = $xml->createElement("rights", "Pommultimédia Online Converter");
|
||||
$xml_feed_rights->setAttribute("type", "text");
|
||||
|
||||
$xml_feed_author = $xml->createElement("author");
|
||||
$xml_feed_author->appendChild($xml->createElement("name", "nemunaire"));
|
||||
|
||||
$xml_feed->appendChild($xml->createElement("title", "Musiques téléchargées de ".$user));
|
||||
$xml_feed->appendChild($xml->createElement("updated", date('c')));
|
||||
$xml_feed->appendChild($xml->createElement("id", "http://musik.p0m.fr/atom.php?".$user));
|
||||
$xml_feed->appendChild($xml_feed_link);
|
||||
$xml_feed->appendChild($xml->createElement("generator", "Onyx Atom generator"));
|
||||
$xml_feed->appendChild($xml_feed_rights);
|
||||
$xml_feed->appendChild($xml_feed_author);
|
||||
|
||||
$files = array();
|
||||
if (is_file(MAIN_DIR."/users/".$user.".dlist.done"))
|
||||
{
|
||||
$ec = file(MAIN_DIR."/users/".$user.".dlist.done",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
$cnt = 0;
|
||||
for ($i = count ($ec) - 1; $i >= 0 && $cnt < 10; $i--, $cnt++)
|
||||
{
|
||||
$musik = get_info($ec[$i]);
|
||||
if (isset($musik) && (is_file (MAIN_DIR."/content/".$musik[4]) || is_file (MAIN_DIR."/content/".$musik[5])))
|
||||
{
|
||||
$xml_entry = $xml->createElement("entry");
|
||||
$xml_entry->appendChild($xml->createElement("id", "http://musik.p0m.fr/".$musik[0]));
|
||||
@$xml_entry->appendChild($xml->createElement("title", strip_tags($musik[1])));
|
||||
if (is_file (MAIN_DIR."/content/".$musik[5]))
|
||||
$xml_entry->appendChild($xml->createElement("updated", date('c', filectime(MAIN_DIR."/content/".$musik[5]))));
|
||||
else
|
||||
$xml_entry->appendChild($xml->createElement("updated", date('c', filectime(MAIN_DIR."/content/".$musik[4]))));
|
||||
|
||||
$xml_entry_summary = $xml->createElement("summary", htmlentities(utf8_decode($musik[2])));
|
||||
$xml_entry_summary->setAttribute("type", "html");
|
||||
|
||||
$xml_entry_enclosure = $xml_entry->appendChild($xml->createElement("link"));
|
||||
$xml_entry_enclosure->setAttribute("href", "http://".$_SERVER["SERVER_NAME"].dirname($_SERVER["REQUEST_URI"]).urlencode("dl.php?".$user."&f=".$i));
|
||||
$xml_entry_enclosure->setAttribute("rel", "enclosure");
|
||||
$xml_entry->appendChild($xml_entry_enclosure);
|
||||
|
||||
$xml_entry_enclosure = $xml_entry->appendChild($xml->createElement("link"));
|
||||
$xml_entry_enclosure->setAttribute("href", $musik[0]);
|
||||
$xml_entry_enclosure->setAttribute("rel", "via");
|
||||
$xml_entry->appendChild($xml_entry_enclosure);
|
||||
|
||||
$xml_entry_link = $xml->createElement("link");
|
||||
$xml_entry_link->setAttribute("rel", "alternate");
|
||||
$xml_entry_link->setAttribute("href", "http://".$_SERVER["SERVER_NAME"].dirname($_SERVER["REQUEST_URI"])."?".$user);
|
||||
|
||||
$xml_entry->appendChild($xml_entry_summary);
|
||||
$xml_entry->appendChild($xml_entry_link);
|
||||
$xml_feed->appendChild($xml_entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$xml->appendChild($xml_feed);
|
||||
|
||||
//Cache::set('flux', array("date" => time(), "flux" => $xml->saveXML()));
|
||||
|
||||
print $xml->saveXML();
|
||||
?>
|
||||
|
|
@ -17,10 +17,14 @@ function get_info($url)
|
|||
}
|
||||
}
|
||||
|
||||
if ($i < $nbLign)
|
||||
if ($i+2 < $nbLign)
|
||||
{
|
||||
$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+3]);
|
||||
return array($ec[$i], $ec[$i+1], $ec[$i+2], $ec[$i+3], trim($filename));
|
||||
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;
|
||||
|
|
@ -50,13 +54,19 @@ if (isset($_GET["f"]))
|
|||
if ($k == $_GET["f"])
|
||||
{
|
||||
$musik = get_info($lign);
|
||||
if (isset($musik) && is_file(MAIN_DIR."/content/".$musik[4]))
|
||||
if (isset($musik) && (is_file(MAIN_DIR."/content/".$musik[4]) || is_file(MAIN_DIR."/content/".$musik[5])))
|
||||
{
|
||||
$filename = MAIN_DIR."/content/".$musik[4];
|
||||
if (is_file(MAIN_DIR."/content/".$musik[5]))
|
||||
$filename = MAIN_DIR."/content/".$musik[5];
|
||||
else
|
||||
$filename = MAIN_DIR."/content/".$musik[4];
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header("Content-Disposition: attachment; filename=\"".$musik[1].".mp3\"");
|
||||
if (is_file(MAIN_DIR."/content/".$musik[5]))
|
||||
header("Content-Disposition: attachment; filename=\"".$musik[1].".ogg\"");
|
||||
else
|
||||
header("Content-Disposition: attachment; filename=\"".$musik[1].".mp3\"");
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
|
|
@ -70,4 +80,4 @@ if (isset($_GET["f"]))
|
|||
}
|
||||
}
|
||||
die ("Fichier introuvable");
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -20,8 +20,12 @@ function get_info($url)
|
|||
|
||||
if ($i+2 < $nbLign)
|
||||
{
|
||||
@$filename = preg_replace("#^(.+)\.([a-zA-Z0-9]{1,4})$#", '\1.mp3', $ec[$i+3]);
|
||||
return @array($ec[$i], $ec[$i+1], $ec[$i+2], $ec[$i+3], trim($filename));
|
||||
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;
|
||||
|
|
@ -64,7 +68,7 @@ if (is_file(MAIN_DIR."/users/".$user.".dlist.done"))
|
|||
foreach ($ec as $k => $lign)
|
||||
{
|
||||
$musik = get_info($lign);
|
||||
if(isset($musik) && is_file($dir.'/'.$musik[4]))
|
||||
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>';
|
||||
|
|
@ -96,7 +100,12 @@ if (empty($someone))
|
|||
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))
|
||||
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"))
|
||||
|
|
|
|||
Reference in a new issue