1: | <?php
2: | namespace Opencart\Catalog\Controller\Extension\Opencart\Captcha;
3: | /**
4: | * Class Basic
5: | *
6: | * @package Opencart\Catalog\Controller\Extension\Opencart\Captcha
7: | */
8: | class Basic extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return string
13: | */
14: | public function index(): string {
15: | $this->load->language('extension/opencart/captcha/basic');
16: |
17: | $data['route'] = (string)$this->request->get['route'];
18: |
19: | $this->session->data['captcha'] = substr(oc_token(100), mt_rand(0, 94), 6);
20: |
21: | return $this->load->view('extension/opencart/captcha/basic', $data);
22: | }
23: |
24: | /**
25: | * Validate
26: | *
27: | * @return string
28: | */
29: | public function validate(): string {
30: | $this->load->language('extension/opencart/captcha/basic');
31: |
32: | if (!isset($this->session->data['captcha']) || !isset($this->request->post['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
33: | return $this->language->get('error_captcha');
34: | } else {
35: | return '';
36: | }
37: | }
38: |
39: | /**
40: | * Captcha
41: | *
42: | * @return void
43: | */
44: | public function captcha(): void {
45: | $image = imagecreatetruecolor(150, 35);
46: |
47: | $width = imagesx($image);
48: | $height = imagesy($image);
49: |
50: | $black = imagecolorallocate($image, 0, 0, 0);
51: | $white = imagecolorallocate($image, 255, 255, 255);
52: | $red = imagecolorallocatealpha($image, 255, 0, 0, 75);
53: | $green = imagecolorallocatealpha($image, 0, 255, 0, 75);
54: | $blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
55: |
56: | imagefilledrectangle($image, 0, 0, $width, $height, $white);
57: | imagefilledellipse($image, mt_rand(5, 145), mt_rand(0, 35), 30, 30, $red);
58: | imagefilledellipse($image, mt_rand(5, 145), mt_rand(0, 35), 30, 30, $green);
59: | imagefilledellipse($image, mt_rand(5, 145), mt_rand(0, 35), 30, 30, $blue);
60: | imagefilledrectangle($image, 0, 0, $width, 0, $black);
61: | imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
62: | imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
63: | imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
64: |
65: | imagestring($image, 10, (int)(($width - (strlen($this->session->data['captcha']) * 9)) / 2), (int)(($height - 15) / 2), $this->session->data['captcha'], $black);
66: |
67: | header('Content-type: image/jpeg');
68: | header('Cache-Control: no-cache');
69: | header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
70: |
71: | imagejpeg($image);
72: |
73: | imagedestroy($image);
74: | exit();
75: | }
76: | }
77: |

OpenCart API API documentation generated by ApiGen dev-master