|
PluginRandomKeywords
Plugin: Assign random keywords
Plugin Plugin for YOURLS 1.5+: Assign random keywords to shorturls, like bitly (ie http://sho.rt/hJudjK) Install
Code<?php
/*
Plugin Name: Random Keywords
Plugin URI: http://yourls.org/
Description: Assign random keywords to shorturls, like bitly (sho.rt/hJudjK)
Version: 1.1
Author: Ozh
Author URI: http://ozh.org/
*/
/* Release History:
*
* 1.0 Initial release
* 1.1 Added: don't increment sequential keyword counter & save one SQL query
* Fixed: plugin now complies to character set defined in config.php
*/
global $ozh_random_keyword;
/*
* CONFIG: EDIT THIS
*/
/* Length of random keyword */
$ozh_random_keyword['length'] = 5;
/*
* DO NOT EDIT FARTHER
*/
// Generate a random keyword
yourls_add_filter( 'random_keyword', 'ozh_random_keyword' );
function ozh_random_keyword() {
global $ozh_random_keyword;
return yourls_rnd_string( $ozh_random_keyword['length'] );
}
// Don't increment sequential keyword tracker
yourls_add_filter( 'get_next_decimal', 'ozh_random_keyword_next_decimal' );
function ozh_random_keyword_next_decimal( $next ) {
return ( $next - 1 );
}
|
► Sign in to add a comment
It says that you need YOURLS 1.5+ and I looked and the highest version available is 1.4.3. Is there a way to use these plugins with the 1.4.3 version? Thanks!
Works like a charm: http://tinyquak.es/nf4t6
Thanks!
I don't know why I want this, but how do you get http://sho.rt/~abc
For some reason that seems the most professional looking to me...
you can simply add the characters that you preferred . e.g return $in.'-'.'~';
Is there any chance to get an already shortened url with the same id? I mean getting 2 times the same id so I have 2 urls with it.
chav: no. If one keyword is already used, the script searches for another one till it finds a free one
This plugin has a flaw. When the total combinations of $ozh_random_keyword['length'] = 5; is filled, the plugin outputs nothing. You may code a few lines that will check if the string is used and if there is no more strings available with that lenght, you level up the lenght by +1.
The plugin checks if the string is used, and if so, tries another one till it finds one free. Indeed, if you fill all 11 millions, it will loop forever.
and if those all possibilities of combination of 5 chars are used, how do you make it to automatically switch to 6 chars?
You update the plugin setting to 6.
does the plugin have to work with 1.5+? what about 1.4.3?
I just need a sanity check here... isn't 5 alphanumeric characters closer to 916 million?
26 lower case letters + 26 uppercase letters + 10 numerals = 62 characters
62 X 62 X 62 X 62 X 62 = 916,132,832
don: my erroneous 11 millions were only taking into account the lowercase letters (default setting) and not the digit. The correct number is (26 + 10)^5 = 66 millions, but you're right if you're using base62 (lowercase + uppercase)
my bad, I missed that bit in the docs... thanks for the clarification.
FYI
define( 'YOURLS_URL_CONVERT', 64 );
This needs to be enabled if you want to use this plugin. I almost pulled my beard off my face
cal: absolutely not. Default encoding just works as well.
awesome thanks perfect
My problem is that even with this plug-in enabled and working when generating URLs manually, the "YOURLS: WordPress? to Twitter" plug-in for WordPress? continues to generate old-style short URLs by increasing a numerical value, eg. short.url/1, short.url/2, etc.
How can I prefix every random string with the same characters (y-), ie sho.rt/y-a1 sho.rt/y-8z etc thanks
I'm having the same problem as "ske..." The plugin continues to generate old style short urls. What should I do?
Is there a way to prevent the hyphen in randomly generated URLs from being at the end of the hash? The problem is that some social services don't correctly understand the link when it ends in a hyphen.
Michael: modify return yourls_rnd_string( $ozh_random_keyword['length'] ); with return trim( yourls_rnd_string( $ozh_random_keyword['length'] ), '-' );
Great plugin! How about excluding letters and only using numbers as random characters like sho.rt/123456 ? Can't figure it out.
friutbildning: look at the "hyphens-in-urls" plugin
Is there any way you could add an option to the public interface to email users a copy of their shortened links for future reference?
The public interface is just here as a basic example. It's up to each user to customize it to will.