-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboot.php
More file actions
142 lines (128 loc) · 6.13 KB
/
Copy pathboot.php
File metadata and controls
142 lines (128 loc) · 6.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
declare(strict_types=1);
/**
* WriteAssist AddOn for REDAXO
*
* Provides translation (DeepL) and text improvement (LanguageTool) services
* Can be used standalone or integrated into Info Center
*/
$addon = rex_addon::get('writeassist');
// API-Klassen explizit registrieren (umgeht Autoload-Cache-Probleme)
rex_api_function::register('writeassist_bulk_translate', 'rex_api_writeassist_bulk_translate');
// Auto-Translate: Artikelnamen und Kategorienamen bei Neuanlage übersetzen
// ART_ADDED feuert innerhalb der foreach-Clang-Schleife von addArticle().
// Wir sammeln nur beim ersten Aufruf (done-Guard) und führen die Übersetzung
// NACH dem Ende aller Clang-Inserts via register_shutdown_function aus.
if (\FriendsOfREDAXO\WriteAssist\AutoTranslateService::isEnabled()) {
rex_extension::register('ART_ADDED', static function (rex_extension_point $ep): void {
static $queued = [];
$id = (int) $ep->getParam('id');
if ($id <= 0 || isset($queued[$id])) {
return;
}
$queued[$id] = true;
$name = (string) $ep->getParam('name');
$sourceClang = rex_clang::getCurrentId();
register_shutdown_function(static function () use ($id, $name, $sourceClang): void {
\FriendsOfREDAXO\WriteAssist\AutoTranslateService::translateName($id, 'article', $name, $sourceClang);
});
});
rex_extension::register('CAT_ADDED', static function (rex_extension_point $ep): void {
static $queued = [];
$id = (int) $ep->getParam('id');
if ($id <= 0 || isset($queued[$id])) {
return;
}
$queued[$id] = true;
$name = (string) $ep->getParam('name');
$sourceClang = rex_clang::getCurrentId();
register_shutdown_function(static function () use ($id, $name, $sourceClang): void {
\FriendsOfREDAXO\WriteAssist\AutoTranslateService::translateName($id, 'category', $name, $sourceClang);
});
});
}
// Auto-Translate bei Umbenennung: Übersetzt Artikel-/Kategorienamen bei Bearbeitung
if (\FriendsOfREDAXO\WriteAssist\AutoTranslateService::isRenameEnabled()) {
rex_extension::register('ART_UPDATED', static function (rex_extension_point $ep): void {
static $queued = [];
$id = (int) $ep->getParam('id');
if ($id <= 0 || isset($queued[$id])) {
return;
}
$queued[$id] = true;
$name = (string) $ep->getParam('name');
$clangId = $ep->getParam('clang_id');
$sourceClang = null !== $clangId ? (int) $clangId : rex_clang::getCurrentId();
if ('' === $name || $sourceClang <= 0) {
return;
}
register_shutdown_function(static function () use ($id, $name, $sourceClang): void {
\FriendsOfREDAXO\WriteAssist\AutoTranslateService::translateName($id, 'article', $name, $sourceClang);
});
});
rex_extension::register('CAT_UPDATED', static function (rex_extension_point $ep): void {
static $queued = [];
$id = (int) $ep->getParam('id');
if ($id <= 0 || isset($queued[$id])) {
return;
}
$queued[$id] = true;
$name = (string) $ep->getParam('name');
$clangId = $ep->getParam('clang_id');
$sourceClang = null !== $clangId ? (int) $clangId : rex_clang::getCurrentId();
if ('' === $name || $sourceClang <= 0) {
return;
}
register_shutdown_function(static function () use ($id, $name, $sourceClang): void {
\FriendsOfREDAXO\WriteAssist\AutoTranslateService::translateName($id, 'category', $name, $sourceClang);
});
});
}
if (rex::isBackend() && rex::getUser()) {
// Register as Info Center Widget if info_center addon is available and enabled
if ($addon->getConfig('enable_infocenter_widget', true) && rex_addon::get('info_center')->isAvailable() && class_exists(\KLXM\InfoCenter\InfoCenter::class)) {
$infoCenter = \KLXM\InfoCenter\InfoCenter::getInstance();
$widget = new \FriendsOfREDAXO\WriteAssist\WriteAssistWidget();
$widget->setPriority(1); // After system widgets
$infoCenter->registerWidget($widget);
}
// Add assets to backend
rex_view::addCssFile($addon->getAssetsUrl('css/writeassist.css'));
rex_view::addJsFile($addon->getAssetsUrl('js/writeassist.js'));
rex_view::addJsFile($addon->getAssetsUrl('js/writeassist-bulk-translate.js'));
rex_view::addJsFile($addon->getAssetsUrl('js/writeassist-settings.js'));
if ($addon->getConfig('enable_markitup_plugin', true) && rex_addon::get('markitup')->isAvailable()) {
// Register MarkItUp integration JS
rex_view::addJsFile($addon->getAssetsUrl('js/markitup-writeassist-plugin.js'));
}
}
// Register TinyMCE Plugin if TinyMCE addon is available and enabled
if (rex::isBackend() && rex::getUser() && $addon->getConfig('enable_tinymce_plugin', true) && rex_addon::get('tinymce')->isAvailable()) {
// Register Plugin Directory
// Ensure we can register multiple plugins
if (class_exists(\FriendsOfRedaxo\TinyMce\PluginRegistry::class)) {
// 1. DeepL Translate Plugin
\FriendsOfRedaxo\TinyMce\PluginRegistry::addPlugin(
'writeassist_translate',
rex_url::base('assets/addons/writeassist/js/tinymce-deepl-plugin.js'),
'writeassist_translate'
);
// 2. AI Generator Plugin (Gemini/OpenWebUI)
\FriendsOfRedaxo\TinyMce\PluginRegistry::addPlugin(
'writeassist_generate',
rex_url::base('assets/addons/writeassist/js/tinymce-generate-plugin.js'),
'writeassist_generate'
);
}
}
// Register TipTap plugin if TipTap addon is available
if (rex::isBackend() && rex::getUser() && rex_addon::get('tiptap')->isAvailable()) {
// Register a minimal integration plugin that enables WriteAssist toolbar features
if (class_exists(\FriendsOfRedaxo\TipTap\PluginRegistry::class)) {
\FriendsOfRedaxo\TipTap\PluginRegistry::addPlugin(
'writeassist_tiptap',
rex_url::base('assets/addons/writeassist/js/tiptap-writeassist-plugin.js'),
'writeassist_tiptap'
);
}
}