The Daily Standa

standa today | an archive

<?php
/**
 * Copyright 2004 spaze; released under GNU General Public License Version 2
 * CSS and JS is inline as I wanted to have it all-in-one. Also no template engine is
 * used for the same reason and for the sake of simplicity. For educational purposes ;)
 */

function getMOTD($url$regexp, &$wrapped, &$raw)
{
  
preg_match($regexpfile_get_contents($url), $arr_matches);
  
$arr_matches[1] = iconv('ISO-8859-2''UTF-8'$arr_matches[1]);
  
$raw preg_replace('/<.*?>/'' '$arr_matches[1]);
  
$wrapat = (strlen($raw) <= 21 15 21);
  
$wrapped wordwrap(wordwrap($raw$wrapat), $wrapat"\n"TRUE);
}

function 
getStanda($motd)
{
  
// cURL classes ;)
  
$standa curl_init('http://vembloud.wz.cz/index.php');
  
curl_setopt($standaCURLOPT_POST1);
  
curl_setopt($standaCURLOPT_POSTFIELDS'text='.urlencode($motd).'&done=Hotovo%21');
  
curl_setopt($standaCURLOPT_USERAGENTini_get('user_agent'));
  
curl_setopt($standaCURLOPT_RETURNTRANSFER1);
  
preg_match('/'.preg_quote('http://vembloud.wz.cz/standa.php?id=''/').'(\d+)/' curl_exec($standa), $arr_matches);
  return 
$arr_matches[1];
}

ini_set('user_agent''Mozilla/5.0 (compatible; Grossbot/2.1; +http://exploited.cz/the-daily-standa/)');

require 
'./you-will-never-see-the-contents-of-this-file.php';  // really

switch ($_SERVER['QUERY_STRING']) {
  case 
'make':
/* ug.cz down, fetching down
    getMOTD('http://www.underground.cz/', '{motd">(.*?)</}i', $motd_full, $motd_full_alt);
    getMOTD('http://text.underground.cz/', '{</center>\s+(.*?)<br>\W+\<\!}i', $motd_text, $motd_text_alt);
    $motd_full_id = getStanda($motd_full);
    $motd_text_id = getStanda($motd_text);

    $sql = 'REPLACE `dailystanda` SET
     `date` = NOW(),
     `full_id` = "'.$motd_full_id.'",
     `text_id` = "'.$motd_text_id.'",
     `motd_full` = "'.mysql_escape_string($motd_full_alt).'",
     `motd_text` = "'.mysql_escape_string($motd_text_alt).'"';
    mysql_query($sql);
*/
        
header('HTTP/1.1 301 Moved Permanently');
        
header('Location: http://'.$_SERVER['SERVER_NAME'].substr($_SERVER['REQUEST_URI'], 0strpos($_SERVER['REQUEST_URI'], '?')));
        
header('Connection: close');
    break;
  case 
'archive':
    
$sql 'SELECT `date`, `motd_full`, `motd_text` FROM `dailystanda` ORDER BY `date` DESC';
    
$result mysql_query($sql);
    
$arr_motds = array();
    while (
$row mysql_fetch_assoc($result)) {
      
$arr_motds[$row['date']]['full'] = $row['motd_full'];
      
$arr_motds[$row['date']]['text'] = $row['motd_text'];
    }
        
$title 'an archive';
    break;
  case 
'source':
    
$source highlight_file($_SERVER['SCRIPT_FILENAME'], TRUE);
        
$title 'dis is open source';
    break;
  default:
    if (!empty(
$_SERVER['QUERY_STRING']))
      
$sql 'SELECT * FROM `dailystanda` WHERE `date` = "'.$_SERVER['QUERY_STRING'].'"';
    else {
      
$sql 'SELECT * FROM `dailystanda` ORDER BY `date` DESC LIMIT 1';
            
$show_regenerate_link FALSE;  // not TRUE anymore as ug.cz is dead
        
}
    
$arr_motd mysql_fetch_assoc(mysql_query($sql));
    
$motd_full_alt = &$arr_motd['motd_full'];
    
$motd_text_alt = &$arr_motd['motd_text'];
    
$motd_full_id = &$arr_motd['full_id'];
    
$motd_text_id = &$arr_motd['text_id'];
    
$archive_anchor = &$arr_motd['date'];
        
$title = &$archive_anchor;
    break;
}

mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The Daily Standa: <?php echo $title?></title>
  <style type="text/css">
    body { color: #A0A9B8; background-color: #213350; text-align: center; font-size: 0.7em; font-family: 'Georgia CE', 'Times New CE', 'New York CE', 'Times CE', Georgia, times, serif; }
    a { color: #C0C9D8; }
        a img { border: 0; }
        .disabled { color: #415370; }
    #full img, #text img { border: 1px solid #222638; }
    #text { display: none; }
    #linktext { color: #213350; }
    #archive { width: 75%; text-align: left; margin: auto; }
    #archive dt { font-weight: bold; }
    #source { width: 75%; text-align: left; margin: auto; padding: 0.5em; background-color: #A0A9B8; border: 1px solid #222638; }
  </style>
  <script type="text/javascript">
  /* <![CDATA[ */
  hidden = '213350'; shown = 'A0A9B8'; d = document; hash = location.hash;
  function show_full() {
    d.getElementById('text').style.display = 'none';
    d.getElementById('full').style.display = 'inline';
    d.getElementById('linktext').style.color = hidden;
    d.getElementById('linkfull').style.color = shown;
  }
  function show_text() {
    d.getElementById('full').style.display = 'none';
    d.getElementById('text').style.display = 'inline';
    d.getElementById('linkfull').style.color = hidden;
    d.getElementById('linktext').style.color = shown;
  }
  d.getElementById('hreffull').onclick = show_full;
  d.getElementById('hreftext').onclick = show_text;
  /* ]]> */
  </script>
</head>
<body>
<h1>The Daily Standa</h1>
<div>
<?php
switch ($_SERVER['QUERY_STRING']) {
  case 
'archive':
?>
    <a href="./"><strong>standa today</strong></a>
    <div id="archive">
    <dl>
<?php
    
foreach ($arr_motds as $key => $value) {
?>
      <dt id="motd-<?php echo $key?>"><a href="?<?php echo $key?>"><?php echo $key?></a></dt>
      <dd><dfn>one:</dfn> <?php echo $value['full']; ?></dd>
      <dd><dfn>two:</dfn> <?php echo $value['text']; ?></dd>
<?php
    
}
?>
    </dl>
  </div>
<?php
    
break;
  case 
'source':
?>
    <strong><a href="./">standa today</a> | <a href="?archive">an archive</a></strong><br /><br />
    <div id="source">
<?php
    
/* This will produce non-valid XHTML pages, but I'm not gonna fix it */
    
echo $source;
?>
    </div>
<?php
    
break;
  default:
?>
    message of the day:
    <strong>
    <span id="linkfull">&raquo;</span>
    <a href="#" id="hreffull">one</a> | <a href="#two" id="hreftext">two</a>
    <span id="linktext">&laquo;</span>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="?archive#motd-<?php echo $archive_anchor?>">an archive</a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?php echo ($show_regenerate_link '<a href="?make" title="will regenerate current billboard, use in case of errors">regenerate</a>' '<a href="./">standa today</a>'); ?>
    </strong><br /><br />
        <span id="full">
    <img src="http://vembloud.wz.cz/standa.php?id=<?php echo $motd_full_id?>" alt="<?php echo htmlspecialchars($motd_full_alt); ?>" /><br />
        <em>Fig. <?php echo $archive_anchor?>/1: <?php echo $motd_full_alt?></em>
        </span>
        <span id="text">
    <img src="http://vembloud.wz.cz/standa.php?id=<?php echo $motd_text_id?>" alt="<?php echo htmlspecialchars($motd_text_alt); ?>" /><br />
        <em>Fig. <?php echo $archive_anchor?>/2: <?php echo $motd_text_alt?></em>
        </span>
    <br />
<?php
    
break;
}
?>
<br />
code by <a href="http://exploited.cz/">spaze</a> | building blocks by <a href="http://www.underground.cz/">underground.cz</a>, <a href="http://vembloud.wz.cz/">SG Creator!</a>, <a href="http://www.tojeono.cz/">TJO</a> | use <a href="http://my.opera.com/spaze/affiliate/">Opera</a> | dis is <a href="?source">open source</a><br /><br />
<a href="http://www.google.com/search?q=define:hate"><img src="http://dl.exploited.cz/hate.gif" alt="powered by HATE" /></a>
</div>
<script type="text/javascript">
/* <![CDATA[ */
d.getElementById('hreffull').onclick = show_full;
d.getElementById('hreftext').onclick = show_text;
if (hash && hash == '#two') {
  show_text();
} else {
  show_full();
}
/* ]]> */
</script>
</body>
</html>

code by spaze | building blocks by underground.cz, SG Creator!, TJO | use Opera | dis is open source

powered by HATE