PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/install/install.inc.php

https://bitbucket.org/kosborn/phpns
PHP | 281 lines | 235 code | 36 blank | 10 comment | 4 complexity | 6733b2d008920fa4d6475efade8e7ef3 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /* Copyright (c) 2007-08 Kyle Osborn, Alec Henriksen
  3. * phpns is free software; you can redistribute it and/or modify it under the
  4. * terms of the GNU General Public Licence (GPL) as published by the Free
  5. * Software Foundation; either version 2 of the Licence, or (at your option) any
  6. * later version.
  7. * Please see the GPL at http://www.gnu.org/copyleft/gpl.html for a complete
  8. * understanding of what this license means and how to abide by it.
  9. */
  10. if (INSTALLING == TRUE) {
  11. $databaseinfo['host'] = $data['db_host'];
  12. $databaseinfo['user'] = $data['db_user'];
  13. $databaseinfo['password'] = $data['db_password'];
  14. $databaseinfo['dbname'] = $data['db_name'];
  15. include("../inc/errors.php"); // include error profiles
  16. if ($_POST['overwrite'] != NULL) {
  17. $sql = 'DROP TABLE IF EXISTS
  18. `'.$data['db_tableprefix'].'articles`,
  19. `'.$data['db_tableprefix'].'banlist`,
  20. `'.$data['db_tableprefix'].'categories`,
  21. `'.$data['db_tableprefix'].'comments`,
  22. `'.$data['db_tableprefix'].'cookielog`,
  23. `'.$data['db_tableprefix'].'gconfig`,
  24. `'.$data['db_tableprefix'].'images`,
  25. `'.$data['db_tableprefix'].'ranks`,
  26. `'.$data['db_tableprefix'].'syslog`,
  27. `'.$data['db_tableprefix'].'templates`,
  28. `'.$data['db_tableprefix'].'themes`,
  29. `'.$data['db_tableprefix'].'userlogin`,
  30. `'.$data['db_tableprefix'].'users`;';
  31. $res = mysql_query($sql) or die("<textarea>Failed to delete existing tables in DB. Mysql: ".mysql_error."</textarea>");
  32. }
  33. //connect to mysql database for all files
  34. $mysql['connection'] = mysql_connect($databaseinfo['host'], $databaseinfo['user'], $databaseinfo['password'])
  35. or die ($error['connection']);
  36. //select mysql database
  37. $mysql['db'] = mysql_select_db($databaseinfo['dbname'],$mysql['connection'])
  38. or die ($error['database']);
  39. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'articles` (
  40. `id` int(25) NOT NULL auto_increment,
  41. `article_title` varchar(150) NOT NULL,
  42. `article_sef_title` varchar(150) NOT NULL,
  43. `article_subtitle` varchar(150) NOT NULL,
  44. `article_author` varchar(100) NOT NULL,
  45. `article_cat` varchar(15) NOT NULL,
  46. `article_text` varchar(20000) NOT NULL,
  47. `article_exptext` varchar(20000) NOT NULL,
  48. `article_imgid` varchar(100) NOT NULL,
  49. `allow_comments` varchar(1) NOT NULL,
  50. `start_date` varchar(15) NOT NULL,
  51. `end_date` varchar(15) NOT NULL,
  52. `active` varchar(1) NOT NULL,
  53. `approved` varchar(1) NOT NULL,
  54. `timestamp` varchar(15) NOT NULL,
  55. `ip` varchar(15) NOT NULL,
  56. PRIMARY KEY (`id`),
  57. KEY `article_title` (`article_title`,`timestamp`)
  58. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
  59. $res = mysql_query($sql);
  60. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'banlist` (
  61. `id` int(10) NOT NULL auto_increment,
  62. `ip` varchar(15) NOT NULL,
  63. `banned_by` varchar(20) NOT NULL,
  64. `reason` varchar(5000) NOT NULL,
  65. `timestamp` varchar(12) NOT NULL,
  66. PRIMARY KEY (`id`)
  67. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
  68. $res = mysql_query($sql);
  69. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'categories` (
  70. `id` int(15) NOT NULL auto_increment,
  71. `cat_name` varchar(100) NOT NULL,
  72. `cat_parent` varchar(10000) NOT NULL,
  73. `cat_author` varchar(100) NOT NULL,
  74. `cat_desc` varchar(1000) NOT NULL,
  75. `timestamp` varchar(15) NOT NULL,
  76. `ip` varchar(15) NOT NULL,
  77. PRIMARY KEY (`id`)
  78. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=32 ;';
  79. $res = mysql_query($sql);
  80. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'comments` (
  81. `id` int(25) NOT NULL auto_increment,
  82. `article_id` varchar(25) NOT NULL,
  83. `comment_text` varchar(1000) NOT NULL,
  84. `website` varchar(100) NOT NULL,
  85. `comment_author` varchar(20) NOT NULL,
  86. `timestamp` varchar(15) NOT NULL,
  87. `approved` varchar(1) NOT NULL,
  88. `ip` varchar(15) NOT NULL,
  89. PRIMARY KEY (`id`)
  90. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
  91. $res = mysql_query($sql);
  92. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'cookielog` (
  93. `id` int(20) NOT NULL auto_increment,
  94. `user_id` varchar(15) NOT NULL,
  95. `rank_id` varchar(15) NOT NULL,
  96. `cookie_id` varchar(32) NOT NULL,
  97. `timestamp` varchar(15) NOT NULL,
  98. `ip` varchar(15) NOT NULL,
  99. PRIMARY KEY (`id`),
  100. KEY `user_id` (`user_id`)
  101. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  102. ';
  103. $res = mysql_query($sql);
  104. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'gconfig` (
  105. `id` int(5) NOT NULL auto_increment,
  106. `name` varchar(100) NOT NULL,
  107. `v1` varchar(17) NOT NULL,
  108. `v2` varchar(10) NOT NULL,
  109. `v3` varchar(1000) NOT NULL,
  110. PRIMARY KEY (`id`)
  111. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;';
  112. $res = mysql_query($sql);
  113. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'images` (
  114. `id` int(15) NOT NULL auto_increment,
  115. `user_id` varchar(15) NOT NULL,
  116. `image_filepath` varchar(500) NOT NULL,
  117. `alt_description` varchar(100) NOT NULL,
  118. `timestamp` varchar(15) NOT NULL,
  119. `ip` varchar(15) NOT NULL,
  120. PRIMARY KEY (`id`),
  121. KEY `user_id` (`user_id`)
  122. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;';
  123. $res = mysql_query($sql);
  124. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'ranks` (
  125. `id` int(15) NOT NULL auto_increment,
  126. `rank_title` varchar(100) NOT NULL,
  127. `rank_desc` varchar(1000) NOT NULL,
  128. `rank_author` varchar(100) NOT NULL,
  129. `permissions` varchar(100) NOT NULL,
  130. `category_list` varchar(200) NOT NULL,
  131. `timestamp` varchar(15) NOT NULL,
  132. PRIMARY KEY (`id`)
  133. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;';
  134. $res = mysql_query($sql);
  135. $sql = 'CREATE TABLE `'.$data['db_tableprefix'].'syslog` (
  136. `id` int(24) NOT NULL auto_increment,
  137. `task` varchar(20) NOT NULL,
  138. `description` varchar(200) NOT NULL,
  139. `user` int(5) NOT NULL,
  140. `page` varchar(120) NOT NULL,
  141. `timestamp` varchar(12) NOT NULL,
  142. PRIMARY KEY (`id`)
  143. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;';
  144. $res = mysql_query($sql);
  145. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'templates` (
  146. `id` int(15) NOT NULL auto_increment,
  147. `template_name` varchar(100) NOT NULL,
  148. `template_desc` varchar(1000) NOT NULL,
  149. `template_author` varchar(100) NOT NULL,
  150. `timestamp` varchar(15) NOT NULL,
  151. `html_article` varchar(5000) NOT NULL,
  152. `html_comment` varchar(5000) NOT NULL,
  153. `html_form` varchar(5000) NOT NULL,
  154. `html_pagination` varchar(5000) NOT NULL,
  155. `template_selected` varchar(1) NOT NULL,
  156. PRIMARY KEY (`id`)
  157. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;';
  158. $res = mysql_query($sql);
  159. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'themes` (
  160. `id` int(10) NOT NULL auto_increment,
  161. `theme_name` varchar(100) NOT NULL,
  162. `theme_author` varchar(100) NOT NULL,
  163. `theme_dir` varchar(200) NOT NULL,
  164. `base_dir` varchar(50) NOT NULL,
  165. `timestamp` varchar(15) NOT NULL,
  166. `theme_selected` varchar(1) NOT NULL,
  167. `permissions` varchar(10000) NOT NULL,
  168. PRIMARY KEY (`id`)
  169. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;';
  170. $res = mysql_query($sql);
  171. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'userlogin` (
  172. `id` int(20) NOT NULL auto_increment,
  173. `username` varchar(15) NOT NULL,
  174. `rank_id` varchar(15) NOT NULL,
  175. `timestamp` varchar(15) NOT NULL,
  176. `ip` varchar(15) NOT NULL,
  177. PRIMARY KEY (`id`),
  178. KEY `user_id` (`username`)
  179. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=82 ;
  180. ';
  181. $res = mysql_query($sql);
  182. $sql = 'CREATE TABLE IF NOT EXISTS `'.$data['db_tableprefix'].'users` (
  183. `id` int(15) NOT NULL auto_increment,
  184. `user_name` varchar(100) NOT NULL,
  185. `full_name` varchar(150) NOT NULL,
  186. `email` varchar(100) NOT NULL,
  187. `password` varchar(40) NOT NULL,
  188. `timestamp` varchar(15) NOT NULL,
  189. `ip` varchar(15) NOT NULL,
  190. `msn` varchar(100) NOT NULL,
  191. `aim` varchar(100) NOT NULL,
  192. `yahoo` varchar(100) NOT NULL,
  193. `skype` varchar(100) NOT NULL,
  194. `display_picture` varchar(150) NOT NULL,
  195. `rank_id` varchar(15) NOT NULL,
  196. `notifications` varchar(1) NOT NULL,
  197. PRIMARY KEY (`id`)
  198. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;';
  199. $res = mysql_query($sql);
  200. $sql = "INSERT INTO `".$data['db_tableprefix']."articles` (`id`, `article_title`, `article_subtitle`, `article_author`, `article_cat`, `article_text`, `article_exptext`, `article_imgid`, `allow_comments`, `start_date`, `end_date`, `active`, `approved`, `timestamp`, `ip`) VALUES (1, 'Welcome to phpns!','','".$data['username']."','all','&lt;p&gt;If you see are viewing this message, the phpns installation was a success! This article is filed under &amp;quot;Site Wide News&amp;quot;, which is the default category that is created during installation.&lt;/p&gt;&lt;p&gt;&lt;font color=&quot;#000000&quot;&gt;You are free to modify this message, or delete it all together&lt;/font&gt;. Why should you use phpns?&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;It&#039;s free&lt;/strong&gt;. Phpns is released under the GPL license, which gives you the ability to change it, redistribute it, and use it personally or professionally.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;It&#039;s easy to integrate&lt;/strong&gt;. Only one line of code is necessary on your website (\<?php include(\'path/to/shownews.php\'); ?\>, and you have a dynamic, fully functional news system. &lt;/li&gt;&lt;li&gt;&lt;strong&gt;It&#039;s easy to install&lt;/strong&gt;. The guided installation will have you up and running in minutes, asking you just a few questions about your database setup.&lt;/li&gt;&lt;/ul&gt;','What does &amp;quot;free&amp;quot; mean? &lt;blockquote&gt;To the phpns developers, the word &amp;quot;free&amp;quot; means more than just the cost of the product. The word free means that &lt;strong&gt;you are free&lt;/strong&gt; to modify anything you want about phpns, without any license restrictions.&lt;/blockquote&gt;&lt;p&gt;Why is phpns free in both price and modification?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Because we believe in the open-source message. Closed source applications restrict the user from customizing the way the system works, and prevents the communitiy from contributing to the package. Plus, we love seeing our software being put to good use, and we love seeing modifications of our work!&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Why don&#039;t you require a &amp;quot;Powered by phpns&amp;quot; message at the bottom of each page, like other news systems?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Because we hate that.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;What can I do to help the project?&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;If you would like to be a part of the project, we always appreciate help. What you can do:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Spread the word. Recommend our system to your friends and co-workers!&lt;/li&gt;&lt;li&gt;Report bugs you&#039;ve encountered at the &lt;a href=&quot;http://launchpad.net/phpns&quot;&gt;phpns launchpad website&lt;/a&gt;. &lt;/li&gt;&lt;li&gt;Submit reviews to software review websites around the internet. As long as they are honest, this is a great way to help us.&lt;/li&gt;&lt;li&gt;Donate. This helps with hosting/domain costs, and you&#039;ll get your name on the website along with a message and URL of your blog/website.&lt;/li&gt;&lt;li&gt;Become a sponsor. If you&#039;re a hosting service, business, or organization, we&#039;re always looking for funding and bandwith.&lt;/li&gt;&lt;li&gt;Develop. Contact us on the website if you think we could use your services.&lt;/li&gt;&lt;/ul&gt;That&#039;s it. Enjoy phpns!&lt;br /&gt;&lt;/blockquote&gt;','imgid','0','','','1','1','".time()."','".$_SERVER['REMOTE_ADDR']."')";
  201. $res = mysql_query($sql);
  202. $sql = "INSERT INTO `".$data['db_tableprefix']."gconfig` (`id`, `name`, `v1`, `v2`, `v3`) VALUES
  203. (NULL, 'siteonline', '0', '0', '0'),
  204. (NULL, 'def_rsslimit', '', '', '3'),
  205. (NULL, 'def_rssorder', 'desc', '', ''),
  206. (NULL, 'def_items_per_page', '10', '', ''),
  207. (NULL, 'def_rsstitle', '', '', 'RSS feed for ".$_SERVER['SERVER_NAME']."'),
  208. (NULL, 'def_rssdesc', '', '', 'An RSS feed from ".$_SERVER['SERVER_NAME']."'),
  209. (NULL, 'def_rssenabled', '1', '', ''),
  210. (NULL, 'def_limit', '10', '', ''),
  211. (NULL, 'def_order', 'desc', '', ''),
  212. (NULL, 'def_offset', '0', '', ''),
  213. (NULL, 'timestamp_format', '', '', 'j-n-Y g:i a'),
  214. (NULL, 'def_comlimit', '', '', '100000'),
  215. (NULL, 'def_comenabled', '1', '', ''),
  216. (NULL, 'def_comorder', 'asc', '', ''),
  217. (NULL, 'global_message', '', '', 'Welcome to the phpns admin panel! Click \'change message\' to modify/delete this message.'),
  218. (NULL, 'siteonline', '0', '0', '0'),
  219. (NULL, 'wysiwyg', 'yes', '', ''),
  220. (NULL, 'sys_time_format', 'l F d, Y g:i a', '', ''),
  221. (NULL, 'line', 'yes', '', '');";
  222. $res = mysql_query($sql);
  223. $sql = "INSERT INTO `".$data['db_tableprefix']."ranks` (`id`, `rank_title`, `rank_desc`, `rank_author`, `permissions`, `category_list`, `timestamp`) VALUES
  224. (1, 'Administrators', 'Any user assigned to this rank will have full access.', '".$data['username']."', '1,1,1,1,1,1,1,1,1,1,1,1', 'all', '".time() ."');";
  225. $res = mysql_query($sql);
  226. $sql = "INSERT INTO `".$data['db_tableprefix']."themes` (`id`, `theme_name`, `theme_author`, `theme_dir`, `base_dir`, `timestamp`, `theme_selected`, `permissions`) VALUES
  227. (1, 'default', 'phpns team', 'themes/default/', 'default', '".time() ."', '1', '');";
  228. $res = mysql_query($sql);
  229. $sql = "INSERT INTO `".$data['db_tableprefix']."users` (`id`, `user_name`, `full_name`, `email`, `password`, `timestamp`, `ip`, `msn`, `aim`, `yahoo`, `skype`, `display_picture`, `rank_id`, `notifications`) VALUES
  230. (1, '".$data['username']."', '".$data['username']."', '".$data['email']."', '".$data['password'] ."', '".time() ."', '127.0.0.1', '', '', '', '', '', '1', '1');";
  231. $res = mysql_query($sql);
  232. $sql = "INSERT INTO `".$data['db_tableprefix']."categories` (`id`, `cat_name`, `cat_parent`, `cat_author`, `cat_desc`, `timestamp`, `ip`) VALUES (1, 'Site Wide News', '', '".$data['username']."', 'This is for general news on your website.', '".time()."','".$_SERVER['REMOTE_ADDR']."');";
  233. $res = mysql_query($sql);
  234. $sql = 'INSERT INTO `'.$data['db_tableprefix'].'templates` (`id`, `template_name`, `template_desc`, `template_author`, `timestamp`, `html_article`, `html_comment`, `html_form`, `html_pagination`, `template_selected`) VALUES
  235. ("1", "Default", "This is the default phpns template.", "Phpns-team", "1194252704", "&lt;div style=&quot;margin-bottom: 30px; min-height: 130px;&quot;&gt;\r\n &lt;h2 style=&quot;margin-bottom: 0pt&quot;&gt;&lt;a href=&quot;{article_href}&quot; style=&quot;text-decoration: none;&quot;&gt;{title}&lt;/a&gt;&lt;/h2&gt;\r\n &lt;h3&gt;&lt;em&gt;{sub_title}&lt;/em&gt;&lt;/h3&gt;\r\n &lt;h4 style=&quot;margin: 0 0 0 3em; font-weight: normal;&quot;&gt;Posted by &lt;a href=&quot;#&quot;&gt;{author}&lt;/a&gt; on {date}&lt;/h4&gt;\r\n &lt;span style=&quot;float: right&quot;&gt;&lt;a href=&quot;{image_location}&quot;&gt;{image}&lt;/a&gt;&lt;/span&gt;\r\n&lt;div style=&quot;float:right; padding: 0 0 10px 10px&quot;&gt;{reddit} {digg}&lt;/div&gt;\r\n {main_article}\r\n {extended_article}\r\n &lt;div id=&quot;comments&quot; style=&quot;text-align: right; clear: both;&quot;&gt;\r\n &lt;strong&gt;&lt;a href=&quot;{article_href}#comments&quot;&gt;{comment_count} comments&lt;/a&gt;&lt;/strong&gt;\r\n &lt;/div&gt;\r\n&lt;/div&gt;\r\n", "&lt;div style=&quot;background: #eee; margin: 20px 0 0 5%; padding: 5px;&quot;&gt;\r\n &lt;div style=&quot;border: 1px solid #ccc; padding: 3px; background: #ccc; margin-bo
  236. ttom: 5px;&quot;&gt; \r\n &lt;div style=&quot;text-align: right; float: right&quot;&gt; {timestamp} {admin}&lt;/div&gt; \r\n &lt;strong&gt;Posted by &lt;a href=&quot;{website}&quot;&gt;{author}&lt;/a&gt;&lt;/strong&gt; as {ip}\r\n &lt;/div&gt;\r\n {comment}\r\n&lt;/div&gt;", "&lt;form style=&quot;margin-top: 50px;&quot; action=&quot;{action}&quot; method=&quot;post&quot;&gt;\r\n &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; /&gt; &lt;label for=&quot;name&quot;&gt;Name (required)&lt;/label&gt;&lt;br /&gt;\r\n &lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot; /&gt; &lt;label for=&quot;email&quot;&gt;Email (not published) (required)&lt;/label&gt;&lt;br /&gt;\r\n &lt;input type=&quot;text&quot; name=&quot;website&quot; value=&quot;http://&quot; id=&quot;website&quot; /&gt; &lt;label for=&quot;website&quot;&gt;Website&lt;/label&gt;&lt;br /&gt;\r\n &lt;textarea cols=&quot;3&quot; rows=&quot;5&quot; name=&quot;comment&quot; style=&quot;width:100%; height: 150px&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;\r\n &lt;input type=&quot;text&quot; name=&quot;captcha&quot; style=&quot;width: 100px&quot; /&gt; &lt;label for=&quot;captcha&quot;&gt;&lt;strong&gt;What is {captcha_question}?&lt;/strong&gt;&lt;/label&gt;&lt;br /&gt;\r\n {hidden_data}\r\n {captcha_answer}\r\n &lt;input type=&quot;submit&quot; value=&quot;Submit comment&quot; id=&quot;submit&quot; /&gt;\r\n&lt;/form&gt;\r\n\r\n", "
  237. &lt;a style=&quot;padding: 3px; margin: 10px; border: 1px solid #888;&quot; href=&quot;{previous_page}&quot;&gt;Previous Page&lt;/a&gt; {middle_pages} &lt;a style=&quot;padding: 3px; margin: 10px; border: 1px solid #888;&quot; href=&quot;{next_page}&quot;&gt;Next Page&lt;/a&gt;", "1"
  238. );
  239. ';
  240. $res = mysql_query($sql) or die(mysql_error());
  241. $sql = "INSERT INTO `".$data['db_tableprefix']."syslog` (`id`, `task`, `description`, `user`, `page`, `timestamp`) VALUES
  242. (1, 'INSTALL', 'User &lt;i&gt;".$data['username']."&lt;/i&gt; has installed phpns!', '1', '/phpns/install/', ".time().")";
  243. $res = mysql_query($sql) or die(mysql_error());
  244. } //end main (installing) if
  245. ?>