public function execute()
 {
     $user = $this->getUser();
     $params = $this->extractRequestParams();
     // If we're in JSON callback mode, no tokens can be obtained
     if ($this->lacksSameOriginSecurity()) {
         $this->dieUsage('Cannot obtain a centralauthtoken when using a callback', 'hascallback');
     }
     if ($user->isAnon()) {
         $this->dieUsage('Anonymous users cannot obtain a centralauthtoken', 'notloggedin');
     }
     if (CentralAuthHooks::hasApiToken()) {
         $this->dieUsage('Cannot obtain a centralauthtoken when using centralauthtoken', 'norecursion');
     }
     $centralUser = CentralAuthUser::getInstance($user);
     if (!$centralUser->exists() || !$centralUser->isAttached()) {
         $this->dieUsage('Cannot obtain a centralauthtoken without an attached global account', 'notattached');
     }
     $data = array('userName' => $user->getName(), 'token' => $centralUser->getAuthToken());
     global $wgMemc;
     $loginToken = MWCryptRand::generateHex(32) . dechex($centralUser->getId());
     $key = CentralAuthUser::memcKey('api-token', $loginToken);
     $wgMemc->add($key, $data, 60);
     $this->getResult()->addValue(null, $this->getModuleName(), array('centralauthtoken' => $loginToken));
 }
Пример #2
0
function doMath($val, $idx, &$values)
{
    $offset = 12288;
    $ret = dechex($val * 8 + $offset);
    $values[$idx][0] = $ret[0] . $ret[1];
    $values[$idx][1] = $ret[2] . $ret[3];
}
Пример #3
0
function LIBDBERROR($num,$st) {
    @ob_get_clean();
    ob_start();
    echo "\nLIBDB: [ ".dechex($num)." ] $st\n" . mysql_error()."\n";
    debug_print_backtrace();
    die(json_encode(array("err" => ob_get_clean())));
  }
function rgbToHex($red, $green, $blue, $format = false)
{
    $red = intval($red);
    $green = intval($green);
    $blue = intval($blue);
    if ($red >= 0 && $red <= 255 && $green >= 0 && $green <= 255 && $blue >= 0 && $blue <= 255) {
        $redhex = strval(dechex($red));
        $greenhex = strval(dechex($green));
        $bluehex = strval(dechex($blue));
        if (strlen($redhex) < 2) {
            $redhex = strval("0" . $redhex);
        }
        if (strlen($greenhex) < 2) {
            $greenhex = strval("0" . $greenhex);
        }
        if (strlen($bluehex) < 2) {
            $bluehex = strval("0" . $bluehex);
        }
        if ($format) {
            return "#" . $redhex . $greenhex . $bluehex;
        } else {
            return $redhex . $greenhex . $bluehex;
        }
    } else {
        return false;
    }
}
Пример #5
0
 /**
  * @desc Convert decimal color to #ffffff
  */
 function RGB2HEX($r, $g, $b)
 {
     $r = $r < 16 ? '0' . dechex($r) : dechex($r);
     $g = $g < 16 ? '0' . dechex($g) : dechex($g);
     $b = $b < 16 ? '0' . dechex($b) : dechex($b);
     return "#{$r}{$g}{$b}";
 }
Пример #6
0
/**
 * Hook function for ParserBeforeTidy
 *
 * HTML Tidy does not understand MathML, and
 * Sanitizer::normalizeCharReferences() does not know about plane-1
 * entities like &Ascr; . Therefore, we replace all MathML tags with
 * placeholders. The original MathML is stored in $parser.
 */
function efBlahtexParserBeforeTidy(&$parser, &$text)
{
    global $wgBlahtexMathContent, $wgBlahtexMathTags;
    $mathtags = array();
    $endtag = "</math>";
    $stripped = "";
    $pos = 0;
    $rand = dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
    $n = 1;
    while (TRUE) {
        $res = preg_match("/<math[^>]*>/i", $text, $matches, PREG_OFFSET_CAPTURE, $pos);
        if ($res == 0) {
            break;
        }
        $pos2 = stripos($text, $endtag, $matches[0][1]);
        if ($pos2 == 0) {
            break;
        }
        $stripped .= substr($text, $pos, $matches[0][1] - $pos);
        $marker = "UNIQ-blahtex-{$rand}" . sprintf('%08X', $n++) . '-QINU';
        $stripped .= $marker;
        $pos = $pos2 + strlen($endtag);
        $mathtags[$marker] = substr($text, $matches[0][1], $pos - $matches[0][1]);
    }
    $parser->blahtexMathtags = $mathtags;
    $text = $stripped . substr($text, $pos);
    return true;
}
Пример #7
0
 function parse($code = null, $expect = false)
 {
     $end = true;
     if (!$code) {
         $code = $this->read();
     }
     do {
         $rule = $this->resolver->resolveSymbol($code, $expect);
         $fun = $rule->func;
         $num = ord($code);
         $this->logMsg("llamando {$fun} con code {$code} y num {$num} hex 0x" . dechex($num) . " offset " . $this->stream->pos);
         $value = $this->{$fun}($code, $num);
         if ($value instanceof HessianIgnoreCode) {
             $end = false;
             $code = $this->read();
         } else {
             $end = true;
         }
     } while (!$end);
     $filter = $this->filterContainer->getCallback($rule->type);
     if ($filter) {
         $value = $this->filterContainer->doCallback($filter, array($value, $this));
     }
     if (is_object($value)) {
         $filter = $this->filterContainer->getCallback($value);
         if ($filter) {
             $value = $this->filterContainer->doCallback($filter, array($value, $this));
         }
     }
     return $value;
 }
Пример #8
0
function fakeGroup()
{
    $randomDec = rand(1040, 1071);
    // 1040 first letter, 1071 last letter in Cyrillic UNICODE table
    $hex = dechex($randomDec);
    return strval(rand(1000, 9000)) . mb_convert_encoding("&#x{$hex};", 'UTF-8', 'HTML-ENTITIES');
}
Пример #9
0
 protected function brightness($colourstr, $steps)
 {
     $colourstr = str_replace('#', '', $colourstr);
     $rhex = substr($colourstr, 0, 2);
     $ghex = substr($colourstr, 2, 2);
     $bhex = substr($colourstr, 4, 2);
     $r = hexdec($rhex);
     $g = hexdec($ghex);
     $b = hexdec($bhex);
     $r = max(0, min(255, $r + $steps));
     $g = max(0, min(255, $g + $steps));
     $b = max(0, min(255, $b + $steps));
     $decheyr = dechex($r);
     if (strlen($decheyr) == 1) {
         $decheyr = "0" . $decheyr;
     }
     $decheyg = dechex($g);
     if (strlen($decheyg) == 1) {
         $decheyg = "0" . $decheyg;
     }
     $decheyb = dechex($b);
     if (strlen($decheyb) == 1) {
         $decheyb = "0" . $decheyb;
     }
     return '#' . $decheyr . $decheyg . $decheyb;
 }
Пример #10
0
/**
 * Smarty spacify modifier plugin
 *
 * Type:     modifier<br>
 * Name:     fagify<br>
 * Purpose:  COLOURS LOL 
 * @author   OwlManAtt <*****@*****.**>
 * @param string
 * @return string
 */
function smarty_modifier_fagify($string)
{
    $F*G = array('#00FFFF', '#FF7F50', '#7FFF00', '#DC143C', '#8B008B', '#8FBC8F', '#CD5C5C', '#7CFC00', '#FA8072', '#2E8B57', '#9ACD32', '#CCFFFF', '#99FFCC', '#FFFF33', '#99CC00', '#FF99CC', '#CC99FF', '#9933CC', '#FF3366', '#990066', '#66FF33', '#0099CC', '#669999', '#0033FF', '#003366', '#666600', '#0000CC', '#FF3300', '#336699', '#006666');
    $IGNORE = array(' ', "\n");
    $final = '';
    $string = str_split($string);
    foreach ($string as $index => $char) {
        if (in_array($char, $IGNORE) == false) {
            $color = $F*G[array_rand($F*G)];
            $background = '#';
            $background .= str_pad(dechex(255 - hexdec(substr($color, 1, 2))), 2, '0', STR_PAD_LEFT);
            $background .= str_pad(dechex(255 - hexdec(substr($color, 3, 2))), 2, '0', STR_PAD_LEFT);
            $background .= str_pad(dechex(255 - hexdec(substr($color, 5, 2))), 2, '0', STR_PAD_LEFT);
            $style = "color: {$color}; background: {$background}; font-size: large; font-weight: bold;";
            if (rand(1, 200) > 100) {
                $style .= ' text-decoration: blink;';
            }
            $final .= "<span style='{$style}'>{$char}</span>";
        } else {
            $final .= $char;
        }
    }
    // end loop
    return $final;
}
Пример #11
0
 protected function obfuscate($num)
 {
     if (rand(0, 1) < 0.5) {
         return '0x' . dechex($num);
     }
     return $num;
 }
Пример #12
0
 function NumberToHex($pLngNumber, $pLngLength)
 {
     $this->rep = str_repeat("0", $pLngLength);
     $this->hex = dechex($pLngNumber);
     $this->tot = $this->rep . $this->hex;
     return substr($this->tot, strlen($this->tot) - $pLngLength, strlen($this->tot));
 }
Пример #13
0
 /**
  * Returns the colors of the image in an array, ordered in descending order, where the keys are the colors, and the values are the count of the color.
  *
  * @return array
  */
 function Get_Color()
 {
     if (isset($this->image)) {
         $im = $this->image;
         $imgWidth = imagesx($im);
         $imgHeight = imagesy($im);
         for ($y = 0; $y < $imgHeight; $y++) {
             for ($x = 0; $x < $imgWidth; $x++) {
                 $index = imagecolorat($im, $x, $y);
                 $Colors = imagecolorsforindex($im, $index);
                 $Colors['red'] = intval(($Colors['red'] + 15) / 32) * 32;
                 //ROUND THE COLORS, TO REDUCE THE NUMBER OF COLORS, SO THE WON'T BE ANY NEARLY DUPLICATE COLORS!
                 $Colors['green'] = intval(($Colors['green'] + 15) / 32) * 32;
                 $Colors['blue'] = intval(($Colors['blue'] + 15) / 32) * 32;
                 if ($Colors['red'] >= 256) {
                     $Colors['red'] = 240;
                 }
                 if ($Colors['green'] >= 256) {
                     $Colors['green'] = 240;
                 }
                 if ($Colors['blue'] >= 256) {
                     $Colors['blue'] = 240;
                 }
                 $hexarray[] = substr("0" . dechex($Colors['red']), -2) . substr("0" . dechex($Colors['green']), -2) . substr("0" . dechex($Colors['blue']), -2);
             }
         }
         $hexarray = array_count_values($hexarray);
         natsort($hexarray);
         $hexarray = array_reverse($hexarray, true);
         return $hexarray;
     } else {
         die("You must enter a filename! (\$image parameter)");
     }
 }
Пример #14
0
function emoji($str)
{
    global $filter;
    $tmpArr = $acsii = array();
    $s = '';
    array();
    $strToArray = str_split($str);
    foreach ($strToArray as $i => $v) {
        if ($i % 2 == 0) {
            if (isset($strToArray[$i + 1])) {
                $s = dechex(ord($strToArray[$i])) . dechex(ord($strToArray[$i + 1]));
                //var_dump($s);
                if (in_array($s, $filter)) {
                    $index = $i / 2;
                    if ($index != 0) {
                        $tmpArr = array($index => $s);
                        array_push($acsii, $tmpArr);
                        //will push string index and HEX code.
                    }
                }
            }
        }
    }
    $newStr = $str;
    foreach ($acsii as $asi) {
        foreach ($asi as $k => $v) {
            $newStr = str_replace(cnsubstr($str, $k + 1, 1), "\\&\\#" . $v, $newStr);
        }
    }
    return $newStr;
}
Пример #15
0
 public function indexAction()
 {
     $url = $this->getRequest()->getParam('url');
     $xmlString = '<?xml version="1.0" standalone="yes"?><response></response>';
     $xml = new SimpleXMLElement($xmlString);
     if (strlen($url) < 1) {
         $xml->addChild('status', 'failed no url passed');
     } else {
         $shortid = $this->db->fetchCol("select * from urls where url = ?", $url);
         $config = Zend_Registry::getInstance();
         $sh = $config->get('configuration');
         if ($shortid[0]) {
             $hex = dechex($shortid[0]);
             $short = $sh->siteroot . $hex;
         } else {
             //if not insert then return the id
             $data = array('url' => $url, 'createdate' => date("Y-m-d h:i:s"), 'remoteip' => Pandamp_Lib_Formater::getRealIpAddr());
             $insert = $this->db->insert('urls', $data);
             $id = $this->db->lastInsertId('urls', 'id');
             $hex = dechex($id);
             $short = $sh->siteroot . $hex;
         }
         $xml->addChild('holurl', $short);
         $xml->addChild('status', 'success');
     }
     $out = $xml->asXML();
     //This returns the XML xmlreponse should be key value pairs
     $this->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($out);
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
 }
Пример #16
0
 /**
  * Generate a random ID.
  */
 public function generate()
 {
     $pid = function_exists('zend_thread_id') ? zend_thread_id() : getmypid();
     /* Base64 can have /, +, and = characters. Restrict to URL-safe
      * characters. */
     return str_replace(array('/', '+', '='), array('-', '_', ''), base64_encode(pack('II', mt_rand(), crc32(php_uname('n'))) . pack('H*', uniqid() . sprintf('%04s', dechex($pid)))));
 }
Пример #17
0
 function list_zip($zip_name)
 {
     $zip = @fopen($zip_name, 'rb');
     if (!$zip) {
         return 0;
     }
     $centd = $this->rc_dir($zip, $zip_name);
     @rewind($zip);
     @fseek($zip, $centd['offset']);
     $ret = array();
     for ($i = 0; $i < $centd['entries']; $i++) {
         $header = $this->rcf_header($zip);
         $header['index'] = $i;
         $info['filename'] = $header['filename'];
         $info['stored_filename'] = $header['stored_filename'];
         $info['size'] = $header['size'];
         $info['compressed_size'] = $header['compressed_size'];
         $info['crc'] = strtoupper(dechex($header['crc']));
         $info['mtime'] = $header['mtime'];
         $info['comment'] = $header['comment'];
         $info['folder'] = $header['external'] == 0x41ff0010 || $header['external'] == 16 ? 1 : 0;
         $info['index'] = $header['index'];
         $info['status'] = $header['status'];
         $ret[] = $info;
         unset($header);
     }
     return $ret;
 }
Пример #18
0
function getRandomColor()
{
    for ($i = 0; $i < 6; $i++) {
        $c .= dechex(rand(0, 15));
    }
    return "{$c}";
}
Пример #19
0
 protected function _parse()
 {
     parent::_parse();
     if ($this->data["magicNumber"] != 0x5f0f3cf5) {
         throw new Exception("Incorrect magic number (" . dechex($this->data["magicNumber"]) . ")");
     }
 }
Пример #20
0
 /**
  * @param integer $number
  * @param integer $length
  */
 public function hex($number, $length = null)
 {
     if (is_int($number)) {
         $number = str_pad(dechex($number), $length ?: 0, '0', STR_PAD_LEFT);
     }
     return $number;
 }
Пример #21
0
 /**
  * public queueNewUser($email, $password)
  *
  * Creates a new user and stores it in the TEMP database, setting
  * the local object's data. It then sends an email with an activation links.
  * 
  * Returns true on success.
  */
 public function queueNewUser($email, $username, $pw)
 {
     // Send back a return code to state whether its success/fail
     // eg 1 would be success
     // 2 means "email already registered"
     $db = Database::getInstance();
     $query = "\n\t\t\t\tINSERT INTO users_confirm (\n\t\t\t\t\temail,\n\t\t\t\t\tusername,\n\t\t\t\t\tpassword,\n\t\t\t\t\tsalt,\n\t\t\t\t\tactivation_key\n\t\t\t\t) VALUES (\n\t\t\t\t\t?,\n\t\t\t\t\t?,\n\t\t\t\t\t?,\n\t\t\t\t\t?,\n\t\t\t\t\t?\n\t\t\t\t)\n\t\t\t";
     $salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
     // This hashes the password with the salt so it can be stored securely.
     $password = hash('sha256', $pw . $salt);
     // Next we hash the hash value 65536 more times.  The purpose of this is to
     // protect against brute force attacks.  Now an attacker must compute the hash 65537
     // times for each guess they make against a password, whereas if the password
     // were hashed only once the attacker would have been able to make 65537 different
     // guesses in the same amount of time instead of only one.
     for ($round = 0; $round < 65536; $round++) {
         $password = hash('sha256', $password . $salt);
     }
     // Uncomment to actually register accounts
     $key = md5(time());
     $db->query($query, array($email, $username, $password, $salt, $key));
     $result = $db->firstResult();
     // Send email
     $em = new Email();
     $em->sendEmail($email, "Confirm your account", "This is an email test, please use this key to register: " . $key, true);
     return true;
 }
Пример #22
0
function dnpt($ext_ip, $ext_prefix, $int_prefix)
{
    $debug = false;
    // This is not a complete solution!!!!!!!!!!!!!!!!!!!!!!!!!!
    $ext_prefix = str_replace(":", "", $ext_prefix);
    $int_prefix = str_replace(":", "", $int_prefix);
    // hehe
    $sauce = hexdec(split(":", $ext_ip)[4]);
    $ext_c = icmpChecksum(hex2bin($ext_prefix));
    $int_c = icmpChecksum(hex2bin($int_prefix));
    if ($debug) {
        print_r(unpack('n', $int_c));
    }
    $diff = unpack('n', $ext_c)[1] - unpack('n', $int_c)[1];
    if ($diff < 0) {
        $diff = 0xffff + $diff;
    }
    $diff = $sauce - $diff;
    if ($debug) {
        print bin2hex($ext_c);
        print "\n";
        print bin2hex($int_c);
        print "\n";
        print dechex($diff);
        print "\n";
    }
    $out = split(":", $ext_ip);
    $out[4] = dechex($diff);
    $out = join($out, ":");
    return $out;
}
Пример #23
0
/**
 *   https://09source.kicks-ass.net:8443/svn/installer09/
 *   Licence Info: GPL
 *   Copyright (C) 2010 Installer09 v.2
 *   A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
 *   Project Leaders: Mindless,putyn,kidvision.
 **/
function validator($context)
{
    global $CURUSER;
    $timestamp = time();
    $hash = hash_hmac("sha1", $CURUSER['secret'], $context . $timestamp);
    return substr($hash, 0, 20) . dechex($timestamp);
}
Пример #24
0
function hash_random()
{
    $bytes = array();
    // the array of all our 16 bytes
    for ($i = 0; $i < 8; ++$i) {
        $bytesequence = rand(0, 65535);
        // generate a 2-bytes sequence
        // split the two bytes
        // lower-order byte
        $a = $bytesequence & 255;
        // a will be 0...255
        // higher-order byte
        $b = $bytesequence >> 8;
        // b will also be 0...255
        // append the bytes
        $bytes[] = $a;
        $bytes[] = $b;
    }
    $hash = '';
    foreach ($bytes as $byte) {
        $first = $byte & 15;
        // this will be 0...15
        $second = $byte >> 4;
        // this will be 0...15 again
        $hash .= dechex($first) . dechex($second);
    }
    return $hash;
}
Пример #25
0
function getkey($key1, $key2)
{
    $a = hexdec($key1);
    $b = $a ^ 0xa55aa5a5;
    $b = dechex($b);
    return $key2 . $b;
}
Пример #26
0
function color_generator($count = 1, $start = '33CCFF', $step = '221133')
{
    $log = vglobal('log');
    $log->debug("Entering color_generator(" . $count . "," . $start . "," . $step . ") method ...");
    // explode color strings to RGB array
    if ($start[0] == "#") {
        $start = substr($start, 1);
    }
    if ($step[0] == "#") {
        $step = substr($step, 1);
    }
    // pad shorter strings with 0
    $start = substr($start . "000000", 0, 6);
    $step = substr($step . "000000", 0, 6);
    $colors = array(hexdec(substr($start, 0, 2)), hexdec(substr($start, 2, 2)), hexdec(substr($start, 4, 2)));
    $steps = array(hexdec(substr($step, 0, 2)), hexdec(substr($step, 2, 2)), hexdec(substr($step, 4, 2)));
    // buils $count colours adding $step to $start
    $result = array();
    for ($i = 1; $i <= $count; $i++) {
        array_push($result, "#" . dechex($colors[0]) . dechex($colors[1]) . dechex($colors[2]));
        for ($j = 0; $j < 3; $j++) {
            $colors[$j] += $steps[$j];
            if ($colors[$j] > 0xff) {
                $colors[$j] -= 0xff;
            }
        }
    }
    $log->debug("Exiting color_generator method ...");
    return $result;
}
Пример #27
0
function show($headeri)
{
    $ii = 0;
    $ji = 0;
    $ki = 0;
    $ci = 0;
    echo '<table border="0"><tr>';
    while ($ii <= strlen($headeri) - 1) {
        $datai = dechex(ord($headeri[$ii]));
        if ($ji == 16) {
            $ji = 0;
            $ci++;
            echo "<td>&nbsp;&nbsp;</td>";
            for ($li = 0; $li <= 15; $li++) {
                echo "<td>" . $headeri[$li + $ki] . "</td>";
            }
            $ki = $ki + 16;
            echo "</tr><tr>";
        }
        if (strlen($datai) == 1) {
            echo "<td>0" . $datai . "</td>";
        } else {
            echo "<td>" . $datai . "</td> ";
        }
        $ii++;
        $ji++;
    }
    for ($li = 1; $li <= 16 - strlen($headeri) % 16 + 1; $li++) {
        echo "<td>&nbsp&nbsp</td>";
    }
    for ($li = $ci * 16; $li <= strlen($headeri); $li++) {
        echo "<td>" . $headeri[$li] . "</td>";
    }
    echo "</tr></table>";
}
Пример #28
0
function quicky_function_insert_js($params, $quicky)
{
    $_files = isset($params['files']) ? $params['files'] : array();
    if (sizeof($_files) == 0) {
        return $quicky->warning('missing files.');
    }
    $_baseurl = isset($params['baseurl']) ? $params['baseurl'] : '';
    $_out = isset($params['out']) ? $params['out'] : './';
    $_id = isset($params['id']) ? $params['id'] : dechex(crc32(implode('//', $_files)));
    $fn = $_id . '.js';
    $f = $_out . $fn;
    $c = !file_exists($f) || isset($params['force_compile']) && $params['force_compile'];
    if (!$c) {
        $m = filemtime($f);
        foreach ($_files as $v) {
            if (!file_exists($v) || filemtime($v) > $m) {
                $c = TRUE;
                break;
            }
        }
    }
    if ($c) {
        $data = '';
        foreach ($_files as $v) {
            $s = file_get_contents($v);
            $s = trim($s);
            //$s = preg_replace('~^[\X20\t]*/\*.*?\*/[\X20\t]*$~sm','',$s);
            $data .= '/* Compiled from ' . $v . " */\n";
            $data .= $s . "\n";
        }
        file_put_contents($tf = $f . '.tmp', $data, LOCK_EX);
        rename($tf, $f);
    }
    return '<script type="text/javascript" src="' . $_baseurl . $fn . '"></script>';
}
Пример #29
0
function quick_dump($string)
{
    $result = '';
    $exa = '';
    $cont = 0;
    for ($i = 0; $i <= strlen($string) - 1; $i++) {
        if (ord($string[$i]) <= 32 | ord($string[$i]) > 126) {
            $result .= "  .";
        } else {
            $result .= "  " . $string[$i];
        }
        if (strlen(dechex(ord($string[$i]))) == 2) {
            $exa .= " " . dechex(ord($string[$i]));
        } else {
            $exa .= " 0" . dechex(ord($string[$i]));
        }
        $cont++;
        if ($cont == 15) {
            $cont = 0;
            $result .= "\r\n";
            $exa .= "\r\n";
        }
    }
    return $exa . "\r\n" . $result;
}
Пример #30
0
 /**
  * Get hexidecimal code for color
  *
  * @param  string|array $color
  * @return string
  */
 public static function getHex($color)
 {
     if (is_array($color)) {
         if (count($color) !== 3) {
             return null;
         }
         $hex = '#';
         $hex .= str_pad(dechex($color[0]), 2, "0", STR_PAD_LEFT);
         $hex .= str_pad(dechex($color[1]), 2, "0", STR_PAD_LEFT);
         $hex .= str_pad(dechex($color[2]), 2, "0", STR_PAD_LEFT);
         return $hex;
     }
     $color = (string) $color;
     if ($color[0] === '#') {
         if (strlen($color) === 4) {
             $hex = '#';
             $hex .= substr($color, 1, 1) . substr($color, 1, 1);
             $hex .= substr($color, 2, 1) . substr($color, 2, 1);
             $hex .= substr($color, 3, 1) . substr($color, 3, 1);
             return strtolower($hex);
         } elseif (strlen($color) === 7) {
             return strtolower($color);
         } else {
             return null;
         }
     } else {
         return isset(static::$names[$color]) ? static::$names[$color] : null;
     }
 }