/** * Turn a string into a in-memory file resource. * Remember to close it when done to free up the used memory. * * @param string $data * * @return resource the in-memory file handle. */ public static function str2resource($data) { $length = BinStringStatic::_strlen($data); $handle = fopen("php://temp/maxmemory:{$length}", 'r+'); fputs($handle, $data); rewind($handle); return $handle; }
public function getComment() { $pos = 0; $len = BinStringStatic::_strlen($this->dataSubBlocks); $comment = ""; while ($pos < $len && ord($this->dataSubBlocks[$pos]) > 0) { $comment .= BinStringStatic::_substr($this->dataSubBlocks, $pos + 1, ord($this->dataSubBlocks[$pos])); $pos += 1 + ord($this->dataSubBlocks[$pos]); } return $comment; }
public function __toString() { $this->zipCommentLength = BinStringStatic::_strlen($this->zipComment); $eocd = AbstractZipHeader::ZIP_END_OF_CENTRAL_DIRECTORY; $eocd .= pack("vvvv", $this->thisDisk, $this->firstCDDisk, $this->cdrCount1, $this->cdrCount2); $eocd .= pack("VVv", $this->cdrLength, $this->cdrStart, $this->zipCommentLength); if ($this->zipCommentLength > 0) { $eocd .= $this->zipComment; } else { $eocd .= AbstractZipHeader::NULL_WORD; } return $eocd; }
/** * @return string */ public function encode() { $ctSize = BinStringStatic::_strlen($this->colorTable); if ($ctSize > 0) { $this->colorTableFlag = true; $this->colorTableSize = $ctSize / 3; } else { $this->colorTableFlag = false; $this->colorTableSize = 2; } $packedFields = 0; $packedFields |= $this->colorTableFlag ? 0x80 : 0x0; $packedFields |= $this->interlaceFlag ? 0x40 : 0x0; $packedFields |= $this->sortFlag ? 0x20 : 0x0; $packedFields |= $this->reserved << 3 & 0x18; $packedFields |= ceil(log($this->colorTableSize) / log(2)) - 1; //$packedFields |= $this->ctSizeList[$this->colorTableSize]; // The lookup table is faster, but I wanted the Pedantic version. $r = DataHandler::packUint16($this->screenLeftPos) . DataHandler::packUint16($this->screenTopPos) . DataHandler::packUint16($this->screenWidth) . DataHandler::packUint16($this->screenHeight) . chr($packedFields & 0xff); if ($this->colorTableFlag && $this->colorTableSize > 0) { $r .= $this->colorTable; } return "," . $r . $this->lzwMinCodeSize . $this->dataSubBlocks . ""; }
/** * @return string */ public function encode() { $ctSize = BinStringStatic::_strlen($this->colorTable); if ($ctSize > 0) { $this->colorTableFlag = true; $this->colorTableSize = $ctSize / 3; } else { $this->colorTableFlag = false; $this->colorTableSize = 2; } $packedFields = 0; $packedFields |= $this->colorTableFlag ? 0x80 : 0x0; $packedFields |= $this->colorResolution << 4 & 0x70; $packedFields |= $this->sortFlag ? 0x8 : 0x0; // For just 8 possible values, the lookup table is faster. // the commented line below is the pedantic way of doing it. //$packedFields |= ceil(log($this->colorTableSize) / log(2)) - 1; $packedFields |= $this->ctSizeList[$this->colorTableSize]; $r = DataHandler::packUint16($this->screenWidth) . DataHandler::packUint16($this->screenHeight) . chr($packedFields & 0xff) . chr($this->bgColorIndex) . chr($this->pixelAspectRatio == 0 ? 0 : (int) ($this->pixelAspectRatio * 64 / 15)); if ($this->colorTableFlag && $this->colorTableSize > 0) { $r .= $this->colorTable; } return $r; }
/** * @return string The version of the field for the Central Header. */ public function getCentralField() { $ts = $this->isModTimeSet ? pack('V', $this->modTime) : ''; $flags = 0; ZipUtils::setBit($flags, 0, $this->isModTimeSet); ZipUtils::setBit($flags, 1, $this->isAcTimeSet); ZipUtils::setBit($flags, 2, $this->isCrTimeSet); return parent::HEADER_EXTENDED_TIMESTAMP . pack('vc', 1 + BinStringStatic::_strlen($ts), $flags) . $ts; }
/** * @return string The version of the field for the Local Header. */ public function getLocalField() { return parent::HEADER_UNICODE_PATH . pack('vV', BinStringStatic::_strlen($this->utf8Data) + 5, $this->CRC32) . $this->version . $this->utf8Data; }
/** * @param $doc * * @return string */ public static function removeComments($doc) { $doc = preg_replace('~--\\s+>~', '-->', $doc); $doc = preg_replace('~<\\s*!\\s*--~', '<!--', $doc); $cPos = BinStringStatic::_strpos($doc, "<!--"); if ($cPos !== false) { $startCount = substr_count($doc, "<!--"); $endCount = substr_count($doc, "-->"); $lastCPos = -1; while ($cPos !== false && $lastCPos != $cPos) { $lastCPos = $cPos; $lastEPos = $cPos; $ePos = $cPos; do { $ePos = BinStringStatic::_strpos($doc, "-->", $ePos + 1); if ($ePos !== false) { $lastEPos = $ePos; $comment = BinStringStatic::_substr($doc, $cPos, $lastEPos + 3 - $cPos); $startCount = substr_count($comment, "<!--"); $endCount = substr_count($comment, "-->"); } elseif ($lastEPos == $cPos) { $lastEPos = BinStringStatic::_strlen($doc) - 3; } } while ($startCount != $endCount && $ePos !== false); $doc = substr_replace($doc, "", $cPos, $lastEPos + 3 - $cPos); $cPos = BinStringStatic::_strpos($doc, "<!--"); } } // print "<pre>\n" . htmlentities($doc) . "\n</pre>\n"; return $doc; }
/** * Compare $byteSequence with the current pointer location without moving the pointer. * * @param string $byteSequence * * @return boolean */ public function compareBytes($byteSequence) { if (isset($this->handle)) { $length = BinStringStatic::_strlen($byteSequence); $data = $this->readData($length); $this->seekReverse($length); return $data === $byteSequence; } return false; }
/** * * @param LogicalScreenDescriptor $lsd * * @return array|bool array of colors or FALSE */ public function getTransparancyColor($lsd = null) { if (!$this->transparentColorFlag) { return false; } if ($this->imageDescriptor->colorTableFlag && $this->imageDescriptor->colorTableSize > 0 && BinStringStatic::_strlen($this->imageDescriptor->colorTable) > $this->transparentColorIndex * 3) { $ct = $this->imageDescriptor->colorTable; } else { $ct = $lsd->colorTable; } if (BinStringStatic::_strlen($this->imageDescriptor->colorTable) > $this->transparentColorIndex * 3) { $color = array(); $color['red'] = $ct[$this->transparentColorIndex * 3]; $color['green'] = $ct[$this->transparentColorIndex * 3 + 1]; $color['blue'] = $ct[$this->transparentColorIndex * 3 + 2]; return $color; } return false; }
/** * Return the current size of the archive * * @author A. Grandt <*****@*****.**> * * @return int Size of the archive */ public function getArchiveSize() { if (!is_resource($this->_zipFile)) { return BinStringStatic::_strlen($this->_zipData); } $stat = fstat($this->_zipFile); return $stat['size']; }
/** * * @author A. Grandt <*****@*****.**> * @author Greg Kappatos * * @return string The full path to a temporary file. */ public static function getTemporaryFile() { if (is_callable(self::$temp)) { $file = @call_user_func(self::$temp); if (is_string($file) && BinStringStatic::_strlen($file) && is_writable($file)) { return $file; } } $dir = (is_string(self::$temp) && BinStringStatic::_strlen(self::$temp)) ? self::$temp : sys_get_temp_dir(); return tempnam($dir, __NAMESPACE__); }
/** * @param ImageDescriptor $idb */ public static function dumpImageDescriptor($idb) { echo "idbScreenLeftPos....................: " . $idb->screenLeftPos . "\n"; echo "idbScreenRightPos...................: " . $idb->screenTopPos . "\n"; echo "idbScreenWidth......................: " . $idb->screenWidth . "\n"; echo "idbScreenHeight.....................: " . $idb->screenHeight . "\n"; echo "idbPackedFields.....................: \n"; echo " - idbColorTableFlag...............: " . self::echoYN($idb->colorTableFlag) . "\n"; echo " - idbInterlaceFlag................: " . self::echoYN($idb->interlaceFlag) . "\n"; echo " - idbSortFlag.....................: " . self::echoYN($idb->sortFlag) . "\n"; echo " - reserved........................: " . $idb->reserved . " (0x" . dechex($idb->reserved) . " > " . decbin($idb->reserved) . ")\n"; echo " - idbColorTableSize...............: " . $idb->colorTableSize . "\n"; echo "\n"; echo "idb Color Table.....................: "; if ($idb->colorTableFlag && $idb->colorTableSize > 0) { echo "LCT present.\n"; if ($idb->colorTableSize < 16) { echo "idb Color Table content.............: "; echo bin2hex($idb->colorTable) . "\n"; } } else { echo "No LCT.\n"; } echo "\n"; echo "Image Data..........................: " . "\n"; echo " - lzwImageMinCodeSize.............: " . ord($idb->lzwMinCodeSize) . "\n"; echo " - lzwImageDataLength..............: " . (BinStringStatic::_strlen($idb->dataSubBlocks) + 1) . "\n"; }
/** * Build the base standard response headers, and ensure the content can be streamed. * * @author A. Grandt <*****@*****.**> * * @param String $fileName The name of the Zip archive, in ISO-8859-1 (or ASCII) encoding, ie. "archive.zip". Optional, defaults to null, which means that no ISO-8859-1 encoded file name will be specified. * @param String $contentType Content mime type. Optional, defaults to "application/zip". * @param String $utf8FileName The name of the Zip archive, in UTF-8 encoding. Optional, defaults to null, which means that no UTF-8 encoded file name will be specified. * @param bool $inline Use Content-Disposition with "inline" instead of "attached". Optional, defaults to false. * * @return bool Always returns true (for backward compatibility). * * @throws \ZipMerge\Zip\Exception\BufferNotEmpty, HeadersSent In case of errors */ protected function buildResponseHeader($fileName = null, $contentType = self::CONTENT_TYPE, $utf8FileName = null, $inline = false) { $ob = null; $headerFile = null; $headerLine = null; $zlibConfig = 'zlib.output_compression'; $ob = ob_get_contents(); if ($ob !== false && BinStringStatic::_strlen($ob)) { $this->_throwException(new BufferNotEmpty(array('outputBuffer' => $ob, 'fileName' => $fileName))); } if (headers_sent($headerFile, $headerLine)) { $this->_throwException(new HeadersSent(array('headerFile' => $headerFile, 'headerLine' => $headerLine, 'fileName' => $fileName))); } if (@ini_get($zlibConfig)) { @ini_set($zlibConfig, 'Off'); } $cd = 'Content-Disposition: ' . ($inline ? 'inline' : 'attached'); if ($fileName) { $cd .= '; filename="' . $fileName . '"'; } if ($utf8FileName) { $cd .= "; filename*=UTF-8''" . rawurlencode($utf8FileName); } header('Pragma: public'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s T')); header('Expires: 0'); header('Accept-Ranges: bytes'); header('Connection: close'); header('Content-Type: ' . $contentType); header($cd); return true; }
public static function encodeField($header, $data) { if ($header != null) { return $header . pack('v', BinStringStatic::_strlen($data)) . $data; } return ''; }