Loading Please wait...

zCaptcha Class Reference
[Captcha Validation Images]

zCaptcha generates Captcha Images Dynamically Requires GD Librery To be Installed Its Meant to be Called from a Controller More...

Inheritance diagram for zCaptcha:

Inheritance graph
[legend]
Collaboration diagram for zCaptcha:

Collaboration graph
[legend]

Public Member Functions

 captcha (&$controller, $len=null)
 Supply the Controller Object and Length(optional) of the captcha Image e.g.
 putText ()
 makeImg ($length)
 output ()
 Outputs the image as image/png.
 strSep ($str, $id=-100)

Data Fields

 $canvas
 $baseColor
 $store = array()
 $setup
 $fonts
 $orgStr
 $controller

Detailed Description

zCaptcha generates Captcha Images Dynamically Requires GD Librery To be Installed Its Meant to be Called from a Controller

Definition at line 30 of file captcha.php.


Member Function Documentation

zCaptcha::captcha ( &$  controller,
len = null 
)

Supply the Controller Object and Length(optional) of the captcha Image e.g.

use new zCaptcha($this) in the controller to initialize

Parameters:
$controller zigControiller&
$len int

Definition at line 46 of file captcha.php.

References $controller, $val, zDef::get(), makeImg(), zDef::set(), and zSession::start().

00046                                              {
00047     $this->controller = $controller;
00048     $deff = parse_ini_file(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.ZIGSETTINGSDIR.DRS.'captcha.ini.php', true);
00049     foreach($deff['sys'] as $key => $val){
00050       if(eregi('^on$', $val))$val = true;
00051       if(eregi('^off$', $val))$val = false;
00052       zDef::set($key, $val);
00053     }
00054     if($len == null)$len = zDef::get('Z_CAPTCHA_LENGTH');//Using the default Length
00055     if(zDef::get('Z_CAPTCHA_USE_EXCLUSIVE_FONT'))$this->fonts = array_keys($deff['fonts']);//Gathering the Fonts
00056     //Prepare the basic canvas
00057     $this->canvas = imagecreate(zDef::get('Z_CAPTCHA_HEIGHT'), zDef::get('Z_CAPTCHA_WIDTH'));
00058     $_tmp_col = explode(',',zDef::get('Z_CAPTCHA_BASE_COLOR'));
00059     $this->baseColor = imagecolorallocate($this->canvas, (int)trim($_tmp_col[0]), (int)trim($_tmp_col[1]), (int)trim($_tmp_col[2]));
00060     if(eregi('on', zDef::get('Z_CAPTCHA_TRANSPARENT'))){
00061       $tmp_trans = imagecolorexact($this->canvas, (int)trim($_tmp_col[0]), (int)trim($_tmp_col[1]), (int)trim($_tmp_col[2]));
00062       imagecolortransparent($this->canvas, $tmp_trans);
00063     }
00064     //}
00065     $this->makeImg($len);
00066     zSession::start();//Start the session
00067   }

Here is the call graph for this function:

zCaptcha::putText (  ) 

For internal use only.

Definition at line 71 of file captcha.php.

References zDef::get(), and strSep().

Referenced by makeImg().

00071                     {
00072     if(count($this->store) > 0){
00073       $next = max($this->store)+zDef::get('Z_CAPTCHA_TEXT_GAP');
00074     }else{
00075       $next = zDef::get('Z_CAPTCHA_TEXT_X_START');
00076     }
00077     $rand = rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_CHAR_RANGE'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_CHAR_RANGE'), 1));
00078     if(zDef::get('Z_CAPTCHA_USE_EXCLUSIVE_FONT')){
00079       $currentFont = ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_FONT.DRS.$this->fonts[rand(0, count($this->fonts)-1)];
00080       imagefttext($this->canvas,
00081                     rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_SIZE_RANGE'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_SIZE_RANGE'), 1)),
00082                     rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_ANGLE_RANGE'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_ANGLE_RANGE'), 1)),
00083                     $next,
00084                     rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_Y_RANGE'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_Y_RANGE'), 1)),
00085                     imagecolorallocate($this->canvas,
00086                                         rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_RED'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_RED'), 1)),
00087                                         rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_GRN'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_GRN'), 1)),
00088                                         rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_BLU'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_BLU'), 1))
00089                                       ),
00090                     $currentFont,
00091                     chr($rand)
00092                   );
00093     }else{
00094       imagechar($this->canvas,
00095                   zDef::get('Z_CAPTCHA_PLAIN_TEXT_SIZE'),
00096                   $next,
00097                   rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_Y_RANGE'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_Y_RANGE'), 1)),
00098                   chr($rand),
00099                   imagecolorallocate($this->canvas,
00100                                       rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_RED'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_RED'), 1)),
00101                                       rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_GRN'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_GRN'), 1)),
00102                                       rand($this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_BLU'), 0), $this->strSep(zDef::get('Z_CAPTCHA_TEXT_COL_RANGE_BLU'), 1))
00103                                     )
00104                 );
00105     }
00106     $this->store[] = $next;
00107     $this->orgStr .= chr($rand);
00108   }

Here is the call graph for this function:

zCaptcha::makeImg ( length  ) 

For internal use only.

Definition at line 112 of file captcha.php.

References putText().

Referenced by captcha().

00112                            {
00113     for($i=0;$i<=$length-1;$i++){
00114       $this->putText();
00115     }
00116   }

Here is the call graph for this function:

zCaptcha::output (  ) 

Outputs the image as image/png.

Call This Method Finall to show the Image

$captchaObj = new zCaptcha($this);
 $captchaObj->output();
Stores the String in the Captcha Object in a Session variable $_SESSION['gd_str']

Definition at line 125 of file captcha.php.

00125                    {
00126     $this->controller->noAutoViewRender();
00127     $this->controller->noLayout();
00128     $this->controller->setContentType('image/png');
00129     imagepng($this->canvas);
00130     imagedestroy($this->canvas);
00131     $_SESSION['gd_str'] = $this->orgStr;
00132   }

zCaptcha::strSep ( str,
id = -100 
)

For internal use only.

Definition at line 136 of file captcha.php.

Referenced by putText().

00136                                    {
00137     foreach(explode(',', $str) as $k => $v){
00138       $ret[$k] = trim($v);
00139     }
00140     if($id == -100){
00141       return $ret;
00142     }else{
00143       return $ret[$id];
00144     }
00145   }


Field Documentation

zCaptcha::$canvas

Definition at line 31 of file captcha.php.

zCaptcha::$baseColor

Definition at line 32 of file captcha.php.

zCaptcha::$store = array()

Definition at line 33 of file captcha.php.

zCaptcha::$setup

Definition at line 34 of file captcha.php.

zCaptcha::$fonts

Definition at line 35 of file captcha.php.

zCaptcha::$orgStr

Definition at line 36 of file captcha.php.

zCaptcha::$controller

Definition at line 37 of file captcha.php.

Referenced by captcha().


The documentation for this class was generated from the following file:

Generated on Mon Oct 27 23:53:21 2008 for zigmoyd.kdevelop by doxygen 1.5.6