core.class.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. class core
  3. {
  4. public static function ifGet(string $_string)
  5. {
  6. if (isset($_GET[$_string])) {
  7. return TRUE;
  8. } else {
  9. return FALSE;
  10. }
  11. }
  12. public static function ifPost(string $_string)
  13. {
  14. if (isset($_POST[$_string])) {
  15. return TRUE;
  16. } else {
  17. return FALSE;
  18. }
  19. }
  20. public static function getGet(string $_string = NULL)
  21. {
  22. if ($_string == NULL) {
  23. return $_GET;
  24. } else {
  25. if (isset($_GET[$_string])) {
  26. return $_GET[$_string];
  27. } else {
  28. return NULL;
  29. }
  30. }
  31. }
  32. public static function getPost(string $_string = NULL)
  33. {
  34. if ($_string == NULL) {
  35. return $_POST;
  36. } else {
  37. if (isset($_POST[$_string])) {
  38. return $_POST[$_string];
  39. } else {
  40. return NULL;
  41. }
  42. }
  43. }
  44. public static function convertDate(string $datetime)
  45. {
  46. $pieces = explode(" ", $datetime);
  47. $pieces3 = explode(":", $pieces[1]);
  48. $pieces2 = explode("-", $pieces[0]);
  49. return $pieces2[2] . "/" . $pieces2[1] . "/" . $pieces2[0] . " à " . $pieces3[0] . ":" . $pieces3[1];
  50. }
  51. public static function dateFr(string $_timestampMysql = NULL)
  52. {
  53. if ($_timestampMysql == NULL) {
  54. $Now = new DateTime('now', new DateTimeZone(TIME_ZONE));
  55. return $Now->format("d/m/Y H:i:s");
  56. } else {
  57. return DateTime::createFromFormat("d/m/Y H:i:s", $_timestampMysql);
  58. }
  59. }
  60. public static function dateFromTimestamp(int $_timestamp = NULL)
  61. {
  62. if ($_timestamp == NULL) {
  63. return NULL;
  64. } else {
  65. return date("Y-m-d H:i:s", $_timestamp);
  66. }
  67. }
  68. public static function formatFileSize(float $_size, int $_decimalplaces = 0)
  69. {
  70. $sizes = array('O', 'Ko', 'Mo', 'Go', 'To');
  71. for ($i = 0; $_size > 1024 && $i < count($sizes) - 1; $i++) {
  72. $_size /= 1024;
  73. }
  74. return round($_size, $_decimalplaces) . ' ' . $sizes[$i];
  75. }
  76. public static function checkStringOnly(string $_string)
  77. {
  78. if (!ctype_alpha($_string)) {
  79. return TRUE;
  80. } else {
  81. return FALSE;
  82. }
  83. }
  84. public static function print_r(array $_array, int $_exit = NULL)
  85. {
  86. echo "<pre>";
  87. print_r($_array);
  88. echo "</pre>";
  89. ($_exit != NULL) ? exit() : NULL;
  90. }
  91. public static function elementMenu(string $_id, string $_href, string $_titre, string $_feather, string $_style = NULL)
  92. {
  93. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  94. echo '<li class="nav-item">
  95. <a class="nav-link' . get::currentPage($_id) . '" aria-current="page" href="' . $_href . '"' . $_style . '>
  96. <span data-feather="' . $_feather . '"' . $_style . '></span>
  97. ' . $_titre . '
  98. </a>
  99. </li>';
  100. }
  101. public static function elementMenuLink(string $_href, string $_titre, string $_feather, string $_style = NULL, string $_target = "_blank")
  102. {
  103. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  104. echo '<li class="nav-item">
  105. <a class="nav-link" target="'. $_target .'" href="' . $_href . '"' . $_style . '>
  106. <span data-feather="' . $_feather . '"' . $_style . '></span>
  107. ' . $_titre . '
  108. </a>
  109. </li>';
  110. }
  111. public static function elementMenuH6(string $_titre, string $_style = NULL)
  112. {
  113. ($_style != NULL) ? $_style = ' style="' . $_style . '"' : NULL;
  114. echo '<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
  115. <span' . $_style . '>' . $_titre . '</span>
  116. </h6>';
  117. }
  118. public static function filAriane(array $_arbo)
  119. {
  120. $return = '<nav aria-label="breadcrumb bg-300">';
  121. $return .= '<ol class="breadcrumb" style="padding:5px 10px; border-bottom: 1px solid #e9ecef;">';
  122. foreach ($_arbo["arbo"] as $label => $lien) {
  123. if ($_arbo["current"] == $label) {
  124. $return .= '<li class="breadcrumb-item active" aria-current="page">' . $label . '</li>';
  125. } elseif ($lien == NULL) {
  126. $return .= '<li class="breadcrumb-item">' . $label . '</li>';
  127. } else {
  128. $return .= '<li class="breadcrumb-item"><a href="' . $lien . '" title="' . $label . '">' . $label . '</a></li>';
  129. }
  130. }
  131. $return .= '</ol>';
  132. $return .= '</nav>';
  133. return $return;
  134. }
  135. public static function encodeUTF8(string $_data)
  136. {
  137. return (mb_detect_encoding($_data) != "UTF-8") ? mb_convert_encoding($_data, 'UTF-8', mb_list_encodings()) : $_data;
  138. }
  139. public static function testConnexionInternet()
  140. {
  141. $hosts = ['1.1.1.1', '1.0.0.1', '8.8.8.8', '8.8.4.4'];
  142. foreach ($hosts as $host) {
  143. if ($connected = @fsockopen($host, 443)) {
  144. fclose($connected);
  145. return TRUE;
  146. }
  147. }
  148. return FALSE;
  149. }
  150. public static function printDateTxt()
  151. {
  152. $date = new IntlDateFormatter('fr_FR', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
  153. return $date->format(time()) . " à " . date("H:m:s");
  154. }
  155. public static function addFileMaintenance(){
  156. $myfile = fopen(DOCUMENT_ROOT . FILE_MAINTENANCE, "w");
  157. fclose($myfile);
  158. }
  159. public static function removeFileMaintenance(){
  160. unlink(DOCUMENT_ROOT . FILE_MAINTENANCE);
  161. }
  162. public static function isMaintenance(){
  163. return (file_exists(DOCUMENT_ROOT . FILE_MAINTENANCE)) ? TRUE : FALSE;
  164. }
  165. public static function addFileDebug(){
  166. $myfile = fopen(DOCUMENT_ROOT . FILE_DEBUG, "w");
  167. fclose($myfile);
  168. }
  169. public static function removeFileDebug(){
  170. unlink(DOCUMENT_ROOT . FILE_DEBUG);
  171. }
  172. public static function isDebug(){
  173. return (file_exists(DOCUMENT_ROOT . FILE_DEBUG)) ? TRUE : FALSE;
  174. }
  175. public static function checkboxSelecter(bool $_val){
  176. echo ($_val == TRUE) ? "checked" : "";
  177. }
  178. }