forked from wisolman/markdown_guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.driver.php
executable file
·79 lines (67 loc) · 2.15 KB
/
extension.driver.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
<?php
Class extension_markdown_guide extends Extension {
// Simply outputs information to Symphony about the extension
public function about() {
$info = array(
'author' => array(
'email' => 'sassercw@cox.net',
'name' => 'Carson Sasser',
'website' => 'http://carsonsasser.com/'
),
'name' => 'Markdown Guide',
'release-date' => '2010-09-28',
'version' => '1.3'
);
return $info;
}
public function getSubscribedDelegates() {
return array(
array(
'page' => '/backend/',
'delegate' => 'ModifyTextareaFieldPublishWidget',
'callback' => 'addGuideBelowTextArea'
),
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'initaliseAdminPageHead'
)
);
}
public function addGuideBelowTextArea($context) {
//only show guide when using markdown
$formatter = $context['field']->get('formatter');
$pattern = '/^markdown/';
if (!preg_match($pattern, $formatter)) return;
//append the textarea here so the guide will show after the textarea in the form
$context['label']->appendChild($context['textarea']);
//nullify the textarea to prevent another one being appended in field.textarea.php
$context['textarea'] = Widget::Label('');
//retrieve the guide and append it
switch($formatter){
case 'markdown':
$file = EXTENSIONS . '/markdown_guide/assets/markdown.php';
break;
case 'markdown_extra':
$file = EXTENSIONS . '/markdown_guide/assets/markdown_extra.php';
break;
case 'markdown_extra_with_smartypants':
$file = EXTENSIONS . '/markdown_guide/assets/markdown_extra_with_smartypants.php';
break;
case 'markdown_with_purifier':
$file = EXTENSIONS . '/markdown_guide/assets/markdown_with_purifier.php';
break;
}
include($file);
foreach($description as $line) {
$contents .= "<strong>{$line[0]}:</strong> {$line[1]}<br />";
}
$guide = Widget::Label($contents, null, 'markdown_guide');
$context['label']->appendChild($guide);
}
public function initaliseAdminPageHead($context) {
$page = $context['parent']->Page;
$page->addScriptToHead(URL . '/extensions/markdown_guide/assets/toggle_guide.js', 900200);
}
}
?>