setting.update.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. global $myUser;
  3. if($myUser->login=='') throw new Exception("Permissions insuffisantes", 403);
  4. ?>
  5. <div class="row">
  6. <div class="col-md-12">
  7. <?php
  8. if(!file_exists(__DIR__.SLASH.'.git')) throw new Exception("Fonctionnalité désactivée car le projet n'est pas versionné via GIT");
  9. //À voir pour le rendre dynamique au
  10. //lieu d'avoir les 30 dernières modifs
  11. $stream = shell_exec('git log -30 --pretty=~~~%ct---%B~~~');
  12. $commits = explode('~~~',$stream);
  13. ?>
  14. <br>
  15. <h3>30 Dernières modifications :</h3>
  16. <hr>
  17. <div class="row">
  18. <div class="col-md-12">
  19. <ul class="update-timeline">
  20. <?php
  21. $i=0;
  22. foreach($commits as $commit):
  23. $infos = explode('---',$commit);
  24. if(count($infos)<2) continue;
  25. $i++;
  26. list($time,$message) = $infos;
  27. $icons = array();
  28. $colors = array();
  29. $tags = array();
  30. if(preg_match('/Merge branch/i', $message)){
  31. $icons[]= 'fas fa-code-branch';
  32. $colors[]= 'info';
  33. $message = str_replace(array('Merge branch',' of ','Conflicts'),array('Fusion de branche',' de ','Conflits'),$message);
  34. $tags['merge'] = 1;
  35. }
  36. // Refactor de la regex pour accepter les syntaxes -Plugin: ou Plugin:
  37. $message = preg_replace('/(^-*|\n|\n-*)[\s\t]*([^:-]*)[\s\t]*:/iU', '<span class="update-commit-module mt-2"><i class="far fa-bookmark"></i> $2</span>', $message);
  38. $message = preg_replace_callback('/#([^\s]*)(\s|$)/iU', function($matches) use(&$tags){
  39. $tag = trim(strtolower($matches[1]));
  40. if($tag=='') return;
  41. if(!isset($tags[$tag])) $tags[$tag] = 0;
  42. $tags[$tag]++;
  43. return $matches[2];
  44. }, $message);
  45. if(isset($tags['feature'])){
  46. $icons[] = 'fas fa-plus-circle';
  47. $colors[] = 'success';
  48. }
  49. if(isset($tags['bug'])){
  50. $icons[] = 'fas fa-bug';
  51. $colors[] = 'danger';
  52. }
  53. if(isset($tags['refactor']) || preg_match('/refactor|rework/i', $message)){
  54. $icons[] = 'fas fa-sync';
  55. $colors[] = 'warning';
  56. }
  57. if(count($icons)==0) $icons[] ='fas fa-pencil-alt';
  58. ?>
  59. <li <?php echo $i%2==0?'class="update-timeline-inverted"':'' ?>>
  60. <div class="update-timeline-badge <?php echo count($colors)==1?$colors[0]:''; ?>" style="font-size: <?php echo 1.4/count($icons); ?>rem;<?php echo count($colors)>1?'background-color:#e83e8c;':''; ?>">
  61. <?php foreach($icons as $icon): ?>
  62. <i class="<?php echo $icon; ?>" style="font-size: <?php echo 1.4/count($icons); ?>rem"></i>
  63. <?php endforeach; ?>
  64. </div>
  65. <div class="update-timeline-panel">
  66. <div class="update-timeline-heading">
  67. <p><small class="text-muted"><i class="far fa-clock"></i> <?php echo relative_time($time); ?></small></p>
  68. </div>
  69. <div class="update-timeline-body">
  70. <p><?php echo nl2br($message); ?></p>
  71. <?php foreach($tags as $tag=>$count): ?>
  72. <span class="update-commit-tag"><i class="fas fa-tag"></i> <?php echo $tag ?><?php echo $count > 1 ? ' ('.$count.')':'' ?></span>
  73. <?php endforeach; ?>
  74. </div>
  75. </div>
  76. </li>
  77. <?php endforeach; ?>
  78. </ul>
  79. </div>
  80. </div>
  81. <br>
  82. </div>
  83. </div>