PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.1.1
Kirki – Freeform Page Builder, Website Builder & Customizer v6.1.1
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 / PageContentResource.php
kirki / app / Resources Last commit date
CollaborationComment 2 weeks ago Collection 2 weeks ago CollectionItem 2 weeks ago Media 2 weeks ago PageContentResource.php 2 days ago PageResource.php 2 days ago PageSettingsResource.php 2 weeks ago SymbolResource.php 2 weeks ago
PageContentResource.php
81 lines
1 <?php
2
3 namespace Kirki\App\Resources;
4
5 defined('ABSPATH') || exit;
6
7 use Kirki\App\Constants\PageMetaKeys;
8 use Kirki\App\Models\Page as PageModel;
9 use Kirki\App\Supports\Facades\Page;
10 use Kirki\App\Supports\PageUrl;
11 use Kirki\App\Utils\PostUtil;
12 use Kirki\Framework\Database\Query\QueryBuilder;
13 use Kirki\Framework\Resource;
14
15 class PageContentResource extends Resource
16 {
17 /** @var string */
18 protected $stage_block_key;
19
20 /** @var int|false */
21 protected $stage_version = false;
22
23 /**
24 * PageContentResource constructor.
25 *
26 * @param PageModel $page
27 * @param int|false $stage_version
28 */
29 public function __construct(PageModel $page, $stage_version = false)
30 {
31 $page_id = $page->ID;
32
33 if (!$stage_version) {
34 $stage_version = Page::get_most_recent_stage_version($page_id, false);
35 }
36
37 $this->stage_version = $stage_version;
38
39 $this->stage_block_key = Page::get_staged_meta_name(PageMetaKeys::BLOCKS, $page_id, $stage_version);
40
41 $page->load_missing([
42 'meta' => function (QueryBuilder $query) use ($page_id) {
43 $query->where_in('meta_key', [
44 PageMetaKeys::BLOCKS,
45 $this->stage_block_key
46 ]);
47 }
48 ]);
49
50 parent::__construct($page);
51 }
52 /**
53 * Convert the collection resource to an array.
54 *
55 * @return array The collection data as an associative array.
56 */
57 public function to_array()
58 {
59 $page_url = PageUrl::create($this->resource);
60
61 $meta = isset($this->meta) ? $this->meta->pluck('meta_value', 'meta_key')->to_array() : [];
62
63 $content = get_the_content(null, false, PostUtil::get_wp_post($this->resource));
64
65 $blocks = !empty($meta[PageMetaKeys::BLOCKS]) ? $meta[PageMetaKeys::BLOCKS] : [];
66
67 if ($this->stage_version) {
68 $blocks = !empty($meta[$this->stage_block_key]) ? $meta[$this->stage_block_key] : [];
69 }
70
71 return [
72 'blocks' => !empty($blocks['blocks']) ? $blocks['blocks'] : null,
73 'content_length' => strlen($content),
74 'is_kirki_editor_mode' => Page::is_kirki_editor_mode($this->ID),
75 'preview_url' => $page_url->get_preview_url(),
76 'styles' => Page::get_page_styleblocks($this->ID, $this->stage_version),
77 'version_info' => Page::get_staged_version_info($this->ID, $this->stage_version),
78 ];
79 }
80 }
81