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); } function is_image($sz) { return in_array(strtolower(str_ext($sz)), ['jpg', 'png', 'jpeg']); } function hesc($sz) { return @htmlentities($sz, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } function text2html($sz) { $base = hesc($sz); $base = preg_replace('~=+(.+)=+~', '\\1', $base); $base = preg_replace('~(https?://[^ \\r\\n\\t]+)~i', '\\1', $base); $btparts = explode('`', $base); if (count($btparts) > 1 && (count($btparts) % 2)) { for ($i = 1, $e = count($btparts); $i < $e; $i += 2) { $btparts[$i] = ''.$btparts[$i].''; } $base = implode('', $btparts); } return nl2br($base); } /** * */ class CProject { private $dir; public $projname; public $shortdesc = '(no description)'; public $subtag = ''; private $longdesc = ''; private $images = array(); private $downloads = array(); public $homeimage = null; 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'); $matches = array(); if (preg_match('~Written in ([^\\r\\n]+)~', $this->longdesc, $matches)) { $this->subtag = rtrim($matches[1], ' .'); } $this->shortdesc = array_shift(explode("\n", $this->longdesc)); $this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase continue; } if (is_image($file)) { $this->images[] = $file; } else { $this->downloads[] = $file; } } } public function write() { // Generate image thumbnails foreach($this->images as $idx => $image) { $outfile = BASEDIR.'wwwroot/srv/'.$this->projname.'_'.$idx; copy($this->dir.$image, $outfile.'.'.str_ext($image)); mkthumbnail($outfile.'.'.str_ext($image), $outfile.'_thumb.jpg', PAGE_THUMB_W, PAGE_THUMB_H); } if (count($this->images)) { $this->homeimage = mkthumbnail( BASEDIR.'wwwroot/srv/'.$this->projname.'_0.'.str_ext($this->images[0]), null, // raw handle INDEX_THUMB_W, INDEX_THUMB_H ); } // Copy downloads to wwwroot foreach($this->downloads as $idx => $filename) { copy($this->dir.$filename, BASEDIR.'wwwroot/srv/'.$filename); } // Generate index page ob_start(); $this->index(); $idxfile = template($this->projname.' | '.SITE_TITLE, ob_get_clean()); file_put_contents(BASEDIR.'wwwroot/'.$this->projname.'.html', $idxfile); } public function index() { ?>
=text2html($this->longdesc)?>
downloads)) { ?> DOWNLOAD=(is_null($handle_lookup[$pr->projname]) ? '' : '')?> |
=hesc($pr->projname)?>,
=hesc($pr->shortdesc)?>
more...
subtag)) { ?>
=hesc($pr->subtag)?> |