Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Undefined array keys and FIXES #10

Open
nerun opened this issue Nov 28, 2022 · 0 comments
Open

Undefined array keys and FIXES #10

nerun opened this issue Nov 28, 2022 · 0 comments

Comments

@nerun
Copy link

nerun commented Nov 28, 2022

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);
        }
nerun added a commit to nerun/dokuwiki-plugin-avatar that referenced this issue Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant