PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / site-editor-views / Fields.php

Fields.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/site-editor-views/Fields.php

123 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The three provenance fields offered to the Pages screen (spec 054 FR-006).
4 *
5 * Field ids are namespaced `templately_*` deliberately. The host applies our
6 * patch by MERGING it key by key, so an id that collided with a core field id
7 * would silently redefine someone else's column rather than adding ours.
8 *
9 * PHP 7.2 SYNTAX ONLY.
10 *
11 * @package Templately
12 */
13
14 namespace Templately\Modules\SiteEditorViews;
15
16 defined( 'ABSPATH' ) || exit;
17
18 class Fields {
19
20 const FIELD_SOURCE = 'templately_source';
21 const FIELD_IMPORTED = 'templately_imported';
22 const FIELD_ORIGIN = 'templately_origin';
23
24 /**
25 * @var Provenance
26 */
27 protected $provenance;
28
29 public function __construct( Provenance $provenance ) {
30 $this->provenance = $provenance;
31 }
32
33 /**
34 * The field ids, in the order they should appear.
35 *
36 * @return string[]
37 */
38 public function ids(): array {
39 return [ self::FIELD_SOURCE, self::FIELD_IMPORTED, self::FIELD_ORIGIN ];
40 }
41
42 /**
43 * What to show for one item.
44 *
45 * Every value derives from the provenance record the screen has already
46 * fetched — no lookup per row, which is FR-013 and the reason SC-005 holds.
47 *
48 * @param int $id
49 * @param string $entity
50 * @return array<string, string> Field id => display value.
51 */
52 public function values_for( $id, $entity = 'post' ): array {
53 if ( ! $this->provenance->has( $id, $entity ) ) {
54 // Not ours. Empty, not "unknown" — a page someone wrote themselves
55 // should look untouched, not mislabelled (FR-011, US1 scenario 2).
56 return [
57 self::FIELD_SOURCE => '',
58 self::FIELD_IMPORTED => '',
59 self::FIELD_ORIGIN => '',
60 ];
61 }
62
63 return [
64 self::FIELD_SOURCE => $this->source_label( $this->provenance->read( $id, Provenance::KEY_PACK, $entity ) ),
65 self::FIELD_IMPORTED => $this->provenance->read( $id, Provenance::KEY_IMPORTED_AT, $entity ),
66 self::FIELD_ORIGIN => $this->origin_label( $this->provenance->read( $id, Provenance::KEY_SOURCE, $entity ) ),
67 ];
68 }
69
70 /**
71 * "Templately", plus the pack when we can name it.
72 *
73 * The pack name can be unresolvable — an offline site, a pack since
74 * withdrawn. Then the field still says Templately rather than showing a bare
75 * identifier or an error, because "this came from Templately" is the useful
76 * part and the id means nothing to the reader (FR-012).
77 *
78 * @param string $pack_id
79 * @return string
80 */
81 public function source_label( $pack_id ): string {
82 $name = '';
83
84 if ( '' !== (string) $pack_id ) {
85 /**
86 * Filters the human-readable name for a pack id.
87 *
88 * @since 3.8.0
89 *
90 * @param string $name
91 * @param string $pack_id
92 */
93 $name = (string) apply_filters( 'templately_provenance_pack_name', '', $pack_id );
94 }
95
96 if ( '' === $name ) {
97 return __( 'Templately', 'templately' );
98 }
99
100 /* translators: %s: the name of the Templately pack the content came from. */
101 return sprintf( __( 'Templately — %s', 'templately' ), $name );
102 }
103
104 /**
105 * Generated, or curated.
106 *
107 * `cloud` and `curated` are both curated as far as a reader is concerned;
108 * only `ai` is generated.
109 *
110 * @param string $source
111 * @return string
112 */
113 public function origin_label( $source ): string {
114 if ( '' === (string) $source ) {
115 return '';
116 }
117
118 return Provenance::SOURCE_AI === $source
119 ? __( 'AI-generated', 'templately' )
120 : __( 'Curated', 'templately' );
121 }
122 }
123