A new, object-oriented, better vesion of μForum
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.4 KiB

  1. <?php
  2. function buildURL($URI, $https = false)
  3. {
  4. $url = 'http';
  5. if ($https && USE_HTTPS)
  6. $url .= 's';
  7. $url .= '://'.FORUM_DOMAIN;
  8. if ($https && USE_HTTPS && HTTPS_PORT != 443)
  9. $url .= ':'.HTTPS_PORT;
  10. if ((!$https || !USE_HTTPS) && HTTP_PORT != 80)
  11. $url .= ':'.HTTP_PORT;
  12. if (strpos($URI, FORUM_PATH) === 0)
  13. $url .= $URI;
  14. else
  15. $url .= FORUM_PATH.'/'.$URI;
  16. return $url;
  17. }
  18. function post_default($key, $default='')
  19. {
  20. $_POST[$key] = (isset($_POST[$key])) ? stripslashes($_POST[$key]) : $default;
  21. }
  22. function input_clean(&$input, &$dbobj, $opts = null)
  23. {
  24. $input = trim($input);
  25. if ($opts != null)
  26. {
  27. if (in_array('spchars', $opts)) //special chars
  28. $input = htmlspecialchars($input);
  29. if (in_array('strip', $opts)) //strip tags
  30. $input = strip_tags($input);
  31. if (in_array('nnegint', $opts)) //non-negative integer
  32. {
  33. $int_options = array('options' => array('min_range' => 0));
  34. $input = filter_var($input, FILTER_VALIDATE_INT, $int_options);
  35. }
  36. }
  37. else
  38. $input = strip_tags($input);
  39. $input = $dbobj->real_escape_string($input);
  40. }
  41. function post_clean($key, &$dbobj, $opts = null)
  42. {
  43. input_clean($_POST[$key], $dbobj, $opts);
  44. }
  45. function get_clean($key, &$dbobj, $intval = true)
  46. {
  47. if (array_key_exists($key, $_GET))
  48. {
  49. $opts = ($intval) ? array('strip', 'nnegint') : null;
  50. input_clean($_GET[$key], $dbobj, $opts);
  51. }
  52. else
  53. {
  54. $_GET[$key] = ($intval) ? 0 : '';
  55. }
  56. }
  57. ?>