Uid based colors. Closes #112
This commit is contained in:
parent
3d82c1a0f7
commit
5220b5810d
@ -64,7 +64,7 @@ class Db_Session extends \OCA\Documents\Db {
|
|||||||
->getData()
|
->getData()
|
||||||
;
|
;
|
||||||
|
|
||||||
$memberColor = Helper::getRandomColor();
|
$memberColor = Helper::getMemberColor($uid);
|
||||||
|
|
||||||
$member = new Db_Member(array(
|
$member = new Db_Member(array(
|
||||||
$session['es_id'],
|
$session['es_id'],
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ownCloud - Documents App
|
* ownCloud - Documents App
|
||||||
*
|
*
|
||||||
@ -11,7 +12,7 @@
|
|||||||
|
|
||||||
namespace OCA\Documents;
|
namespace OCA\Documents;
|
||||||
|
|
||||||
class Helper{
|
class Helper {
|
||||||
|
|
||||||
const APP_ID = 'documents';
|
const APP_ID = 'documents';
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ class Helper{
|
|||||||
|
|
||||||
while ($view->file_exists($path)){
|
while ($view->file_exists($path)){
|
||||||
$fileNum += 1;
|
$fileNum += 1;
|
||||||
$path = preg_replace('/(\.odt|' . $prepend . '\(\d+\)\.odt)$/', $prepend . '(' .$fileNum . ').odt', $path);
|
$path = preg_replace('/(\.odt|' . $prepend . '\(\d+\)\.odt)$/', $prepend . '(' . $fileNum . ').odt', $path);
|
||||||
};
|
};
|
||||||
|
|
||||||
return $path;
|
return $path;
|
||||||
@ -35,6 +36,13 @@ class Helper{
|
|||||||
return '#' . str_pad($str, 6, "0", STR_PAD_LEFT);
|
return '#' . str_pad($str, 6, "0", STR_PAD_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getMemberColor($name){
|
||||||
|
$hash = md5($name);
|
||||||
|
$maxRange = hexdec('ffffffffffffffffffffffffffffffff');
|
||||||
|
$hue = hexdec($hash) / $maxRange * 256;
|
||||||
|
return '#' . self::convertHSLToRGB($hue, 90, 60);
|
||||||
|
}
|
||||||
|
|
||||||
public static function debugLog($message){
|
public static function debugLog($message){
|
||||||
self::log($message, \OCP\Util::DEBUG);
|
self::log($message, \OCP\Util::DEBUG);
|
||||||
}
|
}
|
||||||
@ -50,4 +58,87 @@ class Helper{
|
|||||||
public static function log($message, $level){
|
public static function log($message, $level){
|
||||||
\OCP\Util::writeLog(self::APP_ID, $message, $level);
|
\OCP\Util::writeLog(self::APP_ID, $message, $level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function convertHSLToRGB($iH, $iS, $iV){
|
||||||
|
if ($iH < 0){
|
||||||
|
$iH = 0; // Hue:
|
||||||
|
}
|
||||||
|
if ($iH > 360){
|
||||||
|
$iH = 360; // 0-360
|
||||||
|
}
|
||||||
|
if ($iS < 0){
|
||||||
|
$iS = 0; // Saturation:
|
||||||
|
}
|
||||||
|
if ($iS > 100){
|
||||||
|
$iS = 100; // 0-100
|
||||||
|
}
|
||||||
|
if ($iV < 0){
|
||||||
|
$iV = 0; // Lightness:
|
||||||
|
}
|
||||||
|
if ($iV > 100){
|
||||||
|
$iV = 100; // 0-100
|
||||||
|
}
|
||||||
|
|
||||||
|
$dS = $iS / 100.0; // Saturation: 0.0-1.0
|
||||||
|
$dV = $iV / 100.0; // Lightness: 0.0-1.0
|
||||||
|
$dC = $dV * $dS; // Chroma: 0.0-1.0
|
||||||
|
$dH = $iH / 60.0; // H-Prime: 0.0-6.0
|
||||||
|
$dT = $dH; // Temp variable
|
||||||
|
|
||||||
|
while ($dT >= 2.0)
|
||||||
|
$dT -= 2.0; // php modulus does not work with float
|
||||||
|
$dX = $dC * (1 - abs($dT - 1)); // as used in the Wikipedia link
|
||||||
|
|
||||||
|
switch ($dH){
|
||||||
|
case($dH >= 0.0 && $dH < 1.0):
|
||||||
|
$dR = $dC;
|
||||||
|
$dG = $dX;
|
||||||
|
$dB = 0.0;
|
||||||
|
break;
|
||||||
|
case($dH >= 1.0 && $dH < 2.0):
|
||||||
|
$dR = $dX;
|
||||||
|
$dG = $dC;
|
||||||
|
$dB = 0.0;
|
||||||
|
break;
|
||||||
|
case($dH >= 2.0 && $dH < 3.0):
|
||||||
|
$dR = 0.0;
|
||||||
|
$dG = $dC;
|
||||||
|
$dB = $dX;
|
||||||
|
break;
|
||||||
|
case($dH >= 3.0 && $dH < 4.0):
|
||||||
|
$dR = 0.0;
|
||||||
|
$dG = $dX;
|
||||||
|
$dB = $dC;
|
||||||
|
break;
|
||||||
|
case($dH >= 4.0 && $dH < 5.0):
|
||||||
|
$dR = $dX;
|
||||||
|
$dG = 0.0;
|
||||||
|
$dB = $dC;
|
||||||
|
break;
|
||||||
|
case($dH >= 5.0 && $dH < 6.0):
|
||||||
|
$dR = $dC;
|
||||||
|
$dG = 0.0;
|
||||||
|
$dB = $dX;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$dR = 0.0;
|
||||||
|
$dG = 0.0;
|
||||||
|
$dB = 0.0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dM = $dV - $dC;
|
||||||
|
$dR += $dM;
|
||||||
|
$dG += $dM;
|
||||||
|
$dB += $dM;
|
||||||
|
$dR *= 255;
|
||||||
|
$dG *= 255;
|
||||||
|
$dB *= 255;
|
||||||
|
|
||||||
|
$dR = str_pad(dechex(round($dR)), 2, "0", STR_PAD_LEFT);
|
||||||
|
$dG = str_pad(dechex(round($dG)), 2, "0", STR_PAD_LEFT);
|
||||||
|
$dB = str_pad(dechex(round($dB)), 2, "0", STR_PAD_LEFT);
|
||||||
|
return $dR.$dG.$dB;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user