Example #1
0
 public static function suite()
 {
     if (self::initTable()) {
         self::$sid = md5hash();
         ini_set("session.use_cookies", "0");
         return self::createSuite("Test_Session_Database");
     } else {
         return self::createSuite("");
     }
 }
Example #2
0
 /**
  * @test
  */
 public function isActive()
 {
     $user1 = User::findByUsername("test1");
     $this->isTrue($user1->isActive());
     $user1->save(array("delete_flag" => true));
     $user1 = new User($user1->id);
     $this->isFalse($user1->isActive());
     $user1->save(array("delete_flag" => false, "act_key" => md5hash()));
     $user1 = new User($user1->id);
     $this->isFalse($user1->isActive());
     $user1->save(array("act_key" => null));
 }
Example #3
0
 /**
  * @transaction
  *
  * @param User $aUser
  *
  * @return Logics_Result
  */
 public function preregister(User $aUser)
 {
     $result = new Logics_Result();
     $aUser->created_at = $aUser->updated_at = now();
     if ($errors = $this->validateModel($aUser)) {
         return $result->setErrors($errors);
     }
     $actKey = md5hash();
     $aUser->password = md5($aUser->password);
     if (ENVIRONMENT === DEVELOPMENT) {
         $aUser->save();
     } else {
         $aUser->save(array("act_key" => $actKey));
     }
     $this->mail->sendActivationKey($aUser->email, $actKey);
     return $result;
 }
Example #4
0
function get_temp_dir()
{
    static $exists = null;
    if ($exists === null) {
        $exists = function_exists("sys_get_temp_dir");
    }
    if ($exists) {
        return sys_get_temp_dir();
    } elseif (isset($_ENV["TMP"])) {
        return realpath($_ENV["TMP"]);
    } elseif (isset($_ENV["TMPDIR"])) {
        return realpath($_ENV["TMPDIR"]);
    } elseif (isset($_ENV["TEMP"])) {
        return realpath($_ENV["TEMP"]);
    } else {
        if ($tmpFile = tempnam(md5hash(), "sbl_")) {
            $dirName = realpath(dirname($tmpFile));
            unlink($tmpFile);
            return $dirName;
        } else {
            return null;
        }
    }
}
Example #5
0
 /**
  * Prepare the request body (for POST and PUT requests)
  *
  * @return string
  * @throws Zend_Http_Client_Exception
  */
 protected function _prepareBody()
 {
     // According to RFC2616, a TRACE request should not have a body.
     if ($this->method === self::TRACE) {
         return "";
     }
     $mbIntEnc = null;
     // If mbstring overloads substr and strlen functions, we have to
     // override it's internal encoding
     if (function_exists("mb_internal_encoding") && (int) ini_get("mbstring.func_overload") & 2) {
         $mbIntEnc = mb_internal_encoding();
         mb_internal_encoding("ASCII");
     }
     // If we have raw_post_data set, just use it as the body.
     if (isset($this->raw_post_data)) {
         $this->setHeaders(self::CONTENT_LENGTH, strlen($this->raw_post_data));
         if ($mbIntEnc !== null) {
             mb_internal_encoding($mbIntEnc);
         }
         return $this->raw_post_data;
     }
     $body = "";
     // If we have files to upload, force enctype to multipart/form-data
     if (count($this->files) > 0) {
         $this->setEncType(self::ENC_FORMDATA);
     }
     // If we have POST parameters or files, encode and add them to the body
     if (count($this->paramsPost) > 0 || count($this->files) > 0) {
         switch ($this->enctype) {
             case self::ENC_FORMDATA:
                 // Encode body as multipart/form-data
                 $boundary = md5hash();
                 $this->setHeaders(self::CONTENT_TYPE, self::ENC_FORMDATA . "; boundary={$boundary}");
                 // Get POST parameters and encode them
                 $params = self::_flattenParametersArray($this->paramsPost);
                 foreach ($params as $pp) {
                     $body .= self::encodeFormData($boundary, $pp[0], $pp[1]);
                 }
                 // Encode files
                 foreach ($this->files as $file) {
                     $fhead = array(self::CONTENT_TYPE => $file["ctype"]);
                     $body .= self::encodeFormData($boundary, $file["formname"], $file["data"], $file["filename"], $fhead);
                 }
                 $body .= "--{$boundary}--\r\n";
                 break;
             case self::ENC_URLENCODED:
                 // Encode body as application/x-www-form-urlencoded
                 $this->setHeaders(self::CONTENT_TYPE, self::ENC_URLENCODED);
                 $body = http_build_query($this->paramsPost, "", "&");
                 break;
             default:
                 if (isset($mbIntEnc)) {
                     mb_internal_encoding($mbIntEnc);
                 }
                 $message = __METHOD__ . "() Cannot handle content type '{$this->enctype}' automatically." . " Please use Sabel_Http_Client::setRawData to send this kind of content.";
                 throw new Sabel_Exception_Runtime($message);
         }
     }
     // Set the Content-Length if we have a body or if request is POST/PUT
     if ($body || $this->method === self::POST || $this->method === self::PUT) {
         $this->setHeaders(self::CONTENT_LENGTH, strlen($body));
     }
     if (isset($mbIntEnc)) {
         mb_internal_encoding($mbIntEnc);
     }
     return $body;
 }
Example #6
0
 /**
  * @param string $resource image data
  *
  * @return string
  */
 public function upload($resource)
 {
     $fileName = md5hash() . "." . $this->getType($resource);
     file_put_contents($this->getSourceDir() . DS . $fileName, $resource);
     return $fileName;
 }
Example #7
0
 protected function buildBody()
 {
     $body = "";
     if ($this->method === "GET") {
         unset($this->headers["Content-Type"]);
         unset($this->headers["Content-Length"]);
         return $body;
     }
     $hasValues = !empty($this->postValues);
     $hasFiles = !empty($this->files);
     if ($hasValues || $hasFiles) {
         $body = array();
         $boundary = md5hash();
         if ($hasValues) {
             foreach ($this->postValues as $name => $value) {
                 $body[] = "--" . $boundary;
                 $body[] = "Content-Disposition: form-data; name=\"{$name}\"\r\n";
                 $body[] = $value;
             }
         }
         if ($hasFiles) {
             foreach ($this->files as $name => $file) {
                 $name = $file["name"];
                 $input = $file["formName"];
                 $body[] = "--" . $boundary;
                 $body[] = "Content-Disposition: form-data; name=\"{$input}\"; filename=\"{$name}\"";
                 $body[] = "Content-Type: " . $file["contentType"] . "\r\n";
                 $body[] = $file["data"];
             }
         }
         $body[] = "--{$boundary}--";
         $body = implode("\r\n", $body);
         $this->headers["Content-Type"] = "multipart/form-data; boundary=\"{$boundary}\"";
         $this->headers["Content-Length"] = strlen($body);
     } elseif ($hasValues) {
         $body = http_build_query($this->postValues, "", "&");
         $this->headers["Content-Type"] = "application/x-www-form-urlencoded";
         $this->headers["Content-Length"] = strlen($body);
     }
     return $body;
 }
Example #8
0
 public function __construct($binary)
 {
     $this->binary = $binary;
     $this->filePath = get_temp_dir() . DS . "sbl_" . md5hash();
 }
Example #9
0
 protected static function splitByWhiteSpace($query)
 {
     $replace = array();
     if (preg_match_all("/'.+'/U", $query, $matches)) {
         $hash = md5hash();
         foreach ($matches[0] as $i => $match) {
             $replace[$hash . $i] = $match;
             $query = str_replace($match, $hash . $i, $query);
         }
     }
     $query = preg_replace("/ {2,}/", " ", $query);
     $parts = explode(" ", $query);
     if ($replace) {
         foreach ($parts as &$part) {
             if (isset($replace[$part])) {
                 $part = $replace[$part];
             }
         }
     }
     return $parts;
 }
Example #10
0
 protected function createSessionId()
 {
     return ini_get("session.hash_function") === "1" ? sha1hash() : md5hash();
 }
Example #11
0
function get_mime_type($path)
{
    $tmpFile = null;
    if (!is_file($path)) {
        if ($tmpDir = get_temp_dir()) {
            $tmpFile = $tmpDir . DS . md5hash();
            if (file_put_contents($tmpFile, $path)) {
                $path = $tmpFile;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    $ret = false;
    if (!is_file($path)) {
        return $ret;
    } elseif (extension_loaded("fileinfo")) {
        if (defined("FILEINFO_MAGICDB")) {
            $finfo = new finfo(FILEINFO_MIME, FILEINFO_MAGICDB);
        } else {
            $finfo = new finfo(FILEINFO_MIME);
        }
        $ret = $finfo->file($path);
    } elseif (DS === "/") {
        // *nix
        $ret = trim(shell_exec("file -ib " . escapeshellcmd($path)));
    } elseif (function_exists("mime_content_type")) {
        $ret = mime_content_type($path);
    }
    if ($tmpFile !== null) {
        unlink($tmpFile);
    }
    return $ret;
}
Example #12
0
 public function textlink($htmlescaped = true)
 {
     if ($htmlescaped) {
         $lt = "<";
         $gt = ">";
         $qt = """;
     } else {
         $lt = '<';
         $gt = '>';
         $qt = '"';
     }
     $text = $this->string;
     $chars = '0-9a-zA-Z_\\-\\.\\~\\/\\?@%=:;&#';
     preg_match_all('!' . $lt . 'a .*href=' . $qt . '(https?://[' . $chars . ']+)' . $qt . '.*' . $gt . '(.+)' . $lt . '/a' . $gt . '!U', $text, $matches);
     $replaces = array();
     if (isset($matches[0])) {
         for ($i = 0, $mc = count($matches[0]); $i < $mc; $i++) {
             $hash = md5hash();
             $replaces[$hash] = '<a href="' . $matches[1][$i] . '">' . $matches[2][$i] . '</a>';
             $text = str_replace($matches[0][$i], $hash, $text);
         }
     }
     $text = preg_replace('!https?://[' . $chars . ']+!', '<a href="$0">$0</a>', $text);
     if ($replaces) {
         $text = strtr($text, $replaces);
     }
     $this->string = $text;
     return $this;
 }
Example #13
0
 protected function _setBasicHeaders(array $headers)
 {
     $hasMessageId = false;
     $hasMimeHeader = false;
     $hasDate = false;
     foreach ($headers as $name => $header) {
         $lowered = strtolower($name);
         if ($lowered === "message-id") {
             $hasMessageId = true;
         } elseif ($lowered === "mime-version") {
             $hasMimeHeader = true;
         } elseif ($lowered === "date") {
             $hasDate = true;
         }
     }
     if (!$hasMessageId) {
         $fromAddress = $headers["From"]["address"];
         $this->checkAddressFormat($fromAddress);
         list(, $host) = explode("@", $fromAddress);
         $headers["Message-ID"] = "<" . md5hash() . "@{$host}>";
     }
     if (!$hasMimeHeader) {
         $headers["Mime-Version"] = "1.0";
     }
     if (!$hasDate) {
         $headers["Date"] = date("r");
     }
     return $headers;
 }