source: extensions/EasyCaptcha/tictac/gen_admin.php @ 31175

Last change on this file since 31175 was 29327, checked in by mistic100, 10 years ago

declare IN_ADMIN in tictactoe preview for compatibility with AdminTools

File size: 2.4 KB
Line 
1<?php
2define('PHPWG_ROOT_PATH', '../../../');
3define('IN_ADMIN', true);
4include(PHPWG_ROOT_PATH . 'include/common.inc.php');
5
6is_admin() or die('Hacking attempt!');
7
8defined('EASYCAPTCHA_ID') or die('Hacking attempt!');
9include_once(EASYCAPTCHA_PATH . 'tictac/functions_tictac.inc.php');
10
11$props = array();
12
13// overwrite config from url params
14$conf['EasyCaptcha']['tictac'] = $_GET;
15$props['size'] = $conf['EasyCaptcha']['tictac']['size'];
16
17// compute various sizes
18$props['bd_size'] = max(1, floor($props['size']*0.01));
19$props['box_size'] = floor(($props['size']-4*$props['bd_size'])/3);
20$props['size'] = 3*$props['box_size'] + 4*$props['bd_size'] + 1;
21$props['pad'] = floor($props['box_size']*0.1);
22$props['radius'] = floor($props['box_size']*0.2);
23
24
25// pick a random config
26$configs = get_configs();
27$selection = $configs[ array_rand($configs) ];
28
29
30// create image
31$img = imagecreatetruecolor($props['size'], $props['size']);
32imageantialias($img, true);
33
34// background
35$bg_start = hex2rgb($conf['EasyCaptcha']['tictac']['bg1']);
36$bg_end = hex2rgb($conf['EasyCaptcha']['tictac']['bg2']);
37
38imagegradientrectangle($img, $bg_start , $bg_end);
39// $bg = imagecolorallocatehex($img, $conf['EasyCaptcha']['tictac']['bg1']);
40// imagefilledrectangle($img, 0, 0, $props['size'], $props['size'], $bg);
41
42// borders
43$bd = imagecolorallocatehex($img, $conf['EasyCaptcha']['tictac']['bd']);
44for ($i=0; $i<4; $i++)
45{
46  imagefilledrectangle($img, $i*($props['box_size']+$props['bd_size']), 0, $i*($props['box_size']+$props['bd_size'])+$props['bd_size'], $props['size'], $bd);
47  imagefilledrectangle($img, 0, $i*($props['box_size']+$props['bd_size']), $props['size'], $i*($props['box_size']+$props['bd_size'])+$props['bd_size'], $bd);
48}
49
50// crosses
51foreach ($selection['checked'] as $pos)
52{
53  drawcross($img, $pos, $conf['EasyCaptcha']['tictac']['obj']);
54}
55imagedestroy($img_cross);
56drawcross($img, $selection['answer'], $conf['EasyCaptcha']['tictac']['sel']);
57
58// circles
59$protect = $selection['checked'];
60$protect[] = $selection['answer'];
61$i = rand(2,4);
62$circles = array();
63
64while ($i>0)
65{
66  $pos = array(rand(0, 2), rand(0, 2));
67
68  foreach ($protect as $pro)
69  {
70    if ($pos[0]==$pro[0] && $pos[1]==$pro[1]) continue(2);
71  }
72  if (checkline($pos, $circles)) continue;
73
74  $protect[] = $pos;
75  $circles[$pos[0]][$pos[1]] = true;
76
77  drawcircle($img, $pos, $conf['EasyCaptcha']['tictac']['obj']);
78  $i--;
79}
80
81
82// output
83header('Content-Type: image/png');
84imagepng($img);
Note: See TracBrowser for help on using the repository browser.