functions.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /*
  3. Generic functions used by the rest of the site
  4. Copyright (C) 2015 Leah Rowe <info@minifree.org>
  5. This document is released under Creative Commons Attribution-ShareAlike
  6. 4.0 International license.
  7. See <https://creativecommons.org/licenses/by-sa/4.0/legalcode>
  8. */
  9. /* Functions */
  10. /* Minified HTML output (note: needs work for <pre> tags) */
  11. function miniHtml($strHtml) {
  12. return $strHtml;
  13. /* return $strHtml = preg_replace(
  14. array("/\r|\n/", "/(\s)+/s", "/\>[^\S ]+/s", "/[^\S ]+\</s"),
  15. array("", "\\1", ">", "<"),
  16. $strHtml
  17. ); */
  18. }
  19. /* Minified CSS output */
  20. function miniCss($strCss) {
  21. return $strCss; // preg_replace("/\r|\n/", "", $strCss);
  22. }
  23. /* Generic function for showing a list of URLs */
  24. function mirrorList($arrayMirrors,$strNotFoundMessage,$forIndexStart,$forIndexbelow) {
  25. if (count($arrayMirrors)>0) {
  26. for ($server=$forIndexStart; $server<$forIndexbelow; $server++) {
  27. ?>
  28. <p><a href="<?php echo $arrayMirrors[$server][0]; ?>"><?php echo $arrayMirrors[$server][0]; ?></a> (<?php echo $arrayMirrors[$server][1]; ?>)</p>
  29. <?php
  30. }
  31. } else {
  32. ?>
  33. <p><?php echo $strNotFoundMessage; ?></p>
  34. <?php
  35. }
  36. }
  37. /* List rsync mirroring instructions */
  38. function rsyncList($arrayRsync,$strNotFoundMessage,$forIndexStart,$forIndexBelow) {
  39. if (
  40. count($arrayRsync)>0 && ($forIndexStart<=count($arrayRsync)-1)
  41. && ($forIndexBelow<=count($arrayRsync)) && ($forIndexStart<=$forIndexBelow)) {
  42. for ($server=$forIndexStart; $server<$forIndexBelow; $server++) {
  43. ?>
  44. <h2>
  45. <?php echo $arrayRsync[$server][1]; ?>
  46. </h2>
  47. <p>
  48. <b>rsync -avxP --delete --stats <?php echo $arrayRsync[$server][0]; ?> /path/to/docroot/libreboot/</b>
  49. </p>
  50. <?php
  51. }
  52. } else {
  53. ?>
  54. <p>
  55. <?php echo $strNotFoundMessage; ?>
  56. </p>
  57. <?php
  58. }
  59. }
  60. function sanitize_database_input($input) /* for storing in a database */ {
  61. return htmlspecialchars(addslashes(trim($input)));
  62. }
  63. function sanitize_html_output($input) /* for outputting onto the page */ {
  64. return htmlspecialchars(trim($input));
  65. }
  66. function decode_input($input){ /* for storing in the PHP variable, when processing it */
  67. return stripslashes(htmlspecialchars_decode(trim($input)));
  68. }
  69. // array image example:
  70. // array(
  71. // array("path to thumbnail", "path to full image", "caption"),
  72. // array("path to thumbnail", "path to full image", "caption"),
  73. // array("path to thumbnail", "path to full image", "caption"),
  74. // )
  75. // prefix is e.g. "cats", gets added to ID of images
  76. function gencssboxgallery($arrayImages,$prefix) {
  77. for($i=0; $i<count($arrayImages); $i++) {
  78. ?>
  79. <div class="image_item">
  80. <?php
  81. $mainpic= ($i==0) ? "product_mainpic ":"";
  82. ?>
  83. <a title="<?php echo $arrayImages[$i][2]; ?>" id="<?php echo $prefix; ?>image<?php echo (string)($i); ?>" href="#<?php echo $prefix; ?>image<?php echo (string)($i); ?>"><img alt="<?php echo $arrayImages[$i][2]; ?>" class="<?php echo $mainpic; ?>cssbox_thumb" src="<?php echo $arrayImages[$i][0]; ?>" />
  84. <span class="cssbox_full"><img alt="<?php echo $arrayImages[$i][2]; ?>" src="<?php echo $arrayImages[$i][1]; ?>" /></span>
  85. </a>
  86. <a class="cssbox_close" href="#void"></a>
  87. <?php
  88. if ($i!=0) {
  89. ?>
  90. <a class="cssbox_prev" href="#<?php echo $prefix; ?>image<?php echo (string)($i-1); ?>">&lt;</a>
  91. <?php
  92. }
  93. if ($i!=count($arrayImages)-1) {
  94. ?>
  95. <a class="cssbox_next" href="#<?php echo $prefix; ?>image<?php echo (string)($i+1); ?>">&gt;</a>
  96. <?php
  97. }
  98. ?>
  99. </div>
  100. <?php
  101. }
  102. }
  103. ?>