style.cls.php
来自「国外很不错的一个开源OA系统Group-Office」· PHP 代码 · 共 1,622 行 · 第 1/3 页
PHP
1,622 行
"bottom" => array("width" => $this->__get("border_bottom_width"), "style" => $this->__get("border_bottom_style"), "color" => $this->__get("border_bottom_color")), "right" => array("width" => $this->__get("border_right_width"), "style" => $this->__get("border_right_style"), "color" => $this->__get("border_right_color")), "left" => array("width" => $this->__get("border_left_width"), "style" => $this->__get("border_left_style"), "color" => $this->__get("border_left_color"))); } /** * Return a single border property * * @return mixed */ protected function _get_border($side) { $color = $this->__get("border_" . $side . "_color"); return $this->__get("border_" . $side . "_width") . " " . $this->__get("border_" . $side . "_style") . " " . $color["hex"]; } /**#@+ * Return full border properties as a string * * Border properties are returned just as specified in CSS: * <pre>[width] [style] [color]</pre> * e.g. "1px solid blue" * * @link http://www.w3.org/TR/CSS21/box.html#border-shorthand-properties * @return string */ function get_border_top() { return $this->_get_border("top"); } function get_border_right() { return $this->_get_border("right"); } function get_border_bottom() { return $this->_get_border("bottom"); } function get_border_left() { return $this->_get_border("left"); } /**#@-*/ /** * Returns border spacing as an array * * The array has the format (h_space,v_space) * * @link http://www.w3.org/TR/CSS21/tables.html#propdef-border-spacing * @return array */ function get_border_spacing() { return explode(" ", $this->_props["border_spacing"]); } /** * Sets colour * * The colour parameter can be any valid CSS colour value * * @link http://www.w3.org/TR/CSS21/colors.html#propdef-color * @param string $colour */ function set_color($colour) { $col = $this->munge_colour($colour); if ( is_null($col) ) $col = self::$_defaults["color"]; $this->_props["color"] = $col["hex"]; } /** * Sets the background colour * * @link http://www.w3.org/TR/CSS21/colors.html#propdef-background-color * @param string $colour */ function set_background_color($colour) { $col = $this->munge_colour($colour); if ( is_null($col) ) $col = self::$_defaults["background_color"]; $this->_props["background_color"] = is_array($col) ? $col["hex"] : $col; } /** * Set the background image url * * @link http://www.w3.org/TR/CSS21/colors.html#background-properties * @param string $url */ function set_background_image($val) { if ( mb_strpos($val, "url") !== false ) { $val = preg_replace("/url\(['\"]?([^'\")]+)['\"]?\)/","\\1", trim($val)); } else { $val = "none"; } // Resolve the url now in the context of the current stylesheet $parsed_url = explode_url($val); if ( $parsed_url["protocol"] == "" && $this->_stylesheet->get_protocol() == "" ) $url = realpath($this->_stylesheet->get_base_path() . $parsed_url["file"]); else $url = build_url($this->_stylesheet->get_protocol(), $this->_stylesheet->get_host(), $this->_stylesheet->get_base_path(), $val); $this->_props["background_image"] = $url; } /** * Sets the font size * * $size can be any acceptable CSS size * * @link http://www.w3.org/TR/CSS21/fonts.html#propdef-font-size * @param string|float $size */ function set_font_size($size) { $this->__font_size_calculated = false; $this->_props["font_size"] = $size; } /**#@+ * Sets page break properties * * @link http://www.w3.org/TR/CSS21/page.html#page-breaks * @param string $break */ function set_page_break_before($break) { if ($break === "left" || $break === "right") $break = "always"; $this->_props["page_break_before"] = $break; } function set_page_break_after($break) { if ($break === "left" || $break === "right") $break = "always"; $this->_props["page_break_after"] = $break; } /**#@-*/ //........................................................................ /**#@+ * Sets the margin size * * @link http://www.w3.org/TR/CSS21/box.html#margin-properties * @param $val */ function set_margin_top($val) { $this->_props["margin_top"] = str_replace("none", "0px", $val); } function set_margin_right($val) { $this->_props["margin_right"] = str_replace("none", "0px", $val); } function set_margin_bottom($val) { $this->_props["margin_bottom"] = str_replace("none", "0px", $val); } function set_margin_left($val) { $this->_props["margin_left"] = str_replace("none", "0px", $val); } function set_margin($val) { $val = str_replace("none", "0px", $val); $margins = explode(" ", $val); switch (count($margins)) { case 1: $this->_props["margin_top"] = $margins[0]; $this->_props["margin_right"] = $margins[0]; $this->_props["margin_bottom"] = $margins[0]; $this->_props["margin_left"] = $margins[0]; break; case 2: $this->_props["margin_top"] = $margins[0]; $this->_props["margin_bottom"] = $margins[0]; $this->_props["margin_right"] = $margins[1]; $this->_props["margin_left"] = $margins[1]; break; case 3: $this->_props["margin_top"] = $margins[0]; $this->_props["margin_right"] = $margins[1]; $this->_props["margin_bottom"] = $margins[1]; $this->_props["margin_left"] = $margins[2]; break; case 4: $this->_props["margin_top"] = $margins[0]; $this->_props["margin_right"] = $margins[1]; $this->_props["margin_bottom"] = $margins[2]; $this->_props["margin_left"] = $margins[3]; break; default: break; } $this->_props["margin"] = $val; } /**#@-*/ /**#@+ * Sets the padding size * * @link http://www.w3.org/TR/CSS21/box.html#padding-properties * @param $val */ function set_padding_top($val) { $this->_props["padding_top"] = str_replace("none", "0px", $val); } function set_padding_right($val) { $this->_props["padding_right"] = str_replace("none", "0px", $val); } function set_padding_bottom($val) { $this->_props["padding_bottom"] = str_replace("none", "0px", $val); } function set_padding_left($val) { $this->_props["padding_left"] = str_replace("none", "0px", $val); } function set_padding($val) { $val = str_replace("none", "0px", $val); $paddings = explode(" ", $val); switch (count($paddings)) { case 1: $this->_props["padding_top"] = $paddings[0]; $this->_props["padding_right"] = $paddings[0]; $this->_props["padding_bottom"] = $paddings[0]; $this->_props["padding_left"] = $paddings[0]; break; case 2: $this->_props["padding_top"] = $paddings[0]; $this->_props["padding_bottom"] = $paddings[0]; $this->_props["padding_right"] = $paddings[1]; $this->_props["padding_left"] = $paddings[1]; break; case 3: $this->_props["padding_top"] = $paddings[0]; $this->_props["padding_right"] = $paddings[1]; $this->_props["padding_bottom"] = $paddings[1]; $this->_props["padding_left"] = $paddings[2]; break; case 4: $this->_props["padding_top"] = $paddings[0]; $this->_props["padding_right"] = $paddings[1]; $this->_props["padding_bottom"] = $paddings[2]; $this->_props["padding_left"] = $paddings[3]; break; default: break; } $this->_props["padding"] = $val; } /**#@-*/ /** * Sets a single border * * @param string $side * @param string $border_spec ([width] [style] [color]) */ protected function _set_border($side, $border_spec) { $border_spec = str_replace(",", " ", $border_spec); $arr = explode(" ", $border_spec); // FIXME: handle partial values $p = "border_" . $side; $p_width = $p . "_width"; $p_style = $p . "_style"; $p_color = $p . "_color"; foreach ($arr as $value) { $value = trim($value); if ( in_array($value, self::$BORDER_STYLES) ) { $this->_props[$p_style] = $value; } else if ( preg_match("/[.0-9]+(?:px|pt|pc|em|ex|%|in|mm|cm)|(?:none|normal|thin|medium|thick)/", $value ) ) { $this->_props[$p_width] = str_replace("none", "0px", $value); } else { // must be colour $this->_props[$p_color] = $value; } } $this->_props[$p] = $border_spec; } /**#@+ * Sets the border styles * * @link http://www.w3.org/TR/CSS21/box.html#border-properties * @param string $val */ function set_border_top($val) { $this->_set_border("top", $val); } function set_border_right($val) { $this->_set_border("right", $val); } function set_border_bottom($val) { $this->_set_border("bottom", $val); } function set_border_left($val) { $this->_set_border("left", $val); } function set_border($val) { $this->_set_border("top", $val); $this->_set_border("right", $val); $this->_set_border("bottom", $val); $this->_set_border("left", $val); $this->_props["border"] = $val; } function set_border_width($val) { $arr = explode(" ", $val); switch (count($arr)) { case 1: $this->_props["border_top_width"] = $arr[0]; $this->_props["border_right_width"] = $arr[0]; $this->_props["border_bottom_width"] = $arr[0]; $this->_props["border_left_width"] = $arr[0]; break; case 2: $this->_props["border_top_width"] = $arr[0]; $this->_props["border_bottom_width"] = $arr[0]; $this->_props["border_right_width"] = $arr[1]; $this->_props["border_left_width"] = $arr[1]; break; case 3: $this->_props["border_top_width"] = $arr[0]; $this->_props["border_right_width"] = $arr[1]; $this->_props["border_bottom_width"] = $arr[1]; $this->_props["border_left_width"] = $arr[2]; break; case 4: $this->_props["border_top_width"] = $arr[0]; $this->_props["border_right_width"] = $arr[1]; $this->_props["border_bottom_width"] = $arr[2]; $this->_props["border_left_width"] = $arr[3]; break; default: break; } $this->_props["border_width"] = $val; } function set_border_color($val) { $arr = explode(" ", $val); switch (count($arr)) { case 1: $this->_props["border_top_color"] = $arr[0]; $this->_props["border_right_color"] = $arr[0]; $this->_props["border_bottom_color"] = $arr[0]; $this->_props["border_left_color"] = $arr[0]; break; case 2: $this->_props["border_top_color"] = $arr[0]; $this->_props["border_bottom_color"] = $arr[0]; $this->_props["border_right_color"] = $arr[1]; $this->_props["border_left_color"] = $arr[1]; break; case 3: $this->_props["border_top_color"] = $arr[0]; $this->_props["border_right_color"] = $arr[1]; $this->_props["border_bottom_color"] = $arr[1]; $this->_props["border_left_color"] = $arr[2]; break; case 4: $this->_props["border_top_color"] = $arr[0]; $this->_props["border_right_color"] = $arr[1]; $this->_props["border_bottom_color"] = $arr[2]; $this->_props["border_left_color"] = $arr[3]; break; default: break; } $this->_props["border_color"] = $val; } function set_border_style($val) { $arr = explode(" ", $val); switch (count($arr)) { case 1: $this->_props["border_top_style"] = $arr[0]; $this->_props["border_right_style"] = $arr[0]; $this->_props["border_bottom_style"] = $arr[0]; $this->_props["border_left_style"] = $arr[0]; break; case 2: $this->_props["border_top_style"] = $arr[0]; $this->_props["border_bottom_style"] = $arr[0]; $this->_props["border_right_style"] = $arr[1]; $this->_props["border_left_style"] = $arr[1]; break; case 3: $this->_props["border_top_style"] = $arr[0]; $this->_props["border_right_style"] = $arr[1]; $this->_props["border_bottom_style"] = $arr[1]; $this->_props["border_left_style"] = $arr[2]; break; case 4: $this->_props["border_top_style"] = $arr[0]; $this->_props["border_right_style"] = $arr[1]; $this->_props["border_bottom_style"] = $arr[2]; $this->_props["border_left_style"] = $arr[3]; break; default: break; } $this->_props["border_style"] = $val; } /**#@-*/ /** * Sets the border spacing * * @link http://www.w3.org/TR/CSS21/box.html#border-properties * @param float $val */ function set_border_spacing($val) { $arr = explode(" ", $val); if ( count($arr) == 1 ) $arr[1] = $arr[0]; $this->_props["border_spacing"] = $arr[0] . " " . $arr[1]; } /** * Sets the list style image * * @link http://www.w3.org/TR/CSS21/generate.html#propdef-list-style-image * @param $val */ function set_list_style_image($val) { // Strip url(' ... ') from url values if ( mb_strpos($val, "url") !== false ) { $val = preg_replace("/url\(['\"]?([^'\")]+)['\"]?\)/","\\1", trim($val)); } else { $val = "none"; } $this->_props["list_style_image"] = $val; } /** * Sets the list style * * This is not currently implemented * * @link http://www.w3.org/TR/CSS21/generate.html#propdef-list-style * @param $val */ function set_list_style($val) { $arr = explode(" ", str_replace(",", " ", $val)); $types = array("disc", "circle", "square", "decimal", "decimal-leading-zero", "lower-roman", "upper-roman", "lower-greek", "lower-latin", "upper-latin", "armenian", "georgian", "lower-alpha", "upper-alpha", "none"); $positions = array("inside", "outside"); foreach ($arr as $value) { if ( mb_strpos($value, "url") !== false ) { $this->set_list_style_image($value); continue; } if ( in_array($value, $types) ) { $this->_props["list_style_type"] = $value; } else if ( in_array($value, $positions) ) { $this->_props["list_style_position"] = $value; } } } /** * Generate a string representation of the Style * * This dumps the entire property array into a string via print_r. Useful * for debugging. * * @return string */ function __toString() { return print_r(array_merge(array("parent_font_size" => $this->_parent_font_size), $this->_props), true); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?