Skip to content

Commit

Permalink
Improve detect mime for html elements and static chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
bezumkin committed Jan 9, 2019
1 parent e6f9707 commit 21486b1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 43 deletions.
8 changes: 8 additions & 0 deletions _build/data/transport.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,13 @@
'area' => 'general'
),'',true,true);

$settings['html_elements_mime']= $modx->newObject('modSystemSetting');
$settings['html_elements_mime']->fromArray(array(
'key' => 'ace.html_elements_mime',
'xtype' => 'textfield',
'value' => '',
'namespace' => 'ace',
'area' => 'general'
),'',true,true);

return $settings;
59 changes: 23 additions & 36 deletions core/components/ace/elements/plugins/ace.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@
'twig' => 'text/x-twig'
);

// Define default mime for html elements(templates, chunks and html resources)
$html_elements_mime=$modx->getOption('ace.html_elements_mime',null,false);
if(!$html_elements_mime){
// this may deprecated in future because components may set ace.html_elements_mime option now
switch (true) {
case $modx->getOption('twiggy_class'):
$html_elements_mime = 'text/x-twig';
break;
case $modx->getOption('pdotools_fenom_parser'):
$html_elements_mime = 'text/x-smarty';
break;
default:
$html_elements_mime = 'text/html';
}
}

// Defines wether we should highlight modx tags
$modxTags = false;
switch ($modx->event->name) {
Expand All @@ -54,42 +70,20 @@
case 'OnTempFormPrerender':
$field = 'modx-template-content';
$modxTags = true;

switch (true) {
case $modx->getOption('twiggy_class'):
$mimeType = 'text/x-twig';
break;
case $modx->getOption('pdotools_fenom_parser'):
$mimeType = 'text/x-smarty';
break;
default:
$mimeType = 'text/html';
break;
}

$mimeType = $html_elements_mime;
break;
case 'OnChunkFormPrerender':
$field = 'modx-chunk-snippet';
if ($modx->controller->chunk && $modx->controller->chunk->isStatic()) {
$extension = pathinfo($modx->controller->chunk->getSourceFile(), PATHINFO_EXTENSION);
$extension = pathinfo($modx->controller->chunk->name, PATHINFO_EXTENSION);
if(!$extension||!isset($extensionMap[$extension])){
$extension = pathinfo($modx->controller->chunk->getSourceFile(), PATHINFO_EXTENSION);
}
$mimeType = isset($extensionMap[$extension]) ? $extensionMap[$extension] : 'text/plain';
} else {
$mimeType = 'text/html';
$mimeType = $html_elements_mime;
}
$modxTags = true;

switch (true) {
case $modx->getOption('twiggy_class'):
$mimeType = 'text/x-twig';
break;
case $modx->getOption('pdotools_fenom_default'):
$mimeType = 'text/x-smarty';
break;
default:
$mimeType = 'text/html';
break;
}

break;
case 'OnPluginFormPrerender':
$field = 'modx-plugin-plugincode';
Expand All @@ -114,14 +108,7 @@
$field = 'ta';
$mimeType = $modx->getObject('modContentType', $modx->controller->resourceArray['content_type'])->get('mime_type');

switch (true) {
case $mimeType == 'text/html' && $modx->getOption('twiggy_class'):
$mimeType = 'text/x-twig';
break;
case $mimeType == 'text/html' && $modx->getOption('pdotools_fenom_parser'):
$mimeType = 'text/x-smarty';
break;
}
if($mimeType == 'text/html')$mimeType = $html_elements_mime;

if ($modx->getOption('use_editor')){
$richText = $modx->controller->resourceArray['richtext'];
Expand Down
6 changes: 4 additions & 2 deletions core/components/ace/lexicon/de/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
$_lang['setting_ace.snippets_desc'] = 'Code snippets expanded by “Tab”. Snippet example:<br /><br /><pre>\nsnippet getr\n [!getResources? parents=`${1}`${2}]]\n</pre></br>You can insert “Tab” character by pressing Alt + 09';
$_lang['setting_ace.height'] = 'Edit area height';
$_lang['setting_ace.height_desc'] = 'Editor height in pixel unit. If left blank, a defaul height will be used.';
$_lang ['setting_ace.grow'] = 'Höhe an Text anpassen';
$_lang ['setting_ace.grow_desc'] = 'Die Höhe des Editors wird an den Text angepasst. Die minimale Höhe entspricht der Option ace.height. Mögliche Werte: Leer - Höhe passt nicht zum Text; Die Zahl ist größer als 0 - die Höhe wird an den Text angepasst, aber nicht mehr als der Wert; 0 - Höhe ist für Text angepasst, Höhe ist unbegrenzt. ';
$_lang['setting_ace.grow'] = 'Höhe an Text anpassen';
$_lang['setting_ace.grow_desc'] = 'Die Höhe des Editors wird an den Text angepasst. Die minimale Höhe entspricht der Option ace.height. Mögliche Werte: Leer - Höhe passt nicht zum Text; Die Zahl ist größer als 0 - die Höhe wird an den Text angepasst, aber nicht mehr als der Wert; 0 - Höhe ist für Text angepasst, Höhe ist unbegrenzt. ';
$_lang['setting_ace.html_elements_mime'] = 'MIME-Typ für HTML-Elemente';
$_lang['setting_ace.html_elements_mime_desc'] = 'Dieser Typ wird vom Editor für HTML-Elemente verwendet - Vorlagen, Chunks und Ressourcen mit HTML-Typ. Wenn nicht angegeben, wird der Standardtyp verwendet';
6 changes: 4 additions & 2 deletions core/components/ace/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
$_lang['setting_ace.snippets_desc'] = 'Code snippets you can expand by pressing “Tab” key. Snippet example:<br /><br /><pre>\nsnippet getr\n [!getResources? parents=`${1}`${2}]]\n</pre></br>You can insert “Tab” character by pressing Alt + 09';
$_lang['setting_ace.height'] = 'Edit area height';
$_lang['setting_ace.height_desc'] = 'Editor height in pixel unit. If left blank, a defaul height will be used.';
$_lang ['setting_ace.grow'] = 'Fit height to text';
$_lang ['setting_ace.grow_desc'] = 'The height of the editor will be adjusted to the text. The minimum height will be equal to the option ace.height. Possible values: Empty - height does not fit the text; The number is greater than 0 - the height is adjusted to the text but not more than the value; 0 - height is customized for text, height is unlimited. ';
$_lang['setting_ace.grow'] = 'Fit height to text';
$_lang['setting_ace.grow_desc'] = 'The height of the editor will be adjusted to the text. The minimum height will be equal to the option ace.height. Possible values: Empty - height does not fit the text; The number is greater than 0 - the height is adjusted to the text but not more than the value; 0 - height is customized for text, height is unlimited. ';
$_lang['setting_ace.html_elements_mime'] = 'MIME-type for html elements';
$_lang['setting_ace.html_elements_mime_desc'] = 'This type will be used by the editor for html elements - templates, chunks and resources with html type. If not specified, the default type will be used';
6 changes: 4 additions & 2 deletions core/components/ace/lexicon/nl/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@
$_lang['setting_ace.snippets_desc'] = 'Code snippets you can expand by pressing “Tab” key. Snippet example:<br /><br /><pre>\nsnippet getr\n [!getResources? parents=`${1}`${2}]]\n</pre></br>You can insert “Tab” character by pressing Alt + 09';
$_lang['setting_ace.height'] = 'Edit area height';
$_lang['setting_ace.height_desc'] = 'Editor height in pixel unit. If left blank, a defaul height will be used.';
$_lang ['setting_ace.grow'] = 'Pas hoogte aan tekst aan';
$_lang ['setting_ace.grow_desc'] = 'De hoogte van de editor wordt aangepast aan de tekst. De minimale hoogte is gelijk aan de optie aashoogte. Mogelijke waarden: leeg - hoogte past niet in de tekst; Het aantal is groter dan 0 - de hoogte is aangepast aan de tekst, maar niet hoger dan de waarde; 0 - hoogte is aangepast voor tekst, hoogte is onbeperkt. ';
$_lang['setting_ace.grow'] = 'Pas hoogte aan tekst aan';
$_lang['setting_ace.grow_desc'] = 'De hoogte van de editor wordt aangepast aan de tekst. De minimale hoogte is gelijk aan de optie aashoogte. Mogelijke waarden: leeg - hoogte past niet in de tekst; Het aantal is groter dan 0 - de hoogte is aangepast aan de tekst, maar niet hoger dan de waarde; 0 - hoogte is aangepast voor tekst, hoogte is onbeperkt. ';
$_lang['setting_ace.html_elements_mime'] = 'MIME-type voor html-elementen';
$_lang['setting_ace.html_elements_mime_desc'] = 'Dit type wordt door de editor gebruikt voor html-elementen - sjablonen, chunks en bronnen met html-type. Als dit niet wordt opgegeven, wordt het standaardtype gebruikt';
4 changes: 3 additions & 1 deletion core/components/ace/lexicon/ru/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@
$_lang['setting_ace.height'] = 'Высота области редактирования';
$_lang['setting_ace.height_desc'] = 'Высота редактора в пикселах. Если значение не указано, редактор будет иметь высоту по умолчанию.';
$_lang['setting_ace.grow'] = 'Подогнать высоту под текст';
$_lang['setting_ace.grow_desc'] = 'Высота редактора будет подогнана под текст. Минимальная высота будет равна опции ace.height. Возможные значения: Пусто - высота не подгоняется под текст; Число больше 0 - высота подгоняется под текст но не более значения; 0 - высота подгоняется под текст, высота не ограничена.';
$_lang['setting_ace.grow_desc'] = 'Высота редактора будет подогнана под текст. Минимальная высота будет равна опции ace.height. Возможные значения: Пусто - высота не подгоняется под текст; Число больше 0 - высота подгоняется под текст но не более значения; 0 - высота подгоняется под текст, высота не ограничена.';
$_lang['setting_ace.html_elements_mime'] = 'MIME-type для html элементов';
$_lang['setting_ace.html_elements_mime_desc'] = 'Этот тип будет использован редактором для html элементов - шаблонов, чанков и ресурсов с типом html. Если не указан будет использован тип по умолчанию';

0 comments on commit 21486b1

Please sign in to comment.