PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/assets/inc/getfolders.php

https://github.com/stoat/BACAT
PHP | 201 lines | 169 code | 26 blank | 6 comment | 57 complexity | ffa634a620ddd090d9a2dc8ab539dc07 MD5 | raw file
  1. <?php
  2. function getImages($path, $galleryName) {
  3. $files = array();
  4. $fileNames = array();
  5. $i = 0;
  6. if (is_dir($path)) {
  7. if ($dh = opendir($path)) {
  8. while (($file = readdir($dh)) !== false) {
  9. if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
  10. $fullpath = $path . "/" . $file;
  11. $fkey = strtolower($file);
  12. while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
  13. $a = stat($fullpath);
  14. $files[$fkey]['size'] = $a['size'];
  15. if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
  16. else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
  17. else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
  18. else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
  19. $files[$fkey]['name'] = $file;
  20. $files[$fkey]['type'] = filetype($fullpath);
  21. $fileNames[$i++] = $fkey;
  22. }
  23. closedir($dh);
  24. } else die ("Cannot open directory: $path");
  25. } else die ("Path is not a directory: $path");
  26. sort($fileNames,SORT_STRING);
  27. $sortedFiles = array();
  28. $i = 0;
  29. $photos = array();
  30. foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
  31. echo "var $galleryName = new Array() \n";
  32. $j = 0;
  33. foreach ($sortedFiles as $file) {
  34. // get image sizes
  35. list($width, $height, $type, $attr) = getimagesize($path."/".$file[name], $info);
  36. $size = $file[sizetext];
  37. $iptc = iptcparse($info["APP13"]);
  38. // iptc info
  39. $iptc = iptcparse($info["APP13"]);
  40. $title = $iptc['2#005'][0];
  41. $description = $iptc['2#120'][0];
  42. $description = str_replace("\r", "<br/>", $description);
  43. $description = addslashes($description);
  44. $keywords = $iptc['2#025'][0];
  45. $author = $iptc['2#080'][0];
  46. $copyright = $iptc['2#116'][0];
  47. array_push($photos, $width);
  48. array_push($photos, $height);
  49. echo "$galleryName";echo"[".$j."]=['".$path."/".$file[name]."', '".$width."', '".$height."', '".$size."', '".$title."', '".$author."', '".$copyright."', '".$description."', '".$j."']\n";
  50. $j++;
  51. }
  52. echo "\n";
  53. echo "var currentwidth=".$photos[0].";\n";
  54. echo "var currentheight=".$photos[1].";";
  55. echo "\n";
  56. }
  57. function getfirstimage($path, $galleryName) {
  58. $files = array();
  59. $fileNames = array();
  60. $i = 0;
  61. if (is_dir($path)) {
  62. if ($dh = opendir($path)) {
  63. while (($file = readdir($dh)) !== false) {
  64. if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
  65. $fullpath = $path . "/" . $file;
  66. $fkey = strtolower($file);
  67. while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
  68. $a = stat($fullpath);
  69. $files[$fkey]['size'] = $a['size'];
  70. if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
  71. else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
  72. else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
  73. else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
  74. $files[$fkey]['name'] = $file;
  75. $files[$fkey]['type'] = filetype($fullpath);
  76. $fileNames[$i++] = $fkey;
  77. }
  78. closedir($dh);
  79. } else die ("Cannot open directory: $path");
  80. } else die ("Path is not a directory: $path");
  81. sort($fileNames,SORT_STRING);
  82. $sortedFiles = array();
  83. $i = 0;
  84. $photoarray = array();
  85. $photoinfo = array();
  86. foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
  87. echo'<div id="imgloader">';
  88. $j=0;
  89. foreach ($sortedFiles as $file) {
  90. // get image sizes
  91. list($width, $height, $type, $attr) = getimagesize("$path/$file[name]", $info);
  92. $size = $file[sizetext];
  93. $iptc = iptcparse($info["APP13"]);
  94. // iptc info
  95. $iptc = iptcparse($info["APP13"]);
  96. $title = $iptc['2#005'][0];
  97. $description = $iptc['2#120'][0];
  98. $description = str_replace("\r", "<br/>", $description);
  99. $description = addslashes($description);
  100. $keywords = $iptc['2#025'][0];
  101. $author = $iptc['2#080'][0];
  102. $copyright = $iptc['2#116'][0];
  103. array_push($photoarray, '<img src="'.$path.'/'.$file[name].'" width="'.$width.'" height="'.$height.'" alt="'.$title.'" />');
  104. array_push($photoinfo, $title);
  105. array_push($photoinfo, $author);
  106. array_push($photoinfo, $copyright);
  107. array_push($photoinfo, $description);
  108. }
  109. echo ' </div>
  110. <div id="iptc_info">
  111. <div class="iptc_left"><br/><br/>
  112. Title <br/>
  113. Author <br/>
  114. Copyright <br/><br/>
  115. Description <br/><br/>
  116. </div>
  117. <div class="iptc_right"><br/><br/>
  118. '.$photoinfo[0].'<br/>
  119. '.$photoinfo[1].'<br/>
  120. '.$photoinfo[2].'<br/><br/>
  121. '.$photoinfo[3].'<br/><br/>
  122. </div>
  123. </div>
  124. ';
  125. }
  126. function getthumbnailimages($path, $galleryName, $thumbnailpath) {
  127. $files = array();
  128. $fileNames = array();
  129. $i = 0;
  130. if (is_dir($path)) {
  131. if ($dh = opendir($path)) {
  132. while (($file = readdir($dh)) !== false) {
  133. if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
  134. $fullpath = $path . "/" . $file;
  135. $fkey = strtolower($file);
  136. while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
  137. $a = stat($fullpath);
  138. $files[$fkey]['size'] = $a['size'];
  139. if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
  140. else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
  141. else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
  142. else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
  143. $files[$fkey]['name'] = $file;
  144. $files[$fkey]['type'] = filetype($fullpath);
  145. $fileNames[$i++] = $fkey;
  146. }
  147. closedir($dh);
  148. } else die ("Cannot open directory: $path");
  149. } else die ("Path is not a directory: $path");
  150. sort($fileNames,SORT_STRING);
  151. $sortedFiles = array();
  152. $i = 0;
  153. $thumbs = array();
  154. foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
  155. $j=0;
  156. foreach ($sortedFiles as $file) {
  157. // get image sizes
  158. list($width, $height, $type, $attr) = getimagesize("$path/$file[name]", $info);
  159. $size = $file[sizetext];
  160. $iptc = iptcparse($info["APP13"]);
  161. // iptc info
  162. $iptc = iptcparse($info["APP13"]);
  163. $title = $iptc['2#005'][0];
  164. $description = $iptc['2#120'][0];
  165. $description = str_replace("\r", "<br/>", $description);
  166. $description = addslashes($description);
  167. $keywords = $iptc['2#025'][0];
  168. $author = $iptc['2#080'][0];
  169. $copyright = $iptc['2#116'][0];
  170. array_push($thumbs, '<a href="#" onclick="getstarted('.$width.', '.$height.', \'imgloader\', '.$j.', \''.$j.'\', current_imgid);return false;"><img src="'.$thumbnailpath.'/'.$file[name].'" alt="'.$title.'" title="'.$title.'" tooltitle="'.$title.'" class="toolTipImg" /></a>');
  171. echo $thumbs[$j];
  172. $j++;
  173. }
  174. }
  175. ?>