@@ -4,79 +4,79 @@ |
||
| 4 | 4 | |
| 5 | 5 | if (! function_exists('esc')) |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * Escapes strings to make them safe for use |
|
| 9 | - * within HTML templates. Used by the auto-escaping |
|
| 10 | - * functionality in setVar() and available to |
|
| 11 | - * use within your views. |
|
| 12 | - * |
|
| 13 | - * Uses ZendFramework's Escaper to handle the actual escaping, |
|
| 14 | - * based on context. Valid contexts are: |
|
| 15 | - * - html |
|
| 16 | - * - htmlAttr |
|
| 17 | - * - js |
|
| 18 | - * - css |
|
| 19 | - * - url |
|
| 20 | - * |
|
| 21 | - * References: |
|
| 22 | - * - https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet |
|
| 23 | - * - http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html |
|
| 24 | - * |
|
| 25 | - * @param $data |
|
| 26 | - * @param $context |
|
| 27 | - * @param escaper // An instance of ZF's Escaper to avoid repeated class instantiation. |
|
| 28 | - * |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - function esc($data, $context='html', $escaper=null) |
|
| 32 | - { |
|
| 33 | - if (is_array($data)) |
|
| 34 | - { |
|
| 35 | - foreach ($data as $key => &$value) |
|
| 36 | - { |
|
| 37 | - $value = esc($value, $context); |
|
| 38 | - } |
|
| 39 | - } |
|
| 7 | + /** |
|
| 8 | + * Escapes strings to make them safe for use |
|
| 9 | + * within HTML templates. Used by the auto-escaping |
|
| 10 | + * functionality in setVar() and available to |
|
| 11 | + * use within your views. |
|
| 12 | + * |
|
| 13 | + * Uses ZendFramework's Escaper to handle the actual escaping, |
|
| 14 | + * based on context. Valid contexts are: |
|
| 15 | + * - html |
|
| 16 | + * - htmlAttr |
|
| 17 | + * - js |
|
| 18 | + * - css |
|
| 19 | + * - url |
|
| 20 | + * |
|
| 21 | + * References: |
|
| 22 | + * - https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet |
|
| 23 | + * - http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html |
|
| 24 | + * |
|
| 25 | + * @param $data |
|
| 26 | + * @param $context |
|
| 27 | + * @param escaper // An instance of ZF's Escaper to avoid repeated class instantiation. |
|
| 28 | + * |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + function esc($data, $context='html', $escaper=null) |
|
| 32 | + { |
|
| 33 | + if (is_array($data)) |
|
| 34 | + { |
|
| 35 | + foreach ($data as $key => &$value) |
|
| 36 | + { |
|
| 37 | + $value = esc($value, $context); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - $context = strtolower($context); |
|
| 41 | + $context = strtolower($context); |
|
| 42 | 42 | |
| 43 | - if (! is_object($escaper)) |
|
| 44 | - { |
|
| 45 | - $escaper = new Escaper(config_item('charset')); |
|
| 46 | - } |
|
| 43 | + if (! is_object($escaper)) |
|
| 44 | + { |
|
| 45 | + $escaper = new Escaper(config_item('charset')); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - // Valid context? |
|
| 49 | - if (! in_array($context, ['html', 'htmlattr', 'js', 'css', 'url'])) |
|
| 50 | - { |
|
| 51 | - throw new \InvalidArgumentException('Invalid Context type: '. $context); |
|
| 52 | - } |
|
| 48 | + // Valid context? |
|
| 49 | + if (! in_array($context, ['html', 'htmlattr', 'js', 'css', 'url'])) |
|
| 50 | + { |
|
| 51 | + throw new \InvalidArgumentException('Invalid Context type: '. $context); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - if (! is_string($data)) |
|
| 55 | - { |
|
| 56 | - return $data; |
|
| 57 | - } |
|
| 54 | + if (! is_string($data)) |
|
| 55 | + { |
|
| 56 | + return $data; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - switch ($context) |
|
| 60 | - { |
|
| 61 | - case 'html': |
|
| 62 | - $data = $escaper->escapeHtml($data); |
|
| 63 | - break; |
|
| 64 | - case 'htmlattr': |
|
| 65 | - $data = $escaper->escapeHtmlAttr($data); |
|
| 66 | - break; |
|
| 67 | - case 'js': |
|
| 68 | - $data = $escaper->escapeJs($data); |
|
| 69 | - break; |
|
| 70 | - case 'css': |
|
| 71 | - $data = $escaper->escapeCss($data); |
|
| 72 | - break; |
|
| 73 | - case 'url': |
|
| 74 | - $data = $escaper->escapeUrl($data); |
|
| 75 | - break; |
|
| 76 | - default: |
|
| 77 | - break; |
|
| 78 | - } |
|
| 59 | + switch ($context) |
|
| 60 | + { |
|
| 61 | + case 'html': |
|
| 62 | + $data = $escaper->escapeHtml($data); |
|
| 63 | + break; |
|
| 64 | + case 'htmlattr': |
|
| 65 | + $data = $escaper->escapeHtmlAttr($data); |
|
| 66 | + break; |
|
| 67 | + case 'js': |
|
| 68 | + $data = $escaper->escapeJs($data); |
|
| 69 | + break; |
|
| 70 | + case 'css': |
|
| 71 | + $data = $escaper->escapeCss($data); |
|
| 72 | + break; |
|
| 73 | + case 'url': |
|
| 74 | + $data = $escaper->escapeUrl($data); |
|
| 75 | + break; |
|
| 76 | + default: |
|
| 77 | + break; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - return $data; |
|
| 81 | - } |
|
| 80 | + return $data; |
|
| 81 | + } |
|
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -37,639 +37,639 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class Foundation extends BaseUIKit { |
| 39 | 39 | |
| 40 | - //-------------------------------------------------------------------- |
|
| 41 | - |
|
| 42 | - public function name() |
|
| 43 | - { |
|
| 44 | - return 'Foundation5UIKit'; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - //-------------------------------------------------------------------- |
|
| 48 | - |
|
| 49 | - //-------------------------------------------------------------------- |
|
| 50 | - // Grid |
|
| 51 | - //-------------------------------------------------------------------- |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Creates a row wrapper of HTML. We would have simple returned the |
|
| 55 | - * the class for it, but some frameworks use a completely different |
|
| 56 | - * approach to rows and columns than the reference Bootstrap and Foundation. |
|
| 57 | - * |
|
| 58 | - * @param array $options |
|
| 59 | - * @return mixed |
|
| 60 | - */ |
|
| 61 | - public function row($options=[], \Closure $c) |
|
| 62 | - { |
|
| 63 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
| 64 | - |
|
| 65 | - $output = "<div {$classes} {$id} {$attributes}>"; |
|
| 66 | - |
|
| 67 | - $output .= $this->runClosure($c); |
|
| 68 | - |
|
| 69 | - $output .= "</div>"; |
|
| 70 | - |
|
| 71 | - return $output; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - //-------------------------------------------------------------------- |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Creates the CSS for a column in a grid. |
|
| 78 | - * |
|
| 79 | - * The attribute array is made up of key/value pairs with the |
|
| 80 | - * key being the size, and the value being the number of columns/offset |
|
| 81 | - * in a 12-column grid. |
|
| 82 | - * |
|
| 83 | - * Note that we currently DO NOT support offset columns. |
|
| 84 | - * |
|
| 85 | - * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
| 86 | - * |
|
| 87 | - * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
| 88 | - * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
| 89 | - * |
|
| 90 | - * @param array $attributes |
|
| 91 | - * @return mixed |
|
| 92 | - */ |
|
| 93 | - public function column($options=[], \Closure $c) |
|
| 94 | - { |
|
| 95 | - // Build our classes |
|
| 96 | - $classes = ''; |
|
| 97 | - |
|
| 98 | - foreach ($options['sizes'] as $size => $value) |
|
| 99 | - { |
|
| 100 | - switch ($size) |
|
| 101 | - { |
|
| 102 | - case 's': |
|
| 103 | - $classes .= ' small-'. $value; |
|
| 104 | - break; |
|
| 105 | - case 'm': |
|
| 106 | - $classes .= ' medium-'. $value; |
|
| 107 | - break; |
|
| 108 | - case 'l': |
|
| 109 | - $classes .= ' large-'. $value; |
|
| 110 | - break; |
|
| 111 | - case 'xl': |
|
| 112 | - $classes .= ' large-'. $value; |
|
| 113 | - break; |
|
| 114 | - case 's-offset': |
|
| 115 | - $classes .= ' small-offset-'. $value; |
|
| 116 | - break; |
|
| 117 | - case 'm-offset': |
|
| 118 | - $classes .= ' medium-offset-'. $value; |
|
| 119 | - break; |
|
| 120 | - case 'l-offset': |
|
| 121 | - $classes .= ' large-offset-'. $value; |
|
| 122 | - break; |
|
| 123 | - case 'xl-offset': |
|
| 124 | - $classes .= ' large-offset-'. $value; |
|
| 125 | - break; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $classes = $this->buildClassString($classes .' columns', $options, true); |
|
| 130 | - |
|
| 131 | - $id = $this->buildIdFromOptions($options); |
|
| 132 | - |
|
| 133 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 134 | - |
|
| 135 | - $output = "<div {$classes} {$id} {$attributes}>"; |
|
| 136 | - |
|
| 137 | - $output .= $this->runClosure($c); |
|
| 138 | - |
|
| 139 | - $output .= "</div>"; |
|
| 140 | - |
|
| 141 | - return $output; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - //-------------------------------------------------------------------- |
|
| 145 | - |
|
| 146 | - //-------------------------------------------------------------------- |
|
| 147 | - // Navigation |
|
| 148 | - //-------------------------------------------------------------------- |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Generates the container code for a navbar, typically used along the |
|
| 152 | - * top of a page. |
|
| 153 | - * |
|
| 154 | - * @param array $options |
|
| 155 | - * @param callable $c |
|
| 156 | - * @return string |
|
| 157 | - */ |
|
| 158 | - public function navbar($options=[], \Closure $c) |
|
| 159 | - { |
|
| 160 | - $output = ''; |
|
| 161 | - |
|
| 162 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'top-bar ', true); |
|
| 163 | - |
|
| 164 | - foreach ($options as $option) |
|
| 165 | - { |
|
| 166 | - switch ($option) |
|
| 167 | - { |
|
| 168 | - case 'sticky-top': |
|
| 169 | - $classes .= " navbar-static-top"; |
|
| 170 | - break; |
|
| 171 | - case 'fixed': |
|
| 172 | - $classes .= " navbar-fixed-top"; |
|
| 173 | - break; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $output .= "<nav {$classes} {$id} {$attributes} data-topbar>"; |
|
| 178 | - |
|
| 179 | - /* |
|
| 40 | + //-------------------------------------------------------------------- |
|
| 41 | + |
|
| 42 | + public function name() |
|
| 43 | + { |
|
| 44 | + return 'Foundation5UIKit'; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + //-------------------------------------------------------------------- |
|
| 48 | + |
|
| 49 | + //-------------------------------------------------------------------- |
|
| 50 | + // Grid |
|
| 51 | + //-------------------------------------------------------------------- |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Creates a row wrapper of HTML. We would have simple returned the |
|
| 55 | + * the class for it, but some frameworks use a completely different |
|
| 56 | + * approach to rows and columns than the reference Bootstrap and Foundation. |
|
| 57 | + * |
|
| 58 | + * @param array $options |
|
| 59 | + * @return mixed |
|
| 60 | + */ |
|
| 61 | + public function row($options=[], \Closure $c) |
|
| 62 | + { |
|
| 63 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'row', true); |
|
| 64 | + |
|
| 65 | + $output = "<div {$classes} {$id} {$attributes}>"; |
|
| 66 | + |
|
| 67 | + $output .= $this->runClosure($c); |
|
| 68 | + |
|
| 69 | + $output .= "</div>"; |
|
| 70 | + |
|
| 71 | + return $output; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + //-------------------------------------------------------------------- |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Creates the CSS for a column in a grid. |
|
| 78 | + * |
|
| 79 | + * The attribute array is made up of key/value pairs with the |
|
| 80 | + * key being the size, and the value being the number of columns/offset |
|
| 81 | + * in a 12-column grid. |
|
| 82 | + * |
|
| 83 | + * Note that we currently DO NOT support offset columns. |
|
| 84 | + * |
|
| 85 | + * Valid sizes - 's', 'm', 'l', 'xl', 's-offset', 'm-offset', 'l-offset', 'xl-offset' |
|
| 86 | + * |
|
| 87 | + * Please note that that sizes are different than in Bootstrap. For example, for a 'xs' |
|
| 88 | + * column size in Bootstrap, you would use 's' here. 'sm' = 'm', etc. |
|
| 89 | + * |
|
| 90 | + * @param array $attributes |
|
| 91 | + * @return mixed |
|
| 92 | + */ |
|
| 93 | + public function column($options=[], \Closure $c) |
|
| 94 | + { |
|
| 95 | + // Build our classes |
|
| 96 | + $classes = ''; |
|
| 97 | + |
|
| 98 | + foreach ($options['sizes'] as $size => $value) |
|
| 99 | + { |
|
| 100 | + switch ($size) |
|
| 101 | + { |
|
| 102 | + case 's': |
|
| 103 | + $classes .= ' small-'. $value; |
|
| 104 | + break; |
|
| 105 | + case 'm': |
|
| 106 | + $classes .= ' medium-'. $value; |
|
| 107 | + break; |
|
| 108 | + case 'l': |
|
| 109 | + $classes .= ' large-'. $value; |
|
| 110 | + break; |
|
| 111 | + case 'xl': |
|
| 112 | + $classes .= ' large-'. $value; |
|
| 113 | + break; |
|
| 114 | + case 's-offset': |
|
| 115 | + $classes .= ' small-offset-'. $value; |
|
| 116 | + break; |
|
| 117 | + case 'm-offset': |
|
| 118 | + $classes .= ' medium-offset-'. $value; |
|
| 119 | + break; |
|
| 120 | + case 'l-offset': |
|
| 121 | + $classes .= ' large-offset-'. $value; |
|
| 122 | + break; |
|
| 123 | + case 'xl-offset': |
|
| 124 | + $classes .= ' large-offset-'. $value; |
|
| 125 | + break; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $classes = $this->buildClassString($classes .' columns', $options, true); |
|
| 130 | + |
|
| 131 | + $id = $this->buildIdFromOptions($options); |
|
| 132 | + |
|
| 133 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 134 | + |
|
| 135 | + $output = "<div {$classes} {$id} {$attributes}>"; |
|
| 136 | + |
|
| 137 | + $output .= $this->runClosure($c); |
|
| 138 | + |
|
| 139 | + $output .= "</div>"; |
|
| 140 | + |
|
| 141 | + return $output; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + //-------------------------------------------------------------------- |
|
| 145 | + |
|
| 146 | + //-------------------------------------------------------------------- |
|
| 147 | + // Navigation |
|
| 148 | + //-------------------------------------------------------------------- |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Generates the container code for a navbar, typically used along the |
|
| 152 | + * top of a page. |
|
| 153 | + * |
|
| 154 | + * @param array $options |
|
| 155 | + * @param callable $c |
|
| 156 | + * @return string |
|
| 157 | + */ |
|
| 158 | + public function navbar($options=[], \Closure $c) |
|
| 159 | + { |
|
| 160 | + $output = ''; |
|
| 161 | + |
|
| 162 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'top-bar ', true); |
|
| 163 | + |
|
| 164 | + foreach ($options as $option) |
|
| 165 | + { |
|
| 166 | + switch ($option) |
|
| 167 | + { |
|
| 168 | + case 'sticky-top': |
|
| 169 | + $classes .= " navbar-static-top"; |
|
| 170 | + break; |
|
| 171 | + case 'fixed': |
|
| 172 | + $classes .= " navbar-fixed-top"; |
|
| 173 | + break; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $output .= "<nav {$classes} {$id} {$attributes} data-topbar>"; |
|
| 178 | + |
|
| 179 | + /* |
|
| 180 | 180 | * Do any user content inside the bar |
| 181 | 181 | */ |
| 182 | - $output .= $this->runClosure($c); |
|
| 182 | + $output .= $this->runClosure($c); |
|
| 183 | 183 | |
| 184 | - if (isset($this->states['nav-section-open'])) |
|
| 185 | - { |
|
| 186 | - $output .= "</section>"; |
|
| 187 | - unset($this->states['nav-section-open']); |
|
| 188 | - } |
|
| 184 | + if (isset($this->states['nav-section-open'])) |
|
| 185 | + { |
|
| 186 | + $output .= "</section>"; |
|
| 187 | + unset($this->states['nav-section-open']); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /* |
|
| 190 | + /* |
|
| 191 | 191 | * Close out the navbar |
| 192 | 192 | */ |
| 193 | - $output .= '</nav>'; |
|
| 194 | - |
|
| 195 | - return $output; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - //-------------------------------------------------------------------- |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Builds the HTML for the Title portion of the navbar. This typically |
|
| 202 | - * includes the code for the hamburger menu on small resolutions. |
|
| 203 | - * |
|
| 204 | - * @param $title |
|
| 205 | - * @param string $url |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function navbarTitle($title, $url='#') |
|
| 209 | - { |
|
| 210 | - return "<ul class='title-area'> |
|
| 193 | + $output .= '</nav>'; |
|
| 194 | + |
|
| 195 | + return $output; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + //-------------------------------------------------------------------- |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Builds the HTML for the Title portion of the navbar. This typically |
|
| 202 | + * includes the code for the hamburger menu on small resolutions. |
|
| 203 | + * |
|
| 204 | + * @param $title |
|
| 205 | + * @param string $url |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function navbarTitle($title, $url='#') |
|
| 209 | + { |
|
| 210 | + return "<ul class='title-area'> |
|
| 211 | 211 | <li class='name'> |
| 212 | 212 | <h1><a href='{$url}'>{$title}</a></h1> |
| 213 | 213 | </li> |
| 214 | 214 | <li class='toggle-topbar menu-icon'><a href='#'><span>Menu</span></a></li> |
| 215 | 215 | </ul>"; |
| 216 | - } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - //-------------------------------------------------------------------- |
|
| 218 | + //-------------------------------------------------------------------- |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Creates a UL meant to pull to the right within the navbar. |
|
| 222 | - * |
|
| 223 | - * Available options: |
|
| 224 | - * 'class' - An additional class to add |
|
| 225 | - * |
|
| 226 | - * @param array $options |
|
| 227 | - * @param callable $c |
|
| 228 | - * @return string |
|
| 229 | - */ |
|
| 230 | - public function navbarRight($options=[], \Closure $c) |
|
| 231 | - { |
|
| 232 | - $output = ''; |
|
| 220 | + /** |
|
| 221 | + * Creates a UL meant to pull to the right within the navbar. |
|
| 222 | + * |
|
| 223 | + * Available options: |
|
| 224 | + * 'class' - An additional class to add |
|
| 225 | + * |
|
| 226 | + * @param array $options |
|
| 227 | + * @param callable $c |
|
| 228 | + * @return string |
|
| 229 | + */ |
|
| 230 | + public function navbarRight($options=[], \Closure $c) |
|
| 231 | + { |
|
| 232 | + $output = ''; |
|
| 233 | 233 | |
| 234 | - if (! isset($this->states['nav-section-open'])) |
|
| 235 | - { |
|
| 236 | - $output .= "<section class='top-bar-section'>\n"; |
|
| 237 | - $this->states['nav-section-open'] = true; |
|
| 238 | - } |
|
| 234 | + if (! isset($this->states['nav-section-open'])) |
|
| 235 | + { |
|
| 236 | + $output .= "<section class='top-bar-section'>\n"; |
|
| 237 | + $this->states['nav-section-open'] = true; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - // Class |
|
| 241 | - $classes = $this->buildClassString('right', $options); |
|
| 240 | + // Class |
|
| 241 | + $classes = $this->buildClassString('right', $options); |
|
| 242 | 242 | |
| 243 | - // ID |
|
| 244 | - $id = $this->buildIdFromOptions($options); |
|
| 243 | + // ID |
|
| 244 | + $id = $this->buildIdFromOptions($options); |
|
| 245 | 245 | |
| 246 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 246 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 247 | 247 | |
| 248 | - $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
| 248 | + $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
| 249 | 249 | |
| 250 | - $output .= $this->runClosure($c); |
|
| 250 | + $output .= $this->runClosure($c); |
|
| 251 | 251 | |
| 252 | - $output .= "</ul>\n"; |
|
| 252 | + $output .= "</ul>\n"; |
|
| 253 | 253 | |
| 254 | - return $output; |
|
| 255 | - } |
|
| 254 | + return $output; |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - //-------------------------------------------------------------------- |
|
| 257 | + //-------------------------------------------------------------------- |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Creates a UL meant to pull to the left within the navbar. |
|
| 261 | - * |
|
| 262 | - * Available options: |
|
| 263 | - * 'class' - An additional class to add |
|
| 264 | - * |
|
| 265 | - * @param array $options |
|
| 266 | - * @param callable $c |
|
| 267 | - * @return string |
|
| 268 | - */ |
|
| 269 | - public function navbarLeft($options=[], \Closure $c) |
|
| 270 | - { |
|
| 271 | - $output = ''; |
|
| 259 | + /** |
|
| 260 | + * Creates a UL meant to pull to the left within the navbar. |
|
| 261 | + * |
|
| 262 | + * Available options: |
|
| 263 | + * 'class' - An additional class to add |
|
| 264 | + * |
|
| 265 | + * @param array $options |
|
| 266 | + * @param callable $c |
|
| 267 | + * @return string |
|
| 268 | + */ |
|
| 269 | + public function navbarLeft($options=[], \Closure $c) |
|
| 270 | + { |
|
| 271 | + $output = ''; |
|
| 272 | 272 | |
| 273 | - if (! isset($this->states['nav-section-open'])) |
|
| 274 | - { |
|
| 275 | - $output .= "<section class='top-bar-section'>\n"; |
|
| 276 | - $this->states['nav-section-open'] = true; |
|
| 277 | - } |
|
| 273 | + if (! isset($this->states['nav-section-open'])) |
|
| 274 | + { |
|
| 275 | + $output .= "<section class='top-bar-section'>\n"; |
|
| 276 | + $this->states['nav-section-open'] = true; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - // Class |
|
| 280 | - $classes = $this->buildClassString('left', $options); |
|
| 279 | + // Class |
|
| 280 | + $classes = $this->buildClassString('left', $options); |
|
| 281 | 281 | |
| 282 | - // ID |
|
| 283 | - $id = $this->buildIdFromOptions($options); |
|
| 282 | + // ID |
|
| 283 | + $id = $this->buildIdFromOptions($options); |
|
| 284 | 284 | |
| 285 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 285 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 286 | 286 | |
| 287 | - $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
| 287 | + $output .= "<ul class='{$classes}' {$id} {$attributes}>\n"; |
|
| 288 | 288 | |
| 289 | - $output .= $this->runClosure($c); |
|
| 289 | + $output .= $this->runClosure($c); |
|
| 290 | 290 | |
| 291 | - $output .= "</ul>\n"; |
|
| 291 | + $output .= "</ul>\n"; |
|
| 292 | 292 | |
| 293 | - return $output; |
|
| 294 | - } |
|
| 293 | + return $output; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - //-------------------------------------------------------------------- |
|
| 296 | + //-------------------------------------------------------------------- |
|
| 297 | 297 | |
| 298 | - public function nav() |
|
| 299 | - { |
|
| 298 | + public function nav() |
|
| 299 | + { |
|
| 300 | 300 | |
| 301 | - } |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - //-------------------------------------------------------------------- |
|
| 303 | + //-------------------------------------------------------------------- |
|
| 304 | 304 | |
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Creates a single list item for use within a nav section. |
|
| 308 | - * |
|
| 309 | - * @param $title |
|
| 310 | - * @param $url |
|
| 311 | - * @param array $options |
|
| 312 | - * @return string |
|
| 313 | - */ |
|
| 314 | - public function navItem($title, $url='#', $options=[], $active=false) |
|
| 315 | - { |
|
| 316 | - $options['active'] = $active; |
|
| 306 | + /** |
|
| 307 | + * Creates a single list item for use within a nav section. |
|
| 308 | + * |
|
| 309 | + * @param $title |
|
| 310 | + * @param $url |
|
| 311 | + * @param array $options |
|
| 312 | + * @return string |
|
| 313 | + */ |
|
| 314 | + public function navItem($title, $url='#', $options=[], $active=false) |
|
| 315 | + { |
|
| 316 | + $options['active'] = $active; |
|
| 317 | 317 | |
| 318 | - $classes = $this->buildClassString('', $options, true); |
|
| 318 | + $classes = $this->buildClassString('', $options, true); |
|
| 319 | 319 | |
| 320 | - $id = $this->buildIdFromOptions($options); |
|
| 320 | + $id = $this->buildIdFromOptions($options); |
|
| 321 | 321 | |
| 322 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 322 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 323 | 323 | |
| 324 | - return "\t<li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>"; |
|
| 325 | - } |
|
| 324 | + return "\t<li {$classes} {$id} {$attributes}><a href='{$url}'>{$title}</a></li>"; |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - //-------------------------------------------------------------------- |
|
| 327 | + //-------------------------------------------------------------------- |
|
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * Builds the shell of a Dropdown button for use within a nav area. |
|
| 331 | - * |
|
| 332 | - * @param $title |
|
| 333 | - * @param array $options |
|
| 334 | - * @param callable $c |
|
| 335 | - */ |
|
| 336 | - public function navDropdown($title,$options=[], \Closure $c) |
|
| 337 | - { |
|
| 338 | - $classes = $this->buildClassString('has-dropdown', $options, true); |
|
| 329 | + /** |
|
| 330 | + * Builds the shell of a Dropdown button for use within a nav area. |
|
| 331 | + * |
|
| 332 | + * @param $title |
|
| 333 | + * @param array $options |
|
| 334 | + * @param callable $c |
|
| 335 | + */ |
|
| 336 | + public function navDropdown($title,$options=[], \Closure $c) |
|
| 337 | + { |
|
| 338 | + $classes = $this->buildClassString('has-dropdown', $options, true); |
|
| 339 | 339 | |
| 340 | - $id = $this->buildIdFromOptions($options); |
|
| 340 | + $id = $this->buildIdFromOptions($options); |
|
| 341 | 341 | |
| 342 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 342 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 343 | 343 | |
| 344 | - $output = "\t<li {$classes} {$id} {$attributes}> |
|
| 344 | + $output = "\t<li {$classes} {$id} {$attributes}> |
|
| 345 | 345 | <a href='#'>{$title}</a> |
| 346 | 346 | <ul class='dropdown'>"; |
| 347 | 347 | |
| 348 | - $output .= $this->runClosure($c); |
|
| 348 | + $output .= $this->runClosure($c); |
|
| 349 | 349 | |
| 350 | - $output .= "\t</ul></li>"; |
|
| 350 | + $output .= "\t</ul></li>"; |
|
| 351 | 351 | |
| 352 | - return $output; |
|
| 353 | - } |
|
| 352 | + return $output; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - //-------------------------------------------------------------------- |
|
| 355 | + //-------------------------------------------------------------------- |
|
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * Creates a divider for use within a nav list. |
|
| 359 | - * |
|
| 360 | - * @return string |
|
| 361 | - */ |
|
| 362 | - public function navDivider() |
|
| 363 | - { |
|
| 364 | - return '<li class="divider"></li>'; |
|
| 365 | - } |
|
| 357 | + /** |
|
| 358 | + * Creates a divider for use within a nav list. |
|
| 359 | + * |
|
| 360 | + * @return string |
|
| 361 | + */ |
|
| 362 | + public function navDivider() |
|
| 363 | + { |
|
| 364 | + return '<li class="divider"></li>'; |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - //-------------------------------------------------------------------- |
|
| 367 | + //-------------------------------------------------------------------- |
|
| 368 | 368 | |
| 369 | - public function sideNav($options=[], \Closure $c) |
|
| 370 | - { |
|
| 371 | - $classes = $this->buildClassString('side-nav', $options, true); |
|
| 369 | + public function sideNav($options=[], \Closure $c) |
|
| 370 | + { |
|
| 371 | + $classes = $this->buildClassString('side-nav', $options, true); |
|
| 372 | 372 | |
| 373 | - $id = $this->buildIdFromOptions($options); |
|
| 373 | + $id = $this->buildIdFromOptions($options); |
|
| 374 | 374 | |
| 375 | - $attributes = $this->buildAttributesFromOptions($options); |
|
| 375 | + $attributes = $this->buildAttributesFromOptions($options); |
|
| 376 | 376 | |
| 377 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 378 | - |
|
| 379 | - $output .= $this->runClosure($c); |
|
| 380 | - |
|
| 381 | - $output .= "</ul>\n"; |
|
| 382 | - |
|
| 383 | - return $output; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - //-------------------------------------------------------------------- |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Creates a list of nav items to function as breadcrumbs for a site. |
|
| 390 | - * |
|
| 391 | - * @param array $options |
|
| 392 | - * @param callable $c |
|
| 393 | - * @return mixed |
|
| 394 | - */ |
|
| 395 | - public function breadcrumb($options=[], \Closure $c) |
|
| 396 | - { |
|
| 397 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumbs', true); |
|
| 398 | - |
|
| 399 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 400 | - |
|
| 401 | - $output .= $this->runClosure($c); |
|
| 402 | - |
|
| 403 | - $output .= "</ul>\n"; |
|
| 404 | - |
|
| 405 | - return $output; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - //-------------------------------------------------------------------- |
|
| 409 | - |
|
| 410 | - //-------------------------------------------------------------------- |
|
| 411 | - // Tables |
|
| 412 | - //-------------------------------------------------------------------- |
|
| 413 | - |
|
| 414 | - public function table() |
|
| 415 | - { |
|
| 416 | - return 'table'; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - //-------------------------------------------------------------------- |
|
| 420 | - |
|
| 421 | - //-------------------------------------------------------------------- |
|
| 422 | - // Buttons |
|
| 423 | - //-------------------------------------------------------------------- |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Creates a simple button. |
|
| 427 | - * |
|
| 428 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 429 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 430 | - * |
|
| 431 | - * @param $title |
|
| 432 | - * @param string $style |
|
| 433 | - * @param array $options |
|
| 434 | - * @return mixed |
|
| 435 | - */ |
|
| 436 | - public function button($title, $style='default', $size='default', $options=[]) |
|
| 437 | - { |
|
| 438 | - $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 439 | - |
|
| 440 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - //-------------------------------------------------------------------- |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Creates a simple link styled as a button. |
|
| 447 | - * |
|
| 448 | - * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 449 | - * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 450 | - * |
|
| 451 | - * @param $title |
|
| 452 | - * @param string $url |
|
| 453 | - * @param string $style |
|
| 454 | - * @param array $options |
|
| 455 | - * @return mixed |
|
| 456 | - */ |
|
| 457 | - public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
| 458 | - { |
|
| 459 | - $class = isset($options['class']) ? $options['class'] .' button' : 'button'; |
|
| 460 | - $options['class'] = $class; |
|
| 461 | - |
|
| 462 | - $tag = "<a {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
| 463 | - |
|
| 464 | - return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - //-------------------------------------------------------------------- |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Helper method to render out our buttons in a DRY manner. |
|
| 471 | - * |
|
| 472 | - * @param $title |
|
| 473 | - * @param $style |
|
| 474 | - * @param $size |
|
| 475 | - * @param $tag |
|
| 476 | - */ |
|
| 477 | - protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
| 478 | - { |
|
| 479 | - $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
| 480 | - $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
| 481 | - |
|
| 482 | - if (! in_array($style, $valid_styles)) |
|
| 483 | - { |
|
| 484 | - $style = 'default'; |
|
| 485 | - $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - $classes = 'btn '; |
|
| 489 | - |
|
| 490 | - // Sizes |
|
| 491 | - switch($size) |
|
| 492 | - { |
|
| 493 | - case 'small': |
|
| 494 | - $classes .= 'small '; |
|
| 495 | - break; |
|
| 496 | - case 'xsmall': |
|
| 497 | - $classes .= 'tiny '; |
|
| 498 | - break; |
|
| 499 | - case 'large': |
|
| 500 | - $classes .= 'large '; |
|
| 501 | - break; |
|
| 502 | - default: |
|
| 503 | - break; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - // Styles |
|
| 507 | - switch ($style) |
|
| 508 | - { |
|
| 509 | - case 'primary': |
|
| 510 | - $classes .= ''; |
|
| 511 | - break; |
|
| 512 | - case 'success': |
|
| 513 | - $classes .= 'success '; |
|
| 514 | - break; |
|
| 515 | - case 'info': |
|
| 516 | - $classes .= 'secondary '; |
|
| 517 | - break; |
|
| 518 | - case 'warning': |
|
| 519 | - $classes .= 'alert '; |
|
| 520 | - break; |
|
| 521 | - case 'danger': |
|
| 522 | - $classes .= 'alert '; |
|
| 523 | - break; |
|
| 524 | - case 'default': |
|
| 525 | - $classes .= 'secondary '; |
|
| 526 | - break; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 530 | - |
|
| 531 | - $tag = str_replace('{classes}', $classes, $tag); |
|
| 532 | - $tag = str_replace('{id}', $id, $tag); |
|
| 533 | - $tag = str_replace('{attributes}', $attributes, $tag); |
|
| 534 | - $tag = str_replace('{title}', $title, $tag); |
|
| 535 | - |
|
| 536 | - // If we're in a button group we need to wrap each item in li tags. |
|
| 537 | - if (isset($this->states['inButtonGroup'])) |
|
| 538 | - { |
|
| 539 | - $tag = '<li>'. $tag .'</li>'; |
|
| 540 | - } |
|
| 541 | - return $tag; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - //-------------------------------------------------------------------- |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Creates button groups wrapping HTML. |
|
| 548 | - * |
|
| 549 | - * @param $options |
|
| 550 | - * @param callable $c |
|
| 551 | - * @return mixed |
|
| 552 | - */ |
|
| 553 | - public function buttonGroup($options, \Closure $c) |
|
| 554 | - { |
|
| 555 | - $this->states['inButtonGroup'] = true; |
|
| 556 | - |
|
| 557 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-group', true); |
|
| 558 | - |
|
| 559 | - $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 560 | - |
|
| 561 | - $output .= $this->runClosure($c); |
|
| 562 | - |
|
| 563 | - $output .= "</ul>\n"; |
|
| 564 | - |
|
| 565 | - unset($this->states['inButtonGroup']); |
|
| 566 | - |
|
| 567 | - return $output; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - //-------------------------------------------------------------------- |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Creates the button bar wrapping HTML. |
|
| 574 | - * |
|
| 575 | - * @param $options |
|
| 576 | - * @param callable $c |
|
| 577 | - * @return mixed |
|
| 578 | - */ |
|
| 579 | - public function buttonBar($options, \Closure $c) |
|
| 580 | - { |
|
| 581 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-bar', true); |
|
| 582 | - |
|
| 583 | - $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 584 | - |
|
| 585 | - $output .= $this->runClosure($c); |
|
| 586 | - |
|
| 587 | - $output .= "</div>\n"; |
|
| 588 | - |
|
| 589 | - return $output; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - //-------------------------------------------------------------------- |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
| 596 | - * by some frameworks. |
|
| 597 | - * |
|
| 598 | - * @param $title |
|
| 599 | - * @param string $style |
|
| 600 | - * @param string $size |
|
| 601 | - * @param array $options |
|
| 602 | - * @param callable $c |
|
| 603 | - * @return mixed |
|
| 604 | - */ |
|
| 605 | - public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
| 606 | - { |
|
| 607 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button split', true); |
|
| 608 | - |
|
| 609 | - $output = "<a href='#' {$classes} {$id} {$attributes}>{$title} <span data-dropdown='drop'></span></a><br>\n |
|
| 377 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 378 | + |
|
| 379 | + $output .= $this->runClosure($c); |
|
| 380 | + |
|
| 381 | + $output .= "</ul>\n"; |
|
| 382 | + |
|
| 383 | + return $output; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + //-------------------------------------------------------------------- |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Creates a list of nav items to function as breadcrumbs for a site. |
|
| 390 | + * |
|
| 391 | + * @param array $options |
|
| 392 | + * @param callable $c |
|
| 393 | + * @return mixed |
|
| 394 | + */ |
|
| 395 | + public function breadcrumb($options=[], \Closure $c) |
|
| 396 | + { |
|
| 397 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'breadcrumbs', true); |
|
| 398 | + |
|
| 399 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 400 | + |
|
| 401 | + $output .= $this->runClosure($c); |
|
| 402 | + |
|
| 403 | + $output .= "</ul>\n"; |
|
| 404 | + |
|
| 405 | + return $output; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + //-------------------------------------------------------------------- |
|
| 409 | + |
|
| 410 | + //-------------------------------------------------------------------- |
|
| 411 | + // Tables |
|
| 412 | + //-------------------------------------------------------------------- |
|
| 413 | + |
|
| 414 | + public function table() |
|
| 415 | + { |
|
| 416 | + return 'table'; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + //-------------------------------------------------------------------- |
|
| 420 | + |
|
| 421 | + //-------------------------------------------------------------------- |
|
| 422 | + // Buttons |
|
| 423 | + //-------------------------------------------------------------------- |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Creates a simple button. |
|
| 427 | + * |
|
| 428 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 429 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 430 | + * |
|
| 431 | + * @param $title |
|
| 432 | + * @param string $style |
|
| 433 | + * @param array $options |
|
| 434 | + * @return mixed |
|
| 435 | + */ |
|
| 436 | + public function button($title, $style='default', $size='default', $options=[]) |
|
| 437 | + { |
|
| 438 | + $tag= "<button type='button' {classes} {id} {attributes}>{$title}</button>"; |
|
| 439 | + |
|
| 440 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + //-------------------------------------------------------------------- |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Creates a simple link styled as a button. |
|
| 447 | + * |
|
| 448 | + * $style can be 'default', 'primary', 'success', 'info', 'warning', 'danger' |
|
| 449 | + * $size can be 'default', 'small', 'xsmall', 'large' |
|
| 450 | + * |
|
| 451 | + * @param $title |
|
| 452 | + * @param string $url |
|
| 453 | + * @param string $style |
|
| 454 | + * @param array $options |
|
| 455 | + * @return mixed |
|
| 456 | + */ |
|
| 457 | + public function buttonLink($title, $url='#', $style='default', $size='default', $options=[]) |
|
| 458 | + { |
|
| 459 | + $class = isset($options['class']) ? $options['class'] .' button' : 'button'; |
|
| 460 | + $options['class'] = $class; |
|
| 461 | + |
|
| 462 | + $tag = "<a {classes} {id} {attributes} role='button'>{$title}</a>"; |
|
| 463 | + |
|
| 464 | + return $this->renderButtonElement($title, $style, $size, $options, $tag); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + //-------------------------------------------------------------------- |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Helper method to render out our buttons in a DRY manner. |
|
| 471 | + * |
|
| 472 | + * @param $title |
|
| 473 | + * @param $style |
|
| 474 | + * @param $size |
|
| 475 | + * @param $tag |
|
| 476 | + */ |
|
| 477 | + protected function renderButtonElement($title, $style, $size, $options, $tag) |
|
| 478 | + { |
|
| 479 | + $valid_styles = ['default', 'primary', 'success', 'info', 'warning', 'danger']; |
|
| 480 | + $valid_sizes = ['default', 'small', 'xsmall', 'large']; |
|
| 481 | + |
|
| 482 | + if (! in_array($style, $valid_styles)) |
|
| 483 | + { |
|
| 484 | + $style = 'default'; |
|
| 485 | + $options['attributes'][] = 'data-error="Invalid Style passed to button method."'; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + $classes = 'btn '; |
|
| 489 | + |
|
| 490 | + // Sizes |
|
| 491 | + switch($size) |
|
| 492 | + { |
|
| 493 | + case 'small': |
|
| 494 | + $classes .= 'small '; |
|
| 495 | + break; |
|
| 496 | + case 'xsmall': |
|
| 497 | + $classes .= 'tiny '; |
|
| 498 | + break; |
|
| 499 | + case 'large': |
|
| 500 | + $classes .= 'large '; |
|
| 501 | + break; |
|
| 502 | + default: |
|
| 503 | + break; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + // Styles |
|
| 507 | + switch ($style) |
|
| 508 | + { |
|
| 509 | + case 'primary': |
|
| 510 | + $classes .= ''; |
|
| 511 | + break; |
|
| 512 | + case 'success': |
|
| 513 | + $classes .= 'success '; |
|
| 514 | + break; |
|
| 515 | + case 'info': |
|
| 516 | + $classes .= 'secondary '; |
|
| 517 | + break; |
|
| 518 | + case 'warning': |
|
| 519 | + $classes .= 'alert '; |
|
| 520 | + break; |
|
| 521 | + case 'danger': |
|
| 522 | + $classes .= 'alert '; |
|
| 523 | + break; |
|
| 524 | + case 'default': |
|
| 525 | + $classes .= 'secondary '; |
|
| 526 | + break; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, $classes, true); |
|
| 530 | + |
|
| 531 | + $tag = str_replace('{classes}', $classes, $tag); |
|
| 532 | + $tag = str_replace('{id}', $id, $tag); |
|
| 533 | + $tag = str_replace('{attributes}', $attributes, $tag); |
|
| 534 | + $tag = str_replace('{title}', $title, $tag); |
|
| 535 | + |
|
| 536 | + // If we're in a button group we need to wrap each item in li tags. |
|
| 537 | + if (isset($this->states['inButtonGroup'])) |
|
| 538 | + { |
|
| 539 | + $tag = '<li>'. $tag .'</li>'; |
|
| 540 | + } |
|
| 541 | + return $tag; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + //-------------------------------------------------------------------- |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Creates button groups wrapping HTML. |
|
| 548 | + * |
|
| 549 | + * @param $options |
|
| 550 | + * @param callable $c |
|
| 551 | + * @return mixed |
|
| 552 | + */ |
|
| 553 | + public function buttonGroup($options, \Closure $c) |
|
| 554 | + { |
|
| 555 | + $this->states['inButtonGroup'] = true; |
|
| 556 | + |
|
| 557 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-group', true); |
|
| 558 | + |
|
| 559 | + $output = "<ul {$classes} {$id} {$attributes}>\n"; |
|
| 560 | + |
|
| 561 | + $output .= $this->runClosure($c); |
|
| 562 | + |
|
| 563 | + $output .= "</ul>\n"; |
|
| 564 | + |
|
| 565 | + unset($this->states['inButtonGroup']); |
|
| 566 | + |
|
| 567 | + return $output; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + //-------------------------------------------------------------------- |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Creates the button bar wrapping HTML. |
|
| 574 | + * |
|
| 575 | + * @param $options |
|
| 576 | + * @param callable $c |
|
| 577 | + * @return mixed |
|
| 578 | + */ |
|
| 579 | + public function buttonBar($options, \Closure $c) |
|
| 580 | + { |
|
| 581 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button-bar', true); |
|
| 582 | + |
|
| 583 | + $output = "<div {$classes} {$id} {$attributes}>\n"; |
|
| 584 | + |
|
| 585 | + $output .= $this->runClosure($c); |
|
| 586 | + |
|
| 587 | + $output .= "</div>\n"; |
|
| 588 | + |
|
| 589 | + return $output; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + //-------------------------------------------------------------------- |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Creates a button that also has a dropdown menu. Also called Split Buttons |
|
| 596 | + * by some frameworks. |
|
| 597 | + * |
|
| 598 | + * @param $title |
|
| 599 | + * @param string $style |
|
| 600 | + * @param string $size |
|
| 601 | + * @param array $options |
|
| 602 | + * @param callable $c |
|
| 603 | + * @return mixed |
|
| 604 | + */ |
|
| 605 | + public function buttonDropdown($title, $style='default', $size='default', $options=[], \Closure $c) |
|
| 606 | + { |
|
| 607 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'button split', true); |
|
| 608 | + |
|
| 609 | + $output = "<a href='#' {$classes} {$id} {$attributes}>{$title} <span data-dropdown='drop'></span></a><br>\n |
|
| 610 | 610 | <ul id='drop' class='f-dropdown' data-dropdown-content>\n"; |
| 611 | 611 | |
| 612 | - $output .= $this->runClosure($c); |
|
| 613 | - |
|
| 614 | - $output .= "</ul>\n"; |
|
| 615 | - |
|
| 616 | - return $output; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - //-------------------------------------------------------------------- |
|
| 620 | - |
|
| 621 | - //-------------------------------------------------------------------- |
|
| 622 | - // Notices |
|
| 623 | - //-------------------------------------------------------------------- |
|
| 624 | - |
|
| 625 | - /** |
|
| 626 | - * Creates an 'alert-box' style of notice grid. |
|
| 627 | - * |
|
| 628 | - * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
| 629 | - * |
|
| 630 | - * @param $content |
|
| 631 | - * @param string $style |
|
| 632 | - * @param bool $closable |
|
| 633 | - * @return mixed |
|
| 634 | - */ |
|
| 635 | - public function notice($content, $style='success', $closable=true, $options=[]) |
|
| 636 | - { |
|
| 637 | - list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert-box ', false); |
|
| 638 | - |
|
| 639 | - // Styles |
|
| 640 | - switch ($style) |
|
| 641 | - { |
|
| 642 | - case 'success': |
|
| 643 | - $classes .= ' success '; |
|
| 644 | - break; |
|
| 645 | - case 'info': |
|
| 646 | - $classes .= ' secondary '; |
|
| 647 | - break; |
|
| 648 | - case 'warning': |
|
| 649 | - $classes .= ' alert '; |
|
| 650 | - break; |
|
| 651 | - case 'danger': |
|
| 652 | - $classes .= ' alert '; |
|
| 653 | - break; |
|
| 654 | - case 'default': |
|
| 655 | - $classes .= ' secondary '; |
|
| 656 | - break; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - $output = "<div data-alert class='{$classes}'>\n"; |
|
| 660 | - |
|
| 661 | - $output .= "\t$content\n"; |
|
| 662 | - |
|
| 663 | - if ($closable) |
|
| 664 | - { |
|
| 665 | - $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - $output .= "</div>\n"; |
|
| 669 | - |
|
| 670 | - return $output; |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - //-------------------------------------------------------------------- |
|
| 612 | + $output .= $this->runClosure($c); |
|
| 613 | + |
|
| 614 | + $output .= "</ul>\n"; |
|
| 615 | + |
|
| 616 | + return $output; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + //-------------------------------------------------------------------- |
|
| 620 | + |
|
| 621 | + //-------------------------------------------------------------------- |
|
| 622 | + // Notices |
|
| 623 | + //-------------------------------------------------------------------- |
|
| 624 | + |
|
| 625 | + /** |
|
| 626 | + * Creates an 'alert-box' style of notice grid. |
|
| 627 | + * |
|
| 628 | + * $style can be 'default', 'success', 'info', 'warning', 'danger' |
|
| 629 | + * |
|
| 630 | + * @param $content |
|
| 631 | + * @param string $style |
|
| 632 | + * @param bool $closable |
|
| 633 | + * @return mixed |
|
| 634 | + */ |
|
| 635 | + public function notice($content, $style='success', $closable=true, $options=[]) |
|
| 636 | + { |
|
| 637 | + list($classes, $id, $attributes) = $this->parseStandardOptions($options, 'alert-box ', false); |
|
| 638 | + |
|
| 639 | + // Styles |
|
| 640 | + switch ($style) |
|
| 641 | + { |
|
| 642 | + case 'success': |
|
| 643 | + $classes .= ' success '; |
|
| 644 | + break; |
|
| 645 | + case 'info': |
|
| 646 | + $classes .= ' secondary '; |
|
| 647 | + break; |
|
| 648 | + case 'warning': |
|
| 649 | + $classes .= ' alert '; |
|
| 650 | + break; |
|
| 651 | + case 'danger': |
|
| 652 | + $classes .= ' alert '; |
|
| 653 | + break; |
|
| 654 | + case 'default': |
|
| 655 | + $classes .= ' secondary '; |
|
| 656 | + break; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + $output = "<div data-alert class='{$classes}'>\n"; |
|
| 660 | + |
|
| 661 | + $output .= "\t$content\n"; |
|
| 662 | + |
|
| 663 | + if ($closable) |
|
| 664 | + { |
|
| 665 | + $output .= "\t<a href='#' class='close'>×</a>\n"; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + $output .= "</div>\n"; |
|
| 669 | + |
|
| 670 | + return $output; |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + //-------------------------------------------------------------------- |
|
| 674 | 674 | |
| 675 | 675 | } |
@@ -239,17 +239,17 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | //-------------------------------------------------------------------- |
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * Creates the new APIController - based resource with basic CRUD. |
|
| 244 | - * |
|
| 245 | - * @param $single |
|
| 246 | - * @param $plural |
|
| 247 | - * @param $version |
|
| 248 | - * |
|
| 249 | - * @return $this |
|
| 250 | - * @internal param $name |
|
| 251 | - * |
|
| 252 | - */ |
|
| 242 | + /** |
|
| 243 | + * Creates the new APIController - based resource with basic CRUD. |
|
| 244 | + * |
|
| 245 | + * @param $single |
|
| 246 | + * @param $plural |
|
| 247 | + * @param $version |
|
| 248 | + * |
|
| 249 | + * @return $this |
|
| 250 | + * @internal param $name |
|
| 251 | + * |
|
| 252 | + */ |
|
| 253 | 253 | private function createController( $single, $plural, $version ) |
| 254 | 254 | { |
| 255 | 255 | $data = [ |
@@ -268,44 +268,44 @@ discard block |
||
| 268 | 268 | |
| 269 | 269 | //-------------------------------------------------------------------- |
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Creates the language file to accompany the controller. |
|
| 273 | - * |
|
| 274 | - * @param $single |
|
| 275 | - * @param $plural |
|
| 276 | - * @param $version |
|
| 277 | - * |
|
| 278 | - * @return $this |
|
| 279 | - */ |
|
| 271 | + /** |
|
| 272 | + * Creates the language file to accompany the controller. |
|
| 273 | + * |
|
| 274 | + * @param $single |
|
| 275 | + * @param $plural |
|
| 276 | + * @param $version |
|
| 277 | + * |
|
| 278 | + * @return $this |
|
| 279 | + */ |
|
| 280 | 280 | private function createLanguage( $single, $plural, $version ) |
| 281 | 281 | { |
| 282 | - $data = [ |
|
| 283 | - 'plural' => $plural, |
|
| 284 | - 'single' => $single, |
|
| 285 | - 'uc_single' => ucfirst($single), |
|
| 286 | - 'uc_plural' => ucfirst($plural), |
|
| 287 | - ]; |
|
| 282 | + $data = [ |
|
| 283 | + 'plural' => $plural, |
|
| 284 | + 'single' => $single, |
|
| 285 | + 'uc_single' => ucfirst($single), |
|
| 286 | + 'uc_plural' => ucfirst($plural), |
|
| 287 | + ]; |
|
| 288 | 288 | |
| 289 | - $destination = APPPATH ."language/english/api_{$plural}_lang.php"; |
|
| 289 | + $destination = APPPATH ."language/english/api_{$plural}_lang.php"; |
|
| 290 | 290 | |
| 291 | - return $this->copyTemplate( 'lang', $destination, $data, $this->overwrite ); |
|
| 291 | + return $this->copyTemplate( 'lang', $destination, $data, $this->overwrite ); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | //-------------------------------------------------------------------- |
| 295 | 295 | |
| 296 | - /** |
|
| 297 | - * Creates the API Blueprint file for that resource in |
|
| 298 | - * APPPATH/docs/api |
|
| 299 | - * |
|
| 300 | - * @param $single |
|
| 301 | - * @param $plural |
|
| 302 | - * @param $version |
|
| 303 | - * @param $model |
|
| 304 | - * |
|
| 305 | - * @return $this |
|
| 306 | - * @internal param $name |
|
| 307 | - * |
|
| 308 | - */ |
|
| 296 | + /** |
|
| 297 | + * Creates the API Blueprint file for that resource in |
|
| 298 | + * APPPATH/docs/api |
|
| 299 | + * |
|
| 300 | + * @param $single |
|
| 301 | + * @param $plural |
|
| 302 | + * @param $version |
|
| 303 | + * @param $model |
|
| 304 | + * |
|
| 305 | + * @return $this |
|
| 306 | + * @internal param $name |
|
| 307 | + * |
|
| 308 | + */ |
|
| 309 | 309 | private function createBlueprint( $single, $plural, $version, $model ) |
| 310 | 310 | { |
| 311 | 311 | $version = rtrim($version, '/'); |
@@ -315,10 +315,10 @@ discard block |
||
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | // Load the model so we can use the correct table to use |
| 318 | - $model = strtolower( str_replace('.php', '', $model) ); |
|
| 318 | + $model = strtolower( str_replace('.php', '', $model) ); |
|
| 319 | 319 | $this->load->model( $model, $model, true ); |
| 320 | 320 | |
| 321 | - $obj = $this->formatObject($model); |
|
| 321 | + $obj = $this->formatObject($model); |
|
| 322 | 322 | |
| 323 | 323 | |
| 324 | 324 | $data = [ |
@@ -328,139 +328,139 @@ discard block |
||
| 328 | 328 | 'uc_plural' => ucfirst($plural), |
| 329 | 329 | 'version' => $version, |
| 330 | 330 | 'site_url' => site_url(), |
| 331 | - 'formatted' => $obj |
|
| 331 | + 'formatted' => $obj |
|
| 332 | 332 | ]; |
| 333 | 333 | |
| 334 | 334 | $destination = APPPATH .'docs/api/'. $version . $plural .'.md'; |
| 335 | 335 | |
| 336 | 336 | $success = $this->copyTemplate( 'blueprint', $destination, $data, $this->overwrite ); |
| 337 | 337 | |
| 338 | - if (! $this->updateTOC($plural, $version)) |
|
| 339 | - { |
|
| 340 | - CLI::write("\tUnable to modify the toc file.", 'light_red'); |
|
| 341 | - } |
|
| 338 | + if (! $this->updateTOC($plural, $version)) |
|
| 339 | + { |
|
| 340 | + CLI::write("\tUnable to modify the toc file.", 'light_red'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return $success; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + //-------------------------------------------------------------------- |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Modifies the _toc.ini file (or creates) for the specified Blueprint docs. |
|
| 350 | + * |
|
| 351 | + * @param $plural |
|
| 352 | + * @param $version |
|
| 353 | + * |
|
| 354 | + * @return $this|bool |
|
| 355 | + */ |
|
| 356 | + private function updateTOC( $plural, $version ) |
|
| 357 | + { |
|
| 358 | + $path = APPPATH .'docs/_toc.ini'; |
|
| 359 | + |
|
| 360 | + // We need a TOC file to exist if we're going to modify it silly. |
|
| 361 | + if (! file_exists($path)) |
|
| 362 | + { |
|
| 363 | + if (! $this->copyTemplate('toc', $path)) |
|
| 364 | + { |
|
| 365 | + return false; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + $version = rtrim($version, '/ '); |
|
| 370 | + if (! empty($version)) |
|
| 371 | + { |
|
| 372 | + $version .= '/'; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + $ucname = ucfirst($plural); |
|
| 376 | + |
|
| 377 | + $content = "api/{$version}{$plural}\t= {$ucname}\n"; |
|
| 378 | + |
|
| 379 | + return $this->injectIntoFile($path, $content); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + //-------------------------------------------------------------------- |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Creates a generic representation of the object from the database |
|
| 386 | + * table. |
|
| 387 | + * |
|
| 388 | + * @param $model |
|
| 389 | + * |
|
| 390 | + * @return string |
|
| 391 | + */ |
|
| 392 | + private function formatObject( $model ) |
|
| 393 | + { |
|
| 394 | + $fields = $this->db->field_data($this->$model->table_name); |
|
| 395 | + |
|
| 396 | + $obj = ''; |
|
| 397 | + |
|
| 398 | + foreach ($fields as $field) |
|
| 399 | + { |
|
| 400 | + $obj .= "\"$field->name\": "; |
|
| 342 | 401 | |
| 343 | - return $success; |
|
| 402 | + switch ($field->type) |
|
| 403 | + { |
|
| 404 | + case 'tinyint': |
|
| 405 | + $obj .= "0,\n"; |
|
| 406 | + break; |
|
| 407 | + case 'int': |
|
| 408 | + case 'bigint': |
|
| 409 | + $obj .= "1234,\n"; |
|
| 410 | + break; |
|
| 411 | + case 'float': |
|
| 412 | + case 'double': |
|
| 413 | + $obj .= "123.45,\n"; |
|
| 414 | + break; |
|
| 415 | + case 'date': |
|
| 416 | + $obj .= date("\"Y-m-d\",\n"); |
|
| 417 | + break; |
|
| 418 | + case 'datetime': |
|
| 419 | + $obj .= date("\"Y-m-d H:i:s\",\n"); |
|
| 420 | + break; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if ($field->name == 'email') |
|
| 424 | + { |
|
| 425 | + $obj .= "\"[email protected]\",\n"; |
|
| 426 | + } |
|
| 427 | + else if (strpos('name', $field->name) !== false) |
|
| 428 | + { |
|
| 429 | + $obj .= "\"Lefty\",\n"; |
|
| 430 | + } |
|
| 431 | + else if (in_array($field->type, ['char', 'varchar', 'text'])) |
|
| 432 | + { |
|
| 433 | + $obj .= "\"Some default string\",\n"; |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + return $obj; |
|
| 344 | 438 | } |
| 345 | 439 | |
| 346 | 440 | //-------------------------------------------------------------------- |
| 347 | 441 | |
| 348 | - /** |
|
| 349 | - * Modifies the _toc.ini file (or creates) for the specified Blueprint docs. |
|
| 350 | - * |
|
| 351 | - * @param $plural |
|
| 352 | - * @param $version |
|
| 353 | - * |
|
| 354 | - * @return $this|bool |
|
| 355 | - */ |
|
| 356 | - private function updateTOC( $plural, $version ) |
|
| 357 | - { |
|
| 358 | - $path = APPPATH .'docs/_toc.ini'; |
|
| 359 | - |
|
| 360 | - // We need a TOC file to exist if we're going to modify it silly. |
|
| 361 | - if (! file_exists($path)) |
|
| 362 | - { |
|
| 363 | - if (! $this->copyTemplate('toc', $path)) |
|
| 364 | - { |
|
| 365 | - return false; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - $version = rtrim($version, '/ '); |
|
| 370 | - if (! empty($version)) |
|
| 371 | - { |
|
| 372 | - $version .= '/'; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - $ucname = ucfirst($plural); |
|
| 376 | - |
|
| 377 | - $content = "api/{$version}{$plural}\t= {$ucname}\n"; |
|
| 378 | - |
|
| 379 | - return $this->injectIntoFile($path, $content); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - //-------------------------------------------------------------------- |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Creates a generic representation of the object from the database |
|
| 386 | - * table. |
|
| 387 | - * |
|
| 388 | - * @param $model |
|
| 389 | - * |
|
| 390 | - * @return string |
|
| 391 | - */ |
|
| 392 | - private function formatObject( $model ) |
|
| 393 | - { |
|
| 394 | - $fields = $this->db->field_data($this->$model->table_name); |
|
| 395 | - |
|
| 396 | - $obj = ''; |
|
| 397 | - |
|
| 398 | - foreach ($fields as $field) |
|
| 399 | - { |
|
| 400 | - $obj .= "\"$field->name\": "; |
|
| 401 | - |
|
| 402 | - switch ($field->type) |
|
| 403 | - { |
|
| 404 | - case 'tinyint': |
|
| 405 | - $obj .= "0,\n"; |
|
| 406 | - break; |
|
| 407 | - case 'int': |
|
| 408 | - case 'bigint': |
|
| 409 | - $obj .= "1234,\n"; |
|
| 410 | - break; |
|
| 411 | - case 'float': |
|
| 412 | - case 'double': |
|
| 413 | - $obj .= "123.45,\n"; |
|
| 414 | - break; |
|
| 415 | - case 'date': |
|
| 416 | - $obj .= date("\"Y-m-d\",\n"); |
|
| 417 | - break; |
|
| 418 | - case 'datetime': |
|
| 419 | - $obj .= date("\"Y-m-d H:i:s\",\n"); |
|
| 420 | - break; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if ($field->name == 'email') |
|
| 424 | - { |
|
| 425 | - $obj .= "\"[email protected]\",\n"; |
|
| 426 | - } |
|
| 427 | - else if (strpos('name', $field->name) !== false) |
|
| 428 | - { |
|
| 429 | - $obj .= "\"Lefty\",\n"; |
|
| 430 | - } |
|
| 431 | - else if (in_array($field->type, ['char', 'varchar', 'text'])) |
|
| 432 | - { |
|
| 433 | - $obj .= "\"Some default string\",\n"; |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - return $obj; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - //-------------------------------------------------------------------- |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * Modifies the routes file to include a line for the API endpoints |
|
| 444 | - * for this resource. |
|
| 445 | - * |
|
| 446 | - * @param string $plural |
|
| 447 | - * @param string $version |
|
| 448 | - * |
|
| 449 | - * @return $this |
|
| 450 | - */ |
|
| 442 | + /** |
|
| 443 | + * Modifies the routes file to include a line for the API endpoints |
|
| 444 | + * for this resource. |
|
| 445 | + * |
|
| 446 | + * @param string $plural |
|
| 447 | + * @param string $version |
|
| 448 | + * |
|
| 449 | + * @return $this |
|
| 450 | + */ |
|
| 451 | 451 | private function addRoutes( $plural, $version ) |
| 452 | 452 | { |
| 453 | - $path = APPPATH .'config/routes.php'; |
|
| 453 | + $path = APPPATH .'config/routes.php'; |
|
| 454 | 454 | |
| 455 | - $version = rtrim($version, ', '); |
|
| 456 | - if (! empty($version)) |
|
| 457 | - { |
|
| 458 | - $version .='/'; |
|
| 459 | - } |
|
| 455 | + $version = rtrim($version, ', '); |
|
| 456 | + if (! empty($version)) |
|
| 457 | + { |
|
| 458 | + $version .='/'; |
|
| 459 | + } |
|
| 460 | 460 | |
| 461 | - $content = "\$routes->resources('{$version}{$plural}');\n"; |
|
| 461 | + $content = "\$routes->resources('{$version}{$plural}');\n"; |
|
| 462 | 462 | |
| 463 | - return $this->injectIntoFile($path, $content, ['after' => "// Auto-generated routes go here\n"]); |
|
| 463 | + return $this->injectIntoFile($path, $content, ['after' => "// Auto-generated routes go here\n"]); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | //-------------------------------------------------------------------- |
@@ -203,20 +203,20 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | if ( empty( $fields ) ) |
| 205 | 205 | { |
| 206 | - // If we have a model, we can get our fields from there |
|
| 207 | - if (! empty($this->options['model'])) |
|
| 208 | - { |
|
| 209 | - $fields = $this->getFieldsFromModel( $this->options['model'] ); |
|
| 210 | - |
|
| 211 | - if (empty($fields)) |
|
| 212 | - { |
|
| 213 | - return NULL; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - else |
|
| 217 | - { |
|
| 218 | - return NULL; |
|
| 219 | - } |
|
| 206 | + // If we have a model, we can get our fields from there |
|
| 207 | + if (! empty($this->options['model'])) |
|
| 208 | + { |
|
| 209 | + $fields = $this->getFieldsFromModel( $this->options['model'] ); |
|
| 210 | + |
|
| 211 | + if (empty($fields)) |
|
| 212 | + { |
|
| 213 | + return NULL; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + else |
|
| 217 | + { |
|
| 218 | + return NULL; |
|
| 219 | + } |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | $fields = explode( ' ', $fields ); |
@@ -277,36 +277,36 @@ discard block |
||
| 277 | 277 | |
| 278 | 278 | //-------------------------------------------------------------------- |
| 279 | 279 | |
| 280 | - private function getFieldsFromModel( $model ) |
|
| 281 | - { |
|
| 282 | - $this->load->model($model); |
|
| 280 | + private function getFieldsFromModel( $model ) |
|
| 281 | + { |
|
| 282 | + $this->load->model($model); |
|
| 283 | 283 | |
| 284 | - if (! $this->db->table_exists( $this->$model->table() )) |
|
| 285 | - { |
|
| 286 | - return ''; |
|
| 287 | - } |
|
| 284 | + if (! $this->db->table_exists( $this->$model->table() )) |
|
| 285 | + { |
|
| 286 | + return ''; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - $fields = $this->db->field_data( $this->$model->table() ); |
|
| 289 | + $fields = $this->db->field_data( $this->$model->table() ); |
|
| 290 | 290 | |
| 291 | - $return = ''; |
|
| 291 | + $return = ''; |
|
| 292 | 292 | |
| 293 | - // Prepare the fields in a string format like |
|
| 294 | - // it would have been passed on the CLI |
|
| 295 | - foreach ($fields as $field) |
|
| 296 | - { |
|
| 297 | - $temp = $field->name .':'. $field->type; |
|
| 293 | + // Prepare the fields in a string format like |
|
| 294 | + // it would have been passed on the CLI |
|
| 295 | + foreach ($fields as $field) |
|
| 296 | + { |
|
| 297 | + $temp = $field->name .':'. $field->type; |
|
| 298 | 298 | |
| 299 | - if (! empty($field->max_length)) |
|
| 300 | - { |
|
| 301 | - $temp .= ':'. $field->max_length; |
|
| 302 | - } |
|
| 299 | + if (! empty($field->max_length)) |
|
| 300 | + { |
|
| 301 | + $temp .= ':'. $field->max_length; |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - $return .= ' '. $temp; |
|
| 305 | - } |
|
| 304 | + $return .= ' '. $temp; |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - return $return; |
|
| 308 | - } |
|
| 307 | + return $return; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - //-------------------------------------------------------------------- |
|
| 310 | + //-------------------------------------------------------------------- |
|
| 311 | 311 | |
| 312 | 312 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | if (! empty($model) ) |
| 25 | 25 | { |
| 26 | - $index_method = <<<EOD |
|
| 26 | + $index_method = <<<EOD |
|
| 27 | 27 | \$this->load->library('table'); |
| 28 | 28 | |
| 29 | 29 | \$offset = \$this->uri->segment( \$this->uri->total_segments() ); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | if (! empty($model)) |
| 46 | 46 | { |
| 47 | - $create_method = <<<EOD |
|
| 47 | + $create_method = <<<EOD |
|
| 48 | 48 | \$this->load->helper('form'); |
| 49 | 49 | \$this->load->helper('inflector'); |
| 50 | 50 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | if (! empty($model)) |
| 74 | 74 | { |
| 75 | - $show_method = <<<EOD |
|
| 75 | + $show_method = <<<EOD |
|
| 76 | 76 | \$item = \$this->{$lower_model}->find(\$id); |
| 77 | 77 | |
| 78 | 78 | if (! \$item) |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | if (! empty($model)) |
| 96 | 96 | { |
| 97 | - $update_method = <<<EOD |
|
| 97 | + $update_method = <<<EOD |
|
| 98 | 98 | \$this->load->helper('form'); |
| 99 | 99 | \$this->load->helper('inflector'); |
| 100 | 100 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | if (! empty($model)) |
| 127 | 127 | { |
| 128 | - $delete_method = <<<EOD |
|
| 128 | + $delete_method = <<<EOD |
|
| 129 | 129 | if (\$this->{$lower_model}->delete(\$id)) |
| 130 | 130 | { |
| 131 | 131 | \$this->setMessage('Successfully deleted item.', 'success'); |
@@ -145,12 +145,12 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | if ($themed) |
| 147 | 147 | { |
| 148 | - $index_method .= "\$this->render();"; |
|
| 149 | - $create_method .= "\$this->render();"; |
|
| 150 | - $show_method .= "\$this->render();"; |
|
| 151 | - $update_method .= "\$this->render();"; |
|
| 148 | + $index_method .= "\$this->render();"; |
|
| 149 | + $create_method .= "\$this->render();"; |
|
| 150 | + $show_method .= "\$this->render();"; |
|
| 151 | + $update_method .= "\$this->render();"; |
|
| 152 | 152 | |
| 153 | - $fields = " |
|
| 153 | + $fields = " |
|
| 154 | 154 | /** |
| 155 | 155 | * Allows per-controller override of theme. |
| 156 | 156 | * @var null |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | |
| 33 | 33 | $descriptions = [ |
| 34 | - 'controller' => ['controller <name> [<base>]', 'Creates a new controller file that extends from <base> or BaseController.'] |
|
| 34 | + 'controller' => ['controller <name> [<base>]', 'Creates a new controller file that extends from <base> or BaseController.'] |
|
| 35 | 35 | ]; |
| 36 | 36 | |
| 37 | 37 | $long_description = <<<EOT |
@@ -4,43 +4,43 @@ |
||
| 4 | 4 | |
| 5 | 5 | <?= $uikit->row([], function() use($uikit, $fields) { |
| 6 | 6 | |
| 7 | - $sizes = [ |
|
| 8 | - 's' => 12, |
|
| 9 | - 'm' => 6, |
|
| 10 | - 'l' => 4 |
|
| 11 | - ]; |
|
| 12 | - echo $uikit->column(['sizes' => $sizes], function() use($uikit, $fields) { |
|
| 13 | - |
|
| 14 | - foreach ($fields as $field) |
|
| 15 | - { |
|
| 16 | - echo $uikit->inputWrap( humanize($field['name']), null, function() use($uikit, $field) { |
|
| 17 | - |
|
| 18 | - switch ($field['type']) |
|
| 19 | - { |
|
| 20 | - case 'text': |
|
| 21 | - echo " <input type='text' class='form-control' name='{$field['name']}' />\n"; |
|
| 22 | - break; |
|
| 23 | - case 'number': |
|
| 24 | - echo " <input type='number' class='form-control' name='{$field['name']}' />\n"; |
|
| 25 | - break; |
|
| 26 | - case 'date': |
|
| 27 | - echo " <input type='date' class='form-control' name='{$field['name']}' />\n"; |
|
| 28 | - break; |
|
| 29 | - case 'datetime': |
|
| 30 | - echo " <input type='datetime' class='form-control' name='{$field['name']}' />\n"; |
|
| 31 | - break; |
|
| 32 | - case 'time': |
|
| 33 | - echo " <input type='time' class='form-control' name='{$field['name']}' />\n"; |
|
| 34 | - break; |
|
| 35 | - case 'textarea': |
|
| 36 | - echo " <textarea name='{$field['name']}' class='form-control'></textarea>\n"; |
|
| 37 | - break; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - } ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - }); |
|
| 7 | + $sizes = [ |
|
| 8 | + 's' => 12, |
|
| 9 | + 'm' => 6, |
|
| 10 | + 'l' => 4 |
|
| 11 | + ]; |
|
| 12 | + echo $uikit->column(['sizes' => $sizes], function() use($uikit, $fields) { |
|
| 13 | + |
|
| 14 | + foreach ($fields as $field) |
|
| 15 | + { |
|
| 16 | + echo $uikit->inputWrap( humanize($field['name']), null, function() use($uikit, $field) { |
|
| 17 | + |
|
| 18 | + switch ($field['type']) |
|
| 19 | + { |
|
| 20 | + case 'text': |
|
| 21 | + echo " <input type='text' class='form-control' name='{$field['name']}' />\n"; |
|
| 22 | + break; |
|
| 23 | + case 'number': |
|
| 24 | + echo " <input type='number' class='form-control' name='{$field['name']}' />\n"; |
|
| 25 | + break; |
|
| 26 | + case 'date': |
|
| 27 | + echo " <input type='date' class='form-control' name='{$field['name']}' />\n"; |
|
| 28 | + break; |
|
| 29 | + case 'datetime': |
|
| 30 | + echo " <input type='datetime' class='form-control' name='{$field['name']}' />\n"; |
|
| 31 | + break; |
|
| 32 | + case 'time': |
|
| 33 | + echo " <input type='time' class='form-control' name='{$field['name']}' />\n"; |
|
| 34 | + break; |
|
| 35 | + case 'textarea': |
|
| 36 | + echo " <textarea name='{$field['name']}' class='form-control'></textarea>\n"; |
|
| 37 | + break; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + } ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + }); |
|
| 44 | 44 | |
| 45 | 45 | }); ?> |
| 46 | 46 | |
@@ -5,45 +5,45 @@ |
||
| 5 | 5 | <?= $uikit->row([], function() use($uikit, $fields) |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - $sizes = [ |
|
| 9 | - 's' => 12, |
|
| 10 | - 'm' => 6, |
|
| 11 | - 'l' => 4 |
|
| 12 | - ]; |
|
| 13 | - echo $uikit->column( [ 'sizes' => $sizes ], function () use ( $uikit, $fields ) |
|
| 14 | - { |
|
| 15 | - |
|
| 16 | - foreach ( $fields as $field ) |
|
| 17 | - { |
|
| 18 | - |
|
| 19 | - echo $uikit->inputWrap( humanize( $field['name'] ), NULL, function () use ( $uikit, $field ) |
|
| 20 | - { |
|
| 21 | - |
|
| 22 | - switch ( $field['type'] ) |
|
| 23 | - { |
|
| 24 | - case 'text': |
|
| 25 | - echo " <input type='text' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n"; |
|
| 26 | - break; |
|
| 27 | - case 'number': |
|
| 28 | - echo " <input type='number' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n"; |
|
| 29 | - break; |
|
| 30 | - case 'date': |
|
| 31 | - echo " <input type='date' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n"; |
|
| 32 | - break; |
|
| 33 | - case 'datetime': |
|
| 34 | - echo " <input type='datetime' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n"; |
|
| 35 | - break; |
|
| 36 | - case 'time': |
|
| 37 | - echo " <input type='time' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n"; |
|
| 38 | - break; |
|
| 39 | - case 'textarea': |
|
| 40 | - echo " <textarea class='form-control' name='{$field['name']}'>@= set_value('" . $field["name"] . "') ?></textarea>\n"; |
|
| 41 | - break; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - } ); |
|
| 45 | - } |
|
| 46 | - } ); |
|
| 8 | + $sizes = [ |
|
| 9 | + 's' => 12, |
|
| 10 | + 'm' => 6, |
|
| 11 | + 'l' => 4 |
|
| 12 | + ]; |
|
| 13 | + echo $uikit->column( [ 'sizes' => $sizes ], function () use ( $uikit, $fields ) |
|
| 14 | + { |
|
| 15 | + |
|
| 16 | + foreach ( $fields as $field ) |
|
| 17 | + { |
|
| 18 | + |
|
| 19 | + echo $uikit->inputWrap( humanize( $field['name'] ), NULL, function () use ( $uikit, $field ) |
|
| 20 | + { |
|
| 21 | + |
|
| 22 | + switch ( $field['type'] ) |
|
| 23 | + { |
|
| 24 | + case 'text': |
|
| 25 | + echo " <input type='text' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n"; |
|
| 26 | + break; |
|
| 27 | + case 'number': |
|
| 28 | + echo " <input type='number' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n"; |
|
| 29 | + break; |
|
| 30 | + case 'date': |
|
| 31 | + echo " <input type='date' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n"; |
|
| 32 | + break; |
|
| 33 | + case 'datetime': |
|
| 34 | + echo " <input type='datetime' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n"; |
|
| 35 | + break; |
|
| 36 | + case 'time': |
|
| 37 | + echo " <input type='time' name='{$field['name']}' class='form-control' value='@= set_value('" . $field["name"] . "', \$item->" . $field['name'] . " ) ?>' />\n"; |
|
| 38 | + break; |
|
| 39 | + case 'textarea': |
|
| 40 | + echo " <textarea class='form-control' name='{$field['name']}'>@= set_value('" . $field["name"] . "') ?></textarea>\n"; |
|
| 41 | + break; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + } ); |
|
| 45 | + } |
|
| 46 | + } ); |
|
| 47 | 47 | } ); |
| 48 | 48 | ?> |
| 49 | 49 | |
@@ -12,21 +12,21 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | if ($action == 'create') |
| 14 | 14 | { |
| 15 | - $up = "\$fields = {$fields}; |
|
| 15 | + $up = "\$fields = {$fields}; |
|
| 16 | 16 | |
| 17 | 17 | \$this->dbforge->add_field(\$fields); |
| 18 | 18 | "; |
| 19 | 19 | |
| 20 | - if (! empty($primary_key)) |
|
| 21 | - { |
|
| 22 | - $up .= " \$this->dbforge->add_key('{$primary_key}', true); |
|
| 20 | + if (! empty($primary_key)) |
|
| 21 | + { |
|
| 22 | + $up .= " \$this->dbforge->add_key('{$primary_key}', true); |
|
| 23 | 23 | "; |
| 24 | - } |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - $up .=" \$this->dbforge->create_table('{$table}', true, config_item('migration_create_table_attr') ); |
|
| 26 | + $up .=" \$this->dbforge->create_table('{$table}', true, config_item('migration_create_table_attr') ); |
|
| 27 | 27 | "; |
| 28 | 28 | |
| 29 | - $down = "\$this->dbforge->drop_table('{$table}');"; |
|
| 29 | + $down = "\$this->dbforge->drop_table('{$table}');"; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /* |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | if ($action == 'add' && ! empty($column)) |
| 36 | 36 | { |
| 37 | - $up = "\$field = {$column_string}; |
|
| 37 | + $up = "\$field = {$column_string}; |
|
| 38 | 38 | \$this->dbforge->add_column('{$table}', \$field);"; |
| 39 | 39 | |
| 40 | - $down = "\$this->dbforge->drop_column('{$table}', '{$column}');"; |
|
| 40 | + $down = "\$this->dbforge->drop_column('{$table}', '{$column}');"; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /* |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | if ($action == 'remove' && ! empty($column)) |
| 47 | 47 | { |
| 48 | - $up = "\$this->dbforge->drop_column('{$table}', '{$column}');"; |
|
| 48 | + $up = "\$this->dbforge->drop_column('{$table}', '{$column}');"; |
|
| 49 | 49 | |
| 50 | - $down = "\$field = {$column_string}; |
|
| 50 | + $down = "\$field = {$column_string}; |
|
| 51 | 51 | \$this->dbforge->add_column('{$table}', \$field);"; |
| 52 | 52 | } |
| 53 | 53 | |