/** * 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($metaDatas) { $this->_db =& JFactory::getDBO(); $row =& JTable::getInstance($this->_defaultTable, 'Sh404sefTable'); // only save if there is actually some metas data // at least on new records $metas = ''; foreach ($metaDatas 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, don't 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 . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT) { if (!empty($metaDatas['id'])) { // there is an existing record, meta data was cleared by user, we can delete the record altogether try { Sh404sefHelperDb::delete('#__sh404sef_metas', array('id' => $metaDatas['id'])); return true; } catch (Sh404sefExceptionDefault $e) { $this->setError($e->getMessage()); return false; } } // in any case, don't save anything return true; } $status = true; // load pre-existing values if (!empty($metaDatas['id'])) { $status = $row->load($metaDatas['id']); } // attach incoming data to table object $status = $status && $row->bind($metaDatas); // add language code if missing, except on home page if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE && !preg_match('/(&|\\?)lang=[a-zA-Z]{2,3}/iU', $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 list of plugins from db $db =& JFactory::getDBO(); // read plugin param from db try { $pluginList = Sh404sefHelperDb::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 Sh404sefHelperDb::delete('#__extensions', array('type' => 'plugin', 'element' => $plugin['element'], 'folder' => $plugin['folder'])); } } catch (Sh404sefExceptionDefault $e) { echo $e->getMessage() . '<br />'; } // now delete the files for the whole group if (JFolder::exists(JPATH_ROOT . DS . 'plugins' . DS . $group)) { JFolder::delete(JPATH_ROOT . DS . 'plugins' . DS . $group); } }