Wordpress Linux Kernel Version


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. /*
  3. Plugin Name: Stable Linux Kernel Version Widget
  4. Plugin URI: http://affix.me/
  5. Description: Grab the latest linux kernel version from kernel.org in a very hacky way
  6. Author: Keiran Smith
  7. Version: 1.0.0
  8. Author URI: http://affix.me/
  9. */
  10.  
  11. ####
  12. # Function to Split a String between strings
  13. ####
  14. function split_tag($haystack,$start,$end) {
  15. if (strpos($haystack,$start) === false || strpos($haystack,$end) === false) {
  16. return false;
  17. } else {
  18. $start_position = strpos($haystack,$start)+strlen($start);
  19. $end_position = strpos($haystack,$end);
  20. return substr($haystack,$start_position,$end_position-$start_position);
  21. }
  22. }
  23.  
  24. ####
  25. # Function to display our Widget
  26. ####
  27. function widget_getKernelVersion() {
  28. $page = file_get_contents("http://kernel.org");
  29. $version = split_tag($page, "http://www.kernel.org/pub/linux/kernel/v2.6/linux-", ".tar.bz2");
  30.  
  31. echo "<h2 class=\"widgettitle\">Current Stable Kernel</h2>";
  32. echo "<div align=\"center\"><h2><a href=\"http://www.kernel.org/pub/linux/kernel/v2.6/linux-$version.tar.bz2\">$version</a></h2></div>";
  33. }
  34.  
  35. ####
  36. # Function to initialize our widget
  37. ####
  38. function kernelWidget_init()
  39. {
  40. register_sidebar_widget(__('Kernel Version'), 'widget_getKernelVersion');
  41. }
  42.  
  43.  
  44. add_action("plugins_loaded", "kernelWidget_init");
  45. ?>

URL: affix.me

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.