Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

V2023 02 24+php8 corrections #287

Merged
merged 2 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ODT/ODTFootnote.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ODTFootnote
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function footnoteOpen(ODTInternalParams $params, $element=NULL, $attributes=NULL) {
static function footnoteOpen(ODTInternalParams $params, $element=NULL, $attributes=NULL) {
// $element and $attributes are actually unused

// Move current content to store and record footnote
Expand All @@ -40,7 +40,7 @@ function footnoteOpen(ODTInternalParams $params, $element=NULL, $attributes=NULL
*
* @author Andreas Gohr
*/
function footnoteClose(ODTInternalParams $params) {
static function footnoteClose(ODTInternalParams $params) {
// Close any open paragraph first
$params->document->paragraphClose();

Expand Down
12 changes: 10 additions & 2 deletions ODT/ODTIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,17 @@ protected static function getTOCBody(array $toc, $p_styles, $stylesLNames, $max_
// Only add the heading to the TOC if its <= $max_outline_level
if ( $params [3] <= $max_outline_level ) {
$level = $params [3];
$content .= '<text:p text:style-name="'.$p_styles [$level].'">';
$styleName = "";
if (isset($p_styles[$level])) {
$styleName = $p_styles[$level];
}
$content .= '<text:p text:style-name="'.$styleName.'">';
if ( $links == true ) {
$content .= '<text:a xlink:type="simple" xlink:href="#'.$params [0].'" text:style-name="'.$stylesLNames [$level].'" text:visited-style-name="'.$stylesLNames [$level].'">';
$styleLName = "";
if (isset($stylesLNames[$level])) {
$styleLName = $stylesLNames[$level];
}
$content .= '<text:a xlink:type="simple" xlink:href="#'.$params [0].'" text:style-name="'.$styleLName.'" text:visited-style-name="'.$styleLName.'">';
}
$content .= $params [2];
$content .= '<text:tab/>';
Expand Down
9 changes: 6 additions & 3 deletions ODT/ODTTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function tableOpen(ODTInternalParams $params, $maxcols = NULL, $nu
if (!isset($element)) {
$element = 'table';
}
$elementObj = $params->elementObj;
$elementObj = isset($params->elementObj) ? $params->elementObj : null;

// Close any open paragraph.
$params->document->paragraphClose();
Expand Down Expand Up @@ -398,7 +398,7 @@ public static function tableOpenUseCSS(ODTInternalParams $params, $maxcols=NULL,
* @param null $numrows
*/
public static function tableOpenUseProperties (ODTInternalParams $params, $properties, $maxcols = 0, $numrows = 0){
$elementObj = $params->elementObj;
$elementObj = isset($params->elementObj) ? $params->elementObj : null;

// Eventually adjust table width.
if ( !empty ($properties ['width']) ) {
Expand Down Expand Up @@ -426,7 +426,10 @@ public static function tableOpenUseProperties (ODTInternalParams $params, $prope
*/
public static function tableAddColumnUseProperties (ODTInternalParams $params, array $properties = NULL){
// Add column and set/query assigned style name
$styleName = $properties ['style-name'];
$styleName = null;
if (array_key_exists('style-name', $properties)) {
$styleName = $properties['style-name'];
}
$styleNameGet = '';
self::tableAddColumn ($params, $styleName, $styleNameGet);

Expand Down
6 changes: 3 additions & 3 deletions ODT/ODTUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ public static function deleteUselessElements(&$docContent, array $preventDeletet
public static function getImageSize($src, $maxwidth=NULL, $maxheight=NULL){
if (file_exists($src)) {
$info = getimagesize($src);
if(!$width){
if(!isset($width)){
$width = $info[0];
$height = $info[1];
}else{
} else {
$height = round(($width * $info[1]) / $info[0]);
}

Expand Down Expand Up @@ -434,7 +434,7 @@ public static function adjustValueForODT ($property, $value, ODTUnits $units) {

// If it is a short color value (#xxx) then convert it to long value (#xxxxxx)
// (ODT does not support the short form)
if ( $part [0] == '#' && $length == 4 ) {
if (isset($part[0]) && $part[0] == '#' && $length == 4 ) {
$part = '#'.$part [1].$part [1].$part [2].$part [2].$part [3].$part [3];
} else {
// If it is a CSS color name, get it's real color value
Expand Down
5 changes: 3 additions & 2 deletions ODT/css/cssimportnew.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function matches (array $attributes=NULL) {
switch ($this->operator) {
case '=':
// Attribute should have exactly the value $this->value
if ($attributes [$this->attribute] == $this->value) {
if (isset($attributes[$this->attribute]) && $attributes[$this->attribute] == $this->value) {
return true;
} else {
return false;
Expand Down Expand Up @@ -206,6 +206,7 @@ public function __construct($simple_selector_string) {

$content = '';
$first_sign = '';
$next_sign = '';
$first = true;
$pseudo_element = false;
while ($pos < $max) {
Expand Down Expand Up @@ -1259,7 +1260,7 @@ protected function inherit (array &$dest, array $parents) {
// (MUST be done backwards!)
$max = count ($parents);
foreach ($parents as $parent) {
$properties = $parent->getProperties ();
$properties = $parent->getProperties() ?? [];
foreach ($properties as $key => $value) {
if ($dest [$key] == 'inherit') {
$dest [$key] = $value;
Expand Down
14 changes: 9 additions & 5 deletions ODT/elements/ODTElementTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getOpeningTag () {
if (!isset($style_name)) {
$encoded = '<table:table>';
} else {
$encoded .= '<table:table table:style-name="'.$style_name.'">';
$encoded = '<table:table table:style-name="'.$style_name.'">';
}
$maxcols = $this->getTableMaxColumns();
$count = $this->getCount();
Expand Down Expand Up @@ -171,7 +171,7 @@ public function getTableColumnStyles() {
* @param array $value
*/
public function getTableColumnStyleName($column) {
return $this->table_column_styles [$column];
return $this->table_column_styles [$column] ?? null;
}

/**
Expand Down Expand Up @@ -331,12 +331,15 @@ public function getMaxWidthOfNestedContainer (ODTInternalParams $params, array $
} else if ($cell_style->getProperty('padding') != NULL) {
$value = $cell_style->getProperty('padding');
$value = $params->document->toPoints($value, 'y');
$padding += 2 * $value;
if (is_numeric($value)) {
$padding += 2 * $value;
}
}

$table_column_styles = $this->getTableColumnStyles();
$style_name = $table_column_styles [$column-1];
$style_obj = $params->document->getStyle($style_name);
$width = 0;
if (isset($style_obj)) {
$width = $style_obj->getProperty('column-width');
$width = trim ($width, 'pt');
Expand Down Expand Up @@ -425,6 +428,7 @@ public function adjustWidth (ODTInternalParams $params, $allowNested=false) {
$width = $this->adjustWidthInternal ($params, $max_width);

$style_obj = $params->document->getStyle($table_style_name);
$rel_width = 0;
if (isset($style_obj)) {
$style_obj->setProperty('width', $width.'pt');
if (!$this->isNested ()) {
Expand All @@ -436,7 +440,7 @@ public function adjustWidth (ODTInternalParams $params, $allowNested=false) {
}
} else {
// Calculate rel width in relation to maximum table width
if ($max_width != 0) {
if (is_numeric($max_width) && $max_width != 0) {
$rel_width = round(($width * 100)/$max_width);
}
}
Expand Down Expand Up @@ -466,7 +470,7 @@ public function adjustWidthInternal (ODTInternalParams $params, $maxWidth) {
$table_column_styles = $this->getTableColumnStyles();
$replace = true;
for ($index = 0 ; $index < $this->getTableMaxColumns() ; $index++ ) {
$style_name = $table_column_styles [$index];
$style_name = $table_column_styles [$index] ?? null;
$style_obj = $params->document->getStyle($style_name);
if (isset($style_obj)) {
if ($style_obj->getProperty('rel-column-width') != NULL) {
Expand Down
25 changes: 14 additions & 11 deletions ODT/styles/ODTParagraphStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function __construct() {
*/
public function importProperties($properties, $disabled=array()) {
foreach ($properties as $property => $value) {
if ($disabled [$property] == 0) {
if (isset($disabled[$property]) && $disabled[$property] == 0) {
$this->setProperty($property, $value);
}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ public function setProperty($property, $value) {
public function getProperty($property) {
$style_fields = ODTStyleStyle::getStyleProperties ();
if (array_key_exists ($property, $style_fields)) {
return $this->style_properties [$property]['value'];
return isset($this->style_properties[$property]['value']) ? $this->style_properties[$property]['value'] : null;
}
$paragraph_fields = self::$paragraph_fields;
if (array_key_exists ($property, $paragraph_fields)) {
Expand Down Expand Up @@ -333,20 +333,20 @@ public function toString() {
*/
public static function createParagraphStyle(array $properties, array $disabled_props = NULL, ODTDocument $doc=NULL){
// Convert 'text-decoration'.
if ( $properties ['text-decoration'] == 'line-through' ) {
if (isset($properties['text-decoration']) && $properties['text-decoration'] == 'line-through') {
$properties ['text-line-through-style'] = 'solid';
}
if ( $properties ['text-decoration'] == 'underline' ) {
if (isset($properties['text-decoration']) && $properties['text-decoration'] == 'underline') {
$properties ['text-underline-style'] = 'solid';
}
if ( $properties ['text-decoration'] == 'overline' ) {
if (isset($properties['text-decoration']) && $properties['text-decoration'] == 'overline') {
$properties ['text-overline-style'] = 'solid';
}

// If the property 'vertical-align' has the value 'sub' or 'super'
// then for ODT it needs to be converted to the corresponding 'text-position' property.
// Replace sub and super with text-position.
$valign = $properties ['vertical-align'];
$valign = isset($properties['vertical-align']) ? $properties['vertical-align'] : null;
if (!empty($valign)) {
if ( $valign == 'sub' ) {
$properties ['text-position'] = '-33% 100%';
Expand All @@ -358,8 +358,8 @@ public static function createParagraphStyle(array $properties, array $disabled_p
}

// Separate country from language
$lang = $properties ['lang'];
$country = $properties ['country'];
$lang = isset($properties['lang']) ? $properties['lang'] : null;
$country = isset($properties['country']) ? $properties['country'] : null;
if ( !empty($lang) ) {
$parts = preg_split ('/-/', $lang);
$lang = $parts [0];
Expand Down Expand Up @@ -391,10 +391,10 @@ public static function createParagraphStyle(array $properties, array $disabled_p
}

// Eventually create parent for font-size
$save = $disabled_props ['font-size'];
$save = isset($disabled_props['font-size']) ? $disabled_props['font-size'] : null;
$odt_fo_size = '';
if ( empty ($disabled_props ['font-size']) ) {
$odt_fo_size = $properties ['font-size'];
$odt_fo_size = isset($properties['font-size']) ? $properties['font-size'] : null;
}
$parent = '';
$length = strlen ($odt_fo_size);
Expand All @@ -411,7 +411,10 @@ public static function createParagraphStyle(array $properties, array $disabled_p
}

// Create style name (if not given).
$style_name = $properties ['style-name'];
$style_name = null;
if (array_key_exists('style-name', $properties)) {
$style_name = $properties ['style-name'] ?? null;
}
if ( empty($style_name) ) {
$style_name = self::getNewStylename ('Paragraph');
$properties ['style-name'] = $style_name;
Expand Down
4 changes: 2 additions & 2 deletions ODT/styles/ODTStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ abstract public function setProperty($property, $value);
* @return string The current value of the property
*/
public function getProperty($property) {
return (isset($this->properties [$property]['value']) ? $this->properties [$property]['value'] : NULL);
return $this->properties[$property]['value'] ?? null;
}

/**
Expand Down Expand Up @@ -217,7 +217,7 @@ protected function importODTStyleInternal(array $fields, $xmlCode, &$properties=
*/
protected function importPropertiesInternal(array $fields, $properties, $disabled, &$dest=NULL) {
foreach ($properties as $property => $value) {
if ($disabled [$property] == 0 && array_key_exists ($property, $fields)) {
if (isset($disabled[$property]) && $disabled[$property] == 0 && array_key_exists($property, $fields)) {
$this->setPropertyInternal($property, $fields[$property][0], $value, $fields[$property][1], $dest);
}
}
Expand Down
5 changes: 4 additions & 1 deletion ODT/styles/ODTTableCellStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ static public function getTableCellProperties () {
*/
public static function createTableCellStyle(array $properties, array $disabled_props = NULL){
// Create style name (if not given).
$style_name = $properties ['style-name'];
$style_name = null;
if (array_key_exists('style-name', $properties)) {
$style_name = $properties ['style-name'];
}
if ( empty($style_name) ) {
$style_name = self::getNewStylename ('TableCell');
$properties ['style-name'] = $style_name;
Expand Down
5 changes: 4 additions & 1 deletion ODT/styles/ODTTableColumnStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ public static function createTableColumnStyle(array $properties, array $disabled
}

// Convert width to ODT format
$table_co_width = $properties ['width'];
$table_co_width = null;
if (array_key_exists('width', $properties)) {
$table_co_width = $properties ['width'] ?? null;
}
if ( !empty ($table_co_width) ) {
$length = strlen ($table_co_width);
if ( $table_co_width [$length-1] != '%' ) {
Expand Down
9 changes: 6 additions & 3 deletions ODT/styles/ODTTableStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ public static function createTableTableStyle(array $properties, array $disabled_
if (empty($properties ['align'])) {
$properties ['align'] = 'center';
}
if ($properties ['margin-left'] == '0') {
if (isset($properties['margin-left']) && $properties['margin-left'] == '0') {
unset($properties ['margin-left']);
}
if ($properties ['margin-right'] == '0') {
if (isset($properties['margin-right']) && $properties['margin-right'] == '0') {
unset($properties ['margin-right']);
}

Expand All @@ -206,7 +206,10 @@ public static function createTableTableStyle(array $properties, array $disabled_
}

// Create style name (if not given).
$style_name = $properties ['style-name'];
$style_name = null;
if (array_key_exists('style-name', $properties)) {
$style_name = $properties['style-name'];
}
if ( empty($style_name) ) {
$style_name = self::getNewStylename ('Table');
$properties ['style-name'] = $style_name;
Expand Down
16 changes: 8 additions & 8 deletions ODT/styles/ODTTextStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,20 @@ static public function getTextProperties () {
*/
public static function createTextStyle(array $properties, array $disabled_props = NULL, ODTDocument $doc=NULL){
// Convert 'text-decoration'.
if ( $properties ['text-decoration'] == 'line-through' ) {
if (isset($properties['text-decoration']) && $properties['text-decoration'] == 'line-through') {
$properties ['text-line-through-style'] = 'solid';
}
if ( $properties ['text-decoration'] == 'underline' ) {
if (isset($properties['text-decoration']) && $properties['text-decoration'] == 'underline') {
$properties ['text-underline-style'] = 'solid';
}
if ( $properties ['text-decoration'] == 'overline' ) {
if (isset($properties['text-decoration']) && $properties['text-decoration'] == 'overline') {
$properties ['text-overline-style'] = 'solid';
}

// If the property 'vertical-align' has the value 'sub' or 'super'
// then for ODT it needs to be converted to the corresponding 'text-position' property.
// Replace sub and super with text-position.
$valign = $properties ['vertical-align'];
$valign = isset($properties['vertical-align']) ? $properties['vertical-align'] : '';
if (!empty($valign)) {
if ( $valign == 'sub' ) {
$properties ['text-position'] = '-33% 100%';
Expand All @@ -257,8 +257,8 @@ public static function createTextStyle(array $properties, array $disabled_props
}

// Separate country from language
$lang = $properties ['lang'];
$country = $properties ['country'];
$lang = isset($properties['lang']) ? $properties['lang'] : '';
$country = isset($properties['country']) ? $properties['country'] : '';
if ( !empty($lang) ) {
$parts = preg_split ('/-/', $lang);
$lang = $parts [0];
Expand All @@ -276,10 +276,10 @@ public static function createTextStyle(array $properties, array $disabled_props
}

// Extra handling for font-size in '%'
$save = $disabled_props ['font-size'];
$save = isset($disabled_props['font-size']) ? $disabled_props['font-size'] : '';
$odt_fo_size = '';
if ( empty ($disabled_props ['font-size']) ) {
$odt_fo_size = $properties ['font-size'];
$odt_fo_size = $properties['font-size'] ?? null;
}
$length = strlen ($odt_fo_size);
if ( $length > 0 && $odt_fo_size [$length-1] == '%' && isset($doc)) {
Expand Down
2 changes: 1 addition & 1 deletion ODT/styleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function addStyleInternal(&$dest, &$dest_by_name, ODTStyle $new, $overwri
// The key for a normal style is the name.
$name = $new->getProperty('style-name');

if (!isset($dest_by_name [$name])) {
if (!isset($dest_by_name[$name]) || $dest_by_name[$name] === null) {
$dest [] = $new;
if (!empty($name)) {
$dest_by_name [$name] = $new;
Expand Down
4 changes: 2 additions & 2 deletions helper/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ protected function loadIntern(&$warning, $refresh) {

// Check DokuWiki global configuration.
$dw_name = $this->hasDWGlobalSetting ($name);
if (!$value && isset($conf[$dw_name])) {
if (!$value && isset($conf[$dw_name]) && $conf[$dw_name] !== '') {
$this->setParam ($name, $conf[$dw_name]);
}

Expand All @@ -576,7 +576,7 @@ protected function loadIntern(&$warning, $refresh) {
// Check meta data in case syntax tags have written
// the config parameters to it.
unset($value);
if (isset($odt_meta[$name])) $value = $odt_meta[$name];
$value = $odt_meta[$name] ?? null;
if($this->isMetaSetting($name) && !empty($value)) {
$this->setParam ($name, $value);
}
Expand Down
Loading