Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.14 KB | None | 0 0
  1.     <html>
  2. <head>
  3.  
  4. <script src="./jquery.js"></script>
  5. <script src="./squirrel.js"></script>
  6.  
  7. <style>
  8. *{padding: 0px; margin: 0px;}
  9. html,body{width: 100%; height: 100%:}
  10. #menu{
  11. top: 200px;
  12. left: -130px;
  13. position: absolute;
  14. z-index: 100;
  15. }
  16. #menu:hover{
  17. left: 0px;
  18. }
  19. #menu a{
  20. display: block;
  21. background-color: #0088cc;
  22. color: white;
  23. line-height: 1.5;
  24. width: 150px;
  25. font-size: 20px;
  26. text-align: center;
  27. text-decoration: none;
  28. }
  29. #alphamenu{
  30. position: absolute;
  31. right: 20px;
  32. top: 0px;
  33. background-color: black;
  34. width: 20px;
  35. }
  36. #alphamenu a{
  37. display: block;
  38. color: white;
  39. width: 20px;
  40. text-decoration: none;
  41. font-size: 18px;
  42. line-height: 1.5;
  43. }
  44. #content{
  45. padding-left: 35px;
  46. padding-right: 40px;
  47. background-color: black;
  48. overflow: auto;
  49. height: 100%;
  50. width: 100%:
  51. }
  52. #content .letter{
  53. color: white;
  54. width: 100%;
  55. float: left;
  56. font-size: 18px;
  57. line-height: 1.5;
  58. }
  59. #content .item .imagebox{
  60. width: 150px;
  61. height: 150px;
  62. }
  63. #content .item img{
  64. max-width: 150px;
  65. max-height: 150px;
  66. }
  67. #content .item{
  68. position: relative;
  69. text-align: center;
  70. height: 250px;
  71. width: 150px;
  72. float: left;
  73. margin: 20px 0px;
  74. overflow: hidden;
  75. }
  76. #content .item .textbox{
  77. position: absolute;
  78. left: 150px;
  79. top: 0px;
  80. width: 300px;
  81. height: 250px;
  82. background-color: black;
  83. overflow: hidden;
  84. font-size: 14px;
  85. color: white;
  86. text-align: left;
  87. }
  88. #content .item ul{
  89. padding-left: 25px;
  90. list-style: none;
  91. }
  92. #content .item .textbox > li{
  93. font-size: 18px;
  94. }
  95. #content .item-big{
  96. width: 450px;
  97. }
  98. #content h3{
  99. height: 100px;
  100. font-size: 20px;
  101. width: 150px;
  102. overflow: hidden;
  103. }
  104. #content h3 a{
  105. color: white;
  106. text-decoration: none;
  107. }
  108. #content .sizer{clear: both;height: 100px;}
  109. </style>
  110. </head>
  111. <body>
  112. <?php
  113.  
  114. // Returns array with which contains files in given folder, each files contains ['file'] and ['name']
  115. function explodedir($dir){
  116.     if (is_dir($dir)) { // Is it really dir?
  117.         if ($dh = opendir($dir))    { // Opened?
  118.         while (($file = readdir($dh)) !== false) { // Succes on reading next file from folder
  119.             if($file != "." and $file != ".."){ // We do not want .. and . files
  120.                 $item['file'] = $dir."/".$file;
  121.                 $item['name'] = $file;
  122.                 $items[$item['name']] = $item;
  123.                 unset($item);
  124.             }
  125.         }
  126.         closedir($dh);
  127.         return $items;
  128.         }
  129.     }
  130. }
  131.  
  132. /* Sets Default values
  133.  *
  134.  *  basedir - dir from where script looks for files
  135.  *      - first level dir contains the group of movies/tvshows, second level are movies itself
  136.  *  default_dir - dir which is printed as default
  137.  *  default_img - this image script use to make a cover when he do not find any cover in movies folder
  138.  *  types_img - files with this ending (*.jpg etc...) are used as covers if founded... script pickes first it finds
  139.  *  types_video - same as types_img but for videos
  140.  *  types_subtitles - same as types_img but for subtitles
  141.  */
  142.  
  143. $basedir = "/srv/http/Videos";
  144. $default_dir = 'Movies';
  145. $default_img = "http://4.bp.blogspot.com/-BhrtpyFk3-M/TYBK7JrZWhI/AAAAAAAAAPM/eCAR2DJET10/s400/unavailable.gif";
  146. $types_img = array('jpg','png','jpeg','gif','PNG');
  147. $types_video = array('avi','mkv','mp4');
  148. $types_subtitles = array('srt','txt');
  149.  
  150. //find folders which represents group
  151. $dirs = explodedir($basedir);
  152.  
  153. //generate menu, each item in menu is one group of movies
  154. echo '<div id="menu">';
  155. foreach($dirs as $dir){
  156.     echo '<a href="./index.php?folder='.$dir['name'].'">'.$dir['name'].'</a>';
  157. }
  158. echo '</div>';
  159.  
  160. //sets default group to Movies, otherwise it uses group given in $_GET['folder']
  161. if(isset($_GET['folder'])){
  162.  
  163.     $dir = $_GET['folder'];
  164.  
  165. }else{
  166.  
  167.     $dir = $default_dir;
  168.  
  169. }
  170.  
  171. //explorers dir for Movies etc...
  172. $items = explodedir($basedir."/".$dir);
  173.  
  174. sort($items);
  175.  
  176. //generate base html strucutre
  177. ?>
  178. <div id="content">
  179. <div class="sizer"></div>
  180. <?php
  181.  
  182. $letter = null;
  183.  
  184. //generate Movies
  185. foreach($items as $item){
  186.  
  187.     //set default image
  188.     $img = $default_img;
  189.    
  190.     //explore dir of movie
  191.     $files = explodedir($item['file']);
  192.    
  193.     unset($videos);
  194.     unset($subtitles);
  195.    
  196.     //cycle to find files
  197.     foreach($files as $file){
  198.    
  199.         //gets file last word, exploded by '.', which should be file type
  200.         $file_type = end(
  201.                 explode('.',$file['name'])
  202.                 );
  203.        
  204.         //generate url to acces file from web
  205.         $url = "http://".$_SERVER['HTTP_HOST']."/Videos/".$dir."/".$item['name']."/".$file['name'];
  206.    
  207.         //generate array for future processisng
  208.         $file_info = array('url' => $url,'name' => $file['name']);
  209.    
  210.         //check if files is image, uses types_img to recognize, only one time per item
  211.         if (in_array($file_type,$types_img) and $img == $default_img) {
  212.             $img = $url;
  213.         }
  214.        
  215.         //check if file is video
  216.         if(in_array($file_type,$types_video) or $file['name'] == 'VIDEO_TS'){
  217.             $videos[] = $file_info;
  218.         }
  219.        
  220.         //check for all subtitle files
  221.         if(in_array($file_type,$types_subtitles)){
  222.             $subtitles[] = $file_info;
  223.         }
  224.     }
  225.  
  226.     //check if momental file is selected by user, set's classes based on that
  227.     if($_GET['item']==$item['name']){
  228.    
  229.         $class = 'item item-big';
  230.    
  231.     }else{
  232.    
  233.         $class = 'item';
  234.    
  235.     }
  236.     $movie_letter = substr($item['name'],0,1);
  237.     if($letter != $movie_letter){
  238.         echo '<div class="letter">'.$movie_letter.'<a name="'.$movie_letter.'"></a></div>';
  239.         $letter = $movie_letter;
  240.         $letters[] = $letter;
  241.     }
  242.    
  243.     //Generation of HTML
  244.     ?>
  245.         <div class="<?php echo $class; ?>">
  246.             <div class="imagebox">
  247.                 <img src="<?php echo $img;?>">
  248.             </div>
  249.             <h3>
  250.                 <a href="index.php?folder=<?php echo $dir; ?>&item=<?php echo $item['name']; ?>#<?php echo $item['name'];?>"><?php echo $item['name']; ?></a>
  251.                 <a name="<?php echo $item['name']; ?>"></a>
  252.             </h3>
  253.             <ul class="textbox">
  254.                 <li>Video files:</li>
  255.                 <ul>
  256.                 <?php  foreach($videos as $video){?>
  257.                
  258.                     <li><?php echo $video['name']; ?></li>
  259.                
  260.                 <?php }?>
  261.                 </ul>
  262.                 <li>Subtitle files:</li>
  263.                 <ul>
  264.                 <?php  foreach($subtitles as $subtitle){?>
  265.                
  266.                     <li><?php echo $subtitle['name']; ?></li>
  267.                
  268.                 <?php }?>
  269.                 </ul>
  270.             </ul>
  271.         </div>
  272.     <?php
  273. }
  274. ?>
  275. <div class="sizer"></div>
  276. </div>
  277. <div id="alphamenu">
  278. <?php foreach($letters as $letter){?>
  279.     <a href="#<?php echo $letter;?>"><?php echo $letter;?></a>
  280. <?php } ?>
  281. </div>
  282. </body>
  283. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement