Changeset 1489716
- Timestamp:
- 09/04/2016 01:02:02 PM (9 years ago)
- Location:
- cycle-responsive-slider/trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cycle-responsive-slider/trunk/cycle-responsive-slider.php
r1470961 r1489716 3 3 Plugin Name: WP Cycle Responsive Slider 4 4 Plugin URI: http://www.kiranantony.com/wp-cycle2/ 5 Description: This plugin creates an image slideshow from the images you upload using the jQuery Cycle2 plugin. You can upload/delete images via the administration panel, and display the images in your theme by using the <code> caza_wp_cycle();</code> template tag, which will generate all the necessary HTML for outputting the rotating images. Admin Options Based On wp Cycle Plugin.6 Version: 1. 15 Description: This plugin creates an image slideshow from the images you upload using the jQuery Cycle2 plugin. You can upload/delete images via the administration panel, and display the images in your theme by using the <code>wp_cycle();</code> template tag, which will generate all the necessary HTML for outputting the rotating images. Admin Options Based On wp Cycle Plugin. 6 Version: 1.2 7 7 Author: Kiran Antony 8 8 Author URI: http://www.kiranantony.com/ … … 20 20 */ 21 21 22 /* 23 /////////////////////////////////////////////// 24 This section defines the variables that 25 will be used throughout the plugin 26 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 27 */ 28 // define our defaults (filterable) 22 29 23 $caza_wp_cycle_defaults = apply_filters('caza_wp_cycle_defaults', array( 30 24 'rotate' => 1, … … 41 35 $caza_wp_cycle_settings = get_option('caza_wp_cycle_settings'); 42 36 $caza_wp_cycle_images = get_option('caza_wp_cycle_images'); 37 $caza_wp_cycle_settings = wp_parse_args($caza_wp_cycle_settings, $caza_wp_cycle_defaults); 38 39 if (!class_exists('WP_Cycle_Responsive')) { 40 41 class WP_Cycle_Responsive { 42 43 /** 44 * Construct the plugin object 45 */ 46 public function __construct() { 47 43 48 44 49 // fallback 45 $caza_wp_cycle_settings = wp_parse_args($caza_wp_cycle_settings, $caza_wp_cycle_defaults); 46 47 48 /* 49 /////////////////////////////////////////////// 50 This section hooks the proper functions 51 to the proper actions in WordPress 52 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 53 */ 54 50 // register actions 51 add_action('admin_init', array(&$this, 'caza_wp_cycle_register_settings')); 52 add_action('admin_menu', array(&$this, 'add_caza_wp_cycle_menu')); 53 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'caza_wp_cycle_plugin_action_links')); 54 add_shortcode('wp_cycle', array(&$this, 'caza_wp_cycle_shortcode')); 55 add_shortcode('wp-cycle', array(&$this, 'caza_wp_cycle_shortcode')); 56 add_action('wp_enqueue_scripts', array(&$this, 'caza_wp_cycle_scripts')); 57 add_action('admin_enqueue_scripts', array(&$this, 'caza_wp_cycle_admin_script')); 58 add_action('wp_footer', array(&$this, 'caza_wp_cycle_args'), 90); 59 add_action('wp_head', array(&$this, 'caza_wp_cycle_style')); 60 add_action('admin_footer', array(&$this, 'caza_wp_cycle_sortable'), 100); 61 if (version_compare(PHP_VERSION, '5.3', '<')) { 62 add_action('widgets_init', create_function('', 'return register_widget("WP_CYCLE_WIDGET");') 63 ); 64 } else { 65 add_action('widgets_init', function() { 66 register_widget('WP_CYCLE_WIDGET'); 67 }); 68 } 69 } 70 71 // END public function __construct 72 73 /** 74 * Activate the plugin 75 */ 76 public static function activate() { 77 // Do nothing 78 } 79 80 // END public static function activate 81 82 /** 83 * Deactivate the plugin 84 */ 85 public static function deactivate() { 86 // Do nothing 87 } 88 89 // END public static function deactivate 55 90 // this function registers our settings in the db 56 add_action('admin_init', 'caza_wp_cycle_register_settings'); 57 58 function caza_wp_cycle_register_settings() {59 register_setting('caza_wp_cycle_images', 'caza_wp_cycle_images', 'caza_wp_cycle_images_validate');60 register_setting('caza_wp_cycle_settings', 'caza_wp_cycle_settings', 'caza_wp_cycle_settings_validate');61 }91 92 93 public function caza_wp_cycle_register_settings() { 94 register_setting('caza_wp_cycle_images', 'caza_wp_cycle_images', array(&$this, 'caza_wp_cycle_images_validate')); 95 register_setting('caza_wp_cycle_settings', 'caza_wp_cycle_settings', array(&$this, 'caza_wp_cycle_settings_validate')); 96 } 62 97 63 98 // this function adds the settings page to the Appearance tab 64 add_action('admin_menu', 'add_caza_wp_cycle_menu'); 65 66 function add_caza_wp_cycle_menu() {67 add_submenu_page('upload.php', 'WP-Cycle Settings', 'WP-Cycle', 'upload_files', 'wp-cycle', 'caza_wp_cycle_admin_page');68 }99 100 101 public function add_caza_wp_cycle_menu() { 102 add_submenu_page('upload.php', 'WP-Cycle Settings', 'WP-Cycle', 'upload_files', 'wp-cycle', array(&$this, 'caza_wp_cycle_admin_page')); 103 } 69 104 70 105 // add "Settings" link to plugin page 71 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'caza_wp_cycle_plugin_action_links'); 72 73 function caza_wp_cycle_plugin_action_links($links) { 74 $caza_wp_cycle_settings_link = sprintf('<a href="%s">%s</a>', admin_url('upload.php?page=wp-cycle'), __('Settings')); 75 array_unshift($links, $caza_wp_cycle_settings_link); 76 return $links; 77 } 78 79 /* 80 /////////////////////////////////////////////// 81 this function is the code that gets loaded when the 82 settings page gets loaded by the browser. It calls 83 functions that handle image uploads and image settings 84 changes, as well as producing the visible page output. 85 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 86 */ 87 88 function caza_wp_cycle_admin_page() { 89 echo '<div class="wrap">'; 90 91 // handle image upload, if necessary 92 if (isset($_REQUEST["action"]) && $_REQUEST['action'] == 'wp_handle_upload') 93 caza_wp_cycle_handle_upload(); 94 95 // delete an image, if necessary 96 if (isset($_REQUEST['delete'])) 97 caza_wp_cycle_delete_upload($_REQUEST['delete']); 98 99 // the image management form 100 caza_wp_cycle_images_admin(); 101 102 // the settings management form 103 caza_wp_cycle_settings_admin(); 104 105 echo '</div>'; 106 } 107 108 /* 109 /////////////////////////////////////////////// 110 this section handles uploading images, adding 111 the image data to the database, deleting images, 112 and deleting image data from the database. 113 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 114 */ 115 116 // this function handles the file upload, 117 // resize/crop, and adds the image data to the db 118 function caza_wp_cycle_handle_upload() { 119 $dest_path = ABSPATH . 'wp-content/uploads/resized/'; 120 if (wp_mkdir_p($dest_path)) { 121 122 } 123 global $caza_wp_cycle_settings, $caza_wp_cycle_images; 124 125 // upload the image 126 $upload = wp_handle_upload($_FILES['caza_wp_cycle'], 0); 127 // var_dump($upload); 128 // var_dump($dest_path); 129 // exit(); 130 // extract the $upload array 131 extract($upload); 132 133 // the URL of the directory the file was loaded in 134 $upload_dir_url = get_bloginfo('url') . '/wp-content/uploads/resized/'; 135 136 // get the image dimensions 137 list($width, $height) = getimagesize($file); 138 139 // if the uploaded file is NOT an image 140 if (strpos($type, 'image') === FALSE) { 141 unlink($file); // delete the file 142 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>'; 143 return; 144 } 145 146 // if the image doesn't meet the minimum width/height requirements ... 147 if ($width < $caza_wp_cycle_settings['img_width'] || $height < $caza_wp_cycle_settings['img_height']) { 148 unlink($file); // delete the image 149 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>'; 150 return; 151 } 152 153 // if the image is larger than the width/height requirements, then scale it down. 154 if ($width > $caza_wp_cycle_settings['img_width'] || $height > $caza_wp_cycle_settings['img_height']) { 155 // resize the image 156 157 $image = wp_get_image_editor($file); 158 159 if (!is_wp_error($image)) { 160 $image->resize($caza_wp_cycle_settings['img_width'], $caza_wp_cycle_settings['img_height'], true); 161 $dest_file = $image->generate_filename('resized', $dest_path); 162 $final_image = $image->save($dest_file); 163 } 164 if (isset($final_image)) { 165 if (!is_wp_error($final_image)) { 166 $resized_url = $upload_dir_url . basename($final_image['file']); 167 //print_r($final_image); 168 // delete the original 169 unlink($file); 170 $file = $final_image['path']; 171 $url = $resized_url; 172 } 173 } 174 } 175 176 // make the thumbnail 177 $thumb_height = round((100 * $caza_wp_cycle_settings['img_height']) / $caza_wp_cycle_settings['img_width']); 178 if (isset($upload['file'])) { 179 180 $thumbnail = wp_get_image_editor($file); 181 182 if (!is_wp_error($thumbnail)) { 183 $thumbnail->resize(100, $thumb_height, true); 184 $dest_thumb = $thumbnail->generate_filename('thumb', $dest_path); 185 $final_thumbnail = $thumbnail->save($dest_thumb); 186 } 187 if (isset($final_thumbnail)) { 188 if (!is_wp_error($final_thumbnail)) { 189 $thumbnail_url = $upload_dir_url . basename($final_thumbnail['file']); 190 $thumbnail = $final_thumbnail['path']; 191 } 192 } else { 193 $thumbnail_url = ""; 194 $thumbnail = ""; 195 } 196 } 197 198 // use the timestamp as the array key and id 199 $time = date('YmdHis'); 200 201 // add the image data to the array 202 // UPDATE April 2011 by Chris Grab - added caza_wp_cycle_image_caption to the array 203 204 $caza_wp_cycle_images[$time] = array( 205 'id' => $time, 206 'file' => $file, 207 'file_url' => $url, 208 'thumbnail' => $thumbnail, 209 'thumbnail_url' => $thumbnail_url, 210 'image_links_to' => '', 211 'caza_wp_cycle_image_caption' => '' 212 ); 213 214 215 // add the image information to the database 216 $caza_wp_cycle_images['update'] = 'Added'; 217 update_option('caza_wp_cycle_images', $caza_wp_cycle_images); 218 } 219 220 // this function deletes the image, 221 // and removes the image data from the db 222 function caza_wp_cycle_delete_upload($id) { 223 global $caza_wp_cycle_images; 224 225 // if the ID passed to this function is invalid, 226 // halt the process, and don't try to delete. 227 if (!isset($caza_wp_cycle_images[$id])) 228 return; 229 230 // delete the image and thumbnail 231 unlink($caza_wp_cycle_images[$id]['file']); 232 unlink($caza_wp_cycle_images[$id]['thumbnail']); 233 234 // indicate that the image was deleted 235 $caza_wp_cycle_images['update'] = 'Deleted'; 236 237 // remove the image data from the db 238 unset($caza_wp_cycle_images[$id]); 239 update_option('caza_wp_cycle_images', $caza_wp_cycle_images); 240 } 241 242 /* 243 /////////////////////////////////////////////// 244 these two functions check to see if an update 245 to the data just occurred. if it did, then they 246 will display a notice, and reset the update option. 247 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 248 */ 249 250 // this function checks to see if we just updated the settings 106 107 108 public function caza_wp_cycle_plugin_action_links($links) { 109 $caza_wp_cycle_settings_link = sprintf('<a href="%s">%s</a>', admin_url('upload.php?page=wp-cycle'), __('Settings')); 110 array_unshift($links, $caza_wp_cycle_settings_link); 111 return $links; 112 } 113 114 /* 115 /////////////////////////////////////////////// 116 this function is the code that gets loaded when the 117 settings page gets loaded by the browser. It calls 118 functions that handle image uploads and image settings 119 changes, as well as producing the visible page output. 120 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 121 */ 122 123 public function caza_wp_cycle_admin_page() { 124 if (!current_user_can('manage_options')) { 125 wp_die(__('You do not have sufficient permissions to access this page.')); 126 } 127 require_once plugin_dir_path(__FILE__) . 'includes/admin-settings.php'; 128 } 129 130 // this function sanitizes our settings data for storage 131 public function caza_wp_cycle_settings_validate($input) { 132 $input['rotate'] = ($input['rotate'] == 1 ? 1 : 0); 133 $input['random'] = ($input['random'] == 1 ? 1 : 0); 134 $input['effect'] = wp_filter_nohtml_kses($input['effect']); 135 $input['img_width'] = intval($input['img_width']); 136 $input['img_height'] = intval($input['img_height']); 137 $input['div'] = wp_filter_nohtml_kses($input['div']); 138 139 return $input; 140 } 141 142 // this function sanitizes our image data for storage 143 public function caza_wp_cycle_images_validate($input) { 144 foreach ((array) $input as $key => $value) { 145 if ($key != 'update') { 146 $input[$key]['file_url'] = esc_url($value['file_url']); 147 $input[$key]['thumbnail_url'] = esc_url($value['thumbnail_url']); 148 149 if ($value['image_links_to']) 150 $input[$key]['image_links_to'] = esc_url($value['image_links_to']); 151 152 if ($value['caza_wp_cycle_image_caption']) 153 $input[$key]['caza_wp_cycle_image_caption'] = wp_filter_nohtml_kses($value['caza_wp_cycle_image_caption']); 154 } 155 } 156 return $input; 157 } 158 159 // this function checks to see if we just updated the settings 251 160 // if so, it displays the "updated" message. 252 function caza_wp_cycle_settings_update_check() {253 global $caza_wp_cycle_settings;254 if (isset($caza_wp_cycle_settings['update'])) {255 echo '<div class="updated fade" id="message"><p>WP-Cycle Settings <strong>' . $caza_wp_cycle_settings['update'] . '</strong></p></div>';256 unset($caza_wp_cycle_settings['update']);257 update_option('caza_wp_cycle_settings', $caza_wp_cycle_settings);258 }259 }161 public function caza_wp_cycle_settings_update_check() { 162 global $caza_wp_cycle_settings; 163 if (isset($caza_wp_cycle_settings['update'])) { 164 echo '<div class="updated fade" id="message"><p>WP-Cycle Settings <strong>' . $caza_wp_cycle_settings['update'] . '</strong></p></div>'; 165 unset($caza_wp_cycle_settings['update']); 166 update_option('caza_wp_cycle_settings', $caza_wp_cycle_settings); 167 } 168 } 260 169 261 170 // this function checks to see if we just added a new image 262 171 // if so, it displays the "updated" message. 263 function caza_wp_cycle_images_update_check() { 264 global $caza_wp_cycle_images; 265 if (isset($caza_wp_cycle_images['update']) && $caza_wp_cycle_images['update'] == 'Added' || isset($caza_wp_cycle_images['update']) && $caza_wp_cycle_images['update'] == 'Deleted' || isset($caza_wp_cycle_images['update']) && $caza_wp_cycle_images['update'] == 'Updated') { 266 echo '<div class="updated fade" id="message"><p>Image(s) ' . $caza_wp_cycle_images['update'] . ' Successfully</p></div>'; 267 unset($caza_wp_cycle_images['update']); 268 update_option('caza_wp_cycle_images', $caza_wp_cycle_images); 172 public function caza_wp_cycle_images_update_check() { 173 global $caza_wp_cycle_images; 174 if (isset($caza_wp_cycle_images['update']) && $caza_wp_cycle_images['update'] == 'Added' || isset($caza_wp_cycle_images['update']) && $caza_wp_cycle_images['update'] == 'Deleted' || isset($caza_wp_cycle_images['update']) && $caza_wp_cycle_images['update'] == 'Updated') { 175 echo '<div class="updated fade" id="message"><p>Image(s) ' . $caza_wp_cycle_images['update'] . ' Successfully</p></div>'; 176 unset($caza_wp_cycle_images['update']); 177 update_option('caza_wp_cycle_images', $caza_wp_cycle_images); 178 } 179 } 180 181 public function caza_wp_cycle_handle_upload() { 182 if (!current_user_can('manage_options')) { 183 wp_die(__('You do not have sufficient permissions to access this page.')); 184 } 185 require_once plugin_dir_path(__FILE__) . 'includes/wp_cycle_handle_upload.php'; 186 } 187 188 public function caza_wp_cycle_delete_upload($id) { 189 global $caza_wp_cycle_images; 190 191 // if the ID passed to this function is invalid, 192 // halt the process, and don't try to delete. 193 if (!isset($caza_wp_cycle_images[$id])) 194 return; 195 196 // delete the image and thumbnail 197 unlink($caza_wp_cycle_images[$id]['file']); 198 unlink($caza_wp_cycle_images[$id]['thumbnail']); 199 200 // indicate that the image was deleted 201 $caza_wp_cycle_images['update'] = 'Deleted'; 202 203 // remove the image data from the db 204 unset($caza_wp_cycle_images[$id]); 205 update_option('caza_wp_cycle_images', $caza_wp_cycle_images); 206 } 207 208 public function caza_wp_cycle_images_admin() { 209 if (!current_user_can('manage_options')) { 210 wp_die(__('You do not have sufficient permissions to access this page.')); 211 } 212 require_once plugin_dir_path(__FILE__) . 'includes/wp_cycle_images_admin.php'; 213 } 214 215 // display the settings administration code 216 public function caza_wp_cycle_settings_admin() { 217 if (!current_user_can('manage_options')) { 218 wp_die(__('You do not have sufficient permissions to access this page.')); 219 } 220 require_once plugin_dir_path(__FILE__) . 'includes/wp_cycle_settings_admin.php'; 221 } 222 223 public function caza_wp_cycle($args = array(), $content = null) { 224 global $caza_wp_cycle_settings, $caza_wp_cycle_images; 225 // possible future use 226 $args = wp_parse_args($args, $caza_wp_cycle_settings); 227 228 $newline = "\n"; // line break 229 230 echo '<div class="' . $caza_wp_cycle_settings['div'] . '">' . $newline; 231 232 foreach ((array) $caza_wp_cycle_images as $image => $data) { 233 echo '<div>'; 234 if ($data['image_links_to']) 235 echo '<a href="' . $data['image_links_to'] . '" >'; 236 echo '<img src="' . $data['file_url'] . '" width="' . $caza_wp_cycle_settings['img_width'] . '" height="' . $caza_wp_cycle_settings['img_height'] . '" class="' . $data['id'] . '" alt="' . $data['caza_wp_cycle_image_caption'] . '" />'; 237 238 if ($data['image_links_to']) 239 echo '</a>'; 240 //updated 8/1/2012 by Toby Brommerich -- Moved Caption inside foreach, copied caption variable from img alt 241 if (!empty($data['caza_wp_cycle_image_caption'])) 242 echo '<p id="caption" class="cycle-caption">' . $data['caza_wp_cycle_image_caption'] . '</p>'; 243 echo '</div>'; 244 } 245 246 echo '</div>' . $newline; 247 } 248 249 // create the shortcode [wp_cycle] 250 public function caza_wp_cycle_shortcode($atts) { 251 // Temp solution, output buffer the echo function. 252 ob_start(); 253 $this->caza_wp_cycle(); 254 $output = ob_get_clean(); 255 256 return $output; 257 } 258 259 public function caza_wp_cycle_scripts() { 260 global $caza_wp_cycle_settings; 261 wp_enqueue_script('cycle', plugins_url('/jquery.cycle2.min.js', __FILE__), array('jquery'), ''); 262 if ($caza_wp_cycle_settings['effect'] == 'tileSlide' || $caza_wp_cycle_settings['effect'] == 'tileBlind') 263 wp_enqueue_script('cycle-plugin', plugins_url('/jquery.cycle2.tile.min.js', __FILE__), array('cycle')); 264 if ($caza_wp_cycle_settings['effect'] == 'flipHorz' || $caza_wp_cycle_settings['effect'] == 'flipVert') 265 wp_enqueue_script('cycle-plugin', plugins_url('/jquery.cycle2.flip.min.js', __FILE__), array('cycle'), '', true); 266 if ($caza_wp_cycle_settings['effect'] == 'scrollVert') 267 wp_enqueue_script('cycle-plugin', plugins_url('/jquery.cycle2.scrollVert.min.js', __FILE__), array('cycle'), '', true); 268 if ($caza_wp_cycle_settings['effect'] == 'shuffle') 269 wp_enqueue_script('cycle-plugin', plugins_url('/jquery.cycle2.shuffle.min.js', __FILE__), array('cycle'), '', true); 270 } 271 272 public function caza_wp_cycle_admin_script() { 273 wp_enqueue_script('jquery-ui-sortable'); 274 } 275 276 public function caza_wp_cycle_args() { 277 global $caza_wp_cycle_settings; 278 ?> 279 280 <?php if ($caza_wp_cycle_settings['rotate']) : ?> 281 <script type="text/javascript"> 282 jQuery('document').ready(function () { 283 jQuery(".<?php echo $caza_wp_cycle_settings['div']; ?>").cycle({ 284 fx: '<?php echo $caza_wp_cycle_settings['effect']; ?>', 285 timeout: <?php echo $caza_wp_cycle_settings['delay'] * 1000; ?>, 286 speed: <?php echo $caza_wp_cycle_settings['duration'] * 1000; ?>, 287 random: <?php echo $caza_wp_cycle_settings['random']; ?>, 288 slides: '> div', 289 autoHeight: 'calc', 290 loader: 'wait' 291 }); 292 }); 293 </script> 294 <?php endif; ?> 295 296 <?php 297 } 298 299 public function caza_wp_cycle_style() { 300 global $caza_wp_cycle_settings; 301 ?> 302 303 <style type="text/css" media="screen"> 304 .<?php echo $caza_wp_cycle_settings['div']; ?> { 305 /*position: relative;*/ 306 /*width: <?php // echo $caza_wp_cycle_settings['img_width']; ?>px;*/ 307 /*height: <?php // echo $caza_wp_cycle_settings['img_height'] ?>px;*/ 308 /*margin: 0; padding: 0;*/ 309 310 311 /*overflow: hidden;*/ 312 313 314 } 315 </style> 316 317 <?php 318 } 319 320 public function caza_wp_cycle_sortable() { 321 ?> 322 <style type="text/css"> 323 .wp-cycle-image-list tbody.ui-sortable > tr > td.order { 324 background: #f4f4f4 none repeat scroll 0 0; 325 border-right-color: #e1e1e1; 326 color: #aaa; 327 cursor: move; 328 text-align: center !important; 329 text-shadow: 0 1px 0 #fff; 330 vertical-align: middle; 331 width: 16px !important; 332 } 333 .wp-cycle-image-list tbody.ui-sortable > tr > td { 334 border-bottom: 1px solid #ededed; 335 padding: 8px; 336 position: relative; 337 } 338 .wp-cycle-image-list tbody .row { 339 background: #fff none repeat scroll 0 0; 340 } 341 </style> 342 <script type="text/javascript"> 343 jQuery(document).ready(function () { 344 jQuery(".wp-cycle-image-list .ui-sortable").sortable({ 345 cursor: 'move', 346 items: 'tr.row', 347 handle: 'td.order', 348 cancel: '.fixed,input', 349 update: function () { 350 var order = jQuery('.ui-sortable').sortable('serialize'); 351 jQuery.ajax({ 352 type: "POST", 353 url: "<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php", 354 data: "action=update_field_order&order=" + order 355 }); 356 }}); 357 // jQuery(".ui-sortable").disableSelection(); 358 jQuery("tbody.ui-sortable > tr > td").each(function (index) { 359 jQuery(this).width(jQuery(this).width()); 360 }); 361 }); 362 </script> 363 <?php 364 } 365 269 366 } 367 368 // END class WP_Cycle_Responsive 369 } // END if(!class_exists('WP_Cycle_Responsive')) 370 371 if (class_exists('WP_Cycle_Responsive')) { 372 // Installation and uninstallation hooks 373 register_activation_hook(__FILE__, array('WP_Cycle_Responsive', 'activate')); 374 register_deactivation_hook(__FILE__, array('WP_Cycle_Responsive', 'deactivate')); 375 376 // instantiate the plugin class 377 $wp_plugin_template = new WP_Cycle_Responsive(); 378 379 // support for wp_cycle() ; 380 function wp_cycle($args = array(), $content = null) { 381 global $wp_plugin_template; 382 $wp_plugin_template->caza_wp_cycle($args, $content); 383 } 384 270 385 } 271 386 272 /* 273 /////////////////////////////////////////////// 274 these two functions display the front-end code 275 on the admin page. it's mostly form markup. 276 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 277 */ 278 279 // display the images administration code 280 function caza_wp_cycle_images_admin() { 281 ?> 282 <?php global $caza_wp_cycle_images; ?> 283 <?php caza_wp_cycle_images_update_check(); ?> 284 <h2><?php _e('WP-Cycle Plus Images', 'caza_wp_cycle'); ?></h2> 285 286 <table class="form-table"> 287 <tr valign="top"><th scope="row">Upload New Image</th> 288 <td> 289 <form enctype="multipart/form-data" method="post" action="?page=wp-cycle"> 290 <input type="hidden" name="post_id" id="post_id" value="0" /> 291 <input type="hidden" name="action" id="action" value="wp_handle_upload" /> 292 293 <label for="caza_wp_cycle">Select a File: </label> 294 <input type="file" name="caza_wp_cycle" id="caza_wp_cycle" /> 295 <input type="submit" class="button-primary" name="html-upload" value="Upload" /> 296 </form> 297 </td> 298 </tr> 299 </table><br /> 300 301 <?php if (!empty($caza_wp_cycle_images)) : ?> 302 <form method="post" action="options.php"> 303 <table class="widefat wp-cycle-image-list" cellspacing="0"> 304 <thead> 305 <tr> 306 <th class="order"></th> 307 <th scope="col" class="column-slug">Image</th> 308 <th scope="col">Image Links To</th> 309 <th scope="col">Image Caption</th> 310 <th scope="col" class="column-slug">Actions</th> 311 </tr> 312 </thead> 313 314 <tfoot> 315 <tr> 316 <th class="order"></th> 317 <th scope="col" class="column-slug">Image</th> 318 <th scope="col">Image Links To</th> 319 <th scope="col">Image Caption</th> 320 <th scope="col" class="column-slug">Actions</th> 321 </tr> 322 </tfoot> 323 324 <tbody class="ui-sortable"> 325 326 327 <?php settings_fields('caza_wp_cycle_images'); ?> 328 <?php 329 $i = 0; 330 foreach ((array) $caza_wp_cycle_images as $image => $data) : $i++; 331 ?> 332 <tr class="row"> 333 <td class="order" style="width: 16px;"><?php echo $i; ?></td> 334 <input type="hidden" name="caza_wp_cycle_images[<?php echo $image; ?>][id]" value="<?php echo $data['id']; ?>" /> 335 <input type="hidden" name="caza_wp_cycle_images[<?php echo $image; ?>][file]" value="<?php echo $data['file']; ?>" /> 336 <input type="hidden" name="caza_wp_cycle_images[<?php echo $image; ?>][file_url]" value="<?php echo $data['file_url']; ?>" /> 337 338 <?php if ($data['thumbnail']): ?><input type="hidden" name="caza_wp_cycle_images[<?php echo $image; ?>][thumbnail]" value="<?php echo $data['thumbnail']; ?>" /> 339 <input type="hidden" name="caza_wp_cycle_images[<?php echo $image; ?>][thumbnail_url]" value="<?php echo $data['thumbnail_url']; ?>" /><?php endif; ?> 340 <td scope="row" class="column-slug"> 341 <?php if ($data['thumbnail']): ?><img src="<?php echo $data['thumbnail_url']; ?>" /><?php else: ?><img width="100" src="<?php echo $data['file_url']; ?>" /><?php endif; ?> 342 <div><?php echo basename($data['file_url']); ?></div> 343 </td> 344 <td><input type="text" name="caza_wp_cycle_images[<?php echo $image; ?>][image_links_to]" value="<?php echo $data['image_links_to']; ?>" style="width:100%" /></td> 345 <td><input type="text" name="caza_wp_cycle_images[<?php echo $image; ?>][caza_wp_cycle_image_caption]" value="<?php echo $data['caza_wp_cycle_image_caption']; ?>" style="width:100%" /></td> 346 <td class="column-slug"><a href="?page=wp-cycle&delete=<?php echo $image; ?>" class="button">Delete</a></td> 347 </tr> 348 <?php endforeach; ?> 349 <input type="hidden" name="caza_wp_cycle_images[update]" value="Updated" /> 350 351 352 </tbody> 353 354 </table> 355 <p class="submit"> 356 <input type="submit" class="button-primary" value="Update Images"> 357 </p> 358 </form> 359 <?php endif; ?> 360 361 <?php 362 } 363 364 // display the settings administration code 365 function caza_wp_cycle_settings_admin() { 366 ?> 367 368 <?php caza_wp_cycle_settings_update_check(); ?> 369 <h2><?php _e('WP-Cycle 2 Settings', 'wp-cycle'); ?></h2> 370 <form method="post" action="options.php"> 371 <?php settings_fields('caza_wp_cycle_settings'); ?> 372 <?php 373 global $caza_wp_cycle_settings; 374 $options = $caza_wp_cycle_settings; 375 ?> 376 <table class="form-table" > 377 <tr><th scope="row">Enable Random Image Order</th> 378 <td><input name="caza_wp_cycle_settings[random]" type="checkbox" value="1" <?php checked('1', $options['random']); ?> /> <label for="caza_wp_cycle_settings[random]">Check this box if you want to enable random image order</td> 379 </td></tr> 380 <tr valign="top"><th scope="row">Transition Enabled</th> 381 <td><input name="caza_wp_cycle_settings[rotate]" type="checkbox" value="1" <?php checked('1', $options['rotate']); ?> /> <label for="caza_wp_cycle_settings[rotate]">Check this box if you want to enable the transition effects</td> 382 </tr> 383 <tr><th scope="row">Transition Effect</th> 384 <td>Please select the effect you would like to use when your images rotate (if applicable):<br /> 385 <select name="caza_wp_cycle_settings[effect]"> 386 <option value="fade" <?php selected('fade', $options['effect']); ?>>fade</option> 387 <option value="fadeout" <?php selected('fadeout', $options['effect']); ?>>fadeout</option> 388 <option value="scrollHorz" <?php selected('scrollHorz', $options['effect']); ?>>scrollHorz</option> 389 <!--<option value="tileSlide" <?php selected('tileSlide', $options['effect']); ?>>tileSlide</option>--> 390 <!--<option value="tileBlind" <?php selected('tileBlind', $options['effect']); ?>>tileBlind</option>--> 391 <!--<option value="flipHorz" <?php selected('flipHorz', $options['effect']); ?>>flipHorz</option>--> 392 <!--<option value="flipVert" <?php selected('flipVert', $options['effect']); ?>>flipVert</option>--> 393 <!--<option value="scrollVert" <?php selected('scrollVert', $options['effect']); ?>>scrollVert</option>--> 394 <!--<option value="shuffle" <?php selected('shuffle', $options['effect']); ?>>shuffle</option>--> 395 </select> 396 </td></tr> 397 398 <tr><th scope="row">Transition Delay</th> 399 <td>Length of time (in seconds) you would like each image to be visible:<br /> 400 <input type="text" name="caza_wp_cycle_settings[delay]" value="<?php echo $options['delay'] ?>" size="4" /> 401 <label for="caza_wp_cycle_settings[delay]">second(s)</label> 402 </td></tr> 403 404 <tr><th scope="row">Transition Length</th> 405 <td>Length of time (in seconds) you would like the transition length to be:<br /> 406 <input type="text" name="caza_wp_cycle_settings[duration]" value="<?php echo $options['duration'] ?>" size="4" /> 407 <label for="caza_wp_cycle_settings[duration]">second(s)</label> 408 </td></tr> 409 410 <tr><th scope="row">Image Dimensions</th> 411 <td>Please input the width of the image rotator:<br /> 412 <input type="text" name="caza_wp_cycle_settings[img_width]" value="<?php echo $options['img_width'] ?>" size="4" /> 413 <label for="caza_wp_cycle_settings[img_width]">px</label> 414 <br /><br /> 415 Please input the height of the image rotator:<br /> 416 <input type="text" name="caza_wp_cycle_settings[img_height]" value="<?php echo $options['img_height'] ?>" size="4" /> 417 <label for="caza_wp_cycle_settings[img_height]">px</label> 418 </td></tr> 419 420 <tr><th scope="row">Rotator DIV ID</th> 421 <td>Please indicate what you would like the rotator DIV ID to be:<br /> 422 <input type="text" name="caza_wp_cycle_settings[div]" value="<?php echo $options['div'] ?>" /> 423 </td></tr> 424 425 <input type="hidden" name="caza_wp_cycle_settings[update]" value="UPDATED" /> 426 427 </table> 428 <p class="submit"> 429 <input type="submit" class="button-primary" value="<?php _e('Save Settings') ?>" /> 430 </form> 431 432 <!-- The Reset Option --> 433 <form method="post" action="options.php"> 434 <?php settings_fields('caza_wp_cycle_settings'); ?> 435 <?php global $caza_wp_cycle_defaults; // use the defaults ?> 436 <?php foreach ((array) $caza_wp_cycle_defaults as $key => $value) : ?> 437 <input type="hidden" name="caza_wp_cycle_settings[<?php echo $key; ?>]" value="<?php echo $value; ?>" /> 438 <?php endforeach; ?> 439 <input type="hidden" name="caza_wp_cycle_settings[update]" value="RESET" /> 440 <input type="submit" class="button" value="<?php _e('Reset Settings') ?>" /> 441 </form> 442 <!-- End Reset Option --> 443 </p> 444 445 <?php 446 } 447 448 /* 449 /////////////////////////////////////////////// 450 these two functions sanitize the data before it 451 gets stored in the database via options.php 452 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 453 */ 454 455 // this function sanitizes our settings data for storage 456 function caza_wp_cycle_settings_validate($input) { 457 $input['rotate'] = ($input['rotate'] == 1 ? 1 : 0); 458 $input['random'] = ($input['random'] == 1 ? 1 : 0); 459 $input['effect'] = wp_filter_nohtml_kses($input['effect']); 460 $input['img_width'] = intval($input['img_width']); 461 $input['img_height'] = intval($input['img_height']); 462 $input['div'] = wp_filter_nohtml_kses($input['div']); 463 464 return $input; 465 } 466 467 // this function sanitizes our image data for storage 468 function caza_wp_cycle_images_validate($input) { 469 foreach ((array) $input as $key => $value) { 470 if ($key != 'update') { 471 $input[$key]['file_url'] = esc_url($value['file_url']); 472 $input[$key]['thumbnail_url'] = esc_url($value['thumbnail_url']); 473 474 if ($value['image_links_to']) 475 $input[$key]['image_links_to'] = esc_url($value['image_links_to']); 476 477 if ($value['caza_wp_cycle_image_caption']) 478 $input[$key]['caza_wp_cycle_image_caption'] = wp_filter_nohtml_kses($value['caza_wp_cycle_image_caption']); 479 } 480 } 481 return $input; 482 } 483 484 /* 485 /////////////////////////////////////////////// 486 this final section generates all the code that 487 is displayed on the front-end of the WP Theme 488 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 489 */ 490 491 function caza_wp_cycle($args = array(), $content = null) { 492 global $caza_wp_cycle_settings, $caza_wp_cycle_images; 493 // possible future use 494 $args = wp_parse_args($args, $caza_wp_cycle_settings); 495 496 $newline = "\n"; // line break 497 498 echo '<div id="' . $caza_wp_cycle_settings['div'] . '">' . $newline; 499 500 foreach ((array) $caza_wp_cycle_images as $image => $data) { 501 echo '<div>'; 502 if ($data['image_links_to']) 503 echo '<a href="' . $data['image_links_to'] . '" >'; 504 echo '<img src="' . $data['file_url'] . '" width="' . $caza_wp_cycle_settings['img_width'] . '" height="' . $caza_wp_cycle_settings['img_height'] . '" class="' . $data['id'] . '" alt="' . $data['caza_wp_cycle_image_caption'] . '" />'; 505 506 if ($data['image_links_to']) 507 echo '</a>'; 508 //updated 8/1/2012 by Toby Brommerich -- Moved Caption inside foreach, copied caption variable from img alt 509 if (!empty($data['caza_wp_cycle_image_caption'])) 510 echo '<p id="caption" class="cycle-caption">' . $data['caza_wp_cycle_image_caption'] . '</p>'; 511 echo '</div>'; 512 } 513 514 echo '</div>' . $newline; 515 } 516 517 // create the shortcode [caza_wp_cycle] 518 add_shortcode('wp_cycle', 'caza_wp_cycle_shortcode'); 519 add_shortcode('wp-cycle', 'caza_wp_cycle_shortcode'); 520 521 function caza_wp_cycle_shortcode($atts) { 522 523 // Temp solution, output buffer the echo function. 524 ob_start(); 525 caza_wp_cycle(); 526 $output = ob_get_clean(); 527 528 return $output; 529 } 530 531 add_action('wp_enqueue_scripts', 'caza_wp_cycle_scripts'); 532 533 function caza_wp_cycle_scripts() { 534 global $caza_wp_cycle_settings; 535 wp_enqueue_script('cycle', plugins_url('/jquery.cycle2.min.js', __FILE__), array('jquery'), '', true); 536 if ($caza_wp_cycle_settings['effect'] == 'tileSlide' || $caza_wp_cycle_settings['effect'] == 'tileBlind') 537 wp_enqueue_script('cycle-plugin', plugins_url('/jquery.cycle2.tile.min.js', __FILE__), array('cycle'), '', true); 538 if ($caza_wp_cycle_settings['effect'] == 'flipHorz' || $caza_wp_cycle_settings['effect'] == 'flipVert') 539 wp_enqueue_script('cycle-plugin', plugins_url('/jquery.cycle2.flip.min.js', __FILE__), array('cycle'), '', true); 540 if ($caza_wp_cycle_settings['effect'] == 'scrollVert') 541 wp_enqueue_script('cycle-plugin', plugins_url('/jquery.cycle2.scrollVert.min.js', __FILE__), array('cycle'), '', true); 542 if ($caza_wp_cycle_settings['effect'] == 'shuffle') 543 wp_enqueue_script('cycle-plugin', plugins_url('/jquery.cycle2.shuffle.min.js', __FILE__), array('cycle'), '', true); 544 } 545 546 function caza_wp_cycle_admin_script() { 547 wp_enqueue_script('jquery-ui-sortable'); 548 } 549 550 add_action('admin_enqueue_scripts', 'caza_wp_cycle_admin_script'); 551 552 add_action('wp_footer', 'caza_wp_cycle_args', 90); 553 554 function caza_wp_cycle_args() { 555 global $caza_wp_cycle_settings; 556 ?> 557 558 <?php if ($caza_wp_cycle_settings['rotate']) : ?> 559 <script type="text/javascript"> 560 window.onload = function () { 561 jQuery("#<?php echo $caza_wp_cycle_settings['div']; ?>").cycle({ 562 fx: "<?php echo $caza_wp_cycle_settings['effect']; ?>", 563 timeout: <?php echo ($caza_wp_cycle_settings['delay'] * 1000); ?>, 564 speed: <?php echo ($caza_wp_cycle_settings['duration'] * 1000); ?>, 565 random: <?php echo $caza_wp_cycle_settings['random']; ?>, 566 slides: '> div', 567 autoHeight: 'calc', 568 loader: 'wait' 569 }); 570 571 }; 572 </script> 573 <?php endif; ?> 574 575 <?php 576 } 577 578 add_action('wp_head', 'caza_wp_cycle_style'); 579 580 function caza_wp_cycle_style() { 581 global $caza_wp_cycle_settings; 582 ?> 583 584 <style type="text/css" media="screen"> 585 #<?php echo $caza_wp_cycle_settings['div']; ?> { 586 /*position: relative;*/ 587 /*width: <?php // echo $caza_wp_cycle_settings['img_width']; ?>px;*/ 588 /*height: <?php // echo $caza_wp_cycle_settings['img_height'] ?>px;*/ 589 /*margin: 0; padding: 0;*/ 590 591 592 /*overflow: hidden;*/ 593 594 595 } 596 </style> 597 598 <?php 599 } 600 601 add_action('admin_footer', 'caza_wp_cycle_sortable', 100); 602 603 function caza_wp_cycle_sortable() { 604 ?> 605 <style type="text/css"> 606 .wp-cycle-image-list tbody.ui-sortable > tr > td.order { 607 background: #f4f4f4 none repeat scroll 0 0; 608 border-right-color: #e1e1e1; 609 color: #aaa; 610 cursor: move; 611 text-align: center !important; 612 text-shadow: 0 1px 0 #fff; 613 vertical-align: middle; 614 width: 16px !important; 615 } 616 .wp-cycle-image-list tbody.ui-sortable > tr > td { 617 border-bottom: 1px solid #ededed; 618 padding: 8px; 619 position: relative; 620 } 621 .wp-cycle-image-list tbody .row { 622 background: #fff none repeat scroll 0 0; 623 } 624 </style> 625 <script type="text/javascript"> 626 jQuery(document).ready(function () { 627 jQuery(".wp-cycle-image-list .ui-sortable").sortable({ 628 cursor: 'move', 629 items: 'tr.row', 630 handle: 'td.order', 631 cancel: '.fixed,input', 632 update: function () { 633 var order = jQuery('.ui-sortable').sortable('serialize'); 634 jQuery.ajax({ 635 type: "POST", 636 url: "<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php", 637 data: "action=update_field_order&order=" + order 638 }); 639 }}); 640 // jQuery(".ui-sortable").disableSelection(); 641 jQuery("tbody.ui-sortable > tr > td").each(function (index) { 642 jQuery(this).width(jQuery(this).width()); 643 }); 644 }); 645 </script> 646 <?php 647 } 648 649 class WP_CYCLE_WIDGET extends WP_Widget { 650 651 /** 652 * Sets up the widgets name etc 653 */ 654 public function __construct() { 655 $widget_ops = array( 656 'classname' => 'wp_cycle_widget', 657 'description' => 'Wp Cycle Slider Widget', 658 ); 659 parent::__construct('wp_cycle_widget', 'WP CYCLE', $widget_ops); 660 } 661 662 /** 663 * Outputs the content of the widget 664 * 665 * @param array $args 666 * @param array $instance 667 */ 668 public function widget($args, $instance) { 669 echo $args['before_widget']; 670 if (!empty($instance['title'])) { 671 echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; 672 } 673 wp_cycle(); 674 echo $args['after_widget']; 675 // outputs the content of the widget 676 } 677 678 /** 679 * Outputs the options form on admin 680 * 681 * @param array $instance The widget options 682 */ 683 public function form($instance) { 684 // outputs the options form on admin 685 $title = !empty($instance['title']) ? $instance['title'] : __('My Slider', 'text_domain'); 686 ?> 687 <p> 688 <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php _e(esc_attr('Title:')); ?></label> 689 <input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>"> 690 </p> 691 <?php 692 } 693 694 /** 695 * Processing widget options on save 696 * 697 * @param array $new_instance The new options 698 * @param array $old_instance The previous options 699 */ 700 public function update($new_instance, $old_instance) { 701 // processes widget options to be saved 702 $instance = array(); 703 $instance['title'] = (!empty($new_instance['title']) ) ? strip_tags($new_instance['title']) : ''; 704 705 return $instance; 706 } 707 708 } 709 710 if (version_compare(PHP_VERSION, '5.3', '<')) { 711 add_action('widgets_init', create_function('', 'return register_widget("WP_CYCLE_WIDGET");') 712 ); 713 } else { 714 add_action('widgets_init', function() { 715 register_widget('WP_CYCLE_WIDGET'); 716 }); 717 } 718 719 function wp_cycle($args = array(), $content = null) { 720 caza_wp_cycle($args, $content); 721 } 387 require_once plugin_dir_path(__FILE__) . 'includes/wp_cycle_widget.php'; -
cycle-responsive-slider/trunk/readme.txt
r1484087 r1489716 2 2 Contributors: kiranantony 3 3 Donate link: https://www.paypal.me/kiranantony 4 Tags: slideshow, images, jquery cycle2, wp cycle,wp cycle2,responsive slider, 4 Tags: slideshow, images, jquery cycle2, wp cycle,wp cycle2,responsive slider, wp cycle 5 5 Requires at least: 3.0 6 6 Tested up to: 4.6 7 Stable tag: 1. 17 Stable tag: 1.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 66 66 * Added support to `<?php wp_cycle(); ?>` function 67 67 * Added Widget Support 68 == 1.2 = 69 * Improved Code Base (Object Oriented) 70 * Solved Issues with loading large number of images 71 * Solved Issue With Multiple Instance of the slider in a sinlge page
Note: See TracChangeset
for help on using the changeset viewer.