PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.0
6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / app / Resources / PageResource.php
kirki / app / Resources Last commit date
CollaborationComment 1 month ago Collection 4 days ago CollectionItem 1 month ago Media 1 month ago PageContentResource.php 2 weeks ago PageResource.php 4 days ago PageSettingsResource.php 1 month ago SymbolResource.php 1 month ago
PageResource.php
80 lines
1 <?php
2
3 namespace Kirki\App\Resources;
4
5 defined('ABSPATH') || exit;
6
7 use Kirki\App\Constants\OptionKeys;
8 use Kirki\App\Constants\PageMetaKeys;
9 use Kirki\App\Constants\PostTypes;
10 use Kirki\App\Models\Page as PageModel;
11 use Kirki\App\Supports\Facades\Page;
12 use Kirki\App\Supports\PageUrl;
13 use Kirki\Framework\Database\Query\QueryBuilder;
14 use Kirki\Framework\Resource;
15 use Kirki\Framework\Supports\Facades\Option;
16
17 class PageResource extends Resource
18 {
19 public function __construct(PageModel $page)
20 {
21 $page->load_missing([
22 'meta' => function (QueryBuilder $query) {
23 $query->where_in('meta_key', PageMetaKeys::get_single_post_keys());
24 }
25 ]);
26
27 parent::__construct($page);
28 }
29 /**
30 * Convert the collection resource to an array.
31 *
32 * @return array The collection data as an associative array.
33 */
34 public function to_array()
35 {
36 $page_url = PageUrl::create($this->resource);
37
38 $meta = isset($this->meta) ? $this->meta->pluck('meta_value', 'meta_key')->to_array() : [];
39
40 $data = [
41 'id' => (int) $this->ID,
42 'title' => $this->post_title,
43 'status' => $this->post_status,
44 'post_type' => $this->post_type,
45 'post_parent' => (int) $this->post_parent,
46 'slug' => $this->post_name,
47 'variableMode' => Page::get_variable_mode($this->resource),
48 'isFrontPage' => Page::is_front_page((int) $this->ID),
49 'disabled_page_symbols' => $meta[PageMetaKeys::DISABLED_PAGE_SYMBOLS] ?? [],
50 'staged_last_updated' => $this->get_staged_last_updated(),
51 'preview_url' => $page_url->get_preview_url(),
52 'editor_url' => $page_url->get_editor_url(),
53 ];
54
55 if ($this->post_type === PostTypes::UTILITY) {
56 $data['utility_page_type'] = $meta[PageMetaKeys::UTILITY_PAGE_TYPE] ?? '';
57 }
58
59 if ($this->post_type === PostTypes::TEMPLATE) {
60 $data['conditions'] = $meta[PageMetaKeys::TEMPLATE_CONDITIONS] ?? [];
61 $data['collection_type'] = $meta[PageMetaKeys::TEMPLATE_COLLECTION_TYPE] ?? '';
62 }
63
64 if ($this->post_type === PostTypes::POPUP) {
65 $data['blocks'] = $meta[PageMetaKeys::BLOCKS] ?? [];
66 $data['styleBlocks'] = $meta[PageMetaKeys::STYLE_BLOCKS] ?? [];
67 $data['usedFonts'] = $meta[PageMetaKeys::USED_FONT_LIST] ?? [];
68 }
69
70 return $data;
71 }
72
73 protected function get_staged_last_updated()
74 {
75 $published_staged_info = Page::get_published_staged_version_info((int) $this->ID);
76
77 return isset($published_staged_info['last_updated']) ? $published_staged_info['last_updated'] : null;
78 }
79 }
80