Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
import_style.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * update list of available style
9  *
10  * analyze sub-directories presents in STYLE directory
11  * @author Anakeen 2002
12  * @version $Id: import_style.php,v 1.10 2007/02/21 11:07:12 eric Exp $
13  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
14  * @package FDL
15  * @subpackage WSH
16  */
17 /**
18  */
19 
20 include_once ("Class.Style.php");
21 include_once ("Lib.Color.php");
22 
23 function getStyleInherit($name, &$sty_colorsh, &$sty_consth, &$sty_localsh)
24 {
25  if (file_exists(GetParam("CORE_PUBDIR", DEFAULT_PUBDIR) . "/STYLE/{$name}/{$name}.sty")) {
26  // global $sty_desc,$sty_const,$sty_colors,$sty_local;
27  include ("STYLE/{$name}/{$name}.sty");
28 
29  $sty_consth = $sty_const;
30  $sty_colorsh = $sty_colors;
31  $sty_localsh = $sty_local;
32  }
33 }
34 
35 $name = GetHttpVars("name");
36 $html = (GetHttpVars("html") != "");
37 $thparam = array(); // array of inherited paramters
38 $param = new Param();
39 
40 if (file_exists($action->GetParam("CORE_PUBDIR", DEFAULT_PUBDIR) . "/STYLE/{$name}/{$name}.sty")) {
41  // global $sty_desc,$sty_const,$sty_colors,$sty_local;
42  include ("STYLE/{$name}/{$name}.sty");
43  // inherit
44  if (isset($sty_inherit)) {
45  $thparam = $param->GetStyle($sty_inherit, true);
46  getStyleInherit($sty_inherit, $sty_colors_inherit, $sty_const_inherit, $sty_local_inherit);
47 
48  if (isset($sty_const)) {
49  foreach ($sty_const_inherit as $k => $v) {
50  if (!isset($sty_const[$k])) $sty_const[$k] = $v;
51  }
52  } else {
53  $sty_const = $sty_const_inherit;
54  }
55  if (!isset($sty_colors)) $sty_colors = $sty_colors_inherit;
56  }
57 
58  if (sizeof($sty_desc) > 0) {
59  $sty = new Style("", $name);
60  reset($sty_desc);
61  while (list($k, $v) = each($sty_desc)) {
62  $sty->$k = $v;
63  }
64  if (!$sty->isAffected()) $sty->Add();
65  $sty->Modify();
66  }
67  // delete first old parameters
68  $query = new QueryDb("", "Param");
69  $query->AddQuery("type='" . PARAM_STYLE . $name . "'");
70  $list = $query->Query();
71  if ($query->nb > 0) {
72  while (list($k, $v) = each($list)) {
73  $v->delete();
74  }
75  }
76  // init param
77  foreach ($thparam as $k => $v) {
78  $param->Set($v["name"], $v["val"], PARAM_STYLE . $name, 1);
79  $action->parent->SetVolatileParam($v["name"], $v["val"]);
80  }
81 
82  if (isset($sty_colors)) {
83  // compute all derived color
84  $dark = false;
85  if (isset($sty_const["COLOR_WHITE"])) {
86  $basehsl = srgb2hsl($sty_const["COLOR_WHITE"]);
87  }
88  $dark = ($basehsl[2] < 0.5);
89 
90  foreach ($sty_colors as $k => $v) {
91  $basecolor = $v;
92  if ($basecolor[0] == '#') {
93  $r = hexdec(substr($basecolor, 1, 2));
94  $g = hexdec(substr($basecolor, 3, 2));
95  $b = hexdec(substr($basecolor, 5, 2));
96  $basehsl = srgb2hsl($basecolor);
97  $h = $basehsl[0];
98  $s = $basehsl[1];
99  $l = $basehsl[2];
100  if ($html) print "<table><tr>";
101  if ($dark) $idx = - ($l / 10);
102  else $idx = (1 - $l) / 10;
103  $il = $l;
104  for ($i = 0; $i < 10; $i++) {
105 
106  $rgb = HSL2RGB($h, $s, $il);
107  $pcolor = "COLOR_{$k}{$i}";
108  $param->Set($pcolor, $rgb, PARAM_STYLE . $name, 1);
109  $action->parent->SetVolatileParam($pcolor, $rgb); // to compose css with new paramters
110  $il+= $idx;
111  if ($html) print "<td style='background-color:$rgb'>$pcolor: $rgb</td>\n";
112  }
113  if ($html) print "</tr></table>";
114  }
115  }
116  }
117 
118  if (isset($sty_const)) {
119  reset($sty_const);
120  while (list($k, $v) = each($sty_const)) {
121  $vv = $action->getParam($v, $v);
122  $param->Set($k, $vv, PARAM_STYLE . $name, 1);
123  $action->parent->SetVolatileParam($k, $vv); // to compose css with new paramters
124 
125  }
126  }
127  if (isset($sty_local_inherit)) {
128  foreach ($sty_local_inherit as $k => $v) {
129  $action->parent->SetVolatileParam($k, $action->getParam($v, $v)); // to compose css with new paramters
130 
131  }
132  }
133  if (isset($sty_local)) {
134  foreach ($sty_local as $k => $v) {
135  $action->parent->SetVolatileParam($k, $action->getParam($v, $v)); // to compose css with new paramters
136 
137  }
138  }
139 
140  $inputlay = new Layout("STYLE/$name/Layout/$name.css", $action);
141  if ($sty_inherit) {
142  if ($inputlay->file == "") {
143  $inputlay = new Layout("STYLE/$sty_inherit/Layout/$sty_inherit.css", $action);
144  } else {
145  // concat css
146  $inputlayh = new Layout("STYLE/$sty_inherit/Layout/$sty_inherit.css", $action);
147 
148  if ($inputlayh->file != "") {
149  $inputlay->template = $inputlayh->template . "\n" . $inputlay->template;
150  }
151  }
152  }
153 
154  $out = $inputlay->gen();
155 
156  if (!is_dir($action->GetParam("CORE_PUBDIR") . "/STYLE/$name/Layout")) {
157  mkdir($action->GetParam("CORE_PUBDIR") . "/STYLE/$name/Layout");
158  }
159  file_put_contents($action->GetParam("CORE_PUBDIR") . "/STYLE/$name/Layout/gen.css", $out);
160  // update style list for STYLE parameter definition
161  $query = new QueryDb("", "Style");
162  $list = $query->Query();
163  if ($query->nb > 0) {
164  $ndef = "enum(";
165  while (list($k, $v) = each($list)) {
166  if (substr($v->name, 0, 4) != "SIZE") $ndef.= $v->name . "|";
167  }
168  $ndef = substr($ndef, 0, -1) . ")";
169  } else $ndef = "";
170 
171  $pdef = new ParamDef("", "STYLE");
172  $pdef->kind = $ndef;
173  $pdef->modify();
174 
175  print sprintf(_("%s style updated\n") , $name);
176 }
177 ?>
← centre documentaire © anakeen - published under CC License - Dynacase