@@ -1,208 +1,208 @@ |
||
| 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 | - */ |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * For application languages management |
|
| 29 | - */ |
|
| 30 | - class Lang{ |
|
| 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 | + |
|
| 27 | + /** |
|
| 28 | + * For application languages management |
|
| 29 | + */ |
|
| 30 | + class Lang{ |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The supported available language for this application. |
|
| 34 | - * @example "en" => "english" |
|
| 35 | - * @see Lang::addLang() |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $availables = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * The all messages language |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - protected $languages = array(); |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * The default language to use if can not |
|
| 48 | - * determine the client language |
|
| 49 | - * |
|
| 50 | - * @example $default = 'en' |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - protected $default = null; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * The current client language |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - protected $current = null; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * The logger instance |
|
| 63 | - * @var Log |
|
| 64 | - */ |
|
| 65 | - private $logger; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Construct new Lang instance |
|
| 69 | - */ |
|
| 70 | - public function __construct(){ |
|
| 71 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 72 | - $this->logger->setLogger('Library::Lang'); |
|
| 73 | - |
|
| 74 | - $this->default = get_config('default_language', 'en'); |
|
| 75 | - $this->logger->debug('Setting the supported languages'); |
|
| 32 | + /** |
|
| 33 | + * The supported available language for this application. |
|
| 34 | + * @example "en" => "english" |
|
| 35 | + * @see Lang::addLang() |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $availables = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * The all messages language |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + protected $languages = array(); |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * The default language to use if can not |
|
| 48 | + * determine the client language |
|
| 49 | + * |
|
| 50 | + * @example $default = 'en' |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + protected $default = null; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * The current client language |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + protected $current = null; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * The logger instance |
|
| 63 | + * @var Log |
|
| 64 | + */ |
|
| 65 | + private $logger; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Construct new Lang instance |
|
| 69 | + */ |
|
| 70 | + public function __construct(){ |
|
| 71 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 72 | + $this->logger->setLogger('Library::Lang'); |
|
| 73 | + |
|
| 74 | + $this->default = get_config('default_language', 'en'); |
|
| 75 | + $this->logger->debug('Setting the supported languages'); |
|
| 76 | 76 | |
| 77 | - //add the supported languages ('key', 'display name') |
|
| 78 | - $languages = get_config('languages', null); |
|
| 79 | - if(! empty($languages)){ |
|
| 80 | - foreach($languages as $key => $displayName){ |
|
| 81 | - $this->addLang($key, $displayName); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - unset($languages); |
|
| 85 | - |
|
| 86 | - //if the language exists in cookie use it |
|
| 87 | - $cfgKey = get_config('language_cookie_name'); |
|
| 88 | - $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 89 | - $objCookie = & class_loader('Cookie'); |
|
| 90 | - $cookieLang = $objCookie->get($cfgKey); |
|
| 91 | - if($cookieLang && $this->isValid($cookieLang)){ |
|
| 92 | - $this->current = $cookieLang; |
|
| 93 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 94 | - } |
|
| 95 | - else{ |
|
| 96 | - $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 97 | - $this->current = $this->getDefault(); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Get the all languages messages |
|
| 103 | - * |
|
| 104 | - * @return array the language message list |
|
| 105 | - */ |
|
| 106 | - public function getAll(){ |
|
| 107 | - return $this->languages; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Set the language message |
|
| 112 | - * |
|
| 113 | - * @param string $key the language key to identify |
|
| 114 | - * @param string $value the language message value |
|
| 115 | - */ |
|
| 116 | - public function set($key, $value){ |
|
| 117 | - $this->languages[$key] = $value; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Get the language message for the given key. If can't find return the default value |
|
| 122 | - * |
|
| 123 | - * @param string $key the message language key |
|
| 124 | - * @param string $default the default value to return if can not found the language message key |
|
| 125 | - * |
|
| 126 | - * @return string the language message value |
|
| 127 | - */ |
|
| 128 | - public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
| 129 | - if(isset($this->languages[$key])){ |
|
| 130 | - return $this->languages[$key]; |
|
| 131 | - } |
|
| 132 | - $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
| 133 | - return $default; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Check whether the language file for given name exists |
|
| 138 | - * |
|
| 139 | - * @param string $language the language name like "fr", "en", etc. |
|
| 140 | - * |
|
| 141 | - * @return boolean true if the language directory exists, false or not |
|
| 142 | - */ |
|
| 143 | - public function isValid($language){ |
|
| 144 | - $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
|
| 145 | - foreach($searchDir as $dir){ |
|
| 146 | - if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
| 147 | - return true; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - return false; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Get the default language value like "en" , "fr", etc. |
|
| 155 | - * |
|
| 156 | - * @return string the default language |
|
| 157 | - */ |
|
| 158 | - public function getDefault(){ |
|
| 159 | - return $this->default; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Get the current language defined by cookie or the default value |
|
| 164 | - * |
|
| 165 | - * @return string the current language |
|
| 166 | - */ |
|
| 167 | - public function getCurrent(){ |
|
| 168 | - return $this->current; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Add new supported or available language |
|
| 173 | - * |
|
| 174 | - * @param string $name the short language name like "en", "fr". |
|
| 175 | - * @param string $description the human readable description of this language |
|
| 176 | - */ |
|
| 177 | - public function addLang($name, $description){ |
|
| 178 | - if(isset($this->availables[$name])){ |
|
| 179 | - return; //already added cost in performance |
|
| 180 | - } |
|
| 181 | - if($this->isValid($name)){ |
|
| 182 | - $this->availables[$name] = $description; |
|
| 183 | - } |
|
| 184 | - else{ |
|
| 185 | - show_error('The language [' . $name . '] is not valid or does not exists.'); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Get the list of the application supported language |
|
| 191 | - * |
|
| 192 | - * @return array the list of the application language |
|
| 193 | - */ |
|
| 194 | - public function getSupported(){ |
|
| 195 | - return $this->availables; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Add new language messages |
|
| 200 | - * |
|
| 201 | - * @param array $langs the languages array of the messages to be added |
|
| 202 | - */ |
|
| 203 | - public function addLangMessages(array $langs){ |
|
| 204 | - foreach ($langs as $key => $value) { |
|
| 205 | - $this->set($key, $value); |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - } |
|
| 77 | + //add the supported languages ('key', 'display name') |
|
| 78 | + $languages = get_config('languages', null); |
|
| 79 | + if(! empty($languages)){ |
|
| 80 | + foreach($languages as $key => $displayName){ |
|
| 81 | + $this->addLang($key, $displayName); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + unset($languages); |
|
| 85 | + |
|
| 86 | + //if the language exists in cookie use it |
|
| 87 | + $cfgKey = get_config('language_cookie_name'); |
|
| 88 | + $this->logger->debug('Getting current language from cookie [' .$cfgKey. ']'); |
|
| 89 | + $objCookie = & class_loader('Cookie'); |
|
| 90 | + $cookieLang = $objCookie->get($cfgKey); |
|
| 91 | + if($cookieLang && $this->isValid($cookieLang)){ |
|
| 92 | + $this->current = $cookieLang; |
|
| 93 | + $this->logger->info('Language from cookie [' .$cfgKey. '] is valid so we will set the language using the cookie value [' .$cookieLang. ']'); |
|
| 94 | + } |
|
| 95 | + else{ |
|
| 96 | + $this->logger->info('Language from cookie [' .$cfgKey. '] is not set, use the default value [' .$this->getDefault(). ']'); |
|
| 97 | + $this->current = $this->getDefault(); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Get the all languages messages |
|
| 103 | + * |
|
| 104 | + * @return array the language message list |
|
| 105 | + */ |
|
| 106 | + public function getAll(){ |
|
| 107 | + return $this->languages; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Set the language message |
|
| 112 | + * |
|
| 113 | + * @param string $key the language key to identify |
|
| 114 | + * @param string $value the language message value |
|
| 115 | + */ |
|
| 116 | + public function set($key, $value){ |
|
| 117 | + $this->languages[$key] = $value; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Get the language message for the given key. If can't find return the default value |
|
| 122 | + * |
|
| 123 | + * @param string $key the message language key |
|
| 124 | + * @param string $default the default value to return if can not found the language message key |
|
| 125 | + * |
|
| 126 | + * @return string the language message value |
|
| 127 | + */ |
|
| 128 | + public function get($key, $default = 'LANGUAGE_ERROR'){ |
|
| 129 | + if(isset($this->languages[$key])){ |
|
| 130 | + return $this->languages[$key]; |
|
| 131 | + } |
|
| 132 | + $this->logger->warning('Language key [' .$key. '] does not exist use the default value [' .$default. ']'); |
|
| 133 | + return $default; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Check whether the language file for given name exists |
|
| 138 | + * |
|
| 139 | + * @param string $language the language name like "fr", "en", etc. |
|
| 140 | + * |
|
| 141 | + * @return boolean true if the language directory exists, false or not |
|
| 142 | + */ |
|
| 143 | + public function isValid($language){ |
|
| 144 | + $searchDir = array(CORE_LANG_PATH, APP_LANG_PATH); |
|
| 145 | + foreach($searchDir as $dir){ |
|
| 146 | + if(file_exists($dir . $language) && is_dir($dir . $language)){ |
|
| 147 | + return true; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + return false; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Get the default language value like "en" , "fr", etc. |
|
| 155 | + * |
|
| 156 | + * @return string the default language |
|
| 157 | + */ |
|
| 158 | + public function getDefault(){ |
|
| 159 | + return $this->default; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Get the current language defined by cookie or the default value |
|
| 164 | + * |
|
| 165 | + * @return string the current language |
|
| 166 | + */ |
|
| 167 | + public function getCurrent(){ |
|
| 168 | + return $this->current; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Add new supported or available language |
|
| 173 | + * |
|
| 174 | + * @param string $name the short language name like "en", "fr". |
|
| 175 | + * @param string $description the human readable description of this language |
|
| 176 | + */ |
|
| 177 | + public function addLang($name, $description){ |
|
| 178 | + if(isset($this->availables[$name])){ |
|
| 179 | + return; //already added cost in performance |
|
| 180 | + } |
|
| 181 | + if($this->isValid($name)){ |
|
| 182 | + $this->availables[$name] = $description; |
|
| 183 | + } |
|
| 184 | + else{ |
|
| 185 | + show_error('The language [' . $name . '] is not valid or does not exists.'); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Get the list of the application supported language |
|
| 191 | + * |
|
| 192 | + * @return array the list of the application language |
|
| 193 | + */ |
|
| 194 | + public function getSupported(){ |
|
| 195 | + return $this->availables; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Add new language messages |
|
| 200 | + * |
|
| 201 | + * @param array $langs the languages array of the messages to be added |
|
| 202 | + */ |
|
| 203 | + public function addLangMessages(array $langs){ |
|
| 204 | + foreach ($langs as $key => $value) { |
|
| 205 | + $this->set($key, $value); |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + } |
|
@@ -1,52 +1,52 @@ |
||
| 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 | - if(! function_exists('__')){ |
|
| 28 | - /** |
|
| 29 | - * function for the shortcut to Lang::get() |
|
| 30 | - * @param string $key the language key to retrieve |
|
| 31 | - * @param mixed $default the default value to return if can not find the value |
|
| 32 | - * for the given key |
|
| 33 | - * @return string the language value |
|
| 34 | - */ |
|
| 35 | - function __($key, $default = 'LANGUAGE_ERROR'){ |
|
| 36 | - return get_instance()->lang->get($key, $default); |
|
| 37 | - } |
|
| 27 | + if(! function_exists('__')){ |
|
| 28 | + /** |
|
| 29 | + * function for the shortcut to Lang::get() |
|
| 30 | + * @param string $key the language key to retrieve |
|
| 31 | + * @param mixed $default the default value to return if can not find the value |
|
| 32 | + * for the given key |
|
| 33 | + * @return string the language value |
|
| 34 | + */ |
|
| 35 | + function __($key, $default = 'LANGUAGE_ERROR'){ |
|
| 36 | + return get_instance()->lang->get($key, $default); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - if(! function_exists('get_languages')){ |
|
| 43 | - /** |
|
| 44 | - * function for the shortcut to Lang::getSupported() |
|
| 45 | - * |
|
| 46 | - * @return array all the supported languages |
|
| 47 | - */ |
|
| 48 | - function get_languages(){ |
|
| 49 | - return get_instance()->lang->getSupported(); |
|
| 50 | - } |
|
| 42 | + if(! function_exists('get_languages')){ |
|
| 43 | + /** |
|
| 44 | + * function for the shortcut to Lang::getSupported() |
|
| 45 | + * |
|
| 46 | + * @return array all the supported languages |
|
| 47 | + */ |
|
| 48 | + function get_languages(){ |
|
| 49 | + return get_instance()->lang->getSupported(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - } |
|
| 53 | 52 | \ No newline at end of file |
| 53 | + } |
|
| 54 | 54 | \ No newline at end of file |
@@ -1,739 +1,739 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | - /** |
|
| 4 | - * Simple Mail |
|
| 5 | - * |
|
| 6 | - * A simple PHP wrapper class for sending email using the mail() method. |
|
| 7 | - * |
|
| 8 | - * PHP version > 5.2 |
|
| 9 | - * |
|
| 10 | - * LICENSE: This source file is subject to the MIT license, which is |
|
| 11 | - * available through the world-wide-web at the following URI: |
|
| 12 | - * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt |
|
| 13 | - * |
|
| 14 | - * @category SimpleMail |
|
| 15 | - * @package SimpleMail |
|
| 16 | - * @author Eoghan O'Brien <[email protected]> |
|
| 17 | - * @copyright 2009 - 2017 Eoghan O'Brien |
|
| 18 | - * @license http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT |
|
| 19 | - * @version 1.7.1 |
|
| 20 | - * @link http://github.com/eoghanobrien/php-simple-mail |
|
| 21 | - */ |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Simple Mail class. |
|
| 25 | - * |
|
| 26 | - * @category SimpleMail |
|
| 27 | - * @package SimpleMail |
|
| 28 | - * @author Eoghan O'Brien <[email protected]> |
|
| 29 | - * @copyright 2009 - 2017 Eoghan O'Brien |
|
| 30 | - * @license http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT |
|
| 31 | - * @version 1.7.1 |
|
| 32 | - * @link http://github.com/eoghanobrien/php-simple-mail |
|
| 33 | - */ |
|
| 34 | - class Email |
|
| 35 | - { |
|
| 36 | - /** |
|
| 37 | - * @var int $_wrap |
|
| 38 | - */ |
|
| 39 | - protected $_wrap = 78; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var array $_to |
|
| 43 | - */ |
|
| 44 | - protected $_to = array(); |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string $_subject |
|
| 48 | - */ |
|
| 49 | - protected $_subject; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var string $_message |
|
| 53 | - */ |
|
| 54 | - protected $_message; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var array $_headers |
|
| 58 | - */ |
|
| 59 | - protected $_headers = array(); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string $_parameters |
|
| 63 | - */ |
|
| 64 | - protected $_params; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var array $_attachments |
|
| 68 | - */ |
|
| 69 | - protected $_attachments = array(); |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var string $_uid |
|
| 73 | - */ |
|
| 74 | - protected $_uid; |
|
| 2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
| 3 | + /** |
|
| 4 | + * Simple Mail |
|
| 5 | + * |
|
| 6 | + * A simple PHP wrapper class for sending email using the mail() method. |
|
| 7 | + * |
|
| 8 | + * PHP version > 5.2 |
|
| 9 | + * |
|
| 10 | + * LICENSE: This source file is subject to the MIT license, which is |
|
| 11 | + * available through the world-wide-web at the following URI: |
|
| 12 | + * http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt |
|
| 13 | + * |
|
| 14 | + * @category SimpleMail |
|
| 15 | + * @package SimpleMail |
|
| 16 | + * @author Eoghan O'Brien <[email protected]> |
|
| 17 | + * @copyright 2009 - 2017 Eoghan O'Brien |
|
| 18 | + * @license http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT |
|
| 19 | + * @version 1.7.1 |
|
| 20 | + * @link http://github.com/eoghanobrien/php-simple-mail |
|
| 21 | + */ |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Simple Mail class. |
|
| 25 | + * |
|
| 26 | + * @category SimpleMail |
|
| 27 | + * @package SimpleMail |
|
| 28 | + * @author Eoghan O'Brien <[email protected]> |
|
| 29 | + * @copyright 2009 - 2017 Eoghan O'Brien |
|
| 30 | + * @license http://github.com/eoghanobrien/php-simple-mail/LICENCE.txt MIT |
|
| 31 | + * @version 1.7.1 |
|
| 32 | + * @link http://github.com/eoghanobrien/php-simple-mail |
|
| 33 | + */ |
|
| 34 | + class Email |
|
| 35 | + { |
|
| 36 | + /** |
|
| 37 | + * @var int $_wrap |
|
| 38 | + */ |
|
| 39 | + protected $_wrap = 78; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var array $_to |
|
| 43 | + */ |
|
| 44 | + protected $_to = array(); |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string $_subject |
|
| 48 | + */ |
|
| 49 | + protected $_subject; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var string $_message |
|
| 53 | + */ |
|
| 54 | + protected $_message; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var array $_headers |
|
| 58 | + */ |
|
| 59 | + protected $_headers = array(); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string $_parameters |
|
| 63 | + */ |
|
| 64 | + protected $_params; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var array $_attachments |
|
| 68 | + */ |
|
| 69 | + protected $_attachments = array(); |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var string $_uid |
|
| 73 | + */ |
|
| 74 | + protected $_uid; |
|
| 75 | 75 | |
| 76 | - /** |
|
| 76 | + /** |
|
| 77 | 77 | * The logger instance |
| 78 | 78 | * @var Log |
| 79 | 79 | */ |
| 80 | - private $logger; |
|
| 80 | + private $logger; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * __construct |
|
| 84 | - * |
|
| 85 | - * Resets the class properties. |
|
| 86 | - */ |
|
| 87 | - public function __construct() |
|
| 88 | - { |
|
| 89 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 82 | + /** |
|
| 83 | + * __construct |
|
| 84 | + * |
|
| 85 | + * Resets the class properties. |
|
| 86 | + */ |
|
| 87 | + public function __construct() |
|
| 88 | + { |
|
| 89 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 90 | 90 | $this->logger->setLogger('Library::Email'); |
| 91 | - $this->reset(); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * reset |
|
| 96 | - * |
|
| 97 | - * Resets all properties to initial state. |
|
| 98 | - * |
|
| 99 | - * @return self |
|
| 100 | - */ |
|
| 101 | - public function reset() |
|
| 102 | - { |
|
| 103 | - $this->_to = array(); |
|
| 104 | - $this->_headers = array(); |
|
| 105 | - $this->_subject = null; |
|
| 106 | - $this->_message = null; |
|
| 107 | - $this->_wrap = 78; |
|
| 108 | - $this->_params = null; |
|
| 109 | - $this->_attachments = array(); |
|
| 110 | - $this->_uid = $this->getUniqueId(); |
|
| 111 | - return $this; |
|
| 112 | - } |
|
| 91 | + $this->reset(); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * reset |
|
| 96 | + * |
|
| 97 | + * Resets all properties to initial state. |
|
| 98 | + * |
|
| 99 | + * @return self |
|
| 100 | + */ |
|
| 101 | + public function reset() |
|
| 102 | + { |
|
| 103 | + $this->_to = array(); |
|
| 104 | + $this->_headers = array(); |
|
| 105 | + $this->_subject = null; |
|
| 106 | + $this->_message = null; |
|
| 107 | + $this->_wrap = 78; |
|
| 108 | + $this->_params = null; |
|
| 109 | + $this->_attachments = array(); |
|
| 110 | + $this->_uid = $this->getUniqueId(); |
|
| 111 | + return $this; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * setFrom |
|
| 116 | - * |
|
| 117 | - * @param string $email The email to send as from. |
|
| 118 | - * @param string $name The name to send as from. |
|
| 119 | - * |
|
| 120 | - * @return self |
|
| 121 | - */ |
|
| 122 | - public function setFrom($email, $name = null) |
|
| 123 | - { |
|
| 124 | - $this->addMailHeader('From', (string) $email, (string) $name); |
|
| 125 | - return $this; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * setTo |
|
| 130 | - * |
|
| 131 | - * @param string $email The email address to send to. |
|
| 132 | - * @param string $name The name of the person to send to. |
|
| 133 | - * |
|
| 134 | - * @return self |
|
| 135 | - */ |
|
| 136 | - public function setTo($email, $name = null) |
|
| 137 | - { |
|
| 138 | - $this->_to[] = $this->formatHeader((string) $email, (string) $name); |
|
| 139 | - return $this; |
|
| 140 | - } |
|
| 114 | + /** |
|
| 115 | + * setFrom |
|
| 116 | + * |
|
| 117 | + * @param string $email The email to send as from. |
|
| 118 | + * @param string $name The name to send as from. |
|
| 119 | + * |
|
| 120 | + * @return self |
|
| 121 | + */ |
|
| 122 | + public function setFrom($email, $name = null) |
|
| 123 | + { |
|
| 124 | + $this->addMailHeader('From', (string) $email, (string) $name); |
|
| 125 | + return $this; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * setTo |
|
| 130 | + * |
|
| 131 | + * @param string $email The email address to send to. |
|
| 132 | + * @param string $name The name of the person to send to. |
|
| 133 | + * |
|
| 134 | + * @return self |
|
| 135 | + */ |
|
| 136 | + public function setTo($email, $name = null) |
|
| 137 | + { |
|
| 138 | + $this->_to[] = $this->formatHeader((string) $email, (string) $name); |
|
| 139 | + return $this; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Set destination using array |
|
| 144 | - * @params array $emails the list of recipient. This is an associative array name => email |
|
| 145 | - * @example array('John Doe' => '[email protected]') |
|
| 146 | - * @return Object the current instance |
|
| 147 | - */ |
|
| 148 | - public function setTos(array $emails) |
|
| 149 | - { |
|
| 150 | - foreach ($emails as $name => $email) { |
|
| 151 | - if(is_numeric($name)){ |
|
| 152 | - $this->setTo($email); |
|
| 153 | - } |
|
| 154 | - else{ |
|
| 155 | - $this->setTo($email, $name); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - return $this; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * getTo |
|
| 164 | - * |
|
| 165 | - * Return an array of formatted To addresses. |
|
| 166 | - * |
|
| 167 | - * @return array |
|
| 168 | - */ |
|
| 169 | - public function getTo() |
|
| 170 | - { |
|
| 171 | - return $this->_to; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * setCc |
|
| 177 | - * |
|
| 178 | - * @param array $pairs An array of name => email pairs. |
|
| 179 | - * |
|
| 180 | - * @return self |
|
| 181 | - */ |
|
| 182 | - public function setCc(array $pairs) |
|
| 183 | - { |
|
| 184 | - return $this->addMailHeaders('Cc', $pairs); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * setBcc |
|
| 189 | - * |
|
| 190 | - * @param array $pairs An array of name => email pairs. |
|
| 191 | - * |
|
| 192 | - * @return self |
|
| 193 | - */ |
|
| 194 | - public function setBcc(array $pairs) |
|
| 195 | - { |
|
| 196 | - return $this->addMailHeaders('Bcc', $pairs); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * setReplyTo |
|
| 201 | - * |
|
| 202 | - * @param string $email |
|
| 203 | - * @param string $name |
|
| 204 | - * |
|
| 205 | - * @return self |
|
| 206 | - */ |
|
| 207 | - public function setReplyTo($email, $name = null) |
|
| 208 | - { |
|
| 209 | - return $this->addMailHeader('Reply-To', $email, $name); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * setHtml |
|
| 214 | - * |
|
| 215 | - * @return self |
|
| 216 | - */ |
|
| 217 | - public function setHtml() |
|
| 218 | - { |
|
| 219 | - $this->addGenericHeader( |
|
| 220 | - 'Content-Type', 'text/html; charset="utf-8"' |
|
| 221 | - ); |
|
| 222 | - return $this; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * setSubject |
|
| 227 | - * |
|
| 228 | - * @param string $subject The email subject |
|
| 229 | - * |
|
| 230 | - * @return self |
|
| 231 | - */ |
|
| 232 | - public function setSubject($subject) |
|
| 233 | - { |
|
| 234 | - $this->_subject = $this->encodeUtf8( |
|
| 235 | - $this->filterOther((string) $subject) |
|
| 236 | - ); |
|
| 237 | - return $this; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * getSubject function. |
|
| 242 | - * |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public function getSubject() |
|
| 246 | - { |
|
| 247 | - return $this->_subject; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * setMessage |
|
| 252 | - * |
|
| 253 | - * @param string $message The message to send. |
|
| 254 | - * |
|
| 255 | - * @return self |
|
| 256 | - */ |
|
| 257 | - public function setMessage($message) |
|
| 258 | - { |
|
| 259 | - $this->_message = str_replace("\n.", "\n..", (string) $message); |
|
| 260 | - return $this; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * getMessage |
|
| 265 | - * |
|
| 266 | - * @return string |
|
| 267 | - */ |
|
| 268 | - public function getMessage() |
|
| 269 | - { |
|
| 270 | - return $this->_message; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * addAttachment |
|
| 275 | - * |
|
| 276 | - * @param string $path The file path to the attachment. |
|
| 277 | - * @param string $filename The filename of the attachment when emailed. |
|
| 278 | - * @param string $data |
|
| 279 | - * |
|
| 280 | - * @return self |
|
| 281 | - */ |
|
| 282 | - public function addAttachment($path, $filename = null, $data = null) |
|
| 283 | - { |
|
| 284 | - if(! file_exists($path)){ |
|
| 285 | - show_error('The file [' .$path. '] does not exists.'); |
|
| 286 | - } |
|
| 287 | - $filename = empty($filename) ? basename($path) : $filename; |
|
| 288 | - $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
|
| 289 | - $data = empty($data) ? $this->getAttachmentData($path) : $data; |
|
| 290 | - $this->_attachments[] = array( |
|
| 291 | - 'path' => $path, |
|
| 292 | - 'file' => $filename, |
|
| 293 | - 'data' => chunk_split(base64_encode($data)) |
|
| 294 | - ); |
|
| 295 | - return $this; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * getAttachmentData |
|
| 300 | - * |
|
| 301 | - * @param string $path The path to the attachment file. |
|
| 302 | - * |
|
| 303 | - * @return string |
|
| 304 | - */ |
|
| 305 | - public function getAttachmentData($path) |
|
| 306 | - { |
|
| 307 | - if(! file_exists($path)){ |
|
| 308 | - show_error('The file [' .$path. '] does not exists.'); |
|
| 309 | - } |
|
| 310 | - $filesize = filesize($path); |
|
| 311 | - $handle = fopen($path, "r"); |
|
| 312 | - $attachment = null; |
|
| 313 | - if(is_resource($handle)){ |
|
| 314 | - $attachment = fread($handle, $filesize); |
|
| 315 | - fclose($handle); |
|
| 316 | - } |
|
| 317 | - return $attachment; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * addMailHeader |
|
| 322 | - * |
|
| 323 | - * @param string $header The header to add. |
|
| 324 | - * @param string $email The email to add. |
|
| 325 | - * @param string $name The name to add. |
|
| 326 | - * |
|
| 327 | - * @return self |
|
| 328 | - */ |
|
| 329 | - public function addMailHeader($header, $email, $name = null) |
|
| 330 | - { |
|
| 331 | - $address = $this->formatHeader((string) $email, (string) $name); |
|
| 332 | - $this->_headers[] = sprintf('%s: %s', (string) $header, $address); |
|
| 333 | - return $this; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * addMailHeaders |
|
| 338 | - * |
|
| 339 | - * @param string $header The header to add. |
|
| 340 | - * @param array $pairs An array of name => email pairs. |
|
| 341 | - * |
|
| 342 | - * @return self |
|
| 343 | - */ |
|
| 344 | - public function addMailHeaders($header, array $pairs) |
|
| 345 | - { |
|
| 346 | - if (count($pairs) === 0) { |
|
| 347 | - show_error('You must pass at least one name => email pair.'); |
|
| 348 | - } |
|
| 349 | - $addresses = array(); |
|
| 350 | - foreach ($pairs as $name => $email) { |
|
| 351 | - $name = is_numeric($name) ? null : $name; |
|
| 352 | - $addresses[] = $this->formatHeader($email, $name); |
|
| 353 | - } |
|
| 354 | - $this->addGenericHeader($header, implode(',', $addresses)); |
|
| 355 | - return $this; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * addGenericHeader |
|
| 360 | - * |
|
| 361 | - * @param string $name The generic header to add. |
|
| 362 | - * @param mixed $value The value of the header. |
|
| 363 | - * |
|
| 364 | - * @return self |
|
| 365 | - */ |
|
| 366 | - public function addGenericHeader($name, $value) |
|
| 367 | - { |
|
| 368 | - $this->_headers[] = sprintf( |
|
| 369 | - '%s: %s', |
|
| 370 | - (string) $name, |
|
| 371 | - (string) $value |
|
| 372 | - ); |
|
| 373 | - return $this; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * getHeaders |
|
| 378 | - * |
|
| 379 | - * Return the headers registered so far as an array. |
|
| 380 | - * |
|
| 381 | - * @return array |
|
| 382 | - */ |
|
| 383 | - public function getHeaders() |
|
| 384 | - { |
|
| 385 | - return $this->_headers; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * setAdditionalParameters |
|
| 390 | - * |
|
| 391 | - * Such as "[email protected] |
|
| 392 | - * |
|
| 393 | - * @param string $additionalParameters The addition mail parameter. |
|
| 394 | - * |
|
| 395 | - * @return self |
|
| 396 | - */ |
|
| 397 | - public function setParameters($additionalParameters) |
|
| 398 | - { |
|
| 399 | - $this->_params = (string) $additionalParameters; |
|
| 400 | - return $this; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * getAdditionalParameters |
|
| 405 | - * |
|
| 406 | - * @return string |
|
| 407 | - */ |
|
| 408 | - public function getParameters() |
|
| 409 | - { |
|
| 410 | - return $this->_params; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * setWrap |
|
| 415 | - * |
|
| 416 | - * @param int $wrap The number of characters at which the message will wrap. |
|
| 417 | - * |
|
| 418 | - * @return self |
|
| 419 | - */ |
|
| 420 | - public function setWrap($wrap = 78) |
|
| 421 | - { |
|
| 422 | - $wrap = (int) $wrap; |
|
| 423 | - if ($wrap < 1) { |
|
| 424 | - $wrap = 78; |
|
| 425 | - } |
|
| 426 | - $this->_wrap = $wrap; |
|
| 427 | - return $this; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * getWrap |
|
| 432 | - * |
|
| 433 | - * @return int |
|
| 434 | - */ |
|
| 435 | - public function getWrap() |
|
| 436 | - { |
|
| 437 | - return $this->_wrap; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * hasAttachments |
|
| 442 | - * |
|
| 443 | - * Checks if the email has any registered attachments. |
|
| 444 | - * |
|
| 445 | - * @return bool |
|
| 446 | - */ |
|
| 447 | - public function hasAttachments() |
|
| 448 | - { |
|
| 449 | - return !empty($this->_attachments); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * assembleAttachment |
|
| 454 | - * |
|
| 455 | - * @return string |
|
| 456 | - */ |
|
| 457 | - public function assembleAttachmentHeaders() |
|
| 458 | - { |
|
| 459 | - $head = array(); |
|
| 460 | - $head[] = "MIME-Version: 1.0"; |
|
| 461 | - $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\""; |
|
| 462 | - |
|
| 463 | - return join(PHP_EOL, $head); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * assembleAttachmentBody |
|
| 468 | - * |
|
| 469 | - * @return string |
|
| 470 | - */ |
|
| 471 | - public function assembleAttachmentBody() |
|
| 472 | - { |
|
| 473 | - $body = array(); |
|
| 474 | - $body[] = "This is a multi-part message in MIME format."; |
|
| 475 | - $body[] = "--{$this->_uid}"; |
|
| 476 | - $body[] = "Content-Type: text/html; charset=\"utf-8\""; |
|
| 477 | - $body[] = "Content-Transfer-Encoding: quoted-printable"; |
|
| 478 | - $body[] = ""; |
|
| 479 | - $body[] = quoted_printable_encode($this->_message); |
|
| 480 | - $body[] = ""; |
|
| 481 | - $body[] = "--{$this->_uid}"; |
|
| 482 | - |
|
| 483 | - foreach ($this->_attachments as $attachment) { |
|
| 484 | - $body[] = $this->getAttachmentMimeTemplate($attachment); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return implode(PHP_EOL, $body) . '--'; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * getAttachmentMimeTemplate |
|
| 492 | - * |
|
| 493 | - * @param array $attachment An array containing 'file' and 'data' keys. |
|
| 494 | - * |
|
| 495 | - * @return string |
|
| 496 | - */ |
|
| 497 | - public function getAttachmentMimeTemplate($attachment) |
|
| 498 | - { |
|
| 499 | - $file = $attachment['file']; |
|
| 500 | - $data = $attachment['data']; |
|
| 501 | - |
|
| 502 | - $head = array(); |
|
| 503 | - $head[] = "Content-Type: application/octet-stream; name=\"{$file}\""; |
|
| 504 | - $head[] = "Content-Transfer-Encoding: base64"; |
|
| 505 | - $head[] = "Content-Disposition: attachment; filename=\"{$file}\""; |
|
| 506 | - $head[] = ""; |
|
| 507 | - $head[] = $data; |
|
| 508 | - $head[] = ""; |
|
| 509 | - $head[] = "--{$this->_uid}"; |
|
| 510 | - |
|
| 511 | - return implode(PHP_EOL, $head); |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * send the email |
|
| 516 | - * |
|
| 517 | - * @return boolean |
|
| 518 | - */ |
|
| 519 | - public function send() |
|
| 520 | - { |
|
| 521 | - $to = $this->getToForSend(); |
|
| 522 | - $headers = $this->getHeadersForSend(); |
|
| 523 | - |
|
| 524 | - if (empty($to)) { |
|
| 525 | - show_error('Unable to send, no To address has been set.'); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - if ($this->hasAttachments()) { |
|
| 529 | - $message = $this->assembleAttachmentBody(); |
|
| 530 | - $headers .= PHP_EOL . $this->assembleAttachmentHeaders(); |
|
| 531 | - } else { |
|
| 532 | - $message = $this->getWrapMessage(); |
|
| 533 | - } |
|
| 534 | - $this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message); |
|
| 535 | - return mail($to, $this->_subject, $message, $headers, $this->_params); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * debug |
|
| 540 | - * |
|
| 541 | - * @return string |
|
| 542 | - */ |
|
| 543 | - public function debug() |
|
| 544 | - { |
|
| 545 | - return '<pre>' . print_r($this, true) . '</pre>'; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * magic __toString function |
|
| 550 | - * |
|
| 551 | - * @return string |
|
| 552 | - */ |
|
| 553 | - public function __toString() |
|
| 554 | - { |
|
| 555 | - return print_r($this, true); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * formatHeader |
|
| 560 | - * |
|
| 561 | - * Formats a display address for emails according to RFC2822 e.g. |
|
| 562 | - * Name <[email protected]> |
|
| 563 | - * |
|
| 564 | - * @param string $email The email address. |
|
| 565 | - * @param string $name The display name. |
|
| 566 | - * |
|
| 567 | - * @return string |
|
| 568 | - */ |
|
| 569 | - public function formatHeader($email, $name = null) |
|
| 570 | - { |
|
| 571 | - $email = $this->filterEmail((string) $email); |
|
| 572 | - if (empty($name)) { |
|
| 573 | - return $email; |
|
| 574 | - } |
|
| 575 | - $name = $this->encodeUtf8($this->filterName((string) $name)); |
|
| 576 | - return sprintf('"%s" <%s>', $name, $email); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * encodeUtf8 |
|
| 581 | - * |
|
| 582 | - * @param string $value The value to encode. |
|
| 583 | - * |
|
| 584 | - * @return string |
|
| 585 | - */ |
|
| 586 | - public function encodeUtf8($value) |
|
| 587 | - { |
|
| 588 | - $value = trim($value); |
|
| 589 | - if (preg_match('/(\s)/', $value)) { |
|
| 590 | - return $this->encodeUtf8Words($value); |
|
| 591 | - } |
|
| 592 | - return $this->encodeUtf8Word($value); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * encodeUtf8Word |
|
| 597 | - * |
|
| 598 | - * @param string $value The word to encode. |
|
| 599 | - * |
|
| 600 | - * @return string |
|
| 601 | - */ |
|
| 602 | - public function encodeUtf8Word($value) |
|
| 603 | - { |
|
| 604 | - return sprintf('=?UTF-8?B?%s?=', base64_encode($value)); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * encodeUtf8Words |
|
| 609 | - * |
|
| 610 | - * @param string $value The words to encode. |
|
| 611 | - * |
|
| 612 | - * @return string |
|
| 613 | - */ |
|
| 614 | - public function encodeUtf8Words($value) |
|
| 615 | - { |
|
| 616 | - $words = explode(' ', $value); |
|
| 617 | - $encoded = array(); |
|
| 618 | - foreach ($words as $word) { |
|
| 619 | - $encoded[] = $this->encodeUtf8Word($word); |
|
| 620 | - } |
|
| 621 | - return join($this->encodeUtf8Word(' '), $encoded); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * filterEmail |
|
| 626 | - * |
|
| 627 | - * Removes any carriage return, line feed, tab, double quote, comma |
|
| 628 | - * and angle bracket characters before sanitizing the email address. |
|
| 629 | - * |
|
| 630 | - * @param string $email The email to filter. |
|
| 631 | - * |
|
| 632 | - * @return string |
|
| 633 | - */ |
|
| 634 | - public function filterEmail($email) |
|
| 635 | - { |
|
| 636 | - $rule = array( |
|
| 637 | - "\r" => '', |
|
| 638 | - "\n" => '', |
|
| 639 | - "\t" => '', |
|
| 640 | - '"' => '', |
|
| 641 | - ',' => '', |
|
| 642 | - '<' => '', |
|
| 643 | - '>' => '' |
|
| 644 | - ); |
|
| 645 | - $email = strtr($email, $rule); |
|
| 646 | - $email = filter_var($email, FILTER_SANITIZE_EMAIL); |
|
| 647 | - return $email; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * filterName |
|
| 652 | - * |
|
| 653 | - * Removes any carriage return, line feed or tab characters. Replaces |
|
| 654 | - * double quotes with single quotes and angle brackets with square |
|
| 655 | - * brackets, before sanitizing the string and stripping out html tags. |
|
| 656 | - * |
|
| 657 | - * @param string $name The name to filter. |
|
| 658 | - * |
|
| 659 | - * @return string |
|
| 660 | - */ |
|
| 661 | - public function filterName($name) |
|
| 662 | - { |
|
| 663 | - $rule = array( |
|
| 664 | - "\r" => '', |
|
| 665 | - "\n" => '', |
|
| 666 | - "\t" => '', |
|
| 667 | - '"' => "'", |
|
| 668 | - '<' => '[', |
|
| 669 | - '>' => ']', |
|
| 670 | - ); |
|
| 671 | - $filtered = filter_var( |
|
| 672 | - $name, |
|
| 673 | - FILTER_SANITIZE_STRING, |
|
| 674 | - FILTER_FLAG_NO_ENCODE_QUOTES |
|
| 675 | - ); |
|
| 676 | - return trim(strtr($filtered, $rule)); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * filterOther |
|
| 681 | - * |
|
| 682 | - * Removes ASCII control characters including any carriage return, line |
|
| 683 | - * feed or tab characters. |
|
| 684 | - * |
|
| 685 | - * @param string $data The data to filter. |
|
| 686 | - * |
|
| 687 | - * @return string |
|
| 688 | - */ |
|
| 689 | - public function filterOther($data) |
|
| 690 | - { |
|
| 691 | - return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * getHeadersForSend |
|
| 696 | - * |
|
| 697 | - * @return string |
|
| 698 | - */ |
|
| 699 | - public function getHeadersForSend() |
|
| 700 | - { |
|
| 701 | - if (empty($this->_headers)) { |
|
| 702 | - return ''; |
|
| 703 | - } |
|
| 704 | - return join(PHP_EOL, $this->_headers); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * getToForSend |
|
| 709 | - * |
|
| 710 | - * @return string |
|
| 711 | - */ |
|
| 712 | - public function getToForSend() |
|
| 713 | - { |
|
| 714 | - if (empty($this->_to)) { |
|
| 715 | - return ''; |
|
| 716 | - } |
|
| 717 | - return join(', ', $this->_to); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * getUniqueId |
|
| 722 | - * |
|
| 723 | - * @return string |
|
| 724 | - */ |
|
| 725 | - public function getUniqueId() |
|
| 726 | - { |
|
| 727 | - return md5(uniqid(time())); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * getWrapMessage |
|
| 732 | - * |
|
| 733 | - * @return string |
|
| 734 | - */ |
|
| 735 | - public function getWrapMessage() |
|
| 736 | - { |
|
| 737 | - return wordwrap($this->_message, $this->_wrap); |
|
| 738 | - } |
|
| 739 | - } |
|
| 142 | + /** |
|
| 143 | + * Set destination using array |
|
| 144 | + * @params array $emails the list of recipient. This is an associative array name => email |
|
| 145 | + * @example array('John Doe' => '[email protected]') |
|
| 146 | + * @return Object the current instance |
|
| 147 | + */ |
|
| 148 | + public function setTos(array $emails) |
|
| 149 | + { |
|
| 150 | + foreach ($emails as $name => $email) { |
|
| 151 | + if(is_numeric($name)){ |
|
| 152 | + $this->setTo($email); |
|
| 153 | + } |
|
| 154 | + else{ |
|
| 155 | + $this->setTo($email, $name); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + return $this; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * getTo |
|
| 164 | + * |
|
| 165 | + * Return an array of formatted To addresses. |
|
| 166 | + * |
|
| 167 | + * @return array |
|
| 168 | + */ |
|
| 169 | + public function getTo() |
|
| 170 | + { |
|
| 171 | + return $this->_to; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * setCc |
|
| 177 | + * |
|
| 178 | + * @param array $pairs An array of name => email pairs. |
|
| 179 | + * |
|
| 180 | + * @return self |
|
| 181 | + */ |
|
| 182 | + public function setCc(array $pairs) |
|
| 183 | + { |
|
| 184 | + return $this->addMailHeaders('Cc', $pairs); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * setBcc |
|
| 189 | + * |
|
| 190 | + * @param array $pairs An array of name => email pairs. |
|
| 191 | + * |
|
| 192 | + * @return self |
|
| 193 | + */ |
|
| 194 | + public function setBcc(array $pairs) |
|
| 195 | + { |
|
| 196 | + return $this->addMailHeaders('Bcc', $pairs); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * setReplyTo |
|
| 201 | + * |
|
| 202 | + * @param string $email |
|
| 203 | + * @param string $name |
|
| 204 | + * |
|
| 205 | + * @return self |
|
| 206 | + */ |
|
| 207 | + public function setReplyTo($email, $name = null) |
|
| 208 | + { |
|
| 209 | + return $this->addMailHeader('Reply-To', $email, $name); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * setHtml |
|
| 214 | + * |
|
| 215 | + * @return self |
|
| 216 | + */ |
|
| 217 | + public function setHtml() |
|
| 218 | + { |
|
| 219 | + $this->addGenericHeader( |
|
| 220 | + 'Content-Type', 'text/html; charset="utf-8"' |
|
| 221 | + ); |
|
| 222 | + return $this; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * setSubject |
|
| 227 | + * |
|
| 228 | + * @param string $subject The email subject |
|
| 229 | + * |
|
| 230 | + * @return self |
|
| 231 | + */ |
|
| 232 | + public function setSubject($subject) |
|
| 233 | + { |
|
| 234 | + $this->_subject = $this->encodeUtf8( |
|
| 235 | + $this->filterOther((string) $subject) |
|
| 236 | + ); |
|
| 237 | + return $this; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * getSubject function. |
|
| 242 | + * |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public function getSubject() |
|
| 246 | + { |
|
| 247 | + return $this->_subject; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * setMessage |
|
| 252 | + * |
|
| 253 | + * @param string $message The message to send. |
|
| 254 | + * |
|
| 255 | + * @return self |
|
| 256 | + */ |
|
| 257 | + public function setMessage($message) |
|
| 258 | + { |
|
| 259 | + $this->_message = str_replace("\n.", "\n..", (string) $message); |
|
| 260 | + return $this; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * getMessage |
|
| 265 | + * |
|
| 266 | + * @return string |
|
| 267 | + */ |
|
| 268 | + public function getMessage() |
|
| 269 | + { |
|
| 270 | + return $this->_message; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * addAttachment |
|
| 275 | + * |
|
| 276 | + * @param string $path The file path to the attachment. |
|
| 277 | + * @param string $filename The filename of the attachment when emailed. |
|
| 278 | + * @param string $data |
|
| 279 | + * |
|
| 280 | + * @return self |
|
| 281 | + */ |
|
| 282 | + public function addAttachment($path, $filename = null, $data = null) |
|
| 283 | + { |
|
| 284 | + if(! file_exists($path)){ |
|
| 285 | + show_error('The file [' .$path. '] does not exists.'); |
|
| 286 | + } |
|
| 287 | + $filename = empty($filename) ? basename($path) : $filename; |
|
| 288 | + $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
|
| 289 | + $data = empty($data) ? $this->getAttachmentData($path) : $data; |
|
| 290 | + $this->_attachments[] = array( |
|
| 291 | + 'path' => $path, |
|
| 292 | + 'file' => $filename, |
|
| 293 | + 'data' => chunk_split(base64_encode($data)) |
|
| 294 | + ); |
|
| 295 | + return $this; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * getAttachmentData |
|
| 300 | + * |
|
| 301 | + * @param string $path The path to the attachment file. |
|
| 302 | + * |
|
| 303 | + * @return string |
|
| 304 | + */ |
|
| 305 | + public function getAttachmentData($path) |
|
| 306 | + { |
|
| 307 | + if(! file_exists($path)){ |
|
| 308 | + show_error('The file [' .$path. '] does not exists.'); |
|
| 309 | + } |
|
| 310 | + $filesize = filesize($path); |
|
| 311 | + $handle = fopen($path, "r"); |
|
| 312 | + $attachment = null; |
|
| 313 | + if(is_resource($handle)){ |
|
| 314 | + $attachment = fread($handle, $filesize); |
|
| 315 | + fclose($handle); |
|
| 316 | + } |
|
| 317 | + return $attachment; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * addMailHeader |
|
| 322 | + * |
|
| 323 | + * @param string $header The header to add. |
|
| 324 | + * @param string $email The email to add. |
|
| 325 | + * @param string $name The name to add. |
|
| 326 | + * |
|
| 327 | + * @return self |
|
| 328 | + */ |
|
| 329 | + public function addMailHeader($header, $email, $name = null) |
|
| 330 | + { |
|
| 331 | + $address = $this->formatHeader((string) $email, (string) $name); |
|
| 332 | + $this->_headers[] = sprintf('%s: %s', (string) $header, $address); |
|
| 333 | + return $this; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * addMailHeaders |
|
| 338 | + * |
|
| 339 | + * @param string $header The header to add. |
|
| 340 | + * @param array $pairs An array of name => email pairs. |
|
| 341 | + * |
|
| 342 | + * @return self |
|
| 343 | + */ |
|
| 344 | + public function addMailHeaders($header, array $pairs) |
|
| 345 | + { |
|
| 346 | + if (count($pairs) === 0) { |
|
| 347 | + show_error('You must pass at least one name => email pair.'); |
|
| 348 | + } |
|
| 349 | + $addresses = array(); |
|
| 350 | + foreach ($pairs as $name => $email) { |
|
| 351 | + $name = is_numeric($name) ? null : $name; |
|
| 352 | + $addresses[] = $this->formatHeader($email, $name); |
|
| 353 | + } |
|
| 354 | + $this->addGenericHeader($header, implode(',', $addresses)); |
|
| 355 | + return $this; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * addGenericHeader |
|
| 360 | + * |
|
| 361 | + * @param string $name The generic header to add. |
|
| 362 | + * @param mixed $value The value of the header. |
|
| 363 | + * |
|
| 364 | + * @return self |
|
| 365 | + */ |
|
| 366 | + public function addGenericHeader($name, $value) |
|
| 367 | + { |
|
| 368 | + $this->_headers[] = sprintf( |
|
| 369 | + '%s: %s', |
|
| 370 | + (string) $name, |
|
| 371 | + (string) $value |
|
| 372 | + ); |
|
| 373 | + return $this; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * getHeaders |
|
| 378 | + * |
|
| 379 | + * Return the headers registered so far as an array. |
|
| 380 | + * |
|
| 381 | + * @return array |
|
| 382 | + */ |
|
| 383 | + public function getHeaders() |
|
| 384 | + { |
|
| 385 | + return $this->_headers; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * setAdditionalParameters |
|
| 390 | + * |
|
| 391 | + * Such as "[email protected] |
|
| 392 | + * |
|
| 393 | + * @param string $additionalParameters The addition mail parameter. |
|
| 394 | + * |
|
| 395 | + * @return self |
|
| 396 | + */ |
|
| 397 | + public function setParameters($additionalParameters) |
|
| 398 | + { |
|
| 399 | + $this->_params = (string) $additionalParameters; |
|
| 400 | + return $this; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * getAdditionalParameters |
|
| 405 | + * |
|
| 406 | + * @return string |
|
| 407 | + */ |
|
| 408 | + public function getParameters() |
|
| 409 | + { |
|
| 410 | + return $this->_params; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * setWrap |
|
| 415 | + * |
|
| 416 | + * @param int $wrap The number of characters at which the message will wrap. |
|
| 417 | + * |
|
| 418 | + * @return self |
|
| 419 | + */ |
|
| 420 | + public function setWrap($wrap = 78) |
|
| 421 | + { |
|
| 422 | + $wrap = (int) $wrap; |
|
| 423 | + if ($wrap < 1) { |
|
| 424 | + $wrap = 78; |
|
| 425 | + } |
|
| 426 | + $this->_wrap = $wrap; |
|
| 427 | + return $this; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * getWrap |
|
| 432 | + * |
|
| 433 | + * @return int |
|
| 434 | + */ |
|
| 435 | + public function getWrap() |
|
| 436 | + { |
|
| 437 | + return $this->_wrap; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * hasAttachments |
|
| 442 | + * |
|
| 443 | + * Checks if the email has any registered attachments. |
|
| 444 | + * |
|
| 445 | + * @return bool |
|
| 446 | + */ |
|
| 447 | + public function hasAttachments() |
|
| 448 | + { |
|
| 449 | + return !empty($this->_attachments); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * assembleAttachment |
|
| 454 | + * |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + public function assembleAttachmentHeaders() |
|
| 458 | + { |
|
| 459 | + $head = array(); |
|
| 460 | + $head[] = "MIME-Version: 1.0"; |
|
| 461 | + $head[] = "Content-Type: multipart/mixed; boundary=\"{$this->_uid}\""; |
|
| 462 | + |
|
| 463 | + return join(PHP_EOL, $head); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * assembleAttachmentBody |
|
| 468 | + * |
|
| 469 | + * @return string |
|
| 470 | + */ |
|
| 471 | + public function assembleAttachmentBody() |
|
| 472 | + { |
|
| 473 | + $body = array(); |
|
| 474 | + $body[] = "This is a multi-part message in MIME format."; |
|
| 475 | + $body[] = "--{$this->_uid}"; |
|
| 476 | + $body[] = "Content-Type: text/html; charset=\"utf-8\""; |
|
| 477 | + $body[] = "Content-Transfer-Encoding: quoted-printable"; |
|
| 478 | + $body[] = ""; |
|
| 479 | + $body[] = quoted_printable_encode($this->_message); |
|
| 480 | + $body[] = ""; |
|
| 481 | + $body[] = "--{$this->_uid}"; |
|
| 482 | + |
|
| 483 | + foreach ($this->_attachments as $attachment) { |
|
| 484 | + $body[] = $this->getAttachmentMimeTemplate($attachment); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return implode(PHP_EOL, $body) . '--'; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * getAttachmentMimeTemplate |
|
| 492 | + * |
|
| 493 | + * @param array $attachment An array containing 'file' and 'data' keys. |
|
| 494 | + * |
|
| 495 | + * @return string |
|
| 496 | + */ |
|
| 497 | + public function getAttachmentMimeTemplate($attachment) |
|
| 498 | + { |
|
| 499 | + $file = $attachment['file']; |
|
| 500 | + $data = $attachment['data']; |
|
| 501 | + |
|
| 502 | + $head = array(); |
|
| 503 | + $head[] = "Content-Type: application/octet-stream; name=\"{$file}\""; |
|
| 504 | + $head[] = "Content-Transfer-Encoding: base64"; |
|
| 505 | + $head[] = "Content-Disposition: attachment; filename=\"{$file}\""; |
|
| 506 | + $head[] = ""; |
|
| 507 | + $head[] = $data; |
|
| 508 | + $head[] = ""; |
|
| 509 | + $head[] = "--{$this->_uid}"; |
|
| 510 | + |
|
| 511 | + return implode(PHP_EOL, $head); |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * send the email |
|
| 516 | + * |
|
| 517 | + * @return boolean |
|
| 518 | + */ |
|
| 519 | + public function send() |
|
| 520 | + { |
|
| 521 | + $to = $this->getToForSend(); |
|
| 522 | + $headers = $this->getHeadersForSend(); |
|
| 523 | + |
|
| 524 | + if (empty($to)) { |
|
| 525 | + show_error('Unable to send, no To address has been set.'); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + if ($this->hasAttachments()) { |
|
| 529 | + $message = $this->assembleAttachmentBody(); |
|
| 530 | + $headers .= PHP_EOL . $this->assembleAttachmentHeaders(); |
|
| 531 | + } else { |
|
| 532 | + $message = $this->getWrapMessage(); |
|
| 533 | + } |
|
| 534 | + $this->logger->info('Sending new mail, the information are listed below: destination: ' . $to . ', headers: ' . $headers . ', message: ' . $message); |
|
| 535 | + return mail($to, $this->_subject, $message, $headers, $this->_params); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * debug |
|
| 540 | + * |
|
| 541 | + * @return string |
|
| 542 | + */ |
|
| 543 | + public function debug() |
|
| 544 | + { |
|
| 545 | + return '<pre>' . print_r($this, true) . '</pre>'; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * magic __toString function |
|
| 550 | + * |
|
| 551 | + * @return string |
|
| 552 | + */ |
|
| 553 | + public function __toString() |
|
| 554 | + { |
|
| 555 | + return print_r($this, true); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * formatHeader |
|
| 560 | + * |
|
| 561 | + * Formats a display address for emails according to RFC2822 e.g. |
|
| 562 | + * Name <[email protected]> |
|
| 563 | + * |
|
| 564 | + * @param string $email The email address. |
|
| 565 | + * @param string $name The display name. |
|
| 566 | + * |
|
| 567 | + * @return string |
|
| 568 | + */ |
|
| 569 | + public function formatHeader($email, $name = null) |
|
| 570 | + { |
|
| 571 | + $email = $this->filterEmail((string) $email); |
|
| 572 | + if (empty($name)) { |
|
| 573 | + return $email; |
|
| 574 | + } |
|
| 575 | + $name = $this->encodeUtf8($this->filterName((string) $name)); |
|
| 576 | + return sprintf('"%s" <%s>', $name, $email); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * encodeUtf8 |
|
| 581 | + * |
|
| 582 | + * @param string $value The value to encode. |
|
| 583 | + * |
|
| 584 | + * @return string |
|
| 585 | + */ |
|
| 586 | + public function encodeUtf8($value) |
|
| 587 | + { |
|
| 588 | + $value = trim($value); |
|
| 589 | + if (preg_match('/(\s)/', $value)) { |
|
| 590 | + return $this->encodeUtf8Words($value); |
|
| 591 | + } |
|
| 592 | + return $this->encodeUtf8Word($value); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * encodeUtf8Word |
|
| 597 | + * |
|
| 598 | + * @param string $value The word to encode. |
|
| 599 | + * |
|
| 600 | + * @return string |
|
| 601 | + */ |
|
| 602 | + public function encodeUtf8Word($value) |
|
| 603 | + { |
|
| 604 | + return sprintf('=?UTF-8?B?%s?=', base64_encode($value)); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * encodeUtf8Words |
|
| 609 | + * |
|
| 610 | + * @param string $value The words to encode. |
|
| 611 | + * |
|
| 612 | + * @return string |
|
| 613 | + */ |
|
| 614 | + public function encodeUtf8Words($value) |
|
| 615 | + { |
|
| 616 | + $words = explode(' ', $value); |
|
| 617 | + $encoded = array(); |
|
| 618 | + foreach ($words as $word) { |
|
| 619 | + $encoded[] = $this->encodeUtf8Word($word); |
|
| 620 | + } |
|
| 621 | + return join($this->encodeUtf8Word(' '), $encoded); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * filterEmail |
|
| 626 | + * |
|
| 627 | + * Removes any carriage return, line feed, tab, double quote, comma |
|
| 628 | + * and angle bracket characters before sanitizing the email address. |
|
| 629 | + * |
|
| 630 | + * @param string $email The email to filter. |
|
| 631 | + * |
|
| 632 | + * @return string |
|
| 633 | + */ |
|
| 634 | + public function filterEmail($email) |
|
| 635 | + { |
|
| 636 | + $rule = array( |
|
| 637 | + "\r" => '', |
|
| 638 | + "\n" => '', |
|
| 639 | + "\t" => '', |
|
| 640 | + '"' => '', |
|
| 641 | + ',' => '', |
|
| 642 | + '<' => '', |
|
| 643 | + '>' => '' |
|
| 644 | + ); |
|
| 645 | + $email = strtr($email, $rule); |
|
| 646 | + $email = filter_var($email, FILTER_SANITIZE_EMAIL); |
|
| 647 | + return $email; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * filterName |
|
| 652 | + * |
|
| 653 | + * Removes any carriage return, line feed or tab characters. Replaces |
|
| 654 | + * double quotes with single quotes and angle brackets with square |
|
| 655 | + * brackets, before sanitizing the string and stripping out html tags. |
|
| 656 | + * |
|
| 657 | + * @param string $name The name to filter. |
|
| 658 | + * |
|
| 659 | + * @return string |
|
| 660 | + */ |
|
| 661 | + public function filterName($name) |
|
| 662 | + { |
|
| 663 | + $rule = array( |
|
| 664 | + "\r" => '', |
|
| 665 | + "\n" => '', |
|
| 666 | + "\t" => '', |
|
| 667 | + '"' => "'", |
|
| 668 | + '<' => '[', |
|
| 669 | + '>' => ']', |
|
| 670 | + ); |
|
| 671 | + $filtered = filter_var( |
|
| 672 | + $name, |
|
| 673 | + FILTER_SANITIZE_STRING, |
|
| 674 | + FILTER_FLAG_NO_ENCODE_QUOTES |
|
| 675 | + ); |
|
| 676 | + return trim(strtr($filtered, $rule)); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * filterOther |
|
| 681 | + * |
|
| 682 | + * Removes ASCII control characters including any carriage return, line |
|
| 683 | + * feed or tab characters. |
|
| 684 | + * |
|
| 685 | + * @param string $data The data to filter. |
|
| 686 | + * |
|
| 687 | + * @return string |
|
| 688 | + */ |
|
| 689 | + public function filterOther($data) |
|
| 690 | + { |
|
| 691 | + return filter_var($data, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * getHeadersForSend |
|
| 696 | + * |
|
| 697 | + * @return string |
|
| 698 | + */ |
|
| 699 | + public function getHeadersForSend() |
|
| 700 | + { |
|
| 701 | + if (empty($this->_headers)) { |
|
| 702 | + return ''; |
|
| 703 | + } |
|
| 704 | + return join(PHP_EOL, $this->_headers); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * getToForSend |
|
| 709 | + * |
|
| 710 | + * @return string |
|
| 711 | + */ |
|
| 712 | + public function getToForSend() |
|
| 713 | + { |
|
| 714 | + if (empty($this->_to)) { |
|
| 715 | + return ''; |
|
| 716 | + } |
|
| 717 | + return join(', ', $this->_to); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * getUniqueId |
|
| 722 | + * |
|
| 723 | + * @return string |
|
| 724 | + */ |
|
| 725 | + public function getUniqueId() |
|
| 726 | + { |
|
| 727 | + return md5(uniqid(time())); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * getWrapMessage |
|
| 732 | + * |
|
| 733 | + * @return string |
|
| 734 | + */ |
|
| 735 | + public function getWrapMessage() |
|
| 736 | + { |
|
| 737 | + return wordwrap($this->_message, $this->_wrap); |
|
| 738 | + } |
|
| 739 | + } |
|
@@ -1,112 +1,112 @@ |
||
| 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 | - class Cookie{ |
|
| 27 | + class Cookie{ |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * The logger instance |
|
| 31 | - * @var Log |
|
| 32 | - */ |
|
| 33 | - private static $logger; |
|
| 29 | + /** |
|
| 30 | + * The logger instance |
|
| 31 | + * @var Log |
|
| 32 | + */ |
|
| 33 | + private static $logger; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The signleton of the logger |
|
| 37 | - * @return Object the Log instance |
|
| 38 | - */ |
|
| 39 | - private static function getLogger(){ |
|
| 40 | - if(self::$logger == null){ |
|
| 41 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 42 | - self::$logger[0]->setLogger('Library::Cookie'); |
|
| 43 | - } |
|
| 44 | - return self::$logger[0]; |
|
| 45 | - } |
|
| 35 | + /** |
|
| 36 | + * The signleton of the logger |
|
| 37 | + * @return Object the Log instance |
|
| 38 | + */ |
|
| 39 | + private static function getLogger(){ |
|
| 40 | + if(self::$logger == null){ |
|
| 41 | + self::$logger[0] =& class_loader('Log', 'classes'); |
|
| 42 | + self::$logger[0]->setLogger('Library::Cookie'); |
|
| 43 | + } |
|
| 44 | + return self::$logger[0]; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Get the cookie item value |
|
| 49 | - * @param string $item the cookie item name to get |
|
| 50 | - * @param mixed $default the default value to use if can not find the cokkie item in the list |
|
| 51 | - * @return mixed the cookie value if exist or the default value |
|
| 52 | - */ |
|
| 53 | - public static function get($item, $default = null){ |
|
| 54 | - $logger = self::getLogger(); |
|
| 55 | - if(array_key_exists($item, $_COOKIE)){ |
|
| 56 | - return $_COOKIE[$item]; |
|
| 57 | - } |
|
| 58 | - $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']'); |
|
| 59 | - return $default; |
|
| 60 | - } |
|
| 47 | + /** |
|
| 48 | + * Get the cookie item value |
|
| 49 | + * @param string $item the cookie item name to get |
|
| 50 | + * @param mixed $default the default value to use if can not find the cokkie item in the list |
|
| 51 | + * @return mixed the cookie value if exist or the default value |
|
| 52 | + */ |
|
| 53 | + public static function get($item, $default = null){ |
|
| 54 | + $logger = self::getLogger(); |
|
| 55 | + if(array_key_exists($item, $_COOKIE)){ |
|
| 56 | + return $_COOKIE[$item]; |
|
| 57 | + } |
|
| 58 | + $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']'); |
|
| 59 | + return $default; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Set the cookie item value |
|
| 64 | - * @param string $name the cookie item name |
|
| 65 | - * @param string $value the cookie value to set |
|
| 66 | - * @param integer $expire the time to live for this cookie |
|
| 67 | - * @param string $path the path that the cookie will be available |
|
| 68 | - * @param string $domain the domain that the cookie will be available |
|
| 69 | - * @param boolean $secure if this cookie will be available on secure connection or not |
|
| 70 | - * @param boolean $httponly if this cookie will be available under HTTP protocol. |
|
| 71 | - */ |
|
| 72 | - public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){ |
|
| 73 | - if(headers_sent()){ |
|
| 74 | - show_error('There exists a cookie that we wanted to create that we couldn\'t |
|
| 62 | + /** |
|
| 63 | + * Set the cookie item value |
|
| 64 | + * @param string $name the cookie item name |
|
| 65 | + * @param string $value the cookie value to set |
|
| 66 | + * @param integer $expire the time to live for this cookie |
|
| 67 | + * @param string $path the path that the cookie will be available |
|
| 68 | + * @param string $domain the domain that the cookie will be available |
|
| 69 | + * @param boolean $secure if this cookie will be available on secure connection or not |
|
| 70 | + * @param boolean $httponly if this cookie will be available under HTTP protocol. |
|
| 71 | + */ |
|
| 72 | + public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){ |
|
| 73 | + if(headers_sent()){ |
|
| 74 | + show_error('There exists a cookie that we wanted to create that we couldn\'t |
|
| 75 | 75 | because headers was already sent. Make sure to do this first |
| 76 | 76 | before outputing anything.'); |
| 77 | - } |
|
| 78 | - $timestamp = $expire; |
|
| 79 | - if($expire){ |
|
| 80 | - $timestamp = time() + $expire; |
|
| 81 | - } |
|
| 82 | - setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly); |
|
| 83 | - } |
|
| 77 | + } |
|
| 78 | + $timestamp = $expire; |
|
| 79 | + if($expire){ |
|
| 80 | + $timestamp = time() + $expire; |
|
| 81 | + } |
|
| 82 | + setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Delete the cookie item in the list |
|
| 87 | - * @param string $item the cookie item name to be cleared |
|
| 88 | - * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
| 89 | - */ |
|
| 90 | - public static function delete($item){ |
|
| 91 | - $logger = self::getLogger(); |
|
| 92 | - if(array_key_exists($item, $_COOKIE)){ |
|
| 93 | - $logger->info('Delete cookie item ['.$item.']'); |
|
| 94 | - unset($_COOKIE[$item]); |
|
| 95 | - return true; |
|
| 96 | - } |
|
| 97 | - else{ |
|
| 98 | - $logger->warning('Cookie item ['.$item.'] to be deleted does not exists'); |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - } |
|
| 85 | + /** |
|
| 86 | + * Delete the cookie item in the list |
|
| 87 | + * @param string $item the cookie item name to be cleared |
|
| 88 | + * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
|
| 89 | + */ |
|
| 90 | + public static function delete($item){ |
|
| 91 | + $logger = self::getLogger(); |
|
| 92 | + if(array_key_exists($item, $_COOKIE)){ |
|
| 93 | + $logger->info('Delete cookie item ['.$item.']'); |
|
| 94 | + unset($_COOKIE[$item]); |
|
| 95 | + return true; |
|
| 96 | + } |
|
| 97 | + else{ |
|
| 98 | + $logger->warning('Cookie item ['.$item.'] to be deleted does not exists'); |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Check if the given cookie item exists |
|
| 105 | - * @param string $item the cookie item name |
|
| 106 | - * @return boolean true if the cookie item is set, false or not |
|
| 107 | - */ |
|
| 108 | - public static function exists($item){ |
|
| 109 | - return array_key_exists($item, $_COOKIE); |
|
| 110 | - } |
|
| 103 | + /** |
|
| 104 | + * Check if the given cookie item exists |
|
| 105 | + * @param string $item the cookie item name |
|
| 106 | + * @return boolean true if the cookie item is set, false or not |
|
| 107 | + */ |
|
| 108 | + public static function exists($item){ |
|
| 109 | + return array_key_exists($item, $_COOKIE); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - } |
|
| 112 | + } |
|
@@ -1,65 +1,65 @@ |
||
| 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 | - class StringHash{ |
|
| 27 | + class StringHash{ |
|
| 28 | 28 | |
| 29 | - //blowfish |
|
| 30 | - private static $algo = '$2a'; |
|
| 29 | + //blowfish |
|
| 30 | + private static $algo = '$2a'; |
|
| 31 | 31 | |
| 32 | - //cost parameter |
|
| 33 | - private static $cost = '$10'; |
|
| 32 | + //cost parameter |
|
| 33 | + private static $cost = '$10'; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Get the unique salt for the string hash |
|
| 37 | - * @return string the unique generated salt |
|
| 38 | - */ |
|
| 39 | - private static function uniqueSalt() { |
|
| 40 | - return substr(sha1(mt_rand()), 0, 22); |
|
| 41 | - } |
|
| 35 | + /** |
|
| 36 | + * Get the unique salt for the string hash |
|
| 37 | + * @return string the unique generated salt |
|
| 38 | + */ |
|
| 39 | + private static function uniqueSalt() { |
|
| 40 | + return substr(sha1(mt_rand()), 0, 22); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Hash the given string |
|
| 45 | - * @param string $value the plain string text to be hashed |
|
| 46 | - * @return string the hashed string |
|
| 47 | - */ |
|
| 48 | - public static function hash($value) { |
|
| 49 | - return crypt($value, self::$algo . |
|
| 50 | - self::$cost . |
|
| 51 | - '$' . self::uniqueSalt()); |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * Hash the given string |
|
| 45 | + * @param string $value the plain string text to be hashed |
|
| 46 | + * @return string the hashed string |
|
| 47 | + */ |
|
| 48 | + public static function hash($value) { |
|
| 49 | + return crypt($value, self::$algo . |
|
| 50 | + self::$cost . |
|
| 51 | + '$' . self::uniqueSalt()); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Check if the hash and plain string is valid |
|
| 56 | - * @param string $hash the hashed string |
|
| 57 | - * @param string $plain the plain text |
|
| 58 | - * @return boolean true if is valid or false if not |
|
| 59 | - */ |
|
| 60 | - public static function check($hash, $plain) { |
|
| 61 | - $full_salt = substr($hash, 0, 29); |
|
| 62 | - $new_hash = crypt($plain, $full_salt); |
|
| 63 | - return ($hash === $new_hash); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | 54 | \ No newline at end of file |
| 55 | + /** |
|
| 56 | + * Check if the hash and plain string is valid |
|
| 57 | + * @param string $hash the hashed string |
|
| 58 | + * @param string $plain the plain text |
|
| 59 | + * @return boolean true if is valid or false if not |
|
| 60 | + */ |
|
| 61 | + public static function check($hash, $plain) { |
|
| 62 | + $full_salt = substr($hash, 0, 29); |
|
| 63 | + $new_hash = crypt($plain, $full_salt); |
|
| 64 | + return ($hash === $new_hash); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | \ No newline at end of file |
@@ -1,89 +1,89 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') or 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') or 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 | - * Class for Benchmark |
|
| 29 | - */ |
|
| 30 | - class Benchmark{ |
|
| 31 | - /** |
|
| 32 | - * The markers for excution time |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - private $markersTime = array(); |
|
| 27 | + /** |
|
| 28 | + * Class for Benchmark |
|
| 29 | + */ |
|
| 30 | + class Benchmark{ |
|
| 31 | + /** |
|
| 32 | + * The markers for excution time |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + private $markersTime = array(); |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * The markers for memory usage |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - private $markersMemory = array(); |
|
| 37 | + /** |
|
| 38 | + * The markers for memory usage |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + private $markersMemory = array(); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * This method is used to mark one point for benchmark (execution time and memory usage) |
|
| 45 | - * @param string $name the marker name |
|
| 46 | - */ |
|
| 47 | - public function mark($name){ |
|
| 48 | - //Marker for execution time |
|
| 49 | - $this->markersTime[$name] = microtime(true); |
|
| 50 | - //Marker for memory usage |
|
| 51 | - $this->markersMemory[$name] = memory_get_usage(true); |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * This method is used to mark one point for benchmark (execution time and memory usage) |
|
| 45 | + * @param string $name the marker name |
|
| 46 | + */ |
|
| 47 | + public function mark($name){ |
|
| 48 | + //Marker for execution time |
|
| 49 | + $this->markersTime[$name] = microtime(true); |
|
| 50 | + //Marker for memory usage |
|
| 51 | + $this->markersMemory[$name] = memory_get_usage(true); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * This method is used to get the total excution time in second between two markers |
|
| 56 | - * @param string $startMarkerName the marker for start point |
|
| 57 | - * @param string $endMarkerName the marker for end point |
|
| 58 | - * @param integer $decimalCount the number of decimal |
|
| 59 | - * @return string the total execution time |
|
| 60 | - */ |
|
| 61 | - public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 62 | - if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
| 63 | - return 0; |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * This method is used to get the total excution time in second between two markers |
|
| 56 | + * @param string $startMarkerName the marker for start point |
|
| 57 | + * @param string $endMarkerName the marker for end point |
|
| 58 | + * @param integer $decimalCount the number of decimal |
|
| 59 | + * @return string the total execution time |
|
| 60 | + */ |
|
| 61 | + public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 62 | + if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
| 63 | + return 0; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if(! isset($this->markersTime[$endMarkerName])){ |
|
| 67 | - $this->markersTime[$endMarkerName] = microtime(true); |
|
| 68 | - } |
|
| 69 | - return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
|
| 70 | - } |
|
| 66 | + if(! isset($this->markersTime[$endMarkerName])){ |
|
| 67 | + $this->markersTime[$endMarkerName] = microtime(true); |
|
| 68 | + } |
|
| 69 | + return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * This method is used to get the total memory usage in byte between two markers |
|
| 74 | - * @param string $startMarkerName the marker for start point |
|
| 75 | - * @param string $endMarkerName the marker for end point |
|
| 76 | - * @param integer $decimalCount the number of decimal |
|
| 77 | - * @return string the total memory usage |
|
| 78 | - */ |
|
| 79 | - public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 80 | - if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
| 81 | - return 0; |
|
| 82 | - } |
|
| 72 | + /** |
|
| 73 | + * This method is used to get the total memory usage in byte between two markers |
|
| 74 | + * @param string $startMarkerName the marker for start point |
|
| 75 | + * @param string $endMarkerName the marker for end point |
|
| 76 | + * @param integer $decimalCount the number of decimal |
|
| 77 | + * @return string the total memory usage |
|
| 78 | + */ |
|
| 79 | + public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
| 80 | + if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
| 81 | + return 0; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if(! isset($this->markersMemory[$endMarkerName])){ |
|
| 85 | - $this->markersMemory[$endMarkerName] = microtime(true); |
|
| 86 | - } |
|
| 87 | - return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
|
| 88 | - } |
|
| 89 | - } |
|
| 84 | + if(! isset($this->markersMemory[$endMarkerName])){ |
|
| 85 | + $this->markersMemory[$endMarkerName] = microtime(true); |
|
| 86 | + } |
|
| 87 | + return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
|
| 88 | + } |
|
| 89 | + } |
|
@@ -1,87 +1,87 @@ |
||
| 1 | 1 | <?php |
| 2 | - defined('ROOT_PATH') or 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') or 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 | - * PDF library to generate PDF document using the library DOMPDF |
|
| 29 | - */ |
|
| 30 | - class PDF{ |
|
| 27 | + /** |
|
| 28 | + * PDF library to generate PDF document using the library DOMPDF |
|
| 29 | + */ |
|
| 30 | + class PDF{ |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The dompdf instance |
|
| 34 | - * @var Dompdf |
|
| 35 | - */ |
|
| 36 | - private $dompdf = null; |
|
| 32 | + /** |
|
| 33 | + * The dompdf instance |
|
| 34 | + * @var Dompdf |
|
| 35 | + */ |
|
| 36 | + private $dompdf = null; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * The logger instance |
|
| 40 | - * @var Log |
|
| 41 | - */ |
|
| 42 | - private $logger; |
|
| 38 | + /** |
|
| 39 | + * The logger instance |
|
| 40 | + * @var Log |
|
| 41 | + */ |
|
| 42 | + private $logger; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Create PDF library instance |
|
| 46 | - */ |
|
| 47 | - public function __construct(){ |
|
| 48 | - $this->logger =& class_loader('Log', 'classes'); |
|
| 49 | - $this->logger->setLogger('Library::PDF'); |
|
| 44 | + /** |
|
| 45 | + * Create PDF library instance |
|
| 46 | + */ |
|
| 47 | + public function __construct(){ |
|
| 48 | + $this->logger =& class_loader('Log', 'classes'); |
|
| 49 | + $this->logger->setLogger('Library::PDF'); |
|
| 50 | 50 | |
| 51 | - require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
|
| 52 | - $this->dompdf = new Dompdf(); |
|
| 53 | - } |
|
| 51 | + require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
|
| 52 | + $this->dompdf = new Dompdf(); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Generate PDF document |
|
| 57 | - * @param string $html the HTML content to use for generation |
|
| 58 | - * @param string $filename the generated PDF document filename |
|
| 59 | - * @param boolean $stream if need send the generated PDF to browser for download |
|
| 60 | - * @param string $paper the PDF document paper type like 'A4', 'A5', 'letter', etc. |
|
| 61 | - * @param string $orientation the PDF document orientation like 'portrait', 'landscape' |
|
| 62 | - * @return string|void if $stream is true send PDF document to browser for download, else return the generated PDF |
|
| 63 | - * content like to join in Email attachment of for other purpose use. |
|
| 64 | - */ |
|
| 65 | - public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){ |
|
| 66 | - $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']'); |
|
| 67 | - $this->dompdf->load_html($html); |
|
| 68 | - $this->dompdf->set_paper($paper, $orientation); |
|
| 69 | - $this->dompdf->render(); |
|
| 70 | - if($stream){ |
|
| 71 | - $this->dompdf->stream($filename); |
|
| 72 | - } |
|
| 73 | - else{ |
|
| 74 | - return $this->dompdf->output(); |
|
| 75 | - } |
|
| 76 | - } |
|
| 55 | + /** |
|
| 56 | + * Generate PDF document |
|
| 57 | + * @param string $html the HTML content to use for generation |
|
| 58 | + * @param string $filename the generated PDF document filename |
|
| 59 | + * @param boolean $stream if need send the generated PDF to browser for download |
|
| 60 | + * @param string $paper the PDF document paper type like 'A4', 'A5', 'letter', etc. |
|
| 61 | + * @param string $orientation the PDF document orientation like 'portrait', 'landscape' |
|
| 62 | + * @return string|void if $stream is true send PDF document to browser for download, else return the generated PDF |
|
| 63 | + * content like to join in Email attachment of for other purpose use. |
|
| 64 | + */ |
|
| 65 | + public function generate($html, $filename = 'output.pdf', $stream = true, $paper = 'A4', $orientation = 'portrait'){ |
|
| 66 | + $this->logger->info('Generating of PDF document: filename [' .$filename. '], stream [' .($stream ? 'TRUE':'FALSE'). '], paper [' .$paper. '], orientation [' .$orientation. ']'); |
|
| 67 | + $this->dompdf->load_html($html); |
|
| 68 | + $this->dompdf->set_paper($paper, $orientation); |
|
| 69 | + $this->dompdf->render(); |
|
| 70 | + if($stream){ |
|
| 71 | + $this->dompdf->stream($filename); |
|
| 72 | + } |
|
| 73 | + else{ |
|
| 74 | + return $this->dompdf->output(); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Return the instance of Dompdf |
|
| 80 | - * |
|
| 81 | - * @return object the dompdf instance |
|
| 82 | - */ |
|
| 83 | - public function getDompdf(){ |
|
| 84 | - return $this->dompdf; |
|
| 85 | - } |
|
| 78 | + /** |
|
| 79 | + * Return the instance of Dompdf |
|
| 80 | + * |
|
| 81 | + * @return object the dompdf instance |
|
| 82 | + */ |
|
| 83 | + public function getDompdf(){ |
|
| 84 | + return $this->dompdf; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - } |
|
| 87 | + } |
|
@@ -22,139 +22,139 @@ discard block |
||
| 22 | 22 | * You should have received a copy of the GNU General Public License |
| 23 | 23 | * along with this program; if not, write to the Free Software |
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | - */ |
|
| 25 | + */ |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Upload |
|
| 31 | - * |
|
| 32 | - * A complete class to upload files with php 5 or higher, but the best: very simple to use. |
|
| 33 | - * |
|
| 34 | - * @author Olaf Erlandsen <[email protected]> |
|
| 35 | - * @author http://www.webdevfreelance.com/ |
|
| 36 | - * |
|
| 37 | - * @package FileUpload |
|
| 38 | - * @version 1.5 |
|
| 39 | - */ |
|
| 30 | + * Upload |
|
| 31 | + * |
|
| 32 | + * A complete class to upload files with php 5 or higher, but the best: very simple to use. |
|
| 33 | + * |
|
| 34 | + * @author Olaf Erlandsen <[email protected]> |
|
| 35 | + * @author http://www.webdevfreelance.com/ |
|
| 36 | + * |
|
| 37 | + * @package FileUpload |
|
| 38 | + * @version 1.5 |
|
| 39 | + */ |
|
| 40 | 40 | class Upload{ |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * Version |
|
| 44 | - * |
|
| 45 | - * @since 1.5 |
|
| 46 | - * @version 1.0 |
|
| 47 | - */ |
|
| 43 | + * Version |
|
| 44 | + * |
|
| 45 | + * @since 1.5 |
|
| 46 | + * @version 1.0 |
|
| 47 | + */ |
|
| 48 | 48 | const VERSION = '1.5'; |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Upload function name |
|
| 52 | - * Remember: |
|
| 53 | - * Default function: move_uploaded_file |
|
| 54 | - * Native options: |
|
| 55 | - * - move_uploaded_file (Default and best option) |
|
| 56 | - * - copy |
|
| 57 | - * |
|
| 58 | - * @since 1.0 |
|
| 59 | - * @version 1.0 |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 51 | + * Upload function name |
|
| 52 | + * Remember: |
|
| 53 | + * Default function: move_uploaded_file |
|
| 54 | + * Native options: |
|
| 55 | + * - move_uploaded_file (Default and best option) |
|
| 56 | + * - copy |
|
| 57 | + * |
|
| 58 | + * @since 1.0 |
|
| 59 | + * @version 1.0 |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | private $upload_function = 'move_uploaded_file'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * Array with the information obtained from the |
|
| 66 | - * variable $_FILES or $HTTP_POST_FILES. |
|
| 67 | - * |
|
| 68 | - * @since 1.0 |
|
| 69 | - * @version 1.0 |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 65 | + * Array with the information obtained from the |
|
| 66 | + * variable $_FILES or $HTTP_POST_FILES. |
|
| 67 | + * |
|
| 68 | + * @since 1.0 |
|
| 69 | + * @version 1.0 |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | 72 | private $file_array = array(); |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | - * If the file you are trying to upload already exists it will |
|
| 76 | - * be overwritten if you set the variable to true. |
|
| 77 | - * |
|
| 78 | - * @since 1.0 |
|
| 79 | - * @version 1.0 |
|
| 80 | - * @var boolean |
|
| 81 | - */ |
|
| 75 | + * If the file you are trying to upload already exists it will |
|
| 76 | + * be overwritten if you set the variable to true. |
|
| 77 | + * |
|
| 78 | + * @since 1.0 |
|
| 79 | + * @version 1.0 |
|
| 80 | + * @var boolean |
|
| 81 | + */ |
|
| 82 | 82 | private $overwrite_file = false; |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | - * Input element |
|
| 86 | - * Example: |
|
| 87 | - * <input type="file" name="file" /> |
|
| 88 | - * Result: |
|
| 89 | - * FileUpload::$input = file |
|
| 90 | - * |
|
| 91 | - * @since 1.0 |
|
| 92 | - * @version 1.0 |
|
| 93 | - * @var string |
|
| 94 | - */ |
|
| 85 | + * Input element |
|
| 86 | + * Example: |
|
| 87 | + * <input type="file" name="file" /> |
|
| 88 | + * Result: |
|
| 89 | + * FileUpload::$input = file |
|
| 90 | + * |
|
| 91 | + * @since 1.0 |
|
| 92 | + * @version 1.0 |
|
| 93 | + * @var string |
|
| 94 | + */ |
|
| 95 | 95 | private $input; |
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | - * Path output |
|
| 99 | - * |
|
| 100 | - * @since 1.0 |
|
| 101 | - * @version 1.0 |
|
| 102 | - * @var string |
|
| 103 | - */ |
|
| 98 | + * Path output |
|
| 99 | + * |
|
| 100 | + * @since 1.0 |
|
| 101 | + * @version 1.0 |
|
| 102 | + * @var string |
|
| 103 | + */ |
|
| 104 | 104 | private $destination_directory; |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * Output filename |
|
| 108 | - * |
|
| 109 | - * @since 1.0 |
|
| 110 | - * @version 1.0 |
|
| 111 | - * @var string |
|
| 112 | - */ |
|
| 107 | + * Output filename |
|
| 108 | + * |
|
| 109 | + * @since 1.0 |
|
| 110 | + * @version 1.0 |
|
| 111 | + * @var string |
|
| 112 | + */ |
|
| 113 | 113 | private $filename; |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | - * Max file size |
|
| 117 | - * |
|
| 118 | - * @since 1.0 |
|
| 119 | - * @version 1.0 |
|
| 120 | - * @var float |
|
| 121 | - */ |
|
| 116 | + * Max file size |
|
| 117 | + * |
|
| 118 | + * @since 1.0 |
|
| 119 | + * @version 1.0 |
|
| 120 | + * @var float |
|
| 121 | + */ |
|
| 122 | 122 | private $max_file_size= 0.0; |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * List of allowed mime types |
|
| 126 | - * |
|
| 127 | - * @since 1.0 |
|
| 128 | - * @version 1.0 |
|
| 129 | - * @var array |
|
| 130 | - */ |
|
| 125 | + * List of allowed mime types |
|
| 126 | + * |
|
| 127 | + * @since 1.0 |
|
| 128 | + * @version 1.0 |
|
| 129 | + * @var array |
|
| 130 | + */ |
|
| 131 | 131 | private $allowed_mime_types = array(); |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | - * Callbacks |
|
| 135 | - * |
|
| 136 | - * @since 1.0 |
|
| 137 | - * @version 1.0 |
|
| 138 | - * @var array |
|
| 139 | - */ |
|
| 134 | + * Callbacks |
|
| 135 | + * |
|
| 136 | + * @since 1.0 |
|
| 137 | + * @version 1.0 |
|
| 138 | + * @var array |
|
| 139 | + */ |
|
| 140 | 140 | private $callbacks = array('before' => null, 'after' => null); |
| 141 | 141 | |
| 142 | 142 | /** |
| 143 | - * File object |
|
| 144 | - * |
|
| 145 | - * @since 1.0 |
|
| 146 | - * @version 1.0 |
|
| 147 | - * @var object |
|
| 148 | - */ |
|
| 143 | + * File object |
|
| 144 | + * |
|
| 145 | + * @since 1.0 |
|
| 146 | + * @version 1.0 |
|
| 147 | + * @var object |
|
| 148 | + */ |
|
| 149 | 149 | private $file; |
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | - * Helping mime types |
|
| 153 | - * |
|
| 154 | - * @since 1.0 |
|
| 155 | - * @version 1.0 |
|
| 156 | - * @var array |
|
| 157 | - */ |
|
| 152 | + * Helping mime types |
|
| 153 | + * |
|
| 154 | + * @since 1.0 |
|
| 155 | + * @version 1.0 |
|
| 156 | + * @var array |
|
| 157 | + */ |
|
| 158 | 158 | private $mime_helping = array( |
| 159 | 159 | 'text' => array('text/plain',), |
| 160 | 160 | 'image' => array( |
@@ -210,13 +210,13 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | - * Construct |
|
| 214 | - * |
|
| 215 | - * @since 0.1 |
|
| 216 | - * @version 1.0.1 |
|
| 217 | - * @return object |
|
| 218 | - * @method object __construct |
|
| 219 | - */ |
|
| 213 | + * Construct |
|
| 214 | + * |
|
| 215 | + * @since 0.1 |
|
| 216 | + * @version 1.0.1 |
|
| 217 | + * @return object |
|
| 218 | + * @method object __construct |
|
| 219 | + */ |
|
| 220 | 220 | public function __construct(){ |
| 221 | 221 | $this->logger =& class_loader('Log', 'classes'); |
| 222 | 222 | $this->logger->setLogger('Library::Upload'); |
@@ -260,17 +260,17 @@ discard block |
||
| 260 | 260 | $this->logger->info('The upload file information are : ' .stringfy_vars($this->file_array)); |
| 261 | 261 | } |
| 262 | 262 | /** |
| 263 | - * Set input. |
|
| 264 | - * If you have $_FILES["file"], you must use the key "file" |
|
| 265 | - * Example: |
|
| 266 | - * $object->setInput("file"); |
|
| 267 | - * |
|
| 268 | - * @since 1.0 |
|
| 269 | - * @version 1.0 |
|
| 270 | - * @param string $input |
|
| 271 | - * @return object |
|
| 272 | - * @method boolean setInput |
|
| 273 | - */ |
|
| 263 | + * Set input. |
|
| 264 | + * If you have $_FILES["file"], you must use the key "file" |
|
| 265 | + * Example: |
|
| 266 | + * $object->setInput("file"); |
|
| 267 | + * |
|
| 268 | + * @since 1.0 |
|
| 269 | + * @version 1.0 |
|
| 270 | + * @param string $input |
|
| 271 | + * @return object |
|
| 272 | + * @method boolean setInput |
|
| 273 | + */ |
|
| 274 | 274 | public function setInput($input) |
| 275 | 275 | { |
| 276 | 276 | if (!empty($input) && (is_string($input) || is_numeric($input) )) { |
@@ -279,18 +279,18 @@ discard block |
||
| 279 | 279 | return $this; |
| 280 | 280 | } |
| 281 | 281 | /** |
| 282 | - * Set new filename |
|
| 283 | - * Example: |
|
| 284 | - * FileUpload::setFilename("new file.txt") |
|
| 285 | - * Remember: |
|
| 286 | - * Use %s to retrive file extension |
|
| 287 | - * |
|
| 288 | - * @since 1.0 |
|
| 289 | - * @version 1.0 |
|
| 290 | - * @param string $filename |
|
| 291 | - * @return object |
|
| 292 | - * @method boolean setFilename |
|
| 293 | - */ |
|
| 282 | + * Set new filename |
|
| 283 | + * Example: |
|
| 284 | + * FileUpload::setFilename("new file.txt") |
|
| 285 | + * Remember: |
|
| 286 | + * Use %s to retrive file extension |
|
| 287 | + * |
|
| 288 | + * @since 1.0 |
|
| 289 | + * @version 1.0 |
|
| 290 | + * @param string $filename |
|
| 291 | + * @return object |
|
| 292 | + * @method boolean setFilename |
|
| 293 | + */ |
|
| 294 | 294 | public function setFilename($filename) |
| 295 | 295 | { |
| 296 | 296 | if ($this->isFilename($filename)) { |
@@ -299,14 +299,14 @@ discard block |
||
| 299 | 299 | return $this; |
| 300 | 300 | } |
| 301 | 301 | /** |
| 302 | - * Set automatic filename |
|
| 303 | - * |
|
| 304 | - * @since 1.0 |
|
| 305 | - * @version 1.5 |
|
| 306 | - * @param string $extension |
|
| 307 | - * @return object |
|
| 308 | - * @method boolean setAutoFilename |
|
| 309 | - */ |
|
| 302 | + * Set automatic filename |
|
| 303 | + * |
|
| 304 | + * @since 1.0 |
|
| 305 | + * @version 1.5 |
|
| 306 | + * @param string $extension |
|
| 307 | + * @return object |
|
| 308 | + * @method boolean setAutoFilename |
|
| 309 | + */ |
|
| 310 | 310 | public function setAutoFilename() |
| 311 | 311 | { |
| 312 | 312 | $this->filename = sha1(mt_rand(1, 9999).uniqid()); |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | return $this; |
| 315 | 315 | } |
| 316 | 316 | /** |
| 317 | - * Set file size limit |
|
| 318 | - * |
|
| 319 | - * @since 1.0 |
|
| 320 | - * @version 1.0 |
|
| 321 | - * @param double $file_size |
|
| 322 | - * @return object |
|
| 323 | - * @method boolean setMaxFileSize |
|
| 324 | - */ |
|
| 317 | + * Set file size limit |
|
| 318 | + * |
|
| 319 | + * @since 1.0 |
|
| 320 | + * @version 1.0 |
|
| 321 | + * @param double $file_size |
|
| 322 | + * @return object |
|
| 323 | + * @method boolean setMaxFileSize |
|
| 324 | + */ |
|
| 325 | 325 | public function setMaxFileSize($file_size) |
| 326 | 326 | { |
| 327 | 327 | $file_size = $this->sizeInBytes($file_size); |
@@ -337,14 +337,14 @@ discard block |
||
| 337 | 337 | return $this; |
| 338 | 338 | } |
| 339 | 339 | /** |
| 340 | - * Set array mime types |
|
| 341 | - * |
|
| 342 | - * @since 1.0 |
|
| 343 | - * @version 1.0 |
|
| 344 | - * @param array $mimes |
|
| 345 | - * @return object |
|
| 346 | - * @method boolean setAllowedMimeTypes |
|
| 347 | - */ |
|
| 340 | + * Set array mime types |
|
| 341 | + * |
|
| 342 | + * @since 1.0 |
|
| 343 | + * @version 1.0 |
|
| 344 | + * @param array $mimes |
|
| 345 | + * @return object |
|
| 346 | + * @method boolean setAllowedMimeTypes |
|
| 347 | + */ |
|
| 348 | 348 | public function setAllowedMimeTypes(array $mimes) |
| 349 | 349 | { |
| 350 | 350 | if (count($mimes) > 0) { |
@@ -353,14 +353,14 @@ discard block |
||
| 353 | 353 | return $this; |
| 354 | 354 | } |
| 355 | 355 | /** |
| 356 | - * Set input callback |
|
| 357 | - * |
|
| 358 | - * @since 1.0 |
|
| 359 | - * @version 1.0 |
|
| 360 | - * @param mixed $callback |
|
| 361 | - * @return object |
|
| 362 | - * @method boolean setCallbackInput |
|
| 363 | - */ |
|
| 356 | + * Set input callback |
|
| 357 | + * |
|
| 358 | + * @since 1.0 |
|
| 359 | + * @version 1.0 |
|
| 360 | + * @param mixed $callback |
|
| 361 | + * @return object |
|
| 362 | + * @method boolean setCallbackInput |
|
| 363 | + */ |
|
| 364 | 364 | public function setCallbackInput($callback) |
| 365 | 365 | { |
| 366 | 366 | if (is_callable($callback, false)) { |
@@ -369,14 +369,14 @@ discard block |
||
| 369 | 369 | return $this; |
| 370 | 370 | } |
| 371 | 371 | /** |
| 372 | - * Set output callback |
|
| 373 | - * |
|
| 374 | - * @since 1.0 |
|
| 375 | - * @version 1.0 |
|
| 376 | - * @param mixed $callback |
|
| 377 | - * @return object |
|
| 378 | - * @method boolean setCallbackOutput |
|
| 379 | - */ |
|
| 372 | + * Set output callback |
|
| 373 | + * |
|
| 374 | + * @since 1.0 |
|
| 375 | + * @version 1.0 |
|
| 376 | + * @param mixed $callback |
|
| 377 | + * @return object |
|
| 378 | + * @method boolean setCallbackOutput |
|
| 379 | + */ |
|
| 380 | 380 | public function setCallbackOutput($callback) |
| 381 | 381 | { |
| 382 | 382 | if (is_callable($callback, false)) { |
@@ -385,14 +385,14 @@ discard block |
||
| 385 | 385 | return $this; |
| 386 | 386 | } |
| 387 | 387 | /** |
| 388 | - * Append a mime type to allowed mime types |
|
| 389 | - * |
|
| 390 | - * @since 1.0 |
|
| 391 | - * @version 1.0.1 |
|
| 392 | - * @param string $mime |
|
| 393 | - * @return object |
|
| 394 | - * @method boolean setAllowMimeType |
|
| 395 | - */ |
|
| 388 | + * Append a mime type to allowed mime types |
|
| 389 | + * |
|
| 390 | + * @since 1.0 |
|
| 391 | + * @version 1.0.1 |
|
| 392 | + * @param string $mime |
|
| 393 | + * @return object |
|
| 394 | + * @method boolean setAllowMimeType |
|
| 395 | + */ |
|
| 396 | 396 | public function setAllowMimeType($mime) |
| 397 | 397 | { |
| 398 | 398 | if (!empty($mime) && is_string($mime)) { |
@@ -402,13 +402,13 @@ discard block |
||
| 402 | 402 | return $this; |
| 403 | 403 | } |
| 404 | 404 | /** |
| 405 | - * Set allowed mime types from mime helping |
|
| 406 | - * |
|
| 407 | - * @since 1.0.1 |
|
| 408 | - * @version 1.0.1 |
|
| 409 | - * @return object |
|
| 410 | - * @method boolean setMimeHelping |
|
| 411 | - */ |
|
| 405 | + * Set allowed mime types from mime helping |
|
| 406 | + * |
|
| 407 | + * @since 1.0.1 |
|
| 408 | + * @version 1.0.1 |
|
| 409 | + * @return object |
|
| 410 | + * @method boolean setMimeHelping |
|
| 411 | + */ |
|
| 412 | 412 | public function setMimeHelping($name) |
| 413 | 413 | { |
| 414 | 414 | if (!empty($name) && is_string($name)) { |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | return $this; |
| 420 | 420 | } |
| 421 | 421 | /** |
| 422 | - * Set function to upload file |
|
| 423 | - * Examples: |
|
| 424 | - * 1.- FileUpload::setUploadFunction("move_uploaded_file"); |
|
| 425 | - * 2.- FileUpload::setUploadFunction("copy"); |
|
| 426 | - * |
|
| 427 | - * @since 1.0 |
|
| 428 | - * @version 1.0 |
|
| 429 | - * @param string $function |
|
| 430 | - * @return object |
|
| 431 | - * @method boolean setUploadFunction |
|
| 432 | - */ |
|
| 422 | + * Set function to upload file |
|
| 423 | + * Examples: |
|
| 424 | + * 1.- FileUpload::setUploadFunction("move_uploaded_file"); |
|
| 425 | + * 2.- FileUpload::setUploadFunction("copy"); |
|
| 426 | + * |
|
| 427 | + * @since 1.0 |
|
| 428 | + * @version 1.0 |
|
| 429 | + * @param string $function |
|
| 430 | + * @return object |
|
| 431 | + * @method boolean setUploadFunction |
|
| 432 | + */ |
|
| 433 | 433 | public function setUploadFunction($function) |
| 434 | 434 | { |
| 435 | 435 | if (!empty($function) && (is_array($function) || is_string($function) )) { |
@@ -440,13 +440,13 @@ discard block |
||
| 440 | 440 | return $this; |
| 441 | 441 | } |
| 442 | 442 | /** |
| 443 | - * Clear allowed mime types cache |
|
| 444 | - * |
|
| 445 | - * @since 1.0 |
|
| 446 | - * @version 1.0 |
|
| 447 | - * @return object |
|
| 448 | - * @method boolean clearAllowedMimeTypes |
|
| 449 | - */ |
|
| 443 | + * Clear allowed mime types cache |
|
| 444 | + * |
|
| 445 | + * @since 1.0 |
|
| 446 | + * @version 1.0 |
|
| 447 | + * @return object |
|
| 448 | + * @method boolean clearAllowedMimeTypes |
|
| 449 | + */ |
|
| 450 | 450 | public function clearAllowedMimeTypes() |
| 451 | 451 | { |
| 452 | 452 | $this->allowed_mime_types = array(); |
@@ -454,15 +454,15 @@ discard block |
||
| 454 | 454 | return $this; |
| 455 | 455 | } |
| 456 | 456 | /** |
| 457 | - * Set destination output |
|
| 458 | - * |
|
| 459 | - * @since 1.0 |
|
| 460 | - * @version 1.0 |
|
| 461 | - * @param string $destination_directory Destination path |
|
| 462 | - * @param boolean $create_if_not_exist |
|
| 463 | - * @return object |
|
| 464 | - * @method boolean setDestinationDirectory |
|
| 465 | - */ |
|
| 457 | + * Set destination output |
|
| 458 | + * |
|
| 459 | + * @since 1.0 |
|
| 460 | + * @version 1.0 |
|
| 461 | + * @param string $destination_directory Destination path |
|
| 462 | + * @param boolean $create_if_not_exist |
|
| 463 | + * @return object |
|
| 464 | + * @method boolean setDestinationDirectory |
|
| 465 | + */ |
|
| 466 | 466 | public function setDestinationDirectory($destination_directory, $create_if_not_exist = false) { |
| 467 | 467 | $destination_directory = realpath($destination_directory); |
| 468 | 468 | if (substr($destination_directory, -1) != DIRECTORY_SEPARATOR) { |
@@ -486,14 +486,14 @@ discard block |
||
| 486 | 486 | return $this; |
| 487 | 487 | } |
| 488 | 488 | /** |
| 489 | - * Check file exists |
|
| 490 | - * |
|
| 491 | - * @since 1.0 |
|
| 492 | - * @version 1.0.1 |
|
| 493 | - * @param string $file_destination |
|
| 494 | - * @return boolean |
|
| 495 | - * @method boolean fileExists |
|
| 496 | - */ |
|
| 489 | + * Check file exists |
|
| 490 | + * |
|
| 491 | + * @since 1.0 |
|
| 492 | + * @version 1.0.1 |
|
| 493 | + * @param string $file_destination |
|
| 494 | + * @return boolean |
|
| 495 | + * @method boolean fileExists |
|
| 496 | + */ |
|
| 497 | 497 | public function fileExists($file_destination) |
| 498 | 498 | { |
| 499 | 499 | if ($this->isFilename($file_destination)) { |
@@ -502,14 +502,14 @@ discard block |
||
| 502 | 502 | return false; |
| 503 | 503 | } |
| 504 | 504 | /** |
| 505 | - * Check dir exists |
|
| 506 | - * |
|
| 507 | - * @since 1.0 |
|
| 508 | - * @version 1.0.1 |
|
| 509 | - * @param string $path |
|
| 510 | - * @return boolean |
|
| 511 | - * @method boolean dirExists |
|
| 512 | - */ |
|
| 505 | + * Check dir exists |
|
| 506 | + * |
|
| 507 | + * @since 1.0 |
|
| 508 | + * @version 1.0.1 |
|
| 509 | + * @param string $path |
|
| 510 | + * @return boolean |
|
| 511 | + * @method boolean dirExists |
|
| 512 | + */ |
|
| 513 | 513 | public function dirExists($path) |
| 514 | 514 | { |
| 515 | 515 | if ($this->isDirpath($path)) { |
@@ -518,29 +518,29 @@ discard block |
||
| 518 | 518 | return false; |
| 519 | 519 | } |
| 520 | 520 | /** |
| 521 | - * Check valid filename |
|
| 522 | - * |
|
| 523 | - * @since 1.0 |
|
| 524 | - * @version 1.0.1 |
|
| 525 | - * @param string $filename |
|
| 526 | - * @return boolean |
|
| 527 | - * @method boolean isFilename |
|
| 528 | - */ |
|
| 521 | + * Check valid filename |
|
| 522 | + * |
|
| 523 | + * @since 1.0 |
|
| 524 | + * @version 1.0.1 |
|
| 525 | + * @param string $filename |
|
| 526 | + * @return boolean |
|
| 527 | + * @method boolean isFilename |
|
| 528 | + */ |
|
| 529 | 529 | public function isFilename($filename) |
| 530 | 530 | { |
| 531 | 531 | $filename = basename($filename); |
| 532 | 532 | return (!empty($filename) && (is_string( $filename) || is_numeric($filename))); |
| 533 | 533 | } |
| 534 | 534 | /** |
| 535 | - * Validate mime type with allowed mime types, |
|
| 536 | - * but if allowed mime types is empty, this method return true |
|
| 537 | - * |
|
| 538 | - * @since 1.0 |
|
| 539 | - * @version 1.0 |
|
| 540 | - * @param string $mime |
|
| 541 | - * @return boolean |
|
| 542 | - * @method boolean checkMimeType |
|
| 543 | - */ |
|
| 535 | + * Validate mime type with allowed mime types, |
|
| 536 | + * but if allowed mime types is empty, this method return true |
|
| 537 | + * |
|
| 538 | + * @since 1.0 |
|
| 539 | + * @version 1.0 |
|
| 540 | + * @param string $mime |
|
| 541 | + * @return boolean |
|
| 542 | + * @method boolean checkMimeType |
|
| 543 | + */ |
|
| 544 | 544 | public function checkMimeType($mime) |
| 545 | 545 | { |
| 546 | 546 | if (count($this->allowed_mime_types) == 0) { |
@@ -549,26 +549,26 @@ discard block |
||
| 549 | 549 | return in_array(strtolower($mime), $this->allowed_mime_types); |
| 550 | 550 | } |
| 551 | 551 | /** |
| 552 | - * Retrive status of upload |
|
| 553 | - * |
|
| 554 | - * @since 1.0 |
|
| 555 | - * @version 1.0 |
|
| 556 | - * @return boolean |
|
| 557 | - * @method boolean getStatus |
|
| 558 | - */ |
|
| 552 | + * Retrive status of upload |
|
| 553 | + * |
|
| 554 | + * @since 1.0 |
|
| 555 | + * @version 1.0 |
|
| 556 | + * @return boolean |
|
| 557 | + * @method boolean getStatus |
|
| 558 | + */ |
|
| 559 | 559 | public function getStatus() |
| 560 | 560 | { |
| 561 | 561 | return $this->file['status']; |
| 562 | 562 | } |
| 563 | 563 | /** |
| 564 | - * Check valid path |
|
| 565 | - * |
|
| 566 | - * @since 1.0 |
|
| 567 | - * @version 1.0.1 |
|
| 568 | - * @param string $filename |
|
| 569 | - * @return boolean |
|
| 570 | - * @method boolean isDirpath |
|
| 571 | - */ |
|
| 564 | + * Check valid path |
|
| 565 | + * |
|
| 566 | + * @since 1.0 |
|
| 567 | + * @version 1.0.1 |
|
| 568 | + * @param string $filename |
|
| 569 | + * @return boolean |
|
| 570 | + * @method boolean isDirpath |
|
| 571 | + */ |
|
| 572 | 572 | public function isDirpath($path) |
| 573 | 573 | { |
| 574 | 574 | if (!empty( $path) && (is_string( $path) || is_numeric($path) )) { |
@@ -581,26 +581,26 @@ discard block |
||
| 581 | 581 | return false; |
| 582 | 582 | } |
| 583 | 583 | /** |
| 584 | - * Allow overwriting files |
|
| 585 | - * |
|
| 586 | - * @since 1.0 |
|
| 587 | - * @version 1.0 |
|
| 588 | - * @return object |
|
| 589 | - * @method boolean allowOverwriting |
|
| 590 | - */ |
|
| 584 | + * Allow overwriting files |
|
| 585 | + * |
|
| 586 | + * @since 1.0 |
|
| 587 | + * @version 1.0 |
|
| 588 | + * @return object |
|
| 589 | + * @method boolean allowOverwriting |
|
| 590 | + */ |
|
| 591 | 591 | public function allowOverwriting() |
| 592 | 592 | { |
| 593 | 593 | $this->overwrite_file = true; |
| 594 | 594 | return $this; |
| 595 | 595 | } |
| 596 | 596 | /** |
| 597 | - * File info |
|
| 598 | - * |
|
| 599 | - * @since 1.0 |
|
| 600 | - * @version 1.0 |
|
| 601 | - * @return object |
|
| 602 | - * @method object getInfo |
|
| 603 | - */ |
|
| 597 | + * File info |
|
| 598 | + * |
|
| 599 | + * @since 1.0 |
|
| 600 | + * @version 1.0 |
|
| 601 | + * @return object |
|
| 602 | + * @method object getInfo |
|
| 603 | + */ |
|
| 604 | 604 | public function getInfo() |
| 605 | 605 | { |
| 606 | 606 | return (object)$this->file; |
@@ -618,13 +618,13 @@ discard block |
||
| 618 | 618 | |
| 619 | 619 | |
| 620 | 620 | /** |
| 621 | - * Upload file |
|
| 622 | - * |
|
| 623 | - * @since 1.0 |
|
| 624 | - * @version 1.0.1 |
|
| 625 | - * @return boolean |
|
| 626 | - * @method boolean save |
|
| 627 | - */ |
|
| 621 | + * Upload file |
|
| 622 | + * |
|
| 623 | + * @since 1.0 |
|
| 624 | + * @version 1.0.1 |
|
| 625 | + * @return boolean |
|
| 626 | + * @method boolean save |
|
| 627 | + */ |
|
| 628 | 628 | public function save(){ |
| 629 | 629 | if (count($this->file_array) > 0 && array_key_exists($this->input, $this->file_array)) { |
| 630 | 630 | // set original filename if not have a new name |
@@ -681,15 +681,15 @@ discard block |
||
| 681 | 681 | |
| 682 | 682 | |
| 683 | 683 | /** |
| 684 | - * File size for humans. |
|
| 685 | - * |
|
| 686 | - * @since 1.0 |
|
| 687 | - * @version 1.0 |
|
| 688 | - * @param integer $bytes |
|
| 689 | - * @param integer $precision |
|
| 690 | - * @return string |
|
| 691 | - * @method string sizeFormat |
|
| 692 | - */ |
|
| 684 | + * File size for humans. |
|
| 685 | + * |
|
| 686 | + * @since 1.0 |
|
| 687 | + * @version 1.0 |
|
| 688 | + * @param integer $bytes |
|
| 689 | + * @param integer $precision |
|
| 690 | + * @return string |
|
| 691 | + * @method string sizeFormat |
|
| 692 | + */ |
|
| 693 | 693 | public function sizeFormat($size, $precision = 2) |
| 694 | 694 | { |
| 695 | 695 | if($size > 0){ |
@@ -702,14 +702,14 @@ discard block |
||
| 702 | 702 | |
| 703 | 703 | |
| 704 | 704 | /** |
| 705 | - * Convert human file size to bytes |
|
| 706 | - * |
|
| 707 | - * @since 1.0 |
|
| 708 | - * @version 1.0.1 |
|
| 709 | - * @param integer|double $size |
|
| 710 | - * @return integer|double |
|
| 711 | - * @method string sizeInBytes |
|
| 712 | - */ |
|
| 705 | + * Convert human file size to bytes |
|
| 706 | + * |
|
| 707 | + * @since 1.0 |
|
| 708 | + * @version 1.0.1 |
|
| 709 | + * @param integer|double $size |
|
| 710 | + * @return integer|double |
|
| 711 | + * @method string sizeInBytes |
|
| 712 | + */ |
|
| 713 | 713 | public function sizeInBytes($size) |
| 714 | 714 | { |
| 715 | 715 | $unit = 'B'; |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | return true; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - //check for php upload error |
|
| 764 | + //check for php upload error |
|
| 765 | 765 | if(is_numeric($this->file['error']) && $this->file['error'] > 0){ |
| 766 | 766 | $this->setError($this->getPhpUploadErrorMessageByCode($this->file['error'])); |
| 767 | 767 | return true; |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | return true; |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - // Check file size |
|
| 776 | + // Check file size |
|
| 777 | 777 | if ($this->max_file_size > 0 && $this->max_file_size < $this->file['size']) { |
| 778 | 778 | $this->setError(sprintf($this->error_messages['max_file_size'], $this->sizeFormat($this->max_file_size))); |
| 779 | 779 | return true; |
@@ -1,81 +1,81 @@ |
||
| 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 constants.php |
|
| 29 | - * |
|
| 30 | - * This file contains the declaration of most of the constants used in the system, |
|
| 31 | - * for example: the version, the name of the framework, etc. |
|
| 32 | - * |
|
| 33 | - * @package core |
|
| 34 | - * @author Tony NGUEREZA |
|
| 35 | - * @copyright Copyright (c) 2017 |
|
| 36 | - * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 37 | - * @link http://www.iacademy.cf |
|
| 38 | - * @version 1.0.0 |
|
| 39 | - * @filesource |
|
| 40 | - */ |
|
| 27 | + /** |
|
| 28 | + * @file constants.php |
|
| 29 | + * |
|
| 30 | + * This file contains the declaration of most of the constants used in the system, |
|
| 31 | + * for example: the version, the name of the framework, etc. |
|
| 32 | + * |
|
| 33 | + * @package core |
|
| 34 | + * @author Tony NGUEREZA |
|
| 35 | + * @copyright Copyright (c) 2017 |
|
| 36 | + * @license https://opensource.org/licenses/gpl-3.0.html GNU GPL License (GPL) |
|
| 37 | + * @link http://www.iacademy.cf |
|
| 38 | + * @version 1.0.0 |
|
| 39 | + * @filesource |
|
| 40 | + */ |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The framework name |
|
| 44 | - */ |
|
| 45 | - define('TNH_NAME', 'TNH Framework'); |
|
| 42 | + /** |
|
| 43 | + * The framework name |
|
| 44 | + */ |
|
| 45 | + define('TNH_NAME', 'TNH Framework'); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * The version of the framework in X.Y.Z format (Major, minor and bugs). |
|
| 49 | - * If there is the presence of the word "dev", it means that |
|
| 50 | - * it is a version under development. |
|
| 51 | - */ |
|
| 52 | - define('TNH_VERSION', '1.0.0-dev'); |
|
| 47 | + /** |
|
| 48 | + * The version of the framework in X.Y.Z format (Major, minor and bugs). |
|
| 49 | + * If there is the presence of the word "dev", it means that |
|
| 50 | + * it is a version under development. |
|
| 51 | + */ |
|
| 52 | + define('TNH_VERSION', '1.0.0-dev'); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * The date of publication or release of the framework |
|
| 56 | - */ |
|
| 57 | - define('TNH_RELEASE_DATE', '2017/02/05'); |
|
| 54 | + /** |
|
| 55 | + * The date of publication or release of the framework |
|
| 56 | + */ |
|
| 57 | + define('TNH_RELEASE_DATE', '2017/02/05'); |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * The author of the framework, the person who developed the framework. |
|
| 61 | - */ |
|
| 62 | - define('TNH_AUTHOR', 'Tony NGUEREZA'); |
|
| 59 | + /** |
|
| 60 | + * The author of the framework, the person who developed the framework. |
|
| 61 | + */ |
|
| 62 | + define('TNH_AUTHOR', 'Tony NGUEREZA'); |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Email address of the author of the framework. |
|
| 66 | - */ |
|
| 67 | - define('TNH_AUTHOR_EMAIL', '[email protected]'); |
|
| 64 | + /** |
|
| 65 | + * Email address of the author of the framework. |
|
| 66 | + */ |
|
| 67 | + define('TNH_AUTHOR_EMAIL', '[email protected]'); |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * The minimum PHP version required to use the framework. |
|
| 71 | - * If the version of PHP installed is lower, then the application will not work. |
|
| 72 | - * Note: we use the PHP version_compare function to compare the required version with |
|
| 73 | - * the version installed on your system. |
|
| 74 | - */ |
|
| 75 | - define('TNH_REQUIRED_PHP_MIN_VERSION', '5.4'); |
|
| 69 | + /** |
|
| 70 | + * The minimum PHP version required to use the framework. |
|
| 71 | + * If the version of PHP installed is lower, then the application will not work. |
|
| 72 | + * Note: we use the PHP version_compare function to compare the required version with |
|
| 73 | + * the version installed on your system. |
|
| 74 | + */ |
|
| 75 | + define('TNH_REQUIRED_PHP_MIN_VERSION', '5.4'); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * The maximum version of PHP required to use the framework. |
|
| 79 | - * If the version of PHP installed is higher than the required one, then the application will not work. |
|
| 80 | - */ |
|
| 81 | - define('TNH_REQUIRED_PHP_MAX_VERSION', '7.1'); |
|
| 82 | 77 | \ No newline at end of file |
| 78 | + /** |
|
| 79 | + * The maximum version of PHP required to use the framework. |
|
| 80 | + * If the version of PHP installed is higher than the required one, then the application will not work. |
|
| 81 | + */ |
|
| 82 | + define('TNH_REQUIRED_PHP_MAX_VERSION', '7.1'); |
|
| 83 | 83 | \ No newline at end of file |