PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/NukeViet3.2/admin/modules/themes/install_check.php

http://nuke-viet.googlecode.com/
PHP | 233 lines | 216 code | 4 blank | 13 comment | 19 complexity | a4be9d89d63900579ad79bd0e8d9d2da 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 2-2-2010 12:55
  7. */
  8. if ( ! defined( 'NV_IS_FILE_THEMES' ) ) die( 'Stop!!!' );
  9. $title = $note = $module_file = "";
  10. $filename = NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . NV_TEMPNAM_PREFIX . 'theme' . md5( $global_config['sitekey'] . session_id() ) . '.zip';
  11. if ( file_exists( $filename ) )
  12. {
  13. require_once NV_ROOTDIR . '/includes/class/pclzip.class.php';
  14. $zip = new PclZip( $filename );
  15. $ziplistContent = $zip->listContent();
  16. $overwrite = $nv_Request->get_string( 'overwrite', 'get', '' );
  17. $errorfile = '';
  18. if ( $overwrite != md5( $filename . $global_config['sitekey'] . session_id() ) )
  19. {
  20. foreach ( $ziplistContent as $array_file )
  21. {
  22. //check exist file on system
  23. if ( empty( $array_file['folder'] ) and file_exists( NV_ROOTDIR . '/themes/' . trim( $array_file['filename'] ) ) )
  24. {
  25. $errorfile .= '<span style="color:red">' . $array_file['filename'] . '</span><br />';
  26. }
  27. }
  28. }
  29. if ( ! empty( $errorfile ) )
  30. {
  31. echo '<div id="message" style="display:none;text-align:center;color:red"><img src="' . NV_BASE_SITEURL . 'images/load_bar.gif" alt="" />' . $lang_module['autoinstall_package_processing'] . '</div>';
  32. echo '<strong>' . $lang_module['autoinstall_theme_error_warning_fileexist'] . '</strong>';
  33. echo '<hr /><div style="overflow:auto;height:200px;width:700px">' . $errorfile . '</div>';
  34. echo '<br /><b>' . $lang_module['autoinstall_theme_error_warning_overwrite'] . '</b>';
  35. echo '<br /><input style="margin-top:10px;font-size:15px" type="button" name="install_content_overwrite" value="' . $lang_module['autoinstall_theme_overwrite'] . '"/>';
  36. echo '<script type="text/javascript">
  37. //<![CDATA[
  38. $(function(){
  39. $("input[name=install_content_overwrite]").click(function(){
  40. if(confirm("' . $lang_module['autoinstall_theme_error_warning_overwrite'] . '")){
  41. $("#message").show();
  42. $("#step1").html("");
  43. $("#step1").load("' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $op . '&overwrite=' . md5( $filename . $global_config['sitekey'] . session_id() ) . '",function(){
  44. $("#message").hide();
  45. });
  46. }
  47. });
  48. });
  49. //]]>
  50. </script>';
  51. }
  52. else
  53. {
  54. $temp_extract_dir = NV_TEMP_DIR . '/' . md5( $filename . $global_config['sitekey'] . session_id() );
  55. if ( NV_ROOTDIR . '/' . $temp_extract_dir )
  56. {
  57. nv_deletefile( NV_ROOTDIR . '/' . $temp_extract_dir, true );
  58. }
  59. $ftp_check_login = 0;
  60. if ( $sys_info['ftp_support'] and intval( $global_config['ftp_check_login'] ) == 1 )
  61. {
  62. $ftp_server = nv_unhtmlspecialchars( $global_config['ftp_server'] );
  63. $ftp_port = intval( $global_config['ftp_port'] );
  64. $ftp_user_name = nv_unhtmlspecialchars( $global_config['ftp_user_name'] );
  65. $ftp_user_pass = nv_unhtmlspecialchars( $global_config['ftp_user_pass'] );
  66. $ftp_path = nv_unhtmlspecialchars( $global_config['ftp_path'] );
  67. // set up basic connection
  68. $conn_id = ftp_connect( $ftp_server, $ftp_port, 10 );
  69. // login with username and password
  70. $login_result = ftp_login( $conn_id, $ftp_user_name, $ftp_user_pass );
  71. if ( ( ! $conn_id ) || ( ! $login_result ) )
  72. {
  73. $ftp_check_login = 3;
  74. }
  75. elseif ( ftp_chdir( $conn_id, $ftp_path ) )
  76. {
  77. $ftp_check_login = 1;
  78. }
  79. else
  80. {
  81. $ftp_check_login = 2;
  82. }
  83. }
  84. if ( $ftp_check_login == 1 )
  85. {
  86. ftp_mkdir( $conn_id, $temp_extract_dir );
  87. if ( substr( $sys_info['os'], 0, 3 ) != 'WIN' ) ftp_chmod( $conn_id, 0777, $temp_extract_dir );
  88. foreach ( $ziplistContent as $array_file )
  89. {
  90. if ( ! empty( $array_file['folder'] ) and ! file_exists( NV_ROOTDIR . '/' . $temp_extract_dir . '/' . $array_file['filename'] ) )
  91. {
  92. $cp = "";
  93. $e = explode( "/", $array_file['filename'] );
  94. foreach ( $e as $p )
  95. {
  96. if ( ! empty( $p ) and ! is_dir( NV_ROOTDIR . '/' . $temp_extract_dir . '/' . $cp . $p ) )
  97. {
  98. ftp_mkdir( $conn_id, $temp_extract_dir . '/' . $cp . $p );
  99. if ( substr( $sys_info['os'], 0, 3 ) != 'WIN' ) ftp_chmod( $conn_id, 0777, $temp_extract_dir . '/' . $cp . $p );
  100. }
  101. $cp .= $p . '/';
  102. }
  103. }
  104. }
  105. }
  106. $no_extract = array();
  107. $extract = $zip->extract( PCLZIP_OPT_PATH, NV_ROOTDIR . '/' . $temp_extract_dir );
  108. foreach ( $extract as $extract_i )
  109. {
  110. $filename_i = str_replace( NV_ROOTDIR, "", str_replace( '\\', '/', $extract_i['filename'] ) );
  111. if ( $extract_i['status'] != 'ok' and $extract_i['status'] != 'already_a_directory' )
  112. {
  113. $no_extract[] = $filename_i;
  114. }
  115. }
  116. if ( empty( $no_extract ) )
  117. {
  118. $error_create_folder = array();
  119. foreach ( $ziplistContent as $array_file )
  120. {
  121. $dir_name = "";
  122. if ( ! empty( $array_file['folder'] ) and ! file_exists( NV_ROOTDIR . '/' . $array_file['filename'] ) )
  123. {
  124. $dir_name = $array_file['filename'];
  125. }
  126. elseif ( ! file_exists( NV_ROOTDIR . '/' . dirname( $array_file['filename'] ) ) )
  127. {
  128. $dir_name = dirname( $array_file['filename'] );
  129. }
  130. if ( ! empty( $dir_name ) )
  131. {
  132. $cp = "";
  133. $e = explode( "/", $dir_name );
  134. foreach ( $e as $p )
  135. {
  136. if ( ! empty( $p ) and ! is_dir( NV_ROOTDIR . '/themes/' . $cp . $p ) )
  137. {
  138. if ( ! ( $ftp_check_login == 1 and ftp_mkdir( $conn_id, 'themes/' . $cp . $p ) ) )
  139. {
  140. @mkdir( NV_ROOTDIR . '/themes/' . $cp . $p );
  141. }
  142. if ( ! is_dir( NV_ROOTDIR . '/themes/' . $cp . $p ) )
  143. {
  144. $error_create_folder[] = 'themes/' . $cp . $p;
  145. }
  146. }
  147. $cp .= $p . '/';
  148. }
  149. }
  150. }
  151. $error_create_folder = array_unique( $error_create_folder );
  152. if ( ! empty( $error_create_folder ) )
  153. {
  154. asort( $error_create_folder );
  155. echo "<b>" . $lang_module['autoinstall_theme_permission_folder'] . "</b>:<br /> " . implode( "<br />", $error_create_folder );
  156. }
  157. else
  158. {
  159. $error_move_folder = array();
  160. foreach ( $ziplistContent as $array_file )
  161. {
  162. if ( empty( $array_file['folder'] ) )
  163. {
  164. if ( file_exists( NV_ROOTDIR . '/themes/' . $array_file['filename'] ) )
  165. {
  166. if ( ! ( $ftp_check_login == 1 and ftp_delete( $conn_id, 'themes/' . $array_file['filename'] ) ) )
  167. {
  168. nv_deletefile( NV_ROOTDIR . '/themes/' . $array_file['filename'] );
  169. }
  170. }
  171. if ( ! ( $ftp_check_login == 1 and ftp_rename( $conn_id, $temp_extract_dir . '/' . $array_file['filename'], 'themes/' . $array_file['filename'] ) ) )
  172. {
  173. @rename( NV_ROOTDIR . '/' . $temp_extract_dir . '/' . $array_file['filename'], NV_ROOTDIR . '/themes/' . $array_file['filename'] );
  174. }
  175. if ( file_exists( NV_ROOTDIR . '/' . $temp_extract_dir . '/' . $array_file['filename'] ) )
  176. {
  177. $error_move_folder[] = $array_file['filename'];
  178. }
  179. }
  180. }
  181. if ( empty( $error_move_folder ) )
  182. {
  183. nv_deletefile( $filename );
  184. nv_deletefile( NV_ROOTDIR . '/' . $temp_extract_dir, true );
  185. $theme = substr( $ziplistContent[0]['filename'], 0, - 1 );
  186. $nv_redirect = NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=setuplayout&selectthemes=' . $theme;
  187. echo "<br /><b>" . $lang_module['autoinstall_theme_unzip_success'] . "</b><br />";
  188. echo "<br /><br /><center><a href=\"" . $nv_redirect . "\">" . $lang_module['autoinstall_module_unzip_setuppage'] . "</a></center>";
  189. echo '<script type="text/javascript">
  190. //<![CDATA[
  191. setTimeout("redirect_page()",5000);
  192. function redirect_page()
  193. {
  194. parent.location="' . $nv_redirect . '";
  195. }
  196. //]]>
  197. </script>';
  198. }
  199. else
  200. {
  201. asort( $error_move_folder );
  202. echo "<b>" . $lang_module['autoinstall_theme_error_movefile'] . ":</b> <br />" . implode( "<br />", $error_move_folder );
  203. }
  204. }
  205. }
  206. else
  207. {
  208. echo $lang_module['autoinstall_theme_cantunzip'];
  209. echo '<div id="message" style="display:none;text-align:center;color:red"><img src="' . NV_BASE_SITEURL . 'images/load_bar.gif" alt="" />' . $lang_module['autoinstall_package_processing'] . '</div>';
  210. echo '<input style="margin-top:10px;font-size:15px" type="button" name="checkfile" value="' . $lang_module['autoinstall_theme_checkfile'] . '"/>';
  211. echo '<script type="text/javascript">
  212. $(function(){
  213. //<![CDATA[
  214. $("input[name=checkfile]").click(function(){
  215. $("#message").show();
  216. $("#step1").html("");
  217. $("#step1").load("' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=install_check",function(){
  218. $("#message").hide();
  219. });
  220. });
  221. });
  222. //]]>
  223. </script>';
  224. }
  225. }
  226. }
  227. ?>