#!/usr/bin/perl # upgrade_color.pl by joachim # script to help convert a Drupal theme's color module schemes # to the new system implemented with this patch: http://drupal.org/node/693504 # configuration $color_dir = 'color/'; # subdir of your theme folder that has the color.inc file in use warnings; #$\ = "\n"; # Get PHP to output the $info array in color.inc file # We need to spoof a t() function as color.inc calls that for the labels. $php = qx[php -r 'function t(\$string) {return \$string;} include_once ("color/color.inc"); print_r(\$info["schemes"]);']; # for debug: what we got from PHP #print $php; # The default field names for new color module. @field_names = qw[ base link top bottom text ]; # open the whole array print < array( END # iterate over each scheme foreach (split /\n/, $php) { =pod input we care about is like this: [#0072b9,#027ac6,#2385c2,#5ab5ee,#494949] => Blue Lagoon (Default) =cut # skip lines that don't have an array element !m{\s*\[} and next; # extract colours: list of hex codes in the array key. @colours = m[(#[[:xdigit:]]+)]g; # extract name: the arary value ($name) = m[=>\s+(.+)$]g; #print $name; =pod output we want 'default' => array( 'title' => t('Blue Lagoon (Default)'), 'colors' => array( 'base' => '#0072b9', 'link' => '#027ac6', 'top' => '#2385c2', 'bottom' => '#5ab5ee', 'text' => '#494949', ), ), =cut @colour_lines = (); foreach my $field (@field_names) { $colour = shift @colours; push @colour_lines, qq[ '$field' => '$colour',]; } $colour_block = join "\n", @colour_lines; #print $colour_block; $heredoc = < array( 'title' => t('$name'), 'colors' => array( $colour_block ), ), END #chomp $heredoc; print $heredoc; } # close the whole array print <