@@ -38,228 +38,228 @@ discard block |
||
38 | 38 | */ |
39 | 39 | abstract class BaseUIKit { |
40 | 40 | |
41 | - /** |
|
42 | - * Bucket for methods to control their current state between method calls. |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected $states = []; |
|
46 | - |
|
47 | - protected $name = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * Attached to nav items that are considered active. |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $active_class = 'active'; |
|
54 | - |
|
55 | - //-------------------------------------------------------------------- |
|
56 | - |
|
57 | - public function name() |
|
58 | - { |
|
59 | - return $this->name; |
|
60 | - } |
|
61 | - |
|
62 | - //-------------------------------------------------------------------- |
|
63 | - |
|
64 | - //-------------------------------------------------------------------- |
|
65 | - // Grids |
|
66 | - //-------------------------------------------------------------------- |
|
67 | - |
|
68 | - /** |
|
69 | - * Creates a row wrapper of HTML. We would have simple returned the |
|
70 | - * the class for it, but some frameworks use a completely different |
|
71 | - * approach to rows and columns than the reference Bootstrap and Foundation. |
|
72 | - * |
|
73 | - * @param array $options |
|
74 | - * @return mixed |
|
75 | - */ |
|
76 | - abstract public function row($options=[], \Closure $c); |
|
77 | - |
|
78 | - //-------------------------------------------------------------------- |
|
79 | - |
|
80 | - /** |
|
81 | - * Creates the CSS for a column in a grid. |
|
82 | - * |
|
83 | - * The attribute array is made up of key/value pairs with the |
|
84 | - * key being the size, and the value being the number of columns/offset |
|
85 | - * in a 12-column grid. |
|
86 | - * |
|
87 | - * Note that we currently DO NOT support offset columns. |
|
88 | - * |
|
89 | - * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
90 | - * |
|
91 | - * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
92 | - * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
93 | - * |
|
94 | - * @param array $attributes |
|
95 | - * @return mixed |
|
96 | - */ |
|
97 | - abstract public function column($options=[], \Closure $c); |
|
98 | - |
|
99 | - //-------------------------------------------------------------------- |
|
100 | - |
|
101 | - //-------------------------------------------------------------------- |
|
102 | - // Navigation |
|
103 | - //-------------------------------------------------------------------- |
|
104 | - |
|
105 | - /** |
|
106 | - * Generates the container code for a navbar, typically used along the |
|
107 | - * top of a page. |
|
108 | - * |
|
109 | - * @param array $options |
|
110 | - * @param callable $c |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - abstract public function navbar($options=[], \Closure $c); |
|
114 | - |
|
115 | - //-------------------------------------------------------------------- |
|
116 | - |
|
117 | - /** |
|
118 | - * Builds the HTML for the Title portion of the navbar. This typically |
|
119 | - * includes the code for the hamburger menu on small resolutions. |
|
120 | - * |
|
121 | - * @param $title |
|
122 | - * @param string $url |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - abstract public function navbarTitle($title, $url='#'); |
|
126 | - |
|
127 | - //-------------------------------------------------------------------- |
|
128 | - |
|
129 | - /** |
|
130 | - * Creates a UL meant to pull to the right within the navbar. |
|
131 | - * |
|
132 | - * Available options: |
|
133 | - * 'class' - An additional class to add |
|
134 | - * |
|
135 | - * @param array $options |
|
136 | - * @param callable $c |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - abstract public function navbarRight($options=[], \Closure $c); |
|
140 | - |
|
141 | - //-------------------------------------------------------------------- |
|
142 | - |
|
143 | - /** |
|
144 | - * Creates a single list item for use within a nav section. |
|
145 | - * |
|
146 | - * @param $title |
|
147 | - * @param $url |
|
148 | - * @param array $options |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - abstract public function navItem($title, $url, $options=[], $isActive=false); |
|
152 | - |
|
153 | - //-------------------------------------------------------------------- |
|
154 | - |
|
155 | - /** |
|
156 | - * Builds the shell of a Dropdown button for use within a nav area. |
|
157 | - * |
|
158 | - * @param $title |
|
159 | - * @param array $options |
|
160 | - * @param callable $c |
|
161 | - */ |
|
162 | - abstract public function navDropdown($title,$options=[], \Closure $c); |
|
163 | - |
|
164 | - //-------------------------------------------------------------------- |
|
165 | - |
|
166 | - /** |
|
167 | - * Creates a divider for use within a nav list. |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - abstract public function navDivider(); |
|
172 | - |
|
173 | - //-------------------------------------------------------------------- |
|
174 | - |
|
175 | - /** |
|
176 | - * Creates a list of nav items to function as breadcrumbs for a site. |
|
177 | - * |
|
178 | - * @param array $options |
|
179 | - * @param callable $c |
|
180 | - * @return mixed |
|
181 | - */ |
|
182 | - abstract public function breadcrumb($options=[], \Closure $c); |
|
183 | - |
|
184 | - //-------------------------------------------------------------------- |
|
185 | - |
|
186 | - //-------------------------------------------------------------------- |
|
187 | - // Buttons |
|
188 | - //-------------------------------------------------------------------- |
|
189 | - |
|
190 | - /** |
|
191 | - * Creates a simple button. |
|
192 | - * |
|
193 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
194 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
195 | - * |
|
196 | - * @param $title |
|
197 | - * @param string $style |
|
198 | - * @param array $options |
|
199 | - * @return mixed |
|
200 | - */ |
|
201 | - abstract public function button($title, $style='default', $size='default', $options=[]); |
|
202 | - |
|
203 | - /** |
|
204 | - * Creates a simple link styled as a button. |
|
205 | - * |
|
206 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
207 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
208 | - * |
|
209 | - * @param $title |
|
210 | - * @param string $url |
|
211 | - * @param string $style |
|
212 | - * @param array $options |
|
213 | - * @return mixed |
|
214 | - */ |
|
215 | - abstract public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]); |
|
216 | - |
|
217 | - /** |
|
218 | - * Creates button groups wrapping HTML. |
|
219 | - * |
|
220 | - * @param $options |
|
221 | - * @param callable $c |
|
222 | - * @return mixed |
|
223 | - */ |
|
224 | - abstract public function buttonGroup($options, \Closure $c); |
|
225 | - |
|
226 | - /** |
|
227 | - * Creates the button bar wrapping HTML. |
|
228 | - * |
|
229 | - * @param $options |
|
230 | - * @param callable $c |
|
231 | - * @return mixed |
|
232 | - */ |
|
233 | - abstract public function buttonBar($options, \Closure $c); |
|
234 | - |
|
235 | - /** |
|
236 | - * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
237 | - * by some frameworks. |
|
238 | - * |
|
239 | - * @param $title |
|
240 | - * @param string $style |
|
241 | - * @param string $size |
|
242 | - * @param array $options |
|
243 | - * @param callable $c |
|
244 | - * @return mixed |
|
245 | - */ |
|
246 | - abstract public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c); |
|
247 | - |
|
248 | - //-------------------------------------------------------------------- |
|
249 | - // Notices |
|
250 | - //-------------------------------------------------------------------- |
|
251 | - |
|
252 | - /** |
|
253 | - * Creates an 'alert-box' style of notice grid. |
|
254 | - * |
|
255 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
256 | - * |
|
257 | - * @param $content |
|
258 | - * @param string $style |
|
259 | - * @param bool $closable |
|
260 | - * @return mixed |
|
261 | - */ |
|
262 | - abstract public function notice($content, $style='success', $closable=true); |
|
41 | + /** |
|
42 | + * Bucket for methods to control their current state between method calls. |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected $states = []; |
|
46 | + |
|
47 | + protected $name = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * Attached to nav items that are considered active. |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $active_class = 'active'; |
|
54 | + |
|
55 | + //-------------------------------------------------------------------- |
|
56 | + |
|
57 | + public function name() |
|
58 | + { |
|
59 | + return $this->name; |
|
60 | + } |
|
61 | + |
|
62 | + //-------------------------------------------------------------------- |
|
63 | + |
|
64 | + //-------------------------------------------------------------------- |
|
65 | + // Grids |
|
66 | + //-------------------------------------------------------------------- |
|
67 | + |
|
68 | + /** |
|
69 | + * Creates a row wrapper of HTML. We would have simple returned the |
|
70 | + * the class for it, but some frameworks use a completely different |
|
71 | + * approach to rows and columns than the reference Bootstrap and Foundation. |
|
72 | + * |
|
73 | + * @param array $options |
|
74 | + * @return mixed |
|
75 | + */ |
|
76 | + abstract public function row($options=[], \Closure $c); |
|
77 | + |
|
78 | + //-------------------------------------------------------------------- |
|
79 | + |
|
80 | + /** |
|
81 | + * Creates the CSS for a column in a grid. |
|
82 | + * |
|
83 | + * The attribute array is made up of key/value pairs with the |
|
84 | + * key being the size, and the value being the number of columns/offset |
|
85 | + * in a 12-column grid. |
|
86 | + * |
|
87 | + * Note that we currently DO NOT support offset columns. |
|
88 | + * |
|
89 | + * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
90 | + * |
|
91 | + * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
92 | + * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
93 | + * |
|
94 | + * @param array $attributes |
|
95 | + * @return mixed |
|
96 | + */ |
|
97 | + abstract public function column($options=[], \Closure $c); |
|
98 | + |
|
99 | + //-------------------------------------------------------------------- |
|
100 | + |
|
101 | + //-------------------------------------------------------------------- |
|
102 | + // Navigation |
|
103 | + //-------------------------------------------------------------------- |
|
104 | + |
|
105 | + /** |
|
106 | + * Generates the container code for a navbar, typically used along the |
|
107 | + * top of a page. |
|
108 | + * |
|
109 | + * @param array $options |
|
110 | + * @param callable $c |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + abstract public function navbar($options=[], \Closure $c); |
|
114 | + |
|
115 | + //-------------------------------------------------------------------- |
|
116 | + |
|
117 | + /** |
|
118 | + * Builds the HTML for the Title portion of the navbar. This typically |
|
119 | + * includes the code for the hamburger menu on small resolutions. |
|
120 | + * |
|
121 | + * @param $title |
|
122 | + * @param string $url |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + abstract public function navbarTitle($title, $url='#'); |
|
126 | + |
|
127 | + //-------------------------------------------------------------------- |
|
128 | + |
|
129 | + /** |
|
130 | + * Creates a UL meant to pull to the right within the navbar. |
|
131 | + * |
|
132 | + * Available options: |
|
133 | + * 'class' - An additional class to add |
|
134 | + * |
|
135 | + * @param array $options |
|
136 | + * @param callable $c |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + abstract public function navbarRight($options=[], \Closure $c); |
|
140 | + |
|
141 | + //-------------------------------------------------------------------- |
|
142 | + |
|
143 | + /** |
|
144 | + * Creates a single list item for use within a nav section. |
|
145 | + * |
|
146 | + * @param $title |
|
147 | + * @param $url |
|
148 | + * @param array $options |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + abstract public function navItem($title, $url, $options=[], $isActive=false); |
|
152 | + |
|
153 | + //-------------------------------------------------------------------- |
|
154 | + |
|
155 | + /** |
|
156 | + * Builds the shell of a Dropdown button for use within a nav area. |
|
157 | + * |
|
158 | + * @param $title |
|
159 | + * @param array $options |
|
160 | + * @param callable $c |
|
161 | + */ |
|
162 | + abstract public function navDropdown($title,$options=[], \Closure $c); |
|
163 | + |
|
164 | + //-------------------------------------------------------------------- |
|
165 | + |
|
166 | + /** |
|
167 | + * Creates a divider for use within a nav list. |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + abstract public function navDivider(); |
|
172 | + |
|
173 | + //-------------------------------------------------------------------- |
|
174 | + |
|
175 | + /** |
|
176 | + * Creates a list of nav items to function as breadcrumbs for a site. |
|
177 | + * |
|
178 | + * @param array $options |
|
179 | + * @param callable $c |
|
180 | + * @return mixed |
|
181 | + */ |
|
182 | + abstract public function breadcrumb($options=[], \Closure $c); |
|
183 | + |
|
184 | + //-------------------------------------------------------------------- |
|
185 | + |
|
186 | + //-------------------------------------------------------------------- |
|
187 | + // Buttons |
|
188 | + //-------------------------------------------------------------------- |
|
189 | + |
|
190 | + /** |
|
191 | + * Creates a simple button. |
|
192 | + * |
|
193 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
194 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
195 | + * |
|
196 | + * @param $title |
|
197 | + * @param string $style |
|
198 | + * @param array $options |
|
199 | + * @return mixed |
|
200 | + */ |
|
201 | + abstract public function button($title, $style='default', $size='default', $options=[]); |
|
202 | + |
|
203 | + /** |
|
204 | + * Creates a simple link styled as a button. |
|
205 | + * |
|
206 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
207 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
208 | + * |
|
209 | + * @param $title |
|
210 | + * @param string $url |
|
211 | + * @param string $style |
|
212 | + * @param array $options |
|
213 | + * @return mixed |
|
214 | + */ |
|
215 | + abstract public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]); |
|
216 | + |
|
217 | + /** |
|
218 | + * Creates button groups wrapping HTML. |
|
219 | + * |
|
220 | + * @param $options |
|
221 | + * @param callable $c |
|
222 | + * @return mixed |
|
223 | + */ |
|
224 | + abstract public function buttonGroup($options, \Closure $c); |
|
225 | + |
|
226 | + /** |
|
227 | + * Creates the button bar wrapping HTML. |
|
228 | + * |
|
229 | + * @param $options |
|
230 | + * @param callable $c |
|
231 | + * @return mixed |
|
232 | + */ |
|
233 | + abstract public function buttonBar($options, \Closure $c); |
|
234 | + |
|
235 | + /** |
|
236 | + * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
237 | + * by some frameworks. |
|
238 | + * |
|
239 | + * @param $title |
|
240 | + * @param string $style |
|
241 | + * @param string $size |
|
242 | + * @param array $options |
|
243 | + * @param callable $c |
|
244 | + * @return mixed |
|
245 | + */ |
|
246 | + abstract public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c); |
|
247 | + |
|
248 | + //-------------------------------------------------------------------- |
|
249 | + // Notices |
|
250 | + //-------------------------------------------------------------------- |
|
251 | + |
|
252 | + /** |
|
253 | + * Creates an 'alert-box' style of notice grid. |
|
254 | + * |
|
255 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
256 | + * |
|
257 | + * @param $content |
|
258 | + * @param string $style |
|
259 | + * @param bool $closable |
|
260 | + * @return mixed |
|
261 | + */ |
|
262 | + abstract public function notice($content, $style='success', $closable=true); |
|
263 | 263 | |
264 | 264 | //-------------------------------------------------------------------- |
265 | 265 | // Forms |
@@ -278,137 +278,137 @@ discard block |
||
278 | 278 | */ |
279 | 279 | abstract public function inputWrap($label_text, $options=[], \Closure $c); |
280 | 280 | |
281 | - //-------------------------------------------------------------------- |
|
282 | - // Utility Methods |
|
283 | - //-------------------------------------------------------------------- |
|
284 | - |
|
285 | - /** |
|
286 | - * Helper method to run a Closure and collect the output of it. |
|
287 | - * |
|
288 | - * @param callable $c |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - protected function runClosure(\Closure $c) |
|
292 | - { |
|
293 | - if (! is_callable($c)) return ''; |
|
294 | - |
|
295 | - ob_start(); |
|
296 | - $c(); |
|
297 | - $output = ob_get_contents(); |
|
298 | - ob_end_clean(); |
|
299 | - |
|
300 | - return $output; |
|
301 | - } |
|
302 | - |
|
303 | - //-------------------------------------------------------------------- |
|
304 | - |
|
305 | - /** |
|
306 | - * Provides a single method call to get the $classes, $id, and $attributes |
|
307 | - * from the options array. |
|
308 | - * |
|
309 | - * @param $options |
|
310 | - * @param string $initial_classes |
|
311 | - * @param bool $fullClassString |
|
312 | - * @return array |
|
313 | - */ |
|
314 | - protected function parseStandardOptions($options, $initial_classes='', $fullClassString=false) |
|
315 | - { |
|
316 | - return [ |
|
317 | - $this->buildClassString($initial_classes, $options, $fullClassString), |
|
318 | - $this->buildIdFromOptions($options), |
|
319 | - $this->buildAttributesFromOptions($options) |
|
320 | - ]; |
|
321 | - } |
|
322 | - |
|
323 | - //-------------------------------------------------------------------- |
|
324 | - |
|
325 | - /** |
|
326 | - * Sets the element that is to be considered the active item. This is |
|
327 | - * based on the navItem's $title so it must match, though it is NOT |
|
328 | - * case sensitive. |
|
329 | - * |
|
330 | - * @param $title |
|
331 | - * @return mixed |
|
332 | - */ |
|
333 | - public function setActiveNavItem($title) |
|
334 | - { |
|
335 | - $this->states['activeNavItem'] = strtolower($title); |
|
336 | - } |
|
337 | - |
|
338 | - //-------------------------------------------------------------------- |
|
339 | - |
|
340 | - /** |
|
341 | - * Combines an initial classes string with a 'class' item that |
|
342 | - * might be available within the options array. |
|
343 | - * |
|
344 | - * If 'buildEntireString' is TRUE will return the string with the 'class=""' portion. |
|
345 | - * Otherwise, just returns the raw classes. |
|
346 | - * |
|
347 | - * @param string $initial |
|
348 | - * @param array $options |
|
349 | - * @return array |
|
350 | - */ |
|
351 | - protected function buildClassString($initial, $options, $buildEntireString=false) |
|
352 | - { |
|
353 | - $classes = explode(' ', $initial); |
|
354 | - |
|
355 | - if (isset($options['class'])) |
|
356 | - { |
|
357 | - $classes = array_merge($classes, explode(' ', $options['class'])); |
|
358 | - } |
|
359 | - |
|
360 | - if (isset($this->states['activeNavItem']) && isset($this->states['activeNavTitle']) && |
|
361 | - $this->states['activeNavItem'] == strtolower($this->states['activeNavTitle'])) |
|
362 | - { |
|
363 | - $classes[] = $this->active_class; |
|
364 | - } |
|
365 | - |
|
366 | - $classes = implode(' ', $classes); |
|
367 | - |
|
368 | - // Substitute the active class for a placeholder. |
|
369 | - $classes = str_replace('{active}', $this->active_class, $classes); |
|
370 | - |
|
371 | - return $buildEntireString ? "class='{$classes}'" : $classes; |
|
372 | - } |
|
373 | - //-------------------------------------------------------------------- |
|
374 | - |
|
375 | - /** |
|
376 | - * Checks the options array for an ID and returns the entire string. |
|
377 | - * |
|
378 | - * Example Return: |
|
379 | - * id='MyID' |
|
380 | - * |
|
381 | - * @param $options |
|
382 | - * @return string |
|
383 | - */ |
|
384 | - protected function buildIdFromOptions($options) |
|
385 | - { |
|
386 | - return isset($options['id']) ? "id='{$options['id']}'" : ' '; |
|
387 | - } |
|
388 | - |
|
389 | - //-------------------------------------------------------------------- |
|
390 | - |
|
391 | - /** |
|
392 | - * Parses out attributes from the options array. The attributes array |
|
393 | - * should all contain no key names, only values, so: |
|
394 | - * |
|
395 | - * 'attributes' => [ |
|
396 | - * 'style="width:100%", |
|
397 | - * 'required' |
|
398 | - * ] |
|
399 | - * |
|
400 | - * @param $options |
|
401 | - * @return string |
|
402 | - */ |
|
403 | - protected function buildAttributesFromOptions($options) |
|
404 | - { |
|
405 | - if (isset($options['attributes']) && ! is_array($options['attributes'])) |
|
406 | - { |
|
407 | - $options['attributes'] = [ $options['attributes'] ]; |
|
408 | - } |
|
409 | - |
|
410 | - return isset($options['attributes']) ? implode($options['attributes']) : ''; |
|
411 | - } |
|
412 | - |
|
413 | - //-------------------------------------------------------------------- |
|
281 | + //-------------------------------------------------------------------- |
|
282 | + // Utility Methods |
|
283 | + //-------------------------------------------------------------------- |
|
284 | + |
|
285 | + /** |
|
286 | + * Helper method to run a Closure and collect the output of it. |
|
287 | + * |
|
288 | + * @param callable $c |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + protected function runClosure(\Closure $c) |
|
292 | + { |
|
293 | + if (! is_callable($c)) return ''; |
|
294 | + |
|
295 | + ob_start(); |
|
296 | + $c(); |
|
297 | + $output = ob_get_contents(); |
|
298 | + ob_end_clean(); |
|
299 | + |
|
300 | + return $output; |
|
301 | + } |
|
302 | + |
|
303 | + //-------------------------------------------------------------------- |
|
304 | + |
|
305 | + /** |
|
306 | + * Provides a single method call to get the $classes, $id, and $attributes |
|
307 | + * from the options array. |
|
308 | + * |
|
309 | + * @param $options |
|
310 | + * @param string $initial_classes |
|
311 | + * @param bool $fullClassString |
|
312 | + * @return array |
|
313 | + */ |
|
314 | + protected function parseStandardOptions($options, $initial_classes='', $fullClassString=false) |
|
315 | + { |
|
316 | + return [ |
|
317 | + $this->buildClassString($initial_classes, $options, $fullClassString), |
|
318 | + $this->buildIdFromOptions($options), |
|
319 | + $this->buildAttributesFromOptions($options) |
|
320 | + ]; |
|
321 | + } |
|
322 | + |
|
323 | + //-------------------------------------------------------------------- |
|
324 | + |
|
325 | + /** |
|
326 | + * Sets the element that is to be considered the active item. This is |
|
327 | + * based on the navItem's $title so it must match, though it is NOT |
|
328 | + * case sensitive. |
|
329 | + * |
|
330 | + * @param $title |
|
331 | + * @return mixed |
|
332 | + */ |
|
333 | + public function setActiveNavItem($title) |
|
334 | + { |
|
335 | + $this->states['activeNavItem'] = strtolower($title); |
|
336 | + } |
|
337 | + |
|
338 | + //-------------------------------------------------------------------- |
|
339 | + |
|
340 | + /** |
|
341 | + * Combines an initial classes string with a 'class' item that |
|
342 | + * might be available within the options array. |
|
343 | + * |
|
344 | + * If 'buildEntireString' is TRUE will return the string with the 'class=""' portion. |
|
345 | + * Otherwise, just returns the raw classes. |
|
346 | + * |
|
347 | + * @param string $initial |
|
348 | + * @param array $options |
|
349 | + * @return array |
|
350 | + */ |
|
351 | + protected function buildClassString($initial, $options, $buildEntireString=false) |
|
352 | + { |
|
353 | + $classes = explode(' ', $initial); |
|
354 | + |
|
355 | + if (isset($options['class'])) |
|
356 | + { |
|
357 | + $classes = array_merge($classes, explode(' ', $options['class'])); |
|
358 | + } |
|
359 | + |
|
360 | + if (isset($this->states['activeNavItem']) && isset($this->states['activeNavTitle']) && |
|
361 | + $this->states['activeNavItem'] == strtolower($this->states['activeNavTitle'])) |
|
362 | + { |
|
363 | + $classes[] = $this->active_class; |
|
364 | + } |
|
365 | + |
|
366 | + $classes = implode(' ', $classes); |
|
367 | + |
|
368 | + // Substitute the active class for a placeholder. |
|
369 | + $classes = str_replace('{active}', $this->active_class, $classes); |
|
370 | + |
|
371 | + return $buildEntireString ? "class='{$classes}'" : $classes; |
|
372 | + } |
|
373 | + //-------------------------------------------------------------------- |
|
374 | + |
|
375 | + /** |
|
376 | + * Checks the options array for an ID and returns the entire string. |
|
377 | + * |
|
378 | + * Example Return: |
|
379 | + * id='MyID' |
|
380 | + * |
|
381 | + * @param $options |
|
382 | + * @return string |
|
383 | + */ |
|
384 | + protected function buildIdFromOptions($options) |
|
385 | + { |
|
386 | + return isset($options['id']) ? "id='{$options['id']}'" : ' '; |
|
387 | + } |
|
388 | + |
|
389 | + //-------------------------------------------------------------------- |
|
390 | + |
|
391 | + /** |
|
392 | + * Parses out attributes from the options array. The attributes array |
|
393 | + * should all contain no key names, only values, so: |
|
394 | + * |
|
395 | + * 'attributes' => [ |
|
396 | + * 'style="width:100%", |
|
397 | + * 'required' |
|
398 | + * ] |
|
399 | + * |
|
400 | + * @param $options |
|
401 | + * @return string |
|
402 | + */ |
|
403 | + protected function buildAttributesFromOptions($options) |
|
404 | + { |
|
405 | + if (isset($options['attributes']) && ! is_array($options['attributes'])) |
|
406 | + { |
|
407 | + $options['attributes'] = [ $options['attributes'] ]; |
|
408 | + } |
|
409 | + |
|
410 | + return isset($options['attributes']) ? implode($options['attributes']) : ''; |
|
411 | + } |
|
412 | + |
|
413 | + //-------------------------------------------------------------------- |
|
414 | 414 | } |
@@ -32,183 +32,183 @@ |
||
32 | 32 | |
33 | 33 | class DatabaseStore implements SettingsStoreInterface { |
34 | 34 | |
35 | - protected $ci; |
|
36 | - |
|
37 | - protected $db; |
|
38 | - |
|
39 | - //-------------------------------------------------------------------- |
|
40 | - |
|
41 | - public function __construct( $ci=null ) |
|
42 | - { |
|
43 | - if (is_object($ci)) |
|
44 | - { |
|
45 | - $this->ci =& $ci; |
|
46 | - } |
|
47 | - else { |
|
48 | - $this->ci =& get_instance(); |
|
49 | - } |
|
50 | - |
|
51 | - // Ensure that the database is loaded. |
|
52 | - if (empty($this->ci->db)) |
|
53 | - { |
|
54 | - $this->ci->load->database(); |
|
55 | - } |
|
56 | - } |
|
57 | - |
|
58 | - //-------------------------------------------------------------------- |
|
59 | - |
|
60 | - /** |
|
61 | - * Inserts or Replaces an setting value. |
|
62 | - * |
|
63 | - * @param $key |
|
64 | - * @param null $value |
|
65 | - * @param string $group |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function save($key, $value=null, $group='app') |
|
69 | - { |
|
70 | - if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
71 | - { |
|
72 | - return false; |
|
73 | - } |
|
74 | - |
|
75 | - $where = [ |
|
76 | - 'name' => $key, |
|
77 | - 'group' => $group |
|
78 | - ]; |
|
79 | - $this->ci->db->delete('settings', $where); |
|
80 | - |
|
81 | - if (is_array($value) || is_object($value)) |
|
82 | - { |
|
83 | - $value = serialize($value); |
|
84 | - } |
|
85 | - |
|
86 | - $data = [ |
|
87 | - 'name' => $key, |
|
88 | - 'value' => $value, |
|
89 | - 'group' => $group |
|
90 | - ]; |
|
91 | - return $this->ci->db->insert('settings', $data); |
|
92 | - } |
|
93 | - |
|
94 | - //-------------------------------------------------------------------- |
|
95 | - |
|
96 | - /** |
|
97 | - * Retrieves a single item. |
|
98 | - * |
|
99 | - * @param $key |
|
100 | - * @param string $group |
|
101 | - * @return mixed |
|
102 | - */ |
|
103 | - public function get($key, $group='app') |
|
104 | - { |
|
105 | - if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
106 | - { |
|
107 | - return false; |
|
108 | - } |
|
109 | - |
|
110 | - $where = [ |
|
111 | - 'name' => $key, |
|
112 | - 'group' => $group |
|
113 | - ]; |
|
114 | - |
|
115 | - $query = $this->ci->db->where($where) |
|
116 | - ->get('settings'); |
|
117 | - |
|
118 | - if (! $query->num_rows()) |
|
119 | - { |
|
120 | - return false; |
|
121 | - } |
|
122 | - |
|
123 | - $value = $query->row()->value; |
|
124 | - |
|
125 | - // Check to see if it needs to be unserialized |
|
126 | - $data = @unserialize($value); // We don't need to issue an E_NOTICE here... |
|
127 | - |
|
128 | - // Check for a value of false or |
|
129 | - if ($value === 'b:0;' || $data !== false) |
|
130 | - { |
|
131 | - $value = $data; |
|
132 | - } |
|
133 | - |
|
134 | - return $value; |
|
135 | - } |
|
136 | - |
|
137 | - //-------------------------------------------------------------------- |
|
138 | - |
|
139 | - /** |
|
140 | - * Deletes a single item. |
|
141 | - * |
|
142 | - * @param $key |
|
143 | - * @param $group |
|
144 | - * @return mixed |
|
145 | - */ |
|
146 | - public function delete($key, $group='app') |
|
147 | - { |
|
148 | - if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
149 | - { |
|
150 | - return false; |
|
151 | - } |
|
152 | - |
|
153 | - $where = [ |
|
154 | - 'name' => $key, |
|
155 | - 'group' => $group |
|
156 | - ]; |
|
157 | - |
|
158 | - return $this->ci->db->delete('settings', $where); |
|
159 | - } |
|
160 | - |
|
161 | - //-------------------------------------------------------------------- |
|
162 | - |
|
163 | - /** |
|
164 | - * Searches the store for any items with $field = $value. |
|
165 | - * |
|
166 | - * @param $field |
|
167 | - * @param $value |
|
168 | - * @return mixed |
|
169 | - */ |
|
170 | - public function findBy($field, $value) |
|
171 | - { |
|
172 | - if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
173 | - { |
|
174 | - return false; |
|
175 | - } |
|
176 | - |
|
177 | - $query = $this->ci->db->where($field, $value) |
|
178 | - ->get('settings'); |
|
179 | - |
|
180 | - if (! $query->num_rows()) |
|
181 | - { |
|
182 | - return false; |
|
183 | - } |
|
184 | - |
|
185 | - return $query->result_array(); |
|
186 | - } |
|
187 | - |
|
188 | - //-------------------------------------------------------------------- |
|
189 | - |
|
190 | - /** |
|
191 | - * Retrieves all items in the store either globally or for a single group. |
|
192 | - * |
|
193 | - * @param string $group |
|
194 | - * @return mixed |
|
195 | - */ |
|
196 | - public function all($group=null) |
|
197 | - { |
|
198 | - if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
199 | - { |
|
200 | - return false; |
|
201 | - } |
|
202 | - |
|
203 | - $query = $this->ci->db->get('settings'); |
|
204 | - |
|
205 | - if (! $query->num_rows()) |
|
206 | - { |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - return $query->result_array(); |
|
211 | - } |
|
212 | - |
|
213 | - //-------------------------------------------------------------------- |
|
35 | + protected $ci; |
|
36 | + |
|
37 | + protected $db; |
|
38 | + |
|
39 | + //-------------------------------------------------------------------- |
|
40 | + |
|
41 | + public function __construct( $ci=null ) |
|
42 | + { |
|
43 | + if (is_object($ci)) |
|
44 | + { |
|
45 | + $this->ci =& $ci; |
|
46 | + } |
|
47 | + else { |
|
48 | + $this->ci =& get_instance(); |
|
49 | + } |
|
50 | + |
|
51 | + // Ensure that the database is loaded. |
|
52 | + if (empty($this->ci->db)) |
|
53 | + { |
|
54 | + $this->ci->load->database(); |
|
55 | + } |
|
56 | + } |
|
57 | + |
|
58 | + //-------------------------------------------------------------------- |
|
59 | + |
|
60 | + /** |
|
61 | + * Inserts or Replaces an setting value. |
|
62 | + * |
|
63 | + * @param $key |
|
64 | + * @param null $value |
|
65 | + * @param string $group |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function save($key, $value=null, $group='app') |
|
69 | + { |
|
70 | + if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
71 | + { |
|
72 | + return false; |
|
73 | + } |
|
74 | + |
|
75 | + $where = [ |
|
76 | + 'name' => $key, |
|
77 | + 'group' => $group |
|
78 | + ]; |
|
79 | + $this->ci->db->delete('settings', $where); |
|
80 | + |
|
81 | + if (is_array($value) || is_object($value)) |
|
82 | + { |
|
83 | + $value = serialize($value); |
|
84 | + } |
|
85 | + |
|
86 | + $data = [ |
|
87 | + 'name' => $key, |
|
88 | + 'value' => $value, |
|
89 | + 'group' => $group |
|
90 | + ]; |
|
91 | + return $this->ci->db->insert('settings', $data); |
|
92 | + } |
|
93 | + |
|
94 | + //-------------------------------------------------------------------- |
|
95 | + |
|
96 | + /** |
|
97 | + * Retrieves a single item. |
|
98 | + * |
|
99 | + * @param $key |
|
100 | + * @param string $group |
|
101 | + * @return mixed |
|
102 | + */ |
|
103 | + public function get($key, $group='app') |
|
104 | + { |
|
105 | + if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
106 | + { |
|
107 | + return false; |
|
108 | + } |
|
109 | + |
|
110 | + $where = [ |
|
111 | + 'name' => $key, |
|
112 | + 'group' => $group |
|
113 | + ]; |
|
114 | + |
|
115 | + $query = $this->ci->db->where($where) |
|
116 | + ->get('settings'); |
|
117 | + |
|
118 | + if (! $query->num_rows()) |
|
119 | + { |
|
120 | + return false; |
|
121 | + } |
|
122 | + |
|
123 | + $value = $query->row()->value; |
|
124 | + |
|
125 | + // Check to see if it needs to be unserialized |
|
126 | + $data = @unserialize($value); // We don't need to issue an E_NOTICE here... |
|
127 | + |
|
128 | + // Check for a value of false or |
|
129 | + if ($value === 'b:0;' || $data !== false) |
|
130 | + { |
|
131 | + $value = $data; |
|
132 | + } |
|
133 | + |
|
134 | + return $value; |
|
135 | + } |
|
136 | + |
|
137 | + //-------------------------------------------------------------------- |
|
138 | + |
|
139 | + /** |
|
140 | + * Deletes a single item. |
|
141 | + * |
|
142 | + * @param $key |
|
143 | + * @param $group |
|
144 | + * @return mixed |
|
145 | + */ |
|
146 | + public function delete($key, $group='app') |
|
147 | + { |
|
148 | + if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
149 | + { |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + $where = [ |
|
154 | + 'name' => $key, |
|
155 | + 'group' => $group |
|
156 | + ]; |
|
157 | + |
|
158 | + return $this->ci->db->delete('settings', $where); |
|
159 | + } |
|
160 | + |
|
161 | + //-------------------------------------------------------------------- |
|
162 | + |
|
163 | + /** |
|
164 | + * Searches the store for any items with $field = $value. |
|
165 | + * |
|
166 | + * @param $field |
|
167 | + * @param $value |
|
168 | + * @return mixed |
|
169 | + */ |
|
170 | + public function findBy($field, $value) |
|
171 | + { |
|
172 | + if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
173 | + { |
|
174 | + return false; |
|
175 | + } |
|
176 | + |
|
177 | + $query = $this->ci->db->where($field, $value) |
|
178 | + ->get('settings'); |
|
179 | + |
|
180 | + if (! $query->num_rows()) |
|
181 | + { |
|
182 | + return false; |
|
183 | + } |
|
184 | + |
|
185 | + return $query->result_array(); |
|
186 | + } |
|
187 | + |
|
188 | + //-------------------------------------------------------------------- |
|
189 | + |
|
190 | + /** |
|
191 | + * Retrieves all items in the store either globally or for a single group. |
|
192 | + * |
|
193 | + * @param string $group |
|
194 | + * @return mixed |
|
195 | + */ |
|
196 | + public function all($group=null) |
|
197 | + { |
|
198 | + if (empty($this->ci->db) || ! is_object($this->ci->db)) |
|
199 | + { |
|
200 | + return false; |
|
201 | + } |
|
202 | + |
|
203 | + $query = $this->ci->db->get('settings'); |
|
204 | + |
|
205 | + if (! $query->num_rows()) |
|
206 | + { |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + return $query->result_array(); |
|
211 | + } |
|
212 | + |
|
213 | + //-------------------------------------------------------------------- |
|
214 | 214 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | |
18 | 18 | public function __construct($destination) |
19 | 19 | { |
20 | - $this->source_path = realpath(BUILDBASE .'../'); |
|
20 | + $this->source_path = realpath(BUILDBASE .'../'); |
|
21 | 21 | |
22 | 22 | if (empty($this->source_path)) |
23 | 23 | { |
@@ -1,34 +1,34 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Sprint |
|
4 | - * |
|
5 | - * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
6 | - * |
|
7 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 | - * of this software and associated documentation files (the "Software"), to deal |
|
9 | - * in the Software without restriction, including without limitation the rights |
|
10 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11 | - * copies of the Software, and to permit persons to whom the Software is |
|
12 | - * furnished to do so, subject to the following conditions: |
|
13 | - * |
|
14 | - * The above copyright notice and this permission notice shall be included in |
|
15 | - * all copies or substantial portions of the Software. |
|
16 | - * |
|
17 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
23 | - * THE SOFTWARE. |
|
24 | - * |
|
25 | - * @package Sprint |
|
26 | - * @author Lonnie Ezell |
|
27 | - * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
28 | - * @license http://opensource.org/licenses/MIT (MIT) |
|
29 | - * @link http://sprintphp.com |
|
30 | - * @since Version 1.0 |
|
31 | - */ |
|
3 | + * Sprint |
|
4 | + * |
|
5 | + * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
6 | + * |
|
7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 | + * of this software and associated documentation files (the "Software"), to deal |
|
9 | + * in the Software without restriction, including without limitation the rights |
|
10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11 | + * copies of the Software, and to permit persons to whom the Software is |
|
12 | + * furnished to do so, subject to the following conditions: |
|
13 | + * |
|
14 | + * The above copyright notice and this permission notice shall be included in |
|
15 | + * all copies or substantial portions of the Software. |
|
16 | + * |
|
17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
23 | + * THE SOFTWARE. |
|
24 | + * |
|
25 | + * @package Sprint |
|
26 | + * @author Lonnie Ezell |
|
27 | + * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
28 | + * @license http://opensource.org/licenses/MIT (MIT) |
|
29 | + * @link http://sprintphp.com |
|
30 | + * @since Version 1.0 |
|
31 | + */ |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * BUILD TOOL |
@@ -1,40 +1,40 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * CodeIgniter |
|
4 | - * |
|
5 | - * An open source application development framework for PHP |
|
6 | - * |
|
7 | - * This content is released under the MIT License (MIT) |
|
8 | - * |
|
9 | - * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
|
10 | - * |
|
11 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
12 | - * of this software and associated documentation files (the "Software"), to deal |
|
13 | - * in the Software without restriction, including without limitation the rights |
|
14 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
15 | - * copies of the Software, and to permit persons to whom the Software is |
|
16 | - * furnished to do so, subject to the following conditions: |
|
17 | - * |
|
18 | - * The above copyright notice and this permission notice shall be included in |
|
19 | - * all copies or substantial portions of the Software. |
|
20 | - * |
|
21 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
22 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
23 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
24 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
25 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
26 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
27 | - * THE SOFTWARE. |
|
28 | - * |
|
29 | - * @package CodeIgniter |
|
30 | - * @author EllisLab Dev Team |
|
31 | - * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
|
32 | - * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
|
33 | - * @license http://opensource.org/licenses/MIT MIT License |
|
34 | - * @link http://codeigniter.com |
|
35 | - * @since Version 1.0.0 |
|
36 | - * @filesource |
|
37 | - */ |
|
3 | + * CodeIgniter |
|
4 | + * |
|
5 | + * An open source application development framework for PHP |
|
6 | + * |
|
7 | + * This content is released under the MIT License (MIT) |
|
8 | + * |
|
9 | + * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
|
10 | + * |
|
11 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
12 | + * of this software and associated documentation files (the "Software"), to deal |
|
13 | + * in the Software without restriction, including without limitation the rights |
|
14 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
15 | + * copies of the Software, and to permit persons to whom the Software is |
|
16 | + * furnished to do so, subject to the following conditions: |
|
17 | + * |
|
18 | + * The above copyright notice and this permission notice shall be included in |
|
19 | + * all copies or substantial portions of the Software. |
|
20 | + * |
|
21 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
22 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
23 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
24 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
25 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
26 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
27 | + * THE SOFTWARE. |
|
28 | + * |
|
29 | + * @package CodeIgniter |
|
30 | + * @author EllisLab Dev Team |
|
31 | + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
|
32 | + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
|
33 | + * @license http://opensource.org/licenses/MIT MIT License |
|
34 | + * @link http://codeigniter.com |
|
35 | + * @since Version 1.0.0 |
|
36 | + * @filesource |
|
37 | + */ |
|
38 | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
39 | 39 | |
40 | 40 | /** |
@@ -1,40 +1,40 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * CodeIgniter |
|
4 | - * |
|
5 | - * An open source application development framework for PHP |
|
6 | - * |
|
7 | - * This content is released under the MIT License (MIT) |
|
8 | - * |
|
9 | - * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
|
10 | - * |
|
11 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
12 | - * of this software and associated documentation files (the "Software"), to deal |
|
13 | - * in the Software without restriction, including without limitation the rights |
|
14 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
15 | - * copies of the Software, and to permit persons to whom the Software is |
|
16 | - * furnished to do so, subject to the following conditions: |
|
17 | - * |
|
18 | - * The above copyright notice and this permission notice shall be included in |
|
19 | - * all copies or substantial portions of the Software. |
|
20 | - * |
|
21 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
22 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
23 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
24 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
25 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
26 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
27 | - * THE SOFTWARE. |
|
28 | - * |
|
29 | - * @package CodeIgniter |
|
30 | - * @author EllisLab Dev Team |
|
31 | - * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
|
32 | - * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
|
33 | - * @license http://opensource.org/licenses/MIT MIT License |
|
34 | - * @link http://codeigniter.com |
|
35 | - * @since Version 1.0.0 |
|
36 | - * @filesource |
|
37 | - */ |
|
3 | + * CodeIgniter |
|
4 | + * |
|
5 | + * An open source application development framework for PHP |
|
6 | + * |
|
7 | + * This content is released under the MIT License (MIT) |
|
8 | + * |
|
9 | + * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
|
10 | + * |
|
11 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
12 | + * of this software and associated documentation files (the "Software"), to deal |
|
13 | + * in the Software without restriction, including without limitation the rights |
|
14 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
15 | + * copies of the Software, and to permit persons to whom the Software is |
|
16 | + * furnished to do so, subject to the following conditions: |
|
17 | + * |
|
18 | + * The above copyright notice and this permission notice shall be included in |
|
19 | + * all copies or substantial portions of the Software. |
|
20 | + * |
|
21 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
22 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
23 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
24 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
25 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
26 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
27 | + * THE SOFTWARE. |
|
28 | + * |
|
29 | + * @package CodeIgniter |
|
30 | + * @author EllisLab Dev Team |
|
31 | + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
|
32 | + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
|
33 | + * @license http://opensource.org/licenses/MIT MIT License |
|
34 | + * @link http://codeigniter.com |
|
35 | + * @since Version 1.0.0 |
|
36 | + * @filesource |
|
37 | + */ |
|
38 | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
39 | 39 | |
40 | 40 | /** |
@@ -1,40 +1,40 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * CodeIgniter |
|
4 | - * |
|
5 | - * An open source application development framework for PHP |
|
6 | - * |
|
7 | - * This content is released under the MIT License (MIT) |
|
8 | - * |
|
9 | - * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
|
10 | - * |
|
11 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
12 | - * of this software and associated documentation files (the "Software"), to deal |
|
13 | - * in the Software without restriction, including without limitation the rights |
|
14 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
15 | - * copies of the Software, and to permit persons to whom the Software is |
|
16 | - * furnished to do so, subject to the following conditions: |
|
17 | - * |
|
18 | - * The above copyright notice and this permission notice shall be included in |
|
19 | - * all copies or substantial portions of the Software. |
|
20 | - * |
|
21 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
22 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
23 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
24 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
25 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
26 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
27 | - * THE SOFTWARE. |
|
28 | - * |
|
29 | - * @package CodeIgniter |
|
30 | - * @author EllisLab Dev Team |
|
31 | - * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
|
32 | - * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
|
33 | - * @license http://opensource.org/licenses/MIT MIT License |
|
34 | - * @link http://codeigniter.com |
|
35 | - * @since Version 1.0.0 |
|
36 | - * @filesource |
|
37 | - */ |
|
3 | + * CodeIgniter |
|
4 | + * |
|
5 | + * An open source application development framework for PHP |
|
6 | + * |
|
7 | + * This content is released under the MIT License (MIT) |
|
8 | + * |
|
9 | + * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
|
10 | + * |
|
11 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
12 | + * of this software and associated documentation files (the "Software"), to deal |
|
13 | + * in the Software without restriction, including without limitation the rights |
|
14 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
15 | + * copies of the Software, and to permit persons to whom the Software is |
|
16 | + * furnished to do so, subject to the following conditions: |
|
17 | + * |
|
18 | + * The above copyright notice and this permission notice shall be included in |
|
19 | + * all copies or substantial portions of the Software. |
|
20 | + * |
|
21 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
22 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
23 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
24 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
25 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
26 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
27 | + * THE SOFTWARE. |
|
28 | + * |
|
29 | + * @package CodeIgniter |
|
30 | + * @author EllisLab Dev Team |
|
31 | + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
|
32 | + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
|
33 | + * @license http://opensource.org/licenses/MIT MIT License |
|
34 | + * @link http://codeigniter.com |
|
35 | + * @since Version 1.0.0 |
|
36 | + * @filesource |
|
37 | + */ |
|
38 | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
39 | 39 | |
40 | 40 | /** |
@@ -33,284 +33,284 @@ |
||
33 | 33 | class Docs extends \Myth\Controllers\ThemedController |
34 | 34 | { |
35 | 35 | |
36 | - protected $ignoreFiles = array('_404.md'); |
|
36 | + protected $ignoreFiles = array('_404.md'); |
|
37 | 37 | |
38 | - protected $tocFile; |
|
38 | + protected $tocFile; |
|
39 | 39 | |
40 | - protected $doc_folders = []; |
|
40 | + protected $doc_folders = []; |
|
41 | 41 | |
42 | - protected $current_group = null; |
|
42 | + protected $current_group = null; |
|
43 | 43 | |
44 | - protected $current_path = null; |
|
44 | + protected $current_path = null; |
|
45 | 45 | |
46 | - private $showAppDocs; |
|
46 | + private $showAppDocs; |
|
47 | 47 | |
48 | - private $showDevDocs; |
|
48 | + private $showDevDocs; |
|
49 | 49 | |
50 | - protected $theme = 'docs'; |
|
50 | + protected $theme = 'docs'; |
|
51 | 51 | |
52 | - protected $auto_escape = false; |
|
52 | + protected $auto_escape = false; |
|
53 | 53 | |
54 | - //-------------------------------------------------------------------------- |
|
54 | + //-------------------------------------------------------------------------- |
|
55 | 55 | |
56 | - /** |
|
57 | - * Constructor |
|
58 | - * |
|
59 | - * @return \Docs |
|
60 | - */ |
|
61 | - public function __construct() |
|
62 | - { |
|
63 | - parent::__construct(); |
|
56 | + /** |
|
57 | + * Constructor |
|
58 | + * |
|
59 | + * @return \Docs |
|
60 | + */ |
|
61 | + public function __construct() |
|
62 | + { |
|
63 | + parent::__construct(); |
|
64 | 64 | |
65 | - $this->load->config('docs'); |
|
66 | - $this->lang->load('docs'); |
|
65 | + $this->load->config('docs'); |
|
66 | + $this->lang->load('docs'); |
|
67 | 67 | |
68 | - // Save our folders |
|
69 | - $this->doc_folders = config_item('docs.folders'); |
|
68 | + // Save our folders |
|
69 | + $this->doc_folders = config_item('docs.folders'); |
|
70 | 70 | |
71 | - list($this->current_group, $this->current_path) = $this->determineFromURL(); |
|
71 | + list($this->current_group, $this->current_path) = $this->determineFromURL(); |
|
72 | 72 | |
73 | - $this->determineVisibleGroups($this->current_group, $this->current_path); |
|
73 | + $this->determineVisibleGroups($this->current_group, $this->current_path); |
|
74 | 74 | |
75 | - $this->load->helper('form'); |
|
76 | - $this->load->helper('language'); |
|
75 | + $this->load->helper('form'); |
|
76 | + $this->load->helper('language'); |
|
77 | 77 | |
78 | - $this->docbuilder = new \Myth\Docs\Builder( array('apppath' => APPPATH) ); |
|
78 | + $this->docbuilder = new \Myth\Docs\Builder( array('apppath' => APPPATH) ); |
|
79 | 79 | |
80 | - $formatter = function ($str) { |
|
81 | - $converter = new \League\CommonMark\CommonMarkConverter(); |
|
82 | - return $converter->convertToHtml($str); |
|
83 | - }; |
|
84 | - $this->docbuilder->registerFormatter($formatter, true); |
|
85 | - } |
|
80 | + $formatter = function ($str) { |
|
81 | + $converter = new \League\CommonMark\CommonMarkConverter(); |
|
82 | + return $converter->convertToHtml($str); |
|
83 | + }; |
|
84 | + $this->docbuilder->registerFormatter($formatter, true); |
|
85 | + } |
|
86 | 86 | |
87 | - //-------------------------------------------------------------------- |
|
87 | + //-------------------------------------------------------------------- |
|
88 | 88 | |
89 | - /** |
|
90 | - * Display the list of documents available and the current document |
|
91 | - * |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function index() |
|
95 | - { |
|
96 | - $data = array(); |
|
89 | + /** |
|
90 | + * Display the list of documents available and the current document |
|
91 | + * |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function index() |
|
95 | + { |
|
96 | + $data = array(); |
|
97 | 97 | |
98 | - // Make sure the builder knows where to look |
|
99 | - foreach ($this->doc_folders as $alias => $folder) { |
|
100 | - $this->docbuilder->addDocFolder($alias, $folder); |
|
101 | - } |
|
102 | - |
|
103 | - try { |
|
104 | - $content = $this->docbuilder->readPage($this->current_path, $this->current_group); |
|
105 | - $content = $this->docbuilder->postProcess($content, site_url(), current_url()); |
|
106 | - |
|
107 | - $data['sidebar'] = $this->buildSidebar($content); |
|
108 | - $data['toc'] = $this->buildTOC(); |
|
109 | - $data['content'] = $content; |
|
110 | - $data['page_title'] = $this->docbuilder->pageTitle(); |
|
111 | - } catch (Exception $e) { |
|
112 | - $this->setMessage($e->getMessage(), 'warning'); |
|
113 | - } |
|
114 | - |
|
115 | - $this->render($data, config_item('docs.cache_time')); |
|
116 | - } |
|
117 | - |
|
118 | - //-------------------------------------------------------------------- |
|
119 | - |
|
120 | - /** |
|
121 | - * Display search results and handles the search itself. |
|
122 | - * |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function search() |
|
126 | - { |
|
127 | - $this->benchmark->mark('search_start'); |
|
128 | - $this->docsearch = new \Myth\Docs\Search(); |
|
129 | - $this->load->helper('markdown_extended'); |
|
130 | - $this->docsearch->registerFormatter('MarkdownExtended', true); |
|
131 | - |
|
132 | - $data = array(); |
|
133 | - |
|
134 | - $terms = $this->input->post('search_terms'); |
|
135 | - |
|
136 | - if ($terms) { |
|
137 | - $search_folders = $this->doc_folders; |
|
138 | - |
|
139 | - $data['results'] = $this->docsearch->search($terms, $search_folders); |
|
140 | - } |
|
141 | - |
|
142 | - $this->benchmark->mark('search_end'); |
|
143 | - |
|
144 | - $data['search_time'] = $this->benchmark->elapsed_time('search_start', 'search_end'); |
|
145 | - $data['search_terms'] = $terms; |
|
146 | - $data['page_title'] = 'Search Results'; |
|
147 | - |
|
148 | - $this->render($data); |
|
149 | - } |
|
150 | - |
|
151 | - //-------------------------------------------------------------------------- |
|
152 | - // Private Methods |
|
153 | - //-------------------------------------------------------------------------- |
|
154 | - |
|
155 | - /** |
|
156 | - * Determines which groups are allowed to be viewed by the current system |
|
157 | - * and the user/environment. |
|
158 | - * |
|
159 | - * todo Allow docs groups to be shown/hidden per-environment, using assoc-array for permitted environments |
|
160 | - */ |
|
161 | - private function determineVisibleGroups($current_group, $current_path) |
|
162 | - { |
|
163 | - // Is displaying docs permitted for this environment? |
|
164 | - if (config_item('docs.permitted_environments') |
|
165 | - && !in_array(ENVIRONMENT, config_item('docs.permitted_environments')) |
|
166 | - ) { |
|
167 | - $this->setMessage(lang('docs_env_disabled'), 'danger'); |
|
168 | - redirect(); |
|
169 | - } |
|
170 | - |
|
171 | - $this->showAppDocs = config_item('docs.show_app_docs'); |
|
172 | - $this->showDevDocs = config_item('docs.show_dev_docs'); |
|
173 | - $this->tocFile = config_item('docs.toc_file') ?: '_toc.ini'; |
|
174 | - |
|
175 | - // Make sure we can still get to the search method. |
|
176 | - if ($current_group == 'search') { |
|
177 | - $this->current_group = false; |
|
178 | - } // Are we allowed to show developer docs in this environment? |
|
179 | - elseif ($current_group == 'developer' |
|
180 | - && !$this->showDevDocs |
|
181 | - && ENVIRONMENT != 'development' |
|
182 | - ) { |
|
183 | - if ($this->showAppDocs) { |
|
184 | - $this->setMessage(lang('docs_not_allowed_dev'), 'warning'); |
|
185 | - |
|
186 | - redirect('docs/application'); |
|
187 | - } |
|
188 | - |
|
189 | - show_error(lang('docs_not_allowed')); |
|
190 | - } |
|
191 | - } |
|
192 | - |
|
193 | - //-------------------------------------------------------------------- |
|
194 | - |
|
195 | - /** |
|
196 | - * Determines the current doc group and file path from the current URL. |
|
197 | - * |
|
198 | - * Returns an array with the group and file path in the 0 and 1 positions, respectively. |
|
199 | - * |
|
200 | - * @return array |
|
201 | - */ |
|
202 | - private function determineFromURL() |
|
203 | - { |
|
204 | - $return = [ |
|
205 | - '', // Group |
|
206 | - '', // File Path |
|
207 | - ]; |
|
208 | - |
|
209 | - $segments = $this->uri->segment_array(); |
|
210 | - |
|
211 | - // Remove the 'docs' from the array |
|
212 | - // for now, we assume this is the first one |
|
213 | - // since that is how Bonfire is setup to show docs |
|
214 | - // @todo Make it so the path can be modified and this still works. |
|
215 | - array_shift($segments); |
|
216 | - |
|
217 | - // If nothing left, then assign the default group and redirect to |
|
218 | - // a page we can do something with... |
|
219 | - if (!count($segments)) { |
|
220 | - redirect('docs/' . config_item('docs.default_group')); |
|
221 | - } |
|
222 | - |
|
223 | - // Do we have a group specified? Bonfire Docs requires that a group |
|
224 | - // be part of the URI so it should be the first element on the array. |
|
225 | - $return[0] = array_shift($segments); |
|
226 | - |
|
227 | - // If there's any more left, then join them together and they'll |
|
228 | - // form the path to the file. This will allow for subfolders with the |
|
229 | - // docs folder itself. |
|
230 | - $return[1] = count($segments) ? implode('/', $segments) : 'index'; |
|
231 | - |
|
232 | - return $return; |
|
233 | - } |
|
234 | - |
|
235 | - //-------------------------------------------------------------------- |
|
236 | - |
|
237 | - /** |
|
238 | - * Builds a TOC for the sidebar out of files found in the following folders: |
|
239 | - * - application/docs |
|
240 | - * - bonfire/docs |
|
241 | - * - {module}/docs |
|
242 | - * |
|
243 | - * @param $content The HTML generated for the page content. |
|
244 | - * @return string The HTML for the sidebar. |
|
245 | - */ |
|
246 | - private function buildSidebar(&$content) |
|
247 | - { |
|
248 | - $data = []; |
|
249 | - |
|
250 | - // Set the remaining data for the view |
|
251 | - $data['docsDir'] = 'docs/' . $this->current_group . '/'; |
|
252 | - $data['docsExt'] = config_item('docs.extension'); |
|
253 | - |
|
254 | - $data['docMap'] = $this->docbuilder->buildDocumentMap($content); |
|
255 | - |
|
256 | - return $this->docbuilder->postProcess( |
|
257 | - $this->load->view('docs/_document_map', $data, true), |
|
258 | - site_url(), |
|
259 | - current_url() |
|
260 | - ); |
|
261 | - } |
|
262 | - |
|
263 | - //-------------------------------------------------------------------- |
|
264 | - |
|
265 | - /** |
|
266 | - * Builds out the nested lists of items that are needed |
|
267 | - */ |
|
268 | - private function buildTOC() |
|
269 | - { |
|
270 | - $folder = $this->doc_folders[$this->current_group] . '/'; |
|
271 | - |
|
272 | - $map = $this->docbuilder->buildTOC($folder); |
|
273 | - |
|
274 | - return $this->docbuilder->postProcess( |
|
275 | - $this->load->view('docs/_toc', ['map' => $map], true), |
|
276 | - site_url(), |
|
277 | - current_url() |
|
278 | - ); |
|
279 | - } |
|
280 | - |
|
281 | - //-------------------------------------------------------------------- |
|
282 | - |
|
283 | - /** |
|
284 | - * Checks all modules to see if they include docs and prepares their doc |
|
285 | - * information for use in the sidebar. |
|
286 | - * |
|
287 | - * @return array |
|
288 | - */ |
|
289 | - private function get_module_docs() |
|
290 | - { |
|
291 | - $docs_modules = array(); |
|
292 | - foreach (\Bonfire\Modules::list_modules() as $module) { |
|
293 | - $ignored_folders = array(); |
|
294 | - $path = \Bonfire\Modules::path($module) . $this->docsDir; |
|
295 | - |
|
296 | - // If these are developer docs, add the folder to the path. |
|
297 | - if ($this->current_group == $this->docsTypeBf) { |
|
298 | - $path .= '/' . $this->docsTypeBf; |
|
299 | - } // For Application docs, ignore the 'developers' folder. |
|
300 | - else { |
|
301 | - $ignored_folders[] = $this->docsTypeBf; |
|
302 | - } |
|
303 | - |
|
304 | - if (is_dir($path)) { |
|
305 | - $files = $this->get_folder_files($path, $module, $ignored_folders); |
|
306 | - if (is_array($files) && count($files)) { |
|
307 | - $docs_modules[$module] = $files; |
|
308 | - } |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - return $docs_modules; |
|
313 | - } |
|
314 | - //-------------------------------------------------------------------- |
|
98 | + // Make sure the builder knows where to look |
|
99 | + foreach ($this->doc_folders as $alias => $folder) { |
|
100 | + $this->docbuilder->addDocFolder($alias, $folder); |
|
101 | + } |
|
102 | + |
|
103 | + try { |
|
104 | + $content = $this->docbuilder->readPage($this->current_path, $this->current_group); |
|
105 | + $content = $this->docbuilder->postProcess($content, site_url(), current_url()); |
|
106 | + |
|
107 | + $data['sidebar'] = $this->buildSidebar($content); |
|
108 | + $data['toc'] = $this->buildTOC(); |
|
109 | + $data['content'] = $content; |
|
110 | + $data['page_title'] = $this->docbuilder->pageTitle(); |
|
111 | + } catch (Exception $e) { |
|
112 | + $this->setMessage($e->getMessage(), 'warning'); |
|
113 | + } |
|
114 | + |
|
115 | + $this->render($data, config_item('docs.cache_time')); |
|
116 | + } |
|
117 | + |
|
118 | + //-------------------------------------------------------------------- |
|
119 | + |
|
120 | + /** |
|
121 | + * Display search results and handles the search itself. |
|
122 | + * |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function search() |
|
126 | + { |
|
127 | + $this->benchmark->mark('search_start'); |
|
128 | + $this->docsearch = new \Myth\Docs\Search(); |
|
129 | + $this->load->helper('markdown_extended'); |
|
130 | + $this->docsearch->registerFormatter('MarkdownExtended', true); |
|
131 | + |
|
132 | + $data = array(); |
|
133 | + |
|
134 | + $terms = $this->input->post('search_terms'); |
|
135 | + |
|
136 | + if ($terms) { |
|
137 | + $search_folders = $this->doc_folders; |
|
138 | + |
|
139 | + $data['results'] = $this->docsearch->search($terms, $search_folders); |
|
140 | + } |
|
141 | + |
|
142 | + $this->benchmark->mark('search_end'); |
|
143 | + |
|
144 | + $data['search_time'] = $this->benchmark->elapsed_time('search_start', 'search_end'); |
|
145 | + $data['search_terms'] = $terms; |
|
146 | + $data['page_title'] = 'Search Results'; |
|
147 | + |
|
148 | + $this->render($data); |
|
149 | + } |
|
150 | + |
|
151 | + //-------------------------------------------------------------------------- |
|
152 | + // Private Methods |
|
153 | + //-------------------------------------------------------------------------- |
|
154 | + |
|
155 | + /** |
|
156 | + * Determines which groups are allowed to be viewed by the current system |
|
157 | + * and the user/environment. |
|
158 | + * |
|
159 | + * todo Allow docs groups to be shown/hidden per-environment, using assoc-array for permitted environments |
|
160 | + */ |
|
161 | + private function determineVisibleGroups($current_group, $current_path) |
|
162 | + { |
|
163 | + // Is displaying docs permitted for this environment? |
|
164 | + if (config_item('docs.permitted_environments') |
|
165 | + && !in_array(ENVIRONMENT, config_item('docs.permitted_environments')) |
|
166 | + ) { |
|
167 | + $this->setMessage(lang('docs_env_disabled'), 'danger'); |
|
168 | + redirect(); |
|
169 | + } |
|
170 | + |
|
171 | + $this->showAppDocs = config_item('docs.show_app_docs'); |
|
172 | + $this->showDevDocs = config_item('docs.show_dev_docs'); |
|
173 | + $this->tocFile = config_item('docs.toc_file') ?: '_toc.ini'; |
|
174 | + |
|
175 | + // Make sure we can still get to the search method. |
|
176 | + if ($current_group == 'search') { |
|
177 | + $this->current_group = false; |
|
178 | + } // Are we allowed to show developer docs in this environment? |
|
179 | + elseif ($current_group == 'developer' |
|
180 | + && !$this->showDevDocs |
|
181 | + && ENVIRONMENT != 'development' |
|
182 | + ) { |
|
183 | + if ($this->showAppDocs) { |
|
184 | + $this->setMessage(lang('docs_not_allowed_dev'), 'warning'); |
|
185 | + |
|
186 | + redirect('docs/application'); |
|
187 | + } |
|
188 | + |
|
189 | + show_error(lang('docs_not_allowed')); |
|
190 | + } |
|
191 | + } |
|
192 | + |
|
193 | + //-------------------------------------------------------------------- |
|
194 | + |
|
195 | + /** |
|
196 | + * Determines the current doc group and file path from the current URL. |
|
197 | + * |
|
198 | + * Returns an array with the group and file path in the 0 and 1 positions, respectively. |
|
199 | + * |
|
200 | + * @return array |
|
201 | + */ |
|
202 | + private function determineFromURL() |
|
203 | + { |
|
204 | + $return = [ |
|
205 | + '', // Group |
|
206 | + '', // File Path |
|
207 | + ]; |
|
208 | + |
|
209 | + $segments = $this->uri->segment_array(); |
|
210 | + |
|
211 | + // Remove the 'docs' from the array |
|
212 | + // for now, we assume this is the first one |
|
213 | + // since that is how Bonfire is setup to show docs |
|
214 | + // @todo Make it so the path can be modified and this still works. |
|
215 | + array_shift($segments); |
|
216 | + |
|
217 | + // If nothing left, then assign the default group and redirect to |
|
218 | + // a page we can do something with... |
|
219 | + if (!count($segments)) { |
|
220 | + redirect('docs/' . config_item('docs.default_group')); |
|
221 | + } |
|
222 | + |
|
223 | + // Do we have a group specified? Bonfire Docs requires that a group |
|
224 | + // be part of the URI so it should be the first element on the array. |
|
225 | + $return[0] = array_shift($segments); |
|
226 | + |
|
227 | + // If there's any more left, then join them together and they'll |
|
228 | + // form the path to the file. This will allow for subfolders with the |
|
229 | + // docs folder itself. |
|
230 | + $return[1] = count($segments) ? implode('/', $segments) : 'index'; |
|
231 | + |
|
232 | + return $return; |
|
233 | + } |
|
234 | + |
|
235 | + //-------------------------------------------------------------------- |
|
236 | + |
|
237 | + /** |
|
238 | + * Builds a TOC for the sidebar out of files found in the following folders: |
|
239 | + * - application/docs |
|
240 | + * - bonfire/docs |
|
241 | + * - {module}/docs |
|
242 | + * |
|
243 | + * @param $content The HTML generated for the page content. |
|
244 | + * @return string The HTML for the sidebar. |
|
245 | + */ |
|
246 | + private function buildSidebar(&$content) |
|
247 | + { |
|
248 | + $data = []; |
|
249 | + |
|
250 | + // Set the remaining data for the view |
|
251 | + $data['docsDir'] = 'docs/' . $this->current_group . '/'; |
|
252 | + $data['docsExt'] = config_item('docs.extension'); |
|
253 | + |
|
254 | + $data['docMap'] = $this->docbuilder->buildDocumentMap($content); |
|
255 | + |
|
256 | + return $this->docbuilder->postProcess( |
|
257 | + $this->load->view('docs/_document_map', $data, true), |
|
258 | + site_url(), |
|
259 | + current_url() |
|
260 | + ); |
|
261 | + } |
|
262 | + |
|
263 | + //-------------------------------------------------------------------- |
|
264 | + |
|
265 | + /** |
|
266 | + * Builds out the nested lists of items that are needed |
|
267 | + */ |
|
268 | + private function buildTOC() |
|
269 | + { |
|
270 | + $folder = $this->doc_folders[$this->current_group] . '/'; |
|
271 | + |
|
272 | + $map = $this->docbuilder->buildTOC($folder); |
|
273 | + |
|
274 | + return $this->docbuilder->postProcess( |
|
275 | + $this->load->view('docs/_toc', ['map' => $map], true), |
|
276 | + site_url(), |
|
277 | + current_url() |
|
278 | + ); |
|
279 | + } |
|
280 | + |
|
281 | + //-------------------------------------------------------------------- |
|
282 | + |
|
283 | + /** |
|
284 | + * Checks all modules to see if they include docs and prepares their doc |
|
285 | + * information for use in the sidebar. |
|
286 | + * |
|
287 | + * @return array |
|
288 | + */ |
|
289 | + private function get_module_docs() |
|
290 | + { |
|
291 | + $docs_modules = array(); |
|
292 | + foreach (\Bonfire\Modules::list_modules() as $module) { |
|
293 | + $ignored_folders = array(); |
|
294 | + $path = \Bonfire\Modules::path($module) . $this->docsDir; |
|
295 | + |
|
296 | + // If these are developer docs, add the folder to the path. |
|
297 | + if ($this->current_group == $this->docsTypeBf) { |
|
298 | + $path .= '/' . $this->docsTypeBf; |
|
299 | + } // For Application docs, ignore the 'developers' folder. |
|
300 | + else { |
|
301 | + $ignored_folders[] = $this->docsTypeBf; |
|
302 | + } |
|
303 | + |
|
304 | + if (is_dir($path)) { |
|
305 | + $files = $this->get_folder_files($path, $module, $ignored_folders); |
|
306 | + if (is_array($files) && count($files)) { |
|
307 | + $docs_modules[$module] = $files; |
|
308 | + } |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + return $docs_modules; |
|
313 | + } |
|
314 | + //-------------------------------------------------------------------- |
|
315 | 315 | |
316 | 316 | } |
@@ -1,34 +1,34 @@ discard block |
||
1 | 1 | <?php namespace Myth\Docs; |
2 | 2 | /** |
3 | - * Sprint |
|
4 | - * |
|
5 | - * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
6 | - * |
|
7 | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 | - * of this software and associated documentation files (the "Software"), to deal |
|
9 | - * in the Software without restriction, including without limitation the rights |
|
10 | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11 | - * copies of the Software, and to permit persons to whom the Software is |
|
12 | - * furnished to do so, subject to the following conditions: |
|
13 | - * |
|
14 | - * The above copyright notice and this permission notice shall be included in |
|
15 | - * all copies or substantial portions of the Software. |
|
16 | - * |
|
17 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20 | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22 | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
23 | - * THE SOFTWARE. |
|
24 | - * |
|
25 | - * @package Sprint |
|
26 | - * @author Lonnie Ezell |
|
27 | - * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
28 | - * @license http://opensource.org/licenses/MIT (MIT) |
|
29 | - * @link http://sprintphp.com |
|
30 | - * @since Version 1.0 |
|
31 | - */ |
|
3 | + * Sprint |
|
4 | + * |
|
5 | + * A set of power tools to enhance the CodeIgniter framework and provide consistent workflow. |
|
6 | + * |
|
7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 | + * of this software and associated documentation files (the "Software"), to deal |
|
9 | + * in the Software without restriction, including without limitation the rights |
|
10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11 | + * copies of the Software, and to permit persons to whom the Software is |
|
12 | + * furnished to do so, subject to the following conditions: |
|
13 | + * |
|
14 | + * The above copyright notice and this permission notice shall be included in |
|
15 | + * all copies or substantial portions of the Software. |
|
16 | + * |
|
17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
23 | + * THE SOFTWARE. |
|
24 | + * |
|
25 | + * @package Sprint |
|
26 | + * @author Lonnie Ezell |
|
27 | + * @copyright Copyright 2014-2015, New Myth Media, LLC (http://newmythmedia.com) |
|
28 | + * @license http://opensource.org/licenses/MIT (MIT) |
|
29 | + * @link http://sprintphp.com |
|
30 | + * @since Version 1.0 |
|
31 | + */ |
|
32 | 32 | |
33 | 33 | use Myth\Docs\DocSearchInterface; |
34 | 34 | |
@@ -43,420 +43,420 @@ discard block |
||
43 | 43 | class Search implements DocSearchInterface |
44 | 44 | { |
45 | 45 | |
46 | - /** |
|
47 | - * Minimum characters that can be submitted for a search. |
|
48 | - * |
|
49 | - * @var int |
|
50 | - */ |
|
51 | - protected $min_chars = 3; |
|
52 | - |
|
53 | - /** |
|
54 | - * Maximum characters that can be submitted for a search. |
|
55 | - * |
|
56 | - * @var int |
|
57 | - */ |
|
58 | - protected $max_chars = 30; |
|
59 | - |
|
60 | - /** |
|
61 | - * Valid file extensions we can search in. |
|
62 | - * |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - protected $allowed_file_types = 'html|htm|php|php4|php5|txt|md'; |
|
66 | - |
|
67 | - /** |
|
68 | - * Which files should we skip over during our search? |
|
69 | - * |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - protected $skip_files = ['.', '..', '_404.md', '_toc.ini']; |
|
73 | - |
|
74 | - /** |
|
75 | - * How much of each file should we read. |
|
76 | - * Use lower values for faster searches. |
|
77 | - * |
|
78 | - * @var int |
|
79 | - */ |
|
80 | - protected $byte_size = 51200; |
|
81 | - |
|
82 | - /** |
|
83 | - * Number of words long (approximately) |
|
84 | - * the result excerpt should be. |
|
85 | - * |
|
86 | - * @var int |
|
87 | - */ |
|
88 | - protected $excerpt_length = 60; |
|
89 | - |
|
90 | - /** |
|
91 | - * The maximum number of results allowed from a single file. |
|
92 | - * |
|
93 | - * @var int |
|
94 | - */ |
|
95 | - protected $max_per_file = 1; |
|
96 | - |
|
97 | - protected $doc_folders = array(); |
|
98 | - |
|
99 | - protected $formatters = array(); |
|
100 | - |
|
101 | - //-------------------------------------------------------------------- |
|
102 | - |
|
103 | - /** |
|
104 | - * The entry point for performing a search of the documentation. |
|
105 | - * |
|
106 | - * @param null $terms |
|
107 | - * @param array $folders |
|
108 | - * |
|
109 | - * @return array|null |
|
110 | - */ |
|
111 | - public function search($terms = null, $folders = []) |
|
112 | - { |
|
113 | - if (empty($terms) || empty($folders)) { |
|
114 | - return null; |
|
115 | - } |
|
116 | - |
|
117 | - $results = []; |
|
118 | - $this->doc_folders = $folders; |
|
119 | - |
|
120 | - foreach ($folders as $group => $folder) { |
|
121 | - $results = array_merge($results, $this->searchFolder($terms, $folder, $group)); |
|
122 | - } |
|
123 | - |
|
124 | - return $results; |
|
125 | - } |
|
126 | - |
|
127 | - //-------------------------------------------------------------------- |
|
128 | - |
|
129 | - //-------------------------------------------------------------------- |
|
130 | - // Private Methods |
|
131 | - //-------------------------------------------------------------------- |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * Searches a single directory worth of files. |
|
136 | - * |
|
137 | - * @param $term |
|
138 | - * @param $folder |
|
139 | - * @param $group_name |
|
140 | - * |
|
141 | - * @return array The results. |
|
142 | - */ |
|
143 | - protected function searchFolder($term, $folder, $group_name) |
|
144 | - { |
|
145 | - $results = []; |
|
146 | - |
|
147 | - $map = $this->directory_map($folder, 2); |
|
148 | - |
|
149 | - $map = $this->flattenMap($map); |
|
150 | - |
|
151 | - // Make sure we have something to work with. |
|
152 | - if (! is_array($map) || (is_array($map) && ! count($map))) { |
|
153 | - return []; |
|
154 | - } |
|
155 | - |
|
156 | - // Loop over each file and search the contents for our term. |
|
157 | - foreach ($map as $dir => $file) { |
|
158 | - $file_count = 0; |
|
159 | - |
|
160 | - if (in_array($file, $this->skip_files)) { |
|
161 | - continue; |
|
162 | - } |
|
163 | - |
|
164 | - // Is it a folder? |
|
165 | - if (is_array($file) && count($file)) { |
|
166 | - $results = array_merge($results, $this->searchFolder($term, $folder . '/' . $dir, $group_name)); |
|
167 | - continue; |
|
168 | - } |
|
169 | - |
|
170 | - // Make sure it's the right file type... |
|
171 | - if (! preg_match("/({$this->allowed_file_types})/i", $file)) { |
|
172 | - continue; |
|
173 | - } |
|
174 | - |
|
175 | - $path = is_string($dir) ? $folder . '/' . $dir . '/' . $file : $folder . '/' . $file; |
|
176 | - $term_html = htmlentities($term); |
|
177 | - |
|
178 | - // Read in the file text |
|
179 | - $handle = fopen($path, 'r'); |
|
180 | - $text = fread($handle, $this->byte_size); |
|
181 | - |
|
182 | - // Do we have a match in here somewhere? |
|
183 | - $found = stristr($text, $term) || stristr($text, $term_html); |
|
184 | - |
|
185 | - if (! $found) { |
|
186 | - continue; |
|
187 | - } |
|
188 | - |
|
189 | - // Escape our terms to safely use in a preg_match |
|
190 | - $excerpt = strip_tags($text); |
|
191 | - $term = preg_quote($term); |
|
192 | - $term = str_replace("/", "\/", "{$term}"); |
|
193 | - $term_html = preg_quote($term_html); |
|
194 | - $term_html = str_replace("/", "\/", "{$term_html}"); |
|
195 | - |
|
196 | - // Add the item to our results with extracts. |
|
197 | - if (preg_match_all( |
|
198 | - "/((\s\S*){0,3})($term|$term_html)((\s?\S*){0,3})/i", |
|
199 | - $excerpt, |
|
200 | - $matches, |
|
201 | - PREG_OFFSET_CAPTURE | PREG_SET_ORDER |
|
202 | - )) { |
|
203 | - foreach ($matches as $match) { |
|
204 | - if ($file_count >= $this->max_per_file) { |
|
205 | - continue; |
|
206 | - } |
|
207 | - $result_url = '/docs/' . $group_name . '/' . str_replace('.md', '', $file); |
|
208 | - |
|
209 | - foreach ($this->doc_folders as $alias => $folder) { |
|
210 | - $result_url = str_replace($folder, $alias, $result_url); |
|
211 | - } |
|
212 | - |
|
213 | - $results[] = [ |
|
214 | - 'title' => $this->extractTitle($excerpt, $file), |
|
215 | - 'file' => $folder . '/' . $file, |
|
216 | - 'url' => $result_url, |
|
217 | - 'extract' => $this->buildExtract($excerpt, $term, $match[0][0]) |
|
218 | - ]; |
|
219 | - |
|
220 | - $file_count++; |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - return $results; |
|
226 | - } |
|
227 | - |
|
228 | - //-------------------------------------------------------------------- |
|
229 | - |
|
230 | - /** |
|
231 | - * Stores the name of the callback method to run to convert the source |
|
232 | - * files to viewable files. By default, this should be used to register |
|
233 | - * a Mardown Extended formatter with the system, but could be used to |
|
234 | - * extend the |
|
235 | - * |
|
236 | - * @param string $callback_name |
|
237 | - * @param bool $cascade // If FALSE the formatting of a component ends here. If TRUE, will be passed to next formatter. |
|
238 | - * @return $this |
|
239 | - */ |
|
240 | - public function registerFormatter($callback_name = '', $cascade = false) |
|
241 | - { |
|
242 | - if (empty($callback_name)) return; |
|
243 | - |
|
244 | - $this->formatters[] = array($callback_name => $cascade); |
|
245 | - |
|
246 | - return $this; |
|
247 | - } |
|
248 | - |
|
249 | - //-------------------------------------------------------------------- |
|
250 | - |
|
251 | - /** |
|
252 | - * Runs the text through the registered formatters. |
|
253 | - * |
|
254 | - * @param $str |
|
255 | - * @return mixed |
|
256 | - */ |
|
257 | - public function format($str) |
|
258 | - { |
|
259 | - if (! is_array($this->formatters)) return $str; |
|
260 | - |
|
261 | - foreach ($this->formatters as $formatter) { |
|
262 | - $method = key($formatter); |
|
263 | - $cascade = $formatter[$method]; |
|
264 | - |
|
265 | - $str = call_user_func($method, $str); |
|
266 | - |
|
267 | - if (! $cascade) return $str; |
|
268 | - } |
|
269 | - |
|
270 | - return $str; |
|
271 | - } |
|
272 | - |
|
273 | - //-------------------------------------------------------------------- |
|
274 | - |
|
275 | - |
|
276 | - //-------------------------------------------------------------------- |
|
277 | - // Protected Methods |
|
278 | - //-------------------------------------------------------------------- |
|
279 | - |
|
280 | - /** |
|
281 | - * Converts an array generated by directory_map into a flat array of |
|
282 | - * folders, removing any nested folders and adding them to the path. |
|
283 | - * |
|
284 | - * @param $map |
|
285 | - * @param $prefix Used to recursively add the folder name... |
|
286 | - * @return mixed |
|
287 | - */ |
|
288 | - protected function flattenMap($map, $prefix = '') |
|
289 | - { |
|
290 | - if (! is_array($map) || ! count($map)) { |
|
291 | - return $map; |
|
292 | - } |
|
293 | - |
|
294 | - $return = []; |
|
295 | - |
|
296 | - foreach ($map as $folder => $files) { |
|
297 | - |
|
298 | - // If it's a folder name and an array of files |
|
299 | - // then call this method recursively to flatten it out. |
|
300 | - if (is_array($files)) { |
|
301 | - $return = array_merge($return, $this->flattenMap($files, $prefix . $folder)); |
|
302 | - continue; |
|
303 | - } |
|
304 | - |
|
305 | - // Else, add our prefix (if any) to the filename... |
|
306 | - $return[] = $prefix . $files; |
|
307 | - } |
|
308 | - |
|
309 | - return $return; |
|
310 | - } |
|
311 | - |
|
312 | - //-------------------------------------------------------------------- |
|
313 | - |
|
314 | - /** |
|
315 | - * Handles extracting the text surrounding our match and basic match formatting. |
|
316 | - * |
|
317 | - * @param $excerpt |
|
318 | - * @param $term |
|
319 | - * @param $match_string |
|
320 | - * |
|
321 | - * @return string |
|
322 | - */ |
|
323 | - protected function buildExtract($excerpt, $term, $match_string) |
|
324 | - { |
|
325 | - // Find the character positions within the string that our match was found at. |
|
326 | - // That way we'll know from what positions before and after this we want to grab it in. |
|
327 | - $start_offset = stripos($excerpt, $match_string); |
|
328 | - |
|
329 | - // Modify the start and end positions based on $this->excerpt_length / 2. |
|
330 | - $buffer = floor($this->excerpt_length / 2); |
|
331 | - |
|
332 | - // Adjust our start position |
|
333 | - $start_offset = $start_offset - $buffer; |
|
334 | - if ($start_offset < 0) { |
|
335 | - $start_offset = 0; |
|
336 | - } |
|
337 | - |
|
338 | - $extract = substr($excerpt, $start_offset); |
|
339 | - |
|
340 | - $extract = strip_tags($this->format($extract)); |
|
341 | - |
|
342 | - $extract = $this->firstXWords($extract, $this->excerpt_length); |
|
343 | - |
|
344 | - // Wrap the search term in a span we can style. |
|
345 | - $extract = str_ireplace($term, '<span class="term-hilight">' . $term . '</span>', $extract); |
|
346 | - |
|
347 | - return $extract; |
|
348 | - } |
|
349 | - |
|
350 | - //-------------------------------------------------------------------- |
|
351 | - |
|
352 | - /** |
|
353 | - * Extracts the title from a bit of markdown formatted text. If it doesn't |
|
354 | - * have an h1 or h2, then it uses the filename. |
|
355 | - * |
|
356 | - * @param $excerpt |
|
357 | - * @param $file |
|
358 | - * @return string |
|
359 | - */ |
|
360 | - protected function extractTitle($excerpt, $file) |
|
361 | - { |
|
362 | - $title = ''; |
|
363 | - |
|
364 | - // Easiest to work if this is split into lines. |
|
365 | - $lines = explode("\n", $excerpt); |
|
366 | - |
|
367 | - if (is_array($lines) && count($lines)) { |
|
368 | - foreach ($lines as $line) { |
|
369 | - if (strpos($line, '# ') === 0 || strpos($line, '## ') === 0) { |
|
370 | - $title = trim(str_replace('#', '', $line)); |
|
371 | - break; |
|
372 | - } |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - // If it's empty, we'll use the filename. |
|
377 | - if (empty($title)) { |
|
378 | - $title = str_replace('_', ' ', $file); |
|
379 | - $title = str_replace('.md', ' ', $title); |
|
380 | - $title = ucwords($title); |
|
381 | - } |
|
382 | - |
|
383 | - return $title; |
|
384 | - } |
|
385 | - //-------------------------------------------------------------------- |
|
386 | - |
|
387 | - /** |
|
388 | - * Create a Directory Map |
|
389 | - * |
|
390 | - * Reads the specified directory and builds an array |
|
391 | - * representation of it. Sub-folders contained with the |
|
392 | - * directory will be mapped as well. |
|
393 | - * |
|
394 | - * @param string $source_dir Path to source |
|
395 | - * @param int $directory_depth Depth of directories to traverse |
|
396 | - * (0 = fully recursive, 1 = current dir, etc) |
|
397 | - * @param bool $hidden Whether to show hidden files |
|
398 | - * @return array |
|
399 | - */ |
|
400 | - protected function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) |
|
401 | - { |
|
402 | - if ($fp = @opendir($source_dir)) { |
|
403 | - $filedata = array(); |
|
404 | - $new_depth = $directory_depth - 1; |
|
405 | - $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
406 | - |
|
407 | - while (FALSE !== ($file = readdir($fp))) { |
|
408 | - // Remove '.', '..', and hidden files [optional] |
|
409 | - if ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.')) { |
|
410 | - continue; |
|
411 | - } |
|
412 | - |
|
413 | - is_dir($source_dir . $file) && $file .= DIRECTORY_SEPARATOR; |
|
414 | - |
|
415 | - if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir . $file)) |
|
416 | - { |
|
417 | - $filedata[$file] = $this->directory_map($source_dir . $file, $new_depth, $hidden); |
|
418 | - } else |
|
419 | - { |
|
420 | - // Replace the directory separator here with a forward slash since |
|
421 | - // Windows uses backward slashes and not all browsers will auto-replace |
|
422 | - // those slashes in URLs. |
|
423 | - $filedata[] = str_replace(DIRECTORY_SEPARATOR, '/', $file); |
|
424 | - } |
|
425 | - } |
|
426 | - |
|
427 | - closedir($fp); |
|
428 | - return $filedata; |
|
429 | - } |
|
430 | - |
|
431 | - return FALSE; |
|
432 | - } |
|
433 | - |
|
434 | - //-------------------------------------------------------------------- |
|
435 | - |
|
436 | - /** |
|
437 | - * Gets the first 'X' words of a string. |
|
438 | - * |
|
439 | - * @param $str |
|
440 | - * @param int $wordCount |
|
441 | - * @return string |
|
442 | - */ |
|
443 | - protected function firstXWords($str, $wordCount = 10) |
|
444 | - { |
|
445 | - return implode( |
|
446 | - '', |
|
447 | - array_slice( |
|
448 | - preg_split( |
|
449 | - '/([\s,\.;\?\!]+)/', |
|
450 | - $str, |
|
451 | - $wordCount * 2 + 1, |
|
452 | - PREG_SPLIT_DELIM_CAPTURE |
|
453 | - ), |
|
454 | - 0, |
|
455 | - $wordCount * 2 - 1 |
|
456 | - ) |
|
457 | - ); |
|
458 | - } |
|
459 | - |
|
460 | - //-------------------------------------------------------------------- |
|
46 | + /** |
|
47 | + * Minimum characters that can be submitted for a search. |
|
48 | + * |
|
49 | + * @var int |
|
50 | + */ |
|
51 | + protected $min_chars = 3; |
|
52 | + |
|
53 | + /** |
|
54 | + * Maximum characters that can be submitted for a search. |
|
55 | + * |
|
56 | + * @var int |
|
57 | + */ |
|
58 | + protected $max_chars = 30; |
|
59 | + |
|
60 | + /** |
|
61 | + * Valid file extensions we can search in. |
|
62 | + * |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + protected $allowed_file_types = 'html|htm|php|php4|php5|txt|md'; |
|
66 | + |
|
67 | + /** |
|
68 | + * Which files should we skip over during our search? |
|
69 | + * |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $skip_files = ['.', '..', '_404.md', '_toc.ini']; |
|
73 | + |
|
74 | + /** |
|
75 | + * How much of each file should we read. |
|
76 | + * Use lower values for faster searches. |
|
77 | + * |
|
78 | + * @var int |
|
79 | + */ |
|
80 | + protected $byte_size = 51200; |
|
81 | + |
|
82 | + /** |
|
83 | + * Number of words long (approximately) |
|
84 | + * the result excerpt should be. |
|
85 | + * |
|
86 | + * @var int |
|
87 | + */ |
|
88 | + protected $excerpt_length = 60; |
|
89 | + |
|
90 | + /** |
|
91 | + * The maximum number of results allowed from a single file. |
|
92 | + * |
|
93 | + * @var int |
|
94 | + */ |
|
95 | + protected $max_per_file = 1; |
|
96 | + |
|
97 | + protected $doc_folders = array(); |
|
98 | + |
|
99 | + protected $formatters = array(); |
|
100 | + |
|
101 | + //-------------------------------------------------------------------- |
|
102 | + |
|
103 | + /** |
|
104 | + * The entry point for performing a search of the documentation. |
|
105 | + * |
|
106 | + * @param null $terms |
|
107 | + * @param array $folders |
|
108 | + * |
|
109 | + * @return array|null |
|
110 | + */ |
|
111 | + public function search($terms = null, $folders = []) |
|
112 | + { |
|
113 | + if (empty($terms) || empty($folders)) { |
|
114 | + return null; |
|
115 | + } |
|
116 | + |
|
117 | + $results = []; |
|
118 | + $this->doc_folders = $folders; |
|
119 | + |
|
120 | + foreach ($folders as $group => $folder) { |
|
121 | + $results = array_merge($results, $this->searchFolder($terms, $folder, $group)); |
|
122 | + } |
|
123 | + |
|
124 | + return $results; |
|
125 | + } |
|
126 | + |
|
127 | + //-------------------------------------------------------------------- |
|
128 | + |
|
129 | + //-------------------------------------------------------------------- |
|
130 | + // Private Methods |
|
131 | + //-------------------------------------------------------------------- |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * Searches a single directory worth of files. |
|
136 | + * |
|
137 | + * @param $term |
|
138 | + * @param $folder |
|
139 | + * @param $group_name |
|
140 | + * |
|
141 | + * @return array The results. |
|
142 | + */ |
|
143 | + protected function searchFolder($term, $folder, $group_name) |
|
144 | + { |
|
145 | + $results = []; |
|
146 | + |
|
147 | + $map = $this->directory_map($folder, 2); |
|
148 | + |
|
149 | + $map = $this->flattenMap($map); |
|
150 | + |
|
151 | + // Make sure we have something to work with. |
|
152 | + if (! is_array($map) || (is_array($map) && ! count($map))) { |
|
153 | + return []; |
|
154 | + } |
|
155 | + |
|
156 | + // Loop over each file and search the contents for our term. |
|
157 | + foreach ($map as $dir => $file) { |
|
158 | + $file_count = 0; |
|
159 | + |
|
160 | + if (in_array($file, $this->skip_files)) { |
|
161 | + continue; |
|
162 | + } |
|
163 | + |
|
164 | + // Is it a folder? |
|
165 | + if (is_array($file) && count($file)) { |
|
166 | + $results = array_merge($results, $this->searchFolder($term, $folder . '/' . $dir, $group_name)); |
|
167 | + continue; |
|
168 | + } |
|
169 | + |
|
170 | + // Make sure it's the right file type... |
|
171 | + if (! preg_match("/({$this->allowed_file_types})/i", $file)) { |
|
172 | + continue; |
|
173 | + } |
|
174 | + |
|
175 | + $path = is_string($dir) ? $folder . '/' . $dir . '/' . $file : $folder . '/' . $file; |
|
176 | + $term_html = htmlentities($term); |
|
177 | + |
|
178 | + // Read in the file text |
|
179 | + $handle = fopen($path, 'r'); |
|
180 | + $text = fread($handle, $this->byte_size); |
|
181 | + |
|
182 | + // Do we have a match in here somewhere? |
|
183 | + $found = stristr($text, $term) || stristr($text, $term_html); |
|
184 | + |
|
185 | + if (! $found) { |
|
186 | + continue; |
|
187 | + } |
|
188 | + |
|
189 | + // Escape our terms to safely use in a preg_match |
|
190 | + $excerpt = strip_tags($text); |
|
191 | + $term = preg_quote($term); |
|
192 | + $term = str_replace("/", "\/", "{$term}"); |
|
193 | + $term_html = preg_quote($term_html); |
|
194 | + $term_html = str_replace("/", "\/", "{$term_html}"); |
|
195 | + |
|
196 | + // Add the item to our results with extracts. |
|
197 | + if (preg_match_all( |
|
198 | + "/((\s\S*){0,3})($term|$term_html)((\s?\S*){0,3})/i", |
|
199 | + $excerpt, |
|
200 | + $matches, |
|
201 | + PREG_OFFSET_CAPTURE | PREG_SET_ORDER |
|
202 | + )) { |
|
203 | + foreach ($matches as $match) { |
|
204 | + if ($file_count >= $this->max_per_file) { |
|
205 | + continue; |
|
206 | + } |
|
207 | + $result_url = '/docs/' . $group_name . '/' . str_replace('.md', '', $file); |
|
208 | + |
|
209 | + foreach ($this->doc_folders as $alias => $folder) { |
|
210 | + $result_url = str_replace($folder, $alias, $result_url); |
|
211 | + } |
|
212 | + |
|
213 | + $results[] = [ |
|
214 | + 'title' => $this->extractTitle($excerpt, $file), |
|
215 | + 'file' => $folder . '/' . $file, |
|
216 | + 'url' => $result_url, |
|
217 | + 'extract' => $this->buildExtract($excerpt, $term, $match[0][0]) |
|
218 | + ]; |
|
219 | + |
|
220 | + $file_count++; |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + return $results; |
|
226 | + } |
|
227 | + |
|
228 | + //-------------------------------------------------------------------- |
|
229 | + |
|
230 | + /** |
|
231 | + * Stores the name of the callback method to run to convert the source |
|
232 | + * files to viewable files. By default, this should be used to register |
|
233 | + * a Mardown Extended formatter with the system, but could be used to |
|
234 | + * extend the |
|
235 | + * |
|
236 | + * @param string $callback_name |
|
237 | + * @param bool $cascade // If FALSE the formatting of a component ends here. If TRUE, will be passed to next formatter. |
|
238 | + * @return $this |
|
239 | + */ |
|
240 | + public function registerFormatter($callback_name = '', $cascade = false) |
|
241 | + { |
|
242 | + if (empty($callback_name)) return; |
|
243 | + |
|
244 | + $this->formatters[] = array($callback_name => $cascade); |
|
245 | + |
|
246 | + return $this; |
|
247 | + } |
|
248 | + |
|
249 | + //-------------------------------------------------------------------- |
|
250 | + |
|
251 | + /** |
|
252 | + * Runs the text through the registered formatters. |
|
253 | + * |
|
254 | + * @param $str |
|
255 | + * @return mixed |
|
256 | + */ |
|
257 | + public function format($str) |
|
258 | + { |
|
259 | + if (! is_array($this->formatters)) return $str; |
|
260 | + |
|
261 | + foreach ($this->formatters as $formatter) { |
|
262 | + $method = key($formatter); |
|
263 | + $cascade = $formatter[$method]; |
|
264 | + |
|
265 | + $str = call_user_func($method, $str); |
|
266 | + |
|
267 | + if (! $cascade) return $str; |
|
268 | + } |
|
269 | + |
|
270 | + return $str; |
|
271 | + } |
|
272 | + |
|
273 | + //-------------------------------------------------------------------- |
|
274 | + |
|
275 | + |
|
276 | + //-------------------------------------------------------------------- |
|
277 | + // Protected Methods |
|
278 | + //-------------------------------------------------------------------- |
|
279 | + |
|
280 | + /** |
|
281 | + * Converts an array generated by directory_map into a flat array of |
|
282 | + * folders, removing any nested folders and adding them to the path. |
|
283 | + * |
|
284 | + * @param $map |
|
285 | + * @param $prefix Used to recursively add the folder name... |
|
286 | + * @return mixed |
|
287 | + */ |
|
288 | + protected function flattenMap($map, $prefix = '') |
|
289 | + { |
|
290 | + if (! is_array($map) || ! count($map)) { |
|
291 | + return $map; |
|
292 | + } |
|
293 | + |
|
294 | + $return = []; |
|
295 | + |
|
296 | + foreach ($map as $folder => $files) { |
|
297 | + |
|
298 | + // If it's a folder name and an array of files |
|
299 | + // then call this method recursively to flatten it out. |
|
300 | + if (is_array($files)) { |
|
301 | + $return = array_merge($return, $this->flattenMap($files, $prefix . $folder)); |
|
302 | + continue; |
|
303 | + } |
|
304 | + |
|
305 | + // Else, add our prefix (if any) to the filename... |
|
306 | + $return[] = $prefix . $files; |
|
307 | + } |
|
308 | + |
|
309 | + return $return; |
|
310 | + } |
|
311 | + |
|
312 | + //-------------------------------------------------------------------- |
|
313 | + |
|
314 | + /** |
|
315 | + * Handles extracting the text surrounding our match and basic match formatting. |
|
316 | + * |
|
317 | + * @param $excerpt |
|
318 | + * @param $term |
|
319 | + * @param $match_string |
|
320 | + * |
|
321 | + * @return string |
|
322 | + */ |
|
323 | + protected function buildExtract($excerpt, $term, $match_string) |
|
324 | + { |
|
325 | + // Find the character positions within the string that our match was found at. |
|
326 | + // That way we'll know from what positions before and after this we want to grab it in. |
|
327 | + $start_offset = stripos($excerpt, $match_string); |
|
328 | + |
|
329 | + // Modify the start and end positions based on $this->excerpt_length / 2. |
|
330 | + $buffer = floor($this->excerpt_length / 2); |
|
331 | + |
|
332 | + // Adjust our start position |
|
333 | + $start_offset = $start_offset - $buffer; |
|
334 | + if ($start_offset < 0) { |
|
335 | + $start_offset = 0; |
|
336 | + } |
|
337 | + |
|
338 | + $extract = substr($excerpt, $start_offset); |
|
339 | + |
|
340 | + $extract = strip_tags($this->format($extract)); |
|
341 | + |
|
342 | + $extract = $this->firstXWords($extract, $this->excerpt_length); |
|
343 | + |
|
344 | + // Wrap the search term in a span we can style. |
|
345 | + $extract = str_ireplace($term, '<span class="term-hilight">' . $term . '</span>', $extract); |
|
346 | + |
|
347 | + return $extract; |
|
348 | + } |
|
349 | + |
|
350 | + //-------------------------------------------------------------------- |
|
351 | + |
|
352 | + /** |
|
353 | + * Extracts the title from a bit of markdown formatted text. If it doesn't |
|
354 | + * have an h1 or h2, then it uses the filename. |
|
355 | + * |
|
356 | + * @param $excerpt |
|
357 | + * @param $file |
|
358 | + * @return string |
|
359 | + */ |
|
360 | + protected function extractTitle($excerpt, $file) |
|
361 | + { |
|
362 | + $title = ''; |
|
363 | + |
|
364 | + // Easiest to work if this is split into lines. |
|
365 | + $lines = explode("\n", $excerpt); |
|
366 | + |
|
367 | + if (is_array($lines) && count($lines)) { |
|
368 | + foreach ($lines as $line) { |
|
369 | + if (strpos($line, '# ') === 0 || strpos($line, '## ') === 0) { |
|
370 | + $title = trim(str_replace('#', '', $line)); |
|
371 | + break; |
|
372 | + } |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + // If it's empty, we'll use the filename. |
|
377 | + if (empty($title)) { |
|
378 | + $title = str_replace('_', ' ', $file); |
|
379 | + $title = str_replace('.md', ' ', $title); |
|
380 | + $title = ucwords($title); |
|
381 | + } |
|
382 | + |
|
383 | + return $title; |
|
384 | + } |
|
385 | + //-------------------------------------------------------------------- |
|
386 | + |
|
387 | + /** |
|
388 | + * Create a Directory Map |
|
389 | + * |
|
390 | + * Reads the specified directory and builds an array |
|
391 | + * representation of it. Sub-folders contained with the |
|
392 | + * directory will be mapped as well. |
|
393 | + * |
|
394 | + * @param string $source_dir Path to source |
|
395 | + * @param int $directory_depth Depth of directories to traverse |
|
396 | + * (0 = fully recursive, 1 = current dir, etc) |
|
397 | + * @param bool $hidden Whether to show hidden files |
|
398 | + * @return array |
|
399 | + */ |
|
400 | + protected function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) |
|
401 | + { |
|
402 | + if ($fp = @opendir($source_dir)) { |
|
403 | + $filedata = array(); |
|
404 | + $new_depth = $directory_depth - 1; |
|
405 | + $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
406 | + |
|
407 | + while (FALSE !== ($file = readdir($fp))) { |
|
408 | + // Remove '.', '..', and hidden files [optional] |
|
409 | + if ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.')) { |
|
410 | + continue; |
|
411 | + } |
|
412 | + |
|
413 | + is_dir($source_dir . $file) && $file .= DIRECTORY_SEPARATOR; |
|
414 | + |
|
415 | + if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir . $file)) |
|
416 | + { |
|
417 | + $filedata[$file] = $this->directory_map($source_dir . $file, $new_depth, $hidden); |
|
418 | + } else |
|
419 | + { |
|
420 | + // Replace the directory separator here with a forward slash since |
|
421 | + // Windows uses backward slashes and not all browsers will auto-replace |
|
422 | + // those slashes in URLs. |
|
423 | + $filedata[] = str_replace(DIRECTORY_SEPARATOR, '/', $file); |
|
424 | + } |
|
425 | + } |
|
426 | + |
|
427 | + closedir($fp); |
|
428 | + return $filedata; |
|
429 | + } |
|
430 | + |
|
431 | + return FALSE; |
|
432 | + } |
|
433 | + |
|
434 | + //-------------------------------------------------------------------- |
|
435 | + |
|
436 | + /** |
|
437 | + * Gets the first 'X' words of a string. |
|
438 | + * |
|
439 | + * @param $str |
|
440 | + * @param int $wordCount |
|
441 | + * @return string |
|
442 | + */ |
|
443 | + protected function firstXWords($str, $wordCount = 10) |
|
444 | + { |
|
445 | + return implode( |
|
446 | + '', |
|
447 | + array_slice( |
|
448 | + preg_split( |
|
449 | + '/([\s,\.;\?\!]+)/', |
|
450 | + $str, |
|
451 | + $wordCount * 2 + 1, |
|
452 | + PREG_SPLIT_DELIM_CAPTURE |
|
453 | + ), |
|
454 | + 0, |
|
455 | + $wordCount * 2 - 1 |
|
456 | + ) |
|
457 | + ); |
|
458 | + } |
|
459 | + |
|
460 | + //-------------------------------------------------------------------- |
|
461 | 461 | |
462 | 462 | } |