if (!isset($tables['tlx_account_category_ranks'])) { $DB->Update("CREATE TABLE IF NOT EXISTS `tlx_account_category_ranks` ( {$table_defs['tlx_account_category_ranks']} ) TYPE=MyISAM"); } // Update the tlx_categories table $columns = $DB->GetColumns('tlx_categories', TRUE); if (!isset($columns['page_url'])) { $DB->Update('ALTER TABLE `tlx_categories` ADD COLUMN `page_url` TEXT AFTER `forward_url`'); } // Update the tlx_daily_stats table $columns = $DB->GetColumns('tlx_daily_stats', TRUE); if (!isset($columns['clicks'])) { $DB->Update('ALTER TABLE `tlx_daily_stats` ADD COLUMN `clicks` INT UNSIGNED NOT NULL'); } // Update the tlx_ip_log_ratings table $columns = $DB->GetColumns('tlx_ip_log_ratings', TRUE); if (!isset($columns['last_rating'])) { $DB->Update('DROP TABLE `tlx_ip_log_ratings`'); $DB->Update("CREATE TABLE IF NOT EXISTS `tlx_ip_log_ratings` ( {$table_defs['tlx_ip_log_ratings']} ) TYPE=MyISAM"); } // Update the tlx_accounts table $columns = $DB->GetColumns('tlx_accounts', TRUE); if (!isset($columns['last_rank'])) { $DB->Update('ALTER TABLE `tlx_accounts` ADD COLUMN `last_rank` INT AFTER `category_id`'); $DB->Update('ALTER TABLE `tlx_accounts` ADD COLUMN `last_category_rank` INT AFTER `last_rank`'); } // Insert values into tlx_skim_ratio if they don't already exist if ($DB->Count('SELECT COUNT(*) FROM `tlx_skim_ratio`') < 1) { $DB->Update('INSERT INTO `tlx_skim_ratio` VALUES (0,0)'); } $DB->Disconnect(); echo "Patching has been completed successfully";
function CreateTables() { global $t; $DB = new DB($_REQUEST['db_hostname'], $_REQUEST['db_username'], $_REQUEST['db_password'], $_REQUEST['db_name']); $DB->Connect(); $tables = array(); IniParse("{$GLOBALS['BASE_DIR']}/includes/tables.php", TRUE, $tables); foreach ($tables as $name => $create) { $DB->Update("CREATE TABLE IF NOT EXISTS {$name} ( {$create} ) TYPE=MyISAM"); } $password = RandomPassword(); $domain = preg_replace('~^www\\.~', '', $_SERVER['HTTP_HOST']); $t->assign('password', $password); $DB->Update('DELETE FROM lx_administrators WHERE username=?', array('administrator')); $DB->Update('INSERT INTO lx_administrators VALUES (?,?,?,?,?,?,?,?,?,?)', array('administrator', sha1($password), '', 0, 'Administrator', "webmaster@{$domain}", 'administrator', '', 0, 0)); $DB->Disconnect(); }
function CreateTables() { global $t, $DB; $DB = new DB($_REQUEST['db_hostname'], $_REQUEST['db_username'], $_REQUEST['db_password'], $_REQUEST['db_name']); $DB->Connect(); $tables = array(); IniParse("{$GLOBALS['BASE_DIR']}/includes/tables.php", TRUE, $tables); foreach ($tables as $name => $create) { $DB->Update("CREATE TABLE IF NOT EXISTS {$name} ( {$create} ) TYPE=MyISAM"); } $password = RandomPassword(); $domain = preg_replace('~^www\\.~', '', $_SERVER['HTTP_HOST']); $t->assign('password', $password); // Setup default user defined partner account fields $columns = $DB->GetColumns('tx_partner_fields'); if (in_array('sample_url_1', $columns) && $DB->Count('SELECT COUNT(*) FROM `tx_partner_field_defs` WHERE `name`=?', array('sample_url_1')) < 1) { $DB->Update("INSERT INTO `tx_partner_field_defs` VALUES (NULL,'sample_url_1','Sample URL 1','Text','size=\"80\"','',2,'','Sample URL 1 is not properly formatted',1,1,1,0,0)"); } if (in_array('sample_url_2', $columns) && $DB->Count('SELECT COUNT(*) FROM `tx_partner_field_defs` WHERE `name`=?', array('sample_url_2')) < 1) { $DB->Update("INSERT INTO `tx_partner_field_defs` VALUES (NULL,'sample_url_2','Sample URL 2','Text','size=\"80\"','',2,'','Sample URL 2 is not properly formatted',1,1,1,0,0)"); } if (in_array('sample_url_3', $columns) && $DB->Count('SELECT COUNT(*) FROM `tx_partner_field_defs` WHERE `name`=?', array('sample_url_3')) < 1) { $DB->Update("INSERT INTO `tx_partner_field_defs` VALUES (NULL,'sample_url_3','Sample URL 3','Text','size=\"80\"','',0,'','Sample URL 3 is not properly formatted',1,1,1,0,0)"); } // Setup default category and initial thumbnail preview dimensions $dimensions = array('180x150', '120x150'); $category = array('per_day' => '-1', 'pics_allowed' => 1, 'pics_extensions' => 'jpg,jpeg,bmp,png', 'pics_minimum' => 10, 'pics_maximum' => 30, 'pics_file_size' => 12288, 'pics_preview_allowed' => 1, 'pics_preview_size' => $dimensions[1], 'movies_allowed' => 1, 'movies_extensions' => 'avi,mpg,mpeg,rm,wmv,mov,asf', 'movies_minimum' => 5, 'movies_maximum' => 30, 'movies_file_size' => 102400, 'movies_preview_allowed' => 1, 'movies_preview_size' => $dimensions[0]); StoreValue('default_category', serialize($category)); Storevalue('preview_sizes', serialize($dimensions)); // Setup administrator account $DB->Update('DELETE FROM `tx_administrators` WHERE `username`=?', array('administrator')); $DB->Update('INSERT INTO `tx_administrators` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array('administrator', sha1($password), '', 0, 'Administrator', "webmaster@{$domain}", 'administrator', null, null, null, null, 0, 0, 0, 0, 0, null, null)); $DB->Disconnect(); }
<?php require_once '../app/config.php'; require_once '../app/database.php'; require_once '../app/router.php'; DB::connect(); Router::add('get', '/', function ($data) { include '../view/index.html'; }); Router::add('get', '/note', function ($data) { echo DB::find('note', [], $data->page, $data->size)->json; }, [['page', 1], ['size', 20]], true); Router::add('post', '/note', function ($data) { echo DB::insert('note', ['time' => time(), 'content' => htmlspecialchars($data->content), 'user' => $data->user])->json; }, ['content', 'user']); Router::run(); DB::Disconnect();
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(); }