forked from Wavyzz/dolibarr
Add color lib for color automation
This commit is contained in:
@@ -7849,6 +7849,7 @@ function getDictvalue($tablename, $field, $id, $checkentity = false, $rowidfield
|
||||
*/
|
||||
function colorIsLight($stringcolor)
|
||||
{
|
||||
$stringcolor = str_replace('#', '', $stringcolor);
|
||||
$res = -1;
|
||||
if (!empty($stringcolor))
|
||||
{
|
||||
|
||||
@@ -2200,6 +2200,105 @@ function colorStringToArray($stringcolor, $colorifnotfound = array(88,88,88))
|
||||
return array(hexdec($reg[1]),hexdec($reg[2]),hexdec($reg[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $color
|
||||
* @param boolean $allow_white
|
||||
* @return boolean
|
||||
*/
|
||||
function colorValidateHex($color, $allow_white = false)
|
||||
{
|
||||
|
||||
if(!$allow_white && ($color === '#fff' || $color === '#ffffff') ) return false;
|
||||
|
||||
if(preg_match('/^#[a-f0-9]{6}$/i', $color)) //hex color is valid
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $hex
|
||||
* @param integer $steps
|
||||
* @return string
|
||||
*/
|
||||
function colorAdjustBrightness($hex, $steps) {
|
||||
// Steps should be between -255 and 255. Negative = darker, positive = lighter
|
||||
$steps = max(-255, min(255, $steps));
|
||||
|
||||
// Normalize into a six character long hex string
|
||||
$hex = str_replace('#', '', $hex);
|
||||
if (strlen($hex) == 3) {
|
||||
$hex = str_repeat(substr($hex,0,1), 2).str_repeat(substr($hex,1,1), 2).str_repeat(substr($hex,2,1), 2);
|
||||
}
|
||||
|
||||
// Split into three parts: R, G and B
|
||||
$color_parts = str_split($hex, 2);
|
||||
$return = '#';
|
||||
|
||||
foreach ($color_parts as $color) {
|
||||
$color = hexdec($color); // Convert to decimal
|
||||
$color = max(0,min(255,$color + $steps)); // Adjust color
|
||||
$return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $hex
|
||||
* @param integer $percent 0 to 100
|
||||
* @return string
|
||||
*/
|
||||
function colorDarker($hex, $percent) {
|
||||
$steps = intval(255 * $percent / 100 ) * -1;
|
||||
return colorAdjustBrightness($hex, $steps);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $hex
|
||||
* @param integer $percent 0 to 100
|
||||
* @return string
|
||||
*/
|
||||
function colorLighten($hex, $percent) {
|
||||
$steps = intval(255 * $percent / 100 );
|
||||
return colorAdjustBrightness($hex, $steps);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $hex
|
||||
* @param float $alpha 0 to 1
|
||||
* @param bool $returnArray :
|
||||
* @return string
|
||||
*/
|
||||
function colorHexToRgb($hex, $alpha = false, $returnArray = false) {
|
||||
$string = '';
|
||||
$hex = str_replace('#', '', $hex);
|
||||
$length = strlen($hex);
|
||||
$rgb = array();
|
||||
$rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0));
|
||||
$rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0));
|
||||
$rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1), 2) : 0));
|
||||
if ( $alpha !== false ) {
|
||||
$rgb['a'] = floatval($alpha);
|
||||
$string = 'rgba('.implode(',', $rgb ).')';
|
||||
}
|
||||
else{
|
||||
$string = 'rgb('.implode(',', $rgb ).')';
|
||||
}
|
||||
|
||||
if($returnArray){
|
||||
return $rgb;
|
||||
}
|
||||
else{
|
||||
return $string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Applies the Cartesian product algorithm to an array
|
||||
* Source: http://stackoverflow.com/a/15973172
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
<?php
|
||||
if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?>
|
||||
/* <style type="text/css" > */
|
||||
/*
|
||||
Badge style is based on boostrap framework
|
||||
*/
|
||||
|
||||
if (! defined('ISLOADEDBYSTEELSHEET')) die('Must be call by steelsheet'); ?>
|
||||
/* <style type="text/css" > */
|
||||
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: .25em .4em;
|
||||
@@ -30,6 +28,10 @@ a.badge:focus, a.badge:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* PRIMARY */
|
||||
.badge-primary{
|
||||
color: #fff !important;
|
||||
@@ -37,11 +39,11 @@ a.badge:focus, a.badge:hover {
|
||||
}
|
||||
a.badge-primary.focus, a.badge-primary:focus {
|
||||
outline: 0;
|
||||
box-shadow: 0 0 0 0.2rem rgba(0,123,255,.5);
|
||||
box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgePrimary, 0.5); ?>;
|
||||
}
|
||||
a.badge-primary:focus, a.badge-primary:hover {
|
||||
color: #fff !important;
|
||||
background-color: #0062cc;
|
||||
background-color: <?php print colorDarker($badgePrimary, 10); ?>;
|
||||
}
|
||||
|
||||
/* SECONDARY */
|
||||
@@ -51,11 +53,11 @@ a.badge-primary:focus, a.badge-primary:hover {
|
||||
}
|
||||
a.badge-secondary.focus, a.badge-secondary:focus {
|
||||
outline: 0;
|
||||
box-shadow: 0 0 0 0.2rem rgba(108,117,125,.5);
|
||||
box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSecondary, 0.5); ?>;
|
||||
}
|
||||
a.badge-secondary:focus, a.badge-secondary:hover {
|
||||
color: #fff !important;
|
||||
background-color: #545b62;
|
||||
background-color: <?php print colorDarker($badgeSecondary, 10); ?>;
|
||||
}
|
||||
|
||||
/* SUCCESS */
|
||||
@@ -141,3 +143,8 @@ a.badge-dark:focus, a.badge-dark:hover {
|
||||
color: #fff !important;
|
||||
background-color: #1d2124;
|
||||
}
|
||||
|
||||
/*
|
||||
* STATUS BADGES
|
||||
*/
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ if (! defined('NOLOGIN')) define('NOLOGIN', 1); // File must be
|
||||
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1);
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
|
||||
|
||||
|
||||
// Colors
|
||||
$colorbackhmenu1='60,70,100'; // topmenu
|
||||
$colorbackvmenu1='248,248,248'; // vmenu
|
||||
@@ -60,6 +61,38 @@ $topMenuFontSize='1.1em';
|
||||
$toolTipBgColor='rgba(255, 255, 255, 0.96);';
|
||||
$toolTipFontColor='#333';
|
||||
|
||||
// Badges colors
|
||||
$badgePrimary ='#007bff';
|
||||
$badgeSecondary ='#6c757d';
|
||||
$badgeSuccess ='#28a745';
|
||||
$badgeDanger ='#dc3545';
|
||||
$badgeWarning ='#ffc107';
|
||||
$badgeInfo ='#17a2b8';
|
||||
$badgeDark ='#343a40';
|
||||
$badgeLight ='#f8f9fa';
|
||||
|
||||
|
||||
|
||||
/* default color for status : After a quick check, somme status can have oposite function according to objects
|
||||
* So this badges status uses default value according to theme eldy status img
|
||||
* TODO: use color definition vars above for define badges color status X
|
||||
*/
|
||||
$badgeStatus0='#cbd3d3';
|
||||
$badgeStatus1='#bc9526';
|
||||
$badgeStatus2='#e6f0f0';
|
||||
$badgeStatus3='#bca52b';
|
||||
$badgeStatus4='#277d1e';
|
||||
$badgeStatus5='#cad2d2';
|
||||
$badgeStatus6='#cad2d2';
|
||||
$badgeStatus7='#baa32b';
|
||||
$badgeStatus8='#be3013';
|
||||
$badgeStatus9='#e7f0f0';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (defined('THEME_ONLY_CONSTANT')) return;
|
||||
|
||||
session_cache_limiter('public');
|
||||
@@ -246,4 +279,8 @@ print 'dol_screenwidth='.$_SESSION['dol_screenwidth']."\n";
|
||||
print 'dol_screenheight='.$_SESSION['dol_screenheight']."\n";
|
||||
print 'fontsize='.$fontsize."\n";
|
||||
print 'nbtopmenuentries='.$nbtopmenuentries."\n";
|
||||
print 'fontsizesmaller='.$fontsizesmaller;
|
||||
print 'topMenuFontSize='.$topMenuFontSize."\n";
|
||||
print 'toolTipBgColor='.$toolTipBgColor."\n";
|
||||
print 'toolTipFontColor='.$toolTipFontColor."\n";
|
||||
print '*/'."\n";
|
||||
|
||||
Reference in New Issue
Block a user