00001 <?php
00002
00003 if (!defined( "PLOG_CLASS_PATH" )) {
00004 define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
00005 }
00006
00007 include_once( PLOG_CLASS_PATH."class/object/loader.class.php" );
00008 lt_include( PLOG_CLASS_PATH."class/config/configfilestorage.class.php" );
00009 lt_include( PLOG_CLASS_PATH."class/dao/userpermissions.class.php" );
00010 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" );
00011 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00012 lt_include( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
00013 lt_include( PLOG_CLASS_PATH."class/dao/blogsettings.class.php" );
00014 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
00015 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" );
00016 lt_include( PLOG_CLASS_PATH."class/dao/article.class.php" );
00017 lt_include( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" );
00018 lt_include( PLOG_CLASS_PATH."class/dao/usercomment.class.php" );
00019 lt_include( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" );
00020 lt_include( PLOG_CLASS_PATH."class/dao/trackback.class.php" );
00021
00022
00023 $commandLine = is_array( $argv );
00024 if( $commandLine )
00025 $nl = "\n";
00026 else
00027 $nl = "<br/>";
00028
00029
00030 $params = Array ( "numUsers" => 100,
00031 "numBlogs" => 100,
00032 "numPostsPerBlog" => 15,
00033 "numCategoriesPerBlog" => 10,
00034 "numCategoriesPerPost" => 3,
00035 "numUsersPerBlog" => 2,
00036 "numCommentsPerArticle" => 10,
00037 "numTrackbacksPerArticle" => 10);
00038
00039
00040 $userPool = Array();
00041
00042 $blogPool = Array();
00043
00044 function generateRandomWord($lenght, $uppercase = false, $html = true) {
00045 $newcode_length = 1;
00046 $newcode = "";
00047 while($newcode_length < $lenght) {
00048 $a=97;
00049 $b=122;
00050 if ($newcode_length == 1) {
00051 if (rand(1,4) == 1 || $uppercase) {
00052 $a=65;
00053 $b=90;
00054 }
00055 }
00056 $code_part=chr(rand($a,$b));
00057 $newcode_length++;
00058 $newcode = $newcode.$code_part;
00059 }
00060 if ($html && rand(1, 50) == 1) {
00061 return "<a href=\"http://www.lifetype.net\">$newcode</a>";
00062 }
00063 return $newcode;
00064 }
00065
00066 function generateRandomWords( $count, $uppercase = false, $html = true) {
00067 $words = generateRandomWord( rand( 3, 12), $uppercase );
00068 for ($i = 1; $i < $count; $i++) {
00069 $rand = rand(3, 12);
00070 $words .= ' ' . generateRandomWord( $rand );
00071 }
00072 return $words;
00073 }
00074
00075 function generateRandomParagraph() {
00076 $length = rand( 3, 20 );
00077 $counter = 0;
00078 $text = '<p>' . generateRandomWord( rand( 3, 12 ), true );
00079 while ($counter < $length) {
00080 $word = generateRandomWords( rand(3, 12) );
00081 $text = $text . ' ' . $word;
00082 $counter++;
00083 }
00084 $text .= "</p>";
00085 return $text;
00086 }
00087
00088 function generateRandomParagraphs( $count ) {
00089 $text = '';
00090 for ($i = 1; $i < $count; $i++) {
00091 $text .= generateRandomParagraph();
00092 }
00093 return $text;
00094 }
00095
00096 function generateRandomDate() {
00097
00098 $time = rand(strtotime('01 January 2005'), time());
00099 return date("Y-m-d H:i:s", $time);
00100 }
00101
00102
00103 $i = 0;
00104 $users = new Users();
00105 print("Adding ".$params["numUsers"]." users...{$nl}");
00106 while( $i < $params["numUsers"] ) {
00107 $text = generateRandomWord( rand( 7, 25), false, false );
00108 $user = new UserInfo( $text,
00109 $text,
00110 "{$text}@whatever.com",
00111 generateRandomWords(rand(3, 12), false, false ),
00112 $text." ".generateRandomWord(rand(3, 12), false, false ));
00113
00114
00115 if( $users->addUser( $user )) {
00116 $userPool[$i+1] = $user;
00117 print("User $text added to the db...{$nl}");
00118 ob_flush();
00119 flush();
00120 }
00121 else {
00122 die("There was an error adding user $i - $text{$nl}");
00123 }
00124
00125 $i++;
00126 }
00127
00128
00129 $i = 0;
00130 $blogs = new Blogs();
00131 $numBlogs = $params["numBlogs"];
00132 $usersPerBlog = $params["numUsersPerBlog"];
00133 print("Adding ".$numBlogs." blogs with $usersPerBlog users{$nl}");
00134 while( $i < $numBlogs ) {
00135 $randUserId = rand(1,$params["numUsers"]);
00136 $blog = new BlogInfo( generateRandomWords( rand(1, 10 )),
00137 $userPool[$randUserId]->getId(),
00138 generateRandomWords( rand(1,20)),
00139 new BlogSettings());
00140
00141 if( $blogs->addBlog( $blog )) {
00142 $blogPool[$blog->getId()] = $blog;
00143
00144 $j = 0;
00145 $numUsers = rand(1,$usersPerBlog);
00146 $permissions = new UserPermissions();
00147
00148 while( $j < $numUsers ) {
00149 $perm = new UserPermission( rand(1,$params["numUsers"]), $blog->getId(),PERMISSION_BLOG_USER );
00150 $permissions->grantPermission( $perm );
00151 $j++;
00152 }
00153
00154
00155 $p = 0;
00156 $categories = new ArticleCategories();
00157 $blogCatPool = Array();
00158 $catsPerBlog = rand(1,$params["numCategoriesPerBlog"]);
00159 while( $p < $catsPerBlog ) {
00160
00161
00162 $category = new ArticleCategory( generateRandomWord( rand(5,12)),
00163 '',
00164 $blog->getId(),
00165 generateRandomWords( rand(4,15)));
00166 $catId = $categories->addArticleCategory( $category );
00167 $category->setId( $catId );
00168
00169
00170 $blogCatPool[$p+1] = $category;
00171
00172 $p++;
00173 }
00174
00175
00176 $k = 0;
00177 $articles = new Articles();
00178 $articlesPerBlog = rand(1,$params["numPostsPerBlog"]);
00179 while( $k < $articlesPerBlog ) {
00180
00181 $article = new Article( generateRandomWords( rand(1,5)),
00182 generateRandomParagraphs(rand(1,4)),
00183 Array( $blogCatPool[rand(1,$catsPerBlog)]->getId()),
00184 $blog->getOwner(),
00185 $blog->getId(),
00186 POST_STATUS_PUBLISHED,
00187 0 );
00188 $article->setDate( generateRandomDate() );
00189 $article->setCommentsEnabled( true );
00190
00191
00192 $articles->addArticle( $article );
00193
00194
00195 $l = 0;
00196 $commentsPerArticle = rand(1,$params["numCommentsPerArticle"] );
00197 $userComments = new ArticleComments();
00198 while( $l < $commentsPerArticle ) {
00199 $userComment = new UserComment( $article->getId(),
00200 $blog->getId(),
00201 0,
00202 generateRandomWords(rand(1,3)),
00203 generateRandomParagraph());
00204 $userComments->addComment( $userComment );
00205 $l++;
00206 }
00207
00208
00209 $m = 0;
00210 $trackbacksPerArticle = rand(1,$params["numTrackbacksPerArticle"] );
00211 $tb = new Trackbacks();
00212 while( $m < $trackbacksPerArticle ) {
00213 $url = 'http://www.'.generateRandomWord(10).'.com/'.generateRandomWord(4).'/'.generateRandomWord(15).'.html';
00214 $articleTrackback = new Trackback (
00215 $url,
00216 generateRandomWords(rand(1,3)),
00217 $article->getId(),
00218 $blog->getId(),
00219 generateRandomParagraph(),
00220 generateRandomWords(rand(1,2)),
00221 generateRandomDate(),
00222 '127.0.0.1'
00223 );
00224 $tb->addTrackback( $articleTrackback );
00225 $m++;
00226 }
00227
00228 $k++;
00229 }
00230 print("Blog $i added {$nl}");
00231 ob_flush();
00232 flush();
00233 }
00234 else {
00235 die("There was an error adding blog $i{$nl}");
00236 }
00237
00238 $i++;
00239 }
00240
00241
00242
00243 print("Complete!{$nl}");
00244 ?>