summaryrefslogtreecommitdiff
path: root/p/f.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-27 14:52:56 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-12-27 14:52:56 +0100
commitf52ccf7038199f1eb2f82d7e1f26d2a10caa867b (patch)
tree7c8235198b6b587574b41175a167103d31740a9a /p/f.php
parent7b4451912e2a9008a49854a2496cf9bb99b7ed10 (diff)
parentb99979cef78f7cd0c1cb4ae81115d09881e85926 (diff)
Merge remote-tracking branch 'origin/dev' into beta
Diffstat (limited to 'p/f.php')
-rw-r--r--p/f.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/p/f.php b/p/f.php
new file mode 100644
index 000000000..660128a59
--- /dev/null
+++ b/p/f.php
@@ -0,0 +1,77 @@
+<?php
+require('../constants.php');
+$favicons_dir = DATA_PATH . '/favicons/';
+
+/* Télécharge le favicon d'un site et le place sur le serveur */
+function download_favicon ($website, $dest) {
+ $ok = false;
+ $url = 'http://g.etfv.co/' . $website;
+
+ /*if (!is_dir ($favicons_dir)) {
+ if (!mkdir ($favicons_dir, 0755, true)) {
+ header('Location: ' . $url);
+ return false;
+ }
+ }*/
+
+ $c = curl_init ($url);
+ curl_setopt ($c, CURLOPT_HEADER, false);
+ curl_setopt ($c, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt ($c, CURLOPT_BINARYTRANSFER, true);
+ $imgRaw = curl_exec ($c);
+
+ if (curl_getinfo ($c, CURLINFO_HTTP_CODE) == 200) {
+ $file = fopen ($dest, 'w');
+ if ($file !== false) {
+ fwrite ($file, $imgRaw);
+ fclose ($file);
+ $ok = true;
+ }
+ }
+ curl_close ($c);
+ if (!$ok) {
+ header('Location: ' . $url);
+ return false;
+ }
+ return true;
+}
+
+if (isset($_SERVER['PATH_INFO'])) {
+ $id = substr($_SERVER['PATH_INFO'], 1);
+} elseif (isset($_SERVER['QUERY_STRING'])) {
+ $id = $_SERVER['QUERY_STRING'];
+} else {
+ $id = '0';
+}
+
+if (!ctype_xdigit($id)) {
+ $id = '0';
+}
+
+$txt = $favicons_dir . $id . '.txt';
+$ico = $favicons_dir . $id . '.ico';
+
+$icoMTime = @filemtime($ico);
+$txtMTime = @filemtime($txt);
+
+if (($icoMTime == false) || ($txtMTime > $icoMTime)) {
+ if ($txtMTime == false) {
+ header('HTTP/1.1 404 Not Found');
+ header('Content-Type: image/gif');
+ readfile(PUBLIC_PATH . '/themes/icons/grey.gif'); //TODO: Better 404 favicon
+ die();
+ }
+ $url = file_get_contents($txt);
+ if (!download_favicon($url, $ico)) {
+ die();
+ }
+}
+
+require(LIB_PATH . '/http-conditional.php');
+
+header('Content-Type: image/x-icon');
+header('Content-Disposition: inline; filename="' . $id . '.ico"');
+
+if (!httpConditional($icoMTime, 2592000, 2)) {
+ readfile($ico);
+}