action.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. Action::register('customiser_theme_save',function(&$response){
  3. global $myUser,$_,$conf;
  4. User::check_access('customiser','configure');
  5. $conf->put('core_theme',$_['theme']);
  6. });
  7. //Theme : Gestion upload Zip theme
  8. Action::register('customiser_theme_zipTheme',function(&$response){
  9. User::check_access('customiser','configure');
  10. File::handle_component(array(
  11. 'namespace' => 'customiser', //stockés dans file/customiser/*.*
  12. 'access' => 'customiser', // crud sur customiser,
  13. 'size' => '1000000000', // taille max
  14. 'extension' => 'zip',
  15. 'storage' => 'theme/upload.zip'
  16. ),$response);
  17. });
  18. Action::register('customiser_theme_install',function(&$response){
  19. global $_,$myUser ;
  20. require_once(__DIR__.SLASH.'Theme.class.php');
  21. User::check_access('customiser','configure');
  22. if(empty($_['file'])) return;
  23. try{
  24. File::save_component('file', 'theme/upload.zip');
  25. $zipFile = File::dir().SLASH.'theme/upload.zip';
  26. $zip = new ZipArchive();
  27. if(!$zip->open($zipFile)) throw new Exception("Impossible d'ouvrir l'import");
  28. $app = $zip->getFromName('app.json');
  29. if(!$app) throw new Exception('Fichier app.json manquant à la racine de l\'archive');
  30. $app = json_decode($app,true);
  31. $folderId = str_replace(array('..','/','\\'),array('.',''),$app['id']);
  32. $templateDir = Theme::dir().$folderId;
  33. if(file_exists($templateDir)) throw new Exception('Le thème '.$folderId.' est déja installé sur cette application');
  34. mkdir($templateDir,0755,true);
  35. unzip($zipFile,$templateDir,array('allowedExtensions'=>array('css','json','jpg','png','bmp','jpeg','webp','woff','woff2','eot','ttf','svg')));
  36. }catch(Exception $e){
  37. if(file_exists($zipFile)) unlink($zipFile);
  38. throw $e;
  39. }
  40. });
  41. ?>