@wp-operations/wp-ops 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -27
- package/bin/wp-app.js +2 -0
- package/bin/wp-code.js +2 -0
- package/bin/wp-ide.js +2 -0
- package/package.json +12 -3
- package/src/commands/platform.js +16 -2
- package/src/commands/sandbox.js +3 -3
- package/src/main.js +10 -4
- package/wp-operations/CHANGELOG.md +14 -0
- package/wp-operations/README.md +39 -0
- package/wp-operations/agents/builder/AGENT.md +15 -0
- package/wp-operations/assets/admin.css +631 -0
- package/wp-operations/assets/admin.js +614 -0
- package/wp-operations/assets/app/app.css +1 -0
- package/wp-operations/assets/app/app.js +70 -0
- package/wp-operations/assets/app/fonts/inter-medium.woff +0 -0
- package/wp-operations/assets/app/fonts/inter-regular.woff +0 -0
- package/wp-operations/assets/app/fonts/inter-semibold.woff +0 -0
- package/wp-operations/assets/app/login.css +42 -0
- package/wp-operations/assets/brand/icon.svg +20 -0
- package/wp-operations/assets/brand/mark.svg +19 -0
- package/wp-operations/assets/editors/audiobook.css +311 -0
- package/wp-operations/assets/editors/audiofile.css +286 -0
- package/wp-operations/assets/editors/course.css +701 -0
- package/wp-operations/assets/editors/course.js +698 -0
- package/wp-operations/assets/editors/faq.css +258 -0
- package/wp-operations/assets/editors/faq.js +196 -0
- package/wp-operations/assets/editors/interactive.css +220 -0
- package/wp-operations/assets/editors/interactive.js +378 -0
- package/wp-operations/assets/editors/media-sources.css +3 -0
- package/wp-operations/assets/editors/media-sources.js +40 -0
- package/wp-operations/assets/editors/open-media.css +114 -0
- package/wp-operations/assets/editors/open-media.js +182 -0
- package/wp-operations/assets/editors/thumbnails.css +335 -0
- package/wp-operations/assets/editors/thumbnails.js +447 -0
- package/wp-operations/assets/editors/translator.css +818 -0
- package/wp-operations/functions.php +24 -0
- package/wp-operations/index.php +14 -0
- package/wp-operations/platform.json +1836 -0
- package/wp-operations/skills/ai-development-guardrails/SKILL.md +49 -0
- package/wp-operations/skills/gutenberg-reference/SKILL.md +45 -0
- package/wp-operations/skills/js-tooling-for-themes/SKILL.md +51 -0
- package/wp-operations/skills/tailwind-for-wp/SKILL.md +62 -0
- package/wp-operations/skills/wp-clean-classic-themes/SKILL.md +112 -0
- package/wp-operations/skills/wp-psr4-plugins/SKILL.md +2043 -0
- package/wp-operations/skills/wp-security/SKILL.md +90 -0
- package/wp-operations/src/Admin.php +78 -0
- package/wp-operations/src/App/Access.php +57 -0
- package/wp-operations/src/App/Admin.php +442 -0
- package/wp-operations/src/App/App.php +157 -0
- package/wp-operations/src/App/Apps.php +379 -0
- package/wp-operations/src/App/Bundle.php +111 -0
- package/wp-operations/src/App/Contents.php +676 -0
- package/wp-operations/src/App/Engine.php +554 -0
- package/wp-operations/src/App/Github.php +308 -0
- package/wp-operations/src/App/Module.php +23 -0
- package/wp-operations/src/App/Ops.php +470 -0
- package/wp-operations/src/App/Packages.php +289 -0
- package/wp-operations/src/App/Rest.php +539 -0
- package/wp-operations/src/App/Sandboxes.php +206 -0
- package/wp-operations/src/App/Store.php +104 -0
- package/wp-operations/src/App/Usage.php +268 -0
- package/wp-operations/src/Config.php +249 -0
- package/wp-operations/src/Content/Editor.php +223 -0
- package/wp-operations/src/Content/Fields.php +681 -0
- package/wp-operations/src/Content/Scoring.php +253 -0
- package/wp-operations/src/Content/Structure.php +293 -0
- package/wp-operations/src/Content/Types.php +150 -0
- package/wp-operations/src/Content/Uploads.php +50 -0
- package/wp-operations/src/Editors/AudiobookAuthor.php +61 -0
- package/wp-operations/src/Editors/AudiobookChapters.php +632 -0
- package/wp-operations/src/Editors/AudiobookCover.php +235 -0
- package/wp-operations/src/Editors/Audiofile.php +462 -0
- package/wp-operations/src/Editors/Course.php +784 -0
- package/wp-operations/src/Editors/Ebook.php +242 -0
- package/wp-operations/src/Editors/Editors.php +44 -0
- package/wp-operations/src/Editors/Faq.php +237 -0
- package/wp-operations/src/Editors/Files.php +139 -0
- package/wp-operations/src/Editors/Interactive/Builder.php +103 -0
- package/wp-operations/src/Editors/Interactive/Card.php +76 -0
- package/wp-operations/src/Editors/Interactive/Editor.php +42 -0
- package/wp-operations/src/Editors/Interactive/Field.php +272 -0
- package/wp-operations/src/Editors/Interactive/Map.php +84 -0
- package/wp-operations/src/Editors/Interactive/Models.php +227 -0
- package/wp-operations/src/Editors/Interactive/Report.php +59 -0
- package/wp-operations/src/Editors/Interactive/Save.php +323 -0
- package/wp-operations/src/Editors/Interactive/Scoring.php +244 -0
- package/wp-operations/src/Editors/Interactive/Structure.php +195 -0
- package/wp-operations/src/Editors/Legal.php +235 -0
- package/wp-operations/src/Editors/OpenMedia.php +140 -0
- package/wp-operations/src/Editors/OriginalTitle.php +112 -0
- package/wp-operations/src/Editors/Sources.php +28 -0
- package/wp-operations/src/Editors/Thumbnails/Admin.php +306 -0
- package/wp-operations/src/Editors/Thumbnails/Ajax.php +163 -0
- package/wp-operations/src/Editors/Thumbnails/Box.php +188 -0
- package/wp-operations/src/Editors/Thumbnails/Storage.php +228 -0
- package/wp-operations/src/Editors/Translator/Admin.php +913 -0
- package/wp-operations/src/Editors/Translator/Api.php +63 -0
- package/wp-operations/src/Editors/Translator/Bar.php +83 -0
- package/wp-operations/src/Editors/Translator/Fields.php +273 -0
- package/wp-operations/src/Editors/Translator/Storage.php +131 -0
- package/wp-operations/src/Editors/Translator/Thumbnail.php +215 -0
- package/wp-operations/src/Identity.php +104 -0
- package/wp-operations/src/Languages.php +45 -0
- package/wp-operations/src/Lockdown.php +85 -0
- package/wp-operations/src/Modules/Apps/Admin.php +472 -0
- package/wp-operations/src/Modules/Apps/Api.php +193 -0
- package/wp-operations/src/Modules/Apps/Apps.php +279 -0
- package/wp-operations/src/Modules/Apps/Formatters.php +478 -0
- package/wp-operations/src/Modules/Apps/Schemes.php +248 -0
- package/wp-operations/src/Modules/Apps/Table.php +101 -0
- package/wp-operations/src/Modules/Thumbnails.php +68 -0
- package/wp-operations/src/Modules/Translations.php +133 -0
- package/wp-operations/src/Platform.php +59 -0
- package/wp-operations/src/Setup.php +273 -0
- package/wp-operations/src/Status.php +99 -0
- package/wp-operations/src/Storage/Client.php +168 -0
- package/wp-operations/src/Storage/Offload.php +120 -0
- package/wp-operations/src/Storage/Settings.php +166 -0
- package/wp-operations/src/Storage/Storage.php +35 -0
- package/wp-operations/src/Updates.php +151 -0
- package/wp-operations/style.css +11 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Response shapes for the content API, chosen per content type with "api.format".
|
|
4
|
+
*
|
|
5
|
+
* @package Platform
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
namespace Platform\Modules\Apps;
|
|
9
|
+
|
|
10
|
+
use Platform\Config;
|
|
11
|
+
use Platform\Content\Fields;
|
|
12
|
+
use Platform\Languages;
|
|
13
|
+
use Platform\Modules\Thumbnails;
|
|
14
|
+
|
|
15
|
+
defined( 'ABSPATH' ) || exit;
|
|
16
|
+
|
|
17
|
+
final class Formatters {
|
|
18
|
+
|
|
19
|
+
const LANGUAGE = 'en';
|
|
20
|
+
|
|
21
|
+
public static function handle( array $type, string $name, array $response, array $client ): array {
|
|
22
|
+
$api = $type['api'];
|
|
23
|
+
$format = (string) $api['format'];
|
|
24
|
+
$key = (string) ( $api['data_key'] ?? $name );
|
|
25
|
+
|
|
26
|
+
if ( 'legal' === $format ) {
|
|
27
|
+
$response['data'][ $key ] = self::legal( $type, $client );
|
|
28
|
+
return $response;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if ( 'faq' === $format ) {
|
|
32
|
+
$response['data'][ $key ] = self::faq( $type, $client );
|
|
33
|
+
return $response;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
$config = (array) ( $client['contents'][ $name ] ?? [] );
|
|
37
|
+
$ids = self::resolve_ids( $type['key'], $config );
|
|
38
|
+
|
|
39
|
+
if ( ! $ids ) {
|
|
40
|
+
$response['data'][ $key ] = [];
|
|
41
|
+
return $response;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
$allowed = self::allowed_terms( $config );
|
|
45
|
+
$query = new \WP_Query(
|
|
46
|
+
[
|
|
47
|
+
'post_type' => $type['key'],
|
|
48
|
+
'post_status' => 'publish',
|
|
49
|
+
'posts_per_page' => -1,
|
|
50
|
+
'no_found_rows' => true,
|
|
51
|
+
'post__in' => $ids,
|
|
52
|
+
'orderby' => 'post__in',
|
|
53
|
+
]
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
$method = in_array( $format, [ 'course', 'audiobook', 'audiofile', 'ebook', 'interactive' ], true ) ? $format : 'item';
|
|
57
|
+
$data = [];
|
|
58
|
+
|
|
59
|
+
foreach ( $query->posts as $post ) {
|
|
60
|
+
$data[] = self::$method( $post, $type, $client, $allowed );
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
$response['data'][ $key ] = $data;
|
|
64
|
+
|
|
65
|
+
return $response;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* ---------------------------------------------------------------- formats */
|
|
69
|
+
|
|
70
|
+
private static function course( \WP_Post $post, array $type, array $client, array $allowed ): array {
|
|
71
|
+
$api = $type['api'];
|
|
72
|
+
|
|
73
|
+
return self::base( $post, $client ) + [
|
|
74
|
+
'level' => get_post_meta( $post->ID, (string) ( $api['level'] ?? 'course_level' ), true ) ?: 'beginner',
|
|
75
|
+
'tags' => self::term_names( $post->ID, (string) ( $api['tags'] ?? 'course-tag' ), $allowed ),
|
|
76
|
+
'categories' => self::term_names( $post->ID, (string) ( $api['categories'] ?? 'course-category' ), $allowed ),
|
|
77
|
+
'video' => self::video( get_post_meta( $post->ID, ( $api['video'] ?? 'video' ) . '_' . self::LANGUAGE, true ) ),
|
|
78
|
+
'topics' => self::course_topics( $post->ID, $type ),
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private static function course_topics( int $course_id, array $type ): array {
|
|
83
|
+
$topic_type = Config::type( $type['children'] );
|
|
84
|
+
$lesson_type = $topic_type ? Config::type( $topic_type['children'] ) : [];
|
|
85
|
+
$video_key = (string) ( $type['api']['lesson_video'] ?? '_video' );
|
|
86
|
+
$preview_key = (string) ( $type['api']['preview'] ?? '_is_preview' );
|
|
87
|
+
$topics = [];
|
|
88
|
+
|
|
89
|
+
if ( ! $topic_type || ! $lesson_type ) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
foreach ( self::children( $course_id, $topic_type['key'], 'any' ) as $topic ) {
|
|
94
|
+
$lessons = [];
|
|
95
|
+
|
|
96
|
+
foreach ( self::children( $topic->ID, $lesson_type['key'], 'any' ) as $lesson ) {
|
|
97
|
+
$raw = get_post_meta( $lesson->ID, $video_key . '_' . self::LANGUAGE, true ) ?: get_post_meta( $lesson->ID, $video_key, true );
|
|
98
|
+
|
|
99
|
+
$lessons[] = [
|
|
100
|
+
'id' => $lesson->ID,
|
|
101
|
+
'title' => get_the_title( $lesson ),
|
|
102
|
+
'content' => apply_filters( 'the_content', $lesson->post_content ),
|
|
103
|
+
'is_preview' => (bool) get_post_meta( $lesson->ID, $preview_key, true ),
|
|
104
|
+
'video' => self::video( $raw ),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
$topics[] = [
|
|
109
|
+
'id' => $topic->ID,
|
|
110
|
+
'title' => get_the_title( $topic ),
|
|
111
|
+
'content' => apply_filters( 'the_content', $topic->post_content ),
|
|
112
|
+
'lessons' => $lessons,
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return $topics;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private static function audiobook( \WP_Post $post, array $type, array $client, array $allowed ): array {
|
|
120
|
+
$api = $type['api'];
|
|
121
|
+
$base = self::base( $post, $client );
|
|
122
|
+
$chapters = [];
|
|
123
|
+
$cover = get_post_meta( $post->ID, ( $api['cover'] ?? '_audiobook_cover_image' ) . '_' . self::LANGUAGE, true );
|
|
124
|
+
|
|
125
|
+
$base['thumbnail'] = Thumbnails::resolve( $post->ID, $client )
|
|
126
|
+
?: ( $cover ? wp_get_attachment_image_url( (int) $cover, 'large' ) : '' )
|
|
127
|
+
?: null;
|
|
128
|
+
|
|
129
|
+
$rows = get_post_meta( $post->ID, (string) ( $api['chapters'] ?? '_audiobook_chapters' ), true );
|
|
130
|
+
|
|
131
|
+
foreach ( is_array( $rows ) ? $rows : [] as $row ) {
|
|
132
|
+
$audio = self::audio( $row );
|
|
133
|
+
$chapters[] = [
|
|
134
|
+
'title' => $row['title'] ?? '',
|
|
135
|
+
'description' => $row['description'] ?? '',
|
|
136
|
+
'audio_url' => $audio['audio_url'],
|
|
137
|
+
'duration' => $audio['duration'],
|
|
138
|
+
'allow_download' => ! empty( $row['allow_download'] ),
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return $base + [
|
|
143
|
+
'author' => get_post_meta( $post->ID, (string) ( $api['author'] ?? '_audiobook_author_name' ), true ),
|
|
144
|
+
'original_title' => get_post_meta( $post->ID, (string) ( $api['original_title'] ?? '_original_title' ), true ),
|
|
145
|
+
'tags' => self::term_names( $post->ID, (string) ( $api['tags'] ?? 'book_tag' ), $allowed ),
|
|
146
|
+
'categories' => self::term_names( $post->ID, (string) ( $api['categories'] ?? 'book_category' ), $allowed ),
|
|
147
|
+
'chapters' => $chapters,
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private static function audiofile( \WP_Post $post, array $type, array $client, array $allowed ): array {
|
|
152
|
+
$api = $type['api'];
|
|
153
|
+
$meta = get_post_meta( $post->ID, (string) ( $api['audio'] ?? '_audiofile_data' ), true );
|
|
154
|
+
$audio = self::audio( is_array( $meta ) ? $meta : [] );
|
|
155
|
+
|
|
156
|
+
return self::base( $post, $client ) + [
|
|
157
|
+
'categories' => self::term_names( $post->ID, (string) ( $api['categories'] ?? 'audiofile_category' ), $allowed ),
|
|
158
|
+
'tags' => self::term_names( $post->ID, (string) ( $api['tags'] ?? 'audiofile_tag' ), $allowed ),
|
|
159
|
+
'audio_url' => $audio['audio_url'],
|
|
160
|
+
'duration' => $audio['duration'],
|
|
161
|
+
'allow_download' => ! empty( $meta['allow_download'] ),
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private static function ebook( \WP_Post $post, array $type, array $client, array $allowed ): array {
|
|
166
|
+
$api = $type['api'];
|
|
167
|
+
$urls = get_post_meta( $post->ID, (string) ( $api['pdf'] ?? '_ebook_pdf_urls' ), true );
|
|
168
|
+
$global = get_post_meta( $post->ID, (string) ( $api['download'] ?? '_ebook_allow_download' ), true );
|
|
169
|
+
$legacy = get_post_meta( $post->ID, '_ebook_allow_downloads', true );
|
|
170
|
+
$pdf = is_array( $urls ) ? ( $urls[ self::LANGUAGE ] ?? ( reset( $urls ) ?: '' ) ) : '';
|
|
171
|
+
|
|
172
|
+
if ( '' !== $global ) {
|
|
173
|
+
$download = (bool) $global;
|
|
174
|
+
} else {
|
|
175
|
+
$download = is_array( $legacy ) && ! empty( $legacy[ self::LANGUAGE ] );
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return self::base( $post, $client ) + [
|
|
179
|
+
'tags' => self::term_names( $post->ID, (string) ( $api['tags'] ?? 'course-tag' ), $allowed ),
|
|
180
|
+
'categories' => self::term_names( $post->ID, (string) ( $api['categories'] ?? 'course-category' ), $allowed ),
|
|
181
|
+
'pdf_url' => $pdf,
|
|
182
|
+
'allow_download' => $download,
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private static function interactive( \WP_Post $post, array $type, array $client, array $allowed ): array {
|
|
187
|
+
$api = $type['api'];
|
|
188
|
+
$parts = [];
|
|
189
|
+
$items_key = (string) ( $api['items'] ?? '_items' );
|
|
190
|
+
|
|
191
|
+
if ( '' !== $type['children'] ) {
|
|
192
|
+
foreach ( self::children( $post->ID, $type['children'], 'publish' ) as $child ) {
|
|
193
|
+
$part = [
|
|
194
|
+
'id' => $child->ID,
|
|
195
|
+
'title' => get_the_title( $child ),
|
|
196
|
+
'prompt' => (string) get_post_meta( $child->ID, '_prompt', true ),
|
|
197
|
+
'items' => self::rows( $child->ID, $items_key ),
|
|
198
|
+
];
|
|
199
|
+
|
|
200
|
+
if ( ! empty( $api['staged'] ) ) {
|
|
201
|
+
$part['screen'] = (string) ( get_post_meta( $child->ID, '_section_type', true ) ?: 'items' );
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
$parts[] = $part;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return self::base( $post, $client ) + [
|
|
209
|
+
'categories' => self::all_term_names( $post->ID, $type['key'], $allowed ),
|
|
210
|
+
'icon' => (string) get_post_meta( $post->ID, '_icon', true ),
|
|
211
|
+
'minutes' => self::number( get_post_meta( $post->ID, '_minutes', true ) ),
|
|
212
|
+
'rating' => self::number( get_post_meta( $post->ID, '_rating', true ) ),
|
|
213
|
+
'reviews' => self::number( get_post_meta( $post->ID, '_reviews', true ) ),
|
|
214
|
+
'unlock' => (string) ( get_post_meta( $post->ID, '_unlock', true ) ?: 'open' ),
|
|
215
|
+
'intro_points' => self::rows( $post->ID, '_intro_points' ),
|
|
216
|
+
'scoring' => [
|
|
217
|
+
'model' => (string) get_post_meta( $post->ID, '_algorithm', true ),
|
|
218
|
+
'params' => self::rows( $post->ID, '_algorithm_params' ),
|
|
219
|
+
'scales' => self::rows( $post->ID, '_scales' ),
|
|
220
|
+
'subscales' => self::rows( $post->ID, '_subscales' ),
|
|
221
|
+
'outcomes' => self::rows( $post->ID, '_outcomes' ),
|
|
222
|
+
'axes' => self::rows( $post->ID, '_axes' ),
|
|
223
|
+
'types' => self::rows( $post->ID, '_types' ),
|
|
224
|
+
'mix' => self::rows( $post->ID, '_mix' ),
|
|
225
|
+
'bands' => self::rows( $post->ID, '_bands' ),
|
|
226
|
+
],
|
|
227
|
+
'parts' => $parts,
|
|
228
|
+
'report' => self::rows( $post->ID, '_report' ),
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private static function item( \WP_Post $post, array $type, array $client, array $allowed ): array {
|
|
233
|
+
Fields::use_languages( Languages::for_type( $type['key'] ) );
|
|
234
|
+
|
|
235
|
+
$fields = array_filter( $type['fields'], static fn( array $field ): bool => ! empty( $field['api'] ) );
|
|
236
|
+
|
|
237
|
+
return self::base( $post, $client ) + [
|
|
238
|
+
'categories' => self::all_term_names( $post->ID, $type['key'], $allowed ),
|
|
239
|
+
'fields' => Fields::values( 'post', $post->ID, $fields ),
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private static function legal( array $type, array $client ): array {
|
|
244
|
+
$link = (string) ( $type['api']['link'] ?? '' );
|
|
245
|
+
$term_id = (int) ( $client['links'][ $link ] ?? 0 );
|
|
246
|
+
$taxonomy = (string) ( Apps::links()[ $link ]['taxonomy'] ?? '' );
|
|
247
|
+
$title = (string) ( $type['api']['title_taxonomy'] ?? 'legal_doc_type' );
|
|
248
|
+
|
|
249
|
+
if ( ! $term_id || '' === $taxonomy ) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
$query = new \WP_Query(
|
|
254
|
+
[
|
|
255
|
+
'post_type' => $type['key'],
|
|
256
|
+
'post_status' => 'publish',
|
|
257
|
+
'posts_per_page' => -1,
|
|
258
|
+
'no_found_rows' => true,
|
|
259
|
+
'tax_query' => [
|
|
260
|
+
[
|
|
261
|
+
'taxonomy' => $taxonomy,
|
|
262
|
+
'field' => 'term_id',
|
|
263
|
+
'terms' => $term_id,
|
|
264
|
+
],
|
|
265
|
+
],
|
|
266
|
+
]
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
$data = [];
|
|
270
|
+
|
|
271
|
+
foreach ( $query->posts as $post ) {
|
|
272
|
+
$terms = wp_get_post_terms( $post->ID, $title );
|
|
273
|
+
$term = ! empty( $terms ) && ! is_wp_error( $terms ) ? $terms[0] : null;
|
|
274
|
+
|
|
275
|
+
$data[] = [
|
|
276
|
+
'id' => $post->ID,
|
|
277
|
+
'title' => $term ? $term->name : get_the_title( $post ),
|
|
278
|
+
'slug' => $term ? $term->slug : $post->post_name,
|
|
279
|
+
'content' => apply_filters( 'the_content', $post->post_content ),
|
|
280
|
+
];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return $data;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private static function faq( array $type, array $client ): ?array {
|
|
287
|
+
$id = (int) ( $client['links'][ (string) ( $type['api']['link'] ?? '' ) ] ?? 0 );
|
|
288
|
+
$post = $id ? get_post( $id ) : null;
|
|
289
|
+
|
|
290
|
+
if ( ! $post || 'publish' !== $post->post_status || $post->post_type !== $type['key'] ) {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
$normalize = static fn( $rows ): array => array_values(
|
|
295
|
+
array_filter(
|
|
296
|
+
array_map(
|
|
297
|
+
static fn( $row ): array => [
|
|
298
|
+
'title' => sanitize_text_field( $row['title'] ?? '' ),
|
|
299
|
+
'content' => wp_kses_post( $row['content'] ?? '' ),
|
|
300
|
+
],
|
|
301
|
+
is_array( $rows ) ? $rows : []
|
|
302
|
+
),
|
|
303
|
+
static fn( array $row ): bool => '' !== $row['title'] || '' !== $row['content']
|
|
304
|
+
)
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
return [
|
|
308
|
+
'template_id' => $id,
|
|
309
|
+
'template_title' => get_the_title( $post ),
|
|
310
|
+
'page' => $normalize( get_post_meta( $id, '_faqt_page', true ) ),
|
|
311
|
+
'bot' => $normalize( get_post_meta( $id, '_faqt_bot', true ) ),
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/* ---------------------------------------------------------------- helpers */
|
|
316
|
+
|
|
317
|
+
private static function base( \WP_Post $post, array $client ): array {
|
|
318
|
+
return [
|
|
319
|
+
'id' => $post->ID,
|
|
320
|
+
'title' => get_the_title( $post ),
|
|
321
|
+
'slug' => $post->post_name,
|
|
322
|
+
'excerpt' => wp_strip_all_tags( get_the_excerpt( $post ) ),
|
|
323
|
+
'content' => apply_filters( 'the_content', $post->post_content ),
|
|
324
|
+
'date' => $post->post_date,
|
|
325
|
+
'modified' => $post->post_modified,
|
|
326
|
+
'thumbnail' => Thumbnails::resolve( $post->ID, $client ) ?: get_the_post_thumbnail_url( $post, 'large' ) ?: null,
|
|
327
|
+
];
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private static function video( $raw ): array {
|
|
331
|
+
while ( is_string( $raw ) && is_serialized( $raw ) ) {
|
|
332
|
+
$raw = maybe_unserialize( $raw );
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return wp_parse_args(
|
|
336
|
+
is_array( $raw ) ? $raw : [],
|
|
337
|
+
[
|
|
338
|
+
'source_type' => 'youtube',
|
|
339
|
+
'source' => '',
|
|
340
|
+
'runtime' => [
|
|
341
|
+
'hours' => '00',
|
|
342
|
+
'minutes' => '00',
|
|
343
|
+
'seconds' => '00',
|
|
344
|
+
],
|
|
345
|
+
]
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
private static function audio( array $value ): array {
|
|
350
|
+
$url = $value['audio_url'] ?? '';
|
|
351
|
+
$duration = $value['duration'] ?? '';
|
|
352
|
+
|
|
353
|
+
return [
|
|
354
|
+
'audio_url' => is_array( $url ) ? ( $url[ self::LANGUAGE ] ?? '' ) : (string) $url,
|
|
355
|
+
'duration' => is_array( $duration ) ? (string) ( $duration[ self::LANGUAGE ] ?? '0' ) : ( is_numeric( $duration ) || ( is_string( $duration ) && '' !== $duration ) ? (string) $duration : '0' ),
|
|
356
|
+
];
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
private static function children( int $parent_id, string $type, string $status ): array {
|
|
360
|
+
return get_posts(
|
|
361
|
+
[
|
|
362
|
+
'post_type' => $type,
|
|
363
|
+
'post_parent' => $parent_id,
|
|
364
|
+
'post_status' => $status,
|
|
365
|
+
'posts_per_page' => -1,
|
|
366
|
+
'orderby' => 'menu_order',
|
|
367
|
+
'order' => 'ASC',
|
|
368
|
+
'suppress_filters' => false,
|
|
369
|
+
]
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private static function rows( int $post_id, string $key ): array {
|
|
374
|
+
$value = get_post_meta( $post_id, $key, true );
|
|
375
|
+
|
|
376
|
+
return is_array( $value ) ? $value : [];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
private static function number( $value ) {
|
|
380
|
+
return is_numeric( $value ) ? $value + 0 : null;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
private static function term_names( int $post_id, string $taxonomy, array $allowed ): array {
|
|
384
|
+
$terms = wp_get_post_terms( $post_id, $taxonomy );
|
|
385
|
+
$names = [];
|
|
386
|
+
|
|
387
|
+
if ( is_wp_error( $terms ) ) {
|
|
388
|
+
return [];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
foreach ( $terms as $term ) {
|
|
392
|
+
if ( empty( $allowed[ $taxonomy ] ) || in_array( (int) $term->term_id, $allowed[ $taxonomy ], true ) ) {
|
|
393
|
+
$names[] = $term->name;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return $names;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
private static function all_term_names( int $post_id, string $type, array $allowed ): array {
|
|
401
|
+
$names = [];
|
|
402
|
+
|
|
403
|
+
foreach ( get_object_taxonomies( $type ) as $taxonomy ) {
|
|
404
|
+
$names = array_merge( $names, self::term_names( $post_id, $taxonomy, $allowed ) );
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return $names;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
public static function resolve_ids( string $type, array $config ): array {
|
|
411
|
+
$pinned = array_map( 'intval', (array) ( $config['pinned'] ?? [] ) );
|
|
412
|
+
$blocked = array_map( 'intval', (array) ( $config['blocked'] ?? [] ) );
|
|
413
|
+
$include = array_filter( array_map( 'intval', (array) ( $config['include_by_terms'] ?? [] ) ) );
|
|
414
|
+
$exclude = array_filter( array_map( 'intval', (array) ( $config['exclude_by_terms'] ?? [] ) ) );
|
|
415
|
+
|
|
416
|
+
$excluded = $exclude ? self::ids_in_terms( $type, $exclude ) : [];
|
|
417
|
+
|
|
418
|
+
if ( in_array( 0, $pinned, true ) ) {
|
|
419
|
+
$all = ( new \WP_Query(
|
|
420
|
+
[
|
|
421
|
+
'post_type' => $type,
|
|
422
|
+
'post_status' => 'publish',
|
|
423
|
+
'posts_per_page' => -1,
|
|
424
|
+
'no_found_rows' => true,
|
|
425
|
+
'fields' => 'ids',
|
|
426
|
+
]
|
|
427
|
+
) )->posts;
|
|
428
|
+
|
|
429
|
+
return array_values( array_diff( $all, $excluded, $blocked ) );
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
$ids = $include ? self::ids_in_terms( $type, $include ) : [];
|
|
433
|
+
$ids = array_diff( $ids, $excluded );
|
|
434
|
+
$ids = array_unique( array_merge( $ids, array_filter( $pinned ) ) );
|
|
435
|
+
|
|
436
|
+
return array_values( array_diff( $ids, $blocked ) );
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
private static function ids_in_terms( string $type, array $term_ids ): array {
|
|
440
|
+
$tax_query = [ 'relation' => 'OR' ];
|
|
441
|
+
|
|
442
|
+
foreach ( get_object_taxonomies( $type ) as $taxonomy ) {
|
|
443
|
+
$tax_query[] = [
|
|
444
|
+
'taxonomy' => $taxonomy,
|
|
445
|
+
'field' => 'term_id',
|
|
446
|
+
'terms' => $term_ids,
|
|
447
|
+
];
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return ( new \WP_Query(
|
|
451
|
+
[
|
|
452
|
+
'post_type' => $type,
|
|
453
|
+
'post_status' => 'publish',
|
|
454
|
+
'posts_per_page' => -1,
|
|
455
|
+
'no_found_rows' => true,
|
|
456
|
+
'fields' => 'ids',
|
|
457
|
+
'tax_query' => $tax_query,
|
|
458
|
+
]
|
|
459
|
+
) )->posts;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
private static function allowed_terms( array $config ): array {
|
|
463
|
+
$ids = array_filter( array_map( 'intval', (array) ( $config['include_by_terms'] ?? [] ) ) );
|
|
464
|
+
|
|
465
|
+
if ( ! $ids ) {
|
|
466
|
+
return [];
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
$terms = get_terms( [ 'include' => $ids, 'hide_empty' => false ] );
|
|
470
|
+
$out = [];
|
|
471
|
+
|
|
472
|
+
foreach ( is_wp_error( $terms ) ? [] : $terms as $term ) {
|
|
473
|
+
$out[ $term->taxonomy ][] = (int) $term->term_id;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return $out;
|
|
477
|
+
}
|
|
478
|
+
}
|