// 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="" />',
);
Comments
Comment #1
eric_a commentedCurrently 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().
Comment #2
eric_a commentedNow 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.
Comment #3
eric_a commented#893590: Decouple template_preprocess_chessboard() from global $chessboard_image_path
#897280: Pass around a standard drupal directory path instead of $chessboard_image_path
With the above issues in, this task has become simpler.
Comment #4
eric_a commentedCommitted.