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

/ourproject --username keivenlove@gmail.com/install/install_function.php

http://ourproject.googlecode.com/
PHP | 453 lines | 427 code | 26 blank | 0 comment | 93 complexity | 8e9a25f953a9af9978f128de6fc064fe MD5 | raw file
  1. <?php
  2. function show_view($content) {
  3. global $_K;
  4. show_header();
  5. print<<<END
  6. <table>
  7. <tr><td>$content</td></tr>
  8. </table>
  9. END;
  10. show_footer();
  11. exit();
  12. }
  13. function fun_url_ck() {
  14. if (preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) !== preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])) {
  15. header("Location: index.php");
  16. exit ();
  17. }
  18. }
  19. function show_msg($message,$url_forward) {
  20. global $_K;
  21. if($url_forward) {
  22. $_K['extrahead'] = '<meta http-equiv="refresh" content="1; url='.$url_forward.'">';
  23. $message = "<a href=\"$url_forward\">$message(???...)</a>";
  24. }
  25. show_header();
  26. print<<<END
  27. <table>
  28. <tr><td>$message</td></tr>
  29. </table>
  30. END;
  31. show_footer();
  32. exit();
  33. }
  34. function show_header() {
  35. global $_K, $_SC;
  36. $ver=KEKE_VERSION;
  37. $ver_time = KEKE_RELEASE;
  38. $nowarr = array($_GET['step'] => ' class="current"');
  39. print<<<END
  40. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  41. <html xmlns="http://www.w3.org/1999/xhtml">
  42. <head>
  43. <meta http-equiv="Content-Type" content="text/html"; charset="gb2312" />
  44. $_K[extrahead]
  45. <title>PHPYun.????????1.3 BETA</title>
  46. <script src='js/form_and_validation.js' type='text/javascript'></script>
  47. <link href="data/style.css" rel="stylesheet" type="text/css"/>
  48. </head>
  49. <body>
  50. <div class="bodydiv">
  51. <h1>PHPYun.????????1.3 BETA</h1>
  52. <div style="width:90%;margin:0 auto;">
  53. <table id="menu">
  54. <tr>
  55. <td{$nowarr[start]}>????</td>
  56. <td{$nowarr[checkset]}>????</td>
  57. <td{$nowarr[sql]}>?????</td>
  58. <td{$nowarr[finish]}>????</td>
  59. </tr>
  60. </table>
  61. <br>
  62. END;
  63. }
  64. function show_footer() {
  65. print<<<END
  66. </div>
  67. <div id="footer">Powered by <font color="blue"><a href="http://www.phpyun.com">PHPYun. ????</a></font> 1.3 BETA &copy;2010 </div>
  68. </div>
  69. <br>
  70. </body>
  71. </html>
  72. END;
  73. }
  74. function check_db($dbhost, $dbuser, $dbpw, $dbname, $tablepre) {
  75. if(!function_exists('mysql_connect')) {
  76. show_msg($lang['advice_mysql_connect'], 0);
  77. }
  78. if(!@mysql_connect($dbhost, $dbuser, $dbpw)) {
  79. $errno = mysql_errno();
  80. $error = mysql_error();
  81. if($errno == 1045) {
  82. show_msg($lang['database_errno_1045'], 0);
  83. } elseif($errno == 2003) {
  84. show_msg($lang['database_errno_2003'], 0);
  85. } else {
  86. show_msg($lang['database_connect_error'], 0);
  87. }
  88. } else {
  89. if($query = @mysql_query("SHOW TABLES FROM $dbname")) {
  90. while($row = mysql_fetch_row($query)) {
  91. if(preg_match("/^$tablepre/", $row[0])) {
  92. return false;
  93. }
  94. }
  95. }
  96. }
  97. return true;
  98. }
  99. function dirfile_check(&$dirfile_items) {
  100. foreach($dirfile_items as $key => $item) {
  101. $item_path = $item['path'];
  102. if($item['type'] == 'dir') {
  103. if(!dir_writeable(S_ROOT.$item_path)) {
  104. if(is_dir(S_ROOT.$item_path)) {
  105. $dirfile_items[$key]['status'] = 0;
  106. $dirfile_items[$key]['current'] = '+r';
  107. } else {
  108. $dirfile_items[$key]['status'] = -1;
  109. $dirfile_items[$key]['current'] = 'nodir';
  110. }
  111. } else {
  112. $dirfile_items[$key]['status'] = 1;
  113. $dirfile_items[$key]['current'] = '+r+w';
  114. }
  115. } else {
  116. if(file_exists(S_ROOT.$item_path)) {
  117. if(is_writable(S_ROOT.$item_path)) {
  118. $dirfile_items[$key]['status'] = 1;
  119. $dirfile_items[$key]['current'] = '+r+w';
  120. } else {
  121. $dirfile_items[$key]['status'] = 0;
  122. $dirfile_items[$key]['current'] = '+r';
  123. }
  124. } else {
  125. if(dir_writeable(dirname(S_ROOT.$item_path))) {
  126. $dirfile_items[$key]['status'] = 1;
  127. $dirfile_items[$key]['current'] = '+r+w';
  128. } else {
  129. $dirfile_items[$key]['status'] = -1;
  130. $dirfile_items[$key]['current'] = 'nofile';
  131. }
  132. }
  133. }
  134. }
  135. }
  136. function env_check(&$env_items) {
  137. foreach($env_items as $key => $item) {
  138. if($key == 'php') {
  139. $env_items[$key]['current'] = PHP_VERSION;
  140. } elseif($key == 'attachmentupload') {
  141. $env_items[$key]['current'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknow';
  142. } elseif($key == 'gdversion') {
  143. $tmp = function_exists('gd_info') ? gd_info() : array();
  144. $env_items[$key]['current'] = empty($tmp['GD Version']) ? 'noext' : $tmp['GD Version'];
  145. unset($tmp);
  146. } elseif($key == 'diskspace') {
  147. if(function_exists('disk_free_space')) {
  148. $env_items[$key]['current'] = floor(disk_free_space(S_ROOT) / (1024*1024)).'M';
  149. } else {
  150. $env_items[$key]['current'] = 'unknow';
  151. }
  152. } elseif(isset($item['c'])) {
  153. $env_items[$key]['current'] = constant($item['c']);
  154. }
  155. $env_items[$key]['status'] = 1;
  156. if($item['r'] != 'notset' && strcmp($env_items[$key]['current'], $item['r']) < 0) {
  157. $env_items[$key]['status'] = 0;
  158. }
  159. }
  160. }
  161. function function_check(&$func_items) {
  162. foreach($func_items as $item) {
  163. function_exists($item) or show_msg($lang("advice_".$item), 0);
  164. }
  165. }
  166. if(!function_exists('file_put_contents')) {
  167. function file_put_contents($filename, $s) {
  168. $fp = @fopen($filename, 'w');
  169. @fwrite($fp, $s);
  170. @fclose($fp);
  171. return TRUE;
  172. }
  173. }
  174. function dir_writeable($dir) {
  175. $writeable = 0;
  176. if(!is_dir($dir)) {
  177. @mkdir($dir, 0777);
  178. }
  179. if(is_dir($dir)) {
  180. if($fp = @fopen("$dir/test.txt", 'w')) {
  181. @fclose($fp);
  182. @unlink("$dir/test.txt");
  183. $writeable = 1;
  184. } else {
  185. $writeable = 0;
  186. }
  187. }
  188. return $writeable;
  189. }
  190. function dir_clear($dir) {
  191. global $lang;
  192. showjsmessage($lang['clear_dir'].' '.str_replace(S_ROOT, '', $dir));
  193. if($directory = @dir($dir)) {
  194. while($entry = $directory->read()) {
  195. $filename = $dir.'/'.$entry;
  196. if(is_file($filename)) {
  197. @unlink($filename);
  198. }
  199. }
  200. $directory->close();
  201. @touch($dir.'/index.htm');
  202. }
  203. }
  204. function runquery($sql) {
  205. global $lang, $tablepre, $db;
  206. if(!isset($sql) || empty($sql)) return;
  207. $orig_tablepre = "keke_";
  208. $sql = str_replace("\r", "\n", str_replace(' '.$orig_tablepre, ' '.$tablepre, $sql));
  209. $sql = str_replace("\r", "\n", str_replace(' `'.$orig_tablepre, ' `'.$tablepre, $sql));
  210. $ret = array();
  211. $num = 0;
  212. foreach(explode(";\n", trim($sql)) as $query) {
  213. $ret[$num] = '';
  214. $queries = explode("\n", trim($query));
  215. foreach($queries as $query) {
  216. $ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query;
  217. }
  218. $num++;
  219. }
  220. unset($sql);
  221. foreach($ret as $query) {
  222. $query = trim($query);
  223. if($query) {
  224. if(substr($query, 0, 12) == 'CREATE TABLE') {
  225. $name = preg_replace("/CREATE TABLE ([a-z0-9_]+) .*/is", "\\1", $query);
  226. $db->query(createtable($query));
  227. } else {
  228. $db->query($query);
  229. }
  230. }
  231. }
  232. }
  233. function createtable($sql) {
  234. $type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
  235. $type = in_array($type, array('MYISAM', 'HEAP', 'MEMORY')) ? $type : 'MYISAM';
  236. return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).
  237. (mysql_get_server_info() > '4.1' ? " ENGINE=$type DEFAULT CHARSET=".DBCHARSET : " TYPE=$type");
  238. }
  239. function random($length) {
  240. $hash = '';
  241. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  242. $max = strlen($chars) - 1;
  243. PHP_VERSION < '4.2.0' && mt_srand((double)microtime() * 1000000);
  244. for($i = 0; $i < $length; $i++) {
  245. $hash .= $chars[mt_rand(0, $max)];
  246. }
  247. return $hash;
  248. }
  249. function show_error($error_no, $error_msg = 'ok', $success = 1, $quit = TRUE) {
  250. if(KEKE_OFF) {
  251. $error_code = $success ? 0 : constant(strtoupper($error_no));
  252. $error_msg = empty($error_msg) ? $error_no : $error_msg;
  253. $error_msg = str_replace('"', '\"', $error_msg);
  254. $str = "<root>\n";
  255. $str .= "\t<error errorCode=\"$error_code\" errorMessage=\"$error_msg\" />\n";
  256. $str .= "</root>";
  257. echo $str;
  258. exit;
  259. } else {
  260. show_header();
  261. global $step;$_K;
  262. $title = keke_lang($error_no);
  263. $comment = keke_lang($error_no.'_comment', false);
  264. $errormsg = '';
  265. if($error_msg) {
  266. if(!empty($error_msg)) {
  267. foreach ((array)$error_msg as $k => $v) {
  268. if(is_numeric($k)) {
  269. $comment .= "<li><em class=\"red\">".keke_lang($v)."</em></li>";
  270. }
  271. }
  272. }
  273. }
  274. if($step) {
  275. echo "<div class=\"desc\"><b>$title</b><ul>$comment</ul>";
  276. } else {
  277. echo "</div><div class=\"main\" style=\"margin-top: 20px;\"><b>$title</b><ul style=\"line-height: 200%; margin-left: 30px;\">$comment</ul>";
  278. }
  279. if($quit) {
  280. echo '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="red">'.keke_lang('error_quit_msg').'</span><br /><br /><br />';
  281. }
  282. echo '<center><input type="button" onclick="history.back()" value="'.keke_lang('click_to_back').'" /><center><br /><br /><br />';
  283. echo '</div>';
  284. $quit && show_footer();
  285. }
  286. }
  287. function show_env_result(&$env_items, &$dirfile_items, &$func_items) {
  288. $env_str = $file_str = $dir_str = $func_str = '';
  289. $error_code = 0;
  290. foreach($env_items as $key => $item) {
  291. if($key == 'php' && strcmp($item['current'], $item['r']) < 0) {
  292. show_msg($lang['php_version_too_low'], 0);
  293. }
  294. $status = 1;
  295. if($item['r'] != 'notset') {
  296. if(intval($item['current']) && intval($item['r'])) {
  297. if(intval($item['current']) < intval($item['r'])) {
  298. $status = 0;
  299. $error_code = ENV_ERROR;
  300. }
  301. } else {
  302. if(strcmp($item['current'], $item['r']) < 0) {
  303. $status = 0;
  304. $error_code = ENV_ERROR;
  305. }
  306. }
  307. }
  308. if(KEKE_OFF) {
  309. $env_str .= "\t\t<runCondition name=\"$key\" status=\"$status\" Require=\"$item[r]\" Best=\"$item[b]\" Current=\"$item[current]\"/>\n";
  310. } else {
  311. $env_str .= "<tr>\n";
  312. $env_str .= "<td>".keke_lang($key)."</td>\n";
  313. $env_str .= "<td class=\"padleft\">".keke_lang($item['r'])."</td>\n";
  314. $env_str .= "<td class=\"padleft\">".keke_lang($item['b'])."</td>\n";
  315. $env_str .= ($status ? "<td class=\"w pdleft1\">" : "<td class=\"nw pdleft1\">").$item['current']."</td>\n";
  316. $env_str .= "</tr>\n";
  317. }
  318. }
  319. foreach($dirfile_items as $key => $item) {
  320. $tagname = $item['type'] == 'file' ? 'File' : 'Dir';
  321. $variable = $item['type'].'_str';
  322. if(KEKE_OFF) {
  323. if($item['status'] == 0) {
  324. $error_code = ENV_ERROR;
  325. }
  326. $$variable .= "\t\t\t<File name=\"$item[path]\" status=\"$item[status]\" requirePermisson=\"+r+w\" currentPermisson=\"$item[current]\" />\n";
  327. } else {
  328. $$variable .= "<tr>\n";
  329. $$variable .= "<td>$item[path]</td><td class=\"w pdleft1\">".keke_lang('writeable')."</td>\n";
  330. if($item['status'] == 1) {
  331. $$variable .= "<td class=\"w pdleft1\">".keke_lang('writeable')."</td>\n";
  332. } elseif($item['status'] == -1) {
  333. $error_code = ENV_ERROR;
  334. $$variable .= "<td class=\"nw pdleft1\">".keke_lang('nodir')."</td>\n";
  335. } else {
  336. $error_code = ENV_ERROR;
  337. $$variable .= "<td class=\"nw pdleft1\">".keke_lang('unwriteable')."</td>\n";
  338. }
  339. $$variable .= "</tr>\n";
  340. }
  341. }
  342. if(KEKE_OFF) {
  343. $str = "<root>\n";
  344. $str .= "\t<runConditions>\n";
  345. $str .= $env_str;
  346. $str .= "\t</runConditions>\n";
  347. $str .= "\t<FileDirs>\n";
  348. $str .= "\t\t<Dirs>\n";
  349. $str .= $dir_str;
  350. $str .= "\t\t</Dirs>\n";
  351. $str .= "\t\t<Files>\n";
  352. $str .= $file_str;
  353. $str .= "\t\t</Files>\n";
  354. $str .= "\t</FileDirs>\n";
  355. $str .= "\t<error errorCode=\"$error_code\" errorMessage=\"\" />\n";
  356. $str .= "</root>";
  357. echo $str;
  358. exit;
  359. } else {
  360. show_header();
  361. echo "<h2 class=\"title\">".keke_lang('env_check')."</h2>\n";
  362. echo "<table class=\"tb\" style=\"margin:20px 0 20px 55px;\">\n";
  363. echo "<tr>\n";
  364. echo "\t<th>".keke_lang('project')."</th>\n";
  365. echo "\t<th class=\"padleft\">".keke_lang('kppw_required')."</th>\n";
  366. echo "\t<th class=\"padleft\">".keke_lang('kppw_best')."</th>\n";
  367. echo "\t<th class=\"padleft\">".keke_lang('curr_server')."</th>\n";
  368. echo "</tr>\n";
  369. echo $env_str;
  370. echo "</table>\n";
  371. echo "<h2 class=\"title\">".keke_lang('priv_check')."</h2>\n";
  372. echo "<table class=\"tb\" style=\"margin:20px 0 20px 55px;width:90%;\">\n";
  373. echo "\t<tr>\n";
  374. echo "\t<th>".keke_lang('step1_file')."</th>\n";
  375. echo "\t<th class=\"padleft\">".keke_lang('step1_need_status')."</th>\n";
  376. echo "\t<th class=\"padleft\">".keke_lang('step1_status')."</th>\n";
  377. echo "</tr>\n";
  378. echo $file_str;
  379. echo $dir_str;
  380. echo "</table>\n";
  381. foreach($func_items as $item) {
  382. $status = function_exists($item);
  383. $func_str .= "<tr>\n";
  384. $func_str .= "<td>$item()</td>\n";
  385. if($status) {
  386. $func_str .= "<td class=\"w pdleft1\">".keke_lang('supportted')."</td>\n";
  387. $func_str .= "<td class=\"padleft\">".keke_lang('none')."</td>\n";
  388. } else {
  389. $error_code = ENV_ERROR;
  390. $func_str .= "<td class=\"nw pdleft1\">".keke_lang('unsupportted')."</td>\n";
  391. $func_str .= "<td><font color=\"red\">".keke_lang('advice_'.$item)."</font></td>\n";
  392. }
  393. }
  394. echo "<h2 class=\"title\">".keke_lang('func_depend')."</h2>\n";
  395. echo "<table class=\"tb\" style=\"margin:20px 0 20px 55px;width:90%;\">\n";
  396. echo "<tr>\n";
  397. echo "\t<th>".keke_lang('func_name')."</th>\n";
  398. echo "\t<th class=\"padleft\">".keke_lang('check_result')."</th>\n";
  399. echo "\t<th class=\"padleft\">".keke_lang('suggestion')."</th>\n";
  400. echo "</tr>\n";
  401. echo $func_str;
  402. echo "<tr>\n";
  403. if($error_code==2){
  404. echo "\t<th colspan=\"2\"><center> <input type=\"button\" name=\"step_2\" value=\"???????????\"></center></th>\n";
  405. }else{
  406. echo "\t<th colspan=\"2\"><center> <input type=\"button\" name=\"step_2\" value=\"????\" onclick=\"location.href='index.php?step=sql'\"></center></th>\n";
  407. }
  408. echo "</tr>\n";
  409. echo "</table>\n";
  410. show_footer();
  411. }
  412. }
  413. function show_tips($tip, $title = '', $comment = '', $style = 1) {
  414. global $lang;
  415. $title = empty($title) ? keke_lang($tip) : $title;
  416. $comment = empty($comment) ? keke_lang($tip.'_comment', FALSE) : $comment;
  417. if($style) {
  418. echo "<div class=\"desc\"><b>$title</b>";
  419. } else {
  420. echo "</div><div class=\"main\" style=\"margin-top: -123px;\">$title<div class=\"desc1 marginbot\"><ul>";
  421. }
  422. $comment && print('<br>'.$comment);
  423. echo "</div>";
  424. }
  425. function keke_lang($lang_key, $force = true) {
  426. return isset($GLOBALS['lang'][$lang_key]) ? $GLOBALS['lang'][$lang_key] : ($force ? $lang_key : '');
  427. }