initial commit

This commit is contained in:
mappu 2013-09-21 13:22:48 +12:00
commit 19a5dbb07c
6 changed files with 133 additions and 0 deletions

2
.hgignore Normal file
View File

@ -0,0 +1,2 @@
wwwroot/*
nbproject/*

View File

@ -0,0 +1,3 @@
assorted old projects
A longer description goes here.

0
index_template.htm Normal file
View File

20
page_template.htm Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h2>##PROJECTNAME##</h2>
<p>##DESCRIPTION##</p>
##IMAGESECTION##
<a href="##IMAGE##"><img src="##THUMBNAIL##"></a>
##ENDIMAGESECTION##
##DOWNLOADSECTION##
<a href="##DOWNLOAD_URL##">##FILENAME##</a>
##ENDDOWNLOADSECTION##
</body>
</html>

3
rebuild.cmd Normal file
View File

@ -0,0 +1,3 @@
@echo off
C:\bin\php54\php.exe rebuild.php
pause

105
rebuild.php Normal file
View File

@ -0,0 +1,105 @@
<?php
// Code-hosting website
// ````````````````````
define('BASEDIR', __DIR__.'\\');
// clean up wwwroot
if (file_exists(BASEDIR.'wwwroot')) {
rename(BASEDIR.'wwwroot', BASEDIR.'wwwroot.old.'.uniqid());
}
mkdir(BASEDIR.'wwwroot');
// 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];
}
}
function mkthumbnail($src_file, $dest_file, $width, $height) {
$im = imagecreatefromstring(file_get_contents($src_file));
$dest = imagecreatetruecolor($width, $height);
// TODO
return imagejpeg($dest, $dest_file);
}
function str_ext($sz) {
$dpos = strrpos($sz, '.');
return substr($sz, $dpos+1);
}
function is_image($sz) {
return in_array(strtolower(str_ext($sz)), ['jpg', 'png', 'jpeg']);
}
class CProject {
private $dir;
private $projname;
private $shortdesc = '(no description)';
private $longdesc = '';
private $images = array();
private $downloads = array();
public function __construct($dirname, $projname) {
$this->dir = BASEDIR.'data/'.$dirname.'/';
$this->projname = $projname;
// Identify resources in folder
$ls = scandir($this->dir);
foreach($ls as $file) {
if ($file[0] == '.') continue;
if ($file == 'README.txt') {
$this->longdesc = file_get_contents($this->dir.'README.txt');
$this->shortdesc = array_shift(explode("\n", $this->longdesc));
continue;
}
if (is_image($file)) {
$this->images[] = $file;
} else {
$this->downloads[] = $file;
}
}
}
public function write() {
// Build file mapping
// Generate image thumbnails
// Copy data files to wwwroot
// Generate index page
}
}
// Format project
$pagetpl = @file_get_contents(BASEDIR.'page_template.htm');
if ($pagetpl === false) die('Missing page_template.htm');
foreach($projects as $dirname => $projectname) {
$pr = new CProject($dirname, $projectname);
print_r($pr);
}
// Index page