marttiphpbb / phpbb-ext-codemirror

phpBB extension that integrates CodeMirror
GNU General Public License v2.0
0 stars 0 forks source link

PhpBB Extension - marttiphpbb CodeMirror (helper ext)

Topic on phpBB.com

Requirements

Features

This phpBB extension provides a basic integration of the CodeMirror code editor for use by other extensions. See CodeMirror configuration for the possible options and commands. The extension tries to load all required dependencies by inspecting a configuration set in JSON format.

Screenshot

Configuration

Extra Options and Commands

This extension provides some extra configuration options and commands. All of them are prefixed with "marttiphpbb".

Border

To provide a border around the CodeMirror editor. Helpful for the light themes against the light background of the ACP.

Options

Commands

Full screen

Commands for the CodeMirror "fullScreen" option:

Submit

This command generates a click event on submit buttons:

Limitations

Quick Install

You can install this on the latest release of phpBB by following the steps below:

Uninstall

Support

For extension developers: how to use

In the ACP controller

(in a normal controller likewise)

class main_module
{
    var $u_action;

    function main($id, $mode)
    {
        global $phpbb_container;

        $ext_manager = $phpbb_container->get('ext.manager');
        $template = $phpbb_container->get('template');

        // ...

        switch($mode)
        {
            case 'your_mode':

                //..

                if ($request->is_set_post('submit'))
                {
                    // ...
                }

                //...

                if ($ext_manager->is_enabled('marttiphpbb/codemirror'))
                {
                    $load = $phpbb_container->get('marttiphpbb.codemirror.load');
                    $load->set_mode('json'); // or javascript, css, html, php, markdown, etc.s
                }

                $template->assign_vars([
                    'CONTENT'  => $content,  // retrieve or set somewhere above.
                    'U_ACTION' => $this->u_action,
                ]);

            break;
        }
    }
}

Template (in ACP or board)

<textarea name="content" id="content"{{- marttiphpbb_codemirror.data_attr ?? '' -}}>
    {{- CONTENT -}}
</textarea>

When this extension is enabled, the <textarea> will be hidden and instead a CodeMirror instance is shown. Note that the dashes in {{- CONTENT -}} are important. Otherwise unwanted whitespace will be inserted.

License

GPL-2.0

(CodeMirror is licensed under MIT.)