Advertisement
Guest User

Untitled

a guest
Feb 12th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.72 KB | None | 0 0
  1. function get_background(){
  2.     //return false;
  3.     ?>
  4.     <?php
  5.     if(is_tax()){
  6.         $term = get_term_by('slug', get_query_var("project_category") , 'project_category');
  7.         $term_id = $term->term_id;
  8.         $bg_image = get_field("background_image","project_category_{$term_id}");
  9.         $bg_video = get_field("background_video","project_category_{$term_id}");
  10.     }
  11.     elseif(is_category()){
  12.         $term = get_term_by('slug', get_query_var("category_name") , 'category');
  13.         $term_id = $term->term_id;
  14.         $bg_image = get_field("background_image","category_{$term_id}");
  15.         $bg_video = get_field("background_video","category_{$term_id}");
  16.     }elseif(is_tag()){
  17.         $term = get_term_by('slug', get_query_var("tag") , 'post_tag');
  18.         $term_id = $term->term_id;
  19.         $bg_image = get_field("background_image","post_tag_{$term_id}");
  20.         $bg_video = get_field("background_video","post_tag_{$term_id}");
  21.     }
  22.     else{
  23.         $bg_image = get_field("background_image");
  24.         $bg_video = get_field("background_video");
  25.     }
  26.     if($bg_video):
  27.     ?>
  28.     <script>
  29.         try {
  30.             jQuery("a.mute").hide();
  31.             audioplayer.pause();
  32.         }
  33.         catch (err) {
  34.  
  35.         }
  36.     </script>
  37.     <?php
  38.     else:
  39.     ?>
  40.     <script>
  41.         try {
  42.             jQuery("a.mute").show();
  43.             audioplayer.play();
  44.         }
  45.         catch (err) {
  46.  
  47.         }
  48.     </script>
  49.     <?php
  50.     endif;
  51.  
  52.     if($bg_image || $bg_video):
  53.     ?>
  54.     <script>
  55.     if(typeof vars !== "undefined"){
  56.         vars.is_paused = true;
  57.     }
  58.     </script>
  59.     <style>
  60.     #supersized{
  61.         z-index:-20 !important;
  62.     }
  63.     #overlay_img{
  64.         width: 100%;
  65.         height: 100%;
  66.         z-index: -19 !important;
  67.         background: url("<?php echo $bg_image; ?>") no-repeat fixed center center;
  68.         background-size:cover;
  69.         position: fixed;
  70.         top: 0;
  71.         left: 0;
  72.         filter: progid:DXImageTransform.Microsoft.AlphaImageLoader
  73.             (src='<?php echo $bg_image; ?>',sizingMethod='scale');
  74.     }
  75.     #overlay_video{
  76.         width: 100%;
  77.         height: 100%;
  78.         z-index: -19 !important;
  79.         position: fixed;
  80.         top: 0;
  81.         left: 0;
  82.     }
  83.     #overlay_video iframe{
  84.         width: 100%;
  85.         height: 100%;
  86.     }
  87.     </style>
  88.     <?php if($bg_image): ?>
  89.     <div id="overlay_img"></div>
  90.     <?php endif; ?>
  91.  
  92.     <?php if($bg_video): ?>
  93.     <div id="overlay_video">
  94.     <div id="ov_vid"></div>
  95.     <?php
  96.         $url = $bg_video;
  97.         /*Youtube*/
  98.         $youtube = "";
  99.         preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $youtube);
  100.         /*Vimeo*/
  101.         $vimeo = "";
  102.         sscanf(parse_url($url, PHP_URL_PATH), '/%d', $vimeo);
  103.         if($youtube){
  104.         ?>
  105.             <!--<iframe id="awsome" title="YouTube video player" class="youtube youtube_bg" width ="920" height="420" src="http://www.youtube.com/embed/<?php echo $youtube[0]; ?>?playlist=<?php echo $youtube[0]; ?>&enablejsapi=1&autoplay=1&controls=0&loop=1&showinfo=0&version=3&mute=1" frameborder="0" wmode="Opaque"></iframe>-->
  106.             <script type="text/javascript">
  107.                 function onYouTubeIframeAPIReady() {
  108.                     player = new YT.Player('ov_vid', {
  109.                         height: '390',
  110.                         width: '640',
  111.                         videoId: '<?php echo $youtube[0]; ?>',
  112.                         playerVars: { 'autoplay': 1, 'controls': 0, 'playlist': '<?php echo $youtube[0]; ?>', 'loop': 1, 'showinfo': 0, 'wmode': 'transparent' },
  113.                         events: {
  114.                             'onReady': onPlayerReady
  115.                         }
  116.                     });
  117.                 }
  118.                
  119.                 function onPlayerReady(event) {
  120.                     <?php if(get_field("mute_video")): ?>
  121.                     event.target.mute();
  122.                     <?php endif; ?>
  123.                 }
  124.                
  125.                 onYouTubeIframeAPIReady();
  126.             </script>
  127.         <?php
  128.         }
  129.         if($vimeo){
  130.         ?>
  131.             <iframe class="vimeo" src="http://player.vimeo.com/video/<?php echo $vimeo; ?>?api=1" width="920" height="420" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
  132.             <script type="text/javascript">
  133.                 var f = jQuery('iframe.vimeo');
  134.                 url = f.attr('src').split('?')[0];
  135.                 // Listen for messages from the player
  136.                 if (window.addEventListener) {
  137.                     window.addEventListener('message', onMessageReceived, false);
  138.                 }
  139.                 else {
  140.                     window.attachEvent('onmessage', onMessageReceived, false);
  141.                 }
  142.                 function post(action, value) {
  143.                     var data = { method: action };
  144.    
  145.                     if (value) {
  146.                         data.value = value;
  147.                     }
  148.    
  149.                     f[0].contentWindow.postMessage(JSON.stringify(data), url);
  150.                 }
  151.                 // Handle messages received from the player
  152.                 function onMessageReceived(e) {
  153.                     var data = JSON.parse(e.data);
  154.  
  155.                     switch (data.event) {
  156.                         case 'ready':
  157.                             onReady();
  158.                             break;
  159.                     }
  160.                 }
  161.                 function onReady() {
  162.                     post("play","");
  163.                     post("setLoop","1");
  164.                     <?php if(get_field("mute_video")): ?>
  165.                     post("setVolume","0");
  166.                     <?php endif; ?>
  167.                 }
  168.             </script>
  169.         <?php
  170.         }
  171.     ?>
  172.     </div>
  173.     <?php endif; ?>
  174.    
  175.     <?php else: ?>
  176.     <script>
  177.     if(typeof vars !== "undefined"){
  178.         vars.is_paused = false;
  179.     }
  180.     </script>
  181.     <?php endif; ?>
  182.     <?php
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement