/** * Redirect to another page * */ function yourls_redirect($location, $code = 301) { yourls_do_action('pre_redirect', $location, $code); $location = yourls_apply_filter('redirect_location', $location, $code); $code = yourls_apply_filter('redirect_code', $code, $location); // Redirect, either properly if possible, or via Javascript otherwise if (!headers_sent()) { yourls_status_header($code); header("Location: {$location}"); } else { yourls_redirect_javascript($location); } die; }
function yourls_update_table_to_14() { global $ydb; $table = YOURLS_DB_TABLE_URL; // Modify each link to reflect new structure $chunk = 45; $from = isset($_GET['from']) ? intval($_GET['from']) : 0; $total = yourls_get_db_stats(); $total = $total['total_links']; $sql = "SELECT `keyword`,`url` FROM `{$table}` WHERE 1=1 ORDER BY `url` ASC LIMIT {$from}, {$chunk} ;"; $rows = $ydb->get_results($sql); $count = 0; $queries = 0; foreach ($rows as $row) { $keyword = $row->keyword; $url = $row->url; $newkeyword = yourls_int2string($keyword); $ydb->query("UPDATE `{$table}` SET `keyword` = '{$newkeyword}' WHERE `url` = '{$url}';"); if ($ydb->result === true) { $queries++; } else { echo "<p>Huho... Could not update rown with url='{$url}', from keyword '{$keyword}' to keyword '{$newkeyword}'</p>"; // Find what went wrong :/ } $count++; } // All done for this chunk of queries, did it all go as expected? $success = true; if ($count != $queries) { $success = false; $num = $count - $queries; echo "<p>{$num} error(s) occured while updating the URL table :(</p>"; } if ($count == $chunk) { // there are probably other rows to convert $from = $from + $chunk; $remain = $total - $from; echo "<p>Converted {$chunk} database rows ({$remain} remaining). Continuing... Please do not close this window until it's finished!</p>"; yourls_redirect_javascript(yourls_admin_url("upgrade.php?step=2&oldver=1.3&newver=1.4&oldsql=100&newsql=200&from={$from}"), $success); } else { // All done echo '<p>All rows converted! Please wait...</p>'; yourls_redirect_javascript(yourls_admin_url("upgrade.php?step=3&oldver=1.3&newver=1.4&oldsql=100&newsql=200"), $success); } }
function yourls_redirect($location, $code = 301) { // Redirect, either properly if possible, or via Javascript otherwise if (!headers_sent()) { yourls_status_header($code); header("Location: {$location}"); } else { yourls_redirect_javascript($location); } die; }