Drupal 7 Примеры:
Создать новый форум
$forum = new stdClass();
$forum->name = uniqid();
$forum->description = uniqid();
$forum->parent = array(0);
$forum->weight = 0;
$forum->vid = variable_get('forum_nav_vocabulary', 0);
taxonomy_term_save($forum);
Создать новую тему
$node = new stdClass();
// Set the values for the node
$node->title = "My new forum topic";
$node->body = "The body of my forum topic.\n\nAdditional Information";
$node->type = 'forum'; // Your specified content type
$node->created = time();
$node->changed = $node->created;
$node->status = 1; // To have published, else use 0
$node->comment = 2; // To have active, else use 0
$node->uid = 1; // UID of content owner
//Creates topic at the first "forum"
$node->forum_tid = reset(array_keys(taxonomy_term_load_multiple(array(),
array('vid' => variable_get('forum_nav_vocabulary', 0)))));
$node->language = LANGUAGE_NONE;
$node->taxonomy_forums[LANGUAGE_NONE][0]['tid'] = $node->forum_tid;
node_save($node);
Для создания комментариев к теме
$comment = (object)array(
'nid' => $node->nid,
'pid' => 0,
'cid' => 0,
'uid' => 1,
'mail' => '',
'is_anonymous' => 0,
'homepage' => '',
'status' => COMMENT_PUBLISHED,
'subject' => 'subject test ' . uniqid(),
'language' => LANGUAGE_NONE,
'comment_body' => array(
LANGUAGE_NONE => array(
0 => array(
'value' => 'Comment Body ' . uniqid(),
'format' => 1
)
)
),
);
comment_submit($comment);
comment_save($comment);