Advertisement
nlozovan

Untitled

Jun 23rd, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.70 KB | None | 0 0
  1. SEARCH FOR THIS FUNCTION:
  2.  
  3. static function get_post_img_mosaic($post_id){
  4.  
  5. EDIT THE FUNCTION (hole function):
  6.  
  7. /*generates content for gallery slider when 'mosaic' mode is set*/
  8. static function get_post_img_mosaic($post_id){
  9.  
  10.  
  11. /*check the meta data where the attached image ids are stored*/
  12.  
  13. $post_image_gallery_meta = get_post_meta( $post_id, '_post_image_gallery', true );
  14.  
  15. if(strlen($post_image_gallery_meta) && 'Array' != $post_image_gallery_meta){
  16. $product_image_gallery = $post_image_gallery_meta;
  17.  
  18. $img_id_array = array_filter( explode( ',', $product_image_gallery ) );
  19. }else{
  20. //backward compatibility with version prev to 1.1
  21. $attachet_gallery_ids = meta::get_meta( $post_id, 'imagesattached' );
  22.  
  23. if(isset($attachet_gallery_ids['img_ids']) && strlen($attachet_gallery_ids['img_ids'])){
  24. /*mata is stored as a string of numbers separated by comma (ex: 909,914,913,912,911,910,908)*/
  25. $img_id_array = explode(',', $attachet_gallery_ids['img_ids']); //create an array from the string
  26.  
  27.  
  28. }
  29. }
  30.  
  31. if(isset($img_id_array) && is_array($img_id_array)){
  32. foreach ($img_id_array as $value) {
  33. $attachments[$value] = $value; // create attachments array in the format that will work for us
  34. }
  35. }
  36.  
  37.  
  38. if(!isset($attachments)){ // if no meta is attached to the post then the gallery wil be created from attached images
  39. $attachments = get_children(array('post_parent' => $post_id,
  40. 'post_status' => 'inherit',
  41. 'post_type' => 'attachment',
  42. 'post_mime_type' => 'image',
  43. 'order' => 'ASC',
  44. 'orderby' => 'menu_order ID'));
  45. }
  46.  
  47. if( isset($attachments) && count($attachments) > 0){
  48. ?>
  49. <div class=" row mosaic-view thumb-view gallery-mosaic-view">
  50.  
  51. <div class="twelve columns">
  52. <div class="row masonry for-mosaic" >
  53. <?php
  54. $counter = 0;
  55. $pretty_colection_id = mt_rand(0,99999);
  56. foreach($attachments as $att_id => $attachment) {
  57. $options = array('post_number' => $counter);
  58.  
  59.  
  60. $attachment_info = get_post($att_id); //deb::e($attachment_info );
  61. if( is_object($attachment_info) && isset($attachment_info->post_excerpt)){
  62. $caption = $attachment_info->post_content;
  63. }else{
  64. $caption = '';
  65. }
  66.  
  67. $img_title = $attachment_info -> post_title;
  68.  
  69. //------------------------------------
  70. $default_options = array('post_number' => 0); /*default options*/
  71.  
  72. extract( $options ); /*extract the passed options*/
  73. extract( $default_options, EXTR_PREFIX_SAME, "default"); /* eXtract default options with 'default' prefix in case the option with the same name was already passed */
  74.  
  75.  
  76.  
  77. $position_info = post::get_mosaicinfo_by_order($post_number % 12);
  78. $container_width = $position_info['width'];
  79. $thumb_size = $position_info['thumb_size'];
  80. $container_class = $position_info['container_class'];
  81.  
  82. if( trim($container_class) == 'large-mosaic-elem'){
  83. $thumb_width = 720;
  84. $thumb_height = 720;
  85. $thumb_no_img = 'thumb-transparent-img.png';
  86. }elseif(trim($container_class) == 'long-mosaic-elem'){
  87. $thumb_width = 340;
  88. $thumb_height = 720;
  89. $thumb_no_img = 'no-img-long.png';
  90. }else{
  91. $thumb_width = 340;
  92. $thumb_height = 340;
  93. $thumb_no_img = 'thumb-transparent-img.png';
  94. }
  95.  
  96. $no_img_class = '';
  97.  
  98. if(options::logic( 'blog_post' , 'disable_hover_effect' )){
  99. $disable_hover_effect = '';
  100. } else { $disable_hover_effect = 'hovermove'; }
  101.  
  102. $custom_fields = get_post_custom($att_id);
  103. //deb::e($custom_fields);
  104. $custom_link_db = '';
  105. $custom_link_tab = '';
  106. $tab = '';
  107. if (isset($custom_fields['custom_link'])) {
  108. $custom_link_db = $custom_fields['custom_link'][0];
  109. $custom_link_tab = $custom_fields['custom_link_tab'][0];
  110.  
  111. $tab = $custom_link_tab == 'yes' ? 'target="_blank"' : '';
  112. }
  113.  
  114. ?>
  115. <div class="masonry_elem <?php echo $container_width; ?> columns">
  116. <div class="thumb-elem <?php echo $disable_hover_effect?> <?php echo $container_class; ?> large-mosaic-elem">
  117.  
  118. <header class="thumb-elem-header">
  119. <div class="featimg ">
  120.  
  121. <?php
  122.  
  123.  
  124. $size = 'grid_small';
  125.  
  126. $img_url = wp_get_attachment_url( $att_id ,'full'); //get img URL
  127.  
  128. $img_src = aq_resize( $img_url, get_aqua_size($thumb_size), get_aqua_size($thumb_size, 'height'), true, false); //crop img
  129. //====================
  130. //$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ) , $thumb_size );
  131.  
  132. $img_width = $img_src[1];
  133. $img_height = $img_src[2];
  134.  
  135. if($img_width != $thumb_width || $img_height != $thumb_height){
  136. /*if the image doesn't have the requested size then we will add a transparent square image and will give position absolute to the original image*/
  137. $original_img_style = 'style="position:absolute"';
  138. }else{
  139. $original_img_style = '';
  140. }
  141. ?>
  142. <img class="the-thumb" src="<?php echo $img_src[0]; ?>" alt="" style="position:absolute" />
  143. <img src="<?php echo get_template_directory_uri() ?>/images/<?php echo $thumb_no_img; ?>" alt="<?php echo $caption; ?>" />
  144. <div class="image-title"><?php echo $img_title; ?></div>
  145. <div class="image-description"><?php echo $caption; ?></div>
  146.  
  147. <?php if( options::logic( 'blog_post' , 'enb_lightbox' ) && $custom_link_db == ''){ ?>
  148. <div class="zoom-image">
  149. <a href="<?php echo $img_url; ?>" data-rel="prettyPhoto[<?php echo $pretty_colection_id; ?>]" title="<?php echo $img_title.' - '.$caption; ?>">&nbsp;</a>
  150. </div>
  151. <?php } else if ($custom_link_db != '') { ?>
  152.  
  153. <div class="custom-link">
  154. <div class="icon-link"></div>
  155. <a href="<?php echo $custom_link_db;?>" <?php echo $tab; ?> >&nbsp;</a>
  156. </div>
  157.  
  158. <?php } ?>
  159.  
  160.  
  161. </div>
  162. </header>
  163.  
  164. </div>
  165. </div>
  166. <?php
  167.  
  168.  
  169. $counter ++;
  170. }
  171.  
  172. ?>
  173. </div>
  174. </div>
  175. </div>
  176. <?php
  177. }else{
  178. _e('This gallery has no images attached', 'cosmotheme');
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement