forked from kasperisager/vanilla-wysihtml5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.wysihtml5.plugin.php
executable file
·104 lines (94 loc) · 3.36 KB
/
class.wysihtml5.plugin.php
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
<?php if(!defined("APPLICATION")) exit();
$PluginInfo['Wysihtml5'] = array(
'Name' => 'Wysihtml5',
'Description' => 'Turns the default text area into an HTML5 editor that generates valid and semantic markup. This version of the plugin is compatible with both Vanilla 2.0 and Vanilla 2.1b.',
'Version' => '13.05.28',
'Author' => 'D.Zanella',
'AuthorEmail' => 'diego@pathtoenlightenment.net',
'AuthorUrl' => 'http://dev.pathtoenlightenment.net',
'RequiredApplications' => array('Vanilla' => '2.0.10')
);
/**
* Wysihtml5 plugin for Vanilla
* Based on original work from Kasper Kronborg Isager <kasperisager@gmail.com>.
* Original repository can be found at https://github.com/kasperisager/Wysihtml5.
*
* @author Diego Zanella <diego@pathtoenlightenment.net>
* @license http://opensource.org/licenses/MIT MIT
*/
class Wysihtml5 extends Gdn_Plugin {
/**
* Adds the formatting bar to the form used by the Controller.
*
* @param Gdn_Controller $Sender Sending Controller instance.
*/
private function AttachFormattingBar(Gdn_Controller $Sender) {
$this->_AddWysihtml5($Sender);
$Form = $Sender->Form;
$Format = $Form->GetValue('Format');
if($Format) {
$Formatter = Gdn::Factory($Format . 'Formatter');
if($Formatter && method_exists($Formatter, 'FormatForWysiwyg')) {
$Body = $Formatter->FormatForWysiwyg($Form->GetValue('Body'));
$Form->SetValue('Body', $Body);
}
elseif(!in_array($Format, array('Html', 'Wysiwyg'))) {
$Form->SetValue('Body', Gdn_Format::To($Form->GetValue('Body'), $Format));
}
}
$Form->SetValue('Format', 'Wysiwyg');
echo $Sender->FetchView($this->GetView('toolbar_view.php'));
}
/**
* Vanilla 2.1 only.
* Add the WYSIWYG editor to all text boxes
*
* @param Gdn_Controller $Sender Sending Controller instance.
*/
public function Gdn_Form_BeforeBodyBox_Handler($Sender) {
$this->AttachFormattingBar(Gdn::Controller());
}
/**
* Vanilla 2.0 only.
* Hook DiscussionController::BeforeBodyInput Event Handler.
* This event fires just before the comment textbox is drawn.
*
* @param Gdn_Controller $Sender Sending Controller instance.
*/
public function DiscussionController_BeforeBodyInput_Handler($Sender) {
$this->AttachFormattingBar($Sender);
}
/**
* Vanilla 2.0 only.
* Hook PostController::BeforeBodyInput Event Handler. Vanilla 2.0 only.
* This event fires just before the comment textbox is drawn.
*
* @param Gdn_Controller $Sender Sending Controller instance.
*/
public function PostController_BeforeBodyInput_Handler($Sender) {
$this->AttachFormattingBar($Sender);
}
/**
* Vanilla 2.0 only.
* Hook PostController::BeforeBodyField Event Handler. Vanilla 2.0 only.
* This event fires just before the comment textbox is drawn.
*
* @param Gdn_Controller $Sender Sending Controller instance.
*/
public function DiscussionController_BeforeBodyField_Handler($Sender) {
$this->AttachFormattingBar($Sender);
}
/**
* Add Wysihtml5 resources
*
* @param Gdn_Controller $Sender
*/
private function _AddWysihtml5($Sender) {
$Sender->AddCssFile('wysihtml5.css', 'plugins/Wysihtml5');
$Sender->AddCssFile('sprites12.css', 'plugins/Wysihtml5');
$Sender->AddJsFile('advanced.js', 'plugins/Wysihtml5');
$Sender->AddJsFile('wysihtml5.js', 'plugins/Wysihtml5');
$Sender->AddJsFile('initialize.js', 'plugins/Wysihtml5');
$Sender->AddJsFile('underscore.js', 'plugins/Wysihtml5');
}
}