@@ 250-264 (lines=15) @@ | ||
247 | ||
248 | $keyword = yourls_sanitize_string( $keyword ); |
|
249 | $keyword = yourls_apply_filter( 'custom_keyword', $keyword, $url, $title ); |
|
250 | if ( !yourls_keyword_is_free( $keyword ) ) { |
|
251 | // This shorturl either reserved or taken already |
|
252 | $return['status'] = 'fail'; |
|
253 | $return['code'] = 'error:keyword'; |
|
254 | $return['message'] = yourls_s( 'Short URL %s already exists in database or is reserved', $keyword ); |
|
255 | } else { |
|
256 | // all clear, store ! |
|
257 | yourls_insert_link_in_db( $url, $keyword, $title ); |
|
258 | $return['url'] = array('keyword' => $keyword, 'url' => $strip_url, 'title' => $title, 'date' => date('Y-m-d H:i:s'), 'ip' => $ip ); |
|
259 | $return['status'] = 'success'; |
|
260 | $return['message'] = /* //translators: eg "http://someurl/ added to DB" */ yourls_s( '%s added to database', yourls_trim_long_string( $strip_url ) ); |
|
261 | $return['title'] = $title; |
|
262 | $return['html'] = yourls_table_add_row( $keyword, $url, $title, $ip, 0, time() ); |
|
263 | $return['shorturl'] = YOURLS_SITE .'/'. $keyword; |
|
264 | } |
|
265 | ||
266 | // Create random keyword |
|
267 | } else { |
|
@@ 277-293 (lines=17) @@ | ||
274 | do { |
|
275 | $keyword = yourls_int2string( $id ); |
|
276 | $keyword = yourls_apply_filter( 'random_keyword', $keyword, $url, $title ); |
|
277 | if ( yourls_keyword_is_free($keyword) ) { |
|
278 | if (yourls_insert_link_in_db( $url, $keyword, $title )){ |
|
279 | // everything ok, populate needed vars |
|
280 | $return['url'] = array('keyword' => $keyword, 'url' => $strip_url, 'title' => $title, 'date' => $timestamp, 'ip' => $ip ); |
|
281 | $return['status'] = 'success'; |
|
282 | $return['message'] = /* //translators: eg "http://someurl/ added to DB" */ yourls_s( '%s added to database', yourls_trim_long_string( $strip_url ) ); |
|
283 | $return['title'] = $title; |
|
284 | $return['html'] = yourls_table_add_row( $keyword, $url, $title, $ip, 0, time() ); |
|
285 | $return['shorturl'] = YOURLS_SITE .'/'. $keyword; |
|
286 | } else { |
|
287 | // database error, couldnt store result |
|
288 | $return['status'] = 'fail'; |
|
289 | $return['code'] = 'error:db'; |
|
290 | $return['message'] = yourls_s( 'Error saving url to database' ); |
|
291 | } |
|
292 | $ok = true; |
|
293 | } |
|
294 | $id++; |
|
295 | } while ( !$ok ); |
|
296 | @yourls_update_next_decimal( $id ); |