PageRenderTime 36ms CodeModel.GetById 3ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/lazyest-gallery/lazyest-thumbs.php

http://cartonbank.googlecode.com/
PHP | 255 lines | 184 code | 40 blank | 31 comment | 68 complexity | 9c8b1afbecea186ca45d799f6e29e20f MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, LGPL-2.1, AGPL-1.0, LGPL-3.0
  1. <?php
  2. function showThumbs() { // Builds thumbnails view page
  3. global $gallery_root, $currentdir, $file, $gallery_address, $user_level, $lg_text_domain;
  4. if (!lg_user_can_access($currentdir)) {
  5. echo "<p>";
  6. _e('You cannot browse this folder.', $lg_text_domain);
  7. echo "</p>";
  8. } else {
  9. $gallery_uri = get_option('lg_gallery_uri');
  10. // Fix for permalinks
  11. if (strlen(get_option('permalink_structure')) != 0){
  12. $gallery_uri = $gallery_uri.'?';
  13. } else {
  14. $gallery_uri = $gallery_uri.'&amp;';
  15. }
  16. // gathering pagination infos
  17. $thumbs_page = get_option('lg_thumbs_page');
  18. if($thumbs_page != 0 && isset($_GET['offset']) && is_numeric($_GET['offset'])){
  19. $offset = floor(abs(intval($_GET['offset']))/$thumbs_page)*$thumbs_page;
  20. }
  21. else{
  22. $offset = 0;
  23. }
  24. $folder_caption = clean_folder_caption($currentdir.$dir);
  25. $category = substr($currentdir, 0, (strlen($currentdir) -1));
  26. // Icons code
  27. // This section will display proper icon for each folder
  28. echo "<div class='folder_caption'>";
  29. if (is_file($gallery_root.$currentdir.$category.'.png')){
  30. $resource = imagecreatefrompng($gallery_root.$currentdir.$category.'.png');
  31. if (imagesx($resource) > get_option('lg_thumbwidth'))
  32. echo '<img src="'.get_option('siteurl').'/wp-content/plugins/lazyest-gallery/lazyest-img.php?file='.$currentdir.$category.'.png'.'&amp;thumb=1" alt="" class="icon" />&raquo; '.$folder_caption."\n";
  33. else
  34. echo '<img src="'.$gallery_address.$currentdir.$category.'.png" alt="'.$category.'" class="icon"/> &raquo; '.$folder_caption;
  35. }
  36. else if (is_file($gallery_root.$currentdir.$category.'.jpg')){
  37. $resource = imagecreatefromjpeg($gallery_root.$currentdir.$category.'.jpg');
  38. if (imagesx($resource) > get_option('lg_thumbwidth'))
  39. echo '<img src="'.get_option('siteurl').'/wp-content/plugins/lazyest-gallery/lazyest-img.php?file='.$currentdir.$category.'.jpg'.'&amp;thumb=1" alt="" class="icon" />&raquo; '.$folder_caption."\n";
  40. else
  41. echo '<img src="'.$gallery_address.$currentdir.$category.'.jpg" alt="'.$category.'" class="icon"/> &raquo; '.$folder_caption;
  42. }
  43. else if (is_file($gallery_root.$currentdir.$category.'.jpeg')){
  44. $resource = imagecreatefromjpeg($gallery_root.$currentdir.$category.'.jpeg');
  45. if (imagesx($resource) > get_option('lg_thumbwidth'))
  46. echo '<img src="'.get_option('siteurl').'/wp-content/plugins/lazyest-gallery/lazyest-img.php?file='.$currentdir.$category.'.jpeg'.'&amp;thumb=1" alt="" class="icon" />&raquo; '.$folder_caption."\n";
  47. else
  48. echo '<img src="'.$gallery_address.$currentdir.$category.'.jpeg" alt="'.$category.'" class="icon"/> &raquo; '.$folder_caption;
  49. }
  50. else if (is_file($gallery_root.$currentdir.$category.'.gif')){
  51. $resource = imagecreatefromgif($gallery_root.$currentdir.$category.'.gif');
  52. if (imagesx($resource) > get_option('lg_thumbwidth'))
  53. echo '<img src="'.get_option('siteurl').'/wp-content/plugins/lazyest-gallery/lazyest-img.php?file='.$currentdir.$category.'.gif'.'&amp;thumb=1" alt="" class="icon" />&raquo; '.$folder_caption."\n";
  54. else
  55. echo '<img src="'.$gallery_address.$currentdir.$category.'.gif" alt="'.$category.'" class="icon"/> &raquo; '.$folder_caption;
  56. }
  57. echo "</div>";
  58. // End of Icons code
  59. // Here begins thumbs table
  60. echo '<table class="lazyest_thumb_view" summary="thumbs"><tr>';
  61. $tcol_count = 1;
  62. $tcolumns = get_option('lg_thumbs_columns');
  63. $imgfiles = get_imgfiles($dir);
  64. // Sort the files
  65. if (get_option('lg_sort_alphabetically') == "TRUE")
  66. sort($imgfiles);
  67. if(isset($imgfiles)) {
  68. if($thumbs_page == 0){
  69. // no pagination, display all
  70. $end = count($imgfiles);
  71. $offset = 0;
  72. }
  73. else{
  74. $end = $thumbs_page + $offset ;
  75. if(count($imgfiles) < $end ){
  76. $end = count($imgfiles);
  77. }
  78. }
  79. // This is because XHTML compiling
  80. $currdir = str_replace(" ", "%20", $currentdir);
  81. // Main cycle
  82. for ($i = $offset; $i < $end; $i++) {
  83. $img = $imgfiles[$i];
  84. if( file_exists($gallery_root.$currentdir.'captions.xml')){
  85. $caption = clean_image_caption($img, $currentdir);
  86. }
  87. // Removing HTML tags
  88. $title = ereg_replace("<[^>]*>", "", $caption);
  89. // Tumbs Cache code
  90. if(get_option('lg_enable_cache') == "TRUE"){
  91. if(!file_exists($gallery_root.$currentdir.get_option('lg_thumb_folder').$img)) {
  92. createCache($currentdir, $img, true);
  93. }
  94. /* =============
  95. * The Right URL
  96. * ============= */
  97. // Lightbox informations
  98. $lb_enabled = get_option('lg_enable_lb_support');
  99. $lb_thumbs = get_option('lg_enable_lb_thumbs_support');
  100. $lb_force = get_option('lg_force_lb_support');
  101. // Thickbox informations
  102. $tb_enabled = get_option('lg_enable_tb_support');
  103. $tb_thumbs = get_option('lg_enable_tb_thumbs_support');
  104. $tb_force = get_option('lg_force_tb_support');
  105. // Slides' cache infos
  106. $lg_scache = get_option('lg_enable_slides_cache');
  107. // Lightbox URL
  108. if ($lb_enabled == "TRUE" && $lb_thumbs == "TRUE" && $lg_scache == "TRUE" && some_lightbox_plugin() || $lb_force == "TRUE") {
  109. $slide_folder = get_option('lg_slide_folder');
  110. if(!file_exists($gallery_root.$currentdir.$slide_folder.$img)){
  111. createCache($currentdir, $img, false);
  112. }
  113. $urlImg = str_replace(" ", "%20", $gallery_address.$currentdir.$slide_folder.$img);
  114. echo '<td><a href="'.$urlImg.'" rel="lightbox['.$currentdir.']" title="'.$title.'"><img src="'.$gallery_address.$currdir.get_option('lg_thumb_folder').$img .'" alt="'.$img.'" title="'. $title . '" /></a></td>';
  115. }
  116. // End of lightbox URL
  117. // Thickbox URL
  118. elseif ($tb_enabled == "TRUE" && $tb_thumbs == "TRUE" && $lg_scache == "TRUE" && some_thickbox_plugin() || $tb_force == "TRUE") {
  119. $slide_folder = get_option('lg_slide_folder');
  120. if(!file_exists($gallery_root.$currentdir.$slide_folder.$img)){
  121. createCache($currentdir, $img, false);
  122. }
  123. $thumb_folder = get_option('lg_thumb_folder');
  124. $xhthumbs = str_replace(" ", "%20", $currdir.$thumb_folder.$img);
  125. $xhurl = str_replace(" ", "%20", $currdir.$img);
  126. $xhslides = str_replace(" ", "%20", $currdir.$slide_folder.$img);
  127. echo '<td><a href="'.$gallery_address.$xhslides.'" class="thickbox" title="'. $title . ' "><img src="'. $gallery_address.$xhthumbs .'" alt="'.$img.'" /></a></td>';
  128. }
  129. // End of thickbox URL
  130. // Normal URL
  131. else {
  132. $thumb_folder = get_option('lg_thumb_folder');
  133. $xhthumbs = str_replace(" ", "%20", $currdir.$thumb_folder.$img);
  134. $xhurl = str_replace(" ", "%20", $currdir.$img);
  135. echo '<td><a href="'.$gallery_uri.'file='.$xhurl.'"><img src="'.$gallery_address.$xhthumbs .'" alt="'.$img.'" title="'. $title . '" /></a></td>';
  136. }
  137. /* ================
  138. * End of Right URL
  139. * ================ */
  140. $tcol_count++;
  141. }
  142. // On the fly code
  143. else {
  144. // this will prevent some unshown thumb
  145. $mem = get_option('lg_buffer_size');
  146. ini_set("memory_limit", $mem);
  147. $resource = $gallery_root.$currentdir.$img;
  148. $path = pathinfo($resource);
  149. switch(strtolower($path["extension"])){
  150. case "jpeg":
  151. case "jpg":
  152. $resource = imagecreatefromjpeg($resource);
  153. break;
  154. case "gif":
  155. $resource = imagecreatefromgif($resource);
  156. break;
  157. case "png":
  158. $resource = imagecreatefrompng($resource);
  159. break;
  160. default:
  161. break;
  162. }
  163. if (imagesx($resource) > get_option('lg_thumbwidth')){
  164. echo '<td><a href="'.$gallery_uri.'file='.$currdir.$img.'"><img src="'.get_option('siteurl').'/wp-content/plugins/lazyest-gallery/lazyest-img.php?file='.$currdir.$img.'&amp;thumb=1" alt="'.$img.'" title="'. $title . '"/></a></td>';
  165. } else {
  166. echo '<td><a href="'.$gallery_uri.'file='.$currdir.$img.'"><img src="'.$gallery_address.$currdir.$img.'" alt="'.$img.'" title="'. $title . '"/></a></td>';
  167. }
  168. $tcol_count++;
  169. }
  170. if ( $tcol_count > $tcolumns ){
  171. echo '</tr><tr>';
  172. $tcol_count = 1;
  173. }
  174. }
  175. }
  176. echo '<td></td></tr></table>';
  177. // Pagination's navigatior code
  178. if($thumbs_page != 0){
  179. $pages = ceil(sizeof($imgfiles) / $thumbs_page);
  180. echo '<div id="pagination">';
  181. if($offset > 0){
  182. echo '<a href="'.$gallery_uri.'file='.$currdir.'&amp;offset='.($offset - $thumbs_page) .'" title="previous">'. __('&laquo; Prev', $lg_text_domain) .'</a> '."\n";
  183. }
  184. if( $pages > 1){
  185. for($i = 1; $i <= $pages; $i++){
  186. if( $offset != ($i-1) * $thumbs_page )
  187. echo ' <a href="'.$gallery_uri.'file='.$currdir.'&amp;offset='. ($i-1) * $thumbs_page . '" >'. $i. '</a> ';
  188. else
  189. echo " $i ";
  190. }
  191. }
  192. if(count($imgfiles) > ($thumbs_page + $offset ) ){
  193. echo ' <a href="'.$gallery_uri.'file='.$currdir.'&amp;offset='.$end .'" title="next">'. __('Next &raquo;',$lg_text_domain) .'</a> ';
  194. }
  195. echo '</div>';
  196. }
  197. // End of Pagination's navigatior code
  198. // Admin links
  199. if (get_option('lg_enable_captions') == "TRUE") {
  200. get_currentuserinfo();
  201. if (strlen($currentdir) !=0){
  202. if ($user_level >= 8) {
  203. echo "<div class='lg_admin'>";
  204. echo "<a href='".get_option('siteurl')."/wp-admin/".LG_FLM_PAGE."&amp;captions=".$currdir."'>";
  205. echo "&raquo; ";
  206. _e("Write captions for images in ", $lg_text_domain);
  207. echo " ".substr($currentdir, 0, strlen($currentdir)-1);
  208. echo "</a>";
  209. echo "</div>";
  210. }
  211. }
  212. }
  213. }
  214. }
  215. ?>