new_topic
Purpose: Creates a new topic.
Availability: IPB SDK 0.5
Creates a new topic in the forum forumid with the topic title title, the description description, and the post post. Returns TRUE on success.
If disableemos is set to TRUE emoticons on the message will not be parsed. If disablesig is set to TRUE a signature will not be added below the message. If bypassperms is set to TRUE, the permissions check to check the user can create a new topic in the forum will be bypassed. If the current user is not logged in, you can specify an eighth argument - guestname. This will be used as the Guest's Name on the newly created topic.
If the action failed FALSE will be returned. A full error message can be retrieved with sdk_error.
// If you want you can make these variables come from form or GET input
$forumid = "1";
$title = "Hello Everyone";
$desc = "A funky topic description";
$post = "Whats up people :D";
if ($SDK->new_topic($forumid, $title, $desc, $post)) {
echo 'Topic Created!';
} else {
echo $SDK->sdk_error();
}
User Contributed Notes
CODE |
function new_topic ($forumid, $title, $desc, $post, $membername, $disableemos = '0', $disablesig = '0', $bypassperms = '0', $guestname = '') { if (!$title) { $this->sdkerror($this->lang['sdk_topics_notitle']); return FALSE; } $title = $this->makesafe($title); $desc = $this->makesafe($desc); $post = $this->makesafe($post); // Noms et tous d'invit�. /* if ($this->is_loggedin()) { $postname = $GLOBALS['ibforums']->member['name']; } else { if ($guestname) { $postname = $GLOBALS['ibforums']->vars['guest_name_pre'] . $this->makesafe($guestname) . $GLOBALS['ibforums']->vars['guest_name_suf']; } else { $postname = $GLOBALS['ibforums']->member['name']; } } */ //membername to id $memberid=$this->name2id($membername); // No Posting if ($GLOBALS['ibforums']->member['restrict_post']) { $this->sdkerror($this->lang['sdk_noperms']); return FALSE; } // Flooding if ($GLOBALS['ibforums']->vars['flood_control'] AND $GLOBALS['ibforums']->member['g_avoid_flood'] != '1') { if ((time() - $GLOBALS['ibforums']->member['last_post']) < $GLOBALS['ibforums']->vars['flood_control']) { $this->sdkerror(sprintf($this->lang['sdk_floodcontrol']), $GLOBALS['ibforums']->vars['flood_control']); return FALSE; } } // Check some Forum Stuff $this->DB->query ("SELECT * FROM ibf_forums WHERE id='" . intval($forumid) . "'"); if ($row = $this->DB->fetch_row()) { // Check User can Post to Forum if ($this->is_forum_startable($row['id']) OR $bypassperms) { // Queuing if ($row['preview_posts'] OR $GLOBALS['ibforums']->member['mod_posts']) { $preview = '1'; } else { $preview = '0'; } $time = time(); // Insert Topic Bopic $this->DB->query ("INSERT INTO ibf_topics (title, description, state, posts, starter_id, start_date, last_poster_id, last_post, starter_name, last_poster_name, views, forum_id, approved, author_mode, pinned) VALUES ('{$title}', '{$desc}', 'open', '0', '{$memberid}', '" . $time . "', '{$memberid}', '" . $time . "', '{$membername}', '{$membername}', '0', '{$forumid}', '" . ($preview ? '0' : '1') . "', '1', '0')"); $topicid = $this->DB->get_insert_id(); $this->DB->query ("INSERT INTO ibf_posts (author_id, author_name, use_emo, use_sig, ip_address, post_date, post, queued, topic_id, new_topic, icon_id) VALUES ('{$memberid}', '{$membername}', '" . ($disableemos ? '0' : '1') . "', '" . ($disablesig ? '0' : '1') . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . $time . "', '" . addslashes($GLOBALS['parser']->convert(array('TEXT' => $post, 'CODE' => $row['use_ibc'], 'HTML' => $row['use_html'], 'SMILIES' => ($disableemos ? '0' : '1')))) . "', '{$preview}', '" . $topicid . "', '1', '0')"); // Finally update the forums $this->DB->query ("UPDATE ibf_forums SET last_poster_id='" . $memberid . "', last_poster_name='" . $membername . "', topics=topics+1, last_post='" . $time . "', last_title='" . $title . "', last_id='" . $topicid . "' WHERE id='" . intval($forumid) . "'"); // Oh yes, any update the post count for the user if ($memberid != '0') { if ($row['inc_postcount']) { $this->DB->query ("UPDATE ibf_members SET posts=posts+1, last_post='" . time() . "' WHERE id='" . $memberid . "' LIMIT 1"); } else { $this->DB->query ("UPDATE ibf_members SET last_post='" . time() . "' WHERE id='" . $memberid . "' LIMIT 1"); } } // And stats $GLOBALS['ibforums']->cache['stats']['total_topics'] += 1; $GLOBALS['std']->update_forum_cache(); $GLOBALS['std']->update_cache( array( 'name' => 'stats', 'array' => 1, 'deletefirst' => 0 ) ); //$this->DB->query ('UPDATE ibf_stats SET TOTAL_TOPICS=TOTAL_TOPICS+1'); // Return $topicid rather then TRUE as it is more use return $topicid; } else { $this->sdkerror($this->lang['sdk_noperms']); return FALSE; } } else { $this->sdkerror($this->lang['sdk_forum_notexist']); return FALSE; } } //<end of function> |
===========================
USAGE:
CODE |
new_topic (int forumid, string title, string description, string post, string membername[, bool disableemos[, bool disablesig[, bool bypassperms[, string guestname]]]]) |
EXAMPLE:
CODE |
//starts a new topic in forum id=6 with "Test topic" title, "Test desc" description, "Test post blah-blah-blah" post AND the author of the topic is user with membername "SphinX". $q=$SDK->new_topic(6,"Test topic","Test desc","Test post blah-blah-blah","SphinX"); echo "Topic with id $q has been successfully created!"; |
Documentation Generated at Sat, 16 Apr 2005 07:36:35 -0700
Find the latest version at http://ipbsdk.sourceforge.net
SphinX
As for me i decided to rewrite this function just a little to make it able to create a topic by any user i want - instead of posting a topic from a currently logged in user or from guest, you can specify member's name whom you want to "start a topic".
Here is my variant of new_topic():