Changeset 64
- Timestamp:
- 05/12/2006 12:39:05 PM (7 years ago)
- Files:
-
- 1 modified
-
trunk/actions/color.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/actions/color.php
r46 r64 34 34 35 35 // *** Constant section *** 36 define('ERROR_NO_TEXT_GIVEN','There is no text to highlight!');37 define('ERROR_NO_COLOR_SPECIFIED', 'Sorry, but you did not specify a color for highlighting!');36 if (!defined('ERROR_NO_TEXT_GIVEN')) define('ERROR_NO_TEXT_GIVEN','There is no text to highlight!'); 37 if (!defined('ERROR_NO_COLOR_SPECIFIED')) define('ERROR_NO_COLOR_SPECIFIED', 'Sorry, but you did not specify a color for highlighting!'); 38 38 39 39 // ***Internal function to test if syntax is valid … … 43 43 { 44 44 //Todo: To be more strict, ensure that when using rgb(r, g, b) syntax, integer values for r, g, and b are less than 256, or if % is used, those values are not greater than 100% 45 define('PATTERN_VALID_COLOR', '/^(?>#(?>[\da-f]{3}){1,2}|rgb\(\s*\d+((?>\.\d*)?%)?\s*(?>,\s*\d+(?(1)(\.\d*)?%)\s*){2}\))$/i'); 45 define('PATTERN_VALID_HEX_COLOR', '#(?>[\da-f]{3}){1,2}'); 46 define('PATTERN_VALID_RGB_COLOR', 'rgb\(\s*\d+((?>\.\d*)?%)?\s*(?>,\s*\d+(?(1)(\.\d*)?%)\s*){2}\)'); 46 47 $htlm_color_names = array('aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 47 48 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflower', 'cornsilk', 'crimson', 'cyan', … … 61 62 'inactiveborder', 'inactivecaption', 'inactivecaptiontext', 'infobackground', 'infotext', 'menu', 'menutext', 'scrollbar', 62 63 'threeddarkshadow', 'threedface', 'threedhighlight', 'threedlightshadow', 'threedshadow', 'window', 'windowframe', 'windowtext'); 63 $syntax = trim(strtolower($syntax));64 $syntax = trim(strtolower($syntax)); 64 65 if (in_array($syntax, $htlm_color_names)) 65 66 { 66 67 return($syntax); 67 68 } 68 if (preg_match( PATTERN_VALID_COLOR, $syntax, $match))69 if (preg_match('/^(?>'.PATTERN_VALID_HEX_COLOR.'|'.PATTERN_VALID_RGB_COLOR.')$/i', $syntax, $match)) 69 70 { 70 71 return($match[0]);