run php cs fix

This commit is contained in:
Sebijk 2022-02-21 21:04:55 +01:00
parent 6a8c9a281f
commit cb7b5bdadc
4 changed files with 1496 additions and 1473 deletions

View file

@ -19,117 +19,119 @@
*
*/
if(!defined('B1GMAIL_INIT'))
if (!defined('B1GMAIL_INIT')) {
die('Directly calling this file is not supported');
}
if(!class_exists('BMHTTP'))
include(B1GMAIL_DIR . 'serverlib/http.class.php');
if (!class_exists('BMHTTP')) {
include B1GMAIL_DIR.'serverlib/http.class.php';
}
/**
* sms class
* sms class.
*/
class BMSMS
{
var $_userID;
var $_userObject;
private $_userID;
private $_userObject;
/**
* constructor
* constructor.
*
* @param int $userID User ID
* @param BMUser $userObject User object
*
* @return BMSMS
*/
function __construct($userID, &$userObject)
public function __construct($userID, &$userObject)
{
$this->_userID = (int) $userID;
$this->_userObject = &$userObject;
}
/**
* get outbox
* get outbox.
*
* @return array
*/
function GetOutbox($sortColumn = 'id', $sortOrder = 'DESC')
public function GetOutbox($sortColumn = 'id', $sortOrder = 'DESC')
{
global $db;
$result = array();
$result = [];
$res = $db->Query('SELECT id,`from`,`to`,`text`,price,`date` FROM {pre}smsend WHERE isSMS=1 AND user=? AND deleted=0 ORDER BY `'.$sortColumn.'` '.$sortOrder.' LIMIT 15',
$this->_userID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$result[$row['id']] = $row;
}
$res->Free();
return($result);
return $result;
}
/**
* delete sms outbox entry
* delete sms outbox entry.
*
* @param int $id ID
*/
function DeleteOutboxEntry($id)
public function DeleteOutboxEntry($id)
{
global $db;
$db->Query('UPDATE {pre}smsend SET `deleted`=1,`from`=?,`to`=?,`text`=? WHERE id=? AND user=?',
'', '', '',
$id, $this->_userID);
return($db->AffectedRows() == 1);
return $db->AffectedRows() == 1;
}
/**
* check if $no conforms $pre-list
* check if $no conforms $pre-list.
*
* @param string $no
* @param string $pre
*
* @return bool
*/
function PreOK($no, $pre)
{
if(trim($pre) != '')
public function PreOK($no, $pre)
{
if (trim($pre) != '') {
$ok = false;
$entries = explode(':', $pre);
foreach($entries as $entry)
{
foreach ($entries as $entry) {
$entry = str_replace('+', '00', preg_replace('/[^0-9]/', '', $entry));
if(substr($no, 0, strlen($entry)) == $entry)
{
if (substr($no, 0, strlen($entry)) == $entry) {
$ok = true;
break;
}
}
}
else
} else {
$ok = true;
}
return($ok);
return $ok;
}
/**
* get available SMS types
* get available SMS types.
*
* @return array
*/
function GetTypes()
public function GetTypes()
{
global $db;
if(is_object($this->_userObject))
{
if (is_object($this->_userObject)) {
$group = $this->_userObject->GetGroup();
$groupRow = $group->Fetch();
} else {
$groupRow = ['sms_sig' => ''];
}
else
$groupRow = array('sms_sig' => '');
$result = array();
$result = [];
$res = $db->Query('SELECT id,titel,typ,std,price,gateway,flags,maxlength FROM {pre}smstypen ORDER BY titel ASC');
while($row = $res->FetchArray(MYSQLI_ASSOC))
$result[$row['id']] = array(
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$result[$row['id']] = [
'id' => $row['id'],
'title' => $row['titel'],
'type' => $row['typ'],
@ -137,77 +139,79 @@ class BMSMS
'price' => $row['price'],
'gateway' => $row['gateway'],
'flags' => $row['flags'],
'maxlength' => $row['maxlength'] - strlen($groupRow['sms_sig'])
);
'maxlength' => $row['maxlength'] - strlen($groupRow['sms_sig']),
];
}
$res->Free();
return($result);
return $result;
}
/**
* get max SMS chars for user
* get max SMS chars for user.
*
* @return int
*/
function GetMaxChars($typeID = 0)
public function GetMaxChars($typeID = 0)
{
global $db;
if(is_object($this->_userObject))
{
if (is_object($this->_userObject)) {
$group = $this->_userObject->GetGroup();
$groupRow = $group->Fetch();
} else {
$groupRow = ['sms_sig' => ''];
}
else
$groupRow = array('sms_sig' => '');
$maxChars = 160;
if($typeID > 0)
{
if ($typeID > 0) {
$res = $db->Query('SELECT maxlength FROM {pre}smstypen WHERE id=?', $typeID);
while($row = $res->FetchArray(MYSQLI_ASSOC))
while ($row = $res->FetchArray(MYSQLI_ASSOC)) {
$maxChars = $row['maxlength'];
}
$res->Free();
}
return($maxChars - strlen($groupRow['sms_sig']));
return $maxChars - strlen($groupRow['sms_sig']);
}
/**
* get default gateway or gateway specified by ID
* get default gateway or gateway specified by ID.
*
* @param int $id ID (0 = default gateway)
*
* @return array
*/
function GetGateway($id = 0)
public function GetGateway($id = 0)
{
global $bm_prefs, $db;
if($id == 0)
if ($id == 0) {
$id = $bm_prefs['sms_gateway'];
}
$res = $db->Query('SELECT id,titel,getstring,success,`user`,`pass` FROM {pre}smsgateways WHERE id=?',
$id);
if($res->RowCount() == 1)
{
if ($res->RowCount() == 1) {
$row = $res->FetchArray(MYSQLI_ASSOC);
$res->Free();
return(array(
return [
'id' => $row['id'],
'title' => $row['titel'],
'getstring' => $row['getstring'],
'success' => $row['success'],
'user' => $row['user'],
'pass' => $row['pass']
));
'pass' => $row['pass'],
];
}
return(false);
return false;
}
/**
* send SMS
* send SMS.
*
* @param string $from From
* @param string $to To
@ -216,24 +220,25 @@ class BMSMS
* @param bool $charge Charge user account?
* @param bool $putToOutbox Put SMS to outbox?
* @param int $outboxID ID of outbox entry, if already available
*
* @return bool
*/
function Send($from, $to, $text, $type = 0, $charge = true, $putToOutbox = true, $outboxID = 0)
public function Send($from, $to, $text, $type = 0, $charge = true, $putToOutbox = true, $outboxID = 0)
{
global $bm_prefs, $db, $lang_user;
// module handler
ModuleFunction('OnSendSMS', array(&$text, &$type, &$from, &$to, &$this->_userObject));
ModuleFunction('OnSendSMS', [&$text, &$type, &$from, &$to, &$this->_userObject]);
// get type and type list
$types = $this->GetTypes();
if($type == 0)
{
foreach($types as $typeID=>$typeInfo)
if($typeInfo['default'])
if ($type == 0) {
foreach ($types as $typeID => $typeInfo) {
if ($typeInfo['default']) {
$type = $typeID;
if($type == 0)
{
}
}
if ($type == 0) {
PutLog(sprintf('Default SMS type <%d> not found while trying to send SMS from <%s> to <%s> (userID: %d)',
$type,
$from,
@ -242,13 +247,13 @@ class BMSMS
PRIO_WARNING,
__FILE__,
__LINE__);
return(false);
return false;
}
}
if(isset($types[$type]))
if (isset($types[$type])) {
$type = $types[$type];
else
{
} else {
PutLog(sprintf('SMS type <%d> not found while trying to send SMS from <%s> to <%s> (userID: %d)',
$type,
$from,
@ -257,19 +262,19 @@ class BMSMS
PRIO_WARNING,
__FILE__,
__LINE__);
return(false);
return false;
}
// crop text
if(_strlen($text) > $this->GetMaxChars($type['id']))
if (_strlen($text) > $this->GetMaxChars($type['id'])) {
$text = _substr($text, 0, $this->GetMaxChars($type['id']));
}
// check account balance
if($charge)
{
if ($charge) {
$balance = $this->_userObject->GetBalance();
if($balance < $type['price'])
{
if ($balance < $type['price']) {
PutLog(sprintf('Failed to send SMS from <%s> to <%s>: Not enough credits (userID: %d)',
$from,
$to,
@ -277,14 +282,14 @@ class BMSMS
PRIO_NOTE,
__FILE__,
__LINE__);
return(false);
return false;
}
}
// get gateway info
$gateway = $this->GetGateway($type['gateway']);
if(!$gateway)
{
if (!$gateway) {
PutLog(sprintf('Gateway <%d> not found while trying to send SMS with type <%d> from <%s> to <%s> (userID: %d)',
$type['gateway'],
$type['id'],
@ -294,7 +299,8 @@ class BMSMS
PRIO_WARNING,
__FILE__,
__LINE__);
return(false);
return false;
}
// prepare formatted numbers
@ -330,8 +336,7 @@ class BMSMS
$getString = str_replace('%%msg_utf8%%',
urlencode(CharsetDecode($text, false, 'UTF-8')),
$getString);
if($this->_userObject)
{
if ($this->_userObject) {
$getString = str_replace('%%usermail%%',
_urlencode($this->_userObject->_row['email']),
$getString);
@ -344,7 +349,7 @@ class BMSMS
$getString);
// request!
$http = _new('BMHTTP', array($getString));
$http = _new('BMHTTP', [$getString]);
$result = $http->DownloadToString();
$success = (trim($gateway['success']) == '' && trim($result) == '')
|| (strpos(strtolower($result), strtolower($gateway['success'])) !== false);
@ -360,25 +365,25 @@ class BMSMS
__LINE__);
// ok?
if($success)
{
if ($success) {
// status ID?
if(preg_match('/Status\:([0-9]*)/', $result, $reg) && is_array($reg) && isset($reg[1]))
if (preg_match('/Status\:([0-9]*)/', $result, $reg) && is_array($reg) && isset($reg[1])) {
$statusID = $reg[1];
else
} else {
$statusID = -1;
}
// stats
Add2Stat('sms');
// charge, if requested
if($charge)
if ($charge) {
$outboxID = $this->_userObject->Debit($type['price'] * -1, $lang_user['tx_sms']);
}
// put to outbox?
if($putToOutbox)
if($outboxID == 0)
{
if ($putToOutbox) {
if ($outboxID == 0) {
$db->Query('INSERT INTO {pre}smsend(user,monat,price,isSMS,`from`,`to`,`text`,statusid,`date`) VALUES(?,?,?,?,?,?,?,?,?)',
$this->_userID,
(int) date('mY'),
@ -390,8 +395,7 @@ class BMSMS
$statusID,
time());
$outboxID = $db->InsertId();
}
else
} else {
$db->Query('UPDATE {pre}smsend SET isSMS=?,`from`=?,`to`=?,`text`=?,statusid=?,`date`=? WHERE id=? AND user=?',
1,
$from,
@ -401,9 +405,11 @@ class BMSMS
time(),
$outboxID,
$this->_userID);
}
}
// module handler
ModuleFunction('AfterSendSMS', array(true, $result, $outboxID));
ModuleFunction('AfterSendSMS', [true, $result, $outboxID]);
// log
PutLog(sprintf('Sent SMS from <%s> to <%s> (type: %d; statusID: %d; charged: %d; userID: %d)',
@ -416,12 +422,11 @@ class BMSMS
PRIO_NOTE,
__FILE__,
__LINE__);
return(true);
}
else
{
return true;
} else {
// module handler
ModuleFunction('AfterSendSMS', array(false, $result, $outboxID));
ModuleFunction('AfterSendSMS', [false, $result, $outboxID]);
// log
PutLog(sprintf('Failed to send SMS from <%s> to <%s> (type: %d; charged: 0; userID: %d)',
@ -432,7 +437,8 @@ class BMSMS
PRIO_NOTE,
__FILE__,
__LINE__);
return(false);
return false;
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -19,53 +19,53 @@
*
*/
if(!defined('B1GMAIL_INIT'))
if (!defined('B1GMAIL_INIT')) {
die('Directly calling this file is not supported');
}
/**
* Basic UnZIP class
*
* Basic UnZIP class.
*/
class BMUnZIP
{
var $_fp;
var $_centralDirStruct;
private $_fp;
private $_centralDirStruct;
/**
* constructor
* constructor.
*
* @param resource $fp Input file stream
*
* @return BMUnZIP
*/
function __construct($fp)
public function __construct($fp)
{
$this->_fp = $fp;
$this->_readCentralDirStruct();
}
/**
* get ZIP file directory listing
* get ZIP file directory listing.
*
* @return array
*/
function GetFileList()
public function GetFileList()
{
return($this->_centralDirStruct);
return $this->_centralDirStruct;
}
/**
* get ZIP file directory listing prepared for tree display
* get ZIP file directory listing prepared for tree display.
*
* @return array
*/
function GetFileTree()
public function GetFileTree()
{
$tree = array();
$tree = [];
$folderNoCounter = count($this->_centralDirStruct);
// add files
foreach($this->_centralDirStruct as $fileNo=>$file)
{
foreach ($this->_centralDirStruct as $fileNo => $file) {
$file['parentID'] = -2;
$file['type'] = 'file';
$file['fileNo'] = $fileNo;
@ -76,38 +76,33 @@ class BMUnZIP
// add folders
$again = true;
while($again)
{
while ($again) {
$again = false;
foreach($tree as $id=>$item)
{
if($item['parentID'] != -2)
foreach ($tree as $id => $item) {
if ($item['parentID'] != -2) {
continue;
}
$parentFolderName = dirname($item['fileName']);
if($parentFolderName != '.' && $parentFolderName != '')
{
if ($parentFolderName != '.' && $parentFolderName != '') {
$parentID = -2;
foreach($tree as $id2=>$item2)
{
if($item2['type'] == 'folder' && $item2['fileName'] == $parentFolderName)
{
foreach ($tree as $id2 => $item2) {
if ($item2['type'] == 'folder' && $item2['fileName'] == $parentFolderName) {
$parentID = $item2['fileNo'];
break;
}
}
if($parentID == -2)
{
if ($parentID == -2) {
$folderNo = $folderNoCounter++;
$tree[] = array('type' => 'folder',
$tree[] = ['type' => 'folder',
'fileName' => $parentFolderName,
'baseName' => basename($parentFolderName),
'fileNo' => $folderNo,
'parentID' => -2);
'parentID' => -2, ];
$parentID = $folderNo;
$again = true;
}
@ -117,23 +112,26 @@ class BMUnZIP
}
}
return($tree);
return $tree;
}
/**
* extract a file by file no
* extract a file by file no.
*
* @param int $fileNo File no (from GetFileList() array)
* @param resource $fp Output file stream
*
* @return bool
*/
function ExtractFile($fileNo, $fp = false, $sizeLimit = -1)
public function ExtractFile($fileNo, $fp = false, $sizeLimit = -1)
{
if(!isset($this->_centralDirStruct[$fileNo]))
return(false);
if (!isset($this->_centralDirStruct[$fileNo])) {
return false;
}
if(!in_array($this->_centralDirStruct[$fileNo]['compressionMethod'], array(8, 12)))
return(false);
if (!in_array($this->_centralDirStruct[$fileNo]['compressionMethod'], [8, 12])) {
return false;
}
fseek($this->_fp, $this->_centralDirStruct[$fileNo]['relativeOffset'], SEEK_SET);
@ -142,77 +140,77 @@ class BMUnZIP
$_fileHeader = @unpack('Vsignature/vversionNeeded/vflags/vcompressionMethod/vmTime/vmDate/Vcrc32/VcompressedSize/VuncompressedSize/vfileNameLength/vextraFieldLength',
$fileHeader);
if(!$_fileHeader || $_fileHeader['signature'] != 0x04034b50)
return(false);
if (!$_fileHeader || $_fileHeader['signature'] != 0x04034b50) {
return false;
}
fseek($this->_fp, $_fileHeader['fileNameLength'] + $_fileHeader['extraFieldLength'], SEEK_CUR);
$_fileHeader = $this->_centralDirStruct[$fileNo];
if($_fileHeader['compressedSize'] > 0)
{
if ($_fileHeader['compressedSize'] > 0) {
$compressedData = fread($this->_fp, $_fileHeader['compressedSize']);
$uncompressedData = '';
if($_fileHeader['compressionMethod'] == 8)
{
if ($_fileHeader['compressionMethod'] == 8) {
$uncompressedData = @gzinflate($compressedData);
}
else if($_fileHeader['compressionMethod'] == 12)
{
} elseif ($_fileHeader['compressionMethod'] == 12) {
$uncompressedData = @bzdecompress($compressedData);
}
unset($compressedData);
if(crc32($uncompressedData) != $_fileHeader['crc32'])
return(false);
if (crc32($uncompressedData) != $_fileHeader['crc32']) {
return false;
}
if($fp !== false)
if ($fp !== false) {
fwrite($fp, $uncompressedData, $sizeLimit != -1 ? $sizeLimit : strlen($uncompressedData));
else
echo($uncompressedData);
} else {
echo $uncompressedData;
}
else if($_fileHeader['crc32'] != 0)
{
return(false);
} elseif ($_fileHeader['crc32'] != 0) {
return false;
}
return(true);
return true;
}
/**
* read central dir struct from ZIP file
*
* read central dir struct from ZIP file.
*/
function _readCentralDirStruct()
private function _readCentralDirStruct()
{
$this->_centralDirStruct = array();
$this->_centralDirStruct = [];
fseek($this->_fp, -22, SEEK_END);
$endOfCDS = fread($this->_fp, 22);
while(substr($endOfCDS, 0, 4) != pack('V', 0x06054b50))
{
while (substr($endOfCDS, 0, 4) != pack('V', 0x06054b50)) {
fseek($this->_fp, -1, SEEK_CUR);
$endOfCDS = fgetc($this->_fp).$endOfCDS;
fseek($this->_fp, -1, SEEK_CUR);
if(ftell($this->_fp) < 2)
if (ftell($this->_fp) < 2) {
break;
}
}
if (substr($endOfCDS, 0, 4) != pack('V', 0x06054b50)) {
if (DEBUG) {
trigger_error('File corrupt or not in ZIP format', E_USER_NOTICE);
}
if(substr($endOfCDS, 0, 4) != pack('V', 0x06054b50))
{
if(DEBUG) trigger_error('File corrupt or not in ZIP format', E_USER_NOTICE);
return;
}
// parse endOfCDS record
$_endOfCDS = @unpack('Vsignature/vdiskNo/vcdsStartDiskNo/vcdsDiskEntryCount/vcdsTotalEntryCount/VcdsSize/VcdsOffset/vcommentLength', $endOfCDS);
if(!$_endOfCDS)
{
if(DEBUG) trigger_error('File corrupt or not in ZIP format (eoCDS broken)', E_USER_NOTICE);
if (!$_endOfCDS) {
if (DEBUG) {
trigger_error('File corrupt or not in ZIP format (eoCDS broken)', E_USER_NOTICE);
}
return;
}
@ -220,39 +218,44 @@ class BMUnZIP
fseek($this->_fp, $_endOfCDS['cdsOffset'], SEEK_SET);
// read CDS entries
for($i=0; $i<$_endOfCDS['cdsDiskEntryCount'] && !feof($this->_fp); $i++)
{
for ($i = 0; $i < $_endOfCDS['cdsDiskEntryCount'] && !feof($this->_fp); ++$i) {
$fileHeader = fread($this->_fp, 46);
$_fileHeader = @unpack('Vsignature/vversion/vversionNeeded/vflags/vcompressionMethod/vmTime/vmDate/Vcrc32/VcompressedSize/VuncompressedSize/vfileNameLength/vextraFieldLength/vfileCommentLength/vdiskNumberStart/vinternalAttrs/VexternalAttrs/VrelativeOffset',
$fileHeader);
if(!$_fileHeader || $_fileHeader['signature'] != 0x02014b50)
{
if(DEBUG) trigger_error('File corrupt (CDS broken)');
if (!$_fileHeader || $_fileHeader['signature'] != 0x02014b50) {
if (DEBUG) {
trigger_error('File corrupt (CDS broken)');
}
return;
}
$_fileHeader['cdsOffset'] = ftell($this->_fp) - strlen($fileHeader);
if($_fileHeader['fileNameLength'] > 0)
if ($_fileHeader['fileNameLength'] > 0) {
$_fileHeader['fileName'] = fread($this->_fp, $_fileHeader['fileNameLength']);
if($_fileHeader['extraFieldLength'] > 0)
}
if ($_fileHeader['extraFieldLength'] > 0) {
$_fileHeader['extraField'] = fread($this->_fp, $_fileHeader['extraFieldLength']);
if($_fileHeader['fileCommentLength'] > 0)
}
if ($_fileHeader['fileCommentLength'] > 0) {
$_fileHeader['fileComment'] = fread($this->_fp, $_fileHeader['fileCommentLength']);
}
if(substr($_fileHeader['fileName'], -1) == '/' && $_fileHeader['uncompressedSize'] == 0)
if (substr($_fileHeader['fileName'], -1) == '/' && $_fileHeader['uncompressedSize'] == 0) {
continue;
}
$this->_centralDirStruct[] = $_fileHeader;
}
// sort by filename
uasort($this->_centralDirStruct, array(&$this, '_sortHandler'));
uasort($this->_centralDirStruct, [&$this, '_sortHandler']);
}
function _sortHandler($s1, $s2)
private function _sortHandler($s1, $s2)
{
return(strcmp($s1['fileName'], $s2['fileName']));
return strcmp($s1['fileName'], $s2['fileName']);
}
}

View file

@ -19,43 +19,44 @@
*
*/
if(!defined('B1GMAIL_INIT'))
if (!defined('B1GMAIL_INIT')) {
die('Directly calling this file is not supported');
}
/**
* ZIP class
*
* ZIP class.
*/
class BMZIP
{
/**
* b1gZIP stream (used if b1gZIP is installed)
* b1gZIP stream (used if b1gZIP is installed).
*
* @var resource
*/
var $_b1gzip_stream;
private $_b1gzip_stream;
/**
* output stream
* output stream.
*
* @var resource
*/
var $_fp;
private $_fp;
/**
* central directory structure
* central directory structure.
*
* @var array
*/
var $_centralDirStruct;
private $_centralDirStruct;
/**
* constructor
* constructor.
*
* @param resource $fp Output stream
*
* @return BMZIP
*/
function __construct($fp)
public function __construct($fp)
{
// output stream
$this->_fp = $fp;
@ -63,67 +64,67 @@ class BMZIP
// use b1gZIP?
if (function_exists('b1gzip_create')
&& function_exists('b1gzip_add')
&& function_exists('b1gzip_final'))
{
&& function_exists('b1gzip_final')) {
$this->_b1gzip_stream = b1gzip_create();
}
else
{
} else {
$this->_b1gzip_stream = false;
$this->_centralDirStruct = array();
$this->_centralDirStruct = [];
}
}
/**
* add a file to ZIP file
* add a file to ZIP file.
*
* @param string $fileName File name
* @param string $zipFileName File name in ZIP file
*
* @return bool
*/
function AddFile($fileName, $zipFileName = false)
public function AddFile($fileName, $zipFileName = false)
{
$fileFP = @fopen($fileName, 'rb');
if($fileFP)
{
if ($fileFP) {
$result = $this->AddFileByFP($fileFP, $fileName, $zipFileName);
fclose($fileFP);
return($result);
return $result;
} else {
return false;
}
else
return(false);
}
/**
* add a file to ZIP file by file pointer
* add a file to ZIP file by file pointer.
*
* @param resource $fileFP
* @param string $fileName
* @param string $zipFileName
*
* @return bool
*/
function AddFileByFP($fileFP, $fileName, $zipFileName = false)
public function AddFileByFP($fileFP, $fileName, $zipFileName = false)
{
if(!$zipFileName)
if (!$zipFileName) {
$zipFileName = basename($fileName);
}
// read file
fseek($fileFP, 0, SEEK_SET);
$fileData = '';
while(is_resource($fileFP) && !feof($fileFP))
while (is_resource($fileFP) && !feof($fileFP)) {
$fileData .= @fread($fileFP, 4096);
}
$uncompressedSize = strlen($fileData);
// use b1gZIP
if($this->_b1gzip_stream)
{
if ($this->_b1gzip_stream) {
b1gzip_add($this->_b1gzip_stream, $fileData, $zipFileName);
return(true);
return true;
}
// or own implementation
else
{
else {
// compute crc32
$crc32 = crc32($fileData);
$compressedData = gzcompress($fileData);
@ -136,18 +137,18 @@ class BMZIP
fwrite($this->_fp, $compressedData);
}
return(false);
return false;
}
/**
* begin file
* begin file.
*
* @param int $crc32
* @param int $compressedSize
* @param int $uncompressedSize
* @param string $fileName
*/
function _beginFile($crc32, $compressedSize, $uncompressedSize, $fileName)
private function _beginFile($crc32, $compressedSize, $uncompressedSize, $fileName)
{
// local header
$header = pack('VvvvvvVVVvv',
@ -190,29 +191,27 @@ class BMZIP
}
/**
* finish zip file
* finish zip file.
*
* @return int Size
*/
function Finish()
public function Finish()
{
// use b1gZIP?
if($this->_b1gzip_stream)
{
if ($this->_b1gzip_stream) {
$zipData = b1gzip_final($this->_b1gzip_stream);
fwrite($this->_fp, $zipData);
fseek($this->_fp, 0, SEEK_SET);
return(strlen($zipData));
return strlen($zipData);
}
// or own implementation
else
{
else {
// write central dir struct
$offset = ftell($this->_fp);
$dLength = 0;
foreach($this->_centralDirStruct as $item)
{
foreach ($this->_centralDirStruct as $item) {
fwrite($this->_fp, $item);
$dLength += strlen($item);
}
@ -232,7 +231,8 @@ class BMZIP
// return
$len = ftell($this->_fp);
fseek($this->_fp, 0, SEEK_SET);
return($len);
return $len;
}
}
}