@wp-operations/wp-ops 0.3.0 → 0.4.0
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 +6 -3
- package/package.json +6 -2
- package/src/commands/platform.js +58 -2
- package/src/commands/start.js +2 -2
- package/src/main.js +19 -8
- 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,442 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
namespace Platform\App;
|
|
3
|
+
|
|
4
|
+
use Platform\Config;
|
|
5
|
+
use Platform\Modules\Apps\Apps as Registry;
|
|
6
|
+
|
|
7
|
+
defined( 'ABSPATH' ) || exit;
|
|
8
|
+
|
|
9
|
+
final class Admin {
|
|
10
|
+
|
|
11
|
+
const ACTIONS = [ 'ops_save', 'ops_kinds', 'ops_apps', 'ops_import', 'ops_detect', 'ops_secret', 'ops_secret_delete', 'ops_run', 'ops_sandbox', 'ops_sandbox_delete', 'engine_save', 'engine_test', 'usage_save' ];
|
|
12
|
+
|
|
13
|
+
public static function register(): void {
|
|
14
|
+
add_action( 'admin_menu', [ __CLASS__, 'menu' ] );
|
|
15
|
+
|
|
16
|
+
foreach ( self::ACTIONS as $action ) {
|
|
17
|
+
add_action( 'admin_post_platform_' . $action, [ __CLASS__, 'handle' ] );
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static function menu(): void {
|
|
22
|
+
add_options_page( 'Operations', 'Operations', 'manage_options', Ops::PAGE, [ __CLASS__, 'operations' ] );
|
|
23
|
+
add_options_page( 'AI Models', 'AI Models', 'manage_options', Engine::PAGE, [ __CLASS__, 'models' ] );
|
|
24
|
+
add_users_page( 'Prompt Users', 'Prompt Users', 'list_users', Usage::PAGE, [ __CLASS__, 'usage' ] );
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private static function url( string $page, array $args = [] ): string {
|
|
28
|
+
$base = Usage::PAGE === $page ? 'users.php' : 'options-general.php';
|
|
29
|
+
|
|
30
|
+
return add_query_arg( [ 'page' => $page ] + $args, admin_url( $base ) );
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public static function handle(): void {
|
|
34
|
+
$action = substr( (string) current_action(), strlen( 'admin_post_platform_' ) );
|
|
35
|
+
$input = wp_unslash( $_POST );
|
|
36
|
+
$page = sanitize_key( (string) ( $input['page'] ?? Ops::PAGE ) );
|
|
37
|
+
$tab = sanitize_key( (string) ( $input['tab'] ?? '' ) );
|
|
38
|
+
|
|
39
|
+
if ( ! current_user_can( 'usage_save' === $action ? 'edit_users' : 'manage_options' ) ) {
|
|
40
|
+
wp_die( 'You cannot do that.', 403 );
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
check_admin_referer( 'platform_' . $action );
|
|
44
|
+
|
|
45
|
+
switch ( $action ) {
|
|
46
|
+
case 'ops_save':
|
|
47
|
+
$result = Ops::save( [ 'url' => $input['url'] ?? '', 'branch' => $input['branch'] ?? '', 'packages' => $input['packages'] ?? '', 'workflows' => (array) ( $input['workflows'] ?? [] ) ] );
|
|
48
|
+
$done = 'Repository saved.';
|
|
49
|
+
break;
|
|
50
|
+
case 'ops_kinds':
|
|
51
|
+
$result = Ops::save( [ 'kinds' => (array) ( $input['kinds'] ?? [] ) ] );
|
|
52
|
+
$done = 'App folders saved.';
|
|
53
|
+
break;
|
|
54
|
+
case 'ops_apps':
|
|
55
|
+
$result = Ops::save( [ 'apps' => (array) ( $input['apps'] ?? [] ) ] );
|
|
56
|
+
$done = 'Apps saved.';
|
|
57
|
+
break;
|
|
58
|
+
case 'ops_import':
|
|
59
|
+
$result = Ops::import();
|
|
60
|
+
$done = sprintf( 'Read %s.', Ops::LAYOUT );
|
|
61
|
+
break;
|
|
62
|
+
case 'ops_detect':
|
|
63
|
+
$result = Ops::detect();
|
|
64
|
+
$done = is_wp_error( $result ) ? '' : sprintf( 'Matched %d apps.', $result['matched'] );
|
|
65
|
+
break;
|
|
66
|
+
case 'ops_secret':
|
|
67
|
+
$result = Ops::put_secret( (string) ( $input['name'] ?? '' ), (string) ( $input['value'] ?? '' ), (string) ( $input['environment'] ?? '' ) );
|
|
68
|
+
$done = 'Secret sent to GitHub.';
|
|
69
|
+
break;
|
|
70
|
+
case 'ops_secret_delete':
|
|
71
|
+
$result = Ops::delete_secret( (string) ( $input['name'] ?? '' ), (string) ( $input['environment'] ?? '' ) );
|
|
72
|
+
$done = 'Secret deleted.';
|
|
73
|
+
break;
|
|
74
|
+
case 'ops_run':
|
|
75
|
+
$result = Github::dispatch( (string) ( $input['workflow'] ?? '' ) );
|
|
76
|
+
$done = 'Workflow started.';
|
|
77
|
+
break;
|
|
78
|
+
case 'ops_sandbox':
|
|
79
|
+
$result = Sandboxes::save( (array) ( $input['sandbox'] ?? [] ) );
|
|
80
|
+
$done = 'Sandbox saved.';
|
|
81
|
+
break;
|
|
82
|
+
case 'ops_sandbox_delete':
|
|
83
|
+
$result = Sandboxes::remove( sanitize_key( (string) ( $input['key'] ?? '' ) ) );
|
|
84
|
+
$done = 'Sandbox removed.';
|
|
85
|
+
break;
|
|
86
|
+
case 'engine_save':
|
|
87
|
+
$result = Engine::save( $input );
|
|
88
|
+
$done = 'Models saved.';
|
|
89
|
+
break;
|
|
90
|
+
case 'engine_test':
|
|
91
|
+
$result = Engine::test( sanitize_key( (string) ( $input['provider'] ?? '' ) ) );
|
|
92
|
+
$done = is_wp_error( $result ) ? '' : sprintf( 'Answered "%s" in %d ms.', $result['text'], $result['ms'] );
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
$result = null;
|
|
96
|
+
foreach ( (array) ( $input['users'] ?? [] ) as $user_id => $row ) {
|
|
97
|
+
$result = Usage::set( (int) $user_id, [ 'access' => (string) ( $row['access'] ?? '' ), 'limit' => (string) ( $row['limit'] ?? '' ) ] );
|
|
98
|
+
}
|
|
99
|
+
if ( ! empty( $input['grant'] ) ) {
|
|
100
|
+
$result = Usage::set( (int) $input['grant'], [ 'access' => 'allow' ] );
|
|
101
|
+
}
|
|
102
|
+
$done = 'People saved.';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
$args = '' === $tab ? [] : [ 'tab' => $tab ];
|
|
106
|
+
$args += is_wp_error( $result ) ? [ 'platform_error' => rawurlencode( $result->get_error_message() ) ] : [ 'platform_notice' => rawurlencode( $done ) ];
|
|
107
|
+
|
|
108
|
+
wp_safe_redirect( self::url( $page, $args ) );
|
|
109
|
+
exit;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private static function open( string $action, string $page, string $tab = '' ): void {
|
|
113
|
+
printf( '<form method="post" action="%s">', esc_url( admin_url( 'admin-post.php' ) ) );
|
|
114
|
+
printf( '<input type="hidden" name="action" value="platform_%s"><input type="hidden" name="page" value="%s"><input type="hidden" name="tab" value="%s">', esc_attr( $action ), esc_attr( $page ), esc_attr( $tab ) );
|
|
115
|
+
wp_nonce_field( 'platform_' . $action );
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private static function inline( string $action, string $page, string $tab, string $label, array $fields = [], string $class = 'button', string $confirm = '' ): void {
|
|
119
|
+
printf( '<form method="post" action="%s" style="display:inline">', esc_url( admin_url( 'admin-post.php' ) ) );
|
|
120
|
+
printf( '<input type="hidden" name="action" value="platform_%s"><input type="hidden" name="page" value="%s"><input type="hidden" name="tab" value="%s">', esc_attr( $action ), esc_attr( $page ), esc_attr( $tab ) );
|
|
121
|
+
wp_nonce_field( 'platform_' . $action );
|
|
122
|
+
|
|
123
|
+
foreach ( $fields as $name => $value ) {
|
|
124
|
+
printf( '<input type="hidden" name="%s" value="%s">', esc_attr( $name ), esc_attr( (string) $value ) );
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
printf( '<button type="submit" class="%s"%s>%s</button></form>', esc_attr( $class ), '' === $confirm ? '' : ' onclick="return confirm(' . esc_attr( wp_json_encode( $confirm ) ) . ')"', esc_html( $label ) );
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private static function notices(): void {
|
|
131
|
+
foreach ( [ 'platform_notice' => 'success', 'platform_error' => 'error' ] as $key => $type ) {
|
|
132
|
+
if ( ! empty( $_GET[ $key ] ) ) {
|
|
133
|
+
printf( '<div class="notice notice-%s is-dismissible"><p>%s</p></div>', esc_attr( $type ), esc_html( rawurldecode( (string) wp_unslash( $_GET[ $key ] ) ) ) );
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private static function tabs( string $page, array $tabs, string $current ): void {
|
|
139
|
+
echo '<nav class="nav-tab-wrapper">';
|
|
140
|
+
|
|
141
|
+
foreach ( $tabs as $key => $label ) {
|
|
142
|
+
printf( '<a class="nav-tab%s" href="%s">%s</a>', $key === $current ? ' nav-tab-active' : '', esc_url( self::url( $page, [ 'tab' => $key ] ) ), esc_html( $label ) );
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
echo '</nav>';
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private static function state( bool $on, string $yes, string $no ): string {
|
|
149
|
+
return sprintf( '<span style="display:inline-flex;align-items:center;gap:6px;margin-right:14px"><span style="width:8px;height:8px;border-radius:50%%;background:%s"></span>%s</span>', $on ? '#00a32a' : '#d63638', esc_html( $on ? $yes : $no ) );
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public static function operations(): void {
|
|
153
|
+
$tabs = [ 'repository' => 'Platform repository', 'folders' => 'App folders', 'secrets' => 'Secrets', 'actions' => 'Actions', 'sandboxes' => 'Sandboxes' ];
|
|
154
|
+
$tab = sanitize_key( (string) ( $_GET['tab'] ?? 'repository' ) );
|
|
155
|
+
$tab = isset( $tabs[ $tab ] ) ? $tab : 'repository';
|
|
156
|
+
$admin = Ops::admin();
|
|
157
|
+
$settings = $admin['settings'];
|
|
158
|
+
$status = in_array( $tab, [ 'repository', 'secrets', 'actions' ], true ) ? Ops::status() : null;
|
|
159
|
+
|
|
160
|
+
echo '<div class="wrap"><h1>Operations</h1>';
|
|
161
|
+
echo '<p class="description">The platform repository holds platform.json, every app and the plugins. Deployments run on GitHub Actions; credentials live in GitHub secrets, never in this database.</p>';
|
|
162
|
+
self::notices();
|
|
163
|
+
self::tabs( Ops::PAGE, $tabs, $tab );
|
|
164
|
+
|
|
165
|
+
if ( 'repository' === $tab ) {
|
|
166
|
+
$branches = array_map( static fn( $b ): string => (string) ( $b['name'] ?? '' ), (array) ( $status['branches'] ?? [] ) );
|
|
167
|
+
|
|
168
|
+
echo '<p style="margin-top:16px">' . self::state( $admin['token']['set'], 'GitHub access ready', 'No GitHub token' ) . self::state( null !== ( $status['repo'] ?? null ), 'Platform repository reachable', '' === $settings['repo'] ? 'Platform repository not connected' : 'Platform repository not reachable' ) . '</p>'; // phpcs:ignore
|
|
169
|
+
|
|
170
|
+
if ( ! empty( $status['error'] ) ) {
|
|
171
|
+
printf( '<div class="notice notice-error inline"><p>%s</p></div>', esc_html( $status['error'] ) );
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if ( ! $admin['token']['set'] ) {
|
|
175
|
+
printf( '<p>Create a fine-grained token for the platform repository with <strong>Contents</strong>, <strong>Actions</strong>, <strong>Secrets</strong> and <strong>Environments</strong> (read and write), then add it to <code>wp-config.php</code>:</p><p><code>define( \'%s\', \'github_pat_…\' );</code></p>', esc_html( $admin['token']['constant'] ) );
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
self::open( 'ops_save', Ops::PAGE, $tab );
|
|
179
|
+
echo '<table class="form-table" role="presentation">';
|
|
180
|
+
printf( '<tr><th scope="row"><label for="p-url">Platform repository URL</label></th><td><input id="p-url" name="url" type="url" class="regular-text code" placeholder="https://github.com/owner/platform" value="%s"></td></tr>', esc_attr( $settings['url'] ) );
|
|
181
|
+
echo '<tr><th scope="row"><label for="p-branch">Branch</label></th><td>';
|
|
182
|
+
if ( $branches ) {
|
|
183
|
+
printf( '<select id="p-branch" name="branch"><option value="">Default (%s)</option>', esc_html( (string) ( $status['repo']['default'] ?? 'main' ) ) );
|
|
184
|
+
foreach ( $branches as $branch ) {
|
|
185
|
+
printf( '<option value="%1$s"%2$s>%1$s</option>', esc_attr( $branch ), selected( $settings['branch'], $branch, false ) );
|
|
186
|
+
}
|
|
187
|
+
echo '</select>';
|
|
188
|
+
} else {
|
|
189
|
+
printf( '<input id="p-branch" name="branch" class="regular-text code" placeholder="main" value="%s">', esc_attr( $settings['branch'] ) );
|
|
190
|
+
}
|
|
191
|
+
echo '<p class="description">Deployments run from this branch.</p></td></tr>';
|
|
192
|
+
printf( '<tr><th scope="row"><label for="p-packages">Plugins folder</label></th><td><input id="p-packages" name="packages" class="regular-text code" value="%s"><p class="description">Packages whose composer.json has <code>"type": "psr4-plugin"</code>.</p></td></tr>', esc_attr( $settings['packages'] ) );
|
|
193
|
+
foreach ( [ 'apps' => 'Deploy apps workflow', 'platform' => 'Deploy platform workflow', 'composer' => 'Composer workflow' ] as $key => $label ) {
|
|
194
|
+
printf( '<tr><th scope="row"><label for="p-wf-%1$s">%2$s</label></th><td><input id="p-wf-%1$s" name="workflows[%1$s]" class="regular-text code" value="%3$s"></td></tr>', esc_attr( $key ), esc_html( $label ), esc_attr( (string) ( $settings['workflows'][ $key ] ?? '' ) ) );
|
|
195
|
+
}
|
|
196
|
+
echo '</table>';
|
|
197
|
+
submit_button( 'Save' );
|
|
198
|
+
echo '</form>';
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if ( 'folders' === $tab ) {
|
|
202
|
+
echo '<h2>App folders</h2><p class="description">Root folders of the platform repository, one per kind of app. Each kind has a manifest that maps app slugs to their server path.</p>';
|
|
203
|
+
self::open( 'ops_kinds', Ops::PAGE, $tab );
|
|
204
|
+
echo '<table class="widefat striped" style="max-width:1000px"><thead><tr><th>Key</th><th>Label</th><th>Folder</th><th>Manifest</th></tr></thead><tbody>';
|
|
205
|
+
foreach ( array_merge( $settings['kinds'], [ [ 'key' => '', 'label' => '', 'folder' => '', 'manifest' => '' ] ] ) as $i => $kind ) {
|
|
206
|
+
echo '<tr>';
|
|
207
|
+
foreach ( [ 'key', 'label', 'folder', 'manifest' ] as $field ) {
|
|
208
|
+
printf( '<td><input name="kinds[%d][%s]" class="%s" style="width:100%%" value="%s"%s></td>', (int) $i, esc_attr( $field ), 'label' === $field ? '' : 'code', esc_attr( (string) $kind[ $field ] ), '' === $kind['key'] && 'key' === $field ? ' placeholder="Add a kind…"' : '' );
|
|
209
|
+
}
|
|
210
|
+
echo '</tr>';
|
|
211
|
+
}
|
|
212
|
+
echo '</tbody></table><p class="description">Clear a row to remove it.</p>';
|
|
213
|
+
submit_button( 'Save app folders' );
|
|
214
|
+
echo '</form>';
|
|
215
|
+
|
|
216
|
+
echo '<h2>Apps in the platform repository</h2><p class="description">Where each app from the app manager lives. The folder name is usually the domain.</p>';
|
|
217
|
+
if ( $admin['token']['set'] && '' !== $settings['repo'] ) {
|
|
218
|
+
echo '<p>';
|
|
219
|
+
self::inline( 'ops_import', Ops::PAGE, $tab, 'Read ' . Ops::LAYOUT );
|
|
220
|
+
echo ' ';
|
|
221
|
+
self::inline( 'ops_detect', Ops::PAGE, $tab, 'Match apps from the platform repository' );
|
|
222
|
+
echo '</p>';
|
|
223
|
+
}
|
|
224
|
+
self::open( 'ops_apps', Ops::PAGE, $tab );
|
|
225
|
+
echo '<table class="widefat striped" style="max-width:1000px"><thead><tr><th>App</th><th>Kind</th><th>Folder name</th><th>Path</th></tr></thead><tbody>';
|
|
226
|
+
foreach ( $admin['apps'] as $app ) {
|
|
227
|
+
printf( '<tr><td><strong>%s</strong></td><td><select name="apps[%d][kind]">', esc_html( $app['name'] ), (int) $app['id'] );
|
|
228
|
+
foreach ( $settings['kinds'] as $kind ) {
|
|
229
|
+
printf( '<option value="%s"%s>%s</option>', esc_attr( $kind['key'] ), selected( $app['kind'], $kind['key'], false ), esc_html( $kind['label'] ) );
|
|
230
|
+
}
|
|
231
|
+
printf( '</select></td><td><input name="apps[%d][slug]" class="code" value="%s" placeholder="%s"></td><td><code>%s</code></td></tr>', (int) $app['id'], esc_attr( $app['slug'] ), esc_attr( $app['default'] ), esc_html( $app['path'] ) );
|
|
232
|
+
}
|
|
233
|
+
echo '</tbody></table>';
|
|
234
|
+
submit_button( 'Save apps' );
|
|
235
|
+
echo '</form>';
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if ( 'secrets' === $tab ) {
|
|
239
|
+
if ( ! Github::ready() || empty( $status['repo'] ) ) {
|
|
240
|
+
echo '<p style="margin-top:16px">Connect the platform repository and add the GitHub token first.</p></div>';
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
$rows = array_map( static fn( $s ): array => [ (string) $s['name'], '', (string) ( $s['updated_at'] ?? '' ) ], $status['secrets'] );
|
|
245
|
+
foreach ( $status['environments'] as $environment ) {
|
|
246
|
+
foreach ( (array) ( $environment['secrets'] ?? [] ) as $secret ) {
|
|
247
|
+
$rows[] = [ (string) $secret['name'], (string) $environment['name'], (string) ( $secret['updated_at'] ?? '' ) ];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
echo '<h2>GitHub Actions secrets</h2><p class="description">Sealed with the platform repository public key and sent straight to GitHub. Nothing is stored here; values can never be read back.</p>';
|
|
252
|
+
echo '<table class="widefat striped" style="max-width:1000px"><thead><tr><th>Name</th><th>Scope</th><th>Updated</th><th></th></tr></thead><tbody>';
|
|
253
|
+
if ( ! $rows ) {
|
|
254
|
+
echo '<tr><td colspan="4">No secrets yet.</td></tr>';
|
|
255
|
+
}
|
|
256
|
+
foreach ( $rows as [ $name, $environment, $updated ] ) {
|
|
257
|
+
printf( '<tr><td><code>%s</code></td><td>%s</td><td>%s</td><td style="text-align:right">', esc_html( $name ), esc_html( '' === $environment ? 'Repository' : $environment ), esc_html( $updated ? mysql2date( 'Y-m-d H:i', $updated ) : '' ) );
|
|
258
|
+
self::inline( 'ops_secret_delete', Ops::PAGE, $tab, 'Delete', [ 'name' => $name, 'environment' => $environment ], 'button-link button-link-delete', 'Delete ' . $name . '?' );
|
|
259
|
+
echo '</td></tr>';
|
|
260
|
+
}
|
|
261
|
+
echo '</tbody></table><h3>Add or replace a secret</h3>';
|
|
262
|
+
self::open( 'ops_secret', Ops::PAGE, $tab );
|
|
263
|
+
echo '<table class="form-table" role="presentation"><tr><th scope="row"><label for="s-name">Name</label></th><td><input id="s-name" name="name" list="s-presets" class="regular-text code" required autocomplete="off"><datalist id="s-presets">';
|
|
264
|
+
foreach ( $admin['presets'] as $preset ) {
|
|
265
|
+
printf( '<option value="%s">', esc_attr( $preset ) );
|
|
266
|
+
}
|
|
267
|
+
echo '</datalist></td></tr><tr><th scope="row"><label for="s-value">Value</label></th><td><textarea id="s-value" name="value" rows="4" class="large-text code" required autocomplete="off" spellcheck="false"></textarea></td></tr>';
|
|
268
|
+
echo '<tr><th scope="row"><label for="s-scope">Scope</label></th><td><select id="s-scope" name="environment"><option value="">Repository</option>';
|
|
269
|
+
foreach ( $status['environments'] as $environment ) {
|
|
270
|
+
printf( '<option value="%1$s">Environment: %1$s</option>', esc_attr( (string) $environment['name'] ) );
|
|
271
|
+
}
|
|
272
|
+
echo '</select></td></tr></table>';
|
|
273
|
+
submit_button( 'Send to GitHub' );
|
|
274
|
+
echo '</form>';
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if ( 'actions' === $tab ) {
|
|
278
|
+
if ( ! Github::ready() || empty( $status['repo'] ) ) {
|
|
279
|
+
echo '<p style="margin-top:16px">Connect the platform repository and add the GitHub token first.</p></div>';
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
echo '<h2>Workflows</h2><table class="widefat striped" style="max-width:1000px"><thead><tr><th>Workflow</th><th>File</th><th>State</th><th></th></tr></thead><tbody>';
|
|
284
|
+
if ( ! $status['workflows'] ) {
|
|
285
|
+
echo '<tr><td colspan="4">No workflows in .github/workflows.</td></tr>';
|
|
286
|
+
}
|
|
287
|
+
foreach ( $status['workflows'] as $workflow ) {
|
|
288
|
+
$file = basename( (string) $workflow['path'] );
|
|
289
|
+
printf( '<tr><td>%s</td><td><code>%s</code></td><td>%s</td><td style="text-align:right">', esc_html( (string) $workflow['name'] ), esc_html( $file ), esc_html( (string) $workflow['state'] ) );
|
|
290
|
+
self::inline( 'ops_run', Ops::PAGE, $tab, 'Run', [ 'workflow' => $file ] );
|
|
291
|
+
echo '</td></tr>';
|
|
292
|
+
}
|
|
293
|
+
echo '</tbody></table><h2>Recent runs</h2><table class="widefat striped" style="max-width:1000px"><thead><tr><th>Run</th><th>Branch</th><th>Event</th><th>Result</th><th>Started</th></tr></thead><tbody>';
|
|
294
|
+
if ( ! $status['runs'] ) {
|
|
295
|
+
echo '<tr><td colspan="5">No runs yet.</td></tr>';
|
|
296
|
+
}
|
|
297
|
+
foreach ( $status['runs'] as $run ) {
|
|
298
|
+
printf( '<tr><td><a href="%s" target="_blank" rel="noopener">%s</a></td><td><code>%s</code></td><td>%s</td><td>%s</td><td>%s</td></tr>', esc_url( (string) $run['html_url'] ), esc_html( (string) ( $run['display_title'] ?? $run['name'] ) ), esc_html( (string) $run['head_branch'] ), esc_html( (string) $run['event'] ), esc_html( (string) ( $run['conclusion'] ?: $run['status'] ) ), esc_html( mysql2date( 'Y-m-d H:i', (string) $run['created_at'] ) ) );
|
|
299
|
+
}
|
|
300
|
+
echo '</tbody></table>';
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if ( 'sandboxes' === $tab ) {
|
|
304
|
+
echo '<h2>Sandboxes</h2><p class="description">Runtimes that serve app previews with <code>@wp-operations/wp-app</code>. The builder leases the first free, online one to an app, in this order.</p>';
|
|
305
|
+
echo '<table class="widefat striped" style="max-width:1100px"><thead><tr><th>Sandbox</th><th>Runtime URL</th><th>Preview path</th><th>Token constant</th><th>State</th><th>In use by</th><th></th></tr></thead><tbody>';
|
|
306
|
+
if ( ! $admin['sandboxes'] ) {
|
|
307
|
+
echo '<tr><td colspan="7">No sandboxes yet.</td></tr>';
|
|
308
|
+
}
|
|
309
|
+
foreach ( $admin['sandboxes'] as $sandbox ) {
|
|
310
|
+
printf( '<tr><td><strong>%s</strong>%s</td><td><code>%s</code></td><td><code>%s</code></td><td>%s</td><td>%s</td><td>%s</td><td style="text-align:right">', esc_html( $sandbox['label'] ), $sandbox['enabled'] ? '' : ' <em>(off)</em>', esc_html( $sandbox['url'] ), esc_html( $sandbox['preview'] ), '' === $sandbox['token_constant'] ? '—' : '<code>' . esc_html( $sandbox['token_constant'] ) . '</code>', self::state( ! empty( $sandbox['state']['up'] ), 'Online', (string) ( $sandbox['state']['error'] ?? '' ) ?: 'Offline' ), esc_html( (string) ( $sandbox['state']['app'] ?? '' ) ) ); // phpcs:ignore
|
|
311
|
+
self::inline( 'ops_sandbox_delete', Ops::PAGE, $tab, 'Remove', [ 'key' => $sandbox['key'] ], 'button-link button-link-delete', 'Remove ' . $sandbox['label'] . '?' );
|
|
312
|
+
echo '</td></tr>';
|
|
313
|
+
}
|
|
314
|
+
echo '</tbody></table><h3>Add or update a sandbox</h3><p class="description">Use the same name to update an existing sandbox.</p>';
|
|
315
|
+
self::open( 'ops_sandbox', Ops::PAGE, $tab );
|
|
316
|
+
echo '<table class="form-table" role="presentation">';
|
|
317
|
+
echo '<tr><th scope="row"><label for="b-label">Name</label></th><td><input id="b-label" name="sandbox[label]" class="regular-text" required placeholder="Runtime 1"></td></tr>';
|
|
318
|
+
echo '<tr><th scope="row"><label for="b-url">Runtime URL</label></th><td><input id="b-url" name="sandbox[url]" type="url" class="regular-text code" required placeholder="https://sandbox-1.example.com"></td></tr>';
|
|
319
|
+
echo '<tr><th scope="row"><label for="b-health">Health path</label></th><td><input id="b-health" name="sandbox[health]" class="regular-text code" value="/"></td></tr>';
|
|
320
|
+
echo '<tr><th scope="row"><label for="b-preview">Preview path</label></th><td><input id="b-preview" name="sandbox[preview]" class="regular-text code" value="/{kind}/{slug}/"><p class="description"><code>{kind}</code> <code>{slug}</code> <code>{path}</code> <code>{branch}</code></p></td></tr>';
|
|
321
|
+
echo '<tr><th scope="row"><label for="b-token">Token constant</label></th><td><input id="b-token" name="sandbox[token_constant]" class="regular-text code" placeholder="PLATFORM_SANDBOX_TOKEN"><p class="description">Optional. Sent as a Bearer token on health checks; the value stays in wp-config.php.</p></td></tr>';
|
|
322
|
+
echo '<tr><th scope="row">Enabled</th><td><label><input type="checkbox" name="sandbox[enabled]" value="1" checked> Use for previews</label></td></tr></table>';
|
|
323
|
+
submit_button( 'Save sandbox' );
|
|
324
|
+
echo '</form>';
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
echo '</div>';
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
public static function models(): void {
|
|
331
|
+
$admin = Engine::admin();
|
|
332
|
+
$settings = $admin['settings'];
|
|
333
|
+
$providers = array_merge( (array) $settings['providers'], [ [ 'key' => '', 'label' => '', 'format' => 'openai', 'base_url' => '', 'model' => '', 'key_constant' => '', 'max_tokens' => 8192, 'temperature' => 0.2, 'key_set' => false ] ] );
|
|
334
|
+
$chat = array_filter( (array) $settings['providers'], static fn( array $p ): bool => 'images' !== $p['format'] );
|
|
335
|
+
$images = array_filter( (array) $settings['providers'], static fn( array $p ): bool => 'images' === $p['format'] );
|
|
336
|
+
$select = static function ( string $name, array $list, string $current, string $empty ): void {
|
|
337
|
+
printf( '<select name="%s"><option value="">%s</option>', esc_attr( $name ), esc_html( $empty ) );
|
|
338
|
+
foreach ( $list as $p ) {
|
|
339
|
+
printf( '<option value="%s"%s>%s</option>', esc_attr( $p['key'] ), selected( $current, $p['key'], false ), esc_html( $p['label'] ) );
|
|
340
|
+
}
|
|
341
|
+
echo '</select>';
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
echo '<div class="wrap"><h1>AI Models</h1><p class="description">Any OpenAI-compatible <code>/chat/completions</code> endpoint, the Anthropic <code>/messages</code> API, or an OpenAI-compatible <code>/images/generations</code> endpoint for thumbnails. API keys stay in <code>wp-config.php</code>; only the constant name is saved here.</p>';
|
|
345
|
+
self::notices();
|
|
346
|
+
self::open( 'engine_save', Engine::PAGE );
|
|
347
|
+
echo '<table class="widefat striped" style="max-width:1200px"><thead><tr><th>Name</th><th>API format</th><th>Base URL</th><th>Model</th><th>Key constant</th><th>Max tokens</th><th>Temp.</th><th>Key</th></tr></thead><tbody>';
|
|
348
|
+
foreach ( $providers as $i => $p ) {
|
|
349
|
+
printf( '<tr><td><input type="hidden" name="providers[%1$d][key]" value="%2$s"><input name="providers[%1$d][label]" style="width:100%%" value="%3$s"%4$s></td><td><select name="providers[%1$d][format]">', (int) $i, esc_attr( $p['key'] ), esc_attr( $p['label'] ), '' === $p['key'] ? ' placeholder="Add a model…"' : '' );
|
|
350
|
+
foreach ( $admin['formats'] as $key => $label ) {
|
|
351
|
+
printf( '<option value="%s"%s>%s</option>', esc_attr( $key ), selected( $p['format'], $key, false ), esc_html( $label ) );
|
|
352
|
+
}
|
|
353
|
+
printf(
|
|
354
|
+
'</select></td><td><input name="providers[%1$d][base_url]" class="code" style="width:100%%" value="%2$s" placeholder="https://api.openai.com/v1"></td><td><input name="providers[%1$d][model]" class="code" style="width:100%%" value="%3$s"></td><td><input name="providers[%1$d][key_constant]" class="code" style="width:100%%" value="%4$s" placeholder="PLATFORM_AI_KEY"></td><td><input type="number" min="256" style="width:90px" name="providers[%1$d][max_tokens]" value="%5$d"></td><td><input type="number" min="0" max="1" step="0.05" style="width:70px" name="providers[%1$d][temperature]" value="%6$s"></td><td style="white-space:nowrap">%7$s</td></tr>',
|
|
355
|
+
(int) $i,
|
|
356
|
+
esc_attr( $p['base_url'] ),
|
|
357
|
+
esc_attr( $p['model'] ),
|
|
358
|
+
esc_attr( $p['key_constant'] ),
|
|
359
|
+
(int) $p['max_tokens'],
|
|
360
|
+
esc_attr( (string) $p['temperature'] ),
|
|
361
|
+
'' === $p['key'] ? '' : ( $p['key_set'] ? '<span style="color:#00a32a">●</span> set' : '<span style="color:#d63638">●</span> missing' )
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
echo '</tbody></table><table class="form-table" role="presentation">';
|
|
365
|
+
echo '<tr><th scope="row">Default model</th><td>';
|
|
366
|
+
$select( 'default', $chat, (string) $settings['default'], 'First model' );
|
|
367
|
+
echo '</td></tr><tr><th scope="row">Images</th><td>';
|
|
368
|
+
$select( 'modes[image]', $images, (string) ( $settings['modes']['image'] ?? '' ), 'First image model' );
|
|
369
|
+
echo '<p class="description">Used for AI thumbnails.</p></td></tr>';
|
|
370
|
+
foreach ( $admin['modes'] as $mode ) {
|
|
371
|
+
printf( '<tr><th scope="row">%s mode</th><td>', esc_html( (string) ( $mode['label'] ?? $mode['key'] ) ) );
|
|
372
|
+
$select( 'modes[' . $mode['key'] . ']', $chat, (string) ( $settings['modes'][ $mode['key'] ] ?? '' ), 'Default model' );
|
|
373
|
+
echo '</td></tr>';
|
|
374
|
+
}
|
|
375
|
+
printf( '<tr><th scope="row"><label for="e-branch">Work branch</label></th><td><input id="e-branch" name="branch" class="regular-text code" value="%s"><p class="description">Approved changes are committed here, never to the deploy branch. <code>{slug}</code> <code>{kind}</code></p></td></tr>', esc_attr( (string) $settings['branch'] ) );
|
|
376
|
+
printf( '<tr><th scope="row"><label for="e-history">Conversation memory</label></th><td><input id="e-history" type="number" min="0" max="20" name="history" value="%d"> previous turns</td></tr>', (int) $settings['history'] );
|
|
377
|
+
printf( '<tr><th scope="row"><label for="e-rules">Platform rules</label></th><td><textarea id="e-rules" name="rules" rows="6" class="large-text code">%s</textarea><p class="description">Added after the built-in rules, which cannot be turned off: do only what was asked, never invent code or paths, ask instead of guessing, stay inside the app folder, propose only — a person commits.</p></td></tr>', esc_textarea( (string) $settings['rules'] ) );
|
|
378
|
+
echo '</table>';
|
|
379
|
+
submit_button( 'Save models' );
|
|
380
|
+
echo '</form>';
|
|
381
|
+
|
|
382
|
+
if ( $settings['providers'] ) {
|
|
383
|
+
echo '<h2>Test a connection</h2>';
|
|
384
|
+
self::open( 'engine_test', Engine::PAGE );
|
|
385
|
+
echo '<select name="provider">';
|
|
386
|
+
foreach ( (array) $settings['providers'] as $p ) {
|
|
387
|
+
printf( '<option value="%s">%s</option>', esc_attr( $p['key'] ), esc_html( $p['label'] ) );
|
|
388
|
+
}
|
|
389
|
+
echo '</select> ';
|
|
390
|
+
submit_button( 'Test', 'secondary', 'submit', false );
|
|
391
|
+
echo '</form>';
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
echo '</div>';
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
public static function usage(): void {
|
|
398
|
+
$data = Usage::admin();
|
|
399
|
+
$series = $data['series'];
|
|
400
|
+
$max = max( 1, max( array_column( $series, 'prompts' ) ?: [ 0 ] ), max( array_column( $series, 'credits' ) ?: [ 0 ] ) );
|
|
401
|
+
$points = static function ( string $key ) use ( $series, $max ): string {
|
|
402
|
+
$n = max( 1, count( $series ) - 1 );
|
|
403
|
+
return implode( ' ', array_map( static fn( $i, $row ): string => round( $i * 700 / $n, 1 ) . ',' . round( 150 - ( (float) $row[ $key ] / $max ) * 140, 1 ), array_keys( $series ), $series ) );
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
echo '<div class="wrap"><h1>Prompt Users</h1>';
|
|
407
|
+
self::notices();
|
|
408
|
+
printf( '<p class="description">Roles %s get the <code>%s</code> capability%s. %s credit per prompt; monthly limit %s; alerts at %d%%.</p>', esc_html( implode( ', ', $data['rules']['include'] ) ), esc_html( $data['rules']['capability'] ), $data['rules']['exclude'] ? esc_html( ', except ' . implode( ', ', $data['rules']['exclude'] ) ) : '', esc_html( (string) $data['rules']['per_prompt'] ), $data['rules']['monthly'] ? (int) $data['rules']['monthly'] : 'none', (int) $data['rules']['alert_at'] );
|
|
409
|
+
printf( '<div style="display:flex;gap:12px;margin:16px 0"><div class="card" style="margin:0;min-width:160px"><p>Prompts · 30 days</p><h2>%s</h2></div><div class="card" style="margin:0;min-width:160px"><p>Credits · 30 days</p><h2>%s</h2></div><div class="card" style="margin:0;min-width:160px"><p>People with access</p><h2>%d</h2></div></div>', esc_html( number_format_i18n( $data['totals']['prompts'] ) ), esc_html( number_format_i18n( $data['totals']['credits'], 1 ) ), (int) $data['totals']['users'] );
|
|
410
|
+
printf( '<div class="card" style="max-width:740px"><h2>Last 30 days</h2><svg viewBox="0 0 700 160" style="width:100%%;height:auto"><polyline points="%s" fill="none" stroke="#2271b1" stroke-width="2"/><polyline points="%s" fill="none" stroke="#8c8f94" stroke-width="1.5" stroke-dasharray="4 3"/></svg><p class="description"><span style="color:#2271b1">━</span> prompts <span style="color:#8c8f94">┅</span> credits</p></div>', esc_attr( $points( 'prompts' ) ), esc_attr( $points( 'credits' ) ) );
|
|
411
|
+
|
|
412
|
+
self::open( 'usage_save', Usage::PAGE );
|
|
413
|
+
echo '<h2>People</h2><table class="widefat striped" style="max-width:1100px"><thead><tr><th>Person</th><th>Role</th><th>Access</th><th>This month</th><th>Limit</th><th>Last prompt</th></tr></thead><tbody>';
|
|
414
|
+
foreach ( $data['users'] as $u ) {
|
|
415
|
+
printf( '<tr><td><strong>%s</strong><br><span class="description">%s</span></td><td>%s</td><td><select name="users[%d][access]">', esc_html( $u['name'] ), esc_html( $u['email'] ), esc_html( implode( ', ', $u['roles'] ) ), (int) $u['id'] );
|
|
416
|
+
foreach ( [ '' => $u['by_role'] ? 'By role · yes' : 'By role · no', 'allow' => 'Always', 'deny' => 'Never' ] as $value => $label ) {
|
|
417
|
+
printf( '<option value="%s"%s>%s</option>', esc_attr( $value ), selected( $u['override'], $value, false ), esc_html( $label ) );
|
|
418
|
+
}
|
|
419
|
+
printf( '</select></td><td>%s / %s (%s%%)</td><td><input type="number" min="0" name="users[%d][limit]" value="%s" placeholder="%s" style="width:90px"></td><td>%s</td></tr>', esc_html( (string) round( (float) $u['usage']['credits'], 1 ) ), esc_html( $u['usage']['limit'] ? (string) $u['usage']['limit'] : '∞' ), esc_html( (string) $u['usage']['percent'] ), (int) $u['id'], esc_attr( $u['limit'] ), esc_attr( $data['rules']['monthly'] ? (string) $data['rules']['monthly'] : '∞' ), esc_html( $u['last'] ? human_time_diff( strtotime( $u['last'] . ' UTC' ) ) . ' ago' : 'Never' ) );
|
|
420
|
+
}
|
|
421
|
+
echo '</tbody></table>';
|
|
422
|
+
if ( $data['candidates'] ) {
|
|
423
|
+
echo '<p><label for="u-grant">Give someone access: </label><select id="u-grant" name="grant"><option value="">Choose a person…</option>';
|
|
424
|
+
foreach ( $data['candidates'] as $c ) {
|
|
425
|
+
printf( '<option value="%d">%s (%s)</option>', (int) $c['id'], esc_html( $c['name'] ), esc_html( $c['email'] ) );
|
|
426
|
+
}
|
|
427
|
+
echo '</select></p>';
|
|
428
|
+
}
|
|
429
|
+
submit_button( 'Save people' );
|
|
430
|
+
echo '</form>';
|
|
431
|
+
|
|
432
|
+
if ( $data['alerts'] ) {
|
|
433
|
+
echo '<h2>Alerts</h2><ul>';
|
|
434
|
+
foreach ( $data['alerts'] as $alert ) {
|
|
435
|
+
printf( '<li>%s <span class="description">%s</span></li>', esc_html( (string) $alert['message'] ), esc_html( mysql2date( 'Y-m-d H:i', (string) $alert['at'] ) ) );
|
|
436
|
+
}
|
|
437
|
+
echo '</ul>';
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
echo '</div>';
|
|
441
|
+
}
|
|
442
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
namespace Platform\App;
|
|
3
|
+
|
|
4
|
+
use Platform\Identity;
|
|
5
|
+
use Platform\Platform;
|
|
6
|
+
|
|
7
|
+
defined( 'ABSPATH' ) || exit;
|
|
8
|
+
|
|
9
|
+
final class App {
|
|
10
|
+
|
|
11
|
+
public static function register(): void {
|
|
12
|
+
add_action( 'login_enqueue_scripts', [ __CLASS__, 'login_style' ] );
|
|
13
|
+
add_filter( 'show_admin_bar', [ __CLASS__, 'admin_bar' ] );
|
|
14
|
+
add_action( 'template_redirect', [ __CLASS__, 'only_app' ], 1 );
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public static function only_app(): void {
|
|
18
|
+
if ( is_robots() || is_favicon() ) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if ( ! is_front_page() || is_paged() || is_feed() ) {
|
|
23
|
+
wp_safe_redirect( home_url( '/' ), 301 );
|
|
24
|
+
exit;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static function theme(): string {
|
|
29
|
+
$theme = (array) Module::config( 'theme', [] );
|
|
30
|
+
$vars = [];
|
|
31
|
+
$clean = static fn( $value ): string => preg_replace( '/[^#A-Za-z0-9 ().,%\/_-]/', '', (string) $value );
|
|
32
|
+
|
|
33
|
+
foreach ( (array) ( $theme['colors'] ?? [] ) as $key => $value ) {
|
|
34
|
+
$vars[] = '--color-' . sanitize_key( (string) $key ) . ':' . $clean( $value );
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
foreach ( (array) ( $theme['radius'] ?? [] ) as $key => $value ) {
|
|
38
|
+
$vars[] = '--radius-' . sanitize_key( (string) $key ) . ':' . $clean( $value );
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ( ! empty( $theme['font'] ) ) {
|
|
42
|
+
$vars[] = '--font-sans:"' . $clean( $theme['font'] ) . '",ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return $vars ? ':root{' . implode( ';', $vars ) . '}' : '';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
public static function admin_bar( bool $show ): bool {
|
|
50
|
+
return is_admin() ? $show : false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public static function login_style(): void {
|
|
54
|
+
wp_enqueue_style( 'platform-login', Platform::url( 'assets/app/login.css' ), [], Platform::asset_version( 'assets/app/login.css' ) );
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public static function render(): void {
|
|
58
|
+
nocache_headers();
|
|
59
|
+
|
|
60
|
+
if ( ! is_user_logged_in() ) {
|
|
61
|
+
self::page( 'login' );
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if ( ! Access::can() ) {
|
|
66
|
+
self::page( 'denied' );
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
$brand = Identity::brand();
|
|
71
|
+
$boot = [
|
|
72
|
+
'root' => esc_url_raw( rest_url( Rest::NS . '/' ) ),
|
|
73
|
+
'nonce' => wp_create_nonce( 'wp_rest' ),
|
|
74
|
+
'assets' => Platform::url( 'assets/' ),
|
|
75
|
+
'brand' => $brand,
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
$embed = sanitize_key( (string) ( $_GET['embed'] ?? '' ) );
|
|
79
|
+
|
|
80
|
+
if ( in_array( $embed, [ 'operations', 'models', 'usage' ], true ) && current_user_can( 'manage_options' ) ) {
|
|
81
|
+
$boot['embed'] = $embed;
|
|
82
|
+
}
|
|
83
|
+
?>
|
|
84
|
+
<!doctype html>
|
|
85
|
+
<html lang="<?php echo esc_attr( get_bloginfo( 'language' ) ); ?>" class="dark">
|
|
86
|
+
<head>
|
|
87
|
+
<meta charset="<?php echo esc_attr( get_bloginfo( 'charset' ) ); ?>">
|
|
88
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
89
|
+
<meta name="theme-color" content="<?php echo esc_attr( (string) Module::config( 'theme.colors.bg', '#09090b' ) ); ?>">
|
|
90
|
+
<title><?php echo esc_html( $brand['name'] ); ?></title>
|
|
91
|
+
<?php Identity::icon(); ?>
|
|
92
|
+
<link rel="stylesheet" href="<?php echo esc_url( Platform::url( 'assets/app/app.css' ) . '?ver=' . Platform::asset_version( 'assets/app/app.css' ) ); ?>">
|
|
93
|
+
<style id="platform-theme"><?php echo self::theme(); ?></style>
|
|
94
|
+
<?php if ( '' !== wp_get_custom_css() ) : ?>
|
|
95
|
+
<style id="custom-css"><?php echo wp_strip_all_tags( wp_get_custom_css() ); ?></style>
|
|
96
|
+
<?php endif; ?>
|
|
97
|
+
</head>
|
|
98
|
+
<body>
|
|
99
|
+
<div id="app"></div>
|
|
100
|
+
<script>window.platformBoot =<?php echo wp_json_encode( $boot ); ?>;</script>
|
|
101
|
+
<script type="module" src="<?php echo esc_url( Platform::url( 'assets/app/app.js' ) . '?ver=' . Platform::asset_version( 'assets/app/app.js' ) ); ?>"></script>
|
|
102
|
+
</body>
|
|
103
|
+
</html>
|
|
104
|
+
<?php
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private static function page( string $view ): void {
|
|
108
|
+
$brand = Identity::brand();
|
|
109
|
+
$user = wp_get_current_user();
|
|
110
|
+
?>
|
|
111
|
+
<!doctype html>
|
|
112
|
+
<html lang="<?php echo esc_attr( get_bloginfo( 'language' ) ); ?>" class="dark">
|
|
113
|
+
<head>
|
|
114
|
+
<meta charset="<?php echo esc_attr( get_bloginfo( 'charset' ) ); ?>">
|
|
115
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
116
|
+
<meta name="theme-color" content="<?php echo esc_attr( (string) Module::config( 'theme.colors.bg', '#09090b' ) ); ?>">
|
|
117
|
+
<title><?php echo esc_html( 'login' === $view ? 'Sign in · ' . $brand['name'] : $brand['name'] ); ?></title>
|
|
118
|
+
<?php Identity::icon(); ?>
|
|
119
|
+
<link rel="stylesheet" href="<?php echo esc_url( Platform::url( 'assets/app/login.css' ) . '?ver=' . Platform::asset_version( 'assets/app/login.css' ) ); ?>">
|
|
120
|
+
</head>
|
|
121
|
+
<body class="platform-gate">
|
|
122
|
+
<main class="gate">
|
|
123
|
+
<section class="gate__card">
|
|
124
|
+
<?php if ( '' !== $brand['logo'] ) : ?>
|
|
125
|
+
<img class="gate__mark" src="<?php echo esc_url( $brand['logo'] ); ?>" alt="">
|
|
126
|
+
<?php endif; ?>
|
|
127
|
+
<?php if ( 'login' === $view ) : ?>
|
|
128
|
+
<h1>Sign in to <?php echo esc_html( $brand['name'] ); ?></h1>
|
|
129
|
+
<?php
|
|
130
|
+
wp_login_form(
|
|
131
|
+
[
|
|
132
|
+
'redirect' => home_url( '/' ),
|
|
133
|
+
'label_username' => 'Email or username',
|
|
134
|
+
'label_remember' => 'Remember me',
|
|
135
|
+
'label_log_in' => 'Sign in',
|
|
136
|
+
'remember' => true,
|
|
137
|
+
]
|
|
138
|
+
);
|
|
139
|
+
?>
|
|
140
|
+
<a class="gate__link" href="<?php echo esc_url( wp_lostpassword_url( home_url( '/' ) ) ); ?>">Forgot your password?</a>
|
|
141
|
+
<?php else : ?>
|
|
142
|
+
<h1>No access yet</h1>
|
|
143
|
+
<p class="gate__lead">You're signed in as <?php echo esc_html( $user->display_name ); ?>, but your account can't use <?php echo esc_html( $brand['name'] ); ?>. Ask an administrator to give you access.</p>
|
|
144
|
+
<div class="gate__actions">
|
|
145
|
+
<?php if ( current_user_can( 'read' ) ) : ?>
|
|
146
|
+
<a class="gate__button" href="<?php echo esc_url( admin_url() ); ?>">Go to dashboard</a>
|
|
147
|
+
<?php endif; ?>
|
|
148
|
+
<a class="gate__button is-ghost" href="<?php echo esc_url( wp_logout_url( home_url( '/' ) ) ); ?>">Sign out</a>
|
|
149
|
+
</div>
|
|
150
|
+
<?php endif; ?>
|
|
151
|
+
</section>
|
|
152
|
+
</main>
|
|
153
|
+
</body>
|
|
154
|
+
</html>
|
|
155
|
+
<?php
|
|
156
|
+
}
|
|
157
|
+
}
|