@@ -33,50 +33,50 @@ |
||
| 33 | 33 | |
| 34 | 34 | interface MetaInterface { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Sets a single meta item. |
|
| 38 | - * |
|
| 39 | - * @param $alias |
|
| 40 | - * @param null $value |
|
| 41 | - * |
|
| 42 | - * @return mixed |
|
| 43 | - */ |
|
| 44 | - public function set($alias, $value=null); |
|
| 36 | + /** |
|
| 37 | + * Sets a single meta item. |
|
| 38 | + * |
|
| 39 | + * @param $alias |
|
| 40 | + * @param null $value |
|
| 41 | + * |
|
| 42 | + * @return mixed |
|
| 43 | + */ |
|
| 44 | + public function set($alias, $value=null); |
|
| 45 | 45 | |
| 46 | - //-------------------------------------------------------------------- |
|
| 46 | + //-------------------------------------------------------------------- |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Returns a single meta item. |
|
| 50 | - * |
|
| 51 | - * @param $alias |
|
| 52 | - * |
|
| 53 | - * @return mixed |
|
| 54 | - */ |
|
| 55 | - public function get($alias); |
|
| 48 | + /** |
|
| 49 | + * Returns a single meta item. |
|
| 50 | + * |
|
| 51 | + * @param $alias |
|
| 52 | + * |
|
| 53 | + * @return mixed |
|
| 54 | + */ |
|
| 55 | + public function get($alias); |
|
| 56 | 56 | |
| 57 | - //-------------------------------------------------------------------- |
|
| 57 | + //-------------------------------------------------------------------- |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Renders out all defined meta tags. |
|
| 61 | - * |
|
| 62 | - * @param array $show_tags |
|
| 63 | - * |
|
| 64 | - * @return mixed |
|
| 65 | - */ |
|
| 66 | - public function renderTags(); |
|
| 59 | + /** |
|
| 60 | + * Renders out all defined meta tags. |
|
| 61 | + * |
|
| 62 | + * @param array $show_tags |
|
| 63 | + * |
|
| 64 | + * @return mixed |
|
| 65 | + */ |
|
| 66 | + public function renderTags(); |
|
| 67 | 67 | |
| 68 | - //-------------------------------------------------------------------- |
|
| 68 | + //-------------------------------------------------------------------- |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Registers a new HTTP Equivalent meta tag so it can be |
|
| 72 | - * rendered out properly. |
|
| 73 | - * |
|
| 74 | - * @param $name |
|
| 75 | - * |
|
| 76 | - * @return $this |
|
| 77 | - */ |
|
| 78 | - public function registerHTTPEquivTag($name); |
|
| 70 | + /** |
|
| 71 | + * Registers a new HTTP Equivalent meta tag so it can be |
|
| 72 | + * rendered out properly. |
|
| 73 | + * |
|
| 74 | + * @param $name |
|
| 75 | + * |
|
| 76 | + * @return $this |
|
| 77 | + */ |
|
| 78 | + public function registerHTTPEquivTag($name); |
|
| 79 | 79 | |
| 80 | - //-------------------------------------------------------------------- |
|
| 80 | + //-------------------------------------------------------------------- |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -38,219 +38,219 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | interface ThemerInterface |
| 40 | 40 | { |
| 41 | - /** |
|
| 42 | - * The main entryway into rendering a view. This is called from the |
|
| 43 | - * controller and is generally the last method called. |
|
| 44 | - * |
|
| 45 | - * @param string $layout If provided, will override the default layout. |
|
| 46 | - */ |
|
| 47 | - public function render($layout = null); |
|
| 48 | - |
|
| 49 | - //-------------------------------------------------------------------- |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Used within the template layout file to render the current content. |
|
| 53 | - * This content is typically used to display the current view. |
|
| 54 | - */ |
|
| 55 | - public function content(); |
|
| 56 | - |
|
| 57 | - //-------------------------------------------------------------------- |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Sets the active theme to use. This theme should be |
|
| 61 | - * relative to one of the 'theme_paths' folders. |
|
| 62 | - * |
|
| 63 | - * @param $theme |
|
| 64 | - */ |
|
| 65 | - public function setTheme($theme); |
|
| 66 | - |
|
| 67 | - //-------------------------------------------------------------------- |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Returns the current theme. |
|
| 71 | - * |
|
| 72 | - * @return mixed|string |
|
| 73 | - */ |
|
| 74 | - public function theme(); |
|
| 75 | - |
|
| 76 | - //-------------------------------------------------------------------- |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Sets the default theme to use. |
|
| 80 | - * |
|
| 81 | - * @param $theme |
|
| 82 | - * @return mixed |
|
| 83 | - */ |
|
| 84 | - public function setDefaultTheme($theme); |
|
| 85 | - |
|
| 86 | - //-------------------------------------------------------------------- |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Sets the current view file to render. |
|
| 90 | - * |
|
| 91 | - * @param $file |
|
| 92 | - * @return mixed |
|
| 93 | - */ |
|
| 94 | - public function setView($file); |
|
| 95 | - |
|
| 96 | - //-------------------------------------------------------------------- |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Returns the current view. |
|
| 100 | - * |
|
| 101 | - * @return mixed|string |
|
| 102 | - */ |
|
| 103 | - public function view(); |
|
| 104 | - |
|
| 105 | - //-------------------------------------------------------------------- |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Sets the current layout to be used. MUST be the name of one of |
|
| 109 | - * the layout files within the current theme. Case-sensitive. |
|
| 110 | - * |
|
| 111 | - * @param $file |
|
| 112 | - * @return mixed |
|
| 113 | - */ |
|
| 114 | - public function setLayout($file); |
|
| 115 | - |
|
| 116 | - //-------------------------------------------------------------------- |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Returns the active layout. |
|
| 120 | - * |
|
| 121 | - * @return mixed |
|
| 122 | - */ |
|
| 123 | - public function layout(); |
|
| 124 | - |
|
| 125 | - //-------------------------------------------------------------------- |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Stores one or more pieces of data to be passed to the views when |
|
| 129 | - * they are rendered out. |
|
| 130 | - * |
|
| 131 | - * If both $key and $value are ! empty, then it will treat it as a |
|
| 132 | - * key/value pair. If $key is an array of key/value pairs, then $value |
|
| 133 | - * is ignored and each element of the array are made available to the |
|
| 134 | - * view as if it was a single $key/$value pair. |
|
| 135 | - * |
|
| 136 | - * @param string|array $key |
|
| 137 | - * @param mixed $value |
|
| 138 | - */ |
|
| 139 | - public function set($key, $value = null); |
|
| 140 | - |
|
| 141 | - //-------------------------------------------------------------------- |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Returns a value that has been previously set(). |
|
| 145 | - * |
|
| 146 | - * @param $key |
|
| 147 | - * @return mixed |
|
| 148 | - */ |
|
| 149 | - public function get($key); |
|
| 150 | - |
|
| 151 | - //-------------------------------------------------------------------- |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Determines whether or not the view should be parsed with the |
|
| 155 | - * CodeIgniter's parser. |
|
| 156 | - * |
|
| 157 | - * @param bool $parse |
|
| 158 | - * @return mixed |
|
| 159 | - */ |
|
| 160 | - public function parseViews($parse = false); |
|
| 161 | - |
|
| 162 | - //-------------------------------------------------------------------- |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Theme paths allow you to have multiple locations for themes to be |
|
| 166 | - * stored. This might be used for separating themes for different sub- |
|
| 167 | - * applications, or a core theme and user-submitted themes. |
|
| 168 | - * |
|
| 169 | - * @param $alias The name the theme can be referenced by |
|
| 170 | - * @param $path A new path where themes can be found. |
|
| 171 | - * |
|
| 172 | - * @return mixed |
|
| 173 | - */ |
|
| 174 | - public function addThemePath($alias, $path); |
|
| 175 | - |
|
| 176 | - //-------------------------------------------------------------------- |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Removes a single theme path. |
|
| 180 | - * |
|
| 181 | - * @param $alias |
|
| 182 | - */ |
|
| 183 | - public function removeThemePath($alias); |
|
| 184 | - //-------------------------------------------------------------------- |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Loads a view file. Useful to control caching. Intended for use |
|
| 188 | - * from within view files. |
|
| 189 | - * |
|
| 190 | - * You can specify that a view should belong to a theme by prefixing |
|
| 191 | - * the name of the theme and a colon to the view name. For example, |
|
| 192 | - * "admin:header" would try to display the "header.php" file within |
|
| 193 | - * the "admin" theme. |
|
| 194 | - * |
|
| 195 | - * @param string $view |
|
| 196 | - * @param array $data |
|
| 197 | - * @param int $cache_time The number of MINUTES to cache the output |
|
| 198 | - * @return mixed |
|
| 199 | - */ |
|
| 200 | - public function display($view, $data = array(), $cache_time = 0); |
|
| 201 | - |
|
| 202 | - //-------------------------------------------------------------------- |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Sets the variant used when creating view names. These variants can |
|
| 206 | - * be anything, but by default are used to render specific templates |
|
| 207 | - * for desktop, tablet, and phone. The name of the variant is added |
|
| 208 | - * to the view name, joined by a "+" symbol. |
|
| 209 | - * |
|
| 210 | - * Example: |
|
| 211 | - * $this->setVariant('phone'); |
|
| 212 | - * $this->display('header'); |
|
| 213 | - * |
|
| 214 | - * Tries to display "views/header+phone.php" |
|
| 215 | - * |
|
| 216 | - * @param $variant |
|
| 217 | - * @return mixed |
|
| 218 | - */ |
|
| 219 | - public function setVariant($variant); |
|
| 220 | - |
|
| 221 | - //-------------------------------------------------------------------- |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Adds a new variant to the system. |
|
| 225 | - * |
|
| 226 | - * @param $name |
|
| 227 | - * @param $postfix |
|
| 228 | - * @return mixed |
|
| 229 | - */ |
|
| 230 | - public function addVariant($name, $postfix); |
|
| 231 | - |
|
| 232 | - //-------------------------------------------------------------------- |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Removes a variant from the system. |
|
| 236 | - * |
|
| 237 | - * @param $name |
|
| 238 | - * @param $postfix |
|
| 239 | - * @return mixed |
|
| 240 | - */ |
|
| 241 | - public function removeVariant($name); |
|
| 242 | - |
|
| 243 | - //-------------------------------------------------------------------- |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Runs a callback method and returns the contents to the view. |
|
| 247 | - * |
|
| 248 | - * @param $command |
|
| 249 | - * @param int $cache_minutes |
|
| 250 | - * @return mixed |
|
| 251 | - */ |
|
| 252 | - public function call($command, $cache_minutes=0); |
|
| 253 | - |
|
| 254 | - //-------------------------------------------------------------------- |
|
| 41 | + /** |
|
| 42 | + * The main entryway into rendering a view. This is called from the |
|
| 43 | + * controller and is generally the last method called. |
|
| 44 | + * |
|
| 45 | + * @param string $layout If provided, will override the default layout. |
|
| 46 | + */ |
|
| 47 | + public function render($layout = null); |
|
| 48 | + |
|
| 49 | + //-------------------------------------------------------------------- |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Used within the template layout file to render the current content. |
|
| 53 | + * This content is typically used to display the current view. |
|
| 54 | + */ |
|
| 55 | + public function content(); |
|
| 56 | + |
|
| 57 | + //-------------------------------------------------------------------- |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Sets the active theme to use. This theme should be |
|
| 61 | + * relative to one of the 'theme_paths' folders. |
|
| 62 | + * |
|
| 63 | + * @param $theme |
|
| 64 | + */ |
|
| 65 | + public function setTheme($theme); |
|
| 66 | + |
|
| 67 | + //-------------------------------------------------------------------- |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Returns the current theme. |
|
| 71 | + * |
|
| 72 | + * @return mixed|string |
|
| 73 | + */ |
|
| 74 | + public function theme(); |
|
| 75 | + |
|
| 76 | + //-------------------------------------------------------------------- |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Sets the default theme to use. |
|
| 80 | + * |
|
| 81 | + * @param $theme |
|
| 82 | + * @return mixed |
|
| 83 | + */ |
|
| 84 | + public function setDefaultTheme($theme); |
|
| 85 | + |
|
| 86 | + //-------------------------------------------------------------------- |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Sets the current view file to render. |
|
| 90 | + * |
|
| 91 | + * @param $file |
|
| 92 | + * @return mixed |
|
| 93 | + */ |
|
| 94 | + public function setView($file); |
|
| 95 | + |
|
| 96 | + //-------------------------------------------------------------------- |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Returns the current view. |
|
| 100 | + * |
|
| 101 | + * @return mixed|string |
|
| 102 | + */ |
|
| 103 | + public function view(); |
|
| 104 | + |
|
| 105 | + //-------------------------------------------------------------------- |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Sets the current layout to be used. MUST be the name of one of |
|
| 109 | + * the layout files within the current theme. Case-sensitive. |
|
| 110 | + * |
|
| 111 | + * @param $file |
|
| 112 | + * @return mixed |
|
| 113 | + */ |
|
| 114 | + public function setLayout($file); |
|
| 115 | + |
|
| 116 | + //-------------------------------------------------------------------- |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Returns the active layout. |
|
| 120 | + * |
|
| 121 | + * @return mixed |
|
| 122 | + */ |
|
| 123 | + public function layout(); |
|
| 124 | + |
|
| 125 | + //-------------------------------------------------------------------- |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Stores one or more pieces of data to be passed to the views when |
|
| 129 | + * they are rendered out. |
|
| 130 | + * |
|
| 131 | + * If both $key and $value are ! empty, then it will treat it as a |
|
| 132 | + * key/value pair. If $key is an array of key/value pairs, then $value |
|
| 133 | + * is ignored and each element of the array are made available to the |
|
| 134 | + * view as if it was a single $key/$value pair. |
|
| 135 | + * |
|
| 136 | + * @param string|array $key |
|
| 137 | + * @param mixed $value |
|
| 138 | + */ |
|
| 139 | + public function set($key, $value = null); |
|
| 140 | + |
|
| 141 | + //-------------------------------------------------------------------- |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Returns a value that has been previously set(). |
|
| 145 | + * |
|
| 146 | + * @param $key |
|
| 147 | + * @return mixed |
|
| 148 | + */ |
|
| 149 | + public function get($key); |
|
| 150 | + |
|
| 151 | + //-------------------------------------------------------------------- |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Determines whether or not the view should be parsed with the |
|
| 155 | + * CodeIgniter's parser. |
|
| 156 | + * |
|
| 157 | + * @param bool $parse |
|
| 158 | + * @return mixed |
|
| 159 | + */ |
|
| 160 | + public function parseViews($parse = false); |
|
| 161 | + |
|
| 162 | + //-------------------------------------------------------------------- |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Theme paths allow you to have multiple locations for themes to be |
|
| 166 | + * stored. This might be used for separating themes for different sub- |
|
| 167 | + * applications, or a core theme and user-submitted themes. |
|
| 168 | + * |
|
| 169 | + * @param $alias The name the theme can be referenced by |
|
| 170 | + * @param $path A new path where themes can be found. |
|
| 171 | + * |
|
| 172 | + * @return mixed |
|
| 173 | + */ |
|
| 174 | + public function addThemePath($alias, $path); |
|
| 175 | + |
|
| 176 | + //-------------------------------------------------------------------- |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Removes a single theme path. |
|
| 180 | + * |
|
| 181 | + * @param $alias |
|
| 182 | + */ |
|
| 183 | + public function removeThemePath($alias); |
|
| 184 | + //-------------------------------------------------------------------- |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Loads a view file. Useful to control caching. Intended for use |
|
| 188 | + * from within view files. |
|
| 189 | + * |
|
| 190 | + * You can specify that a view should belong to a theme by prefixing |
|
| 191 | + * the name of the theme and a colon to the view name. For example, |
|
| 192 | + * "admin:header" would try to display the "header.php" file within |
|
| 193 | + * the "admin" theme. |
|
| 194 | + * |
|
| 195 | + * @param string $view |
|
| 196 | + * @param array $data |
|
| 197 | + * @param int $cache_time The number of MINUTES to cache the output |
|
| 198 | + * @return mixed |
|
| 199 | + */ |
|
| 200 | + public function display($view, $data = array(), $cache_time = 0); |
|
| 201 | + |
|
| 202 | + //-------------------------------------------------------------------- |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Sets the variant used when creating view names. These variants can |
|
| 206 | + * be anything, but by default are used to render specific templates |
|
| 207 | + * for desktop, tablet, and phone. The name of the variant is added |
|
| 208 | + * to the view name, joined by a "+" symbol. |
|
| 209 | + * |
|
| 210 | + * Example: |
|
| 211 | + * $this->setVariant('phone'); |
|
| 212 | + * $this->display('header'); |
|
| 213 | + * |
|
| 214 | + * Tries to display "views/header+phone.php" |
|
| 215 | + * |
|
| 216 | + * @param $variant |
|
| 217 | + * @return mixed |
|
| 218 | + */ |
|
| 219 | + public function setVariant($variant); |
|
| 220 | + |
|
| 221 | + //-------------------------------------------------------------------- |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Adds a new variant to the system. |
|
| 225 | + * |
|
| 226 | + * @param $name |
|
| 227 | + * @param $postfix |
|
| 228 | + * @return mixed |
|
| 229 | + */ |
|
| 230 | + public function addVariant($name, $postfix); |
|
| 231 | + |
|
| 232 | + //-------------------------------------------------------------------- |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Removes a variant from the system. |
|
| 236 | + * |
|
| 237 | + * @param $name |
|
| 238 | + * @param $postfix |
|
| 239 | + * @return mixed |
|
| 240 | + */ |
|
| 241 | + public function removeVariant($name); |
|
| 242 | + |
|
| 243 | + //-------------------------------------------------------------------- |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Runs a callback method and returns the contents to the view. |
|
| 247 | + * |
|
| 248 | + * @param $command |
|
| 249 | + * @param int $cache_minutes |
|
| 250 | + * @return mixed |
|
| 251 | + */ |
|
| 252 | + public function call($command, $cache_minutes=0); |
|
| 253 | + |
|
| 254 | + //-------------------------------------------------------------------- |
|
| 255 | 255 | |
| 256 | 256 | } |
@@ -35,70 +35,70 @@ discard block |
||
| 35 | 35 | class ViewThemer implements ThemerInterface |
| 36 | 36 | { |
| 37 | 37 | |
| 38 | - protected $theme = ''; |
|
| 38 | + protected $theme = ''; |
|
| 39 | 39 | |
| 40 | - protected $default_theme = null; |
|
| 40 | + protected $default_theme = null; |
|
| 41 | 41 | |
| 42 | 42 | protected $active_theme = null; |
| 43 | 43 | |
| 44 | - protected $layout = 'index'; |
|
| 44 | + protected $layout = 'index'; |
|
| 45 | 45 | |
| 46 | - protected $view = ''; |
|
| 46 | + protected $view = ''; |
|
| 47 | 47 | |
| 48 | - protected $vars = []; |
|
| 48 | + protected $vars = []; |
|
| 49 | 49 | |
| 50 | - protected $folders = []; |
|
| 50 | + protected $folders = []; |
|
| 51 | 51 | |
| 52 | - protected $variants = []; |
|
| 52 | + protected $variants = []; |
|
| 53 | 53 | |
| 54 | - protected $current_variant = ''; |
|
| 54 | + protected $current_variant = ''; |
|
| 55 | 55 | |
| 56 | 56 | protected $parse_views = false; |
| 57 | 57 | |
| 58 | - protected $ci; |
|
| 58 | + protected $ci; |
|
| 59 | 59 | |
| 60 | - //-------------------------------------------------------------------- |
|
| 60 | + //-------------------------------------------------------------------- |
|
| 61 | 61 | |
| 62 | - public function __construct($ci) |
|
| 63 | - { |
|
| 64 | - $this->ci = $ci; |
|
| 62 | + public function __construct($ci) |
|
| 63 | + { |
|
| 64 | + $this->ci = $ci; |
|
| 65 | 65 | |
| 66 | - $this->parse_views = config_item('theme.parse_views'); |
|
| 67 | - } |
|
| 66 | + $this->parse_views = config_item('theme.parse_views'); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - //-------------------------------------------------------------------- |
|
| 69 | + //-------------------------------------------------------------------- |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * The main entryway into rendering a view. This is called from the |
|
| 73 | - * controller and is generally the last method called. |
|
| 74 | - * |
|
| 75 | - * @param string $layout If provided, will override the default layout. |
|
| 76 | - * @param int $cache_time The number of seconds to cache the output for. |
|
| 77 | - * @return mixed |
|
| 78 | - */ |
|
| 79 | - public function render($layout = null) |
|
| 80 | - { |
|
| 81 | - // Make the template engine available within the views. |
|
| 82 | - $this->vars['themer'] = $this; |
|
| 71 | + /** |
|
| 72 | + * The main entryway into rendering a view. This is called from the |
|
| 73 | + * controller and is generally the last method called. |
|
| 74 | + * |
|
| 75 | + * @param string $layout If provided, will override the default layout. |
|
| 76 | + * @param int $cache_time The number of seconds to cache the output for. |
|
| 77 | + * @return mixed |
|
| 78 | + */ |
|
| 79 | + public function render($layout = null) |
|
| 80 | + { |
|
| 81 | + // Make the template engine available within the views. |
|
| 82 | + $this->vars['themer'] = $this; |
|
| 83 | 83 | |
| 84 | - // Render our current view content |
|
| 85 | - $this->vars['view_content'] = $this->content(); |
|
| 84 | + // Render our current view content |
|
| 85 | + $this->vars['view_content'] = $this->content(); |
|
| 86 | 86 | |
| 87 | - $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
| 87 | + $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
| 88 | 88 | |
| 89 | - if (! isset($this->folders[$theme])) { |
|
| 90 | - throw new \LogicException( sprintf( lang('theme.bad_folder'), $theme ) ); |
|
| 91 | - } |
|
| 89 | + if (! isset($this->folders[$theme])) { |
|
| 90 | + throw new \LogicException( sprintf( lang('theme.bad_folder'), $theme ) ); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $this->active_theme = $theme; |
|
| 93 | + $this->active_theme = $theme; |
|
| 94 | 94 | |
| 95 | - // Make the path available within views. |
|
| 96 | - $this->vars['theme_path'] = $this->folders[$theme]; |
|
| 95 | + // Make the path available within views. |
|
| 96 | + $this->vars['theme_path'] = $this->folders[$theme]; |
|
| 97 | 97 | |
| 98 | - return $this->display($this->folders[$theme] . '/' . $this->layout); |
|
| 99 | - } |
|
| 98 | + return $this->display($this->folders[$theme] . '/' . $this->layout); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - //-------------------------------------------------------------------- |
|
| 101 | + //-------------------------------------------------------------------- |
|
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * Used within the template layout file to render the current content. |
@@ -108,490 +108,490 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return mixed |
| 110 | 110 | */ |
| 111 | - public function content() |
|
| 112 | - { |
|
| 113 | - // Calc our view name based on current method/controller |
|
| 114 | - $dir = $this->ci->router->fetch_directory(); |
|
| 111 | + public function content() |
|
| 112 | + { |
|
| 113 | + // Calc our view name based on current method/controller |
|
| 114 | + $dir = $this->ci->router->fetch_directory(); |
|
| 115 | 115 | |
| 116 | - foreach (Modules::$locations as $key => $offset) { |
|
| 116 | + foreach (Modules::$locations as $key => $offset) { |
|
| 117 | 117 | |
| 118 | - if (stripos($dir, 'module') !== false) { |
|
| 118 | + if (stripos($dir, 'module') !== false) { |
|
| 119 | 119 | // $dir = str_replace($offset, '', $dir); |
| 120 | - $dir = str_replace('controllers/', '', $dir); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $module = $this->ci->router->fetch_module(); |
|
| 125 | - |
|
| 126 | - if (! empty($module) && substr($dir, -strlen($module .'/')) == $module . '/') { |
|
| 127 | - $dir = ''; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $view = ! empty($this->view) ? $this->view : |
|
| 131 | - $dir . $this->ci->router->fetch_class() . '/' . $this->ci->router->fetch_method(); |
|
| 132 | - |
|
| 133 | - return $this->display($view); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - //-------------------------------------------------------------------- |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Loads a view file. Useful to control caching. Intended for use |
|
| 140 | - * from within view files. |
|
| 141 | - * |
|
| 142 | - * You can specify that a view should belong to a theme by prefixing |
|
| 143 | - * the name of the theme and a colon to the view name. For example, |
|
| 144 | - * "admin:header" would try to display the "header.php" file within |
|
| 145 | - * the "admin" theme. |
|
| 146 | - * |
|
| 147 | - * If a variant has been specified, it will be added to the end |
|
| 148 | - * of the view name before looking for the file. |
|
| 149 | - * |
|
| 150 | - * @param string $view |
|
| 151 | - * @param array $data |
|
| 152 | - * @param int $cache_time Number of minutes to cache the page for |
|
| 153 | - * @param string $cache_name A custom name for the cached file. |
|
| 154 | - * @return mixed |
|
| 155 | - */ |
|
| 156 | - public function display($view, $data = array(), $cache_time = 0, $cache_name=null) |
|
| 157 | - { |
|
| 158 | - if (empty($cache_name)) |
|
| 159 | - { |
|
| 160 | - $cache_name = 'theme_view_' . $view . '_' . $this->ci->router->fetch_class() . '_' . $this->ci->router->fetch_method(); |
|
| 161 | - $cache_name = str_replace( '/', '_', $cache_name ); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if ($cache_time == 0 || ! $output = $this->ci->cache->get($cache_name)) |
|
| 165 | - { |
|
| 166 | - $theme = NULL; |
|
| 167 | - $variant_view = NULL; |
|
| 168 | - |
|
| 169 | - // Pull out the theme from the view, if given. |
|
| 170 | - if ( strpos( $view, ':' ) !== FALSE ) |
|
| 171 | - { |
|
| 172 | - list( $theme, $view ) = explode( ':', $view ); |
|
| 173 | - |
|
| 174 | - $theme = str_replace('{theme}', $this->active_theme, $theme); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if ( ! empty( $theme ) && isset( $this->folders[ $theme ] ) ) |
|
| 178 | - { |
|
| 179 | - $view = rtrim( $this->folders[ $theme ], '/' ) . '/' . $view; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (! is_array($data)) |
|
| 183 | - { |
|
| 184 | - $data = []; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $data = array_merge( $this->vars, $data ); |
|
| 188 | - |
|
| 189 | - // if using a variant, add it to the view name. |
|
| 190 | - if ( ! empty( $this->current_variant ) ) |
|
| 191 | - { |
|
| 192 | - $variant_view = $view . $this->variants[ $this->current_variant ]; |
|
| 193 | - |
|
| 194 | - $output = $this->loadView($variant_view, $data); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // If that didn't find anything, then try it without a variant |
|
| 198 | - if ( empty( $output ) ) |
|
| 199 | - { |
|
| 200 | - $output = $this->loadView($view, $data); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - // Cache it |
|
| 204 | - if ((int)$cache_time > 0) |
|
| 205 | - { |
|
| 206 | - $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // Parse views? |
|
| 211 | - if ($this->parse_views) |
|
| 212 | - { |
|
| 213 | - $this->ci->load->library('parser'); |
|
| 214 | - |
|
| 215 | - // Any class objects will cause failure |
|
| 216 | - // so get rid of those bad boys.... |
|
| 217 | - unset($data['uikit'], $data['themer']); |
|
| 218 | - |
|
| 219 | - $output = $this->ci->parser->parse_string($output, $data, true); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - return $output; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - //-------------------------------------------------------------------- |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Runs a callback method and returns the contents to the view. |
|
| 229 | - * |
|
| 230 | - * @param $command |
|
| 231 | - * @param int $cache_time |
|
| 232 | - * @param string $cache_name // Number of MINUTES to cache output |
|
| 233 | - * @return mixed|void |
|
| 234 | - */ |
|
| 235 | - public function call($command, $cache_time=0, $cache_name=null) |
|
| 236 | - { |
|
| 237 | - if (empty($cache_name)) |
|
| 238 | - { |
|
| 239 | - $cache_name = 'theme_call_' . md5( $command ); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - if (! $output = $this->ci->cache->get($cache_name)) { |
|
| 243 | - $parts = explode(' ', $command); |
|
| 244 | - |
|
| 245 | - list($class, $method) = explode(':', array_shift($parts)); |
|
| 246 | - |
|
| 247 | - // Prepare our parameter list to send to the callback |
|
| 248 | - // by splitting $parts on equal signs. |
|
| 249 | - $params = array(); |
|
| 250 | - |
|
| 251 | - foreach ($parts as $part) { |
|
| 252 | - $p = explode('=', $part); |
|
| 253 | - |
|
| 254 | - if (empty($p[0]) || empty($p[1])) |
|
| 255 | - { |
|
| 256 | - continue; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $params[ $p[0] ] = $p[1]; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - // Let PHP try to autoload it through any available autoloaders |
|
| 263 | - // (including Composer and user's custom autoloaders). If we |
|
| 264 | - // don't find it, then assume it's a CI library that we can reach. |
|
| 265 | - if (class_exists($class)) { |
|
| 266 | - $class = new $class(); |
|
| 267 | - } else { |
|
| 268 | - $this->ci->load->library($class); |
|
| 269 | - $class =& $this->ci->$class; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - if (! method_exists($class, $method)) { |
|
| 273 | - throw new \RuntimeException( sprintf( lang('themer.bad_callback'), $class, $method ) ); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // Call the class with our parameters |
|
| 277 | - $output = $class->{$method}($params); |
|
| 278 | - |
|
| 279 | - // Cache it |
|
| 280 | - if ((int)$cache_time > 0) |
|
| 281 | - { |
|
| 282 | - $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - return $output; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - //-------------------------------------------------------------------- |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Sets the active theme to use. This theme should be |
|
| 293 | - * relative to one of the 'theme_paths' folders. |
|
| 294 | - * |
|
| 295 | - * @param $theme |
|
| 296 | - */ |
|
| 297 | - public function setTheme($theme) |
|
| 298 | - { |
|
| 299 | - $this->theme = $theme; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - //-------------------------------------------------------------------- |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Returns the current theme. |
|
| 306 | - * |
|
| 307 | - * @return mixed|string |
|
| 308 | - */ |
|
| 309 | - public function theme() |
|
| 310 | - { |
|
| 311 | - return $this->theme; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - //-------------------------------------------------------------------- |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Sets the default theme to use if another isn't specified. |
|
| 318 | - * |
|
| 319 | - * @param $theme |
|
| 320 | - * @return mixed|void |
|
| 321 | - */ |
|
| 322 | - public function setDefaultTheme($theme) |
|
| 323 | - { |
|
| 324 | - $this->default_theme = $theme; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - //-------------------------------------------------------------------- |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Sets the current view file to render. |
|
| 332 | - * |
|
| 333 | - * @param $file |
|
| 334 | - * @return mixed |
|
| 335 | - */ |
|
| 336 | - public function setView($file) |
|
| 337 | - { |
|
| 338 | - $this->view = $file; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - //-------------------------------------------------------------------- |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Returns the current view. |
|
| 345 | - * |
|
| 346 | - * @return mixed|string |
|
| 347 | - */ |
|
| 348 | - public function view() |
|
| 349 | - { |
|
| 350 | - return $this->view; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - //-------------------------------------------------------------------- |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Sets the current layout to be used. MUST be the name of one of |
|
| 357 | - * the layout files within the current theme. Case-sensitive. |
|
| 358 | - * |
|
| 359 | - * @param $file |
|
| 360 | - * @return mixed |
|
| 361 | - */ |
|
| 362 | - public function setLayout($file) |
|
| 363 | - { |
|
| 364 | - if (empty($file)) return; |
|
| 365 | - |
|
| 366 | - $this->layout = $file; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - //-------------------------------------------------------------------- |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Returns the current layout. |
|
| 373 | - * |
|
| 374 | - * @return mixed|string |
|
| 375 | - */ |
|
| 376 | - public function layout() |
|
| 377 | - { |
|
| 378 | - return $this->layout; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - //-------------------------------------------------------------------- |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Stores one or more pieces of data to be passed to the views when |
|
| 385 | - * they are rendered out. |
|
| 386 | - * |
|
| 387 | - * If both $key and $value are ! empty, then it will treat it as a |
|
| 388 | - * key/value pair. If $key is an array of key/value pairs, then $value |
|
| 389 | - * is ignored and each element of the array are made available to the |
|
| 390 | - * view as if it was a single $key/$value pair. |
|
| 391 | - * |
|
| 392 | - * @param string|array $key |
|
| 393 | - * @param mixed $value |
|
| 394 | - * @return $this |
|
| 395 | - */ |
|
| 396 | - public function set($key, $value = null) |
|
| 397 | - { |
|
| 398 | - if (is_array($key)) { |
|
| 399 | - $this->vars = array_merge($this->vars, $key); |
|
| 400 | - return; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - $this->vars[$key] = $value; |
|
| 404 | - |
|
| 405 | - return $this; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - //-------------------------------------------------------------------- |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Returns a value that has been previously set(). |
|
| 412 | - * |
|
| 413 | - * @param $key |
|
| 414 | - * @return mixed |
|
| 415 | - */ |
|
| 416 | - public function get($key) |
|
| 417 | - { |
|
| 418 | - return isset($this->vars[$key]) ? $this->vars[$key] : null; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - //-------------------------------------------------------------------- |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Determines whether or not the view should be parsed with the |
|
| 425 | - * CodeIgniter's parser. |
|
| 426 | - * |
|
| 427 | - * @param bool $parse |
|
| 428 | - * @return mixed |
|
| 429 | - */ |
|
| 430 | - public function parseViews($parse = false) |
|
| 431 | - { |
|
| 432 | - $this->parse_views = $parse; |
|
| 433 | - |
|
| 434 | - return $this; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - //-------------------------------------------------------------------- |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * Theme paths allow you to have multiple locations for themes to be |
|
| 441 | - * stored. This might be used for separating themes for different sub- |
|
| 442 | - * applications, or a core theme and user-submitted themes. |
|
| 443 | - * |
|
| 444 | - * @param $alias The name the theme can be referenced by |
|
| 445 | - * @param $path A new path where themes can be found. |
|
| 446 | - * |
|
| 447 | - * @return mixed |
|
| 448 | - */ |
|
| 449 | - public function addThemePath($alias, $path) |
|
| 450 | - { |
|
| 451 | - $this->folders[$alias] = $path; |
|
| 452 | - |
|
| 453 | - return $this; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - //-------------------------------------------------------------------- |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Removes a single theme path. |
|
| 460 | - * |
|
| 461 | - * @param $alias |
|
| 462 | - * @return $this |
|
| 463 | - */ |
|
| 464 | - public function removeThemePath($alias) |
|
| 465 | - { |
|
| 466 | - unset($this->folders[$alias]); |
|
| 467 | - |
|
| 468 | - return $this; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - //-------------------------------------------------------------------- |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Returns the path to the active/default theme's folder. |
|
| 475 | - * |
|
| 476 | - * @return string|null |
|
| 477 | - */ |
|
| 478 | - public function getThemePath() |
|
| 479 | - { |
|
| 480 | - $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
| 481 | - |
|
| 482 | - if (! isset($this->folders[ $theme ])) |
|
| 483 | - { |
|
| 484 | - return null; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $this->folders[$theme]; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - //-------------------------------------------------------------------- |
|
| 491 | - |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - //-------------------------------------------------------------------- |
|
| 495 | - // Variants |
|
| 496 | - //-------------------------------------------------------------------- |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Sets the variant used when creating view names. These variants can |
|
| 500 | - * be anything, but by default are used to render specific templates |
|
| 501 | - * for desktop, tablet, and phone. The name of the variant is added |
|
| 502 | - * to the view name, joined by a "+" symbol. |
|
| 503 | - * |
|
| 504 | - * Example: |
|
| 505 | - * $this->setVariant('phone'); |
|
| 506 | - * $this->display('header'); |
|
| 507 | - * |
|
| 508 | - * Tries to display "views/header+phone.php" |
|
| 509 | - * |
|
| 510 | - * @param $variant |
|
| 511 | - * @return $this |
|
| 512 | - */ |
|
| 513 | - public function setVariant($variant) |
|
| 514 | - { |
|
| 515 | - if (isset($this->variants[$variant])) { |
|
| 516 | - $this->current_variant = $variant; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - return $this; |
|
| 520 | - } |
|
| 521 | - //-------------------------------------------------------------------- |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * Adds a new variant to the system. |
|
| 525 | - * |
|
| 526 | - * @param $name |
|
| 527 | - * @param $postfix |
|
| 528 | - * @return $this|mixed |
|
| 529 | - */ |
|
| 530 | - public function addVariant($name, $postfix) |
|
| 531 | - { |
|
| 532 | - $this->variants[$name] = $postfix; |
|
| 533 | - |
|
| 534 | - return $this; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - //-------------------------------------------------------------------- |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Removes a variant from the system. |
|
| 541 | - * |
|
| 542 | - * @param $name |
|
| 543 | - * @return $this|mixed |
|
| 544 | - */ |
|
| 545 | - public function removeVariant($name) |
|
| 546 | - { |
|
| 547 | - if (isset($this->variants[$name])) { |
|
| 548 | - unset($this->variants[$name]); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - return $this; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - //-------------------------------------------------------------------- |
|
| 555 | - // Private Methods |
|
| 556 | - //-------------------------------------------------------------------- |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Handles the actual loading of a view file, and checks for any |
|
| 560 | - * overrides in themes, etc. |
|
| 561 | - * |
|
| 562 | - * @param $view |
|
| 563 | - * @param $data |
|
| 564 | - * |
|
| 565 | - * @return string |
|
| 566 | - */ |
|
| 567 | - private function loadView($view, $data) |
|
| 568 | - { |
|
| 569 | - // First - does it exist in the current theme? |
|
| 570 | - $theme = ! empty($this->active_theme) ? $this->active_theme : $this->default_theme; |
|
| 571 | - $theme = ! empty($this->folders[$theme]) ? $this->folders[$theme] : $theme; |
|
| 572 | - $theme = rtrim($theme, '/ ') .'/'; |
|
| 573 | - |
|
| 574 | - if (file_exists($theme ."{$view}.php")) |
|
| 575 | - { |
|
| 576 | - $output = $this->ci->load->view_path( $theme . $view, $data, TRUE ); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - // Next, if it's a real file with path, then load it |
|
| 580 | - elseif ( realpath( $view . '.php' ) ) |
|
| 581 | - { |
|
| 582 | - $output = $this->ci->load->view_path( $view, $data, TRUE ); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - // Otherwise, treat it as a standard view, which means |
|
| 586 | - // application/views will override any modules. (See HMVC/Loader) |
|
| 587 | - else |
|
| 588 | - { |
|
| 589 | - $output = $this->ci->load->view( $view, $data, TRUE ); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - return $output; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - //-------------------------------------------------------------------- |
|
| 120 | + $dir = str_replace('controllers/', '', $dir); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $module = $this->ci->router->fetch_module(); |
|
| 125 | + |
|
| 126 | + if (! empty($module) && substr($dir, -strlen($module .'/')) == $module . '/') { |
|
| 127 | + $dir = ''; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $view = ! empty($this->view) ? $this->view : |
|
| 131 | + $dir . $this->ci->router->fetch_class() . '/' . $this->ci->router->fetch_method(); |
|
| 132 | + |
|
| 133 | + return $this->display($view); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + //-------------------------------------------------------------------- |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Loads a view file. Useful to control caching. Intended for use |
|
| 140 | + * from within view files. |
|
| 141 | + * |
|
| 142 | + * You can specify that a view should belong to a theme by prefixing |
|
| 143 | + * the name of the theme and a colon to the view name. For example, |
|
| 144 | + * "admin:header" would try to display the "header.php" file within |
|
| 145 | + * the "admin" theme. |
|
| 146 | + * |
|
| 147 | + * If a variant has been specified, it will be added to the end |
|
| 148 | + * of the view name before looking for the file. |
|
| 149 | + * |
|
| 150 | + * @param string $view |
|
| 151 | + * @param array $data |
|
| 152 | + * @param int $cache_time Number of minutes to cache the page for |
|
| 153 | + * @param string $cache_name A custom name for the cached file. |
|
| 154 | + * @return mixed |
|
| 155 | + */ |
|
| 156 | + public function display($view, $data = array(), $cache_time = 0, $cache_name=null) |
|
| 157 | + { |
|
| 158 | + if (empty($cache_name)) |
|
| 159 | + { |
|
| 160 | + $cache_name = 'theme_view_' . $view . '_' . $this->ci->router->fetch_class() . '_' . $this->ci->router->fetch_method(); |
|
| 161 | + $cache_name = str_replace( '/', '_', $cache_name ); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if ($cache_time == 0 || ! $output = $this->ci->cache->get($cache_name)) |
|
| 165 | + { |
|
| 166 | + $theme = NULL; |
|
| 167 | + $variant_view = NULL; |
|
| 168 | + |
|
| 169 | + // Pull out the theme from the view, if given. |
|
| 170 | + if ( strpos( $view, ':' ) !== FALSE ) |
|
| 171 | + { |
|
| 172 | + list( $theme, $view ) = explode( ':', $view ); |
|
| 173 | + |
|
| 174 | + $theme = str_replace('{theme}', $this->active_theme, $theme); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if ( ! empty( $theme ) && isset( $this->folders[ $theme ] ) ) |
|
| 178 | + { |
|
| 179 | + $view = rtrim( $this->folders[ $theme ], '/' ) . '/' . $view; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (! is_array($data)) |
|
| 183 | + { |
|
| 184 | + $data = []; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $data = array_merge( $this->vars, $data ); |
|
| 188 | + |
|
| 189 | + // if using a variant, add it to the view name. |
|
| 190 | + if ( ! empty( $this->current_variant ) ) |
|
| 191 | + { |
|
| 192 | + $variant_view = $view . $this->variants[ $this->current_variant ]; |
|
| 193 | + |
|
| 194 | + $output = $this->loadView($variant_view, $data); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // If that didn't find anything, then try it without a variant |
|
| 198 | + if ( empty( $output ) ) |
|
| 199 | + { |
|
| 200 | + $output = $this->loadView($view, $data); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + // Cache it |
|
| 204 | + if ((int)$cache_time > 0) |
|
| 205 | + { |
|
| 206 | + $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // Parse views? |
|
| 211 | + if ($this->parse_views) |
|
| 212 | + { |
|
| 213 | + $this->ci->load->library('parser'); |
|
| 214 | + |
|
| 215 | + // Any class objects will cause failure |
|
| 216 | + // so get rid of those bad boys.... |
|
| 217 | + unset($data['uikit'], $data['themer']); |
|
| 218 | + |
|
| 219 | + $output = $this->ci->parser->parse_string($output, $data, true); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + return $output; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + //-------------------------------------------------------------------- |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Runs a callback method and returns the contents to the view. |
|
| 229 | + * |
|
| 230 | + * @param $command |
|
| 231 | + * @param int $cache_time |
|
| 232 | + * @param string $cache_name // Number of MINUTES to cache output |
|
| 233 | + * @return mixed|void |
|
| 234 | + */ |
|
| 235 | + public function call($command, $cache_time=0, $cache_name=null) |
|
| 236 | + { |
|
| 237 | + if (empty($cache_name)) |
|
| 238 | + { |
|
| 239 | + $cache_name = 'theme_call_' . md5( $command ); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + if (! $output = $this->ci->cache->get($cache_name)) { |
|
| 243 | + $parts = explode(' ', $command); |
|
| 244 | + |
|
| 245 | + list($class, $method) = explode(':', array_shift($parts)); |
|
| 246 | + |
|
| 247 | + // Prepare our parameter list to send to the callback |
|
| 248 | + // by splitting $parts on equal signs. |
|
| 249 | + $params = array(); |
|
| 250 | + |
|
| 251 | + foreach ($parts as $part) { |
|
| 252 | + $p = explode('=', $part); |
|
| 253 | + |
|
| 254 | + if (empty($p[0]) || empty($p[1])) |
|
| 255 | + { |
|
| 256 | + continue; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $params[ $p[0] ] = $p[1]; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + // Let PHP try to autoload it through any available autoloaders |
|
| 263 | + // (including Composer and user's custom autoloaders). If we |
|
| 264 | + // don't find it, then assume it's a CI library that we can reach. |
|
| 265 | + if (class_exists($class)) { |
|
| 266 | + $class = new $class(); |
|
| 267 | + } else { |
|
| 268 | + $this->ci->load->library($class); |
|
| 269 | + $class =& $this->ci->$class; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + if (! method_exists($class, $method)) { |
|
| 273 | + throw new \RuntimeException( sprintf( lang('themer.bad_callback'), $class, $method ) ); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // Call the class with our parameters |
|
| 277 | + $output = $class->{$method}($params); |
|
| 278 | + |
|
| 279 | + // Cache it |
|
| 280 | + if ((int)$cache_time > 0) |
|
| 281 | + { |
|
| 282 | + $this->ci->cache->save($cache_name, $output, (int)$cache_time * 60); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + return $output; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + //-------------------------------------------------------------------- |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Sets the active theme to use. This theme should be |
|
| 293 | + * relative to one of the 'theme_paths' folders. |
|
| 294 | + * |
|
| 295 | + * @param $theme |
|
| 296 | + */ |
|
| 297 | + public function setTheme($theme) |
|
| 298 | + { |
|
| 299 | + $this->theme = $theme; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + //-------------------------------------------------------------------- |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Returns the current theme. |
|
| 306 | + * |
|
| 307 | + * @return mixed|string |
|
| 308 | + */ |
|
| 309 | + public function theme() |
|
| 310 | + { |
|
| 311 | + return $this->theme; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + //-------------------------------------------------------------------- |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Sets the default theme to use if another isn't specified. |
|
| 318 | + * |
|
| 319 | + * @param $theme |
|
| 320 | + * @return mixed|void |
|
| 321 | + */ |
|
| 322 | + public function setDefaultTheme($theme) |
|
| 323 | + { |
|
| 324 | + $this->default_theme = $theme; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + //-------------------------------------------------------------------- |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Sets the current view file to render. |
|
| 332 | + * |
|
| 333 | + * @param $file |
|
| 334 | + * @return mixed |
|
| 335 | + */ |
|
| 336 | + public function setView($file) |
|
| 337 | + { |
|
| 338 | + $this->view = $file; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + //-------------------------------------------------------------------- |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Returns the current view. |
|
| 345 | + * |
|
| 346 | + * @return mixed|string |
|
| 347 | + */ |
|
| 348 | + public function view() |
|
| 349 | + { |
|
| 350 | + return $this->view; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + //-------------------------------------------------------------------- |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Sets the current layout to be used. MUST be the name of one of |
|
| 357 | + * the layout files within the current theme. Case-sensitive. |
|
| 358 | + * |
|
| 359 | + * @param $file |
|
| 360 | + * @return mixed |
|
| 361 | + */ |
|
| 362 | + public function setLayout($file) |
|
| 363 | + { |
|
| 364 | + if (empty($file)) return; |
|
| 365 | + |
|
| 366 | + $this->layout = $file; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + //-------------------------------------------------------------------- |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Returns the current layout. |
|
| 373 | + * |
|
| 374 | + * @return mixed|string |
|
| 375 | + */ |
|
| 376 | + public function layout() |
|
| 377 | + { |
|
| 378 | + return $this->layout; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + //-------------------------------------------------------------------- |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Stores one or more pieces of data to be passed to the views when |
|
| 385 | + * they are rendered out. |
|
| 386 | + * |
|
| 387 | + * If both $key and $value are ! empty, then it will treat it as a |
|
| 388 | + * key/value pair. If $key is an array of key/value pairs, then $value |
|
| 389 | + * is ignored and each element of the array are made available to the |
|
| 390 | + * view as if it was a single $key/$value pair. |
|
| 391 | + * |
|
| 392 | + * @param string|array $key |
|
| 393 | + * @param mixed $value |
|
| 394 | + * @return $this |
|
| 395 | + */ |
|
| 396 | + public function set($key, $value = null) |
|
| 397 | + { |
|
| 398 | + if (is_array($key)) { |
|
| 399 | + $this->vars = array_merge($this->vars, $key); |
|
| 400 | + return; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + $this->vars[$key] = $value; |
|
| 404 | + |
|
| 405 | + return $this; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + //-------------------------------------------------------------------- |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Returns a value that has been previously set(). |
|
| 412 | + * |
|
| 413 | + * @param $key |
|
| 414 | + * @return mixed |
|
| 415 | + */ |
|
| 416 | + public function get($key) |
|
| 417 | + { |
|
| 418 | + return isset($this->vars[$key]) ? $this->vars[$key] : null; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + //-------------------------------------------------------------------- |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Determines whether or not the view should be parsed with the |
|
| 425 | + * CodeIgniter's parser. |
|
| 426 | + * |
|
| 427 | + * @param bool $parse |
|
| 428 | + * @return mixed |
|
| 429 | + */ |
|
| 430 | + public function parseViews($parse = false) |
|
| 431 | + { |
|
| 432 | + $this->parse_views = $parse; |
|
| 433 | + |
|
| 434 | + return $this; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + //-------------------------------------------------------------------- |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * Theme paths allow you to have multiple locations for themes to be |
|
| 441 | + * stored. This might be used for separating themes for different sub- |
|
| 442 | + * applications, or a core theme and user-submitted themes. |
|
| 443 | + * |
|
| 444 | + * @param $alias The name the theme can be referenced by |
|
| 445 | + * @param $path A new path where themes can be found. |
|
| 446 | + * |
|
| 447 | + * @return mixed |
|
| 448 | + */ |
|
| 449 | + public function addThemePath($alias, $path) |
|
| 450 | + { |
|
| 451 | + $this->folders[$alias] = $path; |
|
| 452 | + |
|
| 453 | + return $this; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + //-------------------------------------------------------------------- |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Removes a single theme path. |
|
| 460 | + * |
|
| 461 | + * @param $alias |
|
| 462 | + * @return $this |
|
| 463 | + */ |
|
| 464 | + public function removeThemePath($alias) |
|
| 465 | + { |
|
| 466 | + unset($this->folders[$alias]); |
|
| 467 | + |
|
| 468 | + return $this; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + //-------------------------------------------------------------------- |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Returns the path to the active/default theme's folder. |
|
| 475 | + * |
|
| 476 | + * @return string|null |
|
| 477 | + */ |
|
| 478 | + public function getThemePath() |
|
| 479 | + { |
|
| 480 | + $theme = empty($this->theme) ? $this->default_theme : $this->theme; |
|
| 481 | + |
|
| 482 | + if (! isset($this->folders[ $theme ])) |
|
| 483 | + { |
|
| 484 | + return null; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $this->folders[$theme]; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + //-------------------------------------------------------------------- |
|
| 491 | + |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + //-------------------------------------------------------------------- |
|
| 495 | + // Variants |
|
| 496 | + //-------------------------------------------------------------------- |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Sets the variant used when creating view names. These variants can |
|
| 500 | + * be anything, but by default are used to render specific templates |
|
| 501 | + * for desktop, tablet, and phone. The name of the variant is added |
|
| 502 | + * to the view name, joined by a "+" symbol. |
|
| 503 | + * |
|
| 504 | + * Example: |
|
| 505 | + * $this->setVariant('phone'); |
|
| 506 | + * $this->display('header'); |
|
| 507 | + * |
|
| 508 | + * Tries to display "views/header+phone.php" |
|
| 509 | + * |
|
| 510 | + * @param $variant |
|
| 511 | + * @return $this |
|
| 512 | + */ |
|
| 513 | + public function setVariant($variant) |
|
| 514 | + { |
|
| 515 | + if (isset($this->variants[$variant])) { |
|
| 516 | + $this->current_variant = $variant; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + return $this; |
|
| 520 | + } |
|
| 521 | + //-------------------------------------------------------------------- |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * Adds a new variant to the system. |
|
| 525 | + * |
|
| 526 | + * @param $name |
|
| 527 | + * @param $postfix |
|
| 528 | + * @return $this|mixed |
|
| 529 | + */ |
|
| 530 | + public function addVariant($name, $postfix) |
|
| 531 | + { |
|
| 532 | + $this->variants[$name] = $postfix; |
|
| 533 | + |
|
| 534 | + return $this; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + //-------------------------------------------------------------------- |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Removes a variant from the system. |
|
| 541 | + * |
|
| 542 | + * @param $name |
|
| 543 | + * @return $this|mixed |
|
| 544 | + */ |
|
| 545 | + public function removeVariant($name) |
|
| 546 | + { |
|
| 547 | + if (isset($this->variants[$name])) { |
|
| 548 | + unset($this->variants[$name]); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + return $this; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + //-------------------------------------------------------------------- |
|
| 555 | + // Private Methods |
|
| 556 | + //-------------------------------------------------------------------- |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Handles the actual loading of a view file, and checks for any |
|
| 560 | + * overrides in themes, etc. |
|
| 561 | + * |
|
| 562 | + * @param $view |
|
| 563 | + * @param $data |
|
| 564 | + * |
|
| 565 | + * @return string |
|
| 566 | + */ |
|
| 567 | + private function loadView($view, $data) |
|
| 568 | + { |
|
| 569 | + // First - does it exist in the current theme? |
|
| 570 | + $theme = ! empty($this->active_theme) ? $this->active_theme : $this->default_theme; |
|
| 571 | + $theme = ! empty($this->folders[$theme]) ? $this->folders[$theme] : $theme; |
|
| 572 | + $theme = rtrim($theme, '/ ') .'/'; |
|
| 573 | + |
|
| 574 | + if (file_exists($theme ."{$view}.php")) |
|
| 575 | + { |
|
| 576 | + $output = $this->ci->load->view_path( $theme . $view, $data, TRUE ); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + // Next, if it's a real file with path, then load it |
|
| 580 | + elseif ( realpath( $view . '.php' ) ) |
|
| 581 | + { |
|
| 582 | + $output = $this->ci->load->view_path( $view, $data, TRUE ); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + // Otherwise, treat it as a standard view, which means |
|
| 586 | + // application/views will override any modules. (See HMVC/Loader) |
|
| 587 | + else |
|
| 588 | + { |
|
| 589 | + $output = $this->ci->load->view( $view, $data, TRUE ); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + return $output; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + //-------------------------------------------------------------------- |
|
| 596 | 596 | |
| 597 | 597 | } |
@@ -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 |
@@ -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 |
@@ -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 | } |