@@ -1,168 +1,168 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * TNH Framework |
|
| 5 | - * |
|
| 6 | - * A simple PHP framework using HMVC architecture |
|
| 7 | - * |
|
| 8 | - * This content is released under the GNU GPL License (GPL) |
|
| 9 | - * |
|
| 10 | - * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | - * |
|
| 12 | - * This program is free software; you can redistribute it and/or |
|
| 13 | - * modify it under the terms of the GNU General Public License |
|
| 14 | - * as published by the Free Software Foundation; either version 3 |
|
| 15 | - * of the License, or (at your option) any later version. |
|
| 16 | - * |
|
| 17 | - * This program is distributed in the hope that it will be useful, |
|
| 18 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | - * GNU General Public License for more details. |
|
| 21 | - * |
|
| 22 | - * You should have received a copy of the GNU General Public License |
|
| 23 | - * along with this program; if not, write to the Free Software |
|
| 24 | - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | - */ |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * TNH Framework |
|
| 5 | + * |
|
| 6 | + * A simple PHP framework using HMVC architecture |
|
| 7 | + * |
|
| 8 | + * This content is released under the GNU GPL License (GPL) |
|
| 9 | + * |
|
| 10 | + * Copyright (C) 2017 Tony NGUEREZA |
|
| 11 | + * |
|
| 12 | + * This program is free software; you can redistribute it and/or |
|
| 13 | + * modify it under the terms of the GNU General Public License |
|
| 14 | + * as published by the Free Software Foundation; either version 3 |
|
| 15 | + * of the License, or (at your option) any later version. |
|
| 16 | + * |
|
| 17 | + * This program is distributed in the hope that it will be useful, |
|
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 | + * GNU General Public License for more details. |
|
| 21 | + * |
|
| 22 | + * You should have received a copy of the GNU General Public License |
|
| 23 | + * along with this program; if not, write to the Free Software |
|
| 24 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @file Assets.php |
|
| 29 | - * |
|
| 30 | - * This class contains static methods for generating static content links (images, Javascript, CSS, etc.). |
|
| 31 | - * |
|
| 32 | - * @package core |
|
| 33 | - * @author Tony NGUEREZA |
|
| 34 | - * @copyright Copyright (c) 2017 |
|
| 35 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | - * @link http://www.iacademy.cf |
|
| 37 | - * @version 1.0.0 |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @filesource |
|
| 40 | - */ |
|
| 41 | - class Assets{ |
|
| 27 | + /** |
|
| 28 | + * @file Assets.php |
|
| 29 | + * |
|
| 30 | + * This class contains static methods for generating static content links (images, Javascript, CSS, etc.). |
|
| 31 | + * |
|
| 32 | + * @package core |
|
| 33 | + * @author Tony NGUEREZA |
|
| 34 | + * @copyright Copyright (c) 2017 |
|
| 35 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 36 | + * @link http://www.iacademy.cf |
|
| 37 | + * @version 1.0.0 |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @filesource |
|
| 40 | + */ |
|
| 41 | + class Assets{ |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * The logger instance |
|
| 45 | - * @var object |
|
| 46 | - */ |
|
| 47 | - private static $logger; |
|
| 43 | + /** |
|
| 44 | + * The logger instance |
|
| 45 | + * @var object |
|
| 46 | + */ |
|
| 47 | + private static $logger; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * The signleton of the logger |
|
| 51 | - * @return Object the Log instance |
|
| 52 | - */ |
|
| 53 | - private static function getLogger(){ |
|
| 54 | - if(self::$logger == null){ |
|
| 55 | - //can't assign reference to static variable |
|
| 56 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 57 | - self::$logger[0]->setLogger('Library::Assets'); |
|
| 58 | - } |
|
| 59 | - return self::$logger[0]; |
|
| 60 | - } |
|
| 49 | + /** |
|
| 50 | + * The signleton of the logger |
|
| 51 | + * @return Object the Log instance |
|
| 52 | + */ |
|
| 53 | + private static function getLogger(){ |
|
| 54 | + if(self::$logger == null){ |
|
| 55 | + //can't assign reference to static variable |
|
| 56 | + self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 57 | + self::$logger[0]->setLogger('Library::Assets'); |
|
| 58 | + } |
|
| 59 | + return self::$logger[0]; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Generate the link of the assets file. |
|
| 65 | - * |
|
| 66 | - * Generates the absolute link of a file inside ASSETS_PATH folder. |
|
| 67 | - * For example : |
|
| 68 | - * echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css |
|
| 69 | - * Note: |
|
| 70 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 71 | - * |
|
| 72 | - * @param string $asset the name of the assets file path with the extension. |
|
| 73 | - * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
|
| 74 | - */ |
|
| 75 | - public static function path($asset){ |
|
| 76 | - $logger = self::getLogger(); |
|
| 77 | - $path = ASSETS_PATH . $asset; |
|
| 63 | + /** |
|
| 64 | + * Generate the link of the assets file. |
|
| 65 | + * |
|
| 66 | + * Generates the absolute link of a file inside ASSETS_PATH folder. |
|
| 67 | + * For example : |
|
| 68 | + * echo Assets::path('foo/bar/css/style.css'); => http://mysite.com/assets/foo/bar/css/style.css |
|
| 69 | + * Note: |
|
| 70 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 71 | + * |
|
| 72 | + * @param string $asset the name of the assets file path with the extension. |
|
| 73 | + * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
|
| 74 | + */ |
|
| 75 | + public static function path($asset){ |
|
| 76 | + $logger = self::getLogger(); |
|
| 77 | + $path = ASSETS_PATH . $asset; |
|
| 78 | 78 | |
| 79 | - $logger->debug('Including the Assets file [' . $path . ']'); |
|
| 80 | - //Check if the file exists |
|
| 81 | - if(file_exists($path)){ |
|
| 82 | - $logger->info('Assets file [' . $path . '] included successfully'); |
|
| 83 | - return Url::base_url($path); |
|
| 84 | - } |
|
| 85 | - $logger->warning('Assets file [' . $path . '] does not exist'); |
|
| 86 | - return null; |
|
| 87 | - } |
|
| 79 | + $logger->debug('Including the Assets file [' . $path . ']'); |
|
| 80 | + //Check if the file exists |
|
| 81 | + if(file_exists($path)){ |
|
| 82 | + $logger->info('Assets file [' . $path . '] included successfully'); |
|
| 83 | + return Url::base_url($path); |
|
| 84 | + } |
|
| 85 | + $logger->warning('Assets file [' . $path . '] does not exist'); |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Generate the link of the css file. |
|
| 91 | - * |
|
| 92 | - * Generates the absolute link of a file containing the CSS style. |
|
| 93 | - * For example : |
|
| 94 | - * echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css |
|
| 95 | - * Note: |
|
| 96 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 97 | - * |
|
| 98 | - * @param string $path the name of the css file without the extension. |
|
| 99 | - * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
|
| 100 | - */ |
|
| 101 | - public static function css($path){ |
|
| 102 | - $logger = self::getLogger(); |
|
| 103 | - /* |
|
| 89 | + /** |
|
| 90 | + * Generate the link of the css file. |
|
| 91 | + * |
|
| 92 | + * Generates the absolute link of a file containing the CSS style. |
|
| 93 | + * For example : |
|
| 94 | + * echo Assets::css('mystyle'); => http://mysite.com/assets/css/mystyle.css |
|
| 95 | + * Note: |
|
| 96 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 97 | + * |
|
| 98 | + * @param string $path the name of the css file without the extension. |
|
| 99 | + * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
|
| 100 | + */ |
|
| 101 | + public static function css($path){ |
|
| 102 | + $logger = self::getLogger(); |
|
| 103 | + /* |
|
| 104 | 104 | * if the file name contains the ".css" extension, replace it with |
| 105 | 105 | * an empty string for better processing. |
| 106 | 106 | */ |
| 107 | - $path = str_ireplace('.css', '', $path); |
|
| 108 | - $path = ASSETS_PATH . 'css/' . $path . '.css'; |
|
| 107 | + $path = str_ireplace('.css', '', $path); |
|
| 108 | + $path = ASSETS_PATH . 'css/' . $path . '.css'; |
|
| 109 | 109 | |
| 110 | - $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
|
| 111 | - //Check if the file exists |
|
| 112 | - if(file_exists($path)){ |
|
| 113 | - $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
|
| 114 | - return Url::base_url($path); |
|
| 115 | - } |
|
| 116 | - $logger->warning('Assets file [' . $path . '] for CSS does not exist'); |
|
| 117 | - return null; |
|
| 118 | - } |
|
| 110 | + $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
|
| 111 | + //Check if the file exists |
|
| 112 | + if(file_exists($path)){ |
|
| 113 | + $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
|
| 114 | + return Url::base_url($path); |
|
| 115 | + } |
|
| 116 | + $logger->warning('Assets file [' . $path . '] for CSS does not exist'); |
|
| 117 | + return null; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Generate the link of the javascript file. |
|
| 122 | - * |
|
| 123 | - * Generates the absolute link of a file containing the javascript. |
|
| 124 | - * For example : |
|
| 125 | - * echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js |
|
| 126 | - * Note: |
|
| 127 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 128 | - * |
|
| 129 | - * @param string $path the name of the javascript file without the extension. |
|
| 130 | - * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
|
| 131 | - */ |
|
| 132 | - public static function js($path){ |
|
| 133 | - $logger = self::getLogger(); |
|
| 134 | - $path = str_ireplace('.js', '', $path); |
|
| 135 | - $path = ASSETS_PATH . 'js/' . $path . '.js'; |
|
| 136 | - $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
|
| 137 | - if(file_exists($path)){ |
|
| 138 | - $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
|
| 139 | - return Url::base_url($path); |
|
| 140 | - } |
|
| 141 | - $logger->warning('Assets file [' . $path . '] for Javascript does not exist'); |
|
| 142 | - return null; |
|
| 143 | - } |
|
| 120 | + /** |
|
| 121 | + * Generate the link of the javascript file. |
|
| 122 | + * |
|
| 123 | + * Generates the absolute link of a file containing the javascript. |
|
| 124 | + * For example : |
|
| 125 | + * echo Assets::js('myscript'); => http://mysite.com/assets/js/myscript.js |
|
| 126 | + * Note: |
|
| 127 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 128 | + * |
|
| 129 | + * @param string $path the name of the javascript file without the extension. |
|
| 130 | + * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
|
| 131 | + */ |
|
| 132 | + public static function js($path){ |
|
| 133 | + $logger = self::getLogger(); |
|
| 134 | + $path = str_ireplace('.js', '', $path); |
|
| 135 | + $path = ASSETS_PATH . 'js/' . $path . '.js'; |
|
| 136 | + $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
|
| 137 | + if(file_exists($path)){ |
|
| 138 | + $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
|
| 139 | + return Url::base_url($path); |
|
| 140 | + } |
|
| 141 | + $logger->warning('Assets file [' . $path . '] for Javascript does not exist'); |
|
| 142 | + return null; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Generate the link of the image file. |
|
| 147 | - * |
|
| 148 | - * Generates the absolute link of a file containing the image. |
|
| 149 | - * For example : |
|
| 150 | - * echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png |
|
| 151 | - * Note: |
|
| 152 | - * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 153 | - * |
|
| 154 | - * @param string $path the name of the image file with the extension. |
|
| 155 | - * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
|
| 156 | - */ |
|
| 157 | - public static function img($path){ |
|
| 158 | - $logger = self::getLogger(); |
|
| 159 | - $path = ASSETS_PATH . 'images/' . $path; |
|
| 160 | - $logger->debug('Including the Assets file [' . $path . '] for image'); |
|
| 161 | - if(file_exists($path)){ |
|
| 162 | - $logger->info('Assets file [' . $path . '] for image included successfully'); |
|
| 163 | - return Url::base_url($path); |
|
| 164 | - } |
|
| 165 | - $logger->warning('Assets file [' . $path . '] for image does not exist'); |
|
| 166 | - return null; |
|
| 167 | - } |
|
| 168 | - } |
|
| 145 | + /** |
|
| 146 | + * Generate the link of the image file. |
|
| 147 | + * |
|
| 148 | + * Generates the absolute link of a file containing the image. |
|
| 149 | + * For example : |
|
| 150 | + * echo Assets::img('myimage.png'); => http://mysite.com/assets/images/myimage.png |
|
| 151 | + * Note: |
|
| 152 | + * The argument passed to this function must be the relative link to the folder that contains the static contents defined by the constant ASSETS_PATH. |
|
| 153 | + * |
|
| 154 | + * @param string $path the name of the image file with the extension. |
|
| 155 | + * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
|
| 156 | + */ |
|
| 157 | + public static function img($path){ |
|
| 158 | + $logger = self::getLogger(); |
|
| 159 | + $path = ASSETS_PATH . 'images/' . $path; |
|
| 160 | + $logger->debug('Including the Assets file [' . $path . '] for image'); |
|
| 161 | + if(file_exists($path)){ |
|
| 162 | + $logger->info('Assets file [' . $path . '] for image included successfully'); |
|
| 163 | + return Url::base_url($path); |
|
| 164 | + } |
|
| 165 | + $logger->warning('Assets file [' . $path . '] for image does not exist'); |
|
| 166 | + return null; |
|
| 167 | + } |
|
| 168 | + } |
|