-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
143 lines (132 loc) · 7.66 KB
/
index.php
File metadata and controls
143 lines (132 loc) · 7.66 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
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
<?php
/*
* Code element addon for Bear CMS
* https://github.com/bearcms/code-element-addon
* Copyright (c) Amplilabs Ltd.
* Free to use under the MIT license.
*/
use BearFramework\App;
$app = App::get();
$app->bearCMS->addons
->register('bearcms/code-element-addon', function (\BearCMS\Addons\Addon $addon) use ($app): void {
$addon->initialize = function () use ($app): void {
$context = $app->contexts->get(__DIR__);
$context->assets->addDir('assets');
$app->localization
->addDictionary('en', function () use ($context) {
return include $context->dir . '/locales/en.php';
})
->addDictionary('bg', function () use ($context) {
return include $context->dir . '/locales/bg.php';
});
$type = new \BearCMS\Internal\ElementType('code', 'bearcms-code-element', $context->dir . '/components/codeElement.php');
$type->properties = [
[
'id' => 'code',
'type' => 'string'
],
[
'id' => 'language',
'type' => 'string'
]
];
\BearCMS\Internal\ElementsTypes::add($type);
$languages = [
'apache' => 'Apache',
'bash' => 'Bash',
'cplusplus' => 'C++',
'csharp' => 'C#',
'css' => 'CSS',
'dart' => 'Dart',
'go' => 'Go',
'html' => 'HTML',
'java' => 'Java',
'javascript' => 'JavaScript',
'json' => 'JSON',
'kotlin' => 'Kotlin',
'less' => 'LESS',
'markdown' => 'Markdown',
'nginx' => 'NGINX',
'objectivec' => 'Objective-C',
'perl' => 'Perl',
'php' => 'PHP',
'plaintext' => 'Plain text',
'python' => 'Python',
'ruby' => 'Ruby',
'rust' => 'Rust',
'shell' => 'Shell',
'swift' => 'Swift',
'typescript' => 'TypeScript',
'xml' => 'XML',
'yaml' => 'YAML',
];
\BearCMS\Internal\Config::$appSpecificServerData['kzn49al1'] = json_encode($languages);
\BearCMS\Internal\Themes::$elementsOptions['code'] = function ($context, $idPrefix, $parentSelector): void {
$groupCode = $context->addGroup(__('bearcms.addon.code-element.theme.options.Code'));
$groupCode->addOption($idPrefix . "CodeCSS", "css", '', [
"cssOutput" => [
["rule", $parentSelector . " .bearcms-code-element", "overflow:auto;white-space:pre;word-wrap:normal;display:block;"],
["selector", $parentSelector . " .bearcms-code-element"]
],
"value" => '{"color":"#333333","background-color":"#f8f8f8","padding-top":"10px","padding-bottom":"10px","padding-left":"10px","padding-right":"10px"}'
]);
$entitiesGroup = $groupCode->addGroup(__('bearcms.addon.code-element.theme.options.Entities'));
$keywordEntityGroup = $entitiesGroup->addGroup(__('bearcms.addon.code-element.theme.options.Entities.Keyword'));
$keywordEntityGroup->addOption($idPrefix . "CodeEntityKeywordCSS", "css", '', [
"cssTypes" => ["cssText", "cssTextShadow"],
"cssOutput" => [
["selector", $parentSelector . " .bearcms-code-element .bearcms-code-element-entity-keyword"]
],
"value" => '{"color":"#333333"}'
]);
$variableEntityGroup = $entitiesGroup->addGroup(__('bearcms.addon.code-element.theme.options.Entities.Variable'));
$variableEntityGroup->addOption($idPrefix . "CodeEntityVariableCSS", "css", '', [
"cssTypes" => ["cssText", "cssTextShadow"],
"cssOutput" => [
["selector", $parentSelector . " .bearcms-code-element .bearcms-code-element-entity-variable"]
],
"value" => '{"color":"#008080"}'
]);
$valueEntityGroup = $entitiesGroup->addGroup(__('bearcms.addon.code-element.theme.options.Entities.Value'));
$valueEntityGroup->addOption($idPrefix . "CodeEntityValueCSS", "css", '', [
"cssTypes" => ["cssText", "cssTextShadow"],
"cssOutput" => [
["selector", $parentSelector . " .bearcms-code-element .bearcms-code-element-entity-value"]
],
"value" => '{"color":"#dd1144"}'
]);
$commentEntityGroup = $entitiesGroup->addGroup(__('bearcms.addon.code-element.theme.options.Entities.Comment'));
$commentEntityGroup->addOption($idPrefix . "CodeEntityCommentCSS", "css", '', [
"cssTypes" => ["cssText", "cssTextShadow"],
"cssOutput" => [
["selector", $parentSelector . " .bearcms-code-element .bearcms-code-element-entity-comment"]
],
"value" => '{"color":"#999988"}'
]);
};
$app->clientPackages
->add('-bearcms-code-element-highlight', function ($package) use ($context): void {
$code = 'window.bearcmscodeelementh={};';
$libraryCode = include $context->dir . '/helpers/highlightjs/highlight.js.php';
$code .= 'var f=' . $libraryCode . 'f(window.bearcmscodeelementh);';
$code .= 'window.bearcmscodeelementh.configure({classPrefix:"bearcms-code-element-entity-internal-"});';
//$updateCode = file_get_contents($context->dir . '/dev/update.js');
$updateCode = 'function(b){var d={comment:"comment",quote:"comment",doctag:"comment",keyword:"keyword","selector-tag":"keyword",variable:"variable","template-variable":"variable","entity-attr":"variable",attr:"variable",number:"value",literal:"value",regexp:"value",string:"value",subst:"value",symbol:"value"},c;for(c in d)b=b.split("bearcms-code-element-entity-internal-"+c).join("bearcms-code-element-entity-"+d[c]);return b=b.replace(RegExp(\' class="bearcms-code-element-entity-internal-[a-z-]*"\',"g"),"")};';
$code .= 'window.bearcmscodeelementu=' . $updateCode;
$package->addJSCode($code);
$package->get = 'return {"library":window.bearcmscodeelementh,"update":window.bearcmscodeelementu};';
});
foreach ($languages as $languageID => $languageName) {
$app->clientPackages
->add('-bearcms-code-element-highlight-' . $languageID, function ($package) use ($context, $languageID): void {
$languageCode = include $context->dir . '/helpers/highlightjs/languages/' . $languageID . '.js.php';
$code = 'clientPackages.get("-bearcms-code-element-highlight").then(function(o){';
$code .= 'var f=' . $languageCode . ';o.library.registerLanguage("' . $languageID . '",f);';
$code .= '});';
$package->addJSCode($code);
$package->embedPackage('-bearcms-code-element-highlight');
$package->get = 'return {"library":window.bearcmscodeelementh,"update":window.bearcmscodeelementu};';
});
}
};
});