mirror of
https://github.com/processwire/processwire.git
synced 2025-08-15 11:14:12 +02:00
Minor refactor of Page::getFieldSubfieldValue() method
This commit is contained in:
@@ -1326,22 +1326,39 @@ class Page extends WireData implements \Countable, WireMatchable {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected function getFieldSubfieldValue($key) {
|
protected function getFieldSubfieldValue($key) {
|
||||||
$value = null;
|
|
||||||
if(!strpos($key, '.')) return null;
|
if(!strpos($key, '.')) return null;
|
||||||
if($this->outputFormatting()) {
|
|
||||||
// allow limited access to field.subfield properties when output formatting is on
|
// we allow any field.subfield properties when output formatting is off
|
||||||
// we only allow known custom fields, and only 1 level of subfield
|
if(!$this->outputFormatting()) return $this->getDot($key);
|
||||||
list($key1, $key2) = explode('.', $key);
|
|
||||||
$field = $this->getField($key1);
|
// allow limited access to field.subfield properties when output formatting is on
|
||||||
if($field && !($field->flags & Field::flagSystem)) {
|
// we only allow known custom fields, and only 1 level of subfield
|
||||||
// known custom field, non-system
|
$keys = explode('.', $key);
|
||||||
// if neither is an API var, then we'll allow it
|
$key1 = $keys[0];
|
||||||
if(!$this->wire($key1) && !$this->wire($key2)) $value = $this->getDot("$key1.$key2");
|
$key2 = $keys[1];
|
||||||
}
|
$field = $this->getField($key1);
|
||||||
} else {
|
|
||||||
// we allow any field.subfield properties when output formatting is off
|
if(!$field || ($field->flags & Field::flagSystem)) return null;
|
||||||
|
|
||||||
|
// test if any parts of key can potentially refer to API variables
|
||||||
|
$api = false;
|
||||||
|
foreach($keys as $k) {
|
||||||
|
if($this->wire($k)) $api = true;
|
||||||
|
if($api) break;
|
||||||
|
}
|
||||||
|
if($api) return null; // do not allow dereference of API variables
|
||||||
|
|
||||||
|
// get first part of value
|
||||||
|
$value = $this->get($key1);
|
||||||
|
|
||||||
|
// then get second part of value
|
||||||
|
if($value instanceof WireData) {
|
||||||
|
$value = $value->get($key2);
|
||||||
|
} else if($value instanceof Wire) {
|
||||||
$value = $this->getDot($key);
|
$value = $this->getDot($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user