/01.Source/01.CORE/modules/download/functions.php
PHP | 430 lines | 314 code | 53 blank | 63 comment | 49 complexity | dac7ca1817024a343e82a14da5e4ec67 MD5 | raw file
Possible License(s): BSD-3-Clause
- <?php
-
- /**
- * @Project NUKEVIET 3.0
- * @Author VINADES.,JSC (contact@vinades.vn)
- * @copyright 2009
- * @createdate 12/31/2009 0:51
- */
-
- if ( ! defined( 'NV_SYSTEM' ) ) die( 'Stop!!!' );
-
- define( 'NV_IS_MOD_DOWNLOAD', true );
-
- /**
- * nv_setcats()
- *
- * @param mixed $id
- * @param mixed $list
- * @param mixed $name
- * @param mixed $is_parentlink
- * @return
- */
- function nv_setcats ( $id, $list, $name, $is_parentlink )
- {
- global $module_name;
-
- if ( $is_parentlink )
- {
- $name = "<a href=\"" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $list[$id]['alias'] . "\">" . $list[$id]['title'] . "</a> » " . $name;
- }
- else
- {
- $name = $list[$id]['title'] . " » " . $name;
- }
- $parentid = $list[$id]['parentid'];
- if ( $parentid )
- {
- $name = nv_setcats( $parentid, $list, $name, $is_parentlink );
- }
-
- return $name;
- }
-
- /**
- * nv_list_cats()
- *
- * @param bool $is_link
- * @param bool $is_parentlink
- * @return
- */
- function nv_list_cats ( $is_link = false, $is_parentlink = true )
- {
- global $module_data, $module_name, $module_info;
-
- $sql = "SELECT `id`,`title`,`alias`,`description`,`who_view`,`groups_view`,`who_download`,`groups_download`, `parentid`
- FROM `" . NV_PREFIXLANG . "_" . $module_data . "_categories` WHERE `status`=1 ORDER BY `parentid`,`weight` ASC";
-
- $list = nv_db_cache( $sql, 'id' );
-
- $list2 = array();
-
- if ( ! empty( $list ) )
- {
- foreach ( $list as $row )
- {
- if ( nv_set_allow( $row['who_view'], $row['groups_view'] ) )
- {
- if ( ! $row['parentid'] or isset( $list[$row['parentid']] ) )
- {
- $list2[$row['id']] = $list[$row['id']];
- $list2[$row['id']]['name'] = $list[$row['id']]['title'];
- $list2[$row['id']]['is_download_allow'] = ( int )nv_set_allow( $row['who_download'], $row['groups_download'] );
- $list2[$row['id']]['subcats'] = array();
-
- if ( $is_link )
- {
- $list2[$row['id']]['name'] = "<a href=\"" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $list2[$row['id']]['alias'] . "\">" . $list2[$row['id']]['name'] . "</a>";
- }
-
- if ( $row['parentid'] )
- {
- $list2[$row['parentid']]['subcats'][] = $row['id'];
-
- $list2[$row['id']]['name'] = nv_setcats( $row['parentid'], $list, $list2[$row['id']]['name'], $is_parentlink );
- }
-
- if ( $is_parentlink )
- {
- $list2[$row['id']]['name'] = "<a href=\"" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "\">" . $module_info['custom_title'] . "</a> » " . $list2[$row['id']]['name'];
- }
- }
- }
- }
- }
-
- return $list2;
- }
-
- /**
- * initial_config_data()
- *
- * @return
- */
- function initial_config_data ( )
- {
- global $module_name, $module_data, $module_name;
-
- $sql = "SELECT `config_name`,`config_value` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_config`";
-
- $list = nv_db_cache( $sql );
-
- $download_config = array();
- foreach ( $list as $values )
- {
- $download_config[$values['config_name']] = $values['config_value'];
- }
-
- $download_config['upload_filetype'] = ! empty( $download_config['upload_filetype'] ) ? explode( ",", $download_config['upload_filetype'] ) : array();
- if ( ! empty( $download_config['upload_filetype'] ) ) $download_config['upload_filetype'] = array_map( "trim", $download_config['upload_filetype'] );
-
- if ( empty( $download_config['upload_filetype'] ) )
- {
- $download_config['is_upload'] = 0;
- }
-
- if ( $download_config['is_addfile'] )
- {
- $download_config['is_addfile_allow'] = nv_set_allow( $download_config['who_addfile'], $download_config['groups_addfile'] );
- }
- else
- {
- $download_config['is_addfile_allow'] = false;
- }
-
- if ( $download_config['is_addfile_allow'] and $download_config['is_upload'] )
- {
- $download_config['is_upload_allow'] = nv_set_allow( $download_config['who_upload'], $download_config['groups_upload'] );
- }
- else
- {
- $download_config['is_upload_allow'] = false;
- }
-
- $download_config['is_autocomment_allow'] = nv_set_allow( $download_config['who_autocomment'], $download_config['groups_autocomment'] );
-
- return $download_config;
- }
-
- if ( $op == "main" )
- {
- $catalias = "";
- $filealias = "";
- $catid = 0;
- $nv_vertical_menu = array();
-
- $list_cats = nv_list_cats( true );
- if ( ! empty( $list_cats ) )
- {
- if ( ! empty( $array_op ) )
- {
- $catalias = isset( $array_op[0] ) ? $array_op[0] : "";
- $filealias = isset( $array_op[1] ) ? $array_op[1] : "";
- }
-
- // Xac dinh ID cua chu de
- foreach ( $list_cats as $c )
- {
- if ( $c['alias'] == $catalias )
- {
- $catid = intval( $c['id'] );
- break;
- }
- }
- //Het Xac dinh ID cua chu de
-
-
- //Xac dinh menu, RSS
- $rss[] = array( //
- 'title' => $module_info['custom_title'], 'src' => NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=rss" //
- );
-
- foreach ( $list_cats as $c )
- {
- if ( $c['parentid'] == 0 )
- {
- $sub_menu = array();
- $act = ( $c['id'] == $catid ) ? 1 : 0;
- if ( $act or ( $catid > 0 and $c['id'] == $list_cats[$catid]['parentid'] ) )
- {
- foreach ( $c['subcats'] as $catid_i )
- {
- $s_c = $list_cats[$catid_i];
- $s_act = ( $s_c['alias'] == $catalias ) ? 1 : 0;
- $s_link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $s_c['alias'];
- $sub_menu[] = array(
- $s_c['title'], $s_link, $s_act
- );
- }
- }
-
- $link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $c['alias'];
- $nv_vertical_menu[] = array(
- $c['title'], $link, $act, 'submenu' => $sub_menu
- );
- }
-
- $rss[] = array(
- 'title' => $module_info['custom_title'] . ' - ' . $c['title'], 'src' => NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=rss/" . $c['alias'] //
- );
- }
- //het Xac dinh menu, RSS
- //Xem chi tiet
- if ( $catid > 0 )
- {
- $op = "viewcat";
- if ( ! empty( $filealias ) )
- {
- $op = "viewfile";
- }
-
- $parentid = $catid;
- while ( $parentid > 0 )
- {
- $c = $list_cats[$parentid];
- $array_mod_title[] = array(
- 'catid' => $parentid, 'title' => $c['title'], 'link' => NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $c['alias']
- );
- $parentid = $c['parentid'];
- }
- sort( $array_mod_title, SORT_NUMERIC );
- }
- }
- }
- /**
- * BoldKeywordInStr()
- *
- * @param mixed $str
- * @param mixed $keyword
- * @return
- */
- function BoldKeywordInStr( $str, $keyword, $logic )
- {
- global $db;
-
- $str = nv_br2nl( $str );
- $str = nv_nl2br( $str, " " );
- $str = nv_unhtmlspecialchars( strip_tags( trim( $str ) ) );
- $str = $db->unfixdb( $str );
-
- $pos = false;
-
- if ( $logic == 'AND' )
- {
- $array_keyword = array( $keyword, nv_EncString( $keyword ) );
- }
- else
- {
- $keyword .= " " . nv_EncString( $keyword );
- $array_keyword = explode( " ", $keyword );
- $array_keyword = array_unique( $array_keyword );
- }
-
- foreach ( $array_keyword as $k )
- {
- unset( $matches );
- if ( preg_match( "/^(.*?)" . preg_quote( $k ) . "/uis", $str, $matches ) )
- {
- $strlen = nv_strlen( $str );
- $kstrlen = nv_strlen( $k );
- $residual = $strlen - 300;
- if ( $residual > 0 )
- {
- $lstrlen = nv_strlen( $matches[1] );
- $rstrlen = $strlen - $lstrlen - $kstrlen;
-
- $medium = round( ( 300 - $kstrlen ) / 2 );
- if ( $lstrlen <= $medium )
- {
- $str = nv_clean60( $str, 300 );
- } elseif ( $rstrlen <= $medium )
- {
- $str = nv_substr( $str, $residual, 300 );
- $str = nv_substr_clean( $str, 'l' );
- }
- else
- {
- $str = nv_substr( $str, $lstrlen - $medium, $strlen - $lstrlen + $medium );
- $str = nv_substr( $str, 0, 300 );
- $str = nv_substr_clean( $str, 'lr' );
- }
- }
-
- $pos = true;
- break;
- }
- }
-
- if ( ! $pos )
- {
- return nv_clean60( $str, 300 );
- }
-
- $pattern = array();
- foreach ( $array_keyword as $k )
- {
- $pattern[] = "/(" . preg_quote( $k ) . ")/uis";
- }
-
- $str = preg_replace( $pattern, "{\\1}", $str );
- $str = str_replace( array( "{", "}" ), array( "<span class=\"keyword\">", "</span>" ), $str );
-
- return $str;
- }
-
- /**
- * nv_setcats()
- *
- * @param mixed $list2
- * @param mixed $id
- * @param mixed $list
- * @param integer $m
- * @param integer $num
- * @return
- */
- function nv_setcats2( $list2, $id, $list, $m = 0, $num = 0 )
- {
- $num++;
- $defis = "";
- for ( $i = 0; $i < $num; $i++ )
- {
- $defis .= "--";
- }
-
- if ( isset( $list[$id] ) )
- {
- foreach ( $list[$id] as $value )
- {
- if ( $value['id'] != $m )
- {
- $list2[$value['id']] = $value;
- $list2[$value['id']]['name'] = "|" . $defis . "> " . $list2[$value['id']]['name'];
- if ( isset( $list[$value['id']] ) )
- {
- $list2 = nv_setcats2( $list2, $value['id'], $list, $m, $num );
- }
- }
- }
- }
- return $list2;
- }
-
- /**
- * nv_listcats()
- *
- * @param mixed $parentid
- * @param integer $m
- * @return
- */
- function nv_listcats( $parentid, $m = 0 )
- {
- global $db, $module_data;
-
- $sql = "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_categories` WHERE `status`=1 ORDER BY `parentid`,`weight` ASC";
- $result = $db->sql_query( $sql );
- $list = array();
- while ( $row = $db->sql_fetchrow( $result ) )
- {
- $list[$row['parentid']][] = array( //
- 'id' => ( int )$row['id'], //
- 'parentid' => ( int )$row['parentid'], //
- 'title' => $row['title'], //
- 'alias' => $row['alias'], //
- 'description' => $row['description'], //
- 'who_view' => ( int )$row['who_view'], //
- 'groups_view' => ! empty( $row['groups_view'] ) ? explode( ",", $row['groups_view'] ) : array(), //
- 'who_download' => ( int )$row['who_download'], //
- 'groups_download' => ! empty( $row['groups_download'] ) ? explode( ",", $row['groups_download'] ) : array(), //
- 'weight' => ( int )$row['weight'], //
- 'status' => $row['weight'], //
- 'name' => $row['title'], //
- 'selected' => $parentid == $row['id'] ? " selected=\"selected\"" : "" //
- );
- }
-
- if ( empty( $list ) )
- {
- return $list;
- }
-
- $list2 = array();
- foreach ( $list[0] as $value )
- {
- if ( $value['id'] != $m )
- {
- $list2[$value['id']] = $value;
- if ( isset( $list[$value['id']] ) )
- {
- $list2 = nv_setcats2( $list2, $value['id'], $list, $m );
- }
- }
- }
-
- return $list2;
- }
- /**
- * nv_substr_clean()
- *
- * @param mixed $string
- * @param string $mode
- * @return
- */
- function nv_substr_clean( $string, $mode = 'lr' )
- {
- $strlen = nv_strlen( $string );
- $pos_bg = nv_strpos( $string, " " ) + 1;
- $pos_en = nv_strrpos( $string, " " );
- if ( $mode == 'l' )
- {
- $string = "..." . nv_substr( $string, $pos_bg, $strlen - $pos_bg );
- } elseif ( $mode == 'r' )
- {
- $string = nv_substr( $string, 0, $strlen - $pos_en ) . "...";
- } elseif ( $mode == 'lr' )
- {
- $string = "..." . nv_substr( $string, $pos_bg, $pos_en - $pos_bg ) . "...";
- }
-
- return $string;
- }
- ?>