Changeset 64

Show
Ignore:
Timestamp:
05/12/2006 12:39:05 PM (7 years ago)
Author:
DotMG
Message:

#40 , proposition of NilsLindenberg

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/actions/color.php

    r46 r64  
    3434 
    3535// *** 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!'); 
     36if (!defined('ERROR_NO_TEXT_GIVEN')) define('ERROR_NO_TEXT_GIVEN','There is no text to highlight!'); 
     37if (!defined('ERROR_NO_COLOR_SPECIFIED')) define('ERROR_NO_COLOR_SPECIFIED', 'Sorry, but you did not specify a color for highlighting!'); 
    3838 
    3939// ***Internal function to test if syntax is valid 
     
    4343        { 
    4444                //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}\)'); 
    4647                $htlm_color_names = array('aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 
    4748                'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflower', 'cornsilk', 'crimson', 'cyan', 
     
    6162                'inactiveborder', 'inactivecaption', 'inactivecaptiontext', 'infobackground', 'infotext', 'menu', 'menutext', 'scrollbar', 
    6263                'threeddarkshadow', 'threedface', 'threedhighlight', 'threedlightshadow', 'threedshadow', 'window', 'windowframe', 'windowtext'); 
    63                         $syntax = trim(strtolower($syntax)); 
     64                $syntax = trim(strtolower($syntax)); 
    6465                if (in_array($syntax, $htlm_color_names)) 
    6566                { 
    6667                        return($syntax); 
    6768                } 
    68                 if (preg_match(PATTERN_VALID_COLOR, $syntax, $match)) 
     69                if (preg_match('/^(?>'.PATTERN_VALID_HEX_COLOR.'|'.PATTERN_VALID_RGB_COLOR.')$/i', $syntax, $match)) 
    6970                { 
    7071                        return($match[0]);