class-wizard-item.php
89 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Data\Utils\Wizard; |
| 4 | |
| 5 | use SuperbAddons\Admin\Controllers\Wizard\WizardTemplatePreviewController; |
| 6 | |
| 7 | defined('ABSPATH') || exit(); |
| 8 | |
| 9 | class WizardItem |
| 10 | { |
| 11 | public $id; |
| 12 | private $slug; |
| 13 | public $type; |
| 14 | public $datatype; |
| 15 | public $title; |
| 16 | public $permalink; |
| 17 | public $no_reload; |
| 18 | public $is_premium; |
| 19 | public $is_file_template; |
| 20 | public $is_restoration_point; |
| 21 | public $use_custom_page_template_preview; |
| 22 | public $plugin_update_required; |
| 23 | public $external_plugin_required; |
| 24 | public $required_plugin_names; |
| 25 | |
| 26 | public function __construct($template) |
| 27 | { |
| 28 | $this->id = isset($template->id) ? $template->id : false; |
| 29 | $this->slug = isset($template->slug) ? $template->slug : $this->id; |
| 30 | $this->type = isset($template->type) ? $template->type : false; |
| 31 | $this->datatype = isset($template->datatype) ? $template->datatype : $this->type; |
| 32 | if ($this->slug === 'front-page') { |
| 33 | $this->datatype = 'front-page'; |
| 34 | } |
| 35 | $this->title = isset($template->title) ? $template->title : false; |
| 36 | $this->permalink = isset($template->permalink) ? $template->permalink : get_home_url(); |
| 37 | $this->no_reload = isset($template->no_reload) ? $template->no_reload : false; |
| 38 | $this->is_premium = isset($template->is_premium) ? $template->is_premium : false; |
| 39 | $this->plugin_update_required = isset($template->plugin_update_required) && $template->plugin_update_required; |
| 40 | $this->external_plugin_required = isset($template->external_plugin_required) && $template->external_plugin_required; |
| 41 | $this->required_plugin_names = isset($template->required_plugin_names) ? $template->required_plugin_names : array(); |
| 42 | $this->is_file_template = false; |
| 43 | $this->is_restoration_point = false; |
| 44 | $this->use_custom_page_template_preview = isset($template->use_custom_page_template_preview) ? $template->use_custom_page_template_preview : 0; |
| 45 | } |
| 46 | |
| 47 | public function GetId() |
| 48 | { |
| 49 | if ($this->is_file_template) { |
| 50 | return $this->id . WizardItemIdAffix::FILE_TEMPLATE; |
| 51 | } |
| 52 | if ($this->is_restoration_point) { |
| 53 | return $this->id . WizardItemIdAffix::RESTORATION_POINT; |
| 54 | } |
| 55 | return $this->id; |
| 56 | } |
| 57 | |
| 58 | public function GetSlug() |
| 59 | { |
| 60 | if ($this->is_file_template) { |
| 61 | return $this->slug . WizardItemIdAffix::FILE_TEMPLATE; |
| 62 | } |
| 63 | if ($this->is_restoration_point) { |
| 64 | return $this->GetId(); |
| 65 | } |
| 66 | return $this->slug; |
| 67 | } |
| 68 | |
| 69 | public function GetBaseSlug() |
| 70 | { |
| 71 | return $this->slug; |
| 72 | } |
| 73 | |
| 74 | public function SetSlug($slug) |
| 75 | { |
| 76 | $this->slug = $slug; |
| 77 | } |
| 78 | |
| 79 | public function IsPattern() |
| 80 | { |
| 81 | return $this->type === WizardItemTypes::PATTERN || $this->type === WizardItemTypes::WP_TEMPLATE_PART; |
| 82 | } |
| 83 | |
| 84 | public function GetPreviewURL() |
| 85 | { |
| 86 | return add_query_arg(array(WizardTemplatePreviewController::TEMPLATE_PREVIEW_KEY => $this->GetId(), WizardTemplatePreviewController::TEMPLATE_TYPE_KEY => $this->type, WizardTemplatePreviewController::USE_PAGE_TEMPLATE_KEY => $this->use_custom_page_template_preview, 'superb-preview-time' => time()), $this->permalink); |
| 87 | } |
| 88 | } |
| 89 |