bbn/home.php

68 lines
1.8 KiB
PHP

<form action="index.php" method="GET">
<div>
<input type="submit" name="home" value="home" accesskey="h">
<input type="submit" name="open" value="open">
<input type="submit" name="filter" value="filter">
<input type="submit" name="search" value="search">
<input type="submit" name="tags" value="tags">
<input type="submit" name="clip" value="clip">
<br>
<input autocomplete="off" class="title" name="param" value="<?php echo $param; ?>">
</div>
</form>
<div class="editor">
<?php
$files = glob($dir . '/*');
usort($files, function($a, $b)
{
return filemtime($b) - filemtime($a);
});
foreach($files as $path)
{
$tags = '';
$name = basename($path);
if (!str_ends_with($name, '.del') && ($action != 'filter' || str_contains(strtolower($name), strtolower($param))))
{
if ($action == 'search' || $action == 'tags')
{
$content = file_get_contents($path);
if (($action == 'search' && !str_contains(strtolower($content), strtolower($param))) ||
($action == 'tags' && !preg_match('/tags:.*' . $param . '/i', $content)))
{
continue;
}
}
echo '<div><a href=index.php?open=true&param=' . urlencode($name) . '>' . $name .'</a>';
if ($action == 'tags')
{
$tags = array();
$hastags = preg_match_all('/tags:(.*)/i', $content, $tags, PREG_SET_ORDER);
if ($hastags)
{
$tagslist = explode(',', $tags[0][1]);
echo '<span class="grey"> ';
foreach ($tagslist as $tag)
{
$tag = trim($tag);
echo('<a class="grey" href="index.php?tags=true&param=' . $tag . '">' . $tag . '</a> ');
}
echo '</span>';
}
}
else if ($action == 'search')
{
$pos = strpos(strtolower($content), strtolower($param));
echo '<span class="grey"> <b>' . $param . '</b>' . substr($content, $pos + strlen($param), 42) . '</span>';
}
echo'</div>';
}
}
?>
</div>