示例#1
0
function create_database($convert_version = FALSE)
{
    global $s, $VIDSRC;
    $conn = my_mysql_connect($s['MYSQL_HOST'], $s['MYSQL_USER'], $s['MYSQL_PASS']);
    $dbs = my_mysql_select_db($s['MYSQL_DBNAME'], $conn);
    if (!$conn || !$dbs) {
        return FALSE;
    }
    my_mysql_query('SET NAMES utf8', $conn);
    $v = $convert_version;
    if ($v == '2.1.0') {
        return TRUE;
    }
    if ($v && $v < '2.1.0') {
        my_mysql_query('CREATE TABLE  `sphinx_delta_ndx_counter` (
			  `index_name` enum("posts","comments","tags","users","groups") NOT NULL PRIMARY KEY,
			  `last_id` int(10) unsigned NOT NULL
			) ENGINE=MyISAM DEFAULT CHARSET=utf8', $conn);
        my_mysql_query('INSERT INTO `sphinx_delta_ndx_counter` (`index_name`,`last_id`) 
						VALUES ("posts",0), ("comments",0), ("tags", 0), ("users", 0), ("groups", 0)	', $conn);
        my_mysql_query('ALTER TABLE  `users` ADD INDEX (  `num_followers` )', $conn);
        my_mysql_query('CREATE TABLE  `post_tags` (
				  `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
				  `tag_name` VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
				  `user_id` INT( 10 ) UNSIGNED NOT NULL,
				  `group_id` INT( 10 ) UNSIGNED NOT NULL,
				  `post_id` INT( 10 ) UNSIGNED NOT NULL ,
				  `date` INT( 10 ) UNSIGNED NOT NULL,
				  PRIMARY KEY (  `id` ),
				  INDEX (tag_name)
				 ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci', $conn);
        my_mysql_query('UPDATE applications SET detect="twitter" WHERE id=8 LIMIT 1', $conn);
    }
    if ($v == '2.0.0') {
        return TRUE;
    }
    if ($v && $v < '2.0.0') {
        my_mysql_query('INSERT INTO `settings` (`word`, `value`) VALUES ("POST_TYPES_TO_AUTODELETE", "feed")', $conn);
        my_mysql_query('INSERT INTO `settings` (`word`, `value`) VALUES ("POST_TYPES_DELETE_PERIOD", "14")', $conn);
        my_mysql_query('ALTER TABLE  `users_details` ADD  `integr_twitter` VARCHAR( 255 ) NOT NULL', $conn);
        my_mysql_query('ALTER TABLE  `users_details` ADD  `extrnlusr_twitter` VARCHAR( 255 ) NOT NULL', $conn);
        my_mysql_query('ALTER TABLE  `users_details` ADD  `integr_facebook` VARCHAR( 255 ) NOT NULL', $conn);
        my_mysql_query('ALTER TABLE  `users_details` ADD  `extrnlusr_facebook` VARCHAR( 255 ) NOT NULL', $conn);
        my_mysql_query('INSERT INTO applications(  `name` ,  `detect`, `total_posts` ) VALUES (\'<a href="http://twitter.com/" target="_blank">Twitter</a>\',  "twitter", 0)', $conn);
        my_mysql_query('INSERT INTO `settings` (`word`, `value`) VALUES ("POST_FROM_TWITTER_TAG", "0")', $conn);
        my_mysql_query('INSERT INTO `settings` (`word`, `value`) VALUES ("LAST_TWITTER_POST_ID", "0")', $conn);
        my_mysql_query('ALTER TABLE  `posts` ADD  `likes` smallint(5) UNSIGNED NOT NULL DEFAULT  "0" AFTER  `reshares`', $conn);
        my_mysql_query('ALTER TABLE  `users_notif_rules` ADD  `ntf_me_on_post_like` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT  "0" COMMENT  "0-off, 3-email"', $conn);
        my_mysql_query('CREATE TABLE  `post_likes` (
				 `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
				 `user_id` INT( 10 ) UNSIGNED NOT NULL ,
				 `post_id` INT( 10 ) UNSIGNED NOT NULL ,
				 `date` INT( 10 ) UNSIGNED NOT NULL ,
				PRIMARY KEY (  `id` )
				) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci;', $conn);
    }
    if ($v == '1.5.4') {
        return TRUE;
    }
    if ($v && $v < '1.5.4') {
        my_mysql_query('UPDATE  `applications` SET  `name` =  "<a href=\'http://www.getspaz.com/\' target=\'_blank\'>Spaz</a>" WHERE `applications`.`id`=7', $conn);
        my_mysql_query('ALTER TABLE  `groups` ADD  `is_special` TINYINT( 1 ) unsigned NOT NULL DEFAULT  "0" AFTER  `is_public`', $conn);
        my_mysql_query('INSERT INTO `settings` (`word`, `value`) VALUES ("PROTECT_OUTSIDE_PAGES", "0")', $conn);
        my_mysql_query('ALTER TABLE  `users` ADD  `is_profile_protected` TINYINT( 1 ) unsigned NOT NULL DEFAULT  "0" AFTER  `is_network_admin`', $conn);
        my_mysql_query('ALTER TABLE  `users` ADD  `is_posts_protected` TINYINT( 1 ) unsigned NOT NULL DEFAULT  "0" AFTER  `is_network_admin`', $conn);
        my_mysql_query('ALTER TABLE  `users` ADD  `is_dm_protected` TINYINT( 1 ) unsigned NOT NULL DEFAULT  "0" AFTER  `is_network_admin`', $conn);
        my_mysql_query('INSERT INTO `settings` (`word`, `value`) VALUES ("SUPPORTED_EMAIL_DOMAINS", "0")', $conn);
        my_mysql_query('INSERT INTO `settings` (`word`, `value`) VALUES ("API_STATUS", "1")', $conn);
    }
    if ($v == '1.5.3') {
        return TRUE;
    }
    if ($v == '1.5.2') {
        return TRUE;
    }
    if ($v && $v < '1.5.2') {
        my_mysql_query('ALTER TABLE  `users_dashboard_tabs` CHANGE  `tab`  `tab` ENUM(  \'\',  \'all\',  \'@me\',  \'private\',  \'commented\',  \'feeds\',  \'tweets\' ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL', $conn);
    }
    if ($v == '1.5.1') {
        return TRUE;
    }
    if ($v && $v < '1.5.1') {
        my_mysql_query('ALTER TABLE  `applications` CHANGE  `name` `name` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL', $conn);
        my_mysql_query('UPDATE  applications SET  name=\'<a href="http://www.tweetdeck.com/" target="_blank">tweetdeck</a>\' WHERE  id=5', $conn);
        my_mysql_query('ALTER TABLE  `applications` ADD  `detect` VARCHAR( 50 ) NOT NULL AFTER  `name`', $conn);
        my_mysql_query('REPLACE INTO applications(id, name, total_posts, detect) VALUES(7, \'<a href="http://getspaz.com/" target="_blank">Spaz</a>\', 0, "spaz")', $conn);
    }
    if ($v == '1.5.0' || $v == '1.5') {
        return TRUE;
    }
    if ($v && $v < '1.5.0') {
        my_mysql_query('ALTER TABLE `applications` ADD `suspended` tinyint(1) unsigned NOT NULL default "0" ', $conn);
        my_mysql_query('ALTER TABLE `oauth_access_token` ADD `rate_limits` int(5) NOT NULL, ADD `rate_limits_date` int(5) NOT NULL', $conn);
        my_mysql_query('ALTER TABLE `oauth_access_token` ADD INDEX `consumer_key` (`consumer_key`) ', $conn);
        my_mysql_query('ALTER TABLE `oauth_request_token` ADD INDEX `request_token` (`request_token`) ', $conn);
        my_mysql_query('ALTER TABLE `posts` ADD `reshares` smallint(5) unsigned NOT NULL default "0" ', $conn);
        my_mysql_query('ALTER TABLE `post_userbox` ADD `id` BIGINT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ', $conn);
        my_mysql_query('ALTER TABLE `post_userbox_feeds` ADD `id` BIGINT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST ', $conn);
        my_mysql_query('ALTER TABLE `users_pageviews` ADD INDEX ( `date` )', $conn);
        my_mysql_query('ALTER TABLE `groups_rssfeeds` ADD `hub_url` VARCHAR( 255 ) NOT NULL AFTER `date_last_item` ', $conn);
        my_mysql_query('ALTER TABLE `groups_rssfeeds` ADD `hub_lastping` INT( 10 ) UNSIGNED NOT NULL DEFAULT "0" AFTER `hub_url` ', $conn);
        my_mysql_query('ALTER TABLE `users_rssfeeds` ADD `hub_url` VARCHAR( 255 ) NOT NULL AFTER `date_last_item` ', $conn);
        my_mysql_query('ALTER TABLE `users_rssfeeds` ADD `hub_lastping` INT( 10 ) UNSIGNED NOT NULL DEFAULT "0" AFTER `hub_url` ', $conn);
        my_mysql_query('ALTER TABLE  `users_rssfeeds` ADD  `is_twitter` TINYINT( 1 ) NOT NULL DEFAULT  "0" AFTER  `is_deleted` ', $conn);
        my_mysql_query('INSERT INTO applications(`id`, `name`, `total_posts`) VALUES(4, "api", 0), (5, \'<a href="http://www.tweetdeck.com/" target="_blank">tweetdeck</a>\', 0), (6, "twitter", 0);', $conn);
        my_mysql_query('
				CREATE TABLE IF NOT EXISTS `ip_rates_limit` (
				  `id` int(10) NOT NULL auto_increment,
				  `ip` bigint(12) NOT NULL,
				  `rate_limits` int(10) NOT NULL,
				  `rate_limits_date` int(10) NOT NULL,
				  PRIMARY KEY  (`id`)
				) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			', $conn);
        my_mysql_query('
				CREATE TABLE IF NOT EXISTS `ip_rates_limit` (
				  `id` int(10) NOT NULL auto_increment,
				  `ip` bigint(12) NOT NULL,
				  `rate_limits` int(10) NOT NULL,
				  `rate_limits_date` int(10) NOT NULL,
				  PRIMARY KEY  (`id`)
				) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			', $conn);
        my_mysql_query('
				CREATE TABLE `posts_reshares` (
				  `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
				  `post_id` INT( 10 ) UNSIGNED NOT NULL,
				  `user_id` INT( 10 ) UNSIGNED NOT NULL,
				  `date` INT( 10 ) UNSIGNED NOT NULL,
				  PRIMARY KEY  (`id`),
				  KEY ( `post_id` )
				) ENGINE=MYISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			', $conn);
        my_mysql_query('
				CREATE TABLE IF NOT EXISTS `pubsubhubbub_subscriptions` (
				  `id` int(10) unsigned NOT NULL auto_increment,
				  `feed_url` varchar(500) collate utf8_unicode_ci NOT NULL,
				  `status` varchar(100) collate utf8_unicode_ci NOT NULL,
				  `last_status_date` int(10) unsigned NOT NULL,
				  `parse_needed` tinyint(1) unsigned NOT NULL default "0",
				  PRIMARY KEY  (`id`),
				  KEY `feed_url` (`feed_url`(333)),
				  KEY `status` (`status`),
				  KEY `parse_needed` (`parse_needed`)
				) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			', $conn);
        my_mysql_query('
				CREATE TABLE IF NOT EXISTS `post_userbox_tweets` (
					`id` BIGINT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
					`user_id` INT( 10 ) UNSIGNED NOT NULL ,
					`post_id` INT( 10 ) UNSIGNED NOT NULL ,
					PRIMARY KEY  (`id`),
					INDEX (  `user_id` ,  `post_id` )
					) ENGINE = MYISAM;
			', $conn);
    }
    if ($v == '1.4.2') {
        return TRUE;
    }
    if ($v && $v < '1.4.2') {
        my_mysql_query('ALTER TABLE `posts` ADD INDEX `api_user_IDX` ( `api_id` , `user_id` )', $conn);
        my_mysql_query('ALTER TABLE `posts_attachments` ADD INDEX `post_type_IDX` ( `post_id` , `type` )', $conn);
        my_mysql_query('ALTER TABLE `posts_comments` ADD FULLTEXT (`message`)', $conn);
        my_mysql_query('ALTER TABLE `posts_comments_watch` ADD INDEX `user_post_IDX` ( `user_id` , `post_id` )', $conn);
        my_mysql_query('ALTER TABLE `posts_pr_attachments` ADD INDEX `post_type_IDX` ( `post_id` , `type` )', $conn);
        my_mysql_query('ALTER TABLE `posts_pr_comments_watch` ADD INDEX `user_post_IDX` ( `user_id` , `post_id` )', $conn);
        my_mysql_query('ALTER TABLE `post_userbox` ADD INDEX `user_post_IDX` ( `user_id` , `post_id` )', $conn);
        my_mysql_query('ALTER TABLE `users` ADD INDEX `pass_reset_IDX` ( `pass_reset_key` , `pass_reset_valid` )', $conn);
    }
    if ($v == '1.4.1') {
        return TRUE;
    }
    if ($v == '1.4.0') {
        return TRUE;
    }
    if ($v && $v < '1.4.0') {
        my_mysql_query("REPLACE INTO `settings` SET `word`='THEME', `value`='default' ", $conn);
        my_mysql_query('RENAME TABLE `post_api` TO `applications`', $conn);
        my_mysql_query('ALTER TABLE `applications` CHANGE `id` `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT', $conn);
        my_mysql_query('
				ALTER TABLE `applications`
				  ADD `app_id` int(10) unsigned NOT NULL,
				  ADD `user_id` int(10) unsigned NOT NULL,
				  ADD `consumer_key` varchar(1000) collate utf8_unicode_ci NOT NULL,
				  ADD `consumer_secret` varchar(100) collate utf8_unicode_ci NOT NULL,
				  ADD `callback_url` varchar(100) collate utf8_unicode_ci NOT NULL,
				  ADD `avatar` varchar(100) collate utf8_unicode_ci NOT NULL,
				  ADD `description` text collate utf8_unicode_ci NOT NULL,
				  ADD `app_website` varchar(100) collate utf8_unicode_ci NOT NULL,
				  ADD `organization` varchar(100) collate utf8_unicode_ci NOT NULL,
				  ADD `website` varchar(100) collate utf8_unicode_ci NOT NULL,
				  ADD `app_type` enum("","browser","client") collate utf8_unicode_ci NOT NULL,
				  ADD `acc_type` enum("","r","rw") collate utf8_unicode_ci NOT NULL,
				  ADD `use_for_login` tinyint(1) unsigned NOT NULL,
				  ADD `reg_date` int(10) unsigned NOT NULL,
				  ADD `reg_ip` bigint(10) unsigned NOT NULL
			', $conn);
        my_mysql_query('ALTER TABLE `applications` ADD INDEX ( `app_id` ) ', $conn);
        my_mysql_query('ALTER TABLE `applications` ADD INDEX ( `consumer_key` ) ', $conn);
        my_mysql_query('
				CREATE TABLE IF NOT EXISTS `oauth_access_token` (
				  `id` int(10) unsigned NOT NULL auto_increment,
				  `app_id` int(10) unsigned NOT NULL,
				  `consumer_key` varchar(255) collate utf8_unicode_ci NOT NULL,
				  `time_stamp` bigint(20) NOT NULL,
				  `version` varchar(10) collate utf8_unicode_ci NOT NULL,
				  `nonce` varchar(255) collate utf8_unicode_ci NOT NULL,
				  `access_token` varchar(255) collate utf8_unicode_ci NOT NULL,
				  `token_secret` varchar(255) collate utf8_unicode_ci NOT NULL,
				  `user_id` int(11) NOT NULL,
				  `user_verified` tinyint(1) NOT NULL,
				  PRIMARY KEY  (`id`)
				) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			', $conn);
        my_mysql_query('
				CREATE TABLE IF NOT EXISTS `oauth_log` (
				  `id` bigint(20) unsigned NOT NULL auto_increment,
				  `app_id` int(10) unsigned NOT NULL,
				  `user_id` int(10) unsigned NOT NULL,
				  `date` int(10) unsigned NOT NULL,
				  PRIMARY KEY  (`id`),
				  KEY `app_id` (`app_id`,`user_id`)
				) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			', $conn);
        my_mysql_query('
				CREATE TABLE IF NOT EXISTS `oauth_request_token` (
				  `id` int(10) unsigned NOT NULL auto_increment,
				  `consumer_key` varchar(255) collate utf8_unicode_ci NOT NULL,
				  `nonce` varchar(255) collate utf8_unicode_ci NOT NULL,
				  `time_stamp` bigint(20) NOT NULL,
				  `version` varchar(10) collate utf8_unicode_ci NOT NULL,
				  `token_secret` varchar(100) collate utf8_unicode_ci NOT NULL,
				  `request_token` varchar(100) collate utf8_unicode_ci NOT NULL,
				  `verifier` varchar(100) collate utf8_unicode_ci NOT NULL,
				  `user_id` bigint(20) NOT NULL,
				  PRIMARY KEY  (`id`)
				) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
			', $conn);
    }
    if ($v == '1.3.0') {
        return TRUE;
    }
    if ($v == '1.2.2' || $v == '1.2.1' || $v == '1.2.0') {
        return TRUE;
    }
    if ($v && $v < '1.2.0') {
        my_mysql_query('ALTER TABLE `users` ADD `twitter_uid` VARCHAR( 32 ) NOT NULL AFTER `facebook_uid` ', $conn);
        my_mysql_query("\n\t\t\t\tCREATE TABLE `email_change_requests` (\n\t\t\t\t  `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n\t\t\t\t  `user_id` INT( 10 ) UNSIGNED NOT NULL ,\n\t\t\t\t  `new_email` VARCHAR( 100 ) NOT NULL ,\n\t\t\t\t  `confirm_key` VARCHAR( 32 ) NOT NULL ,\n\t\t\t\t  `confirm_valid` INT( 10 ) UNSIGNED NOT NULL ,\n\t\t\t\t  INDEX ( `user_id` , `confirm_key` )\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n\t\t\t", $conn);
    }
    if ($v == '1.1.0') {
        return TRUE;
    }
    if ($v == '1.0.4' || $v == '1.0.3') {
        my_mysql_query("ALTER TABLE `posts` ADD INDEX (`api_id`) ", $conn);
        return TRUE;
    }
    if ($v == '1.0.2' || $v == '1.0.1' || $v == '1.0.0') {
        my_mysql_query("REPLACE INTO `settings` SET `word`='USERS_EMAIL_CONFIRMATION', `value`='1' ", $conn);
        my_mysql_query("ALTER TABLE `posts` ADD INDEX (`api_id`) ", $conn);
        return TRUE;
    }
    $prefix = '';
    if ($convert_version) {
        $prefix = substr(md5(rand() . time()), 0, rand(5, 8)) . '__';
    }
    $res = TRUE;
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "applications`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "applications` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `name` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `detect` varchar(50) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `total_posts` int(10) unsigned NOT NULL,\n\t\t\t  `app_id` int(10) unsigned NOT NULL,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `consumer_key` varchar(1000) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `consumer_secret` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `callback_url` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `avatar` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `description` text collate utf8_unicode_ci NOT NULL,\n\t\t\t  `app_website` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `organization` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `website` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `app_type` enum('','browser','client') collate utf8_unicode_ci NOT NULL,\n\t\t\t  `acc_type` enum('','r','rw') collate utf8_unicode_ci NOT NULL,\n\t\t\t  `use_for_login` tinyint(1) unsigned NOT NULL,\n\t\t\t  `reg_date` int(10) unsigned NOT NULL,\n\t\t\t  `reg_ip` bigint(10) unsigned NOT NULL,\n\t\t\t  `suspended` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `app_id` (`app_id`),\n\t\t\t  KEY `consumer_key` (`consumer_key`(333))\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tINSERT INTO `" . $prefix . "applications` (`id`, `name`, `total_posts`) VALUES\n\t\t\t(1, 'mobi', 0),\n\t\t\t(2, 'RSS', 0),\n\t\t\t(3, 'email', 0),\n\t\t\t(4, 'web', 0);\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tUPDATE `" . $prefix . "applications` SET id=0 WHERE id=4 LIMIT 1;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tALTER TABLE `" . $prefix . "applications` AUTO_INCREMENT=4;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tINSERT INTO `" . $prefix . "applications` (`id`, `name`, `total_posts`, `detect`) VALUES\n\t\t\t(4, 'api', 0, ''),\n\t\t\t(5, '<a href=\"http://www.tweetdeck.com/\" target=\"_blank\">tweetdeck</a>', 0, ''),\n\t\t\t(6, 'twitter', 0, ''),\n\t\t\t(7, '<a href=\"http://getspaz.com/\" target=\"_blank\">Spaz</a>', 0, 'spaz'),\n\t\t\t(8, '<a href=\"http://twitter.com/\" target=\"_blank\">Twitter</a>',  0, 'twitter');\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "cache`;\n\t\t", $conn);
    $varchar_len = 255;
    $ver = my_mysql_get_server_info($conn);
    $ver = str_replace('.', '', substr($ver, 0, 5));
    if (intval($ver) >= 503) {
        $varchar_len = 21810;
    }
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "cache` (\n\t\t\t  `key` varchar(32) NOT NULL,\n\t\t\t  `data` varchar(" . $varchar_len . ") NOT NULL,\n\t\t\t  `expire` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`key`)\n\t\t\t) ENGINE=MEMORY DEFAULT CHARSET=utf8;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "crons`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "crons` (\n\t\t\t  `cron` varchar(10) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `last_run` int(10) unsigned NOT NULL,\n\t\t\t  `next_run` int(10) unsigned NOT NULL,\n\t\t\t  `is_running` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`cron`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "email_change_requests`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "email_change_requests` (\n\t\t\t  `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n\t\t\t  `user_id` INT( 10 ) UNSIGNED NOT NULL ,\n\t\t\t  `new_email` VARCHAR( 100 ) NOT NULL ,\n\t\t\t  `confirm_key` VARCHAR( 32 ) NOT NULL ,\n\t\t\t  `confirm_valid` INT( 10 ) UNSIGNED NOT NULL ,\n\t\t\t  INDEX ( `user_id` , `confirm_key` )\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "groups` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `groupname` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `title` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `avatar` varchar(200) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `about_me` varchar(200) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `is_public` tinyint(1) unsigned NOT NULL,\n\t\t\t  `is_special` tinyint(1) unsigned NOT NULL,\n\t\t\t  `num_posts` int(10) unsigned NOT NULL default '0',\n\t\t\t  `num_followers` int(10) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  UNIQUE KEY `groupname` (`groupname`),\n\t\t\t  KEY `is_public` (`is_public`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_admins`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "groups_admins` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `group_id` int(10) unsigned NOT NULL,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `group_id` (`group_id`),\n\t\t\t  KEY `user_id` (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_deleted`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "groups_deleted` (\n\t\t\t  `id` int(10) unsigned NOT NULL,\n\t\t\t  `groupname` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `title` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `is_public` tinyint(1) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `is_public` (`is_public`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_followed`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "groups_followed` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `group_id` int(10) unsigned NOT NULL,\n\t\t\t  `date` int(10) unsigned NOT NULL,\n\t\t\t  `group_from_postid` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `user_id` (`user_id`),\n\t\t\t  KEY `group_id` (`group_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_private_members`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "groups_private_members` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `group_id` int(10) unsigned NOT NULL,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `invited_by` int(10) unsigned NOT NULL,\n\t\t\t  `invited_date` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `group_id` (`group_id`),\n\t\t\t  KEY `user_id` (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_rssfeeds`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "groups_rssfeeds` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `group_id` int(10) unsigned NOT NULL,\n\t\t\t  `feed_url` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `feed_userpwd` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `feed_title` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `filter_keywords` varchar(1000) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `date_added` int(10) unsigned NOT NULL,\n\t\t\t  `date_last_post` int(10) unsigned NOT NULL,\n\t\t\t  `date_last_crawl` int(10) unsigned NOT NULL,\n\t\t\t  `date_last_item` int(10) unsigned NOT NULL,\n\t\t\t  `hub_url` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `hub_lastping` int(10) unsigned NOT NULL default '0',\n\t\t\t  `added_by_user` int(10) unsigned NOT NULL,\n\t\t\t  `is_deleted` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `group_id` (`is_deleted`,`group_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_rssfeeds_posts`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "groups_rssfeeds_posts` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `rssfeed_id` int(10) unsigned NOT NULL,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `rssfeed_id` (`rssfeed_id`),\n\t\t\t  KEY `post_id` (`post_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "invitation_codes`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "invitation_codes` (\n\t\t\t  `code` varchar(32) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `user_id` int(10) NOT NULL,\n\t\t\t  PRIMARY KEY  (`code`),\n\t\t\t  KEY `network_id` (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "ip_rates_limit`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "ip_rates_limit` (\n\t\t\t  `id` int(10) NOT NULL auto_increment,\n\t\t\t  `ip` bigint(12) NOT NULL,\n\t\t\t  `rate_limits` int(10) NOT NULL,\n\t\t\t  `rate_limits_date` int(10) NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "oauth_access_token`;\n\t\t", $conn);
    $res = $res && my_mysql_query('
			CREATE TABLE `' . $prefix . 'oauth_access_token` (
			  `id` int(10) unsigned NOT NULL auto_increment,
			  `app_id` int(10) unsigned NOT NULL,
			  `consumer_key` varchar(255) collate utf8_unicode_ci NOT NULL,
			  `time_stamp` bigint(20) NOT NULL,
			  `version` varchar(10) collate utf8_unicode_ci NOT NULL,
			  `nonce` varchar(255) collate utf8_unicode_ci NOT NULL,
			  `access_token` varchar(255) collate utf8_unicode_ci NOT NULL,
			  `token_secret` varchar(255) collate utf8_unicode_ci NOT NULL,
			  `user_id` int(11) NOT NULL,
			  `user_verified` tinyint(1) NOT NULL,
			  `rate_limits` int(5) NOT NULL,
			  `rate_limits_date` int(5) NOT NULL,
			  PRIMARY KEY  (`id`),
			  KEY `consumer_key` (`consumer_key`)
			) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
		', $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "oauth_log`;\n\t\t", $conn);
    $res = $res && my_mysql_query('
			CREATE TABLE `' . $prefix . 'oauth_log` (
			  `id` bigint(20) unsigned NOT NULL auto_increment,
			  `app_id` int(10) unsigned NOT NULL,
			  `user_id` int(10) unsigned NOT NULL,
			  `date` int(10) unsigned NOT NULL,
			  PRIMARY KEY  (`id`),
			  KEY `app_id` (`app_id`,`user_id`)
			) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
		', $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "oauth_request_token`;\n\t\t", $conn);
    $res = $res && my_mysql_query('
			CREATE TABLE `' . $prefix . 'oauth_request_token` (
			  `id` int(10) unsigned NOT NULL auto_increment,
			  `consumer_key` varchar(255) collate utf8_unicode_ci NOT NULL,
			  `nonce` varchar(255) collate utf8_unicode_ci NOT NULL,
			  `time_stamp` bigint(20) NOT NULL,
			  `version` varchar(10) collate utf8_unicode_ci NOT NULL,
			  `token_secret` varchar(100) collate utf8_unicode_ci NOT NULL,
			  `request_token` varchar(100) collate utf8_unicode_ci NOT NULL,
			  `verifier` varchar(100) collate utf8_unicode_ci NOT NULL,
			  `user_id` bigint(20) NOT NULL,
			  PRIMARY KEY  (`id`),
			  KEY `request_token` (`request_token`)
			) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
		', $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `api_id` smallint(5) unsigned NOT NULL default '0',\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `group_id` int(10) unsigned NOT NULL,\n\t\t\t  `message` varchar(1000) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `mentioned` tinyint(2) unsigned NOT NULL default '0',\n\t\t\t  `attached` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  `posttags` tinyint(2) unsigned NOT NULL default '0',\n\t\t\t  `comments` smallint(4) unsigned NOT NULL default '0',\n\t\t\t  `reshares` smallint(5) unsigned NOT NULL default '0',\n\t\t\t  `likes` smallint(5) unsigned NOT NULL default '0',\n\t\t\t  `date` int(10) unsigned NOT NULL,\n\t\t\t  `date_lastedit` int(10) NOT NULL,\n\t\t\t  `date_lastcomment` int(10) NOT NULL,\n\t\t\t  `ip_addr` bigint(10) NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `user_id` (`user_id`),\n\t\t\t  KEY `group_id` (`group_id`),\n\t\t\t  KEY `api_id` (`api_id`),\n\t\t\t  KEY `api_user_IDX` (`api_id`,`user_id`),\n\t\t\t  FULLTEXT KEY `message` (`message`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_attachments`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_attachments` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  `type` enum('link','image','videoembed','videoupload','text','file') collate utf8_unicode_ci NOT NULL,\n\t\t\t  `data` text collate utf8_unicode_ci NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `post_id` (`post_id`),\n\t\t\t  KEY `type` (`type`),\n\t\t\t  KEY `post_type_IDX` (`post_id`,`type`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_comments`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_comments` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `api_id` smallint(5) unsigned NOT NULL default '0',\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `message` text collate utf8_unicode_ci NOT NULL,\n\t\t\t  `mentioned` tinyint(2) unsigned NOT NULL,\n\t\t\t  `posttags` tinyint(2) unsigned NOT NULL,\n\t\t\t  `date` int(10) unsigned NOT NULL,\n\t\t\t  `ip_addr` bigint(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `post_id` (`post_id`),\n\t\t\t  KEY `user_id` (`user_id`),\n\t\t\t  FULLTEXT KEY `message` (`message`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_comments_mentioned`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_comments_mentioned` (\n\t\t\t  `id` int(10) NOT NULL auto_increment,\n\t\t\t  `comment_id` int(10) NOT NULL,\n\t\t\t  `user_id` int(10) NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `comment_id` (`comment_id`),\n\t\t\t  KEY `user_id` (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_comments_watch`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_comments_watch` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  `newcomments` smallint(5) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `post_id` (`post_id`),\n\t\t\t  KEY `user_id` (`user_id`),\n\t\t\t  KEY `user_post_IDX` (`user_id`,`post_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_mentioned`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_mentioned` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `post_id` (`post_id`),\n\t\t\t  KEY `user_id` (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `api_id` smallint(5) unsigned NOT NULL default '0',\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `to_user` int(10) unsigned NOT NULL,\n\t\t\t  `message` varchar(1000) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `mentioned` tinyint(2) unsigned NOT NULL default '0',\n\t\t\t  `attached` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  `posttags` tinyint(2) unsigned NOT NULL default '0',\n\t\t\t  `comments` smallint(4) unsigned NOT NULL default '0',\n\t\t\t  `date` int(10) unsigned NOT NULL,\n\t\t\t  `date_lastedit` int(10) NOT NULL,\n\t\t\t  `date_lastcomment` int(10) NOT NULL,\n\t\t\t  `ip_addr` bigint(10) NOT NULL,\n\t\t\t  `is_recp_del` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `user_id` (`user_id`),\n\t\t\t  KEY `to_user` (`to_user`),\n\t\t\t  KEY `is_recp_del` (`is_recp_del`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr_attachments`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr_attachments` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  `type` enum('link','image','videoembed','videoupload','text','file') collate utf8_unicode_ci NOT NULL,\n\t\t\t  `data` text collate utf8_unicode_ci NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `post_id` (`post_id`),\n\t\t\t  KEY `type` (`type`),\n\t\t\t  KEY `post_type_IDX` (`post_id`,`type`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr_comments`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr_comments` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `api_id` smallint(5) unsigned NOT NULL default '0',\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `message` text collate utf8_unicode_ci NOT NULL,\n\t\t\t  `mentioned` tinyint(2) unsigned NOT NULL,\n\t\t\t  `posttags` tinyint(2) unsigned NOT NULL,\n\t\t\t  `date` int(10) unsigned NOT NULL,\n\t\t\t  `ip_addr` bigint(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `post_id` (`post_id`),\n\t\t\t  KEY `user_id` (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr_comments_mentioned`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr_comments_mentioned` (\n\t\t\t  `id` int(10) NOT NULL auto_increment,\n\t\t\t  `comment_id` int(10) NOT NULL,\n\t\t\t  `user_id` int(10) NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `comment_id` (`comment_id`),\n\t\t\t  KEY `user_id` (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr_comments_watch`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr_comments_watch` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  `newcomments` smallint(5) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `user_id` (`user_id`),\n\t\t\t  KEY `post_id` (`post_id`),\n\t\t\t  KEY `user_post_IDX` (`user_id`,`post_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr_mentioned`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr_mentioned` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `post_id` (`post_id`),\n\t\t\t  KEY `user_id` (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_reshares`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "posts_reshares` (\n\t\t\t  `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t  `post_id` INT( 10 ) UNSIGNED NOT NULL,\n\t\t\t  `user_id` INT( 10 ) UNSIGNED NOT NULL,\n\t\t\t  `date` INT( 10 ) UNSIGNED NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY ( `post_id` )\n\t\t\t) ENGINE=MYISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "post_tags`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE  `post_tags` (\n\t\t\t\t  `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t  `tag_name` VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,\n\t\t\t\t  `user_id` INT( 10 ) UNSIGNED NOT NULL,\n\t\t\t\t  `group_id` INT( 10 ) UNSIGNED NOT NULL,\n\t\t\t\t  `post_id` INT( 10 ) UNSIGNED NOT NULL ,\n\t\t\t\t  `date` INT( 10 ) UNSIGNED NOT NULL,\n\t\t\t\t  PRIMARY KEY (  `id` ),\n\t\t\t\t  INDEX (tag_name)\n\t\t\t\t ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci;", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "post_favs`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "post_favs` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `post_type` enum('public','private') collate utf8_unicode_ci NOT NULL,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  `date` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `post_type` (`post_type`,`post_id`),\n\t\t\t  KEY `user_id` (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "post_likes`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "post_likes` (\n\t\t\t   `id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t `user_id` INT( 10 ) UNSIGNED NOT NULL ,\n\t\t\t\t `post_id` INT( 10 ) UNSIGNED NOT NULL ,\n\t\t\t\t `date` INT( 10 ) UNSIGNED NOT NULL ,\n\t\t\t\tPRIMARY KEY (  `id` )\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "post_userbox`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "post_userbox` (\n  \t\t\t  `id` bigint(10) unsigned NOT NULL auto_increment,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n  \t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `user_id` (`user_id`),\n\t\t\t  KEY `post_id` (`post_id`),\n\t\t\t  KEY `user_post_IDX` (`user_id`,`post_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "post_userbox_feeds`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "post_userbox_feeds` (\n  \t\t\t  `id` bigint(10) unsigned NOT NULL auto_increment,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n  \t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `user_id` (`user_id`),\n\t\t\t  KEY `post_id` (`post_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    //
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "post_userbox_tweets`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "post_userbox_tweets` (\n\t\t\t\t\t`id` BIGINT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t`user_id` INT( 10 ) UNSIGNED NOT NULL ,\n\t\t\t\t\t`post_id` INT( 10 ) UNSIGNED NOT NULL ,\n\t\t\t\t\t PRIMARY KEY  (`id`),\n\t\t\t\t\tINDEX (  `user_id` ,  `post_id` )\n\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    //
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "pubsubhubbub_subscriptions`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "pubsubhubbub_subscriptions` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `feed_url` varchar(500) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `status` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `last_status_date` int(10) unsigned NOT NULL,\n\t\t\t  `parse_needed` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `feed_url` (`feed_url`(333)),\n\t\t\t  KEY `status` (`status`),\n \t\t\t  KEY `parse_needed` (`parse_needed`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "searches`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "searches` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `search_key` varchar(32) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `search_string` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `search_url` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `added_date` int(10) unsigned NOT NULL,\n\t\t\t  `total_hits` mediumint(5) unsigned NOT NULL default '0',\n\t\t\t  `last_results` mediumint(5) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `user_id` (`user_id`,`search_key`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\t\t\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "settings`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "settings` (\n\t\t\t  `word` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `value` text collate utf8_unicode_ci NOT NULL,\n\t\t\t  UNIQUE KEY `word` (`word`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\t\t\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "sphinx_delta_ndx_counter`;\n\t\t", $conn);
    $res = $res && my_mysql_query("CREATE TABLE  `" . $prefix . "sphinx_delta_ndx_counter` (\n\t\t  `index_name` enum('posts','comments','tags','users','groups') NOT NULL PRIMARY KEY,\n\t\t  `last_id` int(10) unsigned NOT NULL\n\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n\t\t", $conn);
    $res = $res && my_mysql_query('INSERT INTO `' . $prefix . 'sphinx_delta_ndx_counter` (`index_name`,`last_id`) 
						VALUES ("posts",0), ("comments",0), ("tags", 0), ("users", 0), ("groups", 0)	', $conn);
    $res = $res && my_mysql_query("\n\t\t\tINSERT INTO `" . $prefix . "settings` (`word`, `value`) VALUES\n\t\t\t('SITE_TITLE', '" . my_mysql_real_escape_string($s['SITE_TITLE'], $conn) . "'),\n\t\t\t('POST_MAX_SYMBOLS', '160'),\n\t\t\t('LANGUAGE', '" . my_mysql_real_escape_string($s['LANGUAGE'], $conn) . "'),\n\t\t\t('SYSTEM_EMAIL', '" . my_mysql_real_escape_string($s['ADMIN_EMAIL'], $conn) . "'),\n\t\t\t('COMPANY', '" . my_mysql_real_escape_string($s['SITE_TITLE'], $conn) . "'),\n\t\t\t('ATTACH_LINK_DISABLED', '0'),\n\t\t\t('ATTACH_IMAGE_DISABLED', '0'),\n\t\t\t('ATTACH_VIDEO_DISABLED', '0'),\n\t\t\t('ATTACH_FILE_DISABLED', '0'),\n\t\t\t('USERS_EMAIL_CONFIRMATION', '1'),\n\t\t\t('API_STATUS', '1'),\n\t\t\t('SUPPORTED_EMAIL_DOMAINS', '0'),\n\t\t\t('PROTECT_OUTSIDE_PAGES', '0'),\n\t\t\t('THEME', 'default'),\n\t\t\t('MOBI_DISABLED', '0'),\n\t\t\t('POST_TYPES_TO_AUTODELETE', 'feed'),\n\t\t\t('POST_TYPES_DELETE_PERIOD', '14'),\n\t\t\t('POST_FROM_TWITTER_TAG', '0'),\n\t\t\t('LAST_TWITTER_POST_ID', '0')\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "unconfirmed_registrations`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "unconfirmed_registrations` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `email` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `fullname` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `confirm_key` varchar(32) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `invited_code` varchar(32) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `date` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  UNIQUE KEY `email` (`email`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "users` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `facebook_uid` varchar(32) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `twitter_uid` varchar(32) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `email` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `username` varchar(200) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `password` varchar(32) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `fullname` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `avatar` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `about_me` text collate utf8_unicode_ci NOT NULL,\n\t\t\t  `tags` text collate utf8_unicode_ci NOT NULL,\n\t\t\t  `gender` enum('','m','f') collate utf8_unicode_ci NOT NULL,\n\t\t\t  `birthdate` date NOT NULL,\n\t\t\t  `position` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `location` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `language` varchar(5) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `timezone` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `num_posts` int(10) unsigned NOT NULL,\n\t\t\t  `num_followers` int(10) unsigned NOT NULL,\n\t\t\t  `used_storage` bigint(10) unsigned NOT NULL,\n\t\t\t  `js_animations` tinyint(1) unsigned NOT NULL default '1',\n\t\t\t  `dbrd_groups_closed` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  `dbrd_whattodo_closed` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  `comments_expanded` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  `reg_date` int(10) unsigned NOT NULL,\n\t\t\t  `reg_ip` bigint(10) NOT NULL,\n\t\t\t  `lastlogin_date` int(10) unsigned NOT NULL,\n\t\t\t  `lastlogin_ip` bigint(10) NOT NULL,\n\t\t\t  `lastpost_date` int(10) unsigned NOT NULL,\n\t\t\t  `lastemail_date` int(10) unsigned NOT NULL,\n\t\t\t  `lastclick_date` int(10) unsigned NOT NULL,\n\t\t\t  `lastclick_date_newest_post` int(10) unsigned NOT NULL,\n\t\t\t  `pass_reset_key` varchar(32) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `pass_reset_valid` int(10) unsigned NOT NULL,\n\t\t\t  `active` tinyint(1) unsigned NOT NULL default '1',\n\t\t\t  `is_network_admin` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  `is_posts_protected` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  `is_profile_protected` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  `is_dm_protected` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  UNIQUE KEY `email` (`email`),\n\t\t\t  UNIQUE KEY `username` (`username`),\n\t\t\t  KEY `active` (`active`),\n\t\t\t  KEY `num_followers` (`num_followers`),\n\t\t\t  KEY `facebook_uid` (`facebook_uid`),\n\t\t\t  KEY `twitter_uid` (`twitter_uid`),\n\t\t\t  KEY `pass_reset_IDX` (`pass_reset_key`,`pass_reset_valid`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\t\t\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_dashboard_tabs`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "users_dashboard_tabs` (\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `tab` enum('','all','@me','private','commented','feeds','tweets') collate utf8_unicode_ci NOT NULL,\n\t\t\t  `state` tinyint(1) unsigned NOT NULL,\n\t\t\t  `newposts` smallint(4) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`user_id`,`tab`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_details`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "users_details` (\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `website` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `work_phone` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `personal_phone` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `personal_email` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `im_skype` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `im_icq` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `im_gtalk` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `im_msn` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `im_yahoo` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `im_aim` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `im_jabber` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_linkedin` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_facebook` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_twitter` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_flickr` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_friendfeed` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_delicious` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_digg` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_myspace` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_orcut` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_youtube` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_mixx` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_edno23` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `prof_favit` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `integr_twitter` VARCHAR( 255 ) collate utf8_unicode_ci  NOT NULL,\n\t\t\t  `extrnlusr_twitter` VARCHAR( 255 ) collate utf8_unicode_ci  NOT NULL,\n\t\t\t  `integr_facebook` VARCHAR( 255 ) collate utf8_unicode_ci  NOT NULL,\n\t\t\t  `extrnlusr_facebook` VARCHAR( 255 ) collate utf8_unicode_ci  NOT NULL,\n\t\t\t  PRIMARY KEY  (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_followed`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "users_followed` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `who` int(10) unsigned NOT NULL,\n\t\t\t  `whom` int(10) unsigned NOT NULL,\n\t\t\t  `date` int(10) unsigned NOT NULL,\n\t\t\t  `whom_from_postid` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `who` (`who`),\n\t\t\t  KEY `whom` (`whom`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_ignores`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "users_ignores` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `who` int(10) unsigned NOT NULL,\n\t\t\t  `whom` int(10) unsigned NOT NULL,\n\t\t\t  `date` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `who` (`who`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_invitations`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "users_invitations` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `date` int(10) unsigned NOT NULL,\n\t\t\t  `recp_name` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `recp_email` varchar(100) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `recp_is_registered` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  `recp_user_id` int(10) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `user_id` (`user_id`,`recp_is_registered`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_notif_rules`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "users_notif_rules` (\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `ntf_them_if_i_follow_usr` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\n\t\t\t  `ntf_them_if_i_comment` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\n\t\t\t  `ntf_them_if_i_edt_profl` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\n\t\t\t  `ntf_them_if_i_edt_pictr` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\n\t\t\t  `ntf_them_if_i_create_grp` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\n\t\t\t  `ntf_them_if_i_join_grp` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\n\t\t\t  `ntf_me_if_u_follows_me` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_follows_u2` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_commments_me` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_commments_m2` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_edt_profl` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_edt_pictr` tinyint(3) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_creates_grp` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_joins_grp` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_invit_me_grp` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_posts_qme` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_posts_prvmsg` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_if_u_registers` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\n\t\t\t  `ntf_me_on_post_like` tinyint( 1 ) unsigned NOT NULL DEFAULT  '0' COMMENT  '0-off, 3-email',\n\t\t\t  PRIMARY KEY  (`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_pageviews`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "users_pageviews` (\n\t\t\t  `id` bigint(10) unsigned NOT NULL auto_increment,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `date` varchar(13) collate utf8_unicode_ci NOT NULL COMMENT 'YY-MM-DD HH',\n\t\t\t  `pageviews` smallint(5) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `user_id` (`user_id`),\n\t\t\t  KEY `date` (`date`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_rssfeeds`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "users_rssfeeds` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\n\t\t\t  `feed_url` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `feed_userpwd` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `feed_title` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `filter_keywords` varchar(1000) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `date_added` int(10) unsigned NOT NULL,\n\t\t\t  `date_last_post` int(10) unsigned NOT NULL,\n\t\t\t  `date_last_crawl` int(10) unsigned NOT NULL,\n\t\t\t  `date_last_item` int(10) unsigned NOT NULL,\n\t\t\t  `hub_url` varchar(255) collate utf8_unicode_ci NOT NULL,\n\t\t\t  `hub_lastping` int(10) unsigned NOT NULL default '0',\n\t\t\t  `is_deleted` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  `is_twitter` tinyint(1) unsigned NOT NULL default '0',\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `group_id` (`is_deleted`,`user_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_rssfeeds_posts`;\n\t\t", $conn);
    $res = $res && my_mysql_query("\n\t\t\tCREATE TABLE `" . $prefix . "users_rssfeeds_posts` (\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t  `rssfeed_id` int(10) unsigned NOT NULL,\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\n\t\t\t  PRIMARY KEY  (`id`),\n\t\t\t  KEY `rssfeed_id` (`rssfeed_id`),\n\t\t\t  KEY `post_id` (`post_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", $conn);
    if (!$res) {
        if (!empty($prefix)) {
            database_drop_tables_with_prefix($prefix);
        }
        return FALSE;
    }
    if (!$convert_version && $s['ADMIN_ID'] == 0) {
        $res = $res && my_mysql_query("\n\t\t\t\tINSERT INTO `" . $prefix . "users` SET\n\t\t\t\tid='1',\n\t\t\t\tusername='******'ADMIN_USER'], $conn) . "',\n\t\t\t\tpassword='******'ADMIN_PASS']), $conn) . "',\n\t\t\t\temail='" . my_mysql_real_escape_string($s['ADMIN_EMAIL'], $conn) . "',\n\t\t\t\tfullname='" . my_mysql_real_escape_string($s['SITE_TITLE'], $conn) . "',\n\t\t\t\treg_date='" . time() . "',\n\t\t\t\treg_ip='" . ip2long($_SERVER['REMOTE_ADDR']) . "',\n\t\t\t\tlastpost_date='" . time() . "',\n\t\t\t\tlanguage='" . my_mysql_real_escape_string($s['LANGUAGE'], $conn) . "',\n\t\t\t\tnum_posts='1',\n\t\t\t\tnum_followers='0',\n\t\t\t\tactive='1',\n\t\t\t\tis_network_admin='1';\n\t\t\t", $conn);
        $res = $res && my_mysql_query("\n\t\t\t\tINSERT INTO `" . $prefix . "posts` SET\n\t\t\t\tid='1',\n\t\t\t\tapi_id='0',\n\t\t\t\tuser_id='1',\n\t\t\t\tgroup_id='0',\n\t\t\t\tmessage='Welcome to " . $s['SITE_TITLE'] . " :)',\n\t\t\t\tmentioned=0,\n\t\t\t\tattached=0,\n\t\t\t\tposttags=0,\n\t\t\t\tcomments=0,\n\t\t\t\tdate='" . time() . "',\n\t\t\t\tdate_lastedit='',\n\t\t\t\tdate_lastcomment='" . time() . "',\n\t\t\t\tip_addr='" . ip2long($_SERVER['REMOTE_ADDR']) . "';\n\t\t\t", $conn);
        $res = $res && my_mysql_query("\n\t\t\t\tINSERT INTO post_userbox SET user_id='1', post_id='1';\n\t\t\t", $conn);
        if (!$res) {
            if (!empty($prefix)) {
                database_drop_tables_with_prefix($prefix);
            }
            return FALSE;
        }
    }
    if ($convert_version == 'unofficial') {
        $tables = array();
        $tmp = my_mysql_query('SHOW TABLES FROM ' . $s['MYSQL_DBNAME'], $conn);
        while ($tbl = my_mysql_fetch_row($tmp)) {
            $tables[] = $tbl[0];
        }
        if (in_array('users_watched', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "users_followed` (who, whom, date, whom_from_postid) SELECT who, whom, date, whom FROM `users_watched` ORDER BY id ASC", $conn);
        }
        if (in_array('users_invitations', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "users_invitations` (user_id, date, recp_name, recp_email, recp_is_registered, recp_user_id) SELECT user_id, date, recp_name, recp_email, recp_is_registered, recp_user_id FROM `users_invitations` ORDER BY id ASC", $conn);
        }
        if (in_array('users_ignores', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "users_ignores` (who, whom, date) SELECT who, whom, date FROM `users_ignores` ORDER BY id ASC", $conn);
        }
        if (in_array('users_feeds', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "users_rssfeeds` (id, user_id, feed_url, date_added, date_last_post, date_last_crawl, date_last_item, is_deleted) SELECT id, user_id, feed_url, date_added, date_lastpost, date_lastcrawl, date_feed_lastentry, '0' FROM `users_feeds` ORDER BY id ASC", $conn);
            my_mysql_query("UPDATE `" . $prefix . "users_rssfeeds` SET date_date_last_post='" . time() . "', date_last_crawl='" . time() . "', date_last_item='" . time() . "' ", $conn);
        }
        if (in_array('users_feeds_posts', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "users_rssfeeds_posts` (rssfeed_id, post_id) SELECT feed_id, post_id FROM `users_feeds_posts` ORDER BY id ASC", $conn);
        }
        if (in_array('users_feeds_posts', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "users_rssfeeds_posts` (rssfeed_id, post_id) SELECT feed_id, post_id FROM `users_feeds_posts` ORDER BY id ASC", $conn);
        }
        if (in_array('users', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "users` (id, email, username, password, fullname, avatar, about_me, tags, gender, birthdate, location, language, num_posts, num_followers, reg_date, reg_ip, lastlogin_date, lastlogin_ip, lastpost_date, lastemail_date, lastclick_date, lastclick_date_newest_post, active, is_network_admin) SELECT id, email, username, password, fullname, avatar, about_me, tags, gender, birthdate, country, lang, '0', '0', reg_date, reg_ip, lastlogin_date, lastlogin_ip, lastpost_date, lastemail_date, lastclick_date, lastclick_date_newest_post, '1', '0' FROM `users` ORDER BY id ASC", $conn);
            if ($s['ADMIN_ID'] == 0) {
                my_mysql_query("UPDATE `" . $prefix . "users` SET is_network_admin=1 WHERE id='1' LIMIT 1", $conn);
            } else {
                my_mysql_query("UPDATE `" . $prefix . "users` SET is_network_admin=1 WHERE id='" . intval($s['ADMIN_ID']) . "' LIMIT 1", $conn);
            }
            $tmp = my_mysql_query("SELECT whom, COUNT(who) AS c FROM `" . $prefix . "users_followed` GROUP BY whom", $conn);
            while ($obj = my_mysql_fetch_object($tmp)) {
                my_mysql_query("UPDATE `" . $prefix . "users` SET num_followers='" . $obj->c . "' WHERE id='" . $obj->whom . "' LIMIT 1", $conn);
            }
            $tmp = my_mysql_query("SELECT DISTINCT language FROM `" . $prefix . "users` ", $conn);
            while ($obj = my_mysql_fetch_object($tmp)) {
                if (empty($obj->language)) {
                    my_mysql_query("UPDATE `" . $prefix . "users` SET language='" . my_mysql_real_escape_string($s['LANGUAGE']) . "' WHERE language='" . $obj->language . "' LIMIT 1", $conn);
                } elseif ($obj->language != $s['LANGUAGE'] && !file_exists(INCPATH . '../../system/languages/' . $obj->language)) {
                    my_mysql_query("UPDATE `" . $prefix . "users` SET language='" . my_mysql_real_escape_string($s['LANGUAGE']) . "' WHERE language='" . $obj->language . "' LIMIT 1", $conn);
                }
            }
        }
        if (in_array('posts_favs', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "post_favs` (user_id, post_type, post_id, date) SELECT user_id, 'public', post_id, date FROM `posts_favs` WHERE post_type='public' ORDER BY id ASC", $conn);
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "post_favs` (user_id, post_type, post_id, date) SELECT user_id, 'private', post_id, date FROM `posts_favs` WHERE post_type='direct' ORDER BY id ASC", $conn);
        }
        if (in_array('posts_mentioned', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "posts_mentioned` (post_id, user_id) SELECT post_id, user_id FROM `posts_mentioned` ORDER BY id ASC", $conn);
        }
        if (in_array('posts_mentioned_d', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "posts_pr_mentioned` (post_id, user_id) SELECT post_id, user_id FROM `posts_mentioned_d` ORDER BY id ASC", $conn);
        }
        if (in_array('posts_usertabs', $tables)) {
            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "post_userbox` (user_id, post_id) SELECT user_id, post_id FROM posts_usertabs", $conn);
            $ids = array();
            $tmp = my_mysql_query('SELECT id FROM posts WHERE is_feed=1', $conn);
            while ($obj = my_mysql_fetch_object($tmp)) {
                $ids[] = $obj->id;
            }
            if (count($ids)) {
                $ids = implode(', ', $ids);
                my_mysql_query("INSERT INTO `" . $prefix . "post_userbox_feeds` (user_id, post_id) SELECT user_id, post_id FROM `" . $prefix . "post_userbox` WHERE post_id IN(" . $ids . ")", $conn);
                my_mysql_query("DELETE FROM `" . $prefix . "post_userbox` WHERE post_id IN(" . $ids . ")", $conn);
            }
        }
        if (in_array('posts', $tables)) {
            $tmp = my_mysql_query("SELECT id, api_id, user_id, message, mentioned, attached_link, attachments, date, ip_address, is_feed FROM `posts` ORDER BY id ASC", $conn);
            $res = $res && $tmp;
            while ($obj = my_mysql_fetch_object($tmp)) {
                $api_id = $obj->api_id == 1 ? 1 : ($obj->is_feed == 1 ? 2 : 0);
                $message = stripslashes($obj->message);
                $attached = intval($obj->attachments);
                if (!empty($obj->attached_link)) {
                    $attached++;
                }
                $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "posts` SET id='" . $obj->id . "', api_id='" . $api_id . "', user_id='" . $obj->user_id . "', group_id=0, message='" . my_mysql_real_escape_string($message, $conn) . "', mentioned='" . $obj->mentioned . "', attached='" . $attached . "', posttags=0, comments=0, date='" . $obj->date . "', date_lastcomment='" . $obj->date . "', ip_addr='" . $obj->ip_address . "' ", $conn);
                if (!empty($obj->attached_link)) {
                    $atch = (object) array('link' => stripslashes($obj->attached_link), 'hits' => 0);
                    $atch = my_mysql_real_escape_string(serialize($atch), $conn);
                    $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "posts_attachments` SET post_id='" . $obj->id . "', type='link', data='" . $atch . "' ", $conn);
                }
                if ($obj->attachments > 0) {
                    $tmp2 = my_mysql_query("SELECT embed_type, embed_w, embed_h, embed_thumb, if_image_filename, if_video_source, if_video_html FROM `posts_attachments` WHERE post_id='" . $obj->id . "' LIMIT 1", $conn);
                    $res = $res && $tmp2;
                    if ($atchobj = my_mysql_fetch_object($tmp2)) {
                        if ($atchobj->embed_type == 'video') {
                            $src = explode(' ', $atchobj->if_video_source);
                            $src[0] = strtolower($src[0]);
                            if (isset($VIDSRC[$src[0]])) {
                                $atch = (object) array('src_site' => $src[0], 'src_id' => trim($src[1]), 'title' => '', 'file_thumbnail' => '', 'embed_code' => stripslashes($atchobj->if_video_html), 'embed_w' => $atchobj->embed_w, 'embed_h' => $atchobj->embed_h, 'orig_url' => str_replace('###ID###', trim($src[1]), $VIDSRC[$src[0]]->insite_url), 'hits' => 0);
                                $fn = $atchobj->embed_thumb;
                                if (!empty($fn) && $fn != '_NOTHUMB.jpg') {
                                    $oldfile = INCPATH . '../../img/attachments/thumbs/' . $fn;
                                    $newfn = str_replace('.', '_thumb.', $fn);
                                    $newfile = INCPATH . '../../i/attachments/1/' . $newfn;
                                    if (@copy($oldfile, $newfile)) {
                                        @chmod($newfile, 0777);
                                        $atch->file_thumbnail = $newfn;
                                    }
                                }
                                $atch = my_mysql_real_escape_string(serialize($atch), $conn);
                                $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "posts_attachments` SET post_id='" . $obj->id . "', type='videoembed', data='" . $atch . "' ", $conn);
                            }
                        } elseif ($atchobj->embed_type == 'image') {
                            $fn = $atchobj->if_image_filename;
                            $old_file = INCPATH . '../../img/attachments/' . $fn;
                            $old_thumb = INCPATH . '../../img/attachments/thumbs/' . $atchobj->embed_thumb;
                            $atch = (object) array('title' => $fn, 'file_original' => str_replace('.', '_orig.', $fn), 'file_preview' => str_replace('.', '_large.', $fn), 'file_thumbnail' => str_replace('.', '_thumb.', $fn), 'size_original' => array($atchobj->embed_w, $atchobj->embed_h), 'size_preview' => array($atchobj->embed_w, $atchobj->embed_h), 'filesize' => 0, 'hits' => 0);
                            @copy($old_file, INCPATH . '../../i/attachments/1/' . $atch->file_original);
                            @copy($old_file, INCPATH . '../../i/attachments/1/' . $atch->file_preview);
                            @copy($old_thumb, INCPATH . '../../i/attachments/1/' . $atch->file_thumbnail);
                            $atch->filesize = intval(@filesize($old_file));
                            $atch = my_mysql_real_escape_string(serialize($atch), $conn);
                            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "posts_attachments` SET post_id='" . $obj->id . "', type='image', data='" . $atch . "' ", $conn);
                        }
                    }
                }
            }
        }
        if (in_array('posts_direct', $tables)) {
            $tmp = my_mysql_query("SELECT id, api_id, user_id, to_user, message, mentioned, attached_link, attachments, date, ip_address FROM `posts_direct` ORDER BY id ASC", $conn);
            $res = $res && $tmp;
            while ($obj = my_mysql_fetch_object($tmp)) {
                $api_id = $obj->api_id == 1 ? 1 : 0;
                $message = stripslashes($obj->message);
                $attached = intval($obj->attachments);
                if (!empty($obj->attached_link)) {
                    $attached++;
                }
                $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "posts_pr` SET id='" . $obj->id . "', api_id='" . $api_id . "', user_id='" . $obj->user_id . "', to_user='******', message='" . my_mysql_real_escape_string($message, $conn) . "', mentioned='" . $obj->mentioned . "', attached='" . $attached . "', posttags=0, comments=0, date='" . $obj->date . "', date_lastcomment='" . $obj->date . "', ip_addr='" . $obj->ip_address . "' ", $conn);
                if (!empty($obj->attached_link)) {
                    $atch = (object) array('link' => stripslashes($obj->attached_link), 'hits' => 0);
                    $atch = my_mysql_real_escape_string(serialize($atch), $conn);
                    $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "posts_pr_attachments` SET post_id='" . $obj->id . "', type='link', data='" . $atch . "' ", $conn);
                }
                if ($obj->attachments > 0) {
                    $tmp2 = my_mysql_query("SELECT embed_type, embed_w, embed_h, embed_thumb, if_image_filename, if_video_source, if_video_html FROM `posts_attachments_d` WHERE post_id='" . $obj->id . "' LIMIT 1", $conn);
                    $res = $res && $tmp2;
                    if ($atchobj = my_mysql_fetch_object($tmp2)) {
                        if ($atchobj->embed_type == 'video') {
                            $src = explode(' ', $atchobj->if_video_source);
                            $src[0] = strtolower($src[0]);
                            if (isset($VIDSRC[$src[0]])) {
                                $atch = (object) array('src_site' => $src[0], 'src_id' => trim($src[1]), 'title' => '', 'file_thumbnail' => '', 'embed_code' => stripslashes($atchobj->if_video_html), 'embed_w' => $atchobj->embed_w, 'embed_h' => $atchobj->embed_h, 'orig_url' => str_replace('###ID###', trim($src[1]), $VIDSRC[$src[0]]->insite_url), 'hits' => 0);
                                $fn = $atchobj->embed_thumb;
                                if (!empty($fn) && $fn != '_NOTHUMB.jpg') {
                                    $oldfile = INCPATH . '../../img/attachments/thumbs/' . $fn;
                                    $newfn = str_replace('.', '_thumb.', $fn);
                                    $newfile = INCPATH . '../../i/attachments/1/' . $newfn;
                                    if (@copy($oldfile, $newfile)) {
                                        @chmod($newfile, 0777);
                                        $atch->file_thumbnail = $newfn;
                                    }
                                }
                                $atch = my_mysql_real_escape_string(serialize($atch), $conn);
                                $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "posts_pr_attachments` SET post_id='" . $obj->id . "', type='videoembed', data='" . $atch . "' ", $conn);
                            }
                        } elseif ($atchobj->embed_type == 'image') {
                            $fn = $atchobj->if_image_filename;
                            $old_file = INCPATH . '../../img/attachments/' . $fn;
                            $old_thumb = INCPATH . '../../img/attachments/thumbs/' . $atchobj->embed_thumb;
                            $atch = (object) array('title' => $fn, 'file_original' => str_replace('.', '_orig.', $fn), 'file_preview' => str_replace('.', '_large.', $fn), 'file_thumbnail' => str_replace('.', '_thumb.', $fn), 'size_original' => array($atchobj->embed_w, $atchobj->embed_h), 'size_preview' => array($atchobj->embed_w, $atchobj->embed_h), 'filesize' => 0, 'hits' => 0);
                            @copy($old_file, INCPATH . '../../i/attachments/1/' . $atch->file_original);
                            @copy($old_file, INCPATH . '../../i/attachments/1/' . $atch->file_preview);
                            @copy($old_thumb, INCPATH . '../../i/attachments/1/' . $atch->file_thumbnail);
                            $atch->filesize = intval(@filesize($old_file));
                            $atch = my_mysql_real_escape_string(serialize($atch), $conn);
                            $res = $res && my_mysql_query("INSERT INTO `" . $prefix . "posts_pr_attachments` SET post_id='" . $obj->id . "', type='image', data='" . $atch . "' ", $conn);
                        }
                    }
                }
            }
        }
        if (!$res) {
            if (!empty($prefix)) {
                database_drop_tables_with_prefix($prefix);
            }
            return FALSE;
        }
        $tmp = my_mysql_query("SELECT id, user_id FROM `" . $prefix . "posts` WHERE user_id<>0 ORDER BY id ASC", $conn);
        while ($obj = my_mysql_fetch_object($tmp)) {
            my_mysql_query("INSERT INTO `" . $prefix . "posts_comments_watch` SET user_id='" . $obj->user_id . "', post_id='" . $obj->id . "', newcomments=0", $conn);
        }
        $tmp = my_mysql_query("SELECT id, user_id, to_user FROM `" . $prefix . "posts_pr` WHERE user_id<>0 ORDER BY id ASC", $conn);
        while ($obj = my_mysql_fetch_object($tmp)) {
            my_mysql_query("INSERT INTO `" . $prefix . "posts_pr_comments_watch` SET user_id='" . $obj->user_id . "', post_id='" . $obj->id . "', newcomments=0", $conn);
            my_mysql_query("INSERT INTO `" . $prefix . "posts_pr_comments_watch` SET user_id='" . $obj->to_user . "', post_id='" . $obj->id . "', newcomments=0", $conn);
        }
        $tmp = my_mysql_query("SELECT user_id, COUNT(id) AS c FROM `" . $prefix . "posts` GROUP BY user_id", $conn);
        while ($obj = my_mysql_fetch_object($tmp)) {
            my_mysql_query("UPDATE `" . $prefix . "users` SET num_posts='" . $obj->c . "' WHERE id='" . $obj->user_id . "' LIMIT 1", $conn);
        }
        if (!$res) {
            if (!empty($prefix)) {
                database_drop_tables_with_prefix($prefix);
            }
            return FALSE;
        }
        $res = $res && my_mysql_query("DROP TABLE IF EXISTS `badwords`, `posts_direct`, `posts_from_email`, `posts_pingbacks`, `posts_usertabs`, `users_feeds`, `users_feeds_posts`, `users_notif_rules`, `users_notif_sent`, `users_profile_hits`, `users_spammers`, `users_watched`, `users_tabs_state`, `posts_mentioned_d`, `posts_favs`, `posts_attachments_d` ;", $conn);
        foreach ($tables as $tbl) {
            if (substr($tbl, 0, strlen($prefix)) == $prefix) {
                $new = substr($tbl, strlen($prefix));
                $res = $res && my_mysql_query("DROP TABLE IF EXISTS `" . $new . "`;", $conn);
                $res = $res && my_mysql_query("RENAME TABLE `" . $tbl . "` TO `" . $new . "`;", $conn);
            }
        }
        if (!$res) {
            if (!empty($prefix)) {
                database_drop_tables_with_prefix($prefix);
            }
            return FALSE;
        }
    }
    return $res;
}
示例#2
0
function create_database($convert_version = FALSE)
{
    global $s, $VIDSRC;
    $conn = @mysql_connect($s['MYSQL_HOST'], $s['MYSQL_USER'], $s['MYSQL_PASS']);
    $dbs = @mysql_select_db($s['MYSQL_DBNAME'], $conn);
    if (!$conn || !$dbs) {
        return FALSE;
    }
    @mysql_query('SET NAMES utf8', $conn);
    if ($convert_version == '1.0.3' || $convert_version == '1.0.2' || $convert_version == '1.0.1' || $convert_version == '1.0.0') {
        @mysql_query("REPLACE INTO `settings` SET `word`='USERS_EMAIL_CONFIRMATION', `value`='1' ");
        return TRUE;
    }
    $prefix = '';
    if ($convert_version) {
        $prefix = substr(md5(rand() . time()), 0, rand(5, 8)) . '__';
    }
    $res = TRUE;
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "cache`;\r\n\t\t");
    $varchar_len = 255;
    $ver = @mysql_get_server_info($conn);
    $ver = str_replace('.', '', substr($ver, 0, 5));
    if (intval($ver) >= 503) {
        $varchar_len = 21810;
    }
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "cache` (\r\n\t\t\t  `key` varchar(32) NOT NULL,\r\n\t\t\t  `data` varchar(" . $varchar_len . ") NOT NULL,\r\n\t\t\t  `expire` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`key`)\r\n\t\t\t) ENGINE=MEMORY DEFAULT CHARSET=utf8;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "crons`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "crons` (\r\n\t\t\t  `cron` varchar(10) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `last_run` int(10) unsigned NOT NULL,\r\n\t\t\t  `next_run` int(10) unsigned NOT NULL,\r\n\t\t\t  `is_running` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`cron`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "groups` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `groupname` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `title` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `avatar` varchar(200) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `about_me` varchar(200) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `is_public` tinyint(1) unsigned NOT NULL,\r\n\t\t\t  `num_posts` int(10) unsigned NOT NULL default '0',\r\n\t\t\t  `num_followers` int(10) unsigned NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  UNIQUE KEY `groupname` (`groupname`),\r\n\t\t\t  KEY `is_public` (`is_public`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_admins`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "groups_admins` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `group_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `group_id` (`group_id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_deleted`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "groups_deleted` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL,\r\n\t\t\t  `groupname` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `title` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `is_public` tinyint(1) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `is_public` (`is_public`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_followed`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "groups_followed` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `group_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `date` int(10) unsigned NOT NULL,\r\n\t\t\t  `group_from_postid` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `user_id` (`user_id`),\r\n\t\t\t  KEY `group_id` (`group_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_private_members`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "groups_private_members` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `group_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `invited_by` int(10) unsigned NOT NULL,\r\n\t\t\t  `invited_date` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `group_id` (`group_id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_rssfeeds`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "groups_rssfeeds` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `group_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `feed_url` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `feed_userpwd` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `feed_title` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `filter_keywords` varchar(1000) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `date_added` int(10) unsigned NOT NULL,\r\n\t\t\t  `date_last_post` int(10) unsigned NOT NULL,\r\n\t\t\t  `date_last_crawl` int(10) unsigned NOT NULL,\r\n\t\t\t  `date_last_item` int(10) unsigned NOT NULL,\r\n\t\t\t  `added_by_user` int(10) unsigned NOT NULL,\r\n\t\t\t  `is_deleted` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `group_id` (`is_deleted`,`group_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "groups_rssfeeds_posts`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "groups_rssfeeds_posts` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `rssfeed_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `rssfeed_id` (`rssfeed_id`),\r\n\t\t\t  KEY `post_id` (`post_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "invitation_codes`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "invitation_codes` (\r\n\t\t\t  `code` varchar(32) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `user_id` int(10) NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`code`),\r\n\t\t\t  KEY `network_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `api_id` smallint(5) unsigned NOT NULL default '0',\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `group_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `message` varchar(1000) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `mentioned` tinyint(2) unsigned NOT NULL default '0',\r\n\t\t\t  `attached` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  `posttags` tinyint(2) unsigned NOT NULL default '0',\r\n\t\t\t  `comments` smallint(4) unsigned NOT NULL default '0',\r\n\t\t\t  `date` int(10) unsigned NOT NULL,\r\n\t\t\t  `date_lastedit` int(10) NOT NULL,\r\n\t\t\t  `date_lastcomment` int(10) NOT NULL,\r\n\t\t\t  `ip_addr` bigint(10) NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `user_id` (`user_id`),\r\n\t\t\t  KEY `group_id` (`group_id`),\r\n\t\t\t  FULLTEXT KEY `message` (`message`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_attachments`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_attachments` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `type` enum('link','image','videoembed','videoupload','text','file') collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `data` text collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `post_id` (`post_id`),\r\n\t\t\t  KEY `type` (`type`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_comments`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_comments` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `api_id` smallint(5) unsigned NOT NULL default '0',\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `message` text collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `mentioned` tinyint(2) unsigned NOT NULL,\r\n\t\t\t  `posttags` tinyint(2) unsigned NOT NULL,\r\n\t\t\t  `date` int(10) unsigned NOT NULL,\r\n\t\t\t  `ip_addr` bigint(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `post_id` (`post_id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_comments_mentioned`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_comments_mentioned` (\r\n\t\t\t  `id` int(10) NOT NULL auto_increment,\r\n\t\t\t  `comment_id` int(10) NOT NULL,\r\n\t\t\t  `user_id` int(10) NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `comment_id` (`comment_id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_comments_watch`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_comments_watch` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `newcomments` smallint(5) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `post_id` (`post_id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_mentioned`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_mentioned` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `post_id` (`post_id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `api_id` smallint(5) unsigned NOT NULL default '0',\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `to_user` int(10) unsigned NOT NULL,\r\n\t\t\t  `message` varchar(1000) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `mentioned` tinyint(2) unsigned NOT NULL default '0',\r\n\t\t\t  `attached` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  `posttags` tinyint(2) unsigned NOT NULL default '0',\r\n\t\t\t  `comments` smallint(4) unsigned NOT NULL default '0',\r\n\t\t\t  `date` int(10) unsigned NOT NULL,\r\n\t\t\t  `date_lastedit` int(10) NOT NULL,\r\n\t\t\t  `date_lastcomment` int(10) NOT NULL,\r\n\t\t\t  `ip_addr` bigint(10) NOT NULL,\r\n\t\t\t  `is_recp_del` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `user_id` (`user_id`),\r\n\t\t\t  KEY `to_user` (`to_user`),\r\n\t\t\t  KEY `is_recp_del` (`is_recp_del`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr_attachments`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr_attachments` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `type` enum('link','image','videoembed','videoupload','text','file') collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `data` text collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `post_id` (`post_id`),\r\n\t\t\t  KEY `type` (`type`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr_comments`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr_comments` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `api_id` smallint(5) unsigned NOT NULL default '0',\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `message` text collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `mentioned` tinyint(2) unsigned NOT NULL,\r\n\t\t\t  `posttags` tinyint(2) unsigned NOT NULL,\r\n\t\t\t  `date` int(10) unsigned NOT NULL,\r\n\t\t\t  `ip_addr` bigint(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `post_id` (`post_id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr_comments_mentioned`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr_comments_mentioned` (\r\n\t\t\t  `id` int(10) NOT NULL auto_increment,\r\n\t\t\t  `comment_id` int(10) NOT NULL,\r\n\t\t\t  `user_id` int(10) NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `comment_id` (`comment_id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr_comments_watch`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr_comments_watch` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `newcomments` smallint(5) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `user_id` (`user_id`),\r\n\t\t\t  KEY `post_id` (`post_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "posts_pr_mentioned`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "posts_pr_mentioned` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `post_id` (`post_id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "post_api`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "post_api` (\r\n\t\t\t  `id` smallint(5) unsigned NOT NULL auto_increment,\r\n\t\t\t  `name` varchar(50) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `total_posts` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tINSERT INTO `" . $prefix . "post_api` (`id`, `name`, `total_posts`) VALUES\r\n\t\t\t(1, 'mobi', 0),\r\n\t\t\t(2, 'RSS', 0),\r\n\t\t\t(3, 'email', 0),\r\n\t\t\t(4, 'web', 0);\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tUPDATE `" . $prefix . "post_api` SET id=0 WHERE id=4 LIMIT 1;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tALTER TABLE `" . $prefix . "post_api` AUTO_INCREMENT=4;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "post_favs`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "post_favs` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `post_type` enum('public','private') collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `date` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `post_type` (`post_type`,`post_id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "post_userbox`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "post_userbox` (\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  KEY `user_id` (`user_id`),\r\n\t\t\t  KEY `post_id` (`post_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "post_userbox_feeds`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "post_userbox_feeds` (\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  KEY `user_id` (`user_id`),\r\n\t\t\t  KEY `post_id` (`post_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "searches`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "searches` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `search_key` varchar(32) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `search_string` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `search_url` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `added_date` int(10) unsigned NOT NULL,\r\n\t\t\t  `total_hits` mediumint(5) unsigned NOT NULL default '0',\r\n\t\t\t  `last_results` mediumint(5) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `user_id` (`user_id`,`search_key`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\t\t\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "settings`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "settings` (\r\n\t\t\t  `word` varchar(100) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `value` text collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  UNIQUE KEY `word` (`word`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tINSERT INTO `" . $prefix . "settings` (`word`, `value`) VALUES\r\n\t\t\t('SITE_TITLE', '" . mysql_real_escape_string($s['SITE_TITLE']) . "'),\r\n\t\t\t('POST_MAX_SYMBOLS', '160'),\r\n\t\t\t('LANGUAGE', '" . mysql_real_escape_string($s['LANGUAGE']) . "'),\r\n\t\t\t('SYSTEM_EMAIL', '" . mysql_real_escape_string($s['ADMIN_EMAIL']) . "'),\r\n\t\t\t('COMPANY', '" . mysql_real_escape_string($s['SITE_TITLE']) . "'),\r\n\t\t\t('ATTACH_LINK_DISABLED', '0'),\r\n\t\t\t('ATTACH_IMAGE_DISABLED', '0'),\r\n\t\t\t('ATTACH_VIDEO_DISABLED', '0'),\r\n\t\t\t('ATTACH_FILE_DISABLED', '0'),\r\n\t\t\t('USERS_EMAIL_CONFIRMATION', '1'),\r\n\t\t\t('MOBI_DISABLED', '0');\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "unconfirmed_registrations`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "unconfirmed_registrations` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `email` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `fullname` varchar(100) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `confirm_key` varchar(32) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `invited_code` varchar(32) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `date` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  UNIQUE KEY `email` (`email`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "users` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `facebook_uid` varchar(32) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `email` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `username` varchar(200) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `password` varchar(32) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `fullname` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `avatar` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `about_me` text collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `tags` text collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `gender` enum('','m','f') collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `birthdate` date NOT NULL,\r\n\t\t\t  `position` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `location` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `language` varchar(5) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `timezone` varchar(100) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `num_posts` int(10) unsigned NOT NULL,\r\n\t\t\t  `num_followers` int(10) unsigned NOT NULL,\r\n\t\t\t  `used_storage` bigint(10) unsigned NOT NULL,\r\n\t\t\t  `js_animations` tinyint(1) unsigned NOT NULL default '1',\r\n\t\t\t  `dbrd_groups_closed` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  `dbrd_whattodo_closed` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  `comments_expanded` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  `reg_date` int(10) unsigned NOT NULL,\r\n\t\t\t  `reg_ip` bigint(10) NOT NULL,\r\n\t\t\t  `lastlogin_date` int(10) unsigned NOT NULL,\r\n\t\t\t  `lastlogin_ip` bigint(10) NOT NULL,\r\n\t\t\t  `lastpost_date` int(10) unsigned NOT NULL,\r\n\t\t\t  `lastemail_date` int(10) unsigned NOT NULL,\r\n\t\t\t  `lastclick_date` int(10) unsigned NOT NULL,\r\n\t\t\t  `lastclick_date_newest_post` int(10) unsigned NOT NULL,\r\n\t\t\t  `pass_reset_key` varchar(32) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `pass_reset_valid` int(10) unsigned NOT NULL,\r\n\t\t\t  `active` tinyint(1) unsigned NOT NULL default '1',\r\n\t\t\t  `is_network_admin` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  UNIQUE KEY `email` (`email`),\r\n\t\t\t  UNIQUE KEY `username` (`username`),\r\n\t\t\t  KEY `active` (`active`),\r\n\t\t\t  KEY `facebook_uid` (`facebook_uid`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\t\t\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_dashboard_tabs`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "users_dashboard_tabs` (\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `tab` enum('','all','@me','private','commented','feeds') collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `state` tinyint(1) unsigned NOT NULL,\r\n\t\t\t  `newposts` smallint(4) unsigned NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`user_id`,`tab`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_details`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "users_details` (\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `website` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `work_phone` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `personal_phone` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `personal_email` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `im_skype` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `im_icq` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `im_gtalk` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `im_msn` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `im_yahoo` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `im_aim` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `im_jabber` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_linkedin` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_facebook` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_twitter` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_flickr` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_friendfeed` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_delicious` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_digg` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_myspace` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_orcut` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_youtube` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_mixx` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_edno23` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `prof_favit` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_followed`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "users_followed` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `who` int(10) unsigned NOT NULL,\r\n\t\t\t  `whom` int(10) unsigned NOT NULL,\r\n\t\t\t  `date` int(10) unsigned NOT NULL,\r\n\t\t\t  `whom_from_postid` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `who` (`who`),\r\n\t\t\t  KEY `whom` (`whom`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_ignores`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "users_ignores` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `who` int(10) unsigned NOT NULL,\r\n\t\t\t  `whom` int(10) unsigned NOT NULL,\r\n\t\t\t  `date` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `who` (`who`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_invitations`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "users_invitations` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `date` int(10) unsigned NOT NULL,\r\n\t\t\t  `recp_name` varchar(100) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `recp_email` varchar(100) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `recp_is_registered` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  `recp_user_id` int(10) unsigned NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `user_id` (`user_id`,`recp_is_registered`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_notif_rules`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "users_notif_rules` (\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `ntf_them_if_i_follow_usr` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\r\n\t\t\t  `ntf_them_if_i_comment` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\r\n\t\t\t  `ntf_them_if_i_edt_profl` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\r\n\t\t\t  `ntf_them_if_i_edt_pictr` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\r\n\t\t\t  `ntf_them_if_i_create_grp` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\r\n\t\t\t  `ntf_them_if_i_join_grp` tinyint(1) unsigned NOT NULL COMMENT '0-off, 1-on',\r\n\t\t\t  `ntf_me_if_u_follows_me` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_follows_u2` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_commments_me` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_commments_m2` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_edt_profl` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_edt_pictr` tinyint(3) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_creates_grp` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_joins_grp` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_invit_me_grp` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_posts_qme` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_posts_prvmsg` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  `ntf_me_if_u_registers` tinyint(1) unsigned NOT NULL COMMENT '0-off, 2-msg, 3-mail, 1-both',\r\n\t\t\t  PRIMARY KEY  (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_pageviews`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "users_pageviews` (\r\n\t\t\t  `id` bigint(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `date` varchar(13) collate utf8_unicode_ci NOT NULL COMMENT 'YY-MM-DD HH',\r\n\t\t\t  `pageviews` smallint(5) unsigned NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `user_id` (`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_rssfeeds`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "users_rssfeeds` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `user_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `feed_url` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `feed_userpwd` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `feed_title` varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `filter_keywords` varchar(1000) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t  `date_added` int(10) unsigned NOT NULL,\r\n\t\t\t  `date_last_post` int(10) unsigned NOT NULL,\r\n\t\t\t  `date_last_crawl` int(10) unsigned NOT NULL,\r\n\t\t\t  `date_last_item` int(10) unsigned NOT NULL,\r\n\t\t\t  `is_deleted` tinyint(1) unsigned NOT NULL default '0',\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `group_id` (`is_deleted`,`user_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tDROP TABLE IF EXISTS `" . $prefix . "users_rssfeeds_posts`;\r\n\t\t");
    $res = $res && @mysql_query("\r\n\t\t\tCREATE TABLE `" . $prefix . "users_rssfeeds_posts` (\r\n\t\t\t  `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t  `rssfeed_id` int(10) unsigned NOT NULL,\r\n\t\t\t  `post_id` int(10) unsigned NOT NULL,\r\n\t\t\t  PRIMARY KEY  (`id`),\r\n\t\t\t  KEY `rssfeed_id` (`rssfeed_id`),\r\n\t\t\t  KEY `post_id` (`post_id`)\r\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\r\n\t\t");
    if (!$res) {
        if (!empty($prefix)) {
            database_drop_tables_with_prefix($prefix);
        }
        return FALSE;
    }
    if (!$convert_version && $s['ADMIN_ID'] == 0) {
        $res = $res && @mysql_query("\r\n\t\t\t\tINSERT INTO `" . $prefix . "users` SET\r\n\t\t\t\tid='1',\r\n\t\t\t\tusername='******'ADMIN_USER']) . "',\r\n\t\t\t\tpassword='******'ADMIN_PASS'])) . "',\r\n\t\t\t\temail='" . mysql_real_escape_string($s['ADMIN_EMAIL']) . "',\r\n\t\t\t\tfullname='" . mysql_real_escape_string($s['SITE_TITLE']) . "',\r\n\t\t\t\treg_date='" . time() . "',\r\n\t\t\t\treg_ip='" . ip2long($_SERVER['REMOTE_ADDR']) . "',\r\n\t\t\t\tlastpost_date='" . time() . "',\r\n\t\t\t\tlanguage='" . mysql_real_escape_string($s['LANGUAGE']) . "',\r\n\t\t\t\tnum_posts='1',\r\n\t\t\t\tnum_followers='0',\r\n\t\t\t\tactive='1',\r\n\t\t\t\tis_network_admin='1';\r\n\t\t\t");
        $res = $res && @mysql_query("\r\n\t\t\t\tINSERT INTO `" . $prefix . "posts` SET\r\n\t\t\t\tid='1',\r\n\t\t\t\tapi_id='0',\r\n\t\t\t\tuser_id='1',\r\n\t\t\t\tgroup_id='0',\r\n\t\t\t\tmessage='Welcome to " . $s['SITE_TITLE'] . " :)',\r\n\t\t\t\tmentioned=0,\r\n\t\t\t\tattached=0,\r\n\t\t\t\tposttags=0,\r\n\t\t\t\tcomments=0,\r\n\t\t\t\tdate='" . time() . "',\r\n\t\t\t\tdate_lastedit='',\r\n\t\t\t\tdate_lastcomment='" . time() . "',\r\n\t\t\t\tip_addr='" . ip2long($_SERVER['REMOTE_ADDR']) . "';\r\n\t\t\t");
        $res = $res && @mysql_query("\r\n\t\t\t\tINSERT INTO post_userbox SET user_id='1', post_id='1';\r\n\t\t\t");
        if (!$res) {
            if (!empty($prefix)) {
                database_drop_tables_with_prefix($prefix);
            }
            return FALSE;
        }
    }
    if ($convert_version == 'unofficial') {
        $tables = array();
        $tmp = mysql_query('SHOW TABLES FROM ' . $s['MYSQL_DBNAME'], $conn);
        while ($tbl = mysql_fetch_row($tmp)) {
            $tables[] = $tbl[0];
        }
        if (in_array('users_watched', $tables)) {
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "users_followed` (who, whom, date, whom_from_postid) SELECT who, whom, date, whom FROM `users_watched` ORDER BY id ASC");
        }
        if (in_array('users_invitations', $tables)) {
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "users_invitations` (user_id, date, recp_name, recp_email, recp_is_registered, recp_user_id) SELECT user_id, date, recp_name, recp_email, recp_is_registered, recp_user_id FROM `users_invitations` ORDER BY id ASC");
        }
        if (in_array('users_ignores', $tables)) {
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "users_ignores` (who, whom, date) SELECT who, whom, date FROM `users_ignores` ORDER BY id ASC");
        }
        if (in_array('users_feeds', $tables)) {
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "users_rssfeeds` (id, user_id, feed_url, date_added, date_last_post, date_last_crawl, date_last_item, is_deleted) SELECT id, user_id, feed_url, date_added, date_lastpost, date_lastcrawl, date_feed_lastentry, '0' FROM `users_feeds` ORDER BY id ASC");
            @mysql_query("UPDATE `" . $prefix . "users_rssfeeds` SET date_date_last_post='" . time() . "', date_last_crawl='" . time() . "', date_last_item='" . time() . "' ");
        }
        if (in_array('users_feeds_posts', $tables)) {
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "users_rssfeeds_posts` (rssfeed_id, post_id) SELECT feed_id, post_id FROM `users_feeds_posts` ORDER BY id ASC");
        }
        if (in_array('users', $tables)) {
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "users` (id, email, username, password, fullname, avatar, about_me, tags, gender, birthdate, location, language, num_posts, num_followers, reg_date, reg_ip, lastlogin_date, lastlogin_ip, lastpost_date, lastemail_date, lastclick_date, lastclick_date_newest_post, active, is_network_admin) SELECT id, email, username, password, fullname, avatar, about_me, tags, gender, birthdate, country, lang, '0', '0', reg_date, reg_ip, lastlogin_date, lastlogin_ip, lastpost_date, lastemail_date, lastclick_date, lastclick_date_newest_post, '1', '0' FROM `users` ORDER BY id ASC");
            if ($s['ADMIN_ID'] == 0) {
                @mysql_query("UPDATE `" . $prefix . "users` SET is_network_admin=1 WHERE id='1' LIMIT 1");
            } else {
                @mysql_query("UPDATE `" . $prefix . "users` SET is_network_admin=1 WHERE id='" . intval($s['ADMIN_ID']) . "' LIMIT 1");
            }
            $tmp = @mysql_query("SELECT whom, COUNT(who) AS c FROM `" . $prefix . "users_followed` GROUP BY whom");
            while ($obj = @mysql_fetch_object($tmp)) {
                @mysql_query("UPDATE `" . $prefix . "users` SET num_followers='" . $obj->c . "' WHERE id='" . $obj->whom . "' LIMIT 1");
            }
            $tmp = @mysql_query("SELECT DISTINCT language FROM `" . $prefix . "users` ");
            while ($obj = @mysql_fetch_object($tmp)) {
                if (empty($obj->language)) {
                    @mysql_query("UPDATE `" . $prefix . "users` SET language='" . mysql_real_escape_string($s['LANGUAGE']) . "' WHERE language='" . $obj->language . "' LIMIT 1");
                } elseif ($obj->language != $s['LANGUAGE'] && !file_exists(INCPATH . '../../system/languages/' . $obj->language)) {
                    @mysql_query("UPDATE `" . $prefix . "users` SET language='" . mysql_real_escape_string($s['LANGUAGE']) . "' WHERE language='" . $obj->language . "' LIMIT 1");
                }
            }
        }
        if (in_array('posts_favs', $tables)) {
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "post_favs` (user_id, post_type, post_id, date) SELECT user_id, 'public', post_id, date FROM `posts_favs` WHERE post_type='public' ORDER BY id ASC");
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "post_favs` (user_id, post_type, post_id, date) SELECT user_id, 'private', post_id, date FROM `posts_favs` WHERE post_type='direct' ORDER BY id ASC");
        }
        if (in_array('posts_mentioned', $tables)) {
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "posts_mentioned` (post_id, user_id) SELECT post_id, user_id FROM `posts_mentioned` ORDER BY id ASC");
        }
        if (in_array('posts_mentioned_d', $tables)) {
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "posts_pr_mentioned` (post_id, user_id) SELECT post_id, user_id FROM `posts_mentioned_d` ORDER BY id ASC");
        }
        if (in_array('posts_usertabs', $tables)) {
            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "post_userbox` (user_id, post_id) SELECT user_id, post_id FROM posts_usertabs");
            $ids = array();
            $tmp = @mysql_query('SELECT id FROM posts WHERE is_feed=1');
            while ($obj = @mysql_fetch_object($tmp)) {
                $ids[] = $obj->id;
            }
            if (count($ids)) {
                $ids = implode(', ', $ids);
                @mysql_query("INSERT INTO `" . $prefix . "post_userbox_feeds` (user_id, post_id) SELECT user_id, post_id FROM `" . $prefix . "post_userbox` WHERE post_id IN(" . $ids . ")");
                @mysql_query("DELETE FROM `" . $prefix . "post_userbox` WHERE post_id IN(" . $ids . ")");
            }
        }
        if (in_array('posts', $tables)) {
            $tmp = @mysql_query("SELECT id, api_id, user_id, message, mentioned, attached_link, attachments, date, ip_address, is_feed FROM `posts` ORDER BY id ASC");
            $res = $res && $tmp;
            while ($obj = @mysql_fetch_object($tmp)) {
                $api_id = $obj->api_id == 1 ? 1 : ($obj->is_feed == 1 ? 2 : 0);
                $message = stripslashes($obj->message);
                $attached = intval($obj->attachments);
                if (!empty($obj->attached_link)) {
                    $attached++;
                }
                $res = $res && @mysql_query("INSERT INTO `" . $prefix . "posts` SET id='" . $obj->id . "', api_id='" . $api_id . "', user_id='" . $obj->user_id . "', group_id=0, message='" . mysql_real_escape_string($message) . "', mentioned='" . $obj->mentioned . "', attached='" . $attached . "', posttags=0, comments=0, date='" . $obj->date . "', date_lastcomment='" . $obj->date . "', ip_addr='" . $obj->ip_address . "' ");
                if (!empty($obj->attached_link)) {
                    $atch = (object) array('link' => stripslashes($obj->attached_link), 'hits' => 0);
                    $atch = mysql_real_escape_string(serialize($atch));
                    $res = $res && @mysql_query("INSERT INTO `" . $prefix . "posts_attachments` SET post_id='" . $obj->id . "', type='link', data='" . $atch . "' ");
                }
                if ($obj->attachments > 0) {
                    $tmp2 = @mysql_query("SELECT embed_type, embed_w, embed_h, embed_thumb, if_image_filename, if_video_source, if_video_html FROM `posts_attachments` WHERE post_id='" . $obj->id . "' LIMIT 1");
                    $res = $res && $tmp2;
                    if ($atchobj = @mysql_fetch_object($tmp2)) {
                        if ($atchobj->embed_type == 'video') {
                            $src = explode(' ', $atchobj->if_video_source);
                            $src[0] = strtolower($src[0]);
                            if (isset($VIDSRC[$src[0]])) {
                                $atch = (object) array('src_site' => $src[0], 'src_id' => trim($src[1]), 'title' => '', 'file_thumbnail' => '', 'embed_code' => stripslashes($atchobj->if_video_html), 'embed_w' => $atchobj->embed_w, 'embed_h' => $atchobj->embed_h, 'orig_url' => str_replace('###ID###', trim($src[1]), $VIDSRC[$src[0]]->insite_url), 'hits' => 0);
                                $fn = $atchobj->embed_thumb;
                                if (!empty($fn) && $fn != '_NOTHUMB.jpg') {
                                    $oldfile = INCPATH . '../../img/attachments/thumbs/' . $fn;
                                    $newfn = str_replace('.', '_thumb.', $fn);
                                    $newfile = INCPATH . '../../i/attachments/1/' . $newfn;
                                    if (@copy($oldfile, $newfile)) {
                                        @chmod($newfile, 0777);
                                        $atch->file_thumbnail = $newfn;
                                    }
                                }
                                $atch = mysql_real_escape_string(serialize($atch));
                                $res = $res && @mysql_query("INSERT INTO `" . $prefix . "posts_attachments` SET post_id='" . $obj->id . "', type='videoembed', data='" . $atch . "' ");
                            }
                        } elseif ($atchobj->embed_type == 'image') {
                            $fn = $atchobj->if_image_filename;
                            $old_file = INCPATH . '../../img/attachments/' . $fn;
                            $old_thumb = INCPATH . '../../img/attachments/thumbs/' . $atchobj->embed_thumb;
                            $atch = (object) array('title' => $fn, 'file_original' => str_replace('.', '_orig.', $fn), 'file_preview' => str_replace('.', '_large.', $fn), 'file_thumbnail' => str_replace('.', '_thumb.', $fn), 'size_original' => array($atchobj->embed_w, $atchobj->embed_h), 'size_preview' => array($atchobj->embed_w, $atchobj->embed_h), 'filesize' => 0, 'hits' => 0);
                            @copy($old_file, INCPATH . '../../i/attachments/1/' . $atch->file_original);
                            @copy($old_file, INCPATH . '../../i/attachments/1/' . $atch->file_preview);
                            @copy($old_thumb, INCPATH . '../../i/attachments/1/' . $atch->file_thumbnail);
                            $atch->filesize = intval(@filesize($old_file));
                            $atch = mysql_real_escape_string(serialize($atch));
                            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "posts_attachments` SET post_id='" . $obj->id . "', type='image', data='" . $atch . "' ");
                        }
                    }
                }
            }
        }
        if (in_array('posts_direct', $tables)) {
            $tmp = @mysql_query("SELECT id, api_id, user_id, to_user, message, mentioned, attached_link, attachments, date, ip_address FROM `posts_direct` ORDER BY id ASC");
            $res = $res && $tmp;
            while ($obj = @mysql_fetch_object($tmp)) {
                $api_id = $obj->api_id == 1 ? 1 : 0;
                $message = stripslashes($obj->message);
                $attached = intval($obj->attachments);
                if (!empty($obj->attached_link)) {
                    $attached++;
                }
                $res = $res && @mysql_query("INSERT INTO `" . $prefix . "posts_pr` SET id='" . $obj->id . "', api_id='" . $api_id . "', user_id='" . $obj->user_id . "', to_user='******', message='" . mysql_real_escape_string($message) . "', mentioned='" . $obj->mentioned . "', attached='" . $attached . "', posttags=0, comments=0, date='" . $obj->date . "', date_lastcomment='" . $obj->date . "', ip_addr='" . $obj->ip_address . "' ");
                if (!empty($obj->attached_link)) {
                    $atch = (object) array('link' => stripslashes($obj->attached_link), 'hits' => 0);
                    $atch = mysql_real_escape_string(serialize($atch));
                    $res = $res && @mysql_query("INSERT INTO `" . $prefix . "posts_pr_attachments` SET post_id='" . $obj->id . "', type='link', data='" . $atch . "' ");
                }
                if ($obj->attachments > 0) {
                    $tmp2 = @mysql_query("SELECT embed_type, embed_w, embed_h, embed_thumb, if_image_filename, if_video_source, if_video_html FROM `posts_attachments_d` WHERE post_id='" . $obj->id . "' LIMIT 1");
                    $res = $res && $tmp2;
                    if ($atchobj = @mysql_fetch_object($tmp2)) {
                        if ($atchobj->embed_type == 'video') {
                            $src = explode(' ', $atchobj->if_video_source);
                            $src[0] = strtolower($src[0]);
                            if (isset($VIDSRC[$src[0]])) {
                                $atch = (object) array('src_site' => $src[0], 'src_id' => trim($src[1]), 'title' => '', 'file_thumbnail' => '', 'embed_code' => stripslashes($atchobj->if_video_html), 'embed_w' => $atchobj->embed_w, 'embed_h' => $atchobj->embed_h, 'orig_url' => str_replace('###ID###', trim($src[1]), $VIDSRC[$src[0]]->insite_url), 'hits' => 0);
                                $fn = $atchobj->embed_thumb;
                                if (!empty($fn) && $fn != '_NOTHUMB.jpg') {
                                    $oldfile = INCPATH . '../../img/attachments/thumbs/' . $fn;
                                    $newfn = str_replace('.', '_thumb.', $fn);
                                    $newfile = INCPATH . '../../i/attachments/1/' . $newfn;
                                    if (@copy($oldfile, $newfile)) {
                                        @chmod($newfile, 0777);
                                        $atch->file_thumbnail = $newfn;
                                    }
                                }
                                $atch = mysql_real_escape_string(serialize($atch));
                                $res = $res && @mysql_query("INSERT INTO `" . $prefix . "posts_pr_attachments` SET post_id='" . $obj->id . "', type='videoembed', data='" . $atch . "' ");
                            }
                        } elseif ($atchobj->embed_type == 'image') {
                            $fn = $atchobj->if_image_filename;
                            $old_file = INCPATH . '../../img/attachments/' . $fn;
                            $old_thumb = INCPATH . '../../img/attachments/thumbs/' . $atchobj->embed_thumb;
                            $atch = (object) array('title' => $fn, 'file_original' => str_replace('.', '_orig.', $fn), 'file_preview' => str_replace('.', '_large.', $fn), 'file_thumbnail' => str_replace('.', '_thumb.', $fn), 'size_original' => array($atchobj->embed_w, $atchobj->embed_h), 'size_preview' => array($atchobj->embed_w, $atchobj->embed_h), 'filesize' => 0, 'hits' => 0);
                            @copy($old_file, INCPATH . '../../i/attachments/1/' . $atch->file_original);
                            @copy($old_file, INCPATH . '../../i/attachments/1/' . $atch->file_preview);
                            @copy($old_thumb, INCPATH . '../../i/attachments/1/' . $atch->file_thumbnail);
                            $atch->filesize = intval(@filesize($old_file));
                            $atch = mysql_real_escape_string(serialize($atch));
                            $res = $res && @mysql_query("INSERT INTO `" . $prefix . "posts_pr_attachments` SET post_id='" . $obj->id . "', type='image', data='" . $atch . "' ");
                        }
                    }
                }
            }
        }
        if (!$res) {
            if (!empty($prefix)) {
                database_drop_tables_with_prefix($prefix);
            }
            return FALSE;
        }
        $tmp = @mysql_query("SELECT id, user_id FROM `" . $prefix . "posts` WHERE user_id<>0 ORDER BY id ASC");
        while ($obj = @mysql_fetch_object($tmp)) {
            @mysql_query("INSERT INTO `" . $prefix . "posts_comments_watch` SET user_id='" . $obj->user_id . "', post_id='" . $obj->id . "', newcomments=0");
        }
        $tmp = @mysql_query("SELECT id, user_id, to_user FROM `" . $prefix . "posts_pr` WHERE user_id<>0 ORDER BY id ASC");
        while ($obj = @mysql_fetch_object($tmp)) {
            @mysql_query("INSERT INTO `" . $prefix . "posts_pr_comments_watch` SET user_id='" . $obj->user_id . "', post_id='" . $obj->id . "', newcomments=0");
            @mysql_query("INSERT INTO `" . $prefix . "posts_pr_comments_watch` SET user_id='" . $obj->to_user . "', post_id='" . $obj->id . "', newcomments=0");
        }
        $tmp = @mysql_query("SELECT user_id, COUNT(id) AS c FROM `" . $prefix . "posts` GROUP BY user_id");
        while ($obj = @mysql_fetch_object($tmp)) {
            @mysql_query("UPDATE `" . $prefix . "users` SET num_posts='" . $obj->c . "' WHERE id='" . $obj->user_id . "' LIMIT 1");
        }
        if (!$res) {
            if (!empty($prefix)) {
                database_drop_tables_with_prefix($prefix);
            }
            return FALSE;
        }
        $res = $res && @mysql_query("DROP TABLE IF EXISTS `badwords`, `posts_direct`, `posts_from_email`, `posts_pingbacks`, `posts_usertabs`, `users_feeds`, `users_feeds_posts`, `users_notif_rules`, `users_notif_sent`, `users_profile_hits`, `users_spammers`, `users_watched`, `users_tabs_state`, `posts_mentioned_d`, `posts_favs`, `posts_attachments_d` ;");
        foreach ($tables as $tbl) {
            if (substr($tbl, 0, strlen($prefix)) == $prefix) {
                $new = substr($tbl, strlen($prefix));
                $res = $res && @mysql_query("DROP TABLE IF EXISTS `" . $new . "`;");
                $res = $res && @mysql_query("RENAME TABLE `" . $tbl . "` TO `" . $new . "`;");
            }
        }
        if (!$res) {
            if (!empty($prefix)) {
                database_drop_tables_with_prefix($prefix);
            }
            return FALSE;
        }
    }
    return $res;
}