PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/01.Source/01.CORE/modules/download/funcs/upload.php

http://creative-portal.googlecode.com/
PHP | 313 lines | 262 code | 45 blank | 6 comment | 33 complexity | 51d420bf5bf2cae03d0a99d64880cd7b 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 (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_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name );
  14. exit();
  15. }
  16. $list_cats = nv_list_cats( false, false );
  17. if ( empty( $list_cats ) )
  18. {
  19. Header( "Location: " . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name );
  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_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name );
  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. } elseif ( empty( $array['user_name'] ) )
  96. {
  97. $is_error = true;
  98. $error = $lang_module['upload_error2'];
  99. } elseif ( empty( $array['title'] ) )
  100. {
  101. $is_error = true;
  102. $error = $lang_module['file_error_title'];
  103. } elseif ( $is_exists )
  104. {
  105. $is_error = true;
  106. $error = $lang_module['file_title_exists'];
  107. } elseif ( ! $array['catid'] or ! isset( $list_cats[$array['catid']] ) )
  108. {
  109. $is_error = true;
  110. $error = $lang_module['file_catid_exists'];
  111. } elseif ( ! empty( $array['author_email'] ) and ( $check_valid_email = nv_check_valid_email( $array['author_email'] ) ) != "" )
  112. {
  113. $is_error = true;
  114. $error = $check_valid_email;
  115. } elseif ( ! empty( $array['author_url'] ) and ! nv_is_url( $array['author_url'] ) )
  116. {
  117. $is_error = true;
  118. $error = $lang_module['file_error_author_url'];
  119. }
  120. else
  121. {
  122. $fileupload = "";
  123. if ( $download_config['is_upload_allow'] )
  124. {
  125. if ( isset( $_FILES['upload_fileupload'] ) and is_uploaded_file( $_FILES['upload_fileupload']['tmp_name'] ) )
  126. {
  127. $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 );
  128. $upload_info = $upload->save_file( $_FILES['upload_fileupload'], NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $download_config['temp_dir'], false );
  129. @unlink( $_FILES['upload_fileupload']['tmp_name'] );
  130. if ( empty( $upload_info['error'] ) )
  131. {
  132. if ( in_array( $upload_info['ext'], $download_config['upload_filetype'] ) )
  133. {
  134. mt_srand( ( double )microtime() * 1000000 );
  135. $maxran = 1000000;
  136. $random_num = mt_rand( 0, $maxran );
  137. $random_num = md5( $random_num );
  138. $nv_pathinfo_filename = nv_pathinfo_filename( $upload_info['name'] );
  139. $new_name = NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $download_config['temp_dir'] . '/' . $nv_pathinfo_filename . '.' . $random_num . '.' . $upload_info['ext'];
  140. $rename = nv_renamefile( $upload_info['name'], $new_name );
  141. if ( $rename[0] == 1 )
  142. {
  143. $fileupload = $new_name;
  144. }
  145. else
  146. {
  147. $fileupload = $upload_info['name'];
  148. }
  149. @chmod( $fileupload, 0644 );
  150. $fileupload = str_replace( NV_ROOTDIR . '/', "", $fileupload );
  151. $fileupload = NV_BASE_SITEURL . $fileupload;
  152. $array['filesize'] = $upload_info['size'];
  153. }
  154. else
  155. {
  156. @nv_deletefile( $upload_info['name'] );
  157. $is_error = true;
  158. $error = $lang_module['upload_error4'];
  159. }
  160. }
  161. else
  162. {
  163. $is_error = true;
  164. $error = $upload_info['error'];
  165. }
  166. unset( $upload, $upload_info );
  167. }
  168. }
  169. if ( ! $is_error )
  170. {
  171. if ( empty( $fileupload ) and empty( $array['linkdirect'] ) )
  172. {
  173. $is_error = true;
  174. $error = $lang_module['file_error_fileupload'];
  175. }
  176. else
  177. {
  178. $fileimage = "";
  179. if ( isset( $_FILES['upload_fileimage'] ) and is_uploaded_file( $_FILES['upload_fileimage']['tmp_name'] ) )
  180. {
  181. $upload = new upload( array( 'images' ), $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT );
  182. $upload_info = $upload->save_file( $_FILES['upload_fileimage'], NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $download_config['temp_dir'], false );
  183. @unlink( $_FILES['upload_fileimage']['tmp_name'] );
  184. if ( empty( $upload_info['error'] ) )
  185. {
  186. mt_srand( ( double )microtime() * 1000000 );
  187. $maxran = 1000000;
  188. $random_num = mt_rand( 0, $maxran );
  189. $random_num = md5( $random_num );
  190. $nv_pathinfo_filename = nv_pathinfo_filename( $upload_info['name'] );
  191. $new_name = NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $download_config['temp_dir'] . '/' . $nv_pathinfo_filename . '.' . $random_num . '.' . $upload_info['ext'];
  192. $rename = nv_renamefile( $upload_info['name'], $new_name );
  193. if ( $rename[0] == 1 )
  194. {
  195. $fileimage = $new_name;
  196. }
  197. else
  198. {
  199. $fileimage = $upload_info['name'];
  200. }
  201. @chmod( $fileimage, 0644 );
  202. $fileimage = str_replace( NV_ROOTDIR . "/", "", $fileimage );
  203. $fileimage = NV_BASE_SITEURL . $fileimage;
  204. }
  205. }
  206. $array['description'] = nv_nl2br( $array['description'], "<br />" );
  207. $array['introtext'] = nv_nl2br( $array['introtext'], "<br />" );
  208. $array['linkdirect'] = nv_nl2br( $array['linkdirect'], "<br />" );
  209. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_tmp` VALUES (
  210. NULL,
  211. " . $array['catid'] . ",
  212. " . $db->dbescape( $array['title'] ) . ",
  213. " . $db->dbescape( $array['description'] ) . ",
  214. " . $db->dbescape( $array['introtext'] ) . ",
  215. " . NV_CURRENTTIME . ",
  216. " . $array['user_id'] . ",
  217. " . $db->dbescape( $array['user_name'] ) . ",
  218. " . $db->dbescape( $array['author_name'] ) . ",
  219. " . $db->dbescape( $array['author_email'] ) . ",
  220. " . $db->dbescape( $array['author_url'] ) . ",
  221. " . $db->dbescape( $fileupload ) . ",
  222. " . $db->dbescape( $array['linkdirect'] ) . ",
  223. " . $db->dbescape( $array['version'] ) . ",
  224. " . $array['filesize'] . ",
  225. " . $db->dbescape( $fileimage ) . ",
  226. " . $db->dbescape( $array['copyright'] ) . ")";
  227. if ( ! $db->sql_query_insert_id( $sql ) )
  228. {
  229. $is_error = true;
  230. $error = $lang_module['upload_error3'];
  231. }
  232. else
  233. {
  234. $contents = "<div class=\"info_exit\">" . $lang_module['file_upload_ok'] . "</div>";
  235. $contents .= "<meta http-equiv=\"refresh\" content=\"2;url=" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "\" />";
  236. include ( NV_ROOTDIR . "/includes/header.php" );
  237. echo nv_site_theme( $contents );
  238. include ( NV_ROOTDIR . "/includes/footer.php" );
  239. exit;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. else
  246. {
  247. $array['catid'] = $array['filesize'] = 0;
  248. $array['title'] = $array['description'] = $array['introtext'] = $array['author_name'] = $array['author_email'] = $array['author_url'] = $array['linkdirect'] = $array['version'] = $array['copyright'] = $array['user_name'] = "";
  249. if ( defined( 'NV_IS_USER' ) )
  250. {
  251. $array['user_name'] = $user_info['username'];
  252. $array['user_id'] = $user_info['userid'];
  253. }
  254. }
  255. if ( ! $array['filesize'] ) $array['filesize'] = '';
  256. if ( ! empty( $array['description'] ) ) $array['description'] = nv_htmlspecialchars( $array['description'] );
  257. if ( ! empty( $array['introtext'] ) ) $array['introtext'] = nv_htmlspecialchars( $array['introtext'] );
  258. $array['disabled'] = "";
  259. if ( defined( 'NV_IS_USER' ) )
  260. {
  261. $array['disabled'] = " disabled=\"disabled\"";
  262. }
  263. $array['addfile'] = md5( $client_info['session_id'] );
  264. $contents = theme_upload( $array, $list_cats, $download_config, $error );
  265. include ( NV_ROOTDIR . "/includes/header.php" );
  266. echo nv_site_theme( $contents );
  267. include ( NV_ROOTDIR . "/includes/footer.php" );
  268. ?>