diff --git a/wire/core/AdminThemeFramework.php b/wire/core/AdminThemeFramework.php index 28e9c0f7..13fbb698 100644 --- a/wire/core/AdminThemeFramework.php +++ b/wire/core/AdminThemeFramework.php @@ -61,7 +61,11 @@ abstract class AdminThemeFramework extends AdminTheme { public function __construct() { parent::__construct(); $this->set('useAsLogin', false); + } + + public function wired() { $this->sanitizer = $this->wire('sanitizer'); + parent::wired(); } /** diff --git a/wire/core/FileCompiler.php b/wire/core/FileCompiler.php index e2814dce..ff226ca3 100644 --- a/wire/core/FileCompiler.php +++ b/wire/core/FileCompiler.php @@ -123,33 +123,43 @@ class FileCompiler extends Wire { * */ public function __construct($sourcePath, array $options = array()) { - $this->options = array_merge($this->options, $options); - $globalOptions = $this->wire('config')->fileCompilerOptions; + if(strpos($sourcePath, '..') !== false) $sourcePath = realpath($sourcePath); + if(DIRECTORY_SEPARATOR != '/') $sourcePath = str_replace(DIRECTORY_SEPARATOR, '/', $sourcePath); + $this->sourcePath = rtrim($sourcePath, '/') . '/'; + } + + /** + * Wired to instance + * + */ + public function wired() { + /** @var Config $config */ + $config = $this->wire('config'); + $globalOptions = $config->fileCompilerOptions; + if(is_array($globalOptions)) { $this->globalOptions = array_merge($this->globalOptions, $globalOptions); } - + if(!empty($this->globalOptions['extensions'])) { $this->extensions = $this->globalOptions['extensions']; } - + if(empty($this->globalOptions['cachePath'])) { - $this->cachePath = $this->wire('config')->paths->cache . $this->className() . '/'; + $this->cachePath = $config->paths->cache . $this->className() . '/'; } else { $this->cachePath = rtrim($this->globalOptions['cachePath'], '/') . '/'; } - + if(!strlen(__NAMESPACE__)) { // when PW compiled without namespace support $this->options['skipIfNamespace'] = false; $this->options['namespace'] = true; } - - if(strpos($sourcePath, '..') !== false) $sourcePath = realpath($sourcePath); - if(DIRECTORY_SEPARATOR != '/') $sourcePath = str_replace(DIRECTORY_SEPARATOR, '/', $sourcePath); - $this->sourcePath = rtrim($sourcePath, '/') . '/'; + + parent::wired(); } /** @@ -159,6 +169,7 @@ class FileCompiler extends Wire { * */ protected function init() { + if(!$this->isWired()) $this->wired(); static $preloaded = false; $config = $this->wire('config'); diff --git a/wire/core/Fuel.php b/wire/core/Fuel.php index 247e4fa4..33e6ac0b 100644 --- a/wire/core/Fuel.php +++ b/wire/core/Fuel.php @@ -77,8 +77,9 @@ class Fuel implements \IteratorAggregate { * */ static protected $commonNames = array( - 'page' => 1, 'pages' => 1, 'session' => 1, 'input' => 1, 'sanitizer' => 1, 'config' => 1, - 'user' => 1, 'users' => 1, 'fields' => 1, 'templates' => 1, 'database' => 1, 'modules' => 1, + 'page' => 1, 'pages' => 1, 'session' => 1, 'input' => 1, 'sanitizer' => 1, + 'config' => 1, 'user' => 1, 'users' => 1, 'fields' => 1, 'templates' => 1, + 'database' => 1, 'modules' => 1, 'hooks' => 1, ); /** diff --git a/wire/core/InputfieldWrapper.php b/wire/core/InputfieldWrapper.php index 93907dbd..61833f81 100644 --- a/wire/core/InputfieldWrapper.php +++ b/wire/core/InputfieldWrapper.php @@ -101,7 +101,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre * Label displayed when a value is required but missing * */ - protected $requiredLabel = ''; + protected $requiredLabel = 'Missing required value'; /** * Whether or not column width is handled internally @@ -117,26 +117,42 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre */ public function __construct() { parent::__construct(); - $this->children = new InputfieldsArray(); + $this->children = new InputfieldsArray(); $this->set('skipLabel', Inputfield::skipLabelFor); - $this->requiredLabel = $this->_('Missing required value'); - $columnWidthSpacing = $this->wire('config')->inputfieldColumnWidthSpacing; - $columnWidthSpacing = is_null($columnWidthSpacing) ? 1 : (int) $columnWidthSpacing; - $this->set('columnWidthSpacing', $columnWidthSpacing); $this->set('useDependencies', true); // whether or not to use consider field dependencies during processing - // allow optional override of any above settings with a $config->InputfieldWrapper array. - $settings = $this->wire('config')->InputfieldWrapper; - if(is_array($settings)) foreach($settings as $key => $value) { - if($key == 'requiredLabel') { - $this->requiredLabel = $value; - } else if($key == 'useColumnWidth') { - $this->useColumnWidth = $value; - } else { - $this->set($key, $value); - } - } $this->set('renderValueMode', false); $this->set('quietMode', false); // suppress label, description and notes + $this->set('columnWidthSpacing', 0); + } + + public function wired() { + + /** @var Config $config */ + $config = $this->wire('config'); + + $this->wire($this->children); + $this->requiredLabel = $this->_('Missing required value'); + + $columnWidthSpacing = $config->inputfieldColumnWidthSpacing; + $columnWidthSpacing = is_null($columnWidthSpacing) ? 1 : (int) $columnWidthSpacing; + if($columnWidthSpacing > 0) $this->set('columnWidthSpacing', $columnWidthSpacing); + + $columnWidthSpacing = null; + $settings = $config->InputfieldWrapper; + + if(is_array($settings)) { + foreach($settings as $key => $value) { + if($key == 'requiredLabel') { + $this->requiredLabel = $value; + } else if($key == 'useColumnWidth') { + $this->useColumnWidth = $value; + } else { + $this->set($key, $value); + } + } + } + + parent::wired(); } /** diff --git a/wire/core/Modules.php b/wire/core/Modules.php index 2fcf02e3..1b727ebc 100644 --- a/wire/core/Modules.php +++ b/wire/core/Modules.php @@ -312,7 +312,11 @@ class Modules extends WireArray { public function __construct($path) { parent::__construct(); $this->addPath($path); + } + + public function wired() { $this->coreModulesDir = '/' . $this->wire('config')->urls->data('modules'); + parent::wired(); } /** @@ -5091,7 +5095,8 @@ class Modules extends WireArray { // compile if necessary if($compile) { - $compiler = new FileCompiler(dirname($file)); + /** @var FileCompiler $compiler */ + $compiler = $this->wire(new FileCompiler(dirname($file))); $compiledFile = $compiler->compile(basename($file)); if($compiledFile) $file = $compiledFile; } diff --git a/wire/core/PagefilesManager.php b/wire/core/PagefilesManager.php index d035cd3a..8f188ba6 100644 --- a/wire/core/PagefilesManager.php +++ b/wire/core/PagefilesManager.php @@ -93,6 +93,7 @@ class PagefilesManager extends Wire { * */ public function __construct(Page $page) { + $page->wire($this); $this->init($page); } diff --git a/wire/core/Pageimage.php b/wire/core/Pageimage.php index 0914e2a8..7324c421 100644 --- a/wire/core/Pageimage.php +++ b/wire/core/Pageimage.php @@ -161,6 +161,7 @@ class Pageimage extends Pagefile { public function __construct(Pagefiles $pagefiles, $filename) { if(!$pagefiles instanceof Pageimages) throw new WireException("Pageimage::__construct requires instance of Pageimages"); + $pagefiles->wire($this); $this->pageimages = $pagefiles; parent::__construct($pagefiles, $filename); } diff --git a/wire/core/PagesParents.php b/wire/core/PagesParents.php index 07644b78..1943a92d 100644 --- a/wire/core/PagesParents.php +++ b/wire/core/PagesParents.php @@ -538,8 +538,7 @@ class PagesParents extends Wire { // identify parents to store for $page foreach($page->parents() as $parent) { $parents_id = (int) $parent->id; - if($parents_id < 2) break; - $inserts[] = "$pages_id,$parents_id"; + if($parents_id > 1) $inserts[] = "$pages_id,$parents_id"; } if(count($inserts)) { diff --git a/wire/core/SessionCSRF.php b/wire/core/SessionCSRF.php index fd91b266..36909d44 100644 --- a/wire/core/SessionCSRF.php +++ b/wire/core/SessionCSRF.php @@ -71,7 +71,7 @@ class SessionCSRF extends Wire { if(empty($tokenValue)) { // $tokenValue = md5($this->page->path() . mt_rand() . microtime()) . md5($this->page->name . $this->config->userAuthSalt . mt_rand()); $rand = new WireRandom(); - $tokenValue = $rand->base64(32); + $tokenValue = $rand->base64(32, array('fast' => true)); $this->session->set($this, $tokenName, $tokenValue); } return $tokenValue; diff --git a/wire/core/Tfa.php b/wire/core/Tfa.php index f9f44140..45794b9d 100644 --- a/wire/core/Tfa.php +++ b/wire/core/Tfa.php @@ -775,6 +775,7 @@ class Tfa extends WireData implements Module, ConfigurableModule { // fieldset for TFA settings $fieldset = new InputfieldWrapper(); + $this->wire($fieldset); $settings = $this->getUserSettings($user); if(!$this->enabledForUser($user, $settings)) { $this->getUserSettingsInputfields($user, $fieldset, $settings); diff --git a/wire/core/WireDataDB.php b/wire/core/WireDataDB.php index 839da508..32827df9 100644 --- a/wire/core/WireDataDB.php +++ b/wire/core/WireDataDB.php @@ -298,7 +298,11 @@ class WireDataDB extends WireData implements \Countable { * */ public function table($tableName = '') { - if($tableName !== '') $this->table = strtolower($this->wire('database')->escapeTable($tableName)); + if($tableName === '') return $this->table; + if(!ctype_alnum(str_replace('_', '', $tableName))) { + $tableName = preg_replace('/[^_a-zA-Z0-9]/', '_', $tableName); + } + $this->table = strtolower($tableName); return $this->table; } diff --git a/wire/core/WireFileTools.php b/wire/core/WireFileTools.php index 18c5e9f7..744ce267 100644 --- a/wire/core/WireFileTools.php +++ b/wire/core/WireFileTools.php @@ -1187,7 +1187,8 @@ class WireFileTools extends Wire { } else { $f = ''; } - $compiler = new FileCompiler(dirname($file), $options); + /** @var FileCompiler $compiler */ + $compiler = $this->wire(new FileCompiler(dirname($file), $options)); $compiledFile = $compiler->compile(basename($file)); if($f) $compiled[$f] = $compiledFile; return $compiledFile; diff --git a/wire/core/admin.php b/wire/core/admin.php index 509e6c70..41e928ad 100644 --- a/wire/core/admin.php +++ b/wire/core/admin.php @@ -136,6 +136,7 @@ if($page->process && $page->process != 'ProcessPageView') { } $controller = new ProcessController(); + $wire->wire($controller); $controller->setProcessName($page->process); $initFile = $config->paths->adminTemplates . 'init.php'; if(is_file($initFile)) { diff --git a/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module b/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module index dcf6f95c..2ba4e3e0 100644 --- a/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module +++ b/wire/modules/AdminTheme/AdminThemeUikit/AdminThemeUikit.module @@ -97,6 +97,10 @@ class AdminThemeUikit extends AdminThemeFramework implements Module, Configurabl 'dl' => 'uk-description-list uk-description-list-divider', )); + } + + public function wired() { + parent::wired(); $this->addHookAfter('InputfieldSelector::ajaxReady', $this, 'hookInputfieldSelectorAjax'); } diff --git a/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module b/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module index 71ceeb64..b1c49d2e 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module +++ b/wire/modules/Fieldtype/FieldtypeComments/FieldtypeComments.module @@ -80,7 +80,7 @@ class FieldtypeComments extends FieldtypeMulti { ); } - public function __construct() { + public function wired() { if($this->wire('config')->ajax) { $this->addHookBefore('Page::render', $this, 'checkVoteAction'); } @@ -2007,7 +2007,7 @@ class FieldtypeComments extends FieldtypeMulti { $result = false; $this->error($e->getMessage()); } - if($result) try { + if($result !== false) try { $database->exec("DROP TABLE `{$table}_votes`"); // QA } catch(\Exception $e) { // ok to ignore, as table may not exist diff --git a/wire/modules/Fieldtype/FieldtypeComments/InputfieldCommentsAdmin.module b/wire/modules/Fieldtype/FieldtypeComments/InputfieldCommentsAdmin.module index 00beba1f..fa2d7d4a 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/InputfieldCommentsAdmin.module +++ b/wire/modules/Fieldtype/FieldtypeComments/InputfieldCommentsAdmin.module @@ -191,7 +191,7 @@ class InputfieldCommentsAdmin extends Inputfield implements InputfieldItemList { $this->commentIDsToNumbers[$comment->id] = ++$n; } - $fieldset = new InputfieldWrapper(); + $fieldset = new InputfieldWrapper(); // wired $this->wire($fieldset); $n = 0; diff --git a/wire/modules/Fieldtype/FieldtypeFile.module b/wire/modules/Fieldtype/FieldtypeFile.module index 28b245d4..5d23e413 100644 --- a/wire/modules/Fieldtype/FieldtypeFile.module +++ b/wire/modules/Fieldtype/FieldtypeFile.module @@ -1134,7 +1134,7 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule { try { $result = $database->exec("ALTER TABLE `{$table}` ADD `$column` $schema[$column]"); - if($result) { + if($result !== false) { if(isset($schema['keys'][$column])) { $database->exec("ALTER TABLE `{$table}` ADD " . $schema['keys'][$column]); } @@ -1299,7 +1299,8 @@ class FieldtypeFile extends FieldtypeMulti implements ConfigurableModule { if($isNew) { $sql = "INSERT INTO $table SET pages_id=:pages_id, sort=:sort, $sets"; - $binds[":sort"] = $this->getMaxColumnValue($page, $field, 'sort'); + $sort = $this->getMaxColumnValue($page, $field, 'sort', -1); + $binds[":sort"] = ++$sort; } else { $sql = "UPDATE $table SET $sets WHERE pages_id=:pages_id AND data=:name"; $binds[':name'] = $pagefile->name; diff --git a/wire/modules/Fieldtype/FieldtypeOptions/FieldtypeOptions.module b/wire/modules/Fieldtype/FieldtypeOptions/FieldtypeOptions.module index 3606fc8c..ef4cc5bb 100644 --- a/wire/modules/Fieldtype/FieldtypeOptions/FieldtypeOptions.module +++ b/wire/modules/Fieldtype/FieldtypeOptions/FieldtypeOptions.module @@ -37,9 +37,13 @@ class FieldtypeOptions extends FieldtypeMulti implements Module { require_once($path . 'SelectableOption.php'); require_once($path . 'SelectableOptionArray.php'); require_once($path . 'SelectableOptionManager.php'); - $this->manager = $this->wire(new SelectableOptionManager()); parent::__construct(); } + + public function wired() { + $this->manager = $this->wire(new SelectableOptionManager()); + parent::wired(); + } /** * Get a property from the Fieldtype diff --git a/wire/modules/Fieldtype/FieldtypeOptions/SelectableOptionManager.php b/wire/modules/Fieldtype/FieldtypeOptions/SelectableOptionManager.php index 06c2fda6..68e0adfb 100644 --- a/wire/modules/Fieldtype/FieldtypeOptions/SelectableOptionManager.php +++ b/wire/modules/Fieldtype/FieldtypeOptions/SelectableOptionManager.php @@ -45,11 +45,12 @@ class SelectableOptionManager extends Wire { */ protected $removedOptionIDs = array(); - public function __construct() { + public function wired() { if($this->wire('modules')->isInstalled('LanguageSupportFields')) { - $this->useLanguages = true; + $this->useLanguages = true; $this->addHookAfter('Languages::updated', $this, 'updateLanguages'); } + parent::wired(); } /** diff --git a/wire/modules/Fieldtype/FieldtypeRepeater/InputfieldRepeater.module b/wire/modules/Fieldtype/FieldtypeRepeater/InputfieldRepeater.module index 73cc5396..9d0c381a 100644 --- a/wire/modules/Fieldtype/FieldtypeRepeater/InputfieldRepeater.module +++ b/wire/modules/Fieldtype/FieldtypeRepeater/InputfieldRepeater.module @@ -344,7 +344,7 @@ class InputfieldRepeater extends Inputfield implements InputfieldItemList { $inputfields = $this->getRepeaterItemInputfields($page); $isLoaded = true; } else { - $inputfields = new InputfieldWrapper(); // non loaded + $inputfields = $this->wire(new InputfieldWrapper()); // non loaded $isLoaded = false; } $inputfields->set('useDependencies', false); diff --git a/wire/modules/Inputfield/InputfieldCheckbox.module b/wire/modules/Inputfield/InputfieldCheckbox.module index cc601d29..c45cfc73 100644 --- a/wire/modules/Inputfield/InputfieldCheckbox.module +++ b/wire/modules/Inputfield/InputfieldCheckbox.module @@ -53,12 +53,16 @@ class InputfieldCheckbox extends Inputfield { $this->set('checkboxLabel', ''); // typically specified by interactive config $this->set('labelAttrs', array()); // Optional attributes for