1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
$data = array();
preg_match_all('@(\w+)=(?:([\'"])([^$2]+)$2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
foreach ($matches as $m) {
$data[$m[1]] = $m[3] ? trim($m[3],"\",'") : trim($m[4],"\",'");
unset($needed_parts[$m[1]]);
}
return $needed_parts ? false : $data;
}
// Prompt for Authentication
function yourls_auth_headers($realm = '') {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Digest realm="'.$realm.'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
die('Sorry! Retry.');
}
// Make sure a link id (site.com/1fv) is valid.
function yourls_sanitize_string ($in) {
if (YOURLS_URL_CONVERT <= 37)
$in = strtolower($in);
return substr(preg_replace('/[^a-zAZ0-9]/', '', $in), 0, 12);
}
// make sure there's one and only one 'http://' at the beginning (prevents omitting or pasting a URL right after the default 'http://')
function yourls_sanitize_url($url) {
return preg_replace('#^(http://)+#', 'http://', 'http://'.$url);
}
// Make sure an id link is a valid integer (PHP's intval() limits to too small numbers)
function yourls_sanitize_int($in) {
return ( substr(preg_replace('/[^0-9]/', '', strval($in) ), 0, 20) );
}
// Make sure a integer is safe
// Note: this is not checking for integers, since integers on 32bits system are way too limited
// TODO: find a way to validate as integer
function yourls_intval($in) {
return mysql_real_escape_string($in);
}
// Check to see if a given integer id is reserved (ie reserved URL or an existing page)
// Returns bool
function yourls_is_reserved_id($id) {
global $yourls_reserved_URL;
$keyword = yourls_int2string( yourls_intval($id) );
if ( in_array( $keyword, $yourls_reserved_URL)
or file_exists(dirname(dirname(__FILE__))."/pages/$keyword.php")
or is_dir(dirname(dirname(__FILE__))."$keyword")
)
return true;
return false;
}
// Function: Get IP Address
function yourls_get_IP() {
if(!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip_address = $_SERVER['HTTP_CLIENT_IP'];
} else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else if(!empty($_SERVER['REMOTE_ADDR'])) {
$ip_address = $_SERVER['REMOTE_ADDR'];
} else {
$ip_address = '';
}
if(strpos($ip_address, ',') !== false) {
$ip_address = explode(',', $ip_address);
$ip_address = $ip_address[0];
}
return $ip_address;
}
// Add the "Edit" row
function yourls_table_edit_row($id, $db) {
$id = yourls_intval($id);
$table = YOURLS_DB_TABLE_URL;
$url = $db->get_row("SELECT `url` FROM `$table` WHERE `id` = '$id';");
$safe_url = stripslashes($url->url);
$keyword = yourls_int2string($id);
if($url) {
$return = <<
Edit: original URL:
short URL:
RETURN;
} else {
$return = '
Invalid URL ID
';
}
return $return;
}
// Add a link row
function yourls_table_add_row( $id, $keyword, $url, $ip, $clicks, $timestamp ) {
$date = date( 'Y M d H:i', $timestamp+( yourls_HOURS_OFFSET * 3600) );
$clicks = number_format($clicks);
$www = YOURLS_SITE;
return <<