Help Em hỏi về auto post xenforo 2 ạ.

vipkhongtin

Private
Tham gia
13/04/2015
Bài viết
40
Được Like
14
Em muốn hỏi về xenforo ngoài lề chút ạ/
Em định dùng query để insert trực tiếp thread vào db nhưng ko ổn các cụ ạ.
Đoan query insert thread and post của em, nó cũng hoạt động nhưng vì 1 số trường lỗi nên post ko đc hoàn thiện lắm ạ
1f615.png
:/
Có cụ nào viết code leech cho xenforo chưa cho em xin ít kinh nghiệm với ạ.
57210648_1309397315865032_8363352548622467072_o.jpg
 

XenFeature

Private
Tham gia
16/04/2019
Bài viết
6
Được Like
6
you can use this function in xf2
PHP:
function xf2AutoPost($user_id, $node_id, $title, $message)
{
    $dir = __DIR__;
    require($dir . '/src/XF.php');
    XF::start($dir);
    $user = \XF::em()->find('XF:User', $user_id);
    $user = \XF::em()->find('XF:Forum', $node_id);
    \XF::asVisitor($user, function() use ($forum, $title, $message)
    {
        $creator = \XF::service('XF:Thread\Creator', $forum);
        $creator->setContent($title, $message);
        $creator->setPrefix($forum['default_prefix_id']);
        $creator->setIsAutomated();
        $creator->save();
        return $creator;
    }
    return false;

}
 

vipkhongtin

Private
Tham gia
13/04/2015
Bài viết
40
Được Like
14
you can use this function in xf2
PHP:
function xf2AutoPost($user_id, $node_id, $title, $message)
{
    $dir = __DIR__;
    require($dir . '/src/XF.php');
    XF::start($dir);
    $user = \XF::em()->find('XF:User', $user_id);
    $user = \XF::em()->find('XF:Forum', $node_id);
    \XF::asVisitor($user, function() use ($forum, $title, $message)
    {
        $creator = \XF::service('XF:Thread\Creator', $forum);
        $creator->setContent($title, $message);
        $creator->setPrefix($forum['default_prefix_id']);
        $creator->setIsAutomated();
        $creator->save();
        return $creator;
    }
    return false;

}
thanks bro, How to use function? I am newbie
 

XenFeature

Private
Tham gia
16/04/2019
Bài viết
6
Được Like
6
thanks bro, How to use function? I am newbie
hmm....
create php file like PostThread.php with this code:

PHP:
<?php
    $user_id = 1;
    $node_id= 2;
    $title = 'title of thread ';
    $message = 'this is the content';
 
    $dir = __DIR__;
    require($dir . '/src/XF.php');
    XF::start($dir);
    $user = \XF::em()->find('XF:User', $user_id);
    $user = \XF::em()->find('XF:Forum', $node_id);
    \XF::asVisitor($user, function() use ($forum, $title, $message)
    {
        $creator = \XF::service('XF:Thread\Creator', $forum);
        $creator->setContent($title, $message);
        $creator->setPrefix($forum['default_prefix_id']);
        $creator->setIsAutomated();
        $creator->save(); 
    }
upload to your xenforo root patch
run it.
 

vipkhongtin

Private
Tham gia
13/04/2015
Bài viết
40
Được Like
14
hmm....
create php file like PostThread.php with this code:

PHP:
<?php
    $user_id = 1;
    $node_id= 2;
    $title = 'title of thread ';
    $message = 'this is the content';
 
    $dir = __DIR__;
    require($dir . '/src/XF.php');
    XF::start($dir);
    $user = \XF::em()->find('XF:User', $user_id);
    $user = \XF::em()->find('XF:Forum', $node_id);
    \XF::asVisitor($user, function() use ($forum, $title, $message)
    {
        $creator = \XF::service('XF:Thread\Creator', $forum);
        $creator->setContent($title, $message);
        $creator->setPrefix($forum['default_prefix_id']);
        $creator->setIsAutomated();
        $creator->save();
    }
upload to your xenforo root patch
run it.
thanks bro
I want to add a tag, so what do I have to fix?
 
Sửa lần cuối:

Hướng dẫn sử dụng

XenForo 1 XenForo 2
Translate by PVS

Dịch vụ XenForo của VNXF

Mobile/Zalo: 0906081284

Telegram: anhanhxf

Chỉ nhận web nội dung lành mạnh

Nhà Tài Trợ

Mút Xốp Không Gian
Mút Sofa Không Gian
Top Bottom