]>
src.bluestatic.org Git - isso.git/blob - printer_css.php
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();
72 * Valid properties that can be used in CSS
76 var $properties = array(
77 'background' => 'background',
79 'font-style' => 'font_style',
80 'font-size' => 'font_size',
81 'font-family' => 'font_family',
82 'text-decoration' => 'text_decoration'
85 // ###################################################################
89 function __construct(&$registry)
91 $this->registry
=& $registry;
94 // ###################################################################
98 function Printer_CSS(&$registry)
100 $this->__construct($registry);
103 // ###################################################################
105 * Adds a CSS information block to the array for later use
109 * @param string Block title to display in thead
110 * @param string CSS class/descriptor/element name
111 * @param bool Show the link CSS information
113 function add_block($title, $descriptor, $dolink)
115 if (isset($this->descriptors
["$descriptor"]))
117 trigger_error('The descriptor `' . $descriptor . '` already exists', E_USER_WARNING);
121 $this->descriptors["$descriptor"] = array(
123 'descriptor' => $descriptor,
128 // ###################################################################
130 * Sets a master data key for a given descriptor and property
134 * @param string Descriptor
135 * @param string Property
136 * @param string Value
138 function set_master_data($descriptor, $property, $value)
140 $this->masterdata
["$descriptor"]["$property"] = $value;
143 // ###################################################################
145 * Sets a custom data key for a given descriptor and property
149 * @param string Descriptor
150 * @param string Property
151 * @param string Value
153 function set_custom_data($descriptor, $property, $value)
155 $this->customdata
["$descriptor"]["$property"] = $value;
158 // ###################################################################
160 * Generates the HTML needed to output the CSS editing blocks; this is
161 * done in the form of using ISSO.Printer
165 function generate_blocks()
167 $print =& $this->registry
->modules
['printer'];
170 'standard_css_attributes' => $this->registry
->modules
['localize']->string('Standard CSS Attributes'),
171 'extra_css_attributes' => $this->registry
->modules
['localize']->string('Extra CSS Attributes'),
173 'links_normal' => $this->registry
->modules
['localize']->string('Normal CSS Links'),
174 'links_visited' => $this->registry
->modules
['localize']->string('Visited CSS Links'),
175 'links_hover' => $this->registry
->modules
['localize']->string('Hover CSS Links'),
177 'background' => $this->registry
->modules
['localize']->string('Background'),
178 'font_color' => $this->registry
->modules
['localize']->string('Font Color'),
179 'font_style' => $this->registry
->modules
['localize']->string('Font Style'),
180 'font_size' => $this->registry
->modules
['localize']->string('Font Size'),
181 'font_family' => $this->registry
->modules
['localize']->string('Font Family'),
183 'text_decoration' => $this->registry
->modules
['localize']->string('Text Decoration'),
185 'css_selector' => $this->registry
->modules
['localize']->string('CSS Selector'),
186 'save_css' => $this->registry
->modules
['localize']->string('Save CSS')
189 foreach ($this->descriptors
AS $descriptor)
194 $desc = $descriptor['descriptor'];
196 $print->table_start();
197 $print->table_head($descriptor['title']);
199 foreach ($this->properties
AS $prop => $name)
201 $value["$name"] = $this->fetch_value($descriptor['descriptor'], $prop);
202 $status["$name"] = $this->fetch_modified_status($descriptor['descriptor'], $prop);
205 $value['extra'] = $this->fetch_value($descriptor['descriptor'], 'extra');
207 $html = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">
211 <legend><strong>$lang[standard_css_attributes]</strong></legend>
213 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
215 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'background', $lang['background']) . "</td>
216 <td><input name=\"css[$descriptor[descriptor]][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[background]\" /></td>
219 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'color', $lang['font_color']) . "</td>
220 <td><input name=\"css[$descriptor[descriptor]][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[color]\" /></td>
223 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-style', $lang['font_style']) . "</td>
224 <td><input name=\"css[$descriptor[descriptor]][font-style]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_style]\" /></td>
227 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-size', $lang['font_size']) . "</td>
228 <td><input name=\"css[$descriptor[descriptor]][font-size]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_size]\" /></td>
231 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-family', $lang['font_family']) . "</td>
232 <td><input name=\"css[$descriptor[descriptor]][font-family]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_family]\" /></td>
239 <fieldset style=\"height: 115px\">
240 <legend><strong>" . $this->fetch_modified_link($desc, 'extra', $lang['extra_css_attributes']) . "</strong></legend>
241 <textarea name=\"css[$descriptor[descriptor]][extra]\" style=\"width: 100%; height: 90%\">$value[extra]</textarea>
246 if ($descriptor['dolink'])
248 foreach (array('a:link' => 'a_link', 'a:visited' => 'a_visited', 'a:hover' => 'a_hover') AS $sel => $selname)
250 foreach (array('background' => 'background', 'color' => 'color', 'text-decoration' => 'text_decoration') AS $prop => $name)
252 $value["{$selname}_{$name}"] = $this->fetch_value($descriptor['descriptor'] . ' ' . $sel, $prop);
253 $status["{$selname}_{$name}"] = $this->fetch_modified_status($descriptor['descriptor'] . ' ' . $sel, $prop);
259 <table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">
263 <legend><strong>$lang[links_normal]</strong></legend>
265 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
267 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'background', $lang['background']) . "</td>
268 <td><input name=\"css[$descriptor[descriptor] a:link][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_background]\" /></td>
271 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'color', $lang['font_color']) . "</td>
272 <td><input name=\"css[$descriptor[descriptor] a:link][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_color]\" /></td>
275 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'text-decoration', $lang['text_decoration']) . "</td>
276 <td><input name=\"css[$descriptor[descriptor] a:link][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_text_decoration]\" /></td>
284 <legend><strong>$lang[links_visited]</strong></legend>
286 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
288 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'background', $lang['background']) . "</td>
289 <td><input name=\"css[$descriptor[descriptor] a:visited][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_background]\" /></td>
292 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'color', $lang['font_color']) . "</td>
293 <td><input name=\"css[$descriptor[descriptor] a:visited][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_color]\" /></td>
296 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'text-decoration', $lang['text_decoration']) . "</td>
297 <td><input name=\"css[$descriptor[descriptor] a:visited][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_text_decoration]\" /></td>
305 <legend><strong>$lang[links_hover]</strong></legend>
307 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
309 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'background', $lang['background']) . "</td>
310 <td><input name=\"css[$descriptor[descriptor] a:hover][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_background]\" /></td>
313 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'color', $lang['font_color']) . "</td>
314 <td><input name=\"css[$descriptor[descriptor] a:hover][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_color]\" /></td>
317 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'text-decoration', $lang['text_decoration']) . "</td>
318 <td><input name=\"css[$descriptor[descriptor] a:hover][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_text_decoration]\" /></td>
327 $print->row_span($html, 'alt2', 'left', 1);
330 <div class="alt1" style="border: inset 1px; padding: 2px 5px 2px 5px; float: left">' . $lang['css_selector'] . ': <code>' . $descriptor['descriptor'] . '</code></div>
331 <input type="submit" name="submit" value="' . $lang['save_css'] . '" class="button" />', 'tfoot', 'right', 1);
337 // ###################################################################
339 * Returns the value of a given descriptor and property by comparing
340 * the mater set and custom set then returning the right one
344 * @param string Descriptor
345 * @param string Property
347 * @return string Value of the given property
349 function fetch_value($descriptor, $property)
351 if (!isset($this->customdata
["$descriptor"]["$property"]))
353 return $this->masterdata
["$descriptor"]["$property"];
357 return $this->customdata
["$descriptor"]["$property"];
361 // ###################################################################
363 * Returns the state modified state (false for untouched and true
364 * for modified) from the descriptor-property value between the master
365 * set and the custom set of data
369 * @param string Descriptor
370 * @param string Property
372 * @return bool Modified from the master value?
374 function fetch_modified_status($descriptor, $property)
376 if ($this->masterdata
["$descriptor"]["$property"] != $this->customdata
["$descriptor"]["$property"] AND isset($this->customdata
["$descriptor"]["$property"]))
384 // ###################################################################
386 * Fetches a link that shows a revert link for a given property
387 * that uses AJAX to revert when clicked
391 * @param string Descriptor
392 * @param string Property
393 * @param string Nominalized text
395 * @return string Output HTML
397 function fetch_modified_link($descriptor, $property, $name)
399 $status = $this->fetch_modified_status($descriptor, $property);
403 return '<em>' . $name . '</em>';
411 // ###################################################################
413 * Generates an array of queries that should be run on your database to
414 * update CSS changes. All of the queries have sprintf() markers that
415 * need to be evaluated:
417 * %1$s - Database table
418 * %2$s - styleid field
419 * %3$s - descriptor field
420 * %4$s - property field
422 * %6%d - Styleid value
426 * @param array Array of user-inputted information to be transformed into queries
428 * @return array Queries that need to be evaluated then ran
430 function generate_change_query($data)
432 $queries[0] = '--- RESERVED FOR LATER USE ---';
436 foreach ($this->descriptors
AS $descriptor => $opts)
438 $dolink = $opts['dolink'];
442 $loops = array('', ' a:link', ' a:visited', ' a:hover');
449 foreach ($loops AS $sel)
451 foreach ($data["$descriptor$sel"] AS $prop => $value)
453 // the given value matches the master -- no change
454 if ($this->masterdata["$descriptor$sel"]["$prop"] == $value)
458 // the given matches the custom -- no change
459 else if (isset($this->customdata["$descriptor$sel"]["$prop"]) AND $this->customdata["$descriptor$sel"]["$prop"] == $value)
463 // no matching, it's new
466 $deletes[] = "%
3\$s
= '" . $this->escape($descriptor . $sel) . "' AND %
4\$s
= '" . $this->escape($prop) . "'";
467 $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) . "')";
473 if (sizeof($deletes) < 1)
479 $queries[0] = "DELETE FROM %
1\$s WHERE styleid
= %
6\$d
AND ((" . implode(') OR (', $deletes) . "))";
485 // ###################################################################
487 * Wrapper for $this->registry->modules[ISSO_DB_LAYER]->escape_string()
491 * @param string Unprotected string
493 * @return string Sanitized string
495 function escape($string)
497 return $this->registry->modules[ISSO_DB_LAYER]->escape_string($string);
500 // ###################################################################
502 * Generates a linkable/usable CSS stylehseet content file; this can
503 * be outputted to the browser
507 * @return string CSS output
509 function generate_css_output()
513 foreach ($this->descriptors AS $descriptor => $opts)
515 $dolink = $opts['dolink'];
519 $loops = array('', ' a:link', ' a:visited', ' a:hover');
526 foreach ($loops AS $sel)
528 foreach ($this->masterdata["$descriptor$sel"] AS $prop => $value)
530 $data["$descriptor$sel"]["$prop"] = $value;
532 if (is_array($this->customdata
["$descriptor$sel"]))
534 foreach ($this->customdata["$descriptor$sel"] AS $prop => $value)
536 $data["$descriptor$sel"]["$prop"] = $value;
542 $output = '/* CSS Style Sheet (generated by ISSO.Printer.CSS $Revision$) */';
544 foreach ($data AS $selector => $props)
546 $output .= "\n\n$selector\n{";
547 foreach ($props AS $name => $value)
549 if ($name != 'extra' AND $value != '')
551 $output .= "\n\t$name: $value;";
557 $extra = explode("\n", $this->registry
->modules
['functions']->convert_line_breaks($props['extra']));
559 foreach ($extra AS $prop)
561 $output .= "\n\t$prop";
572 /*=====================================================================*\
573 || ###################################################################
576 || ###################################################################
577 \*=====================================================================*/