Archived
1
0

* rewrote setup like in SMF's package SDK and also made it use db_query()

+ added CHMOD of sboxDB.php to 644 as some servers set it to 755 which leads to Internal Server Errors
This commit is contained in:
mbirth
2006-08-05 14:54:26 +00:00
parent f47e84672c
commit c7c0cfa475
+71 -105
View File
@@ -1,119 +1,85 @@
<?php
/******************************************************************************
* sbox_setup.php *
*******************************************************************************
* SMF: Simple Machines Forum - SMF Shoutbox MOD *
* Open-Source Project Inspired by Zef Hemel (zef@zefhemel.com) *
* =========================================================================== *
* Software Version: 1.04 *
* Software originally by: ? *
* Ported to SMF by: Deep, most code stolen from Matthew Wolf (Grudge) *
* Support, News, Updates at: http://www.simplemachines.org *
*******************************************************************************
* This program is free software; you may redistribute it and/or modify it *
* under the terms of the provided license as published by Lewis Media. *
* *
* This program is distributed in the hope that it is and will be useful, *
* but WITHOUT ANY WARRANTIES; without even any implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* See the "license.txt" file for details of the Simple Machines license. *
* The latest version can always be found at http://www.simplemachines.org. *
******************************************************************************/
/*******************************************************************************
This is a simplified script to add settings into SMF.
echo'
<html>
<head>
<title>SMF DataBase Editor - SMF-Shoutbox</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<table border="0" cellspacing="1" cellpadding="4" bgcolor="#000000" width="90%">
<tr>
<th bgcolor="#34699E"><font color="#FFFFFF">SMF DB Editor - SMF-Shoutbox MOD - SQL INSTALL</font></th>
</tr>';
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.)
if (!isset($_REQUEST['sa']))
{
echo'
<tr>
<td bgcolor="#FFFFFF" align="center">
<font size="2"><a href="sbox_setup.php?sa=doit&man=yes">Click here to start shoutbox installation</font></a><br /</td></tr></table>
';
}
else
{
echo '</table>';
================================================================================
if ((isset($_REQUEST['man'])) || (!isset($db_name)))
{
require_once (dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/Settings.php');
$dbcon = mysql_connect($db_server, $db_user, $db_passwd);
mysql_select_db($db_name);
}
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.
$error=0;
$shoutChunkSize = 350;
$timeLimitThreshold = 10;
$self = &$_SERVER['PHP_SELF'];
$start_time = time();
// Now time to make the new table
$result = mysql_query("
*******************************************************************************/
// 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(
'sbox_Visible' => '1',
'sbox_GuestAllowed' => '0',
'sbox_SmiliesVisible' => '1',
'sbox_MaxLines' => '50',
'sbox_Height' => '180',
'sbox_RefreshTime' => '20',
'sbox_FontFamily1' => 'Verdana, sans-serif',
'sbox_FontFamily2' => 'Verdana, sans-serif',
'sbox_TextSize1' => 'xx-small',
'sbox_TextColor1' => '#000000',
'sbox_TextSize2' => 'xx-small',
'sbox_TextColor2' => '#476c8e',
'sbox_BackgroundColor' => '#e5e5e8',
);
/******************************************************************************/
// 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 = db_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> Settings insertion failed!<br />';
$result = db_query("
CREATE TABLE `{$db_prefix}sbox_content` (
`id` int(11) unsigned NOT NULL auto_increment,
`time` int(10) unsigned NOT NULL,
`ID_MEMBER` mediumint(8) unsigned NOT NULL,
`content` text NOT NULL,
PRIMARY KEY (`id`)) ENGINE=MyISAM;");
if (!$result)
{
echo "<font color=red>Error creating shoutbox table. SQL Error: ".mysql_error()."</font><BR />";
$error++;
}
else
echo "<font color=green>Shoutbox table created!</font><BR />";
PRIMARY KEY (`id`))");
$toSet = array();
$toSet['sbox_Visible'] = '1';
$toSet['sbox_GuestAllowed'] = '0';
$toSet['sbox_SmiliesVisible'] = '1';
$toSet['sbox_MaxLines'] = '50';
$toSet['sbox_Height'] = '180';
$toSet['sbox_RefreshTime'] = '20';
$toSet['sbox_FontFamily1'] = 'Verdana, sans-serif';
$toSet['sbox_FontFamily2'] = 'Verdana, sans-serif';
$toSet['sbox_TextSize1'] = 'xx-small';
$toSet['sbox_TextColor1'] = '#000000';
$toSet['sbox_TextSize2'] = 'xx-small';
$toSet['sbox_TextColor2'] = '#476c8e';
$toSet['sbox_BackgroundColor'] = '#E5E5E8';
// Uh-oh spaghetti-oh!
if ($result === false)
echo '<b>Error:</b> Table setup failed!<br />';
// Insert settings
foreach ($toSet as $key => $value)
{
$result = mysql_query("INSERT INTO {$db_prefix}settings (`variable`, `value`) VALUES ('$key', '$value');");
if(!$result)
{
echo "<font color=red>Table: ".mysql_error()." Already exists, skipping.</font><br />";
$error++;
}
else
echo "<font color=green>Data inserted correctly!</font><br />";
}
$done = 1;
// Result
if (isset($done))
{
echo "</td></tr></table>";
if($error==0)
echo "<P>Upgrade of SQL was successfull.";
elseif ($error==1)
echo "<P>There was <B>one</B> error when upgrading your SQL.";
elseif ($error>1)
echo "<P>There were <B>$error</B> errors when upgrading your SQL.";
}
if (file_exists($sourcedir . '/sboxDB.php')) {
$result = chmod($sourcedir . '/sboxDB.php', 0644);
if ($result === false)
echo '<b>Error:</b> CHMOD for sboxDB.php failed!<br />';
}
echo '</body></html>';
?>