action.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. global $_,$conf;
  3. switch($_['action']){
  4. //Reset des paramètres du thème
  5. case 'customiser_reset_theme':
  6. global $myUser,$_,$conf;
  7. if(!$myUser->can('customiser','configure')) throw new Exception("Permissions insuffisantes",403);
  8. if(file_exists(__DIR__.SLASH.'css'.SLASH.'theme.css'))
  9. unlink(__DIR__.SLASH.'css'.SLASH.'theme.css');
  10. header('location: setting.php?section=global.customiser');
  11. break;
  12. //Sauvegarde des configurations de customiser
  13. case 'customiser_setting_save':
  14. Action::write(function(&$response){
  15. global $myUser,$_,$conf;
  16. if(!$myUser->can('customiser','configure')) throw new Exception("Permissions insuffisantes",403);
  17. $themePath = __DIR__.SLASH.'css'.SLASH.'theme.css';
  18. if(!file_exists($themePath)) exit('Feuille de thème manquante');
  19. $themeStream = file_get_contents($themePath);
  20. foreach ($_['fields'] as $i=>$field) {
  21. if($field['type']=='image'){
  22. if(!isset($_FILES['fields']) || !isset($_FILES['fields']['name'][$i])) continue;
  23. $filename = time().$_FILES['fields']['name'][$i]['value'];
  24. copy($_FILES['fields']['tmp_name'][$i]['value'],__DIR__.SLASH.'img'.SLASH.$filename);
  25. $value = "url('../img/$filename')";
  26. }
  27. if(isset($field['value']) && !empty($field['value']))
  28. $value = $field['value'];
  29. $themeStream = preg_replace('$(\n'.preg_quote($field['signature']).'[\s\t\r\n]*?\s?\{.*'.$field['instruction'].': )([^;]*)(;.*})$isU','${1}'.$value.'$3', $themeStream );
  30. }
  31. file_put_contents(__DIR__.SLASH.'css'.SLASH.'theme.css',$themeStream);
  32. });
  33. break;
  34. }
  35. ?>