/themes/pati_theme/design/flashgallery.php

https://github.com/picoder/Deltus · PHP · 108 lines · 91 code · 17 blank · 0 comment · 26 complexity · f0218ef84b43e88f66ee8cf4215c3190 MD5 · raw file

  1. <?php
  2. $allowed_formats = array("jpg", "jpeg", "JPG", "JPEG", "png", "PNG");
  3. $exclude_files = array(
  4. "_derived",
  5. "_private",
  6. "_vti_cnf",
  7. "_vti_pvt",
  8. "vti_script",
  9. "_vti_txt"
  10. ); // add any other folders or files you wish to exclude from the gallery.
  11. $listDir = array();
  12. function detectUTF8($string)
  13. {
  14. return preg_match('%(?:
  15. [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
  16. |\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
  17. |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
  18. |\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
  19. |\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
  20. |[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
  21. |\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
  22. )+%xs', $string);
  23. }
  24. function cp1251_utf8( $sInput )
  25. {
  26. $sOutput = "";
  27. for ( $i = 0; $i < strlen( $sInput ); $i++ )
  28. {
  29. $iAscii = ord( $sInput[$i] );
  30. if ( $iAscii >= 192 && $iAscii <= 255 )
  31. $sOutput .= "&#".( 1040 + ( $iAscii - 192 ) ).";";
  32. else if ( $iAscii == 168 )
  33. $sOutput .= "&#".( 1025 ).";";
  34. else if ( $iAscii == 184 )
  35. $sOutput .= "&#".( 1105 ).";";
  36. else
  37. $sOutput .= $sInput[$i];
  38. }
  39. return $sOutput;
  40. }
  41. function encoding($string){
  42. if (function_exists('iconv')) {
  43. if (@!iconv('utf-8', 'cp1251', $string)) {
  44. $string = iconv('cp1251', 'utf-8', $string);
  45. }
  46. return $string;
  47. } else {
  48. if (detectUTF8($string)) {
  49. return $string;
  50. } else {
  51. return cp1251_utf8($string);
  52. }
  53. }
  54. }
  55. function ReadFolderDirectory($dir)
  56. {
  57. global $listDir,$exclude_files,$allowed_formats;
  58. if($handler = opendir($dir))
  59. {
  60. {
  61. while (($sub = readdir($handler)) !== FALSE)
  62. {
  63. if ($sub != "." && $sub != ".." && $sub != "Thumb.db" && array_search($sub, $exclude_files)===false)
  64. {
  65. $ext = substr($sub, strrpos($sub, ".")+1);
  66. if(is_file($dir."/".$sub) && array_search($ext, $allowed_formats)!==false ) $listDir[] = $dir."/".$sub;
  67. elseif(is_dir($dir."/".$sub)) ReadFolderDirectory($dir."/".$sub);
  68. }
  69. }
  70. }
  71. closedir($handler);
  72. }
  73. }
  74. if(isset($_GET['file_dir'])) ReadFolderDirectory($_GET['file_dir']);
  75. natcasesort($listDir);
  76. print '<?xml version="1.0" encoding="utf-8"?>';
  77. print '
  78. <pics>';
  79. $directory= $_SERVER['HTTP_HOST'] .$_SERVER['PHP_SELF'];
  80. $directory=dirname($directory);
  81. foreach ($listDir as $val)
  82. {
  83. $title = substr(strrchr($val, '/'), 1);
  84. $title=encoding($title);
  85. $val=encoding($val);
  86. print '
  87. <pic src="'.'http://'.$directory.'/'.$val.'" title="'.$title.'" />';
  88. }
  89. print '
  90. </pics>';
  91. ?>