Skip to content

Undefined array keys and FIXES #10

@nerun

Description

@nerun

My system

  • 2022-07-31a "Igor"
  • PHP 8.1
  • Plugin Avatar 2017-08-25

Warnings

Not copy / paste:

These happens if [size] & [title] are not provided:
    Undefined array key 1 in .../lib/plugins/avatar/syntax.php on line 31
    Undefined array key 1 in .../lib/plugins/avatar/syntax.php on line 4
These are uncommon and happens when $user and or $name are nulls:
    Lines 64 and 65

Fixes

syntax.php, starting at line 29:

  function handle($match, $state, $pos, Doku_Handler $handler) {
    list($syntax, $match) = explode('>', substr($match, 0, -2), 2); // strip markup
    list($user, $title) = explode('|', $match, 2); // split title from mail / username

    // Check alignment
    $ralign = (bool)preg_match('/^ /', $user);
    $lalign = (bool)preg_match('/ $/', $user);
    if ($lalign & $ralign) $align = 'center';
    else if ($ralign)      $align = 'right';
    else if ($lalign)      $align = 'left';
    else                   $align = NULL;

    //split into src and size parameter (using the very last questionmark)
    list($user, $param) = explode('?', trim($user), 2);
    if (preg_match('/^s/', $param))       $size = 20;
    else if (preg_match('/^m/', $param))  $size = 40;
    else if (preg_match('/^l/', $param))  $size = 80;
    else if (preg_match('/^xl/', $param)) $size = 120;
    else $size = NULL;

    return array($user, $title, $align, $size);
  }

Change to:

  function handle($match, $state, $pos, Doku_Handler $handler) {
    list($syntax, $match) = explode('>', substr($match, 0, -2), 2); // strip markup
    $one = explode('?', $match, 2);    // [user|mail] ? [size]|[title]
    $two = explode('|', $one[0], 2);   // [user] & [mail]
    $three = explode('|', $one[1], 2); // [size] & [title]
    $user = $two[0];
    $title = $three[1];
    $param = $three[0];
    
    // Check alignment
    $ralign = (bool)preg_match('/^ /', $user);
    $lalign = (bool)preg_match('/ $/', $user);
    if ($lalign & $ralign) $align = 'center';
    else if ($ralign)      $align = 'right';
    else if ($lalign)      $align = 'left';
    else                   $align = NULL;

    if (preg_match('/^s/', $param))       $size = 20;
    else if (preg_match('/^m/', $param))  $size = 40;
    else if (preg_match('/^l/', $param))  $size = 80;
    else if (preg_match('/^xl/', $param)) $size = 120;
    else $size = NULL;

    return array($user, $title, $align, $size);
  }

helper.php, lines 64 and 65:

        $user_img = mediaFN($ns.':'.$user.$format);
        $name_img = mediaFN($ns.':'.$name.$format);

Change to:

        if(isset($user)) {
            $user_img = mediaFN($ns.':'.$user.$format);
        }
        if(isset($name)) {
            $name_img = mediaFN($ns.':'.$name.$format);
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions