-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlainPastePlugin.php
More file actions
68 lines (59 loc) · 1.7 KB
/
PlainPastePlugin.php
File metadata and controls
68 lines (59 loc) · 1.7 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
<?php
namespace APP\plugins\generic\plainPaste;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use APP\template\TemplateManager;
use APP\core\Application;
class PlainPastePlugin extends GenericPlugin
{
/**
* @copydoc Plugin::register()
*/
public function register($category, $path, $mainContextId = null)
{
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled()) {
Hook::add('TemplateManager::display', [$this, 'injectJS']);
}
return true;
}
return false;
}
/**
* Inject the plainPaste.js script into the template manager
*
* @param string $hookName
* @param array $args [TemplateManager, template]
*/
public function injectJS($hookName, $args)
{
$templateMgr = $args[0];
$request = Application::get()->getRequest();
$baseUrl = $request->getBaseUrl();
$jsUrl = $baseUrl . '/' . $this->getPluginPath() . '/js/plainPaste.js';
// Add the script to both frontend and backend
$templateMgr->addJavaScript(
'plainPaste',
$jsUrl,
[
'contexts' => ['backend', 'frontend'],
'priority' => STYLE_SEQUENCE_LAST // Ensure it loads after TinyMCE
]
);
return false;
}
/**
* @copydoc Plugin::getDisplayName()
*/
public function getDisplayName()
{
return 'Plain Paste for TinyMCE';
}
/**
* @copydoc Plugin::getDescription()
*/
public function getDescription()
{
return 'Automatically clears all formatting from pasted content in all TinyMCE editors sitewide.';
}
}