PageRenderTime 26ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/scuttle/tags/scuttle-0.7.2-upstream/functions.inc.php

https://github.com/martijnvermaat/quick-hacks
PHP | 160 lines | 125 code | 23 blank | 12 comment | 53 complexity | bf691398ce54d4499d1d10123b0b3aab MD5 | raw file
  1. <?php
  2. // UTF-8 functions
  3. require_once(dirname(__FILE__) .'/includes/utf8.php');
  4. // Translation
  5. require_once(dirname(__FILE__) .'/includes/php-gettext/gettext.inc');
  6. $domain = 'messages';
  7. T_setlocale(LC_MESSAGES, $locale);
  8. T_bindtextdomain($domain, dirname(__FILE__) .'/locales');
  9. T_bind_textdomain_codeset($domain, 'UTF-8');
  10. T_textdomain($domain);
  11. // Converts tags:
  12. // - direction = out: convert spaces to underscores;
  13. // - direction = in: convert underscores to spaces.
  14. function convertTag($tag, $direction = 'out') {
  15. if ($direction == 'out') {
  16. $tag = str_replace(' ', '_', $tag);
  17. } else {
  18. $tag = str_replace('_', ' ', $tag);
  19. }
  20. return $tag;
  21. }
  22. function filter($data, $type = NULL) {
  23. if (is_string($data)) {
  24. $data = trim($data);
  25. $data = stripslashes($data);
  26. switch ($type) {
  27. case 'url':
  28. $data = rawurlencode($data);
  29. break;
  30. default:
  31. $data = htmlspecialchars($data);
  32. break;
  33. }
  34. } else if (is_array($data)) {
  35. foreach(array_keys($data) as $key) {
  36. $row =& $data[$key];
  37. $row = filter($row, $type);
  38. }
  39. }
  40. return $data;
  41. }
  42. function getPerPageCount() {
  43. global $defaultPerPage;
  44. return $defaultPerPage;
  45. }
  46. function getSortOrder($override = NULL) {
  47. global $defaultOrderBy;
  48. if (isset($_GET['sort'])) {
  49. return $_GET['sort'];
  50. } else if (isset($override)) {
  51. return $override;
  52. } else {
  53. return $defaultOrderBy;
  54. }
  55. }
  56. function multi_array_search($needle, $haystack) {
  57. if (is_array($haystack)) {
  58. foreach(array_keys($haystack) as $key) {
  59. $value =& $haystack[$key];
  60. $result = multi_array_search($needle, $value);
  61. if (is_array($result)) {
  62. $return = $result;
  63. array_unshift($return, $key);
  64. return $return;
  65. } elseif ($result == true) {
  66. $return[] = $key;
  67. return $return;
  68. }
  69. }
  70. return false;
  71. } else {
  72. if ($needle === $haystack) {
  73. return true;
  74. } else {
  75. return false;
  76. }
  77. }
  78. }
  79. function createURL($page = '', $ending = '') {
  80. global $cleanurls, $root;
  81. if (!$cleanurls && $page != '') {
  82. $page .= '.php';
  83. }
  84. return $root . $page .'/'. $ending;
  85. }
  86. function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '', $db = NULL) {
  87. if(defined('HAS_DIED'))
  88. die(T_('message_die() was called multiple times.'));
  89. define('HAS_DIED', 1);
  90. $sql_store = $sql;
  91. // Get SQL error if we are debugging. Do this as soon as possible to prevent
  92. // subsequent queries from overwriting the status of sql_error()
  93. if (DEBUG && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
  94. $sql_error = is_null($db) ? '' : $db->sql_error();
  95. $debug_text = '';
  96. if ($sql_error['message'] != '')
  97. $debug_text .= '<br /><br />'. T_('SQL Error') .' : '. $sql_error['code'] .' '. $sql_error['message'];
  98. if ($sql_store != '')
  99. $debug_text .= '<br /><br />'. $sql_store;
  100. if ($err_line != '' && $err_file != '')
  101. $debug_text .= '</br /><br />'. T_('Line') .' : '. $err_line .'<br />'. T_('File') .' :'. $err_file;
  102. }
  103. switch($msg_code) {
  104. case GENERAL_MESSAGE:
  105. if ($msg_title == '')
  106. $msg_title = T_('Information');
  107. break;
  108. case CRITICAL_MESSAGE:
  109. if ($msg_title == '')
  110. $msg_title = T_('Critical Information');
  111. break;
  112. case GENERAL_ERROR:
  113. if ($msg_text == '')
  114. $msg_text = T_('An error occured');
  115. if ($msg_title == '')
  116. $msg_title = T_('General Error');
  117. break;
  118. case CRITICAL_ERROR:
  119. // Critical errors mean we cannot rely on _ANY_ DB information being
  120. // available so we're going to dump out a simple echo'd statement
  121. if ($msg_text == '')
  122. $msg_text = T_('An critical error occured');
  123. if ($msg_title == '')
  124. $msg_title = T_('Critical Error');
  125. break;
  126. }
  127. // Add on DEBUG info if we've enabled debug mode and this is an error. This
  128. // prevents debug info being output for general messages should DEBUG be
  129. // set TRUE by accident (preventing confusion for the end user!)
  130. if (DEBUG && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
  131. if ($debug_text != '')
  132. $msg_text = $msg_text . '<br /><br /><strong>'. T_('DEBUG MODE') .'</strong>'. $debug_text;
  133. }
  134. echo "<html>\n<body>\n". $msg_title ."\n<br /><br />\n". $msg_text ."</body>\n</html>";
  135. exit;
  136. }
  137. ?>