public function saveValue() { $request = \Ip\ServiceLocator::request(); $request->mustBePost(); $post = $request->getPost(); if (empty($post['fieldName'])) { throw new \Exception('Missing required parameter'); } $fieldName = $post['fieldName']; if (!isset($post['value'])) { throw new \Exception('Missing required parameter'); } $value = $post['value']; if (!in_array($fieldName, array('websiteTitle', 'websiteEmail')) && !(in_array($fieldName, array('automaticCron', 'cronPassword', 'removeOldRevisions', 'removeOldRevisionsDays', 'removeOldEmails', 'removeOldEmailsDays', 'allowAnonymousUploads', 'trailingSlash')) && ipAdminPermission('Config advanced'))) { throw new \Exception('Unknown config value'); } $emailValidator = new \Ip\Form\Validator\Email(); $error = $emailValidator->getError(array('value' => $value), 'value', \Ip\Form::ENVIRONMENT_ADMIN); if ($fieldName === 'websiteEmail' && $error !== false) { return $this->returnError($error); } if (in_array($fieldName, array('websiteTitle', 'websiteEmail'))) { if (!isset($post['languageId'])) { throw new \Exception('Missing required parameter'); } $languageId = $post['languageId']; $language = ipContent()->getLanguage($languageId); ipSetOptionLang('Config.' . $fieldName, $value, $language->getCode()); } else { ipSetOption('Config.' . $fieldName, $value); } return new \Ip\Response\Json(array(1)); }
public static function setupTestDatabase($database, $tablePrefix) { Model::setInstallationDir(ipFile('')); Model::createDatabaseStructure($database, $tablePrefix); Model::importData($tablePrefix); OptionHelper::import(__DIR__ . '/options.json'); Model::insertAdmin('test', '*****@*****.**', 'test'); ipSetOptionLang('Config.websiteTitle', 'TestSite', 'en'); ipSetOptionLang('Config.websiteEmail', '*****@*****.**', 'en'); }
/** * @param array $data * @param $info ['pluginName'] */ public static function ipPluginSaveOptions_20($data, $info) { $plugin = Helper::getPluginData($info['pluginName']); if (empty($plugin['options'])) { return $data; } $form = new \Ip\Form(); /* @var $form \Ip\Form */ $form = Helper::pluginPropertiesFormFields($info['pluginName'], $form); foreach ($plugin['options'] as $option) { if (empty($option['type'])) { $option['type'] = 'text'; } if (empty($option['name'])) { continue; } $field = $form->getField($option['name']); if (!$field) { continue; } $optionName = $info['pluginName'] . '.' . $option['name']; if ($field instanceof \Ip\Form\FieldLang) { //multilingual field $value = ''; if (!empty($data[$option['name']])) { $value = $data[$option['name']]; } if (!is_array($value)) { $value = array(); } foreach ($value as $languageKey => $langValue) { if (!is_string($languageKey)) { continue; } if (!is_string($langValue)) { continue; } ipSetOptionLang($optionName, $langValue, $languageKey); } } else { //standard field if (method_exists($field, 'isChecked')) { //checkbox uniqueness $value = $field->isChecked($data, $option['name']); } else { $value = $field->getValueAsString($data, $option['name']); } ipSetOption($optionName, $value); } unset($data[$option['name']]); // this option is processed } return $data; }
public static function ipLanguageUpdated($data) { $oldCode = $data['old']['code']; $newCode = $data['new']['code']; if ($oldCode != $newCode) { $title = ipGetOptionLang('Config.websiteTitle', $oldCode); $email = ipGetOptionLang('Config.websiteEmail', $oldCode); ipRemoveOptionLang('Config.websiteTitle', $oldCode); ipRemoveOptionLang('Config.websiteEmail', $oldCode); ipSetOptionLang('Config.websiteTitle', $title, $newCode); ipSetOptionLang('Config.websiteEmail', $email, $newCode); } }
public function createDatabase() { if (!Helper::isInstallAvailable()) { return sprintf(__('Please remove content from %s file.', 'Install', false), 'config.php'); } $db = ipRequest()->getPost('db'); if (!isset($_SESSION['db_errors'])) { $_SESSION['db_errors'] = array(); } foreach (array('hostname', 'username', 'database') as $key) { if (empty($db[$key])) { $_SESSION['db_errors'][] = 'Required fields'; return \Ip\Response\JsonRpc::error(__('Please fill in required fields.', 'Install', false)); } } if (empty($db['tablePrefix'])) { $db['tablePrefix'] = ''; } if (strlen($db['tablePrefix']) > 7) { $_SESSION['db_errors'][] = 'Prefix too long'; return \Ip\Response\JsonRpc::error(__("Prefix can't be longer than 7 symbols.", 'Install', false)); } if ($db['tablePrefix'] != '' && !preg_match('/^([A-Za-z_][A-Za-z0-9_]*)$/', $db['tablePrefix'])) { $_SESSION['db_errors'][] = 'Prefix is bad'; return \Ip\Response\JsonRpc::error(__("Prefix can't contain any special characters and should start with a letter.", 'Install', false)); } $dbConfig = array('hostname' => $db['hostname'], 'username' => $db['username'], 'password' => $db['password'], 'tablePrefix' => $db['tablePrefix'], 'database' => '', 'charset' => 'utf8'); ipConfig()->set('db', $dbConfig); try { ipDb()->getConnection(); } catch (\Exception $e) { $_SESSION['db_errors'][] = 'Cannot connect'; return \Ip\Response\JsonRpc::error(__("Can't connect to database.", 'Install'), false); } try { Model::createAndUseDatabase($db['database']); } catch (\Ip\Exception $e) { $_SESSION['db_errors'][] = 'DB cannot be created'; return \Ip\Response\JsonRpc::error(__('Specified database does not exists and cannot be created.', 'Install', false)); } if (Helper::testDBTables($db['tablePrefix']) && empty($db['replaceTables'])) { $_SESSION['db_errors'][] = 'Replace tables'; return \Ip\Response\JsonRpc::error(__('Do you like to replace existing tables in the database?', 'Install', false), 'table_exists'); } $errors = Model::createDatabaseStructure($db['database'], $db['tablePrefix']); if (!$errors) { $errors = Model::importData($dbConfig['tablePrefix']); } if ($errors) { $_SESSION['db_errors'][] = 'Failed install'; return \Ip\Response\JsonRpc::error(__('There were errors while executing install queries. ' . serialize($errors), 'Install', false)); } $dbConfig['database'] = $db['database']; $_SESSION['db'] = $dbConfig; $configToFile = array(); $configToFile['sessionName'] = 'ses' . rand(); $configToFile['db'] = $_SESSION['db']; $configToFile['timezone'] = $_SESSION['config']['timezone']; if (Helper::checkModRewrite() != 'success') { $configToFile['rewritesDisabled'] = true; } $admin = ipRequest()->getPost('admin'); if ($admin) { $adminUsername = $admin['username']; $adminEmail = $admin['email']; $adminPassword = $admin['password']; } $cachedBaseUrl = substr(rtrim(ipConfig()->baseUrl(), "/"), 0, -strlen('install')); try { ipConfig()->set('db', $dbConfig); // if admin data is posted then user will be created if ($admin) { Model::insertAdmin($adminUsername, $adminEmail, $adminPassword); } ipSetOptionLang('Config.websiteTitle', $_SESSION['config']['websiteName'], 'en'); ipSetOptionLang('Config.websiteEmail', $_SESSION['config']['websiteEmail'], 'en'); Model::generateCronPassword(); ipStorage()->set('Ip', 'cachedBaseUrl', $cachedBaseUrl); ipStorage()->set('Ip', 'websiteId', $_SESSION['websiteId']); ipStorage()->set('Ip', 'getImpressPagesSupport', $_SESSION['config']['support']); } catch (\Exception $e) { $_SESSION['db_errors'][] = $e->getTraceAsString(); return \Ip\Response\JsonRpc::error($e->getTraceAsString()); } try { Model::writeConfigFile($configToFile, ipFile('config.php')); } catch (\Exception $e) { $_SESSION['db_errors'][] = 'Cannot write config file'; return \Ip\Response\JsonRpc::error(__('Can\'t write configuration "/config.php"', 'Install', false)); } // Send usage statistics $usageStatistics = Helper::setUsageStatistics('Install.database', $_SESSION['db_errors']); \Ip\Internal\System\Model::sendUsageStatistics($usageStatistics); $redirect = $cachedBaseUrl . 'admin'; return \Ip\Response\JsonRpc::result(array('redirect' => $redirect)); }