-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwikilingo.module
129 lines (116 loc) · 3.42 KB
/
wikilingo.module
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
<?php
/**
* @file
* Additional filter for PHP input.
*/
/**
* Implements hook_help().
*/
function wikilingo_help($path, $arg) {
switch ($path) {
case 'admin/help#wikiLingo':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('A wiki markup language and programming environment') . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Enabling execution of wikiLingo markup in text fields') . '</dt>';
$output .= '<dd>' . t('The wikiLingo filter module allows users with the proper permissions to include special markup') . '</dd>';
$output .= '</dl>';
return $output;
}
}
/**
* Implements hook_permission().
*/
function wikilingo_permission() {
return array(
'use wikiLingo for settings' => array(
'title' => t('Use wikiLingo for settings'),
'restrict access' => TRUE,
),
);
}
/**
* Parses wikiLingo
*
* @param $code
* The code to parse.
*
* @return
* A string containing the printed output of the code, followed by the
* returned output of the code.
*
* @ingroup wikilingo_wrappers
*/
function wikiLingo_parse($code) {
global $theme_path, $theme_info, $conf;
require_once ('vendor/autoload.php');
require_once ('wikilingo.events.custom.php');
$module_path = drupal_get_path('module', 'wikilingo');
$scripts = new WikiLingo\Utilities\Scripts($module_path, $module_path . "/vendor/");
$scripts
//add some css
->addCssLocation("~/jquery/jquery-ui/themes/base/minified/jquery.ui.theme.min.css")
//add some javascript
->addScriptLocation("~/jquery/jquery/jquery-1.10.2.js")
->addScriptLocation("~/jquery/jquery-ui/ui/minified/jquery-ui.min.js");
$wikiLingo = new WikiLingo\Parser($scripts);
$wikiLingo->events
->bind(new WikiLingo\Event\Parsed\RenderPermission(function(WikiLingo\Parsed &$parsed) {
global $user;
if (
$parsed->type == "Plugin"
&& $parsed->expression->type == "Permission"
) {
if (isset($parsed->expression->parametersRaw['role'])) {
$role = $parsed->expression->parametersRaw['role'];
if (in_array($role, $user->roles)) {
$parsed->expressionPermissible = true;
}
}
}
}))
->bind(new WikiLingo\Event\Parsed\RenderBlocked(function(WikiLingo\Parsed &$parsed, &$return) {
$return = '';
}));
//event handler
(new wikiLingoEventsCustom($wikiLingo->events));
$parsed = $wikiLingo->parse($code);
drupal_add_html_head($element = array(
'#type' => 'markup',
'#markup' => $scripts->renderCss() . $scripts->renderScript(),
), 'wikiLingo-tmpl');
return $parsed;
}
/**
* Implements callback_filter_tips().
*
* @see wikiLingo_filter_info()
*/
function _wikilingo_filter_tips($filter, $format, $long = FALSE) {
global $base_url;
if ($long) {
$output = '<h4>' . t('Using wikiLingo') . '</h4>';
$output .= '<p>' . '<p>' . t('wikiLingo is a programming language') . '</p>';
return $output;
}
else {
return t('wikiLingo');
}
}
/**
* Implements hook_filter_info().
*
* Provide wikiLingo code filter. Use with care.
*/
function wikilingo_filter_info() {
$filters['wikilingo_filter'] = array(
'title' => t('wikiLingo'),
'description' => t('Parse wikiLingo'),
'process callback' => 'wikilingo_parse',
'tips callback' => '_wikilingo_filter_tips',
'cache' => FALSE,
);
return $filters;
}