install.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * DZAPP Haodai Install Process
  4. *
  5. * @copyright (c) 2013 DZAPP. (http://www.dzapp.cn)
  6. * @author BranchZero <branchzero@gmail.com>
  7. * @LastModTime 2013/11/22 15:44
  8. */
  9. if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) exit('Access Denied!');
  10. $request_url = str_replace('&step='.$_GET['step'],'',$_SERVER['QUERY_STRING']);
  11. $form_url = str_replace('action=','',$request_url);
  12. showsubmenusteps($installlang['title'], array(
  13. array($installlang['choose'], $_GET['step']==''),
  14. array($installlang['reg'], $_GET['step']=='install'),
  15. array($installlang['succeed'], $_GET['step']=='ok')
  16. ));
  17. switch($_GET['step']){
  18. default:
  19. C::t('common_plugin')->update($_GET['pluginid'], array('available' => '1'));
  20. updatecache(array('plugin', 'setting', 'styles'));
  21. if(stripos($_G['siteurl'], "http://localhost") !== FALSE || stripos($_G['siteurl'], "http://127.0.0.1") !== FALSE) cpmsg($installlang['local_ban'], '', 'error');
  22. cpmsg($installlang['ifreg'], "{$request_url}&step=install&modetype=1", 'form', array(), '', TRUE, $_G['siteurl']."admin.php?{$request_url}&step=install&modetype=2");
  23. case 'install':
  24. if(extension_loaded('curl')){
  25. if($_GET['modetype'] == '1'){
  26. if(!submitcheck('submit')){
  27. showtips($installlang['hd_tip1']);
  28. showformheader("{$form_url}&step=install&modetype=1");
  29. showtableheader($installlang['reg_header']);
  30. showsetting($installlang['email'], 'email', $_G['setting']['adminemail'], 'text', '', '', $installlang['must_fill'].$installlang['email_summary']);
  31. showsetting($installlang['password'], 'passwd', '', 'password', '', '', $installlang['must_fill'].$installlang['password_summary']);
  32. showsetting($installlang['repassword'], 'repasswd', '', 'password', '', '', $installlang['must_fill']);
  33. showsetting($installlang['nickname'], 'nickname', '', 'text', '', '', $installlang['must_fill']);
  34. showsetting($installlang['contact_name'], 'realname', '', 'text', '', '', $installlang['must_fill'].$installlang['contact_name_summary']);
  35. showsetting($installlang['contact_tel'], 'tel', '', 'text', '', '', $installlang['must_fill'].$installlang['contact_tel_summary']);
  36. showsetting('QQ', 'qq', '', 'text', '', '', $installlang['must_fill'].$installlang['qq_summary']);
  37. showsubmit('submit', 'submit');
  38. showtablefooter();
  39. showformfooter();
  40. }else{
  41. if(!$_GET['email'] || !$_GET['passwd'] || !$_GET['repasswd'] || !$_GET['nickname'] || !$_GET['realname'] || !$_GET['tel'] || !$_GET['qq']) cpmsg($installlang['not_fill'], '', 'error');
  42. if($_GET['passwd'] !== $_GET['repasswd']) cpmsg($installlang['psw_not_match'], '', 'error');
  43. define('HD_API_HOST', 'http://api.haodai.com/');
  44. include_once DISCUZ_ROOT.'./source/plugin/dzapp_haodai/haodai.api.class.php';
  45. $client = new HaoDaiClient('1000002', 'sLXuof1JgsqxssYSkJVXqci4MNHftaxB');
  46. $client->set_debug(0);
  47. $config = array();
  48. $data = array(
  49. 'email' => diconv($_GET['email'], CHARSET, 'UTF-8'),
  50. 'tel' => $_GET['tel'],
  51. 'nickname' => diconv($_GET['nickname'], CHARSET, 'UTF-8'),
  52. 'passwd' => diconv($_GET['passwd'], CHARSET, 'UTF-8'),
  53. 'realname' => diconv($_GET['realname'], CHARSET, 'UTF-8'),
  54. 'qq' => $_GET['qq'],
  55. 'domain' => $_G['siteurl'],
  56. 'sitename' => diconv($_G['setting']['sitename'], CHARSET, 'UTF-8')
  57. );
  58. $result = $client->register_union_account($data);
  59. if($result['rs_code'] != '1000'){
  60. cpmsg($installlang['errmsg']."<br>".diconv($result['rs_msg'], 'UTF-8', CHARSET), '', 'error');
  61. }
  62. $config['HD_REF'] = $result['hd_ref'];
  63. define('HD_REF', $config['HD_REF']);
  64. $client = new HaoDaiClient('1000002', 'sLXuof1JgsqxssYSkJVXqci4MNHftaxB');
  65. $client->set_debug(0);
  66. $data = array(
  67. 'app_name' => diconv($_G['setting']['sitename'].' '.dgmdate($_G['timestamp'], 'Y-m-d-H:i'), CHARSET, 'UTF-8'),
  68. 'site_url' => $_G['siteurl'],
  69. 'desc' => diconv($_G['setting']['sitename'].$installlang['hd_desc'], CHARSET, 'UTF-8'),
  70. 'callback_url' => $_G['siteurl'].'plugin.php?id=dzapp_haodai:callback',
  71. );
  72. $result = $client->haodai_app_register($data);
  73. if($result['rs_code'] != '1000'){
  74. cpmsg($installlang['errmsg']."<br>".diconv($result['rs_msg'], 'UTF-8', CHARSET), '', 'error');
  75. }else{
  76. $config['HD_AKEY'] = $result['hd_akey'];
  77. $config['HD_SKEY'] = $result['hd_skey'];
  78. $config['HD_CALLBACK_URL'] = $result['hd_callback_url'];
  79. $config['HD_API_HOST'] = 'http://api.haodai.com/';
  80. $config = daddslashes($config);
  81. $configfile = "<?php \r\n";
  82. foreach($config as $key => $value){
  83. $configfile .= "define('$key', '$value');\r\n";
  84. }
  85. $configfile .= "?>";
  86. $file = DISCUZ_ROOT."./data/dzapp_haodai_config.php";
  87. $fp = fopen($file, 'w');
  88. fwrite($fp, $configfile);
  89. fclose($fp);
  90. cpmsg($installlang['install_succeed'], "{$request_url}&step=ok", 'loading', '');
  91. }
  92. }
  93. }elseif($_GET['modetype'] == '2'){
  94. if(!submitcheck('submit')){
  95. showtips($installlang['hd_tip2']);
  96. showformheader("{$form_url}&step=install&modetype=2");
  97. showtableheader($installlang['reg_header2']);
  98. showsetting($installlang['ref'], 'ref', '', 'text', '', '', $installlang['must_fill'].$installlang['ref_summary']);
  99. showsubmit('submit', 'submit');
  100. showtablefooter();
  101. showformfooter();
  102. }else{
  103. if(!$_GET['ref']) cpmsg($installlang['not_fill'], '', 'error');
  104. define('HD_API_HOST', 'http://api.haodai.com/');
  105. define('HD_REF', $_GET['ref']);
  106. include_once DISCUZ_ROOT.'./source/plugin/dzapp_haodai/haodai.api.class.php';
  107. $client = new HaoDaiClient('1000002', 'sLXuof1JgsqxssYSkJVXqci4MNHftaxB');
  108. $client->set_debug(0);
  109. $config = array();
  110. $config['HD_REF'] = $_GET['ref'];
  111. $data = array(
  112. 'app_name' => diconv($_G['setting']['sitename'].' '.dgmdate($_G['timestamp'], 'Y-m-d-H:i'), CHARSET, 'UTF-8'),
  113. 'site_url' => $_G['siteurl'],
  114. 'desc' => diconv($_G['setting']['sitename'].$installlang['hd_desc'], CHARSET, 'UTF-8'),
  115. 'callback_url' => $_G['siteurl'].'plugin.php?id=dzapp_haodai:callback',
  116. );
  117. $result = $client->haodai_app_register($data);
  118. if($result['rs_code'] != '1000'){
  119. cpmsg($installlang['errmsg']."<br>".diconv($result['rs_msg'], 'UTF-8', CHARSET), '', 'error');
  120. }else{
  121. $config['HD_AKEY'] = $result['hd_akey'];
  122. $config['HD_SKEY'] = $result['hd_skey'];
  123. $config['HD_CALLBACK_URL'] = $result['hd_callback_url'];
  124. $config['HD_API_HOST'] = 'http://api.haodai.com/';
  125. $config['HD_CITY'] = '';
  126. $config = daddslashes($config);
  127. $configfile = "<?php \r\n";
  128. foreach($config as $key => $value){
  129. $configfile .= "define('$key', '$value');\r\n";
  130. }
  131. $configfile .= "?>";
  132. $file = DISCUZ_ROOT."./data/dzapp_haodai_config.php";
  133. $fp = fopen($file, 'w');
  134. fwrite($fp, $configfile);
  135. fclose($fp);
  136. cpmsg($installlang['install_succeed'], "{$request_url}&step=ok", 'loading', '');
  137. }
  138. }
  139. }
  140. }else{
  141. cpmsg($installlang['curl_unsupported'], '', 'error');
  142. }
  143. break;
  144. case 'ok':
  145. $finish = TRUE;
  146. break;
  147. }
  148. ?>