diff --git a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module index e02b2819..d2fe24e5 100644 --- a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module +++ b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module @@ -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 2018 by Ryan Cramer * https://processwire.com * * @property string $noticeUnknown @@ -248,6 +248,64 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod */ protected $config; + /** + * @var Sanitizer + * + */ + protected $sanitizer; + + /** + * @var Session + * + */ + protected $session; + + /** + * Sanitized contents of get[modal] + * + * @var int|string|bool|null + * + */ + protected $requestModal = null; + + /** + * Sanitized contents of get[context] + * + * @var string + * + */ + protected $requestContext = ''; + + /** + * Sanitized contents of get[language] + * + * @var Language|null + * + */ + protected $requestLanguage = null; + + /** + * Is the LanguageSupportPageNames module installed? + * + * @var bool + * + */ + protected $hasLanguagePageNames = false; + + /** + * Contents of $config->pageEdit + * + * @var array + * + */ + protected $configSettings = array( + 'viewNew' => false, + 'confirm' => true, + 'ajaxChildren' => true, + 'ajaxParent' => true, + 'editCrumbs' => false, + ); + /*********************************************************************************************************************** * METHODS @@ -283,28 +341,34 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $this->modules = $this->wire('modules'); $this->input = $this->wire('input'); $this->config = $this->wire('config'); - - if(in_array($this->wire('input')->urlSegment1, array('navJSON', 'bookmarks'))) return; - if(isset($_GET['id']) && $_GET['id'] == 'bookmark') { - $this->wire('session')->redirect('./bookmarks/'); - return; - } + $this->user = $this->wire('user'); + $this->sanitizer = $this->wire('sanitizer'); + $this->session = $this->wire('session'); // predefined messages that maybe used in multiple places $this->set('noticeUnknown', $this->_("Unknown page")); // Init error: Unknown page $this->set('noticeLocked', $this->_("This page is locked for edits")); // Init error: Page is locked $this->set('noticeNoAccess', $this->_("You don't have access to edit")); // Init error: User doesn't have access - + + $settings = $this->config->pageEdit; + if(is_array($settings)) $this->configSettings = array_merge($this->configSettings, $settings); + + if(in_array($this->input->urlSegment1, array('navJSON', 'bookmarks'))) return; + + $getID = $this->input->get('id'); + if($getID === 'bookmark') { + $this->session->redirect('./bookmarks/'); + return; + } + $getID = (int) $getID; $postID = (int) $this->input->post('id'); - $id = $postID; - if(!$id) $id = (int) $this->input->get('id'); + $id = abs($postID ? $postID : $getID); if(!$id) { - $this->wire('session')->redirect('./bookmarks/'); + $this->session->redirect('./bookmarks/'); throw new Wire404Exception($this->noticeUnknown); // Init error: no page provided } - $this->user = $this->wire('user'); $this->page = $this->loadPage($id); $this->id = $this->page->id; $this->pageClass = $this->page->className(); @@ -314,13 +378,13 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod // check if editing specific field or fieldset only if($this->page) { - $field = $this->wire('input')->get('field'); - $fields = $this->wire('input')->get('fields'); + $field = $this->input->get('field'); + $fields = $this->input->get('fields'); if($field && !$fields) $fields = $field; if($fields) { $fields = explode(',', $fields); foreach($fields as $fieldName) { - $fieldName = $this->wire('sanitizer')->fieldName($fieldName); + $fieldName = $this->sanitizer->fieldName($fieldName); if(!$fieldName) throw new WireException("Invalid field name specified"); $field = $this->page->template->fieldgroup->getField($fieldName, true); // get in context if(!$field) throw new WireException("Field '$fieldName' is not applicable to this page"); @@ -342,6 +406,28 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $this->setupBreadcrumbs(); } + // optional context GET var + $context = $this->input->get('context'); + if($context) $this->requestContext = $this->sanitizer->name($context); + + // optional language GET var + $languages = $this->wire('languages'); + if($languages) { + $this->hasLanguagePageNames = $this->modules->isInstalled('LanguageSupportPageNames'); + if($this->hasLanguagePageNames) { + $languageID = (int) $this->input->get('language'); + if($languageID > 0) { + $language = $languages->get($languageID); + if($language->id && $language->id != $this->user->language->id) $this->requestLanguage = $language; + } + } + } + + // optional modal setting + if($this->config->modal) { + $this->requestModal = $this->sanitizer->name($this->config->modal); + } + parent::init(); if(!$this->isPost) { @@ -373,13 +459,13 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $editable = $page->editable(); /** @var User $user */ - $user = $this->wire('user'); + $user = $this->user; /** @var Config $config */ - $config = $this->wire('config'); + $config = $this->config; /** @var Config $config */ - $input = $this->wire('input'); + $input = $this->input; if($page instanceof User) { // special case when page is a User @@ -389,12 +475,12 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod if($userAdmin && $this->wire('process') != 'ProcessUser') { // only allow user pages to be edited from the access section (at least for non-superusers) - $this->wire('session')->redirect($config->urls->admin . 'access/users/edit/?id=' . $page->id); + $this->session->redirect($config->urls->admin . 'access/users/edit/?id=' . $page->id); } else if(!$userAdmin && $page->id === $user->id && $field && $config->ajax) { // user is editing themself and we're responding to an ajax request for a field /** @var PagePermissions $pagePermissions */ - $pagePermissions = $this->wire('modules')->get('PagePermissions'); + $pagePermissions = $this->modules->get('PagePermissions'); $editable = $pagePermissions->userFieldEditable($field); // prevent a later potential redirect to user editor if($editable) $this->setEditor = false; @@ -484,16 +570,17 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod } if(!count($this->fields)) { - $tabs = $this->wire('modules')->get('JqueryWireTabs')->renderTabList($this->getTabs(), array('id' => 'PageEditTabs')); - $this->form->value = $tabs; + /** @var JqueryWireTabs $tabs */ + $tabs = $this->modules->get('JqueryWireTabs'); + $this->form->value = $tabs->renderTabList($this->getTabs(), array('id' => 'PageEditTabs')); } $out .= $this->form->render(); // buttons with dropdowns - if(!$this->wire('config')->modal && !count($this->fields)) { - - $config = $this->wire('config'); + if(!$this->requestModal && !count($this->fields)) { + + $config = $this->config; $file = $config->debug ? 'dropdown.js' : 'dropdown.min.js'; $config->scripts->add($config->urls->InputfieldSubmit . $file); @@ -529,7 +616,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $out .= ""; } - if($viewable && !count($this->fields) && !$this->wire('config')->modal) { + if($viewable && !count($this->fields) && !$this->requestModal) { // this supports code in the buildFormView() method $out .= "