/** * Save Module * * @return void */ public function saveTask() { // get request vars $module = Request::getVar('module', array(), 'post', 'none', JREQUEST_ALLOWRAW); $menu = Request::getVar('menu', array(), 'post'); // set gid number $module['gidNumber'] = $this->group->get('gidNumber'); // clean title & position $module['title'] = preg_replace("/[^-_ a-zA-Z0-9]+/", "", $module['title']); $module['position'] = preg_replace("/[^-_a-zA-Z0-9]+/", "", $module['position']); // get the category object $this->module = new Module($module['id']); // ordering change $ordering = null; if (isset($module['ordering']) && $module['ordering'] != $this->module->get('ordering')) { $ordering = $module['ordering']; unset($module['ordering']); } // if this is new module or were changing position, // get next order possible for position if (!isset($module['id']) || $module['id'] == '' || $module['position'] != $this->module->get('position')) { $ordering = null; $module['ordering'] = $this->module->getNextOrder($module['position']); } // did the module content change? $contentChanged = false; $oldContent = trim($this->module->get('content')); $newContent = isset($module['content']) ? trim($module['content']) : ''; if (!is_object($this->group->params)) { $this->group->params = new \Hubzero\Config\Registry($this->group->params); } if (!$this->group->params->get('page_trusted', 0)) { $newContent = Module::purify($newContent, $this->group->isSuperGroup()); } // is the new and old content different? if ($oldContent != $newContent) { $contentChanged = true; } // bind request vars to module model if (!$this->module->bind($module)) { $this->setNotification($this->module->getError(), 'error'); return $this->editTask(); } // module is approved unless contains php or scripts (checked below) $this->module->set('approved', 1); // if we have php or script tags we must get module approved by admin if (strpos($this->module->get('content'), '<?') !== false || strpos($this->module->get('content'), '<?php') !== false || strpos($this->module->get('content'), '<script') !== false) { // only change approve status if content changed if ($contentChanged) { $this->module->set('approved', 0); $this->module->set('approved_on', NULL); $this->module->set('approved_by', NULL); $this->module->set('checked_errors', 0); $this->module->set('scanned', 0); } } // set created if new module if (!$this->module->get('id')) { $this->module->set('created', Date::toSql()); $this->module->set('created_by', User::get('id')); } // set modified $this->module->set('modified', Date::toSql()); $this->module->set('modified_by', User::get('id')); // check module again (because were not on store() method) if (!$this->module->check()) { $this->setNotification($this->module->getError(), 'error'); $this->editTask(); return; } // save version settings // dont run check on module store, skips onContentBeforeSave in Html format hadler if (!$this->module->store(false, $this->group->isSuperGroup())) { $this->setNotification($this->module->getError(), 'error'); $this->editTask(); return; } // create module menu if (!$this->module->buildMenu($menu)) { $this->setNotification($this->module->getError(), 'error'); $this->editTask(); return; } // do we need to reorder if ($ordering !== null) { $move = (int) $ordering - (int) $this->module->get('ordering'); $this->module->move($move, $this->module->get('position')); } // send to approvers if unapproved if ($this->module->get('approved', 0) == 0) { Helpers\Pages::sendApproveNotification('module', $this->module); } // Push success message and redirect $this->setNotification(Lang::txt('COM_GROUPS_PAGES_MODULE_SAVED'), 'passed'); App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages#modules')); if ($return = Request::getVar('return', '', 'post')) { App::redirect(base64_decode($return)); } }