mirror of
https://github.com/processwire/processwire.git
synced 2025-08-19 21:11:43 +02:00
Minor code improvements and housekeeping for various core classes and modules
This commit is contained in:
@@ -34,7 +34,7 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
'ProcessLanguageTranslator',
|
||||
),
|
||||
'addFlag' => Modules::flagsNoUserConfig
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,6 +92,8 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->set('initialized', false);
|
||||
|
||||
@@ -129,7 +131,9 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
|
||||
// document which pages were already cached at this point, as their values may need
|
||||
// to be reloaded to account for language fields.
|
||||
foreach($pages->getCache() as $id => $value) $this->earlyCachedPages[$id] = $value;
|
||||
foreach($pages->getCache() as $id => $value) {
|
||||
$this->earlyCachedPages[$id] = $value;
|
||||
}
|
||||
|
||||
// prevent possible double init
|
||||
if($this->initialized) return;
|
||||
@@ -203,8 +207,8 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
$this->addHookAfter('Inputfield::processInput', $this, 'hookInputfieldAfterProcessInput');
|
||||
$this->addHookBefore('Inputfield::processInput', $this, 'hookInputfieldBeforeProcessInput');
|
||||
$this->addHookAfter('Field::getInputfield', $this, 'hookFieldGetInputfield');
|
||||
$this->pages->addHook('added', $this, 'hookPageAdded');
|
||||
$this->pages->addHook('deleteReady', $this, 'hookPageDeleteReady');
|
||||
$pages->addHook('added', $this, 'hookPageAdded');
|
||||
$pages->addHook('deleteReady', $this, 'hookPageDeleteReady');
|
||||
$this->addHook('Page::setLanguageValue', $this, 'hookPageSetLanguageValue');
|
||||
$this->addHook('Page::getLanguageValue', $this, 'hookPageGetLanguageValue');
|
||||
|
||||
@@ -257,7 +261,7 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
|
||||
// unset the values from all the early cached pages since they didn't recognize languages
|
||||
// this will force them to reload when accessed
|
||||
foreach($this->earlyCachedPages as $id => $p) {
|
||||
foreach($this->earlyCachedPages as /* $id => */ $p) {
|
||||
$t = $p->trackChanges();
|
||||
if($t) $p->setTrackChanges(false);
|
||||
foreach($fieldNames as $name) unset($p->$name);
|
||||
@@ -281,6 +285,9 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function editableInputfield(Inputfield $inputfield) {
|
||||
|
||||
$page = $this->wire()->page;
|
||||
|
||||
$alwaysAllowInputfields = array(
|
||||
'InputfieldWrapper',
|
||||
'InputfieldPageName',
|
||||
@@ -289,16 +296,18 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
'InputfieldHidden',
|
||||
);
|
||||
// ignore this call if in ProcessProfile
|
||||
if($this->wire('page')->process == 'ProcessProfile') return true;
|
||||
if($this->wire('page')->process == 'ProcessLanguage') return true;
|
||||
if($page->process == 'ProcessProfile') return true;
|
||||
if($page->process == 'ProcessLanguage') return true;
|
||||
|
||||
$user = $this->wire()->user;
|
||||
$languages = $this->wire()->languages;
|
||||
|
||||
$user = $this->wire('user');
|
||||
if($user->isSuperuser()) return true;
|
||||
if($inputfield->getSetting('useLanguages')) return true;
|
||||
if(!$this->LanguageSupportFields) return true;
|
||||
$permissions = $this->wire('languages')->getPageEditPermissions();
|
||||
$permissions = $languages->getPageEditPermissions();
|
||||
if(!isset($permissions['none'])) return true;
|
||||
if(!$this->wire('process') instanceof WirePageEditor) return true;
|
||||
if(!$this->wire()->process instanceof WirePageEditor) return true;
|
||||
if($inputfield->name == 'delete_page') return true;
|
||||
$allow = false;
|
||||
foreach($alwaysAllowInputfields as $type) {
|
||||
@@ -310,7 +319,8 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
}
|
||||
if($allow) return true;
|
||||
if($inputfield->hasFieldtype && $this->LanguageSupportFields->isAlternateField($inputfield->name)) return true;
|
||||
if($this->wire('languages')->editable('none')) return true;
|
||||
if($languages->editable('none')) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -378,7 +388,8 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
if(!strlen($label)) $label = $language->name;
|
||||
$class = 'LanguageSupport';
|
||||
$labelClass = 'LanguageSupportLabel detail';
|
||||
if(!$this->wire('languages')->editable($language)) {
|
||||
|
||||
if(!$this->wire()->languages->editable($language)) {
|
||||
$labelClass .= ' LanguageNotEditable';
|
||||
$class .= ' LanguageNotEditable';
|
||||
$label = "<s>$label</s>";
|
||||
@@ -393,6 +404,7 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
$out = "<div class='$class' id='langTab_$id' data-language='$language->id'>" .
|
||||
"<label for='$id' class='$labelClass'>$label</label>" . $out .
|
||||
"</div>";
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
@@ -407,6 +419,7 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
public function hookInputfieldAfterRender(HookEvent $event) {
|
||||
|
||||
static $numLanguages = null;
|
||||
|
||||
if(!$event->return) return; // if already empty, nothing to do
|
||||
|
||||
/** @var Inputfield $inputfield */
|
||||
@@ -415,14 +428,18 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
|
||||
$renderValueMode = $event->method == 'renderValue';
|
||||
|
||||
/** @var Languages $languages */
|
||||
$languages = $this->wire('languages');
|
||||
$languages = $this->wire()->languages;
|
||||
|
||||
if(is_null($numLanguages)) $numLanguages = $languages->count();
|
||||
|
||||
// provide an automatic translation for some system/default fields if they've not been overridden in the fields editor
|
||||
if($name == 'language' && $inputfield->label == 'Language') $inputfield->label = $this->_('Language'); // Label for 'language' field in user profile
|
||||
else if($name == 'email' && $inputfield->label == 'E-Mail Address') $inputfield->label = $this->_('E-Mail Address'); // Label for 'email' field in user profile
|
||||
else if($name == 'title' && $inputfield->label == 'Title') $inputfield->label = $this->_('Title'); // Label for 'title' field used throughout ProcessWire
|
||||
if($name == 'language' && $inputfield->label == 'Language') {
|
||||
$inputfield->label = $this->_('Language'); // Label for 'language' field in user profile
|
||||
} else if($name == 'email' && $inputfield->label == 'E-Mail Address') {
|
||||
$inputfield->label = $this->_('E-Mail Address'); // Label for 'email' field in user profile
|
||||
} else if($name == 'title' && $inputfield->label == 'Title') {
|
||||
$inputfield->label = $this->_('Title'); // Label for 'title' field used throughout ProcessWire
|
||||
}
|
||||
|
||||
// check if this is a language alternate field (i.e. title_es or title)
|
||||
if($this->LanguageSupportFields) {
|
||||
@@ -504,7 +521,7 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
if($inputfield->getSetting('useLanguages') || $inputfield->getSetting('hasLanguages')) {
|
||||
// multi-language field
|
||||
$this->hookInputfieldBeforeRender($event); // ensures default language values are populated
|
||||
if(!$this->wire('languages')->editable($this->defaultLanguagePage)) $replace = true;
|
||||
if(!$this->wire()->languages->editable($this->defaultLanguagePage)) $replace = true;
|
||||
|
||||
} else {
|
||||
// not a native multi-language field, check if it's language alternate or not editable
|
||||
@@ -512,7 +529,7 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
$replace = true;
|
||||
} else if($inputfield->hasFieldtype && $this->LanguageSupportFields) {
|
||||
$language = $this->LanguageSupportFields->isAlternateField($inputfield->name);
|
||||
if($language && !$this->wire('languages')->editable($language)) $replace = true;
|
||||
if($language && !$this->wire()->languages->editable($language)) $replace = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -536,15 +553,15 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
/** @var Inputfield $inputfield */
|
||||
$inputfield = $event->object;
|
||||
if(!$inputfield->getSetting('useLanguages')) return;
|
||||
|
||||
$post = $event->arguments[0];
|
||||
$languages = $this->wire('languages');
|
||||
$languages = $this->wire()->languages;
|
||||
|
||||
// originals
|
||||
$name = $inputfield->attr('name');
|
||||
$id = $inputfield->attr('id');
|
||||
$value = $inputfield->attr('value');
|
||||
$required = $inputfield->required;
|
||||
|
||||
|
||||
// process and set value for each language
|
||||
foreach($languages as $language) {
|
||||
@@ -577,7 +594,6 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
$inputfield->setAttribute('value', $value);
|
||||
$inputfield->required = $required;
|
||||
$inputfield->setTrackChanges(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -588,24 +604,23 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
*/
|
||||
public function hookFieldGetInputfield(HookEvent $event) {
|
||||
|
||||
$language = $this->wire('user')->language;
|
||||
$language = $this->wire()->user->language;
|
||||
if(!$language || !$language->id) return;
|
||||
|
||||
/** @var Field $field */
|
||||
$field = $event->object;
|
||||
/** @var Page $page */
|
||||
$page = $event->arguments[0];
|
||||
/** @var Template $template */
|
||||
$template = $page ? $page->template : null;
|
||||
$inputfield = $event->return;
|
||||
$field = $event->object; /** @var Field $field */
|
||||
$page = $event->arguments[0]; /** @var Page $page */
|
||||
$template = $page ? $page->template : null; /** @var Template|null $template */
|
||||
$inputfield = $event->return; /** @var Inputfield $inputfield */
|
||||
|
||||
if(!$inputfield) return;
|
||||
|
||||
$translatable = array('label', 'description', 'notes');
|
||||
if($inputfield->attr('placeholder') !== null && $this->wire('process') != 'ProcessField') {
|
||||
if($inputfield->attr('placeholder') !== null && $this->wire()->process != 'ProcessField') {
|
||||
$translatable[] = 'placeholder';
|
||||
}
|
||||
$languages = $template ? $template->getLanguages() : $this->wire('languages');
|
||||
$languages = $template ? $template->getLanguages() : $this->wire()->languages;
|
||||
$useLanguages = $template && $template->noLang ? false : true;
|
||||
if(!$languages) $languages = $this->wire('languages');
|
||||
if(!$languages) $languages = $this->wire()->languages;
|
||||
|
||||
// populate language versions where available
|
||||
foreach($translatable as $key) {
|
||||
@@ -626,7 +641,7 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
// set values in this field specific to each language
|
||||
foreach($languages as $language) {
|
||||
$languageValue = '';
|
||||
if(is_object($value) && $value instanceof LanguagesPageFieldValue) {
|
||||
if($value instanceof LanguagesPageFieldValue) {
|
||||
$languageValue = $value->getLanguageValue($language->id);
|
||||
} else {
|
||||
if($language->isDefault) $languageValue = $value;
|
||||
@@ -649,6 +664,7 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
*/
|
||||
public function hookPageAdded(HookEvent $event) {
|
||||
|
||||
/** @var Page $page */
|
||||
$page = $event->arguments[0];
|
||||
if($page->template->name != self::languageTemplateName) return;
|
||||
|
||||
@@ -656,13 +672,14 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
$ids = $this->otherLanguagePageIDs;
|
||||
$ids[] = $page->id;
|
||||
$this->set('otherLanguagePageIDs', $ids);
|
||||
wire('languages')->added($page);
|
||||
$this->wire()->languages->added($page);
|
||||
|
||||
// save this as a known language page with module settings
|
||||
// this is a shortcut used to identify language pages before the API is fully ready
|
||||
$configData = $this->wire('modules')->getModuleConfigData('LanguageSupport');
|
||||
$modules = $this->wire()->modules;
|
||||
$configData = $modules->getModuleConfigData('LanguageSupport');
|
||||
$configData['otherLanguagePageIDs'][] = $page->id;
|
||||
wire('modules')->saveModuleConfigData('LanguageSupport', $configData);
|
||||
$modules->saveModuleConfigData('LanguageSupport', $configData);
|
||||
|
||||
}
|
||||
|
||||
@@ -674,20 +691,21 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
*/
|
||||
public function hookPageDeleteReady(HookEvent $event) {
|
||||
|
||||
/** @var Page $page */
|
||||
$page = $event->arguments[0];
|
||||
if($page->template->name != self::languageTemplateName) return;
|
||||
$language = $page;
|
||||
|
||||
// remove any language-specific values from any fields
|
||||
foreach($this->wire('fields') as $field) {
|
||||
|
||||
foreach($this->wire()->fields as $field) {
|
||||
/** @var Field $field */
|
||||
$changed = false;
|
||||
|
||||
foreach(array('label', 'description', 'notes') as $name) {
|
||||
$name = $name . $language->id;
|
||||
if(!isset($field->$name)) continue;
|
||||
$field->remove($name);
|
||||
$this->message("Removed {$language->name} $name from field {$field->name}");
|
||||
$this->message("Removed $language->name $name from field $field->name");
|
||||
$changed = true;
|
||||
}
|
||||
|
||||
@@ -695,24 +713,26 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
}
|
||||
|
||||
// remove template labels
|
||||
foreach($this->wire('templates') as $template) {
|
||||
foreach($this->wire()->templates as $template) {
|
||||
/** @var Template $template */
|
||||
$name = 'label' . $page->id;
|
||||
if(isset($template->$name)) {
|
||||
$template->remove($name);
|
||||
$template->save();
|
||||
$this->message("Removed {$language->name} label from template {$template->name}");
|
||||
$this->message("Removed $language->name label from template $template->name");
|
||||
}
|
||||
}
|
||||
|
||||
// trigger hook in $languages
|
||||
wire('languages')->deleted($page);
|
||||
$this->wire()->languages->deleted($page);
|
||||
|
||||
// update the other language module IDs to remove the uninstalled language
|
||||
$configData = $this->wire('modules')->getModuleConfigData('LanguageSupport');
|
||||
$modules = $this->wire()->modules;
|
||||
$configData = $modules->getModuleConfigData('LanguageSupport');
|
||||
$key = array_search($page->id, $configData['otherLanguagePageIDs']);
|
||||
if($key !== false) {
|
||||
unset($configData['otherLanguagePageIDs'][$key]);
|
||||
$this->wire('modules')->saveModuleConfigData('LanguageSupport', $configData);
|
||||
$modules->saveModuleConfigData('LanguageSupport', $configData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -730,12 +750,13 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
public function hookPageSetLanguageValue(HookEvent $event) {
|
||||
|
||||
$page = $event->object;
|
||||
$language = $event->arguments(0);
|
||||
$field = $event->arguments(1);
|
||||
|
||||
$page = $event->object; /** @var Page $page */
|
||||
$language = $event->arguments(0); /** @var Language $language */
|
||||
$field = $event->arguments(1); /** @var string|Field $field */
|
||||
$value = $event->arguments(2);
|
||||
$languages = $this->wire()->languages;
|
||||
|
||||
$event->return = $page;
|
||||
|
||||
if(!is_object($language)) {
|
||||
@@ -743,7 +764,9 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
$language = $languages ? $languages->get($language) : null;
|
||||
}
|
||||
|
||||
if(!$language instanceof Language) throw new WireException('Unknown language set to Page::setLanguageValue');
|
||||
if(!$language instanceof Language) {
|
||||
throw new WireException('Unknown language set to Page::setLanguageValue');
|
||||
}
|
||||
|
||||
if($field === 'name' || $field === 'status') {
|
||||
// set page name or status
|
||||
@@ -761,9 +784,9 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
if(is_object($field)) $field = $field->name;
|
||||
$previousValue = $page->get($field);
|
||||
|
||||
if(is_object($previousValue) && $previousValue instanceof LanguagesValueInterface) {
|
||||
if($previousValue instanceof LanguagesValueInterface) {
|
||||
// utilize existing set methods available in LanguagesValueInterface (which might be slightly quicker than the else condition method
|
||||
if(is_object($value) && $value instanceof LanguagesValueInterface) {
|
||||
if($value instanceof LanguagesValueInterface) {
|
||||
// if given a LanguagesPageFieldValue, then just set it to the page
|
||||
$page->set($field, $value);
|
||||
} else {
|
||||
@@ -774,7 +797,7 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
} else {
|
||||
// temporarily set user's language to field language, set the field value, then set user's language back
|
||||
// we don't know what exactly $field might be, whether custom field or some other field, but we'll set it anyway
|
||||
$user = $this->wire('user');
|
||||
$user = $this->wire()->user;
|
||||
$userLanguage = $user->language->id != $language->id ? $user->language : null;
|
||||
if($userLanguage) $user->language = $language;
|
||||
$page->set($field, $value);
|
||||
@@ -798,22 +821,20 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
*/
|
||||
public function hookPageGetLanguageValue(HookEvent $event) {
|
||||
|
||||
/** @var Page $page */
|
||||
$page = $event->object;
|
||||
/** @var Language $language */
|
||||
$language = $event->arguments(0);
|
||||
/** @var Field $field */
|
||||
$field = $event->arguments(1);
|
||||
$value = null;
|
||||
$page = $event->object; /** @var Page $page */
|
||||
$language = $event->arguments(0); /** @var Language $language */
|
||||
$field = $event->arguments(1); /** @var string|Field $field */
|
||||
|
||||
if(!is_object($language)) {
|
||||
if(ctype_digit("$language")) $language = (int) $language;
|
||||
$language = $this->wire('languages')->get($language);
|
||||
$language = $this->wire()->languages->get($language);
|
||||
}
|
||||
|
||||
if(!$language instanceof Language) throw new WireException('Unknown language sent to Page::getLanguageValue');
|
||||
if(!$language instanceof Language) {
|
||||
throw new WireException('Unknown language sent to Page::getLanguageValue');
|
||||
}
|
||||
|
||||
if($field == 'name') {
|
||||
if($field === 'name') {
|
||||
// get a page name
|
||||
if($language->isDefault()) {
|
||||
$value = $page->name;
|
||||
@@ -826,12 +847,12 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
if(is_object($field)) $field = $field->name;
|
||||
$value = $page->get($field);
|
||||
|
||||
if(is_object($value) && $value instanceof LanguagesValueInterface) {
|
||||
if($value instanceof LanguagesValueInterface) {
|
||||
$value = $value->getLanguageValue($language->id);
|
||||
|
||||
} else {
|
||||
// temporarily set user's language to field language, get the field value, then set user's language back
|
||||
$user = $this->wire('user');
|
||||
$user = $this->wire()->user;
|
||||
$userLanguage = $user->language->id != $language->id ? $user->language : null;
|
||||
if($userLanguage) $user->language = $language;
|
||||
$value = $page->get($field);
|
||||
@@ -862,19 +883,24 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
public function refreshLanguageIDs() {
|
||||
$languages = $this->wire()->languages;
|
||||
$modules = $this->wire()->modules;
|
||||
|
||||
$this->message('Refreshing other language page IDs', Notice::debug);
|
||||
if(!$this->wire('languages')) return;
|
||||
if(!$languages) return;
|
||||
|
||||
$ids = array();
|
||||
foreach($this->wire('languages') as $language) {
|
||||
|
||||
foreach($languages as $language) {
|
||||
if($language->isDefault()) continue;
|
||||
$ids[] = $language->id;
|
||||
}
|
||||
if($this->otherLanguagePageIDs != $ids) {
|
||||
$this->set('otherLanguagePageIDs', $ids);
|
||||
$configData = $this->wire('modules')->getModuleConfigData('LanguageSupport');
|
||||
$configData = $modules->getModuleConfigData('LanguageSupport');
|
||||
if($configData['otherLanguagePageIDs'] != $ids) {
|
||||
$configData['otherLanguagePageIDs'] = $ids;
|
||||
$this->wire('modules')->saveModuleConfigData('LanguageSupport', $configData);
|
||||
$modules->saveModuleConfigData('LanguageSupport', $configData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -57,6 +57,7 @@ class LanguageSupportFields extends WireData implements Module {
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
// load other required classes
|
||||
$dirname = dirname(__FILE__);
|
||||
require_once($dirname . '/LanguagesValueInterface.php');
|
||||
@@ -138,7 +139,7 @@ class LanguageSupportFields extends WireData implements Module {
|
||||
$field = $event->arguments[1];
|
||||
if($field->name === 'language') return;
|
||||
|
||||
$language = $this->wire()->user->get('language');
|
||||
$language = $this->wire()->user->language;
|
||||
if(!$language || !$language->id || $language->isDefault()) return;
|
||||
|
||||
// exit quickly if we can determine now we don't need to continue
|
||||
@@ -327,7 +328,7 @@ class LanguageSupportFields extends WireData implements Module {
|
||||
$fields = $selector->field;
|
||||
$fields = is_array($fields) ? $fields : array($fields);
|
||||
|
||||
foreach($fields as $key => $field) {
|
||||
foreach($fields as $field) {
|
||||
|
||||
$subfield = '';
|
||||
if(strpos($field, '.')) list($field, $subfield) = explode('.', $field);
|
||||
@@ -554,7 +555,7 @@ class LanguageSupportFields extends WireData implements Module {
|
||||
*
|
||||
*/
|
||||
public function ___install() {
|
||||
$this->modules->get('FieldtypeTextLanguage');
|
||||
$this->wire()->modules->get('FieldtypeTextLanguage');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* ProcessWire Language Translator
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*
|
||||
@@ -96,9 +96,10 @@ class LanguageTranslator extends Wire {
|
||||
*
|
||||
*/
|
||||
public function __construct(Language $currentLanguage) {
|
||||
parent::__construct();
|
||||
$currentLanguage->wire($this);
|
||||
$this->setCurrentLanguage($currentLanguage);
|
||||
$this->rootPath = $this->wire('config')->paths->root;
|
||||
$this->rootPath = $this->wire()->config->paths->root;
|
||||
$file = __FILE__;
|
||||
$pos = strpos($file, '/wire/modules/LanguageSupport/');
|
||||
$this->rootPath2 = $pos ? substr($file, 0, $pos+1) : '';
|
||||
|
@@ -29,8 +29,8 @@ class ProcessLanguage extends ProcessPageType {
|
||||
'permission' => 'lang-edit',
|
||||
'permissions' => array(
|
||||
'lang-edit' => 'Administer languages and static translation files'
|
||||
)
|
||||
);
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ class ProcessLanguage extends ProcessPageType {
|
||||
$this->addHookAfter('InputfieldFile::renderUpload', $this, 'renderInputfieldFileUpload');
|
||||
$this->addHookBefore('InputfieldFile::processInput', $this, 'processInputfieldFileInput');
|
||||
|
||||
if(!$this->wire('config')->ajax) {
|
||||
if(!$this->wire()->config->ajax) {
|
||||
$this->addHookBefore('InputfieldForm::render', $this, 'renderInputfieldForm');
|
||||
}
|
||||
parent::init();
|
||||
@@ -98,8 +98,9 @@ class ProcessLanguage extends ProcessPageType {
|
||||
|
||||
protected function translationUrl() {
|
||||
if(!$this->translationUrl) {
|
||||
$support = $this->wire('modules')->get('LanguageSupport');
|
||||
$this->translationUrl = $this->wire('pages')->get($support->languageTranslatorPageID)->url;
|
||||
/** @var LanguageSupport $support */
|
||||
$support = $this->wire()->modules->get('LanguageSupport');
|
||||
$this->translationUrl = $this->wire()->pages->get($support->languageTranslatorPageID)->url;
|
||||
}
|
||||
return $this->translationUrl;
|
||||
}
|
||||
@@ -120,15 +121,14 @@ class ProcessLanguage extends ProcessPageType {
|
||||
*/
|
||||
public function renderInputfieldFile(HookEvent $event) {
|
||||
|
||||
/** @var InputfieldFile $inputfield */
|
||||
$inputfield = $event->object;
|
||||
$language = $this->wire('process')->getPage();
|
||||
$inputfield = $event->object; /** @var InputfieldFile $inputfield */
|
||||
$language = $this->wire()->process->getPage(); /** @var Language $language */
|
||||
|
||||
/** @var Pagefiles $pagefiles */
|
||||
$pagefiles = $inputfield->attr('value');
|
||||
|
||||
foreach($pagefiles as $pagefile) {
|
||||
/** Pagefile $pagefile */
|
||||
/** @var Pagefile $pagefile */
|
||||
if($pagefile->ext() != 'csv') continue;
|
||||
$pagefiles->remove($pagefile);
|
||||
$this->processCSV($pagefile->filename(), $language);
|
||||
@@ -146,9 +146,13 @@ class ProcessLanguage extends ProcessPageType {
|
||||
/** @var InputfieldForm $form */
|
||||
$form = $event->object;
|
||||
$language = $this->getPage();
|
||||
|
||||
if(!$language->id) return;
|
||||
|
||||
$file = $language->filesManager()->path . '.phrase-index.txt';
|
||||
$inputfield = $this->wire('modules')->get('InputfieldMarkup');
|
||||
|
||||
/** @var InputfieldMarkup $inputfield */
|
||||
$inputfield = $this->wire()->modules->get('InputfieldMarkup');
|
||||
$inputfield->label = $this->_('Live Search');
|
||||
$inputfield->icon = 'search';
|
||||
$placeholder = $this->_('Text to search for');
|
||||
@@ -163,12 +167,13 @@ class ProcessLanguage extends ProcessPageType {
|
||||
|
||||
$phrases = file_get_contents($file);
|
||||
$phrases = str_replace(array('"', "\n", "<", ">"), ' ', $phrases);
|
||||
$script = 'script';
|
||||
|
||||
$inputfield->value =
|
||||
"<script>" .
|
||||
"<$script>" .
|
||||
"var phraseIndex = \"$phrases\"; " .
|
||||
"var phraseLanguageID = $language->id;" .
|
||||
"</script>" .
|
||||
"</$script>" .
|
||||
"<p class='description' style='margin:0'>" .
|
||||
$this->_('Search all translatable files for specific text/phrase.') . ' ' .
|
||||
$this->_('Click found matches to edit translation or add file (if not already present).') .
|
||||
@@ -195,10 +200,8 @@ class ProcessLanguage extends ProcessPageType {
|
||||
public function renderInputfieldFileItem(HookEvent $event) {
|
||||
|
||||
$translationUrl = $this->translationUrl();
|
||||
/** @var Pagefile $pagefile */
|
||||
$pagefile = $event->arguments[0];
|
||||
/** @var Language $page */
|
||||
$page = $pagefile->get('page');
|
||||
$pagefile = $event->arguments[0]; /** @var Pagefile $pagefile */
|
||||
$page = $pagefile->get('page'); /** @var Language $page */
|
||||
|
||||
if($pagefile->ext() == 'csv') {
|
||||
$event->return .=
|
||||
@@ -214,9 +217,11 @@ class ProcessLanguage extends ProcessPageType {
|
||||
|
||||
$data = $page->translator->getTextdomain($textdomain);
|
||||
$file = $data['file'];
|
||||
$pathname = $this->wire('config')->paths->root . $file;
|
||||
$pathname = $this->wire()->config->paths->root . $file;
|
||||
$translations =& $data['translations'];
|
||||
$total = count($translations);
|
||||
|
||||
/** @var LanguageParser $parser */
|
||||
$parser = $this->wire(new LanguageParser($page->translator, $pathname));
|
||||
$untranslated = $parser->getUntranslated();
|
||||
$alternates = $parser->getAlternates();
|
||||
@@ -276,18 +281,16 @@ class ProcessLanguage extends ProcessPageType {
|
||||
*
|
||||
*/
|
||||
public function renderInputfieldFileUpload(HookEvent $event) {
|
||||
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$translationUrl = $this->translationUrl();
|
||||
/** @var Pagefiles $pagefiles */
|
||||
$pagefiles = $event->arguments(0);
|
||||
/** @var Page $page */
|
||||
$page = $pagefiles->get('page');
|
||||
/** @var InputfieldFile $inputfield */
|
||||
$inputfield = $event->object;
|
||||
$pagefiles = $event->arguments(0); /** @var Pagefiles $pagefiles */
|
||||
$page = $pagefiles->get('page'); /** @var Page $page */
|
||||
$inputfield = $event->object; /** @var InputfieldFile $inputfield */
|
||||
$out = '';
|
||||
|
||||
/** @var InputfieldButton $btn1 */
|
||||
$btn1 = $this->wire('modules')->get('InputfieldButton');
|
||||
$btn1 = $modules->get('InputfieldButton');
|
||||
$btn1->href = "{$translationUrl}add/?language_id={$page->id}";
|
||||
$btn1->value = $this->_('Find Files to Translate');
|
||||
$btn1->icon = 'plane';
|
||||
@@ -296,7 +299,7 @@ class ProcessLanguage extends ProcessPageType {
|
||||
|
||||
if(count($inputfield->attr('value'))) {
|
||||
/** @var InputfieldButton $btn2 */
|
||||
$btn2 = $this->wire('modules')->get('InputfieldButton');
|
||||
$btn2 = $modules->get('InputfieldButton');
|
||||
$btn2->href = "../download/?language_id={$page->id}&field=" . $inputfield->attr('name');
|
||||
$btn2->value = $this->_('Download ZIP');
|
||||
$btn2->icon = 'file-zip-o';
|
||||
@@ -336,10 +339,11 @@ class ProcessLanguage extends ProcessPageType {
|
||||
|
||||
public function ___execute() {
|
||||
// check if 2.5 update needed to add new language_files_site field
|
||||
if(!$this->wire('fields')->get('language_files_site')) {
|
||||
if(!$this->wire()->fields->get('language_files_site')) {
|
||||
require_once(dirname(__FILE__) . '/LanguageSupportInstall.php');
|
||||
/** @var LanguageSupportInstall $installer */
|
||||
$installer = $this->wire(new LanguageSupportInstall());
|
||||
$installer->addFilesFields($this->wire('fieldgroups')->get(LanguageSupport::languageTemplateName));
|
||||
$installer->addFilesFields($this->wire()->fieldgroups->get(LanguageSupport::languageTemplateName));
|
||||
}
|
||||
return parent::___execute();
|
||||
}
|
||||
@@ -376,7 +380,7 @@ class ProcessLanguage extends ProcessPageType {
|
||||
}
|
||||
}
|
||||
|
||||
if(!count($files) && $fieldName) {
|
||||
if(!count($files)) {
|
||||
foreach($language->$fieldName as $file) {
|
||||
$files[] = $file->filename;
|
||||
}
|
||||
|
@@ -88,11 +88,11 @@ class ProcessLanguageTranslator extends Process {
|
||||
public function init() {
|
||||
|
||||
// if language specified as a GET var in the URL, then pick it up and use it (storing in session)
|
||||
$id = $this->input->get('language_id');
|
||||
$id = $this->wire()->input->get('language_id');
|
||||
if($id) {
|
||||
$this->setLanguage((int) $id);
|
||||
} else if($this->session->get('translateLanguageID')) {
|
||||
$this->setLanguage($this->session->get('translateLanguageID'));
|
||||
} else if($this->wire()->session->get('translateLanguageID')) {
|
||||
$this->setLanguage($this->wire()->session->get('translateLanguageID'));
|
||||
}
|
||||
// else throw new WireException("No language specified");
|
||||
parent::init();
|
||||
@@ -111,12 +111,19 @@ class ProcessLanguageTranslator extends Process {
|
||||
*/
|
||||
public function setLanguage($language) {
|
||||
|
||||
$languages = $this->wire('languages');
|
||||
$languages = $this->wire()->languages;
|
||||
if(!$languages) return;
|
||||
|
||||
if(is_int($language)) $language = $languages->get($language);
|
||||
if(!$language instanceof Language || !$language->id) throw new WireException($this->_("Unknown/invalid language"));
|
||||
if(!$language->editable()) throw new WirePermissionException($this->_('You do not have permission to edit this language'));
|
||||
|
||||
if(!$language instanceof Language || !$language->id) {
|
||||
throw new WireException($this->_("Unknown/invalid language"));
|
||||
}
|
||||
|
||||
if(!$language->editable()) {
|
||||
throw new WirePermissionException($this->_('You do not have permission to edit this language'));
|
||||
}
|
||||
|
||||
$this->language = $language;
|
||||
$this->session->set('translateLanguageID', $language->id);
|
||||
$this->translator = new LanguageTranslator($this->language);
|
||||
@@ -135,10 +142,13 @@ class ProcessLanguageTranslator extends Process {
|
||||
*
|
||||
*/
|
||||
public function ___executeList() {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$config = $this->wire()->config;
|
||||
|
||||
/** @var MarkupAdminDataTable $table */
|
||||
$table = $this->modules->get("MarkupAdminDataTable");
|
||||
$url = $this->pages->get("template=admin, name=language-translations")->url;
|
||||
$table = $modules->get("MarkupAdminDataTable");
|
||||
$url = $this->wire()->pages->get("template=admin, name=language-translations")->url;
|
||||
$out = '';
|
||||
|
||||
foreach(array('language_files', 'language_files_site') as $fieldName) {
|
||||
@@ -155,7 +165,7 @@ class ProcessLanguageTranslator extends Process {
|
||||
$table->row(array(
|
||||
$data['file'] => $url . "edit/?textdomain=$textdomain",
|
||||
count($data['translations']),
|
||||
date($this->config->dateFormat, filemtime($file->filename))
|
||||
date($config->dateFormat, filemtime($file->filename))
|
||||
));
|
||||
$this->translator->unloadTextdomain($textdomain);
|
||||
}
|
||||
@@ -167,7 +177,7 @@ class ProcessLanguageTranslator extends Process {
|
||||
}
|
||||
|
||||
/** @var InputfieldButton $btn */
|
||||
$btn = $this->modules->get('InputfieldButton');
|
||||
$btn = $modules->get('InputfieldButton');
|
||||
$btn->href = $url . 'add/';
|
||||
$btn->icon = 'plane';
|
||||
$btn->showInHeader();
|
||||
@@ -183,26 +193,31 @@ class ProcessLanguageTranslator extends Process {
|
||||
*
|
||||
*/
|
||||
public function ___executeAdd() {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$input = $this->wire()->input;
|
||||
$config = $this->wire()->config;
|
||||
$session = $this->wire()->session;
|
||||
|
||||
$this->addBreadcrumbs();
|
||||
$this->headline($this->_('Select File(s)')); // Headline when adding new translation files
|
||||
|
||||
/** @var InputfieldForm $form */
|
||||
$form = $this->modules->get("InputfieldForm");
|
||||
$form = $modules->get("InputfieldForm");
|
||||
$form->attr('method', 'post');
|
||||
$form->attr('action', "./?language_id={$this->language->id}");
|
||||
//$form->description = sprintf("Select file(s) for translation to %s", $this->language->get('title|name'));
|
||||
$languageTitle = $this->language->get('title|name');
|
||||
$form->description = sprintf($this->_('Select a file (or multiple files) and click Submit to create new %s translation files.'), $languageTitle);
|
||||
$useCache = $this->input->post('submit_refresh') || $this->input->get('refresh') ? false : true;
|
||||
$useCache = $input->post('submit_refresh') || $input->get('refresh') ? false : true;
|
||||
|
||||
$files = array(
|
||||
'site' => $this->findTranslatableFiles($this->wire('config')->paths->site, $useCache),
|
||||
'wire' => $this->findTranslatableFiles($this->wire('config')->paths->wire, $useCache)
|
||||
'site' => $this->findTranslatableFiles($config->paths->site, $useCache),
|
||||
'wire' => $this->findTranslatableFiles($config->paths->wire, $useCache)
|
||||
);
|
||||
|
||||
if($this->input->get('refresh')) {
|
||||
$this->wire('session')->redirect("../../languages/edit/?id={$this->language->id}");
|
||||
if($input->get('refresh')) {
|
||||
$session->redirect("../../languages/edit/?id={$this->language->id}");
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -217,7 +232,7 @@ class ProcessLanguageTranslator extends Process {
|
||||
|
||||
foreach(array_keys($files) as $key) {
|
||||
/** @var InputfieldSelectMultiple $field */
|
||||
$field = $this->modules->get('InputfieldSelectMultiple');
|
||||
$field = $modules->get('InputfieldSelectMultiple');
|
||||
$field->attr('name', 'file_' . $key);
|
||||
$field->label = sprintf($this->_('Translatable files in %s'), "/$key/");
|
||||
$field->addClass('TranslationFileSelect');
|
||||
@@ -274,7 +289,7 @@ class ProcessLanguageTranslator extends Process {
|
||||
}
|
||||
|
||||
/** @var InputfieldText $field */
|
||||
$field = $this->modules->get('InputfieldText');
|
||||
$field = $modules->get('InputfieldText');
|
||||
$field->attr('name', 'filename');
|
||||
$field->label = $this->_('Enter file to translate');
|
||||
$field->icon = 'code';
|
||||
@@ -284,14 +299,14 @@ class ProcessLanguageTranslator extends Process {
|
||||
$form->add($field);
|
||||
|
||||
/** @var InputfieldSubmit $submit */
|
||||
$submit = $this->modules->get("InputfieldSubmit");
|
||||
$submit = $modules->get("InputfieldSubmit");
|
||||
$submit->attr('id+name', 'submit_add');
|
||||
$submit->icon = 'plane';
|
||||
$submit->showInHeader();
|
||||
$form->add($submit);
|
||||
|
||||
/** @var InputfieldSubmit $submit */
|
||||
$submit = $this->modules->get("InputfieldSubmit");
|
||||
$submit = $modules->get("InputfieldSubmit");
|
||||
$submit->attr('name', 'submit_refresh');
|
||||
$submit->attr('value', $this->_('Refresh File List'));
|
||||
$submit->setSecondary();
|
||||
@@ -299,13 +314,13 @@ class ProcessLanguageTranslator extends Process {
|
||||
$form->add($submit);
|
||||
|
||||
if($form->isSubmitted('submit_add')) {
|
||||
if($this->input->post('filename')) {
|
||||
if($input->post('filename')) {
|
||||
$this->processAdd($field);
|
||||
|
||||
} else {
|
||||
$newTextdomains = array();
|
||||
foreach(array('site' => 'file_site', 'wire' => 'file_wire') as $key => $name) {
|
||||
$postFiles = $this->input->post->$name;
|
||||
$postFiles = $input->post->$name;
|
||||
if(!wireCount($postFiles)) continue;
|
||||
foreach($postFiles as $file) {
|
||||
if(!isset($files[$key][$file])) continue;
|
||||
@@ -318,11 +333,11 @@ class ProcessLanguageTranslator extends Process {
|
||||
}
|
||||
}
|
||||
if(count($newTextdomains) == 1) {
|
||||
$this->session->redirect("../edit/?language_id={$this->language->id}&textdomain=" . reset($newTextdomains));
|
||||
$session->redirect("../edit/?language_id={$this->language->id}&textdomain=" . reset($newTextdomains));
|
||||
return '';
|
||||
} else if(count($newTextdomains) > 1) {
|
||||
// render form again
|
||||
$this->session->redirect("../../languages/edit/?id={$this->language->id}");
|
||||
$session->redirect("../../languages/edit/?id={$this->language->id}");
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -340,27 +355,29 @@ class ProcessLanguageTranslator extends Process {
|
||||
*
|
||||
*/
|
||||
protected function ___processAdd($field = null, $sourceFilename = '') {
|
||||
|
||||
$session = $this->wire()->session;
|
||||
|
||||
if($sourceFilename) {
|
||||
$filename = $sourceFilename;
|
||||
} else {
|
||||
$filename = $this->input->post('filename');
|
||||
$filename = $this->wire()->input->post('filename');
|
||||
}
|
||||
|
||||
$filename = str_replace(array('\\', '..'), array('/', ''), $filename);
|
||||
if($field) $field->attr('value', $filename);
|
||||
$pathname = $this->config->paths->root . ltrim($filename, '/');
|
||||
$pathname = $this->wire()->config->paths->root . ltrim($filename, '/');
|
||||
|
||||
if(is_file($pathname)) {
|
||||
|
||||
if(!$sourceFilename) $this->session->get('CSRF')->validate();
|
||||
if(!$sourceFilename) $session->get('CSRF')->validate();
|
||||
$this->message(sprintf($this->_('Found %s'), $filename)); // Found [filename]
|
||||
|
||||
if($this->parseTranslatableFile($pathname)) {
|
||||
|
||||
$textdomain = $this->translator->addFileToTranslate($filename);
|
||||
if($textdomain) {
|
||||
$this->session->redirect("../edit/?language_id={$this->language->id}&textdomain=$textdomain");
|
||||
$session->redirect("../edit/?language_id={$this->language->id}&textdomain=$textdomain");
|
||||
}
|
||||
|
||||
$this->error($this->_('That file is already in the system'));
|
||||
@@ -384,15 +401,16 @@ class ProcessLanguageTranslator extends Process {
|
||||
$qty = substr_count($untranslated, "\n")+1;
|
||||
$qty2 = substr_count($translated, "\n")+1;
|
||||
if($qty2 > $qty) $qty = $qty2;
|
||||
$field = $this->modules->get("InputfieldTextarea");
|
||||
$field = $this->wire()->modules->get("InputfieldTextarea");
|
||||
$field->attr('rows', $qty > 2 ? $qty : 2);
|
||||
} else if(strlen($untranslated) < 128) {
|
||||
$field = $this->modules->get("InputfieldText");
|
||||
$field = $this->wire()->modules->get("InputfieldText");
|
||||
} else {
|
||||
$field = $this->modules->get("InputfieldTextarea");
|
||||
$field = $this->wire()->modules->get("InputfieldTextarea");
|
||||
$field->attr('rows', 3);
|
||||
}
|
||||
|
||||
|
||||
/** @var InputfieldText $field */
|
||||
$field->attr('id+name', $hash);
|
||||
$field->set('textFormat', Inputfield::textFormatNone);
|
||||
$field->attr('value', $translated);
|
||||
@@ -430,9 +448,9 @@ class ProcessLanguageTranslator extends Process {
|
||||
}
|
||||
|
||||
if((!strlen($translated) || $translated === '+') && !$field instanceof InputfieldTextarea) {
|
||||
$languages = $this->wire('languages');
|
||||
$languages = $this->wire()->languages;
|
||||
$languages->setLanguage($this->language);
|
||||
$this->wire('user')->language = $this->language;
|
||||
$this->wire()->user->language = $this->language;
|
||||
$test = $this->translator->commonTranslation($untranslated);
|
||||
$field->textFormat = Inputfield::textFormatBasic;
|
||||
if(strlen($test) && $test !== $untranslated) {
|
||||
@@ -458,9 +476,11 @@ class ProcessLanguageTranslator extends Process {
|
||||
*
|
||||
*/
|
||||
protected function executeEditAbandoned(&$translations, $form) {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
|
||||
/** @var InputfieldFieldset $fieldset */
|
||||
$fieldset = $this->modules->get("InputfieldFieldset");
|
||||
$fieldset = $modules->get("InputfieldFieldset");
|
||||
$fieldset->attr('id+name', 'abandoned_fieldset');
|
||||
$fieldset->description = $this->_('The following unused translations were found. This means that the original untranslated text was either changed or deleted. It is recommended that you delete abandoned translations unless you need to keep them to copy/paste to a new translation.');
|
||||
$fieldset->collapsed = Inputfield::collapsedYes;
|
||||
@@ -475,7 +495,7 @@ class ProcessLanguageTranslator extends Process {
|
||||
|
||||
$n++;
|
||||
/** @var InputfieldCheckbox $field */
|
||||
$field = $this->modules->get("InputfieldCheckbox");
|
||||
$field = $modules->get("InputfieldCheckbox");
|
||||
$field->attr('name', "abandoned$n");
|
||||
$field->attr('value', $hash);
|
||||
$field->description = !strlen($translation['text']) ? $this->_('[empty]') : $translation['text'];
|
||||
@@ -520,7 +540,7 @@ class ProcessLanguageTranslator extends Process {
|
||||
if(!$fileUrl) {
|
||||
$filename = $input->get('filename');
|
||||
$test = $filename ? $this->translator->filenameToTextdomain($filename) : '';
|
||||
if($textdomain && $test === $textdomain) {
|
||||
if($test === $textdomain) {
|
||||
$this->processAdd(null, $filename);
|
||||
} else {
|
||||
throw new WireException($this->_('Unable to load textdomain'));
|
||||
@@ -616,11 +636,15 @@ class ProcessLanguageTranslator extends Process {
|
||||
*
|
||||
*/
|
||||
protected function ___processEdit($form, $textdomain, $translations) {
|
||||
|
||||
$form->processInput($this->input->post);
|
||||
|
||||
$input = $this->wire()->input;
|
||||
$session = $this->wire()->session;
|
||||
|
||||
$numChanges = 0;
|
||||
$numRemoved = 0;
|
||||
|
||||
$form->processInput($input->post);
|
||||
|
||||
foreach($this->untranslated as $hash => $text) {
|
||||
$translation = isset($translations[$hash]) ? $translations[$hash] : array('text' => '');
|
||||
$field = $form->getChildByName($hash);
|
||||
@@ -630,16 +654,16 @@ class ProcessLanguageTranslator extends Process {
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->input->post as $key => $hash) {
|
||||
foreach($input->post as $key => $hash) {
|
||||
if(strpos($key, 'abandoned') !== 0) continue;
|
||||
if(!$field = $form->getChildByName($key)) continue;
|
||||
if(!$form->getChildByName($key)) continue;
|
||||
$this->translator->removeTranslation($textdomain, $hash);
|
||||
$numRemoved++;
|
||||
}
|
||||
|
||||
// show only untranslated toggle, remember setting
|
||||
$untranslated = (int) $this->input->post('untranslated');
|
||||
$this->session->setFor($this, 'untranslated', $untranslated);
|
||||
$untranslated = (int) $input->post('untranslated');
|
||||
$session->setFor($this, 'untranslated', $untranslated);
|
||||
|
||||
if($numChanges) $this->message(sprintf($this->_n('%d translation changed', '%d translations changed', $numChanges), $numChanges));
|
||||
if($numRemoved) $this->message(sprintf($this->_n('%d abandoned translation removed', '%d abandoned translations removed', $numRemoved), $numRemoved));
|
||||
@@ -648,10 +672,10 @@ class ProcessLanguageTranslator extends Process {
|
||||
$this->message(sprintf($this->_('Saved %s'), $textdomain));
|
||||
|
||||
// button actions
|
||||
$action = $this->wire('input')->post('_action_value');
|
||||
$action = $input->post('_action_value');
|
||||
if($action == 'exit') {
|
||||
// save and exit
|
||||
$this->session->redirect("../../languages/edit/?id={$this->language->id}");
|
||||
$session->redirect("../../languages/edit/?id={$this->language->id}");
|
||||
} else if($action == 'next') {
|
||||
// save and edit next file
|
||||
$nextTextdomain = false;
|
||||
@@ -670,10 +694,10 @@ class ProcessLanguageTranslator extends Process {
|
||||
$nextTextdomain = $textdomain;
|
||||
$this->warning($this->_('There is no next file to edit.'));
|
||||
}
|
||||
$this->session->redirect("./?textdomain=$nextTextdomain&language_id={$this->language->id}");
|
||||
$session->redirect("./?textdomain=$nextTextdomain&language_id={$this->language->id}");
|
||||
} else {
|
||||
// save and continue editing (default)
|
||||
$this->session->redirect("./?textdomain=$textdomain&language_id={$this->language->id}");
|
||||
$session->redirect("./?textdomain=$textdomain&language_id={$this->language->id}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -700,11 +724,12 @@ class ProcessLanguageTranslator extends Process {
|
||||
*/
|
||||
protected function addBreadcrumbs() {
|
||||
/** @var LanguageSupport $languageSupport */
|
||||
$languageSupport = $this->modules->get('LanguageSupport');
|
||||
$languageSupport = $this->wire()->modules->get('LanguageSupport');
|
||||
$languagesPage = $this->pages->get($languageSupport->languagesPageID);
|
||||
$url = $languagesPage->url;
|
||||
$this->wire('breadcrumbs')->add(new Breadcrumb($url, $languagesPage->title));
|
||||
$this->wire('breadcrumbs')->add(new Breadcrumb($url . "edit/?id={$this->language->id}", $this->language->get('title|name')));
|
||||
$breadcrumbs = $this->wire()->breadcrumbs;
|
||||
$breadcrumbs->add(new Breadcrumb($url, $languagesPage->title));
|
||||
$breadcrumbs->add(new Breadcrumb($url . "edit/?id={$this->language->id}", $this->language->get('title|name')));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -728,7 +753,7 @@ class ProcessLanguageTranslator extends Process {
|
||||
if(!$level) {
|
||||
$cacheKey = "files_" . md5($path);
|
||||
if($useCache) {
|
||||
$files = $this->session->get($this, $cacheKey);
|
||||
$files = $this->wire()->session->get($this, $cacheKey);
|
||||
if($files !== null) return $files;
|
||||
}
|
||||
} else {
|
||||
@@ -737,13 +762,13 @@ class ProcessLanguageTranslator extends Process {
|
||||
|
||||
if(is_null($this->fp)) {
|
||||
$f = $this->language->filesManager()->path() . '.phrase-index.txt';
|
||||
if(is_file($f)) $this->wire('files')->unlink($f);
|
||||
if(is_file($f)) $this->wire()->files->unlink($f);
|
||||
$this->fp = fopen($f, "a");
|
||||
}
|
||||
|
||||
$files = array();
|
||||
$dirs = array();
|
||||
$root = $this->wire('config')->paths->root;
|
||||
$root = $this->wire()->config->paths->root;
|
||||
$assetsDir = '/site/assets/';
|
||||
if(DIRECTORY_SEPARATOR != '/') $assetsDir = str_replace('/', DIRECTORY_SEPARATOR, $assetsDir);
|
||||
|
||||
@@ -801,7 +826,7 @@ class ProcessLanguageTranslator extends Process {
|
||||
$pathname = str_replace($root, '/', $pathname);
|
||||
$files[$pathname] = $pathname;
|
||||
if(preg_match_all('/\b(?:_[_nx]\(|->_[nx]?\()[\'"](.+?)[\'"]\)/', $text, $matches)) {
|
||||
foreach($matches[1] as $key => $phrase) {
|
||||
foreach($matches[1] as $phrase) {
|
||||
$phrase = str_replace(array('|', '^', "\n", "\r", "\t", "<", ">"), ' ', strip_tags($phrase));
|
||||
fwrite($this->fp, "|$phrase");
|
||||
}
|
||||
@@ -821,7 +846,7 @@ class ProcessLanguageTranslator extends Process {
|
||||
$level--;
|
||||
|
||||
if($cacheKey) {
|
||||
$this->session->set($this, $cacheKey, $files);
|
||||
$this->wire()->session->set($this, $cacheKey, $files);
|
||||
}
|
||||
|
||||
if($this->fp && !$level) {
|
||||
|
@@ -9,7 +9,7 @@
|
||||
* For more details about how Process modules work, please see:
|
||||
* /wire/core/Process.php
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2018 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* @property bool|int $allowReset Allow passwords to be reset?
|
||||
@@ -46,7 +46,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
'version' => 104,
|
||||
'permanent' => false,
|
||||
'permission' => 'page-view',
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,9 +98,16 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$this->set('allowRoles', array());
|
||||
$this->set('blockRoles', array());
|
||||
$this->set('wireMailer', '');
|
||||
|
||||
$emailField = $this->wire('fields')->get('email');
|
||||
if($emailField) $this->set('confirmFields', array("email:$emailField->id"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wired to API
|
||||
*
|
||||
*/
|
||||
public function wired() {
|
||||
$emailField = $this->wire()->fields->get('email');
|
||||
if($emailField) $this->set('confirmFields', array("email:$emailField->id"));
|
||||
parent::wired();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,8 +116,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
public function ___execute() {
|
||||
|
||||
/** @var WireInput $input */
|
||||
$input = $this->wire('input');
|
||||
$input = $this->wire()->input;
|
||||
$out = '';
|
||||
|
||||
$errors = array(
|
||||
@@ -121,7 +127,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$this->headline($this->_('Reset Password')); // Reset password page headline
|
||||
|
||||
// password reset not applicable to logged-in users
|
||||
if($this->user->isLoggedin()) return '';
|
||||
if($this->wire()->user->isLoggedin()) return '';
|
||||
|
||||
$this->setupResetTable();
|
||||
|
||||
@@ -162,7 +168,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
if(empty($out)) $out = $this->renderContinue();
|
||||
$out = $errors . $out;
|
||||
} else if(empty($out)) {
|
||||
$this->wire('session')->redirect('./');
|
||||
$this->wire()->session->location('./');
|
||||
}
|
||||
|
||||
if($out) $out = "<div id='ProcessForgotPassword' style='text-align:left;'>$out</div>";
|
||||
@@ -177,19 +183,21 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function step1_renderForm() {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
|
||||
/** @var InputfieldForm $form */
|
||||
$form = $this->modules->get("InputfieldForm");
|
||||
$form = $modules->get("InputfieldForm");
|
||||
$form->attr('action', './?forgot=1');
|
||||
$form->attr('method', 'post');
|
||||
|
||||
/** @var InputfieldText $field */
|
||||
if($this->askEmail) {
|
||||
$field = $this->modules->get("InputfieldEmail");
|
||||
$field = $modules->get("InputfieldEmail");
|
||||
$field->label = $this->_("Enter your email address");
|
||||
$field->icon = 'envelope-o';
|
||||
} else {
|
||||
$field = $this->modules->get("InputfieldText");
|
||||
$field = $modules->get("InputfieldText");
|
||||
$field->label = $this->_("Enter your user name");
|
||||
$field->icon = 'user-circle-o';
|
||||
}
|
||||
@@ -200,7 +208,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$form->add($field);
|
||||
|
||||
/** @var InputfieldSubmit $submit */
|
||||
$submit = $this->modules->get("InputfieldSubmit");
|
||||
$submit = $modules->get("InputfieldSubmit");
|
||||
$submit->attr('id+name', 'submit_forgot');
|
||||
$form->add($submit);
|
||||
|
||||
@@ -219,14 +227,10 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function step2_processForm() {
|
||||
|
||||
/** @var Sanitizer $sanitizer */
|
||||
$sanitizer = $this->wire('sanitizer');
|
||||
/** @var WireInput $input */
|
||||
$input = $this->wire('input');
|
||||
/** @var Users $users */
|
||||
$users = $this->wire('users');
|
||||
/** @var User $user */
|
||||
$user = null;
|
||||
$sanitizer = $this->wire()->sanitizer;
|
||||
$input = $this->wire()->input;
|
||||
$users = $this->wire()->users;
|
||||
$user = null; /** @var User|null $user */
|
||||
$name = '';
|
||||
|
||||
// track quantity of submitted requests in session qty variable
|
||||
@@ -324,13 +328,13 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $token
|
||||
* @return bool|int
|
||||
* @return int
|
||||
*
|
||||
*/
|
||||
protected function step2_sendEmail(User $user, $token) {
|
||||
|
||||
$verify = $this->sessionGet('verify');
|
||||
$url = $this->page->httpUrl() .
|
||||
$url = $this->wire()->page->httpUrl() .
|
||||
"?forgot=1" .
|
||||
"&u={$user->id}" .
|
||||
"&t=" . urlencode($token);
|
||||
@@ -339,8 +343,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$bodyHTML = $this->renderEmailBody($url, $verify, true);
|
||||
|
||||
$email = null;
|
||||
if($this->wireMailer) $email = $this->wire('mail')->new(array('module' => $this->wireMailer));
|
||||
if(!$email) $email = $this->wire('mail')->new();
|
||||
if($this->wireMailer) $email = $this->wire()->mail->new(array('module' => $this->wireMailer));
|
||||
if(!$email) $email = $this->wire()->mail->new();
|
||||
|
||||
$email->to($user->email)->from($this->getEmailFrom());
|
||||
$email->subject($this->emailSubject)->body($body)->bodyHTML($bodyHTML);
|
||||
@@ -353,13 +357,13 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
* @param User $user
|
||||
* @param $error
|
||||
* @return bool|int
|
||||
* @return int
|
||||
*
|
||||
*/
|
||||
protected function step2_sendErrorEmail(User $user, $error) {
|
||||
$body = $this->renderErrorEmailBody($error);
|
||||
if(self::debug) $this->message("<p>" . nl2br($body) . "</p>", Notice::allowMarkup);
|
||||
$email = $this->wire('mail')->new();
|
||||
$email = $this->wire()->mail->new();
|
||||
$email->to($user->email)->from($this->getEmailFrom());
|
||||
$email->subject($this->emailSubject)->body($body);
|
||||
return $email->send();
|
||||
@@ -419,7 +423,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function ___renderErrorEmailBody($error) {
|
||||
return
|
||||
sprintf($this->_('You requested a password reset for your account at %s.'), $this->wire('config')->httpHost) . ' ' .
|
||||
sprintf($this->_('You requested a password reset for your account at %s.'), $this->wire()->config->httpHost) . ' ' .
|
||||
$this->_('The system is unable to complete this request for the reason listed below:') .
|
||||
"\n\n$error\n\n" .
|
||||
$this->_('Please contact the administrator for assistance with logging in to your account and/or changing your password.') .
|
||||
@@ -438,10 +442,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function step3_processEmailClick() {
|
||||
|
||||
/** @var WireInput $input */
|
||||
$input = $this->wire('input');
|
||||
/** @var WireDatabasePDO $database */
|
||||
$database = $this->wire('database');
|
||||
$input = $this->wire()->input;
|
||||
$database = $this->wire()->database;
|
||||
|
||||
$id = (int) $input->get('u');
|
||||
$token = $input->get('t');
|
||||
@@ -490,15 +492,19 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function step3_buildForm($id, $token) {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$templates = $this->wire()->templates;
|
||||
|
||||
$id = (int) $id;
|
||||
$token = urlencode($token);
|
||||
|
||||
/** @var InputfieldForm $form */
|
||||
$form = $this->modules->get("InputfieldForm");
|
||||
$form = $modules->get("InputfieldForm");
|
||||
$form->attr('method', 'post');
|
||||
$form->attr('action', "./?forgot=1&u=$id&t=$token");
|
||||
|
||||
$f = $this->wire('modules')->get('InputfieldText');
|
||||
|
||||
/** @var InputfieldText $f */
|
||||
$f = $modules->get('InputfieldText');
|
||||
$f->attr('name', 'verify');
|
||||
$f->label = $this->_('Verification Code');
|
||||
$f->description = $this->_('Please type or paste in the code you received in your email.');
|
||||
@@ -506,10 +512,11 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$f->attr('required', 'required');
|
||||
$form->add($f);
|
||||
|
||||
$template = $templates->get('user');
|
||||
$fieldgroup = $template->fieldgroup;
|
||||
$confirmFields = array();
|
||||
|
||||
foreach($this->confirmFields as $key => $fieldName) {
|
||||
/** @var Fieldgroup $fieldgroup */
|
||||
$fieldgroup = $this->wire('templates')->get('user')->fieldgroup;
|
||||
if(strpos($fieldName, ':') === false) {
|
||||
$field = $fieldgroup->getFieldContext($fieldName);
|
||||
} else {
|
||||
@@ -530,8 +537,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
}
|
||||
$this->confirmFields = $confirmFields; // normalized to only known field names
|
||||
|
||||
/** @var Field $field */
|
||||
$field = $this->wire('fields')->get('pass');
|
||||
$field = $this->wire()->fields->get('pass');
|
||||
|
||||
/** @var InputfieldPassword $inputfield */
|
||||
$inputfield = $field->getInputfield(new NullPage(), $field);
|
||||
$inputfield->required = true;
|
||||
@@ -541,7 +548,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$form->add($inputfield);
|
||||
|
||||
/** @var InputfieldSubmit $submit */
|
||||
$submit = $this->modules->get("InputfieldSubmit");
|
||||
$submit = $modules->get("InputfieldSubmit");
|
||||
$submit->attr('id+name', 'submit_reset');
|
||||
$form->add($submit);
|
||||
|
||||
@@ -557,6 +564,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function step4_completeReset($id, $form) {
|
||||
|
||||
$input = $this->wire()->input;
|
||||
|
||||
$confirmInputfields = array();
|
||||
foreach($this->confirmFields as $fieldName) {
|
||||
@@ -570,8 +579,6 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$confirmInputfields[$fieldName] = $inputfield;
|
||||
}
|
||||
|
||||
/** @var WireInput $input */
|
||||
$input = $this->wire('input');
|
||||
$form->processInput($input->post);
|
||||
$attempts = (int) $this->sessionGet('attempts');
|
||||
$this->sessionSet('attempts', ++$attempts);
|
||||
@@ -589,8 +596,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$numErrors++;
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->wire('users')->get((int) $id);
|
||||
$user = $this->wire()->users->get((int) $id);
|
||||
|
||||
foreach($confirmInputfields as $fieldName => $f) {
|
||||
$fv = $f->attr('value');
|
||||
@@ -608,7 +614,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$pass = $form->getChildByName('pass')->attr('value');
|
||||
|
||||
if($numErrors || count($form->getErrors()) || !$user->id || !strlen($pass)) {
|
||||
$this->wire('session')->redirect($form->attr('action'));
|
||||
$this->wire()->session->redirect($form->attr('action'));
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -639,13 +645,13 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function insertNewResetRequest($user) {
|
||||
|
||||
/** @var WireDatabasePDO $database */
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
$session = $this->wire()->session;
|
||||
|
||||
// create the unique verification token that is stored on the server and sent in the email
|
||||
$pass = new Password();
|
||||
$token = $pass->randomBase64String(32);
|
||||
$ip = $this->wire('session')->getIP();
|
||||
$ip = $session->getIP();
|
||||
|
||||
if(!strlen($token)) return false;
|
||||
|
||||
@@ -671,7 +677,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
|
||||
} catch(\Exception $e) {
|
||||
// catch any errors, just to prevent anything from ever being reported to screen
|
||||
$this->wire('session')->removeNotices();
|
||||
$session->removeNotices();
|
||||
$this->errors('all clear');
|
||||
$this->error($this->_('Unable to complete this step'));
|
||||
$this->deleteReset();
|
||||
@@ -691,12 +697,10 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function deleteReset($id = 0, $token = null) {
|
||||
|
||||
/** @var WireDatabasePDO $database */
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
|
||||
if(!$id) $id = (int) $this->sessionGet('id');
|
||||
|
||||
/** @var Session $session */
|
||||
$this->sessionRemove('step');
|
||||
$this->sessionRemove('name');
|
||||
$this->sessionRemove('id');
|
||||
@@ -723,7 +727,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function deleteResetAndRedirect($id = 0, $token = null) {
|
||||
$this->deleteReset($id, $token);
|
||||
$this->wire('session')->redirect('./');
|
||||
$this->wire()->session->redirect('./');
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -735,8 +739,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function setupResetTable() {
|
||||
|
||||
/** @var WireDatabasePDO $database */
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
|
||||
try {
|
||||
$query = $database->prepare("SHOW COLUMNS FROM `" . self::table . "`");
|
||||
@@ -761,7 +764,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function sessionSet($key, $value) {
|
||||
$this->wire('session')->setFor($this, $key, $value);
|
||||
$this->wire()->session->setFor($this, $key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -772,7 +775,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function sessionGet($key) {
|
||||
return $this->wire('session')->getFor($this, $key);
|
||||
return $this->wire()->session->getFor($this, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -782,7 +785,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function sessionRemove($key) {
|
||||
$this->wire('session')->removeFor($this, $key);
|
||||
$this->wire()->session->removeFor($this, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -806,31 +809,32 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
} else if($user->isUnpublished()) {
|
||||
$reason = $this->_('User is unpublished');
|
||||
return false;
|
||||
} else if(!$this->wire('session')->allowLogin($user->name, $user)) {
|
||||
} else if(!$this->wire()->session->allowLogin($user->name, $user)) {
|
||||
$reason = $this->_('User is not allowed to login per site configuration');
|
||||
return false;
|
||||
}
|
||||
|
||||
$allow = true;
|
||||
$roles = $this->wire()->roles;
|
||||
|
||||
foreach(array('allowRoles', 'blockRoles') as $type) {
|
||||
|
||||
$roles = array();
|
||||
$testRoles = array();
|
||||
|
||||
foreach($this->get($type) as $roleName) {
|
||||
$roleID = 0;
|
||||
if(strpos($roleName, ':')) list($roleName, $roleID) = explode(':', $roleName, 2);
|
||||
$role = $this->wire('roles')->get($roleName);
|
||||
if(!$role || !$role->id) $role = $this->wire('roles')->get((int) $roleID);
|
||||
$role = $roles->get($roleName);
|
||||
if(!$role || !$role->id) $role = $roles->get((int) $roleID);
|
||||
if(!$role || !$role->id) continue;
|
||||
$roles[] = $role;
|
||||
$testRoles[] = $role;
|
||||
}
|
||||
|
||||
if(!count($roles)) continue;
|
||||
if(!count($testRoles)) continue;
|
||||
|
||||
$hasRole = false;
|
||||
|
||||
foreach($roles as $role) {
|
||||
foreach($testRoles as $role) {
|
||||
if($user->hasRole($role)) {
|
||||
$hasRole = $role;
|
||||
break;
|
||||
@@ -888,8 +892,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
}
|
||||
|
||||
// check the quantity of *successful* attempts recorded in the database for this IP
|
||||
if($ip === null) $ip = $this->wire('session')->getIP();
|
||||
$query = $this->wire('database')->prepare('SELECT COUNT(*) FROM ' . self::table . ' WHERE ip=:ip');
|
||||
if($ip === null) $ip = $this->wire()->session->getIP();
|
||||
$query = $this->wire()->database->prepare('SELECT COUNT(*) FROM ' . self::table . ' WHERE ip=:ip');
|
||||
$query->bindValue(':ip', $ip);
|
||||
$query->execute();
|
||||
$qty = $query->fetchColumn();
|
||||
@@ -905,7 +909,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
|
||||
// check the quantity of *any) requests recorded in our hourly cache for this IP address
|
||||
$ip = ip2long($ip);
|
||||
$qty = (int) $this->wire('cache')->get("forgotpass$ip", $this->expireSecs);
|
||||
$qty = (int) $this->wire()->cache->get("forgotpass$ip", $this->expireSecs);
|
||||
if($qty >= $maxPerIP) {
|
||||
if(self::debug) {
|
||||
$this->error("Max per IP limit ($qty) reached (via cache)");
|
||||
@@ -923,14 +927,15 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function trackNewRequest() {
|
||||
$cache = $this->wire()->cache;
|
||||
$pass = new Password();
|
||||
$verify = $pass->randomBase64String(22);
|
||||
$this->sessionSet('verify', $verify);
|
||||
$qty = (int) $this->sessionGet('qty');
|
||||
$this->sessionSet('qty', $qty + 1);
|
||||
$ip = $this->wire('session')->getIP(true); // int
|
||||
$qty = (int) $this->wire('cache')->get("forgotpass$ip", $this->expireSecs);
|
||||
$this->wire('cache')->save("forgotpass$ip", $qty + 1, $this->expireSecs);
|
||||
$ip = $this->wire()->session->getIP(true); // int
|
||||
$qty = (int) $cache->get("forgotpass$ip", $this->expireSecs);
|
||||
$cache->save("forgotpass$ip", $qty + 1, $this->expireSecs);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -938,9 +943,9 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
public function clearRequests() {
|
||||
$this->wire('database')->exec("DELETE FROM " . self::table);
|
||||
$this->wire('cache')->delete("forgotpass*");
|
||||
$this->wire('session')->removeAllFor($this);
|
||||
$this->wire()->database->exec("DELETE FROM " . self::table);
|
||||
$this->wire()->cache->delete("forgotpass*");
|
||||
$this->wire()->session->removeAllFor($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -950,13 +955,14 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function getEmailFrom() {
|
||||
$config = $this->wire()->config;
|
||||
$emailFrom = $this->emailFrom;
|
||||
if(empty($emailFrom)) {
|
||||
$settings = $this->wire()->config->wireMail;
|
||||
$settings = $config->wireMail;
|
||||
if(!empty($settings['from'])) $emailFrom = $settings['from'];
|
||||
}
|
||||
if(empty($emailFrom)) $emailFrom = $this->wire('config')->adminEmail;
|
||||
if(empty($emailFrom)) $emailFrom = 'noreply@' . $this->wire('config')->httpHost;
|
||||
if(empty($emailFrom)) $emailFrom = $config->adminEmail;
|
||||
if(empty($emailFrom)) $emailFrom = 'noreply@' . $config->httpHost;
|
||||
return $emailFrom;
|
||||
}
|
||||
|
||||
@@ -969,7 +975,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
public function ___log($str = '', array $options = array()) {
|
||||
if(!$this->useLog) return $this->wire('log');
|
||||
if(!$this->useLog) return $this->wire()->log;
|
||||
if(empty($options['name'])) $options['name'] = 'forgot-password';
|
||||
if($this->logUser) $options['user'] = $this->logUser;
|
||||
return parent::___log($str, $options);
|
||||
@@ -998,11 +1004,13 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
}
|
||||
|
||||
protected function ___renderError($str) {
|
||||
return "<p class='pwfp-error'><strong>" . $this->wire('sanitizer')->entities1($str) . "</strong></p>";
|
||||
$str = $this->wire()->sanitizer->entities1($str);
|
||||
return "<p class='pwfp-error'><strong>$str</strong></p>";
|
||||
}
|
||||
|
||||
protected function ___renderMessage($str) {
|
||||
return "<p class='pwfp-message'>" . $this->wire('sanitizer')->entities1($str) . "</p>";
|
||||
$str = $this->wire()->sanitizer->entities1($str);
|
||||
return "<p class='pwfp-message'>$str</p>";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1025,9 +1033,8 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
public function ___install() {
|
||||
|
||||
/** @var WireDatabasePDO $database */
|
||||
$database = $this->wire('database');
|
||||
$engine = $this->wire('config')->dbEngine;
|
||||
$database = $this->wire()->database;
|
||||
$engine = $this->wire()->config->dbEngine;
|
||||
|
||||
$sql = "CREATE TABLE `" . self::table . "` ( " .
|
||||
"id INT unsigned NOT NULL PRIMARY KEY, " .
|
||||
@@ -1049,8 +1056,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
}
|
||||
|
||||
public function ___uninstall() {
|
||||
/** @var WireDatabasePDO $database */
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
$database->exec("DROP TABLE `" . self::table ."`");
|
||||
}
|
||||
|
||||
@@ -1071,18 +1077,20 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
*/
|
||||
public function getModuleConfigInputfields(InputfieldWrapper $inputfields) {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
|
||||
$form = $inputfields;
|
||||
$optional = ' ' . $this->_('(optional)');
|
||||
|
||||
/** @var InputfieldEmail $f */
|
||||
$f = $this->wire('modules')->get('InputfieldEmail');
|
||||
$f = $modules->get('InputfieldEmail');
|
||||
$f->attr('name', 'emailFrom');
|
||||
$f->label = $this->_('Email address to send messages from');
|
||||
$f->attr('value', $this->emailFrom);
|
||||
$form->add($f);
|
||||
|
||||
/** @var InputfieldCheckbox $f */
|
||||
$f = $this->wire('modules')->get('InputfieldCheckbox');
|
||||
$f = $modules->get('InputfieldCheckbox');
|
||||
$f->attr('name', 'askEmail');
|
||||
$f->label = $this->_('Use email rather than user name');
|
||||
$f->description =
|
||||
@@ -1095,7 +1103,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$form->add($f);
|
||||
|
||||
/** @var InputfieldInteger $f */
|
||||
$f = $this->wire('modules')->get('InputfieldInteger');
|
||||
$f = $modules->get('InputfieldInteger');
|
||||
$f->attr('name', 'maxPerIP');
|
||||
$f->label = $this->_('Max password reset requests per IP address or session');
|
||||
$f->description = $this->_('Use this option to prevent the same IP address or session from flooding reset requests.');
|
||||
@@ -1103,8 +1111,9 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$f->columnWidth = 50;
|
||||
$f->attr('value', $this->maxPerIP);
|
||||
$form->add($f);
|
||||
|
||||
$f = $this->wire('modules')->get('InputfieldCheckbox');
|
||||
|
||||
/** @var InputfieldCheckbox $f */
|
||||
$f = $modules->get('InputfieldCheckbox');
|
||||
$f->attr('name', 'useLog');
|
||||
$f->label = $this->_('Log activity?');
|
||||
$f->description = $this->_('When enabled, password reset requests will be logged.');
|
||||
@@ -1116,7 +1125,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$form->add($f);
|
||||
|
||||
/** @var InputfieldAsmSelect $f */
|
||||
$f = $this->wire('modules')->get('InputfieldAsmSelect');
|
||||
$f = $modules->get('InputfieldAsmSelect');
|
||||
$f->attr('name', 'confirmFields');
|
||||
$f->label = $this->_('Confirm field values') . $optional;
|
||||
$f->description = $this->_('As an extra verification in the last step, ask user to confirm values of these fields before accepting new password.');
|
||||
@@ -1131,7 +1140,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$form->add($f);
|
||||
|
||||
/** @var InputfieldCheckboxes $f */
|
||||
$f = $this->wire('modules')->get('InputfieldCheckboxes');
|
||||
$f = $modules->get('InputfieldCheckboxes');
|
||||
$f->attr('name', 'allowRoles');
|
||||
$f->label = $this->_('Allowed roles') . $optional;
|
||||
$f->description = $this->_('To only allow certain roles to reset password, select them here.');
|
||||
@@ -1145,7 +1154,7 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$form->add($f);
|
||||
|
||||
/** @var InputfieldCheckboxes $f */
|
||||
$f = $this->wire('modules')->get('InputfieldCheckboxes');
|
||||
$f = $modules->get('InputfieldCheckboxes');
|
||||
$f->attr('name', 'blockRoles');
|
||||
$f->label = $this->_('Blocked roles') . $optional;
|
||||
$f->description = $this->_('To block certain roles from resetting password, select them here.');
|
||||
@@ -1158,14 +1167,14 @@ class ProcessForgotPassword extends Process implements ConfigurableModule {
|
||||
$form->add($f);
|
||||
|
||||
/** @var InputfieldCheckbox $f */
|
||||
$f = $this->wire('modules')->get('InputfieldCheckbox');
|
||||
$f = $modules->get('InputfieldCheckbox');
|
||||
$f->attr('name', '_clearCache');
|
||||
$f->label = $this->_('Clear password reset request caches and tables');
|
||||
$f->description = $this->_('This happens automatically over time but can be cleared manually if desired.');
|
||||
$f->collapsed = Inputfield::collapsedYes;
|
||||
$form->add($f);
|
||||
|
||||
if($this->wire('input')->post('_clearCache')) {
|
||||
if($this->wire()->input->post('_clearCache')) {
|
||||
$this->clearRequests();
|
||||
$this->message($this->_('Cleared password reset requests'));
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
* For more details about how Process modules work, please see:
|
||||
* /wire/core/Process.php
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2016 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*
|
||||
@@ -23,7 +23,7 @@ class ProcessList extends Process {
|
||||
'version' => 101,
|
||||
'permanent' => true,
|
||||
'permission' => 'page-view',
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ class ProcessList extends Process {
|
||||
}
|
||||
|
||||
protected function render() {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$sanitizer = $this->wire()->sanitizer;
|
||||
|
||||
$defaults = array(
|
||||
'dlClass' => 'nav',
|
||||
'dtClass' => '',
|
||||
@@ -40,13 +44,14 @@ class ProcessList extends Process {
|
||||
'disabledClass' => 'ui-priority-secondary',
|
||||
'showIcon' => true,
|
||||
);
|
||||
$settings = $this->wire('config')->ProcessList;
|
||||
|
||||
$settings = $this->wire()->config->ProcessList;
|
||||
if(!is_array($settings)) $settings = array();
|
||||
$settings = array_merge($defaults, $settings);
|
||||
$out = "\n<dl class='$settings[dlClass]'>";
|
||||
$cnt = 0;
|
||||
|
||||
foreach($this->page->children("check_access=0") as $child) {
|
||||
foreach($this->wire()->page->children("check_access=0") as $child) {
|
||||
|
||||
if(!$child->viewable()) continue;
|
||||
|
||||
@@ -56,7 +61,7 @@ class ProcessList extends Process {
|
||||
|
||||
if($child->process) {
|
||||
|
||||
$info = $this->modules->getModuleInfoVerbose($child->process, array('noCache' => true));
|
||||
$info = $modules->getModuleInfoVerbose($child->process, array('noCache' => true));
|
||||
if($settings['showIcon']) {
|
||||
$icon = $child->get('page_icon');
|
||||
if(!$icon) $icon = $info['icon'];
|
||||
@@ -71,14 +76,14 @@ class ProcessList extends Process {
|
||||
if(!strlen($title)) $title = $child->name;
|
||||
$titleTranslated = __($title, '/wire/templates-admin/default.php');
|
||||
if($titleTranslated && $titleTranslated != $title) $title = $titleTranslated;
|
||||
$title = $this->wire('sanitizer')->entities1($title);
|
||||
$title = $sanitizer->entities1($title);
|
||||
if($child->summary) {
|
||||
$summary = $child->summary;
|
||||
} else {
|
||||
$summary = $info['summary'];
|
||||
}
|
||||
|
||||
$summary = $this->wire('sanitizer')->entities1($summary);
|
||||
$summary = $sanitizer->entities1($summary);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -88,7 +93,7 @@ class ProcessList extends Process {
|
||||
$dtClass .= ' ' . $settings['disabledClass'];
|
||||
$ddClass .= ' ' . $settings['disabledClass'];
|
||||
} else if($child->summary) {
|
||||
$summary = $this->wire('sanitizer')->entities($child->getUnformatted('summary'));
|
||||
$summary = $sanitizer->entities($child->getUnformatted('summary'));
|
||||
} else {
|
||||
$summary = '<!--' . $this->_('No description available') . '-->';
|
||||
}
|
||||
@@ -104,6 +109,7 @@ class ProcessList extends Process {
|
||||
|
||||
$out .= "\n</dl>";
|
||||
if(!$cnt) $out = '';
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
* For more details about how Process modules work, please see:
|
||||
* /wire/core/Process.php
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2020 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* @property bool $allowForgot Whether the ProcessForgotPassword module is installed.
|
||||
@@ -179,10 +179,10 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
|
||||
$this->id = isset($_GET['id']) ? (int) $_GET['id'] : ''; // id no longer used as anything but a toggle (on/off)
|
||||
$this->set('allowForgot', $this->modules->isInstalled('ProcessForgotPassword'));
|
||||
$this->isAdmin = $this->wire('page')->template == 'admin';
|
||||
$this->isAdmin = $this->wire()->page->template == 'admin';
|
||||
$this->useEmailLogin = $this->useEmailLogin();
|
||||
|
||||
return parent::init();
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,13 +250,13 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
if(!$this->emailField) return false;
|
||||
|
||||
/** @var Field $field */
|
||||
$field = $this->fields->get($this->emailField);
|
||||
$field = $this->wire()->fields->get($this->emailField);
|
||||
if(!$field) return false;
|
||||
if(!$field->type instanceof FieldtypeEmail) return false;
|
||||
if(!$field->hasFlag(Field::flagUnique)) return false;
|
||||
|
||||
/** @var Template $template */
|
||||
$template = $this->templates->get($this->config->userTemplateID);
|
||||
$template = $this->wire()->templates->get($this->wire()->config->userTemplateID);
|
||||
if(!$template || !$template->hasField($field)) return false;
|
||||
|
||||
return (int) $this->allowEmail;
|
||||
@@ -274,7 +274,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
public function setLoginURL($url) {
|
||||
$url = $this->wire('sanitizer')->url($url, array('throw' => true));
|
||||
$url = $this->wire()->sanitizer->url($url, array('throw' => true));
|
||||
$this->loginURL = $url;
|
||||
return $this;
|
||||
}
|
||||
@@ -290,7 +290,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
public function setLogoutURL($url) {
|
||||
$url = $this->wire('sanitizer')->url($url, array('throw' => true));
|
||||
$url = $this->wire()->sanitizer->url($url, array('throw' => true));
|
||||
$this->logoutURL = $url;
|
||||
return $this;
|
||||
}
|
||||
@@ -344,7 +344,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
// two factor authentication
|
||||
if($tfa->success()) {
|
||||
$this->tfaLoginSuccess = true;
|
||||
$this->loginSuccess($this->wire('user'));
|
||||
$this->loginSuccess($this->wire()->user);
|
||||
$this->afterLoginRedirect('./');
|
||||
} else {
|
||||
return $tfa->render();
|
||||
@@ -395,9 +395,8 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
public function getTfa() {
|
||||
$tfa = null;
|
||||
$tfas = $this->wire()->modules->findByPrefix('Tfa');
|
||||
if(!count($tfas)) return $tfa;
|
||||
if(!count($tfas)) return null;
|
||||
$tfa = new Tfa();
|
||||
$this->wire($tfa);
|
||||
$tfa->rememberDays = $this->tfaRememberDays;
|
||||
@@ -416,6 +415,10 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function getLoginName() {
|
||||
|
||||
$sanitizer = $this->wire()->sanitizer;
|
||||
$config = $this->wire()->config;
|
||||
$users = $this->wire()->users;
|
||||
|
||||
$value = $this->nameField->attr('value');
|
||||
if(!strlen($value)) return false;
|
||||
|
||||
@@ -433,7 +436,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
}
|
||||
|
||||
// at this point we are dealing with an email login
|
||||
$value = strtolower($this->sanitizer->email($value));
|
||||
$value = strtolower($sanitizer->email($value));
|
||||
$this->submitLoginName = $value;
|
||||
if(empty($value)) return false;
|
||||
|
||||
@@ -444,7 +447,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
}
|
||||
|
||||
$error = $this->labels('email-not-supported');
|
||||
$items = $this->users->find("include=all, $this->emailField=" . $this->sanitizer->selectorValue($value));
|
||||
$items = $users->find("include=all, $this->emailField=" . $sanitizer->selectorValue($value));
|
||||
|
||||
if(!$items->count()) {
|
||||
// fail: no matches
|
||||
@@ -453,7 +456,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
|
||||
} else if($items->count() > 1) {
|
||||
// fail: more than one match
|
||||
if($this->config->debug) $error .= ' (not unique)';
|
||||
if($config->debug) $error .= ' (not unique)';
|
||||
$this->loginFailed($value, $error);
|
||||
return false;
|
||||
}
|
||||
@@ -463,7 +466,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
|
||||
if($user->status > Page::statusHidden) {
|
||||
// hidden, unpublished, trash
|
||||
if($this->config->debug) $error .= ' (inactive)';
|
||||
if($config->debug) $error .= ' (inactive)';
|
||||
$this->loginFailed($value, $error);
|
||||
return false;
|
||||
}
|
||||
@@ -566,13 +569,14 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
public function ___executeLogout() {
|
||||
if($this->logoutURL) {
|
||||
$url = $this->logoutURL;
|
||||
} else if($this->isAdmin || $this->wire('page')->template == 'admin') {
|
||||
$url = $this->config->urls->admin . './?loggedout=1';
|
||||
} else if($this->isAdmin || $this->wire()->page->template->name === 'admin') {
|
||||
$url = $this->wire()->config->urls->admin . './?loggedout=1';
|
||||
} else {
|
||||
$url = "./?logout=2";
|
||||
}
|
||||
$this->session->logout();
|
||||
$this->session->redirect($url, false);
|
||||
$session = $this->wire()->session;
|
||||
$session->logout();
|
||||
$session->redirect($url, false);
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -585,8 +589,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function ___beforeLogin() {
|
||||
|
||||
/** @var Session $session */
|
||||
$session = $this->wire('session');
|
||||
$session = $this->wire()->session;
|
||||
|
||||
$beforeLoginVars = $this->getBeforeLoginVars();
|
||||
$session->setFor($this, 'beforeLoginVars', $beforeLoginVars);
|
||||
@@ -596,24 +599,30 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
|
||||
// if checks already completed don't run them again
|
||||
if($session->getFor($this, 'beforeLoginChecks')) return;
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$config = $this->wire()->config;
|
||||
$input = $this->wire()->input;
|
||||
$files = $this->wire()->files;
|
||||
$log = $this->wire()->log;
|
||||
|
||||
// any remaining checks only if currently in the admin
|
||||
if(!$this->isAdmin) return;
|
||||
|
||||
if( ini_get('session.save_handler') == 'files'
|
||||
&& !$this->wire('modules')->isInstalled('SessionHandlerDB')
|
||||
&& !$this->wire('input')->get('db')
|
||||
&& !$modules->isInstalled('SessionHandlerDB')
|
||||
&& !$input->get('db')
|
||||
) {
|
||||
|
||||
$installSessionDB = false;
|
||||
$path = $this->config->paths->sessions;
|
||||
$path = $config->paths->sessions;
|
||||
$error = '';
|
||||
|
||||
if(!file_exists($path)) {
|
||||
$this->wire('files')->mkdir($path);
|
||||
$files->mkdir($path);
|
||||
clearstatcache();
|
||||
if(file_exists($path)) {
|
||||
$this->wire('log')->message("Created session path $path");
|
||||
$log->message("Created session path $path");
|
||||
} else {
|
||||
$installSessionDB = true;
|
||||
$error = "Session path $path does not exist and we are unable to create it.";
|
||||
@@ -621,10 +630,10 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
}
|
||||
|
||||
if(!is_writable($path)) {
|
||||
$this->wire('files')->chmod($path);
|
||||
$files->chmod($path);
|
||||
clearstatcache();
|
||||
if(is_writable($path)) {
|
||||
$this->wire('log')->message("Updated session path to be writable $path");
|
||||
$log->message("Updated session path to be writable $path");
|
||||
} else {
|
||||
$installSessionDB = true;
|
||||
$error = "Unable to write to session path $path, and unable to fix the permissions.";
|
||||
@@ -633,12 +642,12 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
|
||||
// if we can't get file-based sessions going, switch to database sessions to ensure admin can login
|
||||
if($installSessionDB) {
|
||||
if($error) $this->wire('log')->error($error);
|
||||
if($this->wire('modules')->get('SessionHandlerDB')) {
|
||||
$this->wire('log')->error("Installed SessionHandlerDB as an alternate session handler. If you wish to uninstall this, do so after correcting the session path error.");
|
||||
$this->wire('session')->redirect("./?db=1"); // db param to prevent potential infinite redirect
|
||||
if($error) $log->error($error);
|
||||
if($modules->get('SessionHandlerDB')) {
|
||||
$log->error("Installed SessionHandlerDB as an alternate session handler. If you wish to uninstall this, do so after correcting the session path error.");
|
||||
$session->redirect("./?db=1"); // db param to prevent potential infinite redirect
|
||||
} else {
|
||||
$this->wire('log')->error("Unable to install alternate session handler module SessionHandlerDB");
|
||||
$log->error("Unable to install alternate session handler module SessionHandlerDB");
|
||||
$this->error("Session write error. Login may not be possible.");
|
||||
}
|
||||
}
|
||||
@@ -655,9 +664,9 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function ___afterLogin() {
|
||||
if($this->wire('user')->isSuperuser()) {
|
||||
if($this->wire()->user->isSuperuser()) {
|
||||
/** @var SystemUpdater $systemUpdater */
|
||||
$systemUpdater = $this->wire('modules')->get('SystemUpdater');
|
||||
$systemUpdater = $this->wire()->modules->get('SystemUpdater');
|
||||
if($systemUpdater) {
|
||||
$updatesApplied = $systemUpdater->getUpdatesApplied();
|
||||
$checks = $systemUpdater->getChecks();
|
||||
@@ -688,6 +697,8 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function ___buildLoginForm() {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
|
||||
$useEmailLogin = $this->useEmailLogin();
|
||||
$nameInputType = 'InputfieldText';
|
||||
$nameInputLabel = $this->labels('username'); // Login form: username field label
|
||||
@@ -699,28 +710,28 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
$nameInputLabel = $this->labels('username-or-email'); // Login form: username OR email field label
|
||||
}
|
||||
|
||||
$this->nameField = $this->modules->get($nameInputType);
|
||||
$this->nameField = $modules->get($nameInputType);
|
||||
$this->nameField->label = $nameInputLabel;
|
||||
$this->nameField->attr('id+name', 'login_name');
|
||||
$this->nameField->attr('class', $this->className() . 'Name');
|
||||
$this->nameField->addClass('InputfieldFocusFirst');
|
||||
$this->nameField->collapsed = Inputfield::collapsedNever;
|
||||
|
||||
$this->passField = $this->modules->get('InputfieldText');
|
||||
$this->passField = $modules->get('InputfieldText');
|
||||
$this->passField->set('label', $this->labels('password')); // Login form: password field label
|
||||
$this->passField->attr('id+name', 'login_pass');
|
||||
$this->passField->attr('type', 'password');
|
||||
$this->passField->attr('class', $this->className() . 'Pass');
|
||||
$this->passField->collapsed = Inputfield::collapsedNever;
|
||||
|
||||
$this->submitField = $this->modules->get('InputfieldSubmit');
|
||||
$this->submitField = $modules->get('InputfieldSubmit');
|
||||
$this->submitField->attr('name', 'login_submit');
|
||||
$this->submitField->attr('value', $this->labels('login')); // Login form: submit login button
|
||||
|
||||
$this->form = $this->modules->get('InputfieldForm');
|
||||
$this->form = $modules->get('InputfieldForm');
|
||||
|
||||
// we'll retain an ID field in the GET url, if it was there (note: no longer used as anything but a toggle on/off)
|
||||
$this->form->attr('action', "./" . ($this->id ? "?id={$this->id}" : ''));
|
||||
$this->form->attr('action', "./" . ($this->id ? "?id=$this->id" : ''));
|
||||
$this->form->addClass('InputfieldFormFocusFirst');
|
||||
|
||||
$this->form->attr('id', $this->className() . 'Form');
|
||||
@@ -731,19 +742,21 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
if($this->isAdmin) {
|
||||
// detect hidpi at login (populated from js)
|
||||
/** @var InputfieldHidden $f */
|
||||
$f = $this->modules->get('InputfieldHidden');
|
||||
$f = $modules->get('InputfieldHidden');
|
||||
$f->attr('id+name', 'login_hidpi');
|
||||
$f->attr('value', 0);
|
||||
$this->form->add($f);
|
||||
|
||||
// detect touch device login (populated from js)
|
||||
$f = $this->modules->get('InputfieldHidden');
|
||||
/** @var InputfieldHidden $f */
|
||||
$f = $modules->get('InputfieldHidden');
|
||||
$f->attr('id+name', 'login_touch');
|
||||
$f->attr('value', 0);
|
||||
$this->form->add($f);
|
||||
|
||||
// detect touch device login (populated from js)
|
||||
$f = $this->modules->get('InputfieldHidden');
|
||||
/** @var InputfieldHidden $f */
|
||||
$f = $modules->get('InputfieldHidden');
|
||||
$f->attr('id+name', 'login_width');
|
||||
$f->attr('value', 0);
|
||||
$this->form->add($f);
|
||||
@@ -765,10 +778,10 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function ___renderLoginForm() {
|
||||
$loggedIn = $this->wire('user')->isLoggedin();
|
||||
$loggedIn = $this->wire()->user->isLoggedin();
|
||||
$out = '';
|
||||
|
||||
if($this->wire('input')->get('login') && $loggedIn) {
|
||||
if($this->wire()->input->get('login') && $loggedIn) {
|
||||
// redirect to page after login
|
||||
$this->afterLoginRedirect();
|
||||
} else if($loggedIn) {
|
||||
@@ -784,9 +797,8 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
if(count($links)) {
|
||||
$out .= str_replace('{out}', implode($this->markup('login-links-split'), $links), $this->markup('login-links'));
|
||||
}
|
||||
if(!$this->wire('modules')->isInstalled('InputDetect')) {
|
||||
/** @var Config $config */
|
||||
$config = $this->wire('config');
|
||||
if(!$this->wire()->modules->isInstalled('InputDetect')) {
|
||||
$config = $this->wire()->config;
|
||||
$config->scripts->prepend($config->urls('ProcessLogin') . 'what-input.min.js');
|
||||
}
|
||||
}
|
||||
@@ -840,14 +852,15 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*
|
||||
*/
|
||||
protected function ___afterLoginOutput() {
|
||||
$config = $this->wire()->config;
|
||||
/** @var InputfieldButton $btn */
|
||||
$btn = $this->wire('modules')->get('InputfieldButton');
|
||||
if($this->wire('user')->hasPermission('profile-edit')) {
|
||||
$btn = $this->wire()->modules->get('InputfieldButton');
|
||||
if($this->wire()->user->hasPermission('profile-edit')) {
|
||||
$btn->value = $this->labels('edit-profile');
|
||||
$btn->href = $this->config->urls->admin . 'profile/';
|
||||
$btn->href = $config->urls->admin . 'profile/';
|
||||
} else {
|
||||
$btn->value = $this->labels('continue');
|
||||
$btn->href = $this->wire('config')->urls->root;
|
||||
$btn->href = $config->urls->root;
|
||||
}
|
||||
return "<p>" . $btn->render() . "</p>";
|
||||
}
|
||||
@@ -961,7 +974,6 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function ___loginSuccess(User $user) {
|
||||
|
||||
/** @var Session $session */
|
||||
$session = $this->wire()->session;
|
||||
|
||||
if($this->isAdmin) {
|
||||
@@ -978,9 +990,10 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
if(!$user->hasTfa() && count($this->tfaRecRoleIDs) && !$this->tfaLoginSuccess) {
|
||||
// determine if Tfa module is installed and user has role requiring Tfa
|
||||
$requireTfa = false;
|
||||
if(count($this->wire('modules')->findByPrefix('Tfa'))) {
|
||||
$roles = $this->wire()->roles;
|
||||
if(count($this->wire()->modules->findByPrefix('Tfa'))) {
|
||||
foreach($this->tfaRecRoleIDs as $roleID) {
|
||||
$role = $this->wire('roles')->get((int) $roleID);
|
||||
$role = $roles->get((int) $roleID);
|
||||
if($role && $user->hasRole($role)) {
|
||||
$requireTfa = true;
|
||||
break;
|
||||
@@ -988,7 +1001,7 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
}
|
||||
}
|
||||
if($requireTfa) {
|
||||
$url = $this->wire('config')->urls('admin') . 'profile/#wrap_Inputfield_tfa_type';
|
||||
$url = $this->wire()->config->urls('admin') . 'profile/#wrap_Inputfield_tfa_type';
|
||||
$session->setFor('_user', 'requireTfa', $url);
|
||||
}
|
||||
}
|
||||
@@ -1004,14 +1017,13 @@ class ProcessLogin extends Process implements ConfigurableModule {
|
||||
*/
|
||||
public function getModuleConfigInputfields(InputfieldWrapper $inputfields) {
|
||||
|
||||
/** @var Modules $modules */
|
||||
$modules = $this->wire('modules');
|
||||
$modules = $this->wire()->modules;
|
||||
|
||||
/** @var InputfieldRadios $f */
|
||||
$f = $modules->get('InputfieldRadios');
|
||||
|
||||
$emailAllow = true;
|
||||
$emailField = $this->fields->get($this->emailField); /** @var Field $field */
|
||||
$emailField = $this->wire()->fields->get($this->emailField); /** @var Field $field */
|
||||
$emailAttrs = array();
|
||||
$emailLabel = $this->_('Email address');
|
||||
$emailNotes = array();
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* ProcessWire System Helper Module
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2020 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* @method coreVersionChange($fromVersion, $toVersion)
|
||||
@@ -75,7 +75,7 @@ class SystemUpdater extends WireData implements Module, ConfigurableModule {
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
$config = $this->wire('config');
|
||||
$config = $this->wire()->config;
|
||||
$info = self::getModuleInfo();
|
||||
$moduleVersion = $info['version'];
|
||||
|
||||
@@ -88,7 +88,7 @@ class SystemUpdater extends WireData implements Module, ConfigurableModule {
|
||||
|
||||
if(empty($systemVersion)) {
|
||||
// double check, just in case (should not be possible for this to occur)
|
||||
$this->configData = $this->wire('modules')->getModuleConfigData($this);
|
||||
$this->configData = $this->wire()->modules->getModuleConfigData($this);
|
||||
$systemVersion = (int) isset($this->configData['systemVersion']) ? $this->configData['systemVersion'] : 0;
|
||||
}
|
||||
|
||||
@@ -122,11 +122,13 @@ class SystemUpdater extends WireData implements Module, ConfigurableModule {
|
||||
static $called = false;
|
||||
if($called) return; // just in case we add auto-ready support to non-autoload modules
|
||||
|
||||
if($this->wire('page')->template != 'admin') return;
|
||||
if($this->wire('config')->ajax) return;
|
||||
if($this->wire()->page->template != 'admin') return;
|
||||
|
||||
$config = $this->wire()->config;
|
||||
if($config->ajax) return;
|
||||
|
||||
$coreVersion = isset($this->configData['coreVersion']) ? $this->configData['coreVersion'] : '';
|
||||
$configVersion = $this->wire('config')->version;
|
||||
$configVersion = $config->version;
|
||||
if($coreVersion != $configVersion) $this->coreVersionChange($coreVersion, $configVersion);
|
||||
$called = true;
|
||||
}
|
||||
@@ -143,32 +145,35 @@ class SystemUpdater extends WireData implements Module, ConfigurableModule {
|
||||
*/
|
||||
protected function ___coreVersionChange($fromVersion, $toVersion) {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$session = $this->wire()->session;
|
||||
$config = $this->wire()->config;
|
||||
|
||||
$this->message(sprintf($this->_('Detected core version change %1$s => %2$s'), $fromVersion, $toVersion));
|
||||
|
||||
if( (strpos($fromVersion, '2') === 0 && strpos($toVersion, '3') === 0) ||
|
||||
(strpos($fromVersion, '3') === 0 && strpos($toVersion, '2') === 0)) {
|
||||
// clear FileCompiler cache
|
||||
$config = $this->wire('config');
|
||||
if($config->templateCompile || $config->moduleCompile) {
|
||||
/** @var FileCompiler $compiler */
|
||||
$compiler = $this->wire(new FileCompiler($this->wire('config')->paths->templates));
|
||||
$compiler = $this->wire(new FileCompiler($config->paths->templates));
|
||||
$compiler->clearCache(true);
|
||||
$this->message($this->_('Cleared file compiler cache'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!$this->numUpdatesApplied) {
|
||||
// reset modules cache, only if it hasn't been reset already by a system update
|
||||
$this->modules->resetCache();
|
||||
$modules->resetCache();
|
||||
}
|
||||
|
||||
$this->configData['coreVersion'] = $toVersion;
|
||||
$this->wire('modules')->saveModuleConfigData($this, $this->configData);
|
||||
$modules->saveModuleConfigData($this, $this->configData);
|
||||
|
||||
// remove admin theme cached info in session
|
||||
foreach($this->wire('session') as $key => $value) {
|
||||
foreach($session as $key => $value) {
|
||||
if(strpos($key, 'AdminTheme') === 0) {
|
||||
$this->wire('session')->remove($key);
|
||||
$session->remove($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,11 +187,12 @@ class SystemUpdater extends WireData implements Module, ConfigurableModule {
|
||||
*/
|
||||
public function saveSystemVersion($version) {
|
||||
if($this->manualVersion == $version) return false;
|
||||
$config = $this->wire()->config;
|
||||
$version = (int) $version;
|
||||
$this->wire('config')->systemVersion = $version;
|
||||
$config->systemVersion = $version;
|
||||
$this->configData['systemVersion'] = $version;
|
||||
$this->configData['coreVersion'] = $this->wire('config')->version;
|
||||
$this->wire('modules')->saveModuleConfigData($this, $this->configData);
|
||||
$this->configData['coreVersion'] = $config->version;
|
||||
$this->wire()->modules->saveModuleConfigData($this, $this->configData);
|
||||
$this->message("Update #$version: Completed!");
|
||||
return true;
|
||||
}
|
||||
@@ -357,12 +363,12 @@ class SystemUpdater extends WireData implements Module, ConfigurableModule {
|
||||
/**
|
||||
* Log a message to system-updater.txt log file
|
||||
*
|
||||
* @param string $text
|
||||
* @param string $str
|
||||
*
|
||||
*/
|
||||
public function log($text) {
|
||||
public function log($str) {
|
||||
$options = array('showUser' => false, 'showPage' => false);
|
||||
$this->wire('log')->save('system-updater', $text, $options);
|
||||
$this->wire()->log->save('system-updater', $str, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,29 +380,36 @@ class SystemUpdater extends WireData implements Module, ConfigurableModule {
|
||||
*/
|
||||
public function getModuleConfigInputfields(array $data) {
|
||||
|
||||
$modules = $this->wire()->modules;
|
||||
$config = $this->wire()->config;
|
||||
$sanitizer = $this->wire()->sanitizer;
|
||||
|
||||
$inputfields = $this->wire(new InputfieldWrapper());
|
||||
|
||||
$logfile = $this->wire('config')->paths->logs . 'system-updater.txt';
|
||||
$logfile = $config->paths->logs . 'system-updater.txt';
|
||||
if(is_file($logfile)) {
|
||||
$f = $this->wire('modules')->get('InputfieldMarkup');
|
||||
/** @var InputfieldMarkup $f */
|
||||
$f = $modules->get('InputfieldMarkup');
|
||||
$f->attr('name', '_log');
|
||||
$f->label = $this->_('System Update Log');
|
||||
$logContent = $this->wire('sanitizer')->unentities(file_get_contents($logfile));
|
||||
$logContent = $sanitizer->unentities(file_get_contents($logfile));
|
||||
$logContent = preg_replace('!<a href=.+?>(.+?)</a>!', '$1', $logContent);
|
||||
$f->value = '<pre>' . $this->wire('sanitizer')->entities($logContent) . '</pre>';
|
||||
$f->value = '<pre>' . $sanitizer->entities($logContent) . '</pre>';
|
||||
$inputfields->add($f);
|
||||
}
|
||||
|
||||
$f = $this->wire('modules')->get('InputfieldInteger');
|
||||
|
||||
/** @var InputfieldInteger $f */
|
||||
$f = $modules->get('InputfieldInteger');
|
||||
$f->attr('name', 'systemVersion');
|
||||
$f->label = $this->_('System Version');
|
||||
$f->description = $this->_('This lets you re-apply a system version update by reducing the version number.');
|
||||
$f->attr('value', $data['systemVersion']);
|
||||
$inputfields->add($f);
|
||||
|
||||
$f = $this->wire('modules')->get('InputfieldHidden');
|
||||
|
||||
/** @var InputfieldHidden $f */
|
||||
$f = $modules->get('InputfieldHidden');
|
||||
$f->attr('name', 'coreVersion');
|
||||
$f->attr('value', $this->wire('config')->version);
|
||||
$f->attr('value', $config->version);
|
||||
$inputfields->add($f);
|
||||
|
||||
return $inputfields;
|
||||
|
Reference in New Issue
Block a user