Location: PHPKode > scripts > Orca Ringmaker > orca-ringmaker/orm3/config.php
<?php /* ***** Orca Ringmaker - Config File ************************* */

/* *********************************************************************
* Orca Ringmaker v3.0
*  A comprehensive web ring creation and managment script
* Copyright (C) 2007 GreyWyvern
*
* This program may be distributed under the terms of the GPL
*   - http://www.gnu.org/licenses/gpl.txt
*
* See the readme.txt file for installation instructions.
********************************************************************* */


// error_reporting(E_ALL);

$_SDATA['now'] = array_sum(explode(" ", microtime()));
$_SDATA['error'] = array();
$_SDATA['success'] = array();



/* ****************************************************************** */
/* ***** Magic Quotes Fix ******************************************* */
if (get_magic_quotes_gpc()) {
	$fsmq = create_function('&$mData, $fnSelf', 'if (is_array($mData)) foreach ($mData as $mKey=>$mValue) $fnSelf($mData[$mKey], $fnSelf); else $mData = stripslashes($mData);');
	$fsmq($_POST, $fsmq);
	$fsmq($_GET, $fsmq);
	$fsmq($_REQUEST, $fsmq);
	$fsmq($_COOKIE, $fsmq);
}
set_magic_quotes_runtime(0);



/* ****************************************************************** */
/* ***** Import Language File *************************************** */
if ($langfile = @fopen("{$_SERVER['DOCUMENT_ROOT']}/{$_SDATA['directory']}/lang.txt", "r")) {
	while (!feof($langfile)) {
		$line = fgets($langfile);
		if (strpos($line, "=") && $line{0} != "#") {
			$line = explode("=", $line, 2);
			if (trim($line[1]) == "{") {
				$_LANG[$line[0]] = "";
				while (trim($multiline = fgets($langfile)) != "}" && !feof($langfile))
					$_LANG[$line[0]] .= trim($multiline)."\n";
				$_LANG[$line[0]] = trim($_LANG[$line[0]]);
			} else $_LANG[$line[0]] = rtrim($line[1]);
		}
	}
	fclose($langfile);
} else die("Unable to load language file");
$_LANG['status'] = array(
	'inactive'    => $_LANG['000'],
	'suspended'   => $_LANG['001'],
	'hibernating' => $_LANG['002'],
	'active'      => $_LANG['003']
);
$_LANG['stats.type'] = array(
	'none'   => $_LANG['004'],
	'hourly' => $_LANG['005'],
	'daily'  => $_LANG['006']
);
$_LANG['level'] = array(
	$_LANG['007'],
	$_LANG['008'],
	$_LANG['009'],
	$_LANG['00b']
);
$_LANG['mail.method'] = array(
	'mail'     => "mail()",
	'sendmail' => "Sendmail",
	'smtp'     => "SMTP"
);
$_LANG['days'] = array(
	$_LANG['00c'],
	$_LANG['00d'],
	$_LANG['00e'],
	$_LANG['00f'],
	$_LANG['00g'],
	$_LANG['00h'],
	$_LANG['00i']
);
$_LANG['range'] = array(
	3  => $_LANG['00j'],
	14 => $_LANG['00k'],
	56 => $_LANG['00l']
);



/* ****************************************************************** */
/* ***** Prepare Ring Data ****************************************** */
$_SERVER['PHP_SELF'] = preg_replace("/\?.*$/i", "", $_SERVER['REQUEST_URI']);
if (!isset($_SERVER['HTTP_USER_AGENT'])) $_SERVER['HTTP_USER_AGENT'] = "";

$_SDATA['version'] = "3.0";
$_SDATA['useragent'] = "Orca Ringmaker v{$_SDATA['version']}";
$_SDATA['allowfopen'] = (ini_get("allow_url_fopen") || ini_set("allow_url_fopen", "1") !== false) ? true : false;
$_SDATA['huburi'] = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$_SDATA['navbar']['default'] = <<<ORCA
<table border="0" cellpadding="2" cellspacing="0" style="border:2px outset #a0b0c0;margin:0px auto;font:normal 12px Arial,sans-serif;background:#d0d7df none;color:#000000;">
  <thead>
    <tr>
      <th style="text-align:left;font-size:15px;background:#c0c7cf none;">__ringname__</th>
    </tr>
  </thead>
 <tbody>
    <tr>
      <td style="text-align:center;background-color:#d0d7df;">
        <a href="__hubURI__?Go&amp;Prev&amp;__id__" style="color:#000080;" target="_top">{$_LANG['00m']}</a> |
        <a href="__hubURI__" style="color:#000080;" target="_top">{$_LANG['00n']}</a> |
        <a href="__hubURI__?Join" style="color:#000080;" target="_top">{$_LANG['00o']}</a> |
        <a href="__hubURI__?Go&amp;Rand&amp;__id__" style="color:#000080;" target="_top">{$_LANG['00p']}</a> |
        <a href="__hubURI__?Go&amp;Next&amp;__id__" style="color:#000080;" target="_top">{$_LANG['00q']}</a>
      </td>
    </tr>
  </tbody>
</table>
ORCA;
$_SDATA['navbar']['minimal'] = <<<ORCA
<div style="display:inline;font-size:11px;">
  <a href="__hubURI__?Go&amp;Prev&amp;__id__" title="{$_LANG['00m']}">&lt;&lt;</a> |
  <a href="__hubURI__" title="__ringname__">{$_LANG['00r']}</a> |
  <a href="__hubURI__?Join">Join</a> |
  <a href="__hubURI__?Go&amp;Rand&amp;__id__" title="{$_LANG['00p']}">?</a> |
  <a href="__hubURI__?Go&amp;Next&amp;__id__" title="{$_LANG['00q']}">&gt;&gt;</a>
</div>
ORCA;
$_SDATA['navbar']['script'] = sprintf($_LANG['00s'], '<a href="__hubURI__">__ringname__</a>');
$_SDATA['themes'] = array("grey");
if ($dh = opendir("{$_SERVER['DOCUMENT_ROOT']}/{$_SDATA['directory']}/themes")) {
	while (($file = readdir($dh)) !== false)
		if ($file != "." && $file != ".." && is_dir("{$_SERVER['DOCUMENT_ROOT']}/{$_SDATA['directory']}/themes/".$file)) $_SDATA['themes'][] = $file;
	closedir($dh);
}
$_SDATA['themes'] = array_unique($_SDATA['themes']); sort($_SDATA['themes']);
$_SDATA['captcha'] = file_exists("{$_SERVER['DOCUMENT_ROOT']}/{$_SDATA['directory']}/captcha.php");
$_SDATA['browsers'] = file_exists("{$_SERVER['DOCUMENT_ROOT']}/{$_SDATA['directory']}/browsers.txt");



/* ****************************************************************** */
/* ***** MySQL Setup ************************************************ */
$_DDATA['online'] = false;

if ($_DDATA['link'] = @mysql_connect($_DDATA['hostname'], $_DDATA['username'], $_DDATA['password'])) {
	if (mysql_select_db($_DDATA['database'], $_DDATA['link'])) {
		$_DDATA['online'] = true;
	} else $_SDATA['error'][] = mysql_errno().": ".mysql_error();
} else $_SDATA['error'][] = mysql_errno().": ".mysql_error();

if ($_DDATA['online']) {
	$_DDATA['tableuser'] = $_DDATA['tablename']."_user";
	$_DDATA['tablesite'] = $_DDATA['tablename']."_site";
	$_DDATA['tablestat'] = $_DDATA['tablename']."_stat";
	$_DDATA['tableauth'] = $_DDATA['tablename']."_auth";
	$_DDATA['tablemail'] = $_DDATA['tablename']."_mail";

	$_DDATA['tables'] = array();
	$show = mysql_query("SHOW TABLES FROM `{$_DDATA['database']}`;", $_DDATA['link']);
	while ($row = mysql_fetch_array($show)) $_DDATA['tables'][] = $row[0];

	if (!in_array($_DDATA['tableuser'], $_DDATA['tables'])) {
		$create = mysql_query("CREATE TABLE `{$_DDATA['tableuser']}` (
			`id` smallint(6) NOT NULL auto_increment,
			`username` tinytext NOT NULL,
			`password` tinytext NOT NULL,
			`date` int(11) NOT NULL default '-1',
			`description` text NOT NULL,
			`email` tinytext NOT NULL,
			`email.new` tinytext NOT NULL,
			`email.date` int(11) NOT NULL default '-1',
			`email.key` tinytext NOT NULL,
			`level` tinyint(4) NOT NULL default '0',
			`filters` text NOT NULL,
			PRIMARY KEY (`id`)
		) TYPE=MyISAM;", $_DDATA['link']);
		$insert = mysql_query("INSERT INTO `{$_DDATA['tableuser']}` SET
			`username`='Administrator',
			`password`='password',
			`date`=UNIX_TIMESTAMP(),
			`email`='hide@address.com',
			`level`='3'
		;", $_DDATA['link']);
	}

	if (!in_array($_DDATA['tablesite'], $_DDATA['tables'])) {
		$create = mysql_query("CREATE TABLE `{$_DDATA['tablesite']}` (
			`id` smallint(6) NOT NULL auto_increment,
			`order` smallint(6) NOT NULL default 0,
			`owner` int(11) NOT NULL default '0',
			`uri` tinytext NOT NULL,
			`title` tinytext NOT NULL,
			`description` text NOT NULL,
			`date` int(11) NOT NULL default '-1',
			`status` enum('inactive','suspended','hibernating','active') NOT NULL default 'inactive',
			`lookahead` enum('yes','no') NOT NULL default 'yes',
			`navbar.status` enum('unchecked','error','not found','found') NOT NULL default 'unchecked',
			`navbar.date` int(11) NOT NULL default '-1',
			PRIMARY KEY (`id`)
		) TYPE=MyISAM;", $_DDATA['link']);
	}

	if (!in_array($_DDATA['tablename'], $_DDATA['tables'])) {
		$create = mysql_query("CREATE TABLE `{$_DDATA['tablename']}` (
			`name` tinytext NOT NULL,
			`date` int(11) NOT NULL default '-1',
			`owner` smallint(6) NOT NULL default '0',
			`db.version` tinyint(4) NOT NULL default '0',
			`mail.method` enum('mail','sendmail','smtp') NOT NULL default 'mail',
			`mail.smtp.server` tinytext NOT NULL,
			`mail.smtp.username` tinytext NOT NULL,
			`mail.smtp.password` tinytext NOT NULL,
			`display.charset` tinytext NOT NULL,
			`display.sitelimit` tinyint(4) NOT NULL default '10',
			`display.announcement` text NOT NULL,
			`display.theme` tinytext NOT NULL,
			`navbar.type` enum('html','script') NOT NULL default 'html',
			`navbar.html` text NOT NULL,
			`navbar.script` text NOT NULL,
			`stats.type` enum('none','hourly','daily') NOT NULL default 'hourly',
			`stats.date` int(11) NOT NULL default '-1',
			`stats.key` tinytext NOT NULL,
			`stats.cache` longtext NOT NULL,
			`stats.lock` enum('yes','no') NOT NULL default 'no',
			`stats.timezone.name` tinytext NOT NULL,
			`stats.timezone.offset` tinyint(4) NOT NULL,
			`stats.toplimit` tinyint(4) NOT NULL default '20',
			`stats.colbots` enum('yes','no') NOT NULL default 'no'
		) TYPE=MyISAM MAX_ROWS=1;", $_DDATA['link']);
		$insert = mysql_query("INSERT INTO `{$_DDATA['tablename']}` SET
			`name`='My Ring',
			`date`=UNIX_TIMESTAMP(),
			`display.charset`='ISO-8859-1',
			`display.announcement`='".addslashes($_LANG['0hd'])."',
			`display.theme`='grey',
			`navbar.html`='',
			`navbar.script`='',
			`stats.date`=UNIX_TIMESTAMP(),
			`stats.timezone.name`='GMT',
			`stats.timezone.offset`='0'
		;", $_DDATA['link']);
	}

	$_VDATA = mysql_fetch_assoc(mysql_query("SELECT * FROM `{$_DDATA['tablename']}`;", $_DDATA['link']));

	if (!$_VDATA['navbar.html']) ORM_setData('navbar.html', $_SDATA['navbar']['default']);
	if (!$_VDATA['navbar.script']) ORM_setData('navbar.script', $_SDATA['navbar']['script']);

	if (!in_array($_DDATA['tablestat'], $_DDATA['tables'])) {
		$create = mysql_query("CREATE TABLE `{$_DDATA['tablestat']}` (
			`from` smallint(6) NOT NULL default '0',
			`to` smallint(6) NOT NULL default '0',
			`success` enum('yes','no') NOT NULL default 'no',
			`date` int(11) NOT NULL default '-1',
			`type` enum('next','prev','rand','site') NOT NULL default 'site',
			`ua` tinytext NOT NULL
		) TYPE=MyISAM;", $_DDATA['link']);
	}

	if (!in_array($_DDATA['tableauth'], $_DDATA['tables']) && $_SDATA['captcha']) {
		$create = mysql_query("CREATE TABLE `{$_DDATA['tableauth']}` (
			`captcha` tinytext NOT NULL,
			`code` tinytext NOT NULL,
			`date` int(11) NOT NULL default '-1'
		) TYPE=MyISAM;", $_DDATA['link']);
	} else if (in_array($_DDATA['tableauth'], $_DDATA['tables']) && !$_SDATA['captcha'])
		$drop = mysql_query("DROP TABLE `{$_DDATA['tableauth']}`;", $_DDATA['link']);

	if (!in_array($_DDATA['tablemail'], $_DDATA['tables'])) {
		$create = mysql_query("CREATE TABLE `{$_DDATA['tablemail']}` (
			`id` smallint(6) NOT NULL auto_increment,
			`sentby` smallint(6) NOT NULL default '0',
			`date` int(11) NOT NULL default '-1',
			`to` tinytext NOT NULL,
			`adds` text NOT NULL,
			`subject` tinytext NOT NULL,
			`message` text NOT NULL,
			PRIMARY KEY (`id`)
		) TYPE=MyISAM;", $_DDATA['link']);
	}


	/* ***** Wash Tables of Old Data ********************************** */
	$select = mysql_query("SELECT `id` FROM `{$_DDATA['tableuser']}` WHERE `level`='0' AND `email.date`<(UNIX_TIMESTAMP()-3600);", $_DDATA['link']);
	while ($row = mysql_fetch_assoc($select)) {
		$delete = mysql_query("DELETE FROM `{$_DDATA['tableuser']}` WHERE `id`='{$row['id']}';", $_DDATA['link']);
		$delete = mysql_query("DELETE FROM `{$_DDATA['tablesite']}` WHERE `owner`='{$row['id']}';", $_DDATA['link']);
	}
	if ($_SDATA['captcha'])
		$delete = mysql_query("DELETE FROM `{$_DDATA['tableauth']}` WHERE `date`<(UNIX_TIMESTAMP()-3600);", $_DDATA['link']);
}



/* ****************************************************************** */
/* ***** Classes **************************************************** */
class ORM_filterSet {
	var $siteOrder = array(array('title', false), array('owner', false), array('errors', false), array('id', false));
	var $siteFilter = array('', '', '');

	var $accoOrder = array(array('username', false), array('level', false), array('id', false) , array('sites', false));
	var $accoFilter = array('', '');

	function ORM_filterSet($code = false) {
		if ($code) {
			$code = unserialize(stripslashes(base64_decode($code)));
			if (count($code) >= 4) {
				$this->siteOrder = $code[0];
				$this->siteFilter = $code[1];
				$this->accoOrder = $code[2];
				$this->accoFilter = $code[3];
			}
		}
	}

	function getCode() {
		return base64_encode(serialize(array($this->siteOrder, $this->siteFilter, $this->accoOrder, $this->accoFilter)));
	}
}



/* ****************************************************************** */
/* ***** Head Functions ********************************************* */
/* *********************************************************************
 * Set a ring variable in the MySQL table
 *
 */
function ORM_setData($field, $input) {
	global $_DDATA, $_VDATA;
	mysql_query("UPDATE `{$_DDATA['tablename']}` SET `$field`='".addslashes($_VDATA[$field] = $input)."';", $_DDATA['link']);
	return mysql_affected_rows();
}


/* *********************************************************************
 * Sanitize incoming form input
 *
 */
function ORM_sanitize(&$input, $maxlength = 65535, $newlines = false) {
	$input = preg_replace(($newlines) ? '/[\x00-\x09\x0B-\x1F]/' : '/[\x00-\x1F]/', "", $input);
	$input = trim(substr($input, 0, $maxlength));
}


/* *********************************************************************
 * Replace double-underscore-delimited codes in navigation bar HTML
 *
 */
function ORM_navbarCodes($code, $id = 0) {
	global $_VDATA, $_SDATA;
	return str_replace(array("__ringname__", "__hubURI__", "__id__"), array($_VDATA['name'], $_SDATA['huburi'], $id), $code);
}


/* *********************************************************************
 * Format HTML for correct display in a ' delimited Javascript string
 *
 */
function ORM_html2js($code, $strict = false) {
	if ($strict)
		return str_replace(array("\r", "\n", "\t", "  ", "'"), array("", "", "", " ", "\'"), $code);
	return str_replace(array("\n", "'") , array('\n', '\x27'), htmlspecialchars($code));
}


/* *********************************************************************
 * Send email using the PHPMailer class
 *
 */
function ORM_ringmail($to, $subject, $message) {
	global $_SDATA, $_VDATA, $_DDATA, $_LANG;
	require_once("{$_SERVER['DOCUMENT_ROOT']}/{$_SDATA['directory']}/phpmailer.php");

	$select = mysql_query("SELECT `username`, `email` FROM `{$_DDATA['tableuser']}` WHERE `level`='3';", $_DDATA['link']);
	$_OWNER = mysql_fetch_assoc($select);

	$mail = new PHPMailer();
	$mail->From = $_OWNER['email'];
	$mail->FromName = $_OWNER['username'];
	$mail->Body = "$message\n\n-- \n{$_SDATA['huburi']}\n{$_VDATA['name']}\n";
	$mail->Subject = $subject;

	switch ($mail->Mailer = $_VDATA['mail.method']) {
		case "smtp":
			$mail->Host = $_VDATA['mail.smtp.server'];
			if ($_VDATA['mail.smtp.username'] || $_VDATA['mail.smtp.password']) {
				$mail->SMTPAuth = true;
				$mail->Username = $_VDATA['mail.smtp.username'];
				$mail->Password = $_VDATA['mail.smtp.password'];
			}
			break;

		case "sendmail":
			$mail->Sendmail = ini_get("sendmail_path");
			if (strpos($mail->Sendmail, " -f") === false) $mail->Sendmail .= " -f{$_OWNER['email']}";
			break;

	}
	$mail->CharSet = $_VDATA['display.charset'];

	if (!is_array($to[0])) $to = array($to);

	$sentcount = 0;
	foreach ($to as $recips) {
		$mail->AddAddress($recips[1], $recips[0]); // Address, Name

		if(!$mail->Send()) {
			$_SDATA['error'][] = $mail->ErrorInfo;
			$_SDATA['error'][] = sprintf($_LANG['042'], $recips[1]);
		} else $sentcount++;
		$mail->ClearAddresses();
	}

	return (count($_SDATA['error'])) ? false : $sentcount;
}


/* *********************************************************************
 * Search the ring for a valid site to which we can send the user
 *
 */
function ORM_ringtravel($uri, $uselookahead = "yes") {
	global $_SDATA, $_DDATA, $_GDATA;

	if ($_GDATA['redirects']++ > 2) return false;
	$error = false;

	if ($uselookahead == "yes") {
		$parsed = @parse_url($uri);
		if (isset($parsed['scheme'])) {
			if (!isset($parsed['path'])) {
				$parsed['path'] = "/";
				if ($uri{strlen($uri) - 1} != "/") $uri .= "/";
			}
			$parsed['full'] = $parsed['path'].((isset($parsed['query'])) ? "?{$parsed['query']}" : "");
			$parsed['hostport'] = $parsed['host'].((isset($parsed['port'])) ? ":".$parsed['port'] : "");
			if (!isset($parsed['port'])) $parsed['port'] = "80";

			if ($conn = @fsockopen("tcp://{$parsed['host']}", $parsed['port'], $erstr, $errno, 3)) {
				$status = socket_get_status($conn);
				if (!$status['blocked']) socket_set_blocking($conn, true);
				socket_set_timeout($conn, 3);

				$parsed['full'] = str_replace(array("&amp;", " "), array("&", "%20"), $parsed['full']);

				fwrite($conn, "HEAD {$parsed['full']} HTTP/1.0\r\nHost: {$parsed['hostport']}\r\nUser-Agent: {$_SDATA['useragent']}\r\n\r\n");
				while (!feof($conn)) {
					$data = fgets($conn, 1024);
					$status = socket_get_status($conn);
					if ($status['timed_out']) $error = true;

					if (preg_match("/^HTTP\/1\.\d ([1-5]\d\d)/i", $data, $code))
						if ($code[1]{0} != "2" && $code[1]{0} != "3") $error = true;

					if (preg_match("/^Location:\s*([^\r\n]*?)[\r\n]/i", $data, $location)) {
						ORM_ringtravel($location[1], $uselookahead);
						$error = true;
					}
				}
			} else $error = true;
		} else $error = true;
	}

	if ($uselookahead == "no" || $error == false) {
		$insert = mysql_query("INSERT INTO `{$_DDATA['tablestat']}` SET
			`from`='{$_GDATA['from']}',
			`to`='{$_GDATA['to']}',
			`success`='yes',
			`date`=UNIX_TIMESTAMP(),
			`type`='{$_GDATA['type']}',
			`ua`='".addslashes($_SERVER['HTTP_USER_AGENT'])."'
		;", $_DDATA['link']);
		header("Location: $uri", true, 302);
		fclose($conn);
		exit();
	}

	$insert = mysql_query("INSERT INTO `{$_DDATA['tablestat']}` SET
		`from`='{$_GDATA['from']}',
		`to`='{$_GDATA['to']}',
		`success`='no',
		`date`=UNIX_TIMESTAMP(),
		`type`='{$_GDATA['type']}',
		`ua`=''
	;", $_DDATA['link']);
	return false;
}



/* ****************************************************************** */
/* ***** Body Functions ********************************************* */
/* *********************************************************************
 * Control display of links in the Controls column
 *
 */
function ORM_controlLink($title, $query, $condition) {
	echo ($condition) ? "<a href=\"{$_SERVER['PHP_SELF']}".(($query) ? "?$query" : "")."\">$title</a>" : "<strong>$title</strong>";
}


/* *********************************************************************
 * Display any error or success messages which have accumulated
 *
 */
function ORM_errorSuccess() {
	global $_SDATA;
	if (count($_SDATA['success'])) { ?> 
		<ul class="orm_notify"><?php
			foreach ($_SDATA['success'] as $success) { ?> 
				<li><?php echo $success; ?></li><?php
			} ?> 
		</ul><?php
	}
	if (count($_SDATA['error'])) { ?> 
		<ul class="orm_notify orm_warn"><?php
			foreach ($_SDATA['error'] as $error) { ?> 
				<li><?php echo $error; ?></li><?php
			} ?> 
		</ul><?php
	}
}

?>
Return current item: Orca Ringmaker