Starting SP3

fixing file download + replacing message types
This commit is contained in:
lutranf
2014-11-27 18:56:36 +01:00
parent 12c1cf8001
commit f9b4505626
3 changed files with 61 additions and 50 deletions

View File

@@ -7,8 +7,8 @@
class Databap extends PhpObject
{
//Common Constants
const VERSION = '1.0.2'; //Versioning: <Main_Version>.<Enhancement_Package>.<Patch>-<Release_Candidate>
const VERSION_DATE = '24/10/2014';
const VERSION = '1.0.3'; //Versioning: <Main_Version>.<Enhancement_Package>.<Patch>-<Release_Candidate>
const VERSION_DATE = '27/11/2014';
const EXPECTED_PAGE_COOKIE = 'exp_page';
const MAIN_SEPARATOR = ' ';
const DATE_FORMAT = 'd/m/Y';
@@ -90,6 +90,26 @@ class Databap extends PhpObject
const MESSAGE_REBOOT = 'R';
const MESSAGE_ARTICLE = 'B';
const MESSAGE_NEWS = 'NW';
private static $MESSAGE_TYPES = array( 'user'=>self::MESSAGE_USER,
'add'=> array( 'code'=>self::MESSAGE_ADD_CODE,
'proc'=>self::MESSAGE_ADD_PROC,
'doc'=>self::MESSAGE_ADD_DOC,
'table'=>self::MESSAGE_ADD_TABLE),
'edit'=>array( 'code'=>self::MESSAGE_EDIT_CODE,
'proc'=>self::MESSAGE_EDIT_PROC,
'doc'=>self::MESSAGE_EDIT_DOC,
'table'=>self::MESSAGE_EDIT_TABLE),
'action'=>self::MESSAGE_ACTION,
'private'=>self::MESSAGE_PRIVATE,
'img'=>self::MESSAGE_IMG,
'9gag'=>self::MESSAGE_9GAG,
'nick'=>self::MESSAGE_NICK,
'status'=>self::MESSAGE_STATUS,
'conn'=>self::MESSAGE_CONN,
'invite'=>self::MESSAGE_INVITE,
'reboot'=>self::MESSAGE_REBOOT,
'article'=>self::MESSAGE_ARTICLE,
'news'=>self::MESSAGE_NEWS);
const DEFAULT_COMPANY_LOGO = 'logo_unknown_24.png';
const ALL_CHAN_ID = 1;
const ALL_CHAN_TEXT = 'A.l.l_C.h.a.n_I.n.c.l.u.d.e.d';
@@ -409,7 +429,8 @@ class Databap extends PhpObject
'reboot_delay'=>self::REBOOT_DELAY,
'versionHtml'=>$this->getItemBlock(),
'opt_console_no'=>self::OPT_CONSOLE_NO,
'types'=>$this->getTypeInfo('title'));
'types'=>$this->getTypeInfo('title'),
'msg_types'=>self::$MESSAGE_TYPES);
$oPage->setTag('constants', $this->jsonConvert($asConstants));
//Variables
@@ -1034,53 +1055,48 @@ class Databap extends PhpObject
public function getFile($iFileId)
{
$sFileName = $this->oMySql->selectValue(self::FILE_TABLE, 'file_name', $iFileId);
//File info
$asFileInfo = $this->oMySql->selectRow(self::FILE_TABLE, $iFileId);
$sFileName = $asFileInfo['file_name'];
$sFileExt = mb_strtolower(pathinfo($sFileName, PATHINFO_EXTENSION));
$sFileDesc = str_replace("&", '\&', str_replace(" ", '\ ', addslashes($asFileInfo['description']))).'.'.$sFileExt;
$sFilePath = self::DOC_FOLDER.$sFileName;
$sFileFullPath = dirname($_SERVER['SCRIPT_FILENAME'])."/".$sFilePath;
if(!file_exists($sFilePath))
{
die();
}
$sResult = '';
if(!file_exists($sFilePath)) header("HTTP/1.0 404 Not Found");
else
{
//get mime type
if(class_exists('finfo'))
//Get mime type & set headers
if(!class_exists('finfo')) $sMimetype = 'application/force-download';
else
{
$oFileInfo = new finfo(FILEINFO_MIME);
$sMimetype = $oFileInfo->file($sFileFullPath);
}
else
{
$sMimetype = 'application/force-download';
}
//set headers
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: public');
header('Content-Description: File Transfer');
header('Content-Type: '.$sMimetype);
header('Content-Disposition: attachment; filename='.$sFileName);
header('Content-Disposition: attachment; filename='.$sFileDesc);
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.@filesize($sFilePath));
// download
//Download
if ($oFile = @fopen($sFilePath, 'rb'))
{
while(!feof($oFile))
{
print(fread($oFile, 1024*8));
$sResult .= print_r(fread($oFile, 1024*8), true);
flush();
if(connection_status() != 0)
{
@fclose($oFile);
}
if(connection_status() != 0) @fclose($oFile);
}
@fclose($oFile);
}
}
return $sResult;
}
public function uploadImage()