[MOD] Codebox Plus - เป็น MOD สำหรับใช้ในการ ไฮไลด์โค้ด

แนะนำ Mod ต่างๆ ของ PHPBB3 แนะนำความสามารถ ของ mod การติดตั้ง การเข้ากันได้กับเวอร์ชั่น

Moderator: mindphp

ภาพประจำตัวสมาชิก
thatsawan
PHP VIP Members
PHP VIP Members
โพสต์: 28508
ลงทะเบียนเมื่อ: 31/03/2014 10:02 am
ติดต่อ:

[MOD] Codebox Plus - เป็น MOD สำหรับใช้ในการ ไฮไลด์โค้ด

โพสต์ที่ยังไม่ได้อ่าน โดย thatsawan »

[MOD] Codebox Plus
23-4-2557 15-23-55.png
23-4-2557 15-23-55.png (29.71 KiB) Viewed 1248 times
รายละเอียดเกี่ยวกับ :: Codebox Plus เป็น MOD สำหรับใช้ในการ ไฮไลด์โค้ด โดย MPD นี้จะช่วยมีความสามารถที่ไฮไลด์โค้ดได้หลายภาษา,เน้นไวยากรณ์ 200 +,เเละยังเเสดงเลขบรรทัด ให้ผู้ใช้งานได้ใช้งานสะดวกขึ้น ,สามารถขยาย / ยุบการแสดงผลได้,ดาวน์โหลดเนื้อหารหัส (ที่มีการยืนยัน), 100% xHTML ที่ถูกต้อง
พัฒนาโดย ::o0johntam0o
Version ::1.1.3
ดาวน์โหลด :: https://www.mindphp.com/download/files/37-35-codebox-plus-zip.html
ไฟล์ที่ใช้ในการติดตั้ง
includes/bbcode.php,
includes/message_parser.php,
language/en/common.php,
styles/prosilver/template/forum_fn.js,
styles/prosilver/template/posting_buttons.html
วิธีการติดตั้ง
เปิดไฟล์ =>includes/bbcode.php
ค้นหา ::

โค้ด: เลือกทั้งหมด

'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise'    => "\$this->bbcode_second_pass_code('\$1', '\$2')", 
เเทนที่ ::

โค้ด: เลือกทั้งหมด

/* CODEBOX PLUS - BEGIN */
//'#\[code(?:=([a-z]+))?:$uid\](.*?)\[/code:$uid\]#ise'    => "\$this->bbcode_second_pass_code('\$1', '\$2')",
  '#\[code(?:=([a-z0-9_-]+))?(?: file=(.*?))?:$uid\](.*?)\[/code:$uid\]#ise'=> \$this-bbcode_second_pass_codebox('\$1', '\$3', '\$2')",
/* CODEBOX PLUS - END */
ค้นหา :: เติมก่อน::

โค้ด: เลือกทั้งหมด

/* CODEBOX PLUS - BEGIN */
    function bbcode_second_pass_codebox($type, $code, $file)
    {
        global $phpbb_root_path, $config, $user;
        
        if (isset($config['codebox_plus_enable']) && $config['codebox_plus_enable'] == 1)
        {
            $cp_current_style = $user->theme['template_path'];
            
            if (!@file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/bbcode.html'))
            {
                $cp_current_style = $user->theme['template_inherit_path'];
            }
            
            switch ($cp_current_style)
            {
                case 'subsilver2':
                    $tpl_codebox_plus_close = '</div><div class="codetitle" style="text-align:right; margin:-10px 5px 10px 5px;"><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>';
                    
                    if (isset($config['codebox_plus_download']) && $config['codebox_plus_download'] == 1)
                    {
                        $tpl_codebox_plus_open = '<div><div class="codetitle"><b>{L_CODE}:</b> <a href="#" onclick="ShowHideCodebox(this); return false;">[{L_CODEBOX_PLUS_EXPAND}/{L_CODEBOX_PLUS_COLLAPSE}]</a> <a class="CodeboxPlus_Censor_123_abc_xyz_890" href="#">[{L_CODEBOX_PLUS_DOWNLOAD}]</a> ({FILE_NAME})</div><div class="codecontent">';
                    }
                    else
                    {
                        $tpl_codebox_plus_open = '<div><div class="codetitle"><b>{L_CODE}:</b> <a href="#" onclick="ShowHideCodebox(this); return false;">[{L_CODEBOX_PLUS_EXPAND}/{L_CODEBOX_PLUS_COLLAPSE}]</a></div><div class="codecontent">';
                    }
                    
                break;
                
                case 'absolution':
                    $tpl_codebox_plus_close = '</div><div style="text-align:right;"><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>';
                    
                    if (isset($config['codebox_plus_download']) && $config['codebox_plus_download'] == 1)
                    {
                        $tpl_codebox_plus_open = '<div class="vtcodebox"><div class="vtcodeselect">{L_CODE}: <a href="#" onclick="selectCodebox(this); return false;">[{L_SELECT_ALL_CODE}]</a> <a href="#" onclick="ShowHideCodebox(this); return false;">[{L_CODEBOX_PLUS_EXPAND}/{L_CODEBOX_PLUS_COLLAPSE}]</a> <a class="CodeboxPlus_Censor_123_abc_xyz_890" href="#">[{L_CODEBOX_PLUS_DOWNLOAD}]</a> ({FILE_NAME})</div><div class="vtcodeinner">';
                    }
                    else
                    {
                        $tpl_codebox_plus_open = '<div class="vtcodebox"><div class="vtcodeselect">{L_CODE}: <a href="#" onclick="selectCodebox(this); return false;">[{L_SELECT_ALL_CODE}]</a> <a href="#" onclick="ShowHideCodebox(this); return false;">[{L_CODEBOX_PLUS_EXPAND}/{L_CODEBOX_PLUS_COLLAPSE}]</a></div><div class="vtcodeinner">';
                    }
                    
                break;
                
                /*
                case 'your_template_path':
                    $tpl_codebox_plus_close = '';
                    
                    if (isset($config['codebox_plus_download']) && $config['codebox_plus_download'] == 1)
                    {
                        $tpl_codebox_plus_open = '';
                    }
                    else
                    {
                        $tpl_codebox_plus_open = '';
                    }
                    
                break;
                */
                
                default:
                    // ProSilver by default...
                    $tpl_codebox_plus_close = '</dd><dd style="text-align:right; border-top:solid 1px #cccccc;"><a href="http://qbnz.com/highlighter/">GeSHi</a> &copy; <a href="https://www.phpbb.com/customise/db/mod/codebox_plus/">Codebox Plus</a></dd></dl>';
                    
                    if (isset($config['codebox_plus_download']) && $config['codebox_plus_download'] == 1)
                    {
                        $tpl_codebox_plus_open = '<dl class="codebox"><dt>{L_CODE}: <a href="#" onclick="selectCodebox(this); return false;">[{L_SELECT_ALL_CODE}]</a> <a href="#" onclick="ShowHideCodebox(this); return false;">[{L_CODEBOX_PLUS_EXPAND}/{L_CODEBOX_PLUS_COLLAPSE}]</a> <a class="CodeboxPlus_Censor_123_abc_xyz_890" href="#">[{L_CODEBOX_PLUS_DOWNLOAD}]</a> ({FILE_NAME})</dt><dd>';
                    }
                    else
                    {
                        $tpl_codebox_plus_open = '<dl class="codebox"><dt>{L_CODE}: <a href="#" onclick="selectCodebox(this); return false;">[{L_SELECT_ALL_CODE}]</a> <a href="#" onclick="ShowHideCodebox(this); return false;">[{L_CODEBOX_PLUS_EXPAND}/{L_CODEBOX_PLUS_COLLAPSE}]</a></dt><dd>';
                    }
                    
                break;
            }
        }
        else
        {
            return $this->bbcode_second_pass_code($type, $code);
        }
        
        $file = (strlen($file) == 0) ? $user->lang['CODEBOX_PLUS_DEFAULT_FILENAME'] : $file;
        
        // when using the /e modifier, preg_replace slashes double-quotes but does not
        // seem to slash anything else
        $code = str_replace('\"', '"', $code);
        
        if (!class_exists("GeSHi"))
        {
            include($phpbb_root_path . 'includes/geshi/geshi.php');
        }
        
        if (strlen($type) != 0)
        {
            // Remove newline at the beginning
            if (!empty($code) && $code[0] == "\n")
            {
                $code = substr($code, 1);
            }
            
            // Some characters was encoded before. We have to decode it
            $str_from = array('<', '>', '&#91;', '&#93;', '&#46;', '&#58;', '&#058;', ''', ''', '"', '&');
            $str_to = array('<', '>', '[', ']', '.', ':', ':', "'", "'", '"', '&');
            $code = str_replace($str_from, $str_to, $code);
            // GeSHi
            $geshi = new GeSHi($code, $type);
            $geshi->set_header_type(GESHI_HEADER_DIV);
            $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
            $geshi->set_line_style('margin-left:20px;', false);
            
            if ($cp_current_style == 'subsilver2')
            {
                $geshi->set_code_style('border-bottom: dotted 1px #cccccc; font-size:200%;', false);
            }
            else
            {
                $geshi->set_code_style('border-bottom: dotted 1px #cccccc; font-size:100%;', false);
            }
            
            $code = str_replace("\n", "", $geshi->parse_code());
        }
        else
        {
            $code = str_replace("\t", '&nbsp; &nbsp;', $code);
            $code = str_replace('  ', '&nbsp; ', $code);
            $code = str_replace('  ', ' &nbsp;', $code);
            $code = str_replace("\n ", "\n&nbsp;", $code);

            // Keep space at the beginning
            if (!empty($code) && $code[0] == ' ')
            {
                $code = '&nbsp;' . substr($code, 1);
            }

            // Remove newline at the beginning
            if (!empty($code) && $code[0] == "\n")
            {
                $code = substr($code, 1);
            }
        }
        
        $str_from = array(
            '{L_CODE}',
            '{L_SELECT_ALL_CODE}',
            '{L_CODEBOX_PLUS_EXPAND}',
            '{L_CODEBOX_PLUS_COLLAPSE}',
            '{L_CODEBOX_PLUS_DOWNLOAD}',
            '{FORUM_URL}',
            '{FILE_NAME}',
        );
        $str_to = array(
            $user->lang['CODEBOX_PLUS_CODE'],
            $user->lang['SELECT_ALL_CODE'],
            $user->lang['CODEBOX_PLUS_EXPAND'],
            $user->lang['CODEBOX_PLUS_COLLAPSE'],
            $user->lang['CODEBOX_PLUS_DOWNLOAD'],
            generate_board_url(),
            $file,
        );
        
        $code = str_replace($str_from, $str_to, $tpl_codebox_plus_open) . $code . $tpl_codebox_plus_close;

        return $code;
    }
    /* CODEBOX PLUS - END */ 
เปิดไฟล์ =>includes/message_parser.php
แทนที่ ::

โค้ด: เลือกทั้งหมด

            'code'            => array('bbcode_id' => 8,    'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#uise' => "\$this->bbcode_code('\$1', '\$2')")), 
ค้นหา ::

โค้ด: เลือกทั้งหมด

/* CODEBOX PLUS - BEGIN */
            //'code'            => array('bbcode_id' => 8,    'regexp' => array('#\[code(?:=([a-z]+))?\](.+\[/code\])#uise' => "\$this->bbcode_code('\$1', '\$2')")),
            'code'            => array('bbcode_id' => 8,    'regexp' => array('#\[code(?:=([a-z0-9_-]+))?(?: file=(.*?))?\](.+\[/code\])#uise' => "\$this->bbcode_codebox('\$1', '\$3', '\$2')")),
            /* CODEBOX PLUS - END */ 
ค้นหา ::

โค้ด: เลือกทั้งหมด

/**
    * Parse code text from code tag
    * @access private
    */ 
เติมก่อน::

โค้ด: เลือกทั้งหมด

/* CODEBOX PLUS - BEGIN */
    function bbcode_parse_codebox($stx, &$code, $file)
    {
        global $config;
        
        if (isset($config['codebox_plus_enable']) && $config['codebox_plus_enable'] == 0)
        {
            return $this->bbcode_parse_code($stx, $code);
        }
        
        // $this->bbcode_specialchars() ----ENCODE---- < > [ ] . :
        // In order to NOT parse any other bbcodes and links
        $code = $this->bbcode_specialchars($code);

        if (strlen($stx) > 0)
        {
            if (strlen($file) > 0)
            {
                return '[code=' . $stx . ' file=' . $file . ':' . $this->bbcode_uid . ']' . $code . '[/code:' . $this->bbcode_uid . ']';
            }
            else
            {
                return '[code=' . $stx . ':' . $this->bbcode_uid . ']' . $code . '[/code:' . $this->bbcode_uid . ']';
            }
        }
        else
        {
            if (strlen($file) > 0)
            {
                return '[code file=' . $file . ':' . $this->bbcode_uid . ']' . $code . '[/code:' . $this->bbcode_uid . ']';
            }
            else
            {
                return '[code:' . $this->bbcode_uid . ']' . $code . '[/code:' . $this->bbcode_uid . ']';
            }
        }
    }

    function bbcode_codebox($stx, $in, $file)
    {
        global $config;
        
        if (isset($config['codebox_plus_enable']) && $config['codebox_plus_enable'] == 0)
        {
            return $this->bbcode_code('', $in);
        }
        
        if (!$this->check_bbcode('code', $in))
        {
            return $in;
        }

        // We remove the hardcoded elements from the code block here because it is not used in code blocks
        // Having it here saves us one preg_replace per message containing [code] blocks
        // Additionally, magic url parsing should go after parsing bbcodes, but for safety those are stripped out too...
        $htm_match = get_preg_expression('bbcode_htm');
        unset($htm_match[4], $htm_match[5]);
        $htm_replace = array('\1', '\1', '\2', '\1');

        $out = $code_block = '';
        $open = 1;

        while ($in)
        {
            // Determine position and tag length of next code block
            preg_match('#(.*?)(\[code(?:=([a-z0-9_-]+))?(?: file=(.*?))?\])(.+)#is', $in, $buffer);
            $pos = (isset($buffer[1])) ? strlen($buffer[1]) : false;
            $tag_length = (isset($buffer[2])) ? strlen($buffer[2]) : false;

            // Determine position of ending code tag
            $pos2 = stripos($in, '
');

            // Which is the next block, ending code or code block
            if ($pos !== false && $pos < $pos2)
            {
                // Open new block
                if (!$open)
                {
                    $out .= substr($in, 0, $pos);
                    $in = substr($in, $pos);
                    $stx = (isset($buffer[3])) ? $buffer[3] : '';
                    $file = (isset($buffer[4])) ? $buffer[4] : '';
                    $code_block = '';
                }
                else
                {
                    // Already opened block, just append to the current block
                    $code_block .= substr($in, 0, $pos) . ((isset($buffer[2])) ? $buffer[2] : '');
                    $in = substr($in, $pos);
                }

                $in = substr($in, $tag_length);
                $open++;
            }
            else
            {
                // Close the block
                if ($open == 1)
                {
                    $code_block .= substr($in, 0, $pos2);
                    $code_block = preg_replace($htm_match, $htm_replace, $code_block);

                    // Parse this code block
                    $out .= $this->bbcode_parse_codebox($stx, $code_block, $file);
                    $code_block = '';
                    $open--;
                }
                else if ($open)
                {
                    // Close one open tag... add to the current code block
                    $code_block .= substr($in, 0, $pos2 + 7);
                    $open--;
                }
                else
                {
                    // end code without opening code... will be always outside code block
                    $out .= substr($in, 0, $pos2 + 7);
                }

                $in = substr($in, $pos2 + 7);
            }
        }

        // if now $code_block has contents we need to parse the remaining code while removing the last closing tag to match up.
        if ($code_block)
        {
            $code_block = substr($code_block, 0, -7);
            $code_block = preg_replace($htm_match, $htm_replace, $code_block);

            $out .= $this->bbcode_parse_codebox($stx, $code_block, $file);
        }

        return $out;
    }
    /* CODEBOX PLUS - END */ [/code]
เปิดไฟล์=>language/en/common.php
ค้นหา :: เติมก่อน::

โค้ด: เลือกทั้งหมด

/* CODEBOX PLUS - BEGIN */
$lang = array_merge($lang, array(
    'CODEBOX_PLUS_CODE'                        => 'Code',
    'CODEBOX_PLUS_DOWNLOAD'                    => 'Download',
    'CODEBOX_PLUS_EXPAND'                    => 'Expand',
    'CODEBOX_PLUS_COLLAPSE'                    => 'Collapse',
    'CODEBOX_PLUS_SELECT'                    => 'Select code',
    'CODEBOX_PLUS_DEFAULT_FILENAME'            => 'Untitled',
));
/* CODEBOX PLUS - END */ 
เปิดไฟล์=>styles/prosilver/template/forum_fn.js
ค้นหา ::

โค้ด: เลือกทั้งหมด

/**
* phpBB3 forum functions
*/ 
เติมท้าย::

โค้ด: เลือกทั้งหมด

/* CODEBOX PLUS - BEGIN */
function ShowHideCodebox(a)
{
    // Get ID of code block
    var e = a.parentNode.parentNode.getElementsByTagName('DD')[0];
    if (e.style.display == 'none')
    {
        e.style.display = 'inline';
    }
    else
    {
        e.style.display = 'none';
    }
}
function selectCodebox(a)
{
    // Get ID of code block
    var e = a.parentNode.parentNode.getElementsByTagName('DD')[0];

    // Not IE and IE9+
    if (window.getSelection)
    {
        var s = window.getSelection();
        // Safari
        if (s.setBaseAndExtent)
        {
            s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
        }
        // Firefox and Opera
        else
        {
            // workaround for bug # 42885
            if (window.opera && e.innerHTML.substring(e.innerHTML.length - 4) == '<BR>')
            {
                e.innerHTML = e.innerHTML + '&nbsp;';
            }

            var r = document.createRange();
            r.selectNodeContents(e);
            s.removeAllRanges();
            s.addRange(r);
        }
    }
    // Some older browsers
    else if (document.getSelection)
    {
        var s = document.getSelection();
        var r = document.createRange();
        r.selectNodeContents(e);
        s.removeAllRanges();
        s.addRange(r);
    }
    // IE
    else if (document.selection)
    {
        var r = document.body.createTextRange();
        r.moveToElementText(e);
        r.select();
    }
}
/* CODEBOX PLUS - END */ 
เปิดไฟล์=>styles/prosilver/template/posting_buttons.html
ค้นหา ::

โค้ด: เลือกทั้งหมด

    <input type="button" class="button2" accesskey="c" name="addbbcode8" value="Code" style="width: 40px" onclick="bbstyle(8)" title="{L_BBCODE_C_HELP}" /> 
เติมท้าย ::

โค้ด: เลือกทั้งหมด

<!-- INCLUDE mods/codebox_plus_buttons.html --> 
***จากนั้นให้ทำการ คัดลอกไฟล์ทั้งหมดที่มี ในโฟลเดอร์ root ไปวาง เเล้วทำการ เปิด Browser :: /install_codebox_plus.php***
การแสดงผลการติดตั้ง
23-4-2557 14-46-03.png
23-4-2557 14-46-03.png (85.16 KiB) Viewed 1248 times
การตั้งค่าในส่วนของ admin
23-4-2557 14-54-48.png
23-4-2557 14-54-48.png (83.79 KiB) Viewed 1248 times
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 62