function Error($code, $string, $file, $line) { global $C, $DB; $reporting = error_reporting(); if ($reporting == 0 || !($code & $reporting)) { return; } $sapi = php_sapi_name(); if ($sapi != 'cli') { require_once "{$GLOBALS['BASE_DIR']}/includes/template.class.php"; $t = new Template(); } $file = basename($file); // Generate stack trace $backtrace = debug_backtrace(); for ($i = 1; $i < count($backtrace); $i++) { $tracefile = $backtrace[$i]; if (!$tracefile['line']) { continue; } $trace .= "{$tracefile['function']} in " . basename($tracefile['file']) . " on line {$tracefile['line']}<br />"; } if ($sapi != 'cli') { $t->assign('trace', $trace); $t->assign('error', $string); $t->assign('file', $file); $t->assign('line', $line); $t->assign_by_ref('config', $C); if (defined('TGPX')) { $t->assign('levelup', '../'); } $t->display('error-fatal.tpl'); } else { echo "Error on line {$line} of file {$file}\n" . "{$string}\n" . "Stack Trace:\n{$trace}\n"; } $error = "Error on line {$line} of file {$file}\n" . strip_tags(str_replace('<br />', "\n", $string)) . "\n\n" . "Stack Trace:\n" . str_replace('<br />', "\n", $trace) . "\n"; if (@get_class($DB) == 'DB' && isset($GLOBALS['build_history_id'])) { $DB->Update('UPDATE `tx_build_history` SET `error_message`=? WHERE `history_id`=?', array($error, $GLOBALS['build_history_id'])); } if ($GLOBALS['ERROR_LOG']) { FileAppend("{$GLOBALS['BASE_DIR']}/data/error_log", "[" . date('r') . "] {$error}\n"); } exit; }
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>"; } }
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']}/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']}/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(); }
function txGalleryImport() { global $DB, $C; VerifyPrivileges(P_GALLERY_ADD); $defaults = array('gallery_url' => null, 'description' => null, 'keywords' => null, 'thumbnails' => 0, 'email' => $C['from_email'], 'nickname' => null, 'weight' => $C['gallery_weight'], 'clicks' => 0, 'submit_ip' => $_SERVER['REMOTE_ADDR'], 'gallery_ip' => '', 'sponsor_id' => !empty($_REQUEST['sponsor']) ? $_REQUEST['sponsor'] : null, 'type' => $_REQUEST['type'], 'format' => $_REQUEST['format'], 'status' => $_REQUEST['status'], 'previous_status' => null, 'date_scanned' => null, 'date_added' => MYSQL_NOW, 'date_approved' => null, 'date_scheduled' => null, 'date_displayed' => null, 'date_deletion' => null, 'partner' => null, 'administrator' => $_SERVER['REMOTE_USER'], 'admin_comments' => null, 'page_hash' => null, 'has_recip' => 0, 'has_preview' => 0, 'allow_scan' => 1, 'allow_preview' => 1, 'times_selected' => 0, 'used_counter' => 0, 'build_counter' => 0, 'tags' => null, 'categories' => null, 'preview_url' => null, 'dimensions' => null); $v = new Validator(); if (empty($_REQUEST['type']) && !in_array('type', $_REQUEST['fields'])) { $v->SetError('You indicated that the gallery type should come from the import data, but that field has not been defined'); } if (empty($_REQUEST['format']) && !in_array('format', $_REQUEST['fields'])) { $v->SetError('You indicated that the gallery format should come from the import data, but that field has not been defined'); } // Make sure only one of each field is submitted $field_counts = array_count_values($_REQUEST['fields']); foreach ($field_counts as $field_name => $field_count) { if ($field_name != 'IGNORE' && $field_count > 1) { $v->SetError("The {$field_name} field has been specified more than once"); } } if (!$v->Validate()) { return $v->ValidationError('txShGalleryImportAnalyze'); } // Create/empty log files for skipped galleries FileWrite("{$GLOBALS['BASE_DIR']}/data/skipped-cat.txt", ''); FileWrite("{$GLOBALS['BASE_DIR']}/data/skipped-dupe.txt", ''); // Initialize variables $imported = 0; $duplicates = 0; $no_matching_cat = 0; $lines = file(SafeFilename("{$GLOBALS['BASE_DIR']}/data/{$_REQUEST['filename']}")); $sponsors =& $DB->FetchAll('SELECT * FROM `tx_sponsors`', null, 'name'); $partners = array(); $columns = $DB->GetColumns('tx_gallery_fields'); foreach ($lines as $line_number => $line) { $line_number++; $line = trim($line); if (IsEmptyString($line)) { continue; } $data = explode('|', $line); $gallery = array(); foreach ($_REQUEST['fields'] as $index => $field) { $gallery[$field] = trim($data[$index]); } $gallery = array_merge($defaults, $gallery); // Check for and handle duplicates $dupes =& $DB->FetchAll('SELECT `gallery_id` FROM `tx_galleries` WHERE `gallery_url`=?', array($gallery['gallery_url'])); if (count($dupes) > 0) { switch ($_REQUEST['duplicates']) { case 'replace': // Remove existing so it can be replaced with new foreach ($dupes as $dupe) { DeleteGallery($dupe['gallery_id']); } break; case 'allow': // Allow duplicate galleries, so do nothing here break; default: // Go to next line if this is a duplicate FileAppend("{$GLOBALS['BASE_DIR']}/data/skipped-dupe.txt", sprintf("%-6d %s", $line_number, $line)); $duplicates++; continue 2; break; } } // Check for valid categories $skipped = array(); $category_tags = CategoryTagsFromList($gallery['categories'], $skipped); if ($category_tags == MIXED_CATEGORY) { switch ($_REQUEST['bad_category']) { case 'create': if (IsEmptyString($gallery['categories'])) { FileAppend("{$GLOBALS['BASE_DIR']}/data/skipped-cat.txt", sprintf("%-6d %s", $line_number, $line)); $no_matching_cat++; continue 2; } $category_tags = CreateCategories($gallery['categories']); break; case 'force': $category_tags = MIXED_CATEGORY . " " . $_REQUEST['forced_category']; break; default: FileAppend("{$GLOBALS['BASE_DIR']}/data/skipped-cat.txt", sprintf("%-6d %s", $line_number, $line)); $no_matching_cat++; continue 2; break; } } if (count($skipped) && $_REQUEST['bad_category'] == 'create') { $category_tags = join(' ', array_unique(array($category_tags, CreateCategories($gallery['categories'])))); } // Setup the sponsor if (empty($_REQUEST['sponsor']) && $_REQUEST['add_sponsor'] && $gallery['sponsor_id'] != null && !isset($sponsors[$gallery['sponsor_id']])) { $DB->Update('INSERT INTO `tx_sponsors` VALUES (?,?,?)', array(null, $gallery['sponsor_id'], null)); $sponsors[$gallery['sponsor_id']]['sponsor_id'] = $DB->InsertID(); $gallery['sponsor_id'] = $sponsors[$gallery['sponsor_id']]['sponsor_id']; } else { if (empty($_REQUEST['sponsor']) && $gallery['sponsor_id'] != null && isset($sponsors[$gallery['sponsor_id']])) { $gallery['sponsor_id'] = $sponsors[$gallery['sponsor_id']]['sponsor_id']; } } // Check for valid format $gallery['format'] = strtolower($gallery['format']); if (!in_array($gallery['format'], array('pictures', 'movies'))) { $gallery['format'] = 'pictures'; } // Check for valid type $gallery['type'] = strtolower($gallery['type']); if (!in_array($gallery['type'], array('submitted', 'permanent'))) { $gallery['type'] = 'submitted'; } // Check date scheduled for errors if ($gallery['date_scheduled'] != null && !preg_match(RE_DATETIME, $gallery['date_scheduled'])) { $gallery['date_scheduled'] = null; } // Check date of deletion for errors if ($gallery['date_deletion'] != null && !preg_match(RE_DATETIME, $gallery['date_deletion'])) { $gallery['date_deletion'] = null; } // Has a preview thumbnail if (!empty($gallery['preview_url'])) { $gallery['has_preview'] = 1; } // Add regular fields $DB->Update('INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $gallery['gallery_url'], $gallery['description'], FormatSpaceSeparated($gallery['keywords']), $gallery['thumbnails'], $gallery['email'], $gallery['nickname'], $gallery['weight'], $gallery['clicks'], $gallery['submit_ip'], $gallery['gallery_ip'], $gallery['sponsor_id'], $gallery['type'], $gallery['format'], $gallery['status'], $gallery['previous_status'], $gallery['date_scanned'], $gallery['date_added'], $gallery['date_approved'], $gallery['date_scheduled'], $gallery['date_displayed'], $gallery['date_deletion'], $gallery['partner'], $gallery['administrator'], $gallery['admin_comments'], $gallery['page_hash'], $gallery['has_recip'], $gallery['has_preview'], $gallery['allow_scan'], $gallery['allow_preview'], $gallery['times_selected'], $gallery['used_counter'], $gallery['build_counter'], FormatSpaceSeparated($gallery['tags']), $category_tags)); $gallery['gallery_id'] = $DB->InsertID(); // Add user defined fields $query_data = CreateUserInsert('tx_gallery_fields', $gallery, $columns); $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']); // Has a preview thumbnail if (!empty($gallery['preview_url'])) { $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery['gallery_id'], $gallery['preview_url'], $gallery['dimensions'])); } // Add icons if (!IsEmptyString($gallery['icons'])) { foreach (explode(',', $gallery['icons']) as $icon) { $icon = trim($icon); if (!empty($icon)) { $icon_id = $DB->Count('SELECT `icon_id` FROM `tx_icons` WHERE `identifier`=?', array($icon)); if ($icon_id) { $DB->Update('INSERT INTO `tx_gallery_icons` VALUES (?,?)', array($gallery['gallery_id'], $icon_id)); } } } } if (!empty($gallery['partner'])) { $partners[$gallery['partner']]++; // Add partner icons $partner_icons =& $DB->FetchAll('SELECT * FROM `tx_partner_icons` WHERE `username`=?', array($gallery['partner'])); foreach ($partner_icons as $icon) { $DB->Update('REPLACE INTO `tx_gallery_icons` VALUES (?,?)', array($gallery['gallery_id'], $icon['icon_id'])); } } $imported++; } StoreValue('last_import', serialize($_REQUEST['fields'])); // Update partner submit counts foreach ($partners as $username => $amount) { $DB->Update('UPDATE `tx_partners` SET `submitted`=`submitted`+? WHERE `username`=?', array($amount, $username)); } $GLOBALS['message'] = "A total of {$imported} galleries have been imported<br />" . "<a href=\"index.php?r=txShSkippedImport&type=dupe\" class=\"window {title: 'Skipped Galleries'}\">{$duplicates} galleries</a> were skipped because they were duplicates<br />" . "<a href=\"index.php?r=txShSkippedImport&type=cat\" class=\"window {title: 'Skipped Galleries'}\">{$no_matching_cat} galleries</a> were skipped because they did not fit into an existing category"; txShGalleryImport(); }