tag support 1/X: parse tags from readme, add classes to html

This commit is contained in:
mappu 2014-05-10 11:12:14 +12:00
parent 4c43510c44
commit bf7b18fd1f

View File

@ -124,6 +124,7 @@ class CProject {
private $longdesc = '';
private $images = array();
private $downloads = array();
public $tags = array();
public $homeimage = null;
@ -144,6 +145,10 @@ class CProject {
$this->subtag = rtrim($matches[1], ' .');
}
if (preg_match('~Tags: ([^\\r\\n]+)~', $this->longdesc, $matches)) {
$this->tags = array_map('trim', explode(',', $matches[1]));
}
$this->shortdesc = array_shift(explode("\n", $this->longdesc));
$this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase
continue;
@ -190,6 +195,14 @@ class CProject {
file_put_contents(BASEDIR.'wwwroot/'.$this->projname.'.html', $idxfile);
}
public function getClassAttr() {
if (count($this->tags)) {
return 'taggedWith-'.implode(' taggedWith-', $this->tags);
} else {
return '';
}
}
public function index() {
?>
<h2><?=hesc($this->projname)?></h2>
@ -322,7 +335,7 @@ function buildall() {
<table class="projtable">
<?php foreach ($plist as $pr) { ?>
<tr>
<tr class="<?=$pr->getClassAttr()?>">
<td>
<a href="<?=hesc(urlencode($pr->projname))?>.html"><?=(is_null($handle_lookup[$pr->projname]) ? '<div class="no-image"></div>' : '<div class="homeimage homeimage-sprite" style="background-position:0 -'.($handle_lookup[$pr->projname]*INDEX_THUMB_H).'px"></div>')?></a>
</td>
@ -330,9 +343,17 @@ function buildall() {
<strong><?=hesc($pr->projname)?></strong>,
<?=hesc($pr->shortdesc)?>
<a href="<?=hesc(urlencode($pr->projname))?>.html">more...</a>
<?php if (strlen($pr->subtag)) { ?>
<?php if (strlen($pr->subtag) || count($pr->tags)) { ?>
<br>
<small><?=hesc($pr->subtag)?></small>
<small>
<?=hesc($pr->subtag)?>
<?php if (strlen($pr->subtag) && count($pr->tags)) { ?>
::
<?php } ?>
<?php foreach($pr->tags as $tag) { ?>
<span class="tag" data-tag="<?=hesc($tag)?>"><?=hesc($tag)?></span>
<?php } ?>
</small>
<?php } ?>
</td>
</tr>