[pLog-svn] r1769 - plog/branches/plog-1.1-ben

ork at devel.plogworld.net ork at devel.plogworld.net
Wed Apr 6 14:52:35 GMT 2005


Author: ork
Date: 2005-04-06 14:52:34 +0000 (Wed, 06 Apr 2005)
New Revision: 1769

Modified:
   plog/branches/plog-1.1-ben/generateRandomData.php
Log:
at least it's okay to fill the blog for one user :)



Modified: plog/branches/plog-1.1-ben/generateRandomData.php
===================================================================
--- plog/branches/plog-1.1-ben/generateRandomData.php	2005-04-05 23:34:56 UTC (rev 1768)
+++ plog/branches/plog-1.1-ben/generateRandomData.php	2005-04-06 14:52:34 UTC (rev 1769)
@@ -1,43 +1,96 @@
 <?
 
-function generateRandomText($codelenght) {
-    while($newcode_length < $codelenght) {
-        $x=1;
-        $y=4;
-        $part = rand($x,$y);
-        if($part==1){$a=48;$b=57;}  // Numbers
-        if($part==2){$a=65;$b=90;}  // UpperCase
-        if($part==3){$a=97;$b=122;} // LowerCase
-        if($part==4){if ($space > 4) { $newcode = $newcode." "; $space = 0; continue;} }  // Space
+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_length + 1;
+        $newcode_length++;
         $newcode = $newcode.$code_part;
-        $space++;
     }
+    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(946681200, time());
-    return $time;
+    $time = rand(strtotime('01 January 2005'), time());
+    return date("Y-m-d H:i:s", $time);
 }
 
 define( "PLOG_CLASS_PATH", "./" );
 
 require_once( "class/dao/article.class.php" );
 require_once( "class/dao/articles.class.php" );
+require_once( "class/dao/usercomment.class.php" );
+require_once( "class/dao/articlecomments.class.php" );
+require_once( "class/dao/articlecommentstatus.class.php" );
 
-$article = new Article(generateRandomText( 20 ),
-                       generateRandomText( 1024 ),
-                       array( 1 ),
-                       1,
-                       1,
-                       POST_STATUS_PUBLISHED,
-                       1);
 $articles = new Articles();
-$articles->addArticle( $article );
+$comments = new ArticleComments();
+for ($i=0; $i < 10; $i++) {
+    $articleText = generateRandomParagraph( );
+    $article = new Article(generateRandomWords( rand(2, 5), true, false ),
+                           generateRandomParagraphs( rand(1, 4) ),
+                           array( 1 ),
+                           1,
+                           1,
+                           POST_STATUS_PUBLISHED,
+                           1);
+    $article->setDate( generateRandomDate() );
+    $article->setCommentsEnabled( true );
+    $postId = $articles->addArticle( $article );
+    for( $i = rand(0, 9); $i < 10; $i++) {
+        $comment = new UserComment( $postId,
+                                    0,
+                                    generateRandomWords( rand(2, 5), true ),
+                                    generateRandomParagraphs( rand(1 ,2) ),
+                                    generateRandomDate(),
+                                    generateRandomWord( rand(3, 8) ));
+        $comment->setClientIp( '192.168.1.1' );
+        $comment->setStatus( COMMENT_STATUS_NONSPAM );
+        $comments->addComment( $comment );
+    }
+}
 
 
-
 ?>




More information about the pLog-svn mailing list