[ABD] Codebox Plus

Any abandoned Extensions will be moved to this forum.

WARNING: Extensions in this forum are not currently being supported or maintained by the original Extension author. Proceed at your own risk.
Forum rules
IMPORTANT: Extension Development Forum rules

WARNING: Extensions in this forum are not currently being supported nor updated by the original Extension author. Proceed at your own risk.
User avatar
o0johntam0o
Registered User
Posts: 228
Joined: Thu Sep 23, 2010 3:53 pm
Location: Viet Nam
Name: Tam
Contact:

Re: [BETA] Codebox Plus

Post by o0johntam0o » Sat Nov 15, 2014 1:27 pm

Hi Tuqe, please take a notice at step 6, you will need to add or remove some characters in the post body, then submit it again (to force re-new the post's hash).

Tuqe
Registered User
Posts: 63
Joined: Mon Nov 10, 2014 9:18 am
Location: Turkey

Re: [BETA] Codebox Plus

Post by Tuqe » Sat Nov 15, 2014 5:33 pm

How do you use? Would you please add a screenshot?
Use case type please.

Code: Select all

[Codebox=?][/Codebox]

User avatar
o0johntam0o
Registered User
Posts: 228
Joined: Thu Sep 23, 2010 3:53 pm
Location: Viet Nam
Name: Tam
Contact:

Re: [BETA] Codebox Plus

Post by o0johntam0o » Sun Nov 16, 2014 5:08 am

Okay Tuqe,
For example, currently your post is:
There is something...
[codebox=php file=exp.php]Source code[/code]
Blah blah
You will need to change it to
There is something...
[codebox=php file=exp.php]Source code[/code]
Blah blah blah
Then submit that post. That's all.

Modified, it's my mistake :oops:
Last edited by o0johntam0o on Mon Nov 17, 2014 3:16 am, edited 1 time in total.

Tuqe
Registered User
Posts: 63
Joined: Mon Nov 10, 2014 9:18 am
Location: Turkey

Re: [BETA] Codebox Plus

Post by Tuqe » Sun Nov 16, 2014 3:53 pm

Image

Sorry, don't it.

User avatar
o0johntam0o
Registered User
Posts: 228
Joined: Thu Sep 23, 2010 3:53 pm
Location: Viet Nam
Name: Tam
Contact:

Re: [BETA] Codebox Plus

Post by o0johntam0o » Mon Nov 17, 2014 3:10 am

There's a mistake in your post Tuqe.
[Codebox=php exp.php]....[/Code]
It should be [Codebox=php [color=#FF0000]file=[/color]exp.php]....[[color=#FF0000]/Codebox[/color]]

Tuqe
Registered User
Posts: 63
Joined: Mon Nov 10, 2014 9:18 am
Location: Turkey

Re: [BETA] Codebox Plus

Post by Tuqe » Mon Nov 17, 2014 7:20 am

it's ended. Thanks a lot.
8-) :geek: :ugeek:
But it's use must easy.

marcovo
Registered User
Posts: 239
Joined: Fri Nov 16, 2012 12:19 pm
Location: The Netherlands
Name: Marco

Re: [BETA] Codebox Plus

Post by marcovo » Wed Dec 03, 2014 1:09 pm

Would it be possible to make the bbcode tag customisable? E.g. to make it possible to change [codebox ] into [geshi ] or maybe even

Code: Select all

?
Alternatively, wouldn't it be a nice alternative to make it possible to use tags like [php ] instead of [codebox=php ], and [html ] instead of [codebox=html ], etc..?
Just a few thoughts... it seems a bit restricted to only be able to use the [codebox ] tag without further options.

User avatar
o0johntam0o
Registered User
Posts: 228
Joined: Thu Sep 23, 2010 3:53 pm
Location: Viet Nam
Name: Tam
Contact:

Re: [BETA] Codebox Plus

Post by o0johntam0o » Wed Dec 03, 2014 4:50 pm

I see your point marcovo, but it's not easy to do that. Also you may get trouble when using another extensions together with Codebox Plus.

trinobi
Registered User
Posts: 8
Joined: Fri Nov 27, 2009 4:53 am
Location: Sài Gòn
Name: Tri NoBi
Contact:

Re: [BETA] Codebox Plus

Post by trinobi » Fri Dec 05, 2014 8:57 am

Hi marcovo,
I modified 2 files to compatible with my old mod:
1. ext\o0johntam0o\codeboxplus\event\main_listener.php

Code: Select all

<?php
/**
*
* Codebox Plus extension for the phpBB Forum Software package
*
* @copyright (c) 2014 o0johntam0o
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

namespace o0johntam0o\codeboxplus\event;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Event listener
*/
class main_listener implements EventSubscriberInterface
{
    protected $helper, $template, $user, $config, $root_path, $php_ext;
    protected $codebox_plus_enabled, $download_enabled, $find, $find_code, $find_lang, $find_file, $geshi_syntax;
    
    public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, $root_path, $php_ext)
    {
        $this->helper = $helper;
        $this->template = $template;
        $this->user = $user;
        $this->config = $config;
        $this->root_path = $root_path;
        $this->php_ext = $php_ext;
        
        $this->codebox_plus_enabled = isset($this->config['codebox_plus_enable']) ? $this->config['codebox_plus_enable'] : 0;
        $this->download_enabled = isset($this->config['codebox_plus_download']) ? $this->config['codebox_plus_download'] : 0;
        
        $this->geshi_syntax = $this->get_geshi_syntaxes();
    }
    
    static public function getSubscribedEvents()
    {
        return array(
            'core.user_setup'                            => 'load_language_on_setup',
            //'core.modify_submit_post_data'                => 'posting_modify_input',
            //'core.posting_modify_template_vars'            => 'posting_event',
            'core.viewtopic_post_rowset_data'            => 'viewtopic_event',
            'core.modify_format_display_text_after'        => 'message_parser_event',
        );
    }
    
    public function load_language_on_setup($event)
    {
        $lang_set_ext = $event['lang_set_ext'];
        $lang_set_ext[] = array(
            'ext_name' => 'o0johntam0o/codeboxplus',
            'lang_set' => 'codebox_plus',
        );
        $event['lang_set_ext'] = $lang_set_ext;
        
        if ($this->user->page['page_name'] == 'posting.' . $this->php_ext)
        {
            $this->template->assign_vars(array(
                'CODEBOX_PLUS_IN_POSTING'                => true,
            ));
        }
        
        if ($this->codebox_plus_enabled)
        {
            $this->template->assign_vars(array(
                'CODEBOX_PLUS_AVAILABLE'                => true,
            ));
        }
        
        if ($this->download_enabled)
        {
            $this->template->assign_vars(array(
                'CODEBOX_PLUS_DOWNLOAD_AVAILABLE'        => true,
            ));
        }
    }
    
    /*
    * Event: core.modify_format_display_text_after (message_parser.php)
    * Use: $this->codebox_template()
    * Generate text for preview
    */
    public function message_parser_event($event)
    {    
        if (isset($event['text']))
        {
            $text = $event['text'];
            while (preg_match("#\[(?P<start>[a-z0-9_-]+)\](?P<code>.*?)\[\/(?P<end>[a-z0-9_-]+)\]#msi", $text, $results) && $results['start'] == $results['end'] && in_array($results['start'], $this->geshi_syntax))
            {
                $results['code'] = $this->codebox_clean_code($results['code']);
                if ($this->codebox_plus_enabled)
                {
                    $text = preg_replace("#\[([a-z0-9_-]+)\](.*?)\[\/([a-z0-9_-]+)\]#msi", $this->codebox_template($results['code'], $results['start']), $text, 1);
                }
                else
                {
                    break;
                }
            }
            $event['text'] = $text;
        }
    }
    
    /*
    * Event: core.viewtopic_post_rowset_data (viewtopic.php)
    */
    public function viewtopic_event($event)
    {
        if (isset($event['rowset_data']))
        {
            $rowset_data = $event['rowset_data'];
            $post_text = isset($rowset_data['post_text']) ? $rowset_data['post_text'] : '';
            $bbcode_uid = isset($rowset_data['bbcode_uid']) ? $rowset_data['bbcode_uid'] : '';
            $post_id = isset($rowset_data['post_id']) ? $rowset_data['post_id'] : 0;
            $part = 0;

            while (preg_match("#\[(?P<start>[a-z0-9_-]+)\](?P<code>.*?)\[\/(?P<end>[a-z0-9_-]+)\]#msi", $post_text, $results) && $results['start'] == $results['end'] && in_array($results['start'], $this->geshi_syntax))
            {
                $part++;
                if ($this->codebox_plus_enabled)
                {
                    $post_text = preg_replace("#\[([a-z0-9_-]+)\](.*?)\[\/([a-z0-9_-]+)\]#msi", $this->codebox_template($results['code'], $results['start'], '', $post_id, $part), $post_text, 1);
                }
                else
                {
                    break;
                }
            }
            
            
            if (isset($rowset_data['post_text']) && $part > 0)
            {
                $rowset_data['post_text'] = $post_text;
                $event['rowset_data'] = $rowset_data;
            }
        }
    }
    
    /*
    * Event: core.modify_submit_post_data (includes/functions_posting.php)
    * Use: $this->codebox_clean_code()
    * Generate text for storage
    */
    /*
    public function posting_modify_input($event)
    {
        if (isset($event['data']))
        {
            // REQUEST
            $data = $event['data'];
            $message = $data['message'];
            $bbcode_uid = $data['bbcode_uid'];
            // MODIFY
            $message = preg_replace("#(\[codebox=[a-z0-9_-]+ file=(?:.*?):" . $bbcode_uid . "\])(.*?)(\[/codebox:" . $bbcode_uid . "\])#msie", "'\$1' . \$this->codebox_clean_code('\$2', \$bbcode_uid) . '\$3'", $message);
            // RETURN
            $data['message'] = $message;
            $event['data'] = $data;
            $event['update_message'] = true;
        }
    }*/
    
    /*
    * Use: $this->codebox_parse_code(), $this->codebox_decode_code()
    * Generate text for display
    */
    public function codebox_template($code = '', $lang = 'text', $file = '', $id = 0, $part = 0)
    {
        if (strlen($code) == 0)
        {
            return '';
        }
        
        if (strlen($file) == 0)
        {
            $file = $this->user->lang['CODEBOX_PLUS_DEFAULT_FILENAME'] . 'txt';
        }
        
        $re = '<div class="codebox_plus_wrap"><div class="codebox_plus_header">';
        $re .= '<strong>' . $this->user->lang['CODEBOX_PLUS_CODE'] . ': </strong>';
        $re .= '<a href="#" onclick="codebox_plus_select(this, 1); return false;">[' . $this->user->lang['SELECT_ALL_CODE'] . ']</a>';
        $re .= '&nbsp;<a href="#" onclick="codebox_plus_toggle(this, 1); return false;">[' . $this->user->lang['CODEBOX_PLUS_EXPAND'] . '/' . $this->user->lang['CODEBOX_PLUS_COLLAPSE'] . ']</a>';
        
        if ($this->download_enabled && $lang != 'NULL')
        {
            $re .= '&nbsp;<a href="' . $this->helper->route('o0johntam0o_codeboxplus_download_controller', array('id' => $id, 'part' => $part)) . '" onclick="window.open(this.href); return false;">';
            $re .= '[' . $this->user->lang['CODEBOX_PLUS_DOWNLOAD'] . ']</a> ';
            //$re .= '[' . $this->user->lang['CODEBOX_PLUS_DOWNLOAD'] . ']</a> ' . '('. $file . ')';
        }
        
        $re .= '</div>';
        $re .= '<div><div style="display: none;">';
        
        if ($lang != 'NULL')
        {
            $re .= $this->codebox_parse_code($this->codebox_decode_code($code), $lang);
        }
        else
        {
            $re .= $this->user->lang['CODEBOX_PLUS_NO_PREVIEW'];
        }
        
        $re .= '</div></div>';
        $re .= '<div class="codebox_plus_footer"><a href="http://qbnz.com/highlighter/">GeSHi</a> &copy; <a href="https://www.phpbb.com/customise/db/mod/codebox_plus/">Codebox Plus</a></div></div>';
        
        return $re;
    }
    
    /*
    * Syntax highlighter
    */
    private function codebox_parse_code($code = '', $lang = 'text')
    {
        if (strlen($code) == 0)
        {
            return '';
        }
        // Remove newline at the beginning
        if (!empty($code) && $code[0] == "\n")
        {
            $code = substr($code, 1);
        }
        
        // GeSHi
        if (!class_exists("GeSHi"))
        {
            include($this->root_path . 'ext/o0johntam0o/codeboxplus/includes/geshi/geshi.' . $this->php_ext);
        }
        
        $geshi = new \GeSHi($code, $lang);
        $geshi->set_header_type(GESHI_HEADER_DIV);
        $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
        $geshi->enable_keyword_links(false);
        $geshi->set_line_style('margin-left:20px;', false);
        $geshi->set_code_style('border-bottom: dotted 1px #cccccc;', false);
        $geshi->set_line_ending("\n");
        $code = str_replace("\n", "", $geshi->parse_code());
        return $code;
    }
    
    /*
    * Decode some special characters
    */
    private function codebox_decode_code($code = '', $bbcode_uid = '')
    {
        if (strlen($code) == 0)
        {
            return $code;
        }
        
        $str_from = array('<', '>', '&#91;', '&#93;', '&#40;', '&#41;', '&#46;', '&#58;', '&#058;', ''', ''', '"', '&');
        $str_to = array('<', '>', '[', ']', '(', ')', '.', ':', ':', "'", "'", '"', '&');
        $code = str_replace($str_from, $str_to, $code);
        
        if (strlen($bbcode_uid) == 0)
        {
            return $code;
        }
        else
        {
            return '[code:' . $bbcode_uid . ']' . $code . '[/code:' . $bbcode_uid . ']';
        }
    }
    
    /*
    * Remove BBCodes UID & Smilies & Emails
    */

    private function codebox_clean_code($code = '', $bbcode_uid = '')
    {
        if (strlen($code) == 0)
        {
            return $code;
        }
        
        // Email
        $code = preg_replace('#<!-- e --><a href=\\\\"mailto:(?:.*?)\\\\">(.*?)</a><!-- e -->#msi', '$1', $code);
        // Smilies
        $code = preg_replace('#<!-- s(.*?) --><img src=\\\\"{SMILIES_PATH}/(?:.*?)\\\\" /><!-- s(?:.*?) -->#msi', '$1', $code);
        // BBCodes
        $code = str_replace(':o:' . $bbcode_uid, '', $code);
        $code = str_replace(':u:' . $bbcode_uid, '', $code);
        $code = str_replace(':m:' . $bbcode_uid, '', $code);
        $code = str_replace(':' . $bbcode_uid, '', $code);
        // Trouble with BBCode [CODE]
        $code = str_replace('<br />', "\n", $code);
        $code = str_replace('\\"', '"', $code);
        $code = str_replace('&nbsp;', ' ', $code);
        $code = preg_replace('#<(.*?)>#msi', '', $code);
        
        return $code;
    }
    
    /**
     *    Get the current list of supported GeSHi syntaxes
     */
    function get_geshi_syntaxes()
    {
        if(!count($this->geshi_syntax))
        {
            if ($handle = @opendir($this->root_path . 'ext/o0johntam0o/codeboxplus/includes/geshi/geshi/'))
            {
                
                $file_list = array();
                $exclude = array('.', '..');
                while (false !== ($file = @readdir($handle)))
                { 
                    $fileinfo = pathinfo($file);
                    if( !in_array($file, $exclude) && strtolower($fileinfo['extension']) == $this->php_ext)
                    { 
                        $file_list[] = substr($file, 0, strpos($file, '.'));
                    }
                }
                @closedir($handle);
                sort($file_list);
                return $file_list;
            }
        }
    }
}
2. ext\o0johntam0o\codeboxplus\styles\prosilver\template\event\posting_editor_buttons_after.html
<!-- IF CODEBOX_PLUS_AVAILABLE && CODEBOX_PLUS_IN_POSTING -->
<div id="format-buttons">
    <select name="addbbcode_codeboxplus" onchange="bbfontstyle('[' + this.form.addbbcode_codeboxplus.options[this.form.addbbcode_codeboxplus.selectedIndex].value + ']', '[/' + this.form.addbbcode_codeboxplus.options[this.form.addbbcode_codeboxplus.selectedIndex].value + ']');this.form.addbbcode_codeboxplus.selectedIndex = 0;" title="{L_CODEBOX_PLUS_SELECT}">        
        <option value="0" selected="selected" style="display: none">{L_CODEBOX_PLUS_SELECT}</option>
        <option value="vb"> Visual Basic </option>
        <option value="vbnet"> Visual Basic.NET </option>
        <option value="csharp"> C# </option>
        <option value="asp"> ASP </option>
        <option value="javascript"> Java Script </option>
        <option value="sql"> SQL </option>
        <option value="pascal"> Pascal </option>
        <option value="xml"> XML </option>
        <option value="css"> CSS </option>
        <option value="c"> C </option>
        <option value="cpp"> C++ </option>
        <option value="java"> Java </option>
        <option value="text"> Text </option>        
    </select>
</div>
<!-- ENDIF --> 
And in folder ext\o0johntam0o\codeboxplus\includes\geshi\geshi, just keep files in list options above.
So if you want to temporary deal with your forum then overwrite with 2 ones.
Regard

Image
Image

Hand of Shadow
Registered User
Posts: 12
Joined: Wed Dec 24, 2014 3:33 pm

Re: [BETA] Codebox Plus

Post by Hand of Shadow » Wed Dec 24, 2014 3:44 pm

Hallo i have a problem

Codebox Plus 1.0.0
PHPBB Core 3.1.2

Ext Run`s but .. ACP> Customize >Codebox Plus Details > white site with his error string


Fatal error: Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]]) in /www/htdocs/...... phpbb/file_downloader.php on line 72

User avatar
o0johntam0o
Registered User
Posts: 228
Joined: Thu Sep 23, 2010 3:53 pm
Location: Viet Nam
Name: Tam
Contact:

Re: [BETA] Codebox Plus

Post by o0johntam0o » Sun Dec 28, 2014 7:44 am

Currently i have no time to maintain this extension, i'll be back a month later. ;)
Note: This extension is still in development

Hand of Shadow
Registered User
Posts: 12
Joined: Wed Dec 24, 2014 3:33 pm

Re: [BETA] Codebox Plus

Post by Hand of Shadow » Sat Jan 17, 2015 11:56 am

Any updates ?

User avatar
Sshadow
Registered User
Posts: 299
Joined: Thu Aug 20, 2009 3:54 pm
Name: Chris C.
Contact:

Re: [BETA] Codebox Plus

Post by Sshadow » Sun Jan 18, 2015 4:32 am

Hand of Shadow wrote:Any updates ?
It's not been a month yet ;)

Hand of Shadow
Registered User
Posts: 12
Joined: Wed Dec 24, 2014 3:33 pm

Re: [BETA] Codebox Plus

Post by Hand of Shadow » Sun Jan 18, 2015 1:41 pm

Sshadow wrote:
Hand of Shadow wrote:Any updates ?
It's not been a month yet ;)

:lol: :lol: :lol: :lol:

Josephur
Registered User
Posts: 2
Joined: Tue Jan 20, 2015 8:05 am

Re: [BETA] Codebox Plus

Post by Josephur » Tue Jan 20, 2015 8:08 am

Does anyone know where to set the color for variables? My variables in this CSharp code are basically invisible due to the font color used on the white background.. very annoying.

https://www.stack-tech.com/forum/viewtopic.php?f=6&t=5

Locked

Return to “Abandoned Extensions”