properties [$property]['value']) ? $this->properties [$property]['value'] : NULL); } /** * Get the value of a property. * * @param $property The property name * @param $properties Properties array to query the value from, * or NULL for using ours. * @return string The current value of the property */ public function getPropertyInternal($property, $properties=NULL) { if ( !isset($properties) ) { return $this->properties [$property]['value']; } else { return $properties [$property]['value']; } } /** * Get the value of a property. * * @param $property The property name * @return string The current value of the property */ public function getPropertySection($property) { return $this->properties [$property]['section']; } /** * Create new style by importing ODT style definition. * * @param $xmlCode Style definition in ODT XML format * @return ODTStyle New specific style */ static public function importODTStyle($xmlCode) { $matches = array(); $pattern = '/<(\w)+[^\s\/>]+/'; if (preg_match ($pattern, $xmlCode, $matches) !== 1) { return NULL; } $element = trim ($matches [0], '"<>'); $style = NULL; switch ($element) { case 'style:style': case 'style:default-style': $style = ODTStyleStyle::importODTStyle($xmlCode); break; case 'text:outline-style': $style = ODTTextOutlineStyle::importODTStyle($xmlCode); break; case 'text:list-style': $style = ODTTextListStyle::importODTStyle($xmlCode); break; case 'style:master-page': $style = ODTMasterPageStyle::importODTStyle($xmlCode); break; case 'style:page-layout': $style = ODTPageLayoutStyle::importODTStyle($xmlCode); break; default: break; } if ( isset($style) ) { return $style; } // Unknown/not implemented style. // Create generic style which can not be changed. $unknown = ODTUnknownStyle::importODTStyle($xmlCode); $unknown->setElementName($element); return $unknown; } /** * Set a property. * * @param $property The name of the property to set * @param $value New value to set */ protected function setPropertyInternal($property, $odt_property, $value, $section, &$dest=NULL) { if (isset($value)) { if ( !isset($dest) ) { $this->properties [$property] = array ('odt_property' => $odt_property, 'value' => $value, 'section' => $section); } else { $dest [$property] = array ('odt_property' => $odt_property, 'value' => $value, 'section' => $section); } } else { if ( !isset($dest) ) { unset ($this->properties [$property]); } else { unset ($dest [$property]); } } } /** * Import ODT style definition according to given fields into given style. * * @param $style ODTStyle object for storing the properties * @param $fields Properties accepted by the object/class * @param $xmlCode Style definition in ODT XML format * @return integer Number of meaningful properties found */ protected function importODTStyleInternal(array $fields, $xmlCode, &$properties=NULL) { $attrs = 0; foreach ($fields as $property => $field) { // The pattern is specified in that way that it also reads in empty attributes. // Sometimes an empty attribute is not the same as an not existing one. E.g. // in ODT XML '' // has NOT the same meaning as ''!!! // So DO NOT change the '*' in the pattern to '+'! if (preg_match ('/'.$field[0].'="[^"]*"/', $xmlCode, $matches) === 1) { $value = substr ($matches [0], strlen($field[0].'="')); $value = trim ($value, '"<>'); $this->setPropertyInternal($property, $field[0], $value, $field[1], $properties); if ( $field[2] == true ) { $attrs++; } } } return $attrs; } /** * Set style properties by importing values from a properties array. * Properties might be disabled by setting them in $disabled. * The style must have been previously created. Only those properties * will be accepted that are mentioned in the fields array. * * @param $style ODTStyle object for storing the properties * @param $fields Properties accepted by the object/class * @param $properties Properties to be imported * @param $disabled Properties to be ignored */ protected function importPropertiesInternal(array $fields, $properties, $disabled, &$dest=NULL) { foreach ($properties as $property => $value) { if ($disabled [$property] == 0 && array_key_exists ($property, $fields)) { $this->setPropertyInternal($property, $fields[$property][0], $value, $fields[$property][1], $dest); } } } /** * Is this style a default style? * Needs to be overwritten if a style could also be a default style. * * @return boolean Always false. */ public function isDefault() { return false; } /** * This function creates a new style name. All functions of this class which create a new * style/style name shall use this function to create the style name. By doing so it is * guaranteed that all style names created by this class are unique. * * The function returns the name of the new style or NULL if all relevant properties are empty. */ public static function getNewStylename ($type = '') { self::$style_count++; $style_name = self::$style_base_name.$type.'_'.self::$style_count; return $style_name; } }