2009-08-03 16:42:04 +04:00
< ? php
/*
* This file is part of FEED ON FEEDS - http :// feedonfeeds . com /
*
* install . php - creates tables and cache directory , if they don ' t exist
*
2014-11-01 15:21:34 +03:00
* Copyright ( C ) 2004 - 2007 Stephen Minutillo steve @ minutillo . com http :// minutillo . com / steve /
* ( C ) 2009 - 2014 Vitaliy Filippov vitalif @ mail . ru http :// yourcmc . ru / wiki /
2009-08-03 16:42:04 +04:00
*
* Distributed under the GPL - see LICENSE
*
*/
$fof_no_login = true ;
$fof_installer = true ;
include_once ( " fof-main.php " );
fof_set_content_type ();
// compatibility testing code lifted from SimplePie
function get_curl_version ()
{
2010-01-25 20:30:38 +03:00
if ( is_array ( $curl = curl_version ()))
$curl = $curl [ 'version' ];
else if ( preg_match ( '/curl\/(\S+)(\s|$)/' , $curl , $match ))
$curl = $match [ 1 ];
else
$curl = 0 ;
return $curl ;
2009-08-03 16:42:04 +04:00
}
$php_ok = ( function_exists ( 'version_compare' ) && version_compare ( phpversion (), '4.3.2' , '>=' ));
$xml_ok = extension_loaded ( 'xml' );
$pcre_ok = extension_loaded ( 'pcre' );
2015-09-16 13:47:49 +03:00
$mysql_ok = extension_loaded ( 'mysqli' );
2009-08-03 16:42:04 +04:00
$curl_ok = ( extension_loaded ( 'curl' ) && version_compare ( get_curl_version (), '7.10.5' , '>=' ));
$zlib_ok = extension_loaded ( 'zlib' );
$mbstring_ok = extension_loaded ( 'mbstring' );
$iconv_ok = extension_loaded ( 'iconv' );
?>
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
2010-01-25 20:30:38 +03:00
< head >
< title > feed on feeds - installation </ title >
< meta http - equiv = " Content-Type " content = " text/html; charset=utf-8 " />
< link rel = " stylesheet " href = " fof.css " media = " screen " />
< script src = " fof.js " type = " text/javascript " ></ script >
< meta name = " ROBOTS " content = " NOINDEX, NOFOLLOW " />
< style >
body
{
font - family : georgia ;
font - size : 16 px ;
}
div
{
background : #eee;
border : 1 px solid black ;
width : 75 % ;
margin : 5 em auto ;
padding : 1.5 em ;
}
hr
{
height : 0 ;
border : 0 ;
border - top : 1 px solid #999;
}
. fail { color : red ; }
. pass { color : green ; }
. warn { color : #a60; }
</ style >
</ head >
2009-08-03 16:42:04 +04:00
2010-01-25 20:30:38 +03:00
< body >< div >< center style = " font-size: 20px; " >< a href = " http://feedonfeeds.com/ " > Feed on Feeds </ a > - Installation </ center >< br >
2009-08-03 16:42:04 +04:00
< ? php
2014-12-10 00:28:17 +03:00
if ( ! empty ( $_GET [ 'password' ]))
2009-08-03 16:42:04 +04:00
{
2014-12-10 00:28:17 +03:00
if ( $_GET [ 'password' ] == $_GET [ 'password2' ])
{
$password_hash = md5 ( $_GET [ 'password' ] . 'admin' );
fof_safe_query ( " insert into $FOF_USER_TABLE (user_id, user_name, user_password_hash, user_level) values (1, 'admin', '%s', 'admin') " , $password_hash );
echo '<center><b>OK! Setup complete! <a href=".">Login as admin</a>, and start subscribing!</center></b></div></body></html>' ;
}
else
2009-08-03 16:42:04 +04:00
{
echo '<center><font color="red">Passwords do not match!</font></center><br><br>' ;
}
2014-12-10 00:28:17 +03:00
}
else
{
2009-08-03 16:42:04 +04:00
?>
Checking compatibility ...
< ? php
if ( $php_ok ) echo " <span class='pass'>PHP ok...</span> " ;
else
{
echo " <br><span class='fail'>Your PHP version is too old!</span> Feed on Feeds requires at least PHP 4.3.2. Sorry! " ;
echo " </div></body></html> " ;
exit ;
}
if ( $xml_ok ) echo " <span class='pass'>XML ok...</span> " ;
else
{
echo " <br><span class='fail'>Your PHP installation is missing the XML extension!</span> This is required by Feed on Feeds. Sorry! " ;
echo " </div></body></html> " ;
exit ;
}
if ( $pcre_ok ) echo " <span class='pass'>PCRE ok...</span> " ;
else
{
echo " <br><span class='fail'>Your PHP installation is missing the PCRE extension!</span> This is required by Feed on Feeds. Sorry! " ;
echo " </div></body></html> " ;
exit ;
}
if ( $mysql_ok ) echo " <span class='pass'>MySQL ok...</span> " ;
else
{
2015-09-16 13:47:49 +03:00
echo " <br><span class='fail'>Your PHP installation is missing the MySQLi extension!</span> This is required by Feed on Feeds. Sorry! " ;
2009-08-03 16:42:04 +04:00
echo " </div></body></html> " ;
exit ;
}
if ( $curl_ok ) echo " <span class='pass'>cURL ok...</span> " ;
else
{
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> " ;
}
if ( $zlib_ok ) echo " <span class='pass'>Zlib ok...</span> " ;
else
{
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> " ;
}
if ( $iconv_ok ) echo " <span class='pass'>iconv ok...</span> " ;
else
{
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> " ;
}
if ( $mbstring_ok ) echo " <span class='pass'>mbstring ok...</span> " ;
else
{
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> " ;
}
?>
< br > Minimum requirements met !
< hr >
Creating tables ...
< ? php
$tables [] = <<< EOQ
CREATE TABLE IF NOT EXISTS `$FOF_FEED_TABLE` (
`feed_id` int ( 11 ) NOT NULL auto_increment ,
`feed_url` text NOT NULL ,
`feed_title` text NOT NULL ,
`feed_link` text NOT NULL ,
`feed_description` text NOT NULL ,
`feed_image` text ,
`feed_image_cache_date` int ( 11 ) default '0' ,
`feed_cache_date` int ( 11 ) default '0' ,
`feed_cache_attempt_date` int ( 11 ) default '0' ,
`feed_cache` text ,
2009-08-21 17:02:59 +04:00
PRIMARY KEY ( `feed_id` )
2014-12-10 00:28:17 +03:00
) ENGINE = InnoDB COLLATE = utf8_unicode_ci ;
2009-08-21 17:02:59 +04:00
EOQ ;
$tables [] = <<< EOQ
CREATE TABLE IF NOT EXISTS `$FOF_TAG_TABLE` (
`tag_id` int ( 11 ) NOT NULL auto_increment ,
`tag_name` char ( 100 ) NOT NULL default '' ,
PRIMARY KEY ( `tag_id` ),
UNIQUE KEY ( `tag_name` )
2014-12-10 00:28:17 +03:00
) ENGINE = InnoDB COLLATE = utf8_unicode_ci ;
2009-08-21 17:02:59 +04:00
EOQ ;
$tables [] = <<< EOQ
CREATE TABLE IF NOT EXISTS `$FOF_USER_TABLE` (
`user_id` int ( 11 ) NOT NULL auto_increment ,
`user_name` varchar ( 100 ) NOT NULL default '' ,
`user_password_hash` varchar ( 32 ) NOT NULL default '' ,
`user_level` enum ( 'user' , 'admin' ) NOT NULL default 'user' ,
`user_prefs` text ,
PRIMARY KEY ( `user_id` )
2014-12-10 00:28:17 +03:00
) ENGINE = InnoDB COLLATE = utf8_unicode_ci ;
2009-08-03 16:42:04 +04:00
EOQ ;
$tables [] = <<< EOQ
CREATE TABLE IF NOT EXISTS `$FOF_ITEM_TABLE` (
`item_id` int ( 11 ) NOT NULL auto_increment ,
`feed_id` int ( 11 ) NOT NULL default '0' ,
`item_guid` text NOT NULL ,
`item_link` text NOT NULL ,
`item_cached` int ( 11 ) NOT NULL default '0' ,
`item_published` int ( 11 ) NOT NULL default '0' ,
`item_updated` int ( 11 ) NOT NULL default '0' ,
`item_title` text NOT NULL ,
2010-02-15 22:06:58 +03:00
`item_author` text NOT NULL ,
2009-08-03 16:42:04 +04:00
`item_content` text NOT NULL ,
PRIMARY KEY ( `item_id` ),
KEY `item_guid` ( `item_guid` ( 255 )),
2012-11-14 00:48:36 +04:00
KEY `feed_id_item_cached` ( `feed_id` , `item_cached` ),
KEY `item_published` ( `item_published` ),
2009-08-21 17:02:59 +04:00
FOREIGN KEY ( `feed_id` ) REFERENCES `$FOF_FEED_TABLE` ( `feed_id` ) ON UPDATE CASCADE
2014-12-10 00:28:17 +03:00
) ENGINE = InnoDB COLLATE = utf8_unicode_ci ;
2009-08-03 16:42:04 +04:00
EOQ ;
$tables [] = <<< EOQ
CREATE TABLE IF NOT EXISTS `$FOF_ITEM_TAG_TABLE` (
`user_id` int ( 11 ) NOT NULL default '0' ,
`item_id` int ( 11 ) NOT NULL default '0' ,
`tag_id` int ( 11 ) NOT NULL default '0' ,
2014-11-01 15:21:34 +03:00
`item_published` int ( 11 ) NOT NULL default '0' ,
2014-11-01 16:12:13 +03:00
`feed_id` int ( 11 ) NOT NULL default '0' ,
2012-11-29 02:16:43 +04:00
PRIMARY KEY ( `tag_id` , `user_id` , `item_id` ),
2014-11-01 15:21:34 +03:00
KEY `tag_id_user_id_item_published_item_id` ( tag_id , user_id , item_published , item_id ),
2014-11-01 16:12:13 +03:00
KEY `tag_id_user_id_feed_id` ( tag_id , user_id , feed_id ),
KEY `item_id_user_id_tag_id` ( item_id , user_id , tag_id ),
2009-08-21 17:02:59 +04:00
FOREIGN KEY ( `tag_id` ) REFERENCES `$FOF_TAG_TABLE` ( `tag_id` ) ON DELETE CASCADE ON UPDATE CASCADE ,
FOREIGN KEY ( `user_id` ) REFERENCES `$FOF_USER_TABLE` ( `user_id` ) ON DELETE CASCADE ON UPDATE CASCADE ,
2014-12-09 18:26:26 +03:00
FOREIGN KEY ( `item_id` ) REFERENCES `$FOF_ITEM_TABLE` ( `item_id` ) ON DELETE CASCADE ON UPDATE CASCADE ,
FOREIGN KEY ( `feed_id` ) REFERENCES `$FOF_FEED_TABLE` ( `feed_id` ) ON DELETE CASCADE ON UPDATE CASCADE
2014-12-10 00:28:17 +03:00
) ENGINE = InnoDB COLLATE = utf8_unicode_ci ;
2009-08-03 16:42:04 +04:00
EOQ ;
$tables [] = <<< EOQ
CREATE TABLE IF NOT EXISTS `$FOF_SUBSCRIPTION_TABLE` (
`feed_id` int ( 11 ) NOT NULL default '0' ,
`user_id` int ( 11 ) NOT NULL default '0' ,
`subscription_prefs` text ,
2009-08-21 17:02:59 +04:00
PRIMARY KEY ( `feed_id` , `user_id` ),
FOREIGN KEY ( `user_id` ) REFERENCES `$FOF_USER_TABLE` ( `user_id` ) ON DELETE CASCADE ON UPDATE CASCADE ,
FOREIGN KEY ( `feed_id` ) REFERENCES `$FOF_FEED_TABLE` ( `feed_id` ) ON DELETE CASCADE ON UPDATE CASCADE
2014-12-10 00:28:17 +03:00
) ENGINE = InnoDB COLLATE = utf8_unicode_ci ;
2009-08-03 16:42:04 +04:00
EOQ ;
foreach ( $tables as $table )
2015-09-16 13:47:49 +03:00
fof_db_query ( $table , 1 );
2009-08-03 16:42:04 +04:00
?>
Tables exist .< hr >
2010-01-25 20:30:38 +03:00
Upgrading schema ...
2009-08-03 16:42:04 +04:00
< ? php
2014-12-10 00:28:17 +03:00
function add_fk ( $show_create_table , $table , $column , $ref_table , $action = 'on delete cascade on update cascade' )
{
2015-09-16 13:47:49 +03:00
if ( ! strpos ( $show_create_table , " FOREIGN KEY (` $column `) " ))
fof_db_query ( " alter table $table add foreign key ( $column ) references $ref_table ( $column ) $action " );
2014-12-10 00:28:17 +03:00
}
$r = fof_db_query ( " show table status " );
2015-09-16 13:47:49 +03:00
while ( $row = fof_db_get_row ( $r ))
2014-12-10 00:28:17 +03:00
{
$table = $row [ 'Name' ];
$alter = array ();
if ( strtolower ( $row [ 'Engine' ]) === 'myisam' )
$alter [] = 'engine=innodb' ;
if ( strpos ( $row [ 'Collation' ], 'utf8' ) === false )
$alter [] = 'convert to character set utf8 collate utf8_unicode_ci' ;
$r2 = fof_db_query ( " desc $table " );
2015-09-16 13:47:49 +03:00
while ( $row2 = fof_db_get_row ( $r2 ))
2014-12-10 00:28:17 +03:00
if ( strtolower ( $row2 [ 'Type' ]) == 'mediumtext' )
$alter [] = 'change ' . $row2 [ 'Field' ] . ' ' . $row2 [ 'Field' ] . ' text' . ( strtolower ( $row2 [ 'Null' ]) == 'no' ? ' not null' : '' );
2015-09-16 13:47:49 +03:00
if ( $alter )
fof_db_query ( " alter table $table " . implode ( ', ' , $alter ));
2014-12-10 00:28:17 +03:00
}
2014-12-09 18:26:26 +03:00
2015-09-16 13:47:49 +03:00
if ( ! fof_num_rows ( fof_db_query ( " show columns from $FOF_FEED_TABLE like 'feed_image_cache_date' " )))
fof_db_query ( " ALTER TABLE $FOF_FEED_TABLE ADD `feed_image_cache_date` INT( 11 ) DEFAULT '0' AFTER `feed_image`; " );
2009-08-03 16:42:04 +04:00
2015-09-16 13:47:49 +03:00
if ( ! fof_num_rows ( fof_db_query ( " show columns from $FOF_USER_TABLE like 'user_password_hash' " )))
{
fof_db_query ( " ALTER TABLE $FOF_USER_TABLE CHANGE `user_password` `user_password_hash` VARCHAR( 32 ) NOT NULL " );
fof_db_query ( " update $FOF_USER_TABLE set user_password_hash = md5(concat(user_password_hash, user_name)) " );
}
2009-08-03 16:42:04 +04:00
2015-09-16 13:47:49 +03:00
if ( ! fof_num_rows ( fof_db_query ( " show columns from $FOF_FEED_TABLE like 'feed_cache_attempt_date' " )))
fof_db_query ( " ALTER TABLE $FOF_FEED_TABLE ADD `feed_cache_attempt_date` INT( 11 ) DEFAULT '0' AFTER `feed_cache_date`; " );
2009-08-03 16:42:04 +04:00
2015-09-16 13:47:49 +03:00
if ( ! fof_num_rows ( fof_db_query ( " show columns from $FOF_ITEM_TABLE like 'item_author' " )))
fof_db_query ( " ALTER TABLE $FOF_ITEM_TABLE ADD `item_author` text NOT NULL AFTER `item_title`; " );
2010-02-15 22:06:58 +03:00
2015-09-16 13:47:49 +03:00
$check = fof_db_get_row ( fof_db_query ( " show create table $FOF_ITEM_TABLE " ));
if ( strpos ( $check [ 1 ], 'KEY `feed_id`' ) !== false )
fof_db_query ( " alter table $FOF_ITEM_TABLE drop key feed_id, add key item_published (item_published) " );
2014-12-09 18:26:26 +03:00
2014-12-10 00:28:17 +03:00
add_fk ( $check [ 1 ], $FOF_ITEM_TABLE , 'feed_id' , $FOF_FEED_TABLE , 'on update cascade' );
2015-09-16 13:47:49 +03:00
$check = fof_db_get_row ( fof_db_query ( " show create table $FOF_ITEM_TAG_TABLE " ));
2014-12-10 00:28:17 +03:00
add_fk ( $check [ 1 ], $FOF_ITEM_TAG_TABLE , 'tag_id' , $FOF_TAG_TABLE );
add_fk ( $check [ 1 ], $FOF_ITEM_TAG_TABLE , 'user_id' , $FOF_USER_TABLE );
add_fk ( $check [ 1 ], $FOF_ITEM_TAG_TABLE , 'item_id' , $FOF_ITEM_TABLE );
2015-09-16 13:47:49 +03:00
if ( strpos ( $check [ 1 ], 'PRIMARY KEY (`user_id`,`item_id`,`tag_id`)' ) !== false )
{
fof_db_query (
" alter table $FOF_ITEM_TAG_TABLE add key user_id (user_id), " .
2014-12-09 18:26:26 +03:00
" add key item_id_user_id_tag_id (item_id, user_id, tag_id), drop primary key, " .
2015-09-16 13:47:49 +03:00
" add primary key (tag_id, user_id, item_id), drop key tag_id, drop key item_id "
);
}
2014-12-09 18:26:26 +03:00
2015-09-16 13:47:49 +03:00
if ( ! strpos ( $check [ 1 ], '`item_published`' ))
{
fof_db_query (
" alter table $FOF_ITEM_TAG_TABLE add item_published int not null default '0', " .
2014-12-09 18:26:26 +03:00
" add feed_id int not null default 0, " .
" add key tag_id_user_id_item_published_item_id (tag_id, user_id, item_published, item_id), " .
" add key tag_id_user_id_feed_id (tag_id, user_id, feed_id), " .
2015-09-16 13:47:49 +03:00
" add key feed_id (feed_id) "
);
}
2014-12-09 18:26:26 +03:00
2015-09-16 13:47:49 +03:00
if ( fof_num_rows ( fof_db_query ( " select count(*) from $FOF_ITEM_TAG_TABLE where feed_id=0 " )))
{
fof_db_query (
" update $FOF_ITEM_TAG_TABLE it, $FOF_ITEM_TABLE i " .
2014-12-09 18:26:26 +03:00
" set it.item_published=i.item_published, it.feed_id=i.feed_id " .
2015-09-16 13:47:49 +03:00
" where it.feed_id=0 and it.item_id=i.item_id "
);
}
2014-12-09 18:26:26 +03:00
2014-12-10 00:28:17 +03:00
add_fk ( $check [ 1 ], $FOF_ITEM_TAG_TABLE , 'feed_id' , $FOF_FEED_TABLE );
2012-11-29 02:16:43 +04:00
2009-08-03 16:42:04 +04:00
?>
2010-01-25 20:30:38 +03:00
Schema up to date .< hr >
2009-08-03 16:42:04 +04:00
Inserting initial data ...
< ? php
fof_db_query ( " insert into $FOF_TAG_TABLE (tag_id, tag_name) values (1, 'unread') " , 1 );
fof_db_query ( " insert into $FOF_TAG_TABLE (tag_id, tag_name) values (2, 'star') " , 1 );
?>
Done .< hr >
Checking cache directory ...
< ? php
2010-01-25 20:30:38 +03:00
if ( ! file_exists ( " cache " ))
2009-08-03 16:42:04 +04:00
{
2010-01-25 20:30:38 +03:00
$status = @ mkdir ( " cache " , 0755 );
if ( ! $status )
{
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> " ;
echo " </div></body></html> " ;
2009-08-03 16:42:04 +04:00
exit ;
2010-01-25 20:30:38 +03:00
}
2009-08-03 16:42:04 +04:00
}
2010-01-25 20:30:38 +03:00
if ( ! is_writable ( " cache " ))
2009-08-03 16:42:04 +04:00
{
2010-01-25 20:30:38 +03:00
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> " ;
echo " </div></body></html> " ;
exit ;
2009-08-03 16:42:04 +04:00
}
?>
Cache directory exists and is writable .< hr >
< ? php
2010-01-25 20:30:38 +03:00
$result = fof_db_query ( " select * from $FOF_USER_TABLE where user_name = 'admin' " );
2015-09-16 13:47:49 +03:00
if ( fof_num_rows ( $result ) == 0 ) {
2009-08-03 16:42:04 +04:00
?>
You now need to choose an initial password for the 'admin' account :< br >
< form >
< table >
< tr >< td > Password :</ td >< td >< input type = password name = password ></ td ></ tr >
< tr >< td > Password again :</ td >< td >< input type = password name = password2 ></ td ></ tr >
</ table >
< input type = submit value = " Set Password " >
</ form >
< ? php } else { ?>
'admin' account already exists .< br >
< br >< b >< center > OK ! Setup complete ! < a href = " . " > Login as admin </ a > , and start subscribing !</ center ></ b >
< ? php } } ?>
</ div ></ body ></ html >