| 1 |
<?php |
| 2 |
/** |
| 3 |
* Declare class Page |
| 4 |
* |
| 5 |
* @package Page |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace LassoLite\Classes; |
| 9 |
|
| 10 |
use LassoLite\Admin\Constant; |
| 11 |
|
| 12 |
use LassoLite\Classes\Helper; |
| 13 |
|
| 14 |
/** |
| 15 |
* Page |
| 16 |
*/ |
| 17 |
class Page { |
| 18 |
|
| 19 |
/** |
| 20 |
* Title |
| 21 |
* |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
public $title; |
| 25 |
|
| 26 |
/** |
| 27 |
* Slug |
| 28 |
* |
| 29 |
* @var string |
| 30 |
*/ |
| 31 |
public $slug; |
| 32 |
|
| 33 |
/** |
| 34 |
* Template |
| 35 |
* |
| 36 |
* @var string |
| 37 |
*/ |
| 38 |
public $template; |
| 39 |
|
| 40 |
/** |
| 41 |
* Active css class |
| 42 |
* |
| 43 |
* @var string |
| 44 |
*/ |
| 45 |
public $active_class; |
| 46 |
|
| 47 |
/** |
| 48 |
* Page constructor. |
| 49 |
* |
| 50 |
* @param string $title Title. |
| 51 |
* @param string $slug Slug. |
| 52 |
* @param string $template Templage. |
| 53 |
*/ |
| 54 |
public function __construct( $title, $slug, $template ) { |
| 55 |
$page = Helper::GET()['page'] ?? ''; // phpcs:ignore |
| 56 |
|
| 57 |
$this->title = $title; |
| 58 |
$this->slug = SIMPLE_URLS_SLUG . '-' . $slug; |
| 59 |
$this->template = $template; |
| 60 |
$this->active_class = $this->slug === $page ? 'active' : ''; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Get Lasso Lite page URL |
| 65 |
* |
| 66 |
* @param string $slug Page slug. |
| 67 |
*/ |
| 68 |
public static function get_page_url( $slug = '' ) { |
| 69 |
if ( empty( $slug ) ) { |
| 70 |
return admin_url( 'edit.php?post_type=' . SIMPLE_URLS_SLUG ); |
| 71 |
} |
| 72 |
|
| 73 |
$page_url = add_query_arg( |
| 74 |
array( |
| 75 |
'post_type' => Constant::LASSO_POST_TYPE, |
| 76 |
'page' => $slug, |
| 77 |
), |
| 78 |
self_admin_url( 'edit.php' ) |
| 79 |
); |
| 80 |
|
| 81 |
return $page_url; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Get Lasso Lite page URL without prefix |
| 86 |
* |
| 87 |
* @param string $slug Page slug. |
| 88 |
*/ |
| 89 |
public static function get_lite_page_url( $slug = '' ) { |
| 90 |
if ( empty( $slug ) ) { |
| 91 |
return admin_url( 'edit.php?post_type=' . SIMPLE_URLS_SLUG ); |
| 92 |
} |
| 93 |
|
| 94 |
$slug = Helper::add_prefix_page( $slug ); |
| 95 |
|
| 96 |
return self::get_page_url( $slug ); |
| 97 |
} |
| 98 |
} |
| 99 |
|