PageRenderTime 59ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/src/site/components/com_medium/filters/post.php

https://github.com/bhar1red/anahita
PHP | 96 lines | 38 code | 14 blank | 44 comment | 3 complexity | d09ad7ff2c9a8516777645ce7e09240c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * LICENSE: ##LICENSE##
  4. *
  5. * @category Anahita
  6. * @package Com_Medium
  7. * @subpackage Filter
  8. * @author Arash Sanieyan <ash@anahitapolis.com>
  9. * @author Rastin Mehr <rastin@anahitapolis.com>
  10. * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc
  11. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
  12. * @version SVN: $Id: resource.php 11985 2012-01-12 10:53:20Z asanieyan $
  13. * @link http://www.anahitapolis.com
  14. */
  15. /**
  16. * Post filter
  17. *
  18. * @category Anahita
  19. * @package Com_Medium
  20. * @subpackage Filter
  21. * @author Arash Sanieyan <ash@anahitapolis.com>
  22. * @author Rastin Mehr <rastin@anahitapolis.com>
  23. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
  24. * @link http://www.anahitapolis.com
  25. */
  26. class ComMediumFilterPost extends KFilterHtml
  27. {
  28. /**
  29. * Initializes the default configuration for the object
  30. *
  31. * Called from {@link __construct()} as a first step of object instantiation.
  32. *
  33. * @param KConfig $config An optional KConfig object with configuration options.
  34. *
  35. * @return void
  36. */
  37. protected function _initialize(KConfig $config)
  38. {
  39. $config->append(array(
  40. 'tag_list' => array('img', 'a', 'blockquote', 'strong', 'em', 'ul', 'ol', 'li', 'code'),
  41. 'tag_method' => 0
  42. ));
  43. parent::_initialize($config);
  44. if ( $config->tag_list )
  45. $config['tag_list'] = KConfig::unbox($config->tag_list);
  46. if ( $config->tag_method )
  47. $config['tag_method'] = KConfig::unbox($config->tag_method);
  48. }
  49. /**
  50. * Try to convert to plaintext
  51. *
  52. * @param string $source The source to convert
  53. *
  54. * @return string Plaintext string
  55. */
  56. protected function _decode($source)
  57. {
  58. $matches = array();
  59. if ( preg_match_all('#<code(.*?)>(.*?)</code>#si', $source, $matches) )
  60. {
  61. $replacements = array_map('htmlentities', $matches[2]);
  62. foreach($replacements as $key => &$match)
  63. {
  64. $match = '<code'.$matches[1][$key].'>'.$match.'</code>';
  65. }
  66. $source = str_replace($matches[0], $replacements, $source);
  67. }
  68. return $source;
  69. // entity decode
  70. $trans_tbl = get_html_translation_table(HTML_ENTITIES);
  71. foreach($trans_tbl as $k => $v) {
  72. $ttr[$v] = utf8_encode($k);
  73. }
  74. $source = strtr($source, $ttr);
  75. // convert decimal
  76. $source = preg_replace('/&#(\d+);/me', "chr(\\1)", $source); // decimal notation
  77. // convert hex
  78. $source = preg_replace('/&#x([a-f0-9]+);/mei', "chr(0x\\1)", $source); // hex notation
  79. return $source;
  80. }
  81. //end class
  82. }