Posted By

Affix on 01/16/11


Tagged

wordpress


Versions (?)

Wordpress Linux Kernel Version


 / Published in: PHP
 

URL: affix.me

  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. ?>

Report this snippet  

You need to login to post a comment.