-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown_editor.php
More file actions
76 lines (68 loc) · 2.08 KB
/
Copy pathmarkdown_editor.php
File metadata and controls
76 lines (68 loc) · 2.08 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
<?php
$thisfile = basename(__FILE__, ".php");
register_plugin(
$thisfile,
'Markdown Editor',
'0.1',
'Carlos Navarro',
'http://www.cyberiada.org/cnb/',
'Create and edit pages using the Markdown syntax',
'',
''
);
if (!defined('MARKDOWN_EDITOR') || MARKDOWN_EDITOR) {
add_action('changedata-save','mde_savecontent');
add_action('edit-extras','mde_editcontent');
add_filter('pagecache','mde_fixpagecache');
if (mde_addlink())
add_action('pages-sidebar', 'mde_sidebar');
}
function mde_editcontent() {
global $content, $HTMLEDITOR, $data_edit;
if (
isset($data_edit->contentmd) ||
isset($_GET['markdown']) ||
(!mde_addlink() && (!isset($_GET['id']) || empty($_GET['id']) || empty($content))) ||
(empty($content) && defined('MARKDOWN_EMPTY') && MARKDOWN_EMPTY)
) {
if (!empty($data_edit->contentmd)) $content = $data_edit->contentmd;
$HTMLEDITOR = '';
echo PHP_EOL,'<input id="markdown-enabled" name="markdown-enabled" type="hidden" value="1">',PHP_EOL;
}
}
function mde_savecontent() {
if (isset($_POST['markdown-enabled']) && $_POST['markdown-enabled'] == '1') {
global $xml;
if (!class_exists('Parsedown'))
require_once 'markdown_editor/parsedown/Parsedown.php';
$Parsedown = new Parsedown();
$text = get_magic_quotes_gpc()!=0 ? stripslashes($_POST['post-content']) : $_POST['post-content'];
unset($xml->content);
$note = $xml->addChild('content');
$note->addCData(safe_slash_html($Parsedown->text($text)));
$note = $xml->addChild('contentmd');
$note->addCData($text);
}
}
function mde_fixpagecache($xml) {
foreach ($xml as $item)
if (isset($item->contentmd)) unset($item->contentmd);
return $xml;
}
function mde_addlink() {
if (!defined('MARKDOWN_ADDLINK'))
return true;
elseif (MARKDOWN_ADDLINK)
return MARKDOWN_ADDLINK;
else
return false;
}
function mde_sidebar() {
if (strlen(mde_addlink()) > 1)
$str = mde_addlink();
else
$str = strip_tags(i18n_r('SIDE_CREATE_NEW')).' (Markdown)';
?>
<li id="sb_markdown_editor" class="plugin_sb"><a href="edit.php?markdown"><?php echo $str; ?></a></li>
<?php
}