"; // please tweak these parameters to suit your needs $params = Array ( "numUsers" => 100, "numBlogs" => 100, "numPostsPerBlog" => 15, "numCategoriesPerBlog" => 10, "numCategoriesPerPost" => 3, "numUsersPerBlog" => 2, "numCommentsPerArticle" => 10, "numTrackbacksPerArticle" => 10); // to keep track of users $userPool = Array(); // to keep track of blogs $blogPool = Array(); function generateRandomWord($lenght, $uppercase = false, $html = true) { $newcode_length = 1; $newcode = ""; while($newcode_length < $lenght) { $a=97; $b=122; if ($newcode_length == 1) { if (rand(1,4) == 1 || $uppercase) { $a=65; $b=90; } } $code_part=chr(rand($a,$b)); $newcode_length++; $newcode = $newcode.$code_part; } if ($html && rand(1, 50) == 1) { return "$newcode"; } return $newcode; } function generateRandomWords( $count, $uppercase = false, $html = true) { $words = generateRandomWord( rand( 3, 12), $uppercase ); for ($i = 1; $i < $count; $i++) { $rand = rand(3, 12); $words .= ' ' . generateRandomWord( $rand ); } return $words; } function generateRandomParagraph() { $length = rand( 3, 20 ); $counter = 0; $text = '

' . generateRandomWord( rand( 3, 12 ), true ); while ($counter < $length) { $word = generateRandomWords( rand(3, 12) ); $text = $text . ' ' . $word; $counter++; } $text .= "

"; return $text; } function generateRandomParagraphs( $count ) { $text = ''; for ($i = 1; $i < $count; $i++) { $text .= generateRandomParagraph(); } return $text; } function generateRandomDate() { // generate random date between 2000-01-01 and now $time = rand(strtotime('01 January 2005'), time()); return date("Y-m-d H:i:s", $time); } // generate as many users as required and put them in the pool $i = 0; $users = new Users(); print("Adding ".$params["numUsers"]." users...{$nl}"); while( $i < $params["numUsers"] ) { $text = generateRandomWord( rand( 7, 25), false, false ); $user = new UserInfo( $text, // username $text, // password "{$text}@whatever.com", // email address generateRandomWords(rand(3, 12), false, false ), // about meself $text." ".generateRandomWord(rand(3, 12), false, false )); // fullname // add the user to the db if( $users->addUser( $user )) { $userPool[$i+1] = $user; print("User $text added to the db...{$nl}"); ob_flush(); flush(); } else { die("There was an error adding user $i - $text{$nl}"); } $i++; } // generate the blogs and assign users from the pool to them $i = 0; $blogs = new Blogs(); $numBlogs = $params["numBlogs"]; $usersPerBlog = $params["numUsersPerBlog"]; print("Adding ".$numBlogs." blogs with $usersPerBlog users{$nl}"); while( $i < $numBlogs ) { $randUserId = rand(1,$params["numUsers"]); $blog = new BlogInfo( generateRandomWords( rand(1, 10 )), // blog title $userPool[$randUserId]->getId(), // random user owner generateRandomWords( rand(1,20)), // about blog new BlogSettings()); // empty settings // add the blog if( $blogs->addBlog( $blog )) { $blogPool[$blog->getId()] = $blog; // add the extra users $j = 0; $numUsers = rand(1,$usersPerBlog); $permissions = new UserPermissions(); while( $j < $numUsers ) { $perm = new UserPermission( rand(1,$params["numUsers"]), $blog->getId(),PERMISSION_BLOG_USER ); $permissions->grantPermission( $perm ); $j++; } // add the categories $p = 0; $categories = new ArticleCategories(); $blogCatPool = Array(); $catsPerBlog = rand(1,$params["numCategoriesPerBlog"]); while( $p < $catsPerBlog ) { // create the category $category = new ArticleCategory( generateRandomWord( rand(5,12)), // cat name '', // url $blog->getId(), // blog id generateRandomWords( rand(4,15))); // description $catId = $categories->addArticleCategory( $category ); $category->setId( $catId ); // add it to to the blog category pool $blogCatPool[$p+1] = $category; $p++; } // add the posts $k = 0; $articles = new Articles(); $articlesPerBlog = rand(1,$params["numPostsPerBlog"]); while( $k < $articlesPerBlog ) { // create the post $article = new Article( generateRandomWords( rand(1,5)), // topic generateRandomParagraphs(rand(1,4)), // text Array( $blogCatPool[rand(1,$catsPerBlog)]->getId()), // category id $blog->getOwner(), // poster $blog->getId(), // blog POST_STATUS_PUBLISHED, // post status 0 ); // number of times that the post has been read $article->setDate( generateRandomDate() ); $article->setCommentsEnabled( true ); // add the post to the blog $articles->addArticle( $article ); // add the comments per article $l = 0; $commentsPerArticle = rand(1,$params["numCommentsPerArticle"] ); $userComments = new ArticleComments(); while( $l < $commentsPerArticle ) { $userComment = new UserComment( $article->getId(), // art id $blog->getId(), // blog id 0, // parent id generateRandomWords(rand(1,3)), // topic generateRandomParagraph()); // text $userComments->addComment( $userComment ); $l++; } // add the trackbakcs per article $m = 0; $trackbacksPerArticle = rand(1,$params["numTrackbacksPerArticle"] ); $tb = new Trackbacks(); while( $m < $trackbacksPerArticle ) { $url = 'http://www.'.generateRandomWord(10).'.com/'.generateRandomWord(4).'/'.generateRandomWord(15).'.html'; $articleTrackback = new Trackback ( $url, // url generateRandomWords(rand(1,3)), // title $article->getId(), // art id $blog->getId(), // blog id generateRandomParagraph(), //excerpt generateRandomWords(rand(1,2)), // blog name generateRandomDate(), // date '127.0.0.1' // client ip ); $tb->addTrackback( $articleTrackback ); $m++; } $k++; } print("Blog $i added {$nl}"); ob_flush(); flush(); } else { die("There was an error adding blog $i{$nl}"); } $i++; } // generate the categories and put them in the category pool print("Complete!{$nl}"); ?>