setting.global.customiser.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. global $myUser,$conf;
  3. if(!$myUser->can('customiser','configure')) throw new Exception("Vous n'avez pas la permission pour executer cette fonctionnalité",403);
  4. $themePath = __DIR__.SLASH.'css'.SLASH.'theme.css';
  5. if(!file_exists($themePath))
  6. copy(__DIR__.SLASH.'css'.SLASH.'theme.sample.css',__DIR__.SLASH.'css'.SLASH.'theme.css');
  7. $themeStream = file_get_contents($themePath);
  8. $types = array(
  9. 'background-color' => array('label'=>'Couleur de fond','type'=>'color'),
  10. 'border-color' => array('label'=>'Couleur de bordure','type'=>'color'),
  11. 'background-image'=>array('label'=>'Image de fond','type'=>'image'),
  12. 'color'=>array('label'=>'Couleur de texte','type'=>'color'),
  13. 'font-size'=>array('label'=>'Taille de texte','type'=>'size'),
  14. 'font-family'=>array('label'=>'Police','type'=>'font'),
  15. );
  16. preg_match_all('$/\*::([^\*]*)\*/
  17. [\n\r\s\t]*([#.]?[^\{]*){([^\}]*)
  18. }$iUs', $themeStream , $matches,PREG_SET_ORDER);
  19. $css = array();
  20. foreach ($matches as $match) {
  21. preg_match_all('$(.*):(.*);$iU', $match[3] , $contentMatches,PREG_SET_ORDER);
  22. $properties = array();
  23. foreach($contentMatches as $contentMatch){
  24. $property = array(
  25. 'instruction' => trim($contentMatch[1]),
  26. 'value' => trim($contentMatch[2]),
  27. 'id' => base64_encode($match[2].'-'.trim($contentMatch[1])),
  28. );
  29. if(!isset($types[$property['instruction']])) continue;
  30. $property['type'] = $types[$property['instruction']]['type'];
  31. $property['description'] = $types[$property['instruction']]['label'];
  32. $properties[] = $property;
  33. }
  34. if(count($properties)==0) continue;
  35. if(!isset($css[trim($match[1])])) $css[trim($match[1])] = array();
  36. $css[trim($match[1])][] = array(
  37. 'comment' => trim($match[1]),
  38. 'signature' => trim($match[2]),
  39. 'content' => $properties
  40. );
  41. }
  42. ?>
  43. <div class="row">
  44. <div class="col-md-12">
  45. <br>
  46. <?php if($myUser->can('customiser', 'edit')) : ?>
  47. <div onclick="customiser_setting_save();" class="btn btn-success float-right"><i class="fas fa-check"></i> Enregistrer</div>
  48. <div onclick="if(confirm('Cette action est irreverssible, êtes vous sûre de vouloir réinitialiser le thème?'))window.location='action.php?action=customiser_reset_theme';" class="btn btn-danger float-right mr-2"><i class="fas fa-undo-alt"></i> Réinitialiser</div>
  49. <?php endif; ?>
  50. <h3>Réglages Thème</h3>
  51. <div class="clear"></div>
  52. <hr>
  53. </div>
  54. </div>
  55. <div class="row">
  56. <!-- search results -->
  57. <div class="col-xl-12">
  58. <table id="customiser-setting-form" class="table table-striped">
  59. <tbody>
  60. <?php foreach($css as $comment=>$blocks): ?>
  61. <tr>
  62. <th colspan="2"><h5><i class="fas fa-angle-right"></i> <?php echo $comment;?></h5></th>
  63. </tr>
  64. <?php foreach($blocks as $block): ?>
  65. <?php foreach($block['content'] as $property): ?>
  66. <tr>
  67. <th class="align-middle"><?php echo $property['description']; ?></th>
  68. <td class="align-middle"><?php
  69. $attributes = array();
  70. if(isset($infos['placeholder'])) $attributes[] = 'placeholder="'.$infos['placeholder'].'"';
  71. $attributes['class'] = 'class="form-control"';
  72. $attributes[] = 'id="'.$property['id'].'"';
  73. $attributes[] = 'data-signature="'.$block['signature'].'"';
  74. $attributes[] = 'data-instruction="'.$property['instruction'].'"';
  75. $attributes[] = 'data-field-type="'.$property['type'].'"';
  76. $attributes['value'] = 'value="'.$property['value'].'"';
  77. $attributes['change'] = 'onchange="customiser_preview(this);"';
  78. switch($property['type']){
  79. case 'color':
  80. if(strlen($property['value']) == 4){
  81. $property['value'] = '#'.str_repeat(substr($property['value'],1), 2);
  82. $attributes['value'] = 'value="'.$property['value'].'"';
  83. }
  84. $input = '<input type="color" '.implode(' ',$attributes).' >';
  85. break;
  86. case 'image':
  87. $property['value'] = str_replace(array("url","'",'"',"(",")"),'',$property['value']);
  88. $property['value'] = str_replace(array("../"),'',$property['value']);
  89. $attributes['value'] = 'value="'.$property['value'].'"';
  90. //$attributes['data-type'] = 'data-type="image"';
  91. $input = '<input type="file" '.implode(' ',$attributes).' >';
  92. break;
  93. case 'font':
  94. $property['value'] = str_replace(array("'",'"'),'',$property['value']);
  95. $attributes['value'] = 'value="'.$property['value'].'"';
  96. $input = '<input type="text" '.implode(' ',$attributes).' >';
  97. break;
  98. default:
  99. $input = '<input type="text" '.implode(' ',$attributes).' >';
  100. break;
  101. }
  102. echo $input; ?>
  103. </td>
  104. <?php endforeach; ?>
  105. <?php endforeach; ?>
  106. </tr>
  107. <?php endforeach; ?>
  108. </tbody>
  109. </table>
  110. </div>
  111. </div>