PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/install.php

https://gitlab.com/pbarnhardtHG/dopresskit
PHP | 209 lines | 173 code | 26 blank | 10 comment | 24 complexity | c10c47b6f4388b4a11b0b32dcf976098 MD5 | raw file
  1. <?php
  2. /*
  3. * Press Kit Installation Script
  4. *
  5. * This script will install the Press Kit to your server.
  6. * To install this script you will need a FTP program.
  7. * Put the install.php file in an empty directory on your server to install.
  8. * Put the install.php file in the root folder of a completed installation to upgrade your installation.
  9. *
  10. */
  11. function dl_r($filename, $remote_url = 'http://www.ramiismail.com/kit/press/' ) {
  12. $remote_url .= $filename;
  13. $local_file = $filename;
  14. if( ini_get('allow_url_fopen') ) {
  15. copy($remote_url, $local_file);
  16. return true;
  17. }
  18. $fp = fopen($local_file, 'w+');
  19. $cp = curl_init();
  20. curl_setopt($cp, CURLOPT_URL, $remote_url);
  21. curl_setopt($cp, CURLOPT_RETURNTRANSFER, 1);
  22. curl_setopt($cp, CURLOPT_CONNECTTIMEOUT, 5);
  23. $buffer = curl_exec($cp);
  24. curl_close($cp);
  25. fwrite($fp, $buffer);
  26. fclose($fp);
  27. return true;
  28. }
  29. if( ini_get('safe_mode') )
  30. {
  31. echo('<h1>Server Environment Check Failed: PHP Safe Mode Enabled</h1><p>Sadly, you or your host seem to have enabled PHP Safe Mode. PHP Safe Mode results in unexpected behaviour with user-installed scripts on your server and might cause presskit() to not function correctly. Please upgrade to PHP 5.4.0 or later or disable Safe Mode to continue.</p><p>If you cannot disable Safe Mode nor upgrade and are comfortable installing scripts, please download the <a href="http://ramiismail.com/kit/press/manual-install.zip">manual installation package</a>.</p>');
  32. die();
  33. }
  34. $upgrade = 0;
  35. $file_needed = 0;
  36. if( count( glob( "*.*" ) ) > 3 )
  37. {
  38. if( file_exists('validation.js') )
  39. {
  40. if( file_exists('data.xml') )
  41. {
  42. $upgrade = 1;
  43. }
  44. if( file_exists('_data.xml') )
  45. {
  46. rename('_data.xml', '_data.bak');
  47. }
  48. }
  49. }
  50. // We'll first need to grab the CSS files. Otherwise, this'll look like crap.
  51. if( file_exists('style.css') )
  52. {
  53. unlink('style.css');
  54. }
  55. dl_r('style.css');
  56. if( !file_exists('style.css') )
  57. {
  58. dl_r('style.css', 'http://dl.dropbox.com/u/12157099/presskit/');
  59. }
  60. if ($upgrade == 0)
  61. {
  62. $title = 'Installation';
  63. } else {
  64. $title = 'Upgrade';
  65. }
  66. dl_r('archive.zip');
  67. if( !file_exists('archive.zip') )
  68. {
  69. dl_r('archive.zip', 'http://dl.dropbox.com/u/12157099/presskit/');
  70. }
  71. if( !class_exists("ZipArchive") )
  72. {
  73. dl_r('pclzip.lib');
  74. rename('pclzip.lib','pclzip.lib.php');
  75. require_once('pclzip.lib.php');
  76. $archive = new PclZip('archive.zip');
  77. if ($archive->extract() == 0)
  78. {
  79. die("Error : ".$archive->errorInfo(true));
  80. }
  81. unlink('pclzip.lib.php');
  82. }
  83. else
  84. {
  85. $zip = new ZipArchive;
  86. $res = $zip->open('archive.zip');
  87. if( $res === TRUE )
  88. {
  89. $zip->extractTo('.');
  90. $zip->close();
  91. }
  92. }
  93. if( file_exists('_data.bak') )
  94. {
  95. rename('_data.bak', '_data.xml');
  96. }
  97. if( !is_dir('images') )
  98. {
  99. $directoriesText = '<li>Creating folders...</li>';
  100. mkdir('images');
  101. } else {
  102. $directoriesText = '';
  103. }
  104. if( !is_dir('trailers') )
  105. {
  106. mkdir('trailers');
  107. }
  108. unlink('archive.zip');
  109. if( $upgrade == 0 )
  110. {
  111. $doneText = '<h2>Now comes the fun part!</h2>
  112. <p>This was rather easy &amp; painless, wasn\'t it? Well, this is where the automated part ends and where you come in. There\'s about thirty to sixty minutes of work left and said work includes some XML-editing and FTP. By all means take a break and think of what you want to say about your company. I\'ll be right here!</p>
  113. <button class=\'uk-button uk-button-primary loadInstall\'>Let\'s do this!</button>';
  114. }
  115. else
  116. {
  117. if( file_exists('_data.xml') )
  118. {
  119. unlink('_data.xml');
  120. }
  121. $doneText = '<h2>That was all!</h2>
  122. <p>Your scripts have been updated! There are a few more things that you need to do before we continue. The next steps should only take a few seconds to complete &amp; as you\'d probably want to minimize the time your press page is unavailable, it\'d be best if you do everything right away.</p>
  123. <button class=\'uk-button uk-button-primary loadUpgrade\'>What are we waiting for?!</button>';
  124. }
  125. echo '<!DOCTYPE html>
  126. <html>
  127. <head>
  128. <meta charset="utf-8">
  129. <meta name="viewport" content="width=device-width, initial-scale=1">
  130. <title>' . $title . '</title>
  131. <link href="http://cdnjs.cloudflare.com/ajax/libs/uikit/1.2.0/css/uikit.gradient.min.css" rel="stylesheet" type="text/css">
  132. <link href="style.css" rel="stylesheet" type="text/css">
  133. </head>
  134. <body>
  135. <div class="uk-container uk-container-center">
  136. <div class="uk-grid">
  137. <div id="navigation" class="uk-width-medium-1-4">
  138. <h1 id="game-title">' . $title . '</h1>
  139. <p><strong>Press Kit</strong></p>
  140. </div>
  141. <div id="content" class="uk-width-medium-3-4">
  142. <h2>Progress</h2>
  143. <p>Don\'t worry, this should be over before you really notice anything has happened.</p>
  144. <ul>
  145. <li>Downloading files...</li>
  146. <li>Installing files...</li>
  147. ' . $directoriesText . '
  148. <li>Deleting residue and temporary files...</li>
  149. </ul>
  150. ' . $doneText . '
  151. </div>
  152. </div>
  153. </div>
  154. <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  155. <script type="text/javascript">
  156. $(function() {
  157. var updateContent = function(type) {
  158. var company = $("#company").val();
  159. var nocache = new Date().getTime();
  160. $(".uk-grid").load("create.php?s=" + type + "&p=" + company +
  161. \'&no_cache=\' + nocache);
  162. setInterval(function() {
  163. // We need to generate a new time each call to avoid caching.
  164. var nocache = new Date().getTime();
  165. $(".uk-grid").load("create.php?s=" + type + "&p=" + company +
  166. \'&no_cache=\' + nocache);
  167. }, 5000);
  168. }
  169. $(".loadInstall").click(function() {
  170. updateContent("installation");
  171. });
  172. $(".loadUpgrade").click(function() {
  173. updateContent("upgrade");
  174. });
  175. });
  176. </script>
  177. </body>
  178. </html>';