Files
5ducky/lib/getcomments.php
T
2022-10-06 22:04:13 +02:00

55 lines
1.8 KiB
PHP

<?php
header("Content-type: text/html; charset=UTF-8");
function shorter($input, $length)
{
//no need to trim, already shorter than trim length
if (strlen($input) <= $length) {
return $input;
}
//find last space within length
$last_space = strrpos(substr($input, 0, $length), ' ');
if(!$last_space) $last_space = $length;
$trimmed_text = substr($input, 0, $last_space);
//add ellipses (...)
$trimmed_text .= '...';
return $trimmed_text;
}
require_once( 'lib/config.php' );
require_once( 'lib/db.php' );
$comments = DB::query('SELECT * FROM pl_comments WHERE c_like="0" ORDER BY created DESC LIMIT 40');
foreach (array_keys($comments) as $c) {
$posterinfo = DB::getRow("SELECT * FROM pl_users WHERE id=:1",$comments[$c]["userId"]);
$commentimg = DB::getRow("SELECT * FROM pl_commentuploads WHERE c_id=:1",$comments[$c]["id"]);
$imageinfo = DB::getRow("SELECT * FROM pl_images WHERE id=:1",$comments[$c]["imageId"]);
$blockedrow = DB::getRow("SELECT id,users FROM pl_blocked WHERE id=:1",$user->id);
$blockeduser = array_map('strtolower', unserialize($blockedrow['users']));
$lower = strtolower($posterinfo["name"]);
if(!($commentimg && ($comments[$c]["userId"] == $imageinfo["user"]))){
if (!in_array($lower,$blockeduser)){
if ($imageinfo && $posterinfo){
?>
<div id="commentbar">
<a href="<?php echo (Config::$absolutePath.'all/view/'.$imageinfo["keyword"]); ?>">
<div id="commentimg">
<img width="28" height="28" src="<?php echo(Config::$absolutePath.$posterinfo["avatar"]); ?>" />
</div>
<div id="commenttext">
<strong><?php echo(shorter(strip_tags($posterinfo["name"]),"10")); ?>: </strong><?php echo(shorter(strip_tags($comments[$c]["content"]),"50")); ?>
</div>
</a>
</div>
<?php }}}}?>