PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/core/basic.php

https://bitbucket.org/simancms/simancms
PHP | 105 lines | 78 code | 15 blank | 12 comment | 6 complexity | ca5686c6738d64d26924dddd4f6aefe5 MD5 | raw file
  1. <?php
  2. //------------------------------------------------------------------------------
  3. //| Content Management System SiMan CMS |
  4. //| http://www.simancms.org |
  5. //------------------------------------------------------------------------------
  6. //==============================================================================
  7. //#ver 1.6.20
  8. //#revision 2021-08-15
  9. //==============================================================================
  10. function sm_count($array)
  11. {
  12. if (empty($array))
  13. return 0;
  14. elseif (!is_array($array))
  15. return 0;
  16. else
  17. return count($array);
  18. }
  19. function sm_get_array_value($array, $key)
  20. {
  21. if (isset($array[$key]))
  22. return $array[$key];
  23. else
  24. return NULL;
  25. }
  26. function sm_set_array_value(&$array, $key, $val)
  27. {
  28. $array[$key]=$val;
  29. }
  30. function sm_getvars($key=NULL)
  31. {
  32. global $_getvars;
  33. if ($key===NULL)
  34. return $_getvars;
  35. elseif (empty($_getvars[$key]))
  36. return '';
  37. else
  38. return $_getvars[$key];
  39. }
  40. function sm_postvars($key=NULL)
  41. {
  42. global $_postvars;
  43. if ($key===NULL)
  44. return $_postvars;
  45. elseif (empty($_postvars[$key]))
  46. return '';
  47. else
  48. return $_postvars[$key];
  49. }
  50. function sm_abs($var)
  51. {
  52. return abs(intval($var));
  53. }
  54. /**
  55. * CMS root directory path
  56. * @return string
  57. */
  58. function sm_cms_rootdir()
  59. {
  60. return dirname(dirname(dirname(__FILE__))).'/';
  61. }
  62. function sm_file_path($relative_filename)
  63. {
  64. return sm_cms_rootdir().$relative_filename;
  65. }
  66. function sm_null_safe_str($val)
  67. {
  68. if ($val===NULL)
  69. return '';
  70. else
  71. return $val;
  72. }
  73. function sm_strcmp($str1, $str2)
  74. {
  75. return strcmp(sm_null_safe_str($str1), sm_null_safe_str($str2));
  76. }
  77. function sm_strlen($str)
  78. {
  79. return strlen(sm_null_safe_str($str));
  80. }
  81. function sm_strpos($haystack, $needle, $offset=0)
  82. {
  83. return strpos(sm_null_safe_str($haystack), sm_null_safe_str($needle), $offset);
  84. }
  85. function sm_auto_class_loader($classname)
  86. {
  87. if (strcmp(substr($classname, 0, 3), 'SM\\')==0)
  88. include_once(dirname(dirname(__FILE__)).'/'.str_replace('\\', '/', $classname).'.php');
  89. }
  90. spl_autoload_register('sm_auto_class_loader');