Advertisement
imath

Ajouter un effet lighbox à BP Album

Jun 27th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.37 KB | None | 0 0
  1. <?php
  2. /*** 1) Dans le functions.php du thème actif ***/
  3.  
  4. /* d'abord on charge thickbox si on est sur la page listant les photos du membre */
  5. function thomas_load_thickbox() {
  6.     wp_enqueue_style('thickbox');
  7.     wp_enqueue_script('jquery');
  8.     wp_enqueue_script('thickbox');
  9.     // on ajoute un hook à wp_footer dés maintenant car on est sûr d'être sur le bon screen
  10.     add_action('wp_footer', 'thomas_override_bp_album');
  11. }
  12. add_action('bp_album_screen_pictures', 'thomas_load_thickbox');
  13.  
  14. /* ici on va ajouter un champ de test car BuddyPress Album ne référence pas les IDs des photos dans le template */
  15. function thomas_build_pattern( $pattern ){
  16.     $extension = explode( ".", $pattern );
  17.     $indice_ext = count( $extension ) - 1;
  18.     $nbcar_ext = strlen( $extension[$indice_ext] ) + 1;
  19.     return substr( $pattern,0, strlen( $pattern ) - $nbcar_ext );
  20. }
  21.  
  22. /* comme on a pas de hook, on surcharge le client ! */
  23. function thomas_override_bp_album() {
  24.     global $pictures_template;
  25.    
  26.     $json_pics = array();
  27.    
  28.     foreach( $pictures_template->pictures as $pics ) {
  29.         //en mettant un attribut rel="diapo" juste après la class thickbox, on peut même faire un diaporama
  30.         $json_pics[]= array( 'pattern' => thomas_build_pattern( $pics->pic_org_url ), 'html' => '<a href="'.site_url( $pics->pic_org_url ).'" class="thickbox">Zoom</a>' );
  31.     }
  32.    
  33.     $json_pics = json_encode($json_pics);
  34.     ?>
  35.         <script type="text/javascript">
  36.         var jsonpics = <?php echo $json_pics;?>
  37.        
  38.         function goodHtml( search ){
  39.             var trouver = -1;
  40.             for( i=0; i < jsonpics.length; i++ ){
  41.                 if( search.indexOf( jsonpics[i]['pattern'] ) !=-1 )
  42.                     trouver = jsonpics[i]['html'];
  43.             }
  44.            
  45.             return trouver;
  46.         }
  47.        
  48.         jQuery('document').ready(function($){
  49.             $('.picture-thumb-box').each(function(){
  50.                 test = goodHtml( $(this).find('.picture-thumb img').attr('src') );
  51.                 if( test != -1 )
  52.                     $(this).append(test);
  53.             });
  54.         });
  55.         </script>
  56.     <?php
  57. }
  58.  
  59. /*** 2) Dans le footer.php du thème actif juste au-dessus de la function wp_footer() ***/
  60. ?>
  61. <script type="text/javascript">
  62.     if ( typeof tb_pathToImage != 'string' )
  63.     {
  64.         var tb_pathToImage = "<?php echo site_url('/wp-includes/js/thickbox/loadingAnimation.gif');?>";
  65.     }
  66.     if ( typeof tb_closeImage != 'string' )
  67.     {
  68.         var tb_closeImage = "<?php echo site_url('/wp-includes/js/thickbox/tb-close.png');?>";
  69.     }
  70. </script>
  71. <?php
  72. /*** et voilà ! ***/
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement