@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function setRealm($realm) |
| 76 | 76 | { |
| 77 | - $this->realm = $realm; |
|
| 77 | + $this->realm = $realm; |
|
| 78 | 78 | return $this; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | 'password' => $password |
| 117 | 117 | ]; |
| 118 | 118 | |
| 119 | - $user = $this->validate($data, true); |
|
| 119 | + $user = $this->validate($data, true); |
|
| 120 | 120 | |
| 121 | 121 | $this->user = $user; |
| 122 | 122 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | */ |
| 273 | 273 | public function checkIPBlacklist() |
| 274 | 274 | { |
| 275 | - $blacklist = explode(',', config_item('api.ip_blacklist')); |
|
| 275 | + $blacklist = explode(',', config_item('api.ip_blacklist')); |
|
| 276 | 276 | |
| 277 | 277 | array_walk($blacklist, function (&$item, $key) { |
| 278 | 278 | $item = trim($item); |
@@ -60,725 +60,725 @@ |
||
| 60 | 60 | class Builder implements DocBuilderInterface |
| 61 | 61 | { |
| 62 | 62 | |
| 63 | - protected $docs_ext = '.md'; |
|
| 64 | - |
|
| 65 | - protected $ignore_files = ['_404.md']; |
|
| 66 | - |
|
| 67 | - protected $doc_folders = []; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Stores the current folder alias, |
|
| 71 | - * once the file has been found. |
|
| 72 | - * |
|
| 73 | - * @var null |
|
| 74 | - */ |
|
| 75 | - protected $current_folder = null; |
|
| 76 | - |
|
| 77 | - protected $table_classes = 'table table-hover'; |
|
| 78 | - |
|
| 79 | - protected $apppath = ''; |
|
| 80 | - |
|
| 81 | - protected $formatters = []; |
|
| 82 | - |
|
| 83 | - protected $page_title = null; |
|
| 84 | - |
|
| 85 | - //-------------------------------------------------------------------- |
|
| 86 | - |
|
| 87 | - public function __construct($config = array()) |
|
| 88 | - { |
|
| 89 | - $this->apppath = ! empty($config['apppath']) ? rtrim($config['apppath'], '/') . '/' : ''; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - //-------------------------------------------------------------------- |
|
| 93 | - |
|
| 94 | - public function pageTitle() |
|
| 95 | - { |
|
| 96 | - return $this->page_title; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - //-------------------------------------------------------------------- |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Does the actual work of reading in and parsing the help file. |
|
| 105 | - * If a folder Nickname (see addDocFolder() ) is passed as the second parameter, |
|
| 106 | - * it will limit it's search to that single folder. If nothing is passed, it will |
|
| 107 | - * search through all of the folders in the order they were given to the library, |
|
| 108 | - * until it finds the first one. |
|
| 109 | - * |
|
| 110 | - * @param string $path The 'path' of the file (relative to the docs |
|
| 111 | - * folder. Usually from the URI) |
|
| 112 | - * @param string $restrictToFolder (Optional) The folder nickname |
|
| 113 | - * |
|
| 114 | - * @return string |
|
| 115 | - */ |
|
| 116 | - public function readPage($path, $restrictToFolder = null) |
|
| 117 | - { |
|
| 118 | - // Clean up our path |
|
| 119 | - $path = trim($path, '/ '); |
|
| 120 | - |
|
| 121 | - $content = $this->locateAndReadFile($path, $restrictToFolder); |
|
| 122 | - |
|
| 123 | - $content = $this->parse($content); |
|
| 124 | - |
|
| 125 | - return $content; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - //-------------------------------------------------------------------- |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Parses the contents. Currently runs through the Markdown Extended |
|
| 132 | - * parser to convert to HTML. |
|
| 133 | - * |
|
| 134 | - * @param $str |
|
| 135 | - * @return mixed |
|
| 136 | - */ |
|
| 137 | - public function parse($str) |
|
| 138 | - { |
|
| 139 | - return $this->format($str); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - //-------------------------------------------------------------------- |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Perform a few housekeeping tasks on a page, like rewriting URLs to full |
|
| 146 | - * URLs, not relative, ensuring they link correctly, etc. |
|
| 147 | - * |
|
| 148 | - * @param $content |
|
| 149 | - * @param null $site_url |
|
| 150 | - * @param null $current_url |
|
| 151 | - * @return string The post-processed HTML. |
|
| 152 | - */ |
|
| 153 | - public function postProcess($content, $site_url = null, $current_url = null) |
|
| 154 | - { |
|
| 155 | - if (empty($content)) { |
|
| 156 | - return $content; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - try { |
|
| 160 | - $xml = new \SimpleXMLElement('<?xml version="1.0" standalone="yes"?><div>' . $content . '</div>'); |
|
| 161 | - } catch (\Exception $e) { |
|
| 162 | - // SimpleXML barfed on us, so send back the un-modified content |
|
| 163 | - return $content; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // Prepare some things and cleanup others |
|
| 167 | - $groups = array_keys($this->doc_folders); |
|
| 168 | - $site_url = rtrim($site_url, '/') . '/'; |
|
| 169 | - $current_url = rtrim($current_url, '#/'); |
|
| 170 | - |
|
| 171 | - // Try to determine the current_url if one isn't set. |
|
| 172 | - if (empty($this->current_folder)) { |
|
| 173 | - $this->current_folder = $this->detectCurrentFolder($current_url, $groups); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /* |
|
| 63 | + protected $docs_ext = '.md'; |
|
| 64 | + |
|
| 65 | + protected $ignore_files = ['_404.md']; |
|
| 66 | + |
|
| 67 | + protected $doc_folders = []; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Stores the current folder alias, |
|
| 71 | + * once the file has been found. |
|
| 72 | + * |
|
| 73 | + * @var null |
|
| 74 | + */ |
|
| 75 | + protected $current_folder = null; |
|
| 76 | + |
|
| 77 | + protected $table_classes = 'table table-hover'; |
|
| 78 | + |
|
| 79 | + protected $apppath = ''; |
|
| 80 | + |
|
| 81 | + protected $formatters = []; |
|
| 82 | + |
|
| 83 | + protected $page_title = null; |
|
| 84 | + |
|
| 85 | + //-------------------------------------------------------------------- |
|
| 86 | + |
|
| 87 | + public function __construct($config = array()) |
|
| 88 | + { |
|
| 89 | + $this->apppath = ! empty($config['apppath']) ? rtrim($config['apppath'], '/') . '/' : ''; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + //-------------------------------------------------------------------- |
|
| 93 | + |
|
| 94 | + public function pageTitle() |
|
| 95 | + { |
|
| 96 | + return $this->page_title; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + //-------------------------------------------------------------------- |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Does the actual work of reading in and parsing the help file. |
|
| 105 | + * If a folder Nickname (see addDocFolder() ) is passed as the second parameter, |
|
| 106 | + * it will limit it's search to that single folder. If nothing is passed, it will |
|
| 107 | + * search through all of the folders in the order they were given to the library, |
|
| 108 | + * until it finds the first one. |
|
| 109 | + * |
|
| 110 | + * @param string $path The 'path' of the file (relative to the docs |
|
| 111 | + * folder. Usually from the URI) |
|
| 112 | + * @param string $restrictToFolder (Optional) The folder nickname |
|
| 113 | + * |
|
| 114 | + * @return string |
|
| 115 | + */ |
|
| 116 | + public function readPage($path, $restrictToFolder = null) |
|
| 117 | + { |
|
| 118 | + // Clean up our path |
|
| 119 | + $path = trim($path, '/ '); |
|
| 120 | + |
|
| 121 | + $content = $this->locateAndReadFile($path, $restrictToFolder); |
|
| 122 | + |
|
| 123 | + $content = $this->parse($content); |
|
| 124 | + |
|
| 125 | + return $content; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + //-------------------------------------------------------------------- |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Parses the contents. Currently runs through the Markdown Extended |
|
| 132 | + * parser to convert to HTML. |
|
| 133 | + * |
|
| 134 | + * @param $str |
|
| 135 | + * @return mixed |
|
| 136 | + */ |
|
| 137 | + public function parse($str) |
|
| 138 | + { |
|
| 139 | + return $this->format($str); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + //-------------------------------------------------------------------- |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Perform a few housekeeping tasks on a page, like rewriting URLs to full |
|
| 146 | + * URLs, not relative, ensuring they link correctly, etc. |
|
| 147 | + * |
|
| 148 | + * @param $content |
|
| 149 | + * @param null $site_url |
|
| 150 | + * @param null $current_url |
|
| 151 | + * @return string The post-processed HTML. |
|
| 152 | + */ |
|
| 153 | + public function postProcess($content, $site_url = null, $current_url = null) |
|
| 154 | + { |
|
| 155 | + if (empty($content)) { |
|
| 156 | + return $content; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + try { |
|
| 160 | + $xml = new \SimpleXMLElement('<?xml version="1.0" standalone="yes"?><div>' . $content . '</div>'); |
|
| 161 | + } catch (\Exception $e) { |
|
| 162 | + // SimpleXML barfed on us, so send back the un-modified content |
|
| 163 | + return $content; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // Prepare some things and cleanup others |
|
| 167 | + $groups = array_keys($this->doc_folders); |
|
| 168 | + $site_url = rtrim($site_url, '/') . '/'; |
|
| 169 | + $current_url = rtrim($current_url, '#/'); |
|
| 170 | + |
|
| 171 | + // Try to determine the current_url if one isn't set. |
|
| 172 | + if (empty($this->current_folder)) { |
|
| 173 | + $this->current_folder = $this->detectCurrentFolder($current_url, $groups); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /* |
|
| 177 | 177 | * Rewrite the URLs |
| 178 | 178 | */ |
| 179 | - foreach ($xml->xpath('//a') as $link) { |
|
| 180 | - $link = $this->reformatAnchor($link, $groups, $current_url, $site_url); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $content = $xml->asXML(); |
|
| 184 | - $content = trim(str_replace('<?xml version="1.0" standalone="yes"?>', '', $content)); |
|
| 185 | - |
|
| 186 | - // Clean up and style the tables |
|
| 187 | - $content = str_replace('<table>', '<table class="' . $this->table_classes . '">', $content); |
|
| 188 | - |
|
| 189 | - return $content; |
|
| 190 | - } |
|
| 191 | - //-------------------------------------------------------------------- |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Allows users to define the classes that are attached to |
|
| 195 | - * generated tables. |
|
| 196 | - * |
|
| 197 | - * @param null $classes |
|
| 198 | - * @return $this |
|
| 199 | - */ |
|
| 200 | - public function setTableClasses($classes = null) |
|
| 201 | - { |
|
| 202 | - $this->table_classes = $classes; |
|
| 203 | - |
|
| 204 | - return $this; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - //-------------------------------------------------------------------- |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Given the contents to render, will build a list of links for the sidebar |
|
| 211 | - * out of the headings in the file. |
|
| 212 | - * |
|
| 213 | - * Note: Will ONLY use h2 and h3 to build the links from. |
|
| 214 | - * |
|
| 215 | - * Note: The $content passed in WILL be modified by adding named anchors |
|
| 216 | - * that match up with the locations. |
|
| 217 | - * |
|
| 218 | - * @param string $content The HTML to analyse for headings. |
|
| 219 | - * @return string |
|
| 220 | - */ |
|
| 221 | - public function buildDocumentMap(&$content) |
|
| 222 | - { |
|
| 223 | - if (empty($content)) { |
|
| 224 | - return $content; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - // If $content already has a wrapping <div> and </div> tags, remove them, |
|
| 228 | - // since we'll replace them just below. |
|
| 229 | - if (strpos($content, '<div>') === 0) { |
|
| 230 | - $content = substr($content, 5); |
|
| 231 | - |
|
| 232 | - // Trailing div also? |
|
| 233 | - if (substr($content, -6) == '</div>') { |
|
| 234 | - $content = substr($content, 0, -6); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - try { |
|
| 239 | - $xml = new \SimpleXMLElement('<?xml version="1.0" standalone="yes"?><div>' . $content . '</div>'); |
|
| 240 | - } catch (\Exception $e) { |
|
| 241 | - // SimpleXML barfed on us, so send back the un-modified content |
|
| 242 | - return []; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - $map = []; |
|
| 246 | - list($map, $content) = $this->extractDocMapAndAddAnchors($content, $xml, $map); |
|
| 247 | - |
|
| 248 | - return $map; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - //-------------------------------------------------------------------- |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Stores the name of the callback method to run to convert the source |
|
| 255 | - * files to viewable files. By default, this should be used to register |
|
| 256 | - * a Mardown Extended formatter with the system, but could be used to |
|
| 257 | - * extend the |
|
| 258 | - * |
|
| 259 | - * @param string $callback |
|
| 260 | - * @param bool $cascade // If FALSE the formatting of a component ends here. If TRUE, will be passed to next formatter. |
|
| 261 | - * @return $this |
|
| 262 | - */ |
|
| 263 | - public function registerFormatter($callback = null, $cascade = false) |
|
| 264 | - { |
|
| 265 | - if (empty($callback)) return; |
|
| 266 | - |
|
| 267 | - $this->formatters[] = [ |
|
| 268 | - 'callable' => $callback, |
|
| 269 | - 'cascade' => (bool)$cascade |
|
| 270 | - ]; |
|
| 271 | - |
|
| 272 | - return $this; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - //-------------------------------------------------------------------- |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Runs the text through the registered formatters. |
|
| 279 | - * |
|
| 280 | - * @param $str |
|
| 281 | - * @return mixed |
|
| 282 | - */ |
|
| 283 | - public function format($str) |
|
| 284 | - { |
|
| 285 | - if (! is_array($this->formatters)) return $str; |
|
| 286 | - |
|
| 287 | - foreach ($this->formatters as $formatter) { |
|
| 288 | - $method = $formatter['callable']; |
|
| 289 | - $cascade = $formatter['cascade']; |
|
| 290 | - |
|
| 291 | - $str = call_user_func($method, $str); |
|
| 292 | - |
|
| 293 | - if (! $cascade) return $str; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - return $str; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - //-------------------------------------------------------------------- |
|
| 300 | - |
|
| 301 | - //-------------------------------------------------------------------- |
|
| 302 | - // Table of Contents methods |
|
| 303 | - //-------------------------------------------------------------------- |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Retrieves the list of files in a folder and preps the name and filename |
|
| 307 | - * so it's ready for creating the HTML. |
|
| 308 | - * |
|
| 309 | - * @param String $folder The path to the folder to retrieve. |
|
| 310 | - * |
|
| 311 | - * @return Array An associative array @see parse_ini_file for format |
|
| 312 | - * details. |
|
| 313 | - */ |
|
| 314 | - public function buildTOC($folder) |
|
| 315 | - { |
|
| 316 | - // If the toc file exists in the folder, use it to build the links. |
|
| 317 | - if (is_file("{$folder}/_toc.ini")) { |
|
| 318 | - $toc = parse_ini_file("{$folder}/_toc.ini", true); |
|
| 319 | - return $this->columnizeTOC($toc); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // If the toc file does not exist, build the links by listing the files |
|
| 323 | - // in the directory (and any sub-directories) |
|
| 324 | - $map = $this->directory_map($folder); |
|
| 325 | - |
|
| 326 | - // If directory_map can not open the directory or find any files inside |
|
| 327 | - // the directory, return an empty array. |
|
| 328 | - if (empty($map)) { |
|
| 329 | - return []; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - // If these docs are located in the /application/docs or /bonfire/docs |
|
| 333 | - // directory, just use $this->current_group for the root. |
|
| 334 | - // Module docs need $this->current_group and $type. |
|
| 335 | - $tocRoot = $this->current_folder; |
|
| 336 | - if ($this->current_folder != strtolower($folder)) { |
|
| 337 | - $tocRoot .= '/' . strtolower($folder); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - $toc = []; |
|
| 341 | - foreach ($map as $files) { |
|
| 342 | - // If $files isn't an array, then make it one so that all situations |
|
| 343 | - // may be dealt with cleanly. |
|
| 344 | - if (! is_array($files)) { |
|
| 345 | - $files = [$files]; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - foreach ($files as $file) { |
|
| 349 | - if (in_array($file, $this->ignore_files)) { |
|
| 350 | - continue; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // The title for the index is the passed $type. Otherwise, |
|
| 354 | - // build the title from the file's name. |
|
| 355 | - if (strpos($file, 'index') === false) { |
|
| 356 | - $title = str_replace($this->docs_ext, '', $file); |
|
| 357 | - $title = str_replace('_', ' ', $title); |
|
| 358 | - $title = ucwords($title); |
|
| 359 | - |
|
| 360 | - $toc["{$tocRoot}/{$file}"] = $title; |
|
| 361 | - } else { |
|
| 362 | - $toc[$tocRoot] = $type; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - $toc = $this->columnizeTOC($toc); |
|
| 368 | - |
|
| 369 | - return $toc; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - //-------------------------------------------------------------------- |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Sorts the passed TOC array into columns of as close to equal length |
|
| 376 | - * as we can get it. |
|
| 377 | - * |
|
| 378 | - * @param $toc |
|
| 379 | - * @return array |
|
| 380 | - */ |
|
| 381 | - protected function columnizeTOC($toc) |
|
| 382 | - { |
|
| 383 | - $section_count = count($toc); |
|
| 384 | - |
|
| 385 | - // First - determine the size of each 'section'. |
|
| 386 | - $sizes = []; |
|
| 387 | - |
|
| 388 | - foreach ($toc as $section => $chapters) { |
|
| 389 | - $sizes[] = count($chapters); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - $column_avg = (int)round(array_sum($sizes) / $section_count); |
|
| 393 | - |
|
| 394 | - // Split things into 4 columns of approximately equal size. |
|
| 395 | - // If we only have 4 columns (or less), then make sure to |
|
| 396 | - // deal with that also. |
|
| 397 | - $columns = []; |
|
| 398 | - |
|
| 399 | - $current_column = 0; |
|
| 400 | - $current_column_count = 0; |
|
| 401 | - $keys = array_keys($toc); |
|
| 402 | - |
|
| 403 | - for ($i = 0; $i <= $section_count; $i++) { |
|
| 404 | - if (! isset($keys[$i])) { |
|
| 405 | - continue; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - $section = array_shift($toc); |
|
| 409 | - |
|
| 410 | - // Can we stay in this column? |
|
| 411 | - if ($current_column_count <= $column_avg && $section_count > 4) { |
|
| 412 | - // Don't forget to account for the heading also. |
|
| 413 | - $current_column_count += count($section) + 1; |
|
| 414 | - } else { |
|
| 415 | - $current_column_count = 0; |
|
| 416 | - $current_column++; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - $columns[$current_column][$keys[$i]] = $section; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - return $columns; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - //-------------------------------------------------------------------- |
|
| 426 | - |
|
| 427 | - //-------------------------------------------------------------------- |
|
| 428 | - // Folder Methods |
|
| 429 | - //-------------------------------------------------------------------- |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Returns the current docFolders array. |
|
| 433 | - * |
|
| 434 | - * @return array |
|
| 435 | - */ |
|
| 436 | - public function docFolders() |
|
| 437 | - { |
|
| 438 | - return $this->doc_folders; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - //-------------------------------------------------------------------- |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Registers a path to be used when searching for documentation files. |
|
| 445 | - * |
|
| 446 | - * @param $name A nickname to reference it by later. |
|
| 447 | - * @param $path The server path to the folder. |
|
| 448 | - * @return $this |
|
| 449 | - */ |
|
| 450 | - public function addDocFolder($name, $path) |
|
| 451 | - { |
|
| 452 | - // Standardize the path |
|
| 453 | - $path = realpath($path) . '/'; |
|
| 454 | - |
|
| 455 | - // realpath will return FALSE if the path doesn't exist |
|
| 456 | - // or the script doesn't have access to it. |
|
| 457 | - if (! $path || $path == '/') { |
|
| 458 | - return $this; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - $name = strtolower($name); |
|
| 462 | - |
|
| 463 | - $this->doc_folders[$name] = $path; |
|
| 464 | - |
|
| 465 | - return $this; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - //-------------------------------------------------------------------- |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Removes a folder from the folders we scan for documentation files |
|
| 472 | - * within. |
|
| 473 | - * |
|
| 474 | - * @param $name |
|
| 475 | - * @return $this |
|
| 476 | - */ |
|
| 477 | - public function removeDocFolder($name) |
|
| 478 | - { |
|
| 479 | - $name = strtolower($name); |
|
| 480 | - |
|
| 481 | - if (isset($this->doc_folders[$name])) { |
|
| 482 | - unset($this->doc_folders[$name]); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - return $this; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - //-------------------------------------------------------------------- |
|
| 489 | - |
|
| 490 | - //-------------------------------------------------------------------- |
|
| 491 | - // Private Methods |
|
| 492 | - //-------------------------------------------------------------------- |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Analyzes the passed in current url string and checks against |
|
| 496 | - * a list of groups to determine what the current group is. |
|
| 497 | - * |
|
| 498 | - * @param $current_url |
|
| 499 | - * @param $groups |
|
| 500 | - * @return string |
|
| 501 | - */ |
|
| 502 | - protected function detectCurrentFolder($current_url, $groups = []) |
|
| 503 | - { |
|
| 504 | - if (! is_array($groups)) { |
|
| 505 | - return null; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - $segments = explode('/', $current_url); |
|
| 509 | - |
|
| 510 | - // We start from the back of the array since |
|
| 511 | - // that's most likely to be close to the end. |
|
| 512 | - $segments = array_reverse($segments); |
|
| 513 | - |
|
| 514 | - foreach ($segments as $segment) { |
|
| 515 | - foreach ($groups as $group) { |
|
| 516 | - if (strtolower($group) == strtolower($segment)) { |
|
| 517 | - return $group; |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - // Nothing found? |
|
| 523 | - return null; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - //-------------------------------------------------------------------- |
|
| 527 | - |
|
| 528 | - //-------------------------------------------------------------------- |
|
| 529 | - // Private Methods |
|
| 530 | - //-------------------------------------------------------------------- |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Locates the file on disk and reads the contents into a single string. |
|
| 534 | - * |
|
| 535 | - * If a folder Nickname (see addDocFolder() ) is passed as the second parameter, |
|
| 536 | - * it will limit it's search to that single folder. If nothing is passed, it will |
|
| 537 | - * search through all of the folders in the order they were given to the library, |
|
| 538 | - * until it finds the first one. |
|
| 539 | - * |
|
| 540 | - * @param string $path The 'path' of the file (relative to the docs |
|
| 541 | - * folder. Usually from the URI) |
|
| 542 | - * @param string $restrictToFolder (Optional) The nickname of one of the |
|
| 543 | - * folders to restrict the search to. |
|
| 544 | - * |
|
| 545 | - * @throws RuntimeException |
|
| 546 | - * @return null|string |
|
| 547 | - */ |
|
| 548 | - private function locateAndReadFile($path, $restrictToFolder = null) |
|
| 549 | - { |
|
| 550 | - $folders = $this->doc_folders; |
|
| 551 | - |
|
| 552 | - if (! is_null($restrictToFolder)) { |
|
| 553 | - // Make sure the folder exists |
|
| 554 | - if (! is_null($restrictToFolder) && ! isset($this->doc_folders[$restrictToFolder])) { |
|
| 555 | - throw new \RuntimeException('You must add the docs folder that you wish to find docs from.'); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - $folders = [$this->doc_folders[$restrictToFolder]]; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - foreach ($folders as $alias => $folder) { |
|
| 562 | - if (file_exists($folder . $path . $this->docs_ext)) { |
|
| 563 | - // Store the alias so we know which folder we're in. |
|
| 564 | - $this->current_folder = $alias; |
|
| 565 | - |
|
| 566 | - return file_get_contents($folder . $path . $this->docs_ext); |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - return null; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - //-------------------------------------------------------------------- |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Re-formats the passed in link. |
|
| 577 | - * |
|
| 578 | - * @param $link |
|
| 579 | - * @param $current_url |
|
| 580 | - * @param $site_url |
|
| 581 | - * @return mixed |
|
| 582 | - */ |
|
| 583 | - private function reformatAnchor($link, $groups, $current_url, $site_url) |
|
| 584 | - { |
|
| 585 | - // Grab the href value. |
|
| 586 | - $href = $link->attributes()->href; |
|
| 587 | - |
|
| 588 | - // If the href is null, it's probably a named anchor with no content. |
|
| 589 | - if (! $href) { |
|
| 590 | - // Make sure it has an href, else the XML will not close this |
|
| 591 | - // tag correctly. |
|
| 592 | - $link['href'] = ' '; |
|
| 593 | - |
|
| 594 | - return $link; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - // Remove any trailing # signs |
|
| 598 | - $href = rtrim($href, '# '); |
|
| 599 | - |
|
| 600 | - // If the href starts with #, then attach the current_url to it |
|
| 601 | - if ($href != '' && substr_compare($href, '#', 0, 1) === 0) { |
|
| 602 | - $link['href'] = $current_url . $href; |
|
| 603 | - |
|
| 604 | - return $link; |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - // If it's a full external path, go on... |
|
| 608 | - if ((strpos($href, 'http://') !== false || strpos($href, 'https://') !== false) && |
|
| 609 | - strpos($href, $site_url) === false |
|
| 610 | - ) { |
|
| 611 | - $link['target'] = "_blank"; |
|
| 612 | - return $link; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - // If it's a full local path, get rid of it. |
|
| 616 | - if (strpos($href, $site_url) !== false) { |
|
| 617 | - $href = str_replace($site_url, '', $href); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - // Strip out some unnecessary items, just in case they're there. |
|
| 621 | - if (substr($href, 0, strlen('docs/')) == 'docs/') { |
|
| 622 | - $href = substr($href, strlen('docs/')); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - // This includes 'bonfire/' if it was missed during the conversion. |
|
| 626 | - if (substr($href, 0, strlen('bonfire/')) == 'bonfire/') { |
|
| 627 | - $href = substr($href, strlen('bonfire/')); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - // If another 'group' is not already defined at the head of the link |
|
| 631 | - // then add the current group to it. |
|
| 632 | - $group_found = false; |
|
| 633 | - |
|
| 634 | - foreach ($groups as $group) { |
|
| 635 | - if (strpos($href, $group) === 0) { |
|
| 636 | - $group_found = true; |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - if (! $group_found) { |
|
| 641 | - $href = $this->current_folder . '/' . $href; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - // Convert to full site_url |
|
| 645 | - if (strpos($href, 'http') !== 0) { |
|
| 646 | - $href = $site_url . 'docs/' . ltrim($href, '/ '); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - // Save the corrected href |
|
| 650 | - $link['href'] = $href; |
|
| 651 | - |
|
| 652 | - return $link; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - //-------------------------------------------------------------------- |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Creates a Document Map based on <h2> and <h3> tags. |
|
| 659 | - * Also adds named anchors into the $content so the map |
|
| 660 | - * can link to the content properly. |
|
| 661 | - * |
|
| 662 | - * @param $content |
|
| 663 | - * @param $xml |
|
| 664 | - * @param $map |
|
| 665 | - * @return array |
|
| 666 | - */ |
|
| 667 | - protected function extractDocMapAndAddAnchors(&$content, $xml, $map) |
|
| 668 | - { |
|
| 669 | - // Holds the current h2 we're processing |
|
| 670 | - $current_obj = []; |
|
| 671 | - |
|
| 672 | - $currentChild = 0; |
|
| 673 | - |
|
| 674 | - foreach ($xml->children() as $childType => $line) { |
|
| 675 | - $currentChild++; |
|
| 676 | - |
|
| 677 | - // If it's an h1 - take the first and make it |
|
| 678 | - // our page title. |
|
| 679 | - if ($childType == 'h1' && empty($this->page_title)) |
|
| 680 | - { |
|
| 681 | - $this->page_title = (string)$line; |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - // Make sure that our current object is |
|
| 685 | - // stored and reset. |
|
| 686 | - if ($childType == 'h1' || $childType == 'h2') { |
|
| 687 | - if (count($current_obj)) { |
|
| 688 | - $map[] = $current_obj; |
|
| 689 | - $current_obj = []; |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - if ($childType == 'h2') { |
|
| 694 | - $name = (string)$line; |
|
| 695 | - $link = strtolower(str_replace(' ', '_', (string)$line)); |
|
| 696 | - |
|
| 697 | - $current_obj['name'] = $name; |
|
| 698 | - $current_obj['link'] = '#' . $link; |
|
| 699 | - $current_obj['items'] = []; |
|
| 700 | - |
|
| 701 | - // Insert a named anchor into the $content |
|
| 702 | - $anchor = '<a name="' . $link . '" id="' . $link . '" ></a>'; |
|
| 703 | - |
|
| 704 | - $search = "<h2>{$name}</h2>"; |
|
| 705 | - |
|
| 706 | - $content = str_replace($search, $anchor . $search, $content); |
|
| 707 | - } elseif ($childType == 'h3') { |
|
| 708 | - // Make sure we have some place to store the items. |
|
| 709 | - if (! isset($current_obj['items'])) { |
|
| 710 | - $current_obj['items'] = []; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - $link = strtolower(str_replace(' ', '_', (string)$line)); |
|
| 714 | - $name = (string)$line; |
|
| 715 | - |
|
| 716 | - $current_obj['items'][] = [ |
|
| 717 | - 'name' => $name, |
|
| 718 | - 'link' => '#' . $link |
|
| 719 | - ]; |
|
| 720 | - |
|
| 721 | - // Insert a named anchor into the $content |
|
| 722 | - $anchor = '<a name="' . $link . '" id="' . $link . '" ></a>'; |
|
| 723 | - |
|
| 724 | - $search = "<h3>{$name}</h3>"; |
|
| 725 | - |
|
| 726 | - $content = str_replace($search, $anchor . $search, $content); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - // Is this the last element? Then close out our current object. |
|
| 730 | - if (count($xml) == $currentChild) { |
|
| 731 | - if (count($current_obj)) { |
|
| 732 | - $map[] = $current_obj; |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - return [$map, $content]; |
|
| 737 | - } |
|
| 738 | - //-------------------------------------------------------------------- |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * Create a Directory Map |
|
| 742 | - * |
|
| 743 | - * Reads the specified directory and builds an array |
|
| 744 | - * representation of it. Sub-folders contained with the |
|
| 745 | - * directory will be mapped as well. |
|
| 746 | - * |
|
| 747 | - * @param string $source_dir Path to source |
|
| 748 | - * @param int $directory_depth Depth of directories to traverse |
|
| 749 | - * (0 = fully recursive, 1 = current dir, etc) |
|
| 750 | - * @param bool $hidden Whether to show hidden files |
|
| 751 | - * @return array |
|
| 752 | - */ |
|
| 753 | - protected function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) |
|
| 754 | - { |
|
| 755 | - if ($fp = @opendir($source_dir)) { |
|
| 756 | - $filedata = array(); |
|
| 757 | - $new_depth = $directory_depth - 1; |
|
| 758 | - $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
| 759 | - |
|
| 760 | - while (FALSE !== ($file = readdir($fp))) { |
|
| 761 | - // Remove '.', '..', and hidden files [optional] |
|
| 762 | - if ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.')) { |
|
| 763 | - continue; |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - is_dir($source_dir . $file) && $file .= DIRECTORY_SEPARATOR; |
|
| 767 | - |
|
| 768 | - if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir . $file)) { |
|
| 769 | - $filedata[$file] = directory_map($source_dir . $file, $new_depth, $hidden); |
|
| 770 | - } else { |
|
| 771 | - $filedata[] = $file; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - closedir($fp); |
|
| 776 | - return $filedata; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - return FALSE; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - //-------------------------------------------------------------------- |
|
| 179 | + foreach ($xml->xpath('//a') as $link) { |
|
| 180 | + $link = $this->reformatAnchor($link, $groups, $current_url, $site_url); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $content = $xml->asXML(); |
|
| 184 | + $content = trim(str_replace('<?xml version="1.0" standalone="yes"?>', '', $content)); |
|
| 185 | + |
|
| 186 | + // Clean up and style the tables |
|
| 187 | + $content = str_replace('<table>', '<table class="' . $this->table_classes . '">', $content); |
|
| 188 | + |
|
| 189 | + return $content; |
|
| 190 | + } |
|
| 191 | + //-------------------------------------------------------------------- |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Allows users to define the classes that are attached to |
|
| 195 | + * generated tables. |
|
| 196 | + * |
|
| 197 | + * @param null $classes |
|
| 198 | + * @return $this |
|
| 199 | + */ |
|
| 200 | + public function setTableClasses($classes = null) |
|
| 201 | + { |
|
| 202 | + $this->table_classes = $classes; |
|
| 203 | + |
|
| 204 | + return $this; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + //-------------------------------------------------------------------- |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Given the contents to render, will build a list of links for the sidebar |
|
| 211 | + * out of the headings in the file. |
|
| 212 | + * |
|
| 213 | + * Note: Will ONLY use h2 and h3 to build the links from. |
|
| 214 | + * |
|
| 215 | + * Note: The $content passed in WILL be modified by adding named anchors |
|
| 216 | + * that match up with the locations. |
|
| 217 | + * |
|
| 218 | + * @param string $content The HTML to analyse for headings. |
|
| 219 | + * @return string |
|
| 220 | + */ |
|
| 221 | + public function buildDocumentMap(&$content) |
|
| 222 | + { |
|
| 223 | + if (empty($content)) { |
|
| 224 | + return $content; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + // If $content already has a wrapping <div> and </div> tags, remove them, |
|
| 228 | + // since we'll replace them just below. |
|
| 229 | + if (strpos($content, '<div>') === 0) { |
|
| 230 | + $content = substr($content, 5); |
|
| 231 | + |
|
| 232 | + // Trailing div also? |
|
| 233 | + if (substr($content, -6) == '</div>') { |
|
| 234 | + $content = substr($content, 0, -6); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + try { |
|
| 239 | + $xml = new \SimpleXMLElement('<?xml version="1.0" standalone="yes"?><div>' . $content . '</div>'); |
|
| 240 | + } catch (\Exception $e) { |
|
| 241 | + // SimpleXML barfed on us, so send back the un-modified content |
|
| 242 | + return []; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + $map = []; |
|
| 246 | + list($map, $content) = $this->extractDocMapAndAddAnchors($content, $xml, $map); |
|
| 247 | + |
|
| 248 | + return $map; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + //-------------------------------------------------------------------- |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Stores the name of the callback method to run to convert the source |
|
| 255 | + * files to viewable files. By default, this should be used to register |
|
| 256 | + * a Mardown Extended formatter with the system, but could be used to |
|
| 257 | + * extend the |
|
| 258 | + * |
|
| 259 | + * @param string $callback |
|
| 260 | + * @param bool $cascade // If FALSE the formatting of a component ends here. If TRUE, will be passed to next formatter. |
|
| 261 | + * @return $this |
|
| 262 | + */ |
|
| 263 | + public function registerFormatter($callback = null, $cascade = false) |
|
| 264 | + { |
|
| 265 | + if (empty($callback)) return; |
|
| 266 | + |
|
| 267 | + $this->formatters[] = [ |
|
| 268 | + 'callable' => $callback, |
|
| 269 | + 'cascade' => (bool)$cascade |
|
| 270 | + ]; |
|
| 271 | + |
|
| 272 | + return $this; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + //-------------------------------------------------------------------- |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Runs the text through the registered formatters. |
|
| 279 | + * |
|
| 280 | + * @param $str |
|
| 281 | + * @return mixed |
|
| 282 | + */ |
|
| 283 | + public function format($str) |
|
| 284 | + { |
|
| 285 | + if (! is_array($this->formatters)) return $str; |
|
| 286 | + |
|
| 287 | + foreach ($this->formatters as $formatter) { |
|
| 288 | + $method = $formatter['callable']; |
|
| 289 | + $cascade = $formatter['cascade']; |
|
| 290 | + |
|
| 291 | + $str = call_user_func($method, $str); |
|
| 292 | + |
|
| 293 | + if (! $cascade) return $str; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + return $str; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + //-------------------------------------------------------------------- |
|
| 300 | + |
|
| 301 | + //-------------------------------------------------------------------- |
|
| 302 | + // Table of Contents methods |
|
| 303 | + //-------------------------------------------------------------------- |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Retrieves the list of files in a folder and preps the name and filename |
|
| 307 | + * so it's ready for creating the HTML. |
|
| 308 | + * |
|
| 309 | + * @param String $folder The path to the folder to retrieve. |
|
| 310 | + * |
|
| 311 | + * @return Array An associative array @see parse_ini_file for format |
|
| 312 | + * details. |
|
| 313 | + */ |
|
| 314 | + public function buildTOC($folder) |
|
| 315 | + { |
|
| 316 | + // If the toc file exists in the folder, use it to build the links. |
|
| 317 | + if (is_file("{$folder}/_toc.ini")) { |
|
| 318 | + $toc = parse_ini_file("{$folder}/_toc.ini", true); |
|
| 319 | + return $this->columnizeTOC($toc); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // If the toc file does not exist, build the links by listing the files |
|
| 323 | + // in the directory (and any sub-directories) |
|
| 324 | + $map = $this->directory_map($folder); |
|
| 325 | + |
|
| 326 | + // If directory_map can not open the directory or find any files inside |
|
| 327 | + // the directory, return an empty array. |
|
| 328 | + if (empty($map)) { |
|
| 329 | + return []; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + // If these docs are located in the /application/docs or /bonfire/docs |
|
| 333 | + // directory, just use $this->current_group for the root. |
|
| 334 | + // Module docs need $this->current_group and $type. |
|
| 335 | + $tocRoot = $this->current_folder; |
|
| 336 | + if ($this->current_folder != strtolower($folder)) { |
|
| 337 | + $tocRoot .= '/' . strtolower($folder); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + $toc = []; |
|
| 341 | + foreach ($map as $files) { |
|
| 342 | + // If $files isn't an array, then make it one so that all situations |
|
| 343 | + // may be dealt with cleanly. |
|
| 344 | + if (! is_array($files)) { |
|
| 345 | + $files = [$files]; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + foreach ($files as $file) { |
|
| 349 | + if (in_array($file, $this->ignore_files)) { |
|
| 350 | + continue; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // The title for the index is the passed $type. Otherwise, |
|
| 354 | + // build the title from the file's name. |
|
| 355 | + if (strpos($file, 'index') === false) { |
|
| 356 | + $title = str_replace($this->docs_ext, '', $file); |
|
| 357 | + $title = str_replace('_', ' ', $title); |
|
| 358 | + $title = ucwords($title); |
|
| 359 | + |
|
| 360 | + $toc["{$tocRoot}/{$file}"] = $title; |
|
| 361 | + } else { |
|
| 362 | + $toc[$tocRoot] = $type; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + $toc = $this->columnizeTOC($toc); |
|
| 368 | + |
|
| 369 | + return $toc; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + //-------------------------------------------------------------------- |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Sorts the passed TOC array into columns of as close to equal length |
|
| 376 | + * as we can get it. |
|
| 377 | + * |
|
| 378 | + * @param $toc |
|
| 379 | + * @return array |
|
| 380 | + */ |
|
| 381 | + protected function columnizeTOC($toc) |
|
| 382 | + { |
|
| 383 | + $section_count = count($toc); |
|
| 384 | + |
|
| 385 | + // First - determine the size of each 'section'. |
|
| 386 | + $sizes = []; |
|
| 387 | + |
|
| 388 | + foreach ($toc as $section => $chapters) { |
|
| 389 | + $sizes[] = count($chapters); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + $column_avg = (int)round(array_sum($sizes) / $section_count); |
|
| 393 | + |
|
| 394 | + // Split things into 4 columns of approximately equal size. |
|
| 395 | + // If we only have 4 columns (or less), then make sure to |
|
| 396 | + // deal with that also. |
|
| 397 | + $columns = []; |
|
| 398 | + |
|
| 399 | + $current_column = 0; |
|
| 400 | + $current_column_count = 0; |
|
| 401 | + $keys = array_keys($toc); |
|
| 402 | + |
|
| 403 | + for ($i = 0; $i <= $section_count; $i++) { |
|
| 404 | + if (! isset($keys[$i])) { |
|
| 405 | + continue; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + $section = array_shift($toc); |
|
| 409 | + |
|
| 410 | + // Can we stay in this column? |
|
| 411 | + if ($current_column_count <= $column_avg && $section_count > 4) { |
|
| 412 | + // Don't forget to account for the heading also. |
|
| 413 | + $current_column_count += count($section) + 1; |
|
| 414 | + } else { |
|
| 415 | + $current_column_count = 0; |
|
| 416 | + $current_column++; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + $columns[$current_column][$keys[$i]] = $section; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + return $columns; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + //-------------------------------------------------------------------- |
|
| 426 | + |
|
| 427 | + //-------------------------------------------------------------------- |
|
| 428 | + // Folder Methods |
|
| 429 | + //-------------------------------------------------------------------- |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Returns the current docFolders array. |
|
| 433 | + * |
|
| 434 | + * @return array |
|
| 435 | + */ |
|
| 436 | + public function docFolders() |
|
| 437 | + { |
|
| 438 | + return $this->doc_folders; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + //-------------------------------------------------------------------- |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Registers a path to be used when searching for documentation files. |
|
| 445 | + * |
|
| 446 | + * @param $name A nickname to reference it by later. |
|
| 447 | + * @param $path The server path to the folder. |
|
| 448 | + * @return $this |
|
| 449 | + */ |
|
| 450 | + public function addDocFolder($name, $path) |
|
| 451 | + { |
|
| 452 | + // Standardize the path |
|
| 453 | + $path = realpath($path) . '/'; |
|
| 454 | + |
|
| 455 | + // realpath will return FALSE if the path doesn't exist |
|
| 456 | + // or the script doesn't have access to it. |
|
| 457 | + if (! $path || $path == '/') { |
|
| 458 | + return $this; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + $name = strtolower($name); |
|
| 462 | + |
|
| 463 | + $this->doc_folders[$name] = $path; |
|
| 464 | + |
|
| 465 | + return $this; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + //-------------------------------------------------------------------- |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Removes a folder from the folders we scan for documentation files |
|
| 472 | + * within. |
|
| 473 | + * |
|
| 474 | + * @param $name |
|
| 475 | + * @return $this |
|
| 476 | + */ |
|
| 477 | + public function removeDocFolder($name) |
|
| 478 | + { |
|
| 479 | + $name = strtolower($name); |
|
| 480 | + |
|
| 481 | + if (isset($this->doc_folders[$name])) { |
|
| 482 | + unset($this->doc_folders[$name]); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + return $this; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + //-------------------------------------------------------------------- |
|
| 489 | + |
|
| 490 | + //-------------------------------------------------------------------- |
|
| 491 | + // Private Methods |
|
| 492 | + //-------------------------------------------------------------------- |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Analyzes the passed in current url string and checks against |
|
| 496 | + * a list of groups to determine what the current group is. |
|
| 497 | + * |
|
| 498 | + * @param $current_url |
|
| 499 | + * @param $groups |
|
| 500 | + * @return string |
|
| 501 | + */ |
|
| 502 | + protected function detectCurrentFolder($current_url, $groups = []) |
|
| 503 | + { |
|
| 504 | + if (! is_array($groups)) { |
|
| 505 | + return null; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + $segments = explode('/', $current_url); |
|
| 509 | + |
|
| 510 | + // We start from the back of the array since |
|
| 511 | + // that's most likely to be close to the end. |
|
| 512 | + $segments = array_reverse($segments); |
|
| 513 | + |
|
| 514 | + foreach ($segments as $segment) { |
|
| 515 | + foreach ($groups as $group) { |
|
| 516 | + if (strtolower($group) == strtolower($segment)) { |
|
| 517 | + return $group; |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + // Nothing found? |
|
| 523 | + return null; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + //-------------------------------------------------------------------- |
|
| 527 | + |
|
| 528 | + //-------------------------------------------------------------------- |
|
| 529 | + // Private Methods |
|
| 530 | + //-------------------------------------------------------------------- |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Locates the file on disk and reads the contents into a single string. |
|
| 534 | + * |
|
| 535 | + * If a folder Nickname (see addDocFolder() ) is passed as the second parameter, |
|
| 536 | + * it will limit it's search to that single folder. If nothing is passed, it will |
|
| 537 | + * search through all of the folders in the order they were given to the library, |
|
| 538 | + * until it finds the first one. |
|
| 539 | + * |
|
| 540 | + * @param string $path The 'path' of the file (relative to the docs |
|
| 541 | + * folder. Usually from the URI) |
|
| 542 | + * @param string $restrictToFolder (Optional) The nickname of one of the |
|
| 543 | + * folders to restrict the search to. |
|
| 544 | + * |
|
| 545 | + * @throws RuntimeException |
|
| 546 | + * @return null|string |
|
| 547 | + */ |
|
| 548 | + private function locateAndReadFile($path, $restrictToFolder = null) |
|
| 549 | + { |
|
| 550 | + $folders = $this->doc_folders; |
|
| 551 | + |
|
| 552 | + if (! is_null($restrictToFolder)) { |
|
| 553 | + // Make sure the folder exists |
|
| 554 | + if (! is_null($restrictToFolder) && ! isset($this->doc_folders[$restrictToFolder])) { |
|
| 555 | + throw new \RuntimeException('You must add the docs folder that you wish to find docs from.'); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + $folders = [$this->doc_folders[$restrictToFolder]]; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + foreach ($folders as $alias => $folder) { |
|
| 562 | + if (file_exists($folder . $path . $this->docs_ext)) { |
|
| 563 | + // Store the alias so we know which folder we're in. |
|
| 564 | + $this->current_folder = $alias; |
|
| 565 | + |
|
| 566 | + return file_get_contents($folder . $path . $this->docs_ext); |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + return null; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + //-------------------------------------------------------------------- |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Re-formats the passed in link. |
|
| 577 | + * |
|
| 578 | + * @param $link |
|
| 579 | + * @param $current_url |
|
| 580 | + * @param $site_url |
|
| 581 | + * @return mixed |
|
| 582 | + */ |
|
| 583 | + private function reformatAnchor($link, $groups, $current_url, $site_url) |
|
| 584 | + { |
|
| 585 | + // Grab the href value. |
|
| 586 | + $href = $link->attributes()->href; |
|
| 587 | + |
|
| 588 | + // If the href is null, it's probably a named anchor with no content. |
|
| 589 | + if (! $href) { |
|
| 590 | + // Make sure it has an href, else the XML will not close this |
|
| 591 | + // tag correctly. |
|
| 592 | + $link['href'] = ' '; |
|
| 593 | + |
|
| 594 | + return $link; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + // Remove any trailing # signs |
|
| 598 | + $href = rtrim($href, '# '); |
|
| 599 | + |
|
| 600 | + // If the href starts with #, then attach the current_url to it |
|
| 601 | + if ($href != '' && substr_compare($href, '#', 0, 1) === 0) { |
|
| 602 | + $link['href'] = $current_url . $href; |
|
| 603 | + |
|
| 604 | + return $link; |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + // If it's a full external path, go on... |
|
| 608 | + if ((strpos($href, 'http://') !== false || strpos($href, 'https://') !== false) && |
|
| 609 | + strpos($href, $site_url) === false |
|
| 610 | + ) { |
|
| 611 | + $link['target'] = "_blank"; |
|
| 612 | + return $link; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + // If it's a full local path, get rid of it. |
|
| 616 | + if (strpos($href, $site_url) !== false) { |
|
| 617 | + $href = str_replace($site_url, '', $href); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + // Strip out some unnecessary items, just in case they're there. |
|
| 621 | + if (substr($href, 0, strlen('docs/')) == 'docs/') { |
|
| 622 | + $href = substr($href, strlen('docs/')); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + // This includes 'bonfire/' if it was missed during the conversion. |
|
| 626 | + if (substr($href, 0, strlen('bonfire/')) == 'bonfire/') { |
|
| 627 | + $href = substr($href, strlen('bonfire/')); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + // If another 'group' is not already defined at the head of the link |
|
| 631 | + // then add the current group to it. |
|
| 632 | + $group_found = false; |
|
| 633 | + |
|
| 634 | + foreach ($groups as $group) { |
|
| 635 | + if (strpos($href, $group) === 0) { |
|
| 636 | + $group_found = true; |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + if (! $group_found) { |
|
| 641 | + $href = $this->current_folder . '/' . $href; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + // Convert to full site_url |
|
| 645 | + if (strpos($href, 'http') !== 0) { |
|
| 646 | + $href = $site_url . 'docs/' . ltrim($href, '/ '); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + // Save the corrected href |
|
| 650 | + $link['href'] = $href; |
|
| 651 | + |
|
| 652 | + return $link; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + //-------------------------------------------------------------------- |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Creates a Document Map based on <h2> and <h3> tags. |
|
| 659 | + * Also adds named anchors into the $content so the map |
|
| 660 | + * can link to the content properly. |
|
| 661 | + * |
|
| 662 | + * @param $content |
|
| 663 | + * @param $xml |
|
| 664 | + * @param $map |
|
| 665 | + * @return array |
|
| 666 | + */ |
|
| 667 | + protected function extractDocMapAndAddAnchors(&$content, $xml, $map) |
|
| 668 | + { |
|
| 669 | + // Holds the current h2 we're processing |
|
| 670 | + $current_obj = []; |
|
| 671 | + |
|
| 672 | + $currentChild = 0; |
|
| 673 | + |
|
| 674 | + foreach ($xml->children() as $childType => $line) { |
|
| 675 | + $currentChild++; |
|
| 676 | + |
|
| 677 | + // If it's an h1 - take the first and make it |
|
| 678 | + // our page title. |
|
| 679 | + if ($childType == 'h1' && empty($this->page_title)) |
|
| 680 | + { |
|
| 681 | + $this->page_title = (string)$line; |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + // Make sure that our current object is |
|
| 685 | + // stored and reset. |
|
| 686 | + if ($childType == 'h1' || $childType == 'h2') { |
|
| 687 | + if (count($current_obj)) { |
|
| 688 | + $map[] = $current_obj; |
|
| 689 | + $current_obj = []; |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + if ($childType == 'h2') { |
|
| 694 | + $name = (string)$line; |
|
| 695 | + $link = strtolower(str_replace(' ', '_', (string)$line)); |
|
| 696 | + |
|
| 697 | + $current_obj['name'] = $name; |
|
| 698 | + $current_obj['link'] = '#' . $link; |
|
| 699 | + $current_obj['items'] = []; |
|
| 700 | + |
|
| 701 | + // Insert a named anchor into the $content |
|
| 702 | + $anchor = '<a name="' . $link . '" id="' . $link . '" ></a>'; |
|
| 703 | + |
|
| 704 | + $search = "<h2>{$name}</h2>"; |
|
| 705 | + |
|
| 706 | + $content = str_replace($search, $anchor . $search, $content); |
|
| 707 | + } elseif ($childType == 'h3') { |
|
| 708 | + // Make sure we have some place to store the items. |
|
| 709 | + if (! isset($current_obj['items'])) { |
|
| 710 | + $current_obj['items'] = []; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + $link = strtolower(str_replace(' ', '_', (string)$line)); |
|
| 714 | + $name = (string)$line; |
|
| 715 | + |
|
| 716 | + $current_obj['items'][] = [ |
|
| 717 | + 'name' => $name, |
|
| 718 | + 'link' => '#' . $link |
|
| 719 | + ]; |
|
| 720 | + |
|
| 721 | + // Insert a named anchor into the $content |
|
| 722 | + $anchor = '<a name="' . $link . '" id="' . $link . '" ></a>'; |
|
| 723 | + |
|
| 724 | + $search = "<h3>{$name}</h3>"; |
|
| 725 | + |
|
| 726 | + $content = str_replace($search, $anchor . $search, $content); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + // Is this the last element? Then close out our current object. |
|
| 730 | + if (count($xml) == $currentChild) { |
|
| 731 | + if (count($current_obj)) { |
|
| 732 | + $map[] = $current_obj; |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + return [$map, $content]; |
|
| 737 | + } |
|
| 738 | + //-------------------------------------------------------------------- |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * Create a Directory Map |
|
| 742 | + * |
|
| 743 | + * Reads the specified directory and builds an array |
|
| 744 | + * representation of it. Sub-folders contained with the |
|
| 745 | + * directory will be mapped as well. |
|
| 746 | + * |
|
| 747 | + * @param string $source_dir Path to source |
|
| 748 | + * @param int $directory_depth Depth of directories to traverse |
|
| 749 | + * (0 = fully recursive, 1 = current dir, etc) |
|
| 750 | + * @param bool $hidden Whether to show hidden files |
|
| 751 | + * @return array |
|
| 752 | + */ |
|
| 753 | + protected function directory_map($source_dir, $directory_depth = 0, $hidden = FALSE) |
|
| 754 | + { |
|
| 755 | + if ($fp = @opendir($source_dir)) { |
|
| 756 | + $filedata = array(); |
|
| 757 | + $new_depth = $directory_depth - 1; |
|
| 758 | + $source_dir = rtrim($source_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
| 759 | + |
|
| 760 | + while (FALSE !== ($file = readdir($fp))) { |
|
| 761 | + // Remove '.', '..', and hidden files [optional] |
|
| 762 | + if ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.')) { |
|
| 763 | + continue; |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + is_dir($source_dir . $file) && $file .= DIRECTORY_SEPARATOR; |
|
| 767 | + |
|
| 768 | + if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir . $file)) { |
|
| 769 | + $filedata[$file] = directory_map($source_dir . $file, $new_depth, $hidden); |
|
| 770 | + } else { |
|
| 771 | + $filedata[] = $file; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + closedir($fp); |
|
| 776 | + return $filedata; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + return FALSE; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + //-------------------------------------------------------------------- |
|
| 783 | 783 | |
| 784 | 784 | } |
@@ -1,71 +1,71 @@ |
||
| 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 | interface DocSearchInterface { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The entry point for performing a search of the documentation. |
|
| 37 | - * |
|
| 38 | - * @param null $terms |
|
| 39 | - * @param array $folders |
|
| 40 | - * |
|
| 41 | - * @return array|null |
|
| 42 | - */ |
|
| 43 | - public function search($terms = null, $folders = []); |
|
| 35 | + /** |
|
| 36 | + * The entry point for performing a search of the documentation. |
|
| 37 | + * |
|
| 38 | + * @param null $terms |
|
| 39 | + * @param array $folders |
|
| 40 | + * |
|
| 41 | + * @return array|null |
|
| 42 | + */ |
|
| 43 | + public function search($terms = null, $folders = []); |
|
| 44 | 44 | |
| 45 | - //-------------------------------------------------------------------- |
|
| 45 | + //-------------------------------------------------------------------- |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Stores the name of the callback method to run to convert the source |
|
| 49 | - * files to viewable files. By default, this should be used to register |
|
| 50 | - * a Mardown Extended formatter with the system, but could be used to |
|
| 51 | - * extend the |
|
| 52 | - * |
|
| 53 | - * @param string $callback_name |
|
| 54 | - * @param bool $cascade // If FALSE the formatting of a component ends here. If TRUE, will be passed to next formatter. |
|
| 55 | - * @return $this |
|
| 56 | - */ |
|
| 57 | - public function registerFormatter($callback_name='', $cascade=false); |
|
| 47 | + /** |
|
| 48 | + * Stores the name of the callback method to run to convert the source |
|
| 49 | + * files to viewable files. By default, this should be used to register |
|
| 50 | + * a Mardown Extended formatter with the system, but could be used to |
|
| 51 | + * extend the |
|
| 52 | + * |
|
| 53 | + * @param string $callback_name |
|
| 54 | + * @param bool $cascade // If FALSE the formatting of a component ends here. If TRUE, will be passed to next formatter. |
|
| 55 | + * @return $this |
|
| 56 | + */ |
|
| 57 | + public function registerFormatter($callback_name='', $cascade=false); |
|
| 58 | 58 | |
| 59 | - //-------------------------------------------------------------------- |
|
| 59 | + //-------------------------------------------------------------------- |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Runs the text through the registered formatters. |
|
| 63 | - * |
|
| 64 | - * @param $str |
|
| 65 | - * @return mixed |
|
| 66 | - */ |
|
| 67 | - public function format($str); |
|
| 61 | + /** |
|
| 62 | + * Runs the text through the registered formatters. |
|
| 63 | + * |
|
| 64 | + * @param $str |
|
| 65 | + * @return mixed |
|
| 66 | + */ |
|
| 67 | + public function format($str); |
|
| 68 | 68 | |
| 69 | - //-------------------------------------------------------------------- |
|
| 69 | + //-------------------------------------------------------------------- |
|
| 70 | 70 | |
| 71 | 71 | } |
@@ -1,214 +1,214 @@ |
||
| 1 | 1 | <?php namespace Myth\Settings; |
| 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 | 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 | } |
@@ -40,58 +40,58 @@ |
||
| 40 | 40 | */ |
| 41 | 41 | interface SettingsStoreInterface { |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Inserts/Replaces a single setting item. |
|
| 45 | - * |
|
| 46 | - * @param $key |
|
| 47 | - * @param null $value |
|
| 48 | - * @param string $group |
|
| 49 | - */ |
|
| 50 | - public function save($key, $value=null, $group='app'); |
|
| 43 | + /** |
|
| 44 | + * Inserts/Replaces a single setting item. |
|
| 45 | + * |
|
| 46 | + * @param $key |
|
| 47 | + * @param null $value |
|
| 48 | + * @param string $group |
|
| 49 | + */ |
|
| 50 | + public function save($key, $value=null, $group='app'); |
|
| 51 | 51 | |
| 52 | - //-------------------------------------------------------------------- |
|
| 52 | + //-------------------------------------------------------------------- |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Retrieves a single item. |
|
| 56 | - * |
|
| 57 | - * @param $key |
|
| 58 | - * @param string $group |
|
| 59 | - * @return mixed |
|
| 60 | - */ |
|
| 61 | - public function get($key, $group='app'); |
|
| 54 | + /** |
|
| 55 | + * Retrieves a single item. |
|
| 56 | + * |
|
| 57 | + * @param $key |
|
| 58 | + * @param string $group |
|
| 59 | + * @return mixed |
|
| 60 | + */ |
|
| 61 | + public function get($key, $group='app'); |
|
| 62 | 62 | |
| 63 | - //-------------------------------------------------------------------- |
|
| 63 | + //-------------------------------------------------------------------- |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Deletes a single item. |
|
| 67 | - * |
|
| 68 | - * @param $key |
|
| 69 | - * @param $group |
|
| 70 | - * @return mixed |
|
| 71 | - */ |
|
| 72 | - public function delete($key, $group='app'); |
|
| 65 | + /** |
|
| 66 | + * Deletes a single item. |
|
| 67 | + * |
|
| 68 | + * @param $key |
|
| 69 | + * @param $group |
|
| 70 | + * @return mixed |
|
| 71 | + */ |
|
| 72 | + public function delete($key, $group='app'); |
|
| 73 | 73 | |
| 74 | - //-------------------------------------------------------------------- |
|
| 74 | + //-------------------------------------------------------------------- |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Searches the store for any items with $field = $value. |
|
| 78 | - * |
|
| 79 | - * @param $field |
|
| 80 | - * @param $value |
|
| 81 | - * @return mixed |
|
| 82 | - */ |
|
| 83 | - public function findBy($field, $value); |
|
| 76 | + /** |
|
| 77 | + * Searches the store for any items with $field = $value. |
|
| 78 | + * |
|
| 79 | + * @param $field |
|
| 80 | + * @param $value |
|
| 81 | + * @return mixed |
|
| 82 | + */ |
|
| 83 | + public function findBy($field, $value); |
|
| 84 | 84 | |
| 85 | - //-------------------------------------------------------------------- |
|
| 85 | + //-------------------------------------------------------------------- |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Retrieves all items in the store either globally or for a single group. |
|
| 89 | - * |
|
| 90 | - * @param string $group |
|
| 91 | - * @return mixed |
|
| 92 | - */ |
|
| 93 | - public function all($group=null); |
|
| 87 | + /** |
|
| 88 | + * Retrieves all items in the store either globally or for a single group. |
|
| 89 | + * |
|
| 90 | + * @param string $group |
|
| 91 | + * @return mixed |
|
| 92 | + */ |
|
| 93 | + public function all($group=null); |
|
| 94 | 94 | |
| 95 | - //-------------------------------------------------------------------- |
|
| 95 | + //-------------------------------------------------------------------- |
|
| 96 | 96 | |
| 97 | 97 | } |
@@ -1,34 +1,34 @@ discard block |
||
| 1 | 1 | <?php namespace Myth\UIKits; |
| 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 | * Class BaseUIKit |
@@ -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 | } |
@@ -1,34 +1,34 @@ discard block |
||
| 1 | 1 | <?php namespace Myth\UIKits; |
| 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 | * Class Bootstrap3UIKit |
@@ -37,168 +37,168 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | class Bootstrap extends BaseUIKit { |
| 39 | 39 | |
| 40 | - protected $name = 'Bootstrap3UIKit'; |
|
| 41 | - |
|
| 42 | - //-------------------------------------------------------------------- |
|
| 43 | - // Grid |
|
| 44 | - //-------------------------------------------------------------------- |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Creates a row wrapper of HTML. We would have simple returned the |
|
| 48 | - * the class for it, but some frameworks use a completely different |
|
| 49 | - * approach to rows and columns than the reference Bootstrap and Foundation. |
|
| 50 | - * |
|
| 51 | - * @param array $options |
|
| 52 | - * @return mixed |
|
| 53 | - */ |
|
| 54 | - public function row($options=[], \Closure $c) |
|
| 55 | - { |
|
| 56 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
| 57 | - |
|
| 58 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 59 | - |
|
| 60 | - $output .= $this->runClosure($c); |
|
| 61 | - |
|
| 62 | - $output .= "</div>\n"; |
|
| 63 | - |
|
| 64 | - return $output; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - //-------------------------------------------------------------------- |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Creates the CSS for a column in a grid. |
|
| 71 | - * |
|
| 72 | - * The attribute array is made up of key/value pairs with the |
|
| 73 | - * key being the size, and the value being the number of columns/offset |
|
| 74 | - * in a 12-column grid. |
|
| 75 | - * |
|
| 76 | - * Note that we currently DO NOT support offset columns. |
|
| 77 | - * |
|
| 78 | - * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
| 79 | - * |
|
| 80 | - * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
| 81 | - * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
| 82 | - * |
|
| 83 | - * @param array $attributes |
|
| 84 | - * @return mixed |
|
| 85 | - */ |
|
| 86 | - public function column($options=[], \Closure $c) |
|
| 87 | - { |
|
| 88 | - // Build our classes |
|
| 89 | - $classes = ''; |
|
| 90 | - |
|
| 91 | - foreach ($options['sizes'] as $size => $value) |
|
| 92 | - { |
|
| 93 | - switch ($size) |
|
| 94 | - { |
|
| 95 | - case 's': |
|
| 96 | - $classes .= ' col-xs-'. $value; |
|
| 97 | - break; |
|
| 98 | - case 'm': |
|
| 99 | - $classes .= ' col-sm-'. $value; |
|
| 100 | - break; |
|
| 101 | - case 'l': |
|
| 102 | - $classes .= ' col-md-'. $value; |
|
| 103 | - break; |
|
| 104 | - case 'xl': |
|
| 105 | - $classes .= ' col-lg-'. $value; |
|
| 106 | - break; |
|
| 107 | - case 's-offset': |
|
| 108 | - $classes .= ' col-xs-offset-'. $value; |
|
| 109 | - break; |
|
| 110 | - case 'm-offset': |
|
| 111 | - $classes .= ' col-sm-offset-'. $value; |
|
| 112 | - break; |
|
| 113 | - case 'l-offset': |
|
| 114 | - $classes .= ' col-md-offset-'. $value; |
|
| 115 | - break; |
|
| 116 | - case 'xl-offset': |
|
| 117 | - $classes .= ' col-lg-offset-'. $value; |
|
| 118 | - break; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 123 | - |
|
| 124 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 125 | - |
|
| 126 | - $output .= $this->runClosure($c); |
|
| 127 | - |
|
| 128 | - $output .= "</div>\n"; |
|
| 129 | - |
|
| 130 | - return $output; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - //-------------------------------------------------------------------- |
|
| 134 | - |
|
| 135 | - //-------------------------------------------------------------------- |
|
| 136 | - // Navigation |
|
| 137 | - //-------------------------------------------------------------------- |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Generates the container code for a navbar, typically used along the |
|
| 141 | - * top of a page. |
|
| 142 | - * |
|
| 143 | - * @param array $options |
|
| 144 | - * @param callable $c |
|
| 145 | - * @return string |
|
| 146 | - */ |
|
| 147 | - public function navbar($options=[], \Closure $c) |
|
| 148 | - { |
|
| 149 | - $output = ''; |
|
| 150 | - |
|
| 151 | - /* |
|
| 40 | + protected $name = 'Bootstrap3UIKit'; |
|
| 41 | + |
|
| 42 | + //-------------------------------------------------------------------- |
|
| 43 | + // Grid |
|
| 44 | + //-------------------------------------------------------------------- |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Creates a row wrapper of HTML. We would have simple returned the |
|
| 48 | + * the class for it, but some frameworks use a completely different |
|
| 49 | + * approach to rows and columns than the reference Bootstrap and Foundation. |
|
| 50 | + * |
|
| 51 | + * @param array $options |
|
| 52 | + * @return mixed |
|
| 53 | + */ |
|
| 54 | + public function row($options=[], \Closure $c) |
|
| 55 | + { |
|
| 56 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
| 57 | + |
|
| 58 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 59 | + |
|
| 60 | + $output .= $this->runClosure($c); |
|
| 61 | + |
|
| 62 | + $output .= "</div>\n"; |
|
| 63 | + |
|
| 64 | + return $output; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + //-------------------------------------------------------------------- |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Creates the CSS for a column in a grid. |
|
| 71 | + * |
|
| 72 | + * The attribute array is made up of key/value pairs with the |
|
| 73 | + * key being the size, and the value being the number of columns/offset |
|
| 74 | + * in a 12-column grid. |
|
| 75 | + * |
|
| 76 | + * Note that we currently DO NOT support offset columns. |
|
| 77 | + * |
|
| 78 | + * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
| 79 | + * |
|
| 80 | + * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
| 81 | + * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
| 82 | + * |
|
| 83 | + * @param array $attributes |
|
| 84 | + * @return mixed |
|
| 85 | + */ |
|
| 86 | + public function column($options=[], \Closure $c) |
|
| 87 | + { |
|
| 88 | + // Build our classes |
|
| 89 | + $classes = ''; |
|
| 90 | + |
|
| 91 | + foreach ($options['sizes'] as $size => $value) |
|
| 92 | + { |
|
| 93 | + switch ($size) |
|
| 94 | + { |
|
| 95 | + case 's': |
|
| 96 | + $classes .= ' col-xs-'. $value; |
|
| 97 | + break; |
|
| 98 | + case 'm': |
|
| 99 | + $classes .= ' col-sm-'. $value; |
|
| 100 | + break; |
|
| 101 | + case 'l': |
|
| 102 | + $classes .= ' col-md-'. $value; |
|
| 103 | + break; |
|
| 104 | + case 'xl': |
|
| 105 | + $classes .= ' col-lg-'. $value; |
|
| 106 | + break; |
|
| 107 | + case 's-offset': |
|
| 108 | + $classes .= ' col-xs-offset-'. $value; |
|
| 109 | + break; |
|
| 110 | + case 'm-offset': |
|
| 111 | + $classes .= ' col-sm-offset-'. $value; |
|
| 112 | + break; |
|
| 113 | + case 'l-offset': |
|
| 114 | + $classes .= ' col-md-offset-'. $value; |
|
| 115 | + break; |
|
| 116 | + case 'xl-offset': |
|
| 117 | + $classes .= ' col-lg-offset-'. $value; |
|
| 118 | + break; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 123 | + |
|
| 124 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 125 | + |
|
| 126 | + $output .= $this->runClosure($c); |
|
| 127 | + |
|
| 128 | + $output .= "</div>\n"; |
|
| 129 | + |
|
| 130 | + return $output; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + //-------------------------------------------------------------------- |
|
| 134 | + |
|
| 135 | + //-------------------------------------------------------------------- |
|
| 136 | + // Navigation |
|
| 137 | + //-------------------------------------------------------------------- |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Generates the container code for a navbar, typically used along the |
|
| 141 | + * top of a page. |
|
| 142 | + * |
|
| 143 | + * @param array $options |
|
| 144 | + * @param callable $c |
|
| 145 | + * @return string |
|
| 146 | + */ |
|
| 147 | + public function navbar($options=[], \Closure $c) |
|
| 148 | + { |
|
| 149 | + $output = ''; |
|
| 150 | + |
|
| 151 | + /* |
|
| 152 | 152 | * Open the navbar |
| 153 | 153 | */ |
| 154 | - $classes = "navbar navbar-default "; |
|
| 155 | - |
|
| 156 | - foreach ($options as $option) |
|
| 157 | - { |
|
| 158 | - switch ($option) |
|
| 159 | - { |
|
| 160 | - case 'sticky-top': |
|
| 161 | - $classes .= " navbar-static-top"; |
|
| 162 | - break; |
|
| 163 | - case 'fixed': |
|
| 164 | - $classes .= " navbar-fixed-top"; |
|
| 165 | - break; |
|
| 166 | - case 'inverse': |
|
| 167 | - $classes .= " navbar-inverse"; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - list($class, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 172 | - |
|
| 173 | - $output .= "<nav {$class} {$id} {$attributes} role='navigation'> |
|
| 154 | + $classes = "navbar navbar-default "; |
|
| 155 | + |
|
| 156 | + foreach ($options as $option) |
|
| 157 | + { |
|
| 158 | + switch ($option) |
|
| 159 | + { |
|
| 160 | + case 'sticky-top': |
|
| 161 | + $classes .= " navbar-static-top"; |
|
| 162 | + break; |
|
| 163 | + case 'fixed': |
|
| 164 | + $classes .= " navbar-fixed-top"; |
|
| 165 | + break; |
|
| 166 | + case 'inverse': |
|
| 167 | + $classes .= " navbar-inverse"; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + list($class, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 172 | + |
|
| 173 | + $output .= "<nav {$class} {$id} {$attributes} role='navigation'> |
|
| 174 | 174 | <div class='container-fluid'>\n"; |
| 175 | 175 | |
| 176 | - /* |
|
| 176 | + /* |
|
| 177 | 177 | * Do any user content inside the bar |
| 178 | 178 | */ |
| 179 | - $output .= $this->runClosure($c); |
|
| 179 | + $output .= $this->runClosure($c); |
|
| 180 | 180 | |
| 181 | - /* |
|
| 181 | + /* |
|
| 182 | 182 | * Close out the navbar |
| 183 | 183 | */ |
| 184 | - $output .= "</div></nav>\n"; |
|
| 185 | - |
|
| 186 | - return $output; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - //-------------------------------------------------------------------- |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Builds the HTML for the Title portion of the navbar. This typically |
|
| 193 | - * includes the code for the hamburger menu on small resolutions. |
|
| 194 | - * |
|
| 195 | - * @param $title |
|
| 196 | - * @param string $url |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - public function navbarTitle($title, $url='#') |
|
| 200 | - { |
|
| 201 | - return '<div class="navbar-header"> |
|
| 184 | + $output .= "</div></nav>\n"; |
|
| 185 | + |
|
| 186 | + return $output; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + //-------------------------------------------------------------------- |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Builds the HTML for the Title portion of the navbar. This typically |
|
| 193 | + * includes the code for the hamburger menu on small resolutions. |
|
| 194 | + * |
|
| 195 | + * @param $title |
|
| 196 | + * @param string $url |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + public function navbarTitle($title, $url='#') |
|
| 200 | + { |
|
| 201 | + return '<div class="navbar-header"> |
|
| 202 | 202 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1"> |
| 203 | 203 | <span class="sr-only">Toggle navigation</span> |
| 204 | 204 | <span class="icon-bar"></span> |
@@ -207,396 +207,396 @@ discard block |
||
| 207 | 207 | </button> |
| 208 | 208 | <a class="navbar-brand" href="'. $url .'">'. $title .'</a> |
| 209 | 209 | </div>'; |
| 210 | - } |
|
| 211 | - |
|
| 212 | - //-------------------------------------------------------------------- |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Creates a UL meant to pull to the right within the navbar. |
|
| 216 | - * |
|
| 217 | - * Available options: |
|
| 218 | - * 'class' - An additional class to add |
|
| 219 | - * |
|
| 220 | - * @param array $options |
|
| 221 | - * @param callable $c |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 224 | - public function navbarRight($options=[], \Closure $c) |
|
| 225 | - { |
|
| 226 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav navbar-nav navbar-right', true); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + //-------------------------------------------------------------------- |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Creates a UL meant to pull to the right within the navbar. |
|
| 216 | + * |
|
| 217 | + * Available options: |
|
| 218 | + * 'class' - An additional class to add |
|
| 219 | + * |
|
| 220 | + * @param array $options |
|
| 221 | + * @param callable $c |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 224 | + public function navbarRight($options=[], \Closure $c) |
|
| 225 | + { |
|
| 226 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav navbar-nav navbar-right', true); |
|
| 227 | 227 | |
| 228 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 228 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 229 | 229 | |
| 230 | - $output .= $this->runClosure($c); |
|
| 230 | + $output .= $this->runClosure($c); |
|
| 231 | 231 | |
| 232 | - $output .= "</ul>\n"; |
|
| 232 | + $output .= "</ul>\n"; |
|
| 233 | 233 | |
| 234 | - return $output; |
|
| 235 | - } |
|
| 234 | + return $output; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - //-------------------------------------------------------------------- |
|
| 237 | + //-------------------------------------------------------------------- |
|
| 238 | 238 | |
| 239 | - public function nav() |
|
| 240 | - { |
|
| 239 | + public function nav() |
|
| 240 | + { |
|
| 241 | 241 | |
| 242 | - } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - //-------------------------------------------------------------------- |
|
| 244 | + //-------------------------------------------------------------------- |
|
| 245 | 245 | |
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * Creates a single list item for use within a nav section. |
|
| 249 | - * |
|
| 250 | - * @param $title |
|
| 251 | - * @param $url |
|
| 252 | - * @param array $options |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - public function navItem($title, $url='#', $options=[], $isActive=false) |
|
| 256 | - { |
|
| 257 | - $this->states['activeNavTitle'] = $title; |
|
| 247 | + /** |
|
| 248 | + * Creates a single list item for use within a nav section. |
|
| 249 | + * |
|
| 250 | + * @param $title |
|
| 251 | + * @param $url |
|
| 252 | + * @param array $options |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + public function navItem($title, $url='#', $options=[], $isActive=false) |
|
| 256 | + { |
|
| 257 | + $this->states['activeNavTitle'] = $title; |
|
| 258 | 258 | |
| 259 | - $class = $isActive ? $this->active_class : ''; |
|
| 259 | + $class = $isActive ? $this->active_class : ''; |
|
| 260 | 260 | |
| 261 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $class, true); |
|
| 261 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $class, true); |
|
| 262 | 262 | |
| 263 | - return " <li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>\n"; |
|
| 264 | - } |
|
| 263 | + return " <li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>\n"; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - //-------------------------------------------------------------------- |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Builds the shell of a Dropdown button for use within a nav area. |
|
| 270 | - * |
|
| 271 | - * @param $title |
|
| 272 | - * @param array $options |
|
| 273 | - * @param callable $c |
|
| 274 | - */ |
|
| 275 | - public function navDropdown($title,$options=[], \Closure $c) |
|
| 276 | - { |
|
| 277 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'dropdown', true); |
|
| 278 | - |
|
| 279 | - $output = "\t<li {$classes} {$id} {$attributes}> |
|
| 266 | + //-------------------------------------------------------------------- |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Builds the shell of a Dropdown button for use within a nav area. |
|
| 270 | + * |
|
| 271 | + * @param $title |
|
| 272 | + * @param array $options |
|
| 273 | + * @param callable $c |
|
| 274 | + */ |
|
| 275 | + public function navDropdown($title,$options=[], \Closure $c) |
|
| 276 | + { |
|
| 277 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'dropdown', true); |
|
| 278 | + |
|
| 279 | + $output = "\t<li {$classes} {$id} {$attributes}> |
|
| 280 | 280 | <a href='#' class='dropdown-toggle' data-toggle='dropdown'>{$title} <span class='caret'></span></a> |
| 281 | 281 | <ul class='dropdown-menu' role='menu'>\n"; |
| 282 | 282 | |
| 283 | - $output .= $this->runClosure($c); |
|
| 283 | + $output .= $this->runClosure($c); |
|
| 284 | + |
|
| 285 | + $output .= " </ul></li>\n"; |
|
| 286 | + |
|
| 287 | + return $output; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + //-------------------------------------------------------------------- |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Creates a divider for use within a nav list. |
|
| 294 | + * |
|
| 295 | + * @return string |
|
| 296 | + */ |
|
| 297 | + public function navDivider() |
|
| 298 | + { |
|
| 299 | + return "<li class=\"divider\"></li>\n"; |
|
| 300 | + } |
|
| 284 | 301 | |
| 285 | - $output .= " </ul></li>\n"; |
|
| 302 | + //-------------------------------------------------------------------- |
|
| 286 | 303 | |
| 287 | - return $output; |
|
| 288 | - } |
|
| 304 | + public function sideNav($options=[], \Closure $c) |
|
| 305 | + { |
|
| 306 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav nav-pills nav-stacked', true); |
|
| 289 | 307 | |
| 290 | - //-------------------------------------------------------------------- |
|
| 308 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 291 | 309 | |
| 292 | - /** |
|
| 293 | - * Creates a divider for use within a nav list. |
|
| 294 | - * |
|
| 295 | - * @return string |
|
| 296 | - */ |
|
| 297 | - public function navDivider() |
|
| 298 | - { |
|
| 299 | - return "<li class=\"divider\"></li>\n"; |
|
| 300 | - } |
|
| 310 | + $output .= $this->runClosure($c); |
|
| 301 | 311 | |
| 302 | - //-------------------------------------------------------------------- |
|
| 312 | + $output .= "</ul>\n"; |
|
| 303 | 313 | |
| 304 | - public function sideNav($options=[], \Closure $c) |
|
| 305 | - { |
|
| 306 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'nav nav-pills nav-stacked', true); |
|
| 314 | + return $output; |
|
| 315 | + } |
|
| 307 | 316 | |
| 308 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 309 | - |
|
| 310 | - $output .= $this->runClosure($c); |
|
| 311 | - |
|
| 312 | - $output .= "</ul>\n"; |
|
| 313 | - |
|
| 314 | - return $output; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - //-------------------------------------------------------------------- |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Creates a list of nav items to function as breadcrumbs for a site. |
|
| 321 | - * |
|
| 322 | - * @param array $options |
|
| 323 | - * @param callable $c |
|
| 324 | - * @return mixed |
|
| 325 | - */ |
|
| 326 | - public function breadcrumb($options=[], \Closure $c) |
|
| 327 | - { |
|
| 328 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumb', true); |
|
| 329 | - |
|
| 330 | - $output = "<ol {$classes} {$id} {$attributes}>\n"; |
|
| 331 | - |
|
| 332 | - $output .= $this->runClosure($c); |
|
| 333 | - |
|
| 334 | - $output .= "</ol>\n"; |
|
| 335 | - |
|
| 336 | - return $output; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - //-------------------------------------------------------------------- |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - //-------------------------------------------------------------------- |
|
| 343 | - |
|
| 344 | - //-------------------------------------------------------------------- |
|
| 345 | - // Tables |
|
| 346 | - //-------------------------------------------------------------------- |
|
| 347 | - |
|
| 348 | - public function table() |
|
| 349 | - { |
|
| 350 | - return 'table'; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - //-------------------------------------------------------------------- |
|
| 354 | - |
|
| 355 | - //-------------------------------------------------------------------- |
|
| 356 | - // Buttons |
|
| 357 | - //-------------------------------------------------------------------- |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Creates a simple button. |
|
| 361 | - * |
|
| 362 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 363 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 364 | - * |
|
| 365 | - * @param $title |
|
| 366 | - * @param string $style |
|
| 367 | - * @param array $options |
|
| 368 | - * @return mixed |
|
| 369 | - */ |
|
| 370 | - public function button($title, $style='default', $size='default', $options=[]) |
|
| 371 | - { |
|
| 372 | - $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 373 | - |
|
| 374 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - //-------------------------------------------------------------------- |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Creates a simple link styled as a button. |
|
| 381 | - * |
|
| 382 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 383 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 384 | - * |
|
| 385 | - * @param $title |
|
| 386 | - * @param string $url |
|
| 387 | - * @param string $style |
|
| 388 | - * @param array $options |
|
| 389 | - * @return mixed |
|
| 390 | - */ |
|
| 391 | - public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
| 392 | - { |
|
| 393 | - $tag = "<a href='{$url}' {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
| 394 | - |
|
| 395 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - //-------------------------------------------------------------------- |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * Helper method to render out our buttons in a DRY manner. |
|
| 402 | - * |
|
| 403 | - * @param $title |
|
| 404 | - * @param $style |
|
| 405 | - * @param $size |
|
| 406 | - * @param $tag |
|
| 407 | - */ |
|
| 408 | - protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
| 409 | - { |
|
| 410 | - $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
| 411 | - $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
| 412 | - |
|
| 413 | - if (! in_array($style, $valid_styles)) |
|
| 414 | - { |
|
| 415 | - $style = 'default'; |
|
| 416 | - $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - $classes = 'btn '; |
|
| 420 | - |
|
| 421 | - // Sizes |
|
| 422 | - switch($size) |
|
| 423 | - { |
|
| 424 | - case 'small': |
|
| 425 | - $classes .= 'btn-sm '; |
|
| 426 | - break; |
|
| 427 | - case 'xsmall': |
|
| 428 | - $classes .= 'btn-xs '; |
|
| 429 | - break; |
|
| 430 | - case 'large': |
|
| 431 | - $classes .= 'btn-lg '; |
|
| 432 | - break; |
|
| 433 | - default: |
|
| 434 | - break; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // Styles |
|
| 438 | - switch ($style) |
|
| 439 | - { |
|
| 440 | - case 'primary': |
|
| 441 | - $classes .= 'btn-primary '; |
|
| 442 | - break; |
|
| 443 | - case 'success': |
|
| 444 | - $classes .= 'btn-success '; |
|
| 445 | - break; |
|
| 446 | - case 'info': |
|
| 447 | - $classes .= 'btn-info '; |
|
| 448 | - break; |
|
| 449 | - case 'warning': |
|
| 450 | - $classes .= 'btn-warning '; |
|
| 451 | - break; |
|
| 452 | - case 'danger': |
|
| 453 | - $classes .= 'btn-danger '; |
|
| 454 | - break; |
|
| 455 | - case 'default': |
|
| 456 | - $classes .= 'btn-default '; |
|
| 457 | - break; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 461 | - |
|
| 462 | - $tag = str_replace('{classes}', $classes, $tag); |
|
| 463 | - $tag = str_replace('{id}', $id, $tag); |
|
| 464 | - $tag = str_replace('{attributes}', $attributes, $tag); |
|
| 465 | - $tag = str_replace('{title}', $title, $tag); |
|
| 466 | - |
|
| 467 | - return $tag; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - //-------------------------------------------------------------------- |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Creates button groups wrapping HTML. |
|
| 474 | - * |
|
| 475 | - * @param $options |
|
| 476 | - * @param callable $c |
|
| 477 | - * @return mixed |
|
| 478 | - */ |
|
| 479 | - public function buttonGroup($options, \Closure $c) |
|
| 480 | - { |
|
| 481 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-group', true); |
|
| 482 | - |
|
| 483 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 484 | - |
|
| 485 | - $output .= $this->runClosure($c); |
|
| 486 | - |
|
| 487 | - $output .= "</div>\n"; |
|
| 488 | - |
|
| 489 | - return $output; |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - //-------------------------------------------------------------------- |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Creates the button bar wrapping HTML. |
|
| 496 | - * |
|
| 497 | - * @param $options |
|
| 498 | - * @param callable $c |
|
| 499 | - * @return mixed |
|
| 500 | - */ |
|
| 501 | - public function buttonBar($options, \Closure $c) |
|
| 502 | - { |
|
| 503 | - $options['attributes'][] = 'role="toolbar"'; |
|
| 504 | - |
|
| 505 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-toolbar', true); |
|
| 506 | - |
|
| 507 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 508 | - |
|
| 509 | - $output .= $this->runClosure($c); |
|
| 510 | - |
|
| 511 | - $output .= "</div>\n"; |
|
| 512 | - |
|
| 513 | - return $output; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - //-------------------------------------------------------------------- |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
| 520 | - * by some frameworks. |
|
| 521 | - * |
|
| 522 | - * @param $title |
|
| 523 | - * @param string $style |
|
| 524 | - * @param string $size |
|
| 525 | - * @param array $options |
|
| 526 | - * @param callable $c |
|
| 527 | - * @return mixed |
|
| 528 | - */ |
|
| 529 | - public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
| 530 | - { |
|
| 531 | - $tag = "<button type='button' {classes} data-toggle='dropdown'> |
|
| 317 | + //-------------------------------------------------------------------- |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Creates a list of nav items to function as breadcrumbs for a site. |
|
| 321 | + * |
|
| 322 | + * @param array $options |
|
| 323 | + * @param callable $c |
|
| 324 | + * @return mixed |
|
| 325 | + */ |
|
| 326 | + public function breadcrumb($options=[], \Closure $c) |
|
| 327 | + { |
|
| 328 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumb', true); |
|
| 329 | + |
|
| 330 | + $output = "<ol {$classes} {$id} {$attributes}>\n"; |
|
| 331 | + |
|
| 332 | + $output .= $this->runClosure($c); |
|
| 333 | + |
|
| 334 | + $output .= "</ol>\n"; |
|
| 335 | + |
|
| 336 | + return $output; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + //-------------------------------------------------------------------- |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + //-------------------------------------------------------------------- |
|
| 343 | + |
|
| 344 | + //-------------------------------------------------------------------- |
|
| 345 | + // Tables |
|
| 346 | + //-------------------------------------------------------------------- |
|
| 347 | + |
|
| 348 | + public function table() |
|
| 349 | + { |
|
| 350 | + return 'table'; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + //-------------------------------------------------------------------- |
|
| 354 | + |
|
| 355 | + //-------------------------------------------------------------------- |
|
| 356 | + // Buttons |
|
| 357 | + //-------------------------------------------------------------------- |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Creates a simple button. |
|
| 361 | + * |
|
| 362 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 363 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 364 | + * |
|
| 365 | + * @param $title |
|
| 366 | + * @param string $style |
|
| 367 | + * @param array $options |
|
| 368 | + * @return mixed |
|
| 369 | + */ |
|
| 370 | + public function button($title, $style='default', $size='default', $options=[]) |
|
| 371 | + { |
|
| 372 | + $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 373 | + |
|
| 374 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + //-------------------------------------------------------------------- |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Creates a simple link styled as a button. |
|
| 381 | + * |
|
| 382 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 383 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 384 | + * |
|
| 385 | + * @param $title |
|
| 386 | + * @param string $url |
|
| 387 | + * @param string $style |
|
| 388 | + * @param array $options |
|
| 389 | + * @return mixed |
|
| 390 | + */ |
|
| 391 | + public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
| 392 | + { |
|
| 393 | + $tag = "<a href='{$url}' {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
| 394 | + |
|
| 395 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + //-------------------------------------------------------------------- |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Helper method to render out our buttons in a DRY manner. |
|
| 402 | + * |
|
| 403 | + * @param $title |
|
| 404 | + * @param $style |
|
| 405 | + * @param $size |
|
| 406 | + * @param $tag |
|
| 407 | + */ |
|
| 408 | + protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
| 409 | + { |
|
| 410 | + $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
| 411 | + $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
| 412 | + |
|
| 413 | + if (! in_array($style, $valid_styles)) |
|
| 414 | + { |
|
| 415 | + $style = 'default'; |
|
| 416 | + $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + $classes = 'btn '; |
|
| 420 | + |
|
| 421 | + // Sizes |
|
| 422 | + switch($size) |
|
| 423 | + { |
|
| 424 | + case 'small': |
|
| 425 | + $classes .= 'btn-sm '; |
|
| 426 | + break; |
|
| 427 | + case 'xsmall': |
|
| 428 | + $classes .= 'btn-xs '; |
|
| 429 | + break; |
|
| 430 | + case 'large': |
|
| 431 | + $classes .= 'btn-lg '; |
|
| 432 | + break; |
|
| 433 | + default: |
|
| 434 | + break; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // Styles |
|
| 438 | + switch ($style) |
|
| 439 | + { |
|
| 440 | + case 'primary': |
|
| 441 | + $classes .= 'btn-primary '; |
|
| 442 | + break; |
|
| 443 | + case 'success': |
|
| 444 | + $classes .= 'btn-success '; |
|
| 445 | + break; |
|
| 446 | + case 'info': |
|
| 447 | + $classes .= 'btn-info '; |
|
| 448 | + break; |
|
| 449 | + case 'warning': |
|
| 450 | + $classes .= 'btn-warning '; |
|
| 451 | + break; |
|
| 452 | + case 'danger': |
|
| 453 | + $classes .= 'btn-danger '; |
|
| 454 | + break; |
|
| 455 | + case 'default': |
|
| 456 | + $classes .= 'btn-default '; |
|
| 457 | + break; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 461 | + |
|
| 462 | + $tag = str_replace('{classes}', $classes, $tag); |
|
| 463 | + $tag = str_replace('{id}', $id, $tag); |
|
| 464 | + $tag = str_replace('{attributes}', $attributes, $tag); |
|
| 465 | + $tag = str_replace('{title}', $title, $tag); |
|
| 466 | + |
|
| 467 | + return $tag; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + //-------------------------------------------------------------------- |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Creates button groups wrapping HTML. |
|
| 474 | + * |
|
| 475 | + * @param $options |
|
| 476 | + * @param callable $c |
|
| 477 | + * @return mixed |
|
| 478 | + */ |
|
| 479 | + public function buttonGroup($options, \Closure $c) |
|
| 480 | + { |
|
| 481 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-group', true); |
|
| 482 | + |
|
| 483 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 484 | + |
|
| 485 | + $output .= $this->runClosure($c); |
|
| 486 | + |
|
| 487 | + $output .= "</div>\n"; |
|
| 488 | + |
|
| 489 | + return $output; |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + //-------------------------------------------------------------------- |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Creates the button bar wrapping HTML. |
|
| 496 | + * |
|
| 497 | + * @param $options |
|
| 498 | + * @param callable $c |
|
| 499 | + * @return mixed |
|
| 500 | + */ |
|
| 501 | + public function buttonBar($options, \Closure $c) |
|
| 502 | + { |
|
| 503 | + $options['attributes'][] = 'role="toolbar"'; |
|
| 504 | + |
|
| 505 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'btn-toolbar', true); |
|
| 506 | + |
|
| 507 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 508 | + |
|
| 509 | + $output .= $this->runClosure($c); |
|
| 510 | + |
|
| 511 | + $output .= "</div>\n"; |
|
| 512 | + |
|
| 513 | + return $output; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + //-------------------------------------------------------------------- |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
| 520 | + * by some frameworks. |
|
| 521 | + * |
|
| 522 | + * @param $title |
|
| 523 | + * @param string $style |
|
| 524 | + * @param string $size |
|
| 525 | + * @param array $options |
|
| 526 | + * @param callable $c |
|
| 527 | + * @return mixed |
|
| 528 | + */ |
|
| 529 | + public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
| 530 | + { |
|
| 531 | + $tag = "<button type='button' {classes} data-toggle='dropdown'> |
|
| 532 | 532 | {title} <span class='caret'></span> |
| 533 | 533 | </button> |
| 534 | 534 | <ul class='dropdown-menu' role='menu'>"; |
| 535 | 535 | |
| 536 | - $output = $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 537 | - |
|
| 538 | - $output .= $this->runClosure($c); |
|
| 539 | - |
|
| 540 | - $output .= "</ul>\n"; |
|
| 541 | - |
|
| 542 | - return $output; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - //-------------------------------------------------------------------- |
|
| 546 | - |
|
| 547 | - //-------------------------------------------------------------------- |
|
| 548 | - // Notices |
|
| 549 | - //-------------------------------------------------------------------- |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Creates an 'alert-box' style of notice grid. |
|
| 553 | - * |
|
| 554 | - * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
| 555 | - * |
|
| 556 | - * @param $content |
|
| 557 | - * @param string $style |
|
| 558 | - * @param bool $closable |
|
| 559 | - * @return mixed |
|
| 560 | - */ |
|
| 561 | - public function notice($content, $style='success', $closable=true, $options=[]) |
|
| 562 | - { |
|
| 563 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert', false); |
|
| 564 | - |
|
| 565 | - // Styles |
|
| 566 | - switch ($style) |
|
| 567 | - { |
|
| 568 | - case 'success': |
|
| 569 | - $classes .= ' alert-success '; |
|
| 570 | - break; |
|
| 571 | - case 'info': |
|
| 572 | - $classes .= ' alert-info '; |
|
| 573 | - break; |
|
| 574 | - case 'warning': |
|
| 575 | - $classes .= ' alert-warning '; |
|
| 576 | - break; |
|
| 577 | - case 'danger': |
|
| 578 | - $classes .= ' alert-danger '; |
|
| 579 | - break; |
|
| 580 | - case 'default': |
|
| 581 | - $classes .= ' text-muted '; |
|
| 582 | - break; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - $output = "<div class='{$classes}'>\n"; |
|
| 586 | - |
|
| 587 | - $output .= "\t$content\n"; |
|
| 588 | - |
|
| 589 | - if ($closable) |
|
| 590 | - { |
|
| 591 | - $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - $output .= "</div>\n"; |
|
| 595 | - |
|
| 596 | - return $output; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - //-------------------------------------------------------------------- |
|
| 536 | + $output = $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 537 | + |
|
| 538 | + $output .= $this->runClosure($c); |
|
| 539 | + |
|
| 540 | + $output .= "</ul>\n"; |
|
| 541 | + |
|
| 542 | + return $output; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + //-------------------------------------------------------------------- |
|
| 546 | + |
|
| 547 | + //-------------------------------------------------------------------- |
|
| 548 | + // Notices |
|
| 549 | + //-------------------------------------------------------------------- |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Creates an 'alert-box' style of notice grid. |
|
| 553 | + * |
|
| 554 | + * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
| 555 | + * |
|
| 556 | + * @param $content |
|
| 557 | + * @param string $style |
|
| 558 | + * @param bool $closable |
|
| 559 | + * @return mixed |
|
| 560 | + */ |
|
| 561 | + public function notice($content, $style='success', $closable=true, $options=[]) |
|
| 562 | + { |
|
| 563 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert', false); |
|
| 564 | + |
|
| 565 | + // Styles |
|
| 566 | + switch ($style) |
|
| 567 | + { |
|
| 568 | + case 'success': |
|
| 569 | + $classes .= ' alert-success '; |
|
| 570 | + break; |
|
| 571 | + case 'info': |
|
| 572 | + $classes .= ' alert-info '; |
|
| 573 | + break; |
|
| 574 | + case 'warning': |
|
| 575 | + $classes .= ' alert-warning '; |
|
| 576 | + break; |
|
| 577 | + case 'danger': |
|
| 578 | + $classes .= ' alert-danger '; |
|
| 579 | + break; |
|
| 580 | + case 'default': |
|
| 581 | + $classes .= ' text-muted '; |
|
| 582 | + break; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + $output = "<div class='{$classes}'>\n"; |
|
| 586 | + |
|
| 587 | + $output .= "\t$content\n"; |
|
| 588 | + |
|
| 589 | + if ($closable) |
|
| 590 | + { |
|
| 591 | + $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + $output .= "</div>\n"; |
|
| 595 | + |
|
| 596 | + return $output; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + //-------------------------------------------------------------------- |
|
| 600 | 600 | |
| 601 | 601 | //-------------------------------------------------------------------- |
| 602 | 602 | // Forms |