diff --git a/wire/core/Field.php b/wire/core/Field.php index 5874b2a5..913f6e5c 100644 --- a/wire/core/Field.php +++ b/wire/core/Field.php @@ -1243,14 +1243,16 @@ class Field extends WireData implements Saveable, Exportable { * */ protected function getText($property, $language = null) { - if(is_null($language)) $language = $this->wire('languages') ? $this->wire('user')->language : null; - if($language) { - $value = $this->get("$property$language"); - if(!strlen($value)) $value = $this->$property; - } else { - $value = $this->$property; + if(is_null($language)) { + $language = $this->wire()->languages ? $this->wire()->user->language : null; } - if($property == 'label' && !strlen($value)) $value = $this->name; + if($language) { + $value = (string) $this->get("$property$language"); + if(!strlen($value)) $value = (string) $this->$property; + } else { + $value = (string) $this->$property; + } + if($property === 'label' && !strlen($value)) $value = $this->name; return $value; } diff --git a/wire/core/Pagefiles.php b/wire/core/Pagefiles.php index 3c073c69..ce2e9912 100644 --- a/wire/core/Pagefiles.php +++ b/wire/core/Pagefiles.php @@ -574,18 +574,20 @@ class Pagefiles extends WireArray implements PageFieldValueInterface { */ public function cleanBasename($basename, $originalize = false, $allowDots = true, $translate = false) { + $sanitizer = $this->wire()->sanitizer; $basename = function_exists('mb_strtolower') ? mb_strtolower($basename) : strtolower($basename); $dot = strrpos($basename, '.'); - $ext = $dot ? substr($basename, $dot) : ''; + $ext = $dot ? substr($basename, $dot) : ''; $basename = basename($basename, $ext); + while(strpos($basename, '..') !== false) $basename = str_replace('..', '', $basename); $test = str_replace(array('-', '_', '.'), '', $basename); if(!ctype_alnum($test)) { if($translate) { - $basename = $this->wire('sanitizer')->filename($basename, Sanitizer::translate); + $basename = $sanitizer->filename($basename, Sanitizer::translate); } else { $basename = preg_replace('/[^-_.a-z0-9]/', '_', $basename); - $basename = $this->wire('sanitizer')->filename($basename); + $basename = $sanitizer->filename($basename); } } diff --git a/wire/core/Sanitizer.php b/wire/core/Sanitizer.php index ba659cc7..7ab1c46b 100644 --- a/wire/core/Sanitizer.php +++ b/wire/core/Sanitizer.php @@ -1802,7 +1802,7 @@ class Sanitizer extends Wire { if(!strlen($value)) return ''; $scheme = parse_url($value, PHP_URL_SCHEME); - if($scheme !== false && strlen($scheme)) { + if(is_string($scheme) && strlen($scheme)) { $_scheme = $scheme; $scheme = strtolower($scheme); $schemeError = false; diff --git a/wire/core/Template.php b/wire/core/Template.php index 1616b161..86aa0e9f 100644 --- a/wire/core/Template.php +++ b/wire/core/Template.php @@ -1313,12 +1313,14 @@ class Template extends WireData implements Saveable, Exportable { * */ public function getLabel($language = null) { - if(is_null($language)) $language = $this->wire('languages') ? $this->wire('user')->language : null; + if(is_null($language)) { + $language = $this->wire()->languages ? $this->wire()->user->language : null; + } if($language) { - $label = $this->get("label$language"); + $label = (string) $this->get("label$language"); if(!strlen($label)) $label = $this->label; } else { - $label = $this->label; + $label = (string) $this->label; } if(!strlen($label)) $label = $this->name; return $label; diff --git a/wire/core/WireDatabasePDO.php b/wire/core/WireDatabasePDO.php index 79a8f548..b7c1959c 100644 --- a/wire/core/WireDatabasePDO.php +++ b/wire/core/WireDatabasePDO.php @@ -1412,7 +1412,7 @@ class WireDatabasePDO extends Wire implements WireDatabase { * */ public function escapeTable($table) { - $table = (string) trim($table); + $table = (string) trim("$table"); if(ctype_alnum($table)) return $table; if(ctype_alnum(str_replace('_', '', $table))) return $table; return preg_replace('/[^_a-zA-Z0-9]/', '_', $table); diff --git a/wire/modules/Inputfield/InputfieldEmail.module b/wire/modules/Inputfield/InputfieldEmail.module index 48efa09f..0a046031 100644 --- a/wire/modules/Inputfield/InputfieldEmail.module +++ b/wire/modules/Inputfield/InputfieldEmail.module @@ -88,6 +88,7 @@ class InputfieldEmail extends InputfieldText { * */ protected function setAttributeValue($value) { + $value = (string) $value; if(strlen($value)) { $value = $this->wire()->sanitizer->email($value); if(!strlen($value)) $this->error($this->_("Please enter a valid e-mail address")); // Error message when email address is invalid diff --git a/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module b/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module index 66b23a6b..1dbc2ec1 100644 --- a/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module +++ b/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module @@ -958,18 +958,20 @@ class InputfieldFile extends Inputfield implements InputfieldItemList, Inputfiel // rename (currently only used by InputfieldImage) $key = "rename_$id"; - $rename = $input->$key; + $rename = (string) $input->$key; if(strlen($rename) && $rename != $pagefile->basename(false)) { $name = $pagefile->basename(); $rename .= "." . $pagefile->ext(); // cleanBasename($basename, $originalize = false, $allowDots = true, $translate = false) $rename = $pagefile->pagefiles->cleanBasename($rename, true, true, true); - $message = sprintf($this->_('Renamed file "%1$s" to "%2$s"'), $name, $rename); - if($pagefile->rename($rename) !== false) { - $this->message($message); - $changed = true; - } else { - $this->warning($this->_('Failed') . " - $message"); + if(strlen($rename)) { + $message = sprintf($this->_('Renamed file "%1$s" to "%2$s"'), $name, $rename); + if($pagefile->rename($rename) !== false) { + $this->message($message); + $changed = true; + } else { + $this->warning($this->_('Failed') . " - $message"); + } } } diff --git a/wire/modules/Inputfield/InputfieldHidden.module b/wire/modules/Inputfield/InputfieldHidden.module index 8eeb43f3..0642f3a6 100644 --- a/wire/modules/Inputfield/InputfieldHidden.module +++ b/wire/modules/Inputfield/InputfieldHidden.module @@ -15,7 +15,7 @@ class InputfieldHidden extends Inputfield { 'version' => 101, 'summary' => __('Hidden value in a form', __FILE__), // Module Summary 'permanent' => true, - ); + ); } public function __construct() { @@ -39,7 +39,7 @@ class InputfieldHidden extends Inputfield { public function getAttributes() { $attrs = parent::getAttributes(); - if(!strlen($attrs['value']) && $this->initValue) $attrs['value'] = $this->initValue; + if(!strlen("$attrs[value]") && $this->initValue) $attrs['value'] = (string) $this->initValue; return $attrs; } @@ -60,6 +60,7 @@ class InputfieldHidden extends Inputfield { $field->description = $this->_('Value to be populated in this hidden field.'); $field->setAttribute('value', $this->initValue); $inputfields->append($field); + return $inputfields; } diff --git a/wire/modules/Inputfield/InputfieldInteger.module b/wire/modules/Inputfield/InputfieldInteger.module index 375225b2..ecc4f379 100644 --- a/wire/modules/Inputfield/InputfieldInteger.module +++ b/wire/modules/Inputfield/InputfieldInteger.module @@ -96,6 +96,7 @@ class InputfieldInteger extends Inputfield { */ protected function sanitizeValue($value) { if(is_int($value)) return $value; + $value = (string) $value; $value = trim($value); if(!strlen("$value")) return ''; $negative = substr($value, 0, 1) === '-'; diff --git a/wire/modules/Inputfield/InputfieldMarkup.module b/wire/modules/Inputfield/InputfieldMarkup.module index 51b7b972..aa6a1fb0 100644 --- a/wire/modules/Inputfield/InputfieldMarkup.module +++ b/wire/modules/Inputfield/InputfieldMarkup.module @@ -42,7 +42,7 @@ class InputfieldMarkup extends InputfieldWrapper { public function ___render() { $out = ''; - $value = $this->attr('value'); + $value = (string) $this->attr('value'); if(strlen($value)) { $out .= "\n" . $value; @@ -63,9 +63,9 @@ class InputfieldMarkup extends InputfieldWrapper { if(wireCount($textformatters)) { foreach($textformatters as $className) { - $t = $this->wire('modules')->get($className); + $t = $this->wire()->modules->get($className); if(!$t) continue; - $t->formatValue($this->wire('page'), $this->wire(new Field()), $out); + $t->formatValue($this->wire()->page, $this->wire(new Field()), $out); } } @@ -101,22 +101,25 @@ class InputfieldMarkup extends InputfieldWrapper { } public function ___getConfigInputfields() { - + + $modules = $this->wire()->modules; $inputfields = parent::___getConfigInputfields(); if($this->hasFieldtype) return $inputfields; - $f = $this->wire('modules')->get('InputfieldTextarea'); + /** @var InputfieldTextarea $f */ + $f = $modules->get('InputfieldTextarea'); $f->attr('id+name', 'markupText'); $f->attr('value', $this->markupText); $f->attr('rows', 10); $f->label = $this->_('Markup Text'); $inputfields->add($f); - $f = $this->modules->get('InputfieldAsmSelect'); + /** @var InputfieldAsmSelect $f */ + $f = $modules->get('InputfieldAsmSelect'); $f->attr('id+name', 'textformatters'); $f->label = $this->_('Text Formatters'); - foreach($this->modules->find("className^=Textformatter") as $textformatter) { + foreach($modules->find("className^=Textformatter") as $textformatter) { $info = $textformatter->getModuleInfo(); $f->addOption($textformatter->className(), "$info[title]"); } diff --git a/wire/modules/Inputfield/InputfieldTextarea.module b/wire/modules/Inputfield/InputfieldTextarea.module index 99398d08..289539d1 100644 --- a/wire/modules/Inputfield/InputfieldTextarea.module +++ b/wire/modules/Inputfield/InputfieldTextarea.module @@ -106,13 +106,14 @@ class InputfieldTextarea extends InputfieldText { */ protected function setAttributeValue($value) { $maxlength = $this->attr('maxlength'); + $value = (string) $value; if($maxlength > 0 && $this->hasFieldtype === false) { - $value = $this->wire('sanitizer')->textarea($value, array( + $value = $this->wire()->sanitizer->textarea($value, array( 'maxLength' => $maxlength, 'maxBytes' => $maxlength*4, 'stripTags' => false, 'trim' => $this->noTrim ? false : true - )); + )); } else { if(strpos($value, "\r\n") !== false) { $value = str_replace("\r\n", "\n", $value); diff --git a/wire/modules/Inputfield/InputfieldToggle/InputfieldToggle.module b/wire/modules/Inputfield/InputfieldToggle/InputfieldToggle.module index ab9d846f..a46be093 100644 --- a/wire/modules/Inputfield/InputfieldToggle/InputfieldToggle.module +++ b/wire/modules/Inputfield/InputfieldToggle/InputfieldToggle.module @@ -443,7 +443,7 @@ class InputfieldToggle extends Inputfield { $prevValue = $this->val(); $value = $input[$this->name]; - $intValue = strlen($value) && ctype_digit("$value") ? (int) $value : null; + $intValue = strlen("$value") && ctype_digit("$value") ? (int) $value : null; if($value === null && $input["_{$this->name}_"] === null) { // input was not rendered in the submitted post, so should be ignored diff --git a/wire/modules/LanguageSupport/LanguageSupportFields.module b/wire/modules/LanguageSupport/LanguageSupportFields.module index 75167e39..6e10a23d 100644 --- a/wire/modules/LanguageSupport/LanguageSupportFields.module +++ b/wire/modules/LanguageSupport/LanguageSupportFields.module @@ -518,9 +518,10 @@ class LanguageSupportFields extends WireData implements Module { * */ public function isAlternateField($name) { + $name = (string) $name; if(isset($this->multilangAlternateFields[$name])) { // default language for an alternate field set - return $this->wire('languages')->getDefault(); + return $this->wire()->languages->getDefault(); } if(!strpos($name, '_')) return false; $language = $this->getAlternateFieldParent($name, true); diff --git a/wire/modules/Process/ProcessLogger/ProcessLogger.module b/wire/modules/Process/ProcessLogger/ProcessLogger.module index 19e3dd76..7cb0a3b7 100644 --- a/wire/modules/Process/ProcessLogger/ProcessLogger.module +++ b/wire/modules/Process/ProcessLogger/ProcessLogger.module @@ -143,54 +143,61 @@ class ProcessLogger extends Process { public function ___executeView() { - $name = $this->wire('input')->urlSegment2; - if(!$name) $this->wire('session')->redirect('../'); - $logs = $this->wire('log')->getLogs(); + $input = $this->wire()->input; + $session = $this->wire()->session; + $config = $this->wire()->config; + $modules = $this->wire()->modules; + $sanitizer = $this->wire()->sanitizer; + $log = $this->wire()->log; + + $name = $input->urlSegment2; + if(!$name) $session->redirect('../'); + $logs = $log->getLogs(); if(!isset($logs[$name])) { $this->error(sprintf('Unknown log: %s', $name)); - $this->wire('session')->redirect('../'); + $session->redirect('../'); } - $action = $this->wire('input')->post('action'); + $action = $input->post('action'); if($action) $this->processAction($action, $name); $limit = 100; $options = array('limit' => $limit); - $q = $this->wire('input')->get('q'); - if(strlen($q)) { - $options['text'] = $this->wire('sanitizer')->text($q); - $this->wire('input')->whitelist('q', $options['text']); + $q = $input->get('q'); + if($q !== null && strlen($q)) { + $options['text'] = $sanitizer->text($q); + $input->whitelist('q', $options['text']); } - $dateFrom = $this->wire('input')->get('date_from'); - if(strlen($dateFrom)) { + $dateFrom = $input->get('date_from'); + if($dateFrom !== null && strlen($dateFrom)) { $options['dateFrom'] = ctype_digit("$dateFrom") ? (int) $dateFrom : strtotime("$dateFrom 00:00:00"); - $this->wire('input')->whitelist('date_from', $options['dateFrom']); + $input->whitelist('date_from', $options['dateFrom']); } - $dateTo = $this->wire('input')->get('date_to'); - if(strlen($dateTo)) { + $dateTo = $input->get('date_to'); + if($dateTo !== null && strlen($dateTo)) { $options['dateTo'] = ctype_digit("$dateTo") ? (int) $dateTo : strtotime("$dateTo 23:59:59"); - $this->wire('input')->whitelist('date_to', $options['dateTo']); + $input->whitelist('date_to', $options['dateTo']); } - $options['pageNum'] = $this->wire('input')->pageNum; + $options['pageNum'] = (int) $input->pageNum; do { // since the total count the pagination is based on may not always be accurate (dups, etc.) // we migrate to the last populated pagination when items turn up empty - $items = $this->wire('log')->getEntries($name, $options); + $items = $log->getEntries($name, $options); if(count($items)) break; if($options['pageNum'] < 2) break; $options['pageNum']--; } while(1); - if($this->wire('config')->ajax) return $this->renderLogAjax($items, $name); + if($config->ajax) return $this->renderLogAjax($items, $name); /** @var InputfieldForm $form */ - $form = $this->wire('modules')->get('InputfieldForm'); + $form = $modules->get('InputfieldForm'); /** @var InputfieldFieldset $fieldset */ - $fieldset = $this->wire('modules')->get('InputfieldFieldset'); + $fieldset = $modules->get('InputfieldFieldset'); $fieldset->attr('id', 'FieldsetTools'); $fieldset->label = $this->_('Helpers'); $fieldset->collapsed = Inputfield::collapsedYes; @@ -198,7 +205,7 @@ class ProcessLogger extends Process { $form->add($fieldset); /** @var InputfieldText $f */ - $f = $this->wire('modules')->get('InputfieldText'); + $f = $modules->get('InputfieldText'); $f->attr('name', 'q'); $f->label = $this->_('Text Search'); $f->icon = 'search'; @@ -206,7 +213,7 @@ class ProcessLogger extends Process { $fieldset->add($f); /** @var InputfieldDatetime $f */ - $f = $this->wire('modules')->get('InputfieldDatetime'); + $f = $modules->get('InputfieldDatetime'); $f->attr('name', 'date_from'); $f->label = $this->_('Date From'); $f->icon = 'calendar'; @@ -216,7 +223,7 @@ class ProcessLogger extends Process { $fieldset->add($f); /** @var InputfieldDatetime $f */ - $f = $this->wire('modules')->get('InputfieldDatetime'); + $f = $modules->get('InputfieldDatetime'); $f->attr('name', 'date_to'); $f->icon = 'calendar'; $f->label = $this->_('Date To'); @@ -226,7 +233,7 @@ class ProcessLogger extends Process { $fieldset->add($f); /** @var InputfieldSelect $f */ - $f = $this->modules->get('InputfieldSelect'); + $f = $modules->get('InputfieldSelect'); $f->attr('name', 'action'); $f->label = $this->_('Actions'); $f->description = $this->_('Select an action below. You will be asked to click a button before the action is executed.'); @@ -235,14 +242,14 @@ class ProcessLogger extends Process { $f->addOption('download', $this->_('Download')); $fieldset->add($f); - if($this->wire('user')->hasPermission('logs-edit')) { + if($this->wire()->user->hasPermission('logs-edit')) { $f->addOption('add', $this->_('Grow (Add Entry)')); $f->addOption('prune', $this->_('Chop (Prune)')); $f->addOption('delete', $this->_('Burn (Delete)')); /** @var InputfieldInteger $f */ - $f = $this->wire('modules')->get('InputfieldInteger'); + $f = $modules->get('InputfieldInteger'); $f->attr('name', 'prune_days'); $f->label = $this->_('Chop To # Days'); $f->inputType = 'number'; @@ -255,7 +262,7 @@ class ProcessLogger extends Process { $fieldset->add($f); /** @var InputfieldText $f */ - $f = $this->wire('modules')->get('InputfieldText'); + $f = $modules->get('InputfieldText'); $f->attr('name', 'add_text'); $f->label = $this->_('New Log Entry'); $f->icon = 'leaf'; @@ -263,29 +270,30 @@ class ProcessLogger extends Process { $fieldset->add($f); /** @var InputfieldSubmit $f */ - $f = $this->wire('modules')->get('InputfieldSubmit'); + $f = $modules->get('InputfieldSubmit'); $f->value = $this->_('Chop this log file now'); $f->icon = 'cut'; $f->attr('name', 'submit_prune'); $f->showIf = 'action=prune'; $fieldset->add($f); - $f = $this->wire('modules')->get('InputfieldSubmit'); + $f = $modules->get('InputfieldSubmit'); $f->value = $this->_('Burn this log now (permanently delete)'); $f->icon = 'fire'; $f->attr('name', 'submit_delete'); $f->showIf = 'action=delete'; $fieldset->add($f); - $f = $this->wire('modules')->get('InputfieldSubmit'); + $f = $modules->get('InputfieldSubmit'); $f->value = $this->_('Add this log entry'); $f->icon = 'leaf'; $f->attr('name', 'submit_add'); $f->showIf = 'action=add'; $fieldset->add($f); } - - $f = $this->wire('modules')->get('InputfieldSubmit'); + + /** @var InputfieldSubmit $f */ + $f = $modules->get('InputfieldSubmit'); $f->value = $this->_('Download this log file now'); $f->icon = 'download'; $f->attr('name', 'submit_download'); @@ -293,17 +301,19 @@ class ProcessLogger extends Process { $fieldset->add($f); $this->headline(ucfirst($name)); - $this->breadcrumb('../../', $this->wire('page')->title); + $this->breadcrumb('../../', $this->wire()->page->title); - $out = $form->render() . + return + $form->render() . "