My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
PluginRandomKeywords  
Plugin: Assign random keywords
Plugin
Updated Aug 4, 2010 by ozh...@gmail.com

Plugin for YOURLS 1.5+: Assign random keywords to shorturls, like bitly (ie http://sho.rt/hJudjK)

Install

  • In /user/plugins, create a new folder named random-keyword
  • In this new directory, create a blank file named plugin.php
  • In this new file, cut and paste the following code
  • Go to the Plugins administration page and activate the plugin

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 );
}

Comment by speaker...@gmail.com, Aug 24, 2010

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!

Comment by lambpa...@gmail.com, Dec 16, 2010

Works like a charm: http://tinyquak.es/nf4t6

Thanks!

Comment by wal...@gmail.com, Jan 20, 2011

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...

Comment by yaha....@gmail.com, Mar 12, 2011

you can simply add the characters that you preferred . e.g return $in.'-'.'~';

Comment by chav...@gmail.com, Mar 23, 2011

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.

Comment by project member ozh...@gmail.com, Mar 23, 2011

chav: no. If one keyword is already used, the script searches for another one till it finds a free one

Comment by rodolfo....@gmail.com, Apr 14, 2011

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.

Comment by project member ozh...@gmail.com, Apr 15, 2011

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.

Comment by suyal...@gmail.com, Jul 10, 2011

and if those all possibilities of combination of 5 chars are used, how do you make it to automatically switch to 6 chars?

Comment by project member ozh...@gmail.com, Aug 1, 2011

You update the plugin setting to 6.

Comment by bradh...@gmail.com, Aug 9, 2011

does the plugin have to work with 1.5+? what about 1.4.3?

Comment by don.earn...@gmail.com, Aug 18, 2011

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

Comment by project member ozh...@gmail.com, Aug 18, 2011

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)

Comment by don.earn...@gmail.com, Aug 18, 2011

my bad, I missed that bit in the docs... thanks for the clarification.

Comment by cal...@gmail.com, Aug 18, 2011

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

Comment by project member ozh...@gmail.com, Aug 18, 2011

cal: absolutely not. Default encoding just works as well.

Comment by sjehu...@gmail.com, Aug 31, 2011

awesome thanks perfect

Comment by ske...@gmail.com, Sep 3, 2011

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.

Comment by ponyfeed...@gmail.com, Oct 17, 2011

How can I prefix every random string with the same characters (y-), ie sho.rt/y-a1 sho.rt/y-8z etc thanks

Comment by nadia.t...@gmail.com, Nov 4, 2011

I'm having the same problem as "ske..." The plugin continues to generate old style short urls. What should I do?

Comment by mich...@michaelphill.com, Dec 15, 2011

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.

Comment by project member ozh...@gmail.com, Dec 15, 2011

Michael: modify return yourls_rnd_string( $ozh_random_keyword['length'] ); with return trim( yourls_rnd_string( $ozh_random_keyword['length'] ), '-' );

Comment by friutbil...@gmail.com, Dec 20, 2011

Great plugin! How about excluding letters and only using numbers as random characters like sho.rt/123456 ? Can't figure it out.

Comment by project member ozh...@gmail.com, Dec 21, 2011

friutbildning: look at the "hyphens-in-urls" plugin

Comment by aidan.ha...@gmail.com, May 11, 2012

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?

Comment by project member ozh...@gmail.com, May 12, 2012

The public interface is just here as a basic example. It's up to each user to customize it to will.


Sign in to add a comment
Powered by Google Project Hosting