code/index.php
<!--
PobCode
Copyright 2022 Fabio DM <fadimatteo@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
-->
<?php
require("conf.php");
$search=$_GET['s'];
function getDescr($pname)
{
global $ProjectsRoot;
$file=$ProjectsRoot.'/'.$pname.'/.pobsrc/descr.pob';
if (is_file($file))
{
return file_get_contents($file);
}else{
return '';
}
}
function getIcon($pname)
{
global $ProjectsRoot;
global $weburl;
$file=$ProjectsRoot.'/'.$pname.'/icon.png';
if (is_file($file))
{
$img="$weburl/$pname/icon.png";
return '<img src="'.$img.'" class="rounded float-left" style="width: 60px;margin-bottom:10px" />';
}else{
return '';
}
}
include ('header.php');
?>
<div class="container">
<p class="h1"><?php echo $Title ?></p>
<p class="lead">Open source projects</p>
<hr/>
<?php
$txtSearchValue='';
if( isset($search)) $txtSearchValue=' value="'.$search.'" ';
?>
<div id="searchBar" style="margin-bottom:10px;text-align:right" ><label>Search: <input id="txtSearch" type="text" <?php echo $txtSearchValue ?> placeholder="write and press enter"></label></div>
<div id="results">
<?php
if(! isset($search))
{
$arrProjects = scandir($ProjectsRoot);
foreach($arrProjects as $entry) {
if ($entry=='.' ) continue;
if ($entry=='..' ) continue;
if ($entry=='tmp' ) continue;
if (is_file($ProjectsRoot.'/'.$entry)) continue;
$url='project.php?p='.$entry;
echo '
<div class="card .container-fluid" style="margin-bottom:5px">
<div class="card-body">
<a href="'.$url.'">'.getIcon($entry).'</a>
<h5 class="card-title"><a href="'.$url.'">'.$entry.'</a></h5>
<p class="card-text">'.getDescr($entry).'</p>
</div>
</div>';
}
}else{ //search
$arrProjects = scandir($ProjectsRoot);
foreach($arrProjects as $entry) {
$descr=getDescr($entry);
if ($entry=='.' ) continue;
if ($entry=='..' ) continue;
if ($entry=='tmp' ) continue;
if (! empty($search) && strpos($entry, $search) === false && strpos($descr, $search) === false)
{
continue;
}
if (is_file($ProjectsRoot.'/'.$entry)) continue;
$url='project.php?p='.$entry;
echo '
<div class="card .container-fluid" style="margin-bottom:5px">
<div class="card-body">
<a href="'.$url.'">'.getIcon($entry).'</a>
<h5 class="card-title"><a href="'.$url.'">'.$entry.'</a></h5>
<p class="card-text">'.$descr.'</p>
</div>
</div>';
}
}
?>
</div>
</div>
<script>
$(document).ready(function(){
$( "#txtSearch" ).keypress(function(e) {
if ( e.which == 13 ) {
e.preventDefault();
spinner='<div id="results" class="spinner-border" role="status"><span class="sr-only">Loading...</span></div>';
url='index.php?s='+$( "#txtSearch" ).val();
window.location.href = url;
}
});
});
</script>
<?php include('footer.php');?>