2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
23 * Printer - CSS Blocks
30 * Printer - CSS Blocks
32 * This framework works in conjunction with ISSO.Printer to create a unique
33 * CSS editor enviornment.
35 * @author Iris Studios, Inc.
36 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
44 * Framework registry object
55 var $descriptors = array();
62 var $masterdata = array();
69 var $customdata = array();
71 // ###################################################################
75 function __construct(&$registry)
77 $this->registry
=& $registry;
80 // ###################################################################
84 function Printer_CSS(&$registry)
86 $this->__construct($registry);
89 // ###################################################################
91 * Adds a CSS information block to the array for later use
95 * @param string Block title to display in thead
96 * @param string CSS class/descriptor/element name
97 * @param bool Show the link CSS information
99 function add_block($title, $descriptor, $dolink)
101 if (isset($this->descriptors
["$descriptor"]))
103 trigger_error('The descriptor `' . $descriptor . '` already exists', E_USER_WARNING
);
107 $this->descriptors
["$descriptor"] = array(
109 'descriptor' => $descriptor,
114 // ###################################################################
116 * Sets a master data key for a given descriptor and property
120 * @param string Descriptor
121 * @param string Property
122 * @param string Value
124 function set_master_data($descriptor, $property, $value)
126 $this->masterdata
["$descriptor"]["$property"] = $value;
129 // ###################################################################
131 * Sets a custom data key for a given descriptor and property
135 * @param string Descriptor
136 * @param string Property
137 * @param string Value
139 function set_custom_data($descriptor, $property, $value)
141 $this->customdata
["$descriptor"]["$property"] = $value;
144 // ###################################################################
146 * Generates the HTML needed to output the CSS editing blocks; this is
147 * done in the form of using ISSO.Printer
151 function generate_blocks()
153 $print =& $this->registry
->modules
['printer'];
156 'standard_css_attributes' => $this->registry
->modules
['localize']->string('Standard CSS Attributes'),
157 'extra_css_attributes' => $this->registry
->modules
['localize']->string('Extra CSS Attributes'),
159 'links_normal' => $this->registry
->modules
['localize']->string('Normal CSS Links'),
160 'links_visited' => $this->registry
->modules
['localize']->string('Visited CSS Links'),
161 'links_hover' => $this->registry
->modules
['localize']->string('Hover CSS Links'),
163 'background' => $this->registry
->modules
['localize']->string('Background'),
164 'font_color' => $this->registry
->modules
['localize']->string('Font Color'),
165 'font_style' => $this->registry
->modules
['localize']->string('Font Style'),
166 'font_size' => $this->registry
->modules
['localize']->string('Font Size'),
167 'font_family' => $this->registry
->modules
['localize']->string('Font Family'),
169 'text_decoration' => $this->registry
->modules
['localize']->string('Text Decoration'),
171 'css_selector' => $this->registry
->modules
['localize']->string('CSS Selector'),
172 'save_css' => $this->registry
->modules
['localize']->string('Save CSS')
175 foreach ($this->descriptors
AS $descriptor)
179 $print->table_start();
180 $print->table_head($descriptor['title']);
182 $value['background'] = $this->fetch_value($descriptor['descriptor'], 'background');
183 $value['color'] = $this->fetch_value($descriptor['descriptor'], 'color');
184 $value['font_style'] = $this->fetch_value($descriptor['descriptor'], 'font-style');
185 $value['font_size'] = $this->fetch_value($descriptor['descriptor'], 'font-size');
186 $value['font_family'] = $this->fetch_value($descriptor['descriptor'], 'font-family');
187 $value['extra'] = $this->fetch_value($descriptor['descriptor'], 'extra');
190 <table cellspacing
="0" cellpadding
="4" border
="0" width
="100%">
194 <legend
><strong
>$lang[standard_css_attributes
]</strong
></legend
>
196 <table cellspacing
="0" cellpadding
="2" border
="0" width
="100%">
198 <td width
="45%">$lang[background
]</td
>
199 <td
><input name
="css[$descriptor[descriptor]][background]" class="input" style
="width: 100%" value
="$value[background]" /></td
>
202 <td width
="45%">$lang[font_color
]</td
>
203 <td
><input name
="css[$descriptor[descriptor]][color]" class="input" style
="width: 100%" value
="$value[color]" /></td
>
206 <td width
="45%">$lang[font_style
]</td
>
207 <td
><input name
="css[$descriptor[descriptor]][font-style]" class="input" style
="width: 100%" value
="$value[font_style]" /></td
>
210 <td width
="45%">$lang[font_size
]</td
>
211 <td
><input name
="css[$descriptor[descriptor]][font-size]" class="input" style
="width: 100%" value
="$value[font_size]" /></td
>
214 <td width
="45%">$lang[font_family
]</td
>
215 <td
><input name
="css[$descriptor[descriptor]][font-family]" class="input" style
="width: 100%" value
="$value[font_family]" /></td
>
222 <fieldset style
="height: 115px">
223 <legend
><strong
>$lang[extra_css_attributes
]</strong
></legend
>
224 <textarea name
="css[$descriptor[descriptor]][extra]" style
="width: 100%; height: 90%">$value[extra
]</textarea
>
230 if ($descriptor['dolink'])
232 foreach (array('a:link' => 'a_link', 'a:visited' => 'a_visited', 'a:hover' => 'a_hover') AS $sel => $selname)
234 $value[$selname . '_background'] = $this->fetch_value($descriptor['descriptor'] . ' ' . $sel, 'background');
235 $value[$selname . '_color'] = $this->fetch_value($descriptor['descriptor'] . ' ' . $sel, 'color');
236 $value[$selname . '_text_decoration'] = $this->fetch_value($descriptor['descriptor'] . ' ' . $sel, 'text-decoration');
241 <table cellspacing
="0" cellpadding
="4" border
="0" width
="100%">
245 <legend
><strong
>$lang[links_normal
]</strong
></legend
>
247 <table cellspacing
="0" cellpadding
="2" border
="0" width
="100%">
249 <td width
="45%">$lang[background
]</td
>
250 <td
><input name
="css[$descriptor[descriptor] a:link][background]" class="input" style
="width: 100%" value
="$value[a_link_background]" /></td
>
253 <td width
="45%">$lang[font_color
]</td
>
254 <td
><input name
="css[$descriptor[descriptor] a:link][color]" class="input" style
="width: 100%" value
="$value[a_link_color]" /></td
>
257 <td width
="45%">$lang[text_decoration
]</td
>
258 <td
><input name
="css[$descriptor[descriptor] a:link][text-decoration]" class="input" style
="width: 100%" value
="$value[a_link_text_decoration]" /></td
>
266 <legend
><strong
>$lang[links_visited
]</strong
></legend
>
268 <table cellspacing
="0" cellpadding
="2" border
="0" width
="100%">
270 <td width
="45%">$lang[background
]</td
>
271 <td
><input name
="css[$descriptor[descriptor] a:visited][background]" class="input" style
="width: 100%" value
="$value[a_visited_background]" /></td
>
274 <td width
="45%">$lang[font_color
]</td
>
275 <td
><input name
="css[$descriptor[descriptor] a:visited][color]" class="input" style
="width: 100%" value
="$value[a_visited_color]" /></td
>
278 <td width
="45%">$lang[text_decoration
]</td
>
279 <td
><input name
="css[$descriptor[descriptor] a:visited][text-decoration]" class="input" style
="width: 100%" value
="$value[a_visited_text_decoration]" /></td
>
287 <legend
><strong
>$lang[links_hover
]</strong
></legend
>
289 <table cellspacing
="0" cellpadding
="2" border
="0" width
="100%">
291 <td width
="45%">$lang[background
]</td
>
292 <td
><input name
="css[$descriptor[descriptor] a:hover][background]" class="input" style
="width: 100%" value
="$value[a_hover_background]" /></td
>
295 <td width
="45%">$lang[font_color
]</td
>
296 <td
><input name
="css[$descriptor[descriptor] a:hover][color]" class="input" style
="width: 100%" value
="$value[a_hover_color]" /></td
>
299 <td width
="45%">$lang[text_decoration
]</td
>
300 <td
><input name
="css[$descriptor[descriptor] a:hover][text-decoration]" class="input" style
="width: 100%" value
="$value[a_hover_text_decoration]" /></td
>
310 $print->row_span($html, 'alt2', 'left', 1);
313 <div class="alt1" style="border: inset 1px; padding: 2px 5px 2px 5px; float: left">' . $lang['css_selector'] . ': <code>' . $descriptor['descriptor'] . '</code></div>
314 <input type="submit" name="submit" value="' . $lang['save_css'] . '" class="button" />', 'tfoot', 'right', 1);
320 // ###################################################################
322 * Returns the value of a given descriptor and property by comparing
323 * the mater set and custom set then returning the right one
327 * @param string Descriptor
328 * @param string Property
330 * @return string Value of the given property
332 function fetch_value($descriptor, $property)
334 if ($this->customdata
["$descriptor"]["$property"] == '')
336 return $this->masterdata
["$descriptor"]["$property"];
340 return $this->customdata
["$descriptor"]["$property"];
344 // ###################################################################
346 * Generates an array of queries that should be run on your database to
347 * update CSS changes. All of the queries have sprintf() markers that
348 * need to be evaluated:
350 * %1$s - Database table
351 * %2$s - styleid field
352 * %3$s - descriptor field
353 * %4$s - property field
355 * %6%d - Styleid value
359 * @param array Array of user-inputted information to be transformed into queries
361 * @return array Queries that need to be evaluated then ran
363 function generate_change_query($data)
365 $queries[0] = '--- RESERVED FOR LATER USE ---';
371 foreach ($this->descriptors
AS $descriptor => $opts)
373 $dolink = $opts['dolink'];
377 $loops = array('', ' a:link', ' a:visited', ' a:hover');
384 foreach ($loops AS $sel)
386 foreach ($data["$descriptor$sel"] AS $prop => $value)
388 // the given value matches the master -- no change
389 if ($this->masterdata
["$descriptor$sel"]["$prop"] == $value)
393 // the given matches the custom -- no change
394 else if ($this->customdata
["$descriptor$sel"]["$prop"] == $value)
398 // no matching, it's new
401 $deletes[] = "%3\$s = '" . $this->escape($descriptor . $sel) . "' AND %4\$s = '" . $this->escape($prop) . "'";
402 $queries[] = "INSERT INTO %1\$s (%2\$s, %3\$s, %4\$s, %5\$s) VALUES (%6\$d, '" . $this->escape($descriptor . $sel) . "', '" . $this->escape($prop) . "', '" . $this->escape($value) . "')";
408 $queries[0] = "DELETE FROM %1\$s WHERE styleid = %6\$d AND ((" . implode(') OR (', $deletes) . "))";
413 // ###################################################################
415 * Wrapper for $this->registry->modules[ISSO_DB_LAYER]->escape_string()
419 * @param string Unprotected string
421 * @return string Sanitized string
423 function escape($string)
425 return $this->registry
->modules
[ISSO_DB_LAYER
]->escape_string($string);
429 /*=====================================================================*\
430 || ###################################################################
433 || ###################################################################
434 \*=====================================================================*/