working entry detection

This commit is contained in:
mappu 2016-04-19 19:20:00 +12:00
parent cfdeee6a46
commit d3739c2f81

View File

@ -43,6 +43,7 @@ class CProject {
$this->longdesc = file_get_contents($this->dir.'README.txt');
$this->longdesc = str_replace("\r", "", $this->longdesc); // filter windows CR
$this->longdesc = preg_replace("~[\s\t]*$~s", "", $this->longdesc); // filter trailing spaces at line endings
// Guess 'last update' time
if (preg_match('~\n(\d\d\d\d-\d\d-\d\d)~', $this->longdesc, $matches)) {
@ -94,7 +95,7 @@ class CProject {
while(strpos($this->longdesc, "\n\n\n") !== false) {
$this->longdesc = str_replace("\n\n\n", "\n\n", $this->longdesc);
}
$this->longdesc = rtrim($this->longdesc, "\n");
$this->longdesc = rtrim($this->longdesc, "\n")."\n";
$this->prefix_html = $prefix_html;
@ -146,7 +147,10 @@ class CProject {
// then move the files
// A release entry is marked by any string following the date field.
preg_match_all('~^(\d\d\d\d-\d\d-\d\d):? (.+?)\n[\s\t]*\n~ms', $this->longdesc, $matches, PREG_SET_ORDER);
// Add one more NL than we really want, for regex reasons
$this->longdesc .= "\n";
preg_match_all('~^(\d\d\d\d-\d\d-\d\d)\s?:? (.+?)\n\n~ms', $this->longdesc, $matches, PREG_SET_ORDER);
do {
// Ensure changelog exists
@ -167,12 +171,21 @@ class CProject {
break;
}
// Ensure all downloads can be assigned to tags
// Ensure all downloads can be assigned to tags.
// In the event of a download matching multiple tags, it'll
// be assigned to the newest (topmost) entry
$found_idx = [];
$render_per_tag = [];
foreach($this->downloads as $idx => $filename) {
foreach(array_keys($known_tags) as $tagname) {
if (stripos($filename, $tagname) !== false) {
$found_idx[$filename] = true;
$found_idx[$idx] = $tagname;
if (! isset($render_per_tag[$tagname])) {
$render_per_tag[$tagname] = [];
}
$render_per_tag[$tagname][$idx] = $filename;
break; // next file
}
}
}
@ -191,18 +204,30 @@ class CProject {
);
}
$this->longdesc = substr($this->longdesc, 0, strlen($this->longdesc)-1); // Strip the extra NL we added
$this->longdesc = text2html($this->longdesc);
foreach($known_tags as $tag_name => $tag_idx) {
$this->longdesc = str_replace('${{TAG_'.$tag_idx.'}}', $this->renderDownloadsBlock(false, $tag_name), $this->longdesc);
$this->longdesc = str_replace(
'${{TAG_'.$tag_idx.'}}',
$this->renderDownloadsBlock($render_per_tag[$tag_name], false),
$this->longdesc
);
}
$this->longdesc = str_replace("</ul>\n<br />", "</ul>", $this->longdesc);
// Skip displaying the global downloads area
// This flag also indicates that the content has been pre-HTMLified
$this->downloads_section_was_replaced = true;
error_log("[".$this->projname."] successful upgrade\n");
// Successful upgrade
} while(false);
if (! $this->downloads_section_was_replaced) {
$this->longdesc = substr($this->longdesc, 0, strlen($this->longdesc)-1); // Strip the extra NL we added
}
}
public function numDownloads() {
@ -256,18 +281,7 @@ class CProject {
}
}
public function renderDownloadsBlock($include_header=false, $filter='') {
$render_downloads = [];
if (strlen($filter)) {
foreach($this->downloads as $idx => $filename) {
if (stripos($filename, $filter) !== false) {
$render_downloads[$idx] = $filename;
}
}
} else {
$render_downloads = $this->downloads;
}
public function renderDownloadsBlock($render_downloads, $include_header=false) {
if (! count($render_downloads)) {
return;
}
@ -309,12 +323,14 @@ class CProject {
<strong><?=hesc(strtoupper(ARTICLE_HEADER))?></strong>
<p><?=$longdesc_html?></p>
<div class="content-paragraph">
<?=$longdesc_html?>
</div>
<?=file_get_contents(BASEDIR.'/footer.htm')?>
<?php if (! $this->downloads_section_was_replaced) { ?>
<?=$this->renderDownloadsBlock(true, '')?>
<?=$this->renderDownloadsBlock($this->downloads, true)?>
<?php } ?>
</div>