Бот за новини от друг сайт

php_css

Registered
Здравейте искам да питам как да сложа бот в форума да добавя новини от някой друг сайт с rss ли се слагат дайте някво инфо че нямам и идея как става с PHPBB
 
php_css каза:
Здравейте искам да питам как да сложа бот в форума да добавя новини от някой друг сайт с rss ли се слагат дайте някво инфо че нямам и идея как става с PHPBB

Здрасти, аз имам такъв бот. Ето кода за бота.

Предлагам ти да си направиш една директоя във файловете на форума "bot" и вътре да си създадеш следните файлове:

bot.php
Код:
<?php
/*
Име: Ботчо
Версия: 0.7a
Автор: Алекс (http://alexsoft-bg.com)
Описание: Бот, който чете rss feed-ове и ги пуска като теми в phpBB2
Demo: http://gimp-bg.com/forums/viewforum.php?f=5
Файл: Основен
*/

define('IN_PHPBB', true);

include("defaults.php");

include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include('insert_post.'.$phpEx);

if(empty($_GET['userid'])) $user_id = $default['user_id']; else $user_id = (int)$_GET['userid']; 

$sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id = $user_id";
if ( !($result = $db->sql_query($sql)) )
{
   message_die(CRITICAL_ERROR, 'Could not obtain lastvisit data from user table', '', __LINE__, __FILE__, $sql);
} 

$userdata = $db->sql_fetchrow($result);
init_userprefs($userdata);

$current_time = time();
$sql = "UPDATE " . USERS_TABLE . "
   SET user_session_time = $current_time, user_session_page = " . PAGE_INDEX . ", user_lastvisit = $current_time
   WHERE user_id = $user_id";
if ( !$db->sql_query($sql) )
{
   message_die(CRITICAL_ERROR, 'Error updating last visit time', '', __LINE__, __FILE__, $sql);
} 

$userdata['user_lastvisit'] = $last_visit; 

if(empty($_GET['forumid'])) $forum_id = $default['forum_id']; else $forum_id = (int)$_GET['forumid'];

if(empty($_GET['broi'])) $broi = $default['broi']; else $broi = (int)$_GET['broi'];

if(empty($_GET['adres'])) {
$adresa = $default['adres']; //http://www.kaldata.com/rosebud/rss.php?catid=3
} else $adresa = $_GET['adres']; 

$readfile = file_get_contents($adresa);
$searchfile = eregi("<item>(.*)</item>", $readfile ,$arrayreg);
$filechunks = explode("<item>", $arrayreg[0]);
$count = count($filechunks); 

for($i=1 ; $i<=$count-1 ;$i++) {

if($i>$broi) break;

ereg("<title>(.*)</title>",$filechunks[$i], $title);
ereg("<link>(.*)</link>",$filechunks[$i], $links);
ereg("<description>(.*)</description",$filechunks[$i],$desc);

$subject = addslashes($title[1]); 
$texta = addslashes($desc[1]); 
$linka = addslashes($links[1]); 

$subject = substr($subject,0,60); // полето в БД е char(60) и за да няма проблеми с проверката съкращаваме името до 60 

$message = strip_tags($texta); // махаме таговете защото попринцип html е забранен в phpbb

$message .= "

[url=".$linka."]".$linka."[/url]"; // добавяме линк към статията 

$sel = mysql_num_rows(mysql_query("SELECT * FROM " . TOPICS_TABLE . " WHERE topic_title='$subject'")); // проверяваме дали вече не е пусната тази тема
if($sel<1) {

    $post_details = insert_post($message, $subject, $forum_id, $userdata['user_id'], $userdata['username'], $userdata['user_attachsig']);
    $url = append_sid($phpbb_root_path . 'viewtopic.' . $phpEx . '?' . POST_TOPIC_URL . '=' . $post_details['topic_id']);

    if(!$bot_cron) {
      echo '<a href="' . $url . '">new topic, id: ' . $post_details['topic_id'] . '</a><br/>'; // изкарваме новата тема
    } else {
      echo 'new topic, id: ' . $post_details['topic_id'] . "\r\n"; // ако бота се изпълнява с cron - без html
    }

}


}

if(!$bot_cron) {
echo "<br />done :)";
}

?>

cp.php
Код:
<?php 
/* 
Име: Ботчо 
Версия: 0.7a 
Автор: Алекс (http://alexsoft-bg.com) 
Описание: Бот, който чете rss feed-ове и ги пуска като теми в phpBB2 
Demo: http://gimp-bg.com/forums/viewforum.php?f=5 
Файл: Контрол панел 
*/ 

define('IN_PHPBB', true); 

include("./defaults.php"); 
?> 
<meta http-equiv="content-type" content="text/html; charset=windows-1251" > 
<h1>Бот Контрол Панел</h1> 
<br /> 

<form action="bot.php" method="get"> 
<table> 

<tr><td><td>От кой адрес да взимам?</td><td><input type="text" name="adres" value="<?=$defaults['adres']?>" size="40"/></td></tr> 
<tr><td><td>Колко теми да пускам?</td><td><input type="text" name="broi" value="<?=$defaults['broi']?>" size="40"/></td></tr> 
<tr><td><td>В кое форумид пиша?</td><td><input type="text" name="userid" value="<?=$defaults['forum_id']?>" size="40"/></td></tr> 
<tr><td><td>За кое юзърид се представям?</td><td><input type="text" name="userid" value="<?=$defaults['user_id']?>" size="40"/></td></tr> 
<tr><td> </td></tr> 
<tr><td colspan="2"><input type="submit" value="Пусни бота"/></td></tr> 

</table> 
</form>

и

insert_post.php
Код:
<?php 
/*************************************************************************** 
 *                         insert_post.php 
 *                      ------------------------------- 
 *   Author        :    netclectic - Adrian Cockburn - adrian@netclectic.com 
 *   Created       :    Monday, Sept 23, 2002 
 *   Modified       :    Sunday, Feb 23, 2003 
 ***************************************************************************/ 

if ( !defined('IN_PHPBB') ) 
{ 
   die('Hacking attempt'); 
} 

include_once($phpbb_root_path . 'includes/bbcode.'.$phpEx); 
include_once($phpbb_root_path . 'includes/functions_post.'.$phpEx); 
include_once($phpbb_root_path . 'includes/functions_search.'.$phpEx); 


function insert_post( 
    $message, 
    $subject, 
    $forum_id, 
    $user_id, 
    $user_name, 
    $user_attach_sig, 
    $topic_id = NULL, 
    $topic_type = POST_NORMAL, 
    $do_notification = false, 
    $notify_user = false, 
    $current_time = 0, 
    $error_die_function = '', 
    $html_on = 0, 
    $bbcode_on = 1, 
    $smilies_on = 1 ) 
{ 
    global $db, $board_config, $user_ip; 

    // initialise some variables 
    $topic_vote = 0; 
    $poll_title = ''; 
    $poll_options = ''; 
    $poll_length = ''; 
    $mode = 'reply'; 

    $bbcode_uid = ($bbcode_on) ? make_bbcode_uid() : ''; 
    $error_die_function = ($error_die_function == '') ? "message_die" : $error_die_function; 
    $current_time = ($current_time == 0) ? time() : $current_time; 
    
    // parse the message and the subject 
    $message = str_replace("\'", "''", prepare_message(trim($message), $html_on, $bbcode_on, $smilies_on, $bbcode_uid)); 
    $subject = str_replace("\'", "''", trim($subject)); 
    $username = str_replace("\'", "''", trim(strip_tags($user_name))); 
    
    // if this is a new topic then insert the topic details 
    if ( is_null($topic_id) ) 
    { 
        $mode = 'newtopic'; 
        $sql = "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_vote) VALUES ('$subject', " . $user_id . ", $current_time, $forum_id, " . TOPIC_UNLOCKED . ", $topic_type, $topic_vote)"; 
        if ( !$db->sql_query($sql, BEGIN_TRANSACTION) ) 
        { 
            $error_die_function(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); 
        } 
        $topic_id = $db->sql_nextid(); 
    } 

    // insert the post details using the topic id 
    $sql = "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, enable_bbcode, enable_html, enable_smilies, enable_sig) VALUES ($topic_id, $forum_id, " . $user_id . ", '$username', $current_time, '$user_ip', $bbcode_on, $html_on, $smilies_on, $user_attach_sig)"; 
    if ( !$db->sql_query($sql, BEGIN_TRANSACTION) ) 
    { 
        $error_die_function(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); 
    } 
    $post_id = $db->sql_nextid(); 
    
    // insert the actual post text for our new post 
    $sql = "INSERT INTO " . POSTS_TEXT_TABLE . " (post_id, post_subject, bbcode_uid, post_text) VALUES ($post_id, '$subject', '$bbcode_uid', '$message')"; 
    if ( !$db->sql_query($sql, BEGIN_TRANSACTION) ) 
    { 
        $error_die_function(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); 
    } 
    
    // update the post counts etc. 
    $newpostsql = ($mode == 'newtopic') ? ',forum_topics = forum_topics + 1' : ''; 
    $sql = "UPDATE " . FORUMS_TABLE . " SET 
                forum_posts = forum_posts + 1, 
                forum_last_post_id = $post_id 
                $newpostsql     
            WHERE forum_id = $forum_id"; 
    if ( !$db->sql_query($sql, BEGIN_TRANSACTION) ) 
    { 
        $error_die_function(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); 
    } 
    
    // update the first / last post ids for the topic 
    $first_post_sql = ( $mode == 'newtopic' ) ? ", topic_first_post_id = $post_id  " : ' , topic_replies=topic_replies+1'; 
    $sql = "UPDATE " . TOPICS_TABLE . " SET 
                topic_last_post_id = $post_id 
                $first_post_sql 
            WHERE topic_id = $topic_id"; 
    if ( !$db->sql_query($sql, BEGIN_TRANSACTION) ) 
    { 
        $error_die_function(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); 
    } 
    
    // update the user's post count and commit the transaction 
    $sql = "UPDATE " . USERS_TABLE . " SET 
                user_posts = user_posts + 1 
            WHERE user_id = $user_id"; 
    if ( !$db->sql_query($sql, END_TRANSACTION) ) 
    { 
        $error_die_function(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); 
    } 
    
    // add the search words for our new post 
    switch ($board_config['version']) 
    { 
        case '.0.0' : 
        case '.0.1' : 
        case '.0.2' : 
        case '.0.3' : 
            add_search_words($post_id, stripslashes($message), stripslashes($subject)); 
            break; 
        
        default : 
            add_search_words('', $post_id, stripslashes($message), stripslashes($subject)); 
            break; 
    } 
    
    // do we need to do user notification 
    if ( ($mode == 'reply') && $do_notification ) 
    { 
        $post_data = array(); 
        user_notification($mode, $post_data, $subject, $forum_id, $topic_id, $post_id, $notify_user); 
    } 
    
    // if all is well then return the id of our new post 
    return array('post_id'=>$post_id, 'topic_id'=>$topic_id); 
} 

?>

Като в cp.php попълваш данните на профила, които си създал предварително за бота. Може да се направи примерно да се зарежда файла всяка седмица автоматично чрез cornjob.
 
Автор: Алекс (http://alexsoft-bg.com)
Описание: Бот, който чете rss feed-ове и ги пуска като теми в phpBB2

За phpbb3 ми трябва
 
php_css каза:
Автор: Алекс (http://alexsoft-bg.com)
Описание: Бот, който чете rss feed-ове и ги пуска като теми в phpBB2

За phpbb3 ми трябва

Ами значи не мога да ти помогна. Може да пробваш да преправиш този..
 

Back
Горе