// Construct the translation table

    // Empty and marked squares
    $table_xhtml = array('-0' => '<img class="chessboard-square" src="'
                           . chessboard_piece_filename('-', 0)
                           . '" alt="-" />',
                         '-1' => '<img class="chessboard-square" src="'
                           . chessboard_piece_filename('-', 1)
                           . '" alt="-" />',
                         'x0' => '<img class="chessboard-square" src="'
                           . chessboard_piece_filename('x', 0)
                           . '" alt="x" />',
                         'x1' => '<img class="chessboard-square" src="'
                           . chessboard_piece_filename('x', 1)
                           . '" alt="x" />',
                        );

    // Pieces
    $pieces = 'kqbnrp';
    for ($i=0; $i<6; $i++) {
      $piece = $pieces[$i];
      $table_xhtml += array(strtoupper($piece) . '0' => '<img class="chessboard-square" src="'
                              . chessboard_piece_filename(strtoupper($piece), 0)
                              . '" alt="' . strtoupper($piece) . '" />',
                            strtoupper($piece) . '1' => '<img class="chessboard-square" src="'
                              . chessboard_piece_filename(strtoupper($piece), 1)
                              . '" alt="' . strtoupper($piece) . '" />',
                            $piece . '0' => '<img class="chessboard-square" src="'
                              . chessboard_piece_filename($piece, 0)
                              . '" alt="' . $piece . '" />',
                            $piece . '1' => '<img class="chessboard-square" src="'
                              . chessboard_piece_filename($piece, 1)
                              . '" alt="' . $piece . '" />',
      );
    }

    // Borders
    $table_xhtml += array('T' => '<img class="chessboard-border-h" src="'
                            . chessboard_border_filename('T')
                            . '" alt="" />',
                          'B' => '<img class="chessboard-border-h" src="'
                            . chessboard_border_filename('B')
                            . '" alt="" />',
                          'L' => '<img class="chessboard-border-v" src="'
                            . chessboard_border_filename('L')
                            . '" alt="" />',
                          'R' => '<img class="chessboard-border-v" src="'
                            . chessboard_border_filename('R')
                            . '" alt="" />',
                          'TL' => '<img class="chessboard-border-c" src="'
                            . chessboard_border_filename('TL')
                            . '" alt="" />',
                          'TR' => '<img class="chessboard-border-c" src="'
                            . chessboard_border_filename('TR')
                            . '" alt="" />',
                          'BL' =>
                            '<img class="chessboard-border-c" src="'
                            . chessboard_border_filename('BL')
                            . '" alt="" />',
                          'BR' =>
                            '<img class="chessboard-border-c" src="'
                            . chessboard_border_filename('BR')
                            . '" alt="" />',
    );
CommentFileSizeAuthor
#3 chessboard-theme_image-888360-3.patch7.57 KBeric_a

Comments

eric_a’s picture

Title: Leverage theme_image() » Fetch the image's dimensions, add as width/height attributes, leverage theme_image()
Priority: Normal » Major

Currently chessboard may be displaying 11 different images on a page. It's a bit embarrassing that we're not fetching width and height attributes in PHP.

We've been adding theme functions and then finally chessboard_render() was drupalfied. Now for Drupal 6 we need to transform $chessboard_image_path to a path relative to base_path() so that we can use theme_image() *and* fetch the dimensions. This transformation is needed only inside the deprecated chessboard_render(). The shiny new theme layer should be fixed to receive a path relative to base_path().

eric_a’s picture

Now for Drupal 6 we need to transform $chessboard_image_path to a path relative to base_path()
It has been legal to pass external paths and paths outside of our Drupal base_path so it is not always possible to do such a transformation. So the goal is now just to pass something to theme_image() that will work.
Note that the typical $chessboard_image_path argument was formatted with a slash at the start and end and did have an internal [$base_dir . $path] between those slashes.

eric_a’s picture

eric_a’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.