lib MDL-19236 Added boilerplates and copyrights

This commit is contained in:
samhemelryk
2009-05-26 05:18:52 +00:00
parent b37eac91cc
commit 72fb21b65b
6 changed files with 516 additions and 337 deletions
+251 -249
View File
@@ -1,172 +1,172 @@
<?php
/*
About validateUrlSyntax():
This function will verify if a http URL is formatted properly, returning
either with true or false.
I used rfc #2396 URI: Generic Syntax as my guide when creating the
regular expression. For all the details see the comments below.
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
Usage:
validateUrlSyntax( url_to_check[, options])
/**
* About validateUrlSyntax():
* This function will verify if a http URL is formatted properly, returning
* either with true or false.
*
* I used rfc #2396 URI: Generic Syntax as my guide when creating the
* regular expression. For all the details see the comments below.
*
* Usage:
* validateUrlSyntax( url_to_check[, options])
*
* url_to_check - string - The url to check
*
* options - string - A optional string of options to set which parts of
* the url are required, optional, or not allowed. Each option
* must be followed by a "+" for required, "?" for optional, or
* "-" for not allowed.
*
* s - Scheme. Allows "+?-", defaults to "s?"
* H - http:// Allows "+?-", defaults to "H?"
* S - https:// (SSL). Allows "+?-", defaults to "S?"
* E - mailto: (email). Allows "+?-", defaults to "E-"
* F - ftp:// Allows "+?-", defaults to "F-"
* Dependant on scheme being enabled
* u - User section. Allows "+?-", defaults to "u?"
* P - Password in user section. Allows "+?-", defaults to "P?"
* Dependant on user section being enabled
* a - Address (ip or domain). Allows "+?-", defaults to "a+"
* I - Ip address. Allows "+?-", defaults to "I?"
* If I+, then domains are disabled
* If I-, then domains are required
* Dependant on address being enabled
* p - Port number. Allows "+?-", defaults to "p?"
* f - File path. Allows "+?-", defaults to "f?"
* q - Query section. Allows "+?-", defaults to "q?"
* r - Fragment (anchor). Allows "+?-", defaults to "r?"
*
* Paste the funtion code, or include_once() this template at the top of the page
* you wish to use this function.
*
*
* Examples:
* <code>
* validateUrlSyntax('http://[email protected]/#top')
*
* validateUrlSyntax('https://games.yahoo.com:8080/board/chess.htm?move=true')
*
* validateUrlSyntax('http://www.hotmail.com/', 's+u-I-p-q-r-')
*
* validateUrlSyntax('/directory/file.php#top', 's-u-a-p-f+')
*
*
* if (validateUrlSyntax('http://www.canowhoopass.com/', 'u-'))
* {
* echo 'URL SYNTAX IS VERIFIED';
* } else {
* echo 'URL SYNTAX IS ILLEGAL';
* }
* </code>
*
* Last Edited:
* December 15th 2004
*
*
* Changelog:
* December 15th 2004
* -Added new TLD's - .jobs, .mobi, .post and .travel. They are official, but not yet active.
*
* August 31th 2004
* -Fixed bug allowing empty username even when it was required
* -Changed and added a few options to add extra schemes
* -Added mailto: ftp:// and http:// options
* -https option was 'l' now it is 'S' (capital)
* -Added password option. Now passwords can be disabled while usernames are ok (for email)
* -IP Address option was 'i' now it is 'I' (capital)
* -Options are now case sensitive
* -Added validateEmailSyntax() and validateFtpSyntax() functions below<br>
*
* August 27th, 2004
* -IP group range is more specific. Used to allow 0-299. Now it is 0-255
* -Port range more specific. Used to allow 0-69999. Now it is 0-65535<br>
* -Fixed bug disallowing 'i-' option.<br>
* -Changed license to GPL
*
* July 8th, 2004
* -Fixed bug disallowing 'l-' option. Thanks Dr. Cheap
*
* June 15, 2004
* -Added options parameter to make it easier for people to plug the function in
* without needed to rework the code.
* -Split the example application away from the function
*
* June 1, 2004
* -Complete rewrite
* -Now more modular
* -Easier to disable sections
* -Easier to port to other languages
* -Easier to port to verify email addresses
* -Uses only simple regular expressions so it is more portable
* -Follows RFC closer for domain names. Some "play" domains may break
* -Renamed from 'verifyUrl()' to 'validateUrlSyntax()'
* -Removed extra code which added 'http://' and trailing '/' if it was missing
* -That code was better suited for a massaging function, not verifying
* -Bug fixes:
* -Now splits up and forces '/path?query#fragment' order
* -No longer requires a path when using a query or fragment
*
* August 29, 2003
* -Allowed port numbers above 9999. Now allows up to 69999
*
* Sometime, 2002
* -Added new top level domains
* -aero, coop, museum, name, info, biz, pro
*
* October 5, 2000
* -First Version
*
*
* Intentional Limitations:
* -Does not verify url actually exists. Only validates the syntax
* -Strictly follows the RFC standards. Some urls exist in the wild which will
* not validate. Including ones with square brackets in the query section '[]'
*
*
* Known Problems:
* -None at this time
*
*
* Author(s):
* Rod Apeldoorn - rod(at)canowhoopass(dot)com
*
*
* Homepage:
* http://www.canowhoopass.com/
*
*
* Thanks!:
* -WEAV -Several members of Weav helped to test - http://weav.bc.ca/
* -There were also a number of emails from other developers expressing
* thanks and suggestions. It is nice to be appreciated. Thanks!
*
* Alternate Commercial Licenses:
* For information in regards to alternate licensing, contact me.
*
* @package moodlecore
* @copyright Copyright 2004, Rod Apeldoorn {@link http://www.canowhoopass.com/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
url_to_check - string - The url to check
options - string - A optional string of options to set which parts of
the url are required, optional, or not allowed. Each option
must be followed by a "+" for required, "?" for optional, or
"-" for not allowed.
s - Scheme. Allows "+?-", defaults to "s?"
H - http:// Allows "+?-", defaults to "H?"
S - https:// (SSL). Allows "+?-", defaults to "S?"
E - mailto: (email). Allows "+?-", defaults to "E-"
F - ftp:// Allows "+?-", defaults to "F-"
Dependant on scheme being enabled
u - User section. Allows "+?-", defaults to "u?"
P - Password in user section. Allows "+?-", defaults to "P?"
Dependant on user section being enabled
a - Address (ip or domain). Allows "+?-", defaults to "a+"
I - Ip address. Allows "+?-", defaults to "I?"
If I+, then domains are disabled
If I-, then domains are required
Dependant on address being enabled
p - Port number. Allows "+?-", defaults to "p?"
f - File path. Allows "+?-", defaults to "f?"
q - Query section. Allows "+?-", defaults to "q?"
r - Fragment (anchor). Allows "+?-", defaults to "r?"
Paste the funtion code, or include_once() this template at the top of the page
you wish to use this function.
Examples:
validateUrlSyntax('http://[email protected]/#top')
validateUrlSyntax('https://games.yahoo.com:8080/board/chess.htm?move=true')
validateUrlSyntax('http://www.hotmail.com/', 's+u-I-p-q-r-')
validateUrlSyntax('/directory/file.php#top', 's-u-a-p-f+')
if (validateUrlSyntax('http://www.canowhoopass.com/', 'u-'))
{
echo 'URL SYNTAX IS VERIFIED';
} else {
echo 'URL SYNTAX IS ILLEGAL';
}
Last Edited:
December 15th 2004
Changelog:
December 15th 2004
-Added new TLD's - .jobs, .mobi, .post and .travel. They are official, but not yet active.
August 31th 2004
-Fixed bug allowing empty username even when it was required
-Changed and added a few options to add extra schemes
-Added mailto: ftp:// and http:// options
-https option was 'l' now it is 'S' (capital)
-Added password option. Now passwords can be disabled while usernames are ok (for email)
-IP Address option was 'i' now it is 'I' (capital)
-Options are now case sensitive
-Added validateEmailSyntax() and validateFtpSyntax() functions below<br>
August 27th, 2004
-IP group range is more specific. Used to allow 0-299. Now it is 0-255
-Port range more specific. Used to allow 0-69999. Now it is 0-65535<br>
-Fixed bug disallowing 'i-' option.<br>
-Changed license to GPL
July 8th, 2004
-Fixed bug disallowing 'l-' option. Thanks Dr. Cheap
June 15, 2004
-Added options parameter to make it easier for people to plug the function in
without needed to rework the code.
-Split the example application away from the function
June 1, 2004
-Complete rewrite
-Now more modular
-Easier to disable sections
-Easier to port to other languages
-Easier to port to verify email addresses
-Uses only simple regular expressions so it is more portable
-Follows RFC closer for domain names. Some "play" domains may break
-Renamed from 'verifyUrl()' to 'validateUrlSyntax()'
-Removed extra code which added 'http://' and trailing '/' if it was missing
-That code was better suited for a massaging function, not verifying
-Bug fixes:
-Now splits up and forces '/path?query#fragment' order
-No longer requires a path when using a query or fragment
August 29, 2003
-Allowed port numbers above 9999. Now allows up to 69999
Sometime, 2002
-Added new top level domains
-aero, coop, museum, name, info, biz, pro
October 5, 2000
-First Version
Intentional Limitations:
-Does not verify url actually exists. Only validates the syntax
-Strictly follows the RFC standards. Some urls exist in the wild which will
not validate. Including ones with square brackets in the query section '[]'
Known Problems:
-None at this time
Author(s):
Rod Apeldoorn - rod(at)canowhoopass(dot)com
Homepage:
http://www.canowhoopass.com/
Thanks!:
-WEAV -Several members of Weav helped to test - http://weav.bc.ca/
-There were also a number of emails from other developers expressing
thanks and suggestions. It is nice to be appreciated. Thanks!
License:
Copyright 2004, Rod Apeldoorn
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
To view the license online, go to: http://www.gnu.org/copyleft/gpl.html
Alternate Commercial Licenses:
For information in regards to alternate licensing, contact me.
*/
// BEGINNING OF validateUrlSyntax() function
/**
* BEGINNING OF validateUrlSyntax() function
*/
function validateUrlSyntax( $urladdr, $options="" ){
// Force Options parameter to be lower case
@@ -328,51 +328,51 @@ function validateUrlSyntax( $urladdr, $options="" ){
/*
About ValidateEmailSyntax():
This function uses the ValidateUrlSyntax() function to easily check the
syntax of an email address. It accepts the same options as ValidateURLSyntax
but defaults them for email addresses.
Usage:
validateEmailSyntax( url_to_check[, options])
url_to_check - string - The url to check
options - string - A optional string of options to set which parts of
the url are required, optional, or not allowed. Each option
must be followed by a "+" for required, "?" for optional, or
"-" for not allowed. See ValidateUrlSyntax() docs for option list.
The default options are changed to:
s-H-S-E+F-u+P-a+I-p-f-q-r-
This only allows an address of "name@domain".
Examples:
validateEmailSyntax('[email protected]')
validateEmailSyntax('mailto:[email protected]', 's+')
validateEmailSyntax('[email protected]?subject=Hi%20George', 'q?')
validateEmailSyntax('[email protected]', 'I?')
Author(s):
Rod Apeldoorn - rod(at)canowhoopass(dot)com
Homepage:
http://www.canowhoopass.com/
License:
Copyright 2004 - Rod Apeldoorn
Released under same license as validateUrlSyntax(). For details, contact me.
*/
/**
* About ValidateEmailSyntax():
* This function uses the ValidateUrlSyntax() function to easily check the
* syntax of an email address. It accepts the same options as ValidateURLSyntax
* but defaults them for email addresses.
*
*
* Usage:
* <code>
* validateEmailSyntax( url_to_check[, options])
* </code>
* url_to_check - string - The url to check
*
* options - string - A optional string of options to set which parts of
* the url are required, optional, or not allowed. Each option
* must be followed by a "+" for required, "?" for optional, or
* "-" for not allowed. See ValidateUrlSyntax() docs for option list.
*
* The default options are changed to:
* s-H-S-E+F-u+P-a+I-p-f-q-r-
*
* This only allows an address of "name@domain".
*
* Examples:
* <code>
* validateEmailSyntax('[email protected]')
* validateEmailSyntax('mailto:[email protected]', 's+')
* validateEmailSyntax('[email protected]?subject=Hi%20George', 'q?')
* validateEmailSyntax('[email protected]', 'I?')
* </code>
*
*
* Author(s):
* Rod Apeldoorn - rod(at)canowhoopass(dot)com
*
*
* Homepage:
* http://www.canowhoopass.com/
*
*
* License:
* Copyright 2004 - Rod Apeldoorn
*
* Released under same license as validateUrlSyntax(). For details, contact me.
*/
function validateEmailSyntax( $emailaddr, $options="" ){
@@ -440,45 +440,47 @@ function validateEmailSyntax( $emailaddr, $options="" ){
/*
About ValidateFtpSyntax():
This function uses the ValidateUrlSyntax() function to easily check the
syntax of an FTP address. It accepts the same options as ValidateURLSyntax
but defaults them for FTP addresses.
Usage:
validateFtpSyntax( url_to_check[, options])
url_to_check - string - The url to check
options - string - A optional string of options to set which parts of
the url are required, optional, or not allowed. Each option
must be followed by a "+" for required, "?" for optional, or
"-" for not allowed. See ValidateUrlSyntax() docs for option list.
The default options are changed to:
s?H-S-E-F+u?P?a+I?p?f?q-r-
Examples:
validateFtpSyntax('ftp://netscape.com')
validateFtpSyntax('moz:[email protected]')
validateFtpSyntax('ftp://netscape.com:2121/browsers/ns7/', 'u-')
Author(s):
Rod Apeldoorn - rod(at)canowhoopass(dot)com
Homepage:
http://www.canowhoopass.com/
License:
Copyright 2004 - Rod Apeldoorn
Released under same license as validateUrlSyntax(). For details, contact me.
*/
/**
* About ValidateFtpSyntax():
* This function uses the ValidateUrlSyntax() function to easily check the
* syntax of an FTP address. It accepts the same options as ValidateURLSyntax
* but defaults them for FTP addresses.
*
*
* Usage:
* <code>
* validateFtpSyntax( url_to_check[, options])
* </code>
* url_to_check - string - The url to check
*
* options - string - A optional string of options to set which parts of
* the url are required, optional, or not allowed. Each option
* must be followed by a "+" for required, "?" for optional, or
* "-" for not allowed. See ValidateUrlSyntax() docs for option list.
*
* The default options are changed to:
* s?H-S-E-F+u?P?a+I?p?f?q-r-
*
* Examples:
* <code>
* validateFtpSyntax('ftp://netscape.com')
* validateFtpSyntax('moz:[email protected]')
* validateFtpSyntax('ftp://netscape.com:2121/browsers/ns7/', 'u-')
* </code>
*
* Author(s):
* Rod Apeldoorn - rod(at)canowhoopass(dot)com
*
*
* Homepage:
* http://www.canowhoopass.com/
*
*
* License:
* Copyright 2004 - Rod Apeldoorn
*
* Released under same license as validateUrlSyntax(). For details, contact me.
*/
function validateFtpSyntax( $ftpaddr, $options="" ){