Вход Регистрация
Файл: adultscript-2.0.3-pro/files/install/migrate-adultvideoscript.php
Строк: 683
<?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");
}

function 
show_prefs($value)
{
    
$show 'all';
    if (
$value == '1') {
        
$show 'friends';
    }
    
    if (
$value == '0') {
        
$show 'no';
    }
    
    return 
$show;
}

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.'/media/videos/flv',
            
$m_path.'/media/videos/hd',
            
$m_path.'/media/videos/tmb',
            
$m_path.'/media/videos/iphone',
            
$m_path.'/media/photos',
            
$m_path.'/media/photos/tmb',
            
$m_path.'/media/albums',
            
$m_path.'/media/categories/video',
            
$m_path.'/media/categories/photo',
            
$m_path.'/media/users'
        
);
        
        foreach (
$dirs as $dir) {
            if (!
file_exists($dir) OR !is_dir($dir) OR !is_readable($dir)) {
                
$errors[] = 'Invalid AVS 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 AVS 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 s.*, p.*
                     FROM #__signup AS s
                     LEFT JOIN #__users_prefs AS p ON (p.UID = s.UID)
                     ORDER BY s.UID ASC"
);
        
$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') ? 0;
            
$status        = ($user['account_status'] == 'Active') ? 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);
                
                
// not everything migrated here
                
$db->query("INSERT INTO #__user_preferences
                            SET user_id = "
.$user_id.",
                                show_video_favorites = '"
.show_prefs($user['show_favorites'])."',
                                show_video_playlists = '"
.show_prefs($user['show_playlist'])."',
                                show_friends = '"
.show_prefs($user['show_friends'])."',
                                show_subscriptions = '"
.show_prefs($user['show_subscriptions'])."',
                                show_subscribers = '"
.show_prefs($user['show_subscribers'])."'");
                
                if (
$user['photo'] != '') {
                      
$avatar $m_path.'/media/users/'.$user['photo'];
                      if (
file_exists($avatar) && is_file($avatar)) {
                          
$ext VFile::ext($avatar);
                          
$dt_method($avatarMEDIA_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 15%, lets initiate our database connections again :-)
        
update_progress('15^Migrating friends...');
        
$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 friends");
        
$friends $mdb->fetch_rows();
        foreach (
$friends as $friend) {
              
$user_id    FALSE;
              
$friend_id    FALSE;
              
              
$db->query("SELECT user_id
                          FROM #__user
                          WHERE old_user_id = "
.(int) $friend['UID']."
                          LIMIT 1"
);
              if (
$db->affected_rows()) {
                  
$user_id = (int) $db->fetch_field('user_id');
              }

              
$db->query("SELECT user_id
                          FROM #__user
                          WHERE old_user_id = "
.(int) $friend['FID']."
                          LIMIT 1"
);
              if (
$db->affected_rows()) {
                  
$friend_id = (int) $db->fetch_field('user_id');
              }
              
              
$status    'approved';
              if (
$friend['status'] != 'Confirmed') {
                  
$status strtolower($friend['status']);
              }
              
              if (
$user_id && $friend_id) {
                 
$add_date $friend['invite_date'].' 00:00:00';
               
$db->query("INSERT INTO #__user_friends
                            SET user_id = "
.$user_id.",
                                friend_id = "
.$friend_id.",
                                add_date = '"
.$add_date."',
                                status = '"
.$status."'");
                if (
$status == 'approved') {
                      
$db->query("UPDATE #__user_activity
                                  SET total_friends = total_friends
                                  WHERE user_id = "
.$friend_id." LIMIT 1");
                }
              }
        }

        
// progress 15%, lets initiate our database connections again :-)
        
update_progress('20^Migrating user 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 wall");
        
$comments $mdb->fetch_rows();
        foreach (
$comments as $comment) {
              
$user_id    FALSE;
              
$poster_id    FALSE;
              
              
$db->query("SELECT user_id
                          FROM #__user
                          WHERE old_user_id = "
.(int) $comment['OID']."
                          LIMIT 1"
);
              if (
$db->affected_rows()) {
                  
$user_id = (int) $db->fetch_field('user_id');
              }

              
$db->query("SELECT user_id
                          FROM #__user
                          WHERE old_user_id = "
.(int) $comment['UID']."
                          LIMIT 1"
);
              if (
$db->affected_rows()) {
                  
$poster_id = (int) $db->fetch_field('user_id');
              }
              
              if (
$user_id && $poster_id) {
                  
$db->query("INSERT INTO #__user_comments
                              SET user_id = "
.$user_id.",
                                  poster_id = "
.$poster_id.",
                                  comment = '"
.$db->escape($comment['message'])."',
                                  add_date = '"
.date('Y-m-d'$comment['addtime'])."'");
              }
        }
        
        
// 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'");
        }

        
$db->query("SHOW COLUMNS FROM #__photo_categories LIKE 'old_cat_id'");
        if (!
$db->affected_rows()) {
            
$db->query("ALTER TABLE #__photo_categories ADD `old_cat_id` int(11) NOT NULL default '0'");
        }

        
$mdb->query("SELECT CHID, name 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))."'");
            if (!
$db->affected_rows()) {
                die(
'Failed to add video category!');
            }

            
$db->query("INSERT INTO #__photo_categories
                        SET old_cat_id = "
.(int) $category['CHID'].",
                            name = '"
.$db->escape($category['name'])."',
                            slug = '"
.$db->escape(prepare_string($category['name'], TRUE))."'");
            if (!
$db->affected_rows()) {
                die(
'Failed to add video category!');
            }
        }

        
// progress 20%, lets initiate our database connections again :-)
        
update_progress('25^Migrating photo_albums...');
        
$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 #__photo_albums LIKE 'old_album_id'");
        if (!
$db->affected_rows()) {
            
$db->query("ALTER TABLE #__photo_albums ADD `old_album_id` int(11) NOT NULL default '0'");
        }
        
        
$mdb->query("SELECT * FROM albums ORDER BY AID ASC");
        
$albums $mdb->fetch_rows();
        foreach (
$albums as $album) {
            
$user_id    = (int) $db->get_field("SELECT user_id FROM #__user WHERE old_user_id = ".(int) $album['UID']." LIMIT 1"'user_id');
              
$db->query("INSERT INTO #__photo_albums
                          SET user_id = "
.$user_id.",
                                old_album_id = "
.(int) $album['AID'].",
                                title = '"
.$db->escape($album['name'])."',
                                slug = '"
.$db->escape(prepare_string($album['name'], true))."',
                                total_views = "
.(int) $album['total_views'].",
                                total_comments = "
.(int) $album['total_comments'].",
                                total_favorites = "
.(int) $album['total_favorites'].",
                                rating = "
.(float) $album['rate'].",
                                rated_by = "
.(int) $album['ratedby'].",
                                add_date = '"
.$album['adddate']."',
                                add_time = "
.strtotime($album['adddate']).",
                                status = '1'"
);
              if (
$db->affected_rows()) {
                  
$album_id $db->get_last_insert_id('#__photo_albums');
                  
$cat_id      $db->get_field("SELECT cat_id
                                              FROM #__photo_categories
                                              WHERE old_cat_id = "
.(int) $album['category']."
                                              LIMIT 1"
'cat_id');
                  
$db->query("INSERT INTO #__photo_category
                              SET album_id = "
.$album_id.",
                                  cat_id = "
.$cat_id);

                
$tag_string str_replace(','''prepare_tags($album['tags']));
                
$tag_array  explode(' '$tag_string);
                
$tags       = array();
                foreach (
$tag_array as $tag) {
                    if (
strlen($tag) >= 3) {
                        
$tags[] = $tag;
                    }
                }
                
                foreach (
$tags as $tag) {
                    
$db->query("INSERT INTO #__photo_tags
                                SET album_id = "
.$album_id.",
                                    name = '"
.$db->escape($tag)."'");
                }
                
                
$cover $m_path.'/media/albums/'.$album['AID'].'.jpg';
                if (
file_exists($cover) && is_file($cover)) {
                      
$dt_method($coverMEDIA_DIR.'/photos/covers/'.$album_id.'.jpg');
                }                
              }                  
        }

        
// progress 20%, lets initiate our database connections again :-)
        
update_progress('27^Migrating photos...');
        
$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');
        
        
$pcfg   VF::cfg('module.photo');
        
$image  VF::factory('image');        

        
$db->query("SHOW COLUMNS FROM #__photo LIKE 'old_photo_id'");
        if (!
$db->affected_rows()) {
            
$db->query("ALTER TABLE #__photo ADD `old_photo_id` int(11) NOT NULL default '0'");
        }
        
        
$mdb->query("SELECT * FROM photos");
        
$photos $mdb->fetch_rows();
        foreach (
$photos as $photo) {
              
$db->query("SELECT album_id FROM #__photo_albums WHERE old_album_id = ".(int) $photo['AID']." LIMIT 1");
              
$album_id = (int) $db->fetch_field('album_id');
              
            
$db->query("INSERT INTO #__photo
                        SET album_id = "
.$album_id.",
                            old_photo_id = "
.$photo['PID'].",
                            caption = '"
.$db->escape($photo['caption'])."',
                            total_views = "
.$photo['total_views'].",
                            rating = "
.$photo['rate'].",
                            rated_by = "
.$photo['ratedby'].",
                            ext = 'jpg',
                            status = '0'"
);
            if (
$db->affected_rows()) {
                
$photo_id     $db->get_last_insert_id('#__photo');
                
                
$src            $m_path.'/media/photos/'.$photo['PID'].'.jpg';
                
$dst            MEDIA_DIR.'/photos/'.$photo_id.'.jpg';
                
$dst_thumb        MEDIA_DIR.'/photos/thumbs/'.$photo_id.'.jpg';
                
$dst_orig        MEDIA_DIR.'/photos/orig/'.$photo_id.'.jpg';
                
$dst_thumb_tmp  TMP_DIR.'/images/'.$photo_id.'.thumb.jpg';
                if (
file_exists($src) && is_file($src)) {
                    
$dt_method($src$dst_orig);
                    
                    if (!
$image->load($dst_orig)) {
                        die(
'failed to load '.$dst_orig);
                        continue;
                    }
                    
                    if (
$image->src['width'] < $pcfg['photo_width']) {
                          
copy($dst_orig$dst);
                    } else {
                          if (!
$image->resize($pcfg['photo_width'], $pcfg['photo_height'], 'MAX_WIDTH'$dst)) {
                              die(
'failed to resize to '.$dst);
                              continue;
                          }
                    }

                    if (
$pcfg['mobile']) {
                          
$dst_mobile MEDIA_DIR.'/photos/mobile/'.$photo_id.'.'.$image->src['ext'];
                        if (
$image->src['width'] < $pcfg['mobile_width']) {
                              
copy($dst_orig$dst_mobile);
                        } else {
                              
$image->resize($pcfg['mobile_width'], $pcfg['mobile_height'], 'MAX_WIDTH'$dst_mobile);
                          }
                    }

                    
                    
$thumb_width    $pcfg['thumb_width']+30;
                    
$thumb_height   $pcfg['thumb_height']+100;
                    
$image->set_option('jpeg_quality'100);
                    if (!
$image->resize($thumb_width$thumb_height'MAX_HEIGHT'$dst_thumb_tmp)) {
                          die(
'failed thumb resize!');
                        continue;
                    }

                    
$image->clear();
                    
$image->load($dst_thumb_tmp);

                    if (!
$image->crop_from_center($pcfg['thumb_width'], $pcfg['thumb_height'], $dst_thumb)) {
                          die(
'failed crop from center');
                        continue;
                    }
                    
                    
$image->clear();
                    
                    
$db->query("UPDATE #__photo
                                SET status = '1'
                                WHERE photo_id = "
.$photo_id."
                                LIMIT 1"
);
                    
                    
$db->query("UPDATE #__photo_albums
                                SET total_photos = total_photos+1,
                                    status = '1'
                                WHERE album_id = "
.$album_id."
                                LIMIT 1"
);
                    
                    
VFile::delete($dst_thumb_tmp);
                }
            }
        }

        
// progress 20%, lets initiate our database connections again :-)
        
update_progress('29^Migrating photo 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 photo_comments");
        
$comments    $mdb->fetch_rows();
        foreach (
$comments as $comment) {
              
$db->query("SELECT album_id, photo_id
                          FROM #__photo
                          WHERE old_photo_id = "
.(int) $comment['PID']."
                          LIMIT 1"
);
              
$photo_id = (int) $db->fetch_field('photo_id');
              
$album_id = (int) $db->fetch_field('album_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 (
$photo_id && $album_id && $user_id) {
                  
$db->query("INSERT INTO #__photo_comments
                              SET photo_id = "
.$photo_id.",
                                  user_id = "
.$user_id.",
                                  comment = '"
.$db->escape($comment['comment'])."',
                                  add_date = '"
.date('Y-m-d h:i:s'$comment['addtime'])."'");
                  
$db->query("UPDATE #__photo
                              SET total_comments = total_comments+1
                              WHERE photo_id = "
.$photo_id."
                              LIMIT 1"
);
              }
        }

        
// progress 20%, lets initiate our database connections again :-)
        
update_progress('30^Migrating photo_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 * FROM photo_favorites");
        
$favorites $mdb->fetch_rows();
        foreach (
$favorites as $favorite) {
            
$db->query("SELECT photo_id
                        FROM #__photo
                        WHERE old_photo_id = "
.(int) $favorite['PID']."
                        LIMIT 1"
);
            if (
$db->affected_rows()) {
                
$photo_id = (int) $db->fetch_field('photo_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 (
$user_id && $photo_id) {
                  
$db->query("INSERT INTO #__photo_favorites
                              SET user_id = "
.$user_id.",
                                  photo_id = "
.$photo_id);
                  
$db->query("UPDATE #__photo
                              SET total_favorites = total_favorites+1
                              WHERE photo_id = "
.$photo_id."
                              LIMIT 1"
);
              }
        }

        
// progress 20%, lets initiate our database connections again :-)
        
update_progress('31^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['url'])."',
                              streaming_method = 'progressive',
                              url = '"
.$db->escape($server['url'])."',
                              ftp_host = '"
.$server['server_ip']."',
                              ftp_username = '"
.$server['ftp_username']."',
                              ftp_password = '"
.$server['ftp_password']."',
                              ftp_root = '"
.$server['ftp_root']."',
                              status = '"
.(int) $server['status']."'");

            
$files[$server['server_id']] = array();
        }
        
        
// progress 20%, lets initiate our database connections again :-)
        
update_progress('32^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 ORDER BY VID ASC");
        
$videos $mdb->fetch_rows();

        
$percent    68;
        
$count      count($videos);
        
$incr       round($percent/round($count/500), 2);
        
$progress   32;
                
        
$index      0;
        foreach (
$videos as $video) {
            
$db->query("SELECT user_id
                        FROM #__user
                        WHERE old_user_id = "
.(int) $video['UID']."
                        LIMIT 1"
);
            
$user_id = (int) $db->fetch_field('user_id');
            
            
$allow_comment    = ($video['be_comment'] == 'yes') ? 0;
            
$allow_rating    = ($video['be_rated'] == 'yes') ? 0;
            
$allow_embed    = ($video['embed'] == 'enabled') ? 0;
            
            
$view_time        = ($video['viewtime'] == '0000-00-00 00:00:00') ? strtotime($video['viewtime']);
            
            
$db->query("INSERT INTO #__video
                        SET old_video_id = "
.(int) $video['VID'].",
                            user_id = "
.$user_id.",
                            title = '"
.$db->escape($video['title'])."',
                            slug = '"
.$db->escape(prepare_string($video['title'], true))."',
                            description = '"
.$db->escape($video['description'])."',
                            rating = "
.$video['rate'].",
                            rated_by = "
.$video['ratedby'].",
                            embed_code = '"
.$db->escape($video['embed_code'])."',
                            allow_comment = '"
.$allow_comment."',
                            allow_rating = '"
.$allow_rating."',
                            allow_embed = '"
.$allow_embed."',
                            duration = "
.$video['duration'].",
                            thumb = "
.$video['thumb'].",
                            thumbs = "
.$video['thumbs'].",
                            total_views = "
.$video['viewnumber'].",
                            total_downloads = "
.$video['download_num'].",
                            add_date = '"
.$db->escape($video['adddate'])."',
                            add_time = "
.$video['addtime'].",
                            view_date = '"
.$video['viewtime']."',
                            view_time = "
.$view_time.",
                            status = 0"
);
            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) >= 3) {
                        
$db->query("INSERT INTO #__video_tags SET video_id = ".$video_id.", name = '".$db->escape($tag)."'");
                    }
                }
                
                
$category $video['channel'];
                if (!
is_numeric($category)) {
                    
$channel     explode('|'$category);
                    
$category     $channel['1'];
                }
                
                
$db->query("SELECT cat_id FROM #__video_categories WHERE old_cat_id = ".(int) $category." LIMIT 1");
                
$cat_id 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);
                
                
$thumbs        0;
                
$thumb_dir     MEDIA_DIR.'/videos/tmb/'.path($video_id);
                
VFolder::create($thumb_dir);
                for (
$i=1$i<=$video['thumbs']; $i++) {
                    
$src $m_path.'/media/videos/tmb/'.$video['VID'].'/'.$i.'.jpg';
                    
$dst $thumb_dir.'/'.$i.'.jpg';
                    if (
file_exists($src) && is_file($src)) {
                        
$dt_method($src$dst);
                        ++
$thumbs;
                    }
                }
                
                
$ext    = ($video['hd'] == '1') ? 'mp4' 'flv';
                
$server    0;
                if (
$video['server'] !== 0) {
                    
$db->query("SELECT server_id FROM #__server WHERE old_server_id = ".(int) $video['server']." LIMIT 1");
                    if (
$db->affected_rows()) {
                        
$server = (int) $db->fetch_field('server_id');
                    }
                }
                
                
$src_flv    $m_path.'/media/videos/flv/'.$video['VID'].'.flv';
                
$dst_flv    MEDIA_DIR.'/videos/flv/'.$video_id.'.flv';
                if (
file_exists($src_flv) && is_file($src_flv)) {
                    
$dt_method($src_flv$dst_flv);
                }
                
                if (
$ext == 'mp4') {
                    
$src_mp4 $m_path.'/media/videos/hd/'.$video['VID'].'.mp4';
                    
$dst_mp4 MEDIA_DIR.'/videos/mp4/'.$video_id.'.mp4';
                    if (
file_exists($src_mp4) && is_file($src_mp4)) {
                        
$dt_method($src_mp4$dst_mp4);
                    }
                }
                
                
$mobile        0;
                
$src_mobile    $m_path.'/media/videos/iphone/'.$video['VID'].'.mp4';
                
$dst_mobile MEDIA_DIR.'/videos/mobile/'.$video_id.'.mp4';
                if (
file_exists($src_mobile) && is_file($src_mobile)) {
                    if (
$dt_method($src_mobile$dst_mobile)) {
                        
$mobile 1;
                    }
                }
                
                
$db->query("UPDATE #__video
                            SET thumbs = "
.$thumbs.",
                                ext = '"
.$db->escape($ext)."',
                                mobile = '"
.$mobile."',
                                server = "
.$server.",
                                status = 1
                            WHERE video_id = "
.$video_id."
                            LIMIT 1"
);
            }
            
            
//lets save some data here...
            
$files[$video['server']][$video['VID']] = array(
                
'video_id'     => $video_id,
                
'flv'        => $video['VID'].'.flv',
                
'mp4'        => $video['VID'].'.mp4',
                
'mobile'    => $video['VID'].'.mp4'
            
);
            
            
            
// 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 20%, 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 video_comments");
        
$comments    $mdb->fetch_rows();
        foreach (
$comments as $comment) {
              
$video_id    FALSE;
              
$user_id    FALSE;
              
              
$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 (
$video_id && $user_id) {
                  
$db->query("INSERT INTO #__video_comments
                              SET video_id = "
.$video_id.",
                                  user_id = "
.$user_id.",
                                  comment = '"
.$db->escape($comment['comment'])."',
                                  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 20%, 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 * FROM favourite");
        
$favorites    $mdb->fetch_rows();
        foreach (
$favorites as $favorite) {
              
$video_id    FALSE;
              
$user_id    FALSE;
              
              
$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 && $user_id) {
                  
$db->query("INSERT INTO #__video_favorites
                                SET video_id = "
.$video_id.",
                                    user_id = "
.$user_id);
              }
        }
        
        
file_put_contents(BASE_DIR.'/install/data/data_videos.php'serialize($files));        
        
        
update_progress('100^Migration finished...');
                
        
$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;">&nbsp;</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 AVS Configuration file located in <code>/WHERE/AVS/IS/INSTALLED/include/config.db.php</code> and you
            need to know the path for the AVS installation.
            <p><strong>Path:</strong> Path where AVS is installed on your server</p>
            <p><strong>Database Server:</strong> AVS Database (MySQL) server address (<code>$config['db_host']</code> in the configuration file)!</p>
            <p><strong>Database Username:</strong> AVS Database (MySQL) username (<code>$config['db_user']</code> in the configuration file)!</p>
            <p><strong>Database Password:</strong> AVS Database (MySQL) password (<code>$config['db_pass']</code> in the configuration file)!</p>
            <p><strong>Database Name:</strong> AVS Database (MySQL) Name (<code>$config['db_name']</code> in the configuration file)!</p>
            <form id="migrate-form" method="post" action="<?php echo BASE_URL?>/install/migrate-adultvideoscript.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>
Онлайн: 2
Реклама