Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.
Please keep in mind:
deFiant said:Alright it worked tyvm dark and danny, but there was 1 image on top and the whole row empty so this is what i did :
if ($i % $config['images_per_row'] == 1) { echo '</tr><td></td><tr>'; }
if ($i % $config['images_per_row'] == 0) { echo '</tr><td></td><tr>'; }
i just changed the 1 to 0.
<?php
session_start();
define('access', 'admin');
include('includes/chevereto.php');
// SETTINGS
$config = array (
'password' => 'admin123',
'image_formats' => 'png,jpg,gif',
'images_per_row' => 8,
'confirm' => true
);
// FUNCTIONS
function deleteFile($path, $type = 'image')
{
if(unlink($path))
{
showMessage($type.' deleted successfully !', true);
}
else
{
showMessage('Could not delete '.$type.' ('.__CHV_PATH_IMAGES__.$_GET['delete'].')', false);
}
}
function showMessage($msg, $success = true)
{
$color = ($success) ? 'green' : 'red';
print('<p style="color:'.$color.';">'.$msg.'</p>');
}
// Variables Declaration
$content = '';
$javascript = '';
// Login validation
if (isset($_POST['password']) && $_POST['password'] === $config['password'])
{
$_SESSION['login'] = true;
}
// Admin content
if (isset($_SESSION['login']) && $_SESSION['login'])
{
// Since we want to stay XHTML Valid…
ob_start();
// ========== DELETE IMAGE START ========== //
if(isset($_POST['delete']))
{
// delete image
if(file_exists(__CHV_PATH_IMAGES__.$_POST['delete']))
{
deleteFile(__CHV_PATH_IMAGES__.$_POST['delete']);
}
else
{
showMessage('Image does not exist ('.__CHV_PATH_IMAGES__.$_POST['delete'].')', false);
}
// delete thumb
if(file_exists(__CHV_PATH_THUMBS__.$_POST['delete']))
{
deleteFile(__CHV_PATH_THUMBS__.$_POST['delete'], 'thumb');
}
else
{
showMessage('Thumb does not exist ('.__CHV_PATH_IMAGES__.$_POST['delete'].')', false);
}
}
// ========== DELETE IMAGE END ========== //
$images = glob("".__CHV_PATH_IMAGES__."*.{".$config['image_formats']."}", GLOB_BRACE);
echo '<table cellspacing="3" cellpadding="0">';
echo '<tr>';
for ($i = 0; $i < count($images); $i++)
{
$name = basename($images[$i]);
if ($i % $config['images_per_row'] == 0) { echo '</tr><td></td><tr>'; }
echo '<td align="center" style="border:1px solid #cccccc;background:#eeeeee;padding:3px;">';
echo '<a href="./?v='.$name.'" target="_blank">';
echo '<img src="'.absolute_to_url(__CHV_PATH_THUMBS__.$name).'" style="margin-bottom:2px;border:0px;"></a><br />';
echo '<a style="font-size:11px;font-family:Arial;text-decoration:none;" class="_delete" alt="'.$name.'" href="#">Delete</a>';
echo '</td>';
}
echo '</tr>';
echo '</table>';
$content = ob_get_contents();
ob_end_clean();
$javascript = '';
}
else
{
$content = '
<form action="#" method="post">
<p><span style="font-weight: bold;">Password:</span> <input type="password" name="password" /></p>
<p><input type="button" value="Login" name="login" /></p>
</form>
';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/url]">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Chevereto Admin</title>
</head>
<body>
<?php print($content); ?>
</body>
</html>
<script type="text/javascript" src="<?php print(absolute_to_url(__CHV_PATH_SYSTEM_JS__)); ?>jquery.min.js"></script>
<script type="text/javascript">
$(function (){
$("._delete").click(function() {
var element = $(this);
<?php if($config['confirm']) { print('if (window.confirm("Are you sure you wish do delete this file?")) {'); } ?>
$.post("admin.php", {delete: $(this).attr('alt')}, function() {
}).success(function() {
$(element).parent().remove();
}).error(function() {
alert('For some obscure reason, we could not delete the file');
});
<?php if($config['confirm']) { print('}'); } ?>
});
});
</script>
<?php
session_start();
define('access', 'admin');
include('includes/chevereto.php');
// SETTINGS
$config = array (
'password' => 'admin123',
'image_formats' => array('gif', 'png', 'jpg', 'jpeg'),
'images_per_row' => 8,
'confirm' => true,
'order' => 'inverse' // normal => (From the oldest to the latest) inverse => (from the latest to the oldest)
);
// FUNCTIONS
function deleteFile($path, $type = 'image')
{
if(unlink($path))
{
showMessage($type.' deleted successfully !', true);
}
else
{
showMessage('Could not delete '.$type.' ('.__CHV_PATH_IMAGES__.$_GET['delete'].')', false);
}
}
function showMessage($msg, $success = true)
{
$color = ($success) ? 'green' : 'red';
print('<p style="color:'.$color.';">'.$msg.'</p>');
}
function fileExtension($fileName)
{
return substr($fileName, strrpos($fileName, '.') + 1);
}
function getFiles($allowedExt)
{
$array = array();
if ($handle = opendir(__CHV_PATH_IMAGES__))
{
while (false !== ($file = readdir($handle)))
{
if ($file != '.' && $file != '..' && in_array(fileExtension($file), $allowedExt))
{
$array[] = array('name' => $file, 'time' => filemtime(__CHV_PATH_IMAGES__.$file));
}
}
closedir($handle);
}
return $array;
}
function sortByTimeNormal($a, $b)
{
if ($a['time'] == $b['time'])
{
return 0;
}
return ($a['time'] < $b['time']) ? -1 : 1;
}
function sortByTimeInverse($a, $b)
{
if ($a['time'] == $b['time'])
{
return 0;
}
return ($a['time'] < $b['time']) ? 1 : -1;
}
// Variables Declaration
$content = '';
$javascript = '';
// Login validation
if (isset($_POST['password']) && $_POST['password'] === $config['password'])
{
$_SESSION['login'] = true;
}
// Admin content
if (isset($_SESSION['login']) && $_SESSION['login'])
{
// Since we want to stay XHTML Valid…
ob_start();
// ========== DELETE IMAGE START ========== //
if(isset($_POST['delete']))
{
// delete image
if(file_exists(__CHV_PATH_IMAGES__.$_POST['delete']))
{
deleteFile(__CHV_PATH_IMAGES__.$_POST['delete']);
}
else
{
showMessage('Image does not exist ('.__CHV_PATH_IMAGES__.$_POST['delete'].')', false);
}
// delete thumb
if(file_exists(__CHV_PATH_THUMBS__.$_POST['delete']))
{
deleteFile(__CHV_PATH_THUMBS__.$_POST['delete'], 'thumb');
}
else
{
showMessage('Thumb does not exist ('.__CHV_PATH_IMAGES__.$_POST['delete'].')', false);
}
}
// ========== DELETE IMAGE END ========== /
$images = getFiles($config['image_formats']);
if ($config['order'] == 'normal')
usort($images, 'sortByTimeNormal');
else
usort($images, 'sortByTimeInverse');
echo '<table cellspacing="3" cellpadding="0">';
echo '<tr>';
for ($i = 0; $i < count($images); $i++)
{
$name = basename($images[$i]['name']);
if ($i % $config['images_per_row'] == 0) { echo '</tr><td></td><tr>'; }
echo '<td align="center" style="border:1px solid #cccccc;background:#eeeeee;padding:3px;">';
echo '<a href="./?v='.$name.'" target="_blank">';
echo '<img src="'.absolute_to_url(__CHV_PATH_THUMBS__.$name).'" style="margin-bottom:2px;border:0px;"></a><br />';
echo '<span style="font-size:11px;font-family:Arial;text-decoration:none;">'.date('F d, Y H:i:s', $images[$i]['time']).'</span><br />';
echo '<a style="font-size:11px;font-family:Arial;text-decoration:none;" class="_delete" alt="'.$name.'" href="#">Delete</a>';
echo '</td>';
}
echo '</tr>';
echo '</table>';
$content = ob_get_contents();
ob_end_clean();
$javascript = '';
}
else
{
$content = '
<form action="#" method="post">
<p><span style="font-weight: bold;">Password:</span> <input type="password" name="password" /></p>
<p><input type="button" value="Login" name="login" /></p>
</form>
';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/url]">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Chevereto Admin</title>
</head>
<body>
<?php print($content); ?>
</body>
</html>
<script type="text/javascript" src="<?php print(absolute_to_url(__CHV_PATH_SYSTEM_JS__)); ?>jquery.min.js"></script>
<script type="text/javascript">
$(function (){
$("._delete").click(function() {
var element = $(this);
<?php if($config['confirm']) { print('if (window.confirm("Are you sure you wish do delete this file?")) {'); } ?>
$.post("admin.php", {delete: $(this).attr('alt')}, function() {
}).success(function() {
$(element).parent().remove();
}).error(function() {
alert('For some obscure reason, we could not delete the file');
});
<?php if($config['confirm']) { print('}'); } ?>
});
});
</script>
<?php
if (!isset($_SESSION)) session_start();
session_unset();
session_destroy();
session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);
header("Location: index.php");
?>
echo "<a href='logout.php'>Logout</a>";
echo '<table cellspacing="3" cellpadding="0">';
<?php
session_start();
define('access', 'admin');
include('includes/chevereto.php');
// SETTINGS
$config = array (
'password' => 'admin123',
'image_formats' => array('gif', 'png', 'jpg', 'jpeg'),
'images_per_row' => 8,
'confirm' => true,
'order' => 'inverse' // normal => (From the oldest to the latest) inverse => (from the latest to the oldest)
);
// FUNCTIONS
function deleteFile($path, $type = 'image')
{
if(unlink($path))
{
showMessage($type.' deleted successfully !', true);
}
else
{
showMessage('Could not delete '.$type.' ('.__CHV_PATH_IMAGES__.$_GET['delete'].')', false);
}
}
function showMessage($msg, $success = true)
{
$color = ($success) ? 'green' : 'red';
print('<p style="color:'.$color.';">'.$msg.'</p>');
}
function fileExtension($fileName)
{
return substr($fileName, strrpos($fileName, '.') + 1);
}
function getFiles($allowedExt)
{
$array = array();
if ($handle = opendir(__CHV_PATH_IMAGES__))
{
while (false !== ($file = readdir($handle)))
{
if ($file != '.' && $file != '..' && in_array(fileExtension($file), $allowedExt))
{
$array[] = array('name' => $file, 'time' => filemtime(__CHV_PATH_IMAGES__.$file));
}
}
closedir($handle);
}
return $array;
}
function sortByTimeNormal($a, $b)
{
if ($a['time'] == $b['time'])
{
return 0;
}
return ($a['time'] < $b['time']) ? -1 : 1;
}
function sortByTimeInverse($a, $b)
{
if ($a['time'] == $b['time'])
{
return 0;
}
return ($a['time'] < $b['time']) ? 1 : -1;
}
// Variables Declaration
$content = '';
$javascript = '';
// Login validation
if (isset($_POST['password']) && $_POST['password'] === $config['password'])
{
$_SESSION['login'] = true;
}
if (isset($_SESSION['login']) && $_SESSION['login'] && isset($_POST['logout']))
{
$_SESSION['login'] = false;
}
// Admin content
if (isset($_SESSION['login']) && $_SESSION['login'])
{
// Since we want to stay XHTML Valid…
ob_start();
// ========== DELETE IMAGE START ========== //
if(isset($_POST['delete']))
{
// delete image
if(file_exists(__CHV_PATH_IMAGES__.$_POST['delete']))
{
deleteFile(__CHV_PATH_IMAGES__.$_POST['delete']);
}
else
{
showMessage('Image does not exist ('.__CHV_PATH_IMAGES__.$_POST['delete'].')', false);
}
// delete thumb
if(file_exists(__CHV_PATH_THUMBS__.$_POST['delete']))
{
deleteFile(__CHV_PATH_THUMBS__.$_POST['delete'], 'thumb');
}
else
{
showMessage('Thumb does not exist ('.__CHV_PATH_IMAGES__.$_POST['delete'].')', false);
}
}
// ========== DELETE IMAGE END ========== /
//$images = glob("".__CHV_PATH_IMAGES__."*.{".$config['image_formats']."}", GLOB_BRACE);
$images = getFiles($config['image_formats']);
if ($config['order'] == 'normal')
usort($images, 'sortByTimeNormal');
else
usort($images, 'sortByTimeInverse');
// Logout button
print ('<div style="float: right;"><form action="#" method="post"><input type="submit" name="logout" value="Log Out" /></form></div>');
echo '<table cellspacing="3" cellpadding="0">';
echo '<tr>';
for ($i = 0; $i < count($images); $i++)
{
$name = basename($images[$i]['name']);
if ($i % $config['images_per_row'] == 0) { echo '</tr><td></td><tr>'; }
echo '<td align="center" style="border:1px solid #cccccc;background:#eeeeee;padding:3px;">';
echo '<a href="./?v='.$name.'" target="_blank">';
echo '<img src="'.absolute_to_url(__CHV_PATH_THUMBS__.$name).'" style="margin-bottom:2px;border:0px;"></a><br />';
echo '<span style="font-size:11px;font-family:Arial;text-decoration:none;">'.date('F d, Y H:i:s', $images[$i]['time']).'</span><br />';
echo '<a style="font-size:11px;font-family:Arial;text-decoration:none;" class="_delete" alt="'.$name.'" href="#">Delete</a>';
echo '</td>';
}
echo '</tr>';
echo '</table>';
$content = ob_get_contents();
ob_end_clean();
$javascript = '';
}
else
{
$content = '
<form action="#" method="post">
<p><span style="font-weight: bold;">Password:</span> <input type="password" name="password" /></p>
<p><input type="button" value="Login" name="login" /></p>
</form>
';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/url]">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Chevereto Admin</title>
</head>
<body>
<?php print($content); ?>
</body>
</html>
<script type="text/javascript" src="<?php print(absolute_to_url(__CHV_PATH_SYSTEM_JS__)); ?>jquery.min.js"></script>
<script type="text/javascript">
$(function (){
$("._delete").click(function() {
var element = $(this);
<?php if($config['confirm']) { print('if (window.confirm("Are you sure you wish do delete this file?")) {'); } ?>
$.post("admin.php", {delete: $(this).attr('alt')}, function() {
}).success(function() {
$(element).parent().remove();
}).error(function() {
alert('For some obscure reason, we could not delete the file');
});
<?php if($config['confirm']) { print('}'); } ?>
});
});
</script>