PageRenderTime 73ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/NukeViet3.2/modules/download/funcs/upload.php

http://nuke-viet.googlecode.com/
PHP | 320 lines | 268 code | 46 blank | 6 comment | 33 complexity | cd18a503987467cea4f5dffba9666af6 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES., JSC. All rights reserved
  6. * @Createdate 3-6-2010 0:30
  7. */
  8. if ( ! defined( 'NV_IS_MOD_DOWNLOAD' ) ) die( 'Stop!!!' );
  9. $page_title = $lang_module['upload'];
  10. $download_config = initial_config_data();
  11. if ( ! $download_config['is_addfile_allow'] )
  12. {
  13. Header( "Location: " . nv_url_rewrite( NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name, true ) );
  14. exit();
  15. }
  16. $list_cats = nv_list_cats( false, false );
  17. if ( empty( $list_cats ) )
  18. {
  19. Header( "Location: " . nv_url_rewrite( NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name, true ) );
  20. exit();
  21. }
  22. $is_error = false;
  23. $error = "";
  24. if ( $nv_Request->isset_request( 'addfile', 'post' ) )
  25. {
  26. @require_once ( NV_ROOTDIR . "/includes/class/upload.class.php" );
  27. $addfile = $nv_Request->get_string( 'addfile', 'post', '' );
  28. if ( empty( $addfile ) or $addfile != md5( $client_info['session_id'] ) )
  29. {
  30. Header( "Location: " . nv_url_rewrite( NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name, true ) );
  31. exit();
  32. }
  33. $array = array();
  34. $array['catid'] = $nv_Request->get_int( 'upload_catid', 'post', 0 );
  35. $array['title'] = filter_text_input( 'upload_title', 'post', '', 1, 255 );
  36. $array['description'] = filter_text_textarea( 'upload_description', '', NV_ALLOWED_HTML_TAGS );
  37. $array['introtext'] = filter_text_textarea( 'upload_introtext', '', NV_ALLOWED_HTML_TAGS );
  38. $array['author_name'] = filter_text_input( 'upload_author_name', 'post', '', 1, 100 );
  39. $array['author_email'] = filter_text_input( 'upload_author_email', 'post', '', 60 );
  40. $array['author_url'] = filter_text_input( 'upload_author_url', 'post', '', 0, 255 );
  41. $array['linkdirect'] = filter_text_textarea( 'upload_linkdirect', '' );
  42. $array['version'] = filter_text_input( 'upload_version', 'post', '', 1, 20 );
  43. $array['filesize'] = $nv_Request->get_int( 'upload_filesize', 'post', 0 );
  44. $array['copyright'] = filter_text_input( 'upload_copyright', 'post', '', 1, 255 );
  45. $array['user_name'] = filter_text_input( 'upload_user_name', 'post', '', 1, 100 );
  46. $array['user_id'] = 0;
  47. $seccode = filter_text_input( 'upload_seccode', 'post', '' );
  48. if ( defined( 'NV_IS_USER' ) )
  49. {
  50. $array['user_name'] = $user_info['username'];
  51. $array['user_id'] = $user_info['userid'];
  52. }
  53. if ( ! empty( $array['author_url'] ) )
  54. {
  55. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $array['author_url'] ) )
  56. {
  57. $array['author_url'] = "http://" . $array['author_url'];
  58. }
  59. }
  60. if ( ! empty( $array['linkdirect'] ) )
  61. {
  62. $linkdirect = $array['linkdirect'];
  63. $linkdirect = nv_nl2br( $linkdirect, "<br />" );
  64. $linkdirect = explode( "<br />", $linkdirect );
  65. $linkdirect = array_map( "trim", $linkdirect );
  66. $linkdirect = array_unique( $linkdirect );
  67. $array['linkdirect'] = array();
  68. foreach ( $linkdirect as $link )
  69. {
  70. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $link ) )
  71. {
  72. $link = "http://" . $link;
  73. }
  74. if ( nv_is_url( $link ) )
  75. {
  76. $array['linkdirect'][] = $link;
  77. }
  78. }
  79. $array['linkdirect'] = ! empty( $array['linkdirect'] ) ? implode( "\n", $array['linkdirect'] ) : "";
  80. }
  81. $alias = change_alias( $array['title'] );
  82. $sql = "SELECT COUNT(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE `alias`=" . $db->dbescape( $alias );
  83. $result = $db->sql_query( $sql );
  84. list( $is_exists ) = $db->sql_fetchrow( $result );
  85. if ( ! $is_exists )
  86. {
  87. $sql = "SELECT COUNT(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_tmp` WHERE `title`=" . $db->dbescape( $array['title'] );
  88. $result = $db->sql_query( $sql );
  89. list( $is_exists ) = $db->sql_fetchrow( $result );
  90. }
  91. if ( ! nv_capcha_txt( $seccode ) )
  92. {
  93. $is_error = true;
  94. $error = $lang_module['upload_error1'];
  95. }
  96. elseif ( empty( $array['user_name'] ) )
  97. {
  98. $is_error = true;
  99. $error = $lang_module['upload_error2'];
  100. }
  101. elseif ( empty( $array['title'] ) )
  102. {
  103. $is_error = true;
  104. $error = $lang_module['file_error_title'];
  105. }
  106. elseif ( $is_exists )
  107. {
  108. $is_error = true;
  109. $error = $lang_module['file_title_exists'];
  110. }
  111. elseif ( ! $array['catid'] or ! isset( $list_cats[$array['catid']] ) )
  112. {
  113. $is_error = true;
  114. $error = $lang_module['file_catid_exists'];
  115. }
  116. elseif ( ! empty( $array['author_email'] ) and ( $check_valid_email = nv_check_valid_email( $array['author_email'] ) ) != "" )
  117. {
  118. $is_error = true;
  119. $error = $check_valid_email;
  120. }
  121. elseif ( ! empty( $array['author_url'] ) and ! nv_is_url( $array['author_url'] ) )
  122. {
  123. $is_error = true;
  124. $error = $lang_module['file_error_author_url'];
  125. }
  126. else
  127. {
  128. $fileupload = "";
  129. if ( $download_config['is_upload_allow'] )
  130. {
  131. if ( isset( $_FILES['upload_fileupload'] ) and is_uploaded_file( $_FILES['upload_fileupload']['tmp_name'] ) )
  132. {
  133. $upload = new upload( $global_config['file_allowed_ext'], $global_config['forbid_extensions'], $global_config['forbid_mimes'], $download_config['maxfilesize'], NV_MAX_WIDTH, NV_MAX_HEIGHT );
  134. $upload_info = $upload->save_file( $_FILES['upload_fileupload'], NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $download_config['temp_dir'], false );
  135. @unlink( $_FILES['upload_fileupload']['tmp_name'] );
  136. if ( empty( $upload_info['error'] ) )
  137. {
  138. if ( in_array( $upload_info['ext'], $download_config['upload_filetype'] ) )
  139. {
  140. mt_srand( ( double )microtime() * 1000000 );
  141. $maxran = 1000000;
  142. $random_num = mt_rand( 0, $maxran );
  143. $random_num = md5( $random_num );
  144. $nv_pathinfo_filename = nv_pathinfo_filename( $upload_info['name'] );
  145. $new_name = NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $download_config['temp_dir'] . '/' . $nv_pathinfo_filename . '.' . $random_num . '.' . $upload_info['ext'];
  146. $rename = nv_renamefile( $upload_info['name'], $new_name );
  147. if ( $rename[0] == 1 )
  148. {
  149. $fileupload = $new_name;
  150. }
  151. else
  152. {
  153. $fileupload = $upload_info['name'];
  154. }
  155. @chmod( $fileupload, 0644 );
  156. $fileupload = str_replace( NV_ROOTDIR . "/" . NV_UPLOADS_DIR, "", $fileupload );
  157. $array['filesize'] = $upload_info['size'];
  158. }
  159. else
  160. {
  161. @nv_deletefile( $upload_info['name'] );
  162. $is_error = true;
  163. $error = $lang_module['upload_error4'];
  164. }
  165. }
  166. else
  167. {
  168. $is_error = true;
  169. $error = $upload_info['error'];
  170. }
  171. unset( $upload, $upload_info );
  172. }
  173. }
  174. if ( ! $is_error )
  175. {
  176. if ( empty( $fileupload ) and empty( $array['linkdirect'] ) )
  177. {
  178. $is_error = true;
  179. $error = $lang_module['file_error_fileupload'];
  180. }
  181. else
  182. {
  183. $fileimage = "";
  184. if ( isset( $_FILES['upload_fileimage'] ) and is_uploaded_file( $_FILES['upload_fileimage']['tmp_name'] ) )
  185. {
  186. $upload = new upload( array( 'images' ), $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT );
  187. $upload_info = $upload->save_file( $_FILES['upload_fileimage'], NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $download_config['temp_dir'], false );
  188. @unlink( $_FILES['upload_fileimage']['tmp_name'] );
  189. if ( empty( $upload_info['error'] ) )
  190. {
  191. mt_srand( ( double )microtime() * 1000000 );
  192. $maxran = 1000000;
  193. $random_num = mt_rand( 0, $maxran );
  194. $random_num = md5( $random_num );
  195. $nv_pathinfo_filename = nv_pathinfo_filename( $upload_info['name'] );
  196. $new_name = NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $download_config['temp_dir'] . '/' . $nv_pathinfo_filename . '.' . $random_num . '.' . $upload_info['ext'];
  197. $rename = nv_renamefile( $upload_info['name'], $new_name );
  198. if ( $rename[0] == 1 )
  199. {
  200. $fileimage = $new_name;
  201. }
  202. else
  203. {
  204. $fileimage = $upload_info['name'];
  205. }
  206. @chmod( $fileimage, 0644 );
  207. $fileimage = str_replace( NV_ROOTDIR . "/" . NV_UPLOADS_DIR, "", $fileimage );
  208. }
  209. }
  210. $array['description'] = nv_nl2br( $array['description'], "<br />" );
  211. $array['introtext'] = nv_nl2br( $array['introtext'], "<br />" );
  212. $array['linkdirect'] = nv_nl2br( $array['linkdirect'], "<br />" );
  213. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_tmp` VALUES (
  214. NULL,
  215. " . $array['catid'] . ",
  216. " . $db->dbescape( $array['title'] ) . ",
  217. " . $db->dbescape( $array['description'] ) . ",
  218. " . $db->dbescape( $array['introtext'] ) . ",
  219. " . NV_CURRENTTIME . ",
  220. " . $array['user_id'] . ",
  221. " . $db->dbescape( $array['user_name'] ) . ",
  222. " . $db->dbescape( $array['author_name'] ) . ",
  223. " . $db->dbescape( $array['author_email'] ) . ",
  224. " . $db->dbescape( $array['author_url'] ) . ",
  225. " . $db->dbescape( $fileupload ) . ",
  226. " . $db->dbescape( $array['linkdirect'] ) . ",
  227. " . $db->dbescape( $array['version'] ) . ",
  228. " . $array['filesize'] . ",
  229. " . $db->dbescape( $fileimage ) . ",
  230. " . $db->dbescape( $array['copyright'] ) . ")";
  231. if ( ! $db->sql_query_insert_id( $sql ) )
  232. {
  233. $is_error = true;
  234. $error = $lang_module['upload_error3'];
  235. }
  236. else
  237. {
  238. $contents = "<div class=\"info_exit\">" . $lang_module['file_upload_ok'] . "</div>";
  239. $contents .= "<meta http-equiv=\"refresh\" content=\"2;url=" . nv_url_rewrite( NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name, true ) . "\" />";
  240. $user_post = defined ( "NV_IS_USER" ) ? " | " . $user_info['username'] : "";
  241. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['upload_files_log'], $array['title'] . " | " . $client_info['ip'] . $user_post, 0 );
  242. include ( NV_ROOTDIR . "/includes/header.php" );
  243. echo nv_site_theme( $contents );
  244. include ( NV_ROOTDIR . "/includes/footer.php" );
  245. exit();
  246. }
  247. }
  248. }
  249. }
  250. }
  251. else
  252. {
  253. $array['catid'] = $array['filesize'] = 0;
  254. $array['title'] = $array['description'] = $array['introtext'] = $array['author_name'] = $array['author_email'] = $array['author_url'] = $array['linkdirect'] = $array['version'] = $array['copyright'] = $array['user_name'] = "";
  255. if ( defined( 'NV_IS_USER' ) )
  256. {
  257. $array['user_name'] = $user_info['username'];
  258. $array['user_id'] = $user_info['userid'];
  259. }
  260. }
  261. if ( ! $array['filesize'] ) $array['filesize'] = '';
  262. if ( ! empty( $array['description'] ) ) $array['description'] = nv_htmlspecialchars( $array['description'] );
  263. if ( ! empty( $array['introtext'] ) ) $array['introtext'] = nv_htmlspecialchars( $array['introtext'] );
  264. $array['disabled'] = "";
  265. if ( defined( 'NV_IS_USER' ) )
  266. {
  267. $array['disabled'] = " disabled=\"disabled\"";
  268. }
  269. $array['addfile'] = md5( $client_info['session_id'] );
  270. $contents = theme_upload( $array, $list_cats, $download_config, $error );
  271. include ( NV_ROOTDIR . "/includes/header.php" );
  272. echo nv_site_theme( $contents );
  273. include ( NV_ROOTDIR . "/includes/footer.php" );
  274. ?>