@@ -259,6 +259,135 @@ public static function generate_title( $post_index = 0 ) {
259259 return $ title ;
260260 }
261261
262+ /**
263+ * Lorem ipsum word list used by {@see self::get_lipsum()}.
264+ *
265+ * @var string[]
266+ */
267+ private const LIPSUM_WORDS = [
268+ 'lorem ' ,
269+ 'ipsum ' ,
270+ 'dolor ' ,
271+ 'sit ' ,
272+ 'amet ' ,
273+ 'consectetur ' ,
274+ 'adipiscing ' ,
275+ 'elit ' ,
276+ 'sed ' ,
277+ 'do ' ,
278+ 'eiusmod ' ,
279+ 'tempor ' ,
280+ 'incididunt ' ,
281+ 'ut ' ,
282+ 'labore ' ,
283+ 'et ' ,
284+ 'dolore ' ,
285+ 'magna ' ,
286+ 'aliqua ' ,
287+ 'enim ' ,
288+ 'ad ' ,
289+ 'minim ' ,
290+ 'veniam ' ,
291+ 'quis ' ,
292+ 'nostrud ' ,
293+ 'exercitation ' ,
294+ 'ullamco ' ,
295+ 'laboris ' ,
296+ 'nisi ' ,
297+ 'aliquip ' ,
298+ 'ex ' ,
299+ 'ea ' ,
300+ 'commodo ' ,
301+ 'consequat ' ,
302+ 'duis ' ,
303+ 'aute ' ,
304+ 'irure ' ,
305+ 'in ' ,
306+ 'reprehenderit ' ,
307+ 'voluptate ' ,
308+ 'velit ' ,
309+ 'esse ' ,
310+ 'cillum ' ,
311+ 'eu ' ,
312+ 'fugiat ' ,
313+ 'nulla ' ,
314+ 'pariatur ' ,
315+ 'excepteur ' ,
316+ 'sint ' ,
317+ 'occaecat ' ,
318+ 'cupidatat ' ,
319+ 'non ' ,
320+ 'proident ' ,
321+ 'sunt ' ,
322+ 'culpa ' ,
323+ 'qui ' ,
324+ 'officia ' ,
325+ 'deserunt ' ,
326+ 'mollit ' ,
327+ 'anim ' ,
328+ 'id ' ,
329+ 'est ' ,
330+ 'laborum ' ,
331+ 'at ' ,
332+ 'vero ' ,
333+ 'eos ' ,
334+ 'accusamus ' ,
335+ 'accusantium ' ,
336+ 'doloremque ' ,
337+ 'laudantium ' ,
338+ 'totam ' ,
339+ 'rem ' ,
340+ 'aperiam ' ,
341+ 'eaque ' ,
342+ 'ipsa ' ,
343+ 'quae ' ,
344+ 'ab ' ,
345+ 'illo ' ,
346+ 'inventore ' ,
347+ 'veritatis ' ,
348+ 'quasi ' ,
349+ 'architecto ' ,
350+ 'beatae ' ,
351+ 'vitae ' ,
352+ 'dicta ' ,
353+ 'explicabo ' ,
354+ 'nemo ' ,
355+ 'ipsam ' ,
356+ 'voluptas ' ,
357+ 'aspernatur ' ,
358+ 'odit ' ,
359+ 'aut ' ,
360+ 'sequi ' ,
361+ 'nesciunt ' ,
362+ 'neque ' ,
363+ 'porro ' ,
364+ 'quisquam ' ,
365+ 'dolorem ' ,
366+ 'adipisci ' ,
367+ 'numquam ' ,
368+ 'eius ' ,
369+ 'modi ' ,
370+ 'tempora ' ,
371+ 'incidunt ' ,
372+ 'magnam ' ,
373+ 'quaerat ' ,
374+ 'etiam ' ,
375+ 'minima ' ,
376+ 'nostrum ' ,
377+ 'exercitationem ' ,
378+ 'corporis ' ,
379+ 'suscipit ' ,
380+ 'laboriosam ' ,
381+ 'aliquid ' ,
382+ 'commodi ' ,
383+ 'consequatur ' ,
384+ 'quo ' ,
385+ 'vel ' ,
386+ 'illum ' ,
387+ 'eum ' ,
388+ 'iure ' ,
389+ ];
390+
262391 /**
263392 * Generate dummy text.
264393 *
@@ -270,18 +399,46 @@ public static function get_lipsum( $type, $amount ) {
270399 if ( Starter_Content::is_e2e () ) {
271400 return file_get_contents ( NEWSPACK_ABSPATH . 'includes/raw_assets/markup/body.txt ' );
272401 }
273- $ lipsum = new \joshtronic \LoremIpsum ();
274- switch ( $ type ) {
275- case 'paras ' :
276- $ text = $ lipsum ->paragraphs ( $ amount + 1 );
277- $ text = implode ( PHP_EOL , array_slice ( explode ( PHP_EOL , $ text ), 1 ) );
278- break ;
279- default :
280- $ text = $ lipsum ->words ( $ amount + 12 );
281- $ text = implode ( ' ' , array_slice ( explode ( ' ' , $ text ), 12 ) );
282- break ;
402+ if ( 'paras ' === $ type ) {
403+ return implode ( PHP_EOL , self ::lipsum_paragraphs ( $ amount ) );
404+ }
405+ return implode ( ' ' , self ::lipsum_words ( $ amount ) );
406+ }
407+
408+ /**
409+ * Pick $count random words from the lorem ipsum pool.
410+ *
411+ * @param int $count Number of words to return.
412+ * @return string[]
413+ */
414+ private static function lipsum_words ( $ count ) {
415+ $ max = count ( self ::LIPSUM_WORDS ) - 1 ;
416+ $ output = [];
417+ for ( $ i = 0 ; $ i < $ count ; $ i ++ ) {
418+ $ output [] = self ::LIPSUM_WORDS [ wp_rand ( 0 , $ max ) ];
419+ }
420+ return $ output ;
421+ }
422+
423+ /**
424+ * Build $count lorem ipsum paragraphs.
425+ *
426+ * @param int $count Number of paragraphs to return.
427+ * @return string[]
428+ */
429+ private static function lipsum_paragraphs ( $ count ) {
430+ $ paragraphs = [];
431+ for ( $ i = 0 ; $ i < $ count ; $ i ++ ) {
432+ $ sentences = [];
433+ $ num = wp_rand ( 4 , 7 );
434+ for ( $ j = 0 ; $ j < $ num ; $ j ++ ) {
435+ $ words = self ::lipsum_words ( wp_rand ( 6 , 14 ) );
436+ $ words [0 ] = ucfirst ( $ words [0 ] );
437+ $ sentences [] = implode ( ' ' , $ words ) . '. ' ;
438+ }
439+ $ paragraphs [] = implode ( ' ' , $ sentences );
283440 }
284- return $ text ;
441+ return $ paragraphs ;
285442 }
286443
287444 /**
0 commit comments