@@ -22,7 +22,7 @@ |
||
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 | class Log{ |
28 | 28 |
@@ -137,8 +137,7 @@ discard block |
||
137 | 137 | if(! in_array(strtolower($this->logger), $configLoggerName)){ |
138 | 138 | return; |
139 | 139 | } |
140 | - } |
|
141 | - else if(strtolower($this->logger) !== strtolower($configLoggerName)){ |
|
140 | + } else if(strtolower($this->logger) !== strtolower($configLoggerName)){ |
|
142 | 141 | return; |
143 | 142 | } |
144 | 143 | } |
@@ -218,20 +217,15 @@ discard block |
||
218 | 217 | //the default value is NONE, so means no need test for NONE |
219 | 218 | if($level == 'fatal'){ |
220 | 219 | $value = self::FATAL; |
221 | - } |
|
222 | - else if($level == 'error'){ |
|
220 | + } else if($level == 'error'){ |
|
223 | 221 | $value = self::ERROR; |
224 | - } |
|
225 | - else if($level == 'warning' || $level == 'warn'){ |
|
222 | + } else if($level == 'warning' || $level == 'warn'){ |
|
226 | 223 | $value = self::WARNING; |
227 | - } |
|
228 | - else if($level == 'info'){ |
|
224 | + } else if($level == 'info'){ |
|
229 | 225 | $value = self::INFO; |
230 | - } |
|
231 | - else if($level == 'debug'){ |
|
226 | + } else if($level == 'debug'){ |
|
232 | 227 | $value = self::DEBUG; |
233 | - } |
|
234 | - else if($level == 'all'){ |
|
228 | + } else if($level == 'all'){ |
|
235 | 229 | $value = self::ALL; |
236 | 230 | } |
237 | 231 | return $value; |
@@ -248,17 +242,13 @@ discard block |
||
248 | 242 | //the default value is NONE, so means no need test for NONE |
249 | 243 | if($level == self::FATAL){ |
250 | 244 | $value = 'FATAL'; |
251 | - } |
|
252 | - else if($level == self::ERROR){ |
|
245 | + } else if($level == self::ERROR){ |
|
253 | 246 | $value = 'ERROR'; |
254 | - } |
|
255 | - else if($level == self::WARNING){ |
|
247 | + } else if($level == self::WARNING){ |
|
256 | 248 | $value = 'WARNING'; |
257 | - } |
|
258 | - else if($level == self::INFO){ |
|
249 | + } else if($level == self::INFO){ |
|
259 | 250 | $value = 'INFO'; |
260 | - } |
|
261 | - else if($level == self::DEBUG){ |
|
251 | + } else if($level == self::DEBUG){ |
|
262 | 252 | $value = 'DEBUG'; |
263 | 253 | } |
264 | 254 | //no need for ALL |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Log{ |
|
27 | + class Log { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The defined constante for Log level |
@@ -52,14 +52,14 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * Create new Log instance |
54 | 54 | */ |
55 | - public function __construct(){ |
|
55 | + public function __construct() { |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Set the logger to identify each message in the log |
60 | 60 | * @param string $logger the logger name |
61 | 61 | */ |
62 | - public function setLogger($logger){ |
|
62 | + public function setLogger($logger) { |
|
63 | 63 | $this->logger = $logger; |
64 | 64 | } |
65 | 65 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @see Log::writeLog for more detail |
69 | 69 | * @param string $message the log message to save |
70 | 70 | */ |
71 | - public function fatal($message){ |
|
71 | + public function fatal($message) { |
|
72 | 72 | $this->writeLog($message, self::FATAL); |
73 | 73 | } |
74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @see Log::writeLog for more detail |
78 | 78 | * @param string $message the log message to save |
79 | 79 | */ |
80 | - public function error($message){ |
|
80 | + public function error($message) { |
|
81 | 81 | $this->writeLog($message, self::ERROR); |
82 | 82 | } |
83 | 83 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @see Log::writeLog for more detail |
87 | 87 | * @param string $message the log message to save |
88 | 88 | */ |
89 | - public function warning($message){ |
|
89 | + public function warning($message) { |
|
90 | 90 | $this->writeLog($message, self::WARNING); |
91 | 91 | } |
92 | 92 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @see Log::writeLog for more detail |
96 | 96 | * @param string $message the log message to save |
97 | 97 | */ |
98 | - public function info($message){ |
|
98 | + public function info($message) { |
|
99 | 99 | $this->writeLog($message, self::INFO); |
100 | 100 | } |
101 | 101 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @see Log::writeLog for more detail |
105 | 105 | * @param string $message the log message to save |
106 | 106 | */ |
107 | - public function debug($message){ |
|
107 | + public function debug($message) { |
|
108 | 108 | $this->writeLog($message, self::DEBUG); |
109 | 109 | } |
110 | 110 | |
@@ -115,59 +115,59 @@ discard block |
||
115 | 115 | * @param integer|string $level the log level in integer or string format, if is string will convert into integer |
116 | 116 | * to allow check the log level threshold. |
117 | 117 | */ |
118 | - public function writeLog($message, $level = self::INFO){ |
|
118 | + public function writeLog($message, $level = self::INFO) { |
|
119 | 119 | $configLogLevel = get_config('log_level'); |
120 | - if(! $configLogLevel){ |
|
120 | + if (!$configLogLevel) { |
|
121 | 121 | //so means no need log just stop here |
122 | 122 | return; |
123 | 123 | } |
124 | 124 | //check config log level |
125 | - if(! self::isValidConfigLevel($configLogLevel)){ |
|
125 | + if (!self::isValidConfigLevel($configLogLevel)) { |
|
126 | 126 | //NOTE: here need put the show_error() "logging" to false to prevent loop |
127 | 127 | show_error('Invalid config log level [' . $configLogLevel . '], the value must be one of the following: ' . implode(', ', array_map('strtoupper', self::$validConfigLevel)), $title = 'Log Config Error', $logging = false); |
128 | 128 | } |
129 | 129 | |
130 | 130 | //check if config log_logger_name is set |
131 | - if($this->logger){ |
|
131 | + if ($this->logger) { |
|
132 | 132 | $configLoggerName = get_config('log_logger_name', ''); |
133 | - if($configLoggerName){ |
|
134 | - if (is_array($configLoggerName)){ |
|
133 | + if ($configLoggerName) { |
|
134 | + if (is_array($configLoggerName)) { |
|
135 | 135 | //for best comparaison put all string to lowercase |
136 | 136 | $configLoggerName = array_map('strtolower', $configLoggerName); |
137 | - if(! in_array(strtolower($this->logger), $configLoggerName)){ |
|
137 | + if (!in_array(strtolower($this->logger), $configLoggerName)) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | } |
141 | - else if(strtolower($this->logger) !== strtolower($configLoggerName)){ |
|
141 | + else if (strtolower($this->logger) !== strtolower($configLoggerName)) { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | 147 | //if $level is not an integer |
148 | - if(! is_numeric($level)){ |
|
148 | + if (!is_numeric($level)) { |
|
149 | 149 | $level = self::getLevelValue($level); |
150 | 150 | } |
151 | 151 | |
152 | 152 | //check if can logging regarding the log level config |
153 | 153 | $configLevel = self::getLevelValue($configLogLevel); |
154 | - if($configLevel > $level){ |
|
154 | + if ($configLevel > $level) { |
|
155 | 155 | //can't log |
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | 159 | $logSavePath = get_config('log_save_path'); |
160 | - if(! $logSavePath){ |
|
160 | + if (!$logSavePath) { |
|
161 | 161 | $logSavePath = LOGS_PATH; |
162 | 162 | } |
163 | 163 | |
164 | - if(! is_dir($logSavePath) || !is_writable($logSavePath)){ |
|
164 | + if (!is_dir($logSavePath) || !is_writable($logSavePath)) { |
|
165 | 165 | //NOTE: here need put the show_error() "logging" to false to prevent loop |
166 | 166 | show_error('Error : the log dir does not exists or is not writable', $title = 'Log directory error', $logging = false); |
167 | 167 | } |
168 | 168 | |
169 | 169 | $path = $logSavePath . 'logs-' . date('Y-m-d') . '.log'; |
170 | - if(! file_exists($path)){ |
|
170 | + if (!file_exists($path)) { |
|
171 | 171 | touch($path); |
172 | 172 | } |
173 | 173 | //may be at this time helper user_agent not yet included |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | $str = $logDate . ' [' . str_pad($levelName, 7 /*warning len*/) . '] ' . ' [' . str_pad($ip, 15) . '] ' . $this->logger . ' : ' . $message . ' ' . '[' . $fileInfo['file'] . '::' . $fileInfo['line'] . ']' . "\n"; |
191 | 191 | $fp = fopen($path, 'a+'); |
192 | - if(is_resource($fp)){ |
|
192 | + if (is_resource($fp)) { |
|
193 | 193 | flock($fp, LOCK_EX); // exclusive lock, will get released when the file is closed |
194 | 194 | fwrite($fp, $str); |
195 | 195 | fclose($fp); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @return boolean true if the given log level is valid, false if not |
205 | 205 | */ |
206 | - private static function isValidConfigLevel($level){ |
|
206 | + private static function isValidConfigLevel($level) { |
|
207 | 207 | $level = strtolower($level); |
208 | 208 | return in_array($level, self::$validConfigLevel); |
209 | 209 | } |
@@ -213,27 +213,27 @@ discard block |
||
213 | 213 | * @param string $level the log level in string format |
214 | 214 | * @return int the log level in integer format using the predefinied constants |
215 | 215 | */ |
216 | - private static function getLevelValue($level){ |
|
216 | + private static function getLevelValue($level) { |
|
217 | 217 | $level = strtolower($level); |
218 | 218 | $value = self::NONE; |
219 | 219 | |
220 | 220 | //the default value is NONE, so means no need test for NONE |
221 | - if($level == 'fatal'){ |
|
221 | + if ($level == 'fatal') { |
|
222 | 222 | $value = self::FATAL; |
223 | 223 | } |
224 | - else if($level == 'error'){ |
|
224 | + else if ($level == 'error') { |
|
225 | 225 | $value = self::ERROR; |
226 | 226 | } |
227 | - else if($level == 'warning' || $level == 'warn'){ |
|
227 | + else if ($level == 'warning' || $level == 'warn') { |
|
228 | 228 | $value = self::WARNING; |
229 | 229 | } |
230 | - else if($level == 'info'){ |
|
230 | + else if ($level == 'info') { |
|
231 | 231 | $value = self::INFO; |
232 | 232 | } |
233 | - else if($level == 'debug'){ |
|
233 | + else if ($level == 'debug') { |
|
234 | 234 | $value = self::DEBUG; |
235 | 235 | } |
236 | - else if($level == 'all'){ |
|
236 | + else if ($level == 'all') { |
|
237 | 237 | $value = self::ALL; |
238 | 238 | } |
239 | 239 | return $value; |
@@ -244,23 +244,23 @@ discard block |
||
244 | 244 | * @param integer $level the log level in integer format |
245 | 245 | * @return string the log level in string format |
246 | 246 | */ |
247 | - private static function getLevelName($level){ |
|
247 | + private static function getLevelName($level) { |
|
248 | 248 | $value = ''; |
249 | 249 | |
250 | 250 | //the default value is NONE, so means no need test for NONE |
251 | - if($level == self::FATAL){ |
|
251 | + if ($level == self::FATAL) { |
|
252 | 252 | $value = 'FATAL'; |
253 | 253 | } |
254 | - else if($level == self::ERROR){ |
|
254 | + else if ($level == self::ERROR) { |
|
255 | 255 | $value = 'ERROR'; |
256 | 256 | } |
257 | - else if($level == self::WARNING){ |
|
257 | + else if ($level == self::WARNING) { |
|
258 | 258 | $value = 'WARNING'; |
259 | 259 | } |
260 | - else if($level == self::INFO){ |
|
260 | + else if ($level == self::INFO) { |
|
261 | 261 | $value = 'INFO'; |
262 | 262 | } |
263 | - else if($level == self::DEBUG){ |
|
263 | + else if ($level == self::DEBUG) { |
|
264 | 264 | $value = 'DEBUG'; |
265 | 265 | } |
266 | 266 | //no need for ALL |
@@ -22,7 +22,7 @@ |
||
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 | * Class for Benchmark |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * Class for Benchmark |
29 | 29 | */ |
30 | - class Benchmark{ |
|
30 | + class Benchmark { |
|
31 | 31 | /** |
32 | 32 | * The markers for excution time |
33 | 33 | * @var array |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * This method is used to mark one point for benchmark (execution time and memory usage) |
45 | 45 | * @param string $name the marker name |
46 | 46 | */ |
47 | - public function mark($name){ |
|
47 | + public function mark($name) { |
|
48 | 48 | //Marker for execution time |
49 | 49 | $this->markersTime[$name] = microtime(true); |
50 | 50 | //Marker for memory usage |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | * @param integer $decimalCount the number of decimal |
59 | 59 | * @return string the total execution time |
60 | 60 | */ |
61 | - public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
62 | - if(! $startMarkerName || !isset($this->markersTime[$startMarkerName])){ |
|
61 | + public function elapsedTime($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) { |
|
62 | + if (!$startMarkerName || !isset($this->markersTime[$startMarkerName])) { |
|
63 | 63 | return 0; |
64 | 64 | } |
65 | 65 | |
66 | - if(! isset($this->markersTime[$endMarkerName])){ |
|
66 | + if (!isset($this->markersTime[$endMarkerName])) { |
|
67 | 67 | $this->markersTime[$endMarkerName] = microtime(true); |
68 | 68 | } |
69 | 69 | return number_format($this->markersTime[$endMarkerName] - $this->markersTime[$startMarkerName], $decimalCount); |
@@ -76,12 +76,12 @@ discard block |
||
76 | 76 | * @param integer $decimalCount the number of decimal |
77 | 77 | * @return string the total memory usage |
78 | 78 | */ |
79 | - public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6){ |
|
80 | - if(! $startMarkerName || !isset($this->markersMemory[$startMarkerName])){ |
|
79 | + public function memoryUsage($startMarkerName = null, $endMarkerName = null, $decimalCount = 6) { |
|
80 | + if (!$startMarkerName || !isset($this->markersMemory[$startMarkerName])) { |
|
81 | 81 | return 0; |
82 | 82 | } |
83 | 83 | |
84 | - if(! isset($this->markersMemory[$endMarkerName])){ |
|
84 | + if (!isset($this->markersMemory[$endMarkerName])) { |
|
85 | 85 | $this->markersMemory[$endMarkerName] = microtime(true); |
86 | 86 | } |
87 | 87 | return number_format($this->markersMemory[$endMarkerName] - $this->markersMemory[$startMarkerName], $decimalCount); |
@@ -22,7 +22,7 @@ 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 | * PDF library to generate PDF document using the library DOMPDF |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * Create PDF library instance |
46 | 46 | */ |
47 | 47 | public function __construct(){ |
48 | - $this->logger =& class_loader('Log', 'classes'); |
|
49 | - $this->logger->setLogger('Library::PDF'); |
|
48 | + $this->logger =& class_loader('Log', 'classes'); |
|
49 | + $this->logger->setLogger('Library::PDF'); |
|
50 | 50 | |
51 | 51 | require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
52 | 52 | $this->dompdf = new Dompdf(); |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Return the instance of Dompdf |
|
80 | - * |
|
81 | - * @return object the dompdf instance |
|
82 | - */ |
|
79 | + * Return the instance of Dompdf |
|
80 | + * |
|
81 | + * @return object the dompdf instance |
|
82 | + */ |
|
83 | 83 | public function getDompdf(){ |
84 | 84 | return $this->dompdf; |
85 | 85 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * PDF library to generate PDF document using the library DOMPDF |
29 | 29 | */ |
30 | - class PDF{ |
|
30 | + class PDF { |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * The dompdf instance |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | /** |
45 | 45 | * Create PDF library instance |
46 | 46 | */ |
47 | - public function __construct(){ |
|
48 | - $this->logger =& class_loader('Log', 'classes'); |
|
47 | + public function __construct() { |
|
48 | + $this->logger = & class_loader('Log', 'classes'); |
|
49 | 49 | $this->logger->setLogger('Library::PDF'); |
50 | 50 | |
51 | - require_once VENDOR_PATH.'dompdf/dompdf_config.inc.php'; |
|
51 | + require_once VENDOR_PATH . 'dompdf/dompdf_config.inc.php'; |
|
52 | 52 | $this->dompdf = new Dompdf(); |
53 | 53 | } |
54 | 54 | |
@@ -62,15 +62,15 @@ discard block |
||
62 | 62 | * @return string|void if $stream is true send PDF document to browser for download, else return the generated PDF |
63 | 63 | * content like to join in Email attachment of for other purpose use. |
64 | 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. ']'); |
|
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 | 67 | $this->dompdf->load_html($html); |
68 | 68 | $this->dompdf->set_paper($paper, $orientation); |
69 | 69 | $this->dompdf->render(); |
70 | - if($stream){ |
|
70 | + if ($stream) { |
|
71 | 71 | $this->dompdf->stream($filename); |
72 | 72 | } |
73 | - else{ |
|
73 | + else { |
|
74 | 74 | return $this->dompdf->output(); |
75 | 75 | } |
76 | 76 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return object the dompdf instance |
82 | 82 | */ |
83 | - public function getDompdf(){ |
|
83 | + public function getDompdf() { |
|
84 | 84 | return $this->dompdf; |
85 | 85 | } |
86 | 86 |
@@ -69,8 +69,7 @@ |
||
69 | 69 | $this->dompdf->render(); |
70 | 70 | if($stream){ |
71 | 71 | $this->dompdf->stream($filename); |
72 | - } |
|
73 | - else{ |
|
72 | + } else{ |
|
74 | 73 | return $this->dompdf->output(); |
75 | 74 | } |
76 | 75 | } |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | protected $_uid; |
75 | 75 | |
76 | 76 | /** |
77 | - * The logger instance |
|
78 | - * @var Log |
|
79 | - */ |
|
77 | + * The logger instance |
|
78 | + * @var Log |
|
79 | + */ |
|
80 | 80 | private $logger; |
81 | 81 | |
82 | 82 | /** |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | public function __construct() |
88 | 88 | { |
89 | 89 | $this->logger =& class_loader('Log', 'classes'); |
90 | - $this->logger->setLogger('Library::Email'); |
|
90 | + $this->logger->setLogger('Library::Email'); |
|
91 | 91 | $this->reset(); |
92 | 92 | } |
93 | 93 | |
@@ -112,13 +112,13 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 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 | - */ |
|
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 | 122 | public function setFrom($email, $name = null) |
123 | 123 | { |
124 | 124 | $this->addMailHeader('From', (string) $email, (string) $name); |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 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 | - */ |
|
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 | 148 | public function setTos(array $emails) |
149 | 149 | { |
150 | 150 | foreach ($emails as $name => $email) { |
@@ -150,8 +150,7 @@ |
||
150 | 150 | foreach ($emails as $name => $email) { |
151 | 151 | if(is_numeric($name)){ |
152 | 152 | $this->setTo($email); |
153 | - } |
|
154 | - else{ |
|
153 | + } else{ |
|
155 | 154 | $this->setTo($email, $name); |
156 | 155 | } |
157 | 156 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function __construct() |
88 | 88 | { |
89 | - $this->logger =& class_loader('Log', 'classes'); |
|
89 | + $this->logger = & class_loader('Log', 'classes'); |
|
90 | 90 | $this->logger->setLogger('Library::Email'); |
91 | 91 | $this->reset(); |
92 | 92 | } |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | public function setTos(array $emails) |
149 | 149 | { |
150 | 150 | foreach ($emails as $name => $email) { |
151 | - if(is_numeric($name)){ |
|
151 | + if (is_numeric($name)) { |
|
152 | 152 | $this->setTo($email); |
153 | 153 | } |
154 | - else{ |
|
154 | + else { |
|
155 | 155 | $this->setTo($email, $name); |
156 | 156 | } |
157 | 157 | } |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | */ |
282 | 282 | public function addAttachment($path, $filename = null, $data = null) |
283 | 283 | { |
284 | - if(! file_exists($path)){ |
|
285 | - show_error('The file [' .$path. '] does not exists.'); |
|
284 | + if (!file_exists($path)) { |
|
285 | + show_error('The file [' . $path . '] does not exists.'); |
|
286 | 286 | } |
287 | 287 | $filename = empty($filename) ? basename($path) : $filename; |
288 | 288 | $filename = $this->encodeUtf8($this->filterOther((string) $filename)); |
@@ -304,13 +304,13 @@ discard block |
||
304 | 304 | */ |
305 | 305 | public function getAttachmentData($path) |
306 | 306 | { |
307 | - if(! file_exists($path)){ |
|
308 | - show_error('The file [' .$path. '] does not exists.'); |
|
307 | + if (!file_exists($path)) { |
|
308 | + show_error('The file [' . $path . '] does not exists.'); |
|
309 | 309 | } |
310 | 310 | $filesize = filesize($path); |
311 | 311 | $handle = fopen($path, "r"); |
312 | 312 | $attachment = null; |
313 | - if(is_resource($handle)){ |
|
313 | + if (is_resource($handle)) { |
|
314 | 314 | $attachment = fread($handle, $filesize); |
315 | 315 | fclose($handle); |
316 | 316 | } |
@@ -22,7 +22,7 @@ |
||
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 | class Cookie{ |
28 | 28 |
@@ -93,8 +93,7 @@ |
||
93 | 93 | $logger->info('Delete cookie item ['.$item.']'); |
94 | 94 | unset($_COOKIE[$item]); |
95 | 95 | return true; |
96 | - } |
|
97 | - else{ |
|
96 | + } else{ |
|
98 | 97 | $logger->warning('Cookie item ['.$item.'] to be deleted does not exists'); |
99 | 98 | return false; |
100 | 99 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Cookie{ |
|
27 | + class Cookie { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The logger instance |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * The signleton of the logger |
37 | 37 | * @return Object the Log instance |
38 | 38 | */ |
39 | - private static function getLogger(){ |
|
40 | - if(self::$logger == null){ |
|
41 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
39 | + private static function getLogger() { |
|
40 | + if (self::$logger == null) { |
|
41 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
42 | 42 | self::$logger[0]->setLogger('Library::Cookie'); |
43 | 43 | } |
44 | 44 | return self::$logger[0]; |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * @param mixed $default the default value to use if can not find the cokkie item in the list |
51 | 51 | * @return mixed the cookie value if exist or the default value |
52 | 52 | */ |
53 | - public static function get($item, $default = null){ |
|
53 | + public static function get($item, $default = null) { |
|
54 | 54 | $logger = self::getLogger(); |
55 | - if(array_key_exists($item, $_COOKIE)){ |
|
55 | + if (array_key_exists($item, $_COOKIE)) { |
|
56 | 56 | return $_COOKIE[$item]; |
57 | 57 | } |
58 | 58 | $logger->warning('Cannot find cookie item [' . $item . '], using the default value [' . $default . ']'); |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | * @param boolean $secure if this cookie will be available on secure connection or not |
70 | 70 | * @param boolean $httponly if this cookie will be available under HTTP protocol. |
71 | 71 | */ |
72 | - public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false){ |
|
73 | - if(headers_sent()){ |
|
72 | + public static function set($name, $value = '', $expire = 0, $path = '/', $domain = '', $secure = false, $httponly = false) { |
|
73 | + if (headers_sent()) { |
|
74 | 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 | 77 | } |
78 | 78 | $timestamp = $expire; |
79 | - if($expire){ |
|
79 | + if ($expire) { |
|
80 | 80 | $timestamp = time() + $expire; |
81 | 81 | } |
82 | 82 | setcookie($name, $value, $timestamp, $path, $domain, $secure, $httponly); |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | * @param string $item the cookie item name to be cleared |
88 | 88 | * @return boolean true if the item exists and is deleted successfully otherwise will return false. |
89 | 89 | */ |
90 | - public static function delete($item){ |
|
90 | + public static function delete($item) { |
|
91 | 91 | $logger = self::getLogger(); |
92 | - if(array_key_exists($item, $_COOKIE)){ |
|
93 | - $logger->info('Delete cookie item ['.$item.']'); |
|
92 | + if (array_key_exists($item, $_COOKIE)) { |
|
93 | + $logger->info('Delete cookie item [' . $item . ']'); |
|
94 | 94 | unset($_COOKIE[$item]); |
95 | 95 | return true; |
96 | 96 | } |
97 | - else{ |
|
98 | - $logger->warning('Cookie item ['.$item.'] to be deleted does not exists'); |
|
97 | + else { |
|
98 | + $logger->warning('Cookie item [' . $item . '] to be deleted does not exists'); |
|
99 | 99 | return false; |
100 | 100 | } |
101 | 101 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param string $item the cookie item name |
106 | 106 | * @return boolean true if the cookie item is set, false or not |
107 | 107 | */ |
108 | - public static function exists($item){ |
|
108 | + public static function exists($item) { |
|
109 | 109 | return array_key_exists($item, $_COOKIE); |
110 | 110 | } |
111 | 111 |
@@ -22,7 +22,7 @@ |
||
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 | * @file Assets.php |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @since 1.0.0 |
39 | 39 | * @filesource |
40 | 40 | */ |
41 | - class Assets{ |
|
41 | + class Assets { |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * The logger instance |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | * The signleton of the logger |
51 | 51 | * @return Object the Log instance |
52 | 52 | */ |
53 | - private static function getLogger(){ |
|
54 | - if(self::$logger == null){ |
|
53 | + private static function getLogger() { |
|
54 | + if (self::$logger == null) { |
|
55 | 55 | //can't assign reference to static variable |
56 | - self::$logger[0] =& class_loader('Log', 'classes'); |
|
56 | + self::$logger[0] = & class_loader('Log', 'classes'); |
|
57 | 57 | self::$logger[0]->setLogger('Library::Assets'); |
58 | 58 | } |
59 | 59 | return self::$logger[0]; |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | * @param $asset the name of the assets file path with the extension. |
73 | 73 | * @return string|null the absolute path of the assets file, if it exists otherwise returns null if the file does not exist. |
74 | 74 | */ |
75 | - public static function path($asset){ |
|
75 | + public static function path($asset) { |
|
76 | 76 | $logger = self::getLogger(); |
77 | 77 | $path = ASSETS_PATH . $asset; |
78 | 78 | |
79 | 79 | $logger->debug('Including the Assets file [' . $path . ']'); |
80 | 80 | //Check if the file exists |
81 | - if(file_exists($path)){ |
|
81 | + if (file_exists($path)) { |
|
82 | 82 | $logger->info('Assets file [' . $path . '] included successfully'); |
83 | 83 | return Url::base_url($path); |
84 | 84 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param $path the name of the css file without the extension. |
99 | 99 | * @return string|null the absolute path of the css file, if it exists otherwise returns null if the file does not exist. |
100 | 100 | */ |
101 | - public static function css($path){ |
|
101 | + public static function css($path) { |
|
102 | 102 | $logger = self::getLogger(); |
103 | 103 | /* |
104 | 104 | * if the file name contains the ".css" extension, replace it with |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | $logger->debug('Including the Assets file [' . $path . '] for CSS'); |
111 | 111 | //Check if the file exists |
112 | - if(file_exists($path)){ |
|
112 | + if (file_exists($path)) { |
|
113 | 113 | $logger->info('Assets file [' . $path . '] for CSS included successfully'); |
114 | 114 | return Url::base_url($path); |
115 | 115 | } |
@@ -129,12 +129,12 @@ discard block |
||
129 | 129 | * @param $path the name of the javascript file without the extension. |
130 | 130 | * @return string|null the absolute path of the javascript file, if it exists otherwise returns null if the file does not exist. |
131 | 131 | */ |
132 | - public static function js($path){ |
|
132 | + public static function js($path) { |
|
133 | 133 | $logger = self::getLogger(); |
134 | 134 | $path = str_ireplace('.js', '', $path); |
135 | 135 | $path = ASSETS_PATH . 'js/' . $path . '.js'; |
136 | 136 | $logger->debug('Including the Assets file [' . $path . '] for javascript'); |
137 | - if(file_exists($path)){ |
|
137 | + if (file_exists($path)) { |
|
138 | 138 | $logger->info('Assets file [' . $path . '] for Javascript included successfully'); |
139 | 139 | return Url::base_url($path); |
140 | 140 | } |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * @param $path the name of the image file with the extension. |
155 | 155 | * @return string|null the absolute path of the image file, if it exists otherwise returns null if the file does not exist. |
156 | 156 | */ |
157 | - public static function img($path){ |
|
157 | + public static function img($path) { |
|
158 | 158 | $logger = self::getLogger(); |
159 | 159 | $path = ASSETS_PATH . 'images/' . $path; |
160 | 160 | $logger->debug('Including the Assets file [' . $path . '] for image'); |
161 | - if(file_exists($path)){ |
|
161 | + if (file_exists($path)) { |
|
162 | 162 | $logger->info('Assets file [' . $path . '] for image included successfully'); |
163 | 163 | return Url::base_url($path); |
164 | 164 | } |
@@ -22,7 +22,7 @@ |
||
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 | class StringHash{ |
28 | 28 |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class StringHash{ |
|
27 | + class StringHash { |
|
28 | 28 | |
29 | 29 | //blowfish |
30 | 30 | private static $algo = '$2a'; |
@@ -22,7 +22,7 @@ |
||
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 | class Html{ |
28 | 28 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Html{ |
|
27 | + class Html { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Generate the html anchor link |
@@ -35,21 +35,21 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return string|void the anchor link generated html if $return is true or display it if not |
37 | 37 | */ |
38 | - public static function a($link = '', $anchor = null, array $attributes = array(), $return = true){ |
|
39 | - if(! is_url($link)){ |
|
38 | + public static function a($link = '', $anchor = null, array $attributes = array(), $return = true) { |
|
39 | + if (!is_url($link)) { |
|
40 | 40 | $link = Url::site_url($link); |
41 | 41 | } |
42 | - if(! $anchor){ |
|
42 | + if (!$anchor) { |
|
43 | 43 | $anchor = $link; |
44 | 44 | } |
45 | 45 | $str = null; |
46 | - $str .= '<a href = "'.$link.'"'; |
|
46 | + $str .= '<a href = "' . $link . '"'; |
|
47 | 47 | $str .= attributes_to_string($attributes); |
48 | 48 | $str .= '>'; |
49 | 49 | $str .= $anchor; |
50 | 50 | $str .= '</a>'; |
51 | 51 | |
52 | - if($return){ |
|
52 | + if ($return) { |
|
53 | 53 | return $str; |
54 | 54 | } |
55 | 55 | echo $str; |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return string|void the generated html for mailto link if $return is true or display it if not |
66 | 66 | */ |
67 | - public static function mailto($link, $anchor = null, array $attributes = array(), $return = true){ |
|
68 | - if(! $anchor){ |
|
67 | + public static function mailto($link, $anchor = null, array $attributes = array(), $return = true) { |
|
68 | + if (!$anchor) { |
|
69 | 69 | $anchor = $link; |
70 | 70 | } |
71 | 71 | $str = null; |
72 | - $str .= '<a href = "mailto:'.$link.'"'; |
|
72 | + $str .= '<a href = "mailto:' . $link . '"'; |
|
73 | 73 | $str .= attributes_to_string($attributes); |
74 | 74 | $str .= '>'; |
75 | 75 | $str .= $anchor; |
76 | 76 | $str .= '</a>'; |
77 | 77 | |
78 | - if($return){ |
|
78 | + if ($return) { |
|
79 | 79 | return $str; |
80 | 80 | } |
81 | 81 | echo $str; |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string|void the generated "br" html if $return is true or display it if not |
90 | 90 | */ |
91 | - public static function br($nb = 1, $return = true){ |
|
92 | - if(! is_numeric($nb) || $nb <= 0){ |
|
91 | + public static function br($nb = 1, $return = true) { |
|
92 | + if (!is_numeric($nb) || $nb <= 0) { |
|
93 | 93 | $nb = 1; |
94 | 94 | } |
95 | 95 | $str = null; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $str .= '<br />'; |
98 | 98 | } |
99 | 99 | |
100 | - if($return){ |
|
100 | + if ($return) { |
|
101 | 101 | return $str; |
102 | 102 | } |
103 | 103 | echo $str; |
@@ -111,15 +111,15 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @return string|void the generated "hr" html if $return is true or display it if not. |
113 | 113 | */ |
114 | - public static function hr($nb = 1, array $attributes = array(), $return = true){ |
|
115 | - if(! is_numeric($nb) || $nb <= 0){ |
|
114 | + public static function hr($nb = 1, array $attributes = array(), $return = true) { |
|
115 | + if (!is_numeric($nb) || $nb <= 0) { |
|
116 | 116 | $nb = 1; |
117 | 117 | } |
118 | 118 | $str = null; |
119 | 119 | for ($i = 1; $i <= $nb; $i++) { |
120 | - $str .= '<hr' .attributes_to_string($attributes). ' />'; |
|
120 | + $str .= '<hr' . attributes_to_string($attributes) . ' />'; |
|
121 | 121 | } |
122 | - if($return){ |
|
122 | + if ($return) { |
|
123 | 123 | return $str; |
124 | 124 | } |
125 | 125 | echo $str; |
@@ -135,18 +135,18 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return string|void the generated header html if $return is true or display it if not. |
137 | 137 | */ |
138 | - public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true){ |
|
139 | - if(! is_numeric($nb) || $nb <= 0){ |
|
138 | + public static function head($type = 1, $text = null, $nb = 1, array $attributes = array(), $return = true) { |
|
139 | + if (!is_numeric($nb) || $nb <= 0) { |
|
140 | 140 | $nb = 1; |
141 | 141 | } |
142 | - if(! is_numeric($type) || $type <= 0 || $type > 6){ |
|
142 | + if (!is_numeric($type) || $type <= 0 || $type > 6) { |
|
143 | 143 | $type = 1; |
144 | 144 | } |
145 | 145 | $str = null; |
146 | 146 | for ($i = 1; $i <= $nb; $i++) { |
147 | - $str .= '<h' . $type . attributes_to_string($attributes). '>' .$text. '</h' . $type . '>'; |
|
147 | + $str .= '<h' . $type . attributes_to_string($attributes) . '>' . $text . '</h' . $type . '>'; |
|
148 | 148 | } |
149 | - if($return){ |
|
149 | + if ($return) { |
|
150 | 150 | return $str; |
151 | 151 | } |
152 | 152 | echo $str; |
@@ -161,15 +161,15 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @return string|void the generated "ul" html if $return is true or display it if not. |
163 | 163 | */ |
164 | - public static function ul($data = array(), $attributes = array(), $return = true){ |
|
164 | + public static function ul($data = array(), $attributes = array(), $return = true) { |
|
165 | 165 | $data = (array) $data; |
166 | 166 | $str = null; |
167 | - $str .= '<ul' . (! empty($attributes['ul']) ? attributes_to_string($attributes['ul']):'') . '>'; |
|
167 | + $str .= '<ul' . (!empty($attributes['ul']) ? attributes_to_string($attributes['ul']) : '') . '>'; |
|
168 | 168 | foreach ($data as $row) { |
169 | - $str .= '<li' . (! empty($attributes['li']) ? attributes_to_string($attributes['li']):'') .'>' .$row. '</li>'; |
|
169 | + $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']) : '') . '>' . $row . '</li>'; |
|
170 | 170 | } |
171 | 171 | $str .= '</ul>'; |
172 | - if($return){ |
|
172 | + if ($return) { |
|
173 | 173 | return $str; |
174 | 174 | } |
175 | 175 | echo $str; |
@@ -183,15 +183,15 @@ discard block |
||
183 | 183 | * @param boolean $return whether need return the generated html or just display it directly |
184 | 184 | * @return string|void the generated "ol" html if $return is true or display it if not. |
185 | 185 | */ |
186 | - public static function ol($data = array(), $attributes = array(), $return = true){ |
|
186 | + public static function ol($data = array(), $attributes = array(), $return = true) { |
|
187 | 187 | $data = (array) $data; |
188 | 188 | $str = null; |
189 | - $str .= '<ol' . (!empty($attributes['ol']) ? attributes_to_string($attributes['ol']):'') . '>'; |
|
189 | + $str .= '<ol' . (!empty($attributes['ol']) ? attributes_to_string($attributes['ol']) : '') . '>'; |
|
190 | 190 | foreach ($data as $row) { |
191 | - $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']):'') .'>' .$row. '</li>'; |
|
191 | + $str .= '<li' . (!empty($attributes['li']) ? attributes_to_string($attributes['li']) : '') . '>' . $row . '</li>'; |
|
192 | 192 | } |
193 | 193 | $str .= '</ol>'; |
194 | - if($return){ |
|
194 | + if ($return) { |
|
195 | 195 | return $str; |
196 | 196 | } |
197 | 197 | echo $str; |
@@ -209,46 +209,46 @@ discard block |
||
209 | 209 | * @param boolean $return whether need return the generated html or just display it directly |
210 | 210 | * @return string|void the generated "table" html if $return is true or display it if not. |
211 | 211 | */ |
212 | - public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true){ |
|
212 | + public static function table($headers = array(), $body = array(), $attributes = array(), $use_footer = false, $return = true) { |
|
213 | 213 | $headers = (array) $headers; |
214 | 214 | $body = (array) $body; |
215 | 215 | $str = null; |
216 | - $str .= '<table' . (! empty($attributes['table']) ? attributes_to_string($attributes['table']):'') . '>'; |
|
217 | - if(! empty($headers)){ |
|
218 | - $str .= '<thead' . (! empty($attributes['thead']) ? attributes_to_string($attributes['thead']):'') .'>'; |
|
219 | - $str .= '<tr' . (! empty($attributes['thead_tr']) ? attributes_to_string($attributes['thead_tr']):'') .'>'; |
|
216 | + $str .= '<table' . (!empty($attributes['table']) ? attributes_to_string($attributes['table']) : '') . '>'; |
|
217 | + if (!empty($headers)) { |
|
218 | + $str .= '<thead' . (!empty($attributes['thead']) ? attributes_to_string($attributes['thead']) : '') . '>'; |
|
219 | + $str .= '<tr' . (!empty($attributes['thead_tr']) ? attributes_to_string($attributes['thead_tr']) : '') . '>'; |
|
220 | 220 | foreach ($headers as $value) { |
221 | - $str .= '<th' . (! empty($attributes['thead_th']) ? attributes_to_string($attributes['thead_th']):'') .'>' .$value. '</th>'; |
|
221 | + $str .= '<th' . (!empty($attributes['thead_th']) ? attributes_to_string($attributes['thead_th']) : '') . '>' . $value . '</th>'; |
|
222 | 222 | } |
223 | 223 | $str .= '</tr>'; |
224 | 224 | $str .= '</thead>'; |
225 | 225 | } |
226 | - else{ |
|
226 | + else { |
|
227 | 227 | //no need check for footer |
228 | 228 | $use_footer = false; |
229 | 229 | } |
230 | - $str .= '<tbody' . (! empty($attributes['tbody']) ? attributes_to_string($attributes['tbody']):'') .'>'; |
|
230 | + $str .= '<tbody' . (!empty($attributes['tbody']) ? attributes_to_string($attributes['tbody']) : '') . '>'; |
|
231 | 231 | foreach ($body as $row) { |
232 | - if(is_array($row)){ |
|
233 | - $str .= '<tr' . (! empty($attributes['tbody_tr']) ? attributes_to_string($attributes['tbody_tr']):'') .'>'; |
|
232 | + if (is_array($row)) { |
|
233 | + $str .= '<tr' . (!empty($attributes['tbody_tr']) ? attributes_to_string($attributes['tbody_tr']) : '') . '>'; |
|
234 | 234 | foreach ($row as $value) { |
235 | - $str .= '<td' . (! empty($attributes['tbody_td']) ? attributes_to_string($attributes['tbody_td']):'') .'>' .$value. '</td>'; |
|
235 | + $str .= '<td' . (!empty($attributes['tbody_td']) ? attributes_to_string($attributes['tbody_td']) : '') . '>' . $value . '</td>'; |
|
236 | 236 | } |
237 | 237 | $str .= '</tr>'; |
238 | 238 | } |
239 | 239 | } |
240 | 240 | $str .= '</tbody>'; |
241 | - if($use_footer){ |
|
242 | - $str .= '<tfoot' . (! empty($attributes['tfoot']) ? attributes_to_string($attributes['tfoot']):'') .'>'; |
|
243 | - $str .= '<tr' . (! empty($attributes['tfoot_tr']) ? attributes_to_string($attributes['tfoot_tr']):'') .'>'; |
|
241 | + if ($use_footer) { |
|
242 | + $str .= '<tfoot' . (!empty($attributes['tfoot']) ? attributes_to_string($attributes['tfoot']) : '') . '>'; |
|
243 | + $str .= '<tr' . (!empty($attributes['tfoot_tr']) ? attributes_to_string($attributes['tfoot_tr']) : '') . '>'; |
|
244 | 244 | foreach ($headers as $value) { |
245 | - $str .= '<th' . (! empty($attributes['tfoot_th']) ? attributes_to_string($attributes['tfoot_th']):'') .'>' .$value. '</th>'; |
|
245 | + $str .= '<th' . (!empty($attributes['tfoot_th']) ? attributes_to_string($attributes['tfoot_th']) : '') . '>' . $value . '</th>'; |
|
246 | 246 | } |
247 | 247 | $str .= '</tr>'; |
248 | 248 | $str .= '</tfoot>'; |
249 | 249 | } |
250 | 250 | $str .= '</table>'; |
251 | - if($return){ |
|
251 | + if ($return) { |
|
252 | 252 | return $str; |
253 | 253 | } |
254 | 254 | echo $str; |
@@ -222,8 +222,7 @@ |
||
222 | 222 | } |
223 | 223 | $str .= '</tr>'; |
224 | 224 | $str .= '</thead>'; |
225 | - } |
|
226 | - else{ |
|
225 | + } else{ |
|
227 | 226 | //no need check for footer |
228 | 227 | $use_footer = false; |
229 | 228 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
25 | 25 | */ |
26 | 26 | |
27 | - class Pagination{ |
|
27 | + class Pagination { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * The list of loaded config |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | * Create an instance of pagination |
37 | 37 | * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php |
38 | 38 | */ |
39 | - public function __construct($overwriteConfig = array()){ |
|
40 | - if(file_exists(CONFIG_PATH . 'config_pagination.php')){ |
|
39 | + public function __construct($overwriteConfig = array()) { |
|
40 | + if (file_exists(CONFIG_PATH . 'config_pagination.php')) { |
|
41 | 41 | require_once CONFIG_PATH . 'config_pagination.php'; |
42 | - if(empty($config) || ! is_array($config)){ |
|
42 | + if (empty($config) || !is_array($config)) { |
|
43 | 43 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
44 | 44 | } |
45 | - else{ |
|
46 | - if(! empty($overwriteConfig)){ |
|
45 | + else { |
|
46 | + if (!empty($overwriteConfig)) { |
|
47 | 47 | $config = array_merge($config, $overwriteConfig); |
48 | 48 | } |
49 | 49 | $this->config = $config; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | unset($config); |
52 | 52 | } |
53 | 53 | } |
54 | - else{ |
|
54 | + else { |
|
55 | 55 | show_error('Unable to find the pagination configuration file'); |
56 | 56 | } |
57 | 57 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * config_pagination.php |
63 | 63 | * @param array $config the configuration to set |
64 | 64 | */ |
65 | - public function setConfig(array $config = array()){ |
|
66 | - if(! empty($config)){ |
|
65 | + public function setConfig(array $config = array()) { |
|
66 | + if (!empty($config)) { |
|
67 | 67 | $this->config = array_merge($this->config, $config); |
68 | 68 | Config::setAll($config); |
69 | 69 | } |
@@ -75,26 +75,26 @@ discard block |
||
75 | 75 | * @param int $currentPageNumber the current page number |
76 | 76 | * @return string the pagination link |
77 | 77 | */ |
78 | - public function getLink($totalRows, $currentPageNumber){ |
|
78 | + public function getLink($totalRows, $currentPageNumber) { |
|
79 | 79 | $pageQueryName = $this->config['page_query_string_name']; |
80 | 80 | $numberOfLink = $this->config['nb_link']; |
81 | 81 | $numberOfRowPerPage = $this->config['pagination_per_page']; |
82 | 82 | $queryString = Url::queryString(); |
83 | 83 | $currentUrl = Url::current(); |
84 | - if($queryString == ''){ |
|
84 | + if ($queryString == '') { |
|
85 | 85 | $query = '?' . $pageQueryName . '='; |
86 | 86 | } |
87 | - else{ |
|
87 | + else { |
|
88 | 88 | $tab = explode($pageQueryName . '=', $queryString); |
89 | 89 | $nb = count($tab); |
90 | - if($nb == 1){ |
|
90 | + if ($nb == 1) { |
|
91 | 91 | $query = '?' . $queryString . '&' . $pageQueryName . '='; |
92 | 92 | } |
93 | - else{ |
|
94 | - if($tab[0] == ''){ |
|
93 | + else { |
|
94 | + if ($tab[0] == '') { |
|
95 | 95 | $query = '?' . $pageQueryName . '='; |
96 | 96 | } |
97 | - else{ |
|
97 | + else { |
|
98 | 98 | $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
99 | 99 | } |
100 | 100 | } |
@@ -103,67 +103,67 @@ discard block |
||
103 | 103 | $query = $temp[0] . $query; |
104 | 104 | $navbar = ''; |
105 | 105 | $numberOfPage = ceil($totalRows / $numberOfRowPerPage); |
106 | - if(! is_numeric ($currentPageNumber) || $currentPageNumber <= 0){ |
|
106 | + if (!is_numeric($currentPageNumber) || $currentPageNumber <= 0) { |
|
107 | 107 | $currentPageNumber = 1; |
108 | 108 | } |
109 | - if($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage) |
|
110 | - ){ |
|
109 | + if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage) |
|
110 | + ) { |
|
111 | 111 | return $navbar; |
112 | 112 | } |
113 | - if($numberOfLink % 2 == 0){ |
|
113 | + if ($numberOfLink % 2 == 0) { |
|
114 | 114 | $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
115 | 115 | $end = $currentPageNumber + ($numberOfLink / 2); |
116 | 116 | } |
117 | - else{ |
|
117 | + else { |
|
118 | 118 | $start = $currentPageNumber - floor($numberOfLink / 2); |
119 | 119 | $end = $currentPageNumber + floor($numberOfLink / 2); |
120 | 120 | } |
121 | - if($start <= 1){ |
|
121 | + if ($start <= 1) { |
|
122 | 122 | $begin = 1; |
123 | 123 | $end = $numberOfLink; |
124 | 124 | } |
125 | - else if($start > 1 && $end < $numberOfPage){ |
|
125 | + else if ($start > 1 && $end < $numberOfPage) { |
|
126 | 126 | $begin = $start; |
127 | 127 | $end = $end; |
128 | 128 | } |
129 | - else{ |
|
129 | + else { |
|
130 | 130 | $begin = ($numberOfPage - $numberOfLink) + 1; |
131 | 131 | $end = $numberOfPage; |
132 | 132 | } |
133 | - if($numberOfPage <= $numberOfLink){ |
|
133 | + if ($numberOfPage <= $numberOfLink) { |
|
134 | 134 | $begin = 1; |
135 | 135 | $end = $numberOfPage; |
136 | 136 | } |
137 | - if($currentPageNumber == 1){ |
|
138 | - for($i = $begin; $i <= $end; $i++){ |
|
139 | - if($i == $currentPageNumber){ |
|
137 | + if ($currentPageNumber == 1) { |
|
138 | + for ($i = $begin; $i <= $end; $i++) { |
|
139 | + if ($i == $currentPageNumber) { |
|
140 | 140 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
141 | 141 | } |
142 | - else{ |
|
142 | + else { |
|
143 | 143 | $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | $navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
147 | 147 | } |
148 | - else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
148 | + else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage) { |
|
149 | 149 | $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
150 | - for($i = $begin; $i <= $end; $i++){ |
|
151 | - if($i == $currentPageNumber){ |
|
150 | + for ($i = $begin; $i <= $end; $i++) { |
|
151 | + if ($i == $currentPageNumber) { |
|
152 | 152 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
153 | 153 | } |
154 | - else{ |
|
155 | - $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close']; |
|
154 | + else { |
|
155 | + $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
|
156 | 156 | } |
157 | 157 | } |
158 | - $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close']; |
|
158 | + $navbar .= $this->config['next_open'] . "<a href='$query" . ($currentPageNumber + 1) . "'>" . $this->config['next_text'] . "</a>" . $this->config['next_close']; |
|
159 | 159 | } |
160 | - else if($currentPageNumber == $numberOfPage){ |
|
160 | + else if ($currentPageNumber == $numberOfPage) { |
|
161 | 161 | $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
162 | - for($i = $begin; $i <= $end; $i++){ |
|
163 | - if($i == $currentPageNumber){ |
|
162 | + for ($i = $begin; $i <= $end; $i++) { |
|
163 | + if ($i == $currentPageNumber) { |
|
164 | 164 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
165 | 165 | } |
166 | - else{ |
|
166 | + else { |
|
167 | 167 | $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
168 | 168 | } |
169 | 169 | } |
@@ -41,8 +41,7 @@ discard block |
||
41 | 41 | require_once CONFIG_PATH . 'config_pagination.php'; |
42 | 42 | if(empty($config) || ! is_array($config)){ |
43 | 43 | show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
44 | - } |
|
45 | - else{ |
|
44 | + } else{ |
|
46 | 45 | if(! empty($overwriteConfig)){ |
47 | 46 | $config = array_merge($config, $overwriteConfig); |
48 | 47 | } |
@@ -50,8 +49,7 @@ discard block |
||
50 | 49 | Config::setAll($config); |
51 | 50 | unset($config); |
52 | 51 | } |
53 | - } |
|
54 | - else{ |
|
52 | + } else{ |
|
55 | 53 | show_error('Unable to find the pagination configuration file'); |
56 | 54 | } |
57 | 55 | } |
@@ -83,18 +81,15 @@ discard block |
||
83 | 81 | $currentUrl = Url::current(); |
84 | 82 | if($queryString == ''){ |
85 | 83 | $query = '?' . $pageQueryName . '='; |
86 | - } |
|
87 | - else{ |
|
84 | + } else{ |
|
88 | 85 | $tab = explode($pageQueryName . '=', $queryString); |
89 | 86 | $nb = count($tab); |
90 | 87 | if($nb == 1){ |
91 | 88 | $query = '?' . $queryString . '&' . $pageQueryName . '='; |
92 | - } |
|
93 | - else{ |
|
89 | + } else{ |
|
94 | 90 | if($tab[0] == ''){ |
95 | 91 | $query = '?' . $pageQueryName . '='; |
96 | - } |
|
97 | - else{ |
|
92 | + } else{ |
|
98 | 93 | $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
99 | 94 | } |
100 | 95 | } |
@@ -113,20 +108,17 @@ discard block |
||
113 | 108 | if($numberOfLink % 2 == 0){ |
114 | 109 | $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
115 | 110 | $end = $currentPageNumber + ($numberOfLink / 2); |
116 | - } |
|
117 | - else{ |
|
111 | + } else{ |
|
118 | 112 | $start = $currentPageNumber - floor($numberOfLink / 2); |
119 | 113 | $end = $currentPageNumber + floor($numberOfLink / 2); |
120 | 114 | } |
121 | 115 | if($start <= 1){ |
122 | 116 | $begin = 1; |
123 | 117 | $end = $numberOfLink; |
124 | - } |
|
125 | - else if($start > 1 && $end < $numberOfPage){ |
|
118 | + } else if($start > 1 && $end < $numberOfPage){ |
|
126 | 119 | $begin = $start; |
127 | 120 | $end = $end; |
128 | - } |
|
129 | - else{ |
|
121 | + } else{ |
|
130 | 122 | $begin = ($numberOfPage - $numberOfLink) + 1; |
131 | 123 | $end = $numberOfPage; |
132 | 124 | } |
@@ -138,32 +130,27 @@ discard block |
||
138 | 130 | for($i = $begin; $i <= $end; $i++){ |
139 | 131 | if($i == $currentPageNumber){ |
140 | 132 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
141 | - } |
|
142 | - else{ |
|
133 | + } else{ |
|
143 | 134 | $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
144 | 135 | } |
145 | 136 | } |
146 | 137 | $navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
147 | - } |
|
148 | - else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
138 | + } else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
149 | 139 | $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
150 | 140 | for($i = $begin; $i <= $end; $i++){ |
151 | 141 | if($i == $currentPageNumber){ |
152 | 142 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
153 | - } |
|
154 | - else{ |
|
143 | + } else{ |
|
155 | 144 | $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close']; |
156 | 145 | } |
157 | 146 | } |
158 | 147 | $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close']; |
159 | - } |
|
160 | - else if($currentPageNumber == $numberOfPage){ |
|
148 | + } else if($currentPageNumber == $numberOfPage){ |
|
161 | 149 | $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
162 | 150 | for($i = $begin; $i <= $end; $i++){ |
163 | 151 | if($i == $currentPageNumber){ |
164 | 152 | $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
165 | - } |
|
166 | - else{ |
|
153 | + } else{ |
|
167 | 154 | $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
168 | 155 | } |
169 | 156 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | - defined('ROOT_PATH') || exit('Access denied'); |
|
2 | + defined('ROOT_PATH') || exit('Access denied'); |
|
3 | 3 | /** |
4 | 4 | * TNH Framework |
5 | 5 | * |
@@ -22,154 +22,154 @@ 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 | - class Pagination{ |
|
27 | + class Pagination{ |
|
28 | 28 | |
29 | 29 | /** |
30 | - * The list of loaded config |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - private $config = array(); |
|
30 | + * The list of loaded config |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + private $config = array(); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Create an instance of pagination |
|
37 | - * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php |
|
38 | - */ |
|
39 | - public function __construct($overwriteConfig = array()){ |
|
40 | - if(file_exists(CONFIG_PATH . 'config_pagination.php')){ |
|
41 | - require_once CONFIG_PATH . 'config_pagination.php'; |
|
42 | - if(empty($config) || ! is_array($config)){ |
|
43 | - show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
|
44 | - } |
|
35 | + /** |
|
36 | + * Create an instance of pagination |
|
37 | + * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php |
|
38 | + */ |
|
39 | + public function __construct($overwriteConfig = array()){ |
|
40 | + if(file_exists(CONFIG_PATH . 'config_pagination.php')){ |
|
41 | + require_once CONFIG_PATH . 'config_pagination.php'; |
|
42 | + if(empty($config) || ! is_array($config)){ |
|
43 | + show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php'); |
|
44 | + } |
|
45 | 45 | else{ |
46 | 46 | if(! empty($overwriteConfig)){ |
47 | 47 | $config = array_merge($config, $overwriteConfig); |
48 | 48 | } |
49 | 49 | $this->config = $config; |
50 | - //put it gobally |
|
50 | + //put it gobally |
|
51 | 51 | Config::setAll($config); |
52 | 52 | unset($config); |
53 | 53 | } |
54 | - } |
|
55 | - else{ |
|
56 | - show_error('Unable to find the pagination configuration file'); |
|
57 | - } |
|
58 | - } |
|
54 | + } |
|
55 | + else{ |
|
56 | + show_error('Unable to find the pagination configuration file'); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Set the pagination custom configuration to overwrite the default configuration in |
|
63 | - * config_pagination.php |
|
64 | - * @param array $config the configuration to set |
|
65 | - */ |
|
66 | - public function setConfig(array $config = array()){ |
|
67 | - if(! empty($config)){ |
|
68 | - $this->config = array_merge($this->config, $config); |
|
69 | - Config::setAll($config); |
|
70 | - } |
|
71 | - } |
|
61 | + /** |
|
62 | + * Set the pagination custom configuration to overwrite the default configuration in |
|
63 | + * config_pagination.php |
|
64 | + * @param array $config the configuration to set |
|
65 | + */ |
|
66 | + public function setConfig(array $config = array()){ |
|
67 | + if(! empty($config)){ |
|
68 | + $this->config = array_merge($this->config, $config); |
|
69 | + Config::setAll($config); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Generate the pagination link |
|
75 | - * @param int $totalRows the total number of data |
|
76 | - * @param int $currentPageNumber the current page number |
|
77 | - * @return string the pagination link |
|
78 | - */ |
|
79 | - public function getLink($totalRows, $currentPageNumber){ |
|
80 | - $pageQueryName = $this->config['page_query_string_name']; |
|
81 | - $numberOfLink = $this->config['nb_link']; |
|
73 | + /** |
|
74 | + * Generate the pagination link |
|
75 | + * @param int $totalRows the total number of data |
|
76 | + * @param int $currentPageNumber the current page number |
|
77 | + * @return string the pagination link |
|
78 | + */ |
|
79 | + public function getLink($totalRows, $currentPageNumber){ |
|
80 | + $pageQueryName = $this->config['page_query_string_name']; |
|
81 | + $numberOfLink = $this->config['nb_link']; |
|
82 | 82 | $numberOfRowPerPage = $this->config['pagination_per_page']; |
83 | - $queryString = Url::queryString(); |
|
84 | - $currentUrl = Url::current(); |
|
85 | - if($queryString == ''){ |
|
86 | - $query = '?' . $pageQueryName . '='; |
|
87 | - } |
|
88 | - else{ |
|
89 | - $tab = explode($pageQueryName . '=', $queryString); |
|
90 | - $nb = count($tab); |
|
91 | - if($nb == 1){ |
|
92 | - $query = '?' . $queryString . '&' . $pageQueryName . '='; |
|
93 | - } |
|
94 | - else{ |
|
95 | - if($tab[0] == ''){ |
|
96 | - $query = '?' . $pageQueryName . '='; |
|
97 | - } |
|
98 | - else{ |
|
99 | - $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - $temp = explode('?', $currentUrl); |
|
104 | - $query = $temp[0] . $query; |
|
105 | - $navbar = ''; |
|
106 | - $numberOfPage = ceil($totalRows / $numberOfRowPerPage); |
|
83 | + $queryString = Url::queryString(); |
|
84 | + $currentUrl = Url::current(); |
|
85 | + if($queryString == ''){ |
|
86 | + $query = '?' . $pageQueryName . '='; |
|
87 | + } |
|
88 | + else{ |
|
89 | + $tab = explode($pageQueryName . '=', $queryString); |
|
90 | + $nb = count($tab); |
|
91 | + if($nb == 1){ |
|
92 | + $query = '?' . $queryString . '&' . $pageQueryName . '='; |
|
93 | + } |
|
94 | + else{ |
|
95 | + if($tab[0] == ''){ |
|
96 | + $query = '?' . $pageQueryName . '='; |
|
97 | + } |
|
98 | + else{ |
|
99 | + $query = '?' . $tab[0] . '' . $pageQueryName . '='; |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + $temp = explode('?', $currentUrl); |
|
104 | + $query = $temp[0] . $query; |
|
105 | + $navbar = ''; |
|
106 | + $numberOfPage = ceil($totalRows / $numberOfRowPerPage); |
|
107 | 107 | if(! is_numeric ($currentPageNumber) || $currentPageNumber <= 0){ |
108 | 108 | $currentPageNumber = 1; |
109 | 109 | } |
110 | - if($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage) |
|
111 | - ){ |
|
112 | - return $navbar; |
|
113 | - } |
|
114 | - if($numberOfLink % 2 == 0){ |
|
115 | - $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
|
116 | - $end = $currentPageNumber + ($numberOfLink / 2); |
|
117 | - } |
|
118 | - else{ |
|
119 | - $start = $currentPageNumber - floor($numberOfLink / 2); |
|
120 | - $end = $currentPageNumber + floor($numberOfLink / 2); |
|
121 | - } |
|
122 | - if($start <= 1){ |
|
123 | - $begin = 1; |
|
124 | - $end = $numberOfLink; |
|
125 | - } |
|
126 | - else if($start > 1 && $end < $numberOfPage){ |
|
127 | - $begin = $start; |
|
128 | - $end = $end; |
|
129 | - } |
|
130 | - else{ |
|
131 | - $begin = ($numberOfPage - $numberOfLink) + 1; |
|
132 | - $end = $numberOfPage; |
|
133 | - } |
|
134 | - if($numberOfPage <= $numberOfLink){ |
|
135 | - $begin = 1; |
|
136 | - $end = $numberOfPage; |
|
137 | - } |
|
138 | - if($currentPageNumber == 1){ |
|
139 | - for($i = $begin; $i <= $end; $i++){ |
|
140 | - if($i == $currentPageNumber){ |
|
141 | - $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
|
142 | - } |
|
143 | - else{ |
|
144 | - $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
|
145 | - } |
|
146 | - } |
|
147 | - $navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
|
148 | - } |
|
149 | - else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
150 | - $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
|
151 | - for($i = $begin; $i <= $end; $i++){ |
|
152 | - if($i == $currentPageNumber){ |
|
153 | - $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
|
154 | - } |
|
155 | - else{ |
|
156 | - $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close']; |
|
157 | - } |
|
158 | - } |
|
159 | - $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close']; |
|
160 | - } |
|
161 | - else if($currentPageNumber == $numberOfPage){ |
|
162 | - $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
|
163 | - for($i = $begin; $i <= $end; $i++){ |
|
164 | - if($i == $currentPageNumber){ |
|
165 | - $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
|
166 | - } |
|
167 | - else{ |
|
168 | - $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close']; |
|
173 | - return $navbar; |
|
174 | - } |
|
175 | - } |
|
110 | + if($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0 || !is_numeric($numberOfLink) || !is_numeric($numberOfRowPerPage) |
|
111 | + ){ |
|
112 | + return $navbar; |
|
113 | + } |
|
114 | + if($numberOfLink % 2 == 0){ |
|
115 | + $start = $currentPageNumber - ($numberOfLink / 2) + 1; |
|
116 | + $end = $currentPageNumber + ($numberOfLink / 2); |
|
117 | + } |
|
118 | + else{ |
|
119 | + $start = $currentPageNumber - floor($numberOfLink / 2); |
|
120 | + $end = $currentPageNumber + floor($numberOfLink / 2); |
|
121 | + } |
|
122 | + if($start <= 1){ |
|
123 | + $begin = 1; |
|
124 | + $end = $numberOfLink; |
|
125 | + } |
|
126 | + else if($start > 1 && $end < $numberOfPage){ |
|
127 | + $begin = $start; |
|
128 | + $end = $end; |
|
129 | + } |
|
130 | + else{ |
|
131 | + $begin = ($numberOfPage - $numberOfLink) + 1; |
|
132 | + $end = $numberOfPage; |
|
133 | + } |
|
134 | + if($numberOfPage <= $numberOfLink){ |
|
135 | + $begin = 1; |
|
136 | + $end = $numberOfPage; |
|
137 | + } |
|
138 | + if($currentPageNumber == 1){ |
|
139 | + for($i = $begin; $i <= $end; $i++){ |
|
140 | + if($i == $currentPageNumber){ |
|
141 | + $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
|
142 | + } |
|
143 | + else{ |
|
144 | + $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
|
145 | + } |
|
146 | + } |
|
147 | + $navbar .= $this->config['next_open'] . '<a href="' . $query . ($currentPageNumber + 1) . '">' . $this->config['next_text'] . '</a>' . $this->config['next_close']; |
|
148 | + } |
|
149 | + else if($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){ |
|
150 | + $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
|
151 | + for($i = $begin; $i <= $end; $i++){ |
|
152 | + if($i == $currentPageNumber){ |
|
153 | + $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
|
154 | + } |
|
155 | + else{ |
|
156 | + $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close']; |
|
157 | + } |
|
158 | + } |
|
159 | + $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close']; |
|
160 | + } |
|
161 | + else if($currentPageNumber == $numberOfPage){ |
|
162 | + $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close']; |
|
163 | + for($i = $begin; $i <= $end; $i++){ |
|
164 | + if($i == $currentPageNumber){ |
|
165 | + $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close']; |
|
166 | + } |
|
167 | + else{ |
|
168 | + $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close']; |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close']; |
|
173 | + return $navbar; |
|
174 | + } |
|
175 | + } |