8 $usage->setDefinitionText(
"apply given style - if no style is set then update current style");
14 $defautStyle =
$action->getParam(
"STYLE");
15 $styFilePath = sprintf(
"STYLE/%s/%s.sty", $defautStyle, $defautStyle);
17 $verbose = (
'yes' ===
$usage->addOptionalParameter(
'verbose',
'verbose', array(
39 protected function log($msg)
42 print str_repeat(
"\t", $this->logIndent) .
" -- " . $msg . PHP_EOL;
61 $this->
log(
"load style definition from $styFilePath");
64 $msg =
"sty file [$styFilePath] does not exists";
66 $msg =
"sty file [$styFilePath] is not readable";
68 throw new \Dcp\Style\Exception(
"STY0001", $msg);
73 $styleDefinition = array(
74 "sty_desc" => empty($sty_desc) ? array() : $sty_desc,
75 "sty_const" => empty($sty_const) ? array() : $sty_const,
76 "sty_colors" => empty($sty_colors) ? array() : $sty_colors,
77 "sty_local" => empty($sty_local) ? array() : $sty_local,
78 "sty_rules" => empty($sty_rules) ? array() : $sty_rules
81 if (!isset($styleDefinition[
'sty_desc']) || !isset($styleDefinition[
'sty_desc'][
'name'])) {
82 throw new \Dcp\Style\Exception(
"STY0002",
"Style definition does not contains style name");
85 if (!empty($sty_inherit)) {
86 $this->
log(
"using parent style file: $sty_inherit");
89 $styleDefinition = array_replace_recursive($parentStyleDefinition, $styleDefinition);
93 $customRulesDirPath = dirname($styFilePath) . DIRECTORY_SEPARATOR . self::CUSTOM_RULES_DIR_NAME;
94 if (is_dir($customRulesDirPath) && is_readable($customRulesDirPath)) {
95 $customRules = & $styleDefinition[
'sty_rules'];
96 $customRulesFiles = scandir($customRulesDirPath);
97 if (
false !== $customRulesFiles) {
98 foreach ($customRulesFiles as $customRulesFile) {
99 if ($customRulesFile ==
'.' || $customRulesFile ==
'..')
continue;
100 $customRules = array_replace_recursive($customRules, $this->
loadCustomRulesFromFile($customRulesDirPath . DIRECTORY_SEPARATOR . $customRulesFile));
105 $globalRulesDirPath = dirname(dirname($styFilePath)) . DIRECTORY_SEPARATOR . self::GLOBAL_RULES_DIR_NAME;
106 if (is_dir($globalRulesDirPath) && is_readable($globalRulesDirPath)) {
107 $globalRules = & $styleDefinition[
'sty_rules'];
108 $globalRulesFiles = scandir($globalRulesDirPath);
109 if (
false !== $globalRulesFiles) {
110 foreach ($globalRulesFiles as $globalRulesFile) {
111 if ($globalRulesFile ==
'.' || $globalRulesFile ==
'..')
continue;
112 $globalRules = array_replace_recursive($globalRules, $this->
loadCustomRulesFromFile($globalRulesDirPath . DIRECTORY_SEPARATOR . $globalRulesFile));
117 return $styleDefinition;
123 $this->
log(
"load custom rules from $customRulesFilePath");
124 if (!is_readable($customRulesFilePath)) {
125 if (!file_exists($customRulesFilePath)) {
126 $msg =
"$customRulesFilePath does not exists";
128 $msg =
"$customRulesFilePath is not readable";
130 throw new \Dcp\ApiUsage\Exception(
"FILE0011", $msg);
133 require $customRulesFilePath;
134 return empty($sty_rules) ? array() : $sty_rules;
143 require_once
"Lib.Color.php";
145 $computedColors = array();
148 throw new \Dcp\Style\Exception(
"STY0002",
"Style definition does not contains sty_colors");
155 if (isset($sty_const[
"COLOR_WHITE"])) {
156 $whiteHsl =
srgb2hsl($sty_const[
"COLOR_WHITE"]);
158 if (!empty($whiteHsl)) {
159 $darkStyle = ($whiteHsl[2] < 0.5);
161 foreach ($styleBaseColors as $colorKey => $baseColor) {
162 $baseColorHsl =
srgb2hsl($baseColor);
163 $baseHue = $baseColorHsl[0];
164 $baseSaturation = $baseColorHsl[1];
165 $baseLuminance = $baseColorHsl[2];
167 $luminanceStep = (0 - $baseLuminance) / 10;
169 $luminanceStep = (1 - $baseLuminance) / 10;
171 $computedColors[$colorKey] = array();
172 $currentStepLuminance = $baseColorHsl[2];
173 for ($i = 0; $i < 10; $i++) {
174 $currentStepColor =
HSL2RGB($baseHue, $baseSaturation, $currentStepLuminance);
175 $computedColors[$colorKey][$i] = $currentStepColor;
176 $currentStepLuminance+= $luminanceStep;
185 public function applyStyle()
190 throw new \Dcp\Style\Exception(
"STY0002",
"Style definition does not contains name");
196 $style =
new Style(
'', $styleName);
197 $style->description = empty(
$styleConfig[
'sty_desc'][
'description']) ?
'' :
$styleConfig[
'sty_desc'][
'description'];
199 print "\n[WARNING] use of parsable property on style is deprecated\n\n";
200 $style->parsable = ((
'Y' ===
$styleConfig[
'sty_desc'][
'parsable']) ?
'Y' :
'N');
203 if (!$style->isAffected()) {
204 $style->name = $styleName;
205 $err = $style->Add();
207 throw new \Dcp\Style\Exception(
"STY0003",
"error when registering style");
210 $err = $style->modify();
212 throw new \Dcp\Style\Exception(
"STY0003",
"error when modifying style");
215 $this->
log(
"delete previous style parameters");
218 $oldParamList =
$query->Query();
219 if (!empty($oldParamList)) {
220 foreach ($oldParamList as $oldParam) {
228 $this->
log(
"register color params");
229 $this->logIndent+= 1;
230 foreach (
$styleConfig[
'computed_colors'] as $colorClass => $colorList) {
231 foreach ($colorList as $colorIndex => $color) {
232 $paramName =
"COLOR_{$colorClass}{$colorIndex}";
235 if (!empty($dynamicColorValue)) {
236 $this->
log(
"dynamic value " . var_export($dynamicColorValue,
true) .
" set for $paramName ($color)");
237 $color = $dynamicColorValue;
239 $this->
log(
"static value " . var_export($color,
true) .
" set for $paramName ($color)");
241 $param->Set($paramName, $color, $paramType, 1);
242 $this->action->parent->SetVolatileParam($paramName, $color);
246 $this->logIndent-= 1;
248 $this->
log(
"register other params");
249 $this->logIndent+= 1;
250 foreach (
$styleConfig[
'sty_const'] as $paramName => $paramValue) {
253 if (!empty($dynamicParamValue)) {
254 $this->
log(
"dynamic value " . var_export($dynamicParamValue,
true) .
" set for $paramName ($paramValue)");
255 $paramValue = $dynamicParamValue;
257 $this->
log(
"static value " . var_export($paramValue,
true) .
" set for $paramName ($paramValue)");
259 $param->Set($paramName, $paramValue, $paramType, 1);
260 $this->action->parent->SetVolatileParam($paramName, $paramValue);
263 $this->logIndent-= 1;
265 $this->
log(
"declare volatile params");
266 $this->logIndent+= 1;
267 foreach (
$styleConfig[
'sty_local'] as $paramName => $paramValue) {
270 if (!empty($dynamicParamValue)) {
271 $this->
log(
"dynamic value " . var_export($dynamicParamValue,
true) .
" used for $paramName ($paramValue)");
272 $paramValue = $dynamicParamValue;
274 $this->
log(
"static value " . var_export($paramValue,
true) .
" used for $paramName ($paramValue)");
276 $this->action->parent->SetVolatileParam($paramName, $paramValue);
279 $this->logIndent-= 1;
284 $err = $style->modify();
286 throw new \Dcp\Style\Exception(
"STY0003",
"error when modifying style");
293 $this->
log(
"deploy style files");
294 $this->logIndent+= 1;
296 $filesDefinition = array();
297 $cssRules = empty($rules[
'css']) ? array() : $rules[
'css'];
298 $filesDefinition[
'css'] = $this->deployStyleCssFiles($cssRules,
'css');
300 $this->logIndent-= 1;
302 return $filesDefinition;
305 protected function deployStyleCssFiles(Array $cssRules, $targetDirName)
307 $this->
log(
"deploy css files");
308 $filesDefinition = array();
311 $targetDir = $pubDir . DIRECTORY_SEPARATOR . $targetDirName;
316 $this->logIndent+= 1;
317 foreach ($cssRules as $targetFile => $rule) {
318 $this->
log(
"processing rules for $targetFile");
320 if (empty($rule[
'src'])) {
321 throw new \Dcp\Style\Exception(
"STY0002",
"rule for $targetFile does not contains src");
325 $destFile = $targetDirName . DIRECTORY_SEPARATOR . $targetFile;
327 $deployParserClass = self::DEFAULT_CSS_PARSER_DEPLOY_CLASS;
328 $deployParserOptions = array();
329 if (!empty($rule[
'deploy_parser'])) {
330 if (!empty($rule[
'deploy_parser'][
'className'])) {
331 $deployParserClass = $rule[
'deploy_parser'][
'className'];
333 if (!empty($rule[
'deploy_parser'][
'options'])) {
334 $deployParserOptions = $rule[
'deploy_parser'][
'options'];
337 $this->
log(
"parsing $targetFile using $deployParserClass");
338 $classInterfaces = class_implements($deployParserClass,
true);
339 if (!isset($classInterfaces[
'Dcp\Style\ICssParser'])) {
340 throw new \Dcp\Style\Exception(
"STY0006",
"class $deployParserClass does not implements \\Dcp\\Style\\ICssParser");
342 $this->
log(print_r($src,
true));
344 $parser =
new $deployParserClass($src, $deployParserOptions, $this->styleConfig);
345 $parser->gen($destFile);
347 $this->logIndent-= 1;
349 return $filesDefinition;
354 if (!file_exists(
$dir))
return true;
355 if (!is_dir(
$dir) || is_link(
$dir))
return unlink(
$dir);
356 foreach (scandir(
$dir) as $item) {
357 if ($item ==
'.' || $item ==
'..')
continue;
359 chmod(
$dir .
"/" . $item, 0777);
const DEFAULT_CSS_PARSER_RUNTIME_CLASS
const DEFAULT_CSS_PARSER_DEPLOY_CLASS
computeStyleColors($styleDefinition)
deployStyleFiles(Array $rules)
static getScopedParameterValue($parameter)
const GLOBAL_RULES_DIR_NAME
if(!$styFilePath) $verbose
loadStyleDefinition($styFilePath)
static setCommonParameterValue($application, $parameterName, $value)
__construct(Action $action)
const CUSTOM_RULES_DIR_NAME
if(($docid!==0)&&(!is_numeric($docid))) $query
if($file) if($subject==""&&$file) if($subject=="") $err
loadCustomRulesFromFile($customRulesFilePath)
Verify arguments for wsh programs.