@@ -8,13 +8,13 @@ discard block |
||
| 8 | 8 | <meta name="description" content="A simple PHP framework using HMVC architecture"> |
| 9 | 9 | <meta name="author" content="Tony NGUEREZA"> |
| 10 | 10 | <title>TNH Framework</title> |
| 11 | - <link href="<?php echo Assets::css('bootstrap.min');?>" rel="stylesheet" type = "text/css" > |
|
| 12 | - <link href="<?php echo Assets::css('font-awesome.min');?>" rel="stylesheet" type = "text/css" > |
|
| 13 | - <link href="<?php echo Assets::css('responsive');?>" rel="stylesheet" type = "text/css" > |
|
| 14 | - <link rel="icon" href="<?php echo Assets::img('favicon.ico');?>"> |
|
| 11 | + <link href="<?php echo Assets::css('bootstrap.min'); ?>" rel="stylesheet" type = "text/css" > |
|
| 12 | + <link href="<?php echo Assets::css('font-awesome.min'); ?>" rel="stylesheet" type = "text/css" > |
|
| 13 | + <link href="<?php echo Assets::css('responsive'); ?>" rel="stylesheet" type = "text/css" > |
|
| 14 | + <link rel="icon" href="<?php echo Assets::img('favicon.ico'); ?>"> |
|
| 15 | 15 | <!--[if lt IE 9]> |
| 16 | - <script src="<?php echo Assets::js('html5shiv');?>"></script> |
|
| 17 | - <script src="<?php echo Assets::js('respond.min');?>"></script> |
|
| 16 | + <script src="<?php echo Assets::js('html5shiv'); ?>"></script> |
|
| 17 | + <script src="<?php echo Assets::js('respond.min'); ?>"></script> |
|
| 18 | 18 | <![endif]--> |
| 19 | 19 | <style type = "text/css"> |
| 20 | 20 | |
@@ -28,15 +28,15 @@ discard block |
||
| 28 | 28 | <div class = "col-md-offset-2 col-md-8 col-md-offset-2"> |
| 29 | 29 | <div class = "panel panel-primary"> |
| 30 | 30 | <div class = "panel-heading"> |
| 31 | - <h2>Welcome on <?php echo TNH_NAME;?> v<?php echo TNH_VERSION;?></h2> |
|
| 31 | + <h2>Welcome on <?php echo TNH_NAME; ?> v<?php echo TNH_VERSION; ?></h2> |
|
| 32 | 32 | </div> |
| 33 | 33 | <div class = "panel-body"> |
| 34 | - <img src = "<?php echo Assets::img('logo.png');?>" class = "img-responsive" style = "float:left;" /> |
|
| 34 | + <img src = "<?php echo Assets::img('logo.png'); ?>" class = "img-responsive" style = "float:left;" /> |
|
| 35 | 35 | <h3> |
| 36 | 36 | A simple PHP framework using HMVC architecture |
| 37 | 37 | </h3> |
| 38 | 38 | <br /> |
| 39 | - <p><?php echo Html::a('https://github.com/tnhfw/tnh-fw', 'Framework on Github', array('class' => 'btn btn-default', 'target' => '_blank'));?></p> |
|
| 39 | + <p><?php echo Html::a('https://github.com/tnhfw/tnh-fw', 'Framework on Github', array('class' => 'btn btn-default', 'target' => '_blank')); ?></p> |
|
| 40 | 40 | </div> |
| 41 | 41 | </div> |
| 42 | 42 | <div class = "panel panel-primary"> |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | <h2>Server information</h2> |
| 45 | 45 | </div> |
| 46 | 46 | <div class = "panel-body"> |
| 47 | - <h4>Running on : <b><?php echo php_uname();?></b></h4> |
|
| 48 | - <h4>PHP server SAPI : <b><?php echo php_sapi_name();?></b></h4> |
|
| 49 | - <h4>PHP Version : <b><?php echo phpversion();?></b></h4> |
|
| 50 | - <h4>PHP Loaded extensions : (<?php echo count(get_loaded_extensions());?> extensions)</h4> |
|
| 47 | + <h4>Running on : <b><?php echo php_uname(); ?></b></h4> |
|
| 48 | + <h4>PHP server SAPI : <b><?php echo php_sapi_name(); ?></b></h4> |
|
| 49 | + <h4>PHP Version : <b><?php echo phpversion(); ?></b></h4> |
|
| 50 | + <h4>PHP Loaded extensions : (<?php echo count(get_loaded_extensions()); ?> extensions)</h4> |
|
| 51 | 51 | <table class = "table table-striped table-condensed table-bordered table-responsive"> |
| 52 | 52 | <tr> |
| 53 | 53 | <th>Name</th> |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | </tr> |
| 56 | 56 | <?php foreach (get_loaded_extensions() as $e):?> |
| 57 | 57 | <tr> |
| 58 | - <td><?php echo $e;?></td> |
|
| 59 | - <td><?php echo phpversion($e);?></td> |
|
| 58 | + <td><?php echo $e; ?></td> |
|
| 59 | + <td><?php echo phpversion($e); ?></td> |
|
| 60 | 60 | </tr> |
| 61 | - <?php endforeach;?> |
|
| 61 | + <?php endforeach; ?> |
|
| 62 | 62 | </table> |
| 63 | 63 | </div> |
| 64 | 64 | </div> |
@@ -67,30 +67,30 @@ discard block |
||
| 67 | 67 | <h2>Framework information</h2> |
| 68 | 68 | </div> |
| 69 | 69 | <div class = "panel-body"> |
| 70 | - <h4>Version : <b><?php echo TNH_VERSION;?></b></h4> |
|
| 71 | - <h4>Required PHP version : <b>PHP >= <?php echo TNH_REQUIRED_PHP_MIN_VERSION;?>, PHP <= <?php echo TNH_REQUIRED_PHP_MAX_VERSION;?></b></h4> |
|
| 72 | - <h4>Build date : <b><?php echo TNH_RELEASE_DATE;?></b></h4> |
|
| 73 | - <h4>Author : <b><?php echo TNH_AUTHOR;?></b></h4> |
|
| 74 | - <h4>Author E-mail : <b><?php echo TNH_AUTHOR_EMAIL;?></b></h4> |
|
| 75 | - <h4>Loaded files : (<?php echo count(get_included_files());?> files)</h4> |
|
| 70 | + <h4>Version : <b><?php echo TNH_VERSION; ?></b></h4> |
|
| 71 | + <h4>Required PHP version : <b>PHP >= <?php echo TNH_REQUIRED_PHP_MIN_VERSION; ?>, PHP <= <?php echo TNH_REQUIRED_PHP_MAX_VERSION; ?></b></h4> |
|
| 72 | + <h4>Build date : <b><?php echo TNH_RELEASE_DATE; ?></b></h4> |
|
| 73 | + <h4>Author : <b><?php echo TNH_AUTHOR; ?></b></h4> |
|
| 74 | + <h4>Author E-mail : <b><?php echo TNH_AUTHOR_EMAIL; ?></b></h4> |
|
| 75 | + <h4>Loaded files : (<?php echo count(get_included_files()); ?> files)</h4> |
|
| 76 | 76 | <table class = "table table-striped table-condensed table-bordered table-responsive"> |
| 77 | 77 | <tr> |
| 78 | 78 | <th>Path</th> |
| 79 | 79 | <th>File</th> |
| 80 | 80 | </tr> |
| 81 | - <?php foreach(get_included_files() as $file):?> |
|
| 81 | + <?php foreach (get_included_files() as $file):?> |
|
| 82 | 82 | <tr> |
| 83 | - <td><?php echo $file;?></td> |
|
| 84 | - <td><?php echo basename($file);?></td> |
|
| 83 | + <td><?php echo $file; ?></td> |
|
| 84 | + <td><?php echo basename($file); ?></td> |
|
| 85 | 85 | </tr> |
| 86 | - <?php endforeach;?> |
|
| 86 | + <?php endforeach; ?> |
|
| 87 | 87 | </table> |
| 88 | 88 | </div> |
| 89 | 89 | </div> |
| 90 | 90 | </div> |
| 91 | 91 | </div> |
| 92 | 92 | </div> |
| 93 | - <script src="<?php echo Assets::js('jquery');?>"></script> |
|
| 94 | - <script src="<?php echo Assets::js('bootstrap.min');?>"></script> |
|
| 93 | + <script src="<?php echo Assets::js('jquery'); ?>"></script> |
|
| 94 | + <script src="<?php echo Assets::js('bootstrap.min'); ?>"></script> |
|
| 95 | 95 | </body> |
| 96 | 96 | </html> |
@@ -243,7 +243,7 @@ |
||
| 243 | 243 | if (version_compare(PHP_VERSION, '5.3', '>=')) { |
| 244 | 244 | error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
| 245 | 245 | } |
| 246 | - else{ |
|
| 246 | + else { |
|
| 247 | 247 | error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
| 248 | 248 | } |
| 249 | 249 | break; |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | - interface CacheInterface{ |
|
| 27 | + interface CacheInterface { |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * This is used to get the cache data using the key |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - class Url{ |
|
| 28 | + class Url { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Return the link using base_url config without front controller "index.php" |
| 32 | 32 | * @param string $path the link path or full URL |
| 33 | 33 | * @return string the full link URL |
| 34 | 34 | */ |
| 35 | - public static function base_url($path = ''){ |
|
| 36 | - if(is_url($path)){ |
|
| 35 | + public static function base_url($path = '') { |
|
| 36 | + if (is_url($path)) { |
|
| 37 | 37 | return $path; |
| 38 | 38 | } |
| 39 | 39 | return get_config('base_url') . $path; |
@@ -44,26 +44,26 @@ discard block |
||
| 44 | 44 | * @param string $path the link path or full URL |
| 45 | 45 | * @return string the full link URL |
| 46 | 46 | */ |
| 47 | - public static function site_url($path = ''){ |
|
| 48 | - if(is_url($path)){ |
|
| 47 | + public static function site_url($path = '') { |
|
| 48 | + if (is_url($path)) { |
|
| 49 | 49 | return $path; |
| 50 | 50 | } |
| 51 | 51 | $path = rtrim($path, '/'); |
| 52 | 52 | $baseUrl = get_config('base_url'); |
| 53 | 53 | $frontController = get_config('front_controller'); |
| 54 | 54 | $url = $baseUrl; |
| 55 | - if($frontController){ |
|
| 55 | + if ($frontController) { |
|
| 56 | 56 | $url .= $frontController . '/'; |
| 57 | 57 | } |
| 58 | - if(($suffix = get_config('url_suffix')) && $path){ |
|
| 59 | - if(strpos($path, '?') !== false){ |
|
| 58 | + if (($suffix = get_config('url_suffix')) && $path) { |
|
| 59 | + if (strpos($path, '?') !== false) { |
|
| 60 | 60 | $query = explode('?', $path); |
| 61 | 61 | $query[0] = str_ireplace($suffix, '', $query[0]); |
| 62 | 62 | $query[0] = rtrim($query[0], '/'); |
| 63 | 63 | $query[0] .= $suffix; |
| 64 | 64 | $path = implode('?', $query); |
| 65 | 65 | } |
| 66 | - else{ |
|
| 66 | + else { |
|
| 67 | 67 | $path .= $suffix; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | * Return the current site URL |
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | - public static function current(){ |
|
| 77 | + public static function current() { |
|
| 78 | 78 | $current = '/'; |
| 79 | 79 | $requestUri = get_instance()->request->requestUri(); |
| 80 | - if($requestUri){ |
|
| 80 | + if ($requestUri) { |
|
| 81 | 81 | $current = $requestUri; |
| 82 | 82 | } |
| 83 | 83 | return static::domain() . $current; |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | * @param boolean $lowercase whether to set the final text to lowe case or not |
| 91 | 91 | * @return string the friendly generated text |
| 92 | 92 | */ |
| 93 | - public static function title($str = null, $separator = '-', $lowercase = true){ |
|
| 93 | + public static function title($str = null, $separator = '-', $lowercase = true) { |
|
| 94 | 94 | $str = trim($str); |
| 95 | - $from = array('ç','À','Á','Â','Ã','Ä','Å','à','á','â','ã','ä','å','Ò','Ó','Ô','Õ','Ö','Ø','ò','ó','ô','õ','ö','ø','È','É','Ê','Ë','è','é','ê','ë','Ç','ç','Ì','Í','Î','Ï','ì','í','î','ï','Ù','Ú','Û','Ü','ù','ú','û','ü','ÿ','Ñ','ñ'); |
|
| 96 | - $to = array('c','a','a','a','a','a','a','a','a','a','a','a','a','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','i','i','i','i','i','i','i','i','u','u','u','u','u','u','u','u','y','n','n'); |
|
| 95 | + $from = array('ç', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'à', 'á', 'â', 'ã', 'ä', 'å', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'È', 'É', 'Ê', 'Ë', 'è', 'é', 'ê', 'ë', 'Ç', 'ç', 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', 'Ù', 'Ú', 'Û', 'Ü', 'ù', 'ú', 'û', 'ü', 'ÿ', 'Ñ', 'ñ'); |
|
| 96 | + $to = array('c', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'y', 'n', 'n'); |
|
| 97 | 97 | $str = str_replace($from, $to, $str); |
| 98 | 98 | $str = preg_replace('#([^a-z0-9]+)#i', $separator, $str); |
| 99 | 99 | $str = str_replace('--', $separator, $str); |
| 100 | 100 | //if after process we get something like one-two-three-, need truncate the last separator "-" |
| 101 | - if(substr($str, -1) == $separator){ |
|
| 101 | + if (substr($str, -1) == $separator) { |
|
| 102 | 102 | $str = substr($str, 0, -1); |
| 103 | 103 | } |
| 104 | - if($lowercase){ |
|
| 104 | + if ($lowercase) { |
|
| 105 | 105 | $str = strtolower($str); |
| 106 | 106 | } |
| 107 | 107 | return $str; |
@@ -111,36 +111,36 @@ discard block |
||
| 111 | 111 | * Get the current application domain with protocol |
| 112 | 112 | * @return string the domain name |
| 113 | 113 | */ |
| 114 | - public static function domain(){ |
|
| 114 | + public static function domain() { |
|
| 115 | 115 | $obj = & get_instance(); |
| 116 | 116 | $domain = 'localhost'; |
| 117 | 117 | $port = $obj->request->server('SERVER_PORT'); |
| 118 | 118 | $protocol = is_https() ? 'https' : 'http'; |
| 119 | 119 | |
| 120 | - if($obj->request->server('HTTP_HOST')){ |
|
| 120 | + if ($obj->request->server('HTTP_HOST')) { |
|
| 121 | 121 | $domain = $obj->request->server('HTTP_HOST'); |
| 122 | 122 | } |
| 123 | - else if($obj->request->server('SERVER_NAME')){ |
|
| 123 | + else if ($obj->request->server('SERVER_NAME')) { |
|
| 124 | 124 | $domain = $obj->request->server('SERVER_NAME'); |
| 125 | 125 | } |
| 126 | - else if($obj->request->server('SERVER_ADDR')){ |
|
| 126 | + else if ($obj->request->server('SERVER_ADDR')) { |
|
| 127 | 127 | $domain = $obj->request->server('SERVER_ADDR'); |
| 128 | 128 | } |
| 129 | - if($port && (is_https() && $port != 443 || !is_https() && $port != 80)){ |
|
| 129 | + if ($port && (is_https() && $port != 443 || !is_https() && $port != 80)) { |
|
| 130 | 130 | //some server use SSL but the port doesn't equal 443 sometime is 80 if is the case put the port at this end |
| 131 | 131 | //of the domain like https://my.domain.com:787 |
| 132 | - if(is_https() && $port != 80){ |
|
| 133 | - $domain .= ':'.$port; |
|
| 132 | + if (is_https() && $port != 80) { |
|
| 133 | + $domain .= ':' . $port; |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | - return $protocol.'://'.$domain; |
|
| 136 | + return $protocol . '://' . $domain; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
| 140 | 140 | * Get the current request query string |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - public static function queryString(){ |
|
| 143 | + public static function queryString() { |
|
| 144 | 144 | return get_instance()->request->server('QUERY_STRING'); |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | \ No newline at end of file |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * This class represent the event detail to dispatch to correspond listener |
| 29 | 29 | */ |
| 30 | - class Event{ |
|
| 30 | + class Event { |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * The event name |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public $stop; |
| 56 | 56 | |
| 57 | - public function __construct($name, $payload = array(), $returnBack = false, $stop = false){ |
|
| 57 | + public function __construct($name, $payload = array(), $returnBack = false, $stop = false) { |
|
| 58 | 58 | $this->name = $name; |
| 59 | 59 | $this->payload = $payload; |
| 60 | 60 | $this->returnBack = $returnBack; |
@@ -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 | |
@@ -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'; |
@@ -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; |
@@ -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 | } |