Skip to content

Commit

Permalink
Update Pagination, Database and Form_validation class. Also there as …
Browse files Browse the repository at this point in the history
…some update in security_helper()
  • Loading branch information
ronmarasigan committed May 30, 2023
1 parent afce028 commit 13ebc5b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
</p>
LavaLust is a lightweight Web Framework - (using MVC pattern) - for people who are developing web sites using PHP. It helps you write code easily using Object-Oriented Approach. It also provides set of libraries for commonly needed tasks, as well as a helper functions to minimize the amount of time coding.

## LavaLust Version 3.1.4
## LavaLust Version 3.1.5 (latest)
<p>
Update your project using this version. You are required to use PHP v7.4 or higher.
LavaLust v3.1.4 is fully compatible to PHP8.2 and higher
LavaLust v3.1.5 is fully compatible to PHP8.2 and higher
</p>

## LavaLust Version 3
Expand Down
13 changes: 13 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
LavaLust 3.1.5

# Changelog

1. Database class was updated. It has offset and pagination method. Check documentation

2. csrf_field() function in security helper was now echoed output. return $form to echo $form.

3. Form_validation class was updated. It has valid_name() method to validate Person's name.

4. Pagination class was updated. initiate() method has new set of parameters.
initiate($table, $rows_per_page, $page_num, $url, $crumbs = 5) //$table is the database table name to paginate

LavaLust 3.1.4 (Compatible with PHP 8.2 and higher)

# Changelog
Expand Down
40 changes: 31 additions & 9 deletions scheme/database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Database {
private $having = NULL;
private $lastIDInserted = 0;
private $transactionCount = 0;
private $offset = null;
private $operators = array('=', '!=', '<', '>', '<=', '>=', '<>');

public function __construct($dbname = NULL)
Expand Down Expand Up @@ -164,6 +165,7 @@ private function resetQuery()
$this->sql = NULL;
$this->bindValues = array();
$this->limit = NULL;
$this->offset = NULL;
$this->orderBy = NULL;
$this->groupBy = NULL;
$this->having = NULL;
Expand Down Expand Up @@ -821,22 +823,38 @@ public function or_not_in($field, array $keys)
public function limit($limit, $end = NULL)
{
if ($end == NULL ) {
$this->limit = " LIMIT {$limit}";
$this->limit = $limit;
}else{
$this->limit = " LIMIT {$limit}, {$end}";
$this->limit = $limit .', '. $end;
}

return $this;
}

/**
* offset
*
* @param int $offset
* @return $this
* Offset
*
* @param int $offset
* @return void
*/
public function offset($offset)
{
$this->offset = $offset;

return $this;
}

/**
* Pagination
*
* @param int $perPage
* @param int $page
* @return void
*/
public function offset($offset) {
$this->limit .= " OFFSET {$offset}";
public function pagination($perPage, $page)
{
$this->limit = $perPage;
$this->offset = (($page > 0 ? $page : 1) - 1) * $perPage;

return $this;
}
Expand Down Expand Up @@ -949,7 +967,11 @@ private function buildQuery()
}

if ($this->limit !== NULL) {
$this->sql .= $this->limit;
$this->sql .= ' LIMIT ' . $this->limit;
}

if ($this->offset !== NULL) {
$this->sql .= ' OFFSET ' . $this->offset;
}
}

Expand Down
2 changes: 1 addition & 1 deletion scheme/helpers/security_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function csrf_field() {
$append,
"\n"
);
return $form;
echo $form;
}
}
?>
14 changes: 14 additions & 0 deletions scheme/libraries/Form_validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Form_validation {
private static $err_less_than_equal_to = 'Please enter a value greater than or equal to %f';
private static $err_in_list = '%s is not in the list';
private static $err_pattern = 'Please is not in %s format';
private static $err_valid_name = '%s is not a valid name';

public $patterns = array(
'url' => '(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})+',
Expand Down Expand Up @@ -562,6 +563,19 @@ public function in_list($list, $custom_error = '')
return $this;
}

/**
* Check if format of Person name is valid
*
* @param string $custom_error
* @return void
*/
public function valid_name($custom_error = '') {
if (!preg_match('/^[\p{L} ]+$/u', $this->value)) {
$this->set_error_message($custom_error, self::$err_valid_name, $this->value);
}
return $this;
}

/**
* Is validated
*
Expand Down
3 changes: 2 additions & 1 deletion scheme/libraries/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ public function __construct()
* @param int $rows_per_page
* @param int $page_num
*/
public function initialize($total_rows, $rows_per_page, $page_num, $url, $crumbs = 5)
public function initialize($table, $rows_per_page, $page_num, $url, $crumbs = 5)
{
$total_rows = $this->LAVA->db->table($table)->select_count('*', 'count')->get()['count'];
$this->crumbs = $crumbs;
$this->rows_per_page = (int) $rows_per_page;
$this->page_array['url'] = $url;
Expand Down

0 comments on commit 13ebc5b

Please sign in to comment.