Hướng dẫn nâng cấp module tương thích bản 4.1.00 lên 4.1.01 - nukeviet/update GitHub Wiki

Hỗ trợ reCAPTCHA

Thêm tùy chọn xuất ra recaptcha:

Tại các chỗ xuất ra captcha trước đó thêm lệnh kiểm tra biến $global_config['captcha_type'] nếu bằng 2 thì xuất thêm ra reCAPTCHA. Ví dụ

Trước khi có reCAPTCHA

if ($global_config['gfx_chk'] > 0) {
    $xtpl->assign('GFX_NUM', NV_GFX_NUM);
    $xtpl->assign('CAPTCHA_REFRESH', $lang_global['captcharefresh']);
    $xtpl->assign('CAPTCHA_REFR_SRC', NV_BASE_SITEURL . NV_ASSETS_DIR . '/images/refresh.png');
    $xtpl->assign('N_CAPTCHA', $lang_global['securitycode']);
    $xtpl->assign('GFX_WIDTH', NV_GFX_WIDTH);
    $xtpl->assign('GFX_HEIGHT', NV_GFX_HEIGHT);
    $xtpl->parse('main.content.captcha');
}

Khi có reCAPTCHA

if ($global_config['gfx_chk'] > 0) {
    if ($global_config['captcha_type'] == 2) {
        $xtpl->assign('RECAPTCHA_ELEMENT', 'recaptcha' . nv_genpass(8));
        $xtpl->assign('N_CAPTCHA', $lang_global['securitycode1']);
        $xtpl->parse('main.content.recaptcha');
    } else {
        $xtpl->assign('GFX_NUM', NV_GFX_NUM);
        $xtpl->assign('CAPTCHA_REFRESH', $lang_global['captcharefresh']);
        $xtpl->assign('CAPTCHA_REFR_SRC', NV_BASE_SITEURL . NV_ASSETS_DIR . '/images/refresh.png');
        $xtpl->assign('N_CAPTCHA', $lang_global['securitycode']);
        $xtpl->assign('GFX_WIDTH', NV_GFX_WIDTH);
        $xtpl->assign('GFX_HEIGHT', NV_GFX_HEIGHT);
        $xtpl->parse('main.content.captcha');
    }
}

Trong file TPL của module thêm reCAPTCHA

<!-- BEGIN: recaptcha -->
<div class="form-group">
    <label class="col-sm-4 control-label">{N_CAPTCHA} <span class="txtrequired">(*)</span></label>
    <div class="col-sm-20">
        <div class="nv-recaptcha-default"><div id="{RECAPTCHA_ELEMENT}"></div></div>
        <script type="text/javascript">
        nv_recaptcha_elements.push({
            id: "{RECAPTCHA_ELEMENT}",
            btn: $('[type="submit"]', $('#{RECAPTCHA_ELEMENT}').parent().parent().parent().parent())
        })
        </script>
    </div>
</div>
<!-- END: recaptcha -->

Xem thêm về cách xuất captcha http://wiki.nukeviet.vn/programming4:thematic:captchathemedefault

Get mã trả về

Đối với reCAPTCHA, mã trả về sẽ nằm ở khóa g-recaptcha-response do đó cần thay đổi ví dụ như sau

if ($global_config['captcha_type'] == 2) {
    $fcode = $nv_Request->get_title('g-recaptcha-response', 'post', '');
} else {
    $fcode = $nv_Request->get_title('fcode', 'post', '');
}

Cho phép mỗi module ảo dùng 1 giao diện module riêng (Cùng theme)

Tìm trong code của module:

themes/' . $module_info['template'] . '/modules/' . $module_file

Thay thế bằng:

themes/' . $module_info['template'] . '/modules/' . $module_info['module_theme']

Tìm trong code của module:

themes/' . $module_info['template'] . '/images/' . $module_file

Thay thế bằng:

themes/' . $module_info['template'] . '/images/' . $module_info['module_theme']

Tùy chỉnh giá trị site_title của module và các function của module

Các module có thể không cần cập nhật, tuy nhiên nếu muốn tùy biến hãy lưu ý:

Thay giá trị

$page_title = $module_info['custom_title'];

Thành

$page_title = $module_info['site_title'];

$page_title = $module_info['funcs'][$op]['func_custom_title'];

Thành

$page_title = $module_info['funcs'][$op]['func_site_title'];

Tại những vị trí thích hợp.

Thay đổi các hằng

Cần kiểm tra thay thế

DIR_FORUM => $global_config['dir_forum']
NV_UNICKMAX => $global_config['nv_unickmax']
NV_UNICKMIN => $global_config['nv_unickmin']
NV_UPASSMAX => $global_config['nv_upassmax']
NV_UPASSMIN => $global_config['nv_upassmin']

Chú ý: Nếu các hằng trên dùng trong hàm cần kiểm tra gọi global biến $global_config.

Tối ưu rewrite cho các module:

Chức năng rewrite các module từ trước giờ có thể không cần sửa gì vẫn hoạt động tốt, tuy nhiên để tối ưu nhất các nhà phát triển module cần chú ý tại các form có menthod = GET cần chú ý thay đổi giá trị action.

Ví dụ luật rewrite cũ ta dùng form với cấu trúc như sau:

<form action="{DATA.action}" name="form_search" method="get" id="form_search" role="form">
    <input type="hidden" name="{NV_LANG_VARIABLE}" value="{NV_LANG_DATA}"/>
    <input type="hidden" name="{NV_NAME_VARIABLE}" value="{MODULE_NAME}"/>
</form>

Khi đó khi submit form thì URL có dạng

index.php?language=vi&nv=seek&q=.....

Trong file xử lý ta thường dùng hàm nv_url_rewrite để rewrite URL trên lại sau đó kiểm tra với giá trị $_SERVER['REQUEST_URI'] nếu sai khác sẽ tiến hành redirect về giá trị đã rewrite. Để tối ưu hơn ta cần thay đổi lại form tìm kiếm như sau:

<form action="{DATA.action}" name="form_search" method="get" id="form_search" role="form">
    <!-- BEGIN: no_rewrite -->
	<input type="hidden" name="{NV_LANG_VARIABLE}" value="{NV_LANG_DATA}"/>
	<input type="hidden" name="{NV_NAME_VARIABLE}" value="{MODULE_NAME}"/>
    <!-- END: no_rewrite -->
</form>

Theo đó giá trị {DATA.action} không phải là {NV_BASE_SITEURL}index.php mà cần thay đổi lại theo

if (!$global_config['rewrite_enable']) {
    $data['action'] = NV_BASE_SITEURL . 'index.php';
} else {
    $data['action'] = nv_url_rewrite(NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&amp;' . NV_NAME_VARIABLE . '=seek', true);
}

Và đoạn

    <!-- BEGIN: no_rewrite -->
	<input type="hidden" name="{NV_LANG_VARIABLE}" value="{NV_LANG_DATA}"/>
	<input type="hidden" name="{NV_NAME_VARIABLE}" value="{MODULE_NAME}"/>
    <!-- END: no_rewrite -->

Chỉ xuất ra nếu tắt rewrite

if (!$global_config['rewrite_enable']) {
    $xtpl->parse('main.no_rewrite');
}

Kiểm tra lại những chỗ có dùng biến $rewrite_keys cần thay lại thành biến $global_config['rewrite_enable']

Lưu ý đến ngữ nghĩa khi thay

⚠️ **GitHub.com Fallback** ⚠️