--- /dev/null
+<?php
+
+class extranetTools {
+
+ public static function hub($args) {
+ global $core;
+ $args = cubePage::getArgs($args);
+
+ $function = array_shift($args);
+
+ if (!isset($_GET['light'])) {
+ echo commonPage::header($args);
+ }
+
+ $cb = array('extranetTools', $function);
+ if (is_callable($cb)) {
+ echo call_user_func($cb, $args);
+ }
+
+ if (!isset($_GET['light'])) {
+ echo commonPage::footer();
+ }
+ }
+
+ public static function favicon($args) {
+ global $core;
+ $res = commonPage::barre();
+ $res .= commonPage::tMain();
+ $res .= commonPage::bh();
+ $res.='<form action="' . SITE_PATH . 'tools/makeFavicon" method="post" class="notajax" enctype="multipart/form-data">';
+ $res.='<table class="liste">';
+ $res.='<tr><th><strong>' . __('Générer un favicon') . '</strong></th></tr>';
+ $res.='<tr><td>' . __('Veuillez charger une image carrée (dimensions optimales : 256x256 px)') . '</td></tr>';
+ $res.='<tr class="odd"><td><input type="file" name="file" /></td></tr>';
+ $res.='<tr><td class="right"><a href="#" class="submit">' . $core->typo->BoutonOK(__('Générer le favicon')) . '</a></td></td>';
+ $res.='</table>';
+ $res.='</form>';
+ $res .= '</div>';
+ $res .= commonPage::bf();
+ $res .= commonPage::bMain();
+ return $res;
+ }
+
+ public static function makeFavicon() {
+
+ $tmp = cubeFiles::tempdir();
+ mkdir($tmp, 0777, true);
+
+
+
+ $upload=$_FILES['file']['tmp_name'];
+
+ $icotool = new cubeCommandLine('icotool');
+ $icotool->setArg('c');
+ $icotool->setArg('o', $tmp . '/favicon.ico');
+
+ $sizes = array(256, 128, 114, 72, 64, 57, 32, 16);
+ $apple = array(114, 72, 57);
+
+
+ foreach ($sizes as $s) {
+ if (in_array($s, $apple)) {
+ $r = $tmp . '/favicon-ios-' . $s . '.png';
+ } else {
+ $r = $tmp . '/ico-' . $s . '.png';
+ }
+ $it = new cubeImageTools();
+ $it->loadImage($upload);
+ $it->resize($s, $s, 'crop', true, 'C', 'M', 'transparent');
+ $it->output('png', $r);
+ if (in_array($s, $apple)) {
+ continue;
+ }
+ $icotool->setArg(null, $r);
+ }
+
+ $icotool->execute();
+
+ rename($tmp . '/ico-16.png', $tmp.'/favicon.png');
+
+ foreach ($sizes as $s) {
+ if ($s == 16 || in_array($s, $apple)) {
+ continue;
+ }
+ unlink($tmp . '/ico-' . $s . '.png');
+ }
+
+ $tmpfile = cubeFiles::tempnam().'.zip';
+
+ $zip = new cubeCommandLine('zip');
+ $zip->cd($tmp);
+ $zip->setArg(null, $tmpfile);
+ $zip->setArg('0');
+ $zip->setArg('u');
+ $zip->setArg('r');
+ $zip->setArg('X');
+ $zip->setArg(null, '.');
+ $zip->execute();
+
+ fb($zip->commande);
+ fb($zip->output);
+
+ cubeHTTP::downloadFile($tmpfile, 'favicon.zip');
+ }
+
+}
+
+?>