Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function pluginindex( )
- {
- global $db;
- global $prefix;
- global $dbforumtype;
- head( );
- $html = "<form action=\"index.php\" method=\"post\">";
- $html .= "<table border=\"0\" cellpadding=\"3\">";
- $html .= "<tr><td valign=\"top\" width=\"30%\"><b>Forum To Populate</b></td><td><select name=\"forumid\">";
- $forumquery = $db->sql_query( "SELECT forumid, title, parentid, options FROM ".$prefix."forum ORDER BY forumid DESC" );
- while ( list( $forumid, $forumtitle, $parentid, $op ) = $db->sql_fetchrow( $forumquery ) )
- {
- if ( substr( decbin( $op ), -3, 1 ) == 1 )
- {
- if ( $parentid != 0 )
- {
- $forumtitle = getparent( $parentid, $forumtitle );
- }
- $html .= "<option value=\"{$forumid}\">{$forumtitle}</option>";
- }
- }
- $html .= "</select></td></tr>";
- $html .= "<tr><td><b>Topic Keywords</b></td><td><input type=\"text\" name=\"yinput\" maxlength=\"255\" size=\"25\" /> ";
- $html .= "<tr><td><b>Type of Post</b></td><td><select name=\"posttype\">";
- $html .= "<option value=\"resolved\" selected=\"selected\">Resolved Topics (1 or more replies)</option>";
- $html .= "<option value=\"open\">Open Discussion (0 or more replies)</option>";
- $html .= "<option value=\"all\">Both (Random)</option>";
- $html .= "</select></td></tr>";
- $html .= "</td></tr>";
- $html .= "<tr><td><b>Topics To Generate</b></td><td><select name=\"maxresults\">";
- $i = 1;
- for ( ; $i <= 50; ++$i )
- {
- $html .= "<option value=\"{$i}\">{$i}</option>";
- }
- $html .= "</select> (Does not include topic replies)</td></tr>";
- $html .= "<tr><td valign=\"top\"><b>Allow Repeated Posts</b></td><td><input type=\"checkbox\" name=\"allow_multiple_posts\" value=\"1\" /> Check this box to allow duplicate posts to be produced.</td></tr>";
- $html .= "<tr><td valign=\"top\"><b>HTML Line Breaks</b></td><td><input type=\"checkbox\" name=\"htmlbr\" value=\"1\" /> Convert all new line tags (\\n\\r) to HTML (<br />) tags.</td></tr>";
- $html .= "<tr><td valign=\"top\"><b>Poster Usernames</b></td><td><select name=\"usernames[]\" size=\"5\" multiple=\"multiple\">";
- $res = $db->sql_query( "SELECT userid, username FROM ".$prefix."user ORDER BY username ASC" );
- while ( list( $uid, $uname ) = $db->sql_fetchrow( $res ) )
- {
- $html .= "<option value=\"{$uid}\">{$uname}</option>";
- }
- $html .= "</select><br /><br /><input type=\"checkbox\" name=\"autocreate\" value=\"1\" checked=\"checked\" /> Check this box to automatically create user (forum posters) accounts instead of choosing them from the list above. By checking this box, the system will not utilize any of the usernames above.</td></tr>";
- $html .= "<tr><td align=\"center\" colspan=\"2\"><br /></td></tr>";
- $html .= "<tr><td valign=\"top\"><b>Posts Interval:</b></td><td align=\"left\">";
- $html .= "<b>From:</b> Month <select name=\"fromtimestamp[0]\">";
- $i = 1;
- for ( ; $i <= 12; ++$i )
- {
- if ( $i == date( "m" ) )
- {
- $sel = "selected=\"selected\"";
- }
- else
- {
- $sel = "";
- }
- $html .= "<option value=\"{$i}\" {$sel}>{$i}</option>";
- }
- $html .= "</select> ";
- $html .= "Day <select name=\"fromtimestamp[1]\">";
- $i = 1;
- for ( ; $i <= 31; ++$i )
- {
- if ( $i == intval( date( "d" ) - 1 ) )
- {
- $sel = "selected=\"selected\"";
- }
- else
- {
- $sel = "";
- }
- $html .= "<option value=\"{$i}\" {$sel}>{$i}</option>";
- }
- $html .= "</select> ";
- $html .= "Year <select name=\"fromtimestamp[2]\">";
- $i = intval( date( "Y" ) + 20 );
- for ( ; intval( date( "Y" ) - 20 ) <= $i; --$i )
- {
- if ( $i == intval( date( "Y" ) ) )
- {
- $sel = "selected=\"selected\"";
- }
- else
- {
- $sel = "";
- }
- $html .= "<option value=\"{$i}\" {$sel}>{$i}</option>";
- }
- $html .= "</select><br /><br />";
- $html .= "<b>To:</b> Month <select name=\"totimestamp[0]\">";
- $i = 1;
- for ( ; $i <= 12; ++$i )
- {
- if ( $i == date( "m" ) )
- {
- $sel = "selected=\"selected\"";
- }
- else
- {
- $sel = "";
- }
- $html .= "<option value=\"{$i}\" {$sel}>{$i}</option>";
- }
- $html .= "</select> ";
- $html .= "Day <select name=\"totimestamp[1]\">";
- $i = 1;
- for ( ; $i <= 31; ++$i )
- {
- if ( $i == date( "d" ) )
- {
- $sel = "selected=\"selected\"";
- }
- else
- {
- $sel = "";
- }
- $html .= "<option value=\"{$i}\" {$sel}>{$i}</option>";
- }
- $html .= "</select> ";
- $html .= "Year <select name=\"totimestamp[2]\">";
- $i = intval( date( "Y" ) + 20 );
- for ( ; intval( date( "Y" ) - 20 ) <= $i; --$i )
- {
- if ( $i == intval( date( "Y" ) ) )
- {
- $sel = "selected=\"selected\"";
- }
- else
- {
- $sel = "";
- }
- $html .= "<option value=\"{$i}\" {$sel}>{$i}</option>";
- }
- $html .= "</select> ";
- $html .= "</td></tr>";
- $html .= "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"Generate Posts!\" /><input type=\"hidden\" name=\"function\" value=\"populate_forum\" /></td></tr></table>";
- $html .= "</form>";
- box2( "Welcome to Instadigi Instant Forum Content Generator. Simply fill up the form below to begin populating your selected forum(s) with posts.", "Welcome!" );
- box( $html, "Populate Forum (".FORUMTYPE.")" );
- foot( );
- }
- function getparent( $parentid, $title )
- {
- global $loader_name;
- global $plugin;
- global $prefix;
- global $db;
- global $forumdbforums;
- list( $id, $cattitle, $catparentid ) = $db->sql_fetchrow( $db->sql_query( "SELECT forumid, title, parentid FROM ".$prefix."forum WHERE forumid='{$parentid}'" ) );
- if ( $cattitle != "" )
- {
- $title = $cattitle."/".$title;
- }
- if ( $catparentid != 0 )
- {
- $title = getparent( $catparentid, $title );
- }
- return $title;
- }
- function populate_forum( $forumid, $maxresults, $yinput, $ytype, $username_array, $fromtimestamp, $totimestamp, $autocreate = 0, $posttype, $allow_multiple_posts = 0, $htmlbr = 0 )
- {
- global $loader_name;
- global $plugin;
- global $db;
- global $prefix;
- global $adminfile;
- global $modulename;
- global $forumdbforums;
- global $forumdbposts;
- global $forumdbcat;
- global $xmlparser;
- $starttimevars = explode( "-", strftime( "%H-%M-%S", time( ) - 20 ) );
- $endtimevars = explode( "-", strftime( "%H-%M-%S", time( ) ) );
- $starttime = mktime( $starttimevars[0], $starttimevars[1], $starttimevars[2], $fromtimestamp[0], $fromtimestamp[1], $fromtimestamp[2] );
- $endtime = mktime( $endtimevars[0], $endtimevars[1], $endtimevars[2], $totimestamp[0], $totimestamp[1], $totimestamp[2] );
- $timeinc = intval( ( $endtime - $starttime ) / $maxresults );
- $ytype = 2;
- if ( $yinput == "" || empty( $forumid ) || 50 < $maxresults || $endtime <= $starttime )
- {
- exit( header( "location: ".httpreferer( )."" ) );
- }
- else if ( sizeof( $username_array ) < 5 && $autocreate == 0 )
- {
- exit( "You should have at least 5 users to proceed." );
- }
- else
- {
- $appid = constant( "APPID" );
- if ( $ytype == 1 )
- {
- $feedurl = "http://answers.yahooapis.com/AnswersService/V1/getByCategory?appid={$appid}&results=".intval( $maxresults )."&type=".$posttype."&sort=date_desc®ion=".REGION."";
- $querylink = "{$feedurl}&category_id={$yinput}";
- }
- else if ( $ytype == 2 )
- {
- $yinput = str_replace( " ", "+", $yinput );
- $feedurl = "http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid={$appid}&results=".intval( $maxresults )."&type=".$posttype."&sort=date_desc®ion=".REGION."";
- $querylink = "{$feedurl}&query={$yinput}";
- }
- else
- {
- exit( );
- }
- $totalquestions = 0;
- $totalanswers = 0;
- $xml = $xmlparser->getxmltree( $querylink );
- $xmlarray_size = sizeof( $xml['RESULTSET'][0]['QUESTION'] );
- head( );
- if ( 0 < $xmlarray_size )
- {
- $i = 0;
- for ( ; $i < $xmlarray_size; ++$i )
- {
- $questionid = htmlspecialchars( $xml['RESULTSET'][0]['QUESTION'][$i]['ATTRIBUTES']['ID'], ENT_QUOTES );
- $subject = strip_tags( addslashes( $xml['RESULTSET'][0]['QUESTION'][$i]['SUBJECT'][0]['VALUE'] ) );
- if ( $htmlbr == 1 )
- {
- $message = nl2br( addslashes( $xml['RESULTSET'][0]['QUESTION'][$i]['CONTENT'][0]['VALUE'] ) );
- }
- else
- {
- $message = addslashes( $xml['RESULTSET'][0]['QUESTION'][$i]['CONTENT'][0]['VALUE'] );
- }
- if ( $allow_multiple_posts == 1 || $allow_multiple_posts != 1 && $db->sql_numrows( $db->sql_query( "SELECT * FROM ".$prefix."post WHERE title='{$subject}'" ) ) <= 0 )
- {
- if ( $autocreate == 1 )
- {
- $yanick = preg_replace( "/[^A-Za-z0-9_-]/i", "", $xml['RESULTSET'][0]['QUESTION'][$i]['USERNICK'][0]['VALUE'] );
- $email = $yanick."@yahoo.com";
- $uq = $db->sql_query( "SELECT user_id FROM ".$prefix."user WHERE username='{$yanick}'" );
- if ( 1 <= $db->sql_numrows( $uq ) )
- {
- list( $poster ) = $db->sql_fetchrow( $uq );
- }
- else
- {
- while ( 0 < $db->sql_numrows( $db->sql_query( "SELECT * FROM ".$prefix."user WHERE username='{$yanick}'" ) ) || $yanick == "" )
- {
- $yanick = $yanick.randomvalue( 4, 3 );
- }
- $result = $db->sql_query( "INSERT INTO ".$prefix."user (email, username, password, joindate, passworddate, showvbcode, daysprune, reputationlevelid, salt, options, usergroupid, usertitle, lastvisit, lastactivity) VALUES ('{$email}', '{$yanick}', '".md5( $yanick.strlen( $yanick ) )."', '".$starttime."', '".strftime( "%Y-%m-%d", $starttime )."', 1, -1, 5, '".randomvalue( 3 )."', 3159, 2, 'Junior Member', ".time( ).", ".time( ).")" );
- $poster = $db->sql_nextid( );
- $uresult1 = $db->sql_query( "INSERT INTO ".$prefix."userfield (userid) VALUES ({$poster})" );
- $uresult2 = $db->sql_query( "INSERT INTO ".$prefix."usertextfield (userid) VALUES ({$poster})" );
- if ( !$result || !$uresult1 || !$uresult2 )
- {
- exit( $db->sql_error( ) );
- }
- }
- }
- else
- {
- $randomposter_key = array_rand( $username_array, 1 );
- $poster = $username_array[$randomposter_key];
- }
- if ( $message == "" || strlen( $message ) < 1 )
- {
- $message = $subject;
- }
- $output = "<i>".htmlspecialchars( stripslashes( $message ), ENT_QUOTES )."</i><br /><br /><b>Replies:</b><br />";
- list( $poster_name ) = $db->sql_fetchrow( $db->sql_query( "SELECT username FROM ".$prefix."user WHERE userid={$poster}" ) );
- $result1 = $db->sql_query( "INSERT INTO ".$prefix."thread (title, forumid, postuserid, dateline, replycount, open, visible) VALUES ('{$subject}', '{$forumid}', '{$poster}', '{$starttime}', '0', '1', '1')" );
- $parenttopicid = $db->sql_nextid( );
- $result2 = $db->sql_query( "INSERT INTO ".$prefix."post (threadid, userid, dateline, ipaddress, title, pagetext, parentid, visible, username, allowsmilie) VALUES ('{$parenttopicid}', '{$poster}', '{$starttime}', '127.0.0.1', '{$subject}', '{$message}', '0', '1', '{$poster_name}', 1)" );
- $parentpostid = $db->sql_nextid( );
- $result3 = $db->sql_query( "UPDATE ".$prefix."thread SET lastpost='{$starttime}', postusername='{$poster_name}', lastposter='{$poster_name}', firstpostid='{$parenttopicid}', lastpostid='{$parentpostid}' WHERE threadid={$parenttopicid}" );
- $result4 = $db->sql_query( "UPDATE ".$prefix."forum SET lastposter='{$poster_name}', lastpost='{$starttime}', lastthread='{$subject}', lastpostid={$parentpostid}, lastthreadid={$parenttopicid}, threadcount=(SELECT count(threadid) FROM ".$prefix."thread WHERE forumid={$forumid}), replycount=replycount+1 WHERE forumid='{$forumid}'" );
- $result5 = $db->sql_query( "UPDATE ".$prefix."user SET lastpost='{$starttime}', lastpostid='{$parentpostid}', posts=(SELECT count(*) FROM ".$prefix."post WHERE userid={$poster} AND userid!=0) WHERE userid={$poster} AND userid!=0" );
- if ( !$result1 || !$result2 || !$result3 || !$result4 || !$result5 )
- {
- exit( "Database Error - Failed to generate post topics!" );
- }
- ++$totalquestions;
- $feedurl2 = "http://answers.yahooapis.com/AnswersService/V1/getQuestion?appid={$appid}";
- $querylink2 = "{$feedurl2}&question_id=".$questionid;
- $xml2 = $xmlparser->getxmltree( $querylink2 );
- $ansxmlsize = sizeof( $xml2['RESULTSET'][0]['QUESTION'][0]['ANSWERS'][0]['ANSWER'] );
- if ( 0 < $ansxmlsize )
- {
- $anstimeinc = intval( $timeinc / $ansxmlsize );
- $ansstarttime = intval( $starttime + $anstimeinc );
- }
- $k = 0;
- for ( ; $k < $ansxmlsize; ++$k )
- {
- if ( $htmlbr == 1 )
- {
- $answer = nl2br( addslashes( $xml2['RESULTSET'][0]['QUESTION'][0]['ANSWERS'][0]['ANSWER'][$k]['CONTENT'][0]['VALUE'] ) );
- }
- else
- {
- $answer = addslashes( $xml2['RESULTSET'][0]['QUESTION'][0]['ANSWERS'][0]['ANSWER'][$k]['CONTENT'][0]['VALUE'] );
- }
- if ( 0 < strlen( $answer ) )
- {
- if ( $autocreate == 1 )
- {
- $ya_replier = preg_replace( "/[^A-Za-z0-9_-]/i", "", $xml2['RESULTSET'][0]['QUESTION'][0]['ANSWERS'][0]['ANSWER'][$k]['USERNICK'][0]['VALUE'] );
- $replier_email = $ya_replier."@yahoo.com";
- $uq = $db->sql_query( "SELECT id FROM ".$prefix."user WHERE username='{$ya_replier}'" );
- if ( 1 <= $db->sql_numrows( $uq ) )
- {
- list( $reply_poster ) = $db->sql_fetchrow( $uq );
- }
- else
- {
- while ( 0 < $db->sql_numrows( $db->sql_query( "SELECT * FROM ".$prefix."user WHERE username='{$ya_replier}'" ) ) || $ya_replier == "" )
- {
- $ya_replier = $ya_replier.randomvalue( 4, 3 );
- }
- $result = $db->sql_query( "INSERT INTO ".$prefix."user (email, username, password, joindate, passworddate, showvbcode, daysprune, reputationlevelid, salt, options, usergroupid, usertitle, lastvisit, lastactivity) VALUES ('{$replier_email}', '{$ya_replier}', '".md5( $ya_replier.strlen( $ya_replier ) )."', '".$ansstarttime."', '".strftime( "%Y-%m-%d", $ansstarttime )."', 1, -1, 5, '".randomvalue( 3 )."', 3159, 2, 'Junior Member', ".time( ).", ".time( ).")" );
- $reply_poster = $db->sql_nextid( );
- $rresult1 = $db->sql_query( "INSERT INTO ".$prefix."userfield (userid) VALUES ({$reply_poster})" );
- $rresult2 = $db->sql_query( "INSERT INTO ".$prefix."usertextfield (userid) VALUES ({$reply_poster})" );
- if ( !$result || !$rresult1 || !$rresult2 )
- {
- exit( $db->sql_error( ) );
- }
- }
- }
- else
- {
- $reply_poster_rand_key = "";
- while ( $reply_poster_rand_key == $randomposter_key || $reply_poster_rand_key == "" )
- {
- $reply_poster_rand_key = array_rand( $username_array, 1 );
- }
- $reply_poster = $username_array[$reply_poster_rand_key];
- }
- list( $reply_poster_name ) = $db->sql_fetchrow( $db->sql_query( "SELECT username FROM ".$prefix."user WHERE userid={$reply_poster}" ) );
- $result1 = $db->sql_query( "INSERT INTO ".$prefix."post (threadid, userid, dateline, ipaddress, title, pagetext, parentid, visible, username, allowsmilie) VALUES ('{$parenttopicid}', '{$reply_poster}', '{$ansstarttime}', '127.0.0.1', '{$subject}', '{$answer}', '0', '1', '{$reply_poster_name}', 1)" );
- $lastpostid = $db->sql_nextid( );
- $result2 = $db->sql_query( "UPDATE ".$prefix."thread SET replycount=replycount+1, views=views+(".rand( 1, 5 )."), lastpost='{$ansstarttime}', postusername='{$poster_name}', lastposter='{$reply_poster_name}', lastpostid='{$lastpostid}' WHERE threadid={$parenttopicid}" );
- $result3 = $db->sql_query( "UPDATE ".$prefix."forum SET lastposter='{$reply_poster_name}', lastpost='{$ansstarttime}', lastthread='{$subject}', lastpostid={$lastpostid}, threadcount=(SELECT count(threadid) FROM ".$prefix."thread WHERE forumid={$forumid}), replycount=replycount+1 WHERE forumid='{$forumid}'" );
- $result4 = $db->sql_query( "UPDATE ".$prefix."user SET lastpost='{$ansstarttime}', lastpostid='{$lastpostid}', posts=(SELECT count(*) FROM ".$prefix."post WHERE userid={$reply_poster} AND userid!=0) WHERE userid={$reply_poster} AND userid!=0" );
- if ( !$result1 || !$result2 || !$result3 || !$result4 )
- {
- exit( "Database Error - Failed to generate post topics!" );
- }
- $output .= "<li>".htmlspecialchars( stripslashes( $answer ), ENT_QUOTES )."</li>";
- ++$totalanswers;
- $ansstarttime = intval( $ansstarttime + $anstimeinc );
- }
- }
- $starttime = intval( $starttime + $timeinc );
- echo "<br />";
- box2( $output, "<b>{$subject}</b>" );
- }
- }
- box( "Topics Posted: {$totalquestions}<br />Topic Replies: {$totalanswers}<br />Total Posts: ".intval( $totalanswers + $totalquestions ), "<b>Results Summary</b>" );
- }
- else
- {
- box( "No results were found for your specified keywords. Please change your keywords and resubmit the form", "<b>Post Generation Error</b>" );
- }
- foot( );
- }
- }
- if ( !defined( "_INDEX_" ) )
- {
- exit( );
- }
- set_time_limit( 0 );
- default :
- pluginindex( );
- switch ( $_REQUEST['function'] )
- {
- case "populate_forum" :
- populate_forum( intval( $_POST['forumid'] ), intval( $_POST['maxresults'] ), $_POST['yinput'], intval( $_POST['ytype'] ), $_POST['usernames'], $_POST['fromtimestamp'], $_POST['totimestamp'], intval( $_POST['autocreate'] ), $_POST['posttype'], intval( $_POST['allow_multiple_posts'] ), intval( $_POST['htmlbr'] ) );
- break;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement