1 | <?php |
||
16 | class FooGallery_LoremIpsum |
||
|
|||
17 | { |
||
18 | /** |
||
19 | * First |
||
20 | * |
||
21 | * Whether or not we should be starting the string with "Lorem ipsum..." |
||
22 | * |
||
23 | * @access private |
||
24 | * @var boolean |
||
25 | */ |
||
26 | private $first = true; |
||
27 | |||
28 | /** |
||
29 | * Words |
||
30 | * |
||
31 | * A lorem ipsum vocabulary of sorts. Not a complete list as I'm unsure if |
||
32 | * a complete list exists and if so, where to get it. |
||
33 | * |
||
34 | * @access private |
||
35 | * @var array |
||
36 | */ |
||
37 | public $words = array( |
||
38 | // Lorem ipsum... |
||
39 | 'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', |
||
40 | |||
41 | // and the rest of the vocabulary |
||
42 | 'a', 'ac', 'accumsan', 'ad', 'aenean', 'aliquam', 'aliquet', 'ante', |
||
43 | 'aptent', 'arcu', 'at', 'auctor', 'augue', 'bibendum', 'blandit', |
||
44 | 'class', 'commodo', 'condimentum', 'congue', 'consequat', 'conubia', |
||
45 | 'convallis', 'cras', 'cubilia', 'curabitur', 'curae', 'cursus', |
||
46 | 'dapibus', 'diam', 'dictum', 'dictumst', 'dignissim', 'dis', 'donec', |
||
47 | 'dui', 'duis', 'efficitur', 'egestas', 'eget', 'eleifend', 'elementum', |
||
48 | 'enim', 'erat', 'eros', 'est', 'et', 'etiam', 'eu', 'euismod', 'ex', |
||
49 | 'facilisi', 'facilisis', 'fames', 'faucibus', 'felis', 'fermentum', |
||
50 | 'feugiat', 'finibus', 'fringilla', 'fusce', 'gravida', 'habitant', |
||
51 | 'habitasse', 'hac', 'hendrerit', 'himenaeos', 'iaculis', 'id', |
||
52 | 'imperdiet', 'in', 'inceptos', 'integer', 'interdum', 'justo', |
||
53 | 'lacinia', 'lacus', 'laoreet', 'lectus', 'leo', 'libero', 'ligula', |
||
54 | 'litora', 'lobortis', 'luctus', 'maecenas', 'magna', 'magnis', |
||
55 | 'malesuada', 'massa', 'mattis', 'mauris', 'maximus', 'metus', 'mi', |
||
56 | 'molestie', 'mollis', 'montes', 'morbi', 'mus', 'nam', 'nascetur', |
||
57 | 'natoque', 'nec', 'neque', 'netus', 'nibh', 'nisi', 'nisl', 'non', |
||
58 | 'nostra', 'nulla', 'nullam', 'nunc', 'odio', 'orci', 'ornare', |
||
59 | 'parturient', 'pellentesque', 'penatibus', 'per', 'pharetra', |
||
60 | 'phasellus', 'placerat', 'platea', 'porta', 'porttitor', 'posuere', |
||
61 | 'potenti', 'praesent', 'pretium', 'primis', 'proin', 'pulvinar', |
||
62 | 'purus', 'quam', 'quis', 'quisque', 'rhoncus', 'ridiculus', 'risus', |
||
63 | 'rutrum', 'sagittis', 'sapien', 'scelerisque', 'sed', 'sem', 'semper', |
||
64 | 'senectus', 'sociosqu', 'sodales', 'sollicitudin', 'suscipit', |
||
65 | 'suspendisse', 'taciti', 'tellus', 'tempor', 'tempus', 'tincidunt', |
||
66 | 'torquent', 'tortor', 'tristique', 'turpis', 'ullamcorper', 'ultrices', |
||
67 | 'ultricies', 'urna', 'ut', 'varius', 'vehicula', 'vel', 'velit', |
||
68 | 'venenatis', 'vestibulum', 'vitae', 'vivamus', 'viverra', 'volutpat', |
||
69 | 'vulputate', |
||
70 | ); |
||
71 | |||
72 | /** |
||
73 | * Word |
||
74 | * |
||
75 | * Generates a single word of lorem ipsum. |
||
76 | * |
||
77 | * @access public |
||
78 | * @param mixed $tags string or array of HTML tags to wrap output with |
||
79 | * @return string generated lorem ipsum word |
||
80 | */ |
||
81 | public function word($tags = false) |
||
85 | |||
86 | /** |
||
87 | * Words Array |
||
88 | * |
||
89 | * Generates an array of lorem ipsum words. |
||
90 | * |
||
91 | * @access public |
||
92 | * @param integer $count how many words to generate |
||
93 | * @param mixed $tags string or array of HTML tags to wrap output with |
||
94 | * @return array generated lorem ipsum words |
||
95 | */ |
||
96 | public function wordsArray($count = 1, $tags = false) |
||
100 | |||
101 | /** |
||
102 | * Words |
||
103 | * |
||
104 | * Generates words of lorem ipsum. |
||
105 | * |
||
106 | * @access public |
||
107 | * @param integer $count how many words to generate |
||
108 | * @param mixed $tags string or array of HTML tags to wrap output with |
||
109 | * @param boolean $array whether an array or a string should be returned |
||
110 | * @return mixed string or array of generated lorem ipsum words |
||
111 | */ |
||
112 | public function words($count = 1, $tags = false, $array = false) |
||
139 | |||
140 | /** |
||
141 | * Sentence |
||
142 | * |
||
143 | * Generates a full sentence of lorem ipsum. |
||
144 | * |
||
145 | * @access public |
||
146 | * @param mixed $tags string or array of HTML tags to wrap output with |
||
147 | * @return string generated lorem ipsum sentence |
||
148 | */ |
||
149 | public function sentence($tags = false) |
||
153 | |||
154 | /** |
||
155 | * Sentences Array |
||
156 | * |
||
157 | * Generates an array of lorem ipsum sentences. |
||
158 | * |
||
159 | * @access public |
||
160 | * @param integer $count how many sentences to generate |
||
161 | * @param mixed $tags string or array of HTML tags to wrap output with |
||
162 | * @return array generated lorem ipsum sentences |
||
163 | */ |
||
164 | public function sentencesArray($count = 1, $tags = false) |
||
168 | |||
169 | /** |
||
170 | * Sentences |
||
171 | * |
||
172 | * Generates sentences of lorem ipsum. |
||
173 | * |
||
174 | * @access public |
||
175 | * @param integer $count how many sentences to generate |
||
176 | * @param mixed $tags string or array of HTML tags to wrap output with |
||
177 | * @param boolean $array whether an array or a string should be returned |
||
178 | * @return mixed string or array of generated lorem ipsum sentences |
||
179 | */ |
||
180 | public function sentences($count = 1, $tags = false, $array = false) |
||
192 | |||
193 | /** |
||
194 | * Paragraph |
||
195 | * |
||
196 | * Generates a full paragraph of lorem ipsum. |
||
197 | * |
||
198 | * @access public |
||
199 | * @param mixed $tags string or array of HTML tags to wrap output with |
||
200 | * @return string generated lorem ipsum paragraph |
||
201 | */ |
||
202 | public function paragraph($tags = false) |
||
206 | |||
207 | /** |
||
208 | * Paragraph Array |
||
209 | * |
||
210 | * Generates an array of lorem ipsum paragraphs. |
||
211 | * |
||
212 | * @access public |
||
213 | * @param integer $count how many paragraphs to generate |
||
214 | * @param mixed $tags string or array of HTML tags to wrap output with |
||
215 | * @return array generated lorem ipsum paragraphs |
||
216 | */ |
||
217 | public function paragraphsArray($count = 1, $tags = false) |
||
221 | |||
222 | /** |
||
223 | * Paragraphss |
||
224 | * |
||
225 | * Generates paragraphs of lorem ipsum. |
||
226 | * |
||
227 | * @access public |
||
228 | * @param integer $count how many paragraphs to generate |
||
229 | * @param mixed $tags string or array of HTML tags to wrap output with |
||
230 | * @param boolean $array whether an array or a string should be returned |
||
231 | * @return mixed string or array of generated lorem ipsum paragraphs |
||
232 | */ |
||
233 | public function paragraphs($count = 1, $tags = false, $array = false) |
||
243 | |||
244 | /** |
||
245 | * Gaussian Distribution |
||
246 | * |
||
247 | * This is some smart kid stuff. I went ahead and combined the N(0,1) logic |
||
248 | * with the N(m,s) logic into this single function. Used to calculate the |
||
249 | * number of words in a sentence, the number of sentences in a paragraph |
||
250 | * and the distribution of commas in a sentence. |
||
251 | * |
||
252 | * @access private |
||
253 | * @param double $mean average value |
||
254 | * @param double $std_dev stadnard deviation |
||
255 | * @return double calculated distribution |
||
256 | */ |
||
257 | private function gauss($mean, $std_dev) |
||
265 | |||
266 | /** |
||
267 | * Shuffle |
||
268 | * |
||
269 | * Shuffles the words, forcing "Lorem ipsum..." at the beginning if it is |
||
270 | * the first time we are generating the text. |
||
271 | * |
||
272 | * @access private |
||
273 | */ |
||
274 | private function shuffle() |
||
289 | |||
290 | /** |
||
291 | * Punctuate |
||
292 | * |
||
293 | * Applies punctuation to a sentence. This includes a period at the end, |
||
294 | * the injection of commas as well as capitalizing the first letter of the |
||
295 | * first word of the sentence. |
||
296 | * |
||
297 | * @access private |
||
298 | * @param array $sentences the sentences we would like to punctuate |
||
299 | */ |
||
300 | private function punctuate(&$sentences) |
||
323 | |||
324 | /** |
||
325 | * Output |
||
326 | * |
||
327 | * Does the rest of the processing of the strings. This includes wrapping |
||
328 | * the strings in HTML tags, handling transformations with the ability of |
||
329 | * back referencing and determining if the passed array should be converted |
||
330 | * into a string or not. |
||
331 | * |
||
332 | * @access private |
||
333 | * @param array $strings an array of generated strings |
||
334 | * @param mixed $tags string or array of HTML tags to wrap output with |
||
335 | * @param boolean $array whether an array or a string should be returned |
||
336 | * @param string $delimiter the string to use when calling implode() |
||
337 | * @return mixed string or array of generated lorem ipsum text |
||
338 | */ |
||
339 | private function output($strings, $tags, $array, $delimiter = ' ') |
||
369 | } |
||
370 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.