-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
executable file
·101 lines (87 loc) · 2.98 KB
/
Module.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
<?php
namespace SocialogCodeMirror;
use Zend\Mvc\MvcEvent;
/**
* Socialog CodeMirror Module
*/
class Module
{
/**
* @param \Zend\Mvc\MvcEvent $e
*/
public function onBootstrap(MvcEvent $e)
{
$app = $e->getApplication();
$sm = $app->getServiceManager();
$sharedEventManager = $sm->get('SharedEventManager');
$cfg = $sm->get('Config');
if ($cfg['socialog-admin']['text-mode'] !== 'markdown') {
return;
}
$renderer = $sm->get('socialog_codemirror_sundownrenderer');
// Inhaken in menue
$sharedEventManager->attach('render', array('post.edit', 'page.edit'), function($e) use ($sm, $cfg) {
$view = $e->getTarget();
$codeMirror = $view->basePath($cfg['socialog-codemirror']['lib_path']);
$view->headLink()
->appendStylesheet($codeMirror . '/lib/codemirror.css')
->appendStylesheet($codeMirror . '/../../css/main.css');
$view->headScript()
->appendFile($codeMirror . '/lib/codemirror.js')
->appendFile($codeMirror . '/mode/xml/xml.js')
->appendFile($codeMirror . '/mode/markdown/markdown.js')
->appendFile($codeMirror . '/mode/gfm/gfm.js')
->appendFile($codeMirror . '/mode/javascript/javascript.js')
->appendScript(<<<SCRIPT
$(function(){
var editor = CodeMirror.fromTextArea($('textarea[name=content]').get(0), {
mode: 'gfm',
lineNumbers: true,
matchBrackets: true,
theme: "default"
});
});
SCRIPT
);
});
$sharedEventManager->attach('Socialog\Mapper\PostMapper', 'save', function($e) use ($sm) {
$post = $e->getParam('post');
$renderer = $sm->get('socialog_codemirror_sundownrenderer');
$post->setContentHtml($renderer->render($post->getContent()));
}, 100);
$sharedEventManager->attach('Socialog\Mapper\PageMapper', 'save', function($e) use ($sm) {
$post = $e->getParam('page');
$renderer = $sm->get('socialog_codemirror_sundownrenderer');
$post->setContentHtml($renderer->render($post->getContent()));
}, 100);
}
/**
* @return array
*/
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
/**
* @return array
*/
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
/**
* Service Configuration
*
* @return array
*/
public function getServiceConfig()
{
return include __DIR__ . '/config/service.config.php';
}
}