1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 00:06:55 +02:00

Minor adjustments to various classes

This commit is contained in:
Ryan Cramer
2019-11-06 15:18:41 -05:00
parent 098e5d03d7
commit dd87518987
4 changed files with 44 additions and 6 deletions

View File

@@ -10,7 +10,7 @@
* This file is licensed under the MIT license
* https://processwire.com/about/license/mit/
*
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer
* https://processwire.com
*
* @property ProcessWire $wire
@@ -37,6 +37,9 @@
* @property Config $config
* @property Fuel $fuel
* @property WireProfilerInterface $profiler
* @property WireFileTools $files
* @property WireMailTools $mail
* @property WireDateTime $datetime
*
*/
class Fuel implements \IteratorAggregate {
@@ -66,6 +69,17 @@ class Fuel implements \IteratorAggregate {
protected $requiredInterfaces = array(
'profiler' => 'WireProfilerInterface'
);
/**
* The most common API variable names, those likely to be called multiple times in any request
*
* @var array
*
*/
static protected $commonNames = array(
'page' => 1, 'pages' => 1, 'session' => 1, 'input' => 1, 'sanitizer' => 1, 'config' => 1,
'user' => 1, 'users' => 1, 'fields' => 1, 'templates' => 1, 'database' => 1, 'modules' => 1,
);
/**
* @param string $key API variable name to set - should be valid PHP variable name.
@@ -110,6 +124,10 @@ class Fuel implements \IteratorAggregate {
public function __get($key) {
return isset($this->data[$key]) ? $this->data[$key] : null;
}
public function get($key) {
return isset($this->data[$key]) ? $this->data[$key] : null;
}
public function getIterator() {
return new \ArrayObject($this->data);
@@ -119,4 +137,7 @@ class Fuel implements \IteratorAggregate {
return $this->data;
}
public static function isCommon($name) {
return isset(self::$commonNames[$name]);
}
}

View File

@@ -767,6 +767,19 @@ class PageFinder extends Wire {
// allow any Fieldtype that is an instance of given one, or extends it
if(!wireInstanceOf($f->type, $fieldtype)
&& ($fieldtypeLang === null || !wireInstanceOf($f->type, $fieldtypeLang))) continue;
/** potential replacement for the above 2 lines
if($f->type->className() === $fieldName) {
// always allowed
} else if(!wireInstanceOf($f->type, $fieldtype) && ($fieldtypeLang === null || !wireInstanceOf($f->type, $fieldtypeLang))) {
// this fields type does not extend the one we are looking for
continue;
} else {
// looks good, but now check operators
$selectorInfo = $f->type->getSelectorInfo($f);
// if operator used in selector is not an allowed one, then skip over this field
if(!in_array($selector->operator(), $selectorInfo['operators'])) continue;
}
*/
} else {
// only allow given Fieldtype
@@ -1979,11 +1992,11 @@ class PageFinder extends Wire {
throw new PageFinderSyntaxException("Operator '$selector->operator' is not supported for path or url unless: 1) non-multi-language; 2) you install the PagePaths module.");
}
if($selector->value == '/') {
$selectorValue = $selector->value;
if($selectorValue === '/') {
$parts = array();
$query->where("pages.id=1");
} else {
$selectorValue = $selector->value;
if(is_array($selectorValue)) {
// only the PagePaths module can perform OR value searches on path/url
if($langNames) {
@@ -1997,7 +2010,7 @@ class PageFinder extends Wire {
$part = $database->escapeStr($this->wire('sanitizer')->pageName(array_pop($parts), Sanitizer::toAscii));
$sql = "pages.name='$part'";
if($langNames) foreach($langNames as $name) $sql .= " OR pages.$name='$part'";
$query->where($sql);
$query->where("($sql)");
if(!count($parts)) $query->where("pages.parent_id=1");
}

View File

@@ -20,6 +20,8 @@ require_once(__DIR__ . '/boot.php');
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer
* https://processwire.com
*
* @property Fuel $fuel
*
* @method init()
* @method ready()
* @method finished()
@@ -734,8 +736,9 @@ class ProcessWire extends Wire {
}
public function __get($key) {
if($key == 'shutdown') return $this->shutdown;
if($key == 'instanceID') return $this->instanceID;
if($key === 'fuel') return $this->fuel;
if($key === 'shutdown') return $this->shutdown;
if($key === 'instanceID') return $this->instanceID;
return parent::__get($key);
}

View File

@@ -502,6 +502,7 @@ class WireTextTools extends Wire {
$tests = array();
$punctuationChars = $this->getPunctuationChars();
$endSentenceChars = $this->getPunctuationChars(true);
$endSentenceChars[] = ':';
if($options['keepFormatTags']) {
$options['keepTags'] = array_merge($options['keepTags'], array(