Login | ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/webcounter/trunk/includes/functions.inc.php
Revision: 7
Committed: Sun Jan 9 00:44:28 2022 UTC (5 months, 3 weeks ago) by daniel-marschall
File size: 4724 byte(s)
Log Message:
Bugfix thanks to PHPstan.
PHPStan Level 5 passed

File Contents

# Content
1 <?php
2
3 /*
4 * PHP Counter mit Reloadsperre, Textdatenbank und Graphic-Libary (without Error Images)
5 * (C)Copyright 2010 - 2022 Daniel Marschall
6 * Revision: 2022-01-09
7 */
8
9 function pdox_execute($statement, $args=array()) {
10 if (!$statement->execute($args)) {
11 echo "SQL Error <br />";
12 echo $statement->queryString."<br />";
13 echo $statement->errorInfo()[2];
14 die();
15 }
16 }
17
18 function fetchip() {
19 return md5($_SERVER['REMOTE_ADDR']); // masked IP wegen DSGVO Kacke
20
21 // Das ist alles Quatsch! Dann kann man die IP ja fälschen
22 /*
23 // Source: http://lists.phpbar.de/pipermail/php/Week-of-Mon-20040322/007749.html
24
25 $client_ip = (isset($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : '';
26 $x_forwarded_for = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
27 $remote_addr = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : '';
28
29 if (!empty($client_ip)) {
30 $ip_expl = explode('.', $client_ip);
31 $referer = explode('.', $remote_addr);
32 if($referer[0] != $ip_expl[0]) {
33 $ip = array_reverse($ip_expl);
34 $return = implode('.', $ip);
35 } else {
36 $return = $client_ip;
37 }
38 } else if (!empty($x_forwarded_for)) {
39 if (strstr($x_forwarded_for, ',')) {
40 $ip_expl = explode(',', $x_forwarded_for);
41 $return = end($ip_expl);
42 }
43 } else {
44 $return = $remote_addr;
45 }
46 unset ($client_ip, $x_forwarded_for, $remote_addr, $ip_expl);
47 return $return;
48 */
49 }
50
51
52 function rgb2hsl($r, $g, $b) {
53 $var_R = ($r / 255);
54 $var_G = ($g / 255);
55 $var_B = ($b / 255);
56
57 $var_Min = min($var_R, $var_G, $var_B);
58 $var_Max = max($var_R, $var_G, $var_B);
59 $del_Max = $var_Max - $var_Min;
60
61 $v = $var_Max;
62
63 if ($del_Max == 0) {
64 $h = 0;
65 $s = 0;
66 } else {
67 $s = $del_Max / $var_Max;
68
69 $del_R = ( ( ( $var_Max - $var_R ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
70 $del_G = ( ( ( $var_Max - $var_G ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
71 $del_B = ( ( ( $var_Max - $var_B ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
72
73 if ($var_R == $var_Max) $h = $del_B - $del_G;
74 else if ($var_G == $var_Max) $h = ( 1 / 3 ) + $del_R - $del_B;
75 else if ($var_B == $var_Max) $h = ( 2 / 3 ) + $del_G - $del_R;
76 else $h = 0; // should not happen
77
78 if ($h < 0) $h++;
79 if ($h > 1) $h--;
80 }
81
82 return array($h, $s, $v);
83 }
84
85 function hsl2rgb($h, $s, $v) {
86 if($s == 0) {
87 $r = $g = $B = $v * 255;
88 } else {
89 $var_H = $h * 6;
90 $var_i = floor( $var_H );
91 $var_1 = $v * ( 1 - $s );
92 $var_2 = $v * ( 1 - $s * ( $var_H - $var_i ) );
93 $var_3 = $v * ( 1 - $s * (1 - ( $var_H - $var_i ) ) );
94
95 if ($var_i == 0) { $var_R = $v ; $var_G = $var_3 ; $var_B = $var_1 ; }
96 else if ($var_i == 1) { $var_R = $var_2 ; $var_G = $v ; $var_B = $var_1 ; }
97 else if ($var_i == 2) { $var_R = $var_1 ; $var_G = $v ; $var_B = $var_3 ; }
98 else if ($var_i == 3) { $var_R = $var_1 ; $var_G = $var_2 ; $var_B = $v ; }
99 else if ($var_i == 4) { $var_R = $var_3 ; $var_G = $var_1 ; $var_B = $v ; }
100 else { $var_R = $v ; $var_G = $var_1 ; $var_B = $var_2 ; }
101
102 $r = $var_R * 255;
103 $g = $var_G * 255;
104 $B = $var_B * 255;
105 }
106 return array($r, $g, $B);
107 }
108
109 function imagehue(&$image, $angle) {
110 if (!is_numeric($angle)) return;
111 if($angle % 360 == 0) return;
112 $width = imagesx($image);
113 $height = imagesy($image);
114
115 $imout = imagecreate($width, $height);
116
117 for($x = 0; $x < $width; $x++) {
118 for($y = 0; $y < $height; $y++) {
119 $rgb = imagecolorat($image, $x, $y);
120 $r = ($rgb >> 16) & 0xFF;
121 $g = ($rgb >> 8) & 0xFF;
122 $b = $rgb & 0xFF;
123 $alpha = ($rgb & 0x7F000000) >> 24;
124 list($h, $s, $l) = rgb2hsl($r, $g, $b);
125 $h += $angle / 360;
126 if($h > 1) $h--;
127 list($r, $g, $b) = hsl2rgb($h, $s, $l);
128 imagesetpixel($imout, $x, $y, imagecolorallocatealpha($imout, $r, $g, $b, $alpha));
129 }
130 }
131
132 imagedestroy($image);
133 $image = $imout;
134 }
135
136 /**
137 * TRUE if any tag matched
138 * FALSE if none matched
139 * NULL if header is not specified
140 * http://stackoverflow.com/questions/2086712/http-if-none-match-and-if-modified-since-and-304-clarification-in-php
141 */
142 function anyTagMatched($myTag) {
143 $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ?
144 stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) :
145 false ;
146
147 if( false !== $if_none_match ) {
148 $tags = explode( ", ", $if_none_match ) ;
149 foreach( $tags as $tag ) {
150 if( $tag == $myTag ) return true ;
151 }
152 return false ;
153 }
154 return null ;
155 }
156