/** * Save a list of meta data as entered by user in backend to the database * * @param string $metaData an array of meta key/meta value from user. Also include nonsef url * @return boolean true on success */ public function save($dataArray = null) { $this->_db = ShlDbHelper::getDb(); $row = JTable::getInstance($this->_defaultTable, 'Sh404sefTable'); // only save if there is actually some metas data // at least on new records $metas = ''; foreach ($dataArray as $key => $value) { if ($key != 'meta_id' && (substr($key, 0, 4) == 'meta' || substr($key, 0, 3) == 'fb_' || substr($key, 0, 3) == 'og_' || $key == 'canonical')) { $metas .= $value; } } // if there is no meta data entered, and this is an existing record, delete it, or at least do not save if (!empty($metas) && $metas == SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT) { if (!empty($dataArray['meta_id'])) { // there is an existing record, meta data was cleared by user, we can delete the record altogether try { ShlDbHelper::delete('#__sh404sef_metas', array('id' => $dataArray['meta_id'])); return true; } catch (Exception $e) { $this->setError($e->getMessage()); return false; } } // in any case, don't save anything return true; } if (empty($metas) && empty($dataArray['meta_id'])) { // avoid creating a new (and empty) record when savnig a record from the "metas" page // where we're editing several records at a time // This would pass the test just above, because we do not have any values for fb_*, og_*, etc // fields as we're only editing title and description return true; } $status = true; // load pre-existing values if (!empty($dataArray['meta_id'])) { $status = $row->load($dataArray['meta_id']); } // attach incoming data to table object $status = $status && $row->bind($dataArray); // add language code if missing, except on home page if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE && !preg_match('/(&|\\?)lang=[a-zA-Z]{2,3}/iuU', $row->newurl)) { // no lang string, let's add default $shTemp = explode('-', shGetDefaultLang()); $shLangTemp = $shTemp[0] ? $shTemp[0] : 'en'; $row->newurl .= '&lang=' . $shLangTemp; } // sort url params, except on home page if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE) { $row->newurl = shSortUrl($row->newurl); } // pre-save checks $status = $status && $row->check(); // save the changes $status = $status && $row->store(); // store error message if (!$status) { $error = $row->getError(); $this->setError($error); } // return true if no error $errors = $this->getError(); return empty($errors); }
/** * Save params, then delete plugin, for all plugins * in a given group * * @param $group the group to be deleted * @return none */ private function _shSaveDeletePluginGroup($group) { $unsafe = array('authentication', 'content', 'editors', 'editors-xtd', 'search', 'system', 'xmlrpc'); if (in_array($group, $unsafe)) { // safety net : we don't want to delete the whole system or content folder return false; } // read plugin param from db try { $pluginList = ShlDbHelper::selectAssocList('#__extensions', array('*'), array('type' => 'plugin', 'folder' => $group)); if (empty($pluginList)) { return true; } // for each plugin foreach ($pluginList as $plugin) { // remove plugin db id unset($plugin['id']); // write everything on disk $this->_shWriteExtensionConfig($plugin['folder'] . '.' . $plugin['element'], array('shConfig' => $plugin)); // now remove plugin details from db ShlDbHelper::delete('#__extensions', array('type' => 'plugin', 'element' => $plugin['element'], 'folder' => $plugin['folder'])); } } catch (Exception $e) { echo $e->getMessage() . '<br />'; } // now delete the files for the whole group if (JFolder::exists(JPATH_ROOT . '/plugins/' . $group)) { JFolder::delete(JPATH_ROOT . '/plugins/' . $group); } }