-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.tmp_LoremIpsum.php.79410~
executable file
·174 lines (152 loc) · 4.16 KB
/
.tmp_LoremIpsum.php.79410~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
/* SVN FILE: $Id: LoremIpsum.php 239 2009-10-18 22:29:37Z david@ramaboo.com $ */
/**
* @brief Lorem ipsum class.
*
* This class is used to generate lorem ipsum.
*
* @class Boo_LoremIpsum
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU General Public License
* @link http://code.ramaboo.com/ Boo Framework
* @copyright 2009 David Singer
* @author David Singer <david@ramaboo.com>
* @version 2.0.1
*/
class Boo_LoremIpsum {
/**
* @brief Array of paragraphs.
*/
protected static $ps = array();
/**
* @brief Array of list items.
*/
protected static $lis = array();
/**
* @brief Array of words.
*/
protected static $words = array();
/**
* @brief Default constructor.
* @param bool $preload Preload ipsum files.
* @return void.
*/
public function __construct($preload = false) {
if ($preload) {
self::loadFiles();
}
}
/**
* @brief Returns a string of words.
* @return string The string of words. Will always end in a period.
* @param int $count[optional] The number of words.
*/
public static function getWords($count = 20) {
$count = (int) $count;
if (empty(self::$words)) {
self::loadFiles();
}
$wordSize = count(self::$words);
if (!Boo_Validator::isInt($count, 1, $wordSize)) {
trigger_error("Count {$count} is not valid", E_USER_WARNING);
return false;
}
$string = '';
for ($i = 0; $i < $count; $i++) {
$string .= self::$words[$i] . ' ';
}
// remove ending characters
$string = rtrim($string, ' .,');
$string .= '.'; // add period
return $string;
}
/**
* @brief Returns an array of paragraphs of lorem ipsum.
* @return Boo_Html A collection of paragraphs.
* @param int $count[optional] The number of paragraphs.
* @param array $attrs[optional] The attributes to apply to each paragraph.
*/
public static function htmlPs($count = 5, array $attrs = array()) {
$count = (int) $count;
if (empty(self::$ps)) {
self::loadFiles();
}
$pSize = count(self::$ps);
if (!Boo_Validator::isInt($count, 1, $pSize)) {
trigger_error("Count {$count} is not valid", E_USER_WARNING);
return false;
}
$html = new Boo_Html(false);
for ($i = 0; $i < $count; $i++) {
$tmpP = new Boo_Html_P;
$tmpP->applyAttrs($attrs);
$tmpP->setContent(self::$ps[$i]);
$html->appendContent($tmpP);
}
return $html;
}
/**
* @brief Gets an unorderd list of lorem ipsum.
* @return Boo_Html_Ul The unordered list.
* @param int $count[optional] The number of list items to include.
* @param array $attrs[optional] The attributes for the unorderd list.
*/
public static function htmlUl($count = 5, array $attrs = array()) {
$count = (int) $count;
if (empty(self::$lis)) {
self::loadFiles();
}
$liSize = count(self::$lis);
if (!Boo_Validator::isInt($count, 1, $liSize)) {
trigger_error("Count {$count} is not valid", E_USER_WARNING);
return false;
}
$ul = new Boo_Html_Ul;
$ul->applyAttrs($attrs);
for ($i = 0; $i < $count; $i++) {
$tmpLi = new Boo_Html_Li;
$tmpLi->setContent(self::$lis[$i]);
$ul->addLi($tmpLi);
}
return $ul;
}
/**
* @brief Loads files into class.
* @return bool Returns TRUE on success, FALSE otherwise.
*/
private static function loadFiles() {
// load paragraphs
$pFile = BOO_LIB_DIR . '/LoremIpsum/ps';
if (file_exists($pFile)) {
$tmp = file($pFile);
// removes line breaks at the end of each line
array_trim($tmp);
self::$ps = $tmp;
} else {
trigger_error("File {$pFile} does not exist", E_USER_ERROR);
return false;
}
// load list items
$liFile = BOO_LIB_DIR . '/LoremIpsum/lis';
if (file_exists($liFile)) {
$tmp = file($liFile);
// removes line breaks at the end of each line
array_trim($tmp);
self::$lis = $tmp;
} else {
trigger_error("File {$liFile} does not exist", E_USER_ERROR);
return false;
}
// load words
$wordFile = BOO_LIB_DIR . '/LoremIpsum/words';
if (file_exists($wordFile)) {
$tmp = file($wordFile);
// removes line breaks at the end of each line
array_trim($tmp);
self::$words = $tmp;
} else {
trigger_error("File {$wordFile} does not exist", E_USER_ERROR);
return false;
}
return true;
}
}