PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/system/application/controllers/gallery.php

https://github.com/stoat/BACAT
PHP | 253 lines | 209 code | 35 blank | 9 comment | 57 complexity | 822d96ee01d5787d76cb10f8e71ff6b1 MD5 | raw file
  1. <?php
  2. class Gallery extends Controller {
  3. function Gallery()
  4. {
  5. parent::Controller();
  6. $this->load->model('contact_model');
  7. $this->load->model('trail_model');
  8. $this->load->library('pagination');
  9. }
  10. function index()
  11. { $menu='<div id="menu">
  12. <ul id="main">
  13. <li class="current_page_item"><a href="/bacat">Home</a></li>
  14. <li><a href="arts">Arts</a></li>
  15. <li><a href="community">Community</a></li>
  16. <li><a href="gardens">Gardens</a></li>
  17. <li><a href="trails">Trails</a></li>
  18. <li><a href="about">About Us</a></li>
  19. <li><a href="contact">Contact Us</a></li>
  20. </ul>
  21. <ul id="feed">
  22. <li><a href="#">Flickr</a></li>
  23. <li><a href="#">Comments RSS</a></li>
  24. </ul>
  25. </div>';
  26. $pageData= array();
  27. $trails=$this->trail_model->gettrails();
  28. $this->config();
  29. $pageData['trails']=$trails;
  30. $pageData['menu']=$menu;
  31. $this->load->view('vw_gallery',$pageData);
  32. }
  33. function config()
  34. {
  35. // var galconfig array();
  36. //Define the folder where your photos will be placed on you server.
  37. //Relative to the path you place the galery index.php
  38. $gallerypath="images"; //EX. images or ../gallery/images no trailing slash needed
  39. $thumbpath="imagethumbs"; //EX. images or ../gallery/images no trailing slash needed
  40. $transitionspeed="500"; //How fast you want the animations to render
  41. $fadespeed="300"; //How fast you want the photos to fade in and out
  42. $users[0]="username_here"; //Username for accessing image uploader
  43. $passw[0]="password"; //Password to access image uploader
  44. }
  45. function getImages($path, $galleryName) {
  46. $files = array();
  47. $fileNames = array();
  48. $i = 0;
  49. if (is_dir($path)) {
  50. if ($dh = opendir($path)) {
  51. while (($file = readdir($dh)) !== false) {
  52. if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
  53. $fullpath = $path . "/" . $file;
  54. $fkey = strtolower($file);
  55. while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
  56. $a = stat($fullpath);
  57. $files[$fkey]['size'] = $a['size'];
  58. if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
  59. else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
  60. else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
  61. else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
  62. $files[$fkey]['name'] = $file;
  63. $files[$fkey]['type'] = filetype($fullpath);
  64. $fileNames[$i++] = $fkey;
  65. }
  66. closedir($dh);
  67. } else die ("Cannot open directory: $path");
  68. } else die ("Path is not a directory: $path");
  69. sort($fileNames,SORT_STRING);
  70. $sortedFiles = array();
  71. $i = 0;
  72. $photos = array();
  73. foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
  74. echo "var $galleryName = new Array() \n";
  75. $j = 0;
  76. foreach ($sortedFiles as $file) {
  77. // get image sizes
  78. list($width, $height, $type, $attr) = getimagesize($path."/".$file[name], $info);
  79. $size = $file[sizetext];
  80. $iptc = iptcparse($info["APP13"]);
  81. // iptc info
  82. $iptc = iptcparse($info["APP13"]);
  83. $title = $iptc['2#005'][0];
  84. $description = $iptc['2#120'][0];
  85. $description = str_replace("\r", "<br/>", $description);
  86. $description = addslashes($description);
  87. $keywords = $iptc['2#025'][0];
  88. $author = $iptc['2#080'][0];
  89. $copyright = $iptc['2#116'][0];
  90. array_push($photos, $width);
  91. array_push($photos, $height);
  92. echo "$galleryName";echo"[".$j."]=['".$path."/".$file[name]."', '".$width."', '".$height."', '".$size."', '".$title."', '".$author."', '".$copyright."', '".$description."', '".$j."']\n";
  93. $j++;
  94. }
  95. echo "\n";
  96. echo "var currentwidth=".$photos[0].";\n";
  97. echo "var currentheight=".$photos[1].";";
  98. echo "\n";
  99. }
  100. function getfirstimage($path, $galleryName) {
  101. $files = array();
  102. $fileNames = array();
  103. $i = 0;
  104. if (is_dir($path)) {
  105. if ($dh = opendir($path)) {
  106. while (($file = readdir($dh)) !== false) {
  107. if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
  108. $fullpath = $path . "/" . $file;
  109. $fkey = strtolower($file);
  110. while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
  111. $a = stat($fullpath);
  112. $files[$fkey]['size'] = $a['size'];
  113. if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
  114. else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
  115. else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
  116. else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
  117. $files[$fkey]['name'] = $file;
  118. $files[$fkey]['type'] = filetype($fullpath);
  119. $fileNames[$i++] = $fkey;
  120. }
  121. closedir($dh);
  122. } else die ("Cannot open directory: $path");
  123. } else die ("Path is not a directory: $path");
  124. sort($fileNames,SORT_STRING);
  125. $sortedFiles = array();
  126. $i = 0;
  127. $photoarray = array();
  128. $photoinfo = array();
  129. foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
  130. echo'<div id="imgloader">';
  131. $j=0;
  132. foreach ($sortedFiles as $file) {
  133. // get image sizes
  134. list($width, $height, $type, $attr) = getimagesize("$path/$file[name]", $info);
  135. $size = $file[sizetext];
  136. $iptc = iptcparse($info["APP13"]);
  137. // iptc info
  138. $iptc = iptcparse($info["APP13"]);
  139. $title = $iptc['2#005'][0];
  140. $description = $iptc['2#120'][0];
  141. $description = str_replace("\r", "<br/>", $description);
  142. $description = addslashes($description);
  143. $keywords = $iptc['2#025'][0];
  144. $author = $iptc['2#080'][0];
  145. $copyright = $iptc['2#116'][0];
  146. array_push($photoarray, '<img src="'.$path.'/'.$file[name].'" width="'.$width.'" height="'.$height.'" alt="'.$title.'" />');
  147. array_push($photoinfo, $title);
  148. array_push($photoinfo, $author);
  149. array_push($photoinfo, $copyright);
  150. array_push($photoinfo, $description);
  151. }
  152. echo ' </div>
  153. <div id="iptc_info">
  154. <div class="iptc_left"><br/><br/>
  155. Title <br/>
  156. Author <br/>
  157. Copyright <br/><br/>
  158. Description <br/><br/>
  159. </div>
  160. <div class="iptc_right"><br/><br/>
  161. '.$photoinfo[0].'<br/>
  162. '.$photoinfo[1].'<br/>
  163. '.$photoinfo[2].'<br/><br/>
  164. '.$photoinfo[3].'<br/><br/>
  165. </div>
  166. </div>
  167. ';
  168. }
  169. function getthumbnailimages($path, $galleryName, $thumbnailpath) {
  170. $files = array();
  171. $fileNames = array();
  172. $i = 0;
  173. if (is_dir($path)) {
  174. if ($dh = opendir($path)) {
  175. while (($file = readdir($dh)) !== false) {
  176. if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
  177. $fullpath = $path . "/" . $file;
  178. $fkey = strtolower($file);
  179. while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
  180. $a = stat($fullpath);
  181. $files[$fkey]['size'] = $a['size'];
  182. if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
  183. else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
  184. else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
  185. else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
  186. $files[$fkey]['name'] = $file;
  187. $files[$fkey]['type'] = filetype($fullpath);
  188. $fileNames[$i++] = $fkey;
  189. }
  190. closedir($dh);
  191. } else die ("Cannot open directory: $path");
  192. } else die ("Path is not a directory: $path");
  193. sort($fileNames,SORT_STRING);
  194. $sortedFiles = array();
  195. $i = 0;
  196. $thumbs = array();
  197. foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
  198. $j=0;
  199. foreach ($sortedFiles as $file) {
  200. // get image sizes
  201. list($width, $height, $type, $attr) = getimagesize("$path/$file[name]", $info);
  202. $size = $file[sizetext];
  203. $iptc = iptcparse($info["APP13"]);
  204. // iptc info
  205. $iptc = iptcparse($info["APP13"]);
  206. $title = $iptc['2#005'][0];
  207. $description = $iptc['2#120'][0];
  208. $description = str_replace("\r", "<br/>", $description);
  209. $description = addslashes($description);
  210. $keywords = $iptc['2#025'][0];
  211. $author = $iptc['2#080'][0];
  212. $copyright = $iptc['2#116'][0];
  213. 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>');
  214. echo $thumbs[$j];
  215. $j++;
  216. }
  217. }
  218. }