Guest User

Modification over wordpress plugin Aboozé Slideshow

a guest
Aug 2nd, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.47 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Aboozé Slideshow
  4. Plugin URI: http://wordpress.org/extend/plugins/abooze-slideshow/
  5. Description: Easily upload images with links to display a nice slideshow on your website. To manage, Go to <strong>Media-> Aboozé Slideshow</strong>. To display the slideshow, add: &lt;?php if (function_exists('ab_show')){ ab_show(); } ?&gt; in your template.
  6. Version: 33.0
  7. Author: Aboobacker Omar
  8. Author URI: http://www.aboobacker.com/
  9. This plugin inherits the GPL license from it's parent system, WordPress., customized from WP-Cycle. Thanks Nathan Rice.
  10. Modified By: Ronny 10th Jul 2012
  11. Added:
  12.     Control delay_speed and fade_speed in GUI
  13.     Fix fade out
  14.     Add ability to put a page/post id instead of url. This is replaced by the permalink in the website.
  15.     Very useful when moving a website - no need to update links.
  16. */
  17. $wp_cycle_defaults = apply_filters('wp_cycle_defaults', array(
  18.     'rotate' => 1,
  19.     'effect' => 'fade', // fade, wipe, scrollUp, scrollDown, scrollLeft, scrollRight, cover, shuffle
  20.     'delay' => 3,
  21.     'duration' => 1,
  22.     'img_width' => 900,
  23.     'img_height' => 450,
  24.     'delay_speed' => 5000,
  25.     'fade_speed' => 1800,
  26.     'div' => 'slideShowItems'
  27. ));
  28. //  pull the settings from the db
  29. $wp_cycle_settings = get_option('wp_cycle_settings');
  30. $wp_cycle_images = get_option('wp_cycle_images');
  31. //  fallback
  32. $wp_cycle_settings = wp_parse_args($wp_cycle_settings, $wp_cycle_defaults);
  33. //  this function registers our settings in the db
  34. add_action('admin_init', 'wp_cycle_register_settings1');
  35. function wp_cycle_register_settings1() {
  36.     register_setting('wp_cycle_images', 'wp_cycle_images', 'wp_cycle_images_validate1');
  37.     register_setting('wp_cycle_settings', 'wp_cycle_settings', 'wp_cycle_settings_validate1');
  38. }
  39. //  this function adds the settings page to the Appearance tab
  40. add_action('admin_menu', 'add_wp_cycle_menu1');
  41. function add_wp_cycle_menu1() {
  42.     add_submenu_page('upload.php', 'Aboozé Slideshow Settings', 'Aboozé Slideshow', 'upload_files', 'abooze-slideshow', 'wp_cycle_admin_page1');
  43. }
  44. //  add "Settings" link to plugin page
  45. add_filter('plugin_action_links_' . plugin_basename(__FILE__) , 'wp_cycle_plugin_action_links1');
  46. function wp_cycle_plugin_action_links1($links) {
  47.     $wp_cycle_settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'upload.php?page=abooze-slideshow' ), __('Settings') );
  48.     array_unshift($links, $wp_cycle_settings_link);
  49.     return $links;
  50. }
  51. function wp_cycle_admin_page1() {
  52.     echo '<div class="wrap">';
  53.         //  handle image upload, if necessary
  54.         if($_REQUEST['action'] == 'wp_handle_upload')
  55.             wp_cycle_handle_upload1();
  56.         //  delete an image, if necessary
  57.         if(isset($_REQUEST['delete']))
  58.             wp_cycle_delete_upload1($_REQUEST['delete']);
  59.         //  the image management form
  60.         wp_cycle_images_admin1();
  61. //  the settings management form - abooze
  62.     wp_cycle_settings_admin1();
  63.     echo '</div>';
  64. }
  65. function wp_cycle_handle_upload1() {
  66.     global $wp_cycle_settings, $wp_cycle_images;
  67.     //  upload the image
  68.     $upload = wp_handle_upload($_FILES['wp_cycle'], 0);
  69.     //  extract the $upload array
  70.     extract($upload);
  71.     //  the URL of the directory the file was loaded in
  72.     $upload_dir_url = str_replace(basename($file), '', $url);
  73.     //  get the image dimensions
  74.     list($width, $height) = getimagesize($file);
  75.     //  if the uploaded file is NOT an image
  76.     if(strpos($type, 'image') === FALSE) {
  77.         unlink($file); // delete the file
  78.         echo '<div class="error" id="message"><p>Sorry, but the file you uploaded does not seem to be a valid image. Please try again.</p></div>';
  79.         return;
  80.     }
  81.  
  82. /*
  83.     //  if the image doesn't meet the minimum width/height requirements ...
  84.     if($width < $wp_cycle_settings['img_width'] || $height < $wp_cycle_settings['img_height']) {
  85.         unlink($file); // delete the image
  86.         echo '<div class="error" id="message"><p>Sorry, but this image does not meet the minimum height/width requirements. Please upload another image</p></div>';
  87.         return;
  88.     }
  89. */
  90.  
  91.     //  if the image is larger than the width/height requirements, then scale it down.
  92.     if($width > $wp_cycle_settings['img_width'] || $height > $wp_cycle_settings['img_height']) {
  93.         //  resize the image
  94.         $resized = image_resize($file, $wp_cycle_settings['img_width'], $wp_cycle_settings['img_height'], true, 'resized');
  95.         $resized_url = $upload_dir_url . basename($resized);
  96.         //  delete the original
  97.         unlink($file);
  98.         $file = $resized;
  99.         $url = $resized_url;
  100.     }
  101.     //  make the thumbnail
  102.     $thumb_height = round((100 * $wp_cycle_settings['img_height']) / $wp_cycle_settings['img_width']);
  103.     if(isset($upload['file'])) {
  104.         $thumbnail = image_resize($file, 100, $thumb_height, true, 'thumb');
  105.         $thumbnail_url = $upload_dir_url . basename($thumbnail);
  106.     }
  107.     //  use the timestamp as the array key and id
  108.     $time = date('YmdHis');
  109.     //  add the image data to the array
  110.     $wp_cycle_images[$time] = array(
  111.         'id' => $time,
  112.         'file' => $file,
  113.         'file_url' => $url,
  114.         'thumbnail' => $thumbnail,
  115.         'thumbnail_url' => $thumbnail_url,
  116.         'image_links_to' => ''
  117.     );
  118.     //  add the image information to the database
  119.     $wp_cycle_images['update'] = 'Added';
  120.     update_option('wp_cycle_images', $wp_cycle_images);
  121. }
  122. //  this function deletes the image,
  123. //  and removes the image data from the db
  124. function wp_cycle_delete_upload1($id) {
  125.     global $wp_cycle_images;
  126.     //  if the ID passed to this function is invalid,
  127.     //  halt the process, and don't try to delete.
  128.     if(!isset($wp_cycle_images[$id])) return;
  129.     //  delete the image and thumbnail
  130.     unlink($wp_cycle_images[$id]['file']);
  131.     unlink($wp_cycle_images[$id]['thumbnail']);
  132.     //  indicate that the image was deleted
  133.     $wp_cycle_images['update'] = 'Deleted';
  134.     //  remove the image data from the db
  135.     unset($wp_cycle_images[$id]);
  136.     update_option('wp_cycle_images', $wp_cycle_images);
  137. }
  138. function wp_cycle_settings_update_check1() {
  139.     global $wp_cycle_settings;
  140.     if(isset($wp_cycle_settings['update'])) {
  141.         echo '<div class="updated fade" id="message"><p>Aboozé Slideshow Settings <strong>'.$wp_cycle_settings['update'].'</strong></p></div>';
  142.         unset($wp_cycle_settings['update']);
  143.         update_option('wp_cycle_settings', $wp_cycle_settings);
  144.     }
  145. }
  146. //  this function checks to see if we just added a new image
  147. //  if so, it displays the "updated" message.
  148. function wp_cycle_images_update_check1() {
  149.     global $wp_cycle_images;
  150.     if($wp_cycle_images['update'] == 'Added' || $wp_cycle_images['update'] == 'Deleted' || $wp_cycle_images['update'] == 'Updated') {
  151.         echo '<div class="updated fade" id="message"><p>Image(s) '.$wp_cycle_images['update'].' Successfully</p></div>';
  152.         unset($wp_cycle_images['update']);
  153.         update_option('wp_cycle_images', $wp_cycle_images);
  154.     }
  155. }
  156. function wp_cycle_images_admin1() { ?>
  157.     <?php global $wp_cycle_images; ?>
  158.     <?php wp_cycle_images_update_check1(); ?>
  159.     <h2><?php _e('Home Slideshow Images', 'wp_cycle'); ?></h2>
  160.     <table class="form-table">
  161.         <tr valign="top"><th scope="row">Upload New Image</th>
  162.             <td>
  163.             <form enctype="multipart/form-data" method="post" action="?page=abooze-slideshow">
  164.                 <input type="hidden" name="post_id" id="post_id" value="0" />
  165.                 <input type="hidden" name="action" id="action" value="wp_handle_upload" />
  166.                 <label for="wp_cycle">Select a File: </label>
  167.                 <input type="file" name="wp_cycle" id="wp_cycle" />
  168.                 <input type="submit" class="button-primary" name="html-upload" value="Upload" />
  169.             </form>
  170.             </td>
  171.         </tr>
  172.     </table><br />
  173.     <?php if(!empty($wp_cycle_images)) : ?>
  174.     <table class="widefat fixed" cellspacing="0">
  175.         <thead>
  176.             <tr>
  177.                 <th scope="col" class="column-slug">Image</th>
  178.                 <th scope="col">Image Links To (Url or page/post ID)</th>
  179.                 <th scope="col" class="column-slug">Actions</th>
  180.             </tr>
  181.         </thead>
  182.         <tfoot>
  183.             <tr>
  184.                 <th scope="col" class="column-slug">Image</th>
  185.                 <th scope="col">Image Links To (Url or page/post ID)</th>
  186.                 <th scope="col" class="column-slug">Actions</th>
  187.             </tr>
  188.         </tfoot>
  189.  
  190.         <tbody>
  191.         <form method="post" action="options.php">
  192.         <?php settings_fields('wp_cycle_images'); ?>
  193.         <?php foreach((array)$wp_cycle_images as $image => $data) : ?>
  194.             <tr>
  195.                 <input type="hidden" name="wp_cycle_images[<?php echo $image; ?>][id]" value="<?php echo $data['id']; ?>" />
  196.                 <input type="hidden" name="wp_cycle_images[<?php echo $image; ?>][file]" value="<?php echo $data['file']; ?>" />
  197.                 <input type="hidden" name="wp_cycle_images[<?php echo $image; ?>][file_url]" value="<?php echo $data['file_url']; ?>" />
  198.                 <input type="hidden" name="wp_cycle_images[<?php echo $image; ?>][thumbnail]" value="<?php echo $data['thumbnail']; ?>" />
  199.                 <input type="hidden" name="wp_cycle_images[<?php echo $image; ?>][thumbnail_url]" value="<?php echo $data['thumbnail_url']; ?>" />
  200.                 <th scope="row" class="column-slug"><img src="<?php echo $data['thumbnail_url']; ?>" /></th>
  201.                 <td><input type="text" name="wp_cycle_images[<?php echo $image; ?>][image_links_to]" value="<?php echo $data['image_links_to']; ?>" size="35" /></td>
  202.                 <td class="column-slug"><input type="submit" class="button-primary" value="Update" /> <a href="?page=abooze-slideshow&amp;delete=<?php echo $image; ?>" class="button">Delete</a></td>
  203.             </tr>
  204.         <?php endforeach; ?>
  205.         <input type="hidden" name="wp_cycle_images[update]" value="Updated" />
  206.         </form>
  207.         </tbody>
  208.     </table>
  209.     <?php endif; ?>
  210.  
  211. <?php
  212. }
  213. //////////////* Option to be added for chosing different diamensions start*///////////////
  214. //////////////////////////////////////////////////////////////////////////////////////////
  215. //  display the settings administration code
  216. function wp_cycle_settings_admin1() { ?>
  217.     <?php wp_cycle_settings_update_check1(); ?>
  218.     <h2><?php _e('Slideshow settings', 'wp-cycle'); ?></h2>
  219.     <form method="post" action="options.php">
  220.     <?php settings_fields('wp_cycle_settings'); ?>
  221.     <?php global $wp_cycle_settings; $options = $wp_cycle_settings; ?>
  222.     <table class="form-table">
  223.         <tr><th scope="row">Image Dimensions</th>
  224.         <td>Please input the width of the image rotator:<br />
  225.             <input type="text" name="wp_cycle_settings[img_width]" value="<?php echo $options['img_width'] ?>" size="4" />
  226.             <label for="wp_cycle_settings[img_width]">px</label>
  227.             <br /><br />
  228.             Please input the height of the image rotator:<br />
  229.             <input type="text" name="wp_cycle_settings[img_height]" value="<?php echo $options['img_height'] ?>" size="4" />
  230.             <label for="wp_cycle_settings[img_height]">px</label>
  231.             <br /><br />
  232.             Please input the delay speed:<br />
  233.             <input type="text" name="wp_cycle_settings[delay_speed]" value="<?php echo $options['delay_speed'] ?>" size="4" />
  234.             <label for="wp_cycle_settings[delay_speed]"> milliseconds</label>
  235.             <br /><br />
  236.             Please input the fade speed:<br />
  237.             <input type="text" name="wp_cycle_settings[fade_speed]" value="<?php echo $options['fade_speed'] ?>" size="4" />
  238.             <label for="wp_cycle_settings[fade_speed]"> milliseconds</label>
  239.         </td></tr>
  240.         <input type="hidden" name="wp_cycle_settings[update]" value="UPDATED" />
  241.     </table>
  242.     <p class="submit">
  243.     <input type="submit" class="button-primary" value="<?php _e('Save Settings') ?>" />
  244.     </form>
  245.     <!-- The Reset Option -->
  246.     <form method="post" action="options.php">
  247.     <?php settings_fields('wp_cycle_settings'); ?>
  248.     <?php global $wp_cycle_defaults; // use the defaults ?>
  249.     <?php foreach((array)$wp_cycle_defaults as $key => $value) : ?>
  250.     <input type="hidden" name="wp_cycle_settings[<?php echo $key; ?>]" value="<?php echo $value; ?>" />
  251.     <?php endforeach; ?>
  252.     <input type="hidden" name="wp_cycle_settings[update]" value="RESET" />
  253.     <input type="submit" class="button" value="<?php _e('Reset Settings') ?>" />
  254.     </form>
  255.     <!-- End Reset Option -->
  256.     </p>
  257. <?php
  258. }
  259. //////////////* Option to be added for chosing different diamensions start end*///////////////
  260. //////////////////////////////////////////////////////////////////////////////////////////
  261. function wp_cycle_settings_validate1($input) {
  262.     $input['rotate'] = ($input['rotate'] == 1 ? 1 : 0);
  263.     $input['effect'] = wp_filter_nohtml_kses($input['effect']);
  264.     $input['img_width'] = intval($input['img_width']);
  265.     $input['img_height'] = intval($input['img_height']);
  266.     //$input['div'] = wp_filter_nohtml_kses($input['div']);
  267.     return $input;
  268. }
  269. //  this function sanitizes our image data for storage
  270. function wp_cycle_images_validate1($input) {
  271.     foreach((array)$input as $key => $value) {
  272.         if($key != 'update') {
  273.             $input[$key]['file_url'] = clean_url($value['file_url']);
  274.             $input[$key]['thumbnail_url'] = clean_url($value['thumbnail_url']);
  275.             $url = isset($value['image_links_to']) ? trim($value['image_links_to']) : '';
  276.             if ($url != '')
  277.                 $input[$key]['image_links_to'] = is_numeric($url) ? $url : clean_url($url);
  278.         }
  279.     }
  280.     return $input;
  281. }
  282. function ab_show($args = array(), $content = null) {
  283.     global $wp_cycle_settings, $wp_cycle_images;
  284.     // possible future use
  285.     $args = wp_parse_args($args, $wp_cycle_settings);
  286.     $newline = "\n"; // line break
  287.     echo '<div style="width:'.$wp_cycle_settings['img_width'].'px"><div id="slideShow"><div id="'.$wp_cycle_settings['div'].'">'.$newline;
  288.     foreach((array)$wp_cycle_images as $image => $data) {
  289.         if($data['image_links_to'])
  290.         {
  291.             $url = is_numeric($data['image_links_to']) ? get_permalink($data['image_links_to']) : $data['image_links_to'];
  292.             echo '<a href="'.$url.'">';
  293.         }
  294.         echo '<div><img src="'.$data['file_url'].'" width="'.$wp_cycle_settings['img_width'].'" height="'.$wp_cycle_settings['img_height'].'" class="'.$data['id'].'" alt="" /></div>';
  295.         if($data['image_links_to'])
  296.         echo '</a>';
  297.         echo $newline;
  298.     }
  299.     echo '</div></div></div>'.$newline;
  300. }
  301. //  create the shortcode [wp_cycle]
  302. add_shortcode('ab_show', 'wp_cycle_shortcode1');
  303. function wp_cycle_shortcode1($atts) {
  304.     // Temp solution, output buffer the echo function.
  305.     ob_start();
  306.     ab_show();
  307.     $output = ob_get_clean();
  308.     return $output;
  309. }
  310. add_action( 'wp_head', 'wp_cycle_style1' );
  311. function wp_cycle_style1() {
  312.     global $wp_cycle_settings;
  313. ?>
  314. <style type="text/css" media="screen">
  315.     #<?php echo $wp_cycle_settings['div']; ?> {
  316.         position: relative;
  317.         width: <?php echo $wp_cycle_settings['img_width']; ?>px;
  318.         height: <?php echo $wp_cycle_settings['img_height']?>px;
  319.         margin: 0; padding: 0;
  320.         overflow: hidden;
  321.     }
  322. </style>
  323. <?php }
  324. add_action('wp_head', 'abooze_slideshow_script');
  325. function abooze_slideshow_script(){
  326.     global $wp_cycle_settings;
  327. ?>
  328. <script type="text/javascript">
  329. jQuery(function($)
  330. {
  331.  
  332. $(document).ready(function() {
  333.     $('#slideShowItems div').hide().css({position:'absolute',width:'<?php echo $wp_cycle_settings['img_width']; ?>px'});
  334. var currentSlide = -1;
  335. var prevSlide = null;
  336. var slides = $('#slideShowItems div');
  337. var interval = null;
  338. var FADE_SPEED = <?php echo $wp_cycle_settings['fade_speed']; ?>;
  339. var DELAY_SPEED = <?php echo $wp_cycle_settings['delay_speed']; ?>;
  340. var html = '<ul id="slideShowCount">'
  341. for (var i = slides.length - 1;i >= 0 ; i--){
  342.     html += '<li id="slide'+ i+'" class="slide"><span>'+(i+1)+'</span></li>' ;
  343. }
  344. html += '</ul>';
  345. $('#slideShow').after(html);
  346. for (var i = slides.length - 1;i >= 0 ; i--){
  347.     $('#slide'+i).bind("click",{index:i},function(event){
  348.         currentSlide = event.data.index;
  349.         gotoSlide(event.data.index);
  350.     });
  351. };
  352. if (slides.length <= 1){
  353.     $('.slide').hide();
  354. }
  355. nextSlide();
  356. function nextSlide (){
  357.     if (currentSlide >= slides.length -1){
  358.         currentSlide = 0;
  359.     }else{
  360.         currentSlide++
  361.     }
  362.     gotoSlide(currentSlide);
  363. }
  364. function gotoSlide(slideNum){
  365.     if (slideNum != prevSlide){
  366.         if (prevSlide != null){
  367.             $(slides[prevSlide]).stop().fadeOut(FADE_SPEED);
  368.             $('#slide'+prevSlide).removeClass('selectedTab');
  369.         }
  370.         $('#slide'+currentSlide).addClass('selectedTab');
  371.         $('#slide'+slideNum).addClass('selectedTab');
  372.         $('#slide'+prevSlide).removeClass('selectedTab');
  373.         $(slides[slideNum]).fadeOut(FADE_SPEED).fadeIn(FADE_SPEED,function(){
  374.             $(this).css({opacity:1});
  375.             if(jQuery.browser.msie){
  376.                 this.style.removeAttribute('filter');
  377.             }
  378.         });
  379.         prevSlide = currentSlide;
  380.  
  381.         if (interval != null){
  382.             clearInterval(interval);
  383.         }
  384.         interval = setInterval(nextSlide, DELAY_SPEED);
  385.     }
  386. }
  387. $('ul#slideShowCount li.slide:first').addClass('fs_li');
  388. $('ul#slideShowCount li.slide:last').addClass('ls_li');
  389. });
  390. });
  391. </script>
  392. <style type="text/css">
  393. /* home slideshow css */
  394. div#slideShowItems{
  395.     height:<?php echo $wp_cycle_settings['img_height']; ?>px;
  396.     overflow:hidden;
  397.     position:relative;
  398. }
  399. div#slideShowItems div{
  400.     width:<?php echo $wp_cycle_settings['img_width']; ?>px;
  401. }
  402. div#slideShowItems img {
  403.     margin-right:13px;
  404.     float:left;
  405. }
  406. ul#slideShowCount{
  407.     margin:0px;
  408.     padding:0px;
  409.     width:<?php echo $wp_cycle_settings['img_width']; ?>px;
  410.     margin: 0 auto;
  411.     display: none;
  412. }
  413. ul#slideShowCount li.slide{
  414.     background:#69A8BB;
  415.     bottom: 45px;
  416.     right: 5px;
  417.     cursor: pointer;
  418.     display: block;
  419.     float: right;
  420.     height: 25px;
  421.     line-height: 22px;
  422.     position: relative;
  423.     width: 26px;
  424.  }
  425.  .fs_li{
  426.     -webkit-border-radius: 0 7px 7px 0;
  427.     -moz-border-radius: 0 7px 7px 0;
  428.     border-radius: 0 7px 7px 0;
  429.  }
  430.  .ls_li{
  431.     -webkit-border-radius: 7px 0px 0px 7px;
  432.     -moz-border-radius: 7px 0px 0px 7px;
  433.     border-radius: 7px 0px 0px 7px;
  434.  }
  435. ul#slideShowCount li.slide span{
  436.     padding-left:10px;
  437.     color:white;
  438.     font-size:11px;
  439. }
  440. ul#slideShowCount li.selectedTab span{
  441.     color: #000;
  442. }
  443. ul#slideShowCount li.slide:hover{
  444.     background-position:left -18px;
  445. }
  446.  
  447. ul#slideShowCount li.slide.selectedTab{
  448.     background-position:left -18px;
  449. }
  450. div#slideShow{
  451.     background:#EEE;
  452.     width:<?php echo $wp_cycle_settings['img_width']; ?>px;
  453.     margin: 0 auto;
  454.     margin-bottom:15px;
  455.     color:#fff;
  456. }
  457. /*home slideshow css end*/
  458. </style>
  459. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment