2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
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.
36 * $this->fetch_modified_link_hook - Required hook that is run when
37 * preparing revert links for properties
40 * @copyright Copyright ©2002 - [#]year[#], Blue Static
48 * Framework registry object
51 private $registry = null
;
57 private $descriptors = array();
63 private $masterdata = array();
69 private $customdata = array();
72 * Valid properties that can be used in CSS
75 private $properties = array(
76 'background' => 'background',
78 'font-style' => 'font_style',
79 'font-size' => 'font_size',
80 'font-family' => 'font_family',
81 'text-decoration' => 'text_decoration'
85 * Hook ran in fetch_modified_link; takes three params: $descriptor, $property, $name
88 private $fetch_modified_link_hook = ':=NO METHOD=:';
94 private $fields = array(
95 'fetch_modified_link_hook' => array(REQ_YES
, null
, false
)
98 // ###################################################################
102 function __construct(&$registry)
104 $this->registry
=& $registry;
107 // ###################################################################
113 * @param string Field name
114 * @param mixed Value of the field
116 function set($name, $value)
118 $this->registry
->do_set($name, $value, 'printer_css');
121 // ###################################################################
127 * @param string Field name
129 * @return mixed Value of the field
131 function get($fieldname)
133 return $this->registry
->do_get($fieldname, 'printer_css');
136 // ###################################################################
138 * Adds a CSS information block to the array for later use
142 * @param string Block title to display in thead
143 * @param string CSS class/descriptor/element name
144 * @param bool Show the link CSS information
146 function add_block($title, $descriptor, $dolink)
148 if (isset($this->descriptors
["$descriptor"]))
150 trigger_error('The descriptor `' . $descriptor . '` already exists', E_USER_WARNING
);
154 $this->descriptors
["$descriptor"] = array(
156 'descriptor' => $descriptor,
161 // ###################################################################
163 * Sets a master data key for a given descriptor and property
167 * @param string Descriptor
168 * @param string Property
169 * @param string Value
171 function set_master_data($descriptor, $property, $value)
173 $this->masterdata
["$descriptor"]["$property"] = $value;
176 // ###################################################################
178 * Sets a custom data key for a given descriptor and property
182 * @param string Descriptor
183 * @param string Property
184 * @param string Value
186 function set_custom_data($descriptor, $property, $value)
188 $this->customdata
["$descriptor"]["$property"] = $value;
191 // ###################################################################
193 * Generates the HTML needed to output the CSS editing blocks; this is
194 * done in the form of using ISSO.Printer
198 function generate_blocks()
200 $print =& $this->registry
->modules
['printer'];
203 'standard_css_attributes' => $this->registry
->modules
['localize']->string('Standard CSS Attributes'),
204 'extra_css_attributes' => $this->registry
->modules
['localize']->string('Extra CSS Attributes'),
206 'links_normal' => $this->registry
->modules
['localize']->string('Normal CSS Links'),
207 'links_visited' => $this->registry
->modules
['localize']->string('Visited CSS Links'),
208 'links_hover' => $this->registry
->modules
['localize']->string('Hover CSS Links'),
210 'background' => $this->registry
->modules
['localize']->string('Background'),
211 'font_color' => $this->registry
->modules
['localize']->string('Font Color'),
212 'font_style' => $this->registry
->modules
['localize']->string('Font Style'),
213 'font_size' => $this->registry
->modules
['localize']->string('Font Size'),
214 'font_family' => $this->registry
->modules
['localize']->string('Font Family'),
216 'text_decoration' => $this->registry
->modules
['localize']->string('Text Decoration'),
218 'css_selector' => $this->registry
->modules
['localize']->string('CSS Selector'),
219 'save_css' => $this->registry
->modules
['localize']->string('Save CSS')
222 foreach ($this->descriptors
AS $descriptor)
227 $desc = $descriptor['descriptor'];
229 $print->table_start();
230 $print->table_head($descriptor['title']);
232 foreach ($this->properties
AS $prop => $name)
234 $value["$name"] = $this->fetch_value($descriptor['descriptor'], $prop);
235 $status["$name"] = $this->fetch_modified_status($descriptor['descriptor'], $prop);
238 $value['extra'] = $this->fetch_value($descriptor['descriptor'], 'extra');
240 $html = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">
244 <legend><strong>$lang[standard_css_attributes]</strong></legend>
246 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
248 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'background', $lang['background']) . "</td>
249 <td><input name=\"css[$descriptor[descriptor]][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[background]\" /></td>
252 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'color', $lang['font_color']) . "</td>
253 <td><input name=\"css[$descriptor[descriptor]][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[color]\" /></td>
256 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-style', $lang['font_style']) . "</td>
257 <td><input name=\"css[$descriptor[descriptor]][font-style]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_style]\" /></td>
260 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-size', $lang['font_size']) . "</td>
261 <td><input name=\"css[$descriptor[descriptor]][font-size]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_size]\" /></td>
264 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-family', $lang['font_family']) . "</td>
265 <td><input name=\"css[$descriptor[descriptor]][font-family]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_family]\" /></td>
272 <fieldset style=\"height: 115px\">
273 <legend><strong>" . $this->fetch_modified_link($desc, 'extra', $lang['extra_css_attributes']) . "</strong></legend>
274 <textarea name=\"css[$descriptor[descriptor]][extra]\" style=\"width: 100%; height: 90%\">$value[extra]</textarea>
279 if ($descriptor['dolink'])
281 foreach (array('a:link' => 'a_link', 'a:visited' => 'a_visited', 'a:hover' => 'a_hover') AS $sel => $selname)
283 foreach (array('background' => 'background', 'color' => 'color', 'text-decoration' => 'text_decoration') AS $prop => $name)
285 $value["{$selname}_{$name}"] = $this->fetch_value($descriptor['descriptor'] . ' ' . $sel, $prop);
286 $status["{$selname}_{$name}"] = $this->fetch_modified_status($descriptor['descriptor'] . ' ' . $sel, $prop);
292 <table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">
296 <legend><strong>$lang[links_normal]</strong></legend>
298 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
300 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'background', $lang['background']) . "</td>
301 <td><input name=\"css[$descriptor[descriptor] a:link][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_background]\" /></td>
304 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'color', $lang['font_color']) . "</td>
305 <td><input name=\"css[$descriptor[descriptor] a:link][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_color]\" /></td>
308 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'text-decoration', $lang['text_decoration']) . "</td>
309 <td><input name=\"css[$descriptor[descriptor] a:link][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_text_decoration]\" /></td>
317 <legend><strong>$lang[links_visited]</strong></legend>
319 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
321 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'background', $lang['background']) . "</td>
322 <td><input name=\"css[$descriptor[descriptor] a:visited][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_background]\" /></td>
325 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'color', $lang['font_color']) . "</td>
326 <td><input name=\"css[$descriptor[descriptor] a:visited][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_color]\" /></td>
329 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'text-decoration', $lang['text_decoration']) . "</td>
330 <td><input name=\"css[$descriptor[descriptor] a:visited][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_text_decoration]\" /></td>
338 <legend><strong>$lang[links_hover]</strong></legend>
340 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
342 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'background', $lang['background']) . "</td>
343 <td><input name=\"css[$descriptor[descriptor] a:hover][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_background]\" /></td>
346 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'color', $lang['font_color']) . "</td>
347 <td><input name=\"css[$descriptor[descriptor] a:hover][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_color]\" /></td>
350 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'text-decoration', $lang['text_decoration']) . "</td>
351 <td><input name=\"css[$descriptor[descriptor] a:hover][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_text_decoration]\" /></td>
360 $print->row_span($html, 'alt2', 'left', 1);
363 <div class="alt1" style="border: inset 1px; padding: 2px 5px 2px 5px; float: left">' . $lang['css_selector'] . ': <code>' . $descriptor['descriptor'] . '</code></div>
364 <input type="submit" name="submit" value="' . $lang['save_css'] . '" class="button" />', 'tfoot', 'right', 1);
370 // ###################################################################
372 * Returns the value of a given descriptor and property by comparing
373 * the mater set and custom set then returning the right one
377 * @param string Descriptor
378 * @param string Property
380 * @return string Value of the given property
382 function fetch_value($descriptor, $property)
384 if (!isset($this->customdata
["$descriptor"]["$property"]))
386 return $this->masterdata
["$descriptor"]["$property"];
390 return $this->customdata
["$descriptor"]["$property"];
394 // ###################################################################
396 * Returns the state modified state (false for untouched and true
397 * for modified) from the descriptor-property value between the master
398 * set and the custom set of data
402 * @param string Descriptor
403 * @param string Property
405 * @return bool Modified from the master value?
407 function fetch_modified_status($descriptor, $property)
409 if ($this->masterdata
["$descriptor"]["$property"] != $this->customdata
["$descriptor"]["$property"] AND isset($this->customdata
["$descriptor"]["$property"]))
417 // ###################################################################
419 * Fetches a link that shows a revert link for a given property
420 * that uses AJAX to revert when clicked
424 * @param string Descriptor
425 * @param string Property
426 * @param string Nominalized text
428 * @return string Output HTML
430 function fetch_modified_link($descriptor, $property, $name)
432 $status = $this->fetch_modified_status($descriptor, $property);
436 if (is_callable($this->fetch_modified_link_hook
))
438 return call_user_func($this->fetch_modified_link_hook
, $descriptor, $property, $name);
442 trigger_error('Printer_CSS::fetch_modified_link() needs to have the fetch_modified_link_hook( $descriptor , $property , $name ) defined', E_USER_ERROR
);
451 // ###################################################################
453 * Generates an array of queries that should be run on your database to
454 * update CSS changes. All of the queries have sprintf() markers that
455 * need to be evaluated:
457 * %1$s - Database table
458 * %2$s - styleid field
459 * %3$s - descriptor field
460 * %4$s - property field
462 * %6$d - Styleid value
466 * @param array Array of user-inputted information to be transformed into queries
468 * @return array Queries that need to be evaluated then ran
470 function generate_change_query($data)
472 $queries[0] = '--- RESERVED FOR LATER USE ---';
476 foreach ($this->descriptors
AS $descriptor => $opts)
478 $dolink = $opts['dolink'];
482 $loops = array('', ' a:link', ' a:visited', ' a:hover');
489 foreach ($loops AS $sel)
491 foreach ($data["$descriptor$sel"] AS $prop => $value)
493 // the given value matches the master -- no change
494 if ($this->masterdata
["$descriptor$sel"]["$prop"] == $value)
498 // the given matches the custom -- no change
499 else if (isset($this->customdata
["$descriptor$sel"]["$prop"]) AND $this->customdata
["$descriptor$sel"]["$prop"] == $value)
503 // no matching, it's new
506 $value = str_replace('%', '%%', $value);
507 $deletes[] = "%3\$s = '" . $this->escape($descriptor . $sel) . "' AND %4\$s = '" . $this->escape($prop) . "'";
508 $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) . "')";
514 if (sizeof($deletes) < 1)
520 $queries[0] = "DELETE FROM %1\$s WHERE styleid = %6\$d AND ((" . implode(') OR (', $deletes) . "))";
526 // ###################################################################
528 * Wrapper for $this->registry->modules[ISSO_DB_LAYER]->escape_string()
532 * @param string Unprotected string
534 * @return string Sanitized string
536 function escape($string)
538 return $this->registry
->modules
[ISSO_DB_LAYER
]->escape_string($string);
541 // ###################################################################
543 * Generates a linkable/usable CSS stylehseet content file; this can
544 * be outputted to the browser
548 * @return string CSS output
550 function generate_css_output()
554 foreach ($this->descriptors
AS $descriptor => $opts)
556 $dolink = $opts['dolink'];
560 $loops = array('', ' a:link', ' a:visited', ' a:hover');
567 foreach ($loops AS $sel)
569 foreach ($this->masterdata
["$descriptor$sel"] AS $prop => $value)
571 $data["$descriptor$sel"]["$prop"] = $value;
573 if (is_array($this->customdata
["$descriptor$sel"]))
575 foreach ($this->customdata
["$descriptor$sel"] AS $prop => $value)
577 $data["$descriptor$sel"]["$prop"] = $value;
583 $output = '/* CSS Style Sheet (generated by ISSO.Printer.CSS $Revision$) */';
585 foreach ($data AS $selector => $props)
587 $output .= "\n\n$selector\n{";
588 foreach ($props AS $name => $value)
590 if ($name != 'extra' AND $value != '')
592 $output .= str_replace('"', '"', "\n\t$name: $value;");
598 $extra = explode("\n", $this->registry
->modules
['functions']->convert_line_breaks($props['extra']));
600 foreach ($extra AS $prop)
602 $output .= "\n\t$prop";
613 /*=====================================================================*\
614 || ###################################################################
617 || ###################################################################
618 \*=====================================================================*/