| 1 | #!/usr/bin/env php |
| 2 | <?php |
| 3 | /** |
| 4 | * color_theme_to_css.php |
| 5 | * |
| 6 | * This script can be used to convert an old $color theme to a stylesheet for |
| 7 | * use with templates. Output is sent to STDOUT. |
| 8 | * |
| 9 | * HOWTO: |
| 10 | * 1. Create a .php file containing your $color theme. |
| 11 | * 2. Run this script from a command line, giving the name of your theme file |
| 12 | * as an arguement to this script, e.g.: |
| 13 | * |
| 14 | * /path/to/squirrelmail/templates/theme_to_css.php /path/to/mytheme.php |
| 15 | * |
| 16 | * To send the output to a .css file, do the following: |
| 17 | * |
| 18 | * /path/to/squirrelmail/templates/theme_to_css.php /path/to/mytheme.php > my_theme.css |
| 19 | * |
| 20 | * @copyright 1999-2016 The SquirrelMail Project Team |
| 21 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 22 | * @version $Id$ |
| 23 | * @package squirrelmail |
| 24 | * @subpackage templates |
| 25 | * @author Steve Brown |
| 26 | * @since 1.5.2 |
| 27 | */ |
| 28 | |
| 29 | /** make sure that first command line argument is set */ |
| 30 | if (empty($argv[1])) { |
| 31 | echo "Please provide the path to the file containing the \$color theme you\n" . |
| 32 | "wish to convert to a stylesheet.\n\n"; |
| 33 | exit (1); |
| 34 | } |
| 35 | |
| 36 | $theme_file = $argv[1]; |
| 37 | if (!is_file($theme_file) || !is_readable($theme_file)) { |
| 38 | echo "The requested theme could not be converted because the file could not\n" . |
| 39 | "be opened. Please specify a theme file that can be read.\n\n"; |
| 40 | exit(1); |
| 41 | } |
| 42 | |
| 43 | /* set default colors in case color theme is not full */ |
| 44 | $def_color = array(); |
| 45 | $def_color[0] = '#dcdcdc'; // (light gray) TitleBar |
| 46 | $def_color[1] = '#800000'; // (red) |
| 47 | $def_color[2] = '#cc0000'; // (light red) Warning/Error Messages |
| 48 | $def_color[3] = '#a0b8c8'; // (green-blue) Left Bar Background |
| 49 | $def_color[4] = '#ffffff'; // (white) Normal Background |
| 50 | $def_color[5] = '#ffffcc'; // (light yellow) Table Headers |
| 51 | $def_color[6] = '#000000'; // (black) Text on left bar |
| 52 | $def_color[7] = '#0000cc'; // (blue) Links |
| 53 | $def_color[8] = '#000000'; // (black) Normal text |
| 54 | $def_color[9] = '#ababab'; // (mid-gray) Darker version of #0 |
| 55 | $def_color[10] = '#666666'; // (dark gray) Darker version of #9 |
| 56 | $def_color[11] = '#770000'; // (dark red) Special Folders color |
| 57 | $def_color[12] = '#ededed'; // (light gray) Alternate color for message list |
| 58 | $def_color[13] = '#800000'; // (dark red) Color for quoted text -- > 1 quote |
| 59 | $def_color[14] = '#ff0000'; // (red) Color for quoted text -- >> 2 or more |
| 60 | $def_color[15] = '#002266'; // (dark blue) Unselectable folders |
| 61 | $def_color[16] = '#ff9933'; // (orange) Highlight color |
| 62 | |
| 63 | $color = $def_color; |
| 64 | include($theme_file); |
| 65 | if ($color === $def_color) { |
| 66 | echo "The theme file you specified did not make any alterations to the default\n" . |
| 67 | "color scheme. Please choose a different file.\n\n"; |
| 68 | exit(1); |
| 69 | } |
| 70 | |
| 71 | $css_source = <<<CSS |
| 72 | /* older css template */ |
| 73 | /* page body formatting */ |
| 74 | body { |
| 75 | color: __COLOR8__; |
| 76 | background-color: __COLOR4__; |
| 77 | } |
| 78 | body.sqm_leftMain { |
| 79 | color: __COLOR6__; |
| 80 | background-color: __COLOR3__; |
| 81 | } |
| 82 | |
| 83 | /* right links */ |
| 84 | a:link, a:visited, a:hover, a:active { |
| 85 | color: __COLOR7__; |
| 86 | } |
| 87 | |
| 88 | /* left links */ |
| 89 | .sqm_leftMain a:link, .sqm_leftMain a:visited, .sqm_leftMain a:hover, .sqm_leftMain a:active { |
| 90 | color: __COLOR6__; |
| 91 | } |
| 92 | .leftunseen, .leftspecial, .leftspecial a:link, .leftspecial a:visited, .leftspecial a:hover, .leftspecial a:active { |
| 93 | color: __COLOR11__; |
| 94 | } |
| 95 | .leftnoselect a:link, .leftnoselect a:visited, .leftnoselect a:hover, .leftnoselect a:active { |
| 96 | color: __COLOR15__; |
| 97 | } |
| 98 | |
| 99 | /* highlighted texts */ |
| 100 | .highlight { |
| 101 | color: __COLOR15__; |
| 102 | } |
| 103 | .error_table { |
| 104 | color: __COLOR14__; |
| 105 | border: 2px solid __COLOR0__; |
| 106 | background-color: __COLOR3__; |
| 107 | } |
| 108 | .error_thead { |
| 109 | background-color: __COLOR10__; |
| 110 | } |
| 111 | .error_thead_caption { |
| 112 | background-color: __COLOR10__; |
| 113 | } |
| 114 | .error_row { |
| 115 | color: __COLOR14__; |
| 116 | } |
| 117 | .error_val { |
| 118 | color: __COLOR8__; |
| 119 | border: 2px solid __COLOR0__; |
| 120 | |
| 121 | } |
| 122 | .error_key { |
| 123 | border: 2px solid __COLOR0__; |
| 124 | color: __COLOR14__; |
| 125 | background-color: __COLOR0__; |
| 126 | } |
| 127 | |
| 128 | /* Standard defs */ |
| 129 | table.table1 { |
| 130 | border: 1px solid __COLOR0__; |
| 131 | } |
| 132 | table.table2 { |
| 133 | border: 1px solid __COLOR9__; |
| 134 | } |
| 135 | td.header1 { |
| 136 | background: __COLOR0__; |
| 137 | } |
| 138 | td.header2 { |
| 139 | background: __COLOR9__; |
| 140 | } |
| 141 | td.header4 { |
| 142 | background: __COLOR5__; |
| 143 | } |
| 144 | tr.even { |
| 145 | background: __COLOR12__; |
| 146 | } |
| 147 | tr.odd { |
| 148 | background: __COLOR4__; |
| 149 | } |
| 150 | .table_standard { |
| 151 | border:1px solid __COLOR0__; |
| 152 | } |
| 153 | |
| 154 | .sqm_loginOrgName, .sqm_signoutBar { |
| 155 | background: __COLOR0__; |
| 156 | } |
| 157 | .sqm_motd { |
| 158 | background: __COLOR9__; |
| 159 | } |
| 160 | .sqm_motd td { |
| 161 | background: __COLOR4__; |
| 162 | } |
| 163 | |
| 164 | /* empty_folder.tpl defs */ |
| 165 | .sqm_emptyFolder { |
| 166 | background: __COLOR9__; |
| 167 | } |
| 168 | .sqm_emptyFolder td { |
| 169 | background: __COLOR4__; |
| 170 | } |
| 171 | |
| 172 | /* error_box.tpl definitions */ |
| 173 | .table_errorBoxWrapper { |
| 174 | background: __COLOR9__; |
| 175 | } |
| 176 | .table_errorBox { |
| 177 | background: __COLOR0__; |
| 178 | } |
| 179 | .error_message { |
| 180 | background: __COLOR4__; |
| 181 | } |
| 182 | |
| 183 | /* page_header.tpl definitions */ |
| 184 | .sqm_currentFolder { |
| 185 | background: __COLOR9__; |
| 186 | } |
| 187 | .sqm_headerSignout { |
| 188 | background: __COLOR9__; |
| 189 | } |
| 190 | |
| 191 | /* message_list.tpl definitions */ |
| 192 | .table_messageListWrapper { |
| 193 | background: __COLOR9__; |
| 194 | } |
| 195 | |
| 196 | .table_messageList { |
| 197 | background: __COLOR5__; |
| 198 | } |
| 199 | .table_messageList td.spacer { |
| 200 | background: __COLOR0__; |
| 201 | } |
| 202 | .table_messageList tr.mouse_over { |
| 203 | background: __COLOR5__; |
| 204 | } |
| 205 | .table_messageList tr.clicked { |
| 206 | background: __COLOR16__; |
| 207 | } |
| 208 | .deleted { |
| 209 | color: __COLOR9__; |
| 210 | } |
| 211 | .flagged { |
| 212 | color: __COLOR2__; |
| 213 | } |
| 214 | .high_priority { |
| 215 | color: __COLOR1__; |
| 216 | } |
| 217 | .low_priority { |
| 218 | color: __COLOR8__; |
| 219 | } |
| 220 | .message_list_controls { |
| 221 | background: __COLOR0__; |
| 222 | } |
| 223 | .spacer { |
| 224 | background: __COLOR4__; |
| 225 | } |
| 226 | |
| 227 | /* folder_manip.tpl defs */ |
| 228 | #folderManip table.wrapper { |
| 229 | border: 1px solid __COLOR0__; |
| 230 | } |
| 231 | #folderManip td.folderAction { |
| 232 | background: __COLOR0__; |
| 233 | } |
| 234 | |
| 235 | /* addressbook_list.tpl defs */ |
| 236 | #addressList table { |
| 237 | border: 1px solid __COLOR9__; |
| 238 | } |
| 239 | #addressList td.header1 { |
| 240 | background: __COLOR9__; |
| 241 | } |
| 242 | #addressList td.abookSwitch { |
| 243 | background: __COLOR0__; |
| 244 | } |
| 245 | |
| 246 | #addressList td.abookButtons { |
| 247 | background: __COLOR0__; |
| 248 | } |
| 249 | #addressList td.abookField { |
| 250 | border-left: 1px solid __COLOR9__; |
| 251 | border-right: 1px solid __COLOR9__; |
| 252 | } |
| 253 | #addressList td.colHeader { |
| 254 | background: __COLOR9__; |
| 255 | } |
| 256 | #addrBookSearch table.wrapper { |
| 257 | border: 1px solid __COLOR9__; |
| 258 | } |
| 259 | #addrAddEdit table { |
| 260 | border: 1px solid __COLOR9__; |
| 261 | } |
| 262 | #addrAddEdit td.header { |
| 263 | background: __COLOR9__; |
| 264 | } |
| 265 | |
| 266 | /* options defs */ |
| 267 | #optionGroups table { |
| 268 | border: 1px solid __COLOR0__; |
| 269 | } |
| 270 | #optionGroups td.title { |
| 271 | background: __COLOR0__; |
| 272 | } |
| 273 | #optionGroups td.optionElement table { |
| 274 | border:1px solid __COLOR9__; |
| 275 | } |
| 276 | #optionGroups td.optionName { |
| 277 | background: __COLOR9__; |
| 278 | } |
| 279 | #optionGroups td.optionDesc { |
| 280 | background: __COLOR0__; |
| 281 | } |
| 282 | #optionDisplay table { |
| 283 | border: 1px solid __COLOR0__ |
| 284 | } |
| 285 | #optionOrder table { |
| 286 | border: 1px solid __COLOR0__ |
| 287 | } |
| 288 | #optionOrder table.moveFields td { |
| 289 | border-left: 1px solid __COLOR0__; |
| 290 | border-right: 1px solid __COLOR0__; |
| 291 | } |
| 292 | #optionsIdentity table.table2 tr { |
| 293 | background: __COLOR0__; |
| 294 | } |
| 295 | #optionsIdentity hr { |
| 296 | width: 95%; |
| 297 | border: 1px solid __COLOR9__; |
| 298 | } |
| 299 | |
| 300 | /* help defs */ |
| 301 | #help td.nav { |
| 302 | color: __COLOR0__; |
| 303 | } |
| 304 | |
| 305 | /* search defs */ |
| 306 | div.search td.header4 { |
| 307 | border-bottom: 1px solid __COLOR9__; |
| 308 | } |
| 309 | div.search td.queryAction { |
| 310 | border-left: 1px solid __COLOR9__; |
| 311 | border-top: 1px solid __COLOR9__; |
| 312 | border-bottom: 1px solid __COLOR9__; |
| 313 | } |
| 314 | |
| 315 | div.search td.queryDesc { |
| 316 | border-top: 1px solid __COLOR9__; |
| 317 | border-bottom: 1px solid __COLOR9__; |
| 318 | } |
| 319 | div.search span.error { |
| 320 | color: __COLOR2__; |
| 321 | } |
| 322 | div.search td.searchForm { |
| 323 | border-right: 1px solid __COLOR0__; |
| 324 | border-left: 1px solid __COLOR0__; |
| 325 | } |
| 326 | div.search td.queryError { |
| 327 | color: __COLOR2__; |
| 328 | } |
| 329 | div.search h2 { |
| 330 | color: __COLOR2__; |
| 331 | } |
| 332 | |
| 333 | /* compse defs */ |
| 334 | div.compose tr.header { |
| 335 | background: __COLOR9__; |
| 336 | } |
| 337 | div.compose tr.attachment td { |
| 338 | background: __COLOR0__; |
| 339 | border-top: 1px solid __COLOR9__; |
| 340 | border-bottom: 1px solid __COLOR9__; |
| 341 | } |
| 342 | |
| 343 | div.compose table.close { |
| 344 | background: __COLOR0__; |
| 345 | border:1px solid __COLOR9__; |
| 346 | } |
| 347 | CSS; |
| 348 | |
| 349 | $p = array(); |
| 350 | for ($k = 0; $k<=16; $k++) { |
| 351 | $p[$k] = '__COLOR'.$k.'__'; |
| 352 | if (!isset($color[$k])) { |
| 353 | $color[$k] = $def_color[$k]; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | // Just to make sure... |
| 358 | ksort($p); |
| 359 | ksort($color); |
| 360 | $css_source = str_replace($p, $color, $css_source); |
| 361 | echo $css_source; |
| 362 | exit(0); |
| 363 | ?> |