setting.customize.customiser.php 4.5 KB

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