[3.3][BETA] CodeMirror (helper ext)

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Ideas Centre
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

[3.3][BETA] CodeMirror (helper ext)

Post by martti »

Extension Name: CodeMirror (helper ext)
Author: martti
Extension Description: This phpBB helper extension provides a basic integration of the CodeMirror code editor for use by other extensions. The extension tries to load all required dependencies by inspecting a configuration set in JSON format.
Extension Version: 0.7.0
Requirements:
  • phpBB 3.3+
  • PHP 7.1+
Extension Download: https://github.com/marttiphpbb/phpbb-ex ... master.zip The files are to be put in ext/marttiphpbb/codemirror
Github repository: https://github.com/marttiphpbb/phpbb-ext-codemirror
Languages: en
Templates: all & ACP
Screenshot:

Image

For extension Developers: How to use in your extension

ACP controller:

First check if this extension is enabled, then get the service marttiphpbb.codemirror.load. With this service you set the mode (language) of the editor.

Code: Select all

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.		
				}
				
				$template->assign_vars([
					'CONTENT'	=> $content,  // retrieve or set somewhere above.
					'U_ACTION'	=> $this->u_action,
				]);
	
			break;
		}
	}
}
ACP Template

Code: Select all

		<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.
Last edited by martti on Mon May 30, 2022 6:59 pm, edited 10 times in total.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.2][BETA] CodeMirror (helper ext)

Post by martti »

Update version 0.2.0
  • The CodeMirror editor can also be used in all templates in the board itself (not only ACP). The way to use it is the same as in the ACP.
  • Upgrade CodeMirror version to 5.39.2
Image
fagbutlil
I've Been Banned!
Posts: 77
Joined: Wed Mar 07, 2018 10:56 pm

Re: [3.2][BETA] CodeMirror (helper ext)

Post by fagbutlil »

Nice thank you.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.2][BETA] CodeMirror (helper ext)

Post by martti »

New version 0.3.0
  • Upgrade to CodeMirror 5.40.2
  • New feature: colorpicker. To enable this, add "colorpicker": true to the configuration. The default configuration comes with the colorpicker enabled.
Image
Lady_G
Registered User
Posts: 276
Joined: Fri Jun 08, 2012 12:38 pm
Location: US

Re: [3.2][BETA] CodeMirror (helper ext)

Post by Lady_G »

I have installed version 0.3.0 (git clone) and see PHP warnings when I enable the extension:

Code: Select all

[phpBB Debug] PHP Warning: in file [ROOT]/ext/marttiphpbb/codemirror/ext.php on line 35: file_get_contents([ROOT]/ext/marttiphpbb/codemirror/codemirror/package.json): failed to open stream: No such file or directory
[phpBB Debug] PHP Notice: in file [ROOT]/ext/marttiphpbb/codemirror/ext.php on line 44: Undefined variable: old_state
ACP --> Extensions --> CodeMirror --> Configuration displays this PHP Notice:

Code: Select all

[phpBB Debug] PHP Notice: in file [ROOT]/ext/marttiphpbb/codemirror/service/load.php on line 260: Undefined variable: valid_config
This is a new install. I have also installed [3.2][BETA] Show Topic Starter and [3.2][BETA] Extra Style, but have not entered any data.

My test environment: localhost
OS: Linux
Database: PostgreSQL 10.5 on x86_64-redhat-linux-gnu
phpBB version: 3.2.3
PHP: 7.1.17

I have also reported a problem with [3.2][BETA] Extra Style. I don't know if these problems are related.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.2][BETA] CodeMirror (helper ext)

Post by martti »

Lady_G wrote: Fri Sep 28, 2018 12:51 am I have installed version 0.3.0 (git clone) and see PHP warnings when I enable the extension:

Code: Select all

[phpBB Debug] PHP Warning: in file [ROOT]/ext/marttiphpbb/codemirror/ext.php on line 35: file_get_contents([ROOT]/ext/marttiphpbb/codemirror/codemirror/package.json): failed to open stream: No such file or directory
[phpBB Debug] PHP Notice: in file [ROOT]/ext/marttiphpbb/codemirror/ext.php on line 44: Undefined variable: old_state
ACP --> Extensions --> CodeMirror --> Configuration displays this PHP Notice:

Code: Select all

[phpBB Debug] PHP Notice: in file [ROOT]/ext/marttiphpbb/codemirror/service/load.php on line 260: Undefined variable: valid_config
Thanks for reporting! I have fixed these in the new version 0.3.1
tofino
Registered User
Posts: 55
Joined: Fri Nov 06, 2015 1:55 pm

Re: [3.2][BETA] CodeMirror (helper ext)

Post by tofino »

Sounds interesting :)
Lady_G
Registered User
Posts: 276
Joined: Fri Jun 08, 2012 12:38 pm
Location: US

Re: [3.2][BETA] CodeMirror (helper ext)

Post by Lady_G »

martti wrote: Fri Sep 28, 2018 8:11 am Thanks for reporting! I have fixed these in the new version 0.3.1
I confirm the fix. The warnings are not displayed.

Can you please clarify the description?

From:
Try theme
This is to try other themes. Only "theme" defined in the json configuration below will be saved.
To:
Try theme
You can change your theme by modifying the json configuration file below. First, select a "theme" from the drop-down list to preview a new theme. Then, edit the configuration file and save your theme.
The Reset button has no effect.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.2][BETA] CodeMirror (helper ext)

Post by martti »

Lady_G wrote: Sat Sep 29, 2018 1:05 am
Can you please clarify the description?

From:
Try theme
This is to try other themes. Only "theme" defined in the json configuration below will be saved.
To:
Try theme
You can change your theme by modifying the json configuration file below. First, select a "theme" from the drop-down list to preview a new theme. Then, edit the configuration file and save your theme.
I wouldn't write an instruction like that. You don't have to preview in order to change the configuration. Maybe it can be better emphasized that this is not a setting that is saved in the database, but just a tool to preview themes.
Lady_G wrote: Sat Sep 29, 2018 1:05 am The Reset button has no effect.
It's working for me. It's to reset unsaved edits. It's like refreshing the page.
Lady_G
Registered User
Posts: 276
Joined: Fri Jun 08, 2012 12:38 pm
Location: US

Re: [3.2][BETA] CodeMirror (helper ext)

Post by Lady_G »

martti wrote: Sun Sep 30, 2018 6:43 am I wouldn't write an instruction like that. You don't have to preview in order to change the configuration. Maybe it can be better emphasized that this is not a setting that is saved in the database, but just a tool to preview themes.
Yes, a clarification will help. Here is my suggestion:
This is to try other themes. The theme is saved in the json configuration file, not in the database. You can edit the json configuration file below.
==========
martti wrote: Sun Sep 30, 2018 6:43 am
Lady_G wrote: Sat Sep 29, 2018 1:05 am The Reset button has no effect.
It's working for me. It's to reset unsaved edits. It's like refreshing the page.
I did not understand the intent of 'Reset'. The button is working as you describe. Perhaps the button text could be changed to "Reset changes"?
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.2][BETA] CodeMirror (helper ext)

Post by martti »

Lady_G wrote: Sun Sep 30, 2018 4:28 pm I did not understand the intent of 'Reset'. The button is working as you describe. Perhaps the button text could be changed to "Reset changes"?
Continue here. (same discussion)
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.2][BETA] CodeMirror (helper ext)

Post by martti »

Version 0.3.2 brings:
  • An update of the version of the colorpicker.
  • Refrasing of the "Try Theme" selector:
    This selector is just a tool to preview themes;
    it`s setting is not part of the configuration and won`t be saved.
    To change the default theme you can edit or add a "theme"
    in the JSON configuration below.
Nothing shocking.
Lady_G
Registered User
Posts: 276
Joined: Fri Jun 08, 2012 12:38 pm
Location: US

Re: [3.2][BETA] CodeMirror (helper ext)

Post by Lady_G »

Version 0.3.2 is working as expected (nothing shocking).

I don't understand your description to add a theme.
This selector is just a tool to preview themes; it`s setting is not part of the configuration and won`t be saved. To change the default theme you can edit or add a "theme" in the JSON configuration below.
The theme is already present in the JSON file. Can more than one theme be implemented?

If only one theme is allowed, I would suggest revising the text description to be:
This selector is just a tool to preview themes; it`s setting is not part of the configuration and won`t be saved. To change the default theme, you can edit the "theme" in the JSON configuration file below.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.2][BETA] CodeMirror (helper ext)

Post by martti »

Lady_G wrote: Thu Oct 25, 2018 11:30 pm Version 0.3.2 is working as expected (nothing shocking).

I don't understand your description to add a theme.
This selector is just a tool to preview themes; it`s setting is not part of the configuration and won`t be saved. To change the default theme you can edit or add a "theme" in the JSON configuration below.
The theme is already present in the JSON file. Can more than one theme be implemented?

If only one theme is allowed, I would suggest revising the text description to be:
This selector is just a tool to preview themes; it`s setting is not part of the configuration and won`t be saved. To change the default theme, you can edit the "theme" in the JSON configuration file below.
You could have the removed the "theme" entry in a previous edit of the JSON file, which gives the default Codemirror theme. That's why add is also a possibility.
User avatar
martti
Registered User
Posts: 914
Joined: Thu Jul 31, 2014 8:23 am
Location: Belgium

Re: [3.2][BETA] CodeMirror (helper ext)

Post by martti »

Update version 0.4.0
  • CodeMirror version 5.41.0
  • I've noticed the command for the Ctrl-F key was wrong ("search") in the default configuration, it should be "find". "search" doesn't do anything.

Return to “Extensions in Development”