forked from 4ducky/4ducky
The PHP sources, templates and old jQuery-based scripts move unchanged into legacy/ for reference. Shared assets (media/, images/, favicon.ico, the default avatar) stay at the repository root. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
209 lines
5.2 KiB
PHP
209 lines
5.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
ImageViewer loads a single image and its comments specified by a keyword.
|
|
*/
|
|
|
|
require_once( 'lib/imagecatalog.php' );
|
|
|
|
class ImageViewer extends ImageCatalog {
|
|
protected $position = 0;
|
|
protected $keyword = '';
|
|
|
|
public $Fav = '';
|
|
|
|
public $image = array();
|
|
public $stream = array();
|
|
public $userInfo = array();
|
|
public $uploadid;
|
|
|
|
public $datenow;
|
|
|
|
|
|
public function setCurrent( $keyword ) {
|
|
$this->keyword = $keyword;
|
|
}
|
|
public function setFav( $case ) {
|
|
$this->Fav = $case;
|
|
}
|
|
public function CommentSpam( $userId) {
|
|
|
|
}
|
|
|
|
public function addComment( $userId, $comment,$iname="") {
|
|
|
|
|
|
$countcomments = DB::getRow("SELECT COUNT(*) as c FROM pl_comments WHERE created > now() - INTERVAL 10 SECOND AND userId=:1",$userId);
|
|
$sp = DB::getRow("SELECT spamblocked, time FROM pl_users WHERE id=:1",$userId);
|
|
|
|
if (intval($countcomments["c"]) > 2 || $sp["spamblocked"] == 1) {
|
|
if (int($sp["time"]) > 0){
|
|
$timeAdd = int($sp["time"]) + 1800;
|
|
}else{
|
|
$timeAdd = time() + 1800;
|
|
}
|
|
DB::updateRow("pl_users",array("id" => $userId),array("spamblocked" => 1,"spam_reason"=>"Commentspam","time" => $timeAdd));
|
|
return false;
|
|
}else{
|
|
|
|
if( $this->image['id'] && $userId && !empty($comment)) {
|
|
|
|
|
|
$datenow = date( 'Y.m.d H:i:s' );
|
|
|
|
if (strlen($iname) > 0){
|
|
DB::insertRow( TABLE_COMMENTS, array(
|
|
'imageId' => $this->image['id'],
|
|
'userId' => $userId,
|
|
'created' => $datenow,
|
|
'content' => $comment,
|
|
'thumb' => 1));
|
|
|
|
|
|
}else{
|
|
DB::insertRow( TABLE_COMMENTS, array(
|
|
'imageId' => $this->image['id'],
|
|
'userId' => $userId,
|
|
'created' => $datenow,
|
|
'content' => $comment,
|
|
'thumb' =>0));
|
|
}
|
|
if ($this->image['user'] != $userId){
|
|
DB::query("UPDATE pl_images SET score=score+1 WHERE id=:1",$this->image['id']);
|
|
}
|
|
|
|
|
|
|
|
$comments_load = DB::query(
|
|
'SELECT userId FROM pl_comments WHERE imageid=:1',
|
|
$this->image['id']
|
|
);
|
|
|
|
|
|
|
|
foreach( array_keys($comments_load) as $i ) {
|
|
|
|
|
|
$counter = DB::getRow("SELECT COUNT(*) as c FROM pl_unread WHERE userid=:1 AND imageid=:2",$comments_load[$i]["userId"],$this->image['id']);
|
|
|
|
if (($counter["c"] == 0) && $comments_load[$i]["userId"] != $userId){
|
|
DB::insertRow( "pl_unread", array('imageid' =>$this->image['id'], 'userid' => $comments_load[$i]["userId"],'keyword' => $this->keyword, 'createdby' => $userId));
|
|
}
|
|
|
|
|
|
}
|
|
|
|
$counter = DB::getRow("SELECT COUNT(*) as c FROM pl_unread WHERE userid=:1 AND imageid=:2",$this->image["user"],$this->image['id']);
|
|
if ($counter["c"] == 0 && $this->image["user"] != $userId){
|
|
DB::insertRow( "pl_unread", array('imageid' =>$this->image['id'], 'userid' => $this->image["user"],'keyword' => $this->keyword, 'createdby' => $userId));}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function load() {
|
|
|
|
|
|
$conditions = '';
|
|
if( !empty($this->user) ) {
|
|
$conditions .= ' AND i.user = :2';
|
|
$this->userInfo = $this->user;
|
|
}
|
|
$this->image = DB::getRow(
|
|
'SELECT
|
|
i.id, i.logged, UNIX_TIMESTAMP(i.logged) AS loggedTS,
|
|
i.keyword, i.image, i.score, i.votes,
|
|
tags, u.name AS userName, i.user, u.color
|
|
FROM '.TABLE_IMAGES.' i
|
|
LEFT JOIN '.TABLE_USERS.' u
|
|
ON u.id = i.user
|
|
WHERE i.keyword = :1 '.$conditions,
|
|
$this->keyword,
|
|
$this->user['id']
|
|
);
|
|
$this->image['path'] = date('Y/m/', $this->image['loggedTS']).$this->image['image'];
|
|
|
|
if( empty( $this->user) ) {
|
|
$this->userInfo = DB::getRow(
|
|
'SELECT id, name, score, images, avatar, website, color
|
|
FROM '.TABLE_USERS.'
|
|
WHERE
|
|
id = :1',
|
|
$this->image['user']
|
|
);
|
|
}
|
|
|
|
// compute previoues and next page
|
|
$next = DB::getRow(
|
|
'SELECT i.keyword
|
|
FROM '.TABLE_IMAGES.' i
|
|
WHERE i.id < :1 '.$conditions.'
|
|
ORDER BY id DESC
|
|
LIMIT 1',
|
|
$this->image['id'],
|
|
$this->user['id']
|
|
);
|
|
|
|
$prev = DB::getRow(
|
|
'SELECT i.keyword
|
|
FROM '.TABLE_IMAGES.' i
|
|
WHERE i.id > :1 '.$conditions.'
|
|
ORDER BY id ASC
|
|
LIMIT 1',
|
|
$this->image['id'],
|
|
$this->user['id']
|
|
);
|
|
|
|
|
|
|
|
if( !empty($next) ) {
|
|
$this->stream['next'] = $next['keyword'];
|
|
}
|
|
if( !empty($prev) ) {
|
|
$this->stream['prev'] = $prev['keyword'];
|
|
}
|
|
}
|
|
|
|
public function howlong($a=0, $b=0) {
|
|
if (!is_numeric($a)) $a = strtotime($a); if (!is_numeric($b)) $b = strtotime($b);
|
|
if ($a == 0) $a = time(); if ($b == 0) $b = time();
|
|
if ($a == $b) return "at the same time";
|
|
if ($a > $b) { $aa = $b; $b = $a; $a = $aa; $q = "away"; } else { $q = "ago"; }
|
|
$value = $b-$a;
|
|
if ($value == 1) return "1 sec $q";
|
|
if ($value < 60) return "$value sec $q";
|
|
$value /= 60;
|
|
if (round($value) == 1) return "1 min $q";
|
|
if ($value < 60) return round($value) . " min $q";
|
|
$value /= 60;
|
|
if (round($value) == 1) return "1 hour $q";
|
|
if ($value < 24) return round($value) . " hours $q";
|
|
$value /= 24;
|
|
if (round($value) == 1) if ($q == "ago") return "yesterday"; else return "tomorrow";
|
|
if ($value < 31) return round($value) . " days $q";
|
|
$value /= 31;
|
|
if (round($value) == 1) return "1 month $q";
|
|
if ($value < 12) return round($value) . " months $q";
|
|
$value /= 12;
|
|
if (round($value) == 1) return "1 year $q";
|
|
return round($value) . " years $q";
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function loadComments() {
|
|
|
|
}
|
|
}
|
|
|
|
?>
|