@@ -37,12 +37,12 @@ class Populate
3737{
3838 private $ blockSize = 500 ;
3939 private $ refreshRate = 0 ;
40- private $ loremIpsum = null ;
41- private $ ounters = array ();
40+ private $ loremIpsum ;
41+ private $ counters = array ();
4242
4343 private $ timeStart = 0 ;
4444
45- public function __construct ($ options = array ())
45+ public function __construct ($ options = array ())
4646 {
4747 global $ smcFunc ;
4848
@@ -58,24 +58,23 @@ public function __construct ($options = array())
5858 $ this ->counters ['topics ' ]['current ' ] = 0 ;
5959 $ this ->counters ['messages ' ]['max ' ] = 3000000 ;
6060 $ this ->counters ['messages ' ]['current ' ] = 0 ;
61- $ this ->timeStart = microtime (TRUE );
61+ $ this ->timeStart = microtime (true );
6262
6363 // Override defaults
6464 foreach ($ options as $ _key => $ _value )
6565 $ this ->$ _key = $ _value ;
6666
6767 $ this ->loremIpsum = new LoremIpsumGenerator ();
6868
69- // Determine our 'currents'
69+ $ end = false ;
7070 foreach ($ this ->counters as $ key => $ val )
7171 {
7272 $ request = $ smcFunc ['db_query ' ]('' , 'SELECT COUNT(*) FROM {db_prefix} ' . $ key );
7373 list ($ this ->counters [$ key ]['current ' ]) = $ smcFunc ['db_fetch_row ' ]($ request );
7474 $ smcFunc ['db_free_result ' ]($ request );
7575 if ($ key != 'topics ' && $ this ->counters [$ key ]['current ' ] < $ this ->counters [$ key ]['max ' ])
7676 {
77- $ func = 'make ' .ucfirst ($ key );
78- $ end = false ;
77+ $ func = 'make ' . ucfirst ($ key );
7978 break ;
8079 }
8180 else
@@ -87,7 +86,7 @@ public function __construct ($options = array())
8786 $ this ->complete ($ end );
8887 }
8988
90- private function makeCategories ()
89+ private function makeCategories ()
9190 {
9291 global $ sourcedir ;
9392 require_once ($ sourcedir . '/Subs-Categories.php ' );
@@ -105,7 +104,7 @@ private function makeCategories ()
105104 $ this ->pause ();
106105 }
107106
108- private function makeBoards ()
107+ private function makeBoards ()
109108 {
110109 global $ sourcedir ;
111110 require_once ($ sourcedir . '/Subs-Boards.php ' );
@@ -121,7 +120,7 @@ private function makeBoards ()
121120 if (mt_rand () < (mt_getrandmax () / 2 ))
122121 {
123122 $ boardOptions = array_merge ($ boardOptions , array (
124- 'target_board ' => mt_rand (1 , $ this ->counters ['boards ' ]['current ' ]- 1 ),
123+ 'target_board ' => mt_rand (1 , $ this ->counters ['boards ' ]['current ' ] - 1 ),
125124 'move_to ' => 'child ' ,
126125 ));
127126 }
@@ -132,7 +131,7 @@ private function makeBoards ()
132131 $ this ->pause ();
133132 }
134133
135- private function makeMembergroups ()
134+ private function makeMembergroups ()
136135 {
137136 global $ smcFunc ;
138137
@@ -159,7 +158,7 @@ private function makeMembergroups ()
159158 $ this ->pause ();
160159 }
161160
162- private function makeMembers ()
161+ private function makeMembers ()
163162 {
164163 global $ sourcedir , $ modSettings ;
165164 require_once ($ sourcedir . '/Subs-Members.php ' );
@@ -172,7 +171,7 @@ private function makeMembers ()
172171 $ regOptions = array (
173172 'interface ' => 'admin ' ,
174173 'username ' => 'Member ' . ++$ this ->counters ['members ' ]['current ' ],
175- 'email ' => 'member_ ' . $ this ->counters ['members ' ]['current ' ] . '@ ' . $ _SERVER ['SERVER_NAME ' ] . (strpos ($ _SERVER ['SERVER_NAME ' ], '. ' ) === FALSE ? '.com ' : '' ),
174+ 'email ' => 'member_ ' . $ this ->counters ['members ' ]['current ' ] . '@ ' . $ _SERVER ['SERVER_NAME ' ] . (strpos ($ _SERVER ['SERVER_NAME ' ], '. ' ) === false ? '.com ' : '' ),
176175 'password ' => '' ,
177176 'require ' => 'nothing ' ,
178177 'send_welcome_email ' => false ,
@@ -187,25 +186,25 @@ private function makeMembers ()
187186 $ this ->pause ();
188187 }
189188
190- private function makeMessages ()
189+ private function makeMessages ()
191190 {
192191 global $ sourcedir ;
193192 require_once ($ sourcedir . '/Subs-Post.php ' );
194193
195194 while ($ this ->counters ['messages ' ]['current ' ] < $ this ->counters ['messages ' ]['max ' ] && $ this ->blockSize --)
196195 {
197196 $ msgOptions = array (
198- 'subject ' => trim ($ this ->loremIpsum ->getContent (mt_rand (1 ,6 ), 'txt ' )),
197+ 'subject ' => trim ($ this ->loremIpsum ->getContent (mt_rand (1 , 6 ), 'txt ' )),
199198 'body ' => trim ($ this ->loremIpsum ->getContent (mt_rand (5 , 60 ), 'txt ' )),
200- 'approved ' => TRUE
199+ 'approved ' => true
201200 );
202201
203202 $ makenew = ($ this ->counters ['topics ' ]['current ' ] < $ this ->counters ['topics ' ]['max ' ]) && (mt_rand () < (int )(mt_getrandmax () * ($ this ->counters ['topics ' ]['max ' ] / $ this ->counters ['messages ' ]['max ' ])));
204203
205204 $ topicOptions = array (
206205 'id ' => $ makenew ? 0 : mt_rand (1 , $ this ->counters ['topics ' ]['current ' ]),
207206 'board ' => mt_rand (1 , $ this ->counters ['boards ' ]['max ' ]),
208- 'mark_as_read ' => TRUE ,
207+ 'mark_as_read ' => true ,
209208 );
210209
211210 if ($ makenew )
@@ -216,15 +215,15 @@ private function makeMessages ()
216215 'id ' => $ member ,
217216 'name ' => 'Member ' . $ member ,
218217 'email ' => 'member_ ' . $ member . '@ ' . $ _SERVER ['SERVER_NAME ' ] . '.com ' ,
219- 'update_post_count ' => TRUE ,
218+ 'update_post_count ' => true ,
220219 );
221220
222221 createPost ($ msgOptions , $ topicOptions , $ posterOptions );
223222 }
224223 $ this ->pause ();
225224 }
226225
227- private function pause ($ end = false )
226+ private function pause ($ end = false )
228227 {
229228 if (!$ end )
230229 {
@@ -244,14 +243,14 @@ private function pause ($end = false)
244243 echo '
245244 ' . $ val ['current ' ] . ' of ' . $ val ['max ' ] . ' ' . $ key . ' created<br /> ' ;
246245 echo '
247- Time taken for last request: ' . round (microtime (TRUE ) - $ this ->timeStart , 3 ) . ' seconds ' ;
246+ Time taken for last request: ' . round (microtime (true ) - $ this ->timeStart , 3 ) . ' seconds ' ;
248247
249248 if ($ end )
250249 echo '<br /><br />
251250 <b>Completed</b> ' ;
252251 }
253252
254- private function fixupTopicsBoards ()
253+ private function fixupTopicsBoards ()
255254 {
256255 global $ smcFunc , $ sourcedir , $ db_type ;
257256
@@ -277,7 +276,7 @@ private function fixupTopicsBoards ()
277276 }
278277 }
279278
280- private function complete ($ end )
279+ private function complete ($ end )
281280 {
282281 if ($ end )
283282 {
@@ -287,41 +286,35 @@ private function complete ($end)
287286 }
288287}
289288
290- class LoremIpsumGenerator {
291- /**
292- * Copyright (c) 2009, Mathew Tinsley ([email protected] ) 293- * All rights reserved.
294- *
295- * Redistribution and use in source and binary forms, with or without
296- * modification, are permitted provided that the following conditions are met:
297- * * Redistributions of source code must retain the above copyright
298- * notice, this list of conditions and the following disclaimer.
299- * * Redistributions in binary form must reproduce the above copyright
300- * notice, this list of conditions and the following disclaimer in the
301- * documentation and/or other materials provided with the distribution.
302- * * Neither the name of the organization nor the
303- * names of its contributors may be used to endorse or promote products
304- * derived from this software without specific prior written permission.
305- *
306- * THIS SOFTWARE IS PROVIDED BY MATHEW TINSLEY ''AS IS'' AND ANY
307- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
308- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
309- * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
310- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
311- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
312- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
313- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
314- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
315- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
316- */
317-
318- private $ words , $ wordsPerParagraph , $ wordsPerSentence ;
319-
320- function __construct ($ wordsPer = 100 )
321- {
322- $ this ->wordsPerParagraph = $ wordsPer ;
323- $ this ->wordsPerSentence = 24.460 ;
324- $ this ->words = array (
289+ /**
290+ * Copyright (c) 2009, Mathew Tinsley ([email protected] ) 291+ * All rights reserved.
292+ *
293+ * Redistribution and use in source and binary forms, with or without
294+ * modification, are permitted provided that the following conditions are met:
295+ * * Redistributions of source code must retain the above copyright
296+ * notice, this list of conditions and the following disclaimer.
297+ * * Redistributions in binary form must reproduce the above copyright
298+ * notice, this list of conditions and the following disclaimer in the
299+ * documentation and/or other materials provided with the distribution.
300+ * * Neither the name of the organization nor the
301+ * names of its contributors may be used to endorse or promote products
302+ * derived from this software without specific prior written permission.
303+ *
304+ * THIS SOFTWARE IS PROVIDED BY MATHEW TINSLEY ''AS IS'' AND ANY
305+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
306+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
307+ * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
308+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
309+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
310+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
311+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
312+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
313+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
314+ */
315+ class LoremIpsumGenerator
316+ {
317+ private $ words = array (
325318 'lorem ' ,
326319 'ipsum ' ,
327320 'dolor ' ,
@@ -499,10 +492,20 @@ function __construct ($wordsPer = 100)
499492 'elementum ' ,
500493 'tempor ' ,
501494 'risus ' ,
502- 'cras ' );
503- }
495+ 'cras '
496+ );
497+
498+ private $ wordsPerParagraph = 100 ;
504499
505- function getContent ($ count , $ format = 'html ' , $ loremipsum = true )
500+ private $ wordsPerSentence = 24.460 ;
501+
502+ /**
503+ * @param $count
504+ * @param string $format
505+ * @param bool $loremipsum
506+ * @return array|string
507+ */
508+ function getContent ($ count , $ format = 'html ' , $ loremipsum = true )
506509 {
507510 $ format = strtolower ($ format );
508511
@@ -520,7 +523,7 @@ function getContent ($count, $format = 'html', $loremipsum = true)
520523 }
521524 }
522525
523- private function getWords (&$ arr , $ count , $ loremipsum )
526+ private function getWords (&$ arr , $ count , $ loremipsum )
524527 {
525528 $ i = 0 ;
526529 if ($ loremipsum )
@@ -543,7 +546,7 @@ private function getWords (&$arr, $count, $loremipsum)
543546 }
544547 }
545548
546- private function getPlain ($ count , $ loremipsum , $ returnStr = true )
549+ private function getPlain ($ count , $ loremipsum , $ returnStr = true )
547550 {
548551 $ words = array ();
549552 $ this ->getWords ($ words , $ count , $ loremipsum );
@@ -583,7 +586,7 @@ private function getPlain ($count, $loremipsum, $returnStr = true)
583586 return $ sentences ;
584587 }
585588
586- private function getText ($ count , $ loremipsum )
589+ private function getText ($ count , $ loremipsum )
587590 {
588591 $ sentences = $ this ->getPlain ($ count , $ loremipsum , false );
589592 $ paragraphs = $ this ->getParagraphArr ($ sentences );
@@ -598,7 +601,7 @@ private function getText ($count, $loremipsum)
598601 return implode ("\n\n\t" , $ paragraphStr );
599602 }
600603
601- private function getParagraphArr ($ sentences )
604+ private function getParagraphArr ($ sentences )
602605 {
603606 $ wordsPer = $ this ->wordsPerParagraph ;
604607 $ sentenceAvg = $ this ->wordsPerSentence ;
@@ -627,7 +630,7 @@ private function getParagraphArr ($sentences)
627630 return $ paragraphs ;
628631 }
629632
630- private function getHTML ($ count , $ loremipsum )
633+ private function getHTML ($ count , $ loremipsum )
631634 {
632635 $ sentences = $ this ->getPlain ($ count , $ loremipsum , false );
633636 $ paragraphs = $ this ->getParagraphArr ($ sentences );
@@ -643,7 +646,7 @@ private function getHTML ($count, $loremipsum)
643646 return implode ("\n" , $ paragraphStr );
644647 }
645648
646- private function paragraphToString ($ paragraph , $ htmlCleanCode = false )
649+ private function paragraphToString ($ paragraph , $ htmlCleanCode = false )
647650 {
648651 $ paragraphStr = '' ;
649652 foreach ($ paragraph as $ sentence )
@@ -661,7 +664,7 @@ private function paragraphToString ($paragraph, $htmlCleanCode = false)
661664 * Inserts commas and periods in the given
662665 * word array.
663666 */
664- private function punctuate (& $ sentence )
667+ private function punctuate (& $ sentence )
665668 {
666669 $ count = count ($ sentence );
667670 $ sentence [$ count - 1 ] = $ sentence [$ count - 1 ] . '. ' ;
@@ -687,7 +690,7 @@ private function punctuate (& $sentence)
687690 * sentence of the given length. Average and
688691 * standard deviation are determined superficially
689692 */
690- private function numberOfCommas ($ len )
693+ private function numberOfCommas ($ len )
691694 {
692695 $ avg = (float ) log ($ len , 6 );
693696 $ stdDev = (float ) $ avg / 6.000 ;
@@ -704,7 +707,7 @@ private function numberOfCommas ($len)
704707 * Average: 24.46
705708 * Standard Deviation: 5.08
706709 */
707- private function gaussianSentence ()
710+ private function gaussianSentence ()
708711 {
709712 $ avg = (float ) 24.460 ;
710713 $ stdDev = (float ) 5.080 ;
@@ -718,32 +721,33 @@ private function gaussianSentence ()
718721 * Source:
719722 * http://us.php.net/manual/en/function.rand.php#53784
720723 */
721- private function gauss ()
722- { // N(0,1)
724+ private function gauss ()
725+ {
726+ // N(0,1)
723727 // returns random number with normal distribution:
724728 // mean=0
725729 // std dev=1
726730
727731 // auxilary vars
728- $ x= $ this ->random_0_1 ();
729- $ y= $ this ->random_0_1 ();
732+ $ x = $ this ->random_0_1 ();
733+ $ y = $ this ->random_0_1 ();
730734
731735 // two independent variables with normal distribution N(0,1)
732- $ u= sqrt (-2 * log ($ x ))* cos (2 * pi ()* $ y );
733- $ v= sqrt (-2 * log ($ x ))* sin (2 * pi ()* $ y );
736+ $ u = sqrt (-2 * log ($ x )) * cos (2 * pi () * $ y );
737+ $ v = sqrt (-2 * log ($ x )) * sin (2 * pi () * $ y );
734738
735739 // i will return only one, couse only one needed
736740 return $ u ;
737741 }
738742
739- private function gauss_ms ($ m= 0.0 ,$ s = 1.0 )
743+ private function gauss_ms ($ m = 0.0 , $ s = 1.0 )
740744 {
741- return $ this ->gauss ()* $ s + $ m ;
745+ return $ this ->gauss () * $ s + $ m ;
742746 }
743747
744- private function random_0_1 ()
748+ private function random_0_1 ()
745749 {
746- return (float )rand ()/ (float )getrandmax ();
750+ return (float ) rand () / (float ) getrandmax ();
747751 }
748752
749753}
0 commit comments