-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathadd_settings.php
68 lines (55 loc) · 2.09 KB
/
add_settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*******************************************************************************
This is a simplified script to add settings into SMF.
ATTENTION: If you are trying to INSTALL this package, please access
it directly, with a URL like the following:
http://www.yourdomain.tld/forum/add_settings.php (or similar.)
================================================================================
This script can be used to add new settings into the database for use
with SMF's $modSettings array. It is meant to be run either from the
package manager or directly by URL.
*******************************************************************************/
// Set the below to true to overwrite already existing settings with the defaults. (not recommended.)
$overwrite_old_settings = false;
// List settings here in the format: setting_key => default_value. Escape any "s. (" => \")
$mod_settings = array(
'tea_enable' => '0',
'tea_userid' => '',
'tea_api' => '',
);
/******************************************************************************/
function query($sql)
{
$return = mysql_query($sql);
if (!$return)
{
//echo $sql;
echo mysql_error();
return false;
}
else
{
return true;
}
}
// If SSI.php is in the same place as this file, and SMF isn't defined, this is being run standalone.
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
// Hmm... no SSI.php and no SMF?
elseif (!defined('SMF'))
die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');
// Turn the array defined above into a string of MySQL data.
$string = '';
foreach ($mod_settings as $k => $v)
$string .= '
(\'' . $k . '\', \'' . $v . '\'),';
// Sorted out the array defined above - now insert the data!
if ($string != '')
$result = query("
" . ($overwrite_old_settings ? 'REPLACE' : 'INSERT IGNORE') . " INTO {$db_prefix}settings
(variable, value)
VALUES" . substr($string, 0, -1));
// Uh-oh spaghetti-oh!
if ($result === false)
echo '<b>Error:</b> Database modifications failed!';
?>