This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

image-slider/slider.php

By: a guest on Mar 17th, 2014  |  syntax: PHP  |  size: 15.54 KB  |  views: 124  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /*
  3. Plugin Name: Image Slider
  4. Plugin URI: http://www.tejuscreative.com/sliderinstructions.docx
  5. Description: This plugin is used to Slide show
  6. Version: 1.0
  7. Author: Dhananjay Singh, Ashwani
  8. Author URI: http://www.tejuscreative.com
  9. License:  GPL2
  10. */
  11. ?>
  12. <?php
  13. /* call a function named dj_myplugin_activate to create a datbase at the activation of plugin*/
  14. register_activation_hook( __FILE__, 'as_tejus_myplugin_activate' );
  15. /* call a function named dj_myplugin_deactivate to delete already craeted datbase at the deactivation of plugin*/
  16. register_deactivation_hook( __FILE__, 'as_tejus_myplugin_deactivate' );
  17. /* craeting daatabase*/
  18. function as_tejus_myplugin_activate(){
  19. global $wpdb;
  20. $as_tejus_table_name = $wpdb->prefix."as_tejus_slideshow";
  21. $sql = "CREATE TABLE  ".$as_tejus_table_name." (
  22.         id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  23.                  path VARCHAR(300),
  24.                  url VARCHAR(300),
  25.                  slideorder INT,
  26.                  caption VARCHAR(200)
  27.       );" ;
  28. $wpdb->query($sql);
  29. }
  30. /*deleting database*/
  31. function as_tejus_myplugin_deactivate(){
  32. global $wpdb;
  33. $as_tejus_table_name = $wpdb->prefix."as_tejus_slideshow";
  34.  $sql= "DROP TABLE IF EXISTS ".$as_tejus_table_name ;
  35.  $wpdb->query($sql);
  36.  }
  37.  add_action('init', 'as_tejus__mysite_init');
  38. /* function to include javascript file*/
  39. function as_tejus__mysite_init() {
  40. wp_enqueue_script( 'jquery' );
  41. $as_tejus_plugin_path = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
  42. wp_enqueue_script('as_tejus_slidejq', $as_tejus_plugin_path . "js/as_tejus_slidejq.js");
  43. wp_enqueue_script('as_tejus_easing', $as_tejus_plugin_path . "js/as_tejus_easing.js");
  44. wp_enqueue_script('as_tejus_anythingslider', $as_tejus_plugin_path . "js/as_tejus_anythingslider.js");
  45. wp_enqueue_script('as_tejus_anythingslidermin', $as_tejus_plugin_path . "js/as_tejus_anythingslidermin.js");
  46. wp_enqueue_style( 'anythingslider',  $as_tejus_plugin_path . "css/anythingslider.css");
  47. }
  48.  add_action('admin_menu','as_tejus_toaddmymenu');
  49. /* to add various menus of plugin to admin panel*/
  50. function as_tejus_toaddmymenu(){
  51. /* adding top level menu */
  52. add_menu_page( 'slide show', 'Image Slider', 'manage_options', 'as_tejus_slideshow', 'as_tejus_callitmyfunction' );
  53. add_submenu_page('as_tejus_slideshow','add option','options','manage_options','as_tejus_slideshow_options','slide_show_option');
  54. }
  55. function as_tejus_callitmyfunction(){
  56. ?>
  57. <div class="wholeform">
  58. <h4> call this function in template file to show slideshow as_tejus_show_slideshow();</h4>
  59. <br/>
  60. <h4>OR use this shortcode [as_tejus_slides] in posts or pages.</h4>
  61. </div>
  62. <div class="wholeform">
  63. <form name="createform" method="post" enctype="multipart/form-data">
  64. <input name="astejusimg" type="file" value="" size="100" >
  65. <label> url </label><input type="text" name="url" VALUE=""/>
  66. <input type="hidden" value="1" name="updatevalueform"/>
  67. <input type="submit" name="createbutton" value="upload" />
  68. </form></div>
  69. <?php
  70. if($_POST['updatevalueform']){
  71. $as_tejus_url = $_POST['url'];
  72. $as_tejus_order = 0;
  73. $as_tejus_caption = $_POST['caption'];
  74. //$djcatformimages = $_POST['djcatimages'];
  75. if(isset($_FILES[ 'astejusimg' ]) && ($_FILES[ 'astejusimg']['size'] > 0)) {
  76. require_once( ABSPATH . 'wp-admin/includes/file.php' );
  77. // Get the type of the uploaded file. This is returned as "type/extension"
  78.  $arr_file_type = wp_check_filetype(basename($_FILES['astejusimg']['name']));
  79.  $uploaded_file_type = $arr_file_type['type'];
  80. // Set an array containing a list of acceptable formats
  81.  $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png');
  82.  // If the uploaded file is the right format
  83.  if(in_array($uploaded_file_type, $allowed_file_types)) {
  84.  // Options array for the wp_handle_upload function. 'test_upload' => false
  85.  $upload_overrides = array( 'test_form' => false );
  86.  // Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array
  87.   $returnigurlofimage = wp_handle_upload($_FILES['astejusimg'], $upload_overrides);
  88.  }
  89. if($returnigurlofimage['url']){ $savethisimageurl = $returnigurlofimage['url'] ;
  90. global $wpdb;
  91. $as_tejus_table_name = $wpdb->prefix."as_tejus_slideshow";
  92. $sql = "INSERT INTO ".$as_tejus_table_name."  VALUES (DEFAULT,'{$savethisimageurl}','{$as_tejus_url}',0,'{$as_tejus_caption}') ";
  93. $wpdb->query($sql);
  94. }
  95. }
  96. }
  97. $as_tejus_plugin_path = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
  98. global $wpdb;
  99. $as_tejus_table_name = $wpdb->prefix."as_tejus_slideshow";
  100. $sql= "SELECT * FROM ". $as_tejus_table_name;
  101. $djalladdedimagestoslides = $wpdb->get_results($sql, ARRAY_A);
  102. ?>
  103. <div class="wholecategorywimagebox">
  104. <table class="widefat" style="width: 80%">
  105. <thead>
  106. <tr>
  107. <th>image id</th>
  108. <th>IMAGE</th>
  109. <th>url</th>
  110. <th>order</th>
  111. <th>caption</th>
  112. <th>UPDATE<th>
  113. <th>Delete</th>
  114. </tr>
  115. </thead>
  116. <tfoot>
  117. <tr>
  118. <th>image id</th>
  119. <th>IMAGE</th>
  120. <th>url</th>
  121. <th>order</th>
  122. <th>caption</th>
  123. <th>UPDATE<th>
  124. <th>Delete</th>
  125. </tr>
  126. </tfoot>
  127. <tbody>
  128. <?php
  129. /*
  130. if($_GET['typeofform']=="updateanddelete"){
  131. if($_GET['task']=="edit"){ $sql = "UPDATE ".$as_tejus_table_name." SET slideorder = ".$_GET['slideorder']." WHERE id = '".$_GET['id']."'";
  132. echo $sql;
  133. $wpdb->query($sql);}
  134.  
  135. if($_GET['task']=="delete"){ $query = "DELETE FROM ".$as_tejus_table_name." WHERE id ='".$_GET['id']."'";
  136. $wpdb->query($query); }
  137. }*/
  138. foreach($djalladdedimagestoslides as $djalladdedimagestoslide){
  139. echo '<tr>';
  140. echo  '<td id="imageidis'.$djalladdedimagestoslide['id'].'">'.$djalladdedimagestoslide['id'].'</td><td><img src="'.$djalladdedimagestoslide['path'].'" width="50" height="50"/></td><td><input type="text" name="url" value="'.$djalladdedimagestoslide['url'].' " id="urlimagesis'.$djalladdedimagestoslide['id'].'"></td><td><input id="orderofimage'.$djalladdedimagestoslide['id'].'" type="text" name="order" value="'.$djalladdedimagestoslide['slideorder'].'"></td><td><input type="text" name="caption" value="'.$djalladdedimagestoslide['caption'].' " id="captionimagesis'.$djalladdedimagestoslide['id'].'"></td><td><input type="button" name="update" id = "as_tejus_update'.$djalladdedimagestoslide['id'].'" value="update" ></td><td><input type="button" name="delete" value="delete" id = "as_tejus_delete'.$djalladdedimagestoslide['id'].'"  ></td>';
  141. echo '</tr>';
  142. }
  143. ?>
  144.  </tbody>
  145. </table></div>
  146. <script>
  147.  jQuery(function($){
  148.  $.ajaxSetup({
  149.   error:function(x,e){
  150.    if(x.status==0){
  151.    alert('You are offline!!\n Please Check Your Network.');
  152.    }else if(x.status==404){
  153.    alert('Requested URL not found.');
  154.    }else if(x.status==500){
  155.    alert('Internel Server Error.');
  156.    }else if(e=='parsererror'){
  157.    alert('Error.\nParsing JSON Request failed.');
  158.    }else if(e=='timeout'){
  159.    alert('Request Time out.');
  160.    }else {
  161.    alert('Unknow Error.\n'+x.responseText);
  162.    }
  163.   }
  164.  });
  165. <?php
  166. global $wpdb;
  167. $as_tejus_table_name = $wpdb->prefix."as_tejus_slideshow";
  168. $sql= "SELECT * FROM ". $as_tejus_table_name;
  169. $djalladdedimagestoslides = $wpdb->get_results($sql, ARRAY_A);
  170. foreach($djalladdedimagestoslides as $djalladdedimagestoslide){
  171. ?>
  172. $("#as_tejus_update<?php echo $djalladdedimagestoslide['id']; ?>").click( function (){
  173. var id<?php echo $djalladdedimagestoslide['id']; ?> = $("#<?php echo 'imageidis'.$djalladdedimagestoslide['id']; ?>").html();
  174. var order<?php echo $djalladdedimagestoslide['id']; ?> = $("#<?php echo 'orderofimage'.$djalladdedimagestoslide['id']; ?>").val();
  175. var url<?php echo $djalladdedimagestoslide['id']; ?> = $("#<?php echo 'urlimagesis'.$djalladdedimagestoslide['id']; ?>").val();
  176. var caption<?php echo $djalladdedimagestoslide['id']; ?> = $("#<?php echo 'captionimagesis'.$djalladdedimagestoslide['id']; ?>").val();
  177. var datastring<?php echo $djalladdedimagestoslide['id']; ?> = "id="+id<?php echo $djalladdedimagestoslide['id']; ?>+"&order="+order<?php echo $djalladdedimagestoslide['id']; ?>+"&url="+url<?php echo $djalladdedimagestoslide['id']; ?>+"&caption="+caption<?php echo $djalladdedimagestoslide['id']; ?>+"&action=update";
  178. //alert(datastring<?php echo $djalladdedimagestoslide['id']; ?>);
  179.  $.ajax({
  180.       type: "POST",
  181.       url: "<?php echo $as_tejus_plugin_path; ?>sliderupdate.php",
  182.       data: datastring<?php echo $djalladdedimagestoslide['id']; ?>,
  183.        
  184.       success: function(html) {
  185.        
  186.         window.location.replace("<?php echo $_SERVER['REQUEST_URI']; ?>");
  187.        
  188.       }
  189.      }); });
  190.          
  191.          $("#as_tejus_delete<?php echo $djalladdedimagestoslide['id']; ?>").click( function (){
  192.        
  193. var id<?php echo $djalladdedimagestoslide['id']; ?> = $("#<?php echo 'imageidis'.$djalladdedimagestoslide['id']; ?>").html();
  194. var datastring<?php echo $djalladdedimagestoslide['id']; ?> = "id="+id<?php echo $djalladdedimagestoslide['id']; ?>+"&action=delete";
  195. //alert(datastring<?php echo $djalladdedimagestoslide['id']; ?>);
  196.  $.ajax({
  197.       type: "POST",
  198.       url: "<?php echo $as_tejus_plugin_path; ?>sliderupdate.php",
  199.       data: datastring<?php echo $djalladdedimagestoslide['id']; ?>,
  200.  
  201.       success: function(html) {
  202.        
  203.        window.location.replace("<?php echo $_SERVER['REQUEST_URI']; ?>");
  204.        
  205.       }
  206.      }); });
  207. <?php } ?>
  208.  
  209. });
  210.  </script>
  211. <?php } ?>
  212. <?php function as_tejus_show_slideshow(){
  213. ?>
  214. <ul id="slider2">
  215. <?php
  216.                 global $wpdb;
  217.                 $as_tejus_table_name = $wpdb->prefix."as_tejus_slideshow";
  218.                 $sql ='SELECT * from '.$as_tejus_table_name.' ORDER BY slideorder ASC';
  219.                 $djalladdedimagestoslides = $wpdb->get_results($sql, ARRAY_A);
  220.                 $counter=10;
  221.                 foreach($djalladdedimagestoslides as $djalladdedimagestoslide){
  222.                 $counter++;
  223.         ?>
  224.   <li class="pane<?php echo $counter;?>">
  225.   <div class="textSlide">
  226.     <a href="<?php echo $djalladdedimagestoslide['url'];?>" target="_blank"><img src="<?php echo $djalladdedimagestoslide['path']; ?>"class="<?php echo get_option('my_quoteSlide'); ?>"></a>
  227.         <h3><?php echo $djalladdedimagestoslide['caption'];?></h3>
  228.         </div>
  229.         <?php } ?>
  230.   </li>
  231.  </ul>
  232.  <script type="text/javascript">
  233.         $(function(){
  234.  $('#slider2') // Demo 2 code, using FX full control
  235.   .anythingSlider({
  236.    resizeContents      : <?php echo get_option('resize'); ?>,
  237.    autoPlay            : <?php echo get_option('auto'); ?>,
  238.    delay                           : <?php if(get_option('delay_time')){ echo get_option('delay_time'); }else{ echo 10000;} ?>,
  239.    buildArrows         : <?php echo get_option('navigation'); ?>,
  240.    buildNavigation     : <?php echo get_option('Show_Navigation'); ?>,
  241.    buildStartStop      : <?php echo get_option('Show_start_button'); ?>,
  242.    toggleArrows        : <?php echo get_option('Show_Navigation_hover'); ?>,
  243.    toggleControls      : <?php echo get_option('Show_start_hover'); ?>
  244.   })
  245.   .anythingSliderFx({
  246.    // base FX definitions can be mixed and matched in here too.
  247.    '.fade' : [ 'fade' ],
  248.  
  249.    // for more precise control, use the "inFx" and "outFx" definitions
  250.    // inFx = the animation that occurs when you slide "in" to a panel
  251.    inFx : {
  252.     '.textSlide h3'  : { opacity: 0.8, duration: 400, easing : 'easeOutBounce' },
  253.     '.textSlide li'  : { opacity: 1, left : 0, duration: 400 },
  254.     '.textSlide img' : { opacity: 1, duration: 400},
  255.     '.quoteSlide'    : { top : 0, duration: 400, easing : 'easeOutElastic' },
  256.     '.expand'        : { width: '100%', top: '0%', left: '0%', duration: 400, easing : 'easeOutBounce' }
  257.    },
  258.    // out = the animation that occurs when you slide "out" of a panel
  259.    // (it also occurs before the "in" animation)
  260.    outFx : {
  261.     '.textSlide h3'      : { opacity: 0, duration: 350 },
  262.     '.textSlide li:odd'  : { opacity: 0, left : '-200px', duration: 350 },
  263.     '.textSlide li:even' : { opacity: 0, left : '200px',  duration: 350 },
  264.     '.textSlide img'     : { opacity: 0, duration: 350 },
  265.     '.quoteSlide:first'  : { top : '-500px', duration: 350 },
  266.     '.quoteSlide:last'   : { top : '500px', duration: 350 },
  267.     '.expand'            : { width: '10%', top: '50%', left: '50%', duration: 350 }
  268.    }
  269.   });
  270. });
  271.         </script>
  272. <?php
  273. } ?>
  274. <?php add_shortcode( 'as_tejus_slides', 'as_tejus_show_slideshow' ); ?>
  275. <?php function slide_show_option(){
  276.  if ( $_POST['update_effctoptions'] == 'true' ) { effctoptions_update(); }
  277. ?>
  278.  <form method="POST" id="admin-theme" action="">
  279. <input type="hidden" name="update_effctoptions" value="true" />
  280. <table border="0" cellspacing="15" cellpadding="0">
  281. <tr><td colspan="2"><h2>Slider Show Option</h2></td></tr>
  282. <tr><td>Slide Effect</td><td>
  283. <select name="my_quoteSlide">
  284. <option value="quoteSlide" <?php if( get_option('my_quoteSlide')=="quoteSlide"){echo "selected";} ?> id="quoteSlide">quoteSlide</option>
  285. <option value="fade" <?php if( get_option('my_quoteSlide')=="fade"){echo "selected";} ?> id="fade" >fade</option>
  286. <option value="expand" <?php if( get_option('my_quoteSlide')=="expand"){echo "selected";} ?> id="expand" >expand</option>
  287. </select>
  288. </td></tr>
  289. <tr>
  290. <td>Auto play</td>
  291. <td>
  292. <select name="auto">
  293. <option id="true" <?php  if( get_option('auto')=="true"){echo "selected";} ?> >true</option>
  294. <option id="false" <?php  if( get_option('auto')=="false"){echo "selected";}?> >false</option>
  295. </select>
  296. </td>
  297. </tr>
  298. <tr>
  299. <td>Delay Time( In mili seconds)</td>
  300. <td><input type="text" id="dtime" name="dtime" size="10" value="<?php echo get_option('delay_time');?>"></td>
  301. </tr>
  302. <tr>
  303. <td>Navigation Arrows</td>
  304. <td>
  305. <select name="navigation">
  306. <option id="true" <?php  if( get_option('navigation')=="true"){echo "selected";} ?> >true</option>
  307. <option id="false" <?php  if( get_option('navigation')=="false"){echo "selected";} ?> >false</option>
  308. </select>
  309. </td>
  310. </tr>
  311. </tr>
  312. <tr>
  313. <td>Auto resize</td>
  314. <td>
  315. <select name="resize">
  316. <option id="true" <?php  if( get_option('resize')=="true"){echo "selected";} ?> >true</option>
  317. <option id="false" <?php  if( get_option('resize')=="false"){echo "selected";} ?> >false</option>
  318. </select>
  319. </td>
  320. </tr>
  321. <tr>
  322. <td>Show Navigation</td>
  323. <td>
  324. <select name="Show_Navigation">
  325. <option id="true" <?php  if( get_option('Show_Navigation')=="true"){echo "selected";} ?> >true</option>
  326. <option id="false" <?php  if( get_option('Show_Navigation')=="false"){echo "selected";} ?> >false</option>
  327. </select>
  328. </td>
  329. </tr>
  330. <tr>
  331. <td>Show Navigation on hover</td>
  332. <td>
  333. <select name="Show_Navigation_hover">
  334. <option id="true" <?php  if( get_option('Show_Navigation_hover')=="true"){echo "selected";} ?> >true</option>
  335. <option id="false" <?php  if( get_option('Show_Navigation_hover')=="false"){echo "selected";} ?> >false</option>
  336. </select>
  337. </td>
  338. </tr>
  339. <tr>
  340. <td>Show start button</td>
  341. <td>
  342. <select name="Show_start_button">
  343. <option id="true" <?php  if( get_option('Show_start_button')=="true"){echo "selected";} ?> >true</option>
  344. <option id="false" <?php  if( get_option('Show_start_button')=="false"){echo "selected";} ?> >false</option>
  345. </select>
  346. </td>
  347. </tr>
  348. <tr>
  349. <td>Show start button on hover</td>
  350. <td>
  351. <select name="Show_start_hover">
  352. <option id="true" <?php  if( get_option('Show_start_hover')=="true"){echo "selected";} ?> >true</option>
  353. <option id="false" <?php  if( get_option('Show_start_hover')=="false"){echo "selected";} ?> >false</option>
  354. </select>
  355. </td>
  356. </tr>
  357. </table>
  358. <input type="submit" name="submit" value="Update Options" />
  359. </form>
  360. <?php }?>
  361. <?php function effctoptions_update()
  362. {
  363. update_option('my_quoteSlide',  $_POST['my_quoteSlide']);
  364. update_option('auto',  $_POST['auto']);
  365. update_option('delay_time',  $_POST['dtime']);
  366. update_option('navigation',  $_POST['navigation']);
  367. update_option('Show_Navigation_hover',  $_POST['Show_Navigation_hover']);
  368. update_option('resize',  $_POST['resize']);
  369. update_option('Show_Navigation',  $_POST['Show_Navigation']);
  370. update_option('Show_start_button',  $_POST['Show_start_button']);
  371. update_option('Show_start_hover',  $_POST['Show_start_hover']);
  372.  }?>
clone this paste RAW Paste Data