/[drupal]/contributions/modules/color_soc08/engines/tag.inc
ViewVC logotype

Contents of /contributions/modules/color_soc08/engines/tag.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Fri Aug 22 10:21:57 2008 UTC (15 months ago) by skiquel
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +45 -0 lines
File MIME type: text/x-php
head commit
1 <?php
2 // $Id: tag.inc,v 1.1.2.2 2008/08/21 22:54:46 skiquel Exp $
3 /**
4 * @file
5 * Tag engine
6 * Finds and replaces hexes based on a tags in CSS
7 * Not coincidentally, the tags replaced are the field names. :)
8 */
9
10 function _color_engine_tag($style, $info, $palette, $options = NULL) {
11 _color_switch('', $palette);
12 $style = preg_replace_callback("~(?:/\*\s*\{\{\s*([^/*]+)\s*\}\}\s*\*/)?\s*(#[0-9a-f]{3,6})\s*(?:/\*\s*\{\{\s*\/?\s*([^/*]+)\s*\}\}\s*\*/)?~is", "_color_switch", $style);
13
14 return $style;
15 }
16
17 /**
18 * Find if tag matches with palette field. If so, return corresponding hex.
19 * Intended to return results to the preg_replace_callback() in _color_engine_tag()
20 *
21 * @param $matches
22 * Array of regex matches
23 * @param $static
24 * Array of field names + hexes for scheme (palette)
25 * @return
26 * Return an array of hexes
27 * or the same code it gave if no match found.
28 */
29 function _color_switch($matches, $static = FALSE) {
30 static $palette;
31
32 if ($static != FALSE) {
33 $palette = $static;
34 }
35 else {
36 // See if any of the regexes match
37 if ($match = array_intersect(array_keys($palette), array_values($matches))) {
38 $matches = $palette[array_shift(array_values($match))];
39 }
40 else {
41 $matches = $matches[0];
42 }
43 }
44 return $matches;
45 }

  ViewVC Help
Powered by ViewVC 1.1.2