spider_random_post

The Business Responsive spider random post class.

Defined (1)

The class is defined in the following location(s).

/admin/widgets/Spider_Random_Post.php  
  1. class spider_random_post extends WP_Widget { 
  2.  
  3. // Constructor // 
  4.  
  5. function spider_random_post() { 
  6. $widget_ops = array( 'classname' => 'spider_random_post', 'description' => 'Spider Random Post allows you to show posts in a random order in a sidebar.' ); // Widget Settings 
  7. $control_ops = array( 'id_base' => 'spider_random_post' ); // Widget Control Settings 
  8. $this->WP_Widget( 'spider_random_post', 'Spider Random Post', $widget_ops, $control_ops ); // Create the widget 
  9.  
  10. // Extract Args // 
  11.  
  12. function widget($args, $instance) { 
  13. extract( $args ); 
  14. $title=$instance['title'];  
  15. $url = plugins_url(); 
  16. global $spider_random_post_id; 
  17. // Before widget // 
  18.  
  19.  
  20. echo $before_widget; 
  21.  
  22. // Title of widget // 
  23.  
  24. if ( $title ) { echo $before_title . $title . $after_title; } 
  25.  
  26. // Widget output // 
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. if($spider_random_post_id==0) { 
  36. /////// print script code one time 
  37. ?> 
  38. <script type="text/javascript"> 
  39.  
  40. function autoUpdate(id, time, category, limit, style, text_for_insert) { 
  41.  
  42. document.getElementById('randarticle_'+id).innerHTML=text_for_insert; 
  43. var t=Math.floor(Math.random()*4+1); 
  44.  
  45.  
  46.  
  47. if (style==5) { 
  48.  
  49. style=t; 
  50.  
  51.  
  52.  
  53. if (style == 1) { 
  54. jQuery("#randarticle_"+id+"").ready(function() 
  55. {  
  56. jQuery("#randarticle_"+id+"").animate({ 
  57.  
  58. opacity: 1,  
  59. margin:'0in' ,  
  60. fontSize: "1em" 
  61.  
  62. }, 1000 ); 
  63. }); 
  64. setTimeout("style("+id+", "+style+", "+time+', '+category+', '+limit+")", time*1000);  
  65.  
  66.  
  67. if (style == 2) { 
  68. jQuery("#randarticle_"+id+"").ready(function() 
  69. jQuery("#randarticle_"+id+"").animate({ 
  70.  
  71. opacity: 1,  
  72.  
  73. fontSize: "1.2em" 
  74.  
  75. }, 700 ); 
  76.  
  77. jQuery("#randarticle_"+id+"").animate({ 
  78.  
  79. opacity: 1,  
  80.  
  81. fontSize: "1em" 
  82.  
  83. } , 300); 
  84. }); 
  85. setTimeout("style("+id+", "+style+", "+time+', '+category+', '+limit+")", time*1000); 
  86.  
  87. if (style == 3) { 
  88. jQuery("#randarticle_"+id+"").ready(function() 
  89. jQuery("#randarticle_"+id+"").animate({ 
  90.  
  91. opacity: 1,  
  92.  
  93. fontSize: "1em" 
  94.  
  95. }, 1000 ); 
  96. }); 
  97. setTimeout("style("+id+", "+style+", "+time+', '+category+', '+limit+")", time*1000);  
  98.  
  99. if (style == 4) { 
  100. document.getElementById("randarticle_"+id).style.overflow="hidden"; 
  101. jQuery("#randarticle_"+id+"").ready(function() 
  102. jQuery("#randarticle_"+id+"").animate({ 
  103. width: "100%",  
  104. opacity: 1,  
  105. fontSize: "1em" 
  106.  
  107. }, 1000); 
  108. }); 
  109.  
  110. setTimeout("style("+id+", "+style+", "+time+', '+category+', '+limit+")", time*1000);  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. function style(id, style, time, category, limit) 
  118. {  
  119. if (style == 1) 
  120. jQuery("#randarticle_"+id+"").ready(function() 
  121.  
  122. jQuery("#randarticle_"+id+"").animate({ 
  123.  
  124. opacity: 0,  
  125.  
  126. marginLeft: "0.6in",  
  127. fontSize: "1em" 
  128.  
  129. }, 1000 ); 
  130.  
  131.  
  132. });  
  133. if (style == 2) 
  134.  
  135. jQuery("#randarticle_"+id+"").ready(function() 
  136.  
  137. jQuery("#randarticle_"+id+"").animate({ 
  138.  
  139. opacity: 0,  
  140.  
  141.  
  142. fontSize: "0em" 
  143.  
  144. }, 1000 ); 
  145.  
  146.  
  147. });  
  148.  
  149.  
  150. if (style == 3) 
  151. jQuery("#randarticle_"+id+"").ready(function() 
  152.  
  153. jQuery("#randarticle_"+id+"").animate({ 
  154.  
  155. opacity: 0,  
  156.  
  157.  
  158. fontSize: "1em" 
  159.  
  160. }, 1000 ); 
  161.  
  162.  
  163. });  
  164.  
  165. if (style == 4) 
  166. jQuery("#randarticle_"+id+"").ready(function() 
  167.  
  168. jQuery("#randarticle_"+id).animate({ 
  169. width: "0.0%" 
  170.  
  171. }, 1000); 
  172. });  
  173.  
  174.  
  175. document.getElementById("randarticle_"+id).style.overflow="hidden";  
  176. setTimeout("ajax_for_post("+id+", "+time+", "+category+", "+limit+", "+style+")", 2000); 
  177.  
  178. function ajax_for_post(id, time, category, limit, style) { 
  179. jQuery.ajax({ 
  180. url: "<?php echo admin_url( 'admin-ajax.php' )."?action=sprandom_post&categori_id="; ?>"+category+"&count_pages="+limit+"&rand="+Math.floor(Math.random()*100000000000000) 
  181. }).done(function(responseText) {  
  182. autoUpdate(id, time, category, limit, style, responseText); 
  183. }); 
  184.  
  185. function Update(id, time, category, limit, style) 
  186.  
  187. document.getElementById('randarticle_'+id).style.display='none'; 
  188. jQuery.fx.interval = 1; 
  189.  
  190. jQuery("#randarticle_"+id+"").ready(function() { 
  191.  
  192. jQuery("#randarticle_"+id+"").fadeIn( 1000 ); 
  193. });  
  194.  
  195. var xmlHttp; 
  196. try{  
  197. xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari 
  198. catch (e) { 
  199. try{ 
  200. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer 
  201. catch (e) { 
  202. try{ 
  203. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
  204. catch (e) { 
  205. alert("No AJAX!?"); 
  206. return false; 
  207.  
  208. xmlHttp.onreadystatechange=function() { 
  209. if(xmlHttp.readyState==4) { 
  210. document.getElementById('randarticle_'+id).innerHTML=xmlHttp.responseText; 
  211. <?php 
  212. if ($instance['AutoUpdate'] ==1 ) 
  213. echo "autoUpdate(id, time, category, limit, style, xmlHttp.responseText);"; 
  214. ?> 
  215.  
  216. xmlHttp.open("GET", "<?php echo admin_url( 'admin-ajax.php' )."?action=sprandom_post&categori_id="; ?>"+category+"&count_pages="+limit+"&rand="+Math.floor(Math.random()*100000000000000), true); 
  217. xmlHttp.send(null); 
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225. </script> 
  226. <?php  
  227.  
  228.  
  229. }// enf if  
  230.  
  231.  
  232.  
  233. ?> 
  234. <div id="randarticle_<?php echo $spider_random_post_id ?>" > 
  235. <?php 
  236. global $spider_random_post_id; 
  237. echo "<script type='text/javascript'> Update(".$spider_random_post_id.", ".$instance['Updating_Time'].", ".$instance['Category'].", ".$instance['quantity_of_posts'].", ".$instance['Style_sra']."); </script>"; 
  238.  
  239. $spider_random_post_id++;  
  240. ?> 
  241. </div> 
  242. <?php 
  243. // After widget // 
  244.  
  245. echo $after_widget; 
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252. // Update Settings // 
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259. function update($new_instance, $old_instance) { 
  260. $instance['title'] = strip_tags($new_instance['title']); // title 
  261. $instance['Category'] = $new_instance['Category']; /// Post quantity 
  262. $instance['quantity_of_posts'] = $new_instance['quantity_of_posts']; /// Post quantity 
  263. $instance['AutoUpdate'] = $new_instance['AutoUpdate']; /// update automatic or no 
  264. $instance['Style_sra'] = $new_instance['Style_sra']; // custom style 
  265. $instance['Updating_Time'] = $new_instance['Updating_Time']; /// time for updating posts or post 
  266.  
  267. return $instance; /// return new value of parametrs 
  268.  
  269.  
  270.  
  271.  
  272.  
  273. // Widget Control Panel // 
  274.  
  275. function form($instance) { 
  276. $url = plugins_url(); //url plugin 
  277.  
  278. $defaults = array( 'title' => '', 'Category' => '1', 'quantity_of_posts' => '1', 'AutoUpdate' => '1', 'Style_sra' =>'1', 'Updating_Time' => '10'); 
  279. $instance = wp_parse_args( (array) $instance, $defaults ); ?> 
  280.  
  281. <p> 
  282. <label for="<?php echo $this->get_field_id('title'); ?>">Title:</label> 
  283. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>'" type="text" value="<?php echo $instance['title']; ?>" /> 
  284. </p> 
  285. <table width="100%" class="paramlist admintable" cellspacing="1"> 
  286. <tbody> 
  287.  
  288. <tr> 
  289. <td style="width:120px" class="paramlist_key"><span class="editlinktip"><label style="font-size:10px" id="paramsstandcatid-lbl" for="Category" class="hasTip">Select Category</label></span></td> 
  290. <td class="paramlist_value"> 
  291. <select name="<?php echo $this->get_field_name('Category'); ?>" id="<?php echo $this->get_field_id('category') ?>" style="font-size:10px" class="inputbox"> 
  292. <option value="0">Select Category</option> 
  293.  
  294. <?php  
  295. $categories=get_categories(); 
  296. $category_count=count($categories); 
  297. for($i=0;$i<$category_count;$i++) 
  298. ?> 
  299.  
  300.  
  301. <option value="<?php echo $categories[$i]->term_id?>" <?php if($instance['Category']==$categories[$i]->term_id) echo 'selected="selected"'; ?>><?php echo $categories[$i]->name ?></option> 
  302.  
  303. <?php 
  304. ?> 
  305. </select> 
  306. </td> 
  307. </tr> 
  308. <tr> 
  309. <tr><td><br /></td></tr> 
  310. <td style="width:120px" class="paramlist_key"><span class="editlinktip"><label style="font-size:10px" id="paramsrand_show-lbl" for="quantity_of_posts">Quantity of Posts:</label></span></td> 
  311. <td class="paramlist_value"><input type="text" name="<?php echo $this->get_field_name('quantity_of_posts'); ?>" id="<?php echo $this->get_field_id('quantity_of_posts') ?>" value="<?php echo $instance['quantity_of_posts']; ?>" class="text_area" size="3"></td> 
  312. </tr> 
  313. <tr><td><br /></td></tr> 
  314. <tr> 
  315. <td style="width:120px" class="paramlist_key"><span class="editlinktip"><label style="font-size:10px" for="autoupdate">Auto Update</label></span></td> 
  316. <td class="paramlist_value"><span id="cuca"></span> 
  317. <input type="radio" name="<?php echo $this->get_field_name('AutoUpdate'); ?>" value="0" <?php if($instance['AutoUpdate']==0) echo 'checked="checked"';?> onchange="document.getElementById('<?php echo $this->get_field_id('Updating_Time') ?>time_sec').setAttribute('style', 'display:none')" id="showup0"> No 
  318. <input type="radio" name="<?php echo $this->get_field_name('AutoUpdate'); ?>" value="1" <?php if($instance['AutoUpdate']==1) echo 'checked="checked"';?> onchange="document.getElementById('<?php echo $this->get_field_id('Updating_Time') ?>time_sec').removeAttribute('style');" id="showup1"> Yes 
  319.  
  320. </td> 
  321. </tr> 
  322. <tr><td><br /></td></tr> 
  323. <tr> 
  324. <td width="120px" class="paramlist_key"><span class="editlinktip"><label style="font-size:10px" id="paramsstyle-lbl" for="Style_sra">Visualization</label></span></td> 
  325. <td class="paramlist_value"> 
  326. <select name="<?php echo $this->get_field_name('Style_sra'); ?>" id="<?php echo $this->get_field_id('Style_sra') ?>" class="inputbox"> 
  327. <option value="1" <?php if($instance['Style_sra']==1) echo 'selected="selected"'; ?>>Style 1</option> 
  328. <option value="2" <?php if($instance['Style_sra']==2) echo 'selected="selected"'; ?>>Style 2</option> 
  329. <option value="3" <?php if($instance['Style_sra']==3) echo 'selected="selected"'; ?>>Style 3</option> 
  330. <option value="4" <?php if($instance['Style_sra']==4) echo 'selected="selected"'; ?>>Style 4</option> 
  331. <option value="5" <?php if($instance['Style_sra']==5) echo 'selected="selected"'; ?>>Random</option> 
  332. </select></td> 
  333. </tr> 
  334. <tr><td><br /></td></tr> 
  335. <tr id="<?php echo $this->get_field_id('Updating_Time') ?>time_sec" <?php if(!$instance['AutoUpdate']==1) echo 'style="display:none"'; ?>> 
  336. <td style="width:120px" class="paramlist_key"><span class="editlinktip"><label style="font-size:10px" for="Updating_Time">Time of update(sec)</label></span></td> 
  337. <td class="paramlist_value"> 
  338. <input type="text" name="<?php echo $this->get_field_name('Updating_Time'); ?>" id="<?php echo $this->get_field_id('Updating_Time') ?>" value="<?php echo $instance['Updating_Time']; ?>" size="3"> 
  339. </td> 
  340. </tr> 
  341. </tbody></table> 
  342. <?php } 
  343.  
  344.