PageRenderTime 39ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/simple-photo-gallery/classes/gallery-templates/wppg-photo-gallery-template-1.php

https://bitbucket.org/samuel-oldra/pousada-katedral-wordpress
PHP | 153 lines | 130 code | 12 blank | 11 comment | 23 complexity | 807603896c5522c5156eab62a084a578 MD5 | raw file
  1. <?php
  2. class WPPG_Gallery_Template_1
  3. {
  4. function __construct()
  5. {
  6. //NOP
  7. }
  8. function render_gallery($gallery_id)
  9. {
  10. global $wp_photo_gallery;
  11. $pagination = false; //Initialize
  12. $gallery = new WPPGPhotoGallery($gallery_id);
  13. $display_photo_details_page = $gallery->display_image_on_page;
  14. $gallery_items = WPPGPhotoGallery::getGalleryItems($gallery_id);
  15. WP_Photo_Gallery_Utility::start_buffer();
  16. ?>
  17. <link type="text/css" rel="stylesheet" href="<?php echo WP_PHOTO_URL.'/classes/gallery-templates/css/wppg-photo-gallery-template-1.css?ver='.WP_PHOTO_VERSION ?>" />
  18. <div id="wppg-gallery-display">
  19. <?php
  20. //Add Pagination if applicable
  21. if ($gallery->enable_pagination == 1){
  22. ?>
  23. <link type="text/css" rel="stylesheet" href="<?php echo WP_PHOTO_URL.'/classes/gallery-templates/css/wppg-pagination.css?ver='.WP_PHOTO_VERSION; ?>" />
  24. <?php
  25. $pagination = WPPGPhotoGallery::apply_gallery_pagination($gallery, $gallery_items);
  26. if ($pagination !== false){
  27. $gallery_items = $pagination['array'];
  28. }
  29. }
  30. foreach($gallery_items as $p)
  31. {
  32. $image_id = $p['id'];
  33. //Now let's create a PhotoProduct object for this item
  34. $wppgPhotoObj = new WPPGPhotoGalleryItem();
  35. $wppgPhotoObj->create_photo_item_by_id($image_id);
  36. $water_mark_url = '';
  37. $file_name = $wppgPhotoObj->image_file_name;
  38. $upload_dir = wp_upload_dir();
  39. $path = $wppgPhotoObj->thumb_url;
  40. if ($display_photo_details_page == 1)
  41. {
  42. $details_page_id = $wp_photo_gallery->configs->get_value('wppg_photo_details_page_id');
  43. if(empty($details_page_id)){
  44. $photo_details_page = get_page_by_path('wppg_photogallery/wppg_photo_details');
  45. if($photo_details_page == NULL){
  46. $wp_photo_gallery->debug_logger->log_debug('Gallery template 1: get_page_by_path returned NULL!',4);
  47. }
  48. $preview_page = $photo_details_page->guid;
  49. }else{
  50. $preview_page = get_permalink($details_page_id);
  51. }
  52. //Check if this gallery is password protected
  53. if(!empty($gallery->password)){
  54. //This gallery is password protected - so let's add an encoded string
  55. $encoded_str = base64_encode(WPPS_PHOTO_VIEW_AUTH_STRING);
  56. $query_params = array('gallery_id'=>$gallery_id,'image_id'=>$image_id, 'auth_key'=>$encoded_str);
  57. }else{
  58. $query_params = array('gallery_id'=>$gallery_id,'image_id'=>$image_id);
  59. }
  60. $preview_url = add_query_arg($query_params, $preview_page);
  61. $button_html = '<span class="wppg_popup_view_details_section"><a href="'.$preview_url.'"><span class="wppg-button">'.__("View Photo", "spgallery").'</span></a></span>';
  62. }
  63. else
  64. {
  65. $source_dir = $upload_dir['basedir'].'/'.WPPG_UPLOAD_SUB_DIRNAME.'/'.$gallery_id.'/';
  66. if($gallery->watermark != NULL)
  67. {
  68. //Get the gallery settings values for watermark placement, width and font size
  69. $watermark_placement = $gallery->watermark_placement;
  70. if ($watermark_placement === NULL)
  71. {
  72. $watermark_placement = '0';
  73. }
  74. $desired_width = $gallery->watermark_width;
  75. if ($desired_width == 0 || empty($desired_width))
  76. {
  77. $desired_width = '600';
  78. }
  79. $wm_font_size = $gallery->watermark_font_size;
  80. if ($wm_font_size == 0 || empty($wm_font_size))
  81. {
  82. $wm_font_size = '14';
  83. }
  84. $args = array('watermark_width' => $desired_width, 'watermark_font_size' => $wm_font_size, 'watermark_placement' => $watermark_placement);
  85. WPPGPhotoGallery::createWatermarkImage($source_dir,$source_dir,$file_name,false,$gallery->watermark, $args);
  86. $water_mark_url = $upload_dir['baseurl'].'/'.WPPG_UPLOAD_SUB_DIRNAME.'/'.$gallery_id.'/watermark_'.$file_name;
  87. $preview_url = $water_mark_url;
  88. }
  89. else
  90. {
  91. //Don't create a watermark URL if the watermark field was empty in the gallery settings. Display original image instead
  92. $preview_url = $wppgPhotoObj->image_file_url;
  93. }
  94. //$button_html = '<input type="button" value="'.__("View Image", "spgallery").'" class="gallerybutton wppg-template1-view-button" id="viewPhotoDetails_'.$wppgPhotoObj->id.'" />';
  95. $button_html = '<a href="'.$preview_url.'" class="wppg_popup wppg-template1-lb-view" id="viewPhotoDetails_'.$wppgPhotoObj->id.'">'.__("View Image", "spgallery").'</a>';
  96. }
  97. ?>
  98. <div class="item">
  99. <div class="wppg-gallery-template1-top">
  100. <div class="wppg-gallery-template1-thumb">
  101. <a class="wppg_popup" title="<?php echo $wppgPhotoObj->name ?>" href="<?php echo $preview_url ?>">
  102. <img alt="<?php echo $wppgPhotoObj->alt_text ?>" src="<?php echo $path ?>">
  103. </a>
  104. </div>
  105. </div>
  106. <div class="wppg-gallery-template1-bottom">
  107. <div class="wppg-gallery-template1-view-button">
  108. <?php echo $button_html; ?>
  109. </div>
  110. </div>
  111. </div><!-- end of .item -->
  112. <?php
  113. }//End foreach loop
  114. ?>
  115. <div class="clear"></div>
  116. <?php
  117. //Insert pagination nav bar at bottom
  118. if ($gallery->enable_pagination == 1 && $pagination !== false){
  119. ?>
  120. <div class="wppg_photo_gallery_pagination"><?php echo $pagination['panel']; ?></div>
  121. <?php
  122. }
  123. ?>
  124. </div> <!--end wppg-gallery-display div -->
  125. <?php
  126. if($display_photo_details_page == 0){
  127. //Load lightbox css file
  128. wp_enqueue_style('jquery-lightbox-css', WP_PHOTO_URL . '/js/jquery-lightbox/css/jquery.lightbox-0.5.css');
  129. //Load lightbox js files
  130. wp_enqueue_script('wppg-lb-script-js', WP_PHOTO_URL.'/js/simple_photo_gallery_js.js', array('jquery'));
  131. wp_localize_script('wppg-lb-script-js', 'WPPG_LIGHTBOX_JS',
  132. array('imgLoading'=>WP_PHOTO_URL.'/js/jquery-lightbox/images/lightbox-ico-loading.gif',
  133. 'imgbtnPrev'=>WP_PHOTO_URL.'/js/jquery-lightbox/images/lightbox-btn-prev.gif',
  134. 'imgbtnNext'=>WP_PHOTO_URL.'/js/jquery-lightbox/images/lightbox-btn-next.gif',
  135. 'imgBlank'=>WP_PHOTO_URL.'/js/jquery-lightbox/images/lightbox-blank.gif',
  136. 'imgbtnClose'=>WP_PHOTO_URL.'/js/jquery-lightbox/images/lightbox-btn-close.gif'));
  137. }
  138. $output = WP_Photo_Gallery_Utility::end_buffer_and_collect();
  139. return $output;
  140. }
  141. }