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

/setup.php

http://netputweets.googlecode.com/
PHP | 146 lines | 139 code | 7 blank | 0 comment | 16 complexity | c772cd318a7e35e8e42ad597b01778ec MD5 | raw file
  1. <?php
  2. error_reporting(E_ALL ^ E_WARNING);
  3. $base_url = 'http://'.$_SERVER['HTTP_HOST'];
  4. if ($directory = trim(dirname($_SERVER['SCRIPT_NAME']), '/\,')){
  5. $base_url .= '/'.$directory;
  6. }
  7. define('BASE_URL', $base_url.'/');
  8. define('ABSPATH', dirname(__FILE__).'/');
  9. $configFile = file(ABSPATH . 'config-sample.php');
  10. $notice = '';
  11. if (!function_exists("curl_init")) {
  12. $notice = '<strong>???</strong>?????? cURL ????????????';
  13. } elseif (file_exists(ABSPATH.'config.php')) {
  14. $notice = '<strong>???</strong> config.php ???????????? config.php ????????????????????? config.php ?<a href="setup.php">??</a>?';
  15. } elseif (!file_exists(ABSPATH.'config-sample.php')) {
  16. $notice = '<strong>???</strong>????? config-sample.php ????????????????????';
  17. } elseif (!is_writable(ABSPATH)) {
  18. $notice = '<strong>???</strong>??????????????????? config.php ?';
  19. }
  20. if (isset($_GET['step'])) {
  21. $step = $_GET['step'];
  22. } else {
  23. $step = 0;
  24. }
  25. function rewritable() {
  26. $ch = curl_init();
  27. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  28. curl_setopt($ch, CURLOPT_URL, BASE_URL.'settings');
  29. curl_exec($ch);
  30. $response_info = curl_getinfo($ch);
  31. if ($response_info["http_code"] == "404") return false;
  32. return true;
  33. }
  34. function display_header($n) {
  35. header('Content-Type: text/html; charset=utf-8');
  36. ?>
  37. <!doctype html><meta charset=utf-8 /><title>???? - ???!</title><link rel="stylesheet" href="https://t.orzdream.com/images/setup.css" type="text/css" /><h1 id="logo"><img alt="???" src="https://t.orzdream.com/images/setup.jpg" /></h1><?php
  38. if ($n !== ''){
  39. echo '<div id="error">'.$n.'</div>';
  40. }
  41. }
  42. switch($step) {
  43. case 0:
  44. display_header($notice);
  45. ?><p><strong>??????????</strong><p /><a href="https://t.orzdream.com/">???</a>???????????? Twitter ??????? <a href="http://dabr.co.uk">Dabr</a> (By <a href="https://twitter.com/davidcarrington">@davidcarrington</a>) ?????????????? <a href="https://twitter.com/iChada">@iChada</a> <a href="https://twitter.com/17th">@17th</a> <a href="https://twitter.com/luosheng">@luosheng</a> <a href="https://twitter.com/lonelyswan">@LonelySwan</a> ???????????????????????? <a href="https://twitter.com/NetPuter">@NetPuter</a> ?<p />???????????????????????</p><ol><li>Twitter OAuth Consumer Key & Secret <a href="https://twitter.com/apps/new" title="????">#</a></li><li>Twitpic API Key <a href="http://dev.twitpic.com/apps/new" title="????">#</a></li><li>Twitter API Proxy <a href="http://code.google.com/p/twip/" title="????">#</a></li></ol><p><strong>??????????????????????????????????????????????????? <code>config-sample.php</code> ??????????????????????? <code>config.php</code> ?</strong></p><p>???????????<a href="http://orzdream.com/2009/10/netputweets-guide/" title="?????????">?????????</a>??????????????? <a href="https://twitter.com/NetPuter">@NetPuter</a> ????????? &hellip; &hellip;</p><?php
  46. if ($notice !== ''){
  47. echo '<p class="step"><a href="setup.php" class="button">??????</a></p>';
  48. }else{
  49. echo '<p class="step"><a href="setup.php?step=1" class="button">???????</a></p>';
  50. }
  51. break;
  52. case 1:
  53. display_header($notice);
  54. ?><form method="post" action="setup.php?step=2"><p>????????????????</p><table class="form-table"><tr><th scope="row"><label for="t_title">??</label></th><td><input name="t_title" id="t_title" type="text" value="???!" size="35" /></td><td>??<a href="https://t.orzdream.com/settings">?? - ???!</a>?</td></tr><tr><th scope="row"><label for="t_urf">??</label></th><td><input name="t_urf" id="t_urf" type="text" value="<?php echo BASE_URL;?>" size="35" /></td><td>??????? ???? / ??</td></tr><tr><th scope="row"><label for="t_ck">Cookie ??</label></th><td><input name="t_ck" id="t_ck" type="text" size="35" value="NetPutweets" /></td><td>????????????????????????</td></tr><tr><th scope="row"><label for="t_tck">Twitter OAuth Consumer Key <a href="https://twitter.com/apps/new" title="????">#</a></label></th><td><input name="t_tck" id="t_tck" type="text" size="35" value="awGBKfiSSqf1B2iKGsmJQ" /></td><td>??????</td></tr><tr><th scope="row"><label for="t_tcs">Twitter OAuth Consumer Secret <a href="https://twitter.com/apps/new" title="????">#</a></label></th><td><input name="t_tcs" id="t_tcs" type="text" size="35" value="hym4qJF1F6nyjISzRUCFBU4OQSIr5mrk7074vId3K8" /></td><td>??????</td></tr><tr><th scope="row"><label for="t_tak">Twitpic API Key <a href="http://dev.twitpic.com/apps/new" title="????">#</a></label></th><td><input name="t_tak" id="t_tak" type="text" value="95a105b0faadab9daa1a5739d4f80992" size="35" /></td><td>???????</td></tr><tr><th scope="row"><label for="t_ta">Twitter API <a href="http://code.google.com/p/twip/" title="????">#</a></label></th><td><input name="t_ta" id="t_ta" type="text" value="http://api.twitter.com/1/" size="35" /></td><td>????????? ?????</td></tr><tr><th scope="row"><label for="t_tsa">Twitter Search API</label></th><td><input name="t_tsa" id="t_tsa" type="text" value="http://search.twitter.com/" size="35" /></td><td>????????? ?????</td></tr><tr><th scope="row"><label for="t_rsl">?????</label></th><td><select name="t_rsl"><option value="1">??</option><option selected="selected" value="0">??</option></select></td><td>????????? ????? ???????????????? ????</td></tr><tr><th scope="row"><label for="t_ivt">????????</label></th><td><select name="t_ivt"><option value="1">??</option><option selected="selected" value="0">??</option></select></td><td>?????????</td></tr><tr><th scope="row"><label for="t_psw">?????</label></th><td><input name="t_psw" id="t_psw" type="text" value="twitter" size="20" /></td><td>??? <a href="invite.php">invite.php</a> ?</td></tr><tr><th scope="row"><label for="t_ssl">???? SSL ????</label></th><td><select name="t_ssl"><option value="1">??</option><option selected="selected" value="0">??</option></select></td><td>??????? ???????????</td></tr></table><?php
  55. if ($notice !== ''){
  56. echo '<p class="step"><a href="setup.php" class="button">????</a></p>';
  57. }else{
  58. echo '<p class="step"><input name="submit" type="submit" value="????" class="button" /></p>';
  59. }
  60. echo '</form>';
  61. break;
  62. case 2:
  63. if (!isset($_POST['submit'])) {
  64. header('location: index.php');
  65. } else {
  66. $t_title= (empty($t_title)) ? trim($_POST['t_title']) : '???!';
  67. $t_urf = (empty($t_urf)) ? trim($_POST['t_urf']) : BASE_URL;
  68. $t_ck = (empty($t_ck)) ? trim($_POST['t_ck']) : 'NetPutweets';
  69. $t_tck = (empty($t_tck)) ? trim($_POST['t_tck']) : 'awGBKfiSSqf1B2iKGsmJQ';
  70. $t_tcs = (empty($t_tcs)) ? trim($_POST['t_tcs']) : 'hym4qJF1F6nyjISzRUCFBU4OQSIr5mrk7074vId3K8';
  71. $t_tak = (empty($t_tak)) ? trim($_POST['t_tak']) : '95a105b0faadab9daa1a5739d4f80992';
  72. $t_ta = (empty($t_ta)) ? trim($_POST['t_ta']) : 'http://api.twitter.com/1/';
  73. $t_tsa = (empty($t_tsa)) ? trim($_POST['t_tsa']) : 'http://search.twitter.com/';
  74. $t_rsl = trim($_POST['t_rsl']);
  75. $t_ivt = trim($_POST['t_ivt']);
  76. $t_psw = (empty($t_psw)) ? trim($_POST['t_psw']) : 'twitter';
  77. $t_ssl = trim($_POST['t_ssl']);
  78. if (rewritable()) {
  79. $t_url = $t_urf;
  80. } else {
  81. $t_url = $t_urf.'index.php?q=';
  82. }
  83. if ($notice == '') {
  84. $handle = fopen(ABSPATH . 'config.php', 'w');
  85. foreach ($configFile as $line_num => $line) {
  86. switch (substr($line,11,5)) {
  87. case "RYPTI":
  88. fwrite($handle, str_replace('putyourinfohere', $t_ck, $line));
  89. break;
  90. case "TH_KE":
  91. fwrite($handle, str_replace('putyourinfohere', $t_tck, $line));
  92. break;
  93. case "TH_SE":
  94. fwrite($handle, str_replace('putyourinfohere', $t_tcs, $line));
  95. break;
  96. case "TPIC_":
  97. fwrite($handle, str_replace('putyourinfohere', $t_tak, $line));
  98. break;
  99. case "E_URL":
  100. fwrite($handle, str_replace('putyourinfohere', $t_url, $line));
  101. break;
  102. case "E_URF":
  103. fwrite($handle, str_replace('putyourinfohere', $t_urf, $line));
  104. break;
  105. case "_TITL":
  106. fwrite($handle, str_replace('putyourinfohere', $t_title, $line));
  107. break;
  108. case "_URL'":
  109. fwrite($handle, str_replace('putyourinfohere', $t_ta, $line));
  110. break;
  111. case "_URLS":
  112. fwrite($handle, str_replace('putyourinfohere', $t_tsa, $line));
  113. break;
  114. case "G_URL":
  115. fwrite($handle, str_replace('0', $t_rsl, $line));
  116. break;
  117. case "ITE',":
  118. fwrite($handle, str_replace('0', $t_ivt, $line));
  119. break;
  120. case "ITE_C":
  121. fwrite($handle, str_replace('putyourinfohere', $t_psw, $line));
  122. break;
  123. case "CE_SS":
  124. fwrite($handle, str_replace('0', $t_ssl, $line));
  125. break;
  126. default:
  127. fwrite($handle, $line);
  128. }
  129. }
  130. fclose($handle);
  131. chmod(ABSPATH.'config.php', 0666);
  132. chmod(ABSPATH.'invite.php', 0666);
  133. display_header($notice);
  134. ?><p>???????????????????? &hellip; &hellip;</p><p class="step"><a href="<?php echo BASE_URL.'" class="button">??????</a></p>';
  135. }
  136. }
  137. break;
  138. }
  139. ?>