corrade-http-templates – Blame information for rev 66
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
12 | eva | 1 | <?php |
2 | |||
3 | ########################################################################### |
||
4 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
||
5 | ########################################################################### |
||
6 | function wasKeyValueGet($key, $data) { |
||
7 | return array_reduce( |
||
8 | explode( |
||
9 | "&", |
||
10 | $data |
||
11 | ), |
||
12 | function($o, $p) { |
||
13 | $x = explode("=", $p); |
||
14 | return array_shift($x) != $o ? $o : array_shift($x); |
||
15 | }, |
||
16 | $key |
||
17 | ); |
||
18 | } |
||
19 | |||
20 | /////////////////////////////////////////////////////////////////////////// |
||
21 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
||
22 | /////////////////////////////////////////////////////////////////////////// |
||
23 | function wasCSVToArray($csv) { |
||
24 | $l = array(); |
||
25 | $s = array(); |
||
26 | $m = ""; |
||
27 | for ($i = 0; $i < strlen($csv); ++$i) { |
||
66 | office | 28 | switch ($csv[$i]) { |
12 | eva | 29 | case ',': |
30 | if (sizeof($s) == 0 || !current($s) == '"') { |
||
31 | array_push($l, $m); |
||
32 | $m = ""; |
||
33 | break; |
||
34 | } |
||
66 | office | 35 | $m .= $csv[$i]; |
12 | eva | 36 | continue; |
37 | case '"': |
||
66 | office | 38 | if ($i + 1 < strlen($csv) && $csv[$i] == $csv[$i + 1]) { |
39 | $m .= $csv[$i]; |
||
12 | eva | 40 | ++$i; |
41 | break; |
||
42 | } |
||
43 | if (sizeof($s) == 0|| !current($s) == $csv[$i]) { |
||
66 | office | 44 | array_push($s, $csv[$i]); |
12 | eva | 45 | continue; |
46 | } |
||
47 | array_pop($s); |
||
48 | break; |
||
49 | default: |
||
66 | office | 50 | $m .= $csv[$i]; |
12 | eva | 51 | break; |
52 | } |
||
53 | } |
||
54 | array_push($l, $m); |
||
55 | return $l; |
||
56 | } |
||
57 | |||
58 | /////////////////////////////////////////////////////////////////////////// |
||
59 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
||
60 | /////////////////////////////////////////////////////////////////////////// |
||
61 | function wasArrayStride($a, $s) { |
||
62 | return array_filter($a, |
||
63 | function($e, $i) use($s) { |
||
64 | return $i % $s == 0; |
||
65 | }, |
||
66 | ARRAY_FILTER_USE_BOTH |
||
67 | ); |
||
68 | } |
||
69 | |||
70 | /////////////////////////////////////////////////////////////////////////// |
||
71 | // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 // |
||
72 | /////////////////////////////////////////////////////////////////////////// |
||
73 | function wasColorHash($a) { |
||
74 | $hash = sha1($a); |
||
75 | $size = strlen($hash); |
||
76 | |||
77 | return substr($hash, 0, 2). |
||
78 | substr($hash, $size/2, 2). |
||
79 | substr($hash, $size-2, 2); |
||
80 | } |
||
81 | |||
82 | ########################################################################### |
||
83 | ## Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 ## |
||
84 | ########################################################################### |
||
85 | function mapValueToRange($value, $xMin, $xMax, $yMin, $yMax) { |
||
86 | return $yMin + ( |
||
87 | ( |
||
88 | $yMax - $yMin |
||
89 | ) |
||
90 | * |
||
91 | ( |
||
92 | $value - $xMin |
||
93 | ) |
||
94 | / |
||
95 | ( |
||
96 | $xMax - $xMin |
||
97 | ) |
||
98 | ); |
||
99 | } |
||
100 | |||
101 | function hex2RGB($hexStr, $returnAsString = false, $seperator = ',') { |
||
102 | $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); |
||
103 | $rgbArray = array(); |
||
104 | switch(strlen($hexStr)) { |
||
105 | case 6: |
||
106 | $colorVal = hexdec($hexStr); |
||
107 | $rgbArray['red'] = 0xFF & ($colorVal >> 0x10); |
||
108 | $rgbArray['green'] = 0xFF & ($colorVal >> 0x8); |
||
109 | $rgbArray['blue'] = 0xFF & $colorVal; |
||
110 | break; |
||
111 | case 3: |
||
112 | $rgbArray['red'] = hexdec( |
||
113 | str_repeat(substr($hexStr, 0, 1), 2)); |
||
114 | $rgbArray['green'] = hexdec( |
||
115 | str_repeat(substr($hexStr, 1, 1), 2)); |
||
116 | $rgbArray['blue'] = hexdec( |
||
117 | str_repeat(substr($hexStr, 2, 1), 2)); |
||
118 | break; |
||
119 | default: |
||
120 | return false; |
||
121 | } |
||
122 | return $returnAsString ? implode($seperator, $rgbArray) : $rgbArray; |
||
123 | } |