| Server IP : 185.11.201.71 / Your IP : 192.168.7.18 Web Server : Apache/2.4.29 (Ubuntu) System : Linux tech-virtual-machine 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 User : tech ( 1000) PHP Version : 7.4.28 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/enaireaceleradora.old/wp-content/plugins/code-snippets/js/ |
Upload File : |
import tinymce from 'tinymce'
import type { Editor } from 'tinymce'
import type { ContentShortcodeAtts, SourceShortcodeAtts } from './types/Shortcodes'
import type { LocalisedEditor } from './types/WordPressEditor'
const convertToValues = (array: Record<string, string>) =>
Object.keys(array).map(key => ({
text: array[Number(key)],
value: key
}))
export const insertContentMenu = (editor: Editor, activeEditor: LocalisedEditor) => ({
text: activeEditor.getLang('code_snippets.insert_source_menu'),
onclick: () => {
editor.windowManager.open({
title: activeEditor.getLang('code_snippets.insert_source_title'),
body: [
{
type: 'listbox',
name: 'id',
label: activeEditor.getLang('code_snippets.snippet_label'),
values: convertToValues(<Record<string, string>> activeEditor.getLang('code_snippets.all_snippets'))
},
{
type: 'checkbox',
name: 'line_numbers',
label: activeEditor.getLang('code_snippets.show_line_numbers_label')
}
],
onsubmit: (event: { data: SourceShortcodeAtts }) => {
const id = parseInt(event.data.id, 10)
if (!id) {
return
}
let atts = ''
if (event.data.line_numbers) {
atts += ' line_numbers=true'
}
editor.insertContent(`[code_snippet_source id=${id}${atts}]`)
}
}, {})
}
})
export const insertSourceMenu = (editor: Editor, ed: LocalisedEditor) => ({
text: ed.getLang('code_snippets.insert_content_menu'),
onclick: () => {
editor.windowManager.open({
title: ed.getLang('code_snippets.insert_content_title'),
body: [
{
type: 'listbox',
name: 'id',
label: ed.getLang('code_snippets.snippet_label'),
values: convertToValues(<Record<string, string>> ed.getLang('code_snippets.content_snippets'))
},
{
type: 'checkbox',
name: 'php',
label: ed.getLang('code_snippets.php_att_label')
},
{
type: 'checkbox',
name: 'format',
label: ed.getLang('code_snippets.format_att_label')
},
{
type: 'checkbox',
name: 'shortcodes',
label: ed.getLang('code_snippets.shortcodes_att_label')
}
],
onsubmit: (event: { data: ContentShortcodeAtts }) => {
const id = parseInt(event.data.id, 10)
if (!id) {
return
}
let atts = ''
for (const [opt, val] of Object.entries(event.data)) {
if ('id' !== opt && val) {
atts += ` ${opt}=${val}`
}
}
editor.insertContent(`[code_snippet id=${id}${atts}]`)
}
}, {})
}
})
tinymce.PluginManager.add('code_snippets', editor => {
const activeEditor = <LocalisedEditor> tinymce.activeEditor
editor.addButton('code_snippets', {
icon: 'code',
menu: [insertContentMenu(editor, activeEditor), insertSourceMenu(editor, activeEditor)],
type: 'menubutton'
})
})