@@ -54,6 +54,9 @@ discard block |
||
54 | 54 | return $caseSensitive?$token:strtoupper($token); |
55 | 55 | } |
56 | 56 | |
57 | +/** |
|
58 | + * @param string $hex |
|
59 | + */ |
|
57 | 60 | function hash2string($hex,$alphabet) |
58 | 61 | { |
59 | 62 | if(strlen($alphabet)<2) |
@@ -121,6 +124,11 @@ discard block |
||
121 | 124 | imagedestroy($image); |
122 | 125 | } |
123 | 126 | |
127 | +/** |
|
128 | + * @param resource $image |
|
129 | + * @param double $width |
|
130 | + * @param double $height |
|
131 | + */ |
|
124 | 132 | function addBackground($image,$width,$height,$opaque,$noisy,$hasGrid,$hasScribble,$morph) |
125 | 133 | { |
126 | 134 | $background=imagecreatetruecolor($width*2,$height*2); |
@@ -148,6 +156,9 @@ discard block |
||
148 | 156 | imagecolortransparent($image,$white); |
149 | 157 | } |
150 | 158 | |
159 | +/** |
|
160 | + * @param resource $image |
|
161 | + */ |
|
151 | 162 | function addNoise($image,$width,$height) |
152 | 163 | { |
153 | 164 | for($x=0;$x<$width;++$x) |
@@ -164,6 +175,9 @@ discard block |
||
164 | 175 | } |
165 | 176 | } |
166 | 177 | |
178 | +/** |
|
179 | + * @param resource $image |
|
180 | + */ |
|
167 | 181 | function addGrid($image,$width,$height) |
168 | 182 | { |
169 | 183 | for($i=0;$i<$width;$i+=rand(15,25)) |
@@ -182,6 +196,9 @@ discard block |
||
182 | 196 | } |
183 | 197 | } |
184 | 198 | |
199 | +/** |
|
200 | + * @param resource $image |
|
201 | + */ |
|
185 | 202 | function addScribble($image,$width,$height) |
186 | 203 | { |
187 | 204 | for($i=0;$i<8;$i++) |
@@ -199,6 +216,9 @@ discard block |
||
199 | 216 | } |
200 | 217 | } |
201 | 218 | |
219 | +/** |
|
220 | + * @param resource $image |
|
221 | + */ |
|
202 | 222 | function morphImage($image,$width,$height) |
203 | 223 | { |
204 | 224 | $tempImage=imagecreatetruecolor($width,$height); |
@@ -100,21 +100,21 @@ discard block |
||
100 | 100 | $font=dirname(__FILE__).DIRECTORY_SEPARATOR.'verase.ttf'; |
101 | 101 | |
102 | 102 | if(function_exists('imagefilter')) |
103 | - imagefilter($image,IMG_FILTER_GAUSSIAN_BLUR); |
|
103 | + imagefilter($image,IMG_FILTER_GAUSSIAN_BLUR); |
|
104 | 104 | |
105 | 105 | $hasShadow=($theme&THEME_SHADOWED_TEXT); |
106 | - for($i=0;$i<$length;$i++) |
|
106 | + for($i=0;$i<$length;$i++) |
|
107 | 107 | { |
108 | - $color=imagecolorallocate($image,rand(150,220),rand(150,220),rand(150,220)); |
|
109 | - $size=rand($fontWidth-10,$fontWidth); |
|
110 | - $angle=rand(-30,30); |
|
111 | - $x=$padding+$i*$fontWidth; |
|
112 | - $y=rand($fontHeight-15,$fontHeight-10); |
|
113 | - imagettftext($image,$size,$angle,$x,$y,$color,$font,$token[$i]); |
|
114 | - if($hasShadow) |
|
115 | - imagettftext($image,$size,$angle,$x+2,$y+2,$color,$font,$token[$i]); |
|
116 | - imagecolordeallocate($image,$color); |
|
117 | - } |
|
108 | + $color=imagecolorallocate($image,rand(150,220),rand(150,220),rand(150,220)); |
|
109 | + $size=rand($fontWidth-10,$fontWidth); |
|
110 | + $angle=rand(-30,30); |
|
111 | + $x=$padding+$i*$fontWidth; |
|
112 | + $y=rand($fontHeight-15,$fontHeight-10); |
|
113 | + imagettftext($image,$size,$angle,$x,$y,$color,$font,$token[$i]); |
|
114 | + if($hasShadow) |
|
115 | + imagettftext($image,$size,$angle,$x+2,$y+2,$color,$font,$token[$i]); |
|
116 | + imagecolordeallocate($image,$color); |
|
117 | + } |
|
118 | 118 | |
119 | 119 | header('Content-Type: image/png'); |
120 | 120 | imagepng($image); |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | { |
159 | 159 | $color=imagecolorallocate($image,rand(150,220),rand(150,220),rand(150,220)); |
160 | 160 | imagesetpixel($image,$x,$y,$color); |
161 | - imagecolordeallocate($image,$color); |
|
162 | - } |
|
161 | + imagecolordeallocate($image,$color); |
|
162 | + } |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
@@ -9,111 +9,110 @@ discard block |
||
9 | 9 | * @package System.Web.UI.WebControls.assets |
10 | 10 | */ |
11 | 11 | |
12 | -define('THEME_OPAQUE_BACKGROUND',0x0001); |
|
13 | -define('THEME_NOISY_BACKGROUND',0x0002); |
|
14 | -define('THEME_HAS_GRID',0x0004); |
|
15 | -define('THEME_HAS_SCRIBBLE',0x0008); |
|
16 | -define('THEME_MORPH_BACKGROUND',0x0010); |
|
17 | -define('THEME_SHADOWED_TEXT',0x0020); |
|
12 | +define('THEME_OPAQUE_BACKGROUND', 0x0001); |
|
13 | +define('THEME_NOISY_BACKGROUND', 0x0002); |
|
14 | +define('THEME_HAS_GRID', 0x0004); |
|
15 | +define('THEME_HAS_SCRIBBLE', 0x0008); |
|
16 | +define('THEME_MORPH_BACKGROUND', 0x0010); |
|
17 | +define('THEME_SHADOWED_TEXT', 0x0020); |
|
18 | 18 | |
19 | -require_once(dirname(__FILE__).'/captcha_key.php'); |
|
19 | +require_once(dirname(__FILE__) . '/captcha_key.php'); |
|
20 | 20 | |
21 | -$token='error'; |
|
22 | -$theme=0; |
|
21 | +$token = 'error'; |
|
22 | +$theme = 0; |
|
23 | 23 | |
24 | -if(isset($_GET['options'])) |
|
24 | +if (isset($_GET['options'])) |
|
25 | 25 | { |
26 | - $str=base64_decode($_GET['options']); |
|
27 | - if(strlen($str)>32) |
|
26 | + $str = base64_decode($_GET['options']); |
|
27 | + if (strlen($str) > 32) |
|
28 | 28 | { |
29 | - $hash=substr($str,0,32); |
|
30 | - $str=substr($str,32); |
|
31 | - if(md5($privateKey.$str)===$hash) |
|
29 | + $hash = substr($str, 0, 32); |
|
30 | + $str = substr($str, 32); |
|
31 | + if (md5($privateKey . $str) === $hash) |
|
32 | 32 | { |
33 | - $options=unserialize($str); |
|
34 | - $publicKey=$options['publicKey']; |
|
35 | - $tokenLength=$options['tokenLength']; |
|
36 | - $caseSensitive=$options['caseSensitive']; |
|
37 | - $alphabet=$options['alphabet']; |
|
38 | - $fontSize=$options['fontSize']; |
|
39 | - $theme=$options['theme']; |
|
40 | - if(($randomSeed=$options['randomSeed'])>0) |
|
33 | + $options = unserialize($str); |
|
34 | + $publicKey = $options['publicKey']; |
|
35 | + $tokenLength = $options['tokenLength']; |
|
36 | + $caseSensitive = $options['caseSensitive']; |
|
37 | + $alphabet = $options['alphabet']; |
|
38 | + $fontSize = $options['fontSize']; |
|
39 | + $theme = $options['theme']; |
|
40 | + if (($randomSeed = $options['randomSeed']) > 0) |
|
41 | 41 | srand($randomSeed); |
42 | 42 | else |
43 | - srand((int)(microtime()*1000000)); |
|
44 | - $token=generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive); |
|
43 | + srand((int) (microtime() * 1000000)); |
|
44 | + $token = generateToken($publicKey, $privateKey, $alphabet, $tokenLength, $caseSensitive); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | -displayToken($token,$fontSize,$theme); |
|
49 | +displayToken($token, $fontSize, $theme); |
|
50 | 50 | |
51 | -function generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive) |
|
51 | +function generateToken($publicKey, $privateKey, $alphabet, $tokenLength, $caseSensitive) |
|
52 | 52 | { |
53 | - $token=substr(hash2string(md5($publicKey.$privateKey),$alphabet).hash2string(md5($privateKey.$publicKey),$alphabet),0,$tokenLength); |
|
54 | - return $caseSensitive?$token:strtoupper($token); |
|
53 | + $token = substr(hash2string(md5($publicKey . $privateKey), $alphabet) . hash2string(md5($privateKey . $publicKey), $alphabet), 0, $tokenLength); |
|
54 | + return $caseSensitive ? $token : strtoupper($token); |
|
55 | 55 | } |
56 | 56 | |
57 | -function hash2string($hex,$alphabet) |
|
57 | +function hash2string($hex, $alphabet) |
|
58 | 58 | { |
59 | - if(strlen($alphabet)<2) |
|
60 | - $alphabet='234578adefhijmnrtABDEFGHJLMNRT'; |
|
61 | - $hexLength=strlen($hex); |
|
62 | - $base=strlen($alphabet); |
|
63 | - $result=''; |
|
64 | - for($i=0;$i<$hexLength;$i+=6) |
|
59 | + if (strlen($alphabet) < 2) |
|
60 | + $alphabet = '234578adefhijmnrtABDEFGHJLMNRT'; |
|
61 | + $hexLength = strlen($hex); |
|
62 | + $base = strlen($alphabet); |
|
63 | + $result = ''; |
|
64 | + for ($i = 0; $i < $hexLength; $i += 6) |
|
65 | 65 | { |
66 | - $number=hexdec(substr($hex,$i,6)); |
|
67 | - while($number) |
|
66 | + $number = hexdec(substr($hex, $i, 6)); |
|
67 | + while ($number) |
|
68 | 68 | { |
69 | - $result.=$alphabet[$number%$base]; |
|
70 | - $number=floor($number/$base); |
|
69 | + $result .= $alphabet[$number % $base]; |
|
70 | + $number = floor($number / $base); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | return $result; |
74 | 74 | } |
75 | 75 | |
76 | -function displayToken($token,$fontSize,$theme) |
|
76 | +function displayToken($token, $fontSize, $theme) |
|
77 | 77 | { |
78 | - if(($fontSize=(int)$fontSize)<22) |
|
79 | - $fontSize=22; |
|
80 | - if($fontSize>100) |
|
81 | - $fontSize=100; |
|
82 | - $length=strlen($token); |
|
83 | - $padding=10; |
|
84 | - $fontWidth=$fontSize; |
|
85 | - $fontHeight=floor($fontWidth*1.5); |
|
86 | - $width=$fontWidth*$length+$padding*2; |
|
87 | - $height=$fontHeight; |
|
88 | - $image=imagecreatetruecolor($width,$height); |
|
89 | - |
|
90 | - addBackground |
|
91 | - ( |
|
78 | + if (($fontSize = (int) $fontSize) < 22) |
|
79 | + $fontSize = 22; |
|
80 | + if ($fontSize > 100) |
|
81 | + $fontSize = 100; |
|
82 | + $length = strlen($token); |
|
83 | + $padding = 10; |
|
84 | + $fontWidth = $fontSize; |
|
85 | + $fontHeight = floor($fontWidth * 1.5); |
|
86 | + $width = $fontWidth * $length + $padding * 2; |
|
87 | + $height = $fontHeight; |
|
88 | + $image = imagecreatetruecolor($width, $height); |
|
89 | + |
|
90 | + addBackground( |
|
92 | 91 | $image, $width, $height, |
93 | - $theme&THEME_OPAQUE_BACKGROUND, |
|
94 | - $theme&THEME_NOISY_BACKGROUND, |
|
95 | - $theme&THEME_HAS_GRID, |
|
96 | - $theme&THEME_HAS_SCRIBBLE, |
|
97 | - $theme&THEME_MORPH_BACKGROUND |
|
92 | + $theme & THEME_OPAQUE_BACKGROUND, |
|
93 | + $theme & THEME_NOISY_BACKGROUND, |
|
94 | + $theme & THEME_HAS_GRID, |
|
95 | + $theme & THEME_HAS_SCRIBBLE, |
|
96 | + $theme & THEME_MORPH_BACKGROUND |
|
98 | 97 | ); |
99 | 98 | |
100 | - $font=dirname(__FILE__).DIRECTORY_SEPARATOR.'verase.ttf'; |
|
99 | + $font = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'verase.ttf'; |
|
101 | 100 | |
102 | - if(function_exists('imagefilter')) |
|
103 | - imagefilter($image,IMG_FILTER_GAUSSIAN_BLUR); |
|
101 | + if (function_exists('imagefilter')) |
|
102 | + imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR); |
|
104 | 103 | |
105 | - $hasShadow=($theme&THEME_SHADOWED_TEXT); |
|
106 | - for($i=0;$i<$length;$i++) |
|
104 | + $hasShadow = ($theme & THEME_SHADOWED_TEXT); |
|
105 | + for ($i = 0; $i < $length; $i++) |
|
107 | 106 | { |
108 | - $color=imagecolorallocate($image,rand(150,220),rand(150,220),rand(150,220)); |
|
109 | - $size=rand($fontWidth-10,$fontWidth); |
|
110 | - $angle=rand(-30,30); |
|
111 | - $x=$padding+$i*$fontWidth; |
|
112 | - $y=rand($fontHeight-15,$fontHeight-10); |
|
113 | - imagettftext($image,$size,$angle,$x,$y,$color,$font,$token[$i]); |
|
114 | - if($hasShadow) |
|
115 | - imagettftext($image,$size,$angle,$x+2,$y+2,$color,$font,$token[$i]); |
|
116 | - imagecolordeallocate($image,$color); |
|
107 | + $color = imagecolorallocate($image, rand(150, 220), rand(150, 220), rand(150, 220)); |
|
108 | + $size = rand($fontWidth - 10, $fontWidth); |
|
109 | + $angle = rand(-30, 30); |
|
110 | + $x = $padding + $i * $fontWidth; |
|
111 | + $y = rand($fontHeight - 15, $fontHeight - 10); |
|
112 | + imagettftext($image, $size, $angle, $x, $y, $color, $font, $token[$i]); |
|
113 | + if ($hasShadow) |
|
114 | + imagettftext($image, $size, $angle, $x + 2, $y + 2, $color, $font, $token[$i]); |
|
115 | + imagecolordeallocate($image, $color); |
|
117 | 116 | } |
118 | 117 | |
119 | 118 | header('Content-Type: image/png'); |
@@ -121,103 +120,103 @@ discard block |
||
121 | 120 | imagedestroy($image); |
122 | 121 | } |
123 | 122 | |
124 | -function addBackground($image,$width,$height,$opaque,$noisy,$hasGrid,$hasScribble,$morph) |
|
123 | +function addBackground($image, $width, $height, $opaque, $noisy, $hasGrid, $hasScribble, $morph) |
|
125 | 124 | { |
126 | - $background=imagecreatetruecolor($width*2,$height*2); |
|
127 | - $white=imagecolorallocate($background,255,255,255); |
|
128 | - imagefill($background,0,0,$white); |
|
125 | + $background = imagecreatetruecolor($width * 2, $height * 2); |
|
126 | + $white = imagecolorallocate($background, 255, 255, 255); |
|
127 | + imagefill($background, 0, 0, $white); |
|
129 | 128 | |
130 | - if($opaque) |
|
131 | - imagefill($background,0,0,imagecolorallocate($background,100,100,100)); |
|
129 | + if ($opaque) |
|
130 | + imagefill($background, 0, 0, imagecolorallocate($background, 100, 100, 100)); |
|
132 | 131 | |
133 | - if($noisy) |
|
134 | - addNoise($background,$width*2,$height*2); |
|
132 | + if ($noisy) |
|
133 | + addNoise($background, $width * 2, $height * 2); |
|
135 | 134 | |
136 | - if($hasGrid) |
|
137 | - addGrid($background,$width*2,$height*2); |
|
135 | + if ($hasGrid) |
|
136 | + addGrid($background, $width * 2, $height * 2); |
|
138 | 137 | |
139 | - if($hasScribble) |
|
140 | - addScribble($background,$width*2,$height*2); |
|
138 | + if ($hasScribble) |
|
139 | + addScribble($background, $width * 2, $height * 2); |
|
141 | 140 | |
142 | - if($morph) |
|
143 | - morphImage($background,$width*2,$height*2); |
|
141 | + if ($morph) |
|
142 | + morphImage($background, $width * 2, $height * 2); |
|
144 | 143 | |
145 | - imagecopy($image,$background,0,0,30,30,$width,$height); |
|
144 | + imagecopy($image, $background, 0, 0, 30, 30, $width, $height); |
|
146 | 145 | |
147 | - if(!$opaque) |
|
148 | - imagecolortransparent($image,$white); |
|
146 | + if (!$opaque) |
|
147 | + imagecolortransparent($image, $white); |
|
149 | 148 | } |
150 | 149 | |
151 | -function addNoise($image,$width,$height) |
|
150 | +function addNoise($image, $width, $height) |
|
152 | 151 | { |
153 | - for($x=0;$x<$width;++$x) |
|
152 | + for ($x = 0; $x < $width; ++$x) |
|
154 | 153 | { |
155 | - for($y=0;$y<$height;++$y) |
|
154 | + for ($y = 0; $y < $height; ++$y) |
|
156 | 155 | { |
157 | - if(rand(0,100)<25) |
|
156 | + if (rand(0, 100) < 25) |
|
158 | 157 | { |
159 | - $color=imagecolorallocate($image,rand(150,220),rand(150,220),rand(150,220)); |
|
160 | - imagesetpixel($image,$x,$y,$color); |
|
161 | - imagecolordeallocate($image,$color); |
|
158 | + $color = imagecolorallocate($image, rand(150, 220), rand(150, 220), rand(150, 220)); |
|
159 | + imagesetpixel($image, $x, $y, $color); |
|
160 | + imagecolordeallocate($image, $color); |
|
162 | 161 | } |
163 | 162 | } |
164 | 163 | } |
165 | 164 | } |
166 | 165 | |
167 | -function addGrid($image,$width,$height) |
|
166 | +function addGrid($image, $width, $height) |
|
168 | 167 | { |
169 | - for($i=0;$i<$width;$i+=rand(15,25)) |
|
168 | + for ($i = 0; $i < $width; $i += rand(15, 25)) |
|
170 | 169 | { |
171 | - imagesetthickness($image,rand(2,6)); |
|
172 | - $color=imagecolorallocate($image,rand(100,180),rand(100,180),rand(100,180)); |
|
173 | - imageline($image,$i+rand(-10,20),0,$i+rand(-10,20),$height,$color); |
|
174 | - imagecolordeallocate($image,$color); |
|
170 | + imagesetthickness($image, rand(2, 6)); |
|
171 | + $color = imagecolorallocate($image, rand(100, 180), rand(100, 180), rand(100, 180)); |
|
172 | + imageline($image, $i + rand(-10, 20), 0, $i + rand(-10, 20), $height, $color); |
|
173 | + imagecolordeallocate($image, $color); |
|
175 | 174 | } |
176 | - for($i=0;$i<$height;$i+=rand(15,25)) |
|
175 | + for ($i = 0; $i < $height; $i += rand(15, 25)) |
|
177 | 176 | { |
178 | - imagesetthickness($image,rand(2,6)); |
|
179 | - $color=imagecolorallocate($image,rand(100,180),rand(100,180),rand(100,180)); |
|
180 | - imageline($image,0,$i+rand(-10,20),$width,$i+rand(-10,20),$color); |
|
181 | - imagecolordeallocate($image,$color); |
|
177 | + imagesetthickness($image, rand(2, 6)); |
|
178 | + $color = imagecolorallocate($image, rand(100, 180), rand(100, 180), rand(100, 180)); |
|
179 | + imageline($image, 0, $i + rand(-10, 20), $width, $i + rand(-10, 20), $color); |
|
180 | + imagecolordeallocate($image, $color); |
|
182 | 181 | } |
183 | 182 | } |
184 | 183 | |
185 | -function addScribble($image,$width,$height) |
|
184 | +function addScribble($image, $width, $height) |
|
186 | 185 | { |
187 | - for($i=0;$i<8;$i++) |
|
186 | + for ($i = 0; $i < 8; $i++) |
|
188 | 187 | { |
189 | - $color=imagecolorallocate($image,rand(100,180),rand(100,180),rand(100,180)); |
|
190 | - $points=array(); |
|
191 | - for($j=1;$j<rand(5,10);$j++) |
|
188 | + $color = imagecolorallocate($image, rand(100, 180), rand(100, 180), rand(100, 180)); |
|
189 | + $points = array(); |
|
190 | + for ($j = 1; $j < rand(5, 10); $j++) |
|
192 | 191 | { |
193 | - $points[]=rand(2*(20*($i+1)),2*(50*($i+1))); |
|
194 | - $points[]=rand(30,$height+30); |
|
192 | + $points[] = rand(2 * (20 * ($i + 1)), 2 * (50 * ($i + 1))); |
|
193 | + $points[] = rand(30, $height + 30); |
|
195 | 194 | } |
196 | - imagesetthickness($image,rand(2,6)); |
|
197 | - imagepolygon($image,$points,intval(sizeof($points)/2),$color); |
|
198 | - imagecolordeallocate($image,$color); |
|
195 | + imagesetthickness($image, rand(2, 6)); |
|
196 | + imagepolygon($image, $points, intval(sizeof($points) / 2), $color); |
|
197 | + imagecolordeallocate($image, $color); |
|
199 | 198 | } |
200 | 199 | } |
201 | 200 | |
202 | -function morphImage($image,$width,$height) |
|
201 | +function morphImage($image, $width, $height) |
|
203 | 202 | { |
204 | - $tempImage=imagecreatetruecolor($width,$height); |
|
205 | - $chunk=rand(1,5); |
|
206 | - for($x=$y=0;$x<$width;$x+=$chunk) |
|
203 | + $tempImage = imagecreatetruecolor($width, $height); |
|
204 | + $chunk = rand(1, 5); |
|
205 | + for ($x = $y = 0; $x < $width; $x += $chunk) |
|
207 | 206 | { |
208 | - $chunk=rand(1,5); |
|
209 | - $y+=rand(-1,1); |
|
210 | - if($y>=$height) $y=$height-5; |
|
211 | - if($y<0) $y=5; |
|
212 | - imagecopy($tempImage,$image,$x,0,$x,$y,$chunk,$height); |
|
207 | + $chunk = rand(1, 5); |
|
208 | + $y += rand(-1, 1); |
|
209 | + if ($y >= $height) $y = $height - 5; |
|
210 | + if ($y < 0) $y = 5; |
|
211 | + imagecopy($tempImage, $image, $x, 0, $x, $y, $chunk, $height); |
|
213 | 212 | } |
214 | - for($x=$y=0;$y<$height;$y+=$chunk) |
|
213 | + for ($x = $y = 0; $y < $height; $y += $chunk) |
|
215 | 214 | { |
216 | - $chunk=rand(1,5); |
|
217 | - $x+=rand(-1,1); |
|
218 | - if($x>=$width) $x=$width-5; |
|
219 | - if($x<0) $x=5; |
|
220 | - imagecopy($image,$tempImage,$x,$y,0,$y,$width,$chunk); |
|
215 | + $chunk = rand(1, 5); |
|
216 | + $x += rand(-1, 1); |
|
217 | + if ($x >= $width) $x = $width - 5; |
|
218 | + if ($x < 0) $x = 5; |
|
219 | + imagecopy($image, $tempImage, $x, $y, 0, $y, $width, $chunk); |
|
221 | 220 | } |
222 | 221 | } |
223 | 222 |
@@ -37,10 +37,11 @@ discard block |
||
37 | 37 | $alphabet=$options['alphabet']; |
38 | 38 | $fontSize=$options['fontSize']; |
39 | 39 | $theme=$options['theme']; |
40 | - if(($randomSeed=$options['randomSeed'])>0) |
|
41 | - srand($randomSeed); |
|
42 | - else |
|
43 | - srand((int)(microtime()*1000000)); |
|
40 | + if(($randomSeed=$options['randomSeed'])>0) { |
|
41 | + srand($randomSeed); |
|
42 | + } else { |
|
43 | + srand((int)(microtime()*1000000)); |
|
44 | + } |
|
44 | 45 | $token=generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive); |
45 | 46 | } |
46 | 47 | } |
@@ -56,8 +57,9 @@ discard block |
||
56 | 57 | |
57 | 58 | function hash2string($hex,$alphabet) |
58 | 59 | { |
59 | - if(strlen($alphabet)<2) |
|
60 | - $alphabet='234578adefhijmnrtABDEFGHJLMNRT'; |
|
60 | + if(strlen($alphabet)<2) { |
|
61 | + $alphabet='234578adefhijmnrtABDEFGHJLMNRT'; |
|
62 | + } |
|
61 | 63 | $hexLength=strlen($hex); |
62 | 64 | $base=strlen($alphabet); |
63 | 65 | $result=''; |
@@ -75,10 +77,12 @@ discard block |
||
75 | 77 | |
76 | 78 | function displayToken($token,$fontSize,$theme) |
77 | 79 | { |
78 | - if(($fontSize=(int)$fontSize)<22) |
|
79 | - $fontSize=22; |
|
80 | - if($fontSize>100) |
|
81 | - $fontSize=100; |
|
80 | + if(($fontSize=(int)$fontSize)<22) { |
|
81 | + $fontSize=22; |
|
82 | + } |
|
83 | + if($fontSize>100) { |
|
84 | + $fontSize=100; |
|
85 | + } |
|
82 | 86 | $length=strlen($token); |
83 | 87 | $padding=10; |
84 | 88 | $fontWidth=$fontSize; |
@@ -99,8 +103,9 @@ discard block |
||
99 | 103 | |
100 | 104 | $font=dirname(__FILE__).DIRECTORY_SEPARATOR.'verase.ttf'; |
101 | 105 | |
102 | - if(function_exists('imagefilter')) |
|
103 | - imagefilter($image,IMG_FILTER_GAUSSIAN_BLUR); |
|
106 | + if(function_exists('imagefilter')) { |
|
107 | + imagefilter($image,IMG_FILTER_GAUSSIAN_BLUR); |
|
108 | + } |
|
104 | 109 | |
105 | 110 | $hasShadow=($theme&THEME_SHADOWED_TEXT); |
106 | 111 | for($i=0;$i<$length;$i++) |
@@ -111,8 +116,9 @@ discard block |
||
111 | 116 | $x=$padding+$i*$fontWidth; |
112 | 117 | $y=rand($fontHeight-15,$fontHeight-10); |
113 | 118 | imagettftext($image,$size,$angle,$x,$y,$color,$font,$token[$i]); |
114 | - if($hasShadow) |
|
115 | - imagettftext($image,$size,$angle,$x+2,$y+2,$color,$font,$token[$i]); |
|
119 | + if($hasShadow) { |
|
120 | + imagettftext($image,$size,$angle,$x+2,$y+2,$color,$font,$token[$i]); |
|
121 | + } |
|
116 | 122 | imagecolordeallocate($image,$color); |
117 | 123 | } |
118 | 124 | |
@@ -127,26 +133,32 @@ discard block |
||
127 | 133 | $white=imagecolorallocate($background,255,255,255); |
128 | 134 | imagefill($background,0,0,$white); |
129 | 135 | |
130 | - if($opaque) |
|
131 | - imagefill($background,0,0,imagecolorallocate($background,100,100,100)); |
|
136 | + if($opaque) { |
|
137 | + imagefill($background,0,0,imagecolorallocate($background,100,100,100)); |
|
138 | + } |
|
132 | 139 | |
133 | - if($noisy) |
|
134 | - addNoise($background,$width*2,$height*2); |
|
140 | + if($noisy) { |
|
141 | + addNoise($background,$width*2,$height*2); |
|
142 | + } |
|
135 | 143 | |
136 | - if($hasGrid) |
|
137 | - addGrid($background,$width*2,$height*2); |
|
144 | + if($hasGrid) { |
|
145 | + addGrid($background,$width*2,$height*2); |
|
146 | + } |
|
138 | 147 | |
139 | - if($hasScribble) |
|
140 | - addScribble($background,$width*2,$height*2); |
|
148 | + if($hasScribble) { |
|
149 | + addScribble($background,$width*2,$height*2); |
|
150 | + } |
|
141 | 151 | |
142 | - if($morph) |
|
143 | - morphImage($background,$width*2,$height*2); |
|
152 | + if($morph) { |
|
153 | + morphImage($background,$width*2,$height*2); |
|
154 | + } |
|
144 | 155 | |
145 | 156 | imagecopy($image,$background,0,0,30,30,$width,$height); |
146 | 157 | |
147 | - if(!$opaque) |
|
148 | - imagecolortransparent($image,$white); |
|
149 | -} |
|
158 | + if(!$opaque) { |
|
159 | + imagecolortransparent($image,$white); |
|
160 | + } |
|
161 | + } |
|
150 | 162 | |
151 | 163 | function addNoise($image,$width,$height) |
152 | 164 | { |
@@ -207,16 +219,24 @@ discard block |
||
207 | 219 | { |
208 | 220 | $chunk=rand(1,5); |
209 | 221 | $y+=rand(-1,1); |
210 | - if($y>=$height) $y=$height-5; |
|
211 | - if($y<0) $y=5; |
|
222 | + if($y>=$height) { |
|
223 | + $y=$height-5; |
|
224 | + } |
|
225 | + if($y<0) { |
|
226 | + $y=5; |
|
227 | + } |
|
212 | 228 | imagecopy($tempImage,$image,$x,0,$x,$y,$chunk,$height); |
213 | 229 | } |
214 | 230 | for($x=$y=0;$y<$height;$y+=$chunk) |
215 | 231 | { |
216 | 232 | $chunk=rand(1,5); |
217 | 233 | $x+=rand(-1,1); |
218 | - if($x>=$width) $x=$width-5; |
|
219 | - if($x<0) $x=5; |
|
234 | + if($x>=$width) { |
|
235 | + $x=$width-5; |
|
236 | + } |
|
237 | + if($x<0) { |
|
238 | + $x=5; |
|
239 | + } |
|
220 | 240 | imagecopy($image,$tempImage,$x,$y,0,$y,$width,$chunk); |
221 | 241 | } |
222 | 242 | } |
@@ -166,6 +166,7 @@ |
||
166 | 166 | * Otherwise, an exception will be raised. |
167 | 167 | * @param mixed data item |
168 | 168 | * @param mixed field name |
169 | + * @param string $field |
|
169 | 170 | * @return mixed data value at the specified field |
170 | 171 | * @throws TInvalidDataValueException if the data is invalid |
171 | 172 | */ |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * TBaseDataList class file |
|
4 | - * |
|
5 | - * @author Qiang Xue <[email protected]> |
|
6 | - * @link https://github.com/pradosoft/prado |
|
7 | - * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | - * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | - * @package System.Web.UI.WebControls |
|
10 | - */ |
|
3 | + * TBaseDataList class file |
|
4 | + * |
|
5 | + * @author Qiang Xue <[email protected]> |
|
6 | + * @link https://github.com/pradosoft/prado |
|
7 | + * @copyright Copyright © 2005-2015 The PRADO Group |
|
8 | + * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT |
|
9 | + * @package System.Web.UI.WebControls |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Includes TDataBoundControl and TDataFieldAccessor classes |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function getCellSpacing() |
58 | 58 | { |
59 | - if($this->getHasStyle()) |
|
59 | + if ($this->getHasStyle()) |
|
60 | 60 | return $this->getStyle()->getCellSpacing(); |
61 | 61 | else |
62 | 62 | return -1; |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function getCellPadding() |
77 | 77 | { |
78 | - if($this->getHasStyle()) |
|
78 | + if ($this->getHasStyle()) |
|
79 | 79 | return $this->getStyle()->getCellPadding(); |
80 | 80 | else |
81 | 81 | return -1; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function getHorizontalAlign() |
96 | 96 | { |
97 | - if($this->getHasStyle()) |
|
97 | + if ($this->getHasStyle()) |
|
98 | 98 | return $this->getStyle()->getHorizontalAlign(); |
99 | 99 | else |
100 | 100 | return THorizontalAlign::NotSet; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getGridLines() |
115 | 115 | { |
116 | - if($this->getHasStyle()) |
|
116 | + if ($this->getHasStyle()) |
|
117 | 117 | return $this->getStyle()->getGridLines(); |
118 | 118 | else |
119 | 119 | return TTableGridLines::None; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function getDataKeyField() |
136 | 136 | { |
137 | - return $this->getViewState('DataKeyField',''); |
|
137 | + return $this->getViewState('DataKeyField', ''); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function setDataKeyField($value) |
144 | 144 | { |
145 | - $this->setViewState('DataKeyField',$value,''); |
|
145 | + $this->setViewState('DataKeyField', $value, ''); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function getDataKeys() |
152 | 152 | { |
153 | - if(($dataKeys=$this->getViewState('DataKeys',null))===null) |
|
153 | + if (($dataKeys = $this->getViewState('DataKeys', null)) === null) |
|
154 | 154 | { |
155 | - $dataKeys=new TList; |
|
156 | - $this->setViewState('DataKeys',$dataKeys,null); |
|
155 | + $dataKeys = new TList; |
|
156 | + $this->setViewState('DataKeys', $dataKeys, null); |
|
157 | 157 | } |
158 | 158 | return $dataKeys; |
159 | 159 | } |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | * @return mixed data value at the specified field |
170 | 170 | * @throws TInvalidDataValueException if the data is invalid |
171 | 171 | */ |
172 | - protected function getDataFieldValue($data,$field) |
|
172 | + protected function getDataFieldValue($data, $field) |
|
173 | 173 | { |
174 | - return TDataFieldAccessor::getDataFieldValue($data,$field); |
|
174 | + return TDataFieldAccessor::getDataFieldValue($data, $field); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function onSelectedIndexChanged($param) |
184 | 184 | { |
185 | - $this->raiseEvent('OnSelectedIndexChanged',$this,$param); |
|
185 | + $this->raiseEvent('OnSelectedIndexChanged', $this, $param); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 |
@@ -56,10 +56,11 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function getCellSpacing() |
58 | 58 | { |
59 | - if($this->getHasStyle()) |
|
60 | - return $this->getStyle()->getCellSpacing(); |
|
61 | - else |
|
62 | - return -1; |
|
59 | + if($this->getHasStyle()) { |
|
60 | + return $this->getStyle()->getCellSpacing(); |
|
61 | + } else { |
|
62 | + return -1; |
|
63 | + } |
|
63 | 64 | } |
64 | 65 | |
65 | 66 | /** |
@@ -75,10 +76,11 @@ discard block |
||
75 | 76 | */ |
76 | 77 | public function getCellPadding() |
77 | 78 | { |
78 | - if($this->getHasStyle()) |
|
79 | - return $this->getStyle()->getCellPadding(); |
|
80 | - else |
|
81 | - return -1; |
|
79 | + if($this->getHasStyle()) { |
|
80 | + return $this->getStyle()->getCellPadding(); |
|
81 | + } else { |
|
82 | + return -1; |
|
83 | + } |
|
82 | 84 | } |
83 | 85 | |
84 | 86 | /** |
@@ -94,10 +96,11 @@ discard block |
||
94 | 96 | */ |
95 | 97 | public function getHorizontalAlign() |
96 | 98 | { |
97 | - if($this->getHasStyle()) |
|
98 | - return $this->getStyle()->getHorizontalAlign(); |
|
99 | - else |
|
100 | - return THorizontalAlign::NotSet; |
|
99 | + if($this->getHasStyle()) { |
|
100 | + return $this->getStyle()->getHorizontalAlign(); |
|
101 | + } else { |
|
102 | + return THorizontalAlign::NotSet; |
|
103 | + } |
|
101 | 104 | } |
102 | 105 | |
103 | 106 | /** |
@@ -113,10 +116,11 @@ discard block |
||
113 | 116 | */ |
114 | 117 | public function getGridLines() |
115 | 118 | { |
116 | - if($this->getHasStyle()) |
|
117 | - return $this->getStyle()->getGridLines(); |
|
118 | - else |
|
119 | - return TTableGridLines::None; |
|
119 | + if($this->getHasStyle()) { |
|
120 | + return $this->getStyle()->getGridLines(); |
|
121 | + } else { |
|
122 | + return TTableGridLines::None; |
|
123 | + } |
|
120 | 124 | } |
121 | 125 | |
122 | 126 | /** |
@@ -182,6 +182,7 @@ discard block |
||
182 | 182 | * TBaseValidator::$_clientClass, be sure to update the corresponding |
183 | 183 | * "Javascript/validation3.js" file as well. |
184 | 184 | * @param TControl control to validate. |
185 | + * @param TControl $control |
|
185 | 186 | * @return string control type for client-side validation. |
186 | 187 | */ |
187 | 188 | private function getClientControlClass($control) |
@@ -259,7 +260,7 @@ discard block |
||
259 | 260 | /** |
260 | 261 | * Update the ControlToValidate component's css class depending |
261 | 262 | * if the ControlCssClass property is set, and whether this is valid. |
262 | - * @return boolean true if change, false otherwise. |
|
263 | + * @return boolean|null true if change, false otherwise. |
|
263 | 264 | */ |
264 | 265 | protected function updateControlCssClass() |
265 | 266 | { |
@@ -384,6 +385,7 @@ discard block |
||
384 | 385 | * The ID path is the dot-connected IDs of the controls reaching from |
385 | 386 | * the validator's naming container to the target control. |
386 | 387 | * @param string the ID path |
388 | + * @param string $value |
|
387 | 389 | */ |
388 | 390 | public function setControlToValidate($value) |
389 | 391 | { |
@@ -549,6 +551,7 @@ discard block |
||
549 | 551 | |
550 | 552 | /** |
551 | 553 | * @param string the css class that is applied to the control being validated in case the validation fails |
554 | + * @param string $value |
|
552 | 555 | */ |
553 | 556 | public function setControlCssClass($value) |
554 | 557 | { |
@@ -691,7 +694,7 @@ discard block |
||
691 | 694 | } |
692 | 695 | |
693 | 696 | /** |
694 | - * @return boolean true to observe changes. |
|
697 | + * @return boolean|string true to observe changes. |
|
695 | 698 | */ |
696 | 699 | public function getObserveChanges() |
697 | 700 | { |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * @var boolean whether the validation succeeds |
79 | 79 | */ |
80 | - private $_isValid=true; |
|
80 | + private $_isValid = true; |
|
81 | 81 | /** |
82 | 82 | * @var boolean whether the validator has been registered with the page |
83 | 83 | */ |
84 | - private $_registered=false; |
|
84 | + private $_registered = false; |
|
85 | 85 | /** |
86 | 86 | * @var TValidatorClientSide validator client-script options. |
87 | 87 | */ |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | { |
112 | 112 | parent::onInit($param); |
113 | 113 | $this->getPage()->getValidators()->add($this); |
114 | - $this->_registered=true; |
|
114 | + $this->_registered = true; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function onUnload($param) |
122 | 122 | { |
123 | - if($this->_registered && ($page=$this->getPage())!==null) |
|
123 | + if ($this->_registered && ($page = $this->getPage()) !== null) |
|
124 | 124 | $page->getValidators()->remove($this); |
125 | - $this->_registered=false; |
|
125 | + $this->_registered = false; |
|
126 | 126 | parent::onUnload($param); |
127 | 127 | } |
128 | 128 | |
@@ -133,13 +133,13 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function addAttributesToRender($writer) |
135 | 135 | { |
136 | - $display=$this->getDisplay(); |
|
137 | - $visible=$this->getEnabled(true) && !$this->getIsValid(); |
|
138 | - if($display===TValidatorDisplayStyle::None || (!$visible && $display===TValidatorDisplayStyle::Dynamic)) |
|
139 | - $writer->addStyleAttribute('display','none'); |
|
140 | - else if(!$visible) |
|
141 | - $writer->addStyleAttribute('visibility','hidden'); |
|
142 | - $writer->addAttribute('id',$this->getClientID()); |
|
136 | + $display = $this->getDisplay(); |
|
137 | + $visible = $this->getEnabled(true) && !$this->getIsValid(); |
|
138 | + if ($display === TValidatorDisplayStyle::None || (!$visible && $display === TValidatorDisplayStyle::Dynamic)) |
|
139 | + $writer->addStyleAttribute('display', 'none'); |
|
140 | + else if (!$visible) |
|
141 | + $writer->addStyleAttribute('visibility', 'hidden'); |
|
142 | + $writer->addAttribute('id', $this->getClientID()); |
|
143 | 143 | parent::addAttributesToRender($writer); |
144 | 144 | $this->renderClientControlScript($writer); |
145 | 145 | } |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | $options['FormID'] = $this->getPage()->getForm()->getClientID(); |
156 | 156 | $options['Display'] = $this->getDisplay(); |
157 | 157 | $options['ErrorMessage'] = $this->getErrorMessage(); |
158 | - if($this->getFocusOnError()) |
|
158 | + if ($this->getFocusOnError()) |
|
159 | 159 | { |
160 | 160 | $options['FocusOnError'] = $this->getFocusOnError(); |
161 | 161 | $options['FocusElementID'] = $this->getFocusElementID(); |
162 | 162 | } |
163 | 163 | $options['ValidationGroup'] = $this->getValidationGroup(); |
164 | - if($control) |
|
164 | + if ($control) |
|
165 | 165 | $options['ControlToValidate'] = $control->getClientID(); |
166 | 166 | $options['ControlCssClass'] = $this->getControlCssClass(); |
167 | 167 | |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | $options['Enabled'] = $this->getEnabled(true); |
170 | 170 | |
171 | 171 | //get date format from date picker target control |
172 | - if($control instanceof TDatePicker) |
|
172 | + if ($control instanceof TDatePicker) |
|
173 | 173 | $options['DateFormat'] = $control->getDateFormat(); |
174 | 174 | |
175 | - $options = array_merge($options,$this->getClientSide()->getOptions()->toArray()); |
|
175 | + $options = array_merge($options, $this->getClientSide()->getOptions()->toArray()); |
|
176 | 176 | |
177 | 177 | return $options; |
178 | 178 | } |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | */ |
187 | 187 | private function getClientControlClass($control) |
188 | 188 | { |
189 | - foreach(self::$_clientClass as $type) |
|
190 | - if($control instanceof $type) |
|
189 | + foreach (self::$_clientClass as $type) |
|
190 | + if ($control instanceof $type) |
|
191 | 191 | return $type; |
192 | 192 | return get_class($control); |
193 | 193 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | */ |
211 | 211 | public function getClientSide() |
212 | 212 | { |
213 | - if($this->_clientSide===null) |
|
213 | + if ($this->_clientSide === null) |
|
214 | 214 | $this->_clientSide = $this->createClientSide(); |
215 | 215 | return $this->_clientSide; |
216 | 216 | } |
@@ -234,15 +234,15 @@ discard block |
||
234 | 234 | $scripts = $this->getPage()->getClientScript(); |
235 | 235 | if ($this->getEnableClientScript()) |
236 | 236 | $scripts->registerPradoScript('validator'); |
237 | - $formID=$this->getPage()->getForm()->getClientID(); |
|
237 | + $formID = $this->getPage()->getForm()->getClientID(); |
|
238 | 238 | $scriptKey = "TBaseValidator:$formID"; |
239 | - if($this->getEnableClientScript() && !$scripts->isEndScriptRegistered($scriptKey)) |
|
239 | + if ($this->getEnableClientScript() && !$scripts->isEndScriptRegistered($scriptKey)) |
|
240 | 240 | { |
241 | 241 | $manager['FormID'] = $formID; |
242 | 242 | $options = TJavaScript::encode($manager); |
243 | 243 | $scripts->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});"); |
244 | 244 | } |
245 | - if($this->getEnableClientScript()) |
|
245 | + if ($this->getEnableClientScript()) |
|
246 | 246 | $this->registerClientScriptValidator(); |
247 | 247 | } |
248 | 248 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * Override parent implementation to update the control CSS Class before |
251 | 251 | * the validated control is rendered |
252 | 252 | */ |
253 | - public function onPreRender ($param) |
|
253 | + public function onPreRender($param) |
|
254 | 254 | { |
255 | 255 | parent::onPreRender($param); |
256 | 256 | $this->updateControlCssClass(); |
@@ -263,15 +263,15 @@ discard block |
||
263 | 263 | */ |
264 | 264 | protected function updateControlCssClass() |
265 | 265 | { |
266 | - if(($cssClass=$this->getControlCssClass())!=='') |
|
266 | + if (($cssClass = $this->getControlCssClass()) !== '') |
|
267 | 267 | { |
268 | - $control=$this->getValidationTarget(); |
|
269 | - if($control instanceof TWebControl) |
|
268 | + $control = $this->getValidationTarget(); |
|
269 | + if ($control instanceof TWebControl) |
|
270 | 270 | { |
271 | - $class = preg_replace ('/ '.preg_quote($cssClass).'/', '',$control->getCssClass()); |
|
272 | - if(!$this->getIsValid()) |
|
271 | + $class = preg_replace('/ ' . preg_quote($cssClass) . '/', '', $control->getCssClass()); |
|
272 | + if (!$this->getIsValid()) |
|
273 | 273 | { |
274 | - $class .= ' '.$cssClass; |
|
274 | + $class .= ' ' . $cssClass; |
|
275 | 275 | $control->setCssClass($class); |
276 | 276 | } elseif ($control->getIsValid()) |
277 | 277 | $control->setCssClass($class); |
@@ -284,11 +284,11 @@ discard block |
||
284 | 284 | */ |
285 | 285 | protected function registerClientScriptValidator() |
286 | 286 | { |
287 | - $key = 'prado:'.$this->getClientID(); |
|
288 | - if(!$this->getPage()->getClientScript()->isEndScriptRegistered($key)) |
|
287 | + $key = 'prado:' . $this->getClientID(); |
|
288 | + if (!$this->getPage()->getClientScript()->isEndScriptRegistered($key)) |
|
289 | 289 | { |
290 | 290 | $options = TJavaScript::encode($this->getClientScriptOptions()); |
291 | - $script = 'new '.$this->getClientClassName().'('.$options.');'; |
|
291 | + $script = 'new ' . $this->getClientClassName() . '(' . $options . ');'; |
|
292 | 292 | $this->getPage()->getClientScript()->registerEndScript($key, $script); |
293 | 293 | } |
294 | 294 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | */ |
308 | 308 | public function setForControl($value) |
309 | 309 | { |
310 | - throw new TNotSupportedException('basevalidator_forcontrol_unsupported',get_class($this)); |
|
310 | + throw new TNotSupportedException('basevalidator_forcontrol_unsupported', get_class($this)); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -316,10 +316,10 @@ discard block |
||
316 | 316 | */ |
317 | 317 | public function setEnabled($value) |
318 | 318 | { |
319 | - $value=TPropertyValue::ensureBoolean($value); |
|
319 | + $value = TPropertyValue::ensureBoolean($value); |
|
320 | 320 | parent::setEnabled($value); |
321 | - if(!$value) |
|
322 | - $this->_isValid=true; |
|
321 | + if (!$value) |
|
322 | + $this->_isValid = true; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | */ |
328 | 328 | public function getDisplay() |
329 | 329 | { |
330 | - return $this->getViewState('Display',TValidatorDisplayStyle::Fixed); |
|
330 | + return $this->getViewState('Display', TValidatorDisplayStyle::Fixed); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public function setDisplay($value) |
337 | 337 | { |
338 | - $this->setViewState('Display',TPropertyValue::ensureEnum($value,'TValidatorDisplayStyle'),TValidatorDisplayStyle::Fixed); |
|
338 | + $this->setViewState('Display', TPropertyValue::ensureEnum($value, 'TValidatorDisplayStyle'), TValidatorDisplayStyle::Fixed); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | */ |
344 | 344 | public function getEnableClientScript() |
345 | 345 | { |
346 | - return $this->getViewState('EnableClientScript',true); |
|
346 | + return $this->getViewState('EnableClientScript', true); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | */ |
352 | 352 | public function setEnableClientScript($value) |
353 | 353 | { |
354 | - $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true); |
|
354 | + $this->setViewState('EnableClientScript', TPropertyValue::ensureBoolean($value), true); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | */ |
360 | 360 | public function getErrorMessage() |
361 | 361 | { |
362 | - return $this->getViewState('ErrorMessage',''); |
|
362 | + return $this->getViewState('ErrorMessage', ''); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function setErrorMessage($value) |
370 | 370 | { |
371 | - $this->setViewState('ErrorMessage',$value,''); |
|
371 | + $this->setViewState('ErrorMessage', $value, ''); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | */ |
377 | 377 | public function getControlToValidate() |
378 | 378 | { |
379 | - return $this->getViewState('ControlToValidate',''); |
|
379 | + return $this->getViewState('ControlToValidate', ''); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | */ |
388 | 388 | public function setControlToValidate($value) |
389 | 389 | { |
390 | - $this->setViewState('ControlToValidate',$value,''); |
|
390 | + $this->setViewState('ControlToValidate', $value, ''); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | */ |
396 | 396 | public function getFocusOnError() |
397 | 397 | { |
398 | - return $this->getViewState('FocusOnError',false); |
|
398 | + return $this->getViewState('FocusOnError', false); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | */ |
404 | 404 | public function setFocusOnError($value) |
405 | 405 | { |
406 | - $this->setViewState('FocusOnError',TPropertyValue::ensureBoolean($value),false); |
|
406 | + $this->setViewState('FocusOnError', TPropertyValue::ensureBoolean($value), false); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -413,17 +413,17 @@ discard block |
||
413 | 413 | */ |
414 | 414 | public function getFocusElementID() |
415 | 415 | { |
416 | - if(($id=$this->getViewState('FocusElementID',''))==='') |
|
416 | + if (($id = $this->getViewState('FocusElementID', '')) === '') |
|
417 | 417 | { |
418 | - $target=$this->getValidationTarget(); |
|
418 | + $target = $this->getValidationTarget(); |
|
419 | 419 | /* Workaround: TCheckBoxList and TRadioButtonList nests the actual |
420 | 420 | * inputs inside a table; we ensure the first input gets focused |
421 | 421 | */ |
422 | - if($target instanceof TCheckBoxList && $target->getItemCount()>0) |
|
422 | + if ($target instanceof TCheckBoxList && $target->getItemCount() > 0) |
|
423 | 423 | { |
424 | - $id=$target->getClientID().'_c0'; |
|
424 | + $id = $target->getClientID() . '_c0'; |
|
425 | 425 | } else { |
426 | - $id=$target->getClientID(); |
|
426 | + $id = $target->getClientID(); |
|
427 | 427 | } |
428 | 428 | } |
429 | 429 | return $id; |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | */ |
444 | 444 | public function getValidationGroup() |
445 | 445 | { |
446 | - return $this->getViewState('ValidationGroup',''); |
|
446 | + return $this->getViewState('ValidationGroup', ''); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | */ |
452 | 452 | public function setValidationGroup($value) |
453 | 453 | { |
454 | - $this->setViewState('ValidationGroup',$value,''); |
|
454 | + $this->setViewState('ValidationGroup', $value, ''); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | */ |
469 | 469 | public function setIsValid($value) |
470 | 470 | { |
471 | - $this->_isValid=TPropertyValue::ensureBoolean($value); |
|
471 | + $this->_isValid = TPropertyValue::ensureBoolean($value); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
@@ -478,10 +478,10 @@ discard block |
||
478 | 478 | */ |
479 | 479 | public function getValidationTarget() |
480 | 480 | { |
481 | - if(($id=$this->getControlToValidate())!=='' && ($control=$this->findControl($id))!==null) |
|
481 | + if (($id = $this->getControlToValidate()) !== '' && ($control = $this->findControl($id)) !== null) |
|
482 | 482 | return $control; |
483 | 483 | else |
484 | - throw new TConfigurationException('basevalidator_controltovalidate_invalid',get_class($this)); |
|
484 | + throw new TConfigurationException('basevalidator_controltovalidate_invalid', get_class($this)); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -492,10 +492,10 @@ discard block |
||
492 | 492 | */ |
493 | 493 | protected function getValidationValue($control) |
494 | 494 | { |
495 | - if($control instanceof IValidatable) |
|
495 | + if ($control instanceof IValidatable) |
|
496 | 496 | return $control->getValidationPropertyValue(); |
497 | 497 | else |
498 | - throw new TInvalidDataTypeException('basevalidator_validatable_required',get_class($this)); |
|
498 | + throw new TInvalidDataTypeException('basevalidator_validatable_required', get_class($this)); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -506,22 +506,22 @@ discard block |
||
506 | 506 | public function validate() |
507 | 507 | { |
508 | 508 | $this->onValidate(); |
509 | - if($this->getVisible(true) && $this->getEnabled(true)) |
|
509 | + if ($this->getVisible(true) && $this->getEnabled(true)) |
|
510 | 510 | { |
511 | - $target=$this->getValidationTarget(); |
|
511 | + $target = $this->getValidationTarget(); |
|
512 | 512 | // if the target is not a disabled web control |
513 | - if($target===null || |
|
514 | - ($target!==null && |
|
513 | + if ($target === null || |
|
514 | + ($target !== null && |
|
515 | 515 | !($target instanceof TWebControl && !$target->getEnabled(true)))) |
516 | 516 | { |
517 | - if($this->evaluateIsValid()) |
|
517 | + if ($this->evaluateIsValid()) |
|
518 | 518 | { |
519 | 519 | $this->setIsValid(true); |
520 | 520 | $this->onValidationSuccess(); |
521 | 521 | } |
522 | 522 | else |
523 | 523 | { |
524 | - if($target) |
|
524 | + if ($target) |
|
525 | 525 | $target->setIsValid(false); |
526 | 526 | $this->setIsValid(false); |
527 | 527 | $this->onValidationError(); |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | */ |
545 | 545 | public function getControlCssClass() |
546 | 546 | { |
547 | - return $this->getViewState('ControlCssClass',''); |
|
547 | + return $this->getViewState('ControlCssClass', ''); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | /** |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | */ |
553 | 553 | public function setControlCssClass($value) |
554 | 554 | { |
555 | - $this->setViewState('ControlCssClass',$value,''); |
|
555 | + $this->setViewState('ControlCssClass', $value, ''); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | /** |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | */ |
568 | 568 | public function onValidationSuccess() |
569 | 569 | { |
570 | - $this->raiseEvent('OnValidationSuccess',$this,null); |
|
570 | + $this->raiseEvent('OnValidationSuccess', $this, null); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | */ |
576 | 576 | public function onValidationError() |
577 | 577 | { |
578 | - $this->raiseEvent('OnValidationError',$this,null); |
|
578 | + $this->raiseEvent('OnValidationError', $this, null); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | */ |
587 | 587 | public function onValidate() |
588 | 588 | { |
589 | - $this->raiseEvent('OnValidate',$this,null); |
|
589 | + $this->raiseEvent('OnValidate', $this, null); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | /** |
@@ -595,9 +595,9 @@ discard block |
||
595 | 595 | */ |
596 | 596 | public function renderContents($writer) |
597 | 597 | { |
598 | - if(($text=$this->getText())!=='') |
|
598 | + if (($text = $this->getText()) !== '') |
|
599 | 599 | $writer->write($text); |
600 | - else if(($text=$this->getErrorMessage())!=='') |
|
600 | + else if (($text = $this->getErrorMessage()) !== '') |
|
601 | 601 | $writer->write($text); |
602 | 602 | else |
603 | 603 | parent::renderContents($writer); |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | public function getObserveChanges() |
697 | 697 | { |
698 | 698 | $changes = $this->getOption('ObserveChanges'); |
699 | - return ($changes===null) ? true : $changes; |
|
699 | + return ($changes === null) ? true : $changes; |
|
700 | 700 | } |
701 | 701 | } |
702 | 702 | |
@@ -717,9 +717,9 @@ discard block |
||
717 | 717 | */ |
718 | 718 | class TValidatorDisplayStyle extends TEnumerable |
719 | 719 | { |
720 | - const None='None'; |
|
721 | - const Dynamic='Dynamic'; |
|
722 | - const Fixed='Fixed'; |
|
720 | + const None = 'None'; |
|
721 | + const Dynamic = 'Dynamic'; |
|
722 | + const Fixed = 'Fixed'; |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | /** |
@@ -739,9 +739,9 @@ discard block |
||
739 | 739 | */ |
740 | 740 | class TValidationDataType extends TEnumerable |
741 | 741 | { |
742 | - const Integer='Integer'; |
|
743 | - const Float='Float'; |
|
744 | - const Date='Date'; |
|
745 | - const String='String'; |
|
742 | + const Integer = 'Integer'; |
|
743 | + const Float = 'Float'; |
|
744 | + const Date = 'Date'; |
|
745 | + const String = 'String'; |
|
746 | 746 | } |
747 | 747 |
@@ -120,8 +120,9 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function onUnload($param) |
122 | 122 | { |
123 | - if($this->_registered && ($page=$this->getPage())!==null) |
|
124 | - $page->getValidators()->remove($this); |
|
123 | + if($this->_registered && ($page=$this->getPage())!==null) { |
|
124 | + $page->getValidators()->remove($this); |
|
125 | + } |
|
125 | 126 | $this->_registered=false; |
126 | 127 | parent::onUnload($param); |
127 | 128 | } |
@@ -135,10 +136,11 @@ discard block |
||
135 | 136 | { |
136 | 137 | $display=$this->getDisplay(); |
137 | 138 | $visible=$this->getEnabled(true) && !$this->getIsValid(); |
138 | - if($display===TValidatorDisplayStyle::None || (!$visible && $display===TValidatorDisplayStyle::Dynamic)) |
|
139 | - $writer->addStyleAttribute('display','none'); |
|
140 | - else if(!$visible) |
|
141 | - $writer->addStyleAttribute('visibility','hidden'); |
|
139 | + if($display===TValidatorDisplayStyle::None || (!$visible && $display===TValidatorDisplayStyle::Dynamic)) { |
|
140 | + $writer->addStyleAttribute('display','none'); |
|
141 | + } else if(!$visible) { |
|
142 | + $writer->addStyleAttribute('visibility','hidden'); |
|
143 | + } |
|
142 | 144 | $writer->addAttribute('id',$this->getClientID()); |
143 | 145 | parent::addAttributesToRender($writer); |
144 | 146 | $this->renderClientControlScript($writer); |
@@ -161,16 +163,18 @@ discard block |
||
161 | 163 | $options['FocusElementID'] = $this->getFocusElementID(); |
162 | 164 | } |
163 | 165 | $options['ValidationGroup'] = $this->getValidationGroup(); |
164 | - if($control) |
|
165 | - $options['ControlToValidate'] = $control->getClientID(); |
|
166 | + if($control) { |
|
167 | + $options['ControlToValidate'] = $control->getClientID(); |
|
168 | + } |
|
166 | 169 | $options['ControlCssClass'] = $this->getControlCssClass(); |
167 | 170 | |
168 | 171 | $options['ControlType'] = $this->getClientControlClass($control); |
169 | 172 | $options['Enabled'] = $this->getEnabled(true); |
170 | 173 | |
171 | 174 | //get date format from date picker target control |
172 | - if($control instanceof TDatePicker) |
|
173 | - $options['DateFormat'] = $control->getDateFormat(); |
|
175 | + if($control instanceof TDatePicker) { |
|
176 | + $options['DateFormat'] = $control->getDateFormat(); |
|
177 | + } |
|
174 | 178 | |
175 | 179 | $options = array_merge($options,$this->getClientSide()->getOptions()->toArray()); |
176 | 180 | |
@@ -186,9 +190,10 @@ discard block |
||
186 | 190 | */ |
187 | 191 | private function getClientControlClass($control) |
188 | 192 | { |
189 | - foreach(self::$_clientClass as $type) |
|
190 | - if($control instanceof $type) |
|
193 | + foreach(self::$_clientClass as $type) { |
|
194 | + if($control instanceof $type) |
|
191 | 195 | return $type; |
196 | + } |
|
192 | 197 | return get_class($control); |
193 | 198 | } |
194 | 199 | |
@@ -210,8 +215,9 @@ discard block |
||
210 | 215 | */ |
211 | 216 | public function getClientSide() |
212 | 217 | { |
213 | - if($this->_clientSide===null) |
|
214 | - $this->_clientSide = $this->createClientSide(); |
|
218 | + if($this->_clientSide===null) { |
|
219 | + $this->_clientSide = $this->createClientSide(); |
|
220 | + } |
|
215 | 221 | return $this->_clientSide; |
216 | 222 | } |
217 | 223 | |
@@ -232,8 +238,9 @@ discard block |
||
232 | 238 | public function renderClientControlScript($writer) |
233 | 239 | { |
234 | 240 | $scripts = $this->getPage()->getClientScript(); |
235 | - if ($this->getEnableClientScript()) |
|
236 | - $scripts->registerPradoScript('validator'); |
|
241 | + if ($this->getEnableClientScript()) { |
|
242 | + $scripts->registerPradoScript('validator'); |
|
243 | + } |
|
237 | 244 | $formID=$this->getPage()->getForm()->getClientID(); |
238 | 245 | $scriptKey = "TBaseValidator:$formID"; |
239 | 246 | if($this->getEnableClientScript() && !$scripts->isEndScriptRegistered($scriptKey)) |
@@ -242,8 +249,9 @@ discard block |
||
242 | 249 | $options = TJavaScript::encode($manager); |
243 | 250 | $scripts->registerEndScript($scriptKey, "new Prado.ValidationManager({$options});"); |
244 | 251 | } |
245 | - if($this->getEnableClientScript()) |
|
246 | - $this->registerClientScriptValidator(); |
|
252 | + if($this->getEnableClientScript()) { |
|
253 | + $this->registerClientScriptValidator(); |
|
254 | + } |
|
247 | 255 | } |
248 | 256 | |
249 | 257 | /** |
@@ -273,8 +281,9 @@ discard block |
||
273 | 281 | { |
274 | 282 | $class .= ' '.$cssClass; |
275 | 283 | $control->setCssClass($class); |
276 | - } elseif ($control->getIsValid()) |
|
277 | - $control->setCssClass($class); |
|
284 | + } elseif ($control->getIsValid()) { |
|
285 | + $control->setCssClass($class); |
|
286 | + } |
|
278 | 287 | } |
279 | 288 | } |
280 | 289 | } |
@@ -318,8 +327,9 @@ discard block |
||
318 | 327 | { |
319 | 328 | $value=TPropertyValue::ensureBoolean($value); |
320 | 329 | parent::setEnabled($value); |
321 | - if(!$value) |
|
322 | - $this->_isValid=true; |
|
330 | + if(!$value) { |
|
331 | + $this->_isValid=true; |
|
332 | + } |
|
323 | 333 | } |
324 | 334 | |
325 | 335 | /** |
@@ -478,10 +488,11 @@ discard block |
||
478 | 488 | */ |
479 | 489 | public function getValidationTarget() |
480 | 490 | { |
481 | - if(($id=$this->getControlToValidate())!=='' && ($control=$this->findControl($id))!==null) |
|
482 | - return $control; |
|
483 | - else |
|
484 | - throw new TConfigurationException('basevalidator_controltovalidate_invalid',get_class($this)); |
|
491 | + if(($id=$this->getControlToValidate())!=='' && ($control=$this->findControl($id))!==null) { |
|
492 | + return $control; |
|
493 | + } else { |
|
494 | + throw new TConfigurationException('basevalidator_controltovalidate_invalid',get_class($this)); |
|
495 | + } |
|
485 | 496 | } |
486 | 497 | |
487 | 498 | /** |
@@ -492,10 +503,11 @@ discard block |
||
492 | 503 | */ |
493 | 504 | protected function getValidationValue($control) |
494 | 505 | { |
495 | - if($control instanceof IValidatable) |
|
496 | - return $control->getValidationPropertyValue(); |
|
497 | - else |
|
498 | - throw new TInvalidDataTypeException('basevalidator_validatable_required',get_class($this)); |
|
506 | + if($control instanceof IValidatable) { |
|
507 | + return $control->getValidationPropertyValue(); |
|
508 | + } else { |
|
509 | + throw new TInvalidDataTypeException('basevalidator_validatable_required',get_class($this)); |
|
510 | + } |
|
499 | 511 | } |
500 | 512 | |
501 | 513 | /** |
@@ -518,16 +530,15 @@ discard block |
||
518 | 530 | { |
519 | 531 | $this->setIsValid(true); |
520 | 532 | $this->onValidationSuccess(); |
521 | - } |
|
522 | - else |
|
533 | + } else |
|
523 | 534 | { |
524 | - if($target) |
|
525 | - $target->setIsValid(false); |
|
535 | + if($target) { |
|
536 | + $target->setIsValid(false); |
|
537 | + } |
|
526 | 538 | $this->setIsValid(false); |
527 | 539 | $this->onValidationError(); |
528 | 540 | } |
529 | - } |
|
530 | - else |
|
541 | + } else |
|
531 | 542 | { |
532 | 543 | $this->evaluateIsValid(); |
533 | 544 | $this->setIsValid(true); |
@@ -595,12 +606,13 @@ discard block |
||
595 | 606 | */ |
596 | 607 | public function renderContents($writer) |
597 | 608 | { |
598 | - if(($text=$this->getText())!=='') |
|
599 | - $writer->write($text); |
|
600 | - else if(($text=$this->getErrorMessage())!=='') |
|
601 | - $writer->write($text); |
|
602 | - else |
|
603 | - parent::renderContents($writer); |
|
609 | + if(($text=$this->getText())!=='') { |
|
610 | + $writer->write($text); |
|
611 | + } else if(($text=$this->getErrorMessage())!=='') { |
|
612 | + $writer->write($text); |
|
613 | + } else { |
|
614 | + parent::renderContents($writer); |
|
615 | + } |
|
604 | 616 | } |
605 | 617 | } |
606 | 618 |
@@ -216,6 +216,7 @@ discard block |
||
216 | 216 | * This method is invoked when the {@link getDisplayMode DisplayMode} is 'LinkButton' |
217 | 217 | * and end-users click on one of the buttons. |
218 | 218 | * @param TBulletedListEventParameter event parameter. |
219 | + * @param TBulletedListEventParameter $param |
|
219 | 220 | */ |
220 | 221 | public function onClick($param) |
221 | 222 | { |
@@ -425,6 +426,7 @@ discard block |
||
425 | 426 | /** |
426 | 427 | * Constructor. |
427 | 428 | * @param integer index of the item clicked |
429 | + * @param integer $index |
|
428 | 430 | */ |
429 | 431 | public function __construct($index) |
430 | 432 | { |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function raisePostBackEvent($param) |
61 | 61 | { |
62 | - if($this->getCausesValidation()) |
|
62 | + if ($this->getCausesValidation()) |
|
63 | 63 | $this->getPage()->validate($this->getValidationGroup()); |
64 | - $this->onClick(new TBulletedListEventParameter((int)$param)); |
|
64 | + $this->onClick(new TBulletedListEventParameter((int) $param)); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | protected function getTagName() |
71 | 71 | { |
72 | - switch($this->getBulletStyle()) |
|
72 | + switch ($this->getBulletStyle()) |
|
73 | 73 | { |
74 | 74 | case TBulletStyle::Numbered: |
75 | 75 | case TBulletStyle::LowerAlpha: |
@@ -98,49 +98,49 @@ discard block |
||
98 | 98 | */ |
99 | 99 | protected function addAttributesToRender($writer) |
100 | 100 | { |
101 | - $needStart=false; |
|
102 | - switch($this->getBulletStyle()) |
|
101 | + $needStart = false; |
|
102 | + switch ($this->getBulletStyle()) |
|
103 | 103 | { |
104 | 104 | case TBulletStyle::None: |
105 | - $writer->addStyleAttribute('list-style-type','none'); |
|
106 | - $needStart=true; |
|
105 | + $writer->addStyleAttribute('list-style-type', 'none'); |
|
106 | + $needStart = true; |
|
107 | 107 | break; |
108 | 108 | case TBulletStyle::Numbered: |
109 | - $writer->addStyleAttribute('list-style-type','decimal'); |
|
110 | - $needStart=true; |
|
109 | + $writer->addStyleAttribute('list-style-type', 'decimal'); |
|
110 | + $needStart = true; |
|
111 | 111 | break; |
112 | 112 | case TBulletStyle::LowerAlpha: |
113 | - $writer->addStyleAttribute('list-style-type','lower-alpha'); |
|
114 | - $needStart=true; |
|
113 | + $writer->addStyleAttribute('list-style-type', 'lower-alpha'); |
|
114 | + $needStart = true; |
|
115 | 115 | break; |
116 | 116 | case TBulletStyle::UpperAlpha: |
117 | - $writer->addStyleAttribute('list-style-type','upper-alpha'); |
|
118 | - $needStart=true; |
|
117 | + $writer->addStyleAttribute('list-style-type', 'upper-alpha'); |
|
118 | + $needStart = true; |
|
119 | 119 | break; |
120 | 120 | case TBulletStyle::LowerRoman: |
121 | - $writer->addStyleAttribute('list-style-type','lower-roman'); |
|
122 | - $needStart=true; |
|
121 | + $writer->addStyleAttribute('list-style-type', 'lower-roman'); |
|
122 | + $needStart = true; |
|
123 | 123 | break; |
124 | 124 | case TBulletStyle::UpperRoman: |
125 | - $writer->addStyleAttribute('list-style-type','upper-roman'); |
|
126 | - $needStart=true; |
|
125 | + $writer->addStyleAttribute('list-style-type', 'upper-roman'); |
|
126 | + $needStart = true; |
|
127 | 127 | break; |
128 | 128 | case TBulletStyle::Disc: |
129 | - $writer->addStyleAttribute('list-style-type','disc'); |
|
129 | + $writer->addStyleAttribute('list-style-type', 'disc'); |
|
130 | 130 | break; |
131 | 131 | case TBulletStyle::Circle: |
132 | - $writer->addStyleAttribute('list-style-type','circle'); |
|
132 | + $writer->addStyleAttribute('list-style-type', 'circle'); |
|
133 | 133 | break; |
134 | 134 | case TBulletStyle::Square: |
135 | - $writer->addStyleAttribute('list-style-type','square'); |
|
135 | + $writer->addStyleAttribute('list-style-type', 'square'); |
|
136 | 136 | break; |
137 | 137 | case TBulletStyle::CustomImage: |
138 | - $url=$this->getBulletImageUrl(); |
|
139 | - $writer->addStyleAttribute('list-style-image',"url($url)"); |
|
138 | + $url = $this->getBulletImageUrl(); |
|
139 | + $writer->addStyleAttribute('list-style-image', "url($url)"); |
|
140 | 140 | break; |
141 | 141 | } |
142 | - if($needStart && ($start=$this->getFirstBulletNumber())!=1) |
|
143 | - $writer->addAttribute('start',"$start"); |
|
142 | + if ($needStart && ($start = $this->getFirstBulletNumber()) != 1) |
|
143 | + $writer->addAttribute('start', "$start"); |
|
144 | 144 | parent::addAttributesToRender($writer); |
145 | 145 | } |
146 | 146 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function getBulletImageUrl() |
151 | 151 | { |
152 | - return $this->getViewState('BulletImageUrl',''); |
|
152 | + return $this->getViewState('BulletImageUrl', ''); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function setBulletImageUrl($value) |
159 | 159 | { |
160 | - $this->setViewState('BulletImageUrl',$value,''); |
|
160 | + $this->setViewState('BulletImageUrl', $value, ''); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function getBulletStyle() |
167 | 167 | { |
168 | - return $this->getViewState('BulletStyle',TBulletStyle::NotSet); |
|
168 | + return $this->getViewState('BulletStyle', TBulletStyle::NotSet); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | public function setBulletStyle($value) |
175 | 175 | { |
176 | - $this->setViewState('BulletStyle',TPropertyValue::ensureEnum($value,'TBulletStyle'),TBulletStyle::NotSet); |
|
176 | + $this->setViewState('BulletStyle', TPropertyValue::ensureEnum($value, 'TBulletStyle'), TBulletStyle::NotSet); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function getDisplayMode() |
183 | 183 | { |
184 | - return $this->getViewState('DisplayMode',TBulletedListDisplayMode::Text); |
|
184 | + return $this->getViewState('DisplayMode', TBulletedListDisplayMode::Text); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | */ |
190 | 190 | public function setDisplayMode($value) |
191 | 191 | { |
192 | - $this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'TBulletedListDisplayMode'),TBulletedListDisplayMode::Text); |
|
192 | + $this->setViewState('DisplayMode', TPropertyValue::ensureEnum($value, 'TBulletedListDisplayMode'), TBulletedListDisplayMode::Text); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function getFirstBulletNumber() |
201 | 201 | { |
202 | - return $this->getViewState('FirstBulletNumber',1); |
|
202 | + return $this->getViewState('FirstBulletNumber', 1); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function setFirstBulletNumber($value) |
210 | 210 | { |
211 | - $this->setViewState('FirstBulletNumber',TPropertyValue::ensureInteger($value),1); |
|
211 | + $this->setViewState('FirstBulletNumber', TPropertyValue::ensureInteger($value), 1); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public function onClick($param) |
221 | 221 | { |
222 | - $this->raiseEvent('OnClick',$this,$param); |
|
222 | + $this->raiseEvent('OnClick', $this, $param); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function getTarget() |
231 | 231 | { |
232 | - return $this->getViewState('Target',''); |
|
232 | + return $this->getViewState('Target', ''); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function setTarget($value) |
241 | 241 | { |
242 | - $this->setViewState('Target',$value,''); |
|
242 | + $this->setViewState('Target', $value, ''); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | */ |
249 | 249 | public function render($writer) |
250 | 250 | { |
251 | - if($this->getHasItems()) |
|
251 | + if ($this->getHasItems()) |
|
252 | 252 | parent::render($writer); |
253 | 253 | } |
254 | 254 | |
@@ -258,15 +258,15 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function renderContents($writer) |
260 | 260 | { |
261 | - $this->_isEnabled=$this->getEnabled(true); |
|
262 | - $this->_postBackOptions=$this->getPostBackOptions(); |
|
261 | + $this->_isEnabled = $this->getEnabled(true); |
|
262 | + $this->_postBackOptions = $this->getPostBackOptions(); |
|
263 | 263 | $writer->writeLine(); |
264 | - foreach($this->getItems() as $index=>$item) |
|
264 | + foreach ($this->getItems() as $index=>$item) |
|
265 | 265 | { |
266 | - if($item->getHasAttributes()) |
|
266 | + if ($item->getHasAttributes()) |
|
267 | 267 | $writer->addAttributes($item->getAttributes()); |
268 | 268 | $writer->renderBeginTag('li'); |
269 | - $this->renderBulletText($writer,$item,$index); |
|
269 | + $this->renderBulletText($writer, $item, $index); |
|
270 | 270 | $writer->renderEndTag(); |
271 | 271 | $writer->writeLine(); |
272 | 272 | } |
@@ -278,9 +278,9 @@ discard block |
||
278 | 278 | * @param TListItem item to be rendered |
279 | 279 | * @param integer index of the item being rendered |
280 | 280 | */ |
281 | - protected function renderBulletText($writer,$item,$index) |
|
281 | + protected function renderBulletText($writer, $item, $index) |
|
282 | 282 | { |
283 | - switch($this->getDisplayMode()) |
|
283 | + switch ($this->getDisplayMode()) |
|
284 | 284 | { |
285 | 285 | case TBulletedListDisplayMode::Text: |
286 | 286 | $this->renderTextItem($writer, $item, $index); |
@@ -296,11 +296,11 @@ discard block |
||
296 | 296 | |
297 | 297 | protected function renderTextItem($writer, $item, $index) |
298 | 298 | { |
299 | - if($item->getEnabled()) |
|
299 | + if ($item->getEnabled()) |
|
300 | 300 | $writer->write(THttpUtility::htmlEncode($item->getText())); |
301 | 301 | else |
302 | 302 | { |
303 | - $writer->addAttribute('disabled','disabled'); |
|
303 | + $writer->addAttribute('disabled', 'disabled'); |
|
304 | 304 | $writer->renderBeginTag('span'); |
305 | 305 | $writer->write(THttpUtility::htmlEncode($item->getText())); |
306 | 306 | $writer->renderEndTag(); |
@@ -309,16 +309,16 @@ discard block |
||
309 | 309 | |
310 | 310 | protected function renderHyperLinkItem($writer, $item, $index) |
311 | 311 | { |
312 | - if(!$this->_isEnabled || !$item->getEnabled()) |
|
313 | - $writer->addAttribute('disabled','disabled'); |
|
312 | + if (!$this->_isEnabled || !$item->getEnabled()) |
|
313 | + $writer->addAttribute('disabled', 'disabled'); |
|
314 | 314 | else |
315 | 315 | { |
316 | - $writer->addAttribute('href',$item->getValue()); |
|
317 | - if(($target=$this->getTarget())!=='') |
|
318 | - $writer->addAttribute('target',$target); |
|
316 | + $writer->addAttribute('href', $item->getValue()); |
|
317 | + if (($target = $this->getTarget()) !== '') |
|
318 | + $writer->addAttribute('target', $target); |
|
319 | 319 | } |
320 | - if(($accesskey=$this->getAccessKey())!=='') |
|
321 | - $writer->addAttribute('accesskey',$accesskey); |
|
320 | + if (($accesskey = $this->getAccessKey()) !== '') |
|
321 | + $writer->addAttribute('accesskey', $accesskey); |
|
322 | 322 | $writer->renderBeginTag('a'); |
323 | 323 | $writer->write(THttpUtility::htmlEncode($item->getText())); |
324 | 324 | $writer->renderEndTag(); |
@@ -326,18 +326,18 @@ discard block |
||
326 | 326 | |
327 | 327 | protected function renderLinkButtonItem($writer, $item, $index) |
328 | 328 | { |
329 | - if(!$this->_isEnabled || !$item->getEnabled()) |
|
330 | - $writer->addAttribute('disabled','disabled'); |
|
329 | + if (!$this->_isEnabled || !$item->getEnabled()) |
|
330 | + $writer->addAttribute('disabled', 'disabled'); |
|
331 | 331 | else |
332 | 332 | { |
333 | 333 | $this->_currentRenderItemIndex = $index; |
334 | - $writer->addAttribute('id', $this->getClientID().$index); |
|
335 | - $writer->addAttribute('href', "javascript:;//".$this->getClientID().$index); |
|
334 | + $writer->addAttribute('id', $this->getClientID() . $index); |
|
335 | + $writer->addAttribute('href', "javascript:;//" . $this->getClientID() . $index); |
|
336 | 336 | $cs = $this->getPage()->getClientScript(); |
337 | - $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions()); |
|
337 | + $cs->registerPostBackControl($this->getClientClassName(), $this->getPostBackOptions()); |
|
338 | 338 | } |
339 | - if(($accesskey=$this->getAccessKey())!=='') |
|
340 | - $writer->addAttribute('accesskey',$accesskey); |
|
339 | + if (($accesskey = $this->getAccessKey()) !== '') |
|
340 | + $writer->addAttribute('accesskey', $accesskey); |
|
341 | 341 | $writer->renderBeginTag('a'); |
342 | 342 | $writer->write(THttpUtility::htmlEncode($item->getText())); |
343 | 343 | $writer->renderEndTag(); |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | $options['CausesValidation'] = $this->getCausesValidation(); |
353 | 353 | $options['EventTarget'] = $this->getUniqueID(); |
354 | 354 | $options['EventParameter'] = $this->_currentRenderItemIndex; |
355 | - $options['ID'] = $this->getClientID().$this->_currentRenderItemIndex; |
|
355 | + $options['ID'] = $this->getClientID() . $this->_currentRenderItemIndex; |
|
356 | 356 | $options['StopEvent'] = true; |
357 | 357 | return $options; |
358 | 358 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | protected function canCauseValidation() |
361 | 361 | { |
362 | 362 | $group = $this->getValidationGroup(); |
363 | - $hasValidators = $this->getPage()->getValidators($group)->getCount()>0; |
|
363 | + $hasValidators = $this->getPage()->getValidators($group)->getCount() > 0; |
|
364 | 364 | return $this->getCausesValidation() && $hasValidators; |
365 | 365 | } |
366 | 366 | |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | */ |
429 | 429 | public function __construct($index) |
430 | 430 | { |
431 | - $this->_index=$index; |
|
431 | + $this->_index = $index; |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -451,17 +451,17 @@ discard block |
||
451 | 451 | */ |
452 | 452 | class TBulletStyle extends TEnumerable |
453 | 453 | { |
454 | - const NotSet='NotSet'; |
|
455 | - const None='None'; |
|
456 | - const Numbered='Numbered'; |
|
457 | - const LowerAlpha='LowerAlpha'; |
|
458 | - const UpperAlpha='UpperAlpha'; |
|
459 | - const LowerRoman='LowerRoman'; |
|
460 | - const UpperRoman='UpperRoman'; |
|
461 | - const Disc='Disc'; |
|
462 | - const Circle='Circle'; |
|
463 | - const Square='Square'; |
|
464 | - const CustomImage='CustomImage'; |
|
454 | + const NotSet = 'NotSet'; |
|
455 | + const None = 'None'; |
|
456 | + const Numbered = 'Numbered'; |
|
457 | + const LowerAlpha = 'LowerAlpha'; |
|
458 | + const UpperAlpha = 'UpperAlpha'; |
|
459 | + const LowerRoman = 'LowerRoman'; |
|
460 | + const UpperRoman = 'UpperRoman'; |
|
461 | + const Disc = 'Disc'; |
|
462 | + const Circle = 'Circle'; |
|
463 | + const Square = 'Square'; |
|
464 | + const CustomImage = 'CustomImage'; |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /** |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | */ |
481 | 481 | class TBulletedListDisplayMode extends TEnumerable |
482 | 482 | { |
483 | - const Text='Text'; |
|
484 | - const HyperLink='HyperLink'; |
|
485 | - const LinkButton='LinkButton'; |
|
483 | + const Text = 'Text'; |
|
484 | + const HyperLink = 'HyperLink'; |
|
485 | + const LinkButton = 'LinkButton'; |
|
486 | 486 | } |
487 | 487 |
@@ -59,8 +59,9 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function raisePostBackEvent($param) |
61 | 61 | { |
62 | - if($this->getCausesValidation()) |
|
63 | - $this->getPage()->validate($this->getValidationGroup()); |
|
62 | + if($this->getCausesValidation()) { |
|
63 | + $this->getPage()->validate($this->getValidationGroup()); |
|
64 | + } |
|
64 | 65 | $this->onClick(new TBulletedListEventParameter((int)$param)); |
65 | 66 | } |
66 | 67 | |
@@ -139,8 +140,9 @@ discard block |
||
139 | 140 | $writer->addStyleAttribute('list-style-image',"url($url)"); |
140 | 141 | break; |
141 | 142 | } |
142 | - if($needStart && ($start=$this->getFirstBulletNumber())!=1) |
|
143 | - $writer->addAttribute('start',"$start"); |
|
143 | + if($needStart && ($start=$this->getFirstBulletNumber())!=1) { |
|
144 | + $writer->addAttribute('start',"$start"); |
|
145 | + } |
|
144 | 146 | parent::addAttributesToRender($writer); |
145 | 147 | } |
146 | 148 | |
@@ -248,8 +250,9 @@ discard block |
||
248 | 250 | */ |
249 | 251 | public function render($writer) |
250 | 252 | { |
251 | - if($this->getHasItems()) |
|
252 | - parent::render($writer); |
|
253 | + if($this->getHasItems()) { |
|
254 | + parent::render($writer); |
|
255 | + } |
|
253 | 256 | } |
254 | 257 | |
255 | 258 | /** |
@@ -263,8 +266,9 @@ discard block |
||
263 | 266 | $writer->writeLine(); |
264 | 267 | foreach($this->getItems() as $index=>$item) |
265 | 268 | { |
266 | - if($item->getHasAttributes()) |
|
267 | - $writer->addAttributes($item->getAttributes()); |
|
269 | + if($item->getHasAttributes()) { |
|
270 | + $writer->addAttributes($item->getAttributes()); |
|
271 | + } |
|
268 | 272 | $writer->renderBeginTag('li'); |
269 | 273 | $this->renderBulletText($writer,$item,$index); |
270 | 274 | $writer->renderEndTag(); |
@@ -296,9 +300,9 @@ discard block |
||
296 | 300 | |
297 | 301 | protected function renderTextItem($writer, $item, $index) |
298 | 302 | { |
299 | - if($item->getEnabled()) |
|
300 | - $writer->write(THttpUtility::htmlEncode($item->getText())); |
|
301 | - else |
|
303 | + if($item->getEnabled()) { |
|
304 | + $writer->write(THttpUtility::htmlEncode($item->getText())); |
|
305 | + } else |
|
302 | 306 | { |
303 | 307 | $writer->addAttribute('disabled','disabled'); |
304 | 308 | $writer->renderBeginTag('span'); |
@@ -309,16 +313,18 @@ discard block |
||
309 | 313 | |
310 | 314 | protected function renderHyperLinkItem($writer, $item, $index) |
311 | 315 | { |
312 | - if(!$this->_isEnabled || !$item->getEnabled()) |
|
313 | - $writer->addAttribute('disabled','disabled'); |
|
314 | - else |
|
316 | + if(!$this->_isEnabled || !$item->getEnabled()) { |
|
317 | + $writer->addAttribute('disabled','disabled'); |
|
318 | + } else |
|
315 | 319 | { |
316 | 320 | $writer->addAttribute('href',$item->getValue()); |
317 | - if(($target=$this->getTarget())!=='') |
|
318 | - $writer->addAttribute('target',$target); |
|
321 | + if(($target=$this->getTarget())!=='') { |
|
322 | + $writer->addAttribute('target',$target); |
|
323 | + } |
|
324 | + } |
|
325 | + if(($accesskey=$this->getAccessKey())!=='') { |
|
326 | + $writer->addAttribute('accesskey',$accesskey); |
|
319 | 327 | } |
320 | - if(($accesskey=$this->getAccessKey())!=='') |
|
321 | - $writer->addAttribute('accesskey',$accesskey); |
|
322 | 328 | $writer->renderBeginTag('a'); |
323 | 329 | $writer->write(THttpUtility::htmlEncode($item->getText())); |
324 | 330 | $writer->renderEndTag(); |
@@ -326,9 +332,9 @@ discard block |
||
326 | 332 | |
327 | 333 | protected function renderLinkButtonItem($writer, $item, $index) |
328 | 334 | { |
329 | - if(!$this->_isEnabled || !$item->getEnabled()) |
|
330 | - $writer->addAttribute('disabled','disabled'); |
|
331 | - else |
|
335 | + if(!$this->_isEnabled || !$item->getEnabled()) { |
|
336 | + $writer->addAttribute('disabled','disabled'); |
|
337 | + } else |
|
332 | 338 | { |
333 | 339 | $this->_currentRenderItemIndex = $index; |
334 | 340 | $writer->addAttribute('id', $this->getClientID().$index); |
@@ -336,8 +342,9 @@ discard block |
||
336 | 342 | $cs = $this->getPage()->getClientScript(); |
337 | 343 | $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions()); |
338 | 344 | } |
339 | - if(($accesskey=$this->getAccessKey())!=='') |
|
340 | - $writer->addAttribute('accesskey',$accesskey); |
|
345 | + if(($accesskey=$this->getAccessKey())!=='') { |
|
346 | + $writer->addAttribute('accesskey',$accesskey); |
|
347 | + } |
|
341 | 348 | $writer->renderBeginTag('a'); |
342 | 349 | $writer->write(THttpUtility::htmlEncode($item->getText())); |
343 | 350 | $writer->renderEndTag(); |
@@ -218,6 +218,7 @@ discard block |
||
218 | 218 | * If you override this method, be sure to call the parent implementation |
219 | 219 | * so that the event handlers can be invoked. |
220 | 220 | * @param TCommandEventParameter event parameter to be passed to the event handlers |
221 | + * @param TCommandEventParameter $param |
|
221 | 222 | */ |
222 | 223 | public function onCommand($param) |
223 | 224 | { |
@@ -342,6 +343,7 @@ discard block |
||
342 | 343 | |
343 | 344 | /** |
344 | 345 | * @param string the group of validators which the button causes validation upon postback |
346 | + * @param string $value |
|
345 | 347 | */ |
346 | 348 | public function setValidationGroup($value) |
347 | 349 | { |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function getButtonTag() |
62 | 62 | { |
63 | - return $this->getViewState('ButtonTag',TButtonTag::Input); |
|
63 | + return $this->getViewState('ButtonTag', TButtonTag::Input); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function setButtonTag($value) |
70 | 70 | { |
71 | - $this->setViewState('ButtonTag',TPropertyValue::ensureEnum($value,'TButtonTag'),TButtonTag::Input); |
|
71 | + $this->setViewState('ButtonTag', TPropertyValue::ensureEnum($value, 'TButtonTag'), TButtonTag::Input); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function getEnableClientScript() |
78 | 78 | { |
79 | - return $this->getViewState('EnableClientScript',true); |
|
79 | + return $this->getViewState('EnableClientScript', true); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function setEnableClientScript($value) |
86 | 86 | { |
87 | - $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true); |
|
87 | + $this->setViewState('EnableClientScript', TPropertyValue::ensureBoolean($value), true); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,22 +94,22 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function addAttributesToRender($writer) |
96 | 96 | { |
97 | - $page=$this->getPage(); |
|
97 | + $page = $this->getPage(); |
|
98 | 98 | $page->ensureRenderInForm($this); |
99 | - $writer->addAttribute('type',strtolower($this->getButtonType())); |
|
100 | - if(($uniqueID=$this->getUniqueID())!=='') |
|
101 | - $writer->addAttribute('name',$uniqueID); |
|
102 | - if($this->getButtonTag()===TButtonTag::Button) |
|
99 | + $writer->addAttribute('type', strtolower($this->getButtonType())); |
|
100 | + if (($uniqueID = $this->getUniqueID()) !== '') |
|
101 | + $writer->addAttribute('name', $uniqueID); |
|
102 | + if ($this->getButtonTag() === TButtonTag::Button) |
|
103 | 103 | $this->addParsedObject($this->getText()); |
104 | 104 | else |
105 | - $writer->addAttribute('value',$this->getText()); |
|
106 | - if($this->getEnabled(true)) |
|
105 | + $writer->addAttribute('value', $this->getText()); |
|
106 | + if ($this->getEnabled(true)) |
|
107 | 107 | { |
108 | - if($this->getEnableClientScript() && $this->needPostBackScript()) |
|
108 | + if ($this->getEnableClientScript() && $this->needPostBackScript()) |
|
109 | 109 | $this->renderClientControlScript($writer); |
110 | 110 | } |
111 | - else if($this->getEnabled()) // in this case, parent will not render 'disabled' |
|
112 | - $writer->addAttribute('disabled','disabled'); |
|
111 | + else if ($this->getEnabled()) // in this case, parent will not render 'disabled' |
|
112 | + $writer->addAttribute('disabled', 'disabled'); |
|
113 | 113 | |
114 | 114 | parent::addAttributesToRender($writer); |
115 | 115 | } |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | */ |
120 | 120 | protected function renderClientControlScript($writer) |
121 | 121 | { |
122 | - $writer->addAttribute('id',$this->getClientID()); |
|
123 | - $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions()); |
|
122 | + $writer->addAttribute('id', $this->getClientID()); |
|
123 | + $this->getPage()->getClientScript()->registerPostBackControl($this->getClientClassName(), $this->getPostBackOptions()); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | */ |
139 | 139 | protected function canCauseValidation() |
140 | 140 | { |
141 | - if($this->getCausesValidation()) |
|
141 | + if ($this->getCausesValidation()) |
|
142 | 142 | { |
143 | - $group=$this->getValidationGroup(); |
|
144 | - return $this->getPage()->getValidators($group)->getCount()>0; |
|
143 | + $group = $this->getValidationGroup(); |
|
144 | + return $this->getPage()->getValidators($group)->getCount() > 0; |
|
145 | 145 | } |
146 | 146 | else |
147 | 147 | return false; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function setIsDefaultButton($value) |
154 | 154 | { |
155 | - $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value),false); |
|
155 | + $this->setViewState('IsDefaultButton', TPropertyValue::ensureBoolean($value), false); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | protected function needPostBackScript() |
170 | 170 | { |
171 | - return $this->canCauseValidation() || ($this->getButtonType()!==TButtonType::Submit && |
|
171 | + return $this->canCauseValidation() || ($this->getButtonType() !== TButtonType::Submit && |
|
172 | 172 | ($this->hasEventHandler('OnClick') || $this->hasEventHandler('OnCommand'))) |
173 | 173 | || $this->getIsDefaultButton(); |
174 | 174 | } |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | */ |
181 | 181 | protected function getPostBackOptions() |
182 | 182 | { |
183 | - $options['ID']=$this->getClientID(); |
|
184 | - $options['CausesValidation']=$this->getCausesValidation(); |
|
183 | + $options['ID'] = $this->getClientID(); |
|
184 | + $options['CausesValidation'] = $this->getCausesValidation(); |
|
185 | 185 | $options['EventTarget'] = $this->getUniqueID(); |
186 | - $options['ValidationGroup']=$this->getValidationGroup(); |
|
186 | + $options['ValidationGroup'] = $this->getValidationGroup(); |
|
187 | 187 | |
188 | 188 | return $options; |
189 | 189 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function renderContents($writer) |
198 | 198 | { |
199 | - if($this->getButtonTag()===TButtonTag::Button) |
|
199 | + if ($this->getButtonTag() === TButtonTag::Button) |
|
200 | 200 | parent::renderContents($writer); |
201 | 201 | } |
202 | 202 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function onClick($param) |
211 | 211 | { |
212 | - $this->raiseEvent('OnClick',$this,$param); |
|
212 | + $this->raiseEvent('OnClick', $this, $param); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | */ |
222 | 222 | public function onCommand($param) |
223 | 223 | { |
224 | - $this->raiseEvent('OnCommand',$this,$param); |
|
225 | - $this->raiseBubbleEvent($this,$param); |
|
224 | + $this->raiseEvent('OnCommand', $this, $param); |
|
225 | + $this->raiseBubbleEvent($this, $param); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -236,10 +236,10 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function raisePostBackEvent($param) |
238 | 238 | { |
239 | - if($this->getCausesValidation()) |
|
239 | + if ($this->getCausesValidation()) |
|
240 | 240 | $this->getPage()->validate($this->getValidationGroup()); |
241 | 241 | $this->onClick(null); |
242 | - $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter())); |
|
242 | + $this->onCommand(new TCommandEventParameter($this->getCommandName(), $this->getCommandParameter())); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function getText() |
249 | 249 | { |
250 | - return $this->getViewState('Text',''); |
|
250 | + return $this->getViewState('Text', ''); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | */ |
256 | 256 | public function setText($value) |
257 | 257 | { |
258 | - $this->setViewState('Text',$value,''); |
|
258 | + $this->setViewState('Text', $value, ''); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function getCausesValidation() |
291 | 291 | { |
292 | - return $this->getViewState('CausesValidation',true); |
|
292 | + return $this->getViewState('CausesValidation', true); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | */ |
298 | 298 | public function setCausesValidation($value) |
299 | 299 | { |
300 | - $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true); |
|
300 | + $this->setViewState('CausesValidation', TPropertyValue::ensureBoolean($value), true); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | */ |
306 | 306 | public function getCommandName() |
307 | 307 | { |
308 | - return $this->getViewState('CommandName',''); |
|
308 | + return $this->getViewState('CommandName', ''); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | */ |
314 | 314 | public function setCommandName($value) |
315 | 315 | { |
316 | - $this->setViewState('CommandName',$value,''); |
|
316 | + $this->setViewState('CommandName', $value, ''); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function getCommandParameter() |
323 | 323 | { |
324 | - return $this->getViewState('CommandParameter',''); |
|
324 | + return $this->getViewState('CommandParameter', ''); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | */ |
330 | 330 | public function setCommandParameter($value) |
331 | 331 | { |
332 | - $this->setViewState('CommandParameter',$value,''); |
|
332 | + $this->setViewState('CommandParameter', $value, ''); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | */ |
338 | 338 | public function getValidationGroup() |
339 | 339 | { |
340 | - return $this->getViewState('ValidationGroup',''); |
|
340 | + return $this->getViewState('ValidationGroup', ''); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function setValidationGroup($value) |
347 | 347 | { |
348 | - $this->setViewState('ValidationGroup',$value,''); |
|
348 | + $this->setViewState('ValidationGroup', $value, ''); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | */ |
354 | 354 | public function getButtonType() |
355 | 355 | { |
356 | - return $this->getViewState('ButtonType',TButtonType::Submit); |
|
356 | + return $this->getViewState('ButtonType', TButtonType::Submit); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | */ |
362 | 362 | public function setButtonType($value) |
363 | 363 | { |
364 | - $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TButtonType'),TButtonType::Submit); |
|
364 | + $this->setViewState('ButtonType', TPropertyValue::ensureEnum($value, 'TButtonType'), TButtonType::Submit); |
|
365 | 365 | } |
366 | 366 | } |
367 | 367 | |
@@ -380,9 +380,9 @@ discard block |
||
380 | 380 | */ |
381 | 381 | class TButtonType extends TEnumerable |
382 | 382 | { |
383 | - const Submit='Submit'; |
|
384 | - const Reset='Reset'; |
|
385 | - const Button='Button'; |
|
383 | + const Submit = 'Submit'; |
|
384 | + const Reset = 'Reset'; |
|
385 | + const Button = 'Button'; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | */ |
399 | 399 | class TButtonTag extends TEnumerable |
400 | 400 | { |
401 | - const Input='Input'; |
|
402 | - const Button='Button'; |
|
401 | + const Input = 'Input'; |
|
402 | + const Button = 'Button'; |
|
403 | 403 | } |
404 | 404 |
@@ -97,19 +97,23 @@ discard block |
||
97 | 97 | $page=$this->getPage(); |
98 | 98 | $page->ensureRenderInForm($this); |
99 | 99 | $writer->addAttribute('type',strtolower($this->getButtonType())); |
100 | - if(($uniqueID=$this->getUniqueID())!=='') |
|
101 | - $writer->addAttribute('name',$uniqueID); |
|
102 | - if($this->getButtonTag()===TButtonTag::Button) |
|
103 | - $this->addParsedObject($this->getText()); |
|
104 | - else |
|
105 | - $writer->addAttribute('value',$this->getText()); |
|
100 | + if(($uniqueID=$this->getUniqueID())!=='') { |
|
101 | + $writer->addAttribute('name',$uniqueID); |
|
102 | + } |
|
103 | + if($this->getButtonTag()===TButtonTag::Button) { |
|
104 | + $this->addParsedObject($this->getText()); |
|
105 | + } else { |
|
106 | + $writer->addAttribute('value',$this->getText()); |
|
107 | + } |
|
106 | 108 | if($this->getEnabled(true)) |
107 | 109 | { |
108 | - if($this->getEnableClientScript() && $this->needPostBackScript()) |
|
109 | - $this->renderClientControlScript($writer); |
|
110 | - } |
|
111 | - else if($this->getEnabled()) // in this case, parent will not render 'disabled' |
|
110 | + if($this->getEnableClientScript() && $this->needPostBackScript()) { |
|
111 | + $this->renderClientControlScript($writer); |
|
112 | + } |
|
113 | + } else if($this->getEnabled()) { |
|
114 | + // in this case, parent will not render 'disabled' |
|
112 | 115 | $writer->addAttribute('disabled','disabled'); |
116 | + } |
|
113 | 117 | |
114 | 118 | parent::addAttributesToRender($writer); |
115 | 119 | } |
@@ -142,9 +146,9 @@ discard block |
||
142 | 146 | { |
143 | 147 | $group=$this->getValidationGroup(); |
144 | 148 | return $this->getPage()->getValidators($group)->getCount()>0; |
149 | + } else { |
|
150 | + return false; |
|
145 | 151 | } |
146 | - else |
|
147 | - return false; |
|
148 | 152 | } |
149 | 153 | |
150 | 154 | /** |
@@ -196,8 +200,9 @@ discard block |
||
196 | 200 | */ |
197 | 201 | public function renderContents($writer) |
198 | 202 | { |
199 | - if($this->getButtonTag()===TButtonTag::Button) |
|
200 | - parent::renderContents($writer); |
|
203 | + if($this->getButtonTag()===TButtonTag::Button) { |
|
204 | + parent::renderContents($writer); |
|
205 | + } |
|
201 | 206 | } |
202 | 207 | |
203 | 208 | /** |
@@ -236,8 +241,9 @@ discard block |
||
236 | 241 | */ |
237 | 242 | public function raisePostBackEvent($param) |
238 | 243 | { |
239 | - if($this->getCausesValidation()) |
|
240 | - $this->getPage()->validate($this->getValidationGroup()); |
|
244 | + if($this->getCausesValidation()) { |
|
245 | + $this->getPage()->validate($this->getValidationGroup()); |
|
246 | + } |
|
241 | 247 | $this->onClick(null); |
242 | 248 | $this->onCommand(new TCommandEventParameter($this->getCommandName(),$this->getCommandParameter())); |
243 | 249 | } |
@@ -267,6 +267,7 @@ discard block |
||
267 | 267 | |
268 | 268 | /** |
269 | 269 | * @param string the public key used for generating the token. A random one will be generated if this is not set. |
270 | + * @param string $value |
|
270 | 271 | */ |
271 | 272 | public function setPublicKey($value) |
272 | 273 | { |
@@ -322,6 +323,7 @@ discard block |
||
322 | 323 | /** |
323 | 324 | * Validates a user input with the token. |
324 | 325 | * @param string user input |
326 | + * @param string $input |
|
325 | 327 | * @return boolean if the user input is not the same as the token. |
326 | 328 | */ |
327 | 329 | public function validate($input) |
@@ -447,6 +449,11 @@ discard block |
||
447 | 449 | * @param string private key |
448 | 450 | * @param integer the length of the token |
449 | 451 | * @param boolean whether the token is case sensitive |
452 | + * @param string $publicKey |
|
453 | + * @param string $privateKey |
|
454 | + * @param string $alphabet |
|
455 | + * @param integer $tokenLength |
|
456 | + * @param boolean $caseSensitive |
|
450 | 457 | * @return string the token generated. |
451 | 458 | */ |
452 | 459 | protected function generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive) |
@@ -459,6 +466,7 @@ discard block |
||
459 | 466 | * Converts a hash string into a string with characters consisting of alphanumeric characters. |
460 | 467 | * @param string the hexadecimal representation of the hash string |
461 | 468 | * @param string the alphabet used to represent the converted string. If empty, it means '234578adefhijmnrtwyABDEFGHIJLMNQRTWY', which excludes those confusing characters. |
469 | + * @param string $hex |
|
462 | 470 | * @return string the converted string |
463 | 471 | */ |
464 | 472 | protected function hash2string($hex,$alphabet='') |
@@ -61,17 +61,17 @@ discard block |
||
61 | 61 | */ |
62 | 62 | class TCaptcha extends TImage |
63 | 63 | { |
64 | - const MIN_TOKEN_LENGTH=2; |
|
65 | - const MAX_TOKEN_LENGTH=40; |
|
64 | + const MIN_TOKEN_LENGTH = 2; |
|
65 | + const MAX_TOKEN_LENGTH = 40; |
|
66 | 66 | private $_privateKey; |
67 | - private $_validated=false; |
|
67 | + private $_validated = false; |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * @return integer the theme of the token image. Defaults to 0. |
71 | 71 | */ |
72 | 72 | public function getTokenImageTheme() |
73 | 73 | { |
74 | - return $this->getViewState('TokenImageTheme',0); |
|
74 | + return $this->getViewState('TokenImageTheme', 0); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function setTokenImageTheme($value) |
91 | 91 | { |
92 | - $value=TPropertyValue::ensureInteger($value); |
|
93 | - if($value>=0 && $value<=63) |
|
94 | - $this->setViewState('TokenImageTheme',$value,0); |
|
92 | + $value = TPropertyValue::ensureInteger($value); |
|
93 | + if ($value >= 0 && $value <= 63) |
|
94 | + $this->setViewState('TokenImageTheme', $value, 0); |
|
95 | 95 | else |
96 | - throw new TConfigurationException('captcha_tokenimagetheme_invalid',0,63); |
|
96 | + throw new TConfigurationException('captcha_tokenimagetheme_invalid', 0, 63); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function getTokenFontSize() |
103 | 103 | { |
104 | - return $this->getViewState('TokenFontSize',30); |
|
104 | + return $this->getViewState('TokenFontSize', 30); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -112,11 +112,11 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function setTokenFontSize($value) |
114 | 114 | { |
115 | - $value=TPropertyValue::ensureInteger($value); |
|
116 | - if($value>=20 && $value<=100) |
|
117 | - $this->setViewState('TokenFontSize',$value,30); |
|
115 | + $value = TPropertyValue::ensureInteger($value); |
|
116 | + if ($value >= 20 && $value <= 100) |
|
117 | + $this->setViewState('TokenFontSize', $value, 30); |
|
118 | 118 | else |
119 | - throw new TConfigurationException('captcha_tokenfontsize_invalid',20,100); |
|
119 | + throw new TConfigurationException('captcha_tokenfontsize_invalid', 20, 100); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function getMinTokenLength() |
126 | 126 | { |
127 | - return $this->getViewState('MinTokenLength',4); |
|
127 | + return $this->getViewState('MinTokenLength', 4); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function setMinTokenLength($value) |
134 | 134 | { |
135 | - $length=TPropertyValue::ensureInteger($value); |
|
136 | - if($length>=self::MIN_TOKEN_LENGTH && $length<=self::MAX_TOKEN_LENGTH) |
|
137 | - $this->setViewState('MinTokenLength',$length,4); |
|
135 | + $length = TPropertyValue::ensureInteger($value); |
|
136 | + if ($length >= self::MIN_TOKEN_LENGTH && $length <= self::MAX_TOKEN_LENGTH) |
|
137 | + $this->setViewState('MinTokenLength', $length, 4); |
|
138 | 138 | else |
139 | - throw new TConfigurationException('captcha_mintokenlength_invalid',self::MIN_TOKEN_LENGTH,self::MAX_TOKEN_LENGTH); |
|
139 | + throw new TConfigurationException('captcha_mintokenlength_invalid', self::MIN_TOKEN_LENGTH, self::MAX_TOKEN_LENGTH); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function getMaxTokenLength() |
146 | 146 | { |
147 | - return $this->getViewState('MaxTokenLength',6); |
|
147 | + return $this->getViewState('MaxTokenLength', 6); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function setMaxTokenLength($value) |
154 | 154 | { |
155 | - $length=TPropertyValue::ensureInteger($value); |
|
156 | - if($length>=self::MIN_TOKEN_LENGTH && $length<=self::MAX_TOKEN_LENGTH) |
|
157 | - $this->setViewState('MaxTokenLength',$length,6); |
|
155 | + $length = TPropertyValue::ensureInteger($value); |
|
156 | + if ($length >= self::MIN_TOKEN_LENGTH && $length <= self::MAX_TOKEN_LENGTH) |
|
157 | + $this->setViewState('MaxTokenLength', $length, 6); |
|
158 | 158 | else |
159 | - throw new TConfigurationException('captcha_maxtokenlength_invalid',self::MIN_TOKEN_LENGTH,self::MAX_TOKEN_LENGTH); |
|
159 | + throw new TConfigurationException('captcha_maxtokenlength_invalid', self::MIN_TOKEN_LENGTH, self::MAX_TOKEN_LENGTH); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function getCaseSensitive() |
166 | 166 | { |
167 | - return $this->getViewState('CaseSensitive',true); |
|
167 | + return $this->getViewState('CaseSensitive', true); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | */ |
173 | 173 | public function setCaseSensitive($value) |
174 | 174 | { |
175 | - $this->setViewState('CaseSensitive',TPropertyValue::ensureBoolean($value),true); |
|
175 | + $this->setViewState('CaseSensitive', TPropertyValue::ensureBoolean($value), true); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | public function getTokenAlphabet() |
182 | 182 | { |
183 | - return $this->getViewState('TokenAlphabet','234578adefhijmnrtABDEFGHJLMNRT'); |
|
183 | + return $this->getViewState('TokenAlphabet', '234578adefhijmnrtABDEFGHJLMNRT'); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function setTokenAlphabet($value) |
190 | 190 | { |
191 | - if(strlen($value)<2) |
|
191 | + if (strlen($value) < 2) |
|
192 | 192 | throw new TConfigurationException('captcha_tokenalphabet_invalid'); |
193 | - $this->setViewState('TokenAlphabet',$value,'234578adefhijmnrtABDEFGHJLMNRT'); |
|
193 | + $this->setViewState('TokenAlphabet', $value, '234578adefhijmnrtABDEFGHJLMNRT'); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function getTokenExpiry() |
200 | 200 | { |
201 | - return $this->getViewState('TokenExpiry',600); |
|
201 | + return $this->getViewState('TokenExpiry', 600); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function setTokenExpiry($value) |
208 | 208 | { |
209 | - $this->setViewState('TokenExpiry',TPropertyValue::ensureInteger($value),600); |
|
209 | + $this->setViewState('TokenExpiry', TPropertyValue::ensureInteger($value), 600); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function getChangingTokenBackground() |
216 | 216 | { |
217 | - return $this->getViewState('ChangingTokenBackground',false); |
|
217 | + return $this->getViewState('ChangingTokenBackground', false); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function setChangingTokenBackground($value) |
224 | 224 | { |
225 | - $this->setViewState('ChangingTokenBackground',TPropertyValue::ensureBoolean($value),false); |
|
225 | + $this->setViewState('ChangingTokenBackground', TPropertyValue::ensureBoolean($value), false); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public function getTestLimit() |
232 | 232 | { |
233 | - return $this->getViewState('TestLimit',5); |
|
233 | + return $this->getViewState('TestLimit', 5); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public function setTestLimit($value) |
240 | 240 | { |
241 | - $this->setViewState('TestLimit',TPropertyValue::ensureInteger($value),5); |
|
241 | + $this->setViewState('TestLimit', TPropertyValue::ensureInteger($value), 5); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function getIsTokenExpired() |
248 | 248 | { |
249 | - if(($expiry=$this->getTokenExpiry())>0 && ($start=$this->getViewState('TokenGenerated',0))>0) |
|
250 | - return $expiry+$start<time(); |
|
249 | + if (($expiry = $this->getTokenExpiry()) > 0 && ($start = $this->getViewState('TokenGenerated', 0)) > 0) |
|
250 | + return $expiry + $start < time(); |
|
251 | 251 | else |
252 | 252 | return false; |
253 | 253 | } |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function getPublicKey() |
259 | 259 | { |
260 | - if(($publicKey=$this->getViewState('PublicKey',''))==='') |
|
260 | + if (($publicKey = $this->getViewState('PublicKey', '')) === '') |
|
261 | 261 | { |
262 | - $publicKey=$this->generateRandomKey(); |
|
262 | + $publicKey = $this->generateRandomKey(); |
|
263 | 263 | $this->setPublicKey($publicKey); |
264 | 264 | } |
265 | 265 | return $publicKey; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | */ |
271 | 271 | public function setPublicKey($value) |
272 | 272 | { |
273 | - $this->setViewState('PublicKey',$value,''); |
|
273 | + $this->setViewState('PublicKey', $value, ''); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | public function getToken() |
280 | 280 | { |
281 | - return $this->generateToken($this->getPublicKey(),$this->getPrivateKey(),$this->getTokenAlphabet(),$this->getTokenLength(),$this->getCaseSensitive()); |
|
281 | + return $this->generateToken($this->getPublicKey(), $this->getPrivateKey(), $this->getTokenAlphabet(), $this->getTokenLength(), $this->getCaseSensitive()); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -286,17 +286,17 @@ discard block |
||
286 | 286 | */ |
287 | 287 | protected function getTokenLength() |
288 | 288 | { |
289 | - if(($tokenLength=$this->getViewState('TokenLength'))===null) |
|
289 | + if (($tokenLength = $this->getViewState('TokenLength')) === null) |
|
290 | 290 | { |
291 | - $minLength=$this->getMinTokenLength(); |
|
292 | - $maxLength=$this->getMaxTokenLength(); |
|
293 | - if($minLength>$maxLength) |
|
294 | - $tokenLength=rand($maxLength,$minLength); |
|
295 | - else if($minLength<$maxLength) |
|
296 | - $tokenLength=rand($minLength,$maxLength); |
|
291 | + $minLength = $this->getMinTokenLength(); |
|
292 | + $maxLength = $this->getMaxTokenLength(); |
|
293 | + if ($minLength > $maxLength) |
|
294 | + $tokenLength = rand($maxLength, $minLength); |
|
295 | + else if ($minLength < $maxLength) |
|
296 | + $tokenLength = rand($minLength, $maxLength); |
|
297 | 297 | else |
298 | - $tokenLength=$minLength; |
|
299 | - $this->setViewState('TokenLength',$tokenLength); |
|
298 | + $tokenLength = $minLength; |
|
299 | + $this->setViewState('TokenLength', $tokenLength); |
|
300 | 300 | } |
301 | 301 | return $tokenLength; |
302 | 302 | } |
@@ -306,13 +306,13 @@ discard block |
||
306 | 306 | */ |
307 | 307 | public function getPrivateKey() |
308 | 308 | { |
309 | - if($this->_privateKey===null) |
|
309 | + if ($this->_privateKey === null) |
|
310 | 310 | { |
311 | - $fileName=$this->generatePrivateKeyFile(); |
|
312 | - $content=file_get_contents($fileName); |
|
313 | - $matches=array(); |
|
314 | - if(preg_match("/privateKey='(.*?)'/ms",$content,$matches)>0) |
|
315 | - $this->_privateKey=$matches[1]; |
|
311 | + $fileName = $this->generatePrivateKeyFile(); |
|
312 | + $content = file_get_contents($fileName); |
|
313 | + $matches = array(); |
|
314 | + if (preg_match("/privateKey='(.*?)'/ms", $content, $matches) > 0) |
|
315 | + $this->_privateKey = $matches[1]; |
|
316 | 316 | else |
317 | 317 | throw new TConfigurationException('captcha_privatekey_unknown'); |
318 | 318 | } |
@@ -326,18 +326,18 @@ discard block |
||
326 | 326 | */ |
327 | 327 | public function validate($input) |
328 | 328 | { |
329 | - $number=$this->getViewState('TestNumber',0); |
|
330 | - if(!$this->_validated) |
|
329 | + $number = $this->getViewState('TestNumber', 0); |
|
330 | + if (!$this->_validated) |
|
331 | 331 | { |
332 | - $this->setViewState('TestNumber',++$number); |
|
333 | - $this->_validated=true; |
|
332 | + $this->setViewState('TestNumber', ++$number); |
|
333 | + $this->_validated = true; |
|
334 | 334 | } |
335 | - if($this->getIsTokenExpired() || (($limit=$this->getTestLimit())>0 && $number>$limit)) |
|
335 | + if ($this->getIsTokenExpired() || (($limit = $this->getTestLimit()) > 0 && $number > $limit)) |
|
336 | 336 | { |
337 | 337 | $this->regenerateToken(); |
338 | 338 | return false; |
339 | 339 | } |
340 | - return ($this->getToken()===($this->getCaseSensitive()?$input:strtoupper($input))); |
|
340 | + return ($this->getToken() === ($this->getCaseSensitive() ? $input : strtoupper($input))); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | $this->setPublicKey(''); |
352 | 352 | $this->clearViewState('TokenGenerated'); |
353 | 353 | $this->clearViewState('RandomSeed'); |
354 | - $this->clearViewState('TestNumber',0); |
|
354 | + $this->clearViewState('TestNumber', 0); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -361,17 +361,17 @@ discard block |
||
361 | 361 | public function onPreRender($param) |
362 | 362 | { |
363 | 363 | parent::onPreRender($param); |
364 | - if(!self::checkRequirements()) |
|
364 | + if (!self::checkRequirements()) |
|
365 | 365 | throw new TConfigurationException('captcha_imagettftext_required'); |
366 | - if(!$this->getViewState('TokenGenerated',0)) |
|
366 | + if (!$this->getViewState('TokenGenerated', 0)) |
|
367 | 367 | { |
368 | - $manager=$this->getApplication()->getAssetManager(); |
|
368 | + $manager = $this->getApplication()->getAssetManager(); |
|
369 | 369 | $manager->publishFilePath($this->getFontFile()); |
370 | - $url=$manager->publishFilePath($this->getCaptchaScriptFile()); |
|
371 | - $url.='?options='.urlencode($this->getTokenImageOptions()); |
|
370 | + $url = $manager->publishFilePath($this->getCaptchaScriptFile()); |
|
371 | + $url .= '?options=' . urlencode($this->getTokenImageOptions()); |
|
372 | 372 | $this->setImageUrl($url); |
373 | 373 | |
374 | - $this->setViewState('TokenGenerated',time()); |
|
374 | + $this->setViewState('TokenGenerated', time()); |
|
375 | 375 | } |
376 | 376 | } |
377 | 377 | |
@@ -380,23 +380,23 @@ discard block |
||
380 | 380 | */ |
381 | 381 | protected function getTokenImageOptions() |
382 | 382 | { |
383 | - $privateKey=$this->getPrivateKey(); // call this method to ensure private key is generated |
|
384 | - $token=$this->getToken(); |
|
385 | - $options=array(); |
|
386 | - $options['publicKey']=$this->getPublicKey(); |
|
387 | - $options['tokenLength']=strlen($token); |
|
388 | - $options['caseSensitive']=$this->getCaseSensitive(); |
|
389 | - $options['alphabet']=$this->getTokenAlphabet(); |
|
390 | - $options['fontSize']=$this->getTokenFontSize(); |
|
391 | - $options['theme']=$this->getTokenImageTheme(); |
|
392 | - if(($randomSeed=$this->getViewState('RandomSeed',0))===0) |
|
383 | + $privateKey = $this->getPrivateKey(); // call this method to ensure private key is generated |
|
384 | + $token = $this->getToken(); |
|
385 | + $options = array(); |
|
386 | + $options['publicKey'] = $this->getPublicKey(); |
|
387 | + $options['tokenLength'] = strlen($token); |
|
388 | + $options['caseSensitive'] = $this->getCaseSensitive(); |
|
389 | + $options['alphabet'] = $this->getTokenAlphabet(); |
|
390 | + $options['fontSize'] = $this->getTokenFontSize(); |
|
391 | + $options['theme'] = $this->getTokenImageTheme(); |
|
392 | + if (($randomSeed = $this->getViewState('RandomSeed', 0)) === 0) |
|
393 | 393 | { |
394 | - $randomSeed=(int)(microtime()*1000000); |
|
395 | - $this->setViewState('RandomSeed',$randomSeed); |
|
394 | + $randomSeed = (int) (microtime() * 1000000); |
|
395 | + $this->setViewState('RandomSeed', $randomSeed); |
|
396 | 396 | } |
397 | - $options['randomSeed']=$this->getChangingTokenBackground()?0:$randomSeed; |
|
398 | - $str=serialize($options); |
|
399 | - return base64_encode(md5($privateKey.$str).$str); |
|
397 | + $options['randomSeed'] = $this->getChangingTokenBackground() ? 0 : $randomSeed; |
|
398 | + $str = serialize($options); |
|
399 | + return base64_encode(md5($privateKey . $str) . $str); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -404,12 +404,12 @@ discard block |
||
404 | 404 | */ |
405 | 405 | protected function getCaptchaScriptFile() |
406 | 406 | { |
407 | - return dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'captcha.php'; |
|
407 | + return dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'captcha.php'; |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | protected function getFontFile() |
411 | 411 | { |
412 | - return dirname(__FILE__).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'verase.ttf'; |
|
412 | + return dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'verase.ttf'; |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
@@ -418,17 +418,17 @@ discard block |
||
418 | 418 | */ |
419 | 419 | protected function generatePrivateKeyFile() |
420 | 420 | { |
421 | - $captchaScript=$this->getCaptchaScriptFile(); |
|
422 | - $path=dirname($this->getApplication()->getAssetManager()->getPublishedPath($captchaScript)); |
|
423 | - $fileName=$path.DIRECTORY_SEPARATOR.'captcha_key.php'; |
|
424 | - if(!is_file($fileName)) |
|
421 | + $captchaScript = $this->getCaptchaScriptFile(); |
|
422 | + $path = dirname($this->getApplication()->getAssetManager()->getPublishedPath($captchaScript)); |
|
423 | + $fileName = $path . DIRECTORY_SEPARATOR . 'captcha_key.php'; |
|
424 | + if (!is_file($fileName)) |
|
425 | 425 | { |
426 | 426 | @mkdir($path); |
427 | - $key=$this->generateRandomKey(); |
|
428 | - $content="<?php |
|
427 | + $key = $this->generateRandomKey(); |
|
428 | + $content = "<?php |
|
429 | 429 | \$privateKey='$key'; |
430 | 430 | ?>"; |
431 | - file_put_contents($fileName,$content); |
|
431 | + file_put_contents($fileName, $content); |
|
432 | 432 | } |
433 | 433 | return $fileName; |
434 | 434 | } |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | */ |
439 | 439 | protected function generateRandomKey() |
440 | 440 | { |
441 | - return md5(rand().rand().rand().rand()); |
|
441 | + return md5(rand() . rand() . rand() . rand()); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | /** |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | * @param boolean whether the token is case sensitive |
450 | 450 | * @return string the token generated. |
451 | 451 | */ |
452 | - protected function generateToken($publicKey,$privateKey,$alphabet,$tokenLength,$caseSensitive) |
|
452 | + protected function generateToken($publicKey, $privateKey, $alphabet, $tokenLength, $caseSensitive) |
|
453 | 453 | { |
454 | - $token=substr($this->hash2string(md5($publicKey.$privateKey),$alphabet).$this->hash2string(md5($privateKey.$publicKey),$alphabet),0,$tokenLength); |
|
455 | - return $caseSensitive?$token:strtoupper($token); |
|
454 | + $token = substr($this->hash2string(md5($publicKey . $privateKey), $alphabet) . $this->hash2string(md5($privateKey . $publicKey), $alphabet), 0, $tokenLength); |
|
455 | + return $caseSensitive ? $token : strtoupper($token); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | /** |
@@ -461,20 +461,20 @@ discard block |
||
461 | 461 | * @param string the alphabet used to represent the converted string. If empty, it means '234578adefhijmnrtwyABDEFGHIJLMNQRTWY', which excludes those confusing characters. |
462 | 462 | * @return string the converted string |
463 | 463 | */ |
464 | - protected function hash2string($hex,$alphabet='') |
|
464 | + protected function hash2string($hex, $alphabet = '') |
|
465 | 465 | { |
466 | - if(strlen($alphabet)<2) |
|
467 | - $alphabet='234578adefhijmnrtABDEFGHJLMNQRT'; |
|
468 | - $hexLength=strlen($hex); |
|
469 | - $base=strlen($alphabet); |
|
470 | - $result=''; |
|
471 | - for($i=0;$i<$hexLength;$i+=6) |
|
466 | + if (strlen($alphabet) < 2) |
|
467 | + $alphabet = '234578adefhijmnrtABDEFGHJLMNQRT'; |
|
468 | + $hexLength = strlen($hex); |
|
469 | + $base = strlen($alphabet); |
|
470 | + $result = ''; |
|
471 | + for ($i = 0; $i < $hexLength; $i += 6) |
|
472 | 472 | { |
473 | - $number=hexdec(substr($hex,$i,6)); |
|
474 | - while($number) |
|
473 | + $number = hexdec(substr($hex, $i, 6)); |
|
474 | + while ($number) |
|
475 | 475 | { |
476 | - $result.=$alphabet[$number%$base]; |
|
477 | - $number=floor($number/$base); |
|
476 | + $result .= $alphabet[$number % $base]; |
|
477 | + $number = floor($number / $base); |
|
478 | 478 | } |
479 | 479 | } |
480 | 480 | return $result; |
@@ -90,10 +90,11 @@ discard block |
||
90 | 90 | public function setTokenImageTheme($value) |
91 | 91 | { |
92 | 92 | $value=TPropertyValue::ensureInteger($value); |
93 | - if($value>=0 && $value<=63) |
|
94 | - $this->setViewState('TokenImageTheme',$value,0); |
|
95 | - else |
|
96 | - throw new TConfigurationException('captcha_tokenimagetheme_invalid',0,63); |
|
93 | + if($value>=0 && $value<=63) { |
|
94 | + $this->setViewState('TokenImageTheme',$value,0); |
|
95 | + } else { |
|
96 | + throw new TConfigurationException('captcha_tokenimagetheme_invalid',0,63); |
|
97 | + } |
|
97 | 98 | } |
98 | 99 | |
99 | 100 | /** |
@@ -113,10 +114,11 @@ discard block |
||
113 | 114 | public function setTokenFontSize($value) |
114 | 115 | { |
115 | 116 | $value=TPropertyValue::ensureInteger($value); |
116 | - if($value>=20 && $value<=100) |
|
117 | - $this->setViewState('TokenFontSize',$value,30); |
|
118 | - else |
|
119 | - throw new TConfigurationException('captcha_tokenfontsize_invalid',20,100); |
|
117 | + if($value>=20 && $value<=100) { |
|
118 | + $this->setViewState('TokenFontSize',$value,30); |
|
119 | + } else { |
|
120 | + throw new TConfigurationException('captcha_tokenfontsize_invalid',20,100); |
|
121 | + } |
|
120 | 122 | } |
121 | 123 | |
122 | 124 | /** |
@@ -133,10 +135,11 @@ discard block |
||
133 | 135 | public function setMinTokenLength($value) |
134 | 136 | { |
135 | 137 | $length=TPropertyValue::ensureInteger($value); |
136 | - if($length>=self::MIN_TOKEN_LENGTH && $length<=self::MAX_TOKEN_LENGTH) |
|
137 | - $this->setViewState('MinTokenLength',$length,4); |
|
138 | - else |
|
139 | - throw new TConfigurationException('captcha_mintokenlength_invalid',self::MIN_TOKEN_LENGTH,self::MAX_TOKEN_LENGTH); |
|
138 | + if($length>=self::MIN_TOKEN_LENGTH && $length<=self::MAX_TOKEN_LENGTH) { |
|
139 | + $this->setViewState('MinTokenLength',$length,4); |
|
140 | + } else { |
|
141 | + throw new TConfigurationException('captcha_mintokenlength_invalid',self::MIN_TOKEN_LENGTH,self::MAX_TOKEN_LENGTH); |
|
142 | + } |
|
140 | 143 | } |
141 | 144 | |
142 | 145 | /** |
@@ -153,10 +156,11 @@ discard block |
||
153 | 156 | public function setMaxTokenLength($value) |
154 | 157 | { |
155 | 158 | $length=TPropertyValue::ensureInteger($value); |
156 | - if($length>=self::MIN_TOKEN_LENGTH && $length<=self::MAX_TOKEN_LENGTH) |
|
157 | - $this->setViewState('MaxTokenLength',$length,6); |
|
158 | - else |
|
159 | - throw new TConfigurationException('captcha_maxtokenlength_invalid',self::MIN_TOKEN_LENGTH,self::MAX_TOKEN_LENGTH); |
|
159 | + if($length>=self::MIN_TOKEN_LENGTH && $length<=self::MAX_TOKEN_LENGTH) { |
|
160 | + $this->setViewState('MaxTokenLength',$length,6); |
|
161 | + } else { |
|
162 | + throw new TConfigurationException('captcha_maxtokenlength_invalid',self::MIN_TOKEN_LENGTH,self::MAX_TOKEN_LENGTH); |
|
163 | + } |
|
160 | 164 | } |
161 | 165 | |
162 | 166 | /** |
@@ -188,8 +192,9 @@ discard block |
||
188 | 192 | */ |
189 | 193 | public function setTokenAlphabet($value) |
190 | 194 | { |
191 | - if(strlen($value)<2) |
|
192 | - throw new TConfigurationException('captcha_tokenalphabet_invalid'); |
|
195 | + if(strlen($value)<2) { |
|
196 | + throw new TConfigurationException('captcha_tokenalphabet_invalid'); |
|
197 | + } |
|
193 | 198 | $this->setViewState('TokenAlphabet',$value,'234578adefhijmnrtABDEFGHJLMNRT'); |
194 | 199 | } |
195 | 200 | |
@@ -246,10 +251,11 @@ discard block |
||
246 | 251 | */ |
247 | 252 | public function getIsTokenExpired() |
248 | 253 | { |
249 | - if(($expiry=$this->getTokenExpiry())>0 && ($start=$this->getViewState('TokenGenerated',0))>0) |
|
250 | - return $expiry+$start<time(); |
|
251 | - else |
|
252 | - return false; |
|
254 | + if(($expiry=$this->getTokenExpiry())>0 && ($start=$this->getViewState('TokenGenerated',0))>0) { |
|
255 | + return $expiry+$start<time(); |
|
256 | + } else { |
|
257 | + return false; |
|
258 | + } |
|
253 | 259 | } |
254 | 260 | |
255 | 261 | /** |
@@ -290,12 +296,13 @@ discard block |
||
290 | 296 | { |
291 | 297 | $minLength=$this->getMinTokenLength(); |
292 | 298 | $maxLength=$this->getMaxTokenLength(); |
293 | - if($minLength>$maxLength) |
|
294 | - $tokenLength=rand($maxLength,$minLength); |
|
295 | - else if($minLength<$maxLength) |
|
296 | - $tokenLength=rand($minLength,$maxLength); |
|
297 | - else |
|
298 | - $tokenLength=$minLength; |
|
299 | + if($minLength>$maxLength) { |
|
300 | + $tokenLength=rand($maxLength,$minLength); |
|
301 | + } else if($minLength<$maxLength) { |
|
302 | + $tokenLength=rand($minLength,$maxLength); |
|
303 | + } else { |
|
304 | + $tokenLength=$minLength; |
|
305 | + } |
|
299 | 306 | $this->setViewState('TokenLength',$tokenLength); |
300 | 307 | } |
301 | 308 | return $tokenLength; |
@@ -311,10 +318,11 @@ discard block |
||
311 | 318 | $fileName=$this->generatePrivateKeyFile(); |
312 | 319 | $content=file_get_contents($fileName); |
313 | 320 | $matches=array(); |
314 | - if(preg_match("/privateKey='(.*?)'/ms",$content,$matches)>0) |
|
315 | - $this->_privateKey=$matches[1]; |
|
316 | - else |
|
317 | - throw new TConfigurationException('captcha_privatekey_unknown'); |
|
321 | + if(preg_match("/privateKey='(.*?)'/ms",$content,$matches)>0) { |
|
322 | + $this->_privateKey=$matches[1]; |
|
323 | + } else { |
|
324 | + throw new TConfigurationException('captcha_privatekey_unknown'); |
|
325 | + } |
|
318 | 326 | } |
319 | 327 | return $this->_privateKey; |
320 | 328 | } |
@@ -361,8 +369,9 @@ discard block |
||
361 | 369 | public function onPreRender($param) |
362 | 370 | { |
363 | 371 | parent::onPreRender($param); |
364 | - if(!self::checkRequirements()) |
|
365 | - throw new TConfigurationException('captcha_imagettftext_required'); |
|
372 | + if(!self::checkRequirements()) { |
|
373 | + throw new TConfigurationException('captcha_imagettftext_required'); |
|
374 | + } |
|
366 | 375 | if(!$this->getViewState('TokenGenerated',0)) |
367 | 376 | { |
368 | 377 | $manager=$this->getApplication()->getAssetManager(); |
@@ -463,8 +472,9 @@ discard block |
||
463 | 472 | */ |
464 | 473 | protected function hash2string($hex,$alphabet='') |
465 | 474 | { |
466 | - if(strlen($alphabet)<2) |
|
467 | - $alphabet='234578adefhijmnrtABDEFGHJLMNQRT'; |
|
475 | + if(strlen($alphabet)<2) { |
|
476 | + $alphabet='234578adefhijmnrtABDEFGHJLMNQRT'; |
|
477 | + } |
|
468 | 478 | $hexLength=strlen($hex); |
469 | 479 | $base=strlen($alphabet); |
470 | 480 | $result=''; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | - * @return TCaptchaControl the CAPTCHA control to be validated against |
|
82 | + * @return TCaptcha the CAPTCHA control to be validated against |
|
83 | 83 | * @throws TConfigurationException if the CAPTCHA cannot be found according to {@link setCaptchaControl CaptchaControl} |
84 | 84 | */ |
85 | 85 | protected function findCaptchaControl() |
@@ -115,6 +115,9 @@ discard block |
||
115 | 115 | return $options; |
116 | 116 | } |
117 | 117 | |
118 | + /** |
|
119 | + * @param string $token |
|
120 | + */ |
|
118 | 121 | private function generateTokenHash($token) |
119 | 122 | { |
120 | 123 | for($h=0,$i=strlen($token)-1;$i>=0;--$i) |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getCaptchaControl() |
52 | 52 | { |
53 | - return $this->getViewState('CaptchaControl',''); |
|
53 | + return $this->getViewState('CaptchaControl', ''); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function setCaptchaControl($value) |
63 | 63 | { |
64 | - $this->setViewState('CaptchaControl',TPropertyValue::ensureString($value),''); |
|
64 | + $this->setViewState('CaptchaControl', TPropertyValue::ensureString($value), ''); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | */ |
74 | 74 | protected function evaluateIsValid() |
75 | 75 | { |
76 | - $value=$this->getValidationValue($this->getValidationTarget()); |
|
77 | - $control=$this->findCaptchaControl(); |
|
76 | + $value = $this->getValidationValue($this->getValidationTarget()); |
|
77 | + $control = $this->findCaptchaControl(); |
|
78 | 78 | return $control->validate(trim($value)); |
79 | 79 | } |
80 | 80 | |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function findCaptchaControl() |
86 | 86 | { |
87 | - if(($id=$this->getCaptchaControl())==='') |
|
87 | + if (($id = $this->getCaptchaControl()) === '') |
|
88 | 88 | throw new TConfigurationException('captchavalidator_captchacontrol_required'); |
89 | - else if(($control=$this->findControl($id))===null) |
|
90 | - throw new TConfigurationException('captchavalidator_captchacontrol_inexistent',$id); |
|
91 | - else if(!($control instanceof TCaptcha)) |
|
92 | - throw new TConfigurationException('captchavalidator_captchacontrol_invalid',$id); |
|
89 | + else if (($control = $this->findControl($id)) === null) |
|
90 | + throw new TConfigurationException('captchavalidator_captchacontrol_inexistent', $id); |
|
91 | + else if (!($control instanceof TCaptcha)) |
|
92 | + throw new TConfigurationException('captchavalidator_captchacontrol_invalid', $id); |
|
93 | 93 | else |
94 | 94 | return $control; |
95 | 95 | } |
@@ -100,25 +100,25 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function getClientScriptOptions() |
102 | 102 | { |
103 | - $options=parent::getClientScriptOptions(); |
|
104 | - $control=$this->findCaptchaControl(); |
|
105 | - if($control->getCaseSensitive()) |
|
103 | + $options = parent::getClientScriptOptions(); |
|
104 | + $control = $this->findCaptchaControl(); |
|
105 | + if ($control->getCaseSensitive()) |
|
106 | 106 | { |
107 | - $options['TokenHash']=$this->generateTokenHash($control->getToken()); |
|
108 | - $options['CaseSensitive']=true; |
|
107 | + $options['TokenHash'] = $this->generateTokenHash($control->getToken()); |
|
108 | + $options['CaseSensitive'] = true; |
|
109 | 109 | } |
110 | 110 | else |
111 | 111 | { |
112 | - $options['TokenHash']=$this->generateTokenHash(strtoupper($control->getToken())); |
|
113 | - $options['CaseSensitive']=false; |
|
112 | + $options['TokenHash'] = $this->generateTokenHash(strtoupper($control->getToken())); |
|
113 | + $options['CaseSensitive'] = false; |
|
114 | 114 | } |
115 | 115 | return $options; |
116 | 116 | } |
117 | 117 | |
118 | 118 | private function generateTokenHash($token) |
119 | 119 | { |
120 | - for($h=0,$i=strlen($token)-1;$i>=0;--$i) |
|
121 | - $h+=ord($token[$i]); |
|
120 | + for ($h = 0, $i = strlen($token) - 1; $i >= 0; --$i) |
|
121 | + $h += ord($token[$i]); |
|
122 | 122 | return $h; |
123 | 123 | } |
124 | 124 | } |
@@ -84,14 +84,15 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function findCaptchaControl() |
86 | 86 | { |
87 | - if(($id=$this->getCaptchaControl())==='') |
|
88 | - throw new TConfigurationException('captchavalidator_captchacontrol_required'); |
|
89 | - else if(($control=$this->findControl($id))===null) |
|
90 | - throw new TConfigurationException('captchavalidator_captchacontrol_inexistent',$id); |
|
91 | - else if(!($control instanceof TCaptcha)) |
|
92 | - throw new TConfigurationException('captchavalidator_captchacontrol_invalid',$id); |
|
93 | - else |
|
94 | - return $control; |
|
87 | + if(($id=$this->getCaptchaControl())==='') { |
|
88 | + throw new TConfigurationException('captchavalidator_captchacontrol_required'); |
|
89 | + } else if(($control=$this->findControl($id))===null) { |
|
90 | + throw new TConfigurationException('captchavalidator_captchacontrol_inexistent',$id); |
|
91 | + } else if(!($control instanceof TCaptcha)) { |
|
92 | + throw new TConfigurationException('captchavalidator_captchacontrol_invalid',$id); |
|
93 | + } else { |
|
94 | + return $control; |
|
95 | + } |
|
95 | 96 | } |
96 | 97 | |
97 | 98 | /** |
@@ -106,8 +107,7 @@ discard block |
||
106 | 107 | { |
107 | 108 | $options['TokenHash']=$this->generateTokenHash($control->getToken()); |
108 | 109 | $options['CaseSensitive']=true; |
109 | - } |
|
110 | - else |
|
110 | + } else |
|
111 | 111 | { |
112 | 112 | $options['TokenHash']=$this->generateTokenHash(strtoupper($control->getToken())); |
113 | 113 | $options['CaseSensitive']=false; |
@@ -117,8 +117,9 @@ discard block |
||
117 | 117 | |
118 | 118 | private function generateTokenHash($token) |
119 | 119 | { |
120 | - for($h=0,$i=strlen($token)-1;$i>=0;--$i) |
|
121 | - $h+=ord($token[$i]); |
|
120 | + for($h=0,$i=strlen($token)-1;$i>=0;--$i) { |
|
121 | + $h+=ord($token[$i]); |
|
122 | + } |
|
122 | 123 | return $h; |
123 | 124 | } |
124 | 125 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | /** |
119 | 119 | * Returns the value of the property that needs validation. |
120 | - * @return mixed the property value to be validated |
|
120 | + * @return boolean the property value to be validated |
|
121 | 121 | */ |
122 | 122 | public function getValidationPropertyValue() |
123 | 123 | { |
@@ -184,6 +184,7 @@ discard block |
||
184 | 184 | |
185 | 185 | /** |
186 | 186 | * @param TTextAlign the alignment of the text caption. Valid values include Left and Right. |
187 | + * @param TTextAlign $value |
|
187 | 188 | */ |
188 | 189 | public function setTextAlign($value) |
189 | 190 | { |
@@ -244,6 +245,7 @@ discard block |
||
244 | 245 | /** |
245 | 246 | * Sets a value indicating whether clicking on the checkbox will post the page. |
246 | 247 | * @param boolean whether clicking on the checkbox will post the page. |
248 | + * @param boolean $value |
|
247 | 249 | */ |
248 | 250 | public function setAutoPostBack($value) |
249 | 251 | { |
@@ -261,6 +263,7 @@ discard block |
||
261 | 263 | /** |
262 | 264 | * Sets the value indicating whether postback event trigger by this checkbox will cause input validation. |
263 | 265 | * @param boolean whether postback event trigger by this checkbox will cause input validation. |
266 | + * @param boolean $value |
|
264 | 267 | */ |
265 | 268 | public function setCausesValidation($value) |
266 | 269 | { |
@@ -277,6 +280,7 @@ discard block |
||
277 | 280 | |
278 | 281 | /** |
279 | 282 | * @param string the group of validators which the checkbox causes validation upon postback |
283 | + * @param string $value |
|
280 | 284 | */ |
281 | 285 | public function setValidationGroup($value) |
282 | 286 | { |
@@ -410,6 +414,7 @@ discard block |
||
410 | 414 | |
411 | 415 | /** |
412 | 416 | * @param boolean whether to render javascript. |
417 | + * @param boolean $value |
|
413 | 418 | */ |
414 | 419 | public function setEnableClientScript($value) |
415 | 420 | { |
@@ -131,14 +131,14 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function getIsValid() |
133 | 133 | { |
134 | - return $this->_isValid; |
|
134 | + return $this->_isValid; |
|
135 | 135 | } |
136 | 136 | /** |
137 | 137 | * @param bool wether this control is valid. |
138 | 138 | */ |
139 | 139 | public function setIsValid($value) |
140 | 140 | { |
141 | - $this->_isValid=TPropertyValue::ensureBoolean($value); |
|
141 | + $this->_isValid=TPropertyValue::ensureBoolean($value); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | */ |
289 | 289 | public function getSurroundingTag() |
290 | 290 | { |
291 | - return 'span'; |
|
291 | + return 'span'; |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | */ |
297 | 297 | public function getSurroundingTagID() |
298 | 298 | { |
299 | - return $this->getSpanNeeded() ? $this->getClientID().'_parent' : $this->getClientID(); |
|
299 | + return $this->getSpanNeeded() ? $this->getClientID().'_parent' : $this->getClientID(); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -326,11 +326,11 @@ discard block |
||
326 | 326 | } |
327 | 327 | else |
328 | 328 | $onclick=''; |
329 | - if($needspan=$this->getSpanNeeded()) |
|
330 | - { |
|
331 | - $writer->addAttribute('id',$this->getSurroundingTagID()); |
|
332 | - $writer->renderBeginTag($this->getSurroundingTag()); |
|
333 | - } |
|
329 | + if($needspan=$this->getSpanNeeded()) |
|
330 | + { |
|
331 | + $writer->addAttribute('id',$this->getSurroundingTagID()); |
|
332 | + $writer->renderBeginTag($this->getSurroundingTag()); |
|
333 | + } |
|
334 | 334 | $clientID=$this->getClientID(); |
335 | 335 | if(($text=$this->getText())!=='') |
336 | 336 | { |
@@ -416,15 +416,15 @@ discard block |
||
416 | 416 | $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true); |
417 | 417 | } |
418 | 418 | |
419 | - /** |
|
420 | - * Check if we need a span tag to surround this control. The span tag will be created if |
|
421 | - * the Text property is set for this control. |
|
422 | - * |
|
423 | - * @return bool wether this control needs a surrounding span tag |
|
424 | - */ |
|
425 | - protected function getSpanNeeded() { |
|
426 | - return $this->getText()!==''; |
|
427 | - } |
|
419 | + /** |
|
420 | + * Check if we need a span tag to surround this control. The span tag will be created if |
|
421 | + * the Text property is set for this control. |
|
422 | + * |
|
423 | + * @return bool wether this control needs a surrounding span tag |
|
424 | + */ |
|
425 | + protected function getSpanNeeded() { |
|
426 | + return $this->getText()!==''; |
|
427 | + } |
|
428 | 428 | |
429 | 429 | /** |
430 | 430 | * Renders a label beside the checkbox. |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | */ |
41 | 41 | class TCheckBox extends TWebControl implements IPostBackDataHandler, IValidatable, IDataRenderer, ISurroundable |
42 | 42 | { |
43 | - private $_dataChanged=false; |
|
44 | - private $_isValid=true; |
|
43 | + private $_dataChanged = false; |
|
44 | + private $_isValid = true; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @return string tag name of the button |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | * @param array the input data collection |
59 | 59 | * @return boolean whether the data of the control has been changed |
60 | 60 | */ |
61 | - public function loadPostData($key,$values) |
|
61 | + public function loadPostData($key, $values) |
|
62 | 62 | { |
63 | - $checked=$this->getChecked(); |
|
64 | - if($newChecked=isset($values[$key])) |
|
63 | + $checked = $this->getChecked(); |
|
64 | + if ($newChecked = isset($values[$key])) |
|
65 | 65 | $this->setValue($values[$key]); |
66 | 66 | $this->setChecked($newChecked); |
67 | - return $this->_dataChanged=($newChecked!==$checked); |
|
67 | + return $this->_dataChanged = ($newChecked !== $checked); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function raisePostDataChangedEvent() |
76 | 76 | { |
77 | - if($this->getAutoPostBack() && $this->getCausesValidation()) |
|
77 | + if ($this->getAutoPostBack() && $this->getCausesValidation()) |
|
78 | 78 | $this->getPage()->validate($this->getValidationGroup()); |
79 | 79 | $this->onCheckedChanged(null); |
80 | 80 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function onCheckedChanged($param) |
89 | 89 | { |
90 | - $this->raiseEvent('OnCheckedChanged',$this,$param); |
|
90 | + $this->raiseEvent('OnCheckedChanged', $this, $param); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | public function onPreRender($param) |
102 | 102 | { |
103 | 103 | parent::onPreRender($param); |
104 | - if($this->getEnabled(true)) |
|
104 | + if ($this->getEnabled(true)) |
|
105 | 105 | $this->getPage()->registerRequiresPostData($this); |
106 | 106 | } |
107 | 107 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function setIsValid($value) |
140 | 140 | { |
141 | - $this->_isValid=TPropertyValue::ensureBoolean($value); |
|
141 | + $this->_isValid = TPropertyValue::ensureBoolean($value); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function getText() |
148 | 148 | { |
149 | - return $this->getViewState('Text',''); |
|
149 | + return $this->getViewState('Text', ''); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function setText($value) |
157 | 157 | { |
158 | - $this->setViewState('Text',$value,''); |
|
158 | + $this->setViewState('Text', $value, ''); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function getValue() |
165 | 165 | { |
166 | - return $this->getViewState('Value',''); |
|
166 | + return $this->getViewState('Value', ''); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function setValue($value) |
173 | 173 | { |
174 | - $this->setViewState('Value',TPropertyValue::ensureString($value),''); |
|
174 | + $this->setViewState('Value', TPropertyValue::ensureString($value), ''); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function getTextAlign() |
181 | 181 | { |
182 | - return $this->getViewState('TextAlign',TTextAlign::Right); |
|
182 | + return $this->getViewState('TextAlign', TTextAlign::Right); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function setTextAlign($value) |
189 | 189 | { |
190 | - $this->setViewState('TextAlign',TPropertyValue::ensureEnum($value,'TTextAlign'),TTextAlign::Right); |
|
190 | + $this->setViewState('TextAlign', TPropertyValue::ensureEnum($value, 'TTextAlign'), TTextAlign::Right); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function getChecked() |
197 | 197 | { |
198 | - return $this->getViewState('Checked',false); |
|
198 | + return $this->getViewState('Checked', false); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public function setChecked($value) |
206 | 206 | { |
207 | - $this->setViewState('Checked',TPropertyValue::ensureBoolean($value),false); |
|
207 | + $this->setViewState('Checked', TPropertyValue::ensureBoolean($value), false); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public function getAutoPostBack() |
240 | 240 | { |
241 | - return $this->getViewState('AutoPostBack',false); |
|
241 | + return $this->getViewState('AutoPostBack', false); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function setAutoPostBack($value) |
249 | 249 | { |
250 | - $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false); |
|
250 | + $this->setViewState('AutoPostBack', TPropertyValue::ensureBoolean($value), false); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | */ |
256 | 256 | public function getCausesValidation() |
257 | 257 | { |
258 | - return $this->getViewState('CausesValidation',true); |
|
258 | + return $this->getViewState('CausesValidation', true); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public function setCausesValidation($value) |
266 | 266 | { |
267 | - $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true); |
|
267 | + $this->setViewState('CausesValidation', TPropertyValue::ensureBoolean($value), true); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | */ |
273 | 273 | public function getValidationGroup() |
274 | 274 | { |
275 | - return $this->getViewState('ValidationGroup',''); |
|
275 | + return $this->getViewState('ValidationGroup', ''); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | */ |
281 | 281 | public function setValidationGroup($value) |
282 | 282 | { |
283 | - $this->setViewState('ValidationGroup',$value,''); |
|
283 | + $this->setViewState('ValidationGroup', $value, ''); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | */ |
297 | 297 | public function getSurroundingTagID() |
298 | 298 | { |
299 | - return $this->getSpanNeeded() ? $this->getClientID().'_parent' : $this->getClientID(); |
|
299 | + return $this->getSpanNeeded() ? $this->getClientID() . '_parent' : $this->getClientID(); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -308,46 +308,46 @@ discard block |
||
308 | 308 | public function render($writer) |
309 | 309 | { |
310 | 310 | $this->getPage()->ensureRenderInForm($this); |
311 | - if($this->getHasStyle()) |
|
311 | + if ($this->getHasStyle()) |
|
312 | 312 | $this->getStyle()->addAttributesToRender($writer); |
313 | - if(($tooltip=$this->getToolTip())!=='') |
|
314 | - $writer->addAttribute('title',$tooltip); |
|
315 | - if($this->getHasAttributes()) |
|
313 | + if (($tooltip = $this->getToolTip()) !== '') |
|
314 | + $writer->addAttribute('title', $tooltip); |
|
315 | + if ($this->getHasAttributes()) |
|
316 | 316 | { |
317 | - $attributes=$this->getAttributes(); |
|
318 | - $value=$attributes->remove('value'); |
|
317 | + $attributes = $this->getAttributes(); |
|
318 | + $value = $attributes->remove('value'); |
|
319 | 319 | // onclick js should only be added to input tag |
320 | - if(($onclick=$attributes->remove('onclick'))===null) |
|
321 | - $onclick=''; |
|
322 | - if($attributes->getCount()) |
|
320 | + if (($onclick = $attributes->remove('onclick')) === null) |
|
321 | + $onclick = ''; |
|
322 | + if ($attributes->getCount()) |
|
323 | 323 | $writer->addAttributes($attributes); |
324 | - if($value!==null) |
|
325 | - $attributes->add('value',$value); |
|
324 | + if ($value !== null) |
|
325 | + $attributes->add('value', $value); |
|
326 | 326 | } |
327 | 327 | else |
328 | - $onclick=''; |
|
329 | - if($needspan=$this->getSpanNeeded()) |
|
328 | + $onclick = ''; |
|
329 | + if ($needspan = $this->getSpanNeeded()) |
|
330 | 330 | { |
331 | - $writer->addAttribute('id',$this->getSurroundingTagID()); |
|
331 | + $writer->addAttribute('id', $this->getSurroundingTagID()); |
|
332 | 332 | $writer->renderBeginTag($this->getSurroundingTag()); |
333 | 333 | } |
334 | - $clientID=$this->getClientID(); |
|
335 | - if(($text=$this->getText())!=='') |
|
334 | + $clientID = $this->getClientID(); |
|
335 | + if (($text = $this->getText()) !== '') |
|
336 | 336 | { |
337 | - if($this->getTextAlign()===TTextAlign::Left) |
|
337 | + if ($this->getTextAlign() === TTextAlign::Left) |
|
338 | 338 | { |
339 | - $this->renderLabel($writer,$clientID,$text); |
|
340 | - $this->renderInputTag($writer,$clientID,$onclick); |
|
339 | + $this->renderLabel($writer, $clientID, $text); |
|
340 | + $this->renderInputTag($writer, $clientID, $onclick); |
|
341 | 341 | } |
342 | 342 | else |
343 | 343 | { |
344 | - $this->renderInputTag($writer,$clientID,$onclick); |
|
345 | - $this->renderLabel($writer,$clientID,$text); |
|
344 | + $this->renderInputTag($writer, $clientID, $onclick); |
|
345 | + $this->renderLabel($writer, $clientID, $text); |
|
346 | 346 | } |
347 | 347 | } |
348 | 348 | else |
349 | - $this->renderInputTag($writer,$clientID,$onclick); |
|
350 | - if($needspan) |
|
349 | + $this->renderInputTag($writer, $clientID, $onclick); |
|
350 | + if ($needspan) |
|
351 | 351 | $writer->renderEndTag(); |
352 | 352 | } |
353 | 353 | |
@@ -356,12 +356,12 @@ discard block |
||
356 | 356 | */ |
357 | 357 | public function getLabelAttributes() |
358 | 358 | { |
359 | - if($attributes=$this->getViewState('LabelAttributes',null)) |
|
359 | + if ($attributes = $this->getViewState('LabelAttributes', null)) |
|
360 | 360 | return $attributes; |
361 | 361 | else |
362 | 362 | { |
363 | - $attributes=new TAttributeCollection; |
|
364 | - $this->setViewState('LabelAttributes',$attributes,null); |
|
363 | + $attributes = new TAttributeCollection; |
|
364 | + $this->setViewState('LabelAttributes', $attributes, null); |
|
365 | 365 | return $attributes; |
366 | 366 | } |
367 | 367 | } |
@@ -371,12 +371,12 @@ discard block |
||
371 | 371 | */ |
372 | 372 | public function getInputAttributes() |
373 | 373 | { |
374 | - if($attributes=$this->getViewState('InputAttributes',null)) |
|
374 | + if ($attributes = $this->getViewState('InputAttributes', null)) |
|
375 | 375 | return $attributes; |
376 | 376 | else |
377 | 377 | { |
378 | - $attributes=new TAttributeCollection; |
|
379 | - $this->setViewState('InputAttributes',$attributes,null); |
|
378 | + $attributes = new TAttributeCollection; |
|
379 | + $this->setViewState('InputAttributes', $attributes, null); |
|
380 | 380 | return $attributes; |
381 | 381 | } |
382 | 382 | } |
@@ -386,14 +386,14 @@ discard block |
||
386 | 386 | */ |
387 | 387 | protected function getValueAttribute() |
388 | 388 | { |
389 | - if(($value=$this->getValue())!=='') |
|
389 | + if (($value = $this->getValue()) !== '') |
|
390 | 390 | return $value; |
391 | 391 | else |
392 | 392 | { |
393 | - $attributes=$this->getViewState('InputAttributes',null); |
|
394 | - if($attributes && $attributes->contains('value')) |
|
393 | + $attributes = $this->getViewState('InputAttributes', null); |
|
394 | + if ($attributes && $attributes->contains('value')) |
|
395 | 395 | return $attributes->itemAt('value'); |
396 | - else if($this->hasAttribute('value')) |
|
396 | + else if ($this->hasAttribute('value')) |
|
397 | 397 | return $this->getAttribute('value'); |
398 | 398 | else |
399 | 399 | return ''; |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | */ |
406 | 406 | public function getEnableClientScript() |
407 | 407 | { |
408 | - return $this->getViewState('EnableClientScript',true); |
|
408 | + return $this->getViewState('EnableClientScript', true); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | */ |
414 | 414 | public function setEnableClientScript($value) |
415 | 415 | { |
416 | - $this->setViewState('EnableClientScript',TPropertyValue::ensureBoolean($value),true); |
|
416 | + $this->setViewState('EnableClientScript', TPropertyValue::ensureBoolean($value), true); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | /** |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | * @return bool wether this control needs a surrounding span tag |
424 | 424 | */ |
425 | 425 | protected function getSpanNeeded() { |
426 | - return $this->getText()!==''; |
|
426 | + return $this->getText() !== ''; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -432,10 +432,10 @@ discard block |
||
432 | 432 | * @param string checkbox id |
433 | 433 | * @param string label text |
434 | 434 | */ |
435 | - protected function renderLabel($writer,$clientID,$text) |
|
435 | + protected function renderLabel($writer, $clientID, $text) |
|
436 | 436 | { |
437 | - $writer->addAttribute('for',$clientID); |
|
438 | - if($attributes=$this->getViewState('LabelAttributes',null)) |
|
437 | + $writer->addAttribute('for', $clientID); |
|
438 | + if ($attributes = $this->getViewState('LabelAttributes', null)) |
|
439 | 439 | $writer->addAttributes($attributes); |
440 | 440 | $writer->renderBeginTag('label'); |
441 | 441 | $writer->write($text); |
@@ -448,24 +448,24 @@ discard block |
||
448 | 448 | * @param string checkbox id |
449 | 449 | * @param string onclick js |
450 | 450 | */ |
451 | - protected function renderInputTag($writer,$clientID,$onclick) |
|
452 | - { |
|
453 | - if($clientID!=='') |
|
454 | - $writer->addAttribute('id',$clientID); |
|
455 | - $writer->addAttribute('type','checkbox'); |
|
456 | - if(($value=$this->getValueAttribute())!=='') |
|
457 | - $writer->addAttribute('value',$value); |
|
458 | - if(!empty($onclick)) |
|
459 | - $writer->addAttribute('onclick',$onclick); |
|
460 | - if(($uniqueID=$this->getUniqueID())!=='') |
|
461 | - $writer->addAttribute('name',$uniqueID); |
|
462 | - if($this->getChecked()) |
|
463 | - $writer->addAttribute('checked','checked'); |
|
464 | - if(!$this->getEnabled(true)) |
|
465 | - $writer->addAttribute('disabled','disabled'); |
|
466 | - |
|
467 | - $page=$this->getPage(); |
|
468 | - if($this->getEnabled(true) |
|
451 | + protected function renderInputTag($writer, $clientID, $onclick) |
|
452 | + { |
|
453 | + if ($clientID !== '') |
|
454 | + $writer->addAttribute('id', $clientID); |
|
455 | + $writer->addAttribute('type', 'checkbox'); |
|
456 | + if (($value = $this->getValueAttribute()) !== '') |
|
457 | + $writer->addAttribute('value', $value); |
|
458 | + if (!empty($onclick)) |
|
459 | + $writer->addAttribute('onclick', $onclick); |
|
460 | + if (($uniqueID = $this->getUniqueID()) !== '') |
|
461 | + $writer->addAttribute('name', $uniqueID); |
|
462 | + if ($this->getChecked()) |
|
463 | + $writer->addAttribute('checked', 'checked'); |
|
464 | + if (!$this->getEnabled(true)) |
|
465 | + $writer->addAttribute('disabled', 'disabled'); |
|
466 | + |
|
467 | + $page = $this->getPage(); |
|
468 | + if ($this->getEnabled(true) |
|
469 | 469 | && $this->getEnableClientScript() |
470 | 470 | && $this->getAutoPostBack() |
471 | 471 | && $page->getClientSupportsJavaScript()) |
@@ -473,11 +473,11 @@ discard block |
||
473 | 473 | $this->renderClientControlScript($writer); |
474 | 474 | } |
475 | 475 | |
476 | - if(($accesskey=$this->getAccessKey())!=='') |
|
477 | - $writer->addAttribute('accesskey',$accesskey); |
|
478 | - if(($tabindex=$this->getTabIndex())>0) |
|
479 | - $writer->addAttribute('tabindex',"$tabindex"); |
|
480 | - if($attributes=$this->getViewState('InputAttributes',null)) |
|
476 | + if (($accesskey = $this->getAccessKey()) !== '') |
|
477 | + $writer->addAttribute('accesskey', $accesskey); |
|
478 | + if (($tabindex = $this->getTabIndex()) > 0) |
|
479 | + $writer->addAttribute('tabindex', "$tabindex"); |
|
480 | + if ($attributes = $this->getViewState('InputAttributes', null)) |
|
481 | 481 | $writer->addAttributes($attributes); |
482 | 482 | $writer->renderBeginTag('input'); |
483 | 483 | $writer->renderEndTag(); |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | protected function renderClientControlScript($writer) |
490 | 490 | { |
491 | 491 | $cs = $this->getPage()->getClientScript(); |
492 | - $cs->registerPostBackControl($this->getClientClassName(),$this->getPostBackOptions()); |
|
492 | + $cs->registerPostBackControl($this->getClientClassName(), $this->getPostBackOptions()); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | */ |
531 | 531 | class TTextAlign extends TEnumerable |
532 | 532 | { |
533 | - const Left='Left'; |
|
534 | - const Right='Right'; |
|
533 | + const Left = 'Left'; |
|
534 | + const Right = 'Right'; |
|
535 | 535 | } |
536 | 536 |
@@ -61,8 +61,9 @@ discard block |
||
61 | 61 | public function loadPostData($key,$values) |
62 | 62 | { |
63 | 63 | $checked=$this->getChecked(); |
64 | - if($newChecked=isset($values[$key])) |
|
65 | - $this->setValue($values[$key]); |
|
64 | + if($newChecked=isset($values[$key])) { |
|
65 | + $this->setValue($values[$key]); |
|
66 | + } |
|
66 | 67 | $this->setChecked($newChecked); |
67 | 68 | return $this->_dataChanged=($newChecked!==$checked); |
68 | 69 | } |
@@ -74,8 +75,9 @@ discard block |
||
74 | 75 | */ |
75 | 76 | public function raisePostDataChangedEvent() |
76 | 77 | { |
77 | - if($this->getAutoPostBack() && $this->getCausesValidation()) |
|
78 | - $this->getPage()->validate($this->getValidationGroup()); |
|
78 | + if($this->getAutoPostBack() && $this->getCausesValidation()) { |
|
79 | + $this->getPage()->validate($this->getValidationGroup()); |
|
80 | + } |
|
79 | 81 | $this->onCheckedChanged(null); |
80 | 82 | } |
81 | 83 | |
@@ -101,8 +103,9 @@ discard block |
||
101 | 103 | public function onPreRender($param) |
102 | 104 | { |
103 | 105 | parent::onPreRender($param); |
104 | - if($this->getEnabled(true)) |
|
105 | - $this->getPage()->registerRequiresPostData($this); |
|
106 | + if($this->getEnabled(true)) { |
|
107 | + $this->getPage()->registerRequiresPostData($this); |
|
108 | + } |
|
106 | 109 | } |
107 | 110 | |
108 | 111 | /** |
@@ -308,24 +311,29 @@ discard block |
||
308 | 311 | public function render($writer) |
309 | 312 | { |
310 | 313 | $this->getPage()->ensureRenderInForm($this); |
311 | - if($this->getHasStyle()) |
|
312 | - $this->getStyle()->addAttributesToRender($writer); |
|
313 | - if(($tooltip=$this->getToolTip())!=='') |
|
314 | - $writer->addAttribute('title',$tooltip); |
|
314 | + if($this->getHasStyle()) { |
|
315 | + $this->getStyle()->addAttributesToRender($writer); |
|
316 | + } |
|
317 | + if(($tooltip=$this->getToolTip())!=='') { |
|
318 | + $writer->addAttribute('title',$tooltip); |
|
319 | + } |
|
315 | 320 | if($this->getHasAttributes()) |
316 | 321 | { |
317 | 322 | $attributes=$this->getAttributes(); |
318 | 323 | $value=$attributes->remove('value'); |
319 | 324 | // onclick js should only be added to input tag |
320 | - if(($onclick=$attributes->remove('onclick'))===null) |
|
321 | - $onclick=''; |
|
322 | - if($attributes->getCount()) |
|
323 | - $writer->addAttributes($attributes); |
|
324 | - if($value!==null) |
|
325 | - $attributes->add('value',$value); |
|
325 | + if(($onclick=$attributes->remove('onclick'))===null) { |
|
326 | + $onclick=''; |
|
327 | + } |
|
328 | + if($attributes->getCount()) { |
|
329 | + $writer->addAttributes($attributes); |
|
330 | + } |
|
331 | + if($value!==null) { |
|
332 | + $attributes->add('value',$value); |
|
333 | + } |
|
334 | + } else { |
|
335 | + $onclick=''; |
|
326 | 336 | } |
327 | - else |
|
328 | - $onclick=''; |
|
329 | 337 | if($needspan=$this->getSpanNeeded()) |
330 | 338 | { |
331 | 339 | $writer->addAttribute('id',$this->getSurroundingTagID()); |
@@ -338,17 +346,17 @@ discard block |
||
338 | 346 | { |
339 | 347 | $this->renderLabel($writer,$clientID,$text); |
340 | 348 | $this->renderInputTag($writer,$clientID,$onclick); |
341 | - } |
|
342 | - else |
|
349 | + } else |
|
343 | 350 | { |
344 | 351 | $this->renderInputTag($writer,$clientID,$onclick); |
345 | 352 | $this->renderLabel($writer,$clientID,$text); |
346 | 353 | } |
354 | + } else { |
|
355 | + $this->renderInputTag($writer,$clientID,$onclick); |
|
356 | + } |
|
357 | + if($needspan) { |
|
358 | + $writer->renderEndTag(); |
|
347 | 359 | } |
348 | - else |
|
349 | - $this->renderInputTag($writer,$clientID,$onclick); |
|
350 | - if($needspan) |
|
351 | - $writer->renderEndTag(); |
|
352 | 360 | } |
353 | 361 | |
354 | 362 | /** |
@@ -356,9 +364,9 @@ discard block |
||
356 | 364 | */ |
357 | 365 | public function getLabelAttributes() |
358 | 366 | { |
359 | - if($attributes=$this->getViewState('LabelAttributes',null)) |
|
360 | - return $attributes; |
|
361 | - else |
|
367 | + if($attributes=$this->getViewState('LabelAttributes',null)) { |
|
368 | + return $attributes; |
|
369 | + } else |
|
362 | 370 | { |
363 | 371 | $attributes=new TAttributeCollection; |
364 | 372 | $this->setViewState('LabelAttributes',$attributes,null); |
@@ -371,9 +379,9 @@ discard block |
||
371 | 379 | */ |
372 | 380 | public function getInputAttributes() |
373 | 381 | { |
374 | - if($attributes=$this->getViewState('InputAttributes',null)) |
|
375 | - return $attributes; |
|
376 | - else |
|
382 | + if($attributes=$this->getViewState('InputAttributes',null)) { |
|
383 | + return $attributes; |
|
384 | + } else |
|
377 | 385 | { |
378 | 386 | $attributes=new TAttributeCollection; |
379 | 387 | $this->setViewState('InputAttributes',$attributes,null); |
@@ -386,17 +394,18 @@ discard block |
||
386 | 394 | */ |
387 | 395 | protected function getValueAttribute() |
388 | 396 | { |
389 | - if(($value=$this->getValue())!=='') |
|
390 | - return $value; |
|
391 | - else |
|
397 | + if(($value=$this->getValue())!=='') { |
|
398 | + return $value; |
|
399 | + } else |
|
392 | 400 | { |
393 | 401 | $attributes=$this->getViewState('InputAttributes',null); |
394 | - if($attributes && $attributes->contains('value')) |
|
395 | - return $attributes->itemAt('value'); |
|
396 | - else if($this->hasAttribute('value')) |
|
397 | - return $this->getAttribute('value'); |
|
398 | - else |
|
399 | - return ''; |
|
402 | + if($attributes && $attributes->contains('value')) { |
|
403 | + return $attributes->itemAt('value'); |
|
404 | + } else if($this->hasAttribute('value')) { |
|
405 | + return $this->getAttribute('value'); |
|
406 | + } else { |
|
407 | + return ''; |
|
408 | + } |
|
400 | 409 | } |
401 | 410 | } |
402 | 411 | |
@@ -435,8 +444,9 @@ discard block |
||
435 | 444 | protected function renderLabel($writer,$clientID,$text) |
436 | 445 | { |
437 | 446 | $writer->addAttribute('for',$clientID); |
438 | - if($attributes=$this->getViewState('LabelAttributes',null)) |
|
439 | - $writer->addAttributes($attributes); |
|
447 | + if($attributes=$this->getViewState('LabelAttributes',null)) { |
|
448 | + $writer->addAttributes($attributes); |
|
449 | + } |
|
440 | 450 | $writer->renderBeginTag('label'); |
441 | 451 | $writer->write($text); |
442 | 452 | $writer->renderEndTag(); |
@@ -450,19 +460,25 @@ discard block |
||
450 | 460 | */ |
451 | 461 | protected function renderInputTag($writer,$clientID,$onclick) |
452 | 462 | { |
453 | - if($clientID!=='') |
|
454 | - $writer->addAttribute('id',$clientID); |
|
463 | + if($clientID!=='') { |
|
464 | + $writer->addAttribute('id',$clientID); |
|
465 | + } |
|
455 | 466 | $writer->addAttribute('type','checkbox'); |
456 | - if(($value=$this->getValueAttribute())!=='') |
|
457 | - $writer->addAttribute('value',$value); |
|
458 | - if(!empty($onclick)) |
|
459 | - $writer->addAttribute('onclick',$onclick); |
|
460 | - if(($uniqueID=$this->getUniqueID())!=='') |
|
461 | - $writer->addAttribute('name',$uniqueID); |
|
462 | - if($this->getChecked()) |
|
463 | - $writer->addAttribute('checked','checked'); |
|
464 | - if(!$this->getEnabled(true)) |
|
465 | - $writer->addAttribute('disabled','disabled'); |
|
467 | + if(($value=$this->getValueAttribute())!=='') { |
|
468 | + $writer->addAttribute('value',$value); |
|
469 | + } |
|
470 | + if(!empty($onclick)) { |
|
471 | + $writer->addAttribute('onclick',$onclick); |
|
472 | + } |
|
473 | + if(($uniqueID=$this->getUniqueID())!=='') { |
|
474 | + $writer->addAttribute('name',$uniqueID); |
|
475 | + } |
|
476 | + if($this->getChecked()) { |
|
477 | + $writer->addAttribute('checked','checked'); |
|
478 | + } |
|
479 | + if(!$this->getEnabled(true)) { |
|
480 | + $writer->addAttribute('disabled','disabled'); |
|
481 | + } |
|
466 | 482 | |
467 | 483 | $page=$this->getPage(); |
468 | 484 | if($this->getEnabled(true) |
@@ -473,12 +489,15 @@ discard block |
||
473 | 489 | $this->renderClientControlScript($writer); |
474 | 490 | } |
475 | 491 | |
476 | - if(($accesskey=$this->getAccessKey())!=='') |
|
477 | - $writer->addAttribute('accesskey',$accesskey); |
|
478 | - if(($tabindex=$this->getTabIndex())>0) |
|
479 | - $writer->addAttribute('tabindex',"$tabindex"); |
|
480 | - if($attributes=$this->getViewState('InputAttributes',null)) |
|
481 | - $writer->addAttributes($attributes); |
|
492 | + if(($accesskey=$this->getAccessKey())!=='') { |
|
493 | + $writer->addAttribute('accesskey',$accesskey); |
|
494 | + } |
|
495 | + if(($tabindex=$this->getTabIndex())>0) { |
|
496 | + $writer->addAttribute('tabindex',"$tabindex"); |
|
497 | + } |
|
498 | + if($attributes=$this->getViewState('InputAttributes',null)) { |
|
499 | + $writer->addAttributes($attributes); |
|
500 | + } |
|
482 | 501 | $writer->renderBeginTag('input'); |
483 | 502 | $writer->renderEndTag(); |
484 | 503 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
157 | - * @return string the direction of traversing the list, defaults to 'Vertical' |
|
157 | + * @return TRepeatDirection the direction of traversing the list, defaults to 'Vertical' |
|
158 | 158 | */ |
159 | 159 | public function getRepeatDirection() |
160 | 160 | { |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | - * @return string how the list should be displayed, using table or using line breaks. Defaults to 'Table'. |
|
173 | + * @return TRepeatLayout how the list should be displayed, using table or using line breaks. Defaults to 'Table'. |
|
174 | 174 | */ |
175 | 175 | public function getRepeatLayout() |
176 | 176 | { |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | /** |
450 | 450 | * Returns the value to be validated. |
451 | 451 | * This methid is required by IValidatable interface. |
452 | - * @return mixed the value of the property to be validated. |
|
452 | + * @return string the value of the property to be validated. |
|
453 | 453 | */ |
454 | 454 | public function getValidationPropertyValue() |
455 | 455 | { |
@@ -463,14 +463,14 @@ |
||
463 | 463 | */ |
464 | 464 | public function getIsValid() |
465 | 465 | { |
466 | - return $this->_isValid; |
|
466 | + return $this->_isValid; |
|
467 | 467 | } |
468 | 468 | /** |
469 | 469 | * @param bool wether this control is valid. |
470 | 470 | */ |
471 | 471 | public function setIsValid($value) |
472 | 472 | { |
473 | - $this->_isValid=TPropertyValue::ensureBoolean($value); |
|
473 | + $this->_isValid=TPropertyValue::ensureBoolean($value); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | * @package System.Web.UI.WebControls |
46 | 46 | * @since 3.0 |
47 | 47 | */ |
48 | -class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler, IValidatable |
|
48 | +class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingContainer, IPostBackDataHandler, IValidatable |
|
49 | 49 | { |
50 | 50 | private $_repeatedControl; |
51 | 51 | private $_isEnabled; |
52 | - private $_changedEventRaised=false; |
|
53 | - private $_dataChanged=false; |
|
54 | - private $_isValid=true; |
|
52 | + private $_changedEventRaised = false; |
|
53 | + private $_dataChanged = false; |
|
54 | + private $_isValid = true; |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Constructor. |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | public function __construct() |
61 | 61 | { |
62 | 62 | parent::__construct(); |
63 | - $this->_repeatedControl=$this->createRepeatedControl(); |
|
63 | + $this->_repeatedControl = $this->createRepeatedControl(); |
|
64 | 64 | $this->_repeatedControl->setEnableViewState(false); |
65 | 65 | $this->_repeatedControl->setID('c0'); |
66 | 66 | $this->getControls()->add($this->_repeatedControl); |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param string control ID |
83 | 83 | * @return TControl control being found |
84 | 84 | */ |
85 | - public function findControl($id, $real=false) |
|
85 | + public function findControl($id, $real = false) |
|
86 | 86 | { |
87 | - if ($real===true) |
|
87 | + if ($real === true) |
|
88 | 88 | return parent::findControl($id); |
89 | 89 | return $this; |
90 | 90 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function getTextAlign() |
114 | 114 | { |
115 | - return $this->getViewState('TextAlign',TTextAlign::Right); |
|
115 | + return $this->getViewState('TextAlign', TTextAlign::Right); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function setTextAlign($value) |
122 | 122 | { |
123 | - $this->setViewState('TextAlign',TPropertyValue::ensureEnum($value,'TTextAlign'),TTextAlign::Right); |
|
123 | + $this->setViewState('TextAlign', TPropertyValue::ensureEnum($value, 'TTextAlign'), TTextAlign::Right); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | |
@@ -129,10 +129,10 @@ discard block |
||
129 | 129 | */ |
130 | 130 | protected function getRepeatInfo() |
131 | 131 | { |
132 | - if(($repeatInfo=$this->getViewState('RepeatInfo',null))===null) |
|
132 | + if (($repeatInfo = $this->getViewState('RepeatInfo', null)) === null) |
|
133 | 133 | { |
134 | - $repeatInfo=new TRepeatInfo; |
|
135 | - $this->setViewState('RepeatInfo',$repeatInfo,null); |
|
134 | + $repeatInfo = new TRepeatInfo; |
|
135 | + $this->setViewState('RepeatInfo', $repeatInfo, null); |
|
136 | 136 | } |
137 | 137 | return $repeatInfo; |
138 | 138 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public function getCellSpacing() |
192 | 192 | { |
193 | - if($this->getHasStyle()) |
|
193 | + if ($this->getHasStyle()) |
|
194 | 194 | return $this->getStyle()->getCellSpacing(); |
195 | 195 | else |
196 | 196 | return -1; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | */ |
211 | 211 | public function getCellPadding() |
212 | 212 | { |
213 | - if($this->getHasStyle()) |
|
213 | + if ($this->getHasStyle()) |
|
214 | 214 | return $this->getStyle()->getCellPadding(); |
215 | 215 | else |
216 | 216 | return -1; |
@@ -266,16 +266,16 @@ discard block |
||
266 | 266 | // and it's a callback, |
267 | 267 | // and we can update clientside, |
268 | 268 | // then update the 'disabled' attribute of the items. |
269 | - if(($this instanceof IActiveControl) && |
|
269 | + if (($this instanceof IActiveControl) && |
|
270 | 270 | $this->getPage()->getIsCallBack() && |
271 | 271 | $this->getActiveControl()->canUpdateClientSide()) |
272 | 272 | { |
273 | 273 | $items = $this->getItems(); |
274 | 274 | $cs = $this->getPage()->getCallbackClient(); |
275 | - $baseClientID = $this->getClientID().'_c'; |
|
276 | - foreach($items as $index=>$item) |
|
275 | + $baseClientID = $this->getClientID() . '_c'; |
|
276 | + foreach ($items as $index=>$item) |
|
277 | 277 | { |
278 | - $cs->setAttribute($baseClientID.$index, 'disabled', $value); |
|
278 | + $cs->setAttribute($baseClientID . $index, 'disabled', $value); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | } |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @param integer index of the item being rendered |
288 | 288 | * @return null |
289 | 289 | */ |
290 | - public function generateItemStyle($itemType,$index) |
|
290 | + public function generateItemStyle($itemType, $index) |
|
291 | 291 | { |
292 | 292 | return null; |
293 | 293 | } |
@@ -300,18 +300,18 @@ discard block |
||
300 | 300 | * @param string item type (Header,Footer,Item,AlternatingItem,SelectedItem,EditItem,Separator,Pager) |
301 | 301 | * @param integer zero-based index of the item in the item list |
302 | 302 | */ |
303 | - public function renderItem($writer,$repeatInfo,$itemType,$index) |
|
303 | + public function renderItem($writer, $repeatInfo, $itemType, $index) |
|
304 | 304 | { |
305 | - $repeatedControl=$this->_repeatedControl; |
|
306 | - $item=$this->getItems()->itemAt($index); |
|
307 | - if($item->getHasAttributes()) |
|
305 | + $repeatedControl = $this->_repeatedControl; |
|
306 | + $item = $this->getItems()->itemAt($index); |
|
307 | + if ($item->getHasAttributes()) |
|
308 | 308 | $repeatedControl->getAttributes()->copyFrom($item->getAttributes()); |
309 | - else if($repeatedControl->getHasAttributes()) |
|
309 | + else if ($repeatedControl->getHasAttributes()) |
|
310 | 310 | $repeatedControl->getAttributes()->clear(); |
311 | 311 | $repeatedControl->setID("c$index"); |
312 | 312 | $repeatedControl->setText($item->getText()); |
313 | 313 | $repeatedControl->setChecked($item->getSelected()); |
314 | - $repeatedControl->setAttribute('value',$item->getValue()); |
|
314 | + $repeatedControl->setAttribute('value', $item->getValue()); |
|
315 | 315 | $repeatedControl->setEnabled($this->_isEnabled && $item->getEnabled()); |
316 | 316 | $repeatedControl->setEnableClientScript(false); |
317 | 317 | $repeatedControl->renderControl($writer); |
@@ -324,25 +324,25 @@ discard block |
||
324 | 324 | * @param array the input data collection |
325 | 325 | * @return boolean whether the data of the control has been changed |
326 | 326 | */ |
327 | - public function loadPostData($key,$values) |
|
327 | + public function loadPostData($key, $values) |
|
328 | 328 | { |
329 | - if($this->getEnabled(true)) |
|
329 | + if ($this->getEnabled(true)) |
|
330 | 330 | { |
331 | - $index=(int)substr($key,strlen($this->getUniqueID())+2); |
|
331 | + $index = (int) substr($key, strlen($this->getUniqueID()) + 2); |
|
332 | 332 | $this->ensureDataBound(); |
333 | - if($index>=0 && $index<$this->getItemCount()) |
|
333 | + if ($index >= 0 && $index < $this->getItemCount()) |
|
334 | 334 | { |
335 | - $item=$this->getItems()->itemAt($index); |
|
336 | - if($item->getEnabled()) |
|
335 | + $item = $this->getItems()->itemAt($index); |
|
336 | + if ($item->getEnabled()) |
|
337 | 337 | { |
338 | - $checked=isset($values[$key]); |
|
339 | - if($item->getSelected()!==$checked) |
|
338 | + $checked = isset($values[$key]); |
|
339 | + if ($item->getSelected() !== $checked) |
|
340 | 340 | { |
341 | 341 | $item->setSelected($checked); |
342 | - if(!$this->_changedEventRaised) |
|
342 | + if (!$this->_changedEventRaised) |
|
343 | 343 | { |
344 | - $this->_changedEventRaised=true; |
|
345 | - return $this->_dataChanged=true; |
|
344 | + $this->_changedEventRaised = true; |
|
345 | + return $this->_dataChanged = true; |
|
346 | 346 | } |
347 | 347 | } |
348 | 348 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | */ |
361 | 361 | public function raisePostDataChangedEvent() |
362 | 362 | { |
363 | - if($this->getAutoPostBack() && $this->getCausesValidation()) |
|
363 | + if ($this->getAutoPostBack() && $this->getCausesValidation()) |
|
364 | 364 | $this->getPage()->validate($this->getValidationGroup()); |
365 | 365 | $this->onSelectedIndexChanged(null); |
366 | 366 | } |
@@ -376,9 +376,9 @@ discard block |
||
376 | 376 | $this->_repeatedControl->setAutoPostBack($this->getAutoPostBack()); |
377 | 377 | $this->_repeatedControl->setCausesValidation($this->getCausesValidation()); |
378 | 378 | $this->_repeatedControl->setValidationGroup($this->getValidationGroup()); |
379 | - $page=$this->getPage(); |
|
380 | - $n=$this->getItemCount(); |
|
381 | - for($i=0;$i<$n;++$i) |
|
379 | + $page = $this->getPage(); |
|
380 | + $n = $this->getItemCount(); |
|
381 | + for ($i = 0; $i < $n; ++$i) |
|
382 | 382 | { |
383 | 383 | $this->_repeatedControl->setID("c$i"); |
384 | 384 | $page->registerRequiresPostData($this->_repeatedControl); |
@@ -390,9 +390,9 @@ discard block |
||
390 | 390 | * |
391 | 391 | *@return boolean true if we need a span |
392 | 392 | */ |
393 | - protected function getSpanNeeded () |
|
393 | + protected function getSpanNeeded() |
|
394 | 394 | { |
395 | - return $this->getRepeatLayout()===TRepeatLayout::Raw; |
|
395 | + return $this->getRepeatLayout() === TRepeatLayout::Raw; |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -402,24 +402,24 @@ discard block |
||
402 | 402 | */ |
403 | 403 | public function render($writer) |
404 | 404 | { |
405 | - if($this->getItemCount()>0) |
|
405 | + if ($this->getItemCount() > 0) |
|
406 | 406 | { |
407 | - if ($needSpan=$this->getSpanNeeded()) |
|
407 | + if ($needSpan = $this->getSpanNeeded()) |
|
408 | 408 | { |
409 | 409 | $writer->addAttribute('id', $this->getClientId()); |
410 | 410 | $writer->renderBeginTag('span'); |
411 | 411 | } |
412 | - $this->_isEnabled=$this->getEnabled(true); |
|
413 | - $repeatInfo=$this->getRepeatInfo(); |
|
414 | - $accessKey=$this->getAccessKey(); |
|
415 | - $tabIndex=$this->getTabIndex(); |
|
412 | + $this->_isEnabled = $this->getEnabled(true); |
|
413 | + $repeatInfo = $this->getRepeatInfo(); |
|
414 | + $accessKey = $this->getAccessKey(); |
|
415 | + $tabIndex = $this->getTabIndex(); |
|
416 | 416 | $this->_repeatedControl->setTextAlign($this->getTextAlign()); |
417 | 417 | $this->_repeatedControl->setAccessKey($accessKey); |
418 | 418 | $this->_repeatedControl->setTabIndex($tabIndex); |
419 | 419 | $this->setAccessKey(''); |
420 | 420 | $this->setTabIndex(0); |
421 | 421 | $this->addAttributesToRender($writer); |
422 | - $repeatInfo->renderRepeater($writer,$this); |
|
422 | + $repeatInfo->renderRepeater($writer, $this); |
|
423 | 423 | $this->setAccessKey($accessKey); |
424 | 424 | $this->setTabIndex($tabIndex); |
425 | 425 | if ($needSpan) |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | } |
428 | 428 | |
429 | 429 | //checkbox skipped the client control script in addAttributesToRender |
430 | - if($this->getEnabled(true) |
|
430 | + if ($this->getEnabled(true) |
|
431 | 431 | && $this->getEnableClientScript() |
432 | 432 | && $this->getAutoPostBack() |
433 | 433 | && $this->getPage()->getClientSupportsJavaScript()) |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | */ |
471 | 471 | public function setIsValid($value) |
472 | 472 | { |
473 | - $this->_isValid=TPropertyValue::ensureBoolean($value); |
|
473 | + $this->_isValid = TPropertyValue::ensureBoolean($value); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
@@ -84,8 +84,9 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function findControl($id, $real=false) |
86 | 86 | { |
87 | - if ($real===true) |
|
88 | - return parent::findControl($id); |
|
87 | + if ($real===true) { |
|
88 | + return parent::findControl($id); |
|
89 | + } |
|
89 | 90 | return $this; |
90 | 91 | } |
91 | 92 | |
@@ -190,10 +191,11 @@ discard block |
||
190 | 191 | */ |
191 | 192 | public function getCellSpacing() |
192 | 193 | { |
193 | - if($this->getHasStyle()) |
|
194 | - return $this->getStyle()->getCellSpacing(); |
|
195 | - else |
|
196 | - return -1; |
|
194 | + if($this->getHasStyle()) { |
|
195 | + return $this->getStyle()->getCellSpacing(); |
|
196 | + } else { |
|
197 | + return -1; |
|
198 | + } |
|
197 | 199 | } |
198 | 200 | |
199 | 201 | /** |
@@ -210,10 +212,11 @@ discard block |
||
210 | 212 | */ |
211 | 213 | public function getCellPadding() |
212 | 214 | { |
213 | - if($this->getHasStyle()) |
|
214 | - return $this->getStyle()->getCellPadding(); |
|
215 | - else |
|
216 | - return -1; |
|
215 | + if($this->getHasStyle()) { |
|
216 | + return $this->getStyle()->getCellPadding(); |
|
217 | + } else { |
|
218 | + return -1; |
|
219 | + } |
|
217 | 220 | } |
218 | 221 | |
219 | 222 | /** |
@@ -304,10 +307,11 @@ discard block |
||
304 | 307 | { |
305 | 308 | $repeatedControl=$this->_repeatedControl; |
306 | 309 | $item=$this->getItems()->itemAt($index); |
307 | - if($item->getHasAttributes()) |
|
308 | - $repeatedControl->getAttributes()->copyFrom($item->getAttributes()); |
|
309 | - else if($repeatedControl->getHasAttributes()) |
|
310 | - $repeatedControl->getAttributes()->clear(); |
|
310 | + if($item->getHasAttributes()) { |
|
311 | + $repeatedControl->getAttributes()->copyFrom($item->getAttributes()); |
|
312 | + } else if($repeatedControl->getHasAttributes()) { |
|
313 | + $repeatedControl->getAttributes()->clear(); |
|
314 | + } |
|
311 | 315 | $repeatedControl->setID("c$index"); |
312 | 316 | $repeatedControl->setText($item->getText()); |
313 | 317 | $repeatedControl->setChecked($item->getSelected()); |
@@ -360,8 +364,9 @@ discard block |
||
360 | 364 | */ |
361 | 365 | public function raisePostDataChangedEvent() |
362 | 366 | { |
363 | - if($this->getAutoPostBack() && $this->getCausesValidation()) |
|
364 | - $this->getPage()->validate($this->getValidationGroup()); |
|
367 | + if($this->getAutoPostBack() && $this->getCausesValidation()) { |
|
368 | + $this->getPage()->validate($this->getValidationGroup()); |
|
369 | + } |
|
365 | 370 | $this->onSelectedIndexChanged(null); |
366 | 371 | } |
367 | 372 | |
@@ -422,8 +427,9 @@ discard block |
||
422 | 427 | $repeatInfo->renderRepeater($writer,$this); |
423 | 428 | $this->setAccessKey($accessKey); |
424 | 429 | $this->setTabIndex($tabIndex); |
425 | - if ($needSpan) |
|
426 | - $writer->renderEndTag(); |
|
430 | + if ($needSpan) { |
|
431 | + $writer->renderEndTag(); |
|
432 | + } |
|
427 | 433 | } |
428 | 434 | |
429 | 435 | //checkbox skipped the client control script in addAttributesToRender |