A new, object-oriented, better vesion of μForum
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.3 KiB

  1. <?php
  2. /**
  3. * @package uForum2
  4. * @file inc/bbcode.php
  5. * @copyright 2007-2015 (c) PioDer
  6. * @link http://www.pioder.pl/
  7. * @license see LICENSE.txt
  8. **/
  9. function BBCode($content)
  10. {
  11. $pattern = array(
  12. '/\:\)/s', # :)
  13. '/\:\|/s', # :|
  14. '/\:\(/s', # :(
  15. '/\;\(/s', # ;(
  16. '/\:D/is', # :D
  17. '/\:o/is', # :o
  18. '/\;\)/s', # ;)
  19. '/\:p/is', # :p
  20. '/\:curve:/is', # :curve:
  21. '/\:!:/is', # :!:
  22. '/\:lol\:/is', # :lol:
  23. '/\:evil\:/is', # :evil:
  24. '/\:mad\:/is', # :mad:
  25. '/\:roll\:/is', # :roll:
  26. '/\:cool\:/is', # :cool:
  27. '/\:redface\:/is', # :redface:
  28. '/\[b\](.*?)\[\/b\]/is', # [b]
  29. '/\[i\](.*?)\[\/i\]/is', # [i]
  30. '/\[u\](.*?)\[\/u\]/is', # [u]
  31. '/\[s\](.*?)\[\/s\]/is', # [s]
  32. '/\[center\](.*?)\[\/center\]/is', # [center]
  33. '/\[url=((http:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)\](.*?)\[\/url\]/is', # [url=]
  34. '/\[url]((http:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)\[\/url\]/is', # [url]
  35. '/\[color=#?([A-F0-9]{3}|[A-F0-9]{6})\](.*?)\[\/color\]/is', # [color] (hex)
  36. '/\[color=?([A-Z]+)\](.*?)\[\/color\]/is', # [color] (text)
  37. '/\[list\](.*?)\[\/list\]/is', # [list]
  38. '/\[\*\](.*?)(\n|\r\n)/is', # [*]
  39. '/\[quote\](.*?)\[\/quote\]/is', # [quote]
  40. '/\[quote=(.+?)\](.*?)\[\/quote\]/is', # [quote=]
  41. '/\[code\](.*?)\[\/code\]/is', # [code]
  42. '/\\n/', # \n
  43. '/\\r/', # \r
  44. '/(^|[^"])((http:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/i',
  45. );
  46. $replace = array(
  47. '<img src="images/smiles/smile.gif" alt=":)">', # :)
  48. '<img src="images/smiles/neutral.gif" alt=":|">', # :|
  49. '<img src="images/smiles/sad.gif" alt=":(" >', # :(
  50. '<img src="images/smiles/cry.png" alt=":(" >', # ;(
  51. '<img src="images/smiles/big_smile.gif" alt=":D" >', # :D
  52. '<img src="images/smiles/yikes.gif" alt=":o" >', # :o
  53. '<img src="images/smiles/wink.gif" alt=";)" >', # ;)
  54. '<img src="images/smiles/tongue.gif" alt=":p" >', # :p
  55. '<img src="images/smiles/curve.gif" alt=":/" >', # :curve:
  56. '<img src="images/smiles/exclaim.gif" alt=":!:" >', # :!:
  57. '<img src="images/smiles/lol.gif" alt=":lol:" >', # :lol:
  58. '<img src="images/smiles/evil.gif" alt=":evil:" >', # :evil:
  59. '<img src="images/smiles/mad.gif" alt=":mad:" >', # :mad:
  60. '<img src="images/smiles/roll.gif" alt=":roll:" >', # :roll:
  61. '<img src="images/smiles/cool.gif" alt=":cool:" >', # :cool:
  62. '<img src="images/smiles/redface.gif" alt=":redface:" >', # :redface:
  63. '<span style="font-weight: bold;">\1</span>', # [b]
  64. '<span style="font-style: italic;">\1</i>', # [i]
  65. '<span style="text-decoration: underline;">\1</span>', # [u]
  66. '<span style="text-decoration: line-through;">\1</span>', # [s]
  67. '<p style="text-align: center;">\1</p>', # [center]
  68. '<a href="\1">\3</a>', # [url=]
  69. '<a href="\1">\1</a>', # [url]
  70. '<span style="color: #\1;">\2</span>', # [color] (hex)
  71. '<span style="color: \1;">\2</span>', # [color] (text)
  72. '<ul>\1</ul>', # [list]
  73. '<li>\1</li>', # [*]
  74. '<div class="qpost"><span style="font-weight: bold">Quote:</span><br>\1</div>', # [quote]
  75. '<div class="qpost"><span style="font-weight: bold">\1 wrote:</span><br>\2</div>', # [quote=]
  76. '<div class="cpost"><span style="font-weight: bold">Code:</span><br>\1</div>', # [code]
  77. '<br>', # \n
  78. '', # \r
  79. '\\1<a href="\\2">\\2</a>',
  80. );
  81. return preg_replace($pattern, $replace, $content);
  82. }
  83. ?>