A tumblelog CMS built on AJAX, PHP and MySQL.

kodrs.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. class kodrs extends plugins {
  3. function kodrs() {
  4. if (!defined('GESHI_VERSION')) {
  5. require_once("geshi/geshi.php");
  6. }
  7. $this->addAction('post_content', 'source_code_beautifier');
  8. }
  9. function info()
  10. {
  11. return array(
  12. 'name' => 'kodrs',
  13. 'version' => '0.1',
  14. 'url' => 'http://plugins.gelatocms.com/kodrs/',
  15. 'author' => 'Pedro Santana',
  16. 'authorurl' => 'http://www.pecesama.net/',
  17. 'license' => 'MIT License',
  18. 'description' => 'Geshify your source codes',
  19. );
  20. }
  21. function source_code_beautifier() {
  22. global $rows;
  23. if(count($rows)>0){
  24. foreach($rows as $key=>$post){
  25. if($post["postType"]=="post"){
  26. $text = $rows[$key]['Body'];
  27. $result = preg_replace_callback("/<code\s+.*lang\s*=\"(.*)\">(.*)<\/code>/siU",
  28. array('kodrs', 'replace_with_geshi'),
  29. $text
  30. );
  31. $rows[$key]['Body'] = $result;
  32. }
  33. }
  34. }
  35. }
  36. static function replace_with_geshi($matches) {
  37. $lang = strtolower($matches[1]) ;
  38. $code = trim($matches[2]);
  39. $geshi = new geshi($code, (isset($lang)) ? $lang : "");
  40. $geshi->enable_classes(false);
  41. $geshi->set_overall_id('geshi_code');
  42. return @$geshi->parse_code();
  43. }
  44. }
  45. ?>