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.

110 lines
3.7 KiB

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