public function addPalette() { if ($this->formSubmitted('addPalette')) { if (!is_dir(SH_TEMP_FOLDER . __CLASS__)) { mkdir(SH_TEMP_FOLDER . __CLASS__); } $file = $this->linker->form_elements->getFile('palette', SH_TEMP_FOLDER . __CLASS__); if ($file['response'] != sh_form_elements::SUCCESS) { $this->linker->html->addMessage($this->getI18n('errorSendingFile')); $error = true; } else { if (substr(strtolower($file['fileName']), -4) != '.png') { $this->linker->html->addMessage($this->getI18n('wrongFileType')); $error = true; } } if (empty($_POST['name']) || strtolower($_POST['name']) == 'default') { $this->linker->html->addMessage($this->getI18n('thereShouldBeAFilename')); $error = true; } if (!$error) { // We have a palette, so we have to explode it $colors = sh_colors::explodePalette($file['completeFileName']); $file = dirname($file['completeFileName']) . '/' . $_POST['name'] . '.php'; $this->helper->writeArrayInFile($file, 'palette', $colors); $this->linker->html->addMessage($this->getI18n('paletteSuccessfullySent') . $file); $this->linker->html->addMessage($this->getI18n('paletteSuccessfullySentHowTo')); } $file['completeFileName']; } $this->render('addPalette', $values); }
public function unpack_palettes() { $this->onlyMaster(); if ($this->formSubmitted('addPalettes')) { set_time_limit(360); // We should download the button pack in the temp folder if (!is_dir(SH_TEMP_FOLDER . __CLASS__)) { mkdir(SH_TEMP_FOLDER . __CLASS__); } $file = $this->linker->form_elements->getFile('zipFile', SH_TEMP_FOLDER . __CLASS__); // We verify if the file is a zip if (substr($file['fileName'], -4) == '.zip') { // we extract it in the same folder $folder = dirname($file['completeFileName']) . '/' . substr($file['fileName'], 0, -4) . '/'; if (is_dir($folder)) { $this->helper->deleteDir($folder); } $zipObject = $this->linker->zipper->extract($file['completeFileName'], $folder, array('png')); $palettes = glob($folder . '*\\.png'); foreach ($palettes as $palette) { sh_colors::explodePalette($palette, dirname(dirname($palette)) . '/' . str_replace('.png', '.php', basename($palette))); $this->linker->html->addMessage('Le fichier de palette ' . dirname(dirname($palette)) . '/' . str_replace('.png', '.php', basename($palette)) . ' a été généré'); } } } $this->render(__FUNCTION__, array()); }