]>
src.bluestatic.org Git - bugdar.git/blob - framework/printer_css.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)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 (c)2002 - [#]year[#], Blue Static
48 * Framework registry object
59 var $descriptors = array();
66 var $masterdata = array();
73 var $customdata = array();
76 * Valid properties that can be used in CSS
80 var $properties = array(
81 'background' => 'background',
83 'font-style' => 'font_style',
84 'font-size' => 'font_size',
85 'font-family' => 'font_family',
86 'text-decoration' => 'text_decoration'
90 * Hook ran in fetch_modified_link; takes three params: $descriptor, $property, $name
94 var $fetch_modified_link_hook = ':=NO METHOD=:';
102 'fetch_modified_link_hook' => array(REQ_YES
, null, false)
105 // ###################################################################
109 function __construct(&$registry)
111 $this->registry
=& $registry;
114 // ###################################################################
116 * (PHP 4) Constructor
118 function Printer_CSS(&$registry)
120 $this->__construct($registry);
123 // ###################################################################
129 * @param string Field name
130 * @param mixed Value of the field
132 function set($name, $value)
134 $this->registry
->do_set($name, $value, 'printer_css');
137 // ###################################################################
143 * @param string Field name
145 * @return mixed Value of the field
147 function get($fieldname)
149 return $this->registry
->do_get($fieldname, 'printer_css');
152 // ###################################################################
154 * Adds a CSS information block to the array for later use
158 * @param string Block title to display in thead
159 * @param string CSS class/descriptor/element name
160 * @param bool Show the link CSS information
162 function add_block($title, $descriptor, $dolink)
164 if (isset($this->descriptors
["$descriptor"]))
166 trigger_error('The descriptor `' . $descriptor . '` already exists', E_USER_WARNING);
170 $this->descriptors["$descriptor"] = array(
172 'descriptor' => $descriptor,
177 // ###################################################################
179 * Sets a master data key for a given descriptor and property
183 * @param string Descriptor
184 * @param string Property
185 * @param string Value
187 function set_master_data($descriptor, $property, $value)
189 $this->masterdata
["$descriptor"]["$property"] = $value;
192 // ###################################################################
194 * Sets a custom data key for a given descriptor and property
198 * @param string Descriptor
199 * @param string Property
200 * @param string Value
202 function set_custom_data($descriptor, $property, $value)
204 $this->customdata
["$descriptor"]["$property"] = $value;
207 // ###################################################################
209 * Generates the HTML needed to output the CSS editing blocks; this is
210 * done in the form of using ISSO.Printer
214 function generate_blocks()
216 $print =& $this->registry
->modules
['printer'];
219 'standard_css_attributes' => T('Standard CSS Attributes'),
220 'extra_css_attributes' => T('Extra CSS Attributes'),
222 'links_normal' => T('Normal CSS Links'),
223 'links_visited' => T('Visited CSS Links'),
224 'links_hover' => T('Hover CSS Links'),
226 'background' => T('Background'),
227 'font_color' => T('Font Color'),
228 'font_style' => T('Font Style'),
229 'font_size' => T('Font Size'),
230 'font_family' => T('Font Family'),
232 'text_decoration' => T('Text Decoration'),
234 'css_selector' => T('CSS Selector'),
235 'save_css' => T('Save CSS')
238 foreach ($this->descriptors
AS $descriptor)
243 $desc = $descriptor['descriptor'];
245 $print->table_start();
246 $print->table_head($descriptor['title']);
248 foreach ($this->properties
AS $prop => $name)
250 $value["$name"] = $this->fetch_value($descriptor['descriptor'], $prop);
251 $status["$name"] = $this->fetch_modified_status($descriptor['descriptor'], $prop);
254 $value['extra'] = $this->fetch_value($descriptor['descriptor'], 'extra');
256 $html = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">
260 <legend><strong>$lang[standard_css_attributes]</strong></legend>
262 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
264 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'background', $lang['background']) . "</td>
265 <td><input name=\"css[$descriptor[descriptor]][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[background]\" /></td>
268 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'color', $lang['font_color']) . "</td>
269 <td><input name=\"css[$descriptor[descriptor]][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[color]\" /></td>
272 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-style', $lang['font_style']) . "</td>
273 <td><input name=\"css[$descriptor[descriptor]][font-style]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_style]\" /></td>
276 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-size', $lang['font_size']) . "</td>
277 <td><input name=\"css[$descriptor[descriptor]][font-size]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_size]\" /></td>
280 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-family', $lang['font_family']) . "</td>
281 <td><input name=\"css[$descriptor[descriptor]][font-family]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_family]\" /></td>
288 <fieldset style=\"height: 115px\">
289 <legend><strong>" . $this->fetch_modified_link($desc, 'extra', $lang['extra_css_attributes']) . "</strong></legend>
290 <textarea name=\"css[$descriptor[descriptor]][extra]\" style=\"width: 100%; height: 90%\">$value[extra]</textarea>
295 if ($descriptor['dolink'])
297 foreach (array('a:link' => 'a_link', 'a:visited' => 'a_visited', 'a:hover' => 'a_hover') AS $sel => $selname)
299 foreach (array('background' => 'background', 'color' => 'color', 'text-decoration' => 'text_decoration') AS $prop => $name)
301 $value["{$selname}_{$name}"] = $this->fetch_value($descriptor['descriptor'] . ' ' . $sel, $prop);
302 $status["{$selname}_{$name}"] = $this->fetch_modified_status($descriptor['descriptor'] . ' ' . $sel, $prop);
308 <table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">
312 <legend><strong>$lang[links_normal]</strong></legend>
314 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
316 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'background', $lang['background']) . "</td>
317 <td><input name=\"css[$descriptor[descriptor] a:link][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_background]\" /></td>
320 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'color', $lang['font_color']) . "</td>
321 <td><input name=\"css[$descriptor[descriptor] a:link][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_color]\" /></td>
324 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'text-decoration', $lang['text_decoration']) . "</td>
325 <td><input name=\"css[$descriptor[descriptor] a:link][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_text_decoration]\" /></td>
333 <legend><strong>$lang[links_visited]</strong></legend>
335 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
337 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'background', $lang['background']) . "</td>
338 <td><input name=\"css[$descriptor[descriptor] a:visited][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_background]\" /></td>
341 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'color', $lang['font_color']) . "</td>
342 <td><input name=\"css[$descriptor[descriptor] a:visited][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_color]\" /></td>
345 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'text-decoration', $lang['text_decoration']) . "</td>
346 <td><input name=\"css[$descriptor[descriptor] a:visited][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_text_decoration]\" /></td>
354 <legend><strong>$lang[links_hover]</strong></legend>
356 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
358 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'background', $lang['background']) . "</td>
359 <td><input name=\"css[$descriptor[descriptor] a:hover][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_background]\" /></td>
362 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'color', $lang['font_color']) . "</td>
363 <td><input name=\"css[$descriptor[descriptor] a:hover][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_color]\" /></td>
366 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'text-decoration', $lang['text_decoration']) . "</td>
367 <td><input name=\"css[$descriptor[descriptor] a:hover][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_text_decoration]\" /></td>
376 $print->row_span($html, 'alt2', 'left', 1);
379 <div class="alt1" style="border: inset 1px; padding: 2px 5px 2px 5px; float: left">' . $lang['css_selector'] . ': <code>' . $descriptor['descriptor'] . '</code></div>
380 <input type="submit" name="submit" value="' . $lang['save_css'] . '" class="button" />', 'tfoot', 'right', 1);
386 // ###################################################################
388 * Returns the value of a given descriptor and property by comparing
389 * the mater set and custom set then returning the right one
393 * @param string Descriptor
394 * @param string Property
396 * @return string Value of the given property
398 function fetch_value($descriptor, $property)
400 if (!isset($this->customdata
["$descriptor"]["$property"]))
402 return $this->masterdata
["$descriptor"]["$property"];
406 return $this->customdata
["$descriptor"]["$property"];
410 // ###################################################################
412 * Returns the state modified state (false for untouched and true
413 * for modified) from the descriptor-property value between the master
414 * set and the custom set of data
418 * @param string Descriptor
419 * @param string Property
421 * @return bool Modified from the master value?
423 function fetch_modified_status($descriptor, $property)
425 if ($this->masterdata
["$descriptor"]["$property"] != $this->customdata
["$descriptor"]["$property"] AND isset($this->customdata
["$descriptor"]["$property"]))
433 // ###################################################################
435 * Fetches a link that shows a revert link for a given property
436 * that uses AJAX to revert when clicked
440 * @param string Descriptor
441 * @param string Property
442 * @param string Nominalized text
444 * @return string Output HTML
446 function fetch_modified_link($descriptor, $property, $name)
448 $status = $this->fetch_modified_status($descriptor, $property);
452 if (is_callable($this->fetch_modified_link_hook
))
454 return call_user_func($this->fetch_modified_link_hook
, $descriptor, $property, $name);
458 trigger_error('Printer_CSS::fetch_modified_link() needs to have the fetch_modified_link_hook( $descriptor , $property , $name ) defined', E_USER_ERROR
);
467 // ###################################################################
469 * Generates an array of queries that should be run on your database to
470 * update CSS changes. All of the queries have sprintf() markers that
471 * need to be evaluated:
473 * %1$s - Database table
474 * %2$s - styleid field
475 * %3$s - descriptor field
476 * %4$s - property field
478 * %6$d - Styleid value
482 * @param array Array of user-inputted information to be transformed into queries
484 * @return array Queries that need to be evaluated then ran
486 function generate_change_query($data)
488 $queries[0] = '--- RESERVED FOR LATER USE ---';
492 foreach ($this->descriptors
AS $descriptor => $opts)
494 $dolink = $opts['dolink'];
498 $loops = array('', ' a:link', ' a:visited', ' a:hover');
505 foreach ($loops AS $sel)
507 foreach ($data["$descriptor$sel"] AS $prop => $value)
509 // the given value matches the master -- no change
510 if ($this->masterdata["$descriptor$sel"]["$prop"] == $value)
514 // the given matches the custom -- no change
515 else if (isset($this->customdata["$descriptor$sel"]["$prop"]) AND $this->customdata["$descriptor$sel"]["$prop"] == $value)
519 // no matching, it's new
522 $value = str_replace('%', '%%', $value);
523 $deletes[] = "%
3\$s
= '" . $this->escape($descriptor . $sel) . "' AND %
4\$s
= '" . $this->escape($prop) . "'";
524 $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) . "')";
530 if (sizeof($deletes) < 1)
536 $queries[0] = "DELETE FROM %
1\$s WHERE styleid
= %
6\$d
AND ((" . implode(') OR (', $deletes) . "))";
542 // ###################################################################
544 * Wrapper for $this->registry->modules[ISSO_DB_LAYER]->escape_string()
548 * @param string Unprotected string
550 * @return string Sanitized string
552 function escape($string)
554 return $this->registry->modules[ISSO_DB_LAYER]->escape_string($string);
557 // ###################################################################
559 * Generates a linkable/usable CSS stylehseet content file; this can
560 * be outputted to the browser
564 * @return string CSS output
566 function generate_css_output()
570 foreach ($this->descriptors AS $descriptor => $opts)
572 $dolink = $opts['dolink'];
576 $loops = array('', ' a:link', ' a:visited', ' a:hover');
583 foreach ($loops AS $sel)
585 foreach ($this->masterdata["$descriptor$sel"] AS $prop => $value)
587 $data["$descriptor$sel"]["$prop"] = $value;
589 if (is_array($this->customdata
["$descriptor$sel"]))
591 foreach ($this->customdata["$descriptor$sel"] AS $prop => $value)
593 $data["$descriptor$sel"]["$prop"] = $value;
599 $output = '/* CSS Style Sheet (generated by ISSO.Printer.CSS $Revision$) */';
601 foreach ($data AS $selector => $props)
603 $output .= "\n\n$selector\n{";
604 foreach ($props AS $name => $value)
606 if ($name != 'extra' AND $value != '')
608 $output .= str_replace('"', '"', "\n\t$name: $value;");
614 $extra = explode("\n", $this->registry
->modules
['functions']->convert_line_breaks($props['extra']));
616 foreach ($extra AS $prop)
618 $output .= "\n\t$prop";