PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/modules/webtools/checkupdate.php

http://viet-group.googlecode.com/
PHP | 327 lines | 266 code | 49 blank | 12 comment | 39 complexity | a6f37fd0a8d699de9d06556c88a1a41c 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 21/12/2010, 8:10
  7. */
  8. if ( ! defined( 'NV_IS_FILE_WEBTOOLS' ) ) die( 'Stop!!!' );
  9. /**
  10. * nv_getModVersion()
  11. *
  12. * @param integer $updatetime
  13. * @return
  14. */
  15. function nv_getModVersion( $updatetime = 3600 )
  16. {
  17. global $global_config;
  18. $my_file = NV_ROOTDIR . '/' . NV_CACHEDIR . '/modules.version.' . NV_LANG_INTERFACE . '.xml';
  19. $xmlcontent = false;
  20. $p = NV_CURRENTTIME - $updatetime;
  21. if ( file_exists( $my_file ) and @filemtime( $my_file ) > $p )
  22. {
  23. $xmlcontent = simplexml_load_file( $my_file );
  24. }
  25. else
  26. {
  27. include ( NV_ROOTDIR . "/includes/class/geturl.class.php" );
  28. $getContent = new UrlGetContents( $global_config );
  29. $nv_sites = array( //
  30. 'update.nukeviet.vn', //
  31. 'update2.nukeviet.vn', //
  32. 'update.nukeviet.info', //
  33. 'update2.nukeviet.info' );
  34. $content = nv_rand_getVersion( $nv_sites, $getContent, true );
  35. if ( ! empty( $content ) )
  36. {
  37. $xmlcontent = simplexml_load_string( $content );
  38. if ( $xmlcontent !== false )
  39. {
  40. file_put_contents( $my_file, $content );
  41. }
  42. }
  43. }
  44. return $xmlcontent;
  45. }
  46. $page_title = $lang_module['checkupdate'];
  47. $contents = "";
  48. $xtpl = new XTemplate( "checkupdate.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  49. $xtpl->assign( 'NV_NAME_VARIABLE', NV_NAME_VARIABLE );
  50. $xtpl->assign( 'NV_OP_VARIABLE', NV_OP_VARIABLE );
  51. $xtpl->assign( 'LANG', $lang_module );
  52. if ( $nv_Request->isset_request( 'i', 'get' ) )
  53. {
  54. $i = $nv_Request->get_string( 'i', 'get' );
  55. if ( $i == 'sysUpd' or $i == 'sysUpdRef' )
  56. {
  57. $values = array();
  58. $values['userVersion'] = $global_config['version'];
  59. $new_version = ( $i == 'sysUpd' ) ? nv_geVersion( 28800 ) : nv_geVersion( 120 );
  60. $values['onlineVersion'] = sprintf( $lang_module['newVersion_detail'], ( string )$new_version->version, ( string )$new_version->name, nv_date( "d-m-Y H:i", strtotime( $new_version->date ) ) );
  61. $xtpl->assign( 'VALUE', $values );
  62. if ( nv_version_compare( $global_config['version'], $new_version->version ) < 0 )
  63. {
  64. $xtpl->assign( 'VERSION_INFO', ( string )$new_version->message );
  65. $xtpl->assign( 'VERSION_LINK', sprintf( $lang_module['newVersion_info'], ( string )$new_version->link ) );
  66. $xtpl->parse( 'sysUpd.inf' );
  67. }
  68. clearstatcache();
  69. $sysUpdDate = filemtime( NV_ROOTDIR . '/' . NV_CACHEDIR . '/nukeviet.version.' . NV_LANG_INTERFACE . '.xml' );
  70. $xtpl->assign( 'SYSUPDDATE', nv_date( "d-m-Y H:i", $sysUpdDate ) );
  71. $xtpl->parse( 'sysUpd' );
  72. echo $xtpl->text( 'sysUpd' );
  73. } elseif ( $i == "modUpd" or $i == "modUpdRef" or $i == "modNewUpd" or $i == "modNewUpdRef" )
  74. {
  75. $_modules = ( $i == 'modUpd' or $i == "modNewUpd" ) ? nv_getModVersion( 28800 ) : nv_getModVersion( 120 );
  76. $_modules = nv_object2array( $_modules );
  77. $_modules = $_modules['module'];
  78. $onlineModules = array();
  79. foreach ( $_modules as $m )
  80. {
  81. $name = array_shift( $m );
  82. $onlineModules[$name] = $m;
  83. unset( $onlineModules[$name]['date'] );
  84. $onlineModules[$name]['pubtime'] = strtotime( $m['date'] );
  85. }
  86. $userModules = array();
  87. $sql = "SELECT `module_file`, `mod_version`, `author` FROM `" . $db_config['prefix'] . "_setup_modules` GROUP BY `module_file` ORDER BY `module_file` ASC";
  88. $result = $db->sql_query( $sql );
  89. while ( list( $module_file, $mod_version, $author ) = $db->sql_fetchrow( $result ) )
  90. {
  91. $userModules[$module_file] = array();
  92. $v = "";
  93. $p = 0;
  94. unset( $matches );
  95. if ( preg_match( "/^([^\s]+)\s+([\d]+)$/", $mod_version, $matches ) )
  96. {
  97. $v = ( string )$matches[1];
  98. $p = ( int )$matches[2];
  99. }
  100. if ( isset( $onlineModules[$module_file] ) )
  101. {
  102. $userModules[$module_file] = $onlineModules[$module_file];
  103. if ( isset( $onlineModules[$module_file]['pubtime'], $onlineModules[$module_file]['version'], $onlineModules[$module_file]['author'] ) //
  104. and $onlineModules[$module_file]['version'] == $v //
  105. and ( $onlineModules[$module_file]['pubtime'] != $p or $onlineModules[$module_file]['author'] != $author ) )
  106. {
  107. $sql2 = "UPDATE `" . $db_config['prefix'] . "_setup_modules`
  108. SET `mod_version`=" . $db->dbescape( $v . ' ' . $onlineModules[$module_file]['pubtime'] ) . ",
  109. `author`=" . $db->dbescape( $onlineModules[$module_file]['author'] ) . "
  110. WHERE `module_file`=" . $db->dbescape( $module_file );
  111. $db->sql_query( $sql2 );
  112. }
  113. }
  114. $userModules[$module_file]['u_version'] = $v;
  115. $userModules[$module_file]['u_pubtime'] = $p;
  116. }
  117. $newModules = array_diff_key( $onlineModules, $userModules );
  118. clearstatcache();
  119. $modUpdDate = filemtime( NV_ROOTDIR . '/' . NV_CACHEDIR . '/modules.version.' . NV_LANG_INTERFACE . '.xml' );
  120. if ( $i != "modNewUpd" and $i != "modNewUpdRef" )
  121. {
  122. $a = 1;
  123. foreach ( $userModules as $modname => $values )
  124. {
  125. if ( ! isset( $values['version'] ) )
  126. {
  127. $note = $lang_module['moduleNote1'];
  128. $cl = "Note1";
  129. } elseif ( empty( $values['u_version'] ) )
  130. {
  131. $note = sprintf( $lang_module['moduleNote3'], $values['link'] );
  132. $cl = "Note3";
  133. } elseif ( nv_version_compare( $values['u_version'], $values['version'] ) < 0 )
  134. {
  135. $note = sprintf( $lang_module['moduleNote4'], $values['link'] );
  136. $cl = "Note4";
  137. }
  138. else
  139. {
  140. $note = $lang_module['moduleNote5'];
  141. $cl = "Note5";
  142. }
  143. $info = $lang_module['userVersion'] . ": ";
  144. $info .= ! empty( $values['u_version'] ) ? $values['u_version'] : "n/a";
  145. $info .= "; " . $lang_module['onlineVersion'] . ": ";
  146. $info .= ! empty( $values['version'] ) ? $values['version'] : "n/a";
  147. $tooltip = array();
  148. $tooltip[] = array( //
  149. 'title' => $lang_module['userVersion'], //
  150. 'content' => ( ! empty( $values['u_version'] ) ? $values['u_version'] : "n/a" ) . ( ! empty( $values['u_pubtime'] ) ? " (" . nv_date( "d-m-Y H:i", $values['u_pubtime'] ) . ")" : "" ) //
  151. );
  152. $tooltip[] = array( //
  153. 'title' => $lang_module['onlineVersion'], //
  154. 'content' => ( ! empty( $values['version'] ) ? $values['version'] : "n/a" ) . ( ! empty( $values['pubtime'] ) ? " (" . nv_date( "d-m-Y H:i", $values['pubtime'] ) . ")" : "" ) //
  155. );
  156. if ( isset( $values['author'] ) and ! empty( $values['author'] ) )
  157. {
  158. $tooltip[] = array( //
  159. 'title' => $lang_module['moduleAuthor'], //
  160. 'content' => $values['author'] //
  161. );
  162. }
  163. if ( isset( $values['license'] ) and ! empty( $values['license'] ) )
  164. {
  165. $tooltip[] = array( //
  166. 'title' => $lang_module['moduleLicense'], //
  167. 'content' => $values['license'] //
  168. );
  169. }
  170. if ( isset( $values['mode'] ) and ! empty( $values['mode'] ) )
  171. {
  172. $tooltip[] = array( //
  173. 'title' => $lang_module['moduleMode'], //
  174. 'content' => $values['mode'] == "sys" ? $lang_module['moduleModeSys'] : $lang_module['moduleModeOther'] //
  175. );
  176. }
  177. if ( isset( $values['link'] ) and ! empty( $values['link'] ) )
  178. {
  179. $tooltip[] = array( //
  180. 'title' => $lang_module['moduleLink'], //
  181. 'content' => "<a href=\"" . $values['link'] . "\">" . $values['link'] . "</a>" //
  182. );
  183. }
  184. if ( isset( $values['support'] ) and ! empty( $values['support'] ) )
  185. {
  186. $tooltip[] = array( //
  187. 'title' => $lang_module['moduleSupport'], //
  188. 'content' => "<a href=\"" . $values['support'] . "\">" . $values['support'] . "</a>" //
  189. );
  190. }
  191. $xtpl->assign( 'CLASS', ( $a % 2 ) ? " class=\"second\"" : "" );
  192. $xtpl->assign( 'MODNAME', $modname );
  193. $xtpl->assign( 'MODINFO', $info );
  194. foreach ( $tooltip as $t )
  195. {
  196. $xtpl->assign( 'MODTOOLTIP', $t );
  197. $xtpl->parse( 'modUpd.loop.li' );
  198. }
  199. if ( ! isset( $values['version'] ) )
  200. {
  201. $xtpl->parse( 'modUpd.loop.note1' );
  202. }
  203. $xtpl->assign( 'MODCL', $cl );
  204. $xtpl->assign( 'MODNOTE', $note );
  205. $xtpl->parse( 'modUpd.loop' );
  206. $a++;
  207. }
  208. $xtpl->assign( 'MODUPDDATE', nv_date( "d-m-Y H:i", $modUpdDate ) );
  209. if ( ! empty( $newModules ) )
  210. {
  211. $xtpl->parse( 'modUpd.newMods' );
  212. }
  213. $xtpl->parse( 'modUpd' );
  214. echo $xtpl->text( 'modUpd' );
  215. }
  216. else
  217. {
  218. $a = 1;
  219. foreach ( $newModules as $modname => $values )
  220. {
  221. $tooltip = array();
  222. $tooltip[] = array( //
  223. 'title' => $lang_module['onlineVersion'], //
  224. 'content' => ( ! empty( $values['version'] ) ? $values['version'] : "n/a" ) . ( ! empty( $values['pubtime'] ) ? " (" . nv_date( "d-m-Y H:i", $values['pubtime'] ) . ")" : "" ) //
  225. );
  226. if ( isset( $values['author'] ) and ! empty( $values['author'] ) )
  227. {
  228. $tooltip[] = array( //
  229. 'title' => $lang_module['moduleAuthor'], //
  230. 'content' => $values['author'] //
  231. );
  232. }
  233. if ( isset( $values['license'] ) and ! empty( $values['license'] ) )
  234. {
  235. $tooltip[] = array( //
  236. 'title' => $lang_module['moduleLicense'], //
  237. 'content' => $values['license'] //
  238. );
  239. }
  240. if ( isset( $values['link'] ) and ! empty( $values['link'] ) )
  241. {
  242. $modname = "<a href=\"" . $values['link'] . "\" title=\"" . $lang_module['moduleNote2'] . "\">" . $modname . "</a>";
  243. $tooltip[] = array( //
  244. 'title' => $lang_module['moduleLink'], //
  245. 'content' => "<a href=\"" . $values['link'] . "\">" . $values['link'] . "</a>" //
  246. );
  247. }
  248. if ( isset( $values['support'] ) and ! empty( $values['support'] ) )
  249. {
  250. $tooltip[] = array( //
  251. 'title' => $lang_module['moduleSupport'], //
  252. 'content' => "<a href=\"" . $values['support'] . "\">" . $values['support'] . "</a>" //
  253. );
  254. }
  255. $xtpl->assign( 'CLASS', ( $a % 2 ) ? " class=\"second\"" : "" );
  256. $xtpl->assign( 'MODNAME', $modname );
  257. $xtpl->assign( 'MODINFO', $values['message'] );
  258. $xtpl->assign( 'MODUPDDATE', nv_date( "d-m-Y H:i", $modUpdDate ) );
  259. foreach ( $tooltip as $t )
  260. {
  261. $xtpl->assign( 'MODTOOLTIP', $t );
  262. $xtpl->parse( 'modsNew.loop.li' );
  263. }
  264. $xtpl->parse( 'modsNew.loop' );
  265. $a++;
  266. }
  267. $xtpl->parse( 'modsNew' );
  268. echo $xtpl->text( 'modsNew' );
  269. }
  270. }
  271. die();
  272. }
  273. $xtpl->parse( 'main' );
  274. $contents = $xtpl->text( 'main' );
  275. include ( NV_ROOTDIR . "/includes/header.php" );
  276. echo nv_admin_theme( $contents );
  277. include ( NV_ROOTDIR . "/includes/footer.php" );
  278. ?>