mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 16:26:59 +02:00
Additional updates for processwire/processwire-issues#1467 via @matjazpotocnik
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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) : '';
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
|
@@ -958,12 +958,13 @@ 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);
|
||||
if(strlen($rename)) {
|
||||
$message = sprintf($this->_('Renamed file "%1$s" to "%2$s"'), $name, $rename);
|
||||
if($pagefile->rename($rename) !== false) {
|
||||
$this->message($message);
|
||||
@@ -972,6 +973,7 @@ class InputfieldFile extends Inputfield implements InputfieldItemList, Inputfiel
|
||||
$this->warning($this->_('Failed') . " - $message");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// description and tags
|
||||
$languages = $this->noLang ? null : $this->wire('languages');
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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) === '-';
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,21 +102,24 @@ 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]");
|
||||
}
|
||||
|
@@ -106,8 +106,9 @@ 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,
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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,21 +270,21 @@ 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');
|
||||
@@ -285,7 +292,8 @@ class ProcessLogger extends Process {
|
||||
$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() .
|
||||
"<div id='ProcessLogEntries'>" .
|
||||
$this->renderLog($items, $name) .
|
||||
"</div>";
|
||||
return $out;
|
||||
}
|
||||
|
||||
protected function renderLogAjax(array $items, $name) {
|
||||
$time = (int) $this->wire('input')->get('time');
|
||||
$input = $this->wire()->input;
|
||||
|
||||
$time = (int) $input->get('time');
|
||||
$render = true;
|
||||
$qtyNew = 0;
|
||||
$note = '';
|
||||
@@ -324,7 +334,7 @@ class ProcessLogger extends Process {
|
||||
'out' => '',
|
||||
'note' => $note,
|
||||
'time' => time(),
|
||||
'url' => $this->wire('input')->url() . '?' . $this->wire('input')->queryString()
|
||||
'url' => $input->url() . '?' . $input->queryString()
|
||||
);
|
||||
if($render) {
|
||||
$data = array_merge($data, array(
|
||||
|
@@ -2948,7 +2948,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod
|
||||
*
|
||||
*/
|
||||
public function getRedirectUrl(array $extras = array()) {
|
||||
$url = $this->redirectUrl;
|
||||
$url = (string) $this->redirectUrl;
|
||||
if(!strlen($url)) $url = "./?id=$this->id";
|
||||
if($this->requestModal && strpos($url, 'modal=') === false) {
|
||||
$extras[] = "modal=$this->requestModal";
|
||||
|
@@ -920,7 +920,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule {
|
||||
$classOptions = '';
|
||||
foreach($optionalClasses as $class => $label) {
|
||||
$labelKey = array_search($label, $labels);
|
||||
$selected = strpos($input->get('class'), $class) !== false ? " selected='selected'" : '';
|
||||
$selected = strpos((string) $input->get('class'), $class) !== false ? " selected='selected'" : '';
|
||||
if($selected) $attrs['class'] .= " $class";
|
||||
$classOptions .= "<option$selected data-label='$labelKey' value='$class'>$label</option>";
|
||||
}
|
||||
|
Reference in New Issue
Block a user