1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* testing/gen.php - rough tool to generate pages for testing |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright © 2013 geekwright, LLC. All rights reserved. |
6
|
|
|
* @license gwiki/docs/license.txt GNU General Public License (GPL) |
7
|
|
|
* @since 1.0 |
8
|
|
|
* @author Richard Griffith <[email protected]> |
9
|
|
|
* @package gwiki |
10
|
|
|
*/ |
11
|
|
|
include_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php'; |
12
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'gwiki_view.tpl'; |
13
|
|
|
include XOOPS_ROOT_PATH . '/header.php'; |
14
|
|
|
$dir = basename(dirname(__DIR__)); |
15
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/' . $dir . '/class/GwikiPage.php'; |
16
|
|
|
global $wikiPage; |
17
|
|
|
$wikiPage = new GwikiPage; |
18
|
|
|
|
19
|
|
|
include __DIR__ . '/LoremIpsumGenerator.php'; |
20
|
|
|
$LIGen = new LoremIpsumGenerator; |
21
|
|
|
|
22
|
|
|
$limit = 100; // how many pages per run |
23
|
|
|
$bodylimit = 1000; // max length of a page body in words |
24
|
|
|
|
25
|
|
|
$pageset = ''; |
26
|
|
|
$pscnt = 0; |
27
|
|
|
|
28
|
|
|
if (!empty($_POST['op'])) { |
29
|
|
|
for ($i = 1; $i <= $limit; ++$i) { |
30
|
|
|
$r = mt_rand(1, 1000); |
31
|
|
|
$keylength = 1; |
32
|
|
|
if ($r < 980) { |
33
|
|
|
$keylength = 2; |
34
|
|
|
} |
35
|
|
|
if ($r < 780) { |
36
|
|
|
$keylength = 3; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$keyword = trim($LIGen->getContent($keylength, 'txt', $loremipsum = false)); |
40
|
|
|
$keyword = str_replace(array(' ', '.', ',', "\t"), array('-', '', '', ''), $keyword); |
41
|
|
|
//echo $keyword . "\n"; |
42
|
|
|
$title = $LIGen->getContent(mt_rand(3, 6), 'txt', $loremipsum = false); |
43
|
|
|
$title = str_replace(array('.', ',', "\t"), '', $title); |
44
|
|
|
//echo $title . "\n"; |
45
|
|
|
$body = $LIGen->getContent(mt_rand(60, $bodylimit), 'txt', $loremipsum = true); |
46
|
|
|
//echo $body . "\n"; |
47
|
|
|
|
48
|
|
|
// convert a few single words in body to links |
49
|
|
|
$linklimit = mt_rand(3, 8); |
50
|
|
View Code Duplication |
for ($j = 1; $j < $linklimit; ++$j) { |
|
|
|
|
51
|
|
|
$text = trim($LIGen->getContent(1, 'txt', $loremipsum = false)); |
52
|
|
|
$text = str_replace('.', '', $text); |
53
|
|
|
$link = str_replace(array(' ', '.', ',', "\t"), array('-', '', '', ''), $text); |
54
|
|
|
$body = str_replace(' ' . $text . ' ', ' [[' . $link . '|' . $text . ']] ', $body); |
55
|
|
|
//echo $text.':'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// convert 2 word phrases in body to links - do lots since most won't be found |
59
|
|
|
$linklimit = mt_rand(100, 300); |
60
|
|
View Code Duplication |
for ($j = 1; $j < $linklimit; ++$j) { |
|
|
|
|
61
|
|
|
$text = trim($LIGen->getContent(2, 'txt', $loremipsum = false)); |
62
|
|
|
$text = str_replace('.', '', $text); |
63
|
|
|
$link = str_replace(array(' ', '.', ',', "\t"), array('-', '', '', ''), $text); |
64
|
|
|
$body = str_replace(' ' . $text . ' ', ' [[' . $link . '|' . $text . ']] ', $body); |
65
|
|
|
//echo $text.':'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$wikiPage->keyword = $keyword; |
69
|
|
|
$wikiPage->title = $title; |
70
|
|
|
$wikiPage->display_keyword = $keyword; |
71
|
|
|
$wikiPage->body = $body; |
72
|
|
|
$wikiPage->uid = $xoopsUser ? $xoopsUser->getVar('uid') : 0; |
73
|
|
|
|
74
|
|
|
// randomly pick a random parent page |
75
|
|
|
$parent = ''; |
76
|
|
|
if (mt_rand(0, 1000) > 700) { |
77
|
|
|
$sql = 'SELECT keyword FROM ' . $xoopsDB->prefix('gwiki_pageids') . ' AS r1 '; |
78
|
|
|
$sql .= 'JOIN (SELECT (RAND() * (SELECT MAX(page_id) FROM ' . $xoopsDB->prefix('gwiki_pageids') . ')) AS id) AS r2 '; |
79
|
|
|
$sql .= 'WHERE r1.page_id >= r2.id ORDER BY r1.page_id ASC LIMIT 1 '; |
80
|
|
|
$result = $xoopsDB->query($sql); |
81
|
|
|
if ($result) { |
82
|
|
|
$myrow = $xoopsDB->fetchRow($result); |
83
|
|
|
$parent = $myrow[0]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$wikiPage->parent_page = $parent; |
88
|
|
|
|
89
|
|
|
// randomly construct a page set |
90
|
|
|
if ($pageset === '' && mt_rand(0, 1000) > 950) { |
91
|
|
|
$pageset = $keyword; |
92
|
|
|
$pscnt = mt_rand(3, 20); |
93
|
|
|
} else { |
94
|
|
|
if ((--$pscnt) < 1) { |
95
|
|
|
$pageset = ''; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$wikiPage->page_set_home = $pageset; |
100
|
|
|
$wikiPage->page_set_order = ''; |
101
|
|
|
$wikiPage->meta_description = ''; |
102
|
|
|
$wikiPage->meta_keywords = ''; |
103
|
|
|
$wikiPage->show_in_index = true; |
104
|
|
|
|
105
|
|
|
$success = $wikiPage->addRevision(); |
106
|
|
|
|
107
|
|
|
echo $success . ' - ' . $keyword . ' (' . $pageset . '-' . $parent . ')<br>'; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
echo '<br><br><form method="post"><input type="hidden" name="op" value="doit"><input type="submit" value="Run"></form>'; |
111
|
|
|
|
112
|
|
|
include XOOPS_ROOT_PATH . '/footer.php'; |
113
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.