Skip to content

Commit

Permalink
Adds support for files path and url with a query string in FSFile and…
Browse files Browse the repository at this point in the history
… Plugin libraries.
  • Loading branch information
JB Lebrun committed Sep 28, 2018
1 parent 89e20c9 commit 6d7338a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
48 changes: 26 additions & 22 deletions engine/lib/object/FSFile.php.inc
Expand Up @@ -4,11 +4,11 @@
* @details Engine / Object Library * @details Engine / Object Library
* @file engine/lib/object/FSFile.php.inc * @file engine/lib/object/FSFile.php.inc
* @author CaMykS Team <camyks.contact@gmail.com> * @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0 * @version 1.0.1
* @date Creation: Jun 2007 * @date Creation: Jun 2007
* @date Modification: Apr 2018 * @date Modification: Sep 2018
* @copyright 2007 - 2018 CaMykS Team * @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. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/ */


Expand All @@ -22,85 +22,85 @@ final class FSFile {
* @brief File name. * @brief File name.
*/ */
public $filename; public $filename;

/** /**
* @var string $path * @var string $path
* @brief File path. * @brief File path.
*/ */
public $path; public $path;

/** /**
* @var string $fullpath * @var string $fullpath
* @brief Full file path with file name. * @brief Full file path with file name.
*/ */
public $fullpath; public $fullpath;

/** /**
* @var boolean $exists * @var boolean $exists
* @brief File exists. * @brief File exists.
*/ */
public $exists; public $exists;

/** /**
* @var integer $size * @var integer $size
* @brief File size in octet/byte. * @brief File size in octet/byte.
*/ */
public $size; public $size;

/** /**
* @var string $hsize * @var string $hsize
* @brief Human readable file size. * @brief Human readable file size.
*/ */
public $hsize; public $hsize;

/** /**
* @var string $mime * @var string $mime
* @brief File mime. * @brief File mime.
*/ */
public $mime; public $mime;

/** /**
* @var string $type * @var string $type
* @brief File type, first part of mime value. * @brief File type, first part of mime value.
*/ */
public $type; public $type;

/** /**
* @var string $ext * @var string $ext
* @brief File extension. * @brief File extension.
*/ */
public $ext; public $ext;

/** /**
* @var integer $atime * @var integer $atime
* @brief File last opening time. * @brief File last opening time.
*/ */
public $atime; public $atime;

/** /**
* @var integer $mtime * @var integer $mtime
* @brief File last modification time. * @brief File last modification time.
*/ */
public $mtime; public $mtime;

/** /**
* @var integer $ctime * @var integer $ctime
* @brief File inode change time. * @brief File inode change time.
*/ */
public $ctime; public $ctime;

/** /**
* @var string $mimedesc * @var string $mimedesc
* @brief File mime description. * @brief File mime description.
*/ */
public $mimedesc; public $mimedesc;

/** /**
* @var string $typedesc * @var string $typedesc
* @brief File type description. * @brief File type description.
*/ */
public $typedesc; public $typedesc;

/** /**
* @var array $moreinfos * @var array $moreinfos
* @brief File additional information. * @brief File additional information.
Expand All @@ -115,10 +115,14 @@ final class FSFile {
*/ */
public function __construct($path='', $file=null) { public function __construct($path='', $file=null) {
if (isset($file)) { if (isset($file)) {
$f = explode('?', $file);
$file = $f[0];
$this->filename = $file; $this->filename = $file;
$this->path = $path; $this->path = $path;
$this->fullpath = $path.'/'.$file; $this->fullpath = $path.'/'.$file;
} else { } else {
$f = explode('?', $path);
$path = $f[0];
$this->fullpath = $path; $this->fullpath = $path;
$p = explode('/', $path); $p = explode('/', $path);
$this->filename = array_pop($p); $this->filename = array_pop($p);
Expand All @@ -140,7 +144,7 @@ final class FSFile {
return; return;
} }
/* get file extension */ /* get file extension */
if (preg_match('/.*\.([^\.]*)/', $this->filename, $ext)) if (preg_match('/.*\.([^\.]*)/', $this->filename, $ext))
$this->ext = $ext[1]; $this->ext = $ext[1];
else else
$this->ext = ''; $this->ext = '';
Expand All @@ -165,7 +169,7 @@ final class FSFile {
$this->type = $t[0]; $this->type = $t[0];
} }


/* /*
* Load file stats. * Load file stats.
* @return void * @return void
*/ */
Expand Down Expand Up @@ -230,7 +234,7 @@ final class FSFile {
* @param string title overwrite title value * @param string title overwrite title value
* @return void * @return void
*/ */
public function download($title=null) { public function download($title=null) {
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/octet-stream'); header('Content-Type: application/octet-stream');
header('Content-Description: File Transfer'); header('Content-Description: File Transfer');
Expand Down Expand Up @@ -279,4 +283,4 @@ final class FSFile {
return 'data:'.$this->mime.';base64,'.base64_encode(file_get_contents($this->fullpath)); return 'data:'.$this->mime.';base64,'.base64_encode(file_get_contents($this->fullpath));
} }
} }
?> ?>
37 changes: 26 additions & 11 deletions engine/lib/object/Plugin.php.inc
Expand Up @@ -5,7 +5,7 @@
* @details Engine / Object Library * @details Engine / Object Library
* @file engine/lib/object/Plugin.php.inc * @file engine/lib/object/Plugin.php.inc
* @author CaMykS Team <camyks.contact@gmail.com> * @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0.6 * @version 1.0.7
* @date Creation: Jun 2005 * @date Creation: Jun 2005
* @date Modification: Sep 2018 * @date Modification: Sep 2018
* @copyright 2005 - 2018 CaMykS Team * @copyright 2005 - 2018 CaMykS Team
Expand Down Expand Up @@ -224,7 +224,7 @@ abstract class Plugin {
* \e 1 Absolute <br /> * \e 1 Absolute <br />
* \e 2 Relative <br /> * \e 2 Relative <br />
* @endparblock * @endparblock
* @return void * @return string
*/ */
public function get_engineFileURL($file='', $path=false) { public function get_engineFileURL($file='', $path=false) {
global $camyks; global $camyks;
Expand Down Expand Up @@ -258,18 +258,25 @@ abstract class Plugin {
public function get_fileURL($file='', $path=null, $default='') { public function get_fileURL($file='', $path=null, $default='') {
global $camyks; global $camyks;


/* check for query string on file */
$f = explode('?', $file);
$f = $f[0];

/* check base url */
switch ($path) { switch ($path) {
case 2: $baseURL = ''; break; case 2: $baseURL = ''; break;
case true: case 1: $baseURL = $camyks->get_rootBaseURL('absolute'); break; case true: case 1: $baseURL = $camyks->get_rootBaseURL('absolute'); break;
case 0: default : $baseURL = $camyks->get_rootBaseURL($path); break; case 0: default : $baseURL = $camyks->get_rootBaseURL($path); break;
} }


/* get file url in site plugin folder */ /* return file url from site plugin folder */
if (file_exists ($this->plugin_site_path.'/'.$file)) if (file_exists ($this->plugin_site_path.'/'.$f))
return $baseURL.$this->plugin_site_url.'/'.$file; 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; return $baseURL.$this->plugin_url.'/'.$file;

/* get default file url */ /* get default file url */
return $default; return $default;
} }
Expand Down Expand Up @@ -302,11 +309,19 @@ abstract class Plugin {
* @return string * @return string
*/ */
public function get_filePath($file='') { public function get_filePath($file='') {
if (file_exists($this->plugin_site_path.'/'.$file)) { /* check for query string on file */
return $this->plugin_site_path.'/'.$file ; $f = explode('?', $file);
} else if (file_exists ($this->plugin_path.'/'.$file)) { $f = $f[0];
return $this->plugin_path.'/'.$file ;
} /* 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 ''; return '';
} }


Expand Down

0 comments on commit 6d7338a

Please sign in to comment.