working entry detection
This commit is contained in:
parent
cfdeee6a46
commit
d3739c2f81
@ -43,6 +43,7 @@ class CProject {
|
|||||||
|
|
||||||
$this->longdesc = file_get_contents($this->dir.'README.txt');
|
$this->longdesc = file_get_contents($this->dir.'README.txt');
|
||||||
$this->longdesc = str_replace("\r", "", $this->longdesc); // filter windows CR
|
$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
|
// Guess 'last update' time
|
||||||
if (preg_match('~\n(\d\d\d\d-\d\d-\d\d)~', $this->longdesc, $matches)) {
|
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) {
|
while(strpos($this->longdesc, "\n\n\n") !== false) {
|
||||||
$this->longdesc = str_replace("\n\n\n", "\n\n", $this->longdesc);
|
$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;
|
$this->prefix_html = $prefix_html;
|
||||||
|
|
||||||
@ -146,7 +147,10 @@ class CProject {
|
|||||||
// then move the files
|
// then move the files
|
||||||
// A release entry is marked by any string following the date field.
|
// 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 {
|
do {
|
||||||
// Ensure changelog exists
|
// Ensure changelog exists
|
||||||
@ -167,12 +171,21 @@ class CProject {
|
|||||||
break;
|
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 = [];
|
$found_idx = [];
|
||||||
|
$render_per_tag = [];
|
||||||
foreach($this->downloads as $idx => $filename) {
|
foreach($this->downloads as $idx => $filename) {
|
||||||
foreach(array_keys($known_tags) as $tagname) {
|
foreach(array_keys($known_tags) as $tagname) {
|
||||||
if (stripos($filename, $tagname) !== false) {
|
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);
|
$this->longdesc = text2html($this->longdesc);
|
||||||
foreach($known_tags as $tag_name => $tag_idx) {
|
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
|
// Skip displaying the global downloads area
|
||||||
// This flag also indicates that the content has been pre-HTMLified
|
// This flag also indicates that the content has been pre-HTMLified
|
||||||
$this->downloads_section_was_replaced = true;
|
$this->downloads_section_was_replaced = true;
|
||||||
|
|
||||||
error_log("[".$this->projname."] successful upgrade\n");
|
// Successful upgrade
|
||||||
|
|
||||||
} while(false);
|
} 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() {
|
public function numDownloads() {
|
||||||
@ -256,18 +281,7 @@ class CProject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderDownloadsBlock($include_header=false, $filter='') {
|
public function renderDownloadsBlock($render_downloads, $include_header=false) {
|
||||||
$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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! count($render_downloads)) {
|
if (! count($render_downloads)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -309,12 +323,14 @@ class CProject {
|
|||||||
|
|
||||||
<strong><?=hesc(strtoupper(ARTICLE_HEADER))?></strong>
|
<strong><?=hesc(strtoupper(ARTICLE_HEADER))?></strong>
|
||||||
|
|
||||||
<p><?=$longdesc_html?></p>
|
<div class="content-paragraph">
|
||||||
|
<?=$longdesc_html?>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?=file_get_contents(BASEDIR.'/footer.htm')?>
|
<?=file_get_contents(BASEDIR.'/footer.htm')?>
|
||||||
|
|
||||||
<?php if (! $this->downloads_section_was_replaced) { ?>
|
<?php if (! $this->downloads_section_was_replaced) { ?>
|
||||||
<?=$this->renderDownloadsBlock(true, '')?>
|
<?=$this->renderDownloadsBlock($this->downloads, true)?>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user