fetch_modified_link_hook - Required hook that is run when * preparing revert links for properties * * @author Iris Studios, Inc. * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc. * @version $Revision$ * @package ISSO * */ class Printer_CSS { /** * Framework registry object * @var object * @access private */ var $registry = null; /** * CSS block list * @var array * @access private */ var $descriptors = array(); /** * Master data set * @var array * @access private */ var $masterdata = array(); /** * Cutomized data set * @var array * @access private */ var $customdata = array(); /** * Valid properties that can be used in CSS * @var array * @access private */ var $properties = array( 'background' => 'background', 'color' => 'color', 'font-style' => 'font_style', 'font-size' => 'font_size', 'font-family' => 'font_family', 'text-decoration' => 'text_decoration' ); /** * Hook ran in fetch_modified_link; takes three params: $descriptor, $property, $name * @var string * @access private */ var $fetch_modified_link_hook = ':=NO METHOD=:'; /** * Module fields * @var array * @access private */ var $fields = array( 'fetch_modified_link_hook' => array(REQ_YES, null, false) ); // ################################################################### /** * Constructor */ function __construct(&$registry) { $this->registry =& $registry; } // ################################################################### /** * (PHP 4) Constructor */ function Printer_CSS(&$registry) { $this->__construct($registry); } // ################################################################### /** * Sets an ISSO field * * @access public * * @param string Field name * @param mixed Value of the field */ function set($name, $value) { $this->registry->do_set($name, $value, 'printer_css'); } // ################################################################### /** * Gets an ISSO field * * @access public * * @param string Field name * * @return mixed Value of the field */ function get($fieldname) { return $this->registry->do_get($fieldname, 'printer_css'); } // ################################################################### /** * Adds a CSS information block to the array for later use * * @access public * * @param string Block title to display in thead * @param string CSS class/descriptor/element name * @param bool Show the link CSS information */ function add_block($title, $descriptor, $dolink) { if (isset($this->descriptors["$descriptor"])) { trigger_error('The descriptor `' . $descriptor . '` already exists', E_USER_WARNING); return; } $this->descriptors["$descriptor"] = array( 'title' => $title, 'descriptor' => $descriptor, 'dolink' => $dolink ); } // ################################################################### /** * Sets a master data key for a given descriptor and property * * @access public * * @param string Descriptor * @param string Property * @param string Value */ function set_master_data($descriptor, $property, $value) { $this->masterdata["$descriptor"]["$property"] = $value; } // ################################################################### /** * Sets a custom data key for a given descriptor and property * * @access public * * @param string Descriptor * @param string Property * @param string Value */ function set_custom_data($descriptor, $property, $value) { $this->customdata["$descriptor"]["$property"] = $value; } // ################################################################### /** * Generates the HTML needed to output the CSS editing blocks; this is * done in the form of using ISSO.Printer * * @access public */ function generate_blocks() { $print =& $this->registry->modules['printer']; $lang = array( 'standard_css_attributes' => $this->registry->modules['localize']->string('Standard CSS Attributes'), 'extra_css_attributes' => $this->registry->modules['localize']->string('Extra CSS Attributes'), 'links_normal' => $this->registry->modules['localize']->string('Normal CSS Links'), 'links_visited' => $this->registry->modules['localize']->string('Visited CSS Links'), 'links_hover' => $this->registry->modules['localize']->string('Hover CSS Links'), 'background' => $this->registry->modules['localize']->string('Background'), 'font_color' => $this->registry->modules['localize']->string('Font Color'), 'font_style' => $this->registry->modules['localize']->string('Font Style'), 'font_size' => $this->registry->modules['localize']->string('Font Size'), 'font_family' => $this->registry->modules['localize']->string('Font Family'), 'text_decoration' => $this->registry->modules['localize']->string('Text Decoration'), 'css_selector' => $this->registry->modules['localize']->string('CSS Selector'), 'save_css' => $this->registry->modules['localize']->string('Save CSS') ); foreach ($this->descriptors AS $descriptor) { $value = array(); $status = array(); $desc = $descriptor['descriptor']; $print->table_start(); $print->table_head($descriptor['title']); foreach ($this->properties AS $prop => $name) { $value["$name"] = $this->fetch_value($descriptor['descriptor'], $prop); $status["$name"] = $this->fetch_modified_status($descriptor['descriptor'], $prop); } $value['extra'] = $this->fetch_value($descriptor['descriptor'], 'extra'); $html = "
$lang[standard_css_attributes]
" . $this->fetch_modified_link($desc, 'background', $lang['background']) . "
" . $this->fetch_modified_link($desc, 'color', $lang['font_color']) . "
" . $this->fetch_modified_link($desc, 'font-style', $lang['font_style']) . "
" . $this->fetch_modified_link($desc, 'font-size', $lang['font_size']) . "
" . $this->fetch_modified_link($desc, 'font-family', $lang['font_family']) . "
" . $this->fetch_modified_link($desc, 'extra', $lang['extra_css_attributes']) . "
"; if ($descriptor['dolink']) { foreach (array('a:link' => 'a_link', 'a:visited' => 'a_visited', 'a:hover' => 'a_hover') AS $sel => $selname) { foreach (array('background' => 'background', 'color' => 'color', 'text-decoration' => 'text_decoration') AS $prop => $name) { $value["{$selname}_{$name}"] = $this->fetch_value($descriptor['descriptor'] . ' ' . $sel, $prop); $status["{$selname}_{$name}"] = $this->fetch_modified_status($descriptor['descriptor'] . ' ' . $sel, $prop); } } $html .= "
$lang[links_normal]
" . $this->fetch_modified_link($desc . ' a:link', 'background', $lang['background']) . "
" . $this->fetch_modified_link($desc . ' a:link', 'color', $lang['font_color']) . "
" . $this->fetch_modified_link($desc . ' a:link', 'text-decoration', $lang['text_decoration']) . "
$lang[links_visited]
" . $this->fetch_modified_link($desc . ' a:visited', 'background', $lang['background']) . "
" . $this->fetch_modified_link($desc . ' a:visited', 'color', $lang['font_color']) . "
" . $this->fetch_modified_link($desc . ' a:visited', 'text-decoration', $lang['text_decoration']) . "
$lang[links_hover]
" . $this->fetch_modified_link($desc . ' a:hover', 'background', $lang['background']) . "
" . $this->fetch_modified_link($desc . ' a:hover', 'color', $lang['font_color']) . "
" . $this->fetch_modified_link($desc . ' a:hover', 'text-decoration', $lang['text_decoration']) . "
"; } $print->row_span($html, 'alt2', 'left', 1); $print->row_span('
' . $lang['css_selector'] . ': ' . $descriptor['descriptor'] . '
', 'tfoot', 'right', 1); $print->table_end(); } } // ################################################################### /** * Returns the value of a given descriptor and property by comparing * the mater set and custom set then returning the right one * * @access private * * @param string Descriptor * @param string Property * * @return string Value of the given property */ function fetch_value($descriptor, $property) { if (!isset($this->customdata["$descriptor"]["$property"])) { return $this->masterdata["$descriptor"]["$property"]; } else { return $this->customdata["$descriptor"]["$property"]; } } // ################################################################### /** * Returns the state modified state (false for untouched and true * for modified) from the descriptor-property value between the master * set and the custom set of data * * @access private * * @param string Descriptor * @param string Property * * @return bool Modified from the master value? */ function fetch_modified_status($descriptor, $property) { if ($this->masterdata["$descriptor"]["$property"] != $this->customdata["$descriptor"]["$property"] AND isset($this->customdata["$descriptor"]["$property"])) { return true; } return false; } // ################################################################### /** * Fetches a link that shows a revert link for a given property * that uses AJAX to revert when clicked * * @access private * * @param string Descriptor * @param string Property * @param string Nominalized text * * @return string Output HTML */ function fetch_modified_link($descriptor, $property, $name) { $status = $this->fetch_modified_status($descriptor, $property); if ($status) { if (is_callable($this->fetch_modified_link_hook)) { return call_user_func($this->fetch_modified_link_hook, $descriptor, $property, $name); } else { trigger_error('Printer_CSS::fetch_modified_link() needs to have the fetch_modified_link_hook( $descriptor , $property , $name ) defined', E_USER_ERROR); } } else { return $name; } } // ################################################################### /** * Generates an array of queries that should be run on your database to * update CSS changes. All of the queries have sprintf() markers that * need to be evaluated: * * %1$s - Database table * %2$s - styleid field * %3$s - descriptor field * %4$s - property field * %5$s - value field * %6$d - Styleid value * * @access public * * @param array Array of user-inputted information to be transformed into queries * * @return array Queries that need to be evaluated then ran */ function generate_change_query($data) { $queries[0] = '--- RESERVED FOR LATER USE ---'; $deletes = array(); foreach ($this->descriptors AS $descriptor => $opts) { $dolink = $opts['dolink']; if ($dolink) { $loops = array('', ' a:link', ' a:visited', ' a:hover'); } else { $loops = array(''); } foreach ($loops AS $sel) { foreach ($data["$descriptor$sel"] AS $prop => $value) { // the given value matches the master -- no change if ($this->masterdata["$descriptor$sel"]["$prop"] == $value) { continue; } // the given matches the custom -- no change else if (isset($this->customdata["$descriptor$sel"]["$prop"]) AND $this->customdata["$descriptor$sel"]["$prop"] == $value) { continue; } // no matching, it's new else { $value = str_replace('%', '%%', $value); $deletes[] = "%3\$s = '" . $this->escape($descriptor . $sel) . "' AND %4\$s = '" . $this->escape($prop) . "'"; $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) . "')"; } } } } if (sizeof($deletes) < 1) { $queries[0] = '##'; } else { $queries[0] = "DELETE FROM %1\$s WHERE styleid = %6\$d AND ((" . implode(') OR (', $deletes) . "))"; } return $queries; } // ################################################################### /** * Wrapper for $this->registry->modules[ISSO_DB_LAYER]->escape_string() * * @access private * * @param string Unprotected string * * @return string Sanitized string */ function escape($string) { return $this->registry->modules[ISSO_DB_LAYER]->escape_string($string); } // ################################################################### /** * Generates a linkable/usable CSS stylehseet content file; this can * be outputted to the browser * * @access public * * @return string CSS output */ function generate_css_output() { $data = array(); foreach ($this->descriptors AS $descriptor => $opts) { $dolink = $opts['dolink']; if ($dolink) { $loops = array('', ' a:link', ' a:visited', ' a:hover'); } else { $loops = array(''); } foreach ($loops AS $sel) { foreach ($this->masterdata["$descriptor$sel"] AS $prop => $value) { $data["$descriptor$sel"]["$prop"] = $value; } if (is_array($this->customdata["$descriptor$sel"])) { foreach ($this->customdata["$descriptor$sel"] AS $prop => $value) { $data["$descriptor$sel"]["$prop"] = $value; } } } } $output = '/* CSS Style Sheet (generated by ISSO.Printer.CSS $Revision$) */'; foreach ($data AS $selector => $props) { $output .= "\n\n$selector\n{"; foreach ($props AS $name => $value) { if ($name != 'extra' AND $value != '') { $output .= str_replace('"', '"', "\n\t$name: $value;"); } } if ($props['extra']) { $extra = explode("\n", $this->registry->modules['functions']->convert_line_breaks($props['extra'])); foreach ($extra AS $prop) { $output .= "\n\t$prop"; } } $output .= "\n}"; } return $output; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>