Файл: adultscript-2.0.3-pro/files/install/migrate-clipshare.php
Строк: 511
<?php
define('_VALID', true);
define('_INSTALL', true);
require realpath('../libraries/bootstrap.php');
define('INSTALL_URL', BASE_URL.'/install');
error_reporting(E_ALL);
ini_set('display_errors', 1);
restore_error_handler();
restore_exception_handler();
while(ob_get_level()) {
ob_end_flush();
}
// we dont need a session opened here
session_write_close();
$dt_method = 'copy';
$tag_length = 3;
$errors = array();
$test = VF::factory('test');
$required = $test->get_required_results();
$optional = $test->get_optional_results();
$recommended = $test->get_recommended_results();
$config = array(
'm_path' => '',
'm_db_host' => '',
'm_db_username' => '',
'm_db_password' => '',
'm_db_name' => '',
'base_url' => BASE_URL,
'relative_url' => RELATIVE_URL,
);
$secret = VText::random();
function show($value)
{
if ($value == '2') {
return 'no';
}
return ($value == '0') ? 'all' : 'friends';
}
function update_progress($data)
{
file_put_contents(TMP_DIR.'/logs/migration_progress.log', $data."n");
}
if (isset($_POST['submitted'])) {
$filter = VF::factory('filter');
$m_path = VFolder::safe($filter->get('m_path'));
$m_db_host = $filter->get('m_db_host');
$m_db_username = $filter->get('m_db_username');
$m_db_password = $filter->get('m_db_password');
$m_db_name = $filter->get('m_db_name');
if ($m_path == '') {
$errors[] = 'You need to enter the Clipshare Installation path to continue!';
} else {
$dirs = array(
$m_path,
$m_path.'/chimg',
$m_path.'/flvideo',
$m_path.'/thumb',
$m_path.'/photo'
);
foreach ($dirs as $dir) {
if (!file_exists($dir) OR !is_dir($dir) OR !is_readable($dir)) {
$errors[] = 'Invalid Clipshare installation (folder: '.$dir.' not found)!';
}
}
}
if ($m_db_host == '' OR $m_db_username == '' OR
$m_db_password == '' OR $m_db_name == '') {
$errors[] = 'You need to enter the Clipshare database host, username, password and name to continue!';
} else {
require 'db.php';
$mdb = new VInstall_db($m_db_host, $m_db_name, $m_db_username, $m_db_password, '');
if ($mdb->is_error()) {
$errors[] = $mdb->get_error();
}
}
if (!$errors) {
update_progress('1^Migrating users....');
$db = VF::factory('database');
$db->query("SHOW COLUMNS FROM #__user LIKE 'old_user_id'");
if (!$db->affected_rows()) {
$db->query("ALTER TABLE #__user ADD `old_user_id` int(11) NOT NULL default '0'");
}
$mdb->query("SELECT UID, email, username, pwd, fname, lname, bdate, gender, relation, aboutme,
city, country, zip, website, occupation, company, school, interest_hobby,
fav_movie_show, fav_music, fav_book, video_viewed, profile_viewed, watched_video,
addtime, logintime, emailverified, account_status, photo
FROM signup");
$users = $mdb->fetch_rows();
foreach ($users as $user) {
if ($user['username'] == 'anonymous') {
$db->query("UPDATE #__user
SET old_user_id = ".(int) $user['UID']."
WHERE username = 'anonymous'
LIMIT 1");
continue;
}
if ($user['username'] == 'admin') {
$db->query("UPDATE #__user
SET old_user_id = ".(int) $user['UID']."
WHERE username = 'admin'
LIMIT 1");
continue;
}
$gender = ($user['gender'] != '') ? strtolower($user['gender']) : 'hidden';
$relation = ($user['relation'] != '') ? strtolower($user['relation']) : 'hidden';
$verified = ($user['emailverified'] == 'yes') ? 1 : 0;
$status = ($user['account_status'] == 'Active') ? 1 : 0;
$db->query("INSERT INTO #__user
SET group_id = 5,
old_user_id = ".(int) $user['UID'].",
username = '".$db->escape(str_replace(' ', '-', $user['username']))."',
password = '".$db->escape($user['pwd'])."',
email = '".$db->escape($user['email'])."',
name = '".$db->escape($user['fname']).' '.$db->escape($user['lname'])."',
gender = '".$db->escape($gender)."',
relation = '".$db->escape($relation)."',
birth_date = '".$db->escape($user['bdate'])."',
city = '".$db->escape($user['city'])."',
country = '".$db->escape($user['country'])."',
join_date = '".$db->escape(date('Y-m-d h:i:s', (int) $user['addtime']))."',
login_date = '".$db->escape(date('Y-m-d h:i:s', (int) $user['logintime']))."',
verified = '".$verified."',
status = '".$status."'");
if ($db->affected_rows()) {
$user_id = $db->get_last_insert_id('#__user');
$db->query("INSERT INTO #__user_activity
SET user_id = ".$user_id.",
total_video_views = ".(int) $user['video_viewed'].",
total_viewed_videos = ".(int) $user['watched_video'].",
total_profile_views = ".(int) $user['profile_viewed']);
$db->query("INSERT INTO #__user_profile
SET user_id = ".$user_id.",
about = '".$db->escape($user['aboutme'])."',
website = '".$db->escape($user['website'])."',
hobbies = '".$db->escape($user['interest_hobby'])."',
school = '".$db->escape($user['school'])."',
occupation = '".$db->escape($user['occupation'])."',
movies = '".$db->escape($user['fav_movie_show'])."',
music = '".$db->escape($user['fav_music'])."',
books = '".$db->escape($user['fav_book'])."'");
$db->query("INSERT INTO #__user_notifications SET user_id = ".$user_id);
$db->query("INSERT INTO #__user_preferences SET user_id = ".$user_id);
if ($user['photo'] != '') {
$avatar = $m_path.'/photo/'.$user['photo'];
if (file_exists($avatar) && is_file($avatar)) {
$ext = VFile::ext($avatar);
$dt_method($avatar, MEDIA_DIR.'/users/'.$user_id.'.'.$ext);
$db->query("UPDATE #__user SET avatar = '".$db->escape($ext)."' WHERE user_id = ".$user_id." LIMIT 1");
}
}
} else {
die('Failed to add user!');
}
}
// progress 19%, lets initiate our database connections again :-)
update_progress('20^Migrating video categories...');
$mdb->close();
$mdb = new VInstall_db($m_db_host, $m_db_name, $m_db_username, $m_db_password, '');
$db = VF::factory_remove('database');
$db = VF::factory('database');
$db->query("SHOW COLUMNS FROM #__video_categories LIKE 'old_cat_id'");
if (!$db->affected_rows()) {
$db->query("ALTER TABLE #__video_categories ADD `old_cat_id` int(11) NOT NULL default '0'");
}
$mdb->query("SELECT CHID, name, descrip FROM channel ORDER BY name ASC");
$categories = $mdb->fetch_rows();
foreach ($categories as $category) {
$db->query("INSERT INTO #__video_categories
SET old_cat_id = ".(int) $category['CHID'].",
name = '".$db->escape($category['name'])."',
slug = '".$db->escape(prepare_string($category['name'], TRUE))."',
description = '".$db->escape($category['descrip'])."'");
if (!$db->affected_rows()) {
die('Failed to add video category!');
}
}
// progress 20%, lets initiate our database connections again :-)
update_progress('25^Migrating video servers...');
$mdb->close();
$mdb = new VInstall_db($m_db_host, $m_db_name, $m_db_username, $m_db_password, '');
$db = VF::factory_remove('database');
$db = VF::factory('database');
// this is to write the required data for the video migration
// for each server
$files = array();
$db->query("SHOW COLUMNS FROM #__server LIKE 'old_server_id'");
if (!$db->affected_rows()) {
$db->query("ALTER TABLE #__server ADD `old_server_id` int(11) NOT NULL default '0'");
}
$mdb->query("SELECT * FROM servers");
$servers = $mdb->fetch_rows();
foreach ($servers as $server) {
$db->query("INSERT INTO #__server
SET old_server_id = ".(int) $server['server_id'].",
server_name = '".$db->escape($server['server_url'])."',
streaming_method = 'progressive',
url = '".$db->escape($server['server_url'])."',
status = '".(int) $server['status']."'");
$files[$server['server_id']] = array();
}
update_progress('30^Migrating videos...');
$mdb->close();
$mdb = new VInstall_db($m_db_host, $m_db_name, $m_db_username, $m_db_password, '');
$db = VF::factory_remove('database');
$db = VF::factory('database');
$db->query("SHOW COLUMNS FROM #__video LIKE 'old_video_id'");
if (!$db->affected_rows()) {
$db->query("ALTER TABLE #__video ADD `old_video_id` int(11) NOT NULL default '0'");
}
$mdb->query("SELECT * FROM video");
$videos = $mdb->fetch_rows();
$percent = 75;
$count = count($videos);
$incr = round($percent/round($count/50, 0), 2);
$progress = 21;
$index = 0;
foreach ($videos as $video) {
$rating = 0;
if ($video['rate'] != '0') {
$rating = floor((float) $video['rate']);
$rating = round($rating/2, 1);
}
$user_id = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $video['UID']." LIMIT 1", 'user_id');
$type = ($video['type'] == 'public') ? 'public' : 'private';
$allow_embed = ($video['embed'] == 'enabled') ? 1 : 0;
$allow_comment = ($video['be_rated'] == 'yes') ? 1 : 0;
$allow_rating = ($video['be_comment'] == 'yes') ? 1 : 0;
$server = 0;
if ($video['server'] != '') {
$db->query("SELECT server_id FROM #__server
WHERE url = '".$db->escape($video['server'])."'
LIMIT 1");
if ($db->affected_rows()) {
$server = (int) $db->fetch_field('server_id');
}
}
$db->query("INSERT INTO #__video
SET user_id = ".$user_id.",
title = '".$db->escape($video['title'])."',
slug = '".$db->escape(prepare_string($video['title'], TRUE))."',
description = '".$db->escape($video['description'])."',
type = '".$db->escape($type)."',
rating = ".$rating.",
rated_by = ".(int) $video['ratedby'].",
duration = ".(float) $video['duration'].",
size = ".(float) $video['space'].",
thumb = ".(int) $video['thumb'].",
thumbs = 3,
allow_embed = '".$allow_embed."',
allow_comment = '".$allow_comment."',
allow_rating = '".$allow_rating."',
embed_code = '".$db->escape($video['embed_code'])."',
total_views = ".$video['viewnumber'].",
total_favorites = ".$video['fav_num'].",
total_comments = ".$video['com_num'].",
add_time = ".$video['addtime'].",
add_date = '".$db->escape($video['adddate'])."',
server = ".$server.",
status = 0,
old_video_id = ".$video['VID']);
if ($db->affected_rows()) {
$video_id = $db->get_last_insert_id('#__video');
$tags = str_replace(',', '', prepare_tags($video['keyword']));
$tags = explode(' ', $tags);
foreach ($tags as $tag) {
if (strlen($tag) >= $tag_length) {
$db->query("INSERT INTO #__video_tags SET video_id = ".$video_id.", name = '".$db->escape($tag)."'");
}
}
$categories = explode('|', $video['channel']);
foreach ($categories as $category) {
if ($category != '0') {
$db->query("SELECT cat_id FROM #__video_categories WHERE old_cat_id = ".(int) $category." LIMIT 1");
if ($db->affected_rows()) {
$cat_id = (int) $db->fetch_field('cat_id');
$db->query("INSERT INTO #__video_category
SET video_id = ".$video_id.",
cat_id = ".$cat_id);
$db->query("UPDATE #__video_categories
SET total_videos = total_videos+1
WHERE cat_id = ".$cat_id."
LIMIT 1");
}
}
}
// code to get the thumbs here once i download 2.9 GB
if ($server !== 0) {
$db->query("UPDATE #__server SET total_videos = total_videos+1 WHERE server_id = ".$server." LIMIT 1");
}
$db->query("UPDATE #__user_activity SET total_videos = total_videos+1 WHERE user_id = ".$user_id." LIMIT 1");
$db->query("UPDATE #__video
SET ext = 'flv',
status = 1
WHERE video_id = ".$video_id."
LIMIT 1");
$video_old = $video['VID'].'.flv';
$video_new = $video_id.'.flv';
$files[$server][$video_old] = $video_new;
} else {
die('Failed to add video!');
}
// doing the progress stuff here...not very accurate...enough for my eye
++$index;
if ($index === 50) {
$index = 0;
$progress = ($progress > 96) ? 96 : ($progress + $incr);
update_progress(floor($progress).'^Migrating videos...');
}
}
// progress 97%, lets initiate our database connections again :-)
update_progress('97^Migrating video comments...');
$mdb->close();
$mdb = new VInstall_db($m_db_host, $m_db_name, $m_db_username, $m_db_password, '');
$db = VF::factory_remove('database');
$db = VF::factory('database');
$mdb->query("SELECT * FROM comments");
$comments = $mdb->fetch_rows();
foreach ($comments as $comment) {
$video_id = 0;
$user_id = 0;
$db->query("SELECT video_id FROM #__video WHERE old_video_id = ".(int) $comment['VID']." LIMIT 1");
if ($db->affected_rows()) {
$video_id = (int) $db->fetch_field('video_id');
}
$db->query("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $comment['UID']." LIMIT 1");
if ($db->affected_rows()) {
$user_id = (int) $db->fetch_field('user_id');
}
if ($user_id !== 0 && $video_id !== 0) {
$db->query("INSERT INTO #__video_comments
SET video_id = ".$video_id.",
user_id = ".$user_id.",
comment = '".$db->escape($comment['commen'])."',
add_date = '".date('Y-m-d h:i:s', $comment['addtime'])."'");
$db->query("UPDATE #__video
SET total_comments = total_comments+1
WHERE video_id = ".$video_id."
LIMIT 1");
}
}
// progress 99%, lets initiate our database connections again :-)
update_progress('99^Migrating video favorites...');
$mdb->close();
$mdb = new VInstall_db($m_db_host, $m_db_name, $m_db_username, $m_db_password, '');
$db = VF::factory_remove('database');
$db = VF::factory('database');
$mdb->query("SELECT VID, UID FROM favourite");
$favorites = $mdb->fetch_rows();
foreach ($favorites as $favorite) {
$video_id = 0;
$user_id = 0;
$db->query("SELECT video_id FROM #__video WHERE old_video_id = ".(int) $favorite['VID']." LIMIT 1");
if ($db->affected_rows()) {
$video_id = (int) $db->fetch_field('video_id');
}
$db->query("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $favorite['UID']." LIMIT 1");
if ($db->affected_rows()) {
$user_id = (int) $db->fetch_field('user_id');
}
if ($video_id !== 0 && $user_id !== 0) {
$db->query("INSERT INTO #__video_favorites
SET video_id = ".$video_id.",
user_id = ".$user_id);
$db->query("UPDATE #__video SET total_favorites = total_favorites+1
WHERE video_id = ".$video_id." LIMIT 1");
}
}
foreach ($files as $key => $values) {
$output = array();
$output[] = '<?php return array(';
foreach ($values as $old => $new) {
$output[] = "'".$old."' => '".$new."',";
}
$output[] = '); ?>';
file_put_contents(BASE_DIR.'/install/data/videos_server_'.$key.'.php', implode("n", $output));
}
$finished = TRUE;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Adult Script Pro Migration</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<?php echo INSTALL_URL ?>/css/style.css?v1" type="text/css" media="all" />
<script type="text/javascript">var base_url = "<?php echo BASE_URL; ?>";</script>
</head>
<script type="text/javascript" src="<?php echo INSTALL_URL; ?>/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function update_migration_progress()
{
$.ajax({
url: base_url + '/install/ajax.php',
cache: false,
type: "POST",
dataType: "json",
data: {},
success: function(response){
$(".progress_msg").html('');
$(".bar").css('width', response.progress + '%');
$(".progress_msg").html(response.msg);
setTimeout("update_migration_progress()", 1200);
}
});
}
$(document).ready(function() {
$("img[id^='help_']").click(function() {
var id = $(this).attr('id').match(/help_(.*)/)[1];
if ($("p[id='test_" + id + "']").is(':visible')) {
$("p[id='test_" + id + "']").slideUp();
} else {
$("p[id='test_" + id + "']").slideDown();
}
});
$("input[id='submit-migrate']").click(function() {
$.ajax({
url: base_url + '/install/ajax.php',
cache: false,
type: "POST",
dataType: "json",
data: {},
success: function(response){
$("#progress-container").fadeIn();
setTimeout("update_migration_progress()", 1200);
$("#migrate-form").submit();
}
});
});
});
</script>
<body>
<div id="container">
<?php if ($errors): ?>
<div class="errors">
<?php foreach ($errors as $error): ?>
<span><?php echo htmlspecialchars($error),'<br />'; ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (isset($finished) && $finished === TRUE): ?>
<div style="width: 970px; padding: 2px 0; border: 1px solid #CCC;">
Migration finished! Please run the thumb and video migration scripts if you host on different server from ssh (or browser)!
</div>
<?php endif; ?>
<div id="progress-container" style="width: 970px; padding: 2px 0; border: 1px solid #CCC; display: none;">
<div style="width: 100%; text-align: center; font-weight: bold;">Please do not close your browser and do not click any link on this page!</div>
<div id="progress" style="width: 98%;"><div class="bar" style="width: 0;"> </div></div>
<div class="progress_msg"></div>
</div>
<div class="left width-475">
<h2>Testing Requirements</h2>
<div class="box-content">
<h3>Required Items</h3>
<?php foreach ($required as $id => $values): if (!isset($values['system'])): ?>
<span class="key"><?php if ($values['status'] !== true): echo '<strong>'; endif; ?><?php echo htmlspecialchars($values['message']); ?><?php if ($values['status'] !== true): echo '</strong>'; endif; ?></span>
<span class="value">
<?php if ($values['status'] === true): ?>
<img src="<?php echo INSTALL_URL; ?>/images/accept.png" alt="accept.png" />
<?php else: ?>
<img src="<?php echo INSTALL_URL; ?>/images/help.png" id="help_<?php echo $id; ?>" class="help" alt="help.png" />
<?php if (isset($values['warning']) && $values['warning'] == '1'): ?>
<img src="<?php echo INSTALL_URL; ?>/images/error.png" alt="error.png" />
<?php else: ?>
<img src="<?php echo INSTALL_URL; ?>/images/delete.png" alt="delete.png" />
<?php endif; endif; ?>
</span>
<div class="clear"></div>
<p id="test_<?php echo $id; ?>" style="display: none;"><?php echo htmlspecialchars($values['error']); ?></p>
<?php endif; endforeach; ?>
<h3>Required PHP Settings</h3>
<?php foreach ($recommended as $id => $values): if (!isset($values['system'])): ?>
<span class="key"><?php if ($values['status'] !== true): echo '<strong>'; endif; ?><?php echo htmlspecialchars($values['message']); ?><?php if ($values['status'] !== true): echo '</strong>'; endif; ?></span>
<span class="value">
<?php if ($values['status'] === true): ?>
<img src="<?php echo INSTALL_URL; ?>/images/accept.png" alt="accept.png" />
<?php else: ?>
<img src="<?php echo INSTALL_URL; ?>/images/help.png" id="help_<?php echo $id; ?>" class="help" alt="help.png" />
<?php if ($values['warning'] == '1'): ?>
<img src="<?php echo INSTALL_URL; ?>/images/error.png" alt="error.png" />
<?php else: ?>
<img src="<?php echo INSTALL_URL; ?>/images/delete.png" alt="delete.png" />
<?php endif; endif; ?>
</span>
<div class="clear"></div>
<p id="test_<?php echo $id; ?>" style="display: none;"><?php echo htmlspecialchars($values['error']); ?></p>
<?php endif; endforeach; ?>
<h3>Optional Items</h3>
<?php foreach ($optional as $id => $values): if (!isset($values['system'])): ?>
<span class="key"><?php if ($values['status'] !== true): echo '<strong>'; endif; ?><?php echo htmlspecialchars($values['message']); ?><?php if ($values['status'] !== true): echo '</strong>'; endif; ?></span>
<span class="value">
<?php if ($values['status'] === true): ?>
<img src="<?php echo INSTALL_URL; ?>/images/accept.png" alt="accept.png" />
<?php else: ?>
<img src="<?php echo INSTALL_URL; ?>/images/help.png" id="help_<?php echo $id; ?>" class="help" alt="help.png" />
<img src="<?php echo INSTALL_URL; ?>/images/error.png" alt="error.png" />
<?php endif; ?>
</span>
<div class="clear"></div>
<p id="test_<?php echo $id; ?>" style="display: none;"><?php echo htmlspecialchars($values['error']); ?></p>
<?php endif; endforeach; ?>
<form name="test-form" method="post" action="<?php echo BASE_URL; ?>/install/migrate.php?a=test">
<div class="submit">
<input name="submit-test" type="submit" id="submit-test" class="submit" value="Run Tests Again" />
</div>
</form>
</div>
</div>
<div class="right width-475">
<h2>Migration Options</h2>
<div class="box-content">
<h3>Migration Help</h3>
The below data can be gathered from the Clipshare Configuration file located in <code>/WHERE/CLIPSHARE/IS/INSTALLED/include/config.local.php</code>!
<p><strong>Path:</strong> Path where Clipshare is installed on your server (<code>$config['BASE_DIR']</code> in the configuration file)!</p>
<p><strong>Database Server:</strong> Clipshare Database (MySQL) server address (<code>$DBHOST</code> in the configuration file)!</p>
<p><strong>Database Username:</strong> Clipshare Database (MySQL) username (<code>$DBUSER</code> in the configuration file)!</p>
<p><strong>Database Password:</strong> Clipshare Database (MySQL) password (<code>$DBPASSWWORD</code> in the configuration file)!</p>
<p><strong>Database Name:</strong> Clipshare Database (MySQL) Name (<code>$DBNAME</code> in the configuration file)!</p>
<form id="migrate-form" method="post" action="<?php echo BASE_URL; ?>/install/migrate-clipshare.php">
<input name="submitted" type="hidden" value="1" />
<h3>Migration Options</h3>
<div>
<label for="m_path">Path</label>
<input name="m_path" type="text" id="m_path" class="large" value="<?php echo $config['m_path']; ?>" />
</div>
<div class="clear-left">
<label for="m_db_host">Database Server</label>
<input name="m_db_host" type="text" id="db_host" value="<?php echo $config['m_db_host']; ?>" />
</div>
<div class="clear-left">
<label for="m_db_username">Database Username</label>
<input name="m_db_username" type="text" id="db_username" value="<?php echo $config['m_db_username']; ?>" />
</div>
<div class="clear-left">
<label for="m_db_password">Database Password</label>
<input name="m_db_password" type="password" id="db_password" value="<?php echo $config['m_db_password']; ?>" />
</div>
<div class="clear-left">
<label for="m_db_name">Database Name</label>
<input name="m_db_name" type="text" id="db_name" value="<?php echo $config['m_db_name']; ?>" />
</div>
<div class="submit clear-left">
<input name="submit-migrate" type="button" id="submit-migrate" class="submit" value="Migrate >"
</div>
</form>
</div>
</div>
<div class="clear"></div>
</div>
</body>
</html>