PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Uthando-Lib/functions/functions.php

https://github.com/shaunfreeman/Uthando-CMS
PHP | 117 lines | 87 code | 15 blank | 15 comment | 25 complexity | 5409aa48adec9845d18ff24257f5bf08 MD5 | raw file
Possible License(s): MIT, GPL-2.0
  1. <?php
  2. // Auto load classes.
  3. function __autoload($class_name)
  4. {
  5. $class_name = explode("_", $class_name);
  6. $class_path = null;
  7. foreach ($class_name as $key => $value) {
  8. $class_path .= '/'.$value;
  9. }
  10. $class_path = substr($class_path, 1);
  11. require ($class_path . '.php');
  12. }
  13. //ini_set('display_errors', 1);
  14. //class UthandoError extends UthandoException {};
  15. /*
  16. function exception_error_handler($errno, $errstr, $errfile, $errline ) {
  17. throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
  18. }
  19. */
  20. //set_error_handler("exception_error_handler");
  21. function print_rr($value) {
  22. print "<pre style=\"background-color:white;color:black;\">";
  23. print_r($value);
  24. print "</pre>";
  25. }
  26. if(!function_exists('parse_ini_string')){
  27. function parse_ini_string($str, $ProcessSections=false){
  28. $lines = explode("\n", $str);
  29. $return = Array();
  30. $inSect = false;
  31. foreach($lines as $line){
  32. $line = trim($line);
  33. if(!$line || $line[0] == "#" || $line[0] == ";")
  34. continue;
  35. if($line[0] == "[" && $endIdx = strpos($line, "]")){
  36. $inSect = substr($line, 1, $endIdx-1);
  37. continue;
  38. }
  39. if(!strpos($line, '=')) // (We don't use "=== false" because value 0 is not valid as well)
  40. continue;
  41. $tmp = explode("=", $line, 2);
  42. if($ProcessSections && $inSect)
  43. $return[$inSect][trim($tmp[0])] = ltrim($tmp[1]);
  44. else
  45. $return[trim($tmp[0])] = ltrim($tmp[1]);
  46. }
  47. return $return;
  48. }
  49. }
  50. // Function for escaping and trimming form data.
  51. function escape_db_data ($data, $tags=true) {
  52. global $registry;
  53. if (ini_get('magic_quotes_gpc')) {
  54. $data = stripslashes($data);
  55. }
  56. if (!$tags) $data = strip_tags($data);
  57. return $registry->db->escape(trim($data));
  58. }
  59. function escape_data ($data, $tags=true) {
  60. if (ini_get('magic_quotes_gpc')) {
  61. $data = stripslashes($data);
  62. }
  63. if (!$tags) $data = strip_tags($data);
  64. return trim($data);
  65. }
  66. // Function for crating usernames.
  67. function create_username ($username) {
  68. $id = uniqid();
  69. $username = explode ("@", $username);
  70. $username = $username[0];
  71. if (strlen($username) > 8) {
  72. $username = substr ($username, 0, 8);
  73. } else {
  74. $username = $username;
  75. }
  76. return $username;
  77. }
  78. function find_files($dirname, $ext, $file_list = array()) {
  79. global $file_list;
  80. // Loop through the folder
  81. $dir = dir($dirname);
  82. while (false !== $entry = $dir->read()) {
  83. // Skip pointers
  84. if ($entry == '.' || $entry == '..') {
  85. continue;
  86. }
  87. // Deep find directories
  88. if (is_dir($dirname . DS . $entry)) {
  89. find_files($dirname . DS . $entry, $ext, $file_list);
  90. } else {
  91. foreach ($ext as $key => $value) {
  92. if (substr($entry,-$value) == $key) {
  93. $file_list[] = $dirname . DS . $entry;
  94. }
  95. }
  96. }
  97. }
  98. // Clean up
  99. $dir->close();
  100. return $file_list;
  101. }
  102. ?>