khardwick

slider.php

Aug 10th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. <?php
  2.  
  3. $imgTypes = array('jpeg', 'jpg', 'png', 'gif'); //The extensions of the images that you want the plugin to read
  4. $sliderEffects = array('boxes-zoomOut', 'boxesDiagonal-zoomOut', 'verticalStripes-openBookY', 'horizontalStripes-openBookX'); //The effects in the order you wish them to appear
  5. $captionEffects = array('openBookY', 'fromLeft', 'openBookX', 'zoomOut'); //The effects in the order you wish them to appear for the captions
  6. $randomOrder = true; // If is set to true the order of the images will be random each time it load
  7.  
  8.  
  9. function make_slider($id, $folder, $sliderEffects = true, $captionEffects = false){
  10.  
  11. if( $sliderEffects == false ){
  12. global $sliderEffects;
  13. }
  14. if( $captionEffects == false ){
  15. global $captionEffects;
  16. }
  17.  
  18. $list = getDirectoryList($folder);
  19.  
  20. if(sizeof($list) == 0){
  21. echo "<div style='width:100%;text-align:center;color:red;'>";
  22. echo "<h4>No images were found in this folder: $folder</h4>";
  23. echo "</div>";
  24. return;
  25. }
  26.  
  27. $currentEffect = 0;
  28. $currentEffect2 = 0;
  29.  
  30. echo "<div class='as_slider' id='$id'>";
  31.  
  32. foreach ($list as $key => $value) {
  33. $extension = preg_split('/\.(?=[^.]*$)/', $value);
  34. $title = $extension[0];
  35. $caption = "data-caption='$title'";
  36.  
  37. if( substr($title, 1, 1) == "-" ){
  38. $title = substr($title, 2);
  39. $caption = "data-caption='$title'";
  40. }
  41.  
  42. //If the image name ends with a '--' then do NOT put a caption
  43. if( substr($title, -2) == '--' ){
  44. $caption = "";
  45. }
  46.  
  47. $fx = $sliderEffects[$currentEffect];
  48. $fxCaption = $captionEffects[$currentEffect2];
  49.  
  50. $caption = str_replace("<:", "</", $caption);
  51.  
  52. echo "<img src='$folder/$value' data-effect='$fx' data-captioneffect='$fxCaption' $caption />";
  53.  
  54. $currentEffect++;
  55. if( $caption != "" ){
  56. $currentEffect2++;
  57. }
  58. if($currentEffect >= count($sliderEffects)){
  59. $currentEffect = 0;
  60. }
  61. if($currentEffect2 >= count($captionEffects)){
  62. $currentEffect2 = 0;
  63. }
  64. }
  65.  
  66. echo "</div>";
  67. }
  68.  
  69. function getDirectoryList ($directory) {
  70. global $imgTypes;
  71. global $randomOrder;
  72.  
  73. if( !is_dir($directory)){
  74. return array();
  75. }
  76.  
  77. $results = array();
  78.  
  79. $handler = opendir($directory);
  80.  
  81. while ($file = readdir($handler)) {
  82. if ($file != "." && $file != ".." && $file != ".DS_Store") {
  83. $extension = preg_split('/\./',$file);
  84. $extension = strtolower($extension[count($extension)-1]);
  85.  
  86. if(array_search($extension,$imgTypes) !== FALSE){
  87. $results[] = $file;
  88. }
  89.  
  90. }
  91. }
  92. if( $randomOrder ){
  93. shuffle($results);
  94. }else{
  95. sort($results);
  96. }
  97.  
  98. closedir($handler);
  99. return $results;
  100. }
  101.  
  102. ?>
  103.  
  104. <!--
  105. THE JUST HTML VERSION
  106. <div class="as_slider" id="slider1">
  107. <img src="images/img2.jpeg" data-effect="boxesOrder-zoomOut" data-captioneffect="fade" data-caption="<h4>Caption here. </h4>" />
  108. <img src="images/img3.jpeg" data-effect="boxesDiagonal" />
  109. <img src="images/img1.jpeg" data-effect="boxes-zoomOut" />
  110. </div>
  111. -->
Advertisement
Add Comment
Please, Sign In to add comment