+ Install-testdata now a plugin package.
gruffen

gruffen commited on 2011-04-25 02:11:53
Showing 7 changed files, with 1060 additions and 0 deletions.

... ...
@@ -0,0 +1,44 @@
1
+<?php
2
+###############################################################
3
+#         Simple Desk Project - www.simpledesk.net            #
4
+###############################################################
5
+#       An advanced help desk modifcation built on SMF        #
6
+###############################################################
7
+#                                                             #
8
+#         * Copyright 2010 - SimpleDesk.net                   #
9
+#                                                             #
10
+#   This file and its contents are subject to the license     #
11
+#   included with this distribution, license.txt, which       #
12
+#   states that this software is New BSD Licensed.            #
13
+#   Any questions, please contact SimpleDesk.net              #
14
+#                                                             #
15
+###############################################################
16
+# SimpleDesk Version: 1.0 Felidae                             #
17
+# File Info: SimpleDesk.english.php / 1.0 Felidae             #
18
+###############################################################
19
+// Version: 1.0 Felidae; SimpleDesk installation test-data
20
+
21
+// Important! Before editing these language files please read the text at the top of index.english.php.
22
+
23
+$txt['shdp_install_testdata'] = 'Install Test-Data';
24
+$txt['shdp_install_testdata_desc'] = 'This plugin creates test data for your helpdesk.';
25
+
26
+$txt['shdp_install_testdata_title'] = 'SimpleDesk test data';
27
+$txt['shdp_install_testdata_invalidtickets'] = 'Invalid ticket count (1-100000)';
28
+$txt['shdp_install_testdata_invalidclosed'] = 'Invalid % of closed tickets (0-100)';
29
+$txt['shdp_install_testdata_invalidassigned'] = 'Invalid % of assigned tickets (0-100)';
30
+$txt['shdp_install_testdata_invalidstaff'] = 'Invalid staff member';
31
+$txt['shd_install_testdata_invalid_dept'] = 'Invalid department';
32
+
33
+$txt['shdp_install_testdata_guestuser'] = '(Guest user)';
34
+$txt['shdp_install_testdata_errors'] = 'Unfortunately, there were some errors';
35
+
36
+$txt['shdp_install_testdata_numtickets'] = 'Number of tickets to make';
37
+$txt['shdp_install_testdata_pcresolved'] = '% chance ticket will be marked resolved';
38
+$txt['shdp_install_testdata_pcassigned'] = '% chance ticket will be marked assigned';
39
+$txt['shdp_install_testdata_staff'] = 'User to use as "staff" in the code';
40
+$txt['shdp_install_testdata_nonstaff'] = 'User to use as "not staff" in the code';
41
+$txt['shdp_install_testdata_dept'] = 'Department the tickets should be added to';
42
+$txt['shdp_install_testdata_create'] = 'Create!';
43
+$txt['shdp_install_testdata_added'] = 'Ticket %1$d added with %2$d replies!';
44
+?>
0 45
\ No newline at end of file
... ...
@@ -0,0 +1,44 @@
1
+<?php
2
+###############################################################
3
+#         Simple Desk Project - www.simpledesk.net            #
4
+###############################################################
5
+#       An advanced help desk modifcation built on SMF        #
6
+###############################################################
7
+#                                                             #
8
+#         * Copyright 2010 - SimpleDesk.net                   #
9
+#                                                             #
10
+#   This file and its contents are subject to the license     #
11
+#   included with this distribution, license.txt, which       #
12
+#   states that this software is New BSD Licensed.            #
13
+#   Any questions, please contact SimpleDesk.net              #
14
+#                                                             #
15
+###############################################################
16
+# SimpleDesk Version: 1.0 Felidae                             #
17
+# File Info: SimpleDesk.english.php / 1.0 Felidae             #
18
+###############################################################
19
+// Version: 1.0 Felidae; SimpleDesk installation test-data
20
+
21
+// Important! Before editing these language files please read the text at the top of index.english.php.
22
+
23
+$txt['shdp_install_testdata'] = 'Install Test-Data';
24
+$txt['shdp_install_testdata_desc'] = 'This plugin creates test data for your helpdesk.';
25
+
26
+$txt['shdp_install_testdata_title'] = 'SimpleDesk test data';
27
+$txt['shdp_install_testdata_invalidtickets'] = 'Invalid ticket count (1-100000)';
28
+$txt['shdp_install_testdata_invalidclosed'] = 'Invalid % of closed tickets (0-100)';
29
+$txt['shdp_install_testdata_invalidassigned'] = 'Invalid % of assigned tickets (0-100)';
30
+$txt['shdp_install_testdata_invalidstaff'] = 'Invalid staff member';
31
+$txt['shd_install_testdata_invalid_dept'] = 'Invalid department';
32
+
33
+$txt['shdp_install_testdata_guestuser'] = '(Guest user)';
34
+$txt['shdp_install_testdata_errors'] = 'Unfortunately, there were some errors';
35
+
36
+$txt['shdp_install_testdata_numtickets'] = 'Number of tickets to make';
37
+$txt['shdp_install_testdata_pcresolved'] = '% chance ticket will be marked resolved';
38
+$txt['shdp_install_testdata_pcassigned'] = '% chance ticket will be marked assigned';
39
+$txt['shdp_install_testdata_staff'] = 'User to use as "staff" in the code';
40
+$txt['shdp_install_testdata_nonstaff'] = 'User to use as "not staff" in the code';
41
+$txt['shdp_install_testdata_dept'] = 'Department the tickets should be added to';
42
+$txt['shdp_install_testdata_create'] = 'Create!';
43
+$txt['shdp_install_testdata_added'] = 'Ticket %1$d added with %2$d replies!';
44
+?>
0 45
\ No newline at end of file
... ...
@@ -0,0 +1,44 @@
1
+<?php
2
+###############################################################
3
+#         Simple Desk Project - www.simpledesk.net            #
4
+###############################################################
5
+#       An advanced help desk modifcation built on SMF        #
6
+###############################################################
7
+#                                                             #
8
+#         * Copyright 2010 - SimpleDesk.net                   #
9
+#                                                             #
10
+#   This file and its contents are subject to the license     #
11
+#   included with this distribution, license.txt, which       #
12
+#   states that this software is New BSD Licensed.            #
13
+#   Any questions, please contact SimpleDesk.net              #
14
+#                                                             #
15
+###############################################################
16
+# SimpleDesk Version: 1.0 Felidae                             #
17
+# File Info: SimpleDesk.english.php / 1.0 Felidae             #
18
+###############################################################
19
+// Version: 1.0 Felidae; SimpleDesk installation test-data
20
+
21
+// Important! Before editing these language files please read the text at the top of index.english.php.
22
+
23
+$txt['shdp_install_testdata'] = 'Install Test-Data';
24
+$txt['shdp_install_testdata_desc'] = 'This plugin creates test data for your helpdesk.';
25
+
26
+$txt['shdp_install_testdata_title'] = 'SimpleDesk test data';
27
+$txt['shdp_install_testdata_invalidtickets'] = 'Invalid ticket count (1-100000)';
28
+$txt['shdp_install_testdata_invalidclosed'] = 'Invalid % of closed tickets (0-100)';
29
+$txt['shdp_install_testdata_invalidassigned'] = 'Invalid % of assigned tickets (0-100)';
30
+$txt['shdp_install_testdata_invalidstaff'] = 'Invalid staff member';
31
+$txt['shd_install_testdata_invalid_dept'] = 'Invalid department';
32
+
33
+$txt['shdp_install_testdata_guestuser'] = '(Guest user)';
34
+$txt['shdp_install_testdata_errors'] = 'Unfortunately, there were some errors';
35
+
36
+$txt['shdp_install_testdata_numtickets'] = 'Number of tickets to make';
37
+$txt['shdp_install_testdata_pcresolved'] = '% chance ticket will be marked resolved';
38
+$txt['shdp_install_testdata_pcassigned'] = '% chance ticket will be marked assigned';
39
+$txt['shdp_install_testdata_staff'] = 'User to use as "staff" in the code';
40
+$txt['shdp_install_testdata_nonstaff'] = 'User to use as "not staff" in the code';
41
+$txt['shdp_install_testdata_dept'] = 'Department the tickets should be added to';
42
+$txt['shdp_install_testdata_create'] = 'Create!';
43
+$txt['shdp_install_testdata_added'] = 'Ticket %1$d added with %2$d replies!';
44
+?>
0 45
\ No newline at end of file
... ...
@@ -0,0 +1,44 @@
1
+<?php
2
+###############################################################
3
+#         Simple Desk Project - www.simpledesk.net            #
4
+###############################################################
5
+#       An advanced help desk modifcation built on SMF        #
6
+###############################################################
7
+#                                                             #
8
+#         * Copyright 2010 - SimpleDesk.net                   #
9
+#                                                             #
10
+#   This file and its contents are subject to the license     #
11
+#   included with this distribution, license.txt, which       #
12
+#   states that this software is New BSD Licensed.            #
13
+#   Any questions, please contact SimpleDesk.net              #
14
+#                                                             #
15
+###############################################################
16
+# SimpleDesk Version: 1.0 Felidae                             #
17
+# File Info: SimpleDesk.english.php / 1.0 Felidae             #
18
+###############################################################
19
+// Version: 1.0 Felidae; SimpleDesk installation test-data
20
+
21
+// Important! Before editing these language files please read the text at the top of index.english.php.
22
+
23
+$txt['shdp_install_testdata'] = 'Install Test-Data';
24
+$txt['shdp_install_testdata_desc'] = 'This plugin creates test data for your helpdesk.';
25
+
26
+$txt['shdp_install_testdata_title'] = 'SimpleDesk test data';
27
+$txt['shdp_install_testdata_invalidtickets'] = 'Invalid ticket count (1-100000)';
28
+$txt['shdp_install_testdata_invalidclosed'] = 'Invalid % of closed tickets (0-100)';
29
+$txt['shdp_install_testdata_invalidassigned'] = 'Invalid % of assigned tickets (0-100)';
30
+$txt['shdp_install_testdata_invalidstaff'] = 'Invalid staff member';
31
+$txt['shd_install_testdata_invalid_dept'] = 'Invalid department';
32
+
33
+$txt['shdp_install_testdata_guestuser'] = '(Guest user)';
34
+$txt['shdp_install_testdata_errors'] = 'Unfortunately, there were some errors';
35
+
36
+$txt['shdp_install_testdata_numtickets'] = 'Number of tickets to make';
37
+$txt['shdp_install_testdata_pcresolved'] = '% chance ticket will be marked resolved';
38
+$txt['shdp_install_testdata_pcassigned'] = '% chance ticket will be marked assigned';
39
+$txt['shdp_install_testdata_staff'] = 'User to use as "staff" in the code';
40
+$txt['shdp_install_testdata_nonstaff'] = 'User to use as "not staff" in the code';
41
+$txt['shdp_install_testdata_dept'] = 'Department the tickets should be added to';
42
+$txt['shdp_install_testdata_create'] = 'Create!';
43
+$txt['shdp_install_testdata_added'] = 'Ticket %1$d added with %2$d replies!';
44
+?>
0 45
\ No newline at end of file
... ...
@@ -0,0 +1,782 @@
1
+<?php
2
+###########################################################
3
+#       Simple Desk Project - www.simpledesk.net          #
4
+###########################################################
5
+#     An advanced help desk modifcation built on SMF      #
6
+###########################################################
7
+#                                                         #
8
+#       * Copyright 2010 - SimpleDesk.net                 #
9
+#                                                         #
10
+# This file and its contents are subject to the license   #
11
+# included with this distribution, license.txt, which     #
12
+# states that this software is New BSD Licensed.          #
13
+# Any questions, please contact SimpleDesk.net            #
14
+#                                                         #
15
+###########################################################
16
+# SimpleDesk Version: 1.0 RC1                             #
17
+# File Info: install-testdata.php / 1.0 RC1               #
18
+###########################################################
19
+
20
+/**
21
+ *	This script allows for large volumes of ticket data to be generated quickly for testing SimpleDesk.
22
+ *
23
+ *	This file is not part of standard distributions of SimpleDesk; it is maintained internally by the dev team for use
24
+ *	with testing features, and is not generally available.
25
+ *
26
+ *	It is meant to be executed through adding to the root directory of the forum, where SSI.php is, and simple call by URL.
27
+ *
28
+ *	@package installer
29
+ *	@since 1.0
30
+ */
31
+
32
+/**
33
+ *	Before attempting to execute, this file attempts to load SSI.php to enable access to the database functions.
34
+*/
35
+
36
+$context = array();
37
+if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
38
+	require_once(dirname(__FILE__) . '/SSI.php');
39
+elseif (!defined('SMF')) // If we are outside SMF and can't find SSI.php, then throw an error
40
+	die('<b>Error:</b> Cannot install - please verify you put this file in the same place as SMF\'s SSI.php.');
41
+elseif (!defined('TICKET_STATUS_NEW')) // SD isn't loaded and active
42
+	die('<b>SimpleDesk needs to be installed and active before running this script.</b>');
43
+
44
+$db_show_debug = false;
45
+shd_load_language('SDPluginInstallTestdata');
46
+
47
+/**
48
+ *	This also requires a subsidiary file to be able to use the post-creation functions.
49
+ *
50
+ *	@see shd_create_ticket_post()
51
+ *	@see shd_members_allowed_to()
52
+*/
53
+require_once($sourcedir . '/sd_source/Subs-SimpleDeskPost.php');
54
+
55
+$lorem = new LoremIpsumGenerator;
56
+
57
+if (SMF == 'SSI')
58
+{
59
+	$context['page_title_html_safe'] = $txt['shdp_install_testdata_title'];
60
+	template_header();
61
+
62
+	// Get departments
63
+	$depts = array();
64
+	$query = $smcFunc['db_query']('', '
65
+		SELECT id_dept, dept_name
66
+		FROM {db_prefix}helpdesk_depts
67
+		ORDER BY dept_order');
68
+	while ($row = $smcFunc['db_fetch_assoc']($query))
69
+		$depts[$row['id_dept']] = $row['dept_name'];
70
+	$smcFunc['db_free_result']($query);
71
+
72
+	$do_form = false;
73
+	$errors = array();
74
+
75
+	$num_tickets = !empty($_POST['tickets']) ? (int) $_POST['tickets'] : 0;
76
+	if ($num_tickets == 0 || $num_tickets > 100000)
77
+		$errors[] = $txt['shdp_install_testdata_invalidtickets'];
78
+
79
+	$pc_closed = !empty($_POST['closed_chance']) ? (int) $_POST['closed_chance'] : 0;
80
+	if ($pc_closed > 100)
81
+		$errors[] = $txt['shdp_install_testdata_invalidclosed'];
82
+
83
+	$pc_assigned = !empty($_POST['assigned_chance']) ? (int) $_POST['assigned_chance'] : 0;
84
+	if ($pc_assigned > 100)
85
+		$errors[] = $txt['shdp_install_testdata_invalidassigned'];
86
+
87
+	$staff_member = !empty($_POST['staff_member']) ? (int) $_POST['staff_member'] : 0;
88
+	if ($staff_member == 0)
89
+		$errors[] = $txt['shdp_install_testdata_invalidstaff'];
90
+
91
+	$user_member = !empty($_POST['user_member']) ? (int) $_POST['user_member'] : 0;
92
+
93
+	$staff = shd_members_allowed_to('shd_staff', 0);
94
+	$names = array(
95
+		0 => $txt['shdp_install_testdata_guestuser'],
96
+	);
97
+
98
+	$dest_dept = !empty($_POST['dept']) ? (int) $_POST['dept'] : 0;
99
+	if (!isset($depts[$dest_dept]))
100
+		$errors[] = $txt['shd_install_testdata_invalid_dept'];
101
+
102
+	$query = $smcFunc['db_query']('', '
103
+		SELECT id_member, real_name
104
+		FROM {db_prefix}members
105
+		ORDER BY real_name
106
+	', array());
107
+
108
+	while ($row = $smcFunc['db_fetch_assoc']($query))
109
+		$names[$row['id_member']] = $row['real_name'];
110
+
111
+	$nonstaff = array_diff(array_keys($names), $staff);
112
+
113
+	if (!empty($errors))
114
+	{
115
+		echo '
116
+				<div class="tborder">
117
+					<div class="cat_bar">
118
+						<h3 class="catbg">
119
+							<img src="', $settings['default_images_url'], '/simpledesk/ticket.png" alt="x" /> ', $txt['shdp_install_testdata_title'], '
120
+						</h3>
121
+					</div>
122
+					<div class="windowbg">
123
+						<span class="topslice"><span></span></span>';
124
+
125
+		if (isset($_POST['go']))
126
+		{
127
+			// crap, that means we actually did the form submission but it was borked somehow :(
128
+			echo '
129
+						<div class="content">', $txt['shdp_install_testdata_errors'], ':
130
+						<ul>';
131
+			foreach ($errors as $msg)
132
+				echo '
133
+							<li>', $msg, '</li>';
134
+
135
+			echo '
136
+						</ul>
137
+						</div>';
138
+		}
139
+
140
+		echo '
141
+						<form id="creator" name="creator" action="', $boardurl, '/install-testdata.php" method="post">
142
+							<input type="hidden" name="go" value="yeah" />
143
+							<div class="content">
144
+								<dl>
145
+									<dt><strong>', $txt['shdp_install_testdata_numtickets'], ':</strong></dt>
146
+									<dd><input type="text" size="5" value="100" name="tickets" class="input_text" /></dd>
147
+									<dt><strong>', $txt['shdp_install_testdata_pcresolved'], ':</strong></dt>
148
+									<dd><input type="text" size="5" value="30" name="closed_chance" class="input_text" /></dd>
149
+									<dt><strong>', $txt['shdp_install_testdata_pcassigned'], ':</strong></dt>
150
+									<dd><input type="text" size="5" value="10" name="assigned_chance" class="input_text" /></dd>									
151
+									<dt><strong>', $txt['shdp_install_testdata_staff'], ':</strong></dt>
152
+									<dd>
153
+										<select name="staff_member">';
154
+		foreach ($staff as $member)
155
+			echo '
156
+											<option value="', $member, '">', $smcFunc['htmlspecialchars']($names[$member]), '</option>';
157
+
158
+		echo '
159
+										</select>
160
+									</dd>
161
+									<dt><strong>', $txt['shdp_install_testdata_nonstaff'], ':</strong></dt>
162
+									<dd>
163
+										<select name="user_member">';
164
+		foreach ($nonstaff as $member)
165
+			echo '
166
+											<option value="', $member, '">', $smcFunc['htmlspecialchars']($names[$member]), '</option>';
167
+
168
+		echo '
169
+										</select>
170
+									</dd>
171
+									<dt><strong>', $txt['shdp_install_testdata_dept'], ':</strong></dt>
172
+									<dd>
173
+										<select name="dept">';
174
+		foreach ($depts as $id => $dept)
175
+		{
176
+			echo '
177
+											<option value="', $id, '">', $dept, '</option>';
178
+		}
179
+
180
+		echo '
181
+										</select>
182
+									</dd>
183
+								</dl>
184
+								<input type="submit" value="', $txt['shdp_install_testdata_create'], '" class="button_submit" />
185
+							</div>
186
+						</form>
187
+						<span class="botslice"><span></span></span>
188
+					</div>
189
+				</div>';
190
+	}
191
+	else
192
+	{
193
+		echo '
194
+				<div class="tborder">
195
+					<div class="cat_bar">
196
+						<h3 class="catbg">
197
+							<img src="', $settings['default_images_url'], '/simpledesk/ticket.png" alt="x" /> ', $txt['shdp_install_testdata_title'], '
198
+						</h3>
199
+					</div>
200
+					<div class="windowbg">
201
+						<span class="topslice"><span></span></span>
202
+						<div class="content">';
203
+
204
+		// Right, let's be naughty.
205
+		@set_time_limit(0);
206
+		ob_end_flush();
207
+		ob_end_flush();
208
+
209
+		for ($i = 1; $i <= $num_tickets; $i++)
210
+		{
211
+			// Some fun facts and figures of the ticket
212
+			$assigned = $pc_assigned > mt_rand(1,100) ? $staff_member : 0;
213
+			$closed = ($pc_closed > mt_rand(1,100));
214
+			$length = 100 + mt_rand(-50, 50) + mt_rand(-25, 25); // range of 25 to 175 words
215
+
216
+			$num_replies = 0;
217
+			$replies = rand(0, 6) + rand(-1, 3) + rand(-1, 5);
218
+			$replies = max(0, $replies); // make it at least zero
219
+
220
+			// Set up the ticket details
221
+			$posterOptions = array(
222
+				'id' => $user_member,
223
+				'name' => $names[$user_member],
224
+				'email' => 'user@example.com',
225
+			);
226
+
227
+			$msgOptions = array(
228
+				'body' => $lorem->getText($length, true),
229
+				'id' => 0,
230
+				'smileys_enabled' => true,
231
+			);
232
+
233
+			$ticketOptions = array(
234
+				'id' => 0,
235
+				'mark_as_read' => true,
236
+				'subject' => 'Ticket ' . $i,
237
+				'private' => false,
238
+				'status' => $closed ? TICKET_STATUS_CLOSED : TICKET_STATUS_NEW,
239
+				'urgency' => TICKET_URGENCY_LOW,
240
+				'assigned' => $assigned,
241
+				'dept' => $dest_dept,
242
+			);
243
+
244
+			shd_create_ticket_post($msgOptions, $ticketOptions, $posterOptions);
245
+
246
+			if ($replies > 0)
247
+			{
248
+				$staff_pc_reply = 65; // % chance a reply will be staff replying
249
+				for ($j = 0; $j < $replies; $j++)
250
+				{
251
+					$reply_length = 75 + mt_rand(-25, 10) + mt_rand(-25, 10);
252
+					// Setting up for a reply
253
+					$msgOptions = array(
254
+						'body' => $lorem->getText($reply_length, true),
255
+						'id' => 0,
256
+						'smileys_enabled' => true,
257
+					);
258
+
259
+					if ($staff_pc_reply <= rand(1,100))
260
+					{
261
+						$posterOptions = array(
262
+							'id' => $staff_member,
263
+							'name' => $names[$staff_member],
264
+							'email' => 'user@example.com',
265
+						);
266
+						$ticketOptions['status'] = TICKET_STATUS_PENDING_USER;
267
+					}
268
+					else
269
+					{
270
+						$posterOptions = array(
271
+							'id' => $user_member,
272
+							'name' => $names[$user_member],
273
+							'email' => 'user@example.com',
274
+						);
275
+						$ticketOptions['status'] = TICKET_STATUS_PENDING_STAFF;
276
+					}
277
+
278
+					if ($closed) // override!!
279
+						$ticketOptions['status'] = TICKET_STATUS_CLOSED;
280
+
281
+					shd_create_ticket_post($msgOptions, $ticketOptions, $posterOptions);
282
+				}
283
+			}
284
+
285
+			$smcFunc['db_query']('', '
286
+				UPDATE {db_prefix}helpdesk_tickets
287
+				SET last_updated = {int:time}
288
+				WHERE id_ticket = {int:ticket}',
289
+				array(
290
+					'ticket' => $ticketOptions['id'],
291
+					'time' => time(),
292
+				)
293
+			);
294
+
295
+			echo sprintf($txt['shdp_install_testdata_added'], $i, $replies), ' <br />';
296
+			flush();
297
+		}
298
+
299
+		echo '
300
+						</div>
301
+						<span class="botslice"><span></span></span>
302
+					</div>
303
+				</div>';
304
+	}
305
+
306
+	template_footer();
307
+}
308
+
309
+/**
310
+ *	Copyright (c) 2009, Mathew Tinsley (tinsley@tinsology.net)
311
+ *	All rights reserved.
312
+ *
313
+ *	Redistribution and use in source and binary forms, with or without
314
+ *	modification, are permitted provided that the following conditions are met:
315
+ *		* Redistributions of source code must retain the above copyright
316
+ *		  notice, this list of conditions and the following disclaimer.
317
+ *		* Redistributions in binary form must reproduce the above copyright
318
+ *		  notice, this list of conditions and the following disclaimer in the
319
+ *		  documentation and/or other materials provided with the distribution.
320
+ *		* Neither the name of the organization nor the
321
+ *		  names of its contributors may be used to endorse or promote products
322
+ *		  derived from this software without specific prior written permission.
323
+ *
324
+ *	THIS SOFTWARE IS PROVIDED BY MATHEW TINSLEY ''AS IS'' AND ANY
325
+ *	EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
326
+ *	WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
327
+ *	DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
328
+ *	DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
329
+ *	(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
330
+ *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
331
+ *	ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
332
+ *	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
333
+ *	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
334
+ *
335
+ *
336
+ *
337
+ *	Changes to this are made by SimpleDesk, and this resultant class is similarly BSD licensed.
338
+ *	-- Arantor, SimpleDesk Lead Developer.
339
+ *
340
+ *	Changed:
341
+ *	- Made PHP 4 compatible (for SMF 2.0 compatibility reasons)
342
+ *	- Added smileys
343
+ *	- Reformatted to comply with SMF coding guidelines
344
+ *	- Removed plain and HTML modes, text mode edited
345
+ *	- Made it capitalise sentences nicely.
346
+ *
347
+ *	@package installer
348
+ *	@since 1.0
349
+*/
350
+
351
+class LoremIpsumGenerator {
352
+	var $words, $wordsPerParagraph, $wordsPerSentence, $bbcode, $smileys;
353
+
354
+	function __construct($wordsPer = 100)
355
+	{
356
+		$this->wordsPerParagraph = $wordsPer;
357
+		$this->wordsPerSentence = 24.460;
358
+		$this->words = array
359
+		(
360
+			'lorem',
361
+			'ipsum',
362
+			'dolor',
363
+			'sit',
364
+			'amet',
365
+			'consectetur',
366
+			'adipiscing',
367
+			'elit',
368
+			'curabitur',
369
+			'vel',
370
+			'hendrerit',
371
+			'libero',
372
+			'eleifend',
373
+			'blandit',
374
+			'nunc',
375
+			'ornare',
376
+			'odio',
377
+			'ut',
378
+			'orci',
379
+			'gravida',
380
+			'imperdiet',
381
+			'nullam',
382
+			'purus',
383
+			'lacinia',
384
+			'a',
385
+			'pretium',
386
+			'quis',
387
+			'congue',
388
+			'praesent',
389
+			'sagittis',
390
+			'laoreet',
391
+			'auctor',
392
+			'mauris',
393
+			'non',
394
+			'velit',
395
+			'eros',
396
+			'dictum',
397
+			'proin',
398
+			'accumsan',
399
+			'sapien',
400
+			'nec',
401
+			'massa',
402
+			'volutpat',
403
+			'venenatis',
404
+			'sed',
405
+			'eu',
406
+			'molestie',
407
+			'lacus',
408
+			'quisque',
409
+			'porttitor',
410
+			'ligula',
411
+			'dui',
412
+			'mollis',
413
+			'tempus',
414
+			'at',
415
+			'magna',
416
+			'vestibulum',
417
+			'turpis',
418
+			'ac',
419
+			'diam',
420
+			'tincidunt',
421
+			'id',
422
+			'condimentum',
423
+			'enim',
424
+			'sodales',
425
+			'in',
426
+			'hac',
427
+			'habitasse',
428
+			'platea',
429
+			'dictumst',
430
+			'aenean',
431
+			'neque',
432
+			'fusce',
433
+			'augue',
434
+			'leo',
435
+			'eget',
436
+			'semper',
437
+			'mattis',
438
+			'tortor',
439
+			'scelerisque',
440
+			'nulla',
441
+			'interdum',
442
+			'tellus',
443
+			'malesuada',
444
+			'rhoncus',
445
+			'porta',
446
+			'sem',
447
+			'aliquet',
448
+			'et',
449
+			'nam',
450
+			'suspendisse',
451
+			'potenti',
452
+			'vivamus',
453
+			'luctus',
454
+			'fringilla',
455
+			'erat',
456
+			'donec',
457
+			'justo',
458
+			'vehicula',
459
+			'ultricies',
460
+			'varius',
461
+			'ante',
462
+			'primis',
463
+			'faucibus',
464
+			'ultrices',
465
+			'posuere',
466
+			'cubilia',
467
+			'curae',
468
+			'etiam',
469
+			'cursus',
470
+			'aliquam',
471
+			'quam',
472
+			'dapibus',
473
+			'nisl',
474
+			'feugiat',
475
+			'egestas',
476
+			'class',
477
+			'aptent',
478
+			'taciti',
479
+			'sociosqu',
480
+			'ad',
481
+			'litora',
482
+			'torquent',
483
+			'per',
484
+			'conubia',
485
+			'nostra',
486
+			'inceptos',
487
+			'himenaeos',
488
+			'phasellus',
489
+			'nibh',
490
+			'pulvinar',
491
+			'vitae',
492
+			'urna',
493
+			'iaculis',
494
+			'lobortis',
495
+			'nisi',
496
+			'viverra',
497
+			'arcu',
498
+			'morbi',
499
+			'pellentesque',
500
+			'metus',
501
+			'commodo',
502
+			'ut',
503
+			'facilisis',
504
+			'felis',
505
+			'tristique',
506
+			'ullamcorper',
507
+			'placerat',
508
+			'aenean',
509
+			'convallis',
510
+			'sollicitudin',
511
+			'integer',
512
+			'rutrum',
513
+			'duis',
514
+			'est',
515
+			'etiam',
516
+			'bibendum',
517
+			'donec',
518
+			'pharetra',
519
+			'vulputate',
520
+			'maecenas',
521
+			'mi',
522
+			'fermentum',
523
+			'consequat',
524
+			'suscipit',
525
+			'aliquam',
526
+			'habitant',
527
+			'senectus',
528
+			'netus',
529
+			'fames',
530
+			'quisque',
531
+			'euismod',
532
+			'curabitur',
533
+			'lectus',
534
+			'elementum',
535
+			'tempor',
536
+			'risus',
537
+			'cras',
538
+		);
539
+
540
+		$this->bbcode = array(
541
+			'b',
542
+			'i',
543
+			'u',
544
+			's',
545
+		);
546
+
547
+		$this->smileys = array(
548
+			':)',
549
+			';)',
550
+			':D',
551
+			';D',
552
+			'>:(',
553
+			':(',
554
+			':o',
555
+			'8)',
556
+			'???',
557
+			'::)',
558
+			':P',
559
+			':-[',
560
+			':-X',
561
+			':-\\',
562
+			':-*',
563
+			':\'(',
564
+		);
565
+	}
566
+
567
+	function getWords(&$arr, $count, $loremipsum)
568
+	{
569
+		$i = 0;
570
+		if($loremipsum)
571
+		{
572
+			$i = 2;
573
+			$arr[0] = 'lorem';
574
+			$arr[1] = 'ipsum';
575
+		}
576
+
577
+		for($i; $i < $count; $i++)
578
+		{
579
+			$index = array_rand($this->words);
580
+			$word = $this->words[$index];
581
+
582
+			if($i > 0 && $arr[$i - 1] == $word)
583
+				$i--;
584
+			else
585
+				$arr[$i] = $word;
586
+		}
587
+	}
588
+
589
+	function getPlain($count, $loremipsum, $returnStr = true)
590
+	{
591
+		$words = array();
592
+		$this->getWords($words, $count, $loremipsum);
593
+
594
+		$delta = $count;
595
+		$curr = 0;
596
+		$sentences = array();
597
+		while($delta > 0)
598
+		{
599
+			$senSize = $this->gaussianSentence();
600
+			if(($delta - $senSize) < 4)
601
+				$senSize = $delta;
602
+
603
+			$delta -= $senSize;
604
+
605
+			$sentence = array();
606
+			for($i = $curr; $i < ($curr + $senSize); $i++)
607
+				$sentence[] = $words[$i];
608
+
609
+			$this->punctuate($sentence);
610
+			$curr = $curr + $senSize;
611
+			$sentences[] = $sentence;
612
+		}
613
+
614
+		if($returnStr)
615
+		{
616
+			$output = '';
617
+			foreach($sentences as $s)
618
+				foreach($s as $w)
619
+					$output .= $w . ' ';
620
+
621
+			return $output;
622
+		}
623
+		else
624
+			return $sentences;
625
+	}
626
+
627
+	function getText($count, $loremipsum = true)
628
+	{
629
+		if ($count <= 0)
630
+			return '';
631
+
632
+		$sentences = $this->getPlain($count, $loremipsum, false);
633
+		$paragraphs = $this->getParagraphArr($sentences);
634
+
635
+		$paragraphStr = array();
636
+		foreach($paragraphs as $p)
637
+			$paragraphStr[] = $this->paragraphToString($p);
638
+
639
+		return implode("\n\n", $paragraphStr);
640
+	}
641
+
642
+	function getParagraphArr($sentences)
643
+	{
644
+		$wordsPer = $this->wordsPerParagraph;
645
+		$sentenceAvg = $this->wordsPerSentence;
646
+		$total = count($sentences);
647
+
648
+		$paragraphs = array();
649
+		$pCount = 0;
650
+		$currCount = 0;
651
+		$curr = array();
652
+
653
+		for($i = 0; $i < $total; $i++)
654
+		{
655
+			$s = $sentences[$i];
656
+			$currCount += count($s);
657
+			$curr[] = $s;
658
+			if($currCount >= ($wordsPer - round($sentenceAvg / 2.00)) || $i == $total - 1)
659
+			{
660
+				$currCount = 0;
661
+				$paragraphs[] = $curr;
662
+				$curr = array();
663
+				//print_r($paragraphs);
664
+			}
665
+			//print_r($paragraphs);
666
+		}
667
+
668
+		return $paragraphs;
669
+	}
670
+
671
+	function paragraphToString($paragraph, $htmlCleanCode = false)
672
+	{
673
+		$paragraphStr = '';
674
+		foreach($paragraph as $sentence)
675
+		{
676
+			foreach($sentence as $word)
677
+				$paragraphStr .= $word . ' ';
678
+
679
+			if($htmlCleanCode)
680
+				$paragraphStr .= "\n";
681
+		}
682
+		return $paragraphStr;
683
+	}
684
+
685
+	/*
686
+	* Inserts commas and periods in the given
687
+	* word array.
688
+	*/
689
+	function punctuate(& $sentence)
690
+	{
691
+		$count = count($sentence);
692
+		$sentence[$count - 1] .= '.';
693
+		$sentence[0] = ucfirst($sentence[0]);
694
+
695
+		if($count < 4)
696
+			return $sentence;
697
+
698
+		$commas = $this->numberOfCommas($count);
699
+
700
+		for($i = 1; $i <= $commas; $i++)
701
+		{
702
+			$index = (int) round($i * $count / ($commas + 1));
703
+
704
+			if($index < ($count - 1) && $index > 0)
705
+				$sentence[$index] .= ',';
706
+		}
707
+
708
+		// Add smileys to the end of the sentence :D
709
+		$n = 3;
710
+		while ($n >= rand(1, 15))
711
+		{
712
+			$n--;
713
+			$sentence[$count - 1] .= ' ' . $this->smileys[rand(0, count($this->smileys)-1)];
714
+		}
715
+	}
716
+
717
+	/*
718
+	* Determines the number of commas for a
719
+	* sentence of the given length. Average and
720
+	* standard deviation are determined superficially
721
+	*/
722
+	function numberOfCommas($len)
723
+	{
724
+		$avg = (float) log($len, 6);
725
+		$stdDev = (float) $avg / 6.000;
726
+
727
+		return (int) round($this->gauss_ms($avg, $stdDev));
728
+	}
729
+
730
+	/*
731
+	* Returns a number on a gaussian distribution
732
+	* based on the average word length of an english
733
+	* sentence.
734
+	* Statistics Source:
735
+	*	http://hearle.nahoo.net/Academic/Maths/Sentence.html
736
+	*	Average: 24.46
737
+	*	Standard Deviation: 5.08
738
+	*/
739
+	function gaussianSentence()
740
+	{
741
+		$avg = (float) 24.460;
742
+		$stdDev = (float) 5.080;
743
+
744
+		return (int) round($this->gauss_ms($avg, $stdDev));
745
+	}
746
+
747
+	/*
748
+	* The following three functions are used to
749
+	* compute numbers with a guassian distrobution
750
+	* Source:
751
+	* 	http://us.php.net/manual/en/function.rand.php#53784
752
+	*/
753
+	function gauss()
754
+	{   // N(0,1)
755
+		// returns random number with normal distribution:
756
+		//   mean=0
757
+		//   std dev=1
758
+
759
+		// auxilary vars
760
+		$x=$this->random_0_1();
761
+		$y=$this->random_0_1();
762
+
763
+		// two independent variables with normal distribution N(0,1)
764
+		$u=sqrt(-2*log($x))*cos(2*pi()*$y);
765
+		$v=sqrt(-2*log($x))*sin(2*pi()*$y);
766
+
767
+		// i will return only one, couse only one needed
768
+		return $u;
769
+	}
770
+
771
+	function gauss_ms($m=0.0,$s=1.0)
772
+	{
773
+		return $this->gauss()*$s+$m;
774
+	}
775
+
776
+	function random_0_1()
777
+	{
778
+		return (float)rand()/(float)getrandmax();
779
+	}
780
+
781
+}
782
+?>
0 783
\ No newline at end of file
... ...
@@ -0,0 +1,75 @@
1
+<?php
2
+###########################################################
3
+#       Simple Desk Project - www.simpledesk.net          #
4
+###########################################################
5
+#     An advanced help desk modifcation built on SMF      #
6
+###########################################################
7
+#                                                         #
8
+#       * Copyright 2010 - SimpleDesk.net                 #
9
+#                                                         #
10
+# This file and its contents are subject to the license   #
11
+# included with this distribution, license.txt, which     #
12
+# states that this software is New BSD Licensed.          #
13
+# Any questions, please contact SimpleDesk.net            #
14
+#                                                         #
15
+###########################################################
16
+# SimpleDesk Version: 1.0 Felidae                         #
17
+# File Info: index.php / 1.0 Felidae                      #
18
+###########################################################
19
+
20
+/**
21
+ *	@package plugin-installtestdata
22
+ *	@since 1.1
23
+*/
24
+
25
+if (!defined('SHD_VERSION'))
26
+	die('Hacking attempt...');
27
+
28
+/*
29
+ *	Return information about this plugin.
30
+ *
31
+ *	details
32
+ *	- name: a $txt reference for the plugin's name (so it can be translated), if not present as a $txt will be used as a literal. (Note, see includes - language below)
33
+ *	- description: a $txt reference one line description of the mod (translatable) - if not present, it will be used as a literal.
34
+ *	- author: Author's name, literal
35
+ *	- website: Website to link back to the author
36
+ *	- version: Plugin version
37
+ *	- compatibility: Array of supported SD version-strings
38
+ *	
39
+ *	includes
40
+ *	- source: a key-value pair array of file names to include at strategic points, key name is the point to include it on, value is a filename or array of filenames to include within the plugin's dir
41
+ *	- language: a key-value pair of array of language files to include, much like source.
42
+ *
43
+ *	hooks
44
+ *	- key-value pair of hook name to function name or array of function names to be called at the hook point
45
+ *
46
+ *	@since 1.1
47
+*/
48
+function shdplugin_install_testdata()
49
+{
50
+	return array(
51
+		'details' => array( // general plugin details
52
+			'title' => 'shdp_install_testdata',
53
+			'description' => 'shdp_install_testdata_desc',
54
+			'author' => 'SimpleDesk Team',
55
+			'website' => 'http://www.simpledesk.net/',
56
+			'version' => '1.0',
57
+			'compatibility' => array(
58
+				'SimpleDesk 1.0 Felidae', // should tie up with the SHD_VERSION constants
59
+			),
60
+			'acp_url' => $GLOBALS['boardurl'] . '/install-testdata.php',
61
+		),
62
+		'includes' => array(
63
+			'source' => array(
64
+			),
65
+			'language' => array(
66
+				'hdadmin' => 'SDPluginInstallTestdata',
67
+			),
68
+		),
69
+		'hooks' => array( // what functions to call when
70
+		),
71
+	);
72
+}
73
+
74
+
75
+?>
0 76
\ No newline at end of file
... ...
@@ -0,0 +1,27 @@
1
+<?xml version="1.0"?>
2
+<!DOCTYPE package-info SYSTEM "http://www.simplemachines.org/xml/package-info">
3
+<package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
4
+	<id>SimpleDeskTeam:installtestdata</id>
5
+	<name>SimpleDesk: Install Test-Data</name>
6
+	<version>1.0</version>
7
+	<type>modification</type>
8
+	<install for="2.0 RC5">
9
+		<require-dir name="install_testdata" destination="$sourcedir/sd_plugins_source" />
10
+		<require-file name="install-testdata.php" destination="$boarddir" />
11
+		<require-file name="SDPluginInstallTestdata.english.php" destination="$languagedir" />
12
+		<require-file name="SDPluginInstallTestdata.english-utf8.php" destination="$languagedir" />
13
+		<require-file name="SDPluginInstallTestdata.english_british.php" destination="$languagedir" />
14
+		<require-file name="SDPluginInstallTestdata.english_british-utf8.php" destination="$languagedir" />
15
+		
16
+		<redirect url="?action=admin;area=helpdesk_plugins#js_feature_install_testdata" />
17
+	</install>
18
+
19
+	<uninstall for="2.0 RC5">
20
+		<remove-dir name="$sourcedir/sd_plugins_source/install_testdata" />
21
+		<remove-file name="$boarddir/install-testdata.php" />
22
+		<remove-file name="$languagedir/SDPluginInstallTestdata.english.php" />
23
+		<remove-file name="$languagedir/SDPluginInstallTestdata.english-utf8.php" />
24
+		<remove-file name="$languagedir/SDPluginInstallTestdata.english_british.php" />
25
+		<remove-file name="$languagedir/SDPluginInstallTestdata.english_british-utf8.php" />
26
+	</uninstall>
27
+</package-info>
0 28
\ No newline at end of file
1 29