url_shortener
[ class tree: url_shortener ] [ index: url_shortener ] [ all elements ]

Class: url_shortener

Source Location: /url_shortener/class.url_shortener.php

Class Overview


Class for shortening urls The urls will be stored in a MySQL database, read doku for table Format.


Author(s):

Version:

  • v0.1_2009.09.10

Variables

Methods



Class Details

[line 75]
Class for shortening urls The urls will be stored in a MySQL database, read doku for table Format.



Tags:

version:  v0.1_2009.09.10
access:  public
name:  Url shorten class


[ Top ]


Class Variables

$db_table_hits =  'url_hits'

[line 89]

Name of Database table for storing redirect hits



Tags:

access:  public

Type:   string


[ Top ]

$db_table_redirect =  'url_redirect'

[line 82]

Name of Database table for storing urls and keys



Tags:

access:  public

Type:   string


[ Top ]

$key_base =  36

[line 98]

Convertion basis for the key convert method.

Default and maximum is 36 (36 => 0..9 and a..z) If you want to have hex keys set this to 16 (16 => 0..9 and a..f)




Tags:

access:  public

Type:   int


[ Top ]

$regex_valid_url =  '@http(s?):\/\/@'

[line 107]

Regex for URL validation

This one is very simple and does only allow urls starting with http:// and https://




Tags:

access:  public

Type:   string


[ Top ]

$url_parts_forbidden = array('http://www.example.com')

[line 115]

List of forbidden URL parts

Can be used to avoid making short links from short links




Tags:

access:  public

Type:   array


[ Top ]



Class Methods


method count_urls [line 204]

int|false count_urls( )

Simply returns the number of current urls



Tags:

return:  false on error
access:  public


[ Top ]

method get_redirect [line 149]

array get_redirect( string $key)

Method for selecting a redirect from database



Tags:

return:  Array with all available data inside, or empty one
access:  public


Parameters:

string   $key   Redirect key to search

[ Top ]

method get_redirect_count [line 187]

int|false get_redirect_count( string $key)

Simply returns the number of current hits for this key



Tags:

return:  false on error
access:  public


Parameters:

string   $key   Key of hitted link

[ Top ]

method log_redirect [line 159]

bool log_redirect( string $key)

Logs a redirect hit by key



Tags:

return:  false on error
access:  public


Parameters:

string   $key   Key of hitted link

[ Top ]

method new_redirect [line 128]

array new_redirect( string $url)

Method for creating a new redirect

Will return data from database if url already shortened




Tags:

return:  Array with all available data inside, or empty one
access:  public


Parameters:

string   $url   Url to shorten

[ Top ]

method _convert_id [line 322]

string _convert_id( int|string $id, [bool $dir = true])

Converts a numeric id from decimal to alphanumeric.



Tags:

return:  Converted id
access:  private


Parameters:

int|string   $id   Integer to convert
bool   $dir   Direction to convert, default=true => normal

[ Top ]

method _forbidden_url [line 239]

bool _forbidden_url( string $url)

Checks if a URL contains forbidden parts



Tags:

return:  True if URL is forbidden
access:  private


Parameters:

string   $url   URL to check

[ Top ]

method _get_ip [line 335]

string _get_ip( )

Returns the ip of current client

Checks for clients behind proxys




Tags:

return:  IP of current client
access:  private


[ Top ]

method _get_redirect_by_key [line 279]

array _get_redirect_by_key( string $key)

Searches a Key in the database and returns the whole dataset



Tags:

return:  Array with all available data inside, or empty one
access:  private


Parameters:

string   $key   Key to search

[ Top ]

method _get_redirect_by_url [line 299]

array _get_redirect_by_url( string $url)

Searches a URL in the database and returns the whole dataset



Tags:

return:  Array with all available data inside, or empty one
access:  private


Parameters:

string   $url   Url to search

[ Top ]

method _insert_url [line 256]

array _insert_url( string $url)

Inserts a URL to the database and returns the whole dataset



Tags:

return:  Array with all available data inside, or empty one
access:  private


Parameters:

string   $url   Url to shorten

[ Top ]

method _valid_url [line 225]

bool _valid_url( strin $url)

Validates a URL with global regex



Tags:

return:  true if URL is ok
access:  private


Parameters:

strin   $url   URL to validate

[ Top ]


Documentation generated on Fri, 29 Jan 2010 08:49:11 +0100 by phpDocumentor 1.4.3