Code Duplication    Length = 17-18 lines in 2 locations

includes/functions.php 2 locations

@@ 175-191 (lines=17) @@
172
 * @param  string $url  URL to check if already shortened
173
 * @return mixed        NULL if does not already exist in DB, or object with URL information as properties (eg keyword, url, title, ...)
174
 */
175
function yourls_url_exists( $url ) {
176
	// Allow plugins to short-circuit the whole function
177
	$pre = yourls_apply_filter( 'shunt_url_exists', false, $url );
178
	if ( false !== $pre )
179
		return $pre;
180
181
	global $ydb;
182
	$table = YOURLS_DB_TABLE_URL;
183
    $url   = yourls_sanitize_url($url);
184
	$url_exists = $ydb->fetchObject("SELECT * FROM `$table` WHERE `url` = :url", array('url'=>$url));
185
186
    if ($url_exists === false) {
187
        $url_exists = NULL;
188
    }
189
190
	return yourls_apply_filter( 'url_exists', $url_exists, $url );
191
}
192
193
/**
194
 * Add a new link in the DB, either with custom keyword, or find one
@@ 418-435 (lines=18) @@
415
 * Check if a keyword is taken (ie there is already a short URL with this id). Return bool.
416
 *
417
 */
418
function yourls_keyword_is_taken( $keyword ) {
419
420
	// Allow plugins to short-circuit the whole function
421
	$pre = yourls_apply_filter( 'shunt_keyword_is_taken', false, $keyword );
422
	if ( false !== $pre )
423
		return $pre;
424
425
	global $ydb;
426
    $keyword = yourls_sanitize_keyword($keyword);
427
	$taken = false;
428
	$table = YOURLS_DB_TABLE_URL;
429
430
	$already_exists = $ydb->fetchValue("SELECT COUNT(`keyword`) FROM `$table` WHERE `keyword` = :keyword;", array('keyword' => $keyword));
431
	if ( $already_exists )
432
		$taken = true;
433
434
	return yourls_apply_filter( 'keyword_is_taken', $taken, $keyword );
435
}
436
437
/**
438
 * Return XML output.