Phiên bản trước của cả hai bênPhiên bản trước | |
programming4:block [2016/06/17 07:35] – hoaquynhtim99 | programming4:block [2016/06/17 07:39] (hiện tại) – hoaquynhtim99 |
---|
<block> | <block> |
<info> | <info> |
<name>Block RSS</name> | <name>Block Groups</name> |
<author>VinaDes.,Jsc</author> | <author>VinaDes.,Jsc</author> |
<website>http://vinades.vn</website> | <website>http://vinades.vn</website> |
</info> | </info> |
<config> | <config> |
<blockid>1</blockid> | <blockid>0</blockid> |
<numrow>5</numrow> | <numrow>5</numrow> |
<type>1</type> | <showtooltip>1</showtooltip> |
| <tooltip_position>bottom</tooltip_position> |
| <tooltip_length>150</tooltip_length> |
</config> | </config> |
<datafunction>nv_block_config_news_blocks</datafunction> | <datafunction>nv_block_config_news_groups</datafunction> |
<submitfunction>nv_block_config_news_blocks_submit</submitfunction> | <submitfunction>nv_block_config_news_groups_submit</submitfunction> |
</block> | </block> |
</code> | </code> |
Phần này là các biến để thiết lập block. | Phần này là các biến để thiết lập block. |
| |
<datafunction>nv_block_config_news_blocks</datafunction> Đây là tên function sẽ được gọi để hiển thị phần cấu hình của block khi thực hiện thao tác thêm hoặc sửa block. | <datafunction>nv_block_config_news_groups</datafunction> Đây là tên function sẽ được gọi để hiển thị phần cấu hình của block khi thực hiện thao tác thêm hoặc sửa block. |
| |
<submitfunction>nv_block_config_news_blocks_submit</submitfunction> Là tên function xử lý dữ liệu cấu hình block khi lưu block. | <submitfunction>nv_block_config_news_groups_submit</submitfunction> Là tên function xử lý dữ liệu cấu hình block khi lưu block. |
| |
Nếu block có ngôn ngữ riêng cần tạo thêm file ngôn ngữ có dạng: | Nếu block có ngôn ngữ riêng cần tạo thêm file ngôn ngữ có dạng: |
| |
/** | /** |
* @Project NUKEVIET 3.0 | * @Project NUKEVIET 4.x |
* @Author VINADES.,JSC (contact@vinades.vn) | * @Author VINADES.,JSC (contact@vinades.vn) |
* @Copyright (C) 2010 VINADES.,JSC. All rights reserved | * @Copyright (C) 2014 VINADES.,JSC. All rights reserved |
* @Language Tiếng Việt | * @Language Tiếng Việt |
* @Createdate Jul 06, 2011, 04:38:01 PM | * @License CC BY-SA (http://creativecommons.org/licenses/by-sa/4.0/) |
*/ | * @Createdate Jun 22, 2010, 08:22:00 AM |
| */ |
| |
if (!defined( 'NV_MAINFILE' )) { | if (! defined('NV_ADMIN') or ! defined('NV_MAINFILE')) { |
die('Stop!!!'); | die('Stop!!!'); |
} | } |
| |
$lang_translator['author'] ="VINADES.,JSC (contact@vinades.vn)"; | $lang_translator['author'] = 'VINADES.,JSC (contact@vinades.vn)'; |
$lang_translator['createdate'] ="22/06/2010, 09:22"; | $lang_translator['createdate'] = '22/06/2010, 09:22'; |
$lang_translator['copyright'] ="@Copyright (C) 2010 VINADES.,JSC. All rights reserved"; | $lang_translator['copyright'] = '@Copyright (C) 2012 VINADES.,JSC. All rights reserved'; |
$lang_translator['info'] =""; | $lang_translator['info'] = ''; |
$lang_translator['langtype'] ="lang_block"; | $lang_translator['langtype'] = 'lang_block'; |
| |
$lang_block['blockid'] = "Nhóm tin liên quan"; | $lang_block['blockid'] = 'Nhóm tin liên quan'; |
$lang_block['numrow'] = "Số bài hiển thị"; | $lang_block['numrow'] = 'Số bài hiển thị'; |
$lang_block['type'] = "Cách thức hiển thị"; | $lang_block['type'] = 'Cách thức hiển thị'; |
| $lang_block['showtooltip'] = 'Hiển thị tooltip'; |
| $lang_block['tooltip_position'] = 'Vị trí'; |
| $lang_block['tooltip_position_top'] = 'Trên'; |
| $lang_block['tooltip_position_bottom'] = 'Dưới'; |
| $lang_block['tooltip_position_left'] = 'Trái'; |
| $lang_block['tooltip_position_right'] = 'Phải'; |
| $lang_block['tooltip_length'] = 'Số ký tự'; |
| |
?> | |
</code> | </code> |
Trong đó biến $lang_translator không nên chỉnh sửa, biến $lang_block gồm nội dung của ngôn ngữ block. | Trong đó biến $lang_translator không nên chỉnh sửa, biến $lang_block gồm nội dung của ngôn ngữ block. |
Ví dụ: | Ví dụ: |
<code php> | <code php> |
if ( ! nv_function_exists( 'nv_news_blocks' ) ) | if (!nv_function_exists('nv_news_blocks')) { |
{ | function nv_news_blocks($block_config) { |
function nv_news_blocks( $block_config ) | // Some code here |
{ | } |
| |
} | |
} | } |
</code> | </code> |
Ví dụ: | Ví dụ: |
<code php> | <code php> |
function nv_block_config_news_blocks ( $module, $data_block, $lang_block ) | function nv_block_config_news_groups($module, $data_block, $lang_block) |
{ | { |
global $db, $language_array, $site_mods; | global $nv_Cache, $site_mods; |
$html = ""; | |
$html .= "<tr>"; | |
$html .= " <td>" . $lang_block['blockid'] . "</td>"; | |
$html .= " <td><select name=\"config_blockid\">\n"; | |
$sql = "SELECT * FROM `" . NV_PREFIXLANG . "_" . $site_mods[$module]['module_data'] . "_block_cat` ORDER BY `weight` ASC"; | |
$list = nv_db_cache( $sql, 'catid', $module ); | |
foreach ( $list as $l ) | |
{ | |
$sel = ( $data_block['blockid'] == $l['bid'] ) ? ' selected' : ''; | |
$html .= "<option value=\"" . $l['bid'] . "\" " . $sel . ">" . $l['title'] . "</option>\n"; | |
} | |
$html .= " </select></td>\n"; | |
$html .= "</tr>"; | |
$html .= "<tr>"; | |
$html .= " <td>" . $lang_block['numrow'] . "</td>"; | |
$html .= " <td><input type=\"text\" name=\"config_numrow\" size=\"5\" value=\"" . $data_block['numrow'] . "\"/></td>"; | |
$html .= "</tr>"; | |
return $html; | |
} | |
| |
function nv_block_config_news_blocks_submit ( $module, $lang_block ) | $html_input = ''; |
{ | $html = ''; |
global $nv_Request; | $html .= '<tr>'; |
$return = array(); | $html .= '<td>' . $lang_block['blockid'] . '</td>'; |
$return['error'] = array(); | $html .= '<td><select name="config_blockid" class="form-control w200">'; |
$return['config'] = array(); | $html .= '<option value="0"> -- </option>'; |
$return['config']['blockid'] = $nv_Request->get_int( 'config_blockid', 'post', 0 ); | $sql = 'SELECT * FROM ' . NV_PREFIXLANG . '_' . $site_mods[$module]['module_data'] . '_block_cat ORDER BY weight ASC'; |
$return['config']['numrow'] = $nv_Request->get_int( 'config_numrow', 'post', 0 ); | $list = $nv_Cache->db($sql, '', $module); |
return $return; | foreach ($list as $l) { |
| $html_input .= '<input type="hidden" id="config_blockid_' . $l['bid'] . '" value="' . NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module . '&' . NV_OP_VARIABLE . '=' . $site_mods[$module]['alias']['groups'] . '/' . $l['alias'] . '" />'; |
| $html .= '<option value="' . $l['bid'] . '" ' . (($data_block['blockid'] == $l['bid']) ? ' selected="selected"' : '') . '>' . $l['title'] . '</option>'; |
} | } |
| $html .= '</select>'; |
| $html .= $html_input; |
| $html .= '<script type="text/javascript">'; |
| $html .= ' $("select[name=config_blockid]").change(function() {'; |
| $html .= ' $("input[name=title]").val($("select[name=config_blockid] option:selected").text());'; |
| $html .= ' $("input[name=link]").val($("#config_blockid_" + $("select[name=config_blockid]").val()).val());'; |
| $html .= ' });'; |
| $html .= '</script>'; |
| $html .= '</tr>'; |
| $html .= '<tr>'; |
| $html .= '<td>' . $lang_block['numrow'] . '</td>'; |
| $html .= '<td><input type="text" class="form-control w200" name="config_numrow" size="5" value="' . $data_block['numrow'] . '"/></td>'; |
| $html .= '</tr>'; |
| $html .= '<tr>'; |
| $html .= '<td>' . $lang_block['showtooltip'] . '</td>'; |
| $html .= '<td>'; |
| $html .= '<input type="checkbox" value="1" name="config_showtooltip" ' . ($data_block['showtooltip'] == 1 ? 'checked="checked"' : '') . ' /><br /><br />'; |
| $tooltip_position = array( 'top' => $lang_block['tooltip_position_top'], 'bottom' => $lang_block['tooltip_position_bottom'], 'left' => $lang_block['tooltip_position_left'], 'right' => $lang_block['tooltip_position_right'] ); |
| $html .= '<span class="text-middle pull-left">' . $lang_block['tooltip_position'] . ' </span><select name="config_tooltip_position" class="form-control w100 pull-left">'; |
| foreach ($tooltip_position as $key => $value) { |
| $html .= '<option value="' . $key . '" ' . ($data_block['tooltip_position'] == $key ? 'selected="selected"' : '') . '>' . $value . '</option>'; |
| } |
| $html .= '</select>'; |
| $html .= ' <span class="text-middle pull-left">' . $lang_block['tooltip_length'] . ' </span><input type="text" class="form-control w100 pull-left" name="config_tooltip_length" size="5" value="' . $data_block['tooltip_length'] . '"/>'; |
| $html .= '</td>'; |
| $html .= '</tr>'; |
| return $html; |
| } |
| |
| function nv_block_config_news_groups_submit($module, $lang_block) |
| { |
| global $nv_Request; |
| $return = array(); |
| $return['error'] = array(); |
| $return['config'] = array(); |
| $return['config']['blockid'] = $nv_Request->get_int('config_blockid', 'post', 0); |
| $return['config']['numrow'] = $nv_Request->get_int('config_numrow', 'post', 0); |
| $return['config']['showtooltip'] = $nv_Request->get_int('config_showtooltip', 'post', 0); |
| $return['config']['tooltip_position'] = $nv_Request->get_string('config_tooltip_position', 'post', 0); |
| $return['config']['tooltip_length'] = $nv_Request->get_string('config_tooltip_length', 'post', 0); |
| return $return; |
| } |
</code> | </code> |
Tiếp theo thêm function chính (nội dung block) | Tiếp theo thêm function chính (nội dung block) |
Ví dụ: | Ví dụ: |
<code php> | <code php> |
function nv_news_blocks ( $block_config ) | function nv_block_news_groups($block_config) |
{ | { |
global $module_array_cat, $module_info, $lang_module, $site_mods; | global $module_array_cat, $module_info, $site_mods, $module_config, $global_config, $nv_Cache, $db; |
$module = $block_config['module']; | $module = $block_config['module']; |
$sql = "SELECT t1.id, t1.listcatid, t1.title, t1.alias, t1.homeimgthumb, t1.homeimgalt FROM `" . NV_PREFIXLANG . "_" . $site_mods[$module]['module_data'] . "_rows` as t1 INNER JOIN `" . NV_PREFIXLANG . "_" . $site_mods[$module]['module_data'] . "_block` AS t2 ON t1.id = t2.id WHERE t2.bid= " . $block_config['blockid'] . " AND t1.status= 1 AND t1.inhome='1' and t1.publtime < " . NV_CURRENTTIME . " AND (t1.exptime=0 OR t1.exptime >" . NV_CURRENTTIME . ") ORDER BY t2.weight ASC LIMIT 0 , " . $block_config['numrow']; | $show_no_image = $module_config[$module]['show_no_image']; |
$list = nv_db_cache( $sql, 'id', $module ); | $blockwidth = $module_config[$module]['blockwidth']; |
$html = ""; | |
$i = 1; | $db->sqlreset() |
if ( ! empty( $list ) ) | ->select('t1.id, t1.catid, t1.title, t1.alias, t1.homeimgfile, t1.homeimgthumb,t1.hometext,t1.publtime') |
{ | ->from(NV_PREFIXLANG . '_' . $site_mods[$module]['module_data'] . '_rows t1') |
if ( file_exists( NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/news/block_blocknews.tpl" ) ) | ->join('INNER JOIN ' . NV_PREFIXLANG . '_' . $site_mods[$module]['module_data'] . '_block t2 ON t1.id = t2.id') |
{ | ->where('t2.bid= ' . $block_config['blockid'] . ' AND t1.status= 1') |
$block_theme = $module_info['template']; | ->order('t2.weight ASC') |
| ->limit($block_config['numrow']); |
| $list = $nv_Cache->db($db->sql(), '', $module); |
| |
| if (! empty($list)) { |
| if (file_exists(NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/news/block_groups.tpl')) { |
| $block_theme = $global_config['module_theme']; |
| } else { |
| $block_theme = 'default'; |
| } |
| $xtpl = new XTemplate('block_groups.tpl', NV_ROOTDIR . '/themes/' . $block_theme . '/modules/news'); |
| $xtpl->assign('NV_BASE_SITEURL', NV_BASE_SITEURL); |
| $xtpl->assign('TEMPLATE', $block_theme); |
| |
| foreach ($list as $l) { |
| $l['link'] = NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module . '&' . NV_OP_VARIABLE . '=' . $module_array_cat[$l['catid']]['alias'] . '/' . $l['alias'] . '-' . $l['id'] . $global_config['rewrite_exturl']; |
| if ($l['homeimgthumb'] == 1) { |
| $l['thumb'] = NV_BASE_SITEURL . NV_FILES_DIR . '/' . $site_mods[$module]['module_upload'] . '/' . $l['homeimgfile']; |
| } elseif ($l['homeimgthumb'] == 2) { |
| $l['thumb'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $site_mods[$module]['module_upload'] . '/' . $l['homeimgfile']; |
| } elseif ($l['homeimgthumb'] == 3) { |
| $l['thumb'] = $l['homeimgfile']; |
| } elseif (! empty($show_no_image)) { |
| $l['thumb'] = NV_BASE_SITEURL . $show_no_image; |
| } else { |
| $l['thumb'] = ''; |
} | } |
else | |
{ | $l['blockwidth'] = $blockwidth; |
$block_theme = "default"; | |
| $l['hometext'] = nv_clean60($l['hometext'], $block_config['tooltip_length'], true); |
| |
| if (! $block_config['showtooltip']) { |
| $xtpl->assign('TITLE', 'title="' . $l['title'] . '"'); |
} | } |
$xtpl = new XTemplate( "block_blocknews.tpl", NV_ROOTDIR . "/themes/" . $block_theme . "/modules/news" ); | |
foreach ( $list as $l ) | $xtpl->assign('ROW', $l); |
{ | if (! empty($l['thumb'])) { |
$arr_catid = explode( ',', $l['listcatid'] ); | $xtpl->parse('main.loop.img'); |
$link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module . "&" . NV_OP_VARIABLE . "=" . $module_array_cat[$arr_catid[0]]['alias'] . "/" . $l['alias'] . "-" . $l['id']; | |
$l['link'] = $link; | |
$l['thumb'] = ""; | |
if ( ! empty( $l['homeimgthumb'] ) ) | |
{ | |
$array_img = array(); | |
$array_img = explode( "|", $l['homeimgthumb'] ); | |
if ( $array_img[0] != "" and file_exists( NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module . '/' . $array_img[0] ) ) | |
{ | |
$imgurl = NV_BASE_SITEURL . NV_FILES_DIR . '/' . $module . '/' . $array_img[0]; | |
$l['thumb'] = $imgurl; | |
} | |
} | |
$xtpl->assign( 'ROW', $l ); | |
if ( ! empty( $l['thumb'] ) ) $xtpl->parse( 'main.loop.img' ); | |
$bg = ( $i % 2 == 0 ) ? "bg" : ""; | |
$xtpl->assign( 'bg', $bg ); | |
$i ++; | |
$xtpl->parse( 'main.loop' ); | |
} | } |
$xtpl->assign( 'HTML_CONTENT', $html ); | $xtpl->parse('main.loop'); |
$xtpl->parse( 'main' ); | |
return $xtpl->text( 'main' ); | |
} | } |
| |
| if ($block_config['showtooltip']) { |
| $xtpl->assign('TOOLTIP_POSITION', $block_config['tooltip_position']); |
| $xtpl->parse('main.tooltip'); |
| } |
| |
| $xtpl->parse('main'); |
| return $xtpl->text('main'); |
} | } |
| } |
</code> | </code> |
Lưu ý: | Lưu ý: |