PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/install.php

http://feed-on-feeds.googlecode.com/
PHP | 362 lines | 301 code | 48 blank | 13 comment | 24 complexity | 100eef5d59f5f291c2b387bca701163d MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * This file is part of FEED ON FEEDS - http://feedonfeeds.com/
  4. *
  5. * install.php - creates tables and cache directory, if they don't exist
  6. *
  7. *
  8. * Copyright (C) 2004-2007 Stephen Minutillo
  9. * steve@minutillo.com - http://minutillo.com/steve/
  10. *
  11. * Distributed under the GPL - see LICENSE
  12. *
  13. */
  14. $fof_no_login = true;
  15. $fof_installer = true;
  16. include_once("fof-main.php");
  17. fof_set_content_type();
  18. // compatibility testing code lifted from SimplePie
  19. function get_curl_version()
  20. {
  21. if (is_array($curl = curl_version()))
  22. {
  23. $curl = $curl['version'];
  24. }
  25. else if (preg_match('/curl\/(\S+)(\s|$)/', $curl, $match))
  26. {
  27. $curl = $match[1];
  28. }
  29. else
  30. {
  31. $curl = 0;
  32. }
  33. return $curl;
  34. }
  35. $php_ok = (function_exists('version_compare') && version_compare(phpversion(), '4.3.2', '>='));
  36. $xml_ok = extension_loaded('xml');
  37. $pcre_ok = extension_loaded('pcre');
  38. $mysql_ok = extension_loaded('mysql');
  39. $curl_ok = (extension_loaded('curl') && version_compare(get_curl_version(), '7.10.5', '>='));
  40. $zlib_ok = extension_loaded('zlib');
  41. $mbstring_ok = extension_loaded('mbstring');
  42. $iconv_ok = extension_loaded('iconv');
  43. ?>
  44. <!DOCTYPE html>
  45. <html>
  46. <head><title>feed on feeds - installation</title>
  47. <link rel="stylesheet" href="fof.css" media="screen" />
  48. <script src="fof.js" type="text/javascript"></script>
  49. <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />
  50. <style>
  51. body
  52. {
  53. font-family: georgia;
  54. font-size: 16px;
  55. }
  56. div
  57. {
  58. background: #eee;
  59. border: 1px solid black;
  60. width: 75%;
  61. margin: 5em auto;
  62. padding: 1.5em;
  63. }
  64. hr
  65. {
  66. height:0;
  67. border:0;
  68. border-top:1px solid #999;
  69. }
  70. .fail { color: red; }
  71. .pass { color: green; }
  72. .warn { color: #a60; }
  73. </style>
  74. </head>
  75. <body><div> <center style="font-size: 20px;"><a href="http://feedonfeeds.com/">Feed on Feeds</a> - Installation</center><br>
  76. <?php
  77. if($_GET['password'] && $_GET['password'] == $_GET['password2'] )
  78. {
  79. $password_hash = md5($_GET['password'] . 'admin');
  80. fof_safe_query("insert into $FOF_USER_TABLE (user_id, user_name, user_password_hash, user_level) values (1, 'admin', '%s', 'admin')", $password_hash);
  81. echo '<center><b>OK! Setup complete! <a href=".">Login as admin</a>, and start subscribing!</center></b></div></body></html>';
  82. }
  83. else
  84. {
  85. if($_GET['password'] != $_GET['password2'] )
  86. {
  87. echo '<center><font color="red">Passwords do not match!</font></center><br><br>';
  88. }
  89. ?>
  90. Checking compatibility...
  91. <?php
  92. if($php_ok) echo "<span class='pass'>PHP ok...</span> ";
  93. else
  94. {
  95. echo "<br><span class='fail'>Your PHP version is too old!</span> Feed on Feeds requires at least PHP 4.3.2. Sorry!";
  96. echo "</div></body></html>";
  97. exit;
  98. }
  99. if($xml_ok) echo "<span class='pass'>XML ok...</span> ";
  100. else
  101. {
  102. echo "<br><span class='fail'>Your PHP installation is missing the XML extension!</span> This is required by Feed on Feeds. Sorry!";
  103. echo "</div></body></html>";
  104. exit;
  105. }
  106. if($pcre_ok) echo "<span class='pass'>PCRE ok...</span> ";
  107. else
  108. {
  109. echo "<br><span class='fail'>Your PHP installation is missing the PCRE extension!</span> This is required by Feed on Feeds. Sorry!";
  110. echo "</div></body></html>";
  111. exit;
  112. }
  113. if($mysql_ok) echo "<span class='pass'>MySQL ok...</span> ";
  114. else
  115. {
  116. echo "<br><span class='fail'>Your PHP installation is missing the MySQL extension!</span> This is required by Feed on Feeds. Sorry!";
  117. echo "</div></body></html>";
  118. exit;
  119. }
  120. if($curl_ok) echo "<span class='pass'>cURL ok...</span> ";
  121. else
  122. {
  123. echo "<br><span class='warn'>Your PHP installation is either missing the cURL extension, or it is too old!</span> cURL version 7.10.5 or later is required to be able to subscribe to https or digest authenticated feeds.<br>";
  124. }
  125. if($zlib_ok) echo "<span class='pass'>Zlib ok...</span> ";
  126. else
  127. {
  128. echo "<br><span class='warn'>Your PHP installation is missing the Zlib extension!</span> Feed on Feeds will not be able to save bandwidth by requesting compressed feeds.<br>";
  129. }
  130. if($iconv_ok) echo "<span class='pass'>iconv ok...</span> ";
  131. else
  132. {
  133. echo "<br><span class='warn'>Your PHP installation is missing the iconv extension!</span> The number of international languages that Feed on Feeds can handle will be reduced.<br>";
  134. }
  135. if($mbstring_ok) echo "<span class='pass'>mbstring ok...</span> ";
  136. else
  137. {
  138. echo "<br><span class='warn'>Your PHP installation is missing the mbstring extension!</span> The number of international languages that Feed on Feeds can handle will be reduced.<br>";
  139. }
  140. ?>
  141. <br>Minimum requirements met!
  142. <hr>
  143. Creating tables...
  144. <?php
  145. $tables[] = <<<EOQ
  146. CREATE TABLE IF NOT EXISTS `$FOF_FEED_TABLE` (
  147. `feed_id` int(11) NOT NULL auto_increment,
  148. `feed_url` text NOT NULL,
  149. `feed_title` text NOT NULL,
  150. `feed_link` text NOT NULL,
  151. `feed_description` text NOT NULL,
  152. `feed_image` text,
  153. `feed_image_cache_date` int(11) default '0',
  154. `feed_cache_date` int(11) default '0',
  155. `feed_cache_attempt_date` int(11) default '0',
  156. `feed_cache` text,
  157. PRIMARY KEY (`feed_id`)
  158. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  159. EOQ;
  160. $tables[] = <<<EOQ
  161. CREATE TABLE IF NOT EXISTS `$FOF_ITEM_TABLE` (
  162. `item_id` int(11) NOT NULL auto_increment,
  163. `feed_id` int(11) NOT NULL default '0',
  164. `item_guid` text NOT NULL,
  165. `item_link` text NOT NULL,
  166. `item_cached` int(11) NOT NULL default '0',
  167. `item_published` int(11) NOT NULL default '0',
  168. `item_updated` int(11) NOT NULL default '0',
  169. `item_title` text NOT NULL,
  170. `item_content` text NOT NULL,
  171. PRIMARY KEY (`item_id`),
  172. KEY `feed_id` (`feed_id`),
  173. KEY `item_guid` (`item_guid`(255)),
  174. KEY `feed_id_item_cached` (`feed_id`,`item_cached`)
  175. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  176. EOQ;
  177. $tables[] = <<<EOQ
  178. CREATE TABLE IF NOT EXISTS `$FOF_ITEM_TAG_TABLE` (
  179. `user_id` int(11) NOT NULL default '0',
  180. `item_id` int(11) NOT NULL default '0',
  181. `tag_id` int(11) NOT NULL default '0',
  182. PRIMARY KEY (`user_id`,`item_id`,`tag_id`)
  183. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  184. EOQ;
  185. $tables[] = <<<EOQ
  186. CREATE TABLE IF NOT EXISTS `$FOF_SUBSCRIPTION_TABLE` (
  187. `feed_id` int(11) NOT NULL default '0',
  188. `user_id` int(11) NOT NULL default '0',
  189. `subscription_prefs` text,
  190. PRIMARY KEY (`feed_id`,`user_id`)
  191. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  192. EOQ;
  193. $tables[] = <<<EOQ
  194. CREATE TABLE IF NOT EXISTS `$FOF_TAG_TABLE` (
  195. `tag_id` int(11) NOT NULL auto_increment,
  196. `tag_name` char(100) NOT NULL default '',
  197. PRIMARY KEY (`tag_id`),
  198. UNIQUE KEY (`tag_name`)
  199. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  200. EOQ;
  201. $tables[] = <<<EOQ
  202. CREATE TABLE IF NOT EXISTS `$FOF_USER_TABLE` (
  203. `user_id` int(11) NOT NULL auto_increment,
  204. `user_name` varchar(100) NOT NULL default '',
  205. `user_password_hash` varchar(32) NOT NULL default '',
  206. `user_level` enum('user','admin') NOT NULL default 'user',
  207. `user_prefs` text,
  208. PRIMARY KEY (`user_id`)
  209. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  210. EOQ;
  211. foreach($tables as $table)
  212. {
  213. if(!fof_db_query($table, 1))
  214. {
  215. exit ("Can't create table. MySQL says: <b>" . mysql_error() . "</b><br>" );
  216. }
  217. }
  218. ?>
  219. Tables exist.<hr>
  220. <?php
  221. $result = fof_db_query("show columns from $FOF_FEED_TABLE like 'feed_image_cache_date'");
  222. if(mysql_num_rows($result) == 0)
  223. {
  224. print "Upgrading schema...";
  225. fof_db_query("ALTER TABLE $FOF_FEED_TABLE ADD `feed_image_cache_date` INT( 11 ) DEFAULT '0' AFTER `feed_image` ;");
  226. print "Done.<hr>";
  227. }
  228. ?>
  229. <?php
  230. $result = fof_db_query("show columns from $FOF_USER_TABLE like 'user_password_hash'");
  231. if(mysql_num_rows($result) == 0)
  232. {
  233. print "Upgrading schema...";
  234. fof_db_query("ALTER TABLE $FOF_USER_TABLE CHANGE `user_password` `user_password_hash` VARCHAR( 32 ) NOT NULL");
  235. fof_db_query("update $FOF_USER_TABLE set user_password_hash = md5(concat(user_password_hash, user_name))");
  236. print "Done.<hr>";
  237. }
  238. ?>
  239. <?php
  240. $result = fof_db_query("show columns from $FOF_FEED_TABLE like 'feed_cache_attempt_date'");
  241. if(mysql_num_rows($result) == 0)
  242. {
  243. print "Upgrading schema...";
  244. fof_db_query("ALTER TABLE $FOF_FEED_TABLE ADD `feed_cache_attempt_date` INT( 11 ) DEFAULT '0' AFTER `feed_cache_date` ;");
  245. print "Done.<hr>";
  246. }
  247. ?>
  248. Inserting initial data...
  249. <?php
  250. fof_db_query("insert into $FOF_TAG_TABLE (tag_id, tag_name) values (1, 'unread')", 1);
  251. fof_db_query("insert into $FOF_TAG_TABLE (tag_id, tag_name) values (2, 'star')", 1);
  252. ?>
  253. Done.<hr>
  254. Checking cache directory...
  255. <?php
  256. if ( ! file_exists( "cache" ) )
  257. {
  258. $status = @mkdir( "cache", 0755 );
  259. if ( ! $status )
  260. {
  261. echo "<font color='red'>Can't create directory <code>" . getcwd() . "/cache/</code>.<br>You will need to create it yourself, and make it writeable by your PHP process.<br>Then, reload this page.</font>";
  262. echo "</div></body></html>";
  263. exit;
  264. }
  265. }
  266. if(!is_writable( "cache" ))
  267. {
  268. echo "<font color='red'>The directory <code>" . getcwd() . "/cache/</code> exists, but is not writable.<br>You will need to make it writeable by your PHP process.<br>Then, reload this page.</font>";
  269. echo "</div></body></html>";
  270. exit;
  271. }
  272. ?>
  273. Cache directory exists and is writable.<hr>
  274. <?php
  275. $result = fof_db_query("select * from $FOF_USER_TABLE where user_name = 'admin'");
  276. if(mysql_num_rows($result) == 0) {
  277. ?>
  278. You now need to choose an initial password for the 'admin' account:<br>
  279. <form>
  280. <table>
  281. <tr><td>Password:</td><td><input type=password name=password></td></tr>
  282. <tr><td>Password again:</td><td><input type=password name=password2></td></tr>
  283. </table>
  284. <input type=submit value="Set Password">
  285. </form>
  286. <?php } else { ?>
  287. 'admin' account already exists.<br>
  288. <br><b><center>OK! Setup complete! <a href=".">Login as admin</a>, and start subscribing!</center></b>
  289. <?php } } ?>
  290. </div></body></html>