예제 #1
0
 private function initDatabase()
 {
     $configFilePath = PathBuilder::getInstance()->buildAbsolutePath(Constants::CONFIG_DIR, Constants::CONFIG_FILE_DB);
     $configLoader = new DbConfigLoader();
     try {
         $this->dbConnector = $configLoader->makeConnectorFromFile($configFilePath);
     } catch (Exception $e) {
         throw new Exception('Error while loading database configuration: ' . $e->getMessage());
     }
 }
예제 #2
0
 public static function loadClass($className)
 {
     if (class_exists($className, false) || interface_exists($className, false)) {
         return;
     }
     $fileName = $className . '.php';
     @(include PathBuilder::getInstance()->buildAbsolutePath(Constants::CLASSES_DIR, $fileName));
     // Hack to to be able to throw an exception instead of an E_ERROR.
     // (see: http://www.phpbar.de/w/autoload() );
     if (!class_exists($className, false) && !interface_exists($className, false)) {
         eval('class ' . $className . ' {' . '	public function __construct() {' . '		throw new Exception( "Class not found: ' . $className . '" );' . '	}' . '}');
     }
 }
 public function writeOutput()
 {
     if ($this->isFault()) {
         error_log('Error while handling captcha image request: ' . $this->faultString . ' (' . $this->faultCode . ')');
         header('HTTP/1.1 500 Internal Server Error');
         die('500 Internal Server Error');
     }
     $outputWidth = 150;
     $outputHeight = 40;
     $maxRotation = 30;
     $minSize = 15;
     $maxSize = 25;
     $backgroundCharCount = 45;
     $font = PathBuilder::getInstance()->buildAbsolutePath(Constants::ASSET_DIR, Constants::CAPTCHA_FONT);
     $image = imagecreatetruecolor($outputWidth, $outputHeight);
     $backColor = imagecolorallocate($image, $this->randInt(224, 255), $this->randInt(244, 255), $this->randInt(224, 255));
     imagefilledrectangle($image, 0, 0, $outputWidth, $outputHeight, $backColor);
     for ($i = 0; $i < $backgroundCharCount; ++$i) {
         $size = $this->randInt($minSize / 2.3, $maxSize / 1.7);
         $angle = $this->randInt(0, 359);
         $x = $this->randInt(0, $outputWidth);
         $y = $this->randInt(0, $outputHeight - $size / 5);
         $color = imagecolorallocate($image, $this->randInt(120, 224), $this->randInt(120, 224), $this->randInt(120, 224));
         $char = chr($this->randInt(33, 126));
         imagettftext($image, $size, $angle, $x, $y, $color, $font, $char);
     }
     $x = $this->randInt($minSize * 0.7, $maxSize * 0.7);
     for ($i = 0; $i < strlen($this->returnValue->getValue()); ++$i) {
         $char = substr($this->returnValue->getValue(), $i, 1);
         $angle = $this->randInt(-$maxRotation, $maxRotation);
         $size = $this->randInt($minSize, $maxSize);
         $y = $this->randInt($size, $outputHeight - $size / 7);
         $color = imagecolorallocate($image, $this->randInt(0, 127), $this->randInt(0, 127), $this->randInt(0, 127));
         $shadow = imagecolorallocate($image, $this->randInt(127, 255), $this->randInt(127, 255), $this->randInt(127, 255));
         imagettftext($image, $size, $angle, $x + (int) ($size / 15), $y, $shadow, $font, $char);
         imagettftext($image, $size, $angle, $x, $y - (int) ($size / 15), $color, $font, $char);
         $x += (int) ($size + $minSize / 6);
     }
     header('Content-Type: image/png');
     imagepng($image);
     imagedestroy($image);
 }
예제 #4
0
<?php

require_once PathBuilder::getInstance()->buildAbsolutePath(Constants::LIBS_DIR, Constants::LIBS_FILE_XMLRPC);
class XmlRpcRequest extends Request
{
    protected function init()
    {
        $requestString = file_get_contents('php://input');
        if (StringUtils::isEmpty($requestString)) {
            return;
        }
        $requestData = XMLRPC_parse($requestString);
        $methodStrings = explode('.', XMLRPC_getMethodName($requestData));
        $this->methodOwner = $methodStrings[0];
        $this->methodName = $methodStrings[1];
        $this->methodParams = XMLRPC_getParams($requestData);
        // TODO: Where to call session_start?
        session_start();
        $this->session = new PhpHttpSession();
    }
}