示例#1
1
 static function lock($path)
 {
     $lockPath = $path . '.lock';
     //funx::debug(__FUNCTION__." $lockPath");
     // get the lock
     $start = time();
     while (@mkdir($lockPath) === false) {
         // delete stale lock
         clearstatcache();
         if (file_exists($lockPath)) {
             $life = self::life($lockPath);
             if ($life > 5) {
                 funx::debug(__FUNCTION__ . " {$lockPath}: unlocked ({$life} seconds stale)");
                 self::unlock($path);
             }
         } else {
             funx::debug(__FUNCTION__ . " {$lockPath}: cannot mkdir and path does not exist");
             break;
         }
         //funx::debug(__FUNCTION__." $lockPath: waiting...");
         usleep(100000);
         // a tenth of one second
         if (funx::wait($start, 15) === false) {
             funx::debug(__FUNCTION__ . " {$lockPath}: waited to long and didnt unlock (lock life={$life})");
             break;
         }
     }
     return true;
 }
示例#2
0
 function doMethod($methodName, $nvpArray)
 {
     // create final name/value/pair array
     $nvpArray = array_merge(array('METHOD' => $methodName, 'VERSION' => '51.0', 'PWD' => $this->pass, 'USER' => $this->user, 'SIGNATURE' => $this->sig), $nvpArray);
     // make it a urlencoded string
     $nvpStr = ra::toNVP($nvpArray);
     //funx::debug($nvpStr);
     // create curl
     $c = curl_init();
     curl_setopt($c, CURLOPT_URL, $this->endpoint);
     //curl_setopt($c, CURLOPT_VERBOSE, 1);
     curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($c, CURLOPT_SSL_VERIFYHOST, FALSE);
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($c, CURLOPT_POST, 1);
     curl_setopt($c, CURLOPT_POSTFIELDS, $nvpStr);
     // execute method on paypal server
     $response = curl_exec($c);
     // parse the response
     $ret = $response ? ra::fromNVP($response) : array('L_LONGMESSAGE' => 'Couldn\'t talk to payment server. Please try again later. ' . curl_error($c) . '(' . curl_errno($c) . ')');
     // debug message
     funx::debug("Response to {$methodName}: " . var_export($response, true) . "\n" . var_export($ret, true));
     $this->lastErrorTxt = "Response was " . str_replace(array("  '"), array("<br /> &nbsp; '"), var_export($ret, true)) . "<br /><br />" . "NVP was " . var_export(str_replace(array("&", $this->user, $this->pass, $this->sig, urlencode($nvpArray['ACCT'])), array("<br /> &nbsp; &amp;", '', '', '', substr($nvpArray['ACCT'], -5, 5)), $nvpStr), true) . '';
     return $ret;
 }
示例#3
0
 private static function saveHeader($hash, $includes, $masterFname, $hashFname)
 {
     // list files
     /*		$files = self::getFnames($includes);
     		$txt = '/'.'* '.
     			$hash."\n".
     			date('n-j-y h:i')."\n".
     			var_export($files,true).' *'.'/'."\n";
     */
     // loop added js
     foreach ($includes as $i) {
         if (is_file($i)) {
             $txt .= self::getScript($i);
         } else {
             $txt .= "\n{$i}\n\n";
         }
     }
     file_put_contents($masterFname, $txt);
     file_put_contents($hashFname, $hash);
     chmod($masterFname, 0605);
     chmod($hashFname, 0600);
     if (self::DEBUG) {
         funx::debug(__METHOD__ . " Wrote a new '{$masterFname}' and '{$hashFname}' (" . count($includes) . " includes)");
     }
 }
示例#4
0
 private function log($ret)
 {
     // safely logg this transaction
     $t = clone $this->tran;
     $t->card = substr($t->card, -4);
     unset($t->pin, $t->expir, $t->cvv2, $t->key);
     foreach ($t as $k => $i) {
         if (!strlen($i)) {
             unset($t->{$k});
         } else {
             $t->{$k} = str_replace(array("\n", "\r"), array('\\n', '\\r'), $i);
         }
     }
     funx::debug($t, DIR_KIT . 'log/gateway.log');
     funx::debug("{$t->result}: \${$t->amount} ************{$t->card} {$t->invoice}");
 }
示例#5
0
文件: db.php 项目: NatWeiss/JankyPHP
 static function trim($ra, $allowedKeys)
 {
     $ret = array();
     if (is_array($ra)) {
         // copy over allowed keys
         foreach ($allowedKeys as $k) {
             $ret[$k] = $ra[$k];
         }
         // track missing keys
         $missing = '';
         $ak = array_flip($allowedKeys);
         foreach ($ra as $k => $i) {
             if (!isset($ak[$k])) {
                 $missing .= (strlen($missing) ? ', ' : '') . "{$k}";
             }
         }
         if (strlen($missing)) {
             $missing = "DB Warning: These fields aren't allowed in one of the tables: {$missing}\n";
             funx::debug($missing);
             email::send(ini::get('email-address'), 'DB Squeak', $missing);
         }
     }
     return $ret;
 }
示例#6
0
 static function getAllTags($txt, $type, $props = array())
 {
     if (strlen($type) > strlen($txt)) {
         funx::debug(__METHOD__ . ' tag type is longer than txt');
         return false;
     }
     if (!is_array($props)) {
         $props = array();
     }
     $ret = array();
     do {
         $tag = self::extractTag($txt, $type);
         if ($tag !== false and ($pos1 = strpos($tag, '>')) !== false and ($pos2 = strrpos($tag, '<')) !== false) {
             // get text
             $r['text'] = substr($tag, $pos1 + 1, $pos2 - $pos1 - 1);
             // parse properties
             $tag = substr($tag, 0, $pos1);
             foreach ($props as $prop) {
                 $val = self::parseProperty($tag, $prop);
                 if (strlen($val)) {
                     $r[$prop] = $val;
                 }
             }
             $ret[] = $r;
         }
     } while ($tag !== false);
     return $ret;
 }
示例#7
0
 static function parse($fname, $args)
 {
     $msg = explode("\n", funx::inc($fname, $args));
     $subject = trim(array_shift($msg));
     $body = ra::condense($msg, '<br />');
     return array($subject, $body);
 }
示例#8
0
 private function log($txt)
 {
     funx::debug($txt);
 }
示例#9
0
 static function drawFile($fname)
 {
     // settings
     ini_set('zlib.output_compression', 'Off');
     ini_set('output_buffering', 'Off');
     // clean output buffers
     for ($i = 0; $i < ob_get_level(); $i++) {
         ob_end_clean();
         if ($i > 10) {
             break;
         }
     }
     // content-type based on extension
     $types = array('default' => array('type' => 'application/octet-stream', 'attach' => true), 'mp3' => 'audio/mpeg', 'mov' => 'video/quicktime', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'pdf' => 'application/pdf', 'zip' => array('type' => 'application/zip', 'attach' => true), 'doc' => array('type' => 'application/msword', 'attach' => true));
     // get type
     $ext = file::ext($fname);
     $t = isset($types[$ext]) ? $types[$ext] : current($types);
     if (!is_array($t)) {
         $t = array('type' => $t);
     }
     // headers
     $id = str::bc36(time());
     $chunk = 1024 * 1024;
     $time_limit = (int) ($chunk / 100);
     $filesize = filesize($fname);
     header("Cache-Control:");
     header("Cache-Control: public");
     header("Pragma: ");
     header('Content-Type: ' . $t['type']);
     header('Content-Disposition: ' . ($t['attach'] ? 'attachment' : 'inline') . ';' . ' filename="' . basename($fname) . '"');
     //' filename="'.file::name($fname).'-'.$id.'.'.file::ext($fname).'"');
     header("Content-Transfer-Encoding: binary\n");
     // check if http_range is sent by browser (or download manager)
     header("Accept-Ranges: bytes");
     if (isset($_SERVER['HTTP_RANGE'])) {
         list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
         str_replace($range, "-", $range);
         $filesize2 = $filesize - 1;
         $new_length = $filesize2 - $range;
         header("HTTP/1.1 206 Partial Content");
         header("Content-Length: {$new_length}");
         header("Content-Range: bytes {$range}{$filesize2}/{$filesize}");
         $filesize = $new_length;
     } else {
         $filesize2 = $filesize - 1;
         header("Content-Range: bytes 0-{$filesize2}/{$filesize}");
     }
     header("Content-Length: " . $filesize);
     // draw
     $fp = fopen($fname, 'rb');
     if ($fp) {
         // resume
         if ($range > 0) {
             fseek($fp, $range);
         }
         // send
         while (!feof($fp) and connection_status() == 0) {
             set_time_limit($time_limit);
             $content = fread($fp, $chunk);
             echo $content;
             ob_flush();
             flush();
             $sent += strlen($content);
             unset($content);
             //funx::debug("$id sent ".(int)($sent/1024)."k".
             //	", memory used ".(int)(memory_get_usage(true)/1024)."k".
             //	", time limit ".(int)($time_limit/60)."m");
         }
         fclose($fp);
     }
     funx::debug("{$id} done ({$sent} of {$filesize}) (connection_status==" . (int) connection_status() . ")");
     return !connection_aborted() and connection_status() == 0 and $sent >= $filesize;
 }