예제 #1
0
 /**
 		Generate CAPTCHA image
 			@param $_dimx integer
 			@param $_dimy integer
 			@param $_len integer
 			@param $_ttfs string
 			@public
 	**/
 public static function captcha($_dimx, $_dimy, $_len, $_ttfs = 'cube')
 {
     $_base = self::rgb(F3::$global['BGCOLOR']);
     $_trans = F3::$global['FGTRANS'];
     // Specify Captcha seed
     if (!strlen(session_id())) {
         session_start();
     }
     $_SESSION['captcha'] = substr(md5(uniqid()), 0, $_len);
     F3::$global['SESSION'] =& $_SESSION;
     // Font size
     $_size = min($_dimx / $_len, 0.6 * $_dimy);
     // Load TrueType font file
     $_fonts = explode('|', $_ttfs);
     $_file = F3::$global['FONTS'] . F3::fixSlashes($_fonts[mt_rand(0, count($_fonts) - 1)]) . '.ttf';
     F3::$global['PROFILE']['FILES']['fonts'][basename($_file)] = filesize($_file);
     $_maxdeg = 15;
     // Compute bounding box metrics
     $_bbox = imagettfbbox($_size, $_angle, $_file, $_SESSION['captcha']);
     $_wimage = 0.9 * (max($_bbox[2], $_bbox[4]) - max($_bbox[0], $_bbox[6]));
     $_himage = max($_bbox[1], $_bbox[3]) - max($_bbox[5], $_bbox[7]);
     // Create blank image
     $_captcha = imagecreatetruecolor($_dimx, $_dimy);
     list($_r, $_g, $_b) = $_base;
     $_bg = imagecolorallocate($_captcha, $_r, $_g, $_b);
     imagefill($_captcha, 0, 0, $_bg);
     $_width = 0;
     // Insert each Captcha character
     for ($_i = 0; $_i < $_len; $_i++) {
         // Random angle
         $_angle = $_maxdeg - mt_rand(0, $_maxdeg * 2);
         // Get CAPTCHA character from session cookie
         $_char = $_SESSION['captcha'][$_i];
         $_fg = imagecolorallocatealpha($_captcha, mt_rand(0, 255 - $_trans), mt_rand(0, 255 - $_trans), mt_rand(0, 255 - $_trans), $_trans);
         imagettftext($_captcha, $_size, $_angle, ($_dimx - $_wimage) / 2 + $_i * $_wimage / $_len, ($_dimy - $_himage) / 2 + 0.9 * $_himage, $_fg, $_file, $_char);
         imagecolordeallocate($_captcha, $_fg);
     }
     // Make the background transparent
     imagecolortransparent($_captcha, $_bg);
     // Send output as PNG image
     if (PHP_SAPI != 'cli' && !headers_sent()) {
         header(F3::HTTP_Content . ': image/png');
     }
     imagepng($_captcha, NULL, self::PNG_Compress, PNG_NO_FILTER);
     // Free resources
     imagedestroy($_captcha);
 }
예제 #2
0
파일: log.php 프로젝트: seyyah/f3kayOLD
 /**
 		Write specified text to log file
 			@param $_text string
 			@public
 	**/
 public function write($_text)
 {
     if (!self::ready()) {
         // Lock attempt failed
         trigger_error(self::TEXT_LogLock);
         return;
     }
     $_path = F3::$global['LOGS'];
     clearstatcache();
     if (filesize($_path . $this->filename) > F3::bytes(self::LOG_Size)) {
         // Perform log rotation sequence
         if (file_exists($_path . $this->filename . '.1')) {
             copy($_path . $this->filename . '.1', $_path . $this->filename . '.2');
         }
         copy($_path . $this->filename, $_path . $this->filename . '.1');
         ftruncate($this->handle, 0);
     }
     // Prepend text with timestamp, source IP, file name and
     // line number for tracking origin
     $_trace = debug_backtrace(FALSE);
     fwrite($this->handle, date('r') . ' [' . $_SERVER['REMOTE_ADDR'] . '] ' . F3::fixSlashes($_trace[0]['file']) . ':' . $_trace[0]['line'] . ' ' . preg_replace('/\\s+/', ' ', $_text) . "\n");
     flock($this->handle, LOCK_UN);
 }