Advertisement
Guest User

Untitled

a guest
Jan 9th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.53 KB | None | 0 0
  1. <?php
  2. /**
  3. * Simple WordPress Auto Installer
  4. *
  5. * @author Ohad Raz <admin@bainternet.info> | http://en.bainternet.info
  6. * @package WordPress Auto Installer
  7. * @version 0.5
  8. * @file: installer.php
  9. * @todo Better error handling.
  10. *
  11. */
  12. ?>
  13. <?php
  14. $versions = array(
  15. array(
  16. 'label' => 'Local file',
  17. 'url' => 'local',
  18. 'description' => 'Use a custom install , zip to a file named latest.zip and place in the same directory of this file.'
  19. ),
  20. array(
  21. 'label' => 'Latest version',
  22. 'url' => 'http://wordpress.org/latest.zip',
  23. 'description' => 'Download the latest stable English version'
  24. ),
  25. array(
  26. 'label' => 'Last nightly',
  27. 'url' => 'http://wordpress.org/nightly-builds/wordpress-latest.zip',
  28. 'description' => 'Download the latest beta version'
  29. ),
  30. array(
  31. 'label' => 'Hebrew - עברית',
  32. 'lang_code' => 'he_IL',
  33. 'url' => 'remote',
  34. 'description' => 'Download the latest stable Hebrew version'
  35. ),
  36. array(
  37. 'label' => 'Italian',
  38. 'lang_code' => 'it_IT',
  39. 'url' => 'remote',
  40. 'description' => 'Download the latest stable Italian version'
  41. ),
  42. array(
  43. 'label' => 'French - Français',
  44. 'lang_code' => 'fr_FR',
  45. 'url' => 'remote',
  46. 'description' => 'Download the latest stable French version'
  47. ),
  48. array(
  49. 'label' => 'Spanish - Español',
  50. 'lang_code' => 'es_ES',
  51. 'url' => 'remote',
  52. 'description' => 'Download the latest stable Spanish version'
  53. ),
  54. array(
  55. 'label' => 'Romanian - Română',
  56. 'lang_code' => 'ro_RO',
  57. 'url' => 'remote',
  58. 'description' => 'Download the latest stable Romanian version'
  59. ),
  60. array(
  61. 'label' => 'Russian — Русский',
  62. 'lang_code' => 'ru_RU',
  63. 'url' => 'remote',
  64. 'description' => 'Download the latest stable Russian version'
  65. ),
  66. array(
  67. 'label' => 'Japanese (日本語)',
  68. 'url' => 'remote',
  69. 'lang_code' => 'ja',
  70. 'description' => 'Download the latest stable Japanese version'
  71. ),
  72. array(
  73. 'label' => 'Brazilian Portuguese',
  74. 'url' => 'remote',
  75. 'lang_code' => 'pt_BR',
  76. 'description' => 'Download the latest stable Brazilian Portuguese version'
  77. ),
  78. array(
  79. 'label' => 'European Portuguese',
  80. 'url' => 'remote',
  81. 'lang_code' => 'pt_PT',
  82. 'description' => 'Download the latest stable European Portuguese version'
  83. ),
  84. array(
  85. 'label' => 'Polish - Polski',
  86. 'url' => 'remote',
  87. 'lang_code' => 'pl_PL',
  88. 'description' => 'Download the latest stable Polish version'
  89. ),
  90. array(
  91. 'label' => 'Korean - 한국어',
  92. 'url' => 'remote',
  93. 'lang_code' => 'ko_KR',
  94. 'description' => 'Download the latest stable Korean version'
  95. ),
  96. array(
  97. 'label' => 'Hungarian - Magyar',
  98. 'url' => 'remote',
  99. 'lang_code' => 'hu_HU',
  100. 'description' => 'Download the latest stable Hungarian version'
  101. ),
  102. array(
  103. 'label' => 'Dutch - Nederlands',
  104. 'url' => 'remote',
  105. 'lang_code' => 'nl_NL',
  106. 'description' => 'Download the latest stable Dutch version'
  107. ),
  108. array(
  109. 'label' => 'Vietnamse - Tiếng Việt',
  110. 'url' => 'remote',
  111. 'lang_code' => 'vi',
  112. 'description' => 'Download the latest stable Vietnamse version'
  113. ),
  114. array(
  115. 'label' => 'Thai',
  116. 'url' => 'remote',
  117. 'lang_code' => 'th',
  118. 'description' => 'Download the latest stable Thai version'
  119. ),
  120. array(
  121. 'label' => 'Swedish - Svenska',
  122. 'url' => 'remote',
  123. 'lang_code' => 'sv_SE',
  124. 'description' => 'Download the latest stable Swedish version'
  125. ),
  126. array(
  127. 'label' => 'Arabic – عربي',
  128. 'url' => 'remote',
  129. 'lang_code' => 'ar',
  130. 'description' => 'Download the latest stable Arabic version'
  131. ),
  132. array(
  133. 'label' => 'Chinese - 中文',
  134. 'url' => 'remote',
  135. 'lang_code' => 'zh_CN',
  136. 'description' => 'Download the latest stable Chinese version'
  137. ),
  138. array(
  139. 'label' => 'Slovenian - Slovenščina',
  140. 'url' => 'remote',
  141. 'lang_code' => 'sl_SI',
  142. 'description' => 'Download the latest stable Slovenian version'
  143. ),
  144. array(
  145. 'label' => 'Slovak – Slovenčina',
  146. 'url' => 'remote',
  147. 'lang_code' => 'sk_SK',
  148. 'description' => 'Download the latest stable Slovak version'
  149. ),
  150. array(
  151. 'label' => 'Danish - Dansk',
  152. 'url' => 'remote',
  153. 'lang_code' => 'da_DK',
  154. 'description' => 'Download the latest stable Danish version'
  155. ),
  156. array(
  157. 'label' => 'Czech - Čeština',
  158. 'url' => 'remote',
  159. 'lang_code' => 'cs_CZ',
  160. 'description' => 'Download the latest stable Czech version'
  161. ),
  162. array(
  163. 'label' => 'Croatian - Hrvatski',
  164. 'url' => 'remote',
  165. 'lang_code' => 'hr',
  166. 'description' => 'Download the latest stable Croatian version'
  167. ),
  168. //any other language you want goes here
  169. );
  170.  
  171. $download_ok = false;
  172. $done_zip = false;
  173. if (isset($_POST['install'])){
  174. //download latest
  175. if (isset($_POST['ver']) && in_array($_POST['ver'],array('1','2'))){
  176. $download_ok = http_get_file($versions[$_POST['ver']]['url'],'latest.zip');
  177. }elseif ($_POST['ver'] == '0'){
  178. //use local file
  179. $download_ok = file_exists('latest.zip');
  180. if(!$download_ok){
  181. echo '<br/> File dosen\'t exists, try downloading the latest version.';
  182. }
  183. }else{
  184. //use get latest stable url for remote
  185. $uri = Get_latest_version_url($versions[$_POST['ver']]['lang_code']);
  186. $download_ok = http_get_file($uri,'latest.zip');
  187. }
  188. //unzip
  189. if ($download_ok){
  190. $done_zip = extract_zip('latest.zip',$_POST['folder']);
  191. }else{
  192. echo '<br/> File dosen\'t exists, try downloading the latest version.';
  193. die();
  194. }
  195.  
  196. //create database
  197. if (isset($_POST['mk_db']) && $_POST['mk_db'] == 'mkdb' ){
  198. create_db($_POST['db_user'],$_POST['db_pass'],$_POST['server'],$_POST['db_name']);
  199. }
  200.  
  201.  
  202.  
  203. //redirect to installer
  204. if ($done_zip){
  205. ?>
  206. <div style="display: none;">
  207. <?php includejQuery(); ?>
  208. <form action="<?php echo $_POST['folder'].'/wp-admin/setup-config.php?step=2'; ?>" method="post" id="insa">
  209. <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
  210. <table class="form-table">
  211. <tbody><tr>
  212. <th scope="row"><label for="dbname">Database Name</label></th>
  213. <td><input type="text" value="<?php echo $_POST['db_name'];?>" size="25" id="dbname" name="dbname"></td>
  214. <td>The name of the database you want to run WP in. </td>
  215. </tr>
  216. <tr>
  217. <th scope="row"><label for="uname">User Name</label></th>
  218. <td><input type="text" value="<?php echo $_POST['db_user'];?>" size="25" id="uname" name="uname"></td>
  219. <td>Your MySQL username</td>
  220. </tr>
  221. <tr>
  222. <th scope="row"><label for="pwd">Password</label></th>
  223. <td><input type="text" value="<?php echo $_POST['db_pass'];?>" size="25" id="pwd" name="pwd"></td>
  224. <td>...and your MySQL password.</td>
  225. </tr>
  226. <tr>
  227. <th scope="row"><label for="dbhost">Database Host</label></th>
  228. <td><input type="text" value="<?php echo $_POST['server'];?>" size="25" id="dbhost" name="dbhost"></td>
  229. <td>You should be able to get this info from your web host, if <code>localhost</code> does not work.</td>
  230. </tr>
  231. <tr>
  232. <th scope="row"><label for="prefix">Table Prefix</label></th>
  233. <td><input type="text" size="25" value="<?php echo $_POST['db_prefix'];?>" id="prefix" name="prefix"></td>
  234. <td>If you want to run multiple WordPress installations in a single database, change this.</td>
  235. </tr>
  236. </tbody></table>
  237. <p class="step"><input id="bong" type="submit" class="button" value="Submit" name="submit"></p>
  238. </form>
  239. </div>
  240. <?php
  241. echo '<script type="text/javascript">
  242. jQuery(document).ready(function() {
  243. jQuery("#bong").click();
  244. });
  245. </script>';
  246. exit();
  247. }
  248. }else{
  249. ?>
  250. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  251. <html>
  252. <head>
  253. <title>WordPress Installer For WAMP</title>
  254. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  255. <style type="text/css">
  256. html{background:#f9f9f9;}body{background:#fff;color:#333;font-family:sans-serif;margin:2em auto;padding:1em 2em;-webkit-border-radius:3px;border-radius:3px;border:1px solid #dfdfdf;max-width:700px;}a{color:#21759B;text-decoration:none;}a:hover{color:#D54E21;}h1{border-bottom:1px solid #dadada;clear:both;color:#666;font:24px Georgia,"Times New Roman",Times,serif;margin:30px 0 0 0;padding:0;padding-bottom:7px;}h2{font-size:16px;}p,li,dd,dt{padding-bottom:2px;font-size:14px;line-height:1.5;}code,.code{font-size:14px;}ul,ol,dl{padding:5px 5px 5px 22px;}a img{border:0;}abbr{border:0;font-variant:normal;}#logo{margin:6px 0 14px 0;border-bottom:none;text-align:center;}.step{margin:20px 0 15px;}.step,th{text-align:left;padding:0;}.submit input,.button,.button-secondary{font-family:sans-serif;text-decoration:none;font-size:14px!important;line-height:16px;padding:6px 12px;cursor:pointer;border:1px solid #bbb;color:#464646;-webkit-border-radius:15px;border-radius:15px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;}.button:hover,.button-secondary:hover,.submit input:hover{color:#000;border-color:#666;}.button,.submit input,.button-secondary{background:#f2f2f2 url(../images/white-grad.png) repeat-x scroll left top;}.button:active,.submit input:active,.button-secondary:active{background:#eee url(../images/white-grad-active.png) repeat-x scroll left top;}textarea{border:1px solid #dfdfdf;-webkit-border-radius:3px;border-radius:3px;font-family:sans-serif;width:695px;}.form-table{border-collapse:collapse;margin-top:1em;width:100%;}.form-table td{margin-bottom:9px;padding:10px 20px 10px 0;border-bottom:8px solid #fff;font-size:14px;vertical-align:top;}.form-table th{font-size:14px;text-align:left;padding:16px 20px 10px 0;border-bottom:8px solid #fff;width:140px;vertical-align:top;}.form-table code{line-height:18px;font-size:14px;}.form-table p{margin:4px 0 0 0;font-size:11px;}.form-table input{line-height:20px;font-size:15px;padding:2px;border:1px #DFDFDF solid;-webkit-border-radius:3px;border-radius:3px;font-family:sans-serif;}.form-table input[type=text],.form-table input[type=password]{width:206px;}.form-table th p{font-weight:normal;}.form-table.install-success td{vertical-align:middle;padding:16px 20px 10px 0;}.form-table.install-success td p{margin:0;font-size:14px;}.form-table.install-success td code{margin:0;font-size:18px;}#error-page{margin-top:50px;}#error-page p{font-size:14px;line-height:18px;margin:25px 0 20px;}#error-page code,.code{font-family:Consolas,Monaco,monospace;}#pass-strength-result{background-color:#eee;border-color:#ddd!important;border-style:solid;border-width:1px;margin:5px 5px 5px 0;padding:5px;text-align:center;width:200px;display:none;}#pass-strength-result.bad{background-color:#ffb78c;border-color:#ff853c!important;}#pass-strength-result.good{background-color:#ffec8b;border-color:#fc0!important;}#pass-strength-result.short{background-color:#ffa0a0;border-color:#f04040!important;}#pass-strength-result.strong{background-color:#c3ff88;border-color:#8dff1c!important;}.message{border:1px solid #e6db55;padding:.3em .6em;margin:5px 0 15px;background-color:#ffffe0;}body.rtl{font-family:Tahoma,arial;}.rtl h1{font-family:arial;margin:5px -4px 0 0;}.rtl ul,.rtl ol{padding:5px 22px 5px 5px;}.rtl .step,.rtl th,.rtl .form-table th{text-align:right;}.rtl .submit input,.rtl .button,.rtl .button-secondary{margin-right:0;}.rtl #user_login,.rtl #admin_email,.rtl #pass1,.rtl #pass2{direction:ltr;}#description {background-repeat: no-repeat;color: #4C4C4C;font-family: Georgia,"Times New Roman",Times,serif;font-size: 14px;font-style: italic;min-height: 45px;padding: 15px 10px;background: none repeat scroll 0 0 #DBECF8;border-radius: 6px 6px 6px 6px;float: right;}
  257. </style>
  258. </head>
  259. <body>
  260. <div>
  261. <h1 id="logo">
  262. <img src="http://s.wordpress.org/about/images/logos/wordpress-logo-hoz-rgb.png">
  263. </h1>
  264. <p>Simple WordPress Auto Installer for WAMP ( XAMP and other stacks)</p>
  265. <p>By Bainternet <a href="http://en.bainternet.info">WordPress Developer</a></p>
  266. <?php if (!function_exists('curl_init') || !in_array('curl', get_loaded_extensions())){ ?>
  267. <p><b>cURL</b> is NOT installed or enabled, This script needs cURL to work.</p>
  268. <?php } ?>
  269. <form method="POST" name="installer_form">
  270. <p>
  271. <input name="installer" type="hidden" value="ins" />
  272. Select Your installation:
  273. <select name="ver" id="ver">
  274. <?php
  275. $radios = '';
  276. foreach ($versions as $key => $arr){
  277. $radios .= '<option value="'.$key.'" />'.$arr['label'].'</option>';
  278. }
  279. $radios = str_replace('value="1"','value="1" selected="selected"',$radios);
  280. echo $radios;
  281. ?>
  282. </select><br/>
  283. <span id="description">
  284.  
  285. </span>
  286. </p>
  287. <p>Folder to create:
  288. <input name="folder" id="folder" type="text" value="" />
  289. </p>
  290. <p>
  291. <input name="mk_db" type="checkbox" value="mkdb" checked="checked"/> Create Database?
  292. </p>
  293. <p>Database server (localhost?)
  294. <input name="server" type="text" value="localhost" />
  295. </p>
  296. <p>Database Name
  297. <input name="db_name" id="db_name" type="text" value="" />
  298. </p>
  299. <p>Database User Name
  300. <input name="db_user" type="text" value="" />
  301. </p>
  302. <p>Database User password
  303. <input name="db_pass" type="text" value="" />
  304. </p>
  305. <p>Table Prefix
  306. <input name="db_prefix" type="text" value="wp_" />
  307. </p>
  308. <p class="step">
  309. <input name="install" type="submit" class="button" value="GO" />
  310. </p>
  311. </form>
  312. <div style="text-align: center">
  313. <small>
  314. <a href="https://github.com/bainternet/Wamp-WordPress-installer/zipball/master">
  315. Download
  316. </a> |
  317. <a href="https://github.com/bainternet/Wamp-WordPress-installer/issues">
  318. Bugs and Support
  319. </a> |
  320. <a href="http://en.bainternet.info" title="My other WordPress Goodies">
  321. More WordPress Goodies
  322. </a>
  323. </small>
  324. </div>
  325. </div>
  326. <?php includejQuery(); ?>
  327. <script>
  328. var descs = [];
  329. jQuery(document).ready(function(){
  330. <?php
  331. foreach ($versions as $key => $arr){
  332. echo 'descs[' . $key . '] = "' .$arr['description']. '";';
  333. echo "\n";
  334. }
  335. ?>
  336. jQuery("#folder").change(function(){
  337. jQuery("#db_name").val(jQuery("#folder").val());
  338. });
  339. jQuery("#description").html(descs[jQuery("#ver").val()]);
  340. jQuery("#ver").change(function(){
  341. jQuery("#description").hide('fast');
  342. jQuery("#description").html(descs[jQuery(this).val()]);
  343. jQuery("#description").show('2300');
  344. });
  345. });
  346. </script>
  347. </body>
  348. </html>
  349. <?php
  350. }
  351.  
  352.  
  353. /**
  354. * http_get_file simple function to download a file using curl
  355. *
  356. * @author Ohad Raz <admin@bainternet.info>
  357. * @since 0.1
  358. * @param (string) $remote_url url of file to download
  359. * @param (string) $local_file name of local file to create
  360. *
  361. * @return (bool)
  362. */
  363. function http_get_file($remote_url, $local_file){
  364. $fp = fopen($local_file, 'w');
  365. $cp = curl_init($remote_url);
  366. curl_setopt($cp, CURLOPT_FILE, $fp);
  367. $buffer = curl_exec($cp);
  368. curl_close($cp);
  369. fclose($fp);
  370. return true;
  371. }
  372.  
  373.  
  374. /**
  375. * extract_zip simple function to extrac a zip archive to a given folder
  376. *
  377. * @author Ohad Raz <admin@bainternet.info>
  378. * @since 0.1
  379. * @param (string) $zip_File zip file name (full path)
  380. * @param (string) $folder destenation folder full path
  381. *
  382. * @return (bool)
  383. */
  384. function extract_zip($zip_File,$folder){
  385. $zip = new ZipArchive() ;
  386. // open archive
  387. if ($zip->open($zip_File) !== TRUE) {
  388. die ('Could not open archive');
  389. }
  390. $zip->extractTo(getcwd());
  391. // close archive
  392. // print success message
  393. $zip->close();
  394. rename(getcwd().'/wordpress', getcwd().'/'.$folder);
  395. return true;
  396. }
  397.  
  398. /**
  399. * create_db function to create a mysql database
  400. *
  401. * @author Ohad Raz <admin@bainternet.info>
  402. * @since 0.1
  403. * @param (string) $user mysql user name
  404. * @param (string) $pass mysql user password
  405. * @param (string) $server server name
  406. * @param (string) $db_name database name to create
  407. *
  408. * @return (bool)
  409. */
  410. function create_db($user,$pass,$server,$db_name){
  411. $link = mysql_connect($server, $user, $pass);
  412. if (!$link) {
  413. die('Could not connect: ' . mysql_error());
  414. }
  415. $sql = 'CREATE DATABASE IF NOT EXISTS '.$db_name;
  416. if (mysql_query($sql, $link)) {
  417. return true;
  418. } else {
  419. return false;
  420. }
  421. }
  422.  
  423. /**
  424. * Get_latest_version_url function to get the latest version download url
  425. *
  426. * @author Ohad Raz <admin@bainternet.info>
  427. * @since 0.3
  428. * @param (string) $local language local key
  429. *
  430. * @return (string)
  431. */
  432. function Get_latest_version_url($local = "en_US"){
  433. $url = 'http://api.wordpress.org/core/version-check/1.6/?locale='.$local;
  434. $c = curl_init($url);
  435. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  436. $page = curl_exec($c);
  437. curl_close($c);
  438. $ret = unserialize( $page);
  439. /* echo '<pre>';
  440. echo $local;
  441. var_dump($ret);
  442. echo '</pre>';
  443. die();*/
  444. return $ret['offers'][0]['download'];
  445. }
  446.  
  447. /**
  448. * includejQuery simple function to include jQuery js
  449. *
  450. * @author Ohad Raz <admin@bainternet.info>
  451. * @since 0.3
  452. *
  453. * @return VOID
  454. */
  455. function includejQuery(){
  456. ?>
  457. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
  458. <?php
  459. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement