X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fwebcolor.php;h=bf791bf794e98438d4a14b3f3ff8b1cce373df23;hb=0a20abf1d8a9a068df9310d6903cc303f39b25ed;hp=65713d26ef7e695821a2faa94c47e9b4ffd54761;hpb=20d93508776398627f5aff64b83bd20a362cb45d;p=quix0rs-gnu-social.git diff --git a/lib/webcolor.php b/lib/webcolor.php index 65713d26ef..bf791bf794 100644 --- a/lib/webcolor.php +++ b/lib/webcolor.php @@ -1,6 +1,6 @@ . * * @category Personal - * @package Laconica - * @author Zach Copley - * @copyright 2009 Control Yourself, Inc. + * @package StatusNet + * @author Zach Copley + * @copyright 2009 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * @link http://laconi.ca/ + * @link http://status.net/ */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } class WebColor { - // XXX: Maybe make getters and setters for r,g,b values and tuples, // e.g.: to support this kinda CSS representation: rgb(255,0,0) // http://www.w3.org/TR/CSS21/syndata.html#color-units @@ -46,7 +45,6 @@ class WebColor { * * @return nothing */ - function __construct($color = null) { if (isset($color)) { @@ -65,7 +63,6 @@ class WebColor { * * @return nothing */ - function parseColor($color) { if (is_numeric($color)) { @@ -79,7 +76,9 @@ class WebColor { if (preg_match('/(#([0-9A-Fa-f]{3,6})\b)/u', $color) > 0) { $this->setHexColor($color); } else { - $errmsg = _('%s is not a valid color!'); + // TRANS: Web color exception thrown when a hexadecimal color code does not validate. + // TRANS: %s is the provided (invalid) color code. + $errmsg = _('%s is not a valid color! Use 3 or 6 hex characters.'); throw new WebColorException(sprintf($errmsg, $color)); } } @@ -90,13 +89,11 @@ class WebColor { * * @return nothing */ - function setNamedColor($name) { // XXX Implement this } - /** * Sets the RGB color values from a a hex tuple * @@ -104,7 +101,6 @@ class WebColor { * * @return nothing */ - function setHexColor($hexcolor) { if ($hexcolor[0] == '#') { @@ -120,7 +116,10 @@ class WebColor { $hexcolor[1].$hexcolor[1], $hexcolor[2].$hexcolor[2]); } else { - return false; + // TRANS: Web color exception thrown when a hexadecimal color code does not validate. + // TRANS: %s is the provided (invalid) color code. + $errmsg = _('%s is not a valid color! Use 3 or 6 hex characters.'); + throw new WebColorException(sprintf($errmsg, $hexcolor)); } $this->red = hexdec($r); @@ -136,7 +135,6 @@ class WebColor { * * @return nothing */ - function setIntColor($intcolor) { // We could do 32 bit and have an alpha channel because @@ -153,7 +151,6 @@ class WebColor { * * @return string */ - function hexValue() { $hexcolor = (strlen(dechex($this->red)) < 2 ? '0' : '' ) . @@ -163,8 +160,7 @@ class WebColor { $hexcolor .= (strlen(dechex($this->blue)) < 2 ? '0' : '') . dechex($this->blue); - return $hexcolor; - + return strtoupper($hexcolor); } /** @@ -175,7 +171,6 @@ class WebColor { * * @return int */ - function intValue() { $intcolor = 256 * 256 * $this->red + 256 * $this->green + $this->blue; @@ -187,5 +182,3 @@ class WebColor { class WebColorException extends Exception { } - -?> \ No newline at end of file