PageRenderTime 76ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/01.Source/01.CORE/admincp/modules/upload/main.php

http://creative-portal.googlecode.com/
PHP | 257 lines | 245 code | 5 blank | 7 comment | 17 complexity | 860a82db142694a63d69f1df0b6e02b5 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 2-9-2010 14:43
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. $page_title = $lang_module['upload_manager'];
  10. # config
  11. $path = htmlspecialchars( trim( $nv_Request->get_string( 'path', 'get', NV_UPLOADS_DIR ) ), ENT_QUOTES );
  12. $currentPath = htmlspecialchars( trim( $nv_Request->get_string( 'currentpath', 'post,get' ) ), ENT_QUOTES );
  13. $area = "";
  14. $popup = $nv_Request->get_int( 'popup', 'get', 0 );
  15. $selectedfile = '';
  16. $uploadflag = $nv_Request->isset_request( 'confirm', 'post' );
  17. if ( $uploadflag )
  18. {
  19. $imgurl = htmlspecialchars( trim( $nv_Request->get_string( 'imgurl', 'post' ) ), ENT_QUOTES );
  20. $imgfolder = htmlspecialchars( trim( $nv_Request->get_string( 'path', 'post' ) ), ENT_QUOTES );
  21. if ( is_uploaded_file( $_FILES['fileupload']['tmp_name'] ) && nv_check_allow_upload_dir( $imgfolder ) )
  22. {
  23. require_once ( NV_ROOTDIR . "/includes/class/upload.class.php" );
  24. $upload = new upload( $admin_info['allow_files_type'], $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, NV_MAX_WIDTH, NV_MAX_HEIGHT );
  25. $upload_info = $upload->save_file( $_FILES['fileupload'], NV_ROOTDIR . '/' . $imgfolder, false );
  26. if ( ! empty( $upload_info['error'] ) )
  27. {
  28. $errors[] = $upload_info['error'];
  29. }
  30. else
  31. {
  32. $selectedfile = $upload_info['basename'];
  33. }
  34. }
  35. elseif ( ! empty( $imgurl ) )
  36. {
  37. $prover = @getimagesize( $imgurl );
  38. if ( $prover )
  39. {
  40. $imgname = end( explode( "/", $imgurl ) );
  41. $imgname = str_replace( '%', '_', $imgname );
  42. $file_type = strtolower( $types[$prover[2]] );
  43. if ( in_array( $file_type, $allowed_extensions ) )
  44. {
  45. include ( NV_ROOTDIR . "/includes/class/geturl.class.php" );
  46. $getContent = new UrlGetContents( $global_config );
  47. $content = '';
  48. $content = $getContent->get( $imgurl );
  49. $handle2 = @fopen( NV_ROOTDIR . '/' . $imgfolder . '/' . basename( $imgname ), 'wb' );
  50. if ( $handle2 && ! empty( $content ) )
  51. {
  52. @fwrite( $handle2, $content );
  53. @fclose( $handle2 );
  54. $datakod = time();
  55. $img_name = $datakod . $imgname;
  56. @rename( NV_ROOTDIR . '/' . $imgfolder . '/' . $imgname, NV_ROOTDIR . '/' . $imgfolder . '/' . $img_name );
  57. }
  58. else
  59. {
  60. $errors[] = $lang_module['upload_file_error_movefile'];
  61. }
  62. }
  63. else
  64. {
  65. $errors[] = $lang_module['upload_file_error_movefile'];
  66. }
  67. }
  68. else
  69. {
  70. $errors[] = $lang_module['upload_create_invalid_filetype'];
  71. }
  72. }
  73. else
  74. {
  75. $errors[] = $lang_module['upload_file_error_invalidurl'];
  76. }
  77. }
  78. if ( ! empty( $errors ) )
  79. {
  80. $contents .= "<div id='edit'></div>\n";
  81. $contents .= "<div class=\"quote\" style=\"width:780px;\">\n";
  82. $contents .= "<blockquote class='error'><span id='message'>" . implode( "<br>", $errors ) . "</span></blockquote>\n";
  83. $contents .= "</div>\n";
  84. $contents .= "<div class=\"clear\"></div>\n";
  85. }
  86. $contents .= '
  87. <table>
  88. <tbody>
  89. <tr>
  90. <td valign="top">
  91. <div name="imgfolder" id="imgfolder" size="25" style="width:200px;height:340px;overflow:auto;cursor:pointer">';
  92. $type = htmlspecialchars( trim( $nv_Request->get_string( 'type', 'get', 'file' ) ), ENT_QUOTES );
  93. $currentpath = $nv_Request->isset_request( 'path', 'post' ) ? htmlspecialchars( trim( $nv_Request->get_string( 'path', 'post', $path ) ), ENT_QUOTES ) : htmlspecialchars( trim( $nv_Request->get_string( 'currentpath', 'get', $path ) ), ENT_QUOTES );
  94. $contents .= ' </div>';
  95. $contents .= '
  96. <script type="text/javascript">
  97. $(function(){
  98. $("#imgfolder").load("' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=folderlist&path=' . $path . '&currentpath=' . $currentpath . '");
  99. $("div#imglist").html("<span style=\'color:red\'><img src=\'' . NV_BASE_SITEURL . 'images/load.gif\'/> please wait...</span>");
  100. $("div#imglist").html("<iframe src=\"' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=imglist&path=' . $currentpath . '&type=' . $type . '&imgfile=' . $selectedfile . '\" style=\"width:590px;height:300px;border:none\"></iframe>");
  101. $("select[name=imgtype]").change(function(){
  102. var folder = $("span#foldervalue").attr("title");
  103. var type = $(this).val();
  104. $("input[name=path]").val(folder);
  105. $("div#imglist").html("<iframe src=\'' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=imglist&path="+folder+"&type="+type+"\' style=\"width:590px;height:300px;border:none\"></iframe>");
  106. });
  107. });
  108. </script>
  109. </td>
  110. <td valign="top">
  111. <select name="imgtype" id="imgtype" style="margin-left:10px;margin-right:10px;float:right">
  112. <option value="file" ' . ( ( $type == 'file' ) ? ' selected' : '' ) . '>' . $lang_module['type_file'] . '</option>
  113. <option value="image" ' . ( ( $type == 'image' ) ? ' selected' : '' ) . '>' . $lang_module['type_image'] . '</option>
  114. <option value="flash" ' . ( ( $type == 'flash' ) ? ' selected' : '' ) . '>' . $lang_module['type_flash'] . '</option>
  115. </select><input type="button" id="uploadfile" value="Upload" style="margin-left:10px;"/>
  116. <form enctype="multipart/form-data" action="" name="uploadimg" id="uploadimg" style="display:none" method="POST">
  117. <input type="hidden" name="path" value="' . ( ! empty( $imgfolder ) ? $imgfolder : $path ) . '"/>
  118. ' . $lang_module['upload_file'] . ' <input type="file" name="fileupload"/> ' . $lang_module['upload_otherurl'] . ' <input type="text" name="imgurl"/> <input type="submit" value="GO" name="confirm"/>
  119. </form>
  120. <br />
  121. <div id="imglist" name="imglist" style="height:360px;width:590px;vertical-align:top;padding:10px"></div>
  122. </td>
  123. </tr>
  124. <tr>
  125. <td colspan="2">';
  126. if ( $popup )
  127. {
  128. $area = htmlspecialchars( trim( $nv_Request->get_string( 'area', 'get' ) ), ENT_QUOTES );
  129. }
  130. $contents .= '<img id="image" src="" name="' . $area . '" title="" style="display:none"/>
  131. <script type="text/javascript">
  132. $("#uploadfile").toggle(function(){
  133. $("#uploadimg").show();
  134. }, function(){
  135. $("#uploadimg").hide();
  136. });
  137. </script>
  138. </td>
  139. </tr>';
  140. $contents .= '<tr style="display:none" class="formfile">
  141. <td style="text-align:center" colspan="2">
  142. <input type="hidden" id="posthidden" value=""/>
  143. </td>
  144. </tr>';
  145. $contents .= '</tbody>
  146. </table>
  147. ';
  148. $contents .= '
  149. <link rel="StyleSheet" href="' . NV_BASE_SITEURL . 'themes/' . $global_config['admin_theme'] . '/css/admin.css" type="text/css" />
  150. <link type="text/css" href="' . NV_BASE_SITEURL . 'js/ui/jquery.ui.all.css" rel="stylesheet" />
  151. <link type="text/css" href="' . NV_BASE_SITEURL . 'js/jquery/jquery.treeview.css" rel="stylesheet" />
  152. <script type="text/javascript" src="' . NV_BASE_SITEURL . 'js/jquery/jquery.treeview.min.js"></script>
  153. <script type="text/javascript" src="' . NV_BASE_SITEURL . 'js/ui/jquery-ui-1.8.2.custom.js"></script>
  154. <script type="text/javascript" src="' . NV_BASE_SITEURL . 'js/contextmenu/jquery.contextmenu.r2.js"></script>
  155. <div id="renamefolder" title="' . $lang_module['renamefolder'] . '">' . $lang_module['rename_newname'] . '<input type="text" name="foldername"/></div>
  156. <div id="createfolder" title="' . $lang_module['createfolder'] . '">' . $lang_module['rename_newname'] . '<input type="text" name="createfoldername"/></div>
  157. <script type="text/javascript">
  158. function insertvaluetofield(){
  159. var value = $("#posthidden").val();
  160. var funcNum = ' . $nv_Request->get_int( 'CKEditorFuncNum', 'get', 0 ) . ';
  161. if (funcNum > 0){
  162. window.opener.CKEDITOR.tools.callFunction(funcNum, value,"");
  163. }
  164. else{
  165. $("#' . $area . '",opener.document).val(value);
  166. }
  167. }
  168. $("div#createfolder").dialog({
  169. autoOpen: false,
  170. width: 250,
  171. height: 160,
  172. modal: true,
  173. position: "center",
  174. buttons: {
  175. Ok: function() {
  176. var foldervalue = $("span#foldervalue").attr("title");
  177. var newname = $("input[name=createfoldername]").val();
  178. if (newname==""){
  179. alert("' . $lang_module['rename_nonamefolder'] . '");
  180. $("input[name=foldername]").focus();
  181. return false;
  182. }
  183. $.ajax({
  184. type: "POST",
  185. url: "' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=createfolder",
  186. data: "path="+foldervalue+"&newname="+newname,
  187. success: function(data){
  188. $("div#imglist").html("<iframe src=\"' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=imglist&path=' . $currentpath . '&type=' . $type . '\" style=\"width:570px;height:360px;border:none\"></iframe>");
  189. $("#imgfolder").load("' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=folderlist&path=' . $path . '&currentpath="+data);
  190. }
  191. });
  192. $(this).dialog("close");
  193. }
  194. }
  195. });
  196. $("div#renamefolder").dialog({
  197. autoOpen: false,
  198. width: 250,
  199. height: 160,
  200. modal: true,
  201. position: "center",
  202. buttons: {
  203. Ok: function() {
  204. var foldervalue = $("span#foldervalue").attr("title");
  205. var newname = $("input[name=foldername]").val();
  206. if (newname=="" || newname==foldervalue){
  207. alert("' . $lang_module['rename_nonamefolder'] . '");
  208. $("input[name=foldername]").focus();
  209. return false;
  210. }
  211. $.ajax({
  212. type: "POST",
  213. url: "' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=renamefolder",
  214. data: "path="+foldervalue+"&newname="+newname,
  215. success: function(data){
  216. $("div#imglist").html("<iframe src=\'' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=imglist&path="+newname+"\' style=\"width:620px;height:360px;border:none\"></iframe>");
  217. $("#imgfolder").load("' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=folderlist&currentpath="+data);
  218. }
  219. });
  220. $(this).dialog("close");
  221. }
  222. }
  223. });
  224. </script>
  225. <span style="display:none" id="foldervalue" title="' . ( ! empty( $imgfolder ) ? $imgfolder : $currentPath ) . '"></span>
  226. <div style="display:none" id="folder-menu">
  227. <ul>';
  228. if ( $admin_info['allow_create_subdirectories'] )
  229. {
  230. $contents .= '<li id="createfolder"><img src="' . NV_BASE_SITEURL . 'js/contextmenu/icons/copy.png"/>' . $lang_module['createfolder'] . '</li>';
  231. }
  232. if ( $admin_info['allow_modify_subdirectories'] )
  233. {
  234. $contents .= '<li id="renamefolder"><img src="' . NV_BASE_SITEURL . 'js/contextmenu/icons/rename.png"/>' . $lang_module['renamefolder'] . '</li>
  235. <li id="deletefolder"><img src="' . NV_BASE_SITEURL . 'js/contextmenu/icons/delete.png"/>' . $lang_module['deletefolder'] . '</li>';
  236. }
  237. $contents .= '
  238. </ul>
  239. </div>';
  240. include ( NV_ROOTDIR . "/includes/header.php" );
  241. if ( $popup )
  242. {
  243. echo '<script type="text/javascript" src="' . NV_BASE_SITEURL . 'js/jquery/jquery.min.js"></script>';
  244. echo $contents;
  245. }
  246. else
  247. {
  248. echo nv_admin_theme( $contents );
  249. }
  250. include ( NV_ROOTDIR . "/includes/footer.php" );
  251. ?>