Codebox Plus

Looking for an Extension? Have an Extension request? Post your request here for help. (Note: This forum is community supported; while there is an Extensions Development Team, said team does not dedicate itself to handling requests in this forum)
Ideas Centre
nou nou
Registered User
Posts: 494
Joined: Sat Oct 29, 2016 8:08 pm

Re: Codebox Plus

Post by nou nou »

I solved it this way; in codeboxplus/controller/main.php at the end of the file, just above return $code;, add:

Code: Select all

$code = str_replace("<br/>", "", $code);
Not sure if that's the prettiest way to do it - I don't speak php. :)

The one thing I can't figure out is to make the download function work with multiple CodeBoxes in a single post. When you have 2, the download picks the last one, and if you click the download button for the second one, the link is dead.
User avatar
tlem
Registered User
Posts: 166
Joined: Sun Jan 24, 2016 4:47 pm
Location: Bordeaux (France)
Name: Thierry
Contact:

Re: Codebox Plus

Post by tlem »

Hi, there is my 2 cents :

For using CodeBox Plus on phpBB 3.2.x forum, I use this version : https://github.com/o0johntam0o/phpBB-Ex ... e/phpbb3.2
And I apply these modification :

For the interline in excess : In \ext\o0johntam0o\codeboxplus\event\main_listener.php
Find

Code: Select all

return $this->codebox_template(preg_replace('#\<br\\s*/?\>#msi', "\n", $arg[3]), $arg[1], $arg[2], $post_id, ++$part);
replace by

Code: Select all

return $this->codebox_template(preg_replace('#\<br\\s*/?\>#msi', "", $arg[3]), $arg[1], $arg[2], $post_id, ++$part);
To remove line numbering : In \ext\o0johntam0o\codeboxplus\event\main_listener.php
Find

Code: Select all

$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
replace by

Code: Select all

//$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
If you want by default a partial extented box : In ext\o0johntam0o\codeboxplus\event\main_listener.php
Find

Code: Select all

$re .= '<div><div style="display: ' . (($lang != 'NULL' && !$this->expanded) ? 'none' : 'inline') . ';">';
replace by

Code: Select all

$re .= '<div><div style="display: ' . (($lang != 'NULL' && !$this->expanded) ? 'none' : 'block') . '; max-height: 250px; overflow:auto;">';
If you want to adapt options of GeSHi : In xt\o0johntam0o\codeboxplus\event\main_listener.php
Find

Code: Select all

// GeSHi
$geshi = new \o0johntam0o\codeboxplus\includes\geshi\geshi();
And change the options from below according to the GeSHi documentation.
If you have problem with "Select All function" : In ext/o0johntam0o/codeboxplus/styles/all/template/script.js
Find

Code: Select all

			s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
replace by

Code: Select all

s.selectAllChildren(e);

I really expect that o0johntam0o will find time to update his extension, and that he adds some setting features.
nou nou
Registered User
Posts: 494
Joined: Sat Oct 29, 2016 8:08 pm

Re: Codebox Plus

Post by nou nou »

Hi tlem,


Thank you very much for sharing!

Have you found a solution for having multiple CodeBox entries in a single post with a download option?

To demonstrate, consider this example post:

Code: Select all

Codebox example:

[Codebox=lua file=testone.lua]
test1
[/Codebox]

Adding a second codebox example:
[Codebox=lua file=testtwo.lua]
test2
[/Codebox]

In the above post, when I click on the first download link, it downloads testtwo.lua. When clicking on the second download link (for testtwo.lua) I get Information: Code contents not found.

testone.lua can't be downloaded from the post at all.

If you have a solution for this - please share, I'd be delighted!
User avatar
tlem
Registered User
Posts: 166
Joined: Sun Jan 24, 2016 4:47 pm
Location: Bordeaux (France)
Name: Thierry
Contact:

Re: Codebox Plus

Post by tlem »

Hi nou nou
I do not use the download function, but I think that what you talk about came from script.js.

My knowledge is not sufficient to help you, but maybe someone with more knowledge will help you. Be patient. ^^
nou nou
Registered User
Posts: 494
Joined: Sat Oct 29, 2016 8:08 pm

Re: Codebox Plus

Post by nou nou »

Hi tlem,


I'm hoping to find the time to look into it again soon. I think it's in main.php, as that is where the previous download issues were, too. But I'm not sure. As I said before, no knowledge of PHP to speak of...

Basically it creates a separate ID for each instance of Codebox inside a post, but there is only ever one valid link.

Development being picked up again would be terrific. It really is a great and useful extension.
nou nou
Registered User
Posts: 494
Joined: Sat Oct 29, 2016 8:08 pm

Re: Codebox Plus

Post by nou nou »

The download issue is fixed! Hurray!

Thanks to kasimi, who was so kind to take a look at the code:
  • Open controller/main.php
  • Find

    Code: Select all

    preg_match_all('#<CODEBOX codebox="[a-z0-9_-]+" file=".*"><s>\[Codebox=[a-z0-9_-]+ file=(.*)\]<\/s>(.*?)<e>\[\/Codebox]<\/e><\/CODEBOX>#msi', $post_data['post_text'], $code_data);
  • Replace with

    Code: Select all

    preg_match_all('#<CODEBOX codebox="[a-z0-9_-]+" file=".*?"><s>\[Codebox=[a-z0-9_-]+ file=(.*?)\]<\/s>(.*?)<e>\[\/Codebox]<\/e><\/CODEBOX>#msi', $post_data['post_text'], $code_data);
There are several versions of main.php in circulation, so if the Find string doesn't match, look for

Code: Select all

//- Process post data
// Collect code
Near line 200, and replace the regex underneath.

Thanks again kasimi, and people in this thread! :D
User avatar
tlem
Registered User
Posts: 166
Joined: Sun Jan 24, 2016 4:47 pm
Location: Bordeaux (France)
Name: Thierry
Contact:

Re: Codebox Plus

Post by tlem »

Thanks to kasimi (and you too nou nou).
sfzeller
Registered User
Posts: 45
Joined: Mon Dec 11, 2017 9:02 pm

Re: Codebox Plus

Post by sfzeller »

Does anybody know how to modify the syntax highlighter https://github.com/s9e/phpbb-ext-highlighter. E.g., I want the tabs to be at 4 spaces instead of 8 etc.?
nou nou
Registered User
Posts: 494
Joined: Sat Oct 29, 2016 8:08 pm

Re: Codebox Plus

Post by nou nou »

sfzeller wrote: Tue Mar 20, 2018 7:54 pm Does anybody know how to modify the syntax highlighter https://github.com/s9e/phpbb-ext-highlighter. E.g., I want the tabs to be at 4 spaces instead of 8 etc.?
I did that with this bit of css:

Code: Select all

.codebox code {
    white-space: pre;
    tab-size: 4;
    -moz-tab-size: 4;
	-o-tab-size: 4;
}
sfzeller
Registered User
Posts: 45
Joined: Mon Dec 11, 2017 9:02 pm

Re: Codebox Plus

Post by sfzeller »

Thank for your reply. But the css you posted refers to Codebox only, not the Highlighter I would like to use, right? If not, and it does apply to the phpBB highlighter, then which style sheet would I be modifying and where can I find it? Sorry for my very basic questions.
nou nou
Registered User
Posts: 494
Joined: Sat Oct 29, 2016 8:08 pm

Re: Codebox Plus

Post by nou nou »

The CSS goes into your style's stylesheets, so it applies to all codeboxes on the forum. The highlighter will highlight the syntax, not change the syntax.
sfzeller
Registered User
Posts: 45
Joined: Mon Dec 11, 2017 9:02 pm

Re: Codebox Plus

Post by sfzeller »

OK, so I added this to: /styles/prosilver/theme/content.css (the only stylesheet I found that had code styles in it):

.codebox code {
overflow: auto;
display: block;
height: auto;
max-height: 200px;
padding: 5px 3px;
font: 0.9em Monaco, "Andale Mono","Courier New", Courier, monospace;
line-height: 1.3em;
white-space: pre;
tab-size: 4;
-moz-tab-size: 4;
-o-tab-size: 4;
}

but it didn't change anything.
nou nou
Registered User
Posts: 494
Joined: Sat Oct 29, 2016 8:08 pm

Re: Codebox Plus

Post by nou nou »

Maybe this helps?

viewtopic.php?f=74&t=2254026

The way I figure out CSS is right click on the element I'd like to change, then select "inspect element" and play with all the CSS rules that show up until the thing does what I want. Then roll those changes into a custom CSS file.
sfzeller
Registered User
Posts: 45
Joined: Mon Dec 11, 2017 9:02 pm

Re: Codebox Plus

Post by sfzeller »

I'm sorry I wasn't very clear in my last post. I have less of a problem inserting the css into the correct stylesheet than applying the style whenever I choose <code> rather than <codebox>. I was under the impression that when I use <code> it would display the code using the highlighter, not codebox. I have both extensions enabled (see attached images) so perhaps they conflict?

Image
Image
User avatar
TJK
Registered User
Posts: 136
Joined: Sat Dec 26, 2015 9:10 pm
Name: Tolaso J Kos
Contact:

Re: Codebox Plus

Post by TJK »

Anyone , any ideas how to update this to the latest version 3.3 ? Its repo is here. The error that I get is

Code: Select all

 PHP Fatal error:  Uncaught InvalidArgumentException: The routing file 
 ".../community/ext/o0johntam0o/codeboxplus/config/routing.yml" contains 
 unsupported keys for "o0johntam0o_codeboxplus_base_controller": "pattern". 
 Expected one of: "resource", "type", "prefix", "path", "host", "schemes", 
 "methods", "defaults", "requirements", "options", "condition", 
 "controller". in /.../community/vendor/symfony/routing/Loader/YamlFileLoader.php:206
Update fixed it myself. Solution is to replace the routing.yml with the following:

Code: Select all

o0johntam0o_codeboxplus_base_controller:
    path: /codeboxplus
    defaults: { _controller: o0johntam0o.codeboxplus.controller:base }

o0johntam0o_codeboxplus_download_controller:
    path: /codeboxplus/download/{id}-{part}
    defaults: { _controller: o0johntam0o.codeboxplus.controller:downloader, id:0, part:0 }
    requirements:
        id: \d+
        part: \d+
Hire me for your update/upgrade forum inquiries or your forum tasks (installation , set up , etc)
Have I been of any help today? Buy me a beer.
Post Reply

Return to “Extension Requests”