]>
src.bluestatic.org Git - isso.git/blob - printer_css.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
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
29 require_once('ISSO/Functions.php');
32 * Printer - CSS Blocks
34 * This framework works in conjunction with ISSO.Printer to create a unique
35 * CSS editor enviornment.
38 * $this->fetch_modified_link_hook - Required hook that is run when
39 * preparing revert links for properties
42 * @copyright Copyright ©2002 - [#]year[#], Blue Static
53 private $descriptors = array();
59 private $masterdata = array();
65 private $customdata = array();
68 * Valid properties that can be used in CSS
71 private $properties = array(
72 'background' => 'background',
74 'font-style' => 'font_style',
75 'font-size' => 'font_size',
76 'font-family' => 'font_family',
77 'text-decoration' => 'text_decoration'
81 * Hook ran in fetch_modified_link; takes three params: $descriptor, $property, $name
84 private $modifiedLinkHook = ':undefined:';
86 // ###################################################################
90 public function __construct()
92 BSRegister
::RequiredModules(array('Db', 'Printer'));
95 // ###################################################################
97 * Sets the function callback that creates a link for modified properties
98 * in the CSS blocks display. It should have the signature:
99 * public string _M(string $descriptor, string $property, string $name)
101 * @param string Callback function
103 public function setModifiedLinkHook($callback)
105 $this->modifiedLinkHook
= $callback;
108 // ###################################################################
110 * Adds a CSS information block to the array for later use
112 * @param string Block title to display in thead
113 * @param string CSS class/descriptor/element name
114 * @param bool Show the link CSS information
116 public function add_block($title, $descriptor, $dolink)
118 if (isset($this->descriptors
["$descriptor"]))
120 trigger_error('The descriptor "' . $descriptor . '" already exists');
124 $this->descriptors["$descriptor"] = array(
126 'descriptor' => $descriptor,
131 // ###################################################################
133 * Sets a master data key for a given descriptor and property
135 * @param string Descriptor
136 * @param string Property
137 * @param string Value
139 public function set_master_data($descriptor, $property, $value)
141 $this->masterdata
["$descriptor"]["$property"] = $value;
144 // ###################################################################
146 * Sets a custom data key for a given descriptor and property
148 * @param string Descriptor
149 * @param string Property
150 * @param string Value
152 public function set_custom_data($descriptor, $property, $value)
154 $this->customdata
["$descriptor"]["$property"] = $value;
157 // ###################################################################
159 * Generates the HTML needed to output the CSS editing blocks; this is
160 * done in the form of using ISSO.Printer
162 public function generate_blocks()
164 $print =& BSRegister
::GetType('Printer');
167 'standard_css_attributes' => _('Standard CSS Attributes'),
168 'extra_css_attributes' => _('Extra CSS Attributes'),
170 'links_normal' => _('Normal CSS Links'),
171 'links_visited' => _('Visited CSS Links'),
172 'links_hover' => _('Hover CSS Links'),
174 'background' => _('Background'),
175 'font_color' => _('Font Color'),
176 'font_style' => _('Font Style'),
177 'font_size' => _('Font Size'),
178 'font_family' => _('Font Family'),
180 'text_decoration' => _('Text Decoration'),
182 'css_selector' => _('CSS Selector'),
183 'save_css' => _('Save CSS')
186 foreach ($this->descriptors
AS $descriptor)
191 $desc = $descriptor['descriptor'];
193 $print->table_start();
194 $print->table_head($descriptor['title']);
196 foreach ($this->properties
AS $prop => $name)
198 $value["$name"] = $this->fetch_value($descriptor['descriptor'], $prop);
199 $status["$name"] = $this->fetch_modified_status($descriptor['descriptor'], $prop);
202 $value['extra'] = $this->fetch_value($descriptor['descriptor'], 'extra');
204 $html = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">
208 <legend><strong>$lang[standard_css_attributes]</strong></legend>
210 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
212 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'background', $lang['background']) . "</td>
213 <td><input name=\"css[$descriptor[descriptor]][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[background]\" /></td>
216 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'color', $lang['font_color']) . "</td>
217 <td><input name=\"css[$descriptor[descriptor]][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[color]\" /></td>
220 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-style', $lang['font_style']) . "</td>
221 <td><input name=\"css[$descriptor[descriptor]][font-style]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_style]\" /></td>
224 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-size', $lang['font_size']) . "</td>
225 <td><input name=\"css[$descriptor[descriptor]][font-size]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_size]\" /></td>
228 <td width=\"45%\">" . $this->fetch_modified_link($desc, 'font-family', $lang['font_family']) . "</td>
229 <td><input name=\"css[$descriptor[descriptor]][font-family]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_family]\" /></td>
236 <fieldset style=\"height: 115px\">
237 <legend><strong>" . $this->fetch_modified_link($desc, 'extra', $lang['extra_css_attributes']) . "</strong></legend>
238 <textarea name=\"css[$descriptor[descriptor]][extra]\" style=\"width: 100%; height: 90%\">$value[extra]</textarea>
243 if ($descriptor['dolink'])
245 foreach (array('a:link' => 'a_link', 'a:visited' => 'a_visited', 'a:hover' => 'a_hover') AS $sel => $selname)
247 foreach (array('background' => 'background', 'color' => 'color', 'text-decoration' => 'text_decoration') AS $prop => $name)
249 $value["{$selname}_{$name}"] = $this->fetch_value($descriptor['descriptor'] . ' ' . $sel, $prop);
250 $status["{$selname}_{$name}"] = $this->fetch_modified_status($descriptor['descriptor'] . ' ' . $sel, $prop);
256 <table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">
260 <legend><strong>$lang[links_normal]</strong></legend>
262 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
264 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'background', $lang['background']) . "</td>
265 <td><input name=\"css[$descriptor[descriptor] a:link][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_background]\" /></td>
268 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'color', $lang['font_color']) . "</td>
269 <td><input name=\"css[$descriptor[descriptor] a:link][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_color]\" /></td>
272 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:link', 'text-decoration', $lang['text_decoration']) . "</td>
273 <td><input name=\"css[$descriptor[descriptor] a:link][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_text_decoration]\" /></td>
281 <legend><strong>$lang[links_visited]</strong></legend>
283 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
285 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'background', $lang['background']) . "</td>
286 <td><input name=\"css[$descriptor[descriptor] a:visited][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_background]\" /></td>
289 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'color', $lang['font_color']) . "</td>
290 <td><input name=\"css[$descriptor[descriptor] a:visited][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_color]\" /></td>
293 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:visited', 'text-decoration', $lang['text_decoration']) . "</td>
294 <td><input name=\"css[$descriptor[descriptor] a:visited][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_text_decoration]\" /></td>
302 <legend><strong>$lang[links_hover]</strong></legend>
304 <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
306 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'background', $lang['background']) . "</td>
307 <td><input name=\"css[$descriptor[descriptor] a:hover][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_background]\" /></td>
310 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'color', $lang['font_color']) . "</td>
311 <td><input name=\"css[$descriptor[descriptor] a:hover][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_color]\" /></td>
314 <td width=\"45%\">" . $this->fetch_modified_link($desc . ' a:hover', 'text-decoration', $lang['text_decoration']) . "</td>
315 <td><input name=\"css[$descriptor[descriptor] a:hover][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_text_decoration]\" /></td>
324 $print->row_span($html, 'alt2', 'left', 1);
327 <div class="alt1" style="border: inset 1px; padding: 2px 5px 2px 5px; float: left">' . $lang['css_selector'] . ': <code>' . $descriptor['descriptor'] . '</code></div>
328 <input type="submit" name="submit" value="' . $lang['save_css'] . '" class="button" />', 'tfoot', 'right', 1);
334 // ###################################################################
336 * Returns the value of a given descriptor and property by comparing
337 * the mater set and custom set then returning the right one
339 * @param string Descriptor
340 * @param string Property
342 * @return string Value of the given property
344 private function fetch_value($descriptor, $property)
346 if (!isset($this->customdata
["$descriptor"]["$property"]))
348 return $this->masterdata
["$descriptor"]["$property"];
352 return $this->customdata
["$descriptor"]["$property"];
356 // ###################################################################
358 * Returns the state modified state (false for untouched and true
359 * for modified) from the descriptor-property value between the master
360 * set and the custom set of data
362 * @param string Descriptor
363 * @param string Property
365 * @return bool Modified from the master value?
367 private function fetch_modified_status($descriptor, $property)
369 return ($this->masterdata
["$descriptor"]["$property"] != $this->customdata
["$descriptor"]["$property"] AND isset($this->customdata
["$descriptor"]["$property"]));
372 // ###################################################################
374 * Fetches a link that shows a revert link for a given property
375 * that uses AJAX to revert when clicked
377 * @param string Descriptor
378 * @param string Property
379 * @param string Nominalized text
381 * @return string Output HTML
383 private function fetch_modified_link($descriptor, $property, $name)
385 $status = $this->fetch_modified_status($descriptor, $property);
389 if (is_callable($this->modifiedLinkHook
))
391 return call_user_func($this->modifiedLinkHook
, $descriptor, $property, $name);
395 trigger_error('Printer_CSS::fetch_modified_link() needs to have the fetchModifiedLinkHook( $descriptor , $property , $name ) defined');
404 // ###################################################################
406 * Generates an array of queries that should be run on your database to
407 * update CSS changes. All of the queries have sprintf() markers that
408 * need to be evaluated:
410 * %1$s - Database table
411 * %2$s - styleid field
412 * %3$s - descriptor field
413 * %4$s - property field
415 * %6$d - Styleid value
417 * @param array Array of user-inputted information to be transformed into queries
419 * @return array Queries that need to be evaluated then ran
421 public function generate_change_query($data)
423 $queries[0] = '--- RESERVED FOR LATER USE ---';
427 foreach ($this->descriptors
AS $descriptor => $opts)
429 $dolink = $opts['dolink'];
433 $loops = array('', ' a:link', ' a:visited', ' a:hover');
440 foreach ($loops AS $sel)
442 foreach ($data["$descriptor$sel"] AS $prop => $value)
444 // the given value matches the master -- no change
445 if ($this->masterdata["$descriptor$sel"]["$prop"] == $value)
449 // the given matches the custom -- no change
450 else if (isset($this->customdata["$descriptor$sel"]["$prop"]) AND $this->customdata["$descriptor$sel"]["$prop"] == $value)
454 // no matching, it's new
457 $value = str_replace('%', '%%', $value);
458 $deletes[] = "%
3\$s
= '" . $this->_escape($descriptor . $sel) . "' AND %
4\$s
= '" . $this->_escape($prop) . "'";
459 $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) . "')";
465 if (sizeof($deletes) < 1)
471 $queries[0] = "DELETE FROM %
1\$s WHERE styleid
= %
6\$d
AND ((" . implode(') OR (', $deletes) . "))";
477 // ###################################################################
479 * Wrapper for BSDb->escapeString()
481 * @param string Unprotected string
483 * @return string Sanitized string
485 private function _escape($string)
487 return BSRegister::GetType('Db')->escapeString($string);
490 // ###################################################################
492 * Generates a linkable/usable CSS stylehseet content file; this can
493 * be outputted to the browser
495 * @return string CSS output
497 public function generate_css_output()
501 foreach ($this->descriptors AS $descriptor => $opts)
503 $dolink = $opts['dolink'];
507 $loops = array('', ' a:link', ' a:visited', ' a:hover');
514 foreach ($loops AS $sel)
516 foreach ($this->masterdata["$descriptor$sel"] AS $prop => $value)
518 $data["$descriptor$sel"]["$prop"] = $value;
520 if (is_array($this->customdata
["$descriptor$sel"]))
522 foreach ($this->customdata["$descriptor$sel"] AS $prop => $value)
524 $data["$descriptor$sel"]["$prop"] = $value;
530 $output = '/* CSS Style Sheet (generated by ISSO.Printer.CSS $Revision$) */';
532 foreach ($data AS $selector => $props)
534 $output .= "\n\n$selector\n{";
535 foreach ($props AS $name => $value)
537 if ($name != 'extra' AND $value != '')
539 $output .= str_replace('"', '"', "\n\t$name: $value;");
545 $extra = explode("\n", BSFunctions
::ConvertLineBreaks($props['extra']));
547 foreach ($extra AS $prop)
549 $output .= "\n\t$prop";
560 /*=====================================================================*\
561 || ###################################################################
564 || ###################################################################
565 \*=====================================================================*/