A tumblelog CMS built on AJAX, PHP and MySQL.

kodrs.php 980B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. Plugin Name: kodrs
  4. Plugin URI: http://plugins.gelatocms.com/kodrs/
  5. Description: Geshify your source codes
  6. Author: Pedro Santana
  7. Author URI: http://www.pecesama.net/
  8. Version: 0.1
  9. */
  10. class kodrs extends plugins {
  11. function kodrs() {
  12. if (!defined('GESHI_VERSION')) {
  13. require_once("geshi/geshi.php");
  14. }
  15. $this->addAction('post_content', 'source_code_beautifier');
  16. }
  17. function source_code_beautifier() {
  18. global $rows;
  19. $text = $rows[0]['Body'];
  20. $result = preg_replace_callback("/<code\s+.*lang\s*=\"(.*)\">(.*)<\/code>/siU",
  21. array('kodrs', 'replace_with_geshi'),
  22. $text);
  23. $rows[0]['Body'] = $result;
  24. }
  25. static function replace_with_geshi($matches) {
  26. $lang = strtolower($matches[1]) ;
  27. $code = trim($matches[2]);
  28. $geshi = new geshi($code, (isset($lang)) ? $lang : "");
  29. $geshi->enable_classes(false);
  30. $geshi->set_overall_id('geshi_code');
  31. return @$geshi->parse_code();
  32. }
  33. }
  34. ?>