Project

General

Profile

« Previous | Next » 

Revision 756

Added by thorn over 16 years ago

call_captcha: added parameter 'style', fixed some issue with parameter 'image' and text-style captchas

View differences:

trunk/CHANGELOG
13 13
------------------------------------- 2.7.0 -------------------------------------
14 14
15-Mar-2008 Thomas Hornik
15 15
#	menulink: link can be menulink or subpage of menulink, too
16
#	call_captcha: added parameter 'style', fixed some issue with parameter 'image' and text-style captchas
16 17
13-Mar-2008 Christian Sommer
17 18
! 	adjusted error/warning templates to the updated backend layout
18 19
13-Mar-2008 Matthias Gallas
trunk/wb/include/captcha/captcha.php
79 79
}
80 80

  
81 81
if(!function_exists('call_captcha')) {
82
	function call_captcha($action='all') {
82
	function call_captcha($action='all', $style='') {
83 83
		global $MOD_CAPTCHA;
84 84
		$t = time();
85 85
		$_SESSION['captcha_time'] = $t;
......
90 90
				case 'text': // text-captcha
91 91
					?><table class="captcha_table"><tr>
92 92
					<td class="text_captcha"><?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?></td>
93
					<td><input type="text" name="captcha" maxlength="50"  style="width:150px" /></td>
93
					<td><input type="text" name="captcha" maxlength="50"  style="width:150px;" /></td>
94 94
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST']; ?></td>
95 95
					</tr></table><?php
96 96
					break;
......
98 98
				case 'calc_text': // calculation as text
99 99
					?><table class="captcha_table"><tr>
100 100
					<td class="text_captcha"><?php include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php'); ?>&nbsp;=&nbsp;</td>
101
					<td><input type="text" name="captcha" maxlength="10"  style="width:20px" /></td>
101
					<td><input type="text" name="captcha" maxlength="10"  style="width:20px;" /></td>
102 102
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
103 103
					</tr></table><?php
104 104
					break;
......
106 106
				case 'calc_ttf_image': // calculation with varying background and ttf-font
107 107
					?><table class="captcha_table"><tr>
108 108
					<td class="image_captcha"><img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t"; ?>" alt="Captcha" /></td><td>&nbsp;=&nbsp;</td>
109
					<td><input type="text" name="captcha" maxlength="10" style="width:20px" /></td>
109
					<td><input type="text" name="captcha" maxlength="10" style="width:20px;" /></td>
110 110
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_RES']; ?></td>
111 111
					</tr></table><?php
112 112
					break;
......
115 115
				case 'old_image': // old captcha
116 116
					?><table class="captcha_table"><tr>
117 117
					<td class="image_captcha"><img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t"; ?>" alt="Captcha" /></td>
118
					<td><input type="text" name="captcha" maxlength="10" style="width:50px" /></td>
118
					<td><input type="text" name="captcha" maxlength="10" style="width:50px;" /></td>
119 119
					<td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT']; ?></td>
120 120
					</tr></table><?php
121 121
					break;
......
124 124
			switch(CAPTCHA_TYPE) {
125 125
				case 'text': // text-captcha
126 126
				case 'calc_text': // calculation as text
127
					echo ($style?"<span $style>":'');
127 128
					include(WB_PATH.'/include/captcha/captchas/'.CAPTCHA_TYPE.'.php');
129
					echo ($style?'</span>':'');
128 130
					break;
129 131
				case 'calc_image': // calculation with image (old captcha)
130 132
				case 'calc_ttf_image': // calculation with varying background and ttf-font
131 133
				case 'ttf_image': // captcha with varying background and ttf-font
132 134
				case 'old_image': // old captcha
133
					echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t";
135
					echo "<img $style src=\"".WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t\" />";
134 136
					break;
135 137
			}
136 138
		} elseif($action=='input') {
137 139
			switch(CAPTCHA_TYPE) {
138 140
				case 'text': // text-captcha
139
					?><input type="text" name="captcha" maxlength="50"  style="width:150px" /><?php
141
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:150px;" maxlength="50"').' />';
140 142
					break;
141 143
				case 'calc_text': // calculation as text
142
					?><input type="text" name="captcha" maxlength="10"  style="width:20px" /><?php
143
					break;
144 144
				case 'calc_image': // calculation with image (old captcha)
145 145
				case 'calc_ttf_image': // calculation with varying background and ttf-font
146
					?><input type="text" name="captcha" maxlength="10" style="width:20px" /><?php
146
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:20px;" maxlength="10"').' />';
147 147
					break;
148
				// normal images
149 148
				case 'ttf_image': // captcha with varying background and ttf-font
150 149
				case 'old_image': // old captcha
151
					?><input type="text" name="captcha" maxlength="10" style="width:50px" /><?php
150
					echo '<input type="text" name="captcha" '.($style?$style:'style="width:50px;" maxlength="10"').' />';
152 151
					break;
153 152
			}
154 153
		} elseif($action=='text') {
154
			echo ($style?"<span $style>":'');
155 155
			switch(CAPTCHA_TYPE) {
156
				// one special case
157 156
				case 'text': // text-captcha
158 157
					echo $MOD_CAPTCHA['VERIFICATION_INFO_QUEST'];
159 158
					break;
160
				// two special cases
161 159
				case 'calc_text': // calculation as text
162
					echo $MOD_CAPTCHA['VERIFICATION_INFO_RES'];
163
					break;
164 160
				case 'calc_image': // calculation with image (old captcha)
165 161
				case 'calc_ttf_image': // calculation with varying background and ttf-font
166 162
					echo $MOD_CAPTCHA['VERIFICATION_INFO_RES'];
167 163
					break;
168
				// normal images
169 164
				case 'ttf_image': // captcha with varying background and ttf-font
170 165
				case 'old_image': // old captcha
171 166
					echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT'];
172 167
					break;
173 168
			}
169
			echo ($style?'</span>':'');
174 170
		}
175 171
	}
176 172
}
trunk/wb/include/captcha/readme.txt
20 20

  
21 21

  
22 22

  
23

  
24
One can improve CAPTCHA-type "CAPTCHA with varying fonts and backgrounds"
23
One can improve all CAPTCHA-types with varying fonts and backgrounds
25 24
- by adding backgrounds (PNG-images, 140x40 pixels) to backgrounds/
26 25
- and by adding TrueType-fonts to fonts/
27 26

  
28 27

  
29 28
How to use:
30
use 
31
	require_once(WB_PATH.'/include/captcha/captcha.php'); // will output a table with 3 columns: |CAPTCHA|Input|Text|. The calc_image captcha have 4 columns |CAPTCHA|=|Input|Text|.
32
and put 
33
	<?php call_captcha(); ?>
34
into your form.
35 29

  
30
1.)
31
put 
32
  require_once(WB_PATH.'/include/captcha/captcha.php');
33
in your file.
36 34

  
37
The CAPTCHA-code is allways stored in $_SESSION['captcha']
38
The user-input is in $_POST['captcha'] (or $_GET['captcha']).
39 35

  
40

  
41
call_captcha() will output code like this
36
2a.)
37
put 
38
  <?php call_captcha(); ?>
39
into your form.
40
This will output a table with varying columns (3 or 4) like this example:
42 41
<table class="captcha_table"><tr>
43
  <td><img src="<?php echo WB_URL.'/include/captcha/captchas/'.CAPTCHA_TYPE.".php?t=$t"; ?>" alt="Captcha" /></td>
42
  <td><img src="http://www.example.org/include/captcha/captchas/ttf.php?t=64241454" alt="Captcha" /></td>
44 43
  <td><input type="text" name="captcha" maxlength="5" style="width:50px" /></td>
45
  <td class="captcha_expl"><?php echo $MOD_CAPTCHA['VERIFICATION_INFO_TEXT']; ?></td>
44
  <td class="captcha_expl">Fill in the result</td>
46 45
</tr></table>
46

  
47

  
48
2b.)
49
If you want to use your own layout, use additional parameters to call_captcha():
50
call_captcha('all') will output the whole table as above.
51

  
52
call_captcha('image', $style); will output the <img>-tag for the image only (or the text for an text-style captcha):
53
Examples:
54
  call_captcha('image', 'style="...; title="captcha"');
55
    <img style="...; title="captcha" src="http://www.example.org/include/captcha/captchas/captcha.php?t=46784246" />
56
    or
57
    <span style="...; title="captcha">4 add 6</span>
58
	call_captcha('image');
59
    <img src="http://www.example.org/include/captcha/captchas/captcha.php?t=46784246" />
60
    or
61
    4 add 6
62

  
63
call_captcha('input', $style); will output the input-field:
64
  call_captcha('input', 'style"...;"');
65
    <input type="text" name="captcha" style="...;" />
66
  call_captcha('input');
67
    <input type="text" name="captcha" style="width:50px;" maxlength="10" />
68

  
69
call_captcha('text', $style); will output a short "what to do"-text
70
  call_captcha('text', 'style="...;"');
71
	  <span style="...;">Fill in the result</span>
72
  call_captcha('text');
73
	  Fill in the result
74

  
75

  
76

  
77
The CAPTCHA-code is allways stored in $_SESSION['captcha'] for verification with user-input.
78
The user-input is in $_POST['captcha'] (or maybe $_GET['captcha']).

Also available in: Unified diff