A tumblelog CMS built on AJAX, PHP and MySQL.

kodrs.php 1.5KB

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