Annotation of pettastic/html/ss1/flashgallery.php, revision 1.1
1.1 ! nick 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:
! 12: $listDir = array();
! 13:
! 14: function detectUTF8($string)
! 15: {
! 16: return preg_match('%(?:
! 17: [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
! 18: |\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
! 19: |[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
! 20: |\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
! 21: |\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
! 22: |[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
! 23: |\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
! 24: )+%xs', $string);
! 25: }
! 26:
! 27: function cp1251_utf8( $sInput )
! 28: {
! 29: $sOutput = "";
! 30:
! 31: for ( $i = 0; $i < strlen( $sInput ); $i++ )
! 32: {
! 33: $iAscii = ord( $sInput[$i] );
! 34:
! 35: if ( $iAscii >= 192 && $iAscii <= 255 )
! 36: $sOutput .= "&#".( 1040 + ( $iAscii - 192 ) ).";";
! 37: else if ( $iAscii == 168 )
! 38: $sOutput .= "&#".( 1025 ).";";
! 39: else if ( $iAscii == 184 )
! 40: $sOutput .= "&#".( 1105 ).";";
! 41: else
! 42: $sOutput .= $sInput[$i];
! 43: }
! 44:
! 45: return $sOutput;
! 46: }
! 47:
! 48: function encoding($string){
! 49: if (function_exists('iconv')) {
! 50: if (@!iconv('utf-8', 'cp1251', $string)) {
! 51: $string = iconv('cp1251', 'utf-8', $string);
! 52: }
! 53: return $string;
! 54: } else {
! 55: if (detectUTF8($string)) {
! 56: return $string;
! 57: } else {
! 58: return cp1251_utf8($string);
! 59: }
! 60: }
! 61: }
! 62:
! 63:
! 64: function ReadFolderDirectory($dir)
! 65: {
! 66: global $listDir,$exclude_files,$allowed_formats;
! 67: if($handler = opendir($dir))
! 68: {
! 69: {
! 70: while (($sub = readdir($handler)) !== FALSE)
! 71: {
! 72:
! 73: if ($sub != "." && $sub != ".." && $sub != "Thumb.db" && array_search($sub, $exclude_files)===false)
! 74: {
! 75: $ext = substr($sub, strrpos($sub, ".")+1);
! 76: if(is_file($dir."/".$sub) && array_search($ext, $allowed_formats)!==false ) $listDir[] = $dir."/".$sub;
! 77: elseif(is_dir($dir."/".$sub)) ReadFolderDirectory($dir."/".$sub);
! 78: }
! 79: }
! 80: }
! 81: closedir($handler);
! 82: }
! 83: }
! 84:
! 85: if(isset($_GET['file_dir'])) ReadFolderDirectory($_GET['file_dir']);
! 86:
! 87: natcasesort($listDir);
! 88:
! 89: print '<?xml version="1.0" encoding="utf-8"?>';
! 90: print '
! 91: <pics>';
! 92:
! 93: $directory= $_SERVER['HTTP_HOST'] .$_SERVER['PHP_SELF'];
! 94: $directory=dirname($directory);
! 95:
! 96: foreach ($listDir as $val)
! 97: {
! 98: $title = substr(strrchr($val, '/'), 1);
! 99: $title=encoding($title);
! 100: $val=encoding($val);
! 101:
! 102: print '
! 103: <pic src="'.'http://'.$directory.'/'.$val.'" title="'.$title.'" />';
! 104: }
! 105:
! 106: print '
! 107: </pics>';
! 108: ?>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>