cosmetic overhaul
This commit is contained in:
parent
8852b2ae8b
commit
ada8e382b9
277
rebuild.php
277
rebuild.php
@ -3,37 +3,19 @@
|
||||
// Code-hosting website
|
||||
// ````````````````````
|
||||
|
||||
// CONFIGURATION
|
||||
// `````````````
|
||||
|
||||
define('BASEDIR', __DIR__.'\\');
|
||||
define('SITE_TITLE', 'code.ivysaur.me');
|
||||
define('PAGE_THUMB_W', 60);
|
||||
define('PAGE_THUMB_H', 60);
|
||||
|
||||
// clean up wwwroot
|
||||
|
||||
if (file_exists(BASEDIR.'wwwroot')) {
|
||||
rename(BASEDIR.'wwwroot', BASEDIR.'wwwroot.old.'.uniqid());
|
||||
}
|
||||
|
||||
mkdir(BASEDIR.'wwwroot');
|
||||
mkdir(BASEDIR.'wwwroot/srv');
|
||||
|
||||
// List of projects
|
||||
|
||||
$ls = scandir(BASEDIR.'data');
|
||||
sort($ls);
|
||||
$projects = array();
|
||||
foreach($ls as $dirname) {
|
||||
if ($dirname[0] == '.') continue;
|
||||
$matches = array();
|
||||
|
||||
if (preg_match('~(?:\d+-)?(.+)~', $dirname, $matches)) {
|
||||
$projects[$dirname] = $matches[1];
|
||||
}
|
||||
}
|
||||
define('INDEX_THUMB_W', 90);
|
||||
define('INDEX_THUMB_H', 30);
|
||||
|
||||
/**
|
||||
* Create a thumbnail of an image. It overscales and crops to fit the target
|
||||
* box.
|
||||
* Create a thumbnail of an image. It overscales, centers, and crops to fit the
|
||||
* target dimensions.
|
||||
*
|
||||
* @param string $src_file
|
||||
* @param string $dest_file
|
||||
@ -50,21 +32,12 @@ function mkthumbnail($src_file, $dest_file, $width, $height) {
|
||||
|
||||
$scale = max( $width/$src_width, $height/$src_height ); // overscale + crop
|
||||
|
||||
print_r($scale);
|
||||
|
||||
$box_w = $width/$scale;
|
||||
$box_h = $height/$scale;
|
||||
|
||||
$box_xoff = floor(($src_width - $box_w)/2);
|
||||
$box_yoff = floor(($src_height - $box_h)/2);
|
||||
|
||||
print_r(array(
|
||||
$dest, $im,
|
||||
0, 0,
|
||||
$box_xoff, $box_yoff,
|
||||
$width, $height, $box_w, $box_h
|
||||
));
|
||||
|
||||
imagecopyresampled(
|
||||
$dest, $im,
|
||||
0, 0,
|
||||
@ -75,6 +48,38 @@ function mkthumbnail($src_file, $dest_file, $width, $height) {
|
||||
return imagejpeg($dest, $dest_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a directory tree and all its contents.
|
||||
*
|
||||
* @author http://www.php.net/manual/en/function.rmdir.php#110489
|
||||
* @param string $dir
|
||||
* @return boolean
|
||||
*/
|
||||
function rmdir_recursive($dir) {
|
||||
$files = array_diff(scandir($dir), array('.','..'));
|
||||
foreach ($files as $file) {
|
||||
if (is_dir("$dir/$file")) {
|
||||
rmdir_recursive("$dir/$file");
|
||||
} else {
|
||||
unlink("$dir/$file");
|
||||
}
|
||||
}
|
||||
return rmdir($dir);
|
||||
}
|
||||
|
||||
function fbytes($size, $suffixes='B|KiB|MiB|GiB|TiB') {
|
||||
$sxlist = explode('|', $suffixes);
|
||||
if ($size < 1024) {
|
||||
return $size.$sxlist[0];
|
||||
}
|
||||
|
||||
while ($size > 1024 && count($sxlist) >= 2) {
|
||||
array_shift($sxlist);
|
||||
$size /= 1024;
|
||||
}
|
||||
return number_format($size, 2).array_shift($sxlist);
|
||||
}
|
||||
|
||||
function str_ext($sz) {
|
||||
$dpos = strrpos($sz, '.');
|
||||
return substr($sz, $dpos+1);
|
||||
@ -88,15 +93,27 @@ function hesc($sz) {
|
||||
return @htmlentities($sz, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
}
|
||||
|
||||
function text2html($sz) {
|
||||
$base = nl2br(hesc($sz));
|
||||
|
||||
preg_replace('~(https?://.+\b)~i', '<a href="\1">\1</a>', $base);
|
||||
return $base;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class CProject {
|
||||
|
||||
private $dir;
|
||||
private $projname;
|
||||
private $shortdesc = '(no description)';
|
||||
public $projname;
|
||||
public $shortdesc = '(no description)';
|
||||
private $longdesc = '';
|
||||
private $images = array();
|
||||
private $downloads = array();
|
||||
|
||||
public $homeimage = 'no_image.png';
|
||||
|
||||
public function __construct($dirname, $projname) {
|
||||
$this->dir = BASEDIR.'data/'.$dirname.'/';
|
||||
$this->projname = $projname;
|
||||
@ -132,6 +149,15 @@ class CProject {
|
||||
mkthumbnail($outfile.'.'.str_ext($image), $outfile.'_thumb.jpg', PAGE_THUMB_W, PAGE_THUMB_H);
|
||||
}
|
||||
|
||||
if (count($this->images)) {
|
||||
mkthumbnail(
|
||||
BASEDIR.'wwwroot/srv/'.$this->projname.'_0.'.str_ext($this->images[0]),
|
||||
BASEDIR.'wwwroot/srv/'.$this->projname.'_headimg.jpg',
|
||||
INDEX_THUMB_W, INDEX_THUMB_H
|
||||
);
|
||||
$this->homeimage = 'srv/'.$this->projname.'_headimg.jpg';
|
||||
}
|
||||
|
||||
// Copy downloads to wwwroot
|
||||
|
||||
foreach($this->downloads as $idx => $filename) {
|
||||
@ -142,55 +168,176 @@ class CProject {
|
||||
|
||||
ob_start();
|
||||
$this->index();
|
||||
$idxfile = ob_get_clean();
|
||||
$idxfile = template($this->projname.' | '.SITE_TITLE, ob_get_clean());
|
||||
file_put_contents(BASEDIR.'wwwroot/'.$this->projname.'.html', $idxfile);
|
||||
}
|
||||
|
||||
public function index() {
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title><?=hesc($this->projname)?> | <?=hesc(SITE_TITLE)?></title>
|
||||
</head>
|
||||
<body>
|
||||
<h2><?=hesc($this->projname)?></h2>
|
||||
<h2><a href="index.html"><?=hesc(SITE_TITLE)?></a> > <?=hesc($this->projname)?></h2>
|
||||
|
||||
<p><?=nl2br(hesc($this->longdesc))?></p>
|
||||
<div class="projinfo">
|
||||
|
||||
<?php if (count($this->images)) { ?>
|
||||
<h3>Images</h3>
|
||||
<?php foreach($this->images as $idx => $origname) { ?>
|
||||
<a href="srv/<?=hesc(urlencode($this->projname))?>_<?=$idx?>.<?=str_ext($origname)?>"><img src="srv/<?=hesc(urlencode($this->projname))?>_<?=$idx?>_thumb.jpg"></a>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<div class="projbody">
|
||||
|
||||
<strong>ABOUT</strong>
|
||||
|
||||
<p><?=text2html($this->longdesc)?></p>
|
||||
|
||||
<?php if (count($this->downloads)) { ?>
|
||||
|
||||
<strong>DOWNLOAD</strong>
|
||||
|
||||
<?php if (count($this->downloads)) { ?>
|
||||
<h3>Files</h3>
|
||||
<ul>
|
||||
<?php foreach($this->downloads as $filename) { ?>
|
||||
<li><a href="srv/<?=hesc(urlencode($filename))?>"><?=hesc($filename)?></a></li>
|
||||
<li>
|
||||
<a href="srv/<?=hesc(urlencode($filename))?>"><?=hesc($filename)?></a>
|
||||
<small>
|
||||
<?=hesc(fbytes(filesize(BASEDIR.'wwwroot/srv/'.$filename)))?>
|
||||
</small>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php if (count($this->images)) { ?>
|
||||
<div class="projimg">
|
||||
<?php foreach($this->images as $idx => $origname) { ?>
|
||||
<a href="srv/<?=hesc(urlencode($this->projname))?>_<?=$idx?>.<?=str_ext($origname)?>"><img src="srv/<?=hesc(urlencode($this->projname))?>_<?=$idx?>_thumb.jpg" class="thumbimage"></a>
|
||||
<?php } ?>
|
||||
</body>
|
||||
</html>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Build all projects
|
||||
|
||||
foreach($projects as $dirname => $projectname) {
|
||||
$pr = new CProject($dirname, $projectname);
|
||||
print_r($pr);
|
||||
|
||||
$pr->write();
|
||||
function template($title, $content) {
|
||||
ob_start();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
|
||||
<meta name="viewport" content="width=768px" >
|
||||
<link type="text/css" rel="stylesheet" href="style.css">
|
||||
<title><?=hesc($title)?></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="content">
|
||||
<?=$content?>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
// Build index page
|
||||
function buildall() {
|
||||
|
||||
// Clean up webroot
|
||||
|
||||
if (file_exists(BASEDIR.'wwwroot')) {
|
||||
rmdir_recursive(BASEDIR.'wwwroot');
|
||||
}
|
||||
|
||||
echo "Creating directories...\n";
|
||||
|
||||
mkdir(BASEDIR.'wwwroot');
|
||||
mkdir(BASEDIR.'wwwroot/srv');
|
||||
|
||||
// Copy in static files
|
||||
|
||||
foreach(scandir(BASEDIR.'static') as $static) {
|
||||
if ($static[0] == '.' || is_dir($static) /* fixme */) continue;
|
||||
copy(BASEDIR.'static/'.$static, BASEDIR.'wwwroot/'.$static);
|
||||
}
|
||||
|
||||
// List projects
|
||||
|
||||
$ls = scandir(BASEDIR.'data');
|
||||
sort($ls);
|
||||
$projects = array();
|
||||
foreach($ls as $dirname) {
|
||||
if ($dirname[0] == '.') continue;
|
||||
$matches = array();
|
||||
|
||||
if (preg_match('~(?:\d+-)?(.+)~', $dirname, $matches)) {
|
||||
$projects[$dirname] = $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Build all projects
|
||||
|
||||
$plist = array();
|
||||
$count = 0;
|
||||
|
||||
foreach($projects as $dirname => $projectname) {
|
||||
|
||||
echo sprintf("[%2d/%2d] ".$projectname."...", ++$count, count($projects));
|
||||
|
||||
$pr = new CProject($dirname, $projectname);
|
||||
$pr->write();
|
||||
$plist[] = $pr;
|
||||
|
||||
echo " done\n";
|
||||
}
|
||||
|
||||
// Build index page
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<h2><?=hesc(SITE_TITLE)?></h2>
|
||||
|
||||
<img src="overview.jpg" class="headimg">
|
||||
|
||||
<p>
|
||||
This page contains several assorted projects, which no longer have any relation. They are listed in roughly chronological order (newest first). <strong>Unless specified otherwise</strong>, you may feel free to use and modify both the binaries and any source code, for any purpose, on the general condition you do not misrepresent who the author is (BSD license).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Some of these projects formerly appeared on Google Code <a href="https://code.google.com/p/mappy/">here</a>, but were moved following the discontinuation of the Google Code binary download system.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For bug reports, feature requests, or if you need any help, please
|
||||
<a
|
||||
href="http://www.google.com/recaptcha/mailhide/d?k=01GuAWzMc9JjSdooo-2KCMQA==&c=kgR3dBrP39yhPIy8FvLFbuBLmWqorQBDc_Zjbw6NAmU="
|
||||
onclick="window.open('http://www.google.com/recaptcha/mailhide/d?k\07501GuAWzMc9JjSdooo-2KCMQA\75\75\46c\75kgR3dBrP39yhPIy8FvLFbuBLmWqorQBDc_Zjbw6NAmU\075', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;"
|
||||
title="Reveal this e-mail address"
|
||||
>click here</a> to email me.
|
||||
</p>
|
||||
|
||||
<img src="projects.jpg" class="headimg">
|
||||
|
||||
<table class="projtable">
|
||||
<?php foreach ($plist as $pr) { ?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<?=hesc(urlencode($pr->projname))?>.html"><img src="<?=hesc($pr->homeimage)?>" class="homeimage"></a>
|
||||
</td>
|
||||
<td>
|
||||
<strong><?=hesc($pr->projname)?></strong>,
|
||||
<?=hesc($pr->shortdesc)?>
|
||||
<a href="<?=hesc(urlencode($pr->projname))?>.html">more...</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
<?php
|
||||
|
||||
$index = template(SITE_TITLE, ob_get_clean());
|
||||
file_put_contents(BASEDIR.'wwwroot/index.html', $index);
|
||||
|
||||
echo "All processes complete.\n";
|
||||
|
||||
}
|
||||
|
||||
buildall();
|
||||
|
BIN
static/no_image.png
Normal file
BIN
static/no_image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 860 B |
BIN
static/overview.jpg
Normal file
BIN
static/overview.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
BIN
static/pixel_weave.png
Normal file
BIN
static/pixel_weave.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 233 B |
BIN
static/pixel_weave_@2X.png
Normal file
BIN
static/pixel_weave_@2X.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 264 B |
BIN
static/projects.jpg
Normal file
BIN
static/projects.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
95
static/style.css
Normal file
95
static/style.css
Normal file
@ -0,0 +1,95 @@
|
||||
/* style.css */
|
||||
|
||||
img {
|
||||
border:0;
|
||||
}
|
||||
a {
|
||||
color:black;
|
||||
}
|
||||
a:hover {
|
||||
color:blue;
|
||||
}
|
||||
h1,h2,h3 {
|
||||
margin-top:0;
|
||||
}
|
||||
|
||||
/* */
|
||||
|
||||
html, body {
|
||||
/* structural */
|
||||
height:100%;
|
||||
margin:0;
|
||||
border:0;
|
||||
padding:0;
|
||||
|
||||
/* cosmetic */
|
||||
background:#DDD url('pixel_weave.png'); /* thanks subtlepatterns.com ! */
|
||||
color:#333;
|
||||
}
|
||||
|
||||
#container {
|
||||
margin:0 auto;
|
||||
width:768px;
|
||||
position:relative;
|
||||
|
||||
height:auto !important;
|
||||
height:100%; /* oldIE */
|
||||
min-height:100%;
|
||||
|
||||
/* cosmetic */
|
||||
background:white;
|
||||
}
|
||||
|
||||
#content {
|
||||
padding:14px;
|
||||
background:white;
|
||||
}
|
||||
|
||||
/* */
|
||||
|
||||
.projtable {
|
||||
|
||||
}
|
||||
.projtable tr {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.projtable td {
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.projinfo {
|
||||
position:relative;
|
||||
}
|
||||
.projbody {
|
||||
position:absolute;
|
||||
left:0;
|
||||
right: 64px;
|
||||
}
|
||||
.projimg {
|
||||
position:absolute;
|
||||
right:0;
|
||||
|
||||
width:60px;
|
||||
}
|
||||
|
||||
/* */
|
||||
|
||||
.headimg {
|
||||
width:310px;
|
||||
height:62px;
|
||||
}
|
||||
|
||||
.homeimage {
|
||||
width:90px;
|
||||
height:30px;
|
||||
}
|
||||
|
||||
.thumbimage {
|
||||
width:60px;
|
||||
height:60px;
|
||||
opacity: 0.8;
|
||||
transition:0.2s opacity;
|
||||
}
|
||||
.thumbimage:hover {
|
||||
opacity:1.0;
|
||||
}
|
Reference in New Issue
Block a user