@wp-operations/wp-ops 0.3.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.
Files changed (117) hide show
  1. package/package.json +6 -2
  2. package/src/commands/platform.js +16 -2
  3. package/src/main.js +9 -3
  4. package/wp-operations/CHANGELOG.md +14 -0
  5. package/wp-operations/README.md +39 -0
  6. package/wp-operations/agents/builder/AGENT.md +15 -0
  7. package/wp-operations/assets/admin.css +631 -0
  8. package/wp-operations/assets/admin.js +614 -0
  9. package/wp-operations/assets/app/app.css +1 -0
  10. package/wp-operations/assets/app/app.js +70 -0
  11. package/wp-operations/assets/app/fonts/inter-medium.woff +0 -0
  12. package/wp-operations/assets/app/fonts/inter-regular.woff +0 -0
  13. package/wp-operations/assets/app/fonts/inter-semibold.woff +0 -0
  14. package/wp-operations/assets/app/login.css +42 -0
  15. package/wp-operations/assets/brand/icon.svg +20 -0
  16. package/wp-operations/assets/brand/mark.svg +19 -0
  17. package/wp-operations/assets/editors/audiobook.css +311 -0
  18. package/wp-operations/assets/editors/audiofile.css +286 -0
  19. package/wp-operations/assets/editors/course.css +701 -0
  20. package/wp-operations/assets/editors/course.js +698 -0
  21. package/wp-operations/assets/editors/faq.css +258 -0
  22. package/wp-operations/assets/editors/faq.js +196 -0
  23. package/wp-operations/assets/editors/interactive.css +220 -0
  24. package/wp-operations/assets/editors/interactive.js +378 -0
  25. package/wp-operations/assets/editors/media-sources.css +3 -0
  26. package/wp-operations/assets/editors/media-sources.js +40 -0
  27. package/wp-operations/assets/editors/open-media.css +114 -0
  28. package/wp-operations/assets/editors/open-media.js +182 -0
  29. package/wp-operations/assets/editors/thumbnails.css +335 -0
  30. package/wp-operations/assets/editors/thumbnails.js +447 -0
  31. package/wp-operations/assets/editors/translator.css +818 -0
  32. package/wp-operations/functions.php +24 -0
  33. package/wp-operations/index.php +14 -0
  34. package/wp-operations/platform.json +1836 -0
  35. package/wp-operations/skills/ai-development-guardrails/SKILL.md +49 -0
  36. package/wp-operations/skills/gutenberg-reference/SKILL.md +45 -0
  37. package/wp-operations/skills/js-tooling-for-themes/SKILL.md +51 -0
  38. package/wp-operations/skills/tailwind-for-wp/SKILL.md +62 -0
  39. package/wp-operations/skills/wp-clean-classic-themes/SKILL.md +112 -0
  40. package/wp-operations/skills/wp-psr4-plugins/SKILL.md +2043 -0
  41. package/wp-operations/skills/wp-security/SKILL.md +90 -0
  42. package/wp-operations/src/Admin.php +78 -0
  43. package/wp-operations/src/App/Access.php +57 -0
  44. package/wp-operations/src/App/Admin.php +442 -0
  45. package/wp-operations/src/App/App.php +157 -0
  46. package/wp-operations/src/App/Apps.php +379 -0
  47. package/wp-operations/src/App/Bundle.php +111 -0
  48. package/wp-operations/src/App/Contents.php +676 -0
  49. package/wp-operations/src/App/Engine.php +554 -0
  50. package/wp-operations/src/App/Github.php +308 -0
  51. package/wp-operations/src/App/Module.php +23 -0
  52. package/wp-operations/src/App/Ops.php +470 -0
  53. package/wp-operations/src/App/Packages.php +289 -0
  54. package/wp-operations/src/App/Rest.php +539 -0
  55. package/wp-operations/src/App/Sandboxes.php +206 -0
  56. package/wp-operations/src/App/Store.php +104 -0
  57. package/wp-operations/src/App/Usage.php +268 -0
  58. package/wp-operations/src/Config.php +249 -0
  59. package/wp-operations/src/Content/Editor.php +223 -0
  60. package/wp-operations/src/Content/Fields.php +681 -0
  61. package/wp-operations/src/Content/Scoring.php +253 -0
  62. package/wp-operations/src/Content/Structure.php +293 -0
  63. package/wp-operations/src/Content/Types.php +150 -0
  64. package/wp-operations/src/Content/Uploads.php +50 -0
  65. package/wp-operations/src/Editors/AudiobookAuthor.php +61 -0
  66. package/wp-operations/src/Editors/AudiobookChapters.php +632 -0
  67. package/wp-operations/src/Editors/AudiobookCover.php +235 -0
  68. package/wp-operations/src/Editors/Audiofile.php +462 -0
  69. package/wp-operations/src/Editors/Course.php +784 -0
  70. package/wp-operations/src/Editors/Ebook.php +242 -0
  71. package/wp-operations/src/Editors/Editors.php +44 -0
  72. package/wp-operations/src/Editors/Faq.php +237 -0
  73. package/wp-operations/src/Editors/Files.php +139 -0
  74. package/wp-operations/src/Editors/Interactive/Builder.php +103 -0
  75. package/wp-operations/src/Editors/Interactive/Card.php +76 -0
  76. package/wp-operations/src/Editors/Interactive/Editor.php +42 -0
  77. package/wp-operations/src/Editors/Interactive/Field.php +272 -0
  78. package/wp-operations/src/Editors/Interactive/Map.php +84 -0
  79. package/wp-operations/src/Editors/Interactive/Models.php +227 -0
  80. package/wp-operations/src/Editors/Interactive/Report.php +59 -0
  81. package/wp-operations/src/Editors/Interactive/Save.php +323 -0
  82. package/wp-operations/src/Editors/Interactive/Scoring.php +244 -0
  83. package/wp-operations/src/Editors/Interactive/Structure.php +195 -0
  84. package/wp-operations/src/Editors/Legal.php +235 -0
  85. package/wp-operations/src/Editors/OpenMedia.php +140 -0
  86. package/wp-operations/src/Editors/OriginalTitle.php +112 -0
  87. package/wp-operations/src/Editors/Sources.php +28 -0
  88. package/wp-operations/src/Editors/Thumbnails/Admin.php +306 -0
  89. package/wp-operations/src/Editors/Thumbnails/Ajax.php +163 -0
  90. package/wp-operations/src/Editors/Thumbnails/Box.php +188 -0
  91. package/wp-operations/src/Editors/Thumbnails/Storage.php +228 -0
  92. package/wp-operations/src/Editors/Translator/Admin.php +913 -0
  93. package/wp-operations/src/Editors/Translator/Api.php +63 -0
  94. package/wp-operations/src/Editors/Translator/Bar.php +83 -0
  95. package/wp-operations/src/Editors/Translator/Fields.php +273 -0
  96. package/wp-operations/src/Editors/Translator/Storage.php +131 -0
  97. package/wp-operations/src/Editors/Translator/Thumbnail.php +215 -0
  98. package/wp-operations/src/Identity.php +104 -0
  99. package/wp-operations/src/Languages.php +45 -0
  100. package/wp-operations/src/Lockdown.php +85 -0
  101. package/wp-operations/src/Modules/Apps/Admin.php +472 -0
  102. package/wp-operations/src/Modules/Apps/Api.php +193 -0
  103. package/wp-operations/src/Modules/Apps/Apps.php +279 -0
  104. package/wp-operations/src/Modules/Apps/Formatters.php +478 -0
  105. package/wp-operations/src/Modules/Apps/Schemes.php +248 -0
  106. package/wp-operations/src/Modules/Apps/Table.php +101 -0
  107. package/wp-operations/src/Modules/Thumbnails.php +68 -0
  108. package/wp-operations/src/Modules/Translations.php +133 -0
  109. package/wp-operations/src/Platform.php +59 -0
  110. package/wp-operations/src/Setup.php +273 -0
  111. package/wp-operations/src/Status.php +99 -0
  112. package/wp-operations/src/Storage/Client.php +168 -0
  113. package/wp-operations/src/Storage/Offload.php +120 -0
  114. package/wp-operations/src/Storage/Settings.php +166 -0
  115. package/wp-operations/src/Storage/Storage.php +35 -0
  116. package/wp-operations/src/Updates.php +151 -0
  117. package/wp-operations/style.css +11 -0
@@ -0,0 +1,248 @@
1
+ <?php
2
+ /**
3
+ * Detail schemes: named sets of app detail keys with a primary key
4
+ *
5
+ * @package Platform
6
+ */
7
+
8
+ namespace Platform\Modules\Apps;
9
+
10
+ use Platform\Config;
11
+ use Platform\Setup;
12
+
13
+ defined( 'ABSPATH' ) || exit;
14
+
15
+ final class Schemes {
16
+
17
+ public static function register(): void {
18
+ add_action( 'admin_menu', [ __CLASS__, 'menu' ], 20 );
19
+ add_action( 'admin_post_platform_record_save', [ __CLASS__, 'save' ] );
20
+ add_action( 'admin_post_platform_record_delete', [ __CLASS__, 'delete' ] );
21
+ add_action( 'admin_post_platform_records_import', [ __CLASS__, 'import' ] );
22
+ }
23
+
24
+ public static function all(): array {
25
+ $schemes = [];
26
+ $labels = array_column( Apps::metadata_fields(), 'label', 'key' );
27
+
28
+ foreach ( (array) Config::get( 'apps.schemes', [] ) as $scheme ) {
29
+ $key = sanitize_key( $scheme['key'] ?? '' );
30
+ $fields = array_values( array_map( 'sanitize_key', (array) ( $scheme['fields'] ?? [] ) ) );
31
+
32
+ if ( '' === $key || ! $fields ) {
33
+ continue;
34
+ }
35
+
36
+ $primary = sanitize_key( $scheme['primary'] ?? $fields[0] );
37
+
38
+ $schemes[ $key ] = [
39
+ 'key' => $key,
40
+ 'label' => (string) ( $scheme['label'] ?? ucfirst( $key ) ),
41
+ 'singular' => (string) ( $scheme['singular'] ?? $scheme['label'] ?? ucfirst( $key ) ),
42
+ 'primary' => $primary,
43
+ 'fields' => array_values( array_unique( array_merge( [ $primary ], $fields ) ) ),
44
+ 'labels' => $labels,
45
+ ];
46
+ }
47
+
48
+ return $schemes;
49
+ }
50
+
51
+ public static function records( string $scheme ): array {
52
+ global $wpdb;
53
+
54
+ $rows = (array) $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . self::table() . ' WHERE scheme = %s ORDER BY title ASC', $scheme ), ARRAY_A );
55
+
56
+ foreach ( $rows as &$row ) {
57
+ $row['id'] = (int) $row['id'];
58
+ $row['data'] = json_decode( (string) $row['data'], true ) ?: [];
59
+ }
60
+
61
+ return $rows;
62
+ }
63
+
64
+ private static function table(): string {
65
+ return Setup::table( 'app_records' );
66
+ }
67
+
68
+ private static function page( string $scheme ): string {
69
+ return 'app-' . $scheme;
70
+ }
71
+
72
+ /* ---------------------------------------------------------------- admin */
73
+
74
+ public static function menu(): void {
75
+ foreach ( self::all() as $scheme ) {
76
+ add_submenu_page( Admin::PAGE, $scheme['label'], $scheme['label'], 'manage_options', self::page( $scheme['key'] ), [ __CLASS__, 'render' ] );
77
+ }
78
+ }
79
+
80
+ public static function render(): void {
81
+ $page = sanitize_key( wp_unslash( (string) ( $_GET['page'] ?? '' ) ) );
82
+ $scheme = null;
83
+
84
+ foreach ( self::all() as $candidate ) {
85
+ if ( self::page( $candidate['key'] ) === $page ) {
86
+ $scheme = $candidate;
87
+ }
88
+ }
89
+
90
+ if ( ! $scheme ) {
91
+ return;
92
+ }
93
+
94
+ $records = self::records( $scheme['key'] );
95
+ $editing = sanitize_key( wp_unslash( (string) ( $_GET['record'] ?? '' ) ) );
96
+ $current = [];
97
+
98
+ foreach ( $records as $record ) {
99
+ if ( (string) $record['id'] === $editing ) {
100
+ $current = $record;
101
+ }
102
+ }
103
+
104
+ $url = admin_url( 'admin.php?page=' . self::page( $scheme['key'] ) );
105
+ ?>
106
+ <div class="wrap">
107
+ <h1 class="wp-heading-inline"><?php echo esc_html( $scheme['label'] ); ?></h1>
108
+ <a class="page-title-action" href="<?php echo esc_url( add_query_arg( 'record', 'new', $url ) ); ?>">Add New</a>
109
+ <hr class="wp-header-end" />
110
+ <?php if ( isset( $_GET['imported'] ) ) : ?>
111
+ <div class="notice notice-success is-dismissible"><p><?php echo esc_html( sprintf( '%d added from existing apps.', absint( $_GET['imported'] ) ) ); ?></p></div>
112
+ <?php endif; ?>
113
+
114
+ <?php if ( '' !== $editing ) : ?>
115
+ <form class="platform-card" style="max-width:720px;margin:16px 0" method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
116
+ <input type="hidden" name="action" value="platform_record_save" />
117
+ <input type="hidden" name="scheme" value="<?php echo esc_attr( $scheme['key'] ); ?>" />
118
+ <input type="hidden" name="id" value="<?php echo (int) ( $current['id'] ?? 0 ); ?>" />
119
+ <?php wp_nonce_field( 'platform_record_save' ); ?>
120
+ <div class="platform-fields">
121
+ <?php foreach ( $scheme['fields'] as $key ) : ?>
122
+ <div class="platform-field">
123
+ <span class="platform-field__label"><?php echo esc_html( $scheme['labels'][ $key ] ?? $key ); ?></span>
124
+ <input type="text" name="data[<?php echo esc_attr( $key ); ?>]" value="<?php echo esc_attr( (string) ( $current['data'][ $key ] ?? '' ) ); ?>"<?php echo $key === $scheme['primary'] ? ' required' : ''; ?> />
125
+ </div>
126
+ <?php endforeach; ?>
127
+ </div>
128
+ <p><?php submit_button( $current ? 'Update' : 'Add', 'primary', 'submit', false ); ?> <a class="button" href="<?php echo esc_url( $url ); ?>">Cancel</a></p>
129
+ </form>
130
+ <?php endif; ?>
131
+
132
+ <table class="widefat striped">
133
+ <thead><tr><?php foreach ( $scheme['fields'] as $key ) : ?><th><?php echo esc_html( $scheme['labels'][ $key ] ?? $key ); ?></th><?php endforeach; ?></tr></thead>
134
+ <tbody>
135
+ <?php foreach ( $records as $record ) : ?>
136
+ <tr>
137
+ <?php foreach ( $scheme['fields'] as $index => $key ) : ?>
138
+ <td>
139
+ <?php if ( 0 === $index ) : ?>
140
+ <strong><a href="<?php echo esc_url( add_query_arg( 'record', $record['id'], $url ) ); ?>"><?php echo esc_html( (string) ( $record['data'][ $key ] ?? '' ) ); ?></a></strong>
141
+ <div class="row-actions">
142
+ <a href="<?php echo esc_url( add_query_arg( 'record', $record['id'], $url ) ); ?>">Edit</a> |
143
+ <a class="submitdelete" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin-post.php?action=platform_record_delete&scheme=' . $scheme['key'] . '&id=' . $record['id'] ), 'platform_record_delete' ) ); ?>" onclick="return confirm('Delete this entry?')">Delete</a>
144
+ </div>
145
+ <?php else : ?>
146
+ <?php echo esc_html( (string) ( $record['data'][ $key ] ?? '' ) ); ?>
147
+ <?php endif; ?>
148
+ </td>
149
+ <?php endforeach; ?>
150
+ </tr>
151
+ <?php endforeach; ?>
152
+ </tbody>
153
+ </table>
154
+
155
+ <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" style="margin-top:16px">
156
+ <input type="hidden" name="action" value="platform_records_import" />
157
+ <input type="hidden" name="scheme" value="<?php echo esc_attr( $scheme['key'] ); ?>" />
158
+ <?php wp_nonce_field( 'platform_records_import' ); ?>
159
+ <?php submit_button( 'Import from existing apps', 'secondary', 'submit', false ); ?>
160
+ <span class="description">Adds every <?php echo esc_html( strtolower( $scheme['labels'][ $scheme['primary'] ] ?? $scheme['primary'] ) ); ?> already used by an app that is not listed yet.</span>
161
+ </form>
162
+ </div>
163
+ <?php
164
+ }
165
+
166
+ public static function save(): void {
167
+ $scheme = self::guard( 'platform_record_save' );
168
+ $data = [];
169
+
170
+ foreach ( $scheme['fields'] as $key ) {
171
+ $data[ $key ] = sanitize_text_field( wp_unslash( (string) ( $_POST['data'][ $key ] ?? '' ) ) );
172
+ }
173
+
174
+ self::write( absint( $_POST['id'] ?? 0 ), $scheme, $data );
175
+
176
+ wp_safe_redirect( admin_url( 'admin.php?page=' . self::page( $scheme['key'] ) ) );
177
+ exit;
178
+ }
179
+
180
+ public static function delete(): void {
181
+ $scheme = self::guard( 'platform_record_delete' );
182
+
183
+ global $wpdb;
184
+ $wpdb->delete( self::table(), [ 'id' => absint( $_GET['id'] ?? 0 ), 'scheme' => $scheme['key'] ] );
185
+
186
+ wp_safe_redirect( admin_url( 'admin.php?page=' . self::page( $scheme['key'] ) ) );
187
+ exit;
188
+ }
189
+
190
+ public static function import(): void {
191
+ $scheme = self::guard( 'platform_records_import' );
192
+ $existing = array_map( 'strtolower', wp_list_pluck( self::records( $scheme['key'] ), 'title' ) );
193
+ $added = 0;
194
+
195
+ foreach ( Apps::all() as $app ) {
196
+ $title = trim( (string) ( $app['metadata'][ $scheme['primary'] ] ?? '' ) );
197
+
198
+ if ( '' === $title || in_array( strtolower( $title ), $existing, true ) ) {
199
+ continue;
200
+ }
201
+
202
+ $data = [];
203
+ foreach ( $scheme['fields'] as $key ) {
204
+ $data[ $key ] = sanitize_text_field( (string) ( $app['metadata'][ $key ] ?? '' ) );
205
+ }
206
+
207
+ self::write( 0, $scheme, $data );
208
+ $existing[] = strtolower( $title );
209
+ ++$added;
210
+ }
211
+
212
+ wp_safe_redirect( admin_url( 'admin.php?page=' . self::page( $scheme['key'] ) . '&imported=' . $added ) );
213
+ exit;
214
+ }
215
+
216
+ private static function write( int $id, array $scheme, array $data ): void {
217
+ global $wpdb;
218
+
219
+ $row = [
220
+ 'scheme' => $scheme['key'],
221
+ 'title' => (string) ( $data[ $scheme['primary'] ] ?? '' ),
222
+ 'data' => wp_json_encode( $data ),
223
+ ];
224
+
225
+ if ( $id ) {
226
+ $wpdb->update( self::table(), $row, [ 'id' => $id, 'scheme' => $scheme['key'] ] );
227
+ } else {
228
+ $wpdb->insert( self::table(), $row );
229
+ }
230
+ }
231
+
232
+ private static function guard( string $nonce ): array {
233
+ if ( ! current_user_can( 'manage_options' ) ) {
234
+ wp_die( 'Not allowed.', 403 );
235
+ }
236
+
237
+ check_admin_referer( $nonce );
238
+
239
+ $key = sanitize_key( wp_unslash( (string) ( $_REQUEST['scheme'] ?? '' ) ) );
240
+ $schemes = self::all();
241
+
242
+ if ( ! isset( $schemes[ $key ] ) ) {
243
+ wp_die( 'Unknown scheme.', 400 );
244
+ }
245
+
246
+ return $schemes[ $key ];
247
+ }
248
+ }
@@ -0,0 +1,101 @@
1
+ <?php
2
+ namespace Platform\Modules\Apps;
3
+
4
+ defined( 'ABSPATH' ) || exit;
5
+
6
+ if ( ! class_exists( 'WP_List_Table' ) ) {
7
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
8
+ }
9
+
10
+ final class Table extends \WP_List_Table {
11
+
12
+ public function __construct() {
13
+ parent::__construct( [ 'singular' => 'app', 'plural' => 'apps', 'ajax' => false ] );
14
+ }
15
+
16
+ public function get_columns(): array {
17
+ $columns = [ 'cb' => '<input type="checkbox" />', 'name' => 'App' ];
18
+
19
+ foreach ( Apps::environments() as $key => $label ) {
20
+ $columns[ 'env_' . $key ] = $label;
21
+ }
22
+
23
+ return $columns + [ 'contents' => 'Content' ];
24
+ }
25
+
26
+ protected function get_sortable_columns(): array {
27
+ return [ 'name' => [ 'name', false ] ];
28
+ }
29
+
30
+ protected function get_bulk_actions(): array {
31
+ $actions = [];
32
+
33
+ foreach ( Apps::environments() as $key => $label ) {
34
+ $actions[ 'push_' . $key ] = 'Push content to ' . strtolower( $label );
35
+ }
36
+
37
+ return $actions + [ 'delete' => 'Delete' ];
38
+ }
39
+
40
+ public function prepare_items(): void {
41
+ $search = sanitize_text_field( wp_unslash( (string) ( $_REQUEST['s'] ?? '' ) ) );
42
+ $order = 'desc' === strtolower( (string) ( $_REQUEST['order'] ?? 'asc' ) ) ? -1 : 1;
43
+ $per_page = $this->get_items_per_page( 'platform_apps_per_page', 20 );
44
+ $items = Apps::all( $search );
45
+
46
+ usort( $items, static fn( array $a, array $b ): int => $order * strcasecmp( (string) $a['name'], (string) $b['name'] ) );
47
+
48
+ $this->set_pagination_args( [ 'total_items' => count( $items ), 'per_page' => $per_page ] );
49
+ $this->items = array_slice( $items, ( $this->get_pagenum() - 1 ) * $per_page, $per_page );
50
+ $this->_column_headers = [ $this->get_columns(), [], $this->get_sortable_columns(), 'name' ];
51
+ }
52
+
53
+ public function no_items(): void {
54
+ echo 'No apps found.';
55
+ }
56
+
57
+ protected function column_cb( $item ): string {
58
+ return sprintf( '<input type="checkbox" name="ids[]" value="%d" />', (int) $item['id'] );
59
+ }
60
+
61
+ protected function column_name( $item ): string {
62
+ $edit = Admin::url( [ 'app' => $item['id'] ] );
63
+ $actions = [ 'edit' => sprintf( '<a href="%s">Edit</a>', esc_url( $edit ) ) ];
64
+
65
+ foreach ( Apps::environments() as $key => $label ) {
66
+ if ( ! empty( $item['environments'][ $key ]['url'] ) ) {
67
+ $actions[ 'push_' . $key ] = sprintf( '<a href="%s">Push to %s</a>', esc_url( Admin::action_url( 'app_push', [ 'id' => $item['id'], 'env' => $key ] ) ), esc_html( strtolower( $label ) ) );
68
+ }
69
+ }
70
+
71
+ $actions['delete'] = sprintf( '<a class="submitdelete" href="%s" onclick="return confirm(\'Delete this app? Its user is kept.\')">Delete</a>', esc_url( Admin::action_url( 'app_delete', [ 'id' => $item['id'] ] ) ) );
72
+
73
+ return sprintf( '<strong><a class="row-title" href="%s">%s</a></strong>%s', esc_url( $edit ), esc_html( (string) $item['name'] ), $this->row_actions( $actions ) );
74
+ }
75
+
76
+ protected function column_contents( $item ): string {
77
+ $endpoints = Api::endpoints();
78
+ $names = array_diff( array_keys( (array) $item['contents'] ), [ 'thumbnail_group_id' ] );
79
+
80
+ return esc_html( implode( ', ', array_map( static fn( $name ) => $endpoints[ $name ]['label'] ?? $name, $names ) ) ?: '—' );
81
+ }
82
+
83
+ protected function column_default( $item, $column_name ) {
84
+ if ( 0 !== strpos( $column_name, 'env_' ) ) {
85
+ return '—';
86
+ }
87
+
88
+ $environment = (array) ( $item['environments'][ substr( $column_name, 4 ) ] ?? [] );
89
+
90
+ if ( empty( $environment['url'] ) ) {
91
+ return '—';
92
+ }
93
+
94
+ return sprintf(
95
+ '<a href="%s" target="_blank" rel="noopener">%s</a><br /><span class="description">%s</span>',
96
+ esc_url( (string) $environment['url'] ),
97
+ esc_html( Apps::host( (string) $environment['url'] ) ),
98
+ esc_html( Apps::format_pull( (string) ( $environment['last_pull'] ?? '' ) ) ?: 'Never pulled' )
99
+ );
100
+ }
101
+ }
@@ -0,0 +1,68 @@
1
+ <?php
2
+ /**
3
+ * Thumbnail groups served to apps in place of default thumbnails.
4
+ *
5
+ * @package Platform
6
+ */
7
+
8
+ namespace Platform\Modules;
9
+
10
+ use Platform\Config;
11
+ use Platform\Setup;
12
+
13
+ defined( 'ABSPATH' ) || exit;
14
+
15
+ final class Thumbnails {
16
+
17
+ public static function groups(): array {
18
+ global $wpdb;
19
+
20
+ return (array) $wpdb->get_results( 'SELECT g.*, COUNT(i.id) AS items FROM ' . Setup::table( 'thumbnail_groups' ) . ' g LEFT JOIN ' . Setup::table( 'thumbnail_items' ) . ' i ON i.group_id = g.id GROUP BY g.id ORDER BY g.name ASC', ARRAY_A );
21
+ }
22
+
23
+ public static function group( int $id ): ?array {
24
+ global $wpdb;
25
+
26
+ return $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . Setup::table( 'thumbnail_groups' ) . ' WHERE id = %d', $id ), ARRAY_A ) ?: null;
27
+ }
28
+
29
+ public static function item( int $group_id, int $object_id, string $object_type, string $asset_type = 'thumbnail' ): ?array {
30
+ global $wpdb;
31
+
32
+ return $wpdb->get_row(
33
+ $wpdb->prepare(
34
+ 'SELECT * FROM ' . Setup::table( 'thumbnail_items' ) . ' WHERE group_id = %d AND object_id = %d AND object_type = %s AND asset_type = %s LIMIT 1',
35
+ $group_id,
36
+ $object_id,
37
+ $object_type,
38
+ $asset_type
39
+ ),
40
+ ARRAY_A
41
+ ) ?: null;
42
+ }
43
+
44
+ public static function resolve( int $post_id, array $client ): ?string {
45
+ if ( ! Config::module( 'thumbnails' ) ) {
46
+ return null;
47
+ }
48
+
49
+ $group_id = (int) ( $client['contents']['thumbnail_group_id'] ?? $client['metadata']['thumbnail_group_id'] ?? 0 );
50
+
51
+ if ( ! $group_id ) {
52
+ return null;
53
+ }
54
+
55
+ $item = self::item( $group_id, $post_id, (string) ( get_post_type( $post_id ) ?: 'post' ) );
56
+
57
+ if ( ! $item || empty( $item['attachment_id'] ) ) {
58
+ return null;
59
+ }
60
+
61
+ return wp_get_attachment_image_url( (int) $item['attachment_id'], 'large' ) ?: null;
62
+ }
63
+
64
+ /* ---------------------------------------------------------------- admin */
65
+
66
+ /* ---------------------------------------------------------------- ajax */
67
+
68
+ }
@@ -0,0 +1,133 @@
1
+ <?php
2
+ /**
3
+ * Content translations for types and taxonomies with "translate": true.
4
+ *
5
+ * @package Platform
6
+ */
7
+
8
+ namespace Platform\Modules;
9
+
10
+ use Platform\Config;
11
+ use Platform\Setup;
12
+
13
+ defined( 'ABSPATH' ) || exit;
14
+
15
+ final class Translations {
16
+ const SKIP_KEYS = [
17
+ 'audio_url', 'image', 'image_url', 'thumbnail', 'thumbnail_url', 'file', 'file_url', 'url', 'link', 'href',
18
+ 'src', 'icon', 'icon_url', 'background', 'background_image', 'photo', 'video', 'video_url', 'attachment',
19
+ 'attachment_url', 'download_url', 'id', 'ID', 'post_id', 'term_id', 'user_id', 'order', 'sort',
20
+ 'allow_download', 'enable', 'enabled', 'disabled', 'status', 'color', 'colour', 'hex', 'rgb', 'date', 'time',
21
+ 'timestamp', 'created_at', 'updated_at', 'slug', 'key', 'duration', 'source', 'source_type', 'runtime',
22
+ ];
23
+
24
+ public static function get( int $id, string $object = 'post' ): array {
25
+ global $wpdb;
26
+
27
+ $json = $wpdb->get_var( $wpdb->prepare( 'SELECT translations FROM ' . Setup::table( 'translations' ) . ' WHERE object_id = %d AND object_type = %s', $id, $object ) );
28
+ $data = $json ? json_decode( $json, true ) : [];
29
+
30
+ return is_array( $data ) ? $data : [];
31
+ }
32
+
33
+ public static function text( int $id, string $field, string $lang, string $object = 'post' ): string {
34
+ return (string) ( self::get( $id, $object )[ $field ][ $lang ] ?? '' );
35
+ }
36
+
37
+ public static function put( int $id, string $object, array $data ): void {
38
+ global $wpdb;
39
+
40
+ $merged = array_replace_recursive( self::get( $id, $object ), $data );
41
+
42
+ $wpdb->replace(
43
+ Setup::table( 'translations' ),
44
+ [
45
+ 'object_id' => $id,
46
+ 'object_type' => $object,
47
+ 'translations' => wp_json_encode( $merged ),
48
+ 'updated_at' => current_time( 'mysql', true ),
49
+ ],
50
+ [ '%d', '%s', '%s', '%s' ]
51
+ );
52
+ }
53
+
54
+ public static function texts( string $object, int $id ): array {
55
+ $texts = [];
56
+
57
+ if ( 'post' === $object ) {
58
+ $post = get_post( $id );
59
+ $fields = Config::type( $post->post_type )['fields'] ?? [];
60
+ $core = [ 'post_title' => 'Title', 'post_content' => 'Content', 'post_excerpt' => 'Excerpt' ];
61
+
62
+ foreach ( $core as $key => $label ) {
63
+ if ( self::translatable( $post->$key ) ) {
64
+ $texts[ $key ] = [ $label, $post->$key ];
65
+ }
66
+ }
67
+ } else {
68
+ $term = get_term( $id );
69
+ $fields = Config::taxonomy( $term->taxonomy )['fields'] ?? [];
70
+
71
+ foreach ( [ 'name' => 'Name', 'description' => 'Description' ] as $key => $label ) {
72
+ if ( self::translatable( $term->$key ) ) {
73
+ $texts[ $key ] = [ $label, $term->$key ];
74
+ }
75
+ }
76
+ }
77
+
78
+ foreach ( $fields as $field ) {
79
+ if ( empty( $field['translate'] ) ) {
80
+ continue;
81
+ }
82
+
83
+ $value = get_metadata( $object, $id, $field['key'], true );
84
+
85
+ while ( is_string( $value ) && is_serialized( $value ) ) {
86
+ $value = maybe_unserialize( $value );
87
+ }
88
+
89
+ if ( is_array( $value ) ) {
90
+ foreach ( self::leaves( $value ) as $path => $leaf ) {
91
+ $texts[ 'meta_' . $field['key'] . '.' . $path ] = [ ( $field['label'] ?: $field['key'] ) . ' › ' . str_replace( '.', ' › ', $path ), $leaf ];
92
+ }
93
+ } elseif ( self::translatable( $value ) ) {
94
+ $texts[ 'meta_' . $field['key'] ] = [ $field['label'] ?: $field['key'], (string) $value ];
95
+ }
96
+ }
97
+
98
+ return $texts;
99
+ }
100
+
101
+ private static function leaves( array $data, string $prefix = '' ): array {
102
+ $out = [];
103
+
104
+ foreach ( $data as $key => $value ) {
105
+ if ( in_array( (string) $key, self::SKIP_KEYS, true ) ) {
106
+ continue;
107
+ }
108
+
109
+ $path = '' === $prefix ? (string) $key : $prefix . '.' . $key;
110
+
111
+ if ( is_array( $value ) ) {
112
+ $out += self::leaves( $value, $path );
113
+ } elseif ( self::translatable( $value ) ) {
114
+ $out[ $path ] = (string) $value;
115
+ }
116
+ }
117
+
118
+ return $out;
119
+ }
120
+
121
+ private static function translatable( $value ): bool {
122
+ if ( ! is_string( $value ) || '' === trim( $value ) ) {
123
+ return false;
124
+ }
125
+
126
+ $value = trim( $value );
127
+
128
+ return ! filter_var( $value, FILTER_VALIDATE_URL ) && ! is_numeric( $value );
129
+ }
130
+
131
+ /* ---------------------------------------------------------------- admin */
132
+
133
+ }
@@ -0,0 +1,59 @@
1
+ <?php
2
+ /**
3
+ * Boots every part of the platform.
4
+ *
5
+ * @package Platform
6
+ */
7
+
8
+ namespace Platform;
9
+
10
+ defined( 'ABSPATH' ) || exit;
11
+
12
+ final class Platform {
13
+
14
+ const SCHEMA = 3;
15
+
16
+ public static function boot(): void {
17
+ Config::load();
18
+
19
+ Lockdown::register();
20
+ Admin::register();
21
+ Identity::register();
22
+ Setup::register();
23
+ Updates::register();
24
+ Status::register();
25
+ Storage\Storage::register();
26
+ Content\Types::register();
27
+ Content\Editor::register();
28
+ Content\Structure::register();
29
+ Content\Uploads::register();
30
+
31
+ Editors\Editors::register();
32
+
33
+
34
+ if ( Config::get( 'app' ) ) {
35
+ App\Module::register();
36
+ }
37
+
38
+ if ( Config::module( 'apps' ) ) {
39
+ Modules\Apps\Api::register();
40
+ Modules\Apps\Admin::register();
41
+ Modules\Apps\Schemes::register();
42
+ }
43
+ }
44
+
45
+
46
+ public static function url( string $path = '' ): string {
47
+ return get_template_directory_uri() . '/' . ltrim( $path, '/' );
48
+ }
49
+
50
+ public static function path( string $path = '' ): string {
51
+ return get_template_directory() . '/' . ltrim( $path, '/' );
52
+ }
53
+
54
+ public static function asset_version( string $path ): string {
55
+ $file = self::path( $path );
56
+
57
+ return is_readable( $file ) ? (string) filemtime( $file ) : (string) self::SCHEMA;
58
+ }
59
+ }