Hack Forums
{SOURCE}MyBB Auto Poster From Blogs - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: General Topics (https://hackforums.net/forumdisplay.php?fid=7)
+--- Forum: World (https://hackforums.net/forumdisplay.php?fid=445)
+---- Forum: The Lounge (https://hackforums.net/forumdisplay.php?fid=25)
+---- Thread: {SOURCE}MyBB Auto Poster From Blogs (/showthread.php?tid=6248010)



{SOURCE}MyBB Auto Poster From Blogs - WebArt - Jul 29, 2023

Recently i made a MyBB Auto Poster From Blogs. it will create post from the blogs directly to your desired section. to check its new post time to time i set cronjob in every 30 min. Its post title and Description with all the photos and videos. see the picture bellow

[Image: 6f1207030f9023bc0d992a12363d5977.png]


Here Is the Source Code

PHP Code

<?php
ini_set
('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

define("IN_MYBB", 1);
require_once 
"global.php";

$website = 'https://indianexpress.com/section/world/';
$html = file_get_contents($website);
$dom = new DomDocument();
$dom->loadHTML($html);


$nodes = $dom->getElementById('north-east-data')->firstChild->childNodes;


function 
createPost($title, $message)
{
    global 
$db, $mybb;
     
// type your Username here.
    
$username = 'Username';
    
// type your UID here.
    
$uid = '1';
    
// type your Forum Section FID here.
    
$fid = '38';

    echo 
'soumik';

    
$exist = $db->simple_select("threads", "*", "subject='" . $db->escape_string($title) . "'", array(
        
"limit" => 1
    
));

    
$post_exist = $db->fetch_array($exist);


    if (
$post_exist) {
        return;
    }


    
$threadData = [
        
'subject' => $db->escape_string($title),
        
'uid' => $uid,
        
'username' => $username,
        
'dateline' => time(),
        
'firstpost' => '',
        
'lastpost' => time(),
        
'fid' => $fid,
        
'lastposter' => $username,
        
'lastposteruid' => $uid,
        
'visible' => '1'
    
];

    
$tid = $db->insert_query('threads', $threadData);

    if (
$tid) {
        
$postData = [
            
'tid' => $tid,
            
'fid' => $fid,
            
'uid' => $uid,
            
'subject' => $db->escape_string($title),
            
'username' => $username,
            
'message' => $db->escape_string($message),
            
'dateline' => time(),
            
'visible' => '1'
        
];

        
$pid = $db->insert_query('posts', $postData);

        if (
$pid) {
            
$db->update_query(
                
'threads',
                [
                    
'firstpost' => $pid
                
],
                
"tid='" . $tid . "'"
            
);


            
$thread_count_query = $db->simple_select("threads", "*", "fid='" . $fid . "'");

            
$threads_total = $db->num_rows($thread_count_query);



            
$db->update_query(
                
'forums',
                [
                    
'threads' => $threads_total
                
],
                
"fid='" . $fid . "'"
            
);


            
$user_threads_query = $db->simple_select("threads", "*", "uid='" . $uid . "'");

            
$users_threads_total = $db->num_rows($user_threads_query);

            
$db->update_query(
                
'users',
                [
                    
'threadnum' => $users_threads_total
                
],
                
"uid='" . $uid . "'"
            
);



            return 
true;
        }
    }
    return 
false;
}




$news = [];
foreach (
$nodes as $index => $node) {
    if (
$node->firstChild->tagName == 'a') {
        foreach (
$node->firstChild->attributes as  $attr) {
            if (
$attr->name == 'href') {
                echo 
$website = $attr->value . '<br>';

                
$page_html = file_get_contents($attr->value);


                
$page_dom = new DomDocument();
                
$page_dom->loadHTML($page_html);
                
$domxpath = new DomXPath($page_dom);

                
$article_title_classname = "native_story_title";
                
$article_title = $domxpath->query("//*[contains(@class, '$article_title_classname')]");

                
$title = $article_title[0]->textContent;


                
$thumb_classname = "custom-caption";
                
$thumb = $domxpath->query("//*[contains(@class, '$thumb_classname')]");

                
$thumb_html = $thumb[0]->c14n();


                
$readmore_classname = "premium-story";
                
$readmore = $domxpath->query("//*[contains(@class, '$readmore_classname')]");
                if (
$readmore->length > 0) {
                    
$readmore_html = $readmore[0]->c14n();
                } else {
                    
$readmore_html = '';
                }


                
$message_node = $page_dom->getElementById('pcl-full-content');

                
$message_html = $message_node->c14n();

                
$message_html  = str_replace($readmore_html, '', $message_html);


// ADD Source Link to Protect from Copyright.
                
$source_html = '<span class="source_url"><a href="' . $attr->value . '">Source Link</a></span>';

                
$message = $thumb_html . $message_html . $source_html;
                
createPost($title, $message);

            }
        }
    }
}

print_r($news); 

Change Only Comment Area for username, UID and FID . upload it to your base location and run it in browser. and see the magic. it will work in any mybb forum. hope you guys will Enjoy it.