Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.53 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * ucaptchaPluginDataProvider supposed to be replaced by class interacting with database
  5.  */
  6.  
  7. class ucaptchaPluginDataProvider{
  8.     private $QUESTIONS;
  9.     public function __construct(){
  10.       $this->QUESTIONS = array(
  11.       array('question'=>'Что такое curses?','answer'=>'какая-то библа для консоли','wrong_answers'=>array('проклятия и ругательства','навигационный термин','этого нет в линупсе','политическая программа',)),
  12.       array('question'=>'GNU - это:','answer'=>'лицензионные ограничения','wrong_answers'=>array('бесплатно','антилопа','делай что хочешь',)),
  13.       array('question'=>'Что такое folder?','answer'=>'этого в моей системе нет','wrong_answers'=>array('в нём файлы на диске','папка или скоросшиватель','фальцевальная машина',)),
  14.           array('question'=>'nice - это:','answer'=>'установка приоритета','wrong_answers'=>array('миленькая программка','нечто изысканное','Windows','как секс')),
  15.           array('question'=>'"ksh" ассоциируется с:','answer'=>'корном','wrong_answers'=>array('изгнанием кота','шипением воды','шелестом листвы','приложением Windows')),
  16.       array('question'=>'Что такое chmod?','answer'=>'выставляет права доступа','wrong_answers'=>array('Демон-чмошник','этого в моей системе нет','модифицирует символы',)),
  17. //        array('question'=>'','answer'=>'','wrong_answers'=>array('','','',)),
  18.       );
  19.     }
  20.     public function getQuestion(){
  21.         return  $this->QUESTIONS[rand(0,count($this->QUESTIONS)-1)];
  22.     }
  23. }
  24.  
  25. /**
  26.  * linux_mind plugin itself
  27.  */
  28.  
  29. class linux_mind
  30. {
  31.  
  32.     private $iHeight;
  33.     private $iWidth;
  34.     private $provider;
  35.     private $canvas;
  36.  
  37.  function print_question($str,$color,$size=9){
  38.      global $captcha_font_path,$captcha_img_path;
  39.      $dx=2;
  40.      for ($i=0;$i<mb_strlen($str,'utf-8');$i++){
  41.     $s=mb_substr($str,$i,1,'utf-8');
  42.         $a=imagefttext($this->canvas, $size, rand (-5,5), $dx, $size*1.5+rand(-1,1), $color,  $captcha_font_path."/LiberationSans-Bold.ttf", $s);
  43.         $dx = max($a[2],$a[4])+1;
  44.      }
  45.  }
  46.  function print_answer($str,$Y,$color,$size){
  47.      global $captcha_font_path,$captcha_img_path;
  48.      $dx=4;
  49.      $dy=$Y;
  50.      for ($i=0;$i<mb_strlen($str,'utf-8');$i++){
  51.     $s=mb_substr($str,$i,1,'utf-8');
  52.         $a=imagefttext($this->canvas, $size, 0, $dx+rand(0,2), $Y+rand(0,1), $color,  $captcha_font_path."/DejaVuLGCSans.ttf", $s);
  53.         $dx = max($a[2],$a[4])+1;
  54.      }
  55.      return $dy;
  56.  }
  57.  
  58.  function generate_image($canvas)
  59.     {
  60.       global $captcha_font_path,$captcha_img_path;
  61.  
  62.       $this->canvas=$canvas;
  63.       $this->provider=new ucaptchaPluginDataProvider();
  64.       $this->iHeight=imagesy($canvas);
  65.       $this->iWidth=imagesx($canvas);
  66.  
  67.       $r=rand(0,99999);
  68.       $captcha = array();
  69.       $captcha[1]=sprintf('%05d',$r);
  70.  
  71.       $bgColor     = imagecolorallocate($canvas, 0x00+rand(0,8),0x66+rand(0,8),0x00+rand(0,8));
  72.       $titleColor  = imagecolorallocate($canvas, 0x66+rand(-32,8),0xf7+rand(-8,8),0x33+rand(-16,8));
  73.       $answerColor = imagecolorallocate($canvas, 0x33+rand(0,16),0xcc+rand(0,16),0x00+rand(0,8));
  74.  
  75.       imagefill($canvas,0,0,$bgColor);
  76.       if(isset($_SERVER['HTTP_USER_AGENT'])&&preg_match('/Windows/',$_SERVER['HTTP_USER_AGENT'])){
  77.       $this->print_question('Вендузятнег детектед!',$titleColor, 8);
  78.       }else{
  79.  
  80.       $question=$this->provider->getQuestion();
  81.       $qAnswers=array($captcha[1].' - '.$question{'answer'});
  82.       for($i=0;$i<count($question{'wrong_answers'}); $i++) $qAnswers[] = sprintf('%05d - %s',rand(0,99999),$question{'wrong_answers'}[$i]);
  83.       shuffle($qAnswers);
  84.       $y=24;
  85.       for($i=0;$i<count($qAnswers); $i++){
  86.         $this->print_answer($qAnswers[$i],$y,$answerColor,7);
  87.         $y+=10;
  88.       };
  89.       $this->print_question($question{'question'},$titleColor, 8);
  90.      
  91.       // Show answer for debugging:
  92.       // imagefttext($this->canvas, 10, 0, $this->iWidth-50, $this->iHeight-18, $titleColor,  $captcha_font_path."/DejaVuLGCSans.ttf", $captcha[1]);
  93.       }
  94.       $nme=$this->ucaptcha->get_filename();
  95.       imagepng($canvas);
  96.       $captcha[0]=$nme;
  97.  
  98.  
  99. //      $captcha[1]=$rand;
  100.       return $captcha;
  101.     }
  102. }
  103. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement