[pLog-svn] r3333 - plog/trunk
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Fri May 5 03:06:04 GMT 2006
Author: jondaley
Date: 2006-05-05 03:06:03 +0000 (Fri, 05 May 2006)
New Revision: 3333
Removed:
plog/trunk/generateData.php
Log:
the real version is in /tools
Deleted: plog/trunk/generateData.php
===================================================================
--- plog/trunk/generateData.php 2006-05-04 20:39:23 UTC (rev 3332)
+++ plog/trunk/generateData.php 2006-05-05 03:06:03 UTC (rev 3333)
@@ -1,205 +0,0 @@
-<?php
-
-if (!defined( "PLOG_CLASS_PATH" )) {
- define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
-}
-
-include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
-include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
-include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
-include_once( PLOG_CLASS_PATH."class/dao/blogsettings.class.php" );
-include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
-include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
-include_once( PLOG_CLASS_PATH."class/dao/article.class.php" );
-include_once( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
-include_once( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
-
-
-// please tweak these parameters to suit your needs
-$params = Array ( "numUsers" => 50,
- "numBlogs" => 50,
- "numPostsPerBlog" => 15,
- "numCategoriesPerBlog" => 10,
- "numCategoriesPerPost" => 3,
- "numUsersPerBlog" => 3,
- "numCommentsPerArticle" => 5 );
-
-// to keep track of users
-$userPool = Array();
-// to keep track of blogs
-$blogPool = Array();
-
-function generateRandomWord($lenght, $uppercase = false, $html = true) {
- $newcode_length = 1;
- 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 "<a href=\"http://www.plogworld.net\">$newcode</a>";
- }
- 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 = '<p>' . generateRandomWord( rand( 3, 12 ), true );
- while ($counter < $length) {
- $word = generateRandomWords( rand(3, 12) );
- $text = $text . ' ' . $word;
- $counter++;
- }
- $text .= "</p>";
- 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...<br/>");
-while( $i < $params["numUsers"] ) {
- $text = generateRandomWord( rand( 3, 12), 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;
- }
- else {
- print("There was an error adding user $i - $text<br/>");
- }
-
- $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<br/>");
-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 ) {
- $permissions->grantPermission( rand(1,$param["numUsers"]), // user id
- $blog->getId(), // blog id
- PERMISSION_BLOG_USER ); // permission type
-
- $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
- 0, // parent id
- generateRandomWords(rand(1,3)), // topic
- generateRandomParagraph()); // text
- $userComments->addComment( $userComment );
- $l++;
- }
-
- $k++;
- }
- }
- else {
- print("There was an error adding blog $i<br/>");
- }
-
- $i++;
-}
-
-// generate the categories and put them in the category pool
-
-print("Complete!<br/>");
-?>
More information about the pLog-svn
mailing list