PageRenderTime 53ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/content/core.php

https://bitbucket.org/baruffaldi/website-be-you-festival
PHP | 137 lines | 69 code | 17 blank | 51 comment | 15 complexity | 7bc07ad3b4d53d46a078204f1a444129 MD5 | raw file
  1. <?php
  2. /* $Id: core.php,v 0.0.0.3 07/06/2006 02:02:07 mdb Exp $
  3. * $Author: mdb $
  4. *
  5. * www.be-you.org Core Scripts
  6. *
  7. * Copyright Kimera Team (c) 2006
  8. *
  9. * You may not reproduce it elsewhere without the prior written permission of the author.
  10. * However, feel free to study the code and use techniques you learn from it elsewhere.
  11. */
  12. /* Funzioni di "core" */
  13. class BEYOU_CORE
  14. {
  15. /* Page Rendering Timing */
  16. function getmicrotime()
  17. {
  18. list($usec, $sec) = explode(" ",microtime());
  19. return ((float)$usec + (float)$sec);
  20. }
  21. function formattext($text)
  22. {
  23. $return = str_replace("<", "[", str_replace(">", "]", $text));
  24. return $return;
  25. }
  26. function formattextrev($text)
  27. {
  28. $return = str_replace("[", "<", str_replace("]", ">", $text));
  29. return $return;
  30. }
  31. function getPagerData($numHits, $limit, $page)
  32. {
  33. $numHits = (int) $numHits;
  34. $limit = max((int) $limit, 1);
  35. $page = (int) $page;
  36. $numPages = ceil($numHits / $limit);
  37. $page = max($page, 1);
  38. $page = min($page, $numPages);
  39. $offset = ($page - 1) * $limit;
  40. $ret = new stdClass;
  41. $ret->offset = $offset;
  42. $ret->limit = $limit;
  43. $ret->numPages = $numPages;
  44. $ret->page = $page;
  45. return $ret;
  46. }
  47. function paging($result)
  48. {
  49. global $pagina;
  50. if (empty($pagina)) $pagina = "1";
  51. $limit = 7;
  52. $total = mysql_num_rows($result);
  53. $pager = BEYOU_CORE::getPagerData($total, $limit, $pagina);
  54. $offset = $pager->offset;
  55. $limit = $pager->limit;
  56. $pagina = $pager->page;
  57. print "<table>";
  58. if ($pagina == 1)
  59. echo "<tr><td>Precedente</td><td>";
  60. else
  61. echo "<tr><td><a href=\"" . str_replace("&page=$pagina", "", $_SERVER[HTTP_X_REWRITE_URL]) . "&amp;pagina=" . ($pagina - 1) . "\">Precedente</a></td><td>";
  62. for ($i = 1; $i <= $pager->numPages; $i++) {
  63. echo " ";
  64. if ($i == $pager->page)
  65. echo "<b>$i</b>";
  66. else
  67. echo "<a href=\"" . str_replace("&pagina=$pagina", "", $_SERVER[HTTP_X_REWRITE_URL]) . "&amp;pagina=$i\">$i</a>";
  68. }
  69. if ($pagina == $pager->numPages)
  70. echo "</td><td>Successiva</td></tr></table>";
  71. else
  72. echo "</td><td><a href=\"" . str_replace("&pagina=$pagina", "", $_SERVER[HTTP_X_REWRITE_URL]) . "&amp;pagina=" . ($pagina + 1) . "\">Successiva</a></td></tr></table>";
  73. return $offset.",".$limit;
  74. }
  75. function rm($fileglob)
  76. {
  77. if (is_string($fileglob)) {
  78. if (is_file($fileglob)) {
  79. return unlink($fileglob);
  80. } else if (is_dir($fileglob)) {
  81. $ok = BEYOU_CORE::rm("$fileglob/*");
  82. if (! $ok) {
  83. return false;
  84. }
  85. return rmdir($fileglob);
  86. } else {
  87. $matching = glob($fileglob);
  88. if ($matching === false) {
  89. trigger_error(sprintf('No files match supplied glob %s', $fileglob), E_USER_WARNING);
  90. return false;
  91. }
  92. $rcs = array_map('rm', $matching);
  93. if (in_array(false, $rcs)) {
  94. return false;
  95. }
  96. }
  97. } else if (is_array($fileglob)) {
  98. $rcs = array_map('rm', $fileglob);
  99. if (in_array(false, $rcs)) {
  100. return false;
  101. }
  102. } else {
  103. trigger_error('Param #1 must be filename or glob pattern, or array of filenames or glob patterns', E_USER_ERROR);
  104. return false;
  105. }
  106. return true;
  107. }
  108. function is_image($file)
  109. {
  110. $fltmp = explode('.', $file);
  111. $tipo = array_pop($fltmp);
  112. if ( strtolower($tipo) != "jpeg" && strtolower($tipo) != "jpg" && strtolower($tipo) != "gif" && strtolower($tipo) != "bmp" && strtolower($tipo) != "png") {
  113. return 0;
  114. } else {
  115. return 1;
  116. }
  117. }
  118. }
  119. ?>