Skip to content

Commit e20f18f

Browse files
author
Marius Cramer
committed
Added config storage method
- Use it like $app->conf('yourpluginname', 'config-key', 'value') - omit the value to read the config value, provide it to set the value
1 parent 3576793 commit e20f18f

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE `sys_config` DROP `config_id`,
2+
ADD PRIMARY KEY (`group`, `name`);

install/sql/ispconfig3.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,10 +1486,10 @@ CREATE TABLE `support_message` (
14861486
--
14871487

14881488
CREATE TABLE `sys_config` (
1489-
`config_id` int(11) unsigned NOT NULL,
14901489
`group` varchar(64) NOT NULL,
14911490
`name` varchar(64) NOT NULL,
1492-
`value` varchar(255) NOT NULL
1491+
`value` varchar(255) NOT NULL,
1492+
PRIMARY KEY (`group`, `name`)
14931493
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
14941494

14951495

@@ -2280,7 +2280,7 @@ INSERT INTO `sys_user` (`userid`, `sys_userid`, `sys_groupid`, `sys_perm_user`,
22802280
-- Dumping data for table `sys_config`
22812281
--
22822282

2283-
INSERT INTO sys_config VALUES ('1','db','db_version','3.0.5.3');
2284-
INSERT INTO sys_config VALUES ('2','interface','session_timeout','0');
2283+
INSERT INTO sys_config VALUES ('db','db_version','3.0.5.3');
2284+
INSERT INTO sys_config VALUES ('interface','session_timeout','0');
22852285

22862286
SET FOREIGN_KEY_CHECKS = 1;

interface/lib/app.inc.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ public function __construct() {
6868
if($this->_conf['start_session'] == true) {
6969

7070
$this->uses('session');
71-
$tmp = $this->db->queryOneRecord("SELECT `value` FROM sys_config WHERE `config_id` = 2 AND `group` = 'interface' AND `name` = 'session_timeout'");
72-
if($tmp && $tmp['value'] > 0) {
71+
$sess_timeout = $this->conf('interface', 'session_timeout');
72+
if($sess_timeout) {
7373
/* check if user wants to stay logged in */
7474
if(isset($_POST['s_mod']) && isset($_POST['s_pg']) && $_POST['s_mod'] == 'login' && $_POST['s_pg'] == 'index' && isset($_POST['stay']) && $_POST['stay'] == '1') {
7575
/* check if staying logged in is allowed */
7676
$this->uses('ini_parser');
7777
$tmp = $this->db->queryOneRecord('SELECT config FROM sys_ini WHERE sysini_id = 1');
7878
$tmp = $this->ini_parser->parse_ini_string(stripslashes($tmp['config']));
7979
if(!isset($tmp['misc']['session_allow_endless']) || $tmp['misc']['session_allow_endless'] != 'y') {
80-
$this->session->set_timeout($tmp['value']);
81-
session_set_cookie_params(($tmp['value'] * 60) + 300); // make the cookie live 5 minutes longer
80+
$this->session->set_timeout($sess_timeout);
81+
session_set_cookie_params(($sess_timeout * 60) + 300); // make the cookie live 5 minutes longer
8282
} else {
8383
// we are doing login here, so we need to set the session data
8484
$this->session->set_permanent(true);
8585
$this->session->set_timeout(365 * 24 * 3600); // one year
8686
session_set_cookie_params(365 * 24 * 3600); // make the cookie live 5 minutes longer
8787
}
8888
} else {
89-
$this->session->set_timeout($tmp['value']);
90-
session_set_cookie_params(($tmp['value'] * 60) + 300); // make the cookie live 5 minutes longer
89+
$this->session->set_timeout($sess_timeout);
90+
session_set_cookie_params(($sess_timeout * 60) + 300); // make the cookie live 5 minutes longer
9191
}
9292
} else {
9393
session_set_cookie_params(0); // until browser is closed
@@ -148,6 +148,22 @@ public function load($files) {
148148
}
149149
}
150150
}
151+
152+
public function conf($plugin, $key, $value = null) {
153+
if(is_null($value)) {
154+
$tmpconf = $this->db->queryOneRecord("SELECT `value` FROM `sys_config` WHERE `group` = '" . $this->db->quote($plugin) . "' AND `name` = '" . $this->db->quote($key) . "'");
155+
if($tmpconf) return $tmpconf['value'];
156+
else return null;
157+
} else {
158+
if($value === false) {
159+
$this->db->query("DELETE FROM `sys_config` WHERE `group` = '" . $this->db->quote($plugin) . "' AND `name` = '" . $this->db->quote($key) . "'");
160+
return null;
161+
} else {
162+
$this->db->query("REPLACE INTO `sys_config` (`group`, `name`, `value`) VALUES ('" . $this->db->quote($plugin) . "', '" . $this->db->quote($key) . "', '" . $this->db->quote($value) . "')");
163+
return $value;
164+
}
165+
}
166+
}
151167

152168
/** Priority values are: 0 = DEBUG, 1 = WARNING, 2 = ERROR */
153169

interface/web/admin/system_config_edit.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ function onUpdateSave($sql) {
150150
} elseif($section == 'mail') {
151151
if($new_config['smtp_pass'] == '') $new_config['smtp_pass'] = $server_config_array['mail']['smtp_pass'];
152152
} elseif($section == 'misc' && $new_config['session_timeout'] != $server_config_array['misc']['session_timeout']) {
153-
$app->db->query("DELETE FROM sys_config WHERE `config_id` = 2 AND `group` = 'interface' AND `name` = 'session_timeout'");
154-
$app->db->query("INSERT INTO sys_config (`config_id`, `group`, `name`, `value`) VALUES (2, 'interface', 'session_timeout', '" . intval($new_config['session_timeout']) . "')");
153+
$app->conf('interface', 'session_timeout', intval($new_config['session_timeout']));
155154
}
156155
$server_config_array[$section] = $new_config;
157156
$server_config_str = $app->ini_parser->get_ini_string($server_config_array);

0 commit comments

Comments
 (0)