+++ /dev/null
-<?php
-/*=====================================================================*\
-|| ###################################################################
-|| # Blue Static ISSO Framework
-|| # Copyright (c)2002-2007 Blue Static
-|| #
-|| # This program is free software; you can redistribute it and/or modify
-|| # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version 2 of the License.
-|| #
-|| # This program is distributed in the hope that it will be useful, but
-|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-|| # more details.
-|| #
-|| # You should have received a copy of the GNU General Public License along
-|| # with this program; if not, write to the Free Software Foundation, Inc.,
-|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-|| ###################################################################
-\*=====================================================================*/
-
-/**
-* Printer: CSS Editor (PrinterCss.php)
-*
-* @package ISSO
-*/
-
-require_once(ISSO . '/Functions.php');
-
-/**
-* Printer: CSS Editor
-*
-* This framework works in conjunction with BSPrinter to create a
-* CSS editor enviornment.
-*
-* Hooks:
-* $this->_fetchModifiedLinkHook - Required hook that is run when
-* preparing revert links for properties
-*
-* @author Blue Static
-* @copyright Copyright (c)2002 - 2007, Blue Static
-* @package ISSO
-*
-*/
-class BSPrinterCss
-{
- /**
- * CSS block list
- * @var array
- */
- private $descriptors = array();
-
- /**
- * Master data set
- * @var array
- */
- private $masterdata = array();
-
- /**
- * Cutomized data set
- * @var array
- */
- private $customdata = array();
-
- /**
- * Valid properties that can be used in CSS
- * @var array
- */
- private $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 _fetchModifiedLink; takes three params: $descriptor, $property, $name
- * @var string
- */
- private $modifiedLinkHook = ':undefined:';
-
- // ###################################################################
- /**
- * Constructor
- */
- public function __construct()
- {
- BSApp::RequiredModules(array('Db', 'Printer'));
- }
-
- // ###################################################################
- /**
- * Sets the function callback that creates a link for modified properties
- * in the CSS blocks display. It should have the signature:
- * public string _M(string $descriptor, string $property, string $name)
- *
- * @param string Callback function
- */
- public function setModifiedLinkHook($callback)
- {
- $this->modifiedLinkHook = $callback;
- }
-
- // ###################################################################
- /**
- * Adds a CSS information block to the array for later use
- *
- * @param string Block title to display in thead
- * @param string CSS class/descriptor/element name
- * @param bool Show the link CSS information
- */
- public function addBlock($title, $descriptor, $dolink)
- {
- if (isset($this->descriptors["$descriptor"]))
- {
- trigger_error('The descriptor "' . $descriptor . '" already exists');
- return;
- }
-
- $this->descriptors["$descriptor"] = array(
- 'title' => $title,
- 'descriptor' => $descriptor,
- 'dolink' => $dolink
- );
- }
-
- // ###################################################################
- /**
- * Sets a master data key for a given descriptor and property
- *
- * @param string Descriptor
- * @param string Property
- * @param string Value
- */
- public function setMasterData($descriptor, $property, $value)
- {
- $this->masterdata["$descriptor"]["$property"] = $value;
- }
-
- // ###################################################################
- /**
- * Sets a custom data key for a given descriptor and property
- *
- * @param string Descriptor
- * @param string Property
- * @param string Value
- */
- public function setCustomData($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 BSPrinter
- */
- public function printEditor()
- {
- $lang = array(
- 'standard_css_attributes' => _('Standard CSS Attributes'),
- 'extra_css_attributes' => _('Extra CSS Attributes'),
-
- 'links_normal' => _('Normal CSS Links'),
- 'links_visited' => _('Visited CSS Links'),
- 'links_hover' => _('Hover CSS Links'),
-
- 'background' => _('Background'),
- 'font_color' => _('Font Color'),
- 'font_style' => _('Font Style'),
- 'font_size' => _('Font Size'),
- 'font_family' => _('Font Family'),
-
- 'text_decoration' => _('Text Decoration'),
-
- 'css_selector' => _('CSS Selector'),
- 'save_css' => _('Save CSS')
- );
-
- foreach ($this->descriptors AS $descriptor)
- {
- $value = array();
- $status = array();
-
- $desc = $descriptor['descriptor'];
-
- $table = new BSPrinterRootElementTable();
- $head = new BSPrinterTableElement(new BSPrinterLabelElement($descriptor['title']));
- $head->setCssClass('tcat');
- $table->addHeadingChild($head);
-
- foreach ($this->properties AS $prop => $name)
- {
- $value["$name"] = $this->_fetchValue($descriptor['descriptor'], $prop);
- $status["$name"] = $this->_fetchModifiedStatus($descriptor['descriptor'], $prop);
- }
-
- $value['extra'] = $this->_fetchValue($descriptor['descriptor'], 'extra');
-
- $html = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">
-<tr valign=\"top\">
- <td width=\"50%\">
- <fieldset>
- <legend><strong>$lang[standard_css_attributes]</strong></legend>
-
- <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc, 'background', $lang['background']) . "</td>
- <td><input name=\"css[$descriptor[descriptor]][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[background]\" /></td>
- </tr>
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc, 'color', $lang['font_color']) . "</td>
- <td><input name=\"css[$descriptor[descriptor]][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[color]\" /></td>
- </tr>
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc, 'font-style', $lang['font_style']) . "</td>
- <td><input name=\"css[$descriptor[descriptor]][font-style]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_style]\" /></td>
- </tr>
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc, 'font-size', $lang['font_size']) . "</td>
- <td><input name=\"css[$descriptor[descriptor]][font-size]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_size]\" /></td>
- </tr>
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc, 'font-family', $lang['font_family']) . "</td>
- <td><input name=\"css[$descriptor[descriptor]][font-family]\" class=\"input\" style=\"width: 100%\" value=\"$value[font_family]\" /></td>
- </tr>
- </table>
- </fieldset>
- </td>
-
- <td>
- <fieldset style=\"height: 115px\">
- <legend><strong>" . $this->_fetchModifiedLink($desc, 'extra', $lang['extra_css_attributes']) . "</strong></legend>
- <textarea name=\"css[$descriptor[descriptor]][extra]\" style=\"width: 100%; height: 90%\">$value[extra]</textarea>
- </fieldset>
- </td>
-</tr>
-</table>";
- 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->_fetchValue($descriptor['descriptor'] . ' ' . $sel, $prop);
- $status["{$selname}_{$name}"] = $this->_fetchModifiedStatus($descriptor['descriptor'] . ' ' . $sel, $prop);
- }
- }
-
- $html .= "
-
-<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" width=\"100%\">
-<tr valign=\"top\">
- <td width=\"33%\">
- <fieldset>
- <legend><strong>$lang[links_normal]</strong></legend>
-
- <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc . ' a:link', 'background', $lang['background']) . "</td>
- <td><input name=\"css[$descriptor[descriptor] a:link][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_background]\" /></td>
- </tr>
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc . ' a:link', 'color', $lang['font_color']) . "</td>
- <td><input name=\"css[$descriptor[descriptor] a:link][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_color]\" /></td>
- </tr>
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc . ' a:link', 'text-decoration', $lang['text_decoration']) . "</td>
- <td><input name=\"css[$descriptor[descriptor] a:link][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_link_text_decoration]\" /></td>
- </tr>
- </table>
- </fieldset>
- </td>
-
- <td width=\"33%\">
- <fieldset>
- <legend><strong>$lang[links_visited]</strong></legend>
-
- <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc . ' a:visited', 'background', $lang['background']) . "</td>
- <td><input name=\"css[$descriptor[descriptor] a:visited][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_background]\" /></td>
- </tr>
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc . ' a:visited', 'color', $lang['font_color']) . "</td>
- <td><input name=\"css[$descriptor[descriptor] a:visited][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_color]\" /></td>
- </tr>
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc . ' a:visited', 'text-decoration', $lang['text_decoration']) . "</td>
- <td><input name=\"css[$descriptor[descriptor] a:visited][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_visited_text_decoration]\" /></td>
- </tr>
- </table>
- </fieldset>
- </td>
-
- <td width=\"33%\">
- <fieldset>
- <legend><strong>$lang[links_hover]</strong></legend>
-
- <table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc . ' a:hover', 'background', $lang['background']) . "</td>
- <td><input name=\"css[$descriptor[descriptor] a:hover][background]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_background]\" /></td>
- </tr>
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc . ' a:hover', 'color', $lang['font_color']) . "</td>
- <td><input name=\"css[$descriptor[descriptor] a:hover][color]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_color]\" /></td>
- </tr>
- <tr>
- <td width=\"45%\">" . $this->_fetchModifiedLink($desc . ' a:hover', 'text-decoration', $lang['text_decoration']) . "</td>
- <td><input name=\"css[$descriptor[descriptor] a:hover][text-decoration]\" class=\"input\" style=\"width: 100%\" value=\"$value[a_hover_text_decoration]\" /></td>
- </tr>
- </table>
- </fieldset>
- </td>
-</tr>
-</table>";
- }
-
- $row = new BSPrinterTableElement(new BSPrinterLabelElement($html));
- $row->setCssClass('alt2');
- $table->addChild($row);
-
- $row = new BSPrinterTableElement(new BSPrinterLabelElement('
- <div class="alt1" style="border: inset 1px; padding: 2px 5px 2px 5px; float: left">' . $lang['css_selector'] . ': <code>' . $descriptor['descriptor'] . '</code></div>
- <input type="submit" name="submit" value="' . $lang['save_css'] . '" class="button" />'));
- $row->setCssClass('tfoot');
- $row->setStyle(array('text-align' => 'right'));
- $table->addChild($row)
-
- echo $table->paint();
- }
- }
-
- // ###################################################################
- /**
- * Returns the value of a given descriptor and property by comparing
- * the mater set and custom set then returning the right one
- *
- * @param string Descriptor
- * @param string Property
- *
- * @return string Value of the given property
- */
- private function _fetchValue($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
- *
- * @param string Descriptor
- * @param string Property
- *
- * @return bool Modified from the master value?
- */
- private function _fetchModifiedStatus($descriptor, $property)
- {
- return ($this->masterdata["$descriptor"]["$property"] != $this->customdata["$descriptor"]["$property"] AND isset($this->customdata["$descriptor"]["$property"]));
- }
-
- // ###################################################################
- /**
- * Fetches a link that shows a revert link for a given property
- * that uses AJAX to revert when clicked
- *
- * @param string Descriptor
- * @param string Property
- * @param string Nominalized text
- *
- * @return string Output HTML
- */
- private function _fetchModifiedLink($descriptor, $property, $name)
- {
- $status = $this->_fetchModifiedStatus($descriptor, $property);
-
- if ($status)
- {
- if (is_callable($this->modifiedLinkHook))
- {
- return call_user_func($this->modifiedLinkHook, $descriptor, $property, $name);
- }
- else
- {
- trigger_error('BSPrinterCss::_fetchModifiedLink() needs to have the fetchModifiedLinkHook( $descriptor , $property , $name ) defined');
- }
- }
- 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
- *
- * @param array Array of user-inputted information to be transformed into queries
- *
- * @return array Queries that need to be evaluated then ran
- */
- public function fetchChangeQuery($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 BSDb->escapeString()
- *
- * @param string Unprotected string
- *
- * @return string Sanitized string
- */
- private function _escape($string)
- {
- return BSApp::GetType('Db')->escapeString($string);
- }
-
- // ###################################################################
- /**
- * Generates a linkable/usable CSS stylehseet content file; this can
- * be outputted to the browser
- *
- * @return string CSS output
- */
- public function fetchCssOutput()
- {
- $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 BSPrinterCss $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", BSFunctions::ConvertLineBreaks($props['extra']));
-
- foreach ($extra AS $prop)
- {
- $output .= "\n\t$prop";
- }
- }
-
- $output .= "\n}";
- }
-
- return $output;
- }
-}
-
-?>
\ No newline at end of file