corrade-http-templates – Diff between revs 2 and 12

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 2 Rev 12
Line 17... Line 17...
17   17  
18 ########################################################################### 18 ###########################################################################
19 ## CONFIGURATION ## 19 ## CONFIGURATION ##
Line 20... Line 20...
20 ########################################################################### 20 ###########################################################################
21   21  
-   22 # The configuration file for this script containing the settings.
Line 22... Line 23...
22 // The configuration file for this script containing the settings. 23 require_once("config.php");
23 include_once("config.php"); 24 require_once("functions.php")
24   25  
Line 25... Line -...
25 ########################################################################### -  
26 ## INTERNALS ## -  
27 ########################################################################### -  
28   -  
29 ########################################################################### -  
30 ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## -  
31 ########################################################################### -  
32 function wasKeyValueGet($key, $data) { -  
33 return array_reduce( -  
34 explode( -  
35 "&", -  
36 $data -  
37 ), -  
38 function($o, $p) { -  
39 $x = explode("=", $p); -  
40 return array_shift($x) != $o ? $o : array_shift($x); -  
41 }, -  
42 $key -  
43 ); -  
44 } -  
45   -  
46 /////////////////////////////////////////////////////////////////////////// -  
47 // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // -  
48 /////////////////////////////////////////////////////////////////////////// -  
49 function wasCSVToArray($csv) { -  
50 $l = array(); -  
51 $s = array(); -  
52 $m = ""; -  
53 for ($i = 0; $i < strlen($csv); ++$i) { -  
54 switch ($csv{$i}) { -  
55 case ',': -  
56 if (sizeof($s) == 0 || !current($s) == '"') { -  
57 array_push($l, $m); -  
58 $m = ""; -  
59 break; -  
60 } -  
61 $m .= $csv{$i}; -  
62 continue; -  
63 case '"': -  
64 if ($i + 1 < strlen($csv) && $csv{$i} == $csv{$i + 1}) { -  
65 $m .= $csv{$i}; -  
66 ++$i; -  
67 break; -  
68 } -  
69 if (sizeof($s) == 0|| !current($s) == $csv[$i]) { -  
70 array_push($s, $csv{$i}); -  
71 continue; -  
72 } -  
73 array_pop($s); -  
74 break; -  
75 default: -  
76 $m .= $csv{$i}; -  
77 break; -  
78 } -  
79 } -  
80 array_push($l, $m); -  
81 return $l; -  
82 } -  
83   -  
84 /////////////////////////////////////////////////////////////////////////// -  
85 // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // -  
86 /////////////////////////////////////////////////////////////////////////// -  
87 function wasArrayStride($a, $s) { -  
88 return array_filter($a, -  
89 function($e, $i) use($s) { -  
90 return $i % $s == 0; -  
91 }, -  
92 ARRAY_FILTER_USE_BOTH -  
93 ); -  
94 } -  
95   -  
96 /////////////////////////////////////////////////////////////////////////// -  
97 // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // -  
98 /////////////////////////////////////////////////////////////////////////// -  
99 function wasColorHash($a) { -  
100 $hash = sha1($a); -  
101 $size = strlen($hash); -  
102   -  
103 return substr($hash, 0, 2). -  
104 substr($hash, $size/2, 2). -  
105 substr($hash, $size-2, 2); -  
106 } -  
107   -  
108 /////////////////////////////////////////////////////////////////////////// -  
109 // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // -  
110 /////////////////////////////////////////////////////////////////////////// -  
111 function mapValueToRange($value, $xMin, $xMax, $yMin, $yMax) { -  
112 return $yMin + ( -  
113 ( -  
114 $yMax - $yMin -  
115 ) -  
116 * -  
117 ( -  
118 $value - $xMin -  
119 ) -  
120 / -  
121 ( -  
122 $xMax - $xMin -  
123 ) -  
124 ); -  
125 } -  
126   -  
127 function hex2RGB($hexStr, $returnAsString = false, $seperator = ',') { -  
128 $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); -  
129 $rgbArray = array(); -  
130 switch(strlen($hexStr)) { -  
131 case 6: -  
132 $colorVal = hexdec($hexStr); -  
133 $rgbArray['red'] = 0xFF & ($colorVal >> 0x10); -  
134 $rgbArray['green'] = 0xFF & ($colorVal >> 0x8); -  
135 $rgbArray['blue'] = 0xFF & $colorVal; -  
136 break; -  
137 case 3: -  
138 $rgbArray['red'] = hexdec( -  
139 str_repeat(substr($hexStr, 0, 1), 2)); -  
140 $rgbArray['green'] = hexdec( -  
141 str_repeat(substr($hexStr, 1, 1), 2)); -  
142 $rgbArray['blue'] = hexdec( -  
143 str_repeat(substr($hexStr, 2, 1), 2)); -  
144 break; -  
145 default: -  
146 return false; -  
147 } 26 ###########################################################################
148 return $returnAsString ? implode($seperator, $rgbArray) : $rgbArray; 27 ## INTERNALS ##
149 } 28 ###########################################################################
150   29  
151 #### 30 ####