Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * ucaptchaPluginDataProvider supposed to be replaced by class interacting with database
- */
- class ucaptchaPluginDataProvider{
- private $QUESTIONS;
- public function __construct(){
- $this->QUESTIONS = array(
- array('question'=>'Что такое curses?','answer'=>'какая-то библа для консоли','wrong_answers'=>array('проклятия и ругательства','навигационный термин','этого нет в линупсе','политическая программа',)),
- array('question'=>'GNU - это:','answer'=>'лицензионные ограничения','wrong_answers'=>array('бесплатно','антилопа','делай что хочешь',)),
- array('question'=>'Что такое folder?','answer'=>'этого в моей системе нет','wrong_answers'=>array('в нём файлы на диске','папка или скоросшиватель','фальцевальная машина',)),
- array('question'=>'nice - это:','answer'=>'установка приоритета','wrong_answers'=>array('миленькая программка','нечто изысканное','Windows','как секс')),
- array('question'=>'"ksh" ассоциируется с:','answer'=>'корном','wrong_answers'=>array('изгнанием кота','шипением воды','шелестом листвы','приложением Windows')),
- array('question'=>'Что такое chmod?','answer'=>'выставляет права доступа','wrong_answers'=>array('Демон-чмошник','этого в моей системе нет','модифицирует символы',)),
- // array('question'=>'','answer'=>'','wrong_answers'=>array('','','',)),
- );
- }
- public function getQuestion(){
- return $this->QUESTIONS[rand(0,count($this->QUESTIONS)-1)];
- }
- }
- /**
- * linux_mind plugin itself
- */
- class linux_mind
- {
- private $iHeight;
- private $iWidth;
- private $provider;
- private $canvas;
- function print_question($str,$color,$size=9){
- global $captcha_font_path,$captcha_img_path;
- $dx=2;
- for ($i=0;$i<mb_strlen($str,'utf-8');$i++){
- $s=mb_substr($str,$i,1,'utf-8');
- $a=imagefttext($this->canvas, $size, rand (-5,5), $dx, $size*1.5+rand(-1,1), $color, $captcha_font_path."/LiberationSans-Bold.ttf", $s);
- $dx = max($a[2],$a[4])+1;
- }
- }
- function print_answer($str,$Y,$color,$size){
- global $captcha_font_path,$captcha_img_path;
- $dx=4;
- $dy=$Y;
- for ($i=0;$i<mb_strlen($str,'utf-8');$i++){
- $s=mb_substr($str,$i,1,'utf-8');
- $a=imagefttext($this->canvas, $size, 0, $dx+rand(0,2), $Y+rand(0,1), $color, $captcha_font_path."/DejaVuLGCSans.ttf", $s);
- $dx = max($a[2],$a[4])+1;
- }
- return $dy;
- }
- function generate_image($canvas)
- {
- global $captcha_font_path,$captcha_img_path;
- $this->canvas=$canvas;
- $this->provider=new ucaptchaPluginDataProvider();
- $this->iHeight=imagesy($canvas);
- $this->iWidth=imagesx($canvas);
- $r=rand(0,99999);
- $captcha = array();
- $captcha[1]=sprintf('%05d',$r);
- $bgColor = imagecolorallocate($canvas, 0x00+rand(0,8),0x66+rand(0,8),0x00+rand(0,8));
- $titleColor = imagecolorallocate($canvas, 0x66+rand(-32,8),0xf7+rand(-8,8),0x33+rand(-16,8));
- $answerColor = imagecolorallocate($canvas, 0x33+rand(0,16),0xcc+rand(0,16),0x00+rand(0,8));
- imagefill($canvas,0,0,$bgColor);
- if(isset($_SERVER['HTTP_USER_AGENT'])&&preg_match('/Windows/',$_SERVER['HTTP_USER_AGENT'])){
- $this->print_question('Вендузятнег детектед!',$titleColor, 8);
- }else{
- $question=$this->provider->getQuestion();
- $qAnswers=array($captcha[1].' - '.$question{'answer'});
- for($i=0;$i<count($question{'wrong_answers'}); $i++) $qAnswers[] = sprintf('%05d - %s',rand(0,99999),$question{'wrong_answers'}[$i]);
- shuffle($qAnswers);
- $y=24;
- for($i=0;$i<count($qAnswers); $i++){
- $this->print_answer($qAnswers[$i],$y,$answerColor,7);
- $y+=10;
- };
- $this->print_question($question{'question'},$titleColor, 8);
- // Show answer for debugging:
- // imagefttext($this->canvas, 10, 0, $this->iWidth-50, $this->iHeight-18, $titleColor, $captcha_font_path."/DejaVuLGCSans.ttf", $captcha[1]);
- }
- $nme=$this->ucaptcha->get_filename();
- imagepng($canvas);
- $captcha[0]=$nme;
- // $captcha[1]=$rand;
- return $captcha;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement