common.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * 判断语言
  4. */
  5. function lang(){
  6. $lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
  7. if ($lang == 'zh-CN') {
  8. $lang = "zh";
  9. }
  10. return include("lang.".$lang.".php");
  11. }
  12. function L($field){
  13. if (!isset($GLOBALS['lang_array'])) {
  14. $GLOBALS['lang_array'] = lang();
  15. }
  16. return $GLOBALS['lang_array'][$field] ;
  17. }
  18. /**
  19. * 判断 文件/目录 是否可写(取代系统自带的 is_writeable 函数)
  20. *
  21. * @param string $file 文件/目录
  22. * @return boolean
  23. */
  24. function new_is_writeable($file) {
  25. if (is_dir($file)){
  26. $dir = $file;
  27. if ($fp = @fopen("$dir/test.txt", 'w')) {
  28. @fclose($fp);
  29. @unlink("$dir/test.txt");
  30. $writeable = 1;
  31. } else {
  32. $writeable = 0;
  33. }
  34. } else {
  35. if ($fp = @fopen($file, 'a+')) {
  36. @fclose($fp);
  37. $writeable = 1;
  38. } else {
  39. $writeable = 0;
  40. }
  41. }
  42. return $writeable;
  43. }
  44. function clear_runtime($path = "../server/Application/Runtime"){
  45. //给定的目录不是一个文件夹
  46. if(!is_dir($path)){
  47. return null;
  48. }
  49. $fh = opendir($path);
  50. while(($row = readdir($fh)) !== false){
  51. //过滤掉虚拟目录
  52. if($row == '.' || $row == '..'|| $row == 'index.html'){
  53. continue;
  54. }
  55. if(!is_dir($path.'/'.$row)){
  56. unlink($path.'/'.$row);
  57. }
  58. clear_runtime($path.'/'.$row);
  59. }
  60. //关闭目录句柄,否则出Permission denied
  61. closedir($fh);
  62. return true;
  63. }
  64. function ajax_out($message,$error_code = 0){
  65. echo json_encode(array("error_code"=>$error_code,"error_message"=>$message));
  66. exit();
  67. }
  68. function replace_file_content($file , $from ,$to ){
  69. $content = file_get_contents($file);
  70. $content2 = str_replace($from,$to,$content);
  71. if ($content2) {
  72. file_put_contents($file,$content2);
  73. }
  74. }