Permalink
Browse files

Adds support for files path and url with a query string in FSFile and…

… Plugin libraries.
  • Loading branch information...
JB Lebrun
JB Lebrun committed Sep 28, 2018
1 parent 89e20c9 commit 6d7338a7b4ebe3ecaafa365d7d9c653a9b606fd5
Showing with 52 additions and 33 deletions.
  1. +26 −22 engine/lib/object/FSFile.php.inc
  2. +26 −11 engine/lib/object/Plugin.php.inc
@@ -4,11 +4,11 @@
* @details Engine / Object Library
* @file engine/lib/object/FSFile.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: Jun 2007
* @date Modification: Apr 2018
* @date Modification: Sep 2018
* @copyright 2007 - 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
@@ -22,85 +22,85 @@ final class FSFile {
* @brief File name.
*/
public $filename;
/**
* @var string $path
* @brief File path.
*/
public $path;
public $path;
/**
* @var string $fullpath
* @brief Full file path with file name.
*/
public $fullpath;
/**
* @var boolean $exists
* @brief File exists.
*/
public $exists;
/**
* @var integer $size
* @brief File size in octet/byte.
*/
public $size;
/**
* @var string $hsize
* @brief Human readable file size.
*/
public $hsize;
/**
* @var string $mime
* @brief File mime.
*/
public $mime;
/**
* @var string $type
* @brief File type, first part of mime value.
*/
public $type;
/**
* @var string $ext
* @brief File extension.
*/
public $ext;
/**
* @var integer $atime
* @brief File last opening time.
*/
public $atime;
/**
* @var integer $mtime
* @brief File last modification time.
*/
public $mtime;
/**
* @var integer $ctime
* @brief File inode change time.
*/
public $ctime;
/**
* @var string $mimedesc
* @brief File mime description.
*/
public $mimedesc;
/**
* @var string $typedesc
* @brief File type description.
*/
public $typedesc;
/**
* @var array $moreinfos
* @brief File additional information.
@@ -115,10 +115,14 @@ final class FSFile {
*/
public function __construct($path='', $file=null) {
if (isset($file)) {
$f = explode('?', $file);
$file = $f[0];
$this->filename = $file;
$this->path = $path;
$this->fullpath = $path.'/'.$file;
} else {
$f = explode('?', $path);
$path = $f[0];
$this->fullpath = $path;
$p = explode('/', $path);
$this->filename = array_pop($p);
@@ -140,7 +144,7 @@ final class FSFile {
return;
}
/* get file extension */
if (preg_match('/.*\.([^\.]*)/', $this->filename, $ext))
if (preg_match('/.*\.([^\.]*)/', $this->filename, $ext))
$this->ext = $ext[1];
else
$this->ext = '';
@@ -165,7 +169,7 @@ final class FSFile {
$this->type = $t[0];
}
/*
/*
* Load file stats.
* @return void
*/
@@ -230,7 +234,7 @@ final class FSFile {
* @param string title overwrite title value
* @return void
*/
public function download($title=null) {
public function download($title=null) {
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/octet-stream');
header('Content-Description: File Transfer');
@@ -279,4 +283,4 @@ final class FSFile {
return 'data:'.$this->mime.';base64,'.base64_encode(file_get_contents($this->fullpath));
}
}
?>
?>
@@ -5,7 +5,7 @@
* @details Engine / Object Library
* @file engine/lib/object/Plugin.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.6
* @version 1.0.7
* @date Creation: Jun 2005
* @date Modification: Sep 2018
* @copyright 2005 - 2018 CaMykS Team
@@ -224,7 +224,7 @@ abstract class Plugin {
* \e 1 Absolute <br />
* \e 2 Relative <br />
* @endparblock
* @return void
* @return string
*/
public function get_engineFileURL($file='', $path=false) {
global $camyks;
@@ -258,18 +258,25 @@ abstract class Plugin {
public function get_fileURL($file='', $path=null, $default='') {
global $camyks;
/* check for query string on file */
$f = explode('?', $file);
$f = $f[0];
/* check base url */
switch ($path) {
case 2: $baseURL = ''; break;
case true: case 1: $baseURL = $camyks->get_rootBaseURL('absolute'); break;
case 0: default : $baseURL = $camyks->get_rootBaseURL($path); break;
}
/* get file url in site plugin folder */
if (file_exists ($this->plugin_site_path.'/'.$file))
/* return file url from site plugin folder */
if (file_exists ($this->plugin_site_path.'/'.$f))
return $baseURL.$this->plugin_site_url.'/'.$file;
/* get file url in plugin folder */
if (file_exists ($this->plugin_path.'/'.$file))
/* return file url from plugin folder */
if (file_exists ($this->plugin_path.'/'.$f))
return $baseURL.$this->plugin_url.'/'.$file;
/* get default file url */
return $default;
}
@@ -302,11 +309,19 @@ abstract class Plugin {
* @return string
*/
public function get_filePath($file='') {
if (file_exists($this->plugin_site_path.'/'.$file)) {
return $this->plugin_site_path.'/'.$file ;
} else if (file_exists ($this->plugin_path.'/'.$file)) {
return $this->plugin_path.'/'.$file ;
}
/* check for query string on file */
$f = explode('?', $file);
$f = $f[0];
/* return file path from site plugin folder */
if (file_exists($this->plugin_site_path.'/'.$f))
return $this->plugin_site_path.'/'.$file;
/* return file path from camyks plugin folder */
if (file_exists($this->plugin_path.'/'.$f))
return $this->plugin_path.'/'.$file;
/* return default result */
return '';
}

0 comments on commit 6d7338a

Please sign in to comment.