mirror of
https://github.com/processwire/processwire.git
synced 2025-08-16 03:34:33 +02:00
Attempt fix for issue processwire/processwire-issues#989
This commit is contained in:
@@ -608,7 +608,7 @@ class Template extends WireData implements Saveable, Exportable {
|
|||||||
$this->setFieldgroup($value);
|
$this->setFieldgroup($value);
|
||||||
|
|
||||||
} else if($key == 'filename') {
|
} else if($key == 'filename') {
|
||||||
$this->setFilename($value);
|
$this->filename($value);
|
||||||
|
|
||||||
} else if($key == 'roles') {
|
} else if($key == 'roles') {
|
||||||
$this->setRoles($value);
|
$this->setRoles($value);
|
||||||
@@ -795,24 +795,11 @@ class Template extends WireData implements Saveable, Exportable {
|
|||||||
* Set this template's filename, with or without path
|
* Set this template's filename, with or without path
|
||||||
*
|
*
|
||||||
* @param string $value The filename with or without path
|
* @param string $value The filename with or without path
|
||||||
|
* @deprecated Now just using filename() method
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected function setFilename($value) {
|
protected function setFilename($value) {
|
||||||
if(empty($value)) return;
|
$this->filename($value);
|
||||||
|
|
||||||
if(strpos($value, '/') === false) {
|
|
||||||
// value is basename
|
|
||||||
$value = $this->config->paths->templates . $value;
|
|
||||||
|
|
||||||
} else if(strpos($value, $this->config->paths->root) !== 0) {
|
|
||||||
// value is path outside of our installation root, which we do not accept
|
|
||||||
$value = $this->config->paths->templates . basename($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(file_exists($value)) {
|
|
||||||
$this->filename = $value;
|
|
||||||
$this->filenameExists = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -879,39 +866,56 @@ class Template extends WireData implements Saveable, Exportable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return corresponding template filename, including path
|
* Return corresponding template filename including path, or set template filename
|
||||||
*
|
*
|
||||||
* #pw-group-files
|
* #pw-group-files
|
||||||
*
|
*
|
||||||
|
* @param string $filename Specify basename or path+basename to set, or omit to get filename. This argument added 3.0.143.
|
||||||
* @return string
|
* @return string
|
||||||
* @throws WireException
|
* @throws WireException
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function filename() {
|
public function filename($filename = null) {
|
||||||
|
|
||||||
/** @var Config $config */
|
/** @var Config $config */
|
||||||
$config = $this->wire('config');
|
$config = $this->wire('config');
|
||||||
$path = $config->paths->templates;
|
$path = $config->paths->templates;
|
||||||
$ext = '.' . $config->templateExtension;
|
|
||||||
$altFilename = $this->altFilename;
|
|
||||||
|
|
||||||
if(!$this->settings['name']) {
|
if($filename !== null) {
|
||||||
throw new WireException("Template must be assigned a name before 'filename' can be accessed");
|
// setting filename
|
||||||
}
|
if(empty($filename) || !is_string($filename)) {
|
||||||
|
// set to empty
|
||||||
if($altFilename) {
|
$filename = '';
|
||||||
$filename = $path . basename($altFilename, $ext) . $ext;
|
} else if(strpos($filename, '/') === false) {
|
||||||
} else {
|
// value is basename
|
||||||
$filename = $path . $this->settings['name'] . $ext;
|
$filename = $path . $filename;
|
||||||
}
|
} else if(strpos($filename, $config->paths->root) !== 0) {
|
||||||
|
// value is path outside of our installation root, which we do not accept
|
||||||
if($filename !== $this->filename) {
|
$filename = $path . basename($filename);
|
||||||
// first set of filename, or filename/path has been changed
|
}
|
||||||
$this->filenameExists = null;
|
if($filename !== $this->filename) $this->filenameExists = null;
|
||||||
$this->filename = $filename;
|
$this->filename = $filename;
|
||||||
|
|
||||||
|
} else if($this->filename) {
|
||||||
|
// get existing filename
|
||||||
|
$filename = $this->filename;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// get filename and determine what it is from template settings
|
||||||
|
$ext = '.' . $config->templateExtension;
|
||||||
|
$altFilename = $this->altFilename;
|
||||||
|
if($altFilename) {
|
||||||
|
$filename = $path . basename($altFilename, $ext) . $ext;
|
||||||
|
} else if(!$this->settings['name']) {
|
||||||
|
throw new WireException("Template must be assigned a name before 'filename' can be accessed");
|
||||||
|
} else {
|
||||||
|
$filename = $path . $this->settings['name'] . $ext;
|
||||||
|
}
|
||||||
|
$this->filename = $filename;
|
||||||
|
$this->filenameExists = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->filenameExists === null) {
|
if($this->filenameExists === null && $filename) {
|
||||||
$this->filenameExists = file_exists($filename);
|
$this->filenameExists = file_exists($filename);
|
||||||
if($this->filenameExists) {
|
if($this->filenameExists) {
|
||||||
// if filename exists, keep track of last modification time
|
// if filename exists, keep track of last modification time
|
||||||
@@ -933,7 +937,6 @@ class Template extends WireData implements Saveable, Exportable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $filename;
|
return $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user