/modules/music/global.functions.php

http://nukeviet-music.googlecode.com/ · PHP · 989 lines · 870 code · 89 blank · 30 comment · 66 complexity · a1ecc1d1ea73e937b010f951f1a66830 MD5 · raw file

  1. <?php
  2. /**
  3. * @Project NUKEVIET-MUSIC
  4. * @Author Phan Tan Dung (phantandung92@gmail.com)
  5. * @Copyright (C) 2011 Freeware
  6. * @Createdate 26/01/2011 09:09 AM
  7. */
  8. if( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );
  9. global $mainURL, $main_header_URL;
  10. $mainURL = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . '&amp;' . NV_OP_VARIABLE;
  11. $main_header_URL = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . '&' . NV_OP_VARIABLE;
  12. // Lay thong tin the loai
  13. function get_category()
  14. {
  15. global $module_data, $db, $lang_module;
  16. $category = array();
  17. $sql = "SELECT * FROM " . NV_PREFIXLANG . "_" . $module_data . "_category ORDER BY `weight` ASC";
  18. $result = nv_db_cache( $sql, 'id' );
  19. $category[0] = array(
  20. 'id' => 0, //
  21. 'title' => $lang_module['unknow'], //
  22. 'keywords' => '', //
  23. 'description' => '' //
  24. );
  25. if( ! empty( $result ) )
  26. {
  27. foreach( $result as $row )
  28. {
  29. $category[$row['id']] = array(
  30. 'id' => $row['id'], //
  31. 'title' => $row['title'], //
  32. 'keywords' => $row['keywords'], //
  33. 'description' => $row['description'] //
  34. );
  35. }
  36. }
  37. return $category;
  38. }
  39. // lay thong tin the loai video
  40. function get_videocategory()
  41. {
  42. global $module_data, $db, $lang_module;
  43. $category = array();
  44. $sql = "SELECT * FROM " . NV_PREFIXLANG . "_" . $module_data . "_video_category ORDER BY `weight` ASC";
  45. $result = nv_db_cache( $sql, 'id' );
  46. $category[0] = array(
  47. 'id' => 0, //
  48. 'title' => $lang_module['unknow'], //
  49. 'keywords' => '', //
  50. 'description' => '' //
  51. );
  52. if( ! empty( $result ) )
  53. {
  54. foreach( $result as $row )
  55. {
  56. $category[$row['id']] = array(
  57. 'id' => $row['id'], //
  58. 'title' => $row['title'], //
  59. 'keywords' => $row['keywords'], //
  60. 'description' => $row['description'] //
  61. );
  62. }
  63. }
  64. return $category;
  65. }
  66. // cau hinh module
  67. function setting_music()
  68. {
  69. global $module_data, $db;
  70. $setting = array();
  71. $sql = "SELECT * FROM " . NV_PREFIXLANG . "_" . $module_data . "_setting";
  72. $result = nv_db_cache( $sql, 'id' );
  73. if( ! empty( $result ) )
  74. {
  75. foreach( $result as $row )
  76. {
  77. if( in_array( $row['key'], array( "root_contain", "description" ) ) )
  78. {
  79. $setting[$row['key']] = $row['char'];
  80. }
  81. else
  82. {
  83. $setting[$row['key']] = $row['value'];
  84. }
  85. }
  86. }
  87. return $setting;
  88. }
  89. // Lay album tu id
  90. function getalbumbyID( $id )
  91. {
  92. global $module_data, $db;
  93. $album = array();
  94. $result = $db->sql_query( " SELECT * FROM " . NV_PREFIXLANG . "_" . $module_data . "_album WHERE id = " . $id );
  95. $album = $db->sql_fetchrow( $result );
  96. return $album;
  97. }
  98. // lay video tu id
  99. function getvideobyID( $id )
  100. {
  101. global $module_data, $db;
  102. $video = array();
  103. $result = $db->sql_query( " SELECT * FROM " . NV_PREFIXLANG . "_" . $module_data . "_video WHERE id = " . $id );
  104. $video = $db->sql_fetchrow( $result );
  105. return $video;
  106. }
  107. // lay song tu id
  108. function getsongbyID( $id )
  109. {
  110. global $module_data, $db;
  111. $song = array();
  112. $result = $db->sql_query( " SELECT * FROM " . NV_PREFIXLANG . "_" . $module_data . " WHERE id = " . $id );
  113. $song = $db->sql_fetchrow( $result );
  114. return $song;
  115. }
  116. // lay album tu ten
  117. function getalbumbyNAME( $name )
  118. {
  119. global $module_data, $db;
  120. $album = array();
  121. $result = $db->sql_query( " SELECT * FROM " . NV_PREFIXLANG . "_" . $module_data . "_album WHERE name =\"" . $name . "\"" );
  122. $album = $db->sql_fetchrow( $result );
  123. return $album;
  124. }
  125. // lay tat ca ca si
  126. function getallsinger( $reverse = false )
  127. {
  128. global $module_data, $db, $lang_module;
  129. $allsinger = array();
  130. if( $reverse === true )
  131. {
  132. $allsinger[$lang_module['unknow']] = 0;
  133. }
  134. else
  135. {
  136. $allsinger[0] = $lang_module['unknow'];
  137. }
  138. $sql = "SELECT `id`, `tenthat` FROM " . NV_PREFIXLANG . "_" . $module_data . "_singer ORDER BY ten ASC";
  139. $result = nv_db_cache( $sql, 'ten' );
  140. if( ! empty( $result ) )
  141. {
  142. foreach( $result as $row )
  143. {
  144. if( $reverse === true )
  145. {
  146. $allsinger[$row['tenthat']] = $row['id'];
  147. }
  148. else
  149. {
  150. $allsinger[$row['id']] = $row['tenthat'];
  151. }
  152. }
  153. }
  154. return $allsinger;
  155. }
  156. // lay tat ca nhac si
  157. function getallauthor( $reverse = false )
  158. {
  159. global $module_data, $db, $lang_module;
  160. $allsinger = array();
  161. if( $reverse === true )
  162. {
  163. $allsinger[$lang_module['unknow']] = 0;
  164. }
  165. else
  166. {
  167. $allsinger[0] = $lang_module['unknow'];
  168. }
  169. $sql = "SELECT `id`, `tenthat` FROM " . NV_PREFIXLANG . "_" . $module_data . "_author ORDER BY ten ASC";
  170. $result = nv_db_cache( $sql, 'ten' );
  171. if( ! empty( $result ) )
  172. {
  173. foreach( $result as $row )
  174. {
  175. if( $reverse === true )
  176. {
  177. $allsinger[$row['tenthat']] = $row['id'];
  178. }
  179. else
  180. {
  181. $allsinger[$row['id']] = $row['tenthat'];
  182. }
  183. }
  184. }
  185. return $allsinger;
  186. }
  187. // lay ca si tu id
  188. function getsingerbyID( $id )
  189. {
  190. global $module_data, $db;
  191. $singer = array();
  192. $result = $db->sql_query( " SELECT * FROM " . NV_PREFIXLANG . "_" . $module_data . "_singer WHERE id=" . $id );
  193. $singer = $db->sql_fetchrow( $result );
  194. return $singer;
  195. }
  196. // Them moi mot ca si
  197. function newsinger( $name, $tname )
  198. {
  199. $error = '';
  200. global $module_data, $lang_module, $db, $module_name;
  201. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_singer` ( `id`, `ten`, `tenthat`, `thumb`, `introduction`, `numsong`, `numalbum`) VALUES ( NULL, " . $db->dbescape( $name ) . ", " . $db->dbescape( $tname ) . ", '', '', 0, 0 )";
  202. $newid = $db->sql_query_insert_id( $sql );
  203. if( $newid )
  204. {
  205. $db->sql_freeresult();
  206. nv_del_moduleCache( $module_name );
  207. return $newid;
  208. }
  209. return false;
  210. }
  211. // Them moi mot nhac si
  212. function newauthor( $name, $tname )
  213. {
  214. global $module_data, $lang_module, $db, $module_name;
  215. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_author` ( `id`, `ten`, `tenthat`, `thumb`, `introduction`, `numsong`, `numvideo`) VALUES ( NULL, " . $db->dbescape( $name ) . ", " . $db->dbescape( $tname ) . ", '', '', 0, 0 )";
  216. $newid = $db->sql_query_insert_id( $sql );
  217. if( $newid )
  218. {
  219. $db->sql_freeresult();
  220. nv_del_moduleCache( $module_name );
  221. return $newid;
  222. }
  223. return false;
  224. }
  225. // cap nhat ca si
  226. function updatesinger( $id, $what, $action )
  227. {
  228. global $module_data, $db;
  229. $result = $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_singer` SET " . $what . " = " . $what . $action . " WHERE `id` = '" . $id . "'" );
  230. return;
  231. }
  232. // cap nhat nhac si
  233. function updateauthor( $id, $what, $action )
  234. {
  235. global $module_data, $db;
  236. $result = $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_author` SET " . $what . " = " . $what . $action . " WHERE `id` = '" . $id . "'" );
  237. return;
  238. }
  239. // cap nhat album
  240. function updatealbum( $id, $action )
  241. {
  242. global $module_data, $db;
  243. $result = $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_album` SET numsong = numsong" . $action . " WHERE `id` = '" . $id . "'" );
  244. return;
  245. }
  246. // Cap nhat so bai hat the loai am nha
  247. function UpdateSongCat( $id, $action )
  248. {
  249. global $module_data, $db;
  250. $result = $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_category` SET numsong = numsong" . $action . " WHERE `id`=" . $id );
  251. return;
  252. }
  253. // Cap nhat so bai hat the loai am nha
  254. function UpdateVideoCat( $id, $action )
  255. {
  256. global $module_data, $db;
  257. $result = $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_video_category` SET numvideo = numvideo" . $action . " WHERE `id`=" . $id );
  258. return;
  259. }
  260. // xoa cac binh luan
  261. function delcomment( $delwwhat, $where )
  262. {
  263. global $module_data, $db;
  264. $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_comment_" . $delwwhat . "` WHERE `what`=" . $where;
  265. $result = $db->sql_query( $sql );
  266. return;
  267. }
  268. // xoa cac loi bai hat
  269. function dellyric( $songid )
  270. {
  271. global $module_data, $db;
  272. $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_lyric` WHERE `songid`=" . $songid;
  273. $result = $db->sql_query( $sql );
  274. return;
  275. }
  276. // xoa cac bao loi
  277. function delerror( $where, $key )
  278. {
  279. global $module_data, $db;
  280. $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_error` WHERE `where`= '" . $where . "' AND `sid`=" . $key;
  281. $result = $db->sql_query( $sql );
  282. return $result;
  283. }
  284. // xoa cac qua tang am nhac
  285. function delgift( $songid )
  286. {
  287. global $module_data, $db;
  288. $sql = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_gift` WHERE `songid` =" . $songid;
  289. $result = $db->sql_query( $sql );
  290. return;
  291. }
  292. // Lay thong tin ftp cua host nhac
  293. function getFTP()
  294. {
  295. global $module_data, $db, $lang_module;
  296. $ftpdata = array();
  297. $sql = "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_ftp` ORDER BY id DESC";
  298. $result = nv_db_cache( $sql, 'id' );
  299. if( ! empty( $result ) )
  300. {
  301. foreach( $result as $row )
  302. {
  303. $ftpdata[$row['id']] = array(
  304. "id" => $row['id'],
  305. "host" => $row['host'],
  306. "user" => $row['user'],
  307. "pass" => $row['pass'],
  308. "fulladdress" => $row['fulladdress'],
  309. "subpart" => $row['subpart'],
  310. "ftppart" => $row['ftppart'],
  311. "active" => ( $row['active'] == 1 ) ? $lang_module['active_yes'] : $lang_module['active_no'] );
  312. }
  313. }
  314. return $ftpdata;
  315. }
  316. // tao duong dan tu mot chuoi
  317. function creatURL( $inputurl )
  318. {
  319. global $module_name, $setting;
  320. $songdata = array();
  321. if( preg_match( '/^(ht|f)tp:\/\//', $inputurl ) )
  322. {
  323. $ftpdata = getFTP();
  324. $str_inurl = str_split( $inputurl );
  325. $no_ftp = true;
  326. foreach( $ftpdata as $id => $data )
  327. {
  328. $this_host = $data['fulladdress'] . $data['subpart'];
  329. $str_check = str_split( $this_host );
  330. $check_ok = false;
  331. foreach( $str_check as $stt => $char )
  332. {
  333. if( $char != $str_inurl[$stt] )
  334. {
  335. $check_ok = false;
  336. break;
  337. }
  338. $check_ok = true;
  339. }
  340. if( $check_ok )
  341. {
  342. $lu = strlen( $this_host );
  343. $songdata['duongdan'] = substr( $inputurl, $lu );
  344. $songdata['server'] = $id;
  345. $no_ftp = false;
  346. break;
  347. }
  348. }
  349. if( $no_ftp )
  350. {
  351. $songdata['duongdan'] = $inputurl;
  352. $songdata['server'] = 0;
  353. }
  354. }
  355. else
  356. {
  357. $lu = strlen( NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" . $setting['root_contain'] . "/" );
  358. $songdata['duongdan'] = substr( $inputurl, $lu );
  359. $songdata['server'] = 1;
  360. }
  361. return $songdata;
  362. }
  363. // xuat duong dan day du
  364. function outputURL( $server, $inputurl )
  365. {
  366. global $module_name, $setting;
  367. $output = "";
  368. if( $server == 0 )
  369. {
  370. $output = $inputurl;
  371. }
  372. elseif( $server == 1 )
  373. {
  374. $output = NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" . $setting['root_contain'] . "/" . $inputurl;
  375. }
  376. else
  377. {
  378. $ftpdata = getFTP();
  379. foreach( $ftpdata as $id => $data )
  380. {
  381. if( $id == $server )
  382. {
  383. if( $data['host'] == "nhaccuatui" )
  384. {
  385. $cache_file = NV_LANG_DATA . "_" . $module_name . "_link_" . md5( $server . $inputurl ) . "_" . NV_CACHE_PREFIX . ".cache";
  386. if( file_exists( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file ) )
  387. {
  388. if( ( ( NV_CURRENTTIME - filemtime( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file ) ) > $setting['del_cache_time_out'] ) and $setting['del_cache_time_out'] != 0 )
  389. {
  390. nv_deletefile( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file );
  391. }
  392. }
  393. if( ( $cache = nv_get_cache( $cache_file ) ) != false )
  394. {
  395. $output = unserialize( $cache );
  396. }
  397. else
  398. {
  399. $output = $data['fulladdress'] . $data['subpart'] . $inputurl;
  400. $output = nv_get_URL_content( $output );
  401. $cache = "";
  402. if( preg_match( "/\[FLASH\](.*?)\[\/FLASH\]/i", $output, $m ) )
  403. {
  404. $output = get_headers( $m[1] );
  405. foreach( $output as $tmp )
  406. {
  407. if( preg_match( "/^Location: (.*)/is", $tmp, $m ) )
  408. {
  409. if( preg_match( "/file\=(.*)\&ads\=/is", $tmp, $m ) )
  410. {
  411. $output = simplexml_load_string( nv_get_URL_content( $m[1] ) );
  412. $output = trim( ( string ) $output->track->location );
  413. break;
  414. }
  415. }
  416. }
  417. }
  418. $cache = serialize( $cache );
  419. nv_set_cache( $cache_file, $cache );
  420. }
  421. }
  422. elseif( $data['host'] == "zing" )
  423. {
  424. $cache_file = NV_LANG_DATA . "_" . $module_name . "_link_" . md5( $server . $inputurl ) . "_" . NV_CACHE_PREFIX . ".cache";
  425. if( file_exists( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file ) )
  426. {
  427. if( ( ( NV_CURRENTTIME - filemtime( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file ) ) > $setting['del_cache_time_out'] ) and $setting['del_cache_time_out'] != 0 )
  428. {
  429. nv_deletefile( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file );
  430. }
  431. }
  432. if( ( $cache = nv_get_cache( $cache_file ) ) != false )
  433. {
  434. $output = unserialize( $cache );
  435. }
  436. else
  437. {
  438. $output = $data['fulladdress'] . $data['subpart'] . $inputurl;
  439. $output = nv_get_URL_content( $output );
  440. $output = explode( '<input type="hidden" id="_strNoAuto" value="', $output );
  441. if( isset( $output[1] ) )
  442. {
  443. $output = explode( '"', $output[1] );
  444. $output = nv_get_URL_content( $output[0] );
  445. $output = explode( "<urlSource>", $output );
  446. if( isset( $output[1] ) )
  447. {
  448. $output = explode( "</urlSource>", $output[1] );
  449. $output = nv_unhtmlspecialchars( $output[0] );
  450. }
  451. else
  452. {
  453. $output = "";
  454. }
  455. }
  456. else
  457. {
  458. $output = "";
  459. }
  460. $cache = serialize( $output );
  461. nv_set_cache( $cache_file, $cache );
  462. }
  463. }
  464. elseif( $data['host'] == "nhacvui" )
  465. {
  466. $cache_file = NV_LANG_DATA . "_" . $module_name . "_link_" . md5( $server . $inputurl ) . "_" . NV_CACHE_PREFIX . ".cache";
  467. if( file_exists( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file ) )
  468. {
  469. if( ( ( NV_CURRENTTIME - filemtime( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file ) ) > $setting['del_cache_time_out'] ) and $setting['del_cache_time_out'] != 0 )
  470. {
  471. nv_deletefile( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file );
  472. }
  473. }
  474. if( ( $cache = nv_get_cache( $cache_file ) ) != false )
  475. {
  476. $output = unserialize( $cache );
  477. }
  478. else
  479. {
  480. $output = $data['fulladdress'] . $data['subpart'] . $inputurl;
  481. $output = nv_get_URL_content( $output );
  482. unset( $m );
  483. $pattern = "/\'playlistfile\'\: \'(.*?)\'\,/i";
  484. if( ! empty( $output ) and preg_match( $pattern, $output, $m ) )
  485. {
  486. $output = nv_get_URL_content( "http://hcm.nhac.vui.vn" . trim( $m[1] ) );
  487. unset( $m );
  488. $pattern = "/\<jwplayer\:file\>\<\!\[CDATA\[(.*?)\]\]\>\<\/jwplayer\:file\>/i";
  489. if( ! empty( $output ) and preg_match( $pattern, $output, $m ) )
  490. {
  491. $output = trim( $m[1] );
  492. }
  493. else
  494. {
  495. $output = "";
  496. }
  497. }
  498. else
  499. {
  500. $output = "";
  501. }
  502. $cache = serialize( $output );
  503. nv_set_cache( $cache_file, $cache );
  504. }
  505. }
  506. elseif( $data['host'] == "nhacso" )
  507. {
  508. $cache_file = NV_LANG_DATA . "_" . $module_name . "_link_" . md5( $server . $inputurl ) . "_" . NV_CACHE_PREFIX . ".cache";
  509. if( file_exists( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file ) )
  510. {
  511. if( ( ( NV_CURRENTTIME - filemtime( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file ) ) > $setting['del_cache_time_out'] ) and $setting['del_cache_time_out'] != 0 )
  512. {
  513. nv_deletefile( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file );
  514. }
  515. }
  516. if( ( $cache = nv_get_cache( $cache_file ) ) != false )
  517. {
  518. $output = unserialize( $cache );
  519. }
  520. else
  521. {
  522. $output = $data['fulladdress'] . $data['subpart'] . $inputurl;
  523. $output = nv_get_URL_content( $output );
  524. $output = explode( 'embedPlaylistjs.swf?xmlPath=', $output );
  525. if( isset( $output[1] ) )
  526. {
  527. $output = explode( '&amp;', $output[1] );
  528. $output = nv_get_URL_content( $output[0] );
  529. $output = explode( "<mp3link><![CDATA[", $output );
  530. if( isset( $output[1] ) )
  531. {
  532. $output = explode( "]]></mp3link>", $output[1] );
  533. $output = trim( $output[0] );
  534. }
  535. else
  536. {
  537. $output = "";
  538. }
  539. }
  540. else
  541. {
  542. $output = "";
  543. }
  544. $cache = serialize( $output );
  545. nv_set_cache( $cache_file, $cache );
  546. }
  547. }
  548. elseif( $data['host'] == "zingclip" )
  549. {
  550. $cache_file = NV_LANG_DATA . "_" . $module_name . "_link_zingclip_" . md5( $server . $inputurl ) . "_" . NV_CACHE_PREFIX . ".cache";
  551. if( file_exists( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file ) )
  552. {
  553. if( ( ( NV_CURRENTTIME - filemtime( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file ) ) > $setting['del_cache_time_out'] ) and $setting['del_cache_time_out'] != 0 )
  554. {
  555. nv_deletefile( NV_ROOTDIR . "/" . NV_CACHEDIR . "/" . $cache_file );
  556. }
  557. }
  558. if( ( $cache = nv_get_cache( $cache_file ) ) != false )
  559. {
  560. $output = unserialize( $cache );
  561. }
  562. else
  563. {
  564. $output = $data['fulladdress'] . $data['subpart'] . $inputurl;
  565. $output = nv_get_URL_content( $output );
  566. unset( $m );
  567. if( ! preg_match( "/\<input type\=\"hidden\" id\=\"\_strAuto\" value\=\"([^\"]+)\"[^\/]+\/\>/is", $output, $m ) )
  568. {
  569. $output = "";
  570. }
  571. else
  572. {
  573. $output = nv_get_URL_content( $m[1] );
  574. if( ( $xml = simplexml_load_string( $output ) ) == false ) return "";
  575. $output = ( string )$xml->item->f480;
  576. }
  577. $cache = serialize( $output );
  578. nv_set_cache( $cache_file, $cache );
  579. }
  580. }
  581. else
  582. {
  583. $output = $data['fulladdress'] . $data['subpart'] . $inputurl;
  584. break;
  585. }
  586. }
  587. }
  588. }
  589. return $output;
  590. }
  591. function unlinkSV( $server, $url )
  592. {
  593. global $module_name, $setting;
  594. if( $server == 1 )
  595. {
  596. @unlink( NV_DOCUMENT_ROOT . NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/" . $setting['root_contain'] . "/" . $url );
  597. }
  598. elseif( $server != 0 )
  599. {
  600. $ftpdata = getFTP();
  601. if( ! isset( $ftpdata[$server] ) ) return;
  602. if( in_array( $ftpdata[$server]['host'], array(
  603. 'nhaccuatui',
  604. 'zing',
  605. 'nhacvui',
  606. 'nhacso' ) ) ) return;
  607. require_once ( NV_ROOTDIR . "/modules/" . $module_name . "/class/ftp.class.php" );
  608. $ftp = new FTP();
  609. if( $ftp->connect( $ftpdata[$server]['host'] ) )
  610. {
  611. if( $ftp->login( $ftpdata[$server]['user'], $ftpdata[$server]['pass'] ) )
  612. {
  613. $ftp->delete( $ftpdata[$server]['ftppart'] . $ftpdata[$server]['subpart'] . $url );
  614. }
  615. $ftp->disconnect();
  616. }
  617. }
  618. return;
  619. }
  620. //
  621. function nv_get_URL_content( $target_url )
  622. {
  623. global $client_info;
  624. $agent = empty( $client_info['agent'] ) ? 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0' : $client_info['agent'];
  625. if( function_exists( 'curl_init' ) )
  626. {
  627. $ch = curl_init();
  628. curl_setopt( $ch, CURLOPT_URL, $target_url );
  629. curl_setopt( $ch, CURLOPT_HEADER, 0 );
  630. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  631. curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
  632. curl_setopt( $ch, CURLOPT_USERAGENT, $agent );
  633. $content = curl_exec( $ch );
  634. $errormsg = curl_error( $ch );
  635. curl_close( $ch );
  636. if( $errormsg != "" )
  637. {
  638. return "";
  639. }
  640. }
  641. if( ! is_array( $content ) )
  642. {
  643. $content = explode( "\n", $content );
  644. }
  645. return implode( "", $content );
  646. }
  647. function nvm_new_song( $array )
  648. {
  649. global $module_data, $db;
  650. $array['ten'] = ! isset( $array['ten'] ) ? "" : $array['ten'];
  651. $array['tenthat'] = ! isset( $array['tenthat'] ) ? "" : $array['tenthat'];
  652. $array['casi'] = ! isset( $array['casi'] ) ? 0 : $array['casi'];
  653. $array['nhacsi'] = ! isset( $array['nhacsi'] ) ? 0 : $array['nhacsi'];
  654. $array['album'] = ! isset( $array['album'] ) ? 0 : $array['album'];
  655. $array['theloai'] = ! isset( $array['theloai'] ) ? 0 : $array['theloai'];
  656. $array['listcat'] = ! isset( $array['listcat'] ) ? array() : $array['listcat'];
  657. $array['data'] = ! isset( $array['data'] ) ? "" : $array['data'];
  658. $array['username'] = ! isset( $array['username'] ) ? "N/A" : $array['username'];
  659. $array['bitrate'] = ! isset( $array['bitrate'] ) ? "0" : $array['bitrate'];
  660. $array['size'] = ! isset( $array['size'] ) ? "0" : $array['size'];
  661. $array['duration'] = ! isset( $array['duration'] ) ? "0" : $array['duration'];
  662. $array['server'] = ! isset( $array['server'] ) ? "1" : $array['server'];
  663. $array['userid'] = ! isset( $array['userid'] ) ? "1" : $array['userid'];
  664. $array['hit'] = ! isset( $array['hit'] ) ? "0-" . NV_CURRENTTIME : $array['hit'];
  665. $array['lyric'] = ! isset( $array['lyric'] ) ? "" : $array['lyric'];
  666. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "` VALUES (
  667. NULL,
  668. " . $db->dbescape( $array['ten'] ) . ",
  669. " . $db->dbescape( $array['tenthat'] ) . ",
  670. " . $array['casi'] . ",
  671. " . $array['nhacsi'] . ",
  672. " . $array['album'] . ",
  673. " . $db->dbescape( $array['theloai'] ) . ",
  674. " . $db->dbescape( implode( ",", $array['listcat'] ) ) . ",
  675. " . $db->dbescape( $array['data'] ) . ",
  676. " . $db->dbescape( $array['username'] ) . " ,
  677. 0,
  678. 1,
  679. " . $db->dbescape( $array['bitrate'] ) . " ,
  680. " . $db->dbescape( $array['size'] ) . " ,
  681. " . $db->dbescape( $array['duration'] ) . ",
  682. " . $array['server'] . ",
  683. " . $array['userid'] . ",
  684. " . NV_CURRENTTIME . ",
  685. 0,
  686. " . $db->dbescape( $array['hit'] ) . "
  687. )";
  688. $_songid = $db->sql_query_insert_id( $sql );
  689. if( $_songid )
  690. {
  691. // Cap nhat bai hat cho the loai
  692. // Xac dinh chu de moi
  693. $list_new_cat = $array['listcat'];
  694. $list_new_cat[] = $array['theloai'];
  695. $list_new_cat = array_unique( $list_new_cat );
  696. foreach( $list_new_cat as $_cid )
  697. {
  698. if( $_cid > 0 ) UpdateSongCat( $_cid, '+1' );
  699. }
  700. // Cap nhat so bai hat cua ca si, nhac si va album
  701. updatesinger( $array['casi'], 'numsong', '+1' );
  702. updateauthor( $array['nhacsi'], 'numsong', '+1' );
  703. updatealbum( $array['album'], '+1' );
  704. // Them bai hat vao danh sach nhac cua album moi
  705. if( ! empty( $array['album'] ) )
  706. {
  707. $sql = "SELECT `listsong` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_album` WHERE `id`=" . $array['album'];
  708. $result = $db->sql_query( $sql );
  709. list( $list_song ) = $db->sql_fetchrow( $result );
  710. $list_song = explode( ',', $list_song );
  711. $list_song[] = $_songid;
  712. $list_song = array_unique( $list_song );
  713. $list_song = array_filter( $list_song );
  714. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_album` SET `listsong`=" . $db->dbescape( implode( ',', $list_song ) ) . " WHERE `id`=" . $array['album'];
  715. $db->sql_query( $sql );
  716. }
  717. // Them loi bai hat moi
  718. if( ! empty( $array['lyric'] ) )
  719. {
  720. $array['lyric'] = nv_nl2br( $array['lyric'], "<br />" );
  721. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_lyric` VALUES(
  722. NULL,
  723. " . $_songid . ",
  724. " . $db->dbescape( $array['username'] ) . ",
  725. " . $db->dbescape( $array['lyric'] ) . ",
  726. 1,
  727. " . NV_CURRENTTIME . "
  728. )";
  729. $db->sql_query( $sql );
  730. }
  731. $db->sql_freeresult();
  732. }
  733. return $_songid;
  734. }
  735. function nvm_edit_song( $array_old, $array )
  736. {
  737. global $module_data, $db;
  738. $array_old['casi'] = ! isset( $array_old['casi'] ) ? 0 : $array_old['casi'];
  739. $array_old['nhacsi'] = ! isset( $array_old['nhacsi'] ) ? 0 : $array_old['nhacsi'];
  740. $array_old['theloai'] = ! isset( $array_old['theloai'] ) ? 0 : $array_old['theloai'];
  741. $array_old['lyric'] = ! isset( $array_old['lyric'] ) ? "" : $array_old['lyric'];
  742. $array_old['listcat'] = ! isset( $array_old['listcat'] ) ? array() : ( array ) $array_old['listcat'];
  743. $array['ten'] = ! isset( $array['ten'] ) ? "" : $array['ten'];
  744. $array['tenthat'] = ! isset( $array['tenthat'] ) ? "" : $array['tenthat'];
  745. $array['casi'] = ! isset( $array['casi'] ) ? 0 : $array['casi'];
  746. $array['nhacsi'] = ! isset( $array['nhacsi'] ) ? 0 : $array['nhacsi'];
  747. $array['album'] = ! isset( $array['album'] ) ? 0 : $array['album'];
  748. $array['theloai'] = ! isset( $array['theloai'] ) ? 0 : $array['theloai'];
  749. $array['listcat'] = ! isset( $array['listcat'] ) ? array() : $array['listcat'];
  750. $array['duongdan'] = ! isset( $array['duongdan'] ) ? "" : $array['duongdan'];
  751. $array['bitrate'] = ! isset( $array['bitrate'] ) ? "0" : $array['bitrate'];
  752. $array['size'] = ! isset( $array['size'] ) ? "0" : $array['size'];
  753. $array['duration'] = ! isset( $array['duration'] ) ? "0" : $array['duration'];
  754. $array['server'] = ! isset( $array['server'] ) ? "1" : $array['server'];
  755. $array['userid'] = ! isset( $array['userid'] ) ? "1" : $array['userid'];
  756. $array['username'] = ! isset( $array['username'] ) ? "N/A" : $array['username'];
  757. $array['lyric'] = ! isset( $array['lyric'] ) ? "" : $array['lyric'];
  758. $array['id'] = ! isset( $array['id'] ) ? "0" : $array['id'];
  759. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "` SET
  760. `ten`=" . $db->dbescape( $array['ten'] ) . ",
  761. `tenthat`=" . $db->dbescape( $array['tenthat'] ) . ",
  762. `casi`=" . $array['casi'] . ",
  763. `nhacsi`=" . $array['nhacsi'] . ",
  764. `album`=" . $array['album'] . ",
  765. `theloai`=" . $db->dbescape( $array['theloai'] ) . ",
  766. `listcat`=" . $db->dbescape( implode( ",", $array['listcat'] ) ) . ",
  767. `duongdan`=" . $db->dbescape( $array['duongdan'] ) . ",
  768. `bitrate`=" . $db->dbescape( $array['bitrate'] ) . " ,
  769. `size`=" . $db->dbescape( $array['size'] ) . " ,
  770. `duration`=" . $db->dbescape( $array['duration'] ) . ",
  771. `server`=" . $array['server'] . "
  772. WHERE `id`=" . $array['id'];
  773. $check_update = $db->sql_query( $sql );
  774. if( $check_update )
  775. {
  776. // Cap nhat bai hat cho the loai
  777. // Xac dinh cac chu de cu
  778. $list_old_cat = $array_old['listcat'];
  779. $list_old_cat[] = $array_old['theloai'];
  780. $list_old_cat = array_unique( $list_old_cat );
  781. // Xac dinh chu de moi
  782. $list_new_cat = $array['listcat'];
  783. $list_new_cat[] = $array['theloai'];
  784. $list_new_cat = array_unique( $list_new_cat );
  785. $array_mul = array_diff( $list_new_cat, $list_old_cat );
  786. $array_div = array_diff( $list_old_cat, $list_new_cat );
  787. foreach( $array_mul as $_cid )
  788. {
  789. if( $_cid > 0 ) UpdateSongCat( $_cid, '+1' );
  790. }
  791. foreach( $array_div as $_cid )
  792. {
  793. if( $_cid > 0 ) UpdateSongCat( $_cid, '-1' );
  794. }
  795. // Cap nhat so bai hat cua ca si
  796. if( $array_old['casi'] != $array['casi'] )
  797. {
  798. updatesinger( $array_old['casi'], 'numsong', '-1' );
  799. updatesinger( $array['casi'], 'numsong', '+1' );
  800. }
  801. // Cap nhat so bai hat cua nhac si
  802. if( $array_old['nhacsi'] != $array['nhacsi'] )
  803. {
  804. updateauthor( $array_old['nhacsi'], 'numsong', '-1' );
  805. updateauthor( $array['nhacsi'], 'numsong', '+1' );
  806. }
  807. // Cap nhat so bai hat cua album
  808. if( $array_old['album'] != $array['album'] )
  809. {
  810. updatealbum( $array_old['album'], '-1' );
  811. updatealbum( $array['album'], '+1' );
  812. // Them bai hat vao danh sach bai hat cua album moi
  813. $sql = "SELECT `listsong` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_album` WHERE `id`=" . $array['album'];
  814. $result = $db->sql_query( $sql );
  815. list( $list_song ) = $db->sql_fetchrow( $result );
  816. $list_song = explode( ',', $list_song );
  817. $list_song[] = $array['id'];
  818. $list_song = array_unique( $list_song );
  819. $list_song = array_filter( $list_song );
  820. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_album` SET `listsong`=" . $db->dbescape( implode( ',', $list_song ) ) . " WHERE `id`=" . $array['album'];
  821. $db->sql_query( $sql );
  822. }
  823. // Xu ly loi bai hat
  824. if( $array['lyric'] != $array_old['lyric'] )
  825. {
  826. $array['lyric'] = nv_nl2br( $array['lyric'], "<br />" );
  827. $sql = "SELECT `id` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_lyric` WHERE `songid`=" . $array['id'] . " AND `user`=" . $db->dbescape( $array['username'] );
  828. $result = $db->sql_query( $sql );
  829. list( $lyric_id ) = $db->sql_fetchrow( $result );
  830. // Cap nhat loi bai hat
  831. if( $lyric_id )
  832. {
  833. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_lyric` SET `body`=" . $db->dbescape( $array['lyric'] ) . " WHERE `id`=" . $lyric_id;
  834. $db->sql_query( $sql );
  835. }
  836. // Them loi bai hat
  837. else
  838. {
  839. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_lyric` VALUES(
  840. NULL,
  841. " . $array['id'] . ",
  842. " . $db->dbescape( $array['username'] ) . ",
  843. " . $db->dbescape( $array['lyric'] ) . ",
  844. 1, " . NV_CURRENTTIME . "
  845. )";
  846. $db->sql_query( $sql );
  847. }
  848. }
  849. $db->sql_freeresult();
  850. }
  851. return $check_update;
  852. }
  853. ?>