PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/01.Source/01.CORE/modules/download/functions.php

http://creative-portal.googlecode.com/
PHP | 430 lines | 314 code | 53 blank | 63 comment | 49 complexity | dac7ca1817024a343e82a14da5e4ec67 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @copyright 2009
  6. * @createdate 12/31/2009 0:51
  7. */
  8. if ( ! defined( 'NV_SYSTEM' ) ) die( 'Stop!!!' );
  9. define( 'NV_IS_MOD_DOWNLOAD', true );
  10. /**
  11. * nv_setcats()
  12. *
  13. * @param mixed $id
  14. * @param mixed $list
  15. * @param mixed $name
  16. * @param mixed $is_parentlink
  17. * @return
  18. */
  19. function nv_setcats ( $id, $list, $name, $is_parentlink )
  20. {
  21. global $module_name;
  22. if ( $is_parentlink )
  23. {
  24. $name = "<a href=\"" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $list[$id]['alias'] . "\">" . $list[$id]['title'] . "</a> &raquo; " . $name;
  25. }
  26. else
  27. {
  28. $name = $list[$id]['title'] . " &raquo; " . $name;
  29. }
  30. $parentid = $list[$id]['parentid'];
  31. if ( $parentid )
  32. {
  33. $name = nv_setcats( $parentid, $list, $name, $is_parentlink );
  34. }
  35. return $name;
  36. }
  37. /**
  38. * nv_list_cats()
  39. *
  40. * @param bool $is_link
  41. * @param bool $is_parentlink
  42. * @return
  43. */
  44. function nv_list_cats ( $is_link = false, $is_parentlink = true )
  45. {
  46. global $module_data, $module_name, $module_info;
  47. $sql = "SELECT `id`,`title`,`alias`,`description`,`who_view`,`groups_view`,`who_download`,`groups_download`, `parentid`
  48. FROM `" . NV_PREFIXLANG . "_" . $module_data . "_categories` WHERE `status`=1 ORDER BY `parentid`,`weight` ASC";
  49. $list = nv_db_cache( $sql, 'id' );
  50. $list2 = array();
  51. if ( ! empty( $list ) )
  52. {
  53. foreach ( $list as $row )
  54. {
  55. if ( nv_set_allow( $row['who_view'], $row['groups_view'] ) )
  56. {
  57. if ( ! $row['parentid'] or isset( $list[$row['parentid']] ) )
  58. {
  59. $list2[$row['id']] = $list[$row['id']];
  60. $list2[$row['id']]['name'] = $list[$row['id']]['title'];
  61. $list2[$row['id']]['is_download_allow'] = ( int )nv_set_allow( $row['who_download'], $row['groups_download'] );
  62. $list2[$row['id']]['subcats'] = array();
  63. if ( $is_link )
  64. {
  65. $list2[$row['id']]['name'] = "<a href=\"" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $list2[$row['id']]['alias'] . "\">" . $list2[$row['id']]['name'] . "</a>";
  66. }
  67. if ( $row['parentid'] )
  68. {
  69. $list2[$row['parentid']]['subcats'][] = $row['id'];
  70. $list2[$row['id']]['name'] = nv_setcats( $row['parentid'], $list, $list2[$row['id']]['name'], $is_parentlink );
  71. }
  72. if ( $is_parentlink )
  73. {
  74. $list2[$row['id']]['name'] = "<a href=\"" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "\">" . $module_info['custom_title'] . "</a> &raquo; " . $list2[$row['id']]['name'];
  75. }
  76. }
  77. }
  78. }
  79. }
  80. return $list2;
  81. }
  82. /**
  83. * initial_config_data()
  84. *
  85. * @return
  86. */
  87. function initial_config_data ( )
  88. {
  89. global $module_name, $module_data, $module_name;
  90. $sql = "SELECT `config_name`,`config_value` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_config`";
  91. $list = nv_db_cache( $sql );
  92. $download_config = array();
  93. foreach ( $list as $values )
  94. {
  95. $download_config[$values['config_name']] = $values['config_value'];
  96. }
  97. $download_config['upload_filetype'] = ! empty( $download_config['upload_filetype'] ) ? explode( ",", $download_config['upload_filetype'] ) : array();
  98. if ( ! empty( $download_config['upload_filetype'] ) ) $download_config['upload_filetype'] = array_map( "trim", $download_config['upload_filetype'] );
  99. if ( empty( $download_config['upload_filetype'] ) )
  100. {
  101. $download_config['is_upload'] = 0;
  102. }
  103. if ( $download_config['is_addfile'] )
  104. {
  105. $download_config['is_addfile_allow'] = nv_set_allow( $download_config['who_addfile'], $download_config['groups_addfile'] );
  106. }
  107. else
  108. {
  109. $download_config['is_addfile_allow'] = false;
  110. }
  111. if ( $download_config['is_addfile_allow'] and $download_config['is_upload'] )
  112. {
  113. $download_config['is_upload_allow'] = nv_set_allow( $download_config['who_upload'], $download_config['groups_upload'] );
  114. }
  115. else
  116. {
  117. $download_config['is_upload_allow'] = false;
  118. }
  119. $download_config['is_autocomment_allow'] = nv_set_allow( $download_config['who_autocomment'], $download_config['groups_autocomment'] );
  120. return $download_config;
  121. }
  122. if ( $op == "main" )
  123. {
  124. $catalias = "";
  125. $filealias = "";
  126. $catid = 0;
  127. $nv_vertical_menu = array();
  128. $list_cats = nv_list_cats( true );
  129. if ( ! empty( $list_cats ) )
  130. {
  131. if ( ! empty( $array_op ) )
  132. {
  133. $catalias = isset( $array_op[0] ) ? $array_op[0] : "";
  134. $filealias = isset( $array_op[1] ) ? $array_op[1] : "";
  135. }
  136. // Xac dinh ID cua chu de
  137. foreach ( $list_cats as $c )
  138. {
  139. if ( $c['alias'] == $catalias )
  140. {
  141. $catid = intval( $c['id'] );
  142. break;
  143. }
  144. }
  145. //Het Xac dinh ID cua chu de
  146. //Xac dinh menu, RSS
  147. $rss[] = array( //
  148. 'title' => $module_info['custom_title'], 'src' => NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=rss" //
  149. );
  150. foreach ( $list_cats as $c )
  151. {
  152. if ( $c['parentid'] == 0 )
  153. {
  154. $sub_menu = array();
  155. $act = ( $c['id'] == $catid ) ? 1 : 0;
  156. if ( $act or ( $catid > 0 and $c['id'] == $list_cats[$catid]['parentid'] ) )
  157. {
  158. foreach ( $c['subcats'] as $catid_i )
  159. {
  160. $s_c = $list_cats[$catid_i];
  161. $s_act = ( $s_c['alias'] == $catalias ) ? 1 : 0;
  162. $s_link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $s_c['alias'];
  163. $sub_menu[] = array(
  164. $s_c['title'], $s_link, $s_act
  165. );
  166. }
  167. }
  168. $link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $c['alias'];
  169. $nv_vertical_menu[] = array(
  170. $c['title'], $link, $act, 'submenu' => $sub_menu
  171. );
  172. }
  173. $rss[] = array(
  174. 'title' => $module_info['custom_title'] . ' - ' . $c['title'], 'src' => NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=rss/" . $c['alias'] //
  175. );
  176. }
  177. //het Xac dinh menu, RSS
  178. //Xem chi tiet
  179. if ( $catid > 0 )
  180. {
  181. $op = "viewcat";
  182. if ( ! empty( $filealias ) )
  183. {
  184. $op = "viewfile";
  185. }
  186. $parentid = $catid;
  187. while ( $parentid > 0 )
  188. {
  189. $c = $list_cats[$parentid];
  190. $array_mod_title[] = array(
  191. 'catid' => $parentid, 'title' => $c['title'], 'link' => NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $c['alias']
  192. );
  193. $parentid = $c['parentid'];
  194. }
  195. sort( $array_mod_title, SORT_NUMERIC );
  196. }
  197. }
  198. }
  199. /**
  200. * BoldKeywordInStr()
  201. *
  202. * @param mixed $str
  203. * @param mixed $keyword
  204. * @return
  205. */
  206. function BoldKeywordInStr( $str, $keyword, $logic )
  207. {
  208. global $db;
  209. $str = nv_br2nl( $str );
  210. $str = nv_nl2br( $str, " " );
  211. $str = nv_unhtmlspecialchars( strip_tags( trim( $str ) ) );
  212. $str = $db->unfixdb( $str );
  213. $pos = false;
  214. if ( $logic == 'AND' )
  215. {
  216. $array_keyword = array( $keyword, nv_EncString( $keyword ) );
  217. }
  218. else
  219. {
  220. $keyword .= " " . nv_EncString( $keyword );
  221. $array_keyword = explode( " ", $keyword );
  222. $array_keyword = array_unique( $array_keyword );
  223. }
  224. foreach ( $array_keyword as $k )
  225. {
  226. unset( $matches );
  227. if ( preg_match( "/^(.*?)" . preg_quote( $k ) . "/uis", $str, $matches ) )
  228. {
  229. $strlen = nv_strlen( $str );
  230. $kstrlen = nv_strlen( $k );
  231. $residual = $strlen - 300;
  232. if ( $residual > 0 )
  233. {
  234. $lstrlen = nv_strlen( $matches[1] );
  235. $rstrlen = $strlen - $lstrlen - $kstrlen;
  236. $medium = round( ( 300 - $kstrlen ) / 2 );
  237. if ( $lstrlen <= $medium )
  238. {
  239. $str = nv_clean60( $str, 300 );
  240. } elseif ( $rstrlen <= $medium )
  241. {
  242. $str = nv_substr( $str, $residual, 300 );
  243. $str = nv_substr_clean( $str, 'l' );
  244. }
  245. else
  246. {
  247. $str = nv_substr( $str, $lstrlen - $medium, $strlen - $lstrlen + $medium );
  248. $str = nv_substr( $str, 0, 300 );
  249. $str = nv_substr_clean( $str, 'lr' );
  250. }
  251. }
  252. $pos = true;
  253. break;
  254. }
  255. }
  256. if ( ! $pos )
  257. {
  258. return nv_clean60( $str, 300 );
  259. }
  260. $pattern = array();
  261. foreach ( $array_keyword as $k )
  262. {
  263. $pattern[] = "/(" . preg_quote( $k ) . ")/uis";
  264. }
  265. $str = preg_replace( $pattern, "{\\1}", $str );
  266. $str = str_replace( array( "{", "}" ), array( "<span class=\"keyword\">", "</span>" ), $str );
  267. return $str;
  268. }
  269. /**
  270. * nv_setcats()
  271. *
  272. * @param mixed $list2
  273. * @param mixed $id
  274. * @param mixed $list
  275. * @param integer $m
  276. * @param integer $num
  277. * @return
  278. */
  279. function nv_setcats2( $list2, $id, $list, $m = 0, $num = 0 )
  280. {
  281. $num++;
  282. $defis = "";
  283. for ( $i = 0; $i < $num; $i++ )
  284. {
  285. $defis .= "--";
  286. }
  287. if ( isset( $list[$id] ) )
  288. {
  289. foreach ( $list[$id] as $value )
  290. {
  291. if ( $value['id'] != $m )
  292. {
  293. $list2[$value['id']] = $value;
  294. $list2[$value['id']]['name'] = "|" . $defis . "&gt; " . $list2[$value['id']]['name'];
  295. if ( isset( $list[$value['id']] ) )
  296. {
  297. $list2 = nv_setcats2( $list2, $value['id'], $list, $m, $num );
  298. }
  299. }
  300. }
  301. }
  302. return $list2;
  303. }
  304. /**
  305. * nv_listcats()
  306. *
  307. * @param mixed $parentid
  308. * @param integer $m
  309. * @return
  310. */
  311. function nv_listcats( $parentid, $m = 0 )
  312. {
  313. global $db, $module_data;
  314. $sql = "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_categories` WHERE `status`=1 ORDER BY `parentid`,`weight` ASC";
  315. $result = $db->sql_query( $sql );
  316. $list = array();
  317. while ( $row = $db->sql_fetchrow( $result ) )
  318. {
  319. $list[$row['parentid']][] = array( //
  320. 'id' => ( int )$row['id'], //
  321. 'parentid' => ( int )$row['parentid'], //
  322. 'title' => $row['title'], //
  323. 'alias' => $row['alias'], //
  324. 'description' => $row['description'], //
  325. 'who_view' => ( int )$row['who_view'], //
  326. 'groups_view' => ! empty( $row['groups_view'] ) ? explode( ",", $row['groups_view'] ) : array(), //
  327. 'who_download' => ( int )$row['who_download'], //
  328. 'groups_download' => ! empty( $row['groups_download'] ) ? explode( ",", $row['groups_download'] ) : array(), //
  329. 'weight' => ( int )$row['weight'], //
  330. 'status' => $row['weight'], //
  331. 'name' => $row['title'], //
  332. 'selected' => $parentid == $row['id'] ? " selected=\"selected\"" : "" //
  333. );
  334. }
  335. if ( empty( $list ) )
  336. {
  337. return $list;
  338. }
  339. $list2 = array();
  340. foreach ( $list[0] as $value )
  341. {
  342. if ( $value['id'] != $m )
  343. {
  344. $list2[$value['id']] = $value;
  345. if ( isset( $list[$value['id']] ) )
  346. {
  347. $list2 = nv_setcats2( $list2, $value['id'], $list, $m );
  348. }
  349. }
  350. }
  351. return $list2;
  352. }
  353. /**
  354. * nv_substr_clean()
  355. *
  356. * @param mixed $string
  357. * @param string $mode
  358. * @return
  359. */
  360. function nv_substr_clean( $string, $mode = 'lr' )
  361. {
  362. $strlen = nv_strlen( $string );
  363. $pos_bg = nv_strpos( $string, " " ) + 1;
  364. $pos_en = nv_strrpos( $string, " " );
  365. if ( $mode == 'l' )
  366. {
  367. $string = "..." . nv_substr( $string, $pos_bg, $strlen - $pos_bg );
  368. } elseif ( $mode == 'r' )
  369. {
  370. $string = nv_substr( $string, 0, $strlen - $pos_en ) . "...";
  371. } elseif ( $mode == 'lr' )
  372. {
  373. $string = "..." . nv_substr( $string, $pos_bg, $pos_en - $pos_bg ) . "...";
  374. }
  375. return $string;
  376. }
  377. ?>