Posted By

Piotrek290 on 06/21/10


Tagged

query bbcode anymous


Versions (?)

Simple Query Menager - XClass


 / Published in: PHP
 

  1. <?php
  2. class x {
  3. public function query($query){
  4. return new Query($query);
  5. }
  6. }
  7.  
  8. class Query {
  9. public function Query($query, $sql){
  10. $this->query = $query;
  11. $this->sql = $sql;
  12. }
  13.  
  14. public function attr(){
  15. $get = func_get_args();
  16. $num = func_num_args()+1;
  17.  
  18. for($i=1; $i<$num; ++$i) $this->query = str_replace("%".$i, $get[$i-1], $this->query);
  19. return $this;
  20. }
  21.  
  22. public function cut($num){
  23. if(strlen($this->query) > $num){
  24. $this->query = substr($this->query, 0, $num)."...";
  25. }
  26.  
  27. return $this;
  28. }
  29.  
  30. public function finish(){ return $this->query; }
  31.  
  32. public function mail($pattern='/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/'){ return preg_match($pattern, $this->query)?true:false; }
  33.  
  34. public function hash(){
  35. $this->query = sha1($this->query);
  36. return $this;
  37. }
  38.  
  39. public function md5(){
  40. $this->query = md5($this->query);
  41. return $this;
  42. }
  43.  
  44. public function protect(){
  45. $this->query = htmlspecialchars(stripslashes($this->query));
  46. }
  47.  
  48. $this->query = @mysql_real_escape_string($this->query);
  49. return $this;
  50. }
  51.  
  52. public function bb($type=false){
  53. $str = $this->query;
  54. $str = htmlspecialchars($str);
  55. $str = nl2br($str);
  56.  
  57. $str = preg_replace("#\[b\](.*?)\[/b\]#si", '<b>\\1</b>', $str);
  58. $str = preg_replace("#\[i\](.*?)\[/i\]#si", '<i>\\1</i>', $str);
  59. $str = preg_replace("#\[u\](.*?)\[/u\]#si", '<u>\\1</u>', $str);
  60. $str = preg_replace("#\[s\](.*?)\[/s\]#si", '<span class="s">\\1</span>', $str);
  61.  
  62. $str = preg_replace("#\[img\](.*?)\[/img\]#si", '<img src="\\1" alt="" />', $str);
  63. $str = preg_replace("#\[img=(.*?)\](.*?)\[/img\]#si", '<img src="\\1" alt="\\2" />', $str);
  64.  
  65. $str = preg_replace("#\[url\](http.*?)\[/url\]#si", "<a href=\"\\1\">\\1</a>", $str);
  66. $str = preg_replace("#\[url=(http.*?)\](.*?)\[/url\]#si", "<a href=\"\\1\">\\2</a>", $str);
  67. $str = preg_replace("#\[url\](.*?)\[/url\]#si", "<a href=\"http://\\1\">\\1</a>", $str);
  68. $str = preg_replace("#\[url=(.*?)\](.*?)\[/url\]#si", "<a href=\"http://\\1\">\\2</a>", $str);
  69.  
  70. $str = preg_replace("#\[quote\](.*?)\[/quote\]#si",'<blockquote class="cytat">\\1</blockquote>',$str);
  71. $str = preg_replace("#\[quote=(.*?)\](.*?)\[/quote\]#si",'<p><cite>\\1</cite> napisa�(a):</p><blockquote>\\2</blockquote>',$str);
  72. $str = preg_replace("#\[code\](.*?)\[/code\]#si",'<pre>\\1</pre>',$str);
  73. $str = preg_replace("#\[hr=([0-9]{1,2}|100)\]#si", '<hr class="linia" width="\\1%">', $str);
  74.  
  75. $this->query = $str;
  76.  
  77. return $type?$this:$str;
  78. }
  79. }
  80. ?>

Report this snippet  

You need to login to post a comment.