| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Class Pagination |
| 10 |
* |
| 11 |
* @package forge12\contactform7\CF7DoubleOptIn |
| 12 |
*/ |
| 13 |
class Pagination |
| 14 |
{ |
| 15 |
private static $_instance = null; |
| 16 |
|
| 17 |
public static function getInstance() |
| 18 |
{ |
| 19 |
if (null === self::$_instance) { |
| 20 |
self::$_instance = new Pagination(); |
| 21 |
} |
| 22 |
return self::$_instance; |
| 23 |
} |
| 24 |
|
| 25 |
private function __construct() |
| 26 |
{ |
| 27 |
// Add additional actions |
| 28 |
add_filter('f12_cf7_doubleoptin_pagination_link', array($this, 'buildLink'), 10, 2); |
| 29 |
} |
| 30 |
|
| 31 |
public function buildLink($link, $parameter = array()) |
| 32 |
{ |
| 33 |
/* |
| 34 |
* Default Parameter |
| 35 |
*/ |
| 36 |
$default = array( |
| 37 |
'perPage' => 10, |
| 38 |
'pageNum' => 1, |
| 39 |
); |
| 40 |
|
| 41 |
if(isset($_GET['perPage'])){ |
| 42 |
$default['perPage'] = (int)$_GET['perPage']; |
| 43 |
} |
| 44 |
|
| 45 |
if(isset($_GET['pageNum'])){ |
| 46 |
$default['pageNum'] = (int)$_GET['pageNum']; |
| 47 |
} |
| 48 |
|
| 49 |
if(isset($_GET['keyword'])){ |
| 50 |
$default['keyword'] = sanitize_text_field($_GET['keyword']); |
| 51 |
} |
| 52 |
|
| 53 |
if(isset($_GET['cf_form_id'])){ |
| 54 |
$default['cf_form_id'] = (int)$_GET['cf_form_id']; |
| 55 |
} |
| 56 |
|
| 57 |
$default = array_merge($default, $parameter); |
| 58 |
|
| 59 |
$default_keypair = array(); |
| 60 |
|
| 61 |
foreach ($default as $key => $value) { |
| 62 |
$default_keypair[] = $key . '=' . $value; |
| 63 |
} |
| 64 |
|
| 65 |
return $link . '?' . implode("&", $default_keypair); |
| 66 |
} |
| 67 |
} |
| 68 |
} |