Clean up code style.
Clean up code style.

File last commit:

06f8872afea7
f6994cfce03c
Show More
frontend.inc.php
370 lines | 10.6 KiB | text/x-php | HtmlPhpLexer
/ frontend.inc.php
Add root-directory files.
r2 <?php
require_once('LocalSettings.php');
set_error_handler('mtdie');
/* BEGIN FRONT END LIBRARY FUNCTIONS */
function validate_comic_id($comic)
{
if(!ctype_digit((string)$comic) || (int)$comic > max_strip_id() || (int)$comic < 1)
{
return false;
}
return $comic;
}
function validate_panel_id($comic, $panel)
{
$panels = get_num_panels($comic);
if(!ctype_digit((string)$panel) || $panel === false || $panel > $panels || $panel < 1)
{
return false;
}
return $panel;
}
function validate_type_id($type)
{
if(!ctype_digit((string)$type) || $type < 1 || count_by_type($type) == 0)
{
return false;
}
}
function get_num_panels($comic)
{
global $link;
if(!validate_comic_id($comic))
{
return false;
}
Remove spaces at EOL.
r36
Add root-directory files.
r2 $rs = mysqli_query($link,'SELECT MAX(panel) FROM transcript WHERE strip = '.(int)$comic);
return current(mysqli_fetch_row($rs));
}
function build_panel_transcript($comic, $panel)
{
$query = 'SELECT speaker, speech FROM transcript
Remove spaces at EOL.
r36 WHERE strip = '.(int)$comic.' AND panel = '.(int)$panel.'
Add root-directory files.
r2 AND speaker NOT LIKE "#%" ORDER BY line';
Remove spaces at EOL.
r36
Add root-directory files.
r2 $qr = query_to_nested($query);
return $qr;
}
function query_to_nested($query)
{
global $link;
$ret = array();
$rs = mysqli_query($link,$query) or die(mysqli_error($link));
while($row = mysqli_fetch_assoc($rs))
{
$ret[]= $row;
}
mysqli_free_result($rs);
Remove spaces at EOL.
r36
Add root-directory files.
r2 return $ret;
}
#Runs a query
#Compresses the specified column in the returned columns into a single array
function query_to_array($query, $col=0)
{
global $link;
$ret = array();
$rs = mysqli_query($link,$query) or die(mysqli_error($link));
while($row = mysqli_fetch_array($rs))
{
$ret[]= $row[0];
}
mysqli_free_result($rs);
Remove spaces at EOL.
r36
Add root-directory files.
r2 return $ret;
}
function count_by_type($type)
{
global $link;
$qr = mysqli_query($link,'SELECT COUNT(*) FROM strip WHERE type = '.(int)$type) or die(mysqli_error($link));
return current(mysqli_fetch_row($qr));
}
function max_rant_id()
{
global $link;
$qr = mysqli_query($link,'SELECT MAX(id) FROM rant WHERE published < NOW()') or die(mysqli_error($link));
return current(mysqli_fetch_row($qr));
}
function max_transcript_strip_id()
{
global $link;
$qr = mysqli_query($link,'SELECT MAX(strip) FROM transcript') or die(mysqli_error($link));
return current(mysqli_fetch_row($qr));
}
function max_strip_id()
{
global $link;
$qr = mysqli_query($link,'SELECT MAX(id) FROM strip WHERE published < NOW()') or die(mysqli_error($link));
return current(mysqli_fetch_row($qr));
}
function load_strip($id)
{
global $link;
$qr = mysqli_query($link,"SELECT UNIX_TIMESTAMP(s.published) as udate,
s.title AS title, media.extension AS ext, s.type AS type,
s.book AS book, s.page AS page,
DATE_FORMAT(s.published, '%M %D, %Y') AS pubdate
FROM media_t media, strip s
WHERE s.media = media.id AND s.id = $id") or die(mysqli_error($link));
return mysqli_fetch_assoc($qr);
}
function load_transcript($id)
{
global $link;
$qr = mysqli_query($link,"SELECT panel, speaker, speech
FROM transcript WHERE strip = $id
AND (transcript.speaker NOT LIKE \"#%\")
ORDER BY panel, line") or die(mysqli_error($link));
return $qr;
}
function conditional_exit($mtime)
{
if(!PERFORM_CONDITIONAL_CACHE)
return;
Remove spaces at EOL.
r36
Add root-directory files.
r2 $f_date = gmdate( 'D, d M Y H:i:s T', $mtime );
header("Last-Modified: $f_date");
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $f_date) {
header('HTTP/1.0 304 Not Modified');
exit(0);
}
}
function mt_query($link,$sql) {
global $link;
$r = mysqli_query($link,$sql);
if( !$r ) trigger_error("SQL Error", E_USER_ERROR);
return $r;
}
function mtdie($errno, $errstr, $errfile, $errline, $errcontext) {
$extra = '';
switch ($errno) {
case E_NOTICE:
break;
case E_WARNING: // for SQL errors
case E_USER_WARNING:
case E_USER_NOTICE:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_USER_ERROR:
case E_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
@header('Content-Type: text/html; charset=utf-8');
$message = "$errstr in $errfile at line $errline";
if (strcasecmp('sql', $errstr) == 0 ) {
$message .= "\r\nSQL Error " .': ' . mysqli_error($link);
}
error_log( $message, 0 ); // Log to Syslog
Remove spaces at EOL.
r36
Add root-directory files.
r2 $message .= "\r\n\r\nBacktrace:";
$backtrace = array_reverse(debug_backtrace());
$i=2;
$message .= "\r\n1: " . $err_context . " at $errfile:$errline";
foreach($backtrace as $k=>$call) {
Remove spaces at EOL.
r36 $message .= "\r\n" . str_pad("$i:", $i+4 ) . $call['function'] . '( ' . implode(', ', $call['args']) . ' ) at ' . $call['file'] . ':' . $call['line'];
Add root-directory files.
r2 $i++;
}
$message .= "\r\n";
Remove spaces at EOL.
r36
Add root-directory files.
r2 $message .= "\r\nRequest Details:"
. "\r\nscript_url: " . $_SERVER["SCRIPT_URL"]
. "\r\nquery_string: " . $_SERVER["QUERY_STRING"]
. "\r\nremote_addr: " . $_SERVER["REMOTE_ADDR"]
. "\r\nhttp_user_agent: " . $_SERVER["HTTP_USER_AGENT"];
print_r($message);
error_log( "Megatokyo Site Error at " .date('Y-m-d H:i'). "\r\n\r\n$message\r\n", 1, SITE_CONTACT ); //, "Subject: Megatokyo Site Errors for " . date('Y-m-d') ); // Log to email
// Log to user on screen
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title?$title:'Megatokyo Administration Editor'; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style media="screen" type="text/css">
html {
background: #eee;
}
body {
background: #fff;
color: #000;
font-family: Georgia, "Times New Roman", Times, serif;
margin-left: 25%;
margin-right: 25%;
padding: .2em 2em;
}
h1 {
color: #006;
font-dize: 18px;
font-weight: lighter;
}
h2 {
font-size: 16px;
color: red;
}
p, li, dt {
line-height: 140%;
padding-bottom: 2px;
}
ul, ol {
padding: 5px 5px 5px 20px;
}
#logo {
margin-bottom: 2em;
}
</style>
</head>
<body>
<h1 id="Logo">Megatokyo</h1>
<h2>Encountered a problem servicing your request.</h2>
<p><?php echo date('Y-m-d H:i'); ?> - Administrators have been notified, we'll try to have things fixed shortly.</p>
<p><a href="<?php SITE_HOST . SITE_PATH; ?>">&lsaquo; Back to Megatokyo.com</a></p>
</body>
</html>
<?php die();
break;
}
}
function term($code)
{
header("HTTP/1.0 $code");
exit(0);
}
function utfentities($string)
{
return htmlentities($string, ENT_COMPAT, 'UTF-8');
}
/* BEGIN FRONT END HTML DISPLAY FUNCTIONS */
function ad_template($zone, $n) { }
/*
{ ?><span class="glowwrap"><script type="text/javascript"><!--// <![CDATA[
OA_show(<?php echo $zone; ?>);
// ]]> --></script></span>
<noscript>
<?php printf('<a href="%s%s/adclick.php?n=%s"><img src="%s%s/adview.php?what=zone:%d&amp;n=%s" alt="" /></a>', ADS_HOST, ADS_PATH, $n, ADS_HOST, ADS_PATH, $zone, $n) ?>
</noscript>
<?php }
*/
function pagehead($caller, $title = 'relax, we understand j00', $style='')
{ ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
Use the older "pragma" style of charset declaration for compatibility.
r22 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Add root-directory files.
r2 <meta name="description" content="MegaTokyo the Comic" />
<meta name="author" content="Frederick M. Gallagher III" />
<meta name="generator" content="Alan J Castonguay, Robert Sherby, Jeremy Wagner-Kaiser, Shawn Morford (!! nathanbp, jrl !!)" />
<meta name="keywords" content="megatokyo.com, online comic, gaming, japanese animation, anime, fan art, pop culture, japan, nihongo, nihonjin, otaku, photoshop, fansubs, computer graphics, fred gallagher" />
<base href="<?php echo SITE_HOST.SITE_PATH ?>/" />
<title>MegaTokyo - <?php echo $title ?></title>
<link type="image/x-icon" rel="shortcut icon" href="favicon.ico" />
Fix CSS paths to use the new directory structure.
r26 <link type="text/css" rel="stylesheet" href="styles/main.css" />
<link type="text/css" rel="stylesheet" href="styles/<?php echo $caller ?>.css" />
Remove spaces at EOL.
r36
Add root-directory files.
r2 <?php
if($style != '')
{
echo '<style type="text/css">';
echo $style;
echo '</style>';
}
?>
<link type="application/rss+xml" rel="alternate" title="Strips Only" href="rss/strips.xml" />
<link type="application/rss+xml" rel="alternate" title="Rants Only" href="rss/rants.xml" />
<link type="application/rss+xml" rel="alternate" title="Strips and Rants" href="rss/megatokyo.xml" />
Remove spaces at EOL.
r36
Add root-directory files.
r2 <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
Remove spaces at EOL.
r36
Add root-directory files.
r2 <script type="text/javascript" src="index.js"></script><?php /*
<script type='text/javascript' src='<?php echo ADS_HOST, ADS_PATH ?>/www/delivery/spcjs.php?id=1'></script> */ ?>
<script type="text/javascript" src="resources.js"></script>
<?php include('analytics.php'); ?>
</head>
<body>
<div id="adbar">
<a id="megagear-ad" href="http://www.megagear.com"><img src="parts/mt-head-left-MG.png" alt="MegaGear" /></a><?php // ad_template(1, 'a2eed23e') ?>
Remove "Community" page link and replace MTVN ad.
r15 <a id="kickstarter-ad" href="http://vn.megatokyo.com"><img src="extra/MTVN-ADBANNER-animated-03.gif" alt="MegaTokyo Visual Novel" /></a>
Add root-directory files.
r2 <a id="cologuys-ad" href="http://www.megagear.com"><img src="parts/mt-head-left-MG.png" alt="MegaGear" /></a>
</div>
<div id="banner"> <div class="blackbar"><span></span>online webcomic / manga / doujinshi</div>
<h1><a href="index.php"><img src="parts/mt-masthead2010.png" alt="megatokyo - relax, we understand j00" /></a></h1>
<ul class="nl" style="letter-spacing: -1px;">
<li><a href="faq">FAQ</a></li>
<li>&middot;</li>
<li><a href="story">story</a></li>
<li>&middot;</li>
Remove old static characters page in favor of a new one in the database.
r40 <li><a href="characters">characters</a></li>
Add root-directory files.
r2 <li>&middot;</li>
Remove "Community" page link and replace MTVN ad.
r15 <li><a href="fredarting" title="Watch Fred draw live on Twitch!">fredarting</a></li>
Add root-directory files.
r2 <li>&middot;</li>
<li><a href="http://www.megagear.com" title="Buy stuff from the MegaGear store!">merchandise</a></li>
<li>&middot;</li>
<li><a href="http://vn.megatokyo.com" title="Megatokyo Visual Novel">visual novel</a></li>
<li>&middot;</li>
<li><a href="http://forums.megatokyo.com">forums</a></li>
<li>&middot;</li>
<li><a href="search">search</a></li>
</ul>
</div>
<?php }
function pagefoot()
{ ?>
<div id="credits">
<h2><span></span>credits</h2>
<p>megatokyo the comic -
copyright &copy; 2000 - <?php echo date('Y'); ?>
<a href="mailto:piro@megatokyo.com">fred gallagher</a>.
all rights reserved.</p>
<p>'megatokyo' is a registered trademark of
<a href="http://www.fredart.com">fredart studios llc</a>.</p>
Remove spaces at EOL.
r36 </div><?php
Add root-directory files.
r2 }
/* OPEN THE DATABASE */
$link = @mysqli_connect(DB_SERVER, DB_READ_USER, DB_READ_PASS, DB_NAME) or trigger_error('Problem connecting to the SQL database server: '.mysqli_error($link), E_USER_ERROR);
?>