Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Klasa/metoda tworząca nowy post na forum phpBB
phpion
post 24.04.2008, 07:58:32
Post #1





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




Witam,
z konieczności napisałem klasę/metodę tworzącą nowy post na forum phpBB. Może komuś się przyda:
  1. <?php
  2. class Helper_Phpbb {
  3. /**
  4.  * Creates new topic for phpBB forum
  5.  * 
  6.  * @access public
  7.  * @static
  8.  * 
  9.  * @param string $title Topic title
  10.  * @param string $content Topic body content
  11.  * @param int $forumId Destination forum
  12.  * @param int $posterId Post author id
  13.  * 
  14.  * @return int Created topic's id. 0 if there were any problems...
  15.  */
  16. static public function createNewTopic($title, $content, $forumId, $posterId) {
  17. $title = mysql_escape_string($title);
  18. $content = mysql_escape_string($content);
  19. $forumId = (int)$forumId;
  20. $poserId = (int)$posterId;
  21.  
  22. mysql_query('START TRANSACTION');
  23.  
  24. // creating new topic
  25. $q = 'INSERT INTO '.TOPICS_TABLE.' SET forum_id='.$forumId.', topic_title="'.$title.'", topic_poster='.$posterId.', topic_time='.time().', topic_views=1, topic_replies=0, topic_status=0, topic_vote=0, topic_type=0, to
  26. ic_first_post_id=0, topic_last_post_id=0, topic_moved_id=0, topic_last_post_uid='.$posterId;
  27. if (!mysql_query($q)) {
  28. mysql_query('ROLLBACK');
  29. return 0;
  30. }
  31.  
  32. $topicId = mysql_insert_id();
  33.  
  34. // creating new post
  35. $q = 'INSERT INTO '.POSTS_TABLE.' SET topic_id='.$topicId.', forum_id='.$forumId.', poster_id='.$posterId.', post_time='.time().', poster_ip="'.encode_ip($_SERVER['REMOTE_ADDR']).'", post_username=NULL, enable_bbcode=1, enable_html=0, enable_smilies=1, ena
    ble_s
  36. g=0, post_edit_time=NULL, post_edit_count=0, raport=0, notice=0';
  37. if (!mysql_query($q)) {
  38. mysql_query('ROLLBACK');
  39. return 0;
  40. }
  41.  
  42. $postId = mysql_insert_id();
  43.  
  44. // creating post content
  45. $q = 'INSERT INTO '.POSTS_TEXT_TABLE.' SET post_id='.$postId.', bbcode_uid="'.make_bbcode_uid2().'", post_subject="'.$title.'", post_text="'.$content.'", mods_notice=NULL';
  46. if (!mysql_query($q)) {
  47. mysql_query('ROLLBACK');
  48. return 0;
  49. }
  50.  
  51. // updating posts table
  52. $q = 'UPDATE '.TOPICS_TABLE.' SET topic_first_post_id='.$postId.', topic_last_post_id='.$postId.' WHERE topic_id='.$topicId.' LIMIT 1';
  53. if (!mysql_query($q)) {
  54. mysql_query('ROLLBACK');
  55. return 0;
  56. }
  57.  
  58. // updating forum statistics
  59. $q = 'UPDATE '.FORUMS_TABLE.' SET forum_posts=forum_posts+1, forum_topics=forum_topics+1, forum_last_post_id='.$postId.' WHERE forum_id='.$forumId.' LIMIT 1';
  60. if (!mysql_query($q)) {
  61. mysql_query('ROLLBACK');
  62. return 0;
  63. }
  64.  
  65. // updating poster statistics
  66. $q = 'UPDATE '.USERS_TABLE.' SET user_posts=user_posts+1 WHERE user_id='.$posterId.' LIMIT 1';
  67. if (!mysql_query($q)) {
  68. mysql_query('ROLLBACK');
  69. return 0;
  70. }
  71.  
  72. mysql_query('COMMIT');
  73.  
  74. return $topicId;
  75. }
  76. }
  77. ?>


pion

PS: Jeśli odpowiedniejszym działem będzie "Algorytmy, klasy, funkcje" proszę o przeniesienie tematu.

Ten post edytował phpion 24.04.2008, 08:04:10
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 10:36