PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/install/functions.php

https://github.com/modulargaming/kittokittokitto
PHP | 279 lines | 178 code | 5 blank | 96 comment | 12 complexity | 738ff6336308555cff6372ebc8bb2a20 MD5 | raw file
  1. <?php
  2. /**
  3. * Installer
  4. *
  5. * @authors Copy112 <copy112@gmail.com> & Joff <spud2k_2000@msn.com>
  6. * @copyright Copy112 & Joff 2009
  7. * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
  8. * @package Installer for MG (modulargaming)
  9. * @version 2.0
  10. **/
  11. function parse_mysql_dump($url, $ignoreerrors = false) {
  12. $file_content = file($url);
  13. //print_r($file_content);
  14. $query = "";
  15. foreach($file_content as $sql_line) {
  16. $tsl = trim($sql_line);
  17. if (($sql_line != "") && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != "#")) {
  18. $query .= $sql_line;
  19. if(preg_match("/;\s*$/", $sql_line)) {
  20. $query = str_replace(";", "", "$query");
  21. $result = mysql_query($query);
  22. if (!$result && !$ignoreerrors) die(mysql_error());
  23. $query = "";
  24. }
  25. }
  26. }
  27. }
  28. function writeConfigFile($host,$username,$password,$name,$basepath,$publicdir) {
  29. global $success;
  30. $basepath = realpath($basepath);
  31. $content = "<?php\n";
  32. $content .= "/**\n";
  33. $content .= " * Config files; includes all critical libraries & sets paths.\n";
  34. $content .= " *\n";
  35. $content .= " * This file is part of 'Kitto_Kitto_Kitto'.\n";
  36. $content .= " *\n";
  37. $content .= " * 'Kitto_Kitto_Kitto' is free software; you can redistribute\n";
  38. $content .= " * it and/or modify it under the terms of the GNU\n";
  39. $content .= " * General Public License as published by the Free\n";
  40. $content .= " * Software Foundation; either version 3 of the License,\n";
  41. $content .= " * or (at your option) any later version.\n";
  42. $content .= " *\n";
  43. $content .= " * 'Kitto_Kitto_Kitto' is distributed in the hope that it will\n";
  44. $content .= " * be useful, but WITHOUT ANY WARRANTY; without even the\n";
  45. $content .= " * implied warranty of MERCHANTABILITY or FITNESS FOR A\n";
  46. $content .= " * PARTICULAR PURPOSE. See the GNU General Public\n";
  47. $content .= " * License for more details.\n";
  48. $content .= " *\n";
  49. $content .= " * You should have received a copy of the GNU General\n";
  50. $content .= " * Public License along with 'Kitto_Kitto_Kitto'; if not,\n";
  51. $content .= " * write to the Free Software Foundation, Inc., 51\n";
  52. $content .= " * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n";
  53. $content .= " *\n";
  54. $content .= " * @author Nicholas 'Owl' Evans <owlmanatt@gmail.com>\n";
  55. $content .= " * @copyright Nicolas Evans, 2007\n";
  56. $content .= " * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3\n";
  57. $content .= " * @package Kitto_Kitto_Kitto\n";
  58. $content .= " * @version 1.0.0\n";
  59. $content .= "**/\n";
  60. $content .= "\n";
  61. $content .= "/**\n";
  62. $content .= " * Include the exception handlers before our switch.\n";
  63. $content .= " *\n";
  64. $content .= " * This keeps the config DRY, since it's setting based on\n";
  65. $content .= " * the RELEASE_MODE and the function has to be defined\n";
  66. $content .= " * _before_ the set_exception_handler() call.\n";
  67. $content .= " **/\n";
  68. $content .= "require('includes/meta/debug.php');\n";
  69. $content .= "\n";
  70. $content .= "// Comment this out to try and pull in the RELEASE_MODE from the\n";
  71. $content .= "// .htaccess file. It may not work, depending on Apache's setup.\n";
  72. $content .= "\$_SERVER['RELEASE_MODE'] = 'DEV';\n";
  73. $content .= "\n";
  74. $content .= "switch(\$_SERVER['RELEASE_MODE'])\n";
  75. $content .= "{\n";
  76. $content .= " case 'DEV':\n";
  77. $content .= " {\n";
  78. $content .= " // Even if your host has error reporting turned off, this *should* \n";
  79. $content .= " // force PHP to send errors to the browser. This is immensely useful\n";
  80. $content .= " // during setup / development, but it's probably not wanted in a \n";
  81. $content .= " // production environment.\n";
  82. $content .= " error_reporting(E_ALL ^ E_NOTICE);\n";
  83. $content .= "\n";
  84. $content .= " // Make the errors useful for dev.\n";
  85. $content .= " set_exception_handler('development_exception_handler');\n";
  86. $content .= "\n";
  87. $content .= " \$APP_CONFIG = array(\n";
  88. $content .= " /**\n";
  89. $content .= " * The datasource name for your database.\n";
  90. $content .= " * \n";
  91. $content .= " * phptype = PEAR::DB driver to use (mysql, oci)\n";
  92. $content .= " * username = The database user to connect as.\n";
  93. $content .= " * password = The password for your database user. \n";
  94. $content .= " * database = The database to USE.\n";
  95. $content .= " * hostspec = The hostname to connect to. If you don't know what\n";
  96. $content .= " * this is, the default 'localhost' is probably correct.\n";
  97. $content .= " *\n";
  98. $content .= " * @var array\n";
  99. $content .= " **/\n";
  100. $content .= " 'db_dsn' => array(\n";
  101. $content .= " 'phptype' => 'mysql', // This can also be run on Oracle (oci).\n";
  102. $content .= " 'username' => '$username',\n";
  103. $content .= " 'password' => '$password',\n";
  104. $content .= " 'hostspec' => '$host',\n";
  105. $content .= " 'database' => '$name',\n";
  106. $content .= " ),\n";
  107. $content .= "\n";
  108. $content .= " /**\n";
  109. $content .= " * The administator's e-mail address. Password recovery notices\n";
  110. $content .= " * come from this address, too!\n";
  111. $content .= " **/\n";
  112. $content .= " 'administrator_email' => 'default@yourgame.com',\n";
  113. $content .= " 'paypal_email' => 'default@yourgame.com',\n";
  114. $content .= "\n";
  115. $content .= " /**\n";
  116. $content .= " * The absolute path (on the filesystem) to your app. On UNIX,\n";
  117. $content .= " * this should look like /something/something/something.\n";
  118. $content .= " *\n";
  119. $content .= " * If you don't know what this should be, put a file calling\n";
  120. $content .= " * phpinfo() into the folder you want KKK to live in and visit\n";
  121. $content .= " * it in your browser. Look for the 'SCRIPT_FILENAME' field.\n";
  122. $content .= " * The base path is everything *except* for the filename.\n";
  123. $content .= " **/\n";
  124. $content .= " 'base_path' => '$basepath',\n";
  125. $content .= "\n";
  126. $content .= " /**\n";
  127. $content .= " * The path to the root of your Smarty template directory.\n";
  128. $content .= " * The templates/, templates_c/, cache/, and configs/ folders\n";
  129. $content .= " * live in here.\n";
  130. $content .= " **/\n";
  131. $content .= "\n";
  132. $content .= " 'template_path' => '$basepath/template',\n";
  133. $content .= "\n";
  134. $content .= " /**\n";
  135. $content .= " * The HTMLPurifier cache must be writable by the webserver's user.\n";
  136. $content .= " * Set this to null to disable the cache (but you *want* the cache\n";
  137. $content .= " * for performance reasons!). Oh, and no trailing slash.\n";
  138. $content .= " **/\n";
  139. $content .= " 'htmlpurifier_cachedir' => '$basepath/cache',\n";
  140. $content .= "\n";
  141. $content .= " /**\n";
  142. $content .= " * The full URL (no trailing slash) to your site.\n";
  143. $content .= " * ie, 'http://demo.modulargaming.com'\n";
  144. $content .= " **/\n";
  145. $content .= " 'public_dir' => '$publicdir',\n";
  146. $content .= "\n";
  147. $content .= " /**\n";
  148. $content .= " * Standard template that will be used if the \n";
  149. $content .= " * user havenīt choosed another.\n";
  150. $content .= " * ie, 'mg'\n";
  151. $content .= " **/\n";
  152. $content .= " 'default_template' => 'mg',\n";
  153. $content .= "\n";
  154. $content .= " /**\n";
  155. $content .= " * If you have many sites at this domain, a cookie prefix\n";
  156. $content .= " * is good to ensure there's no overlap between your various\n";
  157. $content .= " * apps' cookies.\n";
  158. $content .= " **/\n";
  159. $content .= " 'cookie_prefix' => 'mg_',\n";
  160. $content .= "\n";
  161. $content .= " /**\n";
  162. $content .= " * The name of your site.\n";
  163. $content .= " **/\n";
  164. $content .= " 'site_name' => 'Modular Gaming',\n";
  165. $content .= "\n";
  166. $content .= " /**\n";
  167. $content .= " * The name of your site's currency.\n";
  168. $content .= " **/\n";
  169. $content .= " 'currency_name_singular' => 'Credit',\n";
  170. $content .= " 'currency_name_plural' => 'Credits',\n";
  171. $content .= "\n";
  172. $content .= " /**\n";
  173. $content .= " * The maximum number of pets a single user may have.\n";
  174. $content .= " **/\n";
  175. $content .= " 'max_pets' => 2,\n";
  176. $content .= "\n";
  177. $content .= " /**\n";
  178. $content .= " * The number of seconds a user must wait between creating posts\n";
  179. $content .= " * on the forums.\n";
  180. $content .= " **/\n";
  181. $content .= " 'post_interval' => 30,\n";
  182. $content .= "\n";
  183. $content .= " /**\n";
  184. $content .= " * How many seconds does it take for a pet to lose hunger/\n";
  185. $content .= " * happiness levels?\n";
  186. $content .= " **/\n";
  187. $content .= " 'hunger_interval' => (3600 * 6), // 6 hours\n";
  188. $content .= "\n";
  189. $content .= " /**\n";
  190. $content .= " * The total number of people that may be specified in a single\n";
  191. $content .= " * message's 'To' field.\n";
  192. $content .= " *\n";
  193. $content .= " * WARNING: If you want to change this, you must also update the\n";
  194. $content .= " * variable 'maxTo' in resources/script/yasashii.js to match, lest\n";
  195. $content .= " * your compose page be inconsistant with reality!\n";
  196. $content .= " **/\n";
  197. $content .= " 'max_mail_recipients' => 5,\n";
  198. $content .= "\n";
  199. $content .= " /**\n";
  200. $content .= " * The Id of the row where settings should be loaded from\n";
  201. $content .= " *\n";
  202. $content .= " * WARNING: If you want to change this, you must have a new row in\n";
  203. $content .= " * the database table calld settings\n";
  204. $content .= " **/\n";
  205. $content .= " 'settings_row' => 1,\n";
  206. $content .= " );\n";
  207. $content .= "\n";
  208. $content .= " break;\n";
  209. $content .= " } // end dev\n";
  210. $content .= "\n";
  211. $content .= " default:\n";
  212. $content .= " {\n";
  213. $content .= " die(\"RELEASE_MODE '{\$_SERVER['RELEASE_MODE']}' unrecognized; CANNOT PROCEED.\");\n";
  214. $content .= "\n";
  215. $content .= " break;\n";
  216. $content .= " } // end default\n";
  217. $content .= "\n";
  218. $content .= "} // end release mode switch\n";
  219. $content .= "\n";
  220. $content .= "// PEAR::DB gets very angry when it cannot include files in external_libs/DB/.\n";
  221. $content .= "ini_set('include_path',ini_get('include_path').':./external_lib/');\n";
  222. $content .= "\n";
  223. $content .= "/**\n";
  224. $content .= " * These are mission-critical libraries. Nothing else will function \n";
  225. $content .= " * correctly without these. APHP needs to come before any other classes,\n";
  226. $content .= " * otherwise they will cause a fatal error because their parent class is\n";
  227. $content .= " * undefined.\n";
  228. $content .= " **/\n";
  229. $content .= "//This will check if you are running windows or another os \n";
  230. $content .= "if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {\n";
  231. $content .= " require_once(\$APP_CONFIG['base_path'].'\external_lib/DB.php');\n";
  232. $content .= "} else {\n";
  233. $content .= " require_once('external_lib/DB.php');\n";
  234. $content .= "}\n";
  235. $content .= "require_once('external_lib/Log.php');\n";
  236. $content .= "require_once('external_lib/aphp/aphp.php');\n";
  237. $content .= "\n";
  238. $content .= "/**\n";
  239. $content .= " * KKK library files.\n";
  240. $content .= " **/\n";
  241. $content .= "require('includes/meta/macros.lib.php');\n";
  242. $content .= "require('includes/meta/jump_page.class.php');\n";
  243. $content .= "require('includes/meta/pagination.php');\n";
  244. $content .= "require('includes/classes/classes.config.php');\n";
  245. $content .= "require('includes/cronjobs/cronjobs.config.php');\n";
  246. $content .= "\n";
  247. $content .= "\$DB_OPTIONS = array(\n";
  248. $content .= " 'debug' => 2,\n";
  249. $content .= " 'portability' => DB_PORTABILITY_ALL,\n";
  250. $content .= ");\n";
  251. $content .= "\n";
  252. $content .= "\$db = DB::connect(\$APP_CONFIG['db_dsn'],\$DB_OPTIONS);\n";
  253. $content .= "if (PEAR::isError(\$db))\n";
  254. $content .= "{\n";
  255. $content .= " die('An error occured when attempting to connect to the database. Oops!');\n";
  256. $content .= "}\n";
  257. $content .= "\$db->setFetchMode(DB_FETCHMODE_ASSOC);\n";
  258. $content .= "\n";
  259. $content .= "?>\n";
  260. $myfile = '../includes/config.inc.php';
  261. if (is_writable('../includes/')) {
  262. $handle = fopen($myfile, 'w');
  263. fwrite($handle, $content);
  264. fclose($handle);
  265. $success = true;
  266. } else {
  267. $success = false;
  268. echo "Warning:\n";
  269. echo "<b>The folder root/includes/ does not exist or is not writable!</b><br />\n";
  270. echo "<b>What to do?</b><br />";
  271. echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Download the configuration file from <a href='output.php?h=$host&u=$username&p=$password&n=$name&basepath=$basepath&publicdir=$publicdir' target='_blank'><b style='color:#990000;'>HERE</b></a> and upload it into the root/includes/.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The final configuration file path must be: root/inclides/config.inc.php<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; When done, continue the installation wizard.<br /><br />\n";
  272. }
  273. }
  274. ?>