Campaign.php
10 months ago
Campaign_Landing_Page.php
9 months ago
Campaign_UTM_Campaign.php
9 months ago
Campaign_UTM_Medium.php
9 months ago
Campaign_UTM_Source.php
9 months ago
ClickWhale_Link_Page.php
1 year ago
Device.php
10 months ago
Form.php
1 year ago
Geo.php
10 months ago
Journey.php
5 months ago
Link.php
8 months ago
Link_Pattern.php
10 months ago
Model.php
6 months ago
Page.php
4 days ago
Page_Author_Archive.php
2 years ago
Page_Date_Archive.php
2 years ago
Page_Home.php
2 years ago
Page_Not_Found.php
4 days ago
Page_Post_Type_Archive.php
1 year ago
Page_Search.php
2 years ago
Page_Singular.php
4 days ago
Page_Term_Archive.php
2 years ago
Page_Virtual.php
1 year ago
Referrer.php
6 months ago
Referrer_Type.php
9 months ago
Universal_Model_Columns.php
1 year ago
Visitor.php
9 months ago
Page_Singular.php
131 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Models; |
| 4 | |
| 5 | /** @internal */ |
| 6 | class Page_Singular extends \IAWP\Models\Page |
| 7 | { |
| 8 | private $singular_id; |
| 9 | private $comments; |
| 10 | public function __construct($row) |
| 11 | { |
| 12 | $this->singular_id = $row->singular_id; |
| 13 | $this->comments = $row->comments ?? 0; |
| 14 | parent::__construct($row); |
| 15 | } |
| 16 | /** |
| 17 | * Override comments method to add comments support for singular pages. |
| 18 | * |
| 19 | * @return int|null |
| 20 | */ |
| 21 | public function comments() : ?int |
| 22 | { |
| 23 | return $this->comments; |
| 24 | } |
| 25 | protected function resource_key() : string |
| 26 | { |
| 27 | return 'singular_id'; |
| 28 | } |
| 29 | protected function resource_value() : string |
| 30 | { |
| 31 | return $this->singular_id; |
| 32 | } |
| 33 | protected function calculate_is_deleted() : bool |
| 34 | { |
| 35 | $post = \get_post($this->singular_id); |
| 36 | return \is_null($post) || \is_null(\get_post_type_object($post->post_type)); |
| 37 | } |
| 38 | protected function calculate_url() |
| 39 | { |
| 40 | return $this->convert_wpml_url(\get_permalink($this->singular_id)); |
| 41 | } |
| 42 | protected function calculate_title() |
| 43 | { |
| 44 | return \get_the_title($this->singular_id); |
| 45 | } |
| 46 | protected function calculate_type() |
| 47 | { |
| 48 | $post_type_object = \get_post_type_object(\get_post_type($this->singular_id)); |
| 49 | if (\is_null($post_type_object)) { |
| 50 | return null; |
| 51 | } |
| 52 | return $post_type_object->name; |
| 53 | } |
| 54 | protected function calculate_type_label() |
| 55 | { |
| 56 | $post_type_object = \get_post_type_object(\get_post_type($this->singular_id)); |
| 57 | if (\is_null($post_type_object)) { |
| 58 | return null; |
| 59 | } |
| 60 | return $post_type_object->labels->singular_name; |
| 61 | } |
| 62 | protected function calculate_icon() |
| 63 | { |
| 64 | $icon = null; |
| 65 | if (!$this->calculate_is_deleted()) { |
| 66 | $icon = \get_post_type_object($this->type(\true))->menu_icon; |
| 67 | } |
| 68 | $has_icon = !\is_null($icon); |
| 69 | $html = '<div class="post-type-icon">'; |
| 70 | if ($has_icon) { |
| 71 | if (\esc_url_raw($icon) == $icon) { |
| 72 | if (\str_contains($icon, 'svg')) { |
| 73 | $html .= '<span class="custom-icon" style="display: block;-webkit-mask: url(' . \esc_url($icon) . ') no-repeat center;mask: url(' . \esc_url($icon) . ') no-repeat center;"></span>'; |
| 74 | } else { |
| 75 | $html .= '<span><img src="' . \esc_url($icon) . '" width="20px" height="20px" /></span>'; |
| 76 | } |
| 77 | } else { |
| 78 | $html .= '<span class="dashicons ' . \esc_attr($icon) . '"></span>'; |
| 79 | } |
| 80 | } else { |
| 81 | $html .= '<span class="dashicons dashicons-admin-post"></span>'; |
| 82 | } |
| 83 | $html .= '</div>'; |
| 84 | return $html; |
| 85 | } |
| 86 | protected function calculate_author_id() |
| 87 | { |
| 88 | $author_id = \get_post_field('post_author', $this->singular_id); |
| 89 | if ($author_id === '') { |
| 90 | return null; |
| 91 | } |
| 92 | return $author_id; |
| 93 | } |
| 94 | protected function calculate_author() |
| 95 | { |
| 96 | return \get_the_author_meta('display_name', $this->author_id()); |
| 97 | } |
| 98 | protected function calculate_avatar() |
| 99 | { |
| 100 | return \get_avatar($this->author_id(), 20); |
| 101 | } |
| 102 | protected function calculate_date() |
| 103 | { |
| 104 | $date = \get_the_date('Y-m-d', $this->singular_id); |
| 105 | if (!\is_string($date)) { |
| 106 | return null; |
| 107 | } |
| 108 | return $date; |
| 109 | } |
| 110 | protected function calculate_category() |
| 111 | { |
| 112 | $post_type_still_registered = \in_array($this->calculate_type(), \get_post_types()); |
| 113 | $categories = []; |
| 114 | if (!$post_type_still_registered) { |
| 115 | return []; |
| 116 | } |
| 117 | foreach (\get_the_category($this->singular_id) as $category) { |
| 118 | $categories[] = $category->term_id; |
| 119 | } |
| 120 | return $categories; |
| 121 | } |
| 122 | protected function convert_wpml_url($permalink) |
| 123 | { |
| 124 | if (\is_plugin_active('sitepress-multilingual-cms/sitepress.php')) { |
| 125 | $language = \apply_filters('wpml_post_language_details', null, $this->singular_id); |
| 126 | $permalink = \apply_filters('wpml_permalink', $permalink, $language['language_code'], \true); |
| 127 | } |
| 128 | return $permalink; |
| 129 | } |
| 130 | } |
| 131 |