@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,242 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
namespace Platform\Editors;
|
|
3
|
+
|
|
4
|
+
defined( 'ABSPATH' ) || exit;
|
|
5
|
+
|
|
6
|
+
final class Ebook {
|
|
7
|
+
public function __construct() {
|
|
8
|
+
add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] );
|
|
9
|
+
add_action( 'save_post_ebooks', [ $this, 'save_meta' ] );
|
|
10
|
+
|
|
11
|
+
add_action( 'wp_ajax_ebook_upload_pdf', [ $this, 'handle_pdf_upload' ] );
|
|
12
|
+
add_action( 'wp_ajax_ebook_delete_pdf', [ $this, 'handle_pdf_delete' ] );
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public function add_meta_boxes() {
|
|
16
|
+
add_meta_box(
|
|
17
|
+
'ebook_pdf_upload',
|
|
18
|
+
__( 'Ebook PDF Files' ),
|
|
19
|
+
[ $this, 'render_pdf_metabox' ],
|
|
20
|
+
'ebooks',
|
|
21
|
+
'normal',
|
|
22
|
+
'high'
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public function render_pdf_metabox( $post ) {
|
|
27
|
+
wp_nonce_field( 'ebook_save_pdf', 'ebook_pdf_nonce' );
|
|
28
|
+
|
|
29
|
+
$pdf_urls = get_post_meta( $post->ID, '_ebook_pdf_urls', true );
|
|
30
|
+
if ( ! is_array( $pdf_urls ) ) {
|
|
31
|
+
$pdf_urls = [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
$allow_downloads = get_post_meta( $post->ID, '_ebook_allow_downloads', true );
|
|
35
|
+
if ( ! is_array( $allow_downloads ) ) {
|
|
36
|
+
$allow_downloads = [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
$languages = Course::languages_for( 'ebooks' );
|
|
40
|
+
|
|
41
|
+
?>
|
|
42
|
+
<div class="ebook-metabox">
|
|
43
|
+
<style>
|
|
44
|
+
.ebook-lang-row { margin-bottom: 20px; border: 1px solid rgba(255,255,255,.08); padding: 15px; border-radius: 4px; background: #111113; }
|
|
45
|
+
.ebook-lang-row h4 { margin-top: 0; border-bottom: 1px solid rgba(255,255,255,.08); padding-bottom: 10px; }
|
|
46
|
+
.ebook-upload-area { border: 2px dashed rgba(255,255,255,.14); padding: 20px; text-align: center; background: #111113; cursor: pointer; transition: border-color 0.3s; }
|
|
47
|
+
.ebook-upload-area:hover { border-color: rgba(255,255,255,.35); }
|
|
48
|
+
.ebook-upload-area.has-file { border-style: solid; border-color: rgba(74,222,128,.35); background: rgba(74,222,128,.10); }
|
|
49
|
+
.ebook-file-preview { margin-top: 10px; display: flex; align-items: center; justify-content: space-between; }
|
|
50
|
+
.ebook-file-name { font-weight: 600; color: #fafafa; }
|
|
51
|
+
.ebook-progress { height: 10px; background: #17171a; border-radius: 5px; margin-top: 10px; overflow: hidden; display: none; }
|
|
52
|
+
.ebook-progress-bar { height: 100%; background: #fafafa; width: 0; transition: width 0.1s; }
|
|
53
|
+
</style>
|
|
54
|
+
|
|
55
|
+
<div style="margin-bottom: 20px;">
|
|
56
|
+
<label>
|
|
57
|
+
<input type="checkbox" name="ebook_allow_download" value="1" <?php checked( get_post_meta( $post->ID, '_ebook_allow_download', true ) ); ?>>
|
|
58
|
+
<?php _e( 'Enable Download for this PDF' ); ?>
|
|
59
|
+
</label>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<?php foreach ( $languages as $lang ) :
|
|
63
|
+
$code = $lang['code'];
|
|
64
|
+
$url = $pdf_urls[ $code ] ?? '';
|
|
65
|
+
?>
|
|
66
|
+
<div class="ebook-lang-row">
|
|
67
|
+
<h4><?php echo esc_html( $lang['name'] ); ?> (<?php echo esc_html( strtoupper( $code ) ); ?>)</h4>
|
|
68
|
+
|
|
69
|
+
<div class="ebook-upload-area <?php echo $url ? 'has-file' : ''; ?>"
|
|
70
|
+
data-lang="<?php echo esc_attr( $code ); ?>"
|
|
71
|
+
onclick="document.getElementById('ebook_file_<?php echo esc_attr($code); ?>').click();">
|
|
72
|
+
|
|
73
|
+
<div class="ebook-upload-prompt" style="<?php echo $url ? 'display:none;' : ''; ?>">
|
|
74
|
+
<span class="dashicons dashicons-upload" style="font-size: 40px; width: 40px; height: 40px; color: #999;"></span>
|
|
75
|
+
<p><?php _e( 'Click or Drag & Drop PDF file here' ); ?></p>
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<div class="ebook-file-preview" style="<?php echo $url ? '' : 'display:none;'; ?>">
|
|
79
|
+
<span class="dashicons dashicons-pdf" style="font-size: 30px; width: 30px; height: 30px; color: #d11;"></span>
|
|
80
|
+
<span class="ebook-file-name"><?php echo esc_html( basename( $url ) ); ?></span>
|
|
81
|
+
<div class="ebook-file-actions">
|
|
82
|
+
<button type="button" class="button button-small" onclick="event.stopPropagation(); window.open('<?php echo esc_url($url); ?>', '_blank');"><?php _e( 'View' ); ?></button>
|
|
83
|
+
<button type="button" class="button button-small ebook-remove-btn"
|
|
84
|
+
data-lang="<?php echo esc_attr( $code ); ?>"
|
|
85
|
+
onclick="event.stopPropagation(); ebookRemovePdf('<?php echo esc_attr($code); ?>');"><?php _e( 'Remove' ); ?></button>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
<div class="ebook-progress">
|
|
90
|
+
<div class="ebook-progress-bar"></div>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<input type="file" id="ebook_file_<?php echo esc_attr($code); ?>"
|
|
94
|
+
style="display:none;" accept="application/pdf"
|
|
95
|
+
onchange="ebookHandleUpload(this, '<?php echo esc_attr($code); ?>');">
|
|
96
|
+
|
|
97
|
+
<input type="hidden" name="ebook_pdf_urls[<?php echo esc_attr( $code ); ?>]"
|
|
98
|
+
id="ebook_url_<?php echo esc_attr($code); ?>"
|
|
99
|
+
value="<?php echo esc_attr( $url ); ?>">
|
|
100
|
+
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
<?php endforeach; ?>
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<script>
|
|
107
|
+
function ebookHandleUpload(input, lang) {
|
|
108
|
+
if (!input.files || !input.files[0]) return;
|
|
109
|
+
|
|
110
|
+
var file = input.files[0];
|
|
111
|
+
if (file.type !== 'application/pdf') {
|
|
112
|
+
alert('Please select a PDF file.');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var $area = jQuery('.ebook-upload-area[data-lang="' + lang + '"]');
|
|
117
|
+
var $prompt = $area.find('.ebook-upload-prompt');
|
|
118
|
+
var $preview = $area.find('.ebook-file-preview');
|
|
119
|
+
var $progress = $area.find('.ebook-progress');
|
|
120
|
+
var $progressBar = $area.find('.ebook-progress-bar');
|
|
121
|
+
var $hidden = jQuery('#ebook_url_' + lang);
|
|
122
|
+
|
|
123
|
+
var formData = new FormData();
|
|
124
|
+
formData.append('action', 'ebook_upload_pdf');
|
|
125
|
+
formData.append('pdf_file', file);
|
|
126
|
+
formData.append('nonce', '<?php echo wp_create_nonce("ebook_upload_pdf"); ?>');
|
|
127
|
+
|
|
128
|
+
$prompt.hide();
|
|
129
|
+
$preview.hide();
|
|
130
|
+
$progress.show();
|
|
131
|
+
$progressBar.css('width', '0%');
|
|
132
|
+
|
|
133
|
+
jQuery.ajax({
|
|
134
|
+
url: ajaxurl,
|
|
135
|
+
type: 'POST',
|
|
136
|
+
data: formData,
|
|
137
|
+
processData: false,
|
|
138
|
+
contentType: false,
|
|
139
|
+
xhr: function() {
|
|
140
|
+
var xhr = new window.XMLHttpRequest();
|
|
141
|
+
xhr.upload.addEventListener('progress', function(evt) {
|
|
142
|
+
if (evt.lengthComputable) {
|
|
143
|
+
var pct = Math.round((evt.loaded / evt.total) * 100);
|
|
144
|
+
$progressBar.css('width', pct + '%');
|
|
145
|
+
}
|
|
146
|
+
}, false);
|
|
147
|
+
return xhr;
|
|
148
|
+
},
|
|
149
|
+
success: function(response) {
|
|
150
|
+
if (response.success) {
|
|
151
|
+
$hidden.val(response.data.url);
|
|
152
|
+
$preview.find('.ebook-file-name').text(response.data.filename);
|
|
153
|
+
$preview.find('button').first().attr('onclick', "event.stopPropagation(); window.open('" + response.data.url + "', '_blank');");
|
|
154
|
+
|
|
155
|
+
$area.addClass('has-file');
|
|
156
|
+
$preview.show();
|
|
157
|
+
$progress.hide();
|
|
158
|
+
} else {
|
|
159
|
+
alert('Upload failed: ' + response.data);
|
|
160
|
+
$prompt.show();
|
|
161
|
+
$progress.hide();
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
error: function() {
|
|
165
|
+
alert('Ajax error during upload.');
|
|
166
|
+
$prompt.show();
|
|
167
|
+
$progress.hide();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function ebookRemovePdf(lang) {
|
|
173
|
+
if (!confirm('Are you sure you want to remove this PDF?')) return;
|
|
174
|
+
|
|
175
|
+
var $area = jQuery('.ebook-upload-area[data-lang="' + lang + '"]');
|
|
176
|
+
var $hidden = jQuery('#ebook_url_' + lang);
|
|
177
|
+
var url = $hidden.val();
|
|
178
|
+
|
|
179
|
+
jQuery.post(ajaxurl, {
|
|
180
|
+
action: 'ebook_delete_pdf',
|
|
181
|
+
url: url,
|
|
182
|
+
nonce: '<?php echo wp_create_nonce("ebook_delete_pdf"); ?>'
|
|
183
|
+
}, function(response) {
|
|
184
|
+
$hidden.val('');
|
|
185
|
+
$area.removeClass('has-file');
|
|
186
|
+
$area.find('.ebook-file-preview').hide();
|
|
187
|
+
$area.find('.ebook-upload-prompt').show();
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
</script>
|
|
191
|
+
<?php
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public function save_meta( $post_id ) {
|
|
195
|
+
if ( ! isset( $_POST['ebook_pdf_nonce'] ) || ! wp_verify_nonce( $_POST['ebook_pdf_nonce'], 'ebook_save_pdf' ) ) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if ( isset( $_POST['ebook_pdf_urls'] ) ) {
|
|
200
|
+
$urls = [];
|
|
201
|
+
foreach ( $_POST['ebook_pdf_urls'] as $lang => $url ) {
|
|
202
|
+
$urls[ sanitize_key($lang) ] = esc_url_raw($url);
|
|
203
|
+
}
|
|
204
|
+
update_post_meta( $post_id, '_ebook_pdf_urls', $urls );
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if ( isset( $_POST['ebook_allow_download'] ) ) {
|
|
208
|
+
update_post_meta( $post_id, '_ebook_allow_download', 1 );
|
|
209
|
+
} else {
|
|
210
|
+
update_post_meta( $post_id, '_ebook_allow_download', 0 );
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
public function handle_pdf_upload() {
|
|
216
|
+
check_ajax_referer( 'ebook_upload_pdf', 'nonce' );
|
|
217
|
+
|
|
218
|
+
if ( ! current_user_can( 'upload_files' ) ) {
|
|
219
|
+
wp_send_json_error( 'Permission denied' );
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
$stored = Files::store( 'pdf_file', 'ebooks', Files::PDF, 200 );
|
|
223
|
+
|
|
224
|
+
is_wp_error( $stored ) ? wp_send_json_error( $stored->get_error_message() ) : wp_send_json_success( $stored );
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
public function handle_pdf_delete() {
|
|
228
|
+
check_ajax_referer( 'ebook_delete_pdf', 'nonce' );
|
|
229
|
+
|
|
230
|
+
if ( ! current_user_can( 'upload_files' ) ) {
|
|
231
|
+
wp_send_json_error( 'Permission denied' );
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
$url = isset( $_POST['url'] ) ? esc_url_raw( wp_unslash( $_POST['url'] ) ) : '';
|
|
235
|
+
|
|
236
|
+
if ( '' === $url ) {
|
|
237
|
+
wp_send_json_error( 'No URL provided' );
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
Files::remove( $url, 'ebooks' ) ? wp_send_json_success() : wp_send_json_error( 'Could not delete file.' );
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
namespace Platform\Editors;
|
|
3
|
+
|
|
4
|
+
use Platform\Config;
|
|
5
|
+
|
|
6
|
+
defined( 'ABSPATH' ) || exit;
|
|
7
|
+
|
|
8
|
+
final class Editors {
|
|
9
|
+
|
|
10
|
+
const KINDS = [
|
|
11
|
+
'course' => [ Course::class ],
|
|
12
|
+
'audiobook' => [ AudiobookChapters::class, AudiobookCover::class, AudiobookAuthor::class, OriginalTitle::class ],
|
|
13
|
+
'audiofile' => [ Audiofile::class ],
|
|
14
|
+
'ebook' => [ Ebook::class ],
|
|
15
|
+
'interactive' => [ Interactive\Editor::class ],
|
|
16
|
+
'legal' => [ Legal::class ],
|
|
17
|
+
'faq' => [ Faq::class ],
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
public static function register(): void {
|
|
21
|
+
$kinds = array_unique( array_filter( array_column( Config::types(), 'editor' ) ) );
|
|
22
|
+
|
|
23
|
+
foreach ( $kinds as $kind ) {
|
|
24
|
+
foreach ( self::KINDS[ $kind ] ?? [] as $class ) {
|
|
25
|
+
method_exists( $class, 'register' ) ? $class::register() : new $class();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
OpenMedia::boot();
|
|
30
|
+
Sources::boot();
|
|
31
|
+
|
|
32
|
+
if ( Config::module( 'thumbnails' ) ) {
|
|
33
|
+
Thumbnails\Admin::register();
|
|
34
|
+
Thumbnails\Ajax::register();
|
|
35
|
+
Thumbnails\Box::register();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if ( Config::module( 'translations' ) ) {
|
|
39
|
+
Translator\Admin::register();
|
|
40
|
+
Translator\Bar::register();
|
|
41
|
+
Translator\Thumbnail::register();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
namespace Platform\Editors;
|
|
3
|
+
|
|
4
|
+
use Platform\Platform;
|
|
5
|
+
|
|
6
|
+
defined( 'ABSPATH' ) || exit;
|
|
7
|
+
|
|
8
|
+
final class Faq {
|
|
9
|
+
const NONCE = 'faqt_save';
|
|
10
|
+
|
|
11
|
+
const BOXES = array(
|
|
12
|
+
'faqt_page' => array(
|
|
13
|
+
'label' => 'FAQ Page Content',
|
|
14
|
+
'default_rows' => 3
|
|
15
|
+
),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
public static function register() {
|
|
19
|
+
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue' ) );
|
|
20
|
+
add_action( 'add_meta_boxes', array( __CLASS__, 'boxes' ) );
|
|
21
|
+
add_action( 'save_post_faq_template', array( __CLASS__, 'save' ) );
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public static function boxes() {
|
|
25
|
+
add_meta_box(
|
|
26
|
+
'faqt_panel',
|
|
27
|
+
'FAQ Content',
|
|
28
|
+
array( __CLASS__, 'render_panel' ),
|
|
29
|
+
'faq_template',
|
|
30
|
+
'normal',
|
|
31
|
+
'high'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static function render_panel( $post ) {
|
|
36
|
+
wp_nonce_field( self::NONCE, 'faqt_nonce' );
|
|
37
|
+
$keys = array_keys( self::BOXES );
|
|
38
|
+
?>
|
|
39
|
+
<div class="faq-panel">
|
|
40
|
+
|
|
41
|
+
<div class="faq-tabs" role="tablist">
|
|
42
|
+
<?php foreach ( self::BOXES as $key => $box ) :
|
|
43
|
+
$active = ( $key === $keys[0] );
|
|
44
|
+
?>
|
|
45
|
+
<button type="button"
|
|
46
|
+
class="faq-tab<?php echo $active ? ' is-active' : ''; ?>"
|
|
47
|
+
role="tab"
|
|
48
|
+
data-tab="<?php echo esc_attr( $key ); ?>"
|
|
49
|
+
aria-selected="<?php echo $active ? 'true' : 'false'; ?>">
|
|
50
|
+
<?php echo esc_html( $box['label'] ); ?>
|
|
51
|
+
<span class="faq-tab-count" id="faq-count-<?php echo esc_attr( $key ); ?>">0</span>
|
|
52
|
+
</button>
|
|
53
|
+
<?php endforeach; ?>
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
<?php foreach ( self::BOXES as $key => $box ) :
|
|
57
|
+
$active = ( $key === $keys[0] );
|
|
58
|
+
$rows = get_post_meta( $post->ID, "_{$key}", true );
|
|
59
|
+
|
|
60
|
+
if ( empty( $rows ) || ! is_array( $rows ) ) {
|
|
61
|
+
if ( ! empty( $box['defaults'] ) ) {
|
|
62
|
+
$rows = $box['defaults'];
|
|
63
|
+
} else {
|
|
64
|
+
$rows = array_fill( 0, $box['default_rows'], array( 'title' => '', 'content' => '' ) );
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
?>
|
|
68
|
+
<div class="faq-pane<?php echo $active ? ' is-active' : ''; ?>"
|
|
69
|
+
id="faq-pane-<?php echo esc_attr( $key ); ?>"
|
|
70
|
+
role="tabpanel">
|
|
71
|
+
|
|
72
|
+
<div class="faq-accordion"
|
|
73
|
+
id="faq-accordion-<?php echo esc_attr( $key ); ?>"
|
|
74
|
+
data-key="<?php echo esc_attr( $key ); ?>">
|
|
75
|
+
|
|
76
|
+
<?php foreach ( $rows as $i => $row ) : ?>
|
|
77
|
+
<?php self::render_item( $key, $i, $row['title'], $row['content'], $i === 0 ); ?>
|
|
78
|
+
<?php endforeach; ?>
|
|
79
|
+
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
<div class="faq-add-row">
|
|
83
|
+
<button type="button"
|
|
84
|
+
class="faq-btn-add"
|
|
85
|
+
data-accordion="faq-accordion-<?php echo esc_attr( $key ); ?>"
|
|
86
|
+
data-key="<?php echo esc_attr( $key ); ?>">
|
|
87
|
+
+ Add Item
|
|
88
|
+
</button>
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
</div>
|
|
92
|
+
<?php endforeach; ?>
|
|
93
|
+
|
|
94
|
+
</div>
|
|
95
|
+
<?php
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public static function render_item( $key, $index, $title = '', $content = '', $open = false ) {
|
|
99
|
+
$editor_id = 'faqt_editor_' . $key . '_' . $index;
|
|
100
|
+
$name_title = esc_attr( $key ) . '[' . intval( $index ) . '][title]';
|
|
101
|
+
$name_body = esc_attr( $key ) . '[' . intval( $index ) . '][content]';
|
|
102
|
+
$preview = $title ? esc_html( $title ) : 'Item ' . ( $index + 1 );
|
|
103
|
+
?>
|
|
104
|
+
<div class="faq-item<?php echo $open ? ' is-open' : ''; ?>" data-index="<?php echo intval( $index ); ?>">
|
|
105
|
+
|
|
106
|
+
<div class="faq-item-head">
|
|
107
|
+
<button type="button" class="faq-item-toggle" aria-expanded="<?php echo $open ? 'true' : 'false'; ?>">
|
|
108
|
+
<span class="faq-item-num"><?php echo intval( $index ) + 1; ?></span>
|
|
109
|
+
<span class="faq-item-preview"><?php echo $preview; ?></span>
|
|
110
|
+
<span class="faq-item-chevron">
|
|
111
|
+
<svg width="11" height="11" viewBox="0 0 11 11" fill="none" aria-hidden="true">
|
|
112
|
+
<path d="M1.5 3.5l4 4 4-4" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/>
|
|
113
|
+
</svg>
|
|
114
|
+
</span>
|
|
115
|
+
</button>
|
|
116
|
+
<button type="button" class="faq-item-remove" title="Remove" aria-label="Remove item">
|
|
117
|
+
<svg width="11" height="11" viewBox="0 0 11 11" fill="none" aria-hidden="true">
|
|
118
|
+
<path d="M1 1l9 9M10 1L1 10" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/>
|
|
119
|
+
</svg>
|
|
120
|
+
</button>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<div class="faq-item-body">
|
|
124
|
+
<div class="faq-field">
|
|
125
|
+
<label class="faq-field-label" for="<?php echo esc_attr( $editor_id ); ?>_title">Title</label>
|
|
126
|
+
<input type="text"
|
|
127
|
+
id="<?php echo esc_attr( $editor_id ); ?>_title"
|
|
128
|
+
name="<?php echo $name_title; ?>"
|
|
129
|
+
value="<?php echo esc_attr( $title ); ?>"
|
|
130
|
+
class="faq-title-input widefat"
|
|
131
|
+
placeholder="FAQ question or heading">
|
|
132
|
+
</div>
|
|
133
|
+
<div class="faq-field">
|
|
134
|
+
<label class="faq-field-label">Content</label>
|
|
135
|
+
<?php
|
|
136
|
+
wp_editor( $content, $editor_id, array(
|
|
137
|
+
'textarea_name' => $name_body,
|
|
138
|
+
'textarea_rows' => 6,
|
|
139
|
+
'media_buttons' => false,
|
|
140
|
+
'teeny' => false,
|
|
141
|
+
'quicktags' => true,
|
|
142
|
+
'tinymce' => array(
|
|
143
|
+
'toolbar1' => 'bold,italic,underline,strikethrough,separator,bullist,numlist,separator,link,unlink,separator,undo,redo',
|
|
144
|
+
'toolbar2' => '',
|
|
145
|
+
),
|
|
146
|
+
) );
|
|
147
|
+
?>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
</div>
|
|
152
|
+
<?php
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public static function save( $post_id ) {
|
|
156
|
+
if ( ! isset( $_POST['faqt_nonce'] ) || ! wp_verify_nonce( $_POST['faqt_nonce'], self::NONCE ) ) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
foreach ( array_keys( self::BOXES ) as $key ) {
|
|
169
|
+
if ( empty( $_POST[ $key ] ) || ! is_array( $_POST[ $key ] ) ) {
|
|
170
|
+
delete_post_meta( $post_id, "_{$key}" );
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
$rows = array();
|
|
175
|
+
foreach ( $_POST[ $key ] as $row ) {
|
|
176
|
+
$rows[] = array(
|
|
177
|
+
'title' => sanitize_text_field( isset( $row['title'] ) ? $row['title'] : '' ),
|
|
178
|
+
'content' => wp_kses_post( isset( $row['content'] ) ? $row['content'] : '' ),
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
update_post_meta( $post_id, "_{$key}", $rows );
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public static function get_page_rows( $post_id ) {
|
|
187
|
+
$rows = get_post_meta( $post_id, '_faqt_page', true );
|
|
188
|
+
return is_array( $rows ) ? $rows : array();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
public static function get_bot_rows( $post_id ) {
|
|
192
|
+
$rows = get_post_meta( $post_id, '_faqt_bot', true );
|
|
193
|
+
return is_array( $rows ) ? $rows : array();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public static function get_template_by_title( $title ) {
|
|
197
|
+
$results = get_posts( array(
|
|
198
|
+
'post_type' => 'faq_template',
|
|
199
|
+
'title' => $title,
|
|
200
|
+
'posts_per_page' => 1,
|
|
201
|
+
'post_status' => 'publish',
|
|
202
|
+
) );
|
|
203
|
+
|
|
204
|
+
return ! empty( $results ) ? $results[0] : null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public static function enqueue( $hook ) {
|
|
208
|
+
global $post_type;
|
|
209
|
+
|
|
210
|
+
if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if ( $post_type !== 'faq_template' ) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
wp_enqueue_style(
|
|
219
|
+
'faq-admin',
|
|
220
|
+
Platform::url( 'assets/editors/faq.css' ),
|
|
221
|
+
array(),
|
|
222
|
+
Platform::asset_version( 'assets/editors/faq.css' )
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
wp_enqueue_script(
|
|
226
|
+
'faq-admin',
|
|
227
|
+
Platform::url( 'assets/editors/faq.js' ),
|
|
228
|
+
array( 'editor' ),
|
|
229
|
+
Platform::asset_version( 'assets/editors/faq.js' ),
|
|
230
|
+
true
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
wp_localize_script( 'faq-admin', 'faqData', array(
|
|
234
|
+
'boxes' => self::BOXES,
|
|
235
|
+
) );
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
namespace Platform\Editors;
|
|
3
|
+
|
|
4
|
+
use Platform\Storage\Storage;
|
|
5
|
+
|
|
6
|
+
defined( 'ABSPATH' ) || exit;
|
|
7
|
+
|
|
8
|
+
final class Files {
|
|
9
|
+
|
|
10
|
+
const AUDIO = [
|
|
11
|
+
'mp3|mpga|mp2|mp2a|mpe|mpega' => 'audio/mpeg',
|
|
12
|
+
'wav' => 'audio/wav',
|
|
13
|
+
'ogg|oga' => 'audio/ogg',
|
|
14
|
+
'm4a' => 'audio/x-m4a',
|
|
15
|
+
'mp4' => 'audio/mp4',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
const PDF = [ 'pdf' => 'application/pdf' ];
|
|
19
|
+
|
|
20
|
+
public static function upload_audio( string $field, string $folder ): void {
|
|
21
|
+
if ( ! current_user_can( 'upload_files' ) ) {
|
|
22
|
+
wp_send_json_error( 'Permission denied' );
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
$stored = self::store( $field, $folder, self::AUDIO, 50 );
|
|
26
|
+
|
|
27
|
+
if ( is_wp_error( $stored ) ) {
|
|
28
|
+
wp_send_json_error( $stored->get_error_message() );
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
wp_send_json_success( $stored );
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public static function delete_audio( string $folder ): void {
|
|
35
|
+
if ( ! current_user_can( 'upload_files' ) ) {
|
|
36
|
+
wp_send_json_error( 'Permission denied.' );
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
$url = isset( $_POST['file_url'] ) ? esc_url_raw( wp_unslash( $_POST['file_url'] ) ) : '';
|
|
40
|
+
|
|
41
|
+
if ( '' === $url ) {
|
|
42
|
+
wp_send_json_error( 'No file URL provided.' );
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
self::remove( $url, $folder ) ? wp_send_json_success( 'File deleted successfully.' ) : wp_send_json_error( 'Could not delete file.' );
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public static function store( string $field, string $folder, array $mimes, int $max_mb ) {
|
|
49
|
+
if ( empty( $_FILES[ $field ]['tmp_name'] ) ) {
|
|
50
|
+
return new \WP_Error( 'missing', 'No file uploaded' );
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
$file = $_FILES[ $field ];
|
|
54
|
+
$check = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'], $mimes );
|
|
55
|
+
|
|
56
|
+
if ( empty( $check['ext'] ) || empty( $check['type'] ) ) {
|
|
57
|
+
return new \WP_Error( 'type', 'This file type is not allowed.' );
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if ( $file['size'] > $max_mb * MB_IN_BYTES ) {
|
|
61
|
+
return new \WP_Error( 'size', sprintf( 'File too large. Maximum size is %dMB.', $max_mb ) );
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
$name = sanitize_file_name( pathinfo( $file['name'], PATHINFO_FILENAME ) ) . '_' . uniqid() . '.' . $check['ext'];
|
|
65
|
+
$client = Storage::client();
|
|
66
|
+
|
|
67
|
+
if ( $client ) {
|
|
68
|
+
$key = $folder . '/' . $name;
|
|
69
|
+
|
|
70
|
+
if ( ! $client->put_file( $key, $file['tmp_name'], $check['type'] ) ) {
|
|
71
|
+
return new \WP_Error( 'storage', 'Upload to storage failed.' );
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
$url = $client->url( $key );
|
|
75
|
+
} else {
|
|
76
|
+
$uploads = wp_upload_dir();
|
|
77
|
+
$dir = $uploads['basedir'] . '/' . $folder;
|
|
78
|
+
|
|
79
|
+
wp_mkdir_p( $dir );
|
|
80
|
+
|
|
81
|
+
if ( ! move_uploaded_file( $file['tmp_name'], $dir . '/' . $name ) ) {
|
|
82
|
+
return new \WP_Error( 'move', 'Upload failed. Could not save file.' );
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
$url = $uploads['baseurl'] . '/' . $folder . '/' . $name;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return [
|
|
89
|
+
'url' => $url,
|
|
90
|
+
'filename' => $name,
|
|
91
|
+
'size' => size_format( $file['size'] ),
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public static function remove( string $url, string $folder ): bool {
|
|
96
|
+
$client = Storage::client();
|
|
97
|
+
|
|
98
|
+
if ( $client && 0 === strpos( $url, $client->url( '' ) ) ) {
|
|
99
|
+
$key = $client->key_from_url( $url );
|
|
100
|
+
|
|
101
|
+
return 0 === strpos( $key, $folder . '/' ) && $client->delete( $key );
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
$uploads = wp_upload_dir();
|
|
105
|
+
$path = realpath( str_replace( $uploads['baseurl'], $uploads['basedir'], $url ) );
|
|
106
|
+
$base = realpath( $uploads['basedir'] . '/' . $folder );
|
|
107
|
+
|
|
108
|
+
if ( ! $path || ! $base || 0 !== strpos( $path, $base . DIRECTORY_SEPARATOR ) ) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return unlink( $path );
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public static function send( string $url ): void {
|
|
116
|
+
$uploads = wp_upload_dir();
|
|
117
|
+
$path = str_replace( $uploads['baseurl'], $uploads['basedir'], $url );
|
|
118
|
+
|
|
119
|
+
if ( $path !== $url && is_readable( $path ) ) {
|
|
120
|
+
while ( ob_get_level() ) {
|
|
121
|
+
ob_end_clean();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
header( 'Content-Type: application/octet-stream' );
|
|
125
|
+
header( 'Content-Disposition: attachment; filename="' . basename( $path ) . '"' );
|
|
126
|
+
header( 'Content-Length: ' . filesize( $path ) );
|
|
127
|
+
header( 'Cache-Control: private' );
|
|
128
|
+
readfile( $path );
|
|
129
|
+
exit;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if ( wp_http_validate_url( $url ) ) {
|
|
133
|
+
wp_redirect( $url );
|
|
134
|
+
exit;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
wp_die( 'File not found.' );
|
|
138
|
+
}
|
|
139
|
+
}
|