function ConvertData() { global $C, $DB, $from_shell; $errors = array(); if (!is_dir($_REQUEST['directory'])) { $errors[] = "The directory " . htmlspecialchars($_REQUEST['directory']) . " does not exist on your server"; return DisplayMain($errors); } if (!is_file("{$_REQUEST['directory']}/tgpr.pl")) { $errors[] = "The tgpr.pl file could not be found in the " . htmlspecialchars($_REQUEST['directory']) . " directory"; return DisplayMain($errors); } if (!is_readable("{$_REQUEST['directory']}/tgpr.pl")) { $errors[] = "The tgpr.pl file in the " . htmlspecialchars($_REQUEST['directory']) . " directory could not be opened for reading"; return DisplayMain($errors); } // Check version $version_file_contents = file_get_contents("{$_REQUEST['directory']}/tgpr.pl"); if (preg_match('~\\$VERSION\\s+=\\s+\'(.*?)\'~', $version_file_contents, $matches)) { list($a, $b, $c) = explode('.', $matches[1]); if ($b < 2 || strpos($c, '-SS') === FALSE) { $errors[] = "Your TGP Rotator installation is outdated; please upgrade to the very latest snapshot release (1.2.1-SS)"; return DisplayMain($errors); } } else { $errors[] = "Unable to extract version information from tgpr.pl; your version of TGP Rotator is likely too old"; return DisplayMain($errors); } // Extract MySQL information $mysql_file_contents = file_get_contents("{$_REQUEST['directory']}/data/variables"); if ($mysql_file_contents === FALSE) { $errors[] = "Unable to read contents of the variables file"; return DisplayMain($errors); } $vars = array(); if (preg_match_all('~^\\$([a-z0-9_]+)\\s+=\\s+\'(.*?)\';$~msi', $mysql_file_contents, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $vars[$match[1]] = $match[2]; } } if (!isset($vars['USERNAME']) || !isset($vars['DATABASE']) || !isset($vars['HOSTNAME'])) { $errors[] = "Unable to extract MySQL database information from the variables file"; return DisplayMain($errors); } if (!is_writable("{$GLOBALS['BASE_DIR']}/annotations")) { $errors[] = "Change the permissions on the TGPX annotations directory to 777"; return DisplayMain($errors); } if ($C['preview_dir'] == $vars['THUMB_DIR']) { $errors[] = "The TGPX Thumbnail URL cannot be the same as the TGP Rotator Thumbnail URL"; return DisplayMain($errors); } $CONVERTDB = new DB($vars['HOSTNAME'], $vars['USERNAME'], $vars['PASSWORD'], $vars['DATABASE']); $CONVERTDB->Connect(); $CONVERTDB->Update('SET wait_timeout=86400'); $columns = $CONVERTDB->GetColumns('tr_Galleries'); if (!in_array('Thumbnail_URL', $columns)) { $errors[] = "Your TGP Rotator installation is outdated; please upgrade to the latest snapshot release"; return DisplayMain($errors); } if (!$from_shell) { echo "<pre>"; } // Copy annotations FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying annotation font files and images...\n"); echo "Copying annotation font files and images...\n"; flush(); $annotations =& DirRead($vars['ANNOTATION_DIR'], '^[^.]'); foreach ($annotations as $annotation) { @copy("{$vars['ANNOTATION_DIR']}/{$annotation}", "{$GLOBALS['BASE_DIR']}/annotations/{$annotation}"); } // Copy thumbnail previews FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying thumbnail preview images...\n"); echo "Copying thumbnail preview images...\n"; flush(); $thumbs =& DirRead($vars['THUMB_DIR'], '\\.jpg$'); foreach ($thumbs as $thumb) { @copy("{$vars['THUMB_DIR']}/{$thumb}", "{$C['preview_dir']}/t_{$thumb}"); @chmod("{$C['preview_dir']}/t_{$thumb}", 0666); } // // Dump annotations FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting annotation settings...\n"); echo "Converting annotation settings...\n"; flush(); $annotations = array(); $DB->Update('DELETE FROM `tx_annotations`'); $result = $CONVERTDB->Query('SELECT * FROM `tr_Annotations`'); while ($annotation = $CONVERTDB->NextRow($result)) { $DB->Update('INSERT INTO `tx_annotations` VALUES (?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $annotation['Identifier'], strtolower($annotation['Type']), $annotation['String'], 0, $annotation['Font_File'], $annotation['Size'], $annotation['Color'], $annotation['Shadow'], $annotation['Image_File'], $annotation['Transparency'], $annotation['Location'])); $annotations[$annotation['Unique_ID']] = $DB->InsertID(); } $CONVERTDB->Free($result); // // Dump categories FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting categories...\n"); echo "Converting categories...\n"; flush(); $categories = array(); $category_ids = array(); $DB->Update('DELETE FROM `tx_categories`'); $result = $CONVERTDB->Query('SELECT * FROM `tr_Categories`'); while ($category = $CONVERTDB->NextRow($result)) { $tag = CreateCategoryTag($category['Name']); $categories[$category['Name']] = $tag; $DB->Update('INSERT INTO `tx_categories` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $category['Name'], $tag, empty($category['Pictures']) ? 0 : 1, $category['Pictures'], 10, 30, 12288, "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, $annotations[$category['Ann_Pictures']], empty($category['Movies']) ? 0 : 1, $category['Movies'], 5, 30, 102400, "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, $annotations[$category['Ann_Movies']], -1, 0, null, null, null)); $category_ids[$category['Name']] = $DB->InsertID(); } $CONVERTDB->Free($result); // // Dump sponsors FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting sponsors...\n"); echo "Converting sponsors...\n"; flush(); $counter = 1; $sponsors = array(); $DB->Update('DELETE FROM `tx_sponsors`'); $result = $CONVERTDB->Query('SELECT DISTINCT `Sponsor` FROM `tr_Galleries` WHERE `Sponsor`!=?', array('')); while ($sponsor = $CONVERTDB->NextRow($result)) { $sponsors[$sponsor['Sponsor']] = $counter; $DB->Update("INSERT INTO `tx_sponsors` VALUES (?,?,?)", array($counter++, $sponsor['Sponsor'], null)); } $CONVERTDB->Free($result); // // Dump gallery data FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting gallery data...\n"); echo "Converting gallery data...\n"; flush(); $DB->Update('DELETE FROM `tx_galleries`'); $DB->Update('DELETE FROM `tx_gallery_fields`'); $DB->Update('DELETE FROM `tx_gallery_icons`'); $DB->Update('DELETE FROM `tx_gallery_previews`'); $DB->Update('ALTER TABLE `tx_galleries` AUTO_INCREMENT=0'); $DB->Update('ALTER TABLE `tx_gallery_previews` AUTO_INCREMENT=0'); $result = $CONVERTDB->Query('SELECT * FROM `tr_Galleries` ORDER BY `Gallery_ID`'); $preview_sizes = array(); while ($gallery = $CONVERTDB->NextRow($result)) { $DB->Update("INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", array(null, $gallery['Gallery_URL'], $gallery['Description'], $gallery['Keywords'], $gallery['Thumbnails'], $C['from_email'], null, $gallery['Weight'], $gallery['Clicks'], $_SERVER['REMOTE_ADDR'], null, !empty($gallery['Sponsor']) ? $sponsors[$gallery['Sponsor']] : null, 'permanent', strtolower($gallery['Type']), $gallery['Status'] == 'Pending' ? 'approved' : strtolower($gallery['Status']), $gallery['Status'] == 'Disabled' ? 'approved' : null, date(DF_DATETIME, TimeWithTz($gallery['Added'])), date(DF_DATETIME, TimeWithTz($gallery['Added'])), date(DF_DATETIME, TimeWithTz($gallery['Added'])), empty($gallery['Scheduled_Date']) ? null : "{$gallery['Scheduled_Date']} 00:00:00", empty($gallery['Display_Date']) ? null : "{$gallery['Display_Date']} 12:00:00", null, null, 'TGPR Convert', '', null, 0, empty($gallery['Thumbnail_URL']) ? 0 : 1, $gallery['Allow_Scan'], $gallery['Allow_Thumb'], $gallery['Times_Selected'], $gallery['Used_Counter'], $gallery['Build_Counter'], null, MIXED_CATEGORY . " " . $categories[$gallery['Category']])); $gallery_id = $DB->InsertID(); $gallery_info = array('gallery_id' => $gallery_id); $insert = CreateUserInsert('tx_gallery_fields', $gallery_info); $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']); foreach (explode(',', $gallery['Icons']) as $icon_id) { if (isset($icons[$icon_id])) { $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($gallery_id, $icons[$icon_id])); } } if (!empty($gallery['Thumbnail_URL'])) { $dimensions = ''; if (!empty($gallery['Thumb_Width']) && !empty($gallery['Thumb_Height'])) { $dimensions = "{$gallery['Thumb_Width']}x{$gallery['Thumb_Height']}"; $preview_sizes[$dimensions] = TRUE; } $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery_id, '', $dimensions)); $preview_id = $DB->InsertID(); if (preg_match('~^' . preg_quote($vars['THUMB_URL']) . '~i', $gallery['Thumbnail_URL'])) { $gallery['Thumbnail_URL'] = "{$C['preview_url']}/{$preview_id}.jpg"; $DB->Update('UPDATE `tx_gallery_previews` SET `preview_url`=? WHERE `preview_id`=?', array($gallery['Thumbnail_URL'], $preview_id)); @rename("{$C['preview_dir']}/t_{$gallery['Gallery_ID']}.jpg", "{$C['preview_dir']}/{$preview_id}.jpg"); } } } $CONVERTDB->Free($result); // Update the stored thumbnail preview sizes $sizes = unserialize(GetValue('preview_sizes')); if (!is_array($sizes)) { $sizes = array(); } $sizes = array_merge($sizes, array_keys($preview_sizes)); StoreValue('preview_sizes', serialize(array_unique($sizes))); // // Dump TGP page data FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting TGP pages...\n"); echo "Converting TGP pages...\n"; flush(); $build_order = 1; $DB->Update('DELETE FROM `tx_pages`'); $DB->Update('ALTER TABLE `tx_pages` AUTO_INCREMENT=0'); $result = $CONVERTDB->Query('SELECT * FROM `tr_Pages` ORDER BY `Build_Order`'); while ($page = $CONVERTDB->NextRow($result)) { $template = file_get_contents("{$_REQUEST['directory']}/data/pages/{$page['Page_ID']}"); $template = ConvertTemplate($template); $compiled = ''; $page['Directory'] = preg_replace('~/$~', '', $page['Directory']); $DB->Update('INSERT INTO `tx_pages` VALUES (?,?,?,?,?,?,?,?,?)', array(null, "{$page['Directory']}/{$page['Filename']}", $page['Page_URL'], $page['Category'] == 'Mixed' ? null : $category_ids[$page['Category']], $build_order++, 0, null, $template, $compiled)); } $CONVERTDB->Free($result); FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "\nData conversion complete!"); echo "\nData conversion complete!\n"; if (!$from_shell) { echo "</pre>"; } }
if (!is_file('scanner.php')) { echo "This file must be located in the admin directory of your TGPX installation"; exit; } define('TGPX', TRUE); require_once '../includes/common.php'; require_once "{$GLOBALS['BASE_DIR']}/includes/mysql.class.php"; require_once "{$GLOBALS['BASE_DIR']}/admin/includes/functions.php"; SetupRequest(); $DB = new DB($C['db_hostname'], $C['db_username'], $C['db_password'], $C['db_name']); $DB->Connect(); @set_time_limit(0); if ($_SERVER['REQUEST_METHOD'] == 'POST') { ResetInstall(); } else { DisplayMain(); } $DB->Disconnect(); function ResetInstall() { global $DB, $C; IniParse("{$GLOBALS['BASE_DIR']}/includes/tables.php", TRUE, $tables); foreach ($tables as $table => $create) { $DB->Update('DROP TABLE IF EXISTS #', array($table)); } FileWrite("{$GLOBALS['BASE_DIR']}/includes/config.php", "<?php\n\$C = array();\n?>"); if (is_dir("{$GLOBALS['BASE_DIR']}/cache")) { $cached =& DirRead("{$GLOBALS['BASE_DIR']}/cache", '^[^.]'); foreach ($cached as $cache) { @unlink("{$GLOBALS['BASE_DIR']}/cache/{$cache}"); }
function ConvertData() { global $C, $DB, $from_shell; $errors = array(); if (!is_dir($_REQUEST['directory'])) { $errors[] = "The directory " . htmlspecialchars($_REQUEST['directory']) . " does not exist on your server"; return DisplayMain($errors); } if (!is_file("{$_REQUEST['directory']}/agp.pl")) { $errors[] = "The agp.pl file could not be found in the " . htmlspecialchars($_REQUEST['directory']) . " directory; make sure you have version 3.0.0 or newer installed"; return DisplayMain($errors); } if (!is_readable("{$_REQUEST['directory']}/agp.pl")) { $errors[] = "The agp.pl file in the " . htmlspecialchars($_REQUEST['directory']) . " directory could not be opened for reading"; return DisplayMain($errors); } // Check version $version_file_contents = file_get_contents("{$_REQUEST['directory']}/agp.pl"); if (preg_match('~\\$VERSION\\s+=\\s+\'(.*?)\'~', $version_file_contents, $matches)) { list($a, $b, $c) = explode('.', $matches[1]); $c = str_replace('-SS', '', $c); if ($a < 3) { $errors[] = "Your AutoGallery Pro installation is outdated ({$matches[1]}); please upgrade to version 3.0.0+"; return DisplayMain($errors); } } else { $errors[] = "Unable to extract version information from agp.pl; your version of AutoGallery Pro is likely too old"; return DisplayMain($errors); } // Extract variables $var_file_contents = file_get_contents("{$_REQUEST['directory']}/data/variables"); if ($var_file_contents === FALSE) { $errors[] = "Unable to read contents of the variables file"; return DisplayMain($errors); } $vars = array(); if (preg_match_all('~^\\$([a-z0-9_]+)\\s+=\\s+\'(.*?)\';$~msi', $var_file_contents, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $vars[$match[1]] = $match[2]; } } if (!isset($vars['ADMIN_EMAIL'])) { $errors[] = "Unable to extract variable data from the AutoGallery Pro variables file"; return DisplayMain($errors); } if (!is_writable($C['font_dir'])) { $errors[] = "Change the permissions on the TGPX fonts directory to 777"; return DisplayMain($errors); } if ($C['preview_dir'] == $vars['THUMB_DIR']) { $errors[] = "The TGPX Thumbnail URL cannot be the same as the AutoGallery Pro Thumbnail URL"; return DisplayMain($errors); } if (!$from_shell) { echo "<pre>"; } // Copy fonts for validation codes FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying font files for verification codes...\n"); echo "Copying font files for verification codes...\n"; flush(); $fonts =& DirRead($vars['FONT_DIR'], '^[^.]'); foreach ($fonts as $font) { @copy("{$vars['FONT_DIR']}/{$font}", "{$C['font_dir']}/{$font}"); } // Copy thumbnail previews FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying thumbnail preview images...\n"); echo "Copying thumbnail preview images...\n"; flush(); $thumbs =& DirRead($vars['THUMB_DIR'], '\\.jpg$'); foreach ($thumbs as $thumb) { @copy("{$vars['THUMB_DIR']}/{$thumb}", "{$C['preview_dir']}/t_{$thumb}"); @chmod("{$C['preview_dir']}/t_{$thumb}", 0666); } // // Dump e-mail log FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting e-mail log...\n"); echo "Converting e-mail log...\n"; flush(); $emails = file("{$_REQUEST['directory']}/data/emails"); $DB->Update('DELETE FROM `tx_email_log`'); foreach ($emails as $email) { $email = trim($email); if (empty($email)) { continue; } $DB->Update('REPLACE INTO `tx_email_log` VALUES (?)', array($email)); } // // Dump blacklist FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting blacklist...\n"); echo "Converting blacklist...\n"; flush(); $DB->Update('DELETE FROM `tx_blacklist`'); $types = array('submit_ip' => 'submitip', 'email' => 'email', 'url' => 'domain', 'domain_ip' => 'domainip', 'word' => 'word', 'html' => 'html', 'dns' => 'dns'); foreach ($types as $new_type => $old_type) { $blist_items = file("{$_REQUEST['directory']}/data/blacklist/{$old_type}"); foreach ($blist_items as $html) { $html = trim($html); if (empty($html)) { continue; } $regex = 0; if (strpos($html, '*') !== FALSE) { $regex = 1; $html = preg_quote($html); $html = str_replace('\\*', '.*?', $html); } $DB->Update('INSERT INTO `tx_blacklist` VALUES (?,?,?,?,?)', array(null, $new_type, $regex, $html, '')); } } // // Dump whitelist FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting whitelist...\n"); echo "Converting whitelist...\n"; flush(); $DB->Update('DELETE FROM `tx_whitelist`'); $wlist_items = file("{$_REQUEST['directory']}/data/blacklist/whitelist"); foreach ($wlist_items as $html) { $html = trim($html); if (empty($html)) { continue; } $regex = 0; if (strpos($html, '*') !== FALSE) { $regex = 1; $html = preg_quote($html); $html = str_replace('\\*', '.*?', $html); } $DB->Update('INSERT INTO `tx_whitelist` VALUES (?,?,?,?,?,?,?,?,?,?)', array(null, 'url', $regex, $html, '', 1, 0, 0, 0, 0)); } // // Dump reciprocal links FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting reciprocal link settings...\n"); echo "Converting reciprocal link settings...\n"; flush(); $DB->Update('DELETE FROM `tx_reciprocals`'); IniParse("{$_REQUEST['directory']}/data/generalrecips", TRUE, $recips); IniParse("{$_REQUEST['directory']}/data/trustedrecips", TRUE, $recips); foreach ($recips as $identifier => $html) { $regex = 0; if (strpos($html, '*') !== FALSE) { $regex = 1; $html = preg_quote($html); $html = str_replace('\\*', '.*?', $html); } $DB->Update('INSERT INTO `tx_reciprocals` VALUES (?,?,?,?)', array(null, $identifier, trim($html), $regex)); } // // Dump icons FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting icons...\n"); echo "Converting icons...\n"; flush(); $icons = array(); $DB->Update('DELETE FROM `tx_icons`'); IniParse("{$_REQUEST['directory']}/data/icons", TRUE, $icons_ini); foreach ($icons_ini as $identifier => $html) { $identifier = trim($identifier); $html = trim($html); if (empty($identifier) || empty($html)) { continue; } $DB->Update('INSERT INTO `tx_icons` VALUES (?,?,?)', array(null, $identifier, trim($html))); $icons[$identifier] = $DB->InsertID(); } // // Dump categories FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting categories...\n"); echo "Converting categories...\n"; flush(); $cat_format = array('Name', 'Type', 'Ext_Pictures', 'Ext_Movies', 'Min_Pictures', 'Min_Movies', 'Max_Pictures', 'Max_Movies', 'Size_Pictures', 'Size_Movies'); $categories = array(); $category_ids = array(); $DB->Update('DELETE FROM `tx_categories`'); $lines = file("{$_REQUEST['directory']}/data/dbs/categories"); foreach ($lines as $line) { $line = trim($line); if (empty($line)) { continue; } $category = explode('|', $line); foreach ($cat_format as $index => $key) { $category[$key] = $category[$index]; } $tag = CreateCategoryTag($category['Name']); $categories[$category['Name']] = $tag; $DB->Update('INSERT INTO `tx_categories` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $category['Name'], $tag, $category['Type'] != 'Movies' ? 1 : 0, $category['Ext_Pictures'], $category['Min_Pictures'], $category['Max_Pictures'], $category['Size_Pictures'], "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, null, $category['Type'] != 'Pictures' ? 1 : 0, $category['Ext_Movies'], $category['Min_Movies'], $category['Max_Movies'], $category['Size_Movies'], "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, null, -1, 0, null, null, null)); $category_ids[$category['Name']] = $DB->InsertID(); } // // Dump gallery data FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting gallery data...\n"); echo "Converting gallery data...\n"; flush(); $DB->Update('DELETE FROM `tx_galleries`'); $DB->Update('DELETE FROM `tx_gallery_fields`'); $DB->Update('DELETE FROM `tx_gallery_icons`'); $DB->Update('DELETE FROM `tx_gallery_previews`'); $DB->Update('ALTER TABLE `tx_galleries` AUTO_INCREMENT=0'); $DB->Update('ALTER TABLE `tx_gallery_previews` AUTO_INCREMENT=0'); $gal_format = array('Gallery_ID', 'Email', 'Gallery_URL', 'Description', 'Thumbnails', 'Category', 'Nickname', 'Submit_Date', 'Approve_Date', 'Display_Date', 'Display_Stamp', 'Confirm_ID', 'Account_ID', 'CPanel_ID', 'Submit_IP', 'Gallery_IP', 'Scanned', 'Links', 'Has_Recip', 'Page_Bytes', 'Icons'); $gal_dbs = array('unconfirmed' => 'unconfirmed', 'pending' => 'pending', 'approved' => 'used', 'archived' => 'used'); foreach (array_keys($categories) as $cat_name) { $gal_dbs[preg_replace('~[^a-z0-9]~i', '', strtolower($cat_name))] = 'used'; } foreach ($gal_dbs as $db => $status) { $db_file = "{$_REQUEST['directory']}/data/dbs/{$db}"; if (is_file($db_file)) { $lines = file($db_file); foreach ($lines as $line) { $line = trim($line); if (empty($line)) { continue; } $gallery = explode('|', $line); foreach ($gal_format as $index => $key) { $gallery[$key] = $gallery[$index]; } if (!preg_match('!^http(s)?://[\\w-]+\\.[\\w-]+(\\S+)?$!i', $gallery['Gallery_URL'])) { continue; } $has_thumb = is_file("{$vars['THUMB_DIR']}/{$gallery['Gallery_ID']}.jpg"); $DB->Update("INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", array(null, $gallery['Gallery_URL'], $gallery['Description'], null, $gallery['Thumbnails'], $gallery['Email'], $gallery['Nickname'], $C['gallery_weight'], 0, $gallery['Submit_IP'], $gallery['Gallery_IP'], null, 'submitted', FMT_PICTURES, $status, null, "{$gallery['Submit_Date']} 12:00:00", "{$gallery['Submit_Date']} 12:00:00", empty($gallery['Approve_Date']) ? null : "{$gallery['Approve_Date']} 12:00:00", null, empty($gallery['Display_Date']) ? null : "{$gallery['Display_Date']} 12:00:00", null, $gallery['Account_ID'], $gallery['CPanel_ID'], null, null, $gallery['Has_Recip'], $has_thumb ? 1 : 0, 1, 1, 0, 0, 0, null, MIXED_CATEGORY . " " . $categories[$gallery['Category']])); $gallery_id = $DB->InsertID(); $gallery_info = array('gallery_id' => $gallery_id); $insert = CreateUserInsert('tx_gallery_fields', $gallery_info); $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']); foreach (explode(',', $gallery['Icons']) as $icon_id) { if (isset($icons[$icon_id])) { $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($gallery_id, $icons[$icon_id])); } } if (!empty($has_thumb)) { $dimensions = $vars['THUMB_WIDTH'] . 'x' . $vars['THUMB_HEIGHT']; $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery_id, '', $dimensions)); $preview_id = $DB->InsertID(); $gallery['Thumbnail_URL'] = "{$C['preview_url']}/{$preview_id}.jpg"; $DB->Update('UPDATE `tx_gallery_previews` SET `preview_url`=? WHERE `preview_id`=?', array($gallery['Thumbnail_URL'], $preview_id)); @rename("{$C['preview_dir']}/t_{$gallery['Gallery_ID']}.jpg", "{$C['preview_dir']}/{$preview_id}.jpg"); } } } } // // Convert permanent gallery data $perm_format = array('Permanent_ID', 'Gallery_URL', 'Category', 'Thumbnails', 'Description', 'Nickname', 'Location', 'Thumbnail_URL', 'Start_Date', 'Expire_Date'); $lines = file("{$_REQUEST['directory']}/data/dbs/permanent"); foreach ($lines as $line) { $line = trim($line); if (empty($line)) { continue; } $gallery = explode('|', $line); foreach ($perm_format as $index => $key) { $gallery[$key] = $gallery[$index]; } if (!preg_match('!^http(s)?://[\\w-]+\\.[\\w-]+(\\S+)?$!i', $gallery['Gallery_URL'])) { continue; } $has_thumb = is_file("{$vars['THUMB_DIR']}/p{$gallery['Permanent_ID']}.jpg"); $DB->Update("INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", array(null, $gallery['Gallery_URL'], $gallery['Description'], null, $gallery['Thumbnails'], $C['from_email'], $gallery['Nickname'], $C['gallery_weight'], 0, $_SERVER['REMOTE_ADDR'], null, null, 'permanent', FMT_PICTURES, 'approved', null, MYSQL_NOW, MYSQL_NOW, MYSQL_NOW, null, null, null, null, 'AGP Import', null, null, 0, $has_thumb ? 1 : 0, 1, 1, 0, 0, 0, null, MIXED_CATEGORY . " " . $categories[$gallery['Category']])); $gallery_id = $DB->InsertID(); $gallery_info = array('gallery_id' => $gallery_id); $insert = CreateUserInsert('tx_gallery_fields', $gallery_info); $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']); foreach (explode(',', $gallery['Icons']) as $icon_id) { if (isset($icons[$icon_id])) { $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($gallery_id, $icons[$icon_id])); } } if (!empty($has_thumb)) { $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery_id, '', $vars['THUMB_WIDTH'] . 'x' . $vars['THUMB_HEIGHT'])); $preview_id = $DB->InsertID(); $gallery['Thumbnail_URL'] = "{$C['preview_url']}/{$preview_id}.jpg"; $DB->Update('UPDATE `tx_gallery_previews` SET `preview_url`=? WHERE `preview_id`=?', array($gallery['Thumbnail_URL'], $preview_id)); @rename("{$C['preview_dir']}/t_p{$gallery['Permanent_ID']}.jpg", "{$C['preview_dir']}/{$preview_id}.jpg"); } } // // Dump partner data FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting partner accounts...\n"); echo "Converting partner accounts...\n"; flush(); $DB->Update('DELETE FROM `tx_partners`'); $DB->Update('DELETE FROM `tx_partner_fields`'); $DB->Update('DELETE FROM `tx_partner_icons`'); $DB->Update('DELETE FROM `tx_partner_confirms`'); $acct_format = array('Account_ID', 'Password', 'Email', 'Allowed', 'Auto_Approve', 'Recip', 'Blacklist', 'HTML', 'Icons'); $lines = file("{$_REQUEST['directory']}/data/dbs/accounts"); foreach ($lines as $line) { $line = trim($line); if (empty($line)) { continue; } $partner = explode('|', $line); foreach ($acct_format as $index => $key) { $partner[$key] = $partner[$index]; } $DB->Update('INSERT INTO `tx_partners` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array($partner['Account_ID'], sha1($partner['Password']), '', $partner['Email'], null, MYSQL_NOW, null, null, null, $partner['Allowed'], $C['gallery_weight'], null, 0, null, 0, 0, 0, 'active', null, null, 0, $partner['Recip'] ? 0 : 1, $partner['Auto_Approve'], 1, $partner['Blacklist'] ? 0 : 1)); $partner_info = array('username' => $partner['Account_ID']); $insert = CreateUserInsert('tx_partner_fields', $partner_info); $DB->Update('INSERT INTO `tx_partner_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']); foreach (explode(',', $partner['Icons']) as $icon_id) { if (isset($icons[$icon_id])) { $DB->Update('INSERT INTO `tx_partner_icons` VALUES (?,?)', array($partner['Account_ID'], $icons[$icon_id])); } } } // Update the stored thumbnail preview sizes UpdateThumbSizes($vars['THUMB_WIDTH'] . 'x' . $vars['THUMB_HEIGHT']); // // Dump TGP page data FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting TGP pages...\n"); echo "Converting TGP pages...\n"; flush(); $build_order = 1; $DB->Update('DELETE FROM `tx_pages`'); $DB->Update('ALTER TABLE `tx_pages` AUTO_INCREMENT=0'); $pages = GetPageList($vars, $categories); foreach ($pages as $page) { $template = file_get_contents($page['template']); $template = trim(ConvertTemplate($template, $page['arch'])); $compiled = ''; $DB->Update('INSERT INTO `tx_pages` VALUES (?,?,?,?,?,?,?,?,?)', array(null, $page['file'], $page['url'], $page['category'] == 'Mixed' ? null : $category_ids[$page['category']], $build_order++, 0, null, $template, $compiled)); } FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "\nData conversion complete!"); echo "\nData conversion complete!\n"; if (!$from_shell) { echo "</pre>"; } }
function ConvertData() { global $C, $DB, $from_shell; $errors = array(); if (!is_dir($_REQUEST['directory'])) { $errors[] = "The directory " . htmlspecialchars($_REQUEST['directory']) . " does not exist on your server"; return DisplayMain($errors); } if (!is_file("{$_REQUEST['directory']}/ags.pl")) { $errors[] = "The ags.pl file could not be found in the " . htmlspecialchars($_REQUEST['directory']) . " directory"; return DisplayMain($errors); } if (!is_readable("{$_REQUEST['directory']}/ags.pl")) { $errors[] = "The ags.pl file in the " . htmlspecialchars($_REQUEST['directory']) . " directory could not be opened for reading"; return DisplayMain($errors); } // Check version $version_file_contents = file_get_contents("{$_REQUEST['directory']}/ags.pl"); if (preg_match('~\\$VERSION\\s+=\\s+\'(.*?)\'~', $version_file_contents, $matches)) { if ($matches[1] != '3.6.2-SS') { $errors[] = "Your AutoGallery SQL installation is outdated ({$matches[1]}); please upgrade to version 3.6.2-SS"; return DisplayMain($errors); } } else { $errors[] = "Unable to extract version information from ags.pl; your version of AutoGallery SQL is likely too old"; return DisplayMain($errors); } // Extract MySQL information $mysql_file_contents = file_get_contents("{$_REQUEST['directory']}/data/variables"); if ($mysql_file_contents === FALSE) { $errors[] = "Unable to read contents of the variables file"; return DisplayMain($errors); } $vars = array(); if (preg_match_all('~^\\$([a-z0-9_]+)\\s+=\\s+\'(.*?)\';$~msi', $mysql_file_contents, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $vars[$match[1]] = $match[2]; } } if (!isset($vars['USERNAME']) || !isset($vars['DATABASE']) || !isset($vars['HOSTNAME'])) { $errors[] = "Unable to extract MySQL database information from the variables file"; return DisplayMain($errors); } if (!is_writable("{$GLOBALS['BASE_DIR']}/annotations")) { $errors[] = "Change the permissions on the TGPX annotations directory to 777"; return DisplayMain($errors); } if (!is_writable($C['font_dir'])) { $errors[] = "Change the permissions on the TGPX fonts directory to 777"; return DisplayMain($errors); } if ($C['preview_dir'] == $vars['THUMB_DIR']) { $errors[] = "The TGPX Thumbnail URL cannot be the same as the AutoGallery SQL Thumbnail URL"; return DisplayMain($errors); } $CONVERTDB = new DB($vars['HOSTNAME'], $vars['USERNAME'], $vars['PASSWORD'], $vars['DATABASE']); $CONVERTDB->Connect(); $CONVERTDB->Update('SET wait_timeout=86400'); if (!$from_shell) { echo "<pre>"; } // Copy fonts for validation codes FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying font files for verification codes...\n"); echo "Copying font files for verification codes...\n"; flush(); $fonts =& DirRead($vars['FONT_DIR'], '^[^.]'); foreach ($fonts as $font) { @copy("{$vars['FONT_DIR']}/{$font}", "{$C['font_dir']}/{$font}"); } // Copy annotations FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying annotation font files and images...\n"); echo "Copying annotation font files and images...\n"; flush(); $annotations =& DirRead($vars['ANNOTATION_DIR'], '^[^.]'); foreach ($annotations as $annotation) { @copy("{$vars['ANNOTATION_DIR']}/{$annotation}", "{$GLOBALS['BASE_DIR']}/annotations/{$annotation}"); } // Copy thumbnail previews FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying thumbnail preview images...\n"); echo "Copying thumbnail preview images...\n"; flush(); $thumbs =& DirRead($vars['THUMB_DIR'], '\\.jpg$'); foreach ($thumbs as $thumb) { @copy("{$vars['THUMB_DIR']}/{$thumb}", "{$C['preview_dir']}/t_{$thumb}"); @chmod("{$C['preview_dir']}/t_{$thumb}", 0666); } // // Dump e-mail log FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting e-mail log...\n"); echo "Converting e-mail log...\n"; flush(); $emails = file("{$_REQUEST['directory']}/data/emails"); $DB->Update('DELETE FROM `tx_email_log`'); foreach ($emails as $email) { $email = trim($email); if (empty($email)) { continue; } $DB->Update('REPLACE INTO `tx_email_log` VALUES (?)', array($email)); } // // Dump blacklist FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting blacklist...\n"); echo "Converting blacklist...\n"; flush(); $DB->Update('DELETE FROM `tx_blacklist`'); $types = array('submit_ip' => 'submitip', 'email' => 'email', 'url' => 'domain', 'domain_ip' => 'domainip', 'word' => 'word', 'html' => 'html', 'headers' => 'headers', 'dns' => 'dns'); foreach ($types as $new_type => $old_type) { if (is_file("{$_REQUEST['directory']}/data/blacklist/{$old_type}")) { $blist_items = file("{$_REQUEST['directory']}/data/blacklist/{$old_type}"); foreach ($blist_items as $html) { $html = trim($html); if (empty($html)) { continue; } $regex = 0; if (strpos($html, '*') !== FALSE) { $regex = 1; $html = preg_quote($html); $html = str_replace('\\*', '.*?', $html); } $DB->Update('INSERT INTO `tx_blacklist` VALUES (?,?,?,?,?)', array(null, $new_type, $regex, $html, '')); } } } // // Dump whitelist FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting whitelist...\n"); echo "Converting whitelist...\n"; flush(); $DB->Update('DELETE FROM `tx_whitelist`'); $wlist_items = file("{$_REQUEST['directory']}/data/blacklist/whitelist"); foreach ($wlist_items as $html) { $html = trim($html); if (empty($html)) { continue; } $regex = 0; if (strpos($html, '*') !== FALSE) { $regex = 1; $html = preg_quote($html); $html = str_replace('\\*', '.*?', $html); } $DB->Update('INSERT INTO `tx_whitelist` VALUES (?,?,?,?,?,?,?,?,?,?)', array(null, 'url', $regex, $html, '', 1, 0, 0, 0, 0)); } // // Dump reciprocal links FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting reciprocal link settings...\n"); echo "Converting reciprocal link settings...\n"; flush(); $DB->Update('DELETE FROM `tx_reciprocals`'); IniParse("{$_REQUEST['directory']}/data/generalrecips", TRUE, $recips); IniParse("{$_REQUEST['directory']}/data/trustedrecips", TRUE, $recips); foreach ($recips as $identifier => $html) { $regex = 0; if (strpos($html, '*') !== FALSE) { $regex = 1; $html = preg_quote($html); $html = str_replace('\\*', '.*?', $html); } $DB->Update('INSERT INTO `tx_reciprocals` VALUES (?,?,?,?)', array(null, $identifier, $html, $regex)); } // // Dump 2257 code FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting 2257 search code...\n"); echo "Converting 2257 search code...\n"; flush(); $counter = 1; $c2257s = file("{$_REQUEST['directory']}/data/2257"); $DB->Update('DELETE FROM `tx_2257`'); foreach ($c2257s as $html) { $html = trim($html); if (empty($html)) { continue; } $regex = 0; if (strpos($html, '*') !== FALSE) { $regex = 1; $html = preg_quote($html); $html = str_replace('\\*', '.*?', $html); } $DB->Update('INSERT INTO `tx_2257` VALUES (?,?,?,?)', array(null, "AGS Converted #{$counter}", $html, $regex)); $counter++; } // // Dump icons FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting icons...\n"); echo "Converting icons...\n"; flush(); $icons = array(); $DB->Update('DELETE FROM `tx_icons`'); IniParse("{$_REQUEST['directory']}/data/icons", TRUE, $icons_ini); foreach ($icons_ini as $identifier => $html) { $identifier = trim($identifier); $html = trim($html); if (empty($identifier) || empty($html)) { continue; } $DB->Update('INSERT INTO `tx_icons` VALUES (?,?,?)', array(null, $identifier, $html)); $icons[$identifier] = $DB->InsertID(); } // // Dump annotations FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting annotation settings...\n"); echo "Converting annotation settings...\n"; flush(); $annotations = array(); $DB->Update('DELETE FROM `tx_annotations`'); $result = $CONVERTDB->Query('SELECT * FROM `ags_Annotations`'); while ($annotation = $CONVERTDB->NextRow($result)) { $DB->Update('INSERT INTO `tx_annotations` VALUES (?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $annotation['Identifier'], strtolower($annotation['Type']), $annotation['String'], 0, $annotation['Font_File'], $annotation['Size'], $annotation['Color'], $annotation['Shadow'], $annotation['Image_File'], $annotation['Transparency'], $annotation['Location'])); $annotations[$annotation['Unique_ID']] = $DB->InsertID(); } $CONVERTDB->Free($result); // // Dump categories FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting categories...\n"); echo "Converting categories...\n"; flush(); $categories = array(); $category_ids = array(); $DB->Update('DELETE FROM `tx_categories`'); $result = $CONVERTDB->Query('SELECT * FROM `ags_Categories`'); while ($category = $CONVERTDB->NextRow($result)) { $tag = CreateCategoryTag($category['Name']); $categories[$category['Name']] = $tag; $DB->Update('INSERT INTO `tx_categories` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $category['Name'], $tag, empty($category['Ext_Pictures']) ? 0 : 1, $category['Ext_Pictures'], $category['Min_Pictures'], $category['Max_Pictures'], $category['Size_Pictures'], "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, $annotations[$category['Ann_Pictures']], empty($category['Ext_Movies']) ? 0 : 1, $category['Ext_Movies'], $category['Min_Movies'], $category['Max_Movies'], $category['Size_Movies'], "{$vars['THUMB_WIDTH']}x{$vars['THUMB_HEIGHT']}", 1, $annotations[$category['Ann_Movies']], $category['Per_Day'], $category['Hidden'], null, null, null)); $category_ids[$category['Name']] = $DB->InsertID(); } $CONVERTDB->Free($result); // // Dump sponsors FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting sponsors...\n"); echo "Converting sponsors...\n"; flush(); $counter = 1; $sponsors = array(); $DB->Update('DELETE FROM `tx_sponsors`'); $result = $CONVERTDB->Query('SELECT DISTINCT `Sponsor` FROM `ags_Galleries` WHERE `Sponsor`!=?', array('')); while ($sponsor = $CONVERTDB->NextRow($result)) { $sponsors[$sponsor['Sponsor']] = $counter; $DB->Update("INSERT INTO `tx_sponsors` VALUES (?,?,?)", array($counter++, $sponsor['Sponsor'], null)); } $CONVERTDB->Free($result); // // Dump gallery data FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting gallery data...\n"); echo "Converting gallery data...\n"; flush(); $DB->Update('DELETE FROM `tx_galleries`'); $DB->Update('DELETE FROM `tx_gallery_fields`'); $DB->Update('DELETE FROM `tx_gallery_icons`'); $DB->Update('DELETE FROM `tx_gallery_previews`'); $DB->Update('ALTER TABLE `tx_galleries` AUTO_INCREMENT=0'); $DB->Update('ALTER TABLE `tx_gallery_previews` AUTO_INCREMENT=0'); $result = $CONVERTDB->Query('SELECT * FROM `ags_Galleries` ORDER BY `Gallery_ID`'); $preview_sizes = array(); while ($gallery = $CONVERTDB->NextRow($result)) { $DB->Update("INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", array(null, $gallery['Gallery_URL'], $gallery['Description'], $gallery['Keywords'], $gallery['Thumbnails'], $gallery['Email'], $gallery['Nickname'], $gallery['Weight'], $gallery['Clicks'], $gallery['Submit_IP'], $gallery['Gallery_IP'], !empty($gallery['Sponsor']) ? $sponsors[$gallery['Sponsor']] : null, strtolower($gallery['Type']), strtolower($gallery['Format']), strtolower($gallery['Status']), $gallery['Status'] == 'Disabled' ? 'approved' : null, date(DF_DATETIME, TimeWithTz($gallery['Added_Stamp'])), date(DF_DATETIME, TimeWithTz($gallery['Added_Stamp'])), empty($gallery['Approve_Stamp']) ? null : date(DF_DATETIME, TimeWithTz($gallery['Approve_Stamp'])), empty($gallery['Scheduled_Date']) ? null : "{$gallery['Scheduled_Date']} 00:00:00", empty($gallery['Display_Date']) ? null : "{$gallery['Display_Date']} 12:00:00", empty($gallery['Delete_Date']) ? null : "{$gallery['Delete_Date']} 00:00:00", $gallery['Account_ID'], $gallery['Moderator'], $gallery['Comments'], null, $gallery['Has_Recip'], empty($gallery['Thumbnail_URL']) ? 0 : 1, $gallery['Allow_Scan'], $gallery['Allow_Thumb'], $gallery['Times_Selected'], $gallery['Used_Counter'], $gallery['Build_Counter'], null, MIXED_CATEGORY . " " . $categories[$gallery['Category']])); $gallery_id = $DB->InsertID(); $gallery_info = array('gallery_id' => $gallery_id); $insert = CreateUserInsert('tx_gallery_fields', $gallery_info); $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']); foreach (explode(',', $gallery['Icons']) as $icon_id) { if (isset($icons[$icon_id])) { $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($gallery_id, $icons[$icon_id])); } } if (!empty($gallery['Thumbnail_URL'])) { $dimensions = ''; if (!empty($gallery['Thumb_Width']) && !empty($gallery['Thumb_Height'])) { $dimensions = "{$gallery['Thumb_Width']}x{$gallery['Thumb_Height']}"; $preview_sizes[$dimensions] = TRUE; } $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery_id, '', $dimensions)); $preview_id = $DB->InsertID(); if (preg_match('~^' . preg_quote($vars['THUMB_URL']) . '~i', $gallery['Thumbnail_URL'])) { $gallery['Thumbnail_URL'] = "{$C['preview_url']}/{$preview_id}.jpg"; $DB->Update('UPDATE `tx_gallery_previews` SET `preview_url`=? WHERE `preview_id`=?', array($gallery['Thumbnail_URL'], $preview_id)); @rename("{$C['preview_dir']}/t_{$gallery['Gallery_ID']}.jpg", "{$C['preview_dir']}/{$preview_id}.jpg"); } } } $CONVERTDB->Free($result); // // Dump partner data FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting partner accounts...\n"); echo "Converting partner accounts...\n"; flush(); $DB->Update('DELETE FROM `tx_partners`'); $DB->Update('DELETE FROM `tx_partner_fields`'); $DB->Update('DELETE FROM `tx_partner_icons`'); $DB->Update('DELETE FROM `tx_partner_confirms`'); $result = $CONVERTDB->Query('SELECT * FROM `ags_Accounts`'); while ($partner = $CONVERTDB->NextRow($result)) { $DB->Update('INSERT INTO `tx_partners` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array($partner['Account_ID'], sha1($partner['Password']), '', $partner['Email'], null, MYSQL_NOW, $partner['Submitted'] > 0 ? MYSQL_NOW : null, empty($partner['Start_Date']) ? null : "{$partner['Start_Date']} 00:00:00", empty($partner['End_Date']) ? null : "{$partner['End_Date']} 23:59:59", $partner['Allowed'], round($partner['Weight']), null, 0, null, 0, $partner['Submitted'], $partner['Removed'], 'active', null, null, 0, $partner['Check_Recip'] ? 0 : 1, $partner['Auto_Approve'], $partner['Confirm'] ? 0 : 1, $partner['Check_Black'] ? 0 : 1)); $partner_info = array('username' => $partner['Account_ID']); $insert = CreateUserInsert('tx_partner_fields', $partner_info); $DB->Update('INSERT INTO `tx_partner_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']); foreach (explode(',', $partner['Icons']) as $icon_id) { if (isset($icons[$icon_id])) { $DB->Update('INSERT INTO `tx_partner_icons` VALUES (?,?)', array($partner['Account_ID'], $icons[$icon_id])); } } } $CONVERTDB->Free($result); // Update the stored thumbnail preview sizes $sizes = unserialize(GetValue('preview_sizes')); if (!is_array($sizes)) { $sizes = array(); } $sizes = array_merge($sizes, array_keys($preview_sizes)); StoreValue('preview_sizes', serialize(array_unique($sizes))); // // Dump TGP page data FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting TGP pages...\n"); echo "Converting TGP pages...\n"; flush(); $build_order = 1; $docroot_url = parse_url($vars['CGI_URL']); $DB->Update('DELETE FROM `tx_pages`'); $DB->Update('ALTER TABLE `tx_pages` AUTO_INCREMENT=0'); $result = $CONVERTDB->Query('SELECT * FROM `ags_Pages` ORDER BY `Build_Order`'); while ($page = $CONVERTDB->NextRow($result)) { $template = file_get_contents("{$_REQUEST['directory']}/data/html/{$page['Page_ID']}"); $template = ConvertTemplate($template); $compiled = ''; $DB->Update('INSERT INTO `tx_pages` VALUES (?,?,?,?,?,?,?,?,?)', array(null, "{$vars['DOCUMENT_ROOT']}/{$page['Filename']}", "http://{$docroot_url['host']}/{$page['Filename']}", $page['Category'] == 'Mixed' ? null : $category_ids[$page['Category']], $build_order++, 0, null, $template, $compiled)); } $CONVERTDB->Free($result); FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "\nData conversion complete!"); echo "\nData conversion complete!\n"; if (!$from_shell) { echo "</pre>"; } }
function ConvertData() { global $C, $DB, $from_shell; $errors = array(); if (!is_dir($_REQUEST['directory'])) { $errors[] = "The directory " . htmlspecialchars($_REQUEST['directory']) . " does not exist on your server"; return DisplayMain($errors); } if (!is_file("{$_REQUEST['directory']}/arphp.php")) { $errors[] = "The arphp.php file could not be found in the " . htmlspecialchars($_REQUEST['directory']) . " directory"; return DisplayMain($errors); } if (!is_readable("{$_REQUEST['directory']}/arphp.php")) { $errors[] = "The arphp.php file in the " . htmlspecialchars($_REQUEST['directory']) . " directory could not be opened for reading"; return DisplayMain($errors); } // Check version $version_file_contents = file_get_contents("{$_REQUEST['directory']}/common.php"); if (preg_match('~\\$VERSION\\s+=\\s+\'(.*?)\'~', $version_file_contents, $matches)) { list($a, $b, $c) = explode('.', $matches[1]); if ($a < 3) { $errors[] = "Your AutoRank PHP installation is outdated; please upgrade to the 3.0.x series"; return DisplayMain($errors); } } else { $errors[] = "Unable to extract version information from arphp.php; your version of AutoRank PHP is likely too old"; return DisplayMain($errors); } // Extract variables $mysql_file_contents = file_get_contents("{$_REQUEST['directory']}/data/variables"); if ($mysql_file_contents === FALSE) { $errors[] = "Unable to read contents of the variables file"; return DisplayMain($errors); } $vars = array(); if (preg_match_all('~^\\$([a-z0-9_]+)\\s+=\\s+\'(.*?)\';$~msi', $mysql_file_contents, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $vars[$match[1]] = $match[2]; } } if (!isset($vars['USERNAME']) || !isset($vars['DATABASE']) || !isset($vars['HOSTNAME'])) { $errors[] = "Unable to extract MySQL database information from the variables file"; return DisplayMain($errors); } $CONVERTDB = new DB($vars['HOSTNAME'], $vars['USERNAME'], $vars['PASSWORD'], $vars['DATABASE']); $CONVERTDB->Connect(); $CONVERTDB->Update('SET `wait_timeout`=86400'); if (!$from_shell) { echo "<pre>"; } // // Copy banners FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Copying member account banners...\n"); echo "Copying member account banners...\n"; flush(); $banners =& DirRead($vars['BANNER_DIR'], '\\.(png|jpg|gif|bmp)$'); foreach ($banners as $banner) { @copy("{$vars['BANNER_DIR']}/{$banner}", "{$C['banner_dir']}/{$banner}"); @chmod("{$C['banner_dir']}/{$banner}", 0666); } // // Dump categories FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting categories...\n"); echo "Converting categories...\n"; flush(); $categories = array(); $category_ids = array(); $DB->Update('DELETE FROM `tlx_categories`'); $DB->Update('ALTER TABLE `tlx_categories` AUTO_INCREMENT=0'); foreach (explode(',', $vars['CATEGORIES']) as $category) { $DB->Update('INSERT INTO `tlx_categories` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $category, 0, $vars['FORWARD_URL'], null, $vars['BANNER_WIDTH'], $vars['BANNER_HEIGHT'], $vars['BANNER_SIZE'], intval($vars['O_FORCE_DIMS']), intval($vars['O_CHECK_DIMS']), intval($vars['O_SERVE_BANNERS']), 1, 1, $vars['MAX_TITLE'], 1, $vars['MAX_DESC'], intval($vars['O_REQ_RECIP']))); $category_ids[$category] = $DB->InsertID(); } // // Import icons FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting account icons...\n"); echo "Converting account icons...\n"; flush(); $DB->Update('DELETE FROM `tlx_icons`'); $DB->Update('ALTER TABLE `tlx_icons` AUTO_INCREMENT=0'); IniParse("{$_REQUEST['directory']}/data/icons", TRUE, $icons_ini); $icons = array(); foreach ($icons_ini as $key => $value) { $DB->Update('INSERT INTO `tlx_icons` VALUES (?,?,?)', array(null, $key, trim($value))); $icons[$key] = $DB->InsertID(); } // // Import user defined fields FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting user defined database fields...\n"); echo "Converting user defined database fields...\n"; flush(); $DB->Update('DELETE FROM `tlx_account_field_defs`'); $DB->Update('ALTER TABLE `tlx_account_field_defs` AUTO_INCREMENT=0'); $DB->Update('DROP TABLE IF EXISTS `tlx_account_fields`'); $DB->Update('CREATE TABLE `tlx_account_fields` (`username` CHAR(32) NOT NULL PRIMARY KEY)'); for ($i = 1; $i <= 3; $i++) { if (!IsEmptyString($vars["NAME_FIELD_{$i}"])) { $DB->Update('INSERT INTO `tlx_account_field_defs` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, "user_field_{$i}", $vars["NAME_FIELD_{$i}"], FT_TEXT, null, null, 0, null, null, 1, intval($vars["O_REQ_FIELD_{$i}"]), 1, intval($vars["O_REQ_FIELD_{$i}"]))); $DB->Update("ALTER TABLE `tlx_account_fields` ADD COLUMN # TEXT", array("user_field_{$i}")); } } // // Dump account data FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting account data...\n"); echo "Converting account data...\n"; flush(); $DB->Update('DELETE FROM `tlx_accounts`'); $DB->Update('DELETE FROM `tlx_account_hourly_stats`'); $DB->Update('DELETE FROM `tlx_account_daily_stats`'); $DB->Update('DELETE FROM `tlx_account_country_stats`'); $DB->Update('DELETE FROM `tlx_account_referrer_stats`'); $DB->Update('DELETE FROM `tlx_account_icons`'); $DB->Update('DELETE FROM `tlx_account_comments`'); $DB->Update('DELETE FROM `tlx_account_ranks`'); $result = $CONVERTDB->Query('SELECT * FROM `arphp_Accounts`'); while ($account = $CONVERTDB->NextRow($result)) { $parsed_url = parse_url($account['Site_URL']); $account['Domain'] = preg_replace('~^www\\.~i', '', $parsed_url['host']); $account['Banner_URL'] = str_replace($vars['BANNER_URL'], $C['banner_url'], $account['Banner_URL']); $DB->Update('INSERT INTO `tlx_accounts` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array($account['Username'], $account['Email'], $account['Site_URL'], $account['Domain'], $account['Banner_URL'], $account['Banner_URL'], $account['Banner_Height'], $account['Banner_Width'], $account['Title'], $account['Description'], null, date(DF_DATETIME, $account['Signup']), date(DF_DATETIME, $account['Signup']), null, sha1($account['Password']), $C['return_percent'], STATUS_ACTIVE, intval($account['Locked']), intval($account['Suspended']), 0, $category_ids[$account['Category']], 0, 0, $account['Num_Ratings'], $account['Rating_Total'], $account['Inactive'], null, $account['Comments'])); $stats = array_merge(array($account['Username']), array_fill(0, 127, 0)); $DB->Update('INSERT INTO `tlx_account_hourly_stats` VALUES (' . CreateBindList($stats) . ')', $stats); $account_info = array('username' => $account['Username'], 'user_field_1' => $account['Field_1'], 'user_field_2' => $account['Field_2'], 'user_field_3' => $account['Field_3']); $insert = CreateUserInsert('tlx_account_fields', $account_info); $DB->Update('INSERT INTO `tlx_account_fields` VALUES (' . $insert['bind_list'] . ')', $insert['binds']); foreach (explode(',', $account['Icons']) as $icon_id) { if (isset($icons[$icon_id])) { $DB->Update('INSERT INTO `tlx_account_icons` VALUES (?,?)', array($account['Username'], $icons[$icon_id])); } } } $CONVERTDB->Free($result); // // Dump account comments FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting account comments...\n"); echo "Converting account comments...\n"; flush(); $DB->Update('DELETE FROM `tlx_account_comments`'); $result = $CONVERTDB->Query('SELECT * FROM `arphp_Comments`'); while ($comment = $CONVERTDB->NextRow($result)) { $DB->Update('INSERT INTO `tlx_account_comments` VALUES (?,?,?,?,?,?,?,?)', array(null, $comment['Username'], date(DF_DATETIME, $comment['Timestamp']), $comment['IP'], $comment['Name'], $comment['Email'], strtolower($comment['Status']), $comment['Comment'])); } $CONVERTDB->Free($result); // // Dump ranking page data FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "Converting ranking pages...\n"); echo "Converting ranking pages...\n"; flush(); $build_order = 1; $DB->Update('DELETE FROM `tlx_pages`'); $DB->Update('ALTER TABLE `tlx_pages` AUTO_INCREMENT=0'); $result = $CONVERTDB->Query('SELECT * FROM `arphp_Pages`'); while ($page = $CONVERTDB->NextRow($result)) { $template = file_get_contents("{$_REQUEST['directory']}/data/pages/{$page['Identifier']}"); $template = ConvertTemplate($template); $compiled = ''; $DB->Update('INSERT INTO `tlx_pages` VALUES (?,?,?,?,?,?,?)', array(null, "tlx_pages/{$page['Identifier']}.html", $page['category'] == 'Mixed' ? null : $category_ids[$page['category']], $build_order++, null, $template, $compiled)); } $CONVERTDB->Free($result); FileAppend("{$GLOBALS['BASE_DIR']}/data/convert.log", "\nData conversion complete!"); echo "\nData conversion complete!\n"; if (!$from_shell) { echo "</pre>"; } $CONVERTDB->Disconnect(); }