PageRenderTime 97ms CodeModel.GetById 40ms RepoModel.GetById 1ms app.codeStats 0ms

/install/include/install_function.php

https://github.com/kuaileshike/upload
PHP | 1715 lines | 1497 code | 200 blank | 18 comment | 323 complexity | fcf500b8b568f03eb7e9be89524460d8 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: install_function.php 29252 2012-03-31 02:03:00Z chenmengshu $
  7. */
  8. if(!defined('IN_COMSENZ')) {
  9. exit('Access Denied');
  10. }
  11. function show_msg($error_no, $error_msg = 'ok', $success = 1, $quit = TRUE) {
  12. if(VIEW_OFF) {
  13. $error_code = $success ? 0 : constant(strtoupper($error_no));
  14. $error_msg = empty($error_msg) ? $error_no : $error_msg;
  15. $error_msg = str_replace('"', '\"', $error_msg);
  16. $str = "<root>\n";
  17. $str .= "\t<error errorCode=\"$error_code\" errorMessage=\"$error_msg\" />\n";
  18. $str .= "</root>";
  19. echo $str;
  20. exit;
  21. } else {
  22. show_header();
  23. global $step;
  24. $title = lang($error_no);
  25. $comment = lang($error_no.'_comment', false);
  26. $errormsg = '';
  27. if($error_msg) {
  28. if(!empty($error_msg)) {
  29. foreach ((array)$error_msg as $k => $v) {
  30. if(is_numeric($k)) {
  31. $comment .= "<li><em class=\"red\">".lang($v)."</em></li>";
  32. }
  33. }
  34. }
  35. }
  36. if($step > 0) {
  37. echo "<div class=\"desc\"><b>$title</b><ul>$comment</ul>";
  38. } else {
  39. echo "</div><div class=\"main\" style=\"margin-top: -123px;\"><b>$title</b><ul style=\"line-height: 200%; margin-left: 30px;\">$comment</ul>";
  40. }
  41. if($quit) {
  42. echo '<br /><span class="red">'.lang('error_quit_msg').'</span><br /><br /><br />';
  43. }
  44. echo '<input type="button" onclick="history.back()" value="'.lang('click_to_back').'" /><br /><br /><br />';
  45. echo '</div>';
  46. $quit && show_footer();
  47. }
  48. }
  49. function check_db($dbhost, $dbuser, $dbpw, $dbname, $tablepre) {
  50. if(!function_exists('mysql_connect')) {
  51. show_msg('undefine_func', 'mysql_connect', 0);
  52. }
  53. if(!@mysql_connect($dbhost, $dbuser, $dbpw)) {
  54. $errno = mysql_errno();
  55. $error = mysql_error();
  56. if($errno == 1045) {
  57. show_msg('database_errno_1045', $error, 0);
  58. } elseif($errno == 2003) {
  59. show_msg('database_errno_2003', $error, 0);
  60. } else {
  61. show_msg('database_connect_error', $error, 0);
  62. }
  63. } else {
  64. if($query = @mysql_query("SHOW TABLES FROM $dbname")) {
  65. while($row = mysql_fetch_row($query)) {
  66. if(preg_match("/^$tablepre/", $row[0])) {
  67. return false;
  68. }
  69. }
  70. }
  71. }
  72. return true;
  73. }
  74. function dirfile_check(&$dirfile_items) {
  75. foreach($dirfile_items as $key => $item) {
  76. $item_path = $item['path'];
  77. if($item['type'] == 'dir') {
  78. if(!dir_writeable(ROOT_PATH.$item_path)) {
  79. if(is_dir(ROOT_PATH.$item_path)) {
  80. $dirfile_items[$key]['status'] = 0;
  81. $dirfile_items[$key]['current'] = '+r';
  82. } else {
  83. $dirfile_items[$key]['status'] = -1;
  84. $dirfile_items[$key]['current'] = 'nodir';
  85. }
  86. } else {
  87. $dirfile_items[$key]['status'] = 1;
  88. $dirfile_items[$key]['current'] = '+r+w';
  89. }
  90. } else {
  91. if(file_exists(ROOT_PATH.$item_path)) {
  92. if(is_writable(ROOT_PATH.$item_path)) {
  93. $dirfile_items[$key]['status'] = 1;
  94. $dirfile_items[$key]['current'] = '+r+w';
  95. } else {
  96. $dirfile_items[$key]['status'] = 0;
  97. $dirfile_items[$key]['current'] = '+r';
  98. }
  99. } else {
  100. if(dir_writeable(dirname(ROOT_PATH.$item_path))) {
  101. $dirfile_items[$key]['status'] = 1;
  102. $dirfile_items[$key]['current'] = '+r+w';
  103. } else {
  104. $dirfile_items[$key]['status'] = -1;
  105. $dirfile_items[$key]['current'] = 'nofile';
  106. }
  107. }
  108. }
  109. }
  110. }
  111. function env_check(&$env_items) {
  112. foreach($env_items as $key => $item) {
  113. if($key == 'php') {
  114. $env_items[$key]['current'] = PHP_VERSION;
  115. } elseif($key == 'attachmentupload') {
  116. $env_items[$key]['current'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknow';
  117. } elseif($key == 'gdversion') {
  118. $tmp = function_exists('gd_info') ? gd_info() : array();
  119. $env_items[$key]['current'] = empty($tmp['GD Version']) ? 'noext' : $tmp['GD Version'];
  120. unset($tmp);
  121. } elseif($key == 'diskspace') {
  122. if(function_exists('disk_free_space')) {
  123. $env_items[$key]['current'] = floor(disk_free_space(ROOT_PATH) / (1024*1024)).'M';
  124. } else {
  125. $env_items[$key]['current'] = 'unknow';
  126. }
  127. } elseif(isset($item['c'])) {
  128. $env_items[$key]['current'] = constant($item['c']);
  129. }
  130. $env_items[$key]['status'] = 1;
  131. if($item['r'] != 'notset' && strcmp($env_items[$key]['current'], $item['r']) < 0) {
  132. $env_items[$key]['status'] = 0;
  133. }
  134. }
  135. }
  136. function function_check(&$func_items) {
  137. foreach($func_items as $item) {
  138. function_exists($item) or show_msg('undefine_func', $item, 0);
  139. }
  140. }
  141. function show_env_result(&$env_items, &$dirfile_items, &$func_items, &$filesock_items) {
  142. $env_str = $file_str = $dir_str = $func_str = '';
  143. $error_code = 0;
  144. foreach($env_items as $key => $item) {
  145. if($key == 'php' && strcmp($item['current'], $item['r']) < 0) {
  146. show_msg('php_version_too_low', $item['current'], 0);
  147. }
  148. $status = 1;
  149. if($item['r'] != 'notset') {
  150. if(intval($item['current']) && intval($item['r'])) {
  151. if(intval($item['current']) < intval($item['r'])) {
  152. $status = 0;
  153. $error_code = ENV_CHECK_ERROR;
  154. }
  155. } else {
  156. if(strcmp($item['current'], $item['r']) < 0) {
  157. $status = 0;
  158. $error_code = ENV_CHECK_ERROR;
  159. }
  160. }
  161. }
  162. if(VIEW_OFF) {
  163. $env_str .= "\t\t<runCondition name=\"$key\" status=\"$status\" Require=\"$item[r]\" Best=\"$item[b]\" Current=\"$item[current]\"/>\n";
  164. } else {
  165. $env_str .= "<tr>\n";
  166. $env_str .= "<td>".lang($key)."</td>\n";
  167. $env_str .= "<td class=\"padleft\">".lang($item['r'])."</td>\n";
  168. $env_str .= "<td class=\"padleft\">".lang($item['b'])."</td>\n";
  169. $env_str .= ($status ? "<td class=\"w pdleft1\">" : "<td class=\"nw pdleft1\">").$item['current']."</td>\n";
  170. $env_str .= "</tr>\n";
  171. }
  172. }
  173. foreach($dirfile_items as $key => $item) {
  174. $tagname = $item['type'] == 'file' ? 'File' : 'Dir';
  175. $variable = $item['type'].'_str';
  176. if(VIEW_OFF) {
  177. if($item['status'] == 0) {
  178. $error_code = ENV_CHECK_ERROR;
  179. }
  180. $$variable .= "\t\t\t<File name=\"$item[path]\" status=\"$item[status]\" requirePermisson=\"+r+w\" currentPermisson=\"$item[current]\" />\n";
  181. } else {
  182. $$variable .= "<tr>\n";
  183. $$variable .= "<td>$item[path]</td><td class=\"w pdleft1\">".lang('writeable')."</td>\n";
  184. if($item['status'] == 1) {
  185. $$variable .= "<td class=\"w pdleft1\">".lang('writeable')."</td>\n";
  186. } elseif($item['status'] == -1) {
  187. $error_code = ENV_CHECK_ERROR;
  188. $$variable .= "<td class=\"nw pdleft1\">".lang('nodir')."</td>\n";
  189. } else {
  190. $error_code = ENV_CHECK_ERROR;
  191. $$variable .= "<td class=\"nw pdleft1\">".lang('unwriteable')."</td>\n";
  192. }
  193. $$variable .= "</tr>\n";
  194. }
  195. }
  196. if(VIEW_OFF) {
  197. $str = "<root>\n";
  198. $str .= "\t<runConditions>\n";
  199. $str .= $env_str;
  200. $str .= "\t</runConditions>\n";
  201. $str .= "\t<FileDirs>\n";
  202. $str .= "\t\t<Dirs>\n";
  203. $str .= $dir_str;
  204. $str .= "\t\t</Dirs>\n";
  205. $str .= "\t\t<Files>\n";
  206. $str .= $file_str;
  207. $str .= "\t\t</Files>\n";
  208. $str .= "\t</FileDirs>\n";
  209. $str .= "\t<error errorCode=\"$error_code\" errorMessage=\"\" />\n";
  210. $str .= "</root>";
  211. echo $str;
  212. exit;
  213. } else {
  214. show_header();
  215. echo "<h2 class=\"title\">".lang('env_check')."</h2>\n";
  216. echo "<table class=\"tb\" style=\"margin:20px 0 20px 55px;\">\n";
  217. echo "<tr>\n";
  218. echo "\t<th>".lang('project')."</th>\n";
  219. echo "\t<th class=\"padleft\">".lang('ucenter_required')."</th>\n";
  220. echo "\t<th class=\"padleft\">".lang('ucenter_best')."</th>\n";
  221. echo "\t<th class=\"padleft\">".lang('curr_server')."</th>\n";
  222. echo "</tr>\n";
  223. echo $env_str;
  224. echo "</table>\n";
  225. echo "<h2 class=\"title\">".lang('priv_check')."</h2>\n";
  226. echo "<table class=\"tb\" style=\"margin:20px 0 20px 55px;width:90%;\">\n";
  227. echo "\t<tr>\n";
  228. echo "\t<th>".lang('step1_file')."</th>\n";
  229. echo "\t<th class=\"padleft\">".lang('step1_need_status')."</th>\n";
  230. echo "\t<th class=\"padleft\">".lang('step1_status')."</th>\n";
  231. echo "</tr>\n";
  232. echo $file_str;
  233. echo $dir_str;
  234. echo "</table>\n";
  235. foreach($func_items as $item) {
  236. $status = function_exists($item);
  237. $func_str .= "<tr>\n";
  238. $func_str .= "<td>$item()</td>\n";
  239. if($status) {
  240. $func_str .= "<td class=\"w pdleft1\">".lang('supportted')."</td>\n";
  241. $func_str .= "<td class=\"padleft\">".lang('none')."</td>\n";
  242. } else {
  243. $error_code = ENV_CHECK_ERROR;
  244. $func_str .= "<td class=\"nw pdleft1\">".lang('unsupportted')."</td>\n";
  245. $func_str .= "<td><font color=\"red\">".lang('advice_'.$item)."</font></td>\n";
  246. }
  247. }
  248. $func_strextra = '';
  249. $filesock_disabled = 0;
  250. foreach($filesock_items as $item) {
  251. $status = function_exists($item);
  252. $func_strextra .= "<tr>\n";
  253. $func_strextra .= "<td>$item()</td>\n";
  254. if($status) {
  255. $func_strextra .= "<td class=\"w pdleft1\">".lang('supportted')."</td>\n";
  256. $func_strextra .= "<td class=\"padleft\">".lang('none')."</td>\n";
  257. break;
  258. } else {
  259. $filesock_disabled++;
  260. $func_strextra .= "<td class=\"nw pdleft1\">".lang('unsupportted')."</td>\n";
  261. $func_strextra .= "<td><font color=\"red\">".lang('advice_'.$item)."</font></td>\n";
  262. }
  263. }
  264. if($filesock_disabled == count($filesock_items)) {
  265. $error_code = ENV_CHECK_ERROR;
  266. }
  267. echo "<h2 class=\"title\">".lang('func_depend')."</h2>\n";
  268. echo "<table class=\"tb\" style=\"margin:20px 0 20px 55px;width:90%;\">\n";
  269. echo "<tr>\n";
  270. echo "\t<th>".lang('func_name')."</th>\n";
  271. echo "\t<th class=\"padleft\">".lang('check_result')."</th>\n";
  272. echo "\t<th class=\"padleft\">".lang('suggestion')."</th>\n";
  273. echo "</tr>\n";
  274. echo $func_str.$func_strextra;
  275. echo "</table>\n";
  276. show_next_step(2, $error_code);
  277. show_footer();
  278. }
  279. }
  280. function show_next_step($step, $error_code) {
  281. global $uchidden;
  282. echo "<form action=\"index.php\" method=\"post\">\n";
  283. echo "<input type=\"hidden\" name=\"step\" value=\"$step\" />";
  284. if(isset($GLOBALS['hidden'])) {
  285. echo $GLOBALS['hidden'];
  286. }
  287. echo "<input type=\"hidden\" name=\"uchidden\" value=\"$uchidden\" />";
  288. if($error_code == 0) {
  289. $nextstep = "<input type=\"button\" onclick=\"history.back();\" value=\"".lang('old_step')."\"><input type=\"submit\" value=\"".lang('new_step')."\">\n";
  290. } else {
  291. $nextstep = "<input type=\"button\" disabled=\"disabled\" value=\"".lang('not_continue')."\">\n";
  292. }
  293. echo "<div class=\"btnbox marginbot\">".$nextstep."</div>\n";
  294. echo "</form>\n";
  295. }
  296. function show_form(&$form_items, $error_msg) {
  297. global $step, $uchidden;
  298. if(empty($form_items) || !is_array($form_items)) {
  299. return;
  300. }
  301. show_header();
  302. show_setting('start');
  303. show_setting('hidden', 'step', $step);
  304. show_setting('hidden', 'install_ucenter', getgpc('install_ucenter'));
  305. if($step == 2) {
  306. show_tips('install_dzfull');
  307. show_tips('install_dzonly');
  308. }
  309. $is_first = 1;
  310. if(!empty($uchidden)) {
  311. $uc_info_transfer = unserialize(urldecode($uchidden));
  312. }
  313. echo '<div id="form_items_'.$step.'" '.($step == 2 && !getgpc('install_ucenter') ? 'style="display:none"' : '').'><br />';
  314. foreach($form_items as $key => $items) {
  315. global ${'error_'.$key};
  316. if($is_first == 0) {
  317. echo '</table>';
  318. }
  319. if(!${'error_'.$key}) {
  320. show_tips('tips_'.$key);
  321. } else {
  322. show_error('tips_admin_config', ${'error_'.$key});
  323. }
  324. echo '<table class="tb2">';
  325. foreach($items as $k => $v) {
  326. $value = '';
  327. if(!empty($error_msg)) {
  328. $value = isset($_POST[$key][$k]) ? $_POST[$key][$k] : '';
  329. }
  330. if(empty($value)) {
  331. if(isset($v['value']) && is_array($v['value'])) {
  332. if($v['value']['type'] == 'constant') {
  333. $value = defined($v['value']['var']) ? constant($v['value']['var']) : $v['value']['var'];
  334. } else {
  335. $value = $GLOBALS[$v['value']['var']];
  336. }
  337. } else {
  338. $value = '';
  339. }
  340. }
  341. if($k == 'ucurl' && isset($uc_info_transfer['ucapi'])) {
  342. $value = $uc_info_transfer['ucapi'];
  343. } elseif($k == 'ucpw' && isset($uc_info_transfer['ucfounderpw'])) {
  344. $value = $uc_info_transfer['ucfounderpw'];
  345. } elseif($k == 'ucip') {
  346. $value = '';
  347. }
  348. show_setting($k, $key.'['.$k.']', $value, $v['type'], isset($error_msg[$key][$k]) ? $key.'_'.$k.'_invalid' : '');
  349. }
  350. if($is_first) {
  351. $is_first = 0;
  352. }
  353. }
  354. echo '</table>';
  355. echo '</div>';
  356. echo '<table class="tb2">';
  357. show_setting('', 'submitname', 'new_step', ($step == 2 ? 'submit|oldbtn' : 'submit' ));
  358. show_setting('end');
  359. show_footer();
  360. }
  361. function show_license() {
  362. global $self, $uchidden, $step;
  363. $next = $step + 1;
  364. if(VIEW_OFF) {
  365. show_msg('license_contents', lang('license'), 1);
  366. } else {
  367. show_header();
  368. $license = str_replace(' ', '&nbsp; ', lang('license'));
  369. $lang_agreement_yes = lang('agreement_yes');
  370. $lang_agreement_no = lang('agreement_no');
  371. echo <<<EOT
  372. </div>
  373. <div class="main" style="margin-top:-123px;">
  374. <div class="licenseblock">$license</div>
  375. <div class="btnbox marginbot">
  376. <form method="get" autocomplete="off" action="index.php">
  377. <input type="hidden" name="step" value="$next">
  378. <input type="hidden" name="uchidden" value="$uchidden">
  379. <input type="submit" name="submit" value="{$lang_agreement_yes}" style="padding: 2px">&nbsp;
  380. <input type="button" name="exit" value="{$lang_agreement_no}" style="padding: 2px" onclick="javascript: window.close(); return false;">
  381. </form>
  382. </div>
  383. EOT;
  384. show_footer();
  385. }
  386. }
  387. function transfer_ucinfo(&$post) {
  388. global $uchidden;
  389. if(isset($post['ucapi']) && isset($post['ucfounderpw'])) {
  390. $arr = array(
  391. 'ucapi' => $post['ucapi'],
  392. 'ucfounderpw' => $post['ucfounderpw']
  393. );
  394. $uchidden = urlencode(serialize($arr));
  395. } else {
  396. $uchidden = '';
  397. }
  398. }
  399. if(!function_exists('file_put_contents')) {
  400. function file_put_contents($filename, $s) {
  401. $fp = @fopen($filename, 'w');
  402. @fwrite($fp, $s);
  403. @fclose($fp);
  404. return TRUE;
  405. }
  406. }
  407. function createtable($sql) {
  408. $type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
  409. $type = in_array($type, array('MYISAM', 'HEAP', 'MEMORY')) ? $type : 'MYISAM';
  410. return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).
  411. (mysql_get_server_info() > '4.1' ? " ENGINE=$type DEFAULT CHARSET=".DBCHARSET : " TYPE=$type");
  412. }
  413. function dir_writeable($dir) {
  414. $writeable = 0;
  415. if(!is_dir($dir)) {
  416. @mkdir($dir, 0777);
  417. }
  418. if(is_dir($dir)) {
  419. if($fp = @fopen("$dir/test.txt", 'w')) {
  420. @fclose($fp);
  421. @unlink("$dir/test.txt");
  422. $writeable = 1;
  423. } else {
  424. $writeable = 0;
  425. }
  426. }
  427. return $writeable;
  428. }
  429. function dir_clear($dir) {
  430. global $lang;
  431. showjsmessage($lang['clear_dir'].' '.str_replace(ROOT_PATH, '', $dir));
  432. if($directory = @dir($dir)) {
  433. while($entry = $directory->read()) {
  434. $filename = $dir.'/'.$entry;
  435. if(is_file($filename)) {
  436. @unlink($filename);
  437. }
  438. }
  439. $directory->close();
  440. @touch($dir.'/index.htm');
  441. }
  442. }
  443. function show_header() {
  444. define('SHOW_HEADER', TRUE);
  445. global $step;
  446. $version = DISCUZ_VERSION;
  447. $release = DISCUZ_RELEASE;
  448. $install_lang = lang(INSTALL_LANG);
  449. $title = lang('title_install');
  450. $charset = CHARSET;
  451. echo <<<EOT
  452. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  453. <html xmlns="http://www.w3.org/1999/xhtml">
  454. <head>
  455. <meta http-equiv="Content-Type" content="text/html; charset=$charset" />
  456. <title>$title</title>
  457. <link rel="stylesheet" href="images/style.css" type="text/css" media="all" />
  458. <script type="text/javascript">
  459. function $(id) {
  460. return document.getElementById(id);
  461. }
  462. function showmessage(message) {
  463. document.getElementById('notice').innerHTML += message + '<br />';
  464. }
  465. </script>
  466. <meta content="Comsenz Inc." name="Copyright" />
  467. </head>
  468. <div class="container">
  469. <div class="header">
  470. <h1>$title</h1>
  471. <span>Discuz!$version $install_lang $release</span>
  472. EOT;
  473. $step > 0 && show_step($step);
  474. }
  475. function show_footer($quit = true) {
  476. echo <<<EOT
  477. <div class="footer">&copy;2001 - 2012 <a href="http://www.comsenz.com/">Comsenz</a> Inc.</div>
  478. </div>
  479. </div>
  480. </body>
  481. </html>
  482. EOT;
  483. $quit && exit();
  484. }
  485. function loginit($logfile) {
  486. global $lang;
  487. showjsmessage($lang['init_log'].' '.$logfile);
  488. if($fp = @fopen('./forumdata/logs/'.$logfile.'.php', 'w')) {
  489. fwrite($fp, '<'.'?PHP exit(); ?'.">\n");
  490. fclose($fp);
  491. }
  492. }
  493. function showjsmessage($message) {
  494. if(VIEW_OFF) return;
  495. echo '<script type="text/javascript">showmessage(\''.addslashes($message).' \');</script>'."\r\n";
  496. flush();
  497. ob_flush();
  498. }
  499. function random($length) {
  500. $hash = '';
  501. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  502. $max = strlen($chars) - 1;
  503. PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
  504. for($i = 0; $i < $length; $i++) {
  505. $hash .= $chars[mt_rand(0, $max)];
  506. }
  507. return $hash;
  508. }
  509. function redirect($url) {
  510. echo "<script>".
  511. "function redirect() {window.location.replace('$url');}\n".
  512. "setTimeout('redirect();', 0);\n".
  513. "</script>";
  514. exit();
  515. }
  516. function get_onlineip() {
  517. $onlineip = '';
  518. if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
  519. $onlineip = getenv('HTTP_CLIENT_IP');
  520. } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
  521. $onlineip = getenv('HTTP_X_FORWARDED_FOR');
  522. } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
  523. $onlineip = getenv('REMOTE_ADDR');
  524. } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
  525. $onlineip = $_SERVER['REMOTE_ADDR'];
  526. }
  527. return $onlineip;
  528. }
  529. function timezone_set($timeoffset = 8) {
  530. if(function_exists('date_default_timezone_set')) {
  531. @date_default_timezone_set('Etc/GMT'.($timeoffset > 0 ? '-' : '+').(abs($timeoffset)));
  532. }
  533. }
  534. function save_config_file($filename, $config, $default) {
  535. $config = setdefault($config, $default);
  536. $date = gmdate("Y-m-d H:i:s", time() + 3600 * 8);
  537. $content = <<<EOT
  538. <?php
  539. \$_config = array();
  540. EOT;
  541. $content .= getvars(array('_config' => $config));
  542. $content .= "\r\n// ".str_pad(' THE END ', 50, '-', STR_PAD_BOTH)." //\r\n\r\n?>";
  543. file_put_contents($filename, $content);
  544. }
  545. function setdefault($var, $default) {
  546. foreach ($default as $k => $v) {
  547. if(!isset($var[$k])) {
  548. $var[$k] = $default[$k];
  549. } elseif(is_array($v)) {
  550. $var[$k] = setdefault($var[$k], $default[$k]);
  551. }
  552. }
  553. return $var;
  554. }
  555. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  556. $ckey_length = 4;
  557. $key = md5($key ? $key : UC_KEY);
  558. $keya = md5(substr($key, 0, 16));
  559. $keyb = md5(substr($key, 16, 16));
  560. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
  561. $cryptkey = $keya.md5($keya.$keyc);
  562. $key_length = strlen($cryptkey);
  563. $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
  564. $string_length = strlen($string);
  565. $result = '';
  566. $box = range(0, 255);
  567. $rndkey = array();
  568. for($i = 0; $i <= 255; $i++) {
  569. $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  570. }
  571. for($j = $i = 0; $i < 256; $i++) {
  572. $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  573. $tmp = $box[$i];
  574. $box[$i] = $box[$j];
  575. $box[$j] = $tmp;
  576. }
  577. for($a = $j = $i = 0; $i < $string_length; $i++) {
  578. $a = ($a + 1) % 256;
  579. $j = ($j + $box[$a]) % 256;
  580. $tmp = $box[$a];
  581. $box[$a] = $box[$j];
  582. $box[$j] = $tmp;
  583. $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  584. }
  585. if($operation == 'DECODE') {
  586. if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
  587. return substr($result, 26);
  588. } else {
  589. return '';
  590. }
  591. } else {
  592. return $keyc.str_replace('=', '', base64_encode($result));
  593. }
  594. }
  595. function generate_key() {
  596. $random = random(32);
  597. $info = md5($_SERVER['SERVER_SOFTWARE'].$_SERVER['SERVER_NAME'].$_SERVER['SERVER_ADDR'].$_SERVER['SERVER_PORT'].$_SERVER['HTTP_USER_AGENT'].time());
  598. $return = '';
  599. for($i=0; $i<64; $i++) {
  600. $p = intval($i/2);
  601. $return[$i] = $i % 2 ? $random[$p] : $info[$p];
  602. }
  603. return implode('', $return);
  604. }
  605. function show_install() {
  606. if(VIEW_OFF) return;
  607. ?>
  608. <script type="text/javascript">
  609. function showmessage(message) {
  610. document.getElementById('notice').innerHTML += message + '<br />';
  611. document.getElementById('notice').scrollTop = 100000000;
  612. }
  613. function initinput() {
  614. window.location='index.php?method=ext_info';
  615. }
  616. </script>
  617. <div id="notice"></div>
  618. <div class="btnbox margintop marginbot">
  619. <input type="button" name="submit" value="<?php echo lang('install_in_processed');?>" disabled="disabled" id="laststep" onclick="initinput()">
  620. </div>
  621. <?php
  622. }
  623. function runquery($sql) {
  624. global $lang, $tablepre, $db;
  625. if(!isset($sql) || empty($sql)) return;
  626. $sql = str_replace("\r", "\n", str_replace(' '.ORIG_TABLEPRE, ' '.$tablepre, $sql));
  627. $sql = str_replace("\r", "\n", str_replace(' `'.ORIG_TABLEPRE, ' `'.$tablepre, $sql));
  628. $ret = array();
  629. $num = 0;
  630. foreach(explode(";\n", trim($sql)) as $query) {
  631. $ret[$num] = '';
  632. $queries = explode("\n", trim($query));
  633. foreach($queries as $query) {
  634. $ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query;
  635. }
  636. $num++;
  637. }
  638. unset($sql);
  639. foreach($ret as $query) {
  640. $query = trim($query);
  641. if($query) {
  642. if(substr($query, 0, 12) == 'CREATE TABLE') {
  643. $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
  644. showjsmessage(lang('create_table').' '.$name.' ... '.lang('succeed'));
  645. $db->query(createtable($query));
  646. } else {
  647. $db->query($query);
  648. }
  649. }
  650. }
  651. }
  652. function runucquery($sql, $tablepre) {
  653. global $lang, $db;
  654. if(!isset($sql) || empty($sql)) return;
  655. $sql = str_replace("\r", "\n", str_replace(' uc_', ' '.$tablepre, $sql));
  656. $ret = array();
  657. $num = 0;
  658. foreach(explode(";\n", trim($sql)) as $query) {
  659. $ret[$num] = '';
  660. $queries = explode("\n", trim($query));
  661. foreach($queries as $query) {
  662. $ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query;
  663. }
  664. $num++;
  665. }
  666. unset($sql);
  667. foreach($ret as $query) {
  668. $query = trim($query);
  669. if($query) {
  670. if(substr($query, 0, 12) == 'CREATE TABLE') {
  671. $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
  672. showjsmessage(lang('create_table').' '.$name.' ... '.lang('succeed'));
  673. $db->query(createtable($query));
  674. } else {
  675. $db->query($query);
  676. }
  677. }
  678. }
  679. }
  680. function charcovert($string) {
  681. if(!get_magic_quotes_gpc()) {
  682. $string = str_replace('\'', '\\\'', $string);
  683. } else {
  684. $string = str_replace('\"', '"', $string);
  685. }
  686. return $string;
  687. }
  688. function insertconfig($s, $find, $replace) {
  689. if(preg_match($find, $s)) {
  690. $s = preg_replace($find, $replace, $s);
  691. } else {
  692. $s .= "\r\n".$replace;
  693. }
  694. return $s;
  695. }
  696. function getgpc($k, $t='GP') {
  697. $t = strtoupper($t);
  698. switch($t) {
  699. case 'GP' : isset($_POST[$k]) ? $var = &$_POST : $var = &$_GET; break;
  700. case 'G': $var = &$_GET; break;
  701. case 'P': $var = &$_POST; break;
  702. case 'C': $var = &$_COOKIE; break;
  703. case 'R': $var = &$_REQUEST; break;
  704. }
  705. return isset($var[$k]) ? $var[$k] : null;
  706. }
  707. function var_to_hidden($k, $v) {
  708. return "<input type=\"hidden\" name=\"$k\" value=\"$v\" />\n";
  709. }
  710. function fsocketopen($hostname, $port = 80, &$errno, &$errstr, $timeout = 15) {
  711. $fp = '';
  712. if(function_exists('fsockopen')) {
  713. $fp = @fsockopen($hostname, $port, $errno, $errstr, $timeout);
  714. } elseif(function_exists('pfsockopen')) {
  715. $fp = @pfsockopen($hostname, $port, $errno, $errstr, $timeout);
  716. } elseif(function_exists('stream_socket_client')) {
  717. $fp = @stream_socket_client($hostname.':'.$port, $errno, $errstr, $timeout);
  718. }
  719. return $fp;
  720. }
  721. function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) {
  722. $return = '';
  723. $matches = parse_url($url);
  724. $scheme = $matches['scheme'];
  725. $host = $matches['host'];
  726. $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
  727. $port = !empty($matches['port']) ? $matches['port'] : 80;
  728. if(function_exists('curl_init') && $allowcurl) {
  729. $ch = curl_init();
  730. $ip && curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$host));
  731. curl_setopt($ch, CURLOPT_URL, $scheme.'://'.($ip ? $ip : $host).':'.$port.$path);
  732. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  733. if($post) {
  734. curl_setopt($ch, CURLOPT_POST, 1);
  735. if($encodetype == 'URLENCODE') {
  736. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  737. } else {
  738. parse_str($post, $postarray);
  739. curl_setopt($ch, CURLOPT_POSTFIELDS, $postarray);
  740. }
  741. }
  742. if($cookie) {
  743. curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  744. }
  745. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  746. $data = curl_exec($ch);
  747. $status = curl_getinfo($ch);
  748. $errno = curl_errno($ch);
  749. curl_close($ch);
  750. if($errno || $status['http_code'] != 200) {
  751. return;
  752. } else {
  753. return !$limit ? $data : substr($data, 0, $limit);
  754. }
  755. }
  756. if($post) {
  757. $out = "POST $path HTTP/1.0\r\n";
  758. $header = "Accept: */*\r\n";
  759. $header .= "Accept-Language: zh-cn\r\n";
  760. $boundary = $encodetype == 'URLENCODE' ? '' : '; boundary='.trim(substr(trim($post), 2, strpos(trim($post), "\n") - 2));
  761. $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n";
  762. $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  763. $header .= "Host: $host:$port\r\n";
  764. $header .= 'Content-Length: '.strlen($post)."\r\n";
  765. $header .= "Connection: Close\r\n";
  766. $header .= "Cache-Control: no-cache\r\n";
  767. $header .= "Cookie: $cookie\r\n\r\n";
  768. $out .= $header.$post;
  769. } else {
  770. $out = "GET $path HTTP/1.0\r\n";
  771. $header = "Accept: */*\r\n";
  772. $header .= "Accept-Language: zh-cn\r\n";
  773. $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  774. $header .= "Host: $host:$port\r\n";
  775. $header .= "Connection: Close\r\n";
  776. $header .= "Cookie: $cookie\r\n\r\n";
  777. $out .= $header;
  778. }
  779. $fpflag = 0;
  780. if(!$fp = @fsocketopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout)) {
  781. $context = array(
  782. 'http' => array(
  783. 'method' => $post ? 'POST' : 'GET',
  784. 'header' => $header,
  785. 'content' => $post,
  786. 'timeout' => $timeout,
  787. ),
  788. );
  789. $context = stream_context_create($context);
  790. $fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context);
  791. $fpflag = 1;
  792. }
  793. if(!$fp) {
  794. return '';
  795. } else {
  796. stream_set_blocking($fp, $block);
  797. stream_set_timeout($fp, $timeout);
  798. @fwrite($fp, $out);
  799. $status = stream_get_meta_data($fp);
  800. if(!$status['timed_out']) {
  801. while (!feof($fp) && !$fpflag) {
  802. if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
  803. break;
  804. }
  805. }
  806. $stop = false;
  807. while(!feof($fp) && !$stop) {
  808. $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
  809. $return .= $data;
  810. if($limit) {
  811. $limit -= strlen($data);
  812. $stop = $limit <= 0;
  813. }
  814. }
  815. }
  816. @fclose($fp);
  817. return $return;
  818. }
  819. }
  820. function check_env() {
  821. global $lang, $attachdir;
  822. $errors = array('quit' => false);
  823. $quit = false;
  824. if(!function_exists('mysql_connect')) {
  825. $errors[] = 'mysql_unsupport';
  826. $quit = true;
  827. }
  828. if(PHP_VERSION < '4.3') {
  829. $errors[] = 'php_version_430';
  830. $quit = true;
  831. }
  832. if(!file_exists(ROOT_PATH.'./config.inc.php')) {
  833. $errors[] = 'config_nonexistence';
  834. $quit = true;
  835. } elseif(!is_writeable(ROOT_PATH.'./config.inc.php')) {
  836. $errors[] = 'config_unwriteable';
  837. $quit = true;
  838. }
  839. $checkdirarray = array(
  840. 'attach' => $attachdir,
  841. 'forumdata' => './forumdata',
  842. 'cache' => './forumdata/cache',
  843. 'ftemplates' => './forumdata/templates',
  844. 'threadcache' => './forumdata/threadcaches',
  845. 'log' => './forumdata/logs',
  846. 'uccache' => './uc_client/data/cache'
  847. );
  848. foreach($checkdirarray as $key => $dir) {
  849. if(!dir_writeable(ROOT_PATH.$dir)) {
  850. $langkey = $key.'_unwriteable';
  851. $errors[] = $key.'_unwriteable';
  852. if(!in_array($key, array('ftemplate'))) {
  853. $quit = TRUE;
  854. }
  855. }
  856. }
  857. $errors['quit'] = $quit;
  858. return $errors;
  859. }
  860. function show_error($type, $errors = '', $quit = false) {
  861. global $lang, $step;
  862. $title = lang($type);
  863. $comment = lang($type.'_comment', false);
  864. $errormsg = '';
  865. if($errors) {
  866. if(!empty($errors)) {
  867. foreach ((array)$errors as $k => $v) {
  868. if(is_numeric($k)) {
  869. $comment .= "<li><em class=\"red\">".lang($v)."</em></li>";
  870. }
  871. }
  872. }
  873. }
  874. if($step > 0) {
  875. echo "<div class=\"desc\"><b>$title</b><ul>$comment</ul>";
  876. } else {
  877. echo "</div><div class=\"main\" style=\"margin-top: -123px;\"><b>$title</b><ul style=\"line-height: 200%; margin-left: 30px;\">$comment</ul>";
  878. }
  879. if($quit) {
  880. echo '<br /><span class="red">'.$lang['error_quit_msg'].'</span><br /><br /><br /><br /><br /><br />';
  881. }
  882. echo '</div>';
  883. $quit && show_footer();
  884. }
  885. function show_tips($tip, $title = '', $comment = '', $style = 1) {
  886. global $lang;
  887. $title = empty($title) ? lang($tip) : $title;
  888. $comment = empty($comment) ? lang($tip.'_comment', FALSE) : $comment;
  889. if($style) {
  890. echo "<div class=\"desc\"><b>$title</b>";
  891. } else {
  892. echo "</div><div class=\"main\" style=\"margin-top: -123px;\">$title<div class=\"desc1 marginbot\"><ul>";
  893. }
  894. $comment && print('<br>'.$comment);
  895. echo "</div>";
  896. }
  897. function show_setting($setname, $varname = '', $value = '', $type = 'text|password|checkbox', $error = '') {
  898. if($setname == 'start') {
  899. echo "<form method=\"post\" action=\"index.php\">\n";
  900. return;
  901. } elseif($setname == 'end') {
  902. echo "\n</table>\n</form>\n";
  903. return;
  904. } elseif($setname == 'hidden') {
  905. echo "<input type=\"hidden\" name=\"$varname\" value=\"$value\">\n";
  906. return;
  907. }
  908. echo "\n".'<tr><th class="tbopt'.($error ? ' red' : '').'" align="left">&nbsp;'.(empty($setname) ? '' : lang($setname).':')."</th>\n<td>";
  909. if($type == 'text' || $type == 'password') {
  910. $value = dhtmlspecialchars($value);
  911. echo "<input type=\"$type\" name=\"$varname\" value=\"$value\" size=\"35\" class=\"txt\">";
  912. } elseif(strpos($type, 'submit') !== FALSE) {
  913. if(strpos($type, 'oldbtn') !== FALSE) {
  914. echo "<input type=\"button\" name=\"oldbtn\" value=\"".lang('old_step')."\" class=\"btn\" onclick=\"history.back();\">\n";
  915. }
  916. $value = empty($value) ? 'next_step' : $value;
  917. echo "<input type=\"submit\" name=\"$varname\" value=\"".lang($value)."\" class=\"btn\">\n";
  918. } elseif($type == 'checkbox') {
  919. if(!is_array($varname) && !is_array($value)) {
  920. echo "<label><input type=\"checkbox\" name=\"$varname\" value=\"1\"".($value ? 'checked="checked"' : '')."style=\"border: 0\">".lang($setname.'_check_label')."</label>\n";
  921. }
  922. } else {
  923. echo $value;
  924. }
  925. echo "</td>\n<td>";
  926. if($error) {
  927. $comment = '<span class="red">'.(is_string($error) ? lang($error) : lang($setname.'_error')).'</span>';
  928. } else {
  929. $comment = lang($setname.'_comment', false);
  930. }
  931. echo "$comment</td>\n</tr>\n";
  932. return true;
  933. }
  934. function show_step($step) {
  935. global $method;
  936. $laststep = 4;
  937. $title = lang('step_'.$method.'_title');
  938. $comment = lang('step_'.$method.'_desc');
  939. $step_title_1 = lang('step_title_1');
  940. $step_title_2 = lang('step_title_2');
  941. $step_title_3 = lang('step_title_3');
  942. $step_title_4 = lang('step_title_4');
  943. $stepclass = array();
  944. for($i = 1; $i <= $laststep; $i++) {
  945. $stepclass[$i] = $i == $step ? 'current' : ($i < $step ? '' : 'unactivated');
  946. }
  947. $stepclass[$laststep] .= ' last';
  948. echo <<<EOT
  949. <div class="setup step{$step}">
  950. <h2>$title</h2>
  951. <p>$comment</p>
  952. </div>
  953. <div class="stepstat">
  954. <ul>
  955. <li class="$stepclass[1]">$step_title_1</li>
  956. <li class="$stepclass[2]">$step_title_2</li>
  957. <li class="$stepclass[3]">$step_title_3</li>
  958. <li class="$stepclass[4]">$step_title_4</li>
  959. </ul>
  960. <div class="stepstatbg stepstat1"></div>
  961. </div>
  962. </div>
  963. <div class="main">
  964. EOT;
  965. }
  966. function lang($lang_key, $force = true) {
  967. return isset($GLOBALS['lang'][$lang_key]) ? $GLOBALS['lang'][$lang_key] : ($force ? $lang_key : '');
  968. }
  969. function check_adminuser($username, $password, $email) {
  970. include ROOT_PATH.CONFIG_UC;
  971. include ROOT_PATH.'./uc_client/client.php';
  972. $error = '';
  973. $ucresult = uc_user_login($username, $password);
  974. list($tmp['uid'], $tmp['username'], $tmp['password'], $tmp['email']) = uc_addslashes($ucresult);
  975. $ucresult = $tmp;
  976. if($ucresult['uid'] <= 0) {
  977. $uid = uc_user_register($username, $password, $email);
  978. if($uid == -1 || $uid == -2) {
  979. $error = 'admin_username_invalid';
  980. } elseif($uid == -4 || $uid == -5 || $uid == -6) {
  981. $error = 'admin_email_invalid';
  982. } elseif($uid == -3) {
  983. $error = 'admin_exist_password_error';
  984. }
  985. } else {
  986. $uid = $ucresult['uid'];
  987. $email = $ucresult['email'];
  988. $password = $ucresult['password'];
  989. }
  990. if(!$error && $uid > 0) {
  991. $password = md5($password);
  992. uc_user_addprotected($username, '');
  993. } else {
  994. $uid = 0;
  995. $error = empty($error) ? 'error_unknow_type' : $error;
  996. }
  997. return array('uid' => $uid, 'username' => $username, 'password' => $password, 'email' => $email, 'error' => $error);
  998. }
  999. function save_uc_config($config, $file) {
  1000. $success = false;
  1001. list($appauthkey, $appid, $ucdbhost, $ucdbname, $ucdbuser, $ucdbpw, $ucdbcharset, $uctablepre, $uccharset, $ucapi, $ucip) = $config;
  1002. $link = mysql_connect($ucdbhost, $ucdbuser, $ucdbpw, 1);
  1003. $uc_connnect = $link && mysql_select_db($ucdbname, $link) ? 'mysql' : '';
  1004. $date = gmdate("Y-m-d H:i:s", time() + 3600 * 8);
  1005. $year = date('Y');
  1006. $config = <<<EOT
  1007. <?php
  1008. define('UC_CONNECT', '$uc_connnect');
  1009. define('UC_DBHOST', '$ucdbhost');
  1010. define('UC_DBUSER', '$ucdbuser');
  1011. define('UC_DBPW', '$ucdbpw');
  1012. define('UC_DBNAME', '$ucdbname');
  1013. define('UC_DBCHARSET', '$ucdbcharset');
  1014. define('UC_DBTABLEPRE', '`$ucdbname`.$uctablepre');
  1015. define('UC_DBCONNECT', 0);
  1016. define('UC_CHARSET', '$uccharset');
  1017. define('UC_KEY', '$appauthkey');
  1018. define('UC_API', '$ucapi');
  1019. define('UC_APPID', '$appid');
  1020. define('UC_IP', '$ucip');
  1021. define('UC_PPP', 20);
  1022. ?>
  1023. EOT;
  1024. if($fp = fopen($file, 'w')) {
  1025. fwrite($fp, $config);
  1026. fclose($fp);
  1027. $success = true;
  1028. }
  1029. return $success;
  1030. }
  1031. function _generate_key() {
  1032. $random = random(32);
  1033. $info = md5($_SERVER['SERVER_SOFTWARE'].$_SERVER['SERVER_NAME'].$_SERVER['SERVER_ADDR'].$_SERVER['SERVER_PORT'].$_SERVER['HTTP_USER_AGENT'].time());
  1034. $return = array();
  1035. for($i=0; $i<32; $i++) {
  1036. $return[$i] = $random[$i].$info[$i];
  1037. }
  1038. return implode('', $return);
  1039. }
  1040. function uc_write_config($config, $file, $password) {
  1041. list($appauthkey, $appid, $ucdbhost, $ucdbname, $ucdbuser, $ucdbpw, $ucdbcharset, $uctablepre, $uccharset, $ucapi, $ucip) = $config;
  1042. $ucauthkey = _generate_key();
  1043. $ucsiteid = _generate_key();
  1044. $ucmykey = _generate_key();
  1045. $salt = substr(_generate_key(), 0, 6);
  1046. $pw = md5(md5($password).$salt);
  1047. $config = "<?php \r\ndefine('UC_DBHOST', '$ucdbhost');\r\n";
  1048. $config .= "define('UC_DBUSER', '$ucdbuser');\r\n";
  1049. $config .= "define('UC_DBPW', '$ucdbpw');\r\n";
  1050. $config .= "define('UC_DBNAME', '$ucdbname');\r\n";
  1051. $config .= "define('UC_DBCHARSET', '$ucdbcharset');\r\n";
  1052. $config .= "define('UC_DBTABLEPRE', '$uctablepre');\r\n";
  1053. $config .= "define('UC_COOKIEPATH', '/');\r\n";
  1054. $config .= "define('UC_COOKIEDOMAIN', '');\r\n";
  1055. $config .= "define('UC_DBCONNECT', 0);\r\n";
  1056. $config .= "define('UC_CHARSET', '".$uccharset."');\r\n";
  1057. $config .= "define('UC_FOUNDERPW', '$pw');\r\n";
  1058. $config .= "define('UC_FOUNDERSALT', '$salt');\r\n";
  1059. $config .= "define('UC_KEY', '$ucauthkey');\r\n";
  1060. $config .= "define('UC_SITEID', '$ucsiteid');\r\n";
  1061. $config .= "define('UC_MYKEY', '$ucmykey');\r\n";
  1062. $config .= "define('UC_DEBUG', false);\r\n";
  1063. $config .= "define('UC_PPP', 20);\r\n";
  1064. $fp = fopen($file, 'w');
  1065. fwrite($fp, $config);
  1066. fclose($fp);
  1067. }
  1068. function install_uc_server() {
  1069. global $db, $dbhost, $dbuser, $dbpw, $dbname, $tablepre, $username, $password, $email;
  1070. $ucsql = file_get_contents(ROOT_PATH.'./uc_server/install/uc.sql');
  1071. $uctablepre = $tablepre.'ucenter_';
  1072. $ucsql = str_replace(' uc_', ' '.$uctablepre, $ucsql);
  1073. $ucsql && runucquery($ucsql, $uctablepre);
  1074. $appauthkey = _generate_key();
  1075. $ucdbhost = $dbhost;
  1076. $ucdbname = $dbname;
  1077. $ucdbuser = $dbuser;
  1078. $ucdbpw = $dbpw;
  1079. $ucdbcharset = DBCHARSET;
  1080. $uccharset = CHARSET;
  1081. $pathinfo = pathinfo($_SERVER['PHP_SELF']);
  1082. $pathinfo['dirname'] = substr($pathinfo['dirname'], 0, -8);
  1083. $appurl = 'http://'.preg_replace("/\:\d+/", '', $_SERVER['HTTP_HOST']).($_SERVER['SERVER_PORT'] && $_SERVER['SERVER_PORT'] != 80 ? ':'.$_SERVER['SERVER_PORT'] : '').$pathinfo['dirname'];
  1084. $ucapi = $appurl.'/uc_server';
  1085. $ucip = '';
  1086. $app_tagtemplates = 'apptagtemplates[template]='.urlencode('<a href="{url}" target="_blank">{subject}</a>').'&'.
  1087. 'apptagtemplates[fields][subject]='.urlencode($lang['tagtemplates_subject']).'&'.
  1088. 'apptagtemplates[fields][uid]='.urlencode($lang['tagtemplates_uid']).'&'.
  1089. 'apptagtemplates[fields][username]='.urlencode($lang['tagtemplates_username']).'&'.
  1090. 'apptagtemplates[fields][dateline]='.urlencode($lang['tagtemplates_dateline']).'&'.
  1091. 'apptagtemplates[fields][url]='.urlencode($lang['tagtemplates_url']);
  1092. $db->query("INSERT INTO {$uctablepre}applications SET name='Discuz! Board', url='$appurl', ip='$ucip', authkey='$appauthkey', synlogin='1', charset='$charset', dbcharset='$dbcharset', type='DISCUZX', recvnote='1', tagtemplates='$apptagtemplates'", $link);
  1093. $appid = $db->insert_id($link);
  1094. $db->query("ALTER TABLE {$uctablepre}notelist ADD COLUMN app$appid tinyint NOT NULL");
  1095. $config = array($appauthkey,$appid,$ucdbhost,$ucdbname,$ucdbuser,$ucdbpw,$ucdbcharset,$uctablepre,$uccharset,$ucapi,$ucip);
  1096. save_uc_config($config, ROOT_PATH.'./config/config_ucenter.php');
  1097. $salt = substr(uniqid(rand()), -6);
  1098. $passwordmd5 = md5(md5($password).$salt);
  1099. $db->query("INSERT INTO {$uctablepre}members SET $sqladd username='$username', password='$passwordmd5', email='$email', regip='hidden', regdate='".time()."', salt='$salt'");
  1100. $uid = $db->insert_id();
  1101. $db->query("INSERT INTO {$uctablepre}memberfields SET uid='$uid'");
  1102. $db->query("INSERT INTO {$uctablepre}admins SET
  1103. uid='$uid',
  1104. username='$username',
  1105. allowadminsetting='1',
  1106. allowadminapp='1',
  1107. allowadminuser='1',
  1108. allowadminbadword='1',
  1109. allowadmincredits='1',
  1110. allowadmintag='1',
  1111. allowadminpm='1',
  1112. allowadmindomain='1',
  1113. allowadmindb='1',
  1114. allowadminnote='1',
  1115. allowadmincache='1',
  1116. allowadminlog='1'");
  1117. uc_write_config($config, ROOT_PATH.'./uc_server/data/config.inc.php', $password);
  1118. @unlink(ROOT_PATH.'./uc_server/install/index.php');
  1119. @unlink(ROOT_PATH.'./uc_server/data/cache/settings.php');
  1120. @touch(ROOT_PATH.'./uc_server/data/upgrade.lock');
  1121. @touch(ROOT_PATH.'./uc_server/data/install.lock');
  1122. dir_clear(ROOT_PATH.'./uc_server/data/cache');
  1123. dir_clear(ROOT_PATH.'./uc_server/data/view');
  1124. }
  1125. function install_data($username, $uid) {
  1126. global $_G, $db, $tablepre;
  1127. showjsmessage(lang('install_data')." ... ".lang('succeed'));
  1128. $_G = array('db'=>$db,'tablepre'=>$tablepre, 'uid'=>$uid, 'username'=>$username);
  1129. $arr = array(
  1130. 0=> array('importfile'=>'./data/group_index.xml','primaltplname'=>'group/index', 'targettplname'=>'group/index'),
  1131. );
  1132. foreach ($arr as $v) {
  1133. import_diy($v['importfile'], $v['primaltplname'], $v['targettplname']);
  1134. }
  1135. }
  1136. function install_testdata($username, $uid) {
  1137. global $_G, $db, $tablepre;
  1138. showjsmessage(lang('install_test_data')." ... ".lang('succeed'));
  1139. $sqlfile = ROOT_PATH.'./install/data/common_district_{#id}.sql';
  1140. for($i = 1; $i < 4; $i++) {
  1141. $sqlfileid = str_replace('{#id}', $i, $sqlfile);
  1142. if(file_exists($sqlfileid)) {
  1143. $sql = file_get_contents($sqlfileid);
  1144. $sql = str_replace("\r\n", "\n", $sql);
  1145. runquery($sql);
  1146. }
  1147. }
  1148. }
  1149. function getvars($data, $type = 'VAR') {
  1150. $evaluate = '';
  1151. foreach($data as $key => $val) {
  1152. if(!preg_match("/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/", $key)) {
  1153. continue;
  1154. }
  1155. if(is_array($val)) {
  1156. $evaluate .= buildarray($val, 0, "\${$key}")."\r\n";
  1157. } else {
  1158. $val = addcslashes($val, '\'\\');
  1159. $evaluate .= $type == 'VAR' ? "\$$key = '$val';\n" : "define('".strtoupper($key)."', '$val');\n";
  1160. }
  1161. }
  1162. return $evaluate;
  1163. }
  1164. function buildarray($array, $level = 0, $pre = '$_config') {
  1165. static $ks;
  1166. if($level == 0) {
  1167. $ks = array();
  1168. $return = '';
  1169. }
  1170. foreach ($array as $key => $val) {
  1171. if($level == 0) {
  1172. $newline = str_pad(' CONFIG '.strtoupper($key).' ', 70, '-', STR_PAD_BOTH);
  1173. $return .= "\r\n// $newline //\r\n";
  1174. if($key == 'admincp') {
  1175. $newline = str_pad(' Founders: $_config[\'admincp\'][\'founder\'] = \'1,2,3\'; ', 70, '-', STR_PAD_BOTH);
  1176. $return .= "// $newline //\r\n";
  1177. }
  1178. }
  1179. $ks[$level] = $ks[$level - 1]."['$key']";
  1180. if(is_array($val)) {
  1181. $ks[$level] = $ks[$level - 1]."['$key']";
  1182. $return .= buildarray($val, $level + 1, $pre);
  1183. } else {
  1184. $val = is_string($val) || strlen($val) > 12 || !preg_match("/^\-?[1-9]\d*$/", $val) ? '\''.addcslashes($val, '\'\\').'\'' : $val;
  1185. $return .= $pre.$ks[$level - 1]."['$key']"." = $val;\r\n";
  1186. }
  1187. }
  1188. return $return;
  1189. }
  1190. function save_diy_data($primaltplname, $targettplname, $data, $database = false) {
  1191. global $_G;
  1192. if (empty($data) || !is_array($data)) return false;
  1193. $_G['curtplbid'] = array();
  1194. $_G['curtplframe'] = array();
  1195. $tpldirectory = './template/default';
  1196. $file = '.'.$tpldirectory.'/'.$primaltplname.'.htm';
  1197. $content = file_get_contents(realpath($file));
  1198. foreach ($data['layoutdata'] as $key => $value) {
  1199. $html = '';
  1200. $html .= '<div id="'.$key.'" class="area">';
  1201. $html .= getframehtml($value);
  1202. $html .= '</div>';
  1203. $content = preg_replace("/(\<\!\-\-\[diy\=$key\]\-\-\>).+?(\<\!\-\-\[\/diy\]\-\-\>)/is", "\\1".$html."\\2", $content);
  1204. }
  1205. $content = preg_replace("/(\<style id\=\"diy_style\" type\=\"text\/css\"\>).*(\<\/style\>)/is", "\\1".$data['spacecss']."\\2", $content);
  1206. if (!empty($data['style'])) {
  1207. $content = preg_replace("/(\<link id\=\"style_css\" rel\=\"stylesheet\" type\=\"text\/css\" href\=\").+?(\"\>)/is", "\\1".$data['style']."\\2", $content);
  1208. }
  1209. $tplfile =ROOT_PATH.'./data/diy/'.$tpldirectory.'/'.$targettplname.'.htm';
  1210. $tplpath = dirname($tplfile);
  1211. if (!is_dir($tplpath)) dmkdir($tplpath);
  1212. $r = file_put_contents($tplfile, $content);
  1213. if ($r && $database) {
  1214. $_G['db']->query('DELETE FROM '.$_G['tablepre'].'common_template_block WHERE targettplname="'.$targettplname.'"');
  1215. if (!empty($_G['curtplbid'])) {
  1216. $values = array();
  1217. foreach ($_G['curtplbid'] as $bid) {
  1218. $values[] = "('$targettplname', '$tpldirectory', '$bid')";
  1219. }
  1220. if (!empty($values)) {
  1221. $_G['db']->query("INSERT INTO ".$_G['tablepre']."common_template_block (targettplname, tpldirectory, bid) VALUES ".implode(',', $values));
  1222. }
  1223. }
  1224. $tpldata = daddslashes(serialize($data));
  1225. $_G['db']->query("REPLACE INTO ".$_G['tablepre']."common_diy_data (targettplname, tpldirectory, primaltplname, diycontent) VALUES ('$targettplname', '$tpldirectory', '$primaltplname', '$tpldata')");
  1226. }
  1227. return $r;
  1228. }
  1229. function getframehtml($data = array()) {
  1230. global $_G;
  1231. $html = $style = '';
  1232. foreach ((array)$data as $id => $content) {
  1233. list($flag, $name) = explode('`', $id);
  1234. if ($flag == 'frame') {
  1235. $fattr = $content['attr'];
  1236. $moveable = $fattr['moveable'] == 'true' ? ' move-span' : '';
  1237. $html .= '<div id="'.$fattr['name'].'" class="'.$fattr['className'].'">';
  1238. if (checkhastitle($fattr['titles'])) {
  1239. $style = gettitlestyle($fattr['titles']);
  1240. $html .= '<div class="'.implode(' ',$fattr['titles']['className']).'"'.$style.'>'.gettitlehtml($fattr['titles'], 'frame').'</div>';
  1241. }
  1242. foreach ((array)$content as $colid => $coldata) {
  1243. list($colflag, $colname) = explode('`', $colid);
  1244. if ($colflag == 'column') {
  1245. $html .= '<div id="'.$colname.'" class="'.$coldata['attr']['className'].'">';
  1246. $html .= '<div id="'.$colname.'_temp" class="move-span temp"></div>';
  1247. $html .= getframehtml($coldata);
  1248. $html .= '</div>';
  1249. }
  1250. }
  1251. $html .= '</div>';
  1252. } elseif ($flag == 'tab') {
  1253. $fattr = $content['attr'];
  1254. $moveable = $fattr['moveable'] == 'true' ? ' move-span' : '';
  1255. $html .= '<div id="'.$fattr['name'].'" class="'.$fattr['className'].'">';
  1256. $switchtype = 'click';
  1257. foreach ((array)$content as $colid => $coldata) {
  1258. list($colflag, $colname) = explode('`', $colid);
  1259. if ($colflag == 'column') {
  1260. if (checkhastitle($fattr['titles'])) {
  1261. $style = gettitlestyle($fattr['titles']);
  1262. $title = gettitlehtml($fattr['titles'], 'tab');
  1263. }
  1264. $switchtype = is_array($fattr['titles']['switchType']) && !empty($fattr['titles']['switchType'][0]) ? $fattr['titles']['switchType'][0] : 'click';
  1265. $html .= '<div id="'.$colname.'" class="'.$coldata['attr']['className'].'"'.$style.' switchtype="'.$switchtype.'">'.$title;
  1266. $html .= getframehtml($coldata);
  1267. $html .= '</div>';
  1268. }
  1269. }
  1270. $html .= '<div id="'.$fattr['name'].'_content" class="tb-c"></div>';
  1271. $html .= '<script type="text/javascript">initTab("'.$fattr['name'].'","'.$switchtype.'");</script>';
  1272. $html .= '</div>';
  1273. } elseif ($flag == 'block') {
  1274. $battr = $content['attr'];
  1275. $bid = intval(str_replace('portal_block_', '', $battr['name']));
  1276. if (!empty($bid)) {
  1277. $html .= "<!--{block/{$bid}}-->";
  1278. $_G['curtplbid'][$bid] = $bid;
  1279. }
  1280. }
  1281. }
  1282. return $html;
  1283. }
  1284. function gettitlestyle($title) {
  1285. $style = '';
  1286. if (is_array($title['style']) && count($title['style'])) {
  1287. foreach ($title['style'] as $k=>$v){
  1288. $style .= $k.':'.$v.';';
  1289. }
  1290. }
  1291. $style = $style ? ' style=\''.$style.'\'' : '';
  1292. return $style;
  1293. }
  1294. function checkhastitle($title) {
  1295. if (!is_array($title)) return false;
  1296. foreach ($title as $k => $v) {
  1297. if (strval($k) == 'className') continue;
  1298. if (!empty($v['text'])) return true;
  1299. }
  1300. return false;
  1301. }
  1302. function gettitlehtml($title, $type) {
  1303. global $_G;
  1304. if (!is_array($title)) return '';
  1305. $html = $one = $style = $color = '';
  1306. foreach ($title as $k => $v) {
  1307. if (in_array(strval($k),array('className','style'))) continue;
  1308. if (empty($v['src']) && empty($v['text'])) continue;
  1309. $one = "<span class=\"{$v['className']}\"";
  1310. $style = $color = "";
  1311. $style .= empty($v['font-size']) ? '' : "font-size:{$v['font-size']}px;";
  1312. $style .= empty($v['float']) ? '' : "float:{$v['float']};";
  1313. $margin_ = empty($v['float']) ? 'left' : $v['float'];
  1314. $style .= empty($v['margin']) ? '' : "margin-{$margin_}:{$v['margin']}px;";
  1315. $color = empty($v['color']) ? '' : "color:{$v['color']};";
  1316. $img = !empty($v['src']) ? '<img src="'.$v['src'].'" class="vm" alt="'.$v['text'].'"/>' : '';
  1317. if (empty($v['href'])) {
  1318. $style = empty($style)&&empty($color) ? '' : ' style="'.$style.$color.'"';
  1319. $one .= $style.">$img{$v['text']}";
  1320. } else {
  1321. $style = empty($style) ? '' : ' style="'.$style.'"';
  1322. $colorstyle = empty($color) ? '' : ' style="'.$color.'"';
  1323. $one .= $style.'><a href="'.$v['href'].'"'.$colorstyle.'>'.$img.$v['text'].'</a>';
  1324. }
  1325. $one .= '</span>';
  1326. $siteurl = str_replace(array('/','.'),array('\/','\.'),$_G['siteurl']);
  1327. $one = preg_replace('/\"'.$siteurl.'(.*?)\"/','"$1"',$one);
  1328. $html = $k === 'first' ? $one.$html : $html.$one;
  1329. }
  1330. return $html;
  1331. }
  1332. function block_import($data) {
  1333. global $_G;
  1334. if(!is_array($data['block'])) {
  1335. return ;
  1336. }
  1337. $data = daddslashes($data);
  1338. $stylemapping = array();
  1339. if($data['style']) {
  1340. $hashes = $styles = array();
  1341. foreach($data['style'] as $value) {
  1342. $hashes[] = $value['hash'];
  1343. $styles[$value['hash']] = $value['styleid'];
  1344. }
  1345. $query = $_G['db']->query('SELECT styleid, hash FROM '.$_G['tablepre']."common_block_style WHERE hash IN (".dimplode($hashes).')');
  1346. while($value=$_G['db']->fetch_array($query)) {
  1347. $id = $styles[$value['hash']];
  1348. $stylemapping[$id] = intval($value['styleid']);
  1349. unset($styles[$value['hash']]);
  1350. }
  1351. foreach($styles as $id) {
  1352. $style = $data['style'][$id];
  1353. $style['styleid'] = '';
  1354. if(is_array($style['template'])) {
  1355. $style['template'] = dstripslashes($style['template']);
  1356. $style['template'] = addslashes(serialize($style['template']));
  1357. }
  1358. $sql = implode_field_value($style);
  1359. $_G['db']->query('INSERT INTO '.$_G['tablepre'].'common_block_style SET '.$sql);
  1360. $newid = $_G['db']->insert_id();
  1361. $stylemapping[$id] = $newid;
  1362. }
  1363. }
  1364. $blockmapping = array();
  1365. foreach($data['block'] as $block) {
  1366. $oid = $block['bid'];
  1367. if(!empty($block['styleid'])) {
  1368. $block['styleid'] = intval($stylemapping[$block['styleid']]);
  1369. }
  1370. $block['bid'] = '';
  1371. $block['uid'] = $_G['uid'];
  1372. $block['username'] = $_G['username'];
  1373. $block['dateline'] = 0;
  1374. if(is_array($block['param'])) {
  1375. $block['param'] = dstripslashes($block['param']);
  1376. $block['param'] = addslashes(serialize($block['param']));
  1377. }
  1378. $sql = implode_field_value($block);
  1379. $_G['db']->query('INSERT INTO '.$_G['tablepre'].'common_block SET '.$sql);
  1380. $newid = $_G['db']->insert_id();
  1381. $blockmapping[$oid] = $newid;
  1382. }
  1383. return $blockmapping;
  1384. }
  1385. function getframeblock($data) {
  1386. global $_G;
  1387. if (!isset($_G['curtplbid'])) $_G['curtplbid'] = array();
  1388. if (!isset($_G['curtplframe'])) $_G['curtplframe'] = array();
  1389. foreach ((array)$data as $id => $content) {
  1390. list($flag, $name) = explode('`', $id);
  1391. if ($flag == 'frame' || $flag == 'tab') {
  1392. foreach ((array)$content as $colid => $coldata) {
  1393. list($colflag, $colname) = explode('`', $colid);
  1394. if ($colflag == 'column') {
  1395. getframeblock($coldata,$framename);
  1396. }
  1397. }
  1398. $_G['curtplframe'][$name] = array('type'=>$flag,'name'=>$name);
  1399. } elseif ($flag == 'block') {
  1400. $battr = $content['attr'];
  1401. $bid = intval(str_replace('portal_block_', '', $battr['name']));
  1402. if (!empty($bid)) {
  1403. $_G['curtplbid'][$bid] = $bid;
  1404. }
  1405. }
  1406. }
  1407. }
  1408. function import_diy($importfile, $primaltplname, $targettplname) {
  1409. global $_G;
  1410. $css = $html = '';
  1411. $arr = array();
  1412. $content = file_get_contents(realpath($importfile));
  1413. require_once ROOT_PATH.'./source/class/class_xml.php';
  1414. if (empty($content)) return $arr;
  1415. $diycontent = xml2array($content);
  1416. if ($diycontent) {
  1417. foreach ($diycontent['layoutdata'] as $key => $value) {
  1418. if (!empty($value)) getframeblock($value);
  1419. }
  1420. $newframe = array();
  1421. foreach ($_G['curtplframe'] as $value) {
  1422. $newframe[] = $value['type'].random(6);
  1423. }
  1424. $mapping = array();
  1425. if (!empty($diycontent['blockdata'])) {
  1426. $mapping = block_import($diycontent['blockdata']);
  1427. unset($diycontent['blockda…

Large files files are truncated, but you can click here to view the full file