Advertisement
Guest User

Untitled

a guest
Jun 4th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.04 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Site Background Slider
  4. Plugin URI: http://www.presspixels.com/release/background-slider/
  5. Description: <a href="http://www.presspixels.com">Press Pixels</a> <a href="http://www.presspixels.com/release/background-slider/">Site Background Slider</a>  for WordPress adds <strong>Fullscreen Image Slideshows to your WebSite Background</strong>. Images are read from a specified folder, a selection of 8 different texture effects can be overlayed onto the images and the transition time between images can also be set. Settings can be found under your <strong>Appearance Menu</strong>!
  6. Version: 1.0.8
  7. Author: Lumo & Skashi @ Press Pixels
  8. Author URI: http://www.presspixels.com
  9.  
  10. License: GPL2 - http://www.gnu.org/licenses/gpl.txt
  11.  
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program; if not, write to the Free Software
  24. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  25. */
  26.  
  27. // Make sure we don't expose any info if called directly!
  28. if ( !function_exists( 'add_action' ) ) {
  29.     echo "Hi there! I'm just a plugin, not much I can do when called directly.";
  30.     exit;
  31. }
  32.  
  33. // Version Tracking
  34. define( 'SBS_VERSION', '1.0.8' );
  35.  
  36. // If Admin Area, add administration options page
  37. if ( is_admin() ) require_once( dirname( __FILE__ ) . '/admin.php' );
  38.  
  39. // Class Function to filter and remove generator
  40. class SiteBackgroundSlider {
  41.    
  42.     // Add JavaScript Files Correctly and Pass Variables
  43.     public function javaScriptFiles() {
  44.         global $wp_query;
  45.         $use_jquery            = get_option( 'sbs_use_jquery', '1' );
  46.         if( $use_jquery ) {
  47.             wp_deregister_script('jquery');
  48.             wp_register_script('jquery', ("http://code.jquery.com/jquery-latest.min.js"), false, '');
  49.         }
  50.         wp_register_script( 'jQueryNoConflict',  WP_PLUGIN_URL. "/site-background-slider/assets/jquery.noconflict.js");
  51.         wp_register_script( 'jQueryVegas',  WP_PLUGIN_URL. "/site-background-slider/assets/jquery.vegas.js");
  52.         if( $use_jquery ) { wp_enqueue_script( 'jquery' ); }
  53.         wp_enqueue_script( 'jQueryNoConflict' );
  54.         wp_enqueue_script( 'jQueryVegas' );
  55.         $resize_images = get_option( 'sbs_resize_images', '1' );
  56.         wp_localize_script( 'jQueryVegas', 'jQueryVegasVars', array('ResizeImages' => $resize_images ) );
  57.     }
  58.    
  59.     // Set and build the background slider javascript string
  60.     public function setBackgroundSlider() {
  61.         global $wp_query;
  62.         $use_jquery            = get_option( 'sbs_use_jquery', '1' );
  63.         $show_load_icon        = get_option( 'sbs_show_load_icon', '1' );
  64.         $bg_delay              = get_option( 'sbs_bg_delay', '3000' );
  65.         $bg_timer              = get_option( 'sbs_bg_timer', '10000' );
  66.         $img_base_path_string  = get_option( 'sbs_img_base_path_string', 'images' );
  67.         $shuffle_images        = get_option( 'sbs_shuffle', '0' );
  68.         $overlay_image         = get_option( 'sbs_overlay_image', 'overlay-08.png' );
  69.         $i                     = 0;
  70.         $img_base_path         = get_bloginfo( 'wpurl' )."/{$img_base_path_string}";
  71.         $files                 = glob( str_replace( "\\", "/", ABSPATH."$img_base_path_string/*" ) );
  72.         $extension_path        = plugins_url()."/site-background-slider";
  73.         $js_add                = $js_bg = $js_preload = $js = "";
  74.         $loading               = $show_load_icon == 1 ? "" : ", loading: false";
  75.         $overlay               = get_option( 'sbs_show_overlay', '1' );
  76.         $justhome              = get_option( 'sbs_just_home', '0' );
  77.        
  78.         $just_home = (bool)( get_option('sbs_just_home', '1') == 1 ? true : false );
  79.         var_dump(is_home());
  80.         if (($just_home && is_home()) || !$just_home) {
  81.        
  82.             if( $overlay ) {
  83.                 $overlay_txt = "
  84.                         ('overlay', {
  85.                         src:'{$extension_path}/assets/images/overlay/{$overlay_image}'
  86.                         })
  87.                         ";
  88.             } else $overlay_txt = "";
  89.            
  90.             if( is_array($files) ) {
  91.                 if( $shuffle_images == 1 ) shuffle($files);
  92.                 foreach( $files as $file ) {
  93.                     $filename     = explode( "/", $file );
  94.                     $filename     = $filename[sizeof($filename)-1];
  95.                     $js_bg       .= "{ src:'{$img_base_path}/{$filename}', fade:{$bg_delay}, delay:{$bg_timer} {$loading} },\n";
  96.                     $js_preload  .= "preloadImg('{$img_base_path}/{$filename}');\n\n";
  97.                     $i++;
  98.                 }
  99.                 $js .= "
  100.                         <script type=\"text/javascript\">
  101.                         jQuery(document).ready(function(){
  102.                         jQuery.vegas('slideshow', {
  103.                         backgrounds:[
  104.                         $js_bg
  105.                         ]
  106.                         })$overlay_txt;
  107.                         });
  108.                         function preloadImg(imgPath) {
  109.                         preloadImg = new Image();
  110.                         preloadImg.src = imgPath;
  111.                         }
  112.                         </script>
  113.                         <style type=\"text/css\">body > div { position: relative; } .vegas-loading { width: 100px; height: 100px; background: url($extension_path/assets/images/loader.gif) left bottom no-repeat; position: absolute; top: 20px; left: 20px; z-index: 131313}</style>
  114.                         ";
  115.                 echo $js;
  116.                 }
  117.             }
  118.         }
  119.    
  120.     public function setBackLink() {
  121.         echo '<p class="pressback" style="position: fixed;bottom: 5px;left: 3px;font-size: 12px;font-weight: normal;letter-spacing: 1px; normal 13px/28px sans-serif; padding:0px 5px; margin: 0px;"><a style="color: #CCC;" href="http://www.presspixels.com">Press Pixels</a><br /><a style="color: #CCC;" href="http://www.presspixels.com/release/background-slider/">Background Slider</a></p>';
  122.     }
  123. }
  124.  
  125. add_action('init', 'sbs_run');
  126.  
  127. function sbs_run() {
  128.     if ( !is_admin() ) {
  129.         add_action('wp_enqueue_scripts', array('SiteBackgroundSlider', 'javaScriptFiles'));
  130.         add_action( 'wp_head', array('SiteBackgroundSlider', 'setBackgroundSlider') );
  131.         if ( get_option( 'sbs_link', 0 ) == 1 ) {
  132.             add_action( 'get_template_part_content', array('SiteBackGroundSlider', 'setBackLink') );
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement