Completed
Push — develop ( 75b835...a38a21 )
by Maxim
09:33 queued 04:23
created
manager/includes/veriword.php 2 patches
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 $modx->getSettings();
6 6
 $modx->invokeEvent('OnWebPageInit');
7 7
 
8
-$vword = new VeriWord(148,60);
8
+$vword = new VeriWord(148, 60);
9 9
 $vword->output_image();
10 10
 $vword->destroy_image();
11 11
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 ## see sample.php for test and usage
42 42
 ## sample URL: http://www.program-ruti.org/veriword/
43 43
 ####
44
-class VeriWord {
44
+class VeriWord{
45 45
 
46 46
     /* path to font directory*/
47 47
     public $dir_font   = "ttf/";
@@ -51,44 +51,44 @@  discard block
 block discarded – undo
51 51
     public $im_width   = 0;
52 52
     public $im_height  = 0;
53 53
 
54
-    public function __construct($w=200, $h=80) {
54
+    public function __construct($w = 200, $h = 80){
55 55
         /* create session to set word for verification */
56 56
         $this->set_veriword();
57
-        $this->dir_font = dirname(__FILE__) . '/' . $this->dir_font;
57
+        $this->dir_font = dirname(__FILE__).'/'.$this->dir_font;
58 58
         $this->im_width         = $w;
59 59
         $this->im_height        = $h;
60 60
     }
61 61
 
62
-    public function set_veriword() {
62
+    public function set_veriword(){
63 63
         /* create session variable for verification,
64 64
            you may change the session variable name */
65 65
         $this->word             = $this->pick_word();
66 66
         $_SESSION['veriword']   = $this->word;
67 67
     }
68 68
 
69
-    public function output_image() {
69
+    public function output_image(){
70 70
         /* output the image as jpeg */
71 71
         $this->draw_image();
72 72
         header("Content-type: image/jpeg");
73 73
         imagejpeg($this->im);
74 74
     }
75 75
 
76
-    public function pick_word() {
76
+    public function pick_word(){
77 77
         global $modx;
78 78
         // set default words
79
-        $words="MODX,Access,Better,BitCode,Chunk,Cache,Desc,Design,Excell,Enjoy,URLs,TechView,Gerald,Griff,Humphrey,Holiday,Intel,Integration,Joystick,Join(),Oscope,Genetic,Light,Likeness,Marit,Maaike,Niche,Netherlands,Ordinance,Oscillo,Parser,Phusion,Query,Question,Regalia,Righteous,Snippet,Sentinel,Template,Thespian,Unity,Enterprise,Verily,Veri,Website,WideWeb,Yap,Yellow,Zebra,Zygote";
79
+        $words = "MODX,Access,Better,BitCode,Chunk,Cache,Desc,Design,Excell,Enjoy,URLs,TechView,Gerald,Griff,Humphrey,Holiday,Intel,Integration,Joystick,Join(),Oscope,Genetic,Light,Likeness,Marit,Maaike,Niche,Netherlands,Ordinance,Oscillo,Parser,Phusion,Query,Question,Regalia,Righteous,Snippet,Sentinel,Template,Thespian,Unity,Enterprise,Verily,Veri,Website,WideWeb,Yap,Yellow,Zebra,Zygote";
80 80
         $words = $modx->config['captcha_words'] ? $modx->config['captcha_words'] : $words;
81 81
         $arr_words = array_filter(array_map('trim', explode(',', $words)));
82 82
 
83 83
         /* pick one randomly for text verification */
84
-        return (string) $arr_words[array_rand($arr_words)].rand(10,999);
84
+        return (string) $arr_words[array_rand($arr_words)].rand(10, 999);
85 85
     }
86 86
 
87
-    public function draw_text() {
87
+    public function draw_text(){
88 88
         $dir = dir($this->dir_font);
89 89
         $fontstmp = array();
90 90
         while (false !== ($file = $dir->read())) {
91
-            if(substr($file, -4) == '.ttf') {
91
+            if (substr($file, -4) == '.ttf') {
92 92
                 $fontstmp[] = $this->dir_font.$file;
93 93
             }
94 94
         }
@@ -96,35 +96,35 @@  discard block
 block discarded – undo
96 96
         $text_font = (string) $fontstmp[array_rand($fontstmp)];
97 97
 
98 98
         /* angle for text inclination */
99
-        $text_angle = rand(-9,9);
99
+        $text_angle = rand(-9, 9);
100 100
         /* initial text size */
101 101
         $text_size  = 30;
102 102
         /* calculate text width and height */
103
-        $box        = imagettfbbox ( $text_size, $text_angle, $text_font, $this->word);
104
-        $text_width = $box[2]-$box[0]; //text width
105
-        $text_height= $box[5]-$box[3]; //text height
103
+        $box        = imagettfbbox($text_size, $text_angle, $text_font, $this->word);
104
+        $text_width = $box[2] - $box[0]; //text width
105
+        $text_height = $box[5] - $box[3]; //text height
106 106
 
107 107
         /* adjust text size */
108
-        $text_size  = round((20 * $this->im_width)/$text_width);
108
+        $text_size  = round((20 * $this->im_width) / $text_width);
109 109
 
110 110
         /* recalculate text width and height */
111
-        $box        = imagettfbbox ( $text_size, $text_angle, $text_font, $this->word);
112
-        $text_width = $box[2]-$box[0]; //text width
113
-        $text_height= $box[5]-$box[3]; //text height
111
+        $box        = imagettfbbox($text_size, $text_angle, $text_font, $this->word);
112
+        $text_width = $box[2] - $box[0]; //text width
113
+        $text_height = $box[5] - $box[3]; //text height
114 114
 
115 115
         /* calculate center position of text */
116
-        $text_x         = ($this->im_width - $text_width)/2;
117
-        $text_y         = ($this->im_height - $text_height)/2;
116
+        $text_x         = ($this->im_width - $text_width) / 2;
117
+        $text_y         = ($this->im_height - $text_height) / 2;
118 118
 
119 119
         /* create canvas for text drawing */
120
-        $im_text        = imagecreate ($this->im_width, $this->im_height);
121
-        $bg_color       = imagecolorallocate ($im_text, 255, 255, 255);
120
+        $im_text        = imagecreate($this->im_width, $this->im_height);
121
+        $bg_color       = imagecolorallocate($im_text, 255, 255, 255);
122 122
 
123 123
         /* pick color for text */
124
-        $text_color     = imagecolorallocate ($im_text, 0, 51, 153);
124
+        $text_color     = imagecolorallocate($im_text, 0, 51, 153);
125 125
 
126 126
         /* draw text into canvas */
127
-        imagettftext    (   $im_text,
127
+        imagettftext($im_text,
128 128
                             $text_size,
129 129
                             $text_angle,
130 130
                             $text_x,
@@ -139,19 +139,19 @@  discard block
 block discarded – undo
139 139
     }
140 140
 
141 141
 
142
-    public function draw_image() {
142
+    public function draw_image(){
143 143
 
144 144
         /* pick one background image randomly from image directory */
145
-        $img_file       = $this->dir_noise."noise".rand(1,4).".jpg";
145
+        $img_file       = $this->dir_noise."noise".rand(1, 4).".jpg";
146 146
 
147 147
         /* create "noise" background image from your image stock*/
148
-        $noise_img      = @imagecreatefromjpeg ($img_file);
148
+        $noise_img      = @imagecreatefromjpeg($img_file);
149 149
         $noise_width    = imagesx($noise_img);
150 150
         $noise_height   = imagesy($noise_img);
151 151
 
152 152
         /* resize the background image to fit the size of image output */
153
-        $this->im       = imagecreatetruecolor($this->im_width,$this->im_height);
154
-        imagecopyresampled ($this->im,
153
+        $this->im       = imagecreatetruecolor($this->im_width, $this->im_height);
154
+        imagecopyresampled($this->im,
155 155
                             $noise_img,
156 156
                             0, 0, 0, 0,
157 157
                             $this->im_width,
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
                             $noise_height);
161 161
 
162 162
         /* put text image into background image */
163
-        imagecopymerge (    $this->im,
163
+        imagecopymerge($this->im,
164 164
                             $this->draw_text(),
165 165
                             0, 0, 0, 0,
166 166
                             $this->im_width,
167 167
                             $this->im_height,
168
-                            70 );
168
+                            70);
169 169
 
170 170
         return $this->im;
171 171
     }
172 172
 
173
-    public function destroy_image() {
173
+    public function destroy_image(){
174 174
 
175 175
         imagedestroy($this->im);
176 176
 
Please login to merge, or discard this patch.
Braces   +16 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,7 +41,8 @@  discard block
 block discarded – undo
41 41
 ## see sample.php for test and usage
42 42
 ## sample URL: http://www.program-ruti.org/veriword/
43 43
 ####
44
-class VeriWord {
44
+class VeriWord
45
+{
45 46
 
46 47
     /* path to font directory*/
47 48
     public $dir_font   = "ttf/";
@@ -51,7 +52,8 @@  discard block
 block discarded – undo
51 52
     public $im_width   = 0;
52 53
     public $im_height  = 0;
53 54
 
54
-    public function __construct($w=200, $h=80) {
55
+    public function __construct($w=200, $h=80)
56
+    {
55 57
         /* create session to set word for verification */
56 58
         $this->set_veriword();
57 59
         $this->dir_font = dirname(__FILE__) . '/' . $this->dir_font;
@@ -59,21 +61,24 @@  discard block
 block discarded – undo
59 61
         $this->im_height        = $h;
60 62
     }
61 63
 
62
-    public function set_veriword() {
64
+    public function set_veriword()
65
+    {
63 66
         /* create session variable for verification,
64 67
            you may change the session variable name */
65 68
         $this->word             = $this->pick_word();
66 69
         $_SESSION['veriword']   = $this->word;
67 70
     }
68 71
 
69
-    public function output_image() {
72
+    public function output_image()
73
+    {
70 74
         /* output the image as jpeg */
71 75
         $this->draw_image();
72 76
         header("Content-type: image/jpeg");
73 77
         imagejpeg($this->im);
74 78
     }
75 79
 
76
-    public function pick_word() {
80
+    public function pick_word()
81
+    {
77 82
         global $modx;
78 83
         // set default words
79 84
         $words="MODX,Access,Better,BitCode,Chunk,Cache,Desc,Design,Excell,Enjoy,URLs,TechView,Gerald,Griff,Humphrey,Holiday,Intel,Integration,Joystick,Join(),Oscope,Genetic,Light,Likeness,Marit,Maaike,Niche,Netherlands,Ordinance,Oscillo,Parser,Phusion,Query,Question,Regalia,Righteous,Snippet,Sentinel,Template,Thespian,Unity,Enterprise,Verily,Veri,Website,WideWeb,Yap,Yellow,Zebra,Zygote";
@@ -84,7 +89,8 @@  discard block
 block discarded – undo
84 89
         return (string) $arr_words[array_rand($arr_words)].rand(10,999);
85 90
     }
86 91
 
87
-    public function draw_text() {
92
+    public function draw_text()
93
+    {
88 94
         $dir = dir($this->dir_font);
89 95
         $fontstmp = array();
90 96
         while (false !== ($file = $dir->read())) {
@@ -139,7 +145,8 @@  discard block
 block discarded – undo
139 145
     }
140 146
 
141 147
 
142
-    public function draw_image() {
148
+    public function draw_image()
149
+    {
143 150
 
144 151
         /* pick one background image randomly from image directory */
145 152
         $img_file       = $this->dir_noise."noise".rand(1,4).".jpg";
@@ -170,7 +177,8 @@  discard block
 block discarded – undo
170 177
         return $this->im;
171 178
     }
172 179
 
173
-    public function destroy_image() {
180
+    public function destroy_image()
181
+    {
174 182
 
175 183
         imagedestroy($this->im);
176 184
 
Please login to merge, or discard this patch.