Blame view
sources/apps/documents/lib/helper.php
4.01 KB
|
d1bafeea1
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
<?php
/**
* ownCloud - Documents App
*
* @author Victor Dubiniuk
* @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
namespace OCA\Documents;
class Helper {
const APP_ID = 'documents';
public static function getNewFileName($view, $path, $prepend = ' '){
$fileNum = 1;
while ($view->file_exists($path)){
$fileNum += 1;
$path = preg_replace('/(\.odt|' . $prepend . '\(\d+\)\.odt)$/', $prepend . '(' . $fileNum . ').odt', $path);
};
return $path;
}
public static function getArrayValueByKey($array, $key, $default=''){
if (array_key_exists($key, $array)){
return $array[$key];
}
return $default;
}
public static function isVersionsEnabled(){
return \OCP\App::isEnabled('files_versions');
}
public static function getRandomColor(){
$str = dechex(floor(rand(0, 16777215)));
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){
self::log($message, \OCP\Util::DEBUG);
}
public static function warnLog($message){
self::log($message, \OCP\Util::WARN);
}
public static function errorLog($message){
self::log($message, \OCP\Util::ERROR);
}
public static function log($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;
}
|
|
6d9380f96
|
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
public static function findOpenOffice(){
$cmd = '';
if (is_string(\OC_Config::getValue('preview_libreoffice_path', null))){
$cmd = \OC_Config::getValue('preview_libreoffice_path', null);
}
$whichLibreOffice = shell_exec('which libreoffice');
if ($cmd === '' && !empty($whichLibreOffice)){
$cmd = 'libreoffice';
}
$whichOpenOffice = shell_exec('which openoffice');
if ($cmd === '' && !empty($whichOpenOffice)){
$cmd = 'openoffice';
}
if (empty($cmd)){
Helper::warnLog('Pure configuration issue. Missing open office binary that is mandatory for conversion.');
Helper::debugLog('If openoffice or libreoffice is already installed please specify the path to it using preview_libreoffice_path config. Refer to admin manual for details.');
throw new \RuntimeException('Missing open office binary that is mandatory for conversion.');
}
return $cmd;
}
|
|
d1bafeea1
|
175 176 |
} |