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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
<?php
/**
* @file
* Editor integration functions for markItUp.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_markitup_editor() {
$editor['markitup'] = array(
'title' => 'markItUp',
'vendor url' => 'http://markitup.jaysalvat.com',
'download url' => 'http://markitup.jaysalvat.com/downloads',
'library path' => wysiwyg_get_path('markitup'),
'libraries' => array(
'' => array(
'title' => 'Source',
'files' => array('markitup/jquery.markitup.js'),
),
'pack' => array(
'title' => 'Packed',
'files' => array('markitup/jquery.markitup.pack.js'),
),
),
'version callback' => 'wysiwyg_markitup_version',
'themes callback' => 'wysiwyg_markitup_themes',
'settings callback' => 'wysiwyg_markitup_settings',
'plugin callback' => 'wysiwyg_markitup_plugins',
'versions' => array(
'1.1.5' => array(
'js files' => array('markitup.js'),
),
),
);
return $editor;
}
/**
* Detect editor version.
*
* @param $editor
* An array containing editor properties as returned from hook_editor().
*
* @return
* The installed editor version.
*/
function wysiwyg_markitup_version($editor) {
// Changelog was in markitup/markitup/readme.txt <= 1.1.5.
$changelog = $editor['library path'] . '/markitup/readme.txt';
if (!file_exists($changelog)) {
// Changelog was moved up to markitup/CHANGELOG.md after 1.1.5.
$changelog = $editor['library path'] . '/CHANGELOG.md';
if (!file_exists($changelog)) {
return;
}
}
$changelog = fopen($changelog, 'r');
$line = fgets($changelog);
if (preg_match('@([0-9\.]+)@', $line, $version)) {
fclose($changelog);
return $version[1];
}
fclose($changelog);
}
/**
* Determine available editor themes or check/reset a given one.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $profile
* A wysiwyg editor profile.
*
* @return
* An array of theme names. The first returned name should be the default
* theme name.
*/
function wysiwyg_markitup_themes($editor, $profile) {
return array('simple', 'markitup');
}
/**
* Return runtime editor settings for a given wysiwyg profile.
*
* @param $editor
* A processed hook_editor() array of editor properties.
* @param $config
* An array containing wysiwyg editor profile settings.
* @param $theme
* The name of a theme/GUI/skin to use.
*
* @return
* A settings array to be populated in
* Drupal.settings.wysiwyg.configs.{editor}
*/
function wysiwyg_markitup_settings($editor, $config, $theme) {
drupal_add_css($editor['library path'] . '/markitup/skins/' . $theme . '/style.css', array(
// Specify an alternate basename; otherwise, style.css would override a
// commonly used style.css file of the theme.
'basename' => 'markitup.' . $theme . '.style.css',
'group' => CSS_THEME,
));
$settings = array(
'root' => base_path() . $editor['library path'] . '/markitup/',
'nameSpace' => $theme,
'markupSet' => array(),
);
// Add configured buttons or all available.
$default_buttons = array(
'bold' => array(
'name' => t('Bold'),
'className' => 'markitup-bold',
'key' => 'B',
'openWith' => '(!(<strong>|!|<b>)!)',
'closeWith' => '(!(</strong>|!|</b>)!)',
),
'italic' => array(
'name' => t('Italic'),
'className' => 'markitup-italic',
'key' => 'I',
'openWith' => '(!(<em>|!|<i>)!)',
'closeWith' => '(!(</em>|!|</i>)!)',
),
'stroke' => array(
'name' => t('Strike-through'),
'className' => 'markitup-stroke',
'key' => 'S',
'openWith' => '<del>',
'closeWith' => '</del>',
),
'image' => array(
'name' => t('Image'),
'className' => 'markitup-image',
'key' => 'P',
'replaceWith' => '<img src="[![Source:!:http://]!]" alt="[![Alternative text]!]" />',
),
'link' => array(
'name' => t('Link'),
'className' => 'markitup-link',
'key' => 'K',
'openWith' => '<a href="[![Link:!:http://]!]"(!( title="[![Title]!]")!)>',
'closeWith' => '</a>',
'placeHolder' => 'Your text to link...',
),
// @todo
// 'cleanup' => array('name' => t('Clean-up'), 'className' => 'markitup-cleanup', 'replaceWith' => 'function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") }'),
'preview' => array(
'name' => t('Preview'),
'className' => 'markitup-preview',
'call' => 'preview',
),
);
$settings['markupSet'] = array();
if (!empty($config['buttons'])) {
foreach ($config['buttons'] as $plugin) {
foreach ($plugin as $button => $enabled) {
if (isset($default_buttons[$button])) {
$settings['markupSet'][$button] = $default_buttons[$button];
}
}
}
}
return $settings;
}
/**
* Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_markitup_plugins($editor) {
return array(
'default' => array(
'buttons' => array(
'bold' => t('Bold'), 'italic' => t('Italic'),
'stroke' => t('Strike-through'),
'link' => t('Link'),
'image' => t('Image'),
// 'cleanup' => t('Clean-up'),
'preview' => t('Preview'),
),
'internal' => TRUE,
),
);
}
|